summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-05-09 18:34:01 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-05-09 18:34:01 +0000
commit36bc16fc9772ce0271eb5ec62e2c03cb1038282e (patch)
treec13d992c952bd21bc00c393d80bfe31c3b35284e /src
parentprevent overflow index on a pathinfo function (diff)
parentFix Doxyfile (diff)
downloadinkscape-36bc16fc9772ce0271eb5ec62e2c03cb1038282e.tar.gz
inkscape-36bc16fc9772ce0271eb5ec62e2c03cb1038282e.zip
update to trunk
(bzr r13645.1.85)
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/attributes.cpp24
-rw-r--r--src/attributes.h23
-rw-r--r--src/conn-avoid-ref.cpp5
-rw-r--r--src/desktop-style.cpp121
-rw-r--r--src/desktop-style.h25
-rw-r--r--src/desktop.cpp3
-rw-r--r--src/desktop.h2
-rw-r--r--src/dir-util.cpp2
-rw-r--r--src/dir-util.h4
-rw-r--r--src/display/canvas-arena.cpp2
-rw-r--r--src/display/canvas-axonomgrid.cpp4
-rw-r--r--src/display/canvas-grid.cpp28
-rw-r--r--src/document.cpp36
-rw-r--r--src/document.h8
-rw-r--r--src/extension/CMakeLists.txt20
-rw-r--r--src/extension/dbus/document-interface.cpp46
-rw-r--r--src/extension/execution-env.cpp12
-rw-r--r--src/extension/extension.cpp4
-rw-r--r--src/extension/implementation/implementation.cpp8
-rw-r--r--src/extension/implementation/script.cpp28
-rw-r--r--src/extension/implementation/script.h2
-rw-r--r--src/extension/internal/bitmap/imagemagick.cpp22
-rw-r--r--src/extension/internal/bluredge.cpp6
-rw-r--r--src/extension/internal/cairo-render-context.cpp1
-rw-r--r--src/extension/internal/cairo-renderer.cpp8
-rw-r--r--src/extension/internal/cdr-input.h4
-rw-r--r--src/extension/internal/emf-inout.cpp50
-rw-r--r--src/extension/internal/emf-inout.h2
-rw-r--r--src/extension/internal/emf-print.cpp12
-rw-r--r--src/extension/internal/filter/filter.cpp6
-rw-r--r--src/extension/internal/grid.cpp13
-rw-r--r--src/extension/internal/latex-text-renderer.cpp8
-rw-r--r--src/extension/internal/pdfinput/pdf-input.h4
-rw-r--r--src/extension/internal/vsd-input.h4
-rw-r--r--src/extension/internal/wmf-inout.cpp74
-rw-r--r--src/extension/internal/wmf-print.cpp6
-rw-r--r--src/extension/param/bool.cpp4
-rw-r--r--src/extension/param/color.cpp4
-rw-r--r--src/extension/param/description.cpp4
-rw-r--r--src/extension/param/enum.cpp4
-rw-r--r--src/extension/param/float.cpp4
-rw-r--r--src/extension/param/int.cpp4
-rw-r--r--src/extension/param/notebook.cpp4
-rw-r--r--src/extension/param/radiobutton.cpp4
-rw-r--r--src/extension/param/string.cpp4
-rw-r--r--src/extension/prefdialog.h9
-rw-r--r--src/file.cpp13
-rw-r--r--src/gradient-chemistry.cpp12
-rw-r--r--src/gradient-drag.cpp19
-rw-r--r--src/graphlayout.cpp10
-rw-r--r--src/graphlayout.h4
-rw-r--r--src/helper-fns.h2
-rw-r--r--src/helper/geom-pathstroke.cpp204
-rw-r--r--src/helper/geom.cpp9
-rw-r--r--src/helper/png-write.cpp12
-rw-r--r--src/helper/png-write.h7
-rw-r--r--src/inkscape.cpp4
-rw-r--r--src/inkview.cpp2
-rw-r--r--src/libavoid/connector.cpp6
-rw-r--r--src/libavoid/graph.cpp4
-rw-r--r--src/libavoid/orthogonal.cpp1
-rw-r--r--src/libdepixelize/kopftracer2011.cpp7
-rw-r--r--src/libnrtype/FontFactory.h2
-rw-r--r--src/libnrtype/Layout-TNG-OutIter.cpp4
-rw-r--r--src/libnrtype/Layout-TNG.h6
-rw-r--r--src/libnrtype/font-lister.cpp2
-rw-r--r--src/libuemf/CMakeLists.txt1
-rw-r--r--src/libuemf/Makefile_insert2
-rw-r--r--src/libuemf/README100
-rw-r--r--src/libuemf/uemf.c273
-rw-r--r--src/libuemf/uemf.h180
-rw-r--r--src/libuemf/uemf_endian.c1673
-rw-r--r--src/libuemf/uemf_endian.h7
-rw-r--r--src/libuemf/uemf_print.c652
-rw-r--r--src/libuemf/uemf_print.h14
-rw-r--r--src/libuemf/uemf_safe.c1202
-rw-r--r--src/libuemf/uemf_safe.h32
-rw-r--r--src/libuemf/upmf.c1282
-rw-r--r--src/libuemf/upmf.h146
-rw-r--r--src/libuemf/upmf_print.c818
-rw-r--r--src/libuemf/upmf_print.h137
-rw-r--r--src/libuemf/uwmf.c100
-rw-r--r--src/libuemf/uwmf.h5
-rw-r--r--src/libuemf/uwmf_print.c14
-rw-r--r--src/libuemf/uwmf_print.h2
-rw-r--r--src/live_effects/effect.cpp3
-rw-r--r--src/live_effects/effect.h1
-rw-r--r--src/live_effects/lpe-fillet-chamfer.cpp7
-rw-r--r--src/live_effects/lpe-fillet-chamfer.h2
-rw-r--r--src/live_effects/lpe-gears.cpp2
-rw-r--r--src/live_effects/lpe-knot.cpp6
-rw-r--r--src/live_effects/lpe-lattice2.cpp2
-rw-r--r--src/live_effects/lpe-lattice2.h6
-rw-r--r--src/live_effects/lpe-roughen.cpp22
-rw-r--r--src/live_effects/lpe-roughen.h2
-rw-r--r--src/live_effects/lpe-taperstroke.cpp4
-rw-r--r--src/live_effects/parameter/originalpath.cpp4
-rw-r--r--src/live_effects/parameter/originalpatharray.cpp4
-rw-r--r--src/live_effects/parameter/path.cpp8
-rw-r--r--src/live_effects/parameter/satellitearray.cpp14
-rw-r--r--src/live_effects/parameter/satellitearray.h4
-rw-r--r--src/main.cpp24
-rw-r--r--src/object-snapper.cpp5
-rw-r--r--src/object-test.h3
-rw-r--r--src/path-chemistry.cpp127
-rw-r--r--src/path-chemistry.h2
-rw-r--r--src/removeoverlap.cpp13
-rw-r--r--src/removeoverlap.h2
-rw-r--r--src/selcue.cpp19
-rw-r--r--src/selection-chemistry.cpp1041
-rw-r--r--src/selection-chemistry.h11
-rw-r--r--src/selection-describer.cpp34
-rw-r--r--src/selection.cpp185
-rw-r--r--src/selection.h30
-rw-r--r--src/seltrans.cpp55
-rw-r--r--src/seltrans.h2
-rw-r--r--src/snap.cpp14
-rw-r--r--src/snap.h8
-rw-r--r--src/sp-clippath.cpp9
-rw-r--r--src/sp-clippath.h2
-rw-r--r--src/sp-conn-end.cpp5
-rw-r--r--src/sp-defs.cpp8
-rw-r--r--src/sp-filter.cpp18
-rw-r--r--src/sp-filter.h3
-rw-r--r--src/sp-item-group.cpp88
-rw-r--r--src/sp-item-group.h6
-rw-r--r--src/sp-item-transform.cpp6
-rw-r--r--src/sp-lpe-item.cpp30
-rw-r--r--src/sp-marker.cpp6
-rw-r--r--src/sp-marker.h2
-rw-r--r--src/sp-mask.cpp9
-rw-r--r--src/sp-mask.h2
-rw-r--r--src/sp-namedview.cpp2
-rw-r--r--src/sp-object.cpp10
-rw-r--r--src/sp-object.h6
-rw-r--r--src/sp-pattern.cpp6
-rw-r--r--src/sp-pattern.h2
-rw-r--r--src/sp-switch.cpp24
-rw-r--r--src/sp-switch.h2
-rw-r--r--src/sp-text.cpp26
-rw-r--r--src/sp-use.cpp62
-rw-r--r--src/splivarot.cpp97
-rw-r--r--src/style-enums.h137
-rw-r--r--src/style.cpp63
-rw-r--r--src/style.h18
-rw-r--r--src/text-chemistry.cpp84
-rw-r--r--src/text-editing.cpp7
-rw-r--r--src/trace/siox.cpp2
-rw-r--r--src/trace/trace.cpp8
-rw-r--r--src/ui/clipboard.cpp33
-rw-r--r--src/ui/dialog-events.cpp4
-rw-r--r--src/ui/dialog/aboutbox.h8
-rw-r--r--src/ui/dialog/align-and-distribute.cpp86
-rw-r--r--src/ui/dialog/calligraphic-profile-rename.h4
-rw-r--r--src/ui/dialog/clonetiler.cpp16
-rw-r--r--src/ui/dialog/color-item.cpp4
-rw-r--r--src/ui/dialog/debug.cpp4
-rw-r--r--src/ui/dialog/document-properties.cpp4
-rw-r--r--src/ui/dialog/export.cpp32
-rw-r--r--src/ui/dialog/filedialogimpl-gtkmm.h8
-rw-r--r--src/ui/dialog/filedialogimpl-win32.h5
-rw-r--r--src/ui/dialog/filter-effects-dialog.cpp58
-rw-r--r--src/ui/dialog/filter-effects-dialog.h4
-rw-r--r--src/ui/dialog/find.cpp92
-rw-r--r--src/ui/dialog/find.h10
-rw-r--r--src/ui/dialog/floating-behavior.cpp6
-rw-r--r--src/ui/dialog/font-substitution.cpp32
-rw-r--r--src/ui/dialog/font-substitution.h5
-rw-r--r--src/ui/dialog/glyphs.cpp12
-rw-r--r--src/ui/dialog/grid-arrange-tab.cpp70
-rw-r--r--src/ui/dialog/guides.h4
-rw-r--r--src/ui/dialog/icon-preview.cpp14
-rw-r--r--src/ui/dialog/layer-properties.h4
-rw-r--r--src/ui/dialog/layers.h4
-rw-r--r--src/ui/dialog/livepatheffect-add.h8
-rw-r--r--src/ui/dialog/lpe-fillet-chamfer-properties.cpp24
-rw-r--r--src/ui/dialog/lpe-fillet-chamfer-properties.h7
-rw-r--r--src/ui/dialog/lpe-powerstroke-properties.cpp4
-rw-r--r--src/ui/dialog/messages.h8
-rw-r--r--src/ui/dialog/object-attributes.cpp2
-rw-r--r--src/ui/dialog/object-properties.cpp4
-rw-r--r--src/ui/dialog/objects.cpp8
-rw-r--r--src/ui/dialog/objects.h4
-rw-r--r--src/ui/dialog/ocaldialogs.h4
-rw-r--r--src/ui/dialog/pixelartdialog.cpp8
-rw-r--r--src/ui/dialog/polar-arrange-tab.cpp14
-rw-r--r--src/ui/dialog/print.cpp2
-rw-r--r--src/ui/dialog/spellcheck.h4
-rw-r--r--src/ui/dialog/svg-fonts-dialog.cpp4
-rw-r--r--src/ui/dialog/swatches.cpp6
-rw-r--r--src/ui/dialog/symbols.cpp4
-rw-r--r--src/ui/dialog/tags.cpp11
-rw-r--r--src/ui/dialog/text-edit.cpp26
-rw-r--r--src/ui/dialog/text-edit.h4
-rw-r--r--src/ui/dialog/tile.h4
-rw-r--r--src/ui/dialog/transformation.cpp48
-rw-r--r--src/ui/interface.cpp19
-rw-r--r--src/ui/previewholder.h4
-rw-r--r--src/ui/tools/box3d-tool.cpp2
-rw-r--r--src/ui/tools/connector-tool.cpp8
-rw-r--r--src/ui/tools/eraser-tool.cpp33
-rw-r--r--src/ui/tools/flood-tool.cpp2
-rw-r--r--src/ui/tools/gradient-tool.cpp37
-rw-r--r--src/ui/tools/lpe-tool.cpp8
-rw-r--r--src/ui/tools/measure-tool.cpp6
-rw-r--r--src/ui/tools/mesh-tool.cpp27
-rw-r--r--src/ui/tools/node-tool.cpp10
-rw-r--r--src/ui/tools/pen-tool.cpp15
-rw-r--r--src/ui/tools/pencil-tool.cpp3
-rw-r--r--src/ui/tools/rect-tool.cpp1
-rw-r--r--src/ui/tools/select-tool.cpp6
-rw-r--r--src/ui/tools/spray-tool.cpp32
-rw-r--r--src/ui/tools/text-tool.cpp7
-rw-r--r--src/ui/tools/tool-base.cpp10
-rw-r--r--src/ui/tools/tweak-tool.cpp25
-rw-r--r--src/ui/widget/addtoicon.cpp4
-rw-r--r--src/ui/widget/button.h8
-rw-r--r--src/ui/widget/clipmaskicon.cpp4
-rw-r--r--src/ui/widget/color-picker.h8
-rw-r--r--src/ui/widget/color-preview.h4
-rw-r--r--src/ui/widget/dock-item.h4
-rw-r--r--src/ui/widget/dock.h8
-rw-r--r--src/ui/widget/entity-entry.cpp4
-rw-r--r--src/ui/widget/filter-effect-chooser.h8
-rw-r--r--src/ui/widget/frame.h8
-rw-r--r--src/ui/widget/imageicon.h8
-rw-r--r--src/ui/widget/imagetoggler.h4
-rw-r--r--src/ui/widget/insertordericon.h3
-rw-r--r--src/ui/widget/labelled.h8
-rw-r--r--src/ui/widget/layertypeicon.cpp4
-rw-r--r--src/ui/widget/licensor.h8
-rw-r--r--src/ui/widget/notebook-page.h4
-rw-r--r--src/ui/widget/object-composite-settings.cpp3
-rw-r--r--src/ui/widget/object-composite-settings.h8
-rw-r--r--src/ui/widget/panel.cpp4
-rw-r--r--src/ui/widget/panel.h4
-rw-r--r--src/ui/widget/preferences-widget.cpp4
-rw-r--r--src/ui/widget/preferences-widget.h4
-rw-r--r--src/ui/widget/rotateable.cpp4
-rw-r--r--src/ui/widget/selected-style.h4
-rw-r--r--src/ui/widget/spin-scale.h4
-rw-r--r--src/ui/widget/spin-slider.h4
-rw-r--r--src/ui/widget/spinbutton.h8
-rw-r--r--src/ui/widget/style-subject.cpp42
-rw-r--r--src/ui/widget/style-subject.h13
-rw-r--r--src/ui/widget/style-swatch.h4
-rw-r--r--src/ui/widget/tolerance-slider.cpp4
-rw-r--r--src/ui/widget/unit-menu.h8
-rw-r--r--src/unclump.cpp61
-rw-r--r--src/unclump.h2
-rw-r--r--src/util/ziptool.cpp2
-rw-r--r--src/vanishing-point.cpp26
-rw-r--r--src/verbs.cpp43
-rw-r--r--src/widgets/arc-toolbar.cpp33
-rw-r--r--src/widgets/connector-toolbar.cpp16
-rw-r--r--src/widgets/dash-selector.h4
-rw-r--r--src/widgets/desktop-widget.cpp4
-rw-r--r--src/widgets/desktop-widget.h8
-rw-r--r--src/widgets/ege-adjustment-action.cpp2
-rw-r--r--src/widgets/fill-style.cpp36
-rw-r--r--src/widgets/gradient-toolbar.cpp15
-rw-r--r--src/widgets/gradient-vector.cpp1
-rw-r--r--src/widgets/icon.cpp4
-rw-r--r--src/widgets/mesh-toolbar.cpp10
-rw-r--r--src/widgets/paint-selector.cpp22
-rw-r--r--src/widgets/rect-toolbar.cpp18
-rw-r--r--src/widgets/shrink-wrap-button.cpp4
-rw-r--r--src/widgets/sp-attribute-widget.h4
-rw-r--r--src/widgets/spiral-toolbar.cpp16
-rw-r--r--src/widgets/spw-utilities.cpp4
-rw-r--r--src/widgets/star-toolbar.cpp38
-rw-r--r--src/widgets/stroke-marker-selector.h8
-rw-r--r--src/widgets/stroke-style.cpp30
-rw-r--r--src/widgets/stroke-style.h2
-rw-r--r--src/widgets/swatch-selector.h8
-rw-r--r--src/widgets/text-toolbar.cpp48
-rw-r--r--src/widgets/toolbox.cpp4
-rw-r--r--src/xml/repr-util.cpp5
-rw-r--r--src/xml/repr.h2
280 files changed, 7261 insertions, 4486 deletions
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!
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/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp
index c13b9a5d3..eb6694233 100644
--- a/src/conn-avoid-ref.cpp
+++ b/src/conn-avoid-ref.cpp
@@ -252,8 +252,9 @@ static std::vector<Geom::Point> 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);
+ std::vector<SPItem*> itemlist = sp_item_group_item_list(group);
+ for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); i++) {
+ SPItem* child_item = *i;
std::vector<Geom::Point> 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 c713e0d61..afdc3064a 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) {
+ std::vector<SPItem*> const itemlist = desktop->selection->itemList();
+ for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) {
/* last used styles for 3D box faces are stored separately */
- SPObject *obj = reinterpret_cast<SPObject *>(i->data); // TODO unsafe until Selection is refactored.
+ SPObject *obj = *i;
Box3DSide *side = dynamic_cast<Box3DSide *>(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<SPItem *>(i->data);
+ std::vector<SPItem*> const itemlist = desktop->selection->itemList();
+ for (std::vector<SPItem*>::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)) {
@@ -438,18 +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 std::vector<SPItem*> &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<SPObject *>(l->data);
- SPItem *item = dynamic_cast<SPItem *>(obj);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPItem *item = *i;
if (!item) {
continue;
}
@@ -471,7 +470,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<double> const &lhs, std::vector<double> const &rhs )
@@ -492,9 +491,9 @@ static bool vectorsClose( std::vector<double> const &lhs, std::vector<double> 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 std::vector<SPItem*> &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 +513,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i!= objects.end(); i++) {
+ SPObject *obj = *i;
if (!obj) {
continue;
}
@@ -674,7 +673,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 +684,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 std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -698,8 +697,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!obj) {
continue;
}
@@ -739,9 +738,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 std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -754,8 +753,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!obj) {
continue;
}
@@ -815,9 +814,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 std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -828,8 +827,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!dynamic_cast<SPItem *>(obj)) {
continue;
}
@@ -875,9 +874,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 std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -887,8 +886,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!dynamic_cast<SPItem *>(obj)) {
continue;
}
@@ -929,9 +928,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 std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -941,8 +940,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!dynamic_cast<SPItem *>(obj)) {
continue;
}
@@ -984,7 +983,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 std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
@@ -1004,8 +1003,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!isTextualItem(obj)) {
continue;
@@ -1116,15 +1115,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 std::vector<SPItem*> &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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!isTextualItem(obj)) {
continue;
@@ -1173,7 +1172,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 std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
@@ -1192,8 +1191,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!isTextualItem(obj)) {
continue;
@@ -1269,7 +1268,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 std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
int texts = 0;
@@ -1280,8 +1279,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
// std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl;
if (!isTextualItem(obj)) {
@@ -1325,7 +1324,7 @@ objects_query_fontfamily (GSList *objects, SPStyle *style_res)
}
static int
-objects_query_fontspecification (GSList *objects, SPStyle *style_res)
+objects_query_fontspecification (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
int texts = 0;
@@ -1336,8 +1335,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
// std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl;
if (!isTextualItem(obj)) {
@@ -1385,7 +1384,7 @@ objects_query_fontspecification (GSList *objects, SPStyle *style_res)
}
static int
-objects_query_blend (GSList *objects, SPStyle *style_res)
+objects_query_blend (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
const int empty_prev = -2;
const int complex_filter = 5;
@@ -1394,8 +1393,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!obj) {
continue;
}
@@ -1471,9 +1470,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 std::vector<SPItem*> &objects, SPStyle *style_res)
{
- if (g_slist_length(objects) == 0) {
+ if (objects.empty()) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
@@ -1484,8 +1483,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<SPObject *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) {
+ SPObject *obj = *i;
if (!obj) {
continue;
}
@@ -1553,7 +1552,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 std::vector<SPItem*> &list, SPStyle *style, int property)
{
if (property == QUERY_STYLE_PROPERTY_FILL) {
return objects_query_fillstroke (list, style, true);
@@ -1606,7 +1605,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..a72f49776 100644
--- a/src/desktop-style.h
+++ b/src/desktop-style.h
@@ -17,6 +17,7 @@ class ColorRGBA;
class SPCSSAttr;
class SPDesktop;
class SPObject;
+class SPItem;
class SPStyle;
typedef struct _GSList GSList;
namespace Inkscape {
@@ -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 std::vector<SPItem*> &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 std::vector<SPItem*> &objects, SPStyle *style_res, bool const isfill);
+int objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_res);
+int objects_query_fontstyle (const std::vector<SPItem*> &objects, SPStyle *style_res);
+int objects_query_fontfamily (const std::vector<SPItem*> &objects, SPStyle *style_res);
+int objects_query_opacity (const std::vector<SPItem*> &objects, SPStyle *style_res);
+int objects_query_strokewidth (const std::vector<SPItem*> &objects, SPStyle *style_res);
+int objects_query_miterlimit (const std::vector<SPItem*> &objects, SPStyle *style_res);
+int objects_query_strokecap (const std::vector<SPItem*> &objects, SPStyle *style_res);
+int objects_query_strokejoin (const std::vector<SPItem*> &objects, SPStyle *style_res);
-int objects_query_blur (GSList *objects, SPStyle *style_res);
+int objects_query_blur (const std::vector<SPItem*> &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 std::vector<SPItem*> &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 1152184c9..02df50c6b 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 std::vector<SPItem*> &list, Geom::Point const &p) const
{
g_return_val_if_fail (doc() != NULL, NULL);
return SPDocument::getItemFromListAtPointBottom(dkey, doc()->getRoot(), list, p);
@@ -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/desktop.h b/src/desktop.h
index a0b9592d0..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 GSList *list, Geom::Point const &p) const;
+ SPItem *getItemFromListAtPointBottom(const std::vector<SPItem*> &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/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 <cstdlib>
#include <string>
-/**
+/**
* 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
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/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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/label.h>
diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp
index 9b9f64529..decf93626 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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/label.h>
@@ -910,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);
@@ -926,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++) {
@@ -948,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);
@@ -961,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);
diff --git a/src/document.cpp b/src/document.cpp
index 1c6bb76de..741e7c812 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -1266,7 +1266,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 std::vector<SPItem*> &find_items_in_area(std::vector<SPItem*> &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);
@@ -1279,7 +1279,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);
}
}
}
@@ -1306,7 +1306,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, std::vector<SPItem*> const &list,Geom::Point const &p, bool take_insensitive)
{
g_return_val_if_fail(group, NULL);
SPItem *bottomMost = 0;
@@ -1320,7 +1320,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;
}
}
@@ -1422,11 +1422,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
+std::vector<SPItem*> 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);
+ std::vector<SPItem*> x;
+ g_return_val_if_fail(this->priv != NULL, x);
+ return find_items_in_area(x, SP_GROUP(this->root), dkey, box, is_within);
}
/*
@@ -1436,16 +1436,16 @@ GSList *SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) cons
*
*/
-GSList *SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const
+std::vector<SPItem*> 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);
+ std::vector<SPItem*> 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<Geom::Point> points) const
+std::vector<SPItem*> SPDocument::getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const
{
- GSList *items = NULL;
+ std::vector<SPItem*> items;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
// When picking along the path, we don't want small objects close together
@@ -1454,11 +1454,11 @@ GSList *SPDocument::getItemsAtPoints(unsigned const key, std::vector<Geom::Point
gdouble saved_delta = prefs->getDouble("/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 && !g_slist_find(items, item))
- items = g_slist_prepend (items, item);
+ if (item && items.end()==find(items.begin(),items.end(), item))
+ items.push_back(item);
}
// and now we restore it back
@@ -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/document.h b/src/document.h
index 74dcfa75e..16b9bb28d 100644
--- a/src/document.h
+++ b/src/document.h
@@ -232,7 +232,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 std::vector<SPItem*> &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,
@@ -259,10 +259,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;
+ std::vector<SPItem*> getItemsInBox(unsigned int dkey, Geom::Rect const &box) const;
+ std::vector<SPItem*> 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<Geom::Point> points) const;
+ std::vector<SPItem*> getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const;
SPItem *getGroupAtPoint(unsigned int key, Geom::Point const &p) const;
void changeUriAndHrefs(char const *uri);
diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt
index 47292fd97..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,7 +53,6 @@ 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
@@ -103,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
@@ -139,7 +136,6 @@ 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
)
@@ -149,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
@@ -156,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
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<SPObject*>
selection_swap(Inkscape::Selection *sel, gchar *name, GError **error)
{
- const GSList *oldsel = g_slist_copy((GSList *)sel->list());
+ std::vector<SPObject*> 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<SPObject*> 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<SPObject*> 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<SPObject*> 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<SPObject*> 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<SPObject*> 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<SPObject*> 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<SPObject*>::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<SPObject*> 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<SPObject*>::iterator iter = children.begin(), e = children.end(); iter != e; ++iter) {
+ (*out)[i] = g_strdup((*iter)->getId());
i++;
}
(*out)[i] = NULL;
return TRUE;
-
}
diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp
index 13b8d60c4..29c2b5537 100644
--- a/src/extension/execution-env.cpp
+++ b/src/extension/execution-env.cpp
@@ -14,10 +14,6 @@
# include <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include "gtkmm/messagedialog.h"
#include "execution-env.h"
@@ -64,14 +60,12 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Imp
sp_namedview_document_from_window(desktop);
if (desktop != NULL) {
- Inkscape::Util::GSListConstIterator<SPItem *> selected =
- desktop->getSelection()->itemList();
- while ( selected != NULL ) {
+ std::vector<SPItem*> selected = desktop->getSelection()->itemList();
+ for(std::vector<SPItem*>::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/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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <gtkmm/frame.h>
diff --git a/src/extension/implementation/implementation.cpp b/src/extension/implementation/implementation.cpp
index 52f63499a..b0ff3e91c 100644
--- a/src/extension/implementation/implementation.cpp
+++ b/src/extension/implementation/implementation.cpp
@@ -47,12 +47,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<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList();
+ std::vector<SPItem*> 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 = selected[0];
first_select = item->getRepr();
}
diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp
index bbc567f75..e07a3963c 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<SPItem *> selected =
+ std::vector<SPItem*> selected =
desktop->getSelection()->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer
- while ( selected != NULL ) {
+ for(std::vector<SPItem*>::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;
@@ -813,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]);
@@ -824,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()));
@@ -1027,7 +1030,10 @@ int Script::execute (const std::list<std::string> &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<Glib::MainContext> _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<Glib::MainLoop> 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;
diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp
index 76f35415e..bc0dd8e33 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 <glibmm/threads.h>
-#endif
-
#include <libintl.h>
#include <gtkmm/box.h>
@@ -70,8 +66,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 std::vector<SPItem*> selectedItemList = desktop->selection->itemList();
+ int selectCount = selectedItemList.size();
// Init the data-holders
_nodes = new Inkscape::XML::Node*[selectCount];
@@ -83,9 +79,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 (std::vector<SPItem*>::const_iterator i = selectedItemList.begin(); i != selectedItemList.end(); i++) {
+ SPItem *item = *i;
Inkscape::XML::Node *node = reinterpret_cast<Inkscape::XML::Node *>(item->getRepr());
if (!strcmp(node->name(), "image") || !strcmp(node->name(), "svg:image"))
{
@@ -241,13 +236,10 @@ ImageMagick::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::Vie
{
SPDocument * current_document = view->doc();
- using Inkscape::Util::GSListConstIterator;
-
- // FIXME very unsafe cast
- GSListConstIterator<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList();
+ std::vector<SPItem*> 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..9f19f8b3b 100644
--- a/src/extension/internal/bluredge.cpp
+++ b/src/extension/internal/bluredge.cpp
@@ -63,13 +63,11 @@ 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::list<SPItem *> items;
- items.insert<GSListConstIterator<SPItem *> >(items.end(), selection->itemList(), NULL);
+ std::vector<SPItem*> items(selection->itemList());
selection->clear();
- for(std::list<SPItem *>::iterator item = items.begin();
+ for(std::vector<SPItem*>::iterator item = items.begin();
item != items.end(); ++item) {
SPItem * spitem = *item;
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/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp
index 7fbdc4296..5a5553e97 100644
--- a/src/extension/internal/cairo-renderer.cpp
+++ b/src/extension/internal/cairo-renderer.cpp
@@ -294,14 +294,12 @@ 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<SPObject *>(l->data);
- SPItem *item = dynamic_cast<SPItem *>(o);
+ std::vector<SPObject*> l(group->childList(false));
+ for(std::vector<SPObject*>::const_iterator x = l.begin(); x!= l.end(); x++){
+ SPItem *item = dynamic_cast<SPItem*>(*x);
if (item) {
renderer->renderItem(ctx, item);
}
- l = g_slist_remove (l, o);
}
}
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#include "../implementation/implementation.h"
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 <<std::endl;
- off += lpEMFR->nSize;
+// std::cout << "record type: " << iType << " name " << U_emr_names(iType) << " length: " << nSize << " offset: " << off <<std::endl;
+ off += nSize;
SVGOStringStream tmp_outsvg;
SVGOStringStream tmp_path;
SVGOStringStream tmp_str;
SVGOStringStream dbg_str;
- emr_mask = emr_properties(lpEMFR->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 <libuemf/uemf.h>
+#include <libuemf/uemf_safe.h>
+#include <libuemf/uemf_endian.h> // 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/filter/filter.cpp b/src/extension/internal/filter/filter.cpp
index a2c565699..65162af22 100644
--- a/src/extension/internal/filter/filter.cpp
+++ b/src/extension/internal/filter/filter.cpp
@@ -125,15 +125,13 @@ 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<SPItem *> items;
- items.insert<GSListConstIterator<SPItem *> >(items.end(), selection->itemList(), NULL);
+ std::vector<SPItem*> items(selection->itemList());
Inkscape::XML::Document * xmldoc = document->doc()->getReprDoc();
Inkscape::XML::Node * defsrepr = document->doc()->getDefs()->getRepr();
- for(std::list<SPItem *>::iterator item = items.begin();
+ for(std::vector<SPItem*>::iterator item = items.begin();
item != items.end(); ++item) {
SPItem * spitem = *item;
Inkscape::XML::Node * node = spitem->getRepr();
diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp
index 270edfe44..8fd82b675 100644
--- a/src/extension/internal/grid.cpp
+++ b/src/extension/internal/grid.cpp
@@ -15,10 +15,6 @@
# include <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/adjustment.h>
#include <gtkmm/spinbutton.h>
@@ -190,13 +186,10 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View
{
SPDocument * current_document = view->doc();
- using Inkscape::Util::GSListConstIterator;
-
- // FIXME very unsafe cast
- GSListConstIterator<SPItem *> selected = ((SPDesktop *)view)->getSelection()->itemList();
+ std::vector<SPItem*> selected = ((SPDesktop *)view)->getSelection()->itemList();
Inkscape::XML::Node * first_select = NULL;
- if (selected != NULL) {
- first_select = (*selected)->getRepr();
+ if (!selected.empty()) {
+ 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 ab0733848..1026f51ad 100644
--- a/src/extension/internal/latex-text-renderer.cpp
+++ b/src/extension/internal/latex-text-renderer.cpp
@@ -228,14 +228,12 @@ LaTeXTextRenderer::writePostamble()
void LaTeXTextRenderer::sp_group_render(SPGroup *group)
{
- GSList *l = g_slist_reverse(group->childList(false));
- while (l) {
- SPObject *o = reinterpret_cast<SPObject *>(l->data);
- SPItem *item = dynamic_cast<SPItem *>(o);
+ std::vector<SPObject*> l = (group->childList(false));
+ for(std::vector<SPObject*>::const_iterator x = l.begin(); x != l.end(); x++){
+ SPItem *item = dynamic_cast<SPItem*>(*x);
if (item) {
renderItem(item);
}
- l = g_slist_remove (l, o);
}
}
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#include "../implementation/implementation.h"
diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp
index 503a93418..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;
@@ -1497,6 +1495,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 +1561,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 +1603,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 +1669,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 <<std::endl;
- wmr_mask = U_wmr_properties(iType);
- if(wmr_mask == U_WMR_INVALID){ throw "Inkscape fatal programming error at U_wmr_properties"; }
+ SVGOStringStream tmp_path;
+ SVGOStringStream tmp_str;
/* Uncomment the following to track down text problems */
//std::cout << "tri->dirty:"<< d->tri->dirty << " wmr_mask: " << std::hex << wmr_mask << std::dec << std::endl;
@@ -3026,14 +3035,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 +3061,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!
@@ -3064,12 +3083,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;
- if (uri == NULL) {
- return NULL;
- }
+ // 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
@@ -3095,12 +3114,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/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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/spinbutton.h>
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 <iostream>
#include <sstream>
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/spinbutton.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <glibmm/i18n.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/comboboxtext.h>
#include <glibmm/i18n.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/scale.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/scale.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/spinbutton.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/comboboxtext.h>
#include <gtkmm/radiobutton.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/spinbutton.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#include <glibmm/value.h>
#include <glibmm/ustring.h>
-
namespace Gtk {
class CheckButton;
}
diff --git a/src/file.cpp b/src/file.cpp
index f9e259fe2..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;
}
@@ -1069,7 +1069,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place)
desktop->doc()->importDefs(clipdoc);
// copy objects
- GSList *pasted_objects = NULL;
+ std::vector<Inkscape::XML::Node*> 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")) {
@@ -1088,9 +1088,8 @@ 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_back(obj_copy);
}
-
// Change the selection to the freshly pasted objects
Inkscape::Selection *selection = desktop->getSelection();
selection->setReprList(pasted_objects);
@@ -1129,8 +1128,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/gradient-chemistry.cpp b/src/gradient-chemistry.cpp
index aecf1aa35..d90972961 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 std::vector<SPItem*> list=selection->itemList();
+ for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) {
+ sp_item_gradient_invert_vector_color(*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 std::vector<SPItem*> list=selection->itemList();
+ for (std::vector<SPItem*>::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 cb2bd737f..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;
}
@@ -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);
+ std::vector<SPItem*> list = this->selection->itemList();
+ for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) {
+ SPItem *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);
+ std::vector<SPItem*> list = this->selection->itemList();
+ for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) {
+ SPItem *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);
+ std::vector<SPItem*> list = this->selection->itemList();
+ for (std::vector<SPItem*>::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 e5d61ab64..40994347c 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<SPItem *> &filtered) {
- for(GSList *i=(GSList *)items; i!=NULL; i=i->next) {
- SPItem *item=SP_ITEM(i->data);
+void filterConnectors(std::vector<SPItem*> const &items, list<SPItem *> &filtered) {
+ for(std::vector<SPItem*>::const_iterator i = items.begin();i !=items.end(); i++){
+ SPItem *item = *i;
if(!isConnector(item)) {
filtered.push_back(item);
}
@@ -101,8 +101,8 @@ void filterConnectors(GSList const *const items, list<SPItem *> &filtered) {
* connectors between them, and uses graph layout techniques to find
* a nice layout
*/
-void graphlayout(GSList const *const items) {
- if(!items) {
+void graphlayout(std::vector<SPItem*> const &items) {
+ if(items.empty()) {
return;
}
diff --git a/src/graphlayout.h b/src/graphlayout.h
index 0ffb645b6..9794dd6b5 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(std::vector<SPItem*> const &items);
bool isConnector(SPItem const *const item);
-void filterConnectors(GSList const *const items, std::list<SPItem *> &filtered);
+void filterConnectors(std::vector<SPItem*> const &items, std::list<SPItem *> &filtered);
#endif // SEEN_GRAPHLAYOUT_H
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<gdouble> 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-pathstroke.cpp b/src/helper/geom-pathstroke.cpp
index eb0c432c6..1df17acf5 100644
--- a/src/helper/geom-pathstroke.cpp
+++ b/src/helper/geom-pathstroke.cpp
@@ -127,87 +127,104 @@ static Circle touching_circle( D2<SBasis> 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<Geom::LineSegment>(outgoing.initialPoint());
- res.append(outgoing);
+ jd.res.appendNew<Geom::LineSegment>(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<Geom::SVGEllipticalArc>(width, width, 0, false, width <= 0, outgoing.initialPoint());
- res.append(outgoing);
+ jd.res.appendNew<Geom::SVGEllipticalArc>(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<Geom::LineSegment>(p);
+ res.appendNew<LineSegment>(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<Geom::LineSegment>(p1);
+ res.appendNew<LineSegment>(p1);
}
- res.appendNew<Geom::LineSegment>(p2);
+ res.appendNew<LineSegment>(p2);
}
}
- res.appendNew<Geom::LineSegment>(outgoing.initialPoint());
+ res.appendNew<LineSegment>(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,53 +401,78 @@ void extrapolate_join(Geom::Path& res, Geom::Curve const& outgoing, double miter
// Straight line segment:
res.appendNew<Geom::LineSegment>(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::Curve const& incoming = res.back_open();
- 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::Path &res = jd.res;
+ Geom::Path const& temp = jd.outgoing;
+ Geom::Crossings cross = Geom::crossings(res, temp);
+
+ 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);
+ }
+ }
+ }
- Geom::Curve *d2 = outgoing.portion(cross[0].tb, 1.);
- res.setFinal(d2->initialPoint());
- res.append(*d2);
- delete d2;
+ 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();
+ res.append(d1);
+ res.setFinal(d2.initialPoint());
+ res.append(d2);
} else {
- res.appendNew<Geom::LineSegment>(outgoing.initialPoint());
- res.append(outgoing);
+ res.appendNew<Geom::LineSegment>(temp.initialPoint());
+ res.append(temp);
}
}
-bool decide(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.);
- 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 +491,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);
}
}
@@ -579,7 +624,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
@@ -705,6 +750,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 +766,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 +786,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();
//
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/helper/png-write.cpp b/src/helper/png-write.cpp
index 32e50b537..fc365c435 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 std::vector<SPItem*> &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 std::vector<SPItem*> &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 std::vector<SPItem*> &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..2657fb635 100644
--- a/src/helper/png-write.h
+++ b/src/helper/png-write.h
@@ -14,8 +14,9 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-#include <glib.h>
#include <2geom/forward.h>
+
+
class SPDocument;
enum ExportResult {
@@ -33,12 +34,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 std::vector<SPItem*> &items_only = std::vector<SPItem*>());
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 std::vector<SPItem*> &items_only = std::vector<SPItem*>());
#endif // SEEN_SP_PNG_WRITE_H
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 <map>
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/messagedialog.h>
#include "debug/simple-event.h"
#include "debug/event-tracker.h"
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/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 <glibmm.h>
-// Build fix under Inkscape build tree
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <algorithm>
#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/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<Glib::ustring, std::list<StyleNames> > FamilyToStylesMap;
+// typedef std::map<Glib::ustring, std::list<StyleNames> > FamilyToStylesMap;
class font_factory {
public:
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<int>(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<InputStreamTextSource*>(_input_stream.front())->styleGetBlockProgression();}
+ {
+ if(!_input_stream.empty())
+ return static_cast<InputStreamTextSource*>(_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);
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);
}
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
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);
}
@@ -1611,6 +1611,26 @@ U_RECTL rectl_set(
}
/**
+ \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
\param y Y 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 <string.h>
#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; i<ClrUsed; i++, k+= sizeof(U_RGBQUAD)){
- memcpy(&BmiColor, Bmi+k, sizeof(U_RGBQUAD));
- printf("%d:",i); rgbquad_print(BmiColor);
- }
+ k= offsetof(U_BITMAPINFO,bmiColors);
+ IF_MEM_UNSAFE_PRINT_AND_RETURN(Bmi, offsetof(U_BITMAPINFO,bmiColors) + ClrUsed*sizeof(U_RGBQUAD), blimit);
+ for(i=0; i<ClrUsed; i++, k+= sizeof(U_RGBQUAD)){
+ memcpy(&BmiColor, Bmi+k, sizeof(U_RGBQUAD));
+ printf("%d:",i); rgbquad_print(BmiColor);
+ }
}
}
@@ -484,15 +491,19 @@ void rgndataheader_print(
/**
\brief Print a pointer to a U_RGNDATA object.
\param rd pointer to a U_RGNDATA object.
+ \param limit pointer that sets upper limit for data examination
*/
void rgndata_print(
- PU_RGNDATA rd
+ PU_RGNDATA rd,
+ const char *blimit
){
unsigned int i;
PU_RECTL rects;
- printf("rdh:"); rgndataheader_print(rd->rdh );
+ 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;i<rd->rdh.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;i<pEmr->cptl; 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;i<pEmr->nPolys; 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;i<pEmr->cptl; 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; i<pEmr->cpts; 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;i<pEmr->nPolys; 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; i<pEmr->cpts; 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; i<pEmr->cEntries; 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;i<pEmr->cptl; 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;i<pEmr->cptl; 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;i<pEmr->cpts; 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;i<pEmr->cpts; 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; i<pEmr->nTriVert; 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; i<pEmr->nGradObj; 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; i<pEmr->nGradObj; 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; i<pEmr->cbData; 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/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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stddef.h> /* 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_ */
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.
@@ -1516,6 +1523,19 @@ int U_PMF_CMN_HDR_get(const char **contents, U_PMF_CMN_HDR *Header){
}
/**
+ \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.
\returns size of the object in bytes
@@ -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 <string.h>
#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; i<Elements; i++){
printf(" %d:",i);
- if( Flags & U_PPF_P){ (void) U_PMF_POINTR_print(contents, &Xpos, &Ypos); }
- else if(Flags & U_PPF_C){ (void) U_PMF_POINT_print(contents); }
- else { (void) U_PMF_POINTF_print(contents); }
+ if( Flags & U_PPF_P){ (void) U_PMF_POINTR_print(contents, &Xpos, &Ypos, blimit); }
+ else if(Flags & U_PPF_C){ (void) U_PMF_POINT_print(contents, blimit); }
+ else { (void) U_PMF_POINTF_print(contents, blimit); }
}
#if 0
int residual;
@@ -120,16 +121,23 @@ int U_PMF_VARBRUSHID_print(int btype, uint32_t BrushID){
\brief Print any EMF+ record
\returns record length for a normal record, 0 for EMREOF or , -1 for a bad record
\param contents pointer to a buffer holding this EMF+ record
- \param blimit one byte past the end of data of this EMF+ record
+ \param blimit one byte after this EMF+ record
\param recnum EMF number of this record in contents
- \param off Offset from the beginning of the EMF+ file.
+ \param off Offset from the beginning of the EMF+ file to the start of this record.
*/
int U_pmf_onerec_print(const char *contents, const char *blimit, int recnum, int off){
int status;
+ int rstatus;
static U_OBJ_ACCUM ObjCont={NULL,0,0,0,0}; /* for keeping track of object continuation. These may
be split across multiple EMF Comment records */
U_PMF_CMN_HDR Header;
const char *contemp = contents;
+
+ /* Check that COMMON header 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(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CMN_HDR), blimit))return(-1);
if(!U_PMF_CMN_HDR_get(&contemp, &Header)){return(-1);}
int type = Header.Type & U_PMR_TYPE_MASK; /* strip the U_PMR_RECFLAG bit, leaving the indexable part */
@@ -142,67 +150,72 @@ int U_pmf_onerec_print(const char *contents, const char *blimit, int recnum, int
U_PMR_OBJECT_print(contents, blimit, &ObjCont, 1);
}
+ /* Check that the record size is OK, abort if not. */
+ if(Header.Size < sizeof(U_PMF_CMN_HDR) ||
+ IS_MEM_UNSAFE(contents, Header.Size, blimit))return(-1);
+
switch(type){
- case (U_PMR_HEADER): U_PMR_HEADER_print(contents); break;
- case (U_PMR_ENDOFFILE): U_PMR_ENDOFFILE_print(contents);
- U_OA_release(&ObjCont); break;
- case (U_PMR_COMMENT): U_PMR_COMMENT_print(contents); break;
- case (U_PMR_GETDC): U_PMR_GETDC_print(contents); break;
- case (U_PMR_MULTIFORMATSTART): U_PMR_MULTIFORMATSTART_print(contents); break;
- case (U_PMR_MULTIFORMATSECTION): U_PMR_MULTIFORMATSECTION_print(contents); break;
- case (U_PMR_MULTIFORMATEND): U_PMR_MULTIFORMATEND_print(contents); break;
- case (U_PMR_OBJECT): U_PMR_OBJECT_print(contents,blimit,&ObjCont,0); break;
- case (U_PMR_CLEAR): U_PMR_CLEAR_print(contents); break;
- case (U_PMR_FILLRECTS): U_PMR_FILLRECTS_print(contents, blimit); break;
- case (U_PMR_DRAWRECTS): U_PMR_DRAWRECTS_print(contents, blimit); break;
- case (U_PMR_FILLPOLYGON): U_PMR_FILLPOLYGON_print(contents); break;
- case (U_PMR_DRAWLINES): U_PMR_DRAWLINES_print(contents); break;
- case (U_PMR_FILLELLIPSE): U_PMR_FILLELLIPSE_print(contents); break;
- case (U_PMR_DRAWELLIPSE): U_PMR_DRAWELLIPSE_print(contents); break;
- case (U_PMR_FILLPIE): U_PMR_FILLPIE_print(contents); break;
- case (U_PMR_DRAWPIE): U_PMR_DRAWPIE_print(contents); break;
- case (U_PMR_DRAWARC): U_PMR_DRAWARC_print(contents); break;
- case (U_PMR_FILLREGION): U_PMR_FILLREGION_print(contents); break;
- case (U_PMR_FILLPATH): U_PMR_FILLPATH_print(contents); break;
- case (U_PMR_DRAWPATH): U_PMR_DRAWPATH_print(contents); break;
- case (U_PMR_FILLCLOSEDCURVE): U_PMR_FILLCLOSEDCURVE_print(contents); break;
- case (U_PMR_DRAWCLOSEDCURVE): U_PMR_DRAWCLOSEDCURVE_print(contents); break;
- case (U_PMR_DRAWCURVE): U_PMR_DRAWCURVE_print(contents); break;
- case (U_PMR_DRAWBEZIERS): U_PMR_DRAWBEZIERS_print(contents); break;
- case (U_PMR_DRAWIMAGE): U_PMR_DRAWIMAGE_print(contents); break;
- case (U_PMR_DRAWIMAGEPOINTS): U_PMR_DRAWIMAGEPOINTS_print(contents); break;
- case (U_PMR_DRAWSTRING): U_PMR_DRAWSTRING_print(contents); break;
- case (U_PMR_SETRENDERINGORIGIN): U_PMR_SETRENDERINGORIGIN_print(contents); break;
- case (U_PMR_SETANTIALIASMODE): U_PMR_SETANTIALIASMODE_print(contents); break;
- case (U_PMR_SETTEXTRENDERINGHINT): U_PMR_SETTEXTRENDERINGHINT_print(contents); break;
- case (U_PMR_SETTEXTCONTRAST): U_PMR_SETTEXTCONTRAST_print(contents); break;
- case (U_PMR_SETINTERPOLATIONMODE): U_PMR_SETINTERPOLATIONMODE_print(contents); break;
- case (U_PMR_SETPIXELOFFSETMODE): U_PMR_SETPIXELOFFSETMODE_print(contents); break;
- case (U_PMR_SETCOMPOSITINGMODE): U_PMR_SETCOMPOSITINGMODE_print(contents); break;
- case (U_PMR_SETCOMPOSITINGQUALITY): U_PMR_SETCOMPOSITINGQUALITY_print(contents); break;
- case (U_PMR_SAVE): U_PMR_SAVE_print(contents); break;
- case (U_PMR_RESTORE): U_PMR_RESTORE_print(contents); break;
- case (U_PMR_BEGINCONTAINER): U_PMR_BEGINCONTAINER_print(contents); break;
- case (U_PMR_BEGINCONTAINERNOPARAMS): U_PMR_BEGINCONTAINERNOPARAMS_print(contents); break;
- case (U_PMR_ENDCONTAINER): U_PMR_ENDCONTAINER_print(contents); break;
- case (U_PMR_SETWORLDTRANSFORM): U_PMR_SETWORLDTRANSFORM_print(contents); break;
- case (U_PMR_RESETWORLDTRANSFORM): U_PMR_RESETWORLDTRANSFORM_print(contents); break;
- case (U_PMR_MULTIPLYWORLDTRANSFORM): U_PMR_MULTIPLYWORLDTRANSFORM_print(contents); break;
- case (U_PMR_TRANSLATEWORLDTRANSFORM): U_PMR_TRANSLATEWORLDTRANSFORM_print(contents); break;
- case (U_PMR_SCALEWORLDTRANSFORM): U_PMR_SCALEWORLDTRANSFORM_print(contents); break;
- case (U_PMR_ROTATEWORLDTRANSFORM): U_PMR_ROTATEWORLDTRANSFORM_print(contents); break;
- case (U_PMR_SETPAGETRANSFORM): U_PMR_SETPAGETRANSFORM_print(contents); break;
- case (U_PMR_RESETCLIP): U_PMR_RESETCLIP_print(contents); break;
- case (U_PMR_SETCLIPRECT): U_PMR_SETCLIPRECT_print(contents); break;
- case (U_PMR_SETCLIPPATH): U_PMR_SETCLIPPATH_print(contents); break;
- case (U_PMR_SETCLIPREGION): U_PMR_SETCLIPREGION_print(contents); break;
- case (U_PMR_OFFSETCLIP): U_PMR_OFFSETCLIP_print(contents); break;
- case (U_PMR_DRAWDRIVERSTRING): U_PMR_DRAWDRIVERSTRING_print(contents); break;
- case (U_PMR_STROKEFILLPATH): U_PMR_STROKEFILLPATH_print(contents); break;
- case (U_PMR_SERIALIZABLEOBJECT): U_PMR_SERIALIZABLEOBJECT_print(contents); break;
- case (U_PMR_SETTSGRAPHICS): U_PMR_SETTSGRAPHICS_print(contents); break;
- case (U_PMR_SETTSCLIP): U_PMR_SETTSCLIP_print(contents); break;
- }
+ case (U_PMR_HEADER): rstatus = U_PMR_HEADER_print(contents); break;
+ case (U_PMR_ENDOFFILE): rstatus = U_PMR_ENDOFFILE_print(contents);
+ U_OA_release(&ObjCont); break;
+ case (U_PMR_COMMENT): rstatus = U_PMR_COMMENT_print(contents); break;
+ case (U_PMR_GETDC): rstatus = U_PMR_GETDC_print(contents); break;
+ case (U_PMR_MULTIFORMATSTART): rstatus = U_PMR_MULTIFORMATSTART_print(contents); break;
+ case (U_PMR_MULTIFORMATSECTION): rstatus = U_PMR_MULTIFORMATSECTION_print(contents); break;
+ case (U_PMR_MULTIFORMATEND): rstatus = U_PMR_MULTIFORMATEND_print(contents); break;
+ case (U_PMR_OBJECT): rstatus = U_PMR_OBJECT_print(contents,blimit,&ObjCont,0); break;
+ case (U_PMR_CLEAR): rstatus = U_PMR_CLEAR_print(contents); break;
+ case (U_PMR_FILLRECTS): rstatus = U_PMR_FILLRECTS_print(contents); break;
+ case (U_PMR_DRAWRECTS): rstatus = U_PMR_DRAWRECTS_print(contents); break;
+ case (U_PMR_FILLPOLYGON): rstatus = U_PMR_FILLPOLYGON_print(contents); break;
+ case (U_PMR_DRAWLINES): rstatus = U_PMR_DRAWLINES_print(contents); break;
+ case (U_PMR_FILLELLIPSE): rstatus = U_PMR_FILLELLIPSE_print(contents); break;
+ case (U_PMR_DRAWELLIPSE): rstatus = U_PMR_DRAWELLIPSE_print(contents); break;
+ case (U_PMR_FILLPIE): rstatus = U_PMR_FILLPIE_print(contents); break;
+ case (U_PMR_DRAWPIE): rstatus = U_PMR_DRAWPIE_print(contents); break;
+ case (U_PMR_DRAWARC): rstatus = U_PMR_DRAWARC_print(contents); break;
+ case (U_PMR_FILLREGION): rstatus = U_PMR_FILLREGION_print(contents); break;
+ case (U_PMR_FILLPATH): rstatus = U_PMR_FILLPATH_print(contents); break;
+ case (U_PMR_DRAWPATH): rstatus = U_PMR_DRAWPATH_print(contents); break;
+ case (U_PMR_FILLCLOSEDCURVE): rstatus = U_PMR_FILLCLOSEDCURVE_print(contents); break;
+ case (U_PMR_DRAWCLOSEDCURVE): rstatus = U_PMR_DRAWCLOSEDCURVE_print(contents); break;
+ case (U_PMR_DRAWCURVE): rstatus = U_PMR_DRAWCURVE_print(contents); break;
+ case (U_PMR_DRAWBEZIERS): rstatus = U_PMR_DRAWBEZIERS_print(contents); break;
+ case (U_PMR_DRAWIMAGE): rstatus = U_PMR_DRAWIMAGE_print(contents); break;
+ case (U_PMR_DRAWIMAGEPOINTS): rstatus = U_PMR_DRAWIMAGEPOINTS_print(contents); break;
+ case (U_PMR_DRAWSTRING): rstatus = U_PMR_DRAWSTRING_print(contents); break;
+ case (U_PMR_SETRENDERINGORIGIN): rstatus = U_PMR_SETRENDERINGORIGIN_print(contents); break;
+ case (U_PMR_SETANTIALIASMODE): rstatus = U_PMR_SETANTIALIASMODE_print(contents); break;
+ case (U_PMR_SETTEXTRENDERINGHINT): rstatus = U_PMR_SETTEXTRENDERINGHINT_print(contents); break;
+ case (U_PMR_SETTEXTCONTRAST): rstatus = U_PMR_SETTEXTCONTRAST_print(contents); break;
+ case (U_PMR_SETINTERPOLATIONMODE): rstatus = U_PMR_SETINTERPOLATIONMODE_print(contents); break;
+ case (U_PMR_SETPIXELOFFSETMODE): rstatus = U_PMR_SETPIXELOFFSETMODE_print(contents); break;
+ case (U_PMR_SETCOMPOSITINGMODE): rstatus = U_PMR_SETCOMPOSITINGMODE_print(contents); break;
+ case (U_PMR_SETCOMPOSITINGQUALITY): rstatus = U_PMR_SETCOMPOSITINGQUALITY_print(contents); break;
+ case (U_PMR_SAVE): rstatus = U_PMR_SAVE_print(contents); break;
+ case (U_PMR_RESTORE): rstatus = U_PMR_RESTORE_print(contents); break;
+ case (U_PMR_BEGINCONTAINER): rstatus = U_PMR_BEGINCONTAINER_print(contents); break;
+ case (U_PMR_BEGINCONTAINERNOPARAMS): rstatus = U_PMR_BEGINCONTAINERNOPARAMS_print(contents); break;
+ case (U_PMR_ENDCONTAINER): rstatus = U_PMR_ENDCONTAINER_print(contents); break;
+ case (U_PMR_SETWORLDTRANSFORM): rstatus = U_PMR_SETWORLDTRANSFORM_print(contents); break;
+ case (U_PMR_RESETWORLDTRANSFORM): rstatus = U_PMR_RESETWORLDTRANSFORM_print(contents); break;
+ case (U_PMR_MULTIPLYWORLDTRANSFORM): rstatus = U_PMR_MULTIPLYWORLDTRANSFORM_print(contents); break;
+ case (U_PMR_TRANSLATEWORLDTRANSFORM): rstatus = U_PMR_TRANSLATEWORLDTRANSFORM_print(contents); break;
+ case (U_PMR_SCALEWORLDTRANSFORM): rstatus = U_PMR_SCALEWORLDTRANSFORM_print(contents); break;
+ case (U_PMR_ROTATEWORLDTRANSFORM): rstatus = U_PMR_ROTATEWORLDTRANSFORM_print(contents); break;
+ case (U_PMR_SETPAGETRANSFORM): rstatus = U_PMR_SETPAGETRANSFORM_print(contents); break;
+ case (U_PMR_RESETCLIP): rstatus = U_PMR_RESETCLIP_print(contents); break;
+ case (U_PMR_SETCLIPRECT): rstatus = U_PMR_SETCLIPRECT_print(contents); break;
+ case (U_PMR_SETCLIPPATH): rstatus = U_PMR_SETCLIPPATH_print(contents); break;
+ case (U_PMR_SETCLIPREGION): rstatus = U_PMR_SETCLIPREGION_print(contents); break;
+ case (U_PMR_OFFSETCLIP): rstatus = U_PMR_OFFSETCLIP_print(contents); break;
+ case (U_PMR_DRAWDRIVERSTRING): rstatus = U_PMR_DRAWDRIVERSTRING_print(contents); break;
+ case (U_PMR_STROKEFILLPATH): rstatus = U_PMR_STROKEFILLPATH_print(contents); break;
+ case (U_PMR_SERIALIZABLEOBJECT): rstatus = U_PMR_SERIALIZABLEOBJECT_print(contents); break;
+ case (U_PMR_SETTSGRAPHICS): rstatus = U_PMR_SETTSGRAPHICS_print(contents); break;
+ case (U_PMR_SETTSCLIP): rstatus = U_PMR_SETTSCLIP_print(contents); break;
+ }
+ if(!rstatus)status=-1;
return(status);
}
@@ -446,15 +459,16 @@ int U_PMF_NODETYPE_print(int Type){
\brief Print data from a U_PMF_BRUSH 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.1.1, Microsoft name: EmfPlusBrush Object
*/
-int U_PMF_BRUSH_print(const char *contents){
+int U_PMF_BRUSH_print(const char *contents, const char *blimit){
uint32_t Version, Type;
const char *Data;
- int status = U_PMF_BRUSH_get(contents, &Version, &Type, &Data);
+ int status = U_PMF_BRUSH_get(contents, &Version, &Type, &Data, blimit);
if(status){
printf(" + Brush:");
- (void) U_PMF_GRAPHICSVERSION_print((char *)&Version);
+ (void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(" Type:%X(",Type);
(void) U_PMF_BRUSHTYPEENUMERATION_print(Type);
printf(")");
@@ -464,19 +478,19 @@ int U_PMF_BRUSH_print(const char *contents){
break;
case U_BT_HatchFill:
printf("\n");
- status = U_PMF_HATCHBRUSHDATA_print(Data);
+ status = U_PMF_HATCHBRUSHDATA_print(Data, blimit);
break;
case U_BT_TextureFill:
printf("\n");
- status = U_PMF_TEXTUREBRUSHDATA_print(Data);
+ status = U_PMF_TEXTUREBRUSHDATA_print(Data, blimit);
break;
case U_BT_PathGradient:
printf("\n");
- status = U_PMF_PATHGRADIENTBRUSHDATA_print(Data);
+ status = U_PMF_PATHGRADIENTBRUSHDATA_print(Data, blimit);
break;
case U_BT_LinearGradient:
printf("\n");
- status = U_PMF_LINEARGRADIENTBRUSHDATA_print(Data);
+ status = U_PMF_LINEARGRADIENTBRUSHDATA_print(Data, blimit);
break;
default:
status = 0;
@@ -491,23 +505,24 @@ int U_PMF_BRUSH_print(const char *contents){
\return 1 on success, 0 on error
\param contents Record from which to print data
\param Which A string which is either "Start" or "End".
+ \param blimit one byte past the end of data
EMF+ manual 2.2.1.2, Microsoft name: EmfPlusCustomLineCap Object
*/
-int U_PMF_CUSTOMLINECAP_print(const char *contents, const char *Which){
+int U_PMF_CUSTOMLINECAP_print(const char *contents, const char *Which, const char *blimit){
uint32_t Version, Type;
const char *Data;
- int status = U_PMF_CUSTOMLINECAP_get(contents, &Version, &Type, &Data);
+ int status = U_PMF_CUSTOMLINECAP_get(contents, &Version, &Type, &Data, blimit);
if(status){
printf(" + %sLineCap:",Which);
- (void) U_PMF_GRAPHICSVERSION_print((char *)&Version);
+ (void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(", Type %X\n",Type);
switch(Type){
case U_CLCDT_Default:
- status = U_PMF_CUSTOMLINECAPDATA_print(Data);
+ status = U_PMF_CUSTOMLINECAPDATA_print(Data, blimit);
break;
case U_CLCDT_AdjustableArrow:
- status = U_PMF_CUSTOMLINECAPARROWDATA_print(Data);
+ status = U_PMF_CUSTOMLINECAPARROWDATA_print(Data, blimit);
break;
default:
status = 0;
@@ -520,18 +535,19 @@ int U_PMF_CUSTOMLINECAP_print(const char *contents, const char *Which){
\brief Print data from a U_PMF_FONT 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.1.3, Microsoft name: EmfPlusFont Object
*/
-int U_PMF_FONT_print(const char *contents){
+int U_PMF_FONT_print(const char *contents, const char *blimit){
uint32_t Version, SizeUnit, Length;
U_FLOAT EmSize;
int32_t FSFlags;
const char *Data;
char *string;
- int status = U_PMF_FONT_get(contents, &Version, &EmSize, &SizeUnit, &FSFlags, &Length, &Data);
+ int status = U_PMF_FONT_get(contents, &Version, &EmSize, &SizeUnit, &FSFlags, &Length, &Data, blimit);
if(status){
printf(" + Font:");
- (void) U_PMF_GRAPHICSVERSION_print((char *)&Version);
+ (void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(" EmSize:%f ", EmSize );
printf(" SizeUnit:%d ",SizeUnit);
printf(" FSFlags:%d ", FSFlags );
@@ -553,25 +569,27 @@ int U_PMF_FONT_print(const char *contents){
\brief Print data from a U_PMF_IMAGE 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.1.4, Microsoft name: EmfPlusImage Object
*/
-int U_PMF_IMAGE_print(const char *contents){
+int U_PMF_IMAGE_print(const char *contents, const char *blimit){
uint32_t Version, Type;
const char *Data;
- int status = U_PMF_IMAGE_get(contents, &Version, &Type, &Data);
+ int status = U_PMF_IMAGE_get(contents, &Version, &Type, &Data, blimit);
if(status){
printf(" + Image:");
- (void) U_PMF_GRAPHICSVERSION_print((char *)&Version);
+ (void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(" Type:%X\n",Type);
switch(Type){
case U_IDT_Unknown:
printf(" + Unknown Image Type\n");
break;
case U_IDT_Bitmap:
- status = U_PMF_BITMAP_print(Data);
+ status = U_PMF_BITMAP_print(Data, blimit);
break;
case U_IDT_Metafile:
- status = U_PMF_METAFILE_print(Data);
+ status = U_PMF_METAFILE_print(Data, blimit);
break;
default:
status = 0;
@@ -585,15 +603,16 @@ int U_PMF_IMAGE_print(const char *contents){
\brief Print data from a U_PMF_IMAGEATTRIBUTES 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.1.5, Microsoft name: EmfPlusImageAttributes Object
*/
-int U_PMF_IMAGEATTRIBUTES_print(const char *contents){
+int U_PMF_IMAGEATTRIBUTES_print(const char *contents, const char *blimit){
uint32_t Version, WrapMode, ClampColor, ObjectClamp;
- int status = U_PMF_IMAGEATTRIBUTES_get(contents, &Version, &WrapMode, &ClampColor, &ObjectClamp);
+ int status = U_PMF_IMAGEATTRIBUTES_get(contents, &Version, &WrapMode, &ClampColor, &ObjectClamp, blimit);
if(status){
printf(" + Image Attributes: ");
- (void) U_PMF_GRAPHICSVERSION_print((char *)&Version);
+ (void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(" WrapMode:%X", WrapMode);
printf(" ClampColor:%X", ClampColor);
printf(" ObjectClamp:%X\n", ObjectClamp);
@@ -607,20 +626,21 @@ int U_PMF_IMAGEATTRIBUTES_print(const char *contents){
\brief Print data from a U_PMF_PATH 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.1.6, Microsoft name: EmfPlusPath Object
*/
-int U_PMF_PATH_print(const char *contents){
+int U_PMF_PATH_print(const char *contents, const char *blimit){
unsigned int i, pos;
uint32_t Version, Count;
uint16_t Flags;
const char *Points;
const char *Types;
- int status = U_PMF_PATH_get(contents, &Version, &Count, &Flags, &Points, &Types);
+ int status = U_PMF_PATH_get(contents, &Version, &Count, &Flags, &Points, &Types, blimit);
if(status){
printf(" + Path: Version:%X Count:%d Flags:%X\n",Version, Count, Flags);
/* Points part */
- U_PMF_VARPOINTS_print(&Points, Flags, Count);
+ U_PMF_VARPOINTS_print(&Points, Flags, Count, blimit);
/* Types part */
printf(" + Types:");
@@ -631,12 +651,12 @@ int U_PMF_PATH_print(const char *contents){
is which type. */
if(Flags & U_PPF_R){
printf(" %u:",pos);
- pos += U_PMF_PATHPOINTTYPERLE_print(Types);
+ pos += U_PMF_PATHPOINTTYPERLE_print(Types, blimit);
Types+=2;
}
else {
printf(" %d:",i);
- (void) U_PMF_PATHPOINTTYPE_print(Types);
+ (void) U_PMF_PATHPOINTTYPE_print(Types, blimit);
Types++;
}
}
@@ -651,15 +671,15 @@ int U_PMF_PATH_print(const char *contents){
\param contents Record from which to print data
EMF+ manual 2.2.1.7, Microsoft name: EmfPlusPen Object
*/
-int U_PMF_PEN_print(const char *contents){
+int U_PMF_PEN_print(const char *contents, const char *blimit){
uint32_t Version, Type;
const char *PenData;
const char *Brush;
- int status = U_PMF_PEN_get(contents, &Version, &Type, &PenData, &Brush);
+ int status = U_PMF_PEN_get(contents, &Version, &Type, &PenData, &Brush, blimit);
if(status){
printf(" + Pen: Version:%X Type:%d\n",Version,Type);
- (void) U_PMF_PENDATA_print(PenData);
- (void) U_PMF_BRUSH_print(Brush);
+ (void) U_PMF_PENDATA_print(PenData, blimit);
+ (void) U_PMF_BRUSH_print(Brush, blimit);
}
return(status);
}
@@ -668,17 +688,19 @@ int U_PMF_PEN_print(const char *contents){
\brief Print data from a U_PMF_REGION 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.1.8, Microsoft name: EmfPlusRegion Object
*/
-int U_PMF_REGION_print(const char *contents){
+int U_PMF_REGION_print(const char *contents, const char *blimit){
uint32_t Version, Count;
const char *Nodes;
- int status = U_PMF_REGION_get(contents, &Version, &Count, &Nodes);
+ int status = U_PMF_REGION_get(contents, &Version, &Count, &Nodes, blimit);
if(status){
printf(" + ");
- (void) U_PMF_GRAPHICSVERSION_print((char *) &Version);
+ (void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(" ChildNodes:%d",Count);
- (void) U_PMF_REGIONNODE_print(Nodes, 1); /* 1 == top level*/
+ (void) U_PMF_REGIONNODE_print(Nodes, 1, blimit); /* 1 == top level*/
}
return(status);
}
@@ -687,12 +709,13 @@ int U_PMF_REGION_print(const char *contents){
\brief Print data from a U_PMF_STRINGFORMAT 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.1.9, Microsoft name: EmfPlusStringFormat Object
*/
-int U_PMF_STRINGFORMAT_print(const char *contents){
+int U_PMF_STRINGFORMAT_print(const char *contents, const char *blimit){
U_PMF_STRINGFORMAT Sfs;
const char *Data;
- int status = U_PMF_STRINGFORMAT_get(contents, &Sfs, &Data);
+ int status = U_PMF_STRINGFORMAT_get(contents, &Sfs, &Data, blimit);
if(status){
printf(" + StringFormat: ");
printf(" Version:%X", Sfs.Version );
@@ -710,7 +733,7 @@ int U_PMF_STRINGFORMAT_print(const char *contents){
printf(" Trimming:%X", Sfs.Trimming );
printf(" TabStopCount:%u", Sfs.TabStopCount );
printf(" RangeCount:%u", Sfs.RangeCount );
- (void) U_PMF_STRINGFORMATDATA_print(Data, Sfs.TabStopCount, Sfs.RangeCount);
+ (void) U_PMF_STRINGFORMATDATA_print(Data, Sfs.TabStopCount, Sfs.RangeCount, blimit);
}
return(status);
}
@@ -719,11 +742,13 @@ int U_PMF_STRINGFORMAT_print(const char *contents){
\brief Print data from a U_PMF_ARGB object
\return 1 on success, 0 on error
\param contents Record from which to print data
+
+ Does not accept a blimit value.
EMF+ manual 2.2.2.1, Microsoft name: EmfPlusARGB Object
*/
int U_PMF_ARGB_print(const char *contents){
uint8_t Blue, Green, Red, Alpha;
- int status = U_PMF_ARGB_get(contents, &Blue, &Green, &Red, &Alpha);
+ int status = U_PMF_ARGB_get(contents, &Blue, &Green, &Red, &Alpha, contents + sizeof(U_RGBQUAD));
if(status){
printf(" RGBA{%2.2X,%2.2X,%2.2X,%2.2X}", Red, Green, Blue, Alpha);
}
@@ -735,12 +760,13 @@ int U_PMF_ARGB_print(const char *contents){
\brief Print data from a U_PMF_BITMAP 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.2, Microsoft name: EmfPlusBitmap Object
*/
-int U_PMF_BITMAP_print(const char *contents){
+int U_PMF_BITMAP_print(const char *contents, const char *blimit){
U_PMF_BITMAP Bs;
const char *Data;
- int status = U_PMF_BITMAP_get(contents, &Bs, &Data);
+ int status = U_PMF_BITMAP_get(contents, &Bs, &Data, blimit);
if(status){
printf(" + Bitmap: Width:%d Height:%d Stride:%d\n",Bs.Width, Bs.Height, Bs.Stride);
U_PMF_PX_FMT_ENUM_print(Bs.PxFormat);
@@ -759,14 +785,15 @@ int U_PMF_BITMAP_print(const char *contents){
\brief Print data from a U_PMF_BITMAPDATA 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.3, Microsoft name: EmfPlusBitmapData Object
*/
-int U_PMF_BITMAPDATA_print(const char *contents){
+int U_PMF_BITMAPDATA_print(const char *contents, const char *blimit){
unsigned int i;
U_PMF_PALETTE Ps;
const char *Colors;
const char *Data;
- int status = U_PMF_BITMAPDATA_get(contents, &Ps, &Colors, &Data);
+ int status = U_PMF_BITMAPDATA_get(contents, &Ps, &Colors, &Data, blimit);
if(status){
status = 0;
printf(" BMData: Flags:%X, Elements:%u Colors:", Ps.Flags, Ps.Elements);
@@ -781,14 +808,15 @@ int U_PMF_BITMAPDATA_print(const char *contents){
\brief Print data from a U_PMF_BLENDCOLORS object
\return size in bytes 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.4, Microsoft name: EmfPlusBlendColors Object
*/
-int U_PMF_BLENDCOLORS_print(const char *contents){
+int U_PMF_BLENDCOLORS_print(const char *contents, const char *blimit){
unsigned int i;
uint32_t Elements;
U_FLOAT *Positions;
const char *Colors;
- int status = U_PMF_BLENDCOLORS_get(contents, &Elements, &Positions, &Colors);
+ int status = U_PMF_BLENDCOLORS_get(contents, &Elements, &Positions, &Colors, blimit);
if(status){
printf(" + BlendColors: Entries:%d (entry,pos,color): ", Elements);
for(i=0; i<Elements; i++){
@@ -808,14 +836,15 @@ int U_PMF_BLENDCOLORS_print(const char *contents){
\return size on success, 0 on error
\param type Type of BlendFactors, usually H or V
\param contents Record from which to print data
+ \param blimit one byte past the end of data
EMF+ manual 2.2.2.5, Microsoft name: EmfPlusBlendFactors Object
*/
-int U_PMF_BLENDFACTORS_print(const char *contents, const char *type){
+int U_PMF_BLENDFACTORS_print(const char *contents, const char *type, const char *blimit){
unsigned int i;
uint32_t Elements;
U_FLOAT *Positions;
U_FLOAT *Factors;
- int status = U_PMF_BLENDFACTORS_get(contents, &Elements, &Positions, &Factors);
+ int status = U_PMF_BLENDFACTORS_get(contents, &Elements, &Positions, &Factors, blimit);
if(status){
printf(" + BlendFactors%s: Entries:%d (entry,pos,factor): ",type, Elements);
for(i=0; i<Elements; i++){
@@ -832,15 +861,16 @@ int U_PMF_BLENDFACTORS_print(const char *contents, const char *type){
\brief Print data from a U_PMF_BOUNDARYPATHDATA object
\return size 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.6, Microsoft name: EmfPlusBoundaryPathData Object
*/
-int U_PMF_BOUNDARYPATHDATA_print(const char *contents){
+int U_PMF_BOUNDARYPATHDATA_print(const char *contents, const char * blimit){
int32_t Size;
const char *Data;
- int status = U_PMF_BOUNDARYPATHDATA_get(contents, &Size, &Data);
+ int status = U_PMF_BOUNDARYPATHDATA_get(contents, &Size, &Data, blimit);
if(status){
printf(" + BoundaryPathData: Size:%d\n",Size);
- (void) U_PMF_PATH_print(Data);
+ (void) U_PMF_PATH_print(Data, blimit);
}
return(status);
}
@@ -850,12 +880,13 @@ int U_PMF_BOUNDARYPATHDATA_print(const char *contents){
\brief Print data from a U_PMF_BOUNDARYPOINTDATA object
\return size 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.7, Microsoft name: EmfPlusBoundaryPointData Object
*/
-int U_PMF_BOUNDARYPOINTDATA_print(const char *contents){
+int U_PMF_BOUNDARYPOINTDATA_print(const char *contents, const char *blimit){
int32_t Elements;
U_PMF_POINTF *Points;
- int status = U_PMF_BOUNDARYPOINTDATA_get(contents, &Elements, &Points);
+ int status = U_PMF_BOUNDARYPOINTDATA_get(contents, &Elements, &Points, blimit);
if(status){
printf(" + BoundaryPointData: Elements:%u\n",Elements);
U_PMF_VARPOINTF_S_print(Points, Elements);
@@ -868,11 +899,12 @@ int U_PMF_BOUNDARYPOINTDATA_print(const char *contents){
\brief Print data from a U_PMF_CHARACTERRANGE 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.8, Microsoft name: EmfPlusCharacterRange Object
*/
-int U_PMF_CHARACTERRANGE_print(const char *contents){
+int U_PMF_CHARACTERRANGE_print(const char *contents, const char *blimit){
int32_t First, Length;
- int status = U_PMF_CHARACTERRANGE_get(contents, &First, &Length);
+ int status = U_PMF_CHARACTERRANGE_get(contents, &First, &Length, blimit);
if(status){
printf(" {%d,%d}",First,Length);
}
@@ -882,14 +914,15 @@ int U_PMF_CHARACTERRANGE_print(const char *contents){
/**
\brief Print data from a U_PMF_DASHEDLINEDATA 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.2.9, Microsoft name: EmfPlusCompoundLineData Object
*/
-int U_PMF_COMPOUNDLINEDATA_print(const char *contents){
+int U_PMF_COMPOUNDLINEDATA_print(const char *contents, const char *blimit){
int32_t Elements;
U_FLOAT *Widths;
U_FLOAT *hold;
- int status = U_PMF_COMPOUNDLINEDATA_get(contents, &Elements, &Widths);
+ int status = U_PMF_COMPOUNDLINEDATA_get(contents, &Elements, &Widths, blimit);
if(status){
printf(" + CompoundLineData: Elements:%u {",Elements);
Elements--;
@@ -905,13 +938,14 @@ int U_PMF_COMPOUNDLINEDATA_print(const char *contents){
\brief Print data from a U_PMF_COMPRESSEDIMAGE 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.10, Microsoft name: EmfPlusCompressedImage Object
This function does not do anything useful, but it is included so that all objects have a corresponding _get().
*/
-int U_PMF_COMPRESSEDIMAGE_print(const char *contents){
+int U_PMF_COMPRESSEDIMAGE_print(const char *contents, const char *blimit){
const char *Data;
- int status = U_PMF_COMPRESSEDIMAGE_get(contents, &Data);
+ int status = U_PMF_COMPRESSEDIMAGE_get(contents, &Data, blimit);
if(status){
printf("CompressedImage:\n");
}
@@ -922,15 +956,16 @@ int U_PMF_COMPRESSEDIMAGE_print(const char *contents){
\brief Print data from a U_PMF_CUSTOMENDCAPDATA 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.11, Microsoft name: EmfPlusCustomEndCapData Object
*/
-int U_PMF_CUSTOMENDCAPDATA_print(const char *contents){
+int U_PMF_CUSTOMENDCAPDATA_print(const char *contents, const char *blimit){
int32_t Size;
const char *Data;
- int status = U_PMF_CUSTOMENDCAPDATA_get(contents, &Size, &Data);
+ int status = U_PMF_CUSTOMENDCAPDATA_get(contents, &Size, &Data, blimit);
if(status){
printf(" + CustomEndCap: Size:%d\n",Size);
- (void) U_PMF_CUSTOMLINECAP_print(Data, "End");
+ (void) U_PMF_CUSTOMLINECAP_print(Data, "End", blimit);
}
return(status);
}
@@ -939,11 +974,12 @@ int U_PMF_CUSTOMENDCAPDATA_print(const char *contents){
\brief Print data from a U_PMF_CUSTOMLINECAPARROWDATA 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.12, Microsoft name: EmfPlusCustomLineCapArrowData Object
*/
-int U_PMF_CUSTOMLINECAPARROWDATA_print(const char *contents){
+int U_PMF_CUSTOMLINECAPARROWDATA_print(const char *contents, const char *blimit){
U_PMF_CUSTOMLINECAPARROWDATA Ccad;
- int status = U_PMF_CUSTOMLINECAPARROWDATA_get(contents, &Ccad);
+ int status = U_PMF_CUSTOMLINECAPARROWDATA_get(contents, &Ccad, blimit);
if(status){
printf("CustomLineCapArrowData: ");
printf(" Width:%f", Ccad.Width );
@@ -966,12 +1002,13 @@ int U_PMF_CUSTOMLINECAPARROWDATA_print(const char *contents){
\brief Print data from a U_PMF_CUSTOMLINECAPDATA 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.13, Microsoft name: EmfPlusCustomLineCapData Object
*/
-int U_PMF_CUSTOMLINECAPDATA_print(const char *contents){
+int U_PMF_CUSTOMLINECAPDATA_print(const char *contents, const char *blimit){
U_PMF_CUSTOMLINECAPDATA Clcd;
const char *Data;
- int status = U_PMF_CUSTOMLINECAPDATA_get(contents, &Clcd, &Data);
+ int status = U_PMF_CUSTOMLINECAPDATA_get(contents, &Clcd, &Data, blimit);
if(status){
printf(" + CustomLineCapData: ");
printf(" Flags:%X", Clcd.Flags );
@@ -984,7 +1021,7 @@ int U_PMF_CUSTOMLINECAPDATA_print(const char *contents){
printf(" WidthScale:%f", Clcd.WidthScale );
printf(" FillHotSpot:{%f,%f}",Clcd.FillHotSpot[0],Clcd.FillHotSpot[1]);
printf(" LineHotSpot:{%f,%f}\n",Clcd.LineHotSpot[0],Clcd.LineHotSpot[1]);
- (void) U_PMF_CUSTOMLINECAPOPTIONALDATA_print(Data, Clcd.Flags);
+ (void) U_PMF_CUSTOMLINECAPOPTIONALDATA_print(Data, Clcd.Flags, blimit);
/* preceding line always emits an EOL */
}
return(status);
@@ -996,18 +1033,19 @@ int U_PMF_CUSTOMLINECAPDATA_print(const char *contents){
\return 1 on success, 0 on error
\param contents Record from which to print data
\param Flags CustomLineCapData Flags
+ \param blimit one byte past the end of data
EMF+ manual 2.2.2.14, Microsoft name: EmfPlusCustomLineCapOptionalData Object
*/
-int U_PMF_CUSTOMLINECAPOPTIONALDATA_print(const char *contents, uint32_t Flags){
+int U_PMF_CUSTOMLINECAPOPTIONALDATA_print(const char *contents, uint32_t Flags, const char *blimit){
const char *FillData;
const char *LineData;
- int status = U_PMF_CUSTOMLINECAPOPTIONALDATA_get(contents, Flags, &FillData, &LineData);
+ int status = U_PMF_CUSTOMLINECAPOPTIONALDATA_get(contents, Flags, &FillData, &LineData, blimit);
if(status){ /* True even if there is nothing in it! */
printf(" + CustomLineCapOptionalData:");
if(FillData || LineData){
- if(FillData){ (void) U_PMF_FILLPATHOBJ_print(FillData); }
- if(LineData){ (void) U_PMF_LINEPATH_print(LineData); }
+ if(FillData){ (void) U_PMF_FILLPATHOBJ_print(FillData, blimit); }
+ if(LineData){ (void) U_PMF_LINEPATH_print(LineData, blimit); }
}
else {
printf("None");
@@ -1021,15 +1059,16 @@ int U_PMF_CUSTOMLINECAPOPTIONALDATA_print(const char *contents, uint32_t Flags){
\brief Print data from a U_PMF_CUSTOMSTARTCAPDATA 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.15, Microsoft name: EmfPlusCustomStartCapData Object
*/
-int U_PMF_CUSTOMSTARTCAPDATA_print(const char *contents){
+int U_PMF_CUSTOMSTARTCAPDATA_print(const char *contents, const char *blimit){
int32_t Size;
const char *Data;
- int status = U_PMF_CUSTOMSTARTCAPDATA_get(contents, &Size, &Data);
+ int status = U_PMF_CUSTOMSTARTCAPDATA_get(contents, &Size, &Data, blimit);
if(status){
printf(" + CustomStartCap: Size:%d ",Size);
- (void) U_PMF_CUSTOMLINECAP_print(Data, "Start");
+ (void) U_PMF_CUSTOMLINECAP_print(Data, "Start", blimit);
}
return(status);
}
@@ -1038,13 +1077,14 @@ int U_PMF_CUSTOMSTARTCAPDATA_print(const char *contents){
\brief Print data from a U_PMF_DASHEDLINEDATA 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.16, Microsoft name: EmfPlusDashedLineData Object
*/
-int U_PMF_DASHEDLINEDATA_print(const char *contents){
+int U_PMF_DASHEDLINEDATA_print(const char *contents, const char *blimit){
int32_t Elements;
U_FLOAT *Lengths;
U_FLOAT *hold;
- int status = U_PMF_DASHEDLINEDATA_get(contents, &Elements, &Lengths);
+ int status = U_PMF_DASHEDLINEDATA_get(contents, &Elements, &Lengths, blimit);
if(status){
printf(" DashedLineData: Elements:%u {",Elements);
Elements--;
@@ -1059,15 +1099,16 @@ int U_PMF_DASHEDLINEDATA_print(const char *contents){
\brief Print data from a U_PMF_FILLPATHOBJ 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.17, Microsoft name: EmfPlusFillPath Object
*/
-int U_PMF_FILLPATHOBJ_print(const char *contents){
+int U_PMF_FILLPATHOBJ_print(const char *contents, const char * blimit){
int32_t Size;
const char *Data;
- int status = U_PMF_FILLPATHOBJ_get(contents, &Size, &Data);
+ int status = U_PMF_FILLPATHOBJ_get(contents, &Size, &Data, blimit);
if(status){
printf(" FillPathObj: Size:%d\n",Size);
- if(Size){ (void) U_PMF_PATH_print(Data); }
+ if(Size){ (void) U_PMF_PATH_print(Data, blimit); }
}
return(status);
}
@@ -1076,12 +1117,13 @@ int U_PMF_FILLPATHOBJ_print(const char *contents){
\brief Print data from a U_PMF_FOCUSSCALEDATA 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.18, Microsoft name: EmfPlusFocusScaleData Object
*/
-int U_PMF_FOCUSSCALEDATA_print(const char *contents){
+int U_PMF_FOCUSSCALEDATA_print(const char *contents, const char *blimit){
uint32_t Count;
U_FLOAT ScaleX, ScaleY;
- int status = U_PMF_FOCUSSCALEDATA_get(contents, &Count, &ScaleX, &ScaleY);
+ int status = U_PMF_FOCUSSCALEDATA_get(contents, &Count, &ScaleX, &ScaleY, blimit);
if(status){
printf(" FocusScaleData: Count:%d ScaleX:%f ScaleY:%f ",Count,ScaleX,ScaleY);
}
@@ -1089,14 +1131,31 @@ int U_PMF_FOCUSSCALEDATA_print(const char *contents){
}
/**
- \brief Print data from a U_PMF_GRAPHICSVERSION_print object
+ \brief Print data from a U_PMF_GRAPHICSVERSION object already known to be memory safe
+ \return 1 on success, 0 on error
+ \param contents Record from which to print data
+ EMF+ manual 2.2.2.19, Microsoft name: EmfPlusGraphicsVersion Object
+
+ In this module the only time a U_PMF_GRAPHICSVERSION is printed is after it
+ has already been copied into a safe memory structure. This routine fakes up
+ a blimit for the general routine.
+
+*/
+int U_PMF_GRAPHICSVERSION_memsafe_print(const char *contents){
+ const char *blimit = contents + sizeof(U_PMF_GRAPHICSVERSION);
+ return(U_PMF_GRAPHICSVERSION_print(contents, blimit));
+}
+
+/**
+ \brief Print data from a U_PMF_GRAPHICSVERSION 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.19, Microsoft name: EmfPlusGraphicsVersion Object
*/
-int U_PMF_GRAPHICSVERSION_print(const char *contents){
+int U_PMF_GRAPHICSVERSION_print(const char *contents, const char *blimit){
int Signature,GrfVersion;
- int status = U_PMF_GRAPHICSVERSION_get(contents, &Signature, &GrfVersion);
+ int status = U_PMF_GRAPHICSVERSION_get(contents, &Signature, &GrfVersion, blimit);
if(status){
printf(" MetaFileSig:%X",Signature );
printf(" GraphicsVersion:%X", GrfVersion);
@@ -1106,15 +1165,16 @@ int U_PMF_GRAPHICSVERSION_print(const char *contents){
/**
- \brief Print data from a U_PMF_HATCHBRUSHDATA_print object
+ \brief Print data from a U_PMF_HATCHBRUSHDATA object
\return 1 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.2.2.20, Microsoft name: EmfPlusHatchBrushData Object
*/
-int U_PMF_HATCHBRUSHDATA_print(const char *contents){
+int U_PMF_HATCHBRUSHDATA_print(const char *contents, const char *blimit){
uint32_t Style;
U_PMF_ARGB Foreground, Background;
- int status = U_PMF_HATCHBRUSHDATA_get(contents, &Style, &Foreground, &Background);
+ int status = U_PMF_HATCHBRUSHDATA_get(contents, &Style, &Foreground, &Background, blimit);
if(status){
printf(" + HBdata: Style:%u(",Style);
U_PMF_HATCHSTYLEENUMERATION_print(Style);
@@ -1148,12 +1208,13 @@ int U_PMF_LANGUAGEIDENTIFIER_print(U_PMF_LANGUAGEIDENTIFIER LId){
\brief Print data from a U_PMF_LINEARGRADIENTBRUSHDATA object
\return 1 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.2.2.24, Microsoft name: EmfPlusLinearGradientBrushData Object
*/
-int U_PMF_LINEARGRADIENTBRUSHDATA_print(const char *contents){
+int U_PMF_LINEARGRADIENTBRUSHDATA_print(const char *contents, const char *blimit){
U_PMF_LINEARGRADIENTBRUSHDATA Lgbd;
const char *Data;
- int status = U_PMF_LINEARGRADIENTBRUSHDATA_get(contents, &Lgbd, &Data);
+ int status = U_PMF_LINEARGRADIENTBRUSHDATA_get(contents, &Lgbd, &Data, blimit);
if(status){
printf(" + LinearGradientBrushData: Flags:%X WrapMode:%d Rect:",Lgbd.Flags, Lgbd.WrapMode);
(void) U_PMF_RECTF_S_print(&(Lgbd.RectF));
@@ -1167,7 +1228,7 @@ int U_PMF_LINEARGRADIENTBRUSHDATA_print(const char *contents){
printf(" Reserved2:");
(void) U_PMF_ARGB_print((char *)&(Lgbd.Reserved2));
printf("\n");
- (void) U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_print(Data, Lgbd.Flags);
+ (void) U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_print(Data, Lgbd.Flags, blimit);
}
return(status);
}
@@ -1179,16 +1240,17 @@ int U_PMF_LINEARGRADIENTBRUSHDATA_print(const char *contents){
\return 1 on success, 0 on error
\param contents Record from which to print data
\param BDFlag Describes optional values in contents
+ \param blimit One byte past the last record in memory.
EMF+ manual 2.2.2.25, Microsoft name: EmfPlusLinearGradientBrushOptionalData Object
*/
-int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag){
+int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag, const char *blimit){
U_PMF_TRANSFORMMATRIX Tm;
const char *Bc;
const char *BfH;
const char *BfV;
int None=1;
printf(" + LinearGradientBrushOptionalData: ");
- int status = U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_get(contents, BDFlag, &Tm, &Bc, &BfH, &BfV);
+ int status = U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_get(contents, BDFlag, &Tm, &Bc, &BfH, &BfV, blimit);
if(status){
if(BDFlag & U_BD_Transform){
U_PMF_TRANSFORMMATRIX2_print(&Tm);
@@ -1196,17 +1258,17 @@ int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag
}
if(Bc){
printf("\n");
- (void) U_PMF_BLENDCOLORS_print(Bc);
+ (void) U_PMF_BLENDCOLORS_print(Bc, blimit);
None=0;
}
if(BfH){
printf("\n");
- (void) U_PMF_BLENDFACTORS_print(BfH,"H");
+ (void) U_PMF_BLENDFACTORS_print(BfH,"H", blimit);
None=0;
}
if(BfV){
printf("\n");
- (void) U_PMF_BLENDFACTORS_print(BfV,"V");
+ (void) U_PMF_BLENDFACTORS_print(BfV,"V", blimit);
None=0;
}
if(None){
@@ -1220,15 +1282,16 @@ int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag
\brief Print data from a U_PMF_LINEPATH 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.26, Microsoft name: EmfPlusLinePath Object
*/
-int U_PMF_LINEPATH_print(const char *contents){
+int U_PMF_LINEPATH_print(const char *contents, const char * blimit){
int32_t Size;
const char *Data;
- int status = U_PMF_LINEPATH_get(contents, &Size, &Data);
+ int status = U_PMF_LINEPATH_get(contents, &Size, &Data, blimit);
if(status){
printf(" LinePath: Size:%d\n", Size);
- (void) U_PMF_PATH_print(Data);
+ (void) U_PMF_PATH_print(Data, blimit);
}
return(status);
}
@@ -1237,13 +1300,14 @@ int U_PMF_LINEPATH_print(const char *contents){
\brief Print data from a U_PMF_METAFILE 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.27, Microsoft name: EmfPlusMetafile Object
*/
-int U_PMF_METAFILE_print(const char *contents){
+int U_PMF_METAFILE_print(const char *contents, const char * blimit){
uint32_t Type;
uint32_t Size;
const char *Data;
- int status = U_PMF_METAFILE_get(contents, &Type, &Size, &Data);
+ int status = U_PMF_METAFILE_get(contents, &Type, &Size, &Data, blimit);
if(status){
printf(" MetaFile: Type:%X Size:%d",Type, Size);
/* embedded metafiles are not handled beyond this*/
@@ -1255,14 +1319,15 @@ int U_PMF_METAFILE_print(const char *contents){
\brief Print data from a U_PMF_PALETTE 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.28, Microsoft name: EmfPlusPalette Object
*/
-int U_PMF_PALETTE_print(const char *contents){
+int U_PMF_PALETTE_print(const char *contents, const char *blimit){
unsigned int i;
uint32_t Flags;
uint32_t Elements;
const char *Data;
- int status = U_PMF_PALETTE_get(contents, &Flags, &Elements, &Data);
+ int status = U_PMF_PALETTE_get(contents, &Flags, &Elements, &Data, blimit);
if(status){
printf(" Palette: Flags:%X Elements:%u Colors:",Flags, Elements);
for(i=0; i<Elements; i++){
@@ -1278,15 +1343,16 @@ int U_PMF_PALETTE_print(const char *contents){
\brief Print data from a U_PMF_PATHGRADIENTBRUSHDATA 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.29, Microsoft name: EmfPlusPathGradientBrushData Object
*/
-int U_PMF_PATHGRADIENTBRUSHDATA_print(const char *contents){
+int U_PMF_PATHGRADIENTBRUSHDATA_print(const char *contents, const char *blimit){
U_PMF_PATHGRADIENTBRUSHDATA Pgbd;
const char *Gradient;
const char *Boundary;
const char *Data=NULL;
unsigned int i;
- int status = U_PMF_PATHGRADIENTBRUSHDATA_get(contents, &Pgbd, &Gradient, &Boundary, &Data);
+ int status = U_PMF_PATHGRADIENTBRUSHDATA_get(contents, &Pgbd, &Gradient, &Boundary, &Data, blimit);
if(status){
printf(" + PathGradientBrushData: Flags:%X WrapMode:%d, CenterColor:",Pgbd.Flags, Pgbd.WrapMode);
(void) U_PMF_ARGB_print((char *)&(Pgbd.CenterColor));
@@ -1301,12 +1367,12 @@ int U_PMF_PATHGRADIENTBRUSHDATA_print(const char *contents){
printf("\n");
}
if(Pgbd.Flags & U_BD_Path){
- (void) U_PMF_BOUNDARYPATHDATA_print(Boundary);
+ (void) U_PMF_BOUNDARYPATHDATA_print(Boundary, blimit);
}
else {
- (void) U_PMF_BOUNDARYPOINTDATA_print(Boundary);
+ (void) U_PMF_BOUNDARYPOINTDATA_print(Boundary, blimit);
}
- (void) U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_print(Data, Pgbd.Flags);
+ (void) U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_print(Data, Pgbd.Flags, blimit);
}
return(status);
}
@@ -1316,25 +1382,26 @@ int U_PMF_PATHGRADIENTBRUSHDATA_print(const char *contents){
\return 1 on success, 0 on error
\param contents Record from which to print data
\param BDFlag Describes optional values in contents
+ \param blimit one byte past the end of data
EMF+ manual 2.2.2.30, Microsoft name: EmfPlusPathGradientBrushOptionalData Object
*/
-int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag){
+int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag, const char *blimit){
if(BDFlag & (U_BD_Transform | U_BD_PresetColors | U_BD_BlendFactorsH | U_BD_FocusScales)){
printf(" + PathGradientBrushOptionalData: ");
}
if(BDFlag & U_BD_Transform){
- U_PMF_TRANSFORMMATRIX_print(contents);
+ U_PMF_TRANSFORMMATRIX_print(contents, blimit);
contents += sizeof(U_PMF_TRANSFORMMATRIX);
}
if(BDFlag & U_BD_PresetColors){ /* If this is present, BlendFactorsH will not be */
- contents += U_PMF_BLENDCOLORS_print(contents);
+ contents += U_PMF_BLENDCOLORS_print(contents, blimit);
}
if(BDFlag & U_BD_BlendFactorsH){/* If this is present, U_BD_PresetColors will not be */
- contents += U_PMF_BLENDFACTORS_print(contents,"");
+ contents += U_PMF_BLENDFACTORS_print(contents,"", blimit);
}
if(BDFlag & U_BD_FocusScales){
- contents += U_PMF_BLENDFACTORS_print(contents,"");
- U_PMF_FOCUSSCALEDATA_print(contents);
+ contents += U_PMF_BLENDFACTORS_print(contents,"", blimit);
+ U_PMF_FOCUSSCALEDATA_print(contents, blimit);
}
return(1);
}
@@ -1343,11 +1410,12 @@ int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_print(const char *contents, int BDFlag){
\brief Print data from a U_PMF_PATHPOINTTYPE 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.31, Microsoft name: EmfPlusPathPointType Object
*/
-int U_PMF_PATHPOINTTYPE_print(const char *contents){
+int U_PMF_PATHPOINTTYPE_print(const char *contents, const char *blimit){
int Flags, Type;
- int status = U_PMF_PATHPOINTTYPE_get(contents, &Flags, &Type);
+ int status = U_PMF_PATHPOINTTYPE_get(contents, &Flags, &Type, blimit);
if(status){
printf("{Flags:%X Type:",Flags);
(void) U_PMF_PATHPOINTTYPE_ENUM_print(Type);
@@ -1360,11 +1428,12 @@ int U_PMF_PATHPOINTTYPE_print(const char *contents){
\brief Print data from a U_PMF_PATHPOINTTYPERLE object
\return Number of elements in the run, 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.32, Microsoft name: EmfPlusPathPointTypeRLE Object
*/
-int U_PMF_PATHPOINTTYPERLE_print(const char *contents){
+int U_PMF_PATHPOINTTYPERLE_print(const char *contents, const char *blimit){
int Bezier, Elements, Type;
- int status = U_PMF_PATHPOINTTYPERLE_get(contents, &Bezier, &Elements, &Type);
+ int status = U_PMF_PATHPOINTTYPERLE_get(contents, &Bezier, &Elements, &Type, blimit);
if(status){
status = Elements;
printf(" PathPointTypeRLE: Bezier:%c Elements:%u, Type: ",(Bezier ? 'Y' : 'N'), Elements);
@@ -1378,16 +1447,17 @@ int U_PMF_PATHPOINTTYPERLE_print(const char *contents){
\brief Print data from a U_PMF_PATHPOINTTYPERLE 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.33, Microsoft name: EmfPlusPenData Object
*/
-int U_PMF_PENDATA_print(const char *contents){
+int U_PMF_PENDATA_print(const char *contents, const char *blimit){
uint32_t Flags, Unit;
U_FLOAT Width;
const char *Data;
- int status = U_PMF_PENDATA_get(contents, &Flags, &Unit, &Width, &Data);
+ int status = U_PMF_PENDATA_get(contents, &Flags, &Unit, &Width, &Data, blimit);
if(status){
printf(" + Pendata: Flags:%X Unit:%X Width:%f",Flags, Unit, Width);
- (void) U_PMF_PENOPTIONALDATA_print(Data, Flags); /* prints a new line at end */
+ (void) U_PMF_PENOPTIONALDATA_print(Data, Flags, blimit); /* prints a new line at end */
}
return(status);
}
@@ -1398,11 +1468,12 @@ int U_PMF_PENDATA_print(const char *contents){
\brief Print data from a U_PMF_PENOPTIONALDATA 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
\param Flags PenData Flags that determine which optionaldata fields are present in the record.
EMF+ manual 2.2.2.34, Microsoft name: EmfPlusPenOptionalData Object
*/
-int U_PMF_PENOPTIONALDATA_print(const char *contents, int Flags){
+int U_PMF_PENOPTIONALDATA_print(const char *contents, int Flags, const char *blimit){
U_PMF_TRANSFORMMATRIX Matrix;
int32_t StartCap;
int32_t EndCap;
@@ -1431,7 +1502,8 @@ int U_PMF_PENOPTIONALDATA_print(const char *contents, int Flags){
&Alignment,
&CmpndLineData,
&CSCapData,
- &CECapData);
+ &CECapData,
+ blimit);
if(status){
if(Flags & U_PD_Transform){ (void) U_PMF_TRANSFORMMATRIX2_print(&Matrix);}
if(Flags & U_PD_StartCap){ printf(" StartCap:%d", StartCap );}
@@ -1441,14 +1513,14 @@ int U_PMF_PENOPTIONALDATA_print(const char *contents, int Flags){
if(Flags & U_PD_LineStyle){ printf(" Style:%X", Style );}
if(Flags & U_PD_DLCap){ printf(" DLCap:%X", DLCap );}
if(Flags & U_PD_DLOffset){ printf(" DLOffset:%f", DLOffset );}
- if(Flags & U_PD_DLData){ (void) U_PMF_DASHEDLINEDATA_print(DLData );}
+ if(Flags & U_PD_DLData){ (void) U_PMF_DASHEDLINEDATA_print(DLData, blimit );}
if(Flags & U_PD_NonCenter){ printf(" Alignment:%d", Alignment );}
if(Flags & (U_PD_Transform | U_PD_StartCap | U_PD_EndCap |
U_PD_Join | U_PD_MiterLimit | U_PD_LineStyle |
U_PD_DLCap | U_PD_DLOffset |U_PD_DLData |U_PD_NonCenter)){ printf("\n"); }
- if(Flags & U_PD_CLData){ (void) U_PMF_COMPOUNDLINEDATA_print(CmpndLineData); }
- if(Flags & U_PD_CustomStartCap){ (void) U_PMF_CUSTOMSTARTCAPDATA_print(CSCapData); }
- if(Flags & U_PD_CustomEndCap){ (void) U_PMF_CUSTOMENDCAPDATA_print(CECapData); }
+ if(Flags & U_PD_CLData){ (void) U_PMF_COMPOUNDLINEDATA_print(CmpndLineData, blimit); }
+ if(Flags & U_PD_CustomStartCap){ (void) U_PMF_CUSTOMSTARTCAPDATA_print(CSCapData, blimit); }
+ if(Flags & U_PD_CustomEndCap){ (void) U_PMF_CUSTOMENDCAPDATA_print(CECapData, blimit); }
}
return(status);
}
@@ -1456,11 +1528,12 @@ int U_PMF_PENOPTIONALDATA_print(const char *contents, int Flags){
\brief Print data from a U_PMF_POINT 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.35, Microsoft name: EmfPlusPoint Object
*/
-int U_PMF_POINT_print(const char **contents){
+int U_PMF_POINT_print(const char **contents, const char *blimit){
U_FLOAT X, Y;
- int status = U_PMF_POINT_get(contents, &X, &Y);
+ int status = U_PMF_POINT_get(contents, &X, &Y, blimit);
if(status){
printf("{%f,%f}", X, Y);
}
@@ -1483,11 +1556,12 @@ int U_PMF_POINT_S_print(U_PMF_POINT *Point){\
\brief Print data from a U_PMF_POINTF 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.36, Microsoft name: EmfPlusPointF Object
*/
-int U_PMF_POINTF_print(const char **contents){
+int U_PMF_POINTF_print(const char **contents, const char *blimit){
U_FLOAT X, Y;
- int status = U_PMF_POINTF_get(contents, &X, &Y);
+ int status = U_PMF_POINTF_get(contents, &X, &Y, blimit);
if(status){
printf("{%f,%f}", X, Y);
}
@@ -1512,6 +1586,7 @@ int U_PMF_POINTF_S_print(U_PMF_POINTF *Point){
\param contents Pointer to next data to print
\param Xpos X coordinate for current point
\param Ypos Y coordinate for current point
+ \param blimit one byte past the end of data
On each call the next relative offset is extracted, the current
coordinates are modified with that offset, and the pointer is
@@ -1519,9 +1594,9 @@ int U_PMF_POINTF_S_print(U_PMF_POINTF *Point){
EMF+ manual 2.2.2.37, Microsoft name: EmfPlusPointR Object
*/
-int U_PMF_POINTR_print(const char **contents, U_FLOAT *Xpos, U_FLOAT *Ypos){
+int U_PMF_POINTR_print(const char **contents, U_FLOAT *Xpos, U_FLOAT *Ypos, const char *blimit){
U_FLOAT X, Y;
- int status = U_PMF_POINTR_get(contents, &X, &Y);
+ int status = U_PMF_POINTR_get(contents, &X, &Y, blimit);
*Xpos += X;
*Ypos += Y;
if(status){
@@ -1534,11 +1609,12 @@ int U_PMF_POINTR_print(const char **contents, U_FLOAT *Xpos, U_FLOAT *Ypos){
\brief Print data from a U_PMF_RECT 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.38, Microsoft name: EmfPlusRect Object
*/
-int U_PMF_RECT_print(const char **contents){
+int U_PMF_RECT_print(const char **contents, const char *blimit){
int16_t X, Y, Width, Height;
- int status = U_PMF_RECT_get(contents, &X, &Y, &Width, &Height);
+ int status = U_PMF_RECT_get(contents, &X, &Y, &Width, &Height, blimit);
if(status){
printf("{UL{%d,%d},WH{%d,%d}}", X, Y, Width, Height);
}
@@ -1560,11 +1636,12 @@ int U_PMF_RECT_S_print(U_PMF_RECT *Rect){
\brief Print data from a U_PMF_RECTF 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.39, Microsoft name: EmfPlusRectF Object
*/
-int U_PMF_RECTF_print(const char **contents){
+int U_PMF_RECTF_print(const char **contents, const char *blimit){
U_FLOAT X, Y, Width, Height;
- int status = U_PMF_RECTF_get(contents, &X, &Y, &Width, &Height);
+ int status = U_PMF_RECTF_get(contents, &X, &Y, &Width, &Height, blimit);
if(status){
printf("{UL{%f,%f},WH{%f,%f}}", X, Y, Width, Height);
}
@@ -1587,27 +1664,28 @@ int U_PMF_RECTF_S_print(U_PMF_RECTF *Rect){
\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.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);
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<SPLPEItem *>(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<SPLPEItem *>(lpeitem);
- defaultUnit = sp_lpe_item->document->getDisplayUnit()->abbr;
//printf("(SPLPEITEM*) %p\n", sp_lpe_item);
SPShape * shape = dynamic_cast<SPShape *>(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<Geom::Point> selectedNodesPoints;
SPCurve * sp_curve;
diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp
index a846e4bad..1b7f232ed 100644
--- a/src/live_effects/lpe-fillet-chamfer.cpp
+++ b/src/live_effects/lpe-fillet-chamfer.cpp
@@ -43,7 +43,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject)
: Effect(lpeobject),
satellites_param(_("pair_array_param"), _("pair_array_param"),
"satellites_param", &wr, this),
- unit(_("Unit:"), _("Unit"), "unit", &wr, this),
method(_("Method:"), _("Methods to calculate the fillet or chamfer"),
"method", FMConverter, &wr, this, FM_AUTO),
radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr,
@@ -69,7 +68,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject)
pointwise(NULL)
{
registerParameter(&satellites_param);
- registerParameter(&unit);
registerParameter(&method);
registerParameter(&radius);
registerParameter(&chamfer_steps);
@@ -278,8 +276,7 @@ void LPEFilletChamfer::updateAmount()
{
double power = 0;
if (!flexible) {
- power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(),
- defaultUnit);
+ power = radius;
} else {
power = radius / 100;
}
@@ -386,9 +383,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem)
c = path->get_original_curve();
}
//fillet chamfer specific calls
- satellites_param.setDocumentUnit(defaultUnit);
satellites_param.setUseDistance(use_knot_distance);
- satellites_param.setUnit(unit.get_abbreviation());
//mandatory call
satellites_param.setEffectType(effectType());
diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h
index 6acc9fb40..9ec5b5e04 100644
--- a/src/live_effects/lpe-fillet-chamfer.h
+++ b/src/live_effects/lpe-fillet-chamfer.h
@@ -17,7 +17,6 @@
*/
#include "live_effects/parameter/enum.h"
-#include "live_effects/parameter/unit.h"
#include "live_effects/parameter/satellitearray.h"
#include "live_effects/effect.h"
#include "helper/geom-pointwise.h"
@@ -54,7 +53,6 @@ public:
SatelliteArrayParam satellites_param;
private:
- UnitParam unit;
EnumParam<FilletMethod> method;
ScalarParam radius;
ScalarParam chamfer_steps;
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<SBasis> 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-knot.cpp b/src/live_effects/lpe-knot.cpp
index 820221abf..ec2f9c419 100644
--- a/src/live_effects/lpe-knot.cpp
+++ b/src/live_effects/lpe-knot.cpp
@@ -505,9 +505,9 @@ LPEKnot::doEffect_path (std::vector<Geom::Path> const &path_in)
static void
collectPathsAndWidths (SPLPEItem const *lpeitem, std::vector<Geom::Path> &paths, std::vector<double> &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<SPObject *>(iter->data);
+ std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
+ for ( std::vector<SPItem*>::const_iterator iter = item_list.begin(); iter != item_list.end(); iter++) {
+ SPObject *subitem = *iter;
if (SP_IS_LPE_ITEM(subitem)) {
collectPathsAndWidths(SP_LPE_ITEM(subitem), paths, stroke_widths);
}
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 <gtkmm/expander.h>
+
#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 <gtkmm.h>
#include "live_effects/parameter/enum.h"
+#include <gtkmm/widget.h>
#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/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 <glibmm/i18n.h>
-#include <util/units.h>
#include <cmath>
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<Gtk::Widget *>(param->param_newWidget());
- if (param->param_key == "unit") {
- Gtk::Label *unit_label = Gtk::manage(new Gtk::Label(
- Glib::ustring(_("<b>Roughen unit</b>")), 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(_("<b>Add nodes</b> 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<DivisionMethod> method;
ScalarParam max_segment_size;
ScalarParam segments;
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<D2<SBasis> > stretch_along(Piecewise<D2<SBasis> > 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/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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#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 <glibmm/threads.h>
-#endif
-
#include "live_effects/parameter/originalpatharray.h"
#include <gtkmm/widget.h>
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();
}
diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp
index 0e42c23c5..b0b036962 100644
--- a/src/live_effects/parameter/satellitearray.cpp
+++ b/src/live_effects/parameter/satellitearray.cpp
@@ -58,21 +58,11 @@ void SatelliteArrayParam::setPointwise(Geom::Pointwise *pointwise)
param_set_and_write_new_value(_last_pointwise->getSatellites());
}
-void SatelliteArrayParam::setDocumentUnit(Glib::ustring value_document_unit)
-{
- _documentUnit = value_document_unit;
-}
-
void SatelliteArrayParam::setUseDistance(bool use_knot_distance)
{
_use_distance = use_knot_distance;
}
-void SatelliteArrayParam::setUnit(const gchar *abbr)
-{
- _unit = abbr;
-}
-
void SatelliteArrayParam::setEffectType(EffectType et)
{
_effectType = et;
@@ -460,8 +450,8 @@ void FilletChamferKnotHolderEntity::knot_click(guint state)
: false;
}
Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog(
- this->desktop, amount, this, _pparam->_unit, _pparam->_use_distance,
- aprox, _pparam->_documentUnit, _pparam->_vector.at(index));
+ this->desktop, amount, this, _pparam->_use_distance,
+ aprox, _pparam->_vector.at(index));
}
}
diff --git a/src/live_effects/parameter/satellitearray.h b/src/live_effects/parameter/satellitearray.h
index bb53af12b..2845e3969 100644
--- a/src/live_effects/parameter/satellitearray.h
+++ b/src/live_effects/parameter/satellitearray.h
@@ -55,9 +55,7 @@ public:
return true;
}
void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/);
- void setDocumentUnit(Glib::ustring value_document__unit);
void setUseDistance(bool use_knot_distance);
- void setUnit(const gchar *abbr);
void setEffectType(EffectType et);
void setPointwise(Geom::Pointwise *pointwise);
void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode,
@@ -79,8 +77,6 @@ private:
Geom::PathVector _hp;
int _helper_size;
bool _use_distance;
- const gchar *_unit;
- Glib::ustring _documentUnit;
EffectType _effectType;
Geom::Pointwise *_last_pointwise;
diff --git a/src/main.cpp b/src/main.cpp
index 415118407..d1ebdc3bb 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;
+ std::vector<SPItem*> items;
SPRoot *root = doc->getRoot();
doc->ensureUpToDate();
for ( SPObject *iter = root->firstChild(); iter ; iter = iter->getNext()) {
@@ -1166,17 +1166,14 @@ 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;
+ std::vector<SPItem*> selected;
+ std::vector<Inkscape::XML::Node*> 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);
}
if(sp_export_id) {
doc->ensureUpToDate();
@@ -1435,7 +1432,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;
+ std::vector<SPItem*> items;
Geom::Rect area;
if (sp_export_id || sp_export_area_drawing) {
@@ -1459,7 +1456,7 @@ static int sp_do_export_png(SPDocument *doc)
return 1;
}
- items = g_slist_prepend (items, 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);
@@ -1644,10 +1641,12 @@ 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 : NULL) == 1 ) {
+ dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : std::vector<SPItem*>()) == 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 +1656,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..f9c189c58 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<SPItem*>(itemlist->data)) {
+ std::vector<SPItem*> rotationSource=_snapmanager->getRotationCenterSource();
+ for ( std::vector<SPItem*>::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/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<SPItem*> 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 <g> with " << num_elements << " elements\n";
diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp
index 5f6e1495b..7bd5b6298 100644
--- a/src/path-chemistry.cpp
+++ b/src/path-chemistry.cpp
@@ -44,13 +44,22 @@
using Inkscape::DocumentUndo;
+
+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();
+
+ std::vector<SPItem*> items(selection->itemList());
- if (g_slist_length((GSList *) selection->itemList()) < 1) {
+ if (items.size() < 1) {
desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to combine."));
return;
}
@@ -59,28 +68,23 @@ 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;
- if (!dynamic_cast<SPPath *>(item) && !dynamic_cast<SPGroup *>(item)) {
- to_paths = g_slist_prepend(to_paths, item);
+ std::vector<SPItem*> to_paths;
+ for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++) {
+ if (!dynamic_cast<SPPath *>(*i) && !dynamic_cast<SPGroup *>(*i)) {
+ to_paths.push_back(*i);
}
}
- 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)));
+ std::vector<Inkscape::XML::Node*> converted;
+ bool did = sp_item_list_to_curves(to_paths, items, converted);
+ for (std::vector<Inkscape::XML::Node*>::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
- 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
+ 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
gint position = 0;
@@ -97,9 +101,9 @@ sp_selected_path_combine(SPDesktop *desktop)
selection->clear();
}
- for (GSList *i = items; i != NULL; i = i->next) { // going from top to bottom
+ for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++){
- SPItem *item = (SPItem *) i->data;
+ SPItem *item = *i;
SPPath *path = dynamic_cast<SPPath *>(item);
if (!path) {
continue;
@@ -136,7 +140,6 @@ sp_selected_path_combine(SPDesktop *desktop)
}
}
- g_slist_free(items);
if (did) {
first->deleteObject(false);
@@ -200,11 +203,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) {
+ std::vector<SPItem*> itemlist(selection->itemList());
+ for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); i++){
- SPItem *item = (SPItem *) items->data;
+ SPItem *item = *i;
SPPath *path = dynamic_cast<SPPath *>(item);
if (!path) {
@@ -241,7 +243,7 @@ sp_selected_path_break_apart(SPDesktop *desktop)
curve->unref();
- GSList *reprs = NULL;
+ std::vector<Inkscape::XML::Node*> reprs;
for (GSList *l = list; l != NULL; l = l->next) {
curve = (SPCurve *) l->data;
@@ -267,14 +269,12 @@ sp_selected_path_break_apart(SPDesktop *desktop)
if (l == list)
repr->setAttribute("id", id);
- reprs = g_slist_prepend (reprs, repr);
+ reprs.push_back(repr);
Inkscape::GC::release(repr);
}
-
selection->setReprList(reprs);
- g_slist_free(reprs);
g_slist_free(list);
g_free(style);
g_free(path_effect);
@@ -307,18 +307,15 @@ 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;
+ std::vector<SPItem*> selected(selection->itemList());
+ std::vector<Inkscape::XML::Node*> to_select;
selection->clear();
- GSList *items = g_slist_copy(selected);
+ std::vector<SPItem*> 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);
selection->setReprList(to_select);
selection->addList(selected);
- g_slist_free (to_select);
- g_slist_free (selected);
if (interactive && desktop) {
desktop->clearWaitingCursor();
@@ -341,33 +338,24 @@ void sp_selected_to_lpeitems(SPDesktop *desktop)
return;
}
- GSList *selected = g_slist_copy((GSList *) selection->itemList());
- GSList *to_select = NULL;
+ std::vector<SPItem*> selected(selection->itemList());
+ std::vector<Inkscape::XML::Node*> to_select;
selection->clear();
- GSList *items = g_slist_copy(selected);
+ std::vector<SPItem*> 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;
selection->setReprList(to_select);
selection->addList(selected);
- g_slist_free(to_select);
- to_select = 0;
- g_slist_free(selected);
- selected = 0;
}
bool
-sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems)
+sp_item_list_to_curves(const std::vector<SPItem*> &items, std::vector<SPItem*>& selected, std::vector<Inkscape::XML::Node*> &to_select, bool skip_all_lpeitems)
{
bool did = false;
-
- for (;
- items != NULL;
- items = items->next) {
-
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
+ for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++){
+ SPItem *item = *i;
g_assert(item != NULL);
SPDocument *document = item->document;
@@ -398,9 +386,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.insert(to_select.begin(),repr);
did = true;
- *selected = g_slist_remove (*selected, item);
+ selected.erase(remove(selected.begin(), selected.end(), item), selected.end());
}
continue;
@@ -408,17 +396,14 @@ 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);
+ std::vector<SPItem*> item_list = sp_item_group_item_list(group);
- GSList *item_to_select = NULL;
- GSList *item_selected = NULL;
+ std::vector<Inkscape::XML::Node*> item_to_select;
+ std::vector<SPItem*> 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);
continue;
}
@@ -428,7 +413,7 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec
continue;
did = true;
- *selected = g_slist_remove (*selected, item);
+ selected.erase(remove(selected.begin(), selected.end(), item), selected.end());
// remember the position of the item
gint pos = item->getRepr()->position();
@@ -470,7 +455,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.insert(to_select.begin(),repr);
Inkscape::GC::release(repr);
}
@@ -488,6 +473,9 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/)
if (dynamic_cast<SPText *>(item) || dynamic_cast<SPFlowtext *>(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 +496,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 +537,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())
@@ -612,9 +607,9 @@ void
sp_selected_path_reverse(SPDesktop *desktop)
{
Inkscape::Selection *selection = desktop->getSelection();
- GSList *items = (GSList *) selection->itemList();
+ std::vector<SPItem*> items = selection->itemList();
- if (!items) {
+ if (items.empty()) {
desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse."));
return;
}
@@ -626,9 +621,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 (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++){
- SPPath *path = dynamic_cast<SPPath *>(static_cast<SPObject *>(i->data));
+ SPPath *path = dynamic_cast<SPPath *>(*i);
if (!path) {
continue;
}
diff --git a/src/path-chemistry.h b/src/path-chemistry.h
index a2150440c..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 GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems = false);
+bool sp_item_list_to_curves(const std::vector<SPItem*> &items, std::vector<SPItem*> &selected, std::vector<Inkscape::XML::Node*> &to_select, bool skip_all_lpeitems = false);
#endif // SEEN_PATH_CHEMISTRY_H
diff --git a/src/removeoverlap.cpp b/src/removeoverlap.cpp
index ba5740e55..9ea75de0d 100644
--- a/src/removeoverlap.cpp
+++ b/src/removeoverlap.cpp
@@ -38,20 +38,19 @@ 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) {
- using Inkscape::Util::GSListConstIterator;
- std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), items, NULL);
+void removeoverlap(std::vector<SPItem*> const &items, double const xGap, double const yGap) {
+ std::vector<SPItem*> selected(items);
std::vector<Record> records;
std::vector<Rectangle *> rs;
Geom::Point const gap(xGap, yGap);
- for (std::list<SPItem *>::iterator it(selected.begin());
+ for (std::vector<SPItem*>::iterator it(selected.begin());
it != selected.end();
++it)
{
+ SPItem* item = *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 +66,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..d873663d1 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(std::vector<SPItem*> const &items, double xGap, double yGap);
#endif // SEEN_REMOVEOVERLAP_H
diff --git a/src/selcue.cpp b/src/selcue.cpp
index d2fa0970a..c73219b7d 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 std::vector<SPItem*> 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<SPItem *>(l->data);
+ std::vector<SPItem*> ll=_selection->itemList();
+ for (std::vector<SPItem*>::const_iterator l = ll.begin(); l != ll.end(); l++) {
+ SPItem *item = *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<SPItem *>(l->data);
+ std::vector<SPItem*> ll=_selection->itemList();
+ for (std::vector<SPItem*>::const_iterator l = ll.begin(); l != ll.end(); l++) {
+ SPItem *item = *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<SPItem *>(l->data);
+ std::vector<SPItem*> ll = _selection->itemList();
+ for (std::vector<SPItem*>::const_iterator l=ll.begin();l!=ll.end();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 5e8fd5e07..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"
@@ -279,25 +280,21 @@ void SelectionHelper::fixSelection(SPDesktop *dt)
Inkscape::Selection *selection = dt->getSelection();
- GSList *items = NULL;
+ std::vector<SPItem*> items ;
- GSList const *selList = selection->itemList();
+ std::vector<SPItem*> const selList = selection->itemList();
- for( GSList const *i = selList; i; i = i->next ) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for( std::vector<SPItem*>::const_reverse_iterator i = selList.rbegin(); i != selList.rend(); i++ ) {
+ SPItem *item = *i;
if( item &&
!dt->isLayer(item) &&
(!item->isLocked()))
{
- items = g_slist_prepend(items, item);
+ items.push_back(item);
}
}
selection->setList(items);
-
- if(items) {
- g_slist_free(items);
- }
}
} // namespace Inkscape
@@ -307,7 +304,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, std::vector<Inkscape::XML::Node*> &clip, Inkscape::XML::Document* xml_doc)
{
Inkscape::XML::Node *copy = repr->duplicate(xml_doc);
@@ -323,41 +320,39 @@ 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.insert(clip.begin(),copy);
}
-static void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape::XML::Document* xml_doc)
+static void sp_selection_copy_impl(std::vector<SPItem*> const &items, std::vector<Inkscape::XML::Node*> &clip, Inkscape::XML::Document* xml_doc)
{
// Sort items:
- GSList *sorted_items = g_slist_copy(const_cast<GSList *>(items));
- sorted_items = g_slist_sort(static_cast<GSList *>(sorted_items), (GCompareFunc) sp_object_compare_position);
+ std::vector<SPItem*> sorted_items(items);
+ sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool);
// Copy item reprs:
- for (GSList *i = sorted_items; i != NULL; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(SP_OBJECT(i->data));
+ for (std::vector<SPItem*>::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();
}
}
-
- *clip = g_slist_reverse(*clip);
- g_slist_free(static_cast<GSList *>(sorted_items));
+ reverse(clip.begin(),clip.end());
}
// 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 std::vector<Inkscape::XML::Node*> sp_selection_paste_impl(SPDocument *doc, SPObject *parent, std::vector<Inkscape::XML::Node*> &clip)
{
Inkscape::XML::Document *xml_doc = doc->getReprDoc();
SPItem *parentItem = dynamic_cast<SPItem *>(parent);
g_assert(parentItem != NULL);
- GSList *copied = NULL;
+ std::vector<Inkscape::XML::Node*> copied;
// add objects to document
- for (GSList *l = *clip; l != NULL; l = l->next) {
- Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data);
+ for (std::vector<Inkscape::XML::Node*>::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
@@ -375,19 +370,19 @@ static GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList
}
parent->appendChildRepr(copy);
- copied = g_slist_prepend(copied, copy);
+ copied.push_back(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(std::vector<SPItem*> const &items, bool propagate = true, bool propagate_descendants = true)
{
- for (GSList const *i = items ; i ; i = i->next ) {
- sp_object_ref(static_cast<SPItem *>(i->data), NULL);
+ for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) {
+ sp_object_ref(*i, NULL);
}
- for (GSList const *i = items; i != NULL; i = i->next) {
- SPItem *item = static_cast<SPItem *>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) {
+ SPItem *item = *i;
item->deleteObject(propagate, propagate_descendants);
sp_object_unref(item, NULL);
}
@@ -414,11 +409,9 @@ void sp_selection_delete(SPDesktop *desktop)
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Nothing</b> was deleted."));
return;
}
-
- GSList *selected = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ std::vector<SPItem*> selected(selection->itemList());
selection->clear();
sp_selection_delete_impl(selected);
- g_slist_free(selected);
desktop->currentLayer()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
/* a tool may have set up private information in it's selection context
@@ -446,7 +439,7 @@ static void add_ids_recursive(std::vector<const gchar *> &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;
@@ -457,20 +450,24 @@ 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 <b>object(s)</b> to duplicate."));
return;
}
+ std::vector<Inkscape::XML::Node*> reprs(selection->reprList());
- GSList *reprs = g_slist_copy(const_cast<GSList *>(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
// them, just what we need
- reprs = g_slist_sort(reprs, (GCompareFunc) sp_repr_compare_position);
+ sort(reprs.begin(),reprs.end(),sp_repr_compare_position_bool);
- GSList *newsel = NULL;
+ std::vector<Inkscape::XML::Node*> newsel;
std::vector<const gchar *> old_ids;
std::vector<const gchar *> new_ids;
@@ -478,12 +475,15 @@ 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<Inkscape::XML::Node *>(reprs->data);
+ for(std::vector<Inkscape::XML::Node*>::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);
- parent->appendChild(copy);
+ if(! duplicateLayer)
+ parent->appendChild(copy);
+ else
+ parent->addChild(copy, old_repr);
if (relink_clones) {
SPObject *old_obj = doc->getObjectByRepr(old_repr);
@@ -500,8 +500,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone)
}
}
- newsel = g_slist_prepend(newsel, copy);
- reprs = g_slist_remove(reprs, reprs->data);
+ newsel.push_back(copy);
Inkscape::GC::release(copy);
}
@@ -545,10 +544,14 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone)
DocumentUndo::done(desktop->getDocument(), SP_VERB_EDIT_DUPLICATE,
_("Duplicate"));
}
-
- selection->setReprList(newsel);
-
- g_slist_free(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)
@@ -561,11 +564,10 @@ void sp_edit_clear_all(Inkscape::Selection *selection)
SPGroup *group = dynamic_cast<SPGroup *>(selection->layers()->currentLayer());
g_return_if_fail(group != NULL);
- GSList *items = sp_item_group_item_list(group);
+ std::vector<SPItem*> items = sp_item_group_item_list(group);
- while (items) {
- reinterpret_cast<SPObject*>(items->data)->deleteObject();
- items = g_slist_remove(items, items->data);
+ for(unsigned int i = 0; i < items.size(); i++){
+ items[i]->deleteObject();
}
DocumentUndo::done(doc, SP_VERB_EDIT_CLEAR_ALL,
@@ -582,7 +584,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)
+std::vector<SPItem*> &get_all_items(std::vector<SPItem*> &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, std::vector<SPItem*> const &exclude)
{
for ( SPObject *child = from->firstChild() ; child; child = child->getNext() ) {
SPItem *item = dynamic_cast<SPItem *>(child);
@@ -590,10 +592,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<GSList *>(exclude), child))
+ (exclude.empty() || exclude.end() == std::find(exclude.begin(),exclude.end(),child))
)
{
- list = g_slist_prepend(list, item);
+ list.insert(list.begin(),item);
}
if (ingroups || (item && desktop->isLayer(item))) {
@@ -618,9 +620,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;
+ std::vector<SPItem*> items ;
- GSList const *exclude = NULL;
+ std::vector<SPItem*> exclude;
if (invert) {
exclude = selection->itemList();
}
@@ -634,40 +636,38 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i
(onlyvisible && dt->itemIsHidden(dynamic_cast<SPItem *>(dt->currentLayer()))) )
return;
- GSList *all_items = sp_item_group_item_list(dynamic_cast<SPGroup *>(dt->currentLayer()));
+ std::vector<SPItem*> all_items = sp_item_group_item_list(dynamic_cast<SPGroup *>(dt->currentLayer()));
- for (GSList *i = all_items; i; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for (std::vector<SPItem*>::const_reverse_iterator i=all_items.rbegin();i!=all_items.rend();i++) {
+ SPItem *item = *i;
if (item && (!onlysensitive || !item->isLocked())) {
if (!onlyvisible || !dt->itemIsHidden(item)) {
if (!dt->isLayer(item)) {
- if (!invert || !g_slist_find(const_cast<GSList *>(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_back(item); // leave it in the list
}
}
}
}
}
- g_slist_free(all_items);
break;
}
case PREFS_SELECTION_LAYER_RECURSIVE: {
- items = get_all_items(NULL, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude);
+ std::vector<SPItem*> 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);
+ std::vector<SPItem*> x;
+ items = get_all_items(x, dt->currentRoot(), dt, onlyvisible, onlysensitive, FALSE, exclude);
break;
}
}
selection->setList(items);
- if (items) {
- g_slist_free(items);
- }
}
void sp_edit_select_all(SPDesktop *desktop)
@@ -690,16 +690,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(std::vector<Inkscape::XML::Node*> p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) {
- p = g_slist_sort(p, (GCompareFunc) 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 = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->position();
- Inkscape::XML::Node *topmost_parent = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->parent();
+ gint topmost = p.back()->position();
+ Inkscape::XML::Node *topmost_parent = p.back()->parent();
- while (p) {
- Inkscape::XML::Node *current = static_cast<Inkscape::XML::Node *>(p->data);
+ for(std::vector<Inkscape::XML::Node*>::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);
@@ -708,7 +708,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;
+ std::vector<Inkscape::XML::Node*> 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 +724,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,
+ std::vector<Inkscape::XML::Node*> 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<Inkscape::XML::Node *>(copied->data);
+ Inkscape::XML::Node *in_topmost = copied.back();
// make a copy
Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc);
// remove pasted
@@ -740,10 +740,9 @@ 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);
}
// Add the new group to the topmost members' parent
@@ -764,9 +763,7 @@ void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop)
return;
}
- GSList const *l = const_cast<GSList *>(selection->reprList());
-
- GSList *p = g_slist_copy(const_cast<GSList *>(l));
+ std::vector<Inkscape::XML::Node*> p (selection->reprList());
selection->clear();
@@ -802,11 +799,11 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop)
}
// first check whether there is anything to ungroup
- GSList *old_select = const_cast<GSList *>(selection->itemList());
- GSList *new_select = NULL;
+ std::vector<SPItem*> old_select = selection->itemList();
+ std::vector<SPItem*> new_select;
GSList *groups = NULL;
- for (GSList *item = old_select; item; item = item->next) {
- SPItem *obj = static_cast<SPItem*>(item->data);
+ for (std::vector<SPItem*>::const_iterator item = old_select.begin(); item!=old_select.end(); item++) {
+ SPItem *obj = *item;
if (dynamic_cast<SPGroup *>(obj)) {
groups = g_slist_prepend(groups, obj);
}
@@ -818,14 +815,14 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop)
return;
}
- GSList *items = g_slist_copy(old_select);
+ std::vector<SPItem*> 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<SPUse *>(static_cast<SPItem *>(item->data));
+ for (std::vector<SPItem*>::const_iterator item = items.begin(); item != items.end(); item++) {
+ SPUse *use = dynamic_cast<SPUse *>(*item);
SPItem *original = use;
while (dynamic_cast<SPUse *>(original)) {
@@ -833,7 +830,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 +841,53 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop)
for (GSList *item = clones_to_unlink; item; item = item->next) {
SPUse *use = static_cast<SPUse *>(item->data);
- GSList *items_node = g_slist_find(items, item->data);
- items_node->data = use->unlink();
+ std::vector<SPItem*>::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<SPItem *>(item->data);
+ for (std::vector<SPItem*>::iterator item = items.begin(); item != items.end(); item++) {
+ SPItem *obj = *item;
// ungroup only the groups marked earlier
- if (g_slist_find(groups, item->data) != NULL) {
- GSList *children = NULL;
- sp_item_group_ungroup(dynamic_cast<SPGroup *>(obj), &children, false);
+ if (g_slist_find(groups, *item) != NULL) {
+ std::vector<SPItem*> children;
+ sp_item_group_ungroup(dynamic_cast<SPGroup *>(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.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
- 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);
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)
+std::vector<SPItem*>
+sp_degroup_list(std::vector<SPItem*> &items)
{
- GSList *out = NULL;
+ std::vector<SPItem*> out;
bool has_groups = false;
- for (GSList *item = items; item; item = item->next) {
- SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(item->data));
+ for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();item++) {
+ SPGroup *group = dynamic_cast<SPGroup *>(*item);
if (!group) {
- out = g_slist_prepend(out, item->data);
+ out.push_back(*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);
+ std::vector<SPItem*> members = sp_item_group_item_list(group);
+ for (std::vector<SPItem*>::const_iterator member=members.begin();member!=members.end();member++) {
+ out.push_back(*member);
}
- g_slist_free(members);
+ members.clear();
}
}
- out = g_slist_reverse(out);
- g_slist_free(items);
if (has_groups) { // recurse if we unwrapped a group - it may have contained others
out = sp_degroup_list(out);
@@ -906,18 +899,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(std::vector<SPItem*> const items)
{
- if (!items) {
+ if (items.empty()) {
return NULL;
}
- SPObject *parent = SP_OBJECT(items->data)->parent;
+ SPObject *parent = items[0]->parent;
// Strictly speaking this CAN happen, if user selects <svg> from Inkscape::XML editor
if (!dynamic_cast<SPGroup *>(parent)) {
return NULL;
}
- for (items = items->next; items; items = items->next) {
- if (SP_OBJECT(items->data)->parent != parent) {
+ for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();item++) {
+ if((*item)==items[0])continue;
+ if ((*item)->parent != parent) {
return NULL;
}
}
@@ -927,13 +921,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(std::vector<SPItem*> 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<SPItem *>(i->data)->desktopVisualBounds());
+ for (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++) {
+ r.unionWith((*i)->desktopVisualBounds());
}
return r;
}
@@ -948,11 +942,17 @@ static SPObject *prev_sibling(SPObject *child)
return prev;
}
+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;
+}
+
void
sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop)
{
- GSList const *items = const_cast<GSList *>(selection->itemList());
- if (!items) {
+ std::vector<SPItem*> items= selection->itemList();
+ if (items.empty()) {
selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise."));
return;
}
@@ -966,16 +966,16 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop)
Inkscape::XML::Node *grepr = const_cast<Inkscape::XML::Node *>(group->getRepr());
/* Construct reverse-ordered list of selected children. */
- GSList *rev = g_slist_copy(const_cast<GSList *>(items));
- rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position);
+ std::vector<SPItem*> rev(items);
+ 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);
// Iterate over all objects in the selection (starting from top).
if (selected) {
- while (rev) {
- SPObject *child = reinterpret_cast<SPObject*>(rev->data);
+ for (std::vector<SPItem*>::const_iterator item=rev.begin();item!=rev.end();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,
@@ -984,7 +984,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<GSList *>(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,12 +992,8 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop)
}
}
}
- rev = g_slist_remove(rev, child);
}
- } else {
- g_slist_free(rev);
}
-
DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_RAISE,
//TRANSLATORS: "Raise" means "to raise an object" in the undo history
C_("Undo action", "Raise"));
@@ -1012,7 +1008,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto
return;
}
- GSList const *items = const_cast<GSList *>(selection->itemList());
+ std::vector<SPItem*> items = selection->itemList();
SPGroup const *group = sp_item_list_common_parent_group(items);
if (!group) {
@@ -1020,24 +1016,22 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto
return;
}
- GSList *rl = g_slist_copy(const_cast<GSList *>(selection->reprList()));
- rl = g_slist_sort(rl, (GCompareFunc) sp_repr_compare_position);
+ std::vector<Inkscape::XML::Node*> rl(selection->reprList());
+ sort(rl.begin(),rl.end(),sp_repr_compare_position_bool);
- for (GSList *l = rl; l != NULL; l = l->next) {
- Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data);
+ for (std::vector<Inkscape::XML::Node*>::const_iterator l=rl.begin(); l!=rl.end();l++) {
+ Inkscape::XML::Node *repr =(*l);
repr->setPosition(-1);
}
- g_slist_free(rl);
-
DocumentUndo::done(document, SP_VERB_SELECTION_TO_FRONT,
_("Raise to top"));
}
void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop)
{
- GSList const *items = const_cast<GSList *>(selection->itemList());
- if (!items) {
+ std::vector<SPItem*> items = selection->itemList();
+ if (items.empty()) {
selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower."));
return;
}
@@ -1054,14 +1048,13 @@ 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<GSList *>(items));
- rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position);
- rev = g_slist_reverse(rev);
+ std::vector<SPItem*> rev(items);
+ sort(rev.begin(),rev.end(),sp_item_repr_compare_position_bool);
// Iterate over all objects in the selection (starting from top).
if (selected) {
- while (rev) {
- SPObject *child = reinterpret_cast<SPObject*>(rev->data);
+ for (std::vector<SPItem*>::const_reverse_iterator item=rev.rbegin();item!=rev.rend();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,
@@ -1070,7 +1063,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<GSList *>(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 +1075,7 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop)
}
}
}
- rev = g_slist_remove(rev, child);
}
- } else {
- g_slist_free(rev);
}
DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_LOWER,
@@ -1102,7 +1092,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des
return;
}
- GSList const *items = const_cast<GSList *>(selection->itemList());
+ std::vector<SPItem*> items =selection->itemList();
SPGroup const *group = sp_item_list_common_parent_group(items);
if (!group) {
@@ -1110,15 +1100,13 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des
return;
}
- GSList *rl;
- rl = g_slist_copy(const_cast<GSList *>(selection->reprList()));
- rl = g_slist_sort(rl, (GCompareFunc) sp_repr_compare_position);
- rl = g_slist_reverse(rl);
+ std::vector<Inkscape::XML::Node*> rl(selection->reprList());
+ sort(rl.begin(),rl.end(),sp_repr_compare_position_bool);
- for (GSList *l = rl; l != NULL; l = l->next) {
+ for (std::vector<Inkscape::XML::Node*>::const_reverse_iterator l=rl.rbegin();l!=rl.rend();l++) {
gint minpos;
SPObject *pp, *pc;
- Inkscape::XML::Node *repr = static_cast<Inkscape::XML::Node *>(l->data);
+ Inkscape::XML::Node *repr = (*l);
pp = document->getObjectByRepr(repr->parent());
minpos = 0;
g_assert(dynamic_cast<SPGroup *>(pp));
@@ -1130,8 +1118,6 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des
repr->setPosition(minpos);
}
- g_slist_free(rl);
-
DocumentUndo::done(document, SP_VERB_SELECTION_TO_BACK,
_("Lower to bottom"));
}
@@ -1269,9 +1255,9 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop)
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to remove live path effects from."));
return;
}
-
- for ( GSList const *itemlist = selection->itemList(); itemlist != NULL; itemlist = g_slist_next(itemlist) ) {
- SPItem *item = reinterpret_cast<SPItem*>(itemlist->data);
+ std::vector<SPItem*> list=selection->itemList();
+ for ( std::vector<SPItem*>::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) {
+ SPItem *item = *itemlist;
sp_selection_remove_livepatheffect_impl(item);
@@ -1325,10 +1311,10 @@ void sp_selection_paste_size_separately(SPDesktop *desktop, bool apply_x, bool a
* Ensures that the clones of objects are not modified when moving objects between layers.
* Calls the same function as ungroup
*/
-void sp_selection_change_layer_maintain_clones(GSList const *items,SPObject *where)
+void sp_selection_change_layer_maintain_clones(std::vector<SPItem*> const &items,SPObject *where)
{
- for (const GSList *i = items; i != NULL; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(SP_OBJECT(i->data));
+ for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) {
+ SPItem *item = *i;
if (item) {
SPItem *oldparent = dynamic_cast<SPItem *>(item->parent);
SPItem *newparent = dynamic_cast<SPItem *>(where);
@@ -1350,26 +1336,24 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone)
return;
}
- GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ std::vector<SPItem*> 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) {
sp_selection_change_layer_maintain_clones(items,next);
- GSList *temp_clip = NULL;
- sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc());
+ std::vector<Inkscape::XML::Node*> 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;
+ std::vector<Inkscape::XML::Node*> 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);
if (next) dt->setCurrentLayer(next);
if ( !suppressDone ) {
DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_NEXT,
@@ -1383,7 +1367,6 @@ 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<GSList *>(items));
}
void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone)
@@ -1396,26 +1379,24 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone)
return;
}
- GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ const std::vector<SPItem*> 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) {
sp_selection_change_layer_maintain_clones(items,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
+ std::vector<Inkscape::XML::Node*> 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;
+ std::vector<Inkscape::XML::Node*> 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);
if (next) dt->setCurrentLayer(next);
if ( !suppressDone ) {
DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_MOVE_TO_PREV,
@@ -1428,8 +1409,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<GSList *>(items));
}
void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone)
@@ -1442,25 +1421,22 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone)
return;
}
- GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ std::vector<SPItem*> items(selection->itemList());
if (moveto) {
sp_selection_change_layer_maintain_clones(items,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
+ std::vector<Inkscape::XML::Node*> 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);
+ std::vector<Inkscape::XML::Node*> copied = sp_selection_paste_impl(dt->getDocument(), moveto, temp_clip);
+ selection->setReprList(copied);
+ 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<GSList *>(items));
}
static bool
@@ -1495,8 +1471,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<SPItem *>(static_cast<SPObject *>(l->data));
+ std::vector<SPItem*> items = selection->itemList();
+ for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) {
+ SPItem *item = *l;
if (item) {
clone_with_original |= selection_contains_original(item, selection);
if (clone_with_original)
@@ -1539,9 +1516,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<SPItem *>(static_cast<SPObject *>(l->data));
+ std::vector<SPItem*> items = selection->itemList();
+ for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) {
+ SPItem *item = *l;
if( dynamic_cast<SPRoot *>(item) ) {
// An SVG element cannot have a transform. We could change 'x' and 'y' in response
@@ -1710,10 +1687,9 @@ void sp_selection_remove_transform(SPDesktop *desktop)
Inkscape::Selection *selection = desktop->getSelection();
- GSList const *l = const_cast<GSList *>(selection->reprList());
- while (l != NULL) {
- ((Inkscape::XML::Node*)l->data)->setAttribute("transform", NULL, false);
- l = l->next;
+ std::vector<Inkscape::XML::Node*> items = selection->reprList();
+ for (std::vector<Inkscape::XML::Node*>::const_iterator l=items.begin();l!=items.end() ;l++) {
+ (*l)->setAttribute("transform", NULL, false);
}
DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_FLATTEN,
@@ -1811,10 +1787,10 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw)
if (selection->isEmpty())
return;
- GSList const *l = selection->itemList();
+ std::vector<SPItem*> 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<SPItem *>(static_cast<SPObject *>(l2->data));
+ for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) {
+ SPItem *item = *l;
if (item) {
sp_item_rotate_rel(item, rot_90);
} else {
@@ -1870,15 +1846,24 @@ 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;
+ std::vector<SPItem*> x,y;
+ std::vector<SPItem*> all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y);
+ std::vector<SPItem*> all_matches;
Inkscape::Selection *selection = desktop->getSelection();
+ std::vector<SPItem*> items = selection->itemList();
+
+ std::vector<SPItem*> tmp;
+ for (std::vector<SPItem*>::const_iterator iter=all_list.begin();iter!=all_list.end();iter++) {
+ if(!SP_IS_GROUP(*iter)){
+ tmp.push_back(*iter);
+ }
+ }
+ all_list=tmp;
- for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) {
- SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data));
- GSList *matches = all_list;
+ for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) {
+ SPItem *sel = *sel_iter;
+ std::vector<SPItem*> matches = all_list;
if (fill && stroke && style) {
matches = sp_get_same_style(sel, matches);
}
@@ -1891,19 +1876,12 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea
else if (style) {
matches = sp_get_same_style(sel, matches,SP_STROKE_STYLE_ALL);
}
- all_matches = g_slist_concat (all_matches, matches);
+ all_matches.insert(all_matches.end(), matches.begin(),matches.end());
}
selection->clear();
selection->setList(all_matches);
- if (all_matches) {
- g_slist_free(all_matches);
- }
- if (all_list) {
- g_slist_free(all_list);
- }
-
}
@@ -1924,14 +1902,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;
+ std::vector<SPItem*> x,y;
+ std::vector<SPItem*> all_list = get_all_items(x, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, y);
+ std::vector<SPItem*> 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<SPItem *>(static_cast<SPObject *>(sel_iter->data));
+ std::vector<SPItem*> items=selection->itemList();
+ for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) {
+ SPItem *sel = *sel_iter;
if (sel) {
matches = sp_get_same_object_type(sel, matches);
} else {
@@ -1942,12 +1921,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);
- }
}
@@ -1956,15 +1929,15 @@ void sp_select_same_object_type(SPDesktop *desktop)
* 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)
+std::vector<SPItem*> sp_get_same_fill_or_stroke_color(SPItem *sel, std::vector<SPItem*> &src, SPSelectStrokeStyleType type)
{
- GSList *matches = NULL;
+ std::vector<SPItem*> 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<SPItem *>(static_cast<SPObject *>(i->data));
+ for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) {
+ SPItem *iter = *i;
if (iter) {
SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke);
match = false;
@@ -2003,7 +1976,7 @@ GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrok
}
if (match) {
- matches = g_slist_prepend(matches, iter);
+ matches.push_back(iter);
}
} else {
g_assert_not_reached();
@@ -2054,17 +2027,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)
+std::vector<SPItem*> sp_get_same_object_type(SPItem *sel, std::vector<SPItem*> &src)
{
- GSList *matches = NULL;
+ std::vector<SPItem*> matches;
- for (GSList *i = src; i != NULL; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) {
+ SPItem *item = *i;
if (item && item_type_match(sel, item) && !item->cloned) {
- matches = g_slist_prepend (matches, item);
+ matches.push_back(item);
}
}
-
return matches;
}
@@ -2074,9 +2046,9 @@ GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrok
* 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_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type)
+std::vector<SPItem*> sp_get_same_style(SPItem *sel, std::vector<SPItem*> &src, SPSelectStrokeStyleType type)
{
- GSList *matches = NULL;
+ std::vector<SPItem*> matches;
bool match = false;
SPStyle *sel_style = sel->style;
@@ -2092,16 +2064,16 @@ GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type
* Stroke width needs to handle transformations, so call this function
* to get the transformed stroke width
*/
- GSList *objects = NULL;
+ std::vector<SPItem*> objects;
SPStyle *sel_style_for_width = NULL;
if (type == SP_STROKE_STYLE_WIDTH || type == SP_STROKE_STYLE_ALL || type==SP_STYLE_ALL ) {
- objects = g_slist_prepend(objects, sel);
+ objects.push_back(sel);
sel_style_for_width = new SPStyle(SP_ACTIVE_DOCUMENT);
objects_query_strokewidth (objects, sel_style_for_width);
}
bool match_g;
- for (GSList *i = src; i != NULL; i = i->next) {
- SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for (std::vector<SPItem*>::const_iterator i=src.begin();i!=src.end();i++) {
+ SPItem *iter = *i;
if (iter) {
match_g=true;
SPStyle *iter_style = iter->style;
@@ -2110,15 +2082,14 @@ GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type
if (type == SP_STROKE_STYLE_WIDTH|| type == SP_STROKE_STYLE_ALL|| type==SP_STYLE_ALL) {
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);
+ std::vector<SPItem*> objects;
+ objects.insert(objects.begin(),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);
}
}
match_g = match_g && match;
@@ -2141,10 +2112,10 @@ GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type
}
}
}
- match_g = match_g && match;
+ match_g = match_g && match;
if (match_g) {
while (iter->cloned) iter=dynamic_cast<SPItem *>(iter->parent);
- matches = g_slist_prepend(matches, iter);
+ matches.insert(matches.begin(),iter);
}
} else {
g_assert_not_reached();
@@ -2152,8 +2123,6 @@ GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type
}
if( sel_style_for_width != NULL ) delete sel_style_for_width;
- g_slist_free(objects);
-
return matches;
}
@@ -2307,17 +2276,9 @@ sp_selection_move_screen(Inkscape::Selection *selection, gdouble dx, gdouble dy)
}
}
-namespace {
-template <typename D>
-SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root,
- bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive);
-template <typename D>
-SPItem *next_item_from_list(SPDesktop *desktop, GSList 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(); }
@@ -2326,9 +2287,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) {
@@ -2359,8 +2320,87 @@ private:
}
return list;
}
-};
+} ListReverse;
+
+
+
+template <typename D>
+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<SPObject *>(path->data);
+ g_assert(object->parent == root);
+ if (desktop->isLayer(object)) {
+ found = next_item<D>(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<D>(desktop, NULL, object, only_in_viewport, inlayer, onlyvisible, onlysensitive);
+ }
+ } else {
+ SPItem *item = dynamic_cast<SPItem *>(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 <typename D>
+SPItem *next_item_from_list(SPDesktop *desktop, std::vector<SPItem*> const items,
+ SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive)
+{
+ SPObject *current=root;
+ for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++) {
+ SPItem *item = *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<D>(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<D>(desktop, NULL, root, only_in_viewport, inlayer, onlyvisible, onlysensitive);
+ }
+
+ return next;
}
void
@@ -2487,88 +2527,8 @@ void sp_selection_edit_clip_or_mask(SPDesktop * /*dt*/, bool /*clip*/)
}
-namespace {
-
-template <typename D>
-SPItem *next_item_from_list(SPDesktop *desktop, GSList const *items,
- SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive)
-{
- SPObject *current=root;
- while (items) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
- if ( root->isAncestorOf(item) &&
- ( !only_in_viewport || desktop->isWithinViewport(item) ) )
- {
- current = item;
- break;
- }
- items = items->next;
- }
-
- 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<D>(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<D>(desktop, NULL, root, only_in_viewport, inlayer, onlyvisible, onlysensitive);
- }
-
- return next;
-}
-
-template <typename D>
-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<SPObject *>(path->data);
- g_assert(object->parent == root);
- if (desktop->isLayer(object)) {
- found = next_item<D>(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<D>(desktop, NULL, object, only_in_viewport, inlayer, onlyvisible, onlysensitive);
- }
- } else {
- SPItem *item = dynamic_cast<SPItem *>(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
@@ -2608,17 +2568,17 @@ void sp_selection_clone(SPDesktop *desktop)
return;
}
- GSList *reprs = g_slist_copy(const_cast<GSList *>(selection->reprList()));
+ std::vector<Inkscape::XML::Node*> 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);
+ sort(reprs.begin(),reprs.end(),sp_repr_compare_position_bool);
- GSList *newsel = NULL;
+ std::vector<Inkscape::XML::Node*> newsel;
- while (reprs) {
- Inkscape::XML::Node *sel_repr = static_cast<Inkscape::XML::Node *>(reprs->data);
+ for(std::vector<Inkscape::XML::Node*>::const_reverse_iterator i=reprs.rbegin();i!=reprs.rend();i++){
+ Inkscape::XML::Node *sel_repr = *i;
Inkscape::XML::Node *parent = sel_repr->parent();
Inkscape::XML::Node *clone = xml_doc->createElement("svg:use");
@@ -2634,8 +2594,7 @@ 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_back(clone);
Inkscape::GC::release(clone);
}
@@ -2643,8 +2602,6 @@ void sp_selection_clone(SPDesktop *desktop)
C_("Action", "Clone"));
selection->setReprList(newsel);
-
- g_slist_free(newsel);
}
void
@@ -2670,11 +2627,9 @@ sp_selection_relink(SPDesktop *desktop)
// Get a copy of current selection.
bool relinked = false;
- for (GSList *items = const_cast<GSList *>(selection->itemList());
- items != NULL;
- items = items->next)
- {
- SPItem *item = static_cast<SPItem *>(items->data);
+ std::vector<SPItem*> items=selection->itemList();
+ for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *item = *i;
if (dynamic_cast<SPUse *>(item)) {
item->getRepr()->setAttribute("xlink:href", newref);
@@ -2708,13 +2663,11 @@ sp_selection_unlink(SPDesktop *desktop)
}
// Get a copy of current selection.
- GSList *new_select = NULL;
+ std::vector<SPItem*> new_select;
bool unlinked = false;
- for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
- items != NULL;
- items = items->next)
- {
- SPItem *item = static_cast<SPItem *>(items->data);
+ std::vector<SPItem*> items=selection->itemList();
+ for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){
+ SPItem *item = *i;
if (dynamic_cast<SPText *>(item)) {
SPObject *tspan = sp_tref_convert_to_tspan(item);
@@ -2730,7 +2683,7 @@ sp_selection_unlink(SPDesktop *desktop)
if (!(dynamic_cast<SPUse *>(item) || dynamic_cast<SPTRef *>(item))) {
// keep the non-use item in the new selection
- new_select = g_slist_prepend(new_select, item);
+ new_select.push_back(item);
continue;
}
@@ -2740,7 +2693,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_back(item);
continue;
}
} else /*if (SP_IS_TREF(use))*/ {
@@ -2750,13 +2703,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_back(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, _("<b>No clones to unlink</b> in the selection."));
@@ -2779,7 +2731,9 @@ sp_select_clone_original(SPDesktop *desktop)
gchar const *error = _("Select a <b>clone</b> to go to its original. Select a <b>linked offset</b> to go to its source. Select a <b>text on path</b> to go to the path. Select a <b>flowed text</b> to go to its frame.");
// Check if other than two objects are selected
- if (g_slist_length(const_cast<GSList *>(selection->itemList())) != 1 || !item) {
+
+ std::vector<SPItem*> items=selection->itemList();
+ if (items.size() != 1 || !item) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, error);
return;
}
@@ -2876,14 +2830,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)) {
+ std::vector<SPItem*> items=selection->itemList();
+ for (std::vector<SPItem*>::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) {
@@ -2960,12 +2915,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<GSList *>(selection->itemList()));
+ std::vector<SPItem*> 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 = items[0]->parent;
Geom::Affine parent_transform;
{
@@ -2978,10 +2933,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);
+ std::vector<Inkscape::XML::Node*> repr_copies;
+ for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){
+ Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc);
+ repr_copies.push_back(dup);
}
Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max()));
@@ -2989,8 +2944,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<SPObject*>(i->data);
+ for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPObject *item = *i;
item->deleteObject(false);
}
}
@@ -3009,7 +2964,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"));
@@ -3018,8 +2972,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<SPGroup *>(item);
if (group && !dynamic_cast<SPBox3D *>(item) && !wholegroups) {
- for (GSList *i = sp_item_group_item_list(group); i != NULL; i = i->next) {
- sp_selection_to_guides_recursive(static_cast<SPItem*>(i->data), wholegroups);
+ std::vector<SPItem*> items=sp_item_group_item_list(group);
+ for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ sp_selection_to_guides_recursive(*i, wholegroups);
}
} else {
item->convert_to_guides();
@@ -3034,9 +2989,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<GSList *>(selection->itemList()));
+ std::vector<SPItem*> items(selection->itemList());
- if (!items) {
+ if (items.empty()) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to guides."));
return;
}
@@ -3049,8 +3004,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<SPItem*>(i->data), wholegroups);
+ for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ sp_selection_to_guides_recursive(*i, wholegroups);
}
if (deleteitems) {
@@ -3058,8 +3013,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"));
}
@@ -3102,18 +3055,18 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ )
doc->ensureUpToDate();
- GSList *items = g_slist_copy(const_cast<GSList *>(selection->list()));
+ std::vector<SPObject*> items(selection->list());
// Keep track of parent, this is where <use> will be inserted.
- Inkscape::XML::Node *the_first_repr = reinterpret_cast<SPObject *>( items->data )->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
bool single_group = false;
SPGroup *the_group = NULL;
Geom::Affine transform;
- if( g_slist_length( items ) == 1 ) {
- SPObject *object = reinterpret_cast<SPObject *>( items->data );
+ if( items.size() == 1 ) {
+ SPObject *object = items[0];
the_group = dynamic_cast<SPGroup *>(object);
if ( the_group ) {
single_group = true;
@@ -3124,7 +3077,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
@@ -3170,8 +3122,8 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ )
}
// Move selected items to new <symbol>
- for (GSList *i = items; i != NULL; i = i->next) {
- Inkscape::XML::Node *repr = SP_OBJECT(i->data)->getRepr();
+ for (std::vector<SPObject*>::const_iterator i=items.begin();i!=items.end();i++){
+ Inkscape::XML::Node *repr = (*i)->getRepr();
repr->parent()->removeChild(repr);
symbol_repr->addChild(repr,NULL);
}
@@ -3197,7 +3149,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"));
}
@@ -3238,26 +3189,25 @@ void sp_selection_unsymbol(SPDesktop *desktop)
desktop->currentLayer()->getRepr()->appendChild(group);
// Move all children of symbol to group
- GSList* children = symbol->childList(false);
+ std::vector<SPObject*> 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<SPObject *>( children->data );
+ if( children.size() == 1 ) {
+ SPObject *object = children[0];
if ( dynamic_cast<SPGroup *>( 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 (std::vector<SPObject*>::const_reverse_iterator i=children.rbegin();i!=children.rend();i++){
+ Inkscape::XML::Node *repr = (*i)->getRepr();
repr->parent()->removeChild(repr);
group->addChild(repr,NULL);
}
@@ -3283,7 +3233,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"));
}
@@ -3318,12 +3267,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<GSList *>(selection->itemList()));
+ std::vector<SPItem*> items (selection->itemList());
- items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position);
+ sort(items.begin(),items.end(),sp_object_compare_position_bool);
// bottommost object, after sorting
- SPObject *parent = SP_OBJECT(items->data)->parent;
+ SPObject *parent = items[0]->parent;
Geom::Affine parent_transform;
@@ -3337,23 +3286,21 @@ sp_selection_tile(SPDesktop *desktop, bool apply)
}
// remember the position of the first item
- gint pos = SP_OBJECT(items->data)->getRepr()->position();
+ gint pos = items[0]->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);
+ std::vector<Inkscape::XML::Node*> repr_copies;
+ for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc);
+ repr_copies.push_back(dup);
}
- // restore the z-order after prepends
- repr_copies = g_slist_reverse(repr_copies);
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<SPObject*>(i->data);
+ for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPObject *item = *i;
item->deleteObject(false);
}
}
@@ -3399,7 +3346,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"));
@@ -3422,15 +3368,13 @@ void sp_selection_untile(SPDesktop *desktop)
return;
}
- GSList *new_select = NULL;
+ std::vector<SPItem*> new_select;
bool did = false;
- for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
- items != NULL;
- items = items->next) {
-
- SPItem *item = static_cast<SPItem *>(items->data);
+ std::vector<SPItem*> items(selection->itemList());
+ for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){
+ SPItem *item = *i;
SPStyle *style = item->style;
@@ -3466,7 +3410,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_back(i);
} else {
g_assert_not_reached();
}
@@ -3493,18 +3437,14 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring
return;
}
- GSList const *reprlst = selection->reprList();
+ std::vector<Inkscape::XML::Node*> 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 (std::vector<Inkscape::XML::Node*>::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<Inkscape::XML::Node *>(reprlst->data);
+ Inkscape::XML::Node *repr = *i;
if (filename_search) {
const gchar* tmp = repr->attribute("inkscape:export-filename");
@@ -3590,10 +3530,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<GSList *>(selection->itemList()));
+ std::vector<SPItem*> items(selection->itemList());
// Sort items so that the topmost comes last
- items = g_slist_sort(items, (GCompareFunc) 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)
@@ -3604,7 +3544,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"),
+ 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 "_"
@@ -3624,8 +3564,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 = items.back()->getRepr()->position();
+ SPObject *parent_object = items.back()->parent;
Inkscape::XML::Node *parent = parent_object->getRepr();
// Calculate resolution
@@ -3717,8 +3657,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);
@@ -3793,22 +3731,20 @@ void sp_selection_set_clipgroup(SPDesktop *desktop)
return;
}
- GSList const *l = const_cast<GSList *>(selection->reprList());
-
- GSList *p = g_slist_copy(const_cast<GSList *>(l));
+ std::vector<Inkscape::XML::Node*> p(selection->reprList());
- p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position);
+ sort(p.begin(),p.end(),sp_repr_compare_position_bool);
selection->clear();
- gint topmost = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->position();
- Inkscape::XML::Node *topmost_parent = (static_cast<Inkscape::XML::Node *>(g_slist_last(p)->data))->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) {
- Inkscape::XML::Node *current = static_cast<Inkscape::XML::Node *>(p->data);
+ for(std::vector<Inkscape::XML::Node*>::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);
@@ -3817,7 +3753,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;
+ std::vector<Inkscape::XML::Node*> 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
@@ -3833,15 +3769,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,
+ std::vector<Inkscape::XML::Node*> 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<Inkscape::XML::Node *>(copied->data);
+ Inkscape::XML::Node *in_topmost = copied.back();
// make a copy
Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc);
// remove pasted
@@ -3849,10 +3784,8 @@ 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);
}
Inkscape::XML::Node *outer = xml_doc->createElement("svg:g");
@@ -3869,13 +3802,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<Inkscape::XML::Node*> 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));
@@ -3910,7 +3841,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 <b>object(s)</b> 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 <b>object(s)</b> to apply clippath or mask to."));
return;
}
@@ -3925,18 +3856,18 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_
doc->ensureUpToDate();
- GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ std::vector<SPItem*> items(selection->itemList());
- items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position);
+ sort(items.begin(),items.end(),sp_object_compare_position_bool);
// See lp bug #542004
selection->clear();
// create a list of duplicates
- GSList *mask_items = NULL;
- GSList *apply_to_items = NULL;
- GSList *items_to_delete = NULL;
- GSList *items_to_select = NULL;
+ std::vector<Inkscape::XML::Node*> mask_items;
+ std::vector<SPItem*> apply_to_items;
+ std::vector<SPItem*> items_to_delete;
+ std::vector<SPItem*> items_to_select;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
bool topmost = prefs->getBool("/options/maskobject/topmost", true);
@@ -3945,55 +3876,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<SPItem*>::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 (GSList *i = items; i != NULL; i = i->next) {
- Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc);
- mask_items = g_slist_prepend(mask_items, dup);
+ Geom::Affine oldtr=(*i)->transform;
+ (*i)->doWriteTransform((*i)->getRepr(), (*i)->i2doc_affine());
+ Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc);
+ (*i)->doWriteTransform((*i)->getRepr(), oldtr);
+ mask_items.push_back(dup);
- SPObject *item = reinterpret_cast<SPObject*>(i->data);
if (remove_original) {
- items_to_delete = g_slist_prepend(items_to_delete, item);
+ items_to_delete.push_back(*i);
}
else {
- items_to_select = g_slist_prepend(items_to_select, 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
- GSList *i = items;
- Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc);
- mask_items = g_slist_prepend(mask_items, dup);
-
- if (remove_original) {
- SPObject *item = reinterpret_cast<SPObject*>(i->data);
- 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);
- }
- } 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);
- }
-
- Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc);
- mask_items = g_slist_prepend(mask_items, dup);
-
- if (remove_original) {
- SPObject *item = reinterpret_cast<SPObject*>(i->data);
- items_to_delete = g_slist_prepend(items_to_delete, item);
+ continue;
+ }else{
+ apply_to_items.push_back(*i);
+ items_to_select.push_back(*i);
}
}
- g_slist_free(items);
- items = NULL;
+ 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");
@@ -4001,52 +3913,36 @@ 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;
-
- 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);
+ std::vector<Inkscape::XML::Node*> reprs_to_group;
+ for (std::vector<SPItem*>::const_iterator i = apply_to_items.begin(); i != apply_to_items.end(); i++) {
+ reprs_to_group.push_back(static_cast<SPObject*>(*i)->getRepr());
}
- reprs_to_group = g_slist_reverse(reprs_to_group);
+ items_to_select.clear();
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));
+ apply_to_items.clear();
+ apply_to_items.push_back(dynamic_cast<SPItem*>(doc->getObjectByRepr(group)));
- items_to_select = g_slist_prepend(items_to_select, doc->getObjectByRepr(group));
+ items_to_select.push_back((SPItem*)(doc->getObjectByRepr(group)));
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<SPItem *>(i->data);
+ for (std::vector<SPItem*>::const_reverse_iterator i = apply_to_items.rbegin(); i != apply_to_items.rend(); i++) {
+ SPItem *item = reinterpret_cast<SPItem *>(*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->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<Inkscape::XML::Node *>(mask_item->data)->duplicate(xml_doc);
- mask_items_dup = g_slist_prepend(mask_items_dup, dup);
- }
-
- gchar const *mask_id = NULL;
- if (apply_clip_path) {
- mask_id = SPClipPath::create(mask_items_dup, doc, &maskTransform);
- } else {
- mask_id = sp_mask_create(mask_items_dup, doc, &maskTransform);
- }
-
- g_slist_free(mask_items_dup);
- mask_items_dup = NULL;
-
- Inkscape::XML::Node *current = SP_OBJECT(i->data)->getRepr();
+ std::vector<Inkscape::XML::Node*> mask_items_dup;
+ for(std::vector<Inkscape::XML::Node*>::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;
@@ -4058,7 +3954,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 = g_slist_remove(items_to_select, item);
current->parent()->appendChild(group);
sp_repr_unparent(current);
group->appendChild(spnew);
@@ -4067,29 +3962,31 @@ 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_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_dup, doc, &maskTransform);
+ } else {
+ mask_id = sp_mask_create(mask_items_dup, doc, &maskTransform);
+ }
+
apply_mask_to->setAttribute(attributeName, Glib::ustring("url(#") + mask_id + ')');
}
- 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<SPObject*>(i->data);
+ for (std::vector<SPItem*>::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); i++) {
+ SPObject *item = reinterpret_cast<SPObject*>(*i);
item->deleteObject(false);
- items_to_select = g_slist_remove(items_to_select, 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);
-
- items_to_select = g_slist_reverse(items_to_select);
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"));
@@ -4121,20 +4018,19 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) {
gchar const *attributeName = apply_clip_path ? "clip-path" : "mask";
std::map<SPObject*,SPItem*> referenced_objects;
- GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
+ std::vector<SPItem*> 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);
+ std::vector<SPItem*> 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 (GSList const *i = items; NULL != i; i = i->next) {
+ for (std::vector<SPItem*>::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<SPItem *>(i->data);
+ SPItem *item = *i;
Inkscape::URIReference *uri_ref = NULL;
if (apply_clip_path) {
@@ -4149,9 +4045,9 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) {
}
}
- SP_OBJECT(i->data)->getRepr()->setAttribute(attributeName, "none");
+ (*i)->getRepr()->setAttribute(attributeName, "none");
- SPGroup *group = dynamic_cast<SPGroup *>(static_cast<SPObject *>(i->data));
+ SPGroup *group = dynamic_cast<SPGroup *>(*i);
if (ungroup_masked && group) {
// if we had previously enclosed masked object in group,
// add it to list so we can ungroup it later
@@ -4163,7 +4059,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<SPObject*,SPItem*>::iterator it = referenced_objects.begin() ; it != referenced_objects.end() ; ++it) {
@@ -4171,7 +4066,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"));
@@ -4197,7 +4092,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<SPItem *>(desktop->getDocument()->getObjectByRepr(repr));
- items_to_select = g_slist_prepend(items_to_select, 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);
@@ -4212,10 +4107,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<SPGroup *>(static_cast<SPObject *>(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.erase(remove(items_to_select.begin(), items_to_select.end(), group), items_to_select.end());
+ std::vector<SPItem*> children;
+ sp_item_group_ungroup(group, children, false);
+ items_to_select.insert(items_to_select.end(),children.rbegin(),children.rend());
} else {
g_assert_not_reached();
}
@@ -4224,9 +4119,7 @@ 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);
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 4ee7a5200..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);
@@ -143,8 +143,9 @@ enum SPSelectStrokeStyleType {
void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolean strok, gboolean style);
void sp_select_same_object_type(SPDesktop *desktop);
-GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type=SP_STYLE_ALL);
-GSList *sp_get_same_object_type(SPItem *sel, GSList *src);
+
+std::vector<SPItem*> sp_get_same_style(SPItem *sel, std::vector<SPItem*> &src, SPSelectStrokeStyleType type=SP_STYLE_ALL);
+std::vector<SPItem*> sp_get_same_object_type(SPItem *sel, std::vector<SPItem*> &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);
+std::vector<SPItem*> &get_all_items(std::vector<SPItem*> &list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, std::vector<SPItem*> const &exclude);
-GSList *sp_degroup_list (GSList *items);
+std::vector<SPItem*> sp_degroup_list (std::vector<SPItem*> &items);
/* selection cycling */
typedef enum
diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp
index 2386a731e..8304db684 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 std::vector<SPItem*> &items)
{
GSList *check = NULL;
std::stringstream ss;
bool first = true;
- for (GSList *i = (GSList *)items; i != NULL; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>(i->data));
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *item = *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 std::vector<SPItem*> &items)
{
GSList *check = NULL;
int count=0;
- for (GSList *i = (GSList *)items; i != NULL; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>(i->data));
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *item = *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 std::vector<SPItem*> &items)
{
int count=0;
- for (GSList *i = items; i != NULL; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(reinterpret_cast<SPObject *>((i->data)));
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *item = *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();
+ std::vector<SPItem*> 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<SPItem *>(reinterpret_cast<SPObject *>(items->data));
+ SPItem *item = items[0];
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<SPUse *>(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(
"<b>%1$i</b> objects selected of type %2$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("; <i>%d filtered object</i> ",
"; <i>%d filtered objects</i> ", n_filt), n_filt);
diff --git a/src/selection.cpp b/src/selection.cpp
index 81139d044..7979b5d61 100644
--- a/src/selection.cpp
+++ b/src/selection.cpp
@@ -42,9 +42,11 @@
namespace Inkscape {
Selection::Selection(LayerModel *layers, SPDesktop *desktop) :
- _objs(NULL),
- _reprs(NULL),
- _items(NULL),
+ _objs(std::list<SPObject*>()),
+ _objs_vector(std::vector<SPObject*>()),
+ _objs_set(std::set<SPObject*>()),
+ _reprs(std::vector<XML::Node*>()),
+ _items(std::vector<SPItem*>()),
_layers(layers),
_desktop(desktop),
_selection_context(NULL),
@@ -121,17 +123,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<SPObject *>(_objs->data);
+ while (!_objs.empty()) {
+ SPObject *obj=_objs.front();
_remove(obj);
}
}
@@ -148,7 +147,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 ( _objs_set.find(obj)!=_objs_set.end() );
}
void Selection::add(SPObject *obj, bool persist_selection_context/* = false */) {
@@ -179,8 +178,10 @@ void Selection::_add(SPObject *obj) {
// (to prevent double-selection)
_removeObjectDescendants(obj);
_removeObjectAncestors(obj);
+ g_return_if_fail(SP_IS_OBJECT(obj));
- _objs = g_slist_prepend(_objs, obj);
+ _objs.push_front(obj);
+ _objs_set.insert(obj);
add_3D_boxes_recursively(obj);
@@ -234,26 +235,27 @@ void Selection::_remove(SPObject *obj) {
remove_3D_boxes_recursively(obj);
- _objs = g_slist_remove(_objs, obj);
+ _objs.remove(obj);
+ _objs_set.erase(obj);
}
-void Selection::setList(GSList const *list) {
+void Selection::setList(std::vector<SPItem*> 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(std::vector<SPItem*> const &list) {
- if (list == NULL)
+ if (list.empty())
return;
_invalidateCachedLists();
- for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) {
- SPObject *obj = reinterpret_cast<SPObject *>(iter->data);
+ for ( std::vector<SPItem*>::const_iterator iter=list.begin();iter!=list.end();iter++ ) {
+ SPObject *obj = *iter;
if (includes(obj)) continue;
_add (obj);
}
@@ -261,11 +263,11 @@ void Selection::addList(GSList const *list) {
_emitChanged();
}
-void Selection::setReprList(GSList const *list) {
+void Selection::setReprList(std::vector<XML::Node*> const &list) {
_clear();
- for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) {
- SPObject *obj=_objectForXMLNode(reinterpret_cast<Inkscape::XML::Node *>(iter->data));
+ for ( std::vector<XML::Node*>::const_reverse_iterator iter=list.rbegin();iter!=list.rend();iter++ ) {
+ SPObject *obj=_objectForXMLNode(*iter);
if (obj) {
_add(obj);
}
@@ -279,35 +281,38 @@ void Selection::clear() {
_emitChanged();
}
-GSList const *Selection::list() {
- return _objs;
+std::vector<SPObject*> const &Selection::list() {
+ if(!_objs_vector.empty())
+ return _objs_vector;
+
+ for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) {
+ _objs_vector.push_back(*iter);
+ }
+ return _objs_vector;
+
}
-GSList const *Selection::itemList() {
- if (_items) {
+std::vector<SPItem*> const &Selection::itemList() {
+ if (!_items.empty()) {
return _items;
}
- for ( GSList const *iter=_objs ; iter != NULL ; iter = iter->next ) {
- SPObject *obj=reinterpret_cast<SPObject *>(iter->data);
+ for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) {
+ SPObject *obj=*iter;
if (SP_IS_ITEM(obj)) {
- _items = g_slist_prepend(_items, SP_ITEM(obj));
+ _items.push_back(SP_ITEM(obj));
}
}
- _items = g_slist_reverse(_items);
-
return _items;
}
-GSList const *Selection::reprList() {
- if (_reprs) { return _reprs; }
-
- for ( GSList const *iter=itemList() ; iter != NULL ; iter = iter->next ) {
- SPObject *obj=reinterpret_cast<SPObject *>(iter->data);
- _reprs = g_slist_prepend(_reprs, obj->getRepr());
+std::vector<XML::Node*> const &Selection::reprList() {
+ if (!_reprs.empty()) { return _reprs; }
+ std::vector<SPItem*> list = itemList();
+ for ( std::vector<SPItem*>::const_iterator iter=list.begin();iter!=list.end();iter++ ) {
+ SPObject *obj = *iter;
+ _reprs.push_back(obj->getRepr());
}
- _reprs = g_slist_reverse(_reprs);
-
return _reprs;
}
@@ -337,17 +342,17 @@ std::list<SPBox3D *> const Selection::box3DList(Persp3D *persp) {
}
SPObject *Selection::single() {
- if ( _objs != NULL && _objs->next == NULL ) {
- return reinterpret_cast<SPObject *>(_objs->data);
+ if ( _objs.size() == 1 ) {
+ return _objs.front();
} else {
return NULL;
}
}
SPItem *Selection::singleItem() {
- GSList const *items=itemList();
- if ( items != NULL && items->next == NULL ) {
- return reinterpret_cast<SPItem *>(items->data);
+ std::vector<SPItem*> const items=itemList();
+ if ( items.size()==1) {
+ return items[0];
} else {
return NULL;
}
@@ -362,12 +367,12 @@ SPItem *Selection::largestItem(Selection::CompareSize compare) {
}
SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) {
- GSList const *items = const_cast<Selection *>(this)->itemList();
+ std::vector<SPItem*> const items = const_cast<Selection *>(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 ( std::vector<SPItem*>::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 +381,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 +400,22 @@ Geom::OptRect Selection::bounds(SPItem::BBoxType type) const
Geom::OptRect Selection::geometricBounds() const
{
- GSList const *items = const_cast<Selection *>(this)->itemList();
+ std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList();
Geom::OptRect bbox;
- for ( GSList const *i = items ; i != NULL ; i = i->next ) {
- bbox.unionWith(SP_ITEM(i->data)->desktopGeometricBounds());
+ for ( std::vector<SPItem*>::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<Selection *>(this)->itemList();
+ std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList();
Geom::OptRect bbox;
- for ( GSList const *i = items ; i != NULL ; i = i->next ) {
- bbox.unionWith(SP_ITEM(i->data)->desktopVisualBounds());
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ bbox.unionWith(SP_ITEM(*iter)->desktopVisualBounds());
}
return bbox;
}
@@ -427,11 +432,11 @@ Geom::OptRect Selection::preferredBounds() const
Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const
{
Geom::OptRect bbox;
- GSList const *items = const_cast<Selection *>(this)->itemList();
- if (!items) return bbox;
+ std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList();
+ if (items.empty()) return bbox;
- for ( GSList const *iter=items ; iter != NULL ; iter = iter->next ) {
- SPItem *item = SP_ITEM(iter->data);
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *item = SP_ITEM(*iter);
bbox |= item->documentBounds(type);
}
@@ -441,9 +446,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<Geom::Point> Selection::center() const {
- GSList *items = (GSList *) const_cast<Selection *>(this)->itemList();
- if (items) {
- SPItem *first = reinterpret_cast<SPItem*>(g_slist_last(items)->data); // from the first item in selection
+ std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList();
+ if (!items.empty()) {
+ SPItem *first = items.back(); // from the first item in selection
if (first->isCenterSet()) { // only if set explicitly
return first->getCenter();
}
@@ -457,13 +462,13 @@ boost::optional<Geom::Point> Selection::center() const {
}
std::vector<Inkscape::SnapCandidatePoint> Selection::getSnapPoints(SnapPreferences const *snapprefs) const {
- GSList const *items = const_cast<Selection *>(this)->itemList();
+ std::vector<SPItem*> const items = const_cast<Selection *>(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<Inkscape::SnapCandidatePoint> p;
- for (GSList const *iter = items; iter != NULL; iter = iter->next) {
- SPItem *this_item = SP_ITEM(iter->data);
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *this_item = *iter;
this_item->getSnappoints(p, &snapprefs_dummy);
//Include the transformation origin for snapping
@@ -477,19 +482,21 @@ std::vector<Inkscape::SnapCandidatePoint> 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<SPObject *>(iter->data);
+ std::vector<SPObject*> toremove;
+ for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) {
+ SPObject *sel_obj= dynamic_cast<SPObject*>(*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<SPObject*>::const_iterator iter=toremove.begin();iter!=toremove.end();iter++ ) {
+ _remove(*iter);
+ }
}
void Selection::_removeObjectAncestors(SPObject *obj) {
@@ -511,32 +518,24 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const {
return object;
}
-guint Selection::numberOfLayers() {
- GSList const *items = const_cast<Selection *>(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);
- }
+size_t Selection::numberOfLayers() {
+ std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList();
+ std::set<SPObject*> layers;
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPObject *layer = _layers->layerForObject(*iter);
+ layers.insert(layer);
}
- guint ret = g_slist_length (layers);
- g_slist_free (layers);
- return ret;
-}
-
-guint Selection::numberOfParents() {
- GSList const *items = const_cast<Selection *>(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);
- }
+ return layers.size();
+}
+
+size_t Selection::numberOfParents() {
+ std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList();
+ std::set<SPObject*> parents;
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPObject *parent = (*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 19e2ae1fd..952dde51d 100644
--- a/src/selection.h
+++ b/src/selection.h
@@ -16,6 +16,7 @@
#include <vector>
#include <map>
#include <list>
+#include <set>
#include <stddef.h>
#include <sigc++/sigc++.h>
@@ -26,11 +27,11 @@
#include "sp-item.h"
+
class SPDesktop;
class SPItem;
class SPBox3D;
class Persp3D;
-typedef struct _GSList GSList;
namespace Inkscape {
class LayerModel;
@@ -39,6 +40,7 @@ class Node;
}
}
+
namespace Inkscape {
/**
@@ -154,21 +156,21 @@ public:
*
* @param objs the objects to select
*/
- void setList(GSList const *objs);
+ void setList(std::vector<SPItem*> const &objs);
/**
* Adds the specified objects to selection, without deselecting first.
*
* @param objs the objects to select
*/
- void addList(GSList const *objs);
+ void addList(std::vector<SPItem*> 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::vector<XML::Node*> const &reprs);
/** Add items from an STL iterator range to the selection.
* \param from the begin iterator
@@ -192,7 +194,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 +240,13 @@ public:
XML::Node *singleRepr();
/** Returns the list of selected objects. */
- GSList const *list();
+ std::vector<SPObject*> const &list();
/** Returns the list of selected SPItems. */
- GSList const *itemList();
+ std::vector<SPItem*> 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::vector<XML::Node*> const &reprList();
/** Returns a list of all perspectives which have a 3D box in the current selection.
(these may also be nested in groups) */
@@ -257,10 +259,10 @@ public:
std::list<SPBox3D *> 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;
@@ -360,9 +362,11 @@ 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<SPObject*> _objs; //to more efficiently remove arbitrary elements
+ mutable std::vector<SPObject*> _objs_vector; // to be returned by list();
+ mutable std::set<SPObject*> _objs_set; //to efficiently test if object is selected
+ mutable std::vector<XML::Node*> _reprs;
+ mutable std::vector<SPItem*> _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..f7562923f 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(std::vector<SPItem*>()),
_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);
+ std::vector<SPItem*> items=_desktop->selection->itemList();
+ for ( std::vector<SPItem*>::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<SPItem*>(sp_object_ref(SP_ITEM(l->data), NULL));
+ std::vector<SPItem*> items=_desktop->selection->itemList();
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *it = static_cast<SPItem*>(sp_object_ref(*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)
@@ -432,10 +434,8 @@ void Inkscape::SelTrans::ungrab()
for (int i = 0; i < 4; i++)
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 +491,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);
+ std::vector<SPItem*> items=_desktop->selection->itemList();
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *it = *iter;
it->updateRepr();
}
DocumentUndo::done(_desktop->getDocument(), SP_VERB_CONTEXT_SELECT,
@@ -515,26 +516,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) {
+ std::vector<SPItem*> 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();
+ sort(l.begin(),l.end(),sp_object_compare_position_bool);
_stamp_cache = l;
}
- while (l) {
- SPItem *original_item = SP_ITEM(l->data);
+ for(std::vector<SPItem*>::const_iterator x=l.begin();x!=l.end();x++) {
+ SPItem *original_item = *x;
Inkscape::XML::Node *original_repr = original_item->getRepr();
// remember the position of the item
@@ -568,16 +568,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 +710,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);
+ std::vector<SPItem*> items=_desktop->selection->itemList();
+ for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) {
+ SPItem *it = *iter;
it->unsetCenter();
it->updateRepr();
_center_is_set = false; // center has changed
@@ -1283,7 +1282,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 *>(_selection)->itemList();
+ std::vector<SPItem*> items = const_cast<Selection *>(_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..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;
- GSList *_stamp_cache;
+ std::vector<SPItem*> _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 96b5ab53c..30441ca0b 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(std::vector<SPItem*>()),
_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<GSList*>(items); i; i = i->next) {
- _items_to_ignore.push_back(static_cast<SPItem const *>(i->data));
+ std::vector<SPItem*> const items = sel->itemList();
+ for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) {
+ _items_to_ignore.push_back(*i);
}
}
diff --git a/src/snap.h b/src/snap.h
index 20b2b246f..49bdbfa7c 100644
--- a/src/snap.h
+++ b/src/snap.h
@@ -136,7 +136,7 @@ public:
std::vector<Inkscape::SnapCandidatePoint> *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 std::vector<SPItem*> &items) {_rotation_center_source_items = items;}
+ const std::vector<SPItem*> &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<SPItem const *> _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
+ std::vector<SPItem*> _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-clippath.cpp b/src/sp-clippath.cpp
index 3c6167438..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 <defs>
-const gchar *SPClipPath::create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform)
+const gchar *SPClipPath::create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform)
{
Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr();
@@ -308,13 +308,12 @@ 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<Inkscape::XML::Node*>::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) {
- Geom::Affine transform (item->transform);
- transform *= (*applyTransform);
+ Geom::Affine transform (item->transform * (*applyTransform));
item->doWriteTransform(item->getRepr(), transform);
}
}
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<Inkscape::XML::Node*> &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-conn-end.cpp b/src/sp-conn-end.cpp
index 3e5398ced..1e478d1c9 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);
+ std::vector<SPItem*> g = sp_item_group_item_list(group);
+ for (std::vector<SPItem*>::const_iterator i = g.begin();i!=g.end();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 8dd695867..2e341d3c6 100644
--- a/src/sp-defs.cpp
+++ b/src/sp-defs.cpp
@@ -36,11 +36,9 @@ 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);
+ std::vector<SPObject*> l(this->childList(true));
+ for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();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 a70fbd5bb..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.
*/
@@ -235,11 +245,9 @@ 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);
+ std::vector<SPObject*> l(this->childList(true, SPObject::ActionUpdate));
+ for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *child = *i;
if( SP_IS_FILTER_PRIMITIVE( child ) ) {
child->updateDisplay(ctx, childflags);
}
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/sp-item-group.cpp b/src/sp-item-group.cpp
index 55857dacf..72cd5d7fa 100644
--- a/src/sp-item-group.cpp
+++ b/src/sp-item-group.cpp
@@ -161,11 +161,9 @@ 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);
+ std::vector<SPObject*> l=this->childList(true, SPObject::ActionUpdate);
+ for(std::vector<SPObject*> ::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *child = *i;
if (childflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
SPItem *item = dynamic_cast<SPItem *>(child);
@@ -201,20 +199,15 @@ 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);
+ std::vector<SPObject*> l=this->childList(true);
+ for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *child = *i;
if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
child->emitModified(flags);
@@ -286,35 +279,27 @@ 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<SPGroup*>(this)->childList(false, SPObject::ActionBBox);
-
- while (l) {
- SPObject *o = SP_OBJECT (l->data);
-
+ std::vector<SPObject*> l = const_cast<SPGroup*>(this)->childList(false, SPObject::ActionBBox);
+ for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *o = *i;
SPItem *item = dynamic_cast<SPItem *>(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);
-
+ std::vector<SPObject*> l=this->childList(false);
+ for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *o = *i;
SPItem *item = dynamic_cast<SPItem *>(o);
if (item) {
item->invoke_print(ctx);
}
-
- l = g_slist_remove (l, o);
}
}
@@ -362,17 +347,14 @@ 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);
+ std::vector<SPObject*> l=this->childList(false, SPObject::ActionShow);
+ for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *o = *i;
SPItem *item = dynamic_cast<SPItem *>(o);
if (item) {
item->invoke_hide(key);
}
-
- l = g_slist_remove (l, o);
}
// SPLPEItem::onHide(key);
@@ -393,7 +375,7 @@ void sp_item_group_ungroup_handle_clones(SPItem *parent, Geom::Affine const g)
{
for(std::list<SPObject*>::const_iterator refd=parent->hrefList.begin();refd!=parent->hrefList.end();refd++){
SPItem *citem = dynamic_cast<SPItem *>(*refd);
- if (citem) {
+ if (citem && !citem->cloned) {
SPUse *useitem = dynamic_cast<SPUse *>(citem);
if (useitem && useitem->get_original() == parent) {
Geom::Affine ctrans;
@@ -407,7 +389,7 @@ void sp_item_group_ungroup_handle_clones(SPItem *parent, Geom::Affine const g)
}
void
-sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
+sp_item_group_ungroup (SPGroup *group, std::vector<SPItem*> &children, bool do_done)
{
g_return_if_fail (group != NULL);
@@ -559,15 +541,12 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
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 && item) {
- *children = g_slist_prepend(*children, item);
- }
-
items = g_slist_remove (items, items->data);
}
@@ -580,19 +559,17 @@ 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)
+std::vector<SPItem*> sp_item_group_item_list(SPGroup * group)
{
- g_return_val_if_fail(group != NULL, NULL);
-
- GSList *s = NULL;
+ std::vector<SPItem*> s;
+ g_return_val_if_fail(group != NULL, s);
for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) {
if ( dynamic_cast<SPItem *>(o) ) {
- s = g_slist_prepend(s, o);
+ s.push_back((SPItem*)o);
}
}
-
- return g_slist_reverse (s);
+ return s;
}
SPObject *sp_item_group_get_child_by_name(SPGroup *group, SPObject *ref, const gchar *name)
@@ -807,9 +784,9 @@ 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);
+ std::vector<SPObject*> l=this->childList(false, SPObject::ActionShow);
+ for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){
+ SPObject *o = *i;
SPItem * child = dynamic_cast<SPItem *>(o);
if (child) {
ac = child->invoke_show (drawing, key, flags);
@@ -817,7 +794,6 @@ void SPGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *
ai->appendChild(ac);
}
}
- l = g_slist_remove (l, o);
}
}
@@ -826,10 +802,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);
+ std::vector<SPItem*> const item_list = sp_item_group_item_list(this);
- for ( GSList const *iter = item_list; iter; iter = iter->next ) {
- SPObject *subitem = static_cast<SPObject *>(iter->data);
+ for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = *iter;
SPLPEItem *lpeItem = dynamic_cast<SPLPEItem *>(subitem);
if (lpeItem) {
@@ -854,10 +830,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);
+ std::vector<SPItem*> const item_list = sp_item_group_item_list(group);
- for ( GSList const *iter = item_list; iter; iter = iter->next ) {
- SPObject *subitem = static_cast<SPObject *>(iter->data);
+ for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = *iter;
SPGroup *subGroup = dynamic_cast<SPGroup *>(subitem);
if (subGroup) {
diff --git a/src/sp-item-group.h b/src/sp-item-group.h
index f9a8b88f5..fc0b6382f 100644
--- a/src/sp-item-group.h
+++ b/src/sp-item-group.h
@@ -95,6 +95,7 @@ public:
virtual void update_patheffect(bool write);
};
+
/**
* finds clones of a child of the group going out of the group; and inverse the group transform on its clones
* Also called when moving objects between different layers
@@ -104,10 +105,11 @@ public:
*/
void sp_item_group_ungroup_handle_clones(SPItem *parent, Geom::Affine const g);
-void sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done = true);
+void sp_item_group_ungroup (SPGroup *group, std::vector<SPItem*> &children, bool do_done = true);
+
+std::vector<SPItem*> sp_item_group_item_list (SPGroup *group);
-GSList *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-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/sp-lpe-item.cpp b/src/sp-lpe-item.cpp
index 12d85b3ed..9befd2a2b 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<SPObject *>(iter->data);
+ std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
+ for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = *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<SPObject *>(iter->data);
+ std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
+ for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = *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<SPObject *>(iter->data);
+ std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(item));
+ for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = *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<SPObject *>(iter->data);
+ std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(item));
+ for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) {
+ SPObject *subitem = *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<SPObject *>(iter->data);
+ std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(group));
+ for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();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/sp-marker.cpp b/src/sp-marker.cpp
index d3cf50fa7..9334614dc 100644
--- a/src/sp-marker.cpp
+++ b/src/sp-marker.cpp
@@ -419,7 +419,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(std::vector<Inkscape::XML::Node*> &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();
@@ -442,8 +442,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 (std::vector<Inkscape::XML::Node*>::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 e804fd7dc..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 (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Point center, Geom::Affine move);
+const char *generate_marker (std::vector<Inkscape::XML::Node*> &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-mask.cpp b/src/sp-mask.cpp
index d60473e1d..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 <defs>
const gchar *
-sp_mask_create (GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform)
+sp_mask_create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform)
{
Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr();
@@ -221,13 +221,12 @@ 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<Inkscape::XML::Node*>::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) {
- Geom::Affine transform (item->transform);
- transform *= (*applyTransform);
+ Geom::Affine transform (item->transform * (*applyTransform));
item->doWriteTransform(item->getRepr(), transform);
}
}
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<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform);
#endif // SEEN_SP_MASK_H
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:
diff --git a/src/sp-object.cpp b/src/sp-object.cpp
index 343db435e..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 ) {
@@ -380,14 +384,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;
+std::vector<SPObject*> SPObject::childList(bool add_ref, Action) {
+ std::vector<SPObject*> l;
for ( SPObject *child = firstChild() ; child; child = child->getNext() ) {
if (add_ref) {
sp_object_ref (child);
}
- l = g_slist_prepend (l, child);
+ l.push_back(child);
}
return l;
diff --git a/src/sp-object.h b/src/sp-object.h
index ab0b444b6..7bc02fad5 100644
--- a/src/sp-object.h
+++ b/src/sp-object.h
@@ -52,6 +52,7 @@ class SPObject;
#include <sigc++/connection.h>
#include <sigc++/functors/slot.h>
#include <sigc++/signal.h>
+#include <vector>
#include "version.h"
#include "util/forward-pointer-iterator.h"
@@ -328,10 +329,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.
*/
- GSList *childList(bool add_ref, Action action = ActionGeneral);
+ std::vector<SPObject*> childList(bool add_ref, Action action = ActionGeneral);
/**
* Append repr as child of this object.
@@ -875,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/sp-pattern.cpp b/src/sp-pattern.cpp
index 987a86fe4..e89ed77ba 100644
--- a/src/sp-pattern.cpp
+++ b/src/sp-pattern.cpp
@@ -398,7 +398,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 std::vector<Inkscape::XML::Node*> &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();
@@ -416,8 +416,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 (std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();i++){
+ Inkscape::XML::Node *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..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 (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move);
+const char *pattern_tile (const std::vector<Inkscape::XML::Node*> &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 66cec3637..cfc0e7d8b 100644
--- a/src/sp-switch.cpp
+++ b/src/sp-switch.cpp
@@ -41,21 +41,22 @@ SPObject *SPSwitch::_evaluateFirst() {
return first;
}
-GSList *SPSwitch::_childList(bool add_ref, SPObject::Action action) {
+std::vector<SPObject*> SPSwitch::_childList(bool add_ref, SPObject::Action action) {
if ( action != SPObject::ActionGeneral ) {
return this->childList(add_ref, action);
}
SPObject *child = _evaluateFirst();
+ std::vector<SPObject*> 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_back(child);
+ return x;
}
const char *SPSwitch::displayName() const {
@@ -95,10 +96,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);
+ std::vector<SPObject*> item_list = _childList(false, SPObject::ActionShow);
+ for ( std::vector<SPObject*>::const_reverse_iterator iter=item_list.rbegin();iter!=item_list.rend();iter++) {
+ SPObject *o = *iter;
if ( !SP_IS_ITEM (o) ) {
continue;
}
@@ -130,10 +130,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);
+ std::vector<SPObject*> l = this->_childList(false, SPObject::ActionShow);
- while (l) {
- SPObject *o = SP_OBJECT (l->data);
+ for ( std::vector<SPObject*>::const_reverse_iterator iter=l.rbegin();iter!=l.rend();iter++) {
+ SPObject *o = *iter;
if (SP_IS_ITEM (o)) {
SPItem * child = SP_ITEM(o);
@@ -144,8 +144,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..7152e1b82 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);
+ std::vector<SPObject*> _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/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<SPString *>(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<SVGLength> *output_list, std::vector<SVGLength> const &parent_list, unsigned parent_offset, std::vector<SVGLength> const *overlay_list)
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);
diff --git a/src/splivarot.cpp b/src/splivarot.cpp
index 46279cbce..bec300936 100644
--- a/src/splivarot.cpp
+++ b/src/splivarot.cpp
@@ -326,21 +326,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();
+ std::vector<SPItem*> 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 <b>at least 2 paths</b> to perform a boolean operation."));
return;
}
- else if ( g_slist_length(il) < 1 ) {
+ else if ( il.size() < 1 ) {
boolop_display_error_message(desktop, _("Select <b>at least 1 path</b> 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 <b>exactly 2 paths</b> to perform difference, division, or path cut."));
return;
@@ -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->data)->getRepr();
- Inkscape::XML::Node *b = SP_OBJECT(il->next->data)->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 <b>z-order</b> of the objects selected for difference, XOR, division, or path cut."));
@@ -394,38 +394,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 (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++)
{
- SPItem *item = SP_ITEM(l->data);
+ 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 <b>not a path</b>, 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<Path *> originaux(nbOriginaux);
std::vector<FillRule> origWind(nbOriginaux);
int curOrig;
{
curOrig = 0;
- for (GSList *l = il; l != NULL; l = l->next)
+ for (std::vector<SPItem*>::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<SPObject *>(il->data)->getRepr(), "style");
+ SPCSSAttr *css = sp_repr_css_attr(reinterpret_cast<SPObject *>(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;
@@ -435,11 +433,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(*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 +469,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 (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){
+ if(*l==il[0])continue;
originaux[curOrig]->ConvertWithBackData(0.1);
originaux[curOrig]->Fill(theShape, curOrig);
@@ -668,15 +666,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 (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){
+ (*l)->deleteObject();
}
DocumentUndo::done(doc, SP_VERB_NONE, description);
selection->clear();
delete res;
- g_slist_free(il);
return;
}
@@ -684,19 +680,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 = il[0];
} else {
- source = SP_OBJECT(il->next->data);
+ source = 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);
+ std::vector<Inkscape::XML::Node*> sorted(selection->reprList());
- source = doc->getObjectByRepr((Inkscape::XML::Node *)sorted->data);
+ sort(sorted.begin(),sorted.end(),sp_repr_compare_position_bool);
- g_slist_free(sorted);
+ source = doc->getObjectByRepr(sorted.front());
}
// adjust style properties that depend on a possible transform in the source object in order
@@ -721,17 +715,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 (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){
// if this is the bottommost object,
- if (!strcmp(reinterpret_cast<SPObject *>(l->data)->getRepr()->attribute("id"), id)) {
+ if (!strcmp(reinterpret_cast<SPObject *>(*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);
+ (*l)->deleteObject(false);
} else {
// delete the object for real, so that its clones can take appropriate action
- SP_OBJECT(l->data)->deleteObject();
+ (*l)->deleteObject();
}
}
- g_slist_free(il);
// premultiply by the inverse of parent's repr
SPItem *parent_item = SP_ITEM(doc->getObjectByRepr(parent));
@@ -1159,12 +1152,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);
+ std::vector<SPItem*> il(selection->itemList());
+ for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){
+ SPItem *item = *l;
if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
continue;
@@ -1776,12 +1766,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);
+ std::vector<SPItem*> il(selection->itemList());
+ for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){
+ SPItem *item = *l;
SPCurve *curve = NULL;
if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
@@ -1977,7 +1964,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, std::vector<SPItem*> &items,
float threshold, bool justCoalesce,
float angleLimit, bool breakableAngles,
bool modifySelection);
@@ -1996,7 +1983,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));
+ std::vector<SPItem*> items = sp_item_group_item_list(SP_GROUP(item));
return sp_selected_path_simplify_items(desktop, selection, items,
threshold, justCoalesce,
@@ -2121,7 +2108,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop,
bool
sp_selected_path_simplify_items(SPDesktop *desktop,
- Inkscape::Selection *selection, GSList *items,
+ Inkscape::Selection *selection, std::vector<SPItem*> &items,
float threshold, bool justCoalesce,
float angleLimit, bool breakableAngles,
bool modifySelection)
@@ -2147,13 +2134,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 (std::vector<SPItem*>::const_iterator l = items.begin(); l != items.end(); l++){
+ SPItem *item = *l;
if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item)))
continue;
@@ -2201,7 +2188,7 @@ sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool ju
return;
}
- GSList *items = g_slist_copy((GSList *) selection->itemList());
+ std::vector<SPItem*> items(selection->itemList());
bool didSomething = sp_selected_path_simplify_items(desktop, selection,
items, threshold,
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..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<SPIBasePtr>(&SPStyle::font ) ) );
// _propmap.insert( std::make_pair( font_specification.name, reinterpret_cast<SPIBasePtr>(&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<SPIBasePtr>(&SPStyle::text_indent ) ) );
// _propmap.insert( std::make_pair( text_align.name, reinterpret_cast<SPIBasePtr>(&SPStyle::text_align ) ) );
@@ -573,7 +599,15 @@ SPStyle::read( SPObject *object, Inkscape::XML::Node *repr ) {
/* 3 Presentation attributes */
// std::cout << " MERGING PRESENTATION ATTRIBUTES" << std::endl;
for(std::vector<SPIBase*>::size_type i = 0; i != _properties.size(); ++i) {
- _properties[i]->readAttribute( repr );
+
+ // 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 ) {
+ _properties[i]->readAttribute( repr );
+ }
}
// for(SPPropMap::iterator i = _propmap.begin(); i != _propmap.end(); ++i ) {
// (this->*(i->second)).readAttribute( repr );
@@ -686,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 );
@@ -1169,10 +1226,12 @@ void
sp_style_filter_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style)
{
if (old_ref) {
+ (dynamic_cast<SPFilter *>( old_ref ))->_refcount--;
style->filter_modified_connection.disconnect();
}
if ( SP_IS_FILTER(ref))
{
+ (dynamic_cast<SPFilter *>( ref ))->_refcount++;
style->filter_modified_connection =
ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_filter_ref_modified), style));
}
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) */
diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp
index 65b59f2ad..9fc862ad2 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);
+ std::vector<SPItem*> items = selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ if (SP_IS_FLOWTEXT(*i))
+ return *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);
+ std::vector<SPItem*> items = selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i))
+ return *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);
+ std::vector<SPItem*> items = selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ if (SP_IS_SHAPE(*i))
+ return *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 <b>a text and a path</b> 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);
+ std::vector<SPItem*> items(selection->itemList());
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPObject *obj = *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);
+ std::vector<SPItem*> items = selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPObject *obj = *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 <b>a text</b> and one or more <b>paths or shapes</b> 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);
+ std::vector<SPItem*> items = selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *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 <b>a flowed text</b> to unflow it."));
return;
}
- GSList *new_objs = NULL;
+ std::vector<SPItem*> new_objs;
GSList *old_objs = NULL;
- for (GSList *items = g_slist_copy((GSList *) selection->itemList());
- items != NULL;
- items = items->next) {
+ std::vector<SPItem*> items = selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
- if (!SP_IS_FLOWTEXT(SP_OBJECT(items->data))) {
+ if (!SP_IS_FLOWTEXT(*i)) {
continue;
}
- SPItem *flowtext = SP_ITEM(items->data);
+ SPItem *flowtext = *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_back((SPItem*)text_object);
old_objs = g_slist_prepend (old_objs, flowtext);
Inkscape::GC::release(rtext);
@@ -460,13 +452,13 @@ 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);
}
g_slist_free (old_objs);
- g_slist_free (new_objs);
DocumentUndo::done(doc, SP_VERB_CONTEXT_TEXT,
_("Unflow flowed text"));
@@ -487,11 +479,11 @@ flowtext_to_text()
bool did = false;
- GSList *reprs = NULL;
- GSList *items = g_slist_copy((GSList *) selection->itemList());
- for (; items != NULL; items = items->next) {
+ std::vector<Inkscape::XML::Node*> reprs;
+ std::vector<SPItem*> items(selection->itemList());
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
- SPItem *item = (SPItem *) items->data;
+ SPItem *item = *i;
if (!SP_IS_FLOWTEXT(item))
continue;
@@ -519,10 +511,9 @@ flowtext_to_text()
Inkscape::GC::release(repr);
item->deleteObject();
- reprs = g_slist_prepend(reprs, repr);
+ reprs.push_back(repr);
}
- g_slist_free(items);
if (did) {
DocumentUndo::done(desktop->getDocument(),
@@ -535,7 +526,6 @@ flowtext_to_text()
_("<b>No flowed text(s)</b> to convert in the selection."));
}
- g_slist_free(reprs);
}
diff --git a/src/text-editing.cpp b/src/text-editing.cpp
index 4a962ab4c..050e223eb 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<SPItem*>(elem->data);
+ std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(item));
+ for(std::vector<SPItem*>::const_iterator i=item_list.begin();i!=item_list.end();i++){
+ SPItem* list_item = *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/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/trace/trace.cpp b/src/trace/trace.cpp
index cc3d000a3..91c230920 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();
+ std::vector<SPItem*> const list = sel->itemList();
std::vector<SPItem *> 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 (std::vector<SPItem*>::const_iterator i=list.begin() ; list.end()!=i ; i++)
{
- if (!SP_IS_ITEM(list->data))
+ if (!SP_IS_ITEM(*i))
{
continue;
}
- SPItem *item = SP_ITEM(list->data);
+ SPItem *item = *i;
items.insert(items.begin(), item);
}
std::vector<SPItem *>::iterator iter;
diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp
index f1d0ff576..d6cf1f980 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<GSList*>(selection->itemList()) ; i ; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<GSList *>(selection->itemList()) ; itemptr ; itemptr = itemptr->next) {
- SPItem *item = reinterpret_cast<SPItem*>(itemptr->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<GSList *>(items) ; i != NULL ; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<GSList *>(items));
- sorted_items = g_slist_sort(sorted_items, (GCompareFunc) sp_object_compare_position);
+ std::vector<SPItem*> sorted_items(itemlist);
+ sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool);
- for (GSList *i = sorted_items ; i ; i = i->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ for(std::vector<SPItem*>::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){
+ SPItem *item = *i;
if (item) {
Inkscape::XML::Node *obj = item->getRepr();
Inkscape::XML::Node *obj_copy = _copyNode(obj, _doc, _root);
@@ -703,8 +705,8 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection)
}
// copy style for Paste Style action
- if (sorted_items) {
- SPObject *object = static_cast<SPObject *>(sorted_items->data);
+ if (!sorted_items.empty()) {
+ SPObject *object = sorted_items[0];
SPItem *item = dynamic_cast<SPItem *>(object);
if (item) {
SPCSSAttr *style = take_style_from_item(item);
@@ -727,7 +729,6 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection)
sp_repr_set_point(_clipnode, "max", size->max());
}
- g_slist_free(sorted_items);
}
@@ -1164,8 +1165,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);
+ std::vector<SPItem*> x;
+ sp_export_png_file(_clipboardSPDoc, filename, area, width, height, dpi, dpi, bgcolor, NULL, NULL, true, x);
}
else
{
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/entry.h>
#include <gtkmm/window.h>
#include <gdk/gdkkeysyms.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
namespace Inkscape {
diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp
index 65bc94011..882427912 100644
--- a/src/ui/dialog/align-and-distribute.cpp
+++ b/src/ui/dialog/align-and-distribute.cpp
@@ -97,9 +97,7 @@ 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::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ std::vector<SPItem*> selected(selection->itemList());
if (selected.empty()) return;
const Coeffs &a = _allCoeffs[index];
@@ -149,18 +147,19 @@ void ActionAlign::do_action(SPDesktop *desktop, int index)
b = selection->preferredBounds();
//Move each item in the selected list separately
- for (std::list<SPItem *>::iterator it(selected.begin());
+ for (std::vector<SPItem*>::iterator it(selected.begin());
it != selected.end(); ++it)
{
+ SPItem* item= *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;
}
}
@@ -250,26 +249,24 @@ private :
Inkscape::Selection *selection = desktop->getSelection();
if (!selection) return;
- using Inkscape::Util::GSListConstIterator;
- std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ std::vector<SPItem*> selected(selection->itemList());
if (selected.empty()) return;
//Check 2 or more selected objects
- std::list<SPItem *>::iterator second(selected.begin());
+ std::vector<SPItem*>::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<SPItem *>::iterator it(selected.begin());
+ for (std::vector<SPItem*>::iterator it(selected.begin());
it != selected.end();
- ++it)
- {
- Geom::OptRect bbox = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds();
+ ++it){
+ SPItem *item = *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
@@ -549,9 +546,7 @@ private :
Inkscape::Selection *selection = desktop->getSelection();
if (!selection) return;
- using Inkscape::Util::GSListConstIterator;
- std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ std::vector<SPItem*> selected(selection->itemList());
if (selected.empty()) return;
//Check 2 or more selected objects
@@ -569,15 +564,17 @@ private :
} else { // sorting by ZOrder is outomatically done by not setting the center
center.reset();
}
- selected.sort(ActionExchangePositions::sort_compare);
+ sort(selected.begin(),selected.end(),sort_compare);
}
- std::list<SPItem *>::iterator it(selected.begin());
- Geom::Point p1 = (*it)->getCenter();
+ std::vector<SPItem*>::iterator it(selected.begin());
+ SPItem* item = *it;
+ Geom::Point p1 = item->getCenter();
for (++it ;it != selected.end(); ++it)
{
- Geom::Point p2 = (*it)->getCenter();
+ item = *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();
@@ -615,8 +612,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());
+ std::vector<SPItem*> x(_dialog.getDesktop()->getSelection()->itemList());
+ unclump (x);
// restore compensation setting
prefs->setInt("/options/clonecompensation/value", saved_compensation);
@@ -646,9 +643,7 @@ private :
Inkscape::Selection *selection = desktop->getSelection();
if (!selection) return;
- using Inkscape::Util::GSListConstIterator;
- std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ std::vector<SPItem*> selected(selection->itemList());
if (selected.empty()) return;
//Check 2 or more selected objects
@@ -672,12 +667,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<SPItem *>::iterator it(selected.begin());
+ for (std::vector<SPItem*>::iterator it(selected.begin());
it != selected.end();
++it)
{
+ SPItem* item = *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 +682,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));
}
}
@@ -745,9 +741,7 @@ private :
Inkscape::Selection *selection = desktop->getSelection();
if (!selection) return;
- using Inkscape::Util::GSListConstIterator;
- std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ std::vector<SPItem*> selected(selection->itemList());
if (selected.empty()) return;
//Check 2 or more selected objects
@@ -758,20 +752,21 @@ private :
std::vector<Baselines> sorted;
- for (std::list<SPItem *>::iterator it(selected.begin());
+ for (std::vector<SPItem*>::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 = *it;
+ if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT (item)) {
+ Inkscape::Text::Layout const *layout = te_get_layout(item);
boost::optional<Geom::Point> 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 +796,19 @@ private :
}
} else {
- for (std::list<SPItem *>::iterator it(selected.begin());
+ for (std::vector<SPItem*>::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 = *it;
+ if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT (item)) {
+ Inkscape::Text::Layout const *layout = te_get_layout(item);
boost::optional<Geom::Point> 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/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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#include <gtkmm/entry.h>
#include <gtkmm/label.h>
diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp
index bd3ad0254..f84a2ffd6 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), _("<small>More than one object selected.</small>"));
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 <b>one object</b> whose tiled clones to unclump."));
return;
}
@@ -2104,20 +2104,18 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *)
SPObject *obj = selection->singleItem();
SPObject *parent = obj->parent;
- GSList *to_unclump = NULL; // not including the original
+ std::vector<SPItem*> 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_back((SPItem*)child);
}
}
desktop->getDocument()->ensureUpToDate();
-
+ reverse(to_unclump.begin(),to_unclump.end());
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 <b>one object</b> 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, <b>group</b> them and <b>clone the group</b>."));
return;
}
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 <errno.h>
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/label.h>
#include <glibmm/i18n.h>
#include <cairo.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/dialog.h>
#include <gtkmm/textview.h>
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/export.cpp b/src/ui/dialog/export.cpp
index 6d90c792e..384aec415 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 <png.h>
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/buttonbox.h>
#include <gtkmm/dialog.h>
@@ -605,7 +601,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 +813,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 std::vector<XML::Node*> reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList();
+ for(std::vector<XML::Node*>::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) {
+ Inkscape::XML::Node * repr = *i;
if (repr->attribute("id")) {
id = repr->attribute("id");
break;
@@ -1010,7 +1006,7 @@ void Export::onExport ()
if (batch_export.get_active ()) {
// Batch export of selected objects
- gint num = g_slist_length(const_cast<GSList *>(desktop->getSelection()->itemList()));
+ gint num = (desktop->getSelection()->itemList()).size();
gint n = 0;
if (num < 1) {
@@ -1024,8 +1020,9 @@ void Export::onExport ()
gint export_count = 0;
- for (GSList *i = const_cast<GSList *>(desktop->getSelection()->itemList()); i && !interrupted; i = i->next) {
- SPItem *item = reinterpret_cast<SPItem *>(i->data);
+ std::vector<SPItem*> itemlist=desktop->getSelection()->itemList();
+ for(std::vector<SPItem*>::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;i++){
+ SPItem *item = *i;
prog_dlg->set_data("current", GINT_TO_POINTER(n));
prog_dlg->set_data("total", GINT_TO_POINTER(num));
@@ -1063,13 +1060,13 @@ void Export::onExport ()
_("Exporting file <b>%s</b>..."), safeFile), desktop);
MessageCleaner msgFlashCleanup(desktop->messageStack()->flashF(Inkscape::IMMEDIATE_MESSAGE,
_("Exporting file <b>%s</b>..."), safeFile), desktop);
-
+ std::vector<SPItem*> 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<GSList *>(desktop->getSelection()->itemList()) : NULL
+ hide ? (desktop->getSelection()->itemList()) : x
)) {
gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile);
@@ -1153,12 +1150,13 @@ void Export::onExport ()
prog_dlg->set_data("total", GINT_TO_POINTER(0));
/* Do export */
+ std::vector<SPItem*> 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<GSList *>(desktop->getSelection()->itemList()) : NULL
+ hide ? (desktop->getSelection()->itemList()) : x
);
if (status == EXPORT_ERROR) {
gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str());
@@ -1224,7 +1222,7 @@ void Export::onExport ()
break;
}
case SELECTION_SELECTION: {
- const GSList * reprlst;
+ std::vector<XML::Node*> reprlst;
SPDocument * doc = SP_ACTIVE_DOCUMENT;
bool modified = false;
@@ -1232,8 +1230,8 @@ void Export::onExport ()
DocumentUndo::setUndoSensitive(doc, false);
reprlst = desktop->getSelection()->reprList();
- for(; reprlst != NULL; reprlst = reprlst->next) {
- Inkscape::XML::Node * repr = static_cast<Inkscape::XML::Node *>(reprlst->data);
+ for(std::vector<Inkscape::XML::Node*>::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/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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
//Gtk includes
#include <gtkmm/filechooserdialog.h>
#include <glib/gstdio.h>
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 <glibmm.h>
#ifdef WIN32
-#if WITH_GLIBMM_2_32
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-# include <glibmm/threads.h>
-#endif
-#endif
#include "filedialogimpl-gtkmm.h"
diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp
index 077c6f5ca..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 <juca@members.fsf.org>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
+ * insaner
*
* Copyright (C) 2007 Authors
*
@@ -690,7 +691,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 = sel->reprList()[0];
if (!node || !node->matchAttributeName("id")) return;
std::ostringstream xlikhref;
@@ -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);
@@ -1465,9 +1473,9 @@ void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel)
}
std::set<SPObject*> used;
-
- for (GSList const *i = sel->itemList(); i != NULL; i = i->next) {
- SPObject *obj = SP_OBJECT (i->data);
+ std::vector<SPItem*> itemlist=sel->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) {
+ SPObject *obj = *i;
SPStyle *style = obj->style;
if (!style || !SP_IS_ITEM(obj)) {
continue;
@@ -1494,6 +1502,7 @@ void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel)
(*iter)[_columns.sel] = 0;
}
}
+ update_counts();
}
void FilterEffectsDialog::FilterModifier::on_filter_selection_changed()
@@ -1545,10 +1554,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);
+ std::vector<SPItem*> itemlist=sel->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) {
+ SPItem * item = *i;
SPStyle *style = item->style;
g_assert(style != NULL);
@@ -1566,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()
@@ -1650,12 +1667,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)) {
+ std::vector<SPItem*> x,y;
+ std::vector<SPItem*> all = get_all_items(x, _desktop->currentRoot(), _desktop, false, false, true, y);
+ for(std::vector<SPItem*>::const_iterator i=all.begin(); all.end() != i; i++) {
+ if (!SP_IS_ITEM(*i)) {
continue;
}
- SPItem *item = SP_ITEM(i->data);
+ SPItem *item = *i;
if (!item->style) {
continue;
}
@@ -1668,9 +1686,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());
@@ -2422,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);
@@ -2442,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)
@@ -2755,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);
@@ -2784,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 <nicholasbishop@gmail.com>
* Rodrigo Kumpera <kumpera@gmail.com>
+ * insaner
*
* Copyright (C) 2007 Authors
*
@@ -69,11 +70,13 @@ private:
add(filter);
add(label);
add(sel);
+ add(count);
}
Gtk::TreeModelColumn<SPFilter*> filter;
Gtk::TreeModelColumn<Glib::ustring> label;
Gtk::TreeModelColumn<int> sel;
+ Gtk::TreeModelColumn<int> count;
};
void setTargetDesktop(SPDesktop *desktop);
@@ -89,6 +92,7 @@ private:
bool on_filter_move(const Glib::RefPtr<Gdk::DragContext>& /*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();
diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp
index 951cb01ea..a8ac42a1b 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)
+std::vector<SPItem*> Find::filter_fields (std::vector<SPItem*> &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;
+ std::vector<SPItem*> in = l;
+ std::vector<SPItem*> out;
if (check_searchin_text.get_active()) {
- for (GSList *i = in; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) {
+ SPObject *obj = *i;
SPItem *item = dynamic_cast<SPItem *>(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_back(*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<SPObject *>(i->data);
+ for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) {
+ SPObject *obj = *i;
SPItem *item = dynamic_cast<SPItem *>(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_back(*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<SPObject *>(i->data);
+ for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) {
+ SPObject *obj = *i;
SPItem *item = dynamic_cast<SPItem *>(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_back(*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<SPObject *>(i->data);
+ for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) {
+ SPObject *obj = *i;
SPItem *item = dynamic_cast<SPItem *>(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_back(*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<SPObject *>(i->data);
+ for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) {
+ SPObject *obj = *i;
SPItem *item = dynamic_cast<SPItem *>(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_back(*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<SPObject *>(i->data);
+ for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) {
+ SPObject *obj = *i;
SPItem *item = dynamic_cast<SPItem *>(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_back(*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)
+std::vector<SPItem*> Find::filter_types (std::vector<SPItem*> &l)
{
- GSList *n = NULL;
- for (GSList *i = l; i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ std::vector<SPItem*> n;
+ for(std::vector<SPItem*>::const_reverse_iterator i=l.rbegin(); l.rend() != i; i++) {
+ SPObject *obj = *i;
SPItem *item = dynamic_cast<SPItem *>(obj);
g_assert(item != NULL);
if (item_type_match(item)) {
- n = g_slist_prepend (n, i->data);
+ n.push_back(*i);
}
}
return n;
}
-GSList *Find::filter_list (GSList *l, bool exact, bool casematch)
+std::vector<SPItem*> &Find::filter_list (std::vector<SPItem*> &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)
+std::vector<SPItem*> &Find::all_items (SPObject *r, std::vector<SPItem*> &l, bool hidden, bool locked)
{
if (dynamic_cast<SPDefs *>(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<SPItem *>(child);
if (item && !child->cloned && !desktop->isLayer(item)) {
if ((hidden || !desktop->itemIsHidden(item)) && (locked || !item->isLocked())) {
- l = g_slist_prepend (l, child);
+ l.insert(l.begin(),(SPItem*)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)
+std::vector<SPItem*> &Find::all_selection_items (Inkscape::Selection *s, std::vector<SPItem*> &l, SPObject *ancestor, bool hidden, bool locked)
{
- for (GSList *i = (GSList *) s->itemList(); i != NULL; i = i->next) {
- SPObject *obj = reinterpret_cast<SPObject *>(i->data);
+ std::vector<SPItem*> itemlist=s->itemList();
+ for(std::vector<SPItem*>::const_reverse_iterator i=itemlist.rbegin(); itemlist.rend() != i; i++) {
+ SPObject *obj = *i;
SPItem *item = dynamic_cast<SPItem *>(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;
+ std::vector<SPItem*> 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);
+ std::vector<SPItem*> 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("<b>%d</b> object found (out of <b>%d</b>), %s match.",
@@ -857,7 +857,7 @@ void Find::onAction()
Inkscape::Selection *selection = desktop->getSelection();
selection->clear();
selection->setList(n);
- SPObject *obj = reinterpret_cast<SPObject *>(n->data);
+ SPObject *obj = n[0];
SPItem *item = dynamic_cast<SPItem *>(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..4bcb900b6 100644
--- a/src/ui/dialog/find.h
+++ b/src/ui/dialog/find.h
@@ -148,10 +148,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);
+ std::vector<SPItem*> filter_fields (std::vector<SPItem*> &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);
+ std::vector<SPItem*> filter_types (std::vector<SPItem*> &l);
+ std::vector<SPItem*> & filter_list (std::vector<SPItem*> &l, bool exact, bool casematch);
/**
* Find a string within a string and returns true if found with options for exact and casematching
@@ -172,12 +172,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);
+ std::vector<SPItem*> & all_items (SPObject *r, std::vector<SPItem*> &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);
+ std::vector<SPItem*> & all_selection_items (Inkscape::Selection *s, std::vector<SPItem*> &l, SPObject *ancestor, bool hidden, bool locked);
/**
* Shrink the dialog size when the expander widget is closed
diff --git a/src/ui/dialog/floating-behavior.cpp b/src/ui/dialog/floating-behavior.cpp
index 11db14801..55ef0c5bb 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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#include <gtkmm/stock.h>
#include <glibmm/main.h>
@@ -116,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/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp
index ae03bdf0e..19506c6a3 100644
--- a/src/ui/dialog/font-substitution.cpp
+++ b/src/ui/dialog/font-substitution.cpp
@@ -10,10 +10,6 @@
# include <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/messagedialog.h>
#include <gtkmm/checkbutton.h>
#include <gtkmm/scrolledwindow.h>
@@ -70,19 +66,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);
+ std::vector<SPItem*> 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, std::vector<SPItem*> &l)
{
Gtk::MessageDialog warning(_("\nSome fonts are not available and have been substituted."),
false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK, true);
@@ -152,20 +144,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)
+std::vector<SPItem*> FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring *out)
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- GSList *allList = NULL;
- GSList *outList = NULL;
+ std::vector<SPItem*> allList;
+ std::vector<SPItem*> outList,x,y;
std::set<Glib::ustring> setErrors;
std::set<Glib::ustring> setFontSpans;
std::map<SPItem *, Glib::ustring> 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(std::vector<SPItem*>::const_iterator i = allList.begin();i!=allList.end();i++){
+ SPItem *item = *i;
SPStyle *style = item->style;
Glib::ustring family = "";
@@ -220,8 +210,8 @@ GSList * FontSubstitution::getFontReplacedItems(SPDocument* doc, Glib::ustring *
}
// Check if any document styles are not in the actual layout
- std::map<SPItem *, Glib::ustring>::const_iterator mapIter;
- for (mapIter = mapFontStyles.begin(); mapIter != mapFontStyles.end(); ++mapIter) {
+ std::map<SPItem *, Glib::ustring>::const_reverse_iterator mapIter;
+ for (mapIter = mapFontStyles.rbegin(); mapIter != mapFontStyles.rend(); ++mapIter) {
SPItem *item = mapIter->first;
Glib::ustring fonts = mapIter->second;
@@ -254,7 +244,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_back(item);
}
}
diff --git a/src/ui/dialog/font-substitution.h b/src/ui/dialog/font-substitution.h
index 1c445081b..0818d778c 100644
--- a/src/ui/dialog/font-substitution.h
+++ b/src/ui/dialog/font-substitution.h
@@ -14,6 +14,7 @@
#include <glibmm/ustring.h>
+class SPItem;
class SPDocument;
namespace Inkscape {
@@ -25,13 +26,13 @@ public:
FontSubstitution();
virtual ~FontSubstitution();
void checkFontSubstitutions(SPDocument* doc);
- void show(Glib::ustring out, GSList *l);
+ void show(Glib::ustring out, std::vector<SPItem*> &l);
static FontSubstitution &getInstance() { return *new FontSubstitution(); }
Glib::ustring getSubstituteFontName (Glib::ustring font);
protected:
- GSList *getFontReplacedItems(SPDocument* doc, Glib::ustring *out);
+ std::vector<SPItem*> 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 2b9053da9..7ca277ea2 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);
+ std::vector<SPItem*> itemlist=targetDesktop->selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) {
+ if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) {
+ textItem = *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)) {
+ std::vector<SPItem*> itemlist=targetDesktop->selection->itemList();
+ for(std::vector<SPItem*>::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 d3ccb9bde..c44f66a4d 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,40 +76,41 @@ 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;
+ return false;
}
+
namespace Inkscape {
namespace UI {
namespace Dialog {
@@ -168,10 +169,9 @@ void GridArrangeTab::arrange()
desktop->getDocument()->ensureUpToDate();
Inkscape::Selection *selection = desktop->getSelection();
- const GSList *items = selection ? selection->itemList() : 0;
- cnt=0;
- for (; items != NULL; items = items->next) {
- SPItem *item = SP_ITEM(items->data);
+ const std::vector<SPItem*> items = selection ? selection->itemList() : std::vector<SPItem*>();
+ for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++){
+ SPItem *item = *i;
Geom::OptRect b = item->documentVisualBounds();
if (!b) {
continue;
@@ -198,20 +198,18 @@ 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<GSList *>(items2));
- GSList *sorted = NULL;
- rev = g_slist_sort(rev, (GCompareFunc) sp_compare_y_position);
- sorted = g_slist_sort(rev, (GCompareFunc) sp_compare_x_position);
+ std::vector<SPItem*> 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 GSList *sizes = sorted;
- for (; sizes != NULL; sizes = sizes->next) {
- SPItem *item = SP_ITEM(sizes->data);
+ const std::vector<SPItem*> sizes(sorted);
+ for (std::vector<SPItem*>::const_iterator i = sizes.begin();i!=sizes.end();i++) {
+ SPItem *item = *i;
Geom::OptRect b = item->documentVisualBounds();
if (b) {
width = b->dimensions()[Geom::X];
@@ -308,12 +306,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_cnt<NoOfRows)); row_cnt++) {
+ std::vector<SPItem*>::iterator it = sorted.begin();
+ for (row_cnt=0; ((it != sorted.end()) && (row_cnt<NoOfRows)); row_cnt++) {
GSList *current_row = NULL;
- for (col_cnt = 0; ((sorted != NULL) && (col_cnt<NoOfCols)); col_cnt++) {
- current_row = g_slist_append (current_row, sorted->data);
- sorted = sorted->next;
+ col_cnt = 0;
+ for(;it!=sorted.end()&&col<NoOfCols;it++) {
+ current_row = g_slist_append (current_row, *it);
+ col_cnt++;
}
for (; current_row != NULL; current_row = current_row->next) {
@@ -374,8 +374,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);
+ std::vector<SPItem*> const items = selection->itemList();
+ int selcount = items.size();
double PerCol = ceil(selcount / NoOfColsSpinner.get_value());
NoOfRowsSpinner.set_value(PerCol);
@@ -400,8 +400,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 +537,10 @@ void GridArrangeTab::updateSelection()
updating = true;
SPDesktop *desktop = Parent->getDesktop();
Inkscape::Selection *selection = desktop ? desktop->selection : 0;
- GSList const *items = selection ? selection->itemList() : 0;
+ std::vector<SPItem*> const items = selection ? selection->itemList() : std::vector<SPItem*>();
- 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 +608,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/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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#if WITH_GTKMM_3_0
diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp
index b908a90cb..77f120e1a 100644
--- a/src/ui/dialog/icon-preview.cpp
+++ b/src/ui/dialog/icon-preview.cpp
@@ -17,10 +17,6 @@
# include <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/buttonbox.h>
#include <boost/scoped_ptr.hpp>
@@ -316,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)));
}
}
}
@@ -366,16 +362,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 );
+ std::vector<SPItem*> const items = sel->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();!target && i!=items.end();i++){
+ SPItem* item = *i;
gchar const *id = item->getId();
if ( id ) {
targetId = id;
target = item;
}
-
- items = g_slist_next(items);
}
}
}
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#include <gtkmm/entry.h>
#include <gtkmm/label.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/treeview.h>
#include <gtkmm/treestore.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#include <gtkmm/liststore.h>
#include <gtkmm/treeview.h>
diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp
index 2960f0d34..bc6557b19 100644
--- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp
+++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp
@@ -8,10 +8,6 @@
#include <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED &&HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm.h>
#include "lpe-fillet-chamfer-properties.h"
#include <boost/lexical_cast.hpp>
@@ -31,7 +27,6 @@
#include "selection-chemistry.h"
#include "ui/icon-names.h"
#include "ui/widget/imagetoggler.h"
-#include "util/units.h"
#include <cmath>
//#include "event-context.h"
@@ -126,19 +121,15 @@ void FilletChamferPropertiesDialog::showDialog(
SPDesktop *desktop, double _amount,
const Inkscape::LivePathEffect::
FilletChamferKnotHolderEntity *pt,
- const gchar *_unit,
bool _use_distance,
bool _aprox_radius,
- Glib::ustring _documentUnit,
Geom::Satellite _satellite)
{
FilletChamferPropertiesDialog *dialog = new FilletChamferPropertiesDialog();
dialog->_setDesktop(desktop);
- dialog->_setUnit(_unit);
dialog->_setUseDistance(_use_distance);
dialog->_setAprox(_aprox_radius);
- dialog->_setDocumentUnit(_documentUnit);
dialog->_setAmount(_amount);
dialog->_setSatellite(_satellite);
dialog->_setPt(pt);
@@ -173,8 +164,6 @@ void FilletChamferPropertiesDialog::_apply()
d_pos = 0;
}
d_pos = d_pos / 100;
- } else {
- d_pos = Inkscape::Util::Quantity::convert(d_pos, _unit, _document_unit);
}
_satellite.amount = d_pos;
size_t steps = (size_t)_fillet_chamfer_chamfer_subdivisions.get_value();
@@ -227,10 +216,9 @@ void FilletChamferPropertiesDialog::_setSatellite(Geom::Satellite satellite)
_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 = _amount;
- position = Inkscape::Util::Quantity::convert(position, _document_unit, _unit);
}
_fillet_chamfer_position_numeric.set_value(position);
_fillet_chamfer_chamfer_subdivisions.set_value(satellite.steps);
@@ -255,10 +243,6 @@ void FilletChamferPropertiesDialog::_setPt(
pt);
}
-void FilletChamferPropertiesDialog::_setUnit(const gchar *abbr)
-{
- _unit = abbr;
-}
void FilletChamferPropertiesDialog::_setAmount(double amm)
{
@@ -267,12 +251,6 @@ void FilletChamferPropertiesDialog::_setAmount(double amm)
-
-void FilletChamferPropertiesDialog::_setDocumentUnit(Glib::ustring abbr)
-{
- _document_unit = abbr;
-}
-
void FilletChamferPropertiesDialog::_setUseDistance(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 51fc847c3..53bb90b80 100644
--- a/src/ui/dialog/lpe-fillet-chamfer-properties.h
+++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h
@@ -31,10 +31,8 @@ public:
static void showDialog(SPDesktop *desktop, double _amount,
const Inkscape::LivePathEffect::
FilletChamferKnotHolderEntity *pt,
- const gchar *_unit,
bool _use_distance,
bool _aprox_radius,
- Glib::ustring _documentUnit,
Geom::Satellite _satellite);
protected:
@@ -70,8 +68,6 @@ protected:
void _setDesktop(SPDesktop *desktop);
void _setPt(const Inkscape::LivePathEffect::
FilletChamferKnotHolderEntity *pt);
- void _setUnit(const gchar *abbr);
- void _setDocumentUnit(Glib::ustring abbr);
void _setUseDistance(bool use_knot_distance);
void _setAprox(bool aprox_radius);
void _setAmount(double amount);
@@ -85,13 +81,10 @@ protected:
void _close();
bool _flexible;
Geom::Satellite _satellite;
- const gchar *_unit;
- Glib::ustring _document_unit;
bool _use_distance;
double _amount;
bool _aprox;
-
friend class Inkscape::LivePathEffect::
FilletChamferKnotHolderEntity;
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include "lpe-powerstroke-properties.h"
#include <boost/lexical_cast.hpp>
#include <gtkmm/stock.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/textview.h>
#include <gtkmm/button.h>
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/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"));
diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp
index 9db0285d7..781c6ef93 100644
--- a/src/ui/dialog/objects.cpp
+++ b/src/ui/dialog/objects.cpp
@@ -477,15 +477,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<SPItem *>(iter->data);
+ std::vector<SPItem*> const items = sel->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin(); i!=items.end();i++){
+ item = *i;
if (setOpacity)
{
_setCompositingValues(item);
setOpacity = false;
}
- _store->foreach(sigc::bind<SPItem *, bool>( sigc::mem_fun(*this, &ObjectsPanel::_checkForSelected), item, iter->next == NULL));
+ _store->foreach(sigc::bind<SPItem *, bool>( 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/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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-# include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/treeview.h>
#include <gtkmm/treestore.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
//Gtk includes
#include <gtkmm/box.h>
#include <gtkmm/eventbox.h>
diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp
index 5113f172a..760391df6 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) )
+ std::vector<SPItem*> const items = desktop->selection->itemList();
+ for(std::vector<SPItem*>::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..af1386e27 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 std::vector<SPItem*> 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(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++)
{
if(arrangeOnEllipse)
{
- SPItem *item = SP_ITEM(tmp->data);
+ SPItem *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(std::vector<SPItem*>::const_iterator it=tmp.begin();it!=tmp.end();it++)
{
- SPItem *item = SP_ITEM(tmp->data);
+ SPItem *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 ad979b570..c44d645a5 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, std::vector<SPItem*>());
// 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/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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/buttonbox.h>
diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp
index bc228633d..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*) g_slist_nth_data((GSList *)sel->reprList(), 0);
+ 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 <b>path</b> 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 = 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 <b>path</b> description.");
diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp
index 8759039c3..72677c07e 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) {
+ std::vector<SPItem*> const items = selection->itemList();
+ if (!items.empty()) {
SPStyle query( desktop->doc() );
- int result = objects_query_fillstroke(const_cast<GSList *>(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/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 <functional>
#include <sstream>
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/buttonbox.h>
#include <gtkmm/label.h>
diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp
index 7d3edaffb..ed71c826f 100644
--- a/src/ui/dialog/tags.cpp
+++ b/src/ui/dialog/tags.cpp
@@ -352,9 +352,10 @@ void TagsPanel::_objectsSelected( Selection *sel ) {
_selectedConnection.block();
_tree.get_selection()->unselect_all();
- for (const GSList * iter = sel->list(); iter != NULL; iter = iter->next)
+ std::vector<SPObject*> tmp=sel->list();
+ for(std::vector<SPObject*>::const_iterator i=tmp.begin();i!=tmp.end();i++)
{
- SPObject *obj = reinterpret_cast<SPObject *>(iter->data);
+ SPObject *obj = *i;
_store->foreach(sigc::bind<SPObject *>( sigc::mem_fun(*this, &TagsPanel::_checkForSelected), obj));
}
_selectedConnection.unblock();
@@ -649,9 +650,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<SPObject *>(iter->data);
+ std::vector<SPItem*> items=_desktop->selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();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 a8be8b543..815aa12ef 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)
+ std::vector<SPItem*> tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList();
+ for(std::vector<SPItem*>::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 *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)
+ std::vector<SPItem*> tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList();
+ for(std::vector<SPItem*>::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 std::vector<SPItem*> 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(std::vector<SPItem*>::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<SPObject*>(item_list->data)->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;
}
- 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/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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/notebook.h>
#include <gtkmm/button.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/notebook.h>
#include <gtkmm/checkbutton.h>
diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp
index 233d99750..498ad7822 100644
--- a/src/ui/dialog/transformation.cpp
+++ b/src/ui/dialog/transformation.cpp
@@ -15,10 +15,6 @@
# include <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#include <gtkmm/stock.h>
#include <2geom/transforms.h>
@@ -655,7 +651,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 (selection->itemList()[0]->transform); // take from the first item in selection
Geom::Affine new_displayed = current;
@@ -740,20 +736,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<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ std::vector<SPItem*> selected(selection->itemList());
if (selected.empty()) return;
if (fabs(x) > 1e-6) {
std::vector< BBoxSort > sorted;
- for (std::list<SPItem *>::iterator it(selected.begin());
+ for (std::vector<SPItem*>::iterator it(selected.begin());
it != selected.end();
++it)
{
- Geom::OptRect bbox = (*it)->desktopPreferredBounds();
+ SPItem* item = *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 +766,14 @@ void Transformation::applyPageMove(Inkscape::Selection *selection)
}
if (fabs(y) > 1e-6) {
std::vector< BBoxSort > sorted;
- for (std::list<SPItem *>::iterator it(selected.begin());
+ for (std::vector<SPItem*>::iterator it(selected.begin());
it != selected.end();
++it)
{
- Geom::OptRect bbox = (*it)->desktopPreferredBounds();
+ SPItem* item = *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 +811,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);
+ std::vector<SPItem*> tmp=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++){
+ SPItem *item = *i;
Geom::OptRect bbox_pref = item->desktopPreferredBounds();
Geom::OptRect bbox_geom = item->desktopGeometricBounds();
if (bbox_pref && bbox_geom) {
@@ -878,8 +875,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);
+ std::vector<SPItem*> tmp=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++){
+ SPItem *item = *i;
sp_item_rotate_rel(item, Geom::Rotate (angle*M_PI/180.0));
}
} else {
@@ -897,8 +895,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);
+ std::vector<SPItem*> items=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++){
+ SPItem *item = *i;
if (!_units_skew.isAbsolute()) { // percentage
double skewX = _scalar_skew_horizontal.getValue("%");
@@ -998,10 +997,11 @@ 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);
+ std::vector<SPItem*> tmp=selection->itemList();
+ for(std::vector<SPItem*>::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
@@ -1150,7 +1150,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 = 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 87438ac01..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);
}
}
@@ -1906,11 +1906,10 @@ void ContextMenu::ActivateGroup(void)
void ContextMenu::ActivateUngroup(void)
{
- GSList *children = NULL;
+ std::vector<SPItem*> children;
- sp_item_group_ungroup(static_cast<SPGroup*>(_item), &children);
+ sp_item_group_ungroup(static_cast<SPGroup*>(_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<SPAnchor*>(_item), &children, false);
+ std::vector<SPItem*> children;
+ sp_item_group_ungroup(static_cast<SPAnchor*>(_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();
+ std::vector<SPItem*> itemlist=_desktop->selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ Inkscape::XML::Node *ir = (*i)->getRepr();
const gchar *href = ir->attribute("xlink:href");
if (strncmp (href,"file:",5) == 0) {
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/bin.h>
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/connector-tool.cpp b/src/ui/tools/connector-tool.cpp
index c3ef19507..0a36877ff 100644
--- a/src/ui/tools/connector-tool.cpp
+++ b/src/ui/tools/connector-tool.cpp
@@ -1303,12 +1303,12 @@ void cc_selection_set_avoid(bool const set_avoid)
Inkscape::Selection *selection = desktop->getSelection();
- GSList *l = const_cast<GSList *>(selection->itemList());
int changes = 0;
- while (l) {
- SPItem *item = SP_ITEM(l->data);
+ std::vector<SPItem*> l = selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=l.begin();i!=l.end();i++) {
+ SPItem *item = *i;
char const *value = (set_avoid) ? "true" : NULL;
@@ -1317,8 +1317,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 af0cbcb78..10f8c8694 100644
--- a/src/ui/tools/eraser-tool.cpp
+++ b/src/ui/tools/eraser-tool.cpp
@@ -666,8 +666,7 @@ void EraserTool::set_to_accumulated() {
Geom::OptRect eraserBbox = acid->visualBounds();
Geom::Rect bounds = (*eraserBbox) * desktop->doc2dt();
std::vector<SPItem*> remainingItems;
- GSList* toWorkOn = 0;
-
+ std::vector<SPItem*> toWorkOn;
if (selection->isEmpty()) {
if ( eraserMode ) {
toWorkOn = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, bounds);
@@ -675,17 +674,16 @@ void EraserTool::set_to_accumulated() {
Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints());
}
-
- toWorkOn = g_slist_remove( toWorkOn, acid );
+ toWorkOn.erase(std::remove(toWorkOn.begin(), toWorkOn.end(), acid), toWorkOn.end());
} else {
- toWorkOn = g_slist_copy(const_cast<GSList*>(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 (std::vector<SPItem*>::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); i++){
+ SPItem *item = *i;
if ( eraserMode ) {
Geom::OptRect bbox = item->visualBounds();
@@ -702,13 +700,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<GSList *>(selection->itemList()));
-
- for (GSList const *i2 = nowSel ; i2 ; i2 = i2->next ) {
- remainingItems.push_back(SP_ITEM(i2->data));
+ std::vector<SPItem*> nowSel(selection->itemList());
+ for (std::vector<SPItem*>::const_iterator i2 = nowSel.begin();i2!=nowSel.end();i2++) {
+ remainingItems.push_back(*i2);
}
-
- g_slist_free(nowSel);
}
} else {
remainingItems.push_back(item);
@@ -716,20 +711,18 @@ void EraserTool::set_to_accumulated() {
}
}
} else {
- for (GSList *i = toWorkOn ; i ; i = i->next ) {
- sp_object_ref( SP_ITEM(i->data), 0 );
+ for (std::vector<SPItem*> ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) {
+ sp_object_ref( *i, 0 );
}
- for (GSList *i = toWorkOn ; i ; i = i->next ) {
- SPItem *item = SP_ITEM(i->data);
+ for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) {
+ SPItem *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/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<Geom::Point>::iterator start_sort = fill_queue.begin();
std::deque<Geom::Point>::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<Geom::Point>::iterator i = fill_queue.begin(); i != fill_queue.end(); ++i) {
Geom::Point current = *i;
diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp
index b27859ebb..526671515 100644
--- a/src/ui/tools/gradient-tool.cpp
+++ b/src/ui/tools/gradient-tool.cpp
@@ -106,7 +106,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;
@@ -492,10 +492,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);
+ std::vector<SPItem*> items=selection->itemList();
+ for (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();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;
@@ -898,32 +899,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);
+ std::vector<SPItem*> 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(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) {
+ std::vector<SPItem*> itemlist = selection->itemList();
+ for (std::vector<SPItem*>::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((*i)->getRepr(), css, "style");
- sp_item_set_gradient(SP_ITEM(i->data), 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->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 (*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->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 (*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->data)->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
if (ec->_grdrag) {
ec->_grdrag->updateDraggers();
@@ -932,7 +933,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 (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);
@@ -941,7 +942,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("<b>Gradient</b> for %d object; with <b>Ctrl</b> to snap angle",
"<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects),
diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp
index c0517578d..13e47f3a6 100644
--- a/src/ui/tools/lpe-tool.cpp
+++ b/src/ui/tools/lpe-tool.cpp
@@ -396,10 +396,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);
+ std::vector<SPItem*> items=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ if (SP_IS_PATH(*i)) {
+ path = SP_PATH(*i);
curve = path->getCurve();
Geom::Piecewise<Geom::D2<Geom::SBasis> > 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 0875c29e0..570f3e796 100644
--- a/src/ui/tools/measure-tool.cpp
+++ b/src/ui/tools/measure-tool.cpp
@@ -431,10 +431,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);
+ std::vector<SPItem*> items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points);
std::vector<double> intersection_times;
- for (GSList *l = items; l != NULL; l = l->next) {
- SPItem *item = static_cast<SPItem*>(l->data);
+ for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();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 67ed7aef1..0e68af601 100644
--- a/src/ui/tools/mesh-tool.cpp
+++ b/src/ui/tools/mesh-tool.cpp
@@ -103,7 +103,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;
@@ -467,11 +467,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, selection->itemList()[0], 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);
+ std::vector<SPItem*> items=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();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;
@@ -940,27 +941,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);
+ std::vector<SPItem*> 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(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) {
+ std::vector<SPItem*> items=selection->itemList();
+ for(std::vector<SPItem*>::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((*i)->getRepr(), css, "style");
- sp_item_set_gradient(SP_ITEM(i->data), 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->data)->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
// if (ec->_grdrag) {
// ec->_grdrag->updateDraggers();
@@ -978,7 +979,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("<b>Gradient</b> for %d object; with <b>Ctrl</b> to snap angle",
"<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects),
diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp
index a4b903960..ef00eaa40 100644
--- a/src/ui/tools/node-tool.cpp
+++ b/src/ui/tools/node-tool.cpp
@@ -410,10 +410,9 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) {
std::set<ShapeRecord> shapes;
- GSList const *ilist = sel->itemList();
-
- for (GSList *i = const_cast<GSList*>(ilist); i; i = i->next) {
- SPObject *obj = static_cast<SPObject*>(i->data);
+ std::vector<SPItem*> items=sel->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPObject *obj = *i;
if (SP_IS_ITEM(obj)) {
gather_items(this, NULL, static_cast<SPItem*>(obj), SHAPE_ROLE_NORMAL, shapes);
@@ -658,9 +657,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);
+ std::vector<SPItem*> 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/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<Geom::CubicBezier const*>(&*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<Geom::CubicBezier const*>(&*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 40b994968..f06b03d91 100644
--- a/src/ui/tools/select-tool.cpp
+++ b/src/ui/tools/select-tool.cpp
@@ -472,7 +472,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_2BUTTON_PRESS:
if (event->button.button == 1) {
if (!selection->isEmpty()) {
- SPItem *clicked_item = static_cast<SPItem *>(selection->itemList()->data);
+ SPItem *clicked_item = selection->itemList()[0];
if (dynamic_cast<SPGroup *>(clicked_item) && !dynamic_cast<SPBox3D *>(clicked_item)) { // enter group if it's not a 3D box
desktop->setCurrentLayer(clicked_item);
@@ -709,7 +709,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (r->is_started() && !within_tolerance) {
// this was a rubberband drag
- GSList *items = NULL;
+ std::vector<SPItem*> items;
if (r->getMode() == RUBBERBAND_MODE_RECT) {
Geom::OptRect const b = r->getRectangle();
@@ -730,7 +730,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();
@@ -778,7 +777,6 @@ bool SelectTool::root_handler(GdkEvent* event) {
}
rb_escaped = 0;
- ret = TRUE;
}
}
}
diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp
index 0399b1e55..26d74733a 100644
--- a/src/ui/tools/spray-tool.cpp
+++ b/src/ui/tools/spray-tool.cpp
@@ -178,7 +178,7 @@ void SprayTool::update_cursor(bool /*with_shift*/) {
gchar *sel_message = NULL;
if (!desktop->selection->isEmpty()) {
- num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList()));
+ num = desktop->selection->itemList().size();
sel_message = g_strdup_printf(ngettext("<b>%i</b> object selected","<b>%i</b> objects selected",num), num);
} else {
sel_message = g_strdup_printf("%s", _("<b>Nothing</b> selected"));
@@ -426,11 +426,9 @@ static bool sp_spray_recursive(SPDesktop *desktop,
SPItem *unionResult = NULL; // Previous union
int i=1;
- for (GSList *items = g_slist_copy(const_cast<GSList *>(selection->itemList()));
- items != NULL;
- items = items->next) {
-
- SPItem *item1 = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
+ std::vector<SPItem*> items=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator it=items.begin();it!=items.end();it++){
+ SPItem *item1 = *it;
if (i == 1) {
parent_item = item1;
}
@@ -544,20 +542,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<GSList *>(selection->itemList()));
+ std::vector<SPItem*> const items(selection->itemList());
- for (GSList *items = original_selection;
- items != NULL;
- items = items->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *item = *i;
g_assert(item != NULL);
sp_object_ref(item);
}
- for (GSList *items = original_selection;
- items != NULL;
- items = items->next) {
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *item = *i;
g_assert(item != NULL);
if (is_transform_modes(tc->mode)) {
@@ -571,10 +565,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<SPItem *>(static_cast<SPObject *>(items->data));
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *item = *i;
g_assert(item != NULL);
sp_object_unref(item);
}
@@ -650,7 +642,7 @@ bool SprayTool::root_handler(GdkEvent* event) {
guint num = 0;
if (!desktop->selection->isEmpty()) {
- num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList()));
+ num = desktop->selection->itemList().size();
}
if (num == 0) {
this->message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to spray."));
diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp
index a2c0c81ae..1888551cf 100644
--- a/src/ui/tools/text-tool.cpp
+++ b/src/ui/tools/text-tool.cpp
@@ -1461,7 +1461,7 @@ int TextTool::_styleQueried(SPStyle *style, int property)
}
sp_text_context_validate_cursor_iterators(this);
- GSList *styles_list = NULL;
+ std::vector<SPItem*> styles_list;
Inkscape::Text::Layout::iterator begin_it, end_it;
if (this->text_sel_start < this->text_sel_end) {
@@ -1477,7 +1477,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)) {
@@ -1487,12 +1487,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.insert(styles_list.begin(),(SPItem*)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..0f9b3ee7a 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 <glibmm/threads.h>
-#endif
-
#include "shortcuts.h"
#include "file.h"
#include "ui/tools/tool-base.h"
@@ -1178,11 +1174,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);
+ std::vector<SPItem*> temp;
+ temp.push_back(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 80b52fba6..76b52f9be 100644
--- a/src/ui/tools/tweak-tool.cpp
+++ b/src/ui/tools/tweak-tool.cpp
@@ -153,7 +153,7 @@ void TweakTool::update_cursor (bool with_shift) {
gchar *sel_message = NULL;
if (!desktop->selection->isEmpty()) {
- num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList()));
+ num = desktop->selection->itemList().size();
sel_message = g_strdup_printf(ngettext("<b>%i</b> object selected","<b>%i</b> objects selected",num), num);
} else {
sel_message = g_strdup_printf("%s", _("<b>Nothing</b> selected"));
@@ -372,14 +372,13 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P
}
if (dynamic_cast<SPText *>(item) || dynamic_cast<SPFlowtext *>(item)) {
- GSList *items = g_slist_prepend (NULL, item);
- GSList *selected = NULL;
- GSList *to_select = NULL;
+ std::vector<SPItem*> items;
+ items.push_back(item);
+ std::vector<SPItem*> selected;
+ std::vector<Inkscape::XML::Node*> 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<Inkscape::XML::Node *>(to_select->data));
- g_slist_free (to_select);
+ sp_item_list_to_curves (items, selected, to_select);
+ SPObject* newObj = doc->getObjectByRepr(to_select[0]);
item = dynamic_cast<SPItem *>(newObj);
g_assert(item != NULL);
selection->add(item);
@@ -1078,11 +1077,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<GSList *>(selection->itemList()));
- items != NULL;
- items = items->next) {
-
- SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
+ std::vector<SPItem*> items=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ SPItem *item = *i;
if (is_color_mode (tc->mode)) {
if (do_fill || do_stroke || do_opacity) {
@@ -1189,7 +1186,7 @@ bool TweakTool::root_handler(GdkEvent* event) {
guint num = 0;
if (!desktop->selection->isEmpty()) {
- num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList()));
+ num = desktop->selection->itemList().size();
}
if (num == 0) {
this->message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to tweak."));
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-# include <glibmm/threads.h>
-#endif
-
#include "ui/widget/addtoicon.h"
#include <gtkmm/icontheme.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/checkbutton.h>
#include <gtkmm/radiobutton.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-# include <glibmm/threads.h>
-#endif
-
#include "ui/widget/clipmaskicon.h"
#include <gtkmm/icontheme.h>
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 <config.h>
-#endif
-
#include <stddef.h>
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h>
#include <gtkmm/button.h>
#include <sigc++/sigc++.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/widget.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/frame.h>
#include <gtkmm/window.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <list>
#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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/entry.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/combobox.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/alignment.h>
#include <gtkmm/frame.h>
#include <gtkmm/label.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <glibmm/ustring.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/cellrendererpixbuf.h>
#include <gtkmm/widget.h>
#include <glibmm/property.h>
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 <glibmm.h>
#include <gtkmm/cellrendererpixbuf.h>
#include <gtkmm/widget.h>
+#include <glibmm/property.h>
+
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-# include <glibmm/threads.h>
-#endif
-
#include "ui/widget/layertypeicon.h"
#include <gtkmm/icontheme.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
namespace Gtk {
diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp
index 00a74c4fe..8acf083d0 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 ) {
+ std::vector<SPObject*> sel=_subject->list();
+ for (std::vector<SPObject*>::const_iterator i = sel.begin() ; i != sel.end() ; ++i ) {
if (!SP_IS_ITEM(*i)) {
continue;
}
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/alignment.h>
#include <gtkmm/adjustment.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/dialog.h> // for Gtk::RESPONSE_*
#include <gtkmm/menu.h>
#include <gtkmm/stock.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/arrow.h>
#include <gtkmm/button.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/frame.h>
#include <gtkmm/alignment.h>
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 <iostream>
#include <vector>
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/filechooserbutton.h>
#include "ui/widget/spinbutton.h"
#include <stddef.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/eventbox.h>
#include <glibmm/i18n.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/scale.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/scale.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/spinbutton.h>
namespace Inkscape {
diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp
index a48370d9b..da3bbcd20 100644
--- a/src/ui/widget/style-subject.cpp
+++ b/src/ui/widget/style-subject.cpp
@@ -55,13 +55,11 @@ Inkscape::Selection *StyleSubject::Selection::_getSelection() const {
}
}
-StyleSubject::iterator StyleSubject::Selection::begin() {
+std::vector<SPObject*> 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<SPObject*>();
}
Geom::OptRect StyleSubject::Selection::getBounds(SPItem::BBoxType type) {
@@ -104,8 +102,7 @@ void StyleSubject::Selection::setCSS(SPCSSAttr *css) {
}
StyleSubject::CurrentLayer::CurrentLayer() {
- _element.data = NULL;
- _element.next = NULL;
+ _element = NULL;
}
StyleSubject::CurrentLayer::~CurrentLayer() {
@@ -114,10 +111,10 @@ StyleSubject::CurrentLayer::~CurrentLayer() {
void StyleSubject::CurrentLayer::_setLayer(SPObject *layer) {
_layer_release.disconnect();
_layer_modified.disconnect();
- if (_element.data) {
- sp_object_unref(static_cast<SPObject *>(_element.data), NULL);
+ if (_element) {
+ sp_object_unref(_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,19 +124,18 @@ void StyleSubject::CurrentLayer::_setLayer(SPObject *layer) {
}
SPObject *StyleSubject::CurrentLayer::_getLayer() const {
- return static_cast<SPObject *>(_element.data);
+ return _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());
+std::vector<SPObject*> StyleSubject::CurrentLayer::list(){
+ std::vector<SPObject*> list;
+ list.push_back(_element);
+ return list;
}
Geom::OptRect StyleSubject::CurrentLayer::getBounds(SPItem::BBoxType type) {
@@ -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) {
+ std::vector<SPItem*> list;
+ SPObject* i=_getLayerSList();
+ if (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/ui/widget/style-subject.h b/src/ui/widget/style-subject.h
index 47da91732..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 <boost/optional.hpp>
#include <2geom/rect.h>
#include "sp-item.h"
@@ -35,7 +34,6 @@ public:
class Selection;
class CurrentLayer;
- typedef Util::GSListConstIterator<SPObject *> iterator;
StyleSubject();
virtual ~StyleSubject();
@@ -43,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<SPObject*> list(){return std::vector<SPObject*>();};
sigc::connection connectChanged(sigc::signal<void>::slot_type slot) {
return _changed_signal.connect(slot);
@@ -67,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<SPObject*> list();
protected:
virtual void _afterDesktopSwitch(SPDesktop *desktop);
@@ -88,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<SPObject*> list();
protected:
virtual void _afterDesktopSwitch(SPDesktop *desktop);
@@ -99,12 +96,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;
};
}
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <gtkmm/eventbox.h>
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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/label.h>
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/comboboxtext.h>
#include "util/units.h"
diff --git a/src/unclump.cpp b/src/unclump.cpp
index 940369d7a..81c958937 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, std::list<SPItem*> &others)
{
int n = 0;
double sum = 0;
-
- for (GSList *i = others; i != NULL; i = i->next) {
- SPItem *other = SP_ITEM (i->data);
+ for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) {
+ SPItem *other = *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, std::list<SPItem*> &others)
{
double min = HUGE_VAL;
SPItem *closest = NULL;
- for (GSList *i = others; i != NULL; i = i->next) {
- SPItem *other = SP_ITEM (i->data);
+ for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) {
+ SPItem *other = *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, std::list<SPItem*> &others)
{
double max = -HUGE_VAL;
SPItem *farest = NULL;
-
- for (GSList *i = others; i != NULL; i = i->next) {
- SPItem *other = SP_ITEM (i->data);
+ for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) {
+ SPItem *other = *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 std::vector<SPItem*>
+unclump_remove_behind (SPItem *item, SPItem *closest, std::list<SPItem*> &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);
+ std::vector<SPItem*> out;
+ for (std::list<SPItem*>::const_reverse_iterator i = rest.rbegin(); i != rest.rend();i++) {
+ SPItem *other = *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_back(other);
}
}
@@ -334,34 +331,34 @@ 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 (std::vector<SPItem*> &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 (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x:
+ SPItem *item = *i;
- GSList *nei = NULL;
+ std::list<SPItem*> nei;
- GSList *rest = g_slist_copy (items);
- rest = g_slist_remove (rest, item);
+ std::list<SPItem*> rest;
+ for(int i=0;i<items.size();i++)rest.push_front(items[items.size()-i-1]);
+ 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);
- rest = new_rest;
+ nei.push_front(closest);
+ rest.remove(closest);
+ std::vector<SPItem*> new_rest = unclump_remove_behind (item, closest, rest);
+ rest.clear();
+ for(int i=0;i<new_rest.size();i++)rest.push_front(new_rest[new_rest.size()-i-1]);
} 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..461e99d0b 100644
--- a/src/unclump.h
+++ b/src/unclump.h
@@ -13,7 +13,7 @@
typedef struct _GSList GSList;
-void unclump(GSList *items);
+void unclump(std::vector<SPItem*> &items);
#endif /* !UNCLUMP_H_SEEN */
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/vanishing-point.cpp b/src/vanishing-point.cpp
index b62aacbc5..46f895c06 100644
--- a/src/vanishing-point.cpp
+++ b/src/vanishing-point.cpp
@@ -256,8 +256,9 @@ VanishingPoint::set_pos(Proj::Pt2 const &pt) {
std::list<SPBox3D *>
VanishingPoint::selectedBoxes(Inkscape::Selection *sel) {
std::list<SPBox3D *> sel_boxes;
- for (GSList const* i = sel->itemList(); i != NULL; i = i->next) {
- SPItem *item = static_cast<SPItem *>(i->data);
+ std::vector<SPItem*> itemlist=sel->itemList();
+ for (std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++) {
+ SPItem *item = *i;
SPBox3D *box = dynamic_cast<SPBox3D *>(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<SPItem *>(i->data);
+ std::vector<SPItem*> itemlist=sel->itemList();
+ for (std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++) {
+ SPItem *item = *i;
SPBox3D *box = dynamic_cast<SPBox3D *>(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<SPItem *>(i->data);
+ std::vector<SPItem*> itemlist=this->selection->itemList();
+ for (std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++) {
+ SPItem *item = *i;
SPBox3D *box = dynamic_cast<SPBox3D *>(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<SPItem *>(i->data);
+ std::vector<SPItem*> itemlist=this->selection->itemList();
+ for (std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++) {
+ SPItem *item = *i;
SPBox3D *box = dynamic_cast<SPBox3D *>(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)
+ std::vector<SPItem*> 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/verbs.cpp b/src/verbs.cpp
index 5febeeb7c..e0ef27b0d 100644
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
@@ -32,10 +32,9 @@
#include <cstring>
#include <string>
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#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 <gtkmm/filechooserdialog.h>
#include <gtkmm/messagedialog.h>
#include <gtkmm/stock.h>
@@ -1351,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"));
diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp
index 8a64854be..71418e238 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);
-
+ std::vector<SPItem*> itemlist=desktop->getSelection()->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<SPItem*>(items->data);
+ std::vector<SPItem*> itemlist=desktop->getSelection()->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<SPItem *>(items->data);
+ std::vector<SPItem*> itemlist=desktop->getSelection()->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<SPItem *>(items->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();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 c906f7de4..1c99f283d 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<SPDesktop *>(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);
+ std::vector<SPItem*> itemlist=desktop->getSelection()->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<SPDesktop *>(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);
+ std::vector<SPItem*> itemlist=desktop->getSelection()->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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/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 <config.h>
#endif
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/combobox.h>
#include <gtkmm/liststore.h>
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/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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/window.h>
#include "message.h"
#include "ui/view/view-widget.h"
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/fill-style.cpp b/src/widgets/fill-style.cpp
index d60a92b8b..b1f812338 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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <glibmm/i18n.h>
@@ -481,7 +477,7 @@ void FillNStroke::updateFromPaint()
SPDocument *document = desktop->getDocument();
Inkscape::Selection *selection = desktop->getSelection();
- GSList const *items = selection->itemList();
+ std::vector<SPItem*> const items = selection->itemList();
switch (psel->mode) {
case SPPaintSelector::MODE_EMPTY:
@@ -543,7 +539,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 +557,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<GSList *>(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 +572,39 @@ void FillNStroke::updateFromPaint()
}
}
- for (GSList const *i = items; i != NULL; i = i->next) {
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
//FIXME: see above
if (kind == FILL) {
- sp_repr_css_change_recursive(reinterpret_cast<SPObject*>(i->data)->getRepr(), css, "style");
+ sp_repr_css_change_recursive((*i)->getRepr(), css, "style");
}
if (!vector) {
SPGradient *gr = sp_gradient_vector_for_object( document,
desktop,
- reinterpret_cast<SPObject*>(i->data),
+ reinterpret_cast<SPObject*>(*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(*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(*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(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
//FIXME: see above
if (kind == FILL) {
- sp_repr_css_change_recursive(reinterpret_cast<SPObject*>(i->data)->getRepr(), css, "style");
+ sp_repr_css_change_recursive((*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(*i, vector, gradient_type, (kind == FILL) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE);
psel->pushAttrsToGradient( gr );
}
}
@@ -625,7 +621,7 @@ void FillNStroke::updateFromPaint()
case SPPaintSelector::MODE_PATTERN:
- if (items) {
+ if (!items.empty()) {
SPPattern *pattern = psel->getPattern();
if (!pattern) {
@@ -648,12 +644,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<SPObject*>(i->data)->getRepr();
+ for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
+ Inkscape::XML::Node *selrepr = (*i)->getRepr();
if ( (kind == STROKE) && !selrepr) {
continue;
}
- SPObject *selobj = reinterpret_cast<SPObject*>(i->data);
+ SPObject *selobj = *i;
SPStyle *style = selobj->style;
if (style && ((kind == FILL) ? style->fill : style->stroke).isPaintserver()) {
@@ -686,7 +682,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..6743dd23a 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);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ gr_apply_gradient_to_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
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = *i;
SPStyle *style = item->style;
if (style && (style->fill.isPaintserver())) {
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);
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/icontheme.h>
#include <cstring>
#include <glib.h>
diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp
index bf406e632..1af55d9cd 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_type = SP_MESH_TYPE_COONS;
- for (GSList const* i = selection->itemList(); i; i = i->next) {
- SPItem *item = SP_ITEM(i->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = *i;
SPStyle *style = item->style;
if (style && (style->fill.isPaintserver())) {
@@ -213,8 +214,9 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMesh *&ms_sel
{
SPMesh *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
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = *i;// get the items gradient, not the getVector() version
SPStyle *style = item->style;
SPPaintServer *server = 0;
diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp
index 948c80db3..221344296 100644
--- a/src/widgets/paint-selector.cpp
+++ b/src/widgets/paint-selector.cpp
@@ -24,10 +24,6 @@
#include <cstring>
#include <string>
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include "widgets/swatch-selector.h"
#include "sp-pattern.h"
#include <glibmm/i18n.h>
@@ -39,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 <inkscape.h>
@@ -662,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);
@@ -697,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), _("<b>Flat color</b>"));
diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp
index 46f6d1c23..96ba699dc 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)) {
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::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 {
- SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL);
+ (*i)->getRepr()->setAttribute(value_name, NULL);
}
modmade = true;
}
@@ -242,12 +243,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<SPItem *>(items->data))) {
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ if (SP_IS_RECT(*i)) {
n_selected++;
- item = reinterpret_cast<SPItem *>(items->data);
+ item = *i;
repr = item->getRepr();
}
}
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/button.h>
#include <gtk/gtk.h>
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/widget.h>
#include <stddef.h>
#include <sigc++/connection.h>
diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp
index 3fb0015c1..751a60f06 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<SPItem*>(items->data);
+ std::vector<SPItem*> itemlist=desktop->getSelection()->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<SPItem*>(items->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = *i;
if (SP_IS_SPIRAL(item)) {
n_selected++;
repr = item->getRepr();
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 <cstring>
#include <string>
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/label.h>
diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp
index cf12391c1..96005d7df 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<SPItem*>(items->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<SPItem *>(items->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<SPItem *>(items->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<SPItem*>(items->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<SPItem *>(items->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *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<SPItem *>(items->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ SPItem *item = *i;
if (SP_IS_STAR(item)) {
n_selected++;
repr = item->getRepr();
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/combobox.h>
#include <gtkmm/liststore.h>
diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp
index 5ca06a795..482ca7af4 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<SPItem *>(items->data);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();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 <path>
continue;
}
@@ -901,8 +901,8 @@ StrokeStyle::updateLine()
if (!sel || sel->isEmpty())
return;
- GSList const *objects = sel->itemList();
- SPObject * const object = SP_OBJECT(objects->data);
+ std::vector<SPItem*> const objects = sel->itemList();
+ SPObject * const object = objects[0];
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();
+ std::vector<SPItem*> 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(std::vector<SPItem*>::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 = (*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 ((*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(std::vector<SPItem*> const &objects)
{
struct { MarkerComboBox *key; int loc; } const keyloc[] = {
{ startMarkerCombo, SP_MARKER_LOC_START },
@@ -1153,9 +1152,10 @@ 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(std::vector<SPItem*>::const_iterator i=objects.begin();i!=objects.end();i++){
+ if (!SP_IS_TEXT (*i)) {
all_texts = false;
+ break;
}
}
@@ -1167,7 +1167,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 = objects[0];
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..2605e1acf 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(std::vector<SPItem*> const &objects);
void updateMarkerHist(SPMarkerLoc const which);
void setDashSelectorFromStyle(SPDashSelector *dsel, SPStyle *style);
void setJoinType (unsigned const jointype);
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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
class SPDocument;
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index 3d2e6eef8..7b22e4af7 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
@@ -366,9 +372,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);
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();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
@@ -517,11 +524,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));
+ std::vector<SPItem*> itemlist=selection->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
+ if (SP_IS_TEXT (*i)) {
+ (*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL));
modmade = true;
}
}
@@ -863,12 +870,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) {
+ std::vector<SPItem*> itemlist=SP_ACTIVE_DESKTOP->getSelection()->itemList();
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
// const gchar* id = reinterpret_cast<SPItem *>(items->data)->getId();
// std::cout << " " << id << std::endl;
- if( SP_IS_FLOWTEXT(SP_ITEM(items->data))) {
+ if( SP_IS_FLOWTEXT(*i)) {
isFlow = true;
// std::cout << " Found flowed text" << std::endl;
break;
@@ -1153,14 +1159,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;
+ std::vector<SPItem*> 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);
+ std::vector<SPItem*> x,y;
+ std::vector<SPItem*> allList = get_all_items(x, document->getRoot(), desktop, false, false, true, y);
+ for(std::vector<SPItem*>::const_reverse_iterator i=allList.rbegin();i!=allList.rend();i++){
+ SPItem *item = *i;
SPStyle *style = item->style;
if (style) {
@@ -1177,7 +1183,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_back(item);
}
}
}
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 <glibmm/threads.h>
-#endif
-
#include <gtkmm/box.h>
#include <gtkmm/action.h>
#include <gtkmm/actiongroup.h>
diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp
index 7c5d2d6fc..4cbe930a1 100644
--- a/src/xml/repr-util.cpp
+++ b/src/xml/repr-util.cpp
@@ -310,6 +310,11 @@ int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::No
pjrm */
}
+bool sp_repr_compare_position_bool(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second){
+ return sp_repr_compare_position(first, second)<0;
+}
+
+
/**
* Find an element node using an unique attribute.
*
diff --git a/src/xml/repr.h b/src/xml/repr.h
index c3ba40e45..17763195a 100644
--- a/src/xml/repr.h
+++ b/src/xml/repr.h
@@ -120,7 +120,9 @@ unsigned sp_repr_set_svg_length(Inkscape::XML::Node *repr, char const *key, SVGL
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);
+//c++-style comparison : returns (bool)(a<b)
int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second);
+bool sp_repr_compare_position_bool(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second);
// Searching
/**