diff options
Diffstat (limited to 'src/extension')
24 files changed, 729 insertions, 343 deletions
diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 435e347d0..513ec2f5c 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -968,10 +968,7 @@ document_interface_save_as (DocumentInterface *doc_interface, { // FIXME: Isn't there a verb we can use for this instead? SPDocument * doc = doc_interface->target.getDocument(); - #ifdef WITH_GNOME_VFS - const Glib::ustring file(filename); - return file_save_remote(doc, file, NULL, TRUE, TRUE); - #endif + if (!doc || strlen(filename)<1) { //Safety check return false; } diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index f1b328f05..d9ea5eca7 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -64,7 +64,6 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat id = NULL; name = NULL; _state = STATE_UNLOADED; - parameters = NULL; if (in_imp == NULL) { imp = new Implementation::Implementation(); @@ -97,7 +96,7 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat Parameter * param; param = Parameter::make(child_repr, this); if (param != NULL) - parameters = g_slist_append(parameters, param); + parameters.push_back(param); } /* param || _param */ if (!strcmp(chname, "dependency")) { _deps.push_back(new Dependency(child_repr)); @@ -146,12 +145,9 @@ Extension::~Extension (void) /** \todo Need to do parameters here */ // delete parameters: - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for (auto param:parameters) { delete param; } - g_slist_free(parameters); - for (unsigned int i = 0 ; i < _deps.size(); i++) { delete _deps[i]; @@ -402,14 +398,11 @@ Parameter *Extension::get_param(gchar const *name) if (name == NULL) { throw Extension::param_not_exist(); } - if (this->parameters == NULL) { - // the list of parameters is empty + if (this->parameters.empty()) { throw Extension::param_not_exist(); } - for (GSList * list = this->parameters; list != NULL; list = -g_slist_next(list)) { - Parameter * param = static_cast<Parameter*>(list->data); + for( auto param:this->parameters) { if (!strcmp(param->name(), name)) { return param; } else { @@ -730,8 +723,7 @@ Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<v agui->set_spacing(Parameter::GUI_BOX_SPACING); //go through the list of parameters to see if there are any non-hidden ones - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for (auto param:parameters) { if (param->get_hidden()) continue; //Ignore hidden parameters Gtk::Widget * widg = param->get_widget(doc, node, changeSignal); gchar const * tip = param->get_tooltip(); @@ -751,8 +743,7 @@ Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<v void Extension::paramListString (std::list <std::string> &retlist) { - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for(auto param:parameters) { param->string(retlist); } @@ -835,8 +826,7 @@ Extension::get_params_widget(void) unsigned int Extension::param_visible_count ( ) { unsigned int _visible_count = 0; - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for (auto param:parameters) { if (!param->get_hidden()) _visible_count++; } return _visible_count; diff --git a/src/extension/extension.h b/src/extension/extension.h index 962c3c8a7..9ccc9869b 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -133,7 +133,7 @@ public: /* Parameter Stuff */ private: - GSList * parameters; /**< A table to store the parameters for this extension. + std::vector<Parameter *> parameters; /**< A table to store the parameters for this extension. This only gets created if there are parameters in this extension */ @@ -141,8 +141,7 @@ public: /** \brief A function to get the number of parameters that the extension has. \return The number of parameters. */ - unsigned int param_count ( ) { return parameters == NULL ? 0 : - g_slist_length(parameters); }; + unsigned int param_count ( ) { return parameters.size(); }; /** \brief A function to get the number of parameters that are visible to the user that the extension has. \return The number of visible parameters. diff --git a/src/extension/implementation/makefile.in b/src/extension/implementation/makefile.in deleted file mode 100644 index d54ea1d3a..000000000 --- a/src/extension/implementation/makefile.in +++ /dev/null @@ -1,17 +0,0 @@ -# Convenience stub makefile to call the real Makefile. - -@SET_MAKE@ - -OBJEXT = @OBJEXT@ - -# Explicit so that it's the default rule. -all: - cd ../.. && $(MAKE) extension/implementation/all - -clean %.a %.$(OBJEXT): - cd ../.. && $(MAKE) extension/implementation/$@ - -.PHONY: all clean - -.SUFFIXES: -.SUFFIXES: .a .$(OBJEXT) diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 8da56fecd..2901655f1 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -32,7 +32,6 @@ #include "extension/input.h" #include "extension/db.h" #include "inkscape.h" -#include "io/sys.h" #include "io/resource.h" #include "preferences.h" #include "script.h" @@ -398,7 +397,7 @@ ScriptDocCache::ScriptDocCache (Inkscape::UI::View::View * view) : _tempfd(0) { try { - _tempfd = Inkscape::IO::file_open_tmp(_filename, "ink_ext_XXXXXX.svg"); + _tempfd = Glib::file_open_tmp(_filename, "ink_ext_XXXXXX.svg"); } catch (...) { /// \todo Popup dialog here return; @@ -462,7 +461,7 @@ Gtk::Widget *Script::prefs_output(Inkscape::Extension::Output *module) \param filename File to open. First things first, this function needs a temporary file name. To - create on of those the function g_file_open_tmp is used with + create on of those the function Glib::file_open_tmp is used with the header of ink_ext_. The extension is then executed using the 'execute' function @@ -483,7 +482,7 @@ SPDocument *Script::open(Inkscape::Extension::Input *module, std::string tempfilename_out; int tempfd_out = 0; try { - tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg"); + tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg"); } catch (...) { /// \todo Popup dialog here return NULL; @@ -513,7 +512,7 @@ SPDocument *Script::open(Inkscape::Extension::Input *module, mydoc->changeUriAndHrefs(filenameArg); } - // make sure we don't leak file descriptors from g_file_open_tmp + // make sure we don't leak file descriptors from Glib::file_open_tmp close(tempfd_out); unlink(tempfilename_out.c_str()); @@ -539,7 +538,7 @@ SPDocument *Script::open(Inkscape::Extension::Input *module, do that eh? First things first, the document is saved to a temporary file that - is an SVG file. To get the temporary filename g_file_open_tmp is used with + is an SVG file. To get the temporary filename Glib::file_open_tmp is used with ink_ext_ as a prefix. Don't worry, this file gets deleted at the end of the function. @@ -558,7 +557,7 @@ void Script::save(Inkscape::Extension::Output *module, std::string tempfilename_in; int tempfd_in = 0; try { - tempfd_in = Inkscape::IO::file_open_tmp(tempfilename_in, "ink_ext_XXXXXX.svg"); + tempfd_in = Glib::file_open_tmp(tempfilename_in, "ink_ext_XXXXXX.svg"); } catch (...) { /// \todo Popup dialog here throw Inkscape::Extension::Output::save_failed(); @@ -587,7 +586,7 @@ void Script::save(Inkscape::Extension::Output *module, success = fileout.toFile(lfilename); } - // make sure we don't leak file descriptors from g_file_open_tmp + // make sure we don't leak file descriptors from Glib::file_open_tmp close(tempfd_in); // FIXME: convert to utf8 (from "filename encoding") and unlink_utf8name unlink(tempfilename_in.c_str()); @@ -609,7 +608,7 @@ void Script::save(Inkscape::Extension::Output *module, This function is a little bit trickier than the previous two. It needs two temporary files to get it's work done. Both of these - files have random names created for them using the g_file_open_temp function + files have random names created for them using the Glib::file_open_temp function with the ink_ext_ prefix in the temporary directory. Like the other functions, the temporary files are deleted at the end. @@ -667,7 +666,7 @@ void Script::effect(Inkscape::Extension::Effect *module, std::string tempfilename_out; int tempfd_out = 0; try { - tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg"); + tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg"); } catch (...) { /// \todo Popup dialog here return; @@ -740,7 +739,7 @@ void Script::effect(Inkscape::Extension::Effect *module, pump_events(); - // make sure we don't leak file descriptors from g_file_open_tmp + // make sure we don't leak file descriptors from Glib::file_open_tmp close(tempfd_out); g_unlink(tempfilename_out.c_str()); diff --git a/src/extension/implementation/xslt.cpp b/src/extension/implementation/xslt.cpp index 94852a98e..d11283db7 100644 --- a/src/extension/implementation/xslt.cpp +++ b/src/extension/implementation/xslt.cpp @@ -16,13 +16,13 @@ #include <config.h> #endif +#include <glibmm/fileutils.h> #include "file.h" #include "xslt.h" #include "../extension.h" #include "../output.h" #include "extension/input.h" -#include "io/sys.h" #include "io/resource.h" #include <unistd.h> #include <cstring> @@ -175,7 +175,7 @@ void XSLT::save(Inkscape::Extension::Output *module, SPDocument *doc, gchar cons std::string tempfilename_out; int tempfd_out = 0; try { - tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX"); + tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX"); } catch (...) { /// \todo Popup dialog here return; diff --git a/src/extension/init.cpp b/src/extension/init.cpp index 9830b0176..699c0382f 100644 --- a/src/extension/init.cpp +++ b/src/extension/init.cpp @@ -130,20 +130,9 @@ static void check_extensions(); */ static void update_pref(Glib::ustring const &pref_path, - gchar const *pref_default) // , GSList *extension_family) + gchar const *pref_default) { Glib::ustring pref = Inkscape::Preferences::get()->getString(pref_path); - /* - gboolean missing=TRUE; - for (GSList *list = extension_family; list; list = g_slist_next(list)) { - g_assert( list->data ); - - Inkscape::Extension *extension; - extension = reinterpret_cast<Inkscape::Extension *>(list->data); - - if (!strcmp(extension->get_id(),pref)) missing=FALSE; - } - */ if (!Inkscape::Extension::db.get( pref.data() ) /*missing*/) { Inkscape::Preferences::get()->setString(pref_path, pref_default); } diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index cc5b3d1bc..352271e26 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -39,7 +39,7 @@ namespace Bitmap { class ImageMagickDocCache: public Inkscape::Extension::Implementation::ImplementationDocumentCache { friend class ImageMagick; private: - void readImage(char const *xlink, Magick::Image *image); + void readImage(char const *xlink, char const *id, Magick::Image *image); protected: Inkscape::XML::Node** _nodes; @@ -85,11 +85,12 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : { _nodes[_imageCount] = node; char const *xlink = node->attribute("xlink:href"); + char const *id = node->attribute("id"); _originals[_imageCount] = xlink; _caches[_imageCount] = (char*)""; _cacheLengths[_imageCount] = 0; _images[_imageCount] = new Magick::Image(); - readImage(xlink, _images[_imageCount]); + readImage(xlink, id, _images[_imageCount]); _imageItems[_imageCount] = item; _imageCount++; } @@ -113,26 +114,33 @@ ImageMagickDocCache::~ImageMagickDocCache ( ) { } void -ImageMagickDocCache::readImage(const char *xlink, Magick::Image *image) +ImageMagickDocCache::readImage(const char *xlink, const char *id, Magick::Image *image) { // Find if the xlink:href is base64 data, i.e. if the image is embedded - char *search = (char *) g_strndup(xlink, 30); + gchar *search = g_strndup(xlink, 30); if (strstr(search, "base64") != (char*)NULL) { // 7 = strlen("base64") + strlen(",") const char* pureBase64 = strstr(xlink, "base64") + 7; Magick::Blob blob; blob.base64(pureBase64); - image->read(blob); - } - else { - const gchar *path = xlink; - if (strncmp (xlink,"file:", 5) == 0) { - path = g_filename_from_uri(xlink, NULL, NULL); + try { + image->read(blob); + } catch (Magick::Exception &error_) { + g_warning("ImageMagick could not read '%s'\nDetails: %s", id, error_.what()); + } + } else { + gchar *path; + if (strncmp (xlink,"file:", 5) == 0) { + path = g_filename_from_uri(xlink, NULL, NULL); + } else { + path = g_strdup(xlink); } - try { image->read(path); - } catch (...) {} + } catch (Magick::Exception &error_) { + g_warning("ImageMagick could not read '%s' from '%s'\nDetails: %s", id, path, error_.what()); + } + g_free(path); } g_free(search); } diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index c513744a8..3edb58a13 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -163,10 +163,10 @@ CairoRenderState* CairoRenderContext::getCurrentState(void) const CairoRenderState* CairoRenderContext::getParentState(void) const { // if this is the root node just return it - if (g_slist_length(_state_stack) == 1) { + if (_state_stack.size() == 1) { return _state; } else { - return static_cast<CairoRenderState *>(g_slist_nth_data(_state_stack, 1)); + return _state_stack[_state_stack.size()-2]; } } @@ -975,7 +975,7 @@ void CairoRenderContext::pushState(void) CairoRenderState *new_state = _createState(); // copy current state's transform new_state->transform = _state->transform; - _state_stack = g_slist_prepend(_state_stack, new_state); + _state_stack.push_back(new_state); _state = new_state; } @@ -985,11 +985,11 @@ void CairoRenderContext::popState(void) cairo_restore(_cr); - g_free(_state_stack->data); - _state_stack = g_slist_remove_link(_state_stack, _state_stack); - _state = static_cast<CairoRenderState*>(_state_stack->data); + g_free(_state_stack.back()); + _state_stack.pop_back(); - g_assert( g_slist_length(_state_stack) > 0 ); + g_assert( !_state_stack.empty()); + _state = _state_stack.back(); } static bool pattern_hasItemChildren(SPPattern *pat) diff --git a/src/extension/internal/cairo-render-context.h b/src/extension/internal/cairo-render-context.h index 9b976fd6d..be5169a74 100644 --- a/src/extension/internal/cairo-render-context.h +++ b/src/extension/internal/cairo-render-context.h @@ -198,7 +198,7 @@ protected: unsigned int _clip_rule : 8; unsigned int _clip_winding_failed : 1; - GSList *_state_stack; + std::vector<CairoRenderState *> _state_stack; CairoRenderState *_state; // the current state CairoRenderer *_renderer; diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index a2b8fb22f..116364739 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -27,7 +27,6 @@ #include <signal.h> #include <errno.h> -#include <boost/scoped_ptr.hpp> #include "libnrtype/Layout-TNG.h" #include <2geom/transforms.h> @@ -121,13 +120,12 @@ CairoRenderer::createContext(void) CairoRenderContext *new_context = new CairoRenderContext(this); g_assert( new_context != NULL ); - new_context->_state_stack = NULL; new_context->_state = NULL; // create initial render state CairoRenderState *state = new_context->_createState(); state->transform = Geom::identity(); - new_context->_state_stack = g_slist_prepend(new_context->_state_stack, state); + new_context->_state_stack.push_back(state); new_context->_state = state; return new_context; @@ -517,20 +515,17 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx) // Do the export SPDocument *document = item->document; - GSList *items = NULL; - items = g_slist_append(items, item); - boost::scoped_ptr<Inkscape::Pixbuf> pb( + std::unique_ptr<Inkscape::Pixbuf> pb( sp_generate_internal_bitmap(document, NULL, bbox->min()[Geom::X], bbox->min()[Geom::Y], bbox->max()[Geom::X], bbox->max()[Geom::Y], - width, height, res, res, (guint32) 0xffffff00, items )); + width, height, res, res, (guint32) 0xffffff00, item )); if (pb) { //TEST(gdk_pixbuf_save( pb, "bitmap.png", "png", NULL, NULL )); ctx->renderImage(pb.get(), t, item->style); } - g_slist_free (items); } diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp index e0dc90981..26e6531dd 100644 --- a/src/extension/internal/gdkpixbuf-input.cpp +++ b/src/extension/internal/gdkpixbuf-input.cpp @@ -1,6 +1,7 @@ #include <gdk-pixbuf/gdk-pixbuf.h> +#include <gdkmm/pixbuf.h> +#include <gdkmm/pixbufformat.h> -#include <boost/scoped_ptr.hpp> #include <glib/gprintf.h> #include <glibmm/i18n.h> #include "dir-util.h" @@ -63,7 +64,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri) bool embed = ( link.compare( "embed" ) == 0 ); SPDocument *doc = NULL; - boost::scoped_ptr<Inkscape::Pixbuf> pb(Inkscape::Pixbuf::create_from_file(uri)); + std::unique_ptr<Inkscape::Pixbuf> pb(Inkscape::Pixbuf::create_from_file(uri)); // TODO: the pixbuf is created again from the base64-encoded attribute in SPImage. // Find a way to create the pixbuf only once. @@ -163,14 +164,9 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri) void GdkpixbufInput::init(void) { - GSList * formatlist, * formatlisthead; - - /* \todo I'm not sure if I need to free this list */ - for (formatlist = formatlisthead = gdk_pixbuf_get_formats(); - formatlist != NULL; - formatlist = g_slist_next(formatlist)) { - - GdkPixbufFormat *pixformat = (GdkPixbufFormat *)formatlist->data; + static std::vector< Gdk::PixbufFormat > formatlist = Gdk::Pixbuf::get_formats(); + for (auto i: formatlist) { + GdkPixbufFormat *pixformat = i.gobj(); gchar *name = gdk_pixbuf_format_get_name(pixformat); gchar *description = gdk_pixbuf_format_get_description(pixformat); @@ -240,8 +236,6 @@ GdkpixbufInput::init(void) g_strfreev(mimetypes); g_strfreev(extensions); } - - g_slist_free(formatlisthead); } } } } /* namespace Inkscape, Extension, Implementation */ diff --git a/src/extension/internal/makefile.in b/src/extension/internal/makefile.in deleted file mode 100644 index 466309a8f..000000000 --- a/src/extension/internal/makefile.in +++ /dev/null @@ -1,17 +0,0 @@ -# Convenience stub makefile to call the real Makefile. - -@SET_MAKE@ - -OBJEXT = @OBJEXT@ - -# Explicit so that it's the default rule. -all: - cd ../.. && $(MAKE) extension/internal/all - -clean %.a %.$(OBJEXT): - cd ../.. && $(MAKE) extension/internal/$@ - -.PHONY: all clean - -.SUFFIXES: -.SUFFIXES: .a .$(OBJEXT) diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp index 844d16c17..6e0ee75aa 100644 --- a/src/extension/internal/pdfinput/pdf-input.cpp +++ b/src/extension/internal/pdfinput/pdf-input.cpp @@ -846,14 +846,20 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { } // Parse the document structure +#if defined(POPPLER_NEW_OBJECT_API) + Object obj = page->getContents(); +#else Object obj; page->getContents(&obj); +#endif if (!obj.isNull()) { pdf_parser->parse(&obj); } // Cleanup +#if !defined(POPPLER_NEW_OBJECT_API) obj.free(); +#endif delete pdf_parser; delete builder; g_free(docname); diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index 5ede59bf3..604b7f807 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -414,13 +414,21 @@ void PdfParser::parse(Object *obj, GBool topLevel) { if (obj->isArray()) { for (int i = 0; i < obj->arrayGetLength(); ++i) { +#if defined(POPPLER_NEW_OBJECT_API) + obj2 = obj->arrayGet(i); +#else obj->arrayGet(i, &obj2); +#endif if (!obj2.isStream()) { error(errInternal, -1, "Weird page contents"); +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif return; } +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif } } else if (!obj->isStream()) { error(errInternal, -1, "Weird page contents"); @@ -439,7 +447,11 @@ void PdfParser::go(GBool /*topLevel*/) // scan a sequence of objects int numArgs = 0; +#if defined(POPPLER_NEW_OBJECT_API) + obj = parser->getObj(); +#else parser->getObj(&obj); +#endif while (!obj.isEOF()) { // got a command - execute it @@ -457,14 +469,20 @@ void PdfParser::go(GBool /*topLevel*/) // Run the operation execOp(&obj, args, numArgs); +#if !defined(POPPLER_NEW_OBJECT_API) obj.free(); for (int i = 0; i < numArgs; ++i) args[i].free(); +#endif numArgs = 0; // got an argument - save it } else if (numArgs < maxArgs) { +#if defined(POPPLER_NEW_OBJECT_API) + args[numArgs++] = std::move(obj); +#else args[numArgs++] = obj; +#endif // too many arguments - something is wrong } else { @@ -475,13 +493,21 @@ void PdfParser::go(GBool /*topLevel*/) printf("\n"); fflush(stdout); } +#if !defined(POPPLER_NEW_OBJECT_API) obj.free(); +#endif } // grab the next object +#if defined(POPPLER_NEW_OBJECT_API) + obj = parser->getObj(); +#else parser->getObj(&obj); +#endif } +#if !defined(POPPLER_NEW_OBJECT_API) obj.free(); +#endif // args at end with no command if (numArgs > 0) { @@ -495,8 +521,10 @@ void PdfParser::go(GBool /*topLevel*/) printf("\n"); fflush(stdout); } +#if !defined(POPPLER_NEW_OBJECT_API) for (int i = 0; i < numArgs; ++i) args[i].free(); +#endif } } @@ -692,9 +720,13 @@ void PdfParser::opSetDash(Object args[], int /*numArgs*/) if (length != 0) { dash = (double *)gmallocn(length, sizeof(double)); for (int i = 0; i < length; ++i) { +#if defined(POPPLER_NEW_OBJECT_API) + dash[i] = a->get(i).getNum(); +#else Object obj; dash[i] = a->get(i, &obj)->getNum(); obj.free(); +#endif } } state->setLineDash(dash, length, args[1].getNum()); @@ -744,12 +776,18 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/) GBool haveBackdropColor = gFalse; GBool alpha = gFalse; +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj1 = res->lookupGState(args[0].getName())).isNull()) { +#else if (!res->lookupGState(args[0].getName(), &obj1)) { +#endif return; } if (!obj1.isDict()) { error(errSyntaxError, getPos(), "ExtGState '{0:s}' is wrong type"), args[0].getName(); +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif return; } if (printCommands) { @@ -759,7 +797,11 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/) } // transparency support: blend mode, fill/stroke opacity +#if defined(POPPLER_NEW_OBJECT_API) + if (!((obj2 = obj1.dictLookup(const_cast<char*>("BM"))).isNull())) { +#else if (!obj1.dictLookup(const_cast<char*>("BM"), &obj2)->isNull()) { +#endif GfxBlendMode mode = gfxBlendNormal; if (state->parseBlendMode(&obj2, &mode)) { state->setBlendMode(mode); @@ -767,40 +809,71 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/) error(errSyntaxError, getPos(), "Invalid blend mode in ExtGState"); } } +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj2 = obj1.dictLookup(const_cast<char*>("ca"))).isNum()) { +#else obj2.free(); if (obj1.dictLookup(const_cast<char*>("ca"), &obj2)->isNum()) { +#endif state->setFillOpacity(obj2.getNum()); } +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj2 = obj1.dictLookup(const_cast<char*>("CA"))).isNum()) { +#else obj2.free(); if (obj1.dictLookup(const_cast<char*>("CA"), &obj2)->isNum()) { +#endif state->setStrokeOpacity(obj2.getNum()); } +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif // fill/stroke overprint GBool haveFillOP = gFalse; +#if defined(POPPLER_NEW_OBJECT_API) + if ((haveFillOP = (obj2 = obj1.dictLookup(const_cast<char*>("op"))).isBool())) { +#else if ((haveFillOP = (obj1.dictLookup(const_cast<char*>("op"), &obj2)->isBool()))) { +#endif state->setFillOverprint(obj2.getBool()); } +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj2 = obj1.dictLookup(const_cast<char*>("OP"))).isBool()) { +#else obj2.free(); if (obj1.dictLookup(const_cast<char*>("OP"), &obj2)->isBool()) { +#endif state->setStrokeOverprint(obj2.getBool()); if (!haveFillOP) { state->setFillOverprint(obj2.getBool()); } } +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif // stroke adjust +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj2 = obj1.dictLookup(const_cast<char*>("SA"))).isBool()) { +#else if (obj1.dictLookup(const_cast<char*>("SA"), &obj2)->isBool()) { +#endif state->setStrokeAdjust(obj2.getBool()); } +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif // transfer function +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj2 = obj1.dictLookup(const_cast<char*>("TR2"))).isNull()) { + obj2 = obj1.dictLookup(const_cast<char*>("TR")); +#else if (obj1.dictLookup(const_cast<char*>("TR2"), &obj2)->isNull()) { obj2.free(); obj1.dictLookup(const_cast<char*>("TR"), &obj2); +#endif } if (obj2.isName(const_cast<char*>("Default")) || obj2.isName(const_cast<char*>("Identity"))) { @@ -809,9 +882,15 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/) } else if (obj2.isArray() && obj2.arrayGetLength() == 4) { int pos = 4; for (int i = 0; i < 4; ++i) { +#if defined(POPPLER_NEW_OBJECT_API) + obj3 = obj2.arrayGet(i); +#else obj2.arrayGet(i, &obj3); +#endif funcs[i] = Function::parse(&obj3); +#if !defined(POPPLER_NEW_OBJECT_API) obj3.free(); +#endif if (!funcs[i]) { pos = i; break; @@ -828,21 +907,37 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/) } else if (!obj2.isNull()) { error(errSyntaxError, getPos(), "Invalid transfer function in ExtGState"); } +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif // soft mask +#if defined(POPPLER_NEW_OBJECT_API) + if (!((obj2 = obj1.dictLookup(const_cast<char*>("SMask"))).isNull())) { +#else if (!obj1.dictLookup(const_cast<char*>("SMask"), &obj2)->isNull()) { +#endif if (obj2.isName(const_cast<char*>("None"))) { builder->clearSoftMask(state); } else if (obj2.isDict()) { +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj3 = obj2.dictLookup(const_cast<char*>("S"))).isName(const_cast<char*>("Alpha"))) { +#else if (obj2.dictLookup(const_cast<char*>("S"), &obj3)->isName(const_cast<char*>("Alpha"))) { +#endif alpha = gTrue; } else { // "Luminosity" alpha = gFalse; } +#if !defined(POPPLER_NEW_OBJECT_API) obj3.free(); +#endif funcs[0] = NULL; +#if defined(POPPLER_NEW_OBJECT_API) + if (!((obj3 = obj2.dictLookup(const_cast<char*>("TR"))).isNull())) { +#else if (!obj2.dictLookup(const_cast<char*>("TR"), &obj3)->isNull()) { +#endif funcs[0] = Function::parse(&obj3); if (funcs[0]->getInputSize() != 1 || funcs[0]->getOutputSize() != 1) { @@ -851,26 +946,45 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/) funcs[0] = NULL; } } +#if defined(POPPLER_NEW_OBJECT_API) + if ((haveBackdropColor = (obj3 = obj2.dictLookup(const_cast<char*>("BC"))).isArray())) { +#else obj3.free(); if ((haveBackdropColor = obj2.dictLookup(const_cast<char*>("BC"), &obj3)->isArray())) { +#endif for (int i = 0; i < gfxColorMaxComps; ++i) { backdropColor.c[i] = 0; } for (int i = 0; i < obj3.arrayGetLength() && i < gfxColorMaxComps; ++i) { +#if defined(POPPLER_NEW_OBJECT_API) + obj4 = obj3.arrayGet(i); +#else obj3.arrayGet(i, &obj4); +#endif if (obj4.isNum()) { backdropColor.c[i] = dblToCol(obj4.getNum()); } +#if !defined(POPPLER_NEW_OBJECT_API) obj4.free(); +#endif } } +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj3 = obj2.dictLookup(const_cast<char*>("G"))).isStream()) { + if ((obj4 = obj3.streamGetDict()->lookup(const_cast<char*>("Group"))).isDict()) { +#else obj3.free(); if (obj2.dictLookup(const_cast<char*>("G"), &obj3)->isStream()) { if (obj3.streamGetDict()->lookup(const_cast<char*>("Group"), &obj4)->isDict()) { +#endif GfxColorSpace *blendingColorSpace = 0; GBool isolated = gFalse; GBool knockout = gFalse; +#if defined(POPPLER_NEW_OBJECT_API) + if (!((obj5 = obj4.dictLookup(const_cast<char*>("CS"))).isNull())) { +#else if (!obj4.dictLookup(const_cast<char*>("CS"), &obj5)->isNull()) { +#endif #if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) blendingColorSpace = GfxColorSpace::parse(NULL, &obj5, NULL, NULL); #elif defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) @@ -879,15 +993,25 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/) blendingColorSpace = GfxColorSpace::parse(&obj5, NULL); #endif } +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj5 = obj4.dictLookup(const_cast<char*>("I"))).isBool()) { +#else obj5.free(); if (obj4.dictLookup(const_cast<char*>("I"), &obj5)->isBool()) { +#endif isolated = obj5.getBool(); } +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj5 = obj4.dictLookup(const_cast<char*>("K"))).isBool()) { +#else obj5.free(); if (obj4.dictLookup(const_cast<char*>("K"), &obj5)->isBool()) { +#endif knockout = obj5.getBool(); } +#if !defined(POPPLER_NEW_OBJECT_API) obj5.free(); +#endif if (!haveBackdropColor) { if (blendingColorSpace) { blendingColorSpace->getDefaultColor(&backdropColor); @@ -906,18 +1030,24 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/) } else { error(errSyntaxError, getPos(), "Invalid soft mask in ExtGState - missing group"); } +#if !defined(POPPLER_NEW_OBJECT_API) obj4.free(); +#endif } else { error(errSyntaxError, getPos(), "Invalid soft mask in ExtGState - missing group"); } +#if !defined(POPPLER_NEW_OBJECT_API) obj3.free(); +#endif } else if (!obj2.isNull()) { error(errSyntaxError, getPos(), "Invalid soft mask in ExtGState"); } } +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); obj1.free(); +#endif } void PdfParser::doSoftMask(Object *str, GBool alpha, @@ -938,43 +1068,79 @@ void PdfParser::doSoftMask(Object *str, GBool alpha, dict = str->streamGetDict(); // check form type +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("FormType")); +#else dict->lookup(const_cast<char*>("FormType"), &obj1); +#endif if (!(obj1.isNull() || (obj1.isInt() && obj1.getInt() == 1))) { error(errSyntaxError, getPos(), "Unknown form type"); } +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif // get bounding box +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("BBox")); +#else dict->lookup(const_cast<char*>("BBox"), &obj1); +#endif if (!obj1.isArray()) { +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif error(errSyntaxError, getPos(), "Bad form bounding box"); return; } for (i = 0; i < 4; ++i) { +#if defined(POPPLER_NEW_OBJECT_API) + obj2 = obj1.arrayGet(i); +#else obj1.arrayGet(i, &obj2); +#endif bbox[i] = obj2.getNum(); +#if defined(POPPLER_NEW_OBJECT_API) + } +#else obj2.free(); } obj1.free(); +#endif // get matrix +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("Matrix")); +#else dict->lookup(const_cast<char*>("Matrix"), &obj1); +#endif if (obj1.isArray()) { for (i = 0; i < 6; ++i) { +#if defined(POPPLER_NEW_OBJECT_API) + obj2 = obj1.arrayGet(i); +#else obj1.arrayGet(i, &obj2); +#endif m[i] = obj2.getNum(); +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif } } else { m[0] = 1; m[1] = 0; m[2] = 0; m[3] = 1; m[4] = 0; m[5] = 0; } +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif // get resources +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("Resources")); +#else dict->lookup(const_cast<char*>("Resources"), &obj1); +#endif resDict = obj1.isDict() ? obj1.getDict() : (Dict *)NULL; // draw it @@ -987,7 +1153,9 @@ void PdfParser::doSoftMask(Object *str, GBool alpha, if (blendingColorSpace) { delete blendingColorSpace; } +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif } void PdfParser::opSetRenderingIntent(Object /*args*/[], int /*numArgs*/) @@ -1084,7 +1252,11 @@ void PdfParser::opSetFillColorSpace(Object args[], int /*numArgs*/) Object obj; state->setFillPattern(NULL); +#if defined(POPPLER_NEW_OBJECT_API) + obj = res->lookupColorSpace(args[0].getName()); +#else res->lookupColorSpace(args[0].getName(), &obj); +#endif GfxColorSpace *colorSpace = 0; #if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) @@ -1106,7 +1278,9 @@ void PdfParser::opSetFillColorSpace(Object args[], int /*numArgs*/) colorSpace = GfxColorSpace::parse(&obj, NULL); } #endif +#if !defined(POPPLER_NEW_OBJECT_API) obj.free(); +#endif if (colorSpace) { GfxColor color; state->setFillColorSpace(colorSpace); @@ -1125,7 +1299,11 @@ void PdfParser::opSetStrokeColorSpace(Object args[], int /*numArgs*/) GfxColorSpace *colorSpace = 0; state->setStrokePattern(NULL); +#if defined(POPPLER_NEW_OBJECT_API) + obj = res->lookupColorSpace(args[0].getName()); +#else res->lookupColorSpace(args[0].getName(), &obj); +#endif #if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) if (obj.isNull()) { colorSpace = GfxColorSpace::parse(NULL, &args[0], NULL, NULL); @@ -1145,7 +1323,9 @@ void PdfParser::opSetStrokeColorSpace(Object args[], int /*numArgs*/) colorSpace = GfxColorSpace::parse(&obj, NULL); } #endif +#if !defined(POPPLER_NEW_OBJECT_API) obj.free(); +#endif if (colorSpace) { GfxColor color; state->setStrokeColorSpace(colorSpace); @@ -2375,7 +2555,11 @@ void PdfParser::opShowSpaceText(Object args[], int /*numArgs*/) wMode = state->getFont()->getWMode(); a = args[0].getArray(); for (int i = 0; i < a->getLength(); ++i) { +#if defined(POPPLER_NEW_OBJECT_API) + obj = a->get(i); +#else a->get(i, &obj); +#endif if (obj.isNum()) { // this uses the absolute value of the font size to match // Acrobat's behavior @@ -2392,7 +2576,9 @@ void PdfParser::opShowSpaceText(Object args[], int /*numArgs*/) } else { error(errSyntaxError, getPos(), "Element of show/space array must be number or string"); } +#if !defined(POPPLER_NEW_OBJECT_API) obj.free(); +#endif } } @@ -2465,7 +2651,11 @@ void PdfParser::doShowText(GooString *s) { //out->updateCTM(state, 1, 0, 0, 1, 0, 0); if (0){ /*!out->beginType3Char(state, curX + riseX, curY + riseY, tdx, tdy, code, u, uLen)) {*/ +#if defined(POPPLER_NEW_OBJECT_API) + charProc = ((Gfx8BitFont *)font)->getCharProc(code); +#else ((Gfx8BitFont *)font)->getCharProc(code, &charProc); +#endif if ((resDict = ((Gfx8BitFont *)font)->getResources())) { pushResources(resDict); } @@ -2478,7 +2668,9 @@ void PdfParser::doShowText(GooString *s) { if (resDict) { popResources(); } +#if !defined(POPPLER_NEW_OBJECT_API) charProc.free(); +#endif } restoreState(); // GfxState::restore() does *not* restore the current position, @@ -2541,23 +2733,43 @@ void PdfParser::opXObject(Object args[], int /*numArgs*/) Object obj1, obj2, obj3, refObj; char *name = args[0].getName(); +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj1 = res->lookupXObject(name)).isNull()) { +#else if (!res->lookupXObject(name, &obj1)) { +#endif return; } if (!obj1.isStream()) { error(errSyntaxError, getPos(), "XObject '{0:s}' is wrong type", name); +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif return; } +#if defined(POPPLER_NEW_OBJECT_API) + obj2 = obj1.streamGetDict()->lookup(const_cast<char*>("Subtype")); +#else obj1.streamGetDict()->lookup(const_cast<char*>("Subtype"), &obj2); +#endif if (obj2.isName(const_cast<char*>("Image"))) { +#if defined(POPPLER_NEW_OBJECT_API) + refObj = res->lookupXObjectNF(name); +#else res->lookupXObjectNF(name, &refObj); +#endif doImage(&refObj, obj1.getStream(), gFalse); +#if !defined(POPPLER_NEW_OBJECT_API) refObj.free(); +#endif } else if (obj2.isName(const_cast<char*>("Form"))) { doForm(&obj1); } else if (obj2.isName(const_cast<char*>("PS"))) { +#if defined(POPPLER_NEW_OBJECT_API) + obj3 = obj1.streamGetDict()->lookup(const_cast<char*>("Level1")); +#else obj1.streamGetDict()->lookup(const_cast<char*>("Level1"), &obj3); +#endif /* out->psXObject(obj1.getStream(), obj3.isStream() ? obj3.getStream() : (Stream *)NULL);*/ } else if (obj2.isName()) { @@ -2565,8 +2777,10 @@ void PdfParser::opXObject(Object args[], int /*numArgs*/) } else { error(errSyntaxError, getPos(), "XObject subtype is missing or wrong type"); } +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); obj1.free(); +#endif } void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) @@ -2593,10 +2807,18 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) dict = str->getDict(); // get size +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("Width")); +#else dict->lookup(const_cast<char*>("Width"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("W")); +#else obj1.free(); dict->lookup(const_cast<char*>("W"), &obj1); +#endif } if (obj1.isInt()){ width = obj1.getInt(); @@ -2607,11 +2829,19 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) else { goto err2; } +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("Height")); +#else obj1.free(); dict->lookup(const_cast<char*>("Height"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("H")); +#else obj1.free(); dict->lookup(const_cast<char*>("H"), &obj1); +#endif } if (obj1.isInt()) { height = obj1.getInt(); @@ -2622,26 +2852,46 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) else { goto err2; } +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif // image interpolation +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup("Interpolate"); +#else dict->lookup("Interpolate", &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup("I"); +#else obj1.free(); dict->lookup("I", &obj1); +#endif } if (obj1.isBool()) interpolate = obj1.getBool(); else interpolate = gFalse; +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif maskInterpolate = gFalse; // image or mask? +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("ImageMask")); +#else dict->lookup(const_cast<char*>("ImageMask"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("IM")); +#else obj1.free(); dict->lookup(const_cast<char*>("IM"), &obj1); +#endif } mask = gFalse; if (obj1.isBool()) { @@ -2650,14 +2900,24 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) else if (!obj1.isNull()) { goto err2; } +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif // bit depth if (bits == 0) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("BitsPerComponent")); +#else dict->lookup(const_cast<char*>("BitsPerComponent"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("BPC")); +#else obj1.free(); dict->lookup(const_cast<char*>("BPC"), &obj1); +#endif } if (obj1.isInt()) { bits = obj1.getInt(); @@ -2666,7 +2926,9 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) } else { goto err2; } +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif } // display a mask @@ -2676,21 +2938,37 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) goto err1; } invert = gFalse; +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("Decode")); +#else dict->lookup(const_cast<char*>("Decode"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("D")); +#else obj1.free(); dict->lookup(const_cast<char*>("D"), &obj1); +#endif } if (obj1.isArray()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj2 = obj1.arrayGet(0); +#else obj1.arrayGet(0, &obj2); +#endif if (obj2.isInt() && obj2.getInt() == 1) { invert = gTrue; } +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif } else if (!obj1.isNull()) { goto err2; } +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif // draw it builder->addImageMask(state, str, width, height, invert, interpolate); @@ -2698,18 +2976,36 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) } else { // get color space and color map GfxColorSpace *colorSpace; +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("ColorSpace")); +#else dict->lookup(const_cast<char*>("ColorSpace"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("CS")); +#else obj1.free(); dict->lookup(const_cast<char*>("CS"), &obj1); +#endif } if (obj1.isName()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj2 = res->lookupColorSpace(obj1.getName()); +#else res->lookupColorSpace(obj1.getName(), &obj2); +#endif if (!obj2.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = std::move(obj2); +#else obj1.free(); obj1 = obj2; +#endif } else { +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif } } if (!obj1.isNull()) { @@ -2729,17 +3025,29 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) } else { colorSpace = NULL; } +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif if (!colorSpace) { goto err1; } +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("Decode")); +#else dict->lookup(const_cast<char*>("Decode"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("D")); +#else obj1.free(); dict->lookup(const_cast<char*>("D"), &obj1); +#endif } GfxImageColorMap *colorMap = new GfxImageColorMap(bits, &obj1, colorSpace); +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif if (!colorMap->isOk()) { delete colorMap; goto err1; @@ -2753,8 +3061,13 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) int maskHeight = 0; maskInvert = gFalse; GfxImageColorMap *maskColorMap = NULL; +#if defined(POPPLER_NEW_OBJECT_API) + maskObj = dict->lookup(const_cast<char*>("Mask")); + smaskObj = dict->lookup(const_cast<char*>("SMask")); +#else dict->lookup(const_cast<char*>("Mask"), &maskObj); dict->lookup(const_cast<char*>("SMask"), &smaskObj); +#endif Dict* maskDict; if (smaskObj.isStream()) { // soft mask @@ -2763,58 +3076,108 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) } maskStr = smaskObj.getStream(); maskDict = smaskObj.streamGetDict(); +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("Width")); +#else maskDict->lookup(const_cast<char*>("Width"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("W")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("W"), &obj1); +#endif } if (!obj1.isInt()) { goto err2; } maskWidth = obj1.getInt(); +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("Height")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("Height"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("H")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("H"), &obj1); +#endif } if (!obj1.isInt()) { goto err2; } maskHeight = obj1.getInt(); +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("BitsPerComponent")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("BitsPerComponent"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("BPC")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("BPC"), &obj1); +#endif } if (!obj1.isInt()) { goto err2; } int maskBits = obj1.getInt(); +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("Interpolate")); +#else obj1.free(); maskDict->lookup("Interpolate", &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("I")); +#else obj1.free(); maskDict->lookup("I", &obj1); +#endif } if (obj1.isBool()) maskInterpolate = obj1.getBool(); else maskInterpolate = gFalse; +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("ColorSpace")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("ColorSpace"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("CS")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("CS"), &obj1); +#endif } if (obj1.isName()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj2 = res->lookupColorSpace(obj1.getName()); +#else res->lookupColorSpace(obj1.getName(), &obj2); +#endif if (!obj2.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = std::move(obj2); +#else obj1.free(); obj1 = obj2; +#endif } else { +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif } } #if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) @@ -2824,17 +3187,29 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) #else GfxColorSpace *maskColorSpace = GfxColorSpace::parse(&obj1, NULL); #endif +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif if (!maskColorSpace || maskColorSpace->getMode() != csDeviceGray) { goto err1; } +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("Decode")); +#else maskDict->lookup(const_cast<char*>("Decode"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("D")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("D"), &obj1); +#endif } maskColorMap = new GfxImageColorMap(maskBits, &obj1, maskColorSpace); +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif if (!maskColorMap->isOk()) { delete maskColorMap; goto err1; @@ -2845,9 +3220,15 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) // color key mask int i; for (i = 0; i < maskObj.arrayGetLength() && i < 2*gfxColorMaxComps; ++i) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskObj.arrayGet(i); +#else maskObj.arrayGet(i, &obj1); +#endif maskColors[i] = obj1.getInt(); +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif } haveColorKeyMask = gTrue; } else if (maskObj.isStream()) { @@ -2857,61 +3238,111 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) } maskStr = maskObj.getStream(); maskDict = maskObj.streamGetDict(); +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("Width")); +#else maskDict->lookup(const_cast<char*>("Width"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("W")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("W"), &obj1); +#endif } if (!obj1.isInt()) { goto err2; } maskWidth = obj1.getInt(); +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("Height")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("Height"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("H")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("H"), &obj1); +#endif } if (!obj1.isInt()) { goto err2; } maskHeight = obj1.getInt(); +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("ImageMask")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("ImageMask"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("IM")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("IM"), &obj1); +#endif } if (!obj1.isBool() || !obj1.getBool()) { goto err2; } +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup("Interpolate"); +#else obj1.free(); maskDict->lookup("Interpolate", &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup("I"); +#else obj1.free(); maskDict->lookup("I", &obj1); +#endif } if (obj1.isBool()) maskInterpolate = obj1.getBool(); else maskInterpolate = gFalse; +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif maskInvert = gFalse; +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("Decode")); +#else maskDict->lookup(const_cast<char*>("Decode"), &obj1); +#endif if (obj1.isNull()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = maskDict->lookup(const_cast<char*>("D")); +#else obj1.free(); maskDict->lookup(const_cast<char*>("D"), &obj1); +#endif } if (obj1.isArray()) { +#if defined(POPPLER_NEW_OBJECT_API) + obj2 = obj1.arrayGet(0); +#else obj1.arrayGet(0, &obj2); +#endif if (obj2.isInt() && obj2.getInt() == 1) { maskInvert = gTrue; } +#if !defined(POPPLER_NEW_OBJECT_API) obj2.free(); +#endif } else if (!obj1.isNull()) { goto err2; } +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif haveExplicitMask = gTrue; } @@ -2929,14 +3360,18 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) } delete colorMap; +#if !defined(POPPLER_NEW_OBJECT_API) maskObj.free(); smaskObj.free(); +#endif } return; err2: +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif err1: error(errSyntaxError, getPos(), "Bad image parameters"); } @@ -2961,52 +3396,97 @@ void PdfParser::doForm(Object *str) { dict = str->streamGetDict(); // check form type +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = dict->lookup(const_cast<char*>("FormType")); +#else dict->lookup(const_cast<char*>("FormType"), &obj1); +#endif if (!(obj1.isNull() || (obj1.isInt() && obj1.getInt() == 1))) { error(errSyntaxError, getPos(), "Unknown form type"); } +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif // get bounding box +#if defined(POPPLER_NEW_OBJECT_API) + bboxObj = dict->lookup(const_cast<char*>("BBox")); +#else dict->lookup(const_cast<char*>("BBox"), &bboxObj); +#endif if (!bboxObj.isArray()) { +#if !defined(POPPLER_NEW_OBJECT_API) bboxObj.free(); +#endif error(errSyntaxError, getPos(), "Bad form bounding box"); return; } for (i = 0; i < 4; ++i) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = bboxObj.arrayGet(i); +#else bboxObj.arrayGet(i, &obj1); +#endif bbox[i] = obj1.getNum(); +#if defined(POPPLER_NEW_OBJECT_API) + } +#else obj1.free(); } bboxObj.free(); +#endif // get matrix +#if defined(POPPLER_NEW_OBJECT_API) + matrixObj = dict->lookup(const_cast<char*>("Matrix")); +#else dict->lookup(const_cast<char*>("Matrix"), &matrixObj); +#endif if (matrixObj.isArray()) { for (i = 0; i < 6; ++i) { +#if defined(POPPLER_NEW_OBJECT_API) + obj1 = matrixObj.arrayGet(i); +#else matrixObj.arrayGet(i, &obj1); +#endif m[i] = obj1.getNum(); +#if !defined(POPPLER_NEW_OBJECT_API) obj1.free(); +#endif } } else { m[0] = 1; m[1] = 0; m[2] = 0; m[3] = 1; m[4] = 0; m[5] = 0; } +#if !defined(POPPLER_NEW_OBJECT_API) matrixObj.free(); +#endif // get resources +#if defined(POPPLER_NEW_OBJECT_API) + resObj = dict->lookup(const_cast<char*>("Resources")); +#else dict->lookup(const_cast<char*>("Resources"), &resObj); +#endif resDict = resObj.isDict() ? resObj.getDict() : (Dict *)NULL; // check for a transparency group transpGroup = isolated = knockout = gFalse; blendingColorSpace = NULL; +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj1 = dict->lookup(const_cast<char*>("Group"))).isDict()) { + if ((obj2 = obj1.dictLookup(const_cast<char*>("S"))).isName(const_cast<char*>("Transparency"))) { +#else if (dict->lookup(const_cast<char*>("Group"), &obj1)->isDict()) { if (obj1.dictLookup(const_cast<char*>("S"), &obj2)->isName(const_cast<char*>("Transparency"))) { +#endif transpGroup = gTrue; +#if defined(POPPLER_NEW_OBJECT_API) + if (!((obj3 = obj1.dictLookup(const_cast<char*>("CS"))).isNull())) { +#else if (!obj1.dictLookup(const_cast<char*>("CS"), &obj3)->isNull()) { +#endif #if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API) blendingColorSpace = GfxColorSpace::parse(NULL, &obj3, NULL, NULL); #elif defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API) @@ -3015,19 +3495,32 @@ void PdfParser::doForm(Object *str) { blendingColorSpace = GfxColorSpace::parse(&obj3, NULL); #endif } +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj3 = obj1.dictLookup(const_cast<char*>("I"))).isBool()) { +#else obj3.free(); if (obj1.dictLookup(const_cast<char*>("I"), &obj3)->isBool()) { +#endif isolated = obj3.getBool(); } +#if defined(POPPLER_NEW_OBJECT_API) + if ((obj3 = obj1.dictLookup(const_cast<char*>("K"))).isBool()) { +#else obj3.free(); if (obj1.dictLookup(const_cast<char*>("K"), &obj3)->isBool()) { +#endif knockout = obj3.getBool(); } +#if defined(POPPLER_NEW_OBJECT_API) + } + } +#else obj3.free(); } obj2.free(); } obj1.free(); +#endif // draw it ++formDepth; @@ -3038,7 +3531,9 @@ void PdfParser::doForm(Object *str) { if (blendingColorSpace) { delete blendingColorSpace; } +#if !defined(POPPLER_NEW_OBJECT_API) resObj.free(); +#endif } void PdfParser::doForm1(Object *str, Dict *resDict, double *matrix, double *bbox, @@ -3166,35 +3661,61 @@ Stream *PdfParser::buildImageStream() { Stream *str; // build dictionary +#if defined(POPPLER_NEW_OBJECT_API) + dict = Object(new Dict(xref)); + obj = parser->getObj(); +#else dict.initDict(xref); parser->getObj(&obj); +#endif while (!obj.isCmd(const_cast<char*>("ID")) && !obj.isEOF()) { if (!obj.isName()) { error(errSyntaxError, getPos(), "Inline image dictionary key must be a name object"); +#if !defined(POPPLER_NEW_OBJECT_API) obj.free(); +#endif } else { key = copyString(obj.getName()); +#if defined(POPPLER_NEW_OBJECT_API) + obj = parser->getObj(); +#else obj.free(); parser->getObj(&obj); +#endif if (obj.isEOF() || obj.isError()) { gfree(key); break; } +#if defined(POPPLER_NEW_OBJECT_API) + dict.dictAdd(key, std::move(obj)); + } + obj = parser->getObj(); +#else dict.dictAdd(key, &obj); } parser->getObj(&obj); +#endif } if (obj.isEOF()) { error(errSyntaxError, getPos(), "End of file in inline image"); +#if !defined(POPPLER_NEW_OBJECT_API) obj.free(); dict.free(); +#endif return NULL; } +#if !defined(POPPLER_NEW_OBJECT_API) obj.free(); +#endif // make stream +#if defined(POPPLER_NEW_OBJECT_API) + str = new EmbedStream(parser->getStream(), dict.copy(), gFalse, 0); + str = str->addFilters(dict.getDict()); +#else str = new EmbedStream(parser->getStream(), &dict, gFalse, 0); str = str->addFilters(&dict); +#endif return str; } diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp index 9cde90519..b05a7c19b 100644 --- a/src/extension/internal/svg.cpp +++ b/src/extension/internal/svg.cpp @@ -17,21 +17,20 @@ #ifdef HAVE_CONFIG_H # include <config.h> #endif + +#include <vector> +#include <giomm/file.h> + #include "sp-object.h" #include "svg.h" #include "file.h" #include "extension/system.h" #include "extension/output.h" -#include <vector> #include "xml/attribute-record.h" #include "xml/simple-document.h" #include "sp-root.h" #include "document.h" -#ifdef WITH_GNOME_VFS -# include <libgnomevfs/gnome-vfs.h> -#endif - namespace Inkscape { namespace Extension { namespace Internal { @@ -157,80 +156,42 @@ Svg::init(void) "</output>\n" "</inkscape-extension>", new Svg()); -#ifdef WITH_GNOME_VFS - gnome_vfs_init(); -#endif - - return; } -#ifdef WITH_GNOME_VFS -#define BUF_SIZE 8192 - -static gchar * -_load_uri (const gchar *uri) -{ - GnomeVFSHandle *handle = NULL; - GnomeVFSFileSize bytes_read; - - gsize bytesRead = 0; - gsize bytesWritten = 0; - GError* error = NULL; - gchar* uri_local = g_filename_from_utf8( uri, -1, &bytesRead, &bytesWritten, &error); - - if ( uri_local == NULL ) { - g_warning( "Error converting filename to locale encoding."); - } - - GnomeVFSResult result = gnome_vfs_open (&handle, uri_local, GNOME_VFS_OPEN_READ); - - if (result != GNOME_VFS_OK) { - g_warning("%s", gnome_vfs_result_to_string(result)); - } - - std::vector<gchar> doc; - while (result == GNOME_VFS_OK) { - gchar buffer[BUF_SIZE]; - result = gnome_vfs_read (handle, buffer, BUF_SIZE, &bytes_read); - doc.insert(doc.end(), buffer, buffer+bytes_read); - } - - return g_strndup(&doc[0], doc.size()); -} -#endif - - /** \return A new document just for you! \brief This function takes in a filename of a SVG document and turns it into a SPDocument. \param mod Module to use - \param uri The path to the file (UTF-8) + \param uri The path or URI to the file (UTF-8) This function is really simple, it just calls sp_document_new... */ SPDocument * Svg::open (Inkscape::Extension::Input */*mod*/, const gchar *uri) { -#ifdef WITH_GNOME_VFS - if (!gnome_vfs_initialized() || gnome_vfs_uri_is_local(gnome_vfs_uri_new(uri))) { - // Use built-in loader instead of VFS for this - return SPDocument::createNewDoc(uri, TRUE); - } - gchar * buffer = _load_uri(uri); - if (buffer == NULL) { - g_warning("Error: Could not open file '%s' with VFS\n", uri); - return NULL; + auto file = Gio::File::create_for_uri(uri); + const auto path = file->get_path(); + + if (!file->get_uri_scheme().empty()) { + if (path.empty()) { + try { + char *contents; + gsize length; + file->load_contents(contents, length); + return SPDocument::createNewDocFromMem(contents, length, 1); + } catch (Gio::Error &e) { + g_warning("Could not load contents of non-local URI %s\n", uri); + return NULL; + } + } else { + uri = path.c_str(); + } } - SPDocument * doc = SPDocument::createNewDocFromMem(buffer, strlen(buffer), 1); - g_free(buffer); - return doc; -#else return SPDocument::createNewDoc(uri, TRUE); -#endif } /** diff --git a/src/extension/makefile.in b/src/extension/makefile.in deleted file mode 100644 index 5f19ccaa3..000000000 --- a/src/extension/makefile.in +++ /dev/null @@ -1,17 +0,0 @@ -# Convenience stub makefile to call the real Makefile. - -@SET_MAKE@ - -OBJEXT = @OBJEXT@ - -# Explicit so that it's the default rule. -all: - cd .. && $(MAKE) extension/all - -clean %.a %.$(OBJEXT): - cd .. && $(MAKE) extension/$@ - -.PHONY: all clean - -.SUFFIXES: -.SUFFIXES: .a .$(OBJEXT) diff --git a/src/extension/param/enum.cpp b/src/extension/param/enum.cpp index 7cd860465..db34a6ef9 100644 --- a/src/extension/param/enum.cpp +++ b/src/extension/param/enum.cpp @@ -32,20 +32,6 @@ namespace Inkscape { namespace Extension { -/* For internal use only. - Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ -class enumentry { -public: - enumentry (Glib::ustring &val, Glib::ustring &text) : - value(val), - text(text) - {} - - Glib::ustring value; - Glib::ustring text; -}; - - ParamComboBox::ParamComboBox(const gchar * name, const gchar * text, const gchar * description, @@ -55,7 +41,6 @@ ParamComboBox::ParamComboBox(const gchar * name, Inkscape::XML::Node * xml) : Parameter(name, text, description, hidden, indent, ext) , _value(NULL) - , choices(NULL) { const char *xmlval = NULL; // the value stored in XML @@ -93,7 +78,7 @@ ParamComboBox::ParamComboBox(const gchar * name, } if ( (!newtext.empty()) && (!newvalue.empty()) ) { // logical error if this is not true here - choices = g_slist_append( choices, new enumentry(newvalue, newtext) ); + choices.push_back(new enumentry(newvalue, newtext) ); } } } @@ -120,11 +105,9 @@ ParamComboBox::ParamComboBox(const gchar * name, ParamComboBox::~ParamComboBox (void) { //destroy choice strings - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - delete (reinterpret_cast<enumentry *>(list->data)); + for (auto i:choices) { + delete i; } - g_slist_free(choices); - g_free(_value); } @@ -151,8 +134,7 @@ const gchar *ParamComboBox::set(const gchar * in, SPDocument * /*doc*/, Inkscape } Glib::ustring settext; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - enumentry * entr = reinterpret_cast<enumentry *>(list->data); + for (auto entr:choices) { if ( !entr->text.compare(in) ) { settext = entr->value; break; // break out of for loop @@ -181,8 +163,7 @@ bool ParamComboBox::contains(const gchar * text, SPDocument const * /*doc*/, Ink return false; /* Can't have NULL string */ } - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - enumentry * entr = reinterpret_cast<enumentry *>(list->data); + for (auto entr:choices) { if ( !entr->text.compare(text) ) return true; } @@ -256,8 +237,7 @@ Gtk::Widget *ParamComboBox::get_widget(SPDocument * doc, Inkscape::XML::Node * n ParamComboBoxEntry * combo = Gtk::manage(new ParamComboBoxEntry(this, doc, node, changeSignal)); // add choice strings: Glib::ustring settext; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - enumentry * entr = reinterpret_cast<enumentry *>(list->data); + for (auto entr:choices) { Glib::ustring text = entr->text; combo->append(text); diff --git a/src/extension/param/enum.h b/src/extension/param/enum.h index 143a648d7..d34c0dcaa 100644 --- a/src/extension/param/enum.h +++ b/src/extension/param/enum.h @@ -34,7 +34,23 @@ private: been allocated in memory. And should be free'd. It is the value of the current selected string */ gchar * _value; - GSList * choices; /**< A table to store the choice strings */ + + /* For internal use only. + * Note that value and text MUST be non-NULL. + * This is ensured by newing only at one location in the code where non-NULL checks are made. + */ + class enumentry { + public: + enumentry (Glib::ustring &val, Glib::ustring &text) : + value(val), + text(text) + {} + + Glib::ustring value; + Glib::ustring text; + }; + + std::vector<enumentry *> choices; /**< A table to store the choice strings */ public: ParamComboBox(const gchar * name, diff --git a/src/extension/param/notebook.cpp b/src/extension/param/notebook.cpp index 4e94b5216..220d6eb32 100644 --- a/src/extension/param/notebook.cpp +++ b/src/extension/param/notebook.cpp @@ -42,34 +42,7 @@ namespace Inkscape { namespace Extension { -/** - * A class to represent the pages of a notebookparameter of an extension. - */ -class ParamNotebookPage : public Parameter { -private: - GSList * parameters; /**< A table to store the parameters for this page. - This only gets created if there are parameters on this - page */ - -public: - static ParamNotebookPage * makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); - - ParamNotebookPage(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); - ~ParamNotebookPage(void); - - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void paramString (std::list <std::string> &list); - gchar * get_text (void) {return _text;}; - Parameter * get_param (const gchar * name); -}; /* class ParamNotebookPage */ - - -ParamNotebookPage::ParamNotebookPage(const gchar * name, +ParamNotebook::ParamNotebookPage::ParamNotebookPage(const gchar * name, const gchar * text, const gchar * description, bool hidden, @@ -77,7 +50,6 @@ ParamNotebookPage::ParamNotebookPage(const gchar * name, Inkscape::XML::Node * xml) : Parameter(name, text, description, hidden, /*indent*/ 0, ext) { - parameters = NULL; // Read XML to build page if (xml != NULL) { @@ -92,28 +64,25 @@ ParamNotebookPage::ParamNotebookPage(const gchar * name, if (!strcmp(chname, "param") || !strcmp(chname, "_param")) { Parameter * param; param = Parameter::make(child_repr, ext); - if (param != NULL) parameters = g_slist_append(parameters, param); + if (param != NULL) parameters.push_back(param); } child_repr = child_repr->next(); } } } -ParamNotebookPage::~ParamNotebookPage (void) +ParamNotebook::ParamNotebookPage::~ParamNotebookPage (void) { //destroy parameters - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for (auto param:parameters) { delete param; } - g_slist_free(parameters); } /** Return the value as a string. */ -void ParamNotebookPage::paramString(std::list <std::string> &list) +void ParamNotebook::ParamNotebookPage::paramString(std::list <std::string> &list) { - for (GSList * plist = parameters; plist != NULL; plist = g_slist_next(plist)) { - Parameter * param = reinterpret_cast<Parameter *>(plist->data); + for (auto param:parameters) { param->string(list); } } @@ -143,8 +112,8 @@ void ParamNotebookPage::paramString(std::list <std::string> &list) straight forward. In all cases the value is set to the default value from the XML and the type is set to the interpreted type. */ -ParamNotebookPage * -ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext) +ParamNotebook::ParamNotebookPage * +ParamNotebook::ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext) { const char * name; const char * text; @@ -186,7 +155,7 @@ ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension: * * Builds a notebook page (a vbox) and puts parameters on it. */ -Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) +Gtk::Widget * ParamNotebook::ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { if (_hidden) { return NULL; @@ -197,8 +166,7 @@ Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Nod vbox->set_spacing(Parameter::GUI_BOX_SPACING); // add parameters onto page (if any) - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for (auto param:parameters) { Gtk::Widget * widg = param->get_widget(doc, node, changeSignal); if (widg) { int indent = param->get_indent(); @@ -224,6 +192,28 @@ Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Nod return dynamic_cast<Gtk::Widget *>(vbox); } +/** Search the parameter's name in the page content. */ +Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar * name) +{ + if (name == NULL) { + throw Extension::param_not_exist(); + } + if (this->parameters.empty()) { + // the list of parameters is empty + throw Extension::param_not_exist(); + } + + for (auto param:parameters) { + if (!strcmp(param->name(), name)) { + return param; + } + } + + return NULL; +} + +/** End ParamNotebookPage **/ +/** ParamNotebook **/ ParamNotebook::ParamNotebook(const gchar * name, const gchar * text, @@ -234,8 +224,6 @@ ParamNotebook::ParamNotebook(const gchar * name, Inkscape::XML::Node * xml) : Parameter(name, text, description, hidden, indent, ext) { - pages = NULL; - // Read XML tree to add pages: if (xml != NULL) { Inkscape::XML::Node *child_repr = xml->firstChild(); @@ -249,7 +237,7 @@ ParamNotebook::ParamNotebook(const gchar * name, if (!strcmp(chname, "page")) { ParamNotebookPage * page; page = ParamNotebookPage::makepage(child_repr, ext); - if (page != NULL) pages = g_slist_append(pages, page); + if (page != NULL) pages.push_back(page); } child_repr = child_repr->next(); } @@ -258,9 +246,8 @@ ParamNotebook::ParamNotebook(const gchar * name, // Initialize _value with the current page const char * defaultval = NULL; // set first page as default - if (pages != NULL) { - ParamNotebookPage * defpage = reinterpret_cast<ParamNotebookPage *>(pages->data); - defaultval = defpage->name(); + if (!pages.empty()) { + defaultval = pages[0]->name(); } gchar * pref_name = this->pref_name(); @@ -277,12 +264,9 @@ ParamNotebook::ParamNotebook(const gchar * name, ParamNotebook::~ParamNotebook (void) { //destroy pages - for (GSList * list = pages; list != NULL; list = g_slist_next(list)) { - ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(list->data); + for (auto page:pages) { delete page; } - g_slist_free(pages); - g_free(_value); } @@ -304,12 +288,8 @@ ParamNotebook::~ParamNotebook (void) */ const gchar *ParamNotebook::set(const int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) { - ParamNotebookPage * page = NULL; - int i = 0; - for (GSList * list = pages; (list != NULL) && (i <= in); list = g_slist_next(list)) { - page = reinterpret_cast<ParamNotebookPage *>(list->data); - i++; - } + int i = in < pages.size() ? in : pages.size()-1; + ParamNotebookPage * page = pages[i]; if (page == NULL) return _value; @@ -336,8 +316,7 @@ void ParamNotebook::string(std::list <std::string> &list) const param_string += "\""; list.insert(list.end(), param_string); - for (GSList * pglist = pages; pglist != NULL; pglist = g_slist_next(pglist)) { - ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(pglist->data); + for (auto page:pages) { page->paramString(list); } } @@ -384,8 +363,7 @@ Parameter *ParamNotebook::get_param(const gchar * name) if (name == NULL) { throw Extension::param_not_exist(); } - for (GSList * pglist = pages; pglist != NULL; pglist = g_slist_next(pglist)) { - ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(pglist->data); + for (auto page:pages) { Parameter * subparam = page->get_param(name); if (subparam) { return subparam; @@ -395,26 +373,6 @@ Parameter *ParamNotebook::get_param(const gchar * name) return NULL; } -/** Search the parameter's name in the page content. */ -Parameter *ParamNotebookPage::get_param(const gchar * name) -{ - if (name == NULL) { - throw Extension::param_not_exist(); - } - if (this->parameters == NULL) { - // the list of parameters is empty - throw Extension::param_not_exist(); - } - - for (GSList * list = this->parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = static_cast<Parameter*>(list->data); - if (!strcmp(param->name(), name)) { - return param; - } - } - - return NULL; -} /** * Creates a Notebook widget for a notebook parameter. @@ -432,9 +390,8 @@ Gtk::Widget * ParamNotebook::get_widget(SPDocument * doc, Inkscape::XML::Node * // add pages (if any) int i = -1; int pagenr = i; - for (GSList * list = pages; list != NULL; list = g_slist_next(list)) { + for (auto page:pages) { i++; - ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(list->data); Gtk::Widget * widg = page->get_widget(doc, node, changeSignal); nb->append_page(*widg, _(page->get_text())); if (!strcmp(_value, page->name())) { diff --git a/src/extension/param/notebook.h b/src/extension/param/notebook.h index 8475de61d..f1bebd372 100644 --- a/src/extension/param/notebook.h +++ b/src/extension/param/notebook.h @@ -37,7 +37,34 @@ private: */ gchar * _value; - GSList * pages; /**< A table to store the pages with parameters for this notebook. + /** + * A class to represent the pages of a notebookparameter of an extension. + */ + class ParamNotebookPage : public Parameter { + private: + std::vector<Parameter *> parameters; /**< A table to store the parameters for this page. + This only gets created if there are parameters on this + page */ + + public: + static ParamNotebookPage * makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); + + ParamNotebookPage(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); + ~ParamNotebookPage(void); + + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); + void paramString (std::list <std::string> &list); + gchar * get_text (void) {return _text;}; + Parameter * get_param (const gchar * name); + }; /* class ParamNotebookPage */ + + + std::vector<ParamNotebookPage*> pages; /**< A table to store the pages with parameters for this notebook. This only gets created if there are pages in this notebook */ public: diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index a08ba6860..ca6dbb31d 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -42,20 +42,6 @@ namespace Extension { /* For internal use only. Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ -class optionentry { -public: - optionentry (Glib::ustring * val, Glib::ustring * txt) { - value = val; - text = txt; - } - ~optionentry() { - delete value; - delete text; - } - - Glib::ustring * value; - Glib::ustring * text; -}; ParamRadioButton::ParamRadioButton(const gchar * name, const gchar * text, @@ -68,7 +54,6 @@ ParamRadioButton::ParamRadioButton(const gchar * name, : Parameter(name, text, description, hidden, indent, ext) , _value(0) , _mode(mode) - , choices(0) { // Read XML tree to add enumeration items: // printf("Extension Constructor: "); @@ -105,7 +90,7 @@ ParamRadioButton::ParamRadioButton(const gchar * name, } if ( (newtext) && (newvalue) ) { // logical error if this is not true here - choices = g_slist_append( choices, new optionentry(newvalue, newtext) ); + choices.push_back(new optionentry(newvalue, newtext)); } } child_repr = child_repr->next(); @@ -115,8 +100,8 @@ ParamRadioButton::ParamRadioButton(const gchar * name, // Initialize _value with the default value from xml // for simplicity : default to the contents of the first xml-child const char * defaultval = NULL; - if (choices) { - defaultval = (static_cast<optionentry*> (choices->data))->value->c_str(); + if (!choices.empty()) { + defaultval = (static_cast<optionentry*> (choices[0]))->value->c_str(); } gchar * pref_name = this->pref_name(); @@ -135,11 +120,9 @@ ParamRadioButton::ParamRadioButton(const gchar * name, ParamRadioButton::~ParamRadioButton (void) { //destroy choice strings - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - delete (reinterpret_cast<optionentry *>(list->data)); + for(auto i:choices) { + delete i; } - g_slist_free(choices); - g_free(_value); } @@ -166,8 +149,7 @@ const gchar *ParamRadioButton::set(const gchar * in, SPDocument * /*doc*/, Inksc } Glib::ustring * settext = NULL; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - optionentry * entr = reinterpret_cast<optionentry *>(list->data); + for (auto entr:choices) { if ( !entr->value->compare(in) ) { settext = entr->value; break; // break out of for loop @@ -278,8 +260,7 @@ Glib::ustring ParamRadioButton::value_from_label(const Glib::ustring label) { Glib::ustring value = ""; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - optionentry * entr = reinterpret_cast<optionentry *>(list->data); + for ( auto entr:choices) { if ( !entr->text->compare(label) ) { value = *(entr->value); break; @@ -319,8 +300,7 @@ Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node // add choice strings as radiobuttons // and select last selected option (_value) Gtk::RadioButtonGroup group; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - optionentry * entr = reinterpret_cast<optionentry *>(list->data); + for (auto entr:choices) { Glib::ustring * text = entr->text; switch ( _mode ) { case MINIMAL: diff --git a/src/extension/param/radiobutton.h b/src/extension/param/radiobutton.h index b91b11ea3..e3ced8eb8 100644 --- a/src/extension/param/radiobutton.h +++ b/src/extension/param/radiobutton.h @@ -27,6 +27,7 @@ namespace Extension { class Extension; + // \brief A class to represent a radiobutton parameter of an extension class ParamRadioButton : public Parameter { public: @@ -63,7 +64,24 @@ private: It is the value of the current selected string */ gchar * _value; AppearanceMode _mode; - GSList * choices; /**< A table to store the choice strings */ + + /* For internal use only. + Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ + class optionentry { + public: + optionentry (Glib::ustring * val, Glib::ustring * txt) { + value = val; + text = txt; + } + ~optionentry() { + delete value; + delete text; + } + Glib::ustring * value; + Glib::ustring * text; + }; + + std::vector<optionentry*> choices; /**< A table to store the choice strings */ }; /* class ParamRadioButton */ diff --git a/src/extension/plugins/grid2/CMakeLists.txt b/src/extension/plugins/grid2/CMakeLists.txt index f39e259de..eb200e96e 100644 --- a/src/extension/plugins/grid2/CMakeLists.txt +++ b/src/extension/plugins/grid2/CMakeLists.txt @@ -2,7 +2,7 @@ set(grid_PART_SRCS grid.cpp) include_directories( ${CMAKE_BINARY_DIR}/src ) -add_library(grid2 SHARED ${grid_PART_SRCS}) +add_library(grid2 SHARED EXCLUDE_FROM_ALL ${grid_PART_SRCS}) target_link_libraries(grid2 inkscape_base) |
