diff options
Diffstat (limited to 'src/extension/internal')
23 files changed, 123 insertions, 3815 deletions
diff --git a/src/extension/internal/Makefile_insert b/src/extension/internal/Makefile_insert index 1de46034e..ee431ee48 100644 --- a/src/extension/internal/Makefile_insert +++ b/src/extension/internal/Makefile_insert @@ -98,16 +98,8 @@ extension_internal_libinternal_a_SOURCES = \ extension/internal/svg.cpp \ extension/internal/svgz.h \ extension/internal/svgz.cpp \ - extension/internal/ps.h \ - extension/internal/ps.cpp \ - extension/internal/ps-out.h \ - extension/internal/ps-out.cpp \ - extension/internal/pdf-cairo.cpp \ - extension/internal/pdf-cairo.h \ extension/internal/pdf-input-cairo.cpp \ extension/internal/pdf-input-cairo.h \ - extension/internal/cairo-pdf-out.h \ - extension/internal/cairo-pdf-out.cpp \ extension/internal/cairo-ps-out.h \ extension/internal/cairo-ps-out.cpp \ extension/internal/cairo-render-context.h \ @@ -118,8 +110,6 @@ extension_internal_libinternal_a_SOURCES = \ extension/internal/cairo-renderer-pdf-out.cpp \ extension/internal/cairo-png-out.h \ extension/internal/cairo-png-out.cpp \ - extension/internal/eps-out.h \ - extension/internal/eps-out.cpp \ extension/internal/javafx-out.cpp \ extension/internal/javafx-out.h \ extension/internal/gdkpixbuf-input.h \ diff --git a/src/extension/internal/cairo-pdf-out.cpp b/src/extension/internal/cairo-pdf-out.cpp deleted file mode 100644 index ac598b9a0..000000000 --- a/src/extension/internal/cairo-pdf-out.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/* - * A quick hack to use the print output to write out a file. This - * then makes 'save as...' PDF. - * - * Authors: - * Ted Gould <ted@gould.cx> - * Ulf Erikson <ulferikson@users.sf.net> - * - * Copyright (C) 2004-2006 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#ifdef HAVE_CAIRO_PDF - -#include "cairo-pdf-out.h" -#include <print.h> -#include "extension/system.h" -#include "extension/print.h" -#include "extension/db.h" -#include "extension/output.h" -#include "display/nr-arena.h" -#include "display/nr-arena-item.h" -#include "sp-path.h" - -namespace Inkscape { -namespace Extension { -namespace Internal { - -bool -CairoPdfOutput::check (Inkscape::Extension::Extension * module) -{ - if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PDF)) - return FALSE; - - return TRUE; -} - - -static unsigned int -pdf_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int pdf_level, bool texttopath, bool filtertobitmap) -{ - Inkscape::Extension::Print *mod; - SPPrintContext context; - gchar const *oldconst; - gchar *oldoutput; - unsigned int ret; - - sp_document_ensure_up_to_date(doc); - - mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_CAIRO_PDF); - oldconst = mod->get_param_string("destination"); - oldoutput = g_strdup(oldconst); - mod->set_param_string("destination", (gchar *)filename); - -/* Start */ - context.module = mod; - /* fixme: This has to go into module constructor somehow */ - /* Create new arena */ - const gchar* exportId = mod->get_param_string("exportId"); - bool exportDrawing = mod->get_param_bool("exportDrawing"); - bool exportCanvas = mod->get_param_bool("exportCanvas"); - if (exportId && strcmp(exportId, "")) { - // we want to export the given item only - mod->base = SP_ITEM(doc->getObjectById(exportId)); - if (exportCanvas) - mod->set_param_bool("pageBoundingBox", TRUE); - else - mod->set_param_bool("pageBoundingBox", FALSE); - } else { - // we want to export the entire document from root - mod->base = SP_ITEM(sp_document_root(doc)); - if (exportDrawing) - mod->set_param_bool("pageBoundingBox", FALSE); - else - mod->set_param_bool("pageBoundingBox", TRUE); - } - mod->arena = NRArena::create(); - mod->dkey = sp_item_display_key_new(1); - mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY); - - /* Print document */ - ret = mod->begin(doc); - if (ret) { - sp_item_invoke_print(mod->base, &context); - ret = mod->finish(); - } - - /* Release arena */ - sp_item_invoke_hide(mod->base, mod->dkey); - mod->base = NULL; - mod->root = NULL; - nr_object_unref((NRObject *) mod->arena); - mod->arena = NULL; -/* end */ - - mod->set_param_string("destination", oldoutput); - g_free(oldoutput); - - return ret; -} - - -/** - \brief This function calls the print system with the filename - \param mod unused - \param doc Document to be saved - \param uri Filename to save to (probably will end in .pdf) - - The most interesting thing that this function does is just attach - an '>' on the front of the filename. This is the syntax used to - tell the printing system to save to file. -*/ -void -CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) -{ - Inkscape::Extension::Extension * ext; - unsigned int ret; - - ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PDF); - if (ext == NULL) - return; - - bool old_textToPath = FALSE; - bool new_textToPath = FALSE; - try { - old_textToPath = ext->get_param_bool("textToPath"); - new_textToPath = mod->get_param_bool("textToPath"); - ext->set_param_bool("textToPath", new_textToPath); - } - catch(...) { - g_warning("Parameter <textToPath> might not exist"); - } - - bool old_blurToBitmap = FALSE; - bool new_blurToBitmap = FALSE; - try { - old_blurToBitmap = ext->get_param_bool("blurToBitmap"); - new_blurToBitmap = mod->get_param_bool("blurToBitmap"); - ext->set_param_bool("blurToBitmap", new_blurToBitmap); - } - catch(...) { - g_warning("Parameter <blurToBitmap> might not exist"); - } - - const gchar* old_exportId = NULL; - const gchar* new_exportId = NULL; - try { - old_exportId = ext->get_param_string("exportId"); - new_exportId = mod->get_param_string("exportId"); - ext->set_param_string("exportId", new_exportId); - } - catch(...) { - g_warning("Parameter <exportId> might not exist"); - } - - bool old_exportDrawing = false; - bool new_exportDrawing = false; - try { - old_exportDrawing = ext->get_param_bool("exportDrawing"); - new_exportDrawing = mod->get_param_bool("exportDrawing"); - ext->set_param_bool("exportDrawing", new_exportDrawing); - } - catch(...) { - g_warning("Parameter <exportDrawing> might not exist"); - } - - bool old_exportCanvas = false; - bool new_exportCanvas = false; - try { - old_exportCanvas = ext->get_param_bool("exportCanvas"); - new_exportCanvas = mod->get_param_bool("exportCanvas"); - ext->set_param_bool("exportCanvas", new_exportCanvas); - } - catch(...) { - g_warning("Parameter <exportCanvas> might not exist"); - } - - gchar * final_name; - final_name = g_strdup_printf("> %s", uri); - ret = pdf_print_document_to_file(doc, final_name, 0, new_textToPath, new_blurToBitmap); - g_free(final_name); - - try { - ext->set_param_bool("blurToBitmap", old_blurToBitmap); - } - catch(...) { - g_warning("Parameter <blurToBitmap> might not exist"); - } - try { - ext->set_param_bool("textToPath", old_textToPath); - } - catch(...) { - g_warning("Parameter <textToPath> might not exist"); - } - try { - ext->set_param_string("exportId", old_exportId); - } - catch(...) { - g_warning("Parameter <exportId> might not exist"); - } - try { - ext->set_param_bool("exportDrawing", old_exportDrawing); - } - catch(...) { - g_warning("Parameter <exportDrawing> might not exist"); - } - try { - ext->set_param_bool("exportCanvas", old_exportCanvas); - } - catch(...) { - g_warning("Parameter <exportCanvas> might not exist"); - } - - if (!ret) - throw Inkscape::Extension::Output::save_failed(); - - return; -} - -#include "clear-n_.h" -/** - \brief A function allocate a copy of this function. - - This is the definition of PDF out. This function just - calls the extension system with the memory allocated XML that - describes the data. -*/ -void -CairoPdfOutput::init (void) -{ - Inkscape::Extension::build_from_mem( - "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" - "<name>" N_("Cairo PDF Output") "</name>\n" - "<id>org.inkscape.output.pdf.cairo</id>\n" - "<param name=\"PDFversion\" gui-text=\"" N_("Restrict to PDF version") "\" type=\"enum\" >\n" - "<_item value='PDF14'>" N_("PDF 1.4") "</_item>\n" - "</param>\n" - "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n" - "<param name=\"blurToBitmap\" gui-text=\"" N_("Convert blur effects to bitmaps") "\" type=\"boolean\">false</param>\n" - "<param name=\"resolution\" gui-text=\"" N_("Preferred resolution (DPI) of bitmaps") "\" type=\"int\" min=\"72\" max=\"2400\">90</param>\n" - "<param name=\"exportDrawing\" gui-text=\"" N_("Export drawing, not page") "\" type=\"boolean\">false</param>\n" - "<param name=\"exportCanvas\" gui-text=\"" N_("Export canvas") "\" type=\"boolean\">false</param>\n" - "<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID") "\" type=\"string\"></param>\n" - "<output>\n" - "<extension>.pdf</extension>\n" - "<mimetype>application/pdf</mimetype>\n" - "<filetypename>" N_("PDF via Cairo (*.pdf)") "</filetypename>\n" - "<filetypetooltip>" N_("PDF File") "</filetypetooltip>\n" - "</output>\n" - "</inkscape-extension>", new CairoPdfOutput()); - - return; -} - -} } } /* namespace Inkscape, Extension, Implementation */ - -#endif /* HAVE_CAIRO_PDF */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/extension/internal/cairo-pdf-out.h b/src/extension/internal/cairo-pdf-out.h deleted file mode 100644 index 42cd9365c..000000000 --- a/src/extension/internal/cairo-pdf-out.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * A quick hack to use the print output to write out a file. This - * then makes 'save as...' PDF. - * - * Authors: - * Ted Gould <ted@gould.cx> - * Ulf Erikson <ulferikson@users.sf.net> - * - * Copyright (C) 2004-2006 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef EXTENSION_INTERNAL_CAIRO_PDF_OUT_H -#define EXTENSION_INTERNAL_CAIRO_PDF_OUT_H - -#include "extension/implementation/implementation.h" - -#ifdef HAVE_CAIRO_PDF - -namespace Inkscape { -namespace Extension { -namespace Internal { - -class CairoPdfOutput : Inkscape::Extension::Implementation::Implementation { - -public: - bool check(Inkscape::Extension::Extension *module); - void save(Inkscape::Extension::Output *mod, - SPDocument *doc, - gchar const *uri); - static void init(); -}; - -} } } /* namespace Inkscape, Extension, Implementation */ - -#endif /* HAVE_CAIRO_PDF */ - -#endif /* !EXTENSION_INTERNAL_CAIRO_PDF_OUT_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/extension/internal/cairo-ps-out.cpp b/src/extension/internal/cairo-ps-out.cpp index 01afec0fc..e33316c94 100644 --- a/src/extension/internal/cairo-ps-out.cpp +++ b/src/extension/internal/cairo-ps-out.cpp @@ -282,7 +282,7 @@ CairoPsOutput::init (void) "<param name=\"areaCanvas\" gui-text=\"" N_("Export area is whole canvas") "\" type=\"boolean\">true</param>\n" "<param name=\"areaDrawing\" gui-text=\"" N_("Export area is the drawing") "\" type=\"boolean\">true</param>\n" "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n" - "<param name=\"blurToBitmap\" gui-text=\"" N_("Convert blur effects to bitmaps") "\" type=\"boolean\">false</param>\n" + "<param name=\"blurToBitmap\" gui-text=\"" N_("Convert blur effects to bitmaps") "\" type=\"boolean\">true</param>\n" "<param name=\"resolution\" gui-text=\"" N_("Preferred resolution (DPI) of bitmaps") "\" type=\"int\" min=\"72\" max=\"2400\">90</param>\n" "<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID") "\" type=\"string\"></param>\n" "<output>\n" @@ -319,7 +319,7 @@ CairoEpsOutput::init (void) "<param name=\"areaCanvas\" gui-text=\"" N_("Export area is whole canvas") "\" type=\"boolean\">true</param>\n" "<param name=\"areaDrawing\" gui-text=\"" N_("Export area is the drawing") "\" type=\"boolean\">true</param>\n" "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n" - "<param name=\"blurToBitmap\" gui-text=\"" N_("Convert blur effects to bitmaps") "\" type=\"boolean\">false</param>\n" + "<param name=\"blurToBitmap\" gui-text=\"" N_("Convert blur effects to bitmaps") "\" type=\"boolean\">true</param>\n" "<param name=\"resolution\" gui-text=\"" N_("Preferred resolution (DPI) of bitmaps") "\" type=\"int\" min=\"72\" max=\"2400\">90</param>\n" "<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID") "\" type=\"string\"></param>\n" "<output>\n" diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp index c82cc7611..cb17002d4 100644 --- a/src/extension/internal/cairo-renderer-pdf-out.cpp +++ b/src/extension/internal/cairo-renderer-pdf-out.cpp @@ -216,7 +216,7 @@ CairoRendererPdfOutput::init (void) "<_item value='PDF14'>" N_("PDF 1.4") "</_item>\n" "</param>\n" "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n" - "<param name=\"blurToBitmap\" gui-text=\"" N_("Convert filter effects to bitmaps") "\" type=\"boolean\">false</param>\n" + "<param name=\"blurToBitmap\" gui-text=\"" N_("Convert filter effects to bitmaps") "\" type=\"boolean\">true</param>\n" "<param name=\"resolution\" gui-text=\"" N_("Preferred resolution (DPI) of bitmaps") "\" type=\"int\" min=\"72\" max=\"2400\">90</param>\n" "<param name=\"areaDrawing\" gui-text=\"" N_("Export drawing, not page") "\" type=\"boolean\">false</param>\n" "<param name=\"areaCanvas\" gui-text=\"" N_("Export canvas") "\" type=\"boolean\">false</param>\n" diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 5d6315894..4bc983cb7 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -446,7 +446,7 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx) TRACE(("sp_asbitmap_render: resolution: %f\n", res )); // Get the bounding box of the selection in document coordinates. - boost::optional<Geom::Rect> bbox = + Geom::OptRect bbox = item->getBounds(sp_item_i2d_affine(item), SPItem::RENDERING_BBOX); if (!bbox) // no bbox, e.g. empty group diff --git a/src/extension/internal/eps-out.cpp b/src/extension/internal/eps-out.cpp deleted file mode 100644 index c08bd1de6..000000000 --- a/src/extension/internal/eps-out.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Authors: - * Ted Gould <ted@gould.cx> - * - * Copyright (C) 2004 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif -#include "eps-out.h" -#include <print.h> -#include "extension/system.h" -#include "extension/db.h" -#include "extension/output.h" - -namespace Inkscape { -namespace Extension { -namespace Internal { - -bool -EpsOutput::check (Inkscape::Extension::Extension * module) -{ - if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_PS)) - return FALSE; - - return TRUE; -} - -/** - \brief This function calls the print system with the filename - \param mod unused - \param doc Document to be saved - \param uri Filename to save to (probably will end in .eps) - - The most interesting thing that this function does is just attach - an '>' on the front of the filename. This is the syntax used to - tell the printing system to save to file. -*/ -void -EpsOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) -{ - gchar * final_name; - Inkscape::Extension::Extension * ext; - - ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_PS); - if (ext == NULL) - return; - - bool old_pageBoundingBox = ext->get_param_bool("pageBoundingBox"); - bool new_val = mod->get_param_bool("pageBoundingBox"); - ext->set_param_bool("pageBoundingBox", new_val); - - bool old_textToPath = ext->get_param_bool("textToPath"); - new_val = mod->get_param_bool("textToPath"); - ext->set_param_bool("textToPath", new_val); - - bool old_fontEmbedded = ext->get_param_bool("fontEmbedded"); - new_val = mod->get_param_bool("fontEmbedded"); - ext->set_param_bool("fontEmbedded", new_val); - - final_name = g_strdup_printf("> %s", uri); - sp_print_document_to_file(doc, final_name); - g_free(final_name); - - ext->set_param_bool("pageBoundingBox", old_pageBoundingBox); - ext->set_param_bool("textToPath", old_textToPath); - ext->set_param_bool("fontEmbedded", old_fontEmbedded); - - return; -} - -#include "clear-n_.h" - -/** - \brief A function allocate a copy of this function. - - This is the definition of postscript out. This function just - calls the extension system with the memory allocated XML that - describes the data. -*/ -void -EpsOutput::init (void) -{ - Inkscape::Extension::build_from_mem( - "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" - "<name>" N_("Encapsulated Postscript Output") "</name>\n" - "<id>org.inkscape.output.eps</id>\n" - "<param name=\"pageBoundingBox\" type=\"boolean\" gui-text=\"" N_("Make bounding box around full page") "\">false</param>\n" - "<param name=\"textToPath\" type=\"boolean\" gui-text=\"" N_("Convert texts to paths") "\">true</param>\n" - "<param name=\"fontEmbedded\" type=\"boolean\" gui-text=\"" N_("Embed fonts (Type 1 only)") "\">false</param>\n" - "<output>\n" - "<extension>.eps</extension>\n" - "<mimetype>image/x-eps</mimetype>\n" - "<filetypename>" N_("Encapsulated Postscript (*.eps)") "</filetypename>\n" - "<filetypetooltip>" N_("Encapsulated Postscript File") "</filetypetooltip>\n" - "</output>\n" - "</inkscape-extension>", new EpsOutput()); - - return; -} - -} } } /* namespace Inkscape, Extension, Implementation */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/extension/internal/eps-out.h b/src/extension/internal/eps-out.h deleted file mode 100644 index 41a6c1f5c..000000000 --- a/src/extension/internal/eps-out.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * - * Authors: - * Ted Gould <ted@gould.cx> - * - * Copyright (C) 2004 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef EXTENSION_INTERNAL_EPS_OUT_H -#define EXTENSION_INTERNAL_EPS_OUT_H - -#include <gtk/gtkdialog.h> -#include <gtk/gtkwidget.h> - -#include "extension/implementation/implementation.h" - -namespace Inkscape { -namespace Extension { -namespace Internal { - -class EpsOutput : Inkscape::Extension::Implementation::Implementation { -public: - bool check(Inkscape::Extension::Extension *module); - - void save(Inkscape::Extension::Output *mod, - SPDocument *doc, - gchar const *uri); - - static void init(void); -}; - -} } } /* namespace Inkscape, Extension, Implementation */ - -#endif /* EXTENSION_INTERNAL_EPS_OUT_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/extension/internal/filter/drop-shadow.h b/src/extension/internal/filter/drop-shadow.h index e0785df30..4a02086e2 100644 --- a/src/extension/internal/filter/drop-shadow.h +++ b/src/extension/internal/filter/drop-shadow.h @@ -41,7 +41,9 @@ public: "<effect>\n" "<object-type>all</object-type>\n" "<effects-menu>\n" - "<submenu name=\"" N_("Filter") "\" />\n" + "<submenu name=\"" N_("Filters") "\" >\n" + "<submenu name=\"Shadows and Glows\"/>\n" + "</submenu>\n" "</effects-menu>\n" "<menu-tip>" N_("Black, blurred drop shadow") "</menu-tip>\n" "</effect>\n" @@ -61,7 +63,7 @@ DropShadow::get_filter_text (Inkscape::Extension::Extension * ext) float y = ext->get_param_float("yoffset"); _filter = g_strdup_printf( - "<filter>\n" + "<filter width=\"1.5\" height=\"1.5\" x=\"-.25\" y=\"-.25\">\n" "<feGaussianBlur in=\"SourceAlpha\" stdDeviation=\"%f\" result=\"blur\"/>\n" "<feColorMatrix result=\"bluralpha\" type=\"matrix\" values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 %f 0 \" />\n" "<feOffset in=\"bluralpha\" dx=\"%f\" dy=\"%f\" result=\"offsetBlur\"/>\n" @@ -74,6 +76,61 @@ DropShadow::get_filter_text (Inkscape::Extension::Extension * ext) return _filter; }; +class DropGlow : public Inkscape::Extension::Internal::Filter::Filter { +protected: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + DropGlow ( ) : Filter() { }; + virtual ~DropGlow ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" + "<name>" N_("Drop Glow") "</name>\n" + "<id>org.inkscape.effect.filter.drop-glow</id>\n" + "<param name=\"blur\" gui-text=\"" N_("Blur radius, px") "\" type=\"float\" min=\"0.0\" max=\"200.0\">2.0</param>\n" + "<param name=\"opacity\" gui-text=\"" N_("Opacity, %") "\" type=\"float\" min=\"0.0\" max=\"100.0\">50</param>\n" + "<param name=\"xoffset\" gui-text=\"" N_("Horizontal offset, px") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">4.0</param>\n" + "<param name=\"yoffset\" gui-text=\"" N_("Vertical offset, px") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">4.0</param>\n" + "<effect>\n" + "<object-type>all</object-type>\n" + "<effects-menu>\n" + "<submenu name=\"" N_("Filters") "\">\n" + "<submenu name=\"Shadows and Glows\"/>\n" + "</submenu>\n" + "</effects-menu>\n" + "<menu-tip>" N_("White, blurred drop glow") "</menu-tip>\n" + "</effect>\n" + "</inkscape-extension>\n", new DropGlow()); + }; + +}; + +gchar const * +DropGlow::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) g_free((void *)_filter); + + float blur = ext->get_param_float("blur"); + float opacity = ext->get_param_float("opacity") / 100; + float x = ext->get_param_float("xoffset"); + float y = ext->get_param_float("yoffset"); + + _filter = g_strdup_printf( + "<filter width=\"1.5\" height=\"1.5\" x=\"-.25\" y=\"-.25\">\n" + "<feGaussianBlur in=\"SourceAlpha\" stdDeviation=\"%f\" result=\"blur\"/>\n" + "<feColorMatrix result=\"bluralpha\" type=\"matrix\" values=\"-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 %f 0 \" />\n" + "<feOffset in=\"bluralpha\" dx=\"%f\" dy=\"%f\" result=\"offsetBlur\"/>\n" + "<feMerge>\n" + "<feMergeNode in=\"offsetBlur\"/>\n" + "<feMergeNode in=\"SourceGraphic\"/>\n" + "</feMerge>\n" + "</filter>\n", blur, opacity, x, y); + + return _filter; +}; + }; /* namespace Filter */ }; /* namespace Internal */ }; /* namespace Extension */ diff --git a/src/extension/internal/filter/filter-all.cpp b/src/extension/internal/filter/filter-all.cpp index 6f0208a0b..b4b8caf81 100644 --- a/src/extension/internal/filter/filter-all.cpp +++ b/src/extension/internal/filter/filter-all.cpp @@ -8,34 +8,8 @@ #include "filter.h" /* Put your filter here */ -#include "apparition.h" -#include "bloom.h" -#include "clouds.h" -#include "crystal.h" -#include "cutout.h" #include "drop-shadow.h" -#include "emboss.h" -#include "etched-glass.h" -#include "fire.h" -#include "frost.h" -#include "ink-bleed.h" -#include "jelly-bean.h" -#include "jigsaw-piece.h" -#include "leopard-fur.h" -#include "melt.h" -#include "metal.h" -#include "motion-blur.h" -#include "oil-slick.h" -#include "patterned-glass.h" -#include "ridged-border.h" -#include "ripple.h" -#include "roughen.h" -#include "rubber-stamp.h" -#include "sepia.h" #include "snow.h" -#include "speckle.h" -#include "zebra.h" - namespace Inkscape { namespace Extension { @@ -46,35 +20,13 @@ namespace Filter { void Filter::filters_all (void ) { - Apparition::init(); - Bloom::init(); - Clouds::init(); - Crystal::init(); - Cutout::init(); + // Here come the filters which are coded in C++ in order to present a parameters dialog DropShadow::init(); - Emboss::init(); - EtchedGlass::init(); - Fire::init(); - Frost::init(); - InkBleed::init(); - JellyBean::init(); - JigsawPiece::init(); - LeopardFur::init(); - Melt::init(); - Metal::init(); - MotionBlur::init(); - OilSlick::init(); - PatternedGlass::init(); - RidgedBorder::init(); - Ripple::init(); - Roughen::init(); - RubberStamp::init(); - Sepia::init(); + DropGlow::init(); Snow::init(); - Speckle::init(); - Zebra::init(); - + // Here come the rest of the filters that are read from SVG files in share/filters and + // .config/Inkscape/filters /* This should always be last, don't put stuff below this * line. */ Filter::filters_all_files(); diff --git a/src/extension/internal/filter/filter-file.cpp b/src/extension/internal/filter/filter-file.cpp index 857c01a1c..7cb671f51 100644 --- a/src/extension/internal/filter/filter-file.cpp +++ b/src/extension/internal/filter/filter-file.cpp @@ -130,6 +130,8 @@ void Filter::filters_load_node (Inkscape::XML::Node * node, gchar * menuname) { gchar const * label = node->attribute("inkscape:label"); + gchar const * menu = node->attribute("inkscape:menu"); + gchar const * menu_tooltip = node->attribute("inkscape:menu-tooltip"); gchar const * id = node->attribute("id"); if (label == NULL) { @@ -143,12 +145,18 @@ Filter::filters_load_node (Inkscape::XML::Node * node, gchar * menuname) "<effect>\n" "<object-type>all</object-type>\n" "<effects-menu>\n" - "<submenu name=\"" N_("Filter") "\">\n" - "<submenu name=\"%s\"/>\n" - "</submenu>\n" + "<submenu name=\"" N_("Filters") "\">\n" + "<submenu name=\"%s\"/>\n" + "</submenu>\n" "</effects-menu>\n" + "<menu-tip>%s</menu-tip>\n" "</effect>\n" - "</inkscape-extension>\n", label, id, menuname); + "</inkscape-extension>\n", label, id, menu? menu : menuname, menu_tooltip? menu_tooltip : label); + + // FIXME: Bad hack: since we pull out a single filter node out of SVG file and + // serialize it, it loses the namespace declarations from the root, so we must provide + // one right here for our inkscape attributes + node->setAttribute("xmlns:inkscape", SP_INKSCAPE_NS_URI); mywriter writer; sp_repr_write_stream(node, writer, 0, FALSE, g_quark_from_static_string("svg"), 0, 0); diff --git a/src/extension/internal/filter/filter.cpp b/src/extension/internal/filter/filter.cpp index 1ba0ce8ca..5a104b6a1 100644 --- a/src/extension/internal/filter/filter.cpp +++ b/src/extension/internal/filter/filter.cpp @@ -109,8 +109,6 @@ Filter::merge_filters (Inkscape::XML::Node * to, Inkscape::XML::Node * from, Ink } Inkscape::GC::release(to_child); } - - return; } #define FILTER_SRC_GRAPHIC "fbSourceGraphic" @@ -139,8 +137,10 @@ Filter::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *d gchar const * filter = sp_repr_css_property(css, "filter", NULL); if (filter == NULL) { + Inkscape::XML::Node * newfilterroot = xmldoc->createElement("svg:filter"); defsrepr->appendChild(newfilterroot); + Glib::ustring url = "url(#"; url += newfilterroot->attribute("id"); url += ")"; merge_filters(newfilterroot, get_filter(module)->root(), xmldoc); @@ -189,7 +189,7 @@ Filter::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *d #include "extension/internal/clear-n_.h" void -Filter::filter_init (gchar const * id, gchar const * name, gchar const * tip, gchar const * filter) +Filter::filter_init (gchar const * id, gchar const * name, gchar const * submenu, gchar const * tip, gchar const * filter) { gchar * xml_str = g_strdup_printf( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" @@ -198,11 +198,12 @@ Filter::filter_init (gchar const * id, gchar const * name, gchar const * tip, gc "<effect>\n" "<object-type>all</object-type>\n" "<effects-menu>\n" - "<submenu name=\"" N_("Filter") "\" />\n" + "<submenu name=\"" N_("Filters") "\" />\n" + "<submenu name=\"%s\"/>\n" "</effects-menu>\n" "<menu-tip>%s</menu-tip>\n" "</effect>\n" - "</inkscape-extension>\n", name, id, tip); + "</inkscape-extension>\n", name, id, submenu, tip); Inkscape::Extension::build_from_mem(xml_str, new Filter::Filter(filter)); g_free(xml_str); return; diff --git a/src/extension/internal/filter/filter.h b/src/extension/internal/filter/filter.h index 05fdcc4cd..fe6b678d9 100644 --- a/src/extension/internal/filter/filter.h +++ b/src/extension/internal/filter/filter.h @@ -36,7 +36,7 @@ public: Inkscape::Extension::Implementation::ImplementationDocumentCache * newDocCache (Inkscape::Extension::Extension * ext, Inkscape::UI::View::View * doc); void effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document, Inkscape::Extension::Implementation::ImplementationDocumentCache * docCache); - static void filter_init(gchar const * id, gchar const * name, gchar const * tip, gchar const * filter); + static void filter_init(gchar const * id, gchar const * name, gchar const * submenu, gchar const * tip, gchar const * filter); static void filters_all(void); /* File loader related */ diff --git a/src/extension/internal/filter/snow.h b/src/extension/internal/filter/snow.h index 366bdcf1f..cf5065754 100644 --- a/src/extension/internal/filter/snow.h +++ b/src/extension/internal/filter/snow.h @@ -35,9 +35,11 @@ public: "<effect>\n" "<object-type>all</object-type>\n" "<effects-menu>\n" - "<submenu name=\"" N_("Filter") "\" />\n" + "<submenu name=\"" N_("Filters") "\">\n" + "<submenu name=\"Shadows and Glows\"/>\n" + "</submenu>\n" "</effects-menu>\n" - "<menu-tip>" N_("When the weather outside is frightening...") "</menu-tip>\n" + "<menu-tip>" N_("Snow has fallen on object") "</menu-tip>\n" "</effect>\n" "</inkscape-extension>\n", new Snow()); }; diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index 366bab000..d4b35b261 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -85,7 +85,7 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc bounding_area = Geom::Rect( Geom::Point(0,0), Geom::Point(sp_document_width(doc), sp_document_height(doc)) ); } else { - boost::optional<Geom::Rect> bounds = selection->bounds(); + Geom::OptRect bounds = selection->bounds(); if (bounds) { bounding_area = *bounds; } diff --git a/src/extension/internal/javafx-out.cpp b/src/extension/internal/javafx-out.cpp index 967ddd92d..69ee296e5 100644 --- a/src/extension/internal/javafx-out.cpp +++ b/src/extension/internal/javafx-out.cpp @@ -187,6 +187,16 @@ static JavaFXOutput::String getStrokeLineJoin(unsigned value) { }
+/**
+ * Replace illegal characters for JavaFX for a underscore.
+ */
+static JavaFXOutput::String sanatize(const JavaFXOutput::String &badstr){
+ JavaFXOutput::String good(badstr);
+ for (int pos = 0; pos < badstr.length(); ++pos )
+ if((badstr.at(pos)=='-')||(badstr.at(pos)==' '))
+ good.replace(pos, 1, "_");
+ return good;
+}
/**
* Output data to the buffer, printf()-style
@@ -298,11 +308,13 @@ bool JavaFXOutput::doTail() */
bool JavaFXOutput::doGradient(SPGradient *grad, const String &id)
{
+ String jfxid = sanatize(id);
+
if (SP_IS_LINEARGRADIENT(grad))
{
SPLinearGradient *g = SP_LINEARGRADIENT(grad);
- out(" /* create LinearGradient for %s */\n", id.c_str());
- out(" private function %s(): LinearGradient {\n", id.c_str());
+ out(" /* create LinearGradient for %s */\n", jfxid.c_str());
+ out(" private function %s(): LinearGradient {\n", jfxid.c_str());
out(" LinearGradient {\n");
std::vector<SPGradientStop> stops = g->vector.stops;
if (stops.size() > 0)
@@ -320,14 +332,14 @@ bool JavaFXOutput::doGradient(SPGradient *grad, const String &id) out(" ]\n");
}
out(" };\n");
- out(" } // end LinearGradient: %s\n", id.c_str());
+ out(" } // end LinearGradient: %s\n", jfxid.c_str());
out("\n\n");
}
else if (SP_IS_RADIALGRADIENT(grad))
{
SPRadialGradient *g = SP_RADIALGRADIENT(grad);
- out(" /* create RadialGradient for %s */\n", id.c_str());
- out(" private function %s() {\n", id.c_str());
+ out(" /* create RadialGradient for %s */\n", jfxid.c_str());
+ out(" private function %s() {\n", jfxid.c_str());
out(" RadialGradient {\n");
out(" centerX: %s\n", DSTR(g->cx.value));
out(" centerY: %s\n", DSTR(g->cy.value));
@@ -350,12 +362,12 @@ bool JavaFXOutput::doGradient(SPGradient *grad, const String &id) out(" ]\n");
}
out(" };\n");
- out(" } // end RadialGradient: %s\n", id.c_str());
+ out(" } // end RadialGradient: %s\n", jfxid.c_str());
out("\n\n");
}
else
{
- err("Unknown gradient type for '%s'\n", id.c_str());
+ err("Unknown gradient type for '%s'\n", jfxid.c_str());
return false;
}
@@ -392,7 +404,7 @@ bool JavaFXOutput::doStyle(SPStyle *style) /* trim the anchor '#' from the front */
if (uri.size() > 0 && uri[0]=='#')
uri = uri.substr(1);
- out(" fill: %s()\n", uri.c_str());
+ out(" fill: %s()\n", sanatize(uri).c_str());
}
}
@@ -456,6 +468,8 @@ bool JavaFXOutput::doCurve(SPItem *item, const String &id) using Geom::X;
using Geom::Y;
+ String jfxid = sanatize(id);
+
//### Get the Shape
if (!SP_IS_SHAPE(item))//Bulia's suggestion. Allow all shapes
return true;
@@ -467,10 +481,10 @@ bool JavaFXOutput::doCurve(SPItem *item, const String &id) nrShapes++;
- out(" /** path %s */\n", id.c_str());
- out(" private function %s() : Path {\n",id.c_str());
+ out(" /** path %s */\n", jfxid.c_str());
+ out(" private function %s() : Path {\n",jfxid.c_str());
out(" Path {\n");
- out(" id: \"%s\"\n", id.c_str());
+ out(" id: \"%s\"\n", jfxid.c_str());
/**
* Output the style information
@@ -560,7 +574,7 @@ bool JavaFXOutput::doCurve(SPItem *item, const String &id) out(" ] // elements\n");
out(" }; // Path\n");
- out(" } // end path %s\n\n", id.c_str());
+ out(" } // end path %s\n\n", jfxid.c_str());
double cminx = cminmax.min()[X];
double cmaxx = cminmax.max()[X];
@@ -737,7 +751,8 @@ bool JavaFXOutput::doTree(SPDocument *doc) }
-bool JavaFXOutput::doBody(SPDocument *doc, SPObject *obj) {
+bool JavaFXOutput::doBody(SPDocument *doc, SPObject *obj)
+{
/**
* Check the type of node and process
*/
diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 2e0082832..c15b839d7 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -962,10 +962,10 @@ static Geom::Matrix getODFTransform(const SPItem *item) * Get the bounding box of an item, as mapped onto * an ODF document, in cm. */ -static boost::optional<Geom::Rect> getODFBoundingBox(const SPItem *item) +static Geom::OptRect getODFBoundingBox(const SPItem *item) { - boost::optional<Geom::Rect> bbox_temp = sp_item_bbox_desktop((SPItem *)item); - boost::optional<Geom::Rect> bbox; + Geom::OptRect bbox_temp = sp_item_bbox_desktop((SPItem *)item); + Geom::OptRect bbox; if (bbox_temp) { bbox = *bbox_temp; double doc_height = sp_document_height(SP_ACTIVE_DOCUMENT); @@ -1866,7 +1866,7 @@ bool OdfOutput::writeTree(Writer &couts, Writer &souts, Geom::Matrix tf = getODFTransform(item); //### Get ODF bounding box params for item - boost::optional<Geom::Rect> bbox = getODFBoundingBox(item); + Geom::OptRect bbox = getODFBoundingBox(item); if (!bbox) { return true; } diff --git a/src/extension/internal/pdf-cairo.cpp b/src/extension/internal/pdf-cairo.cpp deleted file mode 100644 index 6c2b2ed62..000000000 --- a/src/extension/internal/pdf-cairo.cpp +++ /dev/null @@ -1,1060 +0,0 @@ -#define __SP_PDF_CAIRO_C__ - -/** \file - * PDF printing with Cairo. - */ -/* - * Authors: - * Miklós Erdélyi <erdelyim@gmail.com> - * - * Based on pdf.cpp - * - * Licensed under GNU GPL - */ - -/* Plain Print */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#ifdef HAVE_CAIRO_PDF - -#ifndef PANGO_ENABLE_BACKEND -#define PANGO_ENABLE_BACKEND -#endif - -#ifndef PANGO_ENABLE_ENGINE -#define PANGO_ENABLE_ENGINE -#endif - - -#include <signal.h> -#include <errno.h> - -#include <glib/gmem.h> -#include <gtk/gtkstock.h> -#include <gtk/gtkvbox.h> -#include <gtk/gtkframe.h> -#include <gtk/gtkradiobutton.h> -#include <gtk/gtkcombo.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkentry.h> -#include <gtk/gtktooltips.h> - -#include <glibmm/i18n.h> -#include "display/nr-arena-item.h" -#include "display/canvas-bpath.h" -#include "display/inkscape-cairo.h" -#include "sp-item.h" -#include "style.h" -#include "sp-linear-gradient.h" -#include "sp-radial-gradient.h" - -#include "libnrtype/font-instance.h" -#include "libnrtype/font-style-to-pos.h" - -#include "libnr/nr-matrix.h" -#include "libnr/nr-matrix-fns.h" -#include "libnr/nr-matrix-ops.h" - -#include <unit-constants.h> - -#include "pdf-cairo.h" -#include "extension/system.h" -#include "extension/print.h" - -#include "io/sys.h" - -#include <cairo.h> -#include <cairo-pdf.h> - -#include <pango/pango.h> -#include <pango/pangofc-fontmap.h> - -#ifdef RENDER_WITH_PANGO_CAIRO -#include <pango/pangocairo.h> -#else -#include <cairo-ft.h> -#endif -namespace Inkscape { -namespace Extension { -namespace Internal { - -static cairo_status_t _write_callback(void *closure, const unsigned char *data, unsigned int length); -static void _concat_transform(cairo_t *cr, double xx, double yx, double xy, double yy, double x0, double y0); - -PrintCairoPDF::PrintCairoPDF() : - cr(NULL), - pdf_surface(NULL), - _layout(NULL), - _dpi(72), - _bitmap(false) -{ -} - -PrintCairoPDF::~PrintCairoPDF(void) -{ - if (cr) cairo_destroy(cr); - if (pdf_surface) cairo_surface_destroy(pdf_surface); - if (_layout) g_object_unref(_layout); - - /* restore default signal handling for SIGPIPE */ -#if !defined(_WIN32) && !defined(__WIN32__) - (void) signal(SIGPIPE, SIG_DFL); -#endif - - return; -} - -unsigned int -PrintCairoPDF::setup(Inkscape::Extension::Print * mod) -{ - static gchar const *const pdr[] = {"72", "75", "100", "144", "150", "200", "300", "360", "600", "1200", "2400", NULL}; - -#ifdef TED - Inkscape::XML::Node *repr = ((SPModule *) mod)->repr; -#endif - - unsigned int ret = FALSE; - - /* Create dialog */ - GtkTooltips *tt = gtk_tooltips_new(); - g_object_ref((GObject *) tt); - gtk_object_sink((GtkObject *) tt); - - GtkWidget *dlg = gtk_dialog_new_with_buttons(_("Print Destination"), -// SP_DT_WIDGET(SP_ACTIVE_DESKTOP)->window, - NULL, - (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_PRINT, - GTK_RESPONSE_OK, - NULL); - - gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK); - - GtkWidget *vbox = GTK_DIALOG(dlg)->vbox; - gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); - /* Print properties frame */ - GtkWidget *f = gtk_frame_new(_("Print properties")); - gtk_box_pack_start(GTK_BOX(vbox), f, FALSE, FALSE, 4); - GtkWidget *vb = gtk_vbox_new(FALSE, 4); - gtk_container_add(GTK_CONTAINER(f), vb); - gtk_container_set_border_width(GTK_CONTAINER(vb), 4); - /* Print type */ - bool const p2bm = mod->get_param_bool("bitmap"); - GtkWidget *rb = gtk_radio_button_new_with_label(NULL, _("Print using PDF operators")); - gtk_tooltips_set_tip((GtkTooltips *) tt, rb, - _("Use PDF vector operators. The resulting image is usually smaller " - "in file size and can be arbitrarily scaled, but " - "patterns will be lost."), NULL); - if (!p2bm) gtk_toggle_button_set_active((GtkToggleButton *) rb, TRUE); - gtk_box_pack_start(GTK_BOX(vb), rb, FALSE, FALSE, 0); - rb = gtk_radio_button_new_with_label(gtk_radio_button_get_group((GtkRadioButton *) rb), _("Print as bitmap")); - gtk_tooltips_set_tip((GtkTooltips *) tt, rb, - _("Print everything as bitmap. The resulting image is usually larger " - "in file size and cannot be arbitrarily scaled without quality loss, " - "but all objects will be rendered exactly as displayed."), NULL); - if (p2bm) gtk_toggle_button_set_active((GtkToggleButton *) rb, TRUE); - gtk_box_pack_start(GTK_BOX(vb), rb, FALSE, FALSE, 0); - /* Resolution */ - GtkWidget *hb = gtk_hbox_new(FALSE, 4); - gtk_box_pack_start(GTK_BOX(vb), hb, FALSE, FALSE, 0); - GtkWidget *combo = gtk_combo_new(); - gtk_combo_set_value_in_list(GTK_COMBO(combo), FALSE, FALSE); - gtk_combo_set_use_arrows(GTK_COMBO(combo), TRUE); - gtk_combo_set_use_arrows_always(GTK_COMBO(combo), TRUE); - gtk_widget_set_size_request(combo, 64, -1); - gtk_tooltips_set_tip((GtkTooltips *) tt, GTK_COMBO(combo)->entry, - _("Preferred resolution (dots per inch) of bitmap"), NULL); - /* Setup strings */ - GList *sl = NULL; - for (unsigned i = 0; pdr[i] != NULL; i++) { - sl = g_list_prepend(sl, (gpointer) pdr[i]); - } - sl = g_list_reverse(sl); - gtk_combo_set_popdown_strings(GTK_COMBO(combo), sl); - g_list_free(sl); - if (1) { - gchar const *val = mod->get_param_string("resolution"); - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), val); - } - gtk_box_pack_end(GTK_BOX(hb), combo, FALSE, FALSE, 0); - GtkWidget *l = gtk_label_new(_("Resolution:")); - gtk_box_pack_end(GTK_BOX(hb), l, FALSE, FALSE, 0); - - /* Print destination frame */ - f = gtk_frame_new(_("Print destination")); - gtk_box_pack_start(GTK_BOX(vbox), f, FALSE, FALSE, 4); - vb = gtk_vbox_new(FALSE, 4); - gtk_container_add(GTK_CONTAINER(f), vb); - gtk_container_set_border_width(GTK_CONTAINER(vb), 4); - - l = gtk_label_new(_("Printer name (as given by lpstat -p);\n" - "leave empty to use the system default printer.\n" - "Use '> filename' to print to file.\n" - "Use '| prog arg...' to pipe to a program.")); - gtk_box_pack_start(GTK_BOX(vb), l, FALSE, FALSE, 0); - - GtkWidget *e = gtk_entry_new(); - if (1) { - gchar const *val = mod->get_param_string("destination"); - gtk_entry_set_text(GTK_ENTRY(e), ( val != NULL - ? val - : "" )); - } - gtk_box_pack_start(GTK_BOX(vb), e, FALSE, FALSE, 0); - - // pressing enter in the destination field is the same as clicking Print: - gtk_entry_set_activates_default(GTK_ENTRY(e), TRUE); - - gtk_widget_show_all(vbox); - - int const response = gtk_dialog_run(GTK_DIALOG(dlg)); - - g_object_unref((GObject *) tt); - - if (response == GTK_RESPONSE_OK) { - gchar const *fn; - char const *sstr; - - _bitmap = gtk_toggle_button_get_active((GtkToggleButton *) rb); - sstr = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)); - _dpi = (unsigned int) MAX((int)(atof(sstr)), 1); - /* Arrgh, have to do something */ - fn = gtk_entry_get_text(GTK_ENTRY(e)); - /* skip leading whitespace, bug #1068483 */ - while (fn && *fn==' ') { fn++; } - /* g_print("Printing to %s\n", fn); */ - - mod->set_param_bool("bitmap", _bitmap); - mod->set_param_string("resolution", (gchar *)sstr); - mod->set_param_string("destination", (gchar *)fn); - ret = TRUE; - } - - gtk_widget_destroy(dlg); - - return ret; -} - -unsigned int -PrintCairoPDF::begin(Inkscape::Extension::Print *mod, SPDocument *doc) -{ - FILE *osf = NULL; - FILE *osp = NULL; - - _alpha_stack.clear(); - _alpha_stack.push_back(1.0); - - gsize bytesRead = 0; - gsize bytesWritten = 0; - GError *error = NULL; - gchar const *utf8_fn = mod->get_param_string("destination"); - gchar *local_fn = g_filename_from_utf8( utf8_fn, - -1, &bytesRead, &bytesWritten, &error); - gchar const *fn = local_fn; - - /* TODO: Replace the below fprintf's with something that does the right thing whether in - * gui or batch mode (e.g. --print=blah). Consider throwing an exception: currently one of - * the callers (sp_print_document_to_file, "ret = mod->begin(doc)") wrongly ignores the - * return code. - */ - if (fn != NULL) { - if (*fn == '|') { - fn += 1; - while (isspace(*fn)) fn += 1; -#ifndef WIN32 - osp = popen(fn, "w"); -#else - osp = _popen(fn, "w"); -#endif - if (!osp) { - fprintf(stderr, "inkscape: popen(%s): %s\n", - fn, strerror(errno)); - return 0; - } - _stream = osp; - } else if (*fn == '>') { - fn += 1; - while (isspace(*fn)) fn += 1; - Inkscape::IO::dump_fopen_call(fn, "K"); - osf = Inkscape::IO::fopen_utf8name(fn, "w+"); - if (!osf) { - fprintf(stderr, "inkscape: fopen(%s): %s\n", - fn, strerror(errno)); - return 0; - } - _stream = osf; - } else { - /* put cwd stuff in here */ - gchar *qn = ( *fn - ? g_strdup_printf("lpr -P %s", fn) /* FIXME: quote fn */ - : g_strdup("lpr") ); -#ifndef WIN32 - osp = popen(qn, "w"); -#else - osp = _popen(qn, "w"); -#endif - if (!osp) { - fprintf(stderr, "inkscape: popen(%s): %s\n", - qn, strerror(errno)); - return 0; - } - g_free(qn); - _stream = osp; - } - } - - g_free(local_fn); - - if (_stream) { - /* fixme: this is kinda icky */ -#if !defined(_WIN32) && !defined(__WIN32__) - (void) signal(SIGPIPE, SIG_IGN); -#endif - } - - // test output stream? - - // width and height in pt - _width = sp_document_width(doc) * PT_PER_PX; - _height = sp_document_height(doc) * PT_PER_PX; - - NRRect d; - bool pageBoundingBox = mod->get_param_bool("pageBoundingBox"); - SPItem* doc_item = SP_ITEM(mod->base); - // printf("Page Bounding Box: %s\n", pageBoundingBox ? "TRUE" : "FALSE"); - Geom::Matrix t (Geom::identity()); - if (pageBoundingBox) { - d.x0 = d.y0 = 0; - d.x1 = _width; - d.y1 = _height; - } else { - // if not page, use our base, which is either root or the item we want to export - sp_item_invoke_bbox(doc_item, &d, sp_item_i2doc_affine (doc_item), TRUE); - // convert from px to pt - d.x0 *= PT_PER_PX; - d.x1 *= PT_PER_PX; - d.y0 *= PT_PER_PX; - d.y1 *= PT_PER_PX; - } - - // When rendering a standalone object, we must set cairo's transform to the accumulated - // ancestor transform of that item - e.g. it may be rotated or skewed by its parent group, and - // we must reproduce that in the export even though we start traversing the tree from the - // object itself, ignoring its ancestors - - // complete transform, including doc_item's own transform - t = sp_item_i2doc_affine (doc_item); - // subreact doc_item's transform (comes first) from it - t = Geom::Matrix(doc_item->transform).inverse() * t; - - // create cairo context - pdf_surface = cairo_pdf_surface_create_for_stream(Inkscape::Extension::Internal::_write_callback, _stream, d.x1-d.x0, d.y1-d.y0); - cr = cairo_create(pdf_surface); - - // move to the origin - cairo_translate (cr, -d.x0, -d.y0); - - // set cairo transform; we must scale the translation values to pt - _concat_transform (cr, t[0], t[1], t[2], t[3], t[4]*PT_PER_PX, t[5]*PT_PER_PX); - - if (!_bitmap) { - cairo_scale(cr, PT_PER_PX, PT_PER_PX); - - // from now on we can output px, but they will be treated as pt - // note that the we do not have to flip the y axis - // because Cairo's coordinate system is identical to Inkscape's - } - - return 1; -} - -unsigned int -PrintCairoPDF::finish(Inkscape::Extension::Print *mod) -{ - if (!_stream) return 0; - if (_bitmap) return 0; - - cairo_show_page(cr); - - cairo_destroy(cr); - cairo_surface_finish(pdf_surface); - cairo_status_t status = cairo_surface_status(pdf_surface); - cairo_surface_destroy(pdf_surface); - cr = NULL; - pdf_surface = NULL; - - /* Flush stream to be sure. */ - (void) fflush(_stream); - - /* fixme: should really use pclose for popen'd streams */ - fclose(_stream); - _stream = 0; - - if (status == CAIRO_STATUS_SUCCESS) - return true; - else - return false; -} - -unsigned int -PrintCairoPDF::bind(Inkscape::Extension::Print *mod, Geom::Matrix const *transform, float opacity) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - if (opacity < 1.0) { - cairo_push_group(cr); - } else { - cairo_save(cr); - } - _concat_transform(cr, (*transform)[0], (*transform)[1], (*transform)[2], (*transform)[3], (*transform)[4], (*transform)[5]); - // printf("bind: (%f) %f %f %f %f %f %f\n", opacity, transform->c[0], transform->c[1], transform->c[2], transform->c[3], transform->c[4], transform->c[5]); - // remember these to be able to undo them when outputting text - _last_tx = (*transform)[4]; - _last_ty = (*transform)[5]; - - _alpha_stack.push_back(opacity); - - return 1; -} - -unsigned int -PrintCairoPDF::release(Inkscape::Extension::Print *mod) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - float opacity = _alpha_stack.back(); - - if (opacity < 1.0) { - cairo_pop_group_to_source(cr); - cairo_paint_with_alpha(cr, opacity); - } else { - cairo_restore(cr); - } -// g_printf("release\n"); - _alpha_stack.pop_back(); - g_assert(_alpha_stack.size() > 0); - - return 1; -} - -unsigned int -PrintCairoPDF::comment(Inkscape::Extension::Print *mod, char const *comment) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - return 1; -} - -cairo_pattern_t* -PrintCairoPDF::create_pattern_for_paint(SPPaintServer const *const paintserver, NRRect const *pbox, float alpha) -{ - cairo_pattern_t *pattern = NULL; - bool apply_bbox2user = false; - - if (SP_IS_LINEARGRADIENT (paintserver)) { - - SPLinearGradient *lg=SP_LINEARGRADIENT(paintserver); - - sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built - - Geom::Point p1 (lg->x1.computed, lg->y1.computed); - Geom::Point p2 (lg->x2.computed, lg->y2.computed); - if (pbox && SP_GRADIENT(lg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { - // convert to userspace - Geom::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0); - p1 *= bbox2user; - p2 *= bbox2user; - } - - // create linear gradient pattern - pattern = cairo_pattern_create_linear(p1[Geom::X], p1[Geom::Y], p2[Geom::X], p2[Geom::Y]); - - // add stops - for (gint i = 0; unsigned(i) < lg->vector.stops.size(); i++) { - float rgb[3]; - sp_color_get_rgb_floatv(&lg->vector.stops[i].color, rgb); - cairo_pattern_add_color_stop_rgba(pattern, lg->vector.stops[i].offset, rgb[0], rgb[1], rgb[2], lg->vector.stops[i].opacity * alpha); - } - } else if (SP_IS_RADIALGRADIENT (paintserver)) { - - SPRadialGradient *rg=SP_RADIALGRADIENT(paintserver); - - sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built - - Geom::Point c (rg->cx.computed, rg->cy.computed); - Geom::Point f (rg->fx.computed, rg->fy.computed); - double r = rg->r.computed; - - Geom::Coord const df = hypot(f[Geom::X] - c[Geom::X], f[Geom::Y] - c[Geom::Y]); - if (df >= r) { - f[Geom::X] = c[Geom::X] + (f[Geom::X] - c[Geom::X] ) * r / (float) df; - f[Geom::Y] = c[Geom::Y] + (f[Geom::Y] - c[Geom::Y] ) * r / (float) df; - } - - if (pbox && SP_GRADIENT(rg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) - apply_bbox2user = true; - - // create radial gradient pattern - pattern = cairo_pattern_create_radial(f[Geom::X], f[Geom::Y], 0, c[Geom::X], c[Geom::Y], r); - - // add stops - for (gint i = 0; unsigned(i) < rg->vector.stops.size(); i++) { - float rgb[3]; - sp_color_get_rgb_floatv(&rg->vector.stops[i].color, rgb); - cairo_pattern_add_color_stop_rgba(pattern, rg->vector.stops[i].offset, rgb[0], rgb[1], rgb[2], rg->vector.stops[i].opacity * alpha); - } - } - - if (pattern) { - SPGradient *g = SP_GRADIENT(paintserver); - - // set extend type - SPGradientSpread spread = sp_gradient_get_spread(g); - switch (spread) { - case SP_GRADIENT_SPREAD_REPEAT: - cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); - break; - case SP_GRADIENT_SPREAD_REFLECT: - cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REFLECT); - break; - case SP_GRADIENT_SPREAD_PAD: - default: - cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD); - break; - } - - cairo_matrix_t pattern_matrix; - if (g->gradientTransform_set) { - // apply gradient transformation - cairo_matrix_init(&pattern_matrix, - g->gradientTransform[0], g->gradientTransform[1], - g->gradientTransform[2], g->gradientTransform[3], - g->gradientTransform[4], g->gradientTransform[5]); - } else { - cairo_matrix_init_identity (&pattern_matrix); - } - - if (apply_bbox2user) { - // convert to userspace - cairo_matrix_t bbox2user; - cairo_matrix_init (&bbox2user, pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0); - cairo_matrix_multiply (&pattern_matrix, &bbox2user, &pattern_matrix); - } - cairo_matrix_invert(&pattern_matrix); // because Cairo expects a userspace->patternspace matrix - cairo_pattern_set_matrix(pattern, &pattern_matrix); - } - - return pattern; -} - -void -PrintCairoPDF::print_fill_style(cairo_t *cr, SPStyle const *const style, NRRect const *pbox) -{ - g_return_if_fail( style->fill.isColor() - || ( style->fill.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ); - - if (style->fill.isColor()) { - float rgb[3]; - sp_color_get_rgb_floatv(&style->fill.value.color, rgb); - - float alpha = SP_SCALE24_TO_FLOAT(style->fill_opacity.value); - - cairo_set_source_rgba(cr, rgb[0], rgb[1], rgb[2], alpha); - } else { - g_assert( style->fill.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ); - - cairo_pattern_t *pattern = create_pattern_for_paint(SP_STYLE_FILL_SERVER(style), pbox, 1.0); - - if (pattern) { - cairo_set_source(cr, pattern); - cairo_pattern_destroy(pattern); - } - } -} - -unsigned int -PrintCairoPDF::fill(Inkscape::Extension::Print *mod, Geom::PathVector const &pathv, Geom::Matrix const *ctm, SPStyle const *const style, - NRRect const *pbox, NRRect const *dbox, NRRect const *bbox) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - if ( style->fill.isColor() - || ( style->fill.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) { - - float alpha = SP_SCALE24_TO_FLOAT(style->fill_opacity.value); - - cairo_save(cr); - - print_fill_style(cr, style, pbox); - - cairo_new_path(cr); - feed_pathvector_to_cairo(cr, pathv); - - if (style->fill_rule.computed == SP_WIND_RULE_EVENODD) { - cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); - } else { - cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING); - } - if (alpha != 1.0 && - !style->fill.isColor()) { - - cairo_clip (cr); - cairo_paint_with_alpha (cr, alpha); - } else { - cairo_fill(cr); - } - - cairo_restore(cr); - } - - return 0; -} - -void -PrintCairoPDF::print_stroke_style(cairo_t *cr, SPStyle const *style, NRRect const *pbox) -{ - float alpha = SP_SCALE24_TO_FLOAT(style->stroke_opacity.value); - - if ( style->stroke.isColor() ) { - float rgb[3]; - sp_color_get_rgb_floatv(&style->stroke.value.color, rgb); - - cairo_set_source_rgba(cr, rgb[0], rgb[1], rgb[2], alpha); - } else if ( style->stroke.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) ) { - - cairo_pattern_t *pattern = create_pattern_for_paint(SP_STYLE_STROKE_SERVER(style), pbox, alpha); - - if (pattern) { - cairo_set_source(cr, pattern); - cairo_pattern_destroy(pattern); - } - } - - if (style->stroke_dash.n_dash && - style->stroke_dash.dash ) - { - cairo_set_dash(cr, style->stroke_dash.dash, style->stroke_dash.n_dash, style->stroke_dash.offset); - } else { - cairo_set_dash(cr, NULL, 0, 0.0); // disable dashing - } - - cairo_set_line_width(cr, style->stroke_width.computed); - - // set line join type - cairo_line_join_t join = CAIRO_LINE_JOIN_MITER; - switch (style->stroke_linejoin.computed) { - case SP_STROKE_LINEJOIN_MITER: - join = CAIRO_LINE_JOIN_MITER; - break; - case SP_STROKE_LINEJOIN_ROUND: - join = CAIRO_LINE_JOIN_ROUND; - break; - case SP_STROKE_LINEJOIN_BEVEL: - join = CAIRO_LINE_JOIN_BEVEL; - break; - } - cairo_set_line_join(cr, join); - - // set line cap type - cairo_line_cap_t cap = CAIRO_LINE_CAP_BUTT; - switch (style->stroke_linecap.computed) { - case SP_STROKE_LINECAP_BUTT: - cap = CAIRO_LINE_CAP_BUTT; - break; - case SP_STROKE_LINECAP_ROUND: - cap = CAIRO_LINE_CAP_ROUND; - break; - case SP_STROKE_LINECAP_SQUARE: - cap = CAIRO_LINE_CAP_SQUARE; - break; - } - cairo_set_line_cap(cr, cap); - cairo_set_miter_limit(cr, MAX(1, style->stroke_miterlimit.value)); -} - -unsigned int -PrintCairoPDF::stroke(Inkscape::Extension::Print *mod, Geom::PathVector const &pathv, Geom::Matrix const *ctm, SPStyle const *style, - NRRect const *pbox, NRRect const *dbox, NRRect const *bbox) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - if ( style->stroke.isColor() || - ( style->stroke.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) ) ) { - - cairo_save(cr); - - cairo_new_path(cr); - print_stroke_style(cr, style, pbox); - - feed_pathvector_to_cairo(cr, pathv); - cairo_stroke(cr); - - cairo_restore(cr); - } - - return 0; -} - -unsigned int -PrintCairoPDF::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w, unsigned int h, unsigned int rs, - Geom::Matrix const *transform, SPStyle const *style) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - guchar* px_rgba = (guchar*)g_malloc(4 * w * h); - if (!px_rgba) return 0; - - float alpha = _alpha_stack.back(); - - // make a copy of the original pixbuf with premultiplied alpha - // if we pass the original pixbuf it will get messed up - for (unsigned i = 0; i < h; i++) { - for (unsigned j = 0; j < w; j++) { - guchar const *src = px + i * rs + j * 4; - guint32 *dst = (guint32 *)(px_rgba + i * rs + j * 4); - guchar r, g, b, alpha_dst; - - // calculate opacity-modified alpha - alpha_dst = src[3]; - if (alpha != 1.0) - alpha_dst = (guchar)ceil((float)alpha_dst * alpha); - - // premul alpha (needed because this will be undone by cairo-pdf) - r = src[0]*alpha_dst/255; - g = src[1]*alpha_dst/255; - b = src[2]*alpha_dst/255; - - *dst = (((alpha_dst) << 24) | (((r)) << 16) | (((g)) << 8) | (b)); - } - } - - cairo_surface_t *image_surface = cairo_image_surface_create_for_data(px_rgba, CAIRO_FORMAT_ARGB32, w, h, w * 4); - if (cairo_surface_status(image_surface)) { - g_printf("Error: %s\n", cairo_status_to_string(cairo_surface_status(image_surface))); - return 0; - } - - cairo_save(cr); - - // scaling by width & height is not needed because it will be done by cairo-pdf - // we have to translate down by height also in order to eliminate the last translation done by sp_image_print - cairo_matrix_t matrix; - cairo_matrix_init(&matrix, - (*transform)[0]/w, (*transform)[1], - (*transform)[2], -(*transform)[3]/h, - (*transform)[4], (*transform)[5] + (*transform)[3]); - cairo_transform(cr, &matrix); - - cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image_surface); - cairo_pattern_set_extend(pattern, CAIRO_EXTEND_NONE); - - cairo_set_source(cr, pattern); - cairo_pattern_destroy(pattern); - - // set clip region so that the pattern will not be repeated (bug in Cairo prior 1.2.1) - cairo_new_path(cr); - cairo_rectangle(cr, 0, 0, w, h); - cairo_clip(cr); - - cairo_paint(cr); - - cairo_restore(cr); - - cairo_surface_destroy(image_surface); - g_free(px_rgba); - - return 0; -} - -#define GLYPH_ARRAY_SIZE 64 - -#ifndef RENDER_WITH_PANGO_CAIRO - -Geom::Point -PrintCairoPDF::draw_glyphs(cairo_t *cr, Geom::Point p, PangoFont *font, PangoGlyphString *glyph_string, - bool vertical, bool stroke) -{ - cairo_glyph_t glyph_array[GLYPH_ARRAY_SIZE]; - cairo_glyph_t *glyphs = glyph_array; - if (glyph_string->num_glyphs > GLYPH_ARRAY_SIZE) - glyphs = (cairo_glyph_t*)g_malloc(sizeof(cairo_glyph_t) * glyph_string->num_glyphs); - - PangoGlyphUnit x_offset = 0, y_offset = 0; - PangoGlyphInfo *info; - int num_invalid_glyphs = 0; - for (gint i = 0; i < glyph_string->num_glyphs; i++) { - info = &glyph_string->glyphs[i]; - // skip glyphs which are PANGO_GLYPH_EMPTY (0x0FFFFFFF) or have - // the PANGO_GLYPH_UNKNOWN_FLAG (0x10000000) set - if (info->glyph == 0x0FFFFFFF || info->glyph & 0x10000000) { - num_invalid_glyphs++; - continue; - } - - glyphs[i - num_invalid_glyphs].index = info->glyph; - glyphs[i - num_invalid_glyphs].x = p[Geom::X] + (x_offset + info->geometry.x_offset)/PANGO_SCALE; - glyphs[i - num_invalid_glyphs].y = p[Geom::Y] + (y_offset + info->geometry.y_offset)/PANGO_SCALE; - - if (vertical) { - cairo_text_extents_t extents; - cairo_glyph_extents(cr, &glyphs[i - num_invalid_glyphs], 1, &extents); - y_offset += (PangoGlyphUnit)(extents.y_advance * PANGO_SCALE); - } - else - x_offset += info->geometry.width; - } - - if (stroke) - cairo_glyph_path(cr, glyphs, glyph_string->num_glyphs - num_invalid_glyphs); - else - cairo_show_glyphs(cr, glyphs, glyph_string->num_glyphs - num_invalid_glyphs); - - if (glyph_string->num_glyphs > GLYPH_ARRAY_SIZE) - g_free(glyphs); - - return Geom::Point(x_offset, y_offset); -} -#endif - - - -unsigned int -PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, Geom::Point p, - SPStyle const *const style) -{ - bool dirty_pattern = false; - - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - cairo_save(cr); - - // this needs to be there to encounter Cairo's userspace locking semantics for set_source - // otherwise gradients won't be shown correctly - // printf("\n _last_tx:%f _last_ty:%f", _last_tx, _last_ty); - cairo_translate(cr, -_last_tx, -_last_ty); - - // create pango layout and context if needed - if (_layout == NULL) { -#ifdef RENDER_WITH_PANGO_CAIRO - //_context = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(pango_cairo_font_map_get_default())); - _layout = pango_cairo_create_layout(cr); -#else - _layout = pango_layout_new((font_factory::Default())->fontContext); -#endif - } - - // create font instance from style and use it - font_instance *tf = font_factory::Default()->FaceFromStyle(style); - if (tf == NULL) { // do something - g_printf("Warning: trouble getting font_instance\n"); - tf = (font_factory::Default())->Face("sans", font_style_to_pos(*style)); - } - PangoFontDescription *adjusted = pango_font_description_copy(tf->descr); - - pango_font_description_set_absolute_size(adjusted, (gint)(style->font_size.computed * PANGO_SCALE)); - pango_layout_set_font_description(_layout, adjusted); - pango_layout_set_text(_layout, text, -1); - - pango_font_description_free(adjusted); - tf->Unref(); - -#ifdef RENDER_WITH_PANGO_CAIRO - pango_cairo_update_layout(cr, _layout); -#else - pango_layout_context_changed(_layout); // is this needed? -#endif - - PangoLayoutLine *line = pango_layout_get_line(_layout, 0); - if (line == NULL) - return 0; - -#ifndef RENDER_WITH_PANGO_CAIRO - // apply the selected font - double size; - PangoLayoutRun *first_run = (PangoLayoutRun *)line->runs->data; - PangoFcFont *fc_font = PANGO_FC_FONT(first_run->item->analysis.font); - FcPattern *fc_pattern = fc_font->font_pattern; - - if ( style->writing_mode.set && - (style->writing_mode.computed == SP_CSS_WRITING_MODE_TB_RL || - style->writing_mode.computed == SP_CSS_WRITING_MODE_TB_LR) ) - { - FcPatternDel(fc_pattern, FC_VERTICAL_LAYOUT); - FcPatternAddBool(fc_pattern, FC_VERTICAL_LAYOUT, FcTrue); - dirty_pattern = true; - } - - cairo_font_face_t *font_face = cairo_ft_font_face_create_for_pattern(fc_pattern); - cairo_set_font_face(cr, font_face); - - if (FcPatternGetDouble(fc_pattern, FC_PIXEL_SIZE, 0, &size) != FcResultMatch) - size = 12.0; - - // adjust size and horizontal flip - cairo_matrix_t matrix; - cairo_get_font_matrix(cr, &matrix); - matrix.xx = size; - matrix.yy = -matrix.xx; - cairo_set_font_matrix(cr, &matrix); -#endif - - if ( style->fill.isColor() - || ( style->fill.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) - { - // set fill style - print_fill_style(cr, style, NULL); - -#ifndef RENDER_WITH_PANGO_CAIRO - Geom::Point cursor(_last_tx, _last_ty); - for (GSList *tmpList = line->runs; tmpList && tmpList->data; tmpList = tmpList->next) { - PangoLayoutRun *run = (PangoLayoutRun *)tmpList->data; - cursor += draw_glyphs(cr, cursor, run->item->analysis.font, run->glyphs, dirty_pattern, false) / PANGO_SCALE; - } -#else - cairo_new_path(cr); - // as pango has inverted origin we simulate the moveto and apply the vertical flip - //cairo_move_to(cr, _last_tx, _last_ty); - cairo_translate(cr, _last_tx, _last_ty); - cairo_scale(cr, 1, -1); - cairo_move_to(cr, 0, 0); - pango_cairo_show_layout_line(cr, line); - cairo_scale(cr, 1, -1); - cairo_translate(cr, -_last_tx, -_last_ty); - -#endif - } - - if (style->stroke.isColor() - || ( style->stroke.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) ) ) - { - // set stroke style - print_stroke_style(cr, style, NULL); - - // paint stroke -#ifndef RENDER_WITH_PANGO_CAIRO - Geom::Point cursor(_last_tx, _last_ty); - for (GSList *tmpList = line->runs; tmpList && tmpList->data; tmpList = tmpList->next) { - PangoLayoutRun *run = (PangoLayoutRun *)tmpList->data; - cursor += draw_glyphs(cr, cursor, run->item->analysis.font, run->glyphs, dirty_pattern, true) / PANGO_SCALE; - } -#else - cairo_new_path(cr); - // as pango has inverted origin we simulate the moveto and apply the vertical flip - //cairo_move_to(cr, _last_tx, _last_ty); - cairo_translate(cr, _last_tx, _last_ty); - cairo_scale(cr, 1, -1); - cairo_move_to(cr, 0, 0); - pango_cairo_layout_line_path(cr, line); - cairo_scale(cr, 1, -1); - cairo_translate(cr, -_last_tx, -_last_ty); -#endif - cairo_stroke(cr); - } - - - cairo_restore(cr); - -#ifndef RENDER_WITH_PANGO_CAIRO - cairo_font_face_destroy(font_face); - - if (dirty_pattern) { - FcPatternDel(fc_pattern, FC_VERTICAL_LAYOUT); - FcPatternAddBool(fc_pattern, FC_VERTICAL_LAYOUT, FcFalse); - } -#endif - - return 0; -} - -/* Helper functions */ - -static void -_concat_transform(cairo_t *cr, double xx, double yx, double xy, double yy, double x0, double y0) -{ - cairo_matrix_t matrix; - - cairo_matrix_init(&matrix, xx, yx, xy, yy, x0, y0); - cairo_transform(cr, &matrix); -} - -static cairo_status_t -_write_callback(void *closure, const unsigned char *data, unsigned int length) -{ - size_t written; - FILE *file = (FILE*)closure; - - written = fwrite (data, 1, length, file); - - if (written == length) - return CAIRO_STATUS_SUCCESS; - else - return CAIRO_STATUS_WRITE_ERROR; -} - -bool -PrintCairoPDF::textToPath(Inkscape::Extension::Print * ext) -{ - return ext->get_param_bool("textToPath"); -} - -#include "clear-n_.h" - -void -PrintCairoPDF::init(void) -{ - /* PDF out */ - (void) Inkscape::Extension::build_from_mem( - "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" - "<name>" N_("PDF Print") "</name>\n" - "<id>" SP_MODULE_KEY_PRINT_CAIRO_PDF "</id>\n" - "<param name=\"bitmap\" type=\"boolean\">false</param>\n" - "<param name=\"resolution\" type=\"string\">72</param>\n" - "<param name=\"destination\" type=\"string\">| lp</param>\n" - "<param name=\"pageBoundingBox\" type=\"boolean\">true</param>\n" - "<param name=\"textToPath\" type=\"boolean\">true</param>\n" - "<param name=\"exportDrawing\" type=\"boolean\">false</param>\n" - "<param name=\"exportCanvas\" type=\"boolean\">false</param>\n" - "<param name=\"exportId\" type=\"string\"></param>\n" - "<print/>\n" - "</inkscape-extension>", new PrintCairoPDF()); -} - - -} /* namespace Internal */ -} /* namespace Extension */ -} /* namespace Inkscape */ - -/* End of GNU GPL code */ - -#endif /* HAVE_CAIRO_PDF */ - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/extension/internal/pdf-cairo.h b/src/extension/internal/pdf-cairo.h deleted file mode 100644 index 2b81fa30e..000000000 --- a/src/extension/internal/pdf-cairo.h +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef EXTENSION_INTERNAL_PDF_CAIRO_H_SEEN -#define EXTENSION_INTERNAL_PDF_CAIRO_H_SEEN - -/** \file - * Declaration of PrintCairoPDF, the internal module used to do PDF printing with Cairo. - */ -/* - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * Ted Gould <ted@gould.cx> - * - * Lauris' original code is in the public domain. - * Ted's changes are licensed under the GNU GPL. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#ifdef HAVE_CAIRO_PDF - -#include "extension/extension.h" -#include "extension/implementation/implementation.h" -#include <set> -#include <string> - -#include "libnrtype/font-instance.h" - -#include "svg/stringstream.h" -#include "sp-gradient.h" - -#include <cairo.h> - -namespace Inkscape { -namespace Extension { -namespace Internal { - -class PrintCairoPDF : public Inkscape::Extension::Implementation::Implementation { - float _width; - float _height; - FILE *_stream; - cairo_t *cr; - cairo_surface_t *pdf_surface; - PangoLayout *_layout; -// PangoContext *_context; - std::vector<float> _alpha_stack; - double _last_tx, _last_ty; - - unsigned short _dpi; - bool _bitmap; - - cairo_pattern_t *create_pattern_for_paint(SPPaintServer const *const paintserver, NRRect const *pbox, float alpha); - - void print_fill_style(cairo_t *cr, SPStyle const *const style, NRRect const *pbox); - void print_stroke_style(cairo_t *cr, SPStyle const *style, NRRect const *pbox); - -#ifndef RENDER_WITH_PANGO_CAIRO - Geom::Point draw_glyphs(cairo_t *cr, Geom::Point p, PangoFont *font, PangoGlyphString *glyph_string, - bool vertical, bool stroke); -#endif - -public: - PrintCairoPDF(void); - virtual ~PrintCairoPDF(void); - - /* Print functions */ - virtual unsigned int setup(Inkscape::Extension::Print *module); - /* - virtual unsigned int set_preview(Inkscape::Extension::Print *module); - */ - - virtual unsigned int begin(Inkscape::Extension::Print *module, SPDocument *doc); - virtual unsigned int finish(Inkscape::Extension::Print *module); - - /* Rendering methods */ - virtual unsigned int bind(Inkscape::Extension::Print *module, Geom::Matrix const *transform, float opacity); - virtual unsigned int release(Inkscape::Extension::Print *module); - virtual unsigned int comment(Inkscape::Extension::Print *module, char const *comment); - virtual unsigned int fill(Inkscape::Extension::Print *module, Geom::PathVector const &pathv, Geom::Matrix const *ctm, SPStyle const *style, - NRRect const *pbox, NRRect const *dbox, NRRect const *bbox); - virtual unsigned int stroke(Inkscape::Extension::Print *module, Geom::PathVector const &pathv, Geom::Matrix const *transform, SPStyle const *style, - NRRect const *pbox, NRRect const *dbox, NRRect const *bbox); - virtual unsigned int image(Inkscape::Extension::Print *module, unsigned char *px, unsigned int w, unsigned int h, unsigned int rs, - Geom::Matrix const *transform, SPStyle const *style); - virtual unsigned int text(Inkscape::Extension::Print *module, char const *text, - Geom::Point p, SPStyle const *style); - - bool textToPath(Inkscape::Extension::Print *ext); - static void init(void); -}; - -} /* namespace Internal */ -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* HAVE_CAIRO_PDF */ - -#endif /* !EXTENSION_INTERNAL_PDF_CAIRO_H_SEEN */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/extension/internal/ps-out.cpp b/src/extension/internal/ps-out.cpp deleted file mode 100644 index ba9338198..000000000 --- a/src/extension/internal/ps-out.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * A quick hack to use the print output to write out a file. This - * then makes 'save as...' Postscript. - * - * Authors: - * Ted Gould <ted@gould.cx> - * - * Copyright (C) 2004 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif -#include "ps-out.h" -#include <print.h> -#include "extension/system.h" -#include "extension/db.h" -#include "extension/output.h" - -namespace Inkscape { -namespace Extension { -namespace Internal { - -bool -PsOutput::check( Inkscape::Extension::Extension * /*module*/ ) -{ - if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_PS)) - return FALSE; - - return TRUE; -} - -/** - \brief This function calls the print system with the filename - \param mod unused - \param doc Document to be saved - \param uri Filename to save to (probably will end in .ps) - - The most interesting thing that this function does is just attach - an '>' on the front of the filename. This is the syntax used to - tell the printing system to save to file. -*/ -void -PsOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) -{ - Inkscape::Extension::Extension * ext; - - ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_PS); - if (ext == NULL) - return; - - bool old_textToPath = ext->get_param_bool("textToPath"); - bool new_val = mod->get_param_bool("textToPath"); - ext->set_param_bool("textToPath", new_val); - - gchar * final_name; - final_name = g_strdup_printf("> %s", uri); - sp_print_document_to_file(doc, final_name); - g_free(final_name); - - ext->set_param_bool("textToPath", old_textToPath); - - return; -} - -#include "clear-n_.h" - -/** - \brief A function allocate a copy of this function. - - This is the definition of postscript out. This function just - calls the extension system with the memory allocated XML that - describes the data. -*/ -void -PsOutput::init (void) -{ - Inkscape::Extension::build_from_mem( - "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" - "<name>" N_("Postscript Output") "</name>\n" - "<id>org.inkscape.output.ps</id>\n" - "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">true</param>\n" - "<param name=\"fontEmbedded\" gui-text=\"" N_("Embed fonts (Type 1 only)") "\" type=\"boolean\">false</param>\n" - "<output>\n" - "<extension>.ps</extension>\n" - "<mimetype>image/x-postscript</mimetype>\n" - "<filetypename>" N_("PostScript (old exporter via print) (*.ps)") "</filetypename>\n" - "<filetypetooltip>" N_("PostScript File") "</filetypetooltip>\n" - "</output>\n" - "</inkscape-extension>", new PsOutput()); - - return; -} - -} } } /* namespace Inkscape, Extension, Implementation */ diff --git a/src/extension/internal/ps-out.h b/src/extension/internal/ps-out.h deleted file mode 100644 index 592f3d70e..000000000 --- a/src/extension/internal/ps-out.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * A quick hack to use the print output to write out a file. This - * then makes 'save as...' Postscript. - * - * Authors: - * Ted Gould <ted@gould.cx> - * - * Copyright (C) 2004 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef EXTENSION_INTERNAL_PS_OUT_H -#define EXTENSION_INTERNAL_PS_OUT_H - -#include "extension/implementation/implementation.h" - -namespace Inkscape { -namespace Extension { -namespace Internal { - -class PsOutput : Inkscape::Extension::Implementation::Implementation { - -public: - bool check(Inkscape::Extension::Extension *module); - void save(Inkscape::Extension::Output *mod, - SPDocument *doc, - gchar const *uri); - static void init(); -}; - -} } } /* namespace Inkscape, Extension, Implementation */ - -#endif /* !EXTENSION_INTERNAL_PS_OUT_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/extension/internal/ps.cpp b/src/extension/internal/ps.cpp deleted file mode 100644 index f8b3d999e..000000000 --- a/src/extension/internal/ps.cpp +++ /dev/null @@ -1,1797 +0,0 @@ -#define __SP_PS_C__ - -/** \file - * PostScript printing. - */ -/* - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * bulia byak <buliabyak@users.sf.net> - * - * Basic printing code, EXCEPT image and - * ascii85 filter is in public domain - * - * Image printing and Ascii85 filter: - * - * Copyright (C) 2006 Johan Engelen - * Copyright (C) 1997-98 Peter Kirchgessner - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * George White <aa056@chebucto.ns.ca> - * Austin Donnelly <austin@gimp.org> - * - * Licensed under GNU GPL - */ - -/* Plain Print */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <signal.h> -#include <errno.h> - -#include <libnr/nr-matrix-fns.h> - -#include <glib/gmem.h> -#include <glib/gstrfuncs.h> -#include <gtk/gtkstock.h> -#include <gtk/gtkvbox.h> -#include <gtk/gtkframe.h> -#include <gtk/gtkradiobutton.h> -#include <gtk/gtkcombo.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkentry.h> -#include <gtk/gtktooltips.h> - -#include <glibmm/i18n.h> -#include "display/nr-arena-item.h" -#include "display/canvas-bpath.h" -#include "sp-item.h" -#include "style.h" -#include "sp-linear-gradient.h" -#include "sp-radial-gradient.h" - -#include "libnrtype/font-instance.h" -#include "libnrtype/font-style-to-pos.h" - -#include <unit-constants.h> - -#include "ps.h" -#include "extension/system.h" -#include "extension/print.h" - -#include "io/sys.h" - -#include <ft2build.h> -#include FT_FREETYPE_H -#include FT_XFREE86_H -#include <pango/pangoft2.h> -#include <string> -#include <iostream> -#include <fstream> -#include <cstring> -#include <cstdio> -#include <cstdlib> -#include <cmath> - -#include <2geom/sbasis-to-bezier.h> -#include <2geom/bezier-curve.h> -#include <2geom/hvlinesegment.h> -#include "helper/geom-curves.h" - -/* -using std::atof; -using std::ceil; -using std::fclose; -using std::ferror; -using std::fflush; -using std::fgetc; -using std::fprintf; --> this line will result 'std::libintl_fprintf' has not been declared -using std::fputc; -using std::fseek; -using std::ifstream; -using std::ios; -using std::memset; -using std::strchr; -using std::strcmp; -using std::strerror; -using std::tmpfile; -*/ -using namespace std; - -namespace Inkscape { -namespace Extension { -namespace Internal { - -PrintPS::PrintPS() : - _stream(NULL), - _dpi(72), - _bitmap(false) -{ - //map font types - _fontTypesMap["Type 1"] = FONT_TYPE1; - _fontTypesMap["TrueType"] = FONT_TRUETYPE; - //TODO: support other font types (cf. embed_font()) -} - -PrintPS::~PrintPS(void) -{ - /* fixme: should really use pclose for popen'd streams */ - if (_stream) fclose(_stream); - if(_begin_stream) fclose(_begin_stream); - if(_fonts) g_tree_destroy(_fonts); - - /* restore default signal handling for SIGPIPE */ -#if !defined(_WIN32) && !defined(__WIN32__) - (void) signal(SIGPIPE, SIG_DFL); -#endif - - return; -} - -unsigned int -PrintPS::setup(Inkscape::Extension::Print * mod) -{ - static gchar const *const pdr[] = {"72", "75", "100", "144", "150", "200", "300", "360", "600", "1200", "2400", NULL}; - -#ifdef TED - Inkscape::XML::Node *repr = ((SPModule *) mod)->repr; -#endif - - unsigned int ret = FALSE; - gchar const *destination = mod->get_param_string("destination"); - - /* Create dialog */ - GtkTooltips *tt = gtk_tooltips_new(); - g_object_ref((GObject *) tt); - gtk_object_sink((GtkObject *) tt); - - GtkWidget *dlg = gtk_dialog_new_with_buttons( - destination ? _("Print Configuration") : _("Print Destination"), -// SP_DT_WIDGET(SP_ACTIVE_DESKTOP)->window, - NULL, - (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - destination ? GTK_STOCK_GO_FORWARD : GTK_STOCK_PRINT, - GTK_RESPONSE_OK, - NULL); - - gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK); - - GtkWidget *vbox = GTK_DIALOG(dlg)->vbox; - gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); - /* Print properties frame */ - GtkWidget *f = gtk_frame_new(_("Print properties")); - gtk_box_pack_start(GTK_BOX(vbox), f, FALSE, FALSE, 4); - GtkWidget *vb = gtk_vbox_new(FALSE, 4); - gtk_container_add(GTK_CONTAINER(f), vb); - gtk_container_set_border_width(GTK_CONTAINER(vb), 4); - /* Print type */ - bool const p2bm = mod->get_param_bool("bitmap"); - GtkWidget *rb = gtk_radio_button_new_with_label(NULL, _("Print using PostScript operators")); - gtk_tooltips_set_tip((GtkTooltips *) tt, rb, - _("Use PostScript vector operators. The resulting image is usually smaller " - "in file size and can be arbitrarily scaled, but alpha transparency " - "and patterns will be lost."), NULL); - if (!p2bm) gtk_toggle_button_set_active((GtkToggleButton *) rb, TRUE); - gtk_box_pack_start(GTK_BOX(vb), rb, FALSE, FALSE, 0); - rb = gtk_radio_button_new_with_label(gtk_radio_button_get_group((GtkRadioButton *) rb), _("Print as bitmap")); - gtk_tooltips_set_tip((GtkTooltips *) tt, rb, - _("Print everything as bitmap. The resulting image is usually larger " - "in file size and cannot be arbitrarily scaled without quality loss, " - "but all objects will be rendered exactly as displayed."), NULL); - if (p2bm) gtk_toggle_button_set_active((GtkToggleButton *) rb, TRUE); - gtk_box_pack_start(GTK_BOX(vb), rb, FALSE, FALSE, 0); - /* Resolution */ - GtkWidget *hb = gtk_hbox_new(FALSE, 4); - gtk_box_pack_start(GTK_BOX(vb), hb, FALSE, FALSE, 0); - GtkWidget *combo = gtk_combo_new(); - gtk_combo_set_value_in_list(GTK_COMBO(combo), FALSE, FALSE); - gtk_combo_set_use_arrows(GTK_COMBO(combo), TRUE); - gtk_combo_set_use_arrows_always(GTK_COMBO(combo), TRUE); - gtk_widget_set_size_request(combo, 64, -1); - gtk_tooltips_set_tip((GtkTooltips *) tt, GTK_COMBO(combo)->entry, - _("Preferred resolution (dots per inch) of bitmap"), NULL); - /* Setup strings */ - GList *sl = NULL; - for (unsigned i = 0; pdr[i] != NULL; i++) { - sl = g_list_prepend(sl, (gpointer) pdr[i]); - } - sl = g_list_reverse(sl); - gtk_combo_set_popdown_strings(GTK_COMBO(combo), sl); - g_list_free(sl); - if (1) { - gchar const *val = mod->get_param_string("resolution"); - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), val); - } - gtk_box_pack_end(GTK_BOX(hb), combo, FALSE, FALSE, 0); - GtkWidget *l = gtk_label_new(_("Resolution:")); - gtk_box_pack_end(GTK_BOX(hb), l, FALSE, FALSE, 0); - - GtkWidget *e = NULL; - /* if the destination isn't already set, we must prompt for it */ - if (!destination) { - /* Print destination frame */ - f = gtk_frame_new(_("Print destination")); - gtk_box_pack_start(GTK_BOX(vbox), f, FALSE, FALSE, 4); - vb = gtk_vbox_new(FALSE, 4); - gtk_container_add(GTK_CONTAINER(f), vb); - gtk_container_set_border_width(GTK_CONTAINER(vb), 4); - - l = gtk_label_new(_("Printer name (as given by lpstat -p);\n" - "leave empty to use the system default printer.\n" - "Use '> filename' to print to file.\n" - "Use '| prog arg...' to pipe to a program.")); - gtk_box_pack_start(GTK_BOX(vb), l, FALSE, FALSE, 0); - - e = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(e), ( destination != NULL - ? destination - : "" )); - gtk_box_pack_start(GTK_BOX(vb), e, FALSE, FALSE, 0); - - // pressing enter in the destination field is the same as clicking Print: - gtk_entry_set_activates_default(GTK_ENTRY(e), TRUE); - } - - gtk_widget_show_all(vbox); - - int const response = gtk_dialog_run(GTK_DIALOG(dlg)); - - g_object_unref((GObject *) tt); - - if (response == GTK_RESPONSE_OK) { - gchar const *fn; - char const *sstr; - - _bitmap = gtk_toggle_button_get_active((GtkToggleButton *) rb); - sstr = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)); - _dpi = (unsigned int) MAX((int)(atof(sstr)), 1); - - /* if the destination was prompted for, record the new value */ - if (e) { - /* Arrgh, have to do something */ - fn = gtk_entry_get_text(GTK_ENTRY(e)); - /* skip leading whitespace, bug #1068483 */ - while (fn && *fn==' ') { fn++; } - /* g_print("Printing to %s\n", fn); */ - - mod->set_param_string("destination", (gchar *)fn); - } - mod->set_param_bool("bitmap", _bitmap); - mod->set_param_string("resolution", (gchar *)sstr); - ret = TRUE; - } - - gtk_widget_destroy(dlg); - - return ret; -} - -unsigned int -PrintPS::begin(Inkscape::Extension::Print *mod, SPDocument *doc) -{ - gboolean epsexport = false; - - - _latin1_encoded_fonts.clear(); - _newlatin1font_proc_defined = false; - - FILE *osf = NULL; - FILE *osp = NULL; - FILE *osf_tmp = NULL; - - gsize bytesRead = 0; - gsize bytesWritten = 0; - GError *error = NULL; - //check whether fonts have to be embedded in the (EPS only) output - bool font_embedded = mod->fontEmbedded(); - gchar const *utf8_fn = mod->get_param_string("destination"); - gchar *local_fn = g_filename_from_utf8( utf8_fn, - -1, &bytesRead, &bytesWritten, &error); - gchar const *fn = local_fn; - - /* TODO: Replace the below fprintf's with something that does the right thing whether in - * gui or batch mode (e.g. --print=blah). Consider throwing an exception: currently one of - * the callers (sp_print_document_to_file, "ret = mod->begin(doc)") wrongly ignores the - * return code. - */ - if (fn != NULL) { - if (*fn == '|') { - fn += 1; - while (g_ascii_isspace(*fn)) fn += 1; -#ifndef WIN32 - osp = popen(fn, "w"); -#else - osp = _popen(fn, "w"); -#endif - if (!osp) { - fprintf(stderr, "inkscape: popen(%s): %s\n", - fn, strerror(errno)); - return 0; - } - _stream = _begin_stream = osp; - } else if (*fn == '>') { - fn += 1; - epsexport = g_str_has_suffix(fn,".eps"); - while (isspace(*fn)) fn += 1; - Inkscape::IO::dump_fopen_call(fn, "K"); - osf = Inkscape::IO::fopen_utf8name(fn, "w+"); - if (!osf) { - fprintf(stderr, "inkscape: fopen(%s): %s\n", - fn, strerror(errno)); - return 0; - } - _begin_stream = osf; - /* if font embedding is requested for EPS export... - * TODO:could be extended to PS export if texttopath=FALSE possible - */ - if(font_embedded && epsexport) - { - /** - * Create temporary file where to print the main "script" part of the EPS document. - * Use an extra stream (_begin_stream) to print the prolog and document setup sections. - * Thus, once all the (main) script part printed, all the fonts used are known and can be embedded - * just after the prolog section, in a Begin(End)Setup section (document setup), - * one Begin(End)Resource (DSC comment) section for each font embedded. - * Then, append the final script part from the temporary file (_stream in this case). - * Reference: Adobe Technical note 5001, "PostScript Document Struturing Conventions Specifications" - * page 19 - */ - osf_tmp = tmpfile(); - if(!osf_tmp) - { - g_warning("Could not create a temporary file for font embedding. Font embedding canceled."); - mod->set_param_bool("fontEmbedded", false); - font_embedded = false; - _stream = osf; - } else _stream = osf_tmp; - } else _stream = osf; - } else { - /* put cwd stuff in here */ - gchar *qn = ( *fn - ? g_strdup_printf("lpr -P %s", fn) /* FIXME: quote fn */ - : g_strdup("lpr") ); -#ifndef WIN32 - osp = popen(qn, "w"); -#else - osp = _popen(qn, "w"); -#endif - if (!osp) { - fprintf(stderr, "inkscape: popen(%s): %s\n", - qn, strerror(errno)); - return 0; - } - g_free(qn); - _stream = _begin_stream = osp; - } - } - - g_free(local_fn); - - if (_stream) { - /* fixme: this is kinda icky */ -#if !defined(_WIN32) && !defined(__WIN32__) - (void) signal(SIGPIPE, SIG_IGN); -#endif - } - - int const res = fprintf(_begin_stream, ( epsexport - ? "%%!PS-Adobe-3.0 EPSF-3.0\n" - : "%%!PS-Adobe-3.0\n" )); - /* flush this to test output stream as early as possible */ - if (fflush(_begin_stream)) { - /*g_print("caught error in sp_module_print_plain_begin\n");*/ - if (ferror(_begin_stream)) { - g_print("Error %d on output stream: %s\n", errno, - g_strerror(errno)); - } - g_print("Printing failed\n"); - /* fixme: should use pclose() for pipes */ - fclose(_begin_stream); - _begin_stream = NULL; - fflush(stdout); - return 0; - } - //TODO: do this same test on _stream - - // width and height in pt - _width = sp_document_width(doc) * PT_PER_PX; - _height = sp_document_height(doc) * PT_PER_PX; - - NRRect d; - bool pageBoundingBox; - bool pageLandscape; - pageBoundingBox = mod->get_param_bool("pageBoundingBox"); - // printf("Page Bounding Box: %s\n", pageBoundingBox ? "TRUE" : "FALSE"); - if (pageBoundingBox) { - d.x0 = d.y0 = 0; - d.x1 = ceil(_width); - d.y1 = ceil(_height); - } else { - SPItem* doc_item = SP_ITEM(sp_document_root(doc)); - sp_item_invoke_bbox(doc_item, &d, sp_item_i2r_affine(doc_item), TRUE); - // convert from px to pt - d.x0 *= PT_PER_PX; - d.x1 *= PT_PER_PX; - d.y0 *= PT_PER_PX; - d.y1 *= PT_PER_PX; - } - - Inkscape::SVGOStringStream os; - if (res >= 0) { - - os << "%%Creator: " << PACKAGE_STRING << "\n"; - // This will become problematic if inkscape gains the - // ability to handle multi paged documents. If this is - // the case the %%Orientation: comments should be - // renamed to %%PageOrientation: and moved to the - // respective pages. - os << "%%Pages: 1\n"; - - // 2004 Dec 10, BFC: - // The point of the following code is (1) to do the thing that's expected by users - // who have done File>New>A4_landscape or ...letter_landscape (i.e., rotate - // the output), while (2) not messing up users who simply want their output wider - // than it is tall (e.g., small figures for inclusion in LaTeX). - // The original patch by WQ only had the w>h condition. - { - double w = (d.x1 - d.x0); // width and height of bounding box, in pt - double h = (d.y1 - d.y0); - pageLandscape = ( - (w > 0. && h > 0.) // empty documents fail this sanity check, have w<0, h<0 - && (w > h) // implies, but does not prove, the user wanted landscape - && (w > 600) // approximate maximum printable width of an A4 - && (!epsexport) // eps should always be portrait - ) - ? true : false; - } - - if (pageLandscape) { - os << "%%Orientation: Landscape\n"; - os << "%%BoundingBox: " << (int) (_height - d.y1) << " " - << (int) d.x0 << " " - << (int) ceil(_height - d.y0) << " " - << (int) ceil(d.x1) << "\n"; - // According to Mike Sweet (the author of CUPS) - // HiResBoundingBox is only appropriate - // for EPS files. This means that we should - // distinguish if we export to ps or eps here. - // FIXME: I couldn't find HiResBoundingBox in the PS - // reference manual, so I guess we should skip - // it. - os << "%%HiResBoundingBox: " << (_height - d.y1) << " " - << d.x0 << " " - << (_height - d.y0) << " " - << d.x1 << "\n"; - if (!epsexport) { - os << "%%DocumentMedia: plain " - << (int) ceil(_height) << " " - << (int) ceil(_width) << " " - << "0 () ()\n"; - } - } else { - os << "%%Orientation: Portrait\n"; - os << "%%BoundingBox: " << (int) d.x0 << " " - << (int) d.y0 << " " - << (int) ceil(d.x1) << " " - << (int) ceil(d.y1) << "\n"; - os << "%%HiResBoundingBox: " << d.x0 << " " - << d.y0 << " " - << d.x1 << " " - << d.y1 << "\n"; - if (!epsexport) { - os << "%%DocumentMedia: plain " - << (int) ceil(_width) << " " - << (int) ceil(_height) << " " - << "0 () ()\n"; - } - } - - os << "%%EndComments\n"; - /* If font embedding requested, begin document setup section where to include font resources */ - if(font_embedded) os << "%%BeginSetup\n";/* Resume it later with Begin(End)Resource sections for font embedding. So, for now, we are done with the prolog/setup part. */ - gint ret = fprintf(_begin_stream, "%s", os.str().c_str()); - if(ret < 0) return ret; - - /* Main Script part (after document setup) begins */ - /* Empty os from all previous printing */ - std::string clrstr = ""; - os.str(clrstr); - // This will become problematic if we print multi paged documents: - os << "%%Page: 1 1\n"; - - if (pageLandscape) { - os << "90 rotate\n"; - if (_bitmap) { - os << "0 " << (int) -ceil(_height) << " translate\n"; - } - } else { - if (!_bitmap) { - os << "0 " << (int) ceil(_height) << " translate\n"; - } - } - - if (!_bitmap) { - os << PT_PER_PX << " " << -PT_PER_PX << " scale\n"; - // from now on we can output px, but they will be treated as pt - } - - /* As a new PS document is created, _fontlist has to be reinitialized (unref fonts from possible former PS docs) */ - _fonts = g_tree_new_full((GCompareDataFunc)strcmp, NULL, (GDestroyNotify)g_free, (GDestroyNotify)g_free); - } - - os << "0 0 0 setrgbcolor\n" - << "[] 0 setdash\n" - << "1 setlinewidth\n" - << "0 setlinejoin\n" - << "0 setlinecap\n"; - - /* FIXME: This function is declared to return unsigned, whereas fprintf returns a signed int * - * that can be zero if the first fprintf failed (os is empty) or "negative" (i.e. very positive - * in unsigned int interpretation) if the first fprintf failed but this one succeeds, or - * positive if both succeed. */ - return fprintf(_stream, "%s", os.str().c_str()); -} - -unsigned int -PrintPS::finish(Inkscape::Extension::Print *mod) -{ - if (!_stream) return 0; - - if (_bitmap) { - double const dots_per_pt = _dpi / PT_PER_IN; - - double const x0 = 0.0; - double const y0 = 0.0; - double const x1 = x0 + _width; - double const y1 = y0 + _height; - - /* Bitmap width/height in bitmap dots. */ - int const width = (int) (_width * dots_per_pt + 0.5); - int const height = (int) (_height * dots_per_pt + 0.5); - - Geom::Matrix affine; - affine[0] = width / ((x1 - x0) * PX_PER_PT); - affine[1] = 0.0; - affine[2] = 0.0; - affine[3] = height / ((y1 - y0) * PX_PER_PT); - affine[4] = -affine[0] * x0; - affine[5] = -affine[3] * y0; - - nr_arena_item_set_transform(mod->root, &affine); - - guchar *const px = g_new(guchar, 4 * width * 64); - - for (int y = 0; y < height; y += 64) { - /* Set area of interest. */ - NRRectL bbox; - bbox.x0 = 0; - bbox.y0 = y; - bbox.x1 = width; - bbox.y1 = MIN(height, y + 64); - - /* Update to renderable state. */ - NRGC gc(NULL); - gc.transform.setIdentity(); - nr_arena_item_invoke_update(mod->root, &bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE); - /* Render */ - /* This should take guchar* instead of unsigned char*) */ - NRPixBlock pb; - nr_pixblock_setup_extern(&pb, NR_PIXBLOCK_MODE_R8G8B8A8N, - bbox.x0, bbox.y0, bbox.x1, bbox.y1, - (guchar*)px, 4 * width, FALSE, FALSE); - memset(px, 0xff, 4 * width * 64); - nr_arena_item_invoke_render(NULL, mod->root, &bbox, &pb, 0); - /* Blitter goes here */ - Geom::Matrix imgt; - imgt[0] = (bbox.x1 - bbox.x0) / dots_per_pt; - imgt[1] = 0.0; - imgt[2] = 0.0; - imgt[3] = (bbox.y1 - bbox.y0) / dots_per_pt; - imgt[4] = 0.0; - imgt[5] = _height - y / dots_per_pt - (bbox.y1 - bbox.y0) / dots_per_pt; - - print_image(_stream, px, bbox.x1 - bbox.x0, bbox.y1 - bbox.y0, 4 * width, &imgt); - } - - g_free(px); - } - - fprintf(_stream, "showpage\n"); - int const res = fprintf(_stream, "%%%%EOF\n"); - - /* Flush stream to be sure. */ - (void) fflush(_stream); - - char c; - /* If font embedding... */ - if(mod->get_param_bool("fontEmbedded")) - { - /* Close the document setup section that had been started (because all the needed resources are supposed to be included now) */ - /*res = */fprintf(_begin_stream, "%s", "%%EndSetup\n"); - /* If font embedding requested, the following PS script part was printed to a different file from the prolog/setup, so script part (current _stream) needs to be copied to prolog/setup file to get the complete (E)PS document */ - if(fseek(_stream, 0, SEEK_SET) == 0) - { - while((c = fgetc(_stream))!=EOF) fputc(c, _begin_stream); - } - fclose(_stream); - _stream = _begin_stream; - } - - /* fixme: should really use pclose for popen'd streams */ - fclose(_stream); - _stream = NULL; - - _latin1_encoded_fonts.clear(); - - g_tree_destroy(_fonts); - - return res; -} - -unsigned int -PrintPS::bind(Inkscape::Extension::Print */*mod*/, Geom::Matrix const *transform, float /*opacity*/) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - Inkscape::SVGOStringStream os; - os << "gsave [" << (*transform)[0] << " " - << (*transform)[1] << " " - << (*transform)[2] << " " - << (*transform)[3] << " " - << (*transform)[4] << " " - << (*transform)[5] << "] concat\n"; - - return fprintf(_stream, "%s", os.str().c_str()); -} - -unsigned int -PrintPS::release(Inkscape::Extension::Print */*mod*/) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - return fprintf(_stream, "grestore\n"); -} - -unsigned int -PrintPS::comment(Inkscape::Extension::Print */*mod*/, char const *comment) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - return fprintf(_stream, "%%! %s\n",comment); -} - -void -PrintPS::print_fill_style(SVGOStringStream &os, SPStyle const *const style, NRRect const *pbox) -{ - g_return_if_fail( style->fill.isColor() - || ( style->fill.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ); - - if (style->fill.isColor()) { - float rgb[3]; - sp_color_get_rgb_floatv(&style->fill.value.color, rgb); - - os << rgb[0] << " " << rgb[1] << " " << rgb[2] << " setrgbcolor\n"; - - } else { - g_assert( style->fill.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ); - - if (SP_IS_LINEARGRADIENT(SP_STYLE_FILL_SERVER(style))) { - - SPLinearGradient *lg = SP_LINEARGRADIENT(SP_STYLE_FILL_SERVER(style)); - Geom::Point p1 (lg->x1.computed, lg->y1.computed); - Geom::Point p2 (lg->x2.computed, lg->y2.computed); - if (pbox && SP_GRADIENT(lg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { - // convert to userspace - Geom::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0); - p1 *= bbox2user; - p2 *= bbox2user; - } - - os << "<<\n/ShadingType 2\n/ColorSpace /DeviceRGB\n"; - os << "/Coords [" << p1[Geom::X] << " " << p1[Geom::Y] << " " << p2[Geom::X] << " " << p2[Geom::Y] <<"]\n"; - os << "/Extend [true true]\n"; - os << "/Domain [0 1]\n"; - os << "/Function <<\n/FunctionType 3\n/Functions\n[\n"; - - sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built - for (unsigned i = 0; i + 1 < lg->vector.stops.size(); i++) { - float rgb[3]; - sp_color_get_rgb_floatv(&lg->vector.stops[i].color, rgb); - os << "<<\n/FunctionType 2\n/Domain [0 1]\n"; - os << "/C0 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n"; - sp_color_get_rgb_floatv(&lg->vector.stops[i+1].color, rgb); - os << "/C1 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n"; - os << "/N 1\n>>\n"; - } - os << "]\n/Domain [0 1]\n"; - os << "/Bounds [ "; - for (unsigned i = 0; i + 2 < lg->vector.stops.size(); i++) { - os << lg->vector.stops[i+1].offset <<" "; - } - os << "]\n"; - os << "/Encode [ "; - for (unsigned i = 0; i + 1 < lg->vector.stops.size(); i++) { - os << "0 1 "; - } - os << "]\n"; - os << ">>\n>>\n"; - - } else if (SP_IS_RADIALGRADIENT(SP_STYLE_FILL_SERVER(style))) { - - SPRadialGradient *rg = SP_RADIALGRADIENT(SP_STYLE_FILL_SERVER(style)); - Geom::Point c(rg->cx.computed, rg->cy.computed); - Geom::Point f(rg->fx.computed, rg->fy.computed); - double r = rg->r.computed; - if (pbox && SP_GRADIENT(rg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { - // convert to userspace - Geom::Matrix const bbox2user(pbox->x1 - pbox->x0, 0, - 0, pbox->y1 - pbox->y0, - pbox->x0, pbox->y0); - c *= bbox2user; - f *= bbox2user; - r *= bbox2user.descrim(); - } - - os << "<<\n/ShadingType 3\n/ColorSpace /DeviceRGB\n"; - os << "/Coords ["<< f[Geom::X] <<" "<< f[Geom::Y] <<" 0 "<< c[Geom::X] <<" "<< c[Geom::Y] <<" "<< r <<"]\n"; - os << "/Extend [true true]\n"; - os << "/Domain [0 1]\n"; - os << "/Function <<\n/FunctionType 3\n/Functions\n[\n"; - - sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built - for (unsigned i = 0; i + 1 < rg->vector.stops.size(); i++) { - float rgb[3]; - sp_color_get_rgb_floatv(&rg->vector.stops[i].color, rgb); - os << "<<\n/FunctionType 2\n/Domain [0 1]\n"; - os << "/C0 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n"; - sp_color_get_rgb_floatv(&rg->vector.stops[i+1].color, rgb); - os << "/C1 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n"; - os << "/N 1\n>>\n"; - } - os << "]\n/Domain [0 1]\n"; - os << "/Bounds [ "; - for (unsigned i = 0; i + 2 < rg->vector.stops.size(); i++) { - os << rg->vector.stops[i+1].offset << " "; - } - os << "]\n"; - os << "/Encode [ "; - for (unsigned i = 0; i + 1 < rg->vector.stops.size(); i++) { - os << "0 1 "; - } - os << "]\n"; - os << ">>\n>>\n"; - } - } -} - -void -PrintPS::print_stroke_style(SVGOStringStream &os, SPStyle const *style) -{ - float rgb[3]; - sp_color_get_rgb_floatv(&style->stroke.value.color, rgb); - - os << rgb[0] << " " << rgb[1] << " " << rgb[2] << " setrgbcolor\n"; - - // There are rare cases in which for a solid line stroke_dasharray_set is true. To avoid - // invalid PS-lines such as "[0.0000000 0.0000000] 0.0000000 setdash", which should be "[] 0 setdash", - // we first check if all components of stroke_dash.dash are 0. - bool LineSolid = true; - if (style->stroke_dash.n_dash && - style->stroke_dash.dash ) - { - int i = 0; - while (LineSolid && (i < style->stroke_dash.n_dash)) { - if (style->stroke_dash.dash[i] > 0.00000001) - LineSolid = false; - i++; - } - if (!LineSolid) { - os << "["; - for (i = 0; i < style->stroke_dash.n_dash; i++) { - if (i > 0) { - os << " "; - } - os << style->stroke_dash.dash[i]; - } - os << "] " << style->stroke_dash.offset << " setdash\n"; - } else { - os << "[] 0 setdash\n"; - } - } else { - os << "[] 0 setdash\n"; - } - - os << style->stroke_width.computed << " setlinewidth\n"; - os << style->stroke_linejoin.computed << " setlinejoin\n"; - os << style->stroke_linecap.computed << " setlinecap\n"; -} - - -unsigned int -PrintPS::fill(Inkscape::Extension::Print *mod, Geom::PathVector const &pathv, Geom::Matrix const *ctm, SPStyle const *const style, - NRRect const *pbox, NRRect const *dbox, NRRect const *bbox) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - if ( style->fill.isColor() - || ( style->fill.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) - { - Inkscape::SVGOStringStream os; - - os << "gsave\n"; - - print_fill_style(os, style, pbox); - - print_pathvector(os, pathv); - - if (style->fill_rule.computed == SP_WIND_RULE_EVENODD) { - if (style->fill.isColor()) { - os << "eofill\n"; - } else { - g_assert( style->fill.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ); - SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style)); - os << "eoclip\n"; - if (g->gradientTransform_set) { - os << "gsave [" << g->gradientTransform[0] << " " << g->gradientTransform[1] - << " " << g->gradientTransform[2] << " " << g->gradientTransform[3] - << " " << g->gradientTransform[4] << " " << g->gradientTransform[5] << "] concat\n"; - } - os << "shfill\n"; - if (g->gradientTransform_set) { - os << "grestore\n"; - } - } - } else { - if (style->fill.isColor()) { - os << "fill\n"; - } else { - g_assert( style->fill.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ); - SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style)); - os << "clip\n"; - if (g->gradientTransform_set) { - os << "gsave [" << g->gradientTransform[0] << " " << g->gradientTransform[1] - << " " << g->gradientTransform[2] << " " << g->gradientTransform[3] - << " " << g->gradientTransform[4] << " " << g->gradientTransform[5] << "] concat\n"; - } - os << "shfill\n"; - if (g->gradientTransform_set) { - os << "grestore\n"; - } - } - } - - os << "grestore\n"; - - fprintf(_stream, "%s", os.str().c_str()); - } - - return 0; -} - - -unsigned int -PrintPS::stroke(Inkscape::Extension::Print *mod, Geom::PathVector const &pathv, Geom::Matrix const *ctm, SPStyle const *style, - NRRect const *pbox, NRRect const *dbox, NRRect const *bbox) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - if (style->stroke.isColor()) { - Inkscape::SVGOStringStream os; - - print_stroke_style(os, style); - - print_pathvector(os, pathv); - - os << "stroke\n"; - - fprintf(_stream, "%s", os.str().c_str()); - } - - return 0; -} - -unsigned int -PrintPS::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w, unsigned int h, unsigned int rs, - Geom::Matrix const *transform, SPStyle const *style) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - return print_image(_stream, px, w, h, rs, transform); -} - -/* PSFontName is now useless (cf. text() method code) */ -char const * -PrintPS::PSFontName(SPStyle const *style) -{ - font_instance *tf = font_factory::Default()->FaceFromStyle(style); - - char const *n; - char name_buf[256]; - - // PS does not like spaces in fontnames, replace them with the usual dashes. - - if (tf) { - tf->PSName(name_buf, sizeof(name_buf)); - n = g_strdelimit(name_buf, " ", '-'); - tf->Unref(); - } else { - // 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 - bool i = (style->font_style.value == SP_CSS_FONT_STYLE_ITALIC); - bool o = (style->font_style.value == SP_CSS_FONT_STYLE_OBLIQUE); - bool b = (style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLD) || - (style->font_weight.value >= SP_CSS_FONT_WEIGHT_500 && style->font_weight.value <= SP_CSS_FONT_WEIGHT_900); - - n = g_strdup_printf("%s%s%s%s", - g_strdelimit(style->text->font_family.value, " ", '-'), - (b || i || o) ? "-" : "", - (b) ? "Bold" : "", - (i) ? "Italic" : ((o) ? "Oblique" : "") ); - } - - return g_strdup(n); -} - -//LSB = Least Significant Byte -//converts 4-byte array to "LSB first" to "LSB last" -/** -* (Used by PrintPS::embed_t1 (from libgnomeprint/gnome-font-face.c), -* to get the length of data segment (bytes 3-6 in IBM PC (PostScript) font file format. -* Reference: Adobe technical note 5040, "Supporting Downloadable PostScript -* Language Fonts", page 9) -*/ - -#define INT32_LSB_2_5(q) ((q)[2] + ((q)[3] << 8) + ((q)[4] << 16) + ((q)[5] << 24)) - -/** -* \brief For "Type 1" font only, print font data in output stream, to embed font data in PS output. -* \param os Stream of output. -* \param font Font whose data to embed. -* \return FALSE if font embedding canceled (due to error or not supported font type), TRUE otherwise -* TODO: enable font embedding for True Type -*/ -//adapted more/less from libgnomeprint/gnome_font_face_ps_embed_t1() -bool -PrintPS::embed_t1 (SVGOStringStream &os, font_instance* font) -{ - //check font type - FT_Face font_face = pango_ft2_font_get_face(font->pFont); - const FT_String* font_type = FT_Get_X11_Font_Format(font_face); - g_return_val_if_fail (_fontTypesMap[font_type] == FONT_TYPE1, false); - //get font filename, stream to font file and size - FT_Stream font_stream = font_face->stream; - const char* font_filename = (char*) font_stream->pathname.pointer; - unsigned long font_stream_size = font_stream->size; - //first detect if font file is in IBM PC format - /** - * if first byte is 0x80, font file is pfb, do the same as a pfb to pfa converter - * Reference: Adobe technical note 5040, "Supporting Downloadable PostScript - * Language Fonts", page 9 - * else: include all the ASCII data in the font pfa file - **/ - char* buf = new char[7]; - unsigned char* buffer = new unsigned char[7];//for the 6 header bytes (data segment length is unknown at this point) and final '\0' - std::string ascii_data;//for data segment "type 1" in IBM PC Format - //read the 6 header bytes - //for debug: g_warning("Reading from font file %s...", font_filename); - font_stream->close(font_stream); - ifstream font_file (font_filename, ios::in|ios::binary); - if (!font_file.is_open()) { - g_warning ("file %s: line %d: Cannot open font file %s", __FILE__, __LINE__, font_filename); - return false; - } - font_file.read(buf, 6); - buffer = (unsigned char*) buf; - - //If font file is pfb, do the same as pfb to pfa converter - //check byte 1 - if (buffer[0] == 0x80) { - const char hextab[17] = "0123456789abcdef"; - unsigned long offset = 0; - - while (offset < font_stream_size) { - gint length, i; - if (buffer[0] != 0x80) { - g_warning ("file %s: line %d: Corrupt %s", __FILE__, __LINE__, font_filename); - //TODO: print some default font data anyway like libgnomeprint/gnome_font_face_ps_embed_empty - return false; - } - switch (buffer[1]) { - case 1: - //get data segment length from bytes 3-6 - //(Note: byte 1 is first byte in comments to match Adobe technical note 5040, but index 0 in code) - length = INT32_LSB_2_5 (buffer); - offset += 6; - //resize the buffer to fit the data segment length - delete [] buf; - buf = new char[length + 1]; - buffer = new unsigned char[length + 1]; - //read and print all the data segment length - font_file.read(buf, length); - buffer = (unsigned char*) buf; - /** - * Assigning a part from the buffer of length "length" ensures - * that no incorrect extra character will be printed and make the PS output invalid - * That was the case with the code: - * os << buffer; - * (A substring method could have been used as well.) - */ - ascii_data.assign(buf, 0, length); - os << ascii_data; - offset += length; - //read next 6 header bytes - font_file.read(buf, 6); - break; - case 2: - length = INT32_LSB_2_5 (buffer); - offset += 6; - //resize the buffer to fit the data segment length - delete [] buf; - buf = new char[length + 1]; - buffer = new unsigned char[length + 1]; - //read and print all the data segment length - font_file.read(buf, length); - buffer = (unsigned char*) buf; - for (i = 0; i < length; i++) { - os << hextab[buffer[i] >> 4]; - os << hextab[buffer[i] & 15]; - offset += 1; - if ((i & 31) == 31 || i == length - 1) - os << "\n"; - } - //read next 6 header bytes - font_file.read(buf, 6); - break; - case 3: - /* Finished */ - os << "\n"; - offset = font_stream_size; - break; - default: - os << "%%%ERROR: Font file corrupted at byte " << offset << "\n"; - //TODO: print some default font data anyway like libgnomeprint/gnome_font_face_ps_embed_empty - return false; - } - } - } - //else: font file is pfa, include all directly - else { - //font is not in IBM PC format, all the file content can be directly printed - //resize buffer - delete [] buf; - buf = new char[font_stream_size + 1]; - delete [] buffer; - font_file.seekg (0, ios::beg); - font_file.read(buf, font_stream_size); - /** - * Assigning a part from the buffer of length "length" ensures - * that no incorrect extra character will be printed and make the PS output invalid - * That was the case with the code: - * os << buffer; - * (A substring method could have been used as well.) - */ - ascii_data.assign(buf, 0, font_stream_size); - os << ascii_data; - } - font_file.close(); - delete [] buf; - buf = NULL; - buffer = NULL;// Clear buffer to prevent using invalid memory reference. - - char font_psname[256]; - font->PSName(font_psname, sizeof(font_psname)); - FT_Long font_num_glyphs = font_face->num_glyphs; - if (font_num_glyphs < 256) { - gint glyph; - /* 8-bit vector */ - os << "(" << font_psname << ") cvn findfont dup length dict begin\n"; - os << "{1 index /FID ne {def} {pop pop} ifelse} forall\n"; - os << "/Encoding [\n"; - for (glyph = 0; glyph < 256; glyph++) { - guint g; - gchar c[256]; - FT_Error status; - g = (glyph < font_num_glyphs) ? glyph : 0; - status = FT_Get_Glyph_Name (font_face, g, c, 256); - - if (status != FT_Err_Ok) { - g_warning ("file %s: line %d: Glyph %d has no name in %s", __FILE__, __LINE__, g, font_filename); - g_snprintf (c, 256, ".notdef"); - } - - os << "/" << c << ( ((glyph & 0xf) == 0xf)?"\n":" " ); - } - os << "] def currentdict end\n"; - //TODO: manage several font instances for same ps name like in libgnomeprint/gnome_print_ps2_set_font_real() - //gf_pso_sprintf (pso, "(%s) cvn exch definefont pop\n", pso->encodedname); - os << "(" << font_psname << ") cvn exch definefont pop\n"; - } else { - gint nfonts, i, j; - /* 16-bit vector */ - nfonts = (font_num_glyphs + 255) >> 8; - - os << "32 dict begin\n"; - /* Common entries */ - os << "/FontType 0 def\n"; - os << "/FontMatrix [1 0 0 1 0 0] def\n"; - os << "/FontName (" << font_psname << "-Glyph-Composite) cvn def\n"; - os << "/LanguageLevel 2 def\n"; - - /* Type 0 entries */ - os << "/FMapType 2 def\n"; - - /* Bitch 'o' bitches */ - os << "/FDepVector [\n"; - - for (i = 0; i < nfonts; i++) { - os << "(" << font_psname << ") cvn findfont dup length dict begin\n"; - os << "{1 index /FID ne {def} {pop pop} ifelse} forall\n"; - os << "/Encoding [\n"; - for (j = 0; j < 256; j++) { - gint glyph; - gchar c[256]; - FT_Error status; - glyph = 256 * i + j; - if (glyph >= font_num_glyphs) - glyph = 0; - status = FT_Get_Glyph_Name (font_face, glyph, c, 256); - if (status != FT_Err_Ok) { - g_warning ("file %s: line %d: Glyph %d has no name in %s", __FILE__, __LINE__, glyph, font_filename); - g_snprintf (c, 256, ".notdef"); - } - os << "/" << c << ( ((j & 0xf) == 0xf)?"\n":" " ); - } - os << "] def\n"; - os << "currentdict end (" << font_psname << "-Glyph-Page-"; - os << std::dec << i; - os << ") cvn exch definefont\n"; - } - os << "] def\n"; - os << "/Encoding [\n"; - for (i = 0; i < 256; i++) { - gint fn; - fn = (i < nfonts) ? i : 0; - os << std::dec << fn; - os << ( ((i & 0xf) == 0xf) ? "\n" : " " ); - } - os << "] def\n"; - os << "currentdict end\n"; - //TODO: manage several font instances for same ps name like in libgnomeprint/gnome_print_ps2_set_font_real() - //gf_pso_sprintf (pso, "(%s) cvn exch definefont pop\n", pso->encodedname); - os << "(" << font_psname << ") cvn exch definefont pop\n"; - } - //font embedding completed - return true; -} - - - -/** -* \brief Print font data in output stream, to embed font data in PS output. -* \param os Stream of output. -* \param font Font whose data to embed. -* \return FALSE if font embedding canceled (due to error or not supported font type), TRUE otherwise -*/ -//adapted from libgnomeprint/gnome_font_face_ps_embed() -bool PrintPS::embed_font(SVGOStringStream &os, font_instance* font) -{ - //Hinted at by a comment in libgnomeprint/fcpattern_to_gp_font_entry() - //Determining the font type in the "Pango way" - FT_Face font_face = pango_ft2_font_get_face(font->pFont); - const FT_String* font_type = FT_Get_X11_Font_Format(font_face); - - /** - * Possible values of "font_type": Type 1, TrueType, etc. - * Embedding available only for Type 1 fonts so far. - */ - //TODO: provide support for other font types (TrueType is a priority) - switch(_fontTypesMap[font_type]) - { - case FONT_TYPE1: - return embed_t1 (os, font); - //TODO: implement TT font embedding - /*case FONT_TRUETYPE: - embed_tt (os, font); - break;*/ - default: - g_warning("Unknown (not supported) font type for embedding: %s", font_type); - //TODO: embed something like in libgnomeprint/gnome_font_face_ps_embed_empty(); - return false; - } -} - - -/** -* \brief Converts UTF-8 string to sequence of glyph numbers for PostScript string (cf. "show" commands.). -* \param os Stream of output. -* \param font Font used for unicode->glyph mapping. -* \param unistring UTF-8 encoded string to convert. -*/ -void PrintPS::print_glyphlist(SVGOStringStream &os, font_instance* font, Glib::ustring unistring) -{ - //iterate through unicode chars in unistring - Glib::ustring::iterator unistring_iter; - gunichar unichar; - gint glyph_index, glyph_page; - - FT_Face font_face = pango_ft2_font_get_face(font->pFont); - FT_Long font_num_glyphs = font_face->num_glyphs; - //whether font has more than one glyph pages (16-bit encoding) - bool two_bytes_encoded = (font_num_glyphs > 255); - - for (unistring_iter = unistring.begin(); unistring_iter!=unistring.end(); unistring_iter++) - { - //get unicode char - unichar = *unistring_iter; - //get matching glyph index in current font for unicode char - //default glyph index is 0 for undefined font character (glyph unavailable) - //TODO: if glyph unavailable for current font, use a default font among the most Unicode-compliant - e.g. Bitstream Cyberbit - I guess - glyph_index = font->MapUnicodeChar(unichar); - //if more than one glyph pages for current font (16-bit encoding), - if(two_bytes_encoded) - { - //add glyph page before glyph index. - glyph_page = (glyph_index >> 8) & 0xff; - os << "\\"; - //convert in octal code before printing - os << std::oct << glyph_page; - } - //(If one page - 8-bit encoding -, nothing to add.) - //TODO: explain the following line inspired from libgnomeprint/gnome_print_ps2_glyphlist() - glyph_index = glyph_index & 0xff; - //TODO: mark glyph as used for current font, if Inkscape has to embed minimal font data in PS - os << "\\"; - //convert in octal code before printing - os << std::oct << glyph_index; - } -} - -unsigned int -PrintPS::text(Inkscape::Extension::Print *mod, char const *text, Geom::Point p, - SPStyle const *const style) -{ - if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. - if (_bitmap) return 0; - - //check whether fonts have to be embedded in the PS output - //if not, use the former way of Inkscape to print text - gboolean font_embedded = mod->fontEmbedded(); - - Inkscape::SVGOStringStream os; - //find font - /** - * A font_instance object is necessary for the next steps, - * that's why using PSFontName() method just to get the PS fontname - * is not enough and not appropriate - */ - font_instance *tf = font_factory::Default()->FaceFromStyle(style); - - const gchar *fn = NULL; - char name_buf[256]; - - //check whether font was found - /** - * This check is not strictly reliable - * since Inkscape returns a default font if font not found. - * This is just to be consistent with the method PSFontName(). - */ - if (tf) { - //get font PS name - tf->PSName(name_buf, sizeof(name_buf)); - fn = name_buf; - } else { - // this system does not have this font, so cancel font embedding... - font_embedded = FALSE; - //this case seems to never happen since Inkscape uses a default font instead (like BitstreamVeraSans on Windows) - g_warning("Font %s not found.", fn); - //...and just use the name from SVG in the hope that PS interpreter will make sense of it - bool i = (style->font_style.value == SP_CSS_FONT_STYLE_ITALIC); - bool o = (style->font_style.value == SP_CSS_FONT_STYLE_OBLIQUE); - bool b = (style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLD) || - (style->font_weight.value >= SP_CSS_FONT_WEIGHT_500 && style->font_weight.value <= SP_CSS_FONT_WEIGHT_900); - - fn = g_strdup_printf("%s%s%s%s", - g_strdelimit(style->text->font_family.value, " ", '-'), - (b || i || o) ? "-" : "", - (b) ? "Bold" : "", - (i) ? "Italic" : ((o) ? "Oblique" : "") ); - } - - /** - * If font embedding is requested, tempt to embed the font the first time it is used, once and for all. - * There is no selection of the glyph descriptions to embed, based on the characters used effectively in the document. - * (TODO?) - * Else, back to the former way of printing. - */ - gpointer is_embedded; - //if not first time the font is used and if font embedding requested, check whether the font has been embedded (successfully the first time). - if(g_tree_lookup_extended(_fonts, fn, NULL, &is_embedded)) font_embedded = font_embedded && (strcmp((char *)is_embedded, "TRUE") == 0); - else - { - //first time the font is used - if(font_embedded) - { - //embed font in PS output - //adapted from libgnomeprint/gnome_print_ps2_close() - os << "%%BeginResource: font " << fn << "\n"; - font_embedded = embed_font(os, tf); - os << "%%EndResource: font " << fn << "\n"; - if(!font_embedded) g_warning("Font embedding canceled for font: %s", fn); - else fprintf(_begin_stream, "%s", os.str().c_str()); - //empty os before resume printing to the script stream - std::string clrstr = ""; - os.str(clrstr); - - } - //add to the list - g_tree_insert(_fonts, g_strdup(fn), g_strdup((font_embedded)?"TRUE":"FALSE")); - } - - Glib::ustring s; - // Escape chars - Inkscape::SVGOStringStream escaped_text; - //if font embedding, all characters will be converted to glyph indices (cf. PrintPS::print_glyphlist()), - //so no need to escape characters - //else back to the old way, i.e. escape chars: '\',')','(' and UTF-8 ones - if(font_embedded) s = text; - else { - escaped_text << std::oct; - for (gchar const *p_text = text ; *p_text ; p_text = g_utf8_next_char(p_text)) { - gunichar const c = g_utf8_get_char(p_text); - if (c == '\\' || c == ')' || c == '(') - escaped_text << '\\' << static_cast<char>(c); - else if (c >= 0x80) - escaped_text << '\\' << c; - else - escaped_text << static_cast<char>(c); - } - } - - os << "gsave\n"; - - // set font - if(font_embedded) os << "/" << fn << " findfont\n"; - else { - if (_latin1_encoded_fonts.find(fn) == _latin1_encoded_fonts.end()) { - if (!_newlatin1font_proc_defined) { - // input: newfontname, existingfontname - // output: new font object, also defined to newfontname - os << "/newlatin1font " // name of the proc - "{findfont dup length dict copy " // load the font and create a copy of it - "dup /Encoding ISOLatin1Encoding put " // change the encoding in the copy - "definefont} def\n"; // create the new font and leave it on the stack, define the proc - _newlatin1font_proc_defined = true; - } - if(strchr(fn, ' ') == NULL) - os << "/" << fn << "-ISOLatin1 /" << fn << " newlatin1font\n"; - else - os << "(/" << fn << "-ISOLatin1) (/" << fn << ") newlatin1font\n"; - _latin1_encoded_fonts.insert(fn); - } else - if(strchr(fn, ' ') == NULL) - os << "/" << fn << "-ISOLatin1 findfont\n"; - else - os << "(/" << fn << "-ISOLatin1) findfont\n"; - } - os << style->font_size.computed << " scalefont\n"; - os << "setfont\n"; - //The commented line beneath causes Inkscape to crash under Linux but not under Windows - //g_free((void*) fn); - - if ( style->fill.isColor() - || ( style->fill.isPaintserver() - && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) ) - { - // set fill style - print_fill_style(os, style, NULL); - // FIXME: we don't know the pbox of text, so have to pass NULL. This means gradients with - // bbox units won't work with text. However userspace gradients don't work with text either - // (text is black) for some reason. - - os << "newpath\n"; - os << p[Geom::X] << " " << p[Geom::Y] << " moveto\n"; - os << "("; - if(font_embedded) print_glyphlist(os, tf, s); - else os << escaped_text.str(); - os << ") show\n"; - } - - if (style->stroke.isColor()) { - - // set stroke style - print_stroke_style(os, style); - - // paint stroke - os << "newpath\n"; - os << p[Geom::X] << " " << p[Geom::Y] << " moveto\n"; - os << "("; - if(font_embedded) print_glyphlist(os, tf, s); - else os << escaped_text.str(); - os << ") false charpath stroke\n"; - } - - if(tf) tf->Unref(); - - os << "grestore\n"; - - fprintf(_stream, "%s", os.str().c_str()); - - return 0; -} - - - -/* PostScript helpers */ - -void -PrintPS::print_pathvector(SVGOStringStream &os, Geom::PathVector const &pathv) -{ - if (pathv.empty()) - return; - - os << "newpath\n"; - - for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) { - - os << it->initialPoint()[Geom::X] << " " << it->initialPoint()[Geom::Y] << " moveto\n"; - - for(Geom::Path::const_iterator cit = it->begin(); cit != it->end_open(); ++cit) { - print_2geomcurve(os, *cit); - } - - if (it->closed()) { - os << "closepath\n"; - } - - } -} - -void -PrintPS::print_2geomcurve(SVGOStringStream &os, Geom::Curve const & c ) -{ - using Geom::X; - using Geom::Y; - - if( is_straight_curve(c) ) - { - os << c.finalPoint()[X] << " " << c.finalPoint()[Y] << " lineto\n"; - } - else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast<Geom::CubicBezier const*>(&c)) { - std::vector<Geom::Point> points = cubic_bezier->points(); - os << points[1][X] << " " << points[1][Y] << " " - << points[2][X] << " " << points[2][Y] << " " - << points[3][X] << " " << points[3][Y] << " curveto\n"; - } - else { - //this case handles sbasis as well as all other curve types - Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(c.toSBasis(), 0.1); - - for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) { - print_2geomcurve(os, *iter); - } - } -} - - -/* The following code is licensed under GNU GPL. -** The packbits, ascii85 and imaging printing code -** is from the gimp's postscript.c. -*/ - -/** -* \param nin Number of bytes of source data. -* \param src Source data. -* \param nout Number of output bytes. -* \param dst Buffer for output. -*/ -void -PrintPS::compress_packbits(int nin, - guchar *src, - int *nout, - guchar *dst) - -{ - register guchar c; - int nrepeat, nliteral; - guchar *run_start; - guchar *start_dst = dst; - guchar *last_literal = NULL; - - for (;;) { - if (nin <= 0) break; - - run_start = src; - c = *run_start; - - /* Search repeat bytes */ - if ((nin > 1) && (c == src[1])) { - nrepeat = 1; - nin -= 2; - src += 2; - while ((nin > 0) && (c == *src)) { - nrepeat++; - src++; - nin--; - if (nrepeat == 127) break; /* Maximum repeat */ - } - - /* Add two-byte repeat to last literal run ? */ - if ( (nrepeat == 1) - && (last_literal != NULL) && (((*last_literal)+1)+2 <= 128) ) - { - *last_literal += 2; - *(dst++) = c; - *(dst++) = c; - continue; - } - - /* Add repeat run */ - *(dst++) = (guchar)((-nrepeat) & 0xff); - *(dst++) = c; - last_literal = NULL; - continue; - } - /* Search literal bytes */ - nliteral = 1; - nin--; - src++; - - for (;;) { - if (nin <= 0) break; - - if ((nin >= 2) && (src[0] == src[1])) /* A two byte repeat ? */ - break; - - nliteral++; - nin--; - src++; - if (nliteral == 128) break; /* Maximum literal run */ - } - - /* Could be added to last literal run ? */ - if ((last_literal != NULL) && (((*last_literal)+1)+nliteral <= 128)) { - *last_literal += nliteral; - } else { - last_literal = dst; - *(dst++) = (guchar)(nliteral-1); - } - while (nliteral-- > 0) *(dst++) = *(run_start++); - } - *nout = dst - start_dst; -} - -void -PrintPS::ascii85_init(void) -{ - ascii85_len = 0; - ascii85_linewidth = 0; -} - -void -PrintPS::ascii85_flush(SVGOStringStream &os) -{ - char c[5]; - bool const zero_case = (ascii85_buf == 0); - static int const max_linewidth = 75; - - for (int i = 4; i >= 0; i--) { - c[i] = (ascii85_buf % 85) + '!'; - ascii85_buf /= 85; - } - /* check for special case: "!!!!!" becomes "z", but only if not - * at end of data. */ - if (zero_case && (ascii85_len == 4)) { - if (ascii85_linewidth >= max_linewidth) { - os << '\n'; - ascii85_linewidth = 0; - } - os << 'z'; - ascii85_linewidth++; - } else { - for (int i = 0; i < ascii85_len+1; i++) { - if ((ascii85_linewidth >= max_linewidth) && (c[i] != '%')) { - os << '\n'; - ascii85_linewidth = 0; - } - os << c[i]; - ascii85_linewidth++; - } - } - - ascii85_len = 0; - ascii85_buf = 0; -} - -inline void -PrintPS::ascii85_out(guchar byte, SVGOStringStream &os) -{ - if (ascii85_len == 4) - ascii85_flush(os); - - ascii85_buf <<= 8; - ascii85_buf |= byte; - ascii85_len++; -} - -void -PrintPS::ascii85_nout(int n, guchar *uptr, SVGOStringStream &os) -{ - while (n-- > 0) { - ascii85_out(*uptr, os); - uptr++; - } -} - -void -PrintPS::ascii85_done(SVGOStringStream &os) -{ - if (ascii85_len) { - /* zero any unfilled buffer portion, then flush */ - ascii85_buf <<= (8 * (4-ascii85_len)); - ascii85_flush(os); - } - - os << "~>\n"; -} - -unsigned int -PrintPS::print_image(FILE *ofp, guchar *px, unsigned int width, unsigned int height, unsigned int rs, - Geom::Matrix const *transform) -{ - Inkscape::SVGOStringStream os; - - os << "gsave\n"; - - os << "[" << (*transform)[0] << " " - << (*transform)[1] << " " - << (*transform)[2] << " " - << (*transform)[3] << " " - << (*transform)[4] << " " - << (*transform)[5] << "] concat\n"; - - /* Write read image procedure */ - os << "<<\n"; - os << " /ImageType 3\n"; - os << " /InterleaveType 1\n"; - - os << " /MaskDict\n"; - os << " <<\n"; - os << " /ImageType 1\n"; - os << " /Width " << width << "\n"; - os << " /Height " << height << "\n"; - os << " /ImageMatrix " - << "[" << width << " " - << 0 << " " - << 0 << " " - << -((long) height) << " " - << 0 << " " - << height << "]\n"; - os << " /BitsPerComponent 8\n"; - os << " /Decode [1 0]\n"; - os << " >>\n"; - - os << " /DataDict\n"; - os << " <<\n"; - os << " /ImageType 1\n"; - os << " /Width " << width << "\n"; - os << " /Height " << height << "\n"; - os << " /ImageMatrix " - << "[" << width << " " - << 0 << " " - << 0 << " " - << -((long )height) << " " - << 0 << " " - << height << "]\n"; - os << " /DataSource currentfile /ASCII85Decode filter\n"; - os << " /BitsPerComponent 8\n"; - os << " /Decode [0 1 0 1 0 1]\n"; - os << " >>\n"; - - os << ">>\n"; - - /* Allocate buffer for packbits data. Worst case: Less than 1% increase */ - guchar *const packb = (guchar *)g_malloc((4*width * 105)/100+2); - guchar *const plane = (guchar *)g_malloc(4*width); - - os << "image\n"; - - ascii85_init(); - - for (unsigned i = 0; i < height; i++) { - guchar const *const src = px + i * rs; - - guchar const *src_ptr = src; - guchar *plane_ptr = plane; - for (unsigned j = 0; j < width; j++) { - *(plane_ptr++) = *(src_ptr+3); - *(plane_ptr++) = *(src_ptr+0); - *(plane_ptr++) = *(src_ptr+1); - *(plane_ptr++) = *(src_ptr+2); - src_ptr += 4; - } - - ascii85_nout(4*width, plane, os); - } - ascii85_done(os); - - g_free(packb); - g_free(plane); - - os << "grestore\n"; - - fprintf(ofp, "%s", os.str().c_str()); - - return 0; -} - -bool -PrintPS::textToPath(Inkscape::Extension::Print * ext) -{ - return ext->get_param_bool("textToPath"); -} - -/** -* \brief Get "fontEmbedded" param -* \retval TRUE Fonts have to be embedded in the output so that the user might not need to install fonts to have the interpreter read the document correctly -* \retval FALSE No font embedding -* -* Only available for Adobe Type 1 fonts in EPS output till now -*/ -bool -PrintPS::fontEmbedded(Inkscape::Extension::Print * ext) -{ - return ext->get_param_bool("fontEmbedded"); -} - -#include "clear-n_.h" - -void -PrintPS::init(void) -{ - /* SVG in */ - (void) Inkscape::Extension::build_from_mem( - "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" - "<name>" N_("Postscript Print") "</name>\n" - "<id>" SP_MODULE_KEY_PRINT_PS "</id>\n" - "<param name=\"bitmap\" type=\"boolean\">false</param>\n" - "<param name=\"resolution\" type=\"string\">72</param>\n" - "<param name=\"destination\" type=\"string\">| lp</param>\n" - "<param name=\"pageBoundingBox\" type=\"boolean\">true</param>\n" - "<param name=\"textToPath\" type=\"boolean\">true</param>\n" - "<param name=\"fontEmbedded\" type=\"boolean\">false</param>\n" - "<print/>\n" - "</inkscape-extension>", new PrintPS()); -} - - -} /* namespace Internal */ -} /* namespace Extension */ -} /* namespace Inkscape */ - -/* End of GNU GPL code */ - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/extension/internal/ps.h b/src/extension/internal/ps.h deleted file mode 100644 index 92928b9e4..000000000 --- a/src/extension/internal/ps.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef EXTENSION_INTERNAL_PS_H_SEEN -#define EXTENSION_INTERNAL_PS_H_SEEN - -/** \file - * Declaration of PrintPS, the internal module used to do Postscript Printing. - */ -/* - * Authors: - * Lauris Kaplinski <lauris@kaplinski.com> - * Ted Gould <ted@gould.cx> - * - * Lauris' original code is in the public domain. - * Ted's changes are licensed under the GNU GPL. - */ - -#include <config.h> -#include "extension/extension.h" -#include "extension/implementation/implementation.h" -#include <set> -#include <string> - -#include <libnrtype/font-instance.h> - -#include "svg/stringstream.h" - -namespace Inkscape { -namespace Extension { -namespace Internal { - -typedef enum {FONT_TYPE1, FONT_TRUETYPE} FontType; - -class PrintPS : public Inkscape::Extension::Implementation::Implementation { - float _width; - float _height; - FILE * _begin_stream;//stream to print prolog and document setup of EPS, if font embedding - FILE * _stream;//(main) stream to print the (E)PS output, or only the script part following prolog/document setup, if font embedding - - unsigned short _dpi; - bool _bitmap; - std::set<std::string> _latin1_encoded_fonts; - bool _newlatin1font_proc_defined; - - GTree * _fonts;//maps fonts used in the document, to (value=)"TRUE" only if the font was effectively embedded, "FALSE" if not. - - //map strings of font types to enumeration of int values - std::map<std::string, FontType> _fontTypesMap; - - void print_2geomcurve(SVGOStringStream &os, Geom::Curve const & c ); - void print_pathvector(SVGOStringStream &os, Geom::PathVector const &pathv); - - void print_fill_style(SVGOStringStream &os, SPStyle const *style, NRRect const *pbox); - void print_stroke_style(SVGOStringStream &os, SPStyle const *style); - - char const *PSFontName(SPStyle const *style); - bool embed_t1(SVGOStringStream &os, font_instance* font); - bool embed_font(SVGOStringStream &os, font_instance* font); - - void print_glyphlist(SVGOStringStream &os, font_instance* font, Glib::ustring unistring); - - unsigned int print_image(FILE *ofp, guchar *px, unsigned int width, unsigned int height, unsigned int rs, - Geom::Matrix const *transform); - void compress_packbits(int nin, guchar *src, int *nout, guchar *dst); - - /* ASCII 85 variables */ - guint32 ascii85_buf; - int ascii85_len; - int ascii85_linewidth; - /* ASCII 85 Functions */ - void ascii85_init(void); - void ascii85_flush(SVGOStringStream &os); - inline void ascii85_out(guchar byte, SVGOStringStream &os); - void ascii85_nout(int n, guchar *uptr, SVGOStringStream &os); - void ascii85_done(SVGOStringStream &os); - - -public: - PrintPS(void); - virtual ~PrintPS(void); - - /* Print functions */ - virtual unsigned int setup(Inkscape::Extension::Print *module); - /* - virtual unsigned int set_preview(Inkscape::Extension::Print *module); - */ - - virtual unsigned int begin(Inkscape::Extension::Print *module, SPDocument *doc); - virtual unsigned int finish(Inkscape::Extension::Print *module); - - /* Rendering methods */ - virtual unsigned int bind(Inkscape::Extension::Print *module, Geom::Matrix const *transform, float opacity); - virtual unsigned int release(Inkscape::Extension::Print *module); - virtual unsigned int comment(Inkscape::Extension::Print *module, char const *comment); - virtual unsigned int fill(Inkscape::Extension::Print *module, Geom::PathVector const &pathv, Geom::Matrix const *ctm, SPStyle const *style, - NRRect const *pbox, NRRect const *dbox, NRRect const *bbox); - virtual unsigned int stroke(Inkscape::Extension::Print *module, Geom::PathVector const &pathv, Geom::Matrix const *transform, SPStyle const *style, - NRRect const *pbox, NRRect const *dbox, NRRect const *bbox); - virtual unsigned int image(Inkscape::Extension::Print *module, unsigned char *px, unsigned int w, unsigned int h, unsigned int rs, - Geom::Matrix const *transform, SPStyle const *style); - virtual unsigned int text(Inkscape::Extension::Print *module, char const *text, - Geom::Point p, SPStyle const *style); - - bool textToPath(Inkscape::Extension::Print *ext); - static void init(void); - bool fontEmbedded (Inkscape::Extension::Print * ext); -}; - -} /* namespace Internal */ -} /* namespace Extension */ -} /* namespace Inkscape */ - - -#endif /* !EXTENSION_INTERNAL_PS_H_SEEN */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
