From a7f2b2ba3f13ceb60376802f4a31e104153839e8 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Tue, 17 Feb 2015 03:00:37 +0100 Subject: At first, I was thinking "I just have to go to the selection file, and change that GSList* with a std::list, then resolve the few problems" So, i tried that. And I will continue tomorrow, and the days after, on and on. (bzr r13922.1.1) --- src/conn-avoid-ref.cpp | 5 +- src/desktop-style.cpp | 120 ++-- src/desktop-style.h | 25 +- src/extension/execution-env.cpp | 8 +- src/extension/implementation/implementation.cpp | 7 +- src/extension/implementation/script.cpp | 7 +- src/extension/internal/bitmap/imagemagick.cpp | 16 +- src/extension/internal/bluredge.cpp | 7 +- src/extension/internal/cairo-renderer.cpp | 8 +- src/extension/internal/filter/filter.cpp | 8 +- src/extension/internal/grid.cpp | 7 +- src/extension/internal/latex-text-renderer.cpp | 8 +- src/file.cpp | 6 +- src/filter-chemistry.cpp | 2 +- src/gradient-chemistry.cpp | 12 +- src/gradient-drag.cpp | 17 +- src/graphlayout.cpp | 10 +- src/graphlayout.h | 4 +- src/helper/png-write.cpp | 12 +- src/helper/png-write.h | 9 +- src/live_effects/lpe-knot.cpp | 6 +- src/main.cpp | 23 +- src/object-snapper.cpp | 5 +- src/path-chemistry.cpp | 125 ++-- src/path-chemistry.h | 2 +- src/removeoverlap.cpp | 12 +- src/removeoverlap.h | 2 +- src/selcue.cpp | 19 +- src/selection-chemistry.cpp | 779 +++++++++++------------- src/selection-chemistry.h | 11 +- src/selection-describer.cpp | 34 +- src/selection.cpp | 159 +++-- src/selection.h | 38 +- src/seltrans.cpp | 54 +- src/seltrans.h | 2 +- src/snap.cpp | 14 +- src/snap.h | 8 +- src/sp-conn-end.cpp | 5 +- src/sp-defs.cpp | 9 +- src/sp-filter.cpp | 9 +- src/sp-item-group.cpp | 91 ++- src/sp-item-group.h | 5 +- src/sp-lpe-item.cpp | 30 +- src/sp-marker.cpp | 6 +- src/sp-marker.h | 2 +- src/sp-object.cpp | 6 +- src/sp-object.h | 10 +- src/sp-pattern.cpp | 6 +- src/sp-pattern.h | 2 +- src/sp-switch.cpp | 24 +- src/sp-switch.h | 2 +- src/splivarot.cpp | 102 ++-- src/text-chemistry.cpp | 83 ++- src/text-editing.cpp | 7 +- src/trace/trace.cpp | 8 +- src/ui/clipboard.cpp | 33 +- src/ui/dialog/align-and-distribute.cpp | 87 +-- src/ui/dialog/clonetiler.cpp | 14 +- src/ui/dialog/export.cpp | 28 +- src/ui/dialog/filter-effects-dialog.cpp | 27 +- src/ui/dialog/find.cpp | 92 +-- src/ui/dialog/find.h | 11 +- src/ui/dialog/glyphs.cpp | 12 +- src/ui/interface.cpp | 17 +- src/unclump.cpp | 57 +- src/unclump.h | 3 +- src/vanishing-point.cpp | 26 +- src/widgets/arc-toolbar.cpp | 33 +- src/widgets/connector-toolbar.cpp | 16 +- src/widgets/fill-style.cpp | 32 +- src/widgets/gradient-toolbar.cpp | 15 +- src/widgets/mesh-toolbar.cpp | 10 +- src/widgets/rect-toolbar.cpp | 18 +- src/widgets/spiral-toolbar.cpp | 16 +- src/widgets/star-toolbar.cpp | 38 +- src/widgets/stroke-style.cpp | 29 +- src/widgets/stroke-style.h | 2 +- src/widgets/text-toolbar.cpp | 34 +- 78 files changed, 1283 insertions(+), 1365 deletions(-) (limited to 'src') diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp index c13b9a5d3..f2cde352c 100644 --- a/src/conn-avoid-ref.cpp +++ b/src/conn-avoid-ref.cpp @@ -252,8 +252,9 @@ static std::vector approxItemWithPoints(SPItem const *item, const G { SPGroup* group = SP_GROUP(item); // consider all first-order children - for (GSList const* i = sp_item_group_item_list(group); i != NULL; i = i->next) { - SPItem* child_item = SP_ITEM(i->data); + SelContainer itemlist = sp_item_group_item_list(group); + for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + SPItem* child_item = SP_ITEM(*i); std::vector child_points = approxItemWithPoints(child_item, item_transform * child_item->transform); poly_points.insert(poly_points.end(), child_points.begin(), child_points.end()); } diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index ee9fa39ec..39dfad44b 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -194,10 +194,10 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_repr_css_merge(css_write, css); sp_css_attr_unset_uris(css_write); prefs->mergeStyle("/desktop/style", css_write); - - for (const GSList *i = desktop->selection->itemList(); i != NULL; i = i->next) { + SelContainer const itemlist = desktop->selection->itemList(); + for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { /* last used styles for 3D box faces are stored separately */ - SPObject *obj = reinterpret_cast(i->data); // TODO unsafe until Selection is refactored. + SPObject *obj = reinterpret_cast(*i); // TODO unsafe until Selection is refactored. Box3DSide *side = dynamic_cast(obj); if (side) { const char * descr = box3d_side_axes_string(side); @@ -234,8 +234,9 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_repr_css_merge(css_no_text, css); css_no_text = sp_css_attr_unset_text(css_no_text); - for (GSList const *i = desktop->selection->itemList(); i != NULL; i = i->next) { - SPItem *item = reinterpret_cast(i->data); + SelContainer const itemlist = desktop->selection->itemList(); + for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + SPItem *item = reinterpret_cast(*i); // If not text, don't apply text attributes (can a group have text attributes? Yes! FIXME) if (isTextualItem(item)) { @@ -438,17 +439,16 @@ sp_desktop_get_font_size_tool(SPDesktop *desktop) /** Determine average stroke width, simple method */ // see TODO in dialogs/stroke-style.cpp on how to get rid of this eventually gdouble -stroke_average_width (GSList const *objects) +stroke_average_width (const SelContainer &objects) { - if (g_slist_length ((GSList *) objects) == 0) + if (objects.empty()) return Geom::infinity(); gdouble avgwidth = 0.0; bool notstroked = true; int n_notstroked = 0; - - for (GSList const *l = objects; l != NULL; l = l->next) { - SPObject *obj = reinterpret_cast(l->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); SPItem *item = dynamic_cast(obj); if (!item) { continue; @@ -471,7 +471,7 @@ stroke_average_width (GSList const *objects) if (notstroked) return Geom::infinity(); - return avgwidth / (g_slist_length ((GSList *) objects) - n_notstroked); + return avgwidth / (objects.size() - n_notstroked); } static bool vectorsClose( std::vector const &lhs, std::vector const &rhs ) @@ -492,9 +492,9 @@ static bool vectorsClose( std::vector const &lhs, std::vector co * Write to style_res the average fill or stroke of list of objects, if applicable. */ int -objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill) +objects_query_fillstroke (const SelContainer &objects, SPStyle *style_res, bool const isfill) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -514,8 +514,8 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill prev[0] = prev[1] = prev[2] = 0.0; bool same_color = true; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; } @@ -674,7 +674,7 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill } // Not color - if (g_slist_length(objects) > 1) { + if (objects.size() > 1) { return QUERY_STYLE_MULTIPLE_SAME; } else { return QUERY_STYLE_SINGLE; @@ -685,9 +685,9 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill * Write to style_res the average opacity of a list of objects. */ int -objects_query_opacity (GSList *objects, SPStyle *style_res) +objects_query_opacity (const SelContainer &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -698,8 +698,8 @@ objects_query_opacity (GSList *objects, SPStyle *style_res) guint opacity_items = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; } @@ -739,9 +739,9 @@ objects_query_opacity (GSList *objects, SPStyle *style_res) * Write to style_res the average stroke width of a list of objects. */ int -objects_query_strokewidth (GSList *objects, SPStyle *style_res) +objects_query_strokewidth (const SelContainer &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -754,8 +754,8 @@ objects_query_strokewidth (GSList *objects, SPStyle *style_res) int n_stroked = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; } @@ -815,9 +815,9 @@ objects_query_strokewidth (GSList *objects, SPStyle *style_res) * Write to style_res the average miter limit of a list of objects. */ int -objects_query_miterlimit (GSList *objects, SPStyle *style_res) +objects_query_miterlimit (const SelContainer &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -828,8 +828,8 @@ objects_query_miterlimit (GSList *objects, SPStyle *style_res) gdouble prev_ml = -1; bool same_ml = true; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!dynamic_cast(obj)) { continue; } @@ -875,9 +875,9 @@ objects_query_miterlimit (GSList *objects, SPStyle *style_res) * Write to style_res the stroke cap of a list of objects. */ int -objects_query_strokecap (GSList *objects, SPStyle *style_res) +objects_query_strokecap (const SelContainer &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -887,8 +887,8 @@ objects_query_strokecap (GSList *objects, SPStyle *style_res) bool same_cap = true; int n_stroked = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!dynamic_cast(obj)) { continue; } @@ -929,9 +929,9 @@ objects_query_strokecap (GSList *objects, SPStyle *style_res) * Write to style_res the stroke join of a list of objects. */ int -objects_query_strokejoin (GSList *objects, SPStyle *style_res) +objects_query_strokejoin (const SelContainer &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -941,8 +941,8 @@ objects_query_strokejoin (GSList *objects, SPStyle *style_res) bool same_join = true; int n_stroked = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!dynamic_cast(obj)) { continue; } @@ -984,7 +984,7 @@ objects_query_strokejoin (GSList *objects, SPStyle *style_res) * Write to style_res the average font size and spacing of objects. */ int -objects_query_fontnumbers (GSList *objects, SPStyle *style_res) +objects_query_fontnumbers (const SelContainer &objects, SPStyle *style_res) { bool different = false; @@ -1004,8 +1004,8 @@ objects_query_fontnumbers (GSList *objects, SPStyle *style_res) int texts = 0; int no_size = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!isTextualItem(obj)) { continue; @@ -1116,15 +1116,15 @@ objects_query_fontnumbers (GSList *objects, SPStyle *style_res) * Write to style_res the average font style of objects. */ int -objects_query_fontstyle (GSList *objects, SPStyle *style_res) +objects_query_fontstyle (const SelContainer &objects, SPStyle *style_res) { bool different = false; bool set = false; int texts = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!isTextualItem(obj)) { continue; @@ -1173,7 +1173,7 @@ objects_query_fontstyle (GSList *objects, SPStyle *style_res) * Write to style_res the baseline numbers. */ static int -objects_query_baselines (GSList *objects, SPStyle *style_res) +objects_query_baselines (const SelContainer &objects, SPStyle *style_res) { bool different = false; @@ -1192,8 +1192,8 @@ objects_query_baselines (GSList *objects, SPStyle *style_res) int texts = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!isTextualItem(obj)) { continue; @@ -1269,7 +1269,7 @@ objects_query_baselines (GSList *objects, SPStyle *style_res) * Write to style_res the average font family of objects. */ int -objects_query_fontfamily (GSList *objects, SPStyle *style_res) +objects_query_fontfamily (const SelContainer &objects, SPStyle *style_res) { bool different = false; int texts = 0; @@ -1280,8 +1280,8 @@ objects_query_fontfamily (GSList *objects, SPStyle *style_res) } style_res->font_family.set = FALSE; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; if (!isTextualItem(obj)) { @@ -1325,7 +1325,7 @@ objects_query_fontfamily (GSList *objects, SPStyle *style_res) } static int -objects_query_fontspecification (GSList *objects, SPStyle *style_res) +objects_query_fontspecification (const SelContainer &objects, SPStyle *style_res) { bool different = false; int texts = 0; @@ -1336,8 +1336,8 @@ objects_query_fontspecification (GSList *objects, SPStyle *style_res) } style_res->font_specification.set = FALSE; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; if (!isTextualItem(obj)) { @@ -1385,7 +1385,7 @@ objects_query_fontspecification (GSList *objects, SPStyle *style_res) } static int -objects_query_blend (GSList *objects, SPStyle *style_res) +objects_query_blend (const SelContainer &objects, SPStyle *style_res) { const int empty_prev = -2; const int complex_filter = 5; @@ -1394,8 +1394,8 @@ objects_query_blend (GSList *objects, SPStyle *style_res) bool same_blend = true; guint items = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; } @@ -1471,9 +1471,9 @@ objects_query_blend (GSList *objects, SPStyle *style_res) * Write to style_res the average blurring of a list of objects. */ int -objects_query_blur (GSList *objects, SPStyle *style_res) +objects_query_blur (const SelContainer &objects, SPStyle *style_res) { - if (g_slist_length(objects) == 0) { + if (objects.empty()) { /* No objects, set empty */ return QUERY_STYLE_NOTHING; } @@ -1484,8 +1484,8 @@ objects_query_blur (GSList *objects, SPStyle *style_res) guint blur_items = 0; guint items = 0; - for (GSList const *i = objects; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; } @@ -1553,7 +1553,7 @@ objects_query_blur (GSList *objects, SPStyle *style_res) * the result to style, return appropriate flag. */ int -sp_desktop_query_style_from_list (GSList *list, SPStyle *style, int property) +sp_desktop_query_style_from_list (const SelContainer &list, SPStyle *style, int property) { if (property == QUERY_STYLE_PROPERTY_FILL) { return objects_query_fillstroke (list, style, true); @@ -1606,7 +1606,7 @@ sp_desktop_query_style(SPDesktop *desktop, SPStyle *style, int property) // otherwise, do querying and averaging over selection if (desktop->selection != NULL) { - return sp_desktop_query_style_from_list ((GSList *) desktop->selection->itemList(), style, property); + return sp_desktop_query_style_from_list (desktop->selection->itemList(), style, property); } return QUERY_STYLE_NOTHING; diff --git a/src/desktop-style.h b/src/desktop-style.h index 40ca27e9e..0e40a2652 100644 --- a/src/desktop-style.h +++ b/src/desktop-style.h @@ -13,6 +13,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include "selection.h" // SelContainer class ColorRGBA; class SPCSSAttr; class SPDesktop; @@ -64,21 +65,21 @@ guint32 sp_desktop_get_color_tool(SPDesktop *desktop, Glib::ustring const &tool, double sp_desktop_get_font_size_tool (SPDesktop *desktop); void sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, Glib::ustring const &tool, bool with_text); -gdouble stroke_average_width (GSList const *objects); +gdouble stroke_average_width (const SelContainer &objects); -int objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill); -int objects_query_fontnumbers (GSList *objects, SPStyle *style_res); -int objects_query_fontstyle (GSList *objects, SPStyle *style_res); -int objects_query_fontfamily (GSList *objects, SPStyle *style_res); -int objects_query_opacity (GSList *objects, SPStyle *style_res); -int objects_query_strokewidth (GSList *objects, SPStyle *style_res); -int objects_query_miterlimit (GSList *objects, SPStyle *style_res); -int objects_query_strokecap (GSList *objects, SPStyle *style_res); -int objects_query_strokejoin (GSList *objects, SPStyle *style_res); +int objects_query_fillstroke (const SelContainer &objects, SPStyle *style_res, bool const isfill); +int objects_query_fontnumbers (const SelContainer &objects, SPStyle *style_res); +int objects_query_fontstyle (const SelContainer &objects, SPStyle *style_res); +int objects_query_fontfamily (const SelContainer &objects, SPStyle *style_res); +int objects_query_opacity (const SelContainer &objects, SPStyle *style_res); +int objects_query_strokewidth (const SelContainer &objects, SPStyle *style_res); +int objects_query_miterlimit (const SelContainer &objects, SPStyle *style_res); +int objects_query_strokecap (const SelContainer &objects, SPStyle *style_res); +int objects_query_strokejoin (const SelContainer &objects, SPStyle *style_res); -int objects_query_blur (GSList *objects, SPStyle *style_res); +int objects_query_blur (const SelContainer &objects, SPStyle *style_res); -int sp_desktop_query_style_from_list (GSList *list, SPStyle *style, int property); +int sp_desktop_query_style_from_list (const SelContainer &list, SPStyle *style, int property); int sp_desktop_query_style(SPDesktop *desktop, SPStyle *style, int property); bool sp_desktop_query_style_all (SPDesktop *desktop, SPStyle *query); diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index 13b8d60c4..66a8c4358 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -64,14 +64,12 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Imp sp_namedview_document_from_window(desktop); if (desktop != NULL) { - Inkscape::Util::GSListConstIterator selected = - desktop->getSelection()->itemList(); - while ( selected != NULL ) { + SelContainer selected = desktop->getSelection()->itemList(); + for(SelContainer::const_iterator x=selected.begin();x!=selected.end();x++){ Glib::ustring selected_id; - selected_id = (*selected)->getId(); + selected_id = (*x)->getId(); _selected.insert(_selected.end(), selected_id); //std::cout << "Selected: " << selected_id << std::endl; - ++selected; } } diff --git a/src/extension/implementation/implementation.cpp b/src/extension/implementation/implementation.cpp index 52f63499a..6eff3ede3 100644 --- a/src/extension/implementation/implementation.cpp +++ b/src/extension/implementation/implementation.cpp @@ -48,11 +48,10 @@ Gtk::Widget *Implementation::prefs_effect(Inkscape::Extension::Effect *module, I SPDocument * current_document = view->doc(); using Inkscape::Util::GSListConstIterator; - // FIXME very unsafe cast - GSListConstIterator selected = ((SPDesktop *)view)->getSelection()->itemList(); + SelContainer selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node const* first_select = NULL; - if (selected != NULL) { - const SPItem * item = *selected; + if (!selected.empty()) { + const SPItem * item = SP_ITEM(selected.front()); first_select = item->getRepr(); } diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index bbc567f75..f396e9848 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -689,14 +689,13 @@ void Script::effect(Inkscape::Extension::Effect *module, return; } - Inkscape::Util::GSListConstIterator selected = + SelContainer selected = desktop->getSelection()->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer - while ( selected != NULL ) { + for(SelContainer::const_iterator x=selected.begin();x!=selected.end();x++){ Glib::ustring selected_id; selected_id += "--id="; - selected_id += (*selected)->getId(); + selected_id += (*x)->getId(); params.insert(params.begin(), selected_id); - ++selected; } file_listener fileout; diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index 76f35415e..87ef30887 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -70,8 +70,8 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : _imageItems(NULL) { SPDesktop *desktop = (SPDesktop*)view; - const GSList *selectedItemList = desktop->selection->itemList(); - int selectCount = g_slist_length((GSList *)selectedItemList); + const SelContainer selectedItemList = desktop->selection->itemList(); + int selectCount = selectedItemList.size(); // Init the data-holders _nodes = new Inkscape::XML::Node*[selectCount]; @@ -83,9 +83,8 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : _imageItems = new SPItem*[selectCount]; // Loop through selected items - for (; selectedItemList != NULL; selectedItemList = g_slist_next(selectedItemList)) - { - SPItem *item = SP_ITEM(selectedItemList->data); + for (SelContainer::const_iterator i=selectedItemList.begin();i!=selectedItemList.end();i++) { + SPItem *item = static_cast(*i); Inkscape::XML::Node *node = reinterpret_cast(item->getRepr()); if (!strcmp(node->name(), "image") || !strcmp(node->name(), "svg:image")) { @@ -243,11 +242,10 @@ ImageMagick::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::Vie using Inkscape::Util::GSListConstIterator; - // FIXME very unsafe cast - GSListConstIterator selected = ((SPDesktop *)view)->getSelection()->itemList(); + SelContainer selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; - if (selected != NULL) { - first_select = (*selected)->getRepr(); + if (!selected.empty()) { + first_select = (selected.front())->getRepr(); } return module->autogui(current_document, first_select, changeSignal); diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp index 3ce537d9f..138172715 100644 --- a/src/extension/internal/bluredge.cpp +++ b/src/extension/internal/bluredge.cpp @@ -65,13 +65,12 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View using Inkscape::Util::GSListConstIterator; // TODO need to properly refcount the items, at least - std::list items; - items.insert >(items.end(), selection->itemList(), NULL); + SelContainer items(selection->itemList()); selection->clear(); - for(std::list::iterator item = items.begin(); + for(SelContainer::iterator item = items.begin(); item != items.end(); ++item) { - SPItem * spitem = *item; + SPItem * spitem = static_cast(*item); std::vector new_items(steps); Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 1f48d2097..7ce5cdf8a 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -294,14 +294,14 @@ static void sp_group_render(SPGroup *group, CairoRenderContext *ctx) 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 = reinterpret_cast(l->data); + SelContainer l(group->childList(false)); + l.reverse(); + for(SelContainer::const_iterator x=l.begin();x!=l.end();x++){ + SPObject *o = reinterpret_cast(*x); SPItem *item = dynamic_cast(o); if (item) { renderer->renderItem(ctx, item); } - l = g_slist_remove (l, o); } } diff --git a/src/extension/internal/filter/filter.cpp b/src/extension/internal/filter/filter.cpp index a2c565699..821c023ac 100644 --- a/src/extension/internal/filter/filter.cpp +++ b/src/extension/internal/filter/filter.cpp @@ -125,17 +125,15 @@ void Filter::effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::Vie //printf("Calling filter effect\n"); Inkscape::Selection * selection = ((SPDesktop *)document)->selection; - using Inkscape::Util::GSListConstIterator; // TODO need to properly refcount the items, at least - std::list items; - items.insert >(items.end(), selection->itemList(), NULL); + SelContainer items(selection->itemList()); Inkscape::XML::Document * xmldoc = document->doc()->getReprDoc(); Inkscape::XML::Node * defsrepr = document->doc()->getDefs()->getRepr(); - for(std::list::iterator item = items.begin(); + for(SelContainer::iterator item = items.begin(); item != items.end(); ++item) { - SPItem * spitem = *item; + SPItem * spitem = static_cast(*item); Inkscape::XML::Node * node = spitem->getRepr(); SPCSSAttr * css = sp_repr_css_attr(node, "style"); diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index 270edfe44..4c12f629c 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -192,11 +192,10 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View using Inkscape::Util::GSListConstIterator; - // FIXME very unsafe cast - GSListConstIterator selected = ((SPDesktop *)view)->getSelection()->itemList(); + SelContainer selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; - if (selected != NULL) { - first_select = (*selected)->getRepr(); + if (!selected.empty()) { + first_select = (selected.front())->getRepr(); } return module->autogui(current_document, first_select, changeSignal); diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index ab0733848..dab27a0e1 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -228,14 +228,14 @@ LaTeXTextRenderer::writePostamble() void LaTeXTextRenderer::sp_group_render(SPGroup *group) { - GSList *l = g_slist_reverse(group->childList(false)); - while (l) { - SPObject *o = reinterpret_cast(l->data); + SelContainer l = (group->childList(false)); + l.reverse(); + for(SelContainer::const_iterator x=l.begin();x!=l.end();x++){ + SPObject *o = reinterpret_cast(*x); SPItem *item = dynamic_cast(o); if (item) { renderItem(item); } - l = g_slist_remove (l, o); } } diff --git a/src/file.cpp b/src/file.cpp index 72516d776..4325c838b 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1063,7 +1063,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) desktop->doc()->importDefs(clipdoc); // copy objects - GSList *pasted_objects = NULL; + std::list pasted_objects; for (Inkscape::XML::Node *obj = root->firstChild() ; obj ; obj = obj->next()) { // Don't copy metadata, defs, named views and internal clipboard contents to the document if (!strcmp(obj->name(), "svg:defs")) { @@ -1082,7 +1082,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) target_parent->appendChild(obj_copy); Inkscape::GC::release(obj_copy); - pasted_objects = g_slist_prepend(pasted_objects, (gpointer) obj_copy); + pasted_objects.push_front(dynamic_cast(obj_copy)); } // Change the selection to the freshly pasted objects @@ -1123,8 +1123,6 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) sp_selection_move_relative(selection, offset); } - - g_slist_free(pasted_objects); } diff --git a/src/filter-chemistry.cpp b/src/filter-chemistry.cpp index 9298a1ffc..c89cf6220 100644 --- a/src/filter-chemistry.cpp +++ b/src/filter-chemistry.cpp @@ -23,9 +23,9 @@ #include "filter-chemistry.h" #include "filter-enums.h" - #include "filters/blend.h" #include "filters/gaussian-blur.h" +#include "selection.h" #include "sp-filter.h" #include "sp-filter-reference.h" #include "svg/css-ostringstream.h" diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index cf75f6cf0..5f1da6cf1 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1570,8 +1570,9 @@ void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTa { Inkscape::Selection *selection = desktop->getSelection(); - for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { - sp_item_gradient_invert_vector_color(SP_ITEM(i->data), fill_or_stroke); + const SelContainer list=selection->itemList(); + for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) { + sp_item_gradient_invert_vector_color(SP_ITEM(*i), fill_or_stroke); } // we did an undoable action @@ -1594,9 +1595,10 @@ void sp_gradient_reverse_selected_gradients(SPDesktop *desktop) if (drag && drag->selected) { drag->selected_reverse_vector(); } else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients) - for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { - sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_FILL); - sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_STROKE); + const SelContainer list=selection->itemList(); + for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) { + sp_item_gradient_reverse_vector(SP_ITEM(*i), Inkscape::FOR_FILL); + sp_item_gradient_reverse_vector(SP_ITEM(*i), Inkscape::FOR_STROKE); } } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 154b7339b..649928060 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -2082,9 +2082,9 @@ void GrDrag::updateDraggers() this->draggers = NULL; g_return_if_fail(this->selection != NULL); - - for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { - SPItem *item = SP_ITEM(i->data); + SelContainer list = this->selection->itemList(); + for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) { + SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; if (style && (style->fill.isPaintserver())) { @@ -2151,9 +2151,9 @@ void GrDrag::updateLines() g_return_if_fail(this->selection != NULL); - for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { - - SPItem *item = SP_ITEM(i->data); + SelContainer list = this->selection->itemList(); + for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) { + SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; @@ -2295,8 +2295,9 @@ void GrDrag::updateLevels() g_return_if_fail (this->selection != NULL); - for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { - SPItem *item = SP_ITEM(i->data); + SelContainer list = this->selection->itemList(); + for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) { + SPItem *item = SP_ITEM(*i); Geom::OptRect rect = item->desktopVisualBounds(); if (rect) { // Remember the edges of the bbox and the center axis diff --git a/src/graphlayout.cpp b/src/graphlayout.cpp index e5d61ab64..613440269 100644 --- a/src/graphlayout.cpp +++ b/src/graphlayout.cpp @@ -88,9 +88,9 @@ struct CheckProgress : TestConvergence { * Scans the items list and places those items that are * not connectors in filtered */ -void filterConnectors(GSList const *const items, list &filtered) { - for(GSList *i=(GSList *)items; i!=NULL; i=i->next) { - SPItem *item=SP_ITEM(i->data); +void filterConnectors(SelContainer const &items, list &filtered) { + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = SP_ITEM(*i); if(!isConnector(item)) { filtered.push_back(item); } @@ -101,8 +101,8 @@ void filterConnectors(GSList const *const items, list &filtered) { * connectors between them, and uses graph layout techniques to find * a nice layout */ -void graphlayout(GSList const *const items) { - if(!items) { +void graphlayout(SelContainer const &items) { + if(items.empty()) { return; } diff --git a/src/graphlayout.h b/src/graphlayout.h index 0ffb645b6..c38f9471c 100644 --- a/src/graphlayout.h +++ b/src/graphlayout.h @@ -19,10 +19,10 @@ typedef struct _GSList GSList; class SPItem; -void graphlayout(GSList const *const items); +void graphlayout(SelContainer const &items); bool isConnector(SPItem const *const item); -void filterConnectors(GSList const *const items, std::list &filtered); +void filterConnectors(SelContainer const &items, std::list &filtered); #endif // SEEN_GRAPHLAYOUT_H diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 32e50b537..55fef5a4c 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -361,19 +361,19 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v /** * Hide all items that are not listed in list, recursively, skipping groups and defs. */ -static void hide_other_items_recursively(SPObject *o, GSList *list, unsigned dkey) +static void hide_other_items_recursively(SPObject *o, const SelContainer &list, unsigned dkey) { if ( SP_IS_ITEM(o) && !SP_IS_DEFS(o) && !SP_IS_ROOT(o) && !SP_IS_GROUP(o) - && !g_slist_find(list, o) ) + && list.end()==find(list.begin(),list.end(),o)) { SP_ITEM(o)->invoke_hide(dkey); } // recurse - if (!g_slist_find(list, o)) { + if (list.end()==find(list.begin(),list.end(),o)) { for ( SPObject *child = o->firstChild() ; child; child = child->getNext() ) { hide_other_items_recursively(child, list, dkey); } @@ -387,7 +387,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned int (*status) (float, void *), void *data, bool force_overwrite, - GSList *items_only) + const SelContainer &items_only) { return sp_export_png_file(doc, filename, Geom::Rect(Geom::Point(x0,y0),Geom::Point(x1,y1)), width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only); @@ -399,7 +399,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned (*status)(float, void *), void *data, bool force_overwrite, - GSList *items_only) + const SelContainer &items_only) { g_return_val_if_fail(doc != NULL, EXPORT_ERROR); g_return_val_if_fail(filename != NULL, EXPORT_ERROR); @@ -457,7 +457,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, // We show all and then hide all items we don't want, instead of showing only requested items, // because that would not work if the shown item references something in defs - if (items_only) { + if (!items_only.empty()) { hide_other_items_recursively(doc->getRoot(), items_only, dkey); } diff --git a/src/helper/png-write.h b/src/helper/png-write.h index 8c04b25dc..47fad1b41 100644 --- a/src/helper/png-write.h +++ b/src/helper/png-write.h @@ -16,6 +16,11 @@ #include #include <2geom/forward.h> + +//should be in selection.h +typedef std::list SelContainer; + + class SPDocument; enum ExportResult { @@ -33,12 +38,12 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, double x0, double y0, double x1, double y1, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, GSList *items_only = NULL); + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const SelContainer &items_only = SelContainer()); ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, Geom::Rect const &area, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, GSList *items_only = NULL); + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const SelContainer &items_only = SelContainer()); #endif // SEEN_SP_PNG_WRITE_H diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 3876aa24b..95a6b16dd 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -505,9 +505,9 @@ LPEKnot::doEffect_path (std::vector const &path_in) static void collectPathsAndWidths (SPLPEItem const *lpeitem, std::vector &paths, std::vector &stroke_widths){ if (SP_IS_GROUP(lpeitem)) { - GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast(iter->data); + SelContainer item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); + for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = static_cast(*iter); if (SP_IS_LPE_ITEM(subitem)) { collectPathsAndWidths(SP_LPE_ITEM(subitem), paths, stroke_widths); } diff --git a/src/main.cpp b/src/main.cpp index 15576109d..25dc91f14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1156,7 +1156,7 @@ static int sp_process_file_list(GSList *fl) } if (sp_export_svg) { if (sp_export_text_to_path) { - GSList *items = NULL; + SelContainer items; SPRoot *root = doc->getRoot(); doc->ensureUpToDate(); for ( SPObject *iter = root->firstChild(); iter ; iter = iter->getNext()) { @@ -1166,17 +1166,17 @@ static int sp_process_file_list(GSList *fl) } te_update_layout_now_recursive(item); - items = g_slist_append(items, item); + items.push_back(item); } - GSList *selected = NULL; - GSList *to_select = NULL; + SelContainer selected; + SelContainer to_select; - sp_item_list_to_curves(items, &selected, &to_select); + sp_item_list_to_curves(items, selected, to_select); - g_slist_free (items); - g_slist_free (selected); - g_slist_free (to_select); + items.clear(); + selected.clear(); + to_select.clear(); } if(sp_export_id) { doc->ensureUpToDate(); @@ -1435,7 +1435,7 @@ static int sp_do_export_png(SPDocument *doc) g_warning ("--export-use-hints can only be used with --export-id or --export-area-drawing; ignored."); } - GSList *items = NULL; + SelContainer items; Geom::Rect area; if (sp_export_id || sp_export_area_drawing) { @@ -1459,7 +1459,7 @@ static int sp_do_export_png(SPDocument *doc) return 1; } - items = g_slist_prepend (items, SP_ITEM(o)); + items.push_front(SP_ITEM(o)); if (sp_export_id_only) { g_print("Exporting only object with id=\"%s\"; all other objects hidden\n", sp_export_id); @@ -1647,7 +1647,7 @@ static int sp_do_export_png(SPDocument *doc) if ((width >= 1) && (height >= 1) && (width <= PNG_UINT_31_MAX) && (height <= PNG_UINT_31_MAX)) { if( sp_export_png_file(doc, path.c_str(), area, width, height, dpi, - dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : NULL) == 1 ) { + dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : SelContainer()) == 1 ) { g_print("Bitmap saved as: %s\n", filename.c_str()); } else { g_warning("Bitmap failed to save to: %s", filename.c_str()); @@ -1657,7 +1657,6 @@ static int sp_do_export_png(SPDocument *doc) } } - g_slist_free (items); return retcode; } diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 338f91463..960b5087b 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -237,8 +237,9 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, // current selection (see the comment in SelTrans::centerRequest()) bool old_pref2 = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_ROTATION_CENTER); if (old_pref2) { - for ( GSList const *itemlist = _snapmanager->getRotationCenterSource(); itemlist != NULL; itemlist = g_slist_next(itemlist) ) { - if ((*i).item == reinterpret_cast(itemlist->data)) { + SelContainer rotationSource=_snapmanager->getRotationCenterSource(); + for ( SelContainer::const_iterator itemlist=rotationSource.begin();itemlist!=rotationSource.end();itemlist++) { + if ((*i).item == reinterpret_cast(*itemlist)) { // don't snap to this item's rotation center _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_ROTATION_CENTER, false); break; diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 5f6e1495b..a5e71b720 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -44,13 +44,22 @@ using Inkscape::DocumentUndo; + +inline bool less_than_objects(SPObject const *first, SPObject const *second) +{ + return sp_repr_compare_position(first->getRepr(), + second->getRepr())<0; +} + void sp_selected_path_combine(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); SPDocument *doc = desktop->getDocument(); + + SelContainer items(selection->itemList()); - if (g_slist_length((GSList *) selection->itemList()) < 1) { + if (items.size() < 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to combine.")); return; } @@ -59,28 +68,26 @@ sp_selected_path_combine(SPDesktop *desktop) // set "busy" cursor desktop->setWaitingCursor(); - GSList *items = g_slist_copy((GSList *) selection->itemList()); - items = sp_degroup_list (items); // descend into any groups in selection - GSList *to_paths = NULL; - for (GSList *i = items; i != NULL; i = i->next) { - SPItem *item = (SPItem *) i->data; + SelContainer to_paths; + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + SPItem *item = (SPItem *) (*i); if (!dynamic_cast(item) && !dynamic_cast(item)) { - to_paths = g_slist_prepend(to_paths, item); + to_paths.push_front(item); } } - GSList *converted = NULL; - bool did = sp_item_list_to_curves(to_paths, &items, &converted); - g_slist_free(to_paths); - for (GSList *i = converted; i != NULL; i = i->next) - items = g_slist_prepend(items, doc->getObjectByRepr((Inkscape::XML::Node*)(i->data))); + SelContainer converted; + bool did = sp_item_list_to_curves(to_paths, items, converted); + to_paths.clear(); + for (SelContainer::const_iterator i=converted.begin();i!=converted.end();i++) + items.push_front(doc->getObjectByRepr((Inkscape::XML::Node*)(*i))); items = sp_degroup_list (items); // converting to path may have added more groups, descend again - items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); - items = g_slist_reverse(items); - assert(items); // cannot be NULL because of list length check at top of function + items.sort(less_than_objects); + items.reverse(); + assert(!items.empty()); // cannot be NULL because of list length check at top of function // remember the position, id, transform and style of the topmost path, they will be assigned to the combined one gint position = 0; @@ -97,9 +104,9 @@ sp_selected_path_combine(SPDesktop *desktop) selection->clear(); } - for (GSList *i = items; i != NULL; i = i->next) { // going from top to bottom + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = (SPItem *) i->data; + SPItem *item = (SPItem *) (*i); SPPath *path = dynamic_cast(item); if (!path) { continue; @@ -136,7 +143,6 @@ sp_selected_path_combine(SPDesktop *desktop) } } - g_slist_free(items); if (did) { first->deleteObject(false); @@ -200,11 +206,10 @@ sp_selected_path_break_apart(SPDesktop *desktop) bool did = false; - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { + SelContainer itemlist(selection->itemList()); + for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = (SPItem *) items->data; + SPItem *item = (SPItem *) (*i); SPPath *path = dynamic_cast(item); if (!path) { @@ -241,7 +246,7 @@ sp_selected_path_break_apart(SPDesktop *desktop) curve->unref(); - GSList *reprs = NULL; + SelContainer reprs; for (GSList *l = list; l != NULL; l = l->next) { curve = (SPCurve *) l->data; @@ -267,14 +272,14 @@ sp_selected_path_break_apart(SPDesktop *desktop) if (l == list) repr->setAttribute("id", id); - reprs = g_slist_prepend (reprs, repr); + reprs.push_front(dynamic_cast(repr)); Inkscape::GC::release(repr); } selection->setReprList(reprs); - g_slist_free(reprs); + reprs.clear(); g_slist_free(list); g_free(style); g_free(path_effect); @@ -307,18 +312,18 @@ sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, b desktop->setWaitingCursor(); } - GSList *selected = g_slist_copy((GSList *) selection->itemList()); - GSList *to_select = NULL; + SelContainer selected(selection->itemList()); + SelContainer to_select; selection->clear(); - GSList *items = g_slist_copy(selected); + SelContainer items(selected); - did = sp_item_list_to_curves(items, &selected, &to_select); + did = sp_item_list_to_curves(items, selected, to_select); - g_slist_free (items); + items.clear(); selection->setReprList(to_select); selection->addList(selected); - g_slist_free (to_select); - g_slist_free (selected); + to_select.clear(); + selected.clear(); if (interactive && desktop) { desktop->clearWaitingCursor(); @@ -341,33 +346,29 @@ void sp_selected_to_lpeitems(SPDesktop *desktop) return; } - GSList *selected = g_slist_copy((GSList *) selection->itemList()); - GSList *to_select = NULL; + SelContainer selected(selection->itemList()); + SelContainer to_select; selection->clear(); - GSList *items = g_slist_copy(selected); + SelContainer items(selected); + - sp_item_list_to_curves(items, &selected, &to_select, true); + sp_item_list_to_curves(items, selected, to_select, true); - g_slist_free(items); - items = 0; + items.clear(); selection->setReprList(to_select); selection->addList(selected); - g_slist_free(to_select); - to_select = 0; - g_slist_free(selected); - selected = 0; + to_select.clear(); + selected.clear(); } bool -sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems) +sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelContainer &to_select, bool skip_all_lpeitems) { bool did = false; - for (; - items != NULL; - items = items->next) { + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = dynamic_cast(static_cast(items->data)); + SPItem *item = dynamic_cast(static_cast(*i)); g_assert(item != NULL); SPDocument *document = item->document; @@ -398,9 +399,9 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec Inkscape::XML::Node *repr = box3d_convert_to_group(box)->getRepr(); if (repr) { - *to_select = g_slist_prepend (*to_select, repr); + to_select.push_front(dynamic_cast(repr)); did = true; - *selected = g_slist_remove (*selected, item); + selected.remove(item); } continue; @@ -408,17 +409,17 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec if (group) { group->removeAllPathEffects(true); - GSList *item_list = sp_item_group_item_list(group); + SelContainer item_list = sp_item_group_item_list(group); - GSList *item_to_select = NULL; - GSList *item_selected = NULL; + SelContainer item_to_select; + SelContainer item_selected; - if (sp_item_list_to_curves(item_list, &item_selected, &item_to_select)) + if (sp_item_list_to_curves(item_list, item_selected, item_to_select)) did = true; - g_slist_free(item_list); - g_slist_free(item_to_select); - g_slist_free(item_selected); + item_list.clear(); + item_to_select.clear(); + item_selected.clear(); continue; } @@ -428,7 +429,7 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec continue; did = true; - *selected = g_slist_remove (*selected, item); + selected.remove(item); // remember the position of the item gint pos = item->getRepr()->position(); @@ -470,7 +471,7 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec /* Buglet: We don't re-add the (new version of the) object to the selection of any other * desktops where it was previously selected. */ - *to_select = g_slist_prepend (*to_select, repr); + to_select.push_front(dynamic_cast(repr)); Inkscape::GC::release(repr); } @@ -612,9 +613,9 @@ void sp_selected_path_reverse(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); - GSList *items = (GSList *) selection->itemList(); + SelContainer items = selection->itemList(); - if (!items) { + if (items.empty()) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select path(s) to reverse.")); return; } @@ -626,9 +627,9 @@ sp_selected_path_reverse(SPDesktop *desktop) bool did = false; desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths...")); - for (GSList *i = items; i != NULL; i = i->next) { + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ - SPPath *path = dynamic_cast(static_cast(i->data)); + SPPath *path = dynamic_cast(static_cast(*i)); if (!path) { continue; } diff --git a/src/path-chemistry.h b/src/path-chemistry.h index a2150440c..388268af4 100644 --- a/src/path-chemistry.h +++ b/src/path-chemistry.h @@ -33,7 +33,7 @@ void sp_selected_path_to_curves (Inkscape::Selection *selection, SPDesktop *desk void sp_selected_to_lpeitems(SPDesktop *desktop); Inkscape::XML::Node *sp_selected_item_to_curved_repr(SPItem *item, guint32 text_grouping_policy); void sp_selected_path_reverse (SPDesktop *desktop); -bool sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems = false); +bool sp_item_list_to_curves(const SelContainer &items, SelContainer &selected, SelContainer &to_select, bool skip_all_lpeitems = false); #endif // SEEN_PATH_CHEMISTRY_H diff --git a/src/removeoverlap.cpp b/src/removeoverlap.cpp index ba5740e55..9009de5e9 100644 --- a/src/removeoverlap.cpp +++ b/src/removeoverlap.cpp @@ -38,20 +38,20 @@ namespace { * such that rectangular bounding boxes are separated by at least xGap * horizontally and yGap vertically */ -void removeoverlap(GSList const *const items, double const xGap, double const yGap) { +void removeoverlap(SelContainer const &items, double const xGap, double const yGap) { using Inkscape::Util::GSListConstIterator; - std::list selected; - selected.insert >(selected.end(), items, NULL); + SelContainer selected(items); std::vector records; std::vector rs; Geom::Point const gap(xGap, yGap); - for (std::list::iterator it(selected.begin()); + for (SelContainer::iterator it(selected.begin()); it != selected.end(); ++it) { + SPItem* item=static_cast(*it); using Geom::X; using Geom::Y; - Geom::OptRect item_box((*it)->desktopVisualBounds()); + Geom::OptRect item_box((item)->desktopVisualBounds()); if (item_box) { Geom::Point min(item_box->min() - .5*gap); Geom::Point max(item_box->max() + .5*gap); @@ -67,7 +67,7 @@ void removeoverlap(GSList const *const items, double const xGap, double const yG min[Y] = max[Y] = (min[Y] + max[Y])/2; } Rectangle *vspc_rect = new Rectangle(min[X], max[X], min[Y], max[Y]); - records.push_back(Record(*it, item_box->midpoint(), vspc_rect)); + records.push_back(Record(item, item_box->midpoint(), vspc_rect)); rs.push_back(vspc_rect); } } diff --git a/src/removeoverlap.h b/src/removeoverlap.h index 7109c9513..d050ca9ef 100644 --- a/src/removeoverlap.h +++ b/src/removeoverlap.h @@ -15,6 +15,6 @@ typedef struct _GSList GSList; -void removeoverlap(GSList const *items, double xGap, double yGap); +void removeoverlap(SelContainer const &items, double xGap, double yGap); #endif // SEEN_REMOVEOVERLAP_H diff --git a/src/selcue.cpp b/src/selcue.cpp index d2fa0970a..0fab6e5a8 100644 --- a/src/selcue.cpp +++ b/src/selcue.cpp @@ -96,15 +96,16 @@ void Inkscape::SelCue::_updateItemBboxes(Inkscape::Preferences *prefs) void Inkscape::SelCue::_updateItemBboxes(gint mode, int prefs_bbox) { - GSList const *items = _selection->itemList(); - if (_item_bboxes.size() != g_slist_length((GSList *) items)) { + const SelContainer items = _selection->itemList(); + if (_item_bboxes.size() != items.size()) { _newItemBboxes(); return; } int bcount = 0; - for (GSList const *l = _selection->itemList(); l != NULL; l = l->next) { - SPItem *item = static_cast(l->data); + SelContainer ll=_selection->itemList(); + for (SelContainer::const_iterator l=ll.begin();l!=ll.end();l++) { + SPItem *item = static_cast(*l); SPCanvasItem* box = _item_bboxes[bcount ++]; if (box) { @@ -145,8 +146,9 @@ void Inkscape::SelCue::_newItemBboxes() int prefs_bbox = prefs->getBool("/tools/bounding_box"); - for (GSList const *l = _selection->itemList(); l != NULL; l = l->next) { - SPItem *item = static_cast(l->data); + SelContainer ll=_selection->itemList(); + for (SelContainer::const_iterator l=ll.begin();l!=ll.end();l++) { + SPItem *item = static_cast(*l); Geom::OptRect const b = (prefs_bbox == 0) ? item->desktopVisualBounds() : item->desktopGeometricBounds(); @@ -199,8 +201,9 @@ void Inkscape::SelCue::_newTextBaselines() } _text_baselines.clear(); - for (GSList const *l = _selection->itemList(); l != NULL; l = l->next) { - SPItem *item = static_cast(l->data); + SelContainer ll=_selection->itemList(); + for (SelContainer::const_iterator l=ll.begin();l!=ll.end();l++) { + SPItem *item = static_cast(*l); SPCanvasItem* baseline_point = NULL; if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { // visualize baseline diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index c9837aabe..f20df1594 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -279,25 +279,23 @@ void SelectionHelper::fixSelection(SPDesktop *dt) Inkscape::Selection *selection = dt->getSelection(); - GSList *items = NULL; + SelContainer items ; - GSList const *selList = selection->itemList(); + SelContainer const selList = selection->itemList(); - for( GSList const *i = selList; i; i = i->next ) { - SPItem *item = dynamic_cast(static_cast(i->data)); + for( SelContainer::const_iterator i=selList.begin();i!=selList.end();i++ ) { + SPItem *item = dynamic_cast(static_cast(*i)); if( item && !dt->isLayer(item) && (!item->isLocked())) { - items = g_slist_prepend(items, item); + items.push_front(item); } } selection->setList(items); - if(items) { - g_slist_free(items); - } + items.clear(); } } // namespace Inkscape @@ -307,7 +305,7 @@ void SelectionHelper::fixSelection(SPDesktop *dt) * Copies repr and its inherited css style elements, along with the accumulated transform 'full_t', * then prepends the copy to 'clip'. */ -static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, GSList **clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, SelContainer &clip, Inkscape::XML::Document* xml_doc) { Inkscape::XML::Node *copy = repr->duplicate(xml_doc); @@ -323,18 +321,18 @@ static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t copy->setAttribute("transform", affinestr); g_free(affinestr); - *clip = g_slist_prepend(*clip, copy); + clip.push_front(dynamic_cast(copy)); } -static void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_impl(SelContainer const &items, SelContainer &clip, Inkscape::XML::Document* xml_doc) { // Sort items: - GSList *sorted_items = g_slist_copy(const_cast(items)); - sorted_items = g_slist_sort(static_cast(sorted_items), (GCompareFunc) sp_object_compare_position); + SelContainer sorted_items(items); + sorted_items.sort(sp_object_compare_position); // Copy item reprs: - for (GSList *i = sorted_items; i != NULL; i = i->next) { - SPItem *item = dynamic_cast(SP_OBJECT(i->data)); + for (SelContainer::const_iterator i = sorted_items.begin();i!=sorted_items.end();i++) { + SPItem *item = dynamic_cast(SP_OBJECT(*i)); if (item) { sp_selection_copy_one(item->getRepr(), item->i2doc_affine(), clip, xml_doc); } else { @@ -342,22 +340,22 @@ static void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape: } } - *clip = g_slist_reverse(*clip); - g_slist_free(static_cast(sorted_items)); + clip.reverse(); + sorted_items.clear(); } // TODO check if parent parameter should be changed to SPItem, of if the code should handle non-items. -static GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList **clip) +static SelContainer sp_selection_paste_impl(SPDocument *doc, SPObject *parent, SelContainer &clip) { Inkscape::XML::Document *xml_doc = doc->getReprDoc(); SPItem *parentItem = dynamic_cast(parent); g_assert(parentItem != NULL); - GSList *copied = NULL; + SelContainer copied; // add objects to document - for (GSList *l = *clip; l != NULL; l = l->next) { - Inkscape::XML::Node *repr = static_cast(l->data); + for (SelContainer::const_iterator l=clip.begin();l!=clip.end();l++) { + Inkscape::XML::Node *repr = dynamic_cast(*l); Inkscape::XML::Node *copy = repr->duplicate(xml_doc); // premultiply the item transform by the accumulated parent transform in the paste layer @@ -375,19 +373,19 @@ static GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList } parent->appendChildRepr(copy); - copied = g_slist_prepend(copied, copy); + copied.push_front(dynamic_cast(copy)); Inkscape::GC::release(copy); } return copied; } -static void sp_selection_delete_impl(GSList const *items, bool propagate = true, bool propagate_descendants = true) +static void sp_selection_delete_impl(SelContainer const &items, bool propagate = true, bool propagate_descendants = true) { - for (GSList const *i = items ; i ; i = i->next ) { - sp_object_ref(static_cast(i->data), NULL); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + sp_object_ref(static_cast(*i), NULL); } - for (GSList const *i = items; i != NULL; i = i->next) { - SPItem *item = static_cast(i->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + SPItem *item = static_cast(*i); item->deleteObject(propagate, propagate_descendants); sp_object_unref(item, NULL); } @@ -414,11 +412,10 @@ void sp_selection_delete(SPDesktop *desktop) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing was deleted.")); return; } - - GSList *selected = g_slist_copy(const_cast(selection->itemList())); + SelContainer selected(selection->itemList()); selection->clear(); sp_selection_delete_impl(selected); - g_slist_free(selected); + selected.clear(); desktop->currentLayer()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); /* a tool may have set up private information in it's selection context @@ -446,6 +443,10 @@ static void add_ids_recursive(std::vector &ids, SPObject *obj) } } +bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b){ + return sp_repr_compare_position(dynamic_cast(a),dynamic_cast(b)); +} + void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) { if (desktop == NULL) { @@ -461,16 +462,15 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to duplicate.")); return; } - - GSList *reprs = g_slist_copy(const_cast(selection->reprList())); + SelContainer reprs(selection->reprList()); selection->clear(); // sorting items from different parents sorts each parent's subset without possibly mixing // them, just what we need - reprs = g_slist_sort(reprs, (GCompareFunc) sp_repr_compare_position); + reprs.sort(sp_repr_compare_position_obj); - GSList *newsel = NULL; + SelContainer newsel; std::vector old_ids; std::vector new_ids; @@ -478,8 +478,8 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) bool relink_clones = prefs->getBool("/options/relinkclonesonduplicate/value"); const bool fork_livepatheffects = prefs->getBool("/options/forklpeonduplicate/value", true); - while (reprs) { - Inkscape::XML::Node *old_repr = static_cast(reprs->data); + while (!reprs.empty()) { + Inkscape::XML::Node *old_repr = dynamic_cast(reprs.front()); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); @@ -500,8 +500,8 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) } } - newsel = g_slist_prepend(newsel, copy); - reprs = g_slist_remove(reprs, reprs->data); + newsel.push_front(dynamic_cast(copy)); + reprs.pop_front(); Inkscape::GC::release(copy); } @@ -548,7 +548,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) selection->setReprList(newsel); - g_slist_free(newsel); + newsel.clear(); } void sp_edit_clear_all(Inkscape::Selection *selection) @@ -561,11 +561,11 @@ void sp_edit_clear_all(Inkscape::Selection *selection) SPGroup *group = dynamic_cast(selection->layers()->currentLayer()); g_return_if_fail(group != NULL); - GSList *items = sp_item_group_item_list(group); + SelContainer items = sp_item_group_item_list(group); - while (items) { - reinterpret_cast(items->data)->deleteObject(); - items = g_slist_remove(items, items->data); + while (!items.empty()) { + reinterpret_cast(items.front())->deleteObject(); + items.pop_front(); } DocumentUndo::done(doc, SP_VERB_EDIT_CLEAR_ALL, @@ -582,7 +582,7 @@ void sp_edit_clear_all(Inkscape::Selection *selection) * onlysensitive - TRUE includes only non-locked items * ingroups - TRUE to recursively get grouped items children */ -GSList *get_all_items(GSList *list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, GSList const *exclude) +SelContainer &get_all_items(SelContainer &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, SelContainer const &exclude) { for ( SPObject *child = from->firstChild() ; child; child = child->getNext() ) { SPItem *item = dynamic_cast(child); @@ -590,10 +590,10 @@ GSList *get_all_items(GSList *list, SPObject *from, SPDesktop *desktop, bool onl !desktop->isLayer(item) && (!onlysensitive || !item->isLocked()) && (!onlyvisible || !desktop->itemIsHidden(item)) && - (!exclude || !g_slist_find(const_cast(exclude), child)) + (exclude.empty() || exclude.end() == std::find(exclude.begin(),exclude.end(),child)) ) { - list = g_slist_prepend(list, item); + list.push_front(item); } if (ingroups || (item && desktop->isLayer(item))) { @@ -618,9 +618,9 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); - GSList *items = NULL; + SelContainer items ; - GSList const *exclude = NULL; + SelContainer exclude; if (invert) { exclude = selection->itemList(); } @@ -634,39 +634,41 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i (onlyvisible && dt->itemIsHidden(dynamic_cast(dt->currentLayer()))) ) return; - GSList *all_items = sp_item_group_item_list(dynamic_cast(dt->currentLayer())); + SelContainer all_items = sp_item_group_item_list(dynamic_cast(dt->currentLayer())); - for (GSList *i = all_items; i; i = i->next) { - SPItem *item = dynamic_cast(static_cast(i->data)); + for (SelContainer::const_iterator i=all_items.begin();i!=all_items.end();i++) { + SPItem *item = dynamic_cast(static_cast(*i)); if (item && (!onlysensitive || !item->isLocked())) { if (!onlyvisible || !dt->itemIsHidden(item)) { if (!dt->isLayer(item)) { - if (!invert || !g_slist_find(const_cast(exclude), item)) { - items = g_slist_prepend(items, item); // leave it in the list + if (!invert || exclude.end() == std::find(exclude.begin(),exclude.end(),item)) { + items.push_front(item); // leave it in the list } } } } } - g_slist_free(all_items); + all_items.clear(); break; } case PREFS_SELECTION_LAYER_RECURSIVE: { - items = get_all_items(NULL, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude); + SelContainer x; + items = get_all_items(x, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude); break; } default: { - items = get_all_items(NULL, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude); + SelContainer x; + items = get_all_items(x, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude); break; } } selection->setList(items); - if (items) { - g_slist_free(items); + if (!items.empty()) { + items.clear(); } } @@ -690,16 +692,16 @@ void sp_edit_invert_in_all_layers(SPDesktop *desktop) sp_edit_select_all_full(desktop, true, true); } -static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { +static void sp_selection_group_impl(SelContainer p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { - p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position); + p.sort(sp_repr_compare_position_obj); // Remember the position and parent of the topmost object. - gint topmost = (static_cast(g_slist_last(p)->data))->position(); - Inkscape::XML::Node *topmost_parent = (static_cast(g_slist_last(p)->data))->parent(); + gint topmost = (dynamic_cast(p.back()))->position(); + Inkscape::XML::Node *topmost_parent = (dynamic_cast(p.back()))->parent(); - while (p) { - Inkscape::XML::Node *current = static_cast(p->data); + while (!p.empty()) { + Inkscape::XML::Node *current = dynamic_cast(p.front()); if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -708,7 +710,7 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc Inkscape::GC::release(spnew); topmost --; // only reduce count for those items deleted from topmost_parent } else { // move it to topmost_parent first - GSList *temp_clip = NULL; + SelContainer temp_clip; // At this point, current may already have no item, due to its being a clone whose original is already moved away // So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform @@ -724,15 +726,15 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc // then, if this is clone, looking up its original in that array and pre-multiplying // it by the inverse of that original's transform diff. - sp_selection_copy_one(current, item_t, &temp_clip, xml_doc); + sp_selection_copy_one(current, item_t, temp_clip, xml_doc); sp_repr_unparent(current); // paste into topmost_parent (temporarily) - GSList *copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), &temp_clip); - if (temp_clip) g_slist_free(temp_clip); - if (copied) { // if success, + SelContainer copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), temp_clip); + if (!temp_clip.empty())temp_clip.clear() ; + if (!copied.empty()) { // if success, // take pasted object (now in topmost_parent) - Inkscape::XML::Node *in_topmost = static_cast(copied->data); + Inkscape::XML::Node *in_topmost = dynamic_cast(copied.front()); // make a copy Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc); // remove pasted @@ -740,10 +742,10 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc // put its copy into group group->appendChild(spnew); Inkscape::GC::release(spnew); - g_slist_free(copied); + copied.clear(); } } - p = g_slist_remove(p, current); + p.pop_front(); } // Add the new group to the topmost members' parent @@ -764,9 +766,7 @@ void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop) return; } - GSList const *l = const_cast(selection->reprList()); - - GSList *p = g_slist_copy(const_cast(l)); + SelContainer p (selection->reprList()); selection->clear(); @@ -802,11 +802,11 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) } // first check whether there is anything to ungroup - GSList *old_select = const_cast(selection->itemList()); - GSList *new_select = NULL; + SelContainer old_select = selection->itemList(); + SelContainer new_select; GSList *groups = NULL; - for (GSList *item = old_select; item; item = item->next) { - SPItem *obj = static_cast(item->data); + for (SelContainer::const_iterator item = old_select.begin(); item!=old_select.end(); item++) { + SPItem *obj = static_cast(*item); if (dynamic_cast(obj)) { groups = g_slist_prepend(groups, obj); } @@ -818,14 +818,14 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) return; } - GSList *items = g_slist_copy(old_select); + SelContainer items(old_select); selection->clear(); // If any of the clones refer to the groups, unlink them and replace them with successors // in the items list. GSList *clones_to_unlink = NULL; - for (GSList *item = items; item; item = item->next) { - SPUse *use = dynamic_cast(static_cast(item->data)); + for (SelContainer::const_iterator item = items.begin(); item!=items.end(); item++) { + SPUse *use = dynamic_cast(static_cast(*item)); SPItem *original = use; while (dynamic_cast(original)) { @@ -833,7 +833,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) } if (g_slist_find(groups, original) != NULL) { - clones_to_unlink = g_slist_prepend(clones_to_unlink, item->data); + clones_to_unlink = g_slist_prepend(clones_to_unlink, *item); } } @@ -844,57 +844,57 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) for (GSList *item = clones_to_unlink; item; item = item->next) { SPUse *use = static_cast(item->data); - GSList *items_node = g_slist_find(items, item->data); - items_node->data = use->unlink(); + SelContainer::iterator items_node = std::find(items.begin(),items.end(), item->data); + (*items_node) = use->unlink(); } g_slist_free(clones_to_unlink); // do the actual work - for (GSList *item = items; item; item = item->next) { - SPItem *obj = static_cast(item->data); + for (SelContainer::iterator item = items.begin(); item!=items.end(); item++) { + SPItem *obj = static_cast(*item); // ungroup only the groups marked earlier - if (g_slist_find(groups, item->data) != NULL) { - GSList *children = NULL; - sp_item_group_ungroup(dynamic_cast(obj), &children, false); + if (g_slist_find(groups, *item) != NULL) { + SelContainer children; + sp_item_group_ungroup(dynamic_cast(obj), children, false); // add the items resulting from ungrouping to the selection - new_select = g_slist_concat(new_select, children); - item->data = NULL; // zero out the original pointer, which is no longer valid + new_select.splice(new_select.end(),children); + (*item) = NULL; // zero out the original pointer, which is no longer valid } else { // if not a group, keep in the selection - new_select = g_slist_append(new_select, item->data); + new_select.push_back(*item); } } selection->addList(new_select); - g_slist_free(new_select); - g_slist_free(items); + new_select.clear(); + items.clear(); DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_UNGROUP, _("Ungroup")); } /** Replace all groups in the list with their member objects, recursively; returns a new list, frees old */ -GSList * -sp_degroup_list(GSList *items) +SelContainer +sp_degroup_list(SelContainer &items) { - GSList *out = NULL; + SelContainer out; bool has_groups = false; - for (GSList *item = items; item; item = item->next) { - SPGroup *group = dynamic_cast(static_cast(item->data)); + for (SelContainer::const_iterator item=items.begin();item!=items.end();item++) { + SPGroup *group = dynamic_cast(static_cast(*item)); if (!group) { - out = g_slist_prepend(out, item->data); + out.push_front(*item); } else { has_groups = true; - GSList *members = sp_item_group_item_list(group); - for (GSList *member = members; member; member = member->next) { - out = g_slist_prepend(out, member->data); + SelContainer members = sp_item_group_item_list(group); + for (SelContainer::const_iterator member=members.begin();member!=members.end();member++) { + out.push_front(*member); } - g_slist_free(members); + members.clear(); } } - out = g_slist_reverse(out); - g_slist_free(items); + out.reverse(); + items.clear(); if (has_groups) { // recurse if we unwrapped a group - it may have contained others out = sp_degroup_list(out); @@ -906,18 +906,19 @@ sp_degroup_list(GSList *items) /** If items in the list have a common parent, return it, otherwise return NULL */ static SPGroup * -sp_item_list_common_parent_group(GSList const *items) +sp_item_list_common_parent_group(SelContainer const items) { - if (!items) { + if (items.empty()) { return NULL; } - SPObject *parent = SP_OBJECT(items->data)->parent; + SPObject *parent = SP_OBJECT(items.front())->parent; // Strictly speaking this CAN happen, if user selects from Inkscape::XML editor if (!dynamic_cast(parent)) { return NULL; } - for (items = items->next; items; items = items->next) { - if (SP_OBJECT(items->data)->parent != parent) { + for (SelContainer::const_iterator item=items.begin();item!=items.end();item++) { + if((*item)==items.front())continue; + if (SP_OBJECT(*item)->parent != parent) { return NULL; } } @@ -927,13 +928,13 @@ sp_item_list_common_parent_group(GSList const *items) /** Finds out the minimum common bbox of the selected items. */ static Geom::OptRect -enclose_items(GSList const *items) +enclose_items(SelContainer const &items) { - g_assert(items != NULL); + g_assert(!items.empty()); Geom::OptRect r; - for (GSList const *i = items; i; i = i->next) { - r.unionWith(static_cast(i->data)->desktopVisualBounds()); + for (SelContainer::const_iterator i = items.begin();i!=items.end();i++) { + r.unionWith(static_cast(*i)->desktopVisualBounds()); } return r; } @@ -948,11 +949,17 @@ static SPObject *prev_sibling(SPObject *child) return prev; } +int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *second) +{ + return sp_repr_compare_position(((SPItem*)first)->getRepr(), + ((SPItem*)second)->getRepr())<0; +} + void sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) { - GSList const *items = const_cast(selection->itemList()); - if (!items) { + SelContainer items= selection->itemList(); + if (items.empty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select object(s) to raise.")); return; } @@ -966,16 +973,16 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) Inkscape::XML::Node *grepr = const_cast(group->getRepr()); /* Construct reverse-ordered list of selected children. */ - GSList *rev = g_slist_copy(const_cast(items)); - rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position); + SelContainer rev(items); + rev.sort(sp_item_repr_compare_position_obj); // Determine the common bbox of the selected items. Geom::OptRect selected = enclose_items(items); // Iterate over all objects in the selection (starting from top). if (selected) { - while (rev) { - SPObject *child = reinterpret_cast(rev->data); + while (!rev.empty()) { + SPObject *child = reinterpret_cast(rev.front()); // for each selected object, find the next sibling for (SPObject *newref = child->next; newref; newref = newref->next) { // if the sibling is an item AND overlaps our selection, @@ -984,7 +991,7 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) Geom::OptRect newref_bbox = newItem->desktopVisualBounds(); if ( newref_bbox && selected->intersects(*newref_bbox) ) { // AND if it's not one of our selected objects, - if (!g_slist_find(const_cast(items), newref)) { + if ( std::find(items.begin(),items.end(),newref)==items.end()) { // move the selected object after that sibling grepr->changeOrder(child->getRepr(), newref->getRepr()); } @@ -992,10 +999,10 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) } } } - rev = g_slist_remove(rev, child); + rev.pop_front(); } } else { - g_slist_free(rev); + rev.clear(); } DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_RAISE, @@ -1012,7 +1019,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - GSList const *items = const_cast(selection->itemList()); + SelContainer items = selection->itemList(); SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { @@ -1020,15 +1027,15 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - GSList *rl = g_slist_copy(const_cast(selection->reprList())); - rl = g_slist_sort(rl, (GCompareFunc) sp_repr_compare_position); + SelContainer rl(selection->reprList()); + rl.sort(sp_repr_compare_position_obj); - for (GSList *l = rl; l != NULL; l = l->next) { - Inkscape::XML::Node *repr = static_cast(l->data); + for (SelContainer::iterator l=rl.begin(); l!=rl.end();l++) { + Inkscape::XML::Node *repr = dynamic_cast(*l); repr->setPosition(-1); } - g_slist_free(rl); + rl.clear(); DocumentUndo::done(document, SP_VERB_SELECTION_TO_FRONT, _("Raise to top")); @@ -1036,8 +1043,8 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) { - GSList const *items = const_cast(selection->itemList()); - if (!items) { + SelContainer items = selection->itemList(); + if (items.empty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select object(s) to lower.")); return; } @@ -1054,14 +1061,14 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) Geom::OptRect selected = enclose_items(items); /* Construct direct-ordered list of selected children. */ - GSList *rev = g_slist_copy(const_cast(items)); - rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position); - rev = g_slist_reverse(rev); + SelContainer rev(items); + rev.sort(sp_item_repr_compare_position_obj); + rev.reverse(); // Iterate over all objects in the selection (starting from top). if (selected) { - while (rev) { - SPObject *child = reinterpret_cast(rev->data); + while (!rev.empty()) { + SPObject *child = reinterpret_cast(rev.front()); // for each selected object, find the prev sibling for (SPObject *newref = prev_sibling(child); newref; newref = prev_sibling(newref)) { // if the sibling is an item AND overlaps our selection, @@ -1070,7 +1077,7 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) Geom::OptRect ref_bbox = newItem->desktopVisualBounds(); if ( ref_bbox && selected->intersects(*ref_bbox) ) { // AND if it's not one of our selected objects, - if (!g_slist_find(const_cast(items), newref)) { + if (items.end()==std::find(items.begin(),items.end(),newref)) { // move the selected object before that sibling SPObject *put_after = prev_sibling(newref); if (put_after) @@ -1082,10 +1089,10 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) } } } - rev = g_slist_remove(rev, child); + rev.pop_front(); } } else { - g_slist_free(rev); + rev.clear(); } DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_LOWER, @@ -1102,7 +1109,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - GSList const *items = const_cast(selection->itemList()); + SelContainer items =selection->itemList(); SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { @@ -1110,15 +1117,14 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - GSList *rl; - rl = g_slist_copy(const_cast(selection->reprList())); - rl = g_slist_sort(rl, (GCompareFunc) sp_repr_compare_position); - rl = g_slist_reverse(rl); + SelContainer rl(selection->reprList()); + rl.sort(sp_repr_compare_position_obj); + rl.reverse(); - for (GSList *l = rl; l != NULL; l = l->next) { + for (SelContainer::const_iterator l=rl.begin();l!=rl.end();l++) { gint minpos; SPObject *pp, *pc; - Inkscape::XML::Node *repr = static_cast(l->data); + Inkscape::XML::Node *repr = dynamic_cast(*l); pp = document->getObjectByRepr(repr->parent()); minpos = 0; g_assert(dynamic_cast(pp)); @@ -1130,7 +1136,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des repr->setPosition(minpos); } - g_slist_free(rl); + rl.clear(); DocumentUndo::done(document, SP_VERB_SELECTION_TO_BACK, _("Lower to bottom")); @@ -1269,9 +1275,9 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to remove live path effects from.")); return; } - - for ( GSList const *itemlist = selection->itemList(); itemlist != NULL; itemlist = g_slist_next(itemlist) ) { - SPItem *item = reinterpret_cast(itemlist->data); + SelContainer list=selection->itemList(); + for ( SelContainer::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) { + SPItem *item = reinterpret_cast(*itemlist); sp_selection_remove_livepatheffect_impl(item); @@ -1331,25 +1337,25 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) return; } - GSList const *items = g_slist_copy(const_cast(selection->itemList())); + SelContainer items(selection->itemList()); bool no_more = false; // Set to true, if no more layers above SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); if (next) { - GSList *temp_clip = NULL; - sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); + SelContainer temp_clip; + sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); sp_selection_delete_impl(items, false, false); next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers - GSList *copied; + SelContainer copied; if (next) { - copied = sp_selection_paste_impl(dt->getDocument(), next, &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), next, temp_clip); } else { - copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), temp_clip); no_more = true; } - selection->setReprList((GSList const *) copied); - g_slist_free(copied); - if (temp_clip) g_slist_free(temp_clip); + selection->setReprList(copied); + copied.clear(); + if (!temp_clip.empty()) temp_clip.clear(); if (next) dt->setCurrentLayer(next); if ( !suppressDone ) { DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_NEXT, @@ -1363,7 +1369,7 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers above.")); } - g_slist_free(const_cast(items)); + items.clear(); } void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) @@ -1376,25 +1382,25 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) return; } - GSList const *items = g_slist_copy(const_cast(selection->itemList())); + const SelContainer items(selection->itemList()); bool no_more = false; // Set to true, if no more layers below SPObject *next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); if (next) { - GSList *temp_clip = NULL; - sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs + SelContainer temp_clip; + sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers - GSList *copied; + SelContainer copied; if (next) { - copied = sp_selection_paste_impl(dt->getDocument(), next, &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), next, temp_clip); } else { - copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), &temp_clip); + copied = sp_selection_paste_impl(dt->getDocument(), dt->currentLayer(), temp_clip); no_more = true; } - selection->setReprList((GSList const *) copied); - g_slist_free(copied); - if (temp_clip) g_slist_free(temp_clip); + selection->setReprList( copied); + copied.clear(); + if (!temp_clip.empty()) temp_clip.clear(); if (next) dt->setCurrentLayer(next); if ( !suppressDone ) { DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_PREV, @@ -1407,8 +1413,6 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) if (no_more) { dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers below.")); } - - g_slist_free(const_cast(items)); } void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) @@ -1421,24 +1425,22 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) return; } - GSList const *items = g_slist_copy(const_cast(selection->itemList())); + SelContainer items(selection->itemList()); if (moveto) { - GSList *temp_clip = NULL; - sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs + SelContainer temp_clip; + sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); - GSList *copied = sp_selection_paste_impl(dt->getDocument(), moveto, &temp_clip); - selection->setReprList((GSList const *) copied); - g_slist_free(copied); - if (temp_clip) g_slist_free(temp_clip); + SelContainer copied = sp_selection_paste_impl(dt->getDocument(), moveto, temp_clip); + selection->setReprList(copied); + copied.clear(); + if (!temp_clip.empty()) temp_clip.clear(); if (moveto) dt->setCurrentLayer(moveto); if ( !suppressDone ) { DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO, _("Move selection to layer")); } } - - g_slist_free(const_cast(items)); } static bool @@ -1473,8 +1475,9 @@ static bool selection_contains_both_clone_and_original(Inkscape::Selection *selection) { bool clone_with_original = false; - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = dynamic_cast(static_cast(l->data)); + SelContainer items = selection->itemList(); + for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + SPItem *item = dynamic_cast(static_cast(*l)); if (item) { clone_with_original |= selection_contains_original(item, selection); if (clone_with_original) @@ -1517,9 +1520,9 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, Geom::Affine cons persp3d_apply_affine_transformation(transf_persp, affine); } - - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = dynamic_cast(static_cast(l->data)); + SelContainer items = selection->itemList(); + for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + SPItem *item = dynamic_cast(static_cast(*l)); if( dynamic_cast(item) ) { // An SVG element cannot have a transform. We could change 'x' and 'y' in response @@ -1688,10 +1691,9 @@ void sp_selection_remove_transform(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); - GSList const *l = const_cast(selection->reprList()); - while (l != NULL) { - ((Inkscape::XML::Node*)l->data)->setAttribute("transform", NULL, false); - l = l->next; + SelContainer items = selection->itemList(); + for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + ((Inkscape::XML::Node*)*l)->setAttribute("transform", NULL, false); } DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_FLATTEN, @@ -1789,10 +1791,10 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw) if (selection->isEmpty()) return; - GSList const *l = selection->itemList(); + SelContainer items = selection->itemList(); Geom::Rotate const rot_90(Geom::Point(0, ccw ? 1 : -1)); // pos. or neg. rotation, depending on the value of ccw - for (GSList const *l2 = l ; l2 != NULL ; l2 = l2->next) { - SPItem *item = dynamic_cast(static_cast(l2->data)); + for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + SPItem *item = dynamic_cast(static_cast(*l)); if (item) { sp_item_rotate_rel(item, rot_90); } else { @@ -1848,15 +1850,15 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); bool ingroups = TRUE; - - GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL); - GSList *all_matches = NULL; + SelContainer x,y; + SelContainer all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); + SelContainer all_matches; Inkscape::Selection *selection = desktop->getSelection(); - - for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { - SPItem *sel = dynamic_cast(static_cast(sel_iter->data)); - GSList *matches = all_list; + SelContainer items = selection->itemList(); + for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + SPItem *sel = dynamic_cast(static_cast(*sel_iter)); + SelContainer matches = all_list; if (fill) { matches = sp_get_same_fill_or_stroke_color(sel, matches, SP_FILL_COLOR); } @@ -1868,19 +1870,12 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES); matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_MARKERS); } - all_matches = g_slist_concat (all_matches, matches); + all_matches.splice(all_matches.end(), matches); } selection->clear(); selection->setList(all_matches); - if (all_matches) { - g_slist_free(all_matches); - } - if (all_list) { - g_slist_free(all_list); - } - } @@ -1901,14 +1896,15 @@ void sp_select_same_object_type(SPDesktop *desktop) bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); bool ingroups = TRUE; - - GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL); - GSList *matches = all_list; + SelContainer x,y; + SelContainer all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); + SelContainer matches = all_list; Inkscape::Selection *selection = desktop->getSelection(); - for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { - SPItem *sel = dynamic_cast(static_cast(sel_iter->data)); + SelContainer items=selection->itemList(); + for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + SPItem *sel = dynamic_cast(static_cast(*sel_iter)); if (sel) { matches = sp_get_same_object_type(sel, matches); } else { @@ -1919,12 +1915,6 @@ void sp_select_same_object_type(SPDesktop *desktop) selection->clear(); selection->setList(matches); - if (matches) { - g_slist_free(matches); - } - if (all_list) { - g_slist_free(all_list); - } } /* @@ -1944,13 +1934,14 @@ void sp_select_same_stroke_style(SPDesktop *desktop) bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); bool ingroups = TRUE; - GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL); - GSList *matches = all_list; + SelContainer x,y; + SelContainer matches = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); Inkscape::Selection *selection = desktop->getSelection(); + SelContainer items=selection->itemList(); - for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { - SPItem *sel = dynamic_cast(static_cast(sel_iter->data)); + for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + SPItem *sel = dynamic_cast(static_cast(*sel_iter)); if (sel) { matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_WIDTH); matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES); @@ -1963,27 +1954,21 @@ void sp_select_same_stroke_style(SPDesktop *desktop) selection->clear(); selection->setList(matches); - if (matches) { - g_slist_free(matches); - } - if (all_list) { - g_slist_free(all_list); - } } /* * Find all items in src list that have the same fill or stroke style as sel * Return the list of matching items */ -GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrokeStyleType type) +SelContainer sp_get_same_fill_or_stroke_color(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type) { - GSList *matches = NULL; + SelContainer matches ; gboolean match = false; SPIPaint *sel_paint = (type == SP_FILL_COLOR) ? &(sel->style->fill) : &(sel->style->stroke); - for (GSList *i = src; i != NULL; i = i->next) { - SPItem *iter = dynamic_cast(static_cast(i->data)); + for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) { + SPItem *iter = dynamic_cast(static_cast(*i)); if (iter) { SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke); match = false; @@ -2022,7 +2007,7 @@ GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrok } if (match) { - matches = g_slist_prepend(matches, iter); + matches.push_front(iter); } } else { g_assert_not_reached(); @@ -2073,17 +2058,16 @@ static bool item_type_match (SPItem *i, SPItem *j) * Find all items in src list that have the same object type as sel by type * Return the list of matching items */ -GSList *sp_get_same_object_type(SPItem *sel, GSList *src) +SelContainer sp_get_same_object_type(SPItem *sel, SelContainer &src) { - GSList *matches = NULL; + SelContainer matches; - for (GSList *i = src; i != NULL; i = i->next) { - SPItem *item = dynamic_cast(static_cast(i->data)); + for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) { + SPItem *item = dynamic_cast(static_cast(*i)); if (item && item_type_match(sel, item)) { - matches = g_slist_prepend (matches, item); + matches.push_front(item); } } - return matches; } @@ -2091,9 +2075,9 @@ GSList *sp_get_same_object_type(SPItem *sel, GSList *src) * Find all items in src list that have the same stroke style as sel by type * Return the list of matching items */ -GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type) +SelContainer sp_get_same_stroke_style(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type) { - GSList *matches = NULL; + SelContainer matches; gboolean match = false; SPStyle *sel_style = sel->style; @@ -2106,16 +2090,15 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy * Stroke width needs to handle transformations, so call this function * to get the transformed stroke width */ - GSList *objects = NULL; + SelContainer objects; SPStyle *sel_style_for_width = NULL; if (type == SP_STROKE_STYLE_WIDTH) { - objects = g_slist_prepend(objects, sel); + objects.push_front(sel); sel_style_for_width = new SPStyle(SP_ACTIVE_DOCUMENT); objects_query_strokewidth (objects, sel_style_for_width); } - - for (GSList *i = src; i != NULL; i = i->next) { - SPItem *iter = dynamic_cast(static_cast(i->data)); + for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) { + SPItem *iter = dynamic_cast(static_cast(*i)); if (iter) { SPStyle *iter_style = iter->style; match = false; @@ -2123,15 +2106,15 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy if (type == SP_STROKE_STYLE_WIDTH) { match = (sel_style->stroke_width.set == iter_style->stroke_width.set); if (sel_style->stroke_width.set && iter_style->stroke_width.set) { - GSList *objects = NULL; - objects = g_slist_prepend(objects, iter); + SelContainer objects; + objects.push_front(iter); SPStyle tmp_style(SP_ACTIVE_DOCUMENT); objects_query_strokewidth (objects, &tmp_style); if (sel_style_for_width) { match = (sel_style_for_width->stroke_width.computed == tmp_style.stroke_width.computed); } - g_slist_free(objects); + objects.clear(); } } else if (type == SP_STROKE_STYLE_DASHES ) { @@ -2154,7 +2137,7 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy } if (match) { - matches = g_slist_prepend(matches, iter); + matches.push_front(iter); } } else { g_assert_not_reached(); @@ -2162,8 +2145,6 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy } if( sel_style_for_width != NULL ) delete sel_style_for_width; - g_slist_free(objects); - return matches; } @@ -2320,11 +2301,11 @@ sp_selection_move_screen(Inkscape::Selection *selection, gdouble dx, gdouble dy) namespace { template -SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, +SPItem *next_item(SPDesktop *desktop, SelContainer &path, SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive); template -SPItem *next_item_from_list(SPDesktop *desktop, GSList const *items, SPObject *root, +SPItem *next_item_from_list(SPDesktop *desktop, SelContainer const &items, SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive); struct Forward { @@ -2618,17 +2599,17 @@ void sp_selection_clone(SPDesktop *desktop) return; } - GSList *reprs = g_slist_copy(const_cast(selection->reprList())); + SelContainer reprs (selection->reprList()); selection->clear(); // sorting items from different parents sorts each parent's subset without possibly mixing them, just what we need - reprs = g_slist_sort(reprs, (GCompareFunc) sp_repr_compare_position); + reprs.sort(sp_repr_compare_position_obj); - GSList *newsel = NULL; + SelContainer newsel; - while (reprs) { - Inkscape::XML::Node *sel_repr = static_cast(reprs->data); + while (!reprs.empty()) { + Inkscape::XML::Node *sel_repr = dynamic_cast(reprs.front()); Inkscape::XML::Node *parent = sel_repr->parent(); Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); @@ -2644,8 +2625,8 @@ void sp_selection_clone(SPDesktop *desktop) // add the new clone to the top of the original's parent parent->appendChild(clone); - newsel = g_slist_prepend(newsel, clone); - reprs = g_slist_remove(reprs, sel_repr); + newsel.push_front(dynamic_cast(clone)); + reprs.pop_front(); Inkscape::GC::release(clone); } @@ -2653,8 +2634,6 @@ void sp_selection_clone(SPDesktop *desktop) C_("Action", "Clone")); selection->setReprList(newsel); - - g_slist_free(newsel); } void @@ -2680,11 +2659,9 @@ sp_selection_relink(SPDesktop *desktop) // Get a copy of current selection. bool relinked = false; - for (GSList *items = const_cast(selection->itemList()); - items != NULL; - items = items->next) - { - SPItem *item = static_cast(items->data); + SelContainer items=selection->itemList(); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = static_cast(*i); if (dynamic_cast(item)) { item->getRepr()->setAttribute("xlink:href", newref); @@ -2718,13 +2695,11 @@ sp_selection_unlink(SPDesktop *desktop) } // Get a copy of current selection. - GSList *new_select = NULL; + SelContainer new_select; bool unlinked = false; - for (GSList *items = g_slist_copy(const_cast(selection->itemList())); - items != NULL; - items = items->next) - { - SPItem *item = static_cast(items->data); + SelContainer items=selection->itemList(); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = static_cast(*i); if (dynamic_cast(item)) { SPObject *tspan = sp_tref_convert_to_tspan(item); @@ -2740,7 +2715,7 @@ sp_selection_unlink(SPDesktop *desktop) if (!(dynamic_cast(item) || dynamic_cast(item))) { // keep the non-use item in the new selection - new_select = g_slist_prepend(new_select, item); + new_select.push_front(item); continue; } @@ -2750,7 +2725,7 @@ sp_selection_unlink(SPDesktop *desktop) unlink = use->unlink(); // Unable to unlink use (external or invalid href?) if (!unlink) { - new_select = g_slist_prepend(new_select, item); + new_select.push_front(item); continue; } } else /*if (SP_IS_TREF(use))*/ { @@ -2760,13 +2735,12 @@ sp_selection_unlink(SPDesktop *desktop) unlinked = true; // Add ungrouped items to the new selection. - new_select = g_slist_prepend(new_select, unlink); + new_select.push_front(unlink); } - if (new_select) { // set new selection + if (!new_select.empty()) { // set new selection selection->clear(); selection->setList(new_select); - g_slist_free(new_select); } if (!unlinked) { desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("No clones to unlink in the selection.")); @@ -2789,7 +2763,9 @@ sp_select_clone_original(SPDesktop *desktop) gchar const *error = _("Select a clone to go to its original. Select a linked offset to go to its source. Select a text on path to go to the path. Select a flowed text to go to its frame."); // Check if other than two objects are selected - if (g_slist_length(const_cast(selection->itemList())) != 1 || !item) { + + SelContainer items=selection->itemList(); + if (items.size() != 1 || !item) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, error); return; } @@ -2886,14 +2862,15 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop) Inkscape::SVGOStringStream os; SPObject * firstItem = NULL; - for (const GSList * item = selection->itemList(); item != NULL; item = item->next) { - if (SP_IS_SHAPE(item->data) || SP_IS_TEXT(item->data)) { + SelContainer items=selection->itemList(); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_SHAPE(*i) || SP_IS_TEXT(*i)) { if (firstItem) { os << "|"; } else { - firstItem = SP_ITEM(item->data); + firstItem = SP_ITEM(*i); } - os << '#' << SP_ITEM(item->data)->getId() << ",0"; + os << '#' << SP_ITEM(*i)->getId() << ",0"; } } if (firstItem) { @@ -2970,12 +2947,12 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) Geom::Point center( *c - corner ); // As defined by rotation center center[Geom::Y] = -center[Geom::Y]; - GSList *items = g_slist_copy(const_cast(selection->itemList())); + SelContainer items(selection->itemList()); //items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); // Why needed? // bottommost object, after sorting - SPObject *parent = SP_OBJECT(items->data)->parent; + SPObject *parent = SP_OBJECT(items.front())->parent; Geom::Affine parent_transform; { @@ -2988,10 +2965,10 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) } // Create a list of duplicates, to be pasted inside marker element. - GSList *repr_copies = NULL; - for (GSList *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); - repr_copies = g_slist_prepend(repr_copies, dup); + SelContainer repr_copies; + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); + repr_copies.push_front(dynamic_cast(dup)); } Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max())); @@ -2999,8 +2976,8 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) if (apply) { // Delete objects so that their clones don't get alerted; // the objects will be restored inside the marker element. - for (GSList *i = items; i != NULL; i = i->next) { - SPObject *item = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *item = reinterpret_cast(*i); item->deleteObject(false); } } @@ -3019,7 +2996,6 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) prefs->setInt("/options/clonecompensation/value", saved_compensation); - g_slist_free(items); DocumentUndo::done(doc, SP_VERB_EDIT_SELECTION_2_MARKER, _("Objects to marker")); @@ -3028,8 +3004,9 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) static void sp_selection_to_guides_recursive(SPItem *item, bool wholegroups) { SPGroup *group = dynamic_cast(item); if (group && !dynamic_cast(item) && !wholegroups) { - for (GSList *i = sp_item_group_item_list(group); i != NULL; i = i->next) { - sp_selection_to_guides_recursive(static_cast(i->data), wholegroups); + SelContainer items=sp_item_group_item_list(group); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + sp_selection_to_guides_recursive(static_cast(*i), wholegroups); } } else { item->convert_to_guides(); @@ -3044,9 +3021,9 @@ void sp_selection_to_guides(SPDesktop *desktop) SPDocument *doc = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); // we need to copy the list because it gets reset when objects are deleted - GSList *items = g_slist_copy(const_cast(selection->itemList())); + SelContainer items(selection->itemList()); - if (!items) { + if (items.empty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to convert to guides.")); return; } @@ -3059,8 +3036,8 @@ void sp_selection_to_guides(SPDesktop *desktop) // and its entry in the selection list is invalid (crash). // Therefore: first convert all, then delete all. - for (GSList const *i = items; i != NULL; i = i->next) { - sp_selection_to_guides_recursive(static_cast(i->data), wholegroups); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + sp_selection_to_guides_recursive(static_cast(*i), wholegroups); } if (deleteitems) { @@ -3068,8 +3045,6 @@ void sp_selection_to_guides(SPDesktop *desktop) sp_selection_delete_impl(items); } - g_slist_free(items); - DocumentUndo::done(doc, SP_VERB_EDIT_SELECTION_2_GUIDES, _("Objects to guides")); } @@ -3112,18 +3087,18 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) doc->ensureUpToDate(); - GSList *items = g_slist_copy(const_cast(selection->list())); + SelContainer items(selection->list()); // Keep track of parent, this is where will be inserted. - Inkscape::XML::Node *the_first_repr = reinterpret_cast( items->data )->getRepr(); + Inkscape::XML::Node *the_first_repr = reinterpret_cast( items.front() )->getRepr(); Inkscape::XML::Node *the_parent_repr = the_first_repr->parent(); // Find out if we have a single group bool single_group = false; SPGroup *the_group = NULL; Geom::Affine transform; - if( g_slist_length( items ) == 1 ) { - SPObject *object = reinterpret_cast( items->data ); + if( items.size() == 1 ) { + SPObject *object = reinterpret_cast( items.front() ); the_group = dynamic_cast(object); if ( the_group ) { single_group = true; @@ -3134,7 +3109,6 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) if( transform.isTranslation() ) { // Create new list from group children. - g_slist_free(items); items = object->childList(false); // Hack: Temporarily set clone compensation to unmoved, so that we can move clone-originals @@ -3180,8 +3154,8 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) } // Move selected items to new - for (GSList *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *repr = SP_OBJECT(i->data)->getRepr(); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + Inkscape::XML::Node *repr = SP_OBJECT(*i)->getRepr(); repr->parent()->removeChild(repr); symbol_repr->addChild(repr,NULL); } @@ -3207,7 +3181,6 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) // Clean up Inkscape::GC::release(symbol_repr); - g_slist_free(items); DocumentUndo::done(doc, SP_VERB_EDIT_SYMBOL, _("Group to symbol")); } @@ -3248,26 +3221,25 @@ void sp_selection_unsymbol(SPDesktop *desktop) desktop->currentLayer()->getRepr()->appendChild(group); // Move all children of symbol to group - GSList* children = symbol->childList(false); + SelContainer children = symbol->childList(false); // Converting a group to a symbol inserts a group for non-translational transform. // In converting a symbol back to a group we strip out the inserted group (or any other // group that only adds a transform to the symbol content). - if( g_slist_length( children ) == 1 ) { - SPObject *object = reinterpret_cast( children->data ); + if( children.size() == 1 ) { + SPObject *object = reinterpret_cast( children.front() ); if ( dynamic_cast( object ) ) { if( object->getAttribute("style") == NULL || object->getAttribute("class") == NULL ) { group->setAttribute("transform", object->getAttribute("transform")); - g_slist_free(children); children = object->childList(false); } } } - for (GSList* i = children; i != NULL; i = i->next ) { - Inkscape::XML::Node *repr = SP_OBJECT(i->data)->getRepr(); + for (SelContainer::const_iterator i=children.begin();i!=children.end();i++){ + Inkscape::XML::Node *repr = SP_OBJECT(*i)->getRepr(); repr->parent()->removeChild(repr); group->addChild(repr,NULL); } @@ -3293,7 +3265,6 @@ void sp_selection_unsymbol(SPDesktop *desktop) // Clean up Inkscape::GC::release(group); - g_slist_free(children); DocumentUndo::done(doc, SP_VERB_EDIT_UNSYMBOL, _("Group from symbol")); } @@ -3328,12 +3299,12 @@ sp_selection_tile(SPDesktop *desktop, bool apply) move_p[Geom::Y] = -move_p[Geom::Y]; Geom::Affine move = Geom::Affine(Geom::Translate(move_p)); - GSList *items = g_slist_copy(const_cast(selection->itemList())); + SelContainer items (selection->itemList()); - items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); + items.sort(sp_object_compare_position); // bottommost object, after sorting - SPObject *parent = SP_OBJECT(items->data)->parent; + SPObject *parent = SP_OBJECT(items.front())->parent; Geom::Affine parent_transform; @@ -3347,23 +3318,23 @@ sp_selection_tile(SPDesktop *desktop, bool apply) } // remember the position of the first item - gint pos = SP_OBJECT(items->data)->getRepr()->position(); + gint pos = SP_OBJECT(items.front())->getRepr()->position(); // create a list of duplicates - GSList *repr_copies = NULL; - for (GSList *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); - repr_copies = g_slist_prepend(repr_copies, dup); + SelContainer repr_copies; + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); + repr_copies.push_front(dynamic_cast(dup)); } // restore the z-order after prepends - repr_copies = g_slist_reverse(repr_copies); + repr_copies.reverse(); Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max())); if (apply) { // delete objects so that their clones don't get alerted; this object will be restored shortly - for (GSList *i = items; i != NULL; i = i->next) { - SPObject *item = reinterpret_cast(i->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *item = reinterpret_cast(*i); item->deleteObject(false); } } @@ -3409,7 +3380,6 @@ sp_selection_tile(SPDesktop *desktop, bool apply) selection->set(rectangle); } - g_slist_free(items); DocumentUndo::done(doc, SP_VERB_EDIT_TILE, _("Objects to pattern")); @@ -3432,15 +3402,13 @@ void sp_selection_untile(SPDesktop *desktop) return; } - GSList *new_select = NULL; + SelContainer new_select; bool did = false; - for (GSList *items = g_slist_copy(const_cast(selection->itemList())); - items != NULL; - items = items->next) { - - SPItem *item = static_cast(items->data); + SelContainer items(selection->itemList()); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = static_cast(*i); SPStyle *style = item->style; @@ -3476,7 +3444,7 @@ void sp_selection_untile(SPDesktop *desktop) Geom::Affine transform( i->transform * pat_transform ); i->doWriteTransform(i->getRepr(), transform); - new_select = g_slist_prepend(new_select, i); + new_select.push_front(i); } else { g_assert_not_reached(); } @@ -3503,18 +3471,14 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring return; } - GSList const *reprlst = selection->reprList(); + SelContainer const reprlst = selection->reprList(); bool filename_search = TRUE; bool xdpi_search = TRUE; bool ydpi_search = TRUE; - for (; reprlst != NULL && - filename_search && - xdpi_search && - ydpi_search; - reprlst = reprlst->next) { + for (SelContainer::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){ gchar const *dpi_string; - Inkscape::XML::Node * repr = static_cast(reprlst->data); + Inkscape::XML::Node * repr = dynamic_cast(*i); if (filename_search) { const gchar* tmp = repr->attribute("inkscape:export-filename"); @@ -3600,10 +3564,10 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) } // List of the items to show; all others will be hidden - GSList *items = g_slist_copy(const_cast(selection->itemList())); + SelContainer items(selection->itemList()); // Sort items so that the topmost comes last - items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); + items.sort(sp_item_repr_compare_position_obj); // Generate a random value from the current time (you may create bitmap from the same object(s) // multiple times, and this is done so that they don't clash) @@ -3614,7 +3578,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) // Create the filename. gchar *const basename = g_strdup_printf("%s-%s-%u.png", document->getName(), - SP_OBJECT(items->data)->getRepr()->attribute("id"), + SP_OBJECT(items.front())->getRepr()->attribute("id"), current); // Imagemagick is known not to handle spaces in filenames, so we replace anything but letters, // digits, and a few other chars, with "_" @@ -3634,8 +3598,8 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) //g_print("%s\n", filepath); // Remember parent and z-order of the topmost one - gint pos = SP_OBJECT(g_slist_last(items)->data)->getRepr()->position(); - SPObject *parent_object = SP_OBJECT(g_slist_last(items)->data)->parent; + gint pos = SP_OBJECT(items.back())->getRepr()->position(); + SPObject *parent_object = SP_OBJECT(items.back())->parent; Inkscape::XML::Node *parent = parent_object->getRepr(); // Calculate resolution @@ -3727,8 +3691,6 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) true, /*bool force_overwrite,*/ items); - g_slist_free(items); - // Run filter, if any if (run) { g_print("Running external filter: %s\n", run); @@ -3803,22 +3765,22 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) return; } - GSList const *l = const_cast(selection->reprList()); + SelContainer l=selection->reprList(); - GSList *p = g_slist_copy(const_cast(l)); + SelContainer p(l); - p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position); + p.sort(sp_repr_compare_position_obj); selection->clear(); - gint topmost = (static_cast(g_slist_last(p)->data))->position(); - Inkscape::XML::Node *topmost_parent = (static_cast(g_slist_last(p)->data))->parent(); + gint topmost = (dynamic_cast(p.back()))->position(); + Inkscape::XML::Node *topmost_parent = (dynamic_cast(p.back()))->parent(); Inkscape::XML::Node *inner = xml_doc->createElement("svg:g"); inner->setAttribute("inkscape:label", "Clip"); - while (p) { - Inkscape::XML::Node *current = static_cast(p->data); + while (!p.empty()) { + Inkscape::XML::Node *current = dynamic_cast(p.front()); if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -3827,7 +3789,7 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) Inkscape::GC::release(spnew); topmost --; // only reduce count for those items deleted from topmost_parent } else { // move it to topmost_parent first - GSList *temp_clip = NULL; + SelContainer temp_clip; // At this point, current may already have no item, due to its being a clone whose original is already moved away // So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform @@ -3843,15 +3805,14 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) // then, if this is clone, looking up its original in that array and pre-multiplying // it by the inverse of that original's transform diff. - sp_selection_copy_one(current, item_t, &temp_clip, xml_doc); + sp_selection_copy_one(current, item_t, temp_clip, xml_doc); sp_repr_unparent(current); // paste into topmost_parent (temporarily) - GSList *copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), &temp_clip); - if (temp_clip) g_slist_free(temp_clip); - if (copied) { // if success, + SelContainer copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), temp_clip); + if (!copied.empty()) { // if success, // take pasted object (now in topmost_parent) - Inkscape::XML::Node *in_topmost = static_cast(copied->data); + Inkscape::XML::Node *in_topmost = dynamic_cast(copied.front()); // make a copy Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc); // remove pasted @@ -3859,10 +3820,9 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) // put its copy into group inner->appendChild(spnew); Inkscape::GC::release(spnew); - g_slist_free(copied); } } - p = g_slist_remove(p, current); + p.pop_front(); } Inkscape::XML::Node *outer = xml_doc->createElement("svg:g"); @@ -3920,7 +3880,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ if ( apply_to_layer && is_empty) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to create clippath or mask from.")); return; - } else if (!apply_to_layer && ( is_empty || NULL == selection->itemList()->next )) { + } else if (!apply_to_layer && ( is_empty || selection->itemList().size()==1 )) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select mask object and object(s) to apply clippath or mask to.")); return; } @@ -3935,9 +3895,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ doc->ensureUpToDate(); - GSList *items = g_slist_copy(const_cast(selection->itemList())); + SelContainer items(selection->itemList()); - items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); + items.sort(sp_object_compare_position); // See lp bug #542004 selection->clear(); @@ -3946,7 +3906,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ GSList *mask_items = NULL; GSList *apply_to_items = NULL; GSList *items_to_delete = NULL; - GSList *items_to_select = NULL; + SelContainer items_to_select; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool topmost = prefs->getBool("/options/maskobject/topmost", true); @@ -3957,38 +3917,38 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // all selected items are used for mask, which is applied to a layer apply_to_items = g_slist_prepend(apply_to_items, desktop->currentLayer()); - for (GSList *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); - SPObject *item = reinterpret_cast(i->data); + SPObject *item = reinterpret_cast(*i); if (remove_original) { items_to_delete = g_slist_prepend(items_to_delete, item); } else { - items_to_select = g_slist_prepend(items_to_select, item); + items_to_select.push_front(item); } } } else if (!topmost) { // topmost item is used as a mask, which is applied to other items in a selection - GSList *i = items; - Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *dup = SP_OBJECT(items.front())->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); if (remove_original) { - SPObject *item = reinterpret_cast(i->data); + SPObject *item = reinterpret_cast(items.front()); items_to_delete = g_slist_prepend(items_to_delete, item); } - for (i = i->next; i != NULL; i = i->next) { - apply_to_items = g_slist_prepend(apply_to_items, i->data); - items_to_select = g_slist_prepend(items_to_select, i->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + if(i==items.begin())continue; + apply_to_items = g_slist_prepend(apply_to_items, *i); + items_to_select.push_front(*i); } } else { GSList *i = NULL; - for (i = items; NULL != i->next; i = i->next) { - apply_to_items = g_slist_prepend(apply_to_items, i->data); - items_to_select = g_slist_prepend(items_to_select, i->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + apply_to_items = g_slist_prepend(apply_to_items, *i); + items_to_select.push_front(*i); } Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); @@ -3999,9 +3959,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ items_to_delete = g_slist_prepend(items_to_delete, item); } } - - g_slist_free(items); - items = NULL; + items.clear(); if (apply_to_items && grouping == PREFS_MASKOBJECT_GROUPING_ALL) { // group all those objects into one group @@ -4011,24 +3969,22 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // make a note we should ungroup this when unsetting mask group->setAttribute("inkscape:groupmode", "maskhelper"); - GSList *reprs_to_group = NULL; + SelContainer reprs_to_group; for (GSList *i = apply_to_items ; NULL != i ; i = i->next) { - reprs_to_group = g_slist_prepend(reprs_to_group, SP_OBJECT(i->data)->getRepr()); - items_to_select = g_slist_remove(items_to_select, i->data); + reprs_to_group.push_front(dynamic_cast(SP_OBJECT(i->data)->getRepr())); + items_to_select.remove(static_cast(i->data)); } - reprs_to_group = g_slist_reverse(reprs_to_group); + reprs_to_group.reverse(); sp_selection_group_impl(reprs_to_group, group, xml_doc, doc); - reprs_to_group = NULL; - // apply clip/mask only to newly created group g_slist_free(apply_to_items); apply_to_items = NULL; apply_to_items = g_slist_prepend(apply_to_items, doc->getObjectByRepr(group)); - items_to_select = g_slist_prepend(items_to_select, doc->getObjectByRepr(group)); + items_to_select.push_front(doc->getObjectByRepr(group)); Inkscape::GC::release(group); } @@ -4068,7 +4024,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::XML::Node *spnew = current->duplicate(xml_doc); gint position = current->position(); - items_to_select = g_slist_remove(items_to_select, item); + items_to_select.remove(item); current->parent()->appendChild(group); sp_repr_unparent(current); group->appendChild(spnew); @@ -4077,7 +4033,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // Apply clip/mask to group instead apply_mask_to = group; - items_to_select = g_slist_prepend(items_to_select, doc->getObjectByRepr(group)); + items_to_select.push_front(doc->getObjectByRepr(group)); Inkscape::GC::release(spnew); Inkscape::GC::release(group); } @@ -4092,14 +4048,13 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = items_to_delete; NULL != i; i = i->next) { SPObject *item = reinterpret_cast(i->data); item->deleteObject(false); - items_to_select = g_slist_remove(items_to_select, item); + items_to_select.remove(item); } g_slist_free(items_to_delete); - items_to_select = g_slist_reverse(items_to_select); + items_to_select.reverse(); selection->addList(items_to_select); - g_slist_free(items_to_select); if (apply_clip_path) { DocumentUndo::done(doc, SP_VERB_OBJECT_SET_CLIPPATH, _("Set clipping path")); @@ -4131,20 +4086,20 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { gchar const *attributeName = apply_clip_path ? "clip-path" : "mask"; std::map referenced_objects; - GSList *items = g_slist_copy(const_cast(selection->itemList())); + SelContainer items(selection->itemList()); selection->clear(); GSList *items_to_ungroup = NULL; - GSList *items_to_select = g_slist_copy(items); - items_to_select = g_slist_reverse(items_to_select); + SelContainer items_to_select(items); + items_to_select.reverse(); // SPObject* refers to a group containing the clipped path or mask itself, // whereas SPItem* refers to the item being clipped or masked - for (GSList const *i = items; NULL != i; i = i->next) { + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ if (remove_original) { // remember referenced mask/clippath, so orphaned masks can be moved back to document - SPItem *item = reinterpret_cast(i->data); + SPItem *item = reinterpret_cast(*i); Inkscape::URIReference *uri_ref = NULL; if (apply_clip_path) { @@ -4159,9 +4114,9 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { } } - SP_OBJECT(i->data)->getRepr()->setAttribute(attributeName, "none"); + SP_OBJECT(*i)->getRepr()->setAttribute(attributeName, "none"); - SPGroup *group = dynamic_cast(static_cast(i->data)); + SPGroup *group = dynamic_cast(static_cast(*i)); if (ungroup_masked && group) { // if we had previously enclosed masked object in group, // add it to list so we can ungroup it later @@ -4173,7 +4128,6 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { } } - g_slist_free(items); // restore mask objects into a document for ( std::map::iterator it = referenced_objects.begin() ; it != referenced_objects.end() ; ++it) { @@ -4207,7 +4161,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { repr->setPosition((pos + 1) > 0 ? (pos + 1) : 0); SPItem *mask_item = static_cast(desktop->getDocument()->getObjectByRepr(repr)); - items_to_select = g_slist_prepend(items_to_select, mask_item); + items_to_select.push_front(mask_item); // transform mask, so it is moved the same spot where mask was applied Geom::Affine transform(mask_item->transform); @@ -4222,10 +4176,10 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { for (GSList *i = items_to_ungroup ; NULL != i ; i = i->next) { SPGroup *group = dynamic_cast(static_cast(i->data)); if (group) { - items_to_select = g_slist_remove(items_to_select, group); - GSList *children = NULL; - sp_item_group_ungroup(group, &children, false); - items_to_select = g_slist_concat(children, items_to_select); + items_to_select.remove(group); + SelContainer children; + sp_item_group_ungroup(group, children, false); + items_to_select.splice(items_to_select.begin(),children); } else { g_assert_not_reached(); } @@ -4234,9 +4188,8 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { g_slist_free(items_to_ungroup); // rebuild selection - items_to_select = g_slist_reverse(items_to_select); + items_to_select.reverse(); selection->addList(items_to_select); - g_slist_free(items_to_select); if (apply_clip_path) { DocumentUndo::done(doc, SP_VERB_OBJECT_UNSET_CLIPPATH, _("Release clipping path")); diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index d86906548..bc317d556 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -19,6 +19,7 @@ #include <2geom/forward.h> #include "sp-item.h" +#include "selection.h" class SPCSSAttr; class SPDesktop; @@ -142,9 +143,9 @@ enum SPSelectStrokeStyleType { void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolean strok, gboolean style); void sp_select_same_stroke_style(SPDesktop *desktop); void sp_select_same_object_type(SPDesktop *desktop); -GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrokeStyleType type); -GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type); -GSList *sp_get_same_object_type(SPItem *sel, GSList *src); +SelContainer sp_get_same_fill_or_stroke_color(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type); +SelContainer sp_get_same_stroke_style(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type); +SelContainer sp_get_same_object_type(SPItem *sel, SelContainer &src); void scroll_to_show_item(SPDesktop *desktop, SPItem *item); @@ -171,9 +172,9 @@ void unlock_all_in_all_layers(SPDesktop *dt); void unhide_all(SPDesktop *dt); void unhide_all_in_all_layers(SPDesktop *dt); -GSList *get_all_items(GSList *list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, GSList const *exclude); +SelContainer &get_all_items(SelContainer &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, SelContainer const &exclude); -GSList *sp_degroup_list (GSList *items); +SelContainer sp_degroup_list (SelContainer &items); /* selection cycling */ typedef enum diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index f7814fd57..0625c4002 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -40,14 +40,14 @@ #include "sp-spiral.h" // Returns a list of terms for the items to be used in the statusbar -char* collect_terms (GSList *items) +char* collect_terms (const SelContainer &items) { GSList *check = NULL; std::stringstream ss; bool first = true; - for (GSList *i = (GSList *)items; i != NULL; i = i->next) { - SPItem *item = dynamic_cast(reinterpret_cast(i->data)); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *item = dynamic_cast(reinterpret_cast(*iter)); if (item) { const char *term = item->displayName(); if (term != NULL && g_slist_find (check, term) == NULL) { @@ -61,12 +61,12 @@ char* collect_terms (GSList *items) } // Returns the number of terms in the list -static int count_terms (GSList *items) +static int count_terms (const SelContainer &items) { GSList *check = NULL; int count=0; - for (GSList *i = (GSList *)items; i != NULL; i = i->next) { - SPItem *item = dynamic_cast(reinterpret_cast(i->data)); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *item = dynamic_cast(reinterpret_cast(*iter)); if (item) { const char *term = item->displayName(); if (term != NULL && g_slist_find (check, term) == NULL) { @@ -79,11 +79,11 @@ static int count_terms (GSList *items) } // Returns the number of filtered items in the list -static int count_filtered (GSList *items) +static int count_filtered (const SelContainer &items) { int count=0; - for (GSList *i = items; i != NULL; i = i->next) { - SPItem *item = dynamic_cast(reinterpret_cast((i->data))); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *item = dynamic_cast(reinterpret_cast((*iter))); if (item) { count += item->isFiltered(); } @@ -122,12 +122,12 @@ void SelectionDescriber::_selectionModified(Inkscape::Selection *selection, guin } void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *selection) { - GSList const *items = selection->itemList(); + SelContainer const items = selection->itemList(); - if (!items) { // no items + if (items.empty()) { // no items _context.set(Inkscape::NORMAL_MESSAGE, _when_nothing); } else { - SPItem *item = dynamic_cast(reinterpret_cast(items->data)); + SPItem *item = dynamic_cast(reinterpret_cast(items.front())); g_assert(item != NULL); SPObject *layer = selection->layers()->layerForObject(item); SPObject *root = selection->layers()->currentRoot(); @@ -188,7 +188,7 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select g_free (layer_name); g_free (parent_name); - if (!items->next) { // one item + if (items.size()==1) { // one item char *item_desc = item->detailedDescription(); bool isUse = dynamic_cast(item) != NULL; @@ -228,9 +228,9 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select g_free(item_desc); } else { // multiple items - int objcount = g_slist_length((GSList *)items); - char *terms = collect_terms ((GSList *)items); - int n_terms = count_terms((GSList *)items); + int objcount = items.size(); + char *terms = collect_terms (items); + int n_terms = count_terms(items); gchar *objects_str = g_strdup_printf(ngettext( "%i objects selected of type %s", @@ -241,7 +241,7 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select // indicate all, some, or none filtered gchar *filt_str = NULL; - int n_filt = count_filtered((GSList *)items); //all filtered + int n_filt = count_filtered(items); //all filtered if (n_filt) { filt_str = g_strdup_printf(ngettext("; %d filtered object ", "; %d filtered objects ", n_filt), n_filt); diff --git a/src/selection.cpp b/src/selection.cpp index 81139d044..b509f4272 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -42,9 +42,9 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : - _objs(NULL), - _reprs(NULL), - _items(NULL), + _objs(SelContainer()), + _reprs(SelContainer()), + _items(SelContainer()), _layers(layers), _desktop(desktop), _selection_context(NULL), @@ -121,17 +121,14 @@ Selection::_releaseContext(SPObject *obj) } void Selection::_invalidateCachedLists() { - g_slist_free(_items); - _items = NULL; - - g_slist_free(_reprs); - _reprs = NULL; + _items.clear(); + _reprs.clear(); } void Selection::_clear() { _invalidateCachedLists(); - while (_objs) { - SPObject *obj=reinterpret_cast(_objs->data); + while (!_objs.empty()) { + SPObject *obj=reinterpret_cast(_objs.front()); _remove(obj); } } @@ -148,7 +145,7 @@ bool Selection::includes(SPObject *obj) const { g_return_val_if_fail(SP_IS_OBJECT(obj), FALSE); - return ( g_slist_find(_objs, obj) != NULL ); + return ( find(_objs.begin(),_objs.end(),obj)!=_objs.end() ); } void Selection::add(SPObject *obj, bool persist_selection_context/* = false */) { @@ -180,7 +177,7 @@ void Selection::_add(SPObject *obj) { _removeObjectDescendants(obj); _removeObjectAncestors(obj); - _objs = g_slist_prepend(_objs, obj); + _objs.push_front(obj); add_3D_boxes_recursively(obj); @@ -234,26 +231,26 @@ void Selection::_remove(SPObject *obj) { remove_3D_boxes_recursively(obj); - _objs = g_slist_remove(_objs, obj); + _objs.remove(obj); } -void Selection::setList(GSList const *list) { +void Selection::setList(SelContainer const &list) { // Clear and add, or just clear with emit. - if (list != NULL) { + if (!list.empty()) { _clear(); addList(list); } else clear(); } -void Selection::addList(GSList const *list) { +void Selection::addList(SelContainer const &list) { - if (list == NULL) + if (list.empty()) return; _invalidateCachedLists(); - for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) { - SPObject *obj = reinterpret_cast(iter->data); + for ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + SPObject *obj = reinterpret_cast(*iter); if (includes(obj)) continue; _add (obj); } @@ -261,11 +258,11 @@ void Selection::addList(GSList const *list) { _emitChanged(); } -void Selection::setReprList(GSList const *list) { +void Selection::setReprList(SelContainer const &list) { _clear(); - for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) { - SPObject *obj=_objectForXMLNode(reinterpret_cast(iter->data)); + for ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + SPObject *obj=_objectForXMLNode(reinterpret_cast(*iter)); if (obj) { _add(obj); } @@ -279,34 +276,34 @@ void Selection::clear() { _emitChanged(); } -GSList const *Selection::list() { +SelContainer const &Selection::list() { return _objs; } -GSList const *Selection::itemList() { - if (_items) { +SelContainer const &Selection::itemList() { + if (!_items.empty()) { return _items; } - for ( GSList const *iter=_objs ; iter != NULL ; iter = iter->next ) { - SPObject *obj=reinterpret_cast(iter->data); + for ( SelContainer::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + SPObject *obj=reinterpret_cast(*iter); if (SP_IS_ITEM(obj)) { - _items = g_slist_prepend(_items, SP_ITEM(obj)); + _items.push_front(SP_ITEM(obj)); } } - _items = g_slist_reverse(_items); + _items.reverse(); return _items; } -GSList const *Selection::reprList() { - if (_reprs) { return _reprs; } - - for ( GSList const *iter=itemList() ; iter != NULL ; iter = iter->next ) { - SPObject *obj=reinterpret_cast(iter->data); - _reprs = g_slist_prepend(_reprs, obj->getRepr()); +SelContainer const &Selection::reprList() { + if (!_reprs.empty()) { return _reprs; } + SelContainer list = itemList(); + for ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + SPObject *obj=reinterpret_cast(*iter); + _reprs.push_front(dynamic_cast(obj->getRepr())); } - _reprs = g_slist_reverse(_reprs); + _reprs.reverse(); return _reprs; } @@ -337,17 +334,17 @@ std::list const Selection::box3DList(Persp3D *persp) { } SPObject *Selection::single() { - if ( _objs != NULL && _objs->next == NULL ) { - return reinterpret_cast(_objs->data); + if ( _objs.size() == 1 ) { + return reinterpret_cast(_objs.front()); } else { return NULL; } } SPItem *Selection::singleItem() { - GSList const *items=itemList(); - if ( items != NULL && items->next == NULL ) { - return reinterpret_cast(items->data); + SelContainer const items=itemList(); + if ( !items.size()==1) { + return reinterpret_cast(items.front()); } else { return NULL; } @@ -362,12 +359,12 @@ SPItem *Selection::largestItem(Selection::CompareSize compare) { } SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { - GSList const *items = const_cast(this)->itemList(); + SelContainer const items = const_cast(this)->itemList(); gdouble max = sml ? 1e18 : 0; SPItem *ist = NULL; - for ( GSList const *i = items; i != NULL ; i = i->next ) { - Geom::OptRect obox = SP_ITEM(i->data)->desktopPreferredBounds(); + for ( SelContainer::const_iterator i=items.begin();i!=items.end();i++ ) { + Geom::OptRect obox = SP_ITEM(*i)->desktopPreferredBounds(); if (!obox || obox.isEmpty()) continue; Geom::Rect bbox = *obox; @@ -376,7 +373,7 @@ SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { size = sml ? size : size * -1; if (size < max) { max = size; - ist = SP_ITEM(i->data); + ist = SP_ITEM(*i); } } return ist; @@ -395,22 +392,22 @@ Geom::OptRect Selection::bounds(SPItem::BBoxType type) const Geom::OptRect Selection::geometricBounds() const { - GSList const *items = const_cast(this)->itemList(); + SelContainer const items = const_cast(this)->itemList(); Geom::OptRect bbox; - for ( GSList const *i = items ; i != NULL ; i = i->next ) { - bbox.unionWith(SP_ITEM(i->data)->desktopGeometricBounds()); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + bbox.unionWith(SP_ITEM(*iter)->desktopGeometricBounds()); } return bbox; } Geom::OptRect Selection::visualBounds() const { - GSList const *items = const_cast(this)->itemList(); + SelContainer const items = const_cast(this)->itemList(); Geom::OptRect bbox; - for ( GSList const *i = items ; i != NULL ; i = i->next ) { - bbox.unionWith(SP_ITEM(i->data)->desktopVisualBounds()); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + bbox.unionWith(SP_ITEM(*iter)->desktopVisualBounds()); } return bbox; } @@ -427,11 +424,11 @@ Geom::OptRect Selection::preferredBounds() const Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const { Geom::OptRect bbox; - GSList const *items = const_cast(this)->itemList(); - if (!items) return bbox; + SelContainer const items = const_cast(this)->itemList(); + if (items.empty()) return bbox; - for ( GSList const *iter=items ; iter != NULL ; iter = iter->next ) { - SPItem *item = SP_ITEM(iter->data); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *item = SP_ITEM(*iter); bbox |= item->documentBounds(type); } @@ -441,9 +438,9 @@ Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const // If we have a selection of multiple items, then the center of the first item // will be returned; this is also the case in SelTrans::centerRequest() boost::optional Selection::center() const { - GSList *items = (GSList *) const_cast(this)->itemList(); - if (items) { - SPItem *first = reinterpret_cast(g_slist_last(items)->data); // from the first item in selection + SelContainer const items = const_cast(this)->itemList(); + if (!items.empty()) { + SPItem *first = reinterpret_cast(items.back()); // from the first item in selection if (first->isCenterSet()) { // only if set explicitly return first->getCenter(); } @@ -457,13 +454,13 @@ boost::optional Selection::center() const { } std::vector Selection::getSnapPoints(SnapPreferences const *snapprefs) const { - GSList const *items = const_cast(this)->itemList(); + SelContainer const items = const_cast(this)->itemList(); SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center std::vector p; - for (GSList const *iter = items; iter != NULL; iter = iter->next) { - SPItem *this_item = SP_ITEM(iter->data); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *this_item = SP_ITEM(*iter); this_item->getSnappoints(p, &snapprefs_dummy); //Include the transformation origin for snapping @@ -477,10 +474,8 @@ std::vector Selection::getSnapPoints(SnapPreferenc } void Selection::_removeObjectDescendants(SPObject *obj) { - GSList *iter, *next; - for ( iter = _objs ; iter ; iter = next ) { - next = iter->next; - SPObject *sel_obj=reinterpret_cast(iter->data); + for ( SelContainer::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + SPObject *sel_obj=reinterpret_cast(*iter); SPObject *parent = sel_obj->parent; while (parent) { if ( parent == obj ) { @@ -511,32 +506,24 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { return object; } -guint Selection::numberOfLayers() { - GSList const *items = const_cast(this)->itemList(); - GSList *layers = NULL; - for (GSList const *iter = items; iter != NULL; iter = iter->next) { - SPObject *layer = _layers->layerForObject(SP_OBJECT(iter->data)); - if (g_slist_find (layers, layer) == NULL) { - layers = g_slist_prepend (layers, layer); - } +uint Selection::numberOfLayers() { + SelContainer const items = const_cast(this)->itemList(); + std::set layers; + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPObject *layer = _layers->layerForObject(SP_OBJECT(*iter)); + layers.insert(layer); } - guint ret = g_slist_length (layers); - g_slist_free (layers); - return ret; + return layers.size(); } guint Selection::numberOfParents() { - GSList const *items = const_cast(this)->itemList(); - GSList *parents = NULL; - for (GSList const *iter = items; iter != NULL; iter = iter->next) { - SPObject *parent = SP_OBJECT(iter->data)->parent; - if (g_slist_find (parents, parent) == NULL) { - parents = g_slist_prepend (parents, parent); - } + SelContainer const items = const_cast(this)->itemList(); + std::set parents; + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPObject *parent = SP_OBJECT(*iter)->parent; + parents.insert(parent); } - guint ret = g_slist_length (parents); - g_slist_free (parents); - return ret; + return parents.size(); } } diff --git a/src/selection.h b/src/selection.h index 5964b20e8..7171b8742 100644 --- a/src/selection.h +++ b/src/selection.h @@ -19,6 +19,11 @@ #include #include +#include +#include +#include +#include + #include "gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" @@ -26,11 +31,13 @@ #include "sp-item.h" + class SPDesktop; class SPItem; class SPBox3D; class Persp3D; -typedef struct _GSList GSList; + +typedef std::list SelContainer; namespace Inkscape { class LayerModel; @@ -39,6 +46,15 @@ class Node; } } +/*template +const GSList* std_list_to_GS_list(const std::list list) const +{ + gpointer l=NULL; + for(auto x:list){ + + } +}*/ + namespace Inkscape { /** @@ -154,21 +170,21 @@ public: * * @param objs the objects to select */ - void setList(GSList const *objs); + void setList(SelContainer const &objs); /** * Adds the specified objects to selection, without deselecting first. * * @param objs the objects to select */ - void addList(GSList const *objs); + void addList(SelContainer const &objs); /** * Clears the selection and selects the specified objects. * * @param repr a list of xml nodes for the items to select */ - void setReprList(GSList const *reprs); + void setReprList(std::list const &reprs); /** Add items from an STL iterator range to the selection. * \param from the begin iterator @@ -192,7 +208,7 @@ public: /** * Returns true if no items are selected. */ - bool isEmpty() const { return _objs == NULL; } + bool isEmpty() const { return _objs.empty(); } /** * Returns true if the given object is selected. @@ -238,13 +254,13 @@ public: XML::Node *singleRepr(); /** Returns the list of selected objects. */ - GSList const *list(); + std::list const &list(); /** Returns the list of selected SPItems. */ - GSList const *itemList(); + std::list const &itemList(); /** Returns a list of the xml nodes of all selected objects. */ /// \todo only returns reprs of SPItems currently; need a separate /// method for that - GSList const *reprList(); + std::list const &reprList(); /** Returns a list of all perspectives which have a 3D box in the current selection. (these may also be nested in groups) */ @@ -360,9 +376,9 @@ private: /** Releases an active layer object that is being removed. */ void _releaseContext(SPObject *obj); - mutable GSList *_objs; - mutable GSList *_reprs; - mutable GSList *_items; + mutable std::list _objs; + mutable std::list _reprs; + mutable std::list _items; void add_box_perspective(SPBox3D *box); void add_3D_boxes_recursively(SPObject *obj); diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 5e4c0642e..8c06356db 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -112,7 +112,7 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) : _opposite_for_bboxpoints(Geom::Point(0,0)), _origin_for_specpoints(Geom::Point(0,0)), _origin_for_bboxpoints(Geom::Point(0,0)), - _stamp_cache(NULL), + _stamp_cache(SelContainer()), _message_context(desktop->messageStack()), _bounding_box_prefs_observer(*this) { @@ -239,8 +239,9 @@ void Inkscape::SelTrans::setCenter(Geom::Point const &p) _center_is_set = true; // Write the new center position into all selected items - for (GSList const *l = _desktop->selection->itemList(); l; l = l->next) { - SPItem *it = SP_ITEM(l->data); + SelContainer items=_desktop->selection->itemList(); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *it = SP_ITEM(*iter); it->setCenter(p); // only set the value; updating repr and document_done will be done once, on ungrab } @@ -268,8 +269,9 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s return; } - for (GSList const *l = selection->itemList(); l; l = l->next) { - SPItem *it = reinterpret_cast(sp_object_ref(SP_ITEM(l->data), NULL)); + SelContainer items=_desktop->selection->itemList(); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *it = reinterpret_cast(sp_object_ref(SP_ITEM(*iter), NULL)); _items.push_back(it); _items_const.push_back(it); _items_affines.push_back(it->i2dt_affine()); @@ -370,7 +372,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s } _updateHandles(); - g_return_if_fail(_stamp_cache == NULL); + g_return_if_fail(_stamp_cache.empty()); } void Inkscape::SelTrans::transform(Geom::Affine const &rel_affine, Geom::Point const &norm) @@ -433,9 +435,8 @@ void Inkscape::SelTrans::ungrab() sp_canvas_item_hide(_l[i]); } - if (_stamp_cache) { - g_slist_free(_stamp_cache); - _stamp_cache = NULL; + if (!_stamp_cache.empty()) { + _stamp_cache.clear(); } _message_context.clear(); @@ -491,8 +492,9 @@ void Inkscape::SelTrans::ungrab() if (_center_is_set) { // we were dragging center; update reprs and commit undoable action - for (GSList const *l = _desktop->selection->itemList(); l; l = l->next) { - SPItem *it = SP_ITEM(l->data); + SelContainer items=_desktop->selection->itemList(); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *it = SP_ITEM(*iter); it->updateRepr(); } DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, @@ -515,26 +517,25 @@ void Inkscape::SelTrans::stamp() Inkscape::Selection *selection = _desktop->getSelection(); bool fixup = !_grabbed; - if ( fixup && _stamp_cache ) { + if ( fixup && !_stamp_cache.empty() ) { // TODO - give a proper fix. Simple temporary work-around for the grab() issue - g_slist_free(_stamp_cache); - _stamp_cache = NULL; + _stamp_cache.clear(); } /* stamping mode */ if (!_empty) { - GSList *l; - if (_stamp_cache) { + SelContainer l; + if (!_stamp_cache.empty()) { l = _stamp_cache; } else { /* Build cache */ - l = g_slist_copy((GSList *) selection->itemList()); - l = g_slist_sort(l, (GCompareFunc) sp_object_compare_position); + l = selection->itemList(); + l.sort(sp_object_compare_position); _stamp_cache = l; } - while (l) { - SPItem *original_item = SP_ITEM(l->data); + for(SelContainer::const_iterator x=l.begin();x!=l.end();x++) { + SPItem *original_item = SP_ITEM(*x); Inkscape::XML::Node *original_repr = original_item->getRepr(); // remember the position of the item @@ -568,16 +569,14 @@ void Inkscape::SelTrans::stamp() } Inkscape::GC::release(copy_repr); - l = l->next; } DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, _("Stamp")); } - if ( fixup && _stamp_cache ) { + if ( fixup && !_stamp_cache.empty() ) { // TODO - give a proper fix. Simple temporary work-around for the grab() issue - g_slist_free(_stamp_cache); - _stamp_cache = NULL; + _stamp_cache.clear(); } } @@ -712,8 +711,9 @@ void Inkscape::SelTrans::handleClick(SPKnot */*knot*/, guint state, SPSelTransHa case HANDLE_CENTER: if (state & GDK_SHIFT_MASK) { // Unset the center position for all selected items - for (GSList const *l = _desktop->selection->itemList(); l; l = l->next) { - SPItem *it = SP_ITEM(l->data); + SelContainer items=_desktop->selection->itemList(); + for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + SPItem *it = SP_ITEM(*iter); it->unsetCenter(); it->updateRepr(); _center_is_set = false; // center has changed @@ -1283,7 +1283,7 @@ gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state) // items will share a single center. While dragging that single center, it should never snap to the // centers of any of the selected objects. Therefore we will have to pass the list of selected items // to the snapper, to avoid self-snapping of the rotation center - GSList *items = (GSList *) const_cast(_selection)->itemList(); + SelContainer items = const_cast(_selection)->itemList(); SnapManager &m = _desktop->namedview->snap_manager; m.setup(_desktop); m.setRotationCenterSource(items); diff --git a/src/seltrans.h b/src/seltrans.h index d5db1542d..8f9c329ed 100644 --- a/src/seltrans.h +++ b/src/seltrans.h @@ -187,7 +187,7 @@ private: SPCtrlLine *_l[4]; unsigned int _sel_changed_id; unsigned int _sel_modified_id; - GSList *_stamp_cache; + SelContainer _stamp_cache; Geom::Point _origin; ///< position of origin for transforms Geom::Point _point; ///< original position of the knot being used for the current transform diff --git a/src/snap.cpp b/src/snap.cpp index 8138e4546..a7145b834 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -43,7 +43,7 @@ SnapManager::SnapManager(SPNamedView const *v) : object(this, 0), snapprefs(), _named_view(v), - _rotation_center_source_items(NULL), + _rotation_center_source_items(SelContainer()), _guide_to_ignore(NULL), _desktop(NULL), _snapindicator(true), @@ -1013,7 +1013,7 @@ void SnapManager::setup(SPDesktop const *desktop, _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; _guide_to_ignore = guide_to_ignore; - _rotation_center_source_items = NULL; + _rotation_center_source_items.clear(); } void SnapManager::setup(SPDesktop const *desktop, @@ -1031,7 +1031,7 @@ void SnapManager::setup(SPDesktop const *desktop, _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; _guide_to_ignore = guide_to_ignore; - _rotation_center_source_items = NULL; + _rotation_center_source_items.clear(); } /// Setup, taking the list of items to ignore from the desktop's selection. @@ -1049,13 +1049,13 @@ void SnapManager::setupIgnoreSelection(SPDesktop const *desktop, _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; _guide_to_ignore = guide_to_ignore; - _rotation_center_source_items = NULL; + _rotation_center_source_items.clear(); _items_to_ignore.clear(); Inkscape::Selection *sel = _desktop->selection; - GSList const *items = sel->itemList(); - for (GSList *i = const_cast(items); i; i = i->next) { - _items_to_ignore.push_back(static_cast(i->data)); + SelContainer const items = sel->itemList(); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + _items_to_ignore.push_back(static_cast(*i)); } } diff --git a/src/snap.h b/src/snap.h index 20b2b246f..012eb072b 100644 --- a/src/snap.h +++ b/src/snap.h @@ -136,7 +136,7 @@ public: std::vector *unselected_nodes = NULL, SPGuide *guide_to_ignore = NULL); - void unSetup() {_rotation_center_source_items = NULL; + void unSetup() {_rotation_center_source_items.clear(); _guide_to_ignore = NULL; _desktop = NULL; _unselected_nodes = NULL;} @@ -145,8 +145,8 @@ public: // of this rotation center; this reference is used to make sure that we do not snap a rotation // center to itself // NOTE: Must be called after calling setup(), not before! - void setRotationCenterSource(GSList *items) {_rotation_center_source_items = items;} - GSList const *getRotationCenterSource() {return _rotation_center_source_items;} + void setRotationCenterSource(const SelContainer &items) {_rotation_center_source_items = items;} + SelContainer getRotationCenterSource() {return _rotation_center_source_items;} // freeSnapReturnByRef() is preferred over freeSnap(), because it only returns a // point if snapping has occurred (by overwriting p); otherwise p is untouched @@ -490,7 +490,7 @@ protected: private: std::vector _items_to_ignore; ///< Items that should not be snapped to, for example the items that are currently being dragged. Set using the setup() method - GSList *_rotation_center_source_items; // to avoid snapping a rotation center to itself + SelContainer _rotation_center_source_items; // to avoid snapping a rotation center to itself SPGuide *_guide_to_ignore; ///< A guide that should not be snapped to, e.g. the guide that is currently being dragged SPDesktop const *_desktop; bool _snapindicator; ///< When true, an indicator will be drawn at the position that was being snapped to diff --git a/src/sp-conn-end.cpp b/src/sp-conn-end.cpp index 3e5398ced..bd139277d 100644 --- a/src/sp-conn-end.cpp +++ b/src/sp-conn-end.cpp @@ -50,8 +50,9 @@ static bool try_get_intersect_point_with_item_recursive(Geom::PathVector& conn_p // consider all first-order children double child_pos = 0.0; - for (GSList const* i = sp_item_group_item_list(group); i != NULL; i = i->next) { - SPItem* child_item = SP_ITEM(i->data); + SelContainer g = sp_item_group_item_list(group); + for (SelContainer::const_iterator i = g.begin();i!=g.end();i++) { + SPItem* child_item = SP_ITEM(*i); try_get_intersect_point_with_item_recursive(conn_pv, child_item, item_transform * child_item->transform, child_pos); if (intersect_pos < child_pos) diff --git a/src/sp-defs.cpp b/src/sp-defs.cpp index 334570076..d52fa038a 100644 --- a/src/sp-defs.cpp +++ b/src/sp-defs.cpp @@ -46,11 +46,10 @@ void SPDefs::update(SPCtx *ctx, guint flags) { } flags &= SP_OBJECT_MODIFIED_CASCADE; - - GSList *l = g_slist_reverse(this->childList(true)); - while (l) { - SPObject *child = SP_OBJECT(l->data); - l = g_slist_remove(l, child); + SelContainer l(this->childList(true)); + l.reverse(); + for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *child = SP_OBJECT(*i); if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->updateDisplay(ctx, flags); } diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 9cb33a6f3..bf8f7a5a4 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -244,11 +244,10 @@ void SPFilter::update(SPCtx *ctx, guint flags) { childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } childflags &= SP_OBJECT_MODIFIED_CASCADE; - - GSList *l = g_slist_reverse(this->childList(true, SPObject::ActionUpdate)); - while (l) { - SPObject *child = SP_OBJECT (l->data); - l = g_slist_remove (l, child); + SelContainer l(this->childList(true, SPObject::ActionUpdate)); + l.reverse(); + for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *child = SP_OBJECT (*i); if( SP_IS_FILTER_PRIMITIVE( child ) ) { child->updateDisplay(ctx, childflags); } diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index b1ba37de2..e6531c6be 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -171,11 +171,10 @@ void SPGroup::update(SPCtx *ctx, unsigned int flags) { childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } childflags &= SP_OBJECT_MODIFIED_CASCADE; - - GSList *l = g_slist_reverse(this->childList(true, SPObject::ActionUpdate)); - while (l) { - SPObject *child = SP_OBJECT (l->data); - l = g_slist_remove (l, child); + SelContainer l=this->childList(true, SPObject::ActionUpdate); + l.reverse(); + for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *child = SP_OBJECT (*i); if (childflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { SPItem *item = dynamic_cast(child); @@ -211,20 +210,16 @@ void SPGroup::update(SPCtx *ctx, unsigned int flags) { void SPGroup::modified(guint flags) { // std::cout << "SPGroup::modified(): " << (getId()?getId():"null") << std::endl; SPLPEItem::modified(flags); - - SPObject *child; - if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } flags &= SP_OBJECT_MODIFIED_CASCADE; - GSList *l = g_slist_reverse(this->childList(true)); - - while (l) { - child = SP_OBJECT (l->data); - l = g_slist_remove (l, child); + SelContainer l=this->childList(true); + l.reverse(); + for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *child = SP_OBJECT (*i); if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->emitModified(flags); @@ -296,35 +291,28 @@ Geom::OptRect SPGroup::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox Geom::OptRect bbox; // TODO CPPIFY: replace this const_cast later - GSList *l = const_cast(this)->childList(false, SPObject::ActionBBox); - - while (l) { - SPObject *o = SP_OBJECT (l->data); - + SelContainer l=const_cast(this)->childList(false, SPObject::ActionBBox); + for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *o = SP_OBJECT (*i); SPItem *item = dynamic_cast(o); if (item && !item->isHidden()) { Geom::Affine const ct(item->transform * transform); bbox |= item->bounds(bboxtype, ct); } - - l = g_slist_remove (l, o); } return bbox; } void SPGroup::print(SPPrintContext *ctx) { - GSList *l = g_slist_reverse(this->childList(false)); - - while (l) { - SPObject *o = SP_OBJECT (l->data); - + SelContainer l=this->childList(false); + l.reverse(); + for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *o = SP_OBJECT (*i); SPItem *item = dynamic_cast(o); if (item) { item->invoke_print(ctx); } - - l = g_slist_remove (l, o); } } @@ -372,17 +360,15 @@ Inkscape::DrawingItem *SPGroup::show (Inkscape::Drawing &drawing, unsigned int k } void SPGroup::hide (unsigned int key) { - GSList *l = g_slist_reverse(this->childList(false, SPObject::ActionShow)); - - while (l) { - SPObject *o = SP_OBJECT (l->data); + SelContainer l=this->childList(false, SPObject::ActionShow); + l.reverse(); + for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *o = SP_OBJECT (*i); SPItem *item = dynamic_cast(o); if (item) { item->invoke_hide(key); } - - l = g_slist_remove (l, o); } // SPLPEItem::onHide(key); @@ -401,7 +387,7 @@ void SPGroup::snappoints(std::vector &p, Inkscape: void -sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) +sp_item_group_ungroup (SPGroup *group, SelContainer &children, bool do_done) { g_return_if_fail (group != NULL); @@ -560,8 +546,8 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) } Inkscape::GC::release(repr); - if (children && item) { - *children = g_slist_prepend(*children, item); + if (!children.empty() && item) { + children.push_front(dynamic_cast(item)); } items = g_slist_remove (items, items->data); @@ -576,19 +562,18 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) * some API for list aspect of SPGroup */ -GSList *sp_item_group_item_list(SPGroup * group) +SelContainer sp_item_group_item_list(SPGroup * group) { - g_return_val_if_fail(group != NULL, NULL); - - GSList *s = NULL; + SelContainer s; + g_return_val_if_fail(group != NULL, s); for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) { if ( dynamic_cast(o) ) { - s = g_slist_prepend(s, o); + s.push_front(o); } } - - return g_slist_reverse (s); + s.reverse(); + return s; } SPObject *sp_item_group_get_child_by_name(SPGroup *group, SPObject *ref, const gchar *name) @@ -809,9 +794,10 @@ gint SPGroup::getItemCount() const { void SPGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags) { Inkscape::DrawingItem *ac = NULL; - GSList *l = g_slist_reverse(this->childList(false, SPObject::ActionShow)); - while (l) { - SPObject *o = SP_OBJECT (l->data); + SelContainer l=this->childList(false, SPObject::ActionShow); + l.reverse(); + for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + SPObject *o = SP_OBJECT (*i); SPItem * child = dynamic_cast(o); if (child) { ac = child->invoke_show (drawing, key, flags); @@ -819,7 +805,6 @@ void SPGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem * ai->appendChild(ac); } } - l = g_slist_remove (l, o); } } @@ -828,10 +813,10 @@ void SPGroup::update_patheffect(bool write) { g_message("sp_group_update_patheffect: %p\n", lpeitem); #endif - GSList const *item_list = sp_item_group_item_list(this); + SelContainer const item_list = sp_item_group_item_list(this); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast(iter->data); + for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = static_cast(*iter); SPLPEItem *lpeItem = dynamic_cast(subitem); if (lpeItem) { @@ -856,10 +841,10 @@ void SPGroup::update_patheffect(bool write) { static void sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) { - GSList const *item_list = sp_item_group_item_list(group); + SelContainer const item_list = sp_item_group_item_list(group); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast(iter->data); + for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = static_cast(*iter); SPGroup *subGroup = dynamic_cast(subitem); if (subGroup) { diff --git a/src/sp-item-group.h b/src/sp-item-group.h index 15bb58f22..9a5ee0161 100644 --- a/src/sp-item-group.h +++ b/src/sp-item-group.h @@ -15,6 +15,7 @@ #include #include "sp-lpe-item.h" +#include "selection.h"//SelContainer #define SP_GROUP(obj) (dynamic_cast((SPObject*)obj)) #define SP_IS_GROUP(obj) (dynamic_cast((SPObject*)obj) != NULL) @@ -95,10 +96,10 @@ public: virtual void update_patheffect(bool write); }; -void sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done = true); +void sp_item_group_ungroup (SPGroup *group, SelContainer &children, bool do_done = true); -GSList *sp_item_group_item_list (SPGroup *group); +SelContainer sp_item_group_item_list (SPGroup *group); SPObject *sp_item_group_get_child_by_name (SPGroup *group, SPObject *ref, const char *name); #endif diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index f059ab531..1305efd83 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -353,9 +353,9 @@ sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem) sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild())); } if (SP_IS_GROUP(lpeitem)) { - GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast(iter->data); + SelContainer item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); + for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = static_cast(*iter); if (SP_IS_LPE_ITEM(subitem)) { sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(subitem)); } @@ -387,9 +387,9 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem) sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild())); } } - GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast(iter->data); + SelContainer item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); + for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = static_cast(*iter); if (SP_IS_LPE_ITEM(subitem)) { sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(subitem)); } @@ -680,9 +680,9 @@ SPLPEItem::apply_to_clippath(SPItem *item) } } if(SP_IS_GROUP(item)){ - GSList const *item_list = sp_item_group_item_list(SP_GROUP(item)); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast(iter->data); + SelContainer item_list = sp_item_group_item_list(SP_GROUP(item)); + for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = static_cast(*iter); apply_to_clippath(SP_ITEM(subitem)); } } @@ -732,9 +732,9 @@ SPLPEItem::apply_to_mask(SPItem *item) } } if(SP_IS_GROUP(item)){ - GSList const *item_list = sp_item_group_item_list(SP_GROUP(item)); - for ( GSList const *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast(iter->data); + SelContainer item_list = sp_item_group_item_list(SP_GROUP(item)); + for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = static_cast(*iter); apply_to_mask(SP_ITEM(subitem)); } } @@ -746,9 +746,9 @@ SPLPEItem::apply_to_clip_or_mask_group(SPItem *group, SPItem *item) if (!SP_IS_GROUP(group)) { return; } - GSList *item_list = sp_item_group_item_list(SP_GROUP(group)); - for ( GSList *iter = item_list; iter; iter = iter->next ) { - SPObject *subitem = static_cast(iter->data); + SelContainer item_list = sp_item_group_item_list(SP_GROUP(group)); + for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *subitem = static_cast(*iter); if (SP_IS_GROUP(subitem)) { apply_to_clip_or_mask_group(SP_ITEM(subitem), item); } else if (SP_IS_SHAPE(subitem)) { diff --git a/src/sp-marker.cpp b/src/sp-marker.cpp index 371a6c35c..66b445265 100644 --- a/src/sp-marker.cpp +++ b/src/sp-marker.cpp @@ -429,7 +429,7 @@ sp_marker_hide (SPMarker *marker, unsigned int key) } -const gchar *generate_marker(GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move) +const gchar *generate_marker(SelContainer &reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move) { Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -452,8 +452,8 @@ const gchar *generate_marker(GSList *reprs, Geom::Rect bounds, SPDocument *docum const gchar *mark_id = repr->attribute("id"); SPObject *mark_object = document->getObjectById(mark_id); - for (GSList *i = reprs; i != NULL; i = i->next) { - Inkscape::XML::Node *node = (Inkscape::XML::Node *)(i->data); + for (SelContainer::const_iterator i=reprs.begin();i!=reprs.end();i++){ + Inkscape::XML::Node *node = (Inkscape::XML::Node *)(*i); SPItem *copy = SP_ITEM(mark_object->appendChildRepr(node)); Geom::Affine dup_transform; diff --git a/src/sp-marker.h b/src/sp-marker.h index e804fd7dc..594c164c5 100644 --- a/src/sp-marker.h +++ b/src/sp-marker.h @@ -101,7 +101,7 @@ Inkscape::DrawingItem *sp_marker_show_instance (SPMarker *marker, Inkscape::Draw unsigned int key, unsigned int pos, Geom::Affine const &base, float linewidth); void sp_marker_hide (SPMarker *marker, unsigned int key); -const char *generate_marker (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move); +const char *generate_marker (SelContainer &reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move); SPObject *sp_marker_fork_if_necessary(SPObject *marker); #endif diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 7d24a978e..3ea480f66 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -382,14 +382,14 @@ void SPObject::changeCSS(SPCSSAttr *css, gchar const *attr) sp_repr_css_change(this->getRepr(), css, attr); } -GSList *SPObject::childList(bool add_ref, Action) { - GSList *l = NULL; +SelContainer SPObject::childList(bool add_ref, Action) { + SelContainer l; for ( SPObject *child = firstChild() ; child; child = child->getNext() ) { if (add_ref) { sp_object_ref (child); } - l = g_slist_prepend (l, child); + l.push_front(child); } return l; diff --git a/src/sp-object.h b/src/sp-object.h index ff80eaefc..858587611 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -47,11 +47,14 @@ class SPObject; #define SP_OBJECT_WRITE_ALL (1 << 2) #define SP_OBJECT_WRITE_NO_CHILDREN (1 << 3) + + #include #include #include #include #include +#include #include "version.h" #include "util/forward-pointer-iterator.h" @@ -60,6 +63,11 @@ class SPCSSAttr; class SPStyle; typedef struct _GSList GSList; +//should be in selection.h +typedef std::list SelContainer; + + + namespace Inkscape { namespace XML { class Node; @@ -330,7 +338,7 @@ public: * Retrieves the children as a GSList object, optionally ref'ing the children * in the process, if add_ref is specified. */ - GSList *childList(bool add_ref, Action action = ActionGeneral); + SelContainer childList(bool add_ref, Action action = ActionGeneral); /** * Append repr as child of this object. diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index 961ab0f84..d5eff9796 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -408,7 +408,7 @@ sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool se g_free(c); } -const gchar *pattern_tile(GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) +const gchar *pattern_tile(const SelContainer &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) { Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -426,8 +426,8 @@ const gchar *pattern_tile(GSList *reprs, Geom::Rect bounds, SPDocument *document const gchar *pat_id = repr->attribute("id"); SPObject *pat_object = document->getObjectById(pat_id); - for (GSList *i = reprs; i != NULL; i = i->next) { - Inkscape::XML::Node *node = (Inkscape::XML::Node *)(i->data); + for (SelContainer::const_iterator i=reprs.begin();i!=reprs.end();i++){ + Inkscape::XML::Node *node = (Inkscape::XML::Node *)(*i); SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node)); Geom::Affine dup_transform; diff --git a/src/sp-pattern.h b/src/sp-pattern.h index f021101e2..0e2b058b5 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -89,7 +89,7 @@ SPPattern *pattern_chain (SPPattern *pattern); SPPattern *sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const char *property); void sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set); -const char *pattern_tile (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); +const char *pattern_tile (const SelContainer &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); SPPattern *pattern_getroot (SPPattern *pat); diff --git a/src/sp-switch.cpp b/src/sp-switch.cpp index db6db9909..0090f1855 100644 --- a/src/sp-switch.cpp +++ b/src/sp-switch.cpp @@ -55,21 +55,22 @@ SPObject *SPSwitch::_evaluateFirst() { return first; } -GSList *SPSwitch::_childList(bool add_ref, SPObject::Action action) { +SelContainer SPSwitch::_childList(bool add_ref, SPObject::Action action) { if ( action != SPObject::ActionGeneral ) { return this->childList(add_ref, action); } SPObject *child = _evaluateFirst(); + SelContainer x; if (NULL == child) - return NULL; + return x; if (add_ref) { //g_object_ref (G_OBJECT (child)); sp_object_ref(child); } - - return g_slist_prepend (NULL, child); + x.push_front(child); + return x; } const char *SPSwitch::displayName() const { @@ -109,10 +110,9 @@ void SPSwitch::_reevaluate(bool /*add_to_drawing*/) { _releaseLastItem(_cached_item); - for ( GSList *l = _childList(false, SPObject::ActionShow); - NULL != l ; l = g_slist_remove (l, l->data)) - { - SPObject *o = SP_OBJECT (l->data); + SelContainer item_list = _childList(false, SPObject::ActionShow); + for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPObject *o = SP_OBJECT (*iter); if ( !SP_IS_ITEM (o) ) { continue; } @@ -144,10 +144,10 @@ void SPSwitch::_releaseLastItem(SPObject *obj) void SPSwitch::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags) { SPObject *evaluated_child = this->_evaluateFirst(); - GSList *l = this->_childList(false, SPObject::ActionShow); + SelContainer l = this->_childList(false, SPObject::ActionShow); - while (l) { - SPObject *o = SP_OBJECT (l->data); + for ( SelContainer::const_iterator iter=l.begin();iter!=l.end();iter++) { + SPObject *o = SP_OBJECT (*iter); if (SP_IS_ITEM (o)) { SPItem * child = SP_ITEM(o); @@ -158,8 +158,6 @@ void SPSwitch::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem ai->appendChild(ac); } } - - l = g_slist_remove (l, o); } } diff --git a/src/sp-switch.h b/src/sp-switch.h index 4fce1f5a6..6a83072e7 100644 --- a/src/sp-switch.h +++ b/src/sp-switch.h @@ -29,7 +29,7 @@ public: void resetChildEvaluated() { _reevaluate(); } - GSList *_childList(bool add_ref, SPObject::Action action); + SelContainer _childList(bool add_ref, SPObject::Action action); virtual void _showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags); SPObject *_evaluateFirst(); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 8bb3e9897..aec7051e0 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -60,6 +60,11 @@ using Inkscape::DocumentUndo; bool Ancetre(Inkscape::XML::Node *a, Inkscape::XML::Node *who); +//SHOULD DISAPPEAR +bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b){ + return sp_repr_compare_position(dynamic_cast(a),dynamic_cast(b)); +} + void sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb=SP_VERB_NONE, const Glib::ustring description=""); void sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset); void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updating); @@ -326,21 +331,21 @@ void sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb, const Glib::ustring description) { SPDocument *doc = selection->layers()->getDocument(); - GSList *il = (GSList *) selection->itemList(); + SelContainer il= selection->itemList(); // allow union on a single object for the purpose of removing self overlapse (svn log, revision 13334) - if ( (g_slist_length(il) < 2) && (bop != bool_op_union)) { + if ( (il.size() < 2) && (bop != bool_op_union)) { boolop_display_error_message(desktop, _("Select at least 2 paths to perform a boolean operation.")); return; } - else if ( g_slist_length(il) < 1 ) { + else if ( il.size() < 1 ) { boolop_display_error_message(desktop, _("Select at least 1 path to perform a boolean union.")); return; } - g_assert(il != NULL); + g_assert(!il.empty()); - if (g_slist_length(il) > 2) { + if (il.size() > 2) { if (bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice ) { boolop_display_error_message(desktop, _("Select exactly 2 paths to perform difference, division, or path cut.")); return; @@ -354,8 +359,8 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool if (bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice) { // check in the tree to find which element of the selection list is topmost (for 2-operand commands only) - Inkscape::XML::Node *a = SP_OBJECT(il->data)->getRepr(); - Inkscape::XML::Node *b = SP_OBJECT(il->next->data)->getRepr(); + Inkscape::XML::Node *a = SP_OBJECT(il.front())->getRepr(); + Inkscape::XML::Node *b = SP_OBJECT(il.back())->getRepr(); if (a == NULL || b == NULL) { boolop_display_error_message(desktop, _("Unable to determine the z-order of the objects selected for difference, XOR, division, or path cut.")); @@ -394,38 +399,36 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool } } - il = g_slist_copy(il); - g_assert(il != NULL); + g_assert(!il.empty()); // first check if all the input objects have shapes // otherwise bail out - for (GSList *l = il; l != NULL; l = l->next) + for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++) { - SPItem *item = SP_ITEM(l->data); + SPItem *item = SP_ITEM(*l); if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item) && !SP_IS_FLOWTEXT(item)) { boolop_display_error_message(desktop, _("One of the objects is not a path, cannot perform boolean operation.")); - g_slist_free(il); return; } } // extract the livarot Paths from the source objects // also get the winding rule specified in the style - int nbOriginaux = g_slist_length(il); + int nbOriginaux = il.size(); std::vector originaux(nbOriginaux); std::vector origWind(nbOriginaux); int curOrig; { curOrig = 0; - for (GSList *l = il; l != NULL; l = l->next) + for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++) { // apply live path effects prior to performing boolean operation - if (SP_IS_LPE_ITEM(l->data)) { - SP_LPE_ITEM(l->data)->removeAllPathEffects(true); + if (SP_IS_LPE_ITEM(*l)) { + SP_LPE_ITEM(*l)->removeAllPathEffects(true); } - SPCSSAttr *css = sp_repr_css_attr(reinterpret_cast(il->data)->getRepr(), "style"); + SPCSSAttr *css = sp_repr_css_attr(reinterpret_cast(il.front())->getRepr(), "style"); gchar const *val = sp_repr_css_property(css, "fill-rule", NULL); if (val && strcmp(val, "nonzero") == 0) { origWind[curOrig]= fill_nonZero; @@ -435,11 +438,10 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool origWind[curOrig]= fill_nonZero; } - originaux[curOrig] = Path_for_item((SPItem *) l->data, true, true); + originaux[curOrig] = Path_for_item((SPItem *) (*l), true, true); if (originaux[curOrig] == NULL || originaux[curOrig]->descr_cmd.size() <= 1) { for (int i = curOrig; i >= 0; i--) delete originaux[i]; - g_slist_free(il); return; } curOrig++; @@ -472,7 +474,8 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool theShapeA->ConvertToShape(theShape, origWind[0]); curOrig = 1; - for (GSList *l = il->next; l != NULL; l = l->next) { + for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){ + if(*l==il.front())continue; originaux[curOrig]->ConvertWithBackData(0.1); originaux[curOrig]->Fill(theShape, curOrig); @@ -668,15 +671,13 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool if (res->descr_cmd.size() <= 1) { // only one command, presumably a moveto: it isn't a path - for (GSList *l = il; l != NULL; l = l->next) - { - SP_OBJECT(l->data)->deleteObject(); + for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){ + SP_OBJECT(*l)->deleteObject(); } DocumentUndo::done(doc, SP_VERB_NONE, description); selection->clear(); delete res; - g_slist_free(il); return; } @@ -684,19 +685,17 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool SPObject *source; if ( bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice ) { if (reverseOrderForOp) { - source = SP_OBJECT(il->data); + source = SP_OBJECT(il.front()); } else { - source = SP_OBJECT(il->next->data); + source = SP_OBJECT(il.back()); } } else { // find out the bottom object - GSList *sorted = g_slist_copy((GSList *) selection->reprList()); - - sorted = g_slist_sort(sorted, (GCompareFunc) sp_repr_compare_position); + SelContainer sorted(selection->reprList()); - source = doc->getObjectByRepr((Inkscape::XML::Node *)sorted->data); + sorted.sort(sp_repr_compare_position_obj); - g_slist_free(sorted); + source = doc->getObjectByRepr((Inkscape::XML::Node *)sorted.front()); } // adjust style properties that depend on a possible transform in the source object in order @@ -721,17 +720,16 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool gchar *desc = source->desc(); // remove source paths selection->clear(); - for (GSList *l = il; l != NULL; l = l->next) { + for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){ // if this is the bottommost object, - if (!strcmp(reinterpret_cast(l->data)->getRepr()->attribute("id"), id)) { + if (!strcmp(reinterpret_cast(*l)->getRepr()->attribute("id"), id)) { // delete it so that its clones don't get alerted; this object will be restored shortly, with the same id - SP_OBJECT(l->data)->deleteObject(false); + SP_OBJECT(*l)->deleteObject(false); } else { // delete the object for real, so that its clones can take appropriate action - SP_OBJECT(l->data)->deleteObject(); + SP_OBJECT(*l)->deleteObject(); } } - g_slist_free(il); // premultiply by the inverse of parent's repr SPItem *parent_item = SP_ITEM(doc->getObjectByRepr(parent)); @@ -1159,12 +1157,9 @@ sp_selected_path_outline(SPDesktop *desktop) } bool did = false; - - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { - - SPItem *item = SP_ITEM(items->data); + SelContainer il(selection->itemList()); + for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){ + SPItem *item = SP_ITEM(*l); if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item)) continue; @@ -1774,12 +1769,9 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) } bool did = false; - - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { - - SPItem *item = SP_ITEM(items->data); + SelContainer il(selection->itemList()); + for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){ + SPItem *item = SP_ITEM(*l); SPCurve *curve = NULL; if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item)) @@ -1975,7 +1967,7 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) static bool sp_selected_path_simplify_items(SPDesktop *desktop, - Inkscape::Selection *selection, GSList *items, + Inkscape::Selection *selection, SelContainer &items, float threshold, bool justCoalesce, float angleLimit, bool breakableAngles, bool modifySelection); @@ -1994,7 +1986,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop, //If this is a group, do the children instead if (SP_IS_GROUP(item)) { - GSList *items = sp_item_group_item_list(SP_GROUP(item)); + SelContainer items = sp_item_group_item_list(SP_GROUP(item)); return sp_selected_path_simplify_items(desktop, selection, items, threshold, justCoalesce, @@ -2119,7 +2111,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop, bool sp_selected_path_simplify_items(SPDesktop *desktop, - Inkscape::Selection *selection, GSList *items, + Inkscape::Selection *selection, SelContainer &items, float threshold, bool justCoalesce, float angleLimit, bool breakableAngles, bool modifySelection) @@ -2145,13 +2137,13 @@ sp_selected_path_simplify_items(SPDesktop *desktop, gdouble simplifySize = selectionSize; int pathsSimplified = 0; - int totalPathCount = g_slist_length(items); + int totalPathCount = items.size(); // set "busy" cursor desktop->setWaitingCursor(); - for (; items != NULL; items = items->next) { - SPItem *item = (SPItem *) items->data; + for (SelContainer::const_iterator l = items.begin(); l != items.end(); l++){ + SPItem *item = SP_ITEM(*l); if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item))) continue; @@ -2199,7 +2191,7 @@ sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool ju return; } - GSList *items = g_slist_copy((GSList *) selection->itemList()); + SelContainer items(selection->itemList()); bool didSomething = sp_selected_path_simplify_items(desktop, selection, items, threshold, diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index 65b59f2ad..391e255a5 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -43,11 +43,10 @@ using Inkscape::DocumentUndo; static SPItem * flowtext_in_selection(Inkscape::Selection *selection) { - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_FLOWTEXT(items->data)) - return ((SPItem *) items->data); + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_FLOWTEXT(*i)) + return ((SPItem *) *i); } return NULL; } @@ -55,11 +54,10 @@ flowtext_in_selection(Inkscape::Selection *selection) static SPItem * text_or_flowtext_in_selection(Inkscape::Selection *selection) { - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_TEXT(items->data) || SP_IS_FLOWTEXT(items->data)) - return ((SPItem *) items->data); + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) + return ((SPItem *) *i); } return NULL; } @@ -67,11 +65,10 @@ text_or_flowtext_in_selection(Inkscape::Selection *selection) static SPItem * shape_in_selection(Inkscape::Selection *selection) { - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_SHAPE(items->data)) - return ((SPItem *) items->data); + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_SHAPE(*i)) + return ((SPItem *) *i); } return NULL; } @@ -90,7 +87,7 @@ text_put_on_path() Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - if (!text || !shape || g_slist_length((GSList *) selection->itemList()) != 2) { + if (!text || !shape || selection->itemList().size() != 2) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a text and a path to put text on path.")); return; } @@ -199,11 +196,9 @@ text_remove_from_path() } bool did = false; - - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { - SPObject *obj = SP_OBJECT(items->data); + SelContainer items(selection->itemList()); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *obj = SP_OBJECT(*i); if (SP_IS_TEXT_TEXTPATH(obj)) { SPObject *tp = obj->firstChild(); @@ -219,7 +214,7 @@ text_remove_from_path() } else { DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Remove text from path")); - selection->setList(g_slist_copy((GSList *) selection->itemList())); // reselect to update statusbar description + selection->setList(selection->itemList()); // reselect to update statusbar description } } @@ -265,10 +260,9 @@ text_remove_all_kerns() bool did = false; - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { - SPObject *obj = SP_OBJECT(items->data); + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *obj = SP_OBJECT(*i); if (!SP_IS_TEXT(obj) && !SP_IS_TSPAN(obj) && !SP_IS_FLOWTEXT(obj)) { continue; @@ -302,7 +296,7 @@ text_flow_into_shape() SPItem *text = text_or_flowtext_in_selection(selection); SPItem *shape = shape_in_selection(selection); - if (!text || !shape || g_slist_length((GSList *) selection->itemList()) < 2) { + if (!text || !shape || selection->itemList().size() < 2) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a text and one or more paths or shapes to flow text into frame.")); return; } @@ -326,10 +320,9 @@ text_flow_into_shape() g_return_if_fail(SP_IS_FLOWREGION(object)); /* Add clones */ - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - SPItem *item = SP_ITEM(items->data); + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_SHAPE(item)){ Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); clone->setAttribute("x", "0"); @@ -394,23 +387,22 @@ text_unflow () Inkscape::Selection *selection = desktop->getSelection(); - if (!flowtext_in_selection(selection) || g_slist_length((GSList *) selection->itemList()) < 1) { + if (!flowtext_in_selection(selection) || selection->itemList().size() < 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a flowed text to unflow it.")); return; } - GSList *new_objs = NULL; + SelContainer new_objs; GSList *old_objs = NULL; - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ - if (!SP_IS_FLOWTEXT(SP_OBJECT(items->data))) { + if (!SP_IS_FLOWTEXT(SP_OBJECT(*i))) { continue; } - SPItem *flowtext = SP_ITEM(items->data); + SPItem *flowtext = SP_ITEM(*i); // we discard transform when unflowing, but we must preserve expansion which is visible as // font size multiplier @@ -451,7 +443,7 @@ text_unflow () SPText *text = SP_TEXT(text_object); text->_adjustFontsizeRecursive(text, ex); - new_objs = g_slist_prepend (new_objs, text_object); + new_objs.push_front(text_object); old_objs = g_slist_prepend (old_objs, flowtext); Inkscape::GC::release(rtext); @@ -466,7 +458,6 @@ text_unflow () } g_slist_free (old_objs); - g_slist_free (new_objs); DocumentUndo::done(doc, SP_VERB_CONTEXT_TEXT, _("Unflow flowed text")); @@ -487,11 +478,11 @@ flowtext_to_text() bool did = false; - GSList *reprs = NULL; - GSList *items = g_slist_copy((GSList *) selection->itemList()); - for (; items != NULL; items = items->next) { + SelContainer reprs; + SelContainer items(selection->itemList()); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = (SPItem *) items->data; + SPItem *item = (SPItem *) *i; if (!SP_IS_FLOWTEXT(item)) continue; @@ -519,10 +510,9 @@ flowtext_to_text() Inkscape::GC::release(repr); item->deleteObject(); - reprs = g_slist_prepend(reprs, repr); + reprs.push_front(dynamic_cast(repr)); } - g_slist_free(items); if (did) { DocumentUndo::done(desktop->getDocument(), @@ -535,7 +525,6 @@ flowtext_to_text() _("No flowed text(s) to convert in the selection.")); } - g_slist_free(reprs); } diff --git a/src/text-editing.cpp b/src/text-editing.cpp index 4a962ab4c..44d90b4ae 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -67,12 +67,11 @@ static void te_update_layout_now (SPItem *item) void te_update_layout_now_recursive(SPItem *item) { if (SP_IS_GROUP(item)) { - GSList *item_list = sp_item_group_item_list(SP_GROUP(item)); - for(GSList* elem = item_list; elem; elem = elem->next) { - SPItem* list_item = static_cast(elem->data); + SelContainer item_list = sp_item_group_item_list(SP_GROUP(item)); + for(SelContainer::const_iterator i=item_list.begin();i!=item_list.end();i++){ + SPItem* list_item = static_cast(*i); te_update_layout_now_recursive(list_item); } - g_slist_free(item_list); } else if (SP_IS_TEXT(item)) SP_TEXT(item)->rebuildLayout(); else if (SP_IS_FLOWTEXT (item)) diff --git a/src/trace/trace.cpp b/src/trace/trace.cpp index cc3d000a3..892ecdb87 100644 --- a/src/trace/trace.cpp +++ b/src/trace/trace.cpp @@ -65,7 +65,7 @@ SPImage *Tracer::getSelectedSPImage() if (sioxEnabled) { SPImage *img = NULL; - GSList const *list = sel->itemList(); + SelContainer const list = sel->itemList(); std::vector items; sioxShapes.clear(); @@ -74,13 +74,13 @@ SPImage *Tracer::getSelectedSPImage() them as bottom-to-top so that we can discover the image and any SPItems above it */ - for ( ; list ; list=list->next) + for(SelContainer::const_iterator x=list.begin();x!=list.end();x++){ { - if (!SP_IS_ITEM(list->data)) + if (!SP_IS_ITEM(*x)) { continue; } - SPItem *item = SP_ITEM(list->data); + SPItem *item = SP_ITEM(*x); items.insert(items.begin(), item); } std::vector::iterator iter; diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 94a1eb2dc..20b43af3b 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -523,8 +523,9 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a // resize each object in the selection if (separately) { - for (GSList *i = const_cast(selection->itemList()) ; i ; i = i->next) { - SPItem *item = dynamic_cast(static_cast(i->data)); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (item) { Geom::OptRect obj_size = item->desktopVisualBounds(); if ( obj_size ) { @@ -578,8 +579,9 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) desktop->doc()->importDefs(tempdoc); // make sure all selected items are converted to paths first (i.e. rectangles) sp_selected_to_lpeitems(desktop); - for (GSList *itemptr = const_cast(selection->itemList()) ; itemptr ; itemptr = itemptr->next) { - SPItem *item = reinterpret_cast(itemptr->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); _applyPathEffect(item, effectstack); } @@ -659,10 +661,10 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) */ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) { - GSList const *items = selection->itemList(); // copy the defs used by all items - for (GSList *i = const_cast(items) ; i != NULL ; i = i->next) { - SPItem *item = dynamic_cast(static_cast(i->data)); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (item) { _copyUsedDefs(item); } else { @@ -671,11 +673,11 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) } // copy the representation of the items - GSList *sorted_items = g_slist_copy(const_cast(items)); - sorted_items = g_slist_sort(sorted_items, (GCompareFunc) sp_object_compare_position); + SelContainer sorted_items(itemlist); + sorted_items.sort(sp_object_compare_position); - for (GSList *i = sorted_items ; i ; i = i->next) { - SPItem *item = dynamic_cast(static_cast(i->data)); + for(SelContainer::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ + SPItem *item = SP_ITEM(*i); if (item) { Inkscape::XML::Node *obj = item->getRepr(); Inkscape::XML::Node *obj_copy = _copyNode(obj, _doc, _root); @@ -695,8 +697,8 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) } // copy style for Paste Style action - if (sorted_items) { - SPObject *object = static_cast(sorted_items->data); + if (!sorted_items.empty()) { + SPObject *object = static_cast(sorted_items.front()); SPItem *item = dynamic_cast(object); if (item) { SPCSSAttr *style = take_style_from_item(item); @@ -719,7 +721,6 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) sp_repr_set_point(_clipnode, "max", size->max()); } - g_slist_free(sorted_items); } @@ -1156,8 +1157,8 @@ void ClipboardManagerImpl::_onGet(Gtk::SelectionData &sel, guint /*info*/) sp_repr_get_double(nv, "inkscape:pageopacity", &opacity); bgcolor |= SP_COLOR_F_TO_U(opacity); } - - sp_export_png_file(_clipboardSPDoc, filename, area, width, height, dpi, dpi, bgcolor, NULL, NULL, true, NULL); + SelContainer x; + sp_export_png_file(_clipboardSPDoc, filename, area, width, height, dpi, dpi, bgcolor, NULL, NULL, true, x); } else { diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 65bc94011..562bc28b7 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -98,8 +98,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) bool sel_as_group = prefs->getBool("/dialogs/align/sel-as-groups"); using Inkscape::Util::GSListConstIterator; - std::list selected; - selected.insert >(selected.end(), selection->itemList(), NULL); + SelContainer selected(selection->itemList()); if (selected.empty()) return; const Coeffs &a = _allCoeffs[index]; @@ -149,18 +148,19 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) b = selection->preferredBounds(); //Move each item in the selected list separately - for (std::list::iterator it(selected.begin()); + for (SelContainer::iterator it(selected.begin()); it != selected.end(); ++it) { + SPItem* item=static_cast (*it); desktop->getDocument()->ensureUpToDate(); if (!sel_as_group) - b = (*it)->desktopPreferredBounds(); - if (b && (!focus || (*it) != focus)) { + b = (item)->desktopPreferredBounds(); + if (b && (!focus || (item) != focus)) { Geom::Point const sp(a.sx0 * b->min()[Geom::X] + a.sx1 * b->max()[Geom::X], a.sy0 * b->min()[Geom::Y] + a.sy1 * b->max()[Geom::Y]); Geom::Point const mp_rel( mp - sp ); if (LInfty(mp_rel) > 1e-9) { - sp_item_move_rel(*it, Geom::Translate(mp_rel)); + sp_item_move_rel(item, Geom::Translate(mp_rel)); changed = true; } } @@ -251,25 +251,24 @@ private : if (!selection) return; using Inkscape::Util::GSListConstIterator; - std::list selected; - selected.insert >(selected.end(), selection->itemList(), NULL); + SelContainer selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects - std::list::iterator second(selected.begin()); + SelContainer::iterator second(selected.begin()); ++second; if (second == selected.end()) return; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int prefs_bbox = prefs->getBool("/tools/bounding_box"); std::vector< BBoxSort > sorted; - for (std::list::iterator it(selected.begin()); + for (SelContainer::iterator it(selected.begin()); it != selected.end(); ++it) - { - Geom::OptRect bbox = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds(); + {SPItem *item=static_cast(*it); + Geom::OptRect bbox = !prefs_bbox ? (item)->desktopVisualBounds() : (item)->desktopGeometricBounds(); if (bbox) { - sorted.push_back(BBoxSort(*it, *bbox, _orientation, _kBegin, _kEnd)); + sorted.push_back(BBoxSort(item, *bbox, _orientation, _kBegin, _kEnd)); } } //sort bbox by anchors @@ -541,6 +540,10 @@ private : return (a->isSiblingOf(b)); } + static bool local_obj_compare(SPObject* a,SPObject* b){ + return ActionExchangePositions::sort_compare(static_cast(a),static_cast(b)); + } + virtual void on_button_click() { SPDesktop *desktop = _dialog.getDesktop(); @@ -550,8 +553,7 @@ private : if (!selection) return; using Inkscape::Util::GSListConstIterator; - std::list selected; - selected.insert >(selected.end(), selection->itemList(), NULL); + SelContainer selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects @@ -569,20 +571,22 @@ private : } else { // sorting by ZOrder is outomatically done by not setting the center center.reset(); } - selected.sort(ActionExchangePositions::sort_compare); + selected.sort(local_obj_compare); } - std::list::iterator it(selected.begin()); - Geom::Point p1 = (*it)->getCenter(); + SelContainer::iterator it(selected.begin()); + SPItem* item=static_cast(*it); + Geom::Point p1 = (item)->getCenter(); for (++it ;it != selected.end(); ++it) { - Geom::Point p2 = (*it)->getCenter(); + item=static_cast(*it); + Geom::Point p2 = (item)->getCenter(); Geom::Point delta = p1 - p2; - sp_item_move_rel((*it),Geom::Translate(delta[Geom::X],delta[Geom::Y] )); + sp_item_move_rel((item),Geom::Translate(delta[Geom::X],delta[Geom::Y] )); p1 = p2; } - Geom::Point p2 = selected.front()->getCenter(); + Geom::Point p2 = static_cast(selected.front())->getCenter(); Geom::Point delta = p1 - p2; - sp_item_move_rel(selected.front(),Geom::Translate(delta[Geom::X],delta[Geom::Y] )); + sp_item_move_rel(static_cast(selected.front()),Geom::Translate(delta[Geom::X],delta[Geom::Y] )); // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); @@ -615,8 +619,8 @@ private : Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - - unclump ((GSList *) _dialog.getDesktop()->getSelection()->itemList()); + SelContainer x(_dialog.getDesktop()->getSelection()->itemList()); + unclump (x); // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); @@ -647,8 +651,7 @@ private : if (!selection) return; using Inkscape::Util::GSListConstIterator; - std::list selected; - selected.insert >(selected.end(), selection->itemList(), NULL); + SelContainer selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects @@ -672,12 +675,13 @@ private : int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - for (std::list::iterator it(selected.begin()); + for (SelContainer::iterator it(selected.begin()); it != selected.end(); ++it) { + SPItem* item=static_cast(*it); desktop->getDocument()->ensureUpToDate(); - Geom::OptRect item_box = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds(); + Geom::OptRect item_box = !prefs_bbox ? (item)->desktopVisualBounds() : (item)->desktopGeometricBounds(); if (item_box) { // find new center, staying within bbox double x = _dialog.randomize_bbox->min()[Geom::X] + (*item_box)[Geom::X].extent() /2 + @@ -686,7 +690,7 @@ private : g_random_double_range (0, (*_dialog.randomize_bbox)[Geom::Y].extent() - (*item_box)[Geom::Y].extent()); // displacement is the new center minus old: Geom::Point t = Geom::Point (x, y) - 0.5*(item_box->max() + item_box->min()); - sp_item_move_rel(*it, Geom::Translate(t)); + sp_item_move_rel(item, Geom::Translate(t)); } } @@ -746,8 +750,7 @@ private : if (!selection) return; using Inkscape::Util::GSListConstIterator; - std::list selected; - selected.insert >(selected.end(), selection->itemList(), NULL); + SelContainer selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects @@ -758,20 +761,21 @@ private : std::vector sorted; - for (std::list::iterator it(selected.begin()); + for (SelContainer::iterator it(selected.begin()); it != selected.end(); ++it) { - if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) { - Inkscape::Text::Layout const *layout = te_get_layout(*it); + SPItem* item=static_cast(*it); + if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT (item)) { + Inkscape::Text::Layout const *layout = te_get_layout(item); boost::optional pt = layout->baselineAnchorPoint(); if (pt) { - Geom::Point base = *pt * (*it)->i2dt_affine(); + Geom::Point base = *pt * (item)->i2dt_affine(); if (base[Geom::X] < b_min[Geom::X]) b_min[Geom::X] = base[Geom::X]; if (base[Geom::Y] < b_min[Geom::Y]) b_min[Geom::Y] = base[Geom::Y]; if (base[Geom::X] > b_max[Geom::X]) b_max[Geom::X] = base[Geom::X]; if (base[Geom::Y] > b_max[Geom::Y]) b_max[Geom::Y] = base[Geom::Y]; - Baselines b (*it, base, _orientation); + Baselines b (item, base, _orientation); sorted.push_back(b); } } @@ -801,18 +805,19 @@ private : } } else { - for (std::list::iterator it(selected.begin()); + for (SelContainer::iterator it(selected.begin()); it != selected.end(); ++it) { - if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) { - Inkscape::Text::Layout const *layout = te_get_layout(*it); + SPItem* item=static_cast(*it); + if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT (item)) { + Inkscape::Text::Layout const *layout = te_get_layout(item); boost::optional pt = layout->baselineAnchorPoint(); if (pt) { - Geom::Point base = *pt * (*it)->i2dt_affine(); + Geom::Point base = *pt * (item)->i2dt_affine(); Geom::Point t(0.0, 0.0); t[_orientation] = b_min[_orientation] - base[_orientation]; - sp_item_move_rel(*it, Geom::Translate(t)); + sp_item_move_rel(item, Geom::Translate(t)); changed = true; } } diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index fede30b26..abfab8b19 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -1359,7 +1359,7 @@ void CloneTiler::clonetiler_change_selection(Inkscape::Selection *selection, Gtk return; } - if (g_slist_length ((GSList *) selection->itemList()) > 1) { + if (selection->itemList().size() > 1) { gtk_widget_set_sensitive (buttons, FALSE); gtk_label_set_markup (GTK_LABEL(status), _("More than one object selected.")); return; @@ -2096,7 +2096,7 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *) Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected - if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) { + if (selection->isEmpty() || selection->itemList().size() > 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select one object whose tiled clones to unclump.")); return; } @@ -2104,11 +2104,11 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *) SPObject *obj = selection->singleItem(); SPObject *parent = obj->parent; - GSList *to_unclump = NULL; // not including the original + SelContainer to_unclump; // not including the original for (SPObject *child = parent->firstChild(); child != NULL; child = child->next) { if (clonetiler_is_a_clone_of (child, obj)) { - to_unclump = g_slist_prepend (to_unclump, child); + to_unclump.push_front(child); } } @@ -2116,8 +2116,6 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *) unclump (to_unclump); - g_slist_free (to_unclump); - DocumentUndo::done(desktop->getDocument(), SP_VERB_DIALOG_CLONETILER, _("Unclump tiled clones")); } @@ -2147,7 +2145,7 @@ void CloneTiler::clonetiler_remove(GtkWidget */*widget*/, GtkWidget *dlg, bool d Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected - if (selection->isEmpty() || g_slist_length((GSList *) selection->itemList()) > 1) { + if (selection->isEmpty() || selection->itemList().size() > 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select one object whose tiled clones to remove.")); return; } @@ -2225,7 +2223,7 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) } // Check if more than one object is selected. - if (g_slist_length((GSList *) selection->itemList()) > 1) { + if (selection->itemList().size() > 1) { desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("If you want to clone several objects, group them and clone the group.")); return; } diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 6d90c792e..fc6094c9f 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -605,7 +605,7 @@ void Export::onBatchClicked () void Export::updateCheckbuttons () { - gint num = g_slist_length((GSList *) SP_ACTIVE_DESKTOP->getSelection()->itemList()); + gint num = SP_ACTIVE_DESKTOP->getSelection()->itemList().size(); if (num >= 2) { batch_export.set_sensitive(true); batch_export.set_label(g_strdup_printf (ngettext("B_atch export %d selected object","B_atch export %d selected objects",num), num)); @@ -817,9 +817,9 @@ void Export::onAreaToggled () one that's nice */ if (filename.empty()) { const gchar * id = "object"; - const GSList * reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); - for(; reprlst != NULL; reprlst = reprlst->next) { - Inkscape::XML::Node * repr = (Inkscape::XML::Node *)reprlst->data; + const SelContainer reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); + for(SelContainer::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + Inkscape::XML::Node * repr = (Inkscape::XML::Node *)(*i); if (repr->attribute("id")) { id = repr->attribute("id"); break; @@ -1010,7 +1010,7 @@ void Export::onExport () if (batch_export.get_active ()) { // Batch export of selected objects - gint num = g_slist_length(const_cast(desktop->getSelection()->itemList())); + gint num = (desktop->getSelection()->itemList()).size(); gint n = 0; if (num < 1) { @@ -1024,8 +1024,9 @@ void Export::onExport () gint export_count = 0; - for (GSList *i = const_cast(desktop->getSelection()->itemList()); i && !interrupted; i = i->next) { - SPItem *item = reinterpret_cast(i->data); + SelContainer itemlist=desktop->getSelection()->itemList(); + for(SelContainer::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;i++){ + SPItem *item = reinterpret_cast(*i); prog_dlg->set_data("current", GINT_TO_POINTER(n)); prog_dlg->set_data("total", GINT_TO_POINTER(num)); @@ -1063,13 +1064,13 @@ void Export::onExport () _("Exporting file %s..."), safeFile), desktop); MessageCleaner msgFlashCleanup(desktop->messageStack()->flashF(Inkscape::IMMEDIATE_MESSAGE, _("Exporting file %s..."), safeFile), desktop); - + SelContainer x; if (!sp_export_png_file (doc, path.c_str(), *area, width, height, dpi, dpi, nv->pagecolor, onProgressCallback, (void*)prog_dlg, TRUE, // overwrite without asking - hide ? const_cast(desktop->getSelection()->itemList()) : NULL + hide ? (desktop->getSelection()->itemList()) : x )) { gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); @@ -1153,12 +1154,13 @@ void Export::onExport () prog_dlg->set_data("total", GINT_TO_POINTER(0)); /* Do export */ + SelContainer x; ExportResult status = sp_export_png_file(desktop->getDocument(), path.c_str(), Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi, nv->pagecolor, onProgressCallback, (void*)prog_dlg, FALSE, - hide ? const_cast(desktop->getSelection()->itemList()) : NULL + hide ? (desktop->getSelection()->itemList()) : x ); if (status == EXPORT_ERROR) { gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str()); @@ -1224,7 +1226,7 @@ void Export::onExport () break; } case SELECTION_SELECTION: { - const GSList * reprlst; + SelContainer reprlst; SPDocument * doc = SP_ACTIVE_DOCUMENT; bool modified = false; @@ -1232,8 +1234,8 @@ void Export::onExport () DocumentUndo::setUndoSensitive(doc, false); reprlst = desktop->getSelection()->reprList(); - for(; reprlst != NULL; reprlst = reprlst->next) { - Inkscape::XML::Node * repr = static_cast(reprlst->data); + for(SelContainer::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + Inkscape::XML::Node * repr = dynamic_cast(*i); const gchar * temp_string; Glib::ustring dir = Glib::path_get_dirname(filename.c_str()); const gchar* docURI=SP_ACTIVE_DOCUMENT->getURI(); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 3da0e0043..657d6771b 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -690,7 +690,7 @@ private: void select_svg_element(){ Inkscape::Selection* sel = _desktop->getSelection(); if (sel->isEmpty()) return; - Inkscape::XML::Node* node = (Inkscape::XML::Node*) g_slist_nth_data((GSList *)sel->reprList(), 0); + Inkscape::XML::Node* node = (Inkscape::XML::Node*) sel->reprList().front(); if (!node || !node->matchAttributeName("id")) return; std::ostringstream xlikhref; @@ -1465,9 +1465,9 @@ void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel) } std::set used; - - for (GSList const *i = sel->itemList(); i != NULL; i = i->next) { - SPObject *obj = SP_OBJECT (i->data); + SelContainer itemlist=sel->itemList(); + for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + SPObject *obj = SP_OBJECT (*i); SPStyle *style = obj->style; if (!style || !SP_IS_ITEM(obj)) { continue; @@ -1545,10 +1545,9 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri if((*iter)[_columns.sel] == 1) filter = 0; - GSList const *items = sel->itemList(); - - for (GSList const *i = items; i != NULL; i = i->next) { - SPItem * item = SP_ITEM(i->data); + SelContainer itemlist=sel->itemList(); + for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + SPItem * item = SP_ITEM(*i); SPStyle *style = item->style; g_assert(style != NULL); @@ -1650,12 +1649,13 @@ void FilterEffectsDialog::FilterModifier::remove_filter() SPDocument* doc = filter->document; // Delete all references to this filter - GSList *all = get_all_items(NULL, _desktop->currentRoot(), _desktop, false, false, true, NULL); - for (GSList *i = all; i != NULL; i = i->next) { - if (!SP_IS_ITEM(i->data)) { + SelContainer x,y; + SelContainer all = get_all_items(x, _desktop->currentRoot(), _desktop, false, false, true, y); + for(SelContainer::const_iterator i=all.begin(); all.end() != i; i++) { + if (!SP_IS_ITEM(*i)) { continue; } - SPItem *item = SP_ITEM(i->data); + SPItem *item = SP_ITEM(*i); if (!item->style) { continue; } @@ -1668,9 +1668,6 @@ void FilterEffectsDialog::FilterModifier::remove_filter() } } } - if (all) { - g_slist_free(all); - } //XML Tree being used directly here while it shouldn't be. sp_repr_unparent(filter->getRepr()); diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index 951cb01ea..43ecb60ac 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -549,7 +549,7 @@ bool Find::item_font_match(SPItem *item, const gchar *text, bool exact, bool cas } -GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) +SelContainer Find::filter_fields (SelContainer &l, bool exact, bool casematch) { Glib::ustring tmp = entry_find.getEntry()->get_text(); if (tmp.empty()) { @@ -557,17 +557,17 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) } gchar* text = g_strdup(tmp.c_str()); - GSList *in = l; - GSList *out = NULL; + SelContainer in = l; + SelContainer out; if (check_searchin_text.get_active()) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_text_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(), *i)) { + out.push_front(*i); if (_action_replace) { item_text_match(item, text, exact, casematch, _action_replace); } @@ -584,12 +584,12 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) bool attrvalue = check_attributevalue.get_active(); if (ids) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); if (item_id_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(), *i)) { + out.push_front(*i); if (_action_replace) { item_id_match(item, text, exact, casematch, _action_replace); } @@ -600,14 +600,13 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) if (style) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_style_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(), *i)){ + out.push_front(*i); if (_action_replace) { item_style_match(item, text, exact, casematch, _action_replace); } @@ -618,13 +617,13 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) if (attrname) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_attr_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(), *i)) { + out.push_front(*i); if (_action_replace) { item_attr_match(item, text, exact, casematch, _action_replace); } @@ -635,13 +634,13 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) if (attrvalue) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_attrvalue_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(), *i)) { + out.push_front(*i); if (_action_replace) { item_attrvalue_match(item, text, exact, casematch, _action_replace); } @@ -652,13 +651,13 @@ GSList *Find::filter_fields (GSList *l, bool exact, bool casematch) if (font) { - for (GSList *i = in; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_font_match(item, text, exact, casematch)) { - if (!g_slist_find(out, i->data)) { - out = g_slist_prepend (out, i->data); + if (out.end()==find(out.begin(),out.end(),*i)) { + out.push_front(*i); if (_action_replace) { item_font_match(item, text, exact, casematch, _action_replace); } @@ -716,29 +715,29 @@ bool Find::item_type_match (SPItem *item) return false; } -GSList *Find::filter_types (GSList *l) +SelContainer Find::filter_types (SelContainer &l) { - GSList *n = NULL; - for (GSList *i = l; i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + SelContainer n; + for(SelContainer::const_iterator i=l.begin(); l.end() != i; i++) { + SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_type_match(item)) { - n = g_slist_prepend (n, i->data); + n.push_front(*i); } } return n; } -GSList *Find::filter_list (GSList *l, bool exact, bool casematch) +SelContainer &Find::filter_list (SelContainer &l, bool exact, bool casematch) { l = filter_types (l); l = filter_fields (l, exact, casematch); return l; } -GSList *Find::all_items (SPObject *r, GSList *l, bool hidden, bool locked) +SelContainer &Find::all_items (SPObject *r, SelContainer &l, bool hidden, bool locked) { if (dynamic_cast(r)) { return l; // we're not interested in items in defs @@ -752,7 +751,7 @@ GSList *Find::all_items (SPObject *r, GSList *l, bool hidden, bool locked) SPItem *item = dynamic_cast(child); if (item && !child->cloned && !desktop->isLayer(item)) { if ((hidden || !desktop->itemIsHidden(item)) && (locked || !item->isLocked())) { - l = g_slist_prepend (l, child); + l.push_front(child); } } l = all_items (child, l, hidden, locked); @@ -760,16 +759,17 @@ GSList *Find::all_items (SPObject *r, GSList *l, bool hidden, bool locked) return l; } -GSList *Find::all_selection_items (Inkscape::Selection *s, GSList *l, SPObject *ancestor, bool hidden, bool locked) +SelContainer &Find::all_selection_items (Inkscape::Selection *s, SelContainer &l, SPObject *ancestor, bool hidden, bool locked) { - for (GSList *i = (GSList *) s->itemList(); i != NULL; i = i->next) { - SPObject *obj = reinterpret_cast(i->data); + SelContainer itemlist=s->itemList(); + for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item && !item->cloned && !desktop->isLayer(item)) { if (!ancestor || ancestor->isAncestorOf(item)) { if ((hidden || !desktop->itemIsHidden(item)) && (locked || !item->isLocked())) { - l = g_slist_prepend (l, i->data); + l.push_back(*i); } } } @@ -817,7 +817,7 @@ void Find::onAction() bool casematch = check_case_sensitive.get_active(); blocked = true; - GSList *l = NULL; + SelContainer l; if (check_scope_selection.get_active()) { if (check_scope_layer.get_active()) { l = all_selection_items (desktop->selection, l, desktop->currentLayer(), hidden, locked); @@ -831,12 +831,12 @@ void Find::onAction() l = all_items(desktop->getDocument()->getRoot(), l, hidden, locked); } } - guint all = g_slist_length (l); + guint all = l.size(); - GSList *n = filter_list (l, exact, casematch); + SelContainer n = filter_list (l, exact, casematch); - if (n != NULL) { - int count = g_slist_length (n); + if (!n.empty()) { + int count = n.size(); desktop->messageStack()->flashF(Inkscape::NORMAL_MESSAGE, // TRANSLATORS: "%s" is replaced with "exact" or "partial" when this string is displayed ngettext("%d object found (out of %d), %s match.", @@ -857,7 +857,7 @@ void Find::onAction() Inkscape::Selection *selection = desktop->getSelection(); selection->clear(); selection->setList(n); - SPObject *obj = reinterpret_cast(n->data); + SPObject *obj = reinterpret_cast(n.front()); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); scroll_to_show_item(desktop, item); diff --git a/src/ui/dialog/find.h b/src/ui/dialog/find.h index c0c635f94..1aded96f2 100644 --- a/src/ui/dialog/find.h +++ b/src/ui/dialog/find.h @@ -16,6 +16,7 @@ # include #endif +#include "selection.h" #include "ui/widget/panel.h" #include "ui/widget/button.h" #include "ui/widget/entry.h" @@ -148,10 +149,10 @@ protected: /** * Function to filter a list of items based on the item type by calling each item_XXX_match function */ - GSList * filter_fields (GSList *l, bool exact, bool casematch); + SelContainer filter_fields (SelContainer &l, bool exact, bool casematch); bool item_type_match (SPItem *item); - GSList * filter_types (GSList *l); - GSList * filter_list (GSList *l, bool exact, bool casematch); + SelContainer filter_types (SelContainer &l); + SelContainer & filter_list (SelContainer &l, bool exact, bool casematch); /** * Find a string within a string and returns true if found with options for exact and casematching @@ -172,12 +173,12 @@ protected: * recursive function to return a list of all the items in the SPObject tree * */ - GSList * all_items (SPObject *r, GSList *l, bool hidden, bool locked); + SelContainer & all_items (SPObject *r, SelContainer &l, bool hidden, bool locked); /** * to return a list of all the selected items * */ - GSList * all_selection_items (Inkscape::Selection *s, GSList *l, SPObject *ancestor, bool hidden, bool locked); + SelContainer & all_selection_items (Inkscape::Selection *s, SelContainer &l, SPObject *ancestor, bool hidden, bool locked); /** * Shrink the dialog size when the expander widget is closed diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp index 2b9053da9..1ef97b996 100644 --- a/src/ui/dialog/glyphs.cpp +++ b/src/ui/dialog/glyphs.cpp @@ -578,9 +578,10 @@ void GlyphsPanel::setTargetDesktop(SPDesktop *desktop) void GlyphsPanel::insertText() { SPItem *textItem = 0; - for (const GSList *item = targetDesktop->selection->itemList(); item; item = item->next ) { - if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) { - textItem = SP_ITEM(item->data); + SelContainer itemlist=targetDesktop->selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { + textItem = SP_ITEM(*i); break; } } @@ -687,8 +688,9 @@ void GlyphsPanel::selectionModifiedCB(guint flags) void GlyphsPanel::calcCanInsert() { int items = 0; - for (const GSList *item = targetDesktop->selection->itemList(); item; item = item->next ) { - if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) { + SelContainer itemlist=targetDesktop->selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { ++items; } } diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 28a65e0b4..86cf629c1 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -1906,11 +1906,10 @@ void ContextMenu::ActivateGroup(void) void ContextMenu::ActivateUngroup(void) { - GSList *children = NULL; + SelContainer children; - sp_item_group_ungroup(static_cast(_item), &children); + sp_item_group_ungroup(static_cast(_item), children); _desktop->selection->setList(children); - g_slist_free(children); } void ContextMenu::MakeAnchorMenu(void) @@ -1959,10 +1958,9 @@ void ContextMenu::AnchorLinkFollow(void) void ContextMenu::AnchorLinkRemove(void) { - GSList *children = NULL; - sp_item_group_ungroup(static_cast(_item), &children, false); + SelContainer children; + sp_item_group_ungroup(static_cast(_item), children, false); DocumentUndo::done(_desktop->doc(), SP_VERB_NONE, _("Remove link")); - g_slist_free(children); } void ContextMenu::MakeImageMenu (void) @@ -2051,8 +2049,6 @@ void ContextMenu::ImageEdit(void) _desktop->selection->set(_item); } - GSList const *selected = _desktop->selection->itemList(); - GError* errThing = 0; Glib::ustring cmdline = getImageEditorName(); Glib::ustring name; @@ -2079,8 +2075,9 @@ void ContextMenu::ImageEdit(void) } #endif - for (GSList const *iter = selected; iter != NULL; iter = iter->next) { - Inkscape::XML::Node *ir = SP_ITEM(iter->data)->getRepr(); + SelContainer itemlist=_desktop->selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + Inkscape::XML::Node *ir = SP_ITEM(*i)->getRepr(); const gchar *href = ir->attribute("xlink:href"); if (strncmp (href,"file:",5) == 0) { diff --git a/src/unclump.cpp b/src/unclump.cpp index 940369d7a..d1cfc6628 100644 --- a/src/unclump.cpp +++ b/src/unclump.cpp @@ -168,13 +168,12 @@ unclump_dist (SPItem *item1, SPItem *item2) /** Average unclump_dist from item to others */ -static double unclump_average (SPItem *item, GSList *others) +static double unclump_average (SPItem *item, SelContainer &others) { int n = 0; double sum = 0; - - for (GSList *i = others; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) { + SPItem *other = SP_ITEM (*i); if (other == item) continue; @@ -192,13 +191,13 @@ static double unclump_average (SPItem *item, GSList *others) /** Closest to item among others */ -static SPItem *unclump_closest (SPItem *item, GSList *others) +static SPItem *unclump_closest (SPItem *item, SelContainer &others) { double min = HUGE_VAL; SPItem *closest = NULL; - for (GSList *i = others; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) { + SPItem *other = SP_ITEM (*i); if (other == item) continue; @@ -216,13 +215,12 @@ static SPItem *unclump_closest (SPItem *item, GSList *others) /** Most distant from item among others */ -static SPItem *unclump_farest (SPItem *item, GSList *others) +static SPItem *unclump_farest (SPItem *item, SelContainer &others) { double max = -HUGE_VAL; SPItem *farest = NULL; - - for (GSList *i = others; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) { + SPItem *other = SP_ITEM (*i); if (other == item) continue; @@ -242,8 +240,8 @@ Removes from the \a rest list those items that are "behind" \a closest as seen f i.e. those on the other side of the line through \a closest perpendicular to the direction from \a item to \a closest. Returns a newly created list which must be freed. */ -static GSList * -unclump_remove_behind (SPItem *item, SPItem *closest, GSList *rest) +static SelContainer +unclump_remove_behind (SPItem *item, SPItem *closest, SelContainer &rest) { Geom::Point it = unclump_center (item); Geom::Point p1 = unclump_center (closest); @@ -260,10 +258,9 @@ unclump_remove_behind (SPItem *item, SPItem *closest, GSList *rest) // substitute the item into it: double val_item = A * it[Geom::X] + B * it[Geom::Y] + C; - GSList *out = NULL; - - for (GSList *i = rest; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + SelContainer out; + for (SelContainer::const_iterator i = rest.begin(); i != rest.end();i++) { + SPItem *other = SP_ITEM (*i); if (other == item) continue; @@ -274,7 +271,7 @@ unclump_remove_behind (SPItem *item, SPItem *closest, GSList *rest) if (val_item * val_other <= 1e-6) { // different signs, which means item and other are on the different sides of p1-p2 line; skip } else { - out = g_slist_prepend (out, other); + out.push_front(other); } } @@ -334,34 +331,32 @@ similar to "engraver dots". The only distribution which is unchanged by unclumpi grid. May be called repeatedly for stronger effect. */ void -unclump (GSList *items) +unclump (SelContainer &items) { c_cache.clear(); wh_cache.clear(); - for (GSList *i = items; i != NULL; i = i->next) { // for each original/clone x: - SPItem *item = SP_ITEM (i->data); + for (SelContainer::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x: + SPItem *item = SP_ITEM (*i); - GSList *nei = NULL; + SelContainer nei; - GSList *rest = g_slist_copy (items); - rest = g_slist_remove (rest, item); + SelContainer rest(items); + rest.remove(item); - while (rest != NULL) { + while (!rest.empty()) { SPItem *closest = unclump_closest (item, rest); if (closest) { - nei = g_slist_prepend (nei, closest); - rest = g_slist_remove (rest, closest); - GSList *new_rest = unclump_remove_behind (item, closest, rest); - g_slist_free (rest); + nei.push_front(closest); + rest.remove(closest); + SelContainer new_rest = unclump_remove_behind (item, closest, rest); rest = new_rest; } else { - g_slist_free (rest); break; } } - if (g_slist_length (nei) >= 2) { + if ( (nei.size()) >= 2) { double ave = unclump_average (item, nei); SPItem *closest = unclump_closest (item, nei); diff --git a/src/unclump.h b/src/unclump.h index 2411cb713..54f43ffde 100644 --- a/src/unclump.h +++ b/src/unclump.h @@ -12,8 +12,9 @@ #define SEEN_DIALOGS_UNCLUMP_H typedef struct _GSList GSList; +#include "selection.h" -void unclump(GSList *items); +void unclump(SelContainer &items); #endif /* !UNCLUMP_H_SEEN */ diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index b62aacbc5..98a3eaa67 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -256,8 +256,9 @@ VanishingPoint::set_pos(Proj::Pt2 const &pt) { std::list VanishingPoint::selectedBoxes(Inkscape::Selection *sel) { std::list sel_boxes; - for (GSList const* i = sel->itemList(); i != NULL; i = i->next) { - SPItem *item = static_cast(i->data); + SelContainer itemlist=sel->itemList(); + for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + SPItem *item = static_cast(*i); SPBox3D *box = dynamic_cast(item); if (box && this->hasBox(box)) { sel_boxes.push_back(box); @@ -395,8 +396,9 @@ VPDragger::VPsOfSelectedBoxes() { VanishingPoint *vp; // FIXME: Should we take the selection from the parent VPDrag? I guess it shouldn't make a difference. Inkscape::Selection *sel = SP_ACTIVE_DESKTOP->getSelection(); - for (GSList const* i = sel->itemList(); i != NULL; i = i->next) { - SPItem *item = static_cast(i->data); + SelContainer itemlist=sel->itemList(); + for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + SPItem *item = static_cast(*i); SPBox3D *box = dynamic_cast(item); if (box) { vp = this->findVPWithBox(box); @@ -577,8 +579,9 @@ VPDrag::updateDraggers () g_return_if_fail (this->selection != NULL); - for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { - SPItem *item = static_cast(i->data); + SelContainer itemlist=this->selection->itemList(); + for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + SPItem *item = static_cast(*i); SPBox3D *box = dynamic_cast(item); if (box) { VanishingPoint vp; @@ -609,8 +612,9 @@ VPDrag::updateLines () g_return_if_fail (this->selection != NULL); - for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) { - SPItem *item = static_cast(i->data); + SelContainer itemlist=this->selection->itemList(); + for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + SPItem *item = static_cast(*i); SPBox3D *box = dynamic_cast(item); if (box) { this->drawLinesForFace (box, Proj::X); @@ -626,11 +630,11 @@ VPDrag::updateBoxHandles () // FIXME: Is there a way to update the knots without accessing the // (previously) statically linked function KnotHolder::update_knots? - GSList *sel = (GSList *) selection->itemList(); - if (!sel) + SelContainer sel = selection->itemList(); + if (sel.empty()) return; // no selection - if (g_slist_length (sel) > 1) { + if (sel.size() > 1) { // Currently we only show handles if a single box is selected return; } diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 8a64854be..23c248129 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -97,12 +97,9 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v gchar* namespaced_name = g_strconcat("sodipodi:", value_name, NULL); bool modmade = false; - for (GSList const *items = desktop->getSelection()->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = SP_ITEM(items->data); - + SelContainer itemlist=desktop->getSelection()->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_GENERICELLIPSE(item)) { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); @@ -166,11 +163,9 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) bool modmade = false; if ( ege_select_one_action_get_active(act) != 0 ) { - for (GSList const *items = desktop->getSelection()->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=desktop->getSelection()->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("sodipodi:open", "true"); @@ -179,11 +174,9 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) } } } else { - for (GSList const *items = desktop->getSelection()->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=desktop->getSelection()->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("sodipodi:open", NULL); @@ -271,11 +264,9 @@ static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GOb purge_repr_listener( tbl, tbl ); - for (GSList const *items = selection->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_GENERICELLIPSE(item)) { n_selected++; repr = item->getRepr(); diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index c906f7de4..401ce932a 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -76,7 +76,6 @@ static void sp_connector_path_set_ignore(void) static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl ) { SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); - Inkscape::Selection * selection = desktop->getSelection(); SPDocument *doc = desktop->getDocument(); if (!DocumentUndo::getUndoSensitive(doc)) { @@ -98,9 +97,9 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl gchar *value = is_orthog ? orthog_str : polyline_str ; bool modmade = false; - GSList *l = (GSList *) selection->itemList(); - while (l) { - SPItem *item = SP_ITEM(l->data); + SelContainer itemlist=desktop->getSelection()->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (Inkscape::UI::Tools::cc_item_is_connector(item)) { item->setAttribute( "inkscape:connector-type", @@ -108,7 +107,6 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl item->avoidRef->handleSettingChange(); modmade = true; } - l = l->next; } if (!modmade) { @@ -126,7 +124,6 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) { SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); - Inkscape::Selection * selection = desktop->getSelection(); SPDocument *doc = desktop->getDocument(); if (!DocumentUndo::getUndoSensitive(doc)) { @@ -147,9 +144,9 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) g_ascii_dtostr(value, G_ASCII_DTOSTR_BUF_SIZE, newValue); bool modmade = false; - GSList *l = (GSList *) selection->itemList(); - while (l) { - SPItem *item = SP_ITEM(l->data); + SelContainer itemlist=desktop->getSelection()->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (Inkscape::UI::Tools::cc_item_is_connector(item)) { item->setAttribute( "inkscape:connector-curvature", @@ -157,7 +154,6 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) item->avoidRef->handleSettingChange(); modmade = true; } - l = l->next; } if (!modmade) { diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index d60a92b8b..2c298b04d 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -481,7 +481,7 @@ void FillNStroke::updateFromPaint() SPDocument *document = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); + SelContainer const items = selection->itemList(); switch (psel->mode) { case SPPaintSelector::MODE_EMPTY: @@ -543,7 +543,7 @@ void FillNStroke::updateFromPaint() case SPPaintSelector::MODE_GRADIENT_LINEAR: case SPPaintSelector::MODE_GRADIENT_RADIAL: case SPPaintSelector::MODE_SWATCH: - if (items) { + if (!items.empty()) { SPGradientType const gradient_type = ( psel->mode != SPPaintSelector::MODE_GRADIENT_RADIAL ? SP_GRADIENT_TYPE_LINEAR : SP_GRADIENT_TYPE_RADIAL ); @@ -561,7 +561,7 @@ void FillNStroke::updateFromPaint() /* No vector in paint selector should mean that we just changed mode */ SPStyle query(desktop->doc()); - int result = objects_query_fillstroke(const_cast(items), &query, kind == FILL); + int result = objects_query_fillstroke(items, &query, kind == FILL); if (result == QUERY_STYLE_MULTIPLE_SAME) { SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke; SPColor common; @@ -576,39 +576,39 @@ void FillNStroke::updateFromPaint() } } - for (GSList const *i = items; i != NULL; i = i->next) { + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above if (kind == FILL) { - sp_repr_css_change_recursive(reinterpret_cast(i->data)->getRepr(), css, "style"); + sp_repr_css_change_recursive(reinterpret_cast(*i)->getRepr(), css, "style"); } if (!vector) { SPGradient *gr = sp_gradient_vector_for_object( document, desktop, - reinterpret_cast(i->data), + reinterpret_cast(*i), (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE, createSwatch ); if ( gr && createSwatch ) { gr->setSwatch(); } - sp_item_set_gradient(SP_ITEM(i->data), + sp_item_set_gradient(SP_ITEM(*i), gr, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); } else { - sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); + sp_item_set_gradient(SP_ITEM(*i), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); } } } else { // We have changed from another gradient type, or modified spread/units within // this gradient type. vector = sp_gradient_ensure_vector_normalized(vector); - for (GSList const *i = items; i != NULL; i = i->next) { + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above if (kind == FILL) { - sp_repr_css_change_recursive(reinterpret_cast(i->data)->getRepr(), css, "style"); + sp_repr_css_change_recursive(reinterpret_cast(*i)->getRepr(), css, "style"); } - SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); + SPGradient *gr = sp_item_set_gradient(SP_ITEM(*i), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); psel->pushAttrsToGradient( gr ); } } @@ -625,7 +625,7 @@ void FillNStroke::updateFromPaint() case SPPaintSelector::MODE_PATTERN: - if (items) { + if (!items.empty()) { SPPattern *pattern = psel->getPattern(); if (!pattern) { @@ -648,12 +648,12 @@ void FillNStroke::updateFromPaint() // cannot just call sp_desktop_set_style, because we don't want to touch those // objects who already have the same root pattern but through a different href // chain. FIXME: move this to a sp_item_set_pattern - for (GSList const *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *selrepr = reinterpret_cast(i->data)->getRepr(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + Inkscape::XML::Node *selrepr = reinterpret_cast(*i)->getRepr(); if ( (kind == STROKE) && !selrepr) { continue; } - SPObject *selobj = reinterpret_cast(i->data); + SPObject *selobj = reinterpret_cast(*i); SPStyle *style = selobj->style; if (style && ((kind == FILL) ? style->fill : style->stroke).isPaintserver()) { @@ -686,7 +686,7 @@ void FillNStroke::updateFromPaint() break; case SPPaintSelector::MODE_UNSET: - if (items) { + if (!items.empty()) { SPCSSAttr *css = sp_repr_css_attr_new(); if (kind == FILL) { sp_repr_css_unset_property(css, "fill"); diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index 7ce04403b..b9608130b 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -116,8 +116,9 @@ void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient } // If no drag or no dragger selected, act on selection - for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { - gr_apply_gradient_to_item(SP_ITEM(i->data), gr, initialType, initialMode, initialMode); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + gr_apply_gradient_to_item(SP_ITEM(*i), gr, initialType, initialMode, initialMode); } } @@ -217,8 +218,9 @@ void gr_get_dt_selected_gradient(Inkscape::Selection *selection, SPGradient *&gr { SPGradient *gradient = 0; - for (GSList const* i = selection->itemList(); i; i = i->next) { - SPItem *item = SP_ITEM(i->data); // get the items gradient, not the getVector() version + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i);// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; @@ -284,8 +286,9 @@ void gr_read_selection( Inkscape::Selection *selection, } // If no selected dragger, read desktop selection - for (GSList const* i = selection->itemList(); i; i = i->next) { - SPItem *item = SP_ITEM(i->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; if (style && (style->fill.isPaintserver())) { diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index 3d549047a..b4176db6f 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -87,8 +87,9 @@ void ms_read_selection( Inkscape::Selection *selection, bool first = true; ms_smooth = SP_MESH_SMOOTH_NONE; - for (GSList const* i = selection->itemList(); i; i = i->next) { - SPItem *item = SP_ITEM(i->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; if (style && (style->fill.isPaintserver())) { @@ -213,8 +214,9 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMeshGradient { SPMeshGradient *gradient = 0; - for (GSList const* i = selection->itemList(); i; i = i->next) { - SPItem *item = SP_ITEM(i->data); // get the items gradient, not the getVector() version + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i);// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 016aa4987..1f19867ee 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -106,12 +106,13 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - for (GSList const *items = selection->itemList(); items != NULL; items = items->next) { - if (SP_IS_RECT(items->data)) { + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + if (SP_IS_RECT(*i)) { if (gtk_adjustment_get_value(adj) != 0) { - (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, desktop->getNamedView()->svg_units)); + (SP_RECT(*i)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, desktop->getNamedView()->svg_units)); } else { - SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL); + SP_OBJECT(*i)->getRepr()->setAttribute(value_name, NULL); } modmade = true; } @@ -243,12 +244,11 @@ static void sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GO } purge_repr_listener( tbl, tbl ); - for (GSList const *items = selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_RECT(reinterpret_cast(items->data))) { + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + if (SP_IS_RECT(reinterpret_cast(*i))) { n_selected++; - item = reinterpret_cast(items->data); + item = reinterpret_cast(*i); repr = item->getRepr(); } } diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 3fb0015c1..2f4ad481d 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -79,11 +79,9 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr gchar* namespaced_name = g_strconcat("sodipodi:", value_name.data(), NULL); bool modmade = false; - for (GSList const *items = desktop->getSelection()->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=desktop->getSelection()->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_SPIRAL(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_svg_double( repr, namespaced_name, @@ -197,11 +195,9 @@ static void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, purge_repr_listener( tbl, tbl ); - for (GSList const *items = selection->itemList(); - items != NULL; - items = items->next) - { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_SPIRAL(item)) { n_selected++; repr = item->getRepr(); diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index cf12391c1..37daf69d0 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -83,9 +83,9 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_int(repr,"sodipodi:sides", @@ -128,9 +128,9 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -178,7 +178,6 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(TRUE) ); Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); GtkAction* prop_action = GTK_ACTION( g_object_get_data( dataKludge, "prop_action" ) ); bool modmade = false; @@ -186,8 +185,9 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d gtk_action_set_sensitive( prop_action, !flat ); } - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("inkscape:flatsided", flat ? "true" : "false" ); @@ -224,9 +224,9 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_svg_double(repr, "inkscape:rounded", @@ -264,9 +264,9 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_svg_double(repr, "inkscape:randomized", @@ -367,11 +367,9 @@ sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) purge_repr_listener( tbl, tbl ); - for (GSList const *items = selection->itemList(); - items != NULL; - items = items->next) - { - SPItem* item = reinterpret_cast(items->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { n_selected++; repr = item->getRepr(); diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 5ca06a795..2599fe537 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -475,9 +475,9 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, //spw->updateMarkerHist(which); Inkscape::Selection *selection = spw->desktop->getSelection(); - GSList const *items = selection->itemList(); - for (; items != NULL; items = items->next) { - SPItem *item = reinterpret_cast(items->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + SPItem *item = SP_ITEM(*i); if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) { // can't set marker to rect, until it's converted to using continue; } @@ -901,8 +901,8 @@ StrokeStyle::updateLine() if (!sel || sel->isEmpty()) return; - GSList const *objects = sel->itemList(); - SPObject * const object = SP_OBJECT(objects->data); + SelContainer const objects = sel->itemList(); + SPObject * const object = SP_OBJECT(objects.front()); SPStyle * const style = object->style; /* Markers */ @@ -957,13 +957,12 @@ StrokeStyle::scaleLine() SPDocument *document = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); - - GSList const *items = selection->itemList(); + SelContainer items=selection->itemList(); /* TODO: Create some standardized method */ SPCSSAttr *css = sp_repr_css_attr_new(); - if (items) { + if (!items.empty()) { #if WITH_GTKMM_3_0 double width_typed = (*widthAdj)->get_value(); double const miterlimit = (*miterLimitAdj)->get_value(); @@ -978,13 +977,13 @@ StrokeStyle::scaleLine() int ndash; dashSelector->get_dash(&ndash, &dash, &offset); - for (GSList const *i = items; i != NULL; i = i->next) { + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ /* Set stroke width */ double width; if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { width = Inkscape::Util::Quantity::convert(width_typed, unit, "px"); } else { // percentage - gdouble old_w = SP_OBJECT(i->data)->style->stroke_width.computed; + gdouble old_w = SP_OBJECT(*i)->style->stroke_width.computed; width = old_w * width_typed / 100; } @@ -1003,7 +1002,7 @@ StrokeStyle::scaleLine() /* Set dash */ setScaledDash(css, ndash, dash, offset, width); - sp_desktop_apply_css_recursive (SP_OBJECT(i->data), css, true); + sp_desktop_apply_css_recursive (SP_OBJECT(*i), css, true); } g_free(dash); @@ -1144,7 +1143,7 @@ StrokeStyle::setCapButtons(Gtk::ToggleButton *active) * that marker. */ void -StrokeStyle::updateAllMarkers(GSList const *objects) +StrokeStyle::updateAllMarkers(SelContainer const &objects) { struct { MarkerComboBox *key; int loc; } const keyloc[] = { { startMarkerCombo, SP_MARKER_LOC_START }, @@ -1153,8 +1152,8 @@ StrokeStyle::updateAllMarkers(GSList const *objects) }; bool all_texts = true; - for (GSList *i = (GSList *) objects; i != NULL; i = i->next) { - if (!SP_IS_TEXT (i->data)) { + for(SelContainer::const_iterator i=objects.begin();i!=objects.end();i++){ + if (!SP_IS_TEXT (*i)) { all_texts = false; } } @@ -1167,7 +1166,7 @@ StrokeStyle::updateAllMarkers(GSList const *objects) // We show markers of the first object in the list only // FIXME: use the first in the list that has the marker of each type, if any - SPObject *object = SP_OBJECT(objects->data); + SPObject *object = SP_OBJECT(objects.front()); for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) { // For all three marker types, diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index 83048cb76..286305ec3 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -153,7 +153,7 @@ private: }; void updateLine(); - void updateAllMarkers(GSList const *objects); + void updateAllMarkers(SelContainer const &objects); void updateMarkerHist(SPMarkerLoc const which); void setDashSelectorFromStyle(SPDashSelector *dsel, SPStyle *style); void setJoinType (unsigned const jointype); diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 3d2e6eef8..ba7dfc1fd 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -366,9 +366,10 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) // move the x of all texts to preserve the same bbox Inkscape::Selection *selection = desktop->getSelection(); - for (GSList const *items = selection->itemList(); items != NULL; items = items->next) { - if (SP_IS_TEXT(SP_ITEM(items->data))) { - SPItem *item = SP_ITEM(items->data); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + if (SP_IS_TEXT(SP_ITEM(*i))) { + SPItem *item = SP_ITEM(*i); unsigned writing_mode = item->style->writing_mode.value; // below, variable names suggest horizontal move, but we check the writing direction @@ -517,11 +518,11 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) // Until deprecated sodipodi:linespacing purged: Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); bool modmade = false; - for (; items != NULL; items = items->next) { - if (SP_IS_TEXT (items->data)) { - SP_OBJECT(items->data)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); + SelContainer itemlist=selection->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + if (SP_IS_TEXT (*i)) { + SP_OBJECT(*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); modmade = true; } } @@ -863,12 +864,11 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Only flowed text can be justified, only normal text can be kerned... // Find out if we have flowed text now so we can use it several places gboolean isFlow = false; - for (GSList const *items = SP_ACTIVE_DESKTOP->getSelection()->itemList(); - items != NULL; - items = items->next) { + SelContainer itemlist=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ // const gchar* id = reinterpret_cast(items->data)->getId(); // std::cout << " " << id << std::endl; - if( SP_IS_FLOWTEXT(SP_ITEM(items->data))) { + if( SP_IS_FLOWTEXT(SP_ITEM(*i))) { isFlow = true; // std::cout << " Found flowed text" << std::endl; break; @@ -1153,14 +1153,14 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p //std::cout << "text_toolbox_missing_font_cb: selecting: " << family << std::endl; // Get all items with matching font-family set (not inherited!). - GSList *selectList = NULL; + SelContainer selectList; SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPDocument *document = desktop->getDocument(); - GSList *allList = get_all_items(NULL, document->getRoot(), desktop, false, false, true, NULL); - for (GSList *i = allList; i != NULL; i = i->next) { - - SPItem *item = SP_ITEM(i->data); + SelContainer x,y; + SelContainer allList = get_all_items(x, document->getRoot(), desktop, false, false, true, y); + for(SelContainer::const_iterator i=allList.begin();i!=allList.end();i++){ + SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; if (style) { @@ -1177,7 +1177,7 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p if (family_style.compare( family ) == 0 ) { //std::cout << " found: " << item->getId() << std::endl; - selectList = g_slist_prepend (selectList, item); + selectList.push_front(static_cast(item)); } } } -- cgit v1.2.3 From 193b25a53c51a36fe9538e03203b0054c8cfc355 Mon Sep 17 00:00:00 2001 From: mc <> Date: Wed, 18 Feb 2015 02:02:37 +0100 Subject: Just... some... more... lines... (bzr r13922.1.2) --- src/desktop.cpp | 2 +- src/desktop.h | 2 +- src/document.cpp | 32 ++++++++--------- src/document.h | 9 ++--- src/selection-chemistry.cpp | 13 ++++--- src/splivarot.h | 3 +- src/trace/trace.cpp | 6 ++-- src/ui/dialog/font-substitution.cpp | 24 +++++-------- src/ui/dialog/font-substitution.h | 6 ++-- src/ui/dialog/grid-arrange-tab.cpp | 54 ++++++++++++++++------------- src/ui/dialog/icon-preview.cpp | 8 ++--- src/ui/dialog/objects.cpp | 8 ++--- src/ui/dialog/pixelartdialog.cpp | 8 ++--- src/ui/dialog/polar-arrange-tab.cpp | 14 +++----- src/ui/dialog/print.cpp | 2 +- src/ui/dialog/svg-fonts-dialog.cpp | 4 +-- src/ui/dialog/swatches.cpp | 6 ++-- src/ui/dialog/tags.cpp | 11 +++--- src/ui/dialog/text-edit.cpp | 26 +++++++------- src/ui/dialog/transformation.cpp | 41 ++++++++++++---------- src/ui/tools/connector-tool.cpp | 8 ++--- src/ui/tools/eraser-tool.cpp | 31 +++++++---------- src/ui/tools/gradient-tool.cpp | 43 +++++++++++++---------- src/ui/tools/gradient-tool.h | 3 +- src/ui/tools/lpe-tool.cpp | 8 ++--- src/ui/tools/measure-tool.cpp | 6 ++-- src/ui/tools/mesh-tool.cpp | 34 +++++++++++------- src/ui/tools/node-tool.cpp | 10 +++--- src/ui/tools/select-tool.cpp | 5 ++- src/ui/tools/spray-tool.cpp | 32 +++++++---------- src/ui/tools/text-tool.cpp | 7 ++-- src/ui/tools/tool-base.cpp | 6 ++-- src/ui/tools/tweak-tool.cpp | 25 ++++++------- src/ui/widget/object-composite-settings.cpp | 3 +- src/ui/widget/style-subject.cpp | 34 +++++++++--------- src/ui/widget/style-subject.h | 15 ++++---- 36 files changed, 270 insertions(+), 279 deletions(-) (limited to 'src') diff --git a/src/desktop.cpp b/src/desktop.cpp index cdf8f276c..64353e582 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -716,7 +716,7 @@ Inkscape::UI::Widget::Dock* SPDesktop::getDock() { /** * \see SPDocument::getItemFromListAtPointBottom() */ -SPItem *SPDesktop::getItemFromListAtPointBottom(const GSList *list, Geom::Point const &p) const +SPItem *SPDesktop::getItemFromListAtPointBottom(const SelContainer &list, Geom::Point const &p) const { g_return_val_if_fail (doc() != NULL, NULL); return SPDocument::getItemFromListAtPointBottom(dkey, doc()->getRoot(), list, p); diff --git a/src/desktop.h b/src/desktop.h index a0b9592d0..8765fa699 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -319,7 +319,7 @@ public: //void push_event_context (GType type, const gchar *config, unsigned int key); void set_coordinate_status (Geom::Point p); - SPItem *getItemFromListAtPointBottom(const GSList *list, Geom::Point const &p) const; + SPItem *getItemFromListAtPointBottom(const SelContainer &list, Geom::Point const &p) const; SPItem *getItemAtPoint(Geom::Point const &p, bool into_groups, SPItem *upto = NULL) const; SPItem *getGroupAtPoint(Geom::Point const &p) const; Geom::Point point() const; diff --git a/src/document.cpp b/src/document.cpp index 11971e63d..5c49ff6c3 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1235,7 +1235,7 @@ static bool overlaps(Geom::Rect const &area, Geom::Rect const &box) return area.intersects(box); } -static GSList *find_items_in_area(GSList *s, SPGroup *group, unsigned int dkey, Geom::Rect const &area, +static SelContainer &find_items_in_area(SelContainer &s, SPGroup *group, unsigned int dkey, Geom::Rect const &area, bool (*test)(Geom::Rect const &, Geom::Rect const &), bool take_insensitive = false) { g_return_val_if_fail(SP_IS_GROUP(group), s); @@ -1248,7 +1248,7 @@ static GSList *find_items_in_area(GSList *s, SPGroup *group, unsigned int dkey, SPItem *child = SP_ITEM(o); Geom::OptRect box = child->desktopVisualBounds(); if ( box && test(area, *box) && (take_insensitive || child->isVisibleAndUnlocked(dkey))) { - s = g_slist_append(s, child); + s.push_back(child); } } } @@ -1275,7 +1275,7 @@ static bool item_is_in_group(SPItem *item, SPGroup *group) return inGroup; } -SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, GSList const *list,Geom::Point const &p, bool take_insensitive) +SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, SelContainer const &list,Geom::Point const &p, bool take_insensitive) { g_return_val_if_fail(group, NULL); SPItem *bottomMost = 0; @@ -1289,7 +1289,7 @@ SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *gro Inkscape::DrawingItem *arenaitem = item->get_arenaitem(dkey); if (arenaitem && arenaitem->pick(p, delta, 1) != NULL && (take_insensitive || item->isVisibleAndUnlocked(dkey))) { - if (g_slist_find((GSList *) list, item) != NULL) { + if (find(list.begin(),list.end(),item)==list.end() ) { bottomMost = item; } } @@ -1391,11 +1391,11 @@ static SPItem *find_group_at_point(unsigned int dkey, SPGroup *group, Geom::Poin * Assumes box is normalized (and g_asserts it!) * */ -GSList *SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) const +SelContainer SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) const { - g_return_val_if_fail(this->priv != NULL, NULL); - - return find_items_in_area(NULL, SP_GROUP(this->root), dkey, box, is_within); + SelContainer x; + g_return_val_if_fail(this->priv != NULL, x); + return find_items_in_area(x, SP_GROUP(this->root), dkey, box, is_within); } /* @@ -1405,16 +1405,16 @@ GSList *SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) cons * */ -GSList *SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const +SelContainer SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const { - g_return_val_if_fail(this->priv != NULL, NULL); - - return find_items_in_area(NULL, SP_GROUP(this->root), dkey, box, overlaps); + SelContainer x; + g_return_val_if_fail(this->priv != NULL, x); + return find_items_in_area(x, SP_GROUP(this->root), dkey, box, overlaps); } -GSList *SPDocument::getItemsAtPoints(unsigned const key, std::vector points) const +SelContainer SPDocument::getItemsAtPoints(unsigned const key, std::vector points) const { - GSList *items = NULL; + SelContainer items; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // When picking along the path, we don't want small objects close together @@ -1426,8 +1426,8 @@ GSList *SPDocument::getItemsAtPoints(unsigned const key, std::vector #include #include +#include "selection.h" namespace Avoid { class Router; @@ -232,7 +233,7 @@ public: /** * Returns the bottommost item from the list which is at the point, or NULL if none. */ - static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const GSList *list, Geom::Point const &p, bool take_insensitive = false); + static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const SelContainer &list, Geom::Point const &p, bool take_insensitive = false); static SPDocument *createDoc(Inkscape::XML::Document *rdoc, char const *uri, char const *base, char const *name, unsigned int keepalive, @@ -256,10 +257,10 @@ public: bool addResource(char const *key, SPObject *object); bool removeResource(char const *key, SPObject *object); const GSList *getResourceList(char const *key) const; - GSList *getItemsInBox(unsigned int dkey, Geom::Rect const &box) const; - GSList *getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const; + SelContainer getItemsInBox(unsigned int dkey, Geom::Rect const &box) const; + SelContainer getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const; SPItem *getItemAtPoint(unsigned int key, Geom::Point const &p, bool into_groups, SPItem *upto = NULL) const; - GSList *getItemsAtPoints(unsigned const key, std::vector points) const; + SelContainer getItemsAtPoints(unsigned const key, std::vector points) const; SPItem *getGroupAtPoint(unsigned int key, Geom::Point const &p) const; void changeUriAndHrefs(char const *uri); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index f20df1594..05711e734 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -442,10 +442,10 @@ static void add_ids_recursive(std::vector &ids, SPObject *obj) } } } - +/* bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b){ return sp_repr_compare_position(dynamic_cast(a),dynamic_cast(b)); -} +}*/ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) { @@ -2301,7 +2301,7 @@ sp_selection_move_screen(Inkscape::Selection *selection, gdouble dx, gdouble dy) namespace { template -SPItem *next_item(SPDesktop *desktop, SelContainer &path, SPObject *root, +SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive); template @@ -2481,19 +2481,18 @@ void sp_selection_edit_clip_or_mask(SPDesktop * /*dt*/, bool /*clip*/) namespace { template -SPItem *next_item_from_list(SPDesktop *desktop, GSList const *items, +SPItem *next_item_from_list(SPDesktop *desktop, SelContainer const items, SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) { SPObject *current=root; - while (items) { - SPItem *item = dynamic_cast(static_cast(items->data)); + for(SelContainer::const_iterator i = items.begin();i!=items.end();i++) { + SPItem *item = dynamic_cast(static_cast(*i)); if ( root->isAncestorOf(item) && ( !only_in_viewport || desktop->isWithinViewport(item) ) ) { current = item; break; } - items = items->next; } GSList *path=NULL; diff --git a/src/splivarot.h b/src/splivarot.h index ba314399f..79b9b98a6 100644 --- a/src/splivarot.h +++ b/src/splivarot.h @@ -10,6 +10,7 @@ #include <2geom/forward.h> #include <2geom/path.h> #include "livarot/Path.h" +#include "sp-object.h"//kill it class SPCurve; class SPDesktop; @@ -18,7 +19,7 @@ class SPItem; namespace Inkscape { class Selection; } - +bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b);//kill it with fire // boolean operations // work on the current selection // selection has 2 contain exactly 2 items diff --git a/src/trace/trace.cpp b/src/trace/trace.cpp index 892ecdb87..2becca5cc 100644 --- a/src/trace/trace.cpp +++ b/src/trace/trace.cpp @@ -74,13 +74,13 @@ SPImage *Tracer::getSelectedSPImage() them as bottom-to-top so that we can discover the image and any SPItems above it */ - for(SelContainer::const_iterator x=list.begin();x!=list.end();x++){ + for (SelContainer::const_iterator i=list.begin() ; list.end()!=i ; i++) { - if (!SP_IS_ITEM(*x)) + if (!SP_IS_ITEM(*i)) { continue; } - SPItem *item = SP_ITEM(*x); + SPItem *item = SP_ITEM(*i); items.insert(items.begin(), item); } std::vector::iterator iter; diff --git a/src/ui/dialog/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp index ae03bdf0e..625ed99b9 100644 --- a/src/ui/dialog/font-substitution.cpp +++ b/src/ui/dialog/font-substitution.cpp @@ -70,19 +70,15 @@ FontSubstitution::checkFontSubstitutions(SPDocument* doc) int show_dlg = prefs->getInt("/options/font/substitutedlg", 0); if (show_dlg) { Glib::ustring out; - GSList *l = getFontReplacedItems(doc, &out); + SelContainer l = getFontReplacedItems(doc, &out); if (out.length() > 0) { show(out, l); } - if (l) { - g_slist_free(l); - l = NULL; - } } } void -FontSubstitution::show(Glib::ustring out, GSList *l) +FontSubstitution::show(Glib::ustring out, SelContainer &l) { Gtk::MessageDialog warning(_("\nSome fonts are not available and have been substituted."), false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK, true); @@ -152,20 +148,18 @@ FontSubstitution::show(Glib::ustring out, GSList *l) * b. Build up a list of the objects rendered fonts - taken for the objects layout/spans * If there are fonts in a. that are not in b. then those fonts have been substituted. */ -GSList * FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring *out) +SelContainer FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring *out) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - GSList *allList = NULL; - GSList *outList = NULL; + SelContainer allList; + SelContainer outList,x,y; std::set setErrors; std::set setFontSpans; std::map mapFontStyles; - allList = get_all_items(NULL, doc->getRoot(), desktop, false, false, true, NULL); - - for (GSList *i = allList; i != NULL; i = i->next) { - - SPItem *item = SP_ITEM(i->data); + allList = get_all_items(x, doc->getRoot(), desktop, false, false, true, y); + for(SelContainer::const_iterator i = allList.begin();i!=allList.end();i++){ + SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; Glib::ustring family = ""; @@ -254,7 +248,7 @@ GSList * FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring * Glib::ustring err = Glib::ustring::compose( _("Font '%1' substituted with '%2'"), fonts.c_str(), subName.c_str()); setErrors.insert(err); - outList = g_slist_prepend (outList, item); + outList.push_front(item); } } diff --git a/src/ui/dialog/font-substitution.h b/src/ui/dialog/font-substitution.h index 1c445081b..eed7adcf2 100644 --- a/src/ui/dialog/font-substitution.h +++ b/src/ui/dialog/font-substitution.h @@ -13,7 +13,7 @@ #define INKSCAPE_UI_FONT_SUBSTITUTION_H #include - +#include "selection.h" class SPDocument; namespace Inkscape { @@ -25,13 +25,13 @@ public: FontSubstitution(); virtual ~FontSubstitution(); void checkFontSubstitutions(SPDocument* doc); - void show(Glib::ustring out, GSList *l); + void show(Glib::ustring out, SelContainer &l); static FontSubstitution &getInstance() { return *new FontSubstitution(); } Glib::ustring getSubstituteFontName (Glib::ustring font); protected: - GSList *getFontReplacedItems(SPDocument* doc, Glib::ustring *out); + SelContainer getFontReplacedItems(SPDocument* doc, Glib::ustring *out); private: FontSubstitution(FontSubstitution const &d); diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index d3ccb9bde..ba8616d9b 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -109,6 +109,13 @@ static int sp_compare_y_position(SPItem *first, SPItem *second) return 0; } +static bool sp_compare_y_position_obj(SPObject *first, SPObject *second){ + return sp_compare_y_position(static_cast(first),static_cast(second))<0; +} +static bool sp_compare_x_position_obj(SPObject *first, SPObject *second){ + return sp_compare_x_position(static_cast(first),static_cast(second))<0; +} + namespace Inkscape { namespace UI { @@ -168,10 +175,10 @@ void GridArrangeTab::arrange() desktop->getDocument()->ensureUpToDate(); Inkscape::Selection *selection = desktop->getSelection(); - const GSList *items = selection ? selection->itemList() : 0; + const SelContainer items = selection ? selection->itemList() : SelContainer(); cnt=0; - for (; items != NULL; items = items->next) { - SPItem *item = SP_ITEM(items->data); + for(SelContainer::const_iterator i = items.begin();i!=items.end();i++){ + SPItem *item = SP_ITEM(*i); Geom::OptRect b = item->documentVisualBounds(); if (!b) { continue; @@ -198,20 +205,19 @@ void GridArrangeTab::arrange() // require the sorting done before we can calculate row heights etc. g_return_if_fail(selection); - const GSList *items2 = selection->itemList(); - GSList *rev = g_slist_copy(const_cast(items2)); - GSList *sorted = NULL; - rev = g_slist_sort(rev, (GCompareFunc) sp_compare_y_position); - sorted = g_slist_sort(rev, (GCompareFunc) sp_compare_x_position); + SelContainer rev(selection->itemList()); + rev.sort(sp_compare_y_position_obj); + SelContainer sorted(rev); + sorted.sort(sp_compare_x_position_obj); // Calculate individual Row and Column sizes if necessary cnt=0; - const GSList *sizes = sorted; - for (; sizes != NULL; sizes = sizes->next) { - SPItem *item = SP_ITEM(sizes->data); + const SelContainer sizes(sorted); + for (SelContainer::const_iterator i = sizes.begin();i!=sizes.end();i++) { + SPItem *item = SP_ITEM(*i); Geom::OptRect b = item->documentVisualBounds(); if (b) { width = b->dimensions()[Geom::X]; @@ -308,12 +314,14 @@ g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_h } cnt=0; - for (row_cnt=0; ((sorted != NULL) && (row_cntdata); - sorted = sorted->next; + col_cnt = 0; + for(;it!=sorted.end()&&colnext) { @@ -374,8 +382,8 @@ void GridArrangeTab::on_row_spinbutton_changed() Inkscape::Selection *selection = desktop ? desktop->selection : 0; g_return_if_fail( selection ); - GSList const *items = selection->itemList(); - int selcount = g_slist_length((GSList *)items); + SelContainer const items = selection->itemList(); + int selcount = items.size(); double PerCol = ceil(selcount / NoOfColsSpinner.get_value()); NoOfRowsSpinner.set_value(PerCol); @@ -400,8 +408,7 @@ void GridArrangeTab::on_col_spinbutton_changed() Inkscape::Selection *selection = desktop ? desktop->selection : 0; g_return_if_fail(selection); - GSList const *items = selection->itemList(); - int selcount = g_slist_length((GSList *)items); + int selcount = selection->itemList().size(); double PerRow = ceil(selcount / NoOfRowsSpinner.get_value()); NoOfColsSpinner.set_value(PerRow); @@ -538,10 +545,10 @@ void GridArrangeTab::updateSelection() updating = true; SPDesktop *desktop = Parent->getDesktop(); Inkscape::Selection *selection = desktop ? desktop->selection : 0; - GSList const *items = selection ? selection->itemList() : 0; + SelContainer const items = selection ? selection->itemList() : SelContainer(); - if (items) { - int selcount = g_slist_length((GSList *)items); + if (!items.empty()) { + int selcount = items.size(); if (NoOfColsSpinner.get_value() > 1 && NoOfRowsSpinner.get_value() > 1){ // Update the number of rows assuming number of columns wanted remains same. @@ -609,8 +616,7 @@ GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) g_return_if_fail( selection ); int selcount = 1; if (!selection->isEmpty()) { - GSList const *items = selection->itemList(); - selcount = g_slist_length((GSList *)items); + selcount = selection->itemList().size(); } diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index b908a90cb..79e5b556d 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -366,16 +366,14 @@ void IconPreviewPanel::refreshPreview() if ( sel ) { //g_message("found a selection to play with"); - GSList const *items = sel->itemList(); - while ( items && !target ) { - SPItem* item = SP_ITEM( items->data ); + SelContainer const items = sel->itemList(); + for(SelContainer::const_iterator i=items.begin();!target && i!=items.end();i++){ + SPItem* item = SP_ITEM( *i); gchar const *id = item->getId(); if ( id ) { targetId = id; target = item; } - - items = g_slist_next(items); } } } diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp index c95529a56..0ae3027c7 100644 --- a/src/ui/dialog/objects.cpp +++ b/src/ui/dialog/objects.cpp @@ -479,15 +479,15 @@ void ObjectsPanel::_objectsSelected( Selection *sel ) { _selectedConnection.block(); _tree.get_selection()->unselect_all(); SPItem *item = NULL; - for (const GSList * iter = sel->itemList(); iter != NULL; iter = iter->next) - { - item = reinterpret_cast(iter->data); + SelContainer const items = sel->itemList(); + for(SelContainer::const_iterator i=items.begin(); i!=items.end();i++){ + item = reinterpret_cast(*i); if (setOpacity) { _setCompositingValues(item); setOpacity = false; } - _store->foreach(sigc::bind( sigc::mem_fun(*this, &ObjectsPanel::_checkForSelected), item, iter->next == NULL)); + _store->foreach(sigc::bind( sigc::mem_fun(*this, &ObjectsPanel::_checkForSelected), item, (*i)==items.back())); } if (!item) { if (_desktop->currentLayer() && SP_IS_ITEM(_desktop->currentLayer())) { diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index 5113f172a..273a378e5 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -372,12 +372,12 @@ void PixelArtDialogImpl::vectorize() return; } - for ( GSList const *list = desktop->selection->itemList() ; list - ; list = list->next ) { - if ( !SP_IS_IMAGE(list->data) ) + SelContainer const items = desktop->selection->itemList(); + for(SelContainer::const_iterator i=items.begin(); i!=items.end();i++){ + if ( !SP_IS_IMAGE(*i) ) continue; - SPImage *img = SP_IMAGE(list->data); + SPImage *img = SP_IMAGE(*i); Input input; input.pixbuf = Glib::wrap(img->pixbuf->getPixbufRaw(), true); input.x = img->x; diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index 281958998..8a382fc93 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -297,19 +297,18 @@ static void moveToPoint(int anchor, SPItem *item, Geom::Point p) void PolarArrangeTab::arrange() { Inkscape::Selection *selection = parent->getDesktop()->getSelection(); - const GSList *items, *tmp; - tmp = items = selection->itemList(); + const SelContainer tmp(selection->itemList()); SPGenericEllipse *referenceEllipse = NULL; // Last ellipse in selection bool arrangeOnEllipse = !arrangeOnParametersRadio.get_active(); bool arrangeOnFirstEllipse = arrangeOnEllipse && arrangeOnFirstCircleRadio.get_active(); int count = 0; - while(tmp) + for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++) { if(arrangeOnEllipse) { - SPItem *item = SP_ITEM(tmp->data); + SPItem *item = SP_ITEM(*i); if(arrangeOnFirstEllipse) { @@ -322,7 +321,6 @@ void PolarArrangeTab::arrange() referenceEllipse = SP_GENERICELLIPSE(item); } } - tmp = tmp->next; ++count; } @@ -374,11 +372,10 @@ void PolarArrangeTab::arrange() Geom::Point realCenter = Geom::Point(cx, cy) * transformation; - tmp = items; int i = 0; - while(tmp) + for(SelContainer::const_iterator it=tmp.begin();it!=tmp.end();it++) { - SPItem *item = SP_ITEM(tmp->data); + SPItem *item = SP_ITEM(*it); // Ignore the reference ellipse if any if(item != referenceEllipse) @@ -396,7 +393,6 @@ void PolarArrangeTab::arrange() ++i; } - tmp = tmp->next; } DocumentUndo::done(parent->getDesktop()->getDocument(), SP_VERB_SELECTION_ARRANGE, diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp index a015d28f9..dc98b6032 100644 --- a/src/ui/dialog/print.cpp +++ b/src/ui/dialog/print.cpp @@ -81,7 +81,7 @@ static void draw_page( width, height, (unsigned long)(Inkscape::Util::Quantity::convert(width, "px", "in") * dpi), (unsigned long)(Inkscape::Util::Quantity::convert(height, "px", "in") * dpi), - dpi, dpi, bgcolor, NULL, NULL, true, NULL); + dpi, dpi, bgcolor, NULL, NULL, true, SelContainer()); // This doesn't seem to work: //context->set_cairo_context ( Cairo::Context::create (Cairo::ImageSurface::create_from_png (tmp_png) ), dpi, dpi ); diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index bc228633d..8f5601e3a 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -524,7 +524,7 @@ void SvgFontsDialog::set_glyph_description_from_selected_path(){ return; } - Inkscape::XML::Node* node = (Inkscape::XML::Node*) g_slist_nth_data((GSList *)sel->reprList(), 0); + Inkscape::XML::Node* node = (Inkscape::XML::Node*)(sel->reprList().front()); if (!node) return;//TODO: should this be an assert? if (!node->matchAttributeName("d") || !node->attribute("d")){ char *msg = _("The selected object does not have a path description."); @@ -566,7 +566,7 @@ void SvgFontsDialog::missing_glyph_description_from_selected_path(){ return; } - Inkscape::XML::Node* node = (Inkscape::XML::Node*) g_slist_nth_data((GSList *)sel->reprList(), 0); + Inkscape::XML::Node* node = (Inkscape::XML::Node*)(sel->reprList().front()); if (!node) return;//TODO: should this be an assert? if (!node->matchAttributeName("d") || !node->attribute("d")){ char *msg = _("The selected object does not have a path description."); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 8759039c3..da24ad605 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -123,10 +123,10 @@ static void editGradientImpl( SPDesktop* desktop, SPGradient* gr ) bool shown = false; if ( desktop && desktop->doc() ) { Inkscape::Selection *selection = desktop->getSelection(); - GSList const *items = selection->itemList(); - if (items) { + SelContainer const items = selection->itemList(); + if (!items.empty()) { SPStyle query( desktop->doc() ); - int result = objects_query_fillstroke(const_cast(items), &query, true); + int result = objects_query_fillstroke((items), &query, true); if ( (result == QUERY_STYLE_MULTIPLE_SAME) || (result == QUERY_STYLE_SINGLE) ) { // could be pertinent if (query.fill.isPaintserver()) { diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index 8a104d137..ba3a6b914 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -371,9 +371,10 @@ void TagsPanel::_objectsSelected( Selection *sel ) { _selectedConnection.block(); _tree.get_selection()->unselect_all(); - for (const GSList * iter = sel->list(); iter != NULL; iter = iter->next) + SelContainer tmp=sel->list(); + for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++) { - SPObject *obj = reinterpret_cast(iter->data); + SPObject *obj = reinterpret_cast(*i); _store->foreach(sigc::bind( sigc::mem_fun(*this, &TagsPanel::_checkForSelected), obj)); } _selectedConnection.unblock(); @@ -668,9 +669,9 @@ bool TagsPanel::_handleButtonEvent(GdkEventButton* event) if (col == _tree.get_column(COL_ADD - 1) && down_at_add) { if (SP_IS_TAG(obj)) { bool wasadded = false; - for (const GSList * iter = _desktop->selection->itemList(); iter != NULL; iter = iter->next) - { - SPObject *newobj = reinterpret_cast(iter->data); + SelContainer items=_desktop->selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *newobj = reinterpret_cast(*i); bool addchild = true; for ( SPObject *child = obj->children; child != NULL; child = child->next) { if (SP_IS_TAG_USE(child) && SP_TAG_USE(child)->ref->getObject() == newobj) { diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index a8be8b543..593261ec5 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -418,12 +418,11 @@ SPItem *TextEdit::getSelectedTextItem (void) if (!SP_ACTIVE_DESKTOP) return NULL; - for (const GSList *item = SP_ACTIVE_DESKTOP->getSelection()->itemList(); - item != NULL; - item = item->next) + SelContainer tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++) { - if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) - return SP_ITEM (item->data); + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) + return SP_ITEM (*i); } return NULL; @@ -437,11 +436,10 @@ unsigned TextEdit::getSelectedTextCount (void) unsigned int items = 0; - for (const GSList *item = SP_ACTIVE_DESKTOP->getSelection()->itemList(); - item != NULL; - item = item->next) + SelContainer tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++) { - if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) ++items; } @@ -542,20 +540,20 @@ void TextEdit::onApply() SPDesktop *desktop = SP_ACTIVE_DESKTOP; unsigned items = 0; - const GSList *item_list = desktop->getSelection()->itemList(); + const SelContainer item_list = desktop->getSelection()->itemList(); SPCSSAttr *css = fillTextStyle (); sp_desktop_set_style(desktop, css, true); - for (; item_list != NULL; item_list = item_list->next) { + for(SelContainer::const_iterator i=item_list.begin();i!=item_list.end();i++){ // apply style to the reprs of all text objects in the selection - if (SP_IS_TEXT (item_list->data)) { + if (SP_IS_TEXT (*i)) { // backwards compatibility: - reinterpret_cast(item_list->data)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); + reinterpret_cast(*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); ++items; } - else if (SP_IS_FLOWTEXT (item_list->data)) + else if (SP_IS_FLOWTEXT (*i)) // no need to set sodipodi:linespacing, because Inkscape never supported it on flowtext ++items; } diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 233d99750..8c52144e0 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -655,7 +655,7 @@ void Transformation::updatePageTransform(Inkscape::Selection *selection) { if (selection && !selection->isEmpty()) { if (_check_replace_matrix.get_active()) { - Geom::Affine current (SP_ITEM(selection->itemList()->data)->transform); // take from the first item in selection + Geom::Affine current (SP_ITEM(selection->itemList().front())->transform); // take from the first item in selection Geom::Affine new_displayed = current; @@ -741,19 +741,19 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) if (_check_move_relative.get_active()) { // shift each object relatively to the previous one using Inkscape::Util::GSListConstIterator; - std::list selected; - selected.insert >(selected.end(), selection->itemList(), NULL); + SelContainer selected(selection->itemList()); if (selected.empty()) return; if (fabs(x) > 1e-6) { std::vector< BBoxSort > sorted; - for (std::list::iterator it(selected.begin()); + for (SelContainer::iterator it(selected.begin()); it != selected.end(); ++it) { - Geom::OptRect bbox = (*it)->desktopPreferredBounds(); + SPItem* item=static_cast(*it); + Geom::OptRect bbox = (item)->desktopPreferredBounds(); if (bbox) { - sorted.push_back(BBoxSort(*it, *bbox, Geom::X, x > 0? 1. : 0., x > 0? 0. : 1.)); + sorted.push_back(BBoxSort(item, *bbox, Geom::X, x > 0? 1. : 0., x > 0? 0. : 1.)); } } //sort bbox by anchors @@ -771,13 +771,14 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) } if (fabs(y) > 1e-6) { std::vector< BBoxSort > sorted; - for (std::list::iterator it(selected.begin()); + for (SelContainer::iterator it(selected.begin()); it != selected.end(); ++it) { - Geom::OptRect bbox = (*it)->desktopPreferredBounds(); + SPItem* item=static_cast(*it); + Geom::OptRect bbox = (item)->desktopPreferredBounds(); if (bbox) { - sorted.push_back(BBoxSort(*it, *bbox, Geom::Y, y > 0? 1. : 0., y > 0? 0. : 1.)); + sorted.push_back(BBoxSort(item, *bbox, Geom::Y, y > 0? 1. : 0., y > 0? 0. : 1.)); } } //sort bbox by anchors @@ -815,8 +816,9 @@ void Transformation::applyPageScale(Inkscape::Selection *selection) bool transform_stroke = prefs->getBool("/options/transform/stroke", true); bool preserve = prefs->getBool("/options/preservetransform/value", false); if (prefs->getBool("/dialogs/transformation/applyseparately")) { - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = SP_ITEM(l->data); + SelContainer tmp=selection->itemList(); + for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++){ + SPItem *item = SP_ITEM(*i); Geom::OptRect bbox_pref = item->desktopPreferredBounds(); Geom::OptRect bbox_geom = item->desktopGeometricBounds(); if (bbox_pref && bbox_geom) { @@ -878,8 +880,9 @@ void Transformation::applyPageRotate(Inkscape::Selection *selection) } if (prefs->getBool("/dialogs/transformation/applyseparately")) { - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = SP_ITEM(l->data); + SelContainer tmp=selection->itemList(); + for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++){ + SPItem *item = SP_ITEM(*i); sp_item_rotate_rel(item, Geom::Rotate (angle*M_PI/180.0)); } } else { @@ -897,8 +900,9 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/dialogs/transformation/applyseparately")) { - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = SP_ITEM(l->data); + SelContainer items=selection->itemList(); + for(SelContainer::const_iterator i = items.begin();i!=items.end();i++){ + SPItem *item = SP_ITEM(*i); if (!_units_skew.isAbsolute()) { // percentage double skewX = _scalar_skew_horizontal.getValue("%"); @@ -998,8 +1002,9 @@ void Transformation::applyPageTransform(Inkscape::Selection *selection) } if (_check_replace_matrix.get_active()) { - for (GSList const *l = selection->itemList(); l != NULL; l = l->next) { - SPItem *item = SP_ITEM(l->data); + SelContainer tmp=selection->itemList(); + for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++){ + SPItem *item = SP_ITEM(*i); item->set_item_transform(displayed); SP_OBJECT(item)->updateRepr(); } @@ -1150,7 +1155,7 @@ void Transformation::onReplaceMatrixToggled() double f = _scalar_transform_f.getValue(); Geom::Affine displayed (a, b, c, d, e, f); - Geom::Affine current = SP_ITEM(selection->itemList()->data)->transform; // take from the first item in selection + Geom::Affine current = SP_ITEM(selection->itemList().front())->transform; // take from the first item in selection Geom::Affine new_displayed; if (_check_replace_matrix.get_active()) { diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 26a4eadd5..fc40c20e7 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -1313,12 +1313,12 @@ void cc_selection_set_avoid(bool const set_avoid) Inkscape::Selection *selection = desktop->getSelection(); - GSList *l = const_cast(selection->itemList()); int changes = 0; - while (l) { - SPItem *item = SP_ITEM(l->data); + SelContainer l = selection->itemList(); + for(SelContainer::const_iterator i=l.begin();i!=l.end();i++) { + SPItem *item = SP_ITEM(*i); char const *value = (set_avoid) ? "true" : NULL; @@ -1327,8 +1327,6 @@ void cc_selection_set_avoid(bool const set_avoid) item->avoidRef->handleSettingChange(); changes++; } - - l = l->next; } if (changes == 0) { diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 1b4dcfe25..3526e015a 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -676,7 +676,7 @@ void EraserTool::set_to_accumulated() { Geom::OptRect eraserBbox = acid->visualBounds(); Geom::Rect bounds = (*eraserBbox) * desktop->doc2dt(); std::vector remainingItems; - GSList* toWorkOn = 0; + SelContainer toWorkOn; if (selection->isEmpty()) { if ( eraserMode ) { @@ -686,16 +686,16 @@ void EraserTool::set_to_accumulated() { toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); } - toWorkOn = g_slist_remove( toWorkOn, acid ); + toWorkOn.remove(static_cast(acid) ); } else { - toWorkOn = g_slist_copy(const_cast(selection->itemList())); + toWorkOn = selection->itemList(); wasSelection = true; } - if ( g_slist_length(toWorkOn) > 0 ) { + if ( !toWorkOn.empty() ) { if ( eraserMode ) { - for (GSList *i = toWorkOn ; i ; i = i->next ) { - SPItem *item = SP_ITEM(i->data); + for (SelContainer::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + SPItem *item = SP_ITEM(*i); if ( eraserMode ) { Geom::OptRect bbox = item->visualBounds(); @@ -712,13 +712,10 @@ void EraserTool::set_to_accumulated() { if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. - GSList *nowSel = g_slist_copy(const_cast(selection->itemList())); - - for (GSList const *i2 = nowSel ; i2 ; i2 = i2->next ) { - remainingItems.push_back(SP_ITEM(i2->data)); + SelContainer nowSel(selection->itemList()); + for (SelContainer::const_iterator i2 = nowSel.begin();i!=nowSel.end();i++) { + remainingItems.push_back(SP_ITEM(*i2)); } - - g_slist_free(nowSel); } } else { remainingItems.push_back(item); @@ -726,20 +723,18 @@ void EraserTool::set_to_accumulated() { } } } else { - for (GSList *i = toWorkOn ; i ; i = i->next ) { - sp_object_ref( SP_ITEM(i->data), 0 ); + for (SelContainer::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + sp_object_ref( SP_ITEM(*i), 0 ); } - for (GSList *i = toWorkOn ; i ; i = i->next ) { - SPItem *item = SP_ITEM(i->data); + for (SelContainer::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + SPItem *item = SP_ITEM(*i); item->deleteObject(true); sp_object_unref(item); workDone = true; } } - g_slist_free(toWorkOn); - if ( !eraserMode ) { //sp_selection_delete(desktop); remainingItems.clear(); diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 5da30da7b..d1db5fb93 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -116,7 +116,7 @@ void GradientTool::selection_changed(Inkscape::Selection*) { if (selection == NULL) { return; } - guint n_obj = g_slist_length((GSList *) selection->itemList()); + guint n_obj = selection->itemList().size(); if (!drag->isNonEmpty() || selection->isEmpty()) return; @@ -502,10 +502,11 @@ bool GradientTool::root_handler(GdkEvent* event) { if (over_line) { // we take the first item in selection, because with doubleclick, the first click // always resets selection to the single object under cursor - sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->itemList()->data), this->mousepoint_doc, event->button.time); + sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->itemList().front()), this->mousepoint_doc, event->button.time); } else { - for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { - SPItem *item = SP_ITEM(i->data); + SelContainer items=selection->itemList(); + for (SelContainer::const_iterator i = items.begin();i!=items.end();i++) { + SPItem *item = SP_ITEM(*i); SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR); Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; @@ -889,6 +890,12 @@ bool GradientTool::root_handler(GdkEvent* event) { return ret; } +int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *second) +{ + return sp_repr_compare_position(((SPItem*)first)->getRepr(), + ((SPItem*)second)->getRepr())<0; +} + static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*state*/, guint32 etime) { SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop; @@ -908,32 +915,32 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta } else { // Starting from empty space: // Sort items so that the topmost comes last - GSList *items = g_slist_copy ((GSList *) selection->itemList()); - items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); + SelContainer items(selection->itemList()); + items.sort(sp_item_repr_compare_position_obj); // take topmost - vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(g_slist_last(items)->data), fill_or_stroke); - g_slist_free (items); + vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke); } // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); - for (GSList const *i = selection->itemList(); i != NULL; i = i->next) { + SelContainer itemlist = selection->itemList(); + for (SelContainer::const_iterator i = itemlist.begin();i!=itemlist.end();i++) { //FIXME: see above - sp_repr_css_change_recursive(SP_OBJECT(i->data)->getRepr(), css, "style"); + sp_repr_css_change_recursive(SP_OBJECT(*i)->getRepr(), css, "style"); - sp_item_set_gradient(SP_ITEM(i->data), vector, (SPGradientType) type, fill_or_stroke); + sp_item_set_gradient(SP_ITEM(*i), vector, (SPGradientType) type, fill_or_stroke); if (type == SP_GRADIENT_TYPE_LINEAR) { - sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_LG_BEGIN, 0, rc.origin, fill_or_stroke, true, false); - sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_LG_END, 0, pt, fill_or_stroke, true, false); + sp_item_gradient_set_coords (SP_ITEM(*i), POINT_LG_BEGIN, 0, rc.origin, fill_or_stroke, true, false); + sp_item_gradient_set_coords (SP_ITEM(*i), POINT_LG_END, 0, pt, fill_or_stroke, true, false); } else if (type == SP_GRADIENT_TYPE_RADIAL) { - sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_RG_CENTER, 0, rc.origin, fill_or_stroke, true, false); - sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_RG_R1, 0, pt, fill_or_stroke, true, false); + sp_item_gradient_set_coords (SP_ITEM(*i), POINT_RG_CENTER, 0, rc.origin, fill_or_stroke, true, false); + sp_item_gradient_set_coords (SP_ITEM(*i), POINT_RG_R1, 0, pt, fill_or_stroke, true, false); } - SP_OBJECT(i->data)->requestModified(SP_OBJECT_MODIFIED_FLAG); + SP_OBJECT(*i)->requestModified(SP_OBJECT_MODIFIED_FLAG); } if (ec->_grdrag) { ec->_grdrag->updateDraggers(); @@ -942,7 +949,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta ec->_grdrag->local_change = true; // give the grab out-of-bounds values of xp/yp because we're already dragging // and therefore are already out of tolerance - ec->_grdrag->grabKnot (SP_ITEM(selection->itemList()->data), + ec->_grdrag->grabKnot (SP_ITEM(selection->itemList().front()), type == SP_GRADIENT_TYPE_LINEAR? POINT_LG_END : POINT_RG_R1, -1, // ignore number (though it is always 1) fill_or_stroke, 99999, 99999, etime); @@ -951,7 +958,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta // status text; we do not track coords because this branch is run once, not all the time // during drag - int n_objects = g_slist_length((GSList *) selection->itemList()); + int n_objects = selection->itemList().size(); rc.message_context->setF(Inkscape::NORMAL_MESSAGE, ngettext("Gradient for %d object; with Ctrl to snap angle", "Gradient for %d objects; with Ctrl to snap angle", n_objects), diff --git a/src/ui/tools/gradient-tool.h b/src/ui/tools/gradient-tool.h index 6fe3bca9f..786aed372 100644 --- a/src/ui/tools/gradient-tool.h +++ b/src/ui/tools/gradient-tool.h @@ -18,6 +18,7 @@ #include #include #include "ui/tools/tool-base.h" +class SPObject;//kill it #define SP_GRADIENT_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_GRADIENT_CONTEXT(obj) (dynamic_cast((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) @@ -25,12 +26,12 @@ namespace Inkscape { namespace UI { namespace Tools { +int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *second);//kill it class GradientTool : public ToolBase { public: GradientTool(); virtual ~GradientTool(); - Geom::Point origin; bool cursor_addnode; diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index c9b656397..ce0ad7a9a 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -407,10 +407,10 @@ lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection) SPCanvasGroup *tmpgrp = lc->desktop->getTempGroup(); gchar *arc_length; double lengthval; - - for (GSList const *i = selection->itemList(); i != NULL; i = i->next) { - if (SP_IS_PATH(i->data)) { - path = SP_PATH(i->data); + SelContainer items=selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_PATH(*i)) { + path = SP_PATH(*i); curve = path->getCurve(); Geom::Piecewise > pwd2 = paths_to_pw(curve->get_pathvector()); canvas_text = (SPCanvasText *) sp_canvastext_new(tmpgrp, lc->desktop, Geom::Point(0,0), ""); diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index b7e54b9c8..8d52210ff 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -441,10 +441,10 @@ bool MeasureTool::root_handler(GdkEvent* event) { // TODO switch to a different variable name. The single letter 'l' is easy to misread. //select elements crossed by line segment: - GSList *items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points); + SelContainer items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points); std::vector intersection_times; - for (GSList *l = items; l != NULL; l = l->next) { - SPItem *item = static_cast(l->data); + for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + SPItem *item = static_cast(*i); if (SP_IS_SHAPE(item)) { calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index d333b932e..1cc06a5b9 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -48,6 +48,7 @@ // Mesh specific #include "ui/tools/mesh-tool.h" +#include "ui/tools/gradient-tool.h"//not needed #include "sp-mesh-gradient.h" #include "display/sp-ctrlcurve.h" @@ -113,7 +114,7 @@ void MeshTool::selection_changed(Inkscape::Selection* /*sel*/) { return; } - guint n_obj = g_slist_length((GSList *) selection->itemList()); + guint n_obj = selection->itemList().size(); if (!drag->isNonEmpty() || selection->isEmpty()) { return; @@ -477,11 +478,12 @@ bool MeshTool::root_handler(GdkEvent* event) { if (over_line) { // We take the first item in selection, because with doubleclick, the first click // always resets selection to the single object under cursor - sp_mesh_context_split_near_point(this, SP_ITEM(selection->itemList()->data), this->mousepoint_doc, event->button.time); + sp_mesh_context_split_near_point(this, SP_ITEM(selection->itemList().front()), this->mousepoint_doc, event->button.time); } else { // Create a new gradient with default coordinates. - for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { - SPItem *item = SP_ITEM(i->data); + SelContainer items=selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = SP_ITEM(*i); SPGradientType new_type = SP_GRADIENT_TYPE_MESH; Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; @@ -930,6 +932,12 @@ bool MeshTool::root_handler(GdkEvent* event) { return ret; } +/* +int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *second) +{ + return sp_repr_compare_position(((SPItem*)first)->getRepr(), + ((SPItem*)second)->getRepr())<0; +}*/ static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/, guint32 /*etime*/) { SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop; @@ -950,27 +958,27 @@ static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/ } else { // Starting from empty space: // Sort items so that the topmost comes last - GSList *items = g_slist_copy ((GSList *) selection->itemList()); - items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); + SelContainer items(selection->itemList()); + items.sort(sp_item_repr_compare_position_obj); // take topmost - vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(g_slist_last(items)->data), fill_or_stroke); - g_slist_free (items); + vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke); } // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); - for (GSList const *i = selection->itemList(); i != NULL; i = i->next) { + SelContainer items=selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above - sp_repr_css_change_recursive(SP_OBJECT(i->data)->getRepr(), css, "style"); + sp_repr_css_change_recursive(SP_OBJECT(*i)->getRepr(), css, "style"); - sp_item_set_gradient(SP_ITEM(i->data), vector, (SPGradientType) type, fill_or_stroke); + sp_item_set_gradient(SP_ITEM(*i), vector, (SPGradientType) type, fill_or_stroke); // We don't need to do anything. Mesh is already sized appropriately. - SP_OBJECT(i->data)->requestModified(SP_OBJECT_MODIFIED_FLAG); + SP_OBJECT(*i)->requestModified(SP_OBJECT_MODIFIED_FLAG); } // if (ec->_grdrag) { // ec->_grdrag->updateDraggers(); @@ -988,7 +996,7 @@ static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/ // status text; we do not track coords because this branch is run once, not all the time // during drag - int n_objects = g_slist_length((GSList *) selection->itemList()); + int n_objects = selection->itemList().size(); rc.message_context->setF(Inkscape::NORMAL_MESSAGE, ngettext("Gradient for %d object; with Ctrl to snap angle", "Gradient for %d objects; with Ctrl to snap angle", n_objects), diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index caec901a6..46c978c84 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -420,10 +420,9 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) { std::set shapes; - GSList const *ilist = sel->itemList(); - - for (GSList *i = const_cast(ilist); i; i = i->next) { - SPObject *obj = static_cast(i->data); + SelContainer items=sel->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *obj = static_cast(*i); if (SP_IS_ITEM(obj)) { gather_items(this, NULL, static_cast(obj), SHAPE_ROLE_NORMAL, shapes); @@ -668,9 +667,8 @@ void NodeTool::select_area(Geom::Rect const &sel, GdkEventButton *event) { if (this->_multipath->empty()) { // if multipath is empty, select rubberbanded items rather than nodes Inkscape::Selection *selection = this->desktop->selection; - GSList *items = this->desktop->getDocument()->getItemsInBox(this->desktop->dkey, sel); + SelContainer items = this->desktop->getDocument()->getItemsInBox(this->desktop->dkey, sel); selection->setList(items); - g_slist_free(items); } else { if (!held_shift(*event)) { this->_selected_nodes->clear(); diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 939b1a0b3..f84170631 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -481,7 +481,7 @@ bool SelectTool::root_handler(GdkEvent* event) { case GDK_2BUTTON_PRESS: if (event->button.button == 1) { if (!selection->isEmpty()) { - SPItem *clicked_item = static_cast(selection->itemList()->data); + SPItem *clicked_item = static_cast(selection->itemList().front()); if (dynamic_cast(clicked_item) && !dynamic_cast(clicked_item)) { // enter group if it's not a 3D box desktop->setCurrentLayer(clicked_item); @@ -718,7 +718,7 @@ bool SelectTool::root_handler(GdkEvent* event) { if (r->is_started() && !within_tolerance) { // this was a rubberband drag - GSList *items = NULL; + SelContainer items; if (r->getMode() == RUBBERBAND_MODE_RECT) { Geom::OptRect const b = r->getRectangle(); @@ -739,7 +739,6 @@ bool SelectTool::root_handler(GdkEvent* event) { selection->setList (items); } - g_slist_free (items); } else { // it was just a click, or a too small rubberband r->stop(); diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index a01c5c55b..d339f6d19 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -188,7 +188,7 @@ void SprayTool::update_cursor(bool /*with_shift*/) { gchar *sel_message = NULL; if (!desktop->selection->isEmpty()) { - num = g_slist_length(const_cast(desktop->selection->itemList())); + num = desktop->selection->itemList().size(); sel_message = g_strdup_printf(ngettext("%i object selected","%i objects selected",num), num); } else { sel_message = g_strdup_printf("%s", _("Nothing selected")); @@ -436,11 +436,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPItem *unionResult = NULL; // Previous union int i=1; - for (GSList *items = g_slist_copy(const_cast(selection->itemList())); - items != NULL; - items = items->next) { - - SPItem *item1 = dynamic_cast(static_cast(items->data)); + SelContainer items=selection->itemList(); + for(SelContainer::const_iterator it=items.begin();it!=items.end();it++){ + SPItem *item1 = dynamic_cast(static_cast(*it)); if (i == 1) { parent_item = item1; } @@ -552,20 +550,16 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point double move_standard_deviation = get_move_standard_deviation(tc); { - GSList *const original_selection = g_slist_copy(const_cast(selection->itemList())); + SelContainer const items(selection->itemList()); - for (GSList *items = original_selection; - items != NULL; - items = items->next) { - SPItem *item = dynamic_cast(static_cast(items->data)); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = dynamic_cast(static_cast(*i)); g_assert(item != NULL); sp_object_ref(item); } - for (GSList *items = original_selection; - items != NULL; - items = items->next) { - SPItem *item = dynamic_cast(static_cast(items->data)); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = dynamic_cast(static_cast(*i)); g_assert(item != NULL); if (is_transform_modes(tc->mode)) { @@ -579,10 +573,8 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point } } - for (GSList *items = original_selection; - items != NULL; - items = items->next) { - SPItem *item = dynamic_cast(static_cast(items->data)); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = dynamic_cast(static_cast(*i)); g_assert(item != NULL); sp_object_unref(item); } @@ -658,7 +650,7 @@ bool SprayTool::root_handler(GdkEvent* event) { guint num = 0; if (!desktop->selection->isEmpty()) { - num = g_slist_length(const_cast(desktop->selection->itemList())); + num = desktop->selection->itemList().size(); } if (num == 0) { this->message_context->flash(Inkscape::ERROR_MESSAGE, _("Nothing selected! Select objects to spray.")); diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index df0583d67..a4370256d 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -1470,7 +1470,7 @@ int TextTool::_styleQueried(SPStyle *style, int property) } sp_text_context_validate_cursor_iterators(this); - GSList *styles_list = NULL; + SelContainer styles_list; Inkscape::Text::Layout::iterator begin_it, end_it; if (this->text_sel_start < this->text_sel_end) { @@ -1486,7 +1486,7 @@ int TextTool::_styleQueried(SPStyle *style, int property) } } for (Inkscape::Text::Layout::iterator it = begin_it ; it < end_it ; it.nextStartOfSpan()) { - SPObject const *pos_obj = 0; + SPObject *pos_obj = 0; void *rawptr = 0; layout->getSourceOfCharacter(it, &rawptr); if (!rawptr || !SP_IS_OBJECT(rawptr)) { @@ -1496,12 +1496,11 @@ int TextTool::_styleQueried(SPStyle *style, int property) while (SP_IS_STRING(pos_obj) && pos_obj->parent) { pos_obj = pos_obj->parent; // SPStrings don't have style } - styles_list = g_slist_prepend(styles_list, (gpointer)pos_obj); + styles_list.push_front(pos_obj); } int result = sp_desktop_query_style_from_list (styles_list, style, property); - g_slist_free(styles_list); return result; } diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index a07f2fb86..cc05f9775 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -1178,11 +1178,9 @@ SPItem *sp_event_context_find_item(SPDesktop *desktop, Geom::Point const &p, SPItem * sp_event_context_over_item(SPDesktop *desktop, SPItem *item, Geom::Point const &p) { - GSList *temp = NULL; - temp = g_slist_prepend(temp, item); + SelContainer temp; + temp.push_front(static_cast(item)); SPItem *item_at_point = desktop->getItemFromListAtPointBottom(temp, p); - g_slist_free(temp); - return item_at_point; } diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 5e53fdb93..9342127ce 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -163,7 +163,7 @@ void TweakTool::update_cursor (bool with_shift) { gchar *sel_message = NULL; if (!desktop->selection->isEmpty()) { - num = g_slist_length(const_cast(desktop->selection->itemList())); + num = desktop->selection->itemList().size(); sel_message = g_strdup_printf(ngettext("%i object selected","%i objects selected",num), num); } else { sel_message = g_strdup_printf("%s", _("Nothing selected")); @@ -382,14 +382,13 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P } if (dynamic_cast(item) || dynamic_cast(item)) { - GSList *items = g_slist_prepend (NULL, item); - GSList *selected = NULL; - GSList *to_select = NULL; + SelContainer items; + items.push_back(item); + SelContainer selected; + SelContainer to_select; SPDocument *doc = item->document; - sp_item_list_to_curves (items, &selected, &to_select); - g_slist_free (items); - SPObject* newObj = doc->getObjectByRepr(static_cast(to_select->data)); - g_slist_free (to_select); + sp_item_list_to_curves (items, selected, to_select); + SPObject* newObj = doc->getObjectByRepr(dynamic_cast(to_select.front())); item = dynamic_cast(newObj); g_assert(item != NULL); selection->add(item); @@ -1088,11 +1087,9 @@ sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point double move_force = get_move_force(tc); double color_force = MIN(sqrt(path_force)/20.0, 1); - for (GSList *items = g_slist_copy(const_cast(selection->itemList())); - items != NULL; - items = items->next) { - - SPItem *item = dynamic_cast(static_cast(items->data)); + SelContainer items=selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = dynamic_cast(static_cast(*i)); if (is_color_mode (tc->mode)) { if (do_fill || do_stroke || do_opacity) { @@ -1199,7 +1196,7 @@ bool TweakTool::root_handler(GdkEvent* event) { guint num = 0; if (!desktop->selection->isEmpty()) { - num = g_slist_length(const_cast(desktop->selection->itemList())); + num = desktop->selection->itemList().size(); } if (num == 0) { this->message_context->flash(Inkscape::ERROR_MESSAGE, _("Nothing selected! Select objects to tweak.")); diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp index 00a74c4fe..ddf67fb5b 100644 --- a/src/ui/widget/object-composite-settings.cpp +++ b/src/ui/widget/object-composite-settings.cpp @@ -125,7 +125,8 @@ ObjectCompositeSettings::_blendBlurValueChanged() const Glib::ustring blendmode = _fe_cb.get_blend_mode(); //apply created filter to every selected item - for (StyleSubject::iterator i = _subject->begin() ; i != _subject->end() ; ++i ) { + SelContainer sel=_subject->getDesktop()->getSelection()->itemList(); + for (SelContainer::const_iterator i = sel.begin() ; i != sel.end() ; ++i ) { if (!SP_IS_ITEM(*i)) { continue; } diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp index a48370d9b..9d09e67d3 100644 --- a/src/ui/widget/style-subject.cpp +++ b/src/ui/widget/style-subject.cpp @@ -54,7 +54,7 @@ Inkscape::Selection *StyleSubject::Selection::_getSelection() const { return NULL; } } - +/* StyleSubject::iterator StyleSubject::Selection::begin() { Inkscape::Selection *selection = _getSelection(); if (selection) { @@ -62,7 +62,7 @@ StyleSubject::iterator StyleSubject::Selection::begin() { } else { return iterator(NULL); } -} +}*/ Geom::OptRect StyleSubject::Selection::getBounds(SPItem::BBoxType type) { Inkscape::Selection *selection = _getSelection(); @@ -104,8 +104,7 @@ void StyleSubject::Selection::setCSS(SPCSSAttr *css) { } StyleSubject::CurrentLayer::CurrentLayer() { - _element.data = NULL; - _element.next = NULL; + _element = NULL; } StyleSubject::CurrentLayer::~CurrentLayer() { @@ -114,10 +113,10 @@ StyleSubject::CurrentLayer::~CurrentLayer() { void StyleSubject::CurrentLayer::_setLayer(SPObject *layer) { _layer_release.disconnect(); _layer_modified.disconnect(); - if (_element.data) { - sp_object_unref(static_cast(_element.data), NULL); + if (_element) { + sp_object_unref(static_cast(_element), NULL); } - _element.data = layer; + _element = layer; if (layer) { sp_object_ref(layer, NULL); _layer_release = layer->connectRelease(sigc::hide(sigc::bind(sigc::mem_fun(*this, &CurrentLayer::_setLayer), (SPObject *)NULL))); @@ -127,20 +126,17 @@ void StyleSubject::CurrentLayer::_setLayer(SPObject *layer) { } SPObject *StyleSubject::CurrentLayer::_getLayer() const { - return static_cast(_element.data); + return static_cast(_element); } -GSList *StyleSubject::CurrentLayer::_getLayerSList() const { - if (_element.data) { - return &_element; - } else { - return NULL; - } -} +SPObject *StyleSubject::CurrentLayer::_getLayerSList() const { + return _element; +} +/* StyleSubject::iterator StyleSubject::CurrentLayer::begin() { return iterator(_getLayerSList()); -} +}*/ Geom::OptRect StyleSubject::CurrentLayer::getBounds(SPItem::BBoxType type) { SPObject *layer = _getLayer(); @@ -152,8 +148,10 @@ Geom::OptRect StyleSubject::CurrentLayer::getBounds(SPItem::BBoxType type) { } int StyleSubject::CurrentLayer::queryStyle(SPStyle *query, int property) { - GSList *list = _getLayerSList(); - if (list) { + SelContainer list; + SPObject* i=_getLayerSList(); + if (i) { + list.push_back(i); return sp_desktop_query_style_from_list(list, query, property); } else { return QUERY_STYLE_NOTHING; diff --git a/src/ui/widget/style-subject.h b/src/ui/widget/style-subject.h index 47da91732..60f979eb0 100644 --- a/src/ui/widget/style-subject.h +++ b/src/ui/widget/style-subject.h @@ -35,7 +35,8 @@ public: class Selection; class CurrentLayer; - typedef Util::GSListConstIterator iterator; + //typedef Util::GSListConstIterator iterator; + typedef std::list::iterator iterator; StyleSubject(); virtual ~StyleSubject(); @@ -43,8 +44,8 @@ public: void setDesktop(SPDesktop *desktop); SPDesktop *getDesktop() const { return _desktop; } - virtual iterator begin() = 0; - virtual iterator end() { return iterator(NULL); } +// virtual iterator begin() = 0; +// virtual iterator end() { return iterator(NULL); } virtual Geom::OptRect getBounds(SPItem::BBoxType type) = 0; virtual int queryStyle(SPStyle *query, int property) = 0; virtual void setCSS(SPCSSAttr *css) = 0; @@ -67,7 +68,7 @@ public: Selection(); ~Selection(); - virtual iterator begin(); +// virtual iterator begin(); virtual Geom::OptRect getBounds(SPItem::BBoxType type); virtual int queryStyle(SPStyle *query, int property); virtual void setCSS(SPCSSAttr *css); @@ -88,7 +89,7 @@ public: CurrentLayer(); ~CurrentLayer(); - virtual iterator begin(); +// virtual iterator begin(); virtual Geom::OptRect getBounds(SPItem::BBoxType type); virtual int queryStyle(SPStyle *query, int property); virtual void setCSS(SPCSSAttr *css); @@ -99,12 +100,12 @@ protected: private: SPObject *_getLayer() const; void _setLayer(SPObject *layer); - GSList *_getLayerSList() const; + SPObject *_getLayerSList() const; sigc::connection _layer_switched; sigc::connection _layer_release; sigc::connection _layer_modified; - mutable GSList _element; + mutable SPObject* _element; }; } -- cgit v1.2.3 From cc22d3551937d17c596e4dd209060b16a714d463 Mon Sep 17 00:00:00 2001 From: Mc <> Date: Wed, 18 Feb 2015 02:17:25 +0100 Subject: OMG IT'S COMPILING. IT'S REALLY COMPILING ! (Of course it segfaults (what did you expect ?)) (bzr r13922.1.3) --- src/selection-chemistry.cpp | 174 +++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 91 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 05711e734..c213e76e4 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -2298,17 +2298,9 @@ sp_selection_move_screen(Inkscape::Selection *selection, gdouble dx, gdouble dy) } } -namespace { -template -SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, - bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive); - -template -SPItem *next_item_from_list(SPDesktop *desktop, SelContainer const &items, SPObject *root, - bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive); -struct Forward { +typedef struct Forward { typedef SPObject *Iterator; static Iterator children(SPObject *o) { return o->firstChild(); } @@ -2317,9 +2309,9 @@ struct Forward { static SPObject *object(Iterator i) { return i; } static Iterator next(Iterator i) { return i->getNext(); } -}; +} Forward; -struct ListReverse { +typedef struct ListReverse { typedef GSList *Iterator; static Iterator children(SPObject *o) { @@ -2350,8 +2342,87 @@ private: } return list; } -}; +} ListReverse; + + + +template +SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, + bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) +{ + typename D::Iterator children; + typename D::Iterator iter; + + SPItem *found=NULL; + + if (path) { + SPObject *object=reinterpret_cast(path->data); + g_assert(object->parent == root); + if (desktop->isLayer(object)) { + found = next_item(desktop, path->next, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); + } + iter = children = D::siblings_after(object); + } else { + iter = children = D::children(root); + } + + while ( iter && !found ) { + SPObject *object=D::object(iter); + if (desktop->isLayer(object)) { + if (PREFS_SELECTION_LAYER != inlayer) { // recurse into sublayers + found = next_item(desktop, NULL, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); + } + } else { + SPItem *item = dynamic_cast(object); + if ( item && + ( !only_in_viewport || desktop->isWithinViewport(item) ) && + ( !onlyvisible || !desktop->itemIsHidden(item)) && + ( !onlysensitive || !item->isLocked()) && + !desktop->isLayer(item) ) + { + found = item; + } + } + iter = D::next(iter); + } + + D::dispose(children); + return found; +} + + +template +SPItem *next_item_from_list(SPDesktop *desktop, SelContainer const items, + SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) +{ + SPObject *current=root; + for(SelContainer::const_iterator i = items.begin();i!=items.end();i++) { + SPItem *item = dynamic_cast(static_cast(*i)); + if ( root->isAncestorOf(item) && + ( !only_in_viewport || desktop->isWithinViewport(item) ) ) + { + current = item; + break; + } + } + + GSList *path=NULL; + while ( current != root ) { + path = g_slist_prepend(path, current); + current = current->parent; + } + + SPItem *next; + // first, try from the current object + next = next_item(desktop, path, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); + g_slist_free(path); + + if (!next) { // if we ran out of objects, start over at the root + next = next_item(desktop, NULL, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); + } + + return next; } void @@ -2478,87 +2549,8 @@ void sp_selection_edit_clip_or_mask(SPDesktop * /*dt*/, bool /*clip*/) } -namespace { -template -SPItem *next_item_from_list(SPDesktop *desktop, SelContainer const items, - SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) -{ - SPObject *current=root; - for(SelContainer::const_iterator i = items.begin();i!=items.end();i++) { - SPItem *item = dynamic_cast(static_cast(*i)); - if ( root->isAncestorOf(item) && - ( !only_in_viewport || desktop->isWithinViewport(item) ) ) - { - current = item; - break; - } - } - GSList *path=NULL; - while ( current != root ) { - path = g_slist_prepend(path, current); - current = current->parent; - } - - SPItem *next; - // first, try from the current object - next = next_item(desktop, path, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); - g_slist_free(path); - - if (!next) { // if we ran out of objects, start over at the root - next = next_item(desktop, NULL, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); - } - - return next; -} - -template -SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, - bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) -{ - typename D::Iterator children; - typename D::Iterator iter; - - SPItem *found=NULL; - - if (path) { - SPObject *object=reinterpret_cast(path->data); - g_assert(object->parent == root); - if (desktop->isLayer(object)) { - found = next_item(desktop, path->next, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); - } - iter = children = D::siblings_after(object); - } else { - iter = children = D::children(root); - } - - while ( iter && !found ) { - SPObject *object=D::object(iter); - if (desktop->isLayer(object)) { - if (PREFS_SELECTION_LAYER != inlayer) { // recurse into sublayers - found = next_item(desktop, NULL, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); - } - } else { - SPItem *item = dynamic_cast(object); - if ( item && - ( !only_in_viewport || desktop->isWithinViewport(item) ) && - ( !onlyvisible || !desktop->itemIsHidden(item)) && - ( !onlysensitive || !item->isLocked()) && - !desktop->isLayer(item) ) - { - found = item; - } - } - iter = D::next(iter); - } - - D::dispose(children); - - return found; -} - -} /** * If \a item is not entirely visible then adjust visible area to centre on the centre on of -- cgit v1.2.3 From 9e21d00fb1053897420f80d05a9815c5b2bbf312 Mon Sep 17 00:00:00 2001 From: mc <> Date: Wed, 18 Feb 2015 11:25:23 +0100 Subject: I can't really understand why, but i can now launch inkscape without it segfaulting. That's an improvement. Next thing: code cleaning, replacing containers with vectors (bzr r13922.1.4) --- src/selection-chemistry.cpp | 82 ++++++++++++++------------------- src/selection.cpp | 10 ++-- src/selection.h | 4 +- src/splivarot.cpp | 6 +-- src/ui/dialog/export.cpp | 12 ++--- src/ui/dialog/filter-effects-dialog.cpp | 2 +- src/ui/dialog/svg-fonts-dialog.cpp | 4 +- 7 files changed, 53 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index c213e76e4..9f27ca22e 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -462,13 +462,13 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to duplicate.")); return; } - SelContainer reprs(selection->reprList()); + std::vector reprs(selection->reprList()); selection->clear(); // sorting items from different parents sorts each parent's subset without possibly mixing // them, just what we need - reprs.sort(sp_repr_compare_position_obj); + sort(reprs.begin(),reprs.end(),sp_repr_compare_position); SelContainer newsel; @@ -478,8 +478,8 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) bool relink_clones = prefs->getBool("/options/relinkclonesonduplicate/value"); const bool fork_livepatheffects = prefs->getBool("/options/forklpeonduplicate/value", true); - while (!reprs.empty()) { - Inkscape::XML::Node *old_repr = dynamic_cast(reprs.front()); + for(std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ + Inkscape::XML::Node *old_repr = (*i); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); @@ -501,7 +501,6 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) } newsel.push_front(dynamic_cast(copy)); - reprs.pop_front(); Inkscape::GC::release(copy); } @@ -692,16 +691,16 @@ void sp_edit_invert_in_all_layers(SPDesktop *desktop) sp_edit_select_all_full(desktop, true, true); } -static void sp_selection_group_impl(SelContainer p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { +static void sp_selection_group_impl(std::vector p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { - p.sort(sp_repr_compare_position_obj); + sort(p.begin(),p.end(),sp_repr_compare_position); // Remember the position and parent of the topmost object. gint topmost = (dynamic_cast(p.back()))->position(); Inkscape::XML::Node *topmost_parent = (dynamic_cast(p.back()))->parent(); - while (!p.empty()) { - Inkscape::XML::Node *current = dynamic_cast(p.front()); + for(std::vector::const_iterator i=p.begin();i!=p.end();i++){ + Inkscape::XML::Node *current = (*i); if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -745,7 +744,6 @@ static void sp_selection_group_impl(SelContainer p, Inkscape::XML::Node *group, copied.clear(); } } - p.pop_front(); } // Add the new group to the topmost members' parent @@ -766,7 +764,7 @@ void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop) return; } - SelContainer p (selection->reprList()); + std::vector p (selection->reprList()); selection->clear(); @@ -1027,16 +1025,14 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - SelContainer rl(selection->reprList()); - rl.sort(sp_repr_compare_position_obj); + std::vector rl(selection->reprList()); + sort(rl.begin(),rl.end(),sp_repr_compare_position); - for (SelContainer::iterator l=rl.begin(); l!=rl.end();l++) { - Inkscape::XML::Node *repr = dynamic_cast(*l); + for (std::vector::const_iterator l=rl.begin(); l!=rl.end();l++) { + Inkscape::XML::Node *repr =(*l); repr->setPosition(-1); } - rl.clear(); - DocumentUndo::done(document, SP_VERB_SELECTION_TO_FRONT, _("Raise to top")); } @@ -1117,14 +1113,13 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - SelContainer rl(selection->reprList()); - rl.sort(sp_repr_compare_position_obj); - rl.reverse(); + std::vector rl(selection->reprList()); + sort(rl.begin(),rl.end(),sp_repr_compare_position); - for (SelContainer::const_iterator l=rl.begin();l!=rl.end();l++) { + for (std::vector::const_reverse_iterator l=rl.rbegin();l!=rl.rend();l++) { gint minpos; SPObject *pp, *pc; - Inkscape::XML::Node *repr = dynamic_cast(*l); + Inkscape::XML::Node *repr = (*l); pp = document->getObjectByRepr(repr->parent()); minpos = 0; g_assert(dynamic_cast(pp)); @@ -1136,8 +1131,6 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des repr->setPosition(minpos); } - rl.clear(); - DocumentUndo::done(document, SP_VERB_SELECTION_TO_BACK, _("Lower to bottom")); } @@ -1691,9 +1684,9 @@ void sp_selection_remove_transform(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); - SelContainer items = selection->itemList(); - for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { - ((Inkscape::XML::Node*)*l)->setAttribute("transform", NULL, false); + std::vector items = selection->reprList(); + for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { + (*l)->setAttribute("transform", NULL, false); } DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_FLATTEN, @@ -2590,17 +2583,17 @@ void sp_selection_clone(SPDesktop *desktop) return; } - SelContainer reprs (selection->reprList()); + std::vector reprs (selection->reprList()); selection->clear(); // sorting items from different parents sorts each parent's subset without possibly mixing them, just what we need - reprs.sort(sp_repr_compare_position_obj); + sort(reprs.begin(),reprs.end(),sp_repr_compare_position); SelContainer newsel; - while (!reprs.empty()) { - Inkscape::XML::Node *sel_repr = dynamic_cast(reprs.front()); + for(std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ + Inkscape::XML::Node *sel_repr = *i; Inkscape::XML::Node *parent = sel_repr->parent(); Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); @@ -2617,7 +2610,6 @@ void sp_selection_clone(SPDesktop *desktop) parent->appendChild(clone); newsel.push_front(dynamic_cast(clone)); - reprs.pop_front(); Inkscape::GC::release(clone); } @@ -3462,14 +3454,14 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring return; } - SelContainer const reprlst = selection->reprList(); + std::vector const reprlst = selection->reprList(); bool filename_search = TRUE; bool xdpi_search = TRUE; bool ydpi_search = TRUE; - for (SelContainer::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){ + for (std::vector::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){ gchar const *dpi_string; - Inkscape::XML::Node * repr = dynamic_cast(*i); + Inkscape::XML::Node * repr = (*i); if (filename_search) { const gchar* tmp = repr->attribute("inkscape:export-filename"); @@ -3756,22 +3748,20 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) return; } - SelContainer l=selection->reprList(); - - SelContainer p(l); + std::vector p(selection->reprList()); - p.sort(sp_repr_compare_position_obj); + sort(p.begin(),p.end(),sp_repr_compare_position); selection->clear(); - gint topmost = (dynamic_cast(p.back()))->position(); - Inkscape::XML::Node *topmost_parent = (dynamic_cast(p.back()))->parent(); + int topmost = (p.back())->position(); + Inkscape::XML::Node *topmost_parent = (p.back())->parent(); Inkscape::XML::Node *inner = xml_doc->createElement("svg:g"); inner->setAttribute("inkscape:label", "Clip"); - while (!p.empty()) { - Inkscape::XML::Node *current = dynamic_cast(p.front()); + for(std::vector::const_iterator i=p.begin();i!=p.end();i++){ + Inkscape::XML::Node *current = *i; if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -3813,7 +3803,6 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) Inkscape::GC::release(spnew); } } - p.pop_front(); } Inkscape::XML::Node *outer = xml_doc->createElement("svg:g"); @@ -3960,13 +3949,12 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // make a note we should ungroup this when unsetting mask group->setAttribute("inkscape:groupmode", "maskhelper"); - SelContainer reprs_to_group; + std::vector reprs_to_group; for (GSList *i = apply_to_items ; NULL != i ; i = i->next) { - reprs_to_group.push_front(dynamic_cast(SP_OBJECT(i->data)->getRepr())); + reprs_to_group.push_back(static_cast(i->data)->getRepr()); items_to_select.remove(static_cast(i->data)); } - reprs_to_group.reverse(); sp_selection_group_impl(reprs_to_group, group, xml_doc, doc); diff --git a/src/selection.cpp b/src/selection.cpp index b509f4272..cbde9a799 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -43,7 +43,7 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : _objs(SelContainer()), - _reprs(SelContainer()), + _reprs(std::vector()), _items(SelContainer()), _layers(layers), _desktop(desktop), @@ -296,15 +296,13 @@ SelContainer const &Selection::itemList() { return _items; } -SelContainer const &Selection::reprList() { +std::vector const &Selection::reprList() { if (!_reprs.empty()) { return _reprs; } SelContainer list = itemList(); for ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) { SPObject *obj=reinterpret_cast(*iter); - _reprs.push_front(dynamic_cast(obj->getRepr())); + _reprs.push_back(obj->getRepr()); } - _reprs.reverse(); - return _reprs; } @@ -343,7 +341,7 @@ SPObject *Selection::single() { SPItem *Selection::singleItem() { SelContainer const items=itemList(); - if ( !items.size()==1) { + if ( items.size()==1) { return reinterpret_cast(items.front()); } else { return NULL; diff --git a/src/selection.h b/src/selection.h index 7171b8742..f85c6346b 100644 --- a/src/selection.h +++ b/src/selection.h @@ -260,7 +260,7 @@ public: /** Returns a list of the xml nodes of all selected objects. */ /// \todo only returns reprs of SPItems currently; need a separate /// method for that - std::list const &reprList(); + std::vector const &reprList(); /** Returns a list of all perspectives which have a 3D box in the current selection. (these may also be nested in groups) */ @@ -377,7 +377,7 @@ private: void _releaseContext(SPObject *obj); mutable std::list _objs; - mutable std::list _reprs; + mutable std::vector _reprs; mutable std::list _items; void add_box_perspective(SPBox3D *box); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index aec7051e0..107dfc629 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -691,11 +691,11 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool } } else { // find out the bottom object - SelContainer sorted(selection->reprList()); + std::vector sorted(selection->reprList()); - sorted.sort(sp_repr_compare_position_obj); + sort(sorted.begin(),sorted.end(),sp_repr_compare_position); - source = doc->getObjectByRepr((Inkscape::XML::Node *)sorted.front()); + source = doc->getObjectByRepr(sorted.front()); } // adjust style properties that depend on a possible transform in the source object in order diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index fc6094c9f..0667ba721 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -817,9 +817,9 @@ void Export::onAreaToggled () one that's nice */ if (filename.empty()) { const gchar * id = "object"; - const SelContainer reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); - for(SelContainer::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { - Inkscape::XML::Node * repr = (Inkscape::XML::Node *)(*i); + const std::vector reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); + for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + Inkscape::XML::Node * repr = (*i); if (repr->attribute("id")) { id = repr->attribute("id"); break; @@ -1226,7 +1226,7 @@ void Export::onExport () break; } case SELECTION_SELECTION: { - SelContainer reprlst; + std::vector reprlst; SPDocument * doc = SP_ACTIVE_DOCUMENT; bool modified = false; @@ -1234,8 +1234,8 @@ void Export::onExport () DocumentUndo::setUndoSensitive(doc, false); reprlst = desktop->getSelection()->reprList(); - for(SelContainer::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { - Inkscape::XML::Node * repr = dynamic_cast(*i); + for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + Inkscape::XML::Node * repr = *i; const gchar * temp_string; Glib::ustring dir = Glib::path_get_dirname(filename.c_str()); const gchar* docURI=SP_ACTIVE_DOCUMENT->getURI(); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 657d6771b..f67c1d173 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -690,7 +690,7 @@ private: void select_svg_element(){ Inkscape::Selection* sel = _desktop->getSelection(); if (sel->isEmpty()) return; - Inkscape::XML::Node* node = (Inkscape::XML::Node*) sel->reprList().front(); + Inkscape::XML::Node* node = sel->reprList().front(); if (!node || !node->matchAttributeName("id")) return; std::ostringstream xlikhref; diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index 8f5601e3a..12b423602 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -524,7 +524,7 @@ void SvgFontsDialog::set_glyph_description_from_selected_path(){ return; } - Inkscape::XML::Node* node = (Inkscape::XML::Node*)(sel->reprList().front()); + Inkscape::XML::Node* node = sel->reprList().front(); if (!node) return;//TODO: should this be an assert? if (!node->matchAttributeName("d") || !node->attribute("d")){ char *msg = _("The selected object does not have a path description."); @@ -566,7 +566,7 @@ void SvgFontsDialog::missing_glyph_description_from_selected_path(){ return; } - Inkscape::XML::Node* node = (Inkscape::XML::Node*)(sel->reprList().front()); + Inkscape::XML::Node* node = sel->reprList().front(); if (!node) return;//TODO: should this be an assert? if (!node->matchAttributeName("d") || !node->attribute("d")){ char *msg = _("The selected object does not have a path description."); -- cgit v1.2.3 From 5fd00cab14d48beaf2279a2b8f3ad5b02b76c87b Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 19 Feb 2015 04:25:21 +0100 Subject: Put a few std::vector (bzr r13922.1.5) --- src/conn-avoid-ref.cpp | 4 +- src/desktop-style.cpp | 66 ++--- src/desktop-style.h | 24 +- src/desktop.cpp | 2 +- src/desktop.h | 2 +- src/document.cpp | 20 +- src/document.h | 8 +- src/extension/execution-env.cpp | 4 +- src/extension/implementation/implementation.cpp | 2 +- src/extension/implementation/script.cpp | 4 +- src/extension/internal/bitmap/imagemagick.cpp | 6 +- src/extension/internal/bluredge.cpp | 4 +- src/extension/internal/filter/filter.cpp | 4 +- src/extension/internal/grid.cpp | 2 +- src/file.cpp | 4 +- src/gradient-chemistry.cpp | 8 +- src/gradient-drag.cpp | 12 +- src/graphlayout.cpp | 6 +- src/graphlayout.h | 4 +- src/helper/png-write.cpp | 6 +- src/helper/png-write.h | 4 +- src/live_effects/lpe-knot.cpp | 4 +- src/main.cpp | 12 +- src/object-snapper.cpp | 4 +- src/path-chemistry.cpp | 73 ++--- src/path-chemistry.h | 2 +- src/removeoverlap.cpp | 6 +- src/removeoverlap.h | 2 +- src/selcue.cpp | 14 +- src/selection-chemistry.cpp | 373 ++++++++++++------------ src/selection-chemistry.h | 10 +- src/selection-describer.cpp | 14 +- src/selection.cpp | 56 ++-- src/selection.h | 10 +- src/seltrans.cpp | 26 +- src/seltrans.h | 2 +- src/snap.cpp | 6 +- src/snap.h | 6 +- src/sp-conn-end.cpp | 4 +- src/sp-item-group.cpp | 19 +- src/sp-item-group.h | 4 +- src/sp-lpe-item.cpp | 20 +- src/sp-marker.cpp | 6 +- src/sp-marker.h | 2 +- src/sp-pattern.cpp | 4 +- src/sp-pattern.h | 2 +- src/splivarot.cpp | 30 +- src/text-chemistry.cpp | 40 +-- src/text-editing.cpp | 4 +- src/trace/trace.cpp | 4 +- src/ui/clipboard.cpp | 20 +- src/ui/dialog/align-and-distribute.cpp | 32 +- src/ui/dialog/clonetiler.cpp | 7 +- src/ui/dialog/export.cpp | 8 +- src/ui/dialog/filter-effects-dialog.cpp | 14 +- src/ui/dialog/find.cpp | 54 ++-- src/ui/dialog/find.h | 10 +- src/ui/dialog/font-substitution.cpp | 18 +- src/ui/dialog/font-substitution.h | 4 +- src/ui/dialog/glyphs.cpp | 8 +- src/ui/dialog/grid-arrange-tab.cpp | 21 +- src/ui/dialog/icon-preview.cpp | 4 +- src/ui/dialog/objects.cpp | 4 +- src/ui/dialog/pixelartdialog.cpp | 4 +- src/ui/dialog/polar-arrange-tab.cpp | 6 +- src/ui/dialog/print.cpp | 2 +- src/ui/dialog/swatches.cpp | 2 +- src/ui/dialog/tags.cpp | 4 +- src/ui/dialog/text-edit.cpp | 12 +- src/ui/dialog/transformation.cpp | 22 +- src/ui/interface.cpp | 8 +- src/ui/tools/connector-tool.cpp | 4 +- src/ui/tools/eraser-tool.cpp | 18 +- src/ui/tools/gradient-tool.cpp | 12 +- src/ui/tools/lpe-tool.cpp | 4 +- src/ui/tools/measure-tool.cpp | 4 +- src/ui/tools/mesh-tool.cpp | 12 +- src/ui/tools/node-tool.cpp | 6 +- src/ui/tools/select-tool.cpp | 2 +- src/ui/tools/spray-tool.cpp | 14 +- src/ui/tools/text-tool.cpp | 4 +- src/ui/tools/tool-base.cpp | 4 +- src/ui/tools/tweak-tool.cpp | 12 +- src/ui/widget/object-composite-settings.cpp | 4 +- src/ui/widget/style-subject.cpp | 4 +- src/unclump.cpp | 36 +-- src/unclump.h | 2 +- src/vanishing-point.cpp | 18 +- src/widgets/arc-toolbar.cpp | 16 +- src/widgets/connector-toolbar.cpp | 8 +- src/widgets/fill-style.cpp | 8 +- src/widgets/gradient-toolbar.cpp | 12 +- src/widgets/mesh-toolbar.cpp | 8 +- src/widgets/rect-toolbar.cpp | 8 +- src/widgets/spiral-toolbar.cpp | 8 +- src/widgets/star-toolbar.cpp | 24 +- src/widgets/stroke-style.cpp | 14 +- src/widgets/stroke-style.h | 2 +- src/widgets/text-toolbar.cpp | 22 +- 99 files changed, 744 insertions(+), 765 deletions(-) (limited to 'src') diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp index f2cde352c..fb9fbd935 100644 --- a/src/conn-avoid-ref.cpp +++ b/src/conn-avoid-ref.cpp @@ -252,8 +252,8 @@ static std::vector approxItemWithPoints(SPItem const *item, const G { SPGroup* group = SP_GROUP(item); // consider all first-order children - SelContainer itemlist = sp_item_group_item_list(group); - for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + std::vector itemlist = sp_item_group_item_list(group); + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { SPItem* child_item = SP_ITEM(*i); std::vector child_points = approxItemWithPoints(child_item, item_transform * child_item->transform); poly_points.insert(poly_points.end(), child_points.begin(), child_points.end()); diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 39dfad44b..0c661ebfb 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -194,8 +194,8 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_repr_css_merge(css_write, css); sp_css_attr_unset_uris(css_write); prefs->mergeStyle("/desktop/style", css_write); - SelContainer const itemlist = desktop->selection->itemList(); - for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + std::vector const itemlist = desktop->selection->itemList(); + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { /* last used styles for 3D box faces are stored separately */ SPObject *obj = reinterpret_cast(*i); // TODO unsafe until Selection is refactored. Box3DSide *side = dynamic_cast(obj); @@ -234,8 +234,8 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_repr_css_merge(css_no_text, css); css_no_text = sp_css_attr_unset_text(css_no_text); - SelContainer const itemlist = desktop->selection->itemList(); - for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + std::vector const itemlist = desktop->selection->itemList(); + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { SPItem *item = reinterpret_cast(*i); // If not text, don't apply text attributes (can a group have text attributes? Yes! FIXME) @@ -439,7 +439,7 @@ sp_desktop_get_font_size_tool(SPDesktop *desktop) /** Determine average stroke width, simple method */ // see TODO in dialogs/stroke-style.cpp on how to get rid of this eventually gdouble -stroke_average_width (const SelContainer &objects) +stroke_average_width (const std::vector &objects) { if (objects.empty()) return Geom::infinity(); @@ -447,7 +447,7 @@ stroke_average_width (const SelContainer &objects) gdouble avgwidth = 0.0; bool notstroked = true; int n_notstroked = 0; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); SPItem *item = dynamic_cast(obj); if (!item) { @@ -492,7 +492,7 @@ static bool vectorsClose( std::vector const &lhs, std::vector co * Write to style_res the average fill or stroke of list of objects, if applicable. */ int -objects_query_fillstroke (const SelContainer &objects, SPStyle *style_res, bool const isfill) +objects_query_fillstroke (const std::vector &objects, SPStyle *style_res, bool const isfill) { if (objects.empty()) { /* No objects, set empty */ @@ -514,7 +514,7 @@ objects_query_fillstroke (const SelContainer &objects, SPStyle *style_res, bool prev[0] = prev[1] = prev[2] = 0.0; bool same_color = true; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; @@ -685,7 +685,7 @@ objects_query_fillstroke (const SelContainer &objects, SPStyle *style_res, bool * Write to style_res the average opacity of a list of objects. */ int -objects_query_opacity (const SelContainer &objects, SPStyle *style_res) +objects_query_opacity (const std::vector &objects, SPStyle *style_res) { if (objects.empty()) { /* No objects, set empty */ @@ -698,7 +698,7 @@ objects_query_opacity (const SelContainer &objects, SPStyle *style_res) guint opacity_items = 0; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; @@ -739,7 +739,7 @@ objects_query_opacity (const SelContainer &objects, SPStyle *style_res) * Write to style_res the average stroke width of a list of objects. */ int -objects_query_strokewidth (const SelContainer &objects, SPStyle *style_res) +objects_query_strokewidth (const std::vector &objects, SPStyle *style_res) { if (objects.empty()) { /* No objects, set empty */ @@ -754,7 +754,7 @@ objects_query_strokewidth (const SelContainer &objects, SPStyle *style_res) int n_stroked = 0; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; @@ -815,7 +815,7 @@ objects_query_strokewidth (const SelContainer &objects, SPStyle *style_res) * Write to style_res the average miter limit of a list of objects. */ int -objects_query_miterlimit (const SelContainer &objects, SPStyle *style_res) +objects_query_miterlimit (const std::vector &objects, SPStyle *style_res) { if (objects.empty()) { /* No objects, set empty */ @@ -828,7 +828,7 @@ objects_query_miterlimit (const SelContainer &objects, SPStyle *style_res) gdouble prev_ml = -1; bool same_ml = true; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!dynamic_cast(obj)) { continue; @@ -875,7 +875,7 @@ objects_query_miterlimit (const SelContainer &objects, SPStyle *style_res) * Write to style_res the stroke cap of a list of objects. */ int -objects_query_strokecap (const SelContainer &objects, SPStyle *style_res) +objects_query_strokecap (const std::vector &objects, SPStyle *style_res) { if (objects.empty()) { /* No objects, set empty */ @@ -887,7 +887,7 @@ objects_query_strokecap (const SelContainer &objects, SPStyle *style_res) bool same_cap = true; int n_stroked = 0; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!dynamic_cast(obj)) { continue; @@ -929,7 +929,7 @@ objects_query_strokecap (const SelContainer &objects, SPStyle *style_res) * Write to style_res the stroke join of a list of objects. */ int -objects_query_strokejoin (const SelContainer &objects, SPStyle *style_res) +objects_query_strokejoin (const std::vector &objects, SPStyle *style_res) { if (objects.empty()) { /* No objects, set empty */ @@ -941,7 +941,7 @@ objects_query_strokejoin (const SelContainer &objects, SPStyle *style_res) bool same_join = true; int n_stroked = 0; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!dynamic_cast(obj)) { continue; @@ -984,7 +984,7 @@ objects_query_strokejoin (const SelContainer &objects, SPStyle *style_res) * Write to style_res the average font size and spacing of objects. */ int -objects_query_fontnumbers (const SelContainer &objects, SPStyle *style_res) +objects_query_fontnumbers (const std::vector &objects, SPStyle *style_res) { bool different = false; @@ -1004,7 +1004,7 @@ objects_query_fontnumbers (const SelContainer &objects, SPStyle *style_res) int texts = 0; int no_size = 0; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!isTextualItem(obj)) { @@ -1116,14 +1116,14 @@ objects_query_fontnumbers (const SelContainer &objects, SPStyle *style_res) * Write to style_res the average font style of objects. */ int -objects_query_fontstyle (const SelContainer &objects, SPStyle *style_res) +objects_query_fontstyle (const std::vector &objects, SPStyle *style_res) { bool different = false; bool set = false; int texts = 0; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!isTextualItem(obj)) { @@ -1173,7 +1173,7 @@ objects_query_fontstyle (const SelContainer &objects, SPStyle *style_res) * Write to style_res the baseline numbers. */ static int -objects_query_baselines (const SelContainer &objects, SPStyle *style_res) +objects_query_baselines (const std::vector &objects, SPStyle *style_res) { bool different = false; @@ -1192,7 +1192,7 @@ objects_query_baselines (const SelContainer &objects, SPStyle *style_res) int texts = 0; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!isTextualItem(obj)) { @@ -1269,7 +1269,7 @@ objects_query_baselines (const SelContainer &objects, SPStyle *style_res) * Write to style_res the average font family of objects. */ int -objects_query_fontfamily (const SelContainer &objects, SPStyle *style_res) +objects_query_fontfamily (const std::vector &objects, SPStyle *style_res) { bool different = false; int texts = 0; @@ -1280,7 +1280,7 @@ objects_query_fontfamily (const SelContainer &objects, SPStyle *style_res) } style_res->font_family.set = FALSE; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; @@ -1325,7 +1325,7 @@ objects_query_fontfamily (const SelContainer &objects, SPStyle *style_res) } static int -objects_query_fontspecification (const SelContainer &objects, SPStyle *style_res) +objects_query_fontspecification (const std::vector &objects, SPStyle *style_res) { bool different = false; int texts = 0; @@ -1336,7 +1336,7 @@ objects_query_fontspecification (const SelContainer &objects, SPStyle *style_res } style_res->font_specification.set = FALSE; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; @@ -1385,7 +1385,7 @@ objects_query_fontspecification (const SelContainer &objects, SPStyle *style_res } static int -objects_query_blend (const SelContainer &objects, SPStyle *style_res) +objects_query_blend (const std::vector &objects, SPStyle *style_res) { const int empty_prev = -2; const int complex_filter = 5; @@ -1394,7 +1394,7 @@ objects_query_blend (const SelContainer &objects, SPStyle *style_res) bool same_blend = true; guint items = 0; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; @@ -1471,7 +1471,7 @@ objects_query_blend (const SelContainer &objects, SPStyle *style_res) * Write to style_res the average blurring of a list of objects. */ int -objects_query_blur (const SelContainer &objects, SPStyle *style_res) +objects_query_blur (const std::vector &objects, SPStyle *style_res) { if (objects.empty()) { /* No objects, set empty */ @@ -1484,7 +1484,7 @@ objects_query_blur (const SelContainer &objects, SPStyle *style_res) guint blur_items = 0; guint items = 0; - for (SelContainer::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; @@ -1553,7 +1553,7 @@ objects_query_blur (const SelContainer &objects, SPStyle *style_res) * the result to style, return appropriate flag. */ int -sp_desktop_query_style_from_list (const SelContainer &list, SPStyle *style, int property) +sp_desktop_query_style_from_list (const std::vector &list, SPStyle *style, int property) { if (property == QUERY_STYLE_PROPERTY_FILL) { return objects_query_fillstroke (list, style, true); diff --git a/src/desktop-style.h b/src/desktop-style.h index 0e40a2652..7ca25b9ae 100644 --- a/src/desktop-style.h +++ b/src/desktop-style.h @@ -65,21 +65,21 @@ guint32 sp_desktop_get_color_tool(SPDesktop *desktop, Glib::ustring const &tool, double sp_desktop_get_font_size_tool (SPDesktop *desktop); void sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, Glib::ustring const &tool, bool with_text); -gdouble stroke_average_width (const SelContainer &objects); +gdouble stroke_average_width (const std::vector &objects); -int objects_query_fillstroke (const SelContainer &objects, SPStyle *style_res, bool const isfill); -int objects_query_fontnumbers (const SelContainer &objects, SPStyle *style_res); -int objects_query_fontstyle (const SelContainer &objects, SPStyle *style_res); -int objects_query_fontfamily (const SelContainer &objects, SPStyle *style_res); -int objects_query_opacity (const SelContainer &objects, SPStyle *style_res); -int objects_query_strokewidth (const SelContainer &objects, SPStyle *style_res); -int objects_query_miterlimit (const SelContainer &objects, SPStyle *style_res); -int objects_query_strokecap (const SelContainer &objects, SPStyle *style_res); -int objects_query_strokejoin (const SelContainer &objects, SPStyle *style_res); +int objects_query_fillstroke (const std::vector &objects, SPStyle *style_res, bool const isfill); +int objects_query_fontnumbers (const std::vector &objects, SPStyle *style_res); +int objects_query_fontstyle (const std::vector &objects, SPStyle *style_res); +int objects_query_fontfamily (const std::vector &objects, SPStyle *style_res); +int objects_query_opacity (const std::vector &objects, SPStyle *style_res); +int objects_query_strokewidth (const std::vector &objects, SPStyle *style_res); +int objects_query_miterlimit (const std::vector &objects, SPStyle *style_res); +int objects_query_strokecap (const std::vector &objects, SPStyle *style_res); +int objects_query_strokejoin (const std::vector &objects, SPStyle *style_res); -int objects_query_blur (const SelContainer &objects, SPStyle *style_res); +int objects_query_blur (const std::vector &objects, SPStyle *style_res); -int sp_desktop_query_style_from_list (const SelContainer &list, SPStyle *style, int property); +int sp_desktop_query_style_from_list (const std::vector &list, SPStyle *style, int property); int sp_desktop_query_style(SPDesktop *desktop, SPStyle *style, int property); bool sp_desktop_query_style_all (SPDesktop *desktop, SPStyle *query); diff --git a/src/desktop.cpp b/src/desktop.cpp index 64353e582..0cf0a3872 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -716,7 +716,7 @@ Inkscape::UI::Widget::Dock* SPDesktop::getDock() { /** * \see SPDocument::getItemFromListAtPointBottom() */ -SPItem *SPDesktop::getItemFromListAtPointBottom(const SelContainer &list, Geom::Point const &p) const +SPItem *SPDesktop::getItemFromListAtPointBottom(const std::vector &list, Geom::Point const &p) const { g_return_val_if_fail (doc() != NULL, NULL); return SPDocument::getItemFromListAtPointBottom(dkey, doc()->getRoot(), list, p); diff --git a/src/desktop.h b/src/desktop.h index 8765fa699..754e09766 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -319,7 +319,7 @@ public: //void push_event_context (GType type, const gchar *config, unsigned int key); void set_coordinate_status (Geom::Point p); - SPItem *getItemFromListAtPointBottom(const SelContainer &list, Geom::Point const &p) const; + SPItem *getItemFromListAtPointBottom(const std::vector &list, Geom::Point const &p) const; SPItem *getItemAtPoint(Geom::Point const &p, bool into_groups, SPItem *upto = NULL) const; SPItem *getGroupAtPoint(Geom::Point const &p) const; Geom::Point point() const; diff --git a/src/document.cpp b/src/document.cpp index 5c49ff6c3..07ad10505 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1235,7 +1235,7 @@ static bool overlaps(Geom::Rect const &area, Geom::Rect const &box) return area.intersects(box); } -static SelContainer &find_items_in_area(SelContainer &s, SPGroup *group, unsigned int dkey, Geom::Rect const &area, +static std::vector &find_items_in_area(std::vector &s, SPGroup *group, unsigned int dkey, Geom::Rect const &area, bool (*test)(Geom::Rect const &, Geom::Rect const &), bool take_insensitive = false) { g_return_val_if_fail(SP_IS_GROUP(group), s); @@ -1275,7 +1275,7 @@ static bool item_is_in_group(SPItem *item, SPGroup *group) return inGroup; } -SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, SelContainer const &list,Geom::Point const &p, bool take_insensitive) +SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, std::vector const &list,Geom::Point const &p, bool take_insensitive) { g_return_val_if_fail(group, NULL); SPItem *bottomMost = 0; @@ -1391,9 +1391,9 @@ static SPItem *find_group_at_point(unsigned int dkey, SPGroup *group, Geom::Poin * Assumes box is normalized (and g_asserts it!) * */ -SelContainer SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) const +std::vector SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) const { - SelContainer x; + std::vector x; g_return_val_if_fail(this->priv != NULL, x); return find_items_in_area(x, SP_GROUP(this->root), dkey, box, is_within); } @@ -1405,16 +1405,16 @@ SelContainer SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) * */ -SelContainer SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const +std::vector SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const { - SelContainer x; + std::vector x; g_return_val_if_fail(this->priv != NULL, x); return find_items_in_area(x, SP_GROUP(this->root), dkey, box, overlaps); } -SelContainer SPDocument::getItemsAtPoints(unsigned const key, std::vector points) const +std::vector SPDocument::getItemsAtPoints(unsigned const key, std::vector points) const { - SelContainer items; + std::vector items; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // When picking along the path, we don't want small objects close together @@ -1423,11 +1423,11 @@ SelContainer SPDocument::getItemsAtPoints(unsigned const key, std::vectorgetDouble("/options/cursortolerance/value", 1.0); prefs->setDouble("/options/cursortolerance/value", 0.25); - for(unsigned int i = 0; i < points.size(); i++) { + for(int i = points.size()-1;i>=0; i--) { SPItem *item = getItemAtPoint(key, points[i], false, NULL); if (item && items.end()==find(items.begin(),items.end(), item)) - items.push_front(item); + items.push_back(item); } // and now we restore it back diff --git a/src/document.h b/src/document.h index 87262a079..57ff7643c 100644 --- a/src/document.h +++ b/src/document.h @@ -233,7 +233,7 @@ public: /** * Returns the bottommost item from the list which is at the point, or NULL if none. */ - static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const SelContainer &list, Geom::Point const &p, bool take_insensitive = false); + static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const std::vector &list, Geom::Point const &p, bool take_insensitive = false); static SPDocument *createDoc(Inkscape::XML::Document *rdoc, char const *uri, char const *base, char const *name, unsigned int keepalive, @@ -257,10 +257,10 @@ public: bool addResource(char const *key, SPObject *object); bool removeResource(char const *key, SPObject *object); const GSList *getResourceList(char const *key) const; - SelContainer getItemsInBox(unsigned int dkey, Geom::Rect const &box) const; - SelContainer getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const; + std::vector getItemsInBox(unsigned int dkey, Geom::Rect const &box) const; + std::vector getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const; SPItem *getItemAtPoint(unsigned int key, Geom::Point const &p, bool into_groups, SPItem *upto = NULL) const; - SelContainer getItemsAtPoints(unsigned const key, std::vector points) const; + std::vector getItemsAtPoints(unsigned const key, std::vector points) const; SPItem *getGroupAtPoint(unsigned int key, Geom::Point const &p) const; void changeUriAndHrefs(char const *uri); diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index 66a8c4358..90a7810e6 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -64,8 +64,8 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Imp sp_namedview_document_from_window(desktop); if (desktop != NULL) { - SelContainer selected = desktop->getSelection()->itemList(); - for(SelContainer::const_iterator x=selected.begin();x!=selected.end();x++){ + std::vector selected = desktop->getSelection()->itemList(); + for(std::vector::const_iterator x=selected.begin();x!=selected.end();x++){ Glib::ustring selected_id; selected_id = (*x)->getId(); _selected.insert(_selected.end(), selected_id); diff --git a/src/extension/implementation/implementation.cpp b/src/extension/implementation/implementation.cpp index 6eff3ede3..cea6d139f 100644 --- a/src/extension/implementation/implementation.cpp +++ b/src/extension/implementation/implementation.cpp @@ -48,7 +48,7 @@ Gtk::Widget *Implementation::prefs_effect(Inkscape::Extension::Effect *module, I SPDocument * current_document = view->doc(); using Inkscape::Util::GSListConstIterator; - SelContainer selected = ((SPDesktop *)view)->getSelection()->itemList(); + std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node const* first_select = NULL; if (!selected.empty()) { const SPItem * item = SP_ITEM(selected.front()); diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index f396e9848..95d5c7edc 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -689,9 +689,9 @@ void Script::effect(Inkscape::Extension::Effect *module, return; } - SelContainer selected = + std::vector selected = desktop->getSelection()->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer - for(SelContainer::const_iterator x=selected.begin();x!=selected.end();x++){ + for(std::vector::const_iterator x=selected.begin();x!=selected.end();x++){ Glib::ustring selected_id; selected_id += "--id="; selected_id += (*x)->getId(); diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index 87ef30887..64abd6c4d 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -70,7 +70,7 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : _imageItems(NULL) { SPDesktop *desktop = (SPDesktop*)view; - const SelContainer selectedItemList = desktop->selection->itemList(); + const std::vector selectedItemList = desktop->selection->itemList(); int selectCount = selectedItemList.size(); // Init the data-holders @@ -83,7 +83,7 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : _imageItems = new SPItem*[selectCount]; // Loop through selected items - for (SelContainer::const_iterator i=selectedItemList.begin();i!=selectedItemList.end();i++) { + for (std::vector::const_iterator i=selectedItemList.begin();i!=selectedItemList.end();i++) { SPItem *item = static_cast(*i); Inkscape::XML::Node *node = reinterpret_cast(item->getRepr()); if (!strcmp(node->name(), "image") || !strcmp(node->name(), "svg:image")) @@ -242,7 +242,7 @@ ImageMagick::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::Vie using Inkscape::Util::GSListConstIterator; - SelContainer selected = ((SPDesktop *)view)->getSelection()->itemList(); + std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; if (!selected.empty()) { first_select = (selected.front())->getRepr(); diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp index 138172715..257cac161 100644 --- a/src/extension/internal/bluredge.cpp +++ b/src/extension/internal/bluredge.cpp @@ -65,10 +65,10 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View using Inkscape::Util::GSListConstIterator; // TODO need to properly refcount the items, at least - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); selection->clear(); - for(SelContainer::iterator item = items.begin(); + for(std::vector::iterator item = items.begin(); item != items.end(); ++item) { SPItem * spitem = static_cast(*item); diff --git a/src/extension/internal/filter/filter.cpp b/src/extension/internal/filter/filter.cpp index 821c023ac..a5eb7de60 100644 --- a/src/extension/internal/filter/filter.cpp +++ b/src/extension/internal/filter/filter.cpp @@ -126,12 +126,12 @@ void Filter::effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::Vie Inkscape::Selection * selection = ((SPDesktop *)document)->selection; // TODO need to properly refcount the items, at least - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); Inkscape::XML::Document * xmldoc = document->doc()->getReprDoc(); Inkscape::XML::Node * defsrepr = document->doc()->getDefs()->getRepr(); - for(SelContainer::iterator item = items.begin(); + for(std::vector::iterator item = items.begin(); item != items.end(); ++item) { SPItem * spitem = static_cast(*item); Inkscape::XML::Node * node = spitem->getRepr(); diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index 4c12f629c..440c6b822 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -192,7 +192,7 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View using Inkscape::Util::GSListConstIterator; - SelContainer selected = ((SPDesktop *)view)->getSelection()->itemList(); + std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; if (!selected.empty()) { first_select = (selected.front())->getRepr(); diff --git a/src/file.cpp b/src/file.cpp index 4325c838b..f9dbe00a7 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1063,7 +1063,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) desktop->doc()->importDefs(clipdoc); // copy objects - std::list pasted_objects; + std::vector pasted_objects; for (Inkscape::XML::Node *obj = root->firstChild() ; obj ; obj = obj->next()) { // Don't copy metadata, defs, named views and internal clipboard contents to the document if (!strcmp(obj->name(), "svg:defs")) { @@ -1082,7 +1082,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) target_parent->appendChild(obj_copy); Inkscape::GC::release(obj_copy); - pasted_objects.push_front(dynamic_cast(obj_copy)); + pasted_objects.push_back((obj_copy)); } // Change the selection to the freshly pasted objects diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 5f1da6cf1..a72423bbb 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1570,8 +1570,8 @@ void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTa { Inkscape::Selection *selection = desktop->getSelection(); - const SelContainer list=selection->itemList(); - for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) { + const std::vector list=selection->itemList(); + for (std::vector::const_iterator i=list.begin();i!=list.end();i++) { sp_item_gradient_invert_vector_color(SP_ITEM(*i), fill_or_stroke); } @@ -1595,8 +1595,8 @@ void sp_gradient_reverse_selected_gradients(SPDesktop *desktop) if (drag && drag->selected) { drag->selected_reverse_vector(); } else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients) - const SelContainer list=selection->itemList(); - for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) { + const std::vector list=selection->itemList(); + for (std::vector::const_iterator i=list.begin();i!=list.end();i++) { sp_item_gradient_reverse_vector(SP_ITEM(*i), Inkscape::FOR_FILL); sp_item_gradient_reverse_vector(SP_ITEM(*i), Inkscape::FOR_STROKE); } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 649928060..525fc074f 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -2082,8 +2082,8 @@ void GrDrag::updateDraggers() this->draggers = NULL; g_return_if_fail(this->selection != NULL); - SelContainer list = this->selection->itemList(); - for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) { + std::vector list = this->selection->itemList(); + for (std::vector::const_iterator i=list.begin();i!=list.end();i++) { SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; @@ -2151,8 +2151,8 @@ void GrDrag::updateLines() g_return_if_fail(this->selection != NULL); - SelContainer list = this->selection->itemList(); - for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) { + std::vector list = this->selection->itemList(); + for (std::vector::const_iterator i=list.begin();i!=list.end();i++) { SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; @@ -2295,8 +2295,8 @@ void GrDrag::updateLevels() g_return_if_fail (this->selection != NULL); - SelContainer list = this->selection->itemList(); - for (SelContainer::const_iterator i=list.begin();i!=list.end();i++) { + std::vector list = this->selection->itemList(); + for (std::vector::const_iterator i=list.begin();i!=list.end();i++) { SPItem *item = SP_ITEM(*i); Geom::OptRect rect = item->desktopVisualBounds(); if (rect) { diff --git a/src/graphlayout.cpp b/src/graphlayout.cpp index 613440269..4d590173a 100644 --- a/src/graphlayout.cpp +++ b/src/graphlayout.cpp @@ -88,8 +88,8 @@ struct CheckProgress : TestConvergence { * Scans the items list and places those items that are * not connectors in filtered */ -void filterConnectors(SelContainer const &items, list &filtered) { - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ +void filterConnectors(std::vector const &items, list &filtered) { + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = SP_ITEM(*i); if(!isConnector(item)) { filtered.push_back(item); @@ -101,7 +101,7 @@ void filterConnectors(SelContainer const &items, list &filtered) { * connectors between them, and uses graph layout techniques to find * a nice layout */ -void graphlayout(SelContainer const &items) { +void graphlayout(std::vector const &items) { if(items.empty()) { return; } diff --git a/src/graphlayout.h b/src/graphlayout.h index c38f9471c..9794dd6b5 100644 --- a/src/graphlayout.h +++ b/src/graphlayout.h @@ -19,10 +19,10 @@ typedef struct _GSList GSList; class SPItem; -void graphlayout(SelContainer const &items); +void graphlayout(std::vector const &items); bool isConnector(SPItem const *const item); -void filterConnectors(SelContainer const &items, std::list &filtered); +void filterConnectors(std::vector const &items, std::list &filtered); #endif // SEEN_GRAPHLAYOUT_H diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 55fef5a4c..fc365c435 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -361,7 +361,7 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v /** * Hide all items that are not listed in list, recursively, skipping groups and defs. */ -static void hide_other_items_recursively(SPObject *o, const SelContainer &list, unsigned dkey) +static void hide_other_items_recursively(SPObject *o, const std::vector &list, unsigned dkey) { if ( SP_IS_ITEM(o) && !SP_IS_DEFS(o) @@ -387,7 +387,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned int (*status) (float, void *), void *data, bool force_overwrite, - const SelContainer &items_only) + const std::vector &items_only) { return sp_export_png_file(doc, filename, Geom::Rect(Geom::Point(x0,y0),Geom::Point(x1,y1)), width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only); @@ -399,7 +399,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned (*status)(float, void *), void *data, bool force_overwrite, - const SelContainer &items_only) + const std::vector &items_only) { g_return_val_if_fail(doc != NULL, EXPORT_ERROR); g_return_val_if_fail(filename != NULL, EXPORT_ERROR); diff --git a/src/helper/png-write.h b/src/helper/png-write.h index 47fad1b41..04ca85cd6 100644 --- a/src/helper/png-write.h +++ b/src/helper/png-write.h @@ -38,12 +38,12 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, double x0, double y0, double x1, double y1, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const SelContainer &items_only = SelContainer()); + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector &items_only = std::vector()); ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, Geom::Rect const &area, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const SelContainer &items_only = SelContainer()); + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector &items_only = std::vector()); #endif // SEEN_SP_PNG_WRITE_H diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 95a6b16dd..6cdf09180 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -505,8 +505,8 @@ LPEKnot::doEffect_path (std::vector const &path_in) static void collectPathsAndWidths (SPLPEItem const *lpeitem, std::vector &paths, std::vector &stroke_widths){ if (SP_IS_GROUP(lpeitem)) { - SelContainer item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); - for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + std::vector item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { SPObject *subitem = static_cast(*iter); if (SP_IS_LPE_ITEM(subitem)) { collectPathsAndWidths(SP_LPE_ITEM(subitem), paths, stroke_widths); diff --git a/src/main.cpp b/src/main.cpp index 25dc91f14..c62b9cd25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1156,7 +1156,7 @@ static int sp_process_file_list(GSList *fl) } if (sp_export_svg) { if (sp_export_text_to_path) { - SelContainer items; + std::vector items; SPRoot *root = doc->getRoot(); doc->ensureUpToDate(); for ( SPObject *iter = root->firstChild(); iter ; iter = iter->getNext()) { @@ -1169,8 +1169,8 @@ static int sp_process_file_list(GSList *fl) items.push_back(item); } - SelContainer selected; - SelContainer to_select; + std::vector selected; + std::vector to_select; sp_item_list_to_curves(items, selected, to_select); @@ -1435,7 +1435,7 @@ static int sp_do_export_png(SPDocument *doc) g_warning ("--export-use-hints can only be used with --export-id or --export-area-drawing; ignored."); } - SelContainer items; + std::vector items; Geom::Rect area; if (sp_export_id || sp_export_area_drawing) { @@ -1459,7 +1459,7 @@ static int sp_do_export_png(SPDocument *doc) return 1; } - items.push_front(SP_ITEM(o)); + items.push_back(SP_ITEM(o)); if (sp_export_id_only) { g_print("Exporting only object with id=\"%s\"; all other objects hidden\n", sp_export_id); @@ -1647,7 +1647,7 @@ static int sp_do_export_png(SPDocument *doc) if ((width >= 1) && (height >= 1) && (width <= PNG_UINT_31_MAX) && (height <= PNG_UINT_31_MAX)) { if( sp_export_png_file(doc, path.c_str(), area, width, height, dpi, - dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : SelContainer()) == 1 ) { + dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : std::vector()) == 1 ) { g_print("Bitmap saved as: %s\n", filename.c_str()); } else { g_warning("Bitmap failed to save to: %s", filename.c_str()); diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 960b5087b..830c3c1db 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -237,8 +237,8 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, // current selection (see the comment in SelTrans::centerRequest()) bool old_pref2 = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_ROTATION_CENTER); if (old_pref2) { - SelContainer rotationSource=_snapmanager->getRotationCenterSource(); - for ( SelContainer::const_iterator itemlist=rotationSource.begin();itemlist!=rotationSource.end();itemlist++) { + std::vector rotationSource=_snapmanager->getRotationCenterSource(); + for ( std::vector::const_iterator itemlist=rotationSource.begin();itemlist!=rotationSource.end();itemlist++) { if ((*i).item == reinterpret_cast(*itemlist)) { // don't snap to this item's rotation center _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_ROTATION_CENTER, false); diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index a5e71b720..ae1e0064f 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -51,13 +51,19 @@ inline bool less_than_objects(SPObject const *first, SPObject const *second) second->getRepr())<0; } +inline bool less_than_items(SPItem const *first, SPItem const *second) +{ + return sp_repr_compare_position(first->getRepr(), + second->getRepr())<0; +} + void sp_selected_path_combine(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); SPDocument *doc = desktop->getDocument(); - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); if (items.size() < 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to combine.")); @@ -70,23 +76,22 @@ sp_selected_path_combine(SPDesktop *desktop) items = sp_degroup_list (items); // descend into any groups in selection - SelContainer to_paths; - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + std::vector to_paths; + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++) { SPItem *item = (SPItem *) (*i); if (!dynamic_cast(item) && !dynamic_cast(item)) { - to_paths.push_front(item); + to_paths.push_back(item); } } - SelContainer converted; + std::vector converted; bool did = sp_item_list_to_curves(to_paths, items, converted); to_paths.clear(); - for (SelContainer::const_iterator i=converted.begin();i!=converted.end();i++) - items.push_front(doc->getObjectByRepr((Inkscape::XML::Node*)(*i))); + for (std::vector::const_iterator i=converted.begin();i!=converted.end();i++) + items.push_back((SPItem*)doc->getObjectByRepr((Inkscape::XML::Node*)(*i))); items = sp_degroup_list (items); // converting to path may have added more groups, descend again - items.sort(less_than_objects); - items.reverse(); + sort(items.begin(),items.end(),less_than_objects); assert(!items.empty()); // cannot be NULL because of list length check at top of function // remember the position, id, transform and style of the topmost path, they will be assigned to the combined one @@ -104,7 +109,7 @@ sp_selected_path_combine(SPDesktop *desktop) selection->clear(); } - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ SPItem *item = (SPItem *) (*i); SPPath *path = dynamic_cast(item); @@ -206,8 +211,8 @@ sp_selected_path_break_apart(SPDesktop *desktop) bool did = false; - SelContainer itemlist(selection->itemList()); - for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist(selection->itemList()); + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = (SPItem *) (*i); @@ -246,7 +251,7 @@ sp_selected_path_break_apart(SPDesktop *desktop) curve->unref(); - SelContainer reprs; + std::vector reprs; for (GSList *l = list; l != NULL; l = l->next) { curve = (SPCurve *) l->data; @@ -272,14 +277,13 @@ sp_selected_path_break_apart(SPDesktop *desktop) if (l == list) repr->setAttribute("id", id); - reprs.push_front(dynamic_cast(repr)); + reprs.push_back(repr); Inkscape::GC::release(repr); } - + //reverse selection->setReprList(reprs); - reprs.clear(); g_slist_free(list); g_free(style); g_free(path_effect); @@ -312,10 +316,10 @@ sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, b desktop->setWaitingCursor(); } - SelContainer selected(selection->itemList()); - SelContainer to_select; + std::vector selected(selection->itemList()); + std::vector to_select; selection->clear(); - SelContainer items(selected); + std::vector items(selected); did = sp_item_list_to_curves(items, selected, to_select); @@ -346,27 +350,24 @@ void sp_selected_to_lpeitems(SPDesktop *desktop) return; } - SelContainer selected(selection->itemList()); - SelContainer to_select; + std::vector selected(selection->itemList()); + std::vector to_select; selection->clear(); - SelContainer items(selected); + std::vector items(selected); sp_item_list_to_curves(items, selected, to_select, true); - items.clear(); selection->setReprList(to_select); selection->addList(selected); - to_select.clear(); - selected.clear(); } bool -sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelContainer &to_select, bool skip_all_lpeitems) +sp_item_list_to_curves(const std::vector &items, std::vector& selected, std::vector &to_select, bool skip_all_lpeitems) { bool did = false; - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = dynamic_cast(static_cast(*i)); g_assert(item != NULL); @@ -399,9 +400,9 @@ sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelCon Inkscape::XML::Node *repr = box3d_convert_to_group(box)->getRepr(); if (repr) { - to_select.push_front(dynamic_cast(repr)); + to_select.push_back(repr); did = true; - selected.remove(item); + selected.erase(find(selected.begin(),selected.end(),item)); } continue; @@ -409,10 +410,10 @@ sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelCon if (group) { group->removeAllPathEffects(true); - SelContainer item_list = sp_item_group_item_list(group); + std::vector item_list = sp_item_group_item_list(group); - SelContainer item_to_select; - SelContainer item_selected; + std::vector item_to_select; + std::vector item_selected; if (sp_item_list_to_curves(item_list, item_selected, item_to_select)) did = true; @@ -429,7 +430,7 @@ sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelCon continue; did = true; - selected.remove(item); + selected.erase(find(selected.begin(),selected.end(),item)); // remember the position of the item gint pos = item->getRepr()->position(); @@ -471,7 +472,7 @@ sp_item_list_to_curves(const SelContainer &items, SelContainer& selected, SelCon /* Buglet: We don't re-add the (new version of the) object to the selection of any other * desktops where it was previously selected. */ - to_select.push_front(dynamic_cast(repr)); + to_select.push_back(repr); Inkscape::GC::release(repr); } @@ -613,7 +614,7 @@ void sp_selected_path_reverse(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); - SelContainer items = selection->itemList(); + std::vector items = selection->itemList(); if (items.empty()) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select path(s) to reverse.")); @@ -627,7 +628,7 @@ sp_selected_path_reverse(SPDesktop *desktop) bool did = false; desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths...")); - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPPath *path = dynamic_cast(static_cast(*i)); if (!path) { diff --git a/src/path-chemistry.h b/src/path-chemistry.h index 388268af4..f454167a9 100644 --- a/src/path-chemistry.h +++ b/src/path-chemistry.h @@ -33,7 +33,7 @@ void sp_selected_path_to_curves (Inkscape::Selection *selection, SPDesktop *desk void sp_selected_to_lpeitems(SPDesktop *desktop); Inkscape::XML::Node *sp_selected_item_to_curved_repr(SPItem *item, guint32 text_grouping_policy); void sp_selected_path_reverse (SPDesktop *desktop); -bool sp_item_list_to_curves(const SelContainer &items, SelContainer &selected, SelContainer &to_select, bool skip_all_lpeitems = false); +bool sp_item_list_to_curves(const std::vector &items, std::vector &selected, std::vector &to_select, bool skip_all_lpeitems = false); #endif // SEEN_PATH_CHEMISTRY_H diff --git a/src/removeoverlap.cpp b/src/removeoverlap.cpp index 9009de5e9..7cb1694e3 100644 --- a/src/removeoverlap.cpp +++ b/src/removeoverlap.cpp @@ -38,14 +38,14 @@ namespace { * such that rectangular bounding boxes are separated by at least xGap * horizontally and yGap vertically */ -void removeoverlap(SelContainer const &items, double const xGap, double const yGap) { +void removeoverlap(std::vector const &items, double const xGap, double const yGap) { using Inkscape::Util::GSListConstIterator; - SelContainer selected(items); + std::vector selected(items); std::vector records; std::vector rs; Geom::Point const gap(xGap, yGap); - for (SelContainer::iterator it(selected.begin()); + for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it) { diff --git a/src/removeoverlap.h b/src/removeoverlap.h index d050ca9ef..d873663d1 100644 --- a/src/removeoverlap.h +++ b/src/removeoverlap.h @@ -15,6 +15,6 @@ typedef struct _GSList GSList; -void removeoverlap(SelContainer const &items, double xGap, double yGap); +void removeoverlap(std::vector const &items, double xGap, double yGap); #endif // SEEN_REMOVEOVERLAP_H diff --git a/src/selcue.cpp b/src/selcue.cpp index 0fab6e5a8..f48378cdc 100644 --- a/src/selcue.cpp +++ b/src/selcue.cpp @@ -96,15 +96,15 @@ void Inkscape::SelCue::_updateItemBboxes(Inkscape::Preferences *prefs) void Inkscape::SelCue::_updateItemBboxes(gint mode, int prefs_bbox) { - const SelContainer items = _selection->itemList(); + const std::vector items = _selection->itemList(); if (_item_bboxes.size() != items.size()) { _newItemBboxes(); return; } int bcount = 0; - SelContainer ll=_selection->itemList(); - for (SelContainer::const_iterator l=ll.begin();l!=ll.end();l++) { + std::vector ll=_selection->itemList(); + for (std::vector::const_iterator l=ll.begin();l!=ll.end();l++) { SPItem *item = static_cast(*l); SPCanvasItem* box = _item_bboxes[bcount ++]; @@ -146,8 +146,8 @@ void Inkscape::SelCue::_newItemBboxes() int prefs_bbox = prefs->getBool("/tools/bounding_box"); - SelContainer ll=_selection->itemList(); - for (SelContainer::const_iterator l=ll.begin();l!=ll.end();l++) { + std::vector ll=_selection->itemList(); + for (std::vector::const_iterator l=ll.begin();l!=ll.end();l++) { SPItem *item = static_cast(*l); Geom::OptRect const b = (prefs_bbox == 0) ? @@ -201,8 +201,8 @@ void Inkscape::SelCue::_newTextBaselines() } _text_baselines.clear(); - SelContainer ll=_selection->itemList(); - for (SelContainer::const_iterator l=ll.begin();l!=ll.end();l++) { + std::vector ll=_selection->itemList(); + for (std::vector::const_iterator l=ll.begin();l!=ll.end();l++) { SPItem *item = static_cast(*l); SPCanvasItem* baseline_point = NULL; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 9f27ca22e..f1c96b6b8 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -279,23 +279,21 @@ void SelectionHelper::fixSelection(SPDesktop *dt) Inkscape::Selection *selection = dt->getSelection(); - SelContainer items ; + std::vector items ; - SelContainer const selList = selection->itemList(); + std::vector const selList = selection->itemList(); - for( SelContainer::const_iterator i=selList.begin();i!=selList.end();i++ ) { + for( std::vector::const_reverse_iterator i=selList.rbegin();i!=selList.rend();i++ ) { SPItem *item = dynamic_cast(static_cast(*i)); if( item && !dt->isLayer(item) && (!item->isLocked())) { - items.push_front(item); + items.push_back(item); } } selection->setList(items); - - items.clear(); } } // namespace Inkscape @@ -305,7 +303,7 @@ void SelectionHelper::fixSelection(SPDesktop *dt) * Copies repr and its inherited css style elements, along with the accumulated transform 'full_t', * then prepends the copy to 'clip'. */ -static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, SelContainer &clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, std::vector &clip, Inkscape::XML::Document* xml_doc) { Inkscape::XML::Node *copy = repr->duplicate(xml_doc); @@ -321,17 +319,17 @@ static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t copy->setAttribute("transform", affinestr); g_free(affinestr); - clip.push_front(dynamic_cast(copy)); + clip.insert(clip.begin(),dynamic_cast(copy)); } -static void sp_selection_copy_impl(SelContainer const &items, SelContainer &clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_impl(std::vector const &items, std::vector &clip, Inkscape::XML::Document* xml_doc) { // Sort items: - SelContainer sorted_items(items); - sorted_items.sort(sp_object_compare_position); + std::vector sorted_items(items); + sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position); // Copy item reprs: - for (SelContainer::const_iterator i = sorted_items.begin();i!=sorted_items.end();i++) { + for (std::vector::const_iterator i = sorted_items.begin();i!=sorted_items.end();i++) { SPItem *item = dynamic_cast(SP_OBJECT(*i)); if (item) { sp_selection_copy_one(item->getRepr(), item->i2doc_affine(), clip, xml_doc); @@ -339,22 +337,22 @@ static void sp_selection_copy_impl(SelContainer const &items, SelContainer &clip g_assert_not_reached(); } } - - clip.reverse(); + std::vector tmp(clip); + for(int i=0;i sp_selection_paste_impl(SPDocument *doc, SPObject *parent, std::vector &clip) { Inkscape::XML::Document *xml_doc = doc->getReprDoc(); SPItem *parentItem = dynamic_cast(parent); g_assert(parentItem != NULL); - SelContainer copied; + std::vector copied; // add objects to document - for (SelContainer::const_iterator l=clip.begin();l!=clip.end();l++) { + for (std::vector::const_iterator l=clip.begin();l!=clip.end();l++) { Inkscape::XML::Node *repr = dynamic_cast(*l); Inkscape::XML::Node *copy = repr->duplicate(xml_doc); @@ -373,18 +371,18 @@ static SelContainer sp_selection_paste_impl(SPDocument *doc, SPObject *parent, S } parent->appendChildRepr(copy); - copied.push_front(dynamic_cast(copy)); + copied.push_back(copy); Inkscape::GC::release(copy); } return copied; } -static void sp_selection_delete_impl(SelContainer const &items, bool propagate = true, bool propagate_descendants = true) +static void sp_selection_delete_impl(std::vector const &items, bool propagate = true, bool propagate_descendants = true) { - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { sp_object_ref(static_cast(*i), NULL); } - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { SPItem *item = static_cast(*i); item->deleteObject(propagate, propagate_descendants); sp_object_unref(item, NULL); @@ -412,7 +410,7 @@ void sp_selection_delete(SPDesktop *desktop) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing was deleted.")); return; } - SelContainer selected(selection->itemList()); + std::vector selected(selection->itemList()); selection->clear(); sp_selection_delete_impl(selected); selected.clear(); @@ -470,7 +468,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) // them, just what we need sort(reprs.begin(),reprs.end(),sp_repr_compare_position); - SelContainer newsel; + std::vector newsel; std::vector old_ids; std::vector new_ids; @@ -500,7 +498,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) } } - newsel.push_front(dynamic_cast(copy)); + newsel.push_back(copy); Inkscape::GC::release(copy); } @@ -546,8 +544,6 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) } selection->setReprList(newsel); - - newsel.clear(); } void sp_edit_clear_all(Inkscape::Selection *selection) @@ -560,11 +556,10 @@ void sp_edit_clear_all(Inkscape::Selection *selection) SPGroup *group = dynamic_cast(selection->layers()->currentLayer()); g_return_if_fail(group != NULL); - SelContainer items = sp_item_group_item_list(group); + std::vector items = sp_item_group_item_list(group); - while (!items.empty()) { - reinterpret_cast(items.front())->deleteObject(); - items.pop_front(); + for(int i=0;i(items[i])->deleteObject(); } DocumentUndo::done(doc, SP_VERB_EDIT_CLEAR_ALL, @@ -581,7 +576,7 @@ void sp_edit_clear_all(Inkscape::Selection *selection) * onlysensitive - TRUE includes only non-locked items * ingroups - TRUE to recursively get grouped items children */ -SelContainer &get_all_items(SelContainer &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, SelContainer const &exclude) +std::vector &get_all_items(std::vector &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, std::vector const &exclude) { for ( SPObject *child = from->firstChild() ; child; child = child->getNext() ) { SPItem *item = dynamic_cast(child); @@ -592,7 +587,7 @@ SelContainer &get_all_items(SelContainer &list, SPObject *from, SPDesktop *deskt (exclude.empty() || exclude.end() == std::find(exclude.begin(),exclude.end(),child)) ) { - list.push_front(item); + list.insert(list.begin(),item); } if (ingroups || (item && desktop->isLayer(item))) { @@ -617,9 +612,9 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); - SelContainer items ; + std::vector items ; - SelContainer exclude; + std::vector exclude; if (invert) { exclude = selection->itemList(); } @@ -633,16 +628,16 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i (onlyvisible && dt->itemIsHidden(dynamic_cast(dt->currentLayer()))) ) return; - SelContainer all_items = sp_item_group_item_list(dynamic_cast(dt->currentLayer())); + std::vector all_items = sp_item_group_item_list(dynamic_cast(dt->currentLayer())); - for (SelContainer::const_iterator i=all_items.begin();i!=all_items.end();i++) { + for (std::vector::const_reverse_iterator i=all_items.rbegin();i!=all_items.rend();i++) { SPItem *item = dynamic_cast(static_cast(*i)); if (item && (!onlysensitive || !item->isLocked())) { if (!onlyvisible || !dt->itemIsHidden(item)) { if (!dt->isLayer(item)) { if (!invert || exclude.end() == std::find(exclude.begin(),exclude.end(),item)) { - items.push_front(item); // leave it in the list + items.push_back(item); // leave it in the list } } } @@ -653,12 +648,12 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i break; } case PREFS_SELECTION_LAYER_RECURSIVE: { - SelContainer x; + std::vector x; items = get_all_items(x, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude); break; } default: { - SelContainer x; + std::vector x; items = get_all_items(x, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude); break; } @@ -709,7 +704,7 @@ static void sp_selection_group_impl(std::vector p, Inkscap Inkscape::GC::release(spnew); topmost --; // only reduce count for those items deleted from topmost_parent } else { // move it to topmost_parent first - SelContainer temp_clip; + std::vector temp_clip; // At this point, current may already have no item, due to its being a clone whose original is already moved away // So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform @@ -729,11 +724,11 @@ static void sp_selection_group_impl(std::vector p, Inkscap sp_repr_unparent(current); // paste into topmost_parent (temporarily) - SelContainer copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), temp_clip); + std::vector copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), temp_clip); if (!temp_clip.empty())temp_clip.clear() ; if (!copied.empty()) { // if success, // take pasted object (now in topmost_parent) - Inkscape::XML::Node *in_topmost = dynamic_cast(copied.front()); + Inkscape::XML::Node *in_topmost = copied.back(); // make a copy Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc); // remove pasted @@ -800,10 +795,10 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) } // first check whether there is anything to ungroup - SelContainer old_select = selection->itemList(); - SelContainer new_select; + std::vector old_select = selection->itemList(); + std::vector new_select; GSList *groups = NULL; - for (SelContainer::const_iterator item = old_select.begin(); item!=old_select.end(); item++) { + for (std::vector::const_iterator item = old_select.begin(); item!=old_select.end(); item++) { SPItem *obj = static_cast(*item); if (dynamic_cast(obj)) { groups = g_slist_prepend(groups, obj); @@ -816,13 +811,13 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) return; } - SelContainer items(old_select); + std::vector items(old_select); selection->clear(); // If any of the clones refer to the groups, unlink them and replace them with successors // in the items list. GSList *clones_to_unlink = NULL; - for (SelContainer::const_iterator item = items.begin(); item!=items.end(); item++) { + for (std::vector::const_iterator item = items.begin(); item!=items.end(); item++) { SPUse *use = dynamic_cast(static_cast(*item)); SPItem *original = use; @@ -842,21 +837,21 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) for (GSList *item = clones_to_unlink; item; item = item->next) { SPUse *use = static_cast(item->data); - SelContainer::iterator items_node = std::find(items.begin(),items.end(), item->data); + std::vector::iterator items_node = std::find(items.begin(),items.end(), item->data); (*items_node) = use->unlink(); } g_slist_free(clones_to_unlink); // do the actual work - for (SelContainer::iterator item = items.begin(); item!=items.end(); item++) { + for (std::vector::iterator item = items.begin(); item!=items.end(); item++) { SPItem *obj = static_cast(*item); // ungroup only the groups marked earlier if (g_slist_find(groups, *item) != NULL) { - SelContainer children; + std::vector children; sp_item_group_ungroup(dynamic_cast(obj), children, false); // add the items resulting from ungrouping to the selection - new_select.splice(new_select.end(),children); + new_select.insert(new_select.end(),children.begin(),children.end()); (*item) = NULL; // zero out the original pointer, which is no longer valid } else { // if not a group, keep in the selection @@ -873,25 +868,24 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) } /** Replace all groups in the list with their member objects, recursively; returns a new list, frees old */ -SelContainer -sp_degroup_list(SelContainer &items) +std::vector +sp_degroup_list(std::vector &items) { - SelContainer out; + std::vector out; bool has_groups = false; - for (SelContainer::const_iterator item=items.begin();item!=items.end();item++) { + for (std::vector::const_iterator item=items.begin();item!=items.end();item++) { SPGroup *group = dynamic_cast(static_cast(*item)); if (!group) { - out.push_front(*item); + out.push_back(*item); } else { has_groups = true; - SelContainer members = sp_item_group_item_list(group); - for (SelContainer::const_iterator member=members.begin();member!=members.end();member++) { - out.push_front(*member); + std::vector members = sp_item_group_item_list(group); + for (std::vector::const_iterator member=members.begin();member!=members.end();member++) { + out.push_back(*member); } members.clear(); } } - out.reverse(); items.clear(); if (has_groups) { // recurse if we unwrapped a group - it may have contained others @@ -904,7 +898,7 @@ sp_degroup_list(SelContainer &items) /** If items in the list have a common parent, return it, otherwise return NULL */ static SPGroup * -sp_item_list_common_parent_group(SelContainer const items) +sp_item_list_common_parent_group(std::vector const items) { if (items.empty()) { return NULL; @@ -914,7 +908,7 @@ sp_item_list_common_parent_group(SelContainer const items) if (!dynamic_cast(parent)) { return NULL; } - for (SelContainer::const_iterator item=items.begin();item!=items.end();item++) { + for (std::vector::const_iterator item=items.begin();item!=items.end();item++) { if((*item)==items.front())continue; if (SP_OBJECT(*item)->parent != parent) { return NULL; @@ -926,12 +920,12 @@ sp_item_list_common_parent_group(SelContainer const items) /** Finds out the minimum common bbox of the selected items. */ static Geom::OptRect -enclose_items(SelContainer const &items) +enclose_items(std::vector const &items) { g_assert(!items.empty()); Geom::OptRect r; - for (SelContainer::const_iterator i = items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i = items.begin();i!=items.end();i++) { r.unionWith(static_cast(*i)->desktopVisualBounds()); } return r; @@ -956,7 +950,7 @@ int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *sec void sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) { - SelContainer items= selection->itemList(); + std::vector items= selection->itemList(); if (items.empty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select object(s) to raise.")); return; @@ -971,16 +965,16 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) Inkscape::XML::Node *grepr = const_cast(group->getRepr()); /* Construct reverse-ordered list of selected children. */ - SelContainer rev(items); - rev.sort(sp_item_repr_compare_position_obj); + std::vector rev(items); + sort(rev.begin(),rev.end(),sp_item_repr_compare_position); // Determine the common bbox of the selected items. Geom::OptRect selected = enclose_items(items); // Iterate over all objects in the selection (starting from top). if (selected) { - while (!rev.empty()) { - SPObject *child = reinterpret_cast(rev.front()); + for (std::vector::const_iterator item=rev.begin();item!=rev.end();item++) { + SPObject *child = reinterpret_cast(*item); // for each selected object, find the next sibling for (SPObject *newref = child->next; newref; newref = newref->next) { // if the sibling is an item AND overlaps our selection, @@ -997,7 +991,6 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) } } } - rev.pop_front(); } } else { rev.clear(); @@ -1017,7 +1010,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - SelContainer items = selection->itemList(); + std::vector items = selection->itemList(); SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { @@ -1039,7 +1032,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) { - SelContainer items = selection->itemList(); + std::vector items = selection->itemList(); if (items.empty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select object(s) to lower.")); return; @@ -1057,14 +1050,13 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) Geom::OptRect selected = enclose_items(items); /* Construct direct-ordered list of selected children. */ - SelContainer rev(items); - rev.sort(sp_item_repr_compare_position_obj); - rev.reverse(); + std::vector rev(items); + sort(rev.begin(),rev.end(),sp_item_repr_compare_position); // Iterate over all objects in the selection (starting from top). if (selected) { - while (!rev.empty()) { - SPObject *child = reinterpret_cast(rev.front()); + for (std::vector::const_reverse_iterator item=rev.rbegin();item!=rev.rend();item++) { + SPObject *child = reinterpret_cast(*item); // for each selected object, find the prev sibling for (SPObject *newref = prev_sibling(child); newref; newref = prev_sibling(newref)) { // if the sibling is an item AND overlaps our selection, @@ -1085,7 +1077,6 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) } } } - rev.pop_front(); } } else { rev.clear(); @@ -1105,7 +1096,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - SelContainer items =selection->itemList(); + std::vector items =selection->itemList(); SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { @@ -1268,8 +1259,8 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to remove live path effects from.")); return; } - SelContainer list=selection->itemList(); - for ( SelContainer::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) { + std::vector list=selection->itemList(); + for ( std::vector::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) { SPItem *item = reinterpret_cast(*itemlist); sp_selection_remove_livepatheffect_impl(item); @@ -1330,16 +1321,16 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) return; } - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); bool no_more = false; // Set to true, if no more layers above SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); if (next) { - SelContainer temp_clip; + std::vector temp_clip; sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); sp_selection_delete_impl(items, false, false); next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers - SelContainer copied; + std::vector copied; if (next) { copied = sp_selection_paste_impl(dt->getDocument(), next, temp_clip); } else { @@ -1375,16 +1366,16 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) return; } - const SelContainer items(selection->itemList()); + const std::vector items(selection->itemList()); bool no_more = false; // Set to true, if no more layers below SPObject *next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); if (next) { - SelContainer temp_clip; + std::vector temp_clip; sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers - SelContainer copied; + std::vector copied; if (next) { copied = sp_selection_paste_impl(dt->getDocument(), next, temp_clip); } else { @@ -1418,13 +1409,13 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) return; } - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); if (moveto) { - SelContainer temp_clip; + std::vector temp_clip; sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); - SelContainer copied = sp_selection_paste_impl(dt->getDocument(), moveto, temp_clip); + std::vector copied = sp_selection_paste_impl(dt->getDocument(), moveto, temp_clip); selection->setReprList(copied); copied.clear(); if (!temp_clip.empty()) temp_clip.clear(); @@ -1468,8 +1459,8 @@ static bool selection_contains_both_clone_and_original(Inkscape::Selection *selection) { bool clone_with_original = false; - SelContainer items = selection->itemList(); - for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + std::vector items = selection->itemList(); + for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { SPItem *item = dynamic_cast(static_cast(*l)); if (item) { clone_with_original |= selection_contains_original(item, selection); @@ -1513,8 +1504,8 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, Geom::Affine cons persp3d_apply_affine_transformation(transf_persp, affine); } - SelContainer items = selection->itemList(); - for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + std::vector items = selection->itemList(); + for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { SPItem *item = dynamic_cast(static_cast(*l)); if( dynamic_cast(item) ) { @@ -1784,9 +1775,9 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw) if (selection->isEmpty()) return; - SelContainer items = selection->itemList(); + std::vector items = selection->itemList(); Geom::Rotate const rot_90(Geom::Point(0, ccw ? 1 : -1)); // pos. or neg. rotation, depending on the value of ccw - for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { + for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { SPItem *item = dynamic_cast(static_cast(*l)); if (item) { sp_item_rotate_rel(item, rot_90); @@ -1843,15 +1834,15 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); bool ingroups = TRUE; - SelContainer x,y; - SelContainer all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); - SelContainer all_matches; + std::vector x,y; + std::vector all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); + std::vector all_matches; Inkscape::Selection *selection = desktop->getSelection(); - SelContainer items = selection->itemList(); - for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + std::vector items = selection->itemList(); + for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { SPItem *sel = dynamic_cast(static_cast(*sel_iter)); - SelContainer matches = all_list; + std::vector matches = all_list; if (fill) { matches = sp_get_same_fill_or_stroke_color(sel, matches, SP_FILL_COLOR); } @@ -1863,7 +1854,7 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES); matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_MARKERS); } - all_matches.splice(all_matches.end(), matches); + all_matches.insert(all_matches.end(), matches.begin(),matches.end()); } selection->clear(); @@ -1889,14 +1880,14 @@ void sp_select_same_object_type(SPDesktop *desktop) bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); bool ingroups = TRUE; - SelContainer x,y; - SelContainer all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); - SelContainer matches = all_list; + std::vector x,y; + std::vector all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); + std::vector matches = all_list; Inkscape::Selection *selection = desktop->getSelection(); - SelContainer items=selection->itemList(); - for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + std::vector items=selection->itemList(); + for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { SPItem *sel = dynamic_cast(static_cast(*sel_iter)); if (sel) { matches = sp_get_same_object_type(sel, matches); @@ -1927,13 +1918,13 @@ void sp_select_same_stroke_style(SPDesktop *desktop) bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); bool ingroups = TRUE; - SelContainer x,y; - SelContainer matches = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); + std::vector x,y; + std::vector matches = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y); Inkscape::Selection *selection = desktop->getSelection(); - SelContainer items=selection->itemList(); + std::vector items=selection->itemList(); - for (SelContainer::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { SPItem *sel = dynamic_cast(static_cast(*sel_iter)); if (sel) { matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_WIDTH); @@ -1953,14 +1944,14 @@ void sp_select_same_stroke_style(SPDesktop *desktop) * Find all items in src list that have the same fill or stroke style as sel * Return the list of matching items */ -SelContainer sp_get_same_fill_or_stroke_color(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type) +std::vector sp_get_same_fill_or_stroke_color(SPItem *sel, std::vector &src, SPSelectStrokeStyleType type) { - SelContainer matches ; + std::vector matches ; gboolean match = false; SPIPaint *sel_paint = (type == SP_FILL_COLOR) ? &(sel->style->fill) : &(sel->style->stroke); - for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) { + for (std::vector::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) { SPItem *iter = dynamic_cast(static_cast(*i)); if (iter) { SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke); @@ -2000,7 +1991,7 @@ SelContainer sp_get_same_fill_or_stroke_color(SPItem *sel, SelContainer &src, SP } if (match) { - matches.push_front(iter); + matches.push_back(iter); } } else { g_assert_not_reached(); @@ -2051,14 +2042,14 @@ static bool item_type_match (SPItem *i, SPItem *j) * Find all items in src list that have the same object type as sel by type * Return the list of matching items */ -SelContainer sp_get_same_object_type(SPItem *sel, SelContainer &src) +std::vector sp_get_same_object_type(SPItem *sel, std::vector &src) { - SelContainer matches; + std::vector matches; - for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) { + for (std::vector::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) { SPItem *item = dynamic_cast(static_cast(*i)); if (item && item_type_match(sel, item)) { - matches.push_front(item); + matches.push_back(item); } } return matches; @@ -2068,9 +2059,9 @@ SelContainer sp_get_same_object_type(SPItem *sel, SelContainer &src) * Find all items in src list that have the same stroke style as sel by type * Return the list of matching items */ -SelContainer sp_get_same_stroke_style(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type) +std::vector sp_get_same_stroke_style(SPItem *sel, std::vector &src, SPSelectStrokeStyleType type) { - SelContainer matches; + std::vector matches; gboolean match = false; SPStyle *sel_style = sel->style; @@ -2083,14 +2074,14 @@ SelContainer sp_get_same_stroke_style(SPItem *sel, SelContainer &src, SPSelectSt * Stroke width needs to handle transformations, so call this function * to get the transformed stroke width */ - SelContainer objects; + std::vector objects; SPStyle *sel_style_for_width = NULL; if (type == SP_STROKE_STYLE_WIDTH) { - objects.push_front(sel); + objects.push_back(sel); sel_style_for_width = new SPStyle(SP_ACTIVE_DOCUMENT); objects_query_strokewidth (objects, sel_style_for_width); } - for (SelContainer::const_iterator i=src.begin();i!=src.end();i++) { + for (std::vector::const_iterator i=src.begin();i!=src.end();i++) { SPItem *iter = dynamic_cast(static_cast(*i)); if (iter) { SPStyle *iter_style = iter->style; @@ -2099,8 +2090,8 @@ SelContainer sp_get_same_stroke_style(SPItem *sel, SelContainer &src, SPSelectSt if (type == SP_STROKE_STYLE_WIDTH) { match = (sel_style->stroke_width.set == iter_style->stroke_width.set); if (sel_style->stroke_width.set && iter_style->stroke_width.set) { - SelContainer objects; - objects.push_front(iter); + std::vector objects; + objects.insert(objects.begin(),iter); SPStyle tmp_style(SP_ACTIVE_DOCUMENT); objects_query_strokewidth (objects, &tmp_style); @@ -2130,7 +2121,7 @@ SelContainer sp_get_same_stroke_style(SPItem *sel, SelContainer &src, SPSelectSt } if (match) { - matches.push_front(iter); + matches.insert(matches.begin(),iter); } } else { g_assert_not_reached(); @@ -2386,11 +2377,11 @@ SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, template -SPItem *next_item_from_list(SPDesktop *desktop, SelContainer const items, +SPItem *next_item_from_list(SPDesktop *desktop, std::vector const items, SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) { SPObject *current=root; - for(SelContainer::const_iterator i = items.begin();i!=items.end();i++) { + for(std::vector::const_iterator i = items.begin();i!=items.end();i++) { SPItem *item = dynamic_cast(static_cast(*i)); if ( root->isAncestorOf(item) && ( !only_in_viewport || desktop->isWithinViewport(item) ) ) @@ -2590,7 +2581,7 @@ void sp_selection_clone(SPDesktop *desktop) // sorting items from different parents sorts each parent's subset without possibly mixing them, just what we need sort(reprs.begin(),reprs.end(),sp_repr_compare_position); - SelContainer newsel; + std::vector newsel; for(std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ Inkscape::XML::Node *sel_repr = *i; @@ -2609,7 +2600,7 @@ void sp_selection_clone(SPDesktop *desktop) // add the new clone to the top of the original's parent parent->appendChild(clone); - newsel.push_front(dynamic_cast(clone)); + newsel.push_back(clone); Inkscape::GC::release(clone); } @@ -2642,8 +2633,8 @@ sp_selection_relink(SPDesktop *desktop) // Get a copy of current selection. bool relinked = false; - SelContainer items=selection->itemList(); - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items=selection->itemList(); + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = static_cast(*i); if (dynamic_cast(item)) { @@ -2678,10 +2669,10 @@ sp_selection_unlink(SPDesktop *desktop) } // Get a copy of current selection. - SelContainer new_select; + std::vector new_select; bool unlinked = false; - SelContainer items=selection->itemList(); - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items=selection->itemList(); + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ SPItem *item = static_cast(*i); if (dynamic_cast(item)) { @@ -2698,7 +2689,7 @@ sp_selection_unlink(SPDesktop *desktop) if (!(dynamic_cast(item) || dynamic_cast(item))) { // keep the non-use item in the new selection - new_select.push_front(item); + new_select.push_back(item); continue; } @@ -2708,7 +2699,7 @@ sp_selection_unlink(SPDesktop *desktop) unlink = use->unlink(); // Unable to unlink use (external or invalid href?) if (!unlink) { - new_select.push_front(item); + new_select.push_back(item); continue; } } else /*if (SP_IS_TREF(use))*/ { @@ -2718,7 +2709,7 @@ sp_selection_unlink(SPDesktop *desktop) unlinked = true; // Add ungrouped items to the new selection. - new_select.push_front(unlink); + new_select.push_back(unlink); } if (!new_select.empty()) { // set new selection @@ -2747,7 +2738,7 @@ sp_select_clone_original(SPDesktop *desktop) // Check if other than two objects are selected - SelContainer items=selection->itemList(); + std::vector items=selection->itemList(); if (items.size() != 1 || !item) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, error); return; @@ -2845,8 +2836,8 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop) Inkscape::SVGOStringStream os; SPObject * firstItem = NULL; - SelContainer items=selection->itemList(); - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items=selection->itemList(); + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_SHAPE(*i) || SP_IS_TEXT(*i)) { if (firstItem) { os << "|"; @@ -2930,7 +2921,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) Geom::Point center( *c - corner ); // As defined by rotation center center[Geom::Y] = -center[Geom::Y]; - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); //items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); // Why needed? @@ -2948,10 +2939,10 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) } // Create a list of duplicates, to be pasted inside marker element. - SelContainer repr_copies; - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector repr_copies; + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); - repr_copies.push_front(dynamic_cast(dup)); + repr_copies.push_back(dup); } Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max())); @@ -2959,7 +2950,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) if (apply) { // Delete objects so that their clones don't get alerted; // the objects will be restored inside the marker element. - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPObject *item = reinterpret_cast(*i); item->deleteObject(false); } @@ -2987,8 +2978,8 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) static void sp_selection_to_guides_recursive(SPItem *item, bool wholegroups) { SPGroup *group = dynamic_cast(item); if (group && !dynamic_cast(item) && !wholegroups) { - SelContainer items=sp_item_group_item_list(group); - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items=sp_item_group_item_list(group); + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ sp_selection_to_guides_recursive(static_cast(*i), wholegroups); } } else { @@ -3004,7 +2995,7 @@ void sp_selection_to_guides(SPDesktop *desktop) SPDocument *doc = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); // we need to copy the list because it gets reset when objects are deleted - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); if (items.empty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to convert to guides.")); @@ -3019,7 +3010,7 @@ void sp_selection_to_guides(SPDesktop *desktop) // and its entry in the selection list is invalid (crash). // Therefore: first convert all, then delete all. - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ sp_selection_to_guides_recursive(static_cast(*i), wholegroups); } @@ -3282,9 +3273,9 @@ sp_selection_tile(SPDesktop *desktop, bool apply) move_p[Geom::Y] = -move_p[Geom::Y]; Geom::Affine move = Geom::Affine(Geom::Translate(move_p)); - SelContainer items (selection->itemList()); + std::vector items (selection->itemList()); - items.sort(sp_object_compare_position); + sort(items.begin(),items.end(),sp_object_compare_position); // bottommost object, after sorting SPObject *parent = SP_OBJECT(items.front())->parent; @@ -3304,19 +3295,17 @@ sp_selection_tile(SPDesktop *desktop, bool apply) gint pos = SP_OBJECT(items.front())->getRepr()->position(); // create a list of duplicates - SelContainer repr_copies; - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector repr_copies; + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); - repr_copies.push_front(dynamic_cast(dup)); + repr_copies.push_back(dup); } - // restore the z-order after prepends - repr_copies.reverse(); Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max())); if (apply) { // delete objects so that their clones don't get alerted; this object will be restored shortly - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPObject *item = reinterpret_cast(*i); item->deleteObject(false); } @@ -3385,12 +3374,12 @@ void sp_selection_untile(SPDesktop *desktop) return; } - SelContainer new_select; + std::vector new_select; bool did = false; - SelContainer items(selection->itemList()); - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items(selection->itemList()); + for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ SPItem *item = static_cast(*i); SPStyle *style = item->style; @@ -3427,7 +3416,7 @@ void sp_selection_untile(SPDesktop *desktop) Geom::Affine transform( i->transform * pat_transform ); i->doWriteTransform(i->getRepr(), transform); - new_select.push_front(i); + new_select.push_back(i); } else { g_assert_not_reached(); } @@ -3547,10 +3536,10 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) } // List of the items to show; all others will be hidden - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); // Sort items so that the topmost comes last - items.sort(sp_item_repr_compare_position_obj); + sort(items.begin(),items.end(),sp_item_repr_compare_position); // Generate a random value from the current time (you may create bitmap from the same object(s) // multiple times, and this is done so that they don't clash) @@ -3770,7 +3759,7 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) Inkscape::GC::release(spnew); topmost --; // only reduce count for those items deleted from topmost_parent } else { // move it to topmost_parent first - SelContainer temp_clip; + std::vector temp_clip; // At this point, current may already have no item, due to its being a clone whose original is already moved away // So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform @@ -3790,10 +3779,10 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) sp_repr_unparent(current); // paste into topmost_parent (temporarily) - SelContainer copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), temp_clip); + std::vector copied = sp_selection_paste_impl(doc, doc->getObjectByRepr(topmost_parent), temp_clip); if (!copied.empty()) { // if success, // take pasted object (now in topmost_parent) - Inkscape::XML::Node *in_topmost = dynamic_cast(copied.front()); + Inkscape::XML::Node *in_topmost = copied.back(); // make a copy Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc); // remove pasted @@ -3875,9 +3864,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ doc->ensureUpToDate(); - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); - items.sort(sp_object_compare_position); + sort(items.begin(),items.end(),sp_object_compare_position); // See lp bug #542004 selection->clear(); @@ -3886,7 +3875,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ GSList *mask_items = NULL; GSList *apply_to_items = NULL; GSList *items_to_delete = NULL; - SelContainer items_to_select; + std::vector items_to_select; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool topmost = prefs->getBool("/options/maskobject/topmost", true); @@ -3897,7 +3886,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // all selected items are used for mask, which is applied to a layer apply_to_items = g_slist_prepend(apply_to_items, desktop->currentLayer()); - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); @@ -3906,7 +3895,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ items_to_delete = g_slist_prepend(items_to_delete, item); } else { - items_to_select.push_front(item); + items_to_select.push_back((SPItem*)item); } } } else if (!topmost) { @@ -3919,16 +3908,16 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ items_to_delete = g_slist_prepend(items_to_delete, item); } - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { if(i==items.begin())continue; apply_to_items = g_slist_prepend(apply_to_items, *i); - items_to_select.push_front(*i); + items_to_select.push_back(*i); } } else { GSList *i = NULL; - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { apply_to_items = g_slist_prepend(apply_to_items, *i); - items_to_select.push_front(*i); + items_to_select.push_back(*i); } Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); @@ -3953,7 +3942,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = apply_to_items ; NULL != i ; i = i->next) { reprs_to_group.push_back(static_cast(i->data)->getRepr()); - items_to_select.remove(static_cast(i->data)); + items_to_select.erase(find(items_to_select.begin(),items_to_select.end(),static_cast(i->data))); } sp_selection_group_impl(reprs_to_group, group, xml_doc, doc); @@ -3963,7 +3952,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ apply_to_items = NULL; apply_to_items = g_slist_prepend(apply_to_items, doc->getObjectByRepr(group)); - items_to_select.push_front(doc->getObjectByRepr(group)); + items_to_select.push_back((SPItem*)(doc->getObjectByRepr(group))); Inkscape::GC::release(group); } @@ -4003,7 +3992,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::XML::Node *spnew = current->duplicate(xml_doc); gint position = current->position(); - items_to_select.remove(item); + items_to_select.erase(find(items_to_select.begin(),items_to_select.end(),item)); current->parent()->appendChild(group); sp_repr_unparent(current); group->appendChild(spnew); @@ -4012,7 +4001,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // Apply clip/mask to group instead apply_mask_to = group; - items_to_select.push_front(doc->getObjectByRepr(group)); + items_to_select.push_back((SPItem*)(doc->getObjectByRepr(group))); Inkscape::GC::release(spnew); Inkscape::GC::release(group); } @@ -4027,12 +4016,10 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = items_to_delete; NULL != i; i = i->next) { SPObject *item = reinterpret_cast(i->data); item->deleteObject(false); - items_to_select.remove(item); + items_to_select.erase(find(items_to_select.begin(),items_to_select.end(),item)); } g_slist_free(items_to_delete); - items_to_select.reverse(); - selection->addList(items_to_select); if (apply_clip_path) { @@ -4065,17 +4052,16 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { gchar const *attributeName = apply_clip_path ? "clip-path" : "mask"; std::map referenced_objects; - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); selection->clear(); GSList *items_to_ungroup = NULL; - SelContainer items_to_select(items); - items_to_select.reverse(); + std::vector items_to_select(items); // SPObject* refers to a group containing the clipped path or mask itself, // whereas SPItem* refers to the item being clipped or masked - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (remove_original) { // remember referenced mask/clippath, so orphaned masks can be moved back to document SPItem *item = reinterpret_cast(*i); @@ -4140,7 +4126,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { repr->setPosition((pos + 1) > 0 ? (pos + 1) : 0); SPItem *mask_item = static_cast(desktop->getDocument()->getObjectByRepr(repr)); - items_to_select.push_front(mask_item); + items_to_select.push_back(mask_item); // transform mask, so it is moved the same spot where mask was applied Geom::Affine transform(mask_item->transform); @@ -4155,10 +4141,10 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { for (GSList *i = items_to_ungroup ; NULL != i ; i = i->next) { SPGroup *group = dynamic_cast(static_cast(i->data)); if (group) { - items_to_select.remove(group); - SelContainer children; + items_to_select.erase(find(items_to_select.begin(),items_to_select.end(),group)); + std::vector children; sp_item_group_ungroup(group, children, false); - items_to_select.splice(items_to_select.begin(),children); + items_to_select.insert(items_to_select.end(),children.rbegin(),children.rend()); } else { g_assert_not_reached(); } @@ -4167,7 +4153,6 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { g_slist_free(items_to_ungroup); // rebuild selection - items_to_select.reverse(); selection->addList(items_to_select); if (apply_clip_path) { diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index bc317d556..2acd62c02 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -143,9 +143,9 @@ enum SPSelectStrokeStyleType { void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolean strok, gboolean style); void sp_select_same_stroke_style(SPDesktop *desktop); void sp_select_same_object_type(SPDesktop *desktop); -SelContainer sp_get_same_fill_or_stroke_color(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type); -SelContainer sp_get_same_stroke_style(SPItem *sel, SelContainer &src, SPSelectStrokeStyleType type); -SelContainer sp_get_same_object_type(SPItem *sel, SelContainer &src); +std::vector sp_get_same_fill_or_stroke_color(SPItem *sel, std::vector &src, SPSelectStrokeStyleType type); +std::vector sp_get_same_stroke_style(SPItem *sel, std::vector &src, SPSelectStrokeStyleType type); +std::vector sp_get_same_object_type(SPItem *sel, std::vector &src); void scroll_to_show_item(SPDesktop *desktop, SPItem *item); @@ -172,9 +172,9 @@ void unlock_all_in_all_layers(SPDesktop *dt); void unhide_all(SPDesktop *dt); void unhide_all_in_all_layers(SPDesktop *dt); -SelContainer &get_all_items(SelContainer &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, SelContainer const &exclude); +std::vector &get_all_items(std::vector &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, std::vector const &exclude); -SelContainer sp_degroup_list (SelContainer &items); +std::vector sp_degroup_list (std::vector &items); /* selection cycling */ typedef enum diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index 0625c4002..d86cfa700 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -40,13 +40,13 @@ #include "sp-spiral.h" // Returns a list of terms for the items to be used in the statusbar -char* collect_terms (const SelContainer &items) +char* collect_terms (const std::vector &items) { GSList *check = NULL; std::stringstream ss; bool first = true; - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPItem *item = dynamic_cast(reinterpret_cast(*iter)); if (item) { const char *term = item->displayName(); @@ -61,11 +61,11 @@ char* collect_terms (const SelContainer &items) } // Returns the number of terms in the list -static int count_terms (const SelContainer &items) +static int count_terms (const std::vector &items) { GSList *check = NULL; int count=0; - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPItem *item = dynamic_cast(reinterpret_cast(*iter)); if (item) { const char *term = item->displayName(); @@ -79,10 +79,10 @@ static int count_terms (const SelContainer &items) } // Returns the number of filtered items in the list -static int count_filtered (const SelContainer &items) +static int count_filtered (const std::vector &items) { int count=0; - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPItem *item = dynamic_cast(reinterpret_cast((*iter))); if (item) { count += item->isFiltered(); @@ -122,7 +122,7 @@ void SelectionDescriber::_selectionModified(Inkscape::Selection *selection, guin } void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *selection) { - SelContainer const items = selection->itemList(); + std::vector const items = selection->itemList(); if (items.empty()) { // no items _context.set(Inkscape::NORMAL_MESSAGE, _when_nothing); diff --git a/src/selection.cpp b/src/selection.cpp index cbde9a799..2e8251048 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -44,7 +44,7 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : _objs(SelContainer()), _reprs(std::vector()), - _items(SelContainer()), + _items(std::vector()), _layers(layers), _desktop(desktop), _selection_context(NULL), @@ -234,7 +234,7 @@ void Selection::_remove(SPObject *obj) { _objs.remove(obj); } -void Selection::setList(SelContainer const &list) { +void Selection::setList(std::vector const &list) { // Clear and add, or just clear with emit. if (!list.empty()) { _clear(); @@ -242,14 +242,14 @@ void Selection::setList(SelContainer const &list) { } else clear(); } -void Selection::addList(SelContainer const &list) { +void Selection::addList(std::vector const &list) { if (list.empty()) return; _invalidateCachedLists(); - for ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + for ( std::vector::const_iterator iter=list.begin();iter!=list.end();iter++ ) { SPObject *obj = reinterpret_cast(*iter); if (includes(obj)) continue; _add (obj); @@ -258,11 +258,11 @@ void Selection::addList(SelContainer const &list) { _emitChanged(); } -void Selection::setReprList(SelContainer const &list) { +void Selection::setReprList(std::vector const &list) { _clear(); - for ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) { - SPObject *obj=_objectForXMLNode(reinterpret_cast(*iter)); + for ( std::vector::const_reverse_iterator iter=list.rbegin();iter!=list.rend();iter++ ) { + SPObject *obj=_objectForXMLNode(*iter); if (obj) { _add(obj); } @@ -280,7 +280,7 @@ SelContainer const &Selection::list() { return _objs; } -SelContainer const &Selection::itemList() { +std::vector const &Selection::itemList() { if (!_items.empty()) { return _items; } @@ -288,18 +288,16 @@ SelContainer const &Selection::itemList() { for ( SelContainer::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { SPObject *obj=reinterpret_cast(*iter); if (SP_IS_ITEM(obj)) { - _items.push_front(SP_ITEM(obj)); + _items.push_back(SP_ITEM(obj)); } } - _items.reverse(); - return _items; } std::vector const &Selection::reprList() { if (!_reprs.empty()) { return _reprs; } - SelContainer list = itemList(); - for ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + std::vector list = itemList(); + for ( std::vector::const_iterator iter=list.begin();iter!=list.end();iter++ ) { SPObject *obj=reinterpret_cast(*iter); _reprs.push_back(obj->getRepr()); } @@ -340,7 +338,7 @@ SPObject *Selection::single() { } SPItem *Selection::singleItem() { - SelContainer const items=itemList(); + std::vector const items=itemList(); if ( items.size()==1) { return reinterpret_cast(items.front()); } else { @@ -357,11 +355,11 @@ SPItem *Selection::largestItem(Selection::CompareSize compare) { } SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { - SelContainer const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); gdouble max = sml ? 1e18 : 0; SPItem *ist = NULL; - for ( SelContainer::const_iterator i=items.begin();i!=items.end();i++ ) { + for ( std::vector::const_iterator i=items.begin();i!=items.end();i++ ) { Geom::OptRect obox = SP_ITEM(*i)->desktopPreferredBounds(); if (!obox || obox.isEmpty()) continue; Geom::Rect bbox = *obox; @@ -390,10 +388,10 @@ Geom::OptRect Selection::bounds(SPItem::BBoxType type) const Geom::OptRect Selection::geometricBounds() const { - SelContainer const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); Geom::OptRect bbox; - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { bbox.unionWith(SP_ITEM(*iter)->desktopGeometricBounds()); } return bbox; @@ -401,10 +399,10 @@ Geom::OptRect Selection::geometricBounds() const Geom::OptRect Selection::visualBounds() const { - SelContainer const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); Geom::OptRect bbox; - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { bbox.unionWith(SP_ITEM(*iter)->desktopVisualBounds()); } return bbox; @@ -422,10 +420,10 @@ Geom::OptRect Selection::preferredBounds() const Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const { Geom::OptRect bbox; - SelContainer const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); if (items.empty()) return bbox; - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPItem *item = SP_ITEM(*iter); bbox |= item->documentBounds(type); } @@ -436,7 +434,7 @@ Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const // If we have a selection of multiple items, then the center of the first item // will be returned; this is also the case in SelTrans::centerRequest() boost::optional Selection::center() const { - SelContainer const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); if (!items.empty()) { SPItem *first = reinterpret_cast(items.back()); // from the first item in selection if (first->isCenterSet()) { // only if set explicitly @@ -452,12 +450,12 @@ boost::optional Selection::center() const { } std::vector Selection::getSnapPoints(SnapPreferences const *snapprefs) const { - SelContainer const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center std::vector p; - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPItem *this_item = SP_ITEM(*iter); this_item->getSnappoints(p, &snapprefs_dummy); @@ -505,9 +503,9 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { } uint Selection::numberOfLayers() { - SelContainer const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); std::set layers; - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPObject *layer = _layers->layerForObject(SP_OBJECT(*iter)); layers.insert(layer); } @@ -515,9 +513,9 @@ uint Selection::numberOfLayers() { } guint Selection::numberOfParents() { - SelContainer const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); std::set parents; - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPObject *parent = SP_OBJECT(*iter)->parent; parents.insert(parent); } diff --git a/src/selection.h b/src/selection.h index f85c6346b..2d5e7c34a 100644 --- a/src/selection.h +++ b/src/selection.h @@ -170,21 +170,21 @@ public: * * @param objs the objects to select */ - void setList(SelContainer const &objs); + void setList(std::vector const &objs); /** * Adds the specified objects to selection, without deselecting first. * * @param objs the objects to select */ - void addList(SelContainer const &objs); + void addList(std::vector const &objs); /** * Clears the selection and selects the specified objects. * * @param repr a list of xml nodes for the items to select */ - void setReprList(std::list const &reprs); + void setReprList(std::vector const &reprs); /** Add items from an STL iterator range to the selection. * \param from the begin iterator @@ -256,7 +256,7 @@ public: /** Returns the list of selected objects. */ std::list const &list(); /** Returns the list of selected SPItems. */ - std::list const &itemList(); + std::vector const &itemList(); /** Returns a list of the xml nodes of all selected objects. */ /// \todo only returns reprs of SPItems currently; need a separate /// method for that @@ -378,7 +378,7 @@ private: mutable std::list _objs; mutable std::vector _reprs; - mutable std::list _items; + mutable std::vector _items; void add_box_perspective(SPBox3D *box); void add_3D_boxes_recursively(SPObject *obj); diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 8c06356db..0a428edf2 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -112,7 +112,7 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) : _opposite_for_bboxpoints(Geom::Point(0,0)), _origin_for_specpoints(Geom::Point(0,0)), _origin_for_bboxpoints(Geom::Point(0,0)), - _stamp_cache(SelContainer()), + _stamp_cache(std::vector()), _message_context(desktop->messageStack()), _bounding_box_prefs_observer(*this) { @@ -239,8 +239,8 @@ void Inkscape::SelTrans::setCenter(Geom::Point const &p) _center_is_set = true; // Write the new center position into all selected items - SelContainer items=_desktop->selection->itemList(); - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + std::vector items=_desktop->selection->itemList(); + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPItem *it = SP_ITEM(*iter); it->setCenter(p); // only set the value; updating repr and document_done will be done once, on ungrab @@ -269,8 +269,8 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s return; } - SelContainer items=_desktop->selection->itemList(); - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + std::vector items=_desktop->selection->itemList(); + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPItem *it = reinterpret_cast(sp_object_ref(SP_ITEM(*iter), NULL)); _items.push_back(it); _items_const.push_back(it); @@ -492,8 +492,8 @@ void Inkscape::SelTrans::ungrab() if (_center_is_set) { // we were dragging center; update reprs and commit undoable action - SelContainer items=_desktop->selection->itemList(); - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + std::vector items=_desktop->selection->itemList(); + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPItem *it = SP_ITEM(*iter); it->updateRepr(); } @@ -524,17 +524,17 @@ void Inkscape::SelTrans::stamp() /* stamping mode */ if (!_empty) { - SelContainer l; + std::vector l; if (!_stamp_cache.empty()) { l = _stamp_cache; } else { /* Build cache */ l = selection->itemList(); - l.sort(sp_object_compare_position); + sort(l.begin(),l.end(),sp_object_compare_position); _stamp_cache = l; } - for(SelContainer::const_iterator x=l.begin();x!=l.end();x++) { + for(std::vector::const_iterator x=l.begin();x!=l.end();x++) { SPItem *original_item = SP_ITEM(*x); Inkscape::XML::Node *original_repr = original_item->getRepr(); @@ -711,8 +711,8 @@ void Inkscape::SelTrans::handleClick(SPKnot */*knot*/, guint state, SPSelTransHa case HANDLE_CENTER: if (state & GDK_SHIFT_MASK) { // Unset the center position for all selected items - SelContainer items=_desktop->selection->itemList(); - for ( SelContainer::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + std::vector items=_desktop->selection->itemList(); + for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPItem *it = SP_ITEM(*iter); it->unsetCenter(); it->updateRepr(); @@ -1283,7 +1283,7 @@ gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state) // items will share a single center. While dragging that single center, it should never snap to the // centers of any of the selected objects. Therefore we will have to pass the list of selected items // to the snapper, to avoid self-snapping of the rotation center - SelContainer items = const_cast(_selection)->itemList(); + std::vector items = const_cast(_selection)->itemList(); SnapManager &m = _desktop->namedview->snap_manager; m.setup(_desktop); m.setRotationCenterSource(items); diff --git a/src/seltrans.h b/src/seltrans.h index 8f9c329ed..26c2e9cd9 100644 --- a/src/seltrans.h +++ b/src/seltrans.h @@ -187,7 +187,7 @@ private: SPCtrlLine *_l[4]; unsigned int _sel_changed_id; unsigned int _sel_modified_id; - SelContainer _stamp_cache; + std::vector _stamp_cache; Geom::Point _origin; ///< position of origin for transforms Geom::Point _point; ///< original position of the knot being used for the current transform diff --git a/src/snap.cpp b/src/snap.cpp index a7145b834..c711874d7 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -43,7 +43,7 @@ SnapManager::SnapManager(SPNamedView const *v) : object(this, 0), snapprefs(), _named_view(v), - _rotation_center_source_items(SelContainer()), + _rotation_center_source_items(std::vector()), _guide_to_ignore(NULL), _desktop(NULL), _snapindicator(true), @@ -1053,8 +1053,8 @@ void SnapManager::setupIgnoreSelection(SPDesktop const *desktop, _items_to_ignore.clear(); Inkscape::Selection *sel = _desktop->selection; - SelContainer const items = sel->itemList(); - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + std::vector const items = sel->itemList(); + for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { _items_to_ignore.push_back(static_cast(*i)); } } diff --git a/src/snap.h b/src/snap.h index 012eb072b..49bdbfa7c 100644 --- a/src/snap.h +++ b/src/snap.h @@ -145,8 +145,8 @@ public: // of this rotation center; this reference is used to make sure that we do not snap a rotation // center to itself // NOTE: Must be called after calling setup(), not before! - void setRotationCenterSource(const SelContainer &items) {_rotation_center_source_items = items;} - SelContainer getRotationCenterSource() {return _rotation_center_source_items;} + void setRotationCenterSource(const std::vector &items) {_rotation_center_source_items = items;} + const std::vector &getRotationCenterSource() {return _rotation_center_source_items;} // freeSnapReturnByRef() is preferred over freeSnap(), because it only returns a // point if snapping has occurred (by overwriting p); otherwise p is untouched @@ -490,7 +490,7 @@ protected: private: std::vector _items_to_ignore; ///< Items that should not be snapped to, for example the items that are currently being dragged. Set using the setup() method - SelContainer _rotation_center_source_items; // to avoid snapping a rotation center to itself + std::vector _rotation_center_source_items; // to avoid snapping a rotation center to itself SPGuide *_guide_to_ignore; ///< A guide that should not be snapped to, e.g. the guide that is currently being dragged SPDesktop const *_desktop; bool _snapindicator; ///< When true, an indicator will be drawn at the position that was being snapped to diff --git a/src/sp-conn-end.cpp b/src/sp-conn-end.cpp index bd139277d..d09699f41 100644 --- a/src/sp-conn-end.cpp +++ b/src/sp-conn-end.cpp @@ -50,8 +50,8 @@ static bool try_get_intersect_point_with_item_recursive(Geom::PathVector& conn_p // consider all first-order children double child_pos = 0.0; - SelContainer g = sp_item_group_item_list(group); - for (SelContainer::const_iterator i = g.begin();i!=g.end();i++) { + std::vector g = sp_item_group_item_list(group); + for (std::vector::const_iterator i = g.begin();i!=g.end();i++) { SPItem* child_item = SP_ITEM(*i); try_get_intersect_point_with_item_recursive(conn_pv, child_item, item_transform * child_item->transform, child_pos); diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index e6531c6be..f09a4ee47 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -387,7 +387,7 @@ void SPGroup::snappoints(std::vector &p, Inkscape: void -sp_item_group_ungroup (SPGroup *group, SelContainer &children, bool do_done) +sp_item_group_ungroup (SPGroup *group, std::vector &children, bool do_done) { g_return_if_fail (group != NULL); @@ -547,7 +547,7 @@ sp_item_group_ungroup (SPGroup *group, SelContainer &children, bool do_done) Inkscape::GC::release(repr); if (!children.empty() && item) { - children.push_front(dynamic_cast(item)); + children.insert(children.begin(),item); } items = g_slist_remove (items, items->data); @@ -562,17 +562,16 @@ sp_item_group_ungroup (SPGroup *group, SelContainer &children, bool do_done) * some API for list aspect of SPGroup */ -SelContainer sp_item_group_item_list(SPGroup * group) +std::vector sp_item_group_item_list(SPGroup * group) { - SelContainer s; + std::vector s; g_return_val_if_fail(group != NULL, s); for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) { if ( dynamic_cast(o) ) { - s.push_front(o); + s.push_back((SPItem*)o); } } - s.reverse(); return s; } @@ -813,9 +812,9 @@ void SPGroup::update_patheffect(bool write) { g_message("sp_group_update_patheffect: %p\n", lpeitem); #endif - SelContainer const item_list = sp_item_group_item_list(this); + std::vector const item_list = sp_item_group_item_list(this); - for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { SPObject *subitem = static_cast(*iter); SPLPEItem *lpeItem = dynamic_cast(subitem); @@ -841,9 +840,9 @@ void SPGroup::update_patheffect(bool write) { static void sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) { - SelContainer const item_list = sp_item_group_item_list(group); + std::vector const item_list = sp_item_group_item_list(group); - for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { SPObject *subitem = static_cast(*iter); SPGroup *subGroup = dynamic_cast(subitem); diff --git a/src/sp-item-group.h b/src/sp-item-group.h index 9a5ee0161..dcabea78c 100644 --- a/src/sp-item-group.h +++ b/src/sp-item-group.h @@ -96,10 +96,10 @@ public: virtual void update_patheffect(bool write); }; -void sp_item_group_ungroup (SPGroup *group, SelContainer &children, bool do_done = true); +void sp_item_group_ungroup (SPGroup *group, std::vector &children, bool do_done = true); -SelContainer sp_item_group_item_list (SPGroup *group); +std::vector sp_item_group_item_list (SPGroup *group); SPObject *sp_item_group_get_child_by_name (SPGroup *group, SPObject *ref, const char *name); #endif diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index 1305efd83..1f4704e22 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -353,8 +353,8 @@ sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem) sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild())); } if (SP_IS_GROUP(lpeitem)) { - SelContainer item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); - for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + std::vector item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { SPObject *subitem = static_cast(*iter); if (SP_IS_LPE_ITEM(subitem)) { sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(subitem)); @@ -387,8 +387,8 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem) sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild())); } } - SelContainer item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); - for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + std::vector item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { SPObject *subitem = static_cast(*iter); if (SP_IS_LPE_ITEM(subitem)) { sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(subitem)); @@ -680,8 +680,8 @@ SPLPEItem::apply_to_clippath(SPItem *item) } } if(SP_IS_GROUP(item)){ - SelContainer item_list = sp_item_group_item_list(SP_GROUP(item)); - for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + std::vector item_list = sp_item_group_item_list(SP_GROUP(item)); + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { SPObject *subitem = static_cast(*iter); apply_to_clippath(SP_ITEM(subitem)); } @@ -732,8 +732,8 @@ SPLPEItem::apply_to_mask(SPItem *item) } } if(SP_IS_GROUP(item)){ - SelContainer item_list = sp_item_group_item_list(SP_GROUP(item)); - for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + std::vector item_list = sp_item_group_item_list(SP_GROUP(item)); + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { SPObject *subitem = static_cast(*iter); apply_to_mask(SP_ITEM(subitem)); } @@ -746,8 +746,8 @@ SPLPEItem::apply_to_clip_or_mask_group(SPItem *group, SPItem *item) if (!SP_IS_GROUP(group)) { return; } - SelContainer item_list = sp_item_group_item_list(SP_GROUP(group)); - for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + std::vector item_list = sp_item_group_item_list(SP_GROUP(group)); + for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { SPObject *subitem = static_cast(*iter); if (SP_IS_GROUP(subitem)) { apply_to_clip_or_mask_group(SP_ITEM(subitem), item); diff --git a/src/sp-marker.cpp b/src/sp-marker.cpp index 66b445265..5bb80bd39 100644 --- a/src/sp-marker.cpp +++ b/src/sp-marker.cpp @@ -429,7 +429,7 @@ sp_marker_hide (SPMarker *marker, unsigned int key) } -const gchar *generate_marker(SelContainer &reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move) +const gchar *generate_marker(std::vector &reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move) { Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -452,8 +452,8 @@ const gchar *generate_marker(SelContainer &reprs, Geom::Rect bounds, SPDocument const gchar *mark_id = repr->attribute("id"); SPObject *mark_object = document->getObjectById(mark_id); - for (SelContainer::const_iterator i=reprs.begin();i!=reprs.end();i++){ - Inkscape::XML::Node *node = (Inkscape::XML::Node *)(*i); + for (std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ + Inkscape::XML::Node *node = (*i); SPItem *copy = SP_ITEM(mark_object->appendChildRepr(node)); Geom::Affine dup_transform; diff --git a/src/sp-marker.h b/src/sp-marker.h index 594c164c5..56cbaf94f 100644 --- a/src/sp-marker.h +++ b/src/sp-marker.h @@ -101,7 +101,7 @@ Inkscape::DrawingItem *sp_marker_show_instance (SPMarker *marker, Inkscape::Draw unsigned int key, unsigned int pos, Geom::Affine const &base, float linewidth); void sp_marker_hide (SPMarker *marker, unsigned int key); -const char *generate_marker (SelContainer &reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move); +const char *generate_marker (std::vector &reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move); SPObject *sp_marker_fork_if_necessary(SPObject *marker); #endif diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index d5eff9796..33d66c5dc 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -408,7 +408,7 @@ sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool se g_free(c); } -const gchar *pattern_tile(const SelContainer &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) +const gchar *pattern_tile(const std::vector &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) { Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -426,7 +426,7 @@ const gchar *pattern_tile(const SelContainer &reprs, Geom::Rect bounds, SPDocume const gchar *pat_id = repr->attribute("id"); SPObject *pat_object = document->getObjectById(pat_id); - for (SelContainer::const_iterator i=reprs.begin();i!=reprs.end();i++){ + for (std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ Inkscape::XML::Node *node = (Inkscape::XML::Node *)(*i); SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node)); diff --git a/src/sp-pattern.h b/src/sp-pattern.h index 0e2b058b5..34dd5a05b 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -89,7 +89,7 @@ SPPattern *pattern_chain (SPPattern *pattern); SPPattern *sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const char *property); void sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set); -const char *pattern_tile (const SelContainer &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); +const char *pattern_tile (const std::vector &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); SPPattern *pattern_getroot (SPPattern *pat); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 107dfc629..6e47dfff3 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -331,7 +331,7 @@ void sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb, const Glib::ustring description) { SPDocument *doc = selection->layers()->getDocument(); - SelContainer il= selection->itemList(); + std::vector il= selection->itemList(); // allow union on a single object for the purpose of removing self overlapse (svn log, revision 13334) if ( (il.size() < 2) && (bop != bool_op_union)) { @@ -403,7 +403,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool // first check if all the input objects have shapes // otherwise bail out - for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++) + for (std::vector::const_iterator l = il.begin(); l != il.end(); l++) { SPItem *item = SP_ITEM(*l); if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item) && !SP_IS_FLOWTEXT(item)) @@ -421,7 +421,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool int curOrig; { curOrig = 0; - for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++) + for (std::vector::const_iterator l = il.begin(); l != il.end(); l++) { // apply live path effects prior to performing boolean operation if (SP_IS_LPE_ITEM(*l)) { @@ -474,7 +474,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool theShapeA->ConvertToShape(theShape, origWind[0]); curOrig = 1; - for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){ + for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ if(*l==il.front())continue; originaux[curOrig]->ConvertWithBackData(0.1); @@ -671,7 +671,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool if (res->descr_cmd.size() <= 1) { // only one command, presumably a moveto: it isn't a path - for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){ + for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ SP_OBJECT(*l)->deleteObject(); } DocumentUndo::done(doc, SP_VERB_NONE, description); @@ -720,7 +720,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool gchar *desc = source->desc(); // remove source paths selection->clear(); - for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){ + for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ // if this is the bottommost object, if (!strcmp(reinterpret_cast(*l)->getRepr()->attribute("id"), id)) { // delete it so that its clones don't get alerted; this object will be restored shortly, with the same id @@ -1157,8 +1157,8 @@ sp_selected_path_outline(SPDesktop *desktop) } bool did = false; - SelContainer il(selection->itemList()); - for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){ + std::vector il(selection->itemList()); + for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ SPItem *item = SP_ITEM(*l); if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item)) @@ -1769,8 +1769,8 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) } bool did = false; - SelContainer il(selection->itemList()); - for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){ + std::vector il(selection->itemList()); + for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ SPItem *item = SP_ITEM(*l); SPCurve *curve = NULL; @@ -1967,7 +1967,7 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) static bool sp_selected_path_simplify_items(SPDesktop *desktop, - Inkscape::Selection *selection, SelContainer &items, + Inkscape::Selection *selection, std::vector &items, float threshold, bool justCoalesce, float angleLimit, bool breakableAngles, bool modifySelection); @@ -1986,7 +1986,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop, //If this is a group, do the children instead if (SP_IS_GROUP(item)) { - SelContainer items = sp_item_group_item_list(SP_GROUP(item)); + std::vector items = sp_item_group_item_list(SP_GROUP(item)); return sp_selected_path_simplify_items(desktop, selection, items, threshold, justCoalesce, @@ -2111,7 +2111,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop, bool sp_selected_path_simplify_items(SPDesktop *desktop, - Inkscape::Selection *selection, SelContainer &items, + Inkscape::Selection *selection, std::vector &items, float threshold, bool justCoalesce, float angleLimit, bool breakableAngles, bool modifySelection) @@ -2142,7 +2142,7 @@ sp_selected_path_simplify_items(SPDesktop *desktop, // set "busy" cursor desktop->setWaitingCursor(); - for (SelContainer::const_iterator l = items.begin(); l != items.end(); l++){ + for (std::vector::const_iterator l = items.begin(); l != items.end(); l++){ SPItem *item = SP_ITEM(*l); if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item))) @@ -2191,7 +2191,7 @@ sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool ju return; } - SelContainer items(selection->itemList()); + std::vector items(selection->itemList()); bool didSomething = sp_selected_path_simplify_items(desktop, selection, items, threshold, diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index 391e255a5..33192a330 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -43,8 +43,8 @@ using Inkscape::DocumentUndo; static SPItem * flowtext_in_selection(Inkscape::Selection *selection) { - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_FLOWTEXT(*i)) return ((SPItem *) *i); } @@ -54,8 +54,8 @@ flowtext_in_selection(Inkscape::Selection *selection) static SPItem * text_or_flowtext_in_selection(Inkscape::Selection *selection) { - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) return ((SPItem *) *i); } @@ -65,8 +65,8 @@ text_or_flowtext_in_selection(Inkscape::Selection *selection) static SPItem * shape_in_selection(Inkscape::Selection *selection) { - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_SHAPE(*i)) return ((SPItem *) *i); } @@ -196,8 +196,8 @@ text_remove_from_path() } bool did = false; - SelContainer items(selection->itemList()); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items(selection->itemList()); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPObject *obj = SP_OBJECT(*i); if (SP_IS_TEXT_TEXTPATH(obj)) { @@ -260,8 +260,8 @@ text_remove_all_kerns() bool did = false; - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPObject *obj = SP_OBJECT(*i); if (!SP_IS_TEXT(obj) && !SP_IS_TSPAN(obj) && !SP_IS_FLOWTEXT(obj)) { @@ -320,8 +320,8 @@ text_flow_into_shape() g_return_if_fail(SP_IS_FLOWREGION(object)); /* Add clones */ - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_SHAPE(item)){ Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); @@ -392,11 +392,11 @@ text_unflow () return; } - SelContainer new_objs; + std::vector new_objs; GSList *old_objs = NULL; - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ if (!SP_IS_FLOWTEXT(SP_OBJECT(*i))) { continue; @@ -443,7 +443,7 @@ text_unflow () SPText *text = SP_TEXT(text_object); text->_adjustFontsizeRecursive(text, ex); - new_objs.push_front(text_object); + new_objs.push_back((SPItem*)text_object); old_objs = g_slist_prepend (old_objs, flowtext); Inkscape::GC::release(rtext); @@ -478,9 +478,9 @@ flowtext_to_text() bool did = false; - SelContainer reprs; - SelContainer items(selection->itemList()); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector reprs; + std::vector items(selection->itemList()); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = (SPItem *) *i; @@ -510,7 +510,7 @@ flowtext_to_text() Inkscape::GC::release(repr); item->deleteObject(); - reprs.push_front(dynamic_cast(repr)); + reprs.push_back(repr); } diff --git a/src/text-editing.cpp b/src/text-editing.cpp index 44d90b4ae..88210dc0b 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -67,8 +67,8 @@ static void te_update_layout_now (SPItem *item) void te_update_layout_now_recursive(SPItem *item) { if (SP_IS_GROUP(item)) { - SelContainer item_list = sp_item_group_item_list(SP_GROUP(item)); - for(SelContainer::const_iterator i=item_list.begin();i!=item_list.end();i++){ + std::vector item_list = sp_item_group_item_list(SP_GROUP(item)); + for(std::vector::const_iterator i=item_list.begin();i!=item_list.end();i++){ SPItem* list_item = static_cast(*i); te_update_layout_now_recursive(list_item); } diff --git a/src/trace/trace.cpp b/src/trace/trace.cpp index 2becca5cc..4853f127c 100644 --- a/src/trace/trace.cpp +++ b/src/trace/trace.cpp @@ -65,7 +65,7 @@ SPImage *Tracer::getSelectedSPImage() if (sioxEnabled) { SPImage *img = NULL; - SelContainer const list = sel->itemList(); + std::vector const list = sel->itemList(); std::vector items; sioxShapes.clear(); @@ -74,7 +74,7 @@ SPImage *Tracer::getSelectedSPImage() them as bottom-to-top so that we can discover the image and any SPItems above it */ - for (SelContainer::const_iterator i=list.begin() ; list.end()!=i ; i++) + for (std::vector::const_iterator i=list.begin() ; list.end()!=i ; i++) { if (!SP_IS_ITEM(*i)) { diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 20b43af3b..6c15121c2 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -523,8 +523,8 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a // resize each object in the selection if (separately) { - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (item) { Geom::OptRect obj_size = item->desktopVisualBounds(); @@ -579,8 +579,8 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) desktop->doc()->importDefs(tempdoc); // make sure all selected items are converted to paths first (i.e. rectangles) sp_selected_to_lpeitems(desktop); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); _applyPathEffect(item, effectstack); } @@ -662,8 +662,8 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) { // copy the defs used by all items - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (item) { _copyUsedDefs(item); @@ -673,10 +673,10 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) } // copy the representation of the items - SelContainer sorted_items(itemlist); - sorted_items.sort(sp_object_compare_position); + std::vector sorted_items(itemlist); + sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position); - for(SelContainer::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ + for(std::vector::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ SPItem *item = SP_ITEM(*i); if (item) { Inkscape::XML::Node *obj = item->getRepr(); @@ -1157,7 +1157,7 @@ void ClipboardManagerImpl::_onGet(Gtk::SelectionData &sel, guint /*info*/) sp_repr_get_double(nv, "inkscape:pageopacity", &opacity); bgcolor |= SP_COLOR_F_TO_U(opacity); } - SelContainer x; + std::vector x; sp_export_png_file(_clipboardSPDoc, filename, area, width, height, dpi, dpi, bgcolor, NULL, NULL, true, x); } else diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 562bc28b7..34dbd150b 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -98,7 +98,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) bool sel_as_group = prefs->getBool("/dialogs/align/sel-as-groups"); using Inkscape::Util::GSListConstIterator; - SelContainer selected(selection->itemList()); + std::vector selected(selection->itemList()); if (selected.empty()) return; const Coeffs &a = _allCoeffs[index]; @@ -148,7 +148,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) b = selection->preferredBounds(); //Move each item in the selected list separately - for (SelContainer::iterator it(selected.begin()); + for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it) { SPItem* item=static_cast (*it); @@ -251,18 +251,18 @@ private : if (!selection) return; using Inkscape::Util::GSListConstIterator; - SelContainer selected(selection->itemList()); + std::vector selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects - SelContainer::iterator second(selected.begin()); + std::vector::iterator second(selected.begin()); ++second; if (second == selected.end()) return; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int prefs_bbox = prefs->getBool("/tools/bounding_box"); std::vector< BBoxSort > sorted; - for (SelContainer::iterator it(selected.begin()); + for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it) {SPItem *item=static_cast(*it); @@ -540,10 +540,6 @@ private : return (a->isSiblingOf(b)); } - static bool local_obj_compare(SPObject* a,SPObject* b){ - return ActionExchangePositions::sort_compare(static_cast(a),static_cast(b)); - } - virtual void on_button_click() { SPDesktop *desktop = _dialog.getDesktop(); @@ -553,7 +549,7 @@ private : if (!selection) return; using Inkscape::Util::GSListConstIterator; - SelContainer selected(selection->itemList()); + std::vector selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects @@ -571,9 +567,9 @@ private : } else { // sorting by ZOrder is outomatically done by not setting the center center.reset(); } - selected.sort(local_obj_compare); + sort(selected.begin(),selected.end(),sort_compare); } - SelContainer::iterator it(selected.begin()); + std::vector::iterator it(selected.begin()); SPItem* item=static_cast(*it); Geom::Point p1 = (item)->getCenter(); for (++it ;it != selected.end(); ++it) @@ -619,7 +615,7 @@ private : Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - SelContainer x(_dialog.getDesktop()->getSelection()->itemList()); + std::vector x(_dialog.getDesktop()->getSelection()->itemList()); unclump (x); // restore compensation setting @@ -651,7 +647,7 @@ private : if (!selection) return; using Inkscape::Util::GSListConstIterator; - SelContainer selected(selection->itemList()); + std::vector selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects @@ -675,7 +671,7 @@ private : int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - for (SelContainer::iterator it(selected.begin()); + for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it) { @@ -750,7 +746,7 @@ private : if (!selection) return; using Inkscape::Util::GSListConstIterator; - SelContainer selected(selection->itemList()); + std::vector selected(selection->itemList()); if (selected.empty()) return; //Check 2 or more selected objects @@ -761,7 +757,7 @@ private : std::vector sorted; - for (SelContainer::iterator it(selected.begin()); + for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it) { @@ -805,7 +801,7 @@ private : } } else { - for (SelContainer::iterator it(selected.begin()); + for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it) { diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index abfab8b19..680757373 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -2104,16 +2104,17 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *) SPObject *obj = selection->singleItem(); SPObject *parent = obj->parent; - SelContainer to_unclump; // not including the original + std::vector to_unclump; // not including the original for (SPObject *child = parent->firstChild(); child != NULL; child = child->next) { if (clonetiler_is_a_clone_of (child, obj)) { - to_unclump.push_front(child); + to_unclump.push_back((SPItem*)child); } } desktop->getDocument()->ensureUpToDate(); - + std::vector tu2(to_unclump); + for(int i=0;igetDocument(), SP_VERB_DIALOG_CLONETILER, diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 0667ba721..32eed088c 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -1024,8 +1024,8 @@ void Export::onExport () gint export_count = 0; - SelContainer itemlist=desktop->getSelection()->itemList(); - for(SelContainer::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;i++){ + std::vector itemlist=desktop->getSelection()->itemList(); + for(std::vector::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;i++){ SPItem *item = reinterpret_cast(*i); prog_dlg->set_data("current", GINT_TO_POINTER(n)); @@ -1064,7 +1064,7 @@ void Export::onExport () _("Exporting file %s..."), safeFile), desktop); MessageCleaner msgFlashCleanup(desktop->messageStack()->flashF(Inkscape::IMMEDIATE_MESSAGE, _("Exporting file %s..."), safeFile), desktop); - SelContainer x; + std::vector x; if (!sp_export_png_file (doc, path.c_str(), *area, width, height, dpi, dpi, nv->pagecolor, @@ -1154,7 +1154,7 @@ void Export::onExport () prog_dlg->set_data("total", GINT_TO_POINTER(0)); /* Do export */ - SelContainer x; + std::vector x; ExportResult status = sp_export_png_file(desktop->getDocument(), path.c_str(), Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi, nv->pagecolor, diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index f67c1d173..a6312140d 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1465,8 +1465,8 @@ void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel) } std::set used; - SelContainer itemlist=sel->itemList(); - for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + std::vector itemlist=sel->itemList(); + for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { SPObject *obj = SP_OBJECT (*i); SPStyle *style = obj->style; if (!style || !SP_IS_ITEM(obj)) { @@ -1545,8 +1545,8 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri if((*iter)[_columns.sel] == 1) filter = 0; - SelContainer itemlist=sel->itemList(); - for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + std::vector itemlist=sel->itemList(); + for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { SPItem * item = SP_ITEM(*i); SPStyle *style = item->style; g_assert(style != NULL); @@ -1649,9 +1649,9 @@ void FilterEffectsDialog::FilterModifier::remove_filter() SPDocument* doc = filter->document; // Delete all references to this filter - SelContainer x,y; - SelContainer all = get_all_items(x, _desktop->currentRoot(), _desktop, false, false, true, y); - for(SelContainer::const_iterator i=all.begin(); all.end() != i; i++) { + std::vector x,y; + std::vector all = get_all_items(x, _desktop->currentRoot(), _desktop, false, false, true, y); + for(std::vector::const_iterator i=all.begin(); all.end() != i; i++) { if (!SP_IS_ITEM(*i)) { continue; } diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index 43ecb60ac..283d79c0d 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -549,7 +549,7 @@ bool Find::item_font_match(SPItem *item, const gchar *text, bool exact, bool cas } -SelContainer Find::filter_fields (SelContainer &l, bool exact, bool casematch) +std::vector Find::filter_fields (std::vector &l, bool exact, bool casematch) { Glib::ustring tmp = entry_find.getEntry()->get_text(); if (tmp.empty()) { @@ -557,17 +557,17 @@ SelContainer Find::filter_fields (SelContainer &l, bool exact, bool casematch) } gchar* text = g_strdup(tmp.c_str()); - SelContainer in = l; - SelContainer out; + std::vector in = l; + std::vector out; if (check_searchin_text.get_active()) { - for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_text_match(item, text, exact, casematch)) { if (out.end()==find(out.begin(),out.end(), *i)) { - out.push_front(*i); + out.push_back(*i); if (_action_replace) { item_text_match(item, text, exact, casematch, _action_replace); } @@ -584,12 +584,12 @@ SelContainer Find::filter_fields (SelContainer &l, bool exact, bool casematch) bool attrvalue = check_attributevalue.get_active(); if (ids) { - for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); if (item_id_match(item, text, exact, casematch)) { if (out.end()==find(out.begin(),out.end(), *i)) { - out.push_front(*i); + out.push_back(*i); if (_action_replace) { item_id_match(item, text, exact, casematch, _action_replace); } @@ -600,13 +600,13 @@ SelContainer Find::filter_fields (SelContainer &l, bool exact, bool casematch) if (style) { - for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_style_match(item, text, exact, casematch)) { if (out.end()==find(out.begin(),out.end(), *i)){ - out.push_front(*i); + out.push_back(*i); if (_action_replace) { item_style_match(item, text, exact, casematch, _action_replace); } @@ -617,13 +617,13 @@ SelContainer Find::filter_fields (SelContainer &l, bool exact, bool casematch) if (attrname) { - for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_attr_match(item, text, exact, casematch)) { if (out.end()==find(out.begin(),out.end(), *i)) { - out.push_front(*i); + out.push_back(*i); if (_action_replace) { item_attr_match(item, text, exact, casematch, _action_replace); } @@ -634,13 +634,13 @@ SelContainer Find::filter_fields (SelContainer &l, bool exact, bool casematch) if (attrvalue) { - for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_attrvalue_match(item, text, exact, casematch)) { if (out.end()==find(out.begin(),out.end(), *i)) { - out.push_front(*i); + out.push_back(*i); if (_action_replace) { item_attrvalue_match(item, text, exact, casematch, _action_replace); } @@ -651,13 +651,13 @@ SelContainer Find::filter_fields (SelContainer &l, bool exact, bool casematch) if (font) { - for(SelContainer::const_iterator i=in.begin(); in.end() != i; i++) { + for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_font_match(item, text, exact, casematch)) { if (out.end()==find(out.begin(),out.end(),*i)) { - out.push_front(*i); + out.push_back(*i); if (_action_replace) { item_font_match(item, text, exact, casematch, _action_replace); } @@ -715,29 +715,29 @@ bool Find::item_type_match (SPItem *item) return false; } -SelContainer Find::filter_types (SelContainer &l) +std::vector Find::filter_types (std::vector &l) { - SelContainer n; - for(SelContainer::const_iterator i=l.begin(); l.end() != i; i++) { + std::vector n; + for(std::vector::const_reverse_iterator i=l.rbegin(); l.rend() != i; i++) { SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_type_match(item)) { - n.push_front(*i); + n.push_back(*i); } } return n; } -SelContainer &Find::filter_list (SelContainer &l, bool exact, bool casematch) +std::vector &Find::filter_list (std::vector &l, bool exact, bool casematch) { l = filter_types (l); l = filter_fields (l, exact, casematch); return l; } -SelContainer &Find::all_items (SPObject *r, SelContainer &l, bool hidden, bool locked) +std::vector &Find::all_items (SPObject *r, std::vector &l, bool hidden, bool locked) { if (dynamic_cast(r)) { return l; // we're not interested in items in defs @@ -751,7 +751,7 @@ SelContainer &Find::all_items (SPObject *r, SelContainer &l, bool hidden, bool l SPItem *item = dynamic_cast(child); if (item && !child->cloned && !desktop->isLayer(item)) { if ((hidden || !desktop->itemIsHidden(item)) && (locked || !item->isLocked())) { - l.push_front(child); + l.insert(l.begin(),(SPItem*)child); } } l = all_items (child, l, hidden, locked); @@ -759,10 +759,10 @@ SelContainer &Find::all_items (SPObject *r, SelContainer &l, bool hidden, bool l return l; } -SelContainer &Find::all_selection_items (Inkscape::Selection *s, SelContainer &l, SPObject *ancestor, bool hidden, bool locked) +std::vector &Find::all_selection_items (Inkscape::Selection *s, std::vector &l, SPObject *ancestor, bool hidden, bool locked) { - SelContainer itemlist=s->itemList(); - for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + std::vector itemlist=s->itemList(); + for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { SPObject *obj = SP_OBJECT (*i); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); @@ -817,7 +817,7 @@ void Find::onAction() bool casematch = check_case_sensitive.get_active(); blocked = true; - SelContainer l; + std::vector l; if (check_scope_selection.get_active()) { if (check_scope_layer.get_active()) { l = all_selection_items (desktop->selection, l, desktop->currentLayer(), hidden, locked); @@ -833,7 +833,7 @@ void Find::onAction() } guint all = l.size(); - SelContainer n = filter_list (l, exact, casematch); + std::vector n = filter_list (l, exact, casematch); if (!n.empty()) { int count = n.size(); diff --git a/src/ui/dialog/find.h b/src/ui/dialog/find.h index 1aded96f2..61f4463ae 100644 --- a/src/ui/dialog/find.h +++ b/src/ui/dialog/find.h @@ -149,10 +149,10 @@ protected: /** * Function to filter a list of items based on the item type by calling each item_XXX_match function */ - SelContainer filter_fields (SelContainer &l, bool exact, bool casematch); + std::vector filter_fields (std::vector &l, bool exact, bool casematch); bool item_type_match (SPItem *item); - SelContainer filter_types (SelContainer &l); - SelContainer & filter_list (SelContainer &l, bool exact, bool casematch); + std::vector filter_types (std::vector &l); + std::vector & filter_list (std::vector &l, bool exact, bool casematch); /** * Find a string within a string and returns true if found with options for exact and casematching @@ -173,12 +173,12 @@ protected: * recursive function to return a list of all the items in the SPObject tree * */ - SelContainer & all_items (SPObject *r, SelContainer &l, bool hidden, bool locked); + std::vector & all_items (SPObject *r, std::vector &l, bool hidden, bool locked); /** * to return a list of all the selected items * */ - SelContainer & all_selection_items (Inkscape::Selection *s, SelContainer &l, SPObject *ancestor, bool hidden, bool locked); + std::vector & all_selection_items (Inkscape::Selection *s, std::vector &l, SPObject *ancestor, bool hidden, bool locked); /** * Shrink the dialog size when the expander widget is closed diff --git a/src/ui/dialog/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp index 625ed99b9..e9a0fc017 100644 --- a/src/ui/dialog/font-substitution.cpp +++ b/src/ui/dialog/font-substitution.cpp @@ -70,7 +70,7 @@ FontSubstitution::checkFontSubstitutions(SPDocument* doc) int show_dlg = prefs->getInt("/options/font/substitutedlg", 0); if (show_dlg) { Glib::ustring out; - SelContainer l = getFontReplacedItems(doc, &out); + std::vector l = getFontReplacedItems(doc, &out); if (out.length() > 0) { show(out, l); } @@ -78,7 +78,7 @@ FontSubstitution::checkFontSubstitutions(SPDocument* doc) } void -FontSubstitution::show(Glib::ustring out, SelContainer &l) +FontSubstitution::show(Glib::ustring out, std::vector &l) { Gtk::MessageDialog warning(_("\nSome fonts are not available and have been substituted."), false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK, true); @@ -148,17 +148,17 @@ FontSubstitution::show(Glib::ustring out, SelContainer &l) * b. Build up a list of the objects rendered fonts - taken for the objects layout/spans * If there are fonts in a. that are not in b. then those fonts have been substituted. */ -SelContainer FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring *out) +std::vector FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring *out) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SelContainer allList; - SelContainer outList,x,y; + std::vector allList; + std::vector outList,x,y; std::set setErrors; std::set setFontSpans; std::map mapFontStyles; allList = get_all_items(x, doc->getRoot(), desktop, false, false, true, y); - for(SelContainer::const_iterator i = allList.begin();i!=allList.end();i++){ + for(std::vector::const_iterator i = allList.begin();i!=allList.end();i++){ SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; Glib::ustring family = ""; @@ -214,8 +214,8 @@ SelContainer FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustri } // Check if any document styles are not in the actual layout - std::map::const_iterator mapIter; - for (mapIter = mapFontStyles.begin(); mapIter != mapFontStyles.end(); ++mapIter) { + std::map::const_reverse_iterator mapIter; + for (mapIter = mapFontStyles.rbegin(); mapIter != mapFontStyles.rend(); ++mapIter) { SPItem *item = mapIter->first; Glib::ustring fonts = mapIter->second; @@ -248,7 +248,7 @@ SelContainer FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustri Glib::ustring err = Glib::ustring::compose( _("Font '%1' substituted with '%2'"), fonts.c_str(), subName.c_str()); setErrors.insert(err); - outList.push_front(item); + outList.push_back(item); } } diff --git a/src/ui/dialog/font-substitution.h b/src/ui/dialog/font-substitution.h index eed7adcf2..cdb4e22b4 100644 --- a/src/ui/dialog/font-substitution.h +++ b/src/ui/dialog/font-substitution.h @@ -25,13 +25,13 @@ public: FontSubstitution(); virtual ~FontSubstitution(); void checkFontSubstitutions(SPDocument* doc); - void show(Glib::ustring out, SelContainer &l); + void show(Glib::ustring out, std::vector &l); static FontSubstitution &getInstance() { return *new FontSubstitution(); } Glib::ustring getSubstituteFontName (Glib::ustring font); protected: - SelContainer getFontReplacedItems(SPDocument* doc, Glib::ustring *out); + std::vector getFontReplacedItems(SPDocument* doc, Glib::ustring *out); private: FontSubstitution(FontSubstitution const &d); diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp index 1ef97b996..fa469dc4b 100644 --- a/src/ui/dialog/glyphs.cpp +++ b/src/ui/dialog/glyphs.cpp @@ -578,8 +578,8 @@ void GlyphsPanel::setTargetDesktop(SPDesktop *desktop) void GlyphsPanel::insertText() { SPItem *textItem = 0; - SelContainer itemlist=targetDesktop->selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + std::vector itemlist=targetDesktop->selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { textItem = SP_ITEM(*i); break; @@ -688,8 +688,8 @@ void GlyphsPanel::selectionModifiedCB(guint flags) void GlyphsPanel::calcCanInsert() { int items = 0; - SelContainer itemlist=targetDesktop->selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + std::vector itemlist=targetDesktop->selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { ++items; } diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index ba8616d9b..d62032e9d 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -175,9 +175,9 @@ void GridArrangeTab::arrange() desktop->getDocument()->ensureUpToDate(); Inkscape::Selection *selection = desktop->getSelection(); - const SelContainer items = selection ? selection->itemList() : SelContainer(); + const std::vector items = selection ? selection->itemList() : std::vector(); cnt=0; - for(SelContainer::const_iterator i = items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i = items.begin();i!=items.end();i++){ SPItem *item = SP_ITEM(*i); Geom::OptRect b = item->documentVisualBounds(); if (!b) { @@ -205,18 +205,17 @@ void GridArrangeTab::arrange() // require the sorting done before we can calculate row heights etc. g_return_if_fail(selection); - SelContainer rev(selection->itemList()); - rev.sort(sp_compare_y_position_obj); - SelContainer sorted(rev); - sorted.sort(sp_compare_x_position_obj); + std::vector sorted(selection->itemList()); + sort(sorted.begin(),sorted.end(),sp_compare_y_position); + sort(sorted.begin(),sorted.end(),sp_compare_x_position); // Calculate individual Row and Column sizes if necessary cnt=0; - const SelContainer sizes(sorted); - for (SelContainer::const_iterator i = sizes.begin();i!=sizes.end();i++) { + const std::vector sizes(sorted); + for (std::vector::const_iterator i = sizes.begin();i!=sizes.end();i++) { SPItem *item = SP_ITEM(*i); Geom::OptRect b = item->documentVisualBounds(); if (b) { @@ -314,7 +313,7 @@ g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_h } cnt=0; - SelContainer::iterator it = sorted.begin(); + std::vector::iterator it = sorted.begin(); for (row_cnt=0; ((it != sorted.end()) && (row_cntselection : 0; g_return_if_fail( selection ); - SelContainer const items = selection->itemList(); + std::vector const items = selection->itemList(); int selcount = items.size(); double PerCol = ceil(selcount / NoOfColsSpinner.get_value()); @@ -545,7 +544,7 @@ void GridArrangeTab::updateSelection() updating = true; SPDesktop *desktop = Parent->getDesktop(); Inkscape::Selection *selection = desktop ? desktop->selection : 0; - SelContainer const items = selection ? selection->itemList() : SelContainer(); + std::vector const items = selection ? selection->itemList() : std::vector(); if (!items.empty()) { int selcount = items.size(); diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index 79e5b556d..6ad3d61ac 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -366,8 +366,8 @@ void IconPreviewPanel::refreshPreview() if ( sel ) { //g_message("found a selection to play with"); - SelContainer const items = sel->itemList(); - for(SelContainer::const_iterator i=items.begin();!target && i!=items.end();i++){ + std::vector const items = sel->itemList(); + for(std::vector::const_iterator i=items.begin();!target && i!=items.end();i++){ SPItem* item = SP_ITEM( *i); gchar const *id = item->getId(); if ( id ) { diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp index 0ae3027c7..d60780f78 100644 --- a/src/ui/dialog/objects.cpp +++ b/src/ui/dialog/objects.cpp @@ -479,8 +479,8 @@ void ObjectsPanel::_objectsSelected( Selection *sel ) { _selectedConnection.block(); _tree.get_selection()->unselect_all(); SPItem *item = NULL; - SelContainer const items = sel->itemList(); - for(SelContainer::const_iterator i=items.begin(); i!=items.end();i++){ + std::vector const items = sel->itemList(); + for(std::vector::const_iterator i=items.begin(); i!=items.end();i++){ item = reinterpret_cast(*i); if (setOpacity) { diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index 273a378e5..760391df6 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -372,8 +372,8 @@ void PixelArtDialogImpl::vectorize() return; } - SelContainer const items = desktop->selection->itemList(); - for(SelContainer::const_iterator i=items.begin(); i!=items.end();i++){ + std::vector const items = desktop->selection->itemList(); + for(std::vector::const_iterator i=items.begin(); i!=items.end();i++){ if ( !SP_IS_IMAGE(*i) ) continue; diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index 8a382fc93..a68e73caf 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -297,14 +297,14 @@ static void moveToPoint(int anchor, SPItem *item, Geom::Point p) void PolarArrangeTab::arrange() { Inkscape::Selection *selection = parent->getDesktop()->getSelection(); - const SelContainer tmp(selection->itemList()); + const std::vector tmp(selection->itemList()); SPGenericEllipse *referenceEllipse = NULL; // Last ellipse in selection bool arrangeOnEllipse = !arrangeOnParametersRadio.get_active(); bool arrangeOnFirstEllipse = arrangeOnEllipse && arrangeOnFirstCircleRadio.get_active(); int count = 0; - for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++) + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++) { if(arrangeOnEllipse) { @@ -373,7 +373,7 @@ void PolarArrangeTab::arrange() Geom::Point realCenter = Geom::Point(cx, cy) * transformation; int i = 0; - for(SelContainer::const_iterator it=tmp.begin();it!=tmp.end();it++) + for(std::vector::const_iterator it=tmp.begin();it!=tmp.end();it++) { SPItem *item = SP_ITEM(*it); diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp index dc98b6032..351971294 100644 --- a/src/ui/dialog/print.cpp +++ b/src/ui/dialog/print.cpp @@ -81,7 +81,7 @@ static void draw_page( width, height, (unsigned long)(Inkscape::Util::Quantity::convert(width, "px", "in") * dpi), (unsigned long)(Inkscape::Util::Quantity::convert(height, "px", "in") * dpi), - dpi, dpi, bgcolor, NULL, NULL, true, SelContainer()); + dpi, dpi, bgcolor, NULL, NULL, true, std::vector()); // This doesn't seem to work: //context->set_cairo_context ( Cairo::Context::create (Cairo::ImageSurface::create_from_png (tmp_png) ), dpi, dpi ); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index da24ad605..72677c07e 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -123,7 +123,7 @@ static void editGradientImpl( SPDesktop* desktop, SPGradient* gr ) bool shown = false; if ( desktop && desktop->doc() ) { Inkscape::Selection *selection = desktop->getSelection(); - SelContainer const items = selection->itemList(); + std::vector const items = selection->itemList(); if (!items.empty()) { SPStyle query( desktop->doc() ); int result = objects_query_fillstroke((items), &query, true); diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index ba3a6b914..c2df5fc1c 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -669,8 +669,8 @@ bool TagsPanel::_handleButtonEvent(GdkEventButton* event) if (col == _tree.get_column(COL_ADD - 1) && down_at_add) { if (SP_IS_TAG(obj)) { bool wasadded = false; - SelContainer items=_desktop->selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items=_desktop->selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPObject *newobj = reinterpret_cast(*i); bool addchild = true; for ( SPObject *child = obj->children; child != NULL; child = child->next) { diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index 593261ec5..1c1cf5937 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -418,8 +418,8 @@ SPItem *TextEdit::getSelectedTextItem (void) if (!SP_ACTIVE_DESKTOP) return NULL; - SelContainer tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); - for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++) + std::vector tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) return SP_ITEM (*i); @@ -436,8 +436,8 @@ unsigned TextEdit::getSelectedTextCount (void) unsigned int items = 0; - SelContainer tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); - for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++) + std::vector tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) ++items; @@ -540,11 +540,11 @@ void TextEdit::onApply() SPDesktop *desktop = SP_ACTIVE_DESKTOP; unsigned items = 0; - const SelContainer item_list = desktop->getSelection()->itemList(); + const std::vector item_list = desktop->getSelection()->itemList(); SPCSSAttr *css = fillTextStyle (); sp_desktop_set_style(desktop, css, true); - for(SelContainer::const_iterator i=item_list.begin();i!=item_list.end();i++){ + for(std::vector::const_iterator i=item_list.begin();i!=item_list.end();i++){ // apply style to the reprs of all text objects in the selection if (SP_IS_TEXT (*i)) { diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 8c52144e0..0f81a7e58 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -741,12 +741,12 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) if (_check_move_relative.get_active()) { // shift each object relatively to the previous one using Inkscape::Util::GSListConstIterator; - SelContainer selected(selection->itemList()); + std::vector selected(selection->itemList()); if (selected.empty()) return; if (fabs(x) > 1e-6) { std::vector< BBoxSort > sorted; - for (SelContainer::iterator it(selected.begin()); + for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it) { @@ -771,7 +771,7 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) } if (fabs(y) > 1e-6) { std::vector< BBoxSort > sorted; - for (SelContainer::iterator it(selected.begin()); + for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it) { @@ -816,8 +816,8 @@ void Transformation::applyPageScale(Inkscape::Selection *selection) bool transform_stroke = prefs->getBool("/options/transform/stroke", true); bool preserve = prefs->getBool("/options/preservetransform/value", false); if (prefs->getBool("/dialogs/transformation/applyseparately")) { - SelContainer tmp=selection->itemList(); - for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++){ + std::vector tmp=selection->itemList(); + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++){ SPItem *item = SP_ITEM(*i); Geom::OptRect bbox_pref = item->desktopPreferredBounds(); Geom::OptRect bbox_geom = item->desktopGeometricBounds(); @@ -880,8 +880,8 @@ void Transformation::applyPageRotate(Inkscape::Selection *selection) } if (prefs->getBool("/dialogs/transformation/applyseparately")) { - SelContainer tmp=selection->itemList(); - for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++){ + std::vector tmp=selection->itemList(); + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++){ SPItem *item = SP_ITEM(*i); sp_item_rotate_rel(item, Geom::Rotate (angle*M_PI/180.0)); } @@ -900,8 +900,8 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/dialogs/transformation/applyseparately")) { - SelContainer items=selection->itemList(); - for(SelContainer::const_iterator i = items.begin();i!=items.end();i++){ + std::vector items=selection->itemList(); + for(std::vector::const_iterator i = items.begin();i!=items.end();i++){ SPItem *item = SP_ITEM(*i); if (!_units_skew.isAbsolute()) { // percentage @@ -1002,8 +1002,8 @@ void Transformation::applyPageTransform(Inkscape::Selection *selection) } if (_check_replace_matrix.get_active()) { - SelContainer tmp=selection->itemList(); - for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++){ + std::vector tmp=selection->itemList(); + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++){ SPItem *item = SP_ITEM(*i); item->set_item_transform(displayed); SP_OBJECT(item)->updateRepr(); diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 86cf629c1..43e35df9d 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -1906,7 +1906,7 @@ void ContextMenu::ActivateGroup(void) void ContextMenu::ActivateUngroup(void) { - SelContainer children; + std::vector children; sp_item_group_ungroup(static_cast(_item), children); _desktop->selection->setList(children); @@ -1958,7 +1958,7 @@ void ContextMenu::AnchorLinkFollow(void) void ContextMenu::AnchorLinkRemove(void) { - SelContainer children; + std::vector children; sp_item_group_ungroup(static_cast(_item), children, false); DocumentUndo::done(_desktop->doc(), SP_VERB_NONE, _("Remove link")); } @@ -2075,8 +2075,8 @@ void ContextMenu::ImageEdit(void) } #endif - SelContainer itemlist=_desktop->selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=_desktop->selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ Inkscape::XML::Node *ir = SP_ITEM(*i)->getRepr(); const gchar *href = ir->attribute("xlink:href"); diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index fc40c20e7..9c6eead16 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -1316,8 +1316,8 @@ void cc_selection_set_avoid(bool const set_avoid) int changes = 0; - SelContainer l = selection->itemList(); - for(SelContainer::const_iterator i=l.begin();i!=l.end();i++) { + std::vector l = selection->itemList(); + for(std::vector::const_iterator i=l.begin();i!=l.end();i++) { SPItem *item = SP_ITEM(*i); char const *value = (set_avoid) ? "true" : NULL; diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 3526e015a..520b93e72 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -676,8 +676,7 @@ void EraserTool::set_to_accumulated() { Geom::OptRect eraserBbox = acid->visualBounds(); Geom::Rect bounds = (*eraserBbox) * desktop->doc2dt(); std::vector remainingItems; - SelContainer toWorkOn; - + std::vector toWorkOn; if (selection->isEmpty()) { if ( eraserMode ) { toWorkOn = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, bounds); @@ -685,16 +684,15 @@ void EraserTool::set_to_accumulated() { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); } - - toWorkOn.remove(static_cast(acid) ); + toWorkOn.erase(find(toWorkOn.begin(),toWorkOn.end(),acid)); } else { - toWorkOn = selection->itemList(); + toWorkOn= selection->itemList(); wasSelection = true; } if ( !toWorkOn.empty() ) { if ( eraserMode ) { - for (SelContainer::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + for (std::vector::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { SPItem *item = SP_ITEM(*i); if ( eraserMode ) { @@ -712,8 +710,8 @@ void EraserTool::set_to_accumulated() { if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. - SelContainer nowSel(selection->itemList()); - for (SelContainer::const_iterator i2 = nowSel.begin();i!=nowSel.end();i++) { + std::vector nowSel(selection->itemList()); + for (std::vector::const_iterator i2 = nowSel.begin();i!=nowSel.end();i2++) { remainingItems.push_back(SP_ITEM(*i2)); } } @@ -723,11 +721,11 @@ void EraserTool::set_to_accumulated() { } } } else { - for (SelContainer::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + for (std::vector ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { sp_object_ref( SP_ITEM(*i), 0 ); } - for (SelContainer::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + for (std::vector::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { SPItem *item = SP_ITEM(*i); item->deleteObject(true); sp_object_unref(item); diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index d1db5fb93..6f7b220ed 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -504,8 +504,8 @@ bool GradientTool::root_handler(GdkEvent* event) { // always resets selection to the single object under cursor sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->itemList().front()), this->mousepoint_doc, event->button.time); } else { - SelContainer items=selection->itemList(); - for (SelContainer::const_iterator i = items.begin();i!=items.end();i++) { + std::vector items=selection->itemList(); + for (std::vector::const_iterator i = items.begin();i!=items.end();i++) { SPItem *item = SP_ITEM(*i); SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR); Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; @@ -915,8 +915,8 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta } else { // Starting from empty space: // Sort items so that the topmost comes last - SelContainer items(selection->itemList()); - items.sort(sp_item_repr_compare_position_obj); + std::vector items(selection->itemList()); + sort(items.begin(),items.end(),sp_item_repr_compare_position); // take topmost vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke); } @@ -925,8 +925,8 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); - SelContainer itemlist = selection->itemList(); - for (SelContainer::const_iterator i = itemlist.begin();i!=itemlist.end();i++) { + std::vector itemlist = selection->itemList(); + for (std::vector::const_iterator i = itemlist.begin();i!=itemlist.end();i++) { //FIXME: see above sp_repr_css_change_recursive(SP_OBJECT(*i)->getRepr(), css, "style"); diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index ce0ad7a9a..290eeef87 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -407,8 +407,8 @@ lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection) SPCanvasGroup *tmpgrp = lc->desktop->getTempGroup(); gchar *arc_length; double lengthval; - SelContainer items=selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items=selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_PATH(*i)) { path = SP_PATH(*i); curve = path->getCurve(); diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 8d52210ff..2b44639c8 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -441,9 +441,9 @@ bool MeasureTool::root_handler(GdkEvent* event) { // TODO switch to a different variable name. The single letter 'l' is easy to misread. //select elements crossed by line segment: - SelContainer items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points); + std::vector items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points); std::vector intersection_times; - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { SPItem *item = static_cast(*i); if (SP_IS_SHAPE(item)) { diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index 1cc06a5b9..0a34e4855 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -481,8 +481,8 @@ bool MeshTool::root_handler(GdkEvent* event) { sp_mesh_context_split_near_point(this, SP_ITEM(selection->itemList().front()), this->mousepoint_doc, event->button.time); } else { // Create a new gradient with default coordinates. - SelContainer items=selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items=selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = SP_ITEM(*i); SPGradientType new_type = SP_GRADIENT_TYPE_MESH; Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; @@ -958,8 +958,8 @@ static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/ } else { // Starting from empty space: // Sort items so that the topmost comes last - SelContainer items(selection->itemList()); - items.sort(sp_item_repr_compare_position_obj); + std::vector items(selection->itemList()); + sort(items.begin(),items.end(),sp_item_repr_compare_position); // take topmost vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke); } @@ -968,8 +968,8 @@ static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/ SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); - SelContainer items=selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items=selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above sp_repr_css_change_recursive(SP_OBJECT(*i)->getRepr(), css, "style"); diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 46c978c84..6ddb379cc 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -420,8 +420,8 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) { std::set shapes; - SelContainer items=sel->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items=sel->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPObject *obj = static_cast(*i); if (SP_IS_ITEM(obj)) { @@ -667,7 +667,7 @@ void NodeTool::select_area(Geom::Rect const &sel, GdkEventButton *event) { if (this->_multipath->empty()) { // if multipath is empty, select rubberbanded items rather than nodes Inkscape::Selection *selection = this->desktop->selection; - SelContainer items = this->desktop->getDocument()->getItemsInBox(this->desktop->dkey, sel); + std::vector items = this->desktop->getDocument()->getItemsInBox(this->desktop->dkey, sel); selection->setList(items); } else { if (!held_shift(*event)) { diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index f84170631..25cbf76a4 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -718,7 +718,7 @@ bool SelectTool::root_handler(GdkEvent* event) { if (r->is_started() && !within_tolerance) { // this was a rubberband drag - SelContainer items; + std::vector items; if (r->getMode() == RUBBERBAND_MODE_RECT) { Geom::OptRect const b = r->getRectangle(); diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index d339f6d19..ac41f3a34 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -436,9 +436,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPItem *unionResult = NULL; // Previous union int i=1; - SelContainer items=selection->itemList(); - for(SelContainer::const_iterator it=items.begin();it!=items.end();it++){ - SPItem *item1 = dynamic_cast(static_cast(*it)); + std::vector items=selection->itemList(); + for(std::vector::const_iterator it=items.begin();it!=items.end();it++){ + SPItem *item1 = *it; if (i == 1) { parent_item = item1; } @@ -550,15 +550,15 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point double move_standard_deviation = get_move_standard_deviation(tc); { - SelContainer const items(selection->itemList()); + std::vector const items(selection->itemList()); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = dynamic_cast(static_cast(*i)); g_assert(item != NULL); sp_object_ref(item); } - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = dynamic_cast(static_cast(*i)); g_assert(item != NULL); @@ -573,7 +573,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point } } - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = dynamic_cast(static_cast(*i)); g_assert(item != NULL); sp_object_unref(item); diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index a4370256d..48c109688 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -1470,7 +1470,7 @@ int TextTool::_styleQueried(SPStyle *style, int property) } sp_text_context_validate_cursor_iterators(this); - SelContainer styles_list; + std::vector styles_list; Inkscape::Text::Layout::iterator begin_it, end_it; if (this->text_sel_start < this->text_sel_end) { @@ -1496,7 +1496,7 @@ int TextTool::_styleQueried(SPStyle *style, int property) while (SP_IS_STRING(pos_obj) && pos_obj->parent) { pos_obj = pos_obj->parent; // SPStrings don't have style } - styles_list.push_front(pos_obj); + styles_list.insert(styles_list.begin(),(SPItem*)pos_obj); } int result = sp_desktop_query_style_from_list (styles_list, style, property); diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index cc05f9775..def8080d0 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -1178,8 +1178,8 @@ SPItem *sp_event_context_find_item(SPDesktop *desktop, Geom::Point const &p, SPItem * sp_event_context_over_item(SPDesktop *desktop, SPItem *item, Geom::Point const &p) { - SelContainer temp; - temp.push_front(static_cast(item)); + std::vector temp; + temp.push_back(item); SPItem *item_at_point = desktop->getItemFromListAtPointBottom(temp, p); return item_at_point; } diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 9342127ce..6f7764506 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -382,13 +382,13 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P } if (dynamic_cast(item) || dynamic_cast(item)) { - SelContainer items; + std::vector items; items.push_back(item); - SelContainer selected; - SelContainer to_select; + std::vector selected; + std::vector to_select; SPDocument *doc = item->document; sp_item_list_to_curves (items, selected, to_select); - SPObject* newObj = doc->getObjectByRepr(dynamic_cast(to_select.front())); + SPObject* newObj = doc->getObjectByRepr(to_select.back()); item = dynamic_cast(newObj); g_assert(item != NULL); selection->add(item); @@ -1087,8 +1087,8 @@ sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point double move_force = get_move_force(tc); double color_force = MIN(sqrt(path_force)/20.0, 1); - SelContainer items=selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items=selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = dynamic_cast(static_cast(*i)); if (is_color_mode (tc->mode)) { diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp index ddf67fb5b..598a90e95 100644 --- a/src/ui/widget/object-composite-settings.cpp +++ b/src/ui/widget/object-composite-settings.cpp @@ -125,8 +125,8 @@ ObjectCompositeSettings::_blendBlurValueChanged() const Glib::ustring blendmode = _fe_cb.get_blend_mode(); //apply created filter to every selected item - SelContainer sel=_subject->getDesktop()->getSelection()->itemList(); - for (SelContainer::const_iterator i = sel.begin() ; i != sel.end() ; ++i ) { + std::vector sel=_subject->getDesktop()->getSelection()->itemList(); + for (std::vector::const_iterator i = sel.begin() ; i != sel.end() ; ++i ) { if (!SP_IS_ITEM(*i)) { continue; } diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp index 9d09e67d3..1ded546dd 100644 --- a/src/ui/widget/style-subject.cpp +++ b/src/ui/widget/style-subject.cpp @@ -148,10 +148,10 @@ Geom::OptRect StyleSubject::CurrentLayer::getBounds(SPItem::BBoxType type) { } int StyleSubject::CurrentLayer::queryStyle(SPStyle *query, int property) { - SelContainer list; + std::vector list; SPObject* i=_getLayerSList(); if (i) { - list.push_back(i); + list.push_back((SPItem*)i); return sp_desktop_query_style_from_list(list, query, property); } else { return QUERY_STYLE_NOTHING; diff --git a/src/unclump.cpp b/src/unclump.cpp index d1cfc6628..29608befa 100644 --- a/src/unclump.cpp +++ b/src/unclump.cpp @@ -168,11 +168,11 @@ unclump_dist (SPItem *item1, SPItem *item2) /** Average unclump_dist from item to others */ -static double unclump_average (SPItem *item, SelContainer &others) +static double unclump_average (SPItem *item, std::list &others) { int n = 0; double sum = 0; - for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) { + for (std::list::const_iterator i = others.begin(); i != others.end();i++) { SPItem *other = SP_ITEM (*i); if (other == item) @@ -191,12 +191,12 @@ static double unclump_average (SPItem *item, SelContainer &others) /** Closest to item among others */ -static SPItem *unclump_closest (SPItem *item, SelContainer &others) +static SPItem *unclump_closest (SPItem *item, std::list &others) { double min = HUGE_VAL; SPItem *closest = NULL; - for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) { + for (std::list::const_iterator i = others.begin(); i != others.end();i++) { SPItem *other = SP_ITEM (*i); if (other == item) @@ -215,11 +215,11 @@ static SPItem *unclump_closest (SPItem *item, SelContainer &others) /** Most distant from item among others */ -static SPItem *unclump_farest (SPItem *item, SelContainer &others) +static SPItem *unclump_farest (SPItem *item, std::list &others) { double max = -HUGE_VAL; SPItem *farest = NULL; - for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) { + for (std::list::const_iterator i = others.begin(); i != others.end();i++) { SPItem *other = SP_ITEM (*i); if (other == item) @@ -240,8 +240,8 @@ Removes from the \a rest list those items that are "behind" \a closest as seen f i.e. those on the other side of the line through \a closest perpendicular to the direction from \a item to \a closest. Returns a newly created list which must be freed. */ -static SelContainer -unclump_remove_behind (SPItem *item, SPItem *closest, SelContainer &rest) +static std::vector +unclump_remove_behind (SPItem *item, SPItem *closest, std::list &rest) { Geom::Point it = unclump_center (item); Geom::Point p1 = unclump_center (closest); @@ -258,8 +258,8 @@ unclump_remove_behind (SPItem *item, SPItem *closest, SelContainer &rest) // substitute the item into it: double val_item = A * it[Geom::X] + B * it[Geom::Y] + C; - SelContainer out; - for (SelContainer::const_iterator i = rest.begin(); i != rest.end();i++) { + std::vector out; + for (std::list::const_reverse_iterator i = rest.rbegin(); i != rest.rend();i++) { SPItem *other = SP_ITEM (*i); if (other == item) @@ -271,7 +271,7 @@ unclump_remove_behind (SPItem *item, SPItem *closest, SelContainer &rest) if (val_item * val_other <= 1e-6) { // different signs, which means item and other are on the different sides of p1-p2 line; skip } else { - out.push_front(other); + out.push_back(other); } } @@ -331,17 +331,18 @@ similar to "engraver dots". The only distribution which is unchanged by unclumpi grid. May be called repeatedly for stronger effect. */ void -unclump (SelContainer &items) +unclump (std::vector &items) { c_cache.clear(); wh_cache.clear(); - for (SelContainer::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x: + for (std::vector::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x: SPItem *item = SP_ITEM (*i); - SelContainer nei; + std::list nei; - SelContainer rest(items); + std::list rest; + for(int i=0;i new_rest = unclump_remove_behind (item, closest, rest); + rest.clear(); + for(int i=0;i &items); #endif /* !UNCLUMP_H_SEEN */ diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index 98a3eaa67..770845f38 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -256,8 +256,8 @@ VanishingPoint::set_pos(Proj::Pt2 const &pt) { std::list VanishingPoint::selectedBoxes(Inkscape::Selection *sel) { std::list sel_boxes; - SelContainer itemlist=sel->itemList(); - for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + std::vector itemlist=sel->itemList(); + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { SPItem *item = static_cast(*i); SPBox3D *box = dynamic_cast(item); if (box && this->hasBox(box)) { @@ -396,8 +396,8 @@ VPDragger::VPsOfSelectedBoxes() { VanishingPoint *vp; // FIXME: Should we take the selection from the parent VPDrag? I guess it shouldn't make a difference. Inkscape::Selection *sel = SP_ACTIVE_DESKTOP->getSelection(); - SelContainer itemlist=sel->itemList(); - for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + std::vector itemlist=sel->itemList(); + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { SPItem *item = static_cast(*i); SPBox3D *box = dynamic_cast(item); if (box) { @@ -579,8 +579,8 @@ VPDrag::updateDraggers () g_return_if_fail (this->selection != NULL); - SelContainer itemlist=this->selection->itemList(); - for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + std::vector itemlist=this->selection->itemList(); + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { SPItem *item = static_cast(*i); SPBox3D *box = dynamic_cast(item); if (box) { @@ -612,8 +612,8 @@ VPDrag::updateLines () g_return_if_fail (this->selection != NULL); - SelContainer itemlist=this->selection->itemList(); - for (SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + std::vector itemlist=this->selection->itemList(); + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { SPItem *item = static_cast(*i); SPBox3D *box = dynamic_cast(item); if (box) { @@ -630,7 +630,7 @@ VPDrag::updateBoxHandles () // FIXME: Is there a way to update the knots without accessing the // (previously) statically linked function KnotHolder::update_knots? - SelContainer sel = selection->itemList(); + std::vector sel = selection->itemList(); if (sel.empty()) return; // no selection diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 23c248129..cb24bb8aa 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -97,8 +97,8 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v gchar* namespaced_name = g_strconcat("sodipodi:", value_name, NULL); bool modmade = false; - SelContainer itemlist=desktop->getSelection()->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=desktop->getSelection()->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_GENERICELLIPSE(item)) { @@ -163,8 +163,8 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) bool modmade = false; if ( ege_select_one_action_get_active(act) != 0 ) { - SelContainer itemlist=desktop->getSelection()->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=desktop->getSelection()->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -174,8 +174,8 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) } } } else { - SelContainer itemlist=desktop->getSelection()->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=desktop->getSelection()->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -264,8 +264,8 @@ static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GOb purge_repr_listener( tbl, tbl ); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_GENERICELLIPSE(item)) { n_selected++; diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 401ce932a..49cf8e6fd 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -97,8 +97,8 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl gchar *value = is_orthog ? orthog_str : polyline_str ; bool modmade = false; - SelContainer itemlist=desktop->getSelection()->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=desktop->getSelection()->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (Inkscape::UI::Tools::cc_item_is_connector(item)) { @@ -144,8 +144,8 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) g_ascii_dtostr(value, G_ASCII_DTOSTR_BUF_SIZE, newValue); bool modmade = false; - SelContainer itemlist=desktop->getSelection()->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=desktop->getSelection()->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (Inkscape::UI::Tools::cc_item_is_connector(item)) { diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 2c298b04d..dbb84efba 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -481,7 +481,7 @@ void FillNStroke::updateFromPaint() SPDocument *document = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); - SelContainer const items = selection->itemList(); + std::vector const items = selection->itemList(); switch (psel->mode) { case SPPaintSelector::MODE_EMPTY: @@ -576,7 +576,7 @@ void FillNStroke::updateFromPaint() } } - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above if (kind == FILL) { sp_repr_css_change_recursive(reinterpret_cast(*i)->getRepr(), css, "style"); @@ -602,7 +602,7 @@ void FillNStroke::updateFromPaint() // We have changed from another gradient type, or modified spread/units within // this gradient type. vector = sp_gradient_ensure_vector_normalized(vector); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above if (kind == FILL) { sp_repr_css_change_recursive(reinterpret_cast(*i)->getRepr(), css, "style"); @@ -648,7 +648,7 @@ void FillNStroke::updateFromPaint() // cannot just call sp_desktop_set_style, because we don't want to touch those // objects who already have the same root pattern but through a different href // chain. FIXME: move this to a sp_item_set_pattern - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ Inkscape::XML::Node *selrepr = reinterpret_cast(*i)->getRepr(); if ( (kind == STROKE) && !selrepr) { continue; diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index b9608130b..5aa654a80 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -116,8 +116,8 @@ void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient } // If no drag or no dragger selected, act on selection - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ gr_apply_gradient_to_item(SP_ITEM(*i), gr, initialType, initialMode, initialMode); } } @@ -218,8 +218,8 @@ void gr_get_dt_selected_gradient(Inkscape::Selection *selection, SPGradient *&gr { SPGradient *gradient = 0; - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i);// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; @@ -286,8 +286,8 @@ void gr_read_selection( Inkscape::Selection *selection, } // If no selected dragger, read desktop selection - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index b4176db6f..682c61e77 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -87,8 +87,8 @@ void ms_read_selection( Inkscape::Selection *selection, bool first = true; ms_smooth = SP_MESH_SMOOTH_NONE; - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; @@ -214,8 +214,8 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMeshGradient { SPMeshGradient *gradient = 0; - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i);// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 1f19867ee..65078af01 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -106,8 +106,8 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ if (SP_IS_RECT(*i)) { if (gtk_adjustment_get_value(adj) != 0) { (SP_RECT(*i)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, desktop->getNamedView()->svg_units)); @@ -244,8 +244,8 @@ static void sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GO } purge_repr_listener( tbl, tbl ); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ if (SP_IS_RECT(reinterpret_cast(*i))) { n_selected++; item = reinterpret_cast(*i); diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 2f4ad481d..6f967e8ae 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -79,8 +79,8 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr gchar* namespaced_name = g_strconcat("sodipodi:", value_name.data(), NULL); bool modmade = false; - SelContainer itemlist=desktop->getSelection()->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=desktop->getSelection()->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_SPIRAL(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -195,8 +195,8 @@ static void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, purge_repr_listener( tbl, tbl ); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_SPIRAL(item)) { n_selected++; diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 37daf69d0..1946dee6e 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -83,8 +83,8 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -128,8 +128,8 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -185,8 +185,8 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d gtk_action_set_sensitive( prop_action, !flat ); } - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -224,8 +224,8 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -264,8 +264,8 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -367,8 +367,8 @@ sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) purge_repr_listener( tbl, tbl ); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_STAR(item)) { n_selected++; diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 2599fe537..65390819b 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -475,8 +475,8 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, //spw->updateMarkerHist(which); Inkscape::Selection *selection = spw->desktop->getSelection(); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = SP_ITEM(*i); if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) { // can't set marker to rect, until it's converted to using continue; @@ -901,7 +901,7 @@ StrokeStyle::updateLine() if (!sel || sel->isEmpty()) return; - SelContainer const objects = sel->itemList(); + std::vector const objects = sel->itemList(); SPObject * const object = SP_OBJECT(objects.front()); SPStyle * const style = object->style; @@ -957,7 +957,7 @@ StrokeStyle::scaleLine() SPDocument *document = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); - SelContainer items=selection->itemList(); + std::vector items=selection->itemList(); /* TODO: Create some standardized method */ SPCSSAttr *css = sp_repr_css_attr_new(); @@ -977,7 +977,7 @@ StrokeStyle::scaleLine() int ndash; dashSelector->get_dash(&ndash, &dash, &offset); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ /* Set stroke width */ double width; if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { @@ -1143,7 +1143,7 @@ StrokeStyle::setCapButtons(Gtk::ToggleButton *active) * that marker. */ void -StrokeStyle::updateAllMarkers(SelContainer const &objects) +StrokeStyle::updateAllMarkers(std::vector const &objects) { struct { MarkerComboBox *key; int loc; } const keyloc[] = { { startMarkerCombo, SP_MARKER_LOC_START }, @@ -1152,7 +1152,7 @@ StrokeStyle::updateAllMarkers(SelContainer const &objects) }; bool all_texts = true; - for(SelContainer::const_iterator i=objects.begin();i!=objects.end();i++){ + for(std::vector::const_iterator i=objects.begin();i!=objects.end();i++){ if (!SP_IS_TEXT (*i)) { all_texts = false; } diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index 286305ec3..2605e1acf 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -153,7 +153,7 @@ private: }; void updateLine(); - void updateAllMarkers(SelContainer const &objects); + void updateAllMarkers(std::vector const &objects); void updateMarkerHist(SPMarkerLoc const which); void setDashSelectorFromStyle(SPDashSelector *dsel, SPStyle *style); void setJoinType (unsigned const jointype); diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index ba7dfc1fd..71915377e 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -366,8 +366,8 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) // move the x of all texts to preserve the same bbox Inkscape::Selection *selection = desktop->getSelection(); - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ if (SP_IS_TEXT(SP_ITEM(*i))) { SPItem *item = SP_ITEM(*i); @@ -519,8 +519,8 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) // Until deprecated sodipodi:linespacing purged: Inkscape::Selection *selection = desktop->getSelection(); bool modmade = false; - SelContainer itemlist=selection->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=selection->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ if (SP_IS_TEXT (*i)) { SP_OBJECT(*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); modmade = true; @@ -864,8 +864,8 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Only flowed text can be justified, only normal text can be kerned... // Find out if we have flowed text now so we can use it several places gboolean isFlow = false; - SelContainer itemlist=SP_ACTIVE_DESKTOP->getSelection()->itemList(); - for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + std::vector itemlist=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ // const gchar* id = reinterpret_cast(items->data)->getId(); // std::cout << " " << id << std::endl; if( SP_IS_FLOWTEXT(SP_ITEM(*i))) { @@ -1153,13 +1153,13 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p //std::cout << "text_toolbox_missing_font_cb: selecting: " << family << std::endl; // Get all items with matching font-family set (not inherited!). - SelContainer selectList; + std::vector selectList; SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPDocument *document = desktop->getDocument(); - SelContainer x,y; - SelContainer allList = get_all_items(x, document->getRoot(), desktop, false, false, true, y); - for(SelContainer::const_iterator i=allList.begin();i!=allList.end();i++){ + std::vector x,y; + std::vector allList = get_all_items(x, document->getRoot(), desktop, false, false, true, y); + for(std::vector::const_reverse_iterator i=allList.rbegin();i!=allList.rend();i++){ SPItem *item = SP_ITEM(*i); SPStyle *style = item->style; @@ -1177,7 +1177,7 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p if (family_style.compare( family ) == 0 ) { //std::cout << " found: " << item->getId() << std::endl; - selectList.push_front(static_cast(item)); + selectList.push_back(item); } } } -- cgit v1.2.3 From 7e4b6f793d31d3245bd8afbf6f10aa255ac3e7ae Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 19 Feb 2015 20:20:09 +0100 Subject: added a set to the Selection (bzr r13922.1.6) --- src/extension/internal/cairo-renderer.cpp | 5 ++--- src/extension/internal/latex-text-renderer.cpp | 5 ++--- src/selection-chemistry.cpp | 10 ++++----- src/selection.cpp | 23 ++++++++++++++------ src/selection.h | 12 +++++------ src/sp-defs.cpp | 5 ++--- src/sp-filter.cpp | 5 ++--- src/sp-item-group.cpp | 29 +++++++++++--------------- src/sp-object.cpp | 6 +++--- src/sp-object.h | 5 +++-- src/sp-switch.cpp | 14 ++++++------- src/sp-switch.h | 2 +- src/ui/dialog/grid-arrange-tab.cpp | 28 ++++++++++--------------- src/ui/dialog/tags.cpp | 4 ++-- src/ui/tools/eraser-tool.cpp | 2 +- src/xml/repr-util.cpp | 12 +++++------ src/xml/repr.h | 3 ++- 17 files changed, 83 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 7ce5cdf8a..f614ec745 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -294,9 +294,8 @@ static void sp_group_render(SPGroup *group, CairoRenderContext *ctx) CairoRenderer *renderer = ctx->getRenderer(); TRACE(("sp_group_render opacity: %f\n", SP_SCALE24_TO_FLOAT(item->style->opacity.value))); - SelContainer l(group->childList(false)); - l.reverse(); - for(SelContainer::const_iterator x=l.begin();x!=l.end();x++){ + std::vector l(group->childList(false)); + for(std::vector::const_iterator x=l.begin();x!=l.end();x++){ SPObject *o = reinterpret_cast(*x); SPItem *item = dynamic_cast(o); if (item) { diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index dab27a0e1..a2de264ab 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -228,9 +228,8 @@ LaTeXTextRenderer::writePostamble() void LaTeXTextRenderer::sp_group_render(SPGroup *group) { - SelContainer l = (group->childList(false)); - l.reverse(); - for(SelContainer::const_iterator x=l.begin();x!=l.end();x++){ + std::vector l = (group->childList(false)); + for(std::vector::const_iterator x=l.begin();x!=l.end();x++){ SPObject *o = reinterpret_cast(*x); SPItem *item = dynamic_cast(o); if (item) { diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index f1c96b6b8..736e020dd 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -558,7 +558,7 @@ void sp_edit_clear_all(Inkscape::Selection *selection) g_return_if_fail(group != NULL); std::vector items = sp_item_group_item_list(group); - for(int i=0;i(items[i])->deleteObject(); } @@ -3061,7 +3061,7 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) doc->ensureUpToDate(); - SelContainer items(selection->list()); + std::vector items(selection->list()); // Keep track of parent, this is where will be inserted. Inkscape::XML::Node *the_first_repr = reinterpret_cast( items.front() )->getRepr(); @@ -3128,7 +3128,7 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) } // Move selected items to new - for (SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ Inkscape::XML::Node *repr = SP_OBJECT(*i)->getRepr(); repr->parent()->removeChild(repr); symbol_repr->addChild(repr,NULL); @@ -3195,7 +3195,7 @@ void sp_selection_unsymbol(SPDesktop *desktop) desktop->currentLayer()->getRepr()->appendChild(group); // Move all children of symbol to group - SelContainer children = symbol->childList(false); + std::vector children = symbol->childList(false); // Converting a group to a symbol inserts a group for non-translational transform. // In converting a symbol back to a group we strip out the inserted group (or any other @@ -3212,7 +3212,7 @@ void sp_selection_unsymbol(SPDesktop *desktop) } } - for (SelContainer::const_iterator i=children.begin();i!=children.end();i++){ + for (std::vector::const_iterator i=children.begin();i!=children.end();i++){ Inkscape::XML::Node *repr = SP_OBJECT(*i)->getRepr(); repr->parent()->removeChild(repr); group->addChild(repr,NULL); diff --git a/src/selection.cpp b/src/selection.cpp index 2e8251048..fd3b6abae 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -42,7 +42,9 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : - _objs(SelContainer()), + _objs(std::list()), + _objs_vector(std::vector()), + _objs_set(std::set()), _reprs(std::vector()), _items(std::vector()), _layers(layers), @@ -145,7 +147,7 @@ bool Selection::includes(SPObject *obj) const { g_return_val_if_fail(SP_IS_OBJECT(obj), FALSE); - return ( find(_objs.begin(),_objs.end(),obj)!=_objs.end() ); + return ( _objs_set.find(obj)!=_objs_set.end() ); } void Selection::add(SPObject *obj, bool persist_selection_context/* = false */) { @@ -178,6 +180,7 @@ void Selection::_add(SPObject *obj) { _removeObjectAncestors(obj); _objs.push_front(obj); + _objs_set.insert(obj); add_3D_boxes_recursively(obj); @@ -232,6 +235,7 @@ void Selection::_remove(SPObject *obj) { remove_3D_boxes_recursively(obj); _objs.remove(obj); + _objs_set.erase(obj); } void Selection::setList(std::vector const &list) { @@ -276,8 +280,15 @@ void Selection::clear() { _emitChanged(); } -SelContainer const &Selection::list() { - return _objs; +std::vector const &Selection::list() { + if(!_objs_vector.empty()) + return _objs_vector; + + for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + _objs_vector.push_back(*iter); + } + return _objs_vector; + } std::vector const &Selection::itemList() { @@ -285,7 +296,7 @@ std::vector const &Selection::itemList() { return _items; } - for ( SelContainer::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { SPObject *obj=reinterpret_cast(*iter); if (SP_IS_ITEM(obj)) { _items.push_back(SP_ITEM(obj)); @@ -470,7 +481,7 @@ std::vector Selection::getSnapPoints(SnapPreferenc } void Selection::_removeObjectDescendants(SPObject *obj) { - for ( SelContainer::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { SPObject *sel_obj=reinterpret_cast(*iter); SPObject *parent = sel_obj->parent; while (parent) { diff --git a/src/selection.h b/src/selection.h index 2d5e7c34a..e40810ded 100644 --- a/src/selection.h +++ b/src/selection.h @@ -16,14 +16,10 @@ #include #include #include +#include #include #include -#include -#include -#include -#include - #include "gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" @@ -254,7 +250,7 @@ public: XML::Node *singleRepr(); /** Returns the list of selected objects. */ - std::list const &list(); + std::vector const &list(); /** Returns the list of selected SPItems. */ std::vector const &itemList(); /** Returns a list of the xml nodes of all selected objects. */ @@ -376,7 +372,9 @@ private: /** Releases an active layer object that is being removed. */ void _releaseContext(SPObject *obj); - mutable std::list _objs; + mutable std::list _objs; //to more efficiently remove arbitrary elements + mutable std::vector _objs_vector; // to be returned by list(); + mutable std::set _objs_set; //to efficiently test if object is selected mutable std::vector _reprs; mutable std::vector _items; diff --git a/src/sp-defs.cpp b/src/sp-defs.cpp index d52fa038a..76843fd28 100644 --- a/src/sp-defs.cpp +++ b/src/sp-defs.cpp @@ -46,9 +46,8 @@ void SPDefs::update(SPCtx *ctx, guint flags) { } flags &= SP_OBJECT_MODIFIED_CASCADE; - SelContainer l(this->childList(true)); - l.reverse(); - for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + std::vector l(this->childList(true)); + for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ SPObject *child = SP_OBJECT(*i); if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->updateDisplay(ctx, flags); diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index bf8f7a5a4..93a979287 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -244,9 +244,8 @@ void SPFilter::update(SPCtx *ctx, guint flags) { childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } childflags &= SP_OBJECT_MODIFIED_CASCADE; - SelContainer l(this->childList(true, SPObject::ActionUpdate)); - l.reverse(); - for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + std::vector l(this->childList(true, SPObject::ActionUpdate)); + for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ SPObject *child = SP_OBJECT (*i); if( SP_IS_FILTER_PRIMITIVE( child ) ) { child->updateDisplay(ctx, childflags); diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index f09a4ee47..8a40df5ed 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -171,9 +171,8 @@ void SPGroup::update(SPCtx *ctx, unsigned int flags) { childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } childflags &= SP_OBJECT_MODIFIED_CASCADE; - SelContainer l=this->childList(true, SPObject::ActionUpdate); - l.reverse(); - for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + std::vector l=this->childList(true, SPObject::ActionUpdate); + for(std::vector ::const_iterator i=l.begin();i!=l.end();i++){ SPObject *child = SP_OBJECT (*i); if (childflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { @@ -216,9 +215,8 @@ void SPGroup::modified(guint flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; - SelContainer l=this->childList(true); - l.reverse(); - for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + std::vector l=this->childList(true); + for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ SPObject *child = SP_OBJECT (*i); if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { @@ -291,8 +289,8 @@ Geom::OptRect SPGroup::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox Geom::OptRect bbox; // TODO CPPIFY: replace this const_cast later - SelContainer l=const_cast(this)->childList(false, SPObject::ActionBBox); - for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + std::vector l=const_cast(this)->childList(false, SPObject::ActionBBox); + for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ SPObject *o = SP_OBJECT (*i); SPItem *item = dynamic_cast(o); if (item && !item->isHidden()) { @@ -305,9 +303,8 @@ Geom::OptRect SPGroup::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox } void SPGroup::print(SPPrintContext *ctx) { - SelContainer l=this->childList(false); - l.reverse(); - for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + std::vector l=this->childList(false); + for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ SPObject *o = SP_OBJECT (*i); SPItem *item = dynamic_cast(o); if (item) { @@ -360,9 +357,8 @@ Inkscape::DrawingItem *SPGroup::show (Inkscape::Drawing &drawing, unsigned int k } void SPGroup::hide (unsigned int key) { - SelContainer l=this->childList(false, SPObject::ActionShow); - l.reverse(); - for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + std::vector l=this->childList(false, SPObject::ActionShow); + for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ SPObject *o = SP_OBJECT (*i); SPItem *item = dynamic_cast(o); @@ -793,9 +789,8 @@ gint SPGroup::getItemCount() const { void SPGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags) { Inkscape::DrawingItem *ac = NULL; - SelContainer l=this->childList(false, SPObject::ActionShow); - l.reverse(); - for(SelContainer::const_iterator i=l.begin();i!=l.end();i++){ + std::vector l=this->childList(false, SPObject::ActionShow); + for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ SPObject *o = SP_OBJECT (*i); SPItem * child = dynamic_cast(o); if (child) { diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 3ea480f66..6cc5d7114 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -382,14 +382,14 @@ void SPObject::changeCSS(SPCSSAttr *css, gchar const *attr) sp_repr_css_change(this->getRepr(), css, attr); } -SelContainer SPObject::childList(bool add_ref, Action) { - SelContainer l; +std::vector SPObject::childList(bool add_ref, Action) { + std::vector l; for ( SPObject *child = firstChild() ; child; child = child->getNext() ) { if (add_ref) { sp_object_ref (child); } - l.push_front(child); + l.push_back(child); } return l; diff --git a/src/sp-object.h b/src/sp-object.h index 858587611..1f3032a52 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -55,6 +55,7 @@ class SPObject; #include #include #include +#include #include "version.h" #include "util/forward-pointer-iterator.h" @@ -335,10 +336,10 @@ public: enum Action { ActionGeneral, ActionBBox, ActionUpdate, ActionShow }; /** - * Retrieves the children as a GSList object, optionally ref'ing the children + * Retrieves the children as a std vector object, optionally ref'ing the children * in the process, if add_ref is specified. */ - SelContainer childList(bool add_ref, Action action = ActionGeneral); + std::vector childList(bool add_ref, Action action = ActionGeneral); /** * Append repr as child of this object. diff --git a/src/sp-switch.cpp b/src/sp-switch.cpp index 0090f1855..2c9427df8 100644 --- a/src/sp-switch.cpp +++ b/src/sp-switch.cpp @@ -55,13 +55,13 @@ SPObject *SPSwitch::_evaluateFirst() { return first; } -SelContainer SPSwitch::_childList(bool add_ref, SPObject::Action action) { +std::vector SPSwitch::_childList(bool add_ref, SPObject::Action action) { if ( action != SPObject::ActionGeneral ) { return this->childList(add_ref, action); } SPObject *child = _evaluateFirst(); - SelContainer x; + std::vector x; if (NULL == child) return x; @@ -69,7 +69,7 @@ SelContainer SPSwitch::_childList(bool add_ref, SPObject::Action action) { //g_object_ref (G_OBJECT (child)); sp_object_ref(child); } - x.push_front(child); + x.push_back(child); return x; } @@ -110,8 +110,8 @@ void SPSwitch::_reevaluate(bool /*add_to_drawing*/) { _releaseLastItem(_cached_item); - SelContainer item_list = _childList(false, SPObject::ActionShow); - for ( SelContainer::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + std::vector item_list = _childList(false, SPObject::ActionShow); + for ( std::vector::const_reverse_iterator iter=item_list.rbegin();iter!=item_list.rend();iter++) { SPObject *o = SP_OBJECT (*iter); if ( !SP_IS_ITEM (o) ) { continue; @@ -144,9 +144,9 @@ void SPSwitch::_releaseLastItem(SPObject *obj) void SPSwitch::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags) { SPObject *evaluated_child = this->_evaluateFirst(); - SelContainer l = this->_childList(false, SPObject::ActionShow); + std::vector l = this->_childList(false, SPObject::ActionShow); - for ( SelContainer::const_iterator iter=l.begin();iter!=l.end();iter++) { + for ( std::vector::const_reverse_iterator iter=l.rbegin();iter!=l.rend();iter++) { SPObject *o = SP_OBJECT (*iter); if (SP_IS_ITEM (o)) { diff --git a/src/sp-switch.h b/src/sp-switch.h index 6a83072e7..7152e1b82 100644 --- a/src/sp-switch.h +++ b/src/sp-switch.h @@ -29,7 +29,7 @@ public: void resetChildEvaluated() { _reevaluate(); } - SelContainer _childList(bool add_ref, SPObject::Action action); + std::vector _childList(bool add_ref, SPObject::Action action); virtual void _showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags); SPObject *_evaluateFirst(); diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index d62032e9d..10498b0f9 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -48,7 +48,7 @@ * 0 *elem1 == *elem2 * >0 *elem1 goes after *elem2 */ -static int sp_compare_x_position(SPItem *first, SPItem *second) +static bool sp_compare_x_position(SPItem *first, SPItem *second) { using Geom::X; using Geom::Y; @@ -58,7 +58,7 @@ static int sp_compare_x_position(SPItem *first, SPItem *second) if ( !a || !b ) { // FIXME? - return 0; + return false; } double const a_height = a->dimensions()[Y]; @@ -76,44 +76,38 @@ static int sp_compare_x_position(SPItem *first, SPItem *second) } if (!a_in_b_vert) { - return -1; + return true; } if (a_in_b_vert && a->min()[X] > b->min()[X]) { - return 1; + return false; } if (a_in_b_vert && a->min()[X] < b->min()[X]) { - return -1; + return true; } - return 0; + return false; } /* * Sort items by their y co-ordinates. */ -static int sp_compare_y_position(SPItem *first, SPItem *second) +static bool sp_compare_y_position(SPItem *first, SPItem *second) { Geom::OptRect a = first->documentVisualBounds(); Geom::OptRect b = second->documentVisualBounds(); if ( !a || !b ) { // FIXME? - return 0; + return false; } if (a->min()[Geom::Y] > b->min()[Geom::Y]) { - return 1; + return false; } if (a->min()[Geom::Y] < b->min()[Geom::Y]) { - return -1; + return true; } - return 0; -} -static bool sp_compare_y_position_obj(SPObject *first, SPObject *second){ - return sp_compare_y_position(static_cast(first),static_cast(second))<0; -} -static bool sp_compare_x_position_obj(SPObject *first, SPObject *second){ - return sp_compare_x_position(static_cast(first),static_cast(second))<0; + return false; } diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index c2df5fc1c..bd34c7c66 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -371,8 +371,8 @@ void TagsPanel::_objectsSelected( Selection *sel ) { _selectedConnection.block(); _tree.get_selection()->unselect_all(); - SelContainer tmp=sel->list(); - for(SelContainer::const_iterator i=tmp.begin();i!=tmp.end();i++) + std::vector tmp=sel->list(); + for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++) { SPObject *obj = reinterpret_cast(*i); _store->foreach(sigc::bind( sigc::mem_fun(*this, &TagsPanel::_checkForSelected), obj)); diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 520b93e72..b61a108f0 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -711,7 +711,7 @@ void EraserTool::set_to_accumulated() { if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. std::vector nowSel(selection->itemList()); - for (std::vector::const_iterator i2 = nowSel.begin();i!=nowSel.end();i2++) { + for (std::vector::const_iterator i2 = nowSel.begin();i2!=nowSel.end();i2++) { remainingItems.push_back(SP_ITEM(*i2)); } } diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index 12280ea5a..447f2ff40 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -259,7 +259,7 @@ gchar const *sp_xml_ns_prefix_uri(gchar const *prefix) * -1 first object's position is less than the second * @todo Rewrite this function's description to be understandable */ -int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second) +bool sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second) { int p1, p2; if (first->parent() == second->parent()) { @@ -276,9 +276,9 @@ int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::No g_assert(ancestor != NULL); if (ancestor == first) { - return 1; + return false; } else if (ancestor == second) { - return -1; + return true; } else { Inkscape::XML::Node const *to_first = AncetreFils(first, ancestor); Inkscape::XML::Node const *to_second = AncetreFils(second, ancestor); @@ -288,9 +288,9 @@ int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::No } } - if (p1 > p2) return 1; - if (p1 < p2) return -1; - return 0; + if (p1 > p2) return false; + if (p1 < p2) return true; + return false; /* effic: Assuming that the parent--child relationship is consistent (i.e. that the parent really does contain first and second among diff --git a/src/xml/repr.h b/src/xml/repr.h index e1d7fdfd6..c96560a98 100644 --- a/src/xml/repr.h +++ b/src/xml/repr.h @@ -118,7 +118,8 @@ unsigned sp_repr_set_svg_double(Inkscape::XML::Node *repr, char const *key, doub unsigned sp_repr_set_point(Inkscape::XML::Node *repr, char const *key, Geom::Point const & val); unsigned sp_repr_get_point(Inkscape::XML::Node *repr, char const *key, Geom::Point *val); -int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second); +//c++-style comparison : returns (bool)(a Date: Mon, 23 Feb 2015 22:41:06 +0100 Subject: Removed eclipse files, added removed pot file (bzr r13922.1.7) --- src/helper/png-write.h | 4 ---- src/selection.h | 2 -- src/sp-object.h | 3 --- 3 files changed, 9 deletions(-) (limited to 'src') diff --git a/src/helper/png-write.h b/src/helper/png-write.h index 04ca85cd6..2657fb635 100644 --- a/src/helper/png-write.h +++ b/src/helper/png-write.h @@ -14,12 +14,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include <2geom/forward.h> -//should be in selection.h -typedef std::list SelContainer; - class SPDocument; diff --git a/src/selection.h b/src/selection.h index e40810ded..71be6dd6b 100644 --- a/src/selection.h +++ b/src/selection.h @@ -33,8 +33,6 @@ class SPItem; class SPBox3D; class Persp3D; -typedef std::list SelContainer; - namespace Inkscape { class LayerModel; namespace XML { diff --git a/src/sp-object.h b/src/sp-object.h index 1f3032a52..7c189b01b 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -64,9 +64,6 @@ class SPCSSAttr; class SPStyle; typedef struct _GSList GSList; -//should be in selection.h -typedef std::list SelContainer; - namespace Inkscape { -- cgit v1.2.3 From 9a7fa4d1899d30ec745107823f307b2a0bf3172f Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 27 Feb 2015 03:10:36 +0100 Subject: corrected the casts (hopefully) (bzr r13922.1.10) --- src/conn-avoid-ref.cpp | 4 +- src/desktop-style.cpp | 38 +++--- src/desktop-style.h | 2 +- src/document.cpp | 2 +- src/document.h | 1 - src/extension/execution-env.cpp | 2 +- src/extension/implementation/implementation.cpp | 2 +- src/extension/implementation/script.cpp | 2 +- src/extension/internal/bitmap/imagemagick.cpp | 4 +- src/extension/internal/bluredge.cpp | 2 +- src/extension/internal/cairo-renderer.cpp | 2 +- src/extension/internal/filter/filter.cpp | 2 +- src/extension/internal/grid.cpp | 2 +- src/extension/internal/latex-text-renderer.cpp | 4 +- src/file.cpp | 2 +- src/filter-chemistry.cpp | 2 +- src/gradient-chemistry.cpp | 10 +- src/gradient-drag.cpp | 12 +- src/graphlayout.cpp | 4 +- src/live_effects/lpe-knot.cpp | 2 +- src/main.cpp | 3 - src/object-snapper.cpp | 4 +- src/path-chemistry.cpp | 49 +++----- src/removeoverlap.cpp | 2 +- src/selcue.cpp | 10 +- src/selection-chemistry.cpp | 148 ++++++++++-------------- src/selection-chemistry.h | 1 - src/selection-describer.cpp | 8 +- src/selection.cpp | 16 +-- src/selection.h | 8 -- src/seltrans.cpp | 9 +- src/snap.cpp | 2 +- src/sp-conn-end.cpp | 2 +- src/sp-defs.cpp | 2 +- src/sp-filter.cpp | 2 +- src/sp-item-group.cpp | 14 +-- src/sp-item-group.h | 1 - src/sp-marker.cpp | 2 +- src/sp-object.h | 4 - src/sp-pattern.cpp | 2 +- src/sp-switch.cpp | 4 +- src/splivarot.cpp | 21 ++-- src/splivarot.h | 3 +- src/text-chemistry.cpp | 10 +- src/text-editing.cpp | 2 +- src/trace/trace.cpp | 2 +- src/ui/clipboard.cpp | 10 +- src/ui/dialog/align-and-distribute.cpp | 26 ++--- src/ui/dialog/export.cpp | 4 +- src/ui/dialog/filter-effects-dialog.cpp | 6 +- src/ui/dialog/find.cpp | 2 +- src/ui/dialog/find.h | 1 - src/ui/dialog/font-substitution.cpp | 2 +- src/ui/dialog/font-substitution.h | 3 +- src/ui/dialog/glyphs.cpp | 2 +- src/ui/dialog/grid-arrange-tab.cpp | 2 +- src/ui/dialog/icon-preview.cpp | 2 +- src/ui/dialog/objects.cpp | 2 +- src/ui/dialog/polar-arrange-tab.cpp | 4 +- src/ui/dialog/tags.cpp | 2 +- src/ui/dialog/text-edit.cpp | 2 +- src/ui/dialog/transformation.cpp | 20 ++-- src/ui/interface.cpp | 2 +- src/ui/tools/connector-tool.cpp | 2 +- src/ui/tools/eraser-tool.cpp | 10 +- src/ui/tools/gradient-tool.cpp | 20 ++-- src/ui/tools/gradient-tool.h | 3 +- src/ui/tools/measure-tool.cpp | 2 +- src/ui/tools/mesh-tool.cpp | 11 +- src/ui/tools/select-tool.cpp | 2 +- src/ui/tools/spray-tool.cpp | 6 +- src/ui/tools/tweak-tool.cpp | 2 +- src/unclump.cpp | 10 +- src/unclump.h | 1 - src/vanishing-point.cpp | 8 +- src/widgets/arc-toolbar.cpp | 8 +- src/widgets/connector-toolbar.cpp | 4 +- src/widgets/fill-style.cpp | 6 +- src/widgets/gradient-toolbar.cpp | 6 +- src/widgets/mesh-toolbar.cpp | 4 +- src/widgets/rect-toolbar.cpp | 4 +- src/widgets/spiral-toolbar.cpp | 4 +- src/widgets/star-toolbar.cpp | 12 +- src/widgets/stroke-style.cpp | 7 +- src/widgets/text-toolbar.cpp | 8 +- 85 files changed, 294 insertions(+), 370 deletions(-) (limited to 'src') diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp index fb9fbd935..eb6694233 100644 --- a/src/conn-avoid-ref.cpp +++ b/src/conn-avoid-ref.cpp @@ -253,8 +253,8 @@ static std::vector approxItemWithPoints(SPItem const *item, const G SPGroup* group = SP_GROUP(item); // consider all first-order children std::vector itemlist = sp_item_group_item_list(group); - for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { - SPItem* child_item = SP_ITEM(*i); + for (std::vector::const_iterator i = itemlist.begin(); i != itemlist.end(); i++) { + SPItem* child_item = *i; std::vector child_points = approxItemWithPoints(child_item, item_transform * child_item->transform); poly_points.insert(poly_points.end(), child_points.begin(), child_points.end()); } diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index e1a81f00a..82f66dcdf 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -195,9 +195,9 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_css_attr_unset_uris(css_write); prefs->mergeStyle("/desktop/style", css_write); std::vector const itemlist = desktop->selection->itemList(); - for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + for (std::vector::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) { /* last used styles for 3D box faces are stored separately */ - SPObject *obj = reinterpret_cast(*i); // TODO unsafe until Selection is refactored. + SPObject *obj = reinterpret_cast(*i); Box3DSide *side = dynamic_cast(obj); if (side) { const char * descr = box3d_side_axes_string(side); @@ -235,8 +235,8 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write css_no_text = sp_css_attr_unset_text(css_no_text); std::vector const itemlist = desktop->selection->itemList(); - for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { - SPItem *item = reinterpret_cast(*i); + for (std::vector::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) { + SPItem *item = *i; // If not text, don't apply text attributes (can a group have text attributes? Yes! FIXME) if (isTextualItem(item)) { @@ -447,9 +447,9 @@ stroke_average_width (const std::vector &objects) gdouble avgwidth = 0.0; bool notstroked = true; int n_notstroked = 0; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); - SPItem *item = dynamic_cast(obj); + SPItem *item = *i; if (!item) { continue; } @@ -514,7 +514,7 @@ objects_query_fillstroke (const std::vector &objects, SPStyle *style_re prev[0] = prev[1] = prev[2] = 0.0; bool same_color = true; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i!= objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; @@ -698,7 +698,7 @@ objects_query_opacity (const std::vector &objects, SPStyle *style_res) guint opacity_items = 0; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; @@ -754,7 +754,7 @@ objects_query_strokewidth (const std::vector &objects, SPStyle *style_r int n_stroked = 0; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; @@ -828,7 +828,7 @@ objects_query_miterlimit (const std::vector &objects, SPStyle *style_re gdouble prev_ml = -1; bool same_ml = true; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!dynamic_cast(obj)) { continue; @@ -887,7 +887,7 @@ objects_query_strokecap (const std::vector &objects, SPStyle *style_res bool same_cap = true; int n_stroked = 0; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!dynamic_cast(obj)) { continue; @@ -941,7 +941,7 @@ objects_query_strokejoin (const std::vector &objects, SPStyle *style_re bool same_join = true; int n_stroked = 0; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!dynamic_cast(obj)) { continue; @@ -1004,7 +1004,7 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r int texts = 0; int no_size = 0; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!isTextualItem(obj)) { @@ -1123,7 +1123,7 @@ objects_query_fontstyle (const std::vector &objects, SPStyle *style_res int texts = 0; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!isTextualItem(obj)) { @@ -1192,7 +1192,7 @@ objects_query_baselines (const std::vector &objects, SPStyle *style_res int texts = 0; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!isTextualItem(obj)) { @@ -1280,7 +1280,7 @@ objects_query_fontfamily (const std::vector &objects, SPStyle *style_re } style_res->font_family.set = FALSE; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; @@ -1336,7 +1336,7 @@ objects_query_fontspecification (const std::vector &objects, SPStyle *s } style_res->font_specification.set = FALSE; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; @@ -1394,7 +1394,7 @@ objects_query_blend (const std::vector &objects, SPStyle *style_res) bool same_blend = true; guint items = 0; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; @@ -1484,7 +1484,7 @@ objects_query_blur (const std::vector &objects, SPStyle *style_res) guint blur_items = 0; guint items = 0; - for (std::vector::const_iterator i=objects.begin();i!=objects.end();i++) { + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { SPObject *obj = reinterpret_cast(*i); if (!obj) { continue; diff --git a/src/desktop-style.h b/src/desktop-style.h index 7ca25b9ae..a72f49776 100644 --- a/src/desktop-style.h +++ b/src/desktop-style.h @@ -13,11 +13,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "selection.h" // SelContainer class ColorRGBA; class SPCSSAttr; class SPDesktop; class SPObject; +class SPItem; class SPStyle; typedef struct _GSList GSList; namespace Inkscape { diff --git a/src/document.cpp b/src/document.cpp index 07ad10505..0582f1a70 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1289,7 +1289,7 @@ SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *gro Inkscape::DrawingItem *arenaitem = item->get_arenaitem(dkey); if (arenaitem && arenaitem->pick(p, delta, 1) != NULL && (take_insensitive || item->isVisibleAndUnlocked(dkey))) { - if (find(list.begin(),list.end(),item)==list.end() ) { + if (find(list.begin(),list.end(),item)!=list.end() ) { bottomMost = item; } } diff --git a/src/document.h b/src/document.h index 57ff7643c..bc5b2745a 100644 --- a/src/document.h +++ b/src/document.h @@ -27,7 +27,6 @@ #include #include #include -#include "selection.h" namespace Avoid { class Router; diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index 90a7810e6..971f0b64a 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -65,7 +65,7 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Imp if (desktop != NULL) { std::vector selected = desktop->getSelection()->itemList(); - for(std::vector::const_iterator x=selected.begin();x!=selected.end();x++){ + for(std::vector::const_iterator x = selected.begin(); x != selected.end(); x++){ Glib::ustring selected_id; selected_id = (*x)->getId(); _selected.insert(_selected.end(), selected_id); diff --git a/src/extension/implementation/implementation.cpp b/src/extension/implementation/implementation.cpp index cea6d139f..11c494b18 100644 --- a/src/extension/implementation/implementation.cpp +++ b/src/extension/implementation/implementation.cpp @@ -51,7 +51,7 @@ Gtk::Widget *Implementation::prefs_effect(Inkscape::Extension::Effect *module, I std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node const* first_select = NULL; if (!selected.empty()) { - const SPItem * item = SP_ITEM(selected.front()); + const SPItem * item = selected.front(); first_select = item->getRepr(); } diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 95d5c7edc..5c708cf9a 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -691,7 +691,7 @@ void Script::effect(Inkscape::Extension::Effect *module, std::vector selected = desktop->getSelection()->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer - for(std::vector::const_iterator x=selected.begin();x!=selected.end();x++){ + for(std::vector::const_iterator x = selected.begin(); x != selected.end(); x++){ Glib::ustring selected_id; selected_id += "--id="; selected_id += (*x)->getId(); diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index 64abd6c4d..3a29b3dc0 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -83,8 +83,8 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : _imageItems = new SPItem*[selectCount]; // Loop through selected items - for (std::vector::const_iterator i=selectedItemList.begin();i!=selectedItemList.end();i++) { - SPItem *item = static_cast(*i); + for (std::vector::const_iterator i = selectedItemList.begin(); i != selectedItemList.end(); i++) { + SPItem *item = *i; Inkscape::XML::Node *node = reinterpret_cast(item->getRepr()); if (!strcmp(node->name(), "image") || !strcmp(node->name(), "svg:image")) { diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp index 257cac161..b80e5ddbb 100644 --- a/src/extension/internal/bluredge.cpp +++ b/src/extension/internal/bluredge.cpp @@ -70,7 +70,7 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View for(std::vector::iterator item = items.begin(); item != items.end(); ++item) { - SPItem * spitem = static_cast(*item); + SPItem * spitem = *item; std::vector new_items(steps); Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index f614ec745..b30c8892e 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -295,7 +295,7 @@ static void sp_group_render(SPGroup *group, CairoRenderContext *ctx) TRACE(("sp_group_render opacity: %f\n", SP_SCALE24_TO_FLOAT(item->style->opacity.value))); std::vector l(group->childList(false)); - for(std::vector::const_iterator x=l.begin();x!=l.end();x++){ + for(std::vector::const_iterator x = l.begin(); x!= l.end(); x++){ SPObject *o = reinterpret_cast(*x); SPItem *item = dynamic_cast(o); if (item) { diff --git a/src/extension/internal/filter/filter.cpp b/src/extension/internal/filter/filter.cpp index a5eb7de60..65162af22 100644 --- a/src/extension/internal/filter/filter.cpp +++ b/src/extension/internal/filter/filter.cpp @@ -133,7 +133,7 @@ void Filter::effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::Vie for(std::vector::iterator item = items.begin(); item != items.end(); ++item) { - SPItem * spitem = static_cast(*item); + SPItem * spitem = *item; Inkscape::XML::Node * node = spitem->getRepr(); SPCSSAttr * css = sp_repr_css_attr(node, "style"); diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index 440c6b822..60d606a02 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -195,7 +195,7 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; if (!selected.empty()) { - first_select = (selected.front())->getRepr(); + first_select = selected[0]->getRepr(); } return module->autogui(current_document, first_select, changeSignal); diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index a2de264ab..831a8d030 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -229,8 +229,8 @@ LaTeXTextRenderer::writePostamble() void LaTeXTextRenderer::sp_group_render(SPGroup *group) { std::vector l = (group->childList(false)); - for(std::vector::const_iterator x=l.begin();x!=l.end();x++){ - SPObject *o = reinterpret_cast(*x); + for(std::vector::const_iterator x = l.begin(); x != l.end(); x++){ + SPObject *o = *x; SPItem *item = dynamic_cast(o); if (item) { renderItem(item); diff --git a/src/file.cpp b/src/file.cpp index f33e284b2..07e41c550 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1088,7 +1088,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place) target_parent->appendChild(obj_copy); Inkscape::GC::release(obj_copy); - pasted_objects.push_back((obj_copy)); + pasted_objects.push_back(obj_copy); } // Change the selection to the freshly pasted objects diff --git a/src/filter-chemistry.cpp b/src/filter-chemistry.cpp index c89cf6220..9298a1ffc 100644 --- a/src/filter-chemistry.cpp +++ b/src/filter-chemistry.cpp @@ -23,9 +23,9 @@ #include "filter-chemistry.h" #include "filter-enums.h" + #include "filters/blend.h" #include "filters/gaussian-blur.h" -#include "selection.h" #include "sp-filter.h" #include "sp-filter-reference.h" #include "svg/css-ostringstream.h" diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index a72423bbb..b59b38475 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1571,8 +1571,8 @@ void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTa Inkscape::Selection *selection = desktop->getSelection(); const std::vector list=selection->itemList(); - for (std::vector::const_iterator i=list.begin();i!=list.end();i++) { - sp_item_gradient_invert_vector_color(SP_ITEM(*i), fill_or_stroke); + for (std::vector::const_iterator i = list.begin(); i != list.end(); i++) { + sp_item_gradient_invert_vector_color(*i, fill_or_stroke); } // we did an undoable action @@ -1596,9 +1596,9 @@ void sp_gradient_reverse_selected_gradients(SPDesktop *desktop) drag->selected_reverse_vector(); } else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients) const std::vector list=selection->itemList(); - for (std::vector::const_iterator i=list.begin();i!=list.end();i++) { - sp_item_gradient_reverse_vector(SP_ITEM(*i), Inkscape::FOR_FILL); - sp_item_gradient_reverse_vector(SP_ITEM(*i), Inkscape::FOR_STROKE); + for (std::vector::const_iterator i = list.begin(); i != list.end(); i++) { + sp_item_gradient_reverse_vector(*i, Inkscape::FOR_FILL); + sp_item_gradient_reverse_vector(*i, Inkscape::FOR_STROKE); } } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 525fc074f..5a49435d4 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -2083,8 +2083,8 @@ void GrDrag::updateDraggers() g_return_if_fail(this->selection != NULL); std::vector list = this->selection->itemList(); - for (std::vector::const_iterator i=list.begin();i!=list.end();i++) { - SPItem *item = SP_ITEM(*i); + for (std::vector::const_iterator i = list.begin(); i != list.end(); i++) { + SPItem *item = *i; SPStyle *style = item->style; if (style && (style->fill.isPaintserver())) { @@ -2152,8 +2152,8 @@ void GrDrag::updateLines() g_return_if_fail(this->selection != NULL); std::vector list = this->selection->itemList(); - for (std::vector::const_iterator i=list.begin();i!=list.end();i++) { - SPItem *item = SP_ITEM(*i); + for (std::vector::const_iterator i = list.begin(); i != list.end(); i++) { + SPItem *item = *i; SPStyle *style = item->style; @@ -2296,8 +2296,8 @@ void GrDrag::updateLevels() g_return_if_fail (this->selection != NULL); std::vector list = this->selection->itemList(); - for (std::vector::const_iterator i=list.begin();i!=list.end();i++) { - SPItem *item = SP_ITEM(*i); + for (std::vector::const_iterator i = list.begin(); i != list.end(); i++) { + SPItem *item = *i; Geom::OptRect rect = item->desktopVisualBounds(); if (rect) { // Remember the edges of the bbox and the center axis diff --git a/src/graphlayout.cpp b/src/graphlayout.cpp index 4d590173a..40994347c 100644 --- a/src/graphlayout.cpp +++ b/src/graphlayout.cpp @@ -89,8 +89,8 @@ struct CheckProgress : TestConvergence { * not connectors in filtered */ void filterConnectors(std::vector const &items, list &filtered) { - for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = SP_ITEM(*i); + for(std::vector::const_iterator i = items.begin();i !=items.end(); i++){ + SPItem *item = *i; if(!isConnector(item)) { filtered.push_back(item); } diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 6cdf09180..7a1d391a3 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -506,7 +506,7 @@ static void collectPathsAndWidths (SPLPEItem const *lpeitem, std::vector &paths, std::vector &stroke_widths){ if (SP_IS_GROUP(lpeitem)) { std::vector item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); - for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + for ( std::vector::const_iterator iter = item_list.begin(); iter != item_list.end(); iter++) { SPObject *subitem = static_cast(*iter); if (SP_IS_LPE_ITEM(subitem)) { collectPathsAndWidths(SP_LPE_ITEM(subitem), paths, stroke_widths); diff --git a/src/main.cpp b/src/main.cpp index c62b9cd25..062edcb98 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1174,9 +1174,6 @@ static int sp_process_file_list(GSList *fl) sp_item_list_to_curves(items, selected, to_select); - items.clear(); - selected.clear(); - to_select.clear(); } if(sp_export_id) { doc->ensureUpToDate(); diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 830c3c1db..f9c189c58 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -238,8 +238,8 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, bool old_pref2 = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_ROTATION_CENTER); if (old_pref2) { std::vector rotationSource=_snapmanager->getRotationCenterSource(); - for ( std::vector::const_iterator itemlist=rotationSource.begin();itemlist!=rotationSource.end();itemlist++) { - if ((*i).item == reinterpret_cast(*itemlist)) { + for ( std::vector::const_iterator itemlist = rotationSource.begin(); itemlist != rotationSource.end(); itemlist++) { + if ((*i).item == *itemlist) { // don't snap to this item's rotation center _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_ROTATION_CENTER, false); break; diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index ae1e0064f..53ad96596 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -45,16 +45,10 @@ using Inkscape::DocumentUndo; -inline bool less_than_objects(SPObject const *first, SPObject const *second) -{ - return sp_repr_compare_position(first->getRepr(), - second->getRepr())<0; -} - inline bool less_than_items(SPItem const *first, SPItem const *second) { return sp_repr_compare_position(first->getRepr(), - second->getRepr())<0; + second->getRepr())>0; } void @@ -77,21 +71,19 @@ sp_selected_path_combine(SPDesktop *desktop) items = sp_degroup_list (items); // descend into any groups in selection std::vector to_paths; - for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++) { - SPItem *item = (SPItem *) (*i); - if (!dynamic_cast(item) && !dynamic_cast(item)) { - to_paths.push_back(item); + for (std::vector::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++) { + if (!dynamic_cast(*i) && !dynamic_cast(*i)) { + to_paths.push_back(*i); } } std::vector converted; bool did = sp_item_list_to_curves(to_paths, items, converted); - to_paths.clear(); - for (std::vector::const_iterator i=converted.begin();i!=converted.end();i++) - items.push_back((SPItem*)doc->getObjectByRepr((Inkscape::XML::Node*)(*i))); + for (std::vector::const_iterator i = converted.begin(); i != converted.end(); i++) + items.push_back((SPItem*)doc->getObjectByRepr(*i)); items = sp_degroup_list (items); // converting to path may have added more groups, descend again - sort(items.begin(),items.end(),less_than_objects); + sort(items.begin(),items.end(),less_than_items); assert(!items.empty()); // cannot be NULL because of list length check at top of function // remember the position, id, transform and style of the topmost path, they will be assigned to the combined one @@ -109,9 +101,9 @@ sp_selected_path_combine(SPDesktop *desktop) selection->clear(); } - for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for (std::vector::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++){ - SPItem *item = (SPItem *) (*i); + SPItem *item = *i; SPPath *path = dynamic_cast(item); if (!path) { continue; @@ -212,9 +204,9 @@ sp_selected_path_break_apart(SPDesktop *desktop) bool did = false; std::vector itemlist(selection->itemList()); - for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for (std::vector::const_iterator i = itemlist.begin(); i != itemlist.end(); i++){ - SPItem *item = (SPItem *) (*i); + SPItem *item = *i; SPPath *path = dynamic_cast(item); if (!path) { @@ -277,11 +269,10 @@ sp_selected_path_break_apart(SPDesktop *desktop) if (l == list) repr->setAttribute("id", id); - reprs.push_back(repr); + reprs.insert(reprs.begin(),repr); Inkscape::GC::release(repr); } - //reverse selection->setReprList(reprs); g_slist_free(list); @@ -323,11 +314,8 @@ sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, b did = sp_item_list_to_curves(items, selected, to_select); - items.clear(); selection->setReprList(to_select); selection->addList(selected); - to_select.clear(); - selected.clear(); if (interactive && desktop) { desktop->clearWaitingCursor(); @@ -367,9 +355,9 @@ sp_item_list_to_curves(const std::vector &items, std::vector& { bool did = false; - for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i = items.begin(); i != items.end(); i++){ - SPItem *item = dynamic_cast(static_cast(*i)); + SPItem *item = *i; g_assert(item != NULL); SPDocument *document = item->document; @@ -400,7 +388,7 @@ sp_item_list_to_curves(const std::vector &items, std::vector& Inkscape::XML::Node *repr = box3d_convert_to_group(box)->getRepr(); if (repr) { - to_select.push_back(repr); + to_select.insert(to_select.begin(),repr); did = true; selected.erase(find(selected.begin(),selected.end(),item)); } @@ -418,9 +406,6 @@ sp_item_list_to_curves(const std::vector &items, std::vector& if (sp_item_list_to_curves(item_list, item_selected, item_to_select)) did = true; - item_list.clear(); - item_to_select.clear(); - item_selected.clear(); continue; } @@ -472,7 +457,7 @@ sp_item_list_to_curves(const std::vector &items, std::vector& /* Buglet: We don't re-add the (new version of the) object to the selection of any other * desktops where it was previously selected. */ - to_select.push_back(repr); + to_select.insert(to_select.begin(),repr); Inkscape::GC::release(repr); } @@ -628,7 +613,7 @@ sp_selected_path_reverse(SPDesktop *desktop) bool did = false; desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths...")); - for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector::const_iterator i = items.begin(); i != items.end(); i++){ SPPath *path = dynamic_cast(static_cast(*i)); if (!path) { diff --git a/src/removeoverlap.cpp b/src/removeoverlap.cpp index 7cb1694e3..01ce2c47e 100644 --- a/src/removeoverlap.cpp +++ b/src/removeoverlap.cpp @@ -49,7 +49,7 @@ void removeoverlap(std::vector const &items, double const xGap, double it != selected.end(); ++it) { - SPItem* item=static_cast(*it); + SPItem* item = *it; using Geom::X; using Geom::Y; Geom::OptRect item_box((item)->desktopVisualBounds()); if (item_box) { diff --git a/src/selcue.cpp b/src/selcue.cpp index f48378cdc..76eae3fa8 100644 --- a/src/selcue.cpp +++ b/src/selcue.cpp @@ -104,8 +104,8 @@ void Inkscape::SelCue::_updateItemBboxes(gint mode, int prefs_bbox) int bcount = 0; std::vector ll=_selection->itemList(); - for (std::vector::const_iterator l=ll.begin();l!=ll.end();l++) { - SPItem *item = static_cast(*l); + for (std::vector::const_iterator l = ll.begin(); l != ll.end(); l++) { + SPItem *item = *l; SPCanvasItem* box = _item_bboxes[bcount ++]; if (box) { @@ -147,8 +147,8 @@ void Inkscape::SelCue::_newItemBboxes() int prefs_bbox = prefs->getBool("/tools/bounding_box"); std::vector ll=_selection->itemList(); - for (std::vector::const_iterator l=ll.begin();l!=ll.end();l++) { - SPItem *item = static_cast(*l); + for (std::vector::const_iterator l = ll.begin(); l != ll.end(); l++) { + SPItem *item = *l; Geom::OptRect const b = (prefs_bbox == 0) ? item->desktopVisualBounds() : item->desktopGeometricBounds(); @@ -201,7 +201,7 @@ void Inkscape::SelCue::_newTextBaselines() } _text_baselines.clear(); - std::vector ll=_selection->itemList(); + std::vector ll = _selection->itemList(); for (std::vector::const_iterator l=ll.begin();l!=ll.end();l++) { SPItem *item = static_cast(*l); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 3c91392cf..d6f8b8a37 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -283,8 +283,8 @@ void SelectionHelper::fixSelection(SPDesktop *dt) std::vector const selList = selection->itemList(); - for( std::vector::const_reverse_iterator i=selList.rbegin();i!=selList.rend();i++ ) { - SPItem *item = dynamic_cast(static_cast(*i)); + for( std::vector::const_reverse_iterator i = selList.rbegin(); i != selList.rend(); i++ ) { + SPItem *item = *i; if( item && !dt->isLayer(item) && (!item->isLocked())) @@ -303,7 +303,7 @@ void SelectionHelper::fixSelection(SPDesktop *dt) * Copies repr and its inherited css style elements, along with the accumulated transform 'full_t', * then prepends the copy to 'clip'. */ -static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, std::vector &clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, std::vector &clip, Inkscape::XML::Document* xml_doc) { Inkscape::XML::Node *copy = repr->duplicate(xml_doc); @@ -319,31 +319,32 @@ static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t copy->setAttribute("transform", affinestr); g_free(affinestr); - clip.insert(clip.begin(),dynamic_cast(copy)); + clip.insert(clip.begin(),copy); } -static void sp_selection_copy_impl(std::vector const &items, std::vector &clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_impl(std::vector const &items, std::vector &clip, Inkscape::XML::Document* xml_doc) { // Sort items: std::vector sorted_items(items); sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position); // Copy item reprs: - for (std::vector::const_iterator i = sorted_items.begin();i!=sorted_items.end();i++) { - SPItem *item = dynamic_cast(SP_OBJECT(*i)); + for (std::vector::const_iterator i = sorted_items.begin(); i != sorted_items.end(); i++) { + SPItem *item = *i; if (item) { sp_selection_copy_one(item->getRepr(), item->i2doc_affine(), clip, xml_doc); } else { g_assert_not_reached(); } } - std::vector tmp(clip); - for(int i=0;i tmp(clip); + for(int i=0;i sp_selection_paste_impl(SPDocument *doc, SPObject *parent, std::vector &clip) +static std::vector sp_selection_paste_impl(SPDocument *doc, SPObject *parent, std::vector &clip) { Inkscape::XML::Document *xml_doc = doc->getReprDoc(); @@ -352,8 +353,8 @@ static std::vector sp_selection_paste_impl(SPDocument *doc std::vector copied; // add objects to document - for (std::vector::const_iterator l=clip.begin();l!=clip.end();l++) { - Inkscape::XML::Node *repr = dynamic_cast(*l); + for (std::vector::const_iterator l = clip.begin(); l != clip.end(); l++) { + Inkscape::XML::Node *repr = *l; Inkscape::XML::Node *copy = repr->duplicate(xml_doc); // premultiply the item transform by the accumulated parent transform in the paste layer @@ -379,11 +380,11 @@ static std::vector sp_selection_paste_impl(SPDocument *doc static void sp_selection_delete_impl(std::vector const &items, bool propagate = true, bool propagate_descendants = true) { - for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { - sp_object_ref(static_cast(*i), NULL); + for (std::vector::const_iterator i = items.begin(); i != items.end(); i++) { + sp_object_ref(*i, NULL); } - for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { - SPItem *item = static_cast(*i); + for (std::vector::const_iterator i = items.begin(); i != items.end(); i++) { + SPItem *item = *i; item->deleteObject(propagate, propagate_descendants); sp_object_unref(item, NULL); } @@ -413,7 +414,6 @@ void sp_selection_delete(SPDesktop *desktop) std::vector selected(selection->itemList()); selection->clear(); sp_selection_delete_impl(selected); - selected.clear(); desktop->currentLayer()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); /* a tool may have set up private information in it's selection context @@ -440,10 +440,6 @@ static void add_ids_recursive(std::vector &ids, SPObject *obj) } } } -/* -bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b){ - return sp_repr_compare_position(dynamic_cast(a),dynamic_cast(b)); -}*/ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) { @@ -476,8 +472,8 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) bool relink_clones = prefs->getBool("/options/relinkclonesonduplicate/value"); const bool fork_livepatheffects = prefs->getBool("/options/forklpeonduplicate/value", true); - for(std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ - Inkscape::XML::Node *old_repr = (*i); + for(std::vector::const_reverse_iterator i=reprs.rbegin();i!=reprs.rend();i++){ + Inkscape::XML::Node *old_repr = *i; Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); @@ -558,7 +554,7 @@ void sp_edit_clear_all(Inkscape::Selection *selection) g_return_if_fail(group != NULL); std::vector items = sp_item_group_item_list(group); - for(unsigned int i=0;i(items[i])->deleteObject(); } @@ -644,7 +640,6 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i } } - all_items.clear(); break; } case PREFS_SELECTION_LAYER_RECURSIVE: { @@ -653,17 +648,14 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i break; } default: { - std::vector x; - items = get_all_items(x, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude); + std::vector x; + items = get_all_items(x, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude); break; } } selection->setList(items); - if (!items.empty()) { - items.clear(); - } } void sp_edit_select_all(SPDesktop *desktop) @@ -694,8 +686,8 @@ static void sp_selection_group_impl(std::vector p, Inkscap gint topmost = (dynamic_cast(p.back()))->position(); Inkscape::XML::Node *topmost_parent = (dynamic_cast(p.back()))->parent(); - for(std::vector::const_iterator i=p.begin();i!=p.end();i++){ - Inkscape::XML::Node *current = (*i); + for(std::vector::const_iterator i = p.begin(); i != p.end(); i++){ + Inkscape::XML::Node *current = *i; if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -704,7 +696,7 @@ static void sp_selection_group_impl(std::vector p, Inkscap Inkscape::GC::release(spnew); topmost --; // only reduce count for those items deleted from topmost_parent } else { // move it to topmost_parent first - std::vector temp_clip; + std::vector temp_clip; // At this point, current may already have no item, due to its being a clone whose original is already moved away // So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform @@ -817,7 +809,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) // If any of the clones refer to the groups, unlink them and replace them with successors // in the items list. GSList *clones_to_unlink = NULL; - for (std::vector::const_iterator item = items.begin(); item!=items.end(); item++) { + for (std::vector::const_iterator item = items.begin(); item != items.end(); item++) { SPUse *use = dynamic_cast(static_cast(*item)); SPItem *original = use; @@ -838,13 +830,13 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) for (GSList *item = clones_to_unlink; item; item = item->next) { SPUse *use = static_cast(item->data); std::vector::iterator items_node = std::find(items.begin(),items.end(), item->data); - (*items_node) = use->unlink(); + *items_node = use->unlink(); } g_slist_free(clones_to_unlink); // do the actual work - for (std::vector::iterator item = items.begin(); item!=items.end(); item++) { - SPItem *obj = static_cast(*item); + for (std::vector::iterator item = items.begin(); item != items.end(); item++) { + SPItem *obj = *item; // ungroup only the groups marked earlier if (g_slist_find(groups, *item) != NULL) { @@ -852,7 +844,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) sp_item_group_ungroup(dynamic_cast(obj), children, false); // add the items resulting from ungrouping to the selection new_select.insert(new_select.end(),children.begin(),children.end()); - (*item) = NULL; // zero out the original pointer, which is no longer valid + *item = NULL; // zero out the original pointer, which is no longer valid } else { // if not a group, keep in the selection new_select.push_back(*item); @@ -860,8 +852,6 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) } selection->addList(new_select); - new_select.clear(); - items.clear(); DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_UNGROUP, _("Ungroup")); @@ -886,7 +876,6 @@ sp_degroup_list(std::vector &items) members.clear(); } } - items.clear(); if (has_groups) { // recurse if we unwrapped a group - it may have contained others out = sp_degroup_list(out); @@ -903,13 +892,13 @@ sp_item_list_common_parent_group(std::vector const items) if (items.empty()) { return NULL; } - SPObject *parent = SP_OBJECT(items.front())->parent; + SPObject *parent = SP_OBJECT(items[0])->parent; // Strictly speaking this CAN happen, if user selects from Inkscape::XML editor if (!dynamic_cast(parent)) { return NULL; } for (std::vector::const_iterator item=items.begin();item!=items.end();item++) { - if((*item)==items.front())continue; + if((*item)==items[0])continue; if (SP_OBJECT(*item)->parent != parent) { return NULL; } @@ -992,10 +981,7 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) } } } - } else { - rev.clear(); } - DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_RAISE, //TRANSLATORS: "Raise" means "to raise an object" in the undo history C_("Undo action", "Raise")); @@ -1078,8 +1064,6 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) } } } - } else { - rev.clear(); } DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_LOWER, @@ -1261,7 +1245,7 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop) } std::vector list=selection->itemList(); for ( std::vector::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) { - SPItem *item = reinterpret_cast(*itemlist); + SPItem *item = *itemlist; sp_selection_remove_livepatheffect_impl(item); @@ -1318,7 +1302,7 @@ void sp_selection_paste_size_separately(SPDesktop *desktop, bool apply_x, bool a void sp_selection_change_layer_maintain_clones(std::vector const &items,SPObject *where) { for (std::vector::const_iterator i = items.begin(); i != items.end(); i++) { - SPItem *item = dynamic_cast(SP_OBJECT(*i)); + SPItem *item = *i; if (item) { SPItem *oldparent = dynamic_cast(item->parent); SPItem *newparent = dynamic_cast(where); @@ -1346,7 +1330,7 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); if (next) { sp_selection_change_layer_maintain_clones(items,next); - std::vector temp_clip; + std::vector temp_clip; sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); sp_selection_delete_impl(items, false, false); next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers @@ -1358,8 +1342,6 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) no_more = true; } selection->setReprList(copied); - copied.clear(); - if (!temp_clip.empty()) temp_clip.clear(); if (next) dt->setCurrentLayer(next); if ( !suppressDone ) { DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_NEXT, @@ -1373,7 +1355,6 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers above.")); } - items.clear(); } void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) @@ -1392,7 +1373,7 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) SPObject *next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); if (next) { sp_selection_change_layer_maintain_clones(items,next); - std::vector temp_clip; + std::vector temp_clip; sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers @@ -1404,8 +1385,6 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) no_more = true; } selection->setReprList( copied); - copied.clear(); - if (!temp_clip.empty()) temp_clip.clear(); if (next) dt->setCurrentLayer(next); if ( !suppressDone ) { DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_PREV, @@ -1434,7 +1413,7 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) if (moveto) { sp_selection_change_layer_maintain_clones(items,moveto); - std::vector temp_clip; + std::vector temp_clip; sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); std::vector copied = sp_selection_paste_impl(dt->getDocument(), moveto, temp_clip); @@ -1483,7 +1462,7 @@ selection_contains_both_clone_and_original(Inkscape::Selection *selection) bool clone_with_original = false; std::vector items = selection->itemList(); for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { - SPItem *item = dynamic_cast(static_cast(*l)); + SPItem *item = *l; if (item) { clone_with_original |= selection_contains_original(item, selection); if (clone_with_original) @@ -1528,7 +1507,7 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, Geom::Affine cons } std::vector items = selection->itemList(); for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { - SPItem *item = dynamic_cast(static_cast(*l)); + SPItem *item = *l; if( dynamic_cast(item) ) { // An SVG element cannot have a transform. We could change 'x' and 'y' in response @@ -1800,7 +1779,7 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw) std::vector items = selection->itemList(); Geom::Rotate const rot_90(Geom::Point(0, ccw ? 1 : -1)); // pos. or neg. rotation, depending on the value of ccw for (std::vector::const_iterator l=items.begin();l!=items.end() ;l++) { - SPItem *item = dynamic_cast(static_cast(*l)); + SPItem *item = *l; if (item) { sp_item_rotate_rel(item, rot_90); } else { @@ -1863,7 +1842,7 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea Inkscape::Selection *selection = desktop->getSelection(); std::vector items = selection->itemList(); for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { - SPItem *sel = dynamic_cast(static_cast(*sel_iter)); + SPItem *sel = *sel_iter; std::vector matches = all_list; if (fill && stroke && style) { matches = sp_get_same_style(sel, matches); @@ -1911,7 +1890,7 @@ void sp_select_same_object_type(SPDesktop *desktop) std::vector items=selection->itemList(); for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { - SPItem *sel = dynamic_cast(static_cast(*sel_iter)); + SPItem *sel = *sel_iter; if (sel) { matches = sp_get_same_object_type(sel, matches); } else { @@ -1938,7 +1917,7 @@ std::vector sp_get_same_fill_or_stroke_color(SPItem *sel, std::vectorstyle->fill) : &(sel->style->stroke); for (std::vector::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) { - SPItem *iter = dynamic_cast(static_cast(*i)); + SPItem *iter = *i; if (iter) { SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke); match = false; @@ -2033,7 +2012,7 @@ std::vector sp_get_same_object_type(SPItem *sel, std::vector & std::vector matches; for (std::vector::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) { - SPItem *item = dynamic_cast(static_cast(*i)); + SPItem *item = *i; if (item && item_type_match(sel, item) && !item->cloned) { matches.push_back(item); } @@ -2091,7 +2070,6 @@ std::vector sp_get_same_style(SPItem *sel, std::vector &src, S if (sel_style_for_width) { match = (sel_style_for_width->stroke_width.computed == tmp_style.stroke_width.computed); } - objects.clear(); } } match_g = match_g && match; @@ -2579,7 +2557,7 @@ void sp_selection_clone(SPDesktop *desktop) std::vector newsel; - for(std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ + for(std::vector::const_reverse_iterator i=reprs.rbegin();i!=reprs.rend();i++){ Inkscape::XML::Node *sel_repr = *i; Inkscape::XML::Node *parent = sel_repr->parent(); @@ -2631,7 +2609,7 @@ sp_selection_relink(SPDesktop *desktop) bool relinked = false; std::vector items=selection->itemList(); for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = static_cast(*i); + SPItem *item = *i; if (dynamic_cast(item)) { item->getRepr()->setAttribute("xlink:href", newref); @@ -2669,7 +2647,7 @@ sp_selection_unlink(SPDesktop *desktop) bool unlinked = false; std::vector items=selection->itemList(); for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ - SPItem *item = static_cast(*i); + SPItem *item = *i; if (dynamic_cast(item)) { SPObject *tspan = sp_tref_convert_to_tspan(item); @@ -2922,7 +2900,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) //items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); // Why needed? // bottommost object, after sorting - SPObject *parent = SP_OBJECT(items.front())->parent; + SPObject *parent = SP_OBJECT(items[0])->parent; Geom::Affine parent_transform; { @@ -2976,7 +2954,7 @@ static void sp_selection_to_guides_recursive(SPItem *item, bool wholegroups) { if (group && !dynamic_cast(item) && !wholegroups) { std::vector items=sp_item_group_item_list(group); for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ - sp_selection_to_guides_recursive(static_cast(*i), wholegroups); + sp_selection_to_guides_recursive(*i, wholegroups); } } else { item->convert_to_guides(); @@ -3007,7 +2985,7 @@ void sp_selection_to_guides(SPDesktop *desktop) // Therefore: first convert all, then delete all. for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ - sp_selection_to_guides_recursive(static_cast(*i), wholegroups); + sp_selection_to_guides_recursive(*i, wholegroups); } if (deleteitems) { @@ -3060,7 +3038,7 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) std::vector items(selection->list()); // Keep track of parent, this is where will be inserted. - Inkscape::XML::Node *the_first_repr = reinterpret_cast( items.front() )->getRepr(); + Inkscape::XML::Node *the_first_repr = items[0]->getRepr(); Inkscape::XML::Node *the_parent_repr = the_first_repr->parent(); // Find out if we have a single group @@ -3068,7 +3046,7 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) SPGroup *the_group = NULL; Geom::Affine transform; if( items.size() == 1 ) { - SPObject *object = reinterpret_cast( items.front() ); + SPObject *object = items[0]; the_group = dynamic_cast(object); if ( the_group ) { single_group = true; @@ -3125,7 +3103,7 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) // Move selected items to new for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ - Inkscape::XML::Node *repr = SP_OBJECT(*i)->getRepr(); + Inkscape::XML::Node *repr = (*i)->getRepr(); repr->parent()->removeChild(repr); symbol_repr->addChild(repr,NULL); } @@ -3197,7 +3175,7 @@ void sp_selection_unsymbol(SPDesktop *desktop) // In converting a symbol back to a group we strip out the inserted group (or any other // group that only adds a transform to the symbol content). if( children.size() == 1 ) { - SPObject *object = reinterpret_cast( children.front() ); + SPObject *object = children[0]; if ( dynamic_cast( object ) ) { if( object->getAttribute("style") == NULL || object->getAttribute("class") == NULL ) { @@ -3209,7 +3187,7 @@ void sp_selection_unsymbol(SPDesktop *desktop) } for (std::vector::const_iterator i=children.begin();i!=children.end();i++){ - Inkscape::XML::Node *repr = SP_OBJECT(*i)->getRepr(); + Inkscape::XML::Node *repr = (*i)->getRepr(); repr->parent()->removeChild(repr); group->addChild(repr,NULL); } @@ -3274,7 +3252,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) sort(items.begin(),items.end(),sp_object_compare_position); // bottommost object, after sorting - SPObject *parent = SP_OBJECT(items.front())->parent; + SPObject *parent = SP_OBJECT(items[0])->parent; Geom::Affine parent_transform; @@ -3288,7 +3266,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) } // remember the position of the first item - gint pos = SP_OBJECT(items.front())->getRepr()->position(); + gint pos = SP_OBJECT(items[0])->getRepr()->position(); // create a list of duplicates std::vector repr_copies; @@ -3446,7 +3424,7 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring for (std::vector::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){ gchar const *dpi_string; - Inkscape::XML::Node * repr = (*i); + Inkscape::XML::Node *repr = *i; if (filename_search) { const gchar* tmp = repr->attribute("inkscape:export-filename"); @@ -3546,7 +3524,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) // Create the filename. gchar *const basename = g_strdup_printf("%s-%s-%u.png", document->getName(), - SP_OBJECT(items.front())->getRepr()->attribute("id"), + SP_OBJECT(items[0])->getRepr()->attribute("id"), current); // Imagemagick is known not to handle spaces in filenames, so we replace anything but letters, // digits, and a few other chars, with "_" @@ -3755,7 +3733,7 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) Inkscape::GC::release(spnew); topmost --; // only reduce count for those items deleted from topmost_parent } else { // move it to topmost_parent first - std::vector temp_clip; + std::vector temp_clip; // At this point, current may already have no item, due to its being a clone whose original is already moved away // So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform @@ -3896,7 +3874,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ } } else if (!topmost) { // topmost item is used as a mask, which is applied to other items in a selection - Inkscape::XML::Node *dup = SP_OBJECT(items.front())->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *dup = SP_OBJECT(items[0])->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); if (remove_original) { @@ -4060,7 +4038,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (remove_original) { // remember referenced mask/clippath, so orphaned masks can be moved back to document - SPItem *item = reinterpret_cast(*i); + SPItem *item = *i; Inkscape::URIReference *uri_ref = NULL; if (apply_clip_path) { diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index ce0b5d3da..8bcab664b 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -19,7 +19,6 @@ #include <2geom/forward.h> #include "sp-item.h" -#include "selection.h" class SPCSSAttr; class SPDesktop; diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index d86cfa700..441ce6ea6 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -47,7 +47,7 @@ char* collect_terms (const std::vector &items) bool first = true; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPItem *item = dynamic_cast(reinterpret_cast(*iter)); + SPItem *item = *iter; if (item) { const char *term = item->displayName(); if (term != NULL && g_slist_find (check, term) == NULL) { @@ -66,7 +66,7 @@ static int count_terms (const std::vector &items) GSList *check = NULL; int count=0; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPItem *item = dynamic_cast(reinterpret_cast(*iter)); + SPItem *item = *iter; if (item) { const char *term = item->displayName(); if (term != NULL && g_slist_find (check, term) == NULL) { @@ -83,7 +83,7 @@ static int count_filtered (const std::vector &items) { int count=0; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPItem *item = dynamic_cast(reinterpret_cast((*iter))); + SPItem *item = *iter; if (item) { count += item->isFiltered(); } @@ -127,7 +127,7 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select if (items.empty()) { // no items _context.set(Inkscape::NORMAL_MESSAGE, _when_nothing); } else { - SPItem *item = dynamic_cast(reinterpret_cast(items.front())); + SPItem *item = items[0]; g_assert(item != NULL); SPObject *layer = selection->layers()->layerForObject(item); SPObject *root = selection->layers()->currentRoot(); diff --git a/src/selection.cpp b/src/selection.cpp index fd3b6abae..19e78512b 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -130,7 +130,7 @@ void Selection::_invalidateCachedLists() { void Selection::_clear() { _invalidateCachedLists(); while (!_objs.empty()) { - SPObject *obj=reinterpret_cast(_objs.front()); + SPObject *obj=_objs.front(); _remove(obj); } } @@ -254,7 +254,7 @@ void Selection::addList(std::vector const &list) { _invalidateCachedLists(); for ( std::vector::const_iterator iter=list.begin();iter!=list.end();iter++ ) { - SPObject *obj = reinterpret_cast(*iter); + SPObject *obj = *iter; if (includes(obj)) continue; _add (obj); } @@ -297,7 +297,7 @@ std::vector const &Selection::itemList() { } for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { - SPObject *obj=reinterpret_cast(*iter); + SPObject *obj=*iter; if (SP_IS_ITEM(obj)) { _items.push_back(SP_ITEM(obj)); } @@ -342,7 +342,7 @@ std::list const Selection::box3DList(Persp3D *persp) { SPObject *Selection::single() { if ( _objs.size() == 1 ) { - return reinterpret_cast(_objs.front()); + return _objs.front(); } else { return NULL; } @@ -351,7 +351,7 @@ SPObject *Selection::single() { SPItem *Selection::singleItem() { std::vector const items=itemList(); if ( items.size()==1) { - return reinterpret_cast(items.front()); + return items[0]; } else { return NULL; } @@ -447,7 +447,7 @@ Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const boost::optional Selection::center() const { std::vector const items = const_cast(this)->itemList(); if (!items.empty()) { - SPItem *first = reinterpret_cast(items.back()); // from the first item in selection + SPItem *first = items.back(); // from the first item in selection if (first->isCenterSet()) { // only if set explicitly return first->getCenter(); } @@ -467,7 +467,7 @@ std::vector Selection::getSnapPoints(SnapPreferenc snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center std::vector p; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPItem *this_item = SP_ITEM(*iter); + SPItem *this_item = *iter; this_item->getSnappoints(p, &snapprefs_dummy); //Include the transformation origin for snapping @@ -482,7 +482,7 @@ std::vector Selection::getSnapPoints(SnapPreferenc void Selection::_removeObjectDescendants(SPObject *obj) { for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { - SPObject *sel_obj=reinterpret_cast(*iter); + SPObject *sel_obj= *iter; SPObject *parent = sel_obj->parent; while (parent) { if ( parent == obj ) { diff --git a/src/selection.h b/src/selection.h index 71be6dd6b..9eada3eed 100644 --- a/src/selection.h +++ b/src/selection.h @@ -40,14 +40,6 @@ class Node; } } -/*template -const GSList* std_list_to_GS_list(const std::list list) const -{ - gpointer l=NULL; - for(auto x:list){ - - } -}*/ namespace Inkscape { diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 0a428edf2..61d8a1ab1 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -434,8 +434,7 @@ void Inkscape::SelTrans::ungrab() for (int i = 0; i < 4; i++) sp_canvas_item_hide(_l[i]); } - - if (!_stamp_cache.empty()) { + if(!_stamp_cache.empty()){ _stamp_cache.clear(); } @@ -494,7 +493,7 @@ void Inkscape::SelTrans::ungrab() // we were dragging center; update reprs and commit undoable action std::vector items=_desktop->selection->itemList(); for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPItem *it = SP_ITEM(*iter); + SPItem *it = *iter; it->updateRepr(); } DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT, @@ -535,7 +534,7 @@ void Inkscape::SelTrans::stamp() } for(std::vector::const_iterator x=l.begin();x!=l.end();x++) { - SPItem *original_item = SP_ITEM(*x); + SPItem *original_item = *x; Inkscape::XML::Node *original_repr = original_item->getRepr(); // remember the position of the item @@ -713,7 +712,7 @@ void Inkscape::SelTrans::handleClick(SPKnot */*knot*/, guint state, SPSelTransHa // Unset the center position for all selected items std::vector items=_desktop->selection->itemList(); for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPItem *it = SP_ITEM(*iter); + SPItem *it = *iter; it->unsetCenter(); it->updateRepr(); _center_is_set = false; // center has changed diff --git a/src/snap.cpp b/src/snap.cpp index c711874d7..31cafafcd 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -1055,7 +1055,7 @@ void SnapManager::setupIgnoreSelection(SPDesktop const *desktop, Inkscape::Selection *sel = _desktop->selection; std::vector const items = sel->itemList(); for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { - _items_to_ignore.push_back(static_cast(*i)); + _items_to_ignore.push_back(*i); } } diff --git a/src/sp-conn-end.cpp b/src/sp-conn-end.cpp index d09699f41..1e478d1c9 100644 --- a/src/sp-conn-end.cpp +++ b/src/sp-conn-end.cpp @@ -52,7 +52,7 @@ static bool try_get_intersect_point_with_item_recursive(Geom::PathVector& conn_p double child_pos = 0.0; std::vector g = sp_item_group_item_list(group); for (std::vector::const_iterator i = g.begin();i!=g.end();i++) { - SPItem* child_item = SP_ITEM(*i); + SPItem* child_item = *i; try_get_intersect_point_with_item_recursive(conn_pv, child_item, item_transform * child_item->transform, child_pos); if (intersect_pos < child_pos) diff --git a/src/sp-defs.cpp b/src/sp-defs.cpp index 76843fd28..74d29a05c 100644 --- a/src/sp-defs.cpp +++ b/src/sp-defs.cpp @@ -48,7 +48,7 @@ void SPDefs::update(SPCtx *ctx, guint flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; std::vector l(this->childList(true)); for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ - SPObject *child = SP_OBJECT(*i); + SPObject *child = *i; if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->updateDisplay(ctx, flags); } diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 93a979287..5386a4373 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -246,7 +246,7 @@ void SPFilter::update(SPCtx *ctx, guint flags) { childflags &= SP_OBJECT_MODIFIED_CASCADE; std::vector l(this->childList(true, SPObject::ActionUpdate)); for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ - SPObject *child = SP_OBJECT (*i); + SPObject *child = *i; if( SP_IS_FILTER_PRIMITIVE( child ) ) { child->updateDisplay(ctx, childflags); } diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index d58676235..620c0b70f 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -173,7 +173,7 @@ void SPGroup::update(SPCtx *ctx, unsigned int flags) { childflags &= SP_OBJECT_MODIFIED_CASCADE; std::vector l=this->childList(true, SPObject::ActionUpdate); for(std::vector ::const_iterator i=l.begin();i!=l.end();i++){ - SPObject *child = SP_OBJECT (*i); + SPObject *child = *i; if (childflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { SPItem *item = dynamic_cast(child); @@ -217,7 +217,7 @@ void SPGroup::modified(guint flags) { std::vector l=this->childList(true); for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ - SPObject *child = SP_OBJECT (*i); + SPObject *child = *i; if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->emitModified(flags); @@ -289,9 +289,9 @@ Geom::OptRect SPGroup::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox Geom::OptRect bbox; // TODO CPPIFY: replace this const_cast later - std::vector l=const_cast(this)->childList(false, SPObject::ActionBBox); + std::vector l = const_cast(this)->childList(false, SPObject::ActionBBox); for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ - SPObject *o = SP_OBJECT (*i); + SPObject *o = *i; SPItem *item = dynamic_cast(o); if (item && !item->isHidden()) { Geom::Affine const ct(item->transform * transform); @@ -305,7 +305,7 @@ Geom::OptRect SPGroup::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox void SPGroup::print(SPPrintContext *ctx) { std::vector l=this->childList(false); for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ - SPObject *o = SP_OBJECT (*i); + SPObject *o = *i; SPItem *item = dynamic_cast(o); if (item) { item->invoke_print(ctx); @@ -359,7 +359,7 @@ Inkscape::DrawingItem *SPGroup::show (Inkscape::Drawing &drawing, unsigned int k void SPGroup::hide (unsigned int key) { std::vector l=this->childList(false, SPObject::ActionShow); for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ - SPObject *o = SP_OBJECT (*i); + SPObject *o = *i; SPItem *item = dynamic_cast(o); if (item) { @@ -799,7 +799,7 @@ void SPGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem * Inkscape::DrawingItem *ac = NULL; std::vector l=this->childList(false, SPObject::ActionShow); for(std::vector::const_iterator i=l.begin();i!=l.end();i++){ - SPObject *o = SP_OBJECT (*i); + SPObject *o = *i; SPItem * child = dynamic_cast(o); if (child) { ac = child->invoke_show (drawing, key, flags); diff --git a/src/sp-item-group.h b/src/sp-item-group.h index 2258c2133..fc0b6382f 100644 --- a/src/sp-item-group.h +++ b/src/sp-item-group.h @@ -15,7 +15,6 @@ #include #include "sp-lpe-item.h" -#include "selection.h"//SelContainer #define SP_GROUP(obj) (dynamic_cast((SPObject*)obj)) #define SP_IS_GROUP(obj) (dynamic_cast((SPObject*)obj) != NULL) diff --git a/src/sp-marker.cpp b/src/sp-marker.cpp index 5bb80bd39..9618c5484 100644 --- a/src/sp-marker.cpp +++ b/src/sp-marker.cpp @@ -453,7 +453,7 @@ const gchar *generate_marker(std::vector &reprs, Geom::Rec SPObject *mark_object = document->getObjectById(mark_id); for (std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ - Inkscape::XML::Node *node = (*i); + Inkscape::XML::Node *node = *i; SPItem *copy = SP_ITEM(mark_object->appendChildRepr(node)); Geom::Affine dup_transform; diff --git a/src/sp-object.h b/src/sp-object.h index 8651258bd..df773fea7 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -47,8 +47,6 @@ class SPObject; #define SP_OBJECT_WRITE_ALL (1 << 2) #define SP_OBJECT_WRITE_NO_CHILDREN (1 << 3) - - #include #include #include @@ -64,8 +62,6 @@ class SPCSSAttr; class SPStyle; typedef struct _GSList GSList; - - namespace Inkscape { namespace XML { class Node; diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index 33d66c5dc..b3aeec7bd 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -427,7 +427,7 @@ const gchar *pattern_tile(const std::vector &reprs, Geom:: SPObject *pat_object = document->getObjectById(pat_id); for (std::vector::const_iterator i=reprs.begin();i!=reprs.end();i++){ - Inkscape::XML::Node *node = (Inkscape::XML::Node *)(*i); + Inkscape::XML::Node *node = *i; SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node)); Geom::Affine dup_transform; diff --git a/src/sp-switch.cpp b/src/sp-switch.cpp index 2c9427df8..f252438a4 100644 --- a/src/sp-switch.cpp +++ b/src/sp-switch.cpp @@ -112,7 +112,7 @@ void SPSwitch::_reevaluate(bool /*add_to_drawing*/) { std::vector item_list = _childList(false, SPObject::ActionShow); for ( std::vector::const_reverse_iterator iter=item_list.rbegin();iter!=item_list.rend();iter++) { - SPObject *o = SP_OBJECT (*iter); + SPObject *o = *iter; if ( !SP_IS_ITEM (o) ) { continue; } @@ -147,7 +147,7 @@ void SPSwitch::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem std::vector l = this->_childList(false, SPObject::ActionShow); for ( std::vector::const_reverse_iterator iter=l.rbegin();iter!=l.rend();iter++) { - SPObject *o = SP_OBJECT (*iter); + SPObject *o = *iter; if (SP_IS_ITEM (o)) { SPItem * child = SP_ITEM(o); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 6e47dfff3..bc09802f0 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -60,11 +60,6 @@ using Inkscape::DocumentUndo; bool Ancetre(Inkscape::XML::Node *a, Inkscape::XML::Node *who); -//SHOULD DISAPPEAR -bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b){ - return sp_repr_compare_position(dynamic_cast(a),dynamic_cast(b)); -} - void sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb=SP_VERB_NONE, const Glib::ustring description=""); void sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset); void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updating); @@ -405,7 +400,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool // otherwise bail out for (std::vector::const_iterator l = il.begin(); l != il.end(); l++) { - SPItem *item = SP_ITEM(*l); + SPItem *item = *l; if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item) && !SP_IS_FLOWTEXT(item)) { boolop_display_error_message(desktop, _("One of the objects is not a path, cannot perform boolean operation.")); @@ -428,7 +423,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool SP_LPE_ITEM(*l)->removeAllPathEffects(true); } - SPCSSAttr *css = sp_repr_css_attr(reinterpret_cast(il.front())->getRepr(), "style"); + SPCSSAttr *css = sp_repr_css_attr(reinterpret_cast(il[0])->getRepr(), "style"); gchar const *val = sp_repr_css_property(css, "fill-rule", NULL); if (val && strcmp(val, "nonzero") == 0) { origWind[curOrig]= fill_nonZero; @@ -438,7 +433,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool origWind[curOrig]= fill_nonZero; } - originaux[curOrig] = Path_for_item((SPItem *) (*l), true, true); + originaux[curOrig] = Path_for_item(*l, true, true); if (originaux[curOrig] == NULL || originaux[curOrig]->descr_cmd.size() <= 1) { for (int i = curOrig; i >= 0; i--) delete originaux[i]; @@ -475,7 +470,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool curOrig = 1; for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ - if(*l==il.front())continue; + if(*l==il[0])continue; originaux[curOrig]->ConvertWithBackData(0.1); originaux[curOrig]->Fill(theShape, curOrig); @@ -685,7 +680,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool SPObject *source; if ( bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice ) { if (reverseOrderForOp) { - source = SP_OBJECT(il.front()); + source = SP_OBJECT(il[0]); } else { source = SP_OBJECT(il.back()); } @@ -1159,7 +1154,7 @@ sp_selected_path_outline(SPDesktop *desktop) bool did = false; std::vector il(selection->itemList()); for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ - SPItem *item = SP_ITEM(*l); + SPItem *item = *l; if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item)) continue; @@ -1771,7 +1766,7 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) bool did = false; std::vector il(selection->itemList()); for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ - SPItem *item = SP_ITEM(*l); + SPItem *item = *l; SPCurve *curve = NULL; if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item)) @@ -2143,7 +2138,7 @@ sp_selected_path_simplify_items(SPDesktop *desktop, desktop->setWaitingCursor(); for (std::vector::const_iterator l = items.begin(); l != items.end(); l++){ - SPItem *item = SP_ITEM(*l); + SPItem *item = *l; if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item))) continue; diff --git a/src/splivarot.h b/src/splivarot.h index 79b9b98a6..ba314399f 100644 --- a/src/splivarot.h +++ b/src/splivarot.h @@ -10,7 +10,6 @@ #include <2geom/forward.h> #include <2geom/path.h> #include "livarot/Path.h" -#include "sp-object.h"//kill it class SPCurve; class SPDesktop; @@ -19,7 +18,7 @@ class SPItem; namespace Inkscape { class Selection; } -bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b);//kill it with fire + // boolean operations // work on the current selection // selection has 2 contain exactly 2 items diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index 33192a330..eadab90dd 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -46,7 +46,7 @@ flowtext_in_selection(Inkscape::Selection *selection) std::vector items = selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_FLOWTEXT(*i)) - return ((SPItem *) *i); + return *i; } return NULL; } @@ -57,7 +57,7 @@ text_or_flowtext_in_selection(Inkscape::Selection *selection) std::vector items = selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) - return ((SPItem *) *i); + return *i; } return NULL; } @@ -68,7 +68,7 @@ shape_in_selection(Inkscape::Selection *selection) std::vector items = selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_SHAPE(*i)) - return ((SPItem *) *i); + return *i; } return NULL; } @@ -402,7 +402,7 @@ text_unflow () continue; } - SPItem *flowtext = SP_ITEM(*i); + SPItem *flowtext = *i; // we discard transform when unflowing, but we must preserve expansion which is visible as // font size multiplier @@ -482,7 +482,7 @@ flowtext_to_text() std::vector items(selection->itemList()); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = (SPItem *) *i; + SPItem *item = *i; if (!SP_IS_FLOWTEXT(item)) continue; diff --git a/src/text-editing.cpp b/src/text-editing.cpp index 88210dc0b..050e223eb 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -69,7 +69,7 @@ void te_update_layout_now_recursive(SPItem *item) if (SP_IS_GROUP(item)) { std::vector item_list = sp_item_group_item_list(SP_GROUP(item)); for(std::vector::const_iterator i=item_list.begin();i!=item_list.end();i++){ - SPItem* list_item = static_cast(*i); + SPItem* list_item = *i; te_update_layout_now_recursive(list_item); } } else if (SP_IS_TEXT(item)) diff --git a/src/trace/trace.cpp b/src/trace/trace.cpp index 4853f127c..91c230920 100644 --- a/src/trace/trace.cpp +++ b/src/trace/trace.cpp @@ -80,7 +80,7 @@ SPImage *Tracer::getSelectedSPImage() { continue; } - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; items.insert(items.begin(), item); } std::vector::iterator iter; diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 52bc24f5f..a38a52371 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -525,7 +525,7 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a if (separately) { std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (item) { Geom::OptRect obj_size = item->desktopVisualBounds(); if ( obj_size ) { @@ -581,7 +581,7 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) sp_selected_to_lpeitems(desktop); std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; _applyPathEffect(item, effectstack); } @@ -664,7 +664,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) // copy the defs used by all items std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (item) { _copyUsedDefs(item); } else { @@ -677,7 +677,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position); for(std::vector::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (item) { Inkscape::XML::Node *obj = item->getRepr(); Inkscape::XML::Node *obj_copy = _copyNode(obj, _doc, _root); @@ -706,7 +706,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) // copy style for Paste Style action if (!sorted_items.empty()) { - SPObject *object = static_cast(sorted_items.front()); + SPObject *object = static_cast(sorted_items[0]); SPItem *item = dynamic_cast(object); if (item) { SPCSSAttr *style = take_style_from_item(item); diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 34dbd150b..1ee72dcbc 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -151,7 +151,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it) { - SPItem* item=static_cast (*it); + SPItem* item= *it; desktop->getDocument()->ensureUpToDate(); if (!sel_as_group) b = (item)->desktopPreferredBounds(); @@ -264,8 +264,8 @@ private : std::vector< BBoxSort > sorted; for (std::vector::iterator it(selected.begin()); it != selected.end(); - ++it) - {SPItem *item=static_cast(*it); + ++it){ + SPItem *item = *it; Geom::OptRect bbox = !prefs_bbox ? (item)->desktopVisualBounds() : (item)->desktopGeometricBounds(); if (bbox) { sorted.push_back(BBoxSort(item, *bbox, _orientation, _kBegin, _kEnd)); @@ -570,19 +570,19 @@ private : sort(selected.begin(),selected.end(),sort_compare); } std::vector::iterator it(selected.begin()); - SPItem* item=static_cast(*it); - Geom::Point p1 = (item)->getCenter(); + SPItem* item = *it; + Geom::Point p1 = item->getCenter(); for (++it ;it != selected.end(); ++it) { - item=static_cast(*it); - Geom::Point p2 = (item)->getCenter(); + item = *it; + Geom::Point p2 = item->getCenter(); Geom::Point delta = p1 - p2; - sp_item_move_rel((item),Geom::Translate(delta[Geom::X],delta[Geom::Y] )); + sp_item_move_rel(item,Geom::Translate(delta[Geom::X],delta[Geom::Y] )); p1 = p2; } - Geom::Point p2 = static_cast(selected.front())->getCenter(); + Geom::Point p2 = selected.front()->getCenter(); Geom::Point delta = p1 - p2; - sp_item_move_rel(static_cast(selected.front()),Geom::Translate(delta[Geom::X],delta[Geom::Y] )); + sp_item_move_rel(selected.front(),Geom::Translate(delta[Geom::X],delta[Geom::Y] )); // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); @@ -675,7 +675,7 @@ private : it != selected.end(); ++it) { - SPItem* item=static_cast(*it); + SPItem* item = *it; desktop->getDocument()->ensureUpToDate(); Geom::OptRect item_box = !prefs_bbox ? (item)->desktopVisualBounds() : (item)->desktopGeometricBounds(); if (item_box) { @@ -761,7 +761,7 @@ private : it != selected.end(); ++it) { - SPItem* item=static_cast(*it); + SPItem* item = *it; if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT (item)) { Inkscape::Text::Layout const *layout = te_get_layout(item); boost::optional pt = layout->baselineAnchorPoint(); @@ -805,7 +805,7 @@ private : it != selected.end(); ++it) { - SPItem* item=static_cast(*it); + SPItem* item = *it; if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT (item)) { Inkscape::Text::Layout const *layout = te_get_layout(item); boost::optional pt = layout->baselineAnchorPoint(); diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 32eed088c..ca3971019 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -819,7 +819,7 @@ void Export::onAreaToggled () const gchar * id = "object"; const std::vector reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { - Inkscape::XML::Node * repr = (*i); + Inkscape::XML::Node * repr = *i; if (repr->attribute("id")) { id = repr->attribute("id"); break; @@ -1026,7 +1026,7 @@ void Export::onExport () std::vector itemlist=desktop->getSelection()->itemList(); for(std::vector::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;i++){ - SPItem *item = reinterpret_cast(*i); + SPItem *item = *i; prog_dlg->set_data("current", GINT_TO_POINTER(n)); prog_dlg->set_data("total", GINT_TO_POINTER(num)); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index a6312140d..45c8ce68a 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -690,7 +690,7 @@ private: void select_svg_element(){ Inkscape::Selection* sel = _desktop->getSelection(); if (sel->isEmpty()) return; - Inkscape::XML::Node* node = sel->reprList().front(); + Inkscape::XML::Node* node = sel->reprList()[0]; if (!node || !node->matchAttributeName("id")) return; std::ostringstream xlikhref; @@ -1547,7 +1547,7 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri std::vector itemlist=sel->itemList(); for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { - SPItem * item = SP_ITEM(*i); + SPItem * item = *i; SPStyle *style = item->style; g_assert(style != NULL); @@ -1655,7 +1655,7 @@ void FilterEffectsDialog::FilterModifier::remove_filter() if (!SP_IS_ITEM(*i)) { continue; } - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (!item->style) { continue; } diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index 283d79c0d..dde040036 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -857,7 +857,7 @@ void Find::onAction() Inkscape::Selection *selection = desktop->getSelection(); selection->clear(); selection->setList(n); - SPObject *obj = reinterpret_cast(n.front()); + SPObject *obj = reinterpret_cast(n[0]); SPItem *item = dynamic_cast(obj); g_assert(item != NULL); scroll_to_show_item(desktop, item); diff --git a/src/ui/dialog/find.h b/src/ui/dialog/find.h index 61f4463ae..4bcb900b6 100644 --- a/src/ui/dialog/find.h +++ b/src/ui/dialog/find.h @@ -16,7 +16,6 @@ # include #endif -#include "selection.h" #include "ui/widget/panel.h" #include "ui/widget/button.h" #include "ui/widget/entry.h" diff --git a/src/ui/dialog/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp index e9a0fc017..1be87d180 100644 --- a/src/ui/dialog/font-substitution.cpp +++ b/src/ui/dialog/font-substitution.cpp @@ -159,7 +159,7 @@ std::vector FontSubstitution::getFontReplacedItems(SPDocument* doc, Gli allList = get_all_items(x, doc->getRoot(), desktop, false, false, true, y); for(std::vector::const_iterator i = allList.begin();i!=allList.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; SPStyle *style = item->style; Glib::ustring family = ""; diff --git a/src/ui/dialog/font-substitution.h b/src/ui/dialog/font-substitution.h index cdb4e22b4..0818d778c 100644 --- a/src/ui/dialog/font-substitution.h +++ b/src/ui/dialog/font-substitution.h @@ -13,7 +13,8 @@ #define INKSCAPE_UI_FONT_SUBSTITUTION_H #include -#include "selection.h" + +class SPItem; class SPDocument; namespace Inkscape { diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp index fa469dc4b..7ca277ea2 100644 --- a/src/ui/dialog/glyphs.cpp +++ b/src/ui/dialog/glyphs.cpp @@ -581,7 +581,7 @@ void GlyphsPanel::insertText() std::vector itemlist=targetDesktop->selection->itemList(); for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { - textItem = SP_ITEM(*i); + textItem = *i; break; } } diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index 10498b0f9..8bd130c2e 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -172,7 +172,7 @@ void GridArrangeTab::arrange() const std::vector items = selection ? selection->itemList() : std::vector(); cnt=0; for(std::vector::const_iterator i = items.begin();i!=items.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; Geom::OptRect b = item->documentVisualBounds(); if (!b) { continue; diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index 6ad3d61ac..e9ee7802d 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -368,7 +368,7 @@ void IconPreviewPanel::refreshPreview() std::vector const items = sel->itemList(); for(std::vector::const_iterator i=items.begin();!target && i!=items.end();i++){ - SPItem* item = SP_ITEM( *i); + SPItem* item = *i; gchar const *id = item->getId(); if ( id ) { targetId = id; diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp index 6e09be2ba..781c6ef93 100644 --- a/src/ui/dialog/objects.cpp +++ b/src/ui/dialog/objects.cpp @@ -479,7 +479,7 @@ void ObjectsPanel::_objectsSelected( Selection *sel ) { SPItem *item = NULL; std::vector const items = sel->itemList(); for(std::vector::const_iterator i=items.begin(); i!=items.end();i++){ - item = reinterpret_cast(*i); + item = *i; if (setOpacity) { _setCompositingValues(item); diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index a68e73caf..af1386e27 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -308,7 +308,7 @@ void PolarArrangeTab::arrange() { if(arrangeOnEllipse) { - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if(arrangeOnFirstEllipse) { @@ -375,7 +375,7 @@ void PolarArrangeTab::arrange() int i = 0; for(std::vector::const_iterator it=tmp.begin();it!=tmp.end();it++) { - SPItem *item = SP_ITEM(*it); + SPItem *item = *it; // Ignore the reference ellipse if any if(item != referenceEllipse) diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index b677711ff..5fab9fcfc 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -355,7 +355,7 @@ void TagsPanel::_objectsSelected( Selection *sel ) { std::vector tmp=sel->list(); for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; _store->foreach(sigc::bind( sigc::mem_fun(*this, &TagsPanel::_checkForSelected), obj)); } _selectedConnection.unblock(); diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index 1c1cf5937..9c4790379 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -422,7 +422,7 @@ SPItem *TextEdit::getSelectedTextItem (void) for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) - return SP_ITEM (*i); + return *i; } return NULL; diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 0f81a7e58..459e6e937 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -655,7 +655,7 @@ void Transformation::updatePageTransform(Inkscape::Selection *selection) { if (selection && !selection->isEmpty()) { if (_check_replace_matrix.get_active()) { - Geom::Affine current (SP_ITEM(selection->itemList().front())->transform); // take from the first item in selection + Geom::Affine current (selection->itemList()[0]->transform); // take from the first item in selection Geom::Affine new_displayed = current; @@ -750,8 +750,8 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) it != selected.end(); ++it) { - SPItem* item=static_cast(*it); - Geom::OptRect bbox = (item)->desktopPreferredBounds(); + SPItem* item = *it; + Geom::OptRect bbox = item->desktopPreferredBounds(); if (bbox) { sorted.push_back(BBoxSort(item, *bbox, Geom::X, x > 0? 1. : 0., x > 0? 0. : 1.)); } @@ -775,8 +775,8 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) it != selected.end(); ++it) { - SPItem* item=static_cast(*it); - Geom::OptRect bbox = (item)->desktopPreferredBounds(); + SPItem* item = *it; + Geom::OptRect bbox = item->desktopPreferredBounds(); if (bbox) { sorted.push_back(BBoxSort(item, *bbox, Geom::Y, y > 0? 1. : 0., y > 0? 0. : 1.)); } @@ -818,7 +818,7 @@ void Transformation::applyPageScale(Inkscape::Selection *selection) if (prefs->getBool("/dialogs/transformation/applyseparately")) { std::vector tmp=selection->itemList(); for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; Geom::OptRect bbox_pref = item->desktopPreferredBounds(); Geom::OptRect bbox_geom = item->desktopGeometricBounds(); if (bbox_pref && bbox_geom) { @@ -882,7 +882,7 @@ void Transformation::applyPageRotate(Inkscape::Selection *selection) if (prefs->getBool("/dialogs/transformation/applyseparately")) { std::vector tmp=selection->itemList(); for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; sp_item_rotate_rel(item, Geom::Rotate (angle*M_PI/180.0)); } } else { @@ -902,7 +902,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) if (prefs->getBool("/dialogs/transformation/applyseparately")) { std::vector items=selection->itemList(); for(std::vector::const_iterator i = items.begin();i!=items.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (!_units_skew.isAbsolute()) { // percentage double skewX = _scalar_skew_horizontal.getValue("%"); @@ -1004,7 +1004,7 @@ void Transformation::applyPageTransform(Inkscape::Selection *selection) if (_check_replace_matrix.get_active()) { std::vector tmp=selection->itemList(); for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; item->set_item_transform(displayed); SP_OBJECT(item)->updateRepr(); } @@ -1155,7 +1155,7 @@ void Transformation::onReplaceMatrixToggled() double f = _scalar_transform_f.getValue(); Geom::Affine displayed (a, b, c, d, e, f); - Geom::Affine current = SP_ITEM(selection->itemList().front())->transform; // take from the first item in selection + Geom::Affine current = selection->itemList()[0]->transform; // take from the first item in selection Geom::Affine new_displayed; if (_check_replace_matrix.get_active()) { diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 193dff33c..760d19e89 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -2077,7 +2077,7 @@ void ContextMenu::ImageEdit(void) std::vector itemlist=_desktop->selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - Inkscape::XML::Node *ir = SP_ITEM(*i)->getRepr(); + Inkscape::XML::Node *ir = (*i)->getRepr(); const gchar *href = ir->attribute("xlink:href"); if (strncmp (href,"file:",5) == 0) { diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 9c6eead16..f48e572df 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -1318,7 +1318,7 @@ void cc_selection_set_avoid(bool const set_avoid) std::vector l = selection->itemList(); for(std::vector::const_iterator i=l.begin();i!=l.end();i++) { - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; char const *value = (set_avoid) ? "true" : NULL; diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index b61a108f0..adbbb2bd3 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -692,8 +692,8 @@ void EraserTool::set_to_accumulated() { if ( !toWorkOn.empty() ) { if ( eraserMode ) { - for (std::vector::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { - SPItem *item = SP_ITEM(*i); + for (std::vector::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); i++){ + SPItem *item = *i; if ( eraserMode ) { Geom::OptRect bbox = item->visualBounds(); @@ -712,7 +712,7 @@ void EraserTool::set_to_accumulated() { // If the item was not completely erased, track the new remainder. std::vector nowSel(selection->itemList()); for (std::vector::const_iterator i2 = nowSel.begin();i2!=nowSel.end();i2++) { - remainingItems.push_back(SP_ITEM(*i2)); + remainingItems.push_back(*i2); } } } else { @@ -722,11 +722,11 @@ void EraserTool::set_to_accumulated() { } } else { for (std::vector ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { - sp_object_ref( SP_ITEM(*i), 0 ); + sp_object_ref( *i, 0 ); } for (std::vector::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; item->deleteObject(true); sp_object_unref(item); workDone = true; diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 6f7b220ed..21ad18c26 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -506,7 +506,7 @@ bool GradientTool::root_handler(GdkEvent* event) { } else { std::vector items=selection->itemList(); for (std::vector::const_iterator i = items.begin();i!=items.end();i++) { - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR); Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; @@ -890,12 +890,6 @@ bool GradientTool::root_handler(GdkEvent* event) { return ret; } -int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *second) -{ - return sp_repr_compare_position(((SPItem*)first)->getRepr(), - ((SPItem*)second)->getRepr())<0; -} - static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*state*/, guint32 etime) { SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop; @@ -931,14 +925,14 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta //FIXME: see above sp_repr_css_change_recursive(SP_OBJECT(*i)->getRepr(), css, "style"); - sp_item_set_gradient(SP_ITEM(*i), vector, (SPGradientType) type, fill_or_stroke); + sp_item_set_gradient(*i, vector, (SPGradientType) type, fill_or_stroke); if (type == SP_GRADIENT_TYPE_LINEAR) { - sp_item_gradient_set_coords (SP_ITEM(*i), POINT_LG_BEGIN, 0, rc.origin, fill_or_stroke, true, false); - sp_item_gradient_set_coords (SP_ITEM(*i), POINT_LG_END, 0, pt, fill_or_stroke, true, false); + sp_item_gradient_set_coords (*i, POINT_LG_BEGIN, 0, rc.origin, fill_or_stroke, true, false); + sp_item_gradient_set_coords (*i, POINT_LG_END, 0, pt, fill_or_stroke, true, false); } else if (type == SP_GRADIENT_TYPE_RADIAL) { - sp_item_gradient_set_coords (SP_ITEM(*i), POINT_RG_CENTER, 0, rc.origin, fill_or_stroke, true, false); - sp_item_gradient_set_coords (SP_ITEM(*i), POINT_RG_R1, 0, pt, fill_or_stroke, true, false); + sp_item_gradient_set_coords (*i, POINT_RG_CENTER, 0, rc.origin, fill_or_stroke, true, false); + sp_item_gradient_set_coords (*i, POINT_RG_R1, 0, pt, fill_or_stroke, true, false); } SP_OBJECT(*i)->requestModified(SP_OBJECT_MODIFIED_FLAG); } @@ -949,7 +943,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta ec->_grdrag->local_change = true; // give the grab out-of-bounds values of xp/yp because we're already dragging // and therefore are already out of tolerance - ec->_grdrag->grabKnot (SP_ITEM(selection->itemList().front()), + ec->_grdrag->grabKnot (selection->itemList()[0], type == SP_GRADIENT_TYPE_LINEAR? POINT_LG_END : POINT_RG_R1, -1, // ignore number (though it is always 1) fill_or_stroke, 99999, 99999, etime); diff --git a/src/ui/tools/gradient-tool.h b/src/ui/tools/gradient-tool.h index 786aed372..6fe3bca9f 100644 --- a/src/ui/tools/gradient-tool.h +++ b/src/ui/tools/gradient-tool.h @@ -18,7 +18,6 @@ #include #include #include "ui/tools/tool-base.h" -class SPObject;//kill it #define SP_GRADIENT_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_GRADIENT_CONTEXT(obj) (dynamic_cast((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) @@ -26,12 +25,12 @@ class SPObject;//kill it namespace Inkscape { namespace UI { namespace Tools { -int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *second);//kill it class GradientTool : public ToolBase { public: GradientTool(); virtual ~GradientTool(); + Geom::Point origin; bool cursor_addnode; diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 2b44639c8..5295a16c0 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -444,7 +444,7 @@ bool MeasureTool::root_handler(GdkEvent* event) { std::vector items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points); std::vector intersection_times; for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { - SPItem *item = static_cast(*i); + SPItem *item = *i; if (SP_IS_SHAPE(item)) { calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index 0a34e4855..c8e032089 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -48,7 +48,6 @@ // Mesh specific #include "ui/tools/mesh-tool.h" -#include "ui/tools/gradient-tool.h"//not needed #include "sp-mesh-gradient.h" #include "display/sp-ctrlcurve.h" @@ -478,12 +477,12 @@ bool MeshTool::root_handler(GdkEvent* event) { if (over_line) { // We take the first item in selection, because with doubleclick, the first click // always resets selection to the single object under cursor - sp_mesh_context_split_near_point(this, SP_ITEM(selection->itemList().front()), this->mousepoint_doc, event->button.time); + sp_mesh_context_split_near_point(this, selection->itemList()[0], this->mousepoint_doc, event->button.time); } else { // Create a new gradient with default coordinates. std::vector items=selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; SPGradientType new_type = SP_GRADIENT_TYPE_MESH; Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; @@ -932,12 +931,6 @@ bool MeshTool::root_handler(GdkEvent* event) { return ret; } -/* -int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *second) -{ - return sp_repr_compare_position(((SPItem*)first)->getRepr(), - ((SPItem*)second)->getRepr())<0; -}*/ static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/, guint32 /*etime*/) { SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop; diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 25cbf76a4..fbc1a9e6c 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -481,7 +481,7 @@ bool SelectTool::root_handler(GdkEvent* event) { case GDK_2BUTTON_PRESS: if (event->button.button == 1) { if (!selection->isEmpty()) { - SPItem *clicked_item = static_cast(selection->itemList().front()); + SPItem *clicked_item = selection->itemList()[0]; if (dynamic_cast(clicked_item) && !dynamic_cast(clicked_item)) { // enter group if it's not a 3D box desktop->setCurrentLayer(clicked_item); diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index ac41f3a34..d92d326e0 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -553,13 +553,13 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point std::vector const items(selection->itemList()); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = dynamic_cast(static_cast(*i)); + SPItem *item = *i; g_assert(item != NULL); sp_object_ref(item); } for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = dynamic_cast(static_cast(*i)); + SPItem *item = *i; g_assert(item != NULL); if (is_transform_modes(tc->mode)) { @@ -574,7 +574,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point } for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = dynamic_cast(static_cast(*i)); + SPItem *item = *i; g_assert(item != NULL); sp_object_unref(item); } diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 6f7764506..8c5e4215e 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -1089,7 +1089,7 @@ sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point std::vector items=selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = dynamic_cast(static_cast(*i)); + SPItem *item = *i; if (is_color_mode (tc->mode)) { if (do_fill || do_stroke || do_opacity) { diff --git a/src/unclump.cpp b/src/unclump.cpp index 29608befa..81c958937 100644 --- a/src/unclump.cpp +++ b/src/unclump.cpp @@ -173,7 +173,7 @@ static double unclump_average (SPItem *item, std::list &others) int n = 0; double sum = 0; for (std::list::const_iterator i = others.begin(); i != others.end();i++) { - SPItem *other = SP_ITEM (*i); + SPItem *other = *i; if (other == item) continue; @@ -197,7 +197,7 @@ static SPItem *unclump_closest (SPItem *item, std::list &others) SPItem *closest = NULL; for (std::list::const_iterator i = others.begin(); i != others.end();i++) { - SPItem *other = SP_ITEM (*i); + SPItem *other = *i; if (other == item) continue; @@ -220,7 +220,7 @@ static SPItem *unclump_farest (SPItem *item, std::list &others) double max = -HUGE_VAL; SPItem *farest = NULL; for (std::list::const_iterator i = others.begin(); i != others.end();i++) { - SPItem *other = SP_ITEM (*i); + SPItem *other = *i; if (other == item) continue; @@ -260,7 +260,7 @@ unclump_remove_behind (SPItem *item, SPItem *closest, std::list &rest) std::vector out; for (std::list::const_reverse_iterator i = rest.rbegin(); i != rest.rend();i++) { - SPItem *other = SP_ITEM (*i); + SPItem *other = *i; if (other == item) continue; @@ -337,7 +337,7 @@ unclump (std::vector &items) wh_cache.clear(); for (std::vector::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x: - SPItem *item = SP_ITEM (*i); + SPItem *item = *i; std::list nei; diff --git a/src/unclump.h b/src/unclump.h index 407628f3a..461e99d0b 100644 --- a/src/unclump.h +++ b/src/unclump.h @@ -12,7 +12,6 @@ #define SEEN_DIALOGS_UNCLUMP_H typedef struct _GSList GSList; -#include "selection.h" void unclump(std::vector &items); diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index 770845f38..46f895c06 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -258,7 +258,7 @@ VanishingPoint::selectedBoxes(Inkscape::Selection *sel) { std::list sel_boxes; std::vector itemlist=sel->itemList(); for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { - SPItem *item = static_cast(*i); + SPItem *item = *i; SPBox3D *box = dynamic_cast(item); if (box && this->hasBox(box)) { sel_boxes.push_back(box); @@ -398,7 +398,7 @@ VPDragger::VPsOfSelectedBoxes() { Inkscape::Selection *sel = SP_ACTIVE_DESKTOP->getSelection(); std::vector itemlist=sel->itemList(); for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { - SPItem *item = static_cast(*i); + SPItem *item = *i; SPBox3D *box = dynamic_cast(item); if (box) { vp = this->findVPWithBox(box); @@ -581,7 +581,7 @@ VPDrag::updateDraggers () std::vector itemlist=this->selection->itemList(); for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { - SPItem *item = static_cast(*i); + SPItem *item = *i; SPBox3D *box = dynamic_cast(item); if (box) { VanishingPoint vp; @@ -614,7 +614,7 @@ VPDrag::updateLines () std::vector itemlist=this->selection->itemList(); for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { - SPItem *item = static_cast(*i); + SPItem *item = *i; SPBox3D *box = dynamic_cast(item); if (box) { this->drawLinesForFace (box, Proj::X); diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index cb24bb8aa..71418e238 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -99,7 +99,7 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v bool modmade = false; std::vector itemlist=desktop->getSelection()->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); @@ -165,7 +165,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) if ( ege_select_one_action_get_active(act) != 0 ) { std::vector itemlist=desktop->getSelection()->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("sodipodi:open", "true"); @@ -176,7 +176,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) } else { std::vector itemlist=desktop->getSelection()->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("sodipodi:open", NULL); @@ -266,7 +266,7 @@ static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GOb std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { n_selected++; repr = item->getRepr(); diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 49cf8e6fd..1c99f283d 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -99,7 +99,7 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl bool modmade = false; std::vector itemlist=desktop->getSelection()->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (Inkscape::UI::Tools::cc_item_is_connector(item)) { item->setAttribute( "inkscape:connector-type", @@ -146,7 +146,7 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) bool modmade = false; std::vector itemlist=desktop->getSelection()->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (Inkscape::UI::Tools::cc_item_is_connector(item)) { item->setAttribute( "inkscape:connector-curvature", diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index dbb84efba..7d5a89cf5 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -591,11 +591,11 @@ void FillNStroke::updateFromPaint() if ( gr && createSwatch ) { gr->setSwatch(); } - sp_item_set_gradient(SP_ITEM(*i), + sp_item_set_gradient(*i, gr, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); } else { - sp_item_set_gradient(SP_ITEM(*i), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); + sp_item_set_gradient(*i, vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); } } } else { @@ -608,7 +608,7 @@ void FillNStroke::updateFromPaint() sp_repr_css_change_recursive(reinterpret_cast(*i)->getRepr(), css, "style"); } - SPGradient *gr = sp_item_set_gradient(SP_ITEM(*i), vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); + SPGradient *gr = sp_item_set_gradient(*i, vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); psel->pushAttrsToGradient( gr ); } } diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index 5aa654a80..6743dd23a 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -118,7 +118,7 @@ void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient // If no drag or no dragger selected, act on selection std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - gr_apply_gradient_to_item(SP_ITEM(*i), gr, initialType, initialMode, initialMode); + gr_apply_gradient_to_item(*i, gr, initialType, initialMode, initialMode); } } @@ -220,7 +220,7 @@ void gr_get_dt_selected_gradient(Inkscape::Selection *selection, SPGradient *&gr std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i);// get the items gradient, not the getVector() version + SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; @@ -288,7 +288,7 @@ void gr_read_selection( Inkscape::Selection *selection, // If no selected dragger, read desktop selection std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; SPStyle *style = item->style; if (style && (style->fill.isPaintserver())) { diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index 682c61e77..49fc7b67c 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -89,7 +89,7 @@ void ms_read_selection( Inkscape::Selection *selection, std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; SPStyle *style = item->style; if (style && (style->fill.isPaintserver())) { @@ -216,7 +216,7 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMeshGradient std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i);// get the items gradient, not the getVector() version + SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 65078af01..2b07dd3b9 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -246,9 +246,9 @@ static void sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GO std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - if (SP_IS_RECT(reinterpret_cast(*i))) { + if (SP_IS_RECT(*i)) { n_selected++; - item = reinterpret_cast(*i); + item = *i; repr = item->getRepr(); } } diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 6f967e8ae..751a60f06 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -81,7 +81,7 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr bool modmade = false; std::vector itemlist=desktop->getSelection()->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_SPIRAL(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_svg_double( repr, namespaced_name, @@ -197,7 +197,7 @@ static void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_SPIRAL(item)) { n_selected++; repr = item->getRepr(); diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 1946dee6e..96005d7df 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -85,7 +85,7 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_int(repr,"sodipodi:sides", @@ -130,7 +130,7 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -187,7 +187,7 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("inkscape:flatsided", flat ? "true" : "false" ); @@ -226,7 +226,7 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_svg_double(repr, "inkscape:rounded", @@ -266,7 +266,7 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); sp_repr_set_svg_double(repr, "inkscape:randomized", @@ -369,7 +369,7 @@ sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_STAR(item)) { n_selected++; repr = item->getRepr(); diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 65390819b..c05ef93e7 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -477,7 +477,7 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, Inkscape::Selection *selection = spw->desktop->getSelection(); std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) { // can't set marker to rect, until it's converted to using continue; } @@ -902,7 +902,7 @@ StrokeStyle::updateLine() return; std::vector const objects = sel->itemList(); - SPObject * const object = SP_OBJECT(objects.front()); + SPObject * const object = SP_OBJECT(objects[0]); SPStyle * const style = object->style; /* Markers */ @@ -1155,6 +1155,7 @@ StrokeStyle::updateAllMarkers(std::vector const &objects) for(std::vector::const_iterator i=objects.begin();i!=objects.end();i++){ if (!SP_IS_TEXT (*i)) { all_texts = false; + break; } } @@ -1166,7 +1167,7 @@ StrokeStyle::updateAllMarkers(std::vector const &objects) // We show markers of the first object in the list only // FIXME: use the first in the list that has the marker of each type, if any - SPObject *object = SP_OBJECT(objects.front()); + SPObject *object = SP_OBJECT(objects[0]); for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) { // For all three marker types, diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 71915377e..6b0fb34e6 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -368,8 +368,8 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) Inkscape::Selection *selection = desktop->getSelection(); std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ - if (SP_IS_TEXT(SP_ITEM(*i))) { - SPItem *item = SP_ITEM(*i); + if (SP_IS_TEXT(*i)) { + SPItem *item = *i; unsigned writing_mode = item->style->writing_mode.value; // below, variable names suggest horizontal move, but we check the writing direction @@ -868,7 +868,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ // const gchar* id = reinterpret_cast(items->data)->getId(); // std::cout << " " << id << std::endl; - if( SP_IS_FLOWTEXT(SP_ITEM(*i))) { + if( SP_IS_FLOWTEXT(*i)) { isFlow = true; // std::cout << " Found flowed text" << std::endl; break; @@ -1160,7 +1160,7 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p std::vector x,y; std::vector allList = get_all_items(x, document->getRoot(), desktop, false, false, true, y); for(std::vector::const_reverse_iterator i=allList.rbegin();i!=allList.rend();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; SPStyle *style = item->style; if (style) { -- cgit v1.2.3 From 9bdc157f705ca61516e599cb416580283d21ec35 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 27 Feb 2015 04:21:48 +0100 Subject: more cast cleanup (bzr r13922.1.11) --- src/desktop-style.cpp | 29 ++++++++++---------- src/extension/implementation/implementation.cpp | 2 +- src/extension/internal/cairo-renderer.cpp | 3 +-- src/extension/internal/latex-text-renderer.cpp | 3 +-- src/live_effects/lpe-knot.cpp | 2 +- src/path-chemistry.cpp | 4 +-- src/selcue.cpp | 2 +- src/selection-chemistry.cpp | 36 ++++++++++++------------- src/selection.cpp | 2 +- src/seltrans.cpp | 2 +- src/sp-item-group.cpp | 4 +-- src/sp-lpe-item.cpp | 10 +++---- src/splivarot.cpp | 10 +++---- src/text-chemistry.cpp | 8 +++--- src/ui/clipboard.cpp | 2 +- src/ui/dialog/filter-effects-dialog.cpp | 2 +- src/ui/dialog/find.cpp | 18 ++++++------- src/ui/dialog/grid-arrange-tab.cpp | 2 +- src/ui/dialog/tags.cpp | 2 +- src/ui/dialog/text-edit.cpp | 2 +- src/ui/tools/gradient-tool.cpp | 2 +- src/ui/tools/mesh-tool.cpp | 6 ++--- src/ui/tools/node-tool.cpp | 2 +- src/ui/widget/style-subject.cpp | 4 +-- src/widgets/fill-style.cpp | 8 +++--- src/widgets/rect-toolbar.cpp | 2 +- src/widgets/stroke-style.cpp | 4 +-- src/widgets/text-toolbar.cpp | 2 +- 28 files changed, 86 insertions(+), 89 deletions(-) (limited to 'src') diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 82f66dcdf..afdc3064a 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -197,7 +197,7 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write std::vector const itemlist = desktop->selection->itemList(); for (std::vector::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) { /* last used styles for 3D box faces are stored separately */ - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; Box3DSide *side = dynamic_cast(obj); if (side) { const char * descr = box3d_side_axes_string(side); @@ -448,7 +448,6 @@ stroke_average_width (const std::vector &objects) bool notstroked = true; int n_notstroked = 0; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); SPItem *item = *i; if (!item) { continue; @@ -515,7 +514,7 @@ objects_query_fillstroke (const std::vector &objects, SPStyle *style_re bool same_color = true; for (std::vector::const_iterator i = objects.begin(); i!= objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!obj) { continue; } @@ -699,7 +698,7 @@ objects_query_opacity (const std::vector &objects, SPStyle *style_res) for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!obj) { continue; } @@ -755,7 +754,7 @@ objects_query_strokewidth (const std::vector &objects, SPStyle *style_r int n_stroked = 0; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!obj) { continue; } @@ -829,7 +828,7 @@ objects_query_miterlimit (const std::vector &objects, SPStyle *style_re bool same_ml = true; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!dynamic_cast(obj)) { continue; } @@ -888,7 +887,7 @@ objects_query_strokecap (const std::vector &objects, SPStyle *style_res int n_stroked = 0; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!dynamic_cast(obj)) { continue; } @@ -942,7 +941,7 @@ objects_query_strokejoin (const std::vector &objects, SPStyle *style_re int n_stroked = 0; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!dynamic_cast(obj)) { continue; } @@ -1005,7 +1004,7 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r int no_size = 0; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!isTextualItem(obj)) { continue; @@ -1124,7 +1123,7 @@ objects_query_fontstyle (const std::vector &objects, SPStyle *style_res int texts = 0; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!isTextualItem(obj)) { continue; @@ -1193,7 +1192,7 @@ objects_query_baselines (const std::vector &objects, SPStyle *style_res int texts = 0; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!isTextualItem(obj)) { continue; @@ -1281,7 +1280,7 @@ objects_query_fontfamily (const std::vector &objects, SPStyle *style_re style_res->font_family.set = FALSE; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; if (!isTextualItem(obj)) { @@ -1337,7 +1336,7 @@ objects_query_fontspecification (const std::vector &objects, SPStyle *s style_res->font_specification.set = FALSE; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; // std::cout << " " << reinterpret_cast(i->data)->getId() << std::endl; if (!isTextualItem(obj)) { @@ -1395,7 +1394,7 @@ objects_query_blend (const std::vector &objects, SPStyle *style_res) guint items = 0; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!obj) { continue; } @@ -1485,7 +1484,7 @@ objects_query_blur (const std::vector &objects, SPStyle *style_res) guint items = 0; for (std::vector::const_iterator i = objects.begin(); i != objects.end(); i++) { - SPObject *obj = reinterpret_cast(*i); + SPObject *obj = *i; if (!obj) { continue; } diff --git a/src/extension/implementation/implementation.cpp b/src/extension/implementation/implementation.cpp index 11c494b18..717ca3310 100644 --- a/src/extension/implementation/implementation.cpp +++ b/src/extension/implementation/implementation.cpp @@ -51,7 +51,7 @@ Gtk::Widget *Implementation::prefs_effect(Inkscape::Extension::Effect *module, I std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node const* first_select = NULL; if (!selected.empty()) { - const SPItem * item = selected.front(); + const SPItem * item = selected[0]; first_select = item->getRepr(); } diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index b30c8892e..a2cea014b 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -296,8 +296,7 @@ static void sp_group_render(SPGroup *group, CairoRenderContext *ctx) std::vector l(group->childList(false)); for(std::vector::const_iterator x = l.begin(); x!= l.end(); x++){ - SPObject *o = reinterpret_cast(*x); - SPItem *item = dynamic_cast(o); + SPItem *item = static_cast(*x); if (item) { renderer->renderItem(ctx, item); } diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index 831a8d030..ab863f8b1 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -230,8 +230,7 @@ void LaTeXTextRenderer::sp_group_render(SPGroup *group) { std::vector l = (group->childList(false)); for(std::vector::const_iterator x = l.begin(); x != l.end(); x++){ - SPObject *o = *x; - SPItem *item = dynamic_cast(o); + SPItem *item = static_cast(*x); if (item) { renderItem(item); } diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 7a1d391a3..6ec4b969b 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -507,7 +507,7 @@ collectPathsAndWidths (SPLPEItem const *lpeitem, std::vector &paths, if (SP_IS_GROUP(lpeitem)) { std::vector item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); for ( std::vector::const_iterator iter = item_list.begin(); iter != item_list.end(); iter++) { - SPObject *subitem = static_cast(*iter); + SPObject *subitem = *iter; if (SP_IS_LPE_ITEM(subitem)) { collectPathsAndWidths(SP_LPE_ITEM(subitem), paths, stroke_widths); } diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 53ad96596..b128535bc 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -48,7 +48,7 @@ using Inkscape::DocumentUndo; inline bool less_than_items(SPItem const *first, SPItem const *second) { return sp_repr_compare_position(first->getRepr(), - second->getRepr())>0; + second->getRepr())<0; } void @@ -615,7 +615,7 @@ sp_selected_path_reverse(SPDesktop *desktop) for (std::vector::const_iterator i = items.begin(); i != items.end(); i++){ - SPPath *path = dynamic_cast(static_cast(*i)); + SPPath *path = dynamic_cast(*i); if (!path) { continue; } diff --git a/src/selcue.cpp b/src/selcue.cpp index 76eae3fa8..c73219b7d 100644 --- a/src/selcue.cpp +++ b/src/selcue.cpp @@ -203,7 +203,7 @@ void Inkscape::SelCue::_newTextBaselines() std::vector ll = _selection->itemList(); for (std::vector::const_iterator l=ll.begin();l!=ll.end();l++) { - SPItem *item = static_cast(*l); + SPItem *item = *l; SPCanvasItem* baseline_point = NULL; if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { // visualize baseline diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index d6f8b8a37..0100e1040 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -555,7 +555,7 @@ void sp_edit_clear_all(Inkscape::Selection *selection) std::vector items = sp_item_group_item_list(group); for(unsigned int i = 0; i < items.size(); i++){ - reinterpret_cast(items[i])->deleteObject(); + items[i]->deleteObject(); } DocumentUndo::done(doc, SP_VERB_EDIT_CLEAR_ALL, @@ -627,7 +627,7 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i std::vector all_items = sp_item_group_item_list(dynamic_cast(dt->currentLayer())); for (std::vector::const_reverse_iterator i=all_items.rbegin();i!=all_items.rend();i++) { - SPItem *item = dynamic_cast(static_cast(*i)); + SPItem *item = *i; if (item && (!onlysensitive || !item->isLocked())) { if (!onlyvisible || !dt->itemIsHidden(item)) { @@ -683,8 +683,8 @@ static void sp_selection_group_impl(std::vector p, Inkscap sort(p.begin(),p.end(),sp_repr_compare_position); // Remember the position and parent of the topmost object. - gint topmost = (dynamic_cast(p.back()))->position(); - Inkscape::XML::Node *topmost_parent = (dynamic_cast(p.back()))->parent(); + gint topmost = p.back()->position(); + Inkscape::XML::Node *topmost_parent = p.back()->parent(); for(std::vector::const_iterator i = p.begin(); i != p.end(); i++){ Inkscape::XML::Node *current = *i; @@ -791,7 +791,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) std::vector new_select; GSList *groups = NULL; for (std::vector::const_iterator item = old_select.begin(); item!=old_select.end(); item++) { - SPItem *obj = static_cast(*item); + SPItem *obj = *item; if (dynamic_cast(obj)) { groups = g_slist_prepend(groups, obj); } @@ -810,7 +810,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) // in the items list. GSList *clones_to_unlink = NULL; for (std::vector::const_iterator item = items.begin(); item != items.end(); item++) { - SPUse *use = dynamic_cast(static_cast(*item)); + SPUse *use = dynamic_cast(*item); SPItem *original = use; while (dynamic_cast(original)) { @@ -864,7 +864,7 @@ sp_degroup_list(std::vector &items) std::vector out; bool has_groups = false; for (std::vector::const_iterator item=items.begin();item!=items.end();item++) { - SPGroup *group = dynamic_cast(static_cast(*item)); + SPGroup *group = dynamic_cast(*item); if (!group) { out.push_back(*item); } else { @@ -915,7 +915,7 @@ enclose_items(std::vector const &items) Geom::OptRect r; for (std::vector::const_iterator i = items.begin();i!=items.end();i++) { - r.unionWith(static_cast(*i)->desktopVisualBounds()); + r.unionWith((*i)->desktopVisualBounds()); } return r; } @@ -963,7 +963,7 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) // Iterate over all objects in the selection (starting from top). if (selected) { for (std::vector::const_iterator item=rev.begin();item!=rev.end();item++) { - SPObject *child = reinterpret_cast(*item); + SPObject *child = *item; // for each selected object, find the next sibling for (SPObject *newref = child->next; newref; newref = newref->next) { // if the sibling is an item AND overlaps our selection, @@ -1042,7 +1042,7 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) // Iterate over all objects in the selection (starting from top). if (selected) { for (std::vector::const_reverse_iterator item=rev.rbegin();item!=rev.rend();item++) { - SPObject *child = reinterpret_cast(*item); + SPObject *child = *item; // for each selected object, find the prev sibling for (SPObject *newref = prev_sibling(child); newref; newref = prev_sibling(newref)) { // if the sibling is an item AND overlaps our selection, @@ -2053,7 +2053,7 @@ std::vector sp_get_same_style(SPItem *sel, std::vector &src, S } bool match_g; for (std::vector::const_iterator i=src.begin();i!=src.end();i++) { - SPItem *iter = dynamic_cast(static_cast(*i)); + SPItem *iter = *i; if (iter) { match_g=true; SPStyle *iter_style = iter->style; @@ -2356,7 +2356,7 @@ SPItem *next_item_from_list(SPDesktop *desktop, std::vector const items { SPObject *current=root; for(std::vector::const_iterator i = items.begin();i!=items.end();i++) { - SPItem *item = dynamic_cast(static_cast(*i)); + SPItem *item = *i; if ( root->isAncestorOf(item) && ( !only_in_viewport || desktop->isWithinViewport(item) ) ) { @@ -2925,7 +2925,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) // Delete objects so that their clones don't get alerted; // the objects will be restored inside the marker element. for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPObject *item = reinterpret_cast(*i); + SPObject *item = *i; item->deleteObject(false); } } @@ -3280,7 +3280,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) if (apply) { // delete objects so that their clones don't get alerted; this object will be restored shortly for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPObject *item = reinterpret_cast(*i); + SPObject *item = *i; item->deleteObject(false); } } @@ -3354,7 +3354,7 @@ void sp_selection_untile(SPDesktop *desktop) std::vector items(selection->itemList()); for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ - SPItem *item = static_cast(*i); + SPItem *item = *i; SPStyle *style = item->style; @@ -3864,7 +3864,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); - SPObject *item = reinterpret_cast(*i); + SPObject *item = *i; if (remove_original) { items_to_delete = g_slist_prepend(items_to_delete, item); } @@ -3878,7 +3878,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ mask_items = g_slist_prepend(mask_items, dup); if (remove_original) { - SPObject *item = reinterpret_cast(items.front()); + SPObject *item = items.front(); items_to_delete = g_slist_prepend(items_to_delete, item); } @@ -4055,7 +4055,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { SP_OBJECT(*i)->getRepr()->setAttribute(attributeName, "none"); - SPGroup *group = dynamic_cast(static_cast(*i)); + SPGroup *group = dynamic_cast(*i); if (ungroup_masked && group) { // if we had previously enclosed masked object in group, // add it to list so we can ungroup it later diff --git a/src/selection.cpp b/src/selection.cpp index 19e78512b..7e8190237 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -309,7 +309,7 @@ std::vector const &Selection::reprList() { if (!_reprs.empty()) { return _reprs; } std::vector list = itemList(); for ( std::vector::const_iterator iter=list.begin();iter!=list.end();iter++ ) { - SPObject *obj=reinterpret_cast(*iter); + SPObject *obj = *iter; _reprs.push_back(obj->getRepr()); } return _reprs; diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 61d8a1ab1..bfb8d53f1 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -271,7 +271,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s std::vector items=_desktop->selection->itemList(); for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPItem *it = reinterpret_cast(sp_object_ref(SP_ITEM(*iter), NULL)); + SPItem *it = static_cast(sp_object_ref(*iter, NULL)); _items.push_back(it); _items_const.push_back(it); _items_affines.push_back(it->i2dt_affine()); diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 620c0b70f..64ad9ff43 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -818,7 +818,7 @@ void SPGroup::update_patheffect(bool write) { std::vector const item_list = sp_item_group_item_list(this); for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { - SPObject *subitem = static_cast(*iter); + SPObject *subitem = *iter; SPLPEItem *lpeItem = dynamic_cast(subitem); if (lpeItem) { @@ -846,7 +846,7 @@ sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) std::vector const item_list = sp_item_group_item_list(group); for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { - SPObject *subitem = static_cast(*iter); + SPObject *subitem = *iter; SPGroup *subGroup = dynamic_cast(subitem); if (subGroup) { diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index 1f4704e22..6228f3692 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -355,7 +355,7 @@ sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem) if (SP_IS_GROUP(lpeitem)) { std::vector item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { - SPObject *subitem = static_cast(*iter); + SPObject *subitem = *iter; if (SP_IS_LPE_ITEM(subitem)) { sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(subitem)); } @@ -389,7 +389,7 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem) } std::vector item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { - SPObject *subitem = static_cast(*iter); + SPObject *subitem = *iter; if (SP_IS_LPE_ITEM(subitem)) { sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(subitem)); } @@ -682,7 +682,7 @@ SPLPEItem::apply_to_clippath(SPItem *item) if(SP_IS_GROUP(item)){ std::vector item_list = sp_item_group_item_list(SP_GROUP(item)); for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { - SPObject *subitem = static_cast(*iter); + SPObject *subitem = *iter; apply_to_clippath(SP_ITEM(subitem)); } } @@ -734,7 +734,7 @@ SPLPEItem::apply_to_mask(SPItem *item) if(SP_IS_GROUP(item)){ std::vector item_list = sp_item_group_item_list(SP_GROUP(item)); for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { - SPObject *subitem = static_cast(*iter); + SPObject *subitem = *iter; apply_to_mask(SP_ITEM(subitem)); } } @@ -748,7 +748,7 @@ SPLPEItem::apply_to_clip_or_mask_group(SPItem *group, SPItem *item) } std::vector item_list = sp_item_group_item_list(SP_GROUP(group)); for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { - SPObject *subitem = static_cast(*iter); + SPObject *subitem = *iter; if (SP_IS_GROUP(subitem)) { apply_to_clip_or_mask_group(SP_ITEM(subitem), item); } else if (SP_IS_SHAPE(subitem)) { diff --git a/src/splivarot.cpp b/src/splivarot.cpp index bc09802f0..c668199c0 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -667,7 +667,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool { // only one command, presumably a moveto: it isn't a path for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ - SP_OBJECT(*l)->deleteObject(); + (*l)->deleteObject(); } DocumentUndo::done(doc, SP_VERB_NONE, description); selection->clear(); @@ -680,9 +680,9 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool SPObject *source; if ( bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice ) { if (reverseOrderForOp) { - source = SP_OBJECT(il[0]); + source = il[0]; } else { - source = SP_OBJECT(il.back()); + source = il.back(); } } else { // find out the bottom object @@ -719,10 +719,10 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool // if this is the bottommost object, if (!strcmp(reinterpret_cast(*l)->getRepr()->attribute("id"), id)) { // delete it so that its clones don't get alerted; this object will be restored shortly, with the same id - SP_OBJECT(*l)->deleteObject(false); + (*l)->deleteObject(false); } else { // delete the object for real, so that its clones can take appropriate action - SP_OBJECT(*l)->deleteObject(); + (*l)->deleteObject(); } } diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index eadab90dd..5d57ac020 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -198,7 +198,7 @@ text_remove_from_path() bool did = false; std::vector items(selection->itemList()); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPObject *obj = SP_OBJECT(*i); + SPObject *obj = *i; if (SP_IS_TEXT_TEXTPATH(obj)) { SPObject *tp = obj->firstChild(); @@ -262,7 +262,7 @@ text_remove_all_kerns() std::vector items = selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPObject *obj = SP_OBJECT(*i); + SPObject *obj = *i; if (!SP_IS_TEXT(obj) && !SP_IS_TSPAN(obj) && !SP_IS_FLOWTEXT(obj)) { continue; @@ -322,7 +322,7 @@ text_flow_into_shape() /* Add clones */ std::vector items = selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_SHAPE(item)){ Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); clone->setAttribute("x", "0"); @@ -398,7 +398,7 @@ text_unflow () std::vector items = selection->itemList(); for(std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ - if (!SP_IS_FLOWTEXT(SP_OBJECT(*i))) { + if (!SP_IS_FLOWTEXT(*i)) { continue; } diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index a38a52371..3fe935e7d 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -706,7 +706,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) // copy style for Paste Style action if (!sorted_items.empty()) { - SPObject *object = static_cast(sorted_items[0]); + SPObject *object = sorted_items[0]; SPItem *item = dynamic_cast(object); if (item) { SPCSSAttr *style = take_style_from_item(item); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 45c8ce68a..cb2771503 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1467,7 +1467,7 @@ void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel) std::set used; std::vector itemlist=sel->itemList(); for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { - SPObject *obj = SP_OBJECT (*i); + SPObject *obj = *i; SPStyle *style = obj->style; if (!style || !SP_IS_ITEM(obj)) { continue; diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index dde040036..173acca93 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -562,7 +562,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b if (check_searchin_text.get_active()) { for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { - SPObject *obj = SP_OBJECT (*i); + SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_text_match(item, text, exact, casematch)) { @@ -585,7 +585,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b if (ids) { for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { - SPObject *obj = SP_OBJECT (*i); + SPObject *obj = *i; SPItem *item = dynamic_cast(obj); if (item_id_match(item, text, exact, casematch)) { if (out.end()==find(out.begin(),out.end(), *i)) { @@ -601,7 +601,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b if (style) { for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { - SPObject *obj = SP_OBJECT (*i); + SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_style_match(item, text, exact, casematch)) { @@ -618,7 +618,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b if (attrname) { for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { - SPObject *obj = SP_OBJECT (*i); + SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_attr_match(item, text, exact, casematch)) { @@ -635,7 +635,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b if (attrvalue) { for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { - SPObject *obj = SP_OBJECT (*i); + SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_attrvalue_match(item, text, exact, casematch)) { @@ -652,7 +652,7 @@ std::vector Find::filter_fields (std::vector &l, bool exact, b if (font) { for(std::vector::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { - SPObject *obj = SP_OBJECT (*i); + SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_font_match(item, text, exact, casematch)) { @@ -719,7 +719,7 @@ std::vector Find::filter_types (std::vector &l) { std::vector n; for(std::vector::const_reverse_iterator i=l.rbegin(); l.rend() != i; i++) { - SPObject *obj = SP_OBJECT (*i); + SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item_type_match(item)) { @@ -763,7 +763,7 @@ std::vector &Find::all_selection_items (Inkscape::Selection *s, std::ve { std::vector itemlist=s->itemList(); for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { - SPObject *obj = SP_OBJECT (*i); + SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); if (item && !item->cloned && !desktop->isLayer(item)) { @@ -857,7 +857,7 @@ void Find::onAction() Inkscape::Selection *selection = desktop->getSelection(); selection->clear(); selection->setList(n); - SPObject *obj = reinterpret_cast(n[0]); + SPObject *obj = n[0]; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); scroll_to_show_item(desktop, item); diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index 8bd130c2e..4465d73a9 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -210,7 +210,7 @@ void GridArrangeTab::arrange() cnt=0; const std::vector sizes(sorted); for (std::vector::const_iterator i = sizes.begin();i!=sizes.end();i++) { - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; Geom::OptRect b = item->documentVisualBounds(); if (b) { width = b->dimensions()[Geom::X]; diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index 5fab9fcfc..ed71c826f 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -652,7 +652,7 @@ bool TagsPanel::_handleButtonEvent(GdkEventButton* event) bool wasadded = false; std::vector items=_desktop->selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPObject *newobj = reinterpret_cast(*i); + SPObject *newobj = *i; bool addchild = true; for ( SPObject *child = obj->children; child != NULL; child = child->next) { if (SP_IS_TAG_USE(child) && SP_TAG_USE(child)->ref->getObject() == newobj) { diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index 9c4790379..815aa12ef 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -549,7 +549,7 @@ void TextEdit::onApply() if (SP_IS_TEXT (*i)) { // backwards compatibility: - reinterpret_cast(*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); + (*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); ++items; } diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 21ad18c26..a9e109b5c 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -934,7 +934,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta sp_item_gradient_set_coords (*i, POINT_RG_CENTER, 0, rc.origin, fill_or_stroke, true, false); sp_item_gradient_set_coords (*i, POINT_RG_R1, 0, pt, fill_or_stroke, true, false); } - SP_OBJECT(*i)->requestModified(SP_OBJECT_MODIFIED_FLAG); + (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG); } if (ec->_grdrag) { ec->_grdrag->updateDraggers(); diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index c8e032089..2c817694e 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -965,13 +965,13 @@ static void sp_mesh_drag(MeshTool &rc, Geom::Point const /*pt*/, guint /*state*/ for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above - sp_repr_css_change_recursive(SP_OBJECT(*i)->getRepr(), css, "style"); + sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); - sp_item_set_gradient(SP_ITEM(*i), vector, (SPGradientType) type, fill_or_stroke); + sp_item_set_gradient(*i, vector, (SPGradientType) type, fill_or_stroke); // We don't need to do anything. Mesh is already sized appropriately. - SP_OBJECT(*i)->requestModified(SP_OBJECT_MODIFIED_FLAG); + (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG); } // if (ec->_grdrag) { // ec->_grdrag->updateDraggers(); diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 6ddb379cc..374386686 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -422,7 +422,7 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) { std::vector items=sel->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPObject *obj = static_cast(*i); + SPObject *obj = *i; if (SP_IS_ITEM(obj)) { gather_items(this, NULL, static_cast(obj), SHAPE_ROLE_NORMAL, shapes); diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp index 1ded546dd..95b89bf5f 100644 --- a/src/ui/widget/style-subject.cpp +++ b/src/ui/widget/style-subject.cpp @@ -114,7 +114,7 @@ void StyleSubject::CurrentLayer::_setLayer(SPObject *layer) { _layer_release.disconnect(); _layer_modified.disconnect(); if (_element) { - sp_object_unref(static_cast(_element), NULL); + sp_object_unref(_element, NULL); } _element = layer; if (layer) { @@ -126,7 +126,7 @@ void StyleSubject::CurrentLayer::_setLayer(SPObject *layer) { } SPObject *StyleSubject::CurrentLayer::_getLayer() const { - return static_cast(_element); + return _element; } SPObject *StyleSubject::CurrentLayer::_getLayerSList() const { diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 7d5a89cf5..1d258bbb0 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -579,7 +579,7 @@ void FillNStroke::updateFromPaint() for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above if (kind == FILL) { - sp_repr_css_change_recursive(reinterpret_cast(*i)->getRepr(), css, "style"); + sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); } if (!vector) { @@ -605,7 +605,7 @@ void FillNStroke::updateFromPaint() for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ //FIXME: see above if (kind == FILL) { - sp_repr_css_change_recursive(reinterpret_cast(*i)->getRepr(), css, "style"); + sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); } SPGradient *gr = sp_item_set_gradient(*i, vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE); @@ -649,11 +649,11 @@ void FillNStroke::updateFromPaint() // objects who already have the same root pattern but through a different href // chain. FIXME: move this to a sp_item_set_pattern for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - Inkscape::XML::Node *selrepr = reinterpret_cast(*i)->getRepr(); + Inkscape::XML::Node *selrepr = (*i)->getRepr(); if ( (kind == STROKE) && !selrepr) { continue; } - SPObject *selobj = reinterpret_cast(*i); + SPObject *selobj = *i; SPStyle *style = selobj->style; if (style && ((kind == FILL) ? style->fill : style->stroke).isPaintserver()) { diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 2b07dd3b9..37ffd7553 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -112,7 +112,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * if (gtk_adjustment_get_value(adj) != 0) { (SP_RECT(*i)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, desktop->getNamedView()->svg_units)); } else { - SP_OBJECT(*i)->getRepr()->setAttribute(value_name, NULL); + (*i)->getRepr()->setAttribute(value_name, NULL); } modmade = true; } diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index c05ef93e7..481fa0609 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -983,7 +983,7 @@ StrokeStyle::scaleLine() if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { width = Inkscape::Util::Quantity::convert(width_typed, unit, "px"); } else { // percentage - gdouble old_w = SP_OBJECT(*i)->style->stroke_width.computed; + gdouble old_w = (*i)->style->stroke_width.computed; width = old_w * width_typed / 100; } @@ -1167,7 +1167,7 @@ StrokeStyle::updateAllMarkers(std::vector const &objects) // We show markers of the first object in the list only // FIXME: use the first in the list that has the marker of each type, if any - SPObject *object = SP_OBJECT(objects[0]); + SPObject *object = objects[0]; for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) { // For all three marker types, diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 6b0fb34e6..2160cad2e 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -522,7 +522,7 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ if (SP_IS_TEXT (*i)) { - SP_OBJECT(*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); + (*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); modmade = true; } } -- cgit v1.2.3 From 746649e82ce4b1ea144dabdee26d4abab510cce8 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sun, 26 Apr 2015 14:23:26 +0200 Subject: fix (bzr r13922.1.14) --- src/widgets/rect-toolbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 29a10a534..96ba699dc 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -110,7 +110,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ if (SP_IS_RECT(*i)) { if (gtk_adjustment_get_value(adj) != 0) { - (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); + (SP_RECT(*i)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); } else { (*i)->getRepr()->setAttribute(value_name, NULL); } -- cgit v1.2.3 From 60bdd590969d1c32c392a8fed15f4ceac4a678d2 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Mon, 27 Apr 2015 01:12:03 +0200 Subject: Just reread the entire diff against trunk. Given the diff size, i must have forgotten things, but hopefully, there are only very few changes of semantics: ->childList is now in the intuitive order (childList()[0] is now firstChild) -> sp_selection_paste_impl is now in the opposite order (change is local to selection-chemistry.cpp, and simplify a few things) -> selection.setReprList now takes the list in the opposite order. It was always the case (the list was always reversed before handing to it) -> a few comparison functions now work "the c++ way": the C way was to return -1 if ab, now they return (bool)(agetSelection(); selection->setReprList(pasted_objects); diff --git a/src/main.cpp b/src/main.cpp index 66452906b..d1ebdc3bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1641,7 +1641,9 @@ static int sp_do_export_png(SPDocument *doc) g_print("Background RRGGBBAA: %08x\n", bgcolor); g_print("Area %g:%g:%g:%g exported to %lu x %lu pixels (%g dpi)\n", area[Geom::X][0], area[Geom::Y][0], area[Geom::X][1], area[Geom::Y][1], width, height, dpi); - + + reverse(items.begin(),items.end()); + if ((width >= 1) && (height >= 1) && (width <= PNG_UINT_31_MAX) && (height <= PNG_UINT_31_MAX)) { if( sp_export_png_file(doc, path.c_str(), area, width, height, dpi, dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : std::vector()) == 1 ) { diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index b128535bc..bb313ef1a 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -269,7 +269,7 @@ sp_selected_path_break_apart(SPDesktop *desktop) if (l == list) repr->setAttribute("id", id); - reprs.insert(reprs.begin(),repr); + reprs.push_back(repr); Inkscape::GC::release(repr); } diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 0100e1040..c1d4f58e4 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -337,10 +337,7 @@ static void sp_selection_copy_impl(std::vector const &items, std::vecto g_assert_not_reached(); } } - std::vector tmp(clip); - for(int i=0;i copied = sp_selection_paste_impl(dt->getDocument(), moveto, temp_clip); selection->setReprList(copied); - copied.clear(); if (!temp_clip.empty()) temp_clip.clear(); if (moveto) dt->setCurrentLayer(moveto); if ( !suppressDone ) { @@ -2051,7 +2047,7 @@ std::vector sp_get_same_style(SPItem *sel, std::vector &src, S sel_style_for_width = new SPStyle(SP_ACTIVE_DOCUMENT); objects_query_strokewidth (objects, sel_style_for_width); } - bool match_g; + bool match_g; for (std::vector::const_iterator i=src.begin();i!=src.end();i++) { SPItem *iter = *i; if (iter) { @@ -3186,7 +3182,7 @@ void sp_selection_unsymbol(SPDesktop *desktop) } } - for (std::vector::const_iterator i=children.begin();i!=children.end();i++){ + for (std::vector::const_reverse_iterator i=children.rbegin();i!=children.rend();i++){ Inkscape::XML::Node *repr = (*i)->getRepr(); repr->parent()->removeChild(repr); group->addChild(repr,NULL); diff --git a/src/selection.cpp b/src/selection.cpp index 7e8190237..d9266b599 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -42,9 +42,9 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : - _objs(std::list()), - _objs_vector(std::vector()), - _objs_set(std::set()), + _objs(std::list()), + _objs_vector(std::vector()), + _objs_set(std::set()), _reprs(std::vector()), _items(std::vector()), _layers(layers), @@ -281,10 +281,10 @@ void Selection::clear() { } std::vector const &Selection::list() { - if(!_objs_vector.empty()) + if(!_objs_vector.empty()) return _objs_vector; - for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { _objs_vector.push_back(*iter); } return _objs_vector; @@ -349,7 +349,7 @@ SPObject *Selection::single() { } SPItem *Selection::singleItem() { - std::vector const items=itemList(); + std::vector const items=itemList(); if ( items.size()==1) { return items[0]; } else { @@ -366,7 +366,7 @@ SPItem *Selection::largestItem(Selection::CompareSize compare) { } SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); gdouble max = sml ? 1e18 : 0; SPItem *ist = NULL; @@ -399,7 +399,7 @@ Geom::OptRect Selection::bounds(SPItem::BBoxType type) const Geom::OptRect Selection::geometricBounds() const { - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); Geom::OptRect bbox; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { @@ -410,7 +410,7 @@ Geom::OptRect Selection::geometricBounds() const Geom::OptRect Selection::visualBounds() const { - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); Geom::OptRect bbox; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { @@ -445,7 +445,7 @@ Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const // If we have a selection of multiple items, then the center of the first item // will be returned; this is also the case in SelTrans::centerRequest() boost::optional Selection::center() const { - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); if (!items.empty()) { SPItem *first = items.back(); // from the first item in selection if (first->isCenterSet()) { // only if set explicitly @@ -461,7 +461,7 @@ boost::optional Selection::center() const { } std::vector Selection::getSnapPoints(SnapPreferences const *snapprefs) const { - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->itemList(); SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center @@ -514,8 +514,8 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { } uint Selection::numberOfLayers() { - std::vector const items = const_cast(this)->itemList(); - std::set layers; + std::vector const items = const_cast(this)->itemList(); + std::set layers; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPObject *layer = _layers->layerForObject(SP_OBJECT(*iter)); layers.insert(layer); @@ -524,8 +524,8 @@ uint Selection::numberOfLayers() { } guint Selection::numberOfParents() { - std::vector const items = const_cast(this)->itemList(); - std::set parents; + std::vector const items = const_cast(this)->itemList(); + std::set parents; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { SPObject *parent = SP_OBJECT(*iter)->parent; parents.insert(parent); diff --git a/src/sp-object.h b/src/sp-object.h index df773fea7..f5d47be05 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -52,7 +52,6 @@ class SPObject; #include #include #include -#include #include #include "version.h" diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index 5d57ac020..9fc862ad2 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -396,7 +396,7 @@ text_unflow () GSList *old_objs = NULL; std::vector items = selection->itemList(); - for(std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (!SP_IS_FLOWTEXT(*i)) { continue; @@ -452,6 +452,7 @@ text_unflow () } selection->clear(); + reverse(new_objs.begin(),new_objs.end()); selection->setList(new_objs); for (GSList *i = old_objs; i; i = i->next) { SP_OBJECT(i->data)->deleteObject (true); diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index b348bdcad..f84a2ffd6 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -2113,8 +2113,7 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *) } desktop->getDocument()->ensureUpToDate(); - std::vector tu2(to_unclump); - for(int i=0;igetDocument(), SP_VERB_DIALOG_CLONETILER, diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index 173acca93..a8ac42a1b 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -762,7 +762,7 @@ std::vector &Find::all_items (SPObject *r, std::vector &l, boo std::vector &Find::all_selection_items (Inkscape::Selection *s, std::vector &l, SPObject *ancestor, bool hidden, bool locked) { std::vector itemlist=s->itemList(); - for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + for(std::vector::const_reverse_iterator i=itemlist.rbegin(); itemlist.rend() != i; i++) { SPObject *obj = *i; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 76c748ae0..76b52f9be 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -378,7 +378,7 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P std::vector to_select; SPDocument *doc = item->document; sp_item_list_to_curves (items, selected, to_select); - SPObject* newObj = doc->getObjectByRepr(to_select.back()); + SPObject* newObj = doc->getObjectByRepr(to_select[0]); item = dynamic_cast(newObj); g_assert(item != NULL); selection->add(item); -- cgit v1.2.3 From f20da2a7a6e65bcf3a907c3ee5cb5fd69a71c867 Mon Sep 17 00:00:00 2001 From: Mark Harmer Date: Mon, 27 Apr 2015 12:01:19 -0400 Subject: Mainloop fix for possible data loss if closing before save has completed. Fixed bugs: - https://launchpad.net/bugs/967416 (bzr r14060) --- src/extension/implementation/script.cpp | 5 ++++- src/extension/implementation/script.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index bbc567f75..52c360fcd 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -1027,7 +1027,10 @@ int Script::execute (const std::list &in_command, return 0; } - _main_loop = Glib::MainLoop::create(false); + // Create a new MainContext for the loop so that the original context sources are not run here, + // this enforces that only the file_listeners should be read in this new MainLoop + Glib::RefPtr _main_context = Glib::MainContext::create(); + _main_loop = Glib::MainLoop::create(_main_context, false); file_listener fileerr; fileout.init(stdout_pipe, _main_loop); diff --git a/src/extension/implementation/script.h b/src/extension/implementation/script.h index 6a7d0c3b8..4cf33c989 100644 --- a/src/extension/implementation/script.h +++ b/src/extension/implementation/script.h @@ -90,7 +90,7 @@ private: void init (int fd, Glib::RefPtr main) { _channel = Glib::IOChannel::create_from_fd(fd); _channel->set_encoding(); - _conn = Glib::signal_io().connect(sigc::mem_fun(*this, &file_listener::read), _channel, Glib::IO_IN | Glib::IO_HUP | Glib::IO_ERR); + _conn = main->get_context()->signal_io().connect(sigc::mem_fun(*this, &file_listener::read), _channel, Glib::IO_IN | Glib::IO_HUP | Glib::IO_ERR); _main_loop = main; return; -- cgit v1.2.3 From e40a878a5843b71f06b1d0fa5cb0681abc5787e6 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Mon, 27 Apr 2015 20:14:55 +0200 Subject: Enable snapping of cusp nodes by default (bzr r14061) --- src/sp-namedview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 3154c9e7b..12c2cdf8e 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -517,7 +517,7 @@ void SPNamedView::set(unsigned int key, const gchar* value) { this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_INKSCAPE_SNAP_NODE_CUSP: - this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP, value ? sp_str_to_bool(value) : FALSE); + this->snap_manager.snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP, value ? sp_str_to_bool(value) : TRUE); this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_INKSCAPE_SNAP_BBOX_EDGE: -- cgit v1.2.3 From ac063302cd13238523a4f62744282944761c2a49 Mon Sep 17 00:00:00 2001 From: mathog <> Date: Mon, 27 Apr 2015 11:49:22 -0700 Subject: patch for bugs 1447850 and 1447382 (bzr r14062) --- src/extension/internal/emf-inout.cpp | 50 +- src/extension/internal/emf-inout.h | 2 + src/extension/internal/emf-print.cpp | 12 +- src/extension/internal/wmf-inout.cpp | 64 +- src/extension/internal/wmf-print.cpp | 6 +- src/libuemf/Makefile_insert | 2 + src/libuemf/README | 100 +- src/libuemf/uemf.c | 273 +++--- src/libuemf/uemf.h | 180 +++- src/libuemf/uemf_endian.c | 1673 ++++++++++++++++++++++------------ src/libuemf/uemf_endian.h | 7 +- src/libuemf/uemf_print.c | 652 ++++++++----- src/libuemf/uemf_print.h | 14 +- src/libuemf/upmf.c | 1282 ++++++++++++++++++-------- src/libuemf/upmf.h | 146 +-- src/libuemf/upmf_print.c | 818 +++++++++++------ src/libuemf/upmf_print.h | 137 +-- src/libuemf/uwmf.c | 100 +- src/libuemf/uwmf.h | 5 +- src/libuemf/uwmf_print.c | 14 +- src/libuemf/uwmf_print.h | 2 +- 21 files changed, 3706 insertions(+), 1833 deletions(-) (limited to 'src') diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index 31e69706f..e88cf3d42 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -480,7 +480,7 @@ uint32_t Emf::add_image(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t cbBits, uint uint32_t width, height, colortype, numCt, invert; // if needed these values will be set in get_DIB_params if(cbBits && cbBmi && (iUsage == U_DIB_RGB_COLORS)){ // next call returns pointers and values, but allocates no memory - dibparams = get_DIB_params(pEmr, offBits, offBmi, &px, (const U_RGBQUAD **) &ct, + dibparams = get_DIB_params((const char *)pEmr, offBits, offBmi, &px, (const U_RGBQUAD **) &ct, &numCt, &width, &height, &colortype, &invert); if(dibparams ==U_BI_RGB){ // U_EMRCREATEMONOBRUSH uses text/bk colors instead of what is in the color map. @@ -1307,7 +1307,7 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index) d->dc[d->level].stroke_set = true; } else if(pEmr->elp.elpBrushStyle == U_BS_DIBPATTERN || pEmr->elp.elpBrushStyle == U_BS_DIBPATTERNPT){ - d->dc[d->level].stroke_idx = add_image(d, pEmr, pEmr->cbBits, pEmr->cbBmi, *(uint32_t *) &(pEmr->elp.elpColor), pEmr->offBits, pEmr->offBmi); + d->dc[d->level].stroke_idx = add_image(d, (void *)pEmr, pEmr->cbBits, pEmr->cbBmi, *(uint32_t *) &(pEmr->elp.elpColor), pEmr->offBits, pEmr->offBmi); d->dc[d->level].stroke_mode = DRAW_IMAGE; d->dc[d->level].stroke_set = true; } @@ -1530,7 +1530,7 @@ void Emf::common_image_extraction(PEMF_CALLBACK_DATA d, void *pEmr, uint32_t width, height, colortype, numCt, invert; // if needed these values will be set in get_DIB_params if(cbBits && cbBmi && (iUsage == U_DIB_RGB_COLORS)){ // next call returns pointers and values, but allocates no memory - dibparams = get_DIB_params(pEmr, offBits, offBmi, &px, (const U_RGBQUAD **) &ct, + dibparams = get_DIB_params((const char *)pEmr, offBits, offBmi, &px, (const U_RGBQUAD **) &ct, &numCt, &width, &height, &colortype, &invert); if(dibparams ==U_BI_RGB){ if(sw == 0 || sh == 0){ @@ -1611,6 +1611,10 @@ int Emf::myEnhMetaFileProc(char *contents, unsigned int length, PEMF_CALLBACK_DA uint32_t off=0; uint32_t emr_mask; int OK =1; + int file_status=1; + uint32_t nSize; + uint32_t iType; + const char *blimit = contents + length; PU_ENHMETARECORD lpEMFR; TCHUNK_SPECS tsp; uint32_t tbkMode = U_TRANSPARENT; // holds proposed change to bkMode, if text is involved saving these to the DC must wait until the text is written @@ -1641,19 +1645,32 @@ int Emf::myEnhMetaFileProc(char *contents, unsigned int length, PEMF_CALLBACK_DA while(OK){ if(off>=length)return(0); //normally should exit from while after EMREOF sets OK to false. + // check record sizes and types thoroughly + int badrec = 0; + if (!U_emf_record_sizeok(contents + off, blimit, &nSize, &iType, 1) || + !U_emf_record_safe(contents + off)){ + badrec = 1; + } + else { + emr_mask = emr_properties(iType); + if (emr_mask == U_EMR_INVALID) { badrec = 1; } + } + if (badrec) { + file_status = 0; + break; + } + lpEMFR = (PU_ENHMETARECORD)(contents + off); + // Uncomment the following to track down toxic records -// std::cout << "record type: " << lpEMFR->iType << " name " << U_emr_names(lpEMFR->iType) << " length: " << lpEMFR->nSize << " offset: " << off <nSize; +// std::cout << "record type: " << iType << " name " << U_emr_names(iType) << " length: " << nSize << " offset: " << off <iType); - if(emr_mask == U_EMR_INVALID){ throw "Inkscape fatal memory allocation error - cannot continue"; } - /* Uncomment the following to track down text problems */ //std::cout << "tri->dirty:"<< d->tri->dirty << " emr_mask: " << std::hex << emr_mask << std::dec << std::endl; @@ -1753,7 +1770,7 @@ std::cout << "BEFORE DRAW" } // std::cout << "AFTER DRAW logic d->mask: " << std::hex << d->mask << " emr_mask: " << emr_mask << std::dec << std::endl; - switch (lpEMFR->iType) + switch (iType) { case U_EMR_HEADER: { @@ -3471,7 +3488,7 @@ std::cout << "BEFORE DRAW" // 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; + return(file_status); } void Emf::free_emf_strings(EMF_STRINGS name){ @@ -3486,12 +3503,14 @@ void Emf::free_emf_strings(EMF_STRINGS name){ SPDocument * Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) { - EMF_CALLBACK_DATA d; - if (uri == NULL) { return NULL; } + EMF_CALLBACK_DATA d; + + d.n_obj = 0; //these might not be set otherwise if the input file is corrupt + d.emf_obj = 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. @@ -3518,14 +3537,17 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP, FT_KERNING_UNSCALED); - (void) myEnhMetaFileProc(contents,length, &d); + int good = myEnhMetaFileProc(contents,length, &d); free(contents); if (d.pDesc){ free( d.pDesc ); } // 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 = NULL; + if (good) { + doc = SPDocument::createNewDocFromMem(d.outsvg.c_str(), strlen(d.outsvg.c_str()), TRUE); + } free_emf_strings(d.hatches); free_emf_strings(d.images); diff --git a/src/extension/internal/emf-inout.h b/src/extension/internal/emf-inout.h index c64299093..dd1d8f9c4 100644 --- a/src/extension/internal/emf-inout.h +++ b/src/extension/internal/emf-inout.h @@ -13,6 +13,8 @@ #define SEEN_EXTENSION_INTERNAL_EMF_H #include +#include +#include // for U_emf_record_sizeok() #include "extension/internal/metafile-inout.h" // picks up PNG #include "extension/implementation/implementation.h" #include "style.h" diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index 67a9242bc..ed3ae158a 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -60,6 +60,7 @@ #include "splivarot.h" // pieces for union on shapes #include "2geom/svg-path-parser.h" // to get from SVG text to Geom::Path #include "display/canvas-bpath.h" // for SPWindRule +#include "display/cairo-utils.h" // for Inkscape::Pixbuf::PF_CAIRO #include "emf-print.h" @@ -70,7 +71,6 @@ namespace Internal { #define PXPERMETER 2835 - /* globals */ static double PX2WORLD; static bool FixPPTCharPos, FixPPTDashLine, FixPPTGrad2Polys, FixPPTLinGrad, FixPPTPatternAsHatch, FixImageRot; @@ -481,9 +481,8 @@ int PrintEmf::create_brush(SPStyle const *style, PU_COLORREF fcolor) rgba_px = (char *) pixbuf->pixels(); // Do NOT free this!!! colortype = U_BCBM_COLOR32; (void) RGBA_to_DIB(&px, &cbPx, &ct, &numCt, rgba_px, width, height, width * 4, colortype, 0, 1); - // Not sure why the next swap is needed because the preceding does it, and the code is identical - // to that in stretchdibits_set, which does not need this. - swapRBinRGBA(px, width * height); + // pixbuf can be either PF_CAIRO or PF_GDK, and these have R and B bytes swapped + if (pixbuf->pixelFormat() == Inkscape::Pixbuf::PF_CAIRO) { swapRBinRGBA(px, width * height); } Bmih = bitmapinfoheader_set(width, height, 1, colortype, U_BI_RGB, 0, PXPERMETER, PXPERMETER, numCt, 0); Bmi = bitmapinfo_set(Bmih, ct); rec = createdibpatternbrushpt_set(&brush, eht, U_DIB_RGB_COLORS, Bmi, cbPx, px); @@ -584,9 +583,8 @@ int PrintEmf::create_pen(SPStyle const *style, const Geom::Affine &transform) rgba_px = (char *) pixbuf->pixels(); // Do NOT free this!!! colortype = U_BCBM_COLOR32; (void) RGBA_to_DIB(&px, &cbPx, &ct, &numCt, rgba_px, width, height, width * 4, colortype, 0, 1); - // Not sure why the next swap is needed because the preceding does it, and the code is identical - // to that in stretchdibits_set, which does not need this. - swapRBinRGBA(px, width * height); + // pixbuf can be either PF_CAIRO or PF_GDK, and these have R and B bytes swapped + if (pixbuf->pixelFormat() == Inkscape::Pixbuf::PF_CAIRO) { swapRBinRGBA(px, width * height); } Bmih = bitmapinfoheader_set(width, height, 1, colortype, U_BI_RGB, 0, PXPERMETER, PXPERMETER, numCt, 0); Bmi = bitmapinfo_set(Bmih, ct); } else { // pattern diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index 503a93418..30a028eec 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -1497,6 +1497,7 @@ int Wmf::myMetaFileProc(const char *contents, unsigned int length, PWMF_CALLBACK uint32_t off=0; uint32_t wmr_mask; int OK =1; + int file_status=1; TCHUNK_SPECS tsp; uint8_t iType; int nSize; // size of the current record, in bytes, or an error value if <=0 @@ -1562,7 +1563,9 @@ int Wmf::myMetaFileProc(const char *contents, unsigned int length, PWMF_CALLBACK U_WMRHEADER Header; off = 0; nSize = wmfheader_get(contents, blimit, &Placeable, &Header); - if(!nSize)return(0); + if (!nSize) { + return(0); + } if(!Header.nObjects){ Header.nObjects = 256; }// there _may_ be WMF files with no objects, more likely it is corrupt. Try to use it anyway. d->n_obj = Header.nObjects; d->wmf_obj = new WMF_OBJECT[d->n_obj]; @@ -1602,7 +1605,10 @@ int Wmf::myMetaFileProc(const char *contents, unsigned int length, PWMF_CALLBACK else { off += nSize; } - } + } + else { + return(0); + } } off=0; nSize = hold_nSize; @@ -1665,27 +1671,32 @@ int Wmf::myMetaFileProc(const char *contents, unsigned int length, PWMF_CALLBACK while(OK){ - if(off>=length)return(0); //normally should exit from while after WMREOF sets OK to false. + if (off>=length) { + return(0); //normally should exit from while after WMREOF sets OK to false. + } contents += nSize; // pointer to the start of the next record off += nSize; // offset from beginning of buffer to the start of the next record - SVGOStringStream tmp_path; - SVGOStringStream tmp_str; - - /* Check that the current record size is OK, abort if not. - Pointer math might wrap, so check both sides of the range. - Some of the records will reset this with the same value,others will not - return a value at this time. */ + /* Currently this is a weaker check than for EMF, it only checks the size of the constant part + of the record */ nSize = U_WMRRECSAFE_get(contents, blimit); - if(!nSize)break; + if(!nSize) { + file_status = 0; + break; + } iType = *(uint8_t *)(contents + offsetof(U_METARECORD, iType ) ); + wmr_mask = U_wmr_properties(iType); + if (wmr_mask == U_WMR_INVALID) { + file_status = 0; + break; + } // Uncomment the following to track down toxic records // std::cout << "record type: " << (int) iType << " name " << U_wmr_names(iType) << " length: " << nSize << " offset: " << off <dirty:"<< d->tri->dirty << " wmr_mask: " << std::hex << wmr_mask << std::dec << std::endl; @@ -3026,14 +3037,17 @@ std::cout << "BEFORE DRAW" // 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(); - if(!nSize){ OK=0; std::cout << "nSize == 0, oops!!!" << std::endl; } // There was some problem with this record, it is not safe to continue + if(!nSize){ // There was some problem with the processing of this record, it is not safe to continue + file_status = 0; + break; + } - } //end of while + } //end of while on OK // When testing, uncomment the following to show the final SVG derived from the WMF // 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; + return(file_status); } void Wmf::free_wmf_strings(WMF_STRINGS name){ @@ -3049,7 +3063,14 @@ SPDocument * Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) { + if (uri == NULL) { + return NULL; + } + WMF_CALLBACK_DATA d; + + d.n_obj = 0; //these might not be set otherwise if the input file is corrupt + d.wmf_obj=NULL; // 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! @@ -3067,10 +3088,6 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) 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 ); - if (uri == NULL) { - return 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. @@ -3095,12 +3112,15 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP, FT_KERNING_UNSCALED); - (void) myMetaFileProc(contents,length, &d); + int good = myMetaFileProc(contents,length, &d); free(contents); // 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 = NULL; + if (good) { + doc = SPDocument::createNewDocFromMem(d.outsvg.c_str(), strlen(d.outsvg.c_str()), TRUE); + } free_wmf_strings(d.hatches); free_wmf_strings(d.images); diff --git a/src/extension/internal/wmf-print.cpp b/src/extension/internal/wmf-print.cpp index 567f9f366..9fe1a0259 100644 --- a/src/extension/internal/wmf-print.cpp +++ b/src/extension/internal/wmf-print.cpp @@ -61,6 +61,7 @@ #include "splivarot.h" // pieces for union on shapes #include "2geom/svg-path-parser.h" // to get from SVG text to Geom::Path #include "display/canvas-bpath.h" // for SPWindRule +#include "display/cairo-utils.h" // for Inkscape::Pixbuf::PF_CAIRO #include "wmf-print.h" @@ -471,9 +472,8 @@ int PrintWmf::create_brush(SPStyle const *style, U_COLORREF *fcolor) rgba_px = (char *) pixbuf->pixels(); // Do NOT free this!!! colortype = U_BCBM_COLOR32; (void) RGBA_to_DIB(&px, &cbPx, &ct, &numCt, rgba_px, width, height, width * 4, colortype, 0, 1); - // Not sure why the next swap is needed because the preceding does it, and the code is identical - // to that in stretchdibits_set, which does not need this. - swapRBinRGBA(px, width * height); + // pixbuf can be either PF_CAIRO or PF_GDK, and these have R and B bytes swapped + if (pixbuf->pixelFormat() == Inkscape::Pixbuf::PF_CAIRO) { swapRBinRGBA(px, width * height); } Bmih = bitmapinfoheader_set(width, height, 1, colortype, U_BI_RGB, 0, PXPERMETER, PXPERMETER, numCt, 0); Bmi = bitmapinfo_set(Bmih, ct); rec = wcreatedibpatternbrush_srcdib_set(&brush, wht, U_DIB_RGB_COLORS, Bmi, cbPx, px); diff --git a/src/libuemf/Makefile_insert b/src/libuemf/Makefile_insert index 004c56dfc..427a0e80e 100644 --- a/src/libuemf/Makefile_insert +++ b/src/libuemf/Makefile_insert @@ -12,6 +12,8 @@ libuemf_libuemf_a_SOURCES = \ libuemf/uemf_endian.h \ libuemf/uemf_print.c \ libuemf/uemf_print.h \ + libuemf/uemf_safe.c \ + libuemf/uemf_safe.h \ libuemf/uemf_utf.c \ libuemf/uemf_utf.h \ libuemf/uwmf.c \ diff --git a/src/libuemf/README b/src/libuemf/README index cfa322178..a3dff9b4c 100644 --- a/src/libuemf/README +++ b/src/libuemf/README @@ -1,22 +1,25 @@ Overview: -libUEMF is a portable C99 implementation for reading/writing Enhanced Metafile (EMF) -and Windows Metafile (WMF) files. libUEMF avoids collisions with with Microsoft defined -functions and values, so portable programs which use it, and have a Windows version, do -not require any conditional logic to separate the native GDI support from the WMF/EMF support -proviced by libUEMF. To accomplish this libUEMF does not implement GDI calls. Instead, -for each WMR/EMR record type, and each object type incorporated into such a record, it provides -corresponding *_set, *_print, and *_swap functions. (For WMF there are also *_get functions, see below.) -For example, for the U_EMRBITBLT record there are corresponding functions: -U_EMRBITBLT_set, U_EMRBITBLT_print, and U_EMRBITBLT_swap. A few additional functions are provided for -assembling the EMF in memory, debugging, and converting the EMF file to/from Little Endian representation. -(EMF files' internal data representation is always Little Endian.) - -This code has been tested on 32 bit Ubuntu (LE), 32 bit Mingw, 64 bit Manriva, and 64 bit Solaris (BE). +libUEMF is a portable C99 implementation for reading/writing Enhanced Metafile (EMF), +Enhanced Metafile Format Plus (PMF), and Windows Metafile (WMF) files. libUEMF +avoids collisions with Microsoft defined functions and values, so portable programs +which use it and have a Windows version, do not require any conditional logic to +separate the native GDI support from the WMF/EMF/PMF support proviced by libUEMF. To +accomplish this libUEMF does not implement GDI calls. Instead, for each WMR/EMR/PMR +record type, and each object type incorporated into such a record, it provides +corresponding *_set, *_print, and *_swap functions. For PMF and WMF there are also +*_get functions, see below. For example, for the U_EMRBITBLT record there are +corresponding functions: U_EMRBITBLT_set, U_EMRBITBLT_print, and U_EMRBITBLT_swap. A +few additional functions are provided for assembling the EMF in memory, debugging, and +converting the EMF file to/from Little Endian representation. (EMF files' internal +data representation is always Little Endian.) + +This code has been tested on 32 bit Ubuntu (LE), 32 bit Mingw, 64 bit Mageia, and 64 +bit Solaris (BE). libUEMF is released under the GPL 2 license, read the file 'COPYING' for more information -Version 0.1.10, released January 15, 2014. +Version 0.2.1, released April 23, 2015. To report bugs or provide feedback send email to David Mathog, mathog@caltech.edu. @@ -76,7 +79,14 @@ uemf_endian.c Contains the *_swap functions needed to rearrange bytes betwee uemf_endian.h Prototype for U_emf_endian() and definitions for Endian type of the local machine. - +uemf_safe.c Contains the *_safe functions for EMF records, which verify that all + offsets and counts stay within the declared size of a record. Also checks that + core record sizes are sane. U_emf_record_safe() is the only _safe function which + user code should call directly, and then ONLY after a previous call to + U_emf_record_sizeok(), which is in the endian file. + +uemf_safe.h Prototype for U_emf_record_safe(). + . upmf.c Contains the *_set and *_get functions needed to construct or read an EMF+ file. Also contains auxilliary functions for debugging and constructing EMF+ files in memory. @@ -366,9 +376,69 @@ History (Note, version numbers in files represent the libUEMF release where it was last modified, so not all files will show the same version numbers in each release.) +0.2.1.2015_04_23 + Bug in safety check on EMREXTCREATEFONTINDIRECTW because it had alternative "standard" record sizes. + Changed warnings on unimplemented EMF record types encounterd in swap or safe from stdout to stderr. + Added memory checking for WMF polyline and polygon records, for the variable part and some others. + Note: U_WMRCREATEREGION_get does not check that the variable part stays within the record. Current + implementation seems to be broken since it does not show up in XP preview. +0.2.0 2015_03_20 + Added UEMF _safe functions to better handle corrupt records, where variable sizes fields might + have been specified to read past the end of memory. These are records with offsets, arrays + with counts, and bitmaps. Also any record which specifies a size smaller than the minimum + for that record type. + Added similar code for EMF+. + These changed the API so the minor version number was bumped by 1. + +0.1.18 2015_01_15 + Pierre-Francois Carpentier sent some EMF examples which used U_EMR_EXTSELECTCLIPRGN, which had + not previously been encountered and showed that the handling of regions was broken. + Added tests for U_EMRFILLRGN, U_EMRFRAMERGN, U_EMRFRAMERGN, U_EMREXTSELECTCLIPRGN to testbed_emf. + +0.1.18 2014_04_28 + Fixed typo in testbed_wmf.c. "include,include" in one place should have been + "exclude,exclude". + +0.1.17 2014_04_25 + Added text clipping tests to testbed_emf.c, testbed_wmf.c, and testbed_pmf.c. + Added option to omit clipping tests in testbed's. + +0.1.16 2014_04_14 + Fixed bug in U_WMRRESTOREDC_set. + Added clipping tests to testbed_wmf.c. + +0.1.15 2014_04_04 + Changed record flags for U_EMRSELECTCLIPPATH record, it consumes a path but does not ALTER (which + forced a premature draw.) + Added U_EMROFFSETCLIPRGN test to testbed_emf.c. + Changed location on dist drawing where clipping appears. + +0.1.14 2014_03_27 + Fixed bug, in U_PMF_RECTN_set() in upmf.c. Never tested. + Fixed a few potential bugs in upmf.c if a null pointer was passed for + certain function arguments. (Previously unhandled cases.) + Fixed bug, operations setting variables that are never read along those + execution paths: upmf_print.c, uemf.c, uwmf.c, uemf_endian.cm upmf.c. + Fixed potential (but very unlikely) memory leaks in upmf.c and uemf_utf.c. + Added test of U_PMF_RECTN_set to testbed_pmf.c. + Changed U_wmr_names() and U_wmr_escnames() to const char* (from char*). + Changed method for suppressing unused parameter warnings. + + +0.1.13 2014-03-21 + Fixed bug, cutemf was messing up the object count (pens, brushes, etc.). + Added cutemf can now take ranges of lines. + Added testbed_emf generates clipping records for rect and path (but not region). + +0.1.12 2014-02-14 + Documentation change, U_WMRCREATEPATTERNBRUSH is obsolete. + Changed wmf_finish() so that it accurately reflects the largest number of objects used, + previously it showed the number of appends, which was much larger. + 0.1.11 2014-01-29 Fixed bug in uwmf.c (wrong minimum record size on U_WMRTEXTOUT) Fixed bug in uwmf.c (U_WMRCREATEPATTERNBRUSH not right) + Fixed bug in uwmf_print.c (U_WMRTEXTOUT_print, x,y were reversed) Added error handling to uemf_utf.c for cases where src is a null pointer. Added a test of createpatternbrush to testlib_wmf diff --git a/src/libuemf/uemf.c b/src/libuemf/uemf.c index 1d417dece..3180c757c 100644 --- a/src/libuemf/uemf.c +++ b/src/libuemf/uemf.c @@ -16,11 +16,11 @@ /* File: uemf.c -Version: 0.0.28 -Date: 04-APR-2014 +Version: 0.0.30 +Date: 20-MAR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2014 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifdef __cplusplus @@ -199,7 +199,7 @@ definitions are not needed in end user code, so they are here rather than in uem // this one may also be used A=Msk,B=MskBmi and F=cbMsk #define SET_CB_FROM_PXBMI(A,B,C,D,E,F) /* A=Px, B=Bmi, C=cbImage, D=cbImage4, E=cbBmi, F=cbPx */ \ if(A){\ - if(!B)return(NULL); /* size is derived from U_BIMAPINFO, but NOT from its size field, go figure*/ \ + if(!B)return(NULL); /* size is derived from U_BITMAPINFO, but NOT from its size field, go figure*/ \ C = F;\ D = UP4(C); /* pixel array might not be a multiples of 4 bytes*/ \ E = sizeof(U_BITMAPINFOHEADER) + 4 * get_real_color_count((const char *) &(B->bmiHeader)); /* bmiheader + colortable*/ \ @@ -851,7 +851,7 @@ int get_real_color_icount( \brief Get the DIB parameters from the BMI of the record for use by DBI_to_RGBA() \return BI_Compression Enumeration. For anything other than U_BI_RGB values other than px may not be valid. - \param pEmr pointer to EMR record that has a U_BITMAPINFO and bitmap + \param record pointer to EMR record that has a U_BITMAPINFO and bitmap \param offBitsSrc Offset to the bitmap \param offBmiSrc Offset to the U_BITMAPINFO \param px pointer to DIB pixel array in pEmr @@ -863,7 +863,7 @@ int get_real_color_icount( \param invert If DIB rows are in opposite order from RGBA rows */ int get_DIB_params( - void *pEmr, + const char *record, uint32_t offBitsSrc, uint32_t offBmiSrc, const char **px, @@ -875,7 +875,7 @@ int get_DIB_params( uint32_t *invert ){ uint32_t bic; - PU_BITMAPINFO Bmi = (PU_BITMAPINFO)((char *)pEmr + offBmiSrc); + PU_BITMAPINFO Bmi = (PU_BITMAPINFO)(record + offBmiSrc); PU_BITMAPINFOHEADER Bmih = &(Bmi->bmiHeader); /* if biCompression is not U_BI_RGB some or all of the following might not hold real values */ bic = Bmih->biCompression; @@ -903,7 +903,7 @@ int get_DIB_params( *numCt = Bmih->biSizeImage; *ct = NULL; } - *px = (char *)((char *)pEmr + offBitsSrc); + *px = record + offBitsSrc; return(bic); } @@ -1610,6 +1610,26 @@ U_RECTL rectl_set( return(rct); } +/** + \brief Set rect and rectl objects from Upper Left and Lower Right corner points. + \param array array of rectangles + \param index array entry to fill, numbered from 0 + \param ul upper left corner of rectangle + \param lr lower right corner of rectangle +*/ +void rectli_set( + PU_RECTL array, + int index, + U_POINTL ul, + U_POINTL lr + ){ + PU_RECTL rct = &(array[index]); + rct->left = ul.x; + rct->top = ul.y; + rct->right = lr.x; + rct->bottom = lr.y; +} + /** \brief Set sizel objects with X,Y values. \param x X coordinate @@ -2192,7 +2212,7 @@ U_RGNDATAHEADER rgndataheader_set( rdh.dwSize = U_RDH_OBJSIZE; rdh.iType = U_RDH_RECTANGLES; rdh.nCount = nCount; - rdh.nRgnSize = nCount * sizeof(U_RECTL); // Size in bytes of retangle array + rdh.nRgnSize = nCount * sizeof(U_RECTL); // Size in bytes of rectangle array rdh.rclBounds = rclBounds; return(rdh); } @@ -2857,7 +2877,7 @@ by end user code and to further that end prototypes are NOT provided and they ar // Functions with the same form starting with U_EMRPOLYBEZIER_set -char *U_EMR_CORE1(uint32_t iType, U_RECTL rclBounds, const uint32_t cptl, const U_POINTL *points){ +char *U_EMR_CORE1_set(uint32_t iType, U_RECTL rclBounds, const uint32_t cptl, const U_POINTL *points){ char *record; int cbPoints; int irecsize; @@ -2876,7 +2896,7 @@ char *U_EMR_CORE1(uint32_t iType, U_RECTL rclBounds, const uint32_t cptl, const } // Functions with the same form starting with U_EMR_POLYPOLYLINE -char *U_EMR_CORE2(uint32_t iType, U_RECTL rclBounds, const uint32_t nPolys, const uint32_t *aPolyCounts,const uint32_t cptl, const U_POINTL *points){ +char *U_EMR_CORE2_set(uint32_t iType, U_RECTL rclBounds, const uint32_t nPolys, const uint32_t *aPolyCounts,const uint32_t cptl, const U_POINTL *points){ char *record; int cbPolys,cbPoints,off; int irecsize; @@ -2899,7 +2919,7 @@ char *U_EMR_CORE2(uint32_t iType, U_RECTL rclBounds, const uint32_t nPolys, cons } // Functions with the same form starting with U_EMR_SETMAPMODE_set -char *U_EMR_CORE3(uint32_t iType, uint32_t iMode){ +char *U_EMR_CORE3_set(uint32_t iType, uint32_t iMode){ char *record; int irecsize; @@ -2914,7 +2934,7 @@ char *U_EMR_CORE3(uint32_t iType, uint32_t iMode){ } // Functions taking a single U_RECT or U_RECTL, starting with U_EMRELLIPSE_set, also U_EMRFILLPATH, -char *U_EMR_CORE4(uint32_t iType, U_RECTL rclBox){ +char *U_EMR_CORE4_set(uint32_t iType, U_RECTL rclBox){ char *record; int irecsize; @@ -2930,7 +2950,7 @@ char *U_EMR_CORE4(uint32_t iType, U_RECTL rclBox){ } // Functions with the same form starting with U_EMRSETMETARGN_set -char *U_EMR_CORE5(uint32_t iType){ +char *U_EMR_CORE5_set(uint32_t iType){ char *record; int irecsize = 8; @@ -2943,7 +2963,7 @@ char *U_EMR_CORE5(uint32_t iType){ } // Functions with the same form starting with U_EMRPOLYBEZIER16_set -char *U_EMR_CORE6(uint32_t iType, U_RECTL rclBounds, const uint32_t cpts, const U_POINT16 *points){ +char *U_EMR_CORE6_set(uint32_t iType, U_RECTL rclBounds, const uint32_t cpts, const U_POINT16 *points){ char *record; int cbPoints,cbPoints4,off; int irecsize; @@ -2970,7 +2990,7 @@ char *U_EMR_CORE6(uint32_t iType, U_RECTL rclBounds, const uint32_t cpts, const // Functions that take a single struct argument which contains two uint32_t, starting with U_EMRSETWINDOWEXTEX_set // these all pass two 32 bit ints and are cast by the caller to U_PAIR -char *U_EMR_CORE7(uint32_t iType, U_PAIR pair){ +char *U_EMR_CORE7_set(uint32_t iType, U_PAIR pair){ char *record; int irecsize = sizeof(U_EMRGENERICPAIR); @@ -2984,7 +3004,7 @@ char *U_EMR_CORE7(uint32_t iType, U_PAIR pair){ } // For U_EMREXTTEXTOUTA and U_EMREXTTEXTOUTW -char *U_EMR_CORE8( +char *U_EMR_CORE8_set( uint32_t iType, U_RECTL rclBounds, // Bounding rectangle in device units uint32_t iGraphicsMode, // Graphics mode Enumeration @@ -3033,7 +3053,7 @@ char *U_EMR_CORE8( } // Functions that take a rect and a pair of points, starting with U_EMRARC_set -char *U_EMR_CORE9(uint32_t iType, U_RECTL rclBox, U_POINTL ptlStart, U_POINTL ptlEnd){ +char *U_EMR_CORE9_set(uint32_t iType, U_RECTL rclBox, U_POINTL ptlStart, U_POINTL ptlEnd){ char *record; int irecsize = sizeof(U_EMRARC); @@ -3049,7 +3069,7 @@ char *U_EMR_CORE9(uint32_t iType, U_RECTL rclBox, U_POINTL ptlStart, U_POINTL pt } // Functions with the same form starting with U_EMR_POLYPOLYLINE16 -char *U_EMR_CORE10(uint32_t iType, U_RECTL rclBounds, const uint32_t nPolys, const uint32_t *aPolyCounts,const uint32_t cpts, const U_POINT16 *points){ +char *U_EMR_CORE10_set(uint32_t iType, U_RECTL rclBounds, const uint32_t nPolys, const uint32_t *aPolyCounts,const uint32_t cpts, const U_POINT16 *points){ char *record; int cbPoints,cbPolys,off; int irecsize; @@ -3072,25 +3092,27 @@ char *U_EMR_CORE10(uint32_t iType, U_RECTL rclBounds, const uint32_t nPolys, con } // common code for U_EMRINVERTRGN and U_EMRPAINTRGN, -char *U_EMR_CORE11(uint32_t iType, PU_RGNDATA RgnData){ +char *U_EMR_CORE11_set(uint32_t iType, PU_RGNDATA RgnData){ char *record; int irecsize; - int cbRgns,cbRgns4,off; + int cbRgns,cbRgns4,rds,rds4,off; if(!RgnData)return(NULL); cbRgns = ((PU_RGNDATAHEADER) RgnData)->nRgnSize; cbRgns4 = UP4(cbRgns); - irecsize = sizeof(U_EMRINVERTRGN) + cbRgns4 - sizeof(U_RGNDATAHEADER); // core + array - overlap - record = malloc(irecsize); + rds = sizeof(U_RGNDATAHEADER) + cbRgns; + rds4 = UP4(rds); + irecsize = sizeof(U_EMRINVERTRGN) - sizeof(U_RECTL) + cbRgns4; // core + array - overlap of one rectL + record = malloc(irecsize); if(record){ ((PU_EMR) record)->iType = iType; ((PU_EMR) record)->nSize = irecsize; ((PU_EMRINVERTRGN) record)->rclBounds = ((PU_RGNDATAHEADER) RgnData)->rclBounds; - ((PU_EMRINVERTRGN) record)->cbRgnData = cbRgns; - off = irecsize - cbRgns4; - memcpy(record + off, RgnData, cbRgns); - off += cbRgns; - if(cbRgns < cbRgns4){ memset(record + off,0, cbRgns4 - cbRgns); } // clear any unused bytes + ((PU_EMRINVERTRGN) record)->cbRgnData = rds; + off = sizeof(U_EMRINVERTRGN) - sizeof(U_RGNDATA); + memcpy(record + off, RgnData, rds); + off += rds; + if(rds < rds4){ memset(record + off,0, rds4 - rds); } // clear any unused bytes } return(record); } @@ -3274,7 +3296,7 @@ char *U_EMRPOLYBEZIER_set( const uint32_t cptl, const U_POINTL *points ){ - return(U_EMR_CORE1(U_EMR_POLYBEZIER, rclBounds, cptl, points)); + return(U_EMR_CORE1_set(U_EMR_POLYBEZIER, rclBounds, cptl, points)); } // U_EMRPOLYGON_set 3 @@ -3290,7 +3312,7 @@ char *U_EMRPOLYGON_set( const uint32_t cptl, const U_POINTL *points ){ - return(U_EMR_CORE1(U_EMR_POLYGON, rclBounds, cptl, points)); + return(U_EMR_CORE1_set(U_EMR_POLYGON, rclBounds, cptl, points)); } // U_EMRPOLYLINE_set 4 @@ -3306,7 +3328,7 @@ char *U_EMRPOLYLINE_set( const uint32_t cptl, const U_POINTL *points ){ - return(U_EMR_CORE1(U_EMR_POLYLINE, rclBounds, cptl, points)); + return(U_EMR_CORE1_set(U_EMR_POLYLINE, rclBounds, cptl, points)); } // U_EMRPOLYBEZIERTO_set 5 @@ -3322,7 +3344,7 @@ char *U_EMRPOLYBEZIERTO_set( const uint32_t cptl, const U_POINTL *points ){ - return(U_EMR_CORE1(U_EMR_POLYBEZIERTO, rclBounds, cptl, points)); + return(U_EMR_CORE1_set(U_EMR_POLYBEZIERTO, rclBounds, cptl, points)); } // U_EMRPOLYLINETO_set 6 @@ -3338,7 +3360,7 @@ char *U_EMRPOLYLINETO_set( const uint32_t cptl, const U_POINTL *points ){ - return(U_EMR_CORE1(U_EMR_POLYLINETO, rclBounds, cptl, points)); + return(U_EMR_CORE1_set(U_EMR_POLYLINETO, rclBounds, cptl, points)); } // U_EMRPOLYPOLYLINE_set 7 @@ -3358,7 +3380,7 @@ char *U_EMRPOLYPOLYLINE_set( const uint32_t cptl, const U_POINTL *points ){ - return(U_EMR_CORE2(U_EMR_POLYPOLYLINE, rclBounds, nPolys, aPolyCounts,cptl, points)); + return(U_EMR_CORE2_set(U_EMR_POLYPOLYLINE, rclBounds, nPolys, aPolyCounts,cptl, points)); } // U_EMRPOLYPOLYGON_set 8 @@ -3378,7 +3400,7 @@ char *U_EMRPOLYPOLYGON_set( const uint32_t cptl, const U_POINTL *points ){ - return(U_EMR_CORE2(U_EMR_POLYPOLYGON, rclBounds, nPolys, aPolyCounts,cptl, points)); + return(U_EMR_CORE2_set(U_EMR_POLYPOLYGON, rclBounds, nPolys, aPolyCounts,cptl, points)); } // U_EMRSETWINDOWEXTEX_set 9 @@ -3393,7 +3415,7 @@ char *U_EMRSETWINDOWEXTEX_set( U_PAIR temp; temp.x = szlExtent.cx; temp.y = szlExtent.cy; - return(U_EMR_CORE7(U_EMR_SETWINDOWEXTEX, temp)); + return(U_EMR_CORE7_set(U_EMR_SETWINDOWEXTEX, temp)); } // U_EMRSETWINDOWORGEX_set 10 @@ -3405,7 +3427,7 @@ char *U_EMRSETWINDOWEXTEX_set( char *U_EMRSETWINDOWORGEX_set( const U_POINTL ptlOrigin ){ - return(U_EMR_CORE7(U_EMR_SETWINDOWORGEX, ptlOrigin)); // U_PAIR and U_POINTL are the same thing + return(U_EMR_CORE7_set(U_EMR_SETWINDOWORGEX, ptlOrigin)); // U_PAIR and U_POINTL are the same thing } // U_EMRSETVIEWPORTEXTEX_set 11 @@ -3420,7 +3442,7 @@ char *U_EMRSETVIEWPORTEXTEX_set( U_PAIR temp; temp.x = szlExtent.cx; temp.y = szlExtent.cy; - return(U_EMR_CORE7(U_EMR_SETVIEWPORTEXTEX, temp)); + return(U_EMR_CORE7_set(U_EMR_SETVIEWPORTEXTEX, temp)); } // U_EMRSETVIEWPORTORGEX_set 12 @@ -3432,7 +3454,7 @@ char *U_EMRSETVIEWPORTEXTEX_set( char *U_EMRSETVIEWPORTORGEX_set( const U_POINTL ptlOrigin ){ - return(U_EMR_CORE7(U_EMR_SETVIEWPORTORGEX, ptlOrigin)); // U_PAIR and U_POINTL are the same thing + return(U_EMR_CORE7_set(U_EMR_SETVIEWPORTORGEX, ptlOrigin)); // U_PAIR and U_POINTL are the same thing } // U_EMRSETBRUSHORGEX_set 13 @@ -3444,7 +3466,7 @@ char *U_EMRSETVIEWPORTORGEX_set( char *U_EMRSETBRUSHORGEX_set( const U_POINTL ptlOrigin ){ - return(U_EMR_CORE7(U_EMR_SETBRUSHORGEX, *((PU_PAIR) & ptlOrigin))); + return(U_EMR_CORE7_set(U_EMR_SETBRUSHORGEX, *((PU_PAIR) & ptlOrigin))); } // U_EMREOF_set 14 @@ -3544,7 +3566,7 @@ char *U_EMRSETMAPPERFLAGS_set(void){ char *U_EMRSETMAPMODE_set( const uint32_t iMode ){ - return(U_EMR_CORE3(U_EMR_SETMAPMODE, iMode)); + return(U_EMR_CORE3_set(U_EMR_SETMAPMODE, iMode)); } // U_EMRSETBKMODE_set 18 @@ -3556,7 +3578,7 @@ char *U_EMRSETMAPMODE_set( char *U_EMRSETBKMODE_set( const uint32_t iMode ){ - return(U_EMR_CORE3(U_EMR_SETBKMODE, iMode)); + return(U_EMR_CORE3_set(U_EMR_SETBKMODE, iMode)); } // U_EMRSETPOLYFILLMODE_set 19 @@ -3568,7 +3590,7 @@ char *U_EMRSETBKMODE_set( char *U_EMRSETPOLYFILLMODE_set( const uint32_t iMode ){ - return(U_EMR_CORE3(U_EMR_SETPOLYFILLMODE, iMode)); + return(U_EMR_CORE3_set(U_EMR_SETPOLYFILLMODE, iMode)); } // U_EMRSETROP2_set 20 @@ -3580,7 +3602,7 @@ char *U_EMRSETPOLYFILLMODE_set( char *U_EMRSETROP2_set( const uint32_t iMode ){ - return(U_EMR_CORE3(U_EMR_SETROP2, iMode)); + return(U_EMR_CORE3_set(U_EMR_SETROP2, iMode)); } // U_EMRSETSTRETCHBLTMODE_set 21 @@ -3592,7 +3614,7 @@ char *U_EMRSETROP2_set( char *U_EMRSETSTRETCHBLTMODE_set( const uint32_t iMode ){ - return(U_EMR_CORE3(U_EMR_SETSTRETCHBLTMODE, iMode)); + return(U_EMR_CORE3_set(U_EMR_SETSTRETCHBLTMODE, iMode)); } // U_EMRSETTEXTALIGN_set 22 @@ -3604,7 +3626,7 @@ char *U_EMRSETSTRETCHBLTMODE_set( char *U_EMRSETTEXTALIGN_set( const uint32_t iMode ){ - return(U_EMR_CORE3(U_EMR_SETTEXTALIGN, iMode)); + return(U_EMR_CORE3_set(U_EMR_SETTEXTALIGN, iMode)); } // U_EMRSETCOLORADJUSTMENT_set 23 @@ -3638,7 +3660,7 @@ char *U_EMRSETCOLORADJUSTMENT_set( char *U_EMRSETTEXTCOLOR_set( const U_COLORREF crColor ){ - return(U_EMR_CORE3(U_EMR_SETTEXTCOLOR, *(uint32_t *) &crColor)); + return(U_EMR_CORE3_set(U_EMR_SETTEXTCOLOR, *(uint32_t *) &crColor)); } // U_EMRSETBKCOLOR_set 25 @@ -3650,7 +3672,7 @@ char *U_EMRSETTEXTCOLOR_set( char *U_EMRSETBKCOLOR_set( const U_COLORREF crColor ){ - return(U_EMR_CORE3(U_EMR_SETBKCOLOR, *(uint32_t *) &crColor)); + return(U_EMR_CORE3_set(U_EMR_SETBKCOLOR, *(uint32_t *) &crColor)); } // U_EMROFFSETCLIPRGN_set 26 @@ -3662,7 +3684,7 @@ char *U_EMRSETBKCOLOR_set( char *U_EMROFFSETCLIPRGN_set( const U_POINTL ptl ){ - return(U_EMR_CORE7(U_EMR_OFFSETCLIPRGN, ptl)); + return(U_EMR_CORE7_set(U_EMR_OFFSETCLIPRGN, ptl)); } // U_EMRMOVETOEX_set 27 @@ -3674,7 +3696,7 @@ char *U_EMROFFSETCLIPRGN_set( char *U_EMRMOVETOEX_set( const U_POINTL ptl ){ - return(U_EMR_CORE7(U_EMR_MOVETOEX, ptl)); + return(U_EMR_CORE7_set(U_EMR_MOVETOEX, ptl)); } // U_EMRSETMETARGN_set 28 @@ -3683,7 +3705,7 @@ char *U_EMRMOVETOEX_set( \return pointer to U_EMR_SETMETARGN record, or NULL on error. */ char *U_EMRSETMETARGN_set(void){ - return(U_EMR_CORE5(U_EMR_SETMETARGN)); + return(U_EMR_CORE5_set(U_EMR_SETMETARGN)); } // U_EMREXCLUDECLIPRECT_set 29 @@ -3695,7 +3717,7 @@ char *U_EMRSETMETARGN_set(void){ char *U_EMREXCLUDECLIPRECT_set( const U_RECTL rclClip ){ - return(U_EMR_CORE4(U_EMR_EXCLUDECLIPRECT,rclClip)); + return(U_EMR_CORE4_set(U_EMR_EXCLUDECLIPRECT,rclClip)); } // U_EMRINTERSECTCLIPRECT_set 30 @@ -3707,7 +3729,7 @@ char *U_EMREXCLUDECLIPRECT_set( char *U_EMRINTERSECTCLIPRECT_set( const U_RECTL rclClip ){ - return(U_EMR_CORE4(U_EMR_INTERSECTCLIPRECT,rclClip)); + return(U_EMR_CORE4_set(U_EMR_INTERSECTCLIPRECT,rclClip)); } // U_EMRSCALEVIEWPORTEXTEX_set 31 @@ -3725,7 +3747,7 @@ char *U_EMRSCALEVIEWPORTEXTEX_set( const int32_t yNum, const int32_t yDenom ){ - return(U_EMR_CORE4(U_EMR_SCALEVIEWPORTEXTEX,(U_RECTL){xNum,xDenom,yNum,yDenom})); + return(U_EMR_CORE4_set(U_EMR_SCALEVIEWPORTEXTEX,(U_RECTL){xNum,xDenom,yNum,yDenom})); } @@ -3744,7 +3766,7 @@ char *U_EMRSCALEWINDOWEXTEX_set( const int32_t yNum, const int32_t yDenom ){ - return(U_EMR_CORE4(U_EMR_SCALEWINDOWEXTEX,(U_RECTL){xNum,xDenom,yNum,yDenom})); + return(U_EMR_CORE4_set(U_EMR_SCALEWINDOWEXTEX,(U_RECTL){xNum,xDenom,yNum,yDenom})); } // U_EMRSAVEDC_set 33 @@ -3753,7 +3775,7 @@ char *U_EMRSCALEWINDOWEXTEX_set( \return pointer to U_EMR_SAVEDC record, or NULL on error. */ char *U_EMRSAVEDC_set(void){ - return(U_EMR_CORE5(U_EMR_SAVEDC)); + return(U_EMR_CORE5_set(U_EMR_SAVEDC)); } // U_EMRRESTOREDC_set 34 @@ -3765,7 +3787,7 @@ char *U_EMRSAVEDC_set(void){ char *U_EMRRESTOREDC_set( const int32_t iRelative ){ - return(U_EMR_CORE3(U_EMR_RESTOREDC, (uint32_t) iRelative)); + return(U_EMR_CORE3_set(U_EMR_RESTOREDC, (uint32_t) iRelative)); } // U_EMRSETWORLDTRANSFORM_set 35 @@ -3952,7 +3974,7 @@ char *U_EMRANGLEARC_set( char *U_EMRELLIPSE_set( const U_RECTL rclBox ){ - return(U_EMR_CORE4(U_EMR_ELLIPSE,rclBox)); + return(U_EMR_CORE4_set(U_EMR_ELLIPSE,rclBox)); } // U_EMRRECTANGLE_set 43 @@ -3964,7 +3986,7 @@ char *U_EMRELLIPSE_set( char *U_EMRRECTANGLE_set( const U_RECTL rclBox ){ - return(U_EMR_CORE4(U_EMR_RECTANGLE,rclBox)); + return(U_EMR_CORE4_set(U_EMR_RECTANGLE,rclBox)); } // U_EMRROUNDRECT_set 44 @@ -4005,7 +4027,7 @@ char *U_EMRARC_set( const U_POINTL ptlStart, const U_POINTL ptlEnd ){ - return(U_EMR_CORE9(U_EMR_ARC,rclBox, ptlStart, ptlEnd)); + return(U_EMR_CORE9_set(U_EMR_ARC,rclBox, ptlStart, ptlEnd)); } // U_EMRCHORD_set 46 @@ -4021,7 +4043,7 @@ char *U_EMRCHORD_set( const U_POINTL ptlStart, const U_POINTL ptlEnd ){ - return(U_EMR_CORE9(U_EMR_CHORD,rclBox, ptlStart, ptlEnd)); + return(U_EMR_CORE9_set(U_EMR_CHORD,rclBox, ptlStart, ptlEnd)); } // U_EMRPIE_set 47 @@ -4037,7 +4059,7 @@ char *U_EMRPIE_set( const U_POINTL ptlStart, const U_POINTL ptlEnd ){ - return(U_EMR_CORE9(U_EMR_PIE,rclBox, ptlStart, ptlEnd)); + return(U_EMR_CORE9_set(U_EMR_PIE,rclBox, ptlStart, ptlEnd)); } // U_EMRSELECTPALETTE_set 48 @@ -4049,7 +4071,7 @@ char *U_EMRPIE_set( char *U_EMRSELECTPALETTE_set( const uint32_t ihPal ){ - return(U_EMR_CORE3(U_EMR_SELECTPALETTE, ihPal)); + return(U_EMR_CORE3_set(U_EMR_SELECTPALETTE, ihPal)); } // U_EMRCREATEPALETTE_set 49 @@ -4124,7 +4146,7 @@ char *U_EMRRESIZEPALETTE_set( const uint32_t ihPal, const uint32_t cEntries ){ - return(U_EMR_CORE7(U_EMR_RESIZEPALETTE, (U_PAIR){ihPal,cEntries})); + return(U_EMR_CORE7_set(U_EMR_RESIZEPALETTE, (U_PAIR){ihPal,cEntries})); } // U_EMRREALIZEPALETTE_set 52 @@ -4133,7 +4155,7 @@ char *U_EMRRESIZEPALETTE_set( \return pointer to U_EMR_REALIZEPALETTE record, or NULL on error. */ char *U_EMRREALIZEPALETTE_set(void){ - return(U_EMR_CORE5(U_EMR_REALIZEPALETTE)); + return(U_EMR_CORE5_set(U_EMR_REALIZEPALETTE)); } // U_EMREXTFLOODFILL_set 53 @@ -4173,7 +4195,7 @@ char *U_EMREXTFLOODFILL_set( char *U_EMRLINETO_set( const U_POINTL ptl ){ - return(U_EMR_CORE7(U_EMR_LINETO, ptl)); + return(U_EMR_CORE7_set(U_EMR_LINETO, ptl)); } // U_EMRARCTO_set 55 @@ -4192,7 +4214,7 @@ char *U_EMRARCTO_set( U_POINTL ptlStart, U_POINTL ptlEnd ){ - return(U_EMR_CORE9(U_EMR_ARCTO,rclBox, ptlStart, ptlEnd)); + return(U_EMR_CORE9_set(U_EMR_ARCTO,rclBox, ptlStart, ptlEnd)); } // U_EMRPOLYDRAW_set 56 @@ -4216,7 +4238,7 @@ char *U_EMRPOLYDRAW_set( if(!cptl || !aptl || !abTypes)return(NULL); cbPoints = cptl * sizeof(U_POINTL); // space for aptl - cbAbTypes = cptl; // number of abTypes (also size, 1 byte each) + cbAbTypes = cptl; // number of abTypes (same array size, 1 byte each) cbAbTypes4 = UP4(cbAbTypes); // space for abTypes irecsize = sizeof(U_EMRPOLYDRAW) + cbPoints + cbAbTypes4 - sizeof(U_POINTL) - 1; record = malloc(irecsize); @@ -4244,7 +4266,7 @@ char *U_EMRPOLYDRAW_set( char *U_EMRSETARCDIRECTION_set( const uint32_t iArcDirection ){ - return(U_EMR_CORE3(U_EMR_SETARCDIRECTION, iArcDirection)); + return(U_EMR_CORE3_set(U_EMR_SETARCDIRECTION, iArcDirection)); } // U_EMRSETMITERLIMIT_set 58 @@ -4256,7 +4278,7 @@ char *U_EMRSETARCDIRECTION_set( char *U_EMRSETMITERLIMIT_set( const uint32_t eMiterLimit ){ - return(U_EMR_CORE3(U_EMR_SETMITERLIMIT, eMiterLimit)); + return(U_EMR_CORE3_set(U_EMR_SETMITERLIMIT, eMiterLimit)); } @@ -4266,7 +4288,7 @@ char *U_EMRSETMITERLIMIT_set( \return pointer to U_EMR_BEGINPATH record, or NULL on error. */ char *U_EMRBEGINPATH_set(void){ - return(U_EMR_CORE5(U_EMR_BEGINPATH)); + return(U_EMR_CORE5_set(U_EMR_BEGINPATH)); } // U_EMRENDPATH_set 60 @@ -4275,7 +4297,7 @@ char *U_EMRBEGINPATH_set(void){ \return pointer to U_EMR_ENDPATH record, or NULL on error. */ char *U_EMRENDPATH_set(void){ - return(U_EMR_CORE5(U_EMR_ENDPATH)); + return(U_EMR_CORE5_set(U_EMR_ENDPATH)); } // U_EMRCLOSEFIGURE_set 61 @@ -4284,7 +4306,7 @@ char *U_EMRENDPATH_set(void){ \return pointer to U_EMR_CLOSEFIGURE record, or NULL on error. */ char *U_EMRCLOSEFIGURE_set(void){ - return(U_EMR_CORE5(U_EMR_CLOSEFIGURE)); + return(U_EMR_CORE5_set(U_EMR_CLOSEFIGURE)); } // U_EMRFILLPATH_set 62 @@ -4298,7 +4320,7 @@ char *U_EMRCLOSEFIGURE_set(void){ char *U_EMRFILLPATH_set( const U_RECTL rclBox ){ - return(U_EMR_CORE4(U_EMR_FILLPATH,rclBox)); + return(U_EMR_CORE4_set(U_EMR_FILLPATH,rclBox)); } // U_EMRSTROKEANDFILLPATH_set 63 @@ -4314,7 +4336,7 @@ char *U_EMRFILLPATH_set( char *U_EMRSTROKEANDFILLPATH_set( const U_RECTL rclBox ){ - return(U_EMR_CORE4(U_EMR_STROKEANDFILLPATH,rclBox)); + return(U_EMR_CORE4_set(U_EMR_STROKEANDFILLPATH,rclBox)); } // U_EMRSTROKEPATH_set 64 @@ -4328,7 +4350,7 @@ char *U_EMRSTROKEANDFILLPATH_set( char *U_EMRSTROKEPATH_set( const U_RECTL rclBox ){ - return(U_EMR_CORE4(U_EMR_STROKEPATH,rclBox)); + return(U_EMR_CORE4_set(U_EMR_STROKEPATH,rclBox)); } // U_EMRFLATTENPATH_set 65 @@ -4337,7 +4359,7 @@ char *U_EMRSTROKEPATH_set( \return pointer to U_EMR_FLATTENPATH record, or NULL on error. */ char *U_EMRFLATTENPATH_set(void){ - return(U_EMR_CORE5(U_EMR_FLATTENPATH)); + return(U_EMR_CORE5_set(U_EMR_FLATTENPATH)); } // U_EMRWIDENPATH_set 66 @@ -4346,7 +4368,7 @@ char *U_EMRFLATTENPATH_set(void){ \return pointer to U_EMR_WIDENPATH record, or NULL on error. */ char *U_EMRWIDENPATH_set(void){ - return(U_EMR_CORE5(U_EMR_WIDENPATH)); + return(U_EMR_CORE5_set(U_EMR_WIDENPATH)); } // U_EMRSELECTCLIPPATH_set 67 @@ -4358,7 +4380,7 @@ char *U_EMRWIDENPATH_set(void){ char *U_EMRSELECTCLIPPATH_set( const uint32_t iMode ){ - return(U_EMR_CORE3(U_EMR_SELECTCLIPPATH, iMode)); + return(U_EMR_CORE3_set(U_EMR_SELECTCLIPPATH, iMode)); } // U_EMRABORTPATH_set 68 @@ -4367,7 +4389,7 @@ char *U_EMRSELECTCLIPPATH_set( \return pointer to U_EMR_ABORTPATH record, or NULL on error. */ char *U_EMRABORTPATH_set(void){ - return(U_EMR_CORE5(U_EMR_ABORTPATH)); + return(U_EMR_CORE5_set(U_EMR_ABORTPATH)); } // U_EMRUNDEF69 69 @@ -4416,23 +4438,25 @@ char *U_EMRFILLRGN_set( ){ char *record; int irecsize; - int cbRgns,cbRgns4,off; + int cbRgns,cbRgns4,rds,rds4,off; if(!RgnData)return(NULL); cbRgns = ((PU_RGNDATAHEADER) RgnData)->nRgnSize; - cbRgns4 = UP4(cbRgns); - irecsize = sizeof(U_EMRFILLRGN) + cbRgns4 - sizeof(U_RGNDATAHEADER); // core + array - overlap + cbRgns4 = UP4(cbRgns); + rds = sizeof(U_RGNDATAHEADER) + cbRgns; + rds4 = UP4(rds); + irecsize = sizeof(U_EMRFILLRGN) - sizeof(U_RECTL) + cbRgns4; // core + array - overlap of one rectL record = malloc(irecsize); if(record){ ((PU_EMR) record)->iType = U_EMR_FILLRGN; ((PU_EMR) record)->nSize = irecsize; - ((PU_EMRFILLRGN) record)->rclBounds = rclBounds; // or ??? ((PU_RGNDATAHEADER) RgnData)->rclBounds; - ((PU_EMRFILLRGN) record)->cbRgnData = cbRgns; + ((PU_EMRFILLRGN) record)->rclBounds = rclBounds; + ((PU_EMRFILLRGN) record)->cbRgnData = rds; ((PU_EMRFILLRGN) record)->ihBrush = ihBrush; - off = irecsize - cbRgns4; - memcpy(record + off, RgnData, cbRgns); - off += cbRgns; - if(cbRgns4 > cbRgns){ memset(record + off,0,cbRgns4-cbRgns); } // clear any unused bytes + off = sizeof(U_EMRFILLRGN) - sizeof(U_RGNDATA); + memcpy(record + off, RgnData, rds); + off += rds; + if(rds < rds4){ memset(record + off,0, rds4 - rds); } // clear any unused bytes } return(record); } @@ -4455,24 +4479,26 @@ char *U_EMRFRAMERGN_set( ){ char *record; int irecsize; - int cbRgns,cbRgns4,off; + int cbRgns,cbRgns4,rds,rds4,off; if(!RgnData)return(NULL); cbRgns = ((PU_RGNDATAHEADER) RgnData)->nRgnSize; - cbRgns4 = UP4(cbRgns); - irecsize = sizeof(U_EMRFRAMERGN) + cbRgns4 - sizeof(U_RGNDATAHEADER); // core + array - overlap + cbRgns4 = UP4(cbRgns); + rds = sizeof(U_RGNDATAHEADER) + cbRgns; + rds4 = UP4(rds); + irecsize = sizeof(U_EMRFRAMERGN) - sizeof(U_RECTL) + cbRgns4; // core + array - overlap of one rectL record = malloc(irecsize); if(record){ ((PU_EMR) record)->iType = U_EMR_FRAMERGN; ((PU_EMR) record)->nSize = irecsize; - ((PU_EMRFRAMERGN) record)->rclBounds = rclBounds; // or ??? ((PU_RGNDATAHEADER) RgnData)->rclBounds; - ((PU_EMRFRAMERGN) record)->cbRgnData = cbRgns; + ((PU_EMRFRAMERGN) record)->rclBounds = rclBounds; + ((PU_EMRFRAMERGN) record)->cbRgnData = rds; ((PU_EMRFRAMERGN) record)->ihBrush = ihBrush; ((PU_EMRFRAMERGN) record)->szlStroke = szlStroke; - off = irecsize - cbRgns4; - memcpy(record + off, RgnData, cbRgns); - off += cbRgns; - if(cbRgns4 > cbRgns){ memset(record + off,0,cbRgns4-cbRgns); } // clear any unused bytes + off = sizeof(U_EMRFRAMERGN) - sizeof(U_RGNDATA); + memcpy(record + off, RgnData, rds); + off += rds; + if(rds < rds4){ memset(record + off,0, rds4 - rds); } // clear any unused bytes } return(record); } @@ -4486,7 +4512,7 @@ char *U_EMRFRAMERGN_set( char *U_EMRINVERTRGN_set( const PU_RGNDATA RgnData ){ - return(U_EMR_CORE11(U_EMR_INVERTRGN, RgnData)); + return(U_EMR_CORE11_set(U_EMR_INVERTRGN, RgnData)); } // U_EMRPAINTRGN_set 74 @@ -4498,7 +4524,7 @@ char *U_EMRINVERTRGN_set( char *U_EMRPAINTRGN_set( const PU_RGNDATA RgnData ){ - return(U_EMR_CORE11(U_EMR_PAINTRGN, RgnData)); + return(U_EMR_CORE11_set(U_EMR_PAINTRGN, RgnData)); } // U_EMREXTSELECTCLIPRGN_set 75 @@ -4514,22 +4540,24 @@ char *U_EMREXTSELECTCLIPRGN_set( ){ char *record; int irecsize; - int cbRgns,cbRgns4,off; + int cbRgns,cbRgns4,rds,rds4,off; if(!RgnData)return(NULL); cbRgns = ((PU_RGNDATAHEADER) RgnData)->nRgnSize; - cbRgns4 = UP4(cbRgns); - irecsize = sizeof(U_EMREXTSELECTCLIPRGN) + cbRgns4 - sizeof(U_RGNDATAHEADER); // core + array - overlap + cbRgns4 = UP4(cbRgns); + rds = sizeof(U_RGNDATAHEADER) + cbRgns; + rds4 = UP4(rds); + irecsize = sizeof(U_EMREXTSELECTCLIPRGN) - sizeof(U_RECTL) + cbRgns4; // core + array - overlap of one rectL record = malloc(irecsize); if(record){ ((PU_EMR) record)->iType = U_EMR_EXTSELECTCLIPRGN; ((PU_EMR) record)->nSize = irecsize; - ((PU_EMREXTSELECTCLIPRGN) record)->cbRgnData = cbRgns; + ((PU_EMREXTSELECTCLIPRGN) record)->cbRgnData = rds; ((PU_EMREXTSELECTCLIPRGN) record)->iMode = iMode; - off = irecsize - cbRgns4; - memcpy(record + off, RgnData, cbRgns); - off += cbRgns; - if(cbRgns4 > cbRgns){ memset(record + off,0,cbRgns4-cbRgns); } // clear any unused bytes + off = sizeof(U_EMREXTSELECTCLIPRGN) - sizeof(U_RGNDATA); + memcpy(record + off, RgnData, rds); + off += rds; + if(rds < rds4){ memset(record + off,0, rds4 - rds); } // clear any unused bytes } return(record); } @@ -4568,7 +4596,6 @@ char *U_EMRBITBLT_set( int cbImage,cbImage4,cbBmi,off; SET_CB_FROM_PXBMI(Px,Bmi,cbImage,cbImage4,cbBmi,cbPx); - irecsize = sizeof(U_EMRBITBLT) + cbBmi + cbImage4; record = malloc(irecsize); if(record){ @@ -4933,7 +4960,7 @@ char *U_EMREXTTEXTOUTA_set( const U_FLOAT eyScale, const PU_EMRTEXT emrtext ){ - return(U_EMR_CORE8(U_EMR_EXTTEXTOUTA,rclBounds, iGraphicsMode, exScale, eyScale,emrtext)); + return(U_EMR_CORE8_set(U_EMR_EXTTEXTOUTA,rclBounds, iGraphicsMode, exScale, eyScale,emrtext)); } // U_EMREXTTEXTOUTW_set 84 @@ -4953,7 +4980,7 @@ char *U_EMREXTTEXTOUTW_set( const U_FLOAT eyScale, const PU_EMRTEXT emrtext ){ - return(U_EMR_CORE8(U_EMR_EXTTEXTOUTW,rclBounds, iGraphicsMode, exScale, eyScale,emrtext)); + return(U_EMR_CORE8_set(U_EMR_EXTTEXTOUTW,rclBounds, iGraphicsMode, exScale, eyScale,emrtext)); } // U_EMRPOLYBEZIER16_set 85 @@ -4969,7 +4996,7 @@ char *U_EMRPOLYBEZIER16_set( const uint32_t cpts, const U_POINT16 *points ){ - return(U_EMR_CORE6(U_EMR_POLYBEZIER16, rclBounds, cpts, points)); + return(U_EMR_CORE6_set(U_EMR_POLYBEZIER16, rclBounds, cpts, points)); } // U_EMRPOLYGON16_set 86 @@ -4985,7 +5012,7 @@ char *U_EMRPOLYGON16_set( const uint32_t cpts, const U_POINT16 *points ){ - return(U_EMR_CORE6(U_EMR_POLYGON16, rclBounds, cpts, points)); + return(U_EMR_CORE6_set(U_EMR_POLYGON16, rclBounds, cpts, points)); } // U_EMRPOLYLINE16_set 87 @@ -5001,7 +5028,7 @@ char *U_EMRPOLYLINE16_set( const uint32_t cpts, const U_POINT16 *points ){ - return(U_EMR_CORE6(U_EMR_POLYLINE16, rclBounds, cpts, points)); + return(U_EMR_CORE6_set(U_EMR_POLYLINE16, rclBounds, cpts, points)); } // U_EMRPOLYBEZIERTO16_set 88 @@ -5017,7 +5044,7 @@ char *U_EMRPOLYBEZIERTO16_set( const uint32_t cpts, const U_POINT16 *points ){ - return(U_EMR_CORE6(U_EMR_POLYBEZIERTO16, rclBounds, cpts, points)); + return(U_EMR_CORE6_set(U_EMR_POLYBEZIERTO16, rclBounds, cpts, points)); } // U_EMRPOLYLINETO16_set 89 @@ -5033,7 +5060,7 @@ char *U_EMRPOLYLINETO16_set( const uint32_t cpts, const U_POINT16 *points ){ - return(U_EMR_CORE6(U_EMR_POLYLINETO16, rclBounds, cpts, points)); + return(U_EMR_CORE6_set(U_EMR_POLYLINETO16, rclBounds, cpts, points)); } // U_EMRPOLYPOLYLINE16_set 90 @@ -5053,7 +5080,7 @@ char *U_EMRPOLYPOLYLINE16_set( const uint32_t cpts, const U_POINT16 *points ){ - return(U_EMR_CORE10(U_EMR_POLYPOLYLINE16, rclBounds, nPolys, aPolyCounts,cpts, points)); + return(U_EMR_CORE10_set(U_EMR_POLYPOLYLINE16, rclBounds, nPolys, aPolyCounts,cpts, points)); } // U_EMRPOLYPOLYGON16_set 91 @@ -5073,7 +5100,7 @@ char *U_EMRPOLYPOLYGON16_set( const uint32_t cpts, const U_POINT16 *points ){ - return(U_EMR_CORE10(U_EMR_POLYPOLYGON16, rclBounds, nPolys, aPolyCounts,cpts, points)); + return(U_EMR_CORE10_set(U_EMR_POLYPOLYGON16, rclBounds, nPolys, aPolyCounts,cpts, points)); } @@ -5098,7 +5125,7 @@ char *U_EMRPOLYDRAW16_set( if(!cpts || !aptl || !abTypes)return(NULL); cbPoints = cpts * sizeof(U_POINT16); // space for aptl - cbAbTypes = cpts; // number of abTypes (also size, 1 byte each) + cbAbTypes = cpts; // number of abTypes (same array size, 1 byte each) cbAbTypes4 = UP4(cbAbTypes); // space for abTypes irecsize = sizeof(U_EMRPOLYDRAW16) + cbPoints + cbAbTypes4 - sizeof(U_POINT16) - 1; record = malloc(irecsize); @@ -5242,7 +5269,7 @@ char *U_EMREXTCREATEPEN_set( char *U_EMRSETICMMODE_set( const uint32_t iMode ){ - return(U_EMR_CORE3(U_EMR_SETICMMODE, iMode)); + return(U_EMR_CORE3_set(U_EMR_SETICMMODE, iMode)); } // U_EMRCREATECOLORSPACE_set 99 @@ -5280,7 +5307,7 @@ char *U_EMRCREATECOLORSPACE_set( char *U_EMRSETCOLORSPACE_set( const uint32_t ihCS ){ - return(U_EMR_CORE3(U_EMR_SETCOLORSPACE, ihCS)); + return(U_EMR_CORE3_set(U_EMR_SETCOLORSPACE, ihCS)); } // U_EMRDELETECOLORSPACE_set 101 @@ -5292,7 +5319,7 @@ char *U_EMRSETCOLORSPACE_set( char *U_EMRDELETECOLORSPACE_set( const uint32_t ihCS ){ - return(U_EMR_CORE3(U_EMR_DELETECOLORSPACE, ihCS)); + return(U_EMR_CORE3_set(U_EMR_DELETECOLORSPACE, ihCS)); } // U_EMRGLSRECORD_set 102 Not implemented @@ -5428,7 +5455,7 @@ char *U_EMRALPHABLEND_set( \param iMode Mirroring Enumeration */ char *U_EMRSETLAYOUT_set(uint32_t iMode){ - return(U_EMR_CORE3(U_EMR_SETLAYOUT, iMode)); + return(U_EMR_CORE3_set(U_EMR_SETLAYOUT, iMode)); } // U_EMRTRANSPARENTBLT_set 116 diff --git a/src/libuemf/uemf.h b/src/libuemf/uemf.h index a792a65de..53426cb55 100644 --- a/src/libuemf/uemf.h +++ b/src/libuemf/uemf.h @@ -95,11 +95,11 @@ these WMF enumerations is by referencing the following table: /* File: uemf.h -Version: 0.0.27 -Date: 28-MAR-2014 +Version: 0.0.31 +Date: 23-APR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2014 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifndef _UEMF_ @@ -167,6 +167,9 @@ extern "C" { /** Solaris 8 has problems with round/roundf, just use this everywhere */ #define U_ROUND(A) ( (A) > 0 ? floor((A)+0.5) : ( (A) < 0 ? -floor(-(A)+0.5) : (A) ) ) +#define MAKE_MIN_PTR(A,B) ( A < B ? A : B) +#define IS_MEM_UNSAFE(A,B,C) ( (int8_t *)(A) > (int8_t *)(C) ? 1 : ((int8_t *)(C) - (int8_t *)(A) >= (int)(B) ? 0 : 1 )) //!< Return 1 when a region of memory starting at A of B bytes extends beyond pointer C + /** @} */ @@ -1799,7 +1802,7 @@ typedef struct { //!< In MS documentation this is Log *PU_PATTERN; //!< EMF manual 2.2.12 /** - \brief For U_LOGFONT_PANOSE elfLogFont field + \brief For U_LOGFONT elfLogFont field EMF manual 2.2.13, Microsoft name: LogFont Object */ @@ -2075,6 +2078,9 @@ typedef struct { // *********************************************************************************** // The following have U_EMR_# records. They are ordered by their record index, not by EMF manual position. +// records which are documented but not implemented +#define U_SIZE_EMRNOTIMPLEMENTED 2048 + /* Index 1 */ /** \brief The first U_ENHMETARECORD record in the metafile. @@ -2117,6 +2123,8 @@ typedef struct { U_SIZEL szlMicrometers; //!< Size of the display device in micrometer } U_EMRHEADER, *PU_EMRHEADER; //!< EMF manual 2.2.9 +#define U_SIZE_EMRHEADER sizeof(U_EMRHEADER) // modern EMF files, for _really_ old ones the _MIN size applies +#define U_SIZE_EMRHEADER_MIN (U_SIZE_EMRHEADER - sizeof(U_CBPXLFMT) - sizeof(U_OFFPXLFMT) - sizeof(uint32_t) - sizeof(U_SIZEL)) /* Index 2,3,4,5,6 */ /** EMF manual 2.3.5.16 @@ -2137,6 +2145,11 @@ typedef struct { *PU_EMRPOLYBEZIERTO, //!< EMF manual 2.3.5.18 *PU_EMRPOLYLINETO; //!< EMF manual 2.3.5.26 +#define U_SIZE_EMRPOLYBEZIER (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(U_NUM_POINTL) ) +#define U_SIZE_EMRPOLYGON U_SIZE_EMRPOLYBEZIER +#define U_SIZE_EMRPOLYLINE U_SIZE_EMRPOLYBEZIER +#define U_SIZE_EMRPOLYBEZIERTO U_SIZE_EMRPOLYBEZIER +#define U_SIZE_EMRPOLYLINETO U_SIZE_EMRPOLYBEZIER /* Index 7,8 */ /** EMF manual 2.3.5.30 @@ -2153,6 +2166,8 @@ typedef struct { U_EMRPOLYPOLYGON, //!< EMF manual 2.3.5.28 *PU_EMRPOLYPOLYLINE, //!< EMF manual 2.3.5.30 *PU_EMRPOLYPOLYGON; //!< EMF manual 2.3.5.28 +#define U_SIZE_EMRPOLYPOLYLINE (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(U_NUM_POLYCOUNTS) + sizeof(U_POLYCOUNTS)) +#define U_SIZE_EMRPOLYPOLYGON U_SIZE_EMRPOLYPOLYLINE /* Index 9,11 (numbers interleave with next one) */ /** EMF manual 2.3.11.30 @@ -2164,6 +2179,8 @@ typedef struct { U_EMRSETVIEWPORTEXTEX, //!< EMF manual manual 2.3.11.28 *PU_EMRSETWINDOWEXTEX, //!< EMF manual manual 2.3.11.30 *PU_EMRSETVIEWPORTEXTEX; //!< EMF manual manual 2.3.11.28 +#define U_SIZE_EMRSETWINDOWEXTEX (sizeof(U_EMRSETWINDOWEXTEX )) +#define U_SIZE_EMRSETVIEWPORTEXTEX (sizeof(U_EMRSETVIEWPORTEXTEX)) /* Index 10,12,13 */ /** EMF manual 2.3.11.31 @@ -2177,7 +2194,9 @@ typedef struct { *PU_EMRSETWINDOWORGEX, //!< EMF manual 2.3.11.31 *PU_EMRSETVIEWPORTORGEX, //!< EMF manual 2.3.11.29 *PU_EMRSETBRUSHORGEX; //!< EMF manual 2.3.11.12 - +#define U_SIZE_EMRSETWINDOWORGEX (sizeof(U_EMRSETWINDOWORGEX )) +#define U_SIZE_EMRSETVIEWPORTORGEX (sizeof(U_EMRSETVIEWPORTORGEX)) +#define U_SIZE_EMRSETBRUSHORGEX (sizeof(U_EMRSETBRUSHORGEX )) /* Index 14 */ /** EMF manual 3.2.4.1 @@ -2197,6 +2216,7 @@ typedef struct { U_OFFPLENTRIES offPalEntries; //!< Offset in bytes to array of palette entries } U_EMREOF, *PU_EMREOF; //!< EMF manual 3.2.4.1 +#define U_SIZE_EMREOF (sizeof(U_EMREOF)) /* Index 15 */ /** EMF manual 2.3.5.36 @@ -2207,6 +2227,7 @@ typedef struct { U_COLORREF crColor; //!< Pixel color } U_EMRSETPIXELV, *PU_EMRSETPIXELV; //!< EMF manual 2.3.5.36 +#define U_SIZE_EMRSETPIXELV (sizeof(U_EMRSETPIXELV)) /* Index 16 */ /** EMF manual 2.3.11.20 @@ -2216,6 +2237,7 @@ typedef struct { uint32_t dwFlags; //!< must be 1 } U_EMRSETMAPPERFLAGS, *PU_EMRSETMAPPERFLAGS; //!< EMF manual 2.3.11.20 +#define U_SIZE_EMRSETMAPPERFLAGS (sizeof(U_EMRSETMAPPERFLAGS)) /* Index 17,18,19,20,21,22,67,98,115 */ @@ -2243,6 +2265,16 @@ typedef struct { *PU_EMRSETICMMODE, //!< EMF manual 2.3.11.14 ICMMode Enumeration *PU_EMRSETLAYOUT; //!< EMF manual 2.3.11.17 Mirroring Enumeration +#define U_SIZE_EMRSETMAPMODE (sizeof(U_EMRSETMAPMODE )) +#define U_SIZE_EMRSETBKMODE (sizeof(U_EMRSETBKMODE )) +#define U_SIZE_EMRSETPOLYFILLMODE (sizeof(U_EMRSETPOLYFILLMODE )) +#define U_SIZE_EMRSETROP2 (sizeof(U_EMRSETROP2 )) +#define U_SIZE_EMRSETSTRETCHBLTMODE (sizeof(U_EMRSETSTRETCHBLTMODE)) +#define U_SIZE_EMRSETTEXTALIGN (sizeof(U_EMRSETTEXTALIGN )) +#define U_SIZE_EMRSELECTCLIPPATH (sizeof(U_EMRSELECTCLIPPATH )) +#define U_SIZE_EMRSETICMMODE (sizeof(U_EMRSETICMMODE )) +#define U_SIZE_EMRSETLAYOUT (sizeof(U_EMRSETLAYOUT )) + /* Index 23 */ /** EMF manual 2.3.11.13 */ @@ -2251,6 +2283,7 @@ typedef struct { U_COLORADJUSTMENT ColorAdjustment; //!< Color Adjustment } U_EMRSETCOLORADJUSTMENT, *PU_EMRSETCOLORADJUSTMENT; //!< EMF manual 2.3.11.13 +#define U_SIZE_EMRSETCOLORADJUSTMENT (sizeof(U_EMRSETCOLORADJUSTMENT)) /* Index 24, 25 */ /** EMF manual 2.3.11.26 @@ -2262,6 +2295,8 @@ typedef struct { U_EMRSETBKCOLOR, //!< EMF manual 2.3.11.10 *PU_EMRSETTEXTCOLOR, //!< EMF manual 2.3.11.26 *PU_EMRSETBKCOLOR; //!< EMF manual 2.3.11.10 +#define U_SIZE_EMRSETTEXTCOLOR (sizeof(U_EMRSETTEXTCOLOR)) +#define U_SIZE_EMRSETBKCOLOR (sizeof(U_EMRSETBKCOLOR )) /* Index 26 */ /** EMF manual 2.3.2.4 @@ -2271,6 +2306,7 @@ typedef struct { U_POINTL ptlOffset; //!< Clipping region } U_EMROFFSETCLIPRGN, *PU_EMROFFSETCLIPRGN; //!< EMF manual 2.3.2.4 +#define U_SIZE_EMROFFSETCLIPRGN (sizeof(U_EMROFFSETCLIPRGN)) /* Index 27, 54 */ /** @@ -2284,6 +2320,8 @@ typedef struct { U_EMRLINETO, //!< EMF manual 2.3.5.13 *PU_EMRMOVETOEX, //!< EMF manual 2.3.11.4 *PU_EMRLINETO; //!< EMF manual 2.3.5.13 +#define U_SIZE_EMRMOVETOEX (sizeof(U_EMRMOVETOEX)) +#define U_SIZE_EMRLINETO (sizeof(U_EMRLINETO )) /* Index 28,33,52,59,60,61,65,66,68 */ /** EMF manual 2.3.2 @@ -2309,6 +2347,15 @@ typedef struct { *PU_EMRFLATTENPATH, //!< EMF manual 2.3.10 *PU_EMRWIDENPATH, //!< EMF manual 2.3.10 *PU_EMRABORTPATH; //!< EMF manual 2.3.10 +#define U_SIZE_EMRSETMETARGN (sizeof(U_EMRSETMETARGN )) +#define U_SIZE_EMRSAVEDC (sizeof(U_EMRSAVEDC )) +#define U_SIZE_EMRREALIZEPALETTE (sizeof(U_EMRREALIZEPALETTE)) +#define U_SIZE_EMRBEGINPATH (sizeof(U_EMRBEGINPATH )) +#define U_SIZE_EMRENDPATH (sizeof(U_EMRENDPATH )) +#define U_SIZE_EMRCLOSEFIGURE (sizeof(U_EMRCLOSEFIGURE )) +#define U_SIZE_EMRFLATTENPATH (sizeof(U_EMRFLATTENPATH )) +#define U_SIZE_EMRWIDENPATH (sizeof(U_EMRWIDENPATH )) +#define U_SIZE_EMRABORTPATH (sizeof(U_EMRABORTPATH )) /* Index 29,30 */ /** EMF manual 2.3.2.1 @@ -2320,6 +2367,8 @@ typedef struct { U_EMRINTERSECTCLIPRECT, //!< EMF manual 2.3.2.3 *PU_EMREXCLUDECLIPRECT, //!< EMF manual 2.3.2.1 *PU_EMRINTERSECTCLIPRECT; //!< EMF manual 2.3.2.3 +#define U_SIZE_EMREXCLUDECLIPRECT (sizeof(U_EMREXCLUDECLIPRECT )) +#define U_SIZE_EMRINTERSECTCLIPRECT (sizeof(U_EMRINTERSECTCLIPRECT )) /* Index 31,32 */ /** EMF manual 2.3.11.7 @@ -2334,6 +2383,8 @@ typedef struct { U_EMRSCALEWINDOWEXTEX, //!< EMF manual 2.3.11.8 *PU_EMRSCALEVIEWPORTEXTEX, //!< EMF manual 2.3.11.7 *PU_EMRSCALEWINDOWEXTEX; //!< EMF manual 2.3.11.8 +#define U_SIZE_EMRSCALEVIEWPORTEXTEX (sizeof(U_EMRSCALEVIEWPORTEXTEX)) +#define U_SIZE_EMRSCALEWINDOWEXTEX (sizeof(U_EMRSCALEWINDOWEXTEX )) /* Index 33 (see 28) */ @@ -2345,6 +2396,7 @@ typedef struct { int32_t iRelative; //!< DC to restore. -1 is preceding } U_EMRRESTOREDC, *PU_EMRRESTOREDC; //!< EMF manual 2.3.11.6 +#define U_SIZE_EMRRESTOREDC (sizeof(U_EMRRESTOREDC)) /* Index 35 */ /** EMF manual 2.3.12.2 @@ -2354,6 +2406,7 @@ typedef struct { U_XFORM xform; //!< Transform } U_EMRSETWORLDTRANSFORM, *PU_EMRSETWORLDTRANSFORM; //!< EMF manual 2.3.12.2 +#define U_SIZE_EMRSETWORLDTRANSFORM (sizeof(U_EMRSETWORLDTRANSFORM)) /* Index 36 */ /** EMF manual 2.3.12.1 @@ -2364,6 +2417,7 @@ typedef struct { uint32_t iMode; //!< ModifyWorldTransformMode Enumeration } U_EMRMODIFYWORLDTRANSFORM, *PU_EMRMODIFYWORLDTRANSFORM; //!< EMF manual 2.3.12.1 +#define U_SIZE_EMRMODIFYWORLDTRANSFORM (sizeof(U_EMRMODIFYWORLDTRANSFORM)) /* Index 37,40 */ /** EMF manual 2.3.8.3 @@ -2375,6 +2429,8 @@ typedef struct { U_EMRSELECTOBJECT, //!< EMF manual 2.3.8.5 *PU_EMRDELETEOBJECT, //!< EMF manual 2.3.8.3 *PU_EMRSELECTOBJECT; //!< EMF manual 2.3.8.5 +#define U_SIZE_EMRDELETEOBJECT (sizeof(U_EMRDELETEOBJECT)) +#define U_SIZE_EMRSELECTOBJECT (sizeof(U_EMRSELECTOBJECT)) /* Index 38 */ /** EMF manual 2.3.7.7 @@ -2385,6 +2441,7 @@ typedef struct { U_LOGPEN lopn; //!< Pen properties } U_EMRCREATEPEN, *PU_EMRCREATEPEN; //!< EMF manual 2.3.7.7 +#define U_SIZE_EMRCREATEPEN (sizeof(U_EMRCREATEPEN)) /* Index 39 */ /** EMF manual 2.3.7.1 @@ -2395,6 +2452,7 @@ typedef struct { U_LOGBRUSH lb; //!< Brush properties } U_EMRCREATEBRUSHINDIRECT, *PU_EMRCREATEBRUSHINDIRECT; //!< EMF manual 2.3.7.1 +#define U_SIZE_EMRCREATEBRUSHINDIRECT (sizeof(U_EMRCREATEBRUSHINDIRECT)) /* Index 40 see 37 */ @@ -2409,6 +2467,7 @@ typedef struct { U_FLOAT eSweepAngle; //!< Sweep angle in degrees } U_EMRANGLEARC, *PU_EMRANGLEARC; //!< EMF manual 2.3.5.1 +#define U_SIZE_EMRANGLEARC (sizeof(U_EMRANGLEARC)) /* Index 42,43 */ /** EMF manual 2.3.5.5 @@ -2420,6 +2479,8 @@ typedef struct { U_EMRRECTANGLE, //!< EMF manual 2.3.5.5 *PU_EMRELLIPSE, //!< EMF manual 2.3.5.5 *PU_EMRRECTANGLE; //!< EMF manual 2.3.5.34 +#define U_SIZE_EMRELLIPSE (sizeof(U_EMRELLIPSE )) +#define U_SIZE_EMRRECTANGLE (sizeof(U_EMRRECTANGLE)) /* Index 44 */ /** EMF manual 2.3.5.35 @@ -2430,6 +2491,7 @@ typedef struct { U_SIZEL szlCorner; //!< W & H in logical units of ellipse used to round corner } U_EMRROUNDRECT, *PU_EMRROUNDRECT; //!< EMF manual 2.3.5.35 +#define U_SIZE_EMRROUNDRECT (sizeof(U_EMRROUNDRECT)) /* Index 45, 46 ,47, 55 */ /** EMF manual 2.3.5.2 @@ -2447,6 +2509,10 @@ typedef struct { *PU_EMRCHORD, //!< EMF manual 2.3.5.4 *PU_EMRPIE, //!< EMF manual 2.3.5.15 *PU_EMRARCTO; //!< EMF manual 2.3.5.3 +#define U_SIZE_EMRARC (sizeof(U_EMRARC )) +#define U_SIZE_EMRCHORD (sizeof(U_EMRCHORD)) +#define U_SIZE_EMRPIE (sizeof(U_EMRPIE )) +#define U_SIZE_EMRARCTO (sizeof(U_EMRARCTO)) /* Index 48 */ /** EMF manual 2.3.8.6 @@ -2456,6 +2522,7 @@ typedef struct { uint32_t ihPal; //!< Index of a Palette object in the EMF object table } U_EMRSELECTPALETTE, *PU_EMRSELECTPALETTE; //!< EMF manual 2.3.8.6 +#define U_SIZE_EMRSELECTPALETTE (sizeof(U_EMRSELECTPALETTE)) /* Index 49 */ /** EMF manual 2.3.7.6 @@ -2466,6 +2533,7 @@ typedef struct { U_LOGPALETTE lgpl; //!< Palette properties } U_EMRCREATEPALETTE, *PU_EMRCREATEPALETTE; //!< EMF manual 2.3.7.6 +#define U_SIZE_EMRCREATEPALETTE (sizeof(U_EMRCREATEPALETTE)) /* Index 50 */ /** EMF manual 2.3.8.8 @@ -2478,6 +2546,7 @@ typedef struct { U_LOGPLTNTRY aPalEntries[1]; //!< Values to set with } U_EMRSETPALETTEENTRIES, *PU_EMRSETPALETTEENTRIES; //!< EMF manual 2.3.8.8 +#define U_SIZE_EMRSETPALETTEENTRIES (sizeof(U_EMR) + 2*sizeof(uint32_t) + sizeof(U_NUM_LOGPLTNTRY)) /* Index 51 */ /** EMF manual 2.3.8.4 @@ -2488,6 +2557,7 @@ typedef struct { uint32_t cEntries; //!< Number to expand or truncate the Palette entry list to. } U_EMRRESIZEPALETTE, *PU_EMRRESIZEPALETTE; //!< EMF manual 2.3.8.4 +#define U_SIZE_EMRRESIZEPALETTE (sizeof(U_EMRRESIZEPALETTE)) /* Index 52 (see 28) */ @@ -2501,22 +2571,26 @@ typedef struct { uint32_t iMode; //!< FloodFill Enumeration } U_EMREXTFLOODFILL, *PU_EMREXTFLOODFILL; //!< EMF manual 2.3.5.6 +#define U_SIZE_EMREXTFLOODFILL (sizeof(U_EMREXTFLOODFILL)) /* Index 54 (see 27) */ /* Index 55 (see 45) */ /* Index 56 */ -/** EMF manual 2.3.5.20 +/** EMF manual 2.3.5.20 + + followed by + uint8_t abTypes[1]; //!< Array of Point Enumeration */ typedef struct { U_EMR emr; //!< U_EMR U_RECTL rclBounds; //!< Bounding rectangle in device units U_NUM_POINTL cptl; //!< Number of U_POINTL objects U_POINTL aptl[1]; //!< Array of U_POINTL objects - uint8_t abTypes[1]; //!< Array of Point Enumeration } U_EMRPOLYDRAW, *PU_EMRPOLYDRAW; //!< EMF manual 2.3.5.20 +#define U_SIZE_EMRPOLYDRAW (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(U_NUM_POINTL)) /* Index 57 */ /** EMF manual 2.3.11.9 @@ -2526,6 +2600,7 @@ typedef struct { uint32_t iArcDirection; //!< ArcDirection Enumeration } U_EMRSETARCDIRECTION, *PU_EMRSETARCDIRECTION; //!< EMF manual 2.3.11.9 +#define U_SIZE_EMRSETARCDIRECTION (sizeof(U_EMRSETARCDIRECTION)) /* Index 58 */ /** EMF manual 2.3.11.21 @@ -2538,6 +2613,7 @@ typedef struct { uint32_t eMiterLimit; //!< Miter limit (max value of mitered length / line width) } U_EMRSETMITERLIMIT, *PU_EMRSETMITERLIMIT; //!< EMF manual 2.3.11.21 +#define U_SIZE_EMRSETMITERLIMIT (sizeof(U_EMRSETMITERLIMIT)) /* Index 59,60,61 (see 28) */ @@ -2553,6 +2629,9 @@ typedef struct { *PU_EMRFILLPATH, //!< EMF manual 2.3.5.9 *PU_EMRSTROKEANDFILLPATH, //!< EMF manual 2.3.5.38 *PU_EMRSTROKEPATH; //!< EMF manual 2.3.5.39 +#define U_SIZE_EMRFILLPATH (sizeof(U_EMRFILLPATH )) +#define U_SIZE_EMRSTROKEANDFILLPATH (sizeof(U_EMRSTROKEANDFILLPATH)) +#define U_SIZE_EMRSTROKEPATH (sizeof(U_EMRSTROKEPATH )) /* Index 65,66 (see 28) */ /* Index 67 (see 17) */ @@ -2569,6 +2648,7 @@ typedef struct { uint8_t Data[1]; //!< Comment (any binary data, interpretation is program specific) } U_EMRCOMMENT, *PU_EMRCOMMENT; //!< EMF manual 2.3.3.1, AKA GDICOMMENT +#define U_SIZE_EMRCOMMENT (sizeof(U_EMR) + sizeof(U_CBDATA)) /* variant comment types */ /** EMF manual 2.3.3.2 @@ -2580,6 +2660,7 @@ typedef struct { uint8_t Data[1]; //!< EMF Plus record } U_EMRCOMMENT_EMFPLUS, *PU_EMRCOMMENT_EMFPLUS; //!< EMF manual 2.3.3.2, EMF Plus comment +#define U_SIZE_EMRCOMMENT_EMFPLUS (sizeof(U_EMR) + sizeof(U_CBDATA) + sizeof(uint32_t)) /** EMF manual 2.3.3.3 */ @@ -2591,6 +2672,7 @@ typedef struct { uint8_t Data[1]; //!< EMF Spool records } U_EMRCOMMENT_SPOOL, *PU_EMRCOMMENT_SPOOL; //!< EMF manual 2.3.3.3, EMF Spool comment +#define U_SIZE_EMRCOMMENT_SPOOL (sizeof(U_EMR) + sizeof(U_CBDATA) + 2*sizeof(uint32_t)) /** EMF manual 2.3.3.4 */ @@ -2602,9 +2684,11 @@ typedef struct { uint8_t Data[1]; //!< Public comment data } U_EMRCOMMENT_PUBLIC, *PU_EMRCOMMENT_PUBLIC; //!< EMF manual 2.3.3.4, EMF Public comment +#define U_SIZE_EMRCOMMENT_PUBLIC (sizeof(U_EMR) + sizeof(U_CBDATA) + 2*sizeof(uint32_t)) /* Index 71 */ -/** EMF manual 2.3.5.10 +/** EMF manual 2.3.5.10 + followed by a variable number of U_RECTLs */ typedef struct { U_EMR emr; //!< U_EMR @@ -2614,6 +2698,7 @@ typedef struct { U_RGNDATA RgnData[1]; //!< Variable size U_RGNDATA structure } U_EMRFILLRGN, *PU_EMRFILLRGN; //!< EMF manual 2.3.5.10 +#define U_SIZE_EMRFILLRGN (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(U_CBRGNDATA) + sizeof(uint32_t)) /* Index 72 */ /** EMF manual 2.3.5.11 @@ -2627,6 +2712,7 @@ typedef struct { U_RGNDATA RgnData[1]; //!< Variable size U_RGNDATA structure } U_EMRFRAMERGN, *PU_EMRFRAMERGN; //!< EMF manual 2.3.5.11 +#define U_SIZE_EMRFRAMERGN (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(U_CBRGNDATA) + sizeof(uint32_t) + sizeof(U_SIZEL)) /* Index 73,74 */ /** EMF manual 2.3.11.3 @@ -2640,6 +2726,8 @@ typedef struct { U_EMRPAINTRGN, //!< EMF manual 2.3.5.14 *PU_EMRINVERTRGN, //!< EMF manual 2.3.11.3 *PU_EMRPAINTRGN; //!< EMF manual 2.3.5.14 +#define U_SIZE_EMRINVERTRGN (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(U_CBRGNDATA)) +#define U_SIZE_EMRPAINTRGN U_SIZE_EMRINVERTRGN /* Index 75 */ /** EMF manual 2.3.2.2 @@ -2651,6 +2739,7 @@ typedef struct { U_RGNDATA RgnData[1]; //!< Variable size U_RGNDATA structure } U_EMREXTSELECTCLIPRGN, *PU_EMREXTSELECTCLIPRGN; //!< EMF manual 2.3.2.2 +#define U_SIZE_EMREXTSELECTCLIPRGN (sizeof(U_EMR) + sizeof(U_CBRGNDATA) + sizeof(uint32_t)) /* Index 76 */ /** EMF manual 2.3.1.2 @@ -2672,6 +2761,7 @@ typedef struct { //!< Record may include optional bitmapbuffer } U_EMRBITBLT, *PU_EMRBITBLT; //!< EMF manual 2.3.1.2 +#define U_SIZE_EMRBITBLT (sizeof(U_EMRBITBLT)) /* Index 77 */ /** EMF manual 2.3.1.6 @@ -2694,6 +2784,7 @@ typedef struct { //!< Record may include optional bitmapbuffer } U_EMRSTRETCHBLT, *PU_EMRSTRETCHBLT; //!< EMF manual 2.3.1.6 +#define U_SIZE_EMRSTRETCHBLT (sizeof(U_EMRSTRETCHBLT)) /* Index 78 */ /** EMF manual 2.3.1.3 @@ -2721,6 +2812,7 @@ typedef struct { //!< Record may include optional Source and mask bitmapbuffers } U_EMRMASKBLT, *PU_EMRMASKBLT; //!< EMF manual 2.3.1.3 +#define U_SIZE_EMRMASKBLT (sizeof(U_EMRMASKBLT)) /* Index 79 */ /** EMF manual 2.3.1.4 @@ -2747,6 +2839,7 @@ typedef struct { //!< Record may include optional Source and mask bitmapbuffers } U_EMRPLGBLT, *PU_EMRPLGBLT; //!< EMF manual 2.3.1.4 +#define U_SIZE_EMRPLGBLT (sizeof(U_EMRPLGBLT)) /* Index 80 */ /** EMF manual 2.3.1.5 @@ -2767,6 +2860,7 @@ typedef struct { //!< Record may includes optional bitmapbuffer } U_EMRSETDIBITSTODEVICE, *PU_EMRSETDIBITSTODEVICE; //!< EMF manual 2.3.1.5 +#define U_SIZE_EMRSETDIBITSTODEVICE (sizeof(U_EMRSETDIBITSTODEVICE)) /* Index 81 */ /** EMF manual 2.3.1.7 @@ -2787,6 +2881,7 @@ typedef struct { //!< Record may includes optional bitmapbuffer } U_EMRSTRETCHDIBITS, *PU_EMRSTRETCHDIBITS; //!< EMF manual 2.3.1.7 +#define U_SIZE_EMRSTRETCHDIBITS (sizeof(U_EMRSTRETCHDIBITS)) /* Index 82 */ /** EMF manual 2.3.7.8 @@ -2797,6 +2892,8 @@ typedef struct { U_LOGFONT_PANOSE elfw; //!< Font parameters, either U_LOGFONT or U_LOGFONT_PANOSE, the latter is bigger so use that type here } U_EMREXTCREATEFONTINDIRECTW, *PU_EMREXTCREATEFONTINDIRECTW; //!< EMF manual 2.3.7.8 +#define U_SIZE_EMREXTCREATEFONTINDIRECTW_LOGFONT_PANOSE (sizeof(U_EMR) + 4 + sizeof(U_LOGFONT_PANOSE)) +#define U_SIZE_EMREXTCREATEFONTINDIRECTW_LOGFONT (sizeof(U_EMR) + 4 + sizeof(U_LOGFONT)) /* Index 83,84 */ /** EMF manual 2.3.5.7 @@ -2820,6 +2917,8 @@ typedef struct { U_EMREXTTEXTOUTW, //!< EMF manual 2.3.5.8 *PU_EMREXTTEXTOUTA, //!< EMF manual 2.3.5.7 *PU_EMREXTTEXTOUTW; //!< EMF manual 2.3.5.8 +#define U_SIZE_EMREXTTEXTOUTA (sizeof(U_EMREXTTEXTOUTA)) +#define U_SIZE_EMREXTTEXTOUTW (sizeof(U_EMREXTTEXTOUTW)) /* Index 85,86,87,88,89 */ /** EMF manual 2.3.5.17 @@ -2839,9 +2938,16 @@ typedef struct { *PU_EMRPOLYLINE16, //!< EMF manual 2.3.5.25 *PU_EMRPOLYBEZIERTO16, //!< EMF manual 2.3.5.19 *PU_EMRPOLYLINETO16; //!< EMF manual 2.3.5.27 - +#define U_SIZE_EMRPOLYBEZIER16 (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(U_NUM_POINT16)) +#define U_SIZE_EMRPOLYGON16 U_SIZE_EMRPOLYBEZIER16 +#define U_SIZE_EMRPOLYLINE16 U_SIZE_EMRPOLYBEZIER16 +#define U_SIZE_EMRPOLYBEZIERTO16 U_SIZE_EMRPOLYBEZIER16 +#define U_SIZE_EMRPOLYLINETO16 U_SIZE_EMRPOLYBEZIER16 /* Index 90,91 */ -/** EMF manual 2.3.5.31 +/** EMF manual 2.3.5.31 + + followed by + U_POINT16 apts[1]; //!< array of point16 */ typedef struct { U_EMR emr; //!< U_EMR @@ -2849,24 +2955,28 @@ typedef struct { U_NUM_POLYCOUNTS nPolys; //!< Number of elements in aPolyCounts U_NUM_POINT16 cpts; //!< Total number of points (over all poly) U_POLYCOUNTS aPolyCounts[1]; //!< Number of points in each poly (sequential) -// This will appear somewhere but is not really part of the core structure. -// U_POINT16 apts[1]; //!< array of point16 } U_EMRPOLYPOLYLINE16, U_EMRPOLYPOLYGON16, //!< EMF manual 2.3.5.29 *PU_EMRPOLYPOLYLINE16, //!< EMF manual 2.3.5.31 *PU_EMRPOLYPOLYGON16; //!< EMF manual 2.3.5.29 +#define U_SIZE_EMRPOLYPOLYLINE16 (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(U_NUM_POLYCOUNTS) + sizeof(U_NUM_POINT16)) +#define U_SIZE_EMRPOLYPOLYGON16 U_SIZE_EMRPOLYPOLYLINE16 /* Index 92 */ -/** EMF manual 2.3.5.21 +/** EMF manual 2.3.5.21 + + followed by + uint8_t abTypes[1]; //!< Array of Point Enumeration + */ typedef struct { U_EMR emr; //!< U_EMR U_RECTL rclBounds; //!< Bounding rectangle in device units U_NUM_POINT16 cpts; //!< Total number of points (over all poly) U_POINT16 apts[1]; //!< array of points - uint8_t abTypes[1]; //!< Array of Point Enumeration } U_EMRPOLYDRAW16, *PU_EMRPOLYDRAW16; //!< EMF manual 2.3.5.21 +#define U_SIZE_EMRPOLYDRAW16 (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(U_NUM_POINT16)) /* Index 93 */ /** EMF manual 2.3.7.5 @@ -2882,6 +2992,7 @@ typedef struct { //!< Record may include optional DIB bitmapbuffer } U_EMRCREATEMONOBRUSH, *PU_EMRCREATEMONOBRUSH; //!< EMF manual 2.3.7.5 +#define U_SIZE_EMRCREATEMONOBRUSH (sizeof(U_EMRCREATEMONOBRUSH)) /* Index 94 */ /** EMF manual 2.3.7.4 @@ -2897,6 +3008,7 @@ typedef struct { //!< Record may include optional DIB bitmapbuffer } U_EMRCREATEDIBPATTERNBRUSHPT, *PU_EMRCREATEDIBPATTERNBRUSHPT; //!< EMF manual 2.3.7.4 +#define U_SIZE_EMRCREATEDIBPATTERNBRUSHPT (sizeof(U_EMRCREATEDIBPATTERNBRUSHPT)) /* Index 95 */ /** EMF manual 2.3.7.9 @@ -2912,6 +3024,7 @@ typedef struct { //!< Record may include optional DIB bitmap } U_EMREXTCREATEPEN, *PU_EMREXTCREATEPEN; //!< EMF manual 2.3.7.9 +#define U_SIZE_EMREXTCREATEPEN (sizeof(U_EMREXTCREATEPEN)) /* Index 96.97 */ /** EMF manual 2.3.5.32 @@ -2928,6 +3041,8 @@ typedef struct { U_EMRPOLYTEXTOUTW, //!< EMF manual 2.3.5.33 *PU_EMRPOLYTEXTOUTA, //!< EMF manual 2.3.5.32 *PU_EMRPOLYTEXTOUTW; //!< EMF manual 2.3.5.33 +#define U_SIZE_EMRPOLYTEXTOUTA (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(uint32_t) + 2*sizeof(U_FLOAT) + sizeof(U_NUM_EMRTEXT)) +#define U_SIZE_EMRPOLYTEXTOUTW U_SIZE_EMRPOLYTEXTOUTA /* Index 98 (see 17) */ @@ -2940,6 +3055,7 @@ typedef struct { U_LOGCOLORSPACEA lcs; //!< ColorSpace parameters } U_EMRCREATECOLORSPACE, *PU_EMRCREATECOLORSPACE; //!< EMF manual 2.3.7.2 +#define U_SIZE_EMRCREATECOLORSPACE (sizeof(U_EMRCREATECOLORSPACE)) /* Index 100,101 */ /** EMF manual 2.3.8.2 @@ -2951,6 +3067,8 @@ typedef struct { U_EMRSETCOLORSPACE, //!< EMF manual 2.3.8.7 *PU_EMRDELETECOLORSPACE, //!< EMF manual 2.3.8.2 *PU_EMRSETCOLORSPACE; //!< EMF manual 2.3.8.7 +#define U_SIZE_EMRDELETECOLORSPACE (sizeof(U_EMRDELETECOLORSPACE)) +#define U_SIZE_EMRSETCOLORSPACE (sizeof(U_EMRSETCOLORSPACE )) /* Index 102 */ /** EMF manual 2.3.9.2 @@ -2961,6 +3079,7 @@ typedef struct { U_DATA Data[1]; //!< OpenGL data } U_EMRGLSRECORD, *PU_EMRGLSRECORD; //!< EMF manual 2.3.9.2 +#define U_SIZE_EMRGLSRECORD (sizeof(U_EMRGLSRECORD)) /* Index 103 */ /** EMF manual 2.3.9.1 @@ -2972,6 +3091,7 @@ typedef struct { U_DATA Data[1]; //!< OpenGL data } U_EMRGLSBOUNDEDRECORD, *PU_EMRGLSBOUNDEDRECORD; //!< EMF manual 2.3.9.1 +#define U_SIZE_EMRGLSBOUNDEDRECORD (sizeof(U_EMR) + sizeof(U_RECTL) + sizeof(U_CBDATA)) /* Index 104 */ /** EMF manual 2.3.11.5 @@ -2981,6 +3101,7 @@ typedef struct { U_PIXELFORMATDESCRIPTOR pfd; //!< PixelFormatDescriptor } U_EMRPIXELFORMAT, *PU_EMRPIXELFORMAT; //!< EMF manual 2.3.11.5 +#define U_SIZE_EMRPIXELFORMAT (sizeof(U_EMRPIXELFORMAT)) /* Index 105 */ /** EMF manual 2.3.6.1 @@ -2991,6 +3112,7 @@ typedef struct { U_DATA Data[1]; //!< Data to send } U_EMRDRAWESCAPE, *PU_EMRDRAWESCAPE; //!< EMF manual 2.3.6.1 +#define U_SIZE_EMRDRAWESCAPE (sizeof(U_EMR) + sizeof(U_CBDATA)) /* Index 106 */ /** EMF manual 2.3.6.2 @@ -3001,6 +3123,7 @@ typedef struct { U_DATA Data[1]; //!< Data to send } U_EMREXTESCAPE, *PU_EMREXTESCAPE; //!< EMF manual 2.3.6.2 +#define U_SIZE_EMREXTESCAPE (sizeof(U_EMR) + sizeof(U_CBDATA)) /* Index 107 (not implemented ) */ @@ -3020,22 +3143,26 @@ typedef struct { //!< uint32_t TextString; text to output (fuOptions & ETO_SMALL_CHARS ? 8 bit : 16 bit) } U_EMRSMALLTEXTOUT, *PU_EMRSMALLTEXTOUT; //!< EMF manual 2.3.5.37 +#define U_SIZE_EMRSMALLTEXTOUT (sizeof(U_EMRSMALLTEXTOUT)) /* Index 109 (not implemented ) EMF manual 2.3.11.2 */ /* Index 110 */ -/** EMF manual 2.3.6.3 +/** EMF manual 2.3.6.3 + + followed by + uint8_t Data[1]; //!< Data for printer driver */ typedef struct { U_EMR emr; //!< U_EMR U_CBDATA cbDriver; //!< Number of bytes in driver name (note, BYTES, not CHARACTERS) U_CBDATA cbData; //!< Number of bytes in data uint16_t Driver[1]; //!< Driver name in uint16_t characters, null terminated - uint8_t Data[1]; //!< Data for printer driver } U_EMRNAMEDESCAPE, *PU_EMRNAMEDESCAPE; //!< EMF manual 2.3.6.3 +#define U_SIZE_EMRNAMEDESCAPE (sizeof(U_EMRNAMEDESCAPE)) /* Index 111-113 (not implemented ) EMF manual 2.3.8.1 @@ -3064,6 +3191,7 @@ typedef struct { //!< Record may include optional DIB bitmap } U_EMRALPHABLEND, *PU_EMRALPHABLEND; //!< EMF manual 2.3.1.1 +#define U_SIZE_EMRALPHABLEND (sizeof(U_EMRALPHABLEND)) /* Index 115 (see 17) */ @@ -3088,11 +3216,16 @@ typedef struct { //!< Record may includes optional bitmapbuffer } U_EMRTRANSPARENTBLT, *PU_EMRTRANSPARENTBLT; //!< EMF manual 2.3.1.8 +#define U_SIZE_EMRTRANSPARENTBLT (sizeof(U_EMRTRANSPARENTBLT)) /* Index 117 (not a defined U_EMR record type ) */ /* Index 118 */ -/** EMF manual 2.3.5.12 +/** EMF manual 2.3.5.12 + + followed by + U_TRIVERTEX TriVert[1]; Array of TriVertex objects + uint32_t GradObj[1]; Array of gradient objects (each has 2 or 3 indices into TriVert array) */ typedef struct { U_EMR emr; //!< U_EMR @@ -3100,11 +3233,9 @@ typedef struct { U_NUM_TRIVERTEX nTriVert; //!< Number of TriVertex objects U_NUM_GRADOBJ nGradObj; //!< Number of gradient triangle/rectangle objects uint32_t ulMode; //!< Gradientfill Enumeration (determines Triangle/Rectangle) -//parts that are required but which are not included in the core structure -// U_TRIVERTEX TriVert[1]; Array of TriVertex objects -// uint32_t GradObj[1]; Array of gradient objects (each has 2 or 3 indices into TriVert array) } U_EMRGRADIENTFILL, *PU_EMRGRADIENTFILL; //!< EMF manual 2.3.5.12 +#define U_SIZE_EMRGRADIENTFILL (sizeof(U_EMRGRADIENTFILL)) /* Index 119,120 (not implemented ) EMF manual 2.3.11.18 @@ -3123,6 +3254,7 @@ typedef struct { uint8_t Data[1]; //!< Data of size cbName+cbData: Name in UTF16 then color profile data } U_EMRCOLORMATCHTOTARGETW, *PU_EMRCOLORMATCHTOTARGETW; //!< EMF manual 2.3.11.1 +#define U_SIZE_EMRCOLORMATCHTOTARGETW (sizeof(U_EMR) + 2*sizeof(uint32_t) + sizeof(U_CBNAME) + sizeof(U_CBDATA)) /* Index 122 */ /** EMF manual 2.3.7.3 @@ -3136,6 +3268,10 @@ typedef struct { uint8_t Data[1]; //!< (Optional, dwFlags & 1) color profile data } U_EMRCREATECOLORSPACEW, *PU_EMRCREATECOLORSPACEW; //!< EMF manual 2.3.7.3 +#define U_SIZE_EMRCREATECOLORSPACEW (sizeof(U_EMR) + 2*sizeof(uint32_t) + sizeof(U_LOGCOLORSPACEW) + sizeof(U_CBDATA)) + +// records which are not documented, so we have no idea what to do with them +#define U_SIZE_EMRUNDEFINED 2048 // ************************************************************************************************ // Utility function structures @@ -3207,7 +3343,7 @@ int get_real_color_count(const char *Bmih); int get_real_color_icount(int Colors, int BitCount, int Width, int Height); int RGBA_to_DIB(char **px, uint32_t *cbPx, PU_RGBQUAD *ct, int *numCt, const char *rgba_px, int w, int h, int stride, uint32_t colortype, int use_ct, int invert); -int get_DIB_params( void *pEmr, uint32_t offBitsSrc, uint32_t offBmiSrc, +int get_DIB_params( const char *record, uint32_t offBitsSrc, uint32_t offBmiSrc, const char **px, const U_RGBQUAD **ct, uint32_t *numCt, uint32_t *width, uint32_t *height, uint32_t *colortype, uint32_t *invert ); int DIB_to_RGBA(const char *px, const U_RGBQUAD *ct, int numCt, @@ -3237,6 +3373,7 @@ int emf_htable_free(EMFHANDLES **eht); #define htable_free emf_htable_free U_RECTL rectl_set(U_POINTL ul, U_POINTL lr); +void rectli_set(PU_RECTL array, int index, U_POINTL ul, U_POINTL lr); U_SIZEL sizel_set(int32_t x, int32_t y); U_POINTL point32_set(int32_t x, int32_t y); #define point_set point32_set @@ -3463,6 +3600,7 @@ char *U_EMRSMALLTEXTOUT_set(const U_POINTL Dest, const U_NUM_STR cChars, const u // U_EMRSETICMPROFILEA_set 112 Not implemented // U_EMRSETICMPROFILEW_set 113 Not implemented + char *U_EMRALPHABLEND_set(const U_RECTL rclBounds, const U_POINTL Dest, const U_POINTL cDest, const U_POINTL Src, const U_POINTL cSrc, const U_XFORM xformSrc, const U_COLORREF crBkColorSrc, const uint32_t iUsageSrc, diff --git a/src/libuemf/uemf_endian.c b/src/libuemf/uemf_endian.c index 2d19361e1..f746553f1 100644 --- a/src/libuemf/uemf_endian.c +++ b/src/libuemf/uemf_endian.c @@ -19,11 +19,11 @@ /* File: uemf_endian.c -Version: 0.0.16 -Date: 27-MAR-2014 +Version: 0.0.21 +Date: 23-APR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2014 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifdef __cplusplus @@ -266,18 +266,91 @@ void bitmapinfoheader_swap( \param Bmi Pointer to a U_BITMAPINFO object */ void bitmapinfo_swap( - PU_BITMAPINFO Bmi + const char *Bmi ){ - bitmapinfoheader_swap(&(Bmi->bmiHeader)); // bmIHeader + PU_BITMAPINFO pBmi = (PU_BITMAPINFO)Bmi; + bitmapinfoheader_swap(&(pBmi->bmiHeader)); // bmIHeader // ordered bytes: bmiColors } +/** + \brief Swap the ordered bytes in a DIB and verify that the sizes are OK + + \return 1 on success, 0 on failure + \param record EMF record that contains a DIB pixel array + \param iUsage DIBcolors Enumeration + \param offBmi offset from the start of the record to the start of the bitmapinfo structure + \param cbBmi declared space for the bitmapinfo structure in the record + \param offBits offset from the start of the record to the start of the bitmap + \param cbBits declared space for the bitmap in the record (amount used may be less than this) + \param blimit one byte past the end of the record. + \param torev 1 for native to reversed, 0 for reversed to native + + This method can only test DIBs that hold Microsoft's various bitmap types. PNG or JPG is just a bag + of bytes, and there is no possible way to derive from the known width and height how big it should be. +*/ +int DIB_swap( + const char *record, + uint32_t iUsage, + uint32_t offBmi, + uint32_t cbBmi, + uint32_t offBits, + uint32_t cbBits, + const char *blimit, + int torev + ){ + int dibparams = U_BI_UNKNOWN; // type of image not yet determined + const char *px = NULL; // DIB pixels + const U_RGBQUAD *ct = NULL; // DIB color table + int bs; + int usedbytes; + + if(!cbBmi)return(1); // No DIB in a record where it is optional + if(IS_MEM_UNSAFE(record, offBmi + cbBmi, blimit))return(0); + if(cbBits && IS_MEM_UNSAFE(record, offBits + cbBits, blimit))return(0); + if(iUsage == U_DIB_RGB_COLORS){ + uint32_t width, height, colortype, numCt, invert; // these values will be set in get_DIB_params + // next call returns pointers and values, but allocates no memory + if(torev){ + dibparams = get_DIB_params(record, offBits, offBmi, &px, (const U_RGBQUAD **) &ct, + &numCt, &width, &height, &colortype, &invert); + } + bitmapinfo_swap(record + offBmi); // byte ordered fields in bitmapinfo + if(!torev){ + dibparams = get_DIB_params(record, offBits, offBmi, &px, (const U_RGBQUAD **) &ct, + &numCt, &width, &height, &colortype, &invert); + } + + // sanity checking + if(numCt && colortype >= U_BCBM_COLOR16)return(0); //color tables not used above 16 bit pixels + if(!numCt && colortype < U_BCBM_COLOR16)return(0); //color tables mandatory for < 16 bit + + if(dibparams ==U_BI_RGB){ + // this is the only DIB type where we can calculate how big it should be when stored in the EMF file + bs = colortype/8; + if(bs<1){ + usedbytes = (width*colortype + 7)/8; // width of line in fully and partially occupied bytes + } + else { + usedbytes = width*bs; + } + if(IS_MEM_UNSAFE(record+offBits, usedbytes, blimit))return(0); + } + } + else { + bitmapinfo_swap(record + offBmi); + } + return(1); +} + /** \brief Convert a pointer to a U_EXTLOGPEN object. - \param elp PU_EXTLOGPEN object + \param elp PU_EXTLOGPEN object + \param blimit one byte past the end of the record */ -void extlogpen_swap( +int extlogpen_swap( PU_EXTLOGPEN elp, + const char *blimit, int torev ){ int count=0; @@ -290,7 +363,9 @@ void extlogpen_swap( if(!torev){ count = elp->elpNumEntries; } + if(IS_MEM_UNSAFE(&(elp->elpStyleEntry), count*4, blimit))return(0); U_swap4(&(elp->elpStyleEntry),count); // elpStyleEntry[] + return(1); } /** @@ -330,15 +405,27 @@ void rgndataheader_swap( } /** + \return 1 on success, 0 on failure \brief Convert a pointer to a U_RGNDATA object. - \param rgd pointer to a U_RGNDATA object. + \param rd pointer to a U_RGNDATA object. + \param cbRgnData size of the U_RGNDATA object. */ -void rgndata_swap( - PU_RGNDATA rd +int rgndata_swap( + PU_RGNDATA rd, + int cbRgnData, + int torev ){ - int count = rd->rdh.nCount; + int count = 0; + if(torev){ + count = rd->rdh.nCount; + } rgndataheader_swap(&(rd->rdh)); + if(!torev){ + count = rd->rdh.nCount; + } + if(4*count + (int)sizeof(U_RGNDATAHEADER) > cbRgnData)return(0); U_swap4(rd->Buffer,4*count); + return(1); } /** @@ -368,12 +455,14 @@ void pixelformatdescriptor_swap( \brief Convert a Pointer to a U_EMRTEXT record \param pemt Pointer to a U_EMRTEXT record \param record Pointer to the start of the record which contains this U_EMRTEXT + \param blimit one byte past the end of the record. \param torev 1 for native to reversed, 0 for reversed to native */ -void emrtext_swap( - PU_EMRTEXT pemt, - char *record, - int torev +int emrtext_swap( + PU_EMRTEXT pemt, + char *record, + const char *blimit, + int torev ){ int off; uint32_t count=0; @@ -391,6 +480,7 @@ void emrtext_swap( } off = sizeof(U_EMRTEXT); if(!(fOptions & U_ETO_NO_RECT)){ + if(IS_MEM_UNSAFE(pemt, sizeof(U_RECTL), blimit))return(0); rectl_swap((PU_RECTL)((char *)pemt + off),1); // optional rectangle off+=sizeof(U_RECTL); } @@ -398,11 +488,14 @@ void emrtext_swap( offDx = *(uint32_t *)((char *)pemt +off); } // ordered bytes OR UTF16-LE: the string at offString + if(IS_MEM_UNSAFE(pemt, off + 4, blimit))return(0); U_swap4(((char *)pemt+off),1); // offDx if(!torev){ offDx = *(uint32_t *)((char *)pemt +off); } - U_swap4((record+offDx),count); // Dx[], offset with respect to the Record, NOT the object + if(IS_MEM_UNSAFE(record, count*4, blimit))return(0); + U_swap4((record + offDx),count); // Dx[], offset with respect to the Record, NOT the object + return(1); } @@ -424,182 +517,236 @@ by end user code and to further that end prototypes are NOT provided and they ar // all core*_swap call this, U_EMRSETMARGN_swap and some others all it directly // numbered as core5 to be consistent with uemf.c, but must appear before the others as there is no prototype -void core5_swap(char *record, int torev){ +int core5_swap(char *record, int torev){ UNUSED_PARAMETER(torev); - PU_ENHMETARECORD pEMR = (PU_ENHMETARECORD)(record); - U_swap4(pEMR,2); // iType nSize + if(!record)return(0); + PU_EMR pEmr = (PU_EMR)(record); + U_swap4(pEmr,2); // iType nSize + return(1); } // Functions with the same form starting with U_EMRPOLYBEZIER_swap -void core1_swap(char *record, int torev){ +int core1_swap(char *record, int torev){ int count=0; + const char *blimit = NULL; PU_EMRPOLYLINETO pEmr = (PU_EMRPOLYLINETO) (record); if(torev){ count = pEmr->cptl; + blimit = record + pEmr->emr.nSize; } - core5_swap(record, torev); + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1 ); // rclBounds U_swap4(&(pEmr->cptl),1); // cptl if(!torev){ count = pEmr->cptl; + blimit = record + pEmr->emr.nSize; } + if(IS_MEM_UNSAFE((pEmr->aptl), count*sizeof(U_POINTL), blimit))return(0); pointl_swap((pEmr->aptl),count); // aptl[] + return(1); } // Functions with the same form starting with U_EMRPOLYPOLYLINE_swap -void core2_swap(char *record, int torev){ +int core2_swap(char *record, int torev){ int count=0; int nPolys=0; + const char *blimit = NULL; PU_EMRPOLYPOLYLINE pEmr = (PU_EMRPOLYPOLYLINE) (record); if(torev){ count = pEmr->cptl; nPolys = pEmr->nPolys; + blimit = record + pEmr->emr.nSize; } - core5_swap(record, torev); + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds U_swap4(&(pEmr->nPolys),2); // nPolys cptl if(!torev){ count = pEmr->cptl; nPolys = pEmr->nPolys; + blimit = record + pEmr->emr.nSize; } + if(IS_MEM_UNSAFE((pEmr->aPolyCounts), nPolys*4, blimit))return(0); U_swap4(pEmr->aPolyCounts,nPolys); // aPolyCounts[] - pointl_swap((PU_POINT)(record + sizeof(U_EMRPOLYPOLYLINE) - 4 + sizeof(uint32_t)* nPolys), count); // paptl[] + record += sizeof(U_EMRPOLYPOLYLINE) - 4 + sizeof(uint32_t)* nPolys; + if(IS_MEM_UNSAFE(record, count*sizeof(U_POINTL), blimit))return(0); + pointl_swap((PU_POINT)(record), count); // paptl[] + return(1); } // Functions with the same form starting with U_EMRSETMAPMODE_swap -void core3_swap(char *record, int torev){ +int core3_swap(char *record, int torev){ PU_EMRSETMAPMODE pEmr = (PU_EMRSETMAPMODE)(record); - core5_swap(record, torev); + if(!core5_swap(record, torev))return(0); U_swap4(&(pEmr->iMode),1); // iMode + return(1); } // Functions taking a single U_RECT or U_RECTL, starting with U_EMRELLIPSE_swap, also U_EMRFILLPATH_swap, -void core4_swap(char *record, int torev){ +int core4_swap(char *record, int torev){ PU_EMRELLIPSE pEmr = (PU_EMRELLIPSE)( record); - core5_swap(record, torev); + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBox),1); // rclBox + return(1); } // Functions with the same form starting with U_EMRPOLYBEZIER16_swap -void core6_swap(char *record, int torev){ +int core6_swap(char *record, int torev){ int count=0; + const char *blimit = NULL; PU_EMRPOLYBEZIER16 pEmr = (PU_EMRPOLYBEZIER16) (record); if(torev){ count = pEmr->cpts; + blimit = record + pEmr->emr.nSize; } - core5_swap(record, torev); + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds U_swap4(&(pEmr->cpts),1); // cpts if(!torev){ count = pEmr->cpts; + blimit = record + pEmr->emr.nSize; } + if(IS_MEM_UNSAFE((pEmr->apts), count*sizeof(U_POINT16), blimit))return(0); point16_swap((pEmr->apts),count); // apts[] + return(1); } // Records with the same form starting with U_EMRSETWINDOWEXTEX_swap, that is, all with two uint32_t values after the emr -void core7_swap(char *record, int torev){ +int core7_swap(char *record, int torev){ PU_EMRGENERICPAIR pEmr = (PU_EMRGENERICPAIR) (record); - core5_swap(record, torev); + if(!core5_swap(record, torev))return(0); U_swap4(&(pEmr->pair),2); + return(1); } // For U_EMREXTTEXTOUTA and U_EMREXTTEXTOUTW, type=0 for the first one -void core8_swap(char *record, int torev){ +int core8_swap(char *record, int torev){ + const char *blimit = NULL; PU_EMREXTTEXTOUTA pEmr = (PU_EMREXTTEXTOUTA) (record); - emrtext_swap(&(pEmr->emrtext),record,torev); - core5_swap(record, torev); + if(torev){ + blimit = record + pEmr->emr.nSize; + } + if(!core5_swap(record, torev))return(0); U_swap4(&(pEmr->iGraphicsMode),1); // iGraphicsMode rectl_swap(&(pEmr->rclBounds),1); // rclBounds U_swap4(&(pEmr->exScale),2); // exScale eyScale + if(!torev){ + blimit = record + pEmr->emr.nSize; + } + if(!emrtext_swap(&(pEmr->emrtext),record,blimit,torev))return(0); + return(1); } // Functions that take a rect and a pair of points, starting with U_EMRARC_swap -void core9_swap(char *record, int torev){ +int core9_swap(char *record, int torev){ PU_EMRARC pEmr = (PU_EMRARC) (record); - core5_swap(record, torev); + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBox),1); // rclBox U_swap4(&(pEmr->ptlStart),4); // ptlStart ptlEnd + return(1); } // Functions with the same form starting with U_EMRPOLYPOLYLINE16_swap -void core10_swap(char *record, int torev){ +int core10_swap(char *record, int torev){ int count=0; int nPolys=0; + const char *blimit = NULL; PU_EMRPOLYPOLYLINE16 pEmr = (PU_EMRPOLYPOLYLINE16) (record); if(torev){ count = pEmr->cpts; nPolys = pEmr->nPolys; + blimit = record + pEmr->emr.nSize; } - core5_swap(record, torev); + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds U_swap4(&(pEmr->nPolys),2); // nPolys cpts if(!torev){ count = pEmr->cpts; nPolys = pEmr->nPolys; + blimit = record + pEmr->emr.nSize; } + if(IS_MEM_UNSAFE((pEmr->aPolyCounts), nPolys*4, blimit))return(0); U_swap4(pEmr->aPolyCounts,nPolys); // aPolyCounts[] - point16_swap((PU_POINT16)(record + sizeof(U_EMRPOLYPOLYLINE16) - 4 + sizeof(uint32_t)* nPolys), count); // apts[] + record += sizeof(U_EMRPOLYPOLYLINE16) - 4 + sizeof(uint32_t)* nPolys; + if(IS_MEM_UNSAFE(record, count*sizeof(U_POINT16), blimit))return(0); + point16_swap((PU_POINT16)(record), count); // apts[] + return(1); } // Functions with the same form starting with U_EMRINVERTRGN_swap and U_EMRPAINTRGN_swap, -void core11_swap(char *record, int torev){ - int roff=0; - int nextroff=0; - int limit=0; - PU_EMRINVERTRGN pEmr = (PU_EMRINVERTRGN) (record); - roff = 0; +int core11_swap(char *record, int torev){ + int cbRgnData=0; + const char *blimit = NULL; + PU_EMRINVERTRGN pEmr = (PU_EMRINVERTRGN)(record); if(torev){ - limit = pEmr->emr.nSize; - nextroff = 0; - } - core5_swap(record, torev); - if(!torev){ - limit = pEmr->emr.nSize; + cbRgnData= pEmr->cbRgnData; + blimit = record + pEmr->emr.nSize; } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds U_swap4(&(pEmr->cbRgnData),1); // cbRgnData if(!torev){ - limit = pEmr->emr.nSize; - } - // This one is a pain since each RGNDATA may be a different size, so it isn't possible to index through them. - char *prd = (char *) &(pEmr->RgnData); - while(roff + 28 < limit){ // up to the end of the record - if(torev){ - nextroff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - rgndata_swap((PU_RGNDATA) (prd + roff)); - roff = nextroff; - } - else { - rgndata_swap((PU_RGNDATA) (prd + roff)); - roff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - } + cbRgnData= pEmr->cbRgnData; + blimit = record + pEmr->emr.nSize; } + if(IS_MEM_UNSAFE(pEmr->RgnData, cbRgnData, blimit))return(0); + return(rgndata_swap(pEmr->RgnData, cbRgnData, torev)); } // common code for U_EMRCREATEMONOBRUSH_swap and U_EMRCREATEDIBPATTERNBRUSHPT_swap, -void core12_swap(char *record, int torev){ +int core12_swap(char *record, int torev){ + const char *blimit = NULL; + U_OFFBMI offBmi = 0; + U_CBBMI cbBmi = 0; + U_OFFBITS offBits = 0; + U_CBBITS cbBits = 0; + uint32_t iUsage = 0; PU_EMRCREATEMONOBRUSH pEmr = (PU_EMRCREATEMONOBRUSH) (record); - if(torev && pEmr->cbBmi){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmi)); // Bmi - } - core5_swap(record, torev); + if(torev){ + offBmi = pEmr->offBmi; + cbBmi = pEmr->cbBmi; + offBits = pEmr->offBits; + cbBits = pEmr->cbBits; + iUsage = pEmr->iUsage; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsage, offBmi, cbBmi, offBits, cbBits, blimit, torev))return(0); + } + if(!core5_swap(record, torev))return(0); U_swap4(&(pEmr->ihBrush),6); // ihBrush iUsage offBmi cbBmi offBits cbBits - // ordered bytes: bitmap (including 16 bit 5bit/channel color mode, which is done bytewise). - if(!torev && pEmr->cbBmi){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmi)); // Bmi + if(!torev){ + offBmi = pEmr->offBmi; + cbBmi = pEmr->cbBmi; + offBits = pEmr->offBits; + cbBits = pEmr->cbBits; + iUsage = pEmr->iUsage; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsage, offBmi, cbBmi, offBits, cbBits, blimit, torev))return(0); } + // ordered bytes: bitmap (including 16 bit 5bit/channel color mode, which is done bytewise). + return(1); } // common code for U_EMRALPHABLEND_swap and U_EMRTRANSPARENTBLT_swap, -void core13_swap(char *record, int torev){ +int core13_swap(char *record, int torev){ + const char *blimit = NULL; + U_OFFBMISRC offBmiSrc = 0; + U_CBBMISRC cbBmiSrc = 0; + U_OFFBITSSRC offBitsSrc = 0; + U_CBBITSSRC cbBitsSrc = 0; + uint32_t iUsageSrc = 0; PU_EMRALPHABLEND pEmr = (PU_EMRALPHABLEND) (record); - if(torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); - } - core5_swap(record, torev); + if(torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); + } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds pointl_swap(&(pEmr->Dest),2); // Dest cDest pointl_swap(&(pEmr->Dest),2); // Dest cDest @@ -608,15 +755,25 @@ void core13_swap(char *record, int torev){ xform_swap( &(pEmr->xformSrc)); // xformSrc // ordered bytes: crBkColorSrc U_swap4(&(pEmr->iUsageSrc),5); // iUsageSrc offBmiSrc cbBmiSrc offBitsSrc cbBitsSrc - // ordered bytes: bitmap (including 16 bit 5bit/channel color mode, which is done bytewise). - if(!torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); + if(!torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); } + // ordered bytes: bitmap (including 16 bit 5bit/channel color mode, which is done bytewise). + return(1); } /* ********************************************************************************************** -These are the core EMR functions, each creates a particular type of record. -All return these records via a char* pointer, which is NULL if the call failed. +These are the core EMR_swap functions, each converts a particular type of record. +All operate in place on the chunk of memory holding that record. +Some of these have offsets or counts which, if corrupt or evil would result in access outside + the record. These cases return a status value of 0 if that happens, 1 on success. Other + records which do not have these issues do not return a status value. They are listed in order by the corresponding U_EMR_* index number. *********************************************************************************************** */ @@ -626,37 +783,31 @@ They are listed in order by the corresponding U_EMR_* index number. \param record pointer to a buffer holding the EMR record \param torev 1 for native to reversed, 0 for reversed to native */ -void U_EMRNOTIMPLEMENTED_swap(char *record, int torev){ - core5_swap(record, torev); - printf("WARNING: could not convert data in record type that has not been implemented!\n"); +int U_EMRNOTIMPLEMENTED_swap(char *record, int torev){ + fprintf(stderr,"EMF WARNING: could not swap data bytes on record because that type has not been implemented!\n"); + return(core5_swap(record, torev)); } // U_EMRHEADER 1 -void U_EMRHEADER_swap(char *record, int torev){ +int U_EMRHEADER_swap(char *record, int torev){ int nDesc,offDesc,nSize,cbPix,offPix; + nDesc = offDesc = nSize = cbPix = offPix = 0; PU_EMRHEADER pEmr = (PU_EMRHEADER)(record); if(torev){ nSize = pEmr->emr.nSize; - core5_swap(record, torev); - } - else { - core5_swap(record, torev); - nSize = pEmr->emr.nSize; + nDesc = pEmr->nDescription; + offDesc = pEmr->offDescription; } - + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),2); // rclBounds rclFrame U_swap4(&(pEmr->dSignature), 4); // dSignature nVersion nBytes nRecords U_swap2(&(pEmr->nHandles), 2); // nHandlessReserved - if(torev){ - nDesc = pEmr->nDescription; - offDesc = pEmr->offDescription; - U_swap4(&(pEmr->nDescription), 3); // nDescription offDescription nPalEntries - } - else { - U_swap4(&(pEmr->nDescription), 3); // nDescription offDescription nPalEntries - nDesc = pEmr->nDescription; - offDesc = pEmr->offDescription; - } + U_swap4(&(pEmr->nDescription), 3); // nDescription offDescription nPalEntries + if(!torev){ + nSize = pEmr->emr.nSize; + nDesc = pEmr->nDescription; + offDesc = pEmr->offDescription; + } // UTF16-LE Description sizel_swap(&(pEmr->szlDevice), 2); // szlDevice szlMillimeters if((nDesc && (offDesc >= 100)) || @@ -665,16 +816,14 @@ void U_EMRHEADER_swap(char *record, int torev){ if(torev){ cbPix = pEmr->cbPixelFormat; offPix = pEmr->offPixelFormat; - if(cbPix)pixelformatdescriptor_swap( (PU_PIXELFORMATDESCRIPTOR) (record + pEmr->offPixelFormat)); - U_swap4(&(pEmr->cbPixelFormat), 2); // cbPixelFormat offPixelFormat } - else { - U_swap4(&(pEmr->cbPixelFormat), 2); // cbPixelFormat offPixelFormat + U_swap4(&(pEmr->cbPixelFormat), 2); // cbPixelFormat offPixelFormat + U_swap4(&(pEmr->bOpenGL), 1); // bOpenGL + if(!torev){ cbPix = pEmr->cbPixelFormat; offPix = pEmr->offPixelFormat; - if(cbPix)pixelformatdescriptor_swap( (PU_PIXELFORMATDESCRIPTOR) (record + pEmr->offPixelFormat)); } - U_swap4(&(pEmr->bOpenGL), 1); // bOpenGL + if(cbPix)pixelformatdescriptor_swap( (PU_PIXELFORMATDESCRIPTOR) (record + pEmr->offPixelFormat)); if((nDesc && (offDesc >= 108)) || (cbPix && (offPix >=108)) || (!offDesc && !cbPix && nSize >= 108) @@ -682,543 +831,557 @@ void U_EMRHEADER_swap(char *record, int torev){ sizel_swap(&(pEmr->szlMicrometers), 1); // szlMicrometers } } + return(1); } // U_EMRPOLYBEZIER 2 -void U_EMRPOLYBEZIER_swap(char *record, int torev){ - core1_swap(record, torev); +int U_EMRPOLYBEZIER_swap(char *record, int torev){ + return(core1_swap(record, torev)); } // U_EMRPOLYGON 3 -void U_EMRPOLYGON_swap(char *record, int torev){ - core1_swap(record, torev); +int U_EMRPOLYGON_swap(char *record, int torev){ + return(core1_swap(record, torev)); } // U_EMRPOLYLINE 4 -void U_EMRPOLYLINE_swap(char *record, int torev){ - core1_swap(record, torev); +int U_EMRPOLYLINE_swap(char *record, int torev){ + return(core1_swap(record, torev)); } // U_EMRPOLYBEZIERTO 5 -void U_EMRPOLYBEZIERTO_swap(char *record, int torev){ - core1_swap(record, torev); +int U_EMRPOLYBEZIERTO_swap(char *record, int torev){ + return(core1_swap(record, torev)); } // U_EMRPOLYLINETO 6 -void U_EMRPOLYLINETO_swap(char *record, int torev){ - core1_swap(record, torev); +int U_EMRPOLYLINETO_swap(char *record, int torev){ + return(core1_swap(record, torev)); } // U_EMRPOLYPOLYLINE 7 -void U_EMRPOLYPOLYLINE_swap(char *record, int torev){ - core2_swap(record, torev); +int U_EMRPOLYPOLYLINE_swap(char *record, int torev){ + return(core2_swap(record, torev)); } // U_EMRPOLYPOLYGON 8 -void U_EMRPOLYPOLYGON_swap(char *record, int torev){ - core2_swap(record, torev); +int U_EMRPOLYPOLYGON_swap(char *record, int torev){ + return(core2_swap(record, torev)); } // U_EMRSETWINDOWEXTEX 9 -void U_EMRSETWINDOWEXTEX_swap(char *record, int torev){ - core7_swap(record, torev); +int U_EMRSETWINDOWEXTEX_swap(char *record, int torev){ + return(core7_swap(record, torev)); } // U_EMRSETWINDOWORGEX 10 -void U_EMRSETWINDOWORGEX_swap(char *record, int torev){ - core7_swap(record, torev); +int U_EMRSETWINDOWORGEX_swap(char *record, int torev){ + return(core7_swap(record, torev)); } // U_EMRSETVIEWPORTEXTEX 11 -void U_EMRSETVIEWPORTEXTEX_swap(char *record, int torev){ - core7_swap(record, torev); +int U_EMRSETVIEWPORTEXTEX_swap(char *record, int torev){ + return(core7_swap(record, torev)); } // U_EMRSETVIEWPORTORGEX 12 -void U_EMRSETVIEWPORTORGEX_swap(char *record, int torev){ - core7_swap(record, torev); +int U_EMRSETVIEWPORTORGEX_swap(char *record, int torev){ + return(core7_swap(record, torev)); } // U_EMRSETBRUSHORGEX 13 -void U_EMRSETBRUSHORGEX_swap(char *record, int torev){ - core7_swap(record, torev); +int U_EMRSETBRUSHORGEX_swap(char *record, int torev){ + return(core7_swap(record, torev)); } // U_EMREOF 14 -void U_EMREOF_swap(char *record, int torev){ +int U_EMREOF_swap(char *record, int torev){ int off=0; int cbPalEntries=0; - core5_swap(record, torev); + const char *blimit = NULL; PU_EMREOF pEmr = (PU_EMREOF)(record); if(torev){ + blimit = record + pEmr->emr.nSize; cbPalEntries = pEmr->cbPalEntries; - if(cbPalEntries){ - logpalette_swap( (PU_LOGPALETTE)(record + pEmr->offPalEntries)); - } } + if(!core5_swap(record, torev))return(0); U_swap4(&(pEmr->cbPalEntries),2); // cbPalEntries offPalEntries if(!torev){ + blimit = record + pEmr->emr.nSize; cbPalEntries = pEmr->cbPalEntries; - if(cbPalEntries){ - logpalette_swap( (PU_LOGPALETTE)(record + pEmr->offPalEntries)); - } + } + if(cbPalEntries){ + if(IS_MEM_UNSAFE(record, pEmr->offPalEntries + 2*2, blimit))return(0); // 2 16 bit values in U_LOGPALLETE + logpalette_swap( (PU_LOGPALETTE)(record + pEmr->offPalEntries)); + // U_LOGPLTNTRY values in pallette are ordered data } off = sizeof(U_EMREOF) + 4 * cbPalEntries; + if(IS_MEM_UNSAFE(record, off + 4, blimit))return(0); U_swap4(record + off,1); // nSizeLast + return(1); } // U_EMRSETPIXELV 15 -void U_EMRSETPIXELV_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRSETPIXELV_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRSETPIXELV pEmr = (PU_EMRSETPIXELV)(record); pointl_swap(&(pEmr->ptlPixel),1); // ptlPixel // ordered bytes: crColor + return(1); } // U_EMRSETMAPPERFLAGS 16 -void U_EMRSETMAPPERFLAGS_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRSETMAPPERFLAGS_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRSETMAPPERFLAGS pEmr = (PU_EMRSETMAPPERFLAGS)(record); U_swap4(&(pEmr->dwFlags),1); // dwFlags + return(1); } // U_EMRSETMAPMODE 17 -void U_EMRSETMAPMODE_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETMAPMODE_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRSETBKMODE 18 -void U_EMRSETBKMODE_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETBKMODE_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRSETPOLYFILLMODE 19 -void U_EMRSETPOLYFILLMODE_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETPOLYFILLMODE_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRSETROP2 20 -void U_EMRSETROP2_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETROP2_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRSETSTRETCHBLTMODE 21 -void U_EMRSETSTRETCHBLTMODE_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETSTRETCHBLTMODE_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRSETTEXTALIGN 22 -void U_EMRSETTEXTALIGN_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETTEXTALIGN_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRSETCOLORADJUSTMENT 23 -void U_EMRSETCOLORADJUSTMENT_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRSETCOLORADJUSTMENT_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRSETCOLORADJUSTMENT pEmr = (PU_EMRSETCOLORADJUSTMENT)(record); coloradjustment_swap(&(pEmr->ColorAdjustment)); + return(1); } // U_EMRSETTEXTCOLOR 24 -void U_EMRSETTEXTCOLOR_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRSETTEXTCOLOR_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); // ordered bytes: crColor + return(1); } // U_EMRSETBKCOLOR 25 -void U_EMRSETBKCOLOR_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRSETBKCOLOR_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); // ordered bytes: crColor + return(1); } // U_EMROFFSETCLIPRGN 26 -void U_EMROFFSETCLIPRGN_swap(char *record, int torev){ - core7_swap(record, torev); +int U_EMROFFSETCLIPRGN_swap(char *record, int torev){ + return(core7_swap(record, torev)); } // U_EMRMOVETOEX 27 -void U_EMRMOVETOEX_swap(char *record, int torev){ - core7_swap(record, torev); +int U_EMRMOVETOEX_swap(char *record, int torev){ + return(core7_swap(record, torev)); } // U_EMRSETMETARGN 28 -void U_EMRSETMETARGN_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRSETMETARGN_swap(char *record, int torev){ + return(core5_swap(record, torev)); } // U_EMREXCLUDECLIPRECT 29 -void U_EMREXCLUDECLIPRECT_swap(char *record, int torev){ - core4_swap(record, torev); +int U_EMREXCLUDECLIPRECT_swap(char *record, int torev){ + return(core4_swap(record, torev)); } // U_EMRINTERSECTCLIPRECT 30 -void U_EMRINTERSECTCLIPRECT_swap(char *record, int torev){ - core4_swap(record, torev); +int U_EMRINTERSECTCLIPRECT_swap(char *record, int torev){ + return(core4_swap(record, torev)); } // U_EMRSCALEVIEWPORTEXTEX 31 -void U_EMRSCALEVIEWPORTEXTEX_swap(char *record, int torev){ - core4_swap(record, torev); +int U_EMRSCALEVIEWPORTEXTEX_swap(char *record, int torev){ + return(core4_swap(record, torev)); } - // U_EMRSCALEWINDOWEXTEX 32 -void U_EMRSCALEWINDOWEXTEX_swap(char *record, int torev){ - core4_swap(record, torev); +int U_EMRSCALEWINDOWEXTEX_swap(char *record, int torev){ + return(core4_swap(record, torev)); } // U_EMRSAVEDC 33 -void U_EMRSAVEDC_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRSAVEDC_swap(char *record, int torev){ + return(core5_swap(record, torev)); } // U_EMRRESTOREDC 34 -void U_EMRRESTOREDC_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRRESTOREDC_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRSETWORLDTRANSFORM 35 -void U_EMRSETWORLDTRANSFORM_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRSETWORLDTRANSFORM_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRSETWORLDTRANSFORM pEmr = (PU_EMRSETWORLDTRANSFORM)(record); xform_swap(&(pEmr->xform)); + return(1); } // U_EMRMODIFYWORLDTRANSFORM 36 -void U_EMRMODIFYWORLDTRANSFORM_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRMODIFYWORLDTRANSFORM_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRMODIFYWORLDTRANSFORM pEmr = (PU_EMRMODIFYWORLDTRANSFORM)(record); xform_swap(&(pEmr->xform)); // xform U_swap4(&(pEmr->iMode),1); // iMode + return(1); } // U_EMRSELECTOBJECT 37 -void U_EMRSELECTOBJECT_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRSELECTOBJECT_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRSELECTOBJECT pEmr = (PU_EMRSELECTOBJECT)(record); U_swap4(&(pEmr->ihObject),1); // ihObject + return(1); } // U_EMRCREATEPEN 38 -void U_EMRCREATEPEN_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRCREATEPEN_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRCREATEPEN pEmr = (PU_EMRCREATEPEN)(record); U_swap4(&(pEmr->ihPen),1); // ihPen logpen_swap(&(pEmr->lopn)); // lopn + return(1); } // U_EMRCREATEBRUSHINDIRECT 39 -void U_EMRCREATEBRUSHINDIRECT_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRCREATEBRUSHINDIRECT_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRCREATEBRUSHINDIRECT pEmr = (PU_EMRCREATEBRUSHINDIRECT)(record); U_swap4(&(pEmr->ihBrush),1); // ihBrush logbrush_swap(&(pEmr->lb)); // lb + return(1); } // U_EMRDELETEOBJECT 40 -void U_EMRDELETEOBJECT_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRDELETEOBJECT_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRDELETEOBJECT pEmr = (PU_EMRDELETEOBJECT)(record); U_swap4(&(pEmr->ihObject),1); // ihObject + return(1); } // U_EMRANGLEARC 41 -void U_EMRANGLEARC_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRANGLEARC_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRANGLEARC pEmr = (PU_EMRANGLEARC)(record); pointl_swap(&(pEmr->ptlCenter),1); // ptlCenter U_swap4(&(pEmr->nRadius),3); // nRadius eStartAngle eSweepAngle + return(1); } // U_EMRELLIPSE 42 -void U_EMRELLIPSE_swap(char *record, int torev){ - core4_swap(record, torev); +int U_EMRELLIPSE_swap(char *record, int torev){ + return(core4_swap(record, torev)); } // U_EMRRECTANGLE 43 -void U_EMRRECTANGLE_swap(char *record, int torev){ - core4_swap(record, torev); +int U_EMRRECTANGLE_swap(char *record, int torev){ + return(core4_swap(record, torev)); } // U_EMRROUNDRECT 44 -void U_EMRROUNDRECT_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRROUNDRECT_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRROUNDRECT pEmr = (PU_EMRROUNDRECT)(record); rectl_swap(&(pEmr->rclBox),1); // rclBox sizel_swap(&(pEmr->szlCorner), 1); // szlCorner + return(1); } // U_EMRARC 45 -void U_EMRARC_swap(char *record, int torev){ - core9_swap(record, torev); +int U_EMRARC_swap(char *record, int torev){ + return(core9_swap(record, torev)); } // U_EMRCHORD 46 -void U_EMRCHORD_swap(char *record, int torev){ - core9_swap(record, torev); +int U_EMRCHORD_swap(char *record, int torev){ + return(core9_swap(record, torev)); } // U_EMRPIE 47 -void U_EMRPIE_swap(char *record, int torev){ - core9_swap(record, torev); +int U_EMRPIE_swap(char *record, int torev){ + return(core9_swap(record, torev)); } // U_EMRSELECTPALETTE 48 -void U_EMRSELECTPALETTE_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSELECTPALETTE_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRCREATEPALETTE 49 -void U_EMRCREATEPALETTE_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRCREATEPALETTE_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRCREATEPALETTE pEmr = (PU_EMRCREATEPALETTE)(record); U_swap4(&(pEmr->ihPal),1); // ihPal logpalette_swap( (PU_LOGPALETTE)&(pEmr->lgpl) ); // lgpl + return(1); } // U_EMRSETPALETTEENTRIES 50 -void U_EMRSETPALETTEENTRIES_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRSETPALETTEENTRIES_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRSETPALETTEENTRIES pEmr = (PU_EMRSETPALETTEENTRIES)(record); U_swap4(&(pEmr->ihPal),3); // ihPal iStart cEntries // ordered bytes: aPalEntries[] + return(1); } // U_EMRRESIZEPALETTE 51 -void U_EMRRESIZEPALETTE_swap(char *record, int torev){ - core7_swap(record, torev); +int U_EMRRESIZEPALETTE_swap(char *record, int torev){ + return(core7_swap(record, torev)); } // U_EMRREALIZEPALETTE 52 -void U_EMRREALIZEPALETTE_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRREALIZEPALETTE_swap(char *record, int torev){ + return(core5_swap(record, torev)); } // U_EMREXTFLOODFILL 53 -void U_EMREXTFLOODFILL_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMREXTFLOODFILL_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMREXTFLOODFILL pEmr = (PU_EMREXTFLOODFILL)(record); pointl_swap(&(pEmr->ptlStart),1); // ptlStart // ordered bytes: crColor U_swap4(&(pEmr->iMode),1); // iMode + return(1); } // U_EMRLINETO 54 -void U_EMRLINETO_swap(char *record, int torev){ - core7_swap(record, torev); +int U_EMRLINETO_swap(char *record, int torev){ + return(core7_swap(record, torev)); } // U_EMRARCTO 55 -void U_EMRARCTO_swap(char *record, int torev){ - core9_swap(record, torev); +int U_EMRARCTO_swap(char *record, int torev){ + return(core9_swap(record, torev)); } // U_EMRPOLYDRAW 56 -void U_EMRPOLYDRAW_swap(char *record, int torev){ +int U_EMRPOLYDRAW_swap(char *record, int torev){ int count=0; - core5_swap(record, torev); + const char *blimit = NULL; PU_EMRPOLYDRAW pEmr = (PU_EMRPOLYDRAW)(record); if(torev){ count = pEmr->cptl; + blimit = record + pEmr->emr.nSize; } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds U_swap4(&(pEmr->cptl),1); // cptl if(!torev){ count = pEmr->cptl; + blimit = record + pEmr->emr.nSize; } + if(IS_MEM_UNSAFE((pEmr->aptl), count*sizeof(U_POINTL), blimit))return(0); pointl_swap(pEmr->aptl,count); // aptl[] - U_swap4(pEmr->abTypes,count); // abTypes[] + // single byte data abTypes + return(1); } // U_EMRSETARCDIRECTION 57 -void U_EMRSETARCDIRECTION_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETARCDIRECTION_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRSETMITERLIMIT 58 -void U_EMRSETMITERLIMIT_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETMITERLIMIT_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRBEGINPATH 59 -void U_EMRBEGINPATH_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRBEGINPATH_swap(char *record, int torev){ + return(core5_swap(record, torev)); } // U_EMRENDPATH 60 -void U_EMRENDPATH_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRENDPATH_swap(char *record, int torev){ + return(core5_swap(record, torev)); } // U_EMRCLOSEFIGURE 61 -void U_EMRCLOSEFIGURE_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRCLOSEFIGURE_swap(char *record, int torev){ + return(core5_swap(record, torev)); } // U_EMRFILLPATH 62 -void U_EMRFILLPATH_swap(char *record, int torev){ - core4_swap(record, torev); +int U_EMRFILLPATH_swap(char *record, int torev){ + return(core4_swap(record, torev)); } // U_EMRSTROKEANDFILLPATH 63 -void U_EMRSTROKEANDFILLPATH_swap(char *record, int torev){ - core4_swap(record, torev); +int U_EMRSTROKEANDFILLPATH_swap(char *record, int torev){ + return(core4_swap(record, torev)); } // U_EMRSTROKEPATH 64 -void U_EMRSTROKEPATH_swap(char *record, int torev){ - core4_swap(record, torev); +int U_EMRSTROKEPATH_swap(char *record, int torev){ + return(core4_swap(record, torev)); } // U_EMRFLATTENPATH 65 -void U_EMRFLATTENPATH_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRFLATTENPATH_swap(char *record, int torev){ + return(core5_swap(record, torev)); } // U_EMRWIDENPATH 66 -void U_EMRWIDENPATH_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRWIDENPATH_swap(char *record, int torev){ + return(core5_swap(record, torev)); } // U_EMRSELECTCLIPPATH 67 -void U_EMRSELECTCLIPPATH_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSELECTCLIPPATH_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRABORTPATH 68 -void U_EMRABORTPATH_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRABORTPATH_swap(char *record, int torev){ + return(core5_swap(record, torev)); } // U_EMRUNDEF69 69 #define U_EMRUNDEF69_swap(A,B) U_EMRNOTIMPLEMENTED_swap(A,B) //!< Not implemented. // U_EMRCOMMENT 70 Comment (any binary data, interpretation is program specific) -void U_EMRCOMMENT_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRCOMMENT_swap(char *record, int torev){ + int cbData = 0; + const char *blimit = NULL; PU_EMRCOMMENT pEmr = (PU_EMRCOMMENT)(record); + if(torev){ + cbData = pEmr->cbData; + blimit = record + pEmr->emr.nSize; + } + if(!core5_swap(record, torev))return(0); U_swap4(&(pEmr->cbData),1); // cbData + if(!torev){ + cbData = pEmr->cbData; + blimit = record + pEmr->emr.nSize; + } + if(IS_MEM_UNSAFE(record, cbData + sizeof(U_SIZE_EMRCOMMENT), blimit))return(0); // program specific data, presumably byte ordered, otherwise, not portable + return(1); } // U_EMRFILLRGN 71 -void U_EMRFILLRGN_swap(char *record, int torev){ - int roff=0; - int nextroff=0; - int limit=0; - roff=0; +int U_EMRFILLRGN_swap(char *record, int torev){ + int cbRgnData=0; + const char *blimit = NULL; PU_EMRFILLRGN pEmr = (PU_EMRFILLRGN)(record); if(torev){ - limit = pEmr->emr.nSize; - nextroff = 0; - } - core5_swap(record, torev); - if(!torev){ - limit = pEmr->emr.nSize; + cbRgnData= pEmr->cbRgnData; + blimit = record + pEmr->emr.nSize; } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds U_swap4(&(pEmr->cbRgnData),2); // cbRgnData ihBrush - // This one is a pain since each RGNDATA may be a different size, so it isn't possible to index through them. - char *prd = (char *) &(pEmr->RgnData); - while(roff + 28 < limit){ // up to the end of the record - if(torev){ - nextroff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - rgndata_swap((PU_RGNDATA) (prd + roff)); - roff = nextroff; - } - else { - rgndata_swap((PU_RGNDATA) (prd + roff)); - roff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - } + if(!torev){ + cbRgnData= pEmr->cbRgnData; + blimit = record + pEmr->emr.nSize; } + if(IS_MEM_UNSAFE(pEmr->RgnData, cbRgnData, blimit))return(0); + return(rgndata_swap(pEmr->RgnData, cbRgnData, torev)); } // U_EMRFRAMERGN 72 -void U_EMRFRAMERGN_swap(char *record, int torev){ - int roff=0; - int nextroff=0; - int limit=0; +int U_EMRFRAMERGN_swap(char *record, int torev){ + int cbRgnData=0; + const char *blimit = NULL; PU_EMRFRAMERGN pEmr = (PU_EMRFRAMERGN)(record); - roff = 0; if(torev){ - limit = pEmr->emr.nSize; - nextroff = 0; - } - core5_swap(record, torev); - if(!torev){ - limit = pEmr->emr.nSize; + cbRgnData= pEmr->cbRgnData; + blimit = record + pEmr->emr.nSize; } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds U_swap4(&(pEmr->cbRgnData),2); // cbRgnData ihBrush - sizel_swap(&(pEmr->szlStroke), 2); // szlStroke - // This one is a pain since each RGNDATA may be a different size, so it isn't possible to index through them. - char *prd = (char *) &(pEmr->RgnData); - while(roff + 28 < limit){ // up to the end of the record - if(torev){ - nextroff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - rgndata_swap((PU_RGNDATA) (prd + roff)); - roff = nextroff; - } - else { - rgndata_swap((PU_RGNDATA) (prd + roff)); - roff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - } + sizel_swap(&(pEmr->szlStroke), 1); // szlStroke + if(!torev){ + cbRgnData= pEmr->cbRgnData; + blimit = record + pEmr->emr.nSize; } + if(IS_MEM_UNSAFE(pEmr->RgnData, cbRgnData, blimit))return(0); + return(rgndata_swap(pEmr->RgnData, cbRgnData, torev)); } // U_EMRINVERTRGN 73 -void U_EMRINVERTRGN_swap(char *record, int torev){ - core11_swap(record, torev); +int U_EMRINVERTRGN_swap(char *record, int torev){ + return(core11_swap(record, torev)); } // U_EMRPAINTRGN 74 -void U_EMRPAINTRGN_swap(char *record, int torev){ - core11_swap(record, torev); +int U_EMRPAINTRGN_swap(char *record, int torev){ + return(core11_swap(record, torev)); } // U_EMREXTSELECTCLIPRGN 75 -void U_EMREXTSELECTCLIPRGN_swap(char *record, int torev){ - int roff=0; - int nextroff=0; - int limit=0; - PU_EMREXTSELECTCLIPRGN pEmr = (PU_EMREXTSELECTCLIPRGN) (record); +int U_EMREXTSELECTCLIPRGN_swap(char *record, int torev){ + int cbRgnData=0; + const char *blimit = NULL; + PU_EMREXTSELECTCLIPRGN pEmr = (PU_EMREXTSELECTCLIPRGN)(record); if(torev){ - limit = pEmr->emr.nSize; - } - core5_swap(record, torev); - if(!torev){ - limit = pEmr->emr.nSize; + cbRgnData= pEmr->cbRgnData; + blimit = record + pEmr->emr.nSize; } + if(!core5_swap(record, torev))return(0); U_swap4(&(pEmr->cbRgnData),2); // cbRgnData iMode - // This one is a pain since each RGNDATA may be a different size, so it isn't possible to index through them. - char *prd = (char *) &(pEmr->RgnData); - nextroff = roff = 0; - while(roff + 16 < limit){ // up to the end of the record - if(torev){ - nextroff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - rgndata_swap((PU_RGNDATA) (prd + roff)); - roff = nextroff; - } - else { - rgndata_swap((PU_RGNDATA) (prd + roff)); - roff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - } + if(!torev){ + cbRgnData= pEmr->cbRgnData; + blimit = record + pEmr->emr.nSize; } + if(IS_MEM_UNSAFE(pEmr->RgnData, cbRgnData, blimit))return(0); + return(rgndata_swap(pEmr->RgnData, cbRgnData, torev)); } // U_EMRBITBLT 76 -void U_EMRBITBLT_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRBITBLT_swap(char *record, int torev){ + const char *blimit = NULL; + U_OFFBMISRC offBmiSrc = 0; + U_CBBMISRC cbBmiSrc = 0; + U_OFFBITSSRC offBitsSrc = 0; + U_CBBITSSRC cbBitsSrc = 0; + uint32_t iUsageSrc = 0; PU_EMRBITBLT pEmr = (PU_EMRBITBLT) (record); - if(torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); - } + if(torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); + } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds pointl_swap(&(pEmr->Dest),2); // Dest cDest U_swap4(&(pEmr->dwRop),1); // dwRop @@ -1226,42 +1389,89 @@ void U_EMRBITBLT_swap(char *record, int torev){ xform_swap(&(pEmr->xformSrc)); // xformSrc // ordered bytes: crBkColorSrc U_swap4(&(pEmr->iUsageSrc),5); // iUsageSrc offBmiSrc cbBmiSrc offBitsSrc cbBitsSrc - // ordered bytes: bitmap (including 16 bit 5bit/channel color mode, which is done bytewise). - if(!torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); + if(!torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); } + // ordered bytes: bitmap (including 16 bit 5bit/channel color mode, which is done bytewise). + return(1); } // U_EMRSTRETCHBLT 77 -void U_EMRSTRETCHBLT_swap(char *record, int torev){ +int U_EMRSTRETCHBLT_swap(char *record, int torev){ + const char *blimit = NULL; + U_OFFBMISRC offBmiSrc = 0; + U_CBBMISRC cbBmiSrc = 0; + U_OFFBITSSRC offBitsSrc = 0; + U_CBBITSSRC cbBitsSrc = 0; + uint32_t iUsageSrc = 0; PU_EMRSTRETCHBLT pEmr = (PU_EMRSTRETCHBLT) (record); - core5_swap(record, torev); + if(torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); + } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds pointl_swap(&(pEmr->Dest),2); // Dest cDest U_swap4(&(pEmr->dwRop),1); // dwRop pointl_swap(&(pEmr->Src),1); // Src xform_swap(&(pEmr->xformSrc)); // xformSrc // ordered bytes: crBkColorSrc - if(torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); - } U_swap4(&(pEmr->iUsageSrc),5); // iUsageSrc offBmiSrc cbBmiSrc offBitsSrc cbBitsSrc pointl_swap(&(pEmr->cSrc),1); // cSrc - if(!torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); + if(!torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); } + // ordered bytes: bitmap (including 16 bit 5bit/channel color mode, which is done bytewise). + return(1); } // U_EMRMASKBLT 78 -void U_EMRMASKBLT_swap(char *record, int torev){ +int U_EMRMASKBLT_swap(char *record, int torev){ + const char *blimit = NULL; + U_OFFBMISRC offBmiSrc = 0; + U_CBBMISRC cbBmiSrc = 0; + U_OFFBITSSRC offBitsSrc = 0; + U_CBBITSSRC cbBitsSrc = 0; + uint32_t iUsageSrc = 0; + U_OFFBMIMSK offBmiMask = 0; + U_CBBMIMSK cbBmiMask = 0; + U_OFFBITSMSK offBitsMask = 0; + U_CBBITSMSK cbBitsMask = 0; + uint32_t iUsageMask = 0; PU_EMRMASKBLT pEmr = (PU_EMRMASKBLT) (record); - core5_swap(record, torev); - if(torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); - } - if(torev && pEmr->cbBmiMask){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiMask)); - } + if(torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + offBmiMask = pEmr->offBmiMask; + cbBmiMask = pEmr->cbBmiMask; + offBitsMask = pEmr->offBitsMask; + cbBitsMask = pEmr->cbBitsMask; + iUsageMask = pEmr->iUsageMask; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); + if(!DIB_swap(record, iUsageMask, offBmiMask, cbBmiMask, offBitsMask, cbBitsMask, blimit, torev))return(0); + } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds pointl_swap(&(pEmr->Dest),2); // Dest cDest U_swap4(&(pEmr->dwRop),1); // dwRop @@ -1271,24 +1481,54 @@ void U_EMRMASKBLT_swap(char *record, int torev){ U_swap4(&(pEmr->iUsageSrc),5); // iUsageSrc offBmiSrc cbBmiSrc offBitsSrc cbBitsSrc pointl_swap(&(pEmr->Mask),1); // Mask U_swap4(&(pEmr->iUsageMask),5); // iUsageMask offBmiMask cbBmiMask offBitsMask cbBitsMask - if(!torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); - } - if(!torev && pEmr->cbBmiMask){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiMask)); - } + if(!torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + offBmiMask = pEmr->offBmiMask; + cbBmiMask = pEmr->cbBmiMask; + offBitsMask = pEmr->offBitsMask; + cbBitsMask = pEmr->cbBitsMask; + iUsageMask = pEmr->iUsageMask; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); + if(!DIB_swap(record, iUsageMask, offBmiMask, cbBmiMask, offBitsMask, cbBitsMask, blimit, torev))return(0); + } + return(1); } // U_EMRPLGBLT 79 -void U_EMRPLGBLT_swap(char *record, int torev){ +int U_EMRPLGBLT_swap(char *record, int torev){ + const char *blimit = NULL; + U_OFFBMISRC offBmiSrc = 0; + U_CBBMISRC cbBmiSrc = 0; + U_OFFBITSSRC offBitsSrc = 0; + U_CBBITSSRC cbBitsSrc = 0; + uint32_t iUsageSrc = 0; + U_OFFBMIMSK offBmiMask = 0; + U_CBBMIMSK cbBmiMask = 0; + U_OFFBITSMSK offBitsMask = 0; + U_CBBITSMSK cbBitsMask = 0; + uint32_t iUsageMask = 0; PU_EMRPLGBLT pEmr = (PU_EMRPLGBLT) (record); - core5_swap(record, torev); - if(torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); - } - if(torev && pEmr->cbBmiMask){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiMask)); - } + if(torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + offBmiMask = pEmr->offBmiMask; + cbBmiMask = pEmr->cbBmiMask; + offBitsMask = pEmr->offBitsMask; + cbBitsMask = pEmr->cbBitsMask; + iUsageMask = pEmr->iUsageMask; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); + if(!DIB_swap(record, iUsageMask, offBmiMask, cbBmiMask, offBitsMask, cbBitsMask, blimit, torev))return(0); + } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds pointl_swap(pEmr->aptlDst,3); // aptlDst[] pointl_swap(&(pEmr->Src),2); // Src cSrc @@ -1297,78 +1537,124 @@ void U_EMRPLGBLT_swap(char *record, int torev){ U_swap4(&(pEmr->iUsageSrc),5); // iUsageSrc offBmiSrc cbBmiSrc offBitsSrc cbBitsSrc pointl_swap(&(pEmr->Mask),1); // Mask U_swap4(&(pEmr->iUsageMask),5); // iUsageMask offBmiMask cbBmiMask offBitsMask cbBitsMask - if(!torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); - } - if(!torev && pEmr->cbBmiMask){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiMask)); - } + if(!torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + offBmiMask = pEmr->offBmiMask; + cbBmiMask = pEmr->cbBmiMask; + offBitsMask = pEmr->offBitsMask; + cbBitsMask = pEmr->cbBitsMask; + iUsageMask = pEmr->iUsageMask; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); + if(!DIB_swap(record, iUsageMask, offBmiMask, cbBmiMask, offBitsMask, cbBitsMask, blimit, torev))return(0); + } + return(1); } // U_EMRSETDIBITSTODEVICE 80 -void U_EMRSETDIBITSTODEVICE_swap(char *record, int torev){ +int U_EMRSETDIBITSTODEVICE_swap(char *record, int torev){ + const char *blimit = NULL; + U_OFFBMISRC offBmiSrc = 0; + U_CBBMISRC cbBmiSrc = 0; + U_OFFBITSSRC offBitsSrc = 0; + U_CBBITSSRC cbBitsSrc = 0; + uint32_t iUsageSrc = 0; PU_EMRSETDIBITSTODEVICE pEmr = (PU_EMRSETDIBITSTODEVICE) (record); - core5_swap(record, torev); - if(torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); - } + if(torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); + } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds pointl_swap(&(pEmr->Dest),1); // Dest pointl_swap(&(pEmr->Src),2); // Src cSrc U_swap4(&(pEmr->offBmiSrc),7); // offBmiSrc cbBmiSrc offBitsSrc cbBitsSrc iUsageSrc iStartScan cScans - if(!torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); + if(!torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); } + return(1); } // U_EMRSTRETCHDIBITS 81 -void U_EMRSTRETCHDIBITS_swap(char *record, int torev){ +int U_EMRSTRETCHDIBITS_swap(char *record, int torev){ + const char *blimit = NULL; + U_OFFBMISRC offBmiSrc = 0; + U_CBBMISRC cbBmiSrc = 0; + U_OFFBITSSRC offBitsSrc = 0; + U_CBBITSSRC cbBitsSrc = 0; + uint32_t iUsageSrc = 0; PU_EMRSTRETCHDIBITS pEmr = (PU_EMRSTRETCHDIBITS) (record); - core5_swap(record, torev); - if(torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); - } + if(torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); + } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds pointl_swap(&(pEmr->Dest),1); // Dest pointl_swap(&(pEmr->Src),2); // Src cSrc U_swap4(&(pEmr->offBmiSrc),6); // offBmiSrc cbBmiSrc offBitsSrc cbBitsSrc iUsageSrc dwRop pointl_swap(&(pEmr->cDest),1); // cDest - if(!torev && pEmr->cbBmiSrc){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmiSrc)); + if(!torev){ + offBmiSrc = pEmr->offBmiSrc; + cbBmiSrc = pEmr->cbBmiSrc; + offBitsSrc = pEmr->offBitsSrc; + cbBitsSrc = pEmr->cbBitsSrc; + iUsageSrc = pEmr->iUsageSrc; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit, torev))return(0); } + return(1); } -// U_EMREXTCREATEFONTINDIRECTW_swap 82 -void U_EMREXTCREATEFONTINDIRECTW_swap(char *record, int torev){ +// U_EMREXTCREATEFONTINDIRECTW 82 +int U_EMREXTCREATEFONTINDIRECTW_swap(char *record, int torev){ + int nSize = 0; PU_EMREXTCREATEFONTINDIRECTW pEmr = (PU_EMREXTCREATEFONTINDIRECTW) (record); if(torev){ - if(pEmr->emr.nSize == sizeof(U_EMREXTCREATEFONTINDIRECTW)){ - logfont_panose_swap(&(pEmr->elfw)); - } - else { - logfont_swap( (PU_LOGFONT) &(pEmr->elfw)); - } + nSize = pEmr->emr.nSize; } - core5_swap(record, torev); + if(!core5_swap(record, torev))return(0); + U_swap4(&(pEmr->ihFont),1); // ihFont if(!torev){ - if(pEmr->emr.nSize == sizeof(U_EMREXTCREATEFONTINDIRECTW)){ - logfont_panose_swap(&(pEmr->elfw)); - } - else { - logfont_swap( (PU_LOGFONT) &(pEmr->elfw)); - } + nSize = pEmr->emr.nSize; } - U_swap4(&(pEmr->ihFont),1); // ihFont + if(nSize == U_SIZE_EMREXTCREATEFONTINDIRECTW_LOGFONT_PANOSE){ + logfont_panose_swap(&(pEmr->elfw)); + } + else { // logfont or logfontExDv (which starts with logfont, which can be swapped, and the rest is already in byte order + logfont_swap( (PU_LOGFONT) &(pEmr->elfw)); + } + return(1); } // U_EMREXTTEXTOUTA 83 -void U_EMREXTTEXTOUTA_swap(char *record, int torev){ - core8_swap(record, torev); +int U_EMREXTTEXTOUTA_swap(char *record, int torev){ + return(core8_swap(record, torev)); } // U_EMREXTTEXTOUTW 84 -void U_EMREXTTEXTOUTW_swap(char *record, int torev){ - core8_swap(record, torev); +int U_EMREXTTEXTOUTW_swap(char *record, int torev){ + return(core8_swap(record, torev)); } // U_EMRPOLYBEZIER16 85 @@ -1376,23 +1662,23 @@ void U_EMREXTTEXTOUTW_swap(char *record, int torev){ \brief Convert a pointer to a U_EMR_POLYBEZIER16 record. \param record pointer to a buffer holding the EMR record */ -void U_EMRPOLYBEZIER16_swap(char *record, int torev){ - core6_swap(record, torev); +int U_EMRPOLYBEZIER16_swap(char *record, int torev){ + return(core6_swap(record, torev)); } // U_EMRPOLYGON16 86 -void U_EMRPOLYGON16_swap(char *record, int torev){ - core6_swap(record, torev); +int U_EMRPOLYGON16_swap(char *record, int torev){ + return(core6_swap(record, torev)); } // U_EMRPOLYLINE16 87 -void U_EMRPOLYLINE16_swap(char *record, int torev){ - core6_swap(record, torev); +int U_EMRPOLYLINE16_swap(char *record, int torev){ + return(core6_swap(record, torev)); } // U_EMRPOLYBEZIERTO16 88 -void U_EMRPOLYBEZIERTO16_swap(char *record, int torev){ - core6_swap(record, torev); +int U_EMRPOLYBEZIERTO16_swap(char *record, int torev){ + return(core6_swap(record, torev)); } // U_EMRPOLYLINETO16 89 @@ -1400,61 +1686,81 @@ void U_EMRPOLYBEZIERTO16_swap(char *record, int torev){ \brief Convert a pointer to a U_EMR_POLYLINETO16 record. \param record pointer to a buffer holding the EMR record */ -void U_EMRPOLYLINETO16_swap(char *record, int torev){ - core6_swap(record, torev); +int U_EMRPOLYLINETO16_swap(char *record, int torev){ + return(core6_swap(record, torev)); } // U_EMRPOLYPOLYLINE16 90 -void U_EMRPOLYPOLYLINE16_swap(char *record, int torev){ - core10_swap(record, torev); +int U_EMRPOLYPOLYLINE16_swap(char *record, int torev){ + return(core10_swap(record, torev)); } // U_EMRPOLYPOLYGON16 91 -void U_EMRPOLYPOLYGON16_swap(char *record, int torev){ - core10_swap(record, torev); +int U_EMRPOLYPOLYGON16_swap(char *record, int torev){ + return(core10_swap(record, torev)); } // U_EMRPOLYDRAW16 92 -void U_EMRPOLYDRAW16_swap(char *record, int torev){ +int U_EMRPOLYDRAW16_swap(char *record, int torev){ int count=0; - core5_swap(record, torev); + const char *blimit = NULL; PU_EMRPOLYDRAW16 pEmr = (PU_EMRPOLYDRAW16)(record); if(torev){ count = pEmr->cpts; + blimit = record + pEmr->emr.nSize; } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds U_swap4(&(pEmr->cpts),1); // cpts if(!torev){ count = pEmr->cpts; + blimit = record + pEmr->emr.nSize; } + if(IS_MEM_UNSAFE((pEmr->apts), count*sizeof(U_POINT16), blimit))return(0); point16_swap(pEmr->apts,count); // apts[] - U_swap4(pEmr->abTypes,count); // abTypes[] + // single byte data abTypes + return(1); } // U_EMRCREATEMONOBRUSH 93 -void U_EMRCREATEMONOBRUSH_swap(char *record, int torev){ - core12_swap(record, torev); +int U_EMRCREATEMONOBRUSH_swap(char *record, int torev){ + return(core12_swap(record, torev)); } // U_EMRCREATEDIBPATTERNBRUSHPT_swap 94 -void U_EMRCREATEDIBPATTERNBRUSHPT_swap(char *record, int torev){ - core12_swap(record, torev); +int U_EMRCREATEDIBPATTERNBRUSHPT_swap(char *record, int torev){ + return(core12_swap(record, torev)); } // U_EMREXTCREATEPEN 95 -void U_EMREXTCREATEPEN_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMREXTCREATEPEN_swap(char *record, int torev){ + const char *blimit = NULL; + U_OFFBMI offBmi = 0; + U_CBBMI cbBmi = 0; + U_OFFBITS offBits = 0; + U_CBBITS cbBits = 0; PU_EMREXTCREATEPEN pEmr = (PU_EMREXTCREATEPEN)(record); - if(torev && pEmr->cbBmi){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmi)); - } + if(torev){ + offBmi = pEmr->offBmi; + cbBmi = pEmr->cbBmi; + offBits = pEmr->offBits; + cbBits = pEmr->cbBits; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, U_DIB_RGB_COLORS, offBmi, cbBmi, offBits, cbBits, blimit, torev))return(0); + } + if(!core5_swap(record, torev))return(0); U_swap4(&(pEmr->ihPen),5); // ihPen offBmi cbBmi offBits cbBits - if(!torev && pEmr->cbBmi){ - bitmapinfo_swap((PU_BITMAPINFO)(record + pEmr->offBmi)); + if(!torev){ + offBmi = pEmr->offBmi; + cbBmi = pEmr->cbBmi; + offBits = pEmr->offBits; + cbBits = pEmr->cbBits; + blimit = record + pEmr->emr.nSize; + if(!DIB_swap(record, U_DIB_RGB_COLORS, offBmi, cbBmi, offBits, cbBits, blimit, torev))return(0); } - extlogpen_swap((PU_EXTLOGPEN) &(pEmr->elp), torev); + return(extlogpen_swap((PU_EXTLOGPEN) &(pEmr->elp), blimit, torev)); } // U_EMRPOLYTEXTOUTA 96 NOT IMPLEMENTED, denigrated after Windows NT @@ -1463,26 +1769,27 @@ void U_EMREXTCREATEPEN_swap(char *record, int torev){ #define U_EMRPOLYTEXTOUTW_swap(A,B) U_EMRNOTIMPLEMENTED_swap(A,B) //!< Not implemented. // U_EMRSETICMMODE 98 -void U_EMRSETICMMODE_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETICMMODE_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRCREATECOLORSPACE 99 -void U_EMRCREATECOLORSPACE_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRCREATECOLORSPACE_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRCREATECOLORSPACE pEmr = (PU_EMRCREATECOLORSPACE)(record); U_swap4(&(pEmr->ihCS),1); // ihCS logcolorspacea_swap(&(pEmr->lcs)); // lcs + return(1); } // U_EMRSETCOLORSPACE 100 -void U_EMRSETCOLORSPACE_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETCOLORSPACE_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRDELETECOLORSPACE 101 -void U_EMRDELETECOLORSPACE_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRDELETECOLORSPACE_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRGLSRECORD 102 Not implemented @@ -1491,10 +1798,11 @@ void U_EMRDELETECOLORSPACE_swap(char *record, int torev){ #define U_EMRGLSBOUNDEDRECORD_swap(A,B) U_EMRNOTIMPLEMENTED_swap(A,B) //!< Not implemented. // U_EMRPIXELFORMAT 104 -void U_EMRPIXELFORMAT_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRPIXELFORMAT_swap(char *record, int torev){ + if(!core5_swap(record, torev))return(0); PU_EMRPIXELFORMAT pEmr = (PU_EMRPIXELFORMAT)(record); pixelformatdescriptor_swap(&(pEmr->pfd)); // pfd + return(1); } // U_EMRDRAWESCAPE 105 Not implemented @@ -1505,24 +1813,32 @@ void U_EMRPIXELFORMAT_swap(char *record, int torev){ #define U_EMRUNDEF107_swap(A,B) U_EMRNOTIMPLEMENTED_swap(A,B) //!< Not implemented. // U_EMRSMALLTEXTOUT 108 -void U_EMRSMALLTEXTOUT_swap(char *record, int torev){ - int roff=0; - int fuOptions=0; - core5_swap(record, torev); +int U_EMRSMALLTEXTOUT_swap(char *record, int torev){ + int roff=sizeof(U_EMRSMALLTEXTOUT); // offset to the start of the variable fields + int fuOptions = 0; + int cChars = 0; + const char *blimit = NULL; PU_EMRSMALLTEXTOUT pEmr = (PU_EMRSMALLTEXTOUT)(record); if(torev){ fuOptions = pEmr->fuOptions; + cChars = pEmr->cChars; + blimit = record + pEmr->emr.nSize; } + if(!core5_swap(record, torev))return(0); pointl_swap(&(pEmr->Dest),1); // Dest U_swap4(&(pEmr->cChars),5); // cChars fuOptions iGraphicsMode exScale eyScale if(!torev){ fuOptions = pEmr->fuOptions; + cChars = pEmr->cChars; + blimit = record + pEmr->emr.nSize; } - roff = sizeof(U_EMRSMALLTEXTOUT); // offset to the start of the variable fields if(!(fuOptions & U_ETO_NO_RECT)){ + if(IS_MEM_UNSAFE(record, roff + sizeof(U_RECTL), blimit))return(0); rectl_swap( (PU_RECTL) (record + roff),1); // rclBounds } + if(IS_MEM_UNSAFE(record, roff + sizeof(U_RECTL) + cChars, blimit))return(0); // ordered bytes or UTF16-LE TextString + return(1); } // U_EMRFORCEUFIMAPPING 109 Not implemented @@ -1537,55 +1853,62 @@ void U_EMRSMALLTEXTOUT_swap(char *record, int torev){ #define U_EMRSETICMPROFILEW_swap(A,B) U_EMRNOTIMPLEMENTED_swap(A,B) //!< Not implemented. // U_EMRALPHABLEND 114 -void U_EMRALPHABLEND_swap(char *record, int torev){ - core13_swap(record, torev); +int U_EMRALPHABLEND_swap(char *record, int torev){ + return(core13_swap(record, torev)); } // U_EMRSETLAYOUT 115 -void U_EMRSETLAYOUT_swap(char *record, int torev){ - core3_swap(record, torev); +int U_EMRSETLAYOUT_swap(char *record, int torev){ + return(core3_swap(record, torev)); } // U_EMRTRANSPARENTBLT 116 -void U_EMRTRANSPARENTBLT_swap(char *record, int torev){ - core13_swap(record, torev); +int U_EMRTRANSPARENTBLT_swap(char *record, int torev){ + return(core13_swap(record, torev)); } // U_EMRUNDEF117 117 Not implemented #define U_EMRUNDEF117_swap(A,B) U_EMRNOTIMPLEMENTED_swap(A,B) //!< Not implemented. // U_EMRGRADIENTFILL 118 -void U_EMRGRADIENTFILL_swap(char *record, int torev){ +int U_EMRGRADIENTFILL_swap(char *record, int torev){ int nTriVert=0; int nGradObj=0; int ulMode=0; - core5_swap(record, torev); + const char *blimit = NULL; PU_EMRGRADIENTFILL pEmr = (PU_EMRGRADIENTFILL)(record); if(torev){ nTriVert = pEmr->nTriVert; nGradObj = pEmr->nGradObj; ulMode = pEmr->ulMode; + blimit = record + pEmr->emr.nSize; } + if(!core5_swap(record, torev))return(0); rectl_swap(&(pEmr->rclBounds),1); // rclBounds U_swap4(&(pEmr->nTriVert),3); // nTriVert nGradObj ulMode if(!torev){ nTriVert = pEmr->nTriVert; nGradObj = pEmr->nGradObj; ulMode = pEmr->ulMode; + blimit = record + pEmr->emr.nSize; } record += sizeof(U_EMRGRADIENTFILL); + if(IS_MEM_UNSAFE(record, nTriVert*sizeof(U_TRIVERTEX), blimit))return(0); if(nTriVert){ trivertex_swap((PU_TRIVERTEX)(record),nTriVert); // TriVert[] } record += nTriVert * sizeof(U_TRIVERTEX); if(nGradObj){ if( ulMode == U_GRADIENT_FILL_TRIANGLE){ + if(IS_MEM_UNSAFE(record, nGradObj*sizeof(U_GRADIENT3), blimit))return(0); gradient3_swap((PU_GRADIENT3)(record), nGradObj); // GradObj[] } else if(ulMode == U_GRADIENT_FILL_RECT_H || ulMode == U_GRADIENT_FILL_RECT_V){ + if(IS_MEM_UNSAFE(record, nGradObj*sizeof(U_GRADIENT4), blimit))return(0); gradient4_swap((PU_GRADIENT4)(record), nGradObj); // GradObj[] } } + return(1); } // U_EMRSETLINKEDUFIS 119 Not implemented @@ -1596,17 +1919,185 @@ void U_EMRGRADIENTFILL_swap(char *record, int torev){ #define U_EMRCOLORMATCHTOTARGETW_swap(A,B) U_EMRNOTIMPLEMENTED_swap(A,B) //!< Not implemented. // U_EMRCREATECOLORSPACEW 122 -void U_EMRCREATECOLORSPACEW_swap(char *record, int torev){ - core5_swap(record, torev); +int U_EMRCREATECOLORSPACEW_swap(char *record, int torev){ PU_EMRCREATECOLORSPACEW pEmr = (PU_EMRCREATECOLORSPACEW)(record); + if(!core5_swap(record, torev))return(0); U_swap4(&(pEmr->ihCS),1); // ihCS logcolorspacew_swap(&(pEmr->lcs)); // lcs U_swap4(&(pEmr->dwFlags),2); // dwFlags cbData // ordered bytes: Data + return(1); } //! \endcond +/** + \brief Checks the declared size of a record for consistency + \return 0 on failure, 1 on success + \param record pointer to the start of the EMF record in memory + \param blimit pointer to one byte after the EMF record in memory + \param nSize number of bytes in the record, read from the record + \param iType type of the record, read from the record + \param torev 1 for native to reversed, 0 for reversed to native + + Normally this would be called immediately after reading the data from a file. + Verifies that the declared size is consistent with this type of record. +*/ +int U_emf_record_sizeok(const char *record, const char *blimit, uint32_t *nSize, uint32_t *iType, int torev){ + uint32_t rsize=0; + if(!nSize || !iType)return(0); // programming error + + /* Check that COMMON data in record can be touched without an access violation. If it cannot be + this is either a corrupt EMF or one engineered to cause a buffer overflow. Pointer math + could wrap so check both sides of the range, and fail any indications of such a wrap. + */ + if(IS_MEM_UNSAFE(record, sizeof(U_EMR), blimit))return(0); + + PU_ENHMETARECORD pEmr = (PU_ENHMETARECORD)(record); + *iType = pEmr->iType; + *nSize = pEmr->nSize; + if(!torev){ + U_swap4(iType,1); + U_swap4(nSize,1); + } + + /* Check that the FULL record size is OK, abort if not. */ + if(IS_MEM_UNSAFE(record, *nSize, blimit))return(0); + + switch (*iType) + { + // next line, ancient EMF files used a smaller header, to be safe, test for that + case U_EMR_HEADER: rsize = U_SIZE_EMRHEADER_MIN; break; + case U_EMR_POLYBEZIER: rsize = U_SIZE_EMRPOLYBEZIER; break; + case U_EMR_POLYGON: rsize = U_SIZE_EMRPOLYGON; break; + case U_EMR_POLYLINE: rsize = U_SIZE_EMRPOLYLINE; break; + case U_EMR_POLYBEZIERTO: rsize = U_SIZE_EMRPOLYBEZIERTO; break; + case U_EMR_POLYLINETO: rsize = U_SIZE_EMRPOLYLINETO; break; + case U_EMR_POLYPOLYLINE: rsize = U_SIZE_EMRPOLYPOLYLINE; break; + case U_EMR_POLYPOLYGON: rsize = U_SIZE_EMRPOLYPOLYGON; break; + case U_EMR_SETWINDOWEXTEX: rsize = U_SIZE_EMRSETWINDOWEXTEX; break; + case U_EMR_SETWINDOWORGEX: rsize = U_SIZE_EMRSETWINDOWORGEX; break; + case U_EMR_SETVIEWPORTEXTEX: rsize = U_SIZE_EMRSETVIEWPORTEXTEX; break; + case U_EMR_SETVIEWPORTORGEX: rsize = U_SIZE_EMRSETVIEWPORTORGEX; break; + case U_EMR_SETBRUSHORGEX: rsize = U_SIZE_EMRSETBRUSHORGEX; break; + case U_EMR_EOF: rsize = U_SIZE_EMREOF; break; + case U_EMR_SETPIXELV: rsize = U_SIZE_EMRSETPIXELV; break; + case U_EMR_SETMAPPERFLAGS: rsize = U_SIZE_EMRSETMAPPERFLAGS; break; + case U_EMR_SETMAPMODE: rsize = U_SIZE_EMRSETMAPMODE; break; + case U_EMR_SETBKMODE: rsize = U_SIZE_EMRSETBKMODE; break; + case U_EMR_SETPOLYFILLMODE: rsize = U_SIZE_EMRSETPOLYFILLMODE; break; + case U_EMR_SETROP2: rsize = U_SIZE_EMRSETROP2; break; + case U_EMR_SETSTRETCHBLTMODE: rsize = U_SIZE_EMRSETSTRETCHBLTMODE; break; + case U_EMR_SETTEXTALIGN: rsize = U_SIZE_EMRSETTEXTALIGN; break; + case U_EMR_SETCOLORADJUSTMENT: rsize = U_SIZE_EMRSETCOLORADJUSTMENT; break; + case U_EMR_SETTEXTCOLOR: rsize = U_SIZE_EMRSETTEXTCOLOR; break; + case U_EMR_SETBKCOLOR: rsize = U_SIZE_EMRSETBKCOLOR; break; + case U_EMR_OFFSETCLIPRGN: rsize = U_SIZE_EMROFFSETCLIPRGN; break; + case U_EMR_MOVETOEX: rsize = U_SIZE_EMRMOVETOEX; break; + case U_EMR_SETMETARGN: rsize = U_SIZE_EMRSETMETARGN; break; + case U_EMR_EXCLUDECLIPRECT: rsize = U_SIZE_EMREXCLUDECLIPRECT; break; + case U_EMR_INTERSECTCLIPRECT: rsize = U_SIZE_EMRINTERSECTCLIPRECT; break; + case U_EMR_SCALEVIEWPORTEXTEX: rsize = U_SIZE_EMRSCALEVIEWPORTEXTEX; break; + case U_EMR_SCALEWINDOWEXTEX: rsize = U_SIZE_EMRSCALEWINDOWEXTEX; break; + case U_EMR_SAVEDC: rsize = U_SIZE_EMRSAVEDC; break; + case U_EMR_RESTOREDC: rsize = U_SIZE_EMRRESTOREDC; break; + case U_EMR_SETWORLDTRANSFORM: rsize = U_SIZE_EMRSETWORLDTRANSFORM; break; + case U_EMR_MODIFYWORLDTRANSFORM: rsize = U_SIZE_EMRMODIFYWORLDTRANSFORM; break; + case U_EMR_SELECTOBJECT: rsize = U_SIZE_EMRSELECTOBJECT; break; + case U_EMR_CREATEPEN: rsize = U_SIZE_EMRCREATEPEN; break; + case U_EMR_CREATEBRUSHINDIRECT: rsize = U_SIZE_EMRCREATEBRUSHINDIRECT; break; + case U_EMR_DELETEOBJECT: rsize = U_SIZE_EMRDELETEOBJECT; break; + case U_EMR_ANGLEARC: rsize = U_SIZE_EMRANGLEARC; break; + case U_EMR_ELLIPSE: rsize = U_SIZE_EMRELLIPSE; break; + case U_EMR_RECTANGLE: rsize = U_SIZE_EMRRECTANGLE; break; + case U_EMR_ROUNDRECT: rsize = U_SIZE_EMRROUNDRECT; break; + case U_EMR_ARC: rsize = U_SIZE_EMRARC; break; + case U_EMR_CHORD: rsize = U_SIZE_EMRCHORD; break; + case U_EMR_PIE: rsize = U_SIZE_EMRPIE; break; + case U_EMR_SELECTPALETTE: rsize = U_SIZE_EMRSELECTPALETTE; break; + case U_EMR_CREATEPALETTE: rsize = U_SIZE_EMRCREATEPALETTE; break; + case U_EMR_SETPALETTEENTRIES: rsize = U_SIZE_EMRSETPALETTEENTRIES; break; + case U_EMR_RESIZEPALETTE: rsize = U_SIZE_EMRRESIZEPALETTE; break; + case U_EMR_REALIZEPALETTE: rsize = U_SIZE_EMRREALIZEPALETTE; break; + case U_EMR_EXTFLOODFILL: rsize = U_SIZE_EMREXTFLOODFILL; break; + case U_EMR_LINETO: rsize = U_SIZE_EMRLINETO; break; + case U_EMR_ARCTO: rsize = U_SIZE_EMRARCTO; break; + case U_EMR_POLYDRAW: rsize = U_SIZE_EMRPOLYDRAW; break; + case U_EMR_SETARCDIRECTION: rsize = U_SIZE_EMRSETARCDIRECTION; break; + case U_EMR_SETMITERLIMIT: rsize = U_SIZE_EMRSETMITERLIMIT; break; + case U_EMR_BEGINPATH: rsize = U_SIZE_EMRBEGINPATH; break; + case U_EMR_ENDPATH: rsize = U_SIZE_EMRENDPATH; break; + case U_EMR_CLOSEFIGURE: rsize = U_SIZE_EMRCLOSEFIGURE; break; + case U_EMR_FILLPATH: rsize = U_SIZE_EMRFILLPATH; break; + case U_EMR_STROKEANDFILLPATH: rsize = U_SIZE_EMRSTROKEANDFILLPATH; break; + case U_EMR_STROKEPATH: rsize = U_SIZE_EMRSTROKEPATH; break; + case U_EMR_FLATTENPATH: rsize = U_SIZE_EMRFLATTENPATH; break; + case U_EMR_WIDENPATH: rsize = U_SIZE_EMRWIDENPATH; break; + case U_EMR_SELECTCLIPPATH: rsize = U_SIZE_EMRSELECTCLIPPATH; break; + case U_EMR_ABORTPATH: rsize = U_SIZE_EMRABORTPATH; break; + case U_EMR_UNDEF69: rsize = U_SIZE_EMRUNDEFINED; break; + case U_EMR_COMMENT: rsize = U_SIZE_EMRCOMMENT; break; + case U_EMR_FILLRGN: rsize = U_SIZE_EMRFILLRGN; break; + case U_EMR_FRAMERGN: rsize = U_SIZE_EMRFRAMERGN; break; + case U_EMR_INVERTRGN: rsize = U_SIZE_EMRINVERTRGN; break; + case U_EMR_PAINTRGN: rsize = U_SIZE_EMRPAINTRGN; break; + case U_EMR_EXTSELECTCLIPRGN: rsize = U_SIZE_EMREXTSELECTCLIPRGN; break; + case U_EMR_BITBLT: rsize = U_SIZE_EMRBITBLT; break; + case U_EMR_STRETCHBLT: rsize = U_SIZE_EMRSTRETCHBLT; break; + case U_EMR_MASKBLT: rsize = U_SIZE_EMRMASKBLT; break; + case U_EMR_PLGBLT: rsize = U_SIZE_EMRPLGBLT; break; + case U_EMR_SETDIBITSTODEVICE: rsize = U_SIZE_EMRSETDIBITSTODEVICE; break; + case U_EMR_STRETCHDIBITS: rsize = U_SIZE_EMRSTRETCHDIBITS; break; + case U_EMR_EXTCREATEFONTINDIRECTW: rsize = U_SIZE_EMREXTCREATEFONTINDIRECTW_LOGFONT; break; + case U_EMR_EXTTEXTOUTA: rsize = U_SIZE_EMREXTTEXTOUTA; break; + case U_EMR_EXTTEXTOUTW: rsize = U_SIZE_EMREXTTEXTOUTW; break; + case U_EMR_POLYBEZIER16: rsize = U_SIZE_EMRPOLYBEZIER16; break; + case U_EMR_POLYGON16: rsize = U_SIZE_EMRPOLYGON16; break; + case U_EMR_POLYLINE16: rsize = U_SIZE_EMRPOLYLINE16; break; + case U_EMR_POLYBEZIERTO16: rsize = U_SIZE_EMRPOLYBEZIERTO16; break; + case U_EMR_POLYLINETO16: rsize = U_SIZE_EMRPOLYLINETO16; break; + case U_EMR_POLYPOLYLINE16: rsize = U_SIZE_EMRPOLYPOLYLINE16; break; + case U_EMR_POLYPOLYGON16: rsize = U_SIZE_EMRPOLYPOLYGON16; break; + case U_EMR_POLYDRAW16: rsize = U_SIZE_EMRPOLYDRAW16; break; + case U_EMR_CREATEMONOBRUSH: rsize = U_SIZE_EMRCREATEMONOBRUSH; break; + case U_EMR_CREATEDIBPATTERNBRUSHPT: rsize = U_SIZE_EMRCREATEDIBPATTERNBRUSHPT; break; + case U_EMR_EXTCREATEPEN: rsize = U_SIZE_EMREXTCREATEPEN; break; + case U_EMR_POLYTEXTOUTA: rsize = U_SIZE_EMRPOLYTEXTOUTA; break; + case U_EMR_POLYTEXTOUTW: rsize = U_SIZE_EMRPOLYTEXTOUTW; break; + case U_EMR_SETICMMODE: rsize = U_SIZE_EMRSETICMMODE; break; + case U_EMR_CREATECOLORSPACE: rsize = U_SIZE_EMRCREATECOLORSPACE; break; + case U_EMR_SETCOLORSPACE: rsize = U_SIZE_EMRSETCOLORSPACE; break; + case U_EMR_DELETECOLORSPACE: rsize = U_SIZE_EMRDELETECOLORSPACE; break; + case U_EMR_GLSRECORD: rsize = U_SIZE_EMRGLSRECORD; break; + case U_EMR_GLSBOUNDEDRECORD: rsize = U_SIZE_EMRGLSBOUNDEDRECORD; break; + case U_EMR_PIXELFORMAT: rsize = U_SIZE_EMRPIXELFORMAT; break; + case U_EMR_DRAWESCAPE: rsize = U_SIZE_EMRDRAWESCAPE; break; + case U_EMR_EXTESCAPE: rsize = U_SIZE_EMREXTESCAPE; break; + case U_EMR_UNDEF107: rsize = U_SIZE_EMRUNDEFINED; break; + case U_EMR_SMALLTEXTOUT: rsize = U_SIZE_EMRSMALLTEXTOUT; break; +// case U_EMR_FORCEUFIMAPPING: rsize = U_SIZE_EMRFORCEUFIMAPPING; break; + case U_EMR_NAMEDESCAPE: rsize = U_SIZE_EMRNAMEDESCAPE; break; +// case U_EMR_COLORCORRECTPALETTE: rsize = U_SIZE_EMRCOLORCORRECTPALETTE; break; +// case U_EMR_SETICMPROFILEA: rsize = U_SIZE_EMRSETICMPROFILEA; break; +// case U_EMR_SETICMPROFILEW: rsize = U_SIZE_EMRSETICMPROFILEW; break; + case U_EMR_ALPHABLEND: rsize = U_SIZE_EMRALPHABLEND; break; + case U_EMR_SETLAYOUT: rsize = U_SIZE_EMRSETLAYOUT; break; + case U_EMR_TRANSPARENTBLT: rsize = U_SIZE_EMRTRANSPARENTBLT; break; + case U_EMR_UNDEF117: rsize = U_SIZE_EMRUNDEFINED; break; + case U_EMR_GRADIENTFILL: rsize = U_SIZE_EMRGRADIENTFILL; break; +// case U_EMR_SETLINKEDUFIS: rsize = U_SIZE_EMRSETLINKEDUFIS; break; +// case U_EMR_SETTEXTJUSTIFICATION: rsize = U_SIZE_EMRSETTEXTJUSTIFICATION; break; + case U_EMR_COLORMATCHTOTARGETW: rsize = U_SIZE_EMRCOLORMATCHTOTARGETW; break; + case U_EMR_CREATECOLORSPACEW: rsize = U_SIZE_EMRCREATECOLORSPACEW; break; + default: rsize = U_SIZE_EMRNOTIMPLEMENTED; break; + } //end of switch + // record's declared size must be more than the minimum size for this type of record + if(*nSize < rsize){ + return(0); + } + return(1); +} + /** \brief Convert an entire EMF in memory from Big Endian to Little Endian. @@ -1622,155 +2113,151 @@ int U_emf_endian(char *contents, size_t length, int torev){ uint32_t off; uint32_t OK, recnum, iType; char *record; - PU_ENHMETARECORD pEmr; + const char *blimit = contents + length; /* should never wrap since it describes a structure in memory */ + int rstatus=1; record = contents; OK = 1; off = 0; recnum = 0; while(OK){ - if(record > contents + length){ // this is most likely a corrupt EMF - return(0); - } - pEmr = (PU_ENHMETARECORD)(record); - - iType = pEmr->iType; - off = pEmr->nSize; - if(!torev){ - U_swap4(&iType,1); - U_swap4(&off,1); + if(!U_emf_record_sizeok(record, blimit, &off, &iType, torev)){ + return(0); } switch (iType) { - case U_EMR_HEADER: U_EMRHEADER_swap(record, torev); break; - case U_EMR_POLYBEZIER: U_EMRPOLYBEZIER_swap(record, torev); break; - case U_EMR_POLYGON: U_EMRPOLYGON_swap(record, torev); break; - case U_EMR_POLYLINE: U_EMRPOLYLINE_swap(record, torev); break; - case U_EMR_POLYBEZIERTO: U_EMRPOLYBEZIERTO_swap(record, torev); break; - case U_EMR_POLYLINETO: U_EMRPOLYLINETO_swap(record, torev); break; - case U_EMR_POLYPOLYLINE: U_EMRPOLYPOLYLINE_swap(record, torev); break; - case U_EMR_POLYPOLYGON: U_EMRPOLYPOLYGON_swap(record, torev); break; - case U_EMR_SETWINDOWEXTEX: U_EMRSETWINDOWEXTEX_swap(record, torev); break; - case U_EMR_SETWINDOWORGEX: U_EMRSETWINDOWORGEX_swap(record, torev); break; - case U_EMR_SETVIEWPORTEXTEX: U_EMRSETVIEWPORTEXTEX_swap(record, torev); break; - case U_EMR_SETVIEWPORTORGEX: U_EMRSETVIEWPORTORGEX_swap(record, torev); break; - case U_EMR_SETBRUSHORGEX: U_EMRSETBRUSHORGEX_swap(record, torev); break; + case U_EMR_HEADER: rstatus=U_EMRHEADER_swap(record, torev); break; + case U_EMR_POLYBEZIER: rstatus=U_EMRPOLYBEZIER_swap(record, torev); break; + case U_EMR_POLYGON: rstatus=U_EMRPOLYGON_swap(record, torev); break; + case U_EMR_POLYLINE: rstatus=U_EMRPOLYLINE_swap(record, torev); break; + case U_EMR_POLYBEZIERTO: rstatus=U_EMRPOLYBEZIERTO_swap(record, torev); break; + case U_EMR_POLYLINETO: rstatus=U_EMRPOLYLINETO_swap(record, torev); break; + case U_EMR_POLYPOLYLINE: rstatus=U_EMRPOLYPOLYLINE_swap(record, torev); break; + case U_EMR_POLYPOLYGON: rstatus=U_EMRPOLYPOLYGON_swap(record, torev); break; + case U_EMR_SETWINDOWEXTEX: rstatus=U_EMRSETWINDOWEXTEX_swap(record, torev); break; + case U_EMR_SETWINDOWORGEX: rstatus=U_EMRSETWINDOWORGEX_swap(record, torev); break; + case U_EMR_SETVIEWPORTEXTEX: rstatus=U_EMRSETVIEWPORTEXTEX_swap(record, torev); break; + case U_EMR_SETVIEWPORTORGEX: rstatus=U_EMRSETVIEWPORTORGEX_swap(record, torev); break; + case U_EMR_SETBRUSHORGEX: rstatus=U_EMRSETBRUSHORGEX_swap(record, torev); break; case U_EMR_EOF: - U_EMREOF_swap(record, torev); + rstatus=U_EMREOF_swap(record, torev); OK = 0; /* Exit triggered here */ break; - case U_EMR_SETPIXELV: U_EMRSETPIXELV_swap(record, torev); break; - case U_EMR_SETMAPPERFLAGS: U_EMRSETMAPPERFLAGS_swap(record, torev); break; - case U_EMR_SETMAPMODE: U_EMRSETMAPMODE_swap(record, torev); break; - case U_EMR_SETBKMODE: U_EMRSETBKMODE_swap(record, torev); break; - case U_EMR_SETPOLYFILLMODE: U_EMRSETPOLYFILLMODE_swap(record, torev); break; - case U_EMR_SETROP2: U_EMRSETROP2_swap(record, torev); break; - case U_EMR_SETSTRETCHBLTMODE: U_EMRSETSTRETCHBLTMODE_swap(record, torev); break; - case U_EMR_SETTEXTALIGN: U_EMRSETTEXTALIGN_swap(record, torev); break; - case U_EMR_SETCOLORADJUSTMENT: U_EMRSETCOLORADJUSTMENT_swap(record, torev); break; - case U_EMR_SETTEXTCOLOR: U_EMRSETTEXTCOLOR_swap(record, torev); break; - case U_EMR_SETBKCOLOR: U_EMRSETBKCOLOR_swap(record, torev); break; - case U_EMR_OFFSETCLIPRGN: U_EMROFFSETCLIPRGN_swap(record, torev); break; - case U_EMR_MOVETOEX: U_EMRMOVETOEX_swap(record, torev); break; - case U_EMR_SETMETARGN: U_EMRSETMETARGN_swap(record, torev); break; - case U_EMR_EXCLUDECLIPRECT: U_EMREXCLUDECLIPRECT_swap(record, torev); break; - case U_EMR_INTERSECTCLIPRECT: U_EMRINTERSECTCLIPRECT_swap(record, torev); break; - case U_EMR_SCALEVIEWPORTEXTEX: U_EMRSCALEVIEWPORTEXTEX_swap(record, torev); break; - case U_EMR_SCALEWINDOWEXTEX: U_EMRSCALEWINDOWEXTEX_swap(record, torev); break; - case U_EMR_SAVEDC: U_EMRSAVEDC_swap(record, torev); break; - case U_EMR_RESTOREDC: U_EMRRESTOREDC_swap(record, torev); break; - case U_EMR_SETWORLDTRANSFORM: U_EMRSETWORLDTRANSFORM_swap(record, torev); break; - case U_EMR_MODIFYWORLDTRANSFORM: U_EMRMODIFYWORLDTRANSFORM_swap(record, torev); break; - case U_EMR_SELECTOBJECT: U_EMRSELECTOBJECT_swap(record, torev); break; - case U_EMR_CREATEPEN: U_EMRCREATEPEN_swap(record, torev); break; - case U_EMR_CREATEBRUSHINDIRECT: U_EMRCREATEBRUSHINDIRECT_swap(record, torev); break; - case U_EMR_DELETEOBJECT: U_EMRDELETEOBJECT_swap(record, torev); break; - case U_EMR_ANGLEARC: U_EMRANGLEARC_swap(record, torev); break; - case U_EMR_ELLIPSE: U_EMRELLIPSE_swap(record, torev); break; - case U_EMR_RECTANGLE: U_EMRRECTANGLE_swap(record, torev); break; - case U_EMR_ROUNDRECT: U_EMRROUNDRECT_swap(record, torev); break; - case U_EMR_ARC: U_EMRARC_swap(record, torev); break; - case U_EMR_CHORD: U_EMRCHORD_swap(record, torev); break; - case U_EMR_PIE: U_EMRPIE_swap(record, torev); break; - case U_EMR_SELECTPALETTE: U_EMRSELECTPALETTE_swap(record, torev); break; - case U_EMR_CREATEPALETTE: U_EMRCREATEPALETTE_swap(record, torev); break; - case U_EMR_SETPALETTEENTRIES: U_EMRSETPALETTEENTRIES_swap(record, torev); break; - case U_EMR_RESIZEPALETTE: U_EMRRESIZEPALETTE_swap(record, torev); break; - case U_EMR_REALIZEPALETTE: U_EMRREALIZEPALETTE_swap(record, torev); break; - case U_EMR_EXTFLOODFILL: U_EMREXTFLOODFILL_swap(record, torev); break; - case U_EMR_LINETO: U_EMRLINETO_swap(record, torev); break; - case U_EMR_ARCTO: U_EMRARCTO_swap(record, torev); break; - case U_EMR_POLYDRAW: U_EMRPOLYDRAW_swap(record, torev); break; - case U_EMR_SETARCDIRECTION: U_EMRSETARCDIRECTION_swap(record, torev); break; - case U_EMR_SETMITERLIMIT: U_EMRSETMITERLIMIT_swap(record, torev); break; - case U_EMR_BEGINPATH: U_EMRBEGINPATH_swap(record, torev); break; - case U_EMR_ENDPATH: U_EMRENDPATH_swap(record, torev); break; - case U_EMR_CLOSEFIGURE: U_EMRCLOSEFIGURE_swap(record, torev); break; - case U_EMR_FILLPATH: U_EMRFILLPATH_swap(record, torev); break; - case U_EMR_STROKEANDFILLPATH: U_EMRSTROKEANDFILLPATH_swap(record, torev); break; - case U_EMR_STROKEPATH: U_EMRSTROKEPATH_swap(record, torev); break; - case U_EMR_FLATTENPATH: U_EMRFLATTENPATH_swap(record, torev); break; - case U_EMR_WIDENPATH: U_EMRWIDENPATH_swap(record, torev); break; - case U_EMR_SELECTCLIPPATH: U_EMRSELECTCLIPPATH_swap(record, torev); break; - case U_EMR_ABORTPATH: U_EMRABORTPATH_swap(record, torev); break; - case U_EMR_UNDEF69: U_EMRUNDEF69_swap(record, torev); break; - case U_EMR_COMMENT: U_EMRCOMMENT_swap(record, torev); break; - case U_EMR_FILLRGN: U_EMRFILLRGN_swap(record, torev); break; - case U_EMR_FRAMERGN: U_EMRFRAMERGN_swap(record, torev); break; - case U_EMR_INVERTRGN: U_EMRINVERTRGN_swap(record, torev); break; - case U_EMR_PAINTRGN: U_EMRPAINTRGN_swap(record, torev); break; - case U_EMR_EXTSELECTCLIPRGN: U_EMREXTSELECTCLIPRGN_swap(record, torev); break; - case U_EMR_BITBLT: U_EMRBITBLT_swap(record, torev); break; - case U_EMR_STRETCHBLT: U_EMRSTRETCHBLT_swap(record, torev); break; - case U_EMR_MASKBLT: U_EMRMASKBLT_swap(record, torev); break; - case U_EMR_PLGBLT: U_EMRPLGBLT_swap(record, torev); break; - case U_EMR_SETDIBITSTODEVICE: U_EMRSETDIBITSTODEVICE_swap(record, torev); break; - case U_EMR_STRETCHDIBITS: U_EMRSTRETCHDIBITS_swap(record, torev); break; - case U_EMR_EXTCREATEFONTINDIRECTW: U_EMREXTCREATEFONTINDIRECTW_swap(record, torev); break; - case U_EMR_EXTTEXTOUTA: U_EMREXTTEXTOUTA_swap(record, torev); break; - case U_EMR_EXTTEXTOUTW: U_EMREXTTEXTOUTW_swap(record, torev); break; - case U_EMR_POLYBEZIER16: U_EMRPOLYBEZIER16_swap(record, torev); break; - case U_EMR_POLYGON16: U_EMRPOLYGON16_swap(record, torev); break; - case U_EMR_POLYLINE16: U_EMRPOLYLINE16_swap(record, torev); break; - case U_EMR_POLYBEZIERTO16: U_EMRPOLYBEZIERTO16_swap(record, torev); break; - case U_EMR_POLYLINETO16: U_EMRPOLYLINETO16_swap(record, torev); break; - case U_EMR_POLYPOLYLINE16: U_EMRPOLYPOLYLINE16_swap(record, torev); break; - case U_EMR_POLYPOLYGON16: U_EMRPOLYPOLYGON16_swap(record, torev); break; - case U_EMR_POLYDRAW16: U_EMRPOLYDRAW16_swap(record, torev); break; - case U_EMR_CREATEMONOBRUSH: U_EMRCREATEMONOBRUSH_swap(record, torev); break; - case U_EMR_CREATEDIBPATTERNBRUSHPT: U_EMRCREATEDIBPATTERNBRUSHPT_swap(record, torev); break; - case U_EMR_EXTCREATEPEN: U_EMREXTCREATEPEN_swap(record, torev); break; - case U_EMR_POLYTEXTOUTA: U_EMRPOLYTEXTOUTA_swap(record, torev); break; - case U_EMR_POLYTEXTOUTW: U_EMRPOLYTEXTOUTW_swap(record, torev); break; - case U_EMR_SETICMMODE: U_EMRSETICMMODE_swap(record, torev); break; - case U_EMR_CREATECOLORSPACE: U_EMRCREATECOLORSPACE_swap(record, torev); break; - case U_EMR_SETCOLORSPACE: U_EMRSETCOLORSPACE_swap(record, torev); break; - case U_EMR_DELETECOLORSPACE: U_EMRDELETECOLORSPACE_swap(record, torev); break; - case U_EMR_GLSRECORD: U_EMRGLSRECORD_swap(record, torev); break; - case U_EMR_GLSBOUNDEDRECORD: U_EMRGLSBOUNDEDRECORD_swap(record, torev); break; - case U_EMR_PIXELFORMAT: U_EMRPIXELFORMAT_swap(record, torev); break; - case U_EMR_DRAWESCAPE: U_EMRDRAWESCAPE_swap(record, torev); break; - case U_EMR_EXTESCAPE: U_EMREXTESCAPE_swap(record, torev); break; - case U_EMR_UNDEF107: U_EMRUNDEF107_swap(record, torev); break; - case U_EMR_SMALLTEXTOUT: U_EMRSMALLTEXTOUT_swap(record, torev); break; - case U_EMR_FORCEUFIMAPPING: U_EMRFORCEUFIMAPPING_swap(record, torev); break; - case U_EMR_NAMEDESCAPE: U_EMRNAMEDESCAPE_swap(record, torev); break; - case U_EMR_COLORCORRECTPALETTE: U_EMRCOLORCORRECTPALETTE_swap(record, torev); break; - case U_EMR_SETICMPROFILEA: U_EMRSETICMPROFILEA_swap(record, torev); break; - case U_EMR_SETICMPROFILEW: U_EMRSETICMPROFILEW_swap(record, torev); break; - case U_EMR_ALPHABLEND: U_EMRALPHABLEND_swap(record, torev); break; - case U_EMR_SETLAYOUT: U_EMRSETLAYOUT_swap(record, torev); break; - case U_EMR_TRANSPARENTBLT: U_EMRTRANSPARENTBLT_swap(record, torev); break; - case U_EMR_UNDEF117: U_EMRUNDEF117_swap(record, torev); break; - case U_EMR_GRADIENTFILL: U_EMRGRADIENTFILL_swap(record, torev); break; - case U_EMR_SETLINKEDUFIS: U_EMRSETLINKEDUFIS_swap(record, torev); break; - case U_EMR_SETTEXTJUSTIFICATION: U_EMRSETTEXTJUSTIFICATION_swap(record, torev); break; - case U_EMR_COLORMATCHTOTARGETW: U_EMRCOLORMATCHTOTARGETW_swap(record, torev); break; - case U_EMR_CREATECOLORSPACEW: U_EMRCREATECOLORSPACEW_swap(record, torev); break; - default: U_EMRNOTIMPLEMENTED_swap(record, torev); break; + case U_EMR_SETPIXELV: rstatus=U_EMRSETPIXELV_swap(record, torev); break; + case U_EMR_SETMAPPERFLAGS: rstatus=U_EMRSETMAPPERFLAGS_swap(record, torev); break; + case U_EMR_SETMAPMODE: rstatus=U_EMRSETMAPMODE_swap(record, torev); break; + case U_EMR_SETBKMODE: rstatus=U_EMRSETBKMODE_swap(record, torev); break; + case U_EMR_SETPOLYFILLMODE: rstatus=U_EMRSETPOLYFILLMODE_swap(record, torev); break; + case U_EMR_SETROP2: rstatus=U_EMRSETROP2_swap(record, torev); break; + case U_EMR_SETSTRETCHBLTMODE: rstatus=U_EMRSETSTRETCHBLTMODE_swap(record, torev); break; + case U_EMR_SETTEXTALIGN: rstatus=U_EMRSETTEXTALIGN_swap(record, torev); break; + case U_EMR_SETCOLORADJUSTMENT: rstatus=U_EMRSETCOLORADJUSTMENT_swap(record, torev); break; + case U_EMR_SETTEXTCOLOR: rstatus=U_EMRSETTEXTCOLOR_swap(record, torev); break; + case U_EMR_SETBKCOLOR: rstatus=U_EMRSETBKCOLOR_swap(record, torev); break; + case U_EMR_OFFSETCLIPRGN: rstatus=U_EMROFFSETCLIPRGN_swap(record, torev); break; + case U_EMR_MOVETOEX: rstatus=U_EMRMOVETOEX_swap(record, torev); break; + case U_EMR_SETMETARGN: rstatus=U_EMRSETMETARGN_swap(record, torev); break; + case U_EMR_EXCLUDECLIPRECT: rstatus=U_EMREXCLUDECLIPRECT_swap(record, torev); break; + case U_EMR_INTERSECTCLIPRECT: rstatus=U_EMRINTERSECTCLIPRECT_swap(record, torev); break; + case U_EMR_SCALEVIEWPORTEXTEX: rstatus=U_EMRSCALEVIEWPORTEXTEX_swap(record, torev); break; + case U_EMR_SCALEWINDOWEXTEX: rstatus=U_EMRSCALEWINDOWEXTEX_swap(record, torev); break; + case U_EMR_SAVEDC: rstatus=U_EMRSAVEDC_swap(record, torev); break; + case U_EMR_RESTOREDC: rstatus=U_EMRRESTOREDC_swap(record, torev); break; + case U_EMR_SETWORLDTRANSFORM: rstatus=U_EMRSETWORLDTRANSFORM_swap(record, torev); break; + case U_EMR_MODIFYWORLDTRANSFORM: rstatus=U_EMRMODIFYWORLDTRANSFORM_swap(record, torev); break; + case U_EMR_SELECTOBJECT: rstatus=U_EMRSELECTOBJECT_swap(record, torev); break; + case U_EMR_CREATEPEN: rstatus=U_EMRCREATEPEN_swap(record, torev); break; + case U_EMR_CREATEBRUSHINDIRECT: rstatus=U_EMRCREATEBRUSHINDIRECT_swap(record, torev); break; + case U_EMR_DELETEOBJECT: rstatus=U_EMRDELETEOBJECT_swap(record, torev); break; + case U_EMR_ANGLEARC: rstatus=U_EMRANGLEARC_swap(record, torev); break; + case U_EMR_ELLIPSE: rstatus=U_EMRELLIPSE_swap(record, torev); break; + case U_EMR_RECTANGLE: rstatus=U_EMRRECTANGLE_swap(record, torev); break; + case U_EMR_ROUNDRECT: rstatus=U_EMRROUNDRECT_swap(record, torev); break; + case U_EMR_ARC: rstatus=U_EMRARC_swap(record, torev); break; + case U_EMR_CHORD: rstatus=U_EMRCHORD_swap(record, torev); break; + case U_EMR_PIE: rstatus=U_EMRPIE_swap(record, torev); break; + case U_EMR_SELECTPALETTE: rstatus=U_EMRSELECTPALETTE_swap(record, torev); break; + case U_EMR_CREATEPALETTE: rstatus=U_EMRCREATEPALETTE_swap(record, torev); break; + case U_EMR_SETPALETTEENTRIES: rstatus=U_EMRSETPALETTEENTRIES_swap(record, torev); break; + case U_EMR_RESIZEPALETTE: rstatus=U_EMRRESIZEPALETTE_swap(record, torev); break; + case U_EMR_REALIZEPALETTE: rstatus=U_EMRREALIZEPALETTE_swap(record, torev); break; + case U_EMR_EXTFLOODFILL: rstatus=U_EMREXTFLOODFILL_swap(record, torev); break; + case U_EMR_LINETO: rstatus=U_EMRLINETO_swap(record, torev); break; + case U_EMR_ARCTO: rstatus=U_EMRARCTO_swap(record, torev); break; + case U_EMR_POLYDRAW: rstatus=U_EMRPOLYDRAW_swap(record, torev); break; + case U_EMR_SETARCDIRECTION: rstatus=U_EMRSETARCDIRECTION_swap(record, torev); break; + case U_EMR_SETMITERLIMIT: rstatus=U_EMRSETMITERLIMIT_swap(record, torev); break; + case U_EMR_BEGINPATH: rstatus=U_EMRBEGINPATH_swap(record, torev); break; + case U_EMR_ENDPATH: rstatus=U_EMRENDPATH_swap(record, torev); break; + case U_EMR_CLOSEFIGURE: rstatus=U_EMRCLOSEFIGURE_swap(record, torev); break; + case U_EMR_FILLPATH: rstatus=U_EMRFILLPATH_swap(record, torev); break; + case U_EMR_STROKEANDFILLPATH: rstatus=U_EMRSTROKEANDFILLPATH_swap(record, torev); break; + case U_EMR_STROKEPATH: rstatus=U_EMRSTROKEPATH_swap(record, torev); break; + case U_EMR_FLATTENPATH: rstatus=U_EMRFLATTENPATH_swap(record, torev); break; + case U_EMR_WIDENPATH: rstatus=U_EMRWIDENPATH_swap(record, torev); break; + case U_EMR_SELECTCLIPPATH: rstatus=U_EMRSELECTCLIPPATH_swap(record, torev); break; + case U_EMR_ABORTPATH: rstatus=U_EMRABORTPATH_swap(record, torev); break; + case U_EMR_UNDEF69: rstatus=U_EMRUNDEF69_swap(record, torev); break; + case U_EMR_COMMENT: rstatus=U_EMRCOMMENT_swap(record, torev); break; + case U_EMR_FILLRGN: rstatus=U_EMRFILLRGN_swap(record, torev); break; + case U_EMR_FRAMERGN: rstatus=U_EMRFRAMERGN_swap(record, torev); break; + case U_EMR_INVERTRGN: rstatus=U_EMRINVERTRGN_swap(record, torev); break; + case U_EMR_PAINTRGN: rstatus=U_EMRPAINTRGN_swap(record, torev); break; + case U_EMR_EXTSELECTCLIPRGN: rstatus=U_EMREXTSELECTCLIPRGN_swap(record, torev);break; + case U_EMR_BITBLT: rstatus=U_EMRBITBLT_swap(record, torev); break; + case U_EMR_STRETCHBLT: rstatus=U_EMRSTRETCHBLT_swap(record, torev); break; + case U_EMR_MASKBLT: rstatus=U_EMRMASKBLT_swap(record, torev); break; + case U_EMR_PLGBLT: rstatus=U_EMRPLGBLT_swap(record, torev); break; + case U_EMR_SETDIBITSTODEVICE: rstatus=U_EMRSETDIBITSTODEVICE_swap(record, torev); break; + case U_EMR_STRETCHDIBITS: rstatus=U_EMRSTRETCHDIBITS_swap(record, torev); break; + case U_EMR_EXTCREATEFONTINDIRECTW: rstatus=U_EMREXTCREATEFONTINDIRECTW_swap(record, torev); break; + case U_EMR_EXTTEXTOUTA: rstatus=U_EMREXTTEXTOUTA_swap(record, torev); break; + case U_EMR_EXTTEXTOUTW: rstatus=U_EMREXTTEXTOUTW_swap(record, torev); break; + case U_EMR_POLYBEZIER16: rstatus=U_EMRPOLYBEZIER16_swap(record, torev); break; + case U_EMR_POLYGON16: rstatus=U_EMRPOLYGON16_swap(record, torev); break; + case U_EMR_POLYLINE16: rstatus=U_EMRPOLYLINE16_swap(record, torev); break; + case U_EMR_POLYBEZIERTO16: rstatus=U_EMRPOLYBEZIERTO16_swap(record, torev); break; + case U_EMR_POLYLINETO16: rstatus=U_EMRPOLYLINETO16_swap(record, torev); break; + case U_EMR_POLYPOLYLINE16: rstatus=U_EMRPOLYPOLYLINE16_swap(record, torev); break; + case U_EMR_POLYPOLYGON16: rstatus=U_EMRPOLYPOLYGON16_swap(record, torev); break; + case U_EMR_POLYDRAW16: rstatus=U_EMRPOLYDRAW16_swap(record, torev); break; + case U_EMR_CREATEMONOBRUSH: rstatus=U_EMRCREATEMONOBRUSH_swap(record, torev); break; + case U_EMR_CREATEDIBPATTERNBRUSHPT: rstatus=U_EMRCREATEDIBPATTERNBRUSHPT_swap(record, torev); break; + case U_EMR_EXTCREATEPEN: rstatus=U_EMREXTCREATEPEN_swap(record, torev); break; + case U_EMR_POLYTEXTOUTA: rstatus=U_EMRPOLYTEXTOUTA_swap(record, torev); break; + case U_EMR_POLYTEXTOUTW: rstatus=U_EMRPOLYTEXTOUTW_swap(record, torev); break; + case U_EMR_SETICMMODE: rstatus=U_EMRSETICMMODE_swap(record, torev); break; + case U_EMR_CREATECOLORSPACE: rstatus=U_EMRCREATECOLORSPACE_swap(record, torev); break; + case U_EMR_SETCOLORSPACE: rstatus=U_EMRSETCOLORSPACE_swap(record, torev); break; + case U_EMR_DELETECOLORSPACE: rstatus=U_EMRDELETECOLORSPACE_swap(record, torev); break; + case U_EMR_GLSRECORD: rstatus=U_EMRGLSRECORD_swap(record, torev); break; + case U_EMR_GLSBOUNDEDRECORD: rstatus=U_EMRGLSBOUNDEDRECORD_swap(record, torev); break; + case U_EMR_PIXELFORMAT: rstatus=U_EMRPIXELFORMAT_swap(record, torev); break; + case U_EMR_DRAWESCAPE: rstatus=U_EMRDRAWESCAPE_swap(record, torev); break; + case U_EMR_EXTESCAPE: rstatus=U_EMREXTESCAPE_swap(record, torev); break; + case U_EMR_UNDEF107: rstatus=U_EMRUNDEF107_swap(record, torev); break; + case U_EMR_SMALLTEXTOUT: rstatus=U_EMRSMALLTEXTOUT_swap(record, torev); break; + case U_EMR_FORCEUFIMAPPING: rstatus=U_EMRFORCEUFIMAPPING_swap(record, torev); break; + case U_EMR_NAMEDESCAPE: rstatus=U_EMRNAMEDESCAPE_swap(record, torev); break; + case U_EMR_COLORCORRECTPALETTE: rstatus=U_EMRCOLORCORRECTPALETTE_swap(record, torev); break; + case U_EMR_SETICMPROFILEA: rstatus=U_EMRSETICMPROFILEA_swap(record, torev); break; + case U_EMR_SETICMPROFILEW: rstatus=U_EMRSETICMPROFILEW_swap(record, torev); break; + case U_EMR_ALPHABLEND: rstatus=U_EMRALPHABLEND_swap(record, torev); break; + case U_EMR_SETLAYOUT: rstatus=U_EMRSETLAYOUT_swap(record, torev); break; + case U_EMR_TRANSPARENTBLT: rstatus=U_EMRTRANSPARENTBLT_swap(record, torev); break; + case U_EMR_UNDEF117: rstatus=U_EMRUNDEF117_swap(record, torev); break; + case U_EMR_GRADIENTFILL: rstatus=U_EMRGRADIENTFILL_swap(record, torev); break; + case U_EMR_SETLINKEDUFIS: rstatus=U_EMRSETLINKEDUFIS_swap(record, torev); break; + case U_EMR_SETTEXTJUSTIFICATION: rstatus=U_EMRSETTEXTJUSTIFICATION_swap(record, torev); break; + case U_EMR_COLORMATCHTOTARGETW: rstatus=U_EMRCOLORMATCHTOTARGETW_swap(record, torev); break; + case U_EMR_CREATECOLORSPACEW: rstatus=U_EMRCREATECOLORSPACEW_swap(record, torev); break; + default: rstatus=U_EMRNOTIMPLEMENTED_swap(record, torev); break; } //end of switch + if(!rstatus){ + return(rstatus); + } record += off; recnum++; } //end of while diff --git a/src/libuemf/uemf_endian.h b/src/libuemf/uemf_endian.h index 317968c34..9dbcec455 100644 --- a/src/libuemf/uemf_endian.h +++ b/src/libuemf/uemf_endian.h @@ -6,11 +6,11 @@ /* File: uemf_endian.h -Version: 0.0.3 -Date: 24-JUL-2012 +Version: 0.0.4 +Date: 24-MAR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2012 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifndef _UEMF_ENDIAN_ @@ -49,6 +49,7 @@ extern "C" { //! \cond // prototypes int U_emf_endian(char *contents, size_t length, int torev); +int U_emf_record_sizeok(const char *record, const char *blimit, uint32_t *nSize, uint32_t *iType, int torev); //! \endcond #ifdef __cplusplus diff --git a/src/libuemf/uemf_print.c b/src/libuemf/uemf_print.c index aa574bd73..adcf54c0f 100644 --- a/src/libuemf/uemf_print.c +++ b/src/libuemf/uemf_print.c @@ -6,11 +6,11 @@ /* File: uemf_print.c -Version: 0.0.15 -Date: 17-OCT-2013 +Version: 0.0.18 +Date: 25-MAR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2013 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifdef __cplusplus @@ -23,9 +23,12 @@ extern "C" { #include #include "uemf.h" #include "upmf_print.h" +#include "uemf_safe.h" //! \cond #define UNUSED(x) (void)(x) +/* This bit of code is used all over the place, so reduce it to a DEFINITION */ +#define IF_MEM_UNSAFE_PRINT_AND_RETURN(A,B,C) if(IS_MEM_UNSAFE(A,B,C)){printf(" record corruption HERE\n"); return; } /* one needed prototype */ void U_swap4(void *ul, unsigned int count); @@ -364,24 +367,28 @@ int bitmapinfoheader_print( /** \brief Print a Pointer to a U_BITMAPINFO object. \param Bmi Pointer to a U_BITMAPINFO object + \param blimit Pointer to the first byte after after this record This may be called from WMF _print routines, where problems could occur if the data was passed as the struct or a pointer to the struct, as the struct may not be aligned in memory. */ void bitmapinfo_print( - const char *Bmi + const char *Bmi, + const char *blimit ){ int i,k; int ClrUsed; U_RGBQUAD BmiColor; printf("BmiHeader: "); + IF_MEM_UNSAFE_PRINT_AND_RETURN(Bmi, offsetof(U_BITMAPINFO,bmiHeader) + sizeof(U_BITMAPINFOHEADER), blimit); ClrUsed = bitmapinfoheader_print(Bmi + offsetof(U_BITMAPINFO,bmiHeader)); if(ClrUsed){ - k= offsetof(U_BITMAPINFO,bmiColors); - for(i=0; irdh ); + IF_MEM_UNSAFE_PRINT_AND_RETURN(rd, sizeof(U_RGNDATAHEADER), blimit); + printf("rdh: "); rgndataheader_print(rd->rdh ); printf(" rects: "); if(rd->rdh.nCount){ rects = (PU_RECTL) &(rd->Buffer); + IF_MEM_UNSAFE_PRINT_AND_RETURN(rects, rd->rdh.nCount * sizeof(U_RECTL), blimit); for(i=0;irdh.nCount;i++){ printf("%d:",i); rectl_print(rects[i]); } @@ -559,11 +570,13 @@ void pixelformatdescriptor_print( \brief Print a Pointer to a U_EMRTEXT record \param emt Pointer to a U_EMRTEXT record \param record Pointer to the start of the record which contains this U_ERMTEXT + \param blimit Pointer to the first byte after after this record \param type 0 for 8 bit character, anything else for 16 */ void emrtext_print( const char *emt, const char *record, + const char *blimit, int type ){ unsigned int i,off; @@ -575,9 +588,11 @@ void emrtext_print( printf("offString:%u " ,pemt->offString ); if(pemt->offString){ if(!type){ + IF_MEM_UNSAFE_PRINT_AND_RETURN(record, pemt->offString + pemt->nChars*sizeof(char), blimit); printf("string8:<%s> ",record + pemt->offString); } else { + IF_MEM_UNSAFE_PRINT_AND_RETURN(record, pemt->offString + pemt->nChars*2*sizeof(char), blimit); string = U_Utf16leToUtf8((uint16_t *)(record + pemt->offString), pemt->nChars, NULL); printf("string16:<%s> ",string); free(string); @@ -622,9 +637,15 @@ void core1_print(const char *name, const char *contents){ unsigned int i; UNUSED(name); PU_EMRPOLYLINETO pEmr = (PU_EMRPOLYLINETO) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRPOLYBEZIER)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n"); printf(" cptl: %d\n",pEmr->cptl ); printf(" Points: "); + IF_MEM_UNSAFE_PRINT_AND_RETURN(pEmr->aptl, pEmr->cptl*sizeof(U_POINTL), blimit); for(i=0;icptl; i++){ printf("[%d]:",i); pointl_print(pEmr->aptl[i]); } @@ -636,16 +657,23 @@ void core2_print(const char *name, const char *contents){ unsigned int i; UNUSED(name); PU_EMRPOLYPOLYGON pEmr = (PU_EMRPOLYPOLYGON) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRPOLYPOLYGON)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n"); printf(" nPolys: %d\n",pEmr->nPolys ); printf(" cptl: %d\n",pEmr->cptl ); printf(" Counts: "); + IF_MEM_UNSAFE_PRINT_AND_RETURN(pEmr->aPolyCounts, pEmr->nPolys*sizeof(U_POLYCOUNTS), blimit); for(i=0;inPolys; i++){ printf(" [%d]:%d ",i,pEmr->aPolyCounts[i] ); } printf("\n"); PU_POINTL paptl = (PU_POINTL)((char *)pEmr->aPolyCounts + sizeof(uint32_t)* pEmr->nPolys); printf(" Points: "); + IF_MEM_UNSAFE_PRINT_AND_RETURN(paptl, pEmr->cptl*sizeof(U_POINTL), blimit); for(i=0;icptl; i++){ printf(" [%d]:",i); pointl_print(paptl[i]); } @@ -656,7 +684,12 @@ void core2_print(const char *name, const char *contents){ // Functions with the same form starting with U_EMRSETMAPMODE_print void core3_print(const char *name, const char *label, const char *contents){ UNUSED(name); + /* access violation is impossible for these because there are no counts or offsets */ PU_EMRSETMAPMODE pEmr = (PU_EMRSETMAPMODE)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRSETMAPMODE)){ + printf(" record corruption HERE\n"); + return; + } if(!strcmp(label,"crColor:")){ printf(" %-15s ",label); colorref_print(*(U_COLORREF *)&(pEmr->iMode)); printf("\n"); } @@ -672,6 +705,10 @@ void core3_print(const char *name, const char *label, const char *contents){ void core4_print(const char *name, const char *contents){ UNUSED(name); PU_EMRELLIPSE pEmr = (PU_EMRELLIPSE)( contents); + if(pEmr->emr.nSize < sizeof(U_EMRELLIPSE)){ + printf(" record corruption HERE\n"); + return; + } printf(" rclBox: "); rectl_print(pEmr->rclBox); printf("\n"); } @@ -680,10 +717,16 @@ void core6_print(const char *name, const char *contents){ UNUSED(name); unsigned int i; PU_EMRPOLYBEZIER16 pEmr = (PU_EMRPOLYBEZIER16) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRPOLYBEZIER16)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n"); printf(" cpts: %d\n",pEmr->cpts ); printf(" Points: "); PU_POINT16 papts = (PU_POINT16)(&(pEmr->apts)); + IF_MEM_UNSAFE_PRINT_AND_RETURN(papts, pEmr->cpts*sizeof(U_POINT16), blimit); for(i=0; icpts; i++){ printf(" [%d]:",i); point16_print(papts[i]); } @@ -698,6 +741,10 @@ void core6_print(const char *name, const char *contents){ void core7_print(const char *name, const char *field1, const char *field2, const char *contents){ UNUSED(name); PU_EMRGENERICPAIR pEmr = (PU_EMRGENERICPAIR) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRGENERICPAIR)){ + printf(" record corruption HERE\n"); + return; + } if(*field2){ printf(" %-15s %d\n",field1,pEmr->pair.x); printf(" %-15s %d\n",field2,pEmr->pair.y); @@ -711,12 +758,13 @@ void core7_print(const char *name, const char *field1, const char *field2, const void core8_print(const char *name, const char *contents, int type){ UNUSED(name); PU_EMREXTTEXTOUTA pEmr = (PU_EMREXTTEXTOUTA) (contents); + const char *blimit = contents + pEmr->emr.nSize; printf(" iGraphicsMode: %u\n",pEmr->iGraphicsMode ); printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n"); printf(" exScale: %f\n",pEmr->exScale ); printf(" eyScale: %f\n",pEmr->eyScale ); printf(" emrtext: "); - emrtext_print(contents + sizeof(U_EMREXTTEXTOUTA) - sizeof(U_EMRTEXT),contents,type); + emrtext_print(contents + sizeof(U_EMREXTTEXTOUTA) - sizeof(U_EMRTEXT),contents,blimit,type); printf("\n"); } @@ -724,6 +772,10 @@ void core8_print(const char *name, const char *contents, int type){ void core9_print(const char *name, const char *contents){ UNUSED(name); PU_EMRARC pEmr = (PU_EMRARC) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRARC)){ + printf(" record corruption HERE\n"); + return; + } printf(" rclBox: "); rectl_print(pEmr->rclBox); printf("\n"); printf(" ptlStart: "); pointl_print(pEmr->ptlStart); printf("\n"); printf(" ptlEnd: "); pointl_print(pEmr->ptlEnd); printf("\n"); @@ -734,16 +786,23 @@ void core10_print(const char *name, const char *contents){ UNUSED(name); unsigned int i; PU_EMRPOLYPOLYLINE16 pEmr = (PU_EMRPOLYPOLYLINE16) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRPOLYPOLYLINE16)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n"); printf(" nPolys: %d\n",pEmr->nPolys ); printf(" cpts: %d\n",pEmr->cpts ); printf(" Counts: "); + IF_MEM_UNSAFE_PRINT_AND_RETURN(&(pEmr->aPolyCounts), pEmr->nPolys*sizeof(U_POLYCOUNTS), blimit); for(i=0;inPolys; i++){ printf(" [%d]:%d ",i,pEmr->aPolyCounts[i] ); } printf("\n"); printf(" Points: "); - PU_POINT16 papts = (PU_POINT16)((char *)pEmr->aPolyCounts + sizeof(uint32_t)* pEmr->nPolys); + PU_POINT16 papts = (PU_POINT16)((char *)pEmr->aPolyCounts + pEmr->nPolys*sizeof(U_POLYCOUNTS) ); + IF_MEM_UNSAFE_PRINT_AND_RETURN(papts, pEmr->cpts*sizeof(U_POINT16), blimit); for(i=0; icpts; i++){ printf(" [%d]:",i); point16_print(papts[i]); } @@ -754,20 +813,18 @@ void core10_print(const char *name, const char *contents){ // Functions with the same form starting with U_EMRINVERTRGN_print and U_EMRPAINTRGN_print, void core11_print(const char *name, const char *contents){ UNUSED(name); - unsigned int i,roff; PU_EMRINVERTRGN pEmr = (PU_EMRINVERTRGN) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRINVERTRGN)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n"); printf(" cbRgnData: %d\n",pEmr->cbRgnData); - // This one is a pain since each RGNDATA may be a different size, so it isn't possible to index through them. - roff=0; - i=1; - char *prd = (char *) &(pEmr->RgnData); - while(roff + sizeof(U_RGNDATAHEADER) < pEmr->cbRgnData){ // stop at end of the record 4*4 = header + 4*4=rect - printf(" RegionData:%d",i); - rgndata_print((PU_RGNDATA) (prd + roff)); - roff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - printf("\n"); - } + printf(" RegionData:"); + const char *minptr = MAKE_MIN_PTR(((const char *) &pEmr->RgnData + pEmr->cbRgnData),blimit); + rgndata_print(pEmr->RgnData, minptr); + printf("\n"); } @@ -775,13 +832,18 @@ void core11_print(const char *name, const char *contents){ void core12_print(const char *name, const char *contents){ UNUSED(name); PU_EMRCREATEMONOBRUSH pEmr = (PU_EMRCREATEMONOBRUSH) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRCREATEMONOBRUSH)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" ihBrush: %u\n",pEmr->ihBrush ); printf(" iUsage : %u\n",pEmr->iUsage ); printf(" offBmi : %u\n",pEmr->offBmi ); printf(" cbBmi : %u\n",pEmr->cbBmi ); if(pEmr->cbBmi){ printf(" bitmap:"); - bitmapinfo_print(contents + pEmr->offBmi); + bitmapinfo_print(contents + pEmr->offBmi, blimit); printf("\n"); } printf(" offBits: %u\n",pEmr->offBits ); @@ -792,6 +854,11 @@ void core12_print(const char *name, const char *contents){ void core13_print(const char *name, const char *contents){ UNUSED(name); PU_EMRALPHABLEND pEmr = (PU_EMRALPHABLEND) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRALPHABLEND)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" Dest: "); pointl_print(pEmr->Dest); printf("\n"); printf(" cDest: "); pointl_print(pEmr->cDest); printf("\n"); @@ -804,7 +871,7 @@ void core13_print(const char *name, const char *contents){ printf(" cbBmiSrc: %u\n",pEmr->cbBmiSrc ); if(pEmr->cbBmiSrc){ printf(" bitmap:"); - bitmapinfo_print(contents + pEmr->offBmiSrc); + bitmapinfo_print(contents + pEmr->offBmiSrc, blimit); printf("\n"); } printf(" offBitsSrc: %u\n",pEmr->offBitsSrc ); @@ -839,6 +906,11 @@ void U_EMRHEADER_print(const char *contents){ int p1len; PU_EMRHEADER pEmr = (PU_EMRHEADER)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRHEADER)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" rclFrame: "); rectl_print( pEmr->rclFrame); printf("\n"); printf(" dSignature: 0x%8.8X\n", pEmr->dSignature ); @@ -850,6 +922,7 @@ void U_EMRHEADER_print(const char *contents){ printf(" nDescription: %d\n", pEmr->nDescription ); printf(" offDescription: %d\n", pEmr->offDescription); if(pEmr->offDescription){ + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, pEmr->offDescription + pEmr->nDescription*2*sizeof(char), blimit); string = U_Utf16leToUtf8((uint16_t *)((char *) pEmr + pEmr->offDescription), pEmr->nDescription, NULL); printf(" Desc. A: %s\n",string); free(string); @@ -868,6 +941,7 @@ void U_EMRHEADER_print(const char *contents){ printf(" offPixelFormat: %d\n", pEmr->offPixelFormat); if(pEmr->cbPixelFormat){ printf(" PFD:"); + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, pEmr->offPixelFormat + sizeof(U_PIXELFORMATDESCRIPTOR), blimit); pixelformatdescriptor_print( *(PU_PIXELFORMATDESCRIPTOR) (contents + pEmr->offPixelFormat)); printf("\n"); } @@ -997,6 +1071,10 @@ void U_EMRSETBRUSHORGEX_print(const char *contents){ */ void U_EMREOF_print(const char *contents){ PU_EMREOF pEmr = (PU_EMREOF)(contents); + if(pEmr->emr.nSize < sizeof(U_EMREOF)){ + printf(" record corruption HERE\n"); + return; + } printf(" cbPalEntries: %u\n", pEmr->cbPalEntries ); printf(" offPalEntries: %u\n", pEmr->offPalEntries); if(pEmr->cbPalEntries){ @@ -1014,6 +1092,10 @@ void U_EMREOF_print(const char *contents){ */ void U_EMRSETPIXELV_print(const char *contents){ PU_EMRSETPIXELV pEmr = (PU_EMRSETPIXELV)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRSETPIXELV)){ + printf(" record corruption HERE\n"); + return; + } printf(" ptlPixel: "); pointl_print( pEmr->ptlPixel); printf("\n"); printf(" crColor: "); colorref_print(pEmr->crColor); printf("\n"); } @@ -1026,6 +1108,10 @@ void U_EMRSETPIXELV_print(const char *contents){ */ void U_EMRSETMAPPERFLAGS_print(const char *contents){ PU_EMRSETMAPPERFLAGS pEmr = (PU_EMRSETMAPPERFLAGS)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRSETMAPPERFLAGS)){ + printf(" record corruption HERE\n"); + return; + } printf(" dwFlags: 0x%8.8X\n",pEmr->dwFlags); } @@ -1091,6 +1177,10 @@ void U_EMRSETTEXTALIGN_print(const char *contents){ */ void U_EMRSETCOLORADJUSTMENT_print(const char *contents){ PU_EMRSETCOLORADJUSTMENT pEmr = (PU_EMRSETCOLORADJUSTMENT)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRSETCOLORADJUSTMENT)){ + printf(" record corruption HERE\n"); + return; + } printf(" ColorAdjustment:"); coloradjustment_print(pEmr->ColorAdjustment); printf("\n"); @@ -1203,6 +1293,10 @@ void U_EMRRESTOREDC_print(const char *contents){ */ void U_EMRSETWORLDTRANSFORM_print(const char *contents){ PU_EMRSETWORLDTRANSFORM pEmr = (PU_EMRSETWORLDTRANSFORM)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRSETWORLDTRANSFORM)){ + printf(" record corruption HERE\n"); + return; + } printf(" xform:"); xform_print(pEmr->xform); printf("\n"); @@ -1215,6 +1309,10 @@ void U_EMRSETWORLDTRANSFORM_print(const char *contents){ */ void U_EMRMODIFYWORLDTRANSFORM_print(const char *contents){ PU_EMRMODIFYWORLDTRANSFORM pEmr = (PU_EMRMODIFYWORLDTRANSFORM)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRMODIFYWORLDTRANSFORM)){ + printf(" record corruption HERE\n"); + return; + } printf(" xform:"); xform_print(pEmr->xform); printf("\n"); @@ -1228,6 +1326,10 @@ void U_EMRMODIFYWORLDTRANSFORM_print(const char *contents){ */ void U_EMRSELECTOBJECT_print(const char *contents){ PU_EMRSELECTOBJECT pEmr = (PU_EMRSELECTOBJECT)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRSELECTOBJECT)){ + printf(" record corruption HERE\n"); + return; + } if(pEmr->ihObject & U_STOCK_OBJECT){ printf(" StockObject: 0x%8.8X\n", pEmr->ihObject ); } @@ -1243,6 +1345,10 @@ void U_EMRSELECTOBJECT_print(const char *contents){ */ void U_EMRCREATEPEN_print(const char *contents){ PU_EMRCREATEPEN pEmr = (PU_EMRCREATEPEN)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRCREATEPEN)){ + printf(" record corruption HERE\n"); + return; + } printf(" ihPen: %u\n", pEmr->ihPen ); printf(" lopn: "); logpen_print(pEmr->lopn); printf("\n"); } @@ -1254,6 +1360,10 @@ void U_EMRCREATEPEN_print(const char *contents){ */ void U_EMRCREATEBRUSHINDIRECT_print(const char *contents){ PU_EMRCREATEBRUSHINDIRECT pEmr = (PU_EMRCREATEBRUSHINDIRECT)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRCREATEBRUSHINDIRECT)){ + printf(" record corruption HERE\n"); + return; + } printf(" ihBrush: %u\n", pEmr->ihBrush ); printf(" lb: "); logbrush_print(pEmr->lb); printf("\n"); } @@ -1265,6 +1375,10 @@ void U_EMRCREATEBRUSHINDIRECT_print(const char *contents){ */ void U_EMRDELETEOBJECT_print(const char *contents){ PU_EMRDELETEOBJECT pEmr = (PU_EMRDELETEOBJECT)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRDELETEOBJECT)){ + printf(" record corruption HERE\n"); + return; + } printf(" ihObject: %u\n", pEmr->ihObject ); } @@ -1275,6 +1389,10 @@ void U_EMRDELETEOBJECT_print(const char *contents){ */ void U_EMRANGLEARC_print(const char *contents){ PU_EMRANGLEARC pEmr = (PU_EMRANGLEARC)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRANGLEARC)){ + printf(" record corruption HERE\n"); + return; + } printf(" ptlCenter: "), pointl_print(pEmr->ptlCenter ); printf("\n"); printf(" nRadius: %u\n", pEmr->nRadius ); printf(" eStartAngle: %f\n", pEmr->eStartAngle ); @@ -1306,6 +1424,10 @@ void U_EMRRECTANGLE_print(const char *contents){ */ void U_EMRROUNDRECT_print(const char *contents){ PU_EMRROUNDRECT pEmr = (PU_EMRROUNDRECT)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRROUNDRECT)){ + printf(" record corruption HERE\n"); + return; + } printf(" rclBox: "), rectl_print(pEmr->rclBox ); printf("\n"); printf(" szlCorner: "), sizel_print(pEmr->szlCorner ); printf("\n"); } @@ -1353,6 +1475,10 @@ void U_EMRSELECTPALETTE_print(const char *contents){ */ void U_EMRCREATEPALETTE_print(const char *contents){ PU_EMRCREATEPALETTE pEmr = (PU_EMRCREATEPALETTE)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRCREATEPALETTE)){ + printf(" record corruption HERE\n"); + return; + } printf(" ihPal: %u\n",pEmr->ihPal); printf(" lgpl: "), logpalette_print( (PU_LOGPALETTE)&(pEmr->lgpl) ); printf("\n"); } @@ -1365,12 +1491,18 @@ void U_EMRCREATEPALETTE_print(const char *contents){ void U_EMRSETPALETTEENTRIES_print(const char *contents){ unsigned int i; PU_EMRSETPALETTEENTRIES pEmr = (PU_EMRSETPALETTEENTRIES)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRSETPALETTEENTRIES)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" ihPal: %u\n",pEmr->ihPal); printf(" iStart: %u\n",pEmr->iStart); printf(" cEntries: %u\n",pEmr->cEntries); if(pEmr->cEntries){ printf(" PLTEntries:"); PU_LOGPLTNTRY aPalEntries = (PU_LOGPLTNTRY) &(pEmr->aPalEntries); + IF_MEM_UNSAFE_PRINT_AND_RETURN(aPalEntries, pEmr->cEntries*sizeof(U_LOGPLTNTRY), blimit); for(i=0; icEntries; i++){ printf("%d:",i); logpltntry_print(aPalEntries[i]); } @@ -1403,6 +1535,10 @@ void U_EMRREALIZEPALETTE_print(const char *contents){ */ void U_EMREXTFLOODFILL_print(const char *contents){ PU_EMREXTFLOODFILL pEmr = (PU_EMREXTFLOODFILL)(contents); + if(pEmr->emr.nSize < sizeof(U_EMREXTFLOODFILL)){ + printf(" record corruption HERE\n"); + return; + } printf(" ptlStart: "); pointl_print(pEmr->ptlStart); printf("\n"); printf(" crColor: "); colorref_print(pEmr->crColor); printf("\n"); printf(" iMode: %u\n",pEmr->iMode); @@ -1434,17 +1570,25 @@ void U_EMRARCTO_print(const char *contents){ void U_EMRPOLYDRAW_print(const char *contents){ unsigned int i; PU_EMRPOLYDRAW pEmr = (PU_EMRPOLYDRAW)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRPOLYDRAW)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" cptl: %d\n",pEmr->cptl ); printf(" Points: "); + IF_MEM_UNSAFE_PRINT_AND_RETURN(pEmr->aptl, pEmr->cptl*sizeof(U_POINTL), blimit); for(i=0;icptl; i++){ printf(" [%d]:",i); pointl_print(pEmr->aptl[i]); } printf("\n"); printf(" Types: "); + const char *abTypes = (const char *) pEmr->aptl + pEmr->cptl*sizeof(U_POINTL); + IF_MEM_UNSAFE_PRINT_AND_RETURN(abTypes, pEmr->cptl, blimit); for(i=0;icptl; i++){ - printf(" [%d]:%u ",i,pEmr->abTypes[i]); + printf(" [%d]:%u ",i,((uint8_t *)abTypes)[i]); } printf("\n"); } @@ -1565,12 +1709,11 @@ void U_EMRABORTPATH_print(const char *contents){ /** \brief Print a pointer to a U_EMR_COMMENT record. \param contents pointer to a location in memory holding the comment record - \param blimit size in bytes of the comment record - \param off offset in bytes to the first byte in this record + \param off offset in bytes to the first byte in this record (needed for EMF+ record printing) EMF+ records, if any, are stored in EMF comment records. */ -void U_EMRCOMMENT_print(const char *contents, const char *blimit, size_t off){ +void U_EMRCOMMENT_print(const char *contents, size_t off){ char *string; char *src; uint32_t cIdent,cIdent2,cbData; @@ -1579,21 +1722,30 @@ void U_EMRCOMMENT_print(const char *contents, const char *blimit, size_t off){ static int recnum=0; PU_EMRCOMMENT pEmr = (PU_EMRCOMMENT)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRCOMMENT)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; /* There are several different types of comments */ + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, sizeof(U_EMRCOMMENT), blimit); cbData = pEmr->cbData; printf(" cbData: %d\n",cbData ); + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, sizeof(U_EMR) + sizeof(U_CBDATA) + cbData, blimit); src = (char *)&(pEmr->Data); // default if(cbData >= 4){ /* Since the comment is just a big bag of bytes the emf endian code cannot safely touch - any of its payload. This is the only record type with that limitation. Try to determine + any of its payload. This is the only record type with that limitation. So the record + may appear at this stage with the wrong endianness. Try to determine what the contents are even if more byte swapping is required. */ cIdent = *(uint32_t *)(src); if(U_BYTE_SWAP){ U_swap4(&(cIdent),1); } if( cIdent == U_EMR_COMMENT_PUBLIC ){ printf(" cIdent: Public\n"); PU_EMRCOMMENT_PUBLIC pEmrp = (PU_EMRCOMMENT_PUBLIC) pEmr; + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, sizeof(U_EMRCOMMENT_PUBLIC), blimit); cIdent2 = pEmrp->pcIdent; if(U_BYTE_SWAP){ U_swap4(&(cIdent2),1); } printf(" pcIdent: 0x%8.8x\n",cIdent2); @@ -1603,6 +1755,7 @@ void U_EMRCOMMENT_print(const char *contents, const char *blimit, size_t off){ else if(cIdent == U_EMR_COMMENT_SPOOL ){ printf(" cIdent: Spool\n"); PU_EMRCOMMENT_SPOOL pEmrs = (PU_EMRCOMMENT_SPOOL) pEmr; + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, sizeof(U_EMRCOMMENT_SPOOL), blimit); cIdent2 = pEmrs->esrIdent; if(U_BYTE_SWAP){ U_swap4(&(cIdent2),1); } printf(" esrIdent: 0x%8.8x\n",cIdent2); @@ -1612,11 +1765,16 @@ void U_EMRCOMMENT_print(const char *contents, const char *blimit, size_t off){ else if(cIdent == U_EMR_COMMENT_EMFPLUSRECORD){ printf(" cIdent: EMF+\n"); PU_EMRCOMMENT_EMFPLUS pEmrpl = (PU_EMRCOMMENT_EMFPLUS) pEmr; + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, sizeof(U_EMRCOMMENT_EMFPLUS), blimit); src = (char *)&(pEmrpl->Data); loff = 16; /* Header size of the header part of an EMF+ comment record */ while(loff < cbData + 12){ // EMF+ records may not fill the entire comment, cbData value includes cIdent, but not U_EMR or cbData recsize = U_pmf_onerec_print(src, blimit, recnum, loff + off); - if(recsize<=0)break; + if(recsize==0){ break; } + else if(recsize<0){ + printf(" record corruption HERE\n"); + return; + } loff += recsize; src += recsize; recnum++; @@ -1642,19 +1800,17 @@ void U_EMRCOMMENT_print(const char *contents, const char *blimit, size_t off){ \param contents pointer to a buffer holding all EMR records */ void U_EMRFILLRGN_print(const char *contents){ - int i,roff; PU_EMRFILLRGN pEmr = (PU_EMRFILLRGN)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRFILLRGN)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n"); printf(" cbRgnData: %u\n",pEmr->cbRgnData); printf(" ihBrush: %u\n",pEmr->ihBrush); - // This one is a pain since each RGNDATA may be a different size, so it isn't possible to index through them. - roff=0; - i=1; - char *prd = (char *) &(pEmr->RgnData); - while(roff + sizeof(U_RGNDATAHEADER) < pEmr->emr.nSize){ // up to the end of the record - printf(" RegionData[%d]: ",i); rgndata_print((PU_RGNDATA) (prd + roff)); printf("\n"); - roff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - } + const char *minptr = MAKE_MIN_PTR(((const char *) &pEmr->RgnData + pEmr->cbRgnData + sizeof(U_RGNDATAHEADER)),blimit); + printf(" RegionData: "); rgndata_print(pEmr->RgnData, minptr); printf("\n"); } // U_EMRFRAMERGN 72 @@ -1663,20 +1819,18 @@ void U_EMRFILLRGN_print(const char *contents){ \param contents pointer to a buffer holding all EMR records */ void U_EMRFRAMERGN_print(const char *contents){ - int i,roff; PU_EMRFRAMERGN pEmr = (PU_EMRFRAMERGN)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRFRAMERGN)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n"); printf(" cbRgnData: %u\n",pEmr->cbRgnData); printf(" ihBrush: %u\n",pEmr->ihBrush); printf(" szlStroke: "), sizel_print(pEmr->szlStroke ); printf("\n"); - // This one is a pain since each RGNDATA may be a different size, so it isn't possible to index through them. - roff=0; - i=1; - char *prd = (char *) &(pEmr->RgnData); - while(roff + sizeof(U_RGNDATAHEADER) < pEmr->emr.nSize){ // up to the end of the record - printf(" RegionData[%d]: ",i); rgndata_print((PU_RGNDATA) (prd + roff)); printf("\n"); - roff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - } + const char *minptr = MAKE_MIN_PTR(((const char *) &pEmr->RgnData + pEmr->cbRgnData),blimit); + printf(" RegionData: "); rgndata_print(pEmr->RgnData, minptr); printf("\n"); } // U_EMRINVERTRGN 73 @@ -1703,17 +1857,16 @@ void U_EMRPAINTRGN_print(const char *contents){ \param contents pointer to a buffer holding all EMR records */ void U_EMREXTSELECTCLIPRGN_print(const char *contents){ - int i,roff; PU_EMREXTSELECTCLIPRGN pEmr = (PU_EMREXTSELECTCLIPRGN) (contents); + if(pEmr->emr.nSize < sizeof(U_EMREXTSELECTCLIPRGN)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" cbRgnData: %u\n",pEmr->cbRgnData); printf(" iMode: %u\n",pEmr->iMode); - // This one is a pain since each RGNDATA may be a different size, so it isn't possible to index through them. - char *prd = (char *) &(pEmr->RgnData); - i=roff=0; - while(roff + sizeof(U_RGNDATAHEADER) < pEmr->cbRgnData){ // stop at end of the record 4*4 = header + 4*4=rect - printf(" RegionData[%d]: ",i++); rgndata_print((PU_RGNDATA) (prd + roff)); printf("\n"); - roff += (((PU_RGNDATA)prd)->rdh.dwSize + ((PU_RGNDATA)prd)->rdh.nRgnSize - 16); - } + const char *minptr = MAKE_MIN_PTR(((const char *) &pEmr->RgnData + pEmr->cbRgnData),blimit); + printf(" RegionData: "); rgndata_print(pEmr->RgnData, minptr); printf("\n"); } // U_EMRBITBLT 76 @@ -1723,6 +1876,11 @@ void U_EMREXTSELECTCLIPRGN_print(const char *contents){ */ void U_EMRBITBLT_print(const char *contents){ PU_EMRBITBLT pEmr = (PU_EMRBITBLT) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRBITBLT)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" Dest: "); pointl_print(pEmr->Dest); printf("\n"); printf(" cDest: "); pointl_print(pEmr->cDest); printf("\n"); @@ -1735,7 +1893,7 @@ void U_EMRBITBLT_print(const char *contents){ printf(" cbBmiSrc: %u\n", pEmr->cbBmiSrc ); if(pEmr->cbBmiSrc){ printf(" bitmap: "); - bitmapinfo_print(contents + pEmr->offBmiSrc); + bitmapinfo_print(contents + pEmr->offBmiSrc, blimit); printf("\n"); } printf(" offBitsSrc: %u\n", pEmr->offBitsSrc ); @@ -1749,6 +1907,11 @@ void U_EMRBITBLT_print(const char *contents){ */ void U_EMRSTRETCHBLT_print(const char *contents){ PU_EMRSTRETCHBLT pEmr = (PU_EMRSTRETCHBLT) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRSTRETCHBLT)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" Dest: "); pointl_print(pEmr->Dest); printf("\n"); printf(" cDest: "); pointl_print(pEmr->cDest); printf("\n"); @@ -1761,7 +1924,7 @@ void U_EMRSTRETCHBLT_print(const char *contents){ printf(" cbBmiSrc: %u\n", pEmr->cbBmiSrc ); if(pEmr->cbBmiSrc){ printf(" bitmap: "); - bitmapinfo_print(contents + pEmr->offBmiSrc); + bitmapinfo_print(contents + pEmr->offBmiSrc, blimit); printf("\n"); } printf(" offBitsSrc: %u\n", pEmr->offBitsSrc ); @@ -1776,6 +1939,11 @@ void U_EMRSTRETCHBLT_print(const char *contents){ */ void U_EMRMASKBLT_print(const char *contents){ PU_EMRMASKBLT pEmr = (PU_EMRMASKBLT) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRMASKBLT)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" Dest: "); pointl_print(pEmr->Dest); printf("\n"); printf(" cDest: "); pointl_print(pEmr->cDest); printf("\n"); @@ -1788,7 +1956,7 @@ void U_EMRMASKBLT_print(const char *contents){ printf(" cbBmiSrc: %u\n", pEmr->cbBmiSrc ); if(pEmr->cbBmiSrc){ printf(" Src bitmap: "); - bitmapinfo_print(contents + pEmr->offBmiSrc); + bitmapinfo_print(contents + pEmr->offBmiSrc, blimit); printf("\n"); } printf(" offBitsSrc: %u\n", pEmr->offBitsSrc ); @@ -1799,7 +1967,7 @@ void U_EMRMASKBLT_print(const char *contents){ printf(" cbBmiMask: %u\n", pEmr->cbBmiMask ); if(pEmr->cbBmiMask){ printf(" Mask bitmap: "); - bitmapinfo_print(contents + pEmr->offBmiMask); + bitmapinfo_print(contents + pEmr->offBmiMask, blimit); printf("\n"); } printf(" offBitsMask: %u\n", pEmr->offBitsMask ); @@ -1813,6 +1981,11 @@ void U_EMRMASKBLT_print(const char *contents){ */ void U_EMRPLGBLT_print(const char *contents){ PU_EMRPLGBLT pEmr = (PU_EMRPLGBLT) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRPLGBLT)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" aptlDst(UL): "); pointl_print(pEmr->aptlDst[0]); printf("\n"); printf(" aptlDst(UR): "); pointl_print(pEmr->aptlDst[1]); printf("\n"); @@ -1826,7 +1999,7 @@ void U_EMRPLGBLT_print(const char *contents){ printf(" cbBmiSrc: %u\n", pEmr->cbBmiSrc ); if(pEmr->cbBmiSrc){ printf(" Src bitmap: "); - bitmapinfo_print(contents + pEmr->offBmiSrc); + bitmapinfo_print(contents + pEmr->offBmiSrc, blimit); printf("\n"); } printf(" offBitsSrc: %u\n", pEmr->offBitsSrc ); @@ -1837,7 +2010,7 @@ void U_EMRPLGBLT_print(const char *contents){ printf(" cbBmiMask: %u\n", pEmr->cbBmiMask ); if(pEmr->cbBmiMask){ printf(" Mask bitmap: "); - bitmapinfo_print(contents + pEmr->offBmiMask); + bitmapinfo_print(contents + pEmr->offBmiMask, blimit); printf("\n"); } printf(" offBitsMask: %u\n", pEmr->offBitsMask ); @@ -1851,6 +2024,11 @@ void U_EMRPLGBLT_print(const char *contents){ */ void U_EMRSETDIBITSTODEVICE_print(const char *contents){ PU_EMRSETDIBITSTODEVICE pEmr = (PU_EMRSETDIBITSTODEVICE) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRSETDIBITSTODEVICE)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" Dest: "); pointl_print(pEmr->Dest); printf("\n"); printf(" Src: "); pointl_print(pEmr->Src); printf("\n"); @@ -1859,7 +2037,7 @@ void U_EMRSETDIBITSTODEVICE_print(const char *contents){ printf(" cbBmiSrc: %u\n", pEmr->cbBmiSrc ); if(pEmr->cbBmiSrc){ printf(" Src bitmap: "); - bitmapinfo_print(contents + pEmr->offBmiSrc); + bitmapinfo_print(contents + pEmr->offBmiSrc, blimit); printf("\n"); } printf(" offBitsSrc: %u\n", pEmr->offBitsSrc ); @@ -1876,6 +2054,11 @@ void U_EMRSETDIBITSTODEVICE_print(const char *contents){ */ void U_EMRSTRETCHDIBITS_print(const char *contents){ PU_EMRSTRETCHDIBITS pEmr = (PU_EMRSTRETCHDIBITS) (contents); + if(pEmr->emr.nSize < sizeof(U_EMRSTRETCHDIBITS)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" Dest: "); pointl_print(pEmr->Dest); printf("\n"); printf(" Src: "); pointl_print(pEmr->Src); printf("\n"); @@ -1884,7 +2067,7 @@ void U_EMRSTRETCHDIBITS_print(const char *contents){ printf(" cbBmiSrc: %u\n", pEmr->cbBmiSrc ); if(pEmr->cbBmiSrc){ printf(" Src bitmap: "); - bitmapinfo_print(contents + pEmr->offBmiSrc); + bitmapinfo_print(contents + pEmr->offBmiSrc, blimit); printf("\n"); } printf(" offBitsSrc: %u\n", pEmr->offBitsSrc ); @@ -1901,12 +2084,19 @@ void U_EMRSTRETCHDIBITS_print(const char *contents){ */ void U_EMREXTCREATEFONTINDIRECTW_print(const char *contents){ PU_EMREXTCREATEFONTINDIRECTW pEmr = (PU_EMREXTCREATEFONTINDIRECTW) (contents); + if(pEmr->emr.nSize < U_SIZE_EMREXTCREATEFONTINDIRECTW_LOGFONT){ // smallest variant + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" ihFont: %u\n",pEmr->ihFont ); printf(" Font: "); - if(pEmr->emr.nSize == sizeof(U_EMREXTCREATEFONTINDIRECTW)){ // holds logfont_panose + if(pEmr->emr.nSize == U_SIZE_EMREXTCREATEFONTINDIRECTW_LOGFONT_PANOSE){ // holds logfont_panose + IF_MEM_UNSAFE_PRINT_AND_RETURN(&(pEmr->elfw), sizeof(U_PANOSE), blimit); logfont_panose_print(pEmr->elfw); } - else { // holds logfont + else { // holds logfont or logfontExDv. The latter isn't supported but it starts with logfont, so use that + IF_MEM_UNSAFE_PRINT_AND_RETURN(&(pEmr->elfw), sizeof(U_LOGFONT), blimit); logfont_print( *(PU_LOGFONT) &(pEmr->elfw)); } printf("\n"); @@ -2002,17 +2192,25 @@ void U_EMRPOLYPOLYGON16_print(const char *contents){ void U_EMRPOLYDRAW16_print(const char *contents){ unsigned int i; PU_EMRPOLYDRAW16 pEmr = (PU_EMRPOLYDRAW16)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRPOLYDRAW16)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" cpts: %d\n",pEmr->cpts ); printf(" Points: "); + IF_MEM_UNSAFE_PRINT_AND_RETURN(pEmr->apts, pEmr->cpts*sizeof(U_POINT16), blimit); for(i=0;icpts; i++){ printf(" [%d]:",i); point16_print(pEmr->apts[i]); } printf("\n"); printf(" Types: "); + const char *abTypes = (const char *) pEmr->apts + pEmr->cpts*sizeof(U_POINT16); + IF_MEM_UNSAFE_PRINT_AND_RETURN(abTypes, pEmr->cpts, blimit); for(i=0;icpts; i++){ - printf(" [%d]:%u ",i,pEmr->abTypes[i]); + printf(" [%d]:%u ",i,((uint8_t *)abTypes)[i]); } printf("\n"); } @@ -2043,12 +2241,17 @@ void U_EMRCREATEDIBPATTERNBRUSHPT_print(const char *contents){ */ void U_EMREXTCREATEPEN_print(const char *contents){ PU_EMREXTCREATEPEN pEmr = (PU_EMREXTCREATEPEN)(contents); + if(pEmr->emr.nSize < sizeof(U_EMREXTCREATEPEN)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" ihPen: %u\n", pEmr->ihPen ); printf(" offBmi: %u\n", pEmr->offBmi ); printf(" cbBmi: %u\n", pEmr->cbBmi ); if(pEmr->cbBmi){ printf(" bitmap: "); - bitmapinfo_print(contents + pEmr->offBmi); + bitmapinfo_print(contents + pEmr->offBmi, blimit); printf("\n"); } printf(" offBits: %u\n", pEmr->offBits ); @@ -2077,6 +2280,10 @@ void U_EMRSETICMMODE_print(const char *contents){ */ void U_EMRCREATECOLORSPACE_print(const char *contents){ PU_EMRCREATECOLORSPACE pEmr = (PU_EMRCREATECOLORSPACE)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRCREATECOLORSPACE)){ + printf(" record corruption HERE\n"); + return; + } printf(" ihCS: %u\n", pEmr->ihCS ); printf(" ColorSpace: "); logcolorspacea_print(pEmr->lcs); printf("\n"); } @@ -2111,6 +2318,12 @@ void U_EMRDELETECOLORSPACE_print(const char *contents){ */ void U_EMRPIXELFORMAT_print(const char *contents){ PU_EMRPIXELFORMAT pEmr = (PU_EMRPIXELFORMAT)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRPIXELFORMAT)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; + IF_MEM_UNSAFE_PRINT_AND_RETURN(&(pEmr->pfd), sizeof(U_PIXELFORMATDESCRIPTOR), blimit); printf(" Pfd: "); pixelformatdescriptor_print(pEmr->pfd); printf("\n"); } @@ -2130,6 +2343,11 @@ void U_EMRSMALLTEXTOUT_print(const char *contents){ int roff; char *string; PU_EMRSMALLTEXTOUT pEmr = (PU_EMRSMALLTEXTOUT)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRSMALLTEXTOUT)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" Dest: "); pointl_print(pEmr->Dest); printf("\n"); printf(" cChars: %u\n", pEmr->cChars ); printf(" fuOptions: 0x%8.8X\n", pEmr->fuOptions ); @@ -2138,14 +2356,17 @@ void U_EMRSMALLTEXTOUT_print(const char *contents){ printf(" eyScale: %f\n", pEmr->eyScale ); roff = sizeof(U_EMRSMALLTEXTOUT); //offset to the start of the variable fields if(!(pEmr->fuOptions & U_ETO_NO_RECT)){ + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, roff, blimit); printf(" rclBounds: "); rectl_print( *(PU_RECTL) (contents + roff)); printf("\n"); roff += sizeof(U_RECTL); } if(pEmr->fuOptions & U_ETO_SMALL_CHARS){ + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, roff + pEmr->cChars*sizeof(char), blimit); printf(" Text8: <%.*s>\n",pEmr->cChars,contents+roff); /* May not be null terminated */ } else { string = U_Utf16leToUtf8((uint16_t *)(contents+roff), pEmr->cChars, NULL); + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, roff + pEmr->cChars*2*sizeof(char), blimit); printf(" Text16: <%s>\n",contents+roff); free(string); } @@ -2199,12 +2420,18 @@ void U_EMRTRANSPARENTBLT_print(const char *contents){ void U_EMRGRADIENTFILL_print(const char *contents){ unsigned int i; PU_EMRGRADIENTFILL pEmr = (PU_EMRGRADIENTFILL)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRGRADIENTFILL)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n"); printf(" nTriVert: %u\n", pEmr->nTriVert ); printf(" nGradObj: %u\n", pEmr->nGradObj ); printf(" ulMode: %u\n", pEmr->ulMode ); contents += sizeof(U_EMRGRADIENTFILL); if(pEmr->nTriVert){ + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, pEmr->nTriVert*sizeof(U_TRIVERTEX), blimit); printf(" TriVert: "); for(i=0; inTriVert; i++, contents+=sizeof(U_TRIVERTEX)){ trivertex_print(*(PU_TRIVERTEX)(contents)); @@ -2214,12 +2441,14 @@ void U_EMRGRADIENTFILL_print(const char *contents){ if(pEmr->nGradObj){ printf(" GradObj: "); if( pEmr->ulMode == U_GRADIENT_FILL_TRIANGLE){ + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, pEmr->nGradObj*sizeof(U_GRADIENT3), blimit); for(i=0; inGradObj; i++, contents+=sizeof(U_GRADIENT3)){ gradient3_print(*(PU_GRADIENT3)(contents)); } } else if(pEmr->ulMode == U_GRADIENT_FILL_RECT_H || pEmr->ulMode == U_GRADIENT_FILL_RECT_V){ + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, pEmr->nGradObj*sizeof(U_GRADIENT4), blimit); for(i=0; inGradObj; i++, contents+=sizeof(U_GRADIENT4)){ gradient4_print(*(PU_GRADIENT4)(contents)); } @@ -2244,12 +2473,18 @@ void U_EMRGRADIENTFILL_print(const char *contents){ void U_EMRCREATECOLORSPACEW_print(const char *contents){ unsigned int i; PU_EMRCREATECOLORSPACEW pEmr = (PU_EMRCREATECOLORSPACEW)(contents); + if(pEmr->emr.nSize < sizeof(U_EMRCREATECOLORSPACEW)){ + printf(" record corruption HERE\n"); + return; + } + const char *blimit = contents + pEmr->emr.nSize; printf(" ihCS: %u\n", pEmr->ihCS ); printf(" ColorSpace: "); logcolorspacew_print(pEmr->lcs); printf("\n"); printf(" dwFlags: 0x%8.8X\n", pEmr->dwFlags ); printf(" cbData: %u\n", pEmr->cbData ); printf(" Data(hexvalues):"); if(pEmr->dwFlags & 1){ + IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, pEmr->cbData, blimit); for(i=0; icbData; i++){ printf("[%d]:%2.2X ",i,pEmr->Data[i]); } @@ -2267,145 +2502,154 @@ void U_EMRCREATECOLORSPACEW_print(const char *contents){ */ int U_emf_onerec_print(const char *contents, const char *blimit, int recnum, size_t off){ PU_ENHMETARECORD lpEMFR = (PU_ENHMETARECORD)(contents + off); - unsigned int size; - - printf("%-30srecord:%5d type:%-4d offset:%8d rsize:%8d\n",U_emr_names(lpEMFR->iType),recnum,lpEMFR->iType,(int) off,lpEMFR->nSize); - size = lpEMFR->nSize; - contents += off; + uint32_t nSize; + uint32_t iType; + const char *record = contents + off; - /* Check that the record size is OK, abort if not. - Pointer math might wrap, so check both sides of the range */ - if(size < sizeof(U_EMR) || - contents + size - 1 >= blimit || - contents + size - 1 < contents)return(-1); + if(record < contents)return(-1); // offset wrapped + /* Check that COMMON data in record can be touched without an access violation. If it cannot be + this is either a corrupt EMF or one engineered to cause a buffer overflow. Pointer math + could wrap so check both sides of the range. + */ + if(!U_emf_record_sizeok(record, blimit, &nSize, &iType, 1))return(-1); + + printf("%-30srecord:%5d type:%-4d offset:%8d rsize:%8d\n",U_emr_names(iType),recnum,iType,(int) off,nSize); + fflush(stdout); + + /* print the record header before checking further. + Note if this is a corrupt record, but continue anyway. + The _print routines will stop at the actual problem and print another corrupt message. + */ + if(!U_emf_record_safe(record)){printf("WARNING: Corrupt record. Emitting fields above the problem.\n");} + switch (lpEMFR->iType) { - case U_EMR_HEADER: U_EMRHEADER_print(contents); break; - case U_EMR_POLYBEZIER: U_EMRPOLYBEZIER_print(contents); break; - case U_EMR_POLYGON: U_EMRPOLYGON_print(contents); break; - case U_EMR_POLYLINE: U_EMRPOLYLINE_print(contents); break; - case U_EMR_POLYBEZIERTO: U_EMRPOLYBEZIERTO_print(contents); break; - case U_EMR_POLYLINETO: U_EMRPOLYLINETO_print(contents); break; - case U_EMR_POLYPOLYLINE: U_EMRPOLYPOLYLINE_print(contents); break; - case U_EMR_POLYPOLYGON: U_EMRPOLYPOLYGON_print(contents); break; - case U_EMR_SETWINDOWEXTEX: U_EMRSETWINDOWEXTEX_print(contents); break; - case U_EMR_SETWINDOWORGEX: U_EMRSETWINDOWORGEX_print(contents); break; - case U_EMR_SETVIEWPORTEXTEX: U_EMRSETVIEWPORTEXTEX_print(contents); break; - case U_EMR_SETVIEWPORTORGEX: U_EMRSETVIEWPORTORGEX_print(contents); break; - case U_EMR_SETBRUSHORGEX: U_EMRSETBRUSHORGEX_print(contents); break; - case U_EMR_EOF: U_EMREOF_print(contents); size=0; break; - case U_EMR_SETPIXELV: U_EMRSETPIXELV_print(contents); break; - case U_EMR_SETMAPPERFLAGS: U_EMRSETMAPPERFLAGS_print(contents); break; - case U_EMR_SETMAPMODE: U_EMRSETMAPMODE_print(contents); break; - case U_EMR_SETBKMODE: U_EMRSETBKMODE_print(contents); break; - case U_EMR_SETPOLYFILLMODE: U_EMRSETPOLYFILLMODE_print(contents); break; - case U_EMR_SETROP2: U_EMRSETROP2_print(contents); break; - case U_EMR_SETSTRETCHBLTMODE: U_EMRSETSTRETCHBLTMODE_print(contents); break; - case U_EMR_SETTEXTALIGN: U_EMRSETTEXTALIGN_print(contents); break; - case U_EMR_SETCOLORADJUSTMENT: U_EMRSETCOLORADJUSTMENT_print(contents); break; - case U_EMR_SETTEXTCOLOR: U_EMRSETTEXTCOLOR_print(contents); break; - case U_EMR_SETBKCOLOR: U_EMRSETBKCOLOR_print(contents); break; - case U_EMR_OFFSETCLIPRGN: U_EMROFFSETCLIPRGN_print(contents); break; - case U_EMR_MOVETOEX: U_EMRMOVETOEX_print(contents); break; - case U_EMR_SETMETARGN: U_EMRSETMETARGN_print(contents); break; - case U_EMR_EXCLUDECLIPRECT: U_EMREXCLUDECLIPRECT_print(contents); break; - case U_EMR_INTERSECTCLIPRECT: U_EMRINTERSECTCLIPRECT_print(contents); break; - case U_EMR_SCALEVIEWPORTEXTEX: U_EMRSCALEVIEWPORTEXTEX_print(contents); break; - case U_EMR_SCALEWINDOWEXTEX: U_EMRSCALEWINDOWEXTEX_print(contents); break; - case U_EMR_SAVEDC: U_EMRSAVEDC_print(contents); break; - case U_EMR_RESTOREDC: U_EMRRESTOREDC_print(contents); break; - case U_EMR_SETWORLDTRANSFORM: U_EMRSETWORLDTRANSFORM_print(contents); break; - case U_EMR_MODIFYWORLDTRANSFORM: U_EMRMODIFYWORLDTRANSFORM_print(contents); break; - case U_EMR_SELECTOBJECT: U_EMRSELECTOBJECT_print(contents); break; - case U_EMR_CREATEPEN: U_EMRCREATEPEN_print(contents); break; - case U_EMR_CREATEBRUSHINDIRECT: U_EMRCREATEBRUSHINDIRECT_print(contents); break; - case U_EMR_DELETEOBJECT: U_EMRDELETEOBJECT_print(contents); break; - case U_EMR_ANGLEARC: U_EMRANGLEARC_print(contents); break; - case U_EMR_ELLIPSE: U_EMRELLIPSE_print(contents); break; - case U_EMR_RECTANGLE: U_EMRRECTANGLE_print(contents); break; - case U_EMR_ROUNDRECT: U_EMRROUNDRECT_print(contents); break; - case U_EMR_ARC: U_EMRARC_print(contents); break; - case U_EMR_CHORD: U_EMRCHORD_print(contents); break; - case U_EMR_PIE: U_EMRPIE_print(contents); break; - case U_EMR_SELECTPALETTE: U_EMRSELECTPALETTE_print(contents); break; - case U_EMR_CREATEPALETTE: U_EMRCREATEPALETTE_print(contents); break; - case U_EMR_SETPALETTEENTRIES: U_EMRSETPALETTEENTRIES_print(contents); break; - case U_EMR_RESIZEPALETTE: U_EMRRESIZEPALETTE_print(contents); break; - case U_EMR_REALIZEPALETTE: U_EMRREALIZEPALETTE_print(contents); break; - case U_EMR_EXTFLOODFILL: U_EMREXTFLOODFILL_print(contents); break; - case U_EMR_LINETO: U_EMRLINETO_print(contents); break; - case U_EMR_ARCTO: U_EMRARCTO_print(contents); break; - case U_EMR_POLYDRAW: U_EMRPOLYDRAW_print(contents); break; - case U_EMR_SETARCDIRECTION: U_EMRSETARCDIRECTION_print(contents); break; - case U_EMR_SETMITERLIMIT: U_EMRSETMITERLIMIT_print(contents); break; - case U_EMR_BEGINPATH: U_EMRBEGINPATH_print(contents); break; - case U_EMR_ENDPATH: U_EMRENDPATH_print(contents); break; - case U_EMR_CLOSEFIGURE: U_EMRCLOSEFIGURE_print(contents); break; - case U_EMR_FILLPATH: U_EMRFILLPATH_print(contents); break; - case U_EMR_STROKEANDFILLPATH: U_EMRSTROKEANDFILLPATH_print(contents); break; - case U_EMR_STROKEPATH: U_EMRSTROKEPATH_print(contents); break; - case U_EMR_FLATTENPATH: U_EMRFLATTENPATH_print(contents); break; - case U_EMR_WIDENPATH: U_EMRWIDENPATH_print(contents); break; - case U_EMR_SELECTCLIPPATH: U_EMRSELECTCLIPPATH_print(contents); break; - case U_EMR_ABORTPATH: U_EMRABORTPATH_print(contents); break; - case U_EMR_UNDEF69: U_EMRUNDEF69_print(contents); break; - case U_EMR_COMMENT: U_EMRCOMMENT_print(contents, blimit, off); break; - case U_EMR_FILLRGN: U_EMRFILLRGN_print(contents); break; - case U_EMR_FRAMERGN: U_EMRFRAMERGN_print(contents); break; - case U_EMR_INVERTRGN: U_EMRINVERTRGN_print(contents); break; - case U_EMR_PAINTRGN: U_EMRPAINTRGN_print(contents); break; - case U_EMR_EXTSELECTCLIPRGN: U_EMREXTSELECTCLIPRGN_print(contents); break; - case U_EMR_BITBLT: U_EMRBITBLT_print(contents); break; - case U_EMR_STRETCHBLT: U_EMRSTRETCHBLT_print(contents); break; - case U_EMR_MASKBLT: U_EMRMASKBLT_print(contents); break; - case U_EMR_PLGBLT: U_EMRPLGBLT_print(contents); break; - case U_EMR_SETDIBITSTODEVICE: U_EMRSETDIBITSTODEVICE_print(contents); break; - case U_EMR_STRETCHDIBITS: U_EMRSTRETCHDIBITS_print(contents); break; - case U_EMR_EXTCREATEFONTINDIRECTW: U_EMREXTCREATEFONTINDIRECTW_print(contents); break; - case U_EMR_EXTTEXTOUTA: U_EMREXTTEXTOUTA_print(contents); break; - case U_EMR_EXTTEXTOUTW: U_EMREXTTEXTOUTW_print(contents); break; - case U_EMR_POLYBEZIER16: U_EMRPOLYBEZIER16_print(contents); break; - case U_EMR_POLYGON16: U_EMRPOLYGON16_print(contents); break; - case U_EMR_POLYLINE16: U_EMRPOLYLINE16_print(contents); break; - case U_EMR_POLYBEZIERTO16: U_EMRPOLYBEZIERTO16_print(contents); break; - case U_EMR_POLYLINETO16: U_EMRPOLYLINETO16_print(contents); break; - case U_EMR_POLYPOLYLINE16: U_EMRPOLYPOLYLINE16_print(contents); break; - case U_EMR_POLYPOLYGON16: U_EMRPOLYPOLYGON16_print(contents); break; - case U_EMR_POLYDRAW16: U_EMRPOLYDRAW16_print(contents); break; - case U_EMR_CREATEMONOBRUSH: U_EMRCREATEMONOBRUSH_print(contents); break; - case U_EMR_CREATEDIBPATTERNBRUSHPT: U_EMRCREATEDIBPATTERNBRUSHPT_print(contents); break; - case U_EMR_EXTCREATEPEN: U_EMREXTCREATEPEN_print(contents); break; - case U_EMR_POLYTEXTOUTA: U_EMRPOLYTEXTOUTA_print(contents); break; - case U_EMR_POLYTEXTOUTW: U_EMRPOLYTEXTOUTW_print(contents); break; - case U_EMR_SETICMMODE: U_EMRSETICMMODE_print(contents); break; - case U_EMR_CREATECOLORSPACE: U_EMRCREATECOLORSPACE_print(contents); break; - case U_EMR_SETCOLORSPACE: U_EMRSETCOLORSPACE_print(contents); break; - case U_EMR_DELETECOLORSPACE: U_EMRDELETECOLORSPACE_print(contents); break; - case U_EMR_GLSRECORD: U_EMRGLSRECORD_print(contents); break; - case U_EMR_GLSBOUNDEDRECORD: U_EMRGLSBOUNDEDRECORD_print(contents); break; - case U_EMR_PIXELFORMAT: U_EMRPIXELFORMAT_print(contents); break; - case U_EMR_DRAWESCAPE: U_EMRDRAWESCAPE_print(contents); break; - case U_EMR_EXTESCAPE: U_EMREXTESCAPE_print(contents); break; - case U_EMR_UNDEF107: U_EMRUNDEF107_print(contents); break; - case U_EMR_SMALLTEXTOUT: U_EMRSMALLTEXTOUT_print(contents); break; - case U_EMR_FORCEUFIMAPPING: U_EMRFORCEUFIMAPPING_print(contents); break; - case U_EMR_NAMEDESCAPE: U_EMRNAMEDESCAPE_print(contents); break; - case U_EMR_COLORCORRECTPALETTE: U_EMRCOLORCORRECTPALETTE_print(contents); break; - case U_EMR_SETICMPROFILEA: U_EMRSETICMPROFILEA_print(contents); break; - case U_EMR_SETICMPROFILEW: U_EMRSETICMPROFILEW_print(contents); break; - case U_EMR_ALPHABLEND: U_EMRALPHABLEND_print(contents); break; - case U_EMR_SETLAYOUT: U_EMRSETLAYOUT_print(contents); break; - case U_EMR_TRANSPARENTBLT: U_EMRTRANSPARENTBLT_print(contents); break; - case U_EMR_UNDEF117: U_EMRUNDEF117_print(contents); break; - case U_EMR_GRADIENTFILL: U_EMRGRADIENTFILL_print(contents); break; - case U_EMR_SETLINKEDUFIS: U_EMRSETLINKEDUFIS_print(contents); break; - case U_EMR_SETTEXTJUSTIFICATION: U_EMRSETTEXTJUSTIFICATION_print(contents); break; - case U_EMR_COLORMATCHTOTARGETW: U_EMRCOLORMATCHTOTARGETW_print(contents); break; - case U_EMR_CREATECOLORSPACEW: U_EMRCREATECOLORSPACEW_print(contents); break; - default: U_EMRNOTIMPLEMENTED_print("?",contents); break; + case U_EMR_HEADER: U_EMRHEADER_print(record); break; + case U_EMR_POLYBEZIER: U_EMRPOLYBEZIER_print(record); break; + case U_EMR_POLYGON: U_EMRPOLYGON_print(record); break; + case U_EMR_POLYLINE: U_EMRPOLYLINE_print(record); break; + case U_EMR_POLYBEZIERTO: U_EMRPOLYBEZIERTO_print(record); break; + case U_EMR_POLYLINETO: U_EMRPOLYLINETO_print(record); break; + case U_EMR_POLYPOLYLINE: U_EMRPOLYPOLYLINE_print(record); break; + case U_EMR_POLYPOLYGON: U_EMRPOLYPOLYGON_print(record); break; + case U_EMR_SETWINDOWEXTEX: U_EMRSETWINDOWEXTEX_print(record); break; + case U_EMR_SETWINDOWORGEX: U_EMRSETWINDOWORGEX_print(record); break; + case U_EMR_SETVIEWPORTEXTEX: U_EMRSETVIEWPORTEXTEX_print(record); break; + case U_EMR_SETVIEWPORTORGEX: U_EMRSETVIEWPORTORGEX_print(record); break; + case U_EMR_SETBRUSHORGEX: U_EMRSETBRUSHORGEX_print(record); break; + case U_EMR_EOF: U_EMREOF_print(record); nSize=0; break; + case U_EMR_SETPIXELV: U_EMRSETPIXELV_print(record); break; + case U_EMR_SETMAPPERFLAGS: U_EMRSETMAPPERFLAGS_print(record); break; + case U_EMR_SETMAPMODE: U_EMRSETMAPMODE_print(record); break; + case U_EMR_SETBKMODE: U_EMRSETBKMODE_print(record); break; + case U_EMR_SETPOLYFILLMODE: U_EMRSETPOLYFILLMODE_print(record); break; + case U_EMR_SETROP2: U_EMRSETROP2_print(record); break; + case U_EMR_SETSTRETCHBLTMODE: U_EMRSETSTRETCHBLTMODE_print(record); break; + case U_EMR_SETTEXTALIGN: U_EMRSETTEXTALIGN_print(record); break; + case U_EMR_SETCOLORADJUSTMENT: U_EMRSETCOLORADJUSTMENT_print(record); break; + case U_EMR_SETTEXTCOLOR: U_EMRSETTEXTCOLOR_print(record); break; + case U_EMR_SETBKCOLOR: U_EMRSETBKCOLOR_print(record); break; + case U_EMR_OFFSETCLIPRGN: U_EMROFFSETCLIPRGN_print(record); break; + case U_EMR_MOVETOEX: U_EMRMOVETOEX_print(record); break; + case U_EMR_SETMETARGN: U_EMRSETMETARGN_print(record); break; + case U_EMR_EXCLUDECLIPRECT: U_EMREXCLUDECLIPRECT_print(record); break; + case U_EMR_INTERSECTCLIPRECT: U_EMRINTERSECTCLIPRECT_print(record); break; + case U_EMR_SCALEVIEWPORTEXTEX: U_EMRSCALEVIEWPORTEXTEX_print(record); break; + case U_EMR_SCALEWINDOWEXTEX: U_EMRSCALEWINDOWEXTEX_print(record); break; + case U_EMR_SAVEDC: U_EMRSAVEDC_print(record); break; + case U_EMR_RESTOREDC: U_EMRRESTOREDC_print(record); break; + case U_EMR_SETWORLDTRANSFORM: U_EMRSETWORLDTRANSFORM_print(record); break; + case U_EMR_MODIFYWORLDTRANSFORM: U_EMRMODIFYWORLDTRANSFORM_print(record); break; + case U_EMR_SELECTOBJECT: U_EMRSELECTOBJECT_print(record); break; + case U_EMR_CREATEPEN: U_EMRCREATEPEN_print(record); break; + case U_EMR_CREATEBRUSHINDIRECT: U_EMRCREATEBRUSHINDIRECT_print(record); break; + case U_EMR_DELETEOBJECT: U_EMRDELETEOBJECT_print(record); break; + case U_EMR_ANGLEARC: U_EMRANGLEARC_print(record); break; + case U_EMR_ELLIPSE: U_EMRELLIPSE_print(record); break; + case U_EMR_RECTANGLE: U_EMRRECTANGLE_print(record); break; + case U_EMR_ROUNDRECT: U_EMRROUNDRECT_print(record); break; + case U_EMR_ARC: U_EMRARC_print(record); break; + case U_EMR_CHORD: U_EMRCHORD_print(record); break; + case U_EMR_PIE: U_EMRPIE_print(record); break; + case U_EMR_SELECTPALETTE: U_EMRSELECTPALETTE_print(record); break; + case U_EMR_CREATEPALETTE: U_EMRCREATEPALETTE_print(record); break; + case U_EMR_SETPALETTEENTRIES: U_EMRSETPALETTEENTRIES_print(record); break; + case U_EMR_RESIZEPALETTE: U_EMRRESIZEPALETTE_print(record); break; + case U_EMR_REALIZEPALETTE: U_EMRREALIZEPALETTE_print(record); break; + case U_EMR_EXTFLOODFILL: U_EMREXTFLOODFILL_print(record); break; + case U_EMR_LINETO: U_EMRLINETO_print(record); break; + case U_EMR_ARCTO: U_EMRARCTO_print(record); break; + case U_EMR_POLYDRAW: U_EMRPOLYDRAW_print(record); break; + case U_EMR_SETARCDIRECTION: U_EMRSETARCDIRECTION_print(record); break; + case U_EMR_SETMITERLIMIT: U_EMRSETMITERLIMIT_print(record); break; + case U_EMR_BEGINPATH: U_EMRBEGINPATH_print(record); break; + case U_EMR_ENDPATH: U_EMRENDPATH_print(record); break; + case U_EMR_CLOSEFIGURE: U_EMRCLOSEFIGURE_print(record); break; + case U_EMR_FILLPATH: U_EMRFILLPATH_print(record); break; + case U_EMR_STROKEANDFILLPATH: U_EMRSTROKEANDFILLPATH_print(record); break; + case U_EMR_STROKEPATH: U_EMRSTROKEPATH_print(record); break; + case U_EMR_FLATTENPATH: U_EMRFLATTENPATH_print(record); break; + case U_EMR_WIDENPATH: U_EMRWIDENPATH_print(record); break; + case U_EMR_SELECTCLIPPATH: U_EMRSELECTCLIPPATH_print(record); break; + case U_EMR_ABORTPATH: U_EMRABORTPATH_print(record); break; + case U_EMR_UNDEF69: U_EMRUNDEF69_print(record); break; + case U_EMR_COMMENT: U_EMRCOMMENT_print(record, off); break; + case U_EMR_FILLRGN: U_EMRFILLRGN_print(record); break; + case U_EMR_FRAMERGN: U_EMRFRAMERGN_print(record); break; + case U_EMR_INVERTRGN: U_EMRINVERTRGN_print(record); break; + case U_EMR_PAINTRGN: U_EMRPAINTRGN_print(record); break; + case U_EMR_EXTSELECTCLIPRGN: U_EMREXTSELECTCLIPRGN_print(record); break; + case U_EMR_BITBLT: U_EMRBITBLT_print(record); break; + case U_EMR_STRETCHBLT: U_EMRSTRETCHBLT_print(record); break; + case U_EMR_MASKBLT: U_EMRMASKBLT_print(record); break; + case U_EMR_PLGBLT: U_EMRPLGBLT_print(record); break; + case U_EMR_SETDIBITSTODEVICE: U_EMRSETDIBITSTODEVICE_print(record); break; + case U_EMR_STRETCHDIBITS: U_EMRSTRETCHDIBITS_print(record); break; + case U_EMR_EXTCREATEFONTINDIRECTW: U_EMREXTCREATEFONTINDIRECTW_print(record); break; + case U_EMR_EXTTEXTOUTA: U_EMREXTTEXTOUTA_print(record); break; + case U_EMR_EXTTEXTOUTW: U_EMREXTTEXTOUTW_print(record); break; + case U_EMR_POLYBEZIER16: U_EMRPOLYBEZIER16_print(record); break; + case U_EMR_POLYGON16: U_EMRPOLYGON16_print(record); break; + case U_EMR_POLYLINE16: U_EMRPOLYLINE16_print(record); break; + case U_EMR_POLYBEZIERTO16: U_EMRPOLYBEZIERTO16_print(record); break; + case U_EMR_POLYLINETO16: U_EMRPOLYLINETO16_print(record); break; + case U_EMR_POLYPOLYLINE16: U_EMRPOLYPOLYLINE16_print(record); break; + case U_EMR_POLYPOLYGON16: U_EMRPOLYPOLYGON16_print(record); break; + case U_EMR_POLYDRAW16: U_EMRPOLYDRAW16_print(record); break; + case U_EMR_CREATEMONOBRUSH: U_EMRCREATEMONOBRUSH_print(record); break; + case U_EMR_CREATEDIBPATTERNBRUSHPT: U_EMRCREATEDIBPATTERNBRUSHPT_print(record); break; + case U_EMR_EXTCREATEPEN: U_EMREXTCREATEPEN_print(record); break; + case U_EMR_POLYTEXTOUTA: U_EMRPOLYTEXTOUTA_print(record); break; + case U_EMR_POLYTEXTOUTW: U_EMRPOLYTEXTOUTW_print(record); break; + case U_EMR_SETICMMODE: U_EMRSETICMMODE_print(record); break; + case U_EMR_CREATECOLORSPACE: U_EMRCREATECOLORSPACE_print(record); break; + case U_EMR_SETCOLORSPACE: U_EMRSETCOLORSPACE_print(record); break; + case U_EMR_DELETECOLORSPACE: U_EMRDELETECOLORSPACE_print(record); break; + case U_EMR_GLSRECORD: U_EMRGLSRECORD_print(record); break; + case U_EMR_GLSBOUNDEDRECORD: U_EMRGLSBOUNDEDRECORD_print(record); break; + case U_EMR_PIXELFORMAT: U_EMRPIXELFORMAT_print(record); break; + case U_EMR_DRAWESCAPE: U_EMRDRAWESCAPE_print(record); break; + case U_EMR_EXTESCAPE: U_EMREXTESCAPE_print(record); break; + case U_EMR_UNDEF107: U_EMRUNDEF107_print(record); break; + case U_EMR_SMALLTEXTOUT: U_EMRSMALLTEXTOUT_print(record); break; + case U_EMR_FORCEUFIMAPPING: U_EMRFORCEUFIMAPPING_print(record); break; + case U_EMR_NAMEDESCAPE: U_EMRNAMEDESCAPE_print(record); break; + case U_EMR_COLORCORRECTPALETTE: U_EMRCOLORCORRECTPALETTE_print(record); break; + case U_EMR_SETICMPROFILEA: U_EMRSETICMPROFILEA_print(record); break; + case U_EMR_SETICMPROFILEW: U_EMRSETICMPROFILEW_print(record); break; + case U_EMR_ALPHABLEND: U_EMRALPHABLEND_print(record); break; + case U_EMR_SETLAYOUT: U_EMRSETLAYOUT_print(record); break; + case U_EMR_TRANSPARENTBLT: U_EMRTRANSPARENTBLT_print(record); break; + case U_EMR_UNDEF117: U_EMRUNDEF117_print(record); break; + case U_EMR_GRADIENTFILL: U_EMRGRADIENTFILL_print(record); break; + case U_EMR_SETLINKEDUFIS: U_EMRSETLINKEDUFIS_print(record); break; + case U_EMR_SETTEXTJUSTIFICATION: U_EMRSETTEXTJUSTIFICATION_print(record); break; + case U_EMR_COLORMATCHTOTARGETW: U_EMRCOLORMATCHTOTARGETW_print(record); break; + case U_EMR_CREATECOLORSPACEW: U_EMRCREATECOLORSPACEW_print(record); break; + default: U_EMRNOTIMPLEMENTED_print("?",record); break; } //end of switch - return(size); + return(nSize); } diff --git a/src/libuemf/uemf_print.h b/src/libuemf/uemf_print.h index 896de659e..6568b4cfa 100644 --- a/src/libuemf/uemf_print.h +++ b/src/libuemf/uemf_print.h @@ -6,11 +6,11 @@ /* File: uemf_print.h -Version: 0.0.5 -Date: 14-FEB-2013 +Version: 0.0.7 +Date: 24-MAR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2013 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifndef _UEMF_PRINT_ @@ -44,17 +44,17 @@ void panose_print(U_PANOSE panose); void logfont_print(U_LOGFONT lf); void logfont_panose_print(U_LOGFONT_PANOSE lfp); void bitmapinfoheader_print(const char *Bmih); -void bitmapinfo_print(const char *Bmi); +void bitmapinfo_print(const char *Bmi, const char *blimit); void blend_print(U_BLEND blend); void extlogpen_print(const PU_EXTLOGPEN elp); void logpen_print(U_LOGPEN lp); void logpltntry_print(U_LOGPLTNTRY lpny); void logpalette_print(const PU_LOGPALETTE lp); void rgndataheader_print(U_RGNDATAHEADER rdh); -void rgndata_print(const PU_RGNDATA rd); +void rgndata_print(const PU_RGNDATA rd, const char *blimit); void coloradjustment_print(U_COLORADJUSTMENT ca); void pixelformatdescriptor_print(U_PIXELFORMATDESCRIPTOR pfd); -void emrtext_print(const char *emt, const char *record, int type); +void emrtext_print(const char *emt, const char *record, const char *blimit, int type); /* prototypes for EMR records */ void U_EMRNOTIMPLEMENTED_print(const char *name, const char *contents, int recnum, int off); @@ -126,7 +126,7 @@ void U_EMRFLATTENPATH_print(const char *contents); void U_EMRWIDENPATH_print(const char *contents); void U_EMRSELECTCLIPPATH_print(const char *contents); void U_EMRABORTPATH_print(const char *contents); -void U_EMRCOMMENT_print(const char *contents, const char *blimit, size_t off); +void U_EMRCOMMENT_print(const char *contents, size_t off); void U_EMRFILLRGN_print(const char *contents); void U_EMRFRAMERGN_print(const char *contents); void U_EMRINVERTRGN_print(const char *contents); diff --git a/src/libuemf/upmf.c b/src/libuemf/upmf.c index 01f7ba3a4..7d6349185 100644 --- a/src/libuemf/upmf.c +++ b/src/libuemf/upmf.c @@ -21,11 +21,11 @@ /* File: upmf.c -Version: 0.0.6 -Date: 26-MAR-2014 +Version: 0.0.9 +Date: 25-MAR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2014 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifdef __cplusplus @@ -1459,11 +1459,18 @@ int U_PMF_PTRSAV_COND(const char **Dst, const char *Src, int Doit){ else { *Dst = NULL; } return(1); } +/* + + ===================================================================================== + start of U_PMF_*_get() functions + +*/ /** \brief Get the 16 bit unsigned Flags field from a header. \param contents Record from which to extract data, will be incremented by header size. \return Flags field + In many records the only value needed from the header is Flags. Rather than mapping the entire Header and returning it, in these instances this function may be called to just get this one value. @@ -1515,6 +1522,19 @@ int U_PMF_CMN_HDR_get(const char **contents, U_PMF_CMN_HDR *Header){ return(1); } +/** + \brief return the size in bytes of the EMF+ record + \param contents Record from which to extract data, will not be modified. + \returns size, or 0 if contents is Null +*/ +int U_PMF_RECORD_SIZE_get(const char *contents){ + if(!contents){ return(0); } + int Size; + const char *from = contents + 4; + U_PMF_SERIAL_get(&from, &Size, 4, 1, U_LE); + return(Size); +} + /** \brief Return the size of a PenData object from an EMF+ record. \param PenData Address in memory where the PenData object starts. @@ -5362,6 +5382,17 @@ U_PSEUDO_OBJ *U_PMR_TRANSLATEWORLDTRANSFORM_set(int xmtype, U_FLOAT Dx, U_FLOAT return(po); } +/* + + end of U_PMF_*_set() functions + ===================================================================================== + start of U_PMF_*_get() functions + + These functions all take a blimit value so that they can check if the data description in the fields + they process extend beyond the end of the record. + +*/ + //! \cond /* core _get functions, not accessed outside of this routine */ @@ -5387,11 +5418,15 @@ int U_PMF_CORE1_get(const char *contents, void *v1, void *v2, void *v3, void *v4 \param Version EmfPlusGraphicsVersion object \param Type BrushType Enumeration \param Data one of the 5 types of Brush data + \param blimit one byte past the end of data EMF+ manual 2.2.1.1, Microsoft name: EmfPlusBrush Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_BRUSH_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data){ - if(!contents || !Version || !Type || !Data){ return(0); } +int U_PMF_BRUSH_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data, const char *blimit){ + if(!contents || !Version || !Type || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents,sizeof(U_PMF_BRUSH), blimit))return(0); U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Type, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); @@ -5405,11 +5440,15 @@ int U_PMF_BRUSH_get(const char *contents, uint32_t *Version, uint32_t *Type, con \param Version EmfPlusGraphicsVersion object \param Type CustomLineCapData Enumeration \param Data one of the 2 types of Linecap data + \param blimit one byte past the end of data EMF+ manual 2.2.1.2, Microsoft name: EmfPlusCustomLineCap Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_CUSTOMLINECAP_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data){ - if(!contents || !Version || !Type || !Data){ return(0); } +int U_PMF_CUSTOMLINECAP_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data, const char *blimit){ + if(!contents || !Version || !Type || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CUSTOMLINECAP), blimit))return(0); U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Type, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); @@ -5428,10 +5467,13 @@ int U_PMF_CUSTOMLINECAP_get(const char *contents, uint32_t *Version, uint32_t *T \param Data Unicode (UTF-16LE) name of font family EMF+ manual 2.2.1.3, Microsoft name: EmfPlusFont Object + + Caller must check Data for possible memory access violations. */ int U_PMF_FONT_get(const char *contents, uint32_t *Version, U_FLOAT *EmSize, uint32_t *SizeUnit, - int32_t *FSFlags, uint32_t *Length, const char **Data){ - if(!contents || !Version || !EmSize || !SizeUnit || !FSFlags || !Length || !Data){ return(0); } + int32_t *FSFlags, uint32_t *Length, const char **Data, const char *blimit){ + if(!contents || !Version || !EmSize || !SizeUnit || !FSFlags || !Length || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_FONT), blimit))return(0); U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, EmSize, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, SizeUnit, 4, 1, U_LE); @@ -5452,9 +5494,12 @@ int U_PMF_FONT_get(const char *contents, uint32_t *Version, U_FLOAT *EmSize, uin \param Data one of the 2 types of image data EMF+ manual 2.2.1.4, Microsoft name: EmfPlusImage Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_IMAGE_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data){ - if(!contents || !Version || !Type){ return(0); } +int U_PMF_IMAGE_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data, const char *blimit){ + if(!contents || !Version || !Type || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IMAGE), blimit))return(0); U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Type, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); @@ -5472,8 +5517,10 @@ int U_PMF_IMAGE_get(const char *contents, uint32_t *Version, uint32_t *Type, con EMF+ manual 2.2.1.5, Microsoft name: EmfPlusImageAttributes Object */ -int U_PMF_IMAGEATTRIBUTES_get(const char *contents, uint32_t *Version, uint32_t *WrapMode, uint32_t *ClampColor, uint32_t *ObjectClamp){ - if(!contents || !Version || !WrapMode || !ClampColor || !ObjectClamp){ return(0); } +int U_PMF_IMAGEATTRIBUTES_get(const char *contents, uint32_t *Version, uint32_t *WrapMode, uint32_t *ClampColor, + uint32_t *ObjectClamp, const char *blimit){ + if(!contents || !Version || !WrapMode || !ClampColor || !ObjectClamp || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IMAGEATTRIBUTES), blimit))return(0); U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE); contents += 4; /* Skip Reserved 1*/ U_PMF_SERIAL_get(&contents, WrapMode, 4, 1, U_LE); @@ -5494,21 +5541,31 @@ int U_PMF_IMAGEATTRIBUTES_get(const char *contents, uint32_t *Version, uint32_t \param Types array of U_PMF_PATHPOINTTYPERLE and/or U_PMF_PATHPOINTTYPE EMF+ manual 2.2.1.6, Microsoft name: EmfPlusPath Object + + Caller must check Types for possible memory access violations if type can be U_PMF_PATHPOINTTYPERLE. */ -int U_PMF_PATH_get(const char *contents, uint32_t *Version, uint32_t *Count, uint16_t *Flags, const char **Points, const char **Types){ - if(!contents || !Version || !Count || !Flags || !Points || !Types){ return(0); } +int U_PMF_PATH_get(const char *contents, uint32_t *Version, uint32_t *Count, uint16_t *Flags, + const char **Points, const char **Types, const char *blimit){ + if(!contents || !Version || !Count || !Flags || !Points || !Types || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_PATH), blimit))return(0); U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Count, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Flags, 2, 1, U_LE); contents+=2; /* reserved */ - U_PMF_PTRSAV_SHIFT(Points, &contents, 0); + uint32_t sizeP, sizeT; if(*Flags & U_PPF_P){ - int killme = U_PMF_LEN_REL715(contents,*Count); //DEBUG - printf("DEBUG U_PMF_PATH_get count:%d LENREL715:%d\n",*Count,killme);fflush(stdout); - contents += killme; + sizeP = U_PMF_LEN_REL715(contents,*Count); //DEBUG + printf("DEBUG U_PMF_PATH_get count:%d LENREL715:%d\n",*Count,sizeP);fflush(stdout); } - else if(*Flags & U_PPF_C){ contents += *Count * sizeof(U_PMF_POINT); } - else { contents += *Count * sizeof(U_PMF_POINTF); } + else if(*Flags & U_PPF_C){ sizeP = *Count * sizeof(U_PMF_POINT); } + else { sizeP = *Count * sizeof(U_PMF_POINTF); } + if(IS_MEM_UNSAFE(contents, sizeP, blimit))return(0); + U_PMF_PTRSAV_SHIFT(Points, &contents, 0); + contents += sizeP; + /* this limit is correct if there are only U_PMF_PATHPOINTTYPE PointTypes, it is a lower bound if + there can also be U_PMF_PATHPOINTTYPERLE */ + sizeT = *Count * sizeof(U_PMF_PATHPOINTTYPE); + if(IS_MEM_UNSAFE(contents, sizeT, blimit))return(0); U_PMF_PTRSAV_SHIFT(Types, &contents, 0); return(1); } @@ -5523,9 +5580,12 @@ int U_PMF_PATH_get(const char *contents, uint32_t *Version, uint32_t *Count, uin \param Brush Brush Description EMF+ manual 2.2.1.7, Microsoft name: EmfPlusPen Object + + Caller must check Brush and PenData for possible memory access violations. */ -int U_PMF_PEN_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **PenData, const char **Brush){ - if(!contents || !Type || !PenData || !Brush){ return(0); } +int U_PMF_PEN_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **PenData, const char **Brush, const char *blimit){ + if(!contents || !Type || !PenData || !Brush || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_PEN), blimit))return(0); U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Type, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(PenData, &contents, 0); @@ -5543,8 +5603,9 @@ int U_PMF_PEN_get(const char *contents, uint32_t *Version, uint32_t *Type, const EMF+ manual 2.2.1.8, Microsoft name: EmfPlusRegion Object */ -int U_PMF_REGION_get(const char *contents, uint32_t *Version, uint32_t *Count, const char **Nodes){ - if(!contents || !Version || !Count || !Nodes){ return(0); } +int U_PMF_REGION_get(const char *contents, uint32_t *Version, uint32_t *Count, const char **Nodes, const char *blimit){ + if(!contents || !Version || !Count || !Nodes || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_REGION), blimit))return(0); U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Count, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Nodes, &contents, 0); @@ -5560,8 +5621,9 @@ int U_PMF_REGION_get(const char *contents, uint32_t *Version, uint32_t *Count, c EMF+ manual 2.2.1.9, Microsoft name: EmfPlusStringFormat Object */ -int U_PMF_STRINGFORMAT_get(const char *contents, U_PMF_STRINGFORMAT *Sfs, const char **Data){ - if(!contents || !Sfs || !Data){ return(0); } +int U_PMF_STRINGFORMAT_get(const char *contents, U_PMF_STRINGFORMAT *Sfs, const char **Data, const char *blimit){ + if(!contents || !Sfs || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_STRINGFORMAT), blimit))return(0); U_PMF_SERIAL_get(&contents, Sfs, 4, 15, U_LE); *Data = contents; return(1); @@ -5578,8 +5640,9 @@ int U_PMF_STRINGFORMAT_get(const char *contents, U_PMF_STRINGFORMAT *Sfs, const EMF+ manual 2.2.2.1, Microsoft name: EmfPlusARGB Object */ -int U_PMF_ARGB_get(const char *contents, uint8_t *Blue, uint8_t *Green, uint8_t *Red, uint8_t *Alpha){ - if(!contents || !Blue || !Green || !Red || !Alpha){ return(0); } +int U_PMF_ARGB_get(const char *contents, uint8_t *Blue, uint8_t *Green, uint8_t *Red, uint8_t *Alpha, const char *blimit){ + if(!contents || !Blue || !Green || !Red || !Alpha || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_ARGB), blimit))return(0); U_PMF_SERIAL_get(&contents, Blue, 1, 1, U_XE); U_PMF_SERIAL_get(&contents, Green, 1, 1, U_XE); U_PMF_SERIAL_get(&contents, Red, 1, 1, U_XE); @@ -5595,11 +5658,14 @@ int U_PMF_ARGB_get(const char *contents, uint8_t *Blue, uint8_t *Green, uint8_t \param Data pointer to variable part EMF+ manual 2.2.2.2, Microsoft name: EmfPlusBitmap Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_BITMAP_get(const char *contents, U_PMF_BITMAP *Bs, const char **Data){ - if(!contents || !Bs || !Data){ return(0); } - U_PMF_SERIAL_get(&contents, Bs, 4, 5, U_LE); - U_PMF_PTRSAV_SHIFT(Data, &contents, 0); +int U_PMF_BITMAP_get(const char *contents, U_PMF_BITMAP *Bs, const char **Data, const char *blimit){ + if(!contents || !Bs || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_BITMAP), blimit))return(0); + U_PMF_SERIAL_get(&contents, Bs, 4, 5, U_LE); // width, height, stride, pixelformat, type + U_PMF_PTRSAV_SHIFT(Data, &contents, 0); // bitmapdata return(1); } @@ -5612,11 +5678,16 @@ int U_PMF_BITMAP_get(const char *contents, U_PMF_BITMAP *Bs, const char **Data){ \param Data An array of bytes, meaning depends on fields in U_PMF_BITMAP object and the PixelFormat enumeration. EMF+ manual 2.2.2.3, Microsoft name: EmfPlusBitmapData Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_BITMAPDATA_get(const char *contents, U_PMF_PALETTE *Ps, const char **Colors, const char **Data){ - if(!contents || !Ps || !Colors || !Data ){ return(0); } +int U_PMF_BITMAPDATA_get(const char *contents, U_PMF_PALETTE *Ps, const char **Colors, const char **Data, const char *blimit){ + if(!contents || !Ps || !Colors || !Data || !blimit){ return(0); } + /* this structure is entirely optional */ + if(IS_MEM_UNSAFE(contents, 4*2, blimit))return(0); U_PMF_SERIAL_get(&contents, Ps, 4, 2, U_LE); U_PMF_PTRSAV_SHIFT(Colors, &contents, Ps->Elements * sizeof(U_PMF_ARGB)); + /* difficult to know how big the actual bitmap will be, just return the pointer to it untested */ U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); } @@ -5627,13 +5698,15 @@ int U_PMF_BITMAPDATA_get(const char *contents, U_PMF_PALETTE *Ps, const char **C \param contents Record from which to extract data \param Elements Number of members in Positions and Colors \param Positions Caller must free. Pointer to memory holding positions along gradient line. - \param Colors Caller must NOT free memory ,Pointer to memory holding colors at positions on gradient line. + \param Colors Caller must NOT free memory, Pointer to memory holding colors at positions on gradient line. EMF+ manual 2.2.2.4, Microsoft name: EmfPlusBlendColors Object */ -int U_PMF_BLENDCOLORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Positions, const char **Colors){ - if(!contents || !Positions || !Colors){ return(0); } +int U_PMF_BLENDCOLORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Positions, const char **Colors, const char *blimit){ + if(!contents || !Positions || !Colors || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_BLENDCOLORS), blimit))return(0); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); + if(IS_MEM_UNSAFE(contents, *Elements * 4, blimit))return(0); if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Positions, 4, *Elements, U_LE,1)){ return(0); } U_PMF_PTRSAV_SHIFT(Colors, &contents, 0); return(1); @@ -5649,9 +5722,11 @@ int U_PMF_BLENDCOLORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Po EMF+ manual 2.2.2.5, Microsoft name: EmfPlusBlendFactors Object */ -int U_PMF_BLENDFACTORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Positions, U_FLOAT **Factors){ - if(!contents || !Elements || !Positions || !Factors){ return(0); } +int U_PMF_BLENDFACTORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Positions, U_FLOAT **Factors, const char *blimit){ + if(!contents || !Elements || !Positions || !Factors || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_BLENDFACTORS), blimit))return(0); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); + if(IS_MEM_UNSAFE(contents, *Elements * 4 * 2, blimit))return(0); if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Positions, 4, *Elements, U_LE, 1)){ return(0); } if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Factors, 4, *Elements, U_LE, 1)){ free(*Positions); @@ -5668,9 +5743,12 @@ int U_PMF_BLENDFACTORS_get(const char *contents, uint32_t *Elements, U_FLOAT **P \param Data boundary of the brush EMF+ manual 2.2.2.6, Microsoft name: EmfPlusBoundaryPathData Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_BOUNDARYPATHDATA_get(const char *contents, int32_t *Size, const char **Data){ - if(!contents || !Size || !Data){ return(0); } +int U_PMF_BOUNDARYPATHDATA_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){ + if(!contents || !Size || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_BOUNDARYPATHDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); @@ -5680,14 +5758,16 @@ int U_PMF_BOUNDARYPATHDATA_get(const char *contents, int32_t *Size, const char * \brief Get data from a U_PMF_BOUNDARYPOINTDATA object \return 1 on success, 0 on error \param contents Record from which to extract data - \param Elements Members in POints + \param Elements Members in Points \param Points Caller must free. Pointer to memory holding points along gradient line. Boundary of the brush. EMF+ manual 2.2.2.7, Microsoft name: EmfPlusBoundaryPointData Object */ -int U_PMF_BOUNDARYPOINTDATA_get(const char *contents, int32_t *Elements, U_PMF_POINTF **Points){ - if(!contents || !Elements || !Points){ return(0); } +int U_PMF_BOUNDARYPOINTDATA_get(const char *contents, int32_t *Elements, U_PMF_POINTF **Points, const char *blimit){ + if(!contents || !Elements || !Points || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_BOUNDARYPOINTDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); + if(IS_MEM_UNSAFE(contents, *Elements * 2, blimit))return(0); if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Points, 4, *Elements * 2, U_LE, 1)){ return(0); } return(1); } @@ -5701,8 +5781,9 @@ int U_PMF_BOUNDARYPOINTDATA_get(const char *contents, int32_t *Elements, U_PMF_P EMF+ manual 2.2.2.8, Microsoft name: EmfPlusCharacterRange Object */ -int U_PMF_CHARACTERRANGE_get(const char *contents, int32_t *First, int32_t *Length){ - if(!contents || !First || !Length){ return(0); } +int U_PMF_CHARACTERRANGE_get(const char *contents, int32_t *First, int32_t *Length, const char *blimit){ + if(!contents || !First || !Length || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CHARACTERRANGE), blimit))return(0); U_PMF_SERIAL_get(&contents, First, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Length, 4, 1, U_LE); return(1); @@ -5717,9 +5798,11 @@ int U_PMF_CHARACTERRANGE_get(const char *contents, int32_t *First, int32_t *Leng EMF+ manual 2.2.2.9, Microsoft name: EmfPlusCompoundLineData Object */ -int U_PMF_COMPOUNDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT **Widths){ - if(!contents || !Elements || !Widths){ return(0); } +int U_PMF_COMPOUNDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT **Widths, const char *blimit){ + if(!contents || !Elements || !Widths || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_COMPOUNDLINEDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); + if(IS_MEM_UNSAFE(contents, *Elements * sizeof(U_FLOAT), blimit))return(0); *Widths = (U_FLOAT *)malloc(*Elements * sizeof(U_FLOAT)); if(!*Widths){ return(0); } U_PMF_SERIAL_get(&contents, *Widths, 4, *Elements, U_LE); @@ -5736,9 +5819,12 @@ int U_PMF_COMPOUNDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT This function does not do anything useful, but it is included so that all objects have a corresponding _get(). + + Caller must check Data for possible memory access violations. */ -int U_PMF_COMPRESSEDIMAGE_get(const char *contents, const char **Data){ - if(!contents || !Data){ return(0); } +int U_PMF_COMPRESSEDIMAGE_get(const char *contents, const char **Data, const char *blimit){ + if(!contents || !Data || !blimit){ return(0); } + if(contents >= blimit)return(0); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); } @@ -5751,9 +5837,12 @@ int U_PMF_COMPRESSEDIMAGE_get(const char *contents, const char **Data){ \param Data Description of linecap EMF+ manual 2.2.2.11, Microsoft name: EmfPlusCustomEndCapData Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_CUSTOMENDCAPDATA_get(const char *contents, int32_t *Size, const char **Data){ - if(!contents || !Size || !Data){ return(0); } +int U_PMF_CUSTOMENDCAPDATA_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){ + if(!contents || !Size || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CUSTOMENDCAPDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); @@ -5767,8 +5856,9 @@ int U_PMF_CUSTOMENDCAPDATA_get(const char *contents, int32_t *Size, const char * EMF+ manual 2.2.2.12, Microsoft name: EmfPlusCustomLineCapArrowData Object */ -int U_PMF_CUSTOMLINECAPARROWDATA_get(const char *contents, U_PMF_CUSTOMLINECAPARROWDATA *Ccad){ - if(!contents || !Ccad){ return(0); } +int U_PMF_CUSTOMLINECAPARROWDATA_get(const char *contents, U_PMF_CUSTOMLINECAPARROWDATA *Ccad, const char *blimit){ + if(!contents || !Ccad || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CUSTOMLINECAPARROWDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Ccad, 4, 13, U_LE); return(1); } @@ -5781,9 +5871,12 @@ int U_PMF_CUSTOMLINECAPARROWDATA_get(const char *contents, U_PMF_CUSTOMLINECAPAR \param Data variable part of U_PMF_CUSTOMLINECAPDATA EMF+ manual 2.2.2.13, Microsoft name: EmfPlusCustomLineCapData Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_CUSTOMLINECAPDATA_get(const char *contents, U_PMF_CUSTOMLINECAPDATA *Clcd, const char **Data){ - if(!contents || !Clcd){ return(0); } +int U_PMF_CUSTOMLINECAPDATA_get(const char *contents, U_PMF_CUSTOMLINECAPDATA *Clcd, const char **Data, const char *blimit){ + if(!contents || !Clcd || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CUSTOMLINECAPDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Clcd, 4, 12, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); @@ -5798,14 +5891,19 @@ int U_PMF_CUSTOMLINECAPDATA_get(const char *contents, U_PMF_CUSTOMLINECAPDATA *C \param LineData Path to stroke (optional) EMF+ manual 2.2.2.14, Microsoft name: EmfPlusCustomLineCapOptionalData Object + + Caller must check LineData for possible memory access violations. */ -int U_PMF_CUSTOMLINECAPOPTIONALDATA_get(const char *contents, uint32_t Flags, const char **FillData, const char **LineData){ +int U_PMF_CUSTOMLINECAPOPTIONALDATA_get(const char *contents, uint32_t Flags, const char **FillData, const char **LineData, const char *blimit){ uint32_t length; int status = 1; - if(!contents){ return(0); } + if(!contents || !*FillData || !*LineData || !blimit){ return(0); } + /* this structure is entirely optional */ if(Flags & U_CLCD_FillPath){ if(!FillData){ return(0); } + if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); U_PMF_SERIAL_get(&contents, &length, 4, 1, U_LE); + if(IS_MEM_UNSAFE(contents, length, blimit))return(0); contents -= 4; /* undo the unneeded shift from preceding */ U_PMF_PTRSAV_SHIFT(FillData, &contents, 4 + length); status += 2; @@ -5814,6 +5912,10 @@ int U_PMF_CUSTOMLINECAPOPTIONALDATA_get(const char *contents, uint32_t Flags, co if(Flags & U_CLCD_LinePath){ if(!LineData){ return(0); } + if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + U_PMF_SERIAL_get(&contents, &length, 4, 1, U_LE); + if(IS_MEM_UNSAFE(contents, length, blimit))return(0); + contents -= 4; /* undo the unneeded shift from preceding */ U_PMF_PTRSAV_SHIFT(LineData, &contents, 0); status += 4; } @@ -5829,9 +5931,12 @@ int U_PMF_CUSTOMLINECAPOPTIONALDATA_get(const char *contents, uint32_t Flags, co \param Data Description of linecap EMF+ manual 2.2.2.15, Microsoft name: EmfPlusCustomStartCapData Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_CUSTOMSTARTCAPDATA_get(const char *contents, int32_t *Size, const char **Data){ - if(!contents || !Size || !Data){ return(0); } +int U_PMF_CUSTOMSTARTCAPDATA_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){ + if(!contents || !Size || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CUSTOMSTARTCAPDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); @@ -5846,9 +5951,11 @@ int U_PMF_CUSTOMSTARTCAPDATA_get(const char *contents, int32_t *Size, const char EMF+ manual 2.2.2.16, Microsoft name: EmfPlusDashedLineData Object */ -int U_PMF_DASHEDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT **Lengths){ - if(!contents || !Elements || !Lengths){ return(0); } +int U_PMF_DASHEDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT **Lengths, const char *blimit){ + if(!contents || !Elements || !Lengths || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_DASHEDLINEDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); + if(IS_MEM_UNSAFE(contents, *Elements * sizeof(U_FLOAT), blimit))return(0); *Lengths = (U_FLOAT *)malloc(*Elements * sizeof(U_FLOAT)); if(!*Lengths){ return(0); } U_PMF_SERIAL_get(&contents, *Lengths, 4, *Elements, U_LE); @@ -5863,9 +5970,12 @@ int U_PMF_DASHEDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT ** \param Data Path specification EMF+ manual 2.2.2.17, Microsoft name: EmfPlusFillPath Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_FILLPATHOBJ_get(const char *contents, int32_t *Size, const char **Data){ - if(!contents || !Size || !Data){ return(0); } +int U_PMF_FILLPATHOBJ_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){ + if(!contents || !Size || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_FILLPATHO), blimit))return(0); U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); @@ -5881,8 +5991,9 @@ int U_PMF_FILLPATHOBJ_get(const char *contents, int32_t *Size, const char **Data EMF+ manual 2.2.2.18, Microsoft name: EmfPlusFocusScaleData Object */ -int U_PMF_FOCUSSCALEDATA_get(const char *contents, uint32_t *Count, U_FLOAT *ScaleX, U_FLOAT *ScaleY){ - if(!contents || !Count || !ScaleX || !ScaleY){ return(0); } +int U_PMF_FOCUSSCALEDATA_get(const char *contents, uint32_t *Count, U_FLOAT *ScaleX, U_FLOAT *ScaleY, const char *blimit){ + if(!contents || !Count || !ScaleX || !ScaleY || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_FOCUSSCALEDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Count, 4, 1, U_LE); if(*Count != 2){ return(0); } U_PMF_SERIAL_get(&contents, ScaleX, 4, 1, U_LE); @@ -5899,9 +6010,10 @@ int U_PMF_FOCUSSCALEDATA_get(const char *contents, uint32_t *Count, U_FLOAT *Sca EMF+ manual 2.2.2.19, Microsoft name: EmfPlusGraphicsVersion Object */ -int U_PMF_GRAPHICSVERSION_get(const char *contents, int *Signature, int *GrfVersion){ - if(!contents || !Signature || !GrfVersion){ return(0); } +int U_PMF_GRAPHICSVERSION_get(const char *contents, int *Signature, int *GrfVersion, const char *blimit){ uint32_t tmp; + if(!contents || !Signature || !GrfVersion || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_GRAPHICSVERSION), blimit))return(0); memcpy(&tmp, contents, 4); *Signature = tmp >> 12; *GrfVersion = tmp & U_GFVR_MASKLO; @@ -5918,8 +6030,9 @@ int U_PMF_GRAPHICSVERSION_get(const char *contents, int *Signature, int *GrfVers EMF+ manual 2.2.2.20, Microsoft name: EmfPlusHatchBrushData Object */ -int U_PMF_HATCHBRUSHDATA_get(const char *contents, uint32_t *Style, U_PMF_ARGB *Foreground, U_PMF_ARGB *Background){ - if(!contents || !Style || !Foreground || !Background){ return(0); } +int U_PMF_HATCHBRUSHDATA_get(const char *contents, uint32_t *Style, U_PMF_ARGB *Foreground, U_PMF_ARGB *Background, const char *blimit){ + if(!contents || !Style || !Foreground || !Background || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_HATCHBRUSHDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Style, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Foreground, 4, 1, U_XE); U_PMF_SERIAL_get(&contents, Background, 4, 1, U_XE); @@ -5931,12 +6044,14 @@ int U_PMF_HATCHBRUSHDATA_get(const char *contents, uint32_t *Style, U_PMF_ARGB * \return 1 on success, 0 on error \param contents Record from which to extract data \param Value 7 bit signed integer (stored in an integer) + \param blimit one byte past the end of data EMF+ manual 2.2.2.21, Microsoft name: EmfPlusInteger7 Object */ -int U_PMF_INTEGER7_get(const char **contents, U_FLOAT *Value){ - if(!contents || !*contents || !Value){ return(0); } +int U_PMF_INTEGER7_get(const char **contents, U_FLOAT *Value, const char *blimit){ uint8_t tmp; + if(!contents || !*contents || !Value || !blimit){ return(0); } + if(IS_MEM_UNSAFE(*contents, 1, blimit))return(0); /* past end of buffer */ if(**contents & U_TEST_INT7)return(0); /* this bit must be 0 in this object type */ U_PMF_SERIAL_get(contents, &tmp, 1, 1, U_XE); if(tmp & U_SIGN_INT7){ @@ -5954,12 +6069,14 @@ int U_PMF_INTEGER7_get(const char **contents, U_FLOAT *Value){ \return 1 on success, 0 on error \param contents Record from which to extract data \param Value 15 bit signed integer (stored in an integer) + \param blimit one byte past the end of data EMF+ manual 2.2.2.22, Microsoft name: EmfPlusInteger15 Object */ -int U_PMF_INTEGER15_get(const char **contents, U_FLOAT *Value){ - if(!contents || !*contents || !Value){ return(0); } +int U_PMF_INTEGER15_get(const char **contents, U_FLOAT *Value, const char *blimit){ + if(!contents || !*contents || !Value || !blimit){ return(0); } uint16_t tmp; + if(IS_MEM_UNSAFE(*contents, 2, blimit))return(0); /* past end of buffer */ if(!(**contents & U_TEST_INT7))return(0); /* this bit must be 1 in this object type */ U_PMF_SERIAL_get(contents, &tmp, 2, 1, U_BE); tmp &= U_MASK_INT15; /* drop the 7/15 flag from the most significant bit */ @@ -6000,11 +6117,15 @@ int U_PMF_LANGUAGEIDENTIFIER_get(U_PMF_LANGUAGEIDENTIFIER LId, int *SubLId, int \param contents Record from which to extract data \param Lgbd U_PMF_LINEARGRADIENTBRUSHDATA structure, with no variable part \param Data variable part of U_PMF_LINEARGRADIENTBRUSHDATA + \param blimit one byte past the end of data EMF+ manual 2.2.2.24, Microsoft name: EmfPlusLinearGradientBrushData Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_LINEARGRADIENTBRUSHDATA_get(const char *contents, U_PMF_LINEARGRADIENTBRUSHDATA *Lgbd, const char **Data){ - if(!contents || !Lgbd || !Data){ return(0); } +int U_PMF_LINEARGRADIENTBRUSHDATA_get(const char *contents, U_PMF_LINEARGRADIENTBRUSHDATA *Lgbd, const char **Data, const char *blimit){ + if(!contents || !Lgbd || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_LINEARGRADIENTBRUSHDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Lgbd, 4, 6, U_LE); /* Flags, WrapMode, RectF*/ U_PMF_SERIAL_get(&contents, &(Lgbd->StartColor), 4, 4, U_XE); /* StartColor, EndColor, Reserved1 & 2 */ U_PMF_PTRSAV_SHIFT(Data, &contents, 0); @@ -6020,27 +6141,42 @@ int U_PMF_LINEARGRADIENTBRUSHDATA_get(const char *contents, U_PMF_LINEARGRADIENT \param Bc U_PMF_BLENDCOLORS object or NULL \param BfH U_PMF_BLENDFACTORS (H) object or NULL \param BfV U_PMF_BLENDFACTORS (V) object or NULL (WARNING, GDI+ defines this field but does not render it. DO NOT USE.) + \param blimit one byte past the end of data EMF+ manual 2.2.2.25, Microsoft name: EmfPlusLinearGradientBrushOptionalData Object + */ int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Flags, U_PMF_TRANSFORMMATRIX *Tm, - const char **Bc, const char **BfH, const char **BfV){ + const char **Bc, const char **BfH, const char **BfV, const char *blimit){ uint32_t Elements; - if(!contents || !Tm|| !Bc || !BfH || !BfV){ return(0); } + if(!contents || !Tm|| !Bc || !BfH || !BfV || !blimit){ return(0); } + /* all of the fields are optional! */ *Bc = *BfH = *BfV = NULL; - if(Flags & U_BD_Transform)U_PMF_SERIAL_get(&contents, Tm, 4, 6, U_LE); + if(Flags & U_BD_Transform){ + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_ROTMATRIX), blimit))return(0); + U_PMF_SERIAL_get(&contents, Tm, 4, 6, U_LE); + } if(Flags & U_BD_PresetColors){ + if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + U_PMF_SERIAL_get(&contents, &Elements, 4, 1, U_LE); /* starts with a 4 byte count*/ + if(IS_MEM_UNSAFE(contents, Elements * ( sizeof(U_FLOAT) + sizeof(U_PMF_ARGB)), blimit))return(0); + contents-=4; /* back up to the front of the count, as it is part of the data field */ U_PMF_PTRSAV_SHIFT(Bc, &contents, 0); } else if(Flags & U_BD_BlendFactorsH){ U_PMF_SERIAL_get(&contents, &Elements, 4, 1, U_LE); /* starts with a 4 byte count*/ + if(IS_MEM_UNSAFE(contents, Elements * 2 * sizeof(U_FLOAT), blimit))return(0); contents-=4; /* back up to the front of the count, as it is part of the data field */ - U_PMF_PTRSAV_SHIFT(BfH, &contents, 4 + 8*Elements); /* 4 byte count + 2 * 4bytes * Elements */ + U_PMF_PTRSAV_SHIFT(BfH, &contents, 4 + (Elements * 2 * sizeof(U_FLOAT))); /* 4 byte count + 2 * 4bytes * Elements */ if(Flags & U_BD_BlendFactorsV){ + if(IS_MEM_UNSAFE(contents, Elements * 2 * sizeof(U_FLOAT), blimit))return(0); U_PMF_PTRSAV_SHIFT(BfV, &contents, 0); } } else if(Flags & U_BD_BlendFactorsV){ + U_PMF_SERIAL_get(&contents, &Elements, 4, 1, U_LE); /* starts with a 4 byte count*/ + if(IS_MEM_UNSAFE(contents, Elements * 2 * sizeof(U_FLOAT), blimit))return(0); + contents-=4; /* back up to the front of the count, as it is part of the data field */ U_PMF_PTRSAV_SHIFT(BfV, &contents, 0); } return(1); @@ -6052,11 +6188,15 @@ int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Fla \param contents Record from which to extract data \param Size Bytes in Data \param Data Outline path + \param blimit one byte past the end of data EMF+ manual 2.2.2.26, Microsoft name: EmfPlusLinePath Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_LINEPATH_get(const char *contents, int32_t *Size, const char **Data){ - if(!contents || !Size || !Data){ return(0); } +int U_PMF_LINEPATH_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){ + if(!contents || !Size || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_LINEPATH), blimit))return(0); U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); @@ -6069,11 +6209,15 @@ int U_PMF_LINEPATH_get(const char *contents, int32_t *Size, const char **Data){ \param Type \param Size Bytes in Data \param Data Various types of data, like an EMF metafile, WMF metafile, another EMF+ metafile + \param blimit one byte past the end of data EMF+ manual 2.2.2.27, Microsoft name: EmfPlusMetafile Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_METAFILE_get(const char *contents, uint32_t *Type, uint32_t *Size, const char **Data){ - if(!contents || !Type || !Size || !Data){ return(0); } +int U_PMF_METAFILE_get(const char *contents, uint32_t *Type, uint32_t *Size, const char **Data, const char *blimit){ + if(!contents || !Type || !Size || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_METAFILE), blimit))return(0); U_PMF_SERIAL_get(&contents, &Type, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, &Size, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); @@ -6087,13 +6231,16 @@ int U_PMF_METAFILE_get(const char *contents, uint32_t *Type, uint32_t *Size, con \param Flags PaletteStyle flags \param Elements Members in the array \param Colors Palette data (array of colors) + \param blimit one byte past the end of data EMF+ manual 2.2.2.28, Microsoft name: EmfPlusPalette Object */ -int U_PMF_PALETTE_get(const char *contents, uint32_t *Flags, uint32_t *Elements, const char **Colors){ - if(!contents || !Flags || !Elements || !Colors){ return(0); } +int U_PMF_PALETTE_get(const char *contents, uint32_t *Flags, uint32_t *Elements, const char **Colors, const char *blimit){ + if(!contents || !Flags || !Elements || !Colors || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_PALETTE), blimit))return(0); U_PMF_SERIAL_get(&contents, &Flags, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, &Elements, 4, 1, U_LE); + if(IS_MEM_UNSAFE(contents, *Elements*sizeof(U_RGBQUAD), blimit))return(0); U_PMF_PTRSAV_SHIFT(Colors, &contents, 0); return(1); @@ -6107,21 +6254,32 @@ int U_PMF_PALETTE_get(const char *contents, uint32_t *Flags, uint32_t *Elements, \param Gradient variable part of U_PMF_LINEARGRADIENTBRUSHDATA, Color Gradient with Elements members \param Boundary variable part of U_PMF_LINEARGRADIENTBRUSHDATA, U_PMF_BOUNDARYPATHDATA object if BrushDataPath bit set in Flag, else U_PMF_BOUNDARYPOINTDATA object \param Data variable part of U_PMF_LINEARGRADIENTBRUSHDATA, exact composition depends on Flags + \param blimit one byte past the end of data EMF+ manual 2.2.2.29, Microsoft name: EmfPlusPathGradientBrushData Object + + Caller must check Data for possible memory access violations. + */ -int U_PMF_PATHGRADIENTBRUSHDATA_get(const char *contents, U_PMF_PATHGRADIENTBRUSHDATA *Pgbd, const char **Gradient, const char **Boundary, const char **Data){ - if(!contents || !Pgbd || !Gradient || !Boundary || !Data){ return(0); } +int U_PMF_PATHGRADIENTBRUSHDATA_get(const char *contents, U_PMF_PATHGRADIENTBRUSHDATA *Pgbd, const char **Gradient, + const char **Boundary, const char **Data, const char *blimit){ + if(!contents || !Pgbd || !Gradient || !Boundary || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_PATHGRADIENTBRUSHDATA), blimit))return(0); uint32_t Size; U_PMF_SERIAL_get(&contents, Pgbd, 4, 2, U_LE); /* Flags and WrapMode*/ U_PMF_SERIAL_get(&contents, &(Pgbd->CenterColor), 4, 1, U_XE); U_PMF_SERIAL_get(&contents, &(Pgbd->Center), 4, 3, U_LE); /* Center and Elements */ + if(IS_MEM_UNSAFE(contents, Pgbd->Elements * sizeof(U_PMF_ARGB), blimit))return(0); U_PMF_PTRSAV_SHIFT(Gradient, &contents, Pgbd->Elements * sizeof(U_PMF_ARGB)); U_PMF_PTRSAV_SHIFT(Boundary, &contents, 0); U_PMF_SERIAL_get(&contents, &Size, 4, 1, U_LE); /* The first 4 bytes of the Boundary are always a size */ if(Pgbd->Flags & U_BD_Path){ contents += Size; } // U_PMF_BOUNDARYPATHDATA else { contents += Size*2*sizeof(U_FLOAT); } // U_PMF_BOUNDARYPOINTDATA - U_PMF_PTRSAV_SHIFT(Data, &contents, 0); + if(Pgbd->Flags & (U_BD_Transform |U_BD_PresetColors | U_BD_BlendFactorsH| U_BD_FocusScales)){ // optional data present + if(contents >= blimit)return(0); // the size is variable but this must still hold + U_PMF_PTRSAV_SHIFT(Data, &contents, 0); + } + else { *Data = NULL; } // no optional data present return(1); } @@ -6133,15 +6291,34 @@ int U_PMF_PATHGRADIENTBRUSHDATA_get(const char *contents, U_PMF_PATHGRADIENTBRUS \param Matrix Transformation matrix \param Pattern Blend Pattern \param Data Focus scales for the brush + \param blimit one byte past the end of data EMF+ manual 2.2.2.30, Microsoft name: EmfPlusPathGradientBrushOptionalData Object */ -int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Flags, U_PMF_TRANSFORMMATRIX *Matrix, const char **Pattern, const char **Data){ - if(!contents || !Flags || !Matrix || !Pattern || !Data){ return(0); } - U_PMF_SERIAL_get(&contents, &Flags, 4, 1, U_LE); - U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE); - U_PMF_PTRSAV_COND(Data, contents, (Flags & (U_BD_PresetColors | U_BD_BlendFactorsH))); - U_PMF_PTRSAV_COND(Data, contents, (Flags & U_BD_FocusScales)); +int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Flags, U_PMF_TRANSFORMMATRIX *Matrix, + const char **Pattern, const char **Data, const char *blimit){ + int varsize; + if(!contents || !Flags || !Matrix || !Pattern || !Data || !blimit){ return(0); } + /* this structure is entirely optional */ + if(Flags & U_BD_Transform){ + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_TRANSFORMMATRIX), blimit))return(0); + U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE); + } + if(Flags & (U_BD_PresetColors | U_BD_BlendFactorsH)){ + if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + uint32_t Elements; + U_PMF_SERIAL_get(&contents, &Elements, 4, 1, U_LE); + contents -= 4; + varsize=(Elements * 4 * (Flags & U_BD_BlendFactorsH ? 2 :1)); + if(IS_MEM_UNSAFE(contents, varsize, blimit))return(0); + U_PMF_PTRSAV_SHIFT(Pattern, &contents, varsize); + } + else { *Pattern=NULL; } + if(Flags & U_BD_FocusScales){ + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_FOCUSSCALEDATA), blimit))return(0); + U_PMF_PTRSAV_SHIFT(Data, &contents, sizeof(U_PMF_FOCUSSCALEDATA)); + } + else { *Data=NULL; } return(1); } @@ -6151,14 +6328,16 @@ int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Flags \param contents Record from which to extract data \param Flags PathPointType flags \param Type PathPointType enumeration + \param blimit one byte past the end of data EMF+ manual 2.2.2.31, Microsoft name: EmfPlusPathPointType Object Note: order of 4bit fields appears to be shown in the LE column, not as documented in the BE column. */ -int U_PMF_PATHPOINTTYPE_get(const char *contents, int *Flags, int *Type){ - if(!contents || !Flags || !Type){ return(0); } +int U_PMF_PATHPOINTTYPE_get(const char *contents, int *Flags, int *Type, const char *blimit){ + if(!contents || !Flags || !Type || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, 1, blimit))return(0); uint8_t tmp; memcpy(&tmp, contents, 1); *Flags =(tmp & U_PTP_MASK) >> U_PTP_SHIFT; @@ -6172,13 +6351,15 @@ int U_PMF_PATHPOINTTYPE_get(const char *contents, int *Flags, int *Type){ \param contents Record from which to extract data \param Bezier Set: Bezier curve, Clear: straight line \param RL Run Length - \param Ppt PathPointType enumeration + \param Ppt PathPointType enumeration + \param blimit one byte past the end of data EMF+ manual 2.2.2.32, Microsoft name: EmfPlusPathPointTypeRLE Object */ -int U_PMF_PATHPOINTTYPERLE_get(const char *contents, int *Bezier, int *RL, int *Ppt){ - if(!contents || !Bezier || !RL || !Ppt){ return(0); } +int U_PMF_PATHPOINTTYPERLE_get(const char *contents, int *Bezier, int *RL, int *Ppt, const char *blimit){ + if(!contents || !Bezier || !RL || !Ppt || !blimit){ return(0); } uint16_t tmp; + if(IS_MEM_UNSAFE(contents, 2, blimit))return(0); U_PMF_SERIAL_get(&contents, &tmp, 2, 1, U_LE); *Bezier = tmp & U_PPF_BZ; *RL = (tmp >> U_FF_SHFT_RL) & U_FF_MASK_RL; @@ -6194,14 +6375,17 @@ int U_PMF_PATHPOINTTYPERLE_get(const char *contents, int *Bezier, int *RL, int * \param Unit UnitType enumeration \param Width Width in units set by Unit \param Data Optional pen data, exact composition depends on Flags + \param blimit one byte past the end of data EMF+ manual 2.2.2.33, Microsoft name: EmfPlusPenData Object */ -int U_PMF_PENDATA_get(const char *contents, uint32_t *Flags, uint32_t *Unit, U_FLOAT *Width, const char **Data){ - if(!contents || !Flags || !Unit || !Width || !Data){ return(0); } +int U_PMF_PENDATA_get(const char *contents, uint32_t *Flags, uint32_t *Unit, U_FLOAT *Width, const char **Data, const char *blimit){ + if(!contents || !Flags || !Unit || !Width || !Data || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, 3*4, blimit))return(0); U_PMF_SERIAL_get(&contents, Flags, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Unit, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Width, 4, 1, U_LE); + if(contents >= blimit)return(0); // variable data will extend farther, but this much at least must be true U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); } @@ -6224,6 +6408,7 @@ int U_PMF_PENDATA_get(const char *contents, uint32_t *Flags, uint32_t *Unit, U_F \param CmpndLineData Compount Line (parallel lines drawn instead of one) \param CSCapData Custom start cap \param CECapData Custom end cap + \param blimit one byte past the end of data EMF+ manual 2.2.2.34, Microsoft name: EmfPlusPenOptionalData Object @@ -6245,26 +6430,56 @@ int U_PMF_PENOPTIONALDATA_get( int32_t *Alignment, const char **CmpndLineData, const char **CSCapData, - const char **CECapData){ + const char **CECapData, + const char *blimit){ if(!contents || !Flags || !Matrix || !StartCap || !EndCap || !Join || !MiterLimit || !Style || !DLCap || !DLOffset || !DLData || !Alignment || !CmpndLineData || - !CSCapData || !CECapData){ return(0); } - - if(Flags & U_PD_Transform){ U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE); } - if(Flags & U_PD_StartCap){ U_PMF_SERIAL_get(&contents, StartCap, 4, 1, U_LE); } - if(Flags & U_PD_EndCap){ U_PMF_SERIAL_get(&contents, EndCap, 4, 1, U_LE); } - if(Flags & U_PD_Join){ U_PMF_SERIAL_get(&contents, Join, 4, 1, U_LE); } - if(Flags & U_PD_MiterLimit){ U_PMF_SERIAL_get(&contents, MiterLimit, 4, 1, U_LE); } - if(Flags & U_PD_LineStyle){ U_PMF_SERIAL_get(&contents, Style, 4, 1, U_LE); } - if(Flags & U_PD_DLCap){ U_PMF_SERIAL_get(&contents, DLCap, 4, 1, U_LE); } - if(Flags & U_PD_DLOffset){ U_PMF_SERIAL_get(&contents, DLOffset, 4, 1, U_LE); } - if(Flags & U_PD_DLData){ U_PMF_PTRSAV_SHIFT( DLData, &contents, U_PMF_LEN_FLOATDATA(contents)); } - if(Flags & U_PD_NonCenter){ U_PMF_SERIAL_get(&contents, Alignment, 4, 1, U_LE); } - if(Flags & U_PD_CLData){ U_PMF_PTRSAV_SHIFT( CmpndLineData, &contents, U_PMF_LEN_FLOATDATA(contents)); } - if(Flags & U_PD_CustomStartCap){ U_PMF_PTRSAV_SHIFT( CSCapData, &contents, U_PMF_LEN_BYTEDATA(contents)); } - if(Flags & U_PD_CustomEndCap){ U_PMF_PTRSAV_SHIFT( CECapData, &contents, U_PMF_LEN_BYTEDATA(contents)); } + !CSCapData || !CECapData || !blimit){ return(0); } + + if(Flags & U_PD_Transform){ if(IS_MEM_UNSAFE(contents, 4*6, blimit))return(0); + U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE); + } + if(Flags & U_PD_StartCap){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + U_PMF_SERIAL_get(&contents, StartCap, 4, 1, U_LE); + } + if(Flags & U_PD_EndCap){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + U_PMF_SERIAL_get(&contents, EndCap, 4, 1, U_LE); + } + if(Flags & U_PD_Join){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + U_PMF_SERIAL_get(&contents, Join, 4, 1, U_LE); + } + if(Flags & U_PD_MiterLimit){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + U_PMF_SERIAL_get(&contents, MiterLimit, 4, 1, U_LE); + } + if(Flags & U_PD_LineStyle){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + U_PMF_SERIAL_get(&contents, Style, 4, 1, U_LE); + } + if(Flags & U_PD_DLCap){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + U_PMF_SERIAL_get(&contents, DLCap, 4, 1, U_LE); + } + if(Flags & U_PD_DLOffset){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + U_PMF_SERIAL_get(&contents, DLOffset, 4, 1, U_LE); + } + if(Flags & U_PD_DLData){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + if(IS_MEM_UNSAFE(contents, U_PMF_LEN_FLOATDATA(contents), blimit))return(0); + U_PMF_PTRSAV_SHIFT( DLData, &contents, U_PMF_LEN_FLOATDATA(contents)); + } + if(Flags & U_PD_NonCenter){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + U_PMF_SERIAL_get(&contents, Alignment, 4, 1, U_LE); } + if(Flags & U_PD_CLData){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + if(IS_MEM_UNSAFE(contents, U_PMF_LEN_FLOATDATA(contents), blimit))return(0); + U_PMF_PTRSAV_SHIFT( CmpndLineData, &contents, U_PMF_LEN_FLOATDATA(contents)); + } + if(Flags & U_PD_CustomStartCap){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + if(IS_MEM_UNSAFE(contents, U_PMF_LEN_BYTEDATA(contents), blimit))return(0); + U_PMF_PTRSAV_SHIFT( CSCapData, &contents, U_PMF_LEN_BYTEDATA(contents)); + } + if(Flags & U_PD_CustomEndCap){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); + if(IS_MEM_UNSAFE(contents, U_PMF_LEN_BYTEDATA(contents), blimit))return(0); + U_PMF_PTRSAV_SHIFT( CECapData, &contents, U_PMF_LEN_BYTEDATA(contents)); + } return(1); } @@ -6274,12 +6489,14 @@ int U_PMF_PENOPTIONALDATA_get( \param contents Record from which to extract data. On return position is offset by sizeof(U_PMF_POINT). \param X X coordinate \param Y Y coordinate + \param blimit one byte past the end of data EMF+ manual 2.2.2.35, Microsoft name: EmfPlusPoint Object */ -int U_PMF_POINT_get(const char **contents, U_FLOAT *X, U_FLOAT *Y){ - if(!contents || !X || !Y){ return(0); } +int U_PMF_POINT_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, const char *blimit){ + if(!contents || !X || !Y || !blimit){ return(0); } int16_t tmp; + if(IS_MEM_UNSAFE(*contents, 2*2, blimit))return(0); U_PMF_SERIAL_get(contents, &tmp, 2, 1, U_LE); *X = tmp; U_PMF_SERIAL_get(contents, &tmp, 2, 1, U_LE); *Y = tmp; return(1); @@ -6291,11 +6508,13 @@ int U_PMF_POINT_get(const char **contents, U_FLOAT *X, U_FLOAT *Y){ \param contents Record from which to extract data. On return position is offset by sizeof(U_PMF_POINTF). \param X X coordinate \param Y Y coordinate + \param blimit one byte past the end of data EMF+ manual 2.2.2.36, Microsoft name: EmfPlusPointF Object */ -int U_PMF_POINTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y){ - if(!contents || !X || !Y){ return(0); } +int U_PMF_POINTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, const char *blimit){ + if(!contents || !X || !Y || !blimit){ return(0); } + if(IS_MEM_UNSAFE(*contents, 4*2, blimit))return(0); U_PMF_SERIAL_get(contents, X, 4, 1, U_LE); U_PMF_SERIAL_get(contents, Y, 4, 1, U_LE); return(1); @@ -6307,19 +6526,20 @@ int U_PMF_POINTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y){ \param contents Record from which to extract data. On return position is offset by returned size. \param X X coordinate \param Y Y coordinate + \param blimit one byte past the end of data EMF+ manual 2.2.2.37, Microsoft name: EmfPlusPointR Object */ -int U_PMF_POINTR_get(const char **contents, U_FLOAT *X, U_FLOAT *Y){ - if(!contents || !*contents | !X || !Y){ return(0); } +int U_PMF_POINTR_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, const char *blimit){ + if(!contents || !*contents | !X || !Y || !blimit){ return(0); } int size=0; - if( U_PMF_INTEGER7_get( contents, X)){ size +=1; } - else if(U_PMF_INTEGER15_get(contents, X)){ size +=2; } + if( U_PMF_INTEGER7_get( contents, X, blimit)){ size +=1; } + else if(U_PMF_INTEGER15_get(contents, X, blimit)){ size +=2; } else { return(0); } - if( U_PMF_INTEGER7_get( contents, Y)){ size +=1; } - else if(U_PMF_INTEGER15_get(contents, Y)){ size +=2; } + if( U_PMF_INTEGER7_get( contents, Y, blimit)){ size +=1; } + else if(U_PMF_INTEGER15_get(contents, Y, blimit)){ size +=2; } else { return(0); } return(size); @@ -6332,31 +6552,38 @@ int U_PMF_POINTR_get(const char **contents, U_FLOAT *X, U_FLOAT *Y){ \param Flags Record flags (bits U_PPF_C and U_PPF_P are referenced) \param Elements Number of points to retrieve. \param Points Caller must free. Array of U_PMF_POINTF coordinates. + \param blimit one byte past the end of data + + This function should never be called directly by end user code. */ -int U_PMF_VARPOINTS_get(const char **contents, uint16_t Flags, int Elements, U_PMF_POINTF **Points){ +int U_PMF_VARPOINTS_get(const char *contents, uint16_t Flags, int Elements, U_PMF_POINTF **Points, const char *blimit){ int status = 0; - if(!contents || !*contents || !Points || !Elements){ return(status); } + if(!contents || !Points || !Elements || !blimit){ return(status); } U_PMF_POINTF *pts = (U_PMF_POINTF *)malloc(Elements * sizeof(U_PMF_POINTF)); if(!pts){ return(status); } *Points = pts; U_FLOAT XF, YF; U_FLOAT XFS, YFS; - for(XFS = YFS = 0.0; Elements; Elements--, pts++){ - if(Flags & U_PPF_P){ - if(!U_PMF_POINTR_get(contents, &XF, &YF))break; /* this should never happen */ + if(Flags & U_PPF_P){ + for(XFS = YFS = 0.0; Elements; Elements--, pts++){ + if(!U_PMF_POINTR_get(&contents, &XF, &YF, blimit))return(0); /* this should never happen */ XFS += XF; /* position relative to previous point, first point is always 0,0 */ YFS += YF; pts->X = XFS; pts->Y = YFS; } - else if(Flags & U_PPF_C){ - if(!U_PMF_POINT_get(contents, &XF, &XF))break; /* this should never happen */ + } + else if(Flags & U_PPF_C){ + for(XFS = YFS = 0.0; Elements; Elements--, pts++){ + if(!U_PMF_POINT_get(&contents, &XF, &XF, blimit))break; /* this should never happen */ pts->X = XF; pts->Y = YF; } - else { - (void) U_PMF_POINTF_get(contents, &(pts->X), &(pts->Y)); + } + else { + for(XFS = YFS = 0.0; Elements; Elements--, pts++){ + (void) U_PMF_POINTF_get(&contents, &(pts->X), &(pts->Y), blimit); } } if(Elements){ /* some error in the preceding */ @@ -6377,11 +6604,13 @@ int U_PMF_VARPOINTS_get(const char **contents, uint16_t Flags, int Elements, U_P \param Y UL Y value \param Width Width \param Height Height + \param blimit one byte past the end of data EMF+ manual 2.2.2.38, Microsoft name: EmfPlusRect Object */ -int U_PMF_RECT_get(const char **contents, int16_t *X, int16_t *Y, int16_t *Width, int16_t *Height){ +int U_PMF_RECT_get(const char **contents, int16_t *X, int16_t *Y, int16_t *Width, int16_t *Height, const char *blimit){ if(!contents || !X || !Y|| !Width || !Height){ return(0); } + if(IS_MEM_UNSAFE(*contents, 2*4, blimit))return(0); U_PMF_SERIAL_get(contents, X, 2, 1, U_LE); U_PMF_SERIAL_get(contents, Y, 2, 1, U_LE); U_PMF_SERIAL_get(contents, Width, 2, 1, U_LE); @@ -6397,11 +6626,13 @@ int U_PMF_RECT_get(const char **contents, int16_t *X, int16_t *Y, int16_t *Width \param Y UL Y value \param Width Width \param Height Height + \param blimit one byte past the end of data EMF+ manual 2.2.2.39, Microsoft name: EmfPlusRectF Object */ -int U_PMF_RECTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, U_FLOAT *Width, U_FLOAT *Height){ +int U_PMF_RECTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, U_FLOAT *Width, U_FLOAT *Height, const char *blimit){ if(!contents || !X || !Y|| !Width || !Height){ return(0); } + if(IS_MEM_UNSAFE(*contents, 4*4, blimit))return(0); U_PMF_SERIAL_get(contents, X, 4, 1, U_LE); U_PMF_SERIAL_get(contents, Y, 4, 1, U_LE); U_PMF_SERIAL_get(contents, Width, 4, 1, U_LE); @@ -6416,13 +6647,14 @@ int U_PMF_RECTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, U_FLOAT *Widt \param Flags Record flags (bit U_PPF_C is referenced) \param Elements Number of rects to retrieve. \param Rects Caller must free. Array of U_PMF_RECTF coordinates. + \param blimit one byte past the end of data Rects in record may be either U_PMF_RECT or U_PMF_RECTF, but this function always returns U_PMF_RECTF */ -int U_PMF_VARRECTS_get(const char **contents, uint16_t Flags, int Elements, U_PMF_RECTF **Rects){ +int U_PMF_VARRECTS_get(const char **contents, uint16_t Flags, int Elements, U_PMF_RECTF **Rects, const char *blimit){ int16_t X16, Y16, Width, Height; - if(!contents || !*contents || !Rects){ return(0); } + if(!contents || !*contents || !Rects || !blimit){ return(0); } U_PMF_RECTF *rts = (U_PMF_RECTF *)malloc(Elements * sizeof(U_PMF_RECTF)); if(!rts){ *Rects = NULL; @@ -6430,16 +6662,28 @@ int U_PMF_VARRECTS_get(const char **contents, uint16_t Flags, int Elements, U_PM } *Rects = rts; + if(Flags & U_PPF_C){ + if(IS_MEM_UNSAFE(*contents, Elements*sizeof(U_PMF_RECT), blimit)){ + free(rts); + return(0); + } + } + else { + if(IS_MEM_UNSAFE(*contents, Elements*sizeof(U_PMF_RECT), blimit)){ + free(rts); + return(0); + } + } for(; Elements; Elements--, rts++){ if(Flags & U_PPF_C){ - (void) U_PMF_RECT_get(contents, &X16, &Y16, &Width, &Height); + (void) U_PMF_RECT_get(contents, &X16, &Y16, &Width, &Height, blimit); rts->X = X16; rts->Y = Y16; rts->Width = Width; rts->Height = Height; } else { - (void) U_PMF_RECTF_get(contents, &(rts->X), &(rts->Y), &(rts->Width), &(rts->Height)); + (void) U_PMF_RECTF_get(contents, &(rts->X), &(rts->Y), &(rts->Width), &(rts->Height), blimit); } } return(1); @@ -6451,13 +6695,18 @@ int U_PMF_VARRECTS_get(const char **contents, uint16_t Flags, int Elements, U_PM \param contents Record from which to extract data \param Type RegionNodeDataType \param Data Depending on Type: U_PMF_REGIONNODEPATH, U_PMF_RECTF, or U_PMF_REGIONNODECHILDNODES - + \param blimit one byte past the end of data EMF+ manual 2.2.2.40, Microsoft name: EmfPlusRegionNode Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_REGIONNODE_get(const char *contents, uint32_t *Type, const char **Data){ - if(!contents || !Type|| !Data){ return(0); } +int U_PMF_REGIONNODE_get(const char *contents, uint32_t *Type, const char **Data, const char *blimit){ + if(!contents || !Type || !Data || !blimit){ return(0); } + /* Important! This only checks the constant part, the caller must check that returned data doesn't exceed blimit */ + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_REGIONNODE), blimit))return(0); U_PMF_SERIAL_get(&contents, Type, 4, 1, U_LE); + if(contents >= blimit)return(0); // returned Data is variable size, this much at least must be true U_PMF_PTRSAV_COND(Data, contents, !(*Type == U_RNDT_Empty || *Type == U_RNDT_Infinite )); return(1); } @@ -6481,12 +6730,16 @@ int U_PMF_REGIONNODE_get(const char *contents, uint32_t *Type, const char **Data \param contents Record from which to extract data \param Size Bytes in Data \param Data Boundary of region node + \param blimit one byte past the end of data EMF+ manual 2.2.2.42, Microsoft name: EmfPlusRegionNodePath Object */ -int U_PMF_REGIONNODEPATH_get(const char *contents, int32_t *Size, const char **Data){ - if(!contents || !Size || !Data){ return(0); } +int U_PMF_REGIONNODEPATH_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){ + if(!contents || !Size || !Data || !blimit){ return(0); } + /* Important! This only checks the constant part, the caller must check that returned data doesn't exceed blimit */ + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_REGIONNODEPATH), blimit))return(0); U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE); + if(contents >= blimit)return(0); // returned Data is variable size, this much at least must be true U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); } @@ -6496,11 +6749,13 @@ int U_PMF_REGIONNODEPATH_get(const char *contents, int32_t *Size, const char **D \return 1 on success, 0 on error \param contents Record from which to extract data \param Color Color of brush + \param blimit one byte past the end of data EMF+ manual 2.2.2.43, Microsoft name: EmfPlusSolidBrushData Object */ -int U_PMF_SOLIDBRUSHDATA_get(const char *contents, U_PMF_ARGB *Color){ - if(!contents || !Color){ return(0); } +int U_PMF_SOLIDBRUSHDATA_get(const char *contents, U_PMF_ARGB *Color, const char *blimit){ + if(!contents || !Color || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_SOLIDBRUSHDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Color, 4, 1, U_XE); return(1); } @@ -6513,12 +6768,14 @@ int U_PMF_SOLIDBRUSHDATA_get(const char *contents, U_PMF_ARGB *Color){ \param RangeCount Entries in CharRange array \param TabStops Array of tabstop locations \param CharRange Array of character ranges in the text + \param blimit one byte past the end of data EMF+ manual 2.2.2.44, Microsoft name: EmfPlusStringFormatData Object */ int U_PMF_STRINGFORMATDATA_get(const char *contents, uint32_t TabStopCount, uint32_t RangeCount, - const U_FLOAT **TabStops, const U_PMF_CHARACTERRANGE **CharRange){ - if(!contents || !TabStops|| !CharRange){ return(0); } + const U_FLOAT **TabStops, const U_PMF_CHARACTERRANGE **CharRange, const char *blimit){ + if(!contents || !TabStops|| !CharRange || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, (TabStopCount + 2*RangeCount)*4, blimit))return(0); *TabStops = NULL; if(TabStopCount > 0){ U_PMF_SERIAL_get(&contents, TabStops, 4, TabStopCount, U_LE); } *CharRange = NULL; @@ -6533,13 +6790,19 @@ int U_PMF_STRINGFORMATDATA_get(const char *contents, uint32_t TabStopCount, uint \param Flags BrushData flags \param WrapMode WrapMode enumeration \param Data Optional texture data + \param blimit one byte past the end of data EMF+ manual 2.2.2.45, Microsoft name: EmfPlusTextureBrushData Object + + Caller must check Data for possible memory access violations. */ -int U_PMF_TEXTUREBRUSHDATA_get(const char *contents, uint32_t *Flags, int32_t *WrapMode, const char **Data){ - if(!contents || !Flags || !WrapMode || !Data){ return(0); } +int U_PMF_TEXTUREBRUSHDATA_get(const char *contents, uint32_t *Flags, int32_t *WrapMode, const char **Data, const char *blimit){ + if(!contents || !Flags || !WrapMode || !Data || !blimit){ return(0); } + /* Important! This only checks the constant part, the caller must check that returned data doesn't exceed blimit */ + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_TEXTUREBRUSHDATA), blimit))return(0); U_PMF_SERIAL_get(&contents, Flags, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, WrapMode, 4, 1, U_LE); + if(contents >= blimit)return(0); // returned Data is variable size, this much at least must be true U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); } @@ -6549,16 +6812,25 @@ int U_PMF_TEXTUREBRUSHDATA_get(const char *contents, uint32_t *Flags, int32_t *W \return 1 on success, 0 on error \param contents Record from which to extract data \param HasImage True if this object has an Image - \param Matrix Transformation matrix, present if Flag BrushDataTransform is set. + \param Matrix Transformation matrix, NULL if Flag BrushDataTransform is not set. \param Image Image that contains the texture. - + \param blimit one byte past the end of data EMF+ manual 2.2.2.46, Microsoft name: EmfPlusTextureBrushOptionalData Object + + Caller must check Image for possible memory access violations. */ -int U_PMF_TEXTUREBRUSHOPTIONALDATA_get(const char *contents, int HasImage, U_PMF_TRANSFORMMATRIX *Matrix, const char **Image){ - if(!contents || !Matrix || !Image){ return(0); } - U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE); - U_PMF_PTRSAV_COND(Image, contents, HasImage); +int U_PMF_TEXTUREBRUSHOPTIONALDATA_get(const char *contents, int HasImage, U_PMF_TRANSFORMMATRIX *Matrix, + const char **Image, const char *blimit){ + if(!contents || !Image || !blimit){ return(0); } + if(Matrix){ + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_TRANSFORMMATRIX), blimit))return(0); + U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE); + } + if(HasImage){ + if(contents >= blimit)return(0); // returned Data is variable size, this much at least must be true + U_PMF_PTRSAV_COND(Image, contents, HasImage); + } return(1); } @@ -6567,11 +6839,13 @@ int U_PMF_TEXTUREBRUSHOPTIONALDATA_get(const char *contents, int HasImage, U_PMF \return 1 on success, 0 on error \param contents Record from which to extract data \param Matrix Transformation matrix, present if Flag BrushDataTransform is set. + \param blimit one byte past the end of data EMF+ manual 2.2.2.47, Microsoft name: EmfPlusTransformMatrix Object */ -int U_PMF_TRANSFORMMATRIX_get(const char *contents, U_PMF_TRANSFORMMATRIX *Matrix){ - if(!contents || !Matrix){ return(0); } +int U_PMF_TRANSFORMMATRIX_get(const char *contents, U_PMF_TRANSFORMMATRIX *Matrix, const char *blimit){ + if(!contents || !Matrix || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_TRANSFORMMATRIX), blimit))return(0); U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE); return(1); } @@ -6582,11 +6856,13 @@ int U_PMF_TRANSFORMMATRIX_get(const char *contents, U_PMF_TRANSFORMMATRIX *Matri \param contents Record from which to extract data \param Radius Blur radius in pixels \param ExpandEdge 1: expand bitmap by Radius; 0: bitmap size unchanged + \param blimit one byte past the end of data EMF+ manual 2.2.3.1, Microsoft name: BlurEffect Object */ -int U_PMF_IE_BLUR_get(const char *contents, U_FLOAT *Radius, uint32_t *ExpandEdge){ - if(!contents || !Radius || !ExpandEdge){ return(0); } +int U_PMF_IE_BLUR_get(const char *contents, U_FLOAT *Radius, uint32_t *ExpandEdge, const char *blimit){ + if(!contents || !Radius || !ExpandEdge || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_BLUR), blimit))return(0); U_PMF_SERIAL_get(&contents, Radius, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, ExpandEdge, 4, 1, U_LE); return(1); @@ -6598,11 +6874,13 @@ int U_PMF_IE_BLUR_get(const char *contents, U_FLOAT *Radius, uint32_t *ExpandEdg \param contents Record from which to extract data \param Brightness -255 to 255, 0 is unchanged, positive increases, negative decreases \param Contrast -100 to 100, 0 is unchanged, positive increases, negative decreases + \param blimit one byte past the end of data EMF+ manual 2.2.3.2, Microsoft name: BrightnessContrastEffect Object */ -int U_PMF_IE_BRIGHTNESSCONTRAST_get(const char *contents, int32_t *Brightness, int32_t *Contrast){ - if(!contents || !Brightness || !Contrast){ return(0); } +int U_PMF_IE_BRIGHTNESSCONTRAST_get(const char *contents, int32_t *Brightness, int32_t *Contrast, const char *blimit){ + if(!contents || !Brightness || !Contrast || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_BRIGHTNESSCONTRAST), blimit))return(0); U_PMF_SERIAL_get(&contents, Brightness, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Contrast, 4, 1, U_LE); return(1); @@ -6615,11 +6893,13 @@ int U_PMF_IE_BRIGHTNESSCONTRAST_get(const char *contents, int32_t *Brightness, i \param CyanRed -100 to 100, 0 is unchanged, positive increases Red & decreases Cyan, negative is opposite \param MagentaGreen -100 to 100, 0 is unchanged, positive increases Green & decreases Magenta, negative is opposite \param YellowBlue -100 to 100, 0 is unchanged, positive increases Blue & decreases Yellow, negative is opposite + \param blimit one byte past the end of data EMF+ manual 2.2.3.3, Microsoft name: ColorBalanceEffect Object */ -int U_PMF_IE_COLORBALANCE_get(const char *contents, int32_t *CyanRed, int32_t *MagentaGreen, int32_t *YellowBlue){ - if(!contents || !CyanRed || !MagentaGreen || !YellowBlue){ return(0); } +int U_PMF_IE_COLORBALANCE_get(const char *contents, int32_t *CyanRed, int32_t *MagentaGreen, int32_t *YellowBlue, const char *blimit){ + if(!contents || !CyanRed || !MagentaGreen || !YellowBlue || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_COLORBALANCE), blimit))return(0); U_PMF_SERIAL_get(&contents, CyanRed, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, MagentaGreen, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, YellowBlue, 4, 1, U_LE); @@ -6634,11 +6914,13 @@ int U_PMF_IE_COLORBALANCE_get(const char *contents, int32_t *CyanRed, int32_t *M \param Adjust CurveAdjustment enumeration \param Channel CurveChannel enumeration \param Intensity adjustment to apply. "Adjust" determines what field this is and range values. + \param blimit one byte past the end of data EMF+ manual 2.2.3.4, Microsoft name: ColorCurveEffect Object */ -int U_PMF_IE_COLORCURVE_get(const char *contents, uint32_t *Adjust, uint32_t *Channel, int32_t *Intensity){ - if(!contents || !Adjust || !Channel || !Intensity){ return(0); } +int U_PMF_IE_COLORCURVE_get(const char *contents, uint32_t *Adjust, uint32_t *Channel, int32_t *Intensity, const char *blimit){ + if(!contents || !Adjust || !Channel || !Intensity || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_COLORCURVE), blimit))return(0); U_PMF_SERIAL_get(&contents, Adjust, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Channel, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Intensity, 4, 1, U_LE); @@ -6653,12 +6935,14 @@ int U_PMF_IE_COLORCURVE_get(const char *contents, uint32_t *Adjust, uint32_t *Ch \param GLUT Green color lookup table \param RLUT Red color lookup table \param ALUT Alpha color lookup table + \param blimit one byte past the end of data EMF+ manual 2.2.3.5, Microsoft name: ColorLookupTableEffect Object */ int U_PMF_IE_COLORLOOKUPTABLE_get(const char *contents, - const uint8_t **BLUT, const uint8_t **GLUT, const uint8_t **RLUT, const uint8_t **ALUT){ - if(!contents || !BLUT || !GLUT || !RLUT || !ALUT){ return(0); } + const uint8_t **BLUT, const uint8_t **GLUT, const uint8_t **RLUT, const uint8_t **ALUT, const char *blimit){ + if(!contents || !BLUT || !GLUT || !RLUT || !ALUT || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_COLORLOOKUPTABLE) + 4 * 256, blimit))return(0); U_PMF_PTRSAV_SHIFT((const char **)BLUT, &contents, 256); U_PMF_PTRSAV_SHIFT((const char **)GLUT, &contents, 256); U_PMF_PTRSAV_SHIFT((const char **)RLUT, &contents, 256); @@ -6671,11 +6955,14 @@ int U_PMF_IE_COLORLOOKUPTABLE_get(const char *contents, \return 1 on success, 0 on error \param contents Record from which to extract data \param Matrix 5 x 5 color transformation matrix, First 4 rows are [{4 multiplier values},0.0] for R,G,B,A, last Row is [{4 color translation valuess}, 1.0] + \param blimit one byte past the end of data EMF+ manual 2.2.3.6, Microsoft name: ColorMatrixEffect Object */ -int U_PMF_IE_COLORMATRIX_get(const char *contents, U_PMF_IE_COLORMATRIX *Matrix){ - if(!contents || !Matrix){ return(0); } +int U_PMF_IE_COLORMATRIX_get(const char *contents, U_PMF_IE_COLORMATRIX *Matrix, const char *blimit){ + if(!contents || !Matrix || !blimit){ return(0); } + /* Important! This only checks the constant part, the caller must check that returned data doesn't exceed blimit */ + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_COLORMATRIX), blimit))return(0); U_PMF_SERIAL_get(&contents, Matrix, 4, 5*5, U_LE); return(1); } @@ -6687,11 +6974,13 @@ int U_PMF_IE_COLORMATRIX_get(const char *contents, U_PMF_IE_COLORMATRIX *Matrix) \param Hue -180 to 180, 0 is unchanged \param Saturation -100 to 100, 0 is unchanged \param Lightness -100 to 100, 0 is unchanged + \param blimit one byte past the end of data EMF+ manual 2.2.3.7, Microsoft name: HueSaturationLightnessEffect Object */ -int U_PMF_IE_HUESATURATIONLIGHTNESS_get(const char *contents, int32_t *Hue, int32_t *Saturation, int32_t *Lightness){ - if(!contents || !Hue || !Saturation || !Lightness){ return(0); } +int U_PMF_IE_HUESATURATIONLIGHTNESS_get(const char *contents, int32_t *Hue, int32_t *Saturation, int32_t *Lightness, const char *blimit){ + if(!contents || !Hue || !Saturation || !Lightness || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_HUESATURATIONLIGHTNESS), blimit))return(0); U_PMF_SERIAL_get(&contents, Hue, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Saturation, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Lightness, 4, 1, U_LE); @@ -6705,11 +6994,13 @@ int U_PMF_IE_HUESATURATIONLIGHTNESS_get(const char *contents, int32_t *Hue, int3 \param Highlight 0 to 100, 100 is unchanged \param Midtone -100 to 100, 0 is unchanged \param Shadow 0 to 100, 0 is unchanged + \param blimit one byte past the end of data EMF+ manual 2.2.3.8, Microsoft name: LevelsEffect Object */ -int U_PMF_IE_LEVELS_get(const char *contents, int32_t *Highlight, int32_t *Midtone, int32_t *Shadow){ - if(!contents || !Highlight || !Midtone || !Shadow){ return(0); } +int U_PMF_IE_LEVELS_get(const char *contents, int32_t *Highlight, int32_t *Midtone, int32_t *Shadow, const char *blimit){ + if(!contents || !Highlight || !Midtone || !Shadow || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_LEVELS), blimit))return(0); U_PMF_SERIAL_get(&contents, Highlight, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Midtone, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Shadow, 4, 1, U_LE); @@ -6722,12 +7013,15 @@ int U_PMF_IE_LEVELS_get(const char *contents, int32_t *Highlight, int32_t *Midto \param contents Record from which to extract data \param Elements Number of members in Rects \param Rects Caller must free. Pointer to memory holding an array of U_RECTL. + \param blimit one byte past the end of data EMF+ manual 2.2.3.9, Microsoft name: RedEyeCorrectionEffect Object */ -int U_PMF_IE_REDEYECORRECTION_get(const char *contents, int32_t *Elements, U_RECTL **Rects){ - if(!contents || !Elements || !Rects){ return(0); } +int U_PMF_IE_REDEYECORRECTION_get(const char *contents, int32_t *Elements, U_RECTL **Rects, const char *blimit){ + if(!contents || !Elements || !Rects || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_REDEYECORRECTION), blimit))return(0); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); + if(IS_MEM_UNSAFE(contents, *Elements * 4, blimit))return(0); *Rects = (U_RECTL *) malloc(*Elements * sizeof(U_RECTL)); if(!*Rects){ return(0); } U_PMF_SERIAL_get(&contents, *Rects, 4, *Elements * 4, U_LE); @@ -6740,11 +7034,13 @@ int U_PMF_IE_REDEYECORRECTION_get(const char *contents, int32_t *Elements, U_REC \param contents Record from which to extract data \param Radius Sharpening radius in pixels \param Sharpen 0 to 100, 0 is unchanged + \param blimit one byte past the end of data EMF+ manual 2.2.3.10, Microsoft name: SharpenEffect Object */ -int U_PMF_IE_SHARPEN_get(const char *contents, U_FLOAT *Radius, int32_t *Sharpen){ - if(!contents || !Radius || !Sharpen){ return(0); } +int U_PMF_IE_SHARPEN_get(const char *contents, U_FLOAT *Radius, int32_t *Sharpen, const char *blimit){ + if(!contents || !Radius || !Sharpen || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_SHARPEN), blimit))return(0); U_PMF_SERIAL_get(&contents, Radius, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Sharpen, 4, 1, U_LE); return(1); @@ -6756,16 +7052,51 @@ int U_PMF_IE_SHARPEN_get(const char *contents, U_FLOAT *Radius, int32_t *Sharpen \param contents Record from which to extract data \param Hue -180 to 180, [positive==clockwise] rotation in degrees starting from blue \param Amount -100 [add black] to 100[add white], 0 is unchanged. Change in hue on specified axis + \param blimit one byte past the end of data EMF+ manual 2.2.3.11, Microsoft name: TintEffect Object */ -int U_PMF_IE_TINT_get(const char *contents, int32_t *Hue, int32_t *Amount){ - if(!contents || !Hue || !Amount){ return(0); } +int U_PMF_IE_TINT_get(const char *contents, int32_t *Hue, int32_t *Amount, const char *blimit){ + if(!contents || !Hue || !Amount || !blimit){ return(0); } + if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_TINT), blimit))return(0); U_PMF_SERIAL_get(&contents, Hue, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Amount, 4, 1, U_LE); return(1); } +/* + + end of U_PMF_*_get() functions + ===================================================================================== + start of U_PMR_*_get() functions + + These functions all assume that the size field in the common EMF+ header has already + been checked, so that the extent the record claims exists in the data read in for the file. + Consequently none of them takes a blimit parameter. They generate a new one from the + header size field and contents if needed. + +*/ + +int U_PMR_common_stack_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *StackID){ + if(!contents || !StackID){ return(0); } + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_RESTORE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + U_PMF_SERIAL_get(&contents, StackID, 4, 1, U_LE); + return(1); +} + +/* for records that have a type but no associated flag bits or data */ +int U_PMR_common_header_get(const char *contents, U_PMF_CMN_HDR *Header){ + /* memory access safe, only uses the common header */ + if(!contents){ return(0); } + U_PMF_CMN_HDR_get(&contents, Header); + return(1); +} + /** \brief Get data from a U_PMR_OFFSETCLIP record \return 1 on success, 0 on error @@ -6779,7 +7110,12 @@ int U_PMF_IE_TINT_get(const char *contents, int32_t *Hue, int32_t *Amount){ int U_PMR_OFFSETCLIP_get(const char *contents, U_PMF_CMN_HDR *Header, U_FLOAT *dX, U_FLOAT *dY){ if(!contents){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_OFFSETCLIP))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + U_PMF_SERIAL_get(&contents, dX, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, dY, 4, 1, U_LE); return(1); @@ -6812,10 +7148,14 @@ int U_PMR_RESETCLIP_get(const char *contents, U_PMF_CMN_HDR *Header){ int U_PMR_SETCLIPPATH_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *PathID, int *CMenum){ if(!contents || !PathID || !CMenum){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *CMenum = (Flags >> U_FF_SHFT_CM4) & U_FF_MASK_CM4; - *PathID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SETCLIPPATH))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *CMenum = (lclHeader.Flags >> U_FF_SHFT_CM4) & U_FF_MASK_CM4; + *PathID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; return(1); } @@ -6833,9 +7173,13 @@ int U_PMR_SETCLIPRECT_get(const char *contents, U_PMF_CMN_HDR *Header, int *CMenum, U_PMF_RECTF *Rect){ if(!contents || !CMenum || !Rect ){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *CMenum = (Flags >> U_FF_SHFT_CM4) & U_FF_MASK_CM4; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SETCLIPRECT))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *CMenum = (lclHeader.Flags >> U_FF_SHFT_CM4) & U_FF_MASK_CM4; U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE); return(1); } @@ -6853,10 +7197,14 @@ int U_PMR_SETCLIPRECT_get(const char *contents, U_PMF_CMN_HDR *Header, int U_PMR_SETCLIPREGION_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *PathID, int *CMenum){ if(!contents || !PathID || !CMenum){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *CMenum = (Flags >> U_FF_SHFT_CM4) & U_FF_MASK_CM4; - *PathID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SETCLIPREGION))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *CMenum = (lclHeader.Flags >> U_FF_SHFT_CM4) & U_FF_MASK_CM4; + *PathID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; return(1); } @@ -6868,11 +7216,18 @@ int U_PMR_SETCLIPREGION_get(const char *contents, U_PMF_CMN_HDR *Header, \param Data Private data, may be anything EMF+ manual 2.3.2.1, Microsoft name: EmfPlusComment Record, Index 0x03 + + Caller must check Data for possible memory access violations. */ int U_PMR_COMMENT_get(const char *contents, U_PMF_CMN_HDR *Header, const char **Data){ if(!contents || !Data){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_COMMENT))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + U_PMF_PTRSAV_SHIFT(Data, &contents, 0); return(1); } @@ -6922,9 +7277,13 @@ int U_PMR_HEADER_get(const char *contents, U_PMF_CMN_HDR *Header, U_PMF_GRAPHICSVERSION *Version, int *IsDual, int *IsVideo, uint32_t *LogicalDpiX, uint32_t *LogicalDpiY){ if(!contents || !Version || !IsDual || !IsVideo || !LogicalDpiX || !LogicalDpiY){ return(0); } uint32_t tmp; - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *IsDual = (Flags & U_PPF_DM ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_HEADER))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *IsDual = (lclHeader.Flags & U_PPF_DM ? 1 : 0 ); U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, &tmp, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, LogicalDpiX, 4, 1, U_LE); @@ -6945,7 +7304,12 @@ int U_PMR_HEADER_get(const char *contents, U_PMF_CMN_HDR *Header, int U_PMR_CLEAR_get(const char *contents, U_PMF_CMN_HDR *Header, U_PMF_ARGB *Color){ if(!contents || !Color){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_CLEAR))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + U_PMF_SERIAL_get(&contents, Color, 4, 1, U_LE); return(1); } @@ -6968,16 +7332,26 @@ int U_PMR_DRAWARC_get(const char *contents, U_PMF_CMN_HDR *Header, U_FLOAT *Start, U_FLOAT *Sweep, U_PMF_RECTF *Rect){ if(!contents || !PenID || !ctype || !Start || !Sweep || !Rect){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *PenID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWARC))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, Start, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Sweep, 4, 1, U_LE); - U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE); + U_PMF_RECTF *Rects = NULL; + if(!U_PMF_VARRECTS_get(&contents, lclHeader.Flags, 1, &Rects, blimit))return(0); + memcpy(Rect,Rects,sizeof(U_PMF_RECTF)); + free(Rects); return(1); } + /** \brief Get data from a U_PMR_DRAWBEZIERS record \return 1 on success, 0 on error @@ -6996,14 +7370,20 @@ int U_PMR_DRAWBEZIERS_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *Elements, U_PMF_POINTF **Points){ if(!contents || !PenID || !ctype || !RelAbs || !Elements || !Points){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *RelAbs = (Flags & U_PPF_P ? 1 : 0 ); - *PenID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWBEZIERS))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *RelAbs = (lclHeader.Flags & U_PPF_P ? 1 : 0 ); + *PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); - U_PMF_VARPOINTS_get(&contents, Flags, *Elements, Points); - return(1); + int status = U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit ); + return(status); } /** @@ -7025,14 +7405,20 @@ int U_PMR_DRAWCLOSEDCURVE_get(const char *contents, U_PMF_CMN_HDR *Header, U_FLOAT *Tension, uint32_t *Elements, U_PMF_POINTF **Points){ if(!contents || !PenID || !ctype || !RelAbs || !Tension || !Elements || !Points){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *RelAbs = (Flags & U_PPF_P ? 1 : 0 ); - *PenID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWCLOSEDCURVE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *RelAbs = (lclHeader.Flags & U_PPF_P ? 1 : 0 ); + *PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, Tension, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); - U_PMF_VARPOINTS_get(&contents, Flags, *Elements, Points); + U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit); return(1); } @@ -7056,15 +7442,21 @@ int U_PMR_DRAWCURVE_get(const char *contents, U_PMF_CMN_HDR *Header, U_FLOAT *Tension, uint32_t *Offset, uint32_t *NSegs, uint32_t *Elements, U_PMF_POINTF **Points){ if(!contents || !PenID || !ctype || !Tension || !Offset || !NSegs || !Elements || !Points){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *PenID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWCURVE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, Tension, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Offset, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, NSegs, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); - U_PMF_VARPOINTS_get(&contents, Flags, *Elements, Points); + U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit); return(1); } @@ -7092,15 +7484,22 @@ int U_PMR_DRAWDRIVERSTRING_get(const char *contents, U_PMF_CMN_HDR *Header, uint16_t **Glyphs, U_PMF_POINTF **Points, U_PMF_TRANSFORMMATRIX **Matrix){ if(!contents || !FontID || !btype || !Tension || !BrushID || !DSOFlags || !HasMatrix || !Elements || !Glyphs || !Points || !Matrix){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *btype = (Flags & U_PPF_B ? 1 : 0 ); - *FontID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWDRIVERSTRING))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 ); + *FontID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, Tension, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */ U_PMF_SERIAL_get(&contents, DSOFlags, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, HasMatrix, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); + if(IS_MEM_UNSAFE(contents, *Elements*2 + *Elements*2*4 + 24, blimit))return(0); if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Glyphs, 2, *Elements, U_LE, (*DSOFlags & U_DSO_CmapLookup))){ return(0); } if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Points, 4, *Elements *2, U_LE, (*DSOFlags & U_DSO_RealizedAdvance))){ return(0); } if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Matrix, 4, 6, U_LE, (*HasMatrix))){ return(0); } @@ -7122,10 +7521,14 @@ int U_PMR_DRAWELLIPSE_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *PenID, int *ctype, U_PMF_RECTF *Rect){ if(!contents || !PenID || !ctype || !Rect){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *PenID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWELLIPSE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE); return(1); } @@ -7149,10 +7552,14 @@ int U_PMR_DRAWIMAGE_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *ImgAttrID, int32_t *SrcUnit, U_PMF_RECTF *SrcRect, U_PMF_RECTF *DstRect){ if(!contents || !ImgID || !ctype || !ImgAttrID || !SrcUnit || !SrcRect || !DstRect){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *ImgID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWIMAGE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *ImgID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, ImgAttrID, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, SrcUnit, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, SrcRect, 4, 4, U_LE); @@ -7182,17 +7589,23 @@ int U_PMR_DRAWIMAGEPOINTS_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *ImgAttrID, int32_t *SrcUnit, U_PMF_RECTF *SrcRect, uint32_t *Elements, U_PMF_POINTF **Points){ if(!contents || !ImgID || !ctype || !etype || !RelAbs || !ImgAttrID || !SrcUnit || !Elements || !Points){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *etype = (Flags & U_PPF_E ? 1 : 0 ); - *RelAbs = (Flags & U_PPF_P ? 1 : 0 ); - *ImgID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWIMAGEPOINTS))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *etype = (lclHeader.Flags & U_PPF_E ? 1 : 0 ); + *RelAbs = (lclHeader.Flags & U_PPF_P ? 1 : 0 ); + *ImgID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, ImgAttrID, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, SrcUnit, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, SrcRect, 4, 4, U_LE); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); - U_PMF_VARPOINTS_get(&contents, Flags, *Elements, Points); + U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit); return(1); } @@ -7215,14 +7628,20 @@ int U_PMR_DRAWLINES_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *Elements, U_PMF_POINTF **Points){ if(!contents || !PenID || !ctype || !dtype || !RelAbs || !Elements || !Points){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *dtype = (Flags & U_PPF_D ? 1 : 0 ); - *RelAbs = (Flags & U_PPF_P ? 1 : 0 ); - *PenID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWLINES))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *dtype = (lclHeader.Flags & U_PPF_D ? 1 : 0 ); + *RelAbs = (lclHeader.Flags & U_PPF_P ? 1 : 0 ); + *PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); - U_PMF_VARPOINTS_get(&contents, Flags, *Elements, Points); + U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit); return(1); } @@ -7239,9 +7658,13 @@ int U_PMR_DRAWLINES_get(const char *contents, U_PMF_CMN_HDR *Header, int U_PMR_DRAWPATH_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *PathID, uint32_t *PenID){ if(!contents || !PathID || !PenID){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *PathID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWPATH))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *PathID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, PenID, 4, 1, U_LE); return(1); } @@ -7264,13 +7687,22 @@ int U_PMR_DRAWPIE_get(const char *contents, U_PMF_CMN_HDR *Header, U_FLOAT *Start, U_FLOAT *Sweep, U_PMF_RECTF *Rect){ if(!contents || !PenID || !ctype || !Start || !Sweep || !Rect){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *PenID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWPIE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, Start, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Sweep, 4, 1, U_LE); - U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE); + U_PMF_RECTF *Rects = NULL; + if(!U_PMF_VARRECTS_get(&contents, lclHeader.Flags, 1, &Rects, blimit))return(0); + memcpy(Rect,Rects,sizeof(U_PMF_RECTF)); + free(Rects); return(1); } @@ -7294,12 +7726,18 @@ int U_PMR_DRAWRECTS_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *Elements, U_PMF_RECTF **Rects){ if(!contents || !PenID || !Elements || !Rects){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *PenID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWPIE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); - U_PMF_VARRECTS_get(&contents, Flags, *Elements, Rects); + U_PMF_VARRECTS_get(&contents, lclHeader.Flags, *Elements, Rects, blimit); return(1); } @@ -7323,14 +7761,21 @@ int U_PMR_DRAWSTRING_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *BrushID, uint32_t *FormatID, uint32_t *Elements, U_PMF_RECTF *Rect, uint16_t **String){ if(!contents || !FontID || !btype || !BrushID || !FormatID || !Elements || !String){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *btype = (Flags & U_PPF_B ? 1 : 0 ); - *FontID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWPIE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 ); + *FontID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */ U_PMF_SERIAL_get(&contents, FormatID, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE); + if(IS_MEM_UNSAFE(contents, *Elements * 2, blimit))return(0); if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)String, 2, *Elements, U_XE, 1)){ return(0); } return(1); } @@ -7356,16 +7801,22 @@ int U_PMR_FILLCLOSEDCURVE_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *BrushID, U_FLOAT *Tension, uint32_t *Elements, U_PMF_POINTF **Points){ if(!contents || !btype || !ctype || !ftype || !RelAbs || !BrushID || !Tension || !Elements || !Points){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *btype = (Flags & U_PPF_B ? 1 : 0 ); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *ftype = (Flags & U_PPF_F ? 1 : 0 ); - *RelAbs = (Flags & U_PPF_P ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWLINES))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 ); + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *ftype = (lclHeader.Flags & U_PPF_F ? 1 : 0 ); + *RelAbs = (lclHeader.Flags & U_PPF_P ? 1 : 0 ); U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */ U_PMF_SERIAL_get(&contents, Tension, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); - U_PMF_VARPOINTS_get(&contents, Flags, *Elements, Points); + U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit); return(1); } @@ -7386,10 +7837,14 @@ int U_PMR_FILLELLIPSE_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *BrushID, U_PMF_RECTF *Rect){ if(!contents || !btype || !ctype || !BrushID || !Rect){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *btype = (Flags & U_PPF_B ? 1 : 0 ); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_FILLELLIPSE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 ); + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */ U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE); return(1); @@ -7412,10 +7867,14 @@ int U_PMR_FILLPATH_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *PathID, int *btype, uint32_t *BrushID){ if(!contents || !PathID || !btype || !BrushID){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *btype = (Flags & U_PPF_B ? 1 : 0 ); - *PathID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_FILLPATH))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 ); + *PathID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */ return(1); } @@ -7439,14 +7898,23 @@ int U_PMR_FILLPIE_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *BrushID, U_FLOAT *Start, U_FLOAT *Sweep, U_PMF_RECTF *Rect){ if(!contents || !btype || !ctype || !BrushID || !Start || !Sweep || !Rect){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *btype = (Flags & U_PPF_B ? 1 : 0 ); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_FILLPIE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 ); + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */ U_PMF_SERIAL_get(&contents, Start, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Sweep, 4, 1, U_LE); - U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE); + U_PMF_RECTF *Rects = NULL; + if(!U_PMF_VARRECTS_get(&contents, lclHeader.Flags, 1, &Rects, blimit))return(0); + memcpy(Rect,Rects,sizeof(U_PMF_RECTF)); + free(Rects); return(1); } @@ -7469,14 +7937,20 @@ int U_PMR_FILLPOLYGON_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *BrushID, uint32_t *Elements, U_PMF_POINTF **Points){ if(!contents || !btype || !ctype || !RelAbs || !BrushID || !Elements || !Points){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *btype = (Flags & U_PPF_B ? 1 : 0 ); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *RelAbs = (Flags & U_PPF_R ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_DRAWLINES))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 ); + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *RelAbs = (lclHeader.Flags & U_PPF_R ? 1 : 0 ); U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */ U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); - U_PMF_VARPOINTS_get(&contents, Flags, *Elements, Points); + U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit); return(1); } @@ -7505,13 +7979,19 @@ int U_PMR_FILLRECTS_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *BrushID, uint32_t *Elements, U_PMF_RECTF **Rects){ if(!contents || !btype || !ctype || !BrushID || !Elements || !Rects){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *btype = (Flags & U_PPF_B ? 1 : 0 ); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_FILLRECTS))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 ); + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */ U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE); - U_PMF_VARRECTS_get(&contents, Flags, *Elements, Rects); + U_PMF_VARRECTS_get(&contents, lclHeader.Flags, *Elements, Rects, blimit); /* correct btype, if necessary, for invalid EMF+ input */ if((*BrushID > 63) & !*btype)*btype=1; return(1); @@ -7534,11 +8014,15 @@ int U_PMR_FILLREGION_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *RgnID, int *btype, int *ctype, uint32_t *BrushID){ if(!contents || !RgnID || !btype || !ctype || !BrushID){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *btype = (Flags & U_PPF_B ? 1 : 0 ); - *ctype = (Flags & U_PPF_C ? 1 : 0 ); - *RgnID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_FILLREGION))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 ); + *ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 ); + *RgnID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */ return(1); } @@ -7556,6 +8040,8 @@ int U_PMR_FILLREGION_get(const char *contents, U_PMF_CMN_HDR *Header, EMF+ manual 2.3.5.1, Microsoft name: EmfPlusObject Record, Index 0x13 + Caller must check Data for possible memory access violations. + OTHER NOTES: All objects are to be stored in the same table and retrieved by index. Documentation indicates that this table contains only 64 slots, although the index @@ -7585,11 +8071,15 @@ int U_PMR_OBJECT_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *ObjID, int *otype, int *ntype, uint32_t *TSize, const char **Data){ if(!contents || !ObjID || !otype || !ntype || !Data){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ntype = (Flags & U_PPF_N ? 1 : 0 ); - *ObjID = (Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; - *otype = (Flags >> U_FF_SHFT_OT) & U_FF_MASK_OT; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_OBJECT))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *ntype = (lclHeader.Flags & U_PPF_N ? 1 : 0 ); + *ObjID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8; + *otype = (lclHeader.Flags >> U_FF_SHFT_OT) & U_FF_MASK_OT; if(*ntype){ U_PMF_SERIAL_get(&contents, TSize, 4, 1, U_LE); } else { *TSize = 0; } U_PMF_PTRSAV_SHIFT(Data, &contents, 0); @@ -7606,12 +8096,19 @@ int U_PMR_OBJECT_get(const char *contents, U_PMF_CMN_HDR *Header, \param Data "Serialized image effects parameter block". One of the ImageEffects objects. EMF+ manual 2.3.5.2, Microsoft name: EmfPlusSerializableObject Record, Index 0x38 + + Caller must check Data for possible memory access violations. */ int U_PMR_SERIALIZABLEOBJECT_get(const char *contents, U_PMF_CMN_HDR *Header, uint8_t *GUID, uint32_t *Size, const char **Data){ if(!contents || !GUID || !Size || !Data){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SERIALIZABLEOBJECT))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + U_PMF_SERIAL_get(&contents, GUID, 1, 16, U_XE); U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE); U_PMF_PTRSAV_SHIFT(Data, &contents, 0); @@ -7631,10 +8128,14 @@ int U_PMR_SERIALIZABLEOBJECT_get(const char *contents, U_PMF_CMN_HDR *Header, int U_PMR_SETANTIALIASMODE_get(const char *contents, U_PMF_CMN_HDR *Header, int *SMenum, int *aatype){ if(!contents || !SMenum || !aatype){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *aatype = (Flags & U_PPF_AA ? 1 : 0 ); - *SMenum = (Flags >> U_FF_SHFT_AA) & U_FF_MASK_AA; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SETANTIALIASMODE))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *aatype = (lclHeader.Flags & U_PPF_AA ? 1 : 0 ); + *SMenum = (lclHeader.Flags >> U_FF_SHFT_AA) & U_FF_MASK_AA; return(1); } @@ -7649,6 +8150,7 @@ int U_PMR_SETANTIALIASMODE_get(const char *contents, U_PMF_CMN_HDR *Header, */ int U_PMR_SETCOMPOSITINGMODE_get(const char *contents, U_PMF_CMN_HDR *Header, int *CMenum){ + /* memory access safe, only uses the common header */ if(!contents || !CMenum){ return(0); } uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); *CMenum = (Flags >> U_FF_SHFT_CM) & U_FF_MASK_CM; @@ -7667,6 +8169,7 @@ int U_PMR_SETCOMPOSITINGMODE_get(const char *contents, U_PMF_CMN_HDR *Header, */ int U_PMR_SETCOMPOSITINGQUALITY_get(const char *contents, U_PMF_CMN_HDR *Header, int *CQenum){ + /* memory access safe, only uses the common header */ if(!contents || !CQenum){ return(0); } uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); *CQenum = (Flags >> U_FF_SHFT_CQ) & U_FF_MASK_CQ; @@ -7685,6 +8188,7 @@ int U_PMR_SETCOMPOSITINGQUALITY_get(const char *contents, U_PMF_CMN_HDR *Header, */ int U_PMR_SETINTERPOLATIONMODE_get(const char *contents, U_PMF_CMN_HDR *Header, int *IMenum){ + /* memory access safe, only uses the common header */ if(!contents || !IMenum){ return(0); } uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); *IMenum = (Flags >> U_FF_SHFT_IM) & U_FF_MASK_IM; @@ -7703,6 +8207,7 @@ int U_PMR_SETINTERPOLATIONMODE_get(const char *contents, U_PMF_CMN_HDR *Header, */ int U_PMR_SETPIXELOFFSETMODE_get(const char *contents, U_PMF_CMN_HDR *Header, int *POMenum){ + /* memory access safe, only uses the common header */ if(!contents || !POMenum){ return(0); } uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); *POMenum = (Flags >> U_FF_SHFT_PxOffM) & U_FF_MASK_PxOffM; @@ -7723,7 +8228,12 @@ int U_PMR_SETPIXELOFFSETMODE_get(const char *contents, U_PMF_CMN_HDR *Header, int U_PMR_SETRENDERINGORIGIN_get(const char *contents, U_PMF_CMN_HDR *Header, int32_t *X, int32_t *Y){ if(!contents || !X || !Y){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + if(!U_PMF_CMN_HDR_get(&contents, &lclHeader))return(0); + if(lclHeader.Size < sizeof(U_PMF_SETRENDERINGORIGIN))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + U_PMF_SERIAL_get(&contents, X, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Y, 4, 1, U_LE); return(1); @@ -7740,6 +8250,7 @@ int U_PMR_SETRENDERINGORIGIN_get(const char *contents, U_PMF_CMN_HDR *Header, */ int U_PMR_SETTEXTCONTRAST_get(const char *contents, U_PMF_CMN_HDR *Header, int *TGC){ + /* memory access safe, only uses the common header */ if(!contents || !TGC){ return(0); } uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); *TGC = (Flags >> U_FF_SHFT_TGC) & U_FF_MASK_TGC; @@ -7758,6 +8269,7 @@ int U_PMR_SETTEXTCONTRAST_get(const char *contents, U_PMF_CMN_HDR *Header, */ int U_PMR_SETTEXTRENDERINGHINT_get(const char *contents, U_PMF_CMN_HDR *Header, int *TRHenum){ + /* memory access safe, only uses the common header */ if(!contents || !TRHenum){ return(0); } uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); *TRHenum = (Flags >> U_FF_SHFT_TRH) & U_FF_MASK_TRH; @@ -7781,9 +8293,13 @@ int U_PMR_BEGINCONTAINER_get(const char *contents, U_PMF_CMN_HDR *Header, int *UTenum, U_PMF_RECTF *DstRect, U_PMF_RECTF *SrcRect, uint32_t *StackID){ if(!contents || !UTenum || !DstRect || !SrcRect || !StackID){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *UTenum = (Flags >> U_FF_SHFT_UT) & U_FF_MASK_UT; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SETCLIPREGION))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *UTenum = (lclHeader.Flags >> U_FF_SHFT_UT) & U_FF_MASK_UT; U_PMF_SERIAL_get(&contents, DstRect, 4, 4, U_LE); U_PMF_SERIAL_get(&contents, SrcRect, 4, 4, U_LE); U_PMF_SERIAL_get(&contents, StackID, 4, 1, U_LE); @@ -7800,10 +8316,7 @@ int U_PMR_BEGINCONTAINER_get(const char *contents, U_PMF_CMN_HDR *Header, EMF+ manual 2.3.7.2, Microsoft name: EmfPlusBeginContainerNoParams Record, Index 0x28 */ int U_PMR_BEGINCONTAINERNOPARAMS_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *StackID){ - if(!contents || !StackID){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); - U_PMF_SERIAL_get(&contents, StackID, 4, 1, U_LE); - return(1); + return(U_PMR_common_stack_get(contents, Header, StackID)); } /** @@ -7815,12 +8328,8 @@ int U_PMR_BEGINCONTAINERNOPARAMS_get(const char *contents, U_PMF_CMN_HDR *Header EMF+ manual 2.3.7.3, Microsoft name: EmfPlusEndContainer Record, Index 0x29 */ -int U_PMR_ENDCONTAINER_get(const char *contents, U_PMF_CMN_HDR *Header, - uint32_t *StackID){ - if(!contents || !StackID){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); - U_PMF_SERIAL_get(&contents, StackID, 4, 1, U_LE); - return(1); +int U_PMR_ENDCONTAINER_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *StackID){ + return(U_PMR_common_stack_get(contents, Header, StackID)); } /** @@ -7833,10 +8342,7 @@ int U_PMR_ENDCONTAINER_get(const char *contents, U_PMF_CMN_HDR *Header, EMF+ manual 2.3.7.4, Microsoft name: EmfPlusRestore Record, Index 0x26 */ int U_PMR_RESTORE_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *StackID){ - if(!contents || !StackID){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); - U_PMF_SERIAL_get(&contents, StackID, 4, 1, U_LE); - return(1); + return(U_PMR_common_stack_get(contents, Header, StackID)); } /** @@ -7849,10 +8355,7 @@ int U_PMR_RESTORE_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *Sta EMF+ manual 2.3.7.5, Microsoft name: EmfPlusSave Record, Index 0x25 */ int U_PMR_SAVE_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *StackID){ - if(!contents || !StackID){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); - U_PMF_SERIAL_get(&contents, StackID, 4, 1, U_LE); - return(1); + return(U_PMR_common_stack_get(contents, Header, StackID)); } /** @@ -7870,11 +8373,17 @@ int U_PMR_SETTSCLIP_get(const char *contents, U_PMF_CMN_HDR *Header, int *ctype, uint32_t *Elements, U_PMF_RECTF **Rects){ if(!contents || !ctype || !Elements || !Rects){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *ctype = (Flags & U_PPF_K ? 1 : 0 ); - *Elements = (Flags >> U_FF_SHFT_TSC) & U_FF_MASK_TSC; - U_PMF_CMN_HDR_get(&contents, Header); - U_PMF_VARRECTS_get(&contents, Flags, *Elements, Rects); + + const char *blimit = contents; + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SETTSCLIP))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + blimit += lclHeader.Size; + + *ctype = (lclHeader.Flags & U_PPF_K ? 1 : 0 ); + *Elements = (lclHeader.Flags >> U_FF_SHFT_TSC) & U_FF_MASK_TSC; + U_PMF_VARRECTS_get(&contents, lclHeader.Flags, *Elements, Rects, blimit); return(1); } @@ -7898,6 +8407,8 @@ int U_PMR_SETTSCLIP_get(const char *contents, U_PMF_CMN_HDR *Header, \param Data Palette (optional) EMF+ manual 2.3.8.2, Microsoft name: EmfPlusSetTSGraphics Record, Index 0x39 + + Caller must check Data for possible memory access violations. */ int U_PMR_SETTSGRAPHICS_get(const char *contents, U_PMF_CMN_HDR *Header, int *vgatype, int *pptype, @@ -7909,10 +8420,14 @@ int U_PMR_SETTSGRAPHICS_get(const char *contents, U_PMF_CMN_HDR *Header, !AntiAliasMode || !TextRenderHint || !CompositingMode || !CompositingQuality || !RenderOriginX || !RenderOriginY || !TextContrast || !FilterType || !PixelOffset || !WorldToDevice || !Data){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *vgatype = (Flags & U_PPF_VGA ? 1 : 0 ); - *pptype = (Flags & U_PPF_PP ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SETTSGRAPHICS))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *vgatype = (lclHeader.Flags & U_PPF_VGA ? 1 : 0 ); + *pptype = (lclHeader.Flags & U_PPF_PP ? 1 : 0 ); U_PMF_SERIAL_get(&contents, AntiAliasMode, 1, 1, U_XE); U_PMF_SERIAL_get(&contents, TextRenderHint, 1, 1, U_XE); U_PMF_SERIAL_get(&contents, CompositingMode, 1, 1, U_XE); @@ -7940,9 +8455,13 @@ int U_PMR_MULTIPLYWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header int *xmtype, U_PMF_TRANSFORMMATRIX *Matrix){ if(!contents || !xmtype || !Matrix){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *xmtype = (Flags & U_PPF_XM ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_MULTIPLYWORLDTRANSFORM))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *xmtype = (lclHeader.Flags & U_PPF_XM ? 1 : 0 ); U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE); return(1); } @@ -7956,9 +8475,7 @@ int U_PMR_MULTIPLYWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header EMF+ manual 2.3.9.2, Microsoft name: EmfPlusResetWorldTransform Record, Index 0x2B */ int U_PMR_RESETWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header){ - if(!contents){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); - return(1); + return( U_PMR_common_header_get(contents,Header)); } /** @@ -7975,9 +8492,13 @@ int U_PMR_ROTATEWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header, int *xmtype, U_FLOAT *Angle){ if(!contents || !xmtype || !Angle){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *xmtype = (Flags & U_PPF_XM ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_ROTATEWORLDTRANSFORM))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *xmtype = (lclHeader.Flags & U_PPF_XM ? 1 : 0 ); U_PMF_SERIAL_get(&contents, Angle, 4, 1, U_LE); return(1); } @@ -7997,9 +8518,13 @@ int U_PMR_SCALEWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header, int *xmtype, U_FLOAT *Sx, U_FLOAT *Sy){ if(!contents || !xmtype || !Sx || !Sy){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *xmtype = (Flags & U_PPF_XM ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SCALEWORLDTRANSFORM))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *xmtype = (lclHeader.Flags & U_PPF_XM ? 1 : 0 ); U_PMF_SERIAL_get(&contents, Sx, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Sy, 4, 1, U_LE); return(1); @@ -8019,9 +8544,13 @@ int U_PMR_SETPAGETRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header, int *PUenum, U_FLOAT *Scale){ if(!contents || !PUenum || !Scale){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *PUenum = (Flags >> U_FF_SHFT_PU) & U_FF_MASK_PU; - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SETPAGETRANSFORM))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *PUenum = (lclHeader.Flags >> U_FF_SHFT_PU) & U_FF_MASK_PU; U_PMF_SERIAL_get(&contents, Scale, 4, 1, U_LE); return(1); } @@ -8038,7 +8567,12 @@ int U_PMR_SETPAGETRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header, int U_PMR_SETWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header, U_PMF_TRANSFORMMATRIX *Matrix){ if(!contents || !Matrix){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_SETWORLDTRANSFORM))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE); return(1); } @@ -8058,9 +8592,13 @@ int U_PMR_TRANSLATEWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Heade int *xmtype, U_FLOAT *Dx, U_FLOAT *Dy){ if(!contents || !xmtype || !Dx || !Dy){ return(0); } - uint16_t Flags = U_PMF_HEADERFLAGS_get(contents); - *xmtype = (Flags & U_PPF_XM ? 1 : 0 ); - U_PMF_CMN_HDR_get(&contents, Header); + + U_PMF_CMN_HDR lclHeader; + U_PMF_CMN_HDR_get(&contents, &lclHeader); + if(lclHeader.Size < sizeof(U_PMF_TRANSLATEWORLDTRANSFORM))return(0); + if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); } + + *xmtype = (lclHeader.Flags & U_PPF_XM ? 1 : 0 ); U_PMF_SERIAL_get(&contents, Dx, 4, 1, U_LE); U_PMF_SERIAL_get(&contents, Dy, 4, 1, U_LE); return(1); @@ -8079,9 +8617,7 @@ int U_PMR_TRANSLATEWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Heade the path by using the current pen, and fills its interior by using the current brush." */ int U_PMR_STROKEFILLPATH_get(const char *contents, U_PMF_CMN_HDR *Header){ - if(!contents){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); - return(1); + return( U_PMR_common_header_get(contents,Header)); } /** @@ -8093,9 +8629,7 @@ int U_PMR_STROKEFILLPATH_get(const char *contents, U_PMF_CMN_HDR *Header){ EMF+ manual mentioned in 2.1.1.1, reserved, not otherwise documented, Microsoft name: EmfPlusMultiFormatStart Record, Index 0x05 */ int U_PMR_MULTIFORMATSTART_get(const char *contents, U_PMF_CMN_HDR *Header){ - if(!contents){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); - return(1); + return( U_PMR_common_header_get(contents,Header)); } /** @@ -8107,9 +8641,7 @@ int U_PMR_MULTIFORMATSTART_get(const char *contents, U_PMF_CMN_HDR *Header){ EMF+ manual mentioned in 2.1.1.1, reserved, not otherwise documented, Microsoft name: EmfPlusMultiFormatSection Record, Index 0x06 */ int U_PMR_MULTIFORMATSECTION_get(const char *contents, U_PMF_CMN_HDR *Header){ - if(!contents){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); - return(1); + return( U_PMR_common_header_get(contents,Header)); } /** @@ -8121,9 +8653,7 @@ int U_PMR_MULTIFORMATSECTION_get(const char *contents, U_PMF_CMN_HDR *Header){ EMF+ manual mentioned in 2.1.1.1, reserved, not otherwise documented, Microsoft name: EmfPlusMultiFormatEnd Record, Index 0x06 */ int U_PMR_MULTIFORMATEND_get(const char *contents, U_PMF_CMN_HDR *Header){ - if(!contents){ return(0); } - U_PMF_CMN_HDR_get(&contents, Header); - return(1); + return( U_PMR_common_header_get(contents,Header)); } diff --git a/src/libuemf/upmf.h b/src/libuemf/upmf.h index 27ac94a89..dbda02ba7 100644 --- a/src/libuemf/upmf.h +++ b/src/libuemf/upmf.h @@ -27,11 +27,11 @@ /* File: upmf.h -Version: 0.0.2 -Date: 04-NOV-2013 +Version: 0.0.4 +Date: 17-MAR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2013 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifndef _UPMF_ @@ -1805,9 +1805,8 @@ typedef struct { /** @brief EMF+ manual 2.2.2.25, Microsoft name: EmfPlusLinearGradientBrushOptionalData Object For U_PMF_LINEARGRADIENTBRUSHDATA data field */ -typedef struct { - U_PMF_ROTMATRIX Matrix; //!< Rotation matrix, Manuals says that this should be Transformation matrix, but last two values are missing -/* variable part of object, not part of structure. +/* Entire object is variable and not part of a structure! U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA + U_PMF_ROTMATRIX Matrix; //!< Rotation matrix, Manuals says that this should be Transformation matrix, but last two values are missing (various) pattern; //!< Presence and meaning depend on Flags field, see below Flag values @@ -1818,7 +1817,6 @@ typedef struct { 0 0 1 U_PMF_BLENDFACTORS 0 1 1 U_PMF_BLENDFACTORS, U_PMF_BLENDFACTORS */ -} U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA; /** @brief EMF+ manual 2.2.2.26, Microsoft name: EmfPlusLinePath Object */ typedef struct { @@ -1888,7 +1886,10 @@ typedef struct { Bitfields in the FILE (LITTLE endian here, manual uses BIG endian) are: bits 4-7 PathPointType flags bits 0-3 PathPointType enumeration + @{ */ +typedef uint8_t U_PMF_PATHPOINTTYPE; //!< EMF+ manual 2.2.2.31, Microsoft name: EmfPlusPathPointType Object +/** @} */ /** \defgroup U_PMF_PPTYPERLE PMF Run Length Encoded Path Point Types @brief EMF+ manual 2.2.2.32, Microsoft name: EmfPlusPathPointTypeRLE Object @@ -2838,6 +2839,7 @@ void U_PMF_MEMCPY_DSTSHIFT(char **Dst, const void *Src, size_t Size); void U_PMF_REPCPY_DSTSHIFT(char **Dst, const void *Src, size_t Size, size_t Reps); void U_PMF_PTRSAV_SHIFT(const char **Dst, const char **Src, size_t Size); uint16_t U_PMF_HEADERFLAGS_get(const char *contents); +int U_PMF_RECORD_SIZE_get(const char *contents); int U_PMF_CMN_HDR_get(const char **contents, U_PMF_CMN_HDR *Header); int U_OID_To_OT(uint32_t OID); int U_OID_To_BT(uint32_t OID); @@ -3035,77 +3037,77 @@ U_PSEUDO_OBJ *U_PMR_STROKEFILLPATH_set(void); /* EMF+ prototypes (objects_get) */ -int U_PMF_BRUSH_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data); -int U_PMF_CUSTOMLINECAP_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data); -int U_PMF_FONT_get(const char *contents, uint32_t *Version, U_FLOAT *EmSize, uint32_t *SizeUnit, int32_t *FSFlags, uint32_t *Length, const char **Data); -int U_PMF_IMAGE_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data); -int U_PMF_IMAGEATTRIBUTES_get(const char *contents, uint32_t *Version, uint32_t *WrapMode, uint32_t *ClampColor, uint32_t *ObjectClamp); -int U_PMF_PATH_get(const char *contents, uint32_t *Version, uint32_t *Count, uint16_t *Flags, const char **Points, const char **Types); -int U_PMF_PEN_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **PenData, const char **Brush); -int U_PMF_REGION_get(const char *contents, uint32_t *Version, uint32_t *Count, const char **Nodes); -int U_PMF_STRINGFORMAT_get(const char *contents, U_PMF_STRINGFORMAT *Sfs, const char **Data); -int U_PMF_ARGB_get(const char *contents, uint8_t *Blue, uint8_t *Green, uint8_t *Red, uint8_t *Alpha); -int U_PMF_BITMAP_get(const char *contents, U_PMF_BITMAP *Bs, const char **Data); -int U_PMF_BITMAPDATA_get(const char *contents, U_PMF_PALETTE *Ps, const char **Colors, const char **Data); -int U_PMF_BLENDCOLORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Positions, const char **Colors); -int U_PMF_BLENDFACTORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Positions, U_FLOAT **Factors); -int U_PMF_BOUNDARYPATHDATA_get(const char *contents, int32_t *Size, const char **Data); -int U_PMF_BOUNDARYPOINTDATA_get(const char *contents, int32_t *Elements, U_PMF_POINTF **Points); -int U_PMF_CHARACTERRANGE_get(const char *contents, int32_t *First, int32_t *Length); -int U_PMF_COMPOUNDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT **Widths); -int U_PMF_COMPRESSEDIMAGE_get(const char *contents, const char **Data); -int U_PMF_CUSTOMENDCAPDATA_get(const char *contents, int32_t *Size, const char **Data); -int U_PMF_CUSTOMLINECAPARROWDATA_get(const char *contents, U_PMF_CUSTOMLINECAPARROWDATA *Ccad); -int U_PMF_CUSTOMLINECAPDATA_get(const char *contents, U_PMF_CUSTOMLINECAPDATA *Clcd, const char **Data); -int U_PMF_CUSTOMLINECAPOPTIONALDATA_get(const char *contents, uint32_t Flags, const char **FillData, const char **LineData); -int U_PMF_CUSTOMSTARTCAPDATA_get(const char *contents, int32_t *Size, const char **Data); -int U_PMF_DASHEDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT **Lengths); -int U_PMF_FILLPATHOBJ_get(const char *contents, int32_t *Size, const char **Data); -int U_PMF_FOCUSSCALEDATA_get(const char *contents, uint32_t *Count, U_FLOAT *ScaleX, U_FLOAT *ScaleY); -int U_PMF_GRAPHICSVERSION_get(const char *contents, int *Signature, int *GrfVersion); -int U_PMF_HATCHBRUSHDATA_get(const char *contents, uint32_t *Style, U_PMF_ARGB *Foreground, U_PMF_ARGB *Background); -int U_PMF_INTEGER7_get(const char **contents, U_FLOAT *Value); -int U_PMF_INTEGER15_get(const char **contents, U_FLOAT *Value); +int U_PMF_BRUSH_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data, const char *blimit); +int U_PMF_CUSTOMLINECAP_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data, const char *blimit); +int U_PMF_FONT_get(const char *contents, uint32_t *Version, U_FLOAT *EmSize, uint32_t *SizeUnit, int32_t *FSFlags, uint32_t *Length, const char **Data, const char *blimit); +int U_PMF_IMAGE_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data, const char *blimit); +int U_PMF_IMAGEATTRIBUTES_get(const char *contents, uint32_t *Version, uint32_t *WrapMode, uint32_t *ClampColor, uint32_t *ObjectClamp, const char *blimit); +int U_PMF_PATH_get(const char *contents, uint32_t *Version, uint32_t *Count, uint16_t *Flags, const char **Points, const char **Types, const char *blimit); +int U_PMF_PEN_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **PenData, const char **Brush, const char *blimit); +int U_PMF_REGION_get(const char *contents, uint32_t *Version, uint32_t *Count, const char **Nodes, const char *blimit); +int U_PMF_STRINGFORMAT_get(const char *contents, U_PMF_STRINGFORMAT *Sfs, const char **Data, const char *blimit); +int U_PMF_ARGB_get(const char *contents, uint8_t *Blue, uint8_t *Green, uint8_t *Red, uint8_t *Alpha, const char *blimit); +int U_PMF_BITMAP_get(const char *contents, U_PMF_BITMAP *Bs, const char **Data, const char *blimit); +int U_PMF_BITMAPDATA_get(const char *contents, U_PMF_PALETTE *Ps, const char **Colors, const char **Data, const char *blimit); +int U_PMF_BLENDCOLORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Positions, const char **Colors, const char *blimit); +int U_PMF_BLENDFACTORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Positions, U_FLOAT **Factors, const char *blimit); +int U_PMF_BOUNDARYPATHDATA_get(const char *contents, int32_t *Size, const char **Data, const char *blimit); +int U_PMF_BOUNDARYPOINTDATA_get(const char *contents, int32_t *Elements, U_PMF_POINTF **Points, const char *blimit); +int U_PMF_CHARACTERRANGE_get(const char *contents, int32_t *First, int32_t *Length, const char *blimit); +int U_PMF_COMPOUNDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT **Widths, const char *blimit); +int U_PMF_COMPRESSEDIMAGE_get(const char *contents, const char **Data, const char *blimit); +int U_PMF_CUSTOMENDCAPDATA_get(const char *contents, int32_t *Size, const char **Data, const char *blimit); +int U_PMF_CUSTOMLINECAPARROWDATA_get(const char *contents, U_PMF_CUSTOMLINECAPARROWDATA *Ccad, const char *blimit); +int U_PMF_CUSTOMLINECAPDATA_get(const char *contents, U_PMF_CUSTOMLINECAPDATA *Clcd, const char **Data, const char *blimit); +int U_PMF_CUSTOMLINECAPOPTIONALDATA_get(const char *contents, uint32_t Flags, const char **FillData, const char **LineData, const char *blimit); +int U_PMF_CUSTOMSTARTCAPDATA_get(const char *contents, int32_t *Size, const char **Data, const char *blimit); +int U_PMF_DASHEDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT **Lengths, const char *blimit); +int U_PMF_FILLPATHOBJ_get(const char *contents, int32_t *Size, const char **Data, const char *blimit); +int U_PMF_FOCUSSCALEDATA_get(const char *contents, uint32_t *Count, U_FLOAT *ScaleX, U_FLOAT *ScaleY, const char *blimit); +int U_PMF_GRAPHICSVERSION_get(const char *contents, int *Signature, int *GrfVersion, const char *blimit); +int U_PMF_HATCHBRUSHDATA_get(const char *contents, uint32_t *Style, U_PMF_ARGB *Foreground, U_PMF_ARGB *Background, const char *blimit); +int U_PMF_INTEGER7_get(const char **contents, U_FLOAT *Value, const char *blimit); +int U_PMF_INTEGER15_get(const char **contents, U_FLOAT *Value, const char *blimit); int U_PMF_LANGUAGEIDENTIFIER_get(U_PMF_LANGUAGEIDENTIFIER LId, int *SubLId, int *PriLId); -int U_PMF_LINEARGRADIENTBRUSHDATA_get(const char *contents, U_PMF_LINEARGRADIENTBRUSHDATA *Lgbd, const char **Data); -int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Flags, U_PMF_TRANSFORMMATRIX *Tm, const char **Bc, const char **BfH, const char **BfV); -int U_PMF_LINEPATH_get(const char *contents, int32_t *Size, const char **Data); -int U_PMF_METAFILE_get(const char *contents, uint32_t *Type, uint32_t *Size, const char **Data); -int U_PMF_PALETTE_get(const char *contents, uint32_t *Flags, uint32_t *Elements, const char **Data); -int U_PMF_PATHGRADIENTBRUSHDATA_get(const char *contents, U_PMF_PATHGRADIENTBRUSHDATA *Pgbd, const char **Gradient, const char **Boundary, const char **Data); -int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Flags, U_PMF_TRANSFORMMATRIX *Matrix, const char **Pattern, const char **Data); -int U_PMF_PATHPOINTTYPE_get(const char *contents, int *Flags, int *Type); -int U_PMF_PATHPOINTTYPERLE_get(const char *contents, int *Bezier, int *RL, int *Ppt); -int U_PMF_PENDATA_get(const char *contents, uint32_t *Flags, uint32_t *Unit, U_FLOAT *Width, const char **Data); +int U_PMF_LINEARGRADIENTBRUSHDATA_get(const char *contents, U_PMF_LINEARGRADIENTBRUSHDATA *Lgbd, const char **Data, const char *blimit); +int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Flags, U_PMF_TRANSFORMMATRIX *Tm, const char **Bc, const char **BfH, const char **BfV, const char *blimit); +int U_PMF_LINEPATH_get(const char *contents, int32_t *Size, const char **Data, const char *blimit); +int U_PMF_METAFILE_get(const char *contents, uint32_t *Type, uint32_t *Size, const char **Data, const char *blimit); +int U_PMF_PALETTE_get(const char *contents, uint32_t *Flags, uint32_t *Elements, const char **Data, const char *blimit); +int U_PMF_PATHGRADIENTBRUSHDATA_get(const char *contents, U_PMF_PATHGRADIENTBRUSHDATA *Pgbd, const char **Gradient, const char **Boundary, const char **Data, const char *blimit); +int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Flags, U_PMF_TRANSFORMMATRIX *Matrix, const char **Pattern, const char **Data, const char *blimit); +int U_PMF_PATHPOINTTYPE_get(const char *contents, int *Flags, int *Type, const char *blimit); +int U_PMF_PATHPOINTTYPERLE_get(const char *contents, int *Bezier, int *RL, int *Ppt, const char *blimit); +int U_PMF_PENDATA_get(const char *contents, uint32_t *Flags, uint32_t *Unit, U_FLOAT *Width, const char **Data, const char *blimit); int U_PMF_PENOPTIONALDATA_get(const char *contents, uint32_t Flags, U_PMF_TRANSFORMMATRIX *Matrix, int32_t *StartCap, int32_t *EndCap, uint32_t *Join, U_FLOAT *MiterLimit, int32_t *Style, int32_t *DLCap, U_FLOAT *DLOffset, - const char **DLData, int32_t *Alignment, const char **CmpndLineData, const char **CSCapData, const char **CECapData); -int U_PMF_POINT_get(const char **contents, U_FLOAT *X, U_FLOAT *Y); -int U_PMF_POINTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y); -int U_PMF_POINTR_get(const char **contents, U_FLOAT *X, U_FLOAT *Y); -int U_PMF_RECT_get(const char **contents, int16_t *X, int16_t *Y, int16_t *Width, int16_t *Height); -int U_PMF_RECTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, U_FLOAT *Width, U_FLOAT *Height); -int U_PMF_REGIONNODE_get(const char *contents, uint32_t *Type, const char **Data); + const char **DLData, int32_t *Alignment, const char **CmpndLineData, const char **CSCapData, const char **CECapData, const char *blimit); +int U_PMF_POINT_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, const char *blimit); +int U_PMF_POINTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, const char *blimit); +int U_PMF_POINTR_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, const char *blimit); +int U_PMF_RECT_get(const char **contents, int16_t *X, int16_t *Y, int16_t *Width, int16_t *Height, const char *blimit); +int U_PMF_RECTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, U_FLOAT *Width, U_FLOAT *Height, const char *blimit); +int U_PMF_REGIONNODE_get(const char *contents, uint32_t *Type, const char **Data, const char *blimit); /* There is no U_PMF_REGIONNODECHILDNODES_get, see the note in upmf.c */ -int U_PMF_REGIONNODEPATH_get(const char *contents, int32_t *Size, const char **Data); -int U_PMF_SOLIDBRUSHDATA_get(const char *contents, U_PMF_ARGB *Color); +int U_PMF_REGIONNODEPATH_get(const char *contents, int32_t *Size, const char **Data, const char *blimit); +int U_PMF_SOLIDBRUSHDATA_get(const char *contents, U_PMF_ARGB *Color, const char *blimit); int U_PMF_STRINGFORMATDATA_get(const char *contents, uint32_t TabStopCount, uint32_t RangeCount, - const U_FLOAT **TabStops, const U_PMF_CHARACTERRANGE **CharRange); -int U_PMF_TEXTUREBRUSHDATA_get(const char *contents, uint32_t *Flags, int32_t *WrapMode, const char **Data); -int U_PMF_TEXTUREBRUSHOPTIONALDATA_get(const char *contents, int HasImage, U_PMF_TRANSFORMMATRIX *Matrix, const char **Image); -int U_PMF_TRANSFORMMATRIX_get(const char *contents, U_PMF_TRANSFORMMATRIX *Matrix); -int U_PMF_IE_BLUR_get(const char *contents, U_FLOAT *Radius, uint32_t *ExpandEdge); -int U_PMF_IE_BRIGHTNESSCONTRAST_get(const char *contents, int32_t *Brightness, int32_t *Contrast); -int U_PMF_IE_COLORBALANCE_get(const char *contents, int32_t *CyanRed, int32_t *MagentaGreen, int32_t *YellowBlue); -int U_PMF_IE_COLORCURVE_get(const char *contents, uint32_t *Adjust, uint32_t *Channel, int32_t *Intensity); + const U_FLOAT **TabStops, const U_PMF_CHARACTERRANGE **CharRange, const char *blimit); +int U_PMF_TEXTUREBRUSHDATA_get(const char *contents, uint32_t *Flags, int32_t *WrapMode, const char **Data, const char *blimit); +int U_PMF_TEXTUREBRUSHOPTIONALDATA_get(const char *contents, int HasImage, U_PMF_TRANSFORMMATRIX *Matrix, const char **Image, const char *blimit); +int U_PMF_TRANSFORMMATRIX_get(const char *contents, U_PMF_TRANSFORMMATRIX *Matrix, const char *blimit); +int U_PMF_IE_BLUR_get(const char *contents, U_FLOAT *Radius, uint32_t *ExpandEdge, const char *blimit); +int U_PMF_IE_BRIGHTNESSCONTRAST_get(const char *contents, int32_t *Brightness, int32_t *Contrast, const char *blimit); +int U_PMF_IE_COLORBALANCE_get(const char *contents, int32_t *CyanRed, int32_t *MagentaGreen, int32_t *YellowBlue, const char *blimit); +int U_PMF_IE_COLORCURVE_get(const char *contents, uint32_t *Adjust, uint32_t *Channel, int32_t *Intensity, const char *blimit); int U_PMF_IE_COLORLOOKUPTABLE_get(const char *contents, - const uint8_t **BLUT, const uint8_t **GLUT, const uint8_t **RLUT, const uint8_t **ALUT); -int U_PMF_IE_COLORMATRIX_get(const char *contents, U_PMF_IE_COLORMATRIX *Matrix); -int U_PMF_IE_HUESATURATIONLIGHTNESS_get(const char *contents, int32_t *Hue, int32_t *Saturation, int32_t *Lightness); -int U_PMF_IE_LEVELS_get(const char *contents, int32_t *Highlight, int32_t *Midtone, int32_t *Shadow); -int U_PMF_IE_REDEYECORRECTION_get(const char *contents, int32_t *Elements, U_RECTL **Rects); -int U_PMF_IE_SHARPEN_get(const char *contents, U_FLOAT *Radius, int32_t *Sharpen); -int U_PMF_IE_TINT_get(const char *contents, int32_t *Hue, int32_t *Amount); + const uint8_t **BLUT, const uint8_t **GLUT, const uint8_t **RLUT, const uint8_t **ALUT, const char *blimit); +int U_PMF_IE_COLORMATRIX_get(const char *contents, U_PMF_IE_COLORMATRIX *Matrix, const char *blimit); +int U_PMF_IE_HUESATURATIONLIGHTNESS_get(const char *contents, int32_t *Hue, int32_t *Saturation, int32_t *Lightness, const char *blimit); +int U_PMF_IE_LEVELS_get(const char *contents, int32_t *Highlight, int32_t *Midtone, int32_t *Shadow, const char *blimit); +int U_PMF_IE_REDEYECORRECTION_get(const char *contents, int32_t *Elements, U_RECTL **Rects, const char *blimit); +int U_PMF_IE_SHARPEN_get(const char *contents, U_FLOAT *Radius, int32_t *Sharpen, const char *blimit); +int U_PMF_IE_TINT_get(const char *contents, int32_t *Hue, int32_t *Amount, const char *blimit); /* EMF+ prototypes (records_get) */ diff --git a/src/libuemf/upmf_print.c b/src/libuemf/upmf_print.c index 13bbfade8..7d9598b0d 100644 --- a/src/libuemf/upmf_print.c +++ b/src/libuemf/upmf_print.c @@ -6,11 +6,11 @@ /* File: upmf_print.c -Version: 0.0.3 -Date: 24-MAR-2014 +Version: 0.0.5 +Date: 24-MAR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2014 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ /* compiler options: @@ -30,6 +30,7 @@ extern "C" { #include #include "upmf_print.h" #include "uemf_print.h" +#include "uemf_safe.h" //! \cond @@ -49,7 +50,7 @@ int U_PMR_NODATAREC_print(const char *contents){ /* this function is not visible in the API. Common routine used by many functions that draw points. */ -void U_PMF_VARPOINTS_print(const char **contents, int Flags, uint32_t Elements){ +void U_PMF_VARPOINTS_print(const char **contents, int Flags, uint32_t Elements, const char *blimit){ unsigned int i; U_FLOAT Xpos, Ypos; @@ -58,9 +59,9 @@ void U_PMF_VARPOINTS_print(const char **contents, int Flags, uint32_t Elements){ else { printf(" + Points(Float):"); } for(Xpos = Ypos = i = 0; i1 are child nodes. + \param blimit one byte past the end of data EMF+ manual 2.2.2.40, Microsoft name: EmfPlusRegionNode Object */ -int U_PMF_REGIONNODE_print(const char *contents, int Level){ +int U_PMF_REGIONNODE_print(const char *contents, int Level, const char *blimit){ int len=4; /* Type will always be present */ uint32_t Type; const char *Data; - int status = U_PMF_REGIONNODE_get(contents, &Type, &Data); + int status = U_PMF_REGIONNODE_get(contents, &Type, &Data, blimit); if(status){ printf("\n + RegionNode(Level:%d) { Type:%X(",Level,Type); U_PMF_NODETYPE_print(Type); printf(")"); if(Type >= U_RNDT_And && Type <= U_RNDT_Complement){ - len += U_PMF_REGIONNODECHILDNODES_print(Data, Level+1); + len += U_PMF_REGIONNODECHILDNODES_print(Data, Level+1, blimit); } else if(Type == U_RNDT_Rect){ len += sizeof(U_PMF_RECTF); - (void) U_PMF_RECTF_print(&Data); + (void) U_PMF_RECTF_print(&Data, blimit); printf("\n"); } else if(Type == U_RNDT_Path){ - len += U_PMF_REGIONNODEPATH_print(Data); + len += U_PMF_REGIONNODEPATH_print(Data, blimit); } /* U_RNDT_Empty and U_RNDT_Infinite do not change the length */ else if(Type == U_RNDT_Empty ){ printf(" Empty" ); } @@ -1624,18 +1702,19 @@ int U_PMF_REGIONNODE_print(const char *contents, int Level){ \return size on success, 0 on error \param contents Record from which to print data \param Level Tree level. This routine is recursive and could go down many levels. 1 is the top, >1 are child nodes. + \param blimit one byte past the end of data EMF+ manual 2.2.2.41, Microsoft name: EmfPlusRegionNodeChildNodes Object */ -int U_PMF_REGIONNODECHILDNODES_print(const char *contents, int Level){ +int U_PMF_REGIONNODECHILDNODES_print(const char *contents, int Level, const char *blimit){ uint32_t size,rsize; printf(" RegionNodeChildNodes:\n"); printf(" + RNCN__Left(Level:%d) {", Level); - size = U_PMF_REGIONNODE_print(contents, Level); + size = U_PMF_REGIONNODE_print(contents, Level, blimit); printf(" + RNCN__Left(Level:%d) },\n", Level); if(size){ contents += size; printf(" + RNCN_Right(Level:%d) {", Level); - rsize = U_PMF_REGIONNODE_print(contents, Level); + rsize = U_PMF_REGIONNODE_print(contents, Level, blimit); size += rsize; printf(" + RNCN_Right(Level:%d) },\n",Level); } @@ -1646,15 +1725,16 @@ int U_PMF_REGIONNODECHILDNODES_print(const char *contents, int Level){ \brief Print data from a U_PMF_REGIONNODEPATH object \return Size of data on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.2.42, Microsoft name: EmfPlusRegionNodePath Object */ -int U_PMF_REGIONNODEPATH_print(const char *contents){ +int U_PMF_REGIONNODEPATH_print(const char *contents, const char * blimit){ int32_t Size; const char *Data; - int status = U_PMF_REGIONNODEPATH_get(contents, &Size, &Data); + int status = U_PMF_REGIONNODEPATH_get(contents, &Size, &Data, blimit); if(status){ printf(" RegionNodePath: \n"); - (void) U_PMF_PATH_print(Data); + (void) U_PMF_PATH_print(Data, blimit); status = Size + 4; /* data sizee + the 4 bytes encoding the size */ } return(status); @@ -1665,11 +1745,12 @@ int U_PMF_REGIONNODEPATH_print(const char *contents){ \brief Print data from a U_PMF_SOLIDBRUSHDATA object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.2.43, Microsoft name: EmfPlusSolidBrushData Object */ -int U_PMF_SOLIDBRUSHDATA_print(const char *contents){ +int U_PMF_SOLIDBRUSHDATA_print(const char *contents, const char *blimit){ U_PMF_ARGB Color; - int status = U_PMF_SOLIDBRUSHDATA_get(contents, &Color); + int status = U_PMF_SOLIDBRUSHDATA_get(contents, &Color, blimit); if(status){ printf(" SolidBrushData: "); (void) U_PMF_ARGB_print((char *) &Color); @@ -1683,12 +1764,13 @@ int U_PMF_SOLIDBRUSHDATA_print(const char *contents){ \param contents Record from which to print data \param TabStopCount Entries in TabStop array \param RangeCount Entries in CharRange array + \param blimit one byte past the end of data EMF+ manual 2.2.2.44, Microsoft name: EmfPlusStringFormatData Object */ -int U_PMF_STRINGFORMATDATA_print(const char *contents, uint32_t TabStopCount, uint32_t RangeCount){ +int U_PMF_STRINGFORMATDATA_print(const char *contents, uint32_t TabStopCount, uint32_t RangeCount, const char *blimit){ const U_FLOAT *TabStops; const U_PMF_CHARACTERRANGE *CharRange; - int status = U_PMF_STRINGFORMATDATA_get(contents, TabStopCount, RangeCount, &TabStops, &CharRange); + int status = U_PMF_STRINGFORMATDATA_get(contents, TabStopCount, RangeCount, &TabStops, &CharRange, blimit); if(status){ printf(" SFdata: TabStopCount:%u RangeCount:%u\n", TabStopCount, RangeCount); @@ -1708,13 +1790,14 @@ int U_PMF_STRINGFORMATDATA_print(const char *contents, uint32_t TabStopCount, ui \brief Print data from a U_PMF_TEXTUREBRUSHDATA object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.2.45, Microsoft name: EmfPlusTextureBrushData Object */ -int U_PMF_TEXTUREBRUSHDATA_print(const char *contents){ +int U_PMF_TEXTUREBRUSHDATA_print(const char *contents, const char *blimit){ uint32_t Flags; int32_t WrapMode; const char *Data; - int status = U_PMF_TEXTUREBRUSHDATA_get(contents, &Flags, &WrapMode, &Data); + int status = U_PMF_TEXTUREBRUSHDATA_get(contents, &Flags, &WrapMode, &Data, blimit); if(status){ printf(" + TBdata: Flags:%X WrapMode:%d", Flags, WrapMode); } @@ -1725,18 +1808,23 @@ int U_PMF_TEXTUREBRUSHDATA_print(const char *contents){ \brief Print data from a U_PMF_TEXTUREBRUSHOPTIONALDATA object \return 1 on success, 0 on error \param contents Record from which to print data + \param HasMatrix True if the record contains a matrix. \param HasImage True if the record contains an image. + \param blimit one byte past the end of data EMF+ manual 2.2.2.46, Microsoft name: EmfPlusTextureBrushOptionalData Object */ -int U_PMF_TEXTUREBRUSHOPTIONALDATA_print(const char *contents, int HasImage){ +int U_PMF_TEXTUREBRUSHOPTIONALDATA_print(const char *contents, int HasMatrix, int HasImage, const char *blimit){ U_PMF_TRANSFORMMATRIX Matrix; + U_PMF_TRANSFORMMATRIX *pMatrix; const char *Image; - int status = U_PMF_TEXTUREBRUSHOPTIONALDATA_get(contents, HasImage, &Matrix, &Image); + if(HasMatrix){ pMatrix = &Matrix; } + else { pMatrix = NULL; } + int status = U_PMF_TEXTUREBRUSHOPTIONALDATA_get(contents, HasImage, pMatrix, &Image, blimit); if(status){ printf(" + TBOptdata: Image:%c", (HasImage ? 'Y' : 'N')); (void) U_PMF_TRANSFORMMATRIX2_print(&Matrix); - (void) U_PMF_IMAGE_print(Image); + (void) U_PMF_IMAGE_print(Image, blimit); } return(status); } @@ -1745,11 +1833,12 @@ int U_PMF_TEXTUREBRUSHOPTIONALDATA_print(const char *contents, int HasImage){ \brief Print data from a U_PMF_TRANSFORMMATRIX object stored in file byte order. \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.2.47, Microsoft name: EmfPlusTransformMatrix Object */ -int U_PMF_TRANSFORMMATRIX_print(const char *contents){ +int U_PMF_TRANSFORMMATRIX_print(const char *contents, const char *blimit){ U_PMF_TRANSFORMMATRIX Tm; - int status = U_PMF_TRANSFORMMATRIX_get(contents, &Tm); + int status = U_PMF_TRANSFORMMATRIX_get(contents, &Tm, blimit); if(status){ U_PMF_TRANSFORMMATRIX2_print(&Tm); } @@ -1782,12 +1871,13 @@ int U_PMF_ROTMATRIX2_print(U_PMF_ROTMATRIX *Rm){ \brief Print data from a U_PMF_IE_BLUR object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.3.1, Microsoft name: BlurEffect Object */ -int U_PMF_IE_BLUR_print(const char *contents){ +int U_PMF_IE_BLUR_print(const char *contents, const char *blimit){ U_FLOAT Radius; uint32_t ExpandEdge; - int status = U_PMF_IE_BLUR_get(contents, &Radius, &ExpandEdge); + int status = U_PMF_IE_BLUR_get(contents, &Radius, &ExpandEdge, blimit); if(status){ printf("BlurEffect Radius:%f ExpandEdge:%u\n", Radius, ExpandEdge); } @@ -1798,11 +1888,12 @@ int U_PMF_IE_BLUR_print(const char *contents){ \brief Print data from a U_PMF_IE_BRIGHTNESSCONTRAST object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.3.2, Microsoft name: BrightnessContrastEffect Object */ -int U_PMF_IE_BRIGHTNESSCONTRAST_print(const char *contents){ +int U_PMF_IE_BRIGHTNESSCONTRAST_print(const char *contents, const char *blimit){ int32_t Brightness, Contrast; - int status = U_PMF_IE_BRIGHTNESSCONTRAST_get(contents, &Brightness, &Contrast); + int status = U_PMF_IE_BRIGHTNESSCONTRAST_get(contents, &Brightness, &Contrast, blimit); if(status){ printf("BrightnessContrastEffect Brightness:%d Contrast:%d\n", Brightness, Contrast); } @@ -1813,11 +1904,12 @@ int U_PMF_IE_BRIGHTNESSCONTRAST_print(const char *contents){ \brief Print data from a U_PMF_IE_COLORBALANCE object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.3.3, Microsoft name: ColorBalanceEffect Object */ -int U_PMF_IE_COLORBALANCE_print(const char *contents){ +int U_PMF_IE_COLORBALANCE_print(const char *contents, const char *blimit){ int32_t CyanRed, MagentaGreen, YellowBlue; - int status = U_PMF_IE_COLORBALANCE_get(contents, &CyanRed, &MagentaGreen, &YellowBlue); + int status = U_PMF_IE_COLORBALANCE_get(contents, &CyanRed, &MagentaGreen, &YellowBlue, blimit); if(status){ printf("ColorBalanceEffect CyanRed:%d MagentaGreen:%d YellowBlue:%d\n", CyanRed, MagentaGreen, YellowBlue); } @@ -1828,12 +1920,13 @@ int U_PMF_IE_COLORBALANCE_print(const char *contents){ \brief Print data from a U_PMF_IE_COLORCURVE object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.3.4, Microsoft name: ColorCurveEffect Object */ -int U_PMF_IE_COLORCURVE_print(const char *contents){ +int U_PMF_IE_COLORCURVE_print(const char *contents, const char *blimit){ uint32_t Adjust, Channel; int32_t Intensity; - int status = U_PMF_IE_COLORCURVE_get(contents, &Adjust, &Channel, &Intensity); + int status = U_PMF_IE_COLORCURVE_get(contents, &Adjust, &Channel, &Intensity, blimit); if(status){ printf("ColorBalanceEffect Adjust:%u Channel:%u Intensity:%d\n", Adjust, Channel, Intensity); } @@ -1844,11 +1937,12 @@ int U_PMF_IE_COLORCURVE_print(const char *contents){ \brief Print data from a U_PMF_IE_COLORLOOKUPTABLE object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.3.5, Microsoft name: ColorLookupTableEffect Object */ -int U_PMF_IE_COLORLOOKUPTABLE_print(const char *contents){ +int U_PMF_IE_COLORLOOKUPTABLE_print(const char *contents, const char *blimit){ const uint8_t *BLUT, *GLUT, *RLUT, *ALUT; - int status = U_PMF_IE_COLORLOOKUPTABLE_get(contents, &BLUT, &GLUT, &RLUT, &ALUT); + int status = U_PMF_IE_COLORLOOKUPTABLE_get(contents, &BLUT, &GLUT, &RLUT, &ALUT, blimit); if(status){ printf("ColorLookupTableEffect \n"); U_PMF_UINT8_ARRAY_print(" BLUT:", BLUT, 256, "\n"); @@ -1863,12 +1957,13 @@ int U_PMF_IE_COLORLOOKUPTABLE_print(const char *contents){ \brief Print data from a U_PMF_IE_COLORMATRIX object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.3.6, Microsoft name: ColorMatrixEffect Object */ -int U_PMF_IE_COLORMATRIX_print(const char *contents){ +int U_PMF_IE_COLORMATRIX_print(const char *contents, const char *blimit){ U_PMF_IE_COLORMATRIX Matrix; int i,j; - int status = U_PMF_IE_COLORMATRIX_get(contents, &Matrix); + int status = U_PMF_IE_COLORMATRIX_get(contents, &Matrix, blimit); if(status){ printf("ColorMatrixEffect\n"); for(i=0;i<5;i++){ @@ -1885,11 +1980,12 @@ int U_PMF_IE_COLORMATRIX_print(const char *contents){ \brief Print data from a U_PMF_IE_HUESATURATIONLIGHTNESS object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.3.7, Microsoft name: HueSaturationLightnessEffect Object */ -int U_PMF_IE_HUESATURATIONLIGHTNESS_print(const char *contents){ +int U_PMF_IE_HUESATURATIONLIGHTNESS_print(const char *contents, const char *blimit){ int32_t Hue, Saturation, Lightness; - int status = U_PMF_IE_HUESATURATIONLIGHTNESS_get(contents, &Hue, &Saturation, &Lightness); + int status = U_PMF_IE_HUESATURATIONLIGHTNESS_get(contents, &Hue, &Saturation, &Lightness, blimit); if(status){ printf("HueSaturationLightnessEffect Hue:%d Saturation:%d Lightness:%d\n", Hue, Saturation, Lightness); } @@ -1900,11 +1996,12 @@ int U_PMF_IE_HUESATURATIONLIGHTNESS_print(const char *contents){ \brief Print data from a U_PMF_IE_LEVELS object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.3.8, Microsoft name: LevelsEffect Object */ -int U_PMF_IE_LEVELS_print(const char *contents){ +int U_PMF_IE_LEVELS_print(const char *contents, const char *blimit){ int32_t Highlight, Midtone, Shadow; - int status = U_PMF_IE_LEVELS_get(contents, &Highlight, &Midtone, &Shadow); + int status = U_PMF_IE_LEVELS_get(contents, &Highlight, &Midtone, &Shadow, blimit); if(status){ printf("LevelEffect Highlight:%d Midtone:%d Shadow:%d\n", Highlight, Midtone, Shadow); } @@ -1915,12 +2012,13 @@ int U_PMF_IE_LEVELS_print(const char *contents){ \brief Print data from a U_PMF_IE_REDEYECORRECTION object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.3.9, Microsoft name: RedEyeCorrectionEffect Object */ -int U_PMF_IE_REDEYECORRECTION_print(const char *contents){ +int U_PMF_IE_REDEYECORRECTION_print(const char *contents, const char *blimit){ int32_t Elements; U_RECTL *Rects; - int status = U_PMF_IE_REDEYECORRECTION_get(contents, &Elements, &Rects); + int status = U_PMF_IE_REDEYECORRECTION_get(contents, &Elements, &Rects, blimit); if(status){ printf("RedEyeCorrectionEffect Elements:%u", Elements); for(; Elements; Elements--, Rects++){ @@ -1935,13 +2033,14 @@ int U_PMF_IE_REDEYECORRECTION_print(const char *contents){ /** \brief Print data from a U_PMF_IE_SHARPEN object \return 1 on success, 0 on error + \param blimit one byte past the end of data \param contents Record from which to print data EMF+ manual 2.2.3.10, Microsoft name: SharpenEffect Object */ -int U_PMF_IE_SHARPEN_print(const char *contents){ +int U_PMF_IE_SHARPEN_print(const char *contents, const char *blimit){ U_FLOAT Radius; int32_t Sharpen; - int status = U_PMF_IE_SHARPEN_get(contents, &Radius, &Sharpen); + int status = U_PMF_IE_SHARPEN_get(contents, &Radius, &Sharpen, blimit); if(status){ printf("SharpenEffect Radius:%f Sharpen:%u\n", Radius, Sharpen); } @@ -1952,11 +2051,12 @@ int U_PMF_IE_SHARPEN_print(const char *contents){ \brief Print data from a U_PMF_IE_TINT object \return 1 on success, 0 on error \param contents Record from which to print data + \param blimit one byte past the end of data EMF+ manual 2.2.3.11, Microsoft name: TintEffect Object */ -int U_PMF_IE_TINT_print(const char *contents){ +int U_PMF_IE_TINT_print(const char *contents, const char *blimit){ int32_t Hue, Amount; - int status = U_PMF_IE_TINT_get(contents, &Hue, &Amount); + int status = U_PMF_IE_TINT_get(contents, &Hue, &Amount, blimit); if(status){ printf("TintEffect Hue:%d Amount:%d\n", Hue, Amount); } @@ -1981,6 +2081,9 @@ int U_PMR_OFFSETCLIP_print(const char *contents){ if(status){ printf(" + dx:%f dy:%f\n",dX,dY); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2007,6 +2110,9 @@ int U_PMR_SETCLIPPATH_print(const char *contents){ if(status){ printf(" + PathID:%u CMenum:%d\n",PathID,CMenum); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2027,6 +2133,9 @@ int U_PMR_SETCLIPRECT_print(const char *contents){ U_PMF_RECTF_S_print(&Rect); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2045,6 +2154,9 @@ int U_PMR_SETCLIPREGION_print(const char *contents){ U_PMF_COMBINEMODEENUMERATION_print(CMenum); printf(")\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2061,6 +2173,11 @@ int U_PMR_COMMENT_print(const char *contents){ unsigned int i=0; int status = U_PMR_COMMENT_get(contents, &Header, &Data); if(status){ + const char *blimit = contents + Header.Size; + if(IS_MEM_UNSAFE(Data, Header.DataSize, blimit)){ + printf(" corrupt record\n"); + return(0); + } /* try to print it, but only ASCII, bail on anything that is not ASCII */ printf(" + Data:"); for(i=0; i< Header.DataSize; i++,Data++){ @@ -2070,6 +2187,9 @@ int U_PMR_COMMENT_print(const char *contents){ } printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2107,9 +2227,12 @@ int U_PMR_HEADER_print(const char *contents){ if(status){ /* try to print it, but only ASCII, bail on anything that is not ASCII */ printf(" + "); - (void) U_PMF_GRAPHICSVERSION_print((char *) &Version); + (void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);; printf(" IsDual:%c IsVideo:%d LogicalDpiX,y:{%u,%u}\n",(IsDual ? 'Y' : 'N'),IsVideo,LogicalDpiX, LogicalDpiY); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2127,6 +2250,9 @@ int U_PMR_CLEAR_print(const char *contents){ printf(" + Color:"); (void) U_PMF_ARGB_print((char *) &Color); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2147,6 +2273,9 @@ int U_PMR_DRAWARC_print(const char *contents){ (void) U_PMF_VARRECTF_S_print(&Rect, 1); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2167,6 +2296,9 @@ int U_PMR_DRAWBEZIERS_print(const char *contents){ U_PMF_VARPOINTF_S_print(Points, Elements); free(Points); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2194,6 +2326,9 @@ int U_PMR_DRAWCLOSEDCURVE_print(const char *contents){ U_PMF_VARPOINTF_S_print(Points, Elements); free(Points); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2221,6 +2356,9 @@ int U_PMR_DRAWCURVE_print(const char *contents){ U_PMF_VARPOINTF_S_print(Points, Elements); free(Points); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2269,7 +2407,9 @@ int U_PMR_DRAWDRIVERSTRING_print(const char *contents){ free(Matrix); printf("\n"); } - + } + else { + printf(" corrupt record\n"); } return(status); } @@ -2290,6 +2430,9 @@ int U_PMR_DRAWELLIPSE_print(const char *contents){ (void) U_PMF_VARRECTF_S_print(&Rect, 1); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2313,6 +2456,9 @@ int U_PMR_DRAWIMAGE_print(const char *contents){ (void) U_PMF_RECTF_S_print(&DstRect); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2339,6 +2485,9 @@ int U_PMR_DRAWIMAGEPOINTS_print(const char *contents){ U_PMF_VARPOINTF_S_print(Points, Elements); free(Points); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2360,6 +2509,9 @@ int U_PMR_DRAWLINES_print(const char *contents){ U_PMF_VARPOINTF_S_print(Points, Elements); free(Points); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2375,6 +2527,9 @@ int U_PMR_DRAWPATH_print(const char *contents){ if(status){ printf(" + PathIdx:%d PenIdx:%d\n", PathIdx, PenIdx); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2395,6 +2550,9 @@ int U_PMR_DRAWPIE_print(const char *contents){ (void) U_PMF_VARRECTF_S_print(&Rect, 1); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2402,10 +2560,9 @@ int U_PMR_DRAWPIE_print(const char *contents){ \brief Print data from a U_PMR_DRAWRECTS record \return size of record in bytes on success, 0 on error \param contents Record from which to print data - \param blimit One byte past the last record in memory. EMF+ manual 2.3.4.13, Microsoft name: EmfPlusDrawRects Record, Index 0x0B */ -int U_PMR_DRAWRECTS_print(const char *contents, const char *blimit){ +int U_PMR_DRAWRECTS_print(const char *contents){ uint32_t PenID; int ctype; uint32_t Elements; @@ -2413,11 +2570,13 @@ int U_PMR_DRAWRECTS_print(const char *contents, const char *blimit){ U_PMF_CMN_HDR hdr; int status = U_PMR_DRAWRECTS_get(contents, &hdr, &PenID, &ctype, &Elements, &Rects); if(status){ - if(contents + hdr.Size >= blimit)return(0); printf(" + PenID:%u ctype:%d Elements:%u Rect:", PenID,ctype,Elements); (void) U_PMF_VARRECTF_S_print(Rects, Elements); printf("\n"); } + else { + printf(" corrupt record\n"); + } if(Rects)free(Rects); return(status); } @@ -2452,6 +2611,9 @@ int U_PMR_DRAWSTRING_print(const char *contents){ printf(" String(as_UTF8):(none)\n"); } } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2477,6 +2639,9 @@ int U_PMR_FILLCLOSEDCURVE_print(const char *contents){ U_PMF_VARPOINTF_S_print(Points, Elements); free(Points); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2498,6 +2663,9 @@ int U_PMR_FILLELLIPSE_print(const char *contents){ (void) U_PMF_VARRECTF_S_print(&Rect, 1); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2516,6 +2684,9 @@ int U_PMR_FILLPATH_print(const char *contents){ (void) U_PMF_VARBRUSHID_print(btype, BrushID); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2537,6 +2708,9 @@ int U_PMR_FILLPIE_print(const char *contents){ (void) U_PMF_VARRECTF_S_print(&Rect, 1); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2558,6 +2732,9 @@ int U_PMR_FILLPOLYGON_print(const char *contents){ U_PMF_VARPOINTF_S_print(Points, Elements); free(Points); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2565,23 +2742,24 @@ int U_PMR_FILLPOLYGON_print(const char *contents){ \brief Print data from a U_PMR_FILLRECTS record \return size of record in bytes on success, 0 on error \param contents Record from which to print data - \param blimit One byte past the last record in memory. EMF+ manual 2.3.4.20, Microsoft name: EmfPlusFillRects Record, Index 0x0A */ -int U_PMR_FILLRECTS_print(const char *contents, const char *blimit){ +int U_PMR_FILLRECTS_print(const char *contents){ int btype, ctype; uint32_t BrushID, Elements; U_PMF_RECTF *Rects; U_PMF_CMN_HDR hdr; int status = U_PMR_FILLRECTS_get(contents, &hdr, &btype,&ctype, &BrushID, &Elements, &Rects); if(status){ - if(contents + hdr.Size >= blimit)return(0); printf(" + btype:%d ctype:%d Elements:%u",btype,ctype,Elements); (void) U_PMF_VARBRUSHID_print(btype, BrushID); (void) U_PMF_VARRECTF_S_print(Rects, Elements); free(Rects); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2600,6 +2778,9 @@ int U_PMR_FILLREGION_print(const char *contents){ (void) U_PMF_VARBRUSHID_print(btype, BrushID); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2611,6 +2792,10 @@ int U_PMR_FILLREGION_print(const char *contents){ \param ObjCont Structure that holds accumulated object. \param term Flag used when an abnormal termination of a series of continuation records is encountered. EMF+ manual 2.3.5.1, Microsoft name: EmfPlusObject Record, Index 0x13 + + This is the ONLY EMF+ record type which needs an explicit blimit passed in. Since it glues + together multiple records, and calls itself recursively, the initial caller cannot determine + that all of the sizes will be OK from the first record's header. */ int U_PMR_OBJECT_print(const char *contents, const char *blimit, U_OBJ_ACCUM *ObjCont, int term){ U_PMF_CMN_HDR Header; @@ -2641,8 +2826,11 @@ int U_PMR_OBJECT_print(const char *contents, const char *blimit, U_OBJ_ACCUM *Ob /* In a corrupt EMF+ file we might hit a new type of record before all the continuation records expected have been found. If that happens terminate whatever we have accumulated so far, and then go on to emit the new (unexpected) record. */ - if(contents + Header.Size >= blimit)return(0); - if(!status)return(status); + if(IS_MEM_UNSAFE(contents, Header.Size, blimit))return(0); + if(!status){ + printf(" corrupt record\n"); + return(status); + } if((ObjCont->used > 0) && (U_OA_append(ObjCont, NULL, 0, otype, ObjID) < 0)){ U_PMR_OBJECT_print(contents, blimit, ObjCont, 1); } @@ -2665,16 +2853,17 @@ int U_PMR_OBJECT_print(const char *contents, const char *blimit, U_OBJ_ACCUM *Ob ttype = otype; } if(status){ + blimit = ObjCont->accum + ObjCont->used; /* more restrictive blimit, just to end of object */ switch(ttype){ - case U_OT_Brush: (void) U_PMF_BRUSH_print(ObjCont->accum); break; - case U_OT_Pen: (void) U_PMF_PEN_print(ObjCont->accum); break; - case U_OT_Path: (void) U_PMF_PATH_print(ObjCont->accum); break; - case U_OT_Region: (void) U_PMF_REGION_print(ObjCont->accum); break; - case U_OT_Image: (void) U_PMF_IMAGE_print(ObjCont->accum); break; - case U_OT_Font: (void) U_PMF_FONT_print(ObjCont->accum); break; - case U_OT_StringFormat: (void) U_PMF_STRINGFORMAT_print(ObjCont->accum); break; - case U_OT_ImageAttributes: (void) U_PMF_IMAGEATTRIBUTES_print(ObjCont->accum); break; - case U_OT_CustomLineCap: (void) U_PMF_CUSTOMLINECAP_print(ObjCont->accum,""); break; + case U_OT_Brush: (void) U_PMF_BRUSH_print(ObjCont->accum, blimit); break; + case U_OT_Pen: (void) U_PMF_PEN_print(ObjCont->accum, blimit); break; + case U_OT_Path: (void) U_PMF_PATH_print(ObjCont->accum, blimit); break; + case U_OT_Region: (void) U_PMF_REGION_print(ObjCont->accum, blimit); break; + case U_OT_Image: (void) U_PMF_IMAGE_print(ObjCont->accum, blimit); break; + case U_OT_Font: (void) U_PMF_FONT_print(ObjCont->accum, blimit); break; + case U_OT_StringFormat: (void) U_PMF_STRINGFORMAT_print(ObjCont->accum, blimit); break; + case U_OT_ImageAttributes: (void) U_PMF_IMAGEATTRIBUTES_print(ObjCont->accum, blimit); break; + case U_OT_CustomLineCap: (void) U_PMF_CUSTOMLINECAP_print(ObjCont->accum,"", blimit); break; case U_OT_Invalid: default: printf("INVALID OBJECT TYPE!!!!\n"); @@ -2707,24 +2896,27 @@ int U_PMR_SERIALIZABLEOBJECT_print(const char *contents){ printf("\n + Effect:"); free(string); switch(iee){ - case U_IEE_Unknown: printf("(undefined)\n"); break; - case U_IEE_BlurEffectGuid: U_PMF_IE_BLUR_print(Data); break; - case U_IEE_BrightnessContrastEffectGuid: U_PMF_IE_BRIGHTNESSCONTRAST_print(Data); break; - case U_IEE_ColorBalanceEffectGuid: U_PMF_IE_COLORBALANCE_print(Data); break; - case U_IEE_ColorCurveEffectGuid: U_PMF_IE_COLORCURVE_print(Data); break; - case U_IEE_ColorLookupTableEffectGuid: U_PMF_IE_COLORLOOKUPTABLE_print(Data); break; - case U_IEE_ColorMatrixEffectGuid: U_PMF_IE_COLORMATRIX_print(Data); break; - case U_IEE_HueSaturationLightnessEffectGuid: U_PMF_IE_HUESATURATIONLIGHTNESS_print(Data); break; - case U_IEE_LevelsEffectGuid: U_PMF_IE_LEVELS_print(Data); break; - case U_IEE_RedEyeCorrectionEffectGuid: U_PMF_IE_REDEYECORRECTION_print(Data); break; - case U_IEE_SharpenEffectGuid: U_PMF_IE_SHARPEN_print(Data); break; - case U_IEE_TintEffectGuid: U_PMF_IE_TINT_print(Data); break; + case U_IEE_Unknown: printf("(undefined)\n"); break; + case U_IEE_BlurEffectGuid: U_PMF_IE_BLUR_print(Data, Data + sizeof(U_PMF_IE_BLUR)); break; + case U_IEE_BrightnessContrastEffectGuid: U_PMF_IE_BRIGHTNESSCONTRAST_print(Data, Data + sizeof(U_PMF_IE_BRIGHTNESSCONTRAST)); break; + case U_IEE_ColorBalanceEffectGuid: U_PMF_IE_COLORBALANCE_print(Data, Data + sizeof(U_PMF_IE_COLORBALANCE)); break; + case U_IEE_ColorCurveEffectGuid: U_PMF_IE_COLORCURVE_print(Data, Data + sizeof(U_PMF_IE_COLORCURVE)); break; + case U_IEE_ColorLookupTableEffectGuid: U_PMF_IE_COLORLOOKUPTABLE_print(Data, Data + sizeof(U_PMF_IE_COLORLOOKUPTABLE)); break; + case U_IEE_ColorMatrixEffectGuid: U_PMF_IE_COLORMATRIX_print(Data, Data + sizeof(U_PMF_IE_COLORMATRIX)); break; + case U_IEE_HueSaturationLightnessEffectGuid: U_PMF_IE_HUESATURATIONLIGHTNESS_print(Data, Data + sizeof(U_PMF_IE_HUESATURATIONLIGHTNESS)); break; + case U_IEE_LevelsEffectGuid: U_PMF_IE_LEVELS_print(Data, Data + sizeof(U_PMF_IE_LEVELS)); break; + case U_IEE_RedEyeCorrectionEffectGuid: U_PMF_IE_REDEYECORRECTION_print(Data, Data + sizeof(U_PMF_IE_REDEYECORRECTION)); break; + case U_IEE_SharpenEffectGuid: U_PMF_IE_SHARPEN_print(Data, Data + sizeof(U_PMF_IE_SHARPEN)); break; + case U_IEE_TintEffectGuid: U_PMF_IE_TINT_print(Data, Data + sizeof(U_PMF_IE_TINT)); break; } } else { printf(" + GUID:ERROR Size:%u\n",Size); } } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2740,6 +2932,9 @@ int U_PMR_SETANTIALIASMODE_print(const char *contents){ if(status){ printf(" + SMenum:%d AntiAlias:%c\n",SMenum,(aatype ? 'Y' : 'N')); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2755,6 +2950,9 @@ int U_PMR_SETCOMPOSITINGMODE_print(const char *contents){ if(status){ printf(" + CMenum:%d\n",CMenum); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2770,6 +2968,9 @@ int U_PMR_SETCOMPOSITINGQUALITY_print(const char *contents){ if(status){ printf(" + CQenum:%d\n",CQenum); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2785,6 +2986,9 @@ int U_PMR_SETINTERPOLATIONMODE_print(const char *contents){ if(status){ printf(" + IMenum:%d\n",IMenum); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2800,6 +3004,9 @@ int U_PMR_SETPIXELOFFSETMODE_print(const char *contents){ if(status){ printf(" + POMenum:%d\n",POMenum); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2815,6 +3022,9 @@ int U_PMR_SETRENDERINGORIGIN_print(const char *contents){ if(status){ printf(" + X:%d Y:%d\n", X, Y); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2830,6 +3040,9 @@ int U_PMR_SETTEXTCONTRAST_print(const char *contents){ if(status){ printf(" + GC:%d\n", GC); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2845,6 +3058,9 @@ int U_PMR_SETTEXTRENDERINGHINT_print(const char *contents){ if(status){ printf(" + TRHenum:%d\n",TRHenum); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2865,6 +3081,9 @@ int U_PMR_BEGINCONTAINER_print(const char *contents){ printf(" SrcRect:"); (void) U_PMF_RECTF_S_print(&SrcRect); printf(" StackID:%u\n", StackID); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2880,6 +3099,9 @@ int U_PMR_BEGINCONTAINERNOPARAMS_print(const char *contents){ if(status){ printf(" + StackID:%u\n", StackID); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2895,6 +3117,9 @@ int U_PMR_ENDCONTAINER_print(const char *contents){ if(status){ printf(" + StackID:%u\n", StackID); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2910,6 +3135,9 @@ int U_PMR_RESTORE_print(const char *contents){ if(status){ printf(" + StackID:%u\n", StackID); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2925,6 +3153,9 @@ int U_PMR_SAVE_print(const char *contents){ if(status){ printf(" + StackID:%u\n", StackID); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2945,6 +3176,9 @@ int U_PMR_SETTSCLIP_print(const char *contents){ free(Rects); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2967,6 +3201,7 @@ int U_PMR_SETTSGRAPHICS_print(const char *contents){ &RenderOriginX, &RenderOriginY, &TextContrast, &FilterType, &PixelOffset, &WorldToDevice, &Data); if(status){ + const char *blimit = contents + status; printf(" + vgatype:%d pptype:%u",vgatype,pptype); printf(" AntiAliasMode:%u TextRenderHint:%u CompositingMode:%u CompositingQuality:%u", AntiAliasMode, TextRenderHint, CompositingMode, CompositingQuality); @@ -2974,9 +3209,12 @@ int U_PMR_SETTSGRAPHICS_print(const char *contents){ printf(" TextContrast:%u",TextContrast); printf(" WorldToDevice:"); U_PMF_TRANSFORMMATRIX2_print(&WorldToDevice); - if(pptype){ (void) U_PMF_PALETTE_print(Data); } + if(pptype && !U_PMF_PALETTE_print(Data, blimit))return(0); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -2996,6 +3234,9 @@ int U_PMR_MULTIPLYWORLDTRANSFORM_print(const char *contents){ U_PMF_TRANSFORMMATRIX2_print(&Matrix); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -3022,6 +3263,9 @@ int U_PMR_ROTATEWORLDTRANSFORM_print(const char *contents){ if(status){ printf(" + xmtype:%d Multiply:%s Angle:%f\n",xmtype,(xmtype ? "Post" : "Pre"), Angle); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -3038,6 +3282,9 @@ int U_PMR_SCALEWORLDTRANSFORM_print(const char *contents){ if(status){ printf(" + xmtype:%d Multiply:%s ScaleX:%f ScaleY:%f\n",xmtype,(xmtype ? "Post" : "Pre"), Sx, Sy); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -3054,6 +3301,9 @@ int U_PMR_SETPAGETRANSFORM_print(const char *contents){ if(status){ printf(" + UTenum:%d Scale:%f\n",UTenum, Scale); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -3071,6 +3321,9 @@ int U_PMR_SETWORLDTRANSFORM_print(const char *contents){ U_PMF_TRANSFORMMATRIX2_print(&Matrix); printf("\n"); } + else { + printf(" corrupt record\n"); + } return(status); } @@ -3087,6 +3340,9 @@ int U_PMR_TRANSLATEWORLDTRANSFORM_print(const char *contents){ if(status){ printf(" + xmtype:%d Multiply:%s TranslateX:%f TranlateY:%f\n",xmtype,(xmtype ? "Post" : "Pre"), Dx, Dy); } + else { + printf(" corrupt record\n"); + } return(status); } diff --git a/src/libuemf/upmf_print.h b/src/libuemf/upmf_print.h index 3ba6694eb..fe1c57d60 100644 --- a/src/libuemf/upmf_print.h +++ b/src/libuemf/upmf_print.h @@ -6,11 +6,11 @@ /* File: upmf_print.h -Version: 0.0.2 -Date: 17-OCT-2013 +Version: 0.0.4 +Date: 24-MAR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2013 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifndef _UPMF_PRINT_ @@ -33,77 +33,78 @@ int U_PMF_PX_FMT_ENUM_print(int pfe); int U_PMF_NODETYPE_print(int Type); /* prototypes for objects used in PMR records */ -int U_PMF_BRUSH_print(const char *contents); -int U_PMF_CUSTOMLINECAP_print(const char *contents, const char *Which); -int U_PMF_FONT_print(const char *contents); -int U_PMF_IMAGE_print(const char *contents); -int U_PMF_IMAGEATTRIBUTES_print(const char *contents); -int U_PMF_PATH_print(const char *contents); -int U_PMF_PEN_print(const char *contents); -int U_PMF_REGION_print(const char *contents); -int U_PMF_STRINGFORMAT_print(const char *contents); +int U_PMF_BRUSH_print(const char *contents, const char *blimit); +int U_PMF_CUSTOMLINECAP_print(const char *contents, const char *Which, const char *blimit); +int U_PMF_FONT_print(const char *contents, const char *blimit); +int U_PMF_IMAGE_print(const char *contents, const char *blimit); +int U_PMF_IMAGEATTRIBUTES_print(const char *contents, const char *blimit); +int U_PMF_PATH_print(const char *contents, const char *blimit); +int U_PMF_PEN_print(const char *contents, const char *blimit); +int U_PMF_REGION_print(const char *contents, const char *blimit); +int U_PMF_STRINGFORMAT_print(const char *contents, const char *blimit); int U_PMF_ARGB_print(const char *contents); -int U_PMF_BITMAP_print(const char *contents); -int U_PMF_BITMAPDATA_print(const char *contents); -int U_PMF_BLENDCOLORS_print(const char *contents); -int U_PMF_BLENDFACTORS_print(const char *contents, const char *type); -int U_PMF_BOUNDARYPATHDATA_print(const char *contents); -int U_PMF_BOUNDARYPOINTDATA_print(const char *contents); -int U_PMF_CHARACTERRANGE_print(const char *contents); -int U_PMF_COMPOUNDLINEDATA_print(const char *contents); -int U_PMF_COMPRESSEDIMAGE_print(const char *contents); -int U_PMF_CUSTOMENDCAPDATA_print(const char *contents); -int U_PMF_CUSTOMLINECAPARROWDATA_print(const char *contents); -int U_PMF_CUSTOMLINECAPDATA_print(const char *contents); -int U_PMF_CUSTOMLINECAPOPTIONALDATA_print(const char *contents, uint32_t Flags); -int U_PMF_CUSTOMSTARTCAPDATA_print(const char *contents); -int U_PMF_DASHEDLINEDATA_print(const char *contents); -int U_PMF_FILLPATHOBJ_print(const char *contents); -int U_PMF_FOCUSSCALEDATA_print(const char *contents); -int U_PMF_GRAPHICSVERSION_print(const char *contents); -int U_PMF_HATCHBRUSHDATA_print(const char *contents); +int U_PMF_BITMAP_print(const char *contents, const char *blimit); +int U_PMF_BITMAPDATA_print(const char *contents, const char *blimit); +int U_PMF_BLENDCOLORS_print(const char *contents, const char *blimit); +int U_PMF_BLENDFACTORS_print(const char *contents, const char *type, const char *blimit); +int U_PMF_BOUNDARYPATHDATA_print(const char *contents, const char *blimit); +int U_PMF_BOUNDARYPOINTDATA_print(const char *contents, const char *blimit); +int U_PMF_CHARACTERRANGE_print(const char *contents, const char *blimit); +int U_PMF_COMPOUNDLINEDATA_print(const char *contents, const char *blimit); +int U_PMF_COMPRESSEDIMAGE_print(const char *contents, const char *blimit); +int U_PMF_CUSTOMENDCAPDATA_print(const char *contents, const char *blimit); +int U_PMF_CUSTOMLINECAPARROWDATA_print(const char *contents, const char *blimit); +int U_PMF_CUSTOMLINECAPDATA_print(const char *contents, const char *blimit); +int U_PMF_CUSTOMLINECAPOPTIONALDATA_print(const char *contents, uint32_t Flags, const char *blimit); +int U_PMF_CUSTOMSTARTCAPDATA_print(const char *contents, const char *blimit); +int U_PMF_DASHEDLINEDATA_print(const char *contents, const char *blimit); +int U_PMF_FILLPATHOBJ_print(const char *contents, const char *blimit); +int U_PMF_FOCUSSCALEDATA_print(const char *contents, const char *blimit); +int U_PMF_GRAPHICSVERSION_memsafe_print(const char *contents); +int U_PMF_GRAPHICSVERSION_print(const char *contents, const char *blimit); +int U_PMF_HATCHBRUSHDATA_print(const char *contents, const char *blimit); int U_PMF_LANGUAGEIDENTIFIER_print(U_PMF_LANGUAGEIDENTIFIER LId); -int U_PMF_LINEARGRADIENTBRUSHDATA_print(const char *contents); -int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag); -int U_PMF_LINEPATH_print(const char *contents); -int U_PMF_METAFILE_print(const char *contents); -int U_PMF_PALETTE_print(const char *contents); -int U_PMF_PATHGRADIENTBRUSHDATA_print(const char *contents); -int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag); -int U_PMF_PATHPOINTTYPE_print(const char *contents); -int U_PMF_PATHPOINTTYPERLE_print(const char *contents); -int U_PMF_PENDATA_print(const char *contents); -int U_PMF_PENOPTIONALDATA_print(const char *contents, int Flags); -int U_PMF_POINT_print(const char **contents); -int U_PMF_POINTF_print(const char **contents); -int U_PMF_POINTR_print(const char **contents, U_FLOAT *Xpos, U_FLOAT *Ypos); +int U_PMF_LINEARGRADIENTBRUSHDATA_print(const char *contents, const char *blimit); +int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag, const char *blimit); +int U_PMF_LINEPATH_print(const char *contents, const char *blimit); +int U_PMF_METAFILE_print(const char *contents, const char *blimit); +int U_PMF_PALETTE_print(const char *contents, const char *blimit); +int U_PMF_PATHGRADIENTBRUSHDATA_print(const char *contents, const char *blimit); +int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag, const char *blimit); +int U_PMF_PATHPOINTTYPE_print(const char *contents, const char *blimit); +int U_PMF_PATHPOINTTYPERLE_print(const char *contents, const char *blimit); +int U_PMF_PENDATA_print(const char *contents, const char *blimit); +int U_PMF_PENOPTIONALDATA_print(const char *contents, int Flags, const char *blimit); +int U_PMF_POINT_print(const char **contents, const char *blimit); +int U_PMF_POINTF_print(const char **contents, const char *blimit); +int U_PMF_POINTR_print(const char **contents, U_FLOAT *Xpos, U_FLOAT *Ypos, const char *blimit); int U_PMF_POINT_S_print(U_PMF_POINT *Point); int U_PMF_POINTF_S_print(U_PMF_POINTF *Point); -int U_PMF_RECT_print(const char **contents); -int U_PMF_RECTF_print(const char **contents); +int U_PMF_RECT_print(const char **contents, const char *blimit); +int U_PMF_RECTF_print(const char **contents, const char *blimit); int U_PMF_RECT_S_print(U_PMF_RECT *Rect); int U_PMF_RECTF_S_print(U_PMF_RECTF *Rect); -int U_PMF_REGIONNODE_print(const char *contents, int Level); -int U_PMF_REGIONNODECHILDNODES_print(const char *contents, int Level); -int U_PMF_REGIONNODEPATH_print(const char *contents); -int U_PMF_SOLIDBRUSHDATA_print(const char *contents); -int U_PMF_STRINGFORMATDATA_print(const char *contents, uint32_t TabStopCount, uint32_t RangeCount); -int U_PMF_TEXTUREBRUSHDATA_print(const char *contents); -int U_PMF_TEXTUREBRUSHOPTIONALDATA_print(const char *contents, int HasImage); -int U_PMF_TRANSFORMMATRIX_print(const char *contents); +int U_PMF_REGIONNODE_print(const char *contents, int Level, const char *blimit); +int U_PMF_REGIONNODECHILDNODES_print(const char *contents, int Level, const char *blimit); +int U_PMF_REGIONNODEPATH_print(const char *contents, const char *blimit); +int U_PMF_SOLIDBRUSHDATA_print(const char *contents, const char *blimit); +int U_PMF_STRINGFORMATDATA_print(const char *contents, uint32_t TabStopCount, uint32_t RangeCount, const char *blimit); +int U_PMF_TEXTUREBRUSHDATA_print(const char *contents, const char *blimit); +int U_PMF_TEXTUREBRUSHOPTIONALDATA_print(const char *contents, int HasMatrix, int HasImage, const char *blimit); +int U_PMF_TRANSFORMMATRIX_print(const char *contents, const char *blimit); int U_PMF_TRANSFORMMATRIX2_print(U_PMF_TRANSFORMMATRIX *Matrix); int U_PMF_ROTMATRIX2_print(U_PMF_ROTMATRIX *Matrix); -int U_PMF_IE_BLUR_print(const char *contents); -int U_PMF_IE_BRIGHTNESSCONTRAST_print(const char *contents); -int U_PMF_IE_COLORBALANCE_print(const char *contents); -int U_PMF_IE_COLORCURVE_print(const char *contents); -int U_PMF_IE_COLORLOOKUPTABLE_print(const char *contents); -int U_PMF_IE_COLORMATRIX_print(const char *contents); -int U_PMF_IE_HUESATURATIONLIGHTNESS_print(const char *contents); -int U_PMF_IE_LEVELS_print(const char *contents); -int U_PMF_IE_REDEYECORRECTION_print(const char *contents); -int U_PMF_IE_SHARPEN_print(const char *contents); -int U_PMF_IE_TINT_print(const char *contents); +int U_PMF_IE_BLUR_print(const char *contents, const char *blimit); +int U_PMF_IE_BRIGHTNESSCONTRAST_print(const char *contents, const char *blimit); +int U_PMF_IE_COLORBALANCE_print(const char *contents, const char *blimit); +int U_PMF_IE_COLORCURVE_print(const char *contents, const char *blimit); +int U_PMF_IE_COLORLOOKUPTABLE_print(const char *contents, const char *blimit); +int U_PMF_IE_COLORMATRIX_print(const char *contents, const char *blimit); +int U_PMF_IE_HUESATURATIONLIGHTNESS_print(const char *contents, const char *blimit); +int U_PMF_IE_LEVELS_print(const char *contents, const char *blimit); +int U_PMF_IE_REDEYECORRECTION_print(const char *contents, const char *blimit); +int U_PMF_IE_SHARPEN_print(const char *contents, const char *blimit); +int U_PMF_IE_TINT_print(const char *contents, const char *blimit); /* prototypes for PMR records */ int U_PMR_OFFSETCLIP_print(const char *contents); @@ -127,14 +128,14 @@ int U_PMR_DRAWIMAGEPOINTS_print(const char *contents); int U_PMR_DRAWLINES_print(const char *contents); int U_PMR_DRAWPATH_print(const char *contents); int U_PMR_DRAWPIE_print(const char *contents); -int U_PMR_DRAWRECTS_print(const char *contents, const char *blimit); +int U_PMR_DRAWRECTS_print(const char *contents); int U_PMR_DRAWSTRING_print(const char *contents); int U_PMR_FILLCLOSEDCURVE_print(const char *contents); int U_PMR_FILLELLIPSE_print(const char *contents); int U_PMR_FILLPATH_print(const char *contents); int U_PMR_FILLPIE_print(const char *contents); int U_PMR_FILLPOLYGON_print(const char *contents); -int U_PMR_FILLRECTS_print(const char *contents, const char *blimit); +int U_PMR_FILLRECTS_print(const char *contents); int U_PMR_FILLREGION_print(const char *contents); int U_PMR_OBJECT_print(const char *contents, const char *blimit, U_OBJ_ACCUM *ObjCont, int term); int U_PMR_SERIALIZABLEOBJECT_print(const char *contents); diff --git a/src/libuemf/uwmf.c b/src/libuemf/uwmf.c index b378e587f..35d38f69a 100644 --- a/src/libuemf/uwmf.c +++ b/src/libuemf/uwmf.c @@ -19,8 +19,8 @@ /* File: uwmf.c -Version: 0.0.15 -Date: 11-APR-2014 +Version: 0.0.16 +Date: 25-MAR-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu Copyright: 2014 David Mathog and California Institute of Technology (Caltech) @@ -47,6 +47,7 @@ extern "C" { #endif #include "uwmf.h" #include "uwmf_endian.h" +#include "uemf_safe.h" /** \brief Look up the full numeric type of a WMR record by type. @@ -671,6 +672,51 @@ const char *U_wmr_escnames(int idx){ /* one prototype from uwmf_endian. Put it here because end user should never need to see it, so not in uemf.h or uwmf_endian.h */ void U_swap2(void *ul, unsigned int count); + +/** + \brief Check that the bitmap in the specified packed DIB is compatible with the record size + + \return 1 on success, 0 on failure + \param record EMF record that contains a DIB pixel array + \param blimit one byte past the end of the record. + + This method can only test DIBs that hold Microsoft's various bitmap types. PNG or JPG is just a bag + of bytes, and there is no possible way to derive from the known width and height how big it should be. + + This should not be called directly by end user code. +*/ +int packed_DIB_safe( + const char *record, + const char *blimit + ){ + int dibparams = U_BI_UNKNOWN; // type of image not yet determined + const char *px = NULL; // DIB pixels + const U_RGBQUAD *ct = NULL; // DIB color table + int bs; + int usedbytes; + + if(!bitmapinfo_safe(record, blimit))return(0); // this DIB has issues with colors fitting into the record + uint32_t width, height, colortype, numCt, invert; // these values will be set in get_DIB_params + // next call returns pointers and values, but allocates no memory + dibparams = wget_DIB_params(record, &px, (const U_RGBQUAD **) &ct, &numCt, &width, &height, &colortype, &invert); + // sanity checking + if(numCt && colortype >= U_BCBM_COLOR16)return(0); //color tables not used above 16 bit pixels + if(!numCt && colortype < U_BCBM_COLOR16)return(0); //color tables mandatory for < 16 bit + + if(dibparams ==U_BI_RGB){ + // this is the only DIB type where we can calculate how big it should be when stored in the WMF file + bs = colortype/8; + if(bs<1){ + usedbytes = (width*colortype + 7)/8; // width of line in fully and partially occupied bytes + } + else { + usedbytes = width*bs; + } + if(IS_MEM_UNSAFE(px, usedbytes, blimit))return(0); + } + return(1); +} + //! \endcond /** @@ -4439,9 +4485,7 @@ size_t U_WMRRECSAFE_get( memcpy(&Size16, contents + offsetof(U_METARECORD,Size16_4), 4); size = 2*Size16; /* Record is not self consistent - described size past the end of WMF in memory */ - if(size < U_SIZE_METARECORD || - contents + size - 1 >= blimit || - contents + size - 1 < contents)size=0; + if(size < U_SIZE_METARECORD || IS_MEM_UNSAFE(contents, size, blimit))size=0; return(size); } @@ -4826,20 +4870,21 @@ int wmfheader_get( ){ uint32_t Key; int size=0; - if(!Placeable || !Header || contents + 4 >= blimit)return(0); + if(!contents || !Placeable || !Header || !blimit)return(0); + if(IS_MEM_UNSAFE(contents, 4, blimit))return(0); memcpy(&Key, contents + offsetof(U_WMRPLACEABLE,Key), 4); if(Key == 0x9AC6CDD7){ size += U_SIZE_WMRPLACEABLE; - if(contents + size >= blimit)return(0); + if(IS_MEM_UNSAFE(contents, size, blimit))return(0); memcpy(Placeable, contents, U_SIZE_WMRPLACEABLE); contents += U_SIZE_WMRPLACEABLE; } else { memset(Placeable, 0, U_SIZE_WMRPLACEABLE); } - if(contents + size + U_SIZE_WMRHEADER >= blimit)return(0); + if(IS_MEM_UNSAFE(contents, size + U_SIZE_WMRHEADER, blimit))return(0); size += 2* (*(uint16_t *)(contents + offsetof(U_WMRHEADER,Size16w))); - if(contents + size >= blimit)return(0); + if(IS_MEM_UNSAFE(contents, size, blimit))return(0); memcpy(Header, contents, U_SIZE_WMRHEADER); return(size); } @@ -5512,7 +5557,11 @@ int U_WMRPOLYGON_get( uint16_t *Length, const char **Data ){ - return U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRPOLYGON), NULL, Length, Data); + int size = U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRPOLYGON), NULL, Length, Data); + if(size){ + if(IS_MEM_UNSAFE(*Data, (*Length)*sizeof(U_POINT16), contents+size))return(0); + } + return size; } /** @@ -5527,7 +5576,11 @@ int U_WMRPOLYLINE_get( uint16_t *Length, const char **Data ){ - return U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRPOLYLINE), NULL, Length, Data); + int size = U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRPOLYGON), NULL, Length, Data); + if(size){ + if(IS_MEM_UNSAFE(*Data, (*Length)*sizeof(U_POINT16), contents+size))return(0); + } + return size; } /** @@ -5550,7 +5603,11 @@ int U_WMRESCAPE_get( uint16_t *Length, const char **Data ){ - return U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRESCAPE), Escape, Length, Data); + int size = U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRESCAPE), Escape, Length, Data); + if(size){ + if(IS_MEM_UNSAFE(*Data, *Length, contents+size))return(0); + } + return size; } /** @@ -5787,6 +5844,7 @@ int U_WMRSETDIBTODEV_get( Dst->y = *(int16_t *)( contents + offsetof(U_WMRSETDIBTODEV, yDst )); Dst->x = *(int16_t *)( contents + offsetof(U_WMRSETDIBTODEV, xDst )); *dib = ( contents + offsetof(U_WMRSETDIBTODEV, dib )); + if(!packed_DIB_safe(*dib, *dib+size))return(0); return(size); } @@ -5948,6 +6006,7 @@ int U_WMRDIBBITBLT_get( Dst->y = *(int16_t *)( contents + offsetof(U_WMRDIBBITBLT_PX, yDst )); Dst->x = *(int16_t *)( contents + offsetof(U_WMRDIBBITBLT_PX, xDst )); *dib = ( contents + offsetof(U_WMRDIBBITBLT_PX, dib )); + if(!packed_DIB_safe(*dib, *dib+size))return(0); } return(size); } @@ -5999,6 +6058,7 @@ int U_WMRDIBSTRETCHBLT_get( cDst->y = *(int16_t *)( contents + offsetof(U_WMRDIBSTRETCHBLT_PX, hDst )); cDst->x = *(int16_t *)( contents + offsetof(U_WMRDIBSTRETCHBLT_PX, wDst )); *dib = ( contents + offsetof(U_WMRDIBSTRETCHBLT_PX, dib )); + if(!packed_DIB_safe(*dib, *dib+size))return(0); } return(size); } @@ -6040,11 +6100,13 @@ int U_WMRDIBCREATEPATTERNBRUSH_get( if(TmpBm16.Width <= 0 || TmpBm16.Height <= 0 || TmpBm16.Planes != 1 || TmpBm16.BitsPixel == 0){ *Bm16 = NULL; *dib = (contents + offsetof(U_WMRDIBCREATEPATTERNBRUSH, Src)); + if(!packed_DIB_safe(*dib, *dib+size))return(0); } } else { /* from DIB */ *Bm16 = NULL; *dib = (contents + offsetof(U_WMRDIBCREATEPATTERNBRUSH, Src)); + if(!packed_DIB_safe(*dib, *dib+size))return(0); } return(size); } @@ -6085,6 +6147,7 @@ int U_WMRSTRETCHDIB_get( Dst->y = *(int16_t *)( contents + offsetof(U_WMRSTRETCHDIB, yDst )); Dst->x = *(int16_t *)( contents + offsetof(U_WMRSTRETCHDIB, xDst )); *dib = ( contents + offsetof(U_WMRSTRETCHDIB, dib )); + if(!packed_DIB_safe(*dib, *dib+size))return(0); return(size); } @@ -6914,7 +6977,12 @@ int U_WMRCREATEFONTINDIRECT_get( const char *contents, const char **font ){ - return U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRCREATEFONTINDIRECT), NULL, NULL, font); + int size = U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRCREATEFONTINDIRECT), NULL, NULL, font); + if(size){ + if(IS_MEM_UNSAFE(*font, U_SIZE_FONT_CORE, contents+size))return(0); + if(contents + size - *font > U_SIZE_FONT_CORE + 32)return(0); // font name must fit in a 32 bit field + } + return size; } /** @@ -6927,6 +6995,7 @@ int U_WMRCREATEBRUSHINDIRECT_get( const char *contents, const char **brush ){ + // U_SIZE_WMRCREATEBRUSHINDIRECT is everything, no variable part, so the test below is sufficient return U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRCREATEBRUSHINDIRECT), NULL, NULL, brush); } @@ -6947,16 +7016,19 @@ int U_WMRCREATEBITMAP_get(void){ \return length of the U_WMRCREATEREGION record in bytes, or 0 on error \param contents record to extract data from \param Region pointer to U_REGION structure in memory. Pointer may not be aligned properly for structure. + + Caller must check at the returned Region does not extend outside of the record! */ int U_WMRCREATEREGION_get( const char *contents, const char **Region ){ - return U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRCREATEREGION), NULL, NULL, Region); + return U_WMRCORE_2U16_N16_get(contents, (U_SIZE_WMRCREATEREGION), NULL, NULL, Region); } + #ifdef __cplusplus } #endif diff --git a/src/libuemf/uwmf.h b/src/libuemf/uwmf.h index 54f7f36fe..2237d2221 100644 --- a/src/libuemf/uwmf.h +++ b/src/libuemf/uwmf.h @@ -36,8 +36,8 @@ /* File: uwmf.h -Version: 0.0.10 -Date: 24-MAR-2014 +Version: 0.0.11 +Date: 23-APR-2014 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu Copyright: 2014 David Mathog and California Institute of Technology (Caltech) @@ -728,6 +728,7 @@ enum U_WMR_TYPES{ #define U_SIZE_WMRCREATEFONTINDIRECT 26 /**< X 28 */ #define U_SIZE_WMRCREATEBRUSHINDIRECT 14 /**< X 16 */ #define U_SIZE_WMRCREATEREGION 26 /**< X 28 */ +#define U_SIZE_WMRCREATEREGION_CORE 24 /**< X 28 Like U_SIZE_WMRCREATEREGION minus the variable part */ /** @} */ diff --git a/src/libuemf/uwmf_print.c b/src/libuemf/uwmf_print.c index 0e089a5cd..dd460b2b0 100644 --- a/src/libuemf/uwmf_print.c +++ b/src/libuemf/uwmf_print.c @@ -319,7 +319,7 @@ void scan_print( \param dh void pointer to DIB header A DIB header in an WMF may be either a BitmapCoreHeader or BitmapInfoHeader. */ -void dibheader_print(const void *dh){ +void dibheader_print(const char *dh, const char *blimit){ uint32_t Size; memcpy(&Size, dh, 4); /* may not be aligned */ if(Size == 0xC ){ @@ -330,7 +330,7 @@ void dibheader_print(const void *dh){ } else { printf(" (BitmapInfoHeader) "); - bitmapinfo_print(dh); /* may not be aligned, called routine must handle it */ + bitmapinfo_print(dh, blimit); /* may not be aligned, called routine must handle it */ } } @@ -922,7 +922,7 @@ void U_WMRSETDIBTODEV_print(const char *contents){ printf(" Src X,Y:{%d,%d}\n", Src.x, Src.y ); printf(" W,H:%d,%d\n", cwh.x, cwh.y ); printf(" Dst X,Y:{%d,%d}\n", Dst.x, Dst.y ); - printf(" DIB:"); dibheader_print(dib); printf("\n"); + printf(" DIB:"); dibheader_print(dib, dib+size); printf("\n"); } } @@ -993,7 +993,7 @@ void U_WMRDIBBITBLT_print(const char *contents){ printf(" Src X,Y:{%d,%d}\n", Src.x, Src.x ); printf(" W,H:%d,%d\n", cwh.x, cwh.y ); printf(" Dst X,Y:{%d,%d}\n", Dst.x, Dst.y ); - if(dib){ printf(" DIB:"); dibheader_print(dib); printf("\n"); } + if(dib){ printf(" DIB:"); dibheader_print(dib, dib+size); printf("\n"); } else { printf(" DIB: none\n"); } } } @@ -1009,7 +1009,7 @@ void U_WMRDIBSTRETCHBLT_print(const char *contents){ printf(" Src X,Y:{%d,%d}\n", Src.x, Src.x ); printf(" Dst W,H:%d,%d\n", cDst.x, cDst.y ); printf(" Dst X,Y:{%d,%d}\n", Dst.x, Dst.y ); - if(dib){ printf(" DIB:"); dibheader_print(dib); printf("\n"); } + if(dib){ printf(" DIB:"); dibheader_print(dib, dib+size); printf("\n"); } else { printf(" DIB: none\n"); } } } @@ -1028,7 +1028,7 @@ void U_WMRDIBCREATEPATTERNBRUSH_print(const char *contents){ printf(" Src:Bitmap16:"); bitmap16_print(Bm16); printf("\n"); } else { /* from DIB */ - printf(" Src:DIB:"); dibheader_print(dib); printf("\n"); + printf(" Src:DIB:"); dibheader_print(dib, dib+size); printf("\n"); } } } @@ -1046,7 +1046,7 @@ void U_WMRSTRETCHDIB_print(const char *contents){ printf(" Src X,Y:{%d,%d}\n", Src.x, Src.x ); printf(" Dst W,H:%d,%d\n", cDst.x, cDst.y ); printf(" Dst X,Y:{%d,%d}\n", Dst.x, Dst.y ); - if(dib){ printf(" DIB:"); dibheader_print(dib); printf("\n"); } + if(dib){ printf(" DIB:"); dibheader_print(dib, dib+size); printf("\n"); } else { printf(" DIB: none\n"); } } } diff --git a/src/libuemf/uwmf_print.h b/src/libuemf/uwmf_print.h index 8daee0feb..54dfe9c9c 100644 --- a/src/libuemf/uwmf_print.h +++ b/src/libuemf/uwmf_print.h @@ -37,7 +37,7 @@ void bitmapcoreheader_print(U_BITMAPCOREHEADER ch); void logbrushw_print(U_WLOGBRUSH lb); void polypolygon_print(uint16_t nPolys, const uint16_t *aPolyCounts, const char *Points); void scan_print(U_SCAN sc); -void dibheader_print(const void *dh); +void dibheader_print(const char *dh, const char *blimit); /* prototypes for WMF records */ int wmfheader_print(const char *contents, const char *blimit); -- cgit v1.2.3 From 9b9f0427b04c7e84f7c0baad54ce3005ad08ac65 Mon Sep 17 00:00:00 2001 From: mathog <> Date: Mon, 27 Apr 2015 12:30:27 -0700 Subject: add two files omitted in patch at revision 14062 (bzr r14063) --- src/libuemf/uemf_safe.c | 1202 +++++++++++++++++++++++++++++++++++++++++++++++ src/libuemf/uemf_safe.h | 32 ++ 2 files changed, 1234 insertions(+) create mode 100644 src/libuemf/uemf_safe.c create mode 100644 src/libuemf/uemf_safe.h (limited to 'src') diff --git a/src/libuemf/uemf_safe.c b/src/libuemf/uemf_safe.c new file mode 100644 index 000000000..36284d60e --- /dev/null +++ b/src/libuemf/uemf_safe.c @@ -0,0 +1,1202 @@ +/** + @file uemf_safe.c + + @brief Functions for checking EMF records for memory issues. + + EMF records come in a variety of sizes, and some types have variable sizes. + These functions check the record types and report if there are any issues + that could cause a memory access problem. All counts and offsets are examined + and the data structure checked so that no referenced byte is outside of the + declared size of the record. + + Many variables are initialized to zero even though they will always be set because + some versions of gcc give spurious "may be used uninitialized" warnings otherwise. +*/ + +/* +File: uemf_safe.c +Version: 0.0.4 +Date: 23-APR-2015 +Author: David Mathog, Biology Division, Caltech +email: mathog@caltech.edu +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include /* for offsetof() macro */ +#include "uemf.h" +#include "uemf_endian.h" // for u_emf_record_sizeok + +// hide almost everuything in here from Doxygen +//! \cond + +/** + \brief Test a U_EXTLOGPEN object. + \param elp PU_EXTLOGPEN object + \param blimit one byte past the end of the record +*/ +int extlogpen_safe( + PU_EXTLOGPEN elp, + const char *blimit + ){ + int count=elp->elpNumEntries; + if(IS_MEM_UNSAFE(&(elp->elpStyleEntry), count*4, blimit))return(0); + return(1); +} + +/** + \brief Test a U_EMRTEXT record + \param pemt Pointer to a U_EMRTEXT record + \param record Pointer to the start of the record which contains this U_EMRTEXT + \param blimit one byte past the end of the record. +*/ +int emrtext_safe( + PU_EMRTEXT pemt, + const char *record, + const char *blimit + ){ + int off; + uint32_t count = pemt->nChars; + uint32_t fOptions = pemt->fOptions; + uint32_t offDx = 0; + off = sizeof(U_EMRTEXT); + if(!(fOptions & U_ETO_NO_RECT)){ + if(IS_MEM_UNSAFE(pemt, sizeof(U_RECTL), blimit))return(0); + off+=sizeof(U_RECTL); + } + offDx = *(uint32_t *)((char *)pemt +off); + if(IS_MEM_UNSAFE(pemt, off + 4, blimit))return(0); + if(IS_MEM_UNSAFE(record, offDx + count*4, blimit))return(0); + return(1); +} + +/** + \return 1 on success, 0 on failure + \brief Test a U_RGNDATA object. + \param rd pointer to a U_RGNDATA object. + \param cbRgnData size of the U_RGNDATA object. +*/ +int rgndata_safe( + PU_RGNDATA rd, + int cbRgnData + ){ + int count = rd->rdh.nCount; + if(4*count + (int)sizeof(U_RGNDATAHEADER) > cbRgnData)return(0); + return(1); +} + + +/** + \return 1 on success, 0 on failure + \brief Test a U_BITMAPINFO object. + \param Bmi pointer to a U_BITMAPINFO object. + \param blimit one byte past the end of the record. +*/ +int bitmapinfo_safe( + const char *Bmi, + const char *blimit + ){ + int ClrUsed; + if(IS_MEM_UNSAFE(Bmi, offsetof(U_BITMAPINFO,bmiHeader) + sizeof(U_BITMAPINFOHEADER), blimit))return(0); + ClrUsed = get_real_color_count(Bmi + offsetof(U_BITMAPINFO,bmiHeader)); + if(ClrUsed && IS_MEM_UNSAFE(Bmi, offsetof(U_BITMAPINFO,bmiColors) + ClrUsed*sizeof(U_RGBQUAD), blimit))return(0); + return(1); +} + +/** + \brief Check that the bitmap in the specified DIB is compatible with the record size + + \return 1 on success, 0 on failure + \param record EMF record that contains a DIB pixel array + \param iUsage DIBcolors Enumeration + \param offBmi offset from the start of the record to the start of the bitmapinfo structure + \param cbBmi declared space for the bitmapinfo structure in the record + \param offBits offset from the start of the record to the start of the bitmap + \param cbBits declared space for the bitmap in the record (amount used may be less than this) + \param blimit one byte past the end of the record. + + This method can only test DIBs that hold Microsoft's various bitmap types. PNG or JPG is just a bag + of bytes, and there is no possible way to derive from the known width and height how big it should be. +*/ +int DIB_safe( + const char *record, + uint32_t iUsage, + uint32_t offBmi, + uint32_t cbBmi, + uint32_t offBits, + uint32_t cbBits, + const char *blimit + ){ + int dibparams = U_BI_UNKNOWN; // type of image not yet determined + const char *px = NULL; // DIB pixels + const U_RGBQUAD *ct = NULL; // DIB color table + int bs; + int usedbytes; + + if(!cbBmi)return(1); // No DIB in a record where it is optional + if(IS_MEM_UNSAFE(record, offBmi + cbBmi, blimit))return(0); + if(!bitmapinfo_safe(record + offBmi, blimit))return(0); // checks the number of colors + if(cbBits && IS_MEM_UNSAFE(record, offBits + cbBits, blimit))return(0); + if(iUsage == U_DIB_RGB_COLORS){ + uint32_t width, height, colortype, numCt, invert; // these values will be set in get_DIB_params + // next call returns pointers and values, but allocates no memory + dibparams = get_DIB_params(record, offBits, offBmi, &px, (const U_RGBQUAD **) &ct, + &numCt, &width, &height, &colortype, &invert); + + // sanity checking + if(numCt && colortype >= U_BCBM_COLOR16)return(0); //color tables not used above 16 bit pixels + if(!numCt && colortype < U_BCBM_COLOR16)return(0); //color tables mandatory for < 16 bit + + if(dibparams ==U_BI_RGB){ + // this is the only DIB type where we can calculate how big it should be when stored in the EMF file + bs = colortype/8; + if(bs<1){ + usedbytes = (width*colortype + 7)/8; // width of line in fully and partially occupied bytes + } + else { + usedbytes = width*bs; + } + if(IS_MEM_UNSAFE(record+offBits, usedbytes, blimit))return(0); + } + } + return(1); +} + + +/* ********************************************************************************************** +These functions contain shared code used by various U_EMR*_safe functions. These should NEVER be called +by end user code and to further that end prototypes are NOT provided and they are hidden from Doxygen. + + + These all have this form: + + void core1_safe(const char *record){ + + but some do not actually use torev. + + + +*********************************************************************************************** */ + +// all core*_safe call this, U_EMRSETMARGN_safe and some others all it directly +// numbered as core5 to be consistent with uemf.c, but must appear before the others as there is no prototype +// sizeof(U_ENHMETARECORD) bytes in the record +int core5_safe(const char *record, int minSize){ + PU_EMR pEmr = (PU_EMR)(record); + if((int) pEmr->nSize < minSize)return(0); + return(1); +} + +// Functions with the same form starting with U_EMRPOLYBEZIER_safe +int core1_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRPOLYLINETO))return(0); + PU_EMRPOLYLINETO pEmr = (PU_EMRPOLYLINETO) (record); + int count=pEmr->cptl; + const char *blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(pEmr->aptl, count*sizeof(U_POINTL), blimit))return(0); + return(1); +} + +// Functions with the same form starting with U_EMRPOLYPOLYLINE_safe +int core2_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRPOLYPOLYLINE))return(0); + PU_EMRPOLYPOLYLINE pEmr = (PU_EMRPOLYPOLYLINE) (record); + int count = pEmr->cptl; + int nPolys = pEmr->nPolys; + const char * blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(pEmr->aPolyCounts, nPolys*4, blimit))return(0); + record += sizeof(U_EMRPOLYPOLYLINE) - 4 + sizeof(uint32_t)* nPolys; + if(IS_MEM_UNSAFE(record, count*sizeof(U_POINTL), blimit))return(0); + return(1); +} + + +// Functions with the same form starting with U_EMRSETMAPMODE_safe +int core3_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRSETMAPMODE))return(0); + return(1); +} + +// Functions taking a single U_RECT or U_RECTL, starting with U_EMRELLIPSE_safe, also U_EMRFILLPATH_safe, +int core4_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRELLIPSE))return(0); + return(1); +} + +// Functions with the same form starting with U_EMRPOLYBEZIER16_safe +int core6_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRPOLYBEZIER16))return(0); + PU_EMRPOLYBEZIER16 pEmr = (PU_EMRPOLYBEZIER16) (record); + int count=pEmr->cpts; + const char *blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(pEmr->apts, count*sizeof(U_POINT16), blimit))return(0); + return(1); +} + + +// Records with the same form starting with U_EMRSETWINDOWEXTEX_safe, that is, all with two uint32_t values after the emr +int core7_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRSETWINDOWEXTEX))return(0); + return(1); +} + +// For U_EMREXTTEXTOUTA and U_EMREXTTEXTOUTW, type=0 for the first one +int core8_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMREXTTEXTOUTA))return(0); + PU_EMREXTTEXTOUTA pEmr = (PU_EMREXTTEXTOUTA) (record); + const char *blimit = record + pEmr->emr.nSize; + if(!emrtext_safe(&(pEmr->emrtext),record,blimit))return(0); + return(1); +} + +// Functions that take a rect and a pair of points, starting with U_EMRARC_safe +int core9_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRARC))return(0); + return(1); +} + +// Functions with the same form starting with U_EMRPOLYPOLYLINE16_safe +int core10_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRPOLYPOLYLINE16))return(0); + PU_EMRPOLYPOLYLINE16 pEmr = (PU_EMRPOLYPOLYLINE16) (record); + int count = pEmr->cpts; + int nPolys = pEmr->nPolys; + const char *blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(pEmr->aPolyCounts, nPolys*4, blimit))return(0); + record += sizeof(U_EMRPOLYPOLYLINE16) - 4 + sizeof(uint32_t)* nPolys; + if(IS_MEM_UNSAFE(record, count*sizeof(U_POINT16), blimit))return(0); + return(1); +} + +// Functions with the same form starting with U_EMRINVERTRGN_safe and U_EMRPAINTRGN_safe, +int core11_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRINVERTRGN))return(0); + PU_EMRINVERTRGN pEmr = (PU_EMRINVERTRGN)(record); + int cbRgnData = pEmr->cbRgnData; + const char *blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(pEmr->RgnData, cbRgnData, blimit))return(0); + return(rgndata_safe(pEmr->RgnData, cbRgnData)); +} + + +// common code for U_EMRCREATEMONOBRUSH_safe and U_EMRCREATEDIBPATTERNBRUSHPT_safe, +int core12_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRCREATEMONOBRUSH))return(0); + PU_EMRCREATEMONOBRUSH pEmr = (PU_EMRCREATEMONOBRUSH) (record); + const char *blimit = record + pEmr->emr.nSize; + U_OFFBMI offBmi = pEmr->offBmi; + U_CBBMI cbBmi = pEmr->cbBmi; + U_OFFBITS offBits = pEmr->offBits; + U_CBBITS cbBits = pEmr->cbBits; + uint32_t iUsage = pEmr->iUsage; + return(DIB_safe(record, iUsage, offBmi, cbBmi, offBits, cbBits, blimit)); +} + +// common code for U_EMRALPHABLEND_safe and U_EMRTRANSPARENTBLT_safe, +int core13_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRALPHABLEND))return(0); + PU_EMRALPHABLEND pEmr = (PU_EMRALPHABLEND) (record); + const char *blimit = record + pEmr->emr.nSize; + U_OFFBMISRC offBmiSrc = pEmr->offBmiSrc; + U_CBBMISRC cbBmiSrc = pEmr->cbBmiSrc; + U_OFFBITSSRC offBitsSrc = pEmr->offBitsSrc; + U_CBBITS cbBitsSrc = pEmr->cbBitsSrc; + uint32_t iUsageSrc = pEmr->iUsageSrc; + return(DIB_safe(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit)); +} + +/* ********************************************************************************************** +These are the core EMR_safe functions, each converts a particular type of record. +All operate in place on the chunk of memory holding that record. +Some of these have offsets or counts which, if corrupt or evil would result in access outside + the record. These cases return a status value of 0 if that happens, 1 on success. Other + records which do not have these issues do not return a status value. +They are listed in order by the corresponding U_EMR_* index number. +*********************************************************************************************** */ + +/** + All of the record level (hidden) functions have this form: + \brief Convert a pointer to a U_EMR_whatever record which has not been implemented. + \param record pointer to a buffer holding the EMR record + \param torev 1 for native to reversed, 0 for reversed to native +*/ +int U_EMRNOTIMPLEMENTED_safe(const char *record){ + fprintf(stderr,"EMF WARNING: could not safety check record because that type has not been implemented!\n"); + return(core5_safe(record, sizeof(U_EMR))); +} + +// U_EMRHEADER 1 +int U_EMRHEADER_safe(const char *record){ + // use _MIN form so that it accepts very old EMF files + return(core5_safe(record, U_SIZE_EMRHEADER_MIN)); +} + +// U_EMRPOLYBEZIER 2 +int U_EMRPOLYBEZIER_safe(const char *record){ + return(core1_safe(record)); +} + +// U_EMRPOLYGON 3 +int U_EMRPOLYGON_safe(const char *record){ + return(core1_safe(record)); +} + +// U_EMRPOLYLINE 4 +int U_EMRPOLYLINE_safe(const char *record){ + return(core1_safe(record)); +} + +// U_EMRPOLYBEZIERTO 5 +int U_EMRPOLYBEZIERTO_safe(const char *record){ + return(core1_safe(record)); +} + +// U_EMRPOLYLINETO 6 +int U_EMRPOLYLINETO_safe(const char *record){ + return(core1_safe(record)); +} + +// U_EMRPOLYPOLYLINE 7 +int U_EMRPOLYPOLYLINE_safe(const char *record){ + return(core2_safe(record)); +} + +// U_EMRPOLYPOLYGON 8 +int U_EMRPOLYPOLYGON_safe(const char *record){ + return(core2_safe(record)); +} + +// U_EMRSETWINDOWEXTEX 9 +int U_EMRSETWINDOWEXTEX_safe(const char *record){ + return(core7_safe(record)); +} + +// U_EMRSETWINDOWORGEX 10 +int U_EMRSETWINDOWORGEX_safe(const char *record){ + return(core7_safe(record)); +} + +// U_EMRSETVIEWPORTEXTEX 11 +int U_EMRSETVIEWPORTEXTEX_safe(const char *record){ + return(core7_safe(record)); +} + +// U_EMRSETVIEWPORTORGEX 12 +int U_EMRSETVIEWPORTORGEX_safe(const char *record){ + return(core7_safe(record)); +} + +// U_EMRSETBRUSHORGEX 13 +int U_EMRSETBRUSHORGEX_safe(const char *record){ + return(core7_safe(record)); +} + +// U_EMREOF 14 +int U_EMREOF_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMREOF))return(0); + PU_EMREOF pEmr = (PU_EMREOF)(record); + const char *blimit = record + pEmr->emr.nSize; + int cbPalEntries=pEmr->cbPalEntries; + if(cbPalEntries){ + if(IS_MEM_UNSAFE(record, pEmr->offPalEntries + 2*2, blimit))return(0);// 2 16 bit values in U_LOGPALLETE + } + int off = sizeof(U_EMREOF) + 4 * cbPalEntries; + if(IS_MEM_UNSAFE(record, off + 4, blimit))return(0); + return(1); +} + + +// U_EMRSETPIXELV 15 +int U_EMRSETPIXELV_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRSETPIXELV)); + +} + + +// U_EMRSETMAPPERFLAGS 16 +int U_EMRSETMAPPERFLAGS_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRSETMAPPERFLAGS)); +} + + +// U_EMRSETMAPMODE 17 +int U_EMRSETMAPMODE_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRSETBKMODE 18 +int U_EMRSETBKMODE_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRSETPOLYFILLMODE 19 +int U_EMRSETPOLYFILLMODE_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRSETROP2 20 +int U_EMRSETROP2_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRSETSTRETCHBLTMODE 21 +int U_EMRSETSTRETCHBLTMODE_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRSETTEXTALIGN 22 +int U_EMRSETTEXTALIGN_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRSETCOLORADJUSTMENT 23 +int U_EMRSETCOLORADJUSTMENT_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRSETCOLORADJUSTMENT)); +} + +// U_EMRSETTEXTCOLOR 24 +int U_EMRSETTEXTCOLOR_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRSETTEXTCOLOR)); +} + +// U_EMRSETBKCOLOR 25 +int U_EMRSETBKCOLOR_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRSETBKCOLOR)); +} + +// U_EMROFFSETCLIPRGN 26 +int U_EMROFFSETCLIPRGN_safe(const char *record){ + return(core7_safe(record)); +} + +// U_EMRMOVETOEX 27 +int U_EMRMOVETOEX_safe(const char *record){ + return(core7_safe(record)); +} + +// U_EMRSETMETARGN 28 +int U_EMRSETMETARGN_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRSETMETARGN)); +} + +// U_EMREXCLUDECLIPRECT 29 +int U_EMREXCLUDECLIPRECT_safe(const char *record){ + return(core4_safe(record)); +} + +// U_EMRINTERSECTCLIPRECT 30 +int U_EMRINTERSECTCLIPRECT_safe(const char *record){ + return(core4_safe(record)); +} + +// U_EMRSCALEVIEWPORTEXTEX 31 +int U_EMRSCALEVIEWPORTEXTEX_safe(const char *record){ + return(core4_safe(record)); +} + +// U_EMRSCALEWINDOWEXTEX 32 +int U_EMRSCALEWINDOWEXTEX_safe(const char *record){ + return(core4_safe(record)); +} + +// U_EMRSAVEDC 33 +int U_EMRSAVEDC_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRSAVEDC)); +} + +// U_EMRRESTOREDC 34 +int U_EMRRESTOREDC_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRSETWORLDTRANSFORM 35 +int U_EMRSETWORLDTRANSFORM_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRSETWORLDTRANSFORM)); +} + +// U_EMRMODIFYWORLDTRANSFORM 36 +int U_EMRMODIFYWORLDTRANSFORM_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRMODIFYWORLDTRANSFORM)); +} + +// U_EMRSELECTOBJECT 37 +int U_EMRSELECTOBJECT_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRSELECTOBJECT)); +} + +// U_EMRCREATEPEN 38 +int U_EMRCREATEPEN_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRCREATEPEN)); +} + +// U_EMRCREATEBRUSHINDIRECT 39 +int U_EMRCREATEBRUSHINDIRECT_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRCREATEBRUSHINDIRECT)); +} + +// U_EMRDELETEOBJECT 40 +int U_EMRDELETEOBJECT_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRDELETEOBJECT)); + +} + +// U_EMRANGLEARC 41 +int U_EMRANGLEARC_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRANGLEARC)); +} + +// U_EMRELLIPSE 42 +int U_EMRELLIPSE_safe(const char *record){ + return(core4_safe(record)); +} + +// U_EMRRECTANGLE 43 +int U_EMRRECTANGLE_safe(const char *record){ + return(core4_safe(record)); +} + +// U_EMRROUNDRECT 44 +int U_EMRROUNDRECT_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRROUNDRECT)); +} + +// U_EMRARC 45 +int U_EMRARC_safe(const char *record){ + return(core9_safe(record)); +} + +// U_EMRCHORD 46 +int U_EMRCHORD_safe(const char *record){ + return(core9_safe(record)); +} + +// U_EMRPIE 47 +int U_EMRPIE_safe(const char *record){ + return(core9_safe(record)); +} + +// U_EMRSELECTPALETTE 48 +int U_EMRSELECTPALETTE_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRCREATEPALETTE 49 +int U_EMRCREATEPALETTE_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRCREATEPALETTE)); +} + +// U_EMRSETPALETTEENTRIES 50 +int U_EMRSETPALETTEENTRIES_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRSETPALETTEENTRIES)); +} + +// U_EMRRESIZEPALETTE 51 +int U_EMRRESIZEPALETTE_safe(const char *record){ + return(core7_safe(record)); +} + +// U_EMRREALIZEPALETTE 52 +int U_EMRREALIZEPALETTE_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRREALIZEPALETTE)); +} + +// U_EMREXTFLOODFILL 53 +int U_EMREXTFLOODFILL_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMREXTFLOODFILL)); +} + +// U_EMRLINETO 54 +int U_EMRLINETO_safe(const char *record){ + return(core7_safe(record)); +} + +// U_EMRARCTO 55 +int U_EMRARCTO_safe(const char *record){ + return(core9_safe(record)); +} + +// U_EMRPOLYDRAW 56 +int U_EMRPOLYDRAW_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRPOLYDRAW))return(0); + PU_EMRPOLYDRAW pEmr = (PU_EMRPOLYDRAW)(record); + int count = pEmr->cptl; + const char *blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(pEmr->aptl, count*sizeof(U_POINTL), blimit))return(0); + return(1); +} + +// U_EMRSETARCDIRECTION 57 +int U_EMRSETARCDIRECTION_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRSETMITERLIMIT 58 +int U_EMRSETMITERLIMIT_safe(const char *record){ + return(core3_safe(record)); +} + + +// U_EMRBEGINPATH 59 +int U_EMRBEGINPATH_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRBEGINPATH)); +} + +// U_EMRENDPATH 60 +int U_EMRENDPATH_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRENDPATH)); +} + +// U_EMRCLOSEFIGURE 61 +int U_EMRCLOSEFIGURE_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRCLOSEFIGURE)); +} + +// U_EMRFILLPATH 62 +int U_EMRFILLPATH_safe(const char *record){ + return(core4_safe(record)); +} + +// U_EMRSTROKEANDFILLPATH 63 +int U_EMRSTROKEANDFILLPATH_safe(const char *record){ + return(core4_safe(record)); +} + +// U_EMRSTROKEPATH 64 +int U_EMRSTROKEPATH_safe(const char *record){ + return(core4_safe(record)); +} + +// U_EMRFLATTENPATH 65 +int U_EMRFLATTENPATH_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRFLATTENPATH)); +} + +// U_EMRWIDENPATH 66 +int U_EMRWIDENPATH_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRWIDENPATH)); +} + +// U_EMRSELECTCLIPPATH 67 +int U_EMRSELECTCLIPPATH_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRABORTPATH 68 +int U_EMRABORTPATH_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRABORTPATH)); +} + +// U_EMRUNDEF69 69 +#define U_EMRUNDEF69_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. + +// U_EMRCOMMENT 70 Comment (any binary data, interpretation is program specific) +int U_EMRCOMMENT_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRCOMMENT))return(0); + PU_EMRCOMMENT pEmr = (PU_EMRCOMMENT)(record); + int cbData = pEmr->cbData; + const char *blimit =record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(record, cbData + sizeof(U_SIZE_EMRCOMMENT), blimit))return(0); + return(1); +} + +// U_EMRFILLRGN 71 +int U_EMRFILLRGN_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRFILLRGN))return(0); + PU_EMRFILLRGN pEmr = (PU_EMRFILLRGN)(record); + int cbRgnData = pEmr->cbRgnData; + const char *blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(pEmr->RgnData, cbRgnData, blimit))return(0); + return(rgndata_safe(pEmr->RgnData, cbRgnData)); +} + +// U_EMRFRAMERGN 72 +int U_EMRFRAMERGN_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRFRAMERGN))return(0); + PU_EMRFRAMERGN pEmr = (PU_EMRFRAMERGN)(record); + int cbRgnData = pEmr->cbRgnData; + const char *blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(pEmr->RgnData, cbRgnData, blimit))return(0); + return(rgndata_safe(pEmr->RgnData, cbRgnData)); +} + +// U_EMRINVERTRGN 73 +int U_EMRINVERTRGN_safe(const char *record){ + return(core11_safe(record)); +} + +// U_EMRPAINTRGN 74 +int U_EMRPAINTRGN_safe(const char *record){ + return(core11_safe(record)); +} + +// U_EMREXTSELECTCLIPRGN 75 +int U_EMREXTSELECTCLIPRGN_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMREXTSELECTCLIPRGN))return(0); + PU_EMREXTSELECTCLIPRGN pEmr = (PU_EMREXTSELECTCLIPRGN)(record); + int cbRgnData = pEmr->cbRgnData; + const char *blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(pEmr->RgnData, cbRgnData, blimit))return(0); + return(rgndata_safe(pEmr->RgnData, cbRgnData)); +} + +// U_EMRBITBLT 76 +int U_EMRBITBLT_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRBITBLT))return(0); + PU_EMRBITBLT pEmr = (PU_EMRBITBLT) (record); + const char *blimit = record + pEmr->emr.nSize; + U_OFFBMISRC offBmiSrc = pEmr->offBmiSrc; + U_CBBMISRC cbBmiSrc = pEmr->cbBmiSrc; + U_OFFBITSSRC offBitsSrc = pEmr->offBitsSrc; + U_CBBITS cbBitsSrc = pEmr->cbBitsSrc; + uint32_t iUsageSrc = pEmr->iUsageSrc; + return(DIB_safe(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit)); +} + +// U_EMRSTRETCHBLT 77 +int U_EMRSTRETCHBLT_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRSTRETCHBLT))return(0); + PU_EMRBITBLT pEmr = (PU_EMRBITBLT) (record); + const char *blimit = record + pEmr->emr.nSize; + U_OFFBMISRC offBmiSrc = pEmr->offBmiSrc; + U_CBBMISRC cbBmiSrc = pEmr->cbBmiSrc; + U_OFFBITSSRC offBitsSrc = pEmr->offBitsSrc; + U_CBBITS cbBitsSrc = pEmr->cbBitsSrc; + uint32_t iUsageSrc = pEmr->iUsageSrc; + return(DIB_safe(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit)); +} + +// U_EMRMASKBLT 78 +int U_EMRMASKBLT_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRMASKBLT))return(0); + PU_EMRMASKBLT pEmr = (PU_EMRMASKBLT) (record); + const char *blimit = record + pEmr->emr.nSize; + U_OFFBMISRC offBmiSrc = pEmr->offBmiSrc; + U_CBBMISRC cbBmiSrc = pEmr->cbBmiSrc; + U_OFFBMIMSK offBmiMask = pEmr->offBmiMask; + U_CBBMIMSK cbBmiMask = pEmr->cbBmiMask; + U_OFFBITSSRC offBitsSrc = pEmr->offBitsSrc; + U_CBBITSSRC cbBitsSrc = pEmr->cbBitsSrc; + U_OFFBITSMSK offBitsMask = pEmr->offBitsMask; + U_CBBITSMSK cbBitsMask = pEmr->cbBitsMask; + uint32_t iUsageSrc = pEmr->iUsageSrc; + uint32_t iUsageMask = pEmr->iUsageMask; + if(!DIB_safe(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit))return(0); + return(DIB_safe(record, iUsageMask, offBmiMask, cbBmiMask, offBitsMask, cbBitsMask, blimit)); +} + +// U_EMRPLGBLT 79 +int U_EMRPLGBLT_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRPLGBLT))return(0); + PU_EMRPLGBLT pEmr = (PU_EMRPLGBLT) (record); + const char *blimit = record + pEmr->emr.nSize; + U_OFFBMISRC offBmiSrc = pEmr->offBmiSrc; + U_CBBMISRC cbBmiSrc = pEmr->cbBmiSrc; + U_OFFBMIMSK offBmiMask = pEmr->offBmiMask; + U_CBBMIMSK cbBmiMask = pEmr->cbBmiMask; + U_OFFBITSSRC offBitsSrc = pEmr->offBitsSrc; + U_CBBITSSRC cbBitsSrc = pEmr->cbBitsSrc; + U_OFFBITSMSK offBitsMask = pEmr->offBitsMask; + U_CBBITSMSK cbBitsMask = pEmr->cbBitsMask; + uint32_t iUsageSrc = pEmr->iUsageSrc; + uint32_t iUsageMask = pEmr->iUsageMask; + if(!DIB_safe(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit))return(0); + return(DIB_safe(record, iUsageMask, offBmiMask, cbBmiMask, offBitsMask, cbBitsMask, blimit)); +} + +// U_EMRSETDIBITSTODEVICE 80 +int U_EMRSETDIBITSTODEVICE_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRSETDIBITSTODEVICE))return(0); + PU_EMRSETDIBITSTODEVICE pEmr = (PU_EMRSETDIBITSTODEVICE) (record); + const char *blimit = record + pEmr->emr.nSize; + U_OFFBMISRC offBmiSrc = pEmr->offBmiSrc; + U_CBBMISRC cbBmiSrc = pEmr->cbBmiSrc; + U_OFFBITSSRC offBitsSrc = pEmr->offBitsSrc; + U_CBBITSSRC cbBitsSrc = pEmr->cbBitsSrc; + uint32_t iUsageSrc = pEmr->iUsageSrc; + return(DIB_safe(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit)); +} + +// U_EMRSTRETCHDIBITS 81 +int U_EMRSTRETCHDIBITS_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRSTRETCHDIBITS))return(0); + PU_EMRSTRETCHDIBITS pEmr = (PU_EMRSTRETCHDIBITS) (record); + const char *blimit = record + pEmr->emr.nSize; + U_OFFBMISRC offBmiSrc = pEmr->offBmiSrc; + U_CBBMISRC cbBmiSrc = pEmr->cbBmiSrc; + U_OFFBITSSRC offBitsSrc = pEmr->offBitsSrc; + U_CBBITSSRC cbBitsSrc = pEmr->cbBitsSrc; + uint32_t iUsageSrc = pEmr->iUsageSrc; + return(DIB_safe(record, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, blimit)); +} + +// U_EMREXTCREATEFONTINDIRECTW 82 +int U_EMREXTCREATEFONTINDIRECTW_safe(const char *record){ + /* Panose or logfont, LogFontExDv is not supported. Test smallest to largest */ + if(core5_safe(record, U_SIZE_EMREXTCREATEFONTINDIRECTW_LOGFONT))return(1); + return(core5_safe(record, U_SIZE_EMREXTCREATEFONTINDIRECTW_LOGFONT_PANOSE)); +} + +// U_EMREXTTEXTOUTA 83 +int U_EMREXTTEXTOUTA_safe(const char *record){ + return(core8_safe(record)); +} + +// U_EMREXTTEXTOUTW 84 +int U_EMREXTTEXTOUTW_safe(const char *record){ + return(core8_safe(record)); +} + +// U_EMRPOLYBEZIER16 85 +/** + \brief Convert a pointer to a U_EMR_POLYBEZIER16 record. + \param record pointer to a buffer holding the EMR record +*/ +int U_EMRPOLYBEZIER16_safe(const char *record){ + return(core6_safe(record)); +} + +// U_EMRPOLYGON16 86 +int U_EMRPOLYGON16_safe(const char *record){ + return(core6_safe(record)); +} + +// U_EMRPOLYLINE16 87 +int U_EMRPOLYLINE16_safe(const char *record){ + return(core6_safe(record)); +} + +// U_EMRPOLYBEZIERTO16 88 +int U_EMRPOLYBEZIERTO16_safe(const char *record){ + return(core6_safe(record)); +} + +// U_EMRPOLYLINETO16 89 +/** + \brief Convert a pointer to a U_EMR_POLYLINETO16 record. + \param record pointer to a buffer holding the EMR record +*/ +int U_EMRPOLYLINETO16_safe(const char *record){ + return(core6_safe(record)); +} + +// U_EMRPOLYPOLYLINE16 90 +int U_EMRPOLYPOLYLINE16_safe(const char *record){ + return(core10_safe(record)); +} + +// U_EMRPOLYPOLYGON16 91 +int U_EMRPOLYPOLYGON16_safe(const char *record){ + return(core10_safe(record)); +} + + +// U_EMRPOLYDRAW16 92 +int U_EMRPOLYDRAW16_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRPOLYDRAW16))return(0); + PU_EMRPOLYDRAW16 pEmr = (PU_EMRPOLYDRAW16)(record); + int count = pEmr->cpts; + const char *blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(pEmr->apts, count*sizeof(U_POINT16), blimit))return(0); + return(1); +} + +// U_EMRCREATEMONOBRUSH 93 +int U_EMRCREATEMONOBRUSH_safe(const char *record){ + return(core12_safe(record)); +} + +// U_EMRCREATEDIBPATTERNBRUSHPT_safe 94 +int U_EMRCREATEDIBPATTERNBRUSHPT_safe(const char *record){ + return(core12_safe(record)); +} + + +// U_EMREXTCREATEPEN 95 +int U_EMREXTCREATEPEN_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMREXTCREATEPEN))return(0); + PU_EMREXTCREATEPEN pEmr = (PU_EMREXTCREATEPEN)(record); + const char *blimit = record + pEmr->emr.nSize; + U_OFFBMI offBmi = pEmr->offBmi; + U_CBBMI cbBmi = pEmr->cbBmi; + U_OFFBITS offBits = pEmr->offBits; + U_CBBITS cbBits = pEmr->cbBits; + if(!DIB_safe(record, U_DIB_RGB_COLORS, offBmi, cbBmi, offBits, cbBits, blimit))return(0); + return(extlogpen_safe((PU_EXTLOGPEN) &(pEmr->elp), blimit)); +} + +// U_EMRPOLYTEXTOUTA 96 NOT IMPLEMENTED, denigrated after Windows NT +#define U_EMRPOLYTEXTOUTA_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMRPOLYTEXTOUTW 97 NOT IMPLEMENTED, denigrated after Windows NT +#define U_EMRPOLYTEXTOUTW_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. + +// U_EMRSETICMMODE 98 +int U_EMRSETICMMODE_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRCREATECOLORSPACE 99 +int U_EMRCREATECOLORSPACE_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRCREATECOLORSPACE)); +} + +// U_EMRSETCOLORSPACE 100 +int U_EMRSETCOLORSPACE_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRDELETECOLORSPACE 101 +int U_EMRDELETECOLORSPACE_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRGLSRECORD 102 Not implemented +#define U_EMRGLSRECORD_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMRGLSBOUNDEDRECORD 103 Not implemented +#define U_EMRGLSBOUNDEDRECORD_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. + +// U_EMRPIXELFORMAT 104 +int U_EMRPIXELFORMAT_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRPIXELFORMAT)); +} + +// U_EMRDRAWESCAPE 105 Not implemented +#define U_EMRDRAWESCAPE_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMREXTESCAPE 106 Not implemented +#define U_EMREXTESCAPE_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMRUNDEF107 107 Not implemented +#define U_EMRUNDEF107_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. + +// U_EMRSMALLTEXTOUT 108 +int U_EMRSMALLTEXTOUT_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRSMALLTEXTOUT))return(0); + PU_EMRSMALLTEXTOUT pEmr = (PU_EMRSMALLTEXTOUT)(record); + int roff=sizeof(U_EMRSMALLTEXTOUT); // offset to the start of the variable fields + int fuOptions = pEmr->fuOptions; + int cChars = pEmr->cChars; + const char *blimit = record + pEmr->emr.nSize; + if(!(fuOptions & U_ETO_NO_RECT)){ + if(IS_MEM_UNSAFE(record, roff + sizeof(U_RECTL), blimit))return(0); + } + if(IS_MEM_UNSAFE(record, roff + sizeof(U_RECTL) + cChars, blimit))return(0); + return(1); +} + +// U_EMRFORCEUFIMAPPING 109 Not implemented +#define U_EMRFORCEUFIMAPPING_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMRNAMEDESCAPE 110 Not implemented +#define U_EMRNAMEDESCAPE_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMRCOLORCORRECTPALETTE 111 Not implemented +#define U_EMRCOLORCORRECTPALETTE_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMRSETICMPROFILEA 112 Not implemented +#define U_EMRSETICMPROFILEA_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMRSETICMPROFILEW 113 Not implemented +#define U_EMRSETICMPROFILEW_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. + +// U_EMRALPHABLEND 114 +int U_EMRALPHABLEND_safe(const char *record){ + return(core13_safe(record)); +} + +// U_EMRSETLAYOUT 115 +int U_EMRSETLAYOUT_safe(const char *record){ + return(core3_safe(record)); +} + +// U_EMRTRANSPARENTBLT 116 +int U_EMRTRANSPARENTBLT_safe(const char *record){ + return(core13_safe(record)); +} + + +// U_EMRUNDEF117 117 Not implemented +#define U_EMRUNDEF117_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMRGRADIENTFILL 118 +int U_EMRGRADIENTFILL_safe(const char *record){ + if(!core5_safe(record, U_SIZE_EMRGRADIENTFILL))return(0); + PU_EMRGRADIENTFILL pEmr = (PU_EMRGRADIENTFILL)(record); + int nTriVert = pEmr->nTriVert; + int nGradObj = pEmr->nGradObj; + int ulMode = pEmr->ulMode; + const char *blimit = record + pEmr->emr.nSize; + if(IS_MEM_UNSAFE(record, nTriVert*sizeof(U_TRIVERTEX), blimit))return(0); + record += nTriVert * sizeof(U_TRIVERTEX); + if(nGradObj){ + if( ulMode == U_GRADIENT_FILL_TRIANGLE){ + if(IS_MEM_UNSAFE(record, nGradObj*sizeof(U_GRADIENT3), blimit))return(0); + } + else if(ulMode == U_GRADIENT_FILL_RECT_H || ulMode == U_GRADIENT_FILL_RECT_V){ + if(IS_MEM_UNSAFE(record, nGradObj*sizeof(U_GRADIENT4), blimit))return(0); + } + } + return(1); +} + +// U_EMRSETLINKEDUFIS 119 Not implemented +#define U_EMRSETLINKEDUFIS_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMRSETTEXTJUSTIFICATION120 Not implemented (denigrated) +#define U_EMRSETTEXTJUSTIFICATION_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. +// U_EMRCOLORMATCHTOTARGETW 121 Not implemented +#define U_EMRCOLORMATCHTOTARGETW_safe(A) U_EMRNOTIMPLEMENTED_safe(A) //!< Not implemented. + +// U_EMRCREATECOLORSPACEW 122 +int U_EMRCREATECOLORSPACEW_safe(const char *record){ + return(core5_safe(record, U_SIZE_EMRCREATECOLORSPACEW)); +} + +//! \endcond + +/** + \brief Test an EMF record in memory from Big Endian to Little Endian. + \return 0 on failure, 1 on success + \param record pointer to the EMF record in memory + + Normally this would be called immediately after reading a record from a file + and having called U_emf_record_sizeok(). + It is NOT safe to call this routine without first calling U_emf_record_sizeok)()! + If the file has been converted from one endian to another calling this routine is + not necessary, because those routines also perform these checks. +*/ +int U_emf_record_safe(const char *record){ + int rstatus=1; + + if(!record)return(0); // programming error + + switch (U_EMRTYPE(record)) + { + case U_EMR_HEADER: rstatus=U_EMRHEADER_safe(record); break; + case U_EMR_POLYBEZIER: rstatus=U_EMRPOLYBEZIER_safe(record); break; + case U_EMR_POLYGON: rstatus=U_EMRPOLYGON_safe(record); break; + case U_EMR_POLYLINE: rstatus=U_EMRPOLYLINE_safe(record); break; + case U_EMR_POLYBEZIERTO: rstatus=U_EMRPOLYBEZIERTO_safe(record); break; + case U_EMR_POLYLINETO: rstatus=U_EMRPOLYLINETO_safe(record); break; + case U_EMR_POLYPOLYLINE: rstatus=U_EMRPOLYPOLYLINE_safe(record); break; + case U_EMR_POLYPOLYGON: rstatus=U_EMRPOLYPOLYGON_safe(record); break; + case U_EMR_SETWINDOWEXTEX: rstatus=U_EMRSETWINDOWEXTEX_safe(record); break; + case U_EMR_SETWINDOWORGEX: rstatus=U_EMRSETWINDOWORGEX_safe(record); break; + case U_EMR_SETVIEWPORTEXTEX: rstatus=U_EMRSETVIEWPORTEXTEX_safe(record); break; + case U_EMR_SETVIEWPORTORGEX: rstatus=U_EMRSETVIEWPORTORGEX_safe(record); break; + case U_EMR_SETBRUSHORGEX: rstatus=U_EMRSETBRUSHORGEX_safe(record); break; + case U_EMR_EOF: rstatus=U_EMREOF_safe(record); break; + case U_EMR_SETPIXELV: rstatus=U_EMRSETPIXELV_safe(record); break; + case U_EMR_SETMAPPERFLAGS: rstatus=U_EMRSETMAPPERFLAGS_safe(record); break; + case U_EMR_SETMAPMODE: rstatus=U_EMRSETMAPMODE_safe(record); break; + case U_EMR_SETBKMODE: rstatus=U_EMRSETBKMODE_safe(record); break; + case U_EMR_SETPOLYFILLMODE: rstatus=U_EMRSETPOLYFILLMODE_safe(record); break; + case U_EMR_SETROP2: rstatus=U_EMRSETROP2_safe(record); break; + case U_EMR_SETSTRETCHBLTMODE: rstatus=U_EMRSETSTRETCHBLTMODE_safe(record); break; + case U_EMR_SETTEXTALIGN: rstatus=U_EMRSETTEXTALIGN_safe(record); break; + case U_EMR_SETCOLORADJUSTMENT: rstatus=U_EMRSETCOLORADJUSTMENT_safe(record); break; + case U_EMR_SETTEXTCOLOR: rstatus=U_EMRSETTEXTCOLOR_safe(record); break; + case U_EMR_SETBKCOLOR: rstatus=U_EMRSETBKCOLOR_safe(record); break; + case U_EMR_OFFSETCLIPRGN: rstatus=U_EMROFFSETCLIPRGN_safe(record); break; + case U_EMR_MOVETOEX: rstatus=U_EMRMOVETOEX_safe(record); break; + case U_EMR_SETMETARGN: rstatus=U_EMRSETMETARGN_safe(record); break; + case U_EMR_EXCLUDECLIPRECT: rstatus=U_EMREXCLUDECLIPRECT_safe(record); break; + case U_EMR_INTERSECTCLIPRECT: rstatus=U_EMRINTERSECTCLIPRECT_safe(record); break; + case U_EMR_SCALEVIEWPORTEXTEX: rstatus=U_EMRSCALEVIEWPORTEXTEX_safe(record); break; + case U_EMR_SCALEWINDOWEXTEX: rstatus=U_EMRSCALEWINDOWEXTEX_safe(record); break; + case U_EMR_SAVEDC: rstatus=U_EMRSAVEDC_safe(record); break; + case U_EMR_RESTOREDC: rstatus=U_EMRRESTOREDC_safe(record); break; + case U_EMR_SETWORLDTRANSFORM: rstatus=U_EMRSETWORLDTRANSFORM_safe(record); break; + case U_EMR_MODIFYWORLDTRANSFORM: rstatus=U_EMRMODIFYWORLDTRANSFORM_safe(record); break; + case U_EMR_SELECTOBJECT: rstatus=U_EMRSELECTOBJECT_safe(record); break; + case U_EMR_CREATEPEN: rstatus=U_EMRCREATEPEN_safe(record); break; + case U_EMR_CREATEBRUSHINDIRECT: rstatus=U_EMRCREATEBRUSHINDIRECT_safe(record); break; + case U_EMR_DELETEOBJECT: rstatus=U_EMRDELETEOBJECT_safe(record); break; + case U_EMR_ANGLEARC: rstatus=U_EMRANGLEARC_safe(record); break; + case U_EMR_ELLIPSE: rstatus=U_EMRELLIPSE_safe(record); break; + case U_EMR_RECTANGLE: rstatus=U_EMRRECTANGLE_safe(record); break; + case U_EMR_ROUNDRECT: rstatus=U_EMRROUNDRECT_safe(record); break; + case U_EMR_ARC: rstatus=U_EMRARC_safe(record); break; + case U_EMR_CHORD: rstatus=U_EMRCHORD_safe(record); break; + case U_EMR_PIE: rstatus=U_EMRPIE_safe(record); break; + case U_EMR_SELECTPALETTE: rstatus=U_EMRSELECTPALETTE_safe(record); break; + case U_EMR_CREATEPALETTE: rstatus=U_EMRCREATEPALETTE_safe(record); break; + case U_EMR_SETPALETTEENTRIES: rstatus=U_EMRSETPALETTEENTRIES_safe(record); break; + case U_EMR_RESIZEPALETTE: rstatus=U_EMRRESIZEPALETTE_safe(record); break; + case U_EMR_REALIZEPALETTE: rstatus=U_EMRREALIZEPALETTE_safe(record); break; + case U_EMR_EXTFLOODFILL: rstatus=U_EMREXTFLOODFILL_safe(record); break; + case U_EMR_LINETO: rstatus=U_EMRLINETO_safe(record); break; + case U_EMR_ARCTO: rstatus=U_EMRARCTO_safe(record); break; + case U_EMR_POLYDRAW: rstatus=U_EMRPOLYDRAW_safe(record); break; + case U_EMR_SETARCDIRECTION: rstatus=U_EMRSETARCDIRECTION_safe(record); break; + case U_EMR_SETMITERLIMIT: rstatus=U_EMRSETMITERLIMIT_safe(record); break; + case U_EMR_BEGINPATH: rstatus=U_EMRBEGINPATH_safe(record); break; + case U_EMR_ENDPATH: rstatus=U_EMRENDPATH_safe(record); break; + case U_EMR_CLOSEFIGURE: rstatus=U_EMRCLOSEFIGURE_safe(record); break; + case U_EMR_FILLPATH: rstatus=U_EMRFILLPATH_safe(record); break; + case U_EMR_STROKEANDFILLPATH: rstatus=U_EMRSTROKEANDFILLPATH_safe(record); break; + case U_EMR_STROKEPATH: rstatus=U_EMRSTROKEPATH_safe(record); break; + case U_EMR_FLATTENPATH: rstatus=U_EMRFLATTENPATH_safe(record); break; + case U_EMR_WIDENPATH: rstatus=U_EMRWIDENPATH_safe(record); break; + case U_EMR_SELECTCLIPPATH: rstatus=U_EMRSELECTCLIPPATH_safe(record); break; + case U_EMR_ABORTPATH: rstatus=U_EMRABORTPATH_safe(record); break; + case U_EMR_UNDEF69: rstatus=U_EMRUNDEF69_safe(record); break; + case U_EMR_COMMENT: rstatus=U_EMRCOMMENT_safe(record); break; + case U_EMR_FILLRGN: rstatus=U_EMRFILLRGN_safe(record); break; + case U_EMR_FRAMERGN: rstatus=U_EMRFRAMERGN_safe(record); break; + case U_EMR_INVERTRGN: rstatus=U_EMRINVERTRGN_safe(record); break; + case U_EMR_PAINTRGN: rstatus=U_EMRPAINTRGN_safe(record); break; + case U_EMR_EXTSELECTCLIPRGN: rstatus=U_EMREXTSELECTCLIPRGN_safe(record); break; + case U_EMR_BITBLT: rstatus=U_EMRBITBLT_safe(record); break; + case U_EMR_STRETCHBLT: rstatus=U_EMRSTRETCHBLT_safe(record); break; + case U_EMR_MASKBLT: rstatus=U_EMRMASKBLT_safe(record); break; + case U_EMR_PLGBLT: rstatus=U_EMRPLGBLT_safe(record); break; + case U_EMR_SETDIBITSTODEVICE: rstatus=U_EMRSETDIBITSTODEVICE_safe(record); break; + case U_EMR_STRETCHDIBITS: rstatus=U_EMRSTRETCHDIBITS_safe(record); break; + case U_EMR_EXTCREATEFONTINDIRECTW: rstatus=U_EMREXTCREATEFONTINDIRECTW_safe(record); break; + case U_EMR_EXTTEXTOUTA: rstatus=U_EMREXTTEXTOUTA_safe(record); break; + case U_EMR_EXTTEXTOUTW: rstatus=U_EMREXTTEXTOUTW_safe(record); break; + case U_EMR_POLYBEZIER16: rstatus=U_EMRPOLYBEZIER16_safe(record); break; + case U_EMR_POLYGON16: rstatus=U_EMRPOLYGON16_safe(record); break; + case U_EMR_POLYLINE16: rstatus=U_EMRPOLYLINE16_safe(record); break; + case U_EMR_POLYBEZIERTO16: rstatus=U_EMRPOLYBEZIERTO16_safe(record); break; + case U_EMR_POLYLINETO16: rstatus=U_EMRPOLYLINETO16_safe(record); break; + case U_EMR_POLYPOLYLINE16: rstatus=U_EMRPOLYPOLYLINE16_safe(record); break; + case U_EMR_POLYPOLYGON16: rstatus=U_EMRPOLYPOLYGON16_safe(record); break; + case U_EMR_POLYDRAW16: rstatus=U_EMRPOLYDRAW16_safe(record); break; + case U_EMR_CREATEMONOBRUSH: rstatus=U_EMRCREATEMONOBRUSH_safe(record); break; + case U_EMR_CREATEDIBPATTERNBRUSHPT: rstatus=U_EMRCREATEDIBPATTERNBRUSHPT_safe(record); break; + case U_EMR_EXTCREATEPEN: rstatus=U_EMREXTCREATEPEN_safe(record); break; + case U_EMR_POLYTEXTOUTA: rstatus=U_EMRPOLYTEXTOUTA_safe(record); break; + case U_EMR_POLYTEXTOUTW: rstatus=U_EMRPOLYTEXTOUTW_safe(record); break; + case U_EMR_SETICMMODE: rstatus=U_EMRSETICMMODE_safe(record); break; + case U_EMR_CREATECOLORSPACE: rstatus=U_EMRCREATECOLORSPACE_safe(record); break; + case U_EMR_SETCOLORSPACE: rstatus=U_EMRSETCOLORSPACE_safe(record); break; + case U_EMR_DELETECOLORSPACE: rstatus=U_EMRDELETECOLORSPACE_safe(record); break; + case U_EMR_GLSRECORD: rstatus=U_EMRGLSRECORD_safe(record); break; + case U_EMR_GLSBOUNDEDRECORD: rstatus=U_EMRGLSBOUNDEDRECORD_safe(record); break; + case U_EMR_PIXELFORMAT: rstatus=U_EMRPIXELFORMAT_safe(record); break; + case U_EMR_DRAWESCAPE: rstatus=U_EMRDRAWESCAPE_safe(record); break; + case U_EMR_EXTESCAPE: rstatus=U_EMREXTESCAPE_safe(record); break; + case U_EMR_UNDEF107: rstatus=U_EMRUNDEF107_safe(record); break; + case U_EMR_SMALLTEXTOUT: rstatus=U_EMRSMALLTEXTOUT_safe(record); break; + case U_EMR_FORCEUFIMAPPING: rstatus=U_EMRFORCEUFIMAPPING_safe(record); break; + case U_EMR_NAMEDESCAPE: rstatus=U_EMRNAMEDESCAPE_safe(record); break; + case U_EMR_COLORCORRECTPALETTE: rstatus=U_EMRCOLORCORRECTPALETTE_safe(record); break; + case U_EMR_SETICMPROFILEA: rstatus=U_EMRSETICMPROFILEA_safe(record); break; + case U_EMR_SETICMPROFILEW: rstatus=U_EMRSETICMPROFILEW_safe(record); break; + case U_EMR_ALPHABLEND: rstatus=U_EMRALPHABLEND_safe(record); break; + case U_EMR_SETLAYOUT: rstatus=U_EMRSETLAYOUT_safe(record); break; + case U_EMR_TRANSPARENTBLT: rstatus=U_EMRTRANSPARENTBLT_safe(record); break; + case U_EMR_UNDEF117: rstatus=U_EMRUNDEF117_safe(record); break; + case U_EMR_GRADIENTFILL: rstatus=U_EMRGRADIENTFILL_safe(record); break; + case U_EMR_SETLINKEDUFIS: rstatus=U_EMRSETLINKEDUFIS_safe(record); break; + case U_EMR_SETTEXTJUSTIFICATION: rstatus=U_EMRSETTEXTJUSTIFICATION_safe(record); break; + case U_EMR_COLORMATCHTOTARGETW: rstatus=U_EMRCOLORMATCHTOTARGETW_safe(record); break; + case U_EMR_CREATECOLORSPACEW: rstatus=U_EMRCREATECOLORSPACEW_safe(record); break; + default: rstatus=U_EMRNOTIMPLEMENTED_safe(record); break; + } //end of switch + return(rstatus); +} + + +#ifdef __cplusplus +} +#endif diff --git a/src/libuemf/uemf_safe.h b/src/libuemf/uemf_safe.h new file mode 100644 index 000000000..0c9e3cc69 --- /dev/null +++ b/src/libuemf/uemf_safe.h @@ -0,0 +1,32 @@ +/** + @file uemf_safe.h + + @brief Defintions and prototype for function for converting EMF records between Big Endian and Little Endian byte orders. +*/ + +/* +File: uemf_endian.h +Version: 0.0.2 +Date: 26-MAR-2015 +Author: David Mathog, Biology Division, Caltech +email: mathog@caltech.edu +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) +*/ + +#ifndef _UEMF_SAFE_ +#define _UEMF_SAFE_ + +#ifdef __cplusplus +extern "C" { +#endif + +// prototypes +int U_emf_record_safe(const char *record); +int bitmapinfo_safe(const char *Bmi, const char *blimit); +//! \endcond + +#ifdef __cplusplus +} +#endif + +#endif /* _UEMF_SAFE_ */ -- cgit v1.2.3 From 4bd4a89e23064b6782728d7965b12443978dcd29 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Tue, 28 Apr 2015 00:56:20 +0200 Subject: removed a few "using Inkscape::Util::GSListConstIterator" (bzr r13922.1.16) --- src/extension/implementation/implementation.cpp | 1 - src/extension/internal/bitmap/imagemagick.cpp | 2 -- src/extension/internal/bluredge.cpp | 1 - src/extension/internal/grid.cpp | 2 -- src/removeoverlap.cpp | 1 - src/ui/dialog/align-and-distribute.cpp | 5 ----- src/ui/dialog/transformation.cpp | 1 - 7 files changed, 13 deletions(-) (limited to 'src') diff --git a/src/extension/implementation/implementation.cpp b/src/extension/implementation/implementation.cpp index 717ca3310..b0ff3e91c 100644 --- a/src/extension/implementation/implementation.cpp +++ b/src/extension/implementation/implementation.cpp @@ -47,7 +47,6 @@ Gtk::Widget *Implementation::prefs_effect(Inkscape::Extension::Effect *module, I SPDocument * current_document = view->doc(); - using Inkscape::Util::GSListConstIterator; std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node const* first_select = NULL; if (!selected.empty()) { diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index 3a29b3dc0..5e4c930bc 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -240,8 +240,6 @@ ImageMagick::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::Vie { SPDocument * current_document = view->doc(); - using Inkscape::Util::GSListConstIterator; - std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; if (!selected.empty()) { diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp index b80e5ddbb..9f19f8b3b 100644 --- a/src/extension/internal/bluredge.cpp +++ b/src/extension/internal/bluredge.cpp @@ -63,7 +63,6 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double old_offset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, "px"); - using Inkscape::Util::GSListConstIterator; // TODO need to properly refcount the items, at least std::vector items(selection->itemList()); selection->clear(); diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index 60d606a02..932d9a0d0 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -190,8 +190,6 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View { SPDocument * current_document = view->doc(); - using Inkscape::Util::GSListConstIterator; - std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); Inkscape::XML::Node * first_select = NULL; if (!selected.empty()) { diff --git a/src/removeoverlap.cpp b/src/removeoverlap.cpp index 01ce2c47e..9ea75de0d 100644 --- a/src/removeoverlap.cpp +++ b/src/removeoverlap.cpp @@ -39,7 +39,6 @@ namespace { * horizontally and yGap vertically */ void removeoverlap(std::vector const &items, double const xGap, double const yGap) { - using Inkscape::Util::GSListConstIterator; std::vector selected(items); std::vector records; std::vector rs; diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 1ee72dcbc..882427912 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -97,7 +97,6 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool sel_as_group = prefs->getBool("/dialogs/align/sel-as-groups"); - using Inkscape::Util::GSListConstIterator; std::vector selected(selection->itemList()); if (selected.empty()) return; @@ -250,7 +249,6 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - using Inkscape::Util::GSListConstIterator; std::vector selected(selection->itemList()); if (selected.empty()) return; @@ -548,7 +546,6 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - using Inkscape::Util::GSListConstIterator; std::vector selected(selection->itemList()); if (selected.empty()) return; @@ -646,7 +643,6 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - using Inkscape::Util::GSListConstIterator; std::vector selected(selection->itemList()); if (selected.empty()) return; @@ -745,7 +741,6 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - using Inkscape::Util::GSListConstIterator; std::vector selected(selection->itemList()); if (selected.empty()) return; diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 459e6e937..5bd3cb309 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -740,7 +740,6 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) if (_check_move_relative.get_active()) { // shift each object relatively to the previous one - using Inkscape::Util::GSListConstIterator; std::vector selected(selection->itemList()); if (selected.empty()) return; -- cgit v1.2.3 From 643c75ddbbbea2f018050faa1e7e38c71482418a Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Tue, 28 Apr 2015 01:20:57 +0200 Subject: removed a few useless SP_OBJECT() casts (bzr r13922.1.17) --- src/selection-chemistry.cpp | 28 ++++++++++++++-------------- src/selection.cpp | 4 ++-- src/splivarot.cpp | 4 ++-- src/ui/dialog/object-attributes.cpp | 2 +- src/ui/dialog/transformation.cpp | 2 +- src/ui/tools/gradient-tool.cpp | 2 +- src/widgets/stroke-style.cpp | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index c1d4f58e4..7255e80cb 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -889,14 +889,14 @@ sp_item_list_common_parent_group(std::vector const items) if (items.empty()) { return NULL; } - SPObject *parent = SP_OBJECT(items[0])->parent; + SPObject *parent = items[0]->parent; // Strictly speaking this CAN happen, if user selects from Inkscape::XML editor if (!dynamic_cast(parent)) { return NULL; } for (std::vector::const_iterator item=items.begin();item!=items.end();item++) { if((*item)==items[0])continue; - if (SP_OBJECT(*item)->parent != parent) { + if ((*item)->parent != parent) { return NULL; } } @@ -2896,7 +2896,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) //items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); // Why needed? // bottommost object, after sorting - SPObject *parent = SP_OBJECT(items[0])->parent; + SPObject *parent = items[0]->parent; Geom::Affine parent_transform; { @@ -2911,7 +2911,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) // Create a list of duplicates, to be pasted inside marker element. std::vector repr_copies; for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ - Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); repr_copies.push_back(dup); } @@ -3248,7 +3248,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) sort(items.begin(),items.end(),sp_object_compare_position); // bottommost object, after sorting - SPObject *parent = SP_OBJECT(items[0])->parent; + SPObject *parent = items[0]->parent; Geom::Affine parent_transform; @@ -3262,12 +3262,12 @@ sp_selection_tile(SPDesktop *desktop, bool apply) } // remember the position of the first item - gint pos = SP_OBJECT(items[0])->getRepr()->position(); + gint pos = items[0]->getRepr()->position(); // create a list of duplicates std::vector repr_copies; for (std::vector::const_iterator i=items.begin();i!=items.end();i++){ - Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); repr_copies.push_back(dup); } @@ -3520,7 +3520,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) // Create the filename. gchar *const basename = g_strdup_printf("%s-%s-%u.png", document->getName(), - SP_OBJECT(items[0])->getRepr()->attribute("id"), + items[0]->getRepr()->attribute("id"), current); // Imagemagick is known not to handle spaces in filenames, so we replace anything but letters, // digits, and a few other chars, with "_" @@ -3540,8 +3540,8 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) //g_print("%s\n", filepath); // Remember parent and z-order of the topmost one - gint pos = SP_OBJECT(items.back())->getRepr()->position(); - SPObject *parent_object = SP_OBJECT(items.back())->parent; + gint pos = items.back()->getRepr()->position(); + SPObject *parent_object = items.back()->parent; Inkscape::XML::Node *parent = parent_object->getRepr(); // Calculate resolution @@ -3857,7 +3857,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ apply_to_items = g_slist_prepend(apply_to_items, desktop->currentLayer()); for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { - Inkscape::XML::Node *dup = SP_OBJECT(*i)->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); SPObject *item = *i; @@ -3870,7 +3870,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ } } else if (!topmost) { // topmost item is used as a mask, which is applied to other items in a selection - Inkscape::XML::Node *dup = SP_OBJECT(items[0])->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *dup = items[0]->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); if (remove_original) { @@ -4049,7 +4049,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { } } - SP_OBJECT(*i)->getRepr()->setAttribute(attributeName, "none"); + (*i)->getRepr()->setAttribute(attributeName, "none"); SPGroup *group = dynamic_cast(*i); if (ungroup_masked && group) { @@ -4070,7 +4070,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { GSList *items_to_move = NULL; for ( SPObject *child = obj->firstChild() ; child; child = child->getNext() ) { // Collect all clipped paths and masks within a single group - Inkscape::XML::Node *copy = SP_OBJECT(child)->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *copy = child->getRepr()->duplicate(xml_doc); if(copy->attribute("inkscape:original-d") && copy->attribute("inkscape:path-effect")) { copy->setAttribute("d", copy->attribute("inkscape:original-d")); diff --git a/src/selection.cpp b/src/selection.cpp index d9266b599..b2fb6447e 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -517,7 +517,7 @@ uint Selection::numberOfLayers() { std::vector const items = const_cast(this)->itemList(); std::set layers; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPObject *layer = _layers->layerForObject(SP_OBJECT(*iter)); + SPObject *layer = _layers->layerForObject(*iter); layers.insert(layer); } return layers.size(); @@ -527,7 +527,7 @@ guint Selection::numberOfParents() { std::vector const items = const_cast(this)->itemList(); std::set parents; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPObject *parent = SP_OBJECT(*iter)->parent; + SPObject *parent = (*iter)->parent; parents.insert(parent); } return parents.size(); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index a04dedda9..f61a30462 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -354,8 +354,8 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool if (bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice) { // check in the tree to find which element of the selection list is topmost (for 2-operand commands only) - Inkscape::XML::Node *a = SP_OBJECT(il.front())->getRepr(); - Inkscape::XML::Node *b = SP_OBJECT(il.back())->getRepr(); + Inkscape::XML::Node *a = il.front()->getRepr(); + Inkscape::XML::Node *b = il.back()->getRepr(); if (a == NULL || b == NULL) { boolop_display_error_message(desktop, _("Unable to determine the z-order of the objects selected for difference, XOR, division, or path cut.")); diff --git a/src/ui/dialog/object-attributes.cpp b/src/ui/dialog/object-attributes.cpp index f43a15225..1bc570f43 100644 --- a/src/ui/dialog/object-attributes.cpp +++ b/src/ui/dialog/object-attributes.cpp @@ -127,7 +127,7 @@ void ObjectAttributes::widget_setup (void) blocked = true; // CPPIFY - SPObject *obj = SP_OBJECT(item); //to get the selected item + SPObject *obj = item; //to get the selected item // GObjectClass *klass = G_OBJECT_GET_CLASS(obj); //to deduce the object's type // GType type = G_TYPE_FROM_CLASS(klass); const SPAttrDesc *desc; diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 5bd3cb309..f571828ce 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -1005,7 +1005,7 @@ void Transformation::applyPageTransform(Inkscape::Selection *selection) for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();i++){ SPItem *item = *i; item->set_item_transform(displayed); - SP_OBJECT(item)->updateRepr(); + item->updateRepr(); } } else { sp_selection_apply_affine(selection, displayed); // post-multiply each object's transform diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index bf38b5ca5..526671515 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -913,7 +913,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta for (std::vector::const_iterator i = itemlist.begin();i!=itemlist.end();i++) { //FIXME: see above - sp_repr_css_change_recursive(SP_OBJECT(*i)->getRepr(), css, "style"); + sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); sp_item_set_gradient(*i, vector, (SPGradientType) type, fill_or_stroke); diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 481fa0609..482ca7af4 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -902,7 +902,7 @@ StrokeStyle::updateLine() return; std::vector const objects = sel->itemList(); - SPObject * const object = SP_OBJECT(objects[0]); + SPObject * const object = objects[0]; SPStyle * const style = object->style; /* Markers */ @@ -1002,7 +1002,7 @@ StrokeStyle::scaleLine() /* Set dash */ setScaledDash(css, ndash, dash, offset, width); - sp_desktop_apply_css_recursive (SP_OBJECT(*i), css, true); + sp_desktop_apply_css_recursive ((*i), css, true); } g_free(dash); -- cgit v1.2.3 From ba4dbfb351180e0fc4ad57be6e3534fa2ab5cf8c Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Tue, 28 Apr 2015 00:38:31 +0100 Subject: Fix unnecessary inclusion of glibmm/threads.h. This can be resolved by ensuring that glibmm headers always preceed glib.h headers. Same applies with gtkmm/gtk+ etc (bzr r14064) --- src/display/canvas-axonomgrid.cpp | 4 ---- src/display/canvas-grid.cpp | 4 ---- src/extension/execution-env.cpp | 4 ---- src/extension/extension.cpp | 4 ---- src/extension/internal/bitmap/imagemagick.cpp | 4 ---- src/extension/internal/cdr-input.h | 4 ---- src/extension/internal/grid.cpp | 4 ---- src/extension/internal/pdfinput/pdf-input.h | 4 ---- src/extension/internal/vsd-input.h | 4 ---- src/extension/param/bool.cpp | 4 ---- src/extension/param/color.cpp | 4 ---- src/extension/param/description.cpp | 4 ---- src/extension/param/enum.cpp | 4 ---- src/extension/param/float.cpp | 4 ---- src/extension/param/int.cpp | 4 ---- src/extension/param/notebook.cpp | 4 ---- src/extension/param/radiobutton.cpp | 4 ---- src/extension/param/string.cpp | 4 ---- src/extension/prefdialog.h | 9 --------- src/inkscape.cpp | 4 ---- src/libdepixelize/kopftracer2011.cpp | 7 +------ src/live_effects/lpe-fillet-chamfer.h | 8 -------- src/live_effects/lpe-lattice2.cpp | 2 ++ src/live_effects/lpe-lattice2.h | 6 +++++- src/live_effects/parameter/originalpath.cpp | 4 ---- src/live_effects/parameter/originalpatharray.cpp | 4 ---- src/ui/dialog-events.cpp | 4 ---- src/ui/dialog/aboutbox.h | 8 -------- src/ui/dialog/calligraphic-profile-rename.h | 4 ---- src/ui/dialog/color-item.cpp | 4 ---- src/ui/dialog/debug.cpp | 4 ---- src/ui/dialog/export.cpp | 4 ---- src/ui/dialog/filedialogimpl-gtkmm.h | 8 -------- src/ui/dialog/filedialogimpl-win32.h | 5 ----- src/ui/dialog/floating-behavior.cpp | 4 ---- src/ui/dialog/font-substitution.cpp | 4 ---- src/ui/dialog/guides.h | 4 ---- src/ui/dialog/icon-preview.cpp | 4 ---- src/ui/dialog/layer-properties.h | 4 ---- src/ui/dialog/layers.h | 4 ---- src/ui/dialog/livepatheffect-add.h | 8 -------- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 4 ---- src/ui/dialog/lpe-powerstroke-properties.cpp | 4 ---- src/ui/dialog/messages.h | 8 -------- src/ui/dialog/objects.h | 4 ---- src/ui/dialog/ocaldialogs.h | 4 ---- src/ui/dialog/spellcheck.h | 4 ---- src/ui/dialog/symbols.cpp | 4 ---- src/ui/dialog/text-edit.h | 4 ---- src/ui/dialog/tile.h | 4 ---- src/ui/dialog/transformation.cpp | 4 ---- src/ui/previewholder.h | 4 ---- src/ui/tools/tool-base.cpp | 4 ---- src/ui/widget/addtoicon.cpp | 4 ---- src/ui/widget/button.h | 8 -------- src/ui/widget/clipmaskicon.cpp | 4 ---- src/ui/widget/color-picker.h | 8 -------- src/ui/widget/color-preview.h | 4 ---- src/ui/widget/dock-item.h | 4 ---- src/ui/widget/dock.h | 8 -------- src/ui/widget/entity-entry.cpp | 4 ---- src/ui/widget/filter-effect-chooser.h | 8 -------- src/ui/widget/frame.h | 8 -------- src/ui/widget/imageicon.h | 8 -------- src/ui/widget/imagetoggler.h | 4 ---- src/ui/widget/insertordericon.h | 3 ++- src/ui/widget/labelled.h | 8 -------- src/ui/widget/layertypeicon.cpp | 4 ---- src/ui/widget/licensor.h | 8 -------- src/ui/widget/notebook-page.h | 4 ---- src/ui/widget/object-composite-settings.h | 8 -------- src/ui/widget/panel.cpp | 4 ---- src/ui/widget/panel.h | 4 ---- src/ui/widget/preferences-widget.cpp | 4 ---- src/ui/widget/preferences-widget.h | 4 ---- src/ui/widget/rotateable.cpp | 4 ---- src/ui/widget/selected-style.h | 4 ---- src/ui/widget/spin-scale.h | 4 ---- src/ui/widget/spin-slider.h | 4 ---- src/ui/widget/spinbutton.h | 8 -------- src/ui/widget/style-swatch.h | 4 ---- src/ui/widget/tolerance-slider.cpp | 4 ---- src/ui/widget/unit-menu.h | 8 -------- src/verbs.cpp | 7 +++---- src/widgets/dash-selector.h | 4 ---- src/widgets/desktop-widget.h | 8 -------- src/widgets/fill-style.cpp | 4 ---- src/widgets/icon.cpp | 4 ---- src/widgets/paint-selector.cpp | 4 ---- src/widgets/shrink-wrap-button.cpp | 4 ---- src/widgets/sp-attribute-widget.h | 4 ---- src/widgets/spw-utilities.cpp | 4 ---- src/widgets/stroke-marker-selector.h | 8 -------- src/widgets/swatch-selector.h | 8 -------- src/widgets/toolbox.cpp | 4 ---- 95 files changed, 13 insertions(+), 454 deletions(-) (limited to 'src') diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index a2df86823..1794ccbab 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -17,10 +17,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 9b9f64529..4eda9b194 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -17,10 +17,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index 13b8d60c4..e7cd43d9d 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -14,10 +14,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include "gtkmm/messagedialog.h" #include "execution-env.h" diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 3d0f49a20..6f7539360 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -19,10 +19,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index 76f35415e..7c91bf1ef 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -12,10 +12,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/extension/internal/cdr-input.h b/src/extension/internal/cdr-input.h index 3de6c1ed0..10af41d5a 100644 --- a/src/extension/internal/cdr-input.h +++ b/src/extension/internal/cdr-input.h @@ -19,10 +19,6 @@ #ifdef WITH_LIBCDR -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include "../implementation/implementation.h" diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index 270edfe44..61f2f70e2 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -15,10 +15,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/internal/pdfinput/pdf-input.h b/src/extension/internal/pdfinput/pdf-input.h index d57c3e993..866db5d82 100644 --- a/src/extension/internal/pdfinput/pdf-input.h +++ b/src/extension/internal/pdfinput/pdf-input.h @@ -16,10 +16,6 @@ #ifdef HAVE_POPPLER -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include "../../implementation/implementation.h" diff --git a/src/extension/internal/vsd-input.h b/src/extension/internal/vsd-input.h index 3414e0ec9..acc52debf 100644 --- a/src/extension/internal/vsd-input.h +++ b/src/extension/internal/vsd-input.h @@ -19,10 +19,6 @@ #ifdef WITH_LIBVISIO -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include "../implementation/implementation.h" diff --git a/src/extension/param/bool.cpp b/src/extension/param/bool.cpp index 548dec4fa..de9b1c586 100644 --- a/src/extension/param/bool.cpp +++ b/src/extension/param/bool.cpp @@ -10,10 +10,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/param/color.cpp b/src/extension/param/color.cpp index 5bd70359f..b774bac83 100644 --- a/src/extension/param/color.cpp +++ b/src/extension/param/color.cpp @@ -14,10 +14,6 @@ #include #include -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/param/description.cpp b/src/extension/param/description.cpp index 95ed04afc..326e75e4a 100644 --- a/src/extension/param/description.cpp +++ b/src/extension/param/description.cpp @@ -13,10 +13,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/param/enum.cpp b/src/extension/param/enum.cpp index 74b2a75ad..8bc0fbda7 100644 --- a/src/extension/param/enum.cpp +++ b/src/extension/param/enum.cpp @@ -18,10 +18,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/param/float.cpp b/src/extension/param/float.cpp index 464938f03..81508f6c0 100644 --- a/src/extension/param/float.cpp +++ b/src/extension/param/float.cpp @@ -10,10 +10,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/param/int.cpp b/src/extension/param/int.cpp index 819c75693..c286018fd 100644 --- a/src/extension/param/int.cpp +++ b/src/extension/param/int.cpp @@ -10,10 +10,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/param/notebook.cpp b/src/extension/param/notebook.cpp index 9ec31ca6b..20c8e8481 100644 --- a/src/extension/param/notebook.cpp +++ b/src/extension/param/notebook.cpp @@ -16,10 +16,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index 740acf1d1..8181c6f51 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -18,10 +18,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/param/string.cpp b/src/extension/param/string.cpp index d6e438db5..4e525ff73 100644 --- a/src/extension/param/string.cpp +++ b/src/extension/param/string.cpp @@ -10,10 +10,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/extension/prefdialog.h b/src/extension/prefdialog.h index 905d35744..4714c2c3f 100644 --- a/src/extension/prefdialog.h +++ b/src/extension/prefdialog.h @@ -10,19 +10,10 @@ #ifndef INKSCAPE_EXTENSION_DIALOG_H__ #define INKSCAPE_EXTENSION_DIALOG_H__ -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include - namespace Gtk { class CheckButton; } diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 6a0e0f35a..888a64430 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -22,10 +22,6 @@ #include -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include "debug/simple-event.h" #include "debug/event-tracker.h" diff --git a/src/libdepixelize/kopftracer2011.cpp b/src/libdepixelize/kopftracer2011.cpp index 1e769b0c9..96784b14f 100644 --- a/src/libdepixelize/kopftracer2011.cpp +++ b/src/libdepixelize/kopftracer2011.cpp @@ -28,11 +28,6 @@ #include -// Build fix under Inkscape build tree -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include "kopftracer2011.h" #include "priv/colorspace.h" @@ -667,4 +662,4 @@ inline bool Heuristics::islands(PixelGraph::const_iterator a, fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 0d6a1ff17..fb06e804c 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -15,14 +15,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#if defined(GLIBMM_DISABLE_DEPRECATED) && defined(HAVE_GLIBMM_THREADS_H) -# include -#endif - #include "live_effects/parameter/enum.h" #include "live_effects/parameter/bool.h" #include "live_effects/parameter/unit.h" diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index abd6e7786..02bda3af5 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -18,6 +18,8 @@ #include "live_effects/lpe-lattice2.h" +#include + #include "sp-shape.h" #include "sp-item.h" #include "sp-path.h" diff --git a/src/live_effects/lpe-lattice2.h b/src/live_effects/lpe-lattice2.h index ff2e75641..b32903c9e 100644 --- a/src/live_effects/lpe-lattice2.h +++ b/src/live_effects/lpe-lattice2.h @@ -18,12 +18,16 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include "live_effects/parameter/enum.h" +#include #include "live_effects/effect.h" #include "live_effects/parameter/point.h" #include "live_effects/lpegroupbbox.h" +namespace Gtk { +class Expander; +} + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/parameter/originalpath.cpp b/src/live_effects/parameter/originalpath.cpp index 0884c4c9c..2741461be 100644 --- a/src/live_effects/parameter/originalpath.cpp +++ b/src/live_effects/parameter/originalpath.cpp @@ -8,10 +8,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include "live_effects/parameter/originalpath.h" diff --git a/src/live_effects/parameter/originalpatharray.cpp b/src/live_effects/parameter/originalpatharray.cpp index 7706dbdf8..78e061e66 100644 --- a/src/live_effects/parameter/originalpatharray.cpp +++ b/src/live_effects/parameter/originalpatharray.cpp @@ -8,10 +8,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include "live_effects/parameter/originalpatharray.h" #include diff --git a/src/ui/dialog-events.cpp b/src/ui/dialog-events.cpp index 5bc8088a1..8856631c0 100644 --- a/src/ui/dialog-events.cpp +++ b/src/ui/dialog-events.cpp @@ -15,10 +15,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/aboutbox.h b/src/ui/dialog/aboutbox.h index 015e344a1..f3234b88d 100644 --- a/src/ui/dialog/aboutbox.h +++ b/src/ui/dialog/aboutbox.h @@ -15,14 +15,6 @@ #ifndef INKSCAPE_UI_DIALOG_ABOUTBOX_H #define INKSCAPE_UI_DIALOG_ABOUTBOX_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include namespace Inkscape { diff --git a/src/ui/dialog/calligraphic-profile-rename.h b/src/ui/dialog/calligraphic-profile-rename.h index fa13db196..4ef71900b 100644 --- a/src/ui/dialog/calligraphic-profile-rename.h +++ b/src/ui/dialog/calligraphic-profile-rename.h @@ -15,10 +15,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -# include -#endif - #include #include #include diff --git a/src/ui/dialog/color-item.cpp b/src/ui/dialog/color-item.cpp index a49a47d5c..6603d5c69 100644 --- a/src/ui/dialog/color-item.cpp +++ b/src/ui/dialog/color-item.cpp @@ -17,10 +17,6 @@ #include -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/debug.cpp b/src/ui/dialog/debug.cpp index 9e2287f80..d127261c0 100644 --- a/src/ui/dialog/debug.cpp +++ b/src/ui/dialog/debug.cpp @@ -13,10 +13,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 6d90c792e..9ac5c24fe 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -20,10 +20,6 @@ // This has to be included prior to anything that includes setjmp.h, it croaks otherwise #include -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/filedialogimpl-gtkmm.h b/src/ui/dialog/filedialogimpl-gtkmm.h index 6687915d7..7501b5e14 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.h +++ b/src/ui/dialog/filedialogimpl-gtkmm.h @@ -17,14 +17,6 @@ #ifndef __FILE_DIALOGIMPL_H__ #define __FILE_DIALOGIMPL_H__ -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - //Gtk includes #include #include diff --git a/src/ui/dialog/filedialogimpl-win32.h b/src/ui/dialog/filedialogimpl-win32.h index 8c3b6bad6..b254c3ef6 100644 --- a/src/ui/dialog/filedialogimpl-win32.h +++ b/src/ui/dialog/filedialogimpl-win32.h @@ -16,11 +16,6 @@ #include #ifdef WIN32 -#if WITH_GLIBMM_2_32 -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -# include -#endif -#endif #include "filedialogimpl-gtkmm.h" diff --git a/src/ui/dialog/floating-behavior.cpp b/src/ui/dialog/floating-behavior.cpp index 11db14801..740acd989 100644 --- a/src/ui/dialog/floating-behavior.cpp +++ b/src/ui/dialog/floating-behavior.cpp @@ -14,10 +14,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp index ae03bdf0e..2ef61978f 100644 --- a/src/ui/dialog/font-substitution.cpp +++ b/src/ui/dialog/font-substitution.cpp @@ -10,10 +10,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/guides.h b/src/ui/dialog/guides.h index 22bf5097a..4ff7b4fde 100644 --- a/src/ui/dialog/guides.h +++ b/src/ui/dialog/guides.h @@ -15,10 +15,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #if WITH_GTKMM_3_0 diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index b908a90cb..069b61cb7 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -17,10 +17,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/ui/dialog/layer-properties.h b/src/ui/dialog/layer-properties.h index d114c6ba5..c75a7f190 100644 --- a/src/ui/dialog/layer-properties.h +++ b/src/ui/dialog/layer-properties.h @@ -16,10 +16,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/layers.h b/src/ui/dialog/layers.h index ae0ac6040..9cd2c3b92 100644 --- a/src/ui/dialog/layers.h +++ b/src/ui/dialog/layers.h @@ -16,10 +16,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/livepatheffect-add.h b/src/ui/dialog/livepatheffect-add.h index 99ead878c..c686e8365 100644 --- a/src/ui/dialog/livepatheffect-add.h +++ b/src/ui/dialog/livepatheffect-add.h @@ -11,14 +11,6 @@ #ifndef INKSCAPE_DIALOG_LIVEPATHEFFECT_ADD_H #define INKSCAPE_DIALOG_LIVEPATHEFFECT_ADD_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index 7e5c17133..f63b19e86 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -8,10 +8,6 @@ #include #endif -#if GLIBMM_DISABLE_DEPRECATED &&HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include "lpe-fillet-chamfer-properties.h" #include diff --git a/src/ui/dialog/lpe-powerstroke-properties.cpp b/src/ui/dialog/lpe-powerstroke-properties.cpp index a9e57970d..0cf3e9706 100644 --- a/src/ui/dialog/lpe-powerstroke-properties.cpp +++ b/src/ui/dialog/lpe-powerstroke-properties.cpp @@ -17,10 +17,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include "lpe-powerstroke-properties.h" #include #include diff --git a/src/ui/dialog/messages.h b/src/ui/dialog/messages.h index 54ca84f47..6ed246ece 100644 --- a/src/ui/dialog/messages.h +++ b/src/ui/dialog/messages.h @@ -16,14 +16,6 @@ #ifndef INKSCAPE_UI_DIALOG_MESSAGES_H #define INKSCAPE_UI_DIALOG_MESSAGES_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/objects.h b/src/ui/dialog/objects.h index 74c2382ac..1842fea11 100644 --- a/src/ui/dialog/objects.h +++ b/src/ui/dialog/objects.h @@ -16,10 +16,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -# include -#endif - #include #include #include diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h index bd028c145..6ceceb9ef 100644 --- a/src/ui/dialog/ocaldialogs.h +++ b/src/ui/dialog/ocaldialogs.h @@ -17,10 +17,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - //Gtk includes #include #include diff --git a/src/ui/dialog/spellcheck.h b/src/ui/dialog/spellcheck.h index 27b89e34e..e98a9d80e 100644 --- a/src/ui/dialog/spellcheck.h +++ b/src/ui/dialog/spellcheck.h @@ -16,10 +16,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index eeb4d6cbe..06c17611f 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -18,10 +18,6 @@ #include #include -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/ui/dialog/text-edit.h b/src/ui/dialog/text-edit.h index 8683d80a3..117ad2e28 100644 --- a/src/ui/dialog/text-edit.h +++ b/src/ui/dialog/text-edit.h @@ -22,10 +22,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/tile.h b/src/ui/dialog/tile.h index 2f75a8922..de1d3028b 100644 --- a/src/ui/dialog/tile.h +++ b/src/ui/dialog/tile.h @@ -20,10 +20,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 233d99750..e7ee9529f 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -15,10 +15,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include <2geom/transforms.h> diff --git a/src/ui/previewholder.h b/src/ui/previewholder.h index f9f923be4..f6d1985cc 100644 --- a/src/ui/previewholder.h +++ b/src/ui/previewholder.h @@ -16,10 +16,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index a07f2fb86..2eb6d24d9 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -20,10 +20,6 @@ #include "widgets/desktop-widget.h" -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include "shortcuts.h" #include "file.h" #include "ui/tools/tool-base.h" diff --git a/src/ui/widget/addtoicon.cpp b/src/ui/widget/addtoicon.cpp index f15d7abf7..823e24a00 100644 --- a/src/ui/widget/addtoicon.cpp +++ b/src/ui/widget/addtoicon.cpp @@ -12,10 +12,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -# include -#endif - #include "ui/widget/addtoicon.h" #include diff --git a/src/ui/widget/button.h b/src/ui/widget/button.h index 471b7d8a2..d3c9afa02 100644 --- a/src/ui/widget/button.h +++ b/src/ui/widget/button.h @@ -10,14 +10,6 @@ #ifndef INKSCAPE_UI_WIDGET_BUTTON_H #define INKSCAPE_UI_WIDGET_BUTTON_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/ui/widget/clipmaskicon.cpp b/src/ui/widget/clipmaskicon.cpp index 943b1bebc..421f1df1e 100644 --- a/src/ui/widget/clipmaskicon.cpp +++ b/src/ui/widget/clipmaskicon.cpp @@ -11,10 +11,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -# include -#endif - #include "ui/widget/clipmaskicon.h" #include diff --git a/src/ui/widget/color-picker.h b/src/ui/widget/color-picker.h index b4da5dbf2..99904b081 100644 --- a/src/ui/widget/color-picker.h +++ b/src/ui/widget/color-picker.h @@ -13,16 +13,8 @@ #ifndef __COLOR_PICKER_H__ #define __COLOR_PICKER_H__ -#ifdef HAVE_CONFIG_H -# include -#endif - #include -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/color-preview.h b/src/ui/widget/color-preview.h index 959b5e09b..caddfb9a2 100644 --- a/src/ui/widget/color-preview.h +++ b/src/ui/widget/color-preview.h @@ -15,10 +15,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include namespace Inkscape { diff --git a/src/ui/widget/dock-item.h b/src/ui/widget/dock-item.h index cc0c13eea..25a69d94c 100644 --- a/src/ui/widget/dock-item.h +++ b/src/ui/widget/dock-item.h @@ -15,10 +15,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/dock.h b/src/ui/widget/dock.h index 33e60b836..74b072d22 100644 --- a/src/ui/widget/dock.h +++ b/src/ui/widget/dock.h @@ -12,14 +12,6 @@ #ifndef INKSCAPE_UI_WIDGET_DOCK_H #define INKSCAPE_UI_WIDGET_DOCK_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include "ui/widget/dock-item.h" diff --git a/src/ui/widget/entity-entry.cpp b/src/ui/widget/entity-entry.cpp index c7d5efe29..69173fa25 100644 --- a/src/ui/widget/entity-entry.cpp +++ b/src/ui/widget/entity-entry.cpp @@ -17,10 +17,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/ui/widget/filter-effect-chooser.h b/src/ui/widget/filter-effect-chooser.h index 6092c61a5..0bcf97433 100644 --- a/src/ui/widget/filter-effect-chooser.h +++ b/src/ui/widget/filter-effect-chooser.h @@ -12,14 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/ui/widget/frame.h b/src/ui/widget/frame.h index 55638ad40..a04666651 100644 --- a/src/ui/widget/frame.h +++ b/src/ui/widget/frame.h @@ -10,14 +10,6 @@ #ifndef INKSCAPE_UI_WIDGET_FRAME_H #define INKSCAPE_UI_WIDGET_FRAME_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/imageicon.h b/src/ui/widget/imageicon.h index 8faf13cb1..2ea8b8533 100644 --- a/src/ui/widget/imageicon.h +++ b/src/ui/widget/imageicon.h @@ -12,14 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/ui/widget/imagetoggler.h b/src/ui/widget/imagetoggler.h index df6eb7ded..7b02fa4dc 100644 --- a/src/ui/widget/imagetoggler.h +++ b/src/ui/widget/imagetoggler.h @@ -14,10 +14,6 @@ #include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/insertordericon.h b/src/ui/widget/insertordericon.h index fb3412d3f..bf8ac4fa7 100644 --- a/src/ui/widget/insertordericon.h +++ b/src/ui/widget/insertordericon.h @@ -13,10 +13,11 @@ # include "config.h" #endif -#include #include #include +#include + namespace Inkscape { namespace UI { namespace Widget { diff --git a/src/ui/widget/labelled.h b/src/ui/widget/labelled.h index 5334454bc..88eb3ce19 100644 --- a/src/ui/widget/labelled.h +++ b/src/ui/widget/labelled.h @@ -11,14 +11,6 @@ #ifndef INKSCAPE_UI_WIDGET_LABELLED_H #define INKSCAPE_UI_WIDGET_LABELLED_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include namespace Gtk { diff --git a/src/ui/widget/layertypeicon.cpp b/src/ui/widget/layertypeicon.cpp index 3d6182bf8..672c607e5 100644 --- a/src/ui/widget/layertypeicon.cpp +++ b/src/ui/widget/layertypeicon.cpp @@ -11,10 +11,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -# include -#endif - #include "ui/widget/layertypeicon.h" #include diff --git a/src/ui/widget/licensor.h b/src/ui/widget/licensor.h index c75c5fe9e..b96162589 100644 --- a/src/ui/widget/licensor.h +++ b/src/ui/widget/licensor.h @@ -10,14 +10,6 @@ #ifndef INKSCAPE_UI_WIDGET_LICENSOR_H #define INKSCAPE_UI_WIDGET_LICENSOR_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include class SPDocument; diff --git a/src/ui/widget/notebook-page.h b/src/ui/widget/notebook-page.h index 4f7915423..c11de1b5b 100644 --- a/src/ui/widget/notebook-page.h +++ b/src/ui/widget/notebook-page.h @@ -14,10 +14,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include namespace Gtk { diff --git a/src/ui/widget/object-composite-settings.h b/src/ui/widget/object-composite-settings.h index 5a723a2fd..ae16564e1 100644 --- a/src/ui/widget/object-composite-settings.h +++ b/src/ui/widget/object-composite-settings.h @@ -11,14 +11,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index 0cff25d88..8a1e98a63 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -15,10 +15,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include // for Gtk::RESPONSE_* #include #include diff --git a/src/ui/widget/panel.h b/src/ui/widget/panel.h index 5680cac30..a90060e17 100644 --- a/src/ui/widget/panel.h +++ b/src/ui/widget/panel.h @@ -17,10 +17,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index 98028ed78..72597e4d9 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -14,10 +14,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h index 5d9816e74..8b75b8368 100644 --- a/src/ui/widget/preferences-widget.h +++ b/src/ui/widget/preferences-widget.h @@ -22,10 +22,6 @@ #include #include -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include "ui/widget/spinbutton.h" #include diff --git a/src/ui/widget/rotateable.cpp b/src/ui/widget/rotateable.cpp index 2d7597d7c..5e938dee6 100644 --- a/src/ui/widget/rotateable.cpp +++ b/src/ui/widget/rotateable.cpp @@ -11,10 +11,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h index 0b6a14762..804a6fef6 100644 --- a/src/ui/widget/selected-style.h +++ b/src/ui/widget/selected-style.h @@ -15,10 +15,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #if WITH_GTKMM_3_0 diff --git a/src/ui/widget/spin-scale.h b/src/ui/widget/spin-scale.h index d0447e4a6..50e4fc953 100644 --- a/src/ui/widget/spin-scale.h +++ b/src/ui/widget/spin-scale.h @@ -13,10 +13,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/spin-slider.h b/src/ui/widget/spin-slider.h index 74982ea58..a5999f14f 100644 --- a/src/ui/widget/spin-slider.h +++ b/src/ui/widget/spin-slider.h @@ -14,10 +14,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/spinbutton.h b/src/ui/widget/spinbutton.h index cbe33e8ea..30ffc7d77 100644 --- a/src/ui/widget/spinbutton.h +++ b/src/ui/widget/spinbutton.h @@ -10,14 +10,6 @@ #ifndef INKSCAPE_UI_WIDGET_SPINBUTTON_H #define INKSCAPE_UI_WIDGET_SPINBUTTON_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include namespace Inkscape { diff --git a/src/ui/widget/style-swatch.h b/src/ui/widget/style-swatch.h index 582d2ebb3..0016e0256 100644 --- a/src/ui/widget/style-swatch.h +++ b/src/ui/widget/style-swatch.h @@ -17,10 +17,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/tolerance-slider.cpp b/src/ui/widget/tolerance-slider.cpp index ff525c679..ced811c57 100644 --- a/src/ui/widget/tolerance-slider.cpp +++ b/src/ui/widget/tolerance-slider.cpp @@ -12,10 +12,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/ui/widget/unit-menu.h b/src/ui/widget/unit-menu.h index 2fd25a6a9..f414660f7 100644 --- a/src/ui/widget/unit-menu.h +++ b/src/ui/widget/unit-menu.h @@ -10,14 +10,6 @@ #ifndef INKSCAPE_UI_WIDGET_UNIT_H #define INKSCAPE_UI_WIDGET_UNIT_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include "util/units.h" diff --git a/src/verbs.cpp b/src/verbs.cpp index 5febeeb7c..ea2c06dcf 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -32,10 +32,9 @@ #include #include -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - +// Note that gtkmm headers must be included before gtk+ C headers +// in all files. The same applies for glibmm/glib etc. +// If this is not done, then errors will be generate relating to Glib::Threads being undefined #include #include #include diff --git a/src/widgets/dash-selector.h b/src/widgets/dash-selector.h index 5b9ebfa2b..ec5a1cbd5 100644 --- a/src/widgets/dash-selector.h +++ b/src/widgets/dash-selector.h @@ -14,10 +14,6 @@ # include #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/widgets/desktop-widget.h b/src/widgets/desktop-widget.h index a77d56fc3..489217d9a 100644 --- a/src/widgets/desktop-widget.h +++ b/src/widgets/desktop-widget.h @@ -12,14 +12,6 @@ * ? -2004 */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include "message.h" #include "ui/view/view-widget.h" diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index d60a92b8b..b92b0a474 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -22,10 +22,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index afc4fcfb0..542d16797 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -16,10 +16,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 948c80db3..740ce2b0e 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -24,10 +24,6 @@ #include #include -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include "widgets/swatch-selector.h" #include "sp-pattern.h" #include diff --git a/src/widgets/shrink-wrap-button.cpp b/src/widgets/shrink-wrap-button.cpp index 3558780ed..941a0466c 100644 --- a/src/widgets/shrink-wrap-button.cpp +++ b/src/widgets/shrink-wrap-button.cpp @@ -13,10 +13,6 @@ #include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/widgets/sp-attribute-widget.h b/src/widgets/sp-attribute-widget.h index 4bd6c6959..d9b972201 100644 --- a/src/widgets/sp-attribute-widget.h +++ b/src/widgets/sp-attribute-widget.h @@ -19,10 +19,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/widgets/spw-utilities.cpp b/src/widgets/spw-utilities.cpp index f87889bb1..7030753a5 100644 --- a/src/widgets/spw-utilities.cpp +++ b/src/widgets/spw-utilities.cpp @@ -17,10 +17,6 @@ #include #include -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include diff --git a/src/widgets/stroke-marker-selector.h b/src/widgets/stroke-marker-selector.h index 27ac76d6f..a7ee788b8 100644 --- a/src/widgets/stroke-marker-selector.h +++ b/src/widgets/stroke-marker-selector.h @@ -10,14 +10,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include diff --git a/src/widgets/swatch-selector.h b/src/widgets/swatch-selector.h index c8c9983a6..4b7aa483f 100644 --- a/src/widgets/swatch-selector.h +++ b/src/widgets/swatch-selector.h @@ -1,14 +1,6 @@ #ifndef SEEN_SP_SWATCH_SELECTOR_H #define SEEN_SP_SWATCH_SELECTOR_H -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include class SPDocument; diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 5d52db6f2..d56b91f5e 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -29,10 +29,6 @@ # include "config.h" #endif -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - #include #include #include -- cgit v1.2.3 From 5f42b9187cc50cdc8407e31752f2ae682e6641a8 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 28 Apr 2015 16:26:17 +0200 Subject: Save original text in 'aria-label' attribute for accessibilty reasons. (bzr r14066) --- src/path-chemistry.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 5f6e1495b..988559e30 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -362,7 +362,7 @@ bool sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems) { bool did = false; - + for (; items != NULL; items = items->next) { @@ -488,6 +488,9 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) if (dynamic_cast(item) || dynamic_cast(item)) { // Special treatment for text: convert each glyph to separate path, then group the paths Inkscape::XML::Node *g_repr = xml_doc->createElement("svg:g"); + + Glib::ustring original_text; // To save original text of accessibility. + g_repr->setAttribute("transform", item->getRepr()->attribute("transform")); /* Mask */ gchar *mask_str = (gchar *) item->getRepr()->attribute("mask"); @@ -508,6 +511,8 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); do { + original_text += (gunichar)te_get_layout(item)->characterAt( iter ); + Inkscape::Text::Layout::iterator iter_next = iter; iter_next.nextGlyph(); // iter_next is one glyph ahead from iter if (iter == iter_next) @@ -547,6 +552,11 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) p_repr->setAttribute("style", style_str.c_str()); g_repr->appendChild(p_repr); + + // For accessibility, store original string + if( original_text.size() > 0 ) { + g_repr->setAttribute("aria-label", original_text.c_str() ); + } Inkscape::GC::release(p_repr); if (iter == te_get_layout(item)->end()) -- cgit v1.2.3 From 1b24834a9073b27ffe84dd0a48ebab4ef7cba46f Mon Sep 17 00:00:00 2001 From: mathog <> Date: Tue, 28 Apr 2015 11:11:32 -0700 Subject: enable default pen object for WMF files (bzr r14067) --- src/extension/internal/wmf-inout.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index 30a028eec..3ab7a4e89 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -3085,8 +3085,12 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) 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].style.stroke_width.value = 1.0; // will be reset to something reasonable once WMF draying size is known + d.dc[0].style.stroke_width.value = 1.0; // will be reset to something reasonable once WMF drawing size is known d.dc[0].style.stroke.value.color.set( 0, 0, 0 ); + d.dc[0].stroke_set = true; + + // Default brush is none - no fill. WMF files that do not specify a brush are unlikely to look very good! + d.dc[0].fill_set = false; 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 -- cgit v1.2.3 From 6839dc4380abd4e892cf65600ffe4c63ed91eb67 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Tue, 28 Apr 2015 19:44:34 -0400 Subject: fix tangent sign problems in path outline code (bzr r14068) --- src/helper/geom-pathstroke.cpp | 159 ++++++++++++++++++++++++----------------- 1 file changed, 94 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index eb0c432c6..6b35bb290 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -127,87 +127,104 @@ static Circle touching_circle( D2 const &curve, double t, double tol=0.0 namespace { -// Join functions may: -// - inspect any curve of the current path -// - append any type of curve to the current path -// - inspect the outgoing path -// -// Join functions must: -// - append the outgoing curve -// OR -// - end at outgoing.finalPoint - -typedef void join_func(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width); - -void bevel_join(Geom::Path& res, Geom::Curve const& outgoing, double /*miter*/, double /*width*/) +// Internal data structure + +struct join_data +{ + join_data(Geom::Path &_res, Geom::Path const&_outgoing, Geom::Point _in_tang, Geom::Point _out_tang, double _miter, double _width) + : res(_res), outgoing(_outgoing), in_tang(_in_tang) + , out_tang(_out_tang), miter(_miter), width(_width) {} + + // I/O + Geom::Path &res; + Geom::Path const& outgoing; + + // input tangents + Geom::Point in_tang; + Geom::Point out_tang; + + // line parameters + double miter; + double width; +}; + +// Join functions must append the outgoing path + +typedef void join_func(join_data jd); + +void bevel_join(join_data jd) { - res.appendNew(outgoing.initialPoint()); - res.append(outgoing); + jd.res.appendNew(jd.outgoing.initialPoint()); + jd.res.append(jd.outgoing); } -void round_join(Geom::Path& res, Geom::Curve const& outgoing, double /*miter*/, double width) +void round_join(join_data jd) { - res.appendNew(width, width, 0, false, width <= 0, outgoing.initialPoint()); - res.append(outgoing); + jd.res.appendNew(jd.width, jd.width, 0, false, jd.width <= 0, jd.outgoing.initialPoint()); + jd.res.append(jd.outgoing); } -void miter_join_internal(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width, bool clip) +void miter_join_internal(join_data jd, bool clip) { - Geom::Curve const& incoming = res.back(); - Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); - Geom::Point tang2 = outgoing.unitTangentAt(0); - Geom::Point p = Geom::intersection_point(incoming.finalPoint(), tang1, outgoing.initialPoint(), tang2); + using namespace Geom; + + Curve const& incoming = jd.res.back(); + Curve const& outgoing = jd.outgoing.front(); + Path &res = jd.res; + double width = jd.width, miter = jd.miter; + + Point tang1 = jd.in_tang; + Point tang2 = jd.out_tang; + Point p = intersection_point(incoming.finalPoint(), tang1, outgoing.initialPoint(), tang2); bool satisfied = false; bool inc_ls = res.back_open().degreesOfFreedom() <= 4; if (p.isFinite()) { // check size of miter - Geom::Point point_on_path = incoming.finalPoint() + Geom::rot90(tang1)*width; - satisfied = Geom::distance(p, point_on_path) <= miter * 2.0 * width; + Point point_on_path = incoming.finalPoint() + rot90(tang1)*width; + satisfied = distance(p, point_on_path) <= miter * 2.0 * width; if (satisfied) { // miter OK, check to see if we can do a relocation if (inc_ls) { res.setFinal(p); } else { - res.appendNew(p); + res.appendNew(p); } } else if (clip) { // miter needs clipping, find two points - Geom::Point bisector_versor = Geom::Line(point_on_path, p).versor(); - Geom::Point point_limit = point_on_path + miter * 2.0 * width * bisector_versor; + Point bisector_versor = Line(point_on_path, p).versor(); + Point point_limit = point_on_path + miter * 2.0 * width * bisector_versor; - Geom::Point p1 = Geom::intersection_point(incoming.finalPoint(), tang1, point_limit, bisector_versor.cw()); - Geom::Point p2 = Geom::intersection_point(outgoing.initialPoint(), tang2, point_limit, bisector_versor.cw()); + Point p1 = intersection_point(incoming.finalPoint(), tang1, point_limit, bisector_versor.cw()); + Point p2 = intersection_point(outgoing.initialPoint(), tang2, point_limit, bisector_versor.cw()); if (inc_ls) { res.setFinal(p1); } else { - res.appendNew(p1); + res.appendNew(p1); } - res.appendNew(p2); + res.appendNew(p2); } } - res.appendNew(outgoing.initialPoint()); + res.appendNew(outgoing.initialPoint()); // check if we can do another relocation bool out_ls = outgoing.degreesOfFreedom() <= 4; - if ( (satisfied || clip) && out_ls) { + if ((satisfied || clip) && out_ls) { res.setFinal(outgoing.finalPoint()); } else { res.append(outgoing); } -} -void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width) { - miter_join_internal( res, outgoing, miter, width, false ); + // either way, add the rest of the path + res.insert(res.end(), ++jd.outgoing.begin(), jd.outgoing.end()); } -void miter_clip_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width) { - miter_join_internal( res, outgoing, miter, width, true ); -} +void miter_join(join_data jd) { miter_join_internal(jd, false); } +void miter_clip_join(join_data jd) { miter_join_internal(jd, true); } Geom::Point pick_solution(Geom::Point points[2], Geom::Point tang2, Geom::Point endPt) { @@ -225,15 +242,18 @@ Geom::Point pick_solution(Geom::Point points[2], Geom::Point tang2, Geom::Point return sol; } -void extrapolate_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width) +void extrapolate_join(join_data jd) { using namespace Geom; + Geom::Path &res = jd.res; Geom::Curve const& incoming = res.back(); + Geom::Curve const& outgoing = jd.outgoing.front(); Geom::Point startPt = incoming.finalPoint(); Geom::Point endPt = outgoing.initialPoint(); - Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); - Geom::Point tang2 = outgoing.unitTangentAt(0); + Geom::Point tang1 = jd.in_tang; + Geom::Point tang2 = jd.out_tang; + double width = jd.width, miter = jd.miter; Geom::Circle circle1 = Geom::touching_circle(Geom::reverse(incoming.toSBasis()), 0.); Geom::Circle circle2 = Geom::touching_circle(outgoing.toSBasis(), 0); @@ -280,7 +300,7 @@ void extrapolate_join(Geom::Path& res, Geom::Curve const& outgoing, double miter if (solutions != 2) // no solutions available, fall back to miter - return miter_clip_join(res, outgoing, miter, width); + return miter_clip_join(jd); // We have a solution, thus sol is defined. p1 = sol; @@ -381,14 +401,19 @@ void extrapolate_join(Geom::Path& res, Geom::Curve const& outgoing, double miter // Straight line segment: res.appendNew(outgoing.finalPoint()); } - + + // add the rest of the path + res.insert(res.end(), ++jd.outgoing.begin(), jd.outgoing.end()); + delete arc1; delete arc2; } -void join_inside(Geom::Path& res, Geom::Curve const& outgoing) +void join_inside(join_data jd) { + Geom::Path &res = jd.res; Geom::Curve const& incoming = res.back_open(); + Geom::Curve const& outgoing = jd.outgoing.front(); Geom::Crossings cross = Geom::crossings(incoming, outgoing); if (!cross.empty()) { @@ -406,28 +431,35 @@ void join_inside(Geom::Path& res, Geom::Curve const& outgoing) res.appendNew(outgoing.initialPoint()); res.append(outgoing); } + + // add the rest of the path + res.insert(res.end(), ++jd.outgoing.begin(), jd.outgoing.end()); } -bool decide(Geom::Curve const& incoming, Geom::Curve const& outgoing) +void tangents(Geom::Point* tang, Geom::Curve const& incoming, Geom::Curve const& outgoing) { Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); Geom::Point tang2 = outgoing.unitTangentAt(0.); - return (Geom::cross(tang1, tang2) < 0); + tang[0] = tang1, tang[1] = tang2; } -void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, bool on_outside, double miter, Inkscape::LineJoinType join) +void outline_helper(Geom::Path &res, Geom::Path const& temp, Geom::Point in_tang, Geom::Point out_tang, double width, double miter, Inkscape::LineJoinType join) { - if (res.size() == 0 || to_add.size() == 0) + if (res.size() == 0 || temp.size() == 0) return; - Geom::Curve const& outgoing = to_add[0]; + Geom::Curve const& outgoing = temp.front(); if (Geom::are_near(res.finalPoint(), outgoing.initialPoint())) { // if the points are /that/ close, just ignore this one - res.setFinal(outgoing.initialPoint()); - res.append(outgoing); + res.setFinal(temp.initialPoint()); + res.append(temp); return; } + join_data jd(res, temp, in_tang, out_tang, miter, width); + + bool on_outside = (Geom::cross(in_tang, out_tang) < 0); + if (on_outside) { join_func *jf; switch (join) { @@ -446,9 +478,9 @@ void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, boo default: jf = &miter_join; } - jf(res, outgoing, miter, width); + jf(jd); } else { - join_inside(res, outgoing); + join_inside(jd); } } @@ -705,6 +737,7 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin Geom::Point tang1 = input[0].unitTangentAt(0); Geom::Point start = input.initialPoint() + tang1 * width; Geom::Path temp; + Geom::Point tang[2]; res.start(start); @@ -720,20 +753,16 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin if (u == 0) { res.append(temp); } else { - bool on_outside = decide(input[u-1], input[u]); - outline_helper(res, temp, width, on_outside, miter, join); - if (temp.size() > 0) - res.insert(res.end(), ++temp.begin(), temp.end()); + tangents(tang, input[u-1], input[u]); + outline_helper(res, temp, tang[0], tang[1], width, miter, join); } // odd number of paths if (u < k - 1) { temp = Geom::Path(); offset_curve(temp, &input[u+1], width); - bool on_outside = decide(input[u], input[u+1]); - outline_helper(res, temp, width, on_outside, miter, join); - if (temp.size() > 0) - res.insert(res.end(), ++temp.begin(), temp.end()); + tangents(tang, input[u], input[u+1]); + outline_helper(res, temp, tang[0], tang[1], width, miter, join); } } @@ -744,8 +773,8 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin temp.append(c1); Geom::Path temp2; temp2.append(c2); - bool on_outside = decide(input.back(), input.front()); - outline_helper(temp, temp2, width, on_outside, miter, join); + tangents(tang, input.back(), input.front()); + outline_helper(temp, temp2, tang[0], tang[1], width, miter, join); res.erase(res.begin()); res.erase_last(); // -- cgit v1.2.3 From 5a3f7c27245b1a1858036210efbde031d199ebdc Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Tue, 28 Apr 2015 21:10:13 -0400 Subject: Catch more intersections (can still be improved somewhat I think) (bzr r14069) --- src/helper/geom-pathstroke.cpp | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 6b35bb290..a33fb005b 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -412,31 +412,27 @@ void extrapolate_join(join_data jd) void join_inside(join_data jd) { Geom::Path &res = jd.res; - Geom::Curve const& incoming = res.back_open(); - Geom::Curve const& outgoing = jd.outgoing.front(); - Geom::Crossings cross = Geom::crossings(incoming, outgoing); - - if (!cross.empty()) { - // yeah if we could avoid allocing that'd be great - Geom::Curve *d1 = incoming.portion(0., cross[0].ta); - res.erase_last(); - res.append(*d1); - delete d1; - - Geom::Curve *d2 = outgoing.portion(cross[0].tb, 1.); - res.setFinal(d2->initialPoint()); - res.append(*d2); - delete d2; + Geom::Path const& temp = jd.outgoing; + Geom::Crossings cross = Geom::crossings(res, temp); + + if (cross.size() == 1) { + Geom::Path d1 = res.portion(0., cross[0].ta); + Geom::Path d2 = temp.portion(cross[0].tb, temp.size()); + + // Watch for bugs in 2geom crossing regarding severe inflection points + res.clear(); + res.append(d1); + res.setFinal(d2.initialPoint()); + res.append(d2); } else { - res.appendNew(outgoing.initialPoint()); - res.append(outgoing); + res.appendNew(temp.initialPoint()); + res.append(temp); + // add the rest of the path + res.insert(res.end(), ++jd.outgoing.begin(), jd.outgoing.end()); } - - // add the rest of the path - res.insert(res.end(), ++jd.outgoing.begin(), jd.outgoing.end()); } -void tangents(Geom::Point* tang, Geom::Curve const& incoming, Geom::Curve const& outgoing) +void tangents(Geom::Point tang[2], Geom::Curve const& incoming, Geom::Curve const& outgoing) { Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); Geom::Point tang2 = outgoing.unitTangentAt(0.); -- cgit v1.2.3 From 658291159764636339acd95389827eb8ae159ecb Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Tue, 28 Apr 2015 21:25:47 -0400 Subject: Increase precision (long thin paths had a ton of width variance), fix logic error (bzr r14070) --- src/helper/geom-pathstroke.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index a33fb005b..292ba3044 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -427,8 +427,6 @@ void join_inside(join_data jd) } else { res.appendNew(temp.initialPoint()); res.append(temp); - // add the rest of the path - res.insert(res.end(), ++jd.outgoing.begin(), jd.outgoing.end()); } } @@ -607,7 +605,7 @@ void offset_quadratic(Geom::Path& p, Geom::QuadraticBezier const& bez, double wi void offset_curve(Geom::Path& res, Geom::Curve const* current, double width) { - double const tolerance = 0.005; + double const tolerance = 0.0025; size_t levels = 8; if (current->isDegenerate()) return; // don't do anything -- cgit v1.2.3 From c9402117b96cbde93c13cc52f1596b723861e8ec Mon Sep 17 00:00:00 2001 From: jabiertxof Date: Wed, 29 Apr 2015 11:25:54 -0400 Subject: Fix a bug linking a path parameter to a transformed element (bzr r14071) --- src/live_effects/parameter/path.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index ba95affd9..32e82ff8c 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -427,7 +427,13 @@ PathParam::paste_param_path(const char *svgd) if (svgd && *svgd) { // remove possible link to path remove_link(); - + SPItem * item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); + if (item != NULL) { + Geom::PathVector path_clipboard = sp_svg_read_pathv(svgd); + path_clipboard *= item->i2doc_affine().inverse(); + svgd = sp_svg_write_path( path_clipboard ); + } + param_write_to_repr(svgd); signal_path_pasted.emit(); } -- cgit v1.2.3 From 556a53bca1b75b43730da749313f8a6827f2461d Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 29 Apr 2015 19:24:49 +0200 Subject: Fix regression: Update default font-family if nothing is selected on canvas. (bzr r14072) --- src/libnrtype/FontFactory.h | 2 +- src/widgets/text-toolbar.cpp | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/libnrtype/FontFactory.h b/src/libnrtype/FontFactory.h index bd5a4460c..4c8c2cb29 100644 --- a/src/libnrtype/FontFactory.h +++ b/src/libnrtype/FontFactory.h @@ -68,7 +68,7 @@ public: }; // Map type for gathering UI family and style names -typedef std::map > FamilyToStylesMap; +// typedef std::map > FamilyToStylesMap; class font_factory { public: diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 3d2e6eef8..ec011fffd 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -162,11 +162,17 @@ static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GOb fontlister->fill_css( css ); SPDesktop *desktop = SP_ACTIVE_DESKTOP; - sp_desktop_set_style (desktop, css, true, true); // Results in selection change called twice. + if( desktop->getSelection()->isEmpty() ) { + // Update default + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->mergeStyle("/tools/text/style", css); + } else { + // If there is a selection, update + sp_desktop_set_style (desktop, css, true, true); // Results in selection change called twice. + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, + _("Text: Change font family")); + } sp_repr_css_attr_unref (css); - - DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, - _("Text: Change font family")); } // unfreeze -- cgit v1.2.3 From f4c56b0f307b4f0f2ab499e7f10cf2a9644688c4 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Wed, 29 Apr 2015 16:23:05 -0400 Subject: Better solution picking (bzr r14073) --- src/helper/geom-pathstroke.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 292ba3044..1df17acf5 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -415,9 +415,28 @@ void join_inside(join_data jd) Geom::Path const& temp = jd.outgoing; Geom::Crossings cross = Geom::crossings(res, temp); - if (cross.size() == 1) { - Geom::Path d1 = res.portion(0., cross[0].ta); - Geom::Path d2 = temp.portion(cross[0].tb, temp.size()); + int solution = -1; // lol, really hope there aren't more than INT_MAX crossings + if (cross.size() == 1) solution = 0; + else if (cross.size() > 1) { + // I am not sure how well this will work -- we pick the join node closest + // to the cross point of the paths + Geom::Point original = res.finalPoint()+Geom::rot90(jd.in_tang)*jd.width; + Geom::Coord trial = Geom::L2(res.pointAt(cross[0].ta)-original); + solution = 0; + for (size_t i = 1; i < cross.size(); ++i) { + //printf("Trying %d\n", i); + Geom::Coord test = Geom::L2(res.pointAt(cross[i].ta)-original); + if (test < trial) { + trial = test; + solution = i; + //printf("Found improved solution: %f\n", trial); + } + } + } + + if (solution != -1) { + Geom::Path d1 = res.portion(0., cross[solution].ta); + Geom::Path d2 = temp.portion(cross[solution].tb, temp.size()); // Watch for bugs in 2geom crossing regarding severe inflection points res.clear(); -- cgit v1.2.3 From 71fcf846f0cb03e8f73ef72f1174b7e05f03d1c0 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Wed, 29 Apr 2015 23:03:20 +0200 Subject: corrected test file (bzr r13922.1.20) --- src/object-test.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/object-test.h b/src/object-test.h index 06363c372..4f0be3251 100644 --- a/src/object-test.h +++ b/src/object-test.h @@ -204,7 +204,8 @@ public: assert(n_group != NULL); begin = clock(); - sp_item_group_ungroup(n_group, NULL, false); + std::vector ch; + sp_item_group_ungroup(n_group, ch, false); end = clock(); std::cout << "Took " << double(end - begin) / double(CLOCKS_PER_SEC) << " seconds to ungroup a with " << num_elements << " elements\n"; -- cgit v1.2.3 From 7aac87804be5fe99db56130848d94da4d07e2382 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Wed, 29 Apr 2015 23:30:20 +0200 Subject: uint -> unsigned int (bzr r14075) --- src/selection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/selection.cpp b/src/selection.cpp index b2fb6447e..017089ec5 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -513,7 +513,7 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { return object; } -uint Selection::numberOfLayers() { +unsigned int Selection::numberOfLayers() { std::vector const items = const_cast(this)->itemList(); std::set layers; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { -- cgit v1.2.3 From c848ff33a5f3fd7eabfe83604bb42bb5e705c0b4 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 30 Apr 2015 00:29:17 +0200 Subject: unsigned int -> size_t (bzr r14076) --- src/selection.cpp | 4 ++-- src/selection.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/selection.cpp b/src/selection.cpp index 017089ec5..53772c381 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -513,7 +513,7 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { return object; } -unsigned int Selection::numberOfLayers() { +size_t Selection::numberOfLayers() { std::vector const items = const_cast(this)->itemList(); std::set layers; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { @@ -523,7 +523,7 @@ unsigned int Selection::numberOfLayers() { return layers.size(); } -guint Selection::numberOfParents() { +size_t Selection::numberOfParents() { std::vector const items = const_cast(this)->itemList(); std::set parents; for ( std::vector::const_iterator iter=items.begin();iter!=items.end();iter++ ) { diff --git a/src/selection.h b/src/selection.h index 7ac0f40f3..952dde51d 100644 --- a/src/selection.h +++ b/src/selection.h @@ -259,10 +259,10 @@ public: std::list const box3DList(Persp3D *persp = NULL); /** Returns the number of layers in which there are selected objects. */ - unsigned int numberOfLayers(); + size_t numberOfLayers(); /** Returns the number of parents to which the selected objects belong. */ - unsigned int numberOfParents(); + size_t numberOfParents(); /** Returns the bounding rectangle of the selection. */ Geom::OptRect bounds(SPItem::BBoxType type) const; -- cgit v1.2.3 From ce75639406465cb3e60b097d70defa51bfdc10a6 Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Wed, 29 Apr 2015 18:52:55 -0400 Subject: cmake: Include missing source file in build rules (bzr r14070.1.4) --- src/libuemf/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/libuemf/CMakeLists.txt b/src/libuemf/CMakeLists.txt index f5a97f212..922d404a6 100644 --- a/src/libuemf/CMakeLists.txt +++ b/src/libuemf/CMakeLists.txt @@ -4,6 +4,7 @@ set(libuemf_SRC uemf.c uemf_endian.c uemf_print.c + uemf_safe.c uemf_utf.c uwmf.c uwmf_endian.c -- cgit v1.2.3 From e5abbfaf9a7767bff95f45bdbfed4999ba894a99 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Wed, 29 Apr 2015 22:38:25 -0400 Subject: Fix dbus build (bzr r14077) --- src/extension/dbus/document-interface.cpp | 46 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 4fde6885f..d64bdbc5c 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -186,10 +186,10 @@ selection_get_center_y (Inkscape::Selection *sel){ * know we never bothered to implement it seperatly. Although * they might see the selection box flicker if used in a loop. */ -const GSList * +std::vector selection_swap(Inkscape::Selection *sel, gchar *name, GError **error) { - const GSList *oldsel = g_slist_copy((GSList *)sel->list()); + std::vector oldsel = sel->list(); sel->set(get_object_by_name(sel->layers()->getDocument(), name, error)); return oldsel; @@ -199,9 +199,11 @@ selection_swap(Inkscape::Selection *sel, gchar *name, GError **error) * See selection_swap, above */ void -selection_restore(Inkscape::Selection *sel, const GSList * oldsel) +selection_restore(Inkscape::Selection *sel, std::vector oldsel) { - sel->setList(oldsel); + // ... setList used to work here + sel->clear(); + sel->add(oldsel.begin(), oldsel.end()); } /* @@ -708,8 +710,8 @@ gboolean document_interface_move (DocumentInterface *doc_interface, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(doc_interface->target.getSelection(), name, error); - if (!oldsel) + std::vector oldsel = selection_swap(doc_interface->target.getSelection(), name, error); + if (oldsel.empty()) return FALSE; sp_selection_move (doc_interface->target.getSelection(), x, 0 - y); selection_restore(doc_interface->target.getSelection(), oldsel); @@ -720,8 +722,8 @@ gboolean document_interface_move_to (DocumentInterface *doc_interface, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(doc_interface->target.getSelection(), name, error); - if (!oldsel) + std::vector oldsel = selection_swap(doc_interface->target.getSelection(), name, error); + if (oldsel.empty()) return FALSE; Inkscape::Selection * sel = doc_interface->target.getSelection(); sp_selection_move (doc_interface->target.getSelection(), x - selection_get_center_x(sel), @@ -734,8 +736,8 @@ gboolean document_interface_object_to_path (DocumentInterface *doc_interface, char *shape, GError **error) { - const GSList *oldsel = selection_swap(doc_interface->target.getSelection(), shape, error); - if (!oldsel) + std::vector oldsel = selection_swap(doc_interface->target.getSelection(), shape, error); + if (oldsel.empty()) return FALSE; dbus_call_verb (doc_interface, SP_VERB_OBJECT_TO_CURVE, error); selection_restore(doc_interface->target.getSelection(), oldsel); @@ -849,8 +851,8 @@ gboolean document_interface_move_to_layer (DocumentInterface *doc_interface, gchar *shape, gchar *layerstr, GError **error) { - const GSList *oldsel = selection_swap(doc_interface->target.getSelection(), shape, error); - if (!oldsel) + std::vector oldsel = selection_swap(doc_interface->target.getSelection(), shape, error); + if (oldsel.empty()) return FALSE; document_interface_selection_move_to_layer(doc_interface, layerstr, error); @@ -1085,15 +1087,15 @@ void document_interface_update(DocumentInterface *doc_interface, GError ** error gboolean document_interface_selection_get(DocumentInterface *doc_interface, char ***out, GError ** /*error*/) { Inkscape::Selection * sel = doc_interface->target.getSelection(); - GSList const *oldsel = sel->list(); + std::vector oldsel = sel->list(); - int size = g_slist_length((GSList *) oldsel); + int size = oldsel.size(); *out = g_new0 (char *, size + 1); int i = 0; - for (GSList const *iter = oldsel; iter != NULL; iter = iter->next) { - (*out)[i] = g_strdup(SP_OBJECT(iter->data)->getRepr()->attribute("id")); + for (std::vector::iterator iter = oldsel.begin(), e = oldsel.end(); iter != e; ++iter) { + (*out)[i] = g_strdup((*iter)->getId()); i++; } (*out)[i] = NULL; @@ -1426,23 +1428,21 @@ gboolean dbus_send_ping (SPDesktop* desk, SPItem *item) gboolean document_interface_get_children (DocumentInterface *doc_interface, char *name, char ***out, GError **error) { - SPItem* parent=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); + SPItem* parent=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); + std::vector children = parent->childList(false); - GSList const *children = parent->childList(false); - - int size = g_slist_length((GSList *) children); + int size = children.size(); *out = g_new0 (char *, size + 1); int i = 0; - for (GSList const *iter = children; iter != NULL; iter = iter->next) { - (*out)[i] = g_strdup(SP_OBJECT(iter->data)->getRepr()->attribute("id")); + for (std::vector::iterator iter = children.begin(), e = children.end(); iter != e; ++iter) { + (*out)[i] = g_strdup((*iter)->getId()); i++; } (*out)[i] = NULL; return TRUE; - } -- cgit v1.2.3 From 6307c00b5774db5e914415127b302cca5e21345b Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 1 May 2015 02:26:56 +0200 Subject: Fixed crash bug due to some overlooked function changed in the recent merge. Also fixed the layer ordering in the widget, which was messed up by the same bug in a way i haven't quite sorted out (so the fact that this patch fixed it is quite a mystery, but i won't complain) (bzr r14079) --- src/selection-chemistry.cpp | 12 ++++++------ src/splivarot.cpp | 2 +- src/xml/repr-util.cpp | 17 +++++++++++------ src/xml/repr.h | 3 ++- 4 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 7255e80cb..c30d22503 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -459,7 +459,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) // sorting items from different parents sorts each parent's subset without possibly mixing // them, just what we need - sort(reprs.begin(),reprs.end(),sp_repr_compare_position); + sort(reprs.begin(),reprs.end(),sp_repr_compare_position_bool); std::vector newsel; @@ -677,7 +677,7 @@ void sp_edit_invert_in_all_layers(SPDesktop *desktop) static void sp_selection_group_impl(std::vector p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { - sort(p.begin(),p.end(),sp_repr_compare_position); + sort(p.begin(),p.end(),sp_repr_compare_position_bool); // Remember the position and parent of the topmost object. gint topmost = p.back()->position(); @@ -1002,7 +1002,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto } std::vector rl(selection->reprList()); - sort(rl.begin(),rl.end(),sp_repr_compare_position); + sort(rl.begin(),rl.end(),sp_repr_compare_position_bool); for (std::vector::const_iterator l=rl.begin(); l!=rl.end();l++) { Inkscape::XML::Node *repr =(*l); @@ -1086,7 +1086,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des } std::vector rl(selection->reprList()); - sort(rl.begin(),rl.end(),sp_repr_compare_position); + sort(rl.begin(),rl.end(),sp_repr_compare_position_bool); for (std::vector::const_reverse_iterator l=rl.rbegin();l!=rl.rend();l++) { gint minpos; @@ -2549,7 +2549,7 @@ void sp_selection_clone(SPDesktop *desktop) selection->clear(); // sorting items from different parents sorts each parent's subset without possibly mixing them, just what we need - sort(reprs.begin(),reprs.end(),sp_repr_compare_position); + sort(reprs.begin(),reprs.end(),sp_repr_compare_position_bool); std::vector newsel; @@ -3709,7 +3709,7 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) std::vector p(selection->reprList()); - sort(p.begin(),p.end(),sp_repr_compare_position); + sort(p.begin(),p.end(),sp_repr_compare_position_bool); selection->clear(); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index f61a30462..bec300936 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -688,7 +688,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool // find out the bottom object std::vector sorted(selection->reprList()); - sort(sorted.begin(),sorted.end(),sp_repr_compare_position); + sort(sorted.begin(),sorted.end(),sp_repr_compare_position_bool); source = doc->getObjectByRepr(sorted.front()); } diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index 3858f08a7..305f1b292 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -260,7 +260,7 @@ gchar const *sp_xml_ns_prefix_uri(gchar const *prefix) * -1 first object's position is less than the second * @todo Rewrite this function's description to be understandable */ -bool sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second) +int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second) { int p1, p2; if (first->parent() == second->parent()) { @@ -277,9 +277,9 @@ bool sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::N g_assert(ancestor != NULL); if (ancestor == first) { - return false; + return 1; } else if (ancestor == second) { - return true; + return -1; } else { Inkscape::XML::Node const *to_first = AncetreFils(first, ancestor); Inkscape::XML::Node const *to_second = AncetreFils(second, ancestor); @@ -289,9 +289,9 @@ bool sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::N } } - if (p1 > p2) return false; - if (p1 < p2) return true; - return false; + if (p1 > p2) return 1; + if (p1 < p2) return -1; + return 0; /* effic: Assuming that the parent--child relationship is consistent (i.e. that the parent really does contain first and second among @@ -310,6 +310,11 @@ bool sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::N pjrm */ } +bool sp_repr_compare_position_bool(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second){ + return sp_repr_compare_position_bool(first, second)<0; +} + + /** * Find an element node using an unique attribute. * diff --git a/src/xml/repr.h b/src/xml/repr.h index fbe25ec12..17763195a 100644 --- a/src/xml/repr.h +++ b/src/xml/repr.h @@ -121,7 +121,8 @@ unsigned sp_repr_set_point(Inkscape::XML::Node *repr, char const *key, Geom::Poi unsigned sp_repr_get_point(Inkscape::XML::Node *repr, char const *key, Geom::Point *val); //c++-style comparison : returns (bool)(a Date: Sat, 2 May 2015 01:08:34 +0200 Subject: Fix segfault due to an infinite recursion (due to a typo) (bzr r14083) --- src/xml/repr-util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index 305f1b292..4cbe930a1 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -311,7 +311,7 @@ int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::No } bool sp_repr_compare_position_bool(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second){ - return sp_repr_compare_position_bool(first, second)<0; + return sp_repr_compare_position(first, second)<0; } -- cgit v1.2.3 From fee6f2b2bd4ade26b957f91de04d45c38541b05a Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 2 May 2015 03:14:58 +0200 Subject: fixed selection after ungroup fixed some regression with displacement of clones of clones when ungrouping (test case: icons.svg) (bzr r14084) --- src/sp-item-group.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 9bd42665d..72cd5d7fa 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -375,7 +375,7 @@ void sp_item_group_ungroup_handle_clones(SPItem *parent, Geom::Affine const g) { for(std::list::const_iterator refd=parent->hrefList.begin();refd!=parent->hrefList.end();refd++){ SPItem *citem = dynamic_cast(*refd); - if (citem) { + if (citem && !citem->cloned) { SPUse *useitem = dynamic_cast(citem); if (useitem && useitem->get_original() == parent) { Geom::Affine ctrans; @@ -541,15 +541,12 @@ sp_item_group_ungroup (SPGroup *group, std::vector &children, bool do_d if (item) { item->doWriteTransform(repr, item->transform, NULL, false); + children.insert(children.begin(),item); } else { g_assert_not_reached(); } Inkscape::GC::release(repr); - if (!children.empty() && item) { - children.insert(children.begin(),item); - } - items = g_slist_remove (items, items->data); } -- cgit v1.2.3 From 280053e5ddfcdf158f62d2d6a72681b3092d2168 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 2 May 2015 03:47:39 +0200 Subject: Fixed comparison function used in sorts (bzr r14085) --- src/selection-chemistry.cpp | 6 +++--- src/seltrans.cpp | 2 +- src/sp-object.cpp | 4 ++++ src/sp-object.h | 1 + src/ui/clipboard.cpp | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index c30d22503..68adf5381 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -326,7 +326,7 @@ static void sp_selection_copy_impl(std::vector const &items, std::vecto { // Sort items: std::vector sorted_items(items); - sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position); + sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool); // Copy item reprs: for (std::vector::const_iterator i = sorted_items.begin(); i != sorted_items.end(); i++) { @@ -3245,7 +3245,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) std::vector items (selection->itemList()); - sort(items.begin(),items.end(),sp_object_compare_position); + sort(items.begin(),items.end(),sp_object_compare_position_bool); // bottommost object, after sorting SPObject *parent = items[0]->parent; @@ -3836,7 +3836,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ std::vector items(selection->itemList()); - sort(items.begin(),items.end(),sp_object_compare_position); + sort(items.begin(),items.end(),sp_object_compare_position_bool); // See lp bug #542004 selection->clear(); diff --git a/src/seltrans.cpp b/src/seltrans.cpp index bfb8d53f1..f7562923f 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -529,7 +529,7 @@ void Inkscape::SelTrans::stamp() } else { /* Build cache */ l = selection->itemList(); - sort(l.begin(),l.end(),sp_object_compare_position); + sort(l.begin(),l.end(),sp_object_compare_position_bool); _stamp_cache = l; } diff --git a/src/sp-object.cpp b/src/sp-object.cpp index d4b8a15c0..0bb8c240f 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -357,6 +357,10 @@ int sp_object_compare_position(SPObject const *first, SPObject const *second) return result; } +bool sp_object_compare_position_bool(SPObject const *first, SPObject const *second){ + return sp_object_compare_position(first,second)<0; +} + SPObject *SPObject::appendChildRepr(Inkscape::XML::Node *repr) { if ( !cloned ) { diff --git a/src/sp-object.h b/src/sp-object.h index f5d47be05..7bc02fad5 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -876,6 +876,7 @@ public: * -1 first object's position is less than the second \endverbatim */ int sp_object_compare_position(SPObject const *first, SPObject const *second); +bool sp_object_compare_position_bool(SPObject const *first, SPObject const *second); #endif // SP_OBJECT_H_SEEN diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index a3620b754..d6cf1f980 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -674,7 +674,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) // copy the representation of the items std::vector sorted_items(itemlist); - sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position); + sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool); for(std::vector::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ SPItem *item = *i; -- cgit v1.2.3 From 2f156df97e50f3a1fa2ddc994ddb24dce76a77f2 Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Fri, 1 May 2015 22:25:08 -0400 Subject: bzrignore: Fix *.cmake ignorance Only certain .cmake files should be ignored (bzr r14086) --- src/extension/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index 47292fd97..d1104f3cc 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -57,6 +57,7 @@ set(extension_SRC internal/vsd-input.cpp internal/wmf-inout.cpp internal/wmf-print.cpp + internal/wpg-input.cpp internal/filter/filter-all.cpp internal/filter/filter-file.cpp @@ -142,6 +143,7 @@ set(extension_SRC internal/vsd-input.h internal/wmf-inout.h internal/wmf-print.h + internal/wpg-input.h ) if(WIN32) -- cgit v1.2.3 From d990da7606e88039bbb5b133559b4b1b201a1363 Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Sat, 2 May 2015 02:09:38 -0400 Subject: sp-text: Whitespace cleanup (bzr r14088) --- src/sp-text.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/sp-text.cpp b/src/sp-text.cpp index 0dca42bb4..d351e58e3 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -149,7 +149,7 @@ void SPText::remove_child(Inkscape::XML::Node *rch) { void SPText::update(SPCtx *ctx, guint flags) { unsigned childflags = (flags & SP_OBJECT_MODIFIED_CASCADE); if (flags & SP_OBJECT_MODIFIED_FLAG) { - childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } // Create temporary list of children @@ -519,7 +519,7 @@ unsigned SPText::_buildLayoutInput(SPObject *root, Inkscape::Text::Layout::Optio } } } - + if (SP_IS_TEXT(root)) { SP_TEXT(root)->attributes.mergeInto(&optional_attrs, parent_optional_attrs, parent_attrs_offset, true, true); if (SP_TEXT(root)->attributes.getTextLength()->_set) { // set textLength on the entire layout, see note in TNG-Layout.h @@ -571,7 +571,7 @@ unsigned SPText::_buildLayoutInput(SPObject *root, Inkscape::Text::Layout::Optio child_attrs_offset--; } } - + for (SPObject *child = root->firstChild() ; child ; child = child->getNext() ) { SPString *str = dynamic_cast(child); if (str) { @@ -691,15 +691,15 @@ bool TextTagAttributes::readSingleAttribute(unsigned key, gchar const *value) case SP_ATTR_DX: attr_vector = &attributes.dx; break; case SP_ATTR_DY: attr_vector = &attributes.dy; break; case SP_ATTR_ROTATE: attr_vector = &attributes.rotate; break; - case SP_ATTR_TEXTLENGTH: - attributes.textLength.readOrUnset(value); - return true; + case SP_ATTR_TEXTLENGTH: + attributes.textLength.readOrUnset(value); + return true; break; - case SP_ATTR_LENGTHADJUST: - attributes.lengthAdjust = (value && !strcmp(value, "spacingAndGlyphs")? - Inkscape::Text::Layout::LENGTHADJUST_SPACINGANDGLYPHS : + case SP_ATTR_LENGTHADJUST: + attributes.lengthAdjust = (value && !strcmp(value, "spacingAndGlyphs")? + Inkscape::Text::Layout::LENGTHADJUST_SPACINGANDGLYPHS : Inkscape::Text::Layout::LENGTHADJUST_SPACING); // default is "spacing" - return true; + return true; break; default: return false; } @@ -724,7 +724,7 @@ void TextTagAttributes::writeTo(Inkscape::XML::Node *node) const node->setAttribute("lengthAdjust", "spacing"); } else if (attributes.lengthAdjust == Inkscape::Text::Layout::LENGTHADJUST_SPACINGANDGLYPHS) { node->setAttribute("lengthAdjust", "spacingAndGlyphs"); - } + } } } @@ -734,7 +734,7 @@ void TextTagAttributes::writeSingleAttributeLength(Inkscape::XML::Node *node, gc gchar single_value_string[32]; g_ascii_formatd(single_value_string, sizeof (single_value_string), "%.8g", length.computed); node->setAttribute(key, single_value_string); - } else + } else node->setAttribute(key, NULL); } @@ -802,7 +802,7 @@ void TextTagAttributes::mergeInto(Inkscape::Text::Layout::OptionalTextTagAttrs * output->textLength.unit = attributes.textLength.unit; output->textLength._set = attributes.textLength._set; output->lengthAdjust = attributes.lengthAdjust; - } + } } void TextTagAttributes::mergeSingleAttribute(std::vector *output_list, std::vector const &parent_list, unsigned parent_offset, std::vector const *overlay_list) -- cgit v1.2.3 From f893425c4e9d23a438fb34b9f4bccd409650d484 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 2 May 2015 21:48:52 +0200 Subject: fix crash when setting clip (bzr r14094) --- src/selection-chemistry.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 68adf5381..f444f4217 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3884,17 +3884,18 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ items_to_select.push_back(*i); } } else { - GSList *i = NULL; - for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { - apply_to_items = g_slist_prepend(apply_to_items, *i); - items_to_select.push_back(*i); + SPItem *i = NULL; + for (std::vector::const_iterator j=items.begin();j!=items.end();j++) { + i=*j; + apply_to_items = g_slist_prepend(apply_to_items, i); + items_to_select.push_back(i); } - Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *dup = SP_OBJECT(i)->getRepr()->duplicate(xml_doc); mask_items = g_slist_prepend(mask_items, dup); if (remove_original) { - SPObject *item = reinterpret_cast(i->data); + SPObject *item = reinterpret_cast(i); items_to_delete = g_slist_prepend(items_to_delete, item); } } -- cgit v1.2.3 From a0ed5b5138836e368e409b9ced656f970b225b38 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 3 May 2015 18:58:35 +0200 Subject: First batch (bzr r14095) --- src/conditions.cpp | 4 +- src/display/canvas-grid.cpp | 3 + src/libcroco/cr-statement.c | 1 + src/live_effects/lpe-taperstroke.cpp | 4 +- src/style-enums.h | 137 +++++++++++++++++++++++++++++++++++ src/style.cpp | 8 ++ src/style.h | 18 +++++ 7 files changed, 171 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/conditions.cpp b/src/conditions.cpp index 9b233a74f..39ab16ba8 100644 --- a/src/conditions.cpp +++ b/src/conditions.cpp @@ -77,7 +77,7 @@ static gchar *preprocessLanguageCode(gchar *lngcode) { static bool evaluateSystemLanguage(SPItem const *item, gchar const *value) { if ( NULL == value ) return true; - + std::cout << "evaluateSystemLanguage: " << value << std::endl; std::set language_codes; gchar *str = NULL; gchar **strlist = g_strsplit( value, ",", 0); @@ -105,7 +105,7 @@ static bool evaluateSystemLanguage(SPItem const *item, gchar const *value) { SPDocument *document = item->document; Glib::ustring document_language = document->getLanguage(); - + std::cout << "language: |" << document_language << "|" << std::endl; if (document_language.size() == 0) return false; diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 4eda9b194..8285f7e64 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -916,12 +916,14 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) _empcolor = empcolor; } + std::cout << "CanvasXYGrid::Render: " << no_emp_when_zoomed_out << " " << empspacing << " " << _empcolor << " " << scaled << std::endl; cairo_save(buf->ct); cairo_translate(buf->ct, -buf->rect.left(), -buf->rect.top()); cairo_set_line_width(buf->ct, 1.0); cairo_set_line_cap(buf->ct, CAIRO_LINE_CAP_SQUARE); if (!render_dotted) { + // Render lines gint ylinenum; gdouble y; for (y = syg, ylinenum = ylinestart; y < buf->rect.bottom(); y += sw[Geom::Y], ylinenum++) { @@ -944,6 +946,7 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) } } } else { + // Render dots gint ylinenum; gdouble y; for (y = syg, ylinenum = ylinestart; y < buf->rect.bottom(); y += sw[Geom::Y], ylinenum++) { diff --git a/src/libcroco/cr-statement.c b/src/libcroco/cr-statement.c index 4666f26ec..5fb2dd2fd 100644 --- a/src/libcroco/cr-statement.c +++ b/src/libcroco/cr-statement.c @@ -1678,6 +1678,7 @@ CRStatement * cr_statement_new_at_font_face_rule (CRStyleSheet * a_sheet, CRDeclaration * a_font_decls) { + printf("cr_statement_new_at_font_face_rule\n"); CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); if (!result) { diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index 2c74af6d6..1888bc3f0 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -275,7 +275,7 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) pat_str << "M 1,0 C " << 1 - (double)smoothing << ",0 0,0.5 0,0.5 0,0.5 " << 1 - (double)smoothing << ",1 1,1"; pat_vec = sp_svg_read_pathv(pat_str.str().c_str()); - pwd2.concat(stretch_along(pathv_out[0].toPwSb(), pat_vec[0], -fabs(line_width))); + pwd2.concat(stretch_along(pathv_out[0].toPwSb(), pat_vec[0], fabs(line_width))); throwaway_path = Geom::path_from_piecewise(pwd2, LPE_CONVERSION_TOLERANCE)[0]; real_path.append(throwaway_path); @@ -304,7 +304,7 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) pat_vec = sp_svg_read_pathv(pat_str_1.str().c_str()); pwd2 = Piecewise >(); - pwd2.concat(stretch_along(pathv_out[2].toPwSb(), pat_vec[0], -fabs(line_width))); + pwd2.concat(stretch_along(pathv_out[2].toPwSb(), pat_vec[0], fabs(line_width))); throwaway_path = Geom::path_from_piecewise(pwd2, LPE_CONVERSION_TOLERANCE)[0]; if (!Geom::are_near(real_path.finalPoint(), throwaway_path.initialPoint()) && real_path.size() >= 1) { diff --git a/src/style-enums.h b/src/style-enums.h index f52752018..f235b6699 100644 --- a/src/style-enums.h +++ b/src/style-enums.h @@ -72,6 +72,72 @@ enum SPCSSFontStretch { SP_CSS_FONT_STRETCH_WIDER }; +// Can select more than one +enum SPCSSFontVariantLigatures { + SP_CSS_FONT_VARIANT_LIGATURES_NORMAL, + SP_CSS_FONT_VARIANT_LIGATURES_NONE, + SP_CSS_FONT_VARIANT_LIGATURES_COMMON, + SP_CSS_FONT_VARIANT_LIGATURES_NO_COMMON, + SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY, + SP_CSS_FONT_VARIANT_LIGATURES_NO_DISCRETIONARY, + SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL, + SP_CSS_FONT_VARIANT_LIGATURES_NO_HISTORICAL, + SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL, + SP_CSS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL +}; + +enum SPCSSFontVariantPosition { + SP_CSS_FONT_VARIANT_POSITION_NORMAL, + SP_CSS_FONT_VARIANT_POSITION_SUB, + SP_CSS_FONT_VARIANT_POSITION_SUPER +}; + +enum SPCSSFontVariantCaps { + SP_CSS_FONT_VARIANT_CAPS_NORMAL, + SP_CSS_FONT_VARIANT_CAPS_SMALL, + SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL, + SP_CSS_FONT_VARIANT_CAPS_PETITE, + SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE, + SP_CSS_FONT_VARIANT_CAPS_UNICASE, + SP_CSS_FONT_VARIANT_CAPS_TITLING, +}; + +enum SPCSSFontVariantNumeric { + SP_CSS_FONT_VARIANT_NUMERIC_NORMAL, + SP_CSS_FONT_VARIANT_NUMERIC_LINING_NUMS, + SP_CSS_FONT_VARIANT_NUMERIC_OLDSTYLE_NUMS, + SP_CSS_FONT_VARIANT_NUMERIC_PROPORTIONAL_NUMS, + SP_CSS_FONT_VARIANT_NUMERIC_TABULAR_NUMS, + SP_CSS_FONT_VARIANT_NUMERIC_DIAGONAL_FRACTIONS, + SP_CSS_FONT_VARIANT_NUMERIC_STACKED_FRACTIONS, + SP_CSS_FONT_VARIANT_NUMERIC_ORDINAL, + SP_CSS_FONT_VARIANT_NUMERIC_SLASHED_ZERO +}; + +enum SPCSSFontVariantAlternates { + SP_CSS_FONT_VARIANT_ALTERNATES_NORMAL, + SP_CSS_FONT_VARIANT_ALTERNATES_HISTORICAL_FORMS, + SP_CSS_FONT_VARIANT_ALTERNATES_STYLISTIC, + SP_CSS_FONT_VARIANT_ALTERNATES_STYLESET, + SP_CSS_FONT_VARIANT_ALTERNATES_CHARACTER_VARIANT, + SP_CSS_FONT_VARIANT_ALTERNATES_SWASH, + SP_CSS_FONT_VARIANT_ALTERNATES_ORNAMENTS, + SP_CSS_FONT_VARIANT_ALTERNATES_ANNOTATION +}; + +enum SPCSSFontVariantEastAsian { + SP_CSS_FONT_VARIANT_EAST_ASIAN_NORMAL, + SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS78, + SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS83, + SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS90, + SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS04, + SP_CSS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED, + SP_CSS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL, + SP_CSS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH, + SP_CSS_FONT_VARIANT_EAST_ASIAN_PROPORTIONAL_WIDTH, + SP_CSS_FONT_VARIANT_EAST_ASIAN_RUBY +}; + enum SPCSSTextAlign { SP_CSS_TEXT_ALIGN_START, SP_CSS_TEXT_ALIGN_END, @@ -309,6 +375,77 @@ static SPStyleEnum const enum_font_stretch[] = { {NULL, -1} }; +static SPStyleEnum const enum_font_variant_ligatures[] = { + {"normal", SP_CSS_FONT_VARIANT_LIGATURES_NORMAL}, + {"none", SP_CSS_FONT_VARIANT_LIGATURES_NONE}, + {"common-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_COMMON}, + {"no-common-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NO_COMMON}, + {"discretionary-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY}, + {"no-discretionary-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NO_DISCRETIONARY}, + {"historical-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL}, + {"nohistorical-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NO_HISTORICAL}, + {"contextual", SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL}, + {"no-contextual", SP_CSS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL}, + {NULL, -1} +}; + +static SPStyleEnum const enum_font_variant_position[] = { + {"normal", SP_CSS_FONT_VARIANT_POSITION_NORMAL}, + {"sub", SP_CSS_FONT_VARIANT_POSITION_SUB}, + {"super", SP_CSS_FONT_VARIANT_POSITION_SUPER}, + {NULL, -1} +}; + +static SPStyleEnum const enum_font_variant_caps[] = { + {"normal", SP_CSS_FONT_VARIANT_CAPS_NORMAL}, + {"small-caps", SP_CSS_FONT_VARIANT_CAPS_SMALL}, + {"all-small-caps", SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL}, + {"petite-caps", SP_CSS_FONT_VARIANT_CAPS_PETITE}, + {"all_petite-caps", SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE}, + {"unicase", SP_CSS_FONT_VARIANT_CAPS_UNICASE}, + {"titling", SP_CSS_FONT_VARIANT_CAPS_TITLING}, + {NULL, -1} +}; + +static SPStyleEnum const enum_font_variant_numeric[] = { + {"normal", SP_CSS_FONT_VARIANT_NUMERIC_NORMAL}, + {"lining-nums", SP_CSS_FONT_VARIANT_NUMERIC_LINING_NUMS}, + {"oldstyle-nums", SP_CSS_FONT_VARIANT_NUMERIC_OLDSTYLE_NUMS}, + {"proportional-nums", SP_CSS_FONT_VARIANT_NUMERIC_PROPORTIONAL_NUMS}, + {"tabular-nums", SP_CSS_FONT_VARIANT_NUMERIC_TABULAR_NUMS}, + {"diagonal-fractions", SP_CSS_FONT_VARIANT_NUMERIC_DIAGONAL_FRACTIONS}, + {"stacked-fractions", SP_CSS_FONT_VARIANT_NUMERIC_STACKED_FRACTIONS}, + {"ordinal", SP_CSS_FONT_VARIANT_NUMERIC_ORDINAL}, + {"slashed-zero", SP_CSS_FONT_VARIANT_NUMERIC_SLASHED_ZERO}, + {NULL, -1} +}; + +static SPStyleEnum const enum_font_variant_alternates[] = { + {"normal", SP_CSS_FONT_VARIANT_ALTERNATES_NORMAL}, + {"historical-forms", SP_CSS_FONT_VARIANT_ALTERNATES_HISTORICAL_FORMS}, + {"stylistic", SP_CSS_FONT_VARIANT_ALTERNATES_STYLISTIC}, + {"styleset", SP_CSS_FONT_VARIANT_ALTERNATES_STYLESET}, + {"character_variant", SP_CSS_FONT_VARIANT_ALTERNATES_CHARACTER_VARIANT}, + {"swash", SP_CSS_FONT_VARIANT_ALTERNATES_SWASH}, + {"ornaments", SP_CSS_FONT_VARIANT_ALTERNATES_ORNAMENTS}, + {"annotation", SP_CSS_FONT_VARIANT_ALTERNATES_ANNOTATION}, + {NULL, -1} +}; + +static SPStyleEnum const enum_font_variant_east_asian[] = { + {"normal", SP_CSS_FONT_VARIANT_EAST_ASIAN_NORMAL}, + {"jis78", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS78}, + {"jis83", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS83}, + {"jis90", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS90}, + {"jis04", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS04}, + {"simplified", SP_CSS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED}, + {"traditional", SP_CSS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL}, + {"full-width", SP_CSS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH}, + {"proportional-width", SP_CSS_FONT_VARIANT_EAST_ASIAN_PROPORTIONAL_WIDTH}, + {"ruby", SP_CSS_FONT_VARIANT_EAST_ASIAN_RUBY}, + {NULL, -1} +}; + static SPStyleEnum const enum_text_align[] = { {"start", SP_CSS_TEXT_ALIGN_START}, {"end", SP_CSS_TEXT_ALIGN_END}, diff --git a/src/style.cpp b/src/style.cpp index b65bff53f..943a12f3b 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -118,6 +118,14 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : font(), // SPIFont font_specification( "-inkscape-font-specification" ), // SPIString + // Font variants + font_variant_ligatures( "font-variant-ligatures", enum_font_variant_ligatures, SP_CSS_FONT_VARIANT_LIGATURES_NORMAL ), + font_variant_position( "font-variant-position", enum_font_variant_position, SP_CSS_FONT_VARIANT_POSITION_NORMAL ), + font_variant_caps( "font-variant-caps", enum_font_variant_caps, SP_CSS_FONT_VARIANT_CAPS_NORMAL ), + font_variant_numeric( "font-variant-numeric", enum_font_variant_numeric, SP_CSS_FONT_VARIANT_NUMERIC_NORMAL ), + font_variant_alternates("font-variant-alternates", enum_font_variant_alternates, SP_CSS_FONT_VARIANT_ALTERNATES_NORMAL ), + font_variant_east_asian("font-variant-east_asian", enum_font_variant_east_asian, SP_CSS_FONT_VARIANT_EAST_ASIAN_NORMAL ), + // Text related properties text_indent( "text-indent", 0.0 ), // SPILength text_align( "text-align", enum_text_align, SP_CSS_TEXT_ALIGN_START ), diff --git a/src/style.h b/src/style.h index ab34476b3..f52c14d89 100644 --- a/src/style.h +++ b/src/style.h @@ -111,6 +111,24 @@ public: /** Full font name, as font_factory::ConstructFontSpecification would give, for internal use. */ SPIString font_specification; + /* Font variants -------------------- */ + /** Font variant ligatures */ + SPIEnum font_variant_ligatures; + /** Font variant position (subscript/superscript) */ + SPIEnum font_variant_position; + /** Font variant caps (small caps) */ + SPIEnum font_variant_caps; + /** Font variant numeric (numerical formatting) */ + SPIEnum font_variant_numeric; + /** Font variant alternates (alternates/swatches) */ + SPIEnum font_variant_alternates; + /** Font variant East Asian */ + SPIEnum font_variant_east_asian; + /** Font variant shorthand (Redefines CSS 2.1 value) */ + // ? font_variant; + /** Font feature settings */ + // ? font_feature_settings; + /* Text ----------------------------- */ /** First line indent of paragraphs (css2 16.1) */ -- cgit v1.2.3 From c7ce360901e191572b207df27dd3e972bff3929f Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 3 May 2015 19:01:45 +0200 Subject: Revert bad commit (commited to wrong branch). (bzr r14096) --- src/conditions.cpp | 4 +- src/display/canvas-grid.cpp | 3 - src/libcroco/cr-statement.c | 1 - src/live_effects/lpe-taperstroke.cpp | 4 +- src/style-enums.h | 137 ----------------------------------- src/style.cpp | 8 -- src/style.h | 18 ----- 7 files changed, 4 insertions(+), 171 deletions(-) (limited to 'src') diff --git a/src/conditions.cpp b/src/conditions.cpp index 39ab16ba8..9b233a74f 100644 --- a/src/conditions.cpp +++ b/src/conditions.cpp @@ -77,7 +77,7 @@ static gchar *preprocessLanguageCode(gchar *lngcode) { static bool evaluateSystemLanguage(SPItem const *item, gchar const *value) { if ( NULL == value ) return true; - std::cout << "evaluateSystemLanguage: " << value << std::endl; + std::set language_codes; gchar *str = NULL; gchar **strlist = g_strsplit( value, ",", 0); @@ -105,7 +105,7 @@ static bool evaluateSystemLanguage(SPItem const *item, gchar const *value) { SPDocument *document = item->document; Glib::ustring document_language = document->getLanguage(); - std::cout << "language: |" << document_language << "|" << std::endl; + if (document_language.size() == 0) return false; diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 8285f7e64..4eda9b194 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -916,14 +916,12 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) _empcolor = empcolor; } - std::cout << "CanvasXYGrid::Render: " << no_emp_when_zoomed_out << " " << empspacing << " " << _empcolor << " " << scaled << std::endl; cairo_save(buf->ct); cairo_translate(buf->ct, -buf->rect.left(), -buf->rect.top()); cairo_set_line_width(buf->ct, 1.0); cairo_set_line_cap(buf->ct, CAIRO_LINE_CAP_SQUARE); if (!render_dotted) { - // Render lines gint ylinenum; gdouble y; for (y = syg, ylinenum = ylinestart; y < buf->rect.bottom(); y += sw[Geom::Y], ylinenum++) { @@ -946,7 +944,6 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) } } } else { - // Render dots gint ylinenum; gdouble y; for (y = syg, ylinenum = ylinestart; y < buf->rect.bottom(); y += sw[Geom::Y], ylinenum++) { diff --git a/src/libcroco/cr-statement.c b/src/libcroco/cr-statement.c index 5fb2dd2fd..4666f26ec 100644 --- a/src/libcroco/cr-statement.c +++ b/src/libcroco/cr-statement.c @@ -1678,7 +1678,6 @@ CRStatement * cr_statement_new_at_font_face_rule (CRStyleSheet * a_sheet, CRDeclaration * a_font_decls) { - printf("cr_statement_new_at_font_face_rule\n"); CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); if (!result) { diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index 1888bc3f0..2c74af6d6 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -275,7 +275,7 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) pat_str << "M 1,0 C " << 1 - (double)smoothing << ",0 0,0.5 0,0.5 0,0.5 " << 1 - (double)smoothing << ",1 1,1"; pat_vec = sp_svg_read_pathv(pat_str.str().c_str()); - pwd2.concat(stretch_along(pathv_out[0].toPwSb(), pat_vec[0], fabs(line_width))); + pwd2.concat(stretch_along(pathv_out[0].toPwSb(), pat_vec[0], -fabs(line_width))); throwaway_path = Geom::path_from_piecewise(pwd2, LPE_CONVERSION_TOLERANCE)[0]; real_path.append(throwaway_path); @@ -304,7 +304,7 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) pat_vec = sp_svg_read_pathv(pat_str_1.str().c_str()); pwd2 = Piecewise >(); - pwd2.concat(stretch_along(pathv_out[2].toPwSb(), pat_vec[0], fabs(line_width))); + pwd2.concat(stretch_along(pathv_out[2].toPwSb(), pat_vec[0], -fabs(line_width))); throwaway_path = Geom::path_from_piecewise(pwd2, LPE_CONVERSION_TOLERANCE)[0]; if (!Geom::are_near(real_path.finalPoint(), throwaway_path.initialPoint()) && real_path.size() >= 1) { diff --git a/src/style-enums.h b/src/style-enums.h index f235b6699..f52752018 100644 --- a/src/style-enums.h +++ b/src/style-enums.h @@ -72,72 +72,6 @@ enum SPCSSFontStretch { SP_CSS_FONT_STRETCH_WIDER }; -// Can select more than one -enum SPCSSFontVariantLigatures { - SP_CSS_FONT_VARIANT_LIGATURES_NORMAL, - SP_CSS_FONT_VARIANT_LIGATURES_NONE, - SP_CSS_FONT_VARIANT_LIGATURES_COMMON, - SP_CSS_FONT_VARIANT_LIGATURES_NO_COMMON, - SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY, - SP_CSS_FONT_VARIANT_LIGATURES_NO_DISCRETIONARY, - SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL, - SP_CSS_FONT_VARIANT_LIGATURES_NO_HISTORICAL, - SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL, - SP_CSS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL -}; - -enum SPCSSFontVariantPosition { - SP_CSS_FONT_VARIANT_POSITION_NORMAL, - SP_CSS_FONT_VARIANT_POSITION_SUB, - SP_CSS_FONT_VARIANT_POSITION_SUPER -}; - -enum SPCSSFontVariantCaps { - SP_CSS_FONT_VARIANT_CAPS_NORMAL, - SP_CSS_FONT_VARIANT_CAPS_SMALL, - SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL, - SP_CSS_FONT_VARIANT_CAPS_PETITE, - SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE, - SP_CSS_FONT_VARIANT_CAPS_UNICASE, - SP_CSS_FONT_VARIANT_CAPS_TITLING, -}; - -enum SPCSSFontVariantNumeric { - SP_CSS_FONT_VARIANT_NUMERIC_NORMAL, - SP_CSS_FONT_VARIANT_NUMERIC_LINING_NUMS, - SP_CSS_FONT_VARIANT_NUMERIC_OLDSTYLE_NUMS, - SP_CSS_FONT_VARIANT_NUMERIC_PROPORTIONAL_NUMS, - SP_CSS_FONT_VARIANT_NUMERIC_TABULAR_NUMS, - SP_CSS_FONT_VARIANT_NUMERIC_DIAGONAL_FRACTIONS, - SP_CSS_FONT_VARIANT_NUMERIC_STACKED_FRACTIONS, - SP_CSS_FONT_VARIANT_NUMERIC_ORDINAL, - SP_CSS_FONT_VARIANT_NUMERIC_SLASHED_ZERO -}; - -enum SPCSSFontVariantAlternates { - SP_CSS_FONT_VARIANT_ALTERNATES_NORMAL, - SP_CSS_FONT_VARIANT_ALTERNATES_HISTORICAL_FORMS, - SP_CSS_FONT_VARIANT_ALTERNATES_STYLISTIC, - SP_CSS_FONT_VARIANT_ALTERNATES_STYLESET, - SP_CSS_FONT_VARIANT_ALTERNATES_CHARACTER_VARIANT, - SP_CSS_FONT_VARIANT_ALTERNATES_SWASH, - SP_CSS_FONT_VARIANT_ALTERNATES_ORNAMENTS, - SP_CSS_FONT_VARIANT_ALTERNATES_ANNOTATION -}; - -enum SPCSSFontVariantEastAsian { - SP_CSS_FONT_VARIANT_EAST_ASIAN_NORMAL, - SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS78, - SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS83, - SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS90, - SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS04, - SP_CSS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED, - SP_CSS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL, - SP_CSS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH, - SP_CSS_FONT_VARIANT_EAST_ASIAN_PROPORTIONAL_WIDTH, - SP_CSS_FONT_VARIANT_EAST_ASIAN_RUBY -}; - enum SPCSSTextAlign { SP_CSS_TEXT_ALIGN_START, SP_CSS_TEXT_ALIGN_END, @@ -375,77 +309,6 @@ static SPStyleEnum const enum_font_stretch[] = { {NULL, -1} }; -static SPStyleEnum const enum_font_variant_ligatures[] = { - {"normal", SP_CSS_FONT_VARIANT_LIGATURES_NORMAL}, - {"none", SP_CSS_FONT_VARIANT_LIGATURES_NONE}, - {"common-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_COMMON}, - {"no-common-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NO_COMMON}, - {"discretionary-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY}, - {"no-discretionary-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NO_DISCRETIONARY}, - {"historical-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL}, - {"nohistorical-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NO_HISTORICAL}, - {"contextual", SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL}, - {"no-contextual", SP_CSS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL}, - {NULL, -1} -}; - -static SPStyleEnum const enum_font_variant_position[] = { - {"normal", SP_CSS_FONT_VARIANT_POSITION_NORMAL}, - {"sub", SP_CSS_FONT_VARIANT_POSITION_SUB}, - {"super", SP_CSS_FONT_VARIANT_POSITION_SUPER}, - {NULL, -1} -}; - -static SPStyleEnum const enum_font_variant_caps[] = { - {"normal", SP_CSS_FONT_VARIANT_CAPS_NORMAL}, - {"small-caps", SP_CSS_FONT_VARIANT_CAPS_SMALL}, - {"all-small-caps", SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL}, - {"petite-caps", SP_CSS_FONT_VARIANT_CAPS_PETITE}, - {"all_petite-caps", SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE}, - {"unicase", SP_CSS_FONT_VARIANT_CAPS_UNICASE}, - {"titling", SP_CSS_FONT_VARIANT_CAPS_TITLING}, - {NULL, -1} -}; - -static SPStyleEnum const enum_font_variant_numeric[] = { - {"normal", SP_CSS_FONT_VARIANT_NUMERIC_NORMAL}, - {"lining-nums", SP_CSS_FONT_VARIANT_NUMERIC_LINING_NUMS}, - {"oldstyle-nums", SP_CSS_FONT_VARIANT_NUMERIC_OLDSTYLE_NUMS}, - {"proportional-nums", SP_CSS_FONT_VARIANT_NUMERIC_PROPORTIONAL_NUMS}, - {"tabular-nums", SP_CSS_FONT_VARIANT_NUMERIC_TABULAR_NUMS}, - {"diagonal-fractions", SP_CSS_FONT_VARIANT_NUMERIC_DIAGONAL_FRACTIONS}, - {"stacked-fractions", SP_CSS_FONT_VARIANT_NUMERIC_STACKED_FRACTIONS}, - {"ordinal", SP_CSS_FONT_VARIANT_NUMERIC_ORDINAL}, - {"slashed-zero", SP_CSS_FONT_VARIANT_NUMERIC_SLASHED_ZERO}, - {NULL, -1} -}; - -static SPStyleEnum const enum_font_variant_alternates[] = { - {"normal", SP_CSS_FONT_VARIANT_ALTERNATES_NORMAL}, - {"historical-forms", SP_CSS_FONT_VARIANT_ALTERNATES_HISTORICAL_FORMS}, - {"stylistic", SP_CSS_FONT_VARIANT_ALTERNATES_STYLISTIC}, - {"styleset", SP_CSS_FONT_VARIANT_ALTERNATES_STYLESET}, - {"character_variant", SP_CSS_FONT_VARIANT_ALTERNATES_CHARACTER_VARIANT}, - {"swash", SP_CSS_FONT_VARIANT_ALTERNATES_SWASH}, - {"ornaments", SP_CSS_FONT_VARIANT_ALTERNATES_ORNAMENTS}, - {"annotation", SP_CSS_FONT_VARIANT_ALTERNATES_ANNOTATION}, - {NULL, -1} -}; - -static SPStyleEnum const enum_font_variant_east_asian[] = { - {"normal", SP_CSS_FONT_VARIANT_EAST_ASIAN_NORMAL}, - {"jis78", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS78}, - {"jis83", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS83}, - {"jis90", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS90}, - {"jis04", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS04}, - {"simplified", SP_CSS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED}, - {"traditional", SP_CSS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL}, - {"full-width", SP_CSS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH}, - {"proportional-width", SP_CSS_FONT_VARIANT_EAST_ASIAN_PROPORTIONAL_WIDTH}, - {"ruby", SP_CSS_FONT_VARIANT_EAST_ASIAN_RUBY}, - {NULL, -1} -}; - static SPStyleEnum const enum_text_align[] = { {"start", SP_CSS_TEXT_ALIGN_START}, {"end", SP_CSS_TEXT_ALIGN_END}, diff --git a/src/style.cpp b/src/style.cpp index 943a12f3b..b65bff53f 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -118,14 +118,6 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : font(), // SPIFont font_specification( "-inkscape-font-specification" ), // SPIString - // Font variants - font_variant_ligatures( "font-variant-ligatures", enum_font_variant_ligatures, SP_CSS_FONT_VARIANT_LIGATURES_NORMAL ), - font_variant_position( "font-variant-position", enum_font_variant_position, SP_CSS_FONT_VARIANT_POSITION_NORMAL ), - font_variant_caps( "font-variant-caps", enum_font_variant_caps, SP_CSS_FONT_VARIANT_CAPS_NORMAL ), - font_variant_numeric( "font-variant-numeric", enum_font_variant_numeric, SP_CSS_FONT_VARIANT_NUMERIC_NORMAL ), - font_variant_alternates("font-variant-alternates", enum_font_variant_alternates, SP_CSS_FONT_VARIANT_ALTERNATES_NORMAL ), - font_variant_east_asian("font-variant-east_asian", enum_font_variant_east_asian, SP_CSS_FONT_VARIANT_EAST_ASIAN_NORMAL ), - // Text related properties text_indent( "text-indent", 0.0 ), // SPILength text_align( "text-align", enum_text_align, SP_CSS_TEXT_ALIGN_START ), diff --git a/src/style.h b/src/style.h index f52c14d89..ab34476b3 100644 --- a/src/style.h +++ b/src/style.h @@ -111,24 +111,6 @@ public: /** Full font name, as font_factory::ConstructFontSpecification would give, for internal use. */ SPIString font_specification; - /* Font variants -------------------- */ - /** Font variant ligatures */ - SPIEnum font_variant_ligatures; - /** Font variant position (subscript/superscript) */ - SPIEnum font_variant_position; - /** Font variant caps (small caps) */ - SPIEnum font_variant_caps; - /** Font variant numeric (numerical formatting) */ - SPIEnum font_variant_numeric; - /** Font variant alternates (alternates/swatches) */ - SPIEnum font_variant_alternates; - /** Font variant East Asian */ - SPIEnum font_variant_east_asian; - /** Font variant shorthand (Redefines CSS 2.1 value) */ - // ? font_variant; - /** Font feature settings */ - // ? font_feature_settings; - /* Text ----------------------------- */ /** First line indent of paragraphs (css2 16.1) */ -- cgit v1.2.3 From 2eab6fad30c9c838902d9113c7e0d41b34ce79ea Mon Sep 17 00:00:00 2001 From: houz Date: Mon, 4 May 2015 12:39:09 +0200 Subject: cmake: shorter linker list (remove duplicates) (bzr r14106) --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 27c5e49db..efb604aca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -519,7 +519,7 @@ add_dependencies(inkscape inkscape_version) target_link_libraries(inkscape # order from automake #sp_LIB - nrtype_LIB + #nrtype_LIB #inkscape_LIB #sp_LIB # annoying, we need both! -- cgit v1.2.3 From 7e3aabae24c09340fd06cb69b0678158abb4a375 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 4 May 2015 12:57:06 +0200 Subject: Shorthands are not allowed as presentation attributes. (bzr r14107) --- src/style.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/style.cpp b/src/style.cpp index b65bff53f..8b41bbbd7 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -573,7 +573,15 @@ SPStyle::read( SPObject *object, Inkscape::XML::Node *repr ) { /* 3 Presentation attributes */ // std::cout << " MERGING PRESENTATION ATTRIBUTES" << std::endl; for(std::vector::size_type i = 0; i != _properties.size(); ++i) { - _properties[i]->readAttribute( repr ); + + // Shorthands are not allowed as presentation properites. + // Note: text-decoration is converted to a shorthand in CSS 3 but can still be + // read as a non-shorthand so it should not be in this list. + // We could add a flag to SPIBase to avoid string comparison. + if( _properties[i]->name.compare( "font" ) != 0 && + _properties[i]->name.compare( "marker" ) != 0 ) { + _properties[i]->readAttribute( repr ); + } } // for(SPPropMap::iterator i = _propmap.begin(); i != _propmap.end(); ++i ) { // (this->*(i->second)).readAttribute( repr ); -- cgit v1.2.3 From f9afd4f6cdee501fcfd5ae6185643796e9ec646d Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Mon, 4 May 2015 13:09:20 +0200 Subject: Fix crash in PDF export introduced in r14074 (bzr r14108) --- src/extension/internal/cairo-renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 49e145de0..5a5553e97 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -296,7 +296,7 @@ static void sp_group_render(SPGroup *group, CairoRenderContext *ctx) std::vector l(group->childList(false)); for(std::vector::const_iterator x = l.begin(); x!= l.end(); x++){ - SPItem *item = static_cast(*x); + SPItem *item = dynamic_cast(*x); if (item) { renderer->renderItem(ctx, item); } -- cgit v1.2.3 From abe296168df89e7f62e9d670602ffea62ad78a22 Mon Sep 17 00:00:00 2001 From: Raphael Rosch Date: Mon, 4 May 2015 12:17:58 -0400 Subject: going from swatch to flat color should start with previous swatch color Fixed bugs: - https://launchpad.net/bugs/1450112 (bzr r14109) --- src/widgets/paint-selector.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 740ce2b0e..221344296 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -35,6 +35,7 @@ #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" #include "sp-mesh.h" +#include "sp-stop.h" /* fixme: Move it from dialogs to here */ #include "gradient-selector.h" #include @@ -658,6 +659,20 @@ sp_paint_selector_color_changed(SPColorSelector *csel, SPPaintSelector *psel) static void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelector::Mode /*mode*/) { GtkWidget *csel; + + SPColor newcolor = psel->color; + float newalpha = psel->alpha; + + if ((psel->mode == SPPaintSelector::MODE_SWATCH) + || (psel->mode == SPPaintSelector::MODE_GRADIENT_LINEAR) + || (psel->mode == SPPaintSelector::MODE_GRADIENT_RADIAL) ) { + SPGradientSelector *gsel = getGradientFromData(psel); + if (gsel) { + SPGradient *gradient = gsel->getVector(); + newcolor = gradient->getFirstStop()->specified_color; + newalpha = gradient->getFirstStop()->opacity; + } + } sp_paint_selector_set_style_buttons(psel, psel->solid); gtk_widget_set_sensitive(psel->style, TRUE); @@ -693,8 +708,7 @@ static void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelec psel->selector = vb; /* Set color */ - SP_COLOR_SELECTOR( csel )->base->setColorAlpha( psel->color, psel->alpha ); - + SP_COLOR_SELECTOR( csel )->base->setColorAlpha( newcolor, newalpha ); } gtk_label_set_markup(GTK_LABEL(psel->label), _("Flat color")); -- cgit v1.2.3 From 5af8924e1de466080dc116b47edd7c8d8591652b Mon Sep 17 00:00:00 2001 From: Raphael Rosch Date: Tue, 5 May 2015 13:26:20 -0400 Subject: show filter usage count Fixed bugs: - https://launchpad.net/bugs/1169123 (bzr r14111) --- src/sp-filter.cpp | 10 ++++++++++ src/sp-filter.h | 3 +++ src/style.cpp | 2 ++ src/ui/dialog/filter-effects-dialog.cpp | 31 +++++++++++++++++++++++++------ src/ui/dialog/filter-effects-dialog.h | 4 ++++ 5 files changed, 44 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 2bf1b11a6..1bde69dd1 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -79,6 +79,7 @@ void SPFilter::build(SPDocument *document, Inkscape::XML::Node *repr) { this->readAttr( "height" ); this->readAttr( "filterRes" ); this->readAttr( "xlink:href" ); + this->_refcount = 0; SPObject::build(document, repr); @@ -190,6 +191,15 @@ void SPFilter::set(unsigned int key, gchar const *value) { } } + +/** + * Returns the number of references to the filter. + */ +guint SPFilter::getRefCount() { + // NOTE: this is currently updated by sp_style_filter_ref_changed() in style.cpp + return _refcount; +} + /** * Receives update notifications. */ diff --git a/src/sp-filter.h b/src/sp-filter.h index e6318c569..1c214c6b7 100644 --- a/src/sp-filter.h +++ b/src/sp-filter.h @@ -54,6 +54,9 @@ public: NumberOptNumber filterRes; SPFilterReference *href; sigc::connection modified_connection; + + guint getRefCount(); + guint _refcount; Inkscape::Filters::Filter *_renderer; diff --git a/src/style.cpp b/src/style.cpp index 8b41bbbd7..fa8aed68e 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -1177,10 +1177,12 @@ void sp_style_filter_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style) { if (old_ref) { + (dynamic_cast( old_ref ))->_refcount--; style->filter_modified_connection.disconnect(); } if ( SP_IS_FILTER(ref)) { + (dynamic_cast( ref ))->_refcount++; style->filter_modified_connection = ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_filter_ref_modified), style)); } diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index f81519ed1..1ff9e4a1b 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -8,6 +8,7 @@ * Felipe C. da S. Sanches * Jon A. Cruz * Abhishek Sharma + * insaner * * Copyright (C) 2007 Authors * @@ -1360,8 +1361,15 @@ FilterEffectsDialog::FilterModifier::FilterModifier(FilterEffectsDialog& d) ((Gtk::CellRendererText*)_list.get_column(1)->get_first_cell())-> signal_edited().connect(sigc::mem_fun(*this, &FilterEffectsDialog::FilterModifier::on_name_edited)); + _list.append_column("#", _columns.count); + _list.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE); + _list.get_column(2)->set_expand(false); + sw->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); _list.get_column(1)->set_resizable(true); + _list.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE); + _list.get_column(1)->set_expand(true); + _list.set_reorderable(true); _list.enable_model_drag_dest (Gdk::ACTION_MOVE); @@ -1494,6 +1502,7 @@ void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel) (*iter)[_columns.sel] = 0; } } + update_counts(); } void FilterEffectsDialog::FilterModifier::on_filter_selection_changed() @@ -1565,6 +1574,15 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri } } + +void FilterEffectsDialog::FilterModifier::update_counts() +{ + for(Gtk::TreeModel::iterator i = _model->children().begin(); i != _model->children().end(); ++i) { + SPFilter* f = SP_FILTER((*i)[_columns.filter]); + (*i)[_columns.count] = f->getRefCount(); + } +} + /* Add all filters in the document to the combobox. Keeps the same selection if possible, otherwise selects the first element */ void FilterEffectsDialog::FilterModifier::update_filters() @@ -2419,7 +2437,7 @@ bool FilterEffectsDialog::PrimitiveList::on_motion_notify_event(GdkEventMotion* get_visible_rect(vis); int vis_x, vis_y; - int vis_x2, vis_y2; // NOTE: insaner added -- necessary to get the scrolling while dragging to work + int vis_x2, vis_y2; convert_widget_to_tree_coords(vis.get_x(), vis.get_y(), vis_x2, vis_y2); convert_tree_to_widget_coords(vis.get_x(), vis.get_y(), vis_x, vis_y); @@ -2439,7 +2457,6 @@ bool FilterEffectsDialog::PrimitiveList::on_motion_notify_event(GdkEventMotion* else _autoscroll_y = 0; - // NOTE: insaner added -- necessary to get the scrolling while dragging to work double e2 = ( e->x - vis_x2/2); // horizontal scrolling if(e2 < vis_x) @@ -2752,20 +2769,22 @@ FilterEffectsDialog::FilterEffectsDialog() Gtk::ScrolledWindow* sw_infobox = Gtk::manage(new Gtk::ScrolledWindow); Gtk::HBox* infobox = Gtk::manage(new Gtk::HBox(/*homogeneous:*/false, /*spacing:*/4)); Gtk::HBox* hb_prims = Gtk::manage(new Gtk::HBox); + Gtk::VBox* vb_prims = Gtk::manage(new Gtk::VBox); _getContents()->add(*hpaned); hpaned->pack1(_filter_modifier); hpaned->pack2(_primitive_box); _primitive_box.pack_start(*sw_prims); - _primitive_box.pack_start(*hb_prims, false, false); _primitive_box.pack_start(*sw_infobox, false, false); sw_prims->add(_primitive_list); - sw_infobox->add(*infobox); + sw_infobox->add(*vb_prims); infobox->pack_start(_infobox_icon, false, false); infobox->pack_start(_infobox_desc, false, false); _infobox_desc.set_line_wrap(true); - _infobox_desc.set_size_request(200, -1); + _infobox_desc.set_size_request(250, -1); + vb_prims->pack_start(*hb_prims); + vb_prims->pack_start(*infobox); hb_prims->pack_start(_add_primitive, false, false); hb_prims->pack_start(_add_primitive_type, false, false); @@ -2781,7 +2800,7 @@ FilterEffectsDialog::FilterEffectsDialog() _add_primitive_type.signal_changed().connect( sigc::mem_fun(*this, &FilterEffectsDialog::update_primitive_infobox)); - sw_prims->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); /* NOTE: insaner -- SCROLL the connections panel thing!!! */ + sw_prims->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); sw_prims->set_shadow_type(Gtk::SHADOW_IN); sw_infobox->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER); diff --git a/src/ui/dialog/filter-effects-dialog.h b/src/ui/dialog/filter-effects-dialog.h index 3fc19e7de..a067cd70c 100644 --- a/src/ui/dialog/filter-effects-dialog.h +++ b/src/ui/dialog/filter-effects-dialog.h @@ -4,6 +4,7 @@ /* Authors: * Nicholas Bishop * Rodrigo Kumpera + * insaner * * Copyright (C) 2007 Authors * @@ -69,11 +70,13 @@ private: add(filter); add(label); add(sel); + add(count); } Gtk::TreeModelColumn filter; Gtk::TreeModelColumn label; Gtk::TreeModelColumn sel; + Gtk::TreeModelColumn count; }; void setTargetDesktop(SPDesktop *desktop); @@ -89,6 +92,7 @@ private: bool on_filter_move(const Glib::RefPtr& /*context*/, int x, int y, guint /*time*/); void on_selection_toggled(const Glib::ustring&); + void update_counts(); void update_filters(); void filter_list_button_release(GdkEventButton*); void add_filter(); -- cgit v1.2.3 From 6957740e11e8604b8439c3ef331cf3c44400d1fb Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Wed, 6 May 2015 01:48:53 -0700 Subject: Changed return type to be consistent with other calls and to make header stand-alone. (bzr r14112) --- src/dir-util.cpp | 2 +- src/dir-util.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/dir-util.cpp b/src/dir-util.cpp index c9b88b007..64f7ab7e7 100644 --- a/src/dir-util.cpp +++ b/src/dir-util.cpp @@ -217,7 +217,7 @@ erange: return (NULL); } -gchar *prepend_current_dir_if_relative(gchar const *uri) +char *prepend_current_dir_if_relative(gchar const *uri) { if (!uri) { return NULL; diff --git a/src/dir-util.h b/src/dir-util.h index e78cad6a6..327e1ad5f 100644 --- a/src/dir-util.h +++ b/src/dir-util.h @@ -12,7 +12,7 @@ #include #include -/** +/** * Returns a form of \a path relative to \a base if that is easy to construct (eg if \a path * appears to be in the directory specified by \a base), otherwise returns \a path. * @@ -49,7 +49,7 @@ char *inkscape_rel2abs(char const *path, char const *base, char *result, size_t char *inkscape_abs2rel(char const *path, char const *base, char *result, size_t const size); -gchar *prepend_current_dir_if_relative(char const *filename); +char *prepend_current_dir_if_relative(char const *filename); #endif // !SEEN_DIR_UTIL_H -- cgit v1.2.3 From 12fb2762bc936c08538f041be261c79f43ee80e0 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 6 May 2015 13:55:31 +0200 Subject: Compromise solution for dot grid visibilty. See bug #1357611. (bzr r14114) --- src/display/canvas-grid.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 4eda9b194..decf93626 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -906,7 +906,7 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) gdouble const syg = floor ((buf->rect.top() - ow[Geom::Y]) / sw[Geom::Y]) * sw[Geom::Y] + ow[Geom::Y]; gint const ylinestart = round((syg - ow[Geom::Y]) / sw[Geom::Y]); - //set correct coloring, depending preference (when zoomed out, always major coloring or minor coloring) + // no_emphasize_when_zoomedout determines color (minor or major) when only major grid lines/dots shown. Inkscape::Preferences *prefs = Inkscape::Preferences::get(); guint32 _empcolor; bool no_emp_when_zoomed_out = prefs->getBool("/options/grids/no_emphasize_when_zoomedout", false); @@ -922,6 +922,7 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) cairo_set_line_cap(buf->ct, CAIRO_LINE_CAP_SQUARE); if (!render_dotted) { + // Line grid gint ylinenum; gdouble y; for (y = syg, ylinenum = ylinestart; y < buf->rect.bottom(); y += sw[Geom::Y], ylinenum++) { @@ -944,8 +945,23 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) } } } else { + // Dotted grid gint ylinenum; gdouble y; + + // alpha needs to be larger than in the line case to maintain a similar visual impact but + // setting it to the maximal value makes the dots dominant in some cases. Solution, + // increase the alpha by a factor of 4. This then allows some user adjustment. + guint32 _empdot = (_empcolor & 0xff) << 2; + if (_empdot > 0xff) + _empdot = 0xff; + _empdot += (_empcolor & 0xffffff00); + + guint32 _colordot = (color & 0xff) << 2; + if (_colordot > 0xff) + _colordot = 0xff; + _colordot += (color & 0xffffff00); + for (y = syg, ylinenum = ylinestart; y < buf->rect.bottom(); y += sw[Geom::Y], ylinenum++) { gint const iy = round(y); @@ -957,13 +973,15 @@ CanvasXYGrid::Render (SPCanvasBuf *buf) || (!scaled[Geom::Y] && (ylinenum % empspacing) != 0) || ((scaled[Geom::X] || scaled[Geom::Y]) && no_emp_when_zoomed_out) ) { - grid_dot (buf, ix, iy, color | (guint32)0x000000FF); // put alpha to max value + // Minor point: dot only + grid_dot (buf, ix, iy, _colordot); // | (guint32)0x000000FF); // put alpha to max value } else { + // Major point: small cross gint const pitch = 1; grid_dot (buf, ix-pitch, iy, _empcolor); grid_dot (buf, ix+pitch, iy, _empcolor); - grid_dot (buf, ix, iy, _empcolor | (guint32)0x000000FF); // put alpha to max value + grid_dot (buf, ix, iy, _empdot ); // | (guint32)0x000000FF); // put alpha to max value grid_dot (buf, ix, iy-pitch, _empcolor); grid_dot (buf, ix, iy+pitch, _empcolor); -- cgit v1.2.3 From d71254cf07e2258ab3f8b80fc09b565e4a90f422 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 6 May 2015 15:44:14 +0200 Subject: Start of implementing CSS 3 font variants (access to OpenType features). (bzr r14115) --- src/attributes.cpp | 24 ++++++++-- src/attributes.h | 23 +++++++-- src/style-enums.h | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/style.cpp | 57 ++++++++++++++++++++-- src/style.h | 18 ++++++- 5 files changed, 245 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/attributes.cpp b/src/attributes.cpp index 568f0528a..af19360c1 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -419,6 +419,16 @@ static SPStyleProp const props[] = { {SP_PROP_FONT_STYLE, "font-style"}, {SP_PROP_FONT_VARIANT, "font-variant"}, {SP_PROP_FONT_WEIGHT, "font-weight"}, + + /* Font Variants CSS 3 */ + {SP_PROP_FONT_VARIANT_LIGATURES, "font-variant-ligatures"}, + {SP_PROP_FONT_VARIANT_POSITION, "font-variant-position"}, + {SP_PROP_FONT_VARIANT_CAPS, "font-variant-caps"}, + {SP_PROP_FONT_VARIANT_NUMERIC, "font-variant-numeric"}, + {SP_PROP_FONT_VARIANT_ALTERNATES, "font-variant-alternates"}, + {SP_PROP_FONT_VARIANT_EAST_ASIAN, "font-variant-east-asian"}, + {SP_PROP_FONT_FEATURE_SETTINGS, "font-feature-settings"}, + /* Text */ {SP_PROP_TEXT_INDENT, "text-indent"}, {SP_PROP_TEXT_ALIGN, "text-align"}, @@ -426,6 +436,7 @@ static SPStyleProp const props[] = { {SP_PROP_LETTER_SPACING, "letter-spacing"}, {SP_PROP_WORD_SPACING, "word-spacing"}, {SP_PROP_TEXT_TRANSFORM, "text-transform"}, + /* Text (css3) */ {SP_PROP_DIRECTION, "direction"}, {SP_PROP_BLOCK_PROGRESSION, "block-progression"}, @@ -439,16 +450,21 @@ static SPStyleProp const props[] = { {SP_PROP_KERNING, "kerning"}, {SP_PROP_TEXT_ANCHOR, "text-anchor"}, {SP_PROP_WHITE_SPACE, "white-space"}, + /* SVG 2 Text Wrapping */ {SP_PROP_SHAPE_INSIDE, "shape-inside"}, {SP_PROP_SHAPE_OUTSIDE, "shape-outside"}, {SP_PROP_SHAPE_PADDING, "shape-padding"}, {SP_PROP_SHAPE_MARGIN, "shape-margin"}, + /* Text Decoration */ - {SP_PROP_TEXT_DECORATION, "text-decoration"}, - {SP_PROP_TEXT_DECORATION_LINE, "text-decoration-line"}, - {SP_PROP_TEXT_DECORATION_STYLE,"text-decoration-style"}, - {SP_PROP_TEXT_DECORATION_COLOR,"text-decoration-color"}, + {SP_PROP_TEXT_DECORATION, "text-decoration"}, + {SP_PROP_TEXT_DECORATION_LINE, "text-decoration-line"}, + {SP_PROP_TEXT_DECORATION_STYLE, "text-decoration-style"}, + {SP_PROP_TEXT_DECORATION_COLOR, "text-decoration-color"}, + {SP_PROP_TEXT_DECORATION_FILL, "text-decoration-fill"}, + {SP_PROP_TEXT_DECORATION_STROKE,"text-decoration-stroke"}, + /* Misc */ {SP_PROP_CLIP, "clip"}, {SP_PROP_COLOR, "color"}, diff --git a/src/attributes.h b/src/attributes.h index 91c8868f9..7d6ea70a0 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -424,6 +424,15 @@ enum SPAttributeEnum { SP_PROP_FONT_VARIANT, SP_PROP_FONT_WEIGHT, + /* Font Variants CSS 3 */ + SP_PROP_FONT_VARIANT_LIGATURES, + SP_PROP_FONT_VARIANT_POSITION, + SP_PROP_FONT_VARIANT_CAPS, + SP_PROP_FONT_VARIANT_NUMERIC, + SP_PROP_FONT_VARIANT_ALTERNATES, + SP_PROP_FONT_VARIANT_EAST_ASIAN, + SP_PROP_FONT_FEATURE_SETTINGS, + /* Text Layout */ SP_PROP_TEXT_INDENT, SP_PROP_TEXT_ALIGN, @@ -446,16 +455,20 @@ enum SPAttributeEnum { SP_PROP_TEXT_ANCHOR, SP_PROP_WHITE_SPACE, + /* SVG 2 Text Wrapping */ SP_PROP_SHAPE_INSIDE, SP_PROP_SHAPE_OUTSIDE, SP_PROP_SHAPE_PADDING, SP_PROP_SHAPE_MARGIN, - /* Text Decoration */ - SP_PROP_TEXT_DECORATION, /* SVG 1 underline etc.( no color or style) OR SVG2 with _LINE, _STYLE, _COLOR values */ - SP_PROP_TEXT_DECORATION_LINE, /* SVG 2 underline etc. */ - SP_PROP_TEXT_DECORATION_STYLE, /* SVG 2 proposed solid [SVG 1], dotted, etc.)*/ - SP_PROP_TEXT_DECORATION_COLOR, /* SVG 2 proposed same as text [SVG 1], specified*/ + /* Text Decoration CSS 2/CSS 3 Shorthand */ + SP_PROP_TEXT_DECORATION, + /* Text Decoration CSS 3/SVG 2 */ + SP_PROP_TEXT_DECORATION_LINE, + SP_PROP_TEXT_DECORATION_STYLE, + SP_PROP_TEXT_DECORATION_COLOR, + SP_PROP_TEXT_DECORATION_FILL, + SP_PROP_TEXT_DECORATION_STROKE, /* Misc */ SP_PROP_CLIP, diff --git a/src/style-enums.h b/src/style-enums.h index f52752018..f235b6699 100644 --- a/src/style-enums.h +++ b/src/style-enums.h @@ -72,6 +72,72 @@ enum SPCSSFontStretch { SP_CSS_FONT_STRETCH_WIDER }; +// Can select more than one +enum SPCSSFontVariantLigatures { + SP_CSS_FONT_VARIANT_LIGATURES_NORMAL, + SP_CSS_FONT_VARIANT_LIGATURES_NONE, + SP_CSS_FONT_VARIANT_LIGATURES_COMMON, + SP_CSS_FONT_VARIANT_LIGATURES_NO_COMMON, + SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY, + SP_CSS_FONT_VARIANT_LIGATURES_NO_DISCRETIONARY, + SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL, + SP_CSS_FONT_VARIANT_LIGATURES_NO_HISTORICAL, + SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL, + SP_CSS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL +}; + +enum SPCSSFontVariantPosition { + SP_CSS_FONT_VARIANT_POSITION_NORMAL, + SP_CSS_FONT_VARIANT_POSITION_SUB, + SP_CSS_FONT_VARIANT_POSITION_SUPER +}; + +enum SPCSSFontVariantCaps { + SP_CSS_FONT_VARIANT_CAPS_NORMAL, + SP_CSS_FONT_VARIANT_CAPS_SMALL, + SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL, + SP_CSS_FONT_VARIANT_CAPS_PETITE, + SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE, + SP_CSS_FONT_VARIANT_CAPS_UNICASE, + SP_CSS_FONT_VARIANT_CAPS_TITLING, +}; + +enum SPCSSFontVariantNumeric { + SP_CSS_FONT_VARIANT_NUMERIC_NORMAL, + SP_CSS_FONT_VARIANT_NUMERIC_LINING_NUMS, + SP_CSS_FONT_VARIANT_NUMERIC_OLDSTYLE_NUMS, + SP_CSS_FONT_VARIANT_NUMERIC_PROPORTIONAL_NUMS, + SP_CSS_FONT_VARIANT_NUMERIC_TABULAR_NUMS, + SP_CSS_FONT_VARIANT_NUMERIC_DIAGONAL_FRACTIONS, + SP_CSS_FONT_VARIANT_NUMERIC_STACKED_FRACTIONS, + SP_CSS_FONT_VARIANT_NUMERIC_ORDINAL, + SP_CSS_FONT_VARIANT_NUMERIC_SLASHED_ZERO +}; + +enum SPCSSFontVariantAlternates { + SP_CSS_FONT_VARIANT_ALTERNATES_NORMAL, + SP_CSS_FONT_VARIANT_ALTERNATES_HISTORICAL_FORMS, + SP_CSS_FONT_VARIANT_ALTERNATES_STYLISTIC, + SP_CSS_FONT_VARIANT_ALTERNATES_STYLESET, + SP_CSS_FONT_VARIANT_ALTERNATES_CHARACTER_VARIANT, + SP_CSS_FONT_VARIANT_ALTERNATES_SWASH, + SP_CSS_FONT_VARIANT_ALTERNATES_ORNAMENTS, + SP_CSS_FONT_VARIANT_ALTERNATES_ANNOTATION +}; + +enum SPCSSFontVariantEastAsian { + SP_CSS_FONT_VARIANT_EAST_ASIAN_NORMAL, + SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS78, + SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS83, + SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS90, + SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS04, + SP_CSS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED, + SP_CSS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL, + SP_CSS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH, + SP_CSS_FONT_VARIANT_EAST_ASIAN_PROPORTIONAL_WIDTH, + SP_CSS_FONT_VARIANT_EAST_ASIAN_RUBY +}; + enum SPCSSTextAlign { SP_CSS_TEXT_ALIGN_START, SP_CSS_TEXT_ALIGN_END, @@ -309,6 +375,77 @@ static SPStyleEnum const enum_font_stretch[] = { {NULL, -1} }; +static SPStyleEnum const enum_font_variant_ligatures[] = { + {"normal", SP_CSS_FONT_VARIANT_LIGATURES_NORMAL}, + {"none", SP_CSS_FONT_VARIANT_LIGATURES_NONE}, + {"common-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_COMMON}, + {"no-common-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NO_COMMON}, + {"discretionary-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_DISCRETIONARY}, + {"no-discretionary-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NO_DISCRETIONARY}, + {"historical-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_HISTORICAL}, + {"nohistorical-ligatures", SP_CSS_FONT_VARIANT_LIGATURES_NO_HISTORICAL}, + {"contextual", SP_CSS_FONT_VARIANT_LIGATURES_CONTEXTUAL}, + {"no-contextual", SP_CSS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL}, + {NULL, -1} +}; + +static SPStyleEnum const enum_font_variant_position[] = { + {"normal", SP_CSS_FONT_VARIANT_POSITION_NORMAL}, + {"sub", SP_CSS_FONT_VARIANT_POSITION_SUB}, + {"super", SP_CSS_FONT_VARIANT_POSITION_SUPER}, + {NULL, -1} +}; + +static SPStyleEnum const enum_font_variant_caps[] = { + {"normal", SP_CSS_FONT_VARIANT_CAPS_NORMAL}, + {"small-caps", SP_CSS_FONT_VARIANT_CAPS_SMALL}, + {"all-small-caps", SP_CSS_FONT_VARIANT_CAPS_ALL_SMALL}, + {"petite-caps", SP_CSS_FONT_VARIANT_CAPS_PETITE}, + {"all_petite-caps", SP_CSS_FONT_VARIANT_CAPS_ALL_PETITE}, + {"unicase", SP_CSS_FONT_VARIANT_CAPS_UNICASE}, + {"titling", SP_CSS_FONT_VARIANT_CAPS_TITLING}, + {NULL, -1} +}; + +static SPStyleEnum const enum_font_variant_numeric[] = { + {"normal", SP_CSS_FONT_VARIANT_NUMERIC_NORMAL}, + {"lining-nums", SP_CSS_FONT_VARIANT_NUMERIC_LINING_NUMS}, + {"oldstyle-nums", SP_CSS_FONT_VARIANT_NUMERIC_OLDSTYLE_NUMS}, + {"proportional-nums", SP_CSS_FONT_VARIANT_NUMERIC_PROPORTIONAL_NUMS}, + {"tabular-nums", SP_CSS_FONT_VARIANT_NUMERIC_TABULAR_NUMS}, + {"diagonal-fractions", SP_CSS_FONT_VARIANT_NUMERIC_DIAGONAL_FRACTIONS}, + {"stacked-fractions", SP_CSS_FONT_VARIANT_NUMERIC_STACKED_FRACTIONS}, + {"ordinal", SP_CSS_FONT_VARIANT_NUMERIC_ORDINAL}, + {"slashed-zero", SP_CSS_FONT_VARIANT_NUMERIC_SLASHED_ZERO}, + {NULL, -1} +}; + +static SPStyleEnum const enum_font_variant_alternates[] = { + {"normal", SP_CSS_FONT_VARIANT_ALTERNATES_NORMAL}, + {"historical-forms", SP_CSS_FONT_VARIANT_ALTERNATES_HISTORICAL_FORMS}, + {"stylistic", SP_CSS_FONT_VARIANT_ALTERNATES_STYLISTIC}, + {"styleset", SP_CSS_FONT_VARIANT_ALTERNATES_STYLESET}, + {"character_variant", SP_CSS_FONT_VARIANT_ALTERNATES_CHARACTER_VARIANT}, + {"swash", SP_CSS_FONT_VARIANT_ALTERNATES_SWASH}, + {"ornaments", SP_CSS_FONT_VARIANT_ALTERNATES_ORNAMENTS}, + {"annotation", SP_CSS_FONT_VARIANT_ALTERNATES_ANNOTATION}, + {NULL, -1} +}; + +static SPStyleEnum const enum_font_variant_east_asian[] = { + {"normal", SP_CSS_FONT_VARIANT_EAST_ASIAN_NORMAL}, + {"jis78", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS78}, + {"jis83", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS83}, + {"jis90", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS90}, + {"jis04", SP_CSS_FONT_VARIANT_EAST_ASIAN_JIS04}, + {"simplified", SP_CSS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED}, + {"traditional", SP_CSS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL}, + {"full-width", SP_CSS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH}, + {"proportional-width", SP_CSS_FONT_VARIANT_EAST_ASIAN_PROPORTIONAL_WIDTH}, + {"ruby", SP_CSS_FONT_VARIANT_EAST_ASIAN_RUBY}, + {NULL, -1} +}; + static SPStyleEnum const enum_text_align[] = { {"start", SP_CSS_TEXT_ALIGN_START}, {"end", SP_CSS_TEXT_ALIGN_END}, diff --git a/src/style.cpp b/src/style.cpp index fa8aed68e..49a13604b 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -14,7 +14,7 @@ * Copyright (C) 2001 Ximian, Inc. * Copyright (C) 2005 Monash University * Copyright (C) 2012 Kris De Gussem - * Copyright (C) 2014 Tavmjong Bah + * Copyright (C) 2014-2015 Tavmjong Bah * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -118,6 +118,15 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : font(), // SPIFont font_specification( "-inkscape-font-specification" ), // SPIString + // Font variants + font_variant_ligatures( "font-variant-ligatures", enum_font_variant_ligatures, SP_CSS_FONT_VARIANT_LIGATURES_NORMAL ), + font_variant_position( "font-variant-position", enum_font_variant_position, SP_CSS_FONT_VARIANT_POSITION_NORMAL ), + font_variant_caps( "font-variant-caps", enum_font_variant_caps, SP_CSS_FONT_VARIANT_CAPS_NORMAL ), + font_variant_numeric( "font-variant-numeric", enum_font_variant_numeric, SP_CSS_FONT_VARIANT_NUMERIC_NORMAL ), + font_variant_alternates("font-variant-alternates", enum_font_variant_alternates, SP_CSS_FONT_VARIANT_ALTERNATES_NORMAL ), + font_variant_east_asian("font-variant-east_asian", enum_font_variant_east_asian, SP_CSS_FONT_VARIANT_EAST_ASIAN_NORMAL ), + font_feature_settings( "font-feature-settings", "normal" ), + // Text related properties text_indent( "text-indent", 0.0 ), // SPILength text_align( "text-align", enum_text_align, SP_CSS_TEXT_ALIGN_START ), @@ -288,6 +297,15 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : _properties.push_back( &font ); _properties.push_back( &font_specification ); + // Font variants + _properties.push_back( &font_variant_ligatures ); + _properties.push_back( &font_variant_position ); + _properties.push_back( &font_variant_caps ); + _properties.push_back( &font_variant_numeric ); + _properties.push_back( &font_variant_alternates ); + _properties.push_back( &font_variant_east_asian ); + _properties.push_back( &font_feature_settings ); + _properties.push_back( &text_indent ); _properties.push_back( &text_align ); @@ -374,6 +392,14 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : // _propmap.insert( std::make_pair( font.name, reinterpret_cast(&SPStyle::font ) ) ); // _propmap.insert( std::make_pair( font_specification.name, reinterpret_cast(&SPStyle::font_specification ) ) ); + // font_variant_ligatures ); + // font_variant_position ); + // font_variant_caps ); + // font_variant_numeric ); + // font_variant_alternates ); + // font_variant_east_asian ); + // font_feature_settings ); + // _propmap.insert( std::make_pair( text_indent.name, reinterpret_cast(&SPStyle::text_indent ) ) ); // _propmap.insert( std::make_pair( text_align.name, reinterpret_cast(&SPStyle::text_align ) ) ); @@ -574,9 +600,9 @@ SPStyle::read( SPObject *object, Inkscape::XML::Node *repr ) { // std::cout << " MERGING PRESENTATION ATTRIBUTES" << std::endl; for(std::vector::size_type i = 0; i != _properties.size(); ++i) { - // Shorthands are not allowed as presentation properites. - // Note: text-decoration is converted to a shorthand in CSS 3 but can still be - // read as a non-shorthand so it should not be in this list. + // Shorthands are not allowed as presentation properites. Note: text-decoration and + // font-variant are converted to shorthands in CSS 3 but can still be read as a + // non-shorthand for compatability with older renders, so they should not be in this list. // We could add a flag to SPIBase to avoid string comparison. if( _properties[i]->name.compare( "font" ) != 0 && _properties[i]->name.compare( "marker" ) != 0 ) { @@ -694,6 +720,29 @@ SPStyle::readIfUnset( gint id, gchar const *val ) { font.readIfUnset( val ); break; + /* Font Variants CSS 3 */ + case SP_PROP_FONT_VARIANT_LIGATURES: + font_variant_ligatures.readIfUnset( val ); + break; + case SP_PROP_FONT_VARIANT_POSITION: + font_variant_position.readIfUnset( val ); + break; + case SP_PROP_FONT_VARIANT_CAPS: + font_variant_caps.readIfUnset( val ); + break; + case SP_PROP_FONT_VARIANT_NUMERIC: + font_variant_numeric.readIfUnset( val ); + break; + case SP_PROP_FONT_VARIANT_ALTERNATES: + font_variant_alternates.readIfUnset( val ); + break; + case SP_PROP_FONT_VARIANT_EAST_ASIAN: + font_variant_east_asian.readIfUnset( val ); + break; + case SP_PROP_FONT_FEATURE_SETTINGS: + font_feature_settings.readIfUnset( val ); + break; + /* Text */ case SP_PROP_TEXT_INDENT: text_indent.readIfUnset( val ); diff --git a/src/style.h b/src/style.h index ab34476b3..2618662f5 100644 --- a/src/style.h +++ b/src/style.h @@ -94,7 +94,7 @@ public: /** Font style */ SPIEnum font_style; - /** Which substyle of the font */ + /** Which substyle of the font (CSS 2. CSS 3 redefines as shorthand) */ SPIEnum font_variant; /** Weight of the font */ SPIEnum font_weight; @@ -111,6 +111,22 @@ public: /** Full font name, as font_factory::ConstructFontSpecification would give, for internal use. */ SPIString font_specification; + /* Font variants -------------------- */ + /** Font variant ligatures */ + SPIEnum font_variant_ligatures; + /** Font variant position (subscript/superscript) */ + SPIEnum font_variant_position; + /** Font variant caps (small caps) */ + SPIEnum font_variant_caps; + /** Font variant numeric (numerical formatting) */ + SPIEnum font_variant_numeric; + /** Font variant alternates (alternates/swatches) */ + SPIEnum font_variant_alternates; + /** Font variant East Asian */ + SPIEnum font_variant_east_asian; + /** Font feature settings (Low level access to TrueType tables) */ + SPIString font_feature_settings; + /* Text ----------------------------- */ /** First line indent of paragraphs (css2 16.1) */ -- cgit v1.2.3 From 9c2dcd93aa8c7e2975bda72f92603fcd0a343a95 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Wed, 6 May 2015 17:21:03 +0200 Subject: UI. Fix for Bug #1450877 (GUI glitch in Object Properties) Fixed bugs: - https://launchpad.net/bugs/1450877 (bzr r14116) --- src/ui/dialog/object-properties.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/object-properties.cpp b/src/ui/dialog/object-properties.cpp index dfe211e94..fc21a30d4 100644 --- a/src/ui/dialog/object-properties.cpp +++ b/src/ui/dialog/object-properties.cpp @@ -467,14 +467,14 @@ void ObjectProperties::_labelChanged() gchar *id = g_strdup(_entry_id.get_text().c_str()); g_strcanon(id, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.:", '_'); if (strcmp(id, item->getId()) == 0) { - _label_id.set_markup_with_mnemonic(_("_ID:")); + _label_id.set_markup_with_mnemonic(_("_ID:") + Glib::ustring(" ")); } else if (!*id || !isalnum (*id)) { _label_id.set_text(_("Id invalid! ")); } else if (SP_ACTIVE_DOCUMENT->getObjectById(id) != NULL) { _label_id.set_text(_("Id exists! ")); } else { SPException ex; - _label_id.set_markup_with_mnemonic(_("_ID:")); + _label_id.set_markup_with_mnemonic(_("_ID:") + Glib::ustring(" ")); SP_EXCEPTION_INIT(&ex); item->setAttribute("id", id, &ex); DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, _("Set object ID")); -- cgit v1.2.3 From 8c3f982781088c386acb4105119b19d9c7160502 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 7 May 2015 00:10:23 +0200 Subject: fix crash due to logic error in Selection::_removeObjectDescendants (bzr r14117) --- src/selection.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/selection.cpp b/src/selection.cpp index 53772c381..f728f3381 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -481,17 +481,21 @@ std::vector Selection::getSnapPoints(SnapPreferenc } void Selection::_removeObjectDescendants(SPObject *obj) { + std::vector toremove; for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { SPObject *sel_obj= *iter; SPObject *parent = sel_obj->parent; while (parent) { if ( parent == obj ) { - _remove(sel_obj); + toremove.push_back(sel_obj); break; } parent = parent->parent; } } + for ( std::vector::const_iterator iter=toremove.begin();iter!=toremove.end();iter++ ) { + _remove(*iter); + } } void Selection::_removeObjectAncestors(SPObject *obj) { -- cgit v1.2.3 From fe6f8f1b7976197de20964be02e594d058aead84 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 7 May 2015 00:39:26 +0200 Subject: "select same..." no longer returns groups. (bzr r14118) --- src/selection-chemistry.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index f444f4217..7a5c2c2d5 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1837,6 +1837,15 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea Inkscape::Selection *selection = desktop->getSelection(); std::vector items = selection->itemList(); + + std::vector tmp; + for (std::vector::const_iterator iter=all_list.begin();iter!=all_list.end();iter++) { + if(!SP_IS_GROUP(*iter)){ + tmp.push_back(*iter); + } + } + all_list=tmp; + for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { SPItem *sel = *sel_iter; std::vector matches = all_list; -- cgit v1.2.3 From c8aad8eba683cd12ddfde4acca3870e859216f21 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 7 May 2015 01:18:59 +0200 Subject: fix sorts (bzr r14119) --- src/selection-chemistry.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 7a5c2c2d5..8bc62d4b9 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -927,7 +927,7 @@ static SPObject *prev_sibling(SPObject *child) return prev; } -int sp_item_repr_compare_position_obj(SPObject const *first, SPObject const *second) +bool sp_item_repr_compare_position_bool(SPObject const *first, SPObject const *second) { return sp_repr_compare_position(((SPItem*)first)->getRepr(), ((SPItem*)second)->getRepr())<0; @@ -952,7 +952,7 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) /* Construct reverse-ordered list of selected children. */ std::vector rev(items); - sort(rev.begin(),rev.end(),sp_item_repr_compare_position); + sort(rev.begin(),rev.end(),sp_item_repr_compare_position_bool); // Determine the common bbox of the selected items. Geom::OptRect selected = enclose_items(items); @@ -1034,7 +1034,7 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) /* Construct direct-ordered list of selected children. */ std::vector rev(items); - sort(rev.begin(),rev.end(),sp_item_repr_compare_position); + sort(rev.begin(),rev.end(),sp_item_repr_compare_position_bool); // Iterate over all objects in the selection (starting from top). if (selected) { @@ -3518,7 +3518,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) std::vector items(selection->itemList()); // Sort items so that the topmost comes last - sort(items.begin(),items.end(),sp_item_repr_compare_position); + sort(items.begin(),items.end(),sp_item_repr_compare_position_bool); // Generate a random value from the current time (you may create bitmap from the same object(s) // multiple times, and this is done so that they don't clash) -- cgit v1.2.3 From a06c4852edb10e38fce19fd2df3833c03b6a15e4 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 8 May 2015 00:12:09 +0200 Subject: fix crash when converting a group of objects to path (bzr r14121) --- src/path-chemistry.cpp | 8 ++++++-- src/selection-chemistry.cpp | 16 ++++++++++++---- src/ui/tools/eraser-tool.cpp | 4 +++- 3 files changed, 21 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 8d2695b85..98148b916 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -388,7 +388,9 @@ sp_item_list_to_curves(const std::vector &items, std::vector& if (repr) { to_select.insert(to_select.begin(),repr); did = true; - selected.erase(find(selected.begin(),selected.end(),item)); + std::vector::iterator element=find(selected.begin(),selected.end(),item); + if(element != selected.end()) + selected.erase(find(selected.begin(),selected.end(),item)); } continue; @@ -413,7 +415,9 @@ sp_item_list_to_curves(const std::vector &items, std::vector& continue; did = true; - selected.erase(find(selected.begin(),selected.end(),item)); + std::vector::iterator element=find(selected.begin(),selected.end(),item); + if(element != selected.end()) + selected.erase(element); // remember the position of the item gint pos = item->getRepr()->position(); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 8bc62d4b9..3a68b03e5 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3922,7 +3922,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = apply_to_items ; NULL != i ; i = i->next) { reprs_to_group.push_back(static_cast(i->data)->getRepr()); - items_to_select.erase(find(items_to_select.begin(),items_to_select.end(),static_cast(i->data))); + std::vector::iterator element = find(items_to_select.begin(),items_to_select.end(),static_cast(i->data)); + if(element != items_to_select.end()) + items_to_select.erase(element); } sp_selection_group_impl(reprs_to_group, group, xml_doc, doc); @@ -3972,7 +3974,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::XML::Node *spnew = current->duplicate(xml_doc); gint position = current->position(); - items_to_select.erase(find(items_to_select.begin(),items_to_select.end(),item)); + std::vector::iterator element = find(items_to_select.begin(),items_to_select.end(),item); + if(element != items_to_select.end()) + items_to_select.erase(element); current->parent()->appendChild(group); sp_repr_unparent(current); group->appendChild(spnew); @@ -3996,7 +4000,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = items_to_delete; NULL != i; i = i->next) { SPObject *item = reinterpret_cast(i->data); item->deleteObject(false); - items_to_select.erase(find(items_to_select.begin(),items_to_select.end(),item)); + std::vector::iterator element = find(items_to_select.begin(),items_to_select.end(),item); + if(element != items_to_select.end()) + items_to_select.erase(element); } g_slist_free(items_to_delete); @@ -4121,7 +4127,9 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { for (GSList *i = items_to_ungroup ; NULL != i ; i = i->next) { SPGroup *group = dynamic_cast(static_cast(i->data)); if (group) { - items_to_select.erase(find(items_to_select.begin(),items_to_select.end(),group)); + std::vector::iterator element = find(items_to_select.begin(),items_to_select.end(),group); + if(element != items_to_select.end()) + items_to_select.erase(element); std::vector children; sp_item_group_ungroup(group, children, false); items_to_select.insert(items_to_select.end(),children.rbegin(),children.rend()); diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 01b75fdb4..0af347bef 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -674,7 +674,9 @@ void EraserTool::set_to_accumulated() { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); } - toWorkOn.erase(find(toWorkOn.begin(),toWorkOn.end(),acid)); + std::vector::iterator element = find(toWorkOn.begin(),toWorkOn.end(),acid); + if(element != toWorkOn.end()) + toWorkOn.erase(element); } else { toWorkOn= selection->itemList(); wasSelection = true; -- cgit v1.2.3 From fbe59eb1913a779115d9c4769a4066d08e30ff44 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 8 May 2015 00:25:20 +0200 Subject: better fix, using std::remove instead of std::erase (bzr r14122) --- src/path-chemistry.cpp | 8 ++------ src/selection-chemistry.cpp | 16 ++++------------ src/ui/tools/eraser-tool.cpp | 4 +--- 3 files changed, 7 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 98148b916..ff307cd66 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -388,9 +388,7 @@ sp_item_list_to_curves(const std::vector &items, std::vector& if (repr) { to_select.insert(to_select.begin(),repr); did = true; - std::vector::iterator element=find(selected.begin(),selected.end(),item); - if(element != selected.end()) - selected.erase(find(selected.begin(),selected.end(),item)); + remove(selected.begin(),selected.end(),item); } continue; @@ -415,9 +413,7 @@ sp_item_list_to_curves(const std::vector &items, std::vector& continue; did = true; - std::vector::iterator element=find(selected.begin(),selected.end(),item); - if(element != selected.end()) - selected.erase(element); + remove(selected.begin(),selected.end(),item); // remember the position of the item gint pos = item->getRepr()->position(); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 3a68b03e5..1e3afc6a8 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3922,9 +3922,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = apply_to_items ; NULL != i ; i = i->next) { reprs_to_group.push_back(static_cast(i->data)->getRepr()); - std::vector::iterator element = find(items_to_select.begin(),items_to_select.end(),static_cast(i->data)); - if(element != items_to_select.end()) - items_to_select.erase(element); + remove(items_to_select.begin(),items_to_select.end(),static_cast(i->data)); } sp_selection_group_impl(reprs_to_group, group, xml_doc, doc); @@ -3974,9 +3972,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::XML::Node *spnew = current->duplicate(xml_doc); gint position = current->position(); - std::vector::iterator element = find(items_to_select.begin(),items_to_select.end(),item); - if(element != items_to_select.end()) - items_to_select.erase(element); + remove(items_to_select.begin(),items_to_select.end(),item); current->parent()->appendChild(group); sp_repr_unparent(current); group->appendChild(spnew); @@ -4000,9 +3996,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = items_to_delete; NULL != i; i = i->next) { SPObject *item = reinterpret_cast(i->data); item->deleteObject(false); - std::vector::iterator element = find(items_to_select.begin(),items_to_select.end(),item); - if(element != items_to_select.end()) - items_to_select.erase(element); + remove(items_to_select.begin(),items_to_select.end(),item); } g_slist_free(items_to_delete); @@ -4127,9 +4121,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { for (GSList *i = items_to_ungroup ; NULL != i ; i = i->next) { SPGroup *group = dynamic_cast(static_cast(i->data)); if (group) { - std::vector::iterator element = find(items_to_select.begin(),items_to_select.end(),group); - if(element != items_to_select.end()) - items_to_select.erase(element); + remove(items_to_select.begin(),items_to_select.end(),group); std::vector children; sp_item_group_ungroup(group, children, false); items_to_select.insert(items_to_select.end(),children.rbegin(),children.rend()); diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 0af347bef..8a9db6c72 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -674,9 +674,7 @@ void EraserTool::set_to_accumulated() { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); } - std::vector::iterator element = find(toWorkOn.begin(),toWorkOn.end(),acid); - if(element != toWorkOn.end()) - toWorkOn.erase(element); + std::remove(toWorkOn.begin(),toWorkOn.end(),acid); } else { toWorkOn= selection->itemList(); wasSelection = true; -- cgit v1.2.3 From 57808dd1abe86ae0088a74bd88041321f5df5fb8 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 8 May 2015 00:45:15 +0200 Subject: fix for stl "remove" (bzr r14123) --- src/path-chemistry.cpp | 4 ++-- src/selection-chemistry.cpp | 8 ++++---- src/ui/tools/eraser-tool.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index ff307cd66..7bd5b6298 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -388,7 +388,7 @@ sp_item_list_to_curves(const std::vector &items, std::vector& if (repr) { to_select.insert(to_select.begin(),repr); did = true; - remove(selected.begin(),selected.end(),item); + selected.erase(remove(selected.begin(), selected.end(), item), selected.end()); } continue; @@ -413,7 +413,7 @@ sp_item_list_to_curves(const std::vector &items, std::vector& continue; did = true; - remove(selected.begin(),selected.end(),item); + selected.erase(remove(selected.begin(), selected.end(), item), selected.end()); // remember the position of the item gint pos = item->getRepr()->position(); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 1e3afc6a8..2cd4f6b4e 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3922,7 +3922,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = apply_to_items ; NULL != i ; i = i->next) { reprs_to_group.push_back(static_cast(i->data)->getRepr()); - remove(items_to_select.begin(),items_to_select.end(),static_cast(i->data)); + items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), static_cast(i->data)), items_to_select.end()); } sp_selection_group_impl(reprs_to_group, group, xml_doc, doc); @@ -3972,7 +3972,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::XML::Node *spnew = current->duplicate(xml_doc); gint position = current->position(); - remove(items_to_select.begin(),items_to_select.end(),item); + items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), item), items_to_select.end()); current->parent()->appendChild(group); sp_repr_unparent(current); group->appendChild(spnew); @@ -3996,7 +3996,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = items_to_delete; NULL != i; i = i->next) { SPObject *item = reinterpret_cast(i->data); item->deleteObject(false); - remove(items_to_select.begin(),items_to_select.end(),item); + items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), item), items_to_select.end()); } g_slist_free(items_to_delete); @@ -4121,7 +4121,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { for (GSList *i = items_to_ungroup ; NULL != i ; i = i->next) { SPGroup *group = dynamic_cast(static_cast(i->data)); if (group) { - remove(items_to_select.begin(),items_to_select.end(),group); + items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), group), items_to_select.end()); std::vector children; sp_item_group_ungroup(group, children, false); items_to_select.insert(items_to_select.end(),children.rbegin(),children.rend()); diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 8a9db6c72..10f8c8694 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -674,7 +674,7 @@ void EraserTool::set_to_accumulated() { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); } - std::remove(toWorkOn.begin(),toWorkOn.end(),acid); + toWorkOn.erase(std::remove(toWorkOn.begin(), toWorkOn.end(), acid), toWorkOn.end()); } else { toWorkOn= selection->itemList(); wasSelection = true; -- cgit v1.2.3 From 0f23d91bdb4d8fca7be0c695e65a10b205fee1fc Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 8 May 2015 02:49:43 +0200 Subject: Fixed the layer blends (bzr r14124) --- src/ui/widget/object-composite-settings.cpp | 4 ++-- src/ui/widget/style-subject.cpp | 24 ++++++++++++------------ src/ui/widget/style-subject.h | 10 +++------- 3 files changed, 17 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp index 598a90e95..8acf083d0 100644 --- a/src/ui/widget/object-composite-settings.cpp +++ b/src/ui/widget/object-composite-settings.cpp @@ -125,8 +125,8 @@ ObjectCompositeSettings::_blendBlurValueChanged() const Glib::ustring blendmode = _fe_cb.get_blend_mode(); //apply created filter to every selected item - std::vector sel=_subject->getDesktop()->getSelection()->itemList(); - for (std::vector::const_iterator i = sel.begin() ; i != sel.end() ; ++i ) { + std::vector sel=_subject->list(); + for (std::vector::const_iterator i = sel.begin() ; i != sel.end() ; ++i ) { if (!SP_IS_ITEM(*i)) { continue; } diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp index 95b89bf5f..da3bbcd20 100644 --- a/src/ui/widget/style-subject.cpp +++ b/src/ui/widget/style-subject.cpp @@ -54,15 +54,13 @@ Inkscape::Selection *StyleSubject::Selection::_getSelection() const { return NULL; } } -/* -StyleSubject::iterator StyleSubject::Selection::begin() { + +std::vector StyleSubject::Selection::list(){ Inkscape::Selection *selection = _getSelection(); - if (selection) { - return iterator(selection->list()); - } else { - return iterator(NULL); - } -}*/ + if(selection) + return selection->list(); + else return std::vector(); +} Geom::OptRect StyleSubject::Selection::getBounds(SPItem::BBoxType type) { Inkscape::Selection *selection = _getSelection(); @@ -133,10 +131,12 @@ SPObject *StyleSubject::CurrentLayer::_getLayerSList() const { return _element; } -/* -StyleSubject::iterator StyleSubject::CurrentLayer::begin() { - return iterator(_getLayerSList()); -}*/ + +std::vector StyleSubject::CurrentLayer::list(){ + std::vector list; + list.push_back(_element); + return list; +} Geom::OptRect StyleSubject::CurrentLayer::getBounds(SPItem::BBoxType type) { SPObject *layer = _getLayer(); diff --git a/src/ui/widget/style-subject.h b/src/ui/widget/style-subject.h index 60f979eb0..15a072f44 100644 --- a/src/ui/widget/style-subject.h +++ b/src/ui/widget/style-subject.h @@ -10,7 +10,6 @@ #ifndef SEEN_INKSCAPE_UI_WIDGET_STYLE_SUBJECT_H #define SEEN_INKSCAPE_UI_WIDGET_STYLE_SUBJECT_H -#include "util/glib-list-iterators.h" #include #include <2geom/rect.h> #include "sp-item.h" @@ -35,8 +34,6 @@ public: class Selection; class CurrentLayer; - //typedef Util::GSListConstIterator iterator; - typedef std::list::iterator iterator; StyleSubject(); virtual ~StyleSubject(); @@ -44,11 +41,10 @@ public: void setDesktop(SPDesktop *desktop); SPDesktop *getDesktop() const { return _desktop; } -// virtual iterator begin() = 0; -// virtual iterator end() { return iterator(NULL); } virtual Geom::OptRect getBounds(SPItem::BBoxType type) = 0; virtual int queryStyle(SPStyle *query, int property) = 0; virtual void setCSS(SPCSSAttr *css) = 0; + virtual std::vector list(){return std::vector();}; sigc::connection connectChanged(sigc::signal::slot_type slot) { return _changed_signal.connect(slot); @@ -68,10 +64,10 @@ public: Selection(); ~Selection(); -// virtual iterator begin(); virtual Geom::OptRect getBounds(SPItem::BBoxType type); virtual int queryStyle(SPStyle *query, int property); virtual void setCSS(SPCSSAttr *css); + virtual std::vector list(); protected: virtual void _afterDesktopSwitch(SPDesktop *desktop); @@ -89,10 +85,10 @@ public: CurrentLayer(); ~CurrentLayer(); -// virtual iterator begin(); virtual Geom::OptRect getBounds(SPItem::BBoxType type); virtual int queryStyle(SPStyle *query, int property); virtual void setCSS(SPCSSAttr *css); + virtual std::vector list(); protected: virtual void _afterDesktopSwitch(SPDesktop *desktop); -- cgit v1.2.3 From 9102ee49b968e55e93a7f6ccfb563c8571bf458c Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 8 May 2015 03:22:12 +0200 Subject: forgotten dynamic cast (bzr r14125) --- src/extension/internal/latex-text-renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index ab863f8b1..1026f51ad 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -230,7 +230,7 @@ void LaTeXTextRenderer::sp_group_render(SPGroup *group) { std::vector l = (group->childList(false)); for(std::vector::const_iterator x = l.begin(); x != l.end(); x++){ - SPItem *item = static_cast(*x); + SPItem *item = dynamic_cast(*x); if (item) { renderItem(item); } -- cgit v1.2.3 From 48e0423afcb02fe4a0f705d828a0dbdb3106b397 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 8 May 2015 15:46:25 +0200 Subject: fixes a few of jenkins warnings (bzr r14126) --- src/desktop.cpp | 1 - src/display/canvas-arena.cpp | 2 +- src/document.cpp | 2 +- src/extension/implementation/script.cpp | 16 ++++++++++------ src/extension/internal/cairo-render-context.cpp | 1 + src/extension/internal/wmf-inout.cpp | 6 ++---- src/file.cpp | 6 +++--- src/gradient-drag.cpp | 2 +- src/helper-fns.h | 2 +- src/helper/geom.cpp | 9 ++------- src/inkview.cpp | 2 +- src/libavoid/connector.cpp | 6 +----- src/libavoid/graph.cpp | 4 +++- src/libavoid/orthogonal.cpp | 1 - src/live_effects/lpe-gears.cpp | 2 +- src/live_effects/lpe-taperstroke.cpp | 4 ---- src/live_effects/parameter/filletchamferpointarray.cpp | 1 - src/selection.cpp | 3 ++- src/sp-item-transform.cpp | 6 +++--- src/trace/siox.cpp | 2 +- src/ui/dialog/document-properties.cpp | 4 ++-- src/ui/dialog/floating-behavior.cpp | 2 +- src/ui/dialog/grid-arrange-tab.cpp | 1 - src/ui/dialog/icon-preview.cpp | 2 +- src/ui/interface.cpp | 2 +- src/ui/tools/box3d-tool.cpp | 2 +- src/ui/tools/flood-tool.cpp | 2 +- src/ui/tools/pen-tool.cpp | 15 ++++----------- src/ui/tools/pencil-tool.cpp | 3 --- src/ui/tools/rect-tool.cpp | 1 - src/ui/tools/select-tool.cpp | 1 - src/util/ziptool.cpp | 2 +- src/widgets/desktop-widget.cpp | 4 +++- src/widgets/ege-adjustment-action.cpp | 2 +- src/widgets/gradient-vector.cpp | 1 + 35 files changed, 51 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/desktop.cpp b/src/desktop.cpp index 5a1558b0f..02df50c6b 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -947,7 +947,6 @@ void SPDesktop::zoom_quick(bool enable) if (!zoomed) { zoom_relative(_quick_zoom_stored_area.midpoint()[Geom::X], _quick_zoom_stored_area.midpoint()[Geom::Y], 2.0); - zoomed = true; } } else { set_display_area(_quick_zoom_stored_area, false); diff --git a/src/display/canvas-arena.cpp b/src/display/canvas-arena.cpp index 8738b93e4..ec99eca9a 100644 --- a/src/display/canvas-arena.cpp +++ b/src/display/canvas-arena.cpp @@ -290,7 +290,7 @@ sp_canvas_arena_event (SPCanvasItem *item, GdkEvent *event) ret = sp_canvas_arena_send_event (arena, (GdkEvent *) &ec); } } - ret = sp_canvas_arena_send_event (arena, event); + ret = ret || sp_canvas_arena_send_event (arena, event); break; case GDK_SCROLL: { diff --git a/src/document.cpp b/src/document.cpp index f06953e34..741e7c812 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1591,7 +1591,7 @@ static void vacuum_document_recursive(SPObject *obj) unsigned int SPDocument::vacuumDocument() { unsigned int start = objects_in_document(this); - unsigned int end = start; + unsigned int end; unsigned int newend = start; unsigned int iterations = 0; diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 5cab3a2b2..e07a3963c 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -812,6 +812,12 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr } } + if(!oldroot_namedview) + { + g_warning("Error on copy_doc: No namedview on destination document."); + return; + } + // Unparent (delete) for (unsigned int i = 0; i < delete_list.size(); i++) { sp_repr_unparent(delete_list[i]); @@ -823,12 +829,10 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr 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; - newroot_namedview_child = newroot_namedview_child->next()) { - oldroot_namedview->appendChild(newroot_namedview_child->duplicate(oldroot->document())); - } + for (Inkscape::XML::Node * newroot_namedview_child = child->firstChild(); + newroot_namedview_child != NULL; + newroot_namedview_child = newroot_namedview_child->next()) { + oldroot_namedview->appendChild(newroot_namedview_child->duplicate(oldroot->document())); } } else { oldroot->appendChild(child->duplicate(oldroot->document())); diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index 2d6619e1e..27e34dbcf 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -1393,6 +1393,7 @@ CairoRenderContext::_setStrokeStyle(SPStyle const *style, Geom::OptRect const &p dashes[i] = style->stroke_dasharray.values[i]; } cairo_set_dash(_cr, dashes, ndashes, style->stroke_dashoffset.value); + free(dashes); } else { cairo_set_dash(_cr, NULL, 0, 0.0); // disable dashing } diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index 3ab7a4e89..f76fa16b4 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -95,7 +95,6 @@ Wmf::print_document_to_file(SPDocument *doc, const gchar *filename) SPPrintContext context; const gchar *oldconst; gchar *oldoutput; - unsigned int ret; doc->ensureUpToDate(); @@ -114,13 +113,12 @@ Wmf::print_document_to_file(SPDocument *doc, const gchar *filename) mod->root = mod->base->invoke_show(drawing, mod->dkey, SP_ITEM_SHOW_DISPLAY); drawing.setRoot(mod->root); /* Print document */ - ret = mod->begin(doc); - if (ret) { + if (mod->begin(doc)) { g_free(oldoutput); throw Inkscape::Extension::Output::save_failed(); } mod->base->invoke_print(&context); - ret = mod->finish(); + mod->finish(); /* Release arena */ mod->base->invoke_hide(mod->dkey); mod->base = NULL; diff --git a/src/file.cpp b/src/file.cpp index d1dd2bcd6..984bf7e08 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -769,7 +769,7 @@ file_save_remote(SPDocument */*doc*/, return false; } - result = gnome_vfs_create (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL); + gnome_vfs_create (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL); result = gnome_vfs_open (&to_handle, uri_local, GNOME_VFS_OPEN_WRITE); if (result != GNOME_VFS_OK) { @@ -782,8 +782,8 @@ file_save_remote(SPDocument */*doc*/, result = gnome_vfs_read (from_handle, buffer, 8192, &bytes_read); if ((result == GNOME_VFS_ERROR_EOF) &&(!bytes_read)){ - result = gnome_vfs_close (from_handle); - result = gnome_vfs_close (to_handle); + gnome_vfs_close (from_handle); + gnome_vfs_close (to_handle); return true; } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 169710114..b22714959 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -1155,7 +1155,7 @@ static void gr_knot_clicked_handler(SPKnot */*knot*/, guint state, gpointer data break; default: - break; + return; } diff --git a/src/helper-fns.h b/src/helper-fns.h index 2f1829c37..79771a001 100644 --- a/src/helper-fns.h +++ b/src/helper-fns.h @@ -78,7 +78,7 @@ inline std::vector helperfns_read_vector(const gchar* value){ g_warning("helper-fns::helperfns_read_vector() Unable to convert \"%s\" to number", beg); // We could leave this out, too. If strtod can't convert // anything, it will return zero. - ret = 0; + // ret = 0; break; } v.push_back(ret); diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index 91689375f..77cba4736 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -266,14 +266,13 @@ geom_cubic_bbox_wind_distance (Geom::Coord x000, Geom::Coord y000, Geom::Coord tolerance) { Geom::Coord x0, y0, x1, y1, len2; - int needdist, needwind, needline; + int needdist, needwind; const Geom::Coord Px = pt[X]; const Geom::Coord Py = pt[Y]; needdist = 0; needwind = 0; - needline = 0; if (bbox) cubic_bbox (x000, y000, x001, y001, x011, y011, x111, y111, *bbox); @@ -303,8 +302,6 @@ geom_cubic_bbox_wind_distance (Geom::Coord x000, Geom::Coord y000, /* fixme: (Lauris) */ if (((y1 - y0) > 5.0) || ((x1 - x0) > 5.0)) { needdist = 1; - } else { - needline = 1; } } } @@ -315,8 +312,6 @@ geom_cubic_bbox_wind_distance (Geom::Coord x000, Geom::Coord y000, /* fixme: (Lauris) */ if (((y1 - y0) > 5.0) || ((x1 - x0) > 5.0)) { needwind = 1; - } else { - needline = 1; } } } @@ -345,7 +340,7 @@ geom_cubic_bbox_wind_distance (Geom::Coord x000, Geom::Coord y000, geom_cubic_bbox_wind_distance (x000, y000, x00t, y00t, x0tt, y0tt, xttt, yttt, pt, NULL, wind, best, tolerance); geom_cubic_bbox_wind_distance (xttt, yttt, x1tt, y1tt, x11t, y11t, x111, y111, pt, NULL, wind, best, tolerance); - } else if (1 || needline) { + } else { geom_line_wind_distance (x000, y000, x111, y111, pt, wind, best); } } diff --git a/src/inkview.cpp b/src/inkview.cpp index 2c667237e..8b7492798 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -274,7 +274,7 @@ main (int argc, const char **argv) gchar *last_filename = jar_file_reader.get_last_filename(); if (ss.doc) { ss.slides[ss.length++] = strdup (last_filename); - (ss.doc)->setUri (strdup(last_filename)); + (ss.doc)->setUri (last_filename); } g_byte_array_free(gba, TRUE); g_free(last_filename); diff --git a/src/libavoid/connector.cpp b/src/libavoid/connector.cpp index 40ded7498..36892c668 100644 --- a/src/libavoid/connector.cpp +++ b/src/libavoid/connector.cpp @@ -1476,7 +1476,6 @@ CrossingsInfoPair countRealCrossings(Avoid::Polygon& poly, int prevTurnDir = -1; int startCornerSide = 1; int endCornerSide = 1; - bool reversed = false; if (!front_same) { // If there is a divergence at the beginning, @@ -1485,7 +1484,6 @@ CrossingsInfoPair countRealCrossings(Avoid::Polygon& poly, startCornerSide = Avoid::cornerSide(*c_path[0], *c_path[1], *c_path[2], *p_path[0]) * segDir(*c_path[1], *c_path[2]); - reversed = (startCornerSide != -prevTurnDir); } if (!back_same) { @@ -1497,7 +1495,6 @@ CrossingsInfoPair countRealCrossings(Avoid::Polygon& poly, *c_path[size - 2], *c_path[size - 1], *p_path[size - 1]) * segDir(*c_path[size - 3], *c_path[size - 2]); - reversed = (endCornerSide != -prevTurnDir); } else { @@ -1578,10 +1575,9 @@ CrossingsInfoPair countRealCrossings(Avoid::Polygon& poly, } } #endif - prevTurnDir = 0; if (pointOrders) { - reversed = false; + bool reversed = false; size_t startPt = (front_same) ? 0 : 1; // Orthogonal should always have at least one segment. diff --git a/src/libavoid/graph.cpp b/src/libavoid/graph.cpp index 728f8c085..5b617f123 100644 --- a/src/libavoid/graph.cpp +++ b/src/libavoid/graph.cpp @@ -129,7 +129,9 @@ static inline int orthogTurnOrder(const Point& a, const Point& b, // Note: This method assumes the two Edges that share a common point. bool EdgeInf::rotationLessThan(const VertInf *lastV, const EdgeInf *rhs) const { - if ((_v1 == rhs->_v1) && (_v2 == rhs->_v2)) + assert(_v1 == rhs->_v1 || _v1 == rhs->_v2 || _v2 == rhs->_v1 || _v2 == rhs->_v2 ); + + if ((_v1 == rhs->_v1) && (_v2 == rhs->_v2)) { // Effectively the same visibility edge, so they are equal. return false; diff --git a/src/libavoid/orthogonal.cpp b/src/libavoid/orthogonal.cpp index b5ef8d7e8..466d1dd58 100644 --- a/src/libavoid/orthogonal.cpp +++ b/src/libavoid/orthogonal.cpp @@ -1548,7 +1548,6 @@ extern void generateStaticOrthogonalVisGraph(Router *router) // Process the horizontal sweep thisPos = (totalEvents > 0) ? events[0]->pos : 0; posStartIndex = 0; - posFinishIndex = 0; for (unsigned i = 0; i <= totalEvents; ++i) { // If we have finished the current scanline or all events, then we diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index 003e22567..fafe143b5 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -168,7 +168,7 @@ Geom::Path Gear::path() { D2 root = _arc(cursor, cursor+root_advance, root_radius()); makeContinuous(root, prev); pb.append(SBasisCurve(root)); - cursor += root_advance; + //cursor += root_advance; prev = root.at1(); if (base_radius() > root_radius()) { diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index 2c74af6d6..451810d04 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -389,13 +389,9 @@ Piecewise > stretch_along(Piecewise > pwd2_in, Geom::Path x0 -= pattBndsX->min(); y0 -= pattBndsY->middle(); - double xspace = 0; double noffset = 0; double toffset = 0; // Prevent more than 90% overlap... - if (xspace < -pattBndsX->extent()*.9) { - xspace = -pattBndsX->extent()*.9; - } y0+=noffset; diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index e9d375b93..f05f401e4 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -506,7 +506,6 @@ std::vector FilletChamferPointArrayParam::get_times(int index, std::vect time_it1 = 0; } double resultLenght = 0; - time_it1_B = 1; if (subpaths[positions.first].closed() && last) { time_it2 = modf(to_time(index - positions.second , _vector[index - positions.second ][X]), &intpart); resultLenght = it1_length + to_len(index - positions.second, _vector[index - positions.second ][X]); diff --git a/src/selection.cpp b/src/selection.cpp index f728f3381..7979b5d61 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -178,6 +178,7 @@ void Selection::_add(SPObject *obj) { // (to prevent double-selection) _removeObjectDescendants(obj); _removeObjectAncestors(obj); + g_return_if_fail(SP_IS_OBJECT(obj)); _objs.push_front(obj); _objs_set.insert(obj); @@ -483,7 +484,7 @@ std::vector Selection::getSnapPoints(SnapPreferenc void Selection::_removeObjectDescendants(SPObject *obj) { std::vector toremove; for ( std::list::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { - SPObject *sel_obj= *iter; + SPObject *sel_obj= dynamic_cast(*iter); SPObject *parent = sel_obj->parent; while (parent) { if ( parent == obj ) { diff --git a/src/sp-item-transform.cpp b/src/sp-item-transform.cpp index 767f0ed91..f1c69cdf6 100644 --- a/src/sp-item-transform.cpp +++ b/src/sp-item-transform.cpp @@ -152,7 +152,7 @@ Geom::Affine get_scale_transform_for_uniform_stroke(Geom::Rect const &bbox_visua gdouble scale_x = 1; gdouble scale_y = 1; - gdouble r1 = r0; + gdouble r1; if ((fabs(w0 - stroke_x) < 1e-6) || w1 == 0) { // We have a vertical line at hand scale_y = h1/h0; @@ -310,8 +310,8 @@ Geom::Affine get_scale_transform_for_variable_stroke(Geom::Rect const &bbox_visu gdouble scale_x = 1; gdouble scale_y = 1; - gdouble r1h = r0h; - gdouble r1w = r0w; + gdouble r1h; + gdouble r1w; if ((fabs(w0 - r0w) < 1e-6) || w1 == 0) { // We have a vertical line at hand scale_y = h1/h0; diff --git a/src/trace/siox.cpp b/src/trace/siox.cpp index 065e891ed..9df4e561c 100644 --- a/src/trace/siox.cpp +++ b/src/trace/siox.cpp @@ -682,7 +682,7 @@ GdkPixbuf *SioxImage::getGdkPixbuf() } row += rowstride; } - + free(pixdata); return buf; } diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index c381ed755..b04e8ecc1 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -1672,10 +1672,10 @@ void DocumentProperties::onDocUnitChange() Inkscape::XML::Node *repr = getDesktop()->getNamedView()->getRepr(); - Inkscape::Util::Unit const *old_doc_unit = unit_table.getUnit("px"); + /*Inkscape::Util::Unit const *old_doc_unit = unit_table.getUnit("px"); if(repr->attribute("inkscape:document-units")) { old_doc_unit = unit_table.getUnit(repr->attribute("inkscape:document-units")); - } + }*/ Inkscape::Util::Unit const *doc_unit = _rum_deflt.getUnit(); // Set document unit diff --git a/src/ui/dialog/floating-behavior.cpp b/src/ui/dialog/floating-behavior.cpp index 740acd989..55ef0c5bb 100644 --- a/src/ui/dialog/floating-behavior.cpp +++ b/src/ui/dialog/floating-behavior.cpp @@ -112,7 +112,7 @@ bool FloatingBehavior::_trans_timer (void) { } float goal, current; - goal = current = _d->get_opacity(); + current = _d->get_opacity(); if (_dialog_active.get_value()) { goal = _trans_focus; diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index 4465d73a9..c44f66a4d 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -170,7 +170,6 @@ void GridArrangeTab::arrange() Inkscape::Selection *selection = desktop->getSelection(); const std::vector items = selection ? selection->itemList() : std::vector(); - cnt=0; for(std::vector::const_iterator i = items.begin();i!=items.end();i++){ SPItem *item = *i; Geom::OptRect b = item->documentVisualBounds(); diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index 7dc55c95c..77f120e1a 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -312,7 +312,7 @@ void IconPreviewPanel::setDesktop( SPDesktop* desktop ) if ( this->desktop ) { docReplacedConn = this->desktop->connectDocumentReplaced(sigc::hide<0>(sigc::mem_fun(this, &IconPreviewPanel::setDocument))); if ( this->desktop->selection && Inkscape::Preferences::get()->getBool("/iconpreview/autoRefresh", true) ) { - selChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(this, &IconPreviewPanel::queueRefresh))); + selChangedConn = this->desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(this, &IconPreviewPanel::queueRefresh))); } } } diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 760d19e89..a129d4b92 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -439,7 +439,7 @@ sp_ui_dialog_title_string(Inkscape::Verb *verb, gchar *c) gchar* key = sp_shortcut_get_label(shortcut); s = g_stpcpy(s, " ("); s = g_stpcpy(s, key); - s = g_stpcpy(s, ")"); + g_stpcpy(s, ")"); g_free(key); } } diff --git a/src/ui/tools/box3d-tool.cpp b/src/ui/tools/box3d-tool.cpp index 538e0c7e2..27e755add 100644 --- a/src/ui/tools/box3d-tool.cpp +++ b/src/ui/tools/box3d-tool.cpp @@ -165,7 +165,7 @@ bool Box3dTool::item_handler(SPItem* item, GdkEvent* event) { case GDK_BUTTON_PRESS: if ( event->button.button == 1 && !this->space_panning) { Inkscape::setup_for_drag_start(desktop, this, event); - ret = TRUE; + //ret = TRUE; } break; // motion and release are always on root (why?) diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp index ffd41d97d..748c82717 100644 --- a/src/ui/tools/flood-tool.cpp +++ b/src/ui/tools/flood-tool.cpp @@ -932,7 +932,7 @@ static void sp_flood_do_flood_fill(ToolBase *event_context, GdkEvent *event, boo std::deque::iterator start_sort = fill_queue.begin(); std::deque::iterator end_sort = fill_queue.begin(); unsigned int sort_y = (unsigned int)cp[Geom::Y]; - unsigned int current_y = sort_y; + unsigned int current_y; for (std::deque::iterator i = fill_queue.begin(); i != fill_queue.end(); ++i) { Geom::Point current = *i; diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index daffc7032..be6156fa2 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -762,14 +762,12 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) { } } this->state = PenTool::CONTROL; - ret = true; break; case PenTool::CONTROL: // End current segment this->_endpointSnap(p, revent.state); this->_finishSegment(p, revent.state); this->state = PenTool::POINT; - ret = true; break; case PenTool::CLOSE: // End current segment @@ -783,12 +781,10 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) { } this->_finish(true); this->state = PenTool::POINT; - ret = true; break; case PenTool::STOP: // This is allowed, if we just canceled curve this->state = PenTool::POINT; - ret = true; break; default: break; @@ -823,7 +819,6 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) { break; } this->state = PenTool::POINT; - ret = true; break; default: break; @@ -1432,8 +1427,7 @@ void PenTool::_bsplineSpiroStartAnchorOn() { using Geom::X; using Geom::Y; - SPCurve *tmp_curve = new SPCurve(); - tmp_curve = this->sa->curve->copy(); + SPCurve *tmp_curve = this->sa->curve->copy(); if(this->sa->start) tmp_curve = tmp_curve ->create_reverse(); Geom::CubicBezier const * cubic = dynamic_cast(&*tmp_curve ->last_segment()); @@ -1465,8 +1459,7 @@ void PenTool::_bsplineSpiroStartAnchorOn() void PenTool::_bsplineSpiroStartAnchorOff() { - SPCurve *tmp_curve = new SPCurve(); - tmp_curve = this->sa->curve->copy(); + SPCurve *tmp_curve = this->sa->curve->copy(); if(this->sa->start) tmp_curve = tmp_curve ->create_reverse(); Geom::CubicBezier const * cubic = dynamic_cast(&*tmp_curve ->last_segment()); @@ -1564,7 +1557,7 @@ void PenTool::_bsplineSpiroEndAnchorOn() using Geom::Y; this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]); this->p[2] = Geom::Point(this->p[2][X] + HANDLE_CUBIC_GAP,this->p[2][Y] + HANDLE_CUBIC_GAP); - SPCurve *tmp_curve = new SPCurve(); + SPCurve *tmp_curve; SPCurve *last_segment = new SPCurve(); Geom::Point point_c(0,0); bool reverse = false; @@ -1621,7 +1614,7 @@ void PenTool::_bsplineSpiroEndAnchorOn() void PenTool::_bsplineSpiroEndAnchorOff() { - SPCurve *tmp_curve = new SPCurve(); + SPCurve *tmp_curve; SPCurve *last_segment = new SPCurve(); bool reverse = false; this->p[2] = this->p[3]; diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 008804162..ba103fa8e 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -357,7 +357,6 @@ bool PencilTool::_handleButtonRelease(GdkEventButton const &revent) { // Ctrl+click creates a single point so only set context in ADDLINE mode when Ctrl isn't pressed this->state = SP_PENCIL_CONTEXT_ADDLINE; } - ret = true; break; case SP_PENCIL_CONTEXT_ADDLINE: /* Finish segment now */ @@ -371,7 +370,6 @@ bool PencilTool::_handleButtonRelease(GdkEventButton const &revent) { this->_finishEndpoint(); this->state = SP_PENCIL_CONTEXT_IDLE; sp_event_context_discard_delayed_snap_event(this); - ret = true; break; case SP_PENCIL_CONTEXT_FREEHAND: if (revent.state & GDK_MOD1_MASK) { @@ -413,7 +411,6 @@ bool PencilTool::_handleButtonRelease(GdkEventButton const &revent) { // reset sketch mode too this->sketch_n = 0; } - ret = true; break; case SP_PENCIL_CONTEXT_SKETCH: default: diff --git a/src/ui/tools/rect-tool.cpp b/src/ui/tools/rect-tool.cpp index 62a9006ea..844965c4d 100644 --- a/src/ui/tools/rect-tool.cpp +++ b/src/ui/tools/rect-tool.cpp @@ -143,7 +143,6 @@ bool RectTool::item_handler(SPItem* item, GdkEvent* event) { case GDK_BUTTON_PRESS: if ( event->button.button == 1 && !this->space_panning) { Inkscape::setup_for_drag_start(desktop, this, event); - ret = TRUE; } break; // motion and release are always on root (why?) diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index f8375a1bb..f06b03d91 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -777,7 +777,6 @@ bool SelectTool::root_handler(GdkEvent* event) { } rb_escaped = 0; - ret = TRUE; } } } diff --git a/src/util/ziptool.cpp b/src/util/ziptool.cpp index cf024008f..2eb516b2e 100644 --- a/src/util/ziptool.cpp +++ b/src/util/ziptool.cpp @@ -2605,7 +2605,7 @@ bool ZipFile::readFileData() if (gpBitFlag & 0x8)//bit 3 was set. means we dont know compressed size { unsigned char c1, c2, c3, c4; - c1 = c2 = c3 = c4 = 0; + c2 = c3 = c4 = 0; while (true) { unsigned char ch; diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index fd3756220..e19f56e48 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -1433,8 +1433,10 @@ sp_desktop_widget_maximize(SPDesktopWidget *dtw) if (!dtw->desktop->is_iconified() && !dtw->desktop->is_fullscreen()) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint w, h, x, y; + gint w = -1; + gint h, x, y; dtw->getWindowGeometry(x, y, w, h); + g_assert(w != -1); prefs->setInt("/desktop/geometry/width", w); prefs->setInt("/desktop/geometry/height", h); prefs->setInt("/desktop/geometry/x", x); diff --git a/src/widgets/ege-adjustment-action.cpp b/src/widgets/ege-adjustment-action.cpp index d89a6e3f1..a91149f4c 100644 --- a/src/widgets/ege-adjustment-action.cpp +++ b/src/widgets/ege-adjustment-action.cpp @@ -742,7 +742,7 @@ static GtkWidget* create_popup_number_menu( EgeAdjustmentAction* act ) if ( act->private_data->descriptions ) { gdouble value = ((EgeAdjustmentDescr*)act->private_data->descriptions->data)->value; - addOns = flush_explicit_items( addOns, G_CALLBACK(process_menu_action), BUMP_CUSTOM, menu, act, &single, &group, value ); + flush_explicit_items( addOns, G_CALLBACK(process_menu_action), BUMP_CUSTOM, menu, act, &single, &group, value ); } return menu; diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index d2c46ffec..10d1cc107 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -548,6 +548,7 @@ static void verify_grad(SPGradient *gradient) child->setAttribute("style", os.str().c_str()); gradient->getRepr()->addChild(child, NULL); Inkscape::GC::release(child); + return; } if (i < 2) { sp_repr_set_css_double(stop->getRepr(), "offset", 0.0); -- cgit v1.2.3 From 72d3556428cd68013cb604a708f27d3de0f60855 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 8 May 2015 17:19:23 +0200 Subject: fix for bug 1391374. apparently, libnrtype drastically misses unit tests. Fixed bugs: - https://launchpad.net/bugs/1391374 (bzr r14127) --- src/libnrtype/Layout-TNG-OutIter.cpp | 4 ++-- src/libnrtype/Layout-TNG.h | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/libnrtype/Layout-TNG-OutIter.cpp b/src/libnrtype/Layout-TNG-OutIter.cpp index c9c318960..707897f50 100644 --- a/src/libnrtype/Layout-TNG-OutIter.cpp +++ b/src/libnrtype/Layout-TNG-OutIter.cpp @@ -788,12 +788,12 @@ bool Layout::iterator::prevLineCursor(int n) { if (!_cursor_moving_vertically) beginCursorUpDown(); - unsigned line_index; + int line_index; if (_char_index == _parent_layout->_characters.size()) line_index = _parent_layout->_lines.size() - 1; else line_index = _parent_layout->_characters[_char_index].chunk(_parent_layout).in_line; - if (line_index == 0) + if (line_index <= 0) return false; // nowhere to go else n = MIN (n, static_cast(line_index)); diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h index e91c32ebe..26db1fad9 100644 --- a/src/libnrtype/Layout-TNG.h +++ b/src/libnrtype/Layout-TNG.h @@ -701,7 +701,11 @@ private: /** The overall block-progression of the whole flow. */ inline Direction _blockProgression() const - {return static_cast(_input_stream.front())->styleGetBlockProgression();} + { + if(!_input_stream.empty()) + return static_cast(_input_stream.front())->styleGetBlockProgression(); + return TOP_TO_BOTTOM; + } /** so that LEFT_TO_RIGHT == RIGHT_TO_LEFT but != TOP_TO_BOTTOM */ static bool _directions_are_orthogonal(Direction d1, Direction d2); -- cgit v1.2.3 From 1caee668eff9e8afe58a7592eb78908c96b530ba Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 8 May 2015 19:16:19 +0200 Subject: fix for bug 168013 and its mask counterpart Fixed bugs: - https://launchpad.net/bugs/168013 (bzr r14129) --- src/sp-use.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/sp-use.cpp b/src/sp-use.cpp index 239f487a4..c8a0830c1 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -22,6 +22,8 @@ #include "display/drawing-group.h" #include "attributes.h" #include "document.h" +#include "sp-clippath.h" +#include "sp-mask.h" #include "sp-factory.h" #include "sp-flowregion.h" #include "uri.h" @@ -426,16 +428,43 @@ void SPUse::move_compensate(Geom::Affine const *mp) { return; Geom::Affine m(*mp); + Geom::Affine t = this->get_parent_transform(); + Geom::Affine clone_move = t.inverse() * m * t; // this is not a simple move, do not try to compensate - if (!(m.isTranslation())) + if (!(m.isTranslation())){ + //BUT move clippaths accordingly. + //if clone has a clippath, move it accordingly + if(clip_ref->getObject()){ + SPObject *clip = clip_ref->getObject()->firstChild() ; + while(clip){ + SPItem *item = (SPItem*) clip; + if(item){ + item->transform *= m; + Geom::Affine identity; + item->doWriteTransform(clip->getRepr(),item->transform, &identity); + } + clip = clip->getNext(); + } + } + if(mask_ref->getObject()){ + SPObject *mask = mask_ref->getObject()->firstChild() ; + while(mask){ + SPItem *item = (SPItem*) mask; + if(item){ + item->transform *= m; + Geom::Affine identity; + item->doWriteTransform(mask->getRepr(),item->transform, &identity); + } + mask = mask->getNext(); + } + } return; + } // restore item->transform field from the repr, in case it was changed by seltrans this->readAttr ("transform"); - Geom::Affine t = this->get_parent_transform(); - Geom::Affine clone_move = t.inverse() * m * t; // calculate the compensation matrix and the advertized movement matrix Geom::Affine advertized_move; @@ -449,6 +478,33 @@ void SPUse::move_compensate(Geom::Affine const *mp) { g_assert_not_reached(); } + //if clone has a clippath, move it accordingly + if(clip_ref->getObject()){ + SPObject *clip = clip_ref->getObject()->firstChild() ; + while(clip){ + SPItem *item = (SPItem*) clip; + if(item){ + item->transform *= clone_move.inverse(); + Geom::Affine identity; + item->doWriteTransform(clip->getRepr(),item->transform, &identity); + } + clip = clip->getNext(); + } + } + if(mask_ref->getObject()){ + SPObject *mask = mask_ref->getObject()->firstChild() ; + while(mask){ + SPItem *item = (SPItem*) mask; + if(item){ + item->transform *= clone_move.inverse(); + Geom::Affine identity; + item->doWriteTransform(mask->getRepr(),item->transform, &identity); + } + mask = mask->getNext(); + } + } + + // commit the compensation this->transform *= clone_move; this->doWriteTransform(this->getRepr(), this->transform, &advertized_move); -- cgit v1.2.3 From 76268cdf97916d0de571586ff1111b90c1a65286 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 9 May 2015 00:04:46 +0200 Subject: fixes various bugs with clipping and masking Fixed bugs: - https://launchpad.net/bugs/569281 - https://launchpad.net/bugs/1319171 - https://launchpad.net/bugs/1177650 (bzr r14130) --- src/selection-chemistry.cpp | 34 ++++++++++++++++------------------ src/sp-clippath.cpp | 3 +-- src/sp-mask.cpp | 3 +-- 3 files changed, 18 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 2cd4f6b4e..f72bd1259 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3893,14 +3893,17 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ items_to_select.push_back(*i); } } else { - SPItem *i = NULL; - for (std::vector::const_iterator j=items.begin();j!=items.end();j++) { - i=*j; + SPItem *i = items.front(); + for (std::vector::const_iterator j=items.begin();(j+1)!=items.end();j++) { apply_to_items = g_slist_prepend(apply_to_items, i); items_to_select.push_back(i); + i=*(j+1); } - + Geom::Affine oldtr=i->transform; + i->doWriteTransform(i->getRepr(), i->i2doc_affine()); Inkscape::XML::Node *dup = SP_OBJECT(i)->getRepr()->duplicate(xml_doc); + i->doWriteTransform(i->getRepr(), oldtr); + mask_items = g_slist_prepend(mask_items, dup); if (remove_original) { @@ -3922,8 +3925,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ for (GSList *i = apply_to_items ; NULL != i ; i = i->next) { reprs_to_group.push_back(static_cast(i->data)->getRepr()); - items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), static_cast(i->data)), items_to_select.end()); + //items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), static_cast(i->data)), items_to_select.end()); } + items_to_select.clear(); sp_selection_group_impl(reprs_to_group, group, xml_doc, doc); @@ -3936,30 +3940,25 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::GC::release(group); } + if (grouping == PREFS_MASKOBJECT_GROUPING_SEPARATE) { + items_to_select.clear(); + } + gchar const *attributeName = apply_clip_path ? "clip-path" : "mask"; for (GSList *i = apply_to_items; NULL != i; i = i->next) { SPItem *item = reinterpret_cast(i->data); // inverted object transform should be applied to a mask object, // as mask is calculated in user space (after applying transform) - Geom::Affine maskTransform(item->transform.inverse()); - - GSList *mask_items_dup = NULL; - for (GSList *mask_item = mask_items; NULL != mask_item; mask_item = mask_item->next) { - Inkscape::XML::Node *dup = reinterpret_cast(mask_item->data)->duplicate(xml_doc); - mask_items_dup = g_slist_prepend(mask_items_dup, dup); - } + Geom::Affine maskTransform(item->i2doc_affine().inverse()); gchar const *mask_id = NULL; if (apply_clip_path) { - mask_id = SPClipPath::create(mask_items_dup, doc, &maskTransform); + mask_id = SPClipPath::create(mask_items, doc, &maskTransform); } else { - mask_id = sp_mask_create(mask_items_dup, doc, &maskTransform); + mask_id = sp_mask_create(mask_items, doc, &maskTransform); } - g_slist_free(mask_items_dup); - mask_items_dup = NULL; - Inkscape::XML::Node *current = SP_OBJECT(i->data)->getRepr(); // Node to apply mask to Inkscape::XML::Node *apply_mask_to = current; @@ -3972,7 +3971,6 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::XML::Node *spnew = current->duplicate(xml_doc); gint position = current->position(); - items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), item), items_to_select.end()); current->parent()->appendChild(group); sp_repr_unparent(current); group->appendChild(spnew); diff --git a/src/sp-clippath.cpp b/src/sp-clippath.cpp index 3c6167438..0c13ca80d 100644 --- a/src/sp-clippath.cpp +++ b/src/sp-clippath.cpp @@ -313,8 +313,7 @@ const gchar *SPClipPath::create (GSList *reprs, SPDocument *document, Geom::Affi SPItem *item = SP_ITEM(clip_path_object->appendChildRepr(node)); if (NULL != applyTransform) { - Geom::Affine transform (item->transform); - transform *= (*applyTransform); + Geom::Affine transform (item->transform * (*applyTransform)); item->doWriteTransform(item->getRepr(), transform); } } diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp index d60473e1d..c36c3c005 100644 --- a/src/sp-mask.cpp +++ b/src/sp-mask.cpp @@ -226,8 +226,7 @@ sp_mask_create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTr SPItem *item = SP_ITEM(mask_object->appendChildRepr(node)); if (NULL != applyTransform) { - Geom::Affine transform (item->transform); - transform *= (*applyTransform); + Geom::Affine transform (item->transform * (*applyTransform)); item->doWriteTransform(item->getRepr(), transform); } } -- cgit v1.2.3 From 7cb183695ed9eec9fb3e08045e4a265d10eca76e Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 9 May 2015 01:05:06 +0200 Subject: refactor sp_selection_set_mask (bzr r14131) --- src/selection-chemistry.cpp | 94 +++++++++++++++------------------------------ src/sp-clippath.cpp | 6 +-- src/sp-clippath.h | 2 +- src/sp-mask.cpp | 6 +-- src/sp-mask.h | 2 +- 5 files changed, 40 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index f72bd1259..7be1e3ec0 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3787,13 +3787,11 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) clone->setAttribute("inkscape:transform-center-y", inner->attribute("inkscape:transform-center-y"), false); const Geom::Affine maskTransform(Geom::Affine::identity()); - GSList *templist = NULL; - - templist = g_slist_append(templist, clone); + std::vector templist; + templist.push_back(clone); // add the new clone to the top of the original's parent gchar const *mask_id = SPClipPath::create(templist, doc, &maskTransform); - g_slist_free(templist); outer->setAttribute("clip-path", g_strdup_printf("url(#%s)", mask_id)); @@ -3851,9 +3849,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ selection->clear(); // create a list of duplicates - GSList *mask_items = NULL; - GSList *apply_to_items = NULL; - GSList *items_to_delete = NULL; + std::vector mask_items; + std::vector apply_to_items; + std::vector items_to_delete; std::vector items_to_select; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -3863,57 +3861,36 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ if (apply_to_layer) { // all selected items are used for mask, which is applied to a layer - apply_to_items = g_slist_prepend(apply_to_items, desktop->currentLayer()); + apply_to_items.push_back(SP_ITEM(desktop->currentLayer())); + } + + for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { + if((!topmost && !apply_to_layer && *i == items.front()) + || (topmost && !apply_to_layer && *i == items.back()) + || apply_to_layer){ - for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { + Geom::Affine oldtr=(*i)->transform; + (*i)->doWriteTransform((*i)->getRepr(), (*i)->i2doc_affine()); Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); - mask_items = g_slist_prepend(mask_items, dup); + (*i)->doWriteTransform((*i)->getRepr(), oldtr); + mask_items.push_back(dup); - SPObject *item = *i; if (remove_original) { - items_to_delete = g_slist_prepend(items_to_delete, item); + items_to_delete.push_back(*i); } else { - items_to_select.push_back((SPItem*)item); + items_to_select.push_back(*i); } - } - } else if (!topmost) { - // topmost item is used as a mask, which is applied to other items in a selection - Inkscape::XML::Node *dup = items[0]->getRepr()->duplicate(xml_doc); - mask_items = g_slist_prepend(mask_items, dup); - - if (remove_original) { - SPObject *item = items.front(); - items_to_delete = g_slist_prepend(items_to_delete, item); - } - - for (std::vector::const_iterator i=items.begin();i!=items.end();i++) { - if(i==items.begin())continue; - apply_to_items = g_slist_prepend(apply_to_items, *i); + continue; + }else{ + apply_to_items.push_back(*i); items_to_select.push_back(*i); } - } else { - SPItem *i = items.front(); - for (std::vector::const_iterator j=items.begin();(j+1)!=items.end();j++) { - apply_to_items = g_slist_prepend(apply_to_items, i); - items_to_select.push_back(i); - i=*(j+1); - } - Geom::Affine oldtr=i->transform; - i->doWriteTransform(i->getRepr(), i->i2doc_affine()); - Inkscape::XML::Node *dup = SP_OBJECT(i)->getRepr()->duplicate(xml_doc); - i->doWriteTransform(i->getRepr(), oldtr); - - mask_items = g_slist_prepend(mask_items, dup); - - if (remove_original) { - SPObject *item = reinterpret_cast(i); - items_to_delete = g_slist_prepend(items_to_delete, item); - } } + items.clear(); - if (apply_to_items && grouping == PREFS_MASKOBJECT_GROUPING_ALL) { + if (grouping == PREFS_MASKOBJECT_GROUPING_ALL) { // group all those objects into one group // and apply mask to that Inkscape::XML::Node *group = xml_doc->createElement("svg:g"); @@ -3922,19 +3899,16 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ group->setAttribute("inkscape:groupmode", "maskhelper"); std::vector reprs_to_group; - - for (GSList *i = apply_to_items ; NULL != i ; i = i->next) { - reprs_to_group.push_back(static_cast(i->data)->getRepr()); - //items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), static_cast(i->data)), items_to_select.end()); + for (std::vector::const_iterator i = apply_to_items.begin(); i != apply_to_items.end(); i++) { + reprs_to_group.push_back(static_cast(*i)->getRepr()); } items_to_select.clear(); sp_selection_group_impl(reprs_to_group, group, xml_doc, doc); // apply clip/mask only to newly created group - g_slist_free(apply_to_items); - apply_to_items = NULL; - apply_to_items = g_slist_prepend(apply_to_items, doc->getObjectByRepr(group)); + apply_to_items.clear(); + apply_to_items.push_back(dynamic_cast(doc->getObjectByRepr(group))); items_to_select.push_back((SPItem*)(doc->getObjectByRepr(group))); @@ -3946,8 +3920,8 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ gchar const *attributeName = apply_clip_path ? "clip-path" : "mask"; - for (GSList *i = apply_to_items; NULL != i; i = i->next) { - SPItem *item = reinterpret_cast(i->data); + for (std::vector::const_reverse_iterator i = apply_to_items.rbegin(); i != apply_to_items.rend(); i++) { + SPItem *item = reinterpret_cast(*i); // inverted object transform should be applied to a mask object, // as mask is calculated in user space (after applying transform) Geom::Affine maskTransform(item->i2doc_affine().inverse()); @@ -3959,7 +3933,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ mask_id = sp_mask_create(mask_items, doc, &maskTransform); } - Inkscape::XML::Node *current = SP_OBJECT(i->data)->getRepr(); + Inkscape::XML::Node *current = SP_OBJECT(*i)->getRepr(); // Node to apply mask to Inkscape::XML::Node *apply_mask_to = current; @@ -3988,15 +3962,11 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ } - g_slist_free(mask_items); - g_slist_free(apply_to_items); - - for (GSList *i = items_to_delete; NULL != i; i = i->next) { - SPObject *item = reinterpret_cast(i->data); + for (std::vector::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); i++) { + SPObject *item = reinterpret_cast(*i); item->deleteObject(false); items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), item), items_to_select.end()); } - g_slist_free(items_to_delete); selection->addList(items_to_select); diff --git a/src/sp-clippath.cpp b/src/sp-clippath.cpp index 0c13ca80d..d66508eae 100644 --- a/src/sp-clippath.cpp +++ b/src/sp-clippath.cpp @@ -296,7 +296,7 @@ sp_clippath_view_list_remove(SPClipPathView *list, SPClipPathView *view) } // Create a mask element (using passed elements), add it to -const gchar *SPClipPath::create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform) +const gchar *SPClipPath::create (std::vector &reprs, SPDocument *document, Geom::Affine const* applyTransform) { Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -308,8 +308,8 @@ const gchar *SPClipPath::create (GSList *reprs, SPDocument *document, Geom::Affi const gchar *id = repr->attribute("id"); SPObject *clip_path_object = document->getObjectById(id); - for (GSList *it = reprs; it != NULL; it = it->next) { - Inkscape::XML::Node *node = (Inkscape::XML::Node *)(it->data); + for (std::vector::const_iterator it = reprs.begin(); it != reprs.end(); it++) { + Inkscape::XML::Node *node = (*it); SPItem *item = SP_ITEM(clip_path_object->appendChildRepr(node)); if (NULL != applyTransform) { diff --git a/src/sp-clippath.h b/src/sp-clippath.h index eb8b14174..91dcfd625 100644 --- a/src/sp-clippath.h +++ b/src/sp-clippath.h @@ -45,7 +45,7 @@ public: unsigned int clipPathUnits : 1; SPClipPathView *display; - static char const *create(GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform); + static char const *create(std::vector &reprs, SPDocument *document, Geom::Affine const* applyTransform); //static GType sp_clippath_get_type(void); Inkscape::DrawingItem *show(Inkscape::Drawing &drawing, unsigned int key); diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp index c36c3c005..f8fb7aff4 100644 --- a/src/sp-mask.cpp +++ b/src/sp-mask.cpp @@ -209,7 +209,7 @@ Inkscape::XML::Node* SPMask::write(Inkscape::XML::Document* xml_doc, Inkscape::X // Create a mask element (using passed elements), add it to const gchar * -sp_mask_create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform) +sp_mask_create (std::vector &reprs, SPDocument *document, Geom::Affine const* applyTransform) { Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -221,8 +221,8 @@ sp_mask_create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTr const gchar *mask_id = repr->attribute("id"); SPObject *mask_object = document->getObjectById(mask_id); - for (GSList *it = reprs; it != NULL; it = it->next) { - Inkscape::XML::Node *node = (Inkscape::XML::Node *)(it->data); + for (std::vector::const_iterator it = reprs.begin(); it != reprs.end(); it++) { + Inkscape::XML::Node *node = (*it); SPItem *item = SP_ITEM(mask_object->appendChildRepr(node)); if (NULL != applyTransform) { diff --git a/src/sp-mask.h b/src/sp-mask.h index e991fedb6..3559483bb 100644 --- a/src/sp-mask.h +++ b/src/sp-mask.h @@ -108,6 +108,6 @@ protected: } }; -const char *sp_mask_create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform); +const char *sp_mask_create (std::vector &reprs, SPDocument *document, Geom::Affine const* applyTransform); #endif // SEEN_SP_MASK_H -- cgit v1.2.3 From 31c3977006f63720ca6aa473585760da7d59a833 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 9 May 2015 01:50:13 +0200 Subject: fixed logic error in earlier fix (bzr r14132) --- src/selection-chemistry.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 7be1e3ec0..4352878d6 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3924,15 +3924,6 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ SPItem *item = reinterpret_cast(*i); // inverted object transform should be applied to a mask object, // as mask is calculated in user space (after applying transform) - Geom::Affine maskTransform(item->i2doc_affine().inverse()); - - gchar const *mask_id = NULL; - if (apply_clip_path) { - mask_id = SPClipPath::create(mask_items, doc, &maskTransform); - } else { - mask_id = sp_mask_create(mask_items, doc, &maskTransform); - } - Inkscape::XML::Node *current = SP_OBJECT(*i)->getRepr(); // Node to apply mask to Inkscape::XML::Node *apply_mask_to = current; @@ -3953,11 +3944,22 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // Apply clip/mask to group instead apply_mask_to = group; - items_to_select.push_back((SPItem*)(doc->getObjectByRepr(group))); + items_to_select.push_back(item = (SPItem*)(doc->getObjectByRepr(group))); Inkscape::GC::release(spnew); Inkscape::GC::release(group); } + + + Geom::Affine maskTransform(item->i2doc_affine().inverse()); + + gchar const *mask_id = NULL; + if (apply_clip_path) { + mask_id = SPClipPath::create(mask_items, doc, &maskTransform); + } else { + mask_id = sp_mask_create(mask_items, doc, &maskTransform); + } + apply_mask_to->setAttribute(attributeName, Glib::ustring("url(#") + mask_id + ')'); } -- cgit v1.2.3 From 13fc1db22c959600f7b179abf1a70ca42ab587de Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 9 May 2015 02:57:05 +0200 Subject: fix crash introduces by recent rev when clipping (bzr r14133) --- src/selection-chemistry.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 4352878d6..a21a82983 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3924,6 +3924,9 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ SPItem *item = reinterpret_cast(*i); // inverted object transform should be applied to a mask object, // as mask is calculated in user space (after applying transform) + std::vector mask_items_dup; + for(std::vector::const_iterator it=mask_items.begin();it!=mask_items.end();it++) + mask_items_dup.push_back((*it)->duplicate(xml_doc)); Inkscape::XML::Node *current = SP_OBJECT(*i)->getRepr(); // Node to apply mask to Inkscape::XML::Node *apply_mask_to = current; @@ -3949,15 +3952,13 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ Inkscape::GC::release(group); } - - Geom::Affine maskTransform(item->i2doc_affine().inverse()); gchar const *mask_id = NULL; if (apply_clip_path) { - mask_id = SPClipPath::create(mask_items, doc, &maskTransform); + mask_id = SPClipPath::create(mask_items_dup, doc, &maskTransform); } else { - mask_id = sp_mask_create(mask_items, doc, &maskTransform); + mask_id = sp_mask_create(mask_items_dup, doc, &maskTransform); } apply_mask_to->setAttribute(attributeName, Glib::ustring("url(#") + mask_id + ')'); -- cgit v1.2.3 From 9b1d6715ff2a56c9f1b94c0f8474c3e4efd48539 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 9 May 2015 14:59:00 +0200 Subject: duplicating layers now respect prefs for clone relinking Fixed bugs: - https://launchpad.net/bugs/267565 (bzr r14134) --- src/selection-chemistry.cpp | 25 ++++++++++++++++++++----- src/selection-chemistry.h | 2 +- src/verbs.cpp | 36 +++--------------------------------- 3 files changed, 24 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index a21a82983..d6e9a1e32 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -107,6 +107,7 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS; #include "live_effects/effect.h" #include "live_effects/effect-enum.h" #include "live_effects/parameter/originalpath.h" +#include "layer-manager.h" #include "enums.h" #include "sp-item-group.h" @@ -438,7 +439,7 @@ static void add_ids_recursive(std::vector &ids, SPObject *obj) } } -void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) +void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone, bool duplicateLayer) { if (desktop == NULL) { return; @@ -449,12 +450,17 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected - if (selection->isEmpty()) { + if (selection->isEmpty() && !duplicateLayer) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to duplicate.")); return; } std::vector reprs(selection->reprList()); + if(duplicateLayer){ + reprs.clear(); + reprs.push_back(desktop->currentLayer()->getRepr()); + } + selection->clear(); // sorting items from different parents sorts each parent's subset without possibly mixing @@ -474,7 +480,10 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - parent->appendChild(copy); + if(! duplicateLayer) + parent->appendChild(copy); + else + parent->addChild(copy, old_repr); if (relink_clones) { SPObject *old_obj = doc->getObjectByRepr(old_repr); @@ -535,8 +544,14 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_DUPLICATE, _("Duplicate")); } - - selection->setReprList(newsel); + if(!duplicateLayer) + selection->setReprList(newsel); + else{ + SPObject* new_layer = doc->getObjectByRepr(newsel[0]); + gchar* name = g_strdup_printf(_("%s copy"), new_layer->label()); + desktop->layer_manager->renameLayer( new_layer, name, TRUE ); + g_free(name); + } } void sp_edit_clear_all(Inkscape::Selection *selection) diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 8bcab664b..5bcc5b1ea 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -52,7 +52,7 @@ namespace LivePathEffect { } // namespace Inkscape void sp_selection_delete(SPDesktop *desktop); -void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone = false); +void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone = false, bool duplicateLayer = false); void sp_edit_clear_all(Inkscape::Selection *selection); void sp_edit_select_all(SPDesktop *desktop); diff --git a/src/verbs.cpp b/src/verbs.cpp index ea2c06dcf..e0ef27b0d 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1350,39 +1350,9 @@ void LayerVerb::perform(SPAction *action, void *data) } case SP_VERB_LAYER_DUPLICATE: { if ( dt->currentLayer() != dt->currentRoot() ) { - // Note with either approach: - // Any clone masters are duplicated, their clones use the *original*, - // but the duplicated master is not linked up as master nor clone of the original. -#if 0 - // Only copies selectable things, honoring locks, visibility, avoids sublayers. - SPObject *new_layer = Inkscape::create_layer(dt->currentRoot(), dt->currentLayer(), LPOS_BELOW); - if ( dt->currentLayer()->label() ) { - gchar* name = g_strdup_printf(_("%s copy"), dt->currentLayer()->label()); - dt->layer_manager->renameLayer( new_layer, name, TRUE ); - g_free(name); - } - sp_edit_select_all(dt); - sp_selection_duplicate(dt, true); - sp_selection_to_prev_layer(dt, true); - dt->setCurrentLayer(new_layer); - sp_edit_select_all(dt); -#else - // Copies everything, regardless of locks, visibility, sublayers. - //XML Tree being directly used here while it shouldn't be. - Inkscape::XML::Node *selected = dt->currentLayer()->getRepr(); - Inkscape::XML::Node *parent = selected->parent(); - Inkscape::XML::Node *dup = selected->duplicate(parent->document()); - parent->addChild(dup, selected); - SPObject *new_layer = dt->currentLayer()->next; - if (new_layer) { - if (new_layer->label()) { - gchar* name = g_strdup_printf(_("%s copy"), new_layer->label()); - dt->layer_manager->renameLayer( new_layer, name, TRUE ); - g_free(name); - } - dt->setCurrentLayer(new_layer); - } -#endif + + sp_selection_duplicate(dt, true, true); + DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_DUPLICATE, _("Duplicate layer")); -- cgit v1.2.3 From 5e862e0de5ba75615a722fff471008a3cedb3212 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 9 May 2015 17:39:31 +0200 Subject: Fix potential crash in FontLister (bzr r14135) --- src/libnrtype/font-lister.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index a6ab3b239..70374864a 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -335,7 +335,7 @@ Glib::ustring FontLister::system_fontspec(Glib::ustring fontspec) PangoFontDescription *descr = pango_font_description_from_string(fontspec.c_str()); font_instance *res = (font_factory::Default())->Face(descr); - if (res->pFont) { + if (res && res->pFont) { PangoFontDescription *nFaceDesc = pango_font_describe(res->pFont); out = sp_font_description_get_family(nFaceDesc); } -- cgit v1.2.3 From 78cee203a59243dcabbf67499682ce720be6d1d6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 9 May 2015 17:50:08 +0200 Subject: Remove documentUnits from live_effect/effect.cpp/h Remove units from fillet-chamfer and roughen (bzr r14136) --- src/live_effects/effect.cpp | 3 --- src/live_effects/effect.h | 1 - src/live_effects/lpe-fillet-chamfer.cpp | 7 +------ src/live_effects/lpe-fillet-chamfer.h | 1 - src/live_effects/lpe-roughen.cpp | 22 +++------------------- src/live_effects/lpe-roughen.h | 2 -- .../parameter/filletchamferpointarray.cpp | 12 +----------- .../parameter/filletchamferpointarray.h | 4 ---- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 22 ++-------------------- src/ui/dialog/lpe-fillet-chamfer-properties.h | 8 +------- 10 files changed, 8 insertions(+), 74 deletions(-) (limited to 'src') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 1da364580..53097171b 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -364,7 +364,6 @@ Effect::Effect(LivePathEffectObject *lpeobject) lpeobj(lpeobject), concatenate_before_pwd2(false), sp_lpe_item(NULL), - defaultUnit("px"), current_zoom(1), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden @@ -454,7 +453,6 @@ void Effect::doOnRemove (SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - defaultUnit = sp_lpe_item->document->getDisplayUnit()->abbr; /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); pathvector_before_effect = sp_curve->get_pathvector();*/ doOnApply(lpeitem); @@ -463,7 +461,6 @@ void Effect::doOnApply_impl(SPLPEItem const* lpeitem) void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - defaultUnit = sp_lpe_item->document->getDisplayUnit()->abbr; //printf("(SPLPEITEM*) %p\n", sp_lpe_item); SPShape * shape = dynamic_cast(sp_lpe_item); if(shape){ diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index ac1f0b8dc..a6b5a13ea 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -159,7 +159,6 @@ protected: bool concatenate_before_pwd2; SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. - Glib::ustring defaultUnit; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. double current_zoom; std::vector selectedNodesPoints; SPCurve * sp_curve; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index c8458b8cb..ca87c7be1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -29,7 +29,6 @@ // for programmatically updating knots #include "ui/tools-switch.h" -#include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -57,7 +56,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : only_selected(_("Change only selected nodes"), _("Change only selected nodes"), "only_selected", &wr, this, false), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), - unit(_("Unit:"), _("Unit"), "unit", &wr, this), method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 0), @@ -65,7 +63,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0) { registerParameter(&fillet_chamfer_values); - registerParameter(&unit); registerParameter(&method); registerParameter(&radius); registerParameter(&chamfer_steps); @@ -223,7 +220,7 @@ void LPEFilletChamfer::updateFillet() { double power = 0; if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), defaultUnit) * -1; + power = radius * -1; } else { power = radius; } @@ -444,9 +441,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { fillet_chamfer_values.set_helper_size(helper_size); } - fillet_chamfer_values.set_document_unit(defaultUnit); fillet_chamfer_values.set_use_distance(use_knot_distance); - fillet_chamfer_values.set_unit(unit.get_abbreviation()); SPCurve *c = SP_IS_PATH(lpeItem) ? static_cast(lpeItem) ->get_original_curve() : SP_SHAPE(lpeItem)->getCurve(); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index fb06e804c..f8e03a399 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -66,7 +66,6 @@ private: BoolParam only_selected; BoolParam flexible; BoolParam use_knot_distance; - UnitParam unit; EnumParam method; ScalarParam radius; ScalarParam chamfer_steps; diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 9d1c3152b..c5e002351 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -20,7 +20,6 @@ #include "live_effects/parameter/parameter.h" #include "helper/geom.h" #include -#include #include namespace Inkscape { @@ -36,7 +35,6 @@ DMConverter(DivisionMethodData, DM_END); LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) : Effect(lpeobject), // initialise your parameters here: - unit(_("Unit"), _("Unit"), "unit", &wr, this), method(_("Method"), _("Division method"), "method", DMConverter, &wr, this, DM_SEGMENTS), max_segment_size(_("Max. segment size"), _("Max. segment size"), @@ -54,7 +52,6 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) shift_node_handles(_("Shift node handles"), _("Shift node handles"), "shift_node_handles", &wr, this, true) { - registerParameter(&unit); registerParameter(&method); registerParameter(&max_segment_size); registerParameter(&segments); @@ -98,14 +95,6 @@ Gtk::Widget *LPERoughen::newWidget() if ((*it)->widget_is_visible) { Parameter *param = *it; Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); - if (param->param_key == "unit") { - Gtk::Label *unit_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Roughen unit")), Gtk::ALIGN_START)); - unit_label->set_use_markup(true); - vbox->pack_start(*unit_label, false, false, 2); - vbox->pack_start(*Gtk::manage(new Gtk::HSeparator()), - Gtk::PACK_EXPAND_WIDGET); - } if (param->param_key == "method") { Gtk::Label *method_label = Gtk::manage(new Gtk::Label( Glib::ustring(_("Add nodes Subdivide each segment")), @@ -160,11 +149,8 @@ double LPERoughen::sign(double random_number) Geom::Point LPERoughen::randomize() { - Inkscape::Util::Unit const *svg_units = SP_ACTIVE_DESKTOP->namedview->svg_units; - double displace_x_parsed = Inkscape::Util::Quantity::convert( - displace_x * global_randomize, unit.get_abbreviation(), svg_units->abbr); - double displace_y_parsed = Inkscape::Util::Quantity::convert( - displace_y * global_randomize, unit.get_abbreviation(), svg_units->abbr); + double displace_x_parsed = displace_x * global_randomize; + double displace_y_parsed = displace_y * global_randomize; Geom::Point output = Geom::Point(sign(displace_x_parsed), sign(displace_y_parsed)); return output; @@ -175,7 +161,6 @@ void LPERoughen::doEffect(SPCurve *curve) Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(curve->get_pathvector()); curve->reset(); - Inkscape::Util::Unit const *svg_units = SP_ACTIVE_DESKTOP->namedview->svg_units; for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) @@ -220,8 +205,7 @@ void LPERoughen::doEffect(SPCurve *curve) } else { nCurve->lineto(point3); } - double length = Inkscape::Util::Quantity::convert( - curve_it1->length(0.001), svg_units->abbr, unit.get_abbreviation()); + double length = curve_it1->length(0.001); std::size_t splits = 0; if (method == DM_SEGMENTS) { splits = segments; diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index ed9f06cf7..2b285cd40 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -17,7 +17,6 @@ #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/path.h" #include "live_effects/parameter/bool.h" -#include "live_effects/parameter/unit.h" #include "live_effects/parameter/random.h" namespace Inkscape { @@ -45,7 +44,6 @@ public: virtual Gtk::Widget *newWidget(); private: - UnitParam unit; EnumParam method; ScalarParam max_segment_size; ScalarParam segments; diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index f05f401e4..10ded4d9f 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -354,11 +354,6 @@ void FilletChamferPointArrayParam::set_pwd2( last_pwd2_normal = pwd2_normal_in; } -void FilletChamferPointArrayParam::set_document_unit(Glib::ustring value_document_unit) -{ - documentUnit = value_document_unit; -} - void FilletChamferPointArrayParam::set_helper_size(int hs) { helper_size = hs; @@ -374,11 +369,6 @@ void FilletChamferPointArrayParam::set_use_distance(bool use_knot_distance ) use_distance = use_knot_distance; } -void FilletChamferPointArrayParam::set_unit(const gchar *abbr) -{ - unit = abbr; -} - void FilletChamferPointArrayParam::updateCanvasIndicators() { std::vector ts = data(); @@ -812,7 +802,7 @@ void FilletChamferPointArrayParamKnotHolderEntity::knot_click(guint state) bool aprox = (A[0].degreesOfFreedom() != 2 || B[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; Geom::Point offset = Geom::Point(xModified, _pparam->_vector.at(_index).y()); Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, offset, this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit); + this->desktop, offset, this, _pparam->use_distance, aprox); } } diff --git a/src/live_effects/parameter/filletchamferpointarray.h b/src/live_effects/parameter/filletchamferpointarray.h index 7849d5afb..9bfd86b41 100644 --- a/src/live_effects/parameter/filletchamferpointarray.h +++ b/src/live_effects/parameter/filletchamferpointarray.h @@ -53,8 +53,6 @@ public: virtual void set_helper_size(int hs); virtual void set_use_distance(bool use_knot_distance); virtual void set_chamfer_steps(int value_chamfer_steps); - virtual void set_document_unit(Glib::ustring value_document_unit); - virtual void set_unit(const gchar *abbr); virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); virtual bool providesKnotHolderEntities() const { @@ -89,8 +87,6 @@ private: int helper_size; int chamfer_steps; bool use_distance; - const gchar *unit; - Glib::ustring documentUnit; Geom::PathVector hp; Geom::Piecewise > last_pwd2; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index f63b19e86..061055feb 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -27,7 +27,6 @@ #include "selection-chemistry.h" #include "ui/icon-names.h" #include "ui/widget/imagetoggler.h" -#include "util/units.h" #include //#include "event-context.h" @@ -122,18 +121,14 @@ void FilletChamferPropertiesDialog::showDialog( SPDesktop *desktop, Geom::Point knotpoint, const Inkscape::LivePathEffect:: FilletChamferPointArrayParamKnotHolderEntity *pt, - const gchar *unit, bool use_distance, - bool aprox_radius, - Glib::ustring documentUnit) + bool aprox_radius) { FilletChamferPropertiesDialog *dialog = new FilletChamferPropertiesDialog(); dialog->_set_desktop(desktop); - dialog->_set_unit(unit); dialog->_set_use_distance(use_distance); dialog->_set_aprox(aprox_radius); - dialog->_set_document_unit(documentUnit); dialog->_set_knot_point(knotpoint); dialog->_set_pt(pt); @@ -168,7 +163,6 @@ void FilletChamferPropertiesDialog::_apply() } d_pos = _index + (d_pos / 100); } else { - d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, document_unit); d_pos = d_pos * -1; } _knotpoint->knot_set_offset(Geom::Point(d_pos, d_width)); @@ -218,11 +212,9 @@ void FilletChamferPropertiesDialog::_set_knot_point(Geom::Point knotpoint) _fillet_chamfer_position_label.set_label(_("Position (%):")); } else { _flexible = false; - std::string posConcat = Glib::ustring::compose (_("%1 (%2):"), distance_or_radius, unit); + std::string posConcat = Glib::ustring::compose (_("%1:"), distance_or_radius); _fillet_chamfer_position_label.set_label(_(posConcat.c_str())); position = knotpoint[Geom::X] * -1; - - position = Inkscape::Util::Quantity::convert(position, document_unit, unit); } _fillet_chamfer_position_numeric.set_value(position); if (knotpoint.y() == 1) { @@ -247,16 +239,6 @@ void FilletChamferPropertiesDialog::_set_pt( pt); } -void FilletChamferPropertiesDialog::_set_unit(const gchar *abbr) -{ - unit = abbr; -} - -void FilletChamferPropertiesDialog::_set_document_unit(Glib::ustring abbr) -{ - document_unit = abbr; -} - void FilletChamferPropertiesDialog::_set_use_distance(bool use_knot_distance) { use_distance = use_knot_distance; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index 870a1734f..99494bd63 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h @@ -30,10 +30,8 @@ public: static void showDialog(SPDesktop *desktop, Geom::Point knotpoint, const Inkscape::LivePathEffect:: FilletChamferPointArrayParamKnotHolderEntity *pt, - const gchar *unit, bool use_distance, - bool aprox_radius, - Glib::ustring documentUnit); + bool aprox_radius); protected: @@ -68,15 +66,11 @@ protected: void _set_desktop(SPDesktop *desktop); void _set_pt(const Inkscape::LivePathEffect:: FilletChamferPointArrayParamKnotHolderEntity *pt); - void _set_unit(const gchar *abbr); - void _set_document_unit(Glib::ustring abbr); void _set_use_distance(bool use_knot_distance); void _set_aprox(bool aprox_radius); void _apply(); void _close(); bool _flexible; - const gchar *unit; - Glib::ustring document_unit; bool use_distance; bool aprox; void _set_knot_point(Geom::Point knotpoint); -- cgit v1.2.3 From b80ece09a1c8045cec3597f9c61b417323399290 Mon Sep 17 00:00:00 2001 From: su_v Date: Sat, 9 May 2015 19:20:42 +0200 Subject: cmake: refactor SRC lists for optional input formats (cdr, vsd, wpg) (bzr r14139) --- src/extension/CMakeLists.txt | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index d1104f3cc..21e652563 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -36,7 +36,6 @@ set(extension_SRC internal/cairo-render-context.cpp internal/cairo-renderer.cpp internal/cairo-renderer-pdf-out.cpp - internal/cdr-input.cpp internal/emf-inout.cpp internal/emf-print.cpp internal/gdkpixbuf-input.cpp @@ -54,10 +53,8 @@ set(extension_SRC internal/svg.cpp internal/svgz.cpp internal/text_reassemble.c - internal/vsd-input.cpp internal/wmf-inout.cpp internal/wmf-print.cpp - internal/wpg-input.cpp internal/filter/filter-all.cpp internal/filter/filter-file.cpp @@ -104,7 +101,6 @@ set(extension_SRC internal/cairo-render-context.h internal/cairo-renderer-pdf-out.h internal/cairo-renderer.h - internal/cdr-input.h internal/clear-n_.h internal/emf-inout.h internal/emf-print.h @@ -140,10 +136,8 @@ set(extension_SRC internal/svg.h internal/svgz.h internal/text_reassemble.h - internal/vsd-input.h internal/wmf-inout.h internal/wmf-print.h - internal/wpg-input.h ) if(WIN32) @@ -151,6 +145,20 @@ if(WIN32) ) endif() +if(WITH_LIBCDR) + list(APPEND extension_SRC + internal/cdr-input.cpp + internal/cdr-input.h + ) +endif() + +if(WITH_LIBVISIO) + list(APPEND extension_SRC + internal/vsd-input.cpp + internal/vsd-input.h + ) +endif() + if(WITH_LIBWPG) list(APPEND extension_SRC internal/wpg-input.cpp @@ -158,7 +166,7 @@ if(WITH_LIBWPG) ) endif() -if(ImageMagick_FOUND) +if(WITH_IMAGE_MAGICK) list(APPEND extension_SRC internal/bitmap/adaptiveThreshold.cpp internal/bitmap/adaptiveThreshold.h -- cgit v1.2.3