summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8d12b8e)
raw | patch | inline | side by side (parent: 8d12b8e)
author | mental <mental@users.sourceforge.net> | |
Fri, 10 Nov 2006 00:30:30 +0000 (00:30 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Fri, 10 Nov 2006 00:30:30 +0000 (00:30 +0000) |
src/extension/init.cpp | patch | blob | history | |
src/extension/internal/Makefile_insert | patch | blob | history | |
src/extension/internal/pdf-mini.h | [deleted file] | patch | blob | history |
src/extension/internal/pdf-out.cpp | [deleted file] | patch | blob | history |
src/extension/internal/pdf-out.h | [deleted file] | patch | blob | history |
src/extension/internal/pdf.cpp | [deleted file] | patch | blob | history |
src/extension/internal/pdf.h | [deleted file] | patch | blob | history |
diff --git a/src/extension/init.cpp b/src/extension/init.cpp
index 86fee218efc10df903f846b4a20655eb20a255ad..b1659c0ef1b6c0eb2737097f8219ba9812d32bbf 100644 (file)
--- a/src/extension/init.cpp
+++ b/src/extension/init.cpp
#include "db.h"
#include "internal/svgz.h"
#include "internal/ps.h"
-#include "internal/pdf.h"
#ifdef HAVE_CAIRO_PDF
# include "internal/pdf-cairo.h"
#endif
# include "internal/win32.h"
#endif
#include "internal/ps-out.h"
-#include "internal/pdf-out.h"
#ifdef HAVE_CAIRO_PDF
# include "internal/cairo-pdf-out.h"
# include "internal/cairo-renderer-pdf-out.h"
Internal::PsOutput::init();
Internal::EpsOutput::init();
Internal::PrintPS::init();
- Internal::PdfOutput::init();
- Internal::PrintPDF::init();
#ifdef HAVE_CAIRO_PDF
Internal::CairoPdfOutput::init();
Internal::PrintCairoPDF::init();
index bf93a343fd5af0485fce74c5d4e0b5e6089d3d4f..eff097c95abd6bf65180979526e01896811699ef 100644 (file)
extension/internal/ps.cpp \
extension/internal/ps-out.h \
extension/internal/ps-out.cpp \
- extension/internal/pdf.h \
- extension/internal/pdf.cpp \
- extension/internal/pdf-mini.h \
- extension/internal/pdf-out.h \
- extension/internal/pdf-out.cpp \
extension/internal/pdf-cairo.cpp \
extension/internal/pdf-cairo.h \
extension/internal/cairo-pdf-out.h \
diff --git a/src/extension/internal/pdf-mini.h b/src/extension/internal/pdf-mini.h
+++ /dev/null
@@ -1,342 +0,0 @@
-/** \file\r
- * PDF Mini library.\r
- */\r
-/*\r
- * Authors:\r
- * Ulf Erikson <ulferikson@users.sf.net>\r
- *\r
- * Minimalistic library to support generation of PDF files.\r
- *\r
- * Copyright (C) 2006 Authors\r
- *\r
- * Released under GNU GPL, read the file 'COPYING' for more information\r
- */\r
-\r
-#ifndef PDF_MINI_H_SEEN\r
-#define PDF_MINI_H_SEEN\r
-\r
-\r
-class PdfFile;\r
-class PdfXref;\r
-class PdfObject;\r
-\r
-enum pdf_resource_type { pdf_none, pdf_extgstate, pdf_colorspace, pdf_pattern, pdf_shading, pdf_xobject, pdf_font, pdf_properties };\r
-\r
-char pdf_res_short[][5] = { "", "GS", "CS", "Pa", "Sh", "XObj", "F", "Prop" };\r
-char pdf_res_long[][20] = { "", "ExtGState", "ColorSpace", "Pattern",\r
- "Shading", "XObject", "Font", "Properties" };\r
-\r
-class PdfFile {\r
- public:\r
- PdfFile(FILE *_stream);\r
- ~PdfFile();\r
-\r
- long puts(const char *str);\r
- long puts(std::string ss) { return puts(ss.c_str()); }\r
- long puts(Inkscape::SVGOStringStream &os) { return puts(os.str().c_str()); }\r
- long puts(PdfXref *table);\r
- long puts(PdfObject *object);\r
- \r
- long tell();\r
- \r
- PdfObject *begin_document(double version = 1.2);\r
- void end_document(PdfObject *doc_info);\r
- PdfObject *begin_page(double x0, double y0, double x1, double y1);\r
- PdfObject *begin_page(double w, double h) { return begin_page(0,0, w, h); }\r
- void end_page(PdfObject *page);\r
- PdfObject *begin_object();\r
- void end_object(PdfObject *object);\r
- PdfObject *begin_resource(enum pdf_resource_type);\r
- void end_resource(PdfObject *resource);\r
- \r
- protected:\r
- FILE *fp;\r
- long length;\r
- long stream_pos;\r
-\r
- PdfXref *xref;\r
-\r
- PdfXref *pages;\r
- PdfXref *resources;\r
-\r
- PdfObject *obj_root;\r
- PdfObject *obj_catalog;\r
- PdfObject *obj_info;\r
- PdfObject *obj_resources;\r
- PdfObject *obj_contents;\r
- PdfObject *obj_length;\r
-};\r
-\r
-\r
-class PdfXref {\r
- public:\r
- PdfXref() { table.push_back(0); }\r
- ~PdfXref() { table.clear(); }\r
-\r
- long get_size() { return (long) table.size() - 1; }\r
- long get_entry(long id) { return table.at(id); }\r
- \r
- void update_entry(long id, long offset) {\r
- table.at(id) = offset;\r
- }\r
- \r
- long add_entry(long offset = 0) {\r
- table.push_back(offset);\r
- return get_size();\r
- }\r
-\r
- protected:\r
- std::vector<long> table;\r
-};\r
-\r
-\r
-class PdfObject : public Inkscape::SVGOStringStream {\r
- public:\r
- PdfObject(long i) : next(NULL), name(NULL) { id = i; setf(std::ios::fixed); }\r
- ~PdfObject() { if (name) g_free(name); }\r
-\r
- long get_id() { return id; }\r
- const char *get_name() { return name; }\r
- long get_length() { return str().length(); }\r
- void set_type(enum pdf_resource_type type) {\r
- if (name) g_free(name);\r
- name = g_strdup_printf("/%s%ld", pdf_res_short[type], id);\r
- }\r
- PdfObject *next;\r
-\r
- protected:\r
- long id;\r
- gchar *name;\r
-};\r
-\r
-PdfFile::PdfFile(FILE *_stream) {\r
- fp = _stream;\r
- xref = new PdfXref();\r
-}\r
-\r
-PdfFile::~PdfFile() {\r
- delete xref;\r
-}\r
-\r
-long PdfFile::puts(const char *str) {\r
- long res = fprintf(fp, "%s", str);\r
- if (res >= 0) {\r
- length += res;\r
- res = length;\r
- }\r
- return res;\r
-}\r
-\r
-long PdfFile::puts(PdfObject *object) {\r
- xref->update_entry( object->get_id(), tell() );\r
- return puts(object->str());\r
-}\r
-\r
-long PdfFile::puts(PdfXref *table) {\r
- Inkscape::SVGOStringStream os;\r
- char buffer[32];\r
- int i;\r
-\r
- int size = table->get_size() + 1;\r
-\r
- os << "xref\n";\r
- os << "0" << " " << size << "\n";\r
-\r
- snprintf(buffer, sizeof(buffer), "%010d %05d %c \n", 0, 65535, 'f');\r
- buffer[sizeof(buffer)-1] = 0;\r
- os << buffer;\r
-\r
- for (i = 1; i < size; i++) {\r
- snprintf(buffer, sizeof(buffer), "%010d %05d %c \n", (int)table->get_entry(i), 0, 'n');\r
- buffer[sizeof(buffer)-1] = 0;\r
- os << buffer;\r
- }\r
-\r
- return puts(os);\r
-}\r
-\r
-long PdfFile::tell() {\r
- return length;\r
-}\r
-\r
-PdfObject *PdfFile::begin_document(double version) {\r
- Inkscape::SVGOStringStream os;\r
- char bin[5] = {0x80|'B', 0x80|'i', 0x80|'n', 0x80|'!', 0};\r
- length = 0;\r
- pages = new PdfXref();;\r
-\r
- os << "%PDF-" << version << "\n";\r
- os << "%" << bin << "\n";\r
-\r
- obj_info = begin_object();\r
- *obj_info << "<<\n";\r
-\r
- obj_catalog = begin_object();\r
-\r
- obj_root = begin_object();\r
- *obj_root << "<<\n";\r
- *obj_root << " /Type /Catalog\n";\r
- *obj_root << " /Pages " << obj_catalog->get_id() << " 0 R\n";\r
- *obj_root << ">>\n";\r
- end_object(obj_root);\r
-\r
- puts(os);\r
- puts(obj_root);\r
-\r
- return obj_info;\r
-}\r
-\r
-void PdfFile::end_document(PdfObject *doc_info) {\r
- Inkscape::SVGOStringStream os;\r
- long startxref;\r
- int i;\r
-\r
- *doc_info << ">>\n";\r
- end_object(doc_info);\r
- puts(doc_info);\r
- \r
- *obj_catalog << "<<\n"\r
- << " /Type /Pages\n"\r
- << " /Count " << pages->get_size() << "\n"\r
- << " /Kids [\n";\r
- for (i=1; i<=pages->get_size(); i++) {\r
- *obj_catalog << " " << pages->get_entry(i) << " 0 R\n";\r
- }\r
- *obj_catalog << " ]\n"\r
- << ">>\n";\r
- end_object(obj_catalog);\r
- puts(obj_catalog);\r
- \r
- startxref = tell();\r
-\r
- puts(xref);\r
- \r
- os << "trailer\n"\r
- << "<<\n"\r
- << " /Size " << xref->get_size() << "\n"\r
- << " /Root " << obj_root->get_id() << " 0 R\n"\r
- << " /Info " << obj_info->get_id() << " 0 R\n"\r
- << ">>\n";\r
- os << "startxref\n"\r
- << startxref << "\n";\r
- os << "%%EOF\n";\r
-\r
- puts(os);\r
-\r
- delete pages;\r
- delete obj_root;\r
- delete obj_catalog;\r
- delete obj_info;\r
-}\r
-\r
-PdfObject *PdfFile::begin_page(double x0, double y0, double x1, double y1) {\r
- Inkscape::SVGOStringStream os;\r
-\r
- resources = new PdfXref[11]();\r
- PdfObject *obj_page = begin_object();\r
- \r
- obj_resources = begin_object();\r
- obj_contents = begin_object();\r
- obj_length = begin_object();\r
- \r
- *obj_page << "<<\n"\r
- << " /Type /Page\n"\r
- << " /Parent " << obj_catalog->get_id() << " 0 R\n"\r
- << " /MediaBox [ " << x0 << " " << y0 << " " << x1 << " " << y1 << " ]\n"\r
- << " /Resources " << obj_resources->get_id() << " 0 R\n"\r
- << " /Contents " << obj_contents->get_id() << " 0 R\n"\r
- << " /Group\n"\r
- << " << /Type /Group\n"\r
- << " /S /Transparency\n"\r
- << " /CS /DeviceRGB\n"\r
- << " >>\n"\r
- << ">>\n";\r
- end_object(obj_page);\r
- puts(obj_page);\r
-\r
- pages->add_entry( obj_page->get_id() );\r
-\r
- *obj_contents << "<<\n"\r
- << " /Length " << obj_length->get_id() << " 0 R\n"\r
- << ">>\n"\r
- << "stream\n";\r
- puts(obj_contents);\r
- stream_pos = ftell(fp);\r
-\r
- return obj_contents;\r
-}\r
-\r
-void PdfFile::end_page(PdfObject *page) {\r
- long stream_length = ftell(fp) - stream_pos;\r
- \r
- puts("endstream\n");\r
- puts("endobj\n");\r
- \r
- *obj_length << stream_length << "\n";\r
- end_object(obj_length);\r
- puts(obj_length);\r
-\r
- *obj_resources << "<<\n";\r
- *obj_resources << " /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n";\r
- int res;\r
- for (res=pdf_extgstate; res<=pdf_properties; res++) {\r
- if (resources[res].get_size()) {\r
- *obj_resources << " /" << pdf_res_long[res] << "\n";\r
- *obj_resources << " <<\n";\r
- int i;\r
- for (i=1; i<=resources[res].get_size(); i++) {\r
- int id = resources[res].get_entry(i);\r
- *obj_resources << " /"\r
- << pdf_res_short[res] << id\r
- << " " << id << " 0 R\n";\r
- }\r
- *obj_resources << " >>\n";\r
- }\r
- }\r
- *obj_resources << ">>\n";\r
- end_object(obj_resources);\r
- puts(obj_resources);\r
-\r
- PdfObject *o = obj_resources->next;\r
- while (o) {\r
- PdfObject *t = o->next;\r
- puts(o);\r
- delete o;\r
- o = t;\r
- }\r
- \r
- delete obj_resources;\r
- delete obj_length;\r
- delete obj_contents;\r
- \r
- delete[] resources;\r
-}\r
-\r
-PdfObject *PdfFile::begin_object() {\r
- long id = xref->add_entry();\r
- PdfObject *obj = new PdfObject(id);\r
- *obj << id << " 0 obj\n";\r
- return obj;\r
-}\r
-\r
-void PdfFile::end_object(PdfObject *object) {\r
- *object << "endobj\n";\r
-}\r
-\r
-PdfObject *PdfFile::begin_resource(enum pdf_resource_type res) {\r
- PdfObject *obj = begin_object();\r
- if (res != pdf_none) {\r
- resources[res].add_entry(obj->get_id());\r
- obj->set_type(res);\r
- }\r
- obj->next = obj_resources->next;\r
- obj_resources->next = obj;\r
- return obj;\r
-}\r
-\r
-void PdfFile::end_resource(PdfObject *resource) {\r
- end_object(resource);\r
-}\r
-\r
-\r
-#endif /* !PDF_MINI_H_SEEN */\r
diff --git a/src/extension/internal/pdf-out.cpp b/src/extension/internal/pdf-out.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-/*\r
- * A quick hack to use the print output to write out a file. This\r
- * then makes 'save as...' PDF.\r
- *\r
- * Authors:\r
- * Ted Gould <ted@gould.cx>\r
- * Ulf Erikson <ulferikson@users.sf.net>\r
- *\r
- * Copyright (C) 2004-2006 Authors\r
- *\r
- * Released under GNU GPL, read the file 'COPYING' for more information\r
- */\r
-\r
-#ifdef HAVE_CONFIG_H\r
-# include <config.h>\r
-#endif\r
-#include "pdf-out.h"\r
-#include <print.h>\r
-#include "extension/system.h"\r
-#include "extension/print.h"\r
-#include "extension/db.h"\r
-#include "extension/output.h"\r
-#include "display/nr-arena.h"\r
-#include "display/nr-arena-item.h"\r
-#include "sp-path.h"\r
-\r
-namespace Inkscape {\r
-namespace Extension {\r
-namespace Internal {\r
-\r
-bool\r
-PdfOutput::check (Inkscape::Extension::Extension * module)\r
-{\r
- if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_PDF))\r
- return FALSE;\r
-\r
- return TRUE;\r
-}\r
-\r
-\r
-static unsigned int\r
-pdf_print_document_to_file(SPDocument *doc, gchar const *filename)\r
-{\r
- Inkscape::Extension::Print *mod;\r
- SPPrintContext context;\r
- gchar const *oldconst;\r
- gchar *oldoutput;\r
- unsigned int ret;\r
-\r
- sp_document_ensure_up_to_date(doc);\r
-\r
- mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_PDF);\r
- oldconst = mod->get_param_string("destination");\r
- oldoutput = g_strdup(oldconst);\r
- mod->set_param_string("destination", (gchar *)filename);\r
-\r
-/* Start */\r
- context.module = mod;\r
- /* fixme: This has to go into module constructor somehow */\r
- /* Create new arena */\r
- mod->base = SP_ITEM(sp_document_root(doc));\r
- mod->arena = NRArena::create();\r
- mod->dkey = sp_item_display_key_new(1);\r
- mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);\r
-\r
- /* Print document */\r
- ret = mod->begin(doc);\r
- if (ret) {\r
- sp_item_invoke_print(mod->base, &context);\r
- ret = mod->finish();\r
- }\r
-\r
- /* Release arena */\r
- sp_item_invoke_hide(mod->base, mod->dkey);\r
- mod->base = NULL;\r
- nr_arena_item_unref(mod->root);\r
- mod->root = NULL;\r
- nr_object_unref((NRObject *) mod->arena);\r
- mod->arena = NULL;\r
-/* end */\r
-\r
- mod->set_param_string("destination", oldoutput);\r
- g_free(oldoutput);\r
-\r
- return ret;\r
-}\r
-\r
-\r
-/**\r
- \brief This function calls the print system with the filename\r
- \param mod unused\r
- \param doc Document to be saved\r
- \param uri Filename to save to (probably will end in .pdf)\r
-\r
- The most interesting thing that this function does is just attach\r
- an '>' on the front of the filename. This is the syntax used to\r
- tell the printing system to save to file.\r
-*/\r
-void\r
-PdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)\r
-{\r
- Inkscape::Extension::Extension * ext;\r
- unsigned int ret;\r
-\r
- ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_PDF);\r
- if (ext == NULL)\r
- return;\r
-\r
- gchar * final_name;\r
- final_name = g_strdup_printf("> %s", uri);\r
- ret = pdf_print_document_to_file(doc, final_name);\r
- g_free(final_name);\r
-\r
- if (!ret)\r
- throw Inkscape::Extension::Output::save_failed();\r
-\r
- return;\r
-}\r
-\r
-/**\r
- \brief A function allocate a copy of this function.\r
-\r
- This is the definition of PDF out. This function just\r
- calls the extension system with the memory allocated XML that\r
- describes the data.\r
-*/\r
-void\r
-PdfOutput::init (void)\r
-{\r
- Inkscape::Extension::build_from_mem(\r
- "<inkscape-extension>\n"\r
- "<name>PDF Output</name>\n"\r
- "<id>org.inkscape.output.pdf</id>\n"\r
- "<output>\n"\r
- "<extension>.pdf</extension>\n"\r
- "<mimetype>application/pdf</mimetype>\n"\r
- "<filetypename>PDF (*.pdf)</filetypename>\n"\r
- "<filetypetooltip>PDF File</filetypetooltip>\n"\r
- "</output>\n"\r
- "</inkscape-extension>", new PdfOutput());\r
-\r
- return;\r
-}\r
-\r
-} } } /* namespace Inkscape, Extension, Implementation */\r
diff --git a/src/extension/internal/pdf-out.h b/src/extension/internal/pdf-out.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*\r
- * A quick hack to use the print output to write out a file. This\r
- * then makes 'save as...' PDF.\r
- *\r
- * Authors:\r
- * Ted Gould <ted@gould.cx>\r
- * Ulf Erikson <ulferikson@users.sf.net>\r
- *\r
- * Copyright (C) 2004-2006 Authors\r
- *\r
- * Released under GNU GPL, read the file 'COPYING' for more information\r
- */\r
-\r
-#ifndef EXTENSION_INTERNAL_PDF_OUT_H\r
-#define EXTENSION_INTERNAL_PDF_OUT_H\r
-\r
-#include "extension/implementation/implementation.h"\r
-\r
-namespace Inkscape {\r
-namespace Extension {\r
-namespace Internal {\r
-\r
-class PdfOutput : Inkscape::Extension::Implementation::Implementation {\r
-\r
-public:\r
- bool check(Inkscape::Extension::Extension *module);\r
- void save(Inkscape::Extension::Output *mod,\r
- SPDocument *doc,\r
- gchar const *uri);\r
- static void init();\r
-};\r
-\r
-} } } /* namespace Inkscape, Extension, Implementation */\r
-\r
-#endif /* !EXTENSION_INTERNAL_PDF_OUT_H */\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
diff --git a/src/extension/internal/pdf.cpp b/src/extension/internal/pdf.cpp
+++ /dev/null
@@ -1,1594 +0,0 @@
-#define __SP_PDF_C__\r
-\r
-/** \file\r
- * PDF printing.\r
- */\r
-/*\r
- * Authors:\r
- * Lauris Kaplinski <lauris@kaplinski.com>\r
- * bulia byak <buliabyak@users.sf.net>\r
- * Ulf Erikson <ulferikson@users.sf.net>\r
- *\r
- * Basic printing code, EXCEPT image and\r
- * ascii85 filter is in public domain\r
- *\r
- * Image printing and Ascii85 filter:\r
- *\r
- * Copyright (C) 1995 Spencer Kimball and Peter Mattis\r
- * Copyright (C) 1997-98 Peter Kirchgessner\r
- * George White <aa056@chebucto.ns.ca>\r
- * Austin Donnelly <austin@gimp.org>\r
- *\r
- * Licensed under GNU GPL\r
- */\r
-\r
-/* Plain Print */\r
-\r
-#ifdef HAVE_CONFIG_H\r
-# include "config.h"\r
-#endif\r
-\r
-#include <signal.h>\r
-#include <errno.h>\r
-\r
-#include <glib/gmem.h>\r
-#include <libnr/n-art-bpath.h>\r
-#include <libnr/nr-point-matrix-ops.h>\r
-\r
-#include <gtk/gtkstock.h>\r
-#include <gtk/gtkvbox.h>\r
-#include <gtk/gtkframe.h>\r
-#include <gtk/gtkradiobutton.h>\r
-#include <gtk/gtkcombo.h>\r
-#include <gtk/gtklabel.h>\r
-#include <gtk/gtkentry.h>\r
-#include <gtk/gtktooltips.h>\r
-\r
-#include <glibmm/i18n.h>\r
-#include "display/nr-arena-item.h"\r
-#include "display/canvas-bpath.h"\r
-#include "sp-item.h"\r
-#include "style.h"\r
-#include "sp-linear-gradient.h"\r
-#include "sp-radial-gradient.h"\r
-\r
-#include "libnrtype/font-instance.h"\r
-#include "libnrtype/font-style-to-pos.h"\r
-\r
-#include <unit-constants.h>\r
-\r
-#include "pdf.h"\r
-#include "extension/system.h"\r
-#include "extension/print.h"\r
-\r
-#include "io/sys.h"\r
-\r
-#include "pdf-mini.h"\r
-\r
-namespace Inkscape {\r
-namespace Extension {\r
-namespace Internal {\r
-\r
-PrintPDF::PrintPDF() :\r
- _stream(NULL),\r
- _dpi(72),\r
- _bitmap(false)\r
-{\r
-}\r
-\r
-PrintPDF::~PrintPDF(void)\r
-{\r
- /* fixme: should really use pclose for popen'd streams */\r
- if (_stream) fclose(_stream);\r
-\r
- /* restore default signal handling for SIGPIPE */\r
-#if !defined(_WIN32) && !defined(__WIN32__)\r
- (void) signal(SIGPIPE, SIG_DFL);\r
-#endif\r
-\r
- return;\r
-}\r
-\r
-unsigned int\r
-PrintPDF::setup(Inkscape::Extension::Print * mod)\r
-{\r
- static gchar const *const pdr[] = {"72", "75", "100", "144", "150", "200", "300", "360", "600", "1200", "2400", NULL};\r
-\r
-#ifdef TED\r
- Inkscape::XML::Node *repr = ((SPModule *) mod)->repr;\r
-#endif\r
-\r
- unsigned int ret = FALSE;\r
-\r
- /* Create dialog */\r
- GtkTooltips *tt = gtk_tooltips_new();\r
- g_object_ref((GObject *) tt);\r
- gtk_object_sink((GtkObject *) tt);\r
-\r
- GtkWidget *dlg = gtk_dialog_new_with_buttons(_("Print Destination"),\r
-// SP_DT_WIDGET(SP_ACTIVE_DESKTOP)->window,\r
- NULL,\r
- (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT),\r
- GTK_STOCK_CANCEL,\r
- GTK_RESPONSE_CANCEL,\r
- GTK_STOCK_PRINT,\r
- GTK_RESPONSE_OK,\r
- NULL);\r
-\r
- gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK);\r
-\r
- GtkWidget *vbox = GTK_DIALOG(dlg)->vbox;\r
- gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);\r
- /* Print properties frame */\r
- GtkWidget *f = gtk_frame_new(_("Print properties"));\r
- gtk_box_pack_start(GTK_BOX(vbox), f, FALSE, FALSE, 4);\r
- GtkWidget *vb = gtk_vbox_new(FALSE, 4);\r
- gtk_container_add(GTK_CONTAINER(f), vb);\r
- gtk_container_set_border_width(GTK_CONTAINER(vb), 4);\r
- /* Print type */\r
- bool const p2bm = mod->get_param_bool("bitmap");\r
- GtkWidget *rb = gtk_radio_button_new_with_label(NULL, _("Print using PDF operators"));\r
- gtk_tooltips_set_tip((GtkTooltips *) tt, rb,\r
- _("Use PDF vector operators. The resulting image is usually smaller "\r
- "in file size and can be arbitrarily scaled, but "\r
- "patterns will be lost."), NULL);\r
- if (!p2bm) gtk_toggle_button_set_active((GtkToggleButton *) rb, TRUE);\r
- gtk_box_pack_start(GTK_BOX(vb), rb, FALSE, FALSE, 0);\r
- rb = gtk_radio_button_new_with_label(gtk_radio_button_get_group((GtkRadioButton *) rb), _("Print as bitmap"));\r
- gtk_tooltips_set_tip((GtkTooltips *) tt, rb,\r
- _("Print everything as bitmap. The resulting image is usually larger "\r
- "in file size and cannot be arbitrarily scaled without quality loss, "\r
- "but all objects will be rendered exactly as displayed."), NULL);\r
- if (p2bm) gtk_toggle_button_set_active((GtkToggleButton *) rb, TRUE);\r
- gtk_box_pack_start(GTK_BOX(vb), rb, FALSE, FALSE, 0);\r
- /* Resolution */\r
- GtkWidget *hb = gtk_hbox_new(FALSE, 4);\r
- gtk_box_pack_start(GTK_BOX(vb), hb, FALSE, FALSE, 0);\r
- GtkWidget *combo = gtk_combo_new();\r
- gtk_combo_set_value_in_list(GTK_COMBO(combo), FALSE, FALSE);\r
- gtk_combo_set_use_arrows(GTK_COMBO(combo), TRUE);\r
- gtk_combo_set_use_arrows_always(GTK_COMBO(combo), TRUE);\r
- gtk_widget_set_size_request(combo, 64, -1);\r
- gtk_tooltips_set_tip((GtkTooltips *) tt, GTK_COMBO(combo)->entry,\r
- _("Preferred resolution (dots per inch) of bitmap"), NULL);\r
- /* Setup strings */\r
- GList *sl = NULL;\r
- for (unsigned i = 0; pdr[i] != NULL; i++) {\r
- sl = g_list_prepend(sl, (gpointer) pdr[i]);\r
- }\r
- sl = g_list_reverse(sl);\r
- gtk_combo_set_popdown_strings(GTK_COMBO(combo), sl);\r
- g_list_free(sl);\r
- if (1) {\r
- gchar const *val = mod->get_param_string("resolution");\r
- gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), val);\r
- }\r
- gtk_box_pack_end(GTK_BOX(hb), combo, FALSE, FALSE, 0);\r
- GtkWidget *l = gtk_label_new(_("Resolution:"));\r
- gtk_box_pack_end(GTK_BOX(hb), l, FALSE, FALSE, 0);\r
-\r
- /* Print destination frame */\r
- f = gtk_frame_new(_("Print destination"));\r
- gtk_box_pack_start(GTK_BOX(vbox), f, FALSE, FALSE, 4);\r
- vb = gtk_vbox_new(FALSE, 4);\r
- gtk_container_add(GTK_CONTAINER(f), vb);\r
- gtk_container_set_border_width(GTK_CONTAINER(vb), 4);\r
-\r
- l = gtk_label_new(_("Printer name (as given by lpstat -p);\n"\r
- "leave empty to use the system default printer.\n"\r
- "Use '> filename' to print to file.\n"\r
- "Use '| prog arg...' to pipe to a program."));\r
- gtk_box_pack_start(GTK_BOX(vb), l, FALSE, FALSE, 0);\r
-\r
- GtkWidget *e = gtk_entry_new();\r
- if (1) {\r
- gchar const *val = mod->get_param_string("destination");\r
- gtk_entry_set_text(GTK_ENTRY(e), ( val != NULL\r
- ? val\r
- : "" ));\r
- }\r
- gtk_box_pack_start(GTK_BOX(vb), e, FALSE, FALSE, 0);\r
-\r
- // pressing enter in the destination field is the same as clicking Print:\r
- gtk_entry_set_activates_default(GTK_ENTRY(e), TRUE);\r
-\r
- gtk_widget_show_all(vbox);\r
-\r
- int const response = gtk_dialog_run(GTK_DIALOG(dlg));\r
-\r
- g_object_unref((GObject *) tt);\r
-\r
- if (response == GTK_RESPONSE_OK) {\r
- gchar const *fn;\r
- char const *sstr;\r
-\r
- _bitmap = gtk_toggle_button_get_active((GtkToggleButton *) rb);\r
- sstr = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));\r
- _dpi = (unsigned int) MAX((int)(atof(sstr)), 1);\r
- /* Arrgh, have to do something */\r
- fn = gtk_entry_get_text(GTK_ENTRY(e));\r
- /* skip leading whitespace, bug #1068483 */\r
- while (fn && *fn==' ') { fn++; }\r
- /* g_print("Printing to %s\n", fn); */\r
-\r
- mod->set_param_bool("bitmap", _bitmap);\r
- mod->set_param_string("resolution", (gchar *)sstr);\r
- mod->set_param_string("destination", (gchar *)fn);\r
- ret = TRUE;\r
- }\r
-\r
- gtk_widget_destroy(dlg);\r
-\r
- return ret;\r
-}\r
-\r
-unsigned int\r
-PrintPDF::begin(Inkscape::Extension::Print *mod, SPDocument *doc)\r
-{\r
- gboolean epsexport = false;\r
-\r
- _latin1_encoded_fonts.clear();\r
- _newlatin1font_proc_defined = false;\r
-\r
- FILE *osf = NULL;\r
- FILE *osp = NULL;\r
-\r
- _pushed_alphas.clear();\r
- _pushed_alphas.push_back(1.0);\r
-\r
- gsize bytesRead = 0;\r
- gsize bytesWritten = 0;\r
- GError *error = NULL;\r
- gchar const *utf8_fn = mod->get_param_string("destination");\r
- gchar *local_fn = g_filename_from_utf8( utf8_fn,\r
- -1, &bytesRead, &bytesWritten, &error);\r
- gchar const *fn = local_fn;\r
-\r
- /* TODO: Replace the below fprintf's with something that does the right thing whether in\r
- * gui or batch mode (e.g. --print=blah). Consider throwing an exception: currently one of\r
- * the callers (sp_print_document_to_file, "ret = mod->begin(doc)") wrongly ignores the\r
- * return code.\r
- */\r
- if (fn != NULL) {\r
- if (*fn == '|') {\r
- fn += 1;\r
- while (isspace(*fn)) fn += 1;\r
-#ifndef WIN32\r
- osp = popen(fn, "wb");\r
-#else\r
- osp = _popen(fn, "wb");\r
-#endif\r
- if (!osp) {\r
- fprintf(stderr, "inkscape: popen(%s): %s\n",\r
- fn, strerror(errno));\r
- return 0;\r
- }\r
- _stream = osp;\r
- } else if (*fn == '>') {\r
- fn += 1;\r
- epsexport = g_str_has_suffix(fn,".eps");\r
- while (isspace(*fn)) fn += 1;\r
- Inkscape::IO::dump_fopen_call(fn, "K");\r
- osf = Inkscape::IO::fopen_utf8name(fn, "wb+");\r
- if (!osf) {\r
- fprintf(stderr, "inkscape: fopen(%s): %s\n",\r
- fn, strerror(errno));\r
- return 0;\r
- }\r
- _stream = osf;\r
- } else {\r
- /* put cwd stuff in here */\r
- gchar *qn = ( *fn\r
- ? g_strdup_printf("lpr -P %s", fn) /* FIXME: quote fn */\r
- : g_strdup("lpr") );\r
-#ifndef WIN32\r
- osp = popen(qn, "wb");\r
-#else\r
- osp = _popen(qn, "wb");\r
-#endif\r
- if (!osp) {\r
- fprintf(stderr, "inkscape: popen(%s): %s\n",\r
- qn, strerror(errno));\r
- return 0;\r
- }\r
- g_free(qn);\r
- _stream = osp;\r
- }\r
- }\r
-\r
- g_free(local_fn);\r
-\r
- if (_stream) {\r
- /* fixme: this is kinda icky */\r
-#if !defined(_WIN32) && !defined(__WIN32__)\r
- (void) signal(SIGPIPE, SIG_IGN);\r
-#endif\r
- }\r
-\r
- pdf_file = new PdfFile(_stream);\r
- doc_info = pdf_file->begin_document(1.4);\r
- *doc_info << " /Title(" << doc->name << ")\n";\r
- *doc_info << " /Author(" << g_get_real_name() << ")\n";\r
-// *doc_info << " /Subject(" << "?" << ")\n";\r
-// *doc_info << " /Keywords(" << "?" << ")\n";\r
- *doc_info << " /Creator(" << "www.inkscape.org" << ")\n";\r
- *doc_info << " /Producer(" << "Inkscape " << PACKAGE_STRING << ")\n";\r
- //the date should be in ISO/IEC 8824\r
- GDate date;\r
- GTimeVal ltime;\r
- glong time_hh, time_mm, time_ss;\r
-#if GLIB_CHECK_VERSION(2,9,0)\r
- g_date_set_time_t (&date, time (NULL));\r
-#else\r
- g_date_set_time(&date, time (NULL));\r
-#endif\r
- gchar date_str[100], time_str[100];\r
- g_date_strftime(date_str, 99, "%Y%m%d", &date);\r
- g_get_current_time(<ime);\r
- time_hh=(ltime.tv_sec/3600)%24;\r
- time_mm=(ltime.tv_sec/60)%60;\r
- time_ss=(ltime.tv_sec)%60;\r
- g_snprintf(time_str, 99, "%02ld%02ld%02ld", time_hh, time_mm, time_ss); \r
- *doc_info << " /CreationDate(D:" << date_str << time_str << "Z)\n";\r
-// *doc_info << " /CreationDate(D:" << date_str << time_str << "OHH'mm')\n";\r
-\r
- /* flush this to test output stream as early as possible */\r
- if (fflush(_stream)) {\r
- /*g_print("caught error in sp_module_print_plain_begin\n");*/\r
- if (ferror(_stream)) {\r
- g_print("Error %d on output stream: %s\n", errno,\r
- g_strerror(errno));\r
- }\r
- g_print("Printing failed\n");\r
- /* fixme: should use pclose() for pipes */\r
- fclose(_stream);\r
- _stream = NULL;\r
- fflush(stdout);\r
- return 0;\r
- }\r
-\r
- // width and height in pt\r
- _width = sp_document_width(doc) * PT_PER_PX;\r
- _height = sp_document_height(doc) * PT_PER_PX;\r
-\r
- NRRect d;\r
- bool pageBoundingBox;\r
- pageBoundingBox = mod->get_param_bool("pageBoundingBox");\r
- // printf("Page Bounding Box: %s\n", pageBoundingBox ? "TRUE" : "FALSE");\r
- if (pageBoundingBox) {\r
- d.x0 = d.y0 = 0;\r
- d.x1 = _width;\r
- d.y1 = _height;\r
- } else {\r
- SPItem* doc_item = SP_ITEM(sp_document_root(doc));\r
- sp_item_invoke_bbox(doc_item, &d, sp_item_i2r_affine(doc_item), TRUE);\r
- // convert from px to pt\r
- d.x0 *= PT_PER_PX;\r
- d.x1 *= PT_PER_PX;\r
- d.y0 *= PT_PER_PX;\r
- d.y1 *= PT_PER_PX;\r
- }\r
-\r
- page_stream = pdf_file->begin_page( d.x0, d.y0, d.x1, d.y1 );\r
-\r
- if (!_bitmap) {\r
- Inkscape::SVGOStringStream os;\r
- os.setf(std::ios::fixed);\r
- os << PT_PER_PX << " 0 0 "\r
- << -PT_PER_PX << " 0 " << (int) ceil(_height)\r
- << " cm\n";\r
- // from now on we can output px, but they will be treated as pt\r
- pdf_file->puts(os);\r
- }\r
- \r
- return 1;\r
-}\r
-\r
-unsigned int\r
-PrintPDF::finish(Inkscape::Extension::Print *mod)\r
-{\r
- if (!_stream) return 0;\r
-\r
- if (_bitmap) {\r
- double const dots_per_pt = _dpi / PT_PER_IN;\r
-\r
- double const x0 = 0.0;\r
- double const y0 = 0.0;\r
- double const x1 = x0 + _width;\r
- double const y1 = y0 + _height;\r
-\r
- /* Bitmap width/height in bitmap dots. */\r
- int const width = (int) (_width * dots_per_pt + 0.5);\r
- int const height = (int) (_height * dots_per_pt + 0.5);\r
-\r
- NRMatrix affine;\r
- affine.c[0] = width / ((x1 - x0) * PX_PER_PT);\r
- affine.c[1] = 0.0;\r
- affine.c[2] = 0.0;\r
- affine.c[3] = height / ((y1 - y0) * PX_PER_PT);\r
- affine.c[4] = -affine.c[0] * x0;\r
- affine.c[5] = -affine.c[3] * y0;\r
-\r
- nr_arena_item_set_transform(mod->root, &affine);\r
-\r
- guchar *const px = g_new(guchar, 4 * width * 64);\r
-\r
- for (int y = 0; y < height; y += 64) {\r
- /* Set area of interest. */\r
- NRRectL bbox;\r
- bbox.x0 = 0;\r
- bbox.y0 = y;\r
- bbox.x1 = width;\r
- bbox.y1 = MIN(height, y + 64);\r
-\r
- /* Update to renderable state. */\r
- NRGC gc(NULL);\r
- nr_matrix_set_identity(&gc.transform);\r
- nr_arena_item_invoke_update(mod->root, &bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);\r
- /* Render */\r
- /* This should take guchar* instead of unsigned char*) */\r
- NRPixBlock pb;\r
- nr_pixblock_setup_extern(&pb, NR_PIXBLOCK_MODE_R8G8B8A8N,\r
- bbox.x0, bbox.y0, bbox.x1, bbox.y1,\r
- (guchar*)px, 4 * width, FALSE, FALSE);\r
- memset(px, 0xff, 4 * width * 64);\r
- nr_arena_item_invoke_render(mod->root, &bbox, &pb, 0);\r
- /* Blitter goes here */\r
- NRMatrix imgt;\r
- imgt.c[0] = (bbox.x1 - bbox.x0) / dots_per_pt;\r
- imgt.c[1] = 0.0;\r
- imgt.c[2] = 0.0;\r
- imgt.c[3] = (bbox.y1 - bbox.y0) / dots_per_pt;\r
- imgt.c[4] = 0.0;\r
- imgt.c[5] = _height - y / dots_per_pt - (bbox.y1 - bbox.y0) / dots_per_pt;\r
-\r
- print_image(_stream, px, bbox.x1 - bbox.x0, bbox.y1 - bbox.y0, 4 * width, &imgt);\r
- }\r
-\r
- g_free(px);\r
- }\r
-\r
- pdf_file->end_page(page_stream);\r
- pdf_file->end_document(doc_info);\r
-\r
- delete pdf_file;\r
-\r
- /* Flush stream to be sure. */\r
- (void) fflush(_stream);\r
-\r
- /* fixme: should really use pclose for popen'd streams */\r
- fclose(_stream);\r
- _stream = 0;\r
- _latin1_encoded_fonts.clear();\r
-\r
- return 1;\r
-}\r
-\r
-unsigned int\r
-PrintPDF::bind(Inkscape::Extension::Print *mod, NRMatrix const *transform, float opacity)\r
-{\r
- if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.\r
- if (_bitmap) return 0;\r
-\r
- Inkscape::SVGOStringStream os;\r
- os.setf(std::ios::fixed);\r
- \r
- os << "q\n";\r
- os << transform->c[0] << " "\r
- << transform->c[1] << " "\r
- << transform->c[2] << " "\r
- << transform->c[3] << " "\r
- << transform->c[4] << " "\r
- << transform->c[5] << " cm\n";\r
-\r
- float alpha = opacity * _pushed_alphas.back();\r
- _pushed_alphas.push_back(alpha);\r
-\r
- pdf_file->puts(os);\r
- return 1;\r
-}\r
-\r
-unsigned int\r
-PrintPDF::release(Inkscape::Extension::Print *mod)\r
-{\r
- if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.\r
- if (_bitmap) return 0;\r
-\r
- _pushed_alphas.pop_back();\r
- g_assert( _pushed_alphas.size() > 0 );\r
-\r
- pdf_file->puts("Q\n");\r
-\r
- return 1;\r
-}\r
-\r
-unsigned int\r
-PrintPDF::comment(Inkscape::Extension::Print *mod, char const *comment)\r
-{\r
- if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.\r
- if (_bitmap) return 0;\r
- \r
- return 1;\r
-}\r
-\r
-void\r
-PrintPDF::print_fill_alpha(SVGOStringStream &os, SPStyle const *const style, NRRect const *pbox)\r
-{\r
- g_return_if_fail( style->fill.type == SP_PAINT_TYPE_COLOR\r
- || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER\r
- && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) );\r
- \r
- if (style->fill.type == SP_PAINT_TYPE_COLOR) {\r
- float alpha = 1.0;\r
- alpha *= SP_SCALE24_TO_FLOAT(style->fill_opacity.value);\r
- alpha *= _pushed_alphas.back();\r
-\r
- if (alpha != 1.0) {\r
- PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate);\r
- *pdf_alpha << "<< /Type /ExtGState\n";\r
- *pdf_alpha << " /ca " << alpha << "\n";\r
- *pdf_alpha << " /AIS false\n";\r
- *pdf_alpha << ">>\n";\r
- \r
- os << pdf_alpha->get_name()\r
- << " gs\n";\r
-\r
- pdf_file->end_resource(pdf_alpha);\r
- }\r
- } else {\r
- g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER\r
- && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );\r
- \r
- if (SP_IS_LINEARGRADIENT (SP_STYLE_FILL_SERVER (style))) {\r
- \r
- SPLinearGradient *lg=SP_LINEARGRADIENT(SP_STYLE_FILL_SERVER (style));\r
- sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built\r
-\r
- NR::Point p1 (lg->x1.computed, lg->y1.computed);\r
- NR::Point p2 (lg->x2.computed, lg->y2.computed);\r
- if (pbox && SP_GRADIENT(lg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {\r
- // convert to userspace\r
- NR::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0);\r
- p1 *= bbox2user;\r
- p2 *= bbox2user;\r
- }\r
- \r
- double alpha = 1.0;\r
- for (gint i = 0; unsigned(i) < lg->vector.stops.size(); i++) {\r
- alpha *= lg->vector.stops[i].opacity;\r
- }\r
- \r
- if (alpha != 1.0 || _pushed_alphas.back() != 1.0) {\r
- PdfObject *pdf_gstate = pdf_file->begin_resource(pdf_extgstate);\r
- *pdf_gstate << "<< /Type /ExtGState\n";\r
- \r
- if (_pushed_alphas.back() != 1.0) {\r
- *pdf_gstate << " /ca " << _pushed_alphas.back() << "\n";\r
- *pdf_gstate << " /AIS false\n";\r
- }\r
- \r
- if (alpha != 1.0) {\r
- PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_shading);\r
- PdfObject *pdf_smask = pdf_file->begin_resource(pdf_none);\r
- PdfObject *pdf_xobj = pdf_file->begin_resource(pdf_none);\r
-\r
-\r
- *pdf_gstate << " /SMask " << pdf_smask->get_id() << " 0 R\n";\r
-\r
- \r
- *pdf_alpha << "<<\n/ShadingType 2\n/ColorSpace /DeviceGray\n";\r
- *pdf_alpha << "/Coords [" << p1[NR::X] << " " << p1[NR::Y] << " " << p2[NR::X] << " " << p2[NR::Y] <<"]\n";\r
- *pdf_alpha << "/Extend [true true]\n";\r
- *pdf_alpha << "/Domain [0 1]\n";\r
- *pdf_alpha << "/Function <<\n/FunctionType 3\n/Functions\n[\n";\r
-\r
- for (gint i = 0; unsigned(i) < lg->vector.stops.size() - 1; i++) {\r
- *pdf_alpha << "<<\n/FunctionType 2\n/Domain [0 1]\n";\r
- *pdf_alpha << "/C0 [" << lg->vector.stops[i].opacity << "]\n";\r
- *pdf_alpha << "/C1 [" << lg->vector.stops[i+1].opacity << "]\n";\r
- *pdf_alpha << "/N 1\n>>\n";\r
- }\r
- *pdf_alpha << "]\n/Domain [0 1]\n";\r
- *pdf_alpha << "/Bounds [ ";\r
- for (gint i=0;unsigned(i)<lg->vector.stops.size()-2;i++) {\r
- *pdf_alpha << lg->vector.stops[i+1].offset <<" ";\r
- }\r
- *pdf_alpha << "]\n";\r
- *pdf_alpha << "/Encode [ ";\r
- for (gint i=0;unsigned(i)<lg->vector.stops.size()-1;i++) {\r
- *pdf_alpha << "0 1 ";\r
- }\r
- *pdf_alpha << "]\n";\r
- *pdf_alpha << ">>\n>>\n";\r
-\r
- \r
- *pdf_smask << "<< /Type /Mask\n";\r
- *pdf_smask << " /S /Alpha\n";\r
- *pdf_smask << " /BC [0.0]\n";\r
- *pdf_smask << " /G " << pdf_xobj->get_id() << " 0 R\n";\r
- *pdf_smask << ">>\n";\r
-\r
- \r
- *pdf_xobj << "<< /Type /XObject\n";\r
- *pdf_xobj << " /Subtype /Form\n";\r
- *pdf_xobj << " /FormType 1\n";\r
- *pdf_xobj << " /BBox ["\r
- << pbox->x0 << " "\r
- << pbox->y0 << " "\r
- << pbox->x1 << " "\r
- << pbox->y1 << "]\n";\r
- *pdf_xobj << " /Group\n";\r
- *pdf_xobj << " << /Type /Group\n";\r
- *pdf_xobj << " /S /Transparency\n";\r
- *pdf_xobj << " /CS /DeviceGray \n";\r
- *pdf_xobj << " >>\n";\r
- *pdf_xobj << " /Resources\n";\r
- *pdf_xobj << " <<\n";\r
- *pdf_xobj << " /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n";\r
- *pdf_xobj << " /Shading << "\r
- << pdf_alpha->get_name() << " "\r
- << pdf_alpha->get_id() << " 0 R >>\n";\r
- *pdf_xobj << " >>\n";\r
- \r
- Inkscape::SVGOStringStream os_tmp;\r
- os_tmp.setf(std::ios::fixed);\r
- \r
- os_tmp << "q\n"\r
- << pbox->x0 << " " << pbox->y0 << " m\n"\r
- << pbox->x1 << " " << pbox->y0 << " l\n"\r
- << pbox->x1 << " " << pbox->y1 << " l\n"\r
- << pbox->x0 << " " << pbox->y1 << " l\n"\r
- << pbox->x0 << " " << pbox->y0 << " l\n"\r
- << "h\n"\r
- << "W* n\n";\r
- \r
- SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));\r
- if (g->gradientTransform_set) {\r
- os_tmp << g->gradientTransform[0] << " "\r
- << g->gradientTransform[1] << " "\r
- << g->gradientTransform[2] << " "\r
- << g->gradientTransform[3] << " "\r
- << g->gradientTransform[4] << " "\r
- << g->gradientTransform[5] << " cm\n"; \r
- }\r
- \r
- os_tmp << pdf_alpha->get_name() << " sh\n";\r
- os_tmp << "Q\n";\r
- *pdf_xobj << " /Length " << os_tmp.str().length() << "\n";\r
- *pdf_xobj << ">>\n";\r
- *pdf_xobj << "stream\n";\r
- *pdf_xobj << os_tmp.str().c_str();\r
- *pdf_xobj << "endstream\n";\r
-\r
-\r
- pdf_file->end_resource(pdf_alpha);\r
- pdf_file->end_resource(pdf_smask);\r
- pdf_file->end_resource(pdf_xobj);\r
- }\r
- \r
- *pdf_gstate << ">>\n";\r
-\r
- os << pdf_gstate->get_name() << " gs\n";\r
- \r
- pdf_file->end_resource(pdf_gstate);\r
- }\r
- } else if (SP_IS_RADIALGRADIENT (SP_STYLE_FILL_SERVER (style))) {\r
-\r
- SPRadialGradient *rg=SP_RADIALGRADIENT(SP_STYLE_FILL_SERVER (style));\r
- sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built\r
-\r
- NR::Point c (rg->cx.computed, rg->cy.computed);\r
- NR::Point f (rg->fx.computed, rg->fy.computed);\r
- double r = rg->r.computed;\r
-\r
- NR::Coord const df = hypot(f[NR::X] - c[NR::X], f[NR::Y] - c[NR::Y]);\r
- if (df >= r) {\r
- f[NR::X] = c[NR::X] + (f[NR::X] - c[NR::X] ) * r / (float) df;\r
- f[NR::Y] = c[NR::Y] + (f[NR::Y] - c[NR::Y] ) * r / (float) df;\r
- }\r
-\r
- if (pbox && SP_GRADIENT(rg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {\r
- // convert to userspace\r
- NR::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0);\r
- c *= bbox2user;\r
- f *= bbox2user;\r
- r *= bbox2user.expansion();\r
- }\r
- \r
- double alpha = 1.0;\r
- for (gint i = 0; unsigned(i) < rg->vector.stops.size(); i++) {\r
- alpha *= rg->vector.stops[i].opacity;\r
- }\r
-\r
- if (alpha != 1.0 || _pushed_alphas.back() != 1.0) {\r
- PdfObject *pdf_gstate = pdf_file->begin_resource(pdf_extgstate);\r
- *pdf_gstate << "<< /Type /ExtGState\n";\r
- \r
- if (_pushed_alphas.back() != 1.0) {\r
- *pdf_gstate << " /ca " << _pushed_alphas.back() << "\n";\r
- *pdf_gstate << " /AIS false\n";\r
- }\r
- \r
- if (alpha != 1.0) {\r
- PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_shading);\r
- PdfObject *pdf_smask = pdf_file->begin_resource(pdf_none);\r
- PdfObject *pdf_xobj = pdf_file->begin_resource(pdf_none);\r
-\r
-\r
- *pdf_gstate << " /SMask " << pdf_smask->get_id() << " 0 R\n";\r
-\r
-\r
- *pdf_alpha << "<<\n/ShadingType 3\n/ColorSpace /DeviceGray\n";\r
- *pdf_alpha << "/Coords ["<< f[NR::X] <<" "<< f[NR::Y] <<" 0 "<< c[NR::X] <<" "<< c[NR::Y] <<" "<< r <<"]\n";\r
- *pdf_alpha << "/Extend [true true]\n";\r
- *pdf_alpha << "/Domain [0 1]\n";\r
- *pdf_alpha << "/Function <<\n/FunctionType 3\n/Functions\n[\n";\r
-\r
- for (gint i = 0; unsigned(i) < rg->vector.stops.size() - 1; i++) {\r
- *pdf_alpha << "<<\n/FunctionType 2\n/Domain [0 1]\n";\r
- *pdf_alpha << "/C0 [" << rg->vector.stops[i].opacity << "]\n";\r
- *pdf_alpha << "/C1 [" << rg->vector.stops[i+1].opacity << "]\n";\r
- *pdf_alpha << "/N 1\n>>\n";\r
- }\r
- *pdf_alpha << "]\n/Domain [0 1]\n";\r
- *pdf_alpha << "/Bounds [ ";\r
-\r
- for (gint i=0;unsigned(i)<rg->vector.stops.size()-2;i++) {\r
- *pdf_alpha << rg->vector.stops[i+1].offset <<" ";\r
- }\r
- *pdf_alpha << "]\n";\r
- *pdf_alpha << "/Encode [ ";\r
- for (gint i=0;unsigned(i)<rg->vector.stops.size()-1;i++) {\r
- *pdf_alpha << "0 1 ";\r
- }\r
- *pdf_alpha << "]\n";\r
- *pdf_alpha << ">>\n>>\n";\r
- \r
- \r
- *pdf_smask << "<< /Type /Mask\n";\r
- *pdf_smask << " /S /Alpha\n";\r
- *pdf_smask << " /BC [0.0]\n";\r
- *pdf_smask << " /G " << pdf_xobj->get_id() << " 0 R\n";\r
- *pdf_smask << ">>\n";\r
-\r
- \r
- *pdf_xobj << "<< /Type /XObject\n";\r
- *pdf_xobj << " /Subtype /Form\n";\r
- *pdf_xobj << " /FormType 1\n";\r
- *pdf_xobj << " /BBox ["\r
- << pbox->x0 << " "\r
- << pbox->y0 << " "\r
- << pbox->x1 << " "\r
- << pbox->y1 << "]\n";\r
- *pdf_xobj << " /Group\n";\r
- *pdf_xobj << " << /Type /Group\n";\r
- *pdf_xobj << " /S /Transparency\n";\r
- *pdf_xobj << " /CS /DeviceGray \n";\r
- *pdf_xobj << " >>\n";\r
- *pdf_xobj << " /Resources\n";\r
- *pdf_xobj << " <<\n";\r
- *pdf_xobj << " /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n";\r
- *pdf_xobj << " /Shading << "\r
- << pdf_alpha->get_name() << " "\r
- << pdf_alpha->get_id() << " 0 R >>\n";\r
- *pdf_xobj << " >>\n";\r
- \r
- Inkscape::SVGOStringStream os_tmp;\r
- os_tmp.setf(std::ios::fixed);\r
- \r
- os_tmp << "q\n"\r
- << pbox->x0 << " " << pbox->y0 << " m\n"\r
- << pbox->x1 << " " << pbox->y0 << " l\n"\r
- << pbox->x1 << " " << pbox->y1 << " l\n"\r
- << pbox->x0 << " " << pbox->y1 << " l\n"\r
- << pbox->x0 << " " << pbox->y0 << " l\n"\r
- << "h\n"\r
- << "W* n\n";\r
- \r
- SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));\r
- if (g->gradientTransform_set) {\r
- os_tmp << g->gradientTransform[0] << " "\r
- << g->gradientTransform[1] << " "\r
- << g->gradientTransform[2] << " "\r
- << g->gradientTransform[3] << " "\r
- << g->gradientTransform[4] << " "\r
- << g->gradientTransform[5] << " cm\n"; \r
- }\r
- \r
- os_tmp << pdf_alpha->get_name() << " sh\n";\r
- os_tmp << "Q\n";\r
- *pdf_xobj << " /Length " << os_tmp.str().length() << "\n";\r
- *pdf_xobj << ">>\n";\r
- *pdf_xobj << "stream\n";\r
- *pdf_xobj << os_tmp.str().c_str();\r
- *pdf_xobj << "endstream\n";\r
-\r
-\r
- pdf_file->end_resource(pdf_alpha);\r
- pdf_file->end_resource(pdf_smask);\r
- pdf_file->end_resource(pdf_xobj);\r
- }\r
- \r
- *pdf_gstate << ">>\n";\r
- \r
- os << pdf_gstate->get_name() << " gs\n";\r
- \r
- pdf_file->end_resource(pdf_gstate);\r
- }\r
- }\r
- }\r
-}\r
-\r
-void\r
-PrintPDF::print_fill_style(SVGOStringStream &os, SPStyle const *const style, NRRect const *pbox)\r
-{\r
- g_return_if_fail( style->fill.type == SP_PAINT_TYPE_COLOR\r
- || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER\r
- && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) );\r
- \r
- if (style->fill.type == SP_PAINT_TYPE_COLOR) {\r
- float rgb[3];\r
- sp_color_get_rgb_floatv(&style->fill.value.color, rgb);\r
-\r
- os << rgb[0] << " " << rgb[1] << " " << rgb[2] << " rg\n";\r
- } else {\r
- g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER\r
- && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );\r
-\r
- if (SP_IS_LINEARGRADIENT (SP_STYLE_FILL_SERVER (style))) {\r
-\r
- SPLinearGradient *lg=SP_LINEARGRADIENT(SP_STYLE_FILL_SERVER (style));\r
- sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built\r
-\r
- NR::Point p1 (lg->x1.computed, lg->y1.computed);\r
- NR::Point p2 (lg->x2.computed, lg->y2.computed);\r
- if (pbox && SP_GRADIENT(lg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {\r
- // convert to userspace\r
- NR::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0);\r
- p1 *= bbox2user;\r
- p2 *= bbox2user;\r
- }\r
-\r
- PdfObject *pdf_shade = pdf_file->begin_resource(pdf_shading);\r
-\r
- *pdf_shade << "<<\n/ShadingType 2\n/ColorSpace /DeviceRGB\n";\r
- *pdf_shade << "/Coords [" << p1[NR::X] << " " << p1[NR::Y] << " " << p2[NR::X] << " " << p2[NR::Y] <<"]\n";\r
- *pdf_shade << "/Extend [true true]\n";\r
- *pdf_shade << "/Domain [0 1]\n";\r
- *pdf_shade << "/Function <<\n/FunctionType 3\n/Functions\n[\n";\r
-\r
- for (gint i = 0; unsigned(i) < lg->vector.stops.size() - 1; i++) {\r
- float rgb[3];\r
- sp_color_get_rgb_floatv(&lg->vector.stops[i].color, rgb);\r
- *pdf_shade << "<<\n/FunctionType 2\n/Domain [0 1]\n";\r
- *pdf_shade << "/C0 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n";\r
- sp_color_get_rgb_floatv(&lg->vector.stops[i+1].color, rgb);\r
- *pdf_shade << "/C1 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n";\r
- *pdf_shade << "/N 1\n>>\n";\r
- }\r
- *pdf_shade << "]\n/Domain [0 1]\n";\r
- *pdf_shade << "/Bounds [ ";\r
- for (gint i=0;unsigned(i)<lg->vector.stops.size()-2;i++) {\r
- *pdf_shade << lg->vector.stops[i+1].offset <<" ";\r
- }\r
- *pdf_shade << "]\n";\r
- *pdf_shade << "/Encode [ ";\r
- for (gint i=0;unsigned(i)<lg->vector.stops.size()-1;i++) {\r
- *pdf_shade << "0 1 ";\r
- }\r
- *pdf_shade << "]\n";\r
- *pdf_shade << ">>\n>>\n";\r
- os << pdf_shade->get_name() << " ";\r
-\r
- pdf_file->end_resource(pdf_shade);\r
- } else if (SP_IS_RADIALGRADIENT (SP_STYLE_FILL_SERVER (style))) {\r
-\r
- SPRadialGradient *rg=SP_RADIALGRADIENT(SP_STYLE_FILL_SERVER (style));\r
- sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built\r
-\r
- NR::Point c (rg->cx.computed, rg->cy.computed);\r
- NR::Point f (rg->fx.computed, rg->fy.computed);\r
- double r = rg->r.computed;\r
-\r
- NR::Coord const df = hypot(f[NR::X] - c[NR::X], f[NR::Y] - c[NR::Y]);\r
- if (df >= r) {\r
- f[NR::X] = c[NR::X] + (f[NR::X] - c[NR::X] ) * r / (float) df;\r
- f[NR::Y] = c[NR::Y] + (f[NR::Y] - c[NR::Y] ) * r / (float) df;\r
- }\r
-\r
- if (pbox && SP_GRADIENT(rg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {\r
- // convert to userspace\r
- NR::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0);\r
- c *= bbox2user;\r
- f *= bbox2user;\r
- r *= bbox2user.expansion();\r
- }\r
-\r
- PdfObject *pdf_shade = pdf_file->begin_resource(pdf_shading);\r
-\r
- *pdf_shade << "<<\n/ShadingType 3\n/ColorSpace /DeviceRGB\n";\r
- *pdf_shade << "/Coords ["<< f[NR::X] <<" "<< f[NR::Y] <<" 0 "<< c[NR::X] <<" "<< c[NR::Y] <<" "<< r <<"]\n";\r
- *pdf_shade << "/Extend [true true]\n";\r
- *pdf_shade << "/Domain [0 1]\n";\r
- *pdf_shade << "/Function <<\n/FunctionType 3\n/Functions\n[\n";\r
-\r
- for (gint i = 0; unsigned(i) < rg->vector.stops.size() - 1; i++) {\r
- float rgb[3];\r
- sp_color_get_rgb_floatv(&rg->vector.stops[i].color, rgb);\r
- *pdf_shade << "<<\n/FunctionType 2\n/Domain [0 1]\n";\r
- *pdf_shade << "/C0 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n";\r
- sp_color_get_rgb_floatv(&rg->vector.stops[i+1].color, rgb);\r
- *pdf_shade << "/C1 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n";\r
- *pdf_shade << "/N 1\n>>\n";\r
- }\r
- *pdf_shade << "]\n/Domain [0 1]\n";\r
- *pdf_shade << "/Bounds [ ";\r
-\r
- for (gint i=0;unsigned(i)<rg->vector.stops.size()-2;i++) {\r
- *pdf_shade << rg->vector.stops[i+1].offset <<" ";\r
- }\r
- *pdf_shade << "]\n";\r
- *pdf_shade << "/Encode [ ";\r
- for (gint i=0;unsigned(i)<rg->vector.stops.size()-1;i++) {\r
- *pdf_shade << "0 1 ";\r
- }\r
- *pdf_shade << "]\n";\r
- *pdf_shade << ">>\n>>\n";\r
-\r
- os << pdf_shade->get_name() << " ";\r
-\r
- pdf_file->end_resource(pdf_shade);\r
- }\r
- }\r
-}\r
-\r
-void\r
-PrintPDF::print_stroke_style(SVGOStringStream &os, SPStyle const *style)\r
-{\r
- float rgb[3];\r
- \r
- sp_color_get_rgb_floatv(&style->stroke.value.color, rgb);\r
- os << rgb[0] << " " << rgb[1] << " " << rgb[2] << " RG\n";\r
- \r
- float alpha = 1.0;\r
- alpha *= SP_SCALE24_TO_FLOAT(style->stroke_opacity.value);\r
- alpha *= _pushed_alphas.back();\r
-\r
- if (alpha != 1.0) {\r
- PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate);\r
- *pdf_alpha << "<< /Type /ExtGState\n";\r
- *pdf_alpha << " /CA " << alpha << "\n";\r
- *pdf_alpha << " /AIS false\n";\r
- *pdf_alpha << ">>\n";\r
- \r
- os << pdf_alpha->get_name() << " gs\n";\r
- \r
- pdf_file->end_resource(pdf_alpha);\r
- }\r
-\r
- // There are rare cases in which for a solid line stroke_dasharray_set is true. To avoid\r
- // invalid PS-lines such as "[0.0000000 0.0000000] 0.0000000 setdash", which should be "[] 0 setdash",\r
- // we first check if all components of stroke_dash.dash are 0.\r
- bool LineSolid = true;\r
- if (style->stroke_dash.n_dash &&\r
- style->stroke_dash.dash )\r
- {\r
- int i = 0;\r
- while (LineSolid && (i < style->stroke_dash.n_dash)) {\r
- if (style->stroke_dash.dash[i] > 0.00000001)\r
- LineSolid = false;\r
- i++;\r
- }\r
- if (!LineSolid) {\r
- os << "[";\r
- for (i = 0; i < style->stroke_dash.n_dash; i++) {\r
- if (i > 0) {\r
- os << " ";\r
- }\r
- os << style->stroke_dash.dash[i];\r
- }\r
- os << "] " << style->stroke_dash.offset << " d\n";\r
- } else {\r
- os << "[] 0 d\n";\r
- }\r
- } else {\r
- os << "[] 0 d\n";\r
- }\r
-\r
- os << style->stroke_width.computed << " w\n";\r
- os << style->stroke_linejoin.computed << " j\n";\r
- os << style->stroke_linecap.computed << " J\n";\r
- os <<\r
- ( style->stroke_miterlimit.value > 1 ?\r
- style->stroke_miterlimit.value : 1 ) << " M\n";\r
-}\r
-\r
-\r
-unsigned int\r
-PrintPDF::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *const style,\r
- NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)\r
-{\r
- Inkscape::SVGOStringStream os;\r
- os.setf(std::ios::fixed);\r
-\r
- if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.\r
- if (_bitmap) return 0;\r
-\r
- if ( style->fill.type == SP_PAINT_TYPE_COLOR ) {\r
- os << "q\n";\r
- print_fill_style(os, style, pbox);\r
- print_fill_alpha(os, style, pbox);\r
- print_bpath(os, bpath->path);\r
- if (style->fill_rule.value == SP_WIND_RULE_EVENODD) {\r
- os << "f*\n";\r
- } else {\r
- os << "f\n";\r
- }\r
- os << "Q\n";\r
- }\r
- else if ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER\r
- && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) )\r
- {\r
- os << "q\n";\r
- print_bpath(os, bpath->path);\r
-\r
- if (style->fill_rule.value == SP_WIND_RULE_EVENODD) {\r
- g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER\r
- && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );\r
- SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));\r
- os << "W* n\n";\r
- print_fill_alpha(os, style, pbox);\r
- if (g->gradientTransform_set) {\r
- os << "q\n";\r
- os << g->gradientTransform[0] << " "\r
- << g->gradientTransform[1] << " "\r
- << g->gradientTransform[2] << " "\r
- << g->gradientTransform[3] << " "\r
- << g->gradientTransform[4] << " "\r
- << g->gradientTransform[5] << " cm\n";\r
- }\r
- print_fill_style(os, style, pbox);\r
- os << "sh\n";\r
- if (g->gradientTransform_set) {\r
- os << "Q\n";\r
- }\r
- } else {\r
- g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER\r
- && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );\r
- SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));\r
- os << "W n\n";\r
- print_fill_alpha(os, style, pbox);\r
- if (g->gradientTransform_set) {\r
- os << "q\n";\r
- os << g->gradientTransform[0] << " "\r
- << g->gradientTransform[1] << " "\r
- << g->gradientTransform[2] << " "\r
- << g->gradientTransform[3] << " "\r
- << g->gradientTransform[4] << " "\r
- << g->gradientTransform[5] << " cm\n"; \r
- }\r
- print_fill_style(os, style, pbox);\r
- os << "sh\n";\r
- if (g->gradientTransform_set) {\r
- os << "Q\n";\r
- }\r
- }\r
-\r
- os << "Q\n";\r
- } \r
-\r
- pdf_file->puts(os);\r
- return 0;\r
-}\r
-\r
-\r
-unsigned int\r
-PrintPDF::stroke(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *style,\r
- NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)\r
-{\r
- if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.\r
- if (_bitmap) return 0;\r
-\r
- if (style->stroke.type == SP_PAINT_TYPE_COLOR) {\r
- Inkscape::SVGOStringStream os;\r
- os.setf(std::ios::fixed);\r
-\r
- os << "q\n";\r
-\r
- print_stroke_style(os, style);\r
- print_bpath(os, bpath->path);\r
- os << "S\n";\r
-\r
- os << "Q\n";\r
-\r
- pdf_file->puts(os);\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-unsigned int\r
-PrintPDF::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w, unsigned int h, unsigned int rs,\r
- NRMatrix const *transform, SPStyle const *style)\r
-{\r
- if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.\r
- if (_bitmap) return 0;\r
- \r
- return print_image(_stream, px, w, h, rs, transform);\r
-}\r
-\r
-char const *\r
-PrintPDF::PSFontName(SPStyle const *style)\r
-{\r
- font_instance *tf = (font_factory::Default())->Face(style->text->font_family.value, font_style_to_pos(*style));\r
-\r
- char const *n;\r
- char name_buf[256];\r
-\r
- if (tf) {\r
- tf->PSName(name_buf, sizeof(name_buf));\r
- n = name_buf;\r
- tf->Unref();\r
- } else {\r
- // this system does not have this font, so just use the name from SVG in the hope that PS interpreter will make sense of it\r
- bool i = (style->font_style.value == SP_CSS_FONT_STYLE_ITALIC);\r
- bool o = (style->font_style.value == SP_CSS_FONT_STYLE_OBLIQUE);\r
- bool b = (style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLD) ||\r
- (style->font_weight.value >= SP_CSS_FONT_WEIGHT_500 && style->font_weight.value <= SP_CSS_FONT_WEIGHT_900);\r
-\r
- n = g_strdup_printf("%s%s%s%s",\r
- g_strdelimit(style->text->font_family.value, " ", '-'),\r
- (b || i || o) ? "-" : "",\r
- (b) ? "Bold" : "",\r
- (i) ? "Italic" : ((o) ? "Oblique" : "") );\r
- }\r
-\r
- return g_strdup(n);\r
-}\r
-\r
-\r
-unsigned int\r
-PrintPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point p,\r
- SPStyle const *const style)\r
-{\r
- if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.\r
- if (_bitmap) return 0;\r
-\r
- Inkscape::SVGOStringStream os;\r
- os.setf(std::ios::fixed);\r
-\r
- return 0;\r
- \r
- // Escape chars\r
- Inkscape::SVGOStringStream escaped_text;\r
- escaped_text.setf(std::ios::fixed);\r
- \r
- escaped_text << std::oct;\r
- for (gchar const *p_text = text ; *p_text ; p_text = g_utf8_next_char(p_text)) {\r
- gunichar const c = g_utf8_get_char(p_text);\r
- if (c == '\\' || c == ')' || c == '(')\r
- escaped_text << '\\' << static_cast<char>(c);\r
- else if (c >= 0x80)\r
- escaped_text << '\\' << c;\r
- else\r
- escaped_text << static_cast<char>(c);\r
- }\r
-\r
- os << "gsave\n";\r
-\r
- // set font\r
- char const *fn = PSFontName(style);\r
- if (_latin1_encoded_fonts.find(fn) == _latin1_encoded_fonts.end()) {\r
- if (!_newlatin1font_proc_defined) {\r
- // input: newfontname, existingfontname\r
- // output: new font object, also defined to newfontname\r
- os << "/newlatin1font " // name of the proc\r
- "{findfont dup length dict copy " // load the font and create a copy of it\r
- "dup /Encoding ISOLatin1Encoding put " // change the encoding in the copy\r
- "definefont} def\n"; // create the new font and leave it on the stack, define the proc\r
- _newlatin1font_proc_defined = true;\r
- }\r
- os << "/" << fn << "-ISOLatin1 /" << fn << " newlatin1font\n";\r
- _latin1_encoded_fonts.insert(fn);\r
- } else\r
- os << "/" << fn << "-ISOLatin1 findfont\n";\r
- os << style->font_size.computed << " scalefont\n";\r
- os << "setfont\n";\r
- g_free((void *) fn);\r
-\r
- if ( style->fill.type == SP_PAINT_TYPE_COLOR\r
- || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER\r
- && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) )\r
- {\r
- // set fill style\r
- print_fill_style(os, style, NULL);\r
- // FIXME: we don't know the pbox of text, so have to pass NULL. This means gradients with\r
- // bbox units won't work with text. However userspace gradients don't work with text either\r
- // (text is black) for some reason.\r
-\r
- os << "newpath\n";\r
- os << p[NR::X] << " " << p[NR::Y] << " moveto\n";\r
- os << "(" << escaped_text.str() << ") show\n";\r
- }\r
-\r
- if (style->stroke.type == SP_PAINT_TYPE_COLOR) {\r
-\r
- // set stroke style\r
- print_stroke_style(os, style);\r
-\r
- // paint stroke\r
- os << "newpath\n";\r
- os << p[NR::X] << " " << p[NR::Y] << " moveto\n";\r
- os << "(" << escaped_text.str() << ") false charpath stroke\n";\r
- }\r
-\r
- os << "grestore\n";\r
-\r
- fprintf(_stream, "%s", os.str().c_str());\r
-\r
- return 0;\r
-}\r
-\r
-\r
-\r
-/* PDF helpers */\r
-\r
-void\r
-PrintPDF::print_bpath(SVGOStringStream &os, NArtBpath const *bp)\r
-{\r
- bool closed = false;\r
- while (bp->code != NR_END) {\r
- switch (bp->code) {\r
- case NR_MOVETO:\r
- if (closed) {\r
- os << "h\n";\r
- }\r
- closed = true;\r
- os << bp->x3 << " " << bp->y3 << " m\n";\r
- break;\r
- case NR_MOVETO_OPEN:\r
- if (closed) {\r
- os << "h\n";\r
- }\r
- closed = false;\r
- os << bp->x3 << " " << bp->y3 << " m\n";\r
- break;\r
- case NR_LINETO:\r
- os << bp->x3 << " " << bp->y3 << " l\n";\r
- break;\r
- case NR_CURVETO:\r
- os << bp->x1 << " " << bp->y1 << " "\r
- << bp->x2 << " " << bp->y2 << " "\r
- << bp->x3 << " " << bp->y3 << " c\n";\r
- break;\r
- default:\r
- break;\r
- }\r
- bp += 1;\r
- }\r
- if (closed) {\r
- os << "h\n";\r
- }\r
-}\r
-\r
-/* The following code is licensed under GNU GPL.\r
-** The packbits, ascii85 and imaging printing code\r
-** is from the gimp's postscript.c.\r
-*/\r
-\r
-/**\r
-* \param nin Number of bytes of source data.\r
-* \param src Source data.\r
-* \param nout Number of output bytes.\r
-* \param dst Buffer for output.\r
-*/\r
-void\r
-PrintPDF::compress_packbits(int nin,\r
- guchar *src,\r
- int *nout,\r
- guchar *dst)\r
-\r
-{\r
- register guchar c;\r
- int nrepeat, nliteral;\r
- guchar *run_start;\r
- guchar *start_dst = dst;\r
- guchar *last_literal = NULL;\r
-\r
- for (;;) {\r
- if (nin <= 0) break;\r
-\r
- run_start = src;\r
- c = *run_start;\r
-\r
- /* Search repeat bytes */\r
- if ((nin > 1) && (c == src[1])) {\r
- nrepeat = 1;\r
- nin -= 2;\r
- src += 2;\r
- while ((nin > 0) && (c == *src)) {\r
- nrepeat++;\r
- src++;\r
- nin--;\r
- if (nrepeat == 127) break; /* Maximum repeat */\r
- }\r
-\r
- /* Add two-byte repeat to last literal run ? */\r
- if ( (nrepeat == 1)\r
- && (last_literal != NULL) && (((*last_literal)+1)+2 <= 128) )\r
- {\r
- *last_literal += 2;\r
- *(dst++) = c;\r
- *(dst++) = c;\r
- continue;\r
- }\r
-\r
- /* Add repeat run */\r
- *(dst++) = (guchar)((-nrepeat) & 0xff);\r
- *(dst++) = c;\r
- last_literal = NULL;\r
- continue;\r
- }\r
- /* Search literal bytes */\r
- nliteral = 1;\r
- nin--;\r
- src++;\r
-\r
- for (;;) {\r
- if (nin <= 0) break;\r
-\r
- if ((nin >= 2) && (src[0] == src[1])) /* A two byte repeat ? */\r
- break;\r
-\r
- nliteral++;\r
- nin--;\r
- src++;\r
- if (nliteral == 128) break; /* Maximum literal run */\r
- }\r
-\r
- /* Could be added to last literal run ? */\r
- if ((last_literal != NULL) && (((*last_literal)+1)+nliteral <= 128)) {\r
- *last_literal += nliteral;\r
- } else {\r
- last_literal = dst;\r
- *(dst++) = (guchar)(nliteral-1);\r
- }\r
- while (nliteral-- > 0) *(dst++) = *(run_start++);\r
- }\r
- *nout = dst - start_dst;\r
-}\r
-\r
-void\r
-PrintPDF::ascii85_init(void)\r
-{\r
- ascii85_len = 0;\r
- ascii85_linewidth = 0;\r
-}\r
-\r
-void\r
-PrintPDF::ascii85_flush(SVGOStringStream &os)\r
-{\r
- char c[5];\r
- bool const zero_case = (ascii85_buf == 0);\r
- static int const max_linewidth = 75;\r
-\r
- for (int i = 4; i >= 0; i--) {\r
- c[i] = (ascii85_buf % 85) + '!';\r
- ascii85_buf /= 85;\r
- }\r
- /* check for special case: "!!!!!" becomes "z", but only if not\r
- * at end of data. */\r
- if (zero_case && (ascii85_len == 4)) {\r
- if (ascii85_linewidth >= max_linewidth) {\r
- os << '\n';\r
- ascii85_linewidth = 0;\r
- }\r
- os << 'z';\r
- ascii85_linewidth++;\r
- } else {\r
- for (int i = 0; i < ascii85_len+1; i++) {\r
- if ((ascii85_linewidth >= max_linewidth) && (c[i] != '%')) {\r
- os << '\n';\r
- ascii85_linewidth = 0;\r
- }\r
- os << c[i];\r
- ascii85_linewidth++;\r
- }\r
- }\r
-\r
- ascii85_len = 0;\r
- ascii85_buf = 0;\r
-}\r
-\r
-inline void\r
-PrintPDF::ascii85_out(guchar byte, SVGOStringStream &os)\r
-{\r
- if (ascii85_len == 4)\r
- ascii85_flush(os);\r
-\r
- ascii85_buf <<= 8;\r
- ascii85_buf |= byte;\r
- ascii85_len++;\r
-}\r
-\r
-void\r
-PrintPDF::ascii85_nout(int n, guchar *uptr, SVGOStringStream &os)\r
-{\r
- while (n-- > 0) {\r
- ascii85_out(*uptr, os);\r
- uptr++;\r
- }\r
-}\r
-\r
-void\r
-PrintPDF::ascii85_done(SVGOStringStream &os)\r
-{\r
- if (ascii85_len) {\r
- /* zero any unfilled buffer portion, then flush */\r
- ascii85_buf <<= (8 * (4-ascii85_len));\r
- ascii85_flush(os);\r
- }\r
-\r
- os << "~>\n";\r
-}\r
-\r
-unsigned int\r
-PrintPDF::print_image(FILE *ofp, guchar *px, unsigned int width, unsigned int height, unsigned int rs,\r
- NRMatrix const *transform)\r
-{\r
- Inkscape::SVGOStringStream os;\r
- os.setf(std::ios::fixed);\r
-\r
- PdfObject *pdf_image = pdf_file->begin_resource(pdf_xobject);\r
- PdfObject *pdf_image_len = pdf_file->begin_resource(pdf_none);\r
- \r
- PdfObject *pdf_smask = pdf_file->begin_resource(pdf_xobject);\r
- PdfObject *pdf_smask_len = pdf_file->begin_resource(pdf_none);\r
-\r
-\r
- os << "q\n";\r
- os << transform->c[0] << " "\r
- << transform->c[1] << " "\r
- << transform->c[2] << " "\r
- << transform->c[3] << " "\r
- << transform->c[4] << " "\r
- << transform->c[5] << " cm\n";\r
- os << pdf_image->get_name() << " Do\n";\r
- os << "Q\n";\r
- pdf_file->puts(os);\r
-\r
-\r
- *pdf_image << "<< /Type /XObject\n";\r
- *pdf_image << " /Subtype /Image\n";\r
- *pdf_image << " /Width " << width << "\n";\r
- *pdf_image << " /Height " << height << "\n";\r
- *pdf_image << " /ColorSpace /DeviceRGB\n";\r
- *pdf_image << " /BitsPerComponent 8\n";\r
- *pdf_image << " /Length " << pdf_image_len->get_id() << " 0 R\n";\r
- *pdf_image << " /Filter /ASCIIHexDecode\n";\r
- *pdf_image << " /SMask " << pdf_smask->get_id() << " 0 R\n";\r
- *pdf_image << ">>\n";\r
-\r
- *pdf_image << "stream\n";\r
-\r
-\r
- *pdf_smask << "<< /Type /XObject\n";\r
- *pdf_smask << " /Subtype /Image\n";\r
- *pdf_smask << " /Width " << width << "\n";\r
- *pdf_smask << " /Height " << height << "\n";\r
- *pdf_smask << " /ColorSpace /DeviceGray\n";\r
- *pdf_smask << " /BitsPerComponent 8\n";\r
- *pdf_smask << " /Length " << pdf_smask_len->get_id() << " 0 R\n";\r
- *pdf_smask << " /Filter /ASCIIHexDecode\n";\r
- *pdf_smask << ">>\n";\r
-\r
- *pdf_smask << "stream\n";\r
-\r
-\r
- unsigned long image_len = pdf_image->get_length();\r
- unsigned long smask_len = pdf_smask->get_length();\r
-\r
- int image_chars = 0;\r
- int smask_chars = 0;\r
-\r
- for (unsigned i = 0; i < height; i++) {\r
- guchar const *const src = px + i * rs;\r
-\r
- for (unsigned j = 0; j < width; j++) {\r
- char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};\r
- guchar const *src_ptr = src + 4*j;\r
-\r
- /* Iterate over RGB */\r
- for (int rgb = 0; rgb < 3; rgb++) {\r
- guchar val = *(src_ptr + rgb);\r
-\r
- *pdf_image << hex[val / 16];\r
- *pdf_image << hex[val % 16];\r
-\r
- image_chars += 2;\r
- if (image_chars >= 78) {\r
- *pdf_image << "\n";\r
- image_chars = 0;\r
- }\r
- }\r
-\r
- guchar alpha = *(src_ptr + 3);\r
-\r
- *pdf_smask << hex[alpha / 16];\r
- *pdf_smask << hex[alpha % 16];\r
- \r
- smask_chars += 2;\r
- if (smask_chars >= 78) {\r
- *pdf_smask << "\n";\r
- smask_chars = 0;\r
- }\r
- }\r
- }\r
-\r
-\r
- *pdf_image << ">\n";\r
- image_len = pdf_image->get_length() - image_len;\r
-\r
- *pdf_image << "endstream\n";\r
- pdf_file->end_resource(pdf_image);\r
-\r
- *pdf_image_len << image_len << "\n";\r
- pdf_file->end_resource(pdf_image_len);\r
-\r
-\r
- *pdf_smask << ">\n";\r
- smask_len = pdf_smask->get_length() - smask_len;\r
-\r
- *pdf_smask << "endstream\n";\r
- pdf_file->end_resource(pdf_smask);\r
-\r
- *pdf_smask_len << smask_len << "\n";\r
- pdf_file->end_resource(pdf_smask_len);\r
-\r
-\r
- return 0;\r
-}\r
-\r
-bool\r
-PrintPDF::textToPath(Inkscape::Extension::Print * ext)\r
-{\r
- return ext->get_param_bool("textToPath");\r
-}\r
-\r
-#include "clear-n_.h"\r
-\r
-void\r
-PrintPDF::init(void)\r
-{\r
- /* PDF print */\r
- (void) Inkscape::Extension::build_from_mem(\r
- "<inkscape-extension>\n"\r
- "<name>" N_("PDF Print") "</name>\n"\r
- "<id>" SP_MODULE_KEY_PRINT_PDF "</id>\n"\r
- "<param name=\"bitmap\" type=\"boolean\">FALSE</param>\n"\r
- "<param name=\"resolution\" type=\"string\">72</param>\n"\r
- "<param name=\"destination\" type=\"string\">| lp</param>\n"\r
- "<param name=\"pageBoundingBox\" type=\"boolean\">TRUE</param>\n"\r
- "<param name=\"textToPath\" type=\"boolean\">TRUE</param>\n"\r
- "<print/>\n"\r
- "</inkscape-extension>", new PrintPDF());\r
-}\r
-\r
-\r
-} /* namespace Internal */\r
-} /* namespace Extension */\r
-} /* namespace Inkscape */\r
-\r
-/* End of GNU GPL code */\r
-\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
diff --git a/src/extension/internal/pdf.h b/src/extension/internal/pdf.h
+++ /dev/null
@@ -1,114 +0,0 @@
-#ifndef EXTENSION_INTERNAL_PDF_H_SEEN\r
-#define EXTENSION_INTERNAL_PDF_H_SEEN\r
-\r
-/*\r
- * Authors:\r
- * Lauris Kaplinski <lauris@kaplinski.com>\r
- * Ted Gould <ted@gould.cx>\r
- * Ulf Erikson <ulferikson@users.sf.net>\r
- *\r
- * Lauris' original code is in the public domain.\r
- * Ted's changes are licensed under the GNU GPL.\r
- */\r
-\r
-#include <config.h>\r
-#include "extension/extension.h"\r
-#include "extension/implementation/implementation.h"\r
-#include <set>\r
-#include <string>\r
-\r
-#include "libnr/nr-path.h"\r
-\r
-#include "svg/stringstream.h"\r
-\r
-class PdfFile;\r
-class PdfObject;\r
-\r
-namespace Inkscape {\r
-namespace Extension {\r
-namespace Internal {\r
-\r
-class PrintPDF : public Inkscape::Extension::Implementation::Implementation {\r
- float _width;\r
- float _height;\r
- FILE *_stream;\r
- PdfFile *pdf_file;\r
- PdfObject *doc_info;\r
- PdfObject *page_stream;\r
- std::vector<float> _pushed_alphas;\r
- unsigned short _dpi;\r
- bool _bitmap;\r
- std::set<std::string> _latin1_encoded_fonts;\r
- bool _newlatin1font_proc_defined;\r
-\r
- void print_bpath(SVGOStringStream &os, NArtBpath const *bp);\r
-\r
- void print_fill_style(SVGOStringStream &os, SPStyle const *style, NRRect const *pbox);\r
- void print_fill_alpha(SVGOStringStream &os, SPStyle const *style, NRRect const *pbox);\r
- void print_stroke_style(SVGOStringStream &os, SPStyle const *style);\r
-\r
- char const *PSFontName(SPStyle const *style);\r
-\r
- unsigned int print_image(FILE *ofp, guchar *px, unsigned int width, unsigned int height, unsigned int rs,\r
- NRMatrix const *transform);\r
- void compress_packbits(int nin, guchar *src, int *nout, guchar *dst);\r
-\r
- /* ASCII 85 variables */\r
- guint32 ascii85_buf;\r
- int ascii85_len;\r
- int ascii85_linewidth;\r
- /* ASCII 85 Functions */\r
- void ascii85_init(void);\r
- void ascii85_flush(SVGOStringStream &os);\r
- inline void ascii85_out(guchar byte, SVGOStringStream &os);\r
- void ascii85_nout(int n, guchar *uptr, SVGOStringStream &os);\r
- void ascii85_done(SVGOStringStream &os);\r
-\r
-\r
-public:\r
- PrintPDF(void);\r
- virtual ~PrintPDF(void);\r
-\r
- /* Print functions */\r
- virtual unsigned int setup(Inkscape::Extension::Print *module);\r
- /*\r
- virtual unsigned int set_preview(Inkscape::Extension::Print *module);\r
- */\r
-\r
- virtual unsigned int begin(Inkscape::Extension::Print *module, SPDocument *doc);\r
- virtual unsigned int finish(Inkscape::Extension::Print *module);\r
-\r
- /* Rendering methods */\r
- virtual unsigned int bind(Inkscape::Extension::Print *module, NRMatrix const *transform, float opacity);\r
- virtual unsigned int release(Inkscape::Extension::Print *module);\r
- virtual unsigned int comment(Inkscape::Extension::Print *module, char const *comment);\r
- virtual unsigned int fill(Inkscape::Extension::Print *module, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *style,\r
- NRRect const *pbox, NRRect const *dbox, NRRect const *bbox);\r
- virtual unsigned int stroke(Inkscape::Extension::Print *module, NRBPath const *bpath, NRMatrix const *transform, SPStyle const *style,\r
- NRRect const *pbox, NRRect const *dbox, NRRect const *bbox);\r
- virtual unsigned int image(Inkscape::Extension::Print *module, unsigned char *px, unsigned int w, unsigned int h, unsigned int rs,\r
- NRMatrix const *transform, SPStyle const *style);\r
- virtual unsigned int text(Inkscape::Extension::Print *module, char const *text,\r
- NR::Point p, SPStyle const *style);\r
-\r
- bool textToPath(Inkscape::Extension::Print *ext);\r
- static void init(void);\r
-};\r
-\r
-} /* namespace Internal */\r
-} /* namespace Extension */\r
-} /* namespace Inkscape */\r
-\r
-\r
-#endif /* !EXTENSION_INTERNAL_PDF_H_SEEN */\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r