diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2014-11-23 23:36:49 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2014-11-23 23:36:49 +0000 |
| commit | 0969085ddf607a7a98cf7fd6d9b10da5fbebe62d (patch) | |
| tree | 59b2bc9ed3412ab2de4c703ef30342dfe2401704 /src/extension | |
| parent | refactor from lastApplied (diff) | |
| parent | Fixed a bug pointed by suv running from comand line, also removed another des... (diff) | |
| download | inkscape-0969085ddf607a7a98cf7fd6d9b10da5fbebe62d.tar.gz inkscape-0969085ddf607a7a98cf7fd6d9b10da5fbebe62d.zip | |
fixing to trunk
(bzr r12588.1.34)
Diffstat (limited to 'src/extension')
56 files changed, 2119 insertions, 2052 deletions
diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index 9bc30a592..47292fd97 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -49,7 +49,6 @@ set(extension_SRC internal/metafile-print.cpp internal/odf.cpp internal/latex-text-renderer.cpp - internal/pdf-input-cairo.cpp internal/pov-out.cpp internal/javafx-out.cpp internal/svg.cpp @@ -130,9 +129,9 @@ set(extension_SRC internal/latex-pstricks-out.h internal/latex-pstricks.h internal/latex-text-renderer.h + internal/metafile-inout.h internal/metafile-print.h internal/odf.h - internal/pdf-input-cairo.h internal/pdfinput/pdf-input.h internal/pdfinput/pdf-parser.h internal/pdfinput/svg-builder.h diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert index 7d851715e..192651d87 100644 --- a/src/extension/dbus/Makefile_insert +++ b/src/extension/dbus/Makefile_insert @@ -78,7 +78,7 @@ libinkdbus_la_CFLAGS = \ $(DBUS_CFLAGS) \ $(INKSCAPE_CFLAGS) \ -I$(builddir)/extension/dbus \ - -Wall -Werror + -Wall libinkdbus_la_LIBADD = \ $(DBUS_LIBS) \ diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 221a3e879..e3452f4ce 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -169,7 +169,7 @@ selection_get_center_x (Inkscape::Selection *sel){ gdouble selection_get_center_y (Inkscape::Selection *sel){ Geom::OptRect box = sel->documentBounds(SPItem::GEOMETRIC_BBOX); - return box ? box->midpoint()[Geom::X] : 0; + return box ? box->midpoint()[Geom::Y] : 0; } /* diff --git a/src/extension/dependency.cpp b/src/extension/dependency.cpp index 78012ccc8..e46b6fbd2 100644 --- a/src/extension/dependency.cpp +++ b/src/extension/dependency.cpp @@ -57,14 +57,22 @@ Dependency::Dependency (Inkscape::XML::Node * in_repr) Inkscape::GC::anchor(_repr); - const gchar * location = _repr->attribute("location"); - for (int i = 0; i < LOCATION_CNT && location != NULL; i++) { - if (!strcmp(location, _location_str[i])) { - _location = (location_t)i; - break; + if (const gchar * location = _repr->attribute("location")) { + for (int i = 0; i < LOCATION_CNT && location != NULL; i++) { + if (!strcmp(location, _location_str[i])) { + _location = (location_t)i; + break; + } + } + } else if (const gchar * location = _repr->attribute("reldir")) { + for (int i = 0; i < LOCATION_CNT && location != NULL; i++) { + if (!strcmp(location, _location_str[i])) { + _location = (location_t)i; + break; + } } } - + const gchar * type = _repr->attribute("type"); for (int i = 0; i < TYPE_CNT && type != NULL; i++) { if (!strcmp(type, _type_str[i])) { diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index d63ec7485..6a22eb585 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -111,6 +111,14 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat if (!strcmp(chname, "dependency")) { _deps.push_back(new Dependency(child_repr)); } /* dependency */ + if (!strcmp(chname, "script")) { + for (Inkscape::XML::Node *child = child_repr->firstChild(); child != NULL ; child = child->next()) { + if (child->type() == Inkscape::XML::ELEMENT_NODE) { + _deps.push_back(new Dependency(child)); + break; + } /* skip non-element nodes (see LP #1372200) */ + } + } /* check command as a dependency (see LP #505920) */ if (!strcmp(chname, "options")) { silent = !strcmp( child_repr->attribute("silent"), "true" ); } @@ -262,6 +270,18 @@ Extension::check (void) const char * inx_failure = _(" This is caused by an improper .inx file for this extension." " An improper .inx file could have been caused by a faulty installation of Inkscape."); + + // No need to include Windows only extensions + // See LP bug #1307554 for details - https://bugs.launchpad.net/inkscape/+bug/1307554 +#ifndef WIN32 + const char* win_ext[] = {"com.vaxxine.print.win32"}; + std::vector<std::string> v (win_ext, win_ext + sizeof(win_ext)/sizeof(win_ext[0])); + std::string ext_id(id); + if (std::find(v.begin(), v.end(), ext_id) != v.end()) { + printFailure(Glib::ustring(_("the extension is designed for Windows only.")) + inx_failure); + retval = false; + } +#endif if (id == NULL) { printFailure(Glib::ustring(_("an ID was not defined for it.")) + inx_failure); retval = false; diff --git a/src/extension/implementation/implementation.h b/src/extension/implementation/implementation.h index 9d679982a..fb323cd78 100644 --- a/src/extension/implementation/implementation.h +++ b/src/extension/implementation/implementation.h @@ -29,7 +29,7 @@ namespace Gtk { } class SPDocument; -struct SPStyle; +class SPStyle; namespace Inkscape { diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index f0fd3711b..99c882a01 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -1,28 +1,18 @@ -/** \file - * Code for handling extensions (i.e.\ scripts). - */ -/* +/** + * Code for handling extensions (i.e. scripts). + * * Authors: * Bryce Harrington <bryce@osdl.org> * Ted Gould <ted@gould.cx> * Jon A. Cruz <jon@joncruz.org> * Abhishek Sharma * - * Copyright (C) 2002-2005,2007 Authors + * Copyright (C) 2002-2007 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ -#define __INKSCAPE_EXTENSION_IMPLEMENTATION_SCRIPT_C__ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include <glibmm/threads.h> -#endif - +#include <glibmm.h> #include <gtkmm/messagedialog.h> #include <gtkmm/main.h> #include <gtkmm/scrolledwindow.h> @@ -32,44 +22,38 @@ #include <unistd.h> #include <errno.h> -#include <glib.h> #include <glib/gstdio.h> -#include "ui/view/view.h" #include "desktop-handles.h" #include "desktop.h" -#include "selection.h" -#include "sp-namedview.h" -#include "io/sys.h" -#include "preferences.h" -#include "../system.h" +#include "ui/dialog-events.h" #include "extension/effect.h" #include "extension/output.h" #include "extension/input.h" #include "extension/db.h" -#include "script.h" -#include "dialogs/dialog-events.h" #include "inkscape.h" +#include "io/sys.h" +#include "preferences.h" +#include "script.h" +#include "selection.h" +#include "sp-namedview.h" +#include "extension/system.h" +#include "ui/view/view.h" #include "xml/node.h" #include "xml/attribute-record.h" #include "util/glib-list-iterators.h" #include "path-prefix.h" - #ifdef WIN32 #include <windows.h> #include <sys/stat.h> #include "registrytool.h" #endif - - /** This is the command buffer that gets allocated from the stack */ #define BUFSIZE (255) - - /* Namespaces */ namespace Inkscape { namespace Extension { @@ -742,12 +726,12 @@ void Script::effect(Inkscape::Extension::Effect *module, vd->emitReconstructionStart(); copy_doc(vd->rroot, mydoc->rroot); vd->emitReconstructionFinish(); - SPObject *layer = NULL; - + // Getting the named view from the document generated by the extension SPNamedView *nv = sp_document_namedview(mydoc, NULL); //Check if it has a default layer set up + SPObject *layer = NULL; if ( nv != NULL) { if( nv->default_layer_id != 0 ) { @@ -776,19 +760,21 @@ void Script::effect(Inkscape::Extension::Effect *module, /** - \brief A function to take all the svg elements from one document - and put them in another. - \param oldroot The root node of the document to be replaced - \param newroot The root node of the document to replace it with - - This function first deletes all of the data in the old document. It - does this by creating a list of what needs to be deleted, and then - goes through the list. This two pass approach removes issues with - the list being change while parsing through it. Lots of nasty bugs. - - Then, it goes through the new document, duplicating all of the - elements and putting them into the old document. The copy - is then complete. + \brief A function to replace all the elements in an old document + by those from a new document. + document and repinserts them into an emptied old document. + \param oldroot The root node of the old (destination) document. + \param newroot The root node of the new (source) document. + + This function first deletes all the elements in the old document by + making two pass, the first to create a list of the old elements and + the second to actually delete them. This two pass approach removes issues + with the list being change while parsing through it... lots of nasty bugs. + + Then, it copies all the element in the new document into the old document. + + Finally, it replaces the attributes in the root element of the old document + by the attributes in root of the new document. */ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newroot) { @@ -797,9 +783,21 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr g_warning("Error on copy_doc: NULL pointer input."); return; } + + // For copying attributes in root and in namedview + using Inkscape::Util::List; + using Inkscape::XML::AttributeRecord; + + // Question: Why is the "sodipodi:namedview" special? Treating it as a normal + // elmement results in crashes. + // Seems to be a bug: + // http://inkscape.13.x6.nabble.com/Effect-that-modifies-the-document-properties-tt2822126.html + std::vector<Inkscape::XML::Node *> delete_list; Inkscape::XML::Node * oldroot_namedview = NULL; + Inkscape::XML::Node * newroot_namedview = NULL; + // Make list for (Inkscape::XML::Node * child = oldroot->firstChild(); child != NULL; child = child->next()) { @@ -814,14 +812,18 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr delete_list.push_back(child); } } + + // Unparent (delete) for (unsigned int i = 0; i < delete_list.size(); i++) { sp_repr_unparent(delete_list[i]); } + // Copy for (Inkscape::XML::Node * child = newroot->firstChild(); child != NULL; child = child->next()) { if (!strcmp("sodipodi:namedview", child->name())) { + newroot_namedview = child; if (oldroot_namedview != NULL) { for (Inkscape::XML::Node * newroot_namedview_child = child->firstChild(); newroot_namedview_child != NULL; @@ -834,26 +836,44 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr } } - { - using Inkscape::Util::List; - using Inkscape::XML::AttributeRecord; - std::vector<gchar const *> attribs; + std::vector<gchar const *> attribs; - // Make a list of all attributes of the old root node. - for (List<AttributeRecord const> iter = oldroot->attributeList(); iter; ++iter) { - attribs.push_back(g_quark_to_string(iter->key)); - } + // Must explicitly copy root attributes. - // Delete the attributes of the old root nodes. - for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); ++it) { - oldroot->setAttribute(*it, NULL); - } + // Make a list of all attributes of the old root node. + for (List<AttributeRecord const> iter = oldroot->attributeList(); iter; ++iter) { + attribs.push_back(g_quark_to_string(iter->key)); + } - // Set the new attributes. - for (List<AttributeRecord const> iter = newroot->attributeList(); iter; ++iter) { - gchar const *name = g_quark_to_string(iter->key); - oldroot->setAttribute(name, newroot->attribute(name)); - } + // Delete the attributes of the old root node. + for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); ++it) { + oldroot->setAttribute(*it, NULL); + } + + // Set the new attributes. + for (List<AttributeRecord const> iter = newroot->attributeList(); iter; ++iter) { + gchar const *name = g_quark_to_string(iter->key); + oldroot->setAttribute(name, newroot->attribute(name)); + } + + attribs.clear(); + + // Must explicitly copy namedview attributes. + + // Make a list of all attributes of the old namedview node. + for (List<AttributeRecord const> iter = oldroot_namedview->attributeList(); iter; ++iter) { + attribs.push_back(g_quark_to_string(iter->key)); + } + + // Delete the attributes of the old namedview node. + for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); ++it) { + oldroot_namedview->setAttribute(*it, NULL); + } + + // Set the new attributes. + for (List<AttributeRecord const> iter = newroot_namedview->attributeList(); iter; ++iter) { + gchar const *name = g_quark_to_string(iter->key); + oldroot_namedview->setAttribute(name, newroot_namedview->attribute(name)); } /** \todo Restore correct layer */ @@ -1063,4 +1083,4 @@ int Script::execute (const std::list<std::string> &in_command, fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 : diff --git a/src/extension/implementation/script.h b/src/extension/implementation/script.h index 270c361af..6a7d0c3b8 100644 --- a/src/extension/implementation/script.h +++ b/src/extension/implementation/script.h @@ -22,81 +22,30 @@ namespace Inkscape { namespace XML { class Node; -} -} +} // namespace XML - -namespace Inkscape { namespace Extension { namespace Implementation { - /** * Utility class used for loading and launching script extensions */ class Script : public Implementation { - public: - /** - * - */ Script(void); - - /** - * - */ virtual ~Script(); - - - /** - * - */ virtual bool load(Inkscape::Extension::Extension *module); - - /** - * - */ virtual void unload(Inkscape::Extension::Extension *module); - - /** - * - */ virtual bool check(Inkscape::Extension::Extension *module); ImplementationDocumentCache * newDocCache(Inkscape::Extension::Extension * ext, Inkscape::UI::View::View * view); - /** - * - */ - virtual Gtk::Widget *prefs_input(Inkscape::Extension::Input *module, - gchar const *filename); - - /** - * - */ - virtual SPDocument *open(Inkscape::Extension::Input *module, - gchar const *filename); - - /** - * - */ + virtual Gtk::Widget *prefs_input(Inkscape::Extension::Input *module, gchar const *filename); + virtual SPDocument *open(Inkscape::Extension::Input *module, gchar const *filename); virtual Gtk::Widget *prefs_output(Inkscape::Extension::Output *module); - - /** - * - */ - virtual void save(Inkscape::Extension::Output *module, - SPDocument *doc, - gchar const *filename); - - /** - * - */ - virtual void effect(Inkscape::Extension::Effect *module, - Inkscape::UI::View::View *doc, - ImplementationDocumentCache * docCache); - + virtual void save(Inkscape::Extension::Output *module, SPDocument *doc, gchar const *filename); + virtual void effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc, ImplementationDocumentCache * docCache); virtual bool cancelProcessing (void); private: @@ -105,7 +54,7 @@ private: Glib::RefPtr<Glib::MainLoop> _main_loop; /** - * The command that has been dirived from + * The command that has been derived from * the configuration file with appropriate directories */ std::list<std::string> command; @@ -117,13 +66,10 @@ private: */ Glib::ustring helper_extension; - std::string solve_reldir (Inkscape::XML::Node *reprin); - bool check_existence (const std::string &command); - void copy_doc (Inkscape::XML::Node * olddoc, - Inkscape::XML::Node * newdoc); - void checkStderr (const Glib::ustring &filename, - Gtk::MessageType type, - const Glib::ustring &message); + std::string solve_reldir(Inkscape::XML::Node *repr_in); + bool check_existence (std::string const& command); + void copy_doc(Inkscape::XML::Node * olddoc, Inkscape::XML::Node * newdoc); + void checkStderr (Glib::ustring const& filename, Gtk::MessageType type, Glib::ustring const& message); class file_listener { Glib::ustring _string; @@ -140,6 +86,7 @@ private: bool isDead () { return _dead; } + // TODO move these definitions into script.cpp void init (int fd, Glib::RefPtr<Glib::MainLoop> main) { _channel = Glib::IOChannel::create_from_fd(fd); _channel->set_encoding(); @@ -202,11 +149,6 @@ private: std::string resolveInterpreterExecutable(const Glib::ustring &interpNameArg); }; // class Script - - - - - } // namespace Implementation } // namespace Extension } // namespace Inkscape diff --git a/src/extension/implementation/xslt.cpp b/src/extension/implementation/xslt.cpp index bcea06cb5..85ae9efde 100644 --- a/src/extension/implementation/xslt.cpp +++ b/src/extension/implementation/xslt.cpp @@ -20,6 +20,7 @@ #include "xslt.h" #include "../extension.h" #include "../output.h" +#include "extension/input.h" #include "xml/repr.h" #include "io/sys.h" @@ -53,8 +54,7 @@ XSLT::XSLT(void) : { } -Glib::ustring -XSLT::solve_reldir(Inkscape::XML::Node *reprin) { +Glib::ustring XSLT::solve_reldir(Inkscape::XML::Node *reprin) { gchar const *s = reprin->attribute("reldir"); @@ -90,8 +90,7 @@ XSLT::solve_reldir(Inkscape::XML::Node *reprin) { return ""; } -bool -XSLT::check(Inkscape::Extension::Extension *module) +bool XSLT::check(Inkscape::Extension::Extension *module) { if (load(module)) { unload(module); @@ -101,8 +100,7 @@ XSLT::check(Inkscape::Extension::Extension *module) } } -bool -XSLT::load(Inkscape::Extension::Extension *module) +bool XSLT::load(Inkscape::Extension::Extension *module) { if (module->loaded()) { return true; } @@ -130,8 +128,7 @@ XSLT::load(Inkscape::Extension::Extension *module) return true; } -void -XSLT::unload(Inkscape::Extension::Extension *module) +void XSLT::unload(Inkscape::Extension::Extension *module) { if (!module->loaded()) { return; } xsltFreeStylesheet(_stylesheet); @@ -139,8 +136,8 @@ XSLT::unload(Inkscape::Extension::Extension *module) return; } -SPDocument * -XSLT::open(Inkscape::Extension::Input */*module*/, gchar const *filename) +SPDocument * XSLT::open(Inkscape::Extension::Input */*module*/, + gchar const *filename) { xmlDocPtr filein = xmlParseFile(filename); if (filein == NULL) { return NULL; } @@ -184,8 +181,7 @@ XSLT::open(Inkscape::Extension::Input */*module*/, gchar const *filename) return doc; } -void -XSLT::save(Inkscape::Extension::Output */*module*/, SPDocument *doc, gchar const *filename) +void XSLT::save(Inkscape::Extension::Output *module, SPDocument *doc, gchar const *filename) { /* TODO: Should we assume filename to be in utf8 or to be a raw filename? * See JavaFXOutput::save for discussion. */ @@ -214,10 +210,24 @@ XSLT::save(Inkscape::Extension::Output */*module*/, SPDocument *doc, gchar const return; } - const char * params[1]; - params[0] = NULL; + std::list<std::string> params; + module->paramListString(params); + const int max_parameters = params.size() * 2; + const char * xslt_params[max_parameters+1] ; + + int count = 0; + for(std::list<std::string>::iterator t=params.begin(); t != params.end(); ++t) { + std::size_t pos = t->find("="); + std::ostringstream parameter; + std::ostringstream value; + parameter << t->substr(2,pos-2); + value << t->substr(pos+1); + xslt_params[count++] = g_strdup_printf("%s", parameter.str().c_str()); + xslt_params[count++] = g_strdup_printf("'%s'", value.str().c_str()); + } + xslt_params[count] = NULL; - xmlDocPtr newdoc = xsltApplyStylesheet(_stylesheet, svgdoc, params); + xmlDocPtr newdoc = xsltApplyStylesheet(_stylesheet, svgdoc, xslt_params); //xmlSaveFile(filename, newdoc); int success = xsltSaveResultToFilename(filename, newdoc, _stylesheet, 0); diff --git a/src/extension/init.cpp b/src/extension/init.cpp index 0ff4b79c4..912d58a13 100644 --- a/src/extension/init.cpp +++ b/src/extension/init.cpp @@ -19,9 +19,6 @@ #ifdef HAVE_POPPLER # include "internal/pdfinput/pdf-input.h" #endif -#ifdef HAVE_POPPLER_GLIB -# include "internal/pdf-input-cairo.h" -#endif #include "path-prefix.h" @@ -174,11 +171,6 @@ init() #ifdef HAVE_POPPLER Internal::PdfInput::init(); #endif -#ifdef HAVE_POPPLER_GLIB - if (1) { - Internal::PdfInputCairo::init(); - } -#endif Internal::PrintEmf::init(); Internal::Emf::init(); Internal::PrintWmf::init(); diff --git a/src/extension/input.h b/src/extension/input.h index b01ffeb86..2a0a177a0 100644 --- a/src/extension/input.h +++ b/src/extension/input.h @@ -14,9 +14,8 @@ #include <exception> #include <glib.h> #include "extension.h" -#include "xml/repr.h" -#include "document.h" -#include <gtk/gtk.h> + +class SPDocument; namespace Inkscape { namespace Extension { diff --git a/src/extension/internal/Makefile_insert b/src/extension/internal/Makefile_insert index a31843114..125776d41 100644 --- a/src/extension/internal/Makefile_insert +++ b/src/extension/internal/Makefile_insert @@ -106,8 +106,6 @@ ink_common_sources += \ extension/internal/svg.cpp \ extension/internal/svgz.h \ extension/internal/svgz.cpp \ - extension/internal/pdf-input-cairo.cpp \ - extension/internal/pdf-input-cairo.h \ extension/internal/cairo-ps-out.h \ extension/internal/cairo-ps-out.cpp \ extension/internal/cairo-render-context.h \ diff --git a/src/extension/internal/bitmap/crop.cpp b/src/extension/internal/bitmap/crop.cpp index 0e633afd6..02d92668b 100644 --- a/src/extension/internal/bitmap/crop.cpp +++ b/src/extension/internal/bitmap/crop.cpp @@ -74,7 +74,7 @@ Crop::init(void) "<effects-menu>\n" "<submenu name=\"" N_("Raster") "\" />\n" "</effects-menu>\n" - "<menu-tip>" N_("Crop selected bitmap(s).") "</menu-tip>\n" + "<menu-tip>" N_("Crop selected bitmap(s)") "</menu-tip>\n" "</effect>\n" "</inkscape-extension>\n", new Crop()); } diff --git a/src/extension/internal/bitmap/opacity.cpp b/src/extension/internal/bitmap/opacity.cpp index 742cb7019..f9b4bbc27 100644 --- a/src/extension/internal/bitmap/opacity.cpp +++ b/src/extension/internal/bitmap/opacity.cpp @@ -43,7 +43,7 @@ Opacity::init(void) "<effects-menu>\n" "<submenu name=\"" N_("Raster") "\" />\n" "</effects-menu>\n" - "<menu-tip>" N_("Modify opacity channel(s) of selected bitmap(s).") "</menu-tip>\n" + "<menu-tip>" N_("Modify opacity channel(s) of selected bitmap(s)") "</menu-tip>\n" "</effect>\n" "</inkscape-extension>\n", new Opacity()); } diff --git a/src/extension/internal/cairo-ps-out.cpp b/src/extension/internal/cairo-ps-out.cpp index 055a30add..d1511ba84 100644 --- a/src/extension/internal/cairo-ps-out.cpp +++ b/src/extension/internal/cairo-ps-out.cpp @@ -5,7 +5,7 @@ * Authors: * Ted Gould <ted@gould.cx> * Ulf Erikson <ulferikson@users.sf.net> - * Adib Taraben <theAdib@yahoo.com> + * Adib Taraben <theAdib@gmail.com> * Jon A. Cruz <jon@joncruz.org> * Abhishek Sharma * @@ -333,7 +333,7 @@ CairoPsOutput::init (void) "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n" "<param name=\"textToLaTeX\" gui-text=\"" N_("PS+LaTeX: Omit text in PS, and create LaTeX file") "\" type=\"boolean\">false</param>\n" "<param name=\"blurToBitmap\" gui-text=\"" N_("Rasterize filter effects") "\" type=\"boolean\">true</param>\n" - "<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">90</param>\n" + "<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">96</param>\n" "<param name=\"area\" gui-text=\"" N_("Output page size") "\" type=\"optiongroup\" >\n" "<_option value=\"page\">" N_("Use document's page size") "</_option>" "<_option value=\"drawing\">" N_("Use exported object's size") "</_option>" @@ -372,7 +372,7 @@ CairoEpsOutput::init (void) "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n" "<param name=\"textToLaTeX\" gui-text=\"" N_("EPS+LaTeX: Omit text in EPS, and create LaTeX file") "\" type=\"boolean\">false</param>\n" "<param name=\"blurToBitmap\" gui-text=\"" N_("Rasterize filter effects") "\" type=\"boolean\">true</param>\n" - "<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">90</param>\n" + "<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">96</param>\n" "<param name=\"area\" gui-text=\"" N_("Output page size") "\" type=\"optiongroup\" >\n" "<_option value=\"page\">" N_("Use document's page size") "</_option>" "<_option value=\"drawing\">" N_("Use exported object's size") "</_option>" diff --git a/src/extension/internal/cairo-ps-out.h b/src/extension/internal/cairo-ps-out.h index 7eda3c510..b438b55b4 100644 --- a/src/extension/internal/cairo-ps-out.h +++ b/src/extension/internal/cairo-ps-out.h @@ -5,7 +5,7 @@ * Authors: * Ted Gould <ted@gould.cx> * Ulf Erikson <ulferikson@users.sf.net> - * Adib Taraben <theAdib@yahoo.com> + * Adib Taraben <theAdib@gmail.com> * Abhishek Sharma * * Copyright (C) 2004-2006 Authors diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index c09b8e9c8..d76c187a2 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -39,6 +39,7 @@ #include "sp-item.h" #include "sp-item-group.h" #include "style.h" +#include "sp-hatch.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" #include "sp-pattern.h" @@ -657,12 +658,12 @@ CairoRenderContext::popLayer(void) CairoRenderContext *mask_ctx = _renderer->createContext(); // Fix Me: This is a kludge. PDF and PS output is set to 72 dpi but the - // Cairo surface is expecting the mask to be 90 dpi. + // Cairo surface is expecting the mask to be 96 dpi. float surface_width = _width; float surface_height = _height; if( _vector_based_target ) { - surface_width *= 1.25; - surface_height *= 1.25; + surface_width *= 4.0/3.0; + surface_height *= 4.0/3.0; } if (!mask_ctx->setupSurface( surface_width, surface_height )) { TRACE(("mask: setupSurface failed\n")); @@ -1130,6 +1131,83 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver } cairo_pattern_t* +CairoRenderContext::_createHatchPainter(SPPaintServer const *const paintserver, Geom::OptRect const &pbox) { + SPHatch const *hatch = dynamic_cast<SPHatch const *>(paintserver); + g_assert( hatch ); + + g_assert(hatch->pitch() > 0); + + // create drawing and group + Inkscape::Drawing drawing; + unsigned dkey = SPItem::display_key_new(1); + + // TODO need to refactor 'evil' referenced code for const correctness. + SPHatch *evil = const_cast<SPHatch *>(hatch); + evil->show(drawing, dkey, pbox); + + SPHatch::RenderInfo render_info = hatch->calculateRenderInfo(dkey); + Geom::Rect tile_rect = render_info.tile_rect; + + // Cairo requires an integer pattern surface width/height. + // Subtract 0.5 to prevent small rounding errors from increasing pattern size by one pixel. + // Multiply by SUBPIX_SCALE to allow for less than a pixel precision + const int subpix_scale = 10; + double surface_width = MAX(ceil(subpix_scale * tile_rect.width() - 0.5), 1); + double surface_height = MAX(ceil(subpix_scale * tile_rect.height() - 0.5), 1); + Geom::Affine drawing_scale = Geom::Scale(surface_width / tile_rect.width(), surface_height / tile_rect.height()); + Geom::Affine drawing_transform = Geom::Translate(-tile_rect.min()) * drawing_scale; + + Geom::Affine child_transform = render_info.child_transform; + child_transform *= drawing_transform; + + //The rendering of hatch overflow is implemented by repeated drawing + //of hatch paths over one strip. Within each iteration paths are moved by pitch value. + //The movement progresses from right to left. This gives the same result + //as drawing whole strips in left-to-right order. + gdouble overflow_right_strip = 0.0; + int overflow_steps = 1; + Geom::Affine overflow_transform; + if (hatch->style->overflow.computed == SP_CSS_OVERFLOW_VISIBLE) { + Geom::Interval bounds = hatch->bounds(); + overflow_right_strip = floor(bounds.max() / hatch->pitch()) * hatch->pitch(); + overflow_steps = ceil((overflow_right_strip - bounds.min()) / hatch->pitch()) + 1; + overflow_transform = Geom::Translate(hatch->pitch(), 0.0); + } + + CairoRenderContext *pattern_ctx = cloneMe(surface_width, surface_height); + pattern_ctx->setTransform(child_transform); + pattern_ctx->transform(Geom::Translate(-overflow_right_strip, 0.0)); + pattern_ctx->pushState(); + + std::vector<SPHatchPath *> children(evil->hatchPaths()); + + for (int i = 0; i < overflow_steps; i++) { + for (std::vector<SPHatchPath *>::iterator iter = children.begin(); iter != children.end(); iter++) { + SPHatchPath *path = *iter; + _renderer->renderHatchPath(pattern_ctx, *path, dkey); + } + pattern_ctx->transform(overflow_transform); + } + + pattern_ctx->popState(); + + // setup a cairo_pattern_t + cairo_surface_t *pattern_surface = pattern_ctx->getSurface(); + TEST(pattern_ctx->saveAsPng("hatch.png")); + cairo_pattern_t *result = cairo_pattern_create_for_surface(pattern_surface); + cairo_pattern_set_extend(result, CAIRO_EXTEND_REPEAT); + + Geom::Affine pattern_transform; + pattern_transform = render_info.pattern_to_user_transform.inverse() * drawing_transform; + ink_cairo_pattern_set_matrix(result, pattern_transform); + + evil->hide(dkey); + + delete pattern_ctx; + return result; +} + +cairo_pattern_t* CairoRenderContext::_createPatternForPaintServer(SPPaintServer const *const paintserver, Geom::OptRect const &pbox, float alpha) { @@ -1182,8 +1260,9 @@ CairoRenderContext::_createPatternForPaintServer(SPPaintServer const *const pain cairo_pattern_add_color_stop_rgba(pattern, rg->vector.stops[i].offset, rgb[0], rgb[1], rgb[2], rg->vector.stops[i].opacity * alpha); } } else if (SP_IS_PATTERN (paintserver)) { - pattern = _createPatternPainter(paintserver, pbox); + } else if ( dynamic_cast<SPHatch const *>(paintserver) ) { + pattern = _createHatchPainter(paintserver, pbox); } else { return NULL; } @@ -1249,26 +1328,29 @@ CairoRenderContext::_setFillStyle(SPStyle const *const style, Geom::OptRect cons TRACE(("merged op=%f\n", alpha)); } - if (style->fill.isColor()) { - float rgb[3]; - sp_color_get_rgb_floatv(&style->fill.value.color, rgb); + SPPaintServer const *paint_server = style->getFillPaintServer(); + if (paint_server && paint_server->isValid()) { - cairo_set_source_rgba(_cr, rgb[0], rgb[1], rgb[2], alpha); - - } else if (!style->fill.set) { // unset fill is black - cairo_set_source_rgba(_cr, 0, 0, 0, alpha); - - } else { - g_assert( style->fill.isPaintserver() - || SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) - || SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style)) ); - - cairo_pattern_t *pattern = _createPatternForPaintServer(SP_STYLE_FILL_SERVER(style), pbox, alpha); + g_assert(SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) + || SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style)) + || dynamic_cast<SPHatch *>(SP_STYLE_FILL_SERVER(style))); + cairo_pattern_t *pattern = _createPatternForPaintServer(paint_server, pbox, alpha); if (pattern) { cairo_set_source(_cr, pattern); cairo_pattern_destroy(pattern); } + } else if (style->fill.colorSet) { + float rgb[3]; + sp_color_get_rgb_floatv(&style->fill.value.color, rgb); + + cairo_set_source_rgba(_cr, rgb[0], rgb[1], rgb[2], alpha); + + } else { // unset fill is black + g_assert(!style->fill.set + || (paint_server && !paint_server->isValid())); + + cairo_set_source_rgba(_cr, 0, 0, 0, alpha); } } @@ -1279,7 +1361,7 @@ CairoRenderContext::_setStrokeStyle(SPStyle const *style, Geom::OptRect const &p if (_state->merge_opacity) alpha *= _state->opacity; - if (style->stroke.isColor()) { + if (style->stroke.isColor() || (style->stroke.isPaintserver() && !style->getStrokePaintServer()->isValid())) { float rgb[3]; sp_color_get_rgb_floatv(&style->stroke.value.color, rgb); @@ -1287,7 +1369,8 @@ CairoRenderContext::_setStrokeStyle(SPStyle const *style, Geom::OptRect const &p } else { g_assert( style->stroke.isPaintserver() || SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) - || SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style)) ); + || SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style)) + || dynamic_cast<SPHatch *>(SP_STYLE_STROKE_SERVER(style))); cairo_pattern_t *pattern = _createPatternForPaintServer(SP_STYLE_STROKE_SERVER(style), pbox, alpha); diff --git a/src/extension/internal/cairo-render-context.h b/src/extension/internal/cairo-render-context.h index 8d3e63775..57d155b60 100644 --- a/src/extension/internal/cairo-render-context.h +++ b/src/extension/internal/cairo-render-context.h @@ -31,6 +31,9 @@ class SPClipPath; class SPMask; +typedef struct _PangoFont PangoFont; +typedef struct _PangoLayout PangoLayout; + namespace Inkscape { class Pixbuf; @@ -201,6 +204,7 @@ protected: cairo_pattern_t *_createPatternForPaintServer(SPPaintServer const *const paintserver, Geom::OptRect const &pbox, float alpha); cairo_pattern_t *_createPatternPainter(SPPaintServer const *const paintserver, Geom::OptRect const &pbox); + cairo_pattern_t *_createHatchPainter(SPPaintServer const *const paintserver, Geom::OptRect const &pbox); unsigned int _showGlyphs(cairo_t *cr, PangoFont *font, std::vector<CairoGlyphInfo> const &glyphtext, bool is_stroke); diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp index 0c314a576..0c4ad4f0a 100644 --- a/src/extension/internal/cairo-renderer-pdf-out.cpp +++ b/src/extension/internal/cairo-renderer-pdf-out.cpp @@ -250,7 +250,7 @@ CairoRendererPdfOutput::init (void) "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n" "<param name=\"textToLaTeX\" gui-text=\"" N_("PDF+LaTeX: Omit text in PDF, and create LaTeX file") "\" type=\"boolean\">false</param>\n" "<param name=\"blurToBitmap\" gui-text=\"" N_("Rasterize filter effects") "\" type=\"boolean\">true</param>\n" - "<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">90</param>\n" + "<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">96</param>\n" "<param name=\"area\" gui-text=\"" N_("Output page size:") "\" type=\"optiongroup\" >\n" "<_option value=\"page\">" N_("Use document's page size") "</_option>" "<_option value=\"drawing\">" N_("Use exported object's size") "</_option>" diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 6fbc85c05..5a9a28ef9 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -42,7 +42,7 @@ #include "sp-item.h" #include "sp-item-group.h" #include "style.h" -#include "marker.h" +#include "sp-marker.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" #include "sp-root.h" @@ -50,6 +50,7 @@ #include "sp-use.h" #include "sp-text.h" #include "sp-flowtext.h" +#include "sp-hatch-path.h" #include "sp-image.h" #include "sp-symbol.h" #include "sp-pattern.h" @@ -146,13 +147,13 @@ Here comes the rendering part which could be put into the 'render' methods of SP /* The below functions are copy&pasted plus slightly modified from *_invoke_print functions. */ static void sp_item_invoke_render(SPItem *item, CairoRenderContext *ctx); -static void sp_group_render(SPItem *item, CairoRenderContext *ctx); -static void sp_use_render(SPItem *item, CairoRenderContext *ctx); -static void sp_shape_render(SPItem *item, CairoRenderContext *ctx); -static void sp_text_render(SPItem *item, CairoRenderContext *ctx); -static void sp_flowtext_render(SPItem *item, CairoRenderContext *ctx); -static void sp_image_render(SPItem *item, CairoRenderContext *ctx); -static void sp_symbol_render(SPItem *item, CairoRenderContext *ctx); +static void sp_group_render(SPGroup *group, CairoRenderContext *ctx); +static void sp_use_render(SPUse *use, CairoRenderContext *ctx); +static void sp_shape_render(SPShape *shape, CairoRenderContext *ctx); +static void sp_text_render(SPText *text, CairoRenderContext *ctx); +static void sp_flowtext_render(SPFlowtext *flowtext, CairoRenderContext *ctx); +static void sp_image_render(SPImage *image, CairoRenderContext *ctx); +static void sp_symbol_render(SPSymbol *symbol, CairoRenderContext *ctx); static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx); static void sp_shape_render_invoke_marker_rendering(SPMarker* marker, Geom::Affine tr, SPStyle* style, CairoRenderContext *ctx) @@ -178,17 +179,15 @@ static void sp_shape_render_invoke_marker_rendering(SPMarker* marker, Geom::Affi } } -static void sp_shape_render (SPItem *item, CairoRenderContext *ctx) +static void sp_shape_render(SPShape *shape, CairoRenderContext *ctx) { - SPShape *shape = SP_SHAPE(item); - if (!shape->_curve) { return; } - Geom::OptRect pbox = item->geometricBounds(); + Geom::OptRect pbox = shape->geometricBounds(); - SPStyle* style = item->style; + SPStyle* style = shape->style; Geom::PathVector const & pathv = shape->_curve->get_pathvector(); if (pathv.empty()) { @@ -200,10 +199,12 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx) // START marker for (int i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START if ( shape->_marker[i] ) { - SPMarker* marker = SP_MARKER (shape->_marker[i]); + SPMarker* marker = shape->_marker[i]; Geom::Affine tr; - if (marker->orient_auto) { + if (marker->orient_mode == MARKER_ORIENT_AUTO) { tr = sp_shape_marker_get_transform_at_start(pathv.begin()->front()); + } else if (marker->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) { + tr = Geom::Rotate::from_degrees( 180.0 ) * sp_shape_marker_get_transform_at_start(pathv.begin()->front()); } else { tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(pathv.begin()->front().pointAt(0)); } @@ -213,14 +214,14 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx) // MID marker for (int i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID if ( !shape->_marker[i] ) continue; - SPMarker* marker = SP_MARKER (shape->_marker[i]); + SPMarker* marker = shape->_marker[i]; for(Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { // START position if ( path_it != pathv.begin() && ! ((path_it == (pathv.end()-1)) && (path_it->size_default() == 0)) ) // if this is the last path and it is a moveto-only, there is no mid marker there { Geom::Affine tr; - if (marker->orient_auto) { + if (marker->orient_mode != MARKER_ORIENT_ANGLE) { tr = sp_shape_marker_get_transform_at_start(path_it->front()); } else { tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(path_it->front().pointAt(0)); @@ -237,7 +238,7 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx) * Loop to end_default (so including closing segment), because when a path is closed, * there should be a midpoint marker between last segment and closing straight line segment */ Geom::Affine tr; - if (marker->orient_auto) { + if (marker->orient_mode != MARKER_ORIENT_ANGLE) { tr = sp_shape_marker_get_transform(*curve_it1, *curve_it2); } else { tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(curve_it1->pointAt(1)); @@ -253,7 +254,7 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx) if ( path_it != (pathv.end()-1) && !path_it->empty()) { Geom::Curve const &lastcurve = path_it->back_default(); Geom::Affine tr; - if (marker->orient_auto) { + if (marker->orient_mode != MARKER_ORIENT_ANGLE) { tr = sp_shape_marker_get_transform_at_end(lastcurve); } else { tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1)); @@ -265,7 +266,7 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx) // END marker for (int i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END if ( shape->_marker[i] ) { - SPMarker* marker = SP_MARKER (shape->_marker[i]); + SPMarker* marker = shape->_marker[i]; /* Get reference to last curve in the path. * For moveto-only path, this returns the "closing line segment". */ @@ -277,7 +278,7 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx) Geom::Curve const &lastcurve = path_last[index]; Geom::Affine tr; - if (marker->orient_auto) { + if (marker->orient_mode != MARKER_ORIENT_ANGLE) { tr = sp_shape_marker_get_transform_at_end(lastcurve); } else { tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1)); @@ -288,26 +289,25 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx) } } -static void sp_group_render(SPItem *item, CairoRenderContext *ctx) +static void sp_group_render(SPGroup *group, CairoRenderContext *ctx) { - SPGroup *group = SP_GROUP(item); CairoRenderer *renderer = ctx->getRenderer(); TRACE(("sp_group_render opacity: %f\n", SP_SCALE24_TO_FLOAT(item->style->opacity.value))); GSList *l = g_slist_reverse(group->childList(false)); while (l) { - SPObject *o = SP_OBJECT (l->data); - if (SP_IS_ITEM(o)) { - renderer->renderItem (ctx, SP_ITEM (o)); + SPObject *o = reinterpret_cast<SPObject *>(l->data); + SPItem *item = dynamic_cast<SPItem *>(o); + if (item) { + renderer->renderItem(ctx, item); } l = g_slist_remove (l, o); } } -static void sp_use_render(SPItem *item, CairoRenderContext *ctx) +static void sp_use_render(SPUse *use, CairoRenderContext *ctx) { bool translated = false; - SPUse *use = SP_USE(item); CairoRenderer *renderer = ctx->getRenderer(); if ((use->x._set && use->x.computed != 0) || (use->y._set && use->y.computed != 0)) { @@ -317,8 +317,8 @@ static void sp_use_render(SPItem *item, CairoRenderContext *ctx) translated = true; } - if (use->child && SP_IS_ITEM(use->child)) { - renderer->renderItem(ctx, SP_ITEM(use->child)); + if (use->child) { + renderer->renderItem(ctx, use->child); } if (translated) { @@ -326,30 +326,27 @@ static void sp_use_render(SPItem *item, CairoRenderContext *ctx) } } -static void sp_text_render(SPItem *item, CairoRenderContext *ctx) +static void sp_text_render(SPText *text, CairoRenderContext *ctx) { - SPText *group = SP_TEXT (item); - group->layout.showGlyphs(ctx); + text->layout.showGlyphs(ctx); } -static void sp_flowtext_render(SPItem *item, CairoRenderContext *ctx) +static void sp_flowtext_render(SPFlowtext *flowtext, CairoRenderContext *ctx) { - SPFlowtext *group = SP_FLOWTEXT(item); - group->layout.showGlyphs(ctx); + flowtext->layout.showGlyphs(ctx); } -static void sp_image_render(SPItem *item, CairoRenderContext *ctx) +static void sp_image_render(SPImage *image, CairoRenderContext *ctx) { - SPImage *image; - int w, h; - - image = SP_IMAGE (item); - - if (!image->pixbuf) return; - if ((image->width.computed <= 0.0) || (image->height.computed <= 0.0)) return; + if (!image->pixbuf) { + return; + } + if ((image->width.computed <= 0.0) || (image->height.computed <= 0.0)) { + return; + } - w = image->pixbuf->width(); - h = image->pixbuf->height(); + int w = image->pixbuf->width(); + int h = image->pixbuf->height(); double x = image->x.computed; double y = image->y.computed; @@ -369,12 +366,11 @@ static void sp_image_render(SPItem *item, CairoRenderContext *ctx) Geom::Scale s(width / (double)w, height / (double)h); Geom::Affine t(s * tp); - ctx->renderImage (image->pixbuf, t, item->style); + ctx->renderImage(image->pixbuf, t, image->style); } -static void sp_symbol_render(SPItem *item, CairoRenderContext *ctx) +static void sp_symbol_render(SPSymbol *symbol, CairoRenderContext *ctx) { - SPSymbol *symbol = SP_SYMBOL(item); if (!symbol->cloned) { return; } @@ -409,7 +405,7 @@ static void sp_symbol_render(SPItem *item, CairoRenderContext *ctx) ctx->transform(vb2user); } - sp_group_render(item, ctx); + sp_group_render(symbol, ctx); ctx->popState(); } @@ -476,7 +472,7 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx) double shift_x = bbox->min()[Geom::X]; double shift_y = bbox->max()[Geom::Y]; - // For default 90 dpi, snap bitmap to pixel grid + // For default 96 dpi, snap bitmap to pixel grid if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { shift_x = round (shift_x); shift_y = -round (-shift_y); // Correct rounding despite coordinate inversion. @@ -521,34 +517,56 @@ static void sp_item_invoke_render(SPItem *item, CairoRenderContext *ctx) SPStyle* style = item->style; if((ctx->getFilterToBitmap() == TRUE) && (style->filter.set != 0)) { - return sp_asbitmap_render(item, ctx); + sp_asbitmap_render(item, ctx); } - if (SP_IS_ROOT(item)) { + SPRoot *root = dynamic_cast<SPRoot *>(item); + if (root) { TRACE(("root\n")); - return sp_root_render(SP_ROOT(item), ctx); - } else if (SP_IS_SYMBOL(item)) { - TRACE(("symbol\n")); - return sp_symbol_render(item, ctx); - } else if (SP_IS_GROUP(item)) { - TRACE(("group\n")); - return sp_group_render(item, ctx); - } else if (SP_IS_SHAPE(item)) { - TRACE(("shape\n")); - return sp_shape_render(item, ctx); - } else if (SP_IS_USE(item)) { - TRACE(("use begin---\n")); - sp_use_render(item, ctx); - TRACE(("---use end\n")); - } else if (SP_IS_TEXT(item)) { - TRACE(("text\n")); - return sp_text_render(item, ctx); - } else if (SP_IS_FLOWTEXT(item)) { - TRACE(("flowtext\n")); - return sp_flowtext_render(item, ctx); - } else if (SP_IS_IMAGE(item)) { - TRACE(("image\n")); - return sp_image_render(item, ctx); + sp_root_render(root, ctx); + } else { + SPSymbol *symbol = dynamic_cast<SPSymbol *>(item); + if (symbol) { + TRACE(("symbol\n")); + sp_symbol_render(symbol, ctx); + } else { + SPGroup *group = dynamic_cast<SPGroup *>(item); + if (group) { + TRACE(("group\n")); + sp_group_render(group, ctx); + } else { + SPShape *shape = dynamic_cast<SPShape *>(item); + if (shape) { + TRACE(("shape\n")); + sp_shape_render(shape, ctx); + } else { + SPUse *use = dynamic_cast<SPUse *>(item); + if (use) { + TRACE(("use begin---\n")); + sp_use_render(use, ctx); + TRACE(("---use end\n")); + } else { + SPText *text = dynamic_cast<SPText *>(item); + if (text) { + TRACE(("text\n")); + sp_text_render(text, ctx); + } else { + SPFlowtext *flowtext = dynamic_cast<SPFlowtext *>(item); + if (flowtext) { + TRACE(("flowtext\n")); + sp_flowtext_render(flowtext, ctx); + } else { + SPImage *image = dynamic_cast<SPImage *>(item); + if (image) { + TRACE(("image\n")); + sp_image_render(image, ctx); + } + } + } + } + } + } + } } } @@ -568,8 +586,9 @@ CairoRenderer::setStateForItem(CairoRenderContext *ctx, SPItem const *item) // This is so because we use the image's/(flow)text's transform for positioning // instead of explicitly specifying it and letting the renderer do the // transformation before rendering the item. - if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item) || SP_IS_IMAGE(item)) + if (dynamic_cast<SPText const *>(item) || dynamic_cast<SPFlowtext const *>(item) || dynamic_cast<SPImage const *>(item)) { state->parent_has_userspace = TRUE; + } TRACE(("setStateForItem opacity: %f\n", state->opacity)); } @@ -596,6 +615,21 @@ void CairoRenderer::renderItem(CairoRenderContext *ctx, SPItem *item) ctx->popState(); } +void CairoRenderer::renderHatchPath(CairoRenderContext *ctx, SPHatchPath const &hatchPath, unsigned key) { + ctx->pushState(); + ctx->setStateForStyle(hatchPath.style); + ctx->transform(Geom::Translate(hatchPath.offset.computed, 0)); + + SPCurve *curve = hatchPath.calculateRenderCurve(key); + Geom::PathVector const & pathv =curve->get_pathvector(); + if (!pathv.empty()) { + ctx->renderPathVector(pathv, hatchPath.style, Geom::OptRect()); + } + + curve->unref(); + ctx->popState(); +} + bool CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool pageBoundingBox, float bleedmargin_px, SPItem *base) { @@ -682,8 +716,8 @@ CairoRenderer::applyClipPath(CairoRenderContext *ctx, SPClipPath const *cp) TRACE(("BEGIN clip\n")); SPObject const *co = cp; for ( SPObject const *child = co->firstChild() ; child; child = child->getNext() ) { - if (SP_IS_ITEM(child)) { - SPItem const *item = SP_ITEM(child); + SPItem const *item = dynamic_cast<SPItem const *>(child); + if (item) { // combine transform of the item in clippath and the item using clippath: Geom::Affine tempmat = item->transform * ctx->getCurrentState()->item_transform; @@ -741,8 +775,8 @@ CairoRenderer::applyMask(CairoRenderContext *ctx, SPMask const *mask) TRACE(("BEGIN mask\n")); SPObject const *co = mask; for ( SPObject const *child = co->firstChild() ; child; child = child->getNext() ) { - if (SP_IS_ITEM(child)) { - SPItem const *item = SP_ITEM(child); + SPItem const *item = dynamic_cast<SPItem const *>(child); + if (item) { // TODO fix const correctness: renderItem(ctx, const_cast<SPItem*>(item)); } diff --git a/src/extension/internal/cairo-renderer.h b/src/extension/internal/cairo-renderer.h index cfef6bdea..abc0447d8 100644 --- a/src/extension/internal/cairo-renderer.h +++ b/src/extension/internal/cairo-renderer.h @@ -29,6 +29,7 @@ class SPClipPath; class SPMask; +class SPHatchPath; namespace Inkscape { namespace Extension { @@ -57,6 +58,7 @@ public: /** Traverses the object tree and invokes the render methods. */ void renderItem(CairoRenderContext *ctx, SPItem *item); + void renderHatchPath(CairoRenderContext *ctx, SPHatchPath const &hatchPath, unsigned key); }; // FIXME: this should be a static method of CairoRenderer diff --git a/src/extension/internal/cdr-input.cpp b/src/extension/internal/cdr-input.cpp index 0111ed626..3a3e2b58e 100644 --- a/src/extension/internal/cdr-input.cpp +++ b/src/extension/internal/cdr-input.cpp @@ -24,7 +24,21 @@ #include <cstring> #include <libcdr/libcdr.h> -#include <libwpd-stream/libwpd-stream.h> + +// TODO: Drop this check when librevenge is widespread. +#if WITH_LIBCDR01 + #include <librevenge-stream/librevenge-stream.h> + + using librevenge::RVNGString; + using librevenge::RVNGFileStream; + using librevenge::RVNGStringVector; +#else + #include <libwpd-stream/libwpd-stream.h> + + typedef WPXString RVNGString; + typedef WPXFileStream RVNGFileStream; + typedef libcdr::CDRStringVector RVNGStringVector; +#endif #include <gtkmm/alignment.h> #include <gtkmm/comboboxtext.h> @@ -40,7 +54,7 @@ #include "document-undo.h" #include "inkscape.h" -#include "dialogs/dialog-events.h" +#include "ui/dialog-events.h" #include <gtk/gtk.h> #include "ui/widget/spinbutton.h" #include "ui/widget/frame.h" @@ -60,7 +74,7 @@ namespace Internal { class CdrImportDialog : public Gtk::Dialog { public: - CdrImportDialog(const std::vector<WPXString> &vec); + CdrImportDialog(const std::vector<RVNGString> &vec); virtual ~CdrImportDialog(); bool showDialog(); @@ -86,12 +100,12 @@ private: class Gtk::VBox * vbox2; class Gtk::Widget * _previewArea; - const std::vector<WPXString> &_vec; // Document to be imported + const std::vector<RVNGString> &_vec; // Document to be imported unsigned _current_page; // Current selected page int _preview_width, _preview_height; // Size of the preview area }; -CdrImportDialog::CdrImportDialog(const std::vector<WPXString> &vec) +CdrImportDialog::CdrImportDialog(const std::vector<RVNGString> &vec) : _vec(vec), _current_page(1) { int num_pages = _vec.size(); @@ -139,9 +153,15 @@ CdrImportDialog::CdrImportDialog(const std::vector<WPXString> &vec) _labelTotalPages->set_use_markup(false); _labelTotalPages->set_selectable(false); vbox2->pack_start(*_previewArea, Gtk::PACK_SHRINK, 0); +#if WITH_GTKMM_3_0 + this->get_content_area()->set_homogeneous(false); + this->get_content_area()->set_spacing(0); + this->get_content_area()->pack_start(*vbox2); +#else this->get_vbox()->set_homogeneous(false); this->get_vbox()->set_spacing(0); this->get_vbox()->pack_start(*vbox2); +#endif this->set_title(_("Page Selector")); this->set_modal(true); sp_transientize(GTK_WIDGET(this->gobj())); //Make transient @@ -210,14 +230,20 @@ void CdrImportDialog::_setPreviewPage(unsigned page) SPDocument *CdrInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { - WPXFileStream input(uri); + RVNGFileStream input(uri); if (!libcdr::CDRDocument::isSupported(&input)) { return NULL; } - libcdr::CDRStringVector output; + RVNGStringVector output; +#if WITH_LIBCDR01 + librevenge::RVNGSVGDrawingGenerator generator(output, "svg"); + + if (!libcdr::CDRDocument::parse(&input, &generator)) { +#else if (!libcdr::CDRDocument::generateSVG(&input, output)) { +#endif return NULL; } @@ -225,9 +251,9 @@ SPDocument *CdrInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u return NULL; } - std::vector<WPXString> tmpSVGOutput; + std::vector<RVNGString> tmpSVGOutput; for (unsigned i=0; i<output.size(); ++i) { - WPXString tmpString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); + RVNGString tmpString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); tmpString.append(output[i]); tmpSVGOutput.push_back(tmpString); } diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index eae3bfb5a..4b070cbaa 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -27,15 +27,14 @@ # include "config.h" #endif -//#include <png.h> //This must precede text_reassemble.h or it blows up in pngconf.h when compiling #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <libuemf/symbol_convert.h> -#include "sp-root.h" +#include "document.h" +#include "sp-root.h" // even though it is included indirectly by wmf-inout.h #include "sp-path.h" -#include "style.h" #include "print.h" #include "extension/system.h" #include "extension/print.h" @@ -45,12 +44,9 @@ #include "display/drawing.h" #include "display/drawing-item.h" #include "clear-n_.h" -#include "document.h" -#include "util/units.h" -#include "shape-editor.h" -#include "sp-namedview.h" -#include "document-undo.h" -#include "inkscape.h" +#include "svg/svg.h" +#include "util/units.h" // even though it is included indirectly by wmf-inout.h +#include "inkscape.h" // even though it is included indirectly by wmf-inout.h #include "emf-print.h" #include "emf-inout.h" @@ -65,10 +61,9 @@ namespace Inkscape { namespace Extension { namespace Internal { -static U_RECTL rc_old = rectl_set(pointl_set(-1,-1),pointl_set(-1,-1)); -static bool clipset = false; static uint32_t ICMmode = 0; // not used yet, but code to read it from EMF implemented static uint32_t BLTmode = 0; +float faraway = 10000000; // used in "exclude" clips, hopefully well outside any real drawing! Emf::Emf (void) // The null constructor { @@ -273,54 +268,54 @@ uint32_t Emf::add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hpathname); - *(d->defs) += "\n"; + d->defs += "\n"; switch(hatchType){ case U_HS_HORIZONTAL: - *(d->defs) += " <path id=\""; - *(d->defs) += hpathname; - *(d->defs) += "\" d=\"M 0 0 6 0\" style=\"fill:none;stroke:#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\" />\n"; + d->defs += " <path id=\""; + d->defs += hpathname; + d->defs += "\" d=\"M 0 0 6 0\" style=\"fill:none;stroke:#"; + d->defs += tmpcolor; + d->defs += "\" />\n"; break; case U_HS_VERTICAL: - *(d->defs) += " <path id=\""; - *(d->defs) += hpathname; - *(d->defs) += "\" d=\"M 0 0 0 6\" style=\"fill:none;stroke:#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\" />\n"; + d->defs += " <path id=\""; + d->defs += hpathname; + d->defs += "\" d=\"M 0 0 0 6\" style=\"fill:none;stroke:#"; + d->defs += tmpcolor; + d->defs += "\" />\n"; break; case U_HS_FDIAGONAL: - *(d->defs) += " <line id=\"sub"; - *(d->defs) += hpathname; - *(d->defs) += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\"/>\n"; + d->defs += " <line id=\"sub"; + d->defs += hpathname; + d->defs += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; + d->defs += tmpcolor; + d->defs += "\"/>\n"; break; case U_HS_BDIAGONAL: - *(d->defs) += " <line id=\"sub"; - *(d->defs) += hpathname; - *(d->defs) += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\"/>\n"; + d->defs += " <line id=\"sub"; + d->defs += hpathname; + d->defs += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; + d->defs += tmpcolor; + d->defs += "\"/>\n"; break; case U_HS_CROSS: - *(d->defs) += " <path id=\""; - *(d->defs) += hpathname; - *(d->defs) += "\" d=\"M 0 0 6 0 M 0 0 0 6\" style=\"fill:none;stroke:#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\" />\n"; + d->defs += " <path id=\""; + d->defs += hpathname; + d->defs += "\" d=\"M 0 0 6 0 M 0 0 0 6\" style=\"fill:none;stroke:#"; + d->defs += tmpcolor; + d->defs += "\" />\n"; break; case U_HS_DIAGCROSS: - *(d->defs) += " <line id=\"subfd"; - *(d->defs) += hpathname; - *(d->defs) += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\"/>\n"; - *(d->defs) += " <line id=\"subbd"; - *(d->defs) += hpathname; - *(d->defs) += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\"/>\n"; + d->defs += " <line id=\"subfd"; + d->defs += hpathname; + d->defs += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; + d->defs += tmpcolor; + d->defs += "\"/>\n"; + d->defs += " <line id=\"subbd"; + d->defs += hpathname; + d->defs += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; + d->defs += tmpcolor; + d->defs += "\"/>\n"; break; case U_HS_SOLIDCLR: case U_HS_DITHEREDCLR: @@ -329,12 +324,12 @@ uint32_t Emf::add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat case U_HS_SOLIDBKCLR: case U_HS_DITHEREDBKCLR: default: - *(d->defs) += " <path id=\""; - *(d->defs) += hpathname; - *(d->defs) += "\" d=\"M 0 0 6 0 6 6 0 6 z\" style=\"fill:#"; - *(d->defs) += tmpcolor; - *(d->defs) += ";stroke:none"; - *(d->defs) += "\" />\n"; + d->defs += " <path id=\""; + d->defs += hpathname; + d->defs += "\" d=\"M 0 0 6 0 6 6 0 6 z\" style=\"fill:#"; + d->defs += tmpcolor; + d->defs += ";stroke:none"; + d->defs += "\" />\n"; break; } } @@ -396,12 +391,12 @@ uint32_t Emf::add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(!idx){ // add it if not already present if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hatchname); - *(d->defs) += "\n"; - *(d->defs) += " <pattern id=\""; - *(d->defs) += hatchname; - *(d->defs) += "\" xlink:href=\"#EMFhbasepattern\">\n"; - *(d->defs) += refpath; - *(d->defs) += " </pattern>\n"; + d->defs += "\n"; + d->defs += " <pattern id=\""; + d->defs += hatchname; + d->defs += "\" xlink:href=\"#EMFhbasepattern\">\n"; + d->defs += refpath; + d->defs += " </pattern>\n"; idx = d->hatches.count; } } @@ -414,12 +409,12 @@ uint32_t Emf::add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hbkname); - *(d->defs) += "\n"; - *(d->defs) += " <rect id=\""; - *(d->defs) += hbkname; - *(d->defs) += "\" x=\"0\" y=\"0\" width=\"6\" height=\"6\" fill=\"#"; - *(d->defs) += bkcolor; - *(d->defs) += "\" />\n"; + d->defs += "\n"; + d->defs += " <rect id=\""; + d->defs += hbkname; + d->defs += "\" x=\"0\" y=\"0\" width=\"6\" height=\"6\" fill=\"#"; + d->defs += bkcolor; + d->defs += "\" />\n"; } // this is the pattern, its name will show up in Inkscape's pattern selector @@ -428,15 +423,15 @@ uint32_t Emf::add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(!idx){ // add it if not already present if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hatchname); - *(d->defs) += "\n"; - *(d->defs) += " <pattern id=\""; - *(d->defs) += hatchname; - *(d->defs) += "\" xlink:href=\"#EMFhbasepattern\">\n"; - *(d->defs) += " <use xlink:href=\"#"; - *(d->defs) += hbkname; - *(d->defs) += "\" />\n"; - *(d->defs) += refpath; - *(d->defs) += " </pattern>\n"; + d->defs += "\n"; + d->defs += " <pattern id=\""; + d->defs += hatchname; + d->defs += "\" xlink:href=\"#EMFhbasepattern\">\n"; + d->defs += " <use xlink:href=\"#"; + d->defs += hbkname; + d->defs += "\" />\n"; + d->defs += refpath; + d->defs += " </pattern>\n"; idx = d->hatches.count; } } @@ -452,7 +447,7 @@ void Emf::enlarge_images(PEMF_CALLBACK_DATA d){ /* See if the image string is already in the list. If it is return its position (1->n, not 1-n-1) */ -int Emf::in_images(PEMF_CALLBACK_DATA d, char *test){ +int Emf::in_images(PEMF_CALLBACK_DATA d, const char *test){ int i; for(i=0; i<d->images.count; i++){ if(strcmp(test,d->images.strings[i])==0)return(i+1); @@ -544,35 +539,35 @@ uint32_t Emf::add_image(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t cbBits, uint sprintf(imagename,"EMFimage%d",idx++); sprintf(xywh," x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" ",width,height); // reuse this buffer - *(d->defs) += "\n"; - *(d->defs) += " <image id=\""; - *(d->defs) += imagename; - *(d->defs) += "\"\n "; - *(d->defs) += xywh; - *(d->defs) += "\n"; - if(dibparams == U_BI_JPEG){ *(d->defs) += " xlink:href=\"data:image/jpeg;base64,"; } - else { *(d->defs) += " xlink:href=\"data:image/png;base64,"; } - *(d->defs) += base64String; - *(d->defs) += "\"\n"; - *(d->defs) += " preserveAspectRatio=\"none\"\n"; - *(d->defs) += " />\n"; - - - *(d->defs) += "\n"; - *(d->defs) += " <pattern id=\""; - *(d->defs) += imagename; - *(d->defs) += "_ref\"\n "; - *(d->defs) += xywh; - *(d->defs) += "\n patternUnits=\"userSpaceOnUse\""; - *(d->defs) += " >\n"; - *(d->defs) += " <use id=\""; - *(d->defs) += imagename; - *(d->defs) += "_ign\" "; - *(d->defs) += " xlink:href=\"#"; - *(d->defs) += imagename; - *(d->defs) += "\" />\n"; - *(d->defs) += " "; - *(d->defs) += " </pattern>\n"; + d->defs += "\n"; + d->defs += " <image id=\""; + d->defs += imagename; + d->defs += "\"\n "; + d->defs += xywh; + d->defs += "\n"; + if(dibparams == U_BI_JPEG){ d->defs += " xlink:href=\"data:image/jpeg;base64,"; } + else { d->defs += " xlink:href=\"data:image/png;base64,"; } + d->defs += base64String; + d->defs += "\"\n"; + d->defs += " preserveAspectRatio=\"none\"\n"; + d->defs += " />\n"; + + + d->defs += "\n"; + d->defs += " <pattern id=\""; + d->defs += imagename; + d->defs += "_ref\"\n "; + d->defs += xywh; + d->defs += "\n patternUnits=\"userSpaceOnUse\""; + d->defs += " >\n"; + d->defs += " <use id=\""; + d->defs += imagename; + d->defs += "_ign\" "; + d->defs += " xlink:href=\"#"; + d->defs += imagename; + d->defs += "\" />\n"; + d->defs += " "; + d->defs += " </pattern>\n"; } g_free(base64String);//wait until this point to free because it might be a duplicate image @@ -596,17 +591,17 @@ uint32_t Emf::add_image(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t cbBits, uint d->images.strings[d->images.count++]=strdup(base64String); sprintf(imrotname,"EMFimage%d",idx++); - *(d->defs) += "\n"; - *(d->defs) += " <pattern\n"; - *(d->defs) += " id=\""; - *(d->defs) += imrotname; - *(d->defs) += "_ref\"\n"; - *(d->defs) += " xlink:href=\"#"; - *(d->defs) += imagename; - *(d->defs) += "_ref\"\n"; - *(d->defs) += " patternTransform="; - *(d->defs) += current_matrix(d, 0.0, 0.0, 0); //j use offset 0,0 - *(d->defs) += " />\n"; + d->defs += "\n"; + d->defs += " <pattern\n"; + d->defs += " id=\""; + d->defs += imrotname; + d->defs += "_ref\"\n"; + d->defs += " xlink:href=\"#"; + d->defs += imagename; + d->defs += "_ref\"\n"; + d->defs += " patternTransform="; + d->defs += current_matrix(d, 0.0, 0.0, 0); //j use offset 0,0 + d->defs += " />\n"; } g_free(base64String); } @@ -623,7 +618,7 @@ void Emf::enlarge_gradients(PEMF_CALLBACK_DATA d){ /* See if the gradient name is already in the list. If it is return its position (1->n, not 1-n-1) */ -int Emf::in_gradients(PEMF_CALLBACK_DATA d, char *test){ +int Emf::in_gradients(PEMF_CALLBACK_DATA d, const char *test){ int i; for(i=0; i<d->gradients.count; i++){ if(strcmp(test,d->gradients.strings[i])==0)return(i+1); @@ -716,12 +711,71 @@ uint32_t Emf::add_gradient(PEMF_CALLBACK_DATA d, uint32_t gradientType, U_TRIVER stmp << tmpcolor2; stmp << ";stop-opacity:1\" />\n"; stmp << " </linearGradient>\n"; - *(d->defs) += stmp.str().c_str(); + d->defs += stmp.str().c_str(); } return(idx-1); } +/* Add another 100 blank slots to the clips array. +*/ +void Emf::enlarge_clips(PEMF_CALLBACK_DATA d){ + d->clips.size += 100; + d->clips.strings = (char **) realloc(d->clips.strings,d->clips.size * sizeof(char *)); +} + +/* See if the pattern name is already in the list. If it is return its position (1->n, not 1-n-1) +*/ +int Emf::in_clips(PEMF_CALLBACK_DATA d, const char *test){ + int i; + for(i=0; i<d->clips.count; i++){ + if(strcmp(test,d->clips.strings[i])==0)return(i+1); + } + return(0); +} + +/* (Conditionally) add a clip. + If a matching clip already exists nothing happens + If one does exist it is added to the clips list, entered into <defs>. +*/ +void Emf::add_clips(PEMF_CALLBACK_DATA d, const char *clippath, unsigned int logic){ + int op = combine_ops_to_livarot(logic); + Geom::PathVector combined_vect; + char *combined = NULL; + if (op >= 0 && d->dc[d->level].clip_id) { + unsigned int real_idx = d->dc[d->level].clip_id - 1; + Geom::PathVector old_vect = sp_svg_read_pathv(d->clips.strings[real_idx]); + Geom::PathVector new_vect = sp_svg_read_pathv(clippath); + combined_vect = sp_pathvector_boolop(new_vect, old_vect, (bool_op) op , (FillRule) fill_oddEven, (FillRule) fill_oddEven); + combined = sp_svg_write_path(combined_vect); + } + else { + combined = strdup(clippath); // COPY operation, erases everything and starts a new one + } + + uint32_t idx = in_clips(d, combined); + if(!idx){ // add clip if not already present + if(d->clips.count == d->clips.size){ enlarge_clips(d); } + d->clips.strings[d->clips.count++]=strdup(combined); + d->dc[d->level].clip_id = d->clips.count; // one more than the slot where it is actually stored + SVGOStringStream tmp_clippath; + tmp_clippath << "\n<clipPath"; + tmp_clippath << "\n\tclipPathUnits=\"userSpaceOnUse\" "; + tmp_clippath << "\n\tid=\"clipEmfPath" << d->dc[d->level].clip_id << "\""; + tmp_clippath << " >"; + tmp_clippath << "\n\t<path d=\""; + tmp_clippath << combined; + tmp_clippath << "\""; + tmp_clippath << "\n\t/>"; + tmp_clippath << "\n</clipPath>"; + d->outdef += tmp_clippath.str().c_str(); + } + else { + d->dc[d->level].clip_id = idx; + } + free(combined); +} + void @@ -811,8 +865,8 @@ Emf::output_style(PEMF_CALLBACK_DATA d, int iType) // tmp_id << "\n\tid=\"" << (d->id++) << "\""; -// *(d->outsvg) += tmp_id.str().c_str(); - *(d->outsvg) += "\n\tstyle=\""; +// d->outsvg += tmp_id.str().c_str(); + d->outsvg += "\n\tstyle=\""; if (iType == U_EMR_STROKEPATH || !d->dc[d->level].fill_set) { tmp_style << "fill:none;"; } else { @@ -932,11 +986,10 @@ Emf::output_style(PEMF_CALLBACK_DATA d, int iType) tmp_style << "stroke-opacity:1;"; } tmp_style << "\" "; - if (clipset) - tmp_style << "\n\tclip-path=\"url(#clipEmfPath" << d->id << ")\" "; - clipset = false; + if (d->dc[d->level].clip_id) + tmp_style << "\n\tclip-path=\"url(#clipEmfPath" << d->dc[d->level].clip_id << ")\" "; - *(d->outsvg) += tmp_style.str().c_str(); + d->outsvg += tmp_style.str().c_str(); } @@ -988,13 +1041,30 @@ Emf::pix_to_abs_size(PEMF_CALLBACK_DATA d, double px) return ppx; } -/* returns "x,y" (without the quotes) in inkscape coordinates for a pair of EMF x,y coordinates +/* snaps coordinate pairs made up of values near +/-faraway, +/-faraway to exactly faraway. + This eliminates coordinate drift on repeated clipping cycles which use exclude. + It should not affect internals of normal drawings because the value of faraway is so large. +*/ +void +Emf::snap_to_faraway_pair(double *x, double *y) +{ + if((abs(abs(*x) - faraway)/faraway <= 1e-4) && (abs(abs(*y) - faraway)/faraway <= 1e-4)){ + *x = (*x > 0 ? faraway : -faraway); + *y = (*y > 0 ? faraway : -faraway); + } +} + +/* returns "x,y" (without the quotes) in inkscape coordinates for a pair of EMF x,y coordinates. + Since exclude clip can go through here, it calls snap_to_faraway_pair for numerical stability. */ std::string Emf::pix_to_xy(PEMF_CALLBACK_DATA d, double x, double y){ std::stringstream cxform; - cxform << pix_to_x_point(d,x,y); + double tx = pix_to_x_point(d,x,y); + double ty = pix_to_y_point(d,x,y); + snap_to_faraway_pair(&tx,&ty); + cxform << tx; cxform << ","; - cxform << pix_to_y_point(d,x,y); + cxform << ty; return(cxform.str()); } @@ -1104,14 +1174,11 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index) if (!d->dc[d->level].style.stroke_dasharray.values.empty() && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dasharray.values!=d->dc[d->level-1].style.stroke_dasharray.values))) d->dc[d->level].style.stroke_dasharray.values.clear(); for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) { - int cur_level = d->level; - d->level = d->emf_obj[index].level; // Doing it this way typically results in a pattern that is tiny, better to assume the array // is the same scale as for dot/dash below, that is, no scaling should be applied // double dash_length = pix_to_abs_size( d, pEmr->elp.elpStyleEntry[i] ); double dash_length = pEmr->elp.elpStyleEntry[i]; - d->level = cur_level; - d->dc[d->level].style.stroke_dasharray.values[i] = dash_length; + d->dc[d->level].style.stroke_dasharray.values.push_back(dash_length); } d->dc[d->level].style.stroke_dasharray.set = 1; } else { @@ -1525,8 +1592,8 @@ void Emf::common_image_extraction(PEMF_CALLBACK_DATA d, void *pEmr, tmp_image << " preserveAspectRatio=\"none\"\n"; tmp_image << "/> \n"; - *(d->outsvg) += tmp_image.str().c_str(); - *(d->path) = ""; + d->outsvg += tmp_image.str().c_str(); + d->path = ""; } /** @@ -1573,7 +1640,7 @@ int Emf::myEnhMetaFileProc(char *contents, unsigned int length, PEMF_CALLBACK_DA lpEMFR = (PU_ENHMETARECORD)(contents + off); // Uncomment the following to track down toxic records -//std::cout << "record type: " << lpEMFR->iType << " length: " << lpEMFR->nSize << " offset: " << off <<std::endl; +// std::cout << "record type: " << lpEMFR->iType << " name " << U_emr_names(lpEMFR->iType) << " length: " << lpEMFR->nSize << " offset: " << off <<std::endl; off += lpEMFR->nSize; SVGOStringStream tmp_outsvg; @@ -1592,11 +1659,19 @@ int Emf::myEnhMetaFileProc(char *contents, unsigned int length, PEMF_CALLBACK_DA // next record is valid type and forces pending text to be drawn immediately if ((d->dc[d->level].dirty & DIRTY_TEXT) || ((emr_mask != U_EMR_INVALID) && (emr_mask & U_DRAW_TEXT) && d->tri->dirty)){ TR_layout_analyze(d->tri); + if (d->dc[d->level].clip_id){ + SVGOStringStream tmp_clip; + tmp_clip << "\n<g\n\tclip-path=\"url(#clipEmfPath" << d->dc[d->level].clip_id << ")\"\n>"; + d->outsvg += tmp_clip.str().c_str(); + } TR_layout_2_svg(d->tri); SVGOStringStream ts; ts << d->tri->out; - *(d->outsvg) += ts.str().c_str(); + d->outsvg += ts.str().c_str(); d->tri = trinfo_clear(d->tri); + if (d->dc[d->level].clip_id){ + d->outsvg += "\n</g>\n"; + } } if(d->dc[d->level].dirty){ //Apply the delayed background changes, clear the flag d->dc[d->level].bkMode = tbkMode; @@ -1624,7 +1699,7 @@ int Emf::myEnhMetaFileProc(char *contents, unsigned int length, PEMF_CALLBACK_DA d->dc[d->level].dirty = 0; } -//std::cout << "BEFORE DRAW logic d->mask: " << std::hex << d->mask << " emr_mask: " << emr_mask << std::dec << std::endl; +// std::cout << "BEFORE DRAW logic d->mask: " << std::hex << d->mask << " emr_mask: " << emr_mask << std::dec << std::endl; /* std::cout << "BEFORE DRAW" << " test0 " << ( d->mask & U_DRAW_VISIBLE) @@ -1651,8 +1726,8 @@ std::cout << "BEFORE DRAW" ) ) ){ -// std::cout << "PATH DRAW at TOP" << std::endl; - *(d->outsvg) += " <path "; // this is the ONLY place <path should be used!!! One exception, gradientfill. +// std::cout << "PATH DRAW at TOP path" << *(d->path) << std::endl; + d->outsvg += " <path "; // this is the ONLY place <path should be used!!! One exception, gradientfill. if(d->drawtype){ // explicit draw type EMR record output_style(d, d->drawtype); } @@ -1662,11 +1737,11 @@ std::cout << "BEFORE DRAW" else { output_style(d, U_EMR_STROKEPATH); } - *(d->outsvg) += "\n\t"; - *(d->outsvg) += "\n\td=\""; // this is the ONLY place d=" should be used!!!! One exception, gradientfill. - *(d->outsvg) += *(d->path); - *(d->outsvg) += " \" /> \n"; - *(d->path) = ""; + d->outsvg += "\n\t"; + d->outsvg += "\n\td=\""; // this is the ONLY place d=" should be used!!!! One exception, gradientfill. + d->outsvg += d->path; + d->outsvg += " \" /> \n"; + d->path = ""; // reset the flags d->mask = 0; d->drawtype = 0; @@ -1679,12 +1754,12 @@ std::cout << "BEFORE DRAW" { dbg_str << "<!-- U_EMR_HEADER -->\n"; - *(d->outdef) += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; + d->outdef += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; if (d->pDesc) { - *(d->outdef) += "<!-- "; - *(d->outdef) += d->pDesc; - *(d->outdef) += " -->\n"; + d->outdef += "<!-- "; + d->outdef += d->pDesc; + d->outdef += " -->\n"; } PU_EMRHEADER pEmr = (PU_EMRHEADER) lpEMFR; @@ -1745,8 +1820,8 @@ std::cout << "BEFORE DRAW" tmp_outdef << " width=\"" << d->MMX << "mm\"\n" << " height=\"" << d->MMY << "mm\">\n"; - *(d->outdef) += tmp_outdef.str().c_str(); - *(d->outdef) += "<defs>"; // temporary end of header + d->outdef += tmp_outdef.str().c_str(); + d->outdef += "<defs>"; // temporary end of header // d->defs holds any defines which are read in. @@ -2015,7 +2090,7 @@ std::cout << "BEFORE DRAW" dbg_str << "<!-- U_EMR_EOF -->\n"; tmp_outsvg << "</svg>\n"; - *(d->outsvg) = *(d->outdef) + *(d->defs) + *(d->outsvg); + d->outsvg = d->outdef + d->defs + d->outsvg; OK=0; break; } @@ -2123,7 +2198,24 @@ std::cout << "BEFORE DRAW" } break; } - case U_EMR_OFFSETCLIPRGN: dbg_str << "<!-- U_EMR_OFFSETCLIPRGN -->\n"; break; + case U_EMR_OFFSETCLIPRGN: + { + dbg_str << "<!-- U_EMR_OFFSETCLIPRGN -->\n"; + if (d->dc[d->level].clip_id) { // can only offsetan existing clipping path + PU_EMROFFSETCLIPRGN pEmr = (PU_EMROFFSETCLIPRGN) lpEMFR; + U_POINTL off = pEmr->ptlOffset; + unsigned int real_idx = d->dc[d->level].clip_id - 1; + Geom::PathVector tmp_vect = sp_svg_read_pathv(d->clips.strings[real_idx]); + double ox = pix_to_x_point(d, off.x, off.y) - pix_to_x_point(d, 0, 0); // take into account all active transforms + double oy = pix_to_y_point(d, off.x, off.y) - pix_to_y_point(d, 0, 0); + Geom::Affine tf = Geom::Translate(ox,oy); + tmp_vect *= tf; + char *tmp_path = sp_svg_write_path(tmp_vect); + add_clips(d, tmp_path, U_RGN_COPY); + free(tmp_path); + } + break; + } case U_EMR_MOVETOEX: { dbg_str << "<!-- U_EMR_MOVETOEX -->\n"; @@ -2139,36 +2231,51 @@ std::cout << "BEFORE DRAW" break; } case U_EMR_SETMETARGN: dbg_str << "<!-- U_EMR_SETMETARGN -->\n"; break; - case U_EMR_EXCLUDECLIPRECT: dbg_str << "<!-- U_EMR_EXCLUDECLIPRECT -->\n"; break; + case U_EMR_EXCLUDECLIPRECT: + { + dbg_str << "<!-- U_EMR_EXCLUDECLIPRECT -->\n"; + + PU_EMREXCLUDECLIPRECT pEmr = (PU_EMREXCLUDECLIPRECT) lpEMFR; + U_RECTL rc = pEmr->rclClip; + + SVGOStringStream tmp_path; + //outer rect, clockwise + tmp_path << "M " << faraway << "," << faraway << " "; + tmp_path << "L " << faraway << "," << -faraway << " "; + tmp_path << "L " << -faraway << "," << -faraway << " "; + tmp_path << "L " << -faraway << "," << faraway << " "; + tmp_path << "z "; + //inner rect, counterclockwise (sign of Y is reversed) + tmp_path << "M " << pix_to_xy( d, rc.left , rc.top ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.right, rc.top ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.right, rc.bottom ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.left, rc.bottom ) << " "; + tmp_path << "z"; + + add_clips(d, tmp_path.str().c_str(), U_RGN_AND); + + d->path = ""; + d->drawtype = 0; + break; + } case U_EMR_INTERSECTCLIPRECT: { dbg_str << "<!-- U_EMR_INTERSECTCLIPRECT -->\n"; PU_EMRINTERSECTCLIPRECT pEmr = (PU_EMRINTERSECTCLIPRECT) lpEMFR; U_RECTL rc = pEmr->rclClip; - clipset = true; - if ((rc.left == rc_old.left) && (rc.top == rc_old.top) && (rc.right == rc_old.right) && (rc.bottom == rc_old.bottom)) - break; - rc_old = rc; - double dx = pix_to_x_point( d, rc.left, rc.top ); - double dy = pix_to_y_point( d, rc.left, rc.top ); - double dw = pix_to_abs_size( d, rc.right - rc.left + 1); - double dh = pix_to_abs_size( d, rc.bottom - rc.top + 1); - - SVGOStringStream tmp_rectangle; - tmp_rectangle << "\n<clipPath\n\tclipPathUnits=\"userSpaceOnUse\" "; - tmp_rectangle << "\nid=\"clipEmfPath" << ++(d->id) << "\" >"; - tmp_rectangle << "\n<rect "; - tmp_rectangle << "\n x=\"" << dx << "\" "; - tmp_rectangle << "\n y=\"" << dy << "\" "; - tmp_rectangle << "\n width=\"" << dw << "\" "; - tmp_rectangle << "\n height=\"" << dh << "\" "; - tmp_rectangle << "\n transform=" << current_matrix(d, dx, dy, 1); // calculate appropriate offset - tmp_rectangle << "/>\n</clipPath>"; + SVGOStringStream tmp_path; + tmp_path << "M " << pix_to_xy( d, rc.left , rc.top ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.right, rc.top ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.right, rc.bottom ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.left, rc.bottom ) << " "; + tmp_path << "z"; + + add_clips(d, tmp_path.str().c_str(), U_RGN_AND); - *(d->outdef) += tmp_rectangle.str().c_str(); - *(d->path) = ""; + d->path = ""; + d->drawtype = 0; break; } case U_EMR_SCALEVIEWPORTEXTEX: dbg_str << "<!-- U_EMR_SCALEVIEWPORTEXTEX -->\n"; break; @@ -2179,7 +2286,7 @@ std::cout << "BEFORE DRAW" if (d->level < EMF_MAX_DC) { d->dc[d->level + 1] = d->dc[d->level]; if(d->dc[d->level].font_name){ - d->dc[d->level + 1].font_name = strdup(d->dc[d->level].font_name); // or memory access problems because font name pointer duplicated + d->dc[d->level + 1].font_name = strdup(d->dc[d->level].font_name); // or memory access problems because font name pointer duplicated } d->level = d->level + 1; } @@ -2442,8 +2549,8 @@ std::cout << "BEFORE DRAW" double cx = pix_to_x_point( d, (rclBox.left + rclBox.right)/2.0, (rclBox.bottom + rclBox.top)/2.0 ); double cy = pix_to_y_point( d, (rclBox.left + rclBox.right)/2.0, (rclBox.bottom + rclBox.top)/2.0 ); - double rx = pix_to_abs_size( d, fabs(rclBox.right - rclBox.left )/2.0 ); - double ry = pix_to_abs_size( d, fabs(rclBox.top - rclBox.bottom)/2.0 ); + double rx = pix_to_abs_size( d, std::abs(rclBox.right - rclBox.left )/2.0 ); + double ry = pix_to_abs_size( d, std::abs(rclBox.top - rclBox.bottom)/2.0 ); SVGOStringStream tmp_ellipse; tmp_ellipse << "cx=\"" << cx << "\" "; @@ -2453,12 +2560,12 @@ std::cout << "BEFORE DRAW" d->mask |= emr_mask; - *(d->outsvg) += " <ellipse "; + d->outsvg += " <ellipse "; output_style(d, lpEMFR->iType); // - *(d->outsvg) += "\n\t"; - *(d->outsvg) += tmp_ellipse.str().c_str(); - *(d->outsvg) += "/> \n"; - *(d->path) = ""; + d->outsvg += "\n\t"; + d->outsvg += tmp_ellipse.str().c_str(); + d->outsvg += "/> \n"; + d->path = ""; break; } case U_EMR_RECTANGLE: @@ -2679,7 +2786,7 @@ std::cout << "BEFORE DRAW" // The next line should never be needed, should have been handled before main switch // qualifier added because EMF's encountered where moveto preceded beginpath followed by lineto if(d->mask & U_DRAW_VISIBLE){ - *(d->path) = ""; + d->path = ""; } d->mask |= emr_mask; break; @@ -2735,11 +2842,22 @@ std::cout << "BEFORE DRAW" } case U_EMR_FLATTENPATH: dbg_str << "<!-- U_EMR_FLATTENPATH -->\n"; break; case U_EMR_WIDENPATH: dbg_str << "<!-- U_EMR_WIDENPATH -->\n"; break; - case U_EMR_SELECTCLIPPATH: dbg_str << "<!-- U_EMR_SELECTCLIPPATH -->\n"; break; + case U_EMR_SELECTCLIPPATH: + { + dbg_str << "<!-- U_EMR_SELECTCLIPPATH -->\n"; + PU_EMRSELECTCLIPPATH pEmr = (PU_EMRSELECTCLIPPATH) lpEMFR; + int logic = pEmr->iMode; + + if ((logic < U_RGN_MIN) || (logic > U_RGN_MAX)){ break; } + add_clips(d, d->path.c_str(), logic); // finds an existing one or stores this, sets clip_id + d->path = ""; + d->drawtype = 0; + break; + } case U_EMR_ABORTPATH: { dbg_str << "<!-- U_EMR_ABORTPATH -->\n"; - *(d->path) = ""; + d->path = ""; d->drawtype = 0; break; } @@ -2778,8 +2896,10 @@ std::cout << "BEFORE DRAW" dbg_str << "<!-- U_EMR_EXTSELECTCLIPRGN -->\n"; PU_EMREXTSELECTCLIPRGN pEmr = (PU_EMREXTSELECTCLIPRGN) lpEMFR; - if (pEmr->iMode == U_RGN_COPY) - clipset = false; + // the only mode we implement - this clears the clipping region + if (pEmr->iMode == U_RGN_COPY) { + d->dc[d->level].clip_id = 0; + } break; } case U_EMR_BITBLT: @@ -3046,11 +3166,19 @@ std::cout << "BEFORE DRAW" int status = trinfo_load_textrec(d->tri, &tsp, tsp.ori,TR_EMFBOT); // ori is actually escapement if(status==-1){ // change of escapement, emit what we have and reset TR_layout_analyze(d->tri); + if (d->dc[d->level].clip_id){ + SVGOStringStream tmp_clip; + tmp_clip << "\n<g\n\tclip-path=\"url(#clipEmfPath" << d->dc[d->level].clip_id << ")\"\n>"; + d->outsvg += tmp_clip.str().c_str(); + } TR_layout_2_svg(d->tri); ts << d->tri->out; - *(d->outsvg) += ts.str().c_str(); + d->outsvg += ts.str().c_str(); d->tri = trinfo_clear(d->tri); (void) trinfo_load_textrec(d->tri, &tsp, tsp.ori,TR_EMFBOT); // ignore return status, it must work + if (d->dc[d->level].clip_id){ + d->outsvg += "\n</g>\n"; + } } g_free(escaped_text); @@ -3292,7 +3420,7 @@ std::cout << "BEFORE DRAW" tmp_rectangle << d->gradients.strings[fill_idx]; tmp_rectangle << ");\"\n/>\n"; } - *(d->outsvg) += tmp_rectangle.str().c_str(); + d->outsvg += tmp_rectangle.str().c_str(); } else if(pEmr->ulMode == U_GRADIENT_FILL_TRIANGLE){ SVGOStringStream tmp_triangle; @@ -3310,9 +3438,9 @@ std::cout << "BEFORE DRAW" tmp_triangle << tmpcolor; tmp_triangle << ";\"\n/>\n"; } - *(d->outsvg) += tmp_triangle.str().c_str(); + d->outsvg += tmp_triangle.str().c_str(); } - *(d->path) = ""; + d->path = ""; // if it is anything else the record is bogus, so ignore it break; } @@ -3325,13 +3453,13 @@ std::cout << "BEFORE DRAW" break; } //end of switch // When testing, uncomment the following to place a comment for each processed EMR record in the SVG -// *(d->outsvg) += dbg_str.str().c_str(); - *(d->outsvg) += tmp_outsvg.str().c_str(); - *(d->path) += tmp_path.str().c_str(); +// d->outsvg += dbg_str.str().c_str(); + d->outsvg += tmp_outsvg.str().c_str(); + d->path += tmp_path.str().c_str(); } //end of while // When testing, uncomment the following to show the final SVG derived from the EMF -// std::cout << *(d->outsvg) << std::endl; +// std::cout << d->outsvg << std::endl; (void) emr_properties(U_EMR_INVALID); // force the release of the lookup table memory, returned value is irrelevant return 1; @@ -3342,6 +3470,8 @@ void Emf::free_emf_strings(EMF_STRINGS name){ for(int i=0; i< name.count; i++){ free(name.strings[i]); } free(name.strings); } + name.count = 0; + name.size = 0; } SPDocument * @@ -3349,61 +3479,22 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) { EMF_CALLBACK_DATA d; -// memset(&d, 0, sizeof(d)); - memset(&d, 0, sizeof(EMF_CALLBACK_DATA)); - - for(int i = 0; i < EMF_MAX_DC+1; i++){ // be sure all values and pointers are empty to start with - memset(&(d.dc[i]),0,sizeof(EMF_DEVICE_CONTEXT)); - } - - d.dc[0].worldTransform.eM11 = 1.0; - d.dc[0].worldTransform.eM12 = 0.0; - d.dc[0].worldTransform.eM21 = 0.0; - d.dc[0].worldTransform.eM22 = 1.0; - d.dc[0].worldTransform.eDx = 0.0; - d.dc[0].worldTransform.eDy = 0.0; - d.dc[0].font_name = strdup("Arial"); // Default font, EMF spec says device can pick whatever it wants - d.dc[0].textColor = U_RGB(0, 0, 0); // default foreground color (black) - d.dc[0].bkColor = U_RGB(255, 255, 255); // default background color (white) - d.dc[0].bkMode = U_TRANSPARENT; - d.dc[0].dirty = 0; - if (uri == NULL) { return NULL; } - d.outsvg = new Glib::ustring(""); - d.path = new Glib::ustring(""); - d.outdef = new Glib::ustring(""); - d.defs = new Glib::ustring(""); - d.mask = 0; - d.drawtype = 0; - d.arcdir = U_AD_COUNTERCLOCKWISE; - d.dwRop2 = U_R2_COPYPEN; - d.dwRop3 = 0; - d.E2IdirY = 1.0; - d.D2PscaleX = 1.0; - d.D2PscaleY = 1.0; - d.hatches.size = 0; - d.hatches.count = 0; - d.hatches.strings = NULL; - d.images.size = 0; - d.images.count = 0; - d.images.strings = NULL; - d.gradients.size = 0; - d.gradients.count = 0; - d.gradients.strings = NULL; + d.dc[0].font_name = strdup("Arial"); // Default font, set only on lowest level, it copies up from there EMF spec says device can pick whatever it wants // set up the size default for patterns in defs. This might not be referenced if there are no patterns defined in the drawing. - *(d.defs) += "\n"; - *(d.defs) += " <pattern id=\"EMFhbasepattern\" \n"; - *(d.defs) += " patternUnits=\"userSpaceOnUse\"\n"; - *(d.defs) += " width=\"6\" \n"; - *(d.defs) += " height=\"6\" \n"; - *(d.defs) += " x=\"0\" \n"; - *(d.defs) += " y=\"0\"> \n"; - *(d.defs) += " </pattern> \n"; + d.defs += "\n"; + d.defs += " <pattern id=\"EMFhbasepattern\" \n"; + d.defs += " patternUnits=\"userSpaceOnUse\"\n"; + d.defs += " width=\"6\" \n"; + d.defs += " height=\"6\" \n"; + d.defs += " x=\"0\" \n"; + d.defs += " y=\"0\"> \n"; + d.defs += " </pattern> \n"; size_t length; @@ -3423,17 +3514,14 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) if (d.pDesc){ free( d.pDesc ); } -// std::cout << "SVG Output: " << std::endl << *(d.outsvg) << std::endl; +// std::cout << "SVG Output: " << std::endl << d.outsvg << std::endl; - SPDocument *doc = SPDocument::createNewDocFromMem(d.outsvg->c_str(), strlen(d.outsvg->c_str()), TRUE); + SPDocument *doc = SPDocument::createNewDocFromMem(d.outsvg.c_str(), strlen(d.outsvg.c_str()), TRUE); - delete d.outsvg; - delete d.path; - delete d.outdef; - delete d.defs; free_emf_strings(d.hatches); free_emf_strings(d.images); free_emf_strings(d.gradients); + free_emf_strings(d.clips); if (d.emf_obj) { int i; @@ -3444,45 +3532,13 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) d.dc[0].style.stroke_dasharray.values.clear(); - for(int i=0; i<=d.level;i++){ + for(int i=0; i<=EMF_MAX_DC; i++){ if(d.dc[i].font_name)free(d.dc[i].font_name); } d.tri = trinfo_release_except_FC(d.tri); - // Set viewBox if it doesn't exist - if (doc && !doc->getRoot()->viewBox_set) { - bool saved = Inkscape::DocumentUndo::getUndoSensitive(doc); - Inkscape::DocumentUndo::setUndoSensitive(doc, false); - - doc->ensureUpToDate(); - - // Set document unit - Inkscape::XML::Node *repr = sp_document_namedview(doc, 0)->getRepr(); - Inkscape::SVGOStringStream os; - Inkscape::Util::Unit const* doc_unit = doc->getWidth().unit; - os << doc_unit->abbr; - repr->setAttribute("inkscape:document-units", os.str().c_str()); - - // Set viewBox - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc_unit), doc->getHeight().value(doc_unit))); - doc->ensureUpToDate(); - - // Scale and translate objects - double scale = Inkscape::Util::Quantity::convert(1, "px", doc_unit); - ShapeEditor::blockSetItem(true); - double dh; - if(SP_ACTIVE_DOCUMENT){ // for file menu open or import, or paste from clipboard - dh = SP_ACTIVE_DOCUMENT->getHeight().value("px"); - } - else { // for open via --file on command line - dh = doc->getHeight().value("px"); - } - doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, dh)); - ShapeEditor::blockSetItem(false); - - Inkscape::DocumentUndo::setUndoSensitive(doc, saved); - } + setViewBoxIfMissing(doc); return doc; } diff --git a/src/extension/internal/emf-inout.h b/src/extension/internal/emf-inout.h index a97cb0a54..c64299093 100644 --- a/src/extension/internal/emf-inout.h +++ b/src/extension/internal/emf-inout.h @@ -27,21 +27,62 @@ namespace Internal { #define DIRTY_FILL 0x02 #define DIRTY_STROKE 0x04 -typedef struct { +typedef struct emf_object { + emf_object() : + type(0), + level(0), + lpEMFR(NULL) + {}; int type; int level; char *lpEMFR; } EMF_OBJECT, *PEMF_OBJECT; -typedef struct { +typedef struct emf_strings { + emf_strings() : + size(0), + count(0), + strings(NULL) + {}; int size; // number of slots allocated in strings int count; // number of slots used in strings char **strings; // place to store strings } EMF_STRINGS, *PEMF_STRINGS; typedef struct emf_device_context { - struct SPStyle style; + emf_device_context() : + // SPStyle: class with constructor + font_name(NULL), + clip_id(0), + stroke_set(false), stroke_mode(0), stroke_idx(0), stroke_recidx(0), + fill_set(false), fill_mode(0), fill_idx(0), fill_recidx(0), + dirty(0), + // sizeWnd, sizeView, winorg, vieworg, + ScaleInX(0), ScaleInY(0), + ScaleOutX(0), ScaleOutY(0), + bkMode(U_TRANSPARENT), + // bkColor, textColor + textAlign(0) + // worldTransform, cur + { + font_name = NULL; + sizeWnd = sizel_set( 0.0, 0.0 ); + sizeView = sizel_set( 0.0, 0.0 ); + winorg = point32_set( 0.0, 0.0 ); + vieworg = point32_set( 0.0, 0.0 ); + bkColor = U_RGB(255, 255, 255); // default foreground color (white) + textColor = U_RGB(0, 0, 0); // default foreground color (black) + worldTransform.eM11 = 1.0; + worldTransform.eM12 = 0.0; + worldTransform.eM21 = 0.0; + worldTransform.eM22 = 1.0; + worldTransform.eDx = 0.0; + worldTransform.eDy = 0.0; + cur = point32_set( 0, 0 ); + }; + SPStyle style; char *font_name; + int clip_id; // 0 if none, else 1 + index into clips bool stroke_set; int stroke_mode; // enumeration from drawmode, not used if fill_set is not True int stroke_idx; // used with DRAW_PATTERN and DRAW_IMAGE to return the appropriate fill @@ -67,11 +108,34 @@ typedef struct emf_device_context { #define EMF_MAX_DC 128 -typedef struct { - Glib::ustring *outsvg; - Glib::ustring *path; - Glib::ustring *outdef; - Glib::ustring *defs; +typedef struct emf_callback_data { + + emf_callback_data() : + // dc: array, structure w/ constructor + level(0), + E2IdirY(1.0), + D2PscaleX(1.0), D2PscaleY(1.0), + MM100InX(0), MM100InY(0), + PixelsInX(0), PixelsInY(0), + PixelsOutX(0), PixelsOutY(0), + ulCornerInX(0), ulCornerInY(0), + ulCornerOutX(0), ulCornerOutY(0), + mask(0), + arcdir(U_AD_COUNTERCLOCKWISE), + dwRop2(U_R2_COPYPEN), dwRop3(0), + MMX(0),MMY(0), + drawtype(0), + pDesc(NULL), + // hatches, images, gradients, struct w/ constructor + tri(NULL), + n_obj(0) + // emf_obj; + {}; + + Glib::ustring outsvg; + Glib::ustring path; + Glib::ustring outdef; + Glib::ustring defs; EMF_DEVICE_CONTEXT dc[EMF_MAX_DC+1]; // FIXME: This should be dynamic.. int level; @@ -92,13 +156,13 @@ typedef struct { float MMX; float MMY; - unsigned int id; unsigned int drawtype; // one of 0 or U_EMR_FILLPATH, U_EMR_STROKEPATH, U_EMR_STROKEANDFILLPATH char *pDesc; // both of these end up in <defs> under the names shown here. These structures allow duplicates to be avoided. EMF_STRINGS hatches; // hold pattern names, all like EMFhatch#_$$$$$$ where # is the EMF hatch code and $$$$$$ is the color EMF_STRINGS images; // hold images, all like Image#, where # is the slot the image lives. EMF_STRINGS gradients; // hold gradient names, all like EMF[HV]_$$$$$$_$$$$$$ where $$$$$$ are the colors + EMF_STRINGS clips; // hold clipping paths, referred to be the slot where the clipping path lives TR_INFO *tri; // Text Reassembly data structure @@ -137,18 +201,24 @@ protected: static int in_hatches(PEMF_CALLBACK_DATA d, char *test); static uint32_t add_hatch(PEMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hatchColor); static void enlarge_images(PEMF_CALLBACK_DATA d); - static int in_images(PEMF_CALLBACK_DATA d, char *test); + static int in_images(PEMF_CALLBACK_DATA d, const char *test); static uint32_t add_image(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t cbBits, uint32_t cbBmi, uint32_t iUsage, uint32_t offBits, uint32_t offBmi); static void enlarge_gradients(PEMF_CALLBACK_DATA d); - static int in_gradients(PEMF_CALLBACK_DATA d, char *test); + static int in_gradients(PEMF_CALLBACK_DATA d, const char *test); static uint32_t add_gradient(PEMF_CALLBACK_DATA d, uint32_t gradientType, U_TRIVERTEX tv1, U_TRIVERTEX tv2); + + static void enlarge_clips(PEMF_CALLBACK_DATA d); + static int in_clips(PEMF_CALLBACK_DATA d, const char *test); + static void add_clips(PEMF_CALLBACK_DATA d, const char *clippath, unsigned int logic); + static void output_style(PEMF_CALLBACK_DATA d, int iType); static double _pix_x_to_point(PEMF_CALLBACK_DATA d, double px); static double _pix_y_to_point(PEMF_CALLBACK_DATA d, double py); static double pix_to_x_point(PEMF_CALLBACK_DATA d, double px, double py); static double pix_to_y_point(PEMF_CALLBACK_DATA d, double px, double py); static double pix_to_abs_size(PEMF_CALLBACK_DATA d, double px); + static void snap_to_faraway_pair(double *x, double *y); static std::string pix_to_xy(PEMF_CALLBACK_DATA d, double x, double y); static void select_pen(PEMF_CALLBACK_DATA d, int index); static void select_extpen(PEMF_CALLBACK_DATA d, int index); diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index f4f7f08cb..0f43fbca1 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -34,6 +34,7 @@ #include <2geom/pathvector.h> #include <2geom/rect.h> #include <2geom/curves.h> +#include <sp-clippath.h> #include "helper/geom.h" #include "helper/geom-curves.h" @@ -54,6 +55,7 @@ #include "sp-radial-gradient.h" #include "sp-linear-gradient.h" #include "display/cairo-utils.h" +#include "sp-shape.h" #include "splivarot.h" // pieces for union on shapes #include "2geom/svg-path-parser.h" // to get from SVG text to Geom::Path @@ -142,6 +144,7 @@ unsigned int PrintEmf::begin(Inkscape::Extension::Print *mod, SPDocument *doc) // width and height in px _width = doc->getWidth().value("px"); _height = doc->getHeight().value("px"); + _doc_unit_scale = Inkscape::Util::Quantity::convert(1, (doc->getDefaultUnit()), "px"); // initialize a few global variables hbrush = hbrushOld = hpen = 0; @@ -297,6 +300,7 @@ unsigned int PrintEmf::begin(Inkscape::Extension::Print *mod, SPDocument *doc) unsigned int PrintEmf::finish(Inkscape::Extension::Print * /*mod*/) { + do_clip_if_present(NULL); // Terminate any open clip. char *rec; if (!et) { return 0; @@ -968,16 +972,145 @@ U_TRIVERTEX PrintEmf::make_trivertex(Geom::Point Pt, U_COLORREF uc){ return(tv); } +/* Examine clip. If there is a (new) one then apply it. If there is one and it is the + same as the preceding one, leave the preceding one active. If style is NULL + terminate the current clip, if any, and return. +*/ +void PrintEmf::do_clip_if_present(SPStyle const *style){ + char *rec; + static SPClipPath *scpActive = NULL; + if(!style){ + if(scpActive){ // clear the existing clip + rec = U_EMRRESTOREDC_set(-1); + if (!rec || emf_append((PU_ENHMETARECORD)rec, et, U_REC_FREE)) { + g_error("Fatal programming error in PrintEmf::fill at U_EMRRESTOREDC_set"); + } + scpActive=NULL; + } + } else { + /* The current implementation converts only one level of clipping. If there were more + clips further up the stack they should be combined with the pathvector using "and". Since this + comes up rarely, and would involve a lot of searching (all the way up the stack for every + draw operation), it has not yet been implemented. + + Note, to debug this section of code use print statements on sp_svg_write_path(combined_pathvector). + */ + /* find the first clip_ref at object or up the stack. There may not be one. */ + SPClipPath *scp = NULL; + SPItem *item = SP_ITEM(style->object); + while(1) { + scp = (item->clip_ref ? item->clip_ref->getObject() : NULL); + if(scp)break; + item = SP_ITEM(item->parent); + if(!item || SP_IS_ROOT(item))break; // this will never be a clipping path + } + + if(scp != scpActive){ // change or remove the clipping + if(scpActive){ // clear the existing clip + rec = U_EMRRESTOREDC_set(-1); + if (!rec || emf_append((PU_ENHMETARECORD)rec, et, U_REC_FREE)) { + g_error("Fatal programming error in PrintEmf::fill at U_EMRRESTOREDC_set"); + } + scpActive = NULL; + } + + if (scp) { // set the new clip + /* because of units and who knows what other transforms that might be applied above we + need the full transform all the way to the root. + */ + Geom::Affine tf = item->transform; + SPItem *scan_item = item; + while(1) { + scan_item = SP_ITEM(scan_item->parent); + if(!scan_item)break; + tf *= scan_item->transform; + } + tf *= Geom::Scale(_doc_unit_scale);; // Transform must be in PIXELS, no matter what the document unit is. + + /* find the clipping path */ + Geom::PathVector combined_pathvector; + Geom::Affine tfc; // clipping transform, generally not the same as item transform + for(item = SP_ITEM(scp->firstChild()); item; item=SP_ITEM(item->getNext())){ + if (SP_IS_GROUP(item)) { // not implemented + // return sp_group_render(item); + combined_pathvector = merge_PathVector_with_group(combined_pathvector, item, tfc); + } else if (SP_IS_SHAPE(item)) { + combined_pathvector = merge_PathVector_with_shape(combined_pathvector, item, tfc); + } else { // not implemented + } + } + + if (!combined_pathvector.empty()) { // if clipping path isn't empty, define EMF clipping record + scpActive = scp; // remember for next time + // the sole purpose of this SAVEDC is to let us clear the clipping region later. + rec = U_EMRSAVEDC_set(); + if (!rec || emf_append((PU_ENHMETARECORD)rec, et, U_REC_FREE)) { + g_error("Fatal programming error in PrintEmf::image at U_EMRSAVEDC_set"); + } + (void) draw_pathv_to_EMF(combined_pathvector, tf); + rec = U_EMRSELECTCLIPPATH_set(U_RGN_OR); + if (!rec || emf_append((PU_ENHMETARECORD)rec, et, U_REC_FREE)) { + g_error("Fatal programming error in PrintEmf::do_clip_if_present at U_EMRSELECTCLIPPATH_set"); + } + } + else { + scpActive = NULL; // no valid path available to draw, so no DC was saved, so no signal to restore + } + } // change or remove clipping + } // scp exists + } // style exists +} + +Geom::PathVector PrintEmf::merge_PathVector_with_group(Geom::PathVector const &combined_pathvector, SPItem const *item, const Geom::Affine &transform) +{ + Geom::PathVector new_combined_pathvector; + if(!SP_IS_GROUP(item))return(new_combined_pathvector); // sanity test, only a group should be passed in, return empty if something else happens + + new_combined_pathvector = combined_pathvector; + SPGroup *group = SP_GROUP(item); + Geom::Affine tfc = item->transform * transform; + for(SPItem *item = SP_ITEM(group->firstChild()); item; item=SP_ITEM(item->getNext())){ + if (SP_IS_GROUP(item)) { + new_combined_pathvector = merge_PathVector_with_group(new_combined_pathvector, item, tfc); // could be endlessly recursive on a badly formed SVG + } else if (SP_IS_SHAPE(item)) { + new_combined_pathvector = merge_PathVector_with_shape(new_combined_pathvector, item, tfc); + } else { // not implemented + } + } + return new_combined_pathvector; +} + +Geom::PathVector PrintEmf::merge_PathVector_with_shape(Geom::PathVector const &combined_pathvector, SPItem const *item, const Geom::Affine &transform) +{ + Geom::PathVector new_combined_pathvector; + if(!SP_IS_SHAPE(item))return(new_combined_pathvector); // sanity test, only a shape should be passed in, return empty if something else happens + + Geom::Affine tfc = item->transform * transform; + SPShape *shape = SP_SHAPE(item); + if (shape->_curve) { + Geom::PathVector const & new_vect = shape->_curve->get_pathvector(); + if(combined_pathvector.empty()){ + new_combined_pathvector = new_vect * tfc; + } + else { + new_combined_pathvector = sp_pathvector_boolop(new_vect * tfc, combined_pathvector, bool_op_union , (FillRule) fill_oddEven, (FillRule) fill_oddEven); + } + } + return new_combined_pathvector; +} + unsigned int PrintEmf::fill( Inkscape::Extension::Print * /*mod*/, Geom::PathVector const &pathv, Geom::Affine const & /*transform*/, SPStyle const *style, Geom::OptRect const &/*pbox*/, Geom::OptRect const &/*dbox*/, Geom::OptRect const &/*bbox*/) { + char *rec; using Geom::X; using Geom::Y; - Geom::Affine tf = m_tr_stack.top(); + do_clip_if_present(style); // If clipping is needed set it up + use_fill = true; use_stroke = false; @@ -1091,7 +1224,6 @@ unsigned int PrintEmf::fill( } } else if (gv.mode == DRAW_LINEAR_GRADIENT) { if(is_Rect){ - char *rec; int gMode; Geom::Point ul, ur, lr; Geom::Point outUL, outLR; // UL,LR corners of a stop rectangle, in OUTPUT coordinates @@ -1280,6 +1412,7 @@ unsigned int PrintEmf::stroke( char *rec = NULL; Geom::Affine tf = m_tr_stack.top(); + do_clip_if_present(style); // If clipping is needed set it up use_stroke = true; // use_fill was set in ::fill, if it is needed @@ -1564,12 +1697,14 @@ unsigned int PrintEmf::image( unsigned int h, /** height of bitmap */ unsigned int rs, /** row stride (normally w*4) */ Geom::Affine const &tf_rect, /** affine transform only used for defining location and size of rect, for all other tranforms, use the one from m_tr_stack */ - SPStyle const * /*style*/) /** provides indirect link to image object */ + SPStyle const *style) /** provides indirect link to image object */ { double x1, y1, dw, dh; char *rec = NULL; Geom::Affine tf = m_tr_stack.top(); + do_clip_if_present(style); // If clipping is needed set it up + rec = U_EMRSETSTRETCHBLTMODE_set(U_COLORONCOLOR); if (!rec || emf_append((PU_ENHMETARECORD)rec, et, U_REC_FREE)) { g_error("Fatal programming error in PrintEmf::image at EMRHEADER"); @@ -1654,28 +1789,14 @@ unsigned int PrintEmf::image( return 0; } -// may also be called with a simple_shape or an empty path, whereupon it just returns without doing anything -unsigned int PrintEmf::print_pathv(Geom::PathVector const &pathv, const Geom::Affine &transform) -{ - Geom::Affine tf = transform; - char *rec = NULL; - - simple_shape = print_simple_shape(pathv, tf); - if (simple_shape || pathv.empty()) { - if (use_fill) { - destroy_brush(); // these must be cleared even if nothing is drawn or hbrush,hpen fill up - } - if (use_stroke) { - destroy_pen(); - } - return TRUE; - } +unsigned int PrintEmf::draw_pathv_to_EMF(Geom::PathVector const &pathv, const Geom::Affine &transform) { + char *rec; /* inkscape to EMF scaling is done below, but NOT the rotation/translation transform, that is handled by the EMF MODIFYWORLDTRANSFORM record */ - - Geom::PathVector pv = pathv_to_linear_and_cubic_beziers(pathv * tf); + + Geom::PathVector pv = pathv_to_linear_and_cubic_beziers(pathv * transform); rec = U_EMRBEGINPATH_set(); if (!rec || emf_append((PU_ENHMETARECORD)rec, et, U_REC_FREE)) { @@ -1777,6 +1898,27 @@ unsigned int PrintEmf::print_pathv(Geom::PathVector const &pathv, const Geom::Af if (!rec || emf_append((PU_ENHMETARECORD)rec, et, U_REC_FREE)) { g_error("Fatal programming error in PrintEmf::print_pathv at U_EMRENDPATH_set"); } + return(0); +} + +// may also be called with a simple_shape or an empty path, whereupon it just returns without doing anything +unsigned int PrintEmf::print_pathv(Geom::PathVector const &pathv, const Geom::Affine &transform) +{ + Geom::Affine tf = transform; + char *rec = NULL; + + simple_shape = print_simple_shape(pathv, tf); + if (simple_shape || pathv.empty()) { + if (use_fill) { + destroy_brush(); // these must be cleared even if nothing is drawn or hbrush,hpen fill up + } + if (use_stroke) { + destroy_pen(); + } + return TRUE; + } + + (void) draw_pathv_to_EMF(pathv, tf); // explicit FILL/STROKE commands are needed for each sub section of the path if (use_fill && !use_stroke) { @@ -1815,6 +1957,7 @@ unsigned int PrintEmf::text(Inkscape::Extension::Print * /*mod*/, char const *te return 0; } + do_clip_if_present(style); // If clipping is needed set it up char *rec = NULL; int ccount, newfont; int fix90n = 0; @@ -1869,7 +2012,7 @@ unsigned int PrintEmf::text(Inkscape::Extension::Print * /*mod*/, char const *te _lookup_ppt_fontfix("Convert To Wingdings", params); break; default: //also CVTNON - _lookup_ppt_fontfix(style->text->font_family.value, params); + _lookup_ppt_fontfix(style->font_family.value, params); break; } if (params.f2 != 0 || params.f3 != 0) { @@ -1878,7 +2021,7 @@ unsigned int PrintEmf::text(Inkscape::Extension::Print * /*mod*/, char const *te fix90n = 1; //assume vertical rot = (double)(((int) round(rot)) - irem); rotb = rot * M_PI / 1800.0; - if (abs(rot) == 900.0) { + if (std::abs(rot) == 900.0) { fix90n = 2; } } @@ -1897,7 +2040,7 @@ unsigned int PrintEmf::text(Inkscape::Extension::Print * /*mod*/, char const *te // of the special fonts. uint16_t *wfacename; if (!newfont) { - wfacename = U_Utf8ToUtf16le(style->text->font_family.value, 0, NULL); + wfacename = U_Utf8ToUtf16le(style->font_family.value, 0, NULL); } else { wfacename = U_Utf8ToUtf16le(FontName(newfont), 0, NULL); } diff --git a/src/extension/internal/emf-print.h b/src/extension/internal/emf-print.h index 1e4970a46..5bad48de5 100644 --- a/src/extension/internal/emf-print.h +++ b/src/extension/internal/emf-print.h @@ -29,7 +29,7 @@ namespace Internal { class PrintEmf : public PrintMetafile { - uint32_t hbrush, hbrushOld, hpen, hpenOld; + uint32_t hbrush, hbrushOld, hpen; unsigned int print_pathv (Geom::PathVector const &pathv, const Geom::Affine &transform); bool print_simple_shape (Geom::PathVector const &pathv, const Geom::Affine &transform); @@ -69,6 +69,10 @@ public: protected: static void smuggle_adxkyrtl_out(const char *string, uint32_t **adx, double *ky, int *rtl, int *ndx, float scale); + void do_clip_if_present(SPStyle const *style); + Geom::PathVector merge_PathVector_with_group(Geom::PathVector const &combined_pathvector, SPItem const *item, const Geom::Affine &transform); + Geom::PathVector merge_PathVector_with_shape(Geom::PathVector const &combined_pathvector, SPItem const *item, const Geom::Affine &transform); + unsigned int draw_pathv_to_EMF(Geom::PathVector const &pathv, const Geom::Affine &transform); Geom::Path pathv_to_simple_polygon(Geom::PathVector const &pathv, int *vertices); Geom::Path pathv_to_rect(Geom::PathVector const &pathv, bool *is_rect, double *angle); Geom::Point get_pathrect_corner(Geom::Path pathRect, double angle, int corner); diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp index a384c7bde..28e44c461 100644 --- a/src/extension/internal/gdkpixbuf-input.cpp +++ b/src/extension/internal/gdkpixbuf-input.cpp @@ -1,21 +1,20 @@ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif +#include <gdk-pixbuf/gdk-pixbuf.h> + #include <boost/scoped_ptr.hpp> #include <glib/gprintf.h> #include <glibmm/i18n.h> +#include "dir-util.h" +#include "display/cairo-utils.h" #include "document-private.h" -#include <dir-util.h> +#include "document-undo.h" #include "extension/input.h" #include "extension/system.h" +#include "image-resolution.h" #include "gdkpixbuf-input.h" #include "preferences.h" #include "selection-chemistry.h" #include "sp-image.h" -#include "document-undo.h" #include "util/units.h" -#include "image-resolution.h" -#include "display/cairo-utils.h" #include <set> namespace Inkscape { @@ -87,11 +86,11 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri) ir = new ImageResolution(uri); } if (ir && ir->ok()) { - xscale = 900.0 / floor(10.*ir->x() + .5); // round-off to 0.1 dpi - yscale = 900.0 / floor(10.*ir->y() + .5); + xscale = 960.0 / floor(10.*ir->x() + .5); // round-off to 0.1 dpi + yscale = 960.0 / floor(10.*ir->y() + .5); } else { - xscale = 90.0 / defaultxdpi; - yscale = 90.0 / defaultxdpi; + xscale = 96.0 / defaultxdpi; + yscale = 96.0 / defaultxdpi; } width *= xscale; diff --git a/src/extension/internal/gdkpixbuf-input.h b/src/extension/internal/gdkpixbuf-input.h index 597e7246b..2e03a96db 100644 --- a/src/extension/internal/gdkpixbuf-input.h +++ b/src/extension/internal/gdkpixbuf-input.h @@ -10,7 +10,7 @@ namespace Internal { class GdkpixbufInput : Inkscape::Extension::Implementation::Implementation { public: SPDocument *open(Inkscape::Extension::Input *mod, - gchar const *uri); + char const *uri); static void init(); }; diff --git a/src/extension/internal/image-resolution.cpp b/src/extension/internal/image-resolution.cpp index 18eb97f80..e96fd6437 100644 --- a/src/extension/internal/image-resolution.cpp +++ b/src/extension/internal/image-resolution.cpp @@ -353,18 +353,20 @@ void ImageResolution::readmagick(char const *fn) { g_warning("ImageResolution::readmagick: Unknown error"); return; } - Magick::Geometry geo = image.density(); - std::string type = image.magick(); - - if (type == "PNG") { // PNG only supports pixelspercentimeter - x_ = Inkscape::Util::Quantity::convert((double)geo.width(), "in", "cm"); - y_ = Inkscape::Util::Quantity::convert((double)geo.height(), "in", "cm"); - } else { - x_ = (double)geo.width(); - y_ = (double)geo.height(); - } - ok_ = true; + std::string const type = image.magick(); + x_ = image.xResolution(); + y_ = image.yResolution(); + +// TODO: find out why the hell the following convertion is necessary + if (type == "BMP") { + x_ = Inkscape::Util::Quantity::convert(x_, "in", "cm"); + y_ = Inkscape::Util::Quantity::convert(y_, "in", "cm"); + } + + if (x_ != 0 && y_ != 0) { + ok_ = true; + } } #else diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index 398c9f061..ab0733848 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -66,7 +66,8 @@ latex_render_document_text_to_file( SPDocument *doc, gchar const *filename, bool pageBoundingBox = true; if (exportId && strcmp(exportId, "")) { // we want to export the given item only - base = SP_ITEM(doc->getObjectById(exportId)); + base = dynamic_cast<SPItem *>(doc->getObjectById(exportId)); + g_assert(base != NULL); pageBoundingBox = exportCanvas; } else { @@ -225,26 +226,22 @@ LaTeXTextRenderer::writePostamble() fprintf(_stream, "%s", postamble); } -void -LaTeXTextRenderer::sp_group_render(SPItem *item) +void LaTeXTextRenderer::sp_group_render(SPGroup *group) { - SPGroup *group = SP_GROUP(item); - GSList *l = g_slist_reverse(group->childList(false)); while (l) { - SPObject *o = SP_OBJECT (l->data); - if (SP_IS_ITEM(o)) { - renderItem (SP_ITEM (o)); + SPObject *o = reinterpret_cast<SPObject *>(l->data); + SPItem *item = dynamic_cast<SPItem *>(o); + if (item) { + renderItem(item); } l = g_slist_remove (l, o); } } -void -LaTeXTextRenderer::sp_use_render(SPItem *item) +void LaTeXTextRenderer::sp_use_render(SPUse *use) { bool translated = false; - SPUse *use = SP_USE(item); if ((use->x._set && use->x.computed != 0) || (use->y._set && use->y.computed != 0)) { Geom::Affine tp(Geom::Translate(use->x.computed, use->y.computed)); @@ -252,8 +249,9 @@ LaTeXTextRenderer::sp_use_render(SPItem *item) translated = true; } - if (use->child && SP_IS_ITEM(use->child)) { - renderItem(SP_ITEM(use->child)); + SPItem *childItem = dynamic_cast<SPItem *>(use->child); + if (childItem) { + renderItem(childItem); } if (translated) { @@ -261,16 +259,14 @@ LaTeXTextRenderer::sp_use_render(SPItem *item) } } -void -LaTeXTextRenderer::sp_text_render(SPItem *item) +void LaTeXTextRenderer::sp_text_render(SPText *textobj) { // Only PDFLaTeX supports importing a single page of a graphics file, // so only PDF backend gets interleaved text/graphics if (_pdflatex && _omittext_state == GRAPHIC_ON_TOP) _omittext_state = NEW_PAGE_ON_GRAPHIC; - SPText *textobj = SP_TEXT (item); - SPStyle *style = item->style; + SPStyle *style = textobj->style; // get position and alignment // Align vertically on the baseline of the font (retreived from the anchor point) @@ -312,7 +308,7 @@ LaTeXTextRenderer::sp_text_render(SPItem *item) } // get rotation - Geom::Affine i2doc = item->i2doc_affine(); + Geom::Affine i2doc = textobj->i2doc_affine(); Geom::Affine wotransl = i2doc.withoutTranslation(); double degrees = -180/M_PI * Geom::atan2(wotransl.xAxis()); bool has_rotation = !Geom::are_near(degrees,0.); @@ -336,11 +332,11 @@ LaTeXTextRenderer::sp_text_render(SPItem *item) // Walk through all spans in the text object. // Write span strings to LaTeX, associated with font weight and style. - Inkscape::Text::Layout const &layout = *(te_get_layout (item)); + Inkscape::Text::Layout const &layout = *(te_get_layout (textobj)); for (Inkscape::Text::Layout::iterator li = layout.begin(), le = layout.end(); li != le; li.nextStartOfSpan()) { - SPStyle const &spanstyle = *(sp_te_style_at_position (item, li)); + SPStyle const &spanstyle = *(sp_te_style_at_position (textobj, li)); bool is_bold = false, is_italic = false, is_oblique = false; if (spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_500 || @@ -367,7 +363,7 @@ LaTeXTextRenderer::sp_text_render(SPItem *item) Inkscape::Text::Layout::iterator ln = li; ln.nextStartOfSpan(); - Glib::ustring uspanstr = sp_te_get_string_multiline (item, li, ln); + Glib::ustring uspanstr = sp_te_get_string_multiline (textobj, li, ln); const gchar *spanstr = uspanstr.c_str(); if (!spanstr) { continue; @@ -394,8 +390,7 @@ LaTeXTextRenderer::sp_text_render(SPItem *item) fprintf(_stream, "%s", os.str().c_str()); } -void -LaTeXTextRenderer::sp_flowtext_render(SPItem * item) +void LaTeXTextRenderer::sp_flowtext_render(SPFlowtext *flowtext) { /* Flowtext is possible by using a minipage! :) @@ -407,16 +402,15 @@ Flowing in rectangle is possible, not in arb shape. if (_pdflatex && _omittext_state == GRAPHIC_ON_TOP) _omittext_state = NEW_PAGE_ON_GRAPHIC; - SPFlowtext *flowtext = SP_FLOWTEXT(item); - SPStyle *style = item->style; + SPStyle *style = flowtext->style; SPItem *frame_item = flowtext->get_frame(NULL); - if (!frame_item || !SP_IS_RECT(frame_item)) { + SPRect *frame = dynamic_cast<SPRect *>(frame_item); + if (!frame_item || !frame) { g_warning("LaTeX export: non-rectangular flowed text shapes are not supported, skipping text."); return; // don't know how to handle non-rect frames yet. is quite uncommon for latex users i think } - SPRect *frame = SP_RECT(frame_item); Geom::Rect framebox = frame->getRect() * transform(); // get position and alignment @@ -460,7 +454,7 @@ Flowing in rectangle is possible, not in arb shape. } // get rotation - Geom::Affine i2doc = item->i2doc_affine(); + Geom::Affine i2doc = flowtext->i2doc_affine(); Geom::Affine wotransl = i2doc.withoutTranslation(); double degrees = -180/M_PI * Geom::atan2(wotransl.xAxis()); bool has_rotation = !Geom::are_near(degrees,0.); @@ -485,11 +479,11 @@ Flowing in rectangle is possible, not in arb shape. // Walk through all spans in the text object. // Write span strings to LaTeX, associated with font weight and style. - Inkscape::Text::Layout const &layout = *(te_get_layout (item)); + Inkscape::Text::Layout const &layout = *(te_get_layout(flowtext)); for (Inkscape::Text::Layout::iterator li = layout.begin(), le = layout.end(); li != le; li.nextStartOfSpan()) { - SPStyle const &spanstyle = *(sp_te_style_at_position (item, li)); + SPStyle const &spanstyle = *(sp_te_style_at_position(flowtext, li)); bool is_bold = false, is_italic = false, is_oblique = false; if (spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_500 || @@ -516,7 +510,7 @@ Flowing in rectangle is possible, not in arb shape. Inkscape::Text::Layout::iterator ln = li; ln.nextStartOfSpan(); - Glib::ustring uspanstr = sp_te_get_string_multiline (item, li, ln); + Glib::ustring uspanstr = sp_te_get_string_multiline(flowtext, li, ln); const gchar *spanstr = uspanstr.c_str(); if (!spanstr) { continue; @@ -558,22 +552,36 @@ LaTeXTextRenderer::sp_item_invoke_render(SPItem *item) return; } - if (SP_IS_ROOT(item)) { - return sp_root_render(SP_ROOT(item)); - } else if (SP_IS_GROUP(item)) { - return sp_group_render(item); - } else if (SP_IS_USE(item)) { - sp_use_render(item); - } else if (SP_IS_TEXT(item)) { - return sp_text_render(item); - } else if (SP_IS_FLOWTEXT(item)) { - return sp_flowtext_render(item); + SPRoot *root = dynamic_cast<SPRoot *>(item); + if (root) { + sp_root_render(root); } else { - // Only PDFLaTeX supports importing a single page of a graphics file, - // so only PDF backend gets interleaved text/graphics - if (_pdflatex && (_omittext_state == EMPTY || _omittext_state == NEW_PAGE_ON_GRAPHIC)) - writeGraphicPage(); - _omittext_state = GRAPHIC_ON_TOP; + SPGroup *group = dynamic_cast<SPGroup *>(item); + if (group) { + sp_group_render(group); + } else { + SPUse *use = dynamic_cast<SPUse *>(item); + if (use) { + sp_use_render(use); + } else { + SPText *text = dynamic_cast<SPText *>(item); + if (text) { + sp_text_render(text); + } else { + SPFlowtext *flowtext = dynamic_cast<SPFlowtext *>(item); + if (flowtext) { + sp_flowtext_render(flowtext); + } else { + // Only PDFLaTeX supports importing a single page of a graphics file, + // so only PDF backend gets interleaved text/graphics + if (_pdflatex && (_omittext_state == EMPTY || _omittext_state == NEW_PAGE_ON_GRAPHIC)) { + writeGraphicPage(); + } + _omittext_state = GRAPHIC_ON_TOP; + } + } + } + } } } diff --git a/src/extension/internal/latex-text-renderer.h b/src/extension/internal/latex-text-renderer.h index 77d12bc61..b9563b53b 100644 --- a/src/extension/internal/latex-text-renderer.h +++ b/src/extension/internal/latex-text-renderer.h @@ -23,6 +23,10 @@ class SPItem; class SPRoot; +class SPGroup; +class SPUse; +class SPText; +class SPFlowtext; namespace Inkscape { namespace Extension { @@ -73,10 +77,10 @@ protected: void sp_item_invoke_render(SPItem *item); void sp_root_render(SPRoot *item); - void sp_group_render(SPItem *item); - void sp_use_render(SPItem *item); - void sp_text_render(SPItem *item); - void sp_flowtext_render(SPItem *item); + void sp_group_render(SPGroup *group); + void sp_use_render(SPUse *use); + void sp_text_render(SPText *text); + void sp_flowtext_render(SPFlowtext *flowtext); }; } /* namespace Internal */ diff --git a/src/extension/internal/metafile-inout.cpp b/src/extension/internal/metafile-inout.cpp index 1d419a6a0..824934b3e 100644 --- a/src/extension/internal/metafile-inout.cpp +++ b/src/extension/internal/metafile-inout.cpp @@ -17,6 +17,7 @@ #include <glib.h> #include <glibmm/miscutils.h> +#include "sp-root.h" #include "display/curve.h" #include "extension/internal/metafile-inout.h" // picks up PNG #include "extension/print.h" @@ -27,6 +28,13 @@ #include "sp-pattern.h" #include "sp-radial-gradient.h" #include "style.h" +#include "document.h" +#include "util/units.h" +#include "ui/shape-editor.h" +#include "sp-namedview.h" +#include "document-undo.h" +#include "inkscape.h" +#include "preferences.h" namespace Inkscape { namespace Extension { @@ -171,6 +179,88 @@ void Metafile::toPNG(PMEMPNG accum, int width, int height, const char *px){ } +/* If the viewBox is missing, set one +*/ +void Metafile::setViewBoxIfMissing(SPDocument *doc) { + + if (doc && !doc->getRoot()->viewBox_set) { + bool saved = Inkscape::DocumentUndo::getUndoSensitive(doc); + Inkscape::DocumentUndo::setUndoSensitive(doc, false); + + doc->ensureUpToDate(); + + // Set document unit + Inkscape::XML::Node *repr = sp_document_namedview(doc, 0)->getRepr(); + Inkscape::SVGOStringStream os; + Inkscape::Util::Unit const* doc_unit = doc->getWidth().unit; + os << doc_unit->abbr; + repr->setAttribute("inkscape:document-units", os.str().c_str()); + + // Set viewBox + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc_unit), doc->getHeight().value(doc_unit))); + doc->ensureUpToDate(); + + // Scale and translate objects + double scale = Inkscape::Util::Quantity::convert(1, "px", doc_unit); + Inkscape::UI::ShapeEditor::blockSetItem(true); + double dh; + if(SP_ACTIVE_DOCUMENT){ // for file menu open or import, or paste from clipboard + dh = SP_ACTIVE_DOCUMENT->getHeight().value("px"); + } + else { // for open via --file on command line + dh = doc->getHeight().value("px"); + } + + // These should not affect input, but they do, so set them to a neutral state + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool transform_stroke = prefs->getBool("/options/transform/stroke", true); + bool transform_rectcorners = prefs->getBool("/options/transform/rectcorners", true); + bool transform_pattern = prefs->getBool("/options/transform/pattern", true); + bool transform_gradient = prefs->getBool("/options/transform/gradient", true); + prefs->setBool("/options/transform/stroke", true); + prefs->setBool("/options/transform/rectcorners", true); + prefs->setBool("/options/transform/pattern", true); + prefs->setBool("/options/transform/gradient", true); + + doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, dh), true); + Inkscape::UI::ShapeEditor::blockSetItem(false); + + // restore options + prefs->setBool("/options/transform/stroke", transform_stroke); + prefs->setBool("/options/transform/rectcorners", transform_rectcorners); + prefs->setBool("/options/transform/pattern", transform_pattern); + prefs->setBool("/options/transform/gradient", transform_gradient); + + Inkscape::DocumentUndo::setUndoSensitive(doc, saved); + } +} + +/** + \fn Convert EMF/WMF region combining ops to livarot region combining ops + \return combination operators in livarot enumeration, or -1 on no match + \param ops (int) combination operator (Inkscape) +*/ +int Metafile::combine_ops_to_livarot(const int op) +{ + int ret = -1; + switch(op) { + case U_RGN_AND: + ret = bool_op_inters; + break; + case U_RGN_OR: + ret = bool_op_union; + break; + case U_RGN_XOR: + ret = bool_op_symdiff; + break; + case U_RGN_DIFF: + ret = bool_op_diff; + break; + } + return(ret); +} + + /* convert an EMF RGB(A) color to 0RGB inverse of gethexcolor() in emf-print.cpp diff --git a/src/extension/internal/metafile-inout.h b/src/extension/internal/metafile-inout.h index 968773a3a..b3efee2a6 100644 --- a/src/extension/internal/metafile-inout.h +++ b/src/extension/internal/metafile-inout.h @@ -71,6 +71,8 @@ protected: static void my_png_write_data(png_structp png_ptr, png_bytep data, png_size_t length); static void toPNG(PMEMPNG accum, int width, int height, const char *px); static gchar *bad_image_png(void); + static void setViewBoxIfMissing(SPDocument *doc); + static int combine_ops_to_livarot(const int op); private: diff --git a/src/extension/internal/metafile-print.h b/src/extension/internal/metafile-print.h index a21f9de58..d184b72b7 100644 --- a/src/extension/internal/metafile-print.h +++ b/src/extension/internal/metafile-print.h @@ -69,6 +69,8 @@ protected: double _width; double _height; + double _doc_unit_scale; // to pixels, regardless of the document units + U_RECTL rc; uint32_t htextalignment; diff --git a/src/extension/internal/pdf-input-cairo.cpp b/src/extension/internal/pdf-input-cairo.cpp deleted file mode 100644 index c45367c08..000000000 --- a/src/extension/internal/pdf-input-cairo.cpp +++ /dev/null @@ -1,680 +0,0 @@ - /* - * Simple PDF import extension using libpoppler and Cairo's SVG surface. - * - * Authors: - * miklos erdelyi - * Abhishek Sharma - * - * Copyright (C) 2007 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - * - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#ifdef HAVE_POPPLER_GLIB -#ifdef HAVE_POPPLER_CAIRO - -#include "pdf-input-cairo.h" -#include "extension/system.h" -#include "extension/input.h" -#include "dialogs/dialog-events.h" -#include "document.h" -#include "sp-root.h" -#include "util/units.h" - -#include <2geom/rect.h> - -#include "inkscape.h" - -#include <cairo-svg.h> -#include <poppler/glib/poppler.h> -#include <poppler/glib/poppler-document.h> -#include <poppler/glib/poppler-page.h> - -#include "ui/widget/spinbutton.h" -#include "ui/widget/frame.h" - -#include <gdkmm/general.h> - -namespace Inkscape { -namespace Extension { -namespace Internal { - - -/** - * \brief The PDF import dialog - * FIXME: Probably this should be placed into src/ui/dialog - */ - -static const gchar * crop_setting_choices[] = { - //TRANSLATORS: The following are document crop settings for PDF import - // more info: http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/page_bounds/ - N_("media box"), - N_("crop box"), - N_("trim box"), - N_("bleed box"), - N_("art box") -}; - -PdfImportCairoDialog::PdfImportCairoDialog(PopplerDocument *doc) -{ - if(doc == NULL) { - // if there is no document, throw exception here - throw; - } - - _poppler_doc = doc; - - cancelbutton = Gtk::manage(new class Gtk::Button(Gtk::StockID("gtk-cancel"))); - okbutton = Gtk::manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))); - _labelSelect = Gtk::manage(new class Gtk::Label(_("Select page:"))); - - // Page number - int num_pages = poppler_document_get_n_pages(_poppler_doc); -#if WITH_GTKMM_3_0 - Glib::RefPtr<Gtk::Adjustment> _pageNumberSpin_adj( Gtk::Adjustment::create(1, 1, num_pages, 1, 10, 0) ); - _pageNumberSpin = Gtk::manage(new class Inkscape::UI::Widget::SpinButton(_pageNumberSpin_adj, 1, 1)); -#else - Gtk::Adjustment *_pageNumberSpin_adj = Gtk::manage(new class Gtk::Adjustment(1, 1, num_pages, 1, 10, 0)); - _pageNumberSpin = Gtk::manage(new class Inkscape::UI::Widget::SpinButton(*_pageNumberSpin_adj, 1, 1)); -#endif - _labelTotalPages = Gtk::manage(new class Gtk::Label()); - hbox2 = Gtk::manage(new class Gtk::HBox(false, 0)); - // Disable the page selector when there's only one page - if ( num_pages == 1 ) { - _pageNumberSpin->set_sensitive(false); - } else { - // Display total number of pages - gchar *label_text = g_strdup_printf(_("out of %i"), num_pages); - _labelTotalPages->set_label(label_text); - g_free(label_text); - } - - // Crop settings - _cropCheck = Gtk::manage(new class Gtk::CheckButton(_("Clip to:"))); - _cropTypeCombo = Gtk::manage(new class Gtk::ComboBoxText()); - int num_crop_choices = sizeof(crop_setting_choices) / sizeof(crop_setting_choices[0]); - for ( int i = 0 ; i < num_crop_choices ; i++ ) { - _cropTypeCombo->append(_(crop_setting_choices[i])); - } - _cropTypeCombo->set_active_text(_(crop_setting_choices[0])); - _cropTypeCombo->set_sensitive(false); - - hbox3 = Gtk::manage(new class Gtk::HBox(false, 4)); - vbox2 = Gtk::manage(new class Gtk::VBox(false, 4)); - _pageSettingsFrame = Gtk::manage(new class Inkscape::UI::Widget::Frame(_("Page settings"))); - _labelPrecision = Gtk::manage(new class Gtk::Label(_("Precision of approximating gradient meshes:"))); - _labelPrecisionWarning = Gtk::manage(new class Gtk::Label(_("<b>Note</b>: setting the precision too high may result in a large SVG file and slow performance."))); - -#if WITH_GTKMM_3_0 - _fallbackPrecisionSlider_adj = Gtk::Adjustment::create(2, 1, 256, 1, 10, 10); - _fallbackPrecisionSlider = Gtk::manage(new Gtk::Scale(_fallbackPrecisionSlider_adj)); -#else - _fallbackPrecisionSlider_adj = Gtk::manage(new class Gtk::Adjustment(2, 1, 256, 1, 10, 10)); - _fallbackPrecisionSlider = Gtk::manage(new class Gtk::HScale(*_fallbackPrecisionSlider_adj)); -#endif - _fallbackPrecisionSlider->set_value(2.0); - _labelPrecisionComment = Gtk::manage(new class Gtk::Label(_("rough"))); - hbox6 = Gtk::manage(new class Gtk::HBox(false, 4)); - - // Text options - _labelText = Gtk::manage(new class Gtk::Label(_("Text handling:"))); - _textHandlingCombo = Gtk::manage(new class Gtk::ComboBoxText()); - _textHandlingCombo->append(_("Import text as text")); - _textHandlingCombo->set_active_text(_("Import text as text")); - _localFontsCheck = Gtk::manage(new class Gtk::CheckButton(_("Replace PDF fonts by closest-named installed fonts"))); - - hbox5 = Gtk::manage(new class Gtk::HBox(false, 4)); - _embedImagesCheck = Gtk::manage(new class Gtk::CheckButton(_("Embed images"))); - vbox3 = Gtk::manage(new class Gtk::VBox(false, 4)); - _importSettingsFrame = Gtk::manage(new class Inkscape::UI::Widget::Frame(_("Import settings"))); - vbox1 = Gtk::manage(new class Gtk::VBox(false, 4)); - _previewArea = Gtk::manage(new class Gtk::DrawingArea()); - hbox1 = Gtk::manage(new class Gtk::HBox(false, 4)); - cancelbutton->set_can_focus(); - cancelbutton->set_can_default(); - cancelbutton->set_relief(Gtk::RELIEF_NORMAL); - okbutton->set_can_focus(); - okbutton->set_can_default(); - okbutton->set_relief(Gtk::RELIEF_NORMAL); - this->get_action_area()->property_layout_style().set_value(Gtk::BUTTONBOX_END); - _labelSelect->set_alignment(0.5,0.5); - _labelSelect->set_padding(4,0); - _labelSelect->set_justify(Gtk::JUSTIFY_LEFT); - _labelSelect->set_line_wrap(false); - _labelSelect->set_use_markup(false); - _labelSelect->set_selectable(false); - _pageNumberSpin->set_can_focus(); - _pageNumberSpin->set_update_policy(Gtk::UPDATE_ALWAYS); - _pageNumberSpin->set_numeric(true); - _pageNumberSpin->set_digits(0); - _pageNumberSpin->set_wrap(false); - _labelTotalPages->set_alignment(0.5,0.5); - _labelTotalPages->set_padding(4,0); - _labelTotalPages->set_justify(Gtk::JUSTIFY_LEFT); - _labelTotalPages->set_line_wrap(false); - _labelTotalPages->set_use_markup(false); - _labelTotalPages->set_selectable(false); - hbox2->pack_start(*_labelSelect, Gtk::PACK_SHRINK, 4); - hbox2->pack_start(*_pageNumberSpin, Gtk::PACK_SHRINK, 4); - hbox2->pack_start(*_labelTotalPages, Gtk::PACK_SHRINK, 4); - _cropCheck->set_can_focus(); - _cropCheck->set_relief(Gtk::RELIEF_NORMAL); - _cropCheck->set_mode(true); - _cropCheck->set_active(false); - _cropTypeCombo->set_border_width(1); - hbox3->pack_start(*_cropCheck, Gtk::PACK_SHRINK, 4); - hbox3->pack_start(*_cropTypeCombo, Gtk::PACK_SHRINK, 0); - vbox2->pack_start(*hbox2); - vbox2->pack_start(*hbox3); - _pageSettingsFrame->add(*vbox2); - _pageSettingsFrame->set_border_width(4); - _labelPrecision->set_alignment(0,0.5); - _labelPrecision->set_padding(4,0); - _labelPrecision->set_justify(Gtk::JUSTIFY_LEFT); - _labelPrecision->set_line_wrap(true); - _labelPrecision->set_use_markup(false); - _labelPrecision->set_selectable(false); - _labelPrecisionWarning->set_alignment(0,0.5); - _labelPrecisionWarning->set_padding(4,0); - _labelPrecisionWarning->set_justify(Gtk::JUSTIFY_LEFT); - _labelPrecisionWarning->set_line_wrap(true); - _labelPrecisionWarning->set_use_markup(true); - _labelPrecisionWarning->set_selectable(false); - _fallbackPrecisionSlider->set_size_request(180,-1); - _fallbackPrecisionSlider->set_can_focus(); - _fallbackPrecisionSlider->set_inverted(false); - _fallbackPrecisionSlider->set_digits(1); - _fallbackPrecisionSlider->set_draw_value(true); - _fallbackPrecisionSlider->set_value_pos(Gtk::POS_TOP); - _labelPrecisionComment->set_size_request(90,-1); - _labelPrecisionComment->set_alignment(0.5,0.5); - _labelPrecisionComment->set_padding(4,0); - _labelPrecisionComment->set_justify(Gtk::JUSTIFY_LEFT); - _labelPrecisionComment->set_line_wrap(false); - _labelPrecisionComment->set_use_markup(false); - _labelPrecisionComment->set_selectable(false); - hbox6->pack_start(*_fallbackPrecisionSlider, Gtk::PACK_SHRINK, 4); - hbox6->pack_start(*_labelPrecisionComment, Gtk::PACK_SHRINK, 0); - _labelText->set_alignment(0.5,0.5); - _labelText->set_padding(4,0); - _labelText->set_justify(Gtk::JUSTIFY_LEFT); - _labelText->set_line_wrap(false); - _labelText->set_use_markup(false); - _labelText->set_selectable(false); - hbox5->pack_start(*_labelText, Gtk::PACK_SHRINK, 0); - hbox5->pack_start(*_textHandlingCombo, Gtk::PACK_SHRINK, 0); - _localFontsCheck->set_can_focus(); - _localFontsCheck->set_relief(Gtk::RELIEF_NORMAL); - _localFontsCheck->set_mode(true); - _localFontsCheck->set_active(true); - _embedImagesCheck->set_can_focus(); - _embedImagesCheck->set_relief(Gtk::RELIEF_NORMAL); - _embedImagesCheck->set_mode(true); - _embedImagesCheck->set_active(true); - vbox3->pack_start(*_labelPrecision, Gtk::PACK_SHRINK, 0); - vbox3->pack_start(*hbox6, Gtk::PACK_SHRINK, 0); - vbox3->pack_start(*_labelPrecisionWarning, Gtk::PACK_SHRINK, 0); - vbox3->pack_start(*hbox5, Gtk::PACK_SHRINK, 4); - vbox3->pack_start(*_localFontsCheck, Gtk::PACK_SHRINK, 0); - vbox3->pack_start(*_embedImagesCheck, Gtk::PACK_SHRINK, 0); - _importSettingsFrame->add(*vbox3); - _importSettingsFrame->set_border_width(4); - vbox1->pack_start(*_pageSettingsFrame, Gtk::PACK_EXPAND_PADDING, 0); - vbox1->pack_start(*_importSettingsFrame, Gtk::PACK_EXPAND_PADDING, 0); - hbox1->pack_start(*vbox1); - hbox1->pack_start(*_previewArea, Gtk::PACK_EXPAND_WIDGET, 4); - -#if WITH_GTKMM_3_0 - get_content_area()->set_homogeneous(false); - get_content_area()->set_spacing(0); - get_content_area()->pack_start(*hbox1); -#else - this->get_vbox()->set_homogeneous(false); - this->get_vbox()->set_spacing(0); - this->get_vbox()->pack_start(*hbox1); -#endif - - this->set_title(_("PDF Import Settings")); - this->set_modal(true); - sp_transientize(GTK_WIDGET(this->gobj())); //Make transient - this->property_window_position().set_value(Gtk::WIN_POS_NONE); - this->set_resizable(true); - this->property_destroy_with_parent().set_value(false); - this->add_action_widget(*cancelbutton, -6); - this->add_action_widget(*okbutton, -5); - cancelbutton->show(); - okbutton->show(); - _labelSelect->show(); - _pageNumberSpin->show(); - _labelTotalPages->show(); - hbox2->show(); - _cropCheck->show(); - _cropTypeCombo->show(); - hbox3->show(); - vbox2->show(); - _pageSettingsFrame->show(); - _labelPrecision->show(); - _labelPrecisionWarning->show(); - _fallbackPrecisionSlider->show(); - _labelPrecisionComment->show(); - hbox6->show(); - _labelText->show(); - _textHandlingCombo->show(); - hbox5->show(); - _localFontsCheck->show(); - _embedImagesCheck->show(); - vbox3->show(); - _importSettingsFrame->show(); - vbox1->show(); - _previewArea->show(); - hbox1->show(); - - // Connect signals -#if WITH_GTKMM_3_0 - _previewArea->signal_draw().connect(sigc::mem_fun(*this, &PdfImportCairoDialog::_onDraw)); -#else - _previewArea->signal_expose_event().connect(sigc::mem_fun(*this, &PdfImportCairoDialog::_onExposePreview)); -#endif - _pageNumberSpin_adj->signal_value_changed().connect(sigc::mem_fun(*this, &PdfImportCairoDialog::_onPageNumberChanged)); - _cropCheck->signal_toggled().connect(sigc::mem_fun(*this, &PdfImportCairoDialog::_onToggleCropping)); - _fallbackPrecisionSlider_adj->signal_value_changed().connect(sigc::mem_fun(*this, &PdfImportCairoDialog::_onPrecisionChanged)); - - _render_thumb = false; - _cairo_surface = NULL; - _render_thumb = true; - - // Set default preview size - _preview_width = 200; - _preview_height = 300; - - // Init preview - _thumb_data = NULL; - _pageNumberSpin_adj->set_value(1.0); - _current_page = 1; - _setPreviewPage(_current_page); - - set_default (*okbutton); - set_focus (*okbutton); -} - -PdfImportCairoDialog::~PdfImportCairoDialog() { - if (_cairo_surface) { - cairo_surface_destroy(_cairo_surface); - } - if (_thumb_data) { - if (_render_thumb) { - delete _thumb_data; - } else { - // -->gfree(_thumb_data); - delete _thumb_data; - } - } -} - -bool PdfImportCairoDialog::showDialog() { - show(); - gint b = run(); - hide(); - if ( b == Gtk::RESPONSE_OK ) { - return TRUE; - } else { - return FALSE; - } -} - -int PdfImportCairoDialog::getSelectedPage() { - return _current_page; -} - -/** - * \brief Retrieves the current settings into a repr which SvgBuilder will use - * for determining the behaviour desired by the user - */ -void PdfImportCairoDialog::getImportSettings(Inkscape::XML::Node *prefs) { - sp_repr_set_svg_double(prefs, "selectedPage", (double)_current_page); - if (_cropCheck->get_active()) { - Glib::ustring current_choice = _cropTypeCombo->get_active_text(); - int num_crop_choices = sizeof(crop_setting_choices) / sizeof(crop_setting_choices[0]); - int i = 0; - for ( ; i < num_crop_choices ; i++ ) { - if ( current_choice == _(crop_setting_choices[i]) ) { - break; - } - } - sp_repr_set_svg_double(prefs, "cropTo", (double)i); - } else { - sp_repr_set_svg_double(prefs, "cropTo", -1.0); - } - sp_repr_set_svg_double(prefs, "approximationPrecision", - _fallbackPrecisionSlider->get_value()); - if (_localFontsCheck->get_active()) { - prefs->setAttribute("localFonts", "1"); - } else { - prefs->setAttribute("localFonts", "0"); - } - if (_embedImagesCheck->get_active()) { - prefs->setAttribute("embedImages", "1"); - } else { - prefs->setAttribute("embedImages", "0"); - } -} - -/** - * \brief Redisplay the comment on the current approximation precision setting - * Evenly divides the interval of possible values between the available labels. - */ -void PdfImportCairoDialog::_onPrecisionChanged() { - - static Glib::ustring precision_comments[] = { - Glib::ustring(C_("PDF input precision", "rough")), - Glib::ustring(C_("PDF input precision", "medium")), - Glib::ustring(C_("PDF input precision", "fine")), - Glib::ustring(C_("PDF input precision", "very fine")) - }; - - double min = _fallbackPrecisionSlider_adj->get_lower(); - double max = _fallbackPrecisionSlider_adj->get_upper(); - int num_intervals = sizeof(precision_comments) / sizeof(precision_comments[0]); - double interval_len = ( max - min ) / (double)num_intervals; - double value = _fallbackPrecisionSlider_adj->get_value(); - int comment_idx = (int)floor( ( value - min ) / interval_len ); - _labelPrecisionComment->set_label(precision_comments[comment_idx]); -} - -void PdfImportCairoDialog::_onToggleCropping() { - _cropTypeCombo->set_sensitive(_cropCheck->get_active()); -} - -void PdfImportCairoDialog::_onPageNumberChanged() { - int page = _pageNumberSpin->get_value_as_int(); - _current_page = CLAMP(page, 1, poppler_document_get_n_pages(_poppler_doc)); - _setPreviewPage(_current_page); -} - -/** - * \brief Copies image data from a Cairo surface to a pixbuf - * - * Borrowed from libpoppler, from the file poppler-page.cc - * Copyright (C) 2005, Red Hat, Inc. - * - */ -static void copy_cairo_surface_to_pixbuf (cairo_surface_t *surface, - unsigned char *data, - GdkPixbuf *pixbuf) -{ - int cairo_width, cairo_height, cairo_rowstride; - unsigned char *pixbuf_data, *dst, *cairo_data; - int pixbuf_rowstride, pixbuf_n_channels; - unsigned int *src; - int x, y; - - cairo_width = cairo_image_surface_get_width (surface); - cairo_height = cairo_image_surface_get_height (surface); - cairo_rowstride = cairo_width * 4; - cairo_data = data; - - pixbuf_data = gdk_pixbuf_get_pixels (pixbuf); - pixbuf_rowstride = gdk_pixbuf_get_rowstride (pixbuf); - pixbuf_n_channels = gdk_pixbuf_get_n_channels (pixbuf); - - if (cairo_width > gdk_pixbuf_get_width (pixbuf)) - cairo_width = gdk_pixbuf_get_width (pixbuf); - if (cairo_height > gdk_pixbuf_get_height (pixbuf)) - cairo_height = gdk_pixbuf_get_height (pixbuf); - for (y = 0; y < cairo_height; y++) - { - src = reinterpret_cast<unsigned int *>(cairo_data + y * cairo_rowstride); - dst = pixbuf_data + y * pixbuf_rowstride; - for (x = 0; x < cairo_width; x++) - { - dst[0] = (*src >> 16) & 0xff; - dst[1] = (*src >> 8) & 0xff; - dst[2] = (*src >> 0) & 0xff; - if (pixbuf_n_channels == 4) - dst[3] = (*src >> 24) & 0xff; - dst += pixbuf_n_channels; - src++; - } - } -} - -/** - * \brief Updates the preview area with the previously rendered thumbnail - */ -#if !WITH_GTKMM_3_0 -bool PdfImportCairoDialog::_onExposePreview(GdkEventExpose * /*event*/) { - Cairo::RefPtr<Cairo::Context> cr = _previewArea->get_window()->create_cairo_context(); - return _onDraw(cr); -} -#endif - - -bool PdfImportCairoDialog::_onDraw(const Cairo::RefPtr<Cairo::Context>& cr) { - // Check if we have a thumbnail at all - if (!_thumb_data) { - return true; - } - - // Create the pixbuf for the thumbnail - Glib::RefPtr<Gdk::Pixbuf> thumb; - if (_render_thumb) { - thumb = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, - 8, _thumb_width, _thumb_height); - } else { - thumb = Gdk::Pixbuf::create_from_data(_thumb_data, Gdk::COLORSPACE_RGB, - false, 8, _thumb_width, _thumb_height, _thumb_rowstride); - } - if (!thumb) { - return true; - } - - // Set background to white - if (_render_thumb) { - thumb->fill(0xffffffff); - Gdk::Cairo::set_source_pixbuf(cr, thumb, 0, 0); - cr->paint(); - } - - // Copy the thumbnail image from the Cairo surface - if (_render_thumb) { - copy_cairo_surface_to_pixbuf(_cairo_surface, _thumb_data, thumb->gobj()); - } - Gdk::Cairo::set_source_pixbuf(cr, thumb, 0, _render_thumb ? 0 : 20); - cr->paint(); - - return true; -} - -/** - * \brief Renders the given page's thumbnail using Cairo - */ -void PdfImportCairoDialog::_setPreviewPage(int page) { - - PopplerPage *_previewed_page = poppler_document_get_page(_poppler_doc, page-1); - - // Try to get a thumbnail from the PDF if possible - if (!_render_thumb) { - if (_thumb_data) { - // --> gfree(_thumb_data); - free(_thumb_data); - _thumb_data = NULL; - } - -/* ---> if (!_previewed_page->loadThumb(&_thumb_data, - &_thumb_width, &_thumb_height, &_thumb_rowstride)) { - return; - } -*/ - // Redraw preview area - _previewArea->set_size_request(_thumb_width, _thumb_height + 20); - _previewArea->queue_draw(); - return; - } - - // Get page size by accounting for rotation - double width, height; - // --> int rotate = _previewed_page->getRotate(); - int rotate = 0; - if ( rotate == 90 || rotate == 270 ) { -// --> height = _previewed_page->getCropWidth(); -// --> width = _previewed_page->getCropHeight(); - } else { - poppler_page_get_size (_previewed_page, &width, &height); -// --> width = _previewed_page->getCropWidth(); -// --> height = _previewed_page->getCropHeight(); - } - // Calculate the needed scaling for the page - double scale_x = (double)_preview_width / width; - double scale_y = (double)_preview_height / height; - double scale_factor = ( scale_x > scale_y ) ? scale_y : scale_x; - // Create new Cairo surface - _thumb_width = (int)ceil( width * scale_factor ); - _thumb_height = (int)ceil( height * scale_factor ); - _thumb_rowstride = _thumb_width * 4; - if (_thumb_data) { - delete _thumb_data; - } - _thumb_data = new unsigned char[ _thumb_rowstride * _thumb_height ]; - if (_cairo_surface) { - cairo_surface_destroy(_cairo_surface); - } - _cairo_surface = cairo_image_surface_create_for_data(_thumb_data, - CAIRO_FORMAT_ARGB32, _thumb_width, _thumb_height, _thumb_rowstride); - cairo_t *cr = cairo_create(_cairo_surface); - cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); // Set fill color to white - cairo_paint(cr); // Clear it - cairo_scale(cr, scale_factor, scale_factor); // Use Cairo for resizing the image - // Render page - if (_poppler_doc != NULL) { - PopplerPage *poppler_page = poppler_document_get_page(_poppler_doc, page - 1); - poppler_page_render(poppler_page, cr); - g_object_unref(G_OBJECT(poppler_page)); - } - // Clean up - cairo_destroy(cr); - // Redraw preview area - _previewArea->set_size_request(_preview_width, _preview_height); - _previewArea->queue_draw(); - -} - - -static cairo_status_t _write_ustring_cb(void *closure, const unsigned char *data, unsigned int length); - -SPDocument * -PdfInputCairo::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { - - g_message("Attempting to open using PdfInputCairo\n"); - - gchar* filename_uri = g_filename_to_uri(uri, NULL, NULL); - - GError *error = NULL; - /// @todo handle passwort - /// @todo check if win32 unicode needs special attention - PopplerDocument* document = poppler_document_new_from_file(filename_uri, NULL, &error); - - if(error != NULL) { - g_message("Unable to read file: %s\n", error->message); - g_error_free (error); - } - - if (document == NULL) { - return NULL; - } - - // create and show the import dialog - PdfImportCairoDialog *dlg = NULL; - if (inkscape_use_gui()) { - dlg = new PdfImportCairoDialog(document); - if (!dlg->showDialog()) { - delete dlg; - return NULL; - } - } - - // Get needed page - int page_num; - if (dlg) { - page_num = dlg->getSelectedPage(); - delete dlg; - } - else - page_num = 1; - - double width, height; - PopplerPage* page = poppler_document_get_page(document, page_num - 1); - poppler_page_get_size(page, &width, &height); - - Glib::ustring* output = new Glib::ustring(""); - cairo_surface_t* surface = cairo_svg_surface_create_for_stream(Inkscape::Extension::Internal::_write_ustring_cb, - output, width, height); - cairo_t* cr = cairo_create(surface); - - poppler_page_render(page, cr); - cairo_show_page(cr); - - cairo_destroy(cr); - cairo_surface_destroy(surface); - - SPDocument * doc = SPDocument::createNewDocFromMem(output->c_str(), output->length(), TRUE); - - // Set viewBox if it doesn't exist - if (doc && !doc->getRoot()->viewBox_set) { - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); - } - - delete output; - g_object_unref(page); - g_object_unref(document); - - return doc; -} - -static cairo_status_t - _write_ustring_cb(void *closure, const unsigned char *data, unsigned int length) -{ - Glib::ustring* stream = static_cast<Glib::ustring*>(closure); - stream->append(reinterpret_cast<const char*>(data), length); - - return CAIRO_STATUS_SUCCESS; -} - - -#include "clear-n_.h" - -void -PdfInputCairo::init(void) { - Inkscape::Extension::build_from_mem( - "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" - "<name>" N_("PDF Input") "</name>\n" - "<id>org.inkscape.input.cairo-pdf</id>\n" - "<input>\n" - "<extension>.pdf</extension>\n" - "<mimetype>application/pdf</mimetype>\n" - "<filetypename>" N_("Adobe PDF via poppler-cairo (*.pdf)") "</filetypename>\n" - "<filetypetooltip>" N_("PDF Document") "</filetypetooltip>\n" - "</input>\n" - "</inkscape-extension>", new PdfInputCairo()); -} // init - -} } } /* namespace Inkscape, Extension, Implementation */ - -#endif /* HAVE_POPPLER_CAIRO */ -#endif /* HAVE_POPPLER_GLIB */ - -/* - 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/pdf-input-cairo.h b/src/extension/internal/pdf-input-cairo.h deleted file mode 100644 index b65d22f48..000000000 --- a/src/extension/internal/pdf-input-cairo.h +++ /dev/null @@ -1,157 +0,0 @@ -#ifndef __EXTENSION_INTERNAL_PDFINPUTCAIRO_H__ -#define __EXTENSION_INTERNAL_PDFINPUTCAIRO_H__ - -/* - * PDF input using libpoppler and Cairo's SVG surface. - * - * Authors: - * miklos erdelyi - * - * Copyright (C) 2007 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include <glibmm/threads.h> -#endif - -#include <gtkmm/dialog.h> -#include <gtkmm/button.h> -#include <gtkmm/buttonbox.h> -#include <gtkmm/label.h> -#include <gtkmm/box.h> -#include <gtkmm/checkbutton.h> -#include <gtkmm/comboboxtext.h> -#include <gtkmm/drawingarea.h> -#include <gtkmm/alignment.h> -#include <gtkmm/frame.h> -#include <gtkmm/scale.h> -#include <glibmm/i18n.h> -#include <gdk/gdk.h> - -#ifdef HAVE_POPPLER_GLIB -#ifdef HAVE_POPPLER_CAIRO - -#include <poppler/glib/poppler.h> - -#include "../implementation/implementation.h" - -namespace Gtk { -#if WITH_GTKMM_3_0 - class Scale; -#else - class HScale; -#endif -} - -namespace Inkscape { - -namespace UI { -namespace Widget { - class SpinButton; - class Frame; -} -} - -namespace Extension { -namespace Internal { - -class PdfImportCairoDialog : public Gtk::Dialog -{ -public: - PdfImportCairoDialog(PopplerDocument* doc); - virtual ~PdfImportCairoDialog(); - - bool showDialog(); - int getSelectedPage(); - void getImportSettings(Inkscape::XML::Node *prefs); - -private: - void _setPreviewPage(int page); - - // Signal handlers -#if !WITH_GTKMM_3_0 - bool _onExposePreview(GdkEventExpose *event); -#endif - - bool _onDraw(const Cairo::RefPtr<Cairo::Context>& cr); - void _onPageNumberChanged(); - void _onToggleCropping(); - void _onPrecisionChanged(); - - class Gtk::Button * cancelbutton; - class Gtk::Button * okbutton; - class Gtk::Label * _labelSelect; - class Inkscape::UI::Widget::SpinButton * _pageNumberSpin; - class Gtk::Label * _labelTotalPages; - class Gtk::HBox * hbox2; - class Gtk::CheckButton * _cropCheck; - class Gtk::ComboBoxText * _cropTypeCombo; - class Gtk::HBox * hbox3; - class Gtk::VBox * vbox2; - class Inkscape::UI::Widget::Frame * _pageSettingsFrame; - class Gtk::Label * _labelPrecision; - class Gtk::Label * _labelPrecisionWarning; -#if WITH_GTKMM_3_0 - class Gtk::Scale * _fallbackPrecisionSlider; - Glib::RefPtr<Gtk::Adjustment> _fallbackPrecisionSlider_adj; -#else - class Gtk::HScale * _fallbackPrecisionSlider; - class Gtk::Adjustment *_fallbackPrecisionSlider_adj; -#endif - class Gtk::Label * _labelPrecisionComment; - class Gtk::HBox * hbox6; - class Gtk::Label * _labelText; - class Gtk::ComboBoxText * _textHandlingCombo; - class Gtk::HBox * hbox5; - class Gtk::CheckButton * _localFontsCheck; - class Gtk::CheckButton * _embedImagesCheck; - class Gtk::VBox * vbox3; - class Inkscape::UI::Widget::Frame * _importSettingsFrame; - class Gtk::VBox * vbox1; - class Gtk::DrawingArea * _previewArea; - class Gtk::HBox * hbox1; - - PopplerDocument *_poppler_doc; - // PopplerPage *_previewed_page; - int _current_page; // Current selected page - unsigned char *_thumb_data; // Thumbnail image data - int _thumb_width, _thumb_height; // Thumbnail size - int _thumb_rowstride; - int _preview_width, _preview_height; // Size of the preview area - bool _render_thumb; // Whether we can/shall render thumbnails - cairo_surface_t *_cairo_surface; // this cairo surface is used for preview -}; - - -class PdfInputCairo: public Inkscape::Extension::Implementation::Implementation { - PdfInputCairo () { }; -public: - SPDocument *open( Inkscape::Extension::Input *mod, - const gchar *uri ); - static void init( void ); - -}; - -} } } /* namespace Inkscape, Extension, Implementation */ - -#endif /* HAVE_POPPLER_CAIRO */ -#endif /* HAVE_POPPLER_GLIB */ - -#endif /* __EXTENSION_INTERNAL_PDFINPUTCAIRO_H__ */ - -/* - 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/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp index 3155ac098..c8a7feabf 100644 --- a/src/extension/internal/pdfinput/pdf-input.cpp +++ b/src/extension/internal/pdfinput/pdf-input.cpp @@ -48,7 +48,7 @@ #include "inkscape.h" #include "util/units.h" -#include "dialogs/dialog-events.h" +#include "ui/dialog-events.h" #include <gtk/gtk.h> #include "ui/widget/spinbutton.h" #include "ui/widget/frame.h" @@ -124,6 +124,9 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar */*uri*/) _labelPrecision = Gtk::manage(new class Gtk::Label(_("Precision of approximating gradient meshes:"))); _labelPrecisionWarning = Gtk::manage(new class Gtk::Label(_("<b>Note</b>: setting the precision too high may result in a large SVG file and slow performance."))); +#ifdef HAVE_POPPLER_CAIRO + _importviaPopplerCheck = Gtk::manage(new class Gtk::CheckButton(_("import via Poppler"))); +#endif #if WITH_GTKMM_3_0 _fallbackPrecisionSlider_adj = Gtk::Adjustment::create(2, 1, 256, 1, 10, 10); _fallbackPrecisionSlider = Gtk::manage(new class Gtk::Scale(_fallbackPrecisionSlider_adj)); @@ -199,6 +202,12 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar */*uri*/) _labelPrecisionWarning->set_line_wrap(true); _labelPrecisionWarning->set_use_markup(true); _labelPrecisionWarning->set_selectable(false); +#ifdef HAVE_POPPLER_CAIRO + _importviaPopplerCheck->set_can_focus(); + _importviaPopplerCheck->set_relief(Gtk::RELIEF_NORMAL); + _importviaPopplerCheck->set_mode(true); + _importviaPopplerCheck->set_active(false); +#endif _fallbackPrecisionSlider->set_size_request(180,-1); _fallbackPrecisionSlider->set_can_focus(); _fallbackPrecisionSlider->set_inverted(false); @@ -230,6 +239,9 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar */*uri*/) _embedImagesCheck->set_relief(Gtk::RELIEF_NORMAL); _embedImagesCheck->set_mode(true); _embedImagesCheck->set_active(true); +#ifdef HAVE_POPPLER_CAIRO + vbox3->pack_start(*_importviaPopplerCheck, Gtk::PACK_SHRINK, 0); +#endif vbox3->pack_start(*_labelPrecision, Gtk::PACK_SHRINK, 0); vbox3->pack_start(*hbox6, Gtk::PACK_SHRINK, 0); vbox3->pack_start(*_labelPrecisionWarning, Gtk::PACK_SHRINK, 0); @@ -274,6 +286,9 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar */*uri*/) _pageSettingsFrame->show(); _labelPrecision->show(); _labelPrecisionWarning->show(); +#ifdef HAVE_POPPLER_CAIRO + _importviaPopplerCheck->show(); +#endif _fallbackPrecisionSlider->show(); _labelPrecisionComment->show(); hbox6->show(); @@ -358,6 +373,14 @@ int PdfImportDialog::getSelectedPage() { return _current_page; } +int PdfImportDialog::getImportMethod() { +#ifdef HAVE_POPPLER_CAIRO + return (_importviaPopplerCheck->get_active()) ? 1 : 0; +#else + return 0; +#endif +} + /** * \brief Retrieves the current settings into a repr which SvgBuilder will use * for determining the behaviour desired by the user @@ -389,6 +412,13 @@ void PdfImportDialog::getImportSettings(Inkscape::XML::Node *prefs) { } else { prefs->setAttribute("embedImages", "0"); } +#ifdef HAVE_POPPLER_CAIRO + if (_importviaPopplerCheck->get_active()) { + prefs->setAttribute("importviapoppler", "1"); + } else { + prefs->setAttribute("importviapoppler", "0"); + } +#endif } /** @@ -595,6 +625,18 @@ PdfInput::wasCancelled () { return _cancelled; } +#ifdef HAVE_POPPLER_CAIRO +/// helper method +static cairo_status_t + _write_ustring_cb(void *closure, const unsigned char *data, unsigned int length) +{ + Glib::ustring* stream = static_cast<Glib::ustring*>(closure); + stream->append(reinterpret_cast<const char*>(data), length); + + return CAIRO_STATUS_SUCCESS; +} +#endif + /** * Parses the selected page of the given PDF document using PdfParser. */ @@ -605,7 +647,31 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { // Initialize the globalParams variable for poppler if (!globalParams) { +#ifdef ENABLE_OSX_APP_LOCATIONS + // + // data files for poppler are not relocatable (loaded from + // path defined at build time). This fails to work with relocatable + // application bundles for OS X. + // + // Workaround: + // 1. define $POPPLER_DATADIR env variable in app launcher script + // 2. pass custom $POPPLER_DATADIR via poppler's GlobalParams() + // + // relevant poppler commit: + // <http://cgit.freedesktop.org/poppler/poppler/commit/?id=869584a84eed507775ff1c3183fe484c14b6f77b> + // + // FIXES: Inkscape bug #956282, #1264793 + // TODO: report RFE upstream (full relocation support for OS X packaging) + // + gchar const *poppler_datadir = g_getenv("POPPLER_DATADIR"); + if (poppler_datadir != NULL) { + globalParams = new GlobalParams(poppler_datadir); + } else { + globalParams = new GlobalParams(); + } +#else globalParams = new GlobalParams(); +#endif // ENABLE_OSX_APP_LOCATIONS } // poppler does not use glib g_open. So on win32 we must use unicode call. code was copied from glib gstdio.c #ifndef WIN32 @@ -672,79 +738,146 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { page_num = 1; Catalog *catalog = pdf_doc->getCatalog(); Page *page = catalog->getPage(page_num); + + int is_importvia_poppler = 0; + if(dlg) + { +#ifdef HAVE_POPPLER_CAIRO + is_importvia_poppler = dlg->getImportMethod(); +#endif + } - SPDocument *doc = SPDocument::createNewDoc(NULL, TRUE, TRUE); - bool saved = DocumentUndo::getUndoSensitive(doc); - DocumentUndo::setUndoSensitive(doc, false); // No need to undo in this temporary document + SPDocument *doc = NULL; + bool saved = false; + if(is_importvia_poppler == 0) + { + // native importer + doc = SPDocument::createNewDoc(NULL, TRUE, TRUE); + saved = DocumentUndo::getUndoSensitive(doc); + DocumentUndo::setUndoSensitive(doc, false); // No need to undo in this temporary document + + // Create builder + gchar *docname = g_path_get_basename(uri); + gchar *dot = g_strrstr(docname, "."); + if (dot) { + *dot = 0; + } + SvgBuilder *builder = new SvgBuilder(doc, docname, pdf_doc->getXRef()); + + // Get preferences + Inkscape::XML::Node *prefs = builder->getPreferences(); + if (dlg) + dlg->getImportSettings(prefs); + + printf("pdf import via %s.", (is_importvia_poppler != 0) ? "poppler" : "native"); + + // Apply crop settings + PDFRectangle *clipToBox = NULL; + double crop_setting; + sp_repr_get_double(prefs, "cropTo", &crop_setting); + if ( crop_setting >= 0.0 ) { // Do page clipping + int crop_choice = (int)crop_setting; + switch (crop_choice) { + case 0: // Media box + clipToBox = page->getMediaBox(); + break; + case 1: // Crop box + clipToBox = page->getCropBox(); + break; + case 2: // Bleed box + clipToBox = page->getBleedBox(); + break; + case 3: // Trim box + clipToBox = page->getTrimBox(); + break; + case 4: // Art box + clipToBox = page->getArtBox(); + break; + default: + break; + } + } - // Create builder - gchar *docname = g_path_get_basename(uri); - gchar *dot = g_strrstr(docname, "."); - if (dot) { - *dot = 0; - } - SvgBuilder *builder = new SvgBuilder(doc, docname, pdf_doc->getXRef()); + // Create parser + PdfParser *pdf_parser = new PdfParser(pdf_doc->getXRef(), builder, page_num-1, page->getRotate(), + page->getResourceDict(), page->getCropBox(), clipToBox); - // Get preferences - Inkscape::XML::Node *prefs = builder->getPreferences(); - if (dlg) - dlg->getImportSettings(prefs); - - // Apply crop settings - PDFRectangle *clipToBox = NULL; - double crop_setting; - sp_repr_get_double(prefs, "cropTo", &crop_setting); - if ( crop_setting >= 0.0 ) { // Do page clipping - int crop_choice = (int)crop_setting; - switch (crop_choice) { - case 0: // Media box - clipToBox = page->getMediaBox(); - break; - case 1: // Crop box - clipToBox = page->getCropBox(); - break; - case 2: // Bleed box - clipToBox = page->getBleedBox(); - break; - case 3: // Trim box - clipToBox = page->getTrimBox(); - break; - case 4: // Art box - clipToBox = page->getArtBox(); - break; - default: - break; + // Set up approximation precision for parser + double color_delta; + sp_repr_get_double(prefs, "approximationPrecision", &color_delta); + if ( color_delta <= 0.0 ) { + color_delta = 1.0 / 2.0; + } else { + color_delta = 1.0 / color_delta; + } + for ( int i = 1 ; i <= pdfNumShadingTypes ; i++ ) { + pdf_parser->setApproximationPrecision(i, color_delta, 6); } - } - // Create parser - PdfParser *pdf_parser = new PdfParser(pdf_doc->getXRef(), builder, page_num-1, page->getRotate(), - page->getResourceDict(), page->getCropBox(), clipToBox); + // Parse the document structure + Object obj; + page->getContents(&obj); + if (!obj.isNull()) { + pdf_parser->parse(&obj); + } - // Set up approximation precision for parser - double color_delta; - sp_repr_get_double(prefs, "approximationPrecision", &color_delta); - if ( color_delta <= 0.0 ) { - color_delta = 1.0 / 2.0; - } else { - color_delta = 1.0 / color_delta; - } - for ( int i = 1 ; i <= pdfNumShadingTypes ; i++ ) { - pdf_parser->setApproximationPrecision(i, color_delta, 6); + // Cleanup + obj.free(); + delete pdf_parser; + delete builder; + g_free(docname); } + else + { +#ifdef HAVE_POPPLER_CAIRO + // the poppler import + gchar* filename_uri = g_filename_to_uri(uri, NULL, NULL); + GError *error = NULL; + /// @todo handle passwort + /// @todo check if win32 unicode needs special attention + PopplerDocument* document = poppler_document_new_from_file(filename_uri, NULL, &error); + + if(error != NULL) { + g_error_free (error); + } - // Parse the document structure - Object obj; - page->getContents(&obj); - if (!obj.isNull()) { - pdf_parser->parse(&obj); + if (document != NULL) + { + double width, height; + PopplerPage* page = poppler_document_get_page(document, page_num - 1); + poppler_page_get_size(page, &width, &height); + + Glib::ustring output; + cairo_surface_t* surface = cairo_svg_surface_create_for_stream(Inkscape::Extension::Internal::_write_ustring_cb, + &output, width, height); + cairo_t* cr = cairo_create(surface); + + poppler_page_render_for_printing(page, cr); + cairo_show_page(cr); + + cairo_destroy(cr); + cairo_surface_destroy(surface); + + doc = SPDocument::createNewDocFromMem(output.c_str(), output.length(), TRUE); + + // Cleanup + // delete output; + g_object_unref(G_OBJECT(page)); + g_object_unref(G_OBJECT(document)); + } + else + { + doc = SPDocument::createNewDoc(NULL, TRUE, TRUE); // fallback create empthy document + } + saved = DocumentUndo::getUndoSensitive(doc); + DocumentUndo::setUndoSensitive(doc, false); // No need to undo in this temporary document + + // Cleanup + g_free(filename_uri); +#endif } // Cleanup - obj.free(); - delete pdf_parser; - delete builder; - g_free(docname); delete pdf_doc; delete dlg; diff --git a/src/extension/internal/pdfinput/pdf-input.h b/src/extension/internal/pdfinput/pdf-input.h index f22a783ff..d57c3e993 100644 --- a/src/extension/internal/pdfinput/pdf-input.h +++ b/src/extension/internal/pdfinput/pdf-input.h @@ -75,6 +75,7 @@ public: bool showDialog(); int getSelectedPage(); + int getImportMethod(); void getImportSettings(Inkscape::XML::Node *prefs); private: @@ -103,6 +104,9 @@ private: class Inkscape::UI::Widget::Frame * _pageSettingsFrame; class Gtk::Label * _labelPrecision; class Gtk::Label * _labelPrecisionWarning; +#ifdef HAVE_POPPLER_CAIRO + class Gtk::CheckButton * _importviaPopplerCheck; // using poppler_cairo for importing +#endif #if WITH_GTKMM_3_0 class Gtk::Scale * _fallbackPrecisionSlider; Glib::RefPtr<Gtk::Adjustment> _fallbackPrecisionSlider_adj; diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index b398486e6..0b7dc7905 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -247,30 +247,74 @@ PdfOperator PdfParser::opTab[] = { #define numOps (sizeof(opTab) / sizeof(PdfOperator)) +namespace { + +GfxPatch blankPatch() +{ + GfxPatch patch; + memset(&patch, 0, sizeof(patch)); // quick-n-dirty + return patch; +} + +} // namespace + //------------------------------------------------------------------------ -// PdfParser +// ClipHistoryEntry //------------------------------------------------------------------------ -PdfParser::PdfParser(XRef *xrefA, Inkscape::Extension::Internal::SvgBuilder *builderA, - int /*pageNum*/, int rotate, Dict *resDict, - PDFRectangle *box, PDFRectangle *cropBox) -{ - xref = xrefA; - subPage = gFalse; - printCommands = false; +class ClipHistoryEntry { +public: + + ClipHistoryEntry(GfxPath *clipPath = NULL, GfxClipType clipType = clipNormal); + virtual ~ClipHistoryEntry(); - // start the resource stack - res = new GfxResources(xref, resDict, NULL); + // Manipulate clip path stack + ClipHistoryEntry *save(); + ClipHistoryEntry *restore(); + GBool hasSaves() { return saved != NULL; } + void setClip(GfxPath *newClipPath, GfxClipType newClipType = clipNormal); + GfxPath *getClipPath() { return clipPath; } + GfxClipType getClipType() { return clipType; } - // initialize - state = new GfxState(72.0, 72.0, box, rotate, gTrue); - clipHistory = new ClipHistoryEntry(); +private: + + ClipHistoryEntry *saved; // next clip path on stack + + GfxPath *clipPath; // used as the path to be filled for an 'sh' operator + GfxClipType clipType; + + ClipHistoryEntry(ClipHistoryEntry *other); +}; + +//------------------------------------------------------------------------ +// PdfParser +//------------------------------------------------------------------------ + +PdfParser::PdfParser(XRef *xrefA, + Inkscape::Extension::Internal::SvgBuilder *builderA, + int /*pageNum*/, + int rotate, + Dict *resDict, + PDFRectangle *box, + PDFRectangle *cropBox) : + xref(xrefA), + builder(builderA), + subPage(gFalse), + printCommands(false), + res(new GfxResources(xref, resDict, NULL)), // start the resource stack + state(new GfxState(72.0, 72.0, box, rotate, gTrue)), + fontChanged(gFalse), + clip(clipNone), + ignoreUndef(0), + baseMatrix(), + formDepth(0), + parser(NULL), + colorDeltas(), + maxDepths(), + clipHistory(new ClipHistoryEntry()), + operatorHistory(NULL) +{ setDefaultApproximationPrecision(); - fontChanged = gFalse; - clip = clipNone; - ignoreUndef = 0; - operatorHistory = NULL; - builder = builderA; builder->setDocumentSize(Inkscape::Util::Quantity::convert(state->getPageWidth(), "pt", "px"), Inkscape::Util::Quantity::convert(state->getPageHeight(), "pt", "px")); @@ -306,50 +350,62 @@ PdfParser::PdfParser(XRef *xrefA, Inkscape::Extension::Internal::SvgBuilder *bui pushOperator("startPage"); } -PdfParser::PdfParser(XRef *xrefA, Inkscape::Extension::Internal::SvgBuilder *builderA, - Dict *resDict, PDFRectangle *box) { - - int i; - parser = NULL; - - xref = xrefA; - subPage = gTrue; - printCommands = false; - - // start the resource stack - res = new GfxResources(xref, resDict, NULL); - - // initialize - operatorHistory = NULL; - builder = builderA; - state = new GfxState(72, 72, box, 0, gFalse); - clipHistory = new ClipHistoryEntry(); +PdfParser::PdfParser(XRef *xrefA, + Inkscape::Extension::Internal::SvgBuilder *builderA, + Dict *resDict, + PDFRectangle *box) : + xref(xrefA), + builder(builderA), + subPage(gTrue), + printCommands(false), + res(new GfxResources(xref, resDict, NULL)), // start the resource stack + state(new GfxState(72, 72, box, 0, gFalse)), + fontChanged(gFalse), + clip(clipNone), + ignoreUndef(0), + baseMatrix(), + formDepth(0), + parser(NULL), + colorDeltas(), + maxDepths(), + clipHistory(new ClipHistoryEntry()), + operatorHistory(NULL) +{ setDefaultApproximationPrecision(); - fontChanged = gFalse; - clip = clipNone; - ignoreUndef = 0; - for (i = 0; i < 6; ++i) { + for (int i = 0; i < 6; ++i) { baseMatrix[i] = state->getCTM()[i]; } formDepth = 0; } PdfParser::~PdfParser() { - while (state->hasSaves()) { + while(operatorHistory) { + OpHistoryEntry *tmp = operatorHistory->next; + delete operatorHistory; + operatorHistory = tmp; + } + + while (state && state->hasSaves()) { restoreState(); } + if (!subPage) { //out->endPage(); } + while (res) { popResources(); } + if (state) { delete state; + state = NULL; } + if (clipHistory) { delete clipHistory; + clipHistory = NULL; } } @@ -460,7 +516,8 @@ void PdfParser::go(GBool /*topLevel*/) } } -void PdfParser::pushOperator(const char *name) { +void PdfParser::pushOperator(const char *name) +{ OpHistoryEntry *newEntry = new OpHistoryEntry; newEntry->name = name; newEntry->state = NULL; @@ -866,7 +923,9 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/) GBool isolated = gFalse; GBool knockout = gFalse; if (!obj4.dictLookup(const_cast<char*>("CS"), &obj5)->isNull()) { -#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) +#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) + blendingColorSpace = GfxColorSpace::parse(&obj5, NULL, NULL); +#elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) blendingColorSpace = GfxColorSpace::parse(&obj5, NULL); #else blendingColorSpace = GfxColorSpace::parse(&obj5); @@ -1100,7 +1159,13 @@ void PdfParser::opSetFillColorSpace(Object args[], int /*numArgs*/) res->lookupColorSpace(args[0].getName(), &obj); GfxColorSpace *colorSpace = 0; -#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) +#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) + if (obj.isNull()) { + colorSpace = GfxColorSpace::parse(&args[0], NULL, NULL); + } else { + colorSpace = GfxColorSpace::parse(&obj, NULL, NULL); + } +#elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) if (obj.isNull()) { colorSpace = GfxColorSpace::parse(&args[0], NULL); } else { @@ -1137,7 +1202,13 @@ void PdfParser::opSetStrokeColorSpace(Object args[], int /*numArgs*/) state->setStrokePattern(NULL); res->lookupColorSpace(args[0].getName(), &obj); -#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) +#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) + if (obj.isNull()) { + colorSpace = GfxColorSpace::parse(&args[0], NULL, NULL); + } else { + colorSpace = GfxColorSpace::parse(&obj, NULL, NULL); + } +#elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) if (obj.isNull()) { colorSpace = GfxColorSpace::parse(&args[0], NULL); } else { @@ -1231,7 +1302,13 @@ void PdfParser::opSetFillColorN(Object args[], int numArgs) { builder->updateStyle(state); } GfxPattern *pattern; -#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) +#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) + if (args[numArgs-1].isName() && + (pattern = res->lookupPattern(args[numArgs-1].getName(), NULL, NULL))) { + state->setFillPattern(pattern); + builder->updateStyle(state); + } +#elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) if (args[numArgs-1].isName() && (pattern = res->lookupPattern(args[numArgs-1].getName(), NULL))) { state->setFillPattern(pattern); @@ -1291,7 +1368,13 @@ void PdfParser::opSetStrokeColorN(Object args[], int numArgs) { builder->updateStyle(state); } GfxPattern *pattern; -#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) +#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) + if (args[numArgs-1].isName() && + (pattern = res->lookupPattern(args[numArgs-1].getName(), NULL, NULL))) { + state->setStrokePattern(pattern); + builder->updateStyle(state); + } +#elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) if (args[numArgs-1].isName() && (pattern = res->lookupPattern(args[numArgs-1].getName(), NULL))) { state->setStrokePattern(pattern); @@ -1746,7 +1829,11 @@ void PdfParser::opShFill(Object args[], int /*numArgs*/) double *matrix = NULL; GBool savedState = gFalse; -#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) +#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) + if (!(shading = res->lookupShading(args[0].getName(), NULL, NULL))) { + return; + } +#elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) if (!(shading = res->lookupShading(args[0].getName(), NULL))) { return; } @@ -2056,13 +2143,19 @@ void PdfParser::doPatchMeshShFill(GfxPatchMeshShading *shading) { } void PdfParser::fillPatch(GfxPatch *patch, int nComps, int depth) { - GfxPatch patch00, patch01, patch10, patch11; + GfxPatch patch00 = blankPatch(); + GfxPatch patch01 = blankPatch(); + GfxPatch patch10 = blankPatch(); + GfxPatch patch11 = blankPatch(); #ifdef POPPLER_NEW_GFXPATCH - GfxColor color; + GfxColor color = {{0}}; #endif - double xx[4][8], yy[4][8]; - double xxm, yym; - double patchColorDelta = colorDeltas[pdfPatchMeshShading-1]; + double xx[4][8]; + double yy[4][8]; + double xxm; + double yym; + double patchColorDelta = colorDeltas[pdfPatchMeshShading - 1]; + int i; for (i = 0; i < nComps; ++i) { @@ -2817,7 +2910,9 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) } } if (!obj1.isNull()) { -#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) +#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) + colorSpace = GfxColorSpace::parse(&obj1, NULL, NULL); +#elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) colorSpace = GfxColorSpace::parse(&obj1, NULL); #else colorSpace = GfxColorSpace::parse(&obj1); @@ -2909,7 +3004,9 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) obj2.free(); } } -#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) +#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) + GfxColorSpace *maskColorSpace = GfxColorSpace::parse(&obj1, NULL, NULL); +#elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) GfxColorSpace *maskColorSpace = GfxColorSpace::parse(&obj1, NULL); #else GfxColorSpace *maskColorSpace = GfxColorSpace::parse(&obj1); @@ -3099,7 +3196,9 @@ void PdfParser::doForm(Object *str) { if (obj1.dictLookup(const_cast<char*>("S"), &obj2)->isName(const_cast<char*>("Transparency"))) { transpGroup = gTrue; if (!obj1.dictLookup(const_cast<char*>("CS"), &obj3)->isNull()) { -#if defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) +#if defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) + blendingColorSpace = GfxColorSpace::parse(&obj3, NULL, NULL); +#elif defined(POPPLER_NEW_COLOR_SPACE_API) || defined(POPPLER_NEW_ERRORAPI) blendingColorSpace = GfxColorSpace::parse(&obj3, NULL); #else blendingColorSpace = GfxColorSpace::parse(&obj3); @@ -3427,9 +3526,7 @@ void PdfParser::popResources() { } void PdfParser::setDefaultApproximationPrecision() { - int i; - - for (i = 1; i <= pdfNumShadingTypes; ++i) { + for (int i = 1; i <= pdfNumShadingTypes; ++i) { setApproximationPrecision(i, defaultShadingColorDelta, defaultShadingMaxDepth); } } @@ -3448,19 +3545,18 @@ void PdfParser::setApproximationPrecision(int shadingType, double colorDelta, // ClipHistoryEntry //------------------------------------------------------------------------ -ClipHistoryEntry::ClipHistoryEntry(GfxPath *clipPathA, GfxClipType clipTypeA) { - if (clipPathA) { - clipPath = clipPathA->copy(); - } else { - clipPath = NULL; - } - clipType = clipTypeA; - saved = NULL; +ClipHistoryEntry::ClipHistoryEntry(GfxPath *clipPathA, GfxClipType clipTypeA) : + saved(NULL), + clipPath((clipPathA) ? clipPathA->copy() : NULL), + clipType(clipTypeA) +{ } -ClipHistoryEntry::~ClipHistoryEntry() { +ClipHistoryEntry::~ClipHistoryEntry() +{ if (clipPath) { delete clipPath; + clipPath = NULL; } } @@ -3474,6 +3570,7 @@ void ClipHistoryEntry::setClip(GfxPath *clipPathA, GfxClipType clipTypeA) { clipType = clipTypeA; } else { clipPath = NULL; + clipType = clipNormal; } } @@ -3490,7 +3587,7 @@ ClipHistoryEntry *ClipHistoryEntry::restore() { if (saved) { oldEntry = saved; saved = NULL; - delete this; + delete this; // TODO really should avoid deleting from inside. } else { oldEntry = this; } @@ -3504,6 +3601,7 @@ ClipHistoryEntry::ClipHistoryEntry(ClipHistoryEntry *other) { this->clipType = other->clipType; } else { this->clipPath = NULL; + this->clipType = clipNormal; } saved = NULL; } diff --git a/src/extension/internal/pdfinput/pdf-parser.h b/src/extension/internal/pdfinput/pdf-parser.h index a63d669c7..e28fecc2e 100644 --- a/src/extension/internal/pdfinput/pdf-parser.h +++ b/src/extension/internal/pdfinput/pdf-parser.h @@ -58,6 +58,8 @@ class AnnotBorderStyle; class PdfParser; +class ClipHistoryEntry; + //------------------------------------------------------------------------ #ifndef GFX_H @@ -101,34 +103,6 @@ struct OpHistoryEntry { }; //------------------------------------------------------------------------ -// ClipHistoryEntry -//------------------------------------------------------------------------ - -class ClipHistoryEntry { -public: - - ClipHistoryEntry(GfxPath *clipPath=NULL, GfxClipType clipType=clipNormal); - virtual ~ClipHistoryEntry(); - - // Manipulate clip path stack - ClipHistoryEntry *save(); - ClipHistoryEntry *restore(); - GBool hasSaves() { return saved != NULL; } - void setClip(GfxPath *newClipPath, GfxClipType newClipType=clipNormal); - GfxPath *getClipPath() { return clipPath; } - GfxClipType getClipType() { return clipType; } - -private: - - ClipHistoryEntry *saved; // next clip path on stack - - GfxPath *clipPath; // used as the path to be filled for an 'sh' operator - GfxClipType clipType; - - ClipHistoryEntry(ClipHistoryEntry *other); -}; - -//------------------------------------------------------------------------ // PdfParser //------------------------------------------------------------------------ diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp index 71e6dc6ae..7a504add0 100644 --- a/src/extension/internal/pdfinput/svg-builder.cpp +++ b/src/extension/internal/pdfinput/svg-builder.cpp @@ -123,12 +123,11 @@ void SvgBuilder::_init() { _height = 0; // Fill _availableFontNames (Bug LP #179589) (code cfr. FontLister) - FamilyToStylesMap familyStyleMap; - font_factory::Default()->GetUIFamiliesAndStyles(&familyStyleMap); - for (FamilyToStylesMap::iterator iter = familyStyleMap.begin(); - iter != familyStyleMap.end(); - ++iter) { - _availableFontNames.push_back(iter->first.c_str()); + std::vector<PangoFontFamily *> families; + font_factory::Default()->GetUIFamilies(families); + for ( std::vector<PangoFontFamily *>::iterator iter = families.begin(); + iter != families.end(); ++iter ) { + _availableFontNames.push_back(pango_font_family_get_name(*iter)); } _transp_group_stack = NULL; diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp index 8b272af60..a94bc2141 100644 --- a/src/extension/internal/svg.cpp +++ b/src/extension/internal/svg.cpp @@ -24,6 +24,7 @@ #include "extension/output.h" #include <vector> #include "xml/attribute-record.h" +#include "xml/simple-document.h" #include "sp-root.h" #include "document.h" @@ -42,27 +43,37 @@ using Inkscape::Util::List; using Inkscape::XML::AttributeRecord; using Inkscape::XML::Node; - - -static void pruneExtendedAttributes( Inkscape::XML::Node *repr ) +/* + * Removes all sodipodi and inkscape elements and attributes from an xml tree. + * used to make plain svg output. + */ +static void pruneExtendedNamespaces( Inkscape::XML::Node *repr ) { if (repr) { if ( repr->type() == Inkscape::XML::ELEMENT_NODE ) { - std::vector<gchar const*> toBeRemoved; + std::vector<gchar const*> attrsRemoved; for ( List<AttributeRecord const> it = repr->attributeList(); it; ++it ) { const gchar* attrName = g_quark_to_string(it->key); if ((strncmp("inkscape:", attrName, 9) == 0) || (strncmp("sodipodi:", attrName, 9) == 0)) { - toBeRemoved.push_back(attrName); + attrsRemoved.push_back(attrName); } } // Can't change the set we're interating over while we are iterating. - for ( std::vector<gchar const*>::iterator it = toBeRemoved.begin(); it != toBeRemoved.end(); ++it ) { + for ( std::vector<gchar const*>::iterator it = attrsRemoved.begin(); it != attrsRemoved.end(); ++it ) { repr->setAttribute(*it, 0); } } + std::vector<Inkscape::XML::Node *> nodesRemoved; for ( Node *child = repr->firstChild(); child; child = child->next() ) { - pruneExtendedAttributes(child); + if((strncmp("inkscape:", child->name(), 9) == 0) || strncmp("sodipodi:", child->name(), 9) == 0) { + nodesRemoved.push_back(child); + } else { + pruneExtendedNamespaces(child); + } + } + for ( std::vector<Inkscape::XML::Node *>::iterator it = nodesRemoved.begin(); it != nodesRemoved.end(); ++it ) { + repr->removeChild(*it); } } } @@ -229,24 +240,34 @@ Svg::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filena { g_return_if_fail(doc != NULL); g_return_if_fail(filename != NULL); + Inkscape::XML::Document *rdoc = doc->rdoc; bool const exportExtensions = ( !mod->get_id() || !strcmp (mod->get_id(), SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE) || !strcmp (mod->get_id(), SP_MODULE_KEY_OUTPUT_SVGZ_INKSCAPE)); - Inkscape::XML::Document *rdoc = NULL; - Inkscape::XML::Node *repr = NULL; - if (exportExtensions) { - repr = doc->getReprRoot(); - } else { - rdoc = sp_repr_document_new ("svg:svg"); - repr = rdoc->root(); - repr = doc->getRoot()->updateRepr(rdoc, repr, SP_OBJECT_WRITE_BUILD); + if (!exportExtensions) { + // We make a duplicate document so we don't prune the in-use document + // and loose data. Perhaps the user intends to save as inkscape-svg next. + Inkscape::XML::Document *new_rdoc = new Inkscape::XML::SimpleDocument(); + + // Comments and PI nodes are not included in this duplication + // TODO: Move this code into xml/document.h and duplicate rdoc instead of root. + new_rdoc->setAttribute("version", "1.0"); + new_rdoc->setAttribute("standalone", "no"); + + // Get a new xml repr for the svg root node + Inkscape::XML::Node *root = rdoc->root()->duplicate(new_rdoc); + + // Add the duplicated svg node as the document's rdoc + new_rdoc->appendChild(root); + Inkscape::GC::release(root); - pruneExtendedAttributes(repr); + pruneExtendedNamespaces(root); + rdoc = new_rdoc; } - if (!sp_repr_save_rebased_file(repr->document(), filename, SP_SVG_NS_URI, + if (!sp_repr_save_rebased_file(rdoc, filename, SP_SVG_NS_URI, doc->getBase(), filename)) { throw Inkscape::Extension::Output::save_failed(); } diff --git a/src/extension/internal/text_reassemble.c b/src/extension/internal/text_reassemble.c index 810e3f8cc..4dfc49420 100644 --- a/src/extension/internal/text_reassemble.c +++ b/src/extension/internal/text_reassemble.c @@ -67,8 +67,8 @@ Optional compiler switches for development: File: text_reassemble.c -Version: 0.0.14 -Date: 25-MAR-2014 +Version: 0.0.15 +Date: 24-JUL-2014 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu Copyright: 2014 David Mathog and California Institute of Technology (Caltech) @@ -550,7 +550,7 @@ int TR_check_set_vadvance(TR_INFO *tri, int src, int lines){ See if the line to be added is compatible. All text fields in a complex have the same advance, so just set/check the first one. vadvance must be within 1% or do not add a new line */ - if(fabs(1.0 - (tpi->chunks[trec].vadvance/newV) > 0.01)){ + if(fabs(1.0 - (tpi->chunks[trec].vadvance/newV)) > 0.01){ status = 1; } else { /* recalculate the weighted vadvance */ @@ -1820,7 +1820,9 @@ printf("Face idx:%d bbox: xMax/Min:%ld,%ld yMax/Min:%ld,%ld UpEM:%d asc/des:%d,% fasc = ((double) (fsp->face->ascender) )/64.0; fdsc = ((double) (fsp->face->descender))/64.0; - if(tri->load_flags & FT_LOAD_NO_SCALE) xe *= tsp->fs/32.0; + /* originally the denominator was just 32.0, but it broke when units_per_EM wasn't 2048 */ + double fixscale = tsp->fs/(((double) fsp->face->units_per_EM)/64.0); + if(tri->load_flags & FT_LOAD_NO_SCALE) xe *= fixscale; /* now place the rectangle using ALN information */ if( taln & ALIHORI & ALILEFT ){ @@ -1837,11 +1839,11 @@ printf("Face idx:%d bbox: xMax/Min:%ld,%ld yMax/Min:%ld,%ld UpEM:%d asc/des:%d,% } tpi->chunks[current].ldir = tsp->ldir; - if(tri->load_flags & FT_LOAD_NO_SCALE){ - asc *= tsp->fs/32.0; - dsc *= tsp->fs/32.0; - fasc *= tsp->fs/32.0; - fdsc *= tsp->fs/32.0; + if(tri->load_flags & FT_LOAD_NO_SCALE){ + asc *= fixscale; + dsc *= fixscale; + fasc *= fixscale; + fdsc *= fixscale; } diff --git a/src/extension/internal/vsd-input.cpp b/src/extension/internal/vsd-input.cpp index 6fc79237b..9f9bf2651 100644 --- a/src/extension/internal/vsd-input.cpp +++ b/src/extension/internal/vsd-input.cpp @@ -24,7 +24,22 @@ #include <cstring> #include <libvisio/libvisio.h> -#include <libwpd-stream/libwpd-stream.h> + +// TODO: Drop this check when librevenge is widespread. +#if WITH_LIBVISIO01 + #include <librevenge-stream/librevenge-stream.h> + + using librevenge::RVNGString; + using librevenge::RVNGFileStream; + using librevenge::RVNGStringVector; +#else + #include <libwpd-stream/libwpd-stream.h> + + typedef WPXString RVNGString; + typedef WPXFileStream RVNGFileStream; + typedef libvisio::VSDStringVector RVNGStringVector; +#endif + #include <gtkmm/alignment.h> #include <gtkmm/comboboxtext.h> @@ -41,7 +56,7 @@ #include "inkscape.h" #include "util/units.h" -#include "dialogs/dialog-events.h" +#include "ui/dialog-events.h" #include <gtk/gtk.h> #include "ui/widget/spinbutton.h" #include "ui/widget/frame.h" @@ -59,7 +74,7 @@ namespace Internal { class VsdImportDialog : public Gtk::Dialog { public: - VsdImportDialog(const std::vector<WPXString> &vec); + VsdImportDialog(const std::vector<RVNGString> &vec); virtual ~VsdImportDialog(); bool showDialog(); @@ -85,12 +100,12 @@ private: class Gtk::VBox * vbox2; class Gtk::Widget * _previewArea; - const std::vector<WPXString> &_vec; // Document to be imported + const std::vector<RVNGString> &_vec; // Document to be imported unsigned _current_page; // Current selected page int _preview_width, _preview_height; // Size of the preview area }; -VsdImportDialog::VsdImportDialog(const std::vector<WPXString> &vec) +VsdImportDialog::VsdImportDialog(const std::vector<RVNGString> &vec) : _vec(vec), _current_page(1) { int num_pages = _vec.size(); @@ -138,9 +153,15 @@ VsdImportDialog::VsdImportDialog(const std::vector<WPXString> &vec) _labelTotalPages->set_use_markup(false); _labelTotalPages->set_selectable(false); vbox2->pack_start(*_previewArea, Gtk::PACK_SHRINK, 0); +#if WITH_GTKMM_3_0 + this->get_content_area()->set_homogeneous(false); + this->get_content_area()->set_spacing(0); + this->get_content_area()->pack_start(*vbox2); +#else this->get_vbox()->set_homogeneous(false); this->get_vbox()->set_spacing(0); this->get_vbox()->pack_start(*vbox2); +#endif this->set_title(_("Page Selector")); this->set_modal(true); sp_transientize(GTK_WIDGET(this->gobj())); //Make transient @@ -209,14 +230,20 @@ void VsdImportDialog::_setPreviewPage(unsigned page) SPDocument *VsdInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { - WPXFileStream input(uri); + RVNGFileStream input(uri); if (!libvisio::VisioDocument::isSupported(&input)) { return NULL; } - libvisio::VSDStringVector output; + RVNGStringVector output; +#if WITH_LIBVISIO01 + librevenge::RVNGSVGDrawingGenerator generator(output, "svg"); + + if (!libvisio::VisioDocument::parse(&input, &generator)) { +#else if (!libvisio::VisioDocument::generateSVG(&input, output)) { +#endif return NULL; } @@ -224,9 +251,9 @@ SPDocument *VsdInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u return NULL; } - std::vector<WPXString> tmpSVGOutput; + std::vector<RVNGString> tmpSVGOutput; for (unsigned i=0; i<output.size(); ++i) { - WPXString tmpString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); + RVNGString tmpString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); tmpString.append(output[i]); tmpSVGOutput.push_back(tmpString); } diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index ef95dbe45..72c1c8bd3 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -33,9 +33,9 @@ #include <stdint.h> #include <libuemf/symbol_convert.h> -#include "sp-root.h" +#include "document.h" +#include "sp-root.h" // even though it is included indirectly by wmf-inout.h #include "sp-path.h" -#include "style.h" #include "print.h" #include "extension/system.h" #include "extension/print.h" @@ -44,13 +44,10 @@ #include "extension/output.h" #include "display/drawing.h" #include "display/drawing-item.h" -#include "util/units.h" #include "clear-n_.h" -#include "document.h" -#include "shape-editor.h" -#include "sp-namedview.h" -#include "document-undo.h" -#include "inkscape.h" +#include "svg/svg.h" +#include "util/units.h" // even though it is included indirectly by wmf-inout.h +#include "inkscape.h" // even though it is included indirectly by wmf-inout.h #include "wmf-inout.h" @@ -67,7 +64,6 @@ namespace Extension { namespace Internal { -static U_RECT16 rc_old; static bool clipset = false; static uint32_t BLTmode=0; @@ -251,54 +247,54 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hpathname); - *(d->defs) += "\n"; + d->defs += "\n"; switch(hatchType){ case U_HS_HORIZONTAL: - *(d->defs) += " <path id=\""; - *(d->defs) += hpathname; - *(d->defs) += "\" d=\"M 0 0 6 0\" style=\"fill:none;stroke:#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\" />\n"; + d->defs += " <path id=\""; + d->defs += hpathname; + d->defs += "\" d=\"M 0 0 6 0\" style=\"fill:none;stroke:#"; + d->defs += tmpcolor; + d->defs += "\" />\n"; break; case U_HS_VERTICAL: - *(d->defs) += " <path id=\""; - *(d->defs) += hpathname; - *(d->defs) += "\" d=\"M 0 0 0 6\" style=\"fill:none;stroke:#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\" />\n"; + d->defs += " <path id=\""; + d->defs += hpathname; + d->defs += "\" d=\"M 0 0 0 6\" style=\"fill:none;stroke:#"; + d->defs += tmpcolor; + d->defs += "\" />\n"; break; case U_HS_FDIAGONAL: - *(d->defs) += " <line id=\"sub"; - *(d->defs) += hpathname; - *(d->defs) += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\"/>\n"; + d->defs += " <line id=\"sub"; + d->defs += hpathname; + d->defs += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; + d->defs += tmpcolor; + d->defs += "\"/>\n"; break; case U_HS_BDIAGONAL: - *(d->defs) += " <line id=\"sub"; - *(d->defs) += hpathname; - *(d->defs) += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\"/>\n"; + d->defs += " <line id=\"sub"; + d->defs += hpathname; + d->defs += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; + d->defs += tmpcolor; + d->defs += "\"/>\n"; break; case U_HS_CROSS: - *(d->defs) += " <path id=\""; - *(d->defs) += hpathname; - *(d->defs) += "\" d=\"M 0 0 6 0 M 0 0 0 6\" style=\"fill:none;stroke:#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\" />\n"; + d->defs += " <path id=\""; + d->defs += hpathname; + d->defs += "\" d=\"M 0 0 6 0 M 0 0 0 6\" style=\"fill:none;stroke:#"; + d->defs += tmpcolor; + d->defs += "\" />\n"; break; case U_HS_DIAGCROSS: - *(d->defs) += " <line id=\"subfd"; - *(d->defs) += hpathname; - *(d->defs) += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\"/>\n"; - *(d->defs) += " <line id=\"subbd"; - *(d->defs) += hpathname; - *(d->defs) += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; - *(d->defs) += tmpcolor; - *(d->defs) += "\"/>\n"; + d->defs += " <line id=\"subfd"; + d->defs += hpathname; + d->defs += "\" x1=\"-1\" y1=\"-1\" x2=\"7\" y2=\"7\" stroke=\"#"; + d->defs += tmpcolor; + d->defs += "\"/>\n"; + d->defs += " <line id=\"subbd"; + d->defs += hpathname; + d->defs += "\" x1=\"-1\" y1=\"7\" x2=\"7\" y2=\"-1\" stroke=\"#"; + d->defs += tmpcolor; + d->defs += "\"/>\n"; break; case U_HS_SOLIDCLR: case U_HS_DITHEREDCLR: @@ -307,12 +303,12 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat case U_HS_SOLIDBKCLR: case U_HS_DITHEREDBKCLR: default: - *(d->defs) += " <path id=\""; - *(d->defs) += hpathname; - *(d->defs) += "\" d=\"M 0 0 6 0 6 6 0 6 z\" style=\"fill:#"; - *(d->defs) += tmpcolor; - *(d->defs) += ";stroke:none"; - *(d->defs) += "\" />\n"; + d->defs += " <path id=\""; + d->defs += hpathname; + d->defs += "\" d=\"M 0 0 6 0 6 6 0 6 z\" style=\"fill:#"; + d->defs += tmpcolor; + d->defs += ";stroke:none"; + d->defs += "\" />\n"; break; } } @@ -374,12 +370,12 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(!idx){ // add it if not already present if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hatchname); - *(d->defs) += "\n"; - *(d->defs) += " <pattern id=\""; - *(d->defs) += hatchname; - *(d->defs) += "\" xlink:href=\"#WMFhbasepattern\">\n"; - *(d->defs) += refpath; - *(d->defs) += " </pattern>\n"; + d->defs += "\n"; + d->defs += " <pattern id=\""; + d->defs += hatchname; + d->defs += "\" xlink:href=\"#WMFhbasepattern\">\n"; + d->defs += refpath; + d->defs += " </pattern>\n"; idx = d->hatches.count; } } @@ -392,12 +388,12 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hbkname); - *(d->defs) += "\n"; - *(d->defs) += " <rect id=\""; - *(d->defs) += hbkname; - *(d->defs) += "\" x=\"0\" y=\"0\" width=\"6\" height=\"6\" fill=\"#"; - *(d->defs) += bkcolor; - *(d->defs) += "\" />\n"; + d->defs += "\n"; + d->defs += " <rect id=\""; + d->defs += hbkname; + d->defs += "\" x=\"0\" y=\"0\" width=\"6\" height=\"6\" fill=\"#"; + d->defs += bkcolor; + d->defs += "\" />\n"; } // this is the pattern, its name will show up in Inkscape's pattern selector @@ -406,15 +402,15 @@ uint32_t Wmf::add_hatch(PWMF_CALLBACK_DATA d, uint32_t hatchType, U_COLORREF hat if(!idx){ // add it if not already present if(d->hatches.count == d->hatches.size){ enlarge_hatches(d); } d->hatches.strings[d->hatches.count++]=strdup(hatchname); - *(d->defs) += "\n"; - *(d->defs) += " <pattern id=\""; - *(d->defs) += hatchname; - *(d->defs) += "\" xlink:href=\"#WMFhbasepattern\">\n"; - *(d->defs) += " <use xlink:href=\"#"; - *(d->defs) += hbkname; - *(d->defs) += "\" />\n"; - *(d->defs) += refpath; - *(d->defs) += " </pattern>\n"; + d->defs += "\n"; + d->defs += " <pattern id=\""; + d->defs += hatchname; + d->defs += "\" xlink:href=\"#WMFhbasepattern\">\n"; + d->defs += " <use xlink:href=\"#"; + d->defs += hbkname; + d->defs += "\" />\n"; + d->defs += refpath; + d->defs += " </pattern>\n"; idx = d->hatches.count; } } @@ -503,35 +499,35 @@ uint32_t Wmf::add_dib_image(PWMF_CALLBACK_DATA d, const char *dib, uint32_t iUsa sprintf(imagename,"WMFimage%d",idx++); sprintf(xywh," x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" ",width,height); // reuse this buffer - *(d->defs) += "\n"; - *(d->defs) += " <image id=\""; - *(d->defs) += imagename; - *(d->defs) += "\"\n "; - *(d->defs) += xywh; - *(d->defs) += "\n"; - if(dibparams == U_BI_JPEG){ *(d->defs) += " xlink:href=\"data:image/jpeg;base64,"; } - else { *(d->defs) += " xlink:href=\"data:image/png;base64,"; } - *(d->defs) += base64String; - *(d->defs) += "\"\n"; - *(d->defs) += " preserveAspectRatio=\"none\"\n"; - *(d->defs) += " />\n"; - - - *(d->defs) += "\n"; - *(d->defs) += " <pattern id=\""; - *(d->defs) += imagename; - *(d->defs) += "_ref\"\n "; - *(d->defs) += xywh; - *(d->defs) += "\n patternUnits=\"userSpaceOnUse\""; - *(d->defs) += " >\n"; - *(d->defs) += " <use id=\""; - *(d->defs) += imagename; - *(d->defs) += "_ign\" "; - *(d->defs) += " xlink:href=\"#"; - *(d->defs) += imagename; - *(d->defs) += "\" />\n"; - *(d->defs) += " "; - *(d->defs) += " </pattern>\n"; + d->defs += "\n"; + d->defs += " <image id=\""; + d->defs += imagename; + d->defs += "\"\n "; + d->defs += xywh; + d->defs += "\n"; + if(dibparams == U_BI_JPEG){ d->defs += " xlink:href=\"data:image/jpeg;base64,"; } + else { d->defs += " xlink:href=\"data:image/png;base64,"; } + d->defs += base64String; + d->defs += "\"\n"; + d->defs += " preserveAspectRatio=\"none\"\n"; + d->defs += " />\n"; + + + d->defs += "\n"; + d->defs += " <pattern id=\""; + d->defs += imagename; + d->defs += "_ref\"\n "; + d->defs += xywh; + d->defs += "\n patternUnits=\"userSpaceOnUse\""; + d->defs += " >\n"; + d->defs += " <use id=\""; + d->defs += imagename; + d->defs += "_ign\" "; + d->defs += " xlink:href=\"#"; + d->defs += imagename; + d->defs += "\" />\n"; + d->defs += " "; + d->defs += " </pattern>\n"; } g_free(base64String); //wait until this point to free because it might be a duplicate image return(idx-1); @@ -599,38 +595,99 @@ uint32_t Wmf::add_bm16_image(PWMF_CALLBACK_DATA d, U_BITMAP16 Bm16, const char * sprintf(imagename,"WMFimage%d",idx++); sprintf(xywh," x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" ",width,height); // reuse this buffer - *(d->defs) += "\n"; - *(d->defs) += " <image id=\""; - *(d->defs) += imagename; - *(d->defs) += "\"\n "; - *(d->defs) += xywh; - *(d->defs) += "\n"; - *(d->defs) += " xlink:href=\"data:image/png;base64,"; - *(d->defs) += base64String; - *(d->defs) += "\"\n"; - *(d->defs) += " preserveAspectRatio=\"none\"\n"; - *(d->defs) += " />\n"; - - - *(d->defs) += "\n"; - *(d->defs) += " <pattern id=\""; - *(d->defs) += imagename; - *(d->defs) += "_ref\"\n "; - *(d->defs) += xywh; - *(d->defs) += "\n patternUnits=\"userSpaceOnUse\""; - *(d->defs) += " >\n"; - *(d->defs) += " <use id=\""; - *(d->defs) += imagename; - *(d->defs) += "_ign\" "; - *(d->defs) += " xlink:href=\"#"; - *(d->defs) += imagename; - *(d->defs) += "\" />\n"; - *(d->defs) += " </pattern>\n"; + d->defs += "\n"; + d->defs += " <image id=\""; + d->defs += imagename; + d->defs += "\"\n "; + d->defs += xywh; + d->defs += "\n"; + d->defs += " xlink:href=\"data:image/png;base64,"; + d->defs += base64String; + d->defs += "\"\n"; + d->defs += " preserveAspectRatio=\"none\"\n"; + d->defs += " />\n"; + + + d->defs += "\n"; + d->defs += " <pattern id=\""; + d->defs += imagename; + d->defs += "_ref\"\n "; + d->defs += xywh; + d->defs += "\n patternUnits=\"userSpaceOnUse\""; + d->defs += " >\n"; + d->defs += " <use id=\""; + d->defs += imagename; + d->defs += "_ign\" "; + d->defs += " xlink:href=\"#"; + d->defs += imagename; + d->defs += "\" />\n"; + d->defs += " </pattern>\n"; } g_free(base64String); //wait until this point to free because it might be a duplicate image return(idx-1); } +/* Add another 100 blank slots to the clips array. +*/ +void Wmf::enlarge_clips(PWMF_CALLBACK_DATA d){ + d->clips.size += 100; + d->clips.strings = (char **) realloc(d->clips.strings,d->clips.size * sizeof(char *)); +} + +/* See if the pattern name is already in the list. If it is return its position (1->n, not 1-n-1) +*/ +int Wmf::in_clips(PWMF_CALLBACK_DATA d, const char *test){ + int i; + for(i=0; i<d->clips.count; i++){ + if(strcmp(test,d->clips.strings[i])==0)return(i+1); + } + return(0); +} + +/* (Conditionally) add a clip. + If a matching clip already exists nothing happens + If one does exist it is added to the clips list, entered into <defs>. +*/ +void Wmf::add_clips(PWMF_CALLBACK_DATA d, const char *clippath, unsigned int logic){ + int op = combine_ops_to_livarot(logic); + Geom::PathVector combined_vect; + char *combined = NULL; + if (op >= 0 && d->dc[d->level].clip_id) { + unsigned int real_idx = d->dc[d->level].clip_id - 1; + Geom::PathVector old_vect = sp_svg_read_pathv(d->clips.strings[real_idx]); + Geom::PathVector new_vect = sp_svg_read_pathv(clippath); + combined_vect = sp_pathvector_boolop(new_vect, old_vect, (bool_op) op , (FillRule) fill_oddEven, (FillRule) fill_oddEven); + combined = sp_svg_write_path(combined_vect); + } + else { + combined = strdup(clippath); // COPY operation, erases everything and starts a new one + } + + uint32_t idx = in_clips(d, combined); + if(!idx){ // add clip if not already present + if(d->clips.count == d->clips.size){ enlarge_clips(d); } + d->clips.strings[d->clips.count++]=strdup(combined); + d->dc[d->level].clip_id = d->clips.count; // one more than the slot where it is actually stored + SVGOStringStream tmp_clippath; + tmp_clippath << "\n<clipPath"; + tmp_clippath << "\n\tclipPathUnits=\"userSpaceOnUse\" "; + tmp_clippath << "\n\tid=\"clipWmfPath" << d->dc[d->level].clip_id << "\""; + tmp_clippath << " >"; + tmp_clippath << "\n\t<path d=\""; + tmp_clippath << combined; + tmp_clippath << "\""; + tmp_clippath << "\n\t/>"; + tmp_clippath << "\n</clipPath>"; + d->outdef += tmp_clippath.str().c_str(); + } + else { + d->dc[d->level].clip_id = idx; + } + free(combined); +} + + + void Wmf::output_style(PWMF_CALLBACK_DATA d) { @@ -714,8 +771,8 @@ Wmf::output_style(PWMF_CALLBACK_DATA d) // tmp_id << "\n\tid=\"" << (d->id++) << "\""; -// *(d->outsvg) += tmp_id.str().c_str(); - *(d->outsvg) += "\n\tstyle=\""; +// d->outsvg += tmp_id.str().c_str(); + d->outsvg += "\n\tstyle=\""; if (!d->dc[d->level].fill_set || ( d->mask & U_DRAW_NOFILL)) { // nofill are lines and arcs tmp_style << "fill:none;"; } else { @@ -838,11 +895,10 @@ Wmf::output_style(PWMF_CALLBACK_DATA d) tmp_style << "stroke-opacity:1;"; } tmp_style << "\" "; - if (clipset) - tmp_style << "\n\tclip-path=\"url(#clipWmfPath" << d->id << ")\" "; - clipset = false; + if (d->dc[d->level].clip_id) + tmp_style << "\n\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\" "; - *(d->outsvg) += tmp_style.str().c_str(); + d->outsvg += tmp_style.str().c_str(); } @@ -1326,8 +1382,8 @@ void Wmf::common_dib_to_image(PWMF_CALLBACK_DATA d, const char *dib, tmp_image << " preserveAspectRatio=\"none\"\n"; tmp_image << "/> \n"; - *(d->outsvg) += tmp_image.str().c_str(); - *(d->path) = ""; + d->outsvg += tmp_image.str().c_str(); + d->path = ""; } /** @@ -1418,8 +1474,8 @@ void Wmf::common_bm16_to_image(PWMF_CALLBACK_DATA d, U_BITMAP16 Bm16, const char tmp_image << " preserveAspectRatio=\"none\"\n"; tmp_image << "/> \n"; - *(d->outsvg) += tmp_image.str().c_str(); - *(d->path) = ""; + d->outsvg += tmp_image.str().c_str(); + d->path = ""; } /** @@ -1579,7 +1635,7 @@ int Wmf::myMetaFileProc(const char *contents, unsigned int length, PWMF_CALLBACK d->dc[0].style.stroke_width.value = pix_to_abs_size( d, 1 ); // This could not be set until the size of the WMF was known dbg_str << "<!-- U_WMR_HEADER -->\n"; - *(d->outdef) += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; + d->outdef += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; SVGOStringStream tmp_outdef; tmp_outdef << "<svg\n"; @@ -1592,8 +1648,8 @@ int Wmf::myMetaFileProc(const char *contents, unsigned int length, PWMF_CALLBACK tmp_outdef << " width=\"" << Inkscape::Util::Quantity::convert(d->PixelsOutX, "px", "mm") << "mm\"\n" << " height=\"" << Inkscape::Util::Quantity::convert(d->PixelsOutY, "px", "mm") << "mm\">\n"; - *(d->outdef) += tmp_outdef.str().c_str(); - *(d->outdef) += "<defs>"; // temporary end of header + d->outdef += tmp_outdef.str().c_str(); + d->outdef += "<defs>"; // temporary end of header // d->defs holds any defines which are read in. @@ -1633,11 +1689,19 @@ int Wmf::myMetaFileProc(const char *contents, unsigned int length, PWMF_CALLBACK // next record is valid type and forces pending text to be drawn immediately if ((d->dc[d->level].dirty & DIRTY_TEXT) || ((wmr_mask != U_WMR_INVALID) && (wmr_mask & U_DRAW_TEXT) && d->tri->dirty)){ TR_layout_analyze(d->tri); + if (d->dc[d->level].clip_id){ + SVGOStringStream tmp_clip; + tmp_clip << "\n<g\n\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\"\n>"; + d->outsvg += tmp_clip.str().c_str(); + } TR_layout_2_svg(d->tri); SVGOStringStream ts; ts << d->tri->out; - *(d->outsvg) += ts.str().c_str(); + d->outsvg += ts.str().c_str(); d->tri = trinfo_clear(d->tri); + if (d->dc[d->level].clip_id){ + d->outsvg += "\n</g>\n"; + } } if(d->dc[d->level].dirty){ //Apply the delayed background changes, clear the flag d->dc[d->level].bkMode = tbkMode; @@ -1688,13 +1752,13 @@ std::cout << "BEFORE DRAW" ) ){ // std::cout << "PATH DRAW at TOP <<+++++++++++++++++++++++++++++++++++++" << std::endl; - *(d->outsvg) += " <path "; // this is the ONLY place <path should be used!!!! + d->outsvg += " <path "; // this is the ONLY place <path should be used!!!! output_style(d); - *(d->outsvg) += "\n\t"; - *(d->outsvg) += "\n\td=\""; // this is the ONLY place d=" should be used!!!! - *(d->outsvg) += *(d->path); - *(d->outsvg) += " \" /> \n"; - *(d->path) = ""; //reset the path + d->outsvg += "\n\t"; + d->outsvg += "\n\td=\""; // this is the ONLY place d=" should be used!!!! + d->outsvg += d->path; + d->outsvg += " \" /> \n"; + d->path = ""; //reset the path // reset the flags d->mask = 0; d->drawtype = 0; @@ -1706,7 +1770,7 @@ std::cout << "BEFORE DRAW" { dbg_str << "<!-- U_WMR_EOF -->\n"; - *(d->outsvg) = *(d->outdef) + *(d->defs) + "\n</defs>\n\n" + *(d->outsvg) + "</svg>\n"; + d->outsvg = d->outdef + d->defs + "\n</defs>\n\n" + d->outsvg + "</svg>\n"; OK=0; break; } @@ -1918,34 +1982,51 @@ std::cout << "BEFORE DRAW" "\n\tM " << pix_to_xy( d, pt16.x, pt16.y ) << " "; break; } - case U_WMR_EXCLUDECLIPRECT: dbg_str << "<!-- U_WMR_EXCLUDECLIPRECT -->\n"; break; + case U_WMR_EXCLUDECLIPRECT: + { + dbg_str << "<!-- U_WMR_EXCLUDECLIPRECT -->\n"; + + U_RECT16 rc; + nSize = U_WMREXCLUDECLIPRECT_get(contents, &rc); + + SVGOStringStream tmp_path; + float faraway = 10000000; // hopefully well outside any real drawing! + //outer rect, clockwise + tmp_path << "M " << faraway << "," << faraway << " "; + tmp_path << "L " << faraway << "," << -faraway << " "; + tmp_path << "L " << -faraway << "," << -faraway << " "; + tmp_path << "L " << -faraway << "," << faraway << " "; + tmp_path << "z "; + //inner rect, counterclockwise (sign of Y is reversed) + tmp_path << "M " << pix_to_xy( d, rc.left , rc.top ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.right, rc.top ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.right, rc.bottom ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.left, rc.bottom ) << " "; + tmp_path << "z"; + + add_clips(d, tmp_path.str().c_str(), U_RGN_AND); + + d->path = ""; + d->drawtype = 0; + break; + } case U_WMR_INTERSECTCLIPRECT: { dbg_str << "<!-- U_WMR_INTERSECTCLIPRECT -->\n"; nSize = U_WMRINTERSECTCLIPRECT_get(contents, &rc); - clipset = true; - if ((rc.left == rc_old.left) && (rc.top == rc_old.top) && (rc.right == rc_old.right) && (rc.bottom == rc_old.bottom)) - break; - rc_old = rc; - - double dx = pix_to_x_point( d, rc.left, rc.top ); - double dy = pix_to_y_point( d, rc.left, rc.top ); - double dw = pix_to_abs_size( d, rc.right - rc.left + 1); - double dh = pix_to_abs_size( d, rc.bottom - rc.top + 1); - SVGOStringStream tmp_rectangle; - tmp_rectangle << "\n<clipPath\n\tclipPathUnits=\"userSpaceOnUse\" "; - tmp_rectangle << "\nid=\"clipWmfPath" << ++(d->id) << "\" >"; - tmp_rectangle << "\n<rect "; - tmp_rectangle << "\n x=\"" << dx << "\" "; - tmp_rectangle << "\n y=\"" << dy << "\" "; - tmp_rectangle << "\n width=\"" << dw << "\" "; - tmp_rectangle << "\n height=\"" << dh << "\" />"; - tmp_rectangle << "\n</clipPath>"; + SVGOStringStream tmp_path; + tmp_path << "M " << pix_to_xy( d, rc.left , rc.top ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.right, rc.top ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.right, rc.bottom ) << " "; + tmp_path << "L " << pix_to_xy( d, rc.left, rc.bottom ) << " "; + tmp_path << "z"; + + add_clips(d, tmp_path.str().c_str(), U_RGN_AND); - *(d->outdef) += tmp_rectangle.str().c_str(); - *(d->path) = ""; + d->path = ""; + d->drawtype = 0; break; } case U_WMR_ARC: @@ -1981,8 +2062,8 @@ std::cout << "BEFORE DRAW" double cx = pix_to_x_point( d, (rc.left + rc.right)/2.0, (rc.bottom + rc.top)/2.0 ); double cy = pix_to_y_point( d, (rc.left + rc.right)/2.0, (rc.bottom + rc.top)/2.0 ); - double rx = pix_to_abs_size( d, fabs(rc.right - rc.left )/2.0 ); - double ry = pix_to_abs_size( d, fabs(rc.top - rc.bottom)/2.0 ); + double rx = pix_to_abs_size( d, std::abs(rc.right - rc.left )/2.0 ); + double ry = pix_to_abs_size( d, std::abs(rc.top - rc.bottom)/2.0 ); SVGOStringStream tmp_ellipse; tmp_ellipse << "cx=\"" << cx << "\" "; @@ -1992,12 +2073,12 @@ std::cout << "BEFORE DRAW" d->mask |= wmr_mask; - *(d->outsvg) += " <ellipse "; + d->outsvg += " <ellipse "; output_style(d); - *(d->outsvg) += "\n\t"; - *(d->outsvg) += tmp_ellipse.str().c_str(); - *(d->outsvg) += "/> \n"; - *(d->path) = ""; + d->outsvg += "\n\t"; + d->outsvg += tmp_ellipse.str().c_str(); + d->outsvg += "/> \n"; + d->path = ""; break; } case U_WMR_FLOODFILL: dbg_str << "<!-- U_WMR_EXTFLOODFILL -->\n"; break; @@ -2139,7 +2220,24 @@ std::cout << "BEFORE DRAW" break; } case U_WMR_SETPIXEL: dbg_str << "<!-- U_WMR_SETPIXEL -->\n"; break; - case U_WMR_OFFSETCLIPRGN: dbg_str << "<!-- U_WMR_OFFSETCLIPRGN/POLYLINE -->\n"; break; + case U_WMR_OFFSETCLIPRGN: + { + dbg_str << "<!-- U_EMR_OFFSETCLIPRGN -->\n"; + U_POINT16 off; + nSize = U_WMROFFSETCLIPRGN_get(contents,&off); + if (d->dc[d->level].clip_id) { // can only offset an existing clipping path + unsigned int real_idx = d->dc[d->level].clip_id - 1; + Geom::PathVector tmp_vect = sp_svg_read_pathv(d->clips.strings[real_idx]); + double ox = pix_to_x_point(d, off.x, off.y) - pix_to_x_point(d, 0, 0); // take into account all active transforms + double oy = pix_to_y_point(d, off.x, off.y) - pix_to_y_point(d, 0, 0); + Geom::Affine tf = Geom::Translate(ox,oy); + tmp_vect *= tf; + char *tmp_path = sp_svg_write_path(tmp_vect); + add_clips(d, tmp_path, U_RGN_COPY); + free(tmp_path); + } + break; + } // U_WMR_TEXTOUT should be here, but has been moved down to merge with U_WMR_EXTTEXTOUT case U_WMR_BITBLT: { @@ -2501,11 +2599,19 @@ std::cout << "BEFORE DRAW" status = trinfo_load_textrec(d->tri, &tsp, tsp.ori,TR_EMFBOT); // ori is actually escapement if(status==-1){ // change of escapement, emit what we have and reset TR_layout_analyze(d->tri); + if (d->dc[d->level].clip_id){ + SVGOStringStream tmp_clip; + tmp_clip << "\n<g\n\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\"\n>"; + d->outsvg += tmp_clip.str().c_str(); + } TR_layout_2_svg(d->tri); ts << d->tri->out; - *(d->outsvg) += ts.str().c_str(); + d->outsvg += ts.str().c_str(); d->tri = trinfo_clear(d->tri); (void) trinfo_load_textrec(d->tri, &tsp, tsp.ori,TR_EMFBOT); // ignore return status, it must work + if (d->dc[d->level].clip_id){ + d->outsvg += "\n</g>\n"; + } } g_free(escaped_text); @@ -2910,13 +3016,13 @@ std::cout << "BEFORE DRAW" break; } //end of switch // When testing, uncomment the following to place a comment for each processed WMR record in the SVG -// *(d->outsvg) += dbg_str.str().c_str(); - *(d->path) += tmp_path.str().c_str(); +// d->outsvg += dbg_str.str().c_str(); + d->path += tmp_path.str().c_str(); if(!nSize){ OK=0; std::cout << "nSize == 0, oops!!!" << std::endl; } // There was some problem with this record, it is not safe to continue } //end of while // When testing, uncomment the following to show the final SVG derived from the WMF -// std::cout << *(d->outsvg) << std::endl; +// std::cout << d->outsvg << std::endl; (void) U_wmr_properties(U_WMR_INVALID); // force the release of the lookup table memory, returned value is irrelevant return 1; @@ -2927,6 +3033,8 @@ void Wmf::free_wmf_strings(WMF_STRINGS name){ for(int i=0; i< name.count; i++){ free(name.strings[i]); } free(name.strings); } + name.count = 0; + name.size = 0; } SPDocument * @@ -2935,70 +3043,38 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) WMF_CALLBACK_DATA d; - memset(&d, 0, sizeof(WMF_CALLBACK_DATA)); - - for(int i = 0; i < WMF_MAX_DC+1; i++){ // be sure all values and pointers are empty to start with - memset(&(d.dc[i]),0,sizeof(WMF_DEVICE_CONTEXT)); - } - // set default drawing objects, these are active if no object has been selected - d.dc[0].active_pen = -1; // -1 when the default is used instead of a selected object - d.dc[0].active_brush = -1; - d.dc[0].active_font = -1; - // Default font, WMF spec says device can pick whatever it wants. WMF files that do not specify a font are unlikely to look very good! - d.dc[0].font_name = strdup("Arial"); + // Default font, WMF spec says device can pick whatever it wants. + // WMF files that do not specify a font are unlikely to look very good! d.dc[0].style.font_size.computed = 16.0; d.dc[0].style.font_weight.value = SP_CSS_FONT_WEIGHT_400; d.dc[0].style.font_style.value = SP_CSS_FONT_STYLE_NORMAL; d.dc[0].style.text_decoration_line.underline = 0; d.dc[0].style.text_decoration_line.line_through = 0; d.dc[0].style.baseline_shift.value = 0; - d.dc[0].textColor = U_RGB(0, 0, 0); // default foreground color (black) - d.dc[0].bkColor = U_RGB(255, 255, 255); // default background color (white) - d.dc[0].bkMode = U_TRANSPARENT; - d.dc[0].dirty = 0; + // Default pen, WMF files that do not specify a pen are unlikely to look very good! d.dc[0].style.stroke_dasharray.set = 0; d.dc[0].style.stroke_linecap.computed = 2; // U_PS_ENDCAP_SQUARE; d.dc[0].style.stroke_linejoin.computed = 0; // U_PS_JOIN_MITER; - d.dc[0].stroke_set = true; d.dc[0].style.stroke_width.value = 1.0; // will be reset to something reasonable once WMF draying size is known d.dc[0].style.stroke.value.color.set( 0, 0, 0 ); - // Default brush = none, WMF files that do not specify a brush are unlikely to look very good! - d.dc[0].fill_set = false; if (uri == NULL) { return NULL; } - d.outsvg = new Glib::ustring(""); - d.path = new Glib::ustring(""); - d.outdef = new Glib::ustring(""); - d.defs = new Glib::ustring(""); - d.mask = 0; - d.drawtype = 0; - d.arcdir = U_AD_COUNTERCLOCKWISE; - d.dwRop2 = U_R2_COPYPEN; - d.dwRop3 = 0; - d.E2IdirY = 1.0; - d.D2PscaleX = 1.0; - d.D2PscaleY = 1.0; - d.hatches.size = 0; - d.hatches.count = 0; - d.hatches.strings = NULL; - d.images.size = 0; - d.images.count = 0; - d.images.strings = NULL; + d.dc[0].font_name = strdup("Arial"); // Default font, set only on lowest level, it copies up from there WMF spec says device can pick whatever it wants // set up the size default for patterns in defs. This might not be referenced if there are no patterns defined in the drawing. - *(d.defs) += "\n"; - *(d.defs) += " <pattern id=\"WMFhbasepattern\" \n"; - *(d.defs) += " patternUnits=\"userSpaceOnUse\"\n"; - *(d.defs) += " width=\"6\" \n"; - *(d.defs) += " height=\"6\" \n"; - *(d.defs) += " x=\"0\" \n"; - *(d.defs) += " y=\"0\"> \n"; - *(d.defs) += " </pattern> \n"; + d.defs += "\n"; + d.defs += " <pattern id=\"WMFhbasepattern\" \n"; + d.defs += " patternUnits=\"userSpaceOnUse\"\n"; + d.defs += " width=\"6\" \n"; + d.defs += " height=\"6\" \n"; + d.defs += " x=\"0\" \n"; + d.defs += " y=\"0\"> \n"; + d.defs += " </pattern> \n"; size_t length; @@ -3014,16 +3090,13 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) (void) myMetaFileProc(contents,length, &d); free(contents); -// std::cout << "SVG Output: " << std::endl << *(d.outsvg) << std::endl; +// std::cout << "SVG Output: " << std::endl << d.outsvg << std::endl; - SPDocument *doc = SPDocument::createNewDocFromMem(d.outsvg->c_str(), strlen(d.outsvg->c_str()), TRUE); + SPDocument *doc = SPDocument::createNewDocFromMem(d.outsvg.c_str(), strlen(d.outsvg.c_str()), TRUE); - delete d.outsvg; - delete d.path; - delete d.outdef; - delete d.defs; free_wmf_strings(d.hatches); free_wmf_strings(d.images); + free_wmf_strings(d.clips); if (d.wmf_obj) { int i; @@ -3034,45 +3107,13 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) d.dc[0].style.stroke_dasharray.values.clear(); - for(int i=0; i<=d.level;i++){ + for(int i=0; i<=WMF_MAX_DC; i++){ if(d.dc[i].font_name)free(d.dc[i].font_name); } d.tri = trinfo_release_except_FC(d.tri); - // Set viewBox if it doesn't exist - if (doc && !doc->getRoot()->viewBox_set) { - bool saved = Inkscape::DocumentUndo::getUndoSensitive(doc); - Inkscape::DocumentUndo::setUndoSensitive(doc, false); - - doc->ensureUpToDate(); - - // Set document unit - Inkscape::XML::Node *repr = sp_document_namedview(doc, 0)->getRepr(); - Inkscape::SVGOStringStream os; - Inkscape::Util::Unit const* doc_unit = doc->getWidth().unit; - os << doc_unit->abbr; - repr->setAttribute("inkscape:document-units", os.str().c_str()); - - // Set viewBox - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc_unit), doc->getHeight().value(doc_unit))); - doc->ensureUpToDate(); - - // Scale and translate objects - double scale = Inkscape::Util::Quantity::convert(1, "px", doc_unit); - ShapeEditor::blockSetItem(true); - double dh; - if(SP_ACTIVE_DOCUMENT){ // for file menu open or import, or paste from clipboard - dh = SP_ACTIVE_DOCUMENT->getHeight().value("px"); - } - else { // for open via --file on command line - dh = doc->getHeight().value("px"); - } - doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, dh)); - ShapeEditor::blockSetItem(false); - - Inkscape::DocumentUndo::setUndoSensitive(doc, saved); - } + setViewBoxIfMissing(doc); return doc; } diff --git a/src/extension/internal/wmf-inout.h b/src/extension/internal/wmf-inout.h index 3d23ca749..5a0a760dd 100644 --- a/src/extension/internal/wmf-inout.h +++ b/src/extension/internal/wmf-inout.h @@ -26,21 +26,57 @@ namespace Internal { #define DIRTY_FILL 0x02 #define DIRTY_STROKE 0x04 // not used currently -typedef struct { +typedef struct wmf_object { + wmf_object() : + type(0), + level(0), + record(NULL) + {}; int type; int level; char *record; } WMF_OBJECT, *PWMF_OBJECT; -typedef struct { +typedef struct wmf_strings { + wmf_strings() : + size(0), + count(0), + strings(NULL) + {}; int size; // number of slots allocated in strings int count; // number of slots used in strings char **strings; // place to store strings } WMF_STRINGS, *PWMF_STRINGS; typedef struct wmf_device_context { - struct SPStyle style; + wmf_device_context() : + // SPStyle: class with constructor + font_name(NULL), + clip_id(0), + stroke_set(false), stroke_mode(0), stroke_idx(0), stroke_recidx(0), + fill_set(false), fill_mode(0), fill_idx(0), fill_recidx(0), + dirty(0), + active_pen(-1), active_brush(-1), active_font(-1), // -1 when the default is used + // sizeWnd, sizeView, winorg, vieworg, + ScaleInX(0), ScaleInY(0), + ScaleOutX(0), ScaleOutY(0), + bkMode(U_TRANSPARENT), + // bkColor, textColor + textAlign(0) + // worldTransform, cur + { + font_name = NULL; + sizeWnd = point16_set( 0.0, 0.0 ); + sizeView = point16_set( 0.0, 0.0 ); + winorg = point16_set( 0.0, 0.0 ); + vieworg = point16_set( 0.0, 0.0 ); + bkColor = U_RGB(255, 255, 255); // default foreground color (white) + textColor = U_RGB(0, 0, 0); // default foreground color (black) + cur = point16_set( 0.0, 0.0 ); + }; + SPStyle style; char *font_name; + int clip_id; // 0 if none, else 1 + index into clips bool stroke_set; int stroke_mode; // enumeration from drawmode, not used if fill_set is not True int stroke_idx; // used with DRAW_PATTERN and DRAW_IMAGE to return the appropriate fill @@ -74,11 +110,32 @@ typedef struct wmf_device_context { // this fixes it, so some confusion between this struct and the one in emf-inout??? //typedef struct wmf_callback_data { // as does this -typedef struct { - Glib::ustring *outsvg; - Glib::ustring *path; - Glib::ustring *outdef; - Glib::ustring *defs; +typedef struct wmf_callback_data { + + wmf_callback_data() : + // dc: array, structure w/ constructor + level(0), + E2IdirY(1.0), + D2PscaleX(1.0), D2PscaleY(1.0), + PixelsInX(0), PixelsInY(0), + PixelsOutX(0), PixelsOutY(0), + ulCornerInX(0), ulCornerInY(0), + ulCornerOutX(0), ulCornerOutY(0), + mask(0), + arcdir(U_AD_COUNTERCLOCKWISE), + dwRop2(U_R2_COPYPEN), dwRop3(0), + id(0), drawtype(0), + // hatches, images, gradients, struct w/ constructor + tri(NULL), + n_obj(0), + low_water(0) + //wmf_obj + {}; + + Glib::ustring outsvg; + Glib::ustring path; + Glib::ustring outdef; + Glib::ustring defs; WMF_DEVICE_CONTEXT dc[WMF_MAX_DC+1]; // FIXME: This should be dynamic.. int level; @@ -100,6 +157,7 @@ typedef struct { // both of these end up in <defs> under the names shown here. These structures allow duplicates to be avoided. WMF_STRINGS hatches; // hold pattern names, all like WMFhatch#_$$$$$$ where # is the WMF hatch code and $$$$$$ is the color WMF_STRINGS images; // hold images, all like Image#, where # is the slot the image lives. + WMF_STRINGS clips; // hold clipping paths, referred to be the slot where the clipping path lives TR_INFO *tri; // Text Reassembly data structure @@ -140,6 +198,11 @@ protected: static int in_images(PWMF_CALLBACK_DATA d, char *test); static uint32_t add_dib_image(PWMF_CALLBACK_DATA d, const char *dib, uint32_t iUsage); static uint32_t add_bm16_image(PWMF_CALLBACK_DATA d, U_BITMAP16 Bm16, const char *px); + + static void enlarge_clips(PWMF_CALLBACK_DATA d); + static int in_clips(PWMF_CALLBACK_DATA d, const char *test); + static void add_clips(PWMF_CALLBACK_DATA d, const char *clippath, unsigned int logic); + static void output_style(PWMF_CALLBACK_DATA d); static double _pix_x_to_point(PWMF_CALLBACK_DATA d, double px); static double _pix_y_to_point(PWMF_CALLBACK_DATA d, double py); diff --git a/src/extension/internal/wmf-print.cpp b/src/extension/internal/wmf-print.cpp index 5a552ad83..e5ff34009 100644 --- a/src/extension/internal/wmf-print.cpp +++ b/src/extension/internal/wmf-print.cpp @@ -1387,7 +1387,7 @@ unsigned int PrintWmf::text(Inkscape::Extension::Print * /*mod*/, char const *te _lookup_ppt_fontfix("Convert To Wingdings", params); break; default: //also CVTNON - _lookup_ppt_fontfix(style->text->font_family.value, params); + _lookup_ppt_fontfix(style->font_family.value, params); break; } if (params.f2 != 0 || params.f3 != 0) { @@ -1396,7 +1396,7 @@ unsigned int PrintWmf::text(Inkscape::Extension::Print * /*mod*/, char const *te fix90n = 1; //assume vertical rot = (double)(((int) round(rot)) - irem); rotb = rot * M_PI / 1800.0; - if (abs(rot) == 900.0) { + if (std::abs(rot) == 900.0) { fix90n = 2; } } @@ -1416,7 +1416,7 @@ unsigned int PrintWmf::text(Inkscape::Extension::Print * /*mod*/, char const *te // of the special fonts. char *facename; if (!newfont) { - facename = U_Utf8ToLatin1(style->text->font_family.value, 0, NULL); + facename = U_Utf8ToLatin1(style->font_family.value, 0, NULL); } else { facename = U_Utf8ToLatin1(FontName(newfont), 0, NULL); } diff --git a/src/extension/internal/wmf-print.h b/src/extension/internal/wmf-print.h index 1e5d4c323..e4cf19184 100644 --- a/src/extension/internal/wmf-print.h +++ b/src/extension/internal/wmf-print.h @@ -28,7 +28,7 @@ namespace Internal { class PrintWmf : public PrintMetafile { - uint32_t hbrush, hpen, hpenOld, hbrush_null, hpen_null; + uint32_t hbrush, hpen, hbrush_null, hpen_null; uint32_t hmiterlimit; // used to minimize redundant records that set this unsigned int print_pathv (Geom::PathVector const &pathv, const Geom::Affine &transform); diff --git a/src/extension/internal/wpg-input.cpp b/src/extension/internal/wpg-input.cpp index 14ff3ec77..12d86a99a 100644 --- a/src/extension/internal/wpg-input.cpp +++ b/src/extension/internal/wpg-input.cpp @@ -52,16 +52,24 @@ #include "util/units.h" #include <cstring> -// Take a guess and fallback to 0.1.x if no configure has run -#if !defined(WITH_LIBWPG01) && !defined(WITH_LIBWPG02) -#define WITH_LIBWPG01 1 +// Take a guess and fallback to 0.2.x if no configure has run +#if !defined(WITH_LIBWPG03) && !defined(WITH_LIBWPG02) +#define WITH_LIBWPG02 1 #endif #include "libwpg/libwpg.h" -#if WITH_LIBWPG01 -#include "libwpg/WPGStreamImplementation.h" -#elif WITH_LIBWPG02 -#include "libwpd-stream/libwpd-stream.h" +#if WITH_LIBWPG03 + #include <librevenge-stream/librevenge-stream.h> + + using librevenge::RVNGString; + using librevenge::RVNGFileStream; + using librevenge::RVNGInputStream; +#else + #include "libwpd-stream/libwpd-stream.h" + + typedef WPXString RVNGString; + typedef WPXFileStream RVNGFileStream; + typedef WPXInputStream RVNGInputStream; #endif using namespace libwpg; @@ -73,17 +81,15 @@ namespace Internal { SPDocument *WpgInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { -#if WITH_LIBWPG01 - WPXInputStream* input = new libwpg::WPGFileStream(uri); -#elif WITH_LIBWPG02 - WPXInputStream* input = new WPXFileStream(uri); -#endif + RVNGInputStream* input = new RVNGFileStream(uri); +#if WITH_LIBWPG03 + if (input->isStructured()) { + RVNGInputStream* olestream = input->getSubStreamByName("PerfectOffice_MAIN"); +#else if (input->isOLEStream()) { -#if WITH_LIBWPG01 - WPXInputStream* olestream = input->getDocumentOLEStream(); -#elif WITH_LIBWPG02 - WPXInputStream* olestream = input->getDocumentOLEStream("PerfectOffice_MAIN"); + RVNGInputStream* olestream = input->getDocumentOLEStream("PerfectOffice_MAIN"); #endif + if (olestream) { delete input; input = olestream; @@ -98,15 +104,24 @@ SPDocument *WpgInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u return NULL; } -#if WITH_LIBWPG01 - libwpg::WPGString output; -#elif WITH_LIBWPG02 - WPXString output; -#endif +#if WITH_LIBWPG03 + librevenge::RVNGStringVector vec; + librevenge::RVNGSVGDrawingGenerator generator(vec, ""); + + if (!libwpg::WPGraphics::parse(input, &generator) || vec.empty() || vec[0].empty()) { + delete input; + return NULL; + } + + RVNGString output("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); + output.append(vec[0]); +#else + RVNGString output; if (!libwpg::WPGraphics::generateSVG(input, output)) { delete input; return NULL; } +#endif //printf("I've got a doc: \n%s", painter.document.c_str()); diff --git a/src/extension/output.h b/src/extension/output.h index c5b1beb45..44a731ca0 100644 --- a/src/extension/output.h +++ b/src/extension/output.h @@ -13,7 +13,6 @@ #ifndef INKSCAPE_EXTENSION_OUTPUT_H__ #define INKSCAPE_EXTENSION_OUTPUT_H__ -#include <gtk/gtk.h> #include "extension.h" class SPDocument; diff --git a/src/extension/param/color.cpp b/src/extension/param/color.cpp index 0a2598c56..5bd70359f 100644 --- a/src/extension/param/color.cpp +++ b/src/extension/param/color.cpp @@ -59,9 +59,10 @@ guint32 ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * return _value; } -ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), - _changeSignal(0) +ParamColor::ParamColor(const gchar *name, const gchar *guitext, const gchar *desc, const Parameter::_scope_t scope, + bool gui_hidden, const gchar *gui_tip, Inkscape::Extension::Extension *ext, + Inkscape::XML::Node *xml) + : Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(0), _changeSignal(0) { const char * defaulthex = NULL; if (xml->firstChild() != NULL) @@ -75,7 +76,8 @@ ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * if (!paramval.empty()) defaulthex = paramval.data(); - _value = atoi(defaulthex); + if (defaulthex) + _value = atoi(defaulthex); } void ParamColor::string(std::string &string) const @@ -87,7 +89,7 @@ void ParamColor::string(std::string &string) const Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * changeSignal ) { - if (_gui_hidden) return NULL; + if (_gui_hidden) return NULL; _changeSignal = new sigc::signal<void>(*changeSignal); Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); diff --git a/src/extension/param/enum.cpp b/src/extension/param/enum.cpp index bb50c06e1..74b2a75ad 100644 --- a/src/extension/param/enum.cpp +++ b/src/extension/param/enum.cpp @@ -41,8 +41,8 @@ namespace Extension { class enumentry { public: enumentry (Glib::ustring &val, Glib::ustring &text) : - value(val), - guitext(text) + value(val), + guitext(text) {} Glib::ustring value; @@ -50,16 +50,19 @@ public: }; -ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _indent(0) +ParamComboBox::ParamComboBox(const gchar *name, const gchar *guitext, const gchar *desc, + const Parameter::_scope_t scope, bool gui_hidden, const gchar *gui_tip, + Inkscape::Extension::Extension *ext, Inkscape::XML::Node *xml) + : Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext) + , _value(NULL) + , _indent(0) + , choices(NULL) { - choices = NULL; - _value = NULL; + const char *xmlval = NULL; // the value stored in XML - // Read XML tree to add enumeration items: - // printf("Extension Constructor: "); if (xml != NULL) { - for (Inkscape::XML::Node *node = xml->firstChild(); node; node = node->next()) { + // Read XML tree to add enumeration items: + for (Inkscape::XML::Node *node = xml->firstChild(); node; node = node->next()) { char const * chname = node->name(); if (!strcmp(chname, INKSCAPE_EXTENSION_NS "item") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_item")) { Glib::ustring newguitext, newvalue; @@ -69,8 +72,8 @@ ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const g } if (contents != NULL) { // don't translate when 'item' but do translate when '_item' - // NOTE: internal extensions use build_from_mem and don't need _item but - // still need to include if are to be localized + // NOTE: internal extensions use build_from_mem and don't need _item but + // still need to include if are to be localized if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_item")) { if (node->attribute("msgctxt") != NULL) { newguitext = g_dpgettext2(NULL, node->attribute("msgctxt"), contents); @@ -95,30 +98,28 @@ ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const g } } } - } - - // Initialize _value with the default value from xml - // for simplicity : default to the contents of the first xml-child - const char * defaultval = NULL; - if (xml->firstChild() && xml->firstChild()->firstChild()) { - defaultval = xml->firstChild()->attribute("value"); - } + + // Initialize _value with the default value from xml + // for simplicity : default to the contents of the first xml-child + if (xml->firstChild() && xml->firstChild()->firstChild()) { + xmlval = xml->firstChild()->attribute("value"); + } - const char * indent = xml->attribute("indent"); - if (indent != NULL) { - _indent = atoi(indent) * 12; + const char *indent = xml->attribute("indent"); + if (indent != NULL) { + _indent = atoi(indent) * 12; + } } gchar * pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); + Glib::ustring paramval = prefs ? prefs->getString(extension_pref_root + pref_name) : ""; g_free(pref_name); if (!paramval.empty()) { - defaultval = paramval.data(); - } - if (defaultval != NULL) { - _value = g_strdup(defaultval); + _value = g_strdup(paramval.data()); + } else if (xmlval) { + _value = g_strdup(xmlval); } } diff --git a/src/extension/param/notebook.cpp b/src/extension/param/notebook.cpp index 97002e33f..9ec31ca6b 100644 --- a/src/extension/param/notebook.cpp +++ b/src/extension/param/notebook.cpp @@ -214,7 +214,7 @@ Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Nod // printf("Tip: '%s'\n", tip); vbox->pack_start(*widg, false, false, 2); if (tip) { - widg->set_tooltip_text(tip); + widg->set_tooltip_text(_(tip)); } else { widg->set_tooltip_text(""); widg->set_has_tooltip(false); diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index 75d5a40e3..f9515197c 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -122,7 +122,7 @@ ParamRadioButton::ParamRadioButton (const gchar * name, defaultval = (static_cast<optionentry*> (choices->data))->value->c_str(); } - const char * indent = xml->attribute("indent"); + const char *indent = xml ? xml->attribute("indent") : NULL; if (indent != NULL) { _indent = atoi(indent) * 12; } diff --git a/src/extension/prefdialog.cpp b/src/extension/prefdialog.cpp index 1b657f644..0ea15a5cd 100644 --- a/src/extension/prefdialog.cpp +++ b/src/extension/prefdialog.cpp @@ -13,7 +13,7 @@ #include <gtkmm/separator.h> #include <glibmm/i18n.h> -#include "../dialogs/dialog-events.h" +#include "ui/dialog-events.h" #include "xml/repr.h" // Used to get SP_ACTIVE_DESKTOP @@ -90,6 +90,10 @@ PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * co if (_effect != NULL && !_effect->no_live_preview) { if (_param_preview == NULL) { XML::Document * doc = sp_repr_read_mem(live_param_xml, strlen(live_param_xml), NULL); + if (doc == NULL) { + std::cout << "Error encountered loading live parameter XML !!!" << std::endl; + return; + } _param_preview = Parameter::make(doc->root(), _effect); } @@ -212,6 +216,9 @@ PrefDialog::preview_toggle (void) { void PrefDialog::param_change (void) { if (_exEnv != NULL) { + if (!_effect->loaded()) { + _effect->set_state(Extension::STATE_LOADED); + } _timersig.disconnect(); _timersig = Glib::signal_timeout().connect(sigc::mem_fun(this, &PrefDialog::param_timer_expire), 250, /* ms */ diff --git a/src/extension/system.cpp b/src/extension/system.cpp index c244d9c16..5225f11ee 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -20,7 +20,7 @@ # include <config.h> #endif -#include <interface.h> +#include "ui/interface.h" #include <unistd.h> #include <glibmm/miscutils.h> @@ -556,7 +556,7 @@ build_from_file(gchar const *filename) } /** - * \return The module created + * \return The module created, or NULL if buffer is invalid * \brief This function creates a module from a buffer holding an * XML description. * \param buffer The buffer holding the XML description of the module. @@ -568,6 +568,7 @@ Extension * build_from_mem(gchar const *buffer, Implementation::Implementation *in_imp) { Inkscape::XML::Document *doc = sp_repr_read_mem(buffer, strlen(buffer), INKSCAPE_EXTENSION_URI); + g_return_val_if_fail(doc != NULL, NULL); Extension *ext = build_from_reprdoc(doc, in_imp); Inkscape::GC::release(doc); return ext; |
