diff options
Diffstat (limited to 'src/style.cpp')
| -rw-r--r-- | src/style.cpp | 5177 |
1 files changed, 907 insertions, 4270 deletions
diff --git a/src/style.cpp b/src/style.cpp index bc869b127..11b1dc440 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -14,6 +14,7 @@ * Copyright (C) 2001 Ximian, Inc. * Copyright (C) 2005 Monash University * Copyright (C) 2012 Kris De Gussem + * Copyright (C) 2014 Tavmjong Bah * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -24,6 +25,7 @@ #include <cstring> #include <string> +#include <algorithm> #include "libcroco/cr-sel-eng.h" #include "xml/croco-node-iface.h" @@ -65,925 +67,541 @@ using std::vector; struct SPStyleEnum; +int SPStyle::_count = 0; + /*######################### ## FORWARD DECLARATIONS #########################*/ -static void sp_style_clear(SPStyle *style); - -static void sp_style_merge_property(SPStyle *style, gint id, gchar const *val); - -static void sp_style_merge_ipaint(SPStyle *style, SPIPaint *paint, SPIPaint const *parent); -static void sp_style_merge_ifilter(SPStyle *style, SPIFilter const *parent); -static void sp_style_read_dash(SPStyle *style, gchar const *str); - -static SPTextStyle *sp_text_style_new(void); -static void sp_text_style_clear(SPTextStyle *ts); -static SPTextStyle *sp_text_style_unref(SPTextStyle *st); -static SPTextStyle *sp_text_style_duplicate_unset(SPTextStyle *st); -static guint sp_text_style_write(gchar *p, guint len, SPTextStyle const *st, guint flags = SP_STYLE_FLAG_IFSET); -static void sp_style_privatize_text(SPStyle *style); - -static void sp_style_read_ifloat(SPIFloat *val, gchar const *str); -static void sp_style_read_iscale24(SPIScale24 *val, gchar const *str); -static void sp_style_read_ienum(SPIEnum *val, gchar const *str, SPStyleEnum const *dict, bool can_explicitly_inherit); -static void sp_style_read_istring(SPIString *val, gchar const *str); -static void sp_style_read_ilength(SPILength *val, gchar const *str); -static void sp_style_read_ilengthornormal(SPILengthOrNormal *val, gchar const *str); - -static void sp_style_read_ipaintorder(SPIPaintOrder *val, gchar const *str); - -static void sp_style_read_itextdecoration(SPITextDecorationLine *line, SPITextDecorationStyle *style, SPIPaint *color, gchar const *str); -static void sp_style_read_itextdecorationLine(SPITextDecorationLine *line, gchar const *str); -static void sp_style_read_itextdecorationStyle(SPITextDecorationStyle *style, gchar const *str); -static void sp_style_read_itextdecorationColor(SPIPaint *color, gchar const *str); - -static void sp_style_read_icolor(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocument *document); -static void sp_style_read_ifontsize(SPIFontSize *val, gchar const *str); -static void sp_style_read_ibaselineshift(SPIBaselineShift *val, gchar const *str); -static void sp_style_read_ifilter(gchar const *str, SPStyle *style, SPDocument *document); - -static void sp_style_read_penum(SPIEnum *val, Inkscape::XML::Node *repr, gchar const *key, SPStyleEnum const *dict, bool can_explicitly_inherit); -static void sp_style_read_plength(SPILength *val, Inkscape::XML::Node *repr, gchar const *key); -static void sp_style_read_pfontsize(SPIFontSize *val, Inkscape::XML::Node *repr, gchar const *key); -static void sp_style_read_pbaselineshift(SPIBaselineShift *val, Inkscape::XML::Node *repr, gchar const *key); -static void sp_style_read_pfloat(SPIFloat *val, Inkscape::XML::Node *repr, gchar const *key); - -static gint sp_style_write_ifloat(gchar *p, gint len, gchar const *key, SPIFloat const *val, SPIFloat const *base, guint flags); -static gint sp_style_write_iscale24(gchar *p, gint len, gchar const *key, SPIScale24 const *val, SPIScale24 const *base, guint flags); -static gint sp_style_write_ienum(gchar *p, gint len, gchar const *key, SPStyleEnum const *dict, SPIEnum const *val, SPIEnum const *base, guint flags); -static gint sp_style_write_istring(gchar *p, gint len, gchar const *key, SPIString const *val, SPIString const *base, guint flags); -static gint sp_style_write_ilength(gchar *p, gint len, gchar const *key, SPILength const *val, SPILength const *base, guint flags); -static gint sp_style_write_ipaint(gchar *b, gint len, gchar const *key, SPIPaint const *paint, SPIPaint const *base, guint flags); -static gint sp_style_write_ipaintorder(gchar *p, gint len, gchar const *key, SPIPaintOrder const *paint_order, SPIPaintOrder const *base, guint flags); -static gint sp_style_write_idasharray(gchar *p, gint const len, gchar const *const key, SPIDashArray const *const val, SPIDashArray const *const base, guint const flags); - -static gint sp_style_write_ifontsize(gchar *p, gint len, gchar const *key, SPIFontSize const *val, SPIFontSize const *base, guint flags); -static gint sp_style_write_ibaselineshift(gchar *p, gint len, gchar const *key, SPIBaselineShift const *val, SPIBaselineShift const *base, guint flags); -static gint sp_style_write_ilengthornormal(gchar *p, gint const len, gchar const *const key, SPILengthOrNormal const *const val, SPILengthOrNormal const *const base, guint const flags); -static gint sp_style_write_itextdecoration(gchar *p, gint const len, gchar const *const key, - SPITextDecorationLine const *const line, - SPITextDecorationStyle const *const style, - SPIPaint const *const color, - SPITextDecorationLine const *const baseLine, - SPITextDecorationStyle const *const baseStyle, - SPIPaint const *const baseColor, - guint const flags); -static gint sp_style_write_ifilter(gchar *b, gint len, gchar const *key, SPIFilter const *filter, SPIFilter const *base, guint flags); - -static void sp_style_filter_clear(SPStyle *style); - -#define SPS_READ_IENUM_IF_UNSET(v,s,d,i) if (!(v)->set) {sp_style_read_ienum((v), (s), (d), (i));} -#define SPS_READ_PENUM_IF_UNSET(v,r,k,d,i) if (!(v)->set) {sp_style_read_penum((v), (r), (k), (d), (i));} - -#define SPS_READ_ILENGTH_IF_UNSET(v,s) if (!(v)->set) {sp_style_read_ilength((v), (s));} -#define SPS_READ_PLENGTH_IF_UNSET(v,r,k) if (!(v)->set) {sp_style_read_plength((v), (r), (k));} - -#define SPS_READ_PFLOAT_IF_UNSET(v,r,k) if (!(v)->set) {sp_style_read_pfloat((v), (r), (k));} - -#define SPS_READ_IFONTSIZE_IF_UNSET(v,s) if (!(v)->set) {sp_style_read_ifontsize((v), (s));} -#define SPS_READ_PFONTSIZE_IF_UNSET(v,r,k) if (!(v)->set) {sp_style_read_pfontsize((v), (r), (k));} - -#define SPS_READ_IBASELINE_SHIFT_IF_UNSET(v,s) if (!(v)->set) {sp_style_read_ibaselineshift((v), (s));} -#define SPS_READ_PBASELINE_SHIFT_IF_UNSET(v,r,k) if (!(v)->set) {sp_style_read_pbaselineshift((v), (r), (k));} - -static void sp_style_merge_from_object_stylesheet(SPStyle *, SPObject const *); - -struct SPStyleEnum { - gchar const *key; - gint value; -}; - -static SPStyleEnum const enum_fill_rule[] = { - {"nonzero", SP_WIND_RULE_NONZERO}, - {"evenodd", SP_WIND_RULE_EVENODD}, - {NULL, -1} -}; - -static SPStyleEnum const enum_stroke_linecap[] = { - {"butt", SP_STROKE_LINECAP_BUTT}, - {"round", SP_STROKE_LINECAP_ROUND}, - {"square", SP_STROKE_LINECAP_SQUARE}, - {NULL, -1} -}; - -static SPStyleEnum const enum_stroke_linejoin[] = { - {"miter", SP_STROKE_LINEJOIN_MITER}, - {"round", SP_STROKE_LINEJOIN_ROUND}, - {"bevel", SP_STROKE_LINEJOIN_BEVEL}, - {NULL, -1} -}; - -static SPStyleEnum const enum_font_style[] = { - {"normal", SP_CSS_FONT_STYLE_NORMAL}, - {"italic", SP_CSS_FONT_STYLE_ITALIC}, - {"oblique", SP_CSS_FONT_STYLE_OBLIQUE}, - {NULL, -1} -}; - -static SPStyleEnum const enum_font_size[] = { - {"xx-small", SP_CSS_FONT_SIZE_XX_SMALL}, - {"x-small", SP_CSS_FONT_SIZE_X_SMALL}, - {"small", SP_CSS_FONT_SIZE_SMALL}, - {"medium", SP_CSS_FONT_SIZE_MEDIUM}, - {"large", SP_CSS_FONT_SIZE_LARGE}, - {"x-large", SP_CSS_FONT_SIZE_X_LARGE}, - {"xx-large", SP_CSS_FONT_SIZE_XX_LARGE}, - {"smaller", SP_CSS_FONT_SIZE_SMALLER}, - {"larger", SP_CSS_FONT_SIZE_LARGER}, - {NULL, -1} -}; - -static SPStyleEnum const enum_font_variant[] = { - {"normal", SP_CSS_FONT_VARIANT_NORMAL}, - {"small-caps", SP_CSS_FONT_VARIANT_SMALL_CAPS}, - {NULL, -1} -}; - -static SPStyleEnum const enum_font_weight[] = { - {"100", SP_CSS_FONT_WEIGHT_100}, - {"200", SP_CSS_FONT_WEIGHT_200}, - {"300", SP_CSS_FONT_WEIGHT_300}, - {"400", SP_CSS_FONT_WEIGHT_400}, - {"500", SP_CSS_FONT_WEIGHT_500}, - {"600", SP_CSS_FONT_WEIGHT_600}, - {"700", SP_CSS_FONT_WEIGHT_700}, - {"800", SP_CSS_FONT_WEIGHT_800}, - {"900", SP_CSS_FONT_WEIGHT_900}, - {"normal", SP_CSS_FONT_WEIGHT_NORMAL}, - {"bold", SP_CSS_FONT_WEIGHT_BOLD}, - {"lighter", SP_CSS_FONT_WEIGHT_LIGHTER}, - {"bolder", SP_CSS_FONT_WEIGHT_BOLDER}, - {NULL, -1} -}; - -static SPStyleEnum const enum_font_stretch[] = { - {"ultra-condensed", SP_CSS_FONT_STRETCH_ULTRA_CONDENSED}, - {"extra-condensed", SP_CSS_FONT_STRETCH_EXTRA_CONDENSED}, - {"condensed", SP_CSS_FONT_STRETCH_CONDENSED}, - {"semi-condensed", SP_CSS_FONT_STRETCH_SEMI_CONDENSED}, - {"normal", SP_CSS_FONT_STRETCH_NORMAL}, - {"semi-expanded", SP_CSS_FONT_STRETCH_SEMI_EXPANDED}, - {"expanded", SP_CSS_FONT_STRETCH_EXPANDED}, - {"extra-expanded", SP_CSS_FONT_STRETCH_EXTRA_EXPANDED}, - {"ultra-expanded", SP_CSS_FONT_STRETCH_ULTRA_EXPANDED}, - {"narrower", SP_CSS_FONT_STRETCH_NARROWER}, - {"wider", SP_CSS_FONT_STRETCH_WIDER}, - {NULL, -1} -}; - -static SPStyleEnum const enum_text_align[] = { - {"start", SP_CSS_TEXT_ALIGN_START}, - {"end", SP_CSS_TEXT_ALIGN_END}, - {"left", SP_CSS_TEXT_ALIGN_LEFT}, - {"right", SP_CSS_TEXT_ALIGN_RIGHT}, - {"center", SP_CSS_TEXT_ALIGN_CENTER}, - {"justify", SP_CSS_TEXT_ALIGN_JUSTIFY}, - {NULL, -1} -}; - -static SPStyleEnum const enum_text_transform[] = { - {"capitalize", SP_CSS_TEXT_TRANSFORM_CAPITALIZE}, - {"uppercase", SP_CSS_TEXT_TRANSFORM_UPPERCASE}, - {"lowercase", SP_CSS_TEXT_TRANSFORM_LOWERCASE}, - {"none", SP_CSS_TEXT_TRANSFORM_NONE}, - {NULL, -1} -}; - -static SPStyleEnum const enum_text_anchor[] = { - {"start", SP_CSS_TEXT_ANCHOR_START}, - {"middle", SP_CSS_TEXT_ANCHOR_MIDDLE}, - {"end", SP_CSS_TEXT_ANCHOR_END}, - {NULL, -1} -}; - -static SPStyleEnum const enum_direction[] = { - {"ltr", SP_CSS_DIRECTION_LTR}, - {"rtl", SP_CSS_DIRECTION_RTL}, - {NULL, -1} -}; - -static SPStyleEnum const enum_block_progression[] = { - {"tb", SP_CSS_BLOCK_PROGRESSION_TB}, - {"rl", SP_CSS_BLOCK_PROGRESSION_RL}, - {"lr", SP_CSS_BLOCK_PROGRESSION_LR}, - {NULL, -1} -}; - -static SPStyleEnum const enum_writing_mode[] = { - /* Note that using the same enumerator for lr as lr-tb means we write as lr-tb even if the - * input file said lr. We prefer writing lr-tb on the grounds that the spec says the initial - * value is lr-tb rather than lr. - * - * ECMA scripts may be surprised to find tb-rl in DOM if they set the attribute to rl, so - * sharing enumerators for different strings may be a bug (once we support ecma script). - */ - {"lr-tb", SP_CSS_WRITING_MODE_LR_TB}, - {"rl-tb", SP_CSS_WRITING_MODE_RL_TB}, - {"tb-rl", SP_CSS_WRITING_MODE_TB_RL}, - {"lr", SP_CSS_WRITING_MODE_LR_TB}, - {"rl", SP_CSS_WRITING_MODE_RL_TB}, - {"tb", SP_CSS_WRITING_MODE_TB_RL}, - {NULL, -1} -}; - -static SPStyleEnum const enum_baseline_shift[] = { - {"baseline", SP_CSS_BASELINE_SHIFT_BASELINE}, - {"sub", SP_CSS_BASELINE_SHIFT_SUB}, - {"super", SP_CSS_BASELINE_SHIFT_SUPER}, - {NULL, -1} -}; - -static SPStyleEnum const enum_visibility[] = { - {"hidden", SP_CSS_VISIBILITY_HIDDEN}, - {"collapse", SP_CSS_VISIBILITY_COLLAPSE}, - {"visible", SP_CSS_VISIBILITY_VISIBLE}, - {NULL, -1} -}; - -static SPStyleEnum const enum_overflow[] = { - {"visible", SP_CSS_OVERFLOW_VISIBLE}, - {"hidden", SP_CSS_OVERFLOW_HIDDEN}, - {"scroll", SP_CSS_OVERFLOW_SCROLL}, - {"auto", SP_CSS_OVERFLOW_AUTO}, - {NULL, -1} -}; - -// CSS Compositing and Blending Level 1 -static SPStyleEnum const enum_isolation[] = { - {"auto", SP_CSS_ISOLATION_AUTO}, - {"isolate", SP_CSS_ISOLATION_ISOLATE}, - {NULL, -1} -}; - -static SPStyleEnum const enum_blend_mode[] = { - {"normal", SP_CSS_BLEND_NORMAL}, - {"multiply", SP_CSS_BLEND_MULTIPLY}, - {"screen", SP_CSS_BLEND_SCREEN}, - {"darken", SP_CSS_BLEND_DARKEN}, - {"lighten", SP_CSS_BLEND_LIGHTEN}, - {"overlay", SP_CSS_BLEND_OVERLAY}, - {"color-dodge", SP_CSS_BLEND_COLORDODGE}, - {"color-burn", SP_CSS_BLEND_COLORBURN}, - {"hard-light", SP_CSS_BLEND_HARDLIGHT}, - {"soft-light", SP_CSS_BLEND_SOFTLIGHT}, - {"difference", SP_CSS_BLEND_DIFFERENCE}, - {"exclusion", SP_CSS_BLEND_EXCLUSION}, - {"hue", SP_CSS_BLEND_HUE}, - {"saturation", SP_CSS_BLEND_SATURATION}, - {"color", SP_CSS_BLEND_COLOR}, - {"luminosity", SP_CSS_BLEND_LUMINOSITY}, - {NULL, -1} -}; - -static SPStyleEnum const enum_display[] = { - {"none", SP_CSS_DISPLAY_NONE}, - {"inline", SP_CSS_DISPLAY_INLINE}, - {"block", SP_CSS_DISPLAY_BLOCK}, - {"list-item", SP_CSS_DISPLAY_LIST_ITEM}, - {"run-in", SP_CSS_DISPLAY_RUN_IN}, - {"compact", SP_CSS_DISPLAY_COMPACT}, - {"marker", SP_CSS_DISPLAY_MARKER}, - {"table", SP_CSS_DISPLAY_TABLE}, - {"inline-table", SP_CSS_DISPLAY_INLINE_TABLE}, - {"table-row-group", SP_CSS_DISPLAY_TABLE_ROW_GROUP}, - {"table-header-group", SP_CSS_DISPLAY_TABLE_HEADER_GROUP}, - {"table-footer-group", SP_CSS_DISPLAY_TABLE_FOOTER_GROUP}, - {"table-row", SP_CSS_DISPLAY_TABLE_ROW}, - {"table-column-group", SP_CSS_DISPLAY_TABLE_COLUMN_GROUP}, - {"table-column", SP_CSS_DISPLAY_TABLE_COLUMN}, - {"table-cell", SP_CSS_DISPLAY_TABLE_CELL}, - {"table-caption", SP_CSS_DISPLAY_TABLE_CAPTION}, - {NULL, -1} -}; - -static SPStyleEnum const enum_shape_rendering[] = { - {"auto", SP_CSS_SHAPE_RENDERING_AUTO}, - {"optimizeSpeed", SP_CSS_SHAPE_RENDERING_OPTIMIZESPEED}, - {"crispEdges", SP_CSS_SHAPE_RENDERING_CRISPEDGES}, - {"geometricPrecision", SP_CSS_SHAPE_RENDERING_GEOMETRICPRECISION}, - {NULL, -1} -}; - -static SPStyleEnum const enum_color_rendering[] = { - {"auto", SP_CSS_COLOR_RENDERING_AUTO}, - {"optimizeSpeed", SP_CSS_COLOR_RENDERING_OPTIMIZESPEED}, - {"optimizeQuality", SP_CSS_COLOR_RENDERING_OPTIMIZEQUALITY}, - {NULL, -1} -}; - -static SPStyleEnum const enum_image_rendering[] = { - {"auto", SP_CSS_IMAGE_RENDERING_AUTO}, - {"optimizeSpeed", SP_CSS_IMAGE_RENDERING_OPTIMIZESPEED}, - {"optimizeQuality", SP_CSS_IMAGE_RENDERING_OPTIMIZEQUALITY}, - {"-inkscape-crisp-edges", SP_CSS_IMAGE_RENDERING_CRISPEDGES}, - {"-inkscape-pixelated", SP_CSS_IMAGE_RENDERING_PIXELATED}, - {NULL, -1} -}; - -static SPStyleEnum const enum_text_rendering[] = { - {"auto", SP_CSS_TEXT_RENDERING_AUTO}, - {"optimizeSpeed", SP_CSS_TEXT_RENDERING_OPTIMIZESPEED}, - {"optimizeLegibility", SP_CSS_TEXT_RENDERING_OPTIMIZELEGIBILITY}, - {"geometricPrecision", SP_CSS_TEXT_RENDERING_GEOMETRICPRECISION}, - {NULL, -1} -}; - -static SPStyleEnum const enum_enable_background[] = { - {"accumulate", SP_CSS_BACKGROUND_ACCUMULATE}, - {"new", SP_CSS_BACKGROUND_NEW}, - {NULL, -1} -}; - -static SPStyleEnum const enum_clip_rule[] = { - {"nonzero", SP_WIND_RULE_NONZERO}, - {"evenodd", SP_WIND_RULE_EVENODD}, - {NULL, -1} -}; - -static SPStyleEnum const enum_color_interpolation[] = { - {"auto", SP_CSS_COLOR_INTERPOLATION_AUTO}, - {"sRGB", SP_CSS_COLOR_INTERPOLATION_SRGB}, - {"linearRGB", SP_CSS_COLOR_INTERPOLATION_LINEARRGB}, - {NULL, -1} -}; +void sp_style_filter_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style); +void sp_style_fill_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style); +void sp_style_stroke_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style); + +static void sp_style_object_release(SPObject *object, SPStyle *style); +static CRSelEng *sp_repr_sel_eng(); + + +//SPPropMap SPStyle::_propmap; + +// C++11 allows one constructor to call another... might be useful. The original C code +// had separate calls to create SPStyle, one with only SPDocument and the other with only +// SPObject as parameters. +SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : + + // Unimplemented SVG 1.1: alignment-baseline, clip, clip-path, color-profile, cursor, + // dominant-baseline, flood-color, flood-opacity, font-size-adjust, + // glyph-orientation-horizontal, glyph-orientation-vertical, kerning, lighting-color, + // pointer-events, stop-color, stop-opacity, unicode-bidi + + // For enums: property( name, enumeration, default value , inherits = true ); + // For scale24: property( name, default value = 0, inherits = true ); + + // 'font', 'font-size', and 'font-family' must come first as other properties depend on them + // for calculated values (through 'em' and 'ex'). ('ex' is currently not read.) + // The following properties can depend on 'em' and 'ex': + // baseline-shift, kerning, letter-spacing, stroke-dash-offset, stroke-width, word-spacing, + // Non-SVG 1.1: text-indent, line-spacing + + // Hidden in SPIFontStyle: (to be refactored) + // font-family + // font-specification + + // Font related properties and 'font' shorthand + font_style( "font-style", enum_font_style, SP_CSS_FONT_STYLE_NORMAL ), + font_variant( "font-variant", enum_font_variant, SP_CSS_FONT_VARIANT_NORMAL ), + font_weight( "font-weight", enum_font_weight, SP_CSS_FONT_WEIGHT_NORMAL, SP_CSS_FONT_WEIGHT_400 ), + font_stretch( "font-stretch", enum_font_stretch, SP_CSS_FONT_STRETCH_NORMAL ), + font_size(), + line_height( "line-height", 1.0 ), // SPILengthOrNormal + font_family( "font-family", "sans-serif" ), // SPIString w/default + font(), // SPIFont + font_specification( "-inkscape-font-specification" ), // SPIString + + // Text related properties + text_indent( "text-indent", 0.0 ), // SPILength + text_align( "text-align", enum_text_align, SP_CSS_TEXT_ALIGN_START ), + text_decoration(), + text_decoration_line(), + text_decoration_style(), + text_decoration_color( "text-decoration-color" ), // SPIColor + + letter_spacing( "letter-spacing", 0.0 ), // SPILengthOrNormal + word_spacing( "word-spacing", 0.0 ), // SPILengthOrNormal + text_transform( "text-transform", enum_text_transform, SP_CSS_TEXT_TRANSFORM_NONE ), + + direction( "direction", enum_direction, SP_CSS_DIRECTION_LTR ), + block_progression("block-progression", enum_block_progression, SP_CSS_BLOCK_PROGRESSION_TB), + writing_mode( "writing-mode", enum_writing_mode, SP_CSS_WRITING_MODE_LR_TB ), + baseline_shift(), + text_anchor( "text-anchor", enum_text_anchor, SP_CSS_TEXT_ANCHOR_START ), + + // General visual properties + clip_rule( "clip-rule", enum_clip_rule, SP_WIND_RULE_NONZERO ), + display( "display", enum_display, SP_CSS_DISPLAY_INLINE, false ), + overflow( "overflow", enum_overflow, SP_CSS_OVERFLOW_VISIBLE, false ), + visibility( "visibility", enum_visibility, SP_CSS_VISIBILITY_VISIBLE ), + opacity( "opacity", SP_SCALE24_MAX, false ), + + isolation( "isolation", enum_isolation, SP_CSS_ISOLATION_AUTO ), + blend_mode( "blend_mode", enum_blend_mode, SP_CSS_BLEND_NORMAL ), + + paint_order(), // SPIPaintOrder + + // Color properties + color( "color" ), // SPIColor + color_interpolation( "color-interpolation", enum_color_interpolation, SP_CSS_COLOR_INTERPOLATION_SRGB), + color_interpolation_filters("color-interpolation-filters", enum_color_interpolation, SP_CSS_COLOR_INTERPOLATION_LINEARRGB), + + // Fill properties + fill( "fill" ), // SPIPaint + fill_opacity( "fill-opacity", SP_SCALE24_MAX ), + fill_rule( "fill-rule", enum_fill_rule, SP_WIND_RULE_NONZERO ), + + // Stroke properites + stroke( "stroke" ), // SPIPaint + stroke_width( "stroke-width", 1.0 ), // SPILength + stroke_linecap( "stroke-linecap", enum_stroke_linecap, SP_STROKE_LINECAP_BUTT ), + stroke_linejoin( "stroke-linejoin", enum_stroke_linejoin, SP_STROKE_LINEJOIN_MITER ), + stroke_miterlimit("stroke-miterlimit", 4 ), // SPIFloat (only use of float!) + stroke_dasharray(), // SPIDashArray + stroke_dashoffset("stroke-dashoffset", 0.0 ), // SPILength for now + + stroke_opacity( "stroke-opacity", SP_SCALE24_MAX ), + + marker( "marker" ), // SPIString + marker_start( "marker-start" ), // SPIString + marker_mid( "marker-mid" ), // SPIString + marker_end( "marker-end" ), // SPIString + + // Filter properties + filter(), + filter_blend_mode("filter-blend-mode", enum_blend_mode, SP_CSS_BLEND_NORMAL), + filter_gaussianBlur_deviation( "filter-gaussianBlur-deviation", 0.0 ), // SPILength + enable_background("enable-background", enum_enable_background, SP_CSS_BACKGROUND_ACCUMULATE, false), + + // Rendering hint properties + color_rendering( "color-rendering", enum_color_rendering, SP_CSS_COLOR_RENDERING_AUTO), + image_rendering( "image-rendering", enum_image_rendering, SP_CSS_IMAGE_RENDERING_AUTO), + shape_rendering( "shape-rendering", enum_shape_rendering, SP_CSS_SHAPE_RENDERING_AUTO), + text_rendering( "text-rendering", enum_text_rendering, SP_CSS_TEXT_RENDERING_AUTO ) + +{ + // std::cout << "SPStyle::SPStyle( SPDocument ): Entrance: (" << _count << ")" << std::endl; + // std::cout << " Document: " << (document_in?"present":"null") << std::endl; + // std::cout << " Object: " + // << (object_in?(object_in->getId()?object_in->getId():"id null"):"object null") << std::endl; + + // static bool first = true; + // if( first ) { + // std::cout << "Size of SPStyle: " << sizeof(SPStyle) << std::endl; + // std::cout << " SPIBase: " << sizeof(SPIBase) << std::endl; + // std::cout << " SPIFloat: " << sizeof(SPIFloat) << std::endl; + // std::cout << " SPIScale24: " << sizeof(SPIScale24) << std::endl; + // std::cout << " SPILength: " << sizeof(SPILength) << std::endl; + // std::cout << " SPILengthOrNormal: " << sizeof(SPILengthOrNormal) << std::endl; + // std::cout << " SPIColor: " << sizeof(SPIColor) << std::endl; + // std::cout << " SPIPaint: " << sizeof(SPIPaint) << std::endl; + // std::cout << " SPITextDecorationLine" << sizeof(SPITextDecorationLine) << std::endl; + // std::cout << " Glib::ustring:" << sizeof(Glib::ustring) << std::endl; + // std::cout << " SPColor: " << sizeof(SPColor) << std::endl; + // first = false; + // } + + ++_count; // Poor man's memory leak detector + + _refcount = 1; + + cloned = false; + + object = object_in; + if( object ) { + g_assert( SP_IS_OBJECT(object) ); + document = object->document; + release_connection = + object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_style_object_release), this)); + + cloned = object->cloned; -/** - * Release callback. - */ -static void -sp_style_object_release(SPObject *object, SPStyle *style) -{ - (void)object; // TODO - style->object = NULL; -} + } else { + document = document_in; + } + + new (&release_connection) sigc::connection(); + new (&filter_modified_connection) sigc::connection(); + new (&fill_ps_modified_connection) sigc::connection(); + new (&stroke_ps_modified_connection) sigc::connection(); + + // 'font' shorthand requires access to included properties. + font.setStylePointer( this ); + + // Properties that depend on 'font-size' for calculating lengths. + baseline_shift.setStylePointer( this ); + text_indent.setStylePointer( this ); + line_height.setStylePointer( this ); + letter_spacing.setStylePointer( this ); + word_spacing.setStylePointer( this ); + stroke_width.setStylePointer( this ); + stroke_dashoffset.setStylePointer( this ); + + // Properties that depend on 'color' + text_decoration_color.setStylePointer( this ); + fill.setStylePointer( this ); + stroke.setStylePointer( this ); + // color.setStylePointer( this ); // Doen't need reference to self + + // 'text_decoration' shorthand requires access to included properties. + text_decoration.setStylePointer( this ); + + // SPIPaint, SPIFilter needs access to 'this' (SPStyle) + // for setting up signals... 'fill', 'stroke' already done + filter.setStylePointer( this ); + + // Used to iterate over markers + marker_ptrs[SP_MARKER_LOC] = ▮ + marker_ptrs[SP_MARKER_LOC_START] = &marker_start; + marker_ptrs[SP_MARKER_LOC_MID] = &marker_mid; + marker_ptrs[SP_MARKER_LOC_END] = &marker_end; + + + // This might be too resource hungary... but for now it possible to loop over properties + + // 'color' must be before 'fill', 'stroke', 'text-decoration-color', ... + _properties.push_back( &color ); + + // 'font-size'/'font' must be before properties that need to know em, ex size (SPILength, + // SPILenghtOrNormal) + _properties.push_back( &font_style ); + _properties.push_back( &font_variant ); + _properties.push_back( &font_weight ); + _properties.push_back( &font_stretch ); + _properties.push_back( &font_size ); + _properties.push_back( &line_height ); + _properties.push_back( &font_family ); + _properties.push_back( &font ); + _properties.push_back( &font_specification ); + + _properties.push_back( &text_indent ); + _properties.push_back( &text_align ); + + _properties.push_back( &text_decoration ); + _properties.push_back( &text_decoration_line ); + _properties.push_back( &text_decoration_style ); + _properties.push_back( &text_decoration_color ); + + _properties.push_back( &letter_spacing ); + _properties.push_back( &word_spacing ); + _properties.push_back( &text_transform ); + + _properties.push_back( &direction ); + _properties.push_back( &block_progression ); + _properties.push_back( &writing_mode ); + _properties.push_back( &baseline_shift ); + _properties.push_back( &text_anchor ); + + _properties.push_back( &clip_rule ); + _properties.push_back( &display ); + _properties.push_back( &overflow ); + _properties.push_back( &visibility ); + _properties.push_back( &opacity ); + + _properties.push_back( &isolation ); + _properties.push_back( &blend_mode ); + + _properties.push_back( &color_interpolation ); + _properties.push_back( &color_interpolation_filters ); + + _properties.push_back( &fill ); + _properties.push_back( &fill_opacity ); + _properties.push_back( &fill_rule ); + + _properties.push_back( &stroke ); + _properties.push_back( &stroke_width ); + _properties.push_back( &stroke_linecap ); + _properties.push_back( &stroke_linejoin ); + _properties.push_back( &stroke_miterlimit ); + _properties.push_back( &stroke_dasharray ); + _properties.push_back( &stroke_dashoffset ); + _properties.push_back( &stroke_opacity ); + + _properties.push_back( &marker ); + _properties.push_back( &marker_start ); + _properties.push_back( &marker_mid ); + _properties.push_back( &marker_end ); + + _properties.push_back( &paint_order ); + + _properties.push_back( &filter ); + _properties.push_back( &filter_blend_mode ); + _properties.push_back( &filter_gaussianBlur_deviation ); + + _properties.push_back( &color_rendering ); + _properties.push_back( &image_rendering ); + _properties.push_back( &shape_rendering ); + _properties.push_back( &text_rendering ); + + _properties.push_back( &enable_background ); -/** - * Emit style modified signal on style's object if the filter changed. - */ -static void -sp_style_filter_ref_modified(SPObject *obj, guint flags, SPStyle *style) -{ - (void)flags; // TODO - SPFilter *filter=static_cast<SPFilter *>(obj); - if (style->getFilter() == filter) - { - if (style->object) { - style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); - } - } -} + // MAP ------------------------------------------- -/** - * Gets called when the filter is (re)attached to the style - */ -static void -sp_style_filter_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style) -{ - if (old_ref) { - style->filter_modified_connection.disconnect(); - } - if ( SP_IS_FILTER(ref)) - { - style->filter_modified_connection = - ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_filter_ref_modified), style)); - } + // if( _propmap.size() == 0 ) { - sp_style_filter_ref_modified(ref, 0, style); -} + // // 'color' must be before 'fill', 'stroke', 'text-decoration-color', ... + // _propmap.insert( std::make_pair( color.name, reinterpret_cast<SPIBasePtr>(&SPStyle::color ) ) ); -/** - * Emit style modified signal on style's object if server is style's fill - * or stroke paint server. - */ -static void -sp_style_paint_server_ref_modified(SPObject *obj, guint flags, SPStyle *style) -{ - (void)flags; // TODO - SPPaintServer *server = static_cast<SPPaintServer *>(obj); + // // 'font-size' must be before properties that need to know em, ex size (SPILength, SPILenghtOrNormal) + // _propmap.insert( std::make_pair( font_style.name, reinterpret_cast<SPIBasePtr>(&SPStyle::font_style ) ) ); + // _propmap.insert( std::make_pair( font_variant.name, reinterpret_cast<SPIBasePtr>(&SPStyle::font_variant ) ) ); + // _propmap.insert( std::make_pair( font_weight.name, reinterpret_cast<SPIBasePtr>(&SPStyle::font_weight ) ) ); + // _propmap.insert( std::make_pair( font_stretch.name, reinterpret_cast<SPIBasePtr>(&SPStyle::font_stretch ) ) ); + // _propmap.insert( std::make_pair( font_size.name, reinterpret_cast<SPIBasePtr>(&SPStyle::font_size ) ) ); + // _propmap.insert( std::make_pair( line_height.name, reinterpret_cast<SPIBasePtr>(&SPStyle::line_height ) ) ); + // _propmap.insert( std::make_pair( font_family.name, reinterpret_cast<SPIBasePtr>(&SPStyle::font_family ) ) ); + // _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 ) ) ); - if ((style->fill.isPaintserver()) - && style->getFillPaintServer() == server) - { - if (style->object) { - /** \todo - * fixme: I do not know, whether it is optimal - we are - * forcing reread of everything (Lauris) - */ - /** \todo - * fixme: We have to use object_modified flag, because parent - * flag is only available downstreams. - */ - style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); - } - } else if ((style->stroke.isPaintserver()) - && style->getStrokePaintServer() == server) - { - if (style->object) { - /// \todo fixme: - style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); - } - } else if (server) { - g_assert_not_reached(); - } -} + // _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 ) ) ); -/** - * Gets called when the paintserver is (re)attached to the style - */ -static void -sp_style_fill_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style) -{ - if (old_ref) { - style->fill_ps_modified_connection.disconnect(); - } - if (SP_IS_PAINT_SERVER(ref)) { - style->fill_ps_modified_connection = - ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_paint_server_ref_modified), style)); - } + // _propmap.insert( std::make_pair( text_decoration.name, reinterpret_cast<SPIBasePtr>(&SPStyle::text_decoration ) ) ); + // _propmap.insert( std::make_pair( text_decoration_line.name, reinterpret_cast<SPIBasePtr>(&SPStyle::text_decoration_line ) ) ); + // _propmap.insert( std::make_pair( text_decoration_style.name, reinterpret_cast<SPIBasePtr>(&SPStyle::text_decoration_style ) ) ); + // _propmap.insert( std::make_pair( text_decoration_color.name, reinterpret_cast<SPIBasePtr>(&SPStyle::text_decoration_color ) ) ); - sp_style_paint_server_ref_modified(ref, 0, style); -} + // _propmap.insert( std::make_pair( letter_spacing.name, reinterpret_cast<SPIBasePtr>(&SPStyle::letter_spacing ) ) ); + // _propmap.insert( std::make_pair( word_spacing.name, reinterpret_cast<SPIBasePtr>(&SPStyle::word_spacing ) ) ); + // _propmap.insert( std::make_pair( text_transform.name, reinterpret_cast<SPIBasePtr>(&SPStyle::text_transform ) ) ); -/** - * Gets called when the paintserver is (re)attached to the style - */ -static void -sp_style_stroke_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style) -{ - if (old_ref) { - style->stroke_ps_modified_connection.disconnect(); - } - if (SP_IS_PAINT_SERVER(ref)) { - style->stroke_ps_modified_connection = - ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_paint_server_ref_modified), style)); - } + // _propmap.insert( std::make_pair( direction.name, reinterpret_cast<SPIBasePtr>(&SPStyle::direction ) ) ); + // _propmap.insert( std::make_pair( block_progression.name, reinterpret_cast<SPIBasePtr>(&SPStyle::block_progression ) ) ); + // _propmap.insert( std::make_pair( writing_mode.name, reinterpret_cast<SPIBasePtr>(&SPStyle::writing_mode ) ) ); + // _propmap.insert( std::make_pair( baseline_shift.name, reinterpret_cast<SPIBasePtr>(&SPStyle::baseline_shift ) ) ); + // _propmap.insert( std::make_pair( text_anchor.name, reinterpret_cast<SPIBasePtr>(&SPStyle::text_anchor ) ) ); - sp_style_paint_server_ref_modified(ref, 0, style); -} + // _propmap.insert( std::make_pair( clip_rule.name, reinterpret_cast<SPIBasePtr>(&SPStyle::clip_rule ) ) ); + // _propmap.insert( std::make_pair( display.name, reinterpret_cast<SPIBasePtr>(&SPStyle::display ) ) ); + // _propmap.insert( std::make_pair( overflow.name, reinterpret_cast<SPIBasePtr>(&SPStyle::overflow ) ) ); + // _propmap.insert( std::make_pair( visibility.name, reinterpret_cast<SPIBasePtr>(&SPStyle::visibility ) ) ); + // _propmap.insert( std::make_pair( opacity.name, reinterpret_cast<SPIBasePtr>(&SPStyle::opacity ) ) ); -/** - * Returns a new SPStyle object with settings as per sp_style_clear(). - */ -SPStyle * -sp_style_new(SPDocument *document) -{ - SPStyle *const style = g_new0(SPStyle, 1); + // _propmap.insert( std::make_pair( isolation.name, reinterpret_cast<SPIBasePtr>(&SPStyle::isolation ) ) ); + // _propmap.insert( std::make_pair( blend_mode.name, reinterpret_cast<SPIBasePtr>(&SPStyle::blend_mode ) ) ); - style->refcount = 1; - style->object = NULL; - style->document = document; - style->text = sp_text_style_new(); - style->text_private = TRUE; + // _propmap.insert( std::make_pair( color_interpolation.name, reinterpret_cast<SPIBasePtr>(&SPStyle::color_interpolation ) ) ); + // _propmap.insert( std::make_pair( color_interpolation_filters.name, reinterpret_cast<SPIBasePtr>(&SPStyle::color_interpolation_filters ) ) ); - sp_style_clear(style); + // _propmap.insert( std::make_pair( fill.name, reinterpret_cast<SPIBasePtr>(&SPStyle::fill ) ) ); + // _propmap.insert( std::make_pair( fill_opacity.name, reinterpret_cast<SPIBasePtr>(&SPStyle::fill_opacity ) ) ); + // _propmap.insert( std::make_pair( fill_rule.name, reinterpret_cast<SPIBasePtr>(&SPStyle::fill_rule ) ) ); - style->cloned = false; + // _propmap.insert( std::make_pair( stroke.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke ) ) ); + // _propmap.insert( std::make_pair( stroke_width.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke_width ) ) ); + // _propmap.insert( std::make_pair( stroke_linecap.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke_linecap ) ) ); + // _propmap.insert( std::make_pair( stroke_linejoin.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke_linejoin ) ) ); + // _propmap.insert( std::make_pair( stroke_miterlimit.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke_miterlimit ) ) ); + // _propmap.insert( std::make_pair( stroke_dasharray.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke_dasharray ) ) ); + // _propmap.insert( std::make_pair( stroke_dashoffset.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke_dashoffset ) ) ); + // _propmap.insert( std::make_pair( stroke_opacity.name, reinterpret_cast<SPIBasePtr>(&SPStyle::stroke_opacity ) ) ); - new (&style->release_connection) sigc::connection(); - new (&style->filter_modified_connection) sigc::connection(); - new (&style->fill_ps_modified_connection) sigc::connection(); - new (&style->stroke_ps_modified_connection) sigc::connection(); + // _propmap.insert( std::make_pair( marker.name, reinterpret_cast<SPIBasePtr>(&SPStyle::marker ) ) ); + // _propmap.insert( std::make_pair( marker_start.name, reinterpret_cast<SPIBasePtr>(&SPStyle::marker_start ) ) ); + // _propmap.insert( std::make_pair( marker_mid.name, reinterpret_cast<SPIBasePtr>(&SPStyle::marker_mid ) ) ); + // _propmap.insert( std::make_pair( marker_end.name, reinterpret_cast<SPIBasePtr>(&SPStyle::marker_end ) ) ); - return style; + // _propmap.insert( std::make_pair( paint_order.name, reinterpret_cast<SPIBasePtr>(&SPStyle::paint_order ) ) ); + + // _propmap.insert( std::make_pair( filter.name, reinterpret_cast<SPIBasePtr>(&SPStyle::filter ) ) ); + // _propmap.insert( std::make_pair( filter_blend_mode.name, reinterpret_cast<SPIBasePtr>(&SPStyle::filter_blend_mode ) ) ); + // _propmap.insert( std::make_pair( filter_gaussianBlur_deviation.name, reinterpret_cast<SPIBasePtr>(&SPStyle::filter_gaussianBlur_deviation ) ) ); + + // _propmap.insert( std::make_pair( color_rendering.name, reinterpret_cast<SPIBasePtr>(&SPStyle::color_rendering ) ) ); + // _propmap.insert( std::make_pair( image_rendering.name, reinterpret_cast<SPIBasePtr>(&SPStyle::image_rendering ) ) ); + // _propmap.insert( std::make_pair( shape_rendering.name, reinterpret_cast<SPIBasePtr>(&SPStyle::shape_rendering ) ) ); + // _propmap.insert( std::make_pair( text_rendering.name, reinterpret_cast<SPIBasePtr>(&SPStyle::text_rendering ) ) ); + + // _propmap.insert( std::make_pair( enable_background.name, reinterpret_cast<SPIBasePtr>(&SPStyle::enable_background ) ) ); + + // } } +SPStyle::~SPStyle() { -/** - * Creates a new SPStyle object, and attaches it to the specified SPObject. - */ -SPStyle * -sp_style_new_from_object(SPObject *object) -{ - g_return_val_if_fail(object != NULL, NULL); - g_return_val_if_fail(SP_IS_OBJECT(object), NULL); + // std::cout << "SPStyle::~SPStyle" << std::endl; + --_count; // Poor man's memory leak detector. - SPStyle *style = sp_style_new( object->document ); - style->object = object; - style->release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_style_object_release), style)); + // Remove connections + release_connection.disconnect(); + release_connection.~connection(); - if (object->cloned) { - style->cloned = true; + // The following shoud be moved into SPIPaint and SPIFilter + if (fill.value.href) { + fill_ps_modified_connection.disconnect(); } - return style; -} + if (stroke.value.href) { + stroke_ps_modified_connection.disconnect(); + } + if (filter.href) { + filter_modified_connection.disconnect(); + } -/** - * Increase refcount of style. - */ -SPStyle * -sp_style_ref(SPStyle *style) -{ - g_return_val_if_fail(style != NULL, NULL); - g_return_val_if_fail(style->refcount > 0, NULL); + filter_modified_connection.~connection(); + fill_ps_modified_connection.~connection(); + stroke_ps_modified_connection.~connection(); - style->refcount += 1; + _properties.clear(); + //_propmap.clear(); - return style; + // std::cout << "SPStyle::~SPstyle(): Exit\n" << std::endl; } +// Used in SPStyle::clear() +void clear_property( SPIBase* p ) { + p->clear(); +} -/** - * Decrease refcount of style with possible destruction. - */ -SPStyle * -sp_style_unref(SPStyle *style) -{ - g_return_val_if_fail(style != NULL, NULL); - g_return_val_if_fail(style->refcount > 0, NULL); - - style->refcount -= 1; - - if (style->refcount < 1) { - style->release_connection.disconnect(); - style->release_connection.~connection(); - if (style->text) sp_text_style_unref(style->text); - - if (style->fill.value.href) { - style->fill_ps_modified_connection.disconnect(); - delete style->fill.value.href; - style->fill.value.href = NULL; - } - if (style->stroke.value.href) { - style->stroke_ps_modified_connection.disconnect(); - delete style->stroke.value.href; - style->stroke.value.href = NULL; - } - if (style->filter.href) { - style->filter_modified_connection.disconnect(); - delete style->filter.href; - style->filter.href = NULL; - } - - style->filter_modified_connection.~connection(); - style->fill_ps_modified_connection.~connection(); - style->stroke_ps_modified_connection.~connection(); - - style->fill.clear(); - style->stroke.clear(); - sp_style_filter_clear(style); - - style->stroke_dasharray.values.clear(); - - for (unsigned i = SP_MARKER_LOC; i < SP_MARKER_LOC_QTY; i++) { - if (style->marker[i].value) { - g_free(style->marker[i].value); - style->marker[i].value = NULL; - } - } - g_free(style); - return NULL; +// Matches void sp_style_clear(); +void +SPStyle::clear() { + + for_each( _properties.begin(), _properties.end(), clear_property ); + // for(SPPropMap::iterator i = _propmap.begin(); i != _propmap.end(); ++i ) { + // (this->*(i->second)).clear(); + // } + + // Release connection to object, created in sp_style_new_from_object() + release_connection.disconnect(); + + // href->detach() called in fill->clear()... + fill_ps_modified_connection.disconnect(); + if (fill.value.href) { + delete fill.value.href; + fill.value.href = NULL; } - return style; + stroke_ps_modified_connection.disconnect(); + if (stroke.value.href) { + delete stroke.value.href; + stroke.value.href = NULL; + } + filter_modified_connection.disconnect(); + if (filter.href) { + delete filter.href; + filter.href = NULL; + } + + if (document) { + filter.href = new SPFilterReference(document); + filter.href->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_style_filter_ref_changed), this)); + + fill.value.href = new SPPaintServerReference(document); + fill.value.href->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_style_fill_paint_server_ref_changed), this)); + + stroke.value.href = new SPPaintServerReference(document); + stroke.value.href->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_style_stroke_paint_server_ref_changed), this)); + } + + cloned = false; + } -/** - * Reads the various style parameters for an object from repr. - */ -static void -sp_style_read(SPStyle *style, SPObject *object, Inkscape::XML::Node *repr) -{ - g_assert(style != NULL); +// Matches void sp_style_read(SPStyle *style, SPObject *object, Inkscape::XML::Node *repr) +void +SPStyle::read( SPObject *object, Inkscape::XML::Node *repr ) { + + // std::cout << "SPstyle::read( SPObject, Inkscape::XML::Node ): Entrance: " + // << (object?(object->getId()?object->getId():"id null"):"object null") << " " + // << (repr?(repr->name()?repr->name():"no name"):"repr null") + // << std::endl; g_assert(repr != NULL); g_assert(!object || (object->getRepr() == repr)); - sp_style_clear(style); + // // Uncomment to verify that we don't need to call clear. + // std::cout << " Creating temp style for testing" << std::endl; + // SPStyle *temp = new SPStyle(); + // if( !(*temp == *this ) ) std::cout << "SPStyle::read: Need to clear" << std::endl; + // delete temp; + + clear(); // FIXME, If this isn't here, gradient editing stops working. Why? if (object && object->cloned) { - style->cloned = true; + cloned = true; } /* 1. Style attribute */ + // std::cout << " MERGING STYLE ATTRIBUTE" << std::endl; gchar const *val = repr->attribute("style"); - if (val != NULL && *val) { - sp_style_merge_from_style_string(style, val); + if( val != NULL && *val ) { + _mergeString( val ); } + /* 2 Style sheet */ + // std::cout << " MERGING OBJECT STYLESHEET" << std::endl; if (object) { - sp_style_merge_from_object_stylesheet(style, object); + _mergeObjectStylesheet( object ); } else { - /** \todo No stylesheet information. Find out under what circumstances - * this occurs, and handle accordingly. (If we really wanted to, we - * could probably get stylesheets by going through repr->doc.) - */ + // std::cerr << "SPStyle::read: No object! Can not read style sheet" << std::endl; } - /* 2. Presentation attributes */ - /* Attributes are only read in if not already set in a style sheet or style attribute above. */ - - /* CSS2 */ - SPS_READ_PENUM_IF_UNSET(&style->visibility, repr, "visibility", enum_visibility, true); - SPS_READ_PENUM_IF_UNSET(&style->display, repr, "display", enum_display, true); - SPS_READ_PENUM_IF_UNSET(&style->overflow, repr, "overflow", enum_overflow, true); - - /* CSS Compositing and Blending Level 1 */ - SPS_READ_PENUM_IF_UNSET(&style->isolation, repr, "isolation", enum_isolation, true); - SPS_READ_PENUM_IF_UNSET(&style->blend_mode, repr, "mix_blend_mode", enum_blend_mode, true); - - /* Font */ - SPS_READ_PFONTSIZE_IF_UNSET(&style->font_size, repr, "font-size"); - SPS_READ_PENUM_IF_UNSET(&style->font_style, repr, "font-style", enum_font_style, true); - SPS_READ_PENUM_IF_UNSET(&style->font_variant, repr, "font-variant", enum_font_variant, true); - SPS_READ_PENUM_IF_UNSET(&style->font_weight, repr, "font-weight", enum_font_weight, true); - SPS_READ_PENUM_IF_UNSET(&style->font_stretch, repr, "font-stretch", enum_font_stretch, true); - /* Text (css2 chapter 16) */ - SPS_READ_PLENGTH_IF_UNSET(&style->text_indent, repr, "text-indent"); - SPS_READ_PENUM_IF_UNSET(&style->text_align, repr, "text-align", enum_text_align, true); - if (!style->text_decoration_line.set) { - // assume it uses either text-decoration or text-decoration-line, but not both - if ((val = repr->attribute("text-decoration")) || (val = repr->attribute("text-decoration-line"))) { - sp_style_read_itextdecoration(&style->text_decoration_line, &style->text_decoration_style, &style->text_decoration_color, val); - } - } - if (!style->line_height.set) { - val = repr->attribute("line-height"); - if (val) { - sp_style_read_ilengthornormal(&style->line_height, val); - } - } - if (!style->letter_spacing.set) { - val = repr->attribute("letter-spacing"); - if (val) { - sp_style_read_ilengthornormal(&style->letter_spacing, val); - } - } - if (!style->word_spacing.set) { - val = repr->attribute("word-spacing"); - if (val) { - sp_style_read_ilengthornormal(&style->word_spacing, val); - } - } - SPS_READ_PENUM_IF_UNSET(&style->text_transform, repr, "text-transform", enum_text_transform, true); - SPS_READ_PENUM_IF_UNSET(&style->direction, repr, "direction", enum_direction, true); - SPS_READ_PENUM_IF_UNSET(&style->block_progression, repr, "block_progression", enum_block_progression, true); - - /* SVG */ - SPS_READ_PENUM_IF_UNSET(&style->writing_mode, repr, "writing-mode", - enum_writing_mode, true); - SPS_READ_PENUM_IF_UNSET(&style->text_anchor, repr, "text-anchor", - enum_text_anchor, true); - SPS_READ_PBASELINE_SHIFT_IF_UNSET(&style->baseline_shift, repr, "baseline-shift"); - - /* opacity */ - if (!style->opacity.set) { - val = repr->attribute("opacity"); - if (val) { - sp_style_read_iscale24(&style->opacity, val); - } - } - /* color */ - if (!style->color.set) { - val = repr->attribute("color"); - if (val) { - sp_style_read_icolor(&style->color, val, style, ( object - ? object->document - : NULL )); - } - } - /* color interpolation */ - SPS_READ_PENUM_IF_UNSET(&style->color_interpolation, repr, "color-interpolation", enum_color_interpolation, true); - /* color interpolation filters*/ - SPS_READ_PENUM_IF_UNSET(&style->color_interpolation_filters, repr, "color-interpolation-filters", enum_color_interpolation, true); - /* fill */ - if (!style->fill.set) { - val = repr->attribute("fill"); - if (val) { - style->fill.read( val, *style, (object) ? object->document : NULL ); - } - } - /* fill-opacity */ - if (!style->fill_opacity.set) { - val = repr->attribute("fill-opacity"); - if (val) { - sp_style_read_iscale24(&style->fill_opacity, val); - } - } - /* fill-rule */ - SPS_READ_PENUM_IF_UNSET(&style->fill_rule, repr, "fill-rule", enum_fill_rule, true); - /* stroke */ - if (!style->stroke.set) { - val = repr->attribute("stroke"); - if (val) { - style->stroke.read( val, *style, (object) ? object->document : NULL ); - } - } - SPS_READ_PLENGTH_IF_UNSET(&style->stroke_width, repr, "stroke-width"); - SPS_READ_PENUM_IF_UNSET(&style->stroke_linecap, repr, "stroke-linecap", enum_stroke_linecap, true); - SPS_READ_PENUM_IF_UNSET(&style->stroke_linejoin, repr, "stroke-linejoin", enum_stroke_linejoin, true); - SPS_READ_PFLOAT_IF_UNSET(&style->stroke_miterlimit, repr, "stroke-miterlimit"); - - /* markers */ - if (!style->marker[SP_MARKER_LOC].set) { - val = repr->attribute("marker"); - if (val) { - sp_style_read_istring(&style->marker[SP_MARKER_LOC], val); - } - } - if (!style->marker[SP_MARKER_LOC_START].set) { - val = repr->attribute("marker-start"); - if (val) { - sp_style_read_istring(&style->marker[SP_MARKER_LOC_START], val); - } - } - if (!style->marker[SP_MARKER_LOC_MID].set) { - val = repr->attribute("marker-mid"); - if (val) { - sp_style_read_istring(&style->marker[SP_MARKER_LOC_MID], val); - } - } - if (!style->marker[SP_MARKER_LOC_END].set) { - val = repr->attribute("marker-end"); - if (val) { - sp_style_read_istring(&style->marker[SP_MARKER_LOC_END], val); - } + /* 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 ); } + // for(SPPropMap::iterator i = _propmap.begin(); i != _propmap.end(); ++i ) { + // (this->*(i->second)).readAttribute( repr ); + // } - /* stroke-opacity */ - if (!style->stroke_opacity.set) { - val = repr->attribute("stroke-opacity"); - if (val) { - sp_style_read_iscale24(&style->stroke_opacity, val); - } - } - if (!style->stroke_dasharray.set) { - val = repr->attribute("stroke-dasharray"); - if (val) { - sp_style_read_dash(style, val); - } - } - SPS_READ_PLENGTH_IF_UNSET(&style->stroke_width, repr, "stroke-dashoffset"); - - /* paint-order */ - if (!style->paint_order.set) { - val = repr->attribute("paint-order"); - if (val) { - sp_style_read_ipaintorder(&style->paint_order, val); - } else { - style->paint_order.layer[0] = SP_CSS_PAINT_ORDER_NORMAL; - } - } - - /* -inkscape-font-specification */ - if (!style->text_private || !style->text->font_specification.set) { - val = repr->attribute("-inkscape-font-specification"); - if (val) { - if (!style->text_private) sp_style_privatize_text(style); - gchar *val_unquoted = attribute_unquote(val); - sp_style_read_istring(&style->text->font_specification, val_unquoted); - if (val_unquoted) g_free (val_unquoted); - } - } - - /* font-family */ - if (!style->text_private || !style->text->font_family.set) { - val = repr->attribute("font-family"); - if (val) { - if (!style->text_private) sp_style_privatize_text(style); - gchar *val_unquoted = attribute_unquote(val); - sp_style_read_istring(&style->text->font_family, val_unquoted); - if (val_unquoted) g_free (val_unquoted); - } - } - - /* filter effects */ - if (!style->filter.set) { - val = repr->attribute("filter"); - if (val) { - sp_style_read_ifilter(val, style, (object) ? object->document : NULL); - } - } - SPS_READ_PENUM_IF_UNSET(&style->enable_background, repr, - "enable-background", enum_enable_background, true); - - /* clip-rule */ - SPS_READ_PENUM_IF_UNSET(&style->clip_rule, repr, "clip-rule", enum_clip_rule, true); - - /* color_rendering, image_rendering, shape_rendering, text_rendering */ - SPS_READ_PENUM_IF_UNSET(&style->color_rendering, repr, "color-rendering", enum_color_rendering, true); - SPS_READ_PENUM_IF_UNSET(&style->image_rendering, repr, "image-rendering", enum_image_rendering, true); - SPS_READ_PENUM_IF_UNSET(&style->shape_rendering, repr, "shape-rendering", enum_shape_rendering, true); - SPS_READ_PENUM_IF_UNSET(&style->text_rendering, repr, "text-rendering", enum_text_rendering, true); - - /* 3. Merge from parent */ - if (object) { - if (object->parent) { - sp_style_merge_from_parent(style, object->parent->style); + /* 4 Cascade from parent */ + // std::cout << " CASCADING FROM PARENT" << std::endl; + if( object ) { + if( object->parent ) { + cascade( object->parent->style ); } } else { - if (repr->parent()) { - /// \todo fixme: This is not the prettiest thing (Lauris) - SPStyle *parent = sp_style_new(NULL); - sp_style_read(parent, NULL, repr->parent()); - sp_style_merge_from_parent(style, parent); - sp_style_unref(parent); + // When does this happen? + // std::cout << "SPStyle::read(): reading via repr->parent()" << std::endl; + if( repr->parent() ) { + SPStyle *parent = new SPStyle(); + parent->read( NULL, repr->parent() ); + cascade( parent ); + delete parent; } } } - -/** - * Read style properties from object's repr. - * - * 1. Reset existing object style - * 2. Load current effective object style - * 3. Load i attributes from immediate parent (which has to be up-to-date) - */ +// Matches void sp_style_read_from_object(SPStyle *style, SPObject *object); void -sp_style_read_from_object(SPStyle *style, SPObject *object) -{ - g_return_if_fail(style != NULL); +SPStyle::readFromObject( SPObject *object ) { + + // std::cout << "SPStyle::readFromObject: "<< (object->getId()?object->getId():"null")<< std::endl; + g_return_if_fail(object != NULL); g_return_if_fail(SP_IS_OBJECT(object)); Inkscape::XML::Node *repr = object->getRepr(); g_return_if_fail(repr != NULL); - sp_style_read(style, object, repr); + read( object, repr ); } - -/** - * Read style properties from preferences. - * @param style The style to write to - * @param path Preferences directory from which the style should be read - */ +// Matches sp_style_merge_property(SPStyle *style, gint id, gchar const *val) void -sp_style_read_from_prefs(SPStyle *style, Glib::ustring const &path) -{ - g_return_if_fail(style != NULL); - g_return_if_fail(path != ""); - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - // not optimal: we reconstruct the node based on the prefs, then pass it to - // sp_style_read for actual processing. - Inkscape::XML::SimpleDocument *tempdoc = new Inkscape::XML::SimpleDocument; - Inkscape::XML::Node *tempnode = tempdoc->createElement("temp"); - - std::vector<Inkscape::Preferences::Entry> attrs = prefs->getAllEntries(path); - for (std::vector<Inkscape::Preferences::Entry>::iterator i = attrs.begin(); i != attrs.end(); ++i) { - tempnode->setAttribute(i->getEntryName().data(), i->getString().data()); - } - - sp_style_read(style, NULL, tempnode); - - Inkscape::GC::release(tempnode); - Inkscape::GC::release(tempdoc); - delete tempdoc; -} - +SPStyle::readIfUnset( gint id, gchar const *val ) { - -/** - * - */ -static void -sp_style_privatize_text(SPStyle *style) -{ - SPTextStyle *text = style->text; - style->text = sp_text_style_duplicate_unset(style->text); - sp_text_style_unref(text); - style->text_private = TRUE; -} - - -/** - * Merge property into style. - * - * Should be called in order of highest to lowest precedence. - * E.g. for a single style string, call from the last declaration to the first, - * as CSS says that later declarations override earlier ones. - * - * \pre val != NULL. - */ -static void -sp_style_merge_property(SPStyle *style, gint id, gchar const *val) -{ + // std::cout << "SPStyle::readIfUnset: Entrance: " << (val?val:"null") << std::endl; + // To Do: If it is not too slow, use std::map instead of std::vector inorder to remove switch() + // (looking up SP_PROP_xxxx already uses a hash). g_return_if_fail(val != NULL); switch (id) { case SP_PROP_INKSCAPE_FONT_SPEC: - if (!style->text_private) sp_style_privatize_text(style); - if (!style->text->font_specification.set) { - gchar *val_unquoted = attribute_unquote(val); - sp_style_read_istring(&style->text->font_specification, val_unquoted); - if (val_unquoted) g_free (val_unquoted); - } + font_specification.readIfUnset( val ); break; - /* CSS2 */ - /* Font */ case SP_PROP_FONT_FAMILY: - if (!style->text_private) sp_style_privatize_text(style); - if (!style->text->font_family.set) { - gchar *val_unquoted = attribute_unquote(val); - sp_style_read_istring(&style->text->font_family, val_unquoted); - if (val_unquoted) g_free (val_unquoted); - } + font_family.readIfUnset( val ); break; case SP_PROP_FONT_SIZE: - SPS_READ_IFONTSIZE_IF_UNSET(&style->font_size, val); + font_size.readIfUnset( val ); break; case SP_PROP_FONT_SIZE_ADJUST: if (strcmp(val, "none") != 0) { @@ -991,220 +609,71 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val) } break; case SP_PROP_FONT_STYLE: - SPS_READ_IENUM_IF_UNSET(&style->font_style, val, enum_font_style, true); + font_style.readIfUnset( val ); break; case SP_PROP_FONT_VARIANT: - SPS_READ_IENUM_IF_UNSET(&style->font_variant, val, enum_font_variant, true); + font_variant.readIfUnset( val ); break; case SP_PROP_FONT_WEIGHT: - SPS_READ_IENUM_IF_UNSET(&style->font_weight, val, enum_font_weight, true); + font_weight.readIfUnset( val ); break; case SP_PROP_FONT_STRETCH: - SPS_READ_IENUM_IF_UNSET(&style->font_stretch, val, enum_font_stretch, true); + font_stretch.readIfUnset( val ); break; case SP_PROP_FONT: - if (!style->text_private) sp_style_privatize_text(style); - if (!style->text->font.set) { - g_free(style->text->font.value); - style->text->font.value = g_strdup(val); - style->text->font.set = TRUE; - style->text->font.inherit = (val && !strcmp(val, "inherit")); - - // Break string into white space separated tokens - std::stringstream os( val ); - Glib::ustring param; - - while (os >> param) { - - // CSS is case insensitive but we're comparing against lowercase strings - Glib::ustring lparam = param.lowercase(); - - if (lparam == "/") { - - os >> param; - // Eat the line-height for the moment as it is not an SVG property. - // lparam = param.lowercase(); - // sp_style_read_ilengthornormal(&style->line_height, lparam); - - } else { - - // Skip if "normal" as that is the default (and we don't know which attribute it applies to). - if (lparam == "normal") continue; - - // Check each property in turn - - // font-style - SPIEnum test_style; - test_style.set = FALSE; - - // Read once to see if param is valid style. If valid, .set will be TRUE. - sp_style_read_ienum(&test_style, lparam.c_str(), enum_font_style, true); - - // If valid style parameter - if (test_style.set) { - - // If not previously set - if (!style->font_style.set) { - style->font_style.set = TRUE; - style->font_style.inherit = test_style.inherit; - style->font_style.value = test_style.value; - style->font_style.computed = test_style.computed; - } - continue; // Next parameter. - } - - // font-variant (small-caps) - SPIEnum test_variant; - test_variant.set = FALSE; - sp_style_read_ienum(&test_variant, lparam.c_str(), enum_font_variant, true); - - // If valid variant parameter - if (test_variant.set) { - - // If not previously set - if (!style->font_variant.set) { - style->font_variant.set = TRUE; - style->font_variant.inherit = test_variant.inherit; - style->font_variant.value = test_variant.value; - style->font_variant.computed = test_variant.computed; - } - continue; // Next parameter. - } - - // font-weight - SPIEnum test_weight; - test_weight.set = FALSE; - sp_style_read_ienum(&test_weight, lparam.c_str(), enum_font_weight, true); - - // If valid weight parameter - if (test_weight.set) { - - // If not previously set - if (!style->font_weight.set) { - style->font_weight.set = TRUE; - style->font_weight.inherit = test_weight.inherit; - style->font_weight.value = test_weight.value; - style->font_weight.computed = test_weight.computed; - } - continue; // Next parameter - } - - // Font-size - SPIFontSize test_size; - test_size.set = FALSE; - - // Read once to see if param is valid size. - sp_style_read_ifontsize( &test_size, lparam.c_str() ); - - // If valid size parameter - if (test_size.set) { - - // If not previously set - if (!style->font_size.set) { - style->font_size.set = TRUE; - style->font_size.inherit = test_size.inherit; - style->font_size.unit = test_size.unit; - style->font_size.value = test_size.value; - style->font_size.computed = test_size.computed; - style->font_size.type = test_size.type; - style->font_size.literal = test_size.literal; - } - continue; - } - - // No valid property value found. - break; - } - } // params - - // The rest must be font-family... - std::string val_s = val; - std::string family = val_s.substr( val_s.find( param ) ); - - if (!style->text_private) sp_style_privatize_text(style); - if (!style->text->font_family.set) { - gchar *val_unquoted = attribute_unquote( family.c_str() ); - sp_style_read_istring(&style->text->font_family, val_unquoted); - if (val_unquoted) g_free (val_unquoted); - } - - // Set all properties to their default values per CSS 2.1 spec if not already set - SPS_READ_IFONTSIZE_IF_UNSET(&style->font_size, "medium" ); - SPS_READ_IENUM_IF_UNSET(&style->font_style, "normal", enum_font_style, true); - SPS_READ_IENUM_IF_UNSET(&style->font_variant, "normal", enum_font_variant, true); - SPS_READ_IENUM_IF_UNSET(&style->font_weight, "normal", enum_font_weight, true); - // Line height is not an SVG property but Inkscape uses it for multi-line text. - // sp_style_read_ilengthornormal(&style->line_height, "normal"); - - } - + font.readIfUnset( val ); break; /* Text */ case SP_PROP_TEXT_INDENT: - SPS_READ_ILENGTH_IF_UNSET(&style->text_indent, val); + text_indent.readIfUnset( val ); break; case SP_PROP_TEXT_ALIGN: - SPS_READ_IENUM_IF_UNSET(&style->text_align, val, enum_text_align, true); + text_align.readIfUnset( val ); break; case SP_PROP_TEXT_DECORATION: - if (!style->text_decoration_line.set) { - sp_style_read_itextdecoration(&style->text_decoration_line, &style->text_decoration_style, &style->text_decoration_color, val); - } + text_decoration.readIfUnset( val ); break; case SP_PROP_TEXT_DECORATION_LINE: - if (!style->text_decoration_line.set) { - sp_style_read_itextdecorationLine(&style->text_decoration_line, val); - } + text_decoration_line.readIfUnset( val ); break; case SP_PROP_TEXT_DECORATION_STYLE: - if (!style->text_decoration_style.set) { - sp_style_read_itextdecorationStyle(&style->text_decoration_style, val); - } + text_decoration_style.readIfUnset( val ); break; case SP_PROP_TEXT_DECORATION_COLOR: - if (!style->text_decoration_color.set) { - sp_style_read_itextdecorationColor(&style->text_decoration_color, val); - } + text_decoration_color.readIfUnset( val ); break; case SP_PROP_LINE_HEIGHT: - if (!style->line_height.set) { - sp_style_read_ilengthornormal(&style->line_height, val); - } + line_height.readIfUnset( val ); break; case SP_PROP_LETTER_SPACING: - if (!style->letter_spacing.set) { - sp_style_read_ilengthornormal(&style->letter_spacing, val); - } + letter_spacing.readIfUnset( val ); break; case SP_PROP_WORD_SPACING: - if (!style->word_spacing.set) { - sp_style_read_ilengthornormal(&style->word_spacing, val); - } + word_spacing.readIfUnset( val ); break; case SP_PROP_TEXT_TRANSFORM: - SPS_READ_IENUM_IF_UNSET(&style->text_transform, val, enum_text_transform, true); + text_transform.readIfUnset( val ); break; /* Text (css3) */ case SP_PROP_DIRECTION: - SPS_READ_IENUM_IF_UNSET(&style->direction, val, enum_direction, true); + direction.readIfUnset( val ); break; case SP_PROP_BLOCK_PROGRESSION: - SPS_READ_IENUM_IF_UNSET(&style->block_progression, val, enum_block_progression, true); + block_progression.readIfUnset( val ); break; case SP_PROP_WRITING_MODE: - SPS_READ_IENUM_IF_UNSET(&style->writing_mode, val, enum_writing_mode, true); + writing_mode.readIfUnset( val ); break; case SP_PROP_TEXT_ANCHOR: - SPS_READ_IENUM_IF_UNSET(&style->text_anchor, val, enum_text_anchor, true); + text_anchor.readIfUnset( val ); break; case SP_PROP_BASELINE_SHIFT: - SPS_READ_IBASELINE_SHIFT_IF_UNSET(&style->baseline_shift, val); + baseline_shift.readIfUnset( val ); break; - case SP_PROP_TEXT_RENDERING: { - SPS_READ_IENUM_IF_UNSET(&style->text_rendering, val, enum_text_rendering, true); + case SP_PROP_TEXT_RENDERING: + text_rendering.readIfUnset( val ); break; - } case SP_PROP_ALIGNMENT_BASELINE: g_warning("Unimplemented style property SP_PROP_ALIGNMENT_BASELINE: value: %s", val); break; @@ -1225,31 +694,25 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val) g_warning("Unimplemented style property SP_PROP_CLIP: value: %s", val); break; case SP_PROP_COLOR: - if (!style->color.set) { - sp_style_read_icolor(&style->color, val, style, (style->object) ? style->object->document : NULL); - } + color.readIfUnset( val ); break; case SP_PROP_CURSOR: g_warning("Unimplemented style property SP_PROP_CURSOR: value: %s", val); break; case SP_PROP_DISPLAY: - SPS_READ_IENUM_IF_UNSET(&style->display, val, enum_display, true); + display.readIfUnset( val ); break; case SP_PROP_OVERFLOW: - /** \todo - * FIXME: not supported properly yet, we just read and write it, - * but act as if it is always "display". - */ - SPS_READ_IENUM_IF_UNSET(&style->overflow, val, enum_overflow, true); + overflow.readIfUnset( val ); break; case SP_PROP_VISIBILITY: - SPS_READ_IENUM_IF_UNSET(&style->visibility, val, enum_visibility, true); + visibility.readIfUnset( val ); break; case SP_PROP_ISOLATION: - SPS_READ_IENUM_IF_UNSET(&style->isolation, val, enum_isolation, true); + isolation.readIfUnset( val ); break; case SP_PROP_BLEND_MODE: - SPS_READ_IENUM_IF_UNSET(&style->blend_mode, val, enum_blend_mode, true); + blend_mode.readIfUnset( val ); break; /* SVG */ @@ -1264,12 +727,10 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val) g_warning("attribute 'clip-path' given as CSS"); //XML Tree being directly used here. - style->object->getRepr()->setAttribute("clip-path", val); + this->object->getRepr()->setAttribute("clip-path", val); break; case SP_PROP_CLIP_RULE: - if (!style->clip_rule.set) { - sp_style_read_ienum(&style->clip_rule, val, enum_clip_rule, true); - } + clip_rule.readIfUnset( val ); break; case SP_PROP_MASK: /** \todo @@ -1278,22 +739,17 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val) g_warning("attribute 'mask' given as CSS"); //XML Tree being directly used here. - style->object->getRepr()->setAttribute("mask", val); + this->object->getRepr()->setAttribute("mask", val); break; case SP_PROP_OPACITY: - if (!style->opacity.set) { - sp_style_read_iscale24(&style->opacity, val); - } + opacity.readIfUnset( val ); break; case SP_PROP_ENABLE_BACKGROUND: - SPS_READ_IENUM_IF_UNSET(&style->enable_background, val, - enum_enable_background, true); + enable_background.readIfUnset( val ); break; /* Filter */ case SP_PROP_FILTER: - if (!style->filter.set && !style->filter.inherit) { - sp_style_read_ifilter(val, style, (style->object) ? style->object->document : NULL); - } + if( !filter.inherit ) filter.readIfUnset( val ); break; case SP_PROP_FLOOD_COLOR: g_warning("Unimplemented style property SP_PROP_FLOOD_COLOR: value: %s", val); @@ -1318,139 +774,186 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val) /* Paint */ case SP_PROP_COLOR_INTERPOLATION: // We read it but issue warning - SPS_READ_IENUM_IF_UNSET(&style->color_interpolation, val, enum_color_interpolation, true); - if( style->color_interpolation.value != SP_CSS_COLOR_INTERPOLATION_SRGB ) { + color_interpolation.readIfUnset( val ); + if( color_interpolation.value != SP_CSS_COLOR_INTERPOLATION_SRGB ) { g_warning("Inkscape currently only supports color-interpolation = sRGB"); } break; case SP_PROP_COLOR_INTERPOLATION_FILTERS: - SPS_READ_IENUM_IF_UNSET(&style->color_interpolation_filters, val, enum_color_interpolation, true); + color_interpolation_filters.readIfUnset( val ); break; case SP_PROP_COLOR_PROFILE: g_warning("Unimplemented style property SP_PROP_COLOR_PROFILE: value: %s", val); break; - case SP_PROP_COLOR_RENDERING: { - SPS_READ_IENUM_IF_UNSET(&style->color_rendering, val, enum_color_rendering, true); + case SP_PROP_COLOR_RENDERING: + color_rendering.readIfUnset( val ); break; - } case SP_PROP_FILL: - if (!style->fill.set) { - style->fill.read( val, *style, (style->object) ? style->object->document : NULL ); - } + fill.readIfUnset( val ); break; case SP_PROP_FILL_OPACITY: - if (!style->fill_opacity.set) { - sp_style_read_iscale24(&style->fill_opacity, val); - } + fill_opacity.readIfUnset( val ); break; case SP_PROP_FILL_RULE: - if (!style->fill_rule.set) { - sp_style_read_ienum(&style->fill_rule, val, enum_fill_rule, true); - } + fill_rule.readIfUnset( val ); break; - case SP_PROP_IMAGE_RENDERING: { - SPS_READ_IENUM_IF_UNSET(&style->image_rendering, val, enum_image_rendering, true); + case SP_PROP_IMAGE_RENDERING: + image_rendering.readIfUnset( val ); break; - } case SP_PROP_MARKER: - /* TODO: Call sp_uri_reference_resolve(SPDocument *document, guchar const *uri) */ - /* style->marker[SP_MARKER_LOC] = g_quark_from_string(val); */ - if (!style->marker[SP_MARKER_LOC].set) { - g_free(style->marker[SP_MARKER_LOC].value); - style->marker[SP_MARKER_LOC].value = g_strdup(val); - style->marker[SP_MARKER_LOC].set = TRUE; - style->marker[SP_MARKER_LOC].inherit = (val && !strcmp(val, "inherit")); - } + /* TODO: Call sp_uri_reference_resolve(SPDocument *document, guchar const *uri) */ + marker.readIfUnset( val ); break; - case SP_PROP_MARKER_START: /* TODO: Call sp_uri_reference_resolve(SPDocument *document, guchar const *uri) */ - if (!style->marker[SP_MARKER_LOC_START].set) { - g_free(style->marker[SP_MARKER_LOC_START].value); - style->marker[SP_MARKER_LOC_START].value = g_strdup(val); - style->marker[SP_MARKER_LOC_START].set = TRUE; - style->marker[SP_MARKER_LOC_START].inherit = (val && !strcmp(val, "inherit")); - } + marker_start.readIfUnset( val ); break; case SP_PROP_MARKER_MID: /* TODO: Call sp_uri_reference_resolve(SPDocument *document, guchar const *uri) */ - if (!style->marker[SP_MARKER_LOC_MID].set) { - g_free(style->marker[SP_MARKER_LOC_MID].value); - style->marker[SP_MARKER_LOC_MID].value = g_strdup(val); - style->marker[SP_MARKER_LOC_MID].set = TRUE; - style->marker[SP_MARKER_LOC_MID].inherit = (val && !strcmp(val, "inherit")); - } + marker_mid.readIfUnset( val ); break; case SP_PROP_MARKER_END: /* TODO: Call sp_uri_reference_resolve(SPDocument *document, guchar const *uri) */ - if (!style->marker[SP_MARKER_LOC_END].set) { - g_free(style->marker[SP_MARKER_LOC_END].value); - style->marker[SP_MARKER_LOC_END].value = g_strdup(val); - style->marker[SP_MARKER_LOC_END].set = TRUE; - style->marker[SP_MARKER_LOC_END].inherit = (val && !strcmp(val, "inherit")); - } + marker_end.readIfUnset( val ); break; - - case SP_PROP_SHAPE_RENDERING: { - SPS_READ_IENUM_IF_UNSET(&style->shape_rendering, val, enum_shape_rendering, true); + case SP_PROP_SHAPE_RENDERING: + shape_rendering.readIfUnset( val ); break; - } - case SP_PROP_STROKE: - if (!style->stroke.set) { - style->stroke.read( val, *style, (style->object) ? style->object->document : NULL ); - } + stroke.readIfUnset( val ); break; case SP_PROP_STROKE_WIDTH: - SPS_READ_ILENGTH_IF_UNSET(&style->stroke_width, val); + stroke_width.readIfUnset( val ); break; case SP_PROP_STROKE_DASHARRAY: - if (!style->stroke_dasharray.set) { - sp_style_read_dash(style, val); - } + stroke_dasharray.readIfUnset( val ); break; case SP_PROP_STROKE_DASHOFFSET: - SPS_READ_ILENGTH_IF_UNSET(&style->stroke_dashoffset, val); + stroke_dashoffset.readIfUnset( val ); break; case SP_PROP_STROKE_LINECAP: - if (!style->stroke_linecap.set) { - sp_style_read_ienum(&style->stroke_linecap, val, enum_stroke_linecap, true); - } + stroke_linecap.readIfUnset( val ); break; case SP_PROP_STROKE_LINEJOIN: - if (!style->stroke_linejoin.set) { - sp_style_read_ienum(&style->stroke_linejoin, val, enum_stroke_linejoin, true); - } + stroke_linejoin.readIfUnset( val ); break; case SP_PROP_STROKE_MITERLIMIT: - if (!style->stroke_miterlimit.set) { - sp_style_read_ifloat(&style->stroke_miterlimit, val); - } + stroke_miterlimit.readIfUnset( val ); break; case SP_PROP_STROKE_OPACITY: - if (!style->stroke_opacity.set) { - sp_style_read_iscale24(&style->stroke_opacity, val); - } + stroke_opacity.readIfUnset( val ); break; case SP_PROP_PAINT_ORDER: - if (!style->paint_order.set) { - sp_style_read_ipaintorder(&style->paint_order, val); - } + paint_order.readIfUnset( val ); break; - default: - g_warning("Invalid style property id: %d value: %s", id, val); + g_warning("SPIStyle::readIfUnset(): Invalid style property id: %d value: %s", id, val); break; } } -static void -sp_style_merge_style_from_decl(SPStyle *const style, CRDeclaration const *const decl) -{ - /** \todo Ensure that property is lcased, as per - * http://www.w3.org/TR/REC-CSS2/syndata.html#q4. - * Should probably be done in libcroco. - */ +Glib::ustring +SPStyle::write( guint const flags, SPStyle const *const base ) const { + + // std::cout << "SPStyle::write" << std::endl; + + Glib::ustring style_string; + for(std::vector<SPIBase*>::size_type i = 0; i != _properties.size(); ++i) { + if( base != NULL ) { + style_string += _properties[i]->write( flags, base->_properties[i] ); + } else { + style_string += _properties[i]->write( flags, NULL ); + } + } + // for(SPPropMap::iterator i = _propmap.begin(); i != _propmap.end(); ++i ) { + // if( base != NULL ) { + // style_string += (this->*(i->second)).write( flags, &(base->*(i->second)) ); + // } else { + // style_string += (this->*(i->second)).write( flags, NULL ); + // } + // } + + // Remove trailing ';' + if( style_string.size() > 0 ) { + style_string.erase( style_string.size() - 1 ); + } + return style_string; +} + +// Corresponds to sp_style_merge_from_parent() +void +SPStyle::cascade( SPStyle const *const parent ) { + // std::cout << "SPStyle::cascade" << std::endl; + for(std::vector<SPIBase*>::size_type i = 0; i != _properties.size(); ++i) { + _properties[i]->cascade( parent->_properties[i] ); + } + // for(SPPropMap::iterator i = _propmap.begin(); i != _propmap.end(); ++i ) { + // (this->*(i->second)).cascade( &(parent->*(i->second)) ); + // } +} + +// Corresponds to sp_style_merge_from_dying_parent() +void +SPStyle::merge( SPStyle const *const parent ) { + // std::cout << "SPStyle::merge" << std::endl; + for(std::vector<SPIBase*>::size_type i = 0; i != _properties.size(); ++i) { + _properties[i]->merge( parent->_properties[i] ); + } + // for(SPPropMap::iterator i = _propmap.begin(); i != _propmap.end(); ++i ) { + // (this->*(i->second)).cascade( &(parent->*(i->second)) ); + // } +} + +// Mostly for unit testing +bool +SPStyle::operator==(const SPStyle& rhs) { + + // Uncomment for testing + // for(std::vector<SPIBase*>::size_type i = 0; i != _properties.size(); ++i) { + // if( *_properties[i] != *rhs._properties[i]) + // std::cout << _properties[i]->name << ": " + // << _properties[i]->write(SP_STYLE_FLAG_ALWAYS,NULL) << " " + // << rhs._properties[i]->write(SP_STYLE_FLAG_ALWAYS,NULL) + // << (*_properties[i] == *rhs._properties[i]) << std::endl; + // } + + for(std::vector<SPIBase*>::size_type i = 0; i != _properties.size(); ++i) { + if( *_properties[i] != *rhs._properties[i]) return false; + } + return true; +} + +void +SPStyle::_mergeString( gchar const *const p ) { + + // std::cout << "SPStyle::_mergeString: " << (p?p:"null") << std::endl; + CRDeclaration *const decl_list + = cr_declaration_parse_list_from_buf(reinterpret_cast<guchar const *>(p), CR_UTF_8); + if (decl_list) { + _mergeDeclList( decl_list ); + cr_declaration_destroy(decl_list); + } +} + +void +SPStyle::_mergeDeclList( CRDeclaration const *const decl_list ) { + + // std::cout << "SPStyle::_mergeDeclList" << std::endl; + + // In reverse order, as later declarations to take precedence over earlier ones. + // (Properties are only set if not previously set. See: + // Ref: http://www.w3.org/TR/REC-CSS2/cascade.html#cascading-order point 4.) + if (decl_list->next) { + _mergeDeclList( decl_list->next ); + } + _mergeDecl( decl_list ); +} + +void +SPStyle::_mergeDecl( CRDeclaration const *const decl ) { + + // std::cout << "SPStyle::_mergeDecl" << std::endl; + unsigned const prop_idx = sp_attribute_lookup(decl->property->stryng->str); if (prop_idx != SP_ATTR_INVALID) { /** \todo @@ -1460,71 +963,30 @@ sp_style_merge_style_from_decl(SPStyle *const style, CRDeclaration const *const */ guchar *const str_value_unsigned = cr_term_to_string(decl->value); gchar *const str_value = reinterpret_cast<gchar *>(str_value_unsigned); - sp_style_merge_property(style, prop_idx, str_value); + readIfUnset( prop_idx, str_value ); g_free(str_value); } } -static void -sp_style_merge_from_props(SPStyle *const style, CRPropList *const props) -{ -#if 0 /* forwards */ - for (CRPropList const *cur = props; cur; cur = cr_prop_list_get_next(cur)) { - CRDeclaration *decl = NULL; - cr_prop_list_get_decl(cur, &decl); - sp_style_merge_style_from_decl(style, decl); - } -#else /* in reverse order, as we need later declarations to take precedence over earlier ones. */ +void +SPStyle::_mergeProps( CRPropList *const props ) { + + // std::cout << "SPStyle::_mergeProps" << std::endl; + + // In reverse order, as later declarations to take precedence over earlier ones. if (props) { - sp_style_merge_from_props(style, cr_prop_list_get_next(props)); + _mergeProps( cr_prop_list_get_next( props ) ); CRDeclaration *decl = NULL; cr_prop_list_get_decl(props, &decl); - sp_style_merge_style_from_decl(style, decl); + _mergeDecl( decl ); } -#endif -} - -/** - * \pre decl_list != NULL - */ -static void -sp_style_merge_from_decl_list(SPStyle *const style, CRDeclaration const *const decl_list) -{ - // read the decls from end to start, using head recursion, so that latter declarations override - // (Ref: http://www.w3.org/TR/REC-CSS2/cascade.html#cascading-order point 4.) - // because sp_style_merge_style_from_decl only sets properties that are unset - if (decl_list->next) { - sp_style_merge_from_decl_list(style, decl_list->next); - } - sp_style_merge_style_from_decl(style, decl_list); } -static CRSelEng * -sp_repr_sel_eng() -{ - CRSelEng *const ret = cr_sel_eng_new(); - cr_sel_eng_set_node_iface(ret, &Inkscape::XML::croco_node_iface); - - /** \todo - * Check whether we need to register any pseudo-class handlers. - * libcroco has its own default handlers for first-child and lang. - * - * We probably want handlers for link and arguably visited (though - * inkscape can't visit links at the time of writing). hover etc. - * more useful in inkview than the editor inkscape. - * - * http://www.w3.org/TR/SVG11/styling.html#StylingWithCSS says that - * the following should be honoured, at least by inkview: - * :hover, :active, :focus, :visited, :link. - */ +void +SPStyle::_mergeObjectStylesheet( SPObject const *const object ) { - g_assert(ret); - return ret; -} + // std::cout << "SPStyle::_mergeObjectStylesheet: " << (object->getId()?object->getId():"null") << std::endl; -static void -sp_style_merge_from_object_stylesheet(SPStyle *const style, SPObject const *const object) -{ static CRSelEng *sel_eng = NULL; if (!sel_eng) { sel_eng = sp_repr_sel_eng(); @@ -1540,586 +1002,319 @@ sp_style_merge_from_object_stylesheet(SPStyle *const style, SPObject const *cons g_return_if_fail(status == CR_OK); /// \todo Check what errors can occur, and handle them properly. if (props) { - sp_style_merge_from_props(style, props); + _mergeProps(props); cr_prop_list_destroy(props); } } +// Internal /** - * Parses a style="..." string and merges it with an existing SPStyle. + * Release callback. */ -void -sp_style_merge_from_style_string(SPStyle *const style, gchar const *const p) -{ - /* - * Reference: http://www.w3.org/TR/SVG11/styling.html#StyleAttribute: - * ``When CSS styling is used, CSS inline style is specified by including - * semicolon-separated property declarations of the form "name : value" - * within the style attribute''. - * - * That's fairly ambiguous. Is a `value' allowed to contain semicolons? - * Why does it say "including", what else is allowed in the style - * attribute value? - */ - - CRDeclaration *const decl_list - = cr_declaration_parse_list_from_buf(reinterpret_cast<guchar const *>(p), CR_UTF_8); - if (decl_list) { - sp_style_merge_from_decl_list(style, decl_list); - cr_declaration_destroy(decl_list); - } -} - -/** Indexed by SP_CSS_FONT_SIZE_blah. */ -static float const font_size_table[] = {6.0, 8.0, 10.0, 12.0, 14.0, 18.0, 24.0}; - static void -sp_style_merge_font_size_from_parent(SPIFontSize &child, SPIFontSize const &parent) +sp_style_object_release(SPObject *object, SPStyle *style) { - /* 'font-size' */ - if (!child.set || child.inherit) { - /* Inherit the computed value. Reference: http://www.w3.org/TR/SVG11/styling.html#Inheritance */ - child.computed = parent.computed; - } else if (child.type == SP_FONT_SIZE_LITERAL) { - /** \todo - * fixme: SVG and CSS do not specify clearly, whether we should use - * user or screen coordinates (Lauris) - */ - if (child.literal < SP_CSS_FONT_SIZE_SMALLER) { - child.computed = font_size_table[child.literal]; - } else if (child.literal == SP_CSS_FONT_SIZE_SMALLER) { - child.computed = parent.computed / 1.2; - } else if (child.literal == SP_CSS_FONT_SIZE_LARGER) { - child.computed = parent.computed * 1.2; - } else { - /* Illegal value */ - } - } else if (child.type == SP_FONT_SIZE_PERCENTAGE) { - /* Unlike most other lengths, percentage for font size is relative to parent computed value - * rather than viewport. */ - child.computed = parent.computed * child.value; - } else if (child.type == SP_FONT_SIZE_LENGTH) { - switch (child.unit) { - case SP_CSS_UNIT_EM: - /* Relative to parent font size */ - child.computed = parent.computed * child.value; - break; - case SP_CSS_UNIT_EX: - /* Relative to parent font size */ - child.computed = parent.computed * child.value * 0.5; /* Hack */ - break; - default: - /* No change */ - break; - } - } + (void)object; // TODO + style->object = NULL; } -// Some shifts are defined relative to parent. +// Internal +/** + * Emit style modified signal on style's object if the filter changed. + */ static void -sp_style_merge_baseline_shift_from_parent(SPIBaselineShift &child, SPIBaselineShift const &parent, - SPIFontSize const &pfont_size) +sp_style_filter_ref_modified(SPObject *obj, guint flags, SPStyle *style) { - /* 'baseline-shift' */ - if (!child.set || child.inherit) { - /* Inherit the computed value. Reference: http://www.w3.org/TR/SVG11/styling.html#Inheritance */ - child.computed = parent.computed; // Does this make sense (applying a shift a second time)? - } else if (child.type == SP_BASELINE_SHIFT_LITERAL) { - if( child.literal == SP_CSS_BASELINE_SHIFT_BASELINE ) { - child.computed = 0; // No change - } else if (child.literal == SP_CSS_BASELINE_SHIFT_SUB ) { - // Should use subscript position from font relative to alphabetic baseline - // OpenOffice, Adobe: -0.33, Word -0.14, LaTex about -0.2. - child.computed = -0.2 * pfont_size.computed; - } else if (child.literal == SP_CSS_BASELINE_SHIFT_SUPER ) { - // Should use superscript position from font relative to alphabetic baseline - // OpenOffice, Adobe: 0.33, Word 0.35, LaTex about 0.45. - child.computed = 0.4 * pfont_size.computed; - } else { - /* Illegal value */ - } - } else if (child.type == SP_BASELINE_SHIFT_PERCENTAGE) { - // Percentage for baseline shift is relative to computed "line-height" - // which is just font-size (see SVG1.1 'font'). - child.computed = pfont_size.computed * child.value; - } else if (child.type == SP_BASELINE_SHIFT_LENGTH) { - switch (child.unit) { - case SP_CSS_UNIT_EM: - child.computed = child.value * pfont_size.computed; - break; - case SP_CSS_UNIT_EX: - child.computed = child.value * 0.5 * pfont_size.computed; - break; - default: - /* No change */ - break; + (void)flags; // TODO + SPFilter *filter=static_cast<SPFilter *>(obj); + if (style->getFilter() == filter) + { + if (style->object) { + style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } } - // baseline-shifts are relative to parent baseline - child.computed += parent.computed; } +// Internal /** - * Sets computed values in \a style, which may involve inheriting from (or in some other way - * calculating from) corresponding computed values of \a parent. - * - * References: http://www.w3.org/TR/SVG11/propidx.html shows what properties inherit by default. - * http://www.w3.org/TR/SVG11/styling.html#Inheritance gives general rules as to what it means to - * inherit a value. http://www.w3.org/TR/REC-CSS2/cascade.html#computed-value is more precise - * about what the computed value is (not obvious for lengths). - * - * \pre \a parent's computed values are already up-to-date. + * Gets called when the filter is (re)attached to the style */ void -sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent) +sp_style_filter_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style) { - g_return_if_fail(style != NULL); - - /** \todo - * fixme: Check for existing callers that might pass null parent. - * This should probably be g_return_if_fail, or else we should make a - * best attempt to set computed values correctly without having a parent - * (i.e., by assuming parent has initial values). - */ - if (!parent) - return; - - /* CSS2 */ - /* Font */ - sp_style_merge_font_size_from_parent(style->font_size, parent->font_size); - - /* 'font-style' */ - if (!style->font_style.set || style->font_style.inherit) { - style->font_style.computed = parent->font_style.computed; - } - - /* 'font-variant' */ - if (!style->font_variant.set || style->font_variant.inherit) { - style->font_variant.computed = parent->font_variant.computed; - } - - /* 'font-weight' */ - if (!style->font_weight.set || style->font_weight.inherit) { - style->font_weight.computed = parent->font_weight.computed; - } else if (style->font_weight.value == SP_CSS_FONT_WEIGHT_NORMAL) { - /** \todo - * fixme: This is unconditional, i.e., happens even if parent not - * present. - */ - style->font_weight.computed = SP_CSS_FONT_WEIGHT_400; - } else if (style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLD) { - style->font_weight.computed = SP_CSS_FONT_WEIGHT_700; - } else if (style->font_weight.value == SP_CSS_FONT_WEIGHT_LIGHTER) { - unsigned const parent_val = parent->font_weight.computed; - g_assert(SP_CSS_FONT_WEIGHT_100 == 0); - // strictly, 'bolder' and 'lighter' should go to the next weight - // expressible in the current font family, but that's difficult to - // find out, so jumping by 3 seems an appropriate approximation - style->font_weight.computed = (parent_val <= SP_CSS_FONT_WEIGHT_100 + 3 - ? (unsigned)SP_CSS_FONT_WEIGHT_100 - : parent_val - 3); - g_assert(style->font_weight.computed <= (unsigned) SP_CSS_FONT_WEIGHT_900); - } else if (style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLDER) { - unsigned const parent_val = parent->font_weight.computed; - g_assert(parent_val <= SP_CSS_FONT_WEIGHT_900); - style->font_weight.computed = (parent_val >= SP_CSS_FONT_WEIGHT_900 - 3 - ? (unsigned)SP_CSS_FONT_WEIGHT_900 - : parent_val + 3); - g_assert(style->font_weight.computed <= (unsigned) SP_CSS_FONT_WEIGHT_900); - } - - /* 'font-stretch' */ - if (!style->font_stretch.set || style->font_stretch.inherit) { - style->font_stretch.computed = parent->font_stretch.computed; - } else if (style->font_stretch.value == SP_CSS_FONT_STRETCH_NARROWER) { - unsigned const parent_val = parent->font_stretch.computed; - style->font_stretch.computed = (parent_val == SP_CSS_FONT_STRETCH_ULTRA_CONDENSED - ? parent_val - : parent_val - 1); - g_assert(style->font_stretch.computed <= (unsigned) SP_CSS_FONT_STRETCH_ULTRA_EXPANDED); - } else if (style->font_stretch.value == SP_CSS_FONT_STRETCH_WIDER) { - unsigned const parent_val = parent->font_stretch.computed; - g_assert(parent_val <= SP_CSS_FONT_STRETCH_ULTRA_EXPANDED); - style->font_stretch.computed = (parent_val == SP_CSS_FONT_STRETCH_ULTRA_EXPANDED - ? parent_val - : parent_val + 1); - g_assert(style->font_stretch.computed <= (unsigned) SP_CSS_FONT_STRETCH_ULTRA_EXPANDED); - } - - /* text (css2) */ - if (!style->text_indent.set || style->text_indent.inherit) { - style->text_indent.computed = parent->text_indent.computed; - } - - if (!style->text_align.set || style->text_align.inherit) { - style->text_align.computed = parent->text_align.computed; - } - - if (!style->text_decoration_line.set || style->text_decoration_line.inherit) { - style->text_decoration_line.underline = parent->text_decoration_line.underline; - style->text_decoration_line.overline = parent->text_decoration_line.overline; - style->text_decoration_line.line_through = parent->text_decoration_line.line_through; - style->text_decoration_line.blink = parent->text_decoration_line.blink; - } - - if (!style->text_decoration_style.set || style->text_decoration_style.inherit) { - style->text_decoration_style.solid = parent->text_decoration_style.solid; - style->text_decoration_style.isdouble = parent->text_decoration_style.isdouble; - style->text_decoration_style.dotted = parent->text_decoration_style.dotted; - style->text_decoration_style.dashed = parent->text_decoration_style.dashed; - style->text_decoration_style.wavy = parent->text_decoration_style.wavy; + if (old_ref) { + style->filter_modified_connection.disconnect(); } - - if (!style->text_decoration_color.set || style->text_decoration_color.inherit) { - sp_style_merge_ipaint(style, &style->text_decoration_color, &parent->text_decoration_color); + if ( SP_IS_FILTER(ref)) + { + style->filter_modified_connection = + ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_filter_ref_modified), style)); } - if (!style->line_height.set || style->line_height.inherit) { - style->line_height.value = parent->line_height.value; - style->line_height.computed = parent->line_height.computed; - style->line_height.normal = parent->line_height.normal; - } + sp_style_filter_ref_modified(ref, 0, style); +} - if (!style->letter_spacing.set || style->letter_spacing.inherit) { - style->letter_spacing.value = parent->letter_spacing.value; - style->letter_spacing.computed = parent->letter_spacing.computed; - style->letter_spacing.normal = parent->letter_spacing.normal; - } +/** + * Emit style modified signal on style's object if server is style's fill + * or stroke paint server. + */ +static void +sp_style_paint_server_ref_modified(SPObject *obj, guint flags, SPStyle *style) +{ + (void)flags; // TODO + SPPaintServer *server = static_cast<SPPaintServer *>(obj); - if (!style->word_spacing.set || style->word_spacing.inherit) { - style->word_spacing.value = parent->word_spacing.value; - style->word_spacing.computed = parent->word_spacing.computed; - style->word_spacing.normal = parent->word_spacing.normal; + if ((style->fill.isPaintserver()) + && style->getFillPaintServer() == server) + { + if (style->object) { + /** \todo + * fixme: I do not know, whether it is optimal - we are + * forcing reread of everything (Lauris) + */ + /** \todo + * fixme: We have to use object_modified flag, because parent + * flag is only available downstreams. + */ + style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); + } + } else if ((style->stroke.isPaintserver()) + && style->getStrokePaintServer() == server) + { + if (style->object) { + /// \todo fixme: + style->object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); + } + } else if (server) { + g_assert_not_reached(); } +} - if (!style->text_transform.set || style->text_transform.inherit) { - style->text_transform.computed = parent->text_transform.computed; +/** + * Gets called when the paintserver is (re)attached to the style + */ +void +sp_style_fill_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style) +{ + if (old_ref) { + style->fill_ps_modified_connection.disconnect(); } - - if (!style->direction.set || style->direction.inherit) { - style->direction.computed = parent->direction.computed; + if (SP_IS_PAINT_SERVER(ref)) { + style->fill_ps_modified_connection = + ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_paint_server_ref_modified), style)); } - if (!style->block_progression.set || style->block_progression.inherit) { - style->block_progression.computed = parent->block_progression.computed; - } + sp_style_paint_server_ref_modified(ref, 0, style); +} - if (!style->writing_mode.set || style->writing_mode.inherit) { - style->writing_mode.computed = parent->writing_mode.computed; +/** + * Gets called when the paintserver is (re)attached to the style + */ +void +sp_style_stroke_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style) +{ + if (old_ref) { + style->stroke_ps_modified_connection.disconnect(); } - - if (!style->text_anchor.set || style->text_anchor.inherit) { - style->text_anchor.computed = parent->text_anchor.computed; + if (SP_IS_PAINT_SERVER(ref)) { + style->stroke_ps_modified_connection = + ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_paint_server_ref_modified), style)); } - /* Baseline Shift... Some shifts are relative to parent. */ - sp_style_merge_baseline_shift_from_parent(style->baseline_shift, parent->baseline_shift, - parent->font_size); + sp_style_paint_server_ref_modified(ref, 0, style); +} - if (style->opacity.inherit) { - style->opacity.value = parent->opacity.value; - } +// Called in: desktop-style.cpp, gradient-chemistry.cpp, sp-object.cpp, sp-stop.cpp, style.cpp +// text-editing.cpp, libnrtype/font-lister.cpp, widgets/dash-selector.cpp, widgets/fill-style.cpp, +// widgets/stroke-style.cpp, widgets/text-toolbar.cpp, ui/dialog/glyphs.cpp, ui/dialog/swatches.cpp, +// ui/dialog/swatches.cpp, ui/dialog/text-edit.cpp. ui/tools/freehand-base.cpp, +// ui/widget/object-composite-settings.cpp, ui/widget/selected-style.cpp, ui/widget/style-swatch.cpp +/** + * Returns a new SPStyle object with default settings. + */ +SPStyle * +sp_style_new(SPDocument *document) +{ + SPStyle *const style = new SPStyle( document ); + return style; +} - /* Color */ - if (!style->color.set || style->color.inherit) { - sp_style_merge_ipaint(style, &style->color, &parent->color); - } - if (!style->color_interpolation.set || style->color_interpolation.inherit) { - style->color_interpolation.computed = parent->color_interpolation.computed; - } - if (!style->color_interpolation_filters.set || style->color_interpolation_filters.inherit) { - style->color_interpolation_filters.computed = parent->color_interpolation_filters.computed; - } +// Called in: sp-object.cpp +/** + * Creates a new SPStyle object, and attaches it to the specified SPObject. + */ +SPStyle * +sp_style_new_from_object(SPObject *object) +{ + g_return_val_if_fail(object != NULL, NULL); + g_return_val_if_fail(SP_IS_OBJECT(object), NULL); + SPStyle *const style = new SPStyle( NULL, object ); + return style; +} - /* Fill */ - if (!style->fill.set || style->fill.inherit || style->fill.currentcolor) { - sp_style_merge_ipaint(style, &style->fill, &parent->fill); - } +// Called in display/drawing-item.cpp, display/nr-filter-primitive.cpp, libnrtype/Layout-TNG-Input.cpp +/** + * Increase refcount of style. + */ +SPStyle * +sp_style_ref(SPStyle *style) +{ + g_return_val_if_fail(style != NULL, NULL); - if (!style->fill_opacity.set || style->fill_opacity.inherit) { - style->fill_opacity.value = parent->fill_opacity.value; - } + style->ref(); // Increase ref count - if (!style->fill_rule.set || style->fill_rule.inherit) { - style->fill_rule.computed = parent->fill_rule.computed; - } + return style; +} - /* Stroke */ - if (!style->stroke.set || style->stroke.inherit || style->stroke.currentcolor) { - sp_style_merge_ipaint(style, &style->stroke, &parent->stroke); +// Called in style.cpp, desktop-style.cpp, sp-object.cpp, sp-stop.cpp, text-editing.cpp +// display/drawing-group.cpp, ... +/** + * Decrease refcount of style with possible destruction. + */ +SPStyle * +sp_style_unref(SPStyle *style) +{ + g_return_val_if_fail(style != NULL, NULL); + if (style->unref() < 1) { + delete style; + return NULL; } + return style; +} - if (!style->stroke_width.set || style->stroke_width.inherit) { - style->stroke_width.computed = parent->stroke_width.computed; - } else { - /* Update computed value for any change in font inherited from parent. */ - double const em = style->font_size.computed; - if (style->stroke_width.unit == SP_CSS_UNIT_EM) { - style->stroke_width.computed = style->stroke_width.value * em; - } else if (style->stroke_width.unit == SP_CSS_UNIT_EX) { - double const ex = em * 0.5; // fixme: Get x height from libnrtype or pango. - style->stroke_width.computed = style->stroke_width.value * ex; - } - } - if (!style->stroke_linecap.set || style->stroke_linecap.inherit) { - style->stroke_linecap.computed = parent->stroke_linecap.computed; - } - if (!style->stroke_linejoin.set || style->stroke_linejoin.inherit) { - style->stroke_linejoin.computed = parent->stroke_linejoin.computed; - } +// Called in: sp-clippath.cpp, sp-item.cpp (suspicious), sp-object.cpp, sp-style-elem.cpp +/** + * Read style properties from object's repr. + * + * 1. Reset existing object style + * 2. Load current effective object style + * 3. Load i attributes from immediate parent (which has to be up-to-date) + */ +void +sp_style_read_from_object(SPStyle *style, SPObject *object) +{ + // std::cout << "sp_style_read_from_object: " << (object->getId()?object->getId():"null") << std::endl; + g_return_if_fail(style != NULL); + g_return_if_fail(object != NULL); + g_return_if_fail(SP_IS_OBJECT(object)); - if (!style->stroke_miterlimit.set || style->stroke_miterlimit.inherit) { - style->stroke_miterlimit.value = parent->stroke_miterlimit.value; - } + Inkscape::XML::Node *repr = object->getRepr(); + g_return_if_fail(repr != NULL); - if (!style->stroke_dasharray.set || style->stroke_dasharray.inherit) { - style->stroke_dasharray.values = parent->stroke_dasharray.values; - } + style->read( object, repr ); +} - if (!style->stroke_dashoffset.set || style->stroke_dashoffset.inherit) { - style->stroke_dashoffset.value = parent->stroke_dashoffset.value; - } +// Called in: libnrtype/font-lister.cpp, widgets/dash-selector.cpp, widgets/text-toolbar.cpp, +// ui/dialog/text-edit.cpp +// Why is this called when draging a gradient handle? +/** + * Read style properties from preferences. + * @param style The style to write to + * @param path Preferences directory from which the style should be read + */ +void +sp_style_read_from_prefs(SPStyle *style, Glib::ustring const &path) +{ + g_return_if_fail(style != NULL); + g_return_if_fail(path != ""); - if (!style->stroke_opacity.set || style->stroke_opacity.inherit) { - style->stroke_opacity.value = parent->stroke_opacity.value; - } + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (!style->paint_order.set || style->paint_order.inherit) { - g_free(style->paint_order.value); - style->paint_order.value = g_strdup(parent->paint_order.value); - for (unsigned i = 0; i < PAINT_ORDER_LAYERS; ++i) { - style->paint_order.layer[i] = parent->paint_order.layer[i]; - style->paint_order.layer_set[i] = parent->paint_order.layer_set[i]; - } - } + // not optimal: we reconstruct the node based on the prefs, then pass it to + // sp_style_read for actual processing. + Inkscape::XML::SimpleDocument *tempdoc = new Inkscape::XML::SimpleDocument; + Inkscape::XML::Node *tempnode = tempdoc->createElement("prefs"); - if (style->text && parent->text) { - if (!style->text->font_family.set || style->text->font_family.inherit) { - g_free(style->text->font_family.value); - style->text->font_family.value = g_strdup(parent->text->font_family.value); - } + std::vector<Inkscape::Preferences::Entry> attrs = prefs->getAllEntries(path); + for (std::vector<Inkscape::Preferences::Entry>::iterator i = attrs.begin(); i != attrs.end(); ++i) { + tempnode->setAttribute(i->getEntryName().data(), i->getString().data()); } - if (style->text && parent->text) { - if (!style->text->font_specification.set || style->text->font_specification.inherit) { - g_free(style->text->font_specification.value); - style->text->font_specification.value = g_strdup(parent->text->font_specification.value); - } - } + style->read( NULL, tempnode ); - /* Markers - Free the old value and make copy of the new */ - for (unsigned i = SP_MARKER_LOC; i < SP_MARKER_LOC_QTY; i++) { - if (!style->marker[i].set || style->marker[i].inherit) { - g_free(style->marker[i].value); - style->marker[i].value = g_strdup(parent->marker[i].value); - } - } + Inkscape::GC::release(tempnode); + Inkscape::GC::release(tempdoc); + delete tempdoc; +} - /* Filter effects */ - if (style->filter.inherit) { - sp_style_merge_ifilter(style, &parent->filter); - } - if(style->enable_background.inherit) { - style->enable_background.value = parent->enable_background.value; - } +static CRSelEng * +sp_repr_sel_eng() +{ + CRSelEng *const ret = cr_sel_eng_new(); + cr_sel_eng_set_node_iface(ret, &Inkscape::XML::croco_node_iface); - /* Clipping */ - if (!style->clip_rule.set || style->clip_rule.inherit) { - style->clip_rule.computed = parent->clip_rule.computed; - } + /** \todo + * Check whether we need to register any pseudo-class handlers. + * libcroco has its own default handlers for first-child and lang. + * + * We probably want handlers for link and arguably visited (though + * inkscape can't visit links at the time of writing). hover etc. + * more useful in inkview than the editor inkscape. + * + * http://www.w3.org/TR/SVG11/styling.html#StylingWithCSS says that + * the following should be honoured, at least by inkview: + * :hover, :active, :focus, :visited, :link. + */ - /* Rendering */ - if (!style->color_rendering.set || style->color_rendering.inherit) { - style->color_rendering.computed = parent->color_rendering.computed; - } - if (!style->image_rendering.set || style->image_rendering.inherit) { - style->image_rendering.computed = parent->image_rendering.computed; - } - if (!style->shape_rendering.set || style->shape_rendering.inherit) { - style->shape_rendering.computed = parent->shape_rendering.computed; - } - if (!style->text_rendering.set || style->text_rendering.inherit) { - style->text_rendering.computed = parent->text_rendering.computed; - } + g_assert(ret); + return ret; } -template <typename T> -static void -sp_style_merge_prop_from_dying_parent(T &child, T const &parent) -{ - if ( ( !(child.set) || child.inherit ) - && parent.set && !(parent.inherit) ) - { - child = parent; - } -} +// Called in text-editting.cpp, ui/tools/frehand-base.cpp, ui/widget/style-swatch.cpp /** - * Copy SPIString from parent to child. + * Parses a style="..." string and merges it with an existing SPStyle. */ -static void -sp_style_merge_string_prop_from_dying_parent(SPIString &child, SPIString const &parent) -{ - if ( ( !(child.set) || child.inherit ) - && parent.set && !(parent.inherit) ) - { - g_free(child.value); - child.value = g_strdup(parent.value); - child.set = parent.set; - child.inherit = parent.inherit; - } -} - -static void -sp_style_merge_paint_prop_from_dying_parent(SPStyle *style, - SPIPaint &child, SPIPaint const &parent) +void +sp_style_merge_from_style_string(SPStyle *const style, gchar const *const p) { - /** \todo - * I haven't given this much attention. See comments below about - * currentColor, colorProfile, and relative URIs. + // std::cout << "sp_style_merge_from_style_string: " << (p?p:"null") <<std::endl; + /* + * Reference: http://www.w3.org/TR/SVG11/styling.html#StyleAttribute: + * ``When CSS styling is used, CSS inline style is specified by including + * semicolon-separated property declarations of the form "name : value" + * within the style attribute''. + * + * That's fairly ambiguous. Is a `value' allowed to contain semicolons? + * Why does it say "including", what else is allowed in the style + * attribute value? */ - if (!child.set || child.inherit) { - sp_style_merge_ipaint(style, &child, &parent); - child.set = parent.set; - child.inherit = parent.inherit; - } + style->_mergeString( p ); } -static void -sp_style_merge_rel_enum_prop_from_dying_parent(SPIEnum &child, SPIEnum const &parent, - unsigned const max_computed_val, - unsigned const smaller_val) -{ - /* We assume that min computed val is 0, contiguous up to max_computed_val, - then zero or more other absolute values, then smaller_val then larger_val. */ - unsigned const min_computed_val = 0; - unsigned const larger_val = smaller_val + 1; - g_return_if_fail(min_computed_val < max_computed_val); - g_return_if_fail(max_computed_val < smaller_val); - - if (parent.set && !parent.inherit) { - if (!child.set || child.inherit) { - child.value = parent.value; - child.set = parent.set; // i.e. true - child.inherit = parent.inherit; // i.e. false - } else if (child.value < smaller_val) { - /* Child has absolute value: leave as is. */ - } else if ( ( child.value == smaller_val - && parent.value == larger_val ) - || ( parent.value == smaller_val - && child.value == larger_val ) ) - { - child.set = false; - /* - * Note that this can result in a change in computed value in the - * rare case that the parent's setting was a no-op (i.e. if the - * parent's parent's computed value was already ultra-condensed or - * ultra-expanded). However, I'd guess that the change is for the - * better: I'd guess that if the properties were specified - * relatively, then the intent is to counteract parent's effect. - * I.e. I believe this is the best code even in that case. - */ - } else if (child.value == parent.value) { - /* Leave as is. */ - /** \todo - * It's unclear what to do if style and parent specify the same - * relative directive (narrower or wider). We can either convert - * to absolute specification or coalesce to a single relative - * request (of half the strength of the original pair). - * - * Converting to a single level of relative specification is a - * better choice if the newly-unlinked clone is itself cloned to - * other contexts (inheriting different font stretchiness): it - * would preserve the effect that it will be narrower than - * the inherited context in each case. The disadvantage is that - * it will ~certainly affect the computed value of the - * newly-unlinked clone. - */ - } else { - unsigned const parent_val = parent.computed; - child.value = ( child.value == smaller_val - ? ( parent_val == min_computed_val - ? parent_val - : parent_val - 1 ) - : ( parent_val == max_computed_val - ? parent_val - : parent_val + 1 ) ); - g_assert(child.value <= max_computed_val); - child.inherit = false; - g_assert(child.set); - } - } -} - -template <typename LengthT> -static void -sp_style_merge_length_prop_from_dying_parent(LengthT &child, LengthT const &parent, - double const parent_child_em_ratio) -{ - if ( ( !(child.set) || child.inherit ) - && parent.set && !(parent.inherit) ) - { - child = parent; - switch (parent.unit) { - case SP_CSS_UNIT_EM: - case SP_CSS_UNIT_EX: - child.value *= parent_child_em_ratio; - /** \todo - * fixme: Have separate ex ratio parameter. - * Get x height from libnrtype or pango. - */ - if (!IS_FINITE(child.value)) { - child.value = child.computed; - child.unit = SP_CSS_UNIT_NONE; - } - break; - - default: - break; - } - } -} +/** Indexed by SP_CSS_FONT_SIZE_blah. These seem a bit small */ +static float const font_size_table[] = {6.0, 8.0, 10.0, 12.0, 14.0, 18.0, 24.0}; -static double -get_relative_font_size_frac(SPIFontSize const &font_size) +// Called in sp-object.cpp, sp-tref.cpp, sp-use.cpp +/** + * Sets computed values in \a style, which may involve inheriting from (or in some other way + * calculating from) corresponding computed values of \a parent. + * + * References: http://www.w3.org/TR/SVG11/propidx.html shows what properties inherit by default. + * http://www.w3.org/TR/SVG11/styling.html#Inheritance gives general rules as to what it means to + * inherit a value. http://www.w3.org/TR/REC-CSS2/cascade.html#computed-value is more precise + * about what the computed value is (not obvious for lengths). + * + * \pre \a parent's computed values are already up-to-date. + */ +void +sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent) { - switch (font_size.type) { - case SP_FONT_SIZE_LITERAL: { - switch (font_size.literal) { - case SP_CSS_FONT_SIZE_SMALLER: - return 5.0 / 6.0; - - case SP_CSS_FONT_SIZE_LARGER: - return 6.0 / 5.0; - - default: - g_assert_not_reached(); - } - } - - case SP_FONT_SIZE_PERCENTAGE: - return font_size.value; - - case SP_FONT_SIZE_LENGTH: { - switch (font_size.unit ) { - case SP_CSS_UNIT_EM: - return font_size.value; + // std::cout << "sp_style_merge_from_parent" << std::endl; + g_return_if_fail(style != NULL); - case SP_CSS_UNIT_EX: - return font_size.value * 0.5; + if (!parent) + return; - default: - g_assert_not_reached(); - } - } - } - g_assert_not_reached(); + style->cascade( parent ); + return; } +// Called in: sp-use.cpp, sp-tref.cpp, sp-item.cpp /** * Combine \a style and \a parent style specifications into a single style specification that * preserves (as much as possible) the effect of the existing \a style being a child of \a parent. @@ -2140,370 +1335,16 @@ get_relative_font_size_frac(SPIFontSize const &font_size) void sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const parent) { - /** \note - * The general rule for each property is as follows: - * - * If style is set to an absolute value, then leave it as is. - * - * Otherwise (i.e. if style has a relative value): - * - * If parent is set to an absolute value, then set style to the computed value. - * - * Otherwise, calculate the combined relative value (e.g. multiplying the two percentages). - */ - - /* We do font-size first, to ensure that em size is up-to-date. */ - /** \todo - * fixme: We'll need to have more font-related things up the top once - * we're getting x-height from pango or libnrtype. - */ - - /* Some things that allow relative specifications. */ - { - /* font-size. Note that we update the computed font-size of style, - to assist in em calculations later in this function. */ - - if (parent->font_size.set && !parent->font_size.inherit) { - /* Parent has defined font-size */ - - if (!style->font_size.set || style->font_size.inherit) { - /* font_size inherits the computed value, so we can use the parent value - * verbatim. */ - style->font_size = parent->font_size; - - } else if ( style->font_size.type == SP_FONT_SIZE_LENGTH && - style->font_size.unit != SP_CSS_UNIT_EM && - style->font_size.unit != SP_CSS_UNIT_EX ) { - - /* Child already has absolute size (stored in computed value), so do nothing. */ - - } else if ( style->font_size.type == SP_FONT_SIZE_LITERAL - && style->font_size.literal < SP_CSS_FONT_SIZE_SMALLER ) { - /* Child already has absolute size, but we ensure that the computed value - is up-to-date. */ - unsigned const ix = style->font_size.literal; - g_assert(ix < G_N_ELEMENTS(font_size_table)); - style->font_size.computed = font_size_table[ix]; - - } else { - /* Child has relative size. */ - double const child_frac(get_relative_font_size_frac(style->font_size)); - style->font_size.set = true; - style->font_size.inherit = false; - style->font_size.computed = parent->font_size.computed * child_frac; - - if ( ( parent->font_size.type == SP_FONT_SIZE_LITERAL - && parent->font_size.literal < SP_CSS_FONT_SIZE_SMALLER ) || - ( parent->font_size.type == SP_FONT_SIZE_LENGTH && - parent->font_size.unit != SP_CSS_UNIT_EM && - parent->font_size.unit != SP_CSS_UNIT_EX ) ) { - - /* Absolute value. */ - style->font_size.type = SP_FONT_SIZE_LENGTH; - /* .value is unused for non ex/em SP_FONT_SIZE_LENGTH. */ - - } else { - /* Relative value. */ - - double const parent_frac(get_relative_font_size_frac(parent->font_size)); - if( style->font_size.type == SP_FONT_SIZE_LENGTH ) { - /* Value in terms of ex/em */ - style->font_size.value *= parent_frac; - } else { - style->font_size.value = parent_frac * child_frac; - style->font_size.type = SP_FONT_SIZE_PERCENTAGE; - } - } - } - } - - /* 'font-stretch' */ - sp_style_merge_rel_enum_prop_from_dying_parent(style->font_stretch, - parent->font_stretch, - SP_CSS_FONT_STRETCH_ULTRA_EXPANDED, - SP_CSS_FONT_STRETCH_NARROWER); - - /* font-weight */ - sp_style_merge_rel_enum_prop_from_dying_parent(style->font_weight, - parent->font_weight, - SP_CSS_FONT_WEIGHT_900, - SP_CSS_FONT_WEIGHT_LIGHTER); - } - - - /* Enum values that don't have any relative settings (other than `inherit'). */ - { - SPIEnum SPStyle::*const fields[] = { - &SPStyle::blend_mode, - &SPStyle::clip_rule, - &SPStyle::color_interpolation, - &SPStyle::color_interpolation_filters, - &SPStyle::color_rendering, - &SPStyle::direction, - &SPStyle::fill_rule, - &SPStyle::font_style, - &SPStyle::font_variant, - &SPStyle::image_rendering, - &SPStyle::isolation, - //nyi: SPStyle::pointer_events, - &SPStyle::shape_rendering, - &SPStyle::stroke_linecap, - &SPStyle::stroke_linejoin, - &SPStyle::text_anchor, - &SPStyle::text_rendering, - &SPStyle::visibility, - &SPStyle::writing_mode - }; - - for (unsigned i = 0; i < G_N_ELEMENTS(fields); ++i) { - SPIEnum SPStyle::*const fld = fields[i]; - sp_style_merge_prop_from_dying_parent<SPIEnum>(style->*fld, parent->*fld); - } - } - - /* A few other simple inheritance properties. */ - { - sp_style_merge_prop_from_dying_parent<SPIScale24>(style->fill_opacity, parent->fill_opacity); - sp_style_merge_prop_from_dying_parent<SPIScale24>(style->stroke_opacity, parent->stroke_opacity); - sp_style_merge_prop_from_dying_parent<SPIFloat>(style->stroke_miterlimit, parent->stroke_miterlimit); - - /** \todo - * We currently treat text-decoration as if it were a simple inherited - * property (fixme). This code may need changing once we do the - * special fill/stroke inheritance mentioned by the spec. - */ - sp_style_merge_prop_from_dying_parent<SPITextDecorationLine>( style->text_decoration_line, parent->text_decoration_line); - sp_style_merge_prop_from_dying_parent<SPITextDecorationStyle>(style->text_decoration_style, parent->text_decoration_style); - sp_style_merge_paint_prop_from_dying_parent(style,style->text_decoration_color, parent->text_decoration_color); - - //nyi: font-size-adjust, // <number> | none | inherit - //nyi: glyph-orientation-horizontal, - //nyi: glyph-orientation-vertical, - } - - /* Properties that involve length but are easy in other respects. */ - { - /* The difficulty with lengths is that font-relative units need adjusting if the font - * varies between parent & child. - * - * Lengths specified in the existing child can stay as they are: its computed font - * specification should stay unchanged, so em & ex lengths should continue to mean the same - * size. - * - * Lengths specified in the dying parent in em or ex need to be scaled according to the - * ratio of em or ex size between parent & child. - */ - double const parent_child_em_ratio = parent->font_size.computed / style->font_size.computed; - - SPILength SPStyle::*const lfields[] = { - &SPStyle::stroke_width, - &SPStyle::text_indent - }; - for (unsigned i = 0; i < G_N_ELEMENTS(lfields); ++i) { - SPILength SPStyle::*fld = lfields[i]; - sp_style_merge_length_prop_from_dying_parent<SPILength>(style->*fld, - parent->*fld, - parent_child_em_ratio); - } - - SPILengthOrNormal SPStyle::*const nfields[] = { - &SPStyle::letter_spacing, - &SPStyle::line_height, - &SPStyle::word_spacing - }; - for (unsigned i = 0; i < G_N_ELEMENTS(nfields); ++i) { - SPILengthOrNormal SPStyle::*fld = nfields[i]; - sp_style_merge_length_prop_from_dying_parent<SPILengthOrNormal>(style->*fld, - parent->*fld, - parent_child_em_ratio); - } - - //nyi: &SPStyle::kerning: length or `auto' - - /* fixme: Move stroke-dash and stroke-dash-offset here once they - can accept units. */ - } - - /* Properties that involve a URI but are easy in other respects. */ - { - /** \todo - * Could cause problems if original object was in another document - * and it used a relative URL. (At the time of writing, we don't - * allow hrefs to other documents, so this isn't a problem yet.) - * Paint properties also allow URIs. - */ - //nyi: cursor, // may involve change in effect, but we can't do much better - //nyi: color-profile, - - // Markers (marker-start, marker-mid, marker-end). - for (unsigned i = SP_MARKER_LOC; i < SP_MARKER_LOC_QTY; i++) { - sp_style_merge_string_prop_from_dying_parent(style->marker[i], parent->marker[i]); - } - } - - /* CSS2 */ - /* Font */ - - if (style->text && parent->text) { - sp_style_merge_string_prop_from_dying_parent(style->text->font_specification, - parent->text->font_specification); - - sp_style_merge_string_prop_from_dying_parent(style->text->font_family, - parent->text->font_family); - } - - - /* Properties that don't inherit by default. Most of these need special handling. */ - { - /* - * opacity's effect is cumulative; we set the new value to the combined effect. The - * default value for opacity is 1.0, not inherit. (Note that stroke-opacity and - * fill-opacity are quite different from opacity, and don't need any special handling.) - * - * Cases: - * - parent & child were each previously unset, in which case the effective - * opacity value is 1.0, and style should remain unset. - * - parent was previously unset (so computed opacity value of 1.0) - * and child was set to inherit. The merged child should - * get a value of 1.0, and shouldn't inherit (lest the new parent - * has a different opacity value). Given that opacity's default - * value is 1.0 (rather than inherit), we might as well have the - * merged child's opacity be unset. - * - parent was previously unset (so opacity 1.0), and child was set to a number. - * The merged child should retain its existing settings (though it doesn't matter - * if we make it unset if that number was 1.0). - * - parent was inherit and child was unset. Merged child should be set to inherit. - * - parent was inherit and child was inherit. (We can't in general reproduce this - * effect (short of introducing a new group), but setting opacity to inherit is rare.) - * If the inherited value was strictly between 0.0 and 1.0 (exclusive) then the merged - * child's value should be set to the product of the two, i.e. the square of the - * inherited value, and should not be marked as inherit. (This decision assumes that it - * is more important to retain the effective opacity than to retain the inheriting - * effect, and assumes that the inheriting effect either isn't important enough to create - * a group or isn't common enough to bother maintaining the code to create a group.) If - * the inherited value was 0.0 or 1.0, then marking the merged child as inherit comes - * closer to maintaining the effect. - * - parent was inherit and child was set to a numerical value. If the child's value - * was 1.0, then the merged child should have the same settings as the parent. - * If the child's value was 0, then the merged child should also be set to 0. - * If the child's value was anything else, then we do the same as for the inherit/inherit - * case above: have the merged child set to the product of the two opacities and not - * marked as inherit, for the same reasons as for that case. - * - parent was set to a value, and child was unset. The merged child should have - * parent's settings. - * - parent was set to a value, and child was inherit. The merged child should - * be set to the product, i.e. the square of the parent's value. - * - parent & child are each set to a value. The merged child should be set to the - * product. - */ - if ( !style->opacity.set - || ( !style->opacity.inherit - && style->opacity.value == SP_SCALE24_MAX ) ) - { - style->opacity = parent->opacity; - } else { - /* Ensure that style's computed value is up-to-date. */ - if (style->opacity.inherit) { - style->opacity.value = parent->opacity.value; - } - - /* Multiplication of opacities occurs even if a child's opacity is set to inherit. */ - style->opacity.value = SP_SCALE24_MUL(style->opacity.value, - parent->opacity.value); - - style->opacity.inherit = (parent->opacity.inherit - && style->opacity.inherit - && (parent->opacity.value == 0 || - parent->opacity.value == SP_SCALE24_MAX)); - style->opacity.set = ( style->opacity.inherit - || style->opacity.value < SP_SCALE24_MAX ); - } - - /* display is in principle similar to opacity, but implementation is easier. */ - if ( parent->display.set && !parent->display.inherit - && parent->display.value == SP_CSS_DISPLAY_NONE ) { - style->display.value = SP_CSS_DISPLAY_NONE; - style->display.set = true; - style->display.inherit = false; - } else if (style->display.inherit) { - style->display.value = parent->display.value; - style->display.set = parent->display.set; - style->display.inherit = parent->display.inherit; - } else { - /* Leave as is. (display doesn't inherit by default.) */ - } - - /* enable-background - this is rather complicated, because - * it is valid only when applied to container elements. - * Let's check a simple case anyhow. */ - if (parent->enable_background.set - && !parent->enable_background.inherit - && style->enable_background.inherit) - { - style->enable_background.set = true; - style->enable_background.inherit = false; - style->enable_background.value = parent->enable_background.value; - } - - if (!style->filter.set || style->filter.inherit) - { - sp_style_merge_ifilter(style, &parent->filter); - + // std::cout << "sp_style_merge_from_dying_parent" << std::endl; + style->merge( parent ); } - /** \todo - * fixme: Check that we correctly handle all properties that don't - * inherit by default (as shown in - * http://www.w3.org/TR/SVG11/propidx.html for most SVG 1.1 properties). - */ - } - - /* SPIPaint properties (including color). */ - { - /** \todo - * Think about the issues involved if specified as currentColor or - * if specified relative to colorProfile, and if the currentColor or - * colorProfile differs between parent \& child. See also comments - * elsewhere in this function about URIs. - */ - SPIPaint SPStyle::*const fields[] = { - &SPStyle::color, - &SPStyle::fill, - &SPStyle::stroke - }; - for (unsigned i = 0; i < G_N_ELEMENTS(fields); ++i) { - SPIPaint SPStyle::*const fld = fields[i]; - sp_style_merge_paint_prop_from_dying_parent(style, style->*fld, parent->*fld); - } - } - - /* Things from SVG 1.2 or CSS3. */ - { - /* Note: If we ever support setting string values for text-align then we'd need strdup - * handling here. */ - sp_style_merge_prop_from_dying_parent<SPIEnum>(style->text_align, parent->text_align); - - sp_style_merge_prop_from_dying_parent<SPIEnum>(style->text_transform, parent->text_transform); - sp_style_merge_prop_from_dying_parent<SPIEnum>(style->block_progression, parent->block_progression); - } - - /* Note: this will need length handling once dasharray supports units. */ - if ( ( !style->stroke_dasharray.set || style->stroke_dasharray.inherit ) - && parent->stroke_dasharray.set && !parent->stroke_dasharray.inherit ) - { - style->stroke_dasharray.values = parent->stroke_dasharray.values; - style->stroke_dasharray.set = parent->stroke_dasharray.set; - style->stroke_dasharray.inherit = parent->stroke_dasharray.inherit; - } - { - sp_style_merge_prop_from_dying_parent<SPILength>(style->stroke_dashoffset, parent->stroke_dashoffset); - } -} - - -static void +// The following functions should be incorporated into SPIPaint. FIXME +// Called in: style.cpp, style-internal.cpp +void sp_style_set_ipaint_to_uri(SPStyle *style, SPIPaint *paint, const Inkscape::URI *uri, SPDocument *document) { + // std::cout << "sp_style_set_ipaint_to_uri: Entrance: " << uri << " " << (void*)document << std::endl; // it may be that this style's SPIPaint has not yet created its URIReference; // now that we have a document, we can create it here if (!paint->value.href && document) { @@ -2525,7 +1366,8 @@ sp_style_set_ipaint_to_uri(SPStyle *style, SPIPaint *paint, const Inkscape::URI } } -static void +// Called in: style.cpp, style-internal.cpp +void sp_style_set_ipaint_to_uri_string (SPStyle *style, SPIPaint *paint, const gchar *uri) { try { @@ -2536,12 +1378,14 @@ sp_style_set_ipaint_to_uri_string (SPStyle *style, SPIPaint *paint, const gchar } } +// Called in: desktop-style.cpp void sp_style_set_to_uri_string (SPStyle *style, bool isfill, const gchar *uri) { sp_style_set_ipaint_to_uri_string (style, isfill? &style->fill : &style->stroke, uri); } +// Called in: widgets/font-selector.cpp, widgets/text-toolbar.cpp, ui/dialog/text-edit.cpp gchar const * sp_style_get_css_unit_string(int unit) { @@ -2564,6 +1408,7 @@ sp_style_get_css_unit_string(int unit) return "px"; } +// Called in: style-internal.cpp, widgets/text-toolbar.cpp, ui/dialog/text-edit.cpp /* * Convert a size in pixels into another CSS unit size */ @@ -2592,6 +1437,7 @@ sp_style_css_size_px_to_units(double size, int unit) return unit_size; } +// Called in: widgets/text-toolbar.cpp, ui/dialog/text-edit.cpp /* * Convert a size in a CSS unit size to pixels */ @@ -2604,82 +1450,8 @@ sp_style_css_size_units_to_px(double size, int unit) //g_message("sp_style_css_size_units_to_px %f %d = %f px", size, unit, out); return size * (size / sp_style_css_size_px_to_units(size, unit));; } -/** - * - */ -static void -sp_style_merge_ipaint(SPStyle *style, SPIPaint *paint, SPIPaint const *parent) -{ - if ((paint->set && paint->currentcolor) || parent->currentcolor) { - bool isset = paint->set; - paint->clear(); - paint->set = isset; - paint->currentcolor = TRUE; - paint->setColor(style->color.value.color); - return; - } - - paint->clear(); - if ( parent->isPaintserver() ) { - if (parent->value.href) { - sp_style_set_ipaint_to_uri(style, paint, parent->value.href->getURI(), parent->value.href->getOwnerDocument()); - } else { - g_warning("Expected paint server not found."); - } - } else if ( parent->isColor() ) { - paint->setColor( parent->value.color ); - } else if ( parent->isNoneSet() ) { - paint->noneSet = TRUE; - } else if ( parent->isNone() ) { - // - } else { - g_assert_not_reached(); - } -} - - -/** - * Merge filter style from parent. - * Filter effects do not inherit by default - */ -static void -sp_style_merge_ifilter(SPStyle *style, SPIFilter const *parent) -{ - // FIXME: - // instead of just copying over, we need to _really merge_ the two filters by combining their - // filter primitives - - sp_style_filter_clear(style); - style->filter.set = parent->set; - style->filter.inherit = parent->inherit; - - if (style->filter.href){ - if (style->filter.href->getObject()){ - style->filter.href->detach(); - } - } - else{ - // it may be that this style has not yet created its SPFilterReference - if (style->object){ - if (style->object->document) { - style->filter.href = new SPFilterReference(style->object->document); - style->filter.href->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_style_filter_ref_changed), style)); - } - } - } - - if (style->filter.href && parent->href){ - if (parent->href->getObject()) { - try { - style->filter.href->attach(*parent->href->getURI()); - } catch (Inkscape::BadURIException &e) { - g_warning("%s", e.what()); - style->filter.href->detach(); - } - } - } -} +// Called in style.cpp, text-editing.cpp /** * Dumps the style to a CSS string, with either SP_STYLE_FLAG_IFSET or * SP_STYLE_FLAG_ALWAYS flags. Used with Always for copying an object's @@ -2702,146 +1474,11 @@ sp_style_write_string(SPStyle const *const style, guint const flags) (flags == SP_STYLE_FLAG_ALWAYS) ), NULL); - gchar c[BMAX]; - gchar *p = c; - *p = '\0'; - - p += sp_style_write_ifontsize(p, c + BMAX - p, "font-size", &style->font_size, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "font-style", enum_font_style, &style->font_style, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "font-variant", enum_font_variant, &style->font_variant, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "font-weight", enum_font_weight, &style->font_weight, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "font-stretch", enum_font_stretch, &style->font_stretch, NULL, flags); - - /* Text */ - p += sp_style_write_ilength(p, c + BMAX - p, "text-indent", &style->text_indent, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "text-align", enum_text_align, &style->text_align, NULL, flags); - p += sp_style_write_itextdecoration(p, c + BMAX - p, "text-decoration", - &style->text_decoration_line, &style->text_decoration_style, &style->text_decoration_color, - NULL, NULL, NULL, flags); - p += sp_style_write_ilengthornormal(p, c + BMAX - p, "line-height", &style->line_height, NULL, flags); - p += sp_style_write_ilengthornormal(p, c + BMAX - p, "letter-spacing", &style->letter_spacing, NULL, flags); - p += sp_style_write_ilengthornormal(p, c + BMAX - p, "word-spacing", &style->word_spacing, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "text-transform", enum_text_transform, &style->text_transform, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "direction", enum_direction, &style->direction, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "block-progression", enum_block_progression, &style->block_progression, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "writing-mode", enum_writing_mode, &style->writing_mode, NULL, flags); - - p += sp_style_write_ienum(p, c + BMAX - p, "text-anchor", enum_text_anchor, &style->text_anchor, NULL, flags); - p += sp_style_write_ibaselineshift(p, c + BMAX - p, "baseline-shift", &style->baseline_shift, NULL, flags); - - - /// \todo fixme: Per type methods need default flag too (lauris) - - if (style->opacity.value != SP_SCALE24_MAX) { - p += sp_style_write_iscale24(p, c + BMAX - p, "opacity", &style->opacity, NULL, flags); - } - - if (!style->color.noneSet) { // CSS does not permit "none" for color - p += sp_style_write_ipaint(p, c + BMAX - p, "color", &style->color, NULL, flags); - } - p += sp_style_write_ienum(p, c + BMAX - p, "color-interpolation", enum_color_interpolation, &style->color_interpolation, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "color-interpolation-filters", enum_color_interpolation, &style->color_interpolation_filters, NULL, flags); - - - p += sp_style_write_ipaint(p, c + BMAX - p, "fill", &style->fill, NULL, flags); - // if fill:none, skip writing fill properties - if (!style->fill.noneSet) { - p += sp_style_write_iscale24(p, c + BMAX - p, "fill-opacity", &style->fill_opacity, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "fill-rule", enum_fill_rule, &style->fill_rule, NULL, flags); - } - - p += sp_style_write_ipaint(p, c + BMAX - p, "stroke", &style->stroke, NULL, flags); - - // stroke width affects markers, so write it if there's stroke OR any markers - if (!style->stroke.noneSet || - style->marker[SP_MARKER_LOC].set || - style->marker[SP_MARKER_LOC_START].set || - style->marker[SP_MARKER_LOC_MID].set || - style->marker[SP_MARKER_LOC_END].set) { - p += sp_style_write_ilength(p, c + BMAX - p, "stroke-width", &style->stroke_width, NULL, flags); - } - - // if stroke:none, skip writing stroke properties - if (!style->stroke.noneSet) { - p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linecap", enum_stroke_linecap, &style->stroke_linecap, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linejoin", enum_stroke_linejoin, &style->stroke_linejoin, NULL, flags); - p += sp_style_write_ifloat(p, c + BMAX - p, "stroke-miterlimit", &style->stroke_miterlimit, NULL, flags); - p += sp_style_write_iscale24(p, c + BMAX - p, "stroke-opacity", &style->stroke_opacity, NULL, flags); - p += sp_style_write_idasharray(p, c + BMAX - p, "stroke-dasharray", &style->stroke_dasharray, NULL, flags); - p += sp_style_write_ilength(p, c + BMAX - p, "stroke-dashoffset", &style->stroke_dashoffset, NULL, flags); - } - - if (style->paint_order.set) { - p += sp_style_write_ipaintorder(p, c + BMAX - p, "paint-order", &style->paint_order, NULL, flags); - } else if (flags == SP_STYLE_FLAG_ALWAYS) { - p += g_snprintf(p, c + BMAX - p, "paint-order:normal;"); - } - - bool marker_none = false; - gchar *master = style->marker[SP_MARKER_LOC].value; - if (style->marker[SP_MARKER_LOC].set) { - p += g_snprintf(p, c + BMAX - p, "marker:%s;", style->marker[SP_MARKER_LOC].value); - } else if (flags == SP_STYLE_FLAG_ALWAYS) { - p += g_snprintf(p, c + BMAX - p, "marker:none;"); - marker_none = true; - } - if (style->marker[SP_MARKER_LOC_START].set - && (!master || strcmp(master, style->marker[SP_MARKER_LOC_START].value))) { - p += g_snprintf(p, c + BMAX - p, "marker-start:%s;", style->marker[SP_MARKER_LOC_START].value); - } else if (flags == SP_STYLE_FLAG_ALWAYS && !marker_none) { - p += g_snprintf(p, c + BMAX - p, "marker-start:none;"); - } - if (style->marker[SP_MARKER_LOC_MID].set - && (!master || strcmp(master, style->marker[SP_MARKER_LOC_MID].value))) { - p += g_snprintf(p, c + BMAX - p, "marker-mid:%s;", style->marker[SP_MARKER_LOC_MID].value); - } else if (flags == SP_STYLE_FLAG_ALWAYS && !marker_none) { - p += g_snprintf(p, c + BMAX - p, "marker-mid:none;"); - } - if (style->marker[SP_MARKER_LOC_END].set - && (!master || strcmp(master, style->marker[SP_MARKER_LOC_END].value))) { - p += g_snprintf(p, c + BMAX - p, "marker-end:%s;", style->marker[SP_MARKER_LOC_END].value); - } else if (flags == SP_STYLE_FLAG_ALWAYS && !marker_none) { - p += g_snprintf(p, c + BMAX - p, "marker-end:none;"); - } - - p += sp_style_write_ienum(p, c + BMAX - p, "visibility", enum_visibility, &style->visibility, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "display", enum_display, &style->display, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "overflow", enum_overflow, &style->overflow, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "isolation", enum_isolation, &style->isolation, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "mix-blend-mode", enum_blend_mode, &style->blend_mode, NULL, flags); - - /* filter: */ - p += sp_style_write_ifilter(p, c + BMAX - p, "filter", &style->filter, NULL, flags); - - p += sp_style_write_ienum(p, c + BMAX - p, "enable-background", enum_enable_background, &style->enable_background, NULL, flags); - - /* clipping */ - p += sp_style_write_ienum(p, c + BMAX - p, "clip-rule", enum_clip_rule, &style->clip_rule, NULL, flags); - - /* rendering */ - p += sp_style_write_ienum(p, c + BMAX - p, "color-rendering", enum_color_rendering, &style->color_rendering, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "image-rendering", enum_image_rendering, &style->image_rendering, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "shape-rendering", enum_shape_rendering, &style->shape_rendering, NULL, flags); - p += sp_style_write_ienum(p, c + BMAX - p, "text-rendering", enum_text_rendering, &style->text_rendering, NULL, flags); - - /* fixme: */ - p += sp_text_style_write(p, c + BMAX - p, style->text, flags); - - /* Get rid of trailing `;'. */ - if (p != c) { - --p; - if (*p == ';') { - *p = '\0'; - } - } - - return g_strdup(c); + return g_strdup( style->write( flags ).c_str() ); } -#define STYLE_BUF_MAX - - +// Called in style.cpp, path-chemistry, NOT in text-editting.cpp (because of bug) /** * Dumps style to CSS string, see sp_style_write_string() * @@ -2855,2016 +1492,7 @@ sp_style_write_difference(SPStyle const *const from, SPStyle const *const to) g_return_val_if_fail(from != NULL, NULL); g_return_val_if_fail(to != NULL, NULL); - gchar c[BMAX], *p = c; - *p = '\0'; - - p += sp_style_write_ifontsize(p, c + BMAX - p, "font-size", &from->font_size, &to->font_size, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "font-style", enum_font_style, &from->font_style, &to->font_style, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "font-variant", enum_font_variant, &from->font_variant, &to->font_variant, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "font-weight", enum_font_weight, &from->font_weight, &to->font_weight, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "font-stretch", enum_font_stretch, &from->font_stretch, &to->font_stretch, SP_STYLE_FLAG_IFDIFF); - - /* Text */ - p += sp_style_write_ilength(p, c + BMAX - p, "text-indent", &from->text_indent, &to->text_indent, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "text-align", enum_text_align, &from->text_align, &to->text_align, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_itextdecoration(p, c + BMAX - p, "text-decoration", - &from->text_decoration_line, &from->text_decoration_style, &from->text_decoration_color, - &to->text_decoration_line, &to->text_decoration_style, &to->text_decoration_color, - SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ilengthornormal(p, c + BMAX - p, "line-height", &from->line_height, &to->line_height, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ilengthornormal(p, c + BMAX - p, "letter-spacing", &from->letter_spacing, &to->letter_spacing, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ilengthornormal(p, c + BMAX - p, "word-spacing", &from->word_spacing, &to->word_spacing, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "text-transform", enum_text_transform, &from->text_transform, &to->text_transform, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "direction", enum_direction, &from->direction, &to->direction, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "block-progression", enum_block_progression, &from->block_progression, &to->block_progression, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "writing-mode", enum_writing_mode, &from->writing_mode, &to->writing_mode, SP_STYLE_FLAG_IFDIFF); - - p += sp_style_write_ienum(p, c + BMAX - p, "text-anchor", enum_text_anchor, &from->text_anchor, &to->text_anchor, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ibaselineshift(p, c + BMAX - p, "baseline-shift", &from->baseline_shift, &to->baseline_shift, SP_STYLE_FLAG_IFDIFF); - - /// \todo fixme: Per type methods need default flag too - if (from->opacity.set && from->opacity.value != SP_SCALE24_MAX) { - p += sp_style_write_iscale24(p, c + BMAX - p, "opacity", &from->opacity, &to->opacity, SP_STYLE_FLAG_IFSET); - } - - if (!from->color.noneSet) { // CSS does not permit "none" for color - p += sp_style_write_ipaint(p, c + BMAX - p, "color", &from->color, &to->color, SP_STYLE_FLAG_IFSET); - } - p += sp_style_write_ienum(p, c + BMAX - p, "color-interpolation", enum_color_interpolation, &from->color_interpolation, &to->color_interpolation, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "color-interpolation-filters", enum_color_interpolation, &from->color_interpolation_filters, &to->color_interpolation_filters, SP_STYLE_FLAG_IFDIFF); - - p += sp_style_write_ipaint(p, c + BMAX - p, "fill", &from->fill, &to->fill, SP_STYLE_FLAG_IFDIFF); - // if fill:none, skip writing fill properties - if (!from->fill.noneSet) { - p += sp_style_write_iscale24(p, c + BMAX - p, "fill-opacity", &from->fill_opacity, &to->fill_opacity, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "fill-rule", enum_fill_rule, &from->fill_rule, &to->fill_rule, SP_STYLE_FLAG_IFDIFF); - } - - p += sp_style_write_ipaint(p, c + BMAX - p, "stroke", &from->stroke, &to->stroke, SP_STYLE_FLAG_IFDIFF); - - // stroke width affects markers, so write it if there's stroke OR any markers - if (!from->stroke.noneSet || - from->marker[SP_MARKER_LOC].set || - from->marker[SP_MARKER_LOC_START].set || - from->marker[SP_MARKER_LOC_MID].set || - from->marker[SP_MARKER_LOC_END].set) { - p += sp_style_write_ilength(p, c + BMAX - p, "stroke-width", &from->stroke_width, &to->stroke_width, SP_STYLE_FLAG_IFDIFF); - } - - // if stroke:none, skip writing stroke properties - if (!from->stroke.noneSet) { - p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linecap", enum_stroke_linecap, - &from->stroke_linecap, &to->stroke_linecap, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "stroke-linejoin", enum_stroke_linejoin, - &from->stroke_linejoin, &to->stroke_linejoin, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ifloat(p, c + BMAX - p, "stroke-miterlimit", - &from->stroke_miterlimit, &to->stroke_miterlimit, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_idasharray(p, c + BMAX - p, "stroke-dasharray", - &from->stroke_dasharray, &to->stroke_dasharray, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ilength(p, c + BMAX - p, "stroke-dashoffset", &from->stroke_dashoffset, &to->stroke_dashoffset, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_iscale24(p, c + BMAX - p, "stroke-opacity", &from->stroke_opacity, &to->stroke_opacity, SP_STYLE_FLAG_IFDIFF); - } - - /* paint-order */ - if( from->paint_order.set) { - p += sp_style_write_ipaintorder(p, c + BMAX - p, "paint-order", &from->paint_order, &to->paint_order, SP_STYLE_FLAG_IFDIFF); - } - - /* markers */ - gchar *master = from->marker[SP_MARKER_LOC].value; - if (master != NULL) { - p += g_snprintf(p, c + BMAX - p, "marker:%s;", master); - } - if (from->marker[SP_MARKER_LOC_START].value != NULL && (!master || strcmp(master, from->marker[SP_MARKER_LOC_START].value))) { - p += g_snprintf(p, c + BMAX - p, "marker-start:%s;", from->marker[SP_MARKER_LOC_START].value); - } - if (from->marker[SP_MARKER_LOC_MID].value != NULL && (!master || strcmp(master, from->marker[SP_MARKER_LOC_MID].value))) { - p += g_snprintf(p, c + BMAX - p, "marker-mid:%s;", from->marker[SP_MARKER_LOC_MID].value); - } - if (from->marker[SP_MARKER_LOC_END].value != NULL && (!master || strcmp(master, from->marker[SP_MARKER_LOC_END].value))) { - p += g_snprintf(p, c + BMAX - p, "marker-end:%s;", from->marker[SP_MARKER_LOC_END].value); - } - - p += sp_style_write_ienum(p, c + BMAX - p, "visibility", enum_visibility, &from->visibility, &to->visibility, SP_STYLE_FLAG_IFSET); - p += sp_style_write_ienum(p, c + BMAX - p, "display", enum_display, &from->display, &to->display, SP_STYLE_FLAG_IFSET); - p += sp_style_write_ienum(p, c + BMAX - p, "overflow", enum_overflow, &from->overflow, &to->overflow, SP_STYLE_FLAG_IFSET); - p += sp_style_write_ienum(p, c + BMAX - p, "isolation", enum_isolation, &from->isolation, &to->isolation, SP_STYLE_FLAG_IFSET); - p += sp_style_write_ienum(p, c + BMAX - p, "mix-blend-mode", enum_blend_mode, &from->blend_mode, &to->blend_mode, SP_STYLE_FLAG_IFSET); - - /* filter: */ - p += sp_style_write_ifilter(p, c + BMAX - p, "filter", &from->filter, &to->filter, SP_STYLE_FLAG_IFDIFF); - - p += sp_style_write_ienum(p, c + BMAX - p, "enable-background", enum_enable_background, &from->enable_background, &to->enable_background, SP_STYLE_FLAG_IFSET); - - p += sp_text_style_write(p, c + BMAX - p, from->text, SP_STYLE_FLAG_IFDIFF); - - p += sp_style_write_ienum(p, c + BMAX - p, "clip-rule", enum_clip_rule, &from->clip_rule, &to->clip_rule, SP_STYLE_FLAG_IFDIFF); - - /* rendering */ - p += sp_style_write_ienum(p, c + BMAX - p, "color-rendering", enum_color_rendering, &from->color_rendering, &to->color_rendering, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "image-rendering", enum_image_rendering, &from->image_rendering, &to->image_rendering, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "shape-rendering", enum_shape_rendering, &from->shape_rendering, &to->shape_rendering, SP_STYLE_FLAG_IFDIFF); - p += sp_style_write_ienum(p, c + BMAX - p, "text-rendering", enum_text_rendering, &from->text_rendering, &to->text_rendering, SP_STYLE_FLAG_IFDIFF); - - /** \todo - * The reason we use IFSET rather than IFDIFF is the belief that the IFDIFF - * flag is mainly only for attributes that don't handle explicit unset well. - * We may need to revisit the behaviour of this routine. - */ - - /* Get rid of trailing `;'. */ - if (p != c) { - --p; - if (*p == ';') { - *p = '\0'; - } - } - - return g_strdup(c); -} - - - -/** - * Reset all style properties. - */ -static void -sp_style_clear(SPStyle *style) -{ - g_return_if_fail(style != NULL); - - style->fill.clear(); - style->stroke.clear(); - sp_style_filter_clear(style); - - style->release_connection.disconnect(); - - style->fill_ps_modified_connection.disconnect(); - if (style->fill.value.href) { - delete style->fill.value.href; - style->fill.value.href = NULL; - } - style->stroke_ps_modified_connection.disconnect(); - if (style->stroke.value.href) { - delete style->stroke.value.href; - style->stroke.value.href = NULL; - } - style->filter_modified_connection.disconnect(); - if (style->filter.href) { - delete style->filter.href; - style->filter.href = NULL; - } - - style->stroke_dasharray.values.clear(); - style->stroke_dasharray.inherit = FALSE; - style->stroke_dashoffset.inherit = FALSE; - - /** \todo fixme: Do that text manipulation via parents */ - SPObject *object = style->object; - SPDocument *document = style->document; - gint const refcount = style->refcount; - SPTextStyle *text = style->text; - unsigned const text_private = style->text_private; - - - style->refcount = refcount; - style->object = object; - style->document = document; - - if (document) { - style->filter.href = new SPFilterReference(document); - style->filter.href->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_style_filter_ref_changed), style)); - - style->fill.value.href = new SPPaintServerReference(document); - style->fill.value.href->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_style_fill_paint_server_ref_changed), style)); - - style->stroke.value.href = new SPPaintServerReference(document); - style->stroke.value.href->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_style_stroke_paint_server_ref_changed), style)); - } - - style->text = text; - style->text_private = text_private; - - style->text->font_specification.set = FALSE; - style->text->font.set = FALSE; - style->text->font_family.set = FALSE; - - style->font_size.set = FALSE; - style->font_size.inherit = FALSE; - style->font_size.type = SP_FONT_SIZE_LITERAL; - style->font_size.unit = 0; - style->font_size.literal = SP_CSS_FONT_SIZE_MEDIUM; - style->font_size.value = 12.0; - style->font_size.computed = 12.0; - style->font_style.set = FALSE; - style->font_style.inherit = FALSE; - style->font_style.value = style->font_style.computed = SP_CSS_FONT_STYLE_NORMAL; - style->font_variant.set = FALSE; - style->font_variant.inherit = FALSE; - style->font_variant.value = style->font_variant.computed = SP_CSS_FONT_VARIANT_NORMAL; - style->font_weight.set = FALSE; - style->font_weight.inherit = FALSE; - style->font_weight.value = SP_CSS_FONT_WEIGHT_NORMAL; - style->font_weight.computed = SP_CSS_FONT_WEIGHT_400; - style->font_stretch.set = FALSE; - style->font_stretch.inherit = FALSE; - style->font_stretch.value = style->font_stretch.computed = SP_CSS_FONT_STRETCH_NORMAL; - - /* text */ - style->text_indent.set = FALSE; - style->text_indent.inherit = FALSE; - style->text_indent.unit = SP_CSS_UNIT_NONE; - style->text_indent.computed = 0.0; - - style->text_align.set = FALSE; - style->text_align.inherit = FALSE; - style->text_align.value = style->text_align.computed = SP_CSS_TEXT_ALIGN_START; - - style->text_decoration_line.set = FALSE; - style->text_decoration_line.inherit = FALSE; - style->text_decoration_line.underline = FALSE; - style->text_decoration_line.overline = FALSE; - style->text_decoration_line.line_through = FALSE; - style->text_decoration_line.blink = FALSE; - - style->text_decoration_style.set = FALSE; - style->text_decoration_style.inherit = FALSE; - style->text_decoration_style.solid = FALSE; - style->text_decoration_style.isdouble = FALSE; - style->text_decoration_style.dotted = FALSE; - style->text_decoration_style.dashed = FALSE; - style->text_decoration_style.wavy = FALSE; - - style->text_decoration_color.clear(); - - style->line_height.set = FALSE; - style->line_height.inherit = FALSE; - style->line_height.unit = SP_CSS_UNIT_PERCENT; - style->line_height.normal = TRUE; - style->line_height.value = style->line_height.computed = 1.0; - - style->letter_spacing.set = FALSE; - style->letter_spacing.inherit = FALSE; - style->letter_spacing.unit = SP_CSS_UNIT_NONE; - style->letter_spacing.normal = TRUE; - style->letter_spacing.value = style->letter_spacing.computed = 0.0; - - style->word_spacing.set = FALSE; - style->word_spacing.inherit = FALSE; - style->word_spacing.unit = SP_CSS_UNIT_NONE; - style->word_spacing.normal = TRUE; - style->word_spacing.value = style->word_spacing.computed = 0.0; - - style->baseline_shift.set = FALSE; - style->baseline_shift.inherit = FALSE; - style->baseline_shift.type = SP_BASELINE_SHIFT_LITERAL; - style->baseline_shift.unit = SP_CSS_UNIT_NONE; - style->baseline_shift.literal = SP_CSS_BASELINE_SHIFT_BASELINE; - style->baseline_shift.value = 0.0; - style->baseline_shift.computed = 0.0; - - style->text_transform.set = FALSE; - style->text_transform.inherit = FALSE; - style->text_transform.value = style->text_transform.computed = SP_CSS_TEXT_TRANSFORM_NONE; - - style->direction.set = FALSE; - style->direction.inherit = FALSE; - style->direction.value = style->direction.computed = SP_CSS_DIRECTION_LTR; - - style->block_progression.set = FALSE; - style->block_progression.inherit = FALSE; - style->block_progression.value = style->block_progression.computed = SP_CSS_BLOCK_PROGRESSION_TB; - - style->writing_mode.set = FALSE; - style->writing_mode.inherit = FALSE; - style->writing_mode.value = style->writing_mode.computed = SP_CSS_WRITING_MODE_LR_TB; - - style->text_anchor.set = FALSE; - style->text_anchor.inherit = FALSE; - style->text_anchor.value = style->text_anchor.computed = SP_CSS_TEXT_ANCHOR_START; - - style->clip_set = FALSE; - style->color_set = FALSE; - style->cursor_set = FALSE; - style->overflow_set = FALSE; - style->clip_path_set = FALSE; - style->mask_set = FALSE; - - style->clip_rule.set = FALSE; - style->clip_rule.inherit = FALSE; - style->clip_rule.value = style->clip_rule.computed = SP_WIND_RULE_NONZERO; - - style->opacity.set = FALSE; - style->opacity.inherit = FALSE; - style->opacity.value = SP_SCALE24_MAX; - style->visibility.set = FALSE; - style->visibility.inherit = FALSE; - style->visibility.value = style->visibility.computed = SP_CSS_VISIBILITY_VISIBLE; - style->display.set = FALSE; - style->display.inherit = FALSE; - style->display.value = style->display.computed = SP_CSS_DISPLAY_INLINE; - style->overflow.set = FALSE; - style->overflow.inherit = FALSE; - style->overflow.value = style->overflow.computed = SP_CSS_OVERFLOW_VISIBLE; - style->isolation.set = FALSE; - style->isolation.inherit = FALSE; - style->isolation.value = style->isolation.computed = SP_CSS_ISOLATION_AUTO; - style->blend_mode.set = FALSE; - style->blend_mode.inherit = FALSE; - style->blend_mode.value = style->blend_mode.computed = SP_CSS_BLEND_NORMAL; - - style->color.clear(); - style->color.setColor(0.0, 0.0, 0.0); - style->color_interpolation.set = FALSE; - style->color_interpolation.inherit = FALSE; - style->color_interpolation.value = style->color_interpolation.computed = SP_CSS_COLOR_INTERPOLATION_SRGB; - style->color_interpolation_filters.set = FALSE; - style->color_interpolation_filters.inherit = FALSE; - style->color_interpolation_filters.value = style->color_interpolation_filters.computed = SP_CSS_COLOR_INTERPOLATION_LINEARRGB; - - - style->fill.clear(); - style->fill.setColor(0.0, 0.0, 0.0); - style->fill_opacity.set = FALSE; - style->fill_opacity.inherit = FALSE; - style->fill_opacity.value = SP_SCALE24_MAX; - style->fill_rule.set = FALSE; - style->fill_rule.inherit = FALSE; - style->fill_rule.value = style->fill_rule.computed = SP_WIND_RULE_NONZERO; - - style->stroke.clear(); - style->stroke_opacity.set = FALSE; - style->stroke_opacity.inherit = FALSE; - style->stroke_opacity.value = SP_SCALE24_MAX; - - style->stroke_width.set = FALSE; - style->stroke_width.inherit = FALSE; - style->stroke_width.unit = SP_CSS_UNIT_NONE; - style->stroke_width.value = style->stroke_width.computed = 1.0; - - style->stroke_linecap.set = FALSE; - style->stroke_linecap.inherit = FALSE; - style->stroke_linecap.value = style->stroke_linecap.computed = SP_STROKE_LINECAP_BUTT; - style->stroke_linejoin.set = FALSE; - style->stroke_linejoin.inherit = FALSE; - style->stroke_linejoin.value = style->stroke_linejoin.computed = SP_STROKE_LINEJOIN_MITER; - - style->stroke_miterlimit.set = FALSE; - style->stroke_miterlimit.inherit = FALSE; - style->stroke_miterlimit.value = 4.0; - - style->stroke_dasharray.values.clear(); - style->stroke_dasharray.set = FALSE; - style->stroke_dasharray.inherit = FALSE; - - style->stroke_dashoffset.value = style->stroke_dashoffset.computed = 0.0; - style->stroke_dashoffset.set = FALSE; - style->stroke_dashoffset.inherit = FALSE; - - for (unsigned i = SP_MARKER_LOC; i < SP_MARKER_LOC_QTY; i++) { - g_free(style->marker[i].value); - style->marker[i].set = FALSE; - style->marker[i].inherit = FALSE; - style->marker[i].data = 0; - style->marker[i].value = NULL; - } - - /* SVG 2 */ - style->paint_order.set = FALSE; - style->paint_order.inherit = FALSE; // For now - for (unsigned i = 0; i < PAINT_ORDER_LAYERS; ++i) { - style->paint_order.layer[i] = SP_CSS_PAINT_ORDER_NORMAL; - style->paint_order.layer_set[i] = false; - } - style->paint_order.value = NULL; - - style->filter.set = FALSE; - style->filter.inherit = FALSE; - style->filter.href = NULL; - - style->enable_background.value = SP_CSS_BACKGROUND_ACCUMULATE; - style->enable_background.set = false; - style->enable_background.inherit = false; - - style->filter_blend_mode.set = style->filter_blend_mode.inherit = false; - style->filter_blend_mode.value = style->filter_blend_mode.computed = 0; - style->filter_gaussianBlur_deviation.set = style->filter_gaussianBlur_deviation.inherit = false; - style->filter_gaussianBlur_deviation.value = style->filter_gaussianBlur_deviation.computed = 0; - - style->color_rendering.set = style->color_rendering.inherit = false; - style->color_rendering.value = style->color_rendering.computed = SP_CSS_COLOR_RENDERING_AUTO; - style->image_rendering.set = style->image_rendering.inherit = false; - style->image_rendering.value = style->image_rendering.computed = SP_CSS_IMAGE_RENDERING_AUTO; - style->shape_rendering.set = style->shape_rendering.inherit = false; - style->shape_rendering.value = style->shape_rendering.computed = SP_CSS_SHAPE_RENDERING_AUTO; - style->text_rendering.set = style->text_rendering.inherit = false; - style->text_rendering.value = style->text_rendering.computed = SP_CSS_TEXT_RENDERING_AUTO; - - style->cloned = false; -} - - - -/** - * - */ -static void -sp_style_read_dash(SPStyle *style, gchar const *str) -{ - /* Ref: http://www.w3.org/TR/SVG11/painting.html#StrokeDasharrayProperty */ - style->stroke_dasharray.set = TRUE; - - if (strcmp(str, "inherit") == 0) { - style->stroke_dasharray.inherit = true; - return; - } - style->stroke_dasharray.inherit = false; - - style->stroke_dasharray.values.clear(); - - if (strcmp(str, "none") == 0) { - return; - } - - gchar *e = NULL; - bool LineSolid = true; - while (e != str) { - /* TODO: Should allow <length> rather than just a unitless (px) number. */ - double number = g_ascii_strtod(str, (char **) &e); - style->stroke_dasharray.values.push_back( number ); - if (number > 0.00000001) - LineSolid = false; - if (e != str) { - str = e; - } - while (str && *str && !isalnum(*str)) str += 1; - } - - if (LineSolid) { - style->stroke_dasharray.values.clear(); - } -} - - -/*######################### -## SPTextStyle operations -#########################*/ - - -/** - * Return new SPTextStyle object with default settings. - */ -static SPTextStyle * -sp_text_style_new() -{ - SPTextStyle *ts = g_new0(SPTextStyle, 1); - ts->refcount = 1; - sp_text_style_clear(ts); - - ts->font_specification.value = g_strdup("sans-serif"); - ts->font.value = g_strdup("sans-serif"); - ts->font_family.value = g_strdup("sans-serif"); - - return ts; -} - - -/** - * Clear text style settings. - */ -static void -sp_text_style_clear(SPTextStyle *ts) -{ - ts->font_specification.set = FALSE; - ts->font.set = FALSE; - ts->font_family.set = FALSE; -} - - - -/** - * Reduce refcount of text style and possibly free it. - */ -static SPTextStyle * -sp_text_style_unref(SPTextStyle *st) -{ - st->refcount -= 1; - - if (st->refcount < 1) { - g_free(st->font_specification.value); - g_free(st->font.value); - g_free(st->font_family.value); - g_free(st); - } - - return NULL; -} - - - -/** - * Return duplicate of text style. - */ -static SPTextStyle * -sp_text_style_duplicate_unset(SPTextStyle *st) -{ - SPTextStyle *nt = g_new0(SPTextStyle, 1); - nt->refcount = 1; - - nt->font_specification.value = g_strdup(st->font_specification.value); - nt->font.value = g_strdup(st->font.value); - nt->font_family.value = g_strdup(st->font_family.value); - - return nt; -} - - - -/** - * Write SPTextStyle object into string. - */ -static guint -sp_text_style_write(gchar *p, guint const len, SPTextStyle const *const st, guint flags) -{ - gint d = 0; - - // We do not do diffing for text style - if (flags == SP_STYLE_FLAG_IFDIFF) - flags = SP_STYLE_FLAG_IFSET; - - d += sp_style_write_istring(p + d, len - d, "font-family", &st->font_family, NULL, flags); - d += sp_style_write_istring(p + d, len - d, "-inkscape-font-specification", &st->font_specification, NULL, flags); - return d; -} - - - -/* The following sp_tyle_read_* functions ignore invalid values, as per - * http://www.w3.org/TR/REC-CSS2/syndata.html#parsing-errors. - * - * [However, the SVG spec is somewhat unclear as to whether the style attribute should - * be handled as per CSS2 rules or whether it must simply be a set of PROPERTY:VALUE - * pairs, in which case SVG's error-handling rules - * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing should instead be applied.] - */ - - -/** - * Set SPIFloat object from string. - */ -static void -sp_style_read_ifloat(SPIFloat *val, gchar const *str) -{ - if (!strcmp(str, "inherit")) { - val->set = TRUE; - val->inherit = TRUE; - } else { - gfloat value; - if (sp_svg_number_read_f(str, &value)) { - val->set = TRUE; - val->inherit = FALSE; - val->value = value; - } - } -} - - - -/** - * Set SPIScale24 object from string. - */ -static void -sp_style_read_iscale24(SPIScale24 *val, gchar const *str) -{ - if (!strcmp(str, "inherit")) { - val->set = TRUE; - val->inherit = TRUE; - } else { - gfloat value; - if (sp_svg_number_read_f(str, &value)) { - val->set = TRUE; - val->inherit = FALSE; - value = CLAMP(value, 0.0, 1.0); - val->value = SP_SCALE24_FROM_FLOAT(value); - } - } -} - -/** - * Reads a style value and performs lookup based on the given style value enumerations. - */ -static void -sp_style_read_ienum(SPIEnum *val, gchar const *str, SPStyleEnum const *dict, - bool const can_explicitly_inherit) -{ - if ( can_explicitly_inherit && !strcmp(str, "inherit") ) { - val->set = TRUE; - val->inherit = TRUE; - } else { - for (unsigned i = 0; dict[i].key; i++) { - if (!strcmp(str, dict[i].key)) { - val->set = TRUE; - val->inherit = FALSE; - val->value = dict[i].value; - /* Save copying for values not needing it */ - val->computed = val->value; - break; - } - } - } - return; -} - - - -/** - * Set SPIString object from string. - */ -static void -sp_style_read_istring(SPIString *val, gchar const *str) -{ - g_free(val->value); - - if (!strcmp(str, "inherit")) { - val->set = TRUE; - val->inherit = TRUE; - val->value = NULL; - } else { - val->set = TRUE; - val->inherit = FALSE; - val->value = g_strdup(str); - } -} - - - -/** - * Set SPILength object from string. - */ -static void -sp_style_read_ilength(SPILength *val, gchar const *str) -{ - if (!strcmp(str, "inherit")) { - val->set = TRUE; - val->inherit = TRUE; - } else { - gdouble value; - gchar *e; - /** \todo fixme: Move this to standard place (Lauris) */ - value = g_ascii_strtod(str, &e); - if ( !IS_FINITE(value) ) { // fix for bug lp:935157 - return; - } - if ((gchar const *) e != str) { - /** \todo - * Allow the number of px per inch to vary (document preferences, - * X server or whatever). E.g. don't fill in computed here, do - * it at the same time as percentage units are done. - */ - val->value = value; - if (!*e) { - /* Userspace */ - val->unit = SP_CSS_UNIT_NONE; - val->computed = value; - } else if (!strcmp(e, "px")) { - /* Userspace */ - val->unit = SP_CSS_UNIT_PX; - val->computed = value; - } else if (!strcmp(e, "pt")) { - /* Userspace / DEVICESCALE */ - val->unit = SP_CSS_UNIT_PT; - val->computed = Inkscape::Util::Quantity::convert(value, "pt", "px"); - } else if (!strcmp(e, "pc")) { - val->unit = SP_CSS_UNIT_PC; - val->computed = Inkscape::Util::Quantity::convert(value, "pc", "px"); - } else if (!strcmp(e, "mm")) { - val->unit = SP_CSS_UNIT_MM; - val->computed = Inkscape::Util::Quantity::convert(value, "mm", "px"); - } else if (!strcmp(e, "cm")) { - val->unit = SP_CSS_UNIT_CM; - val->computed = Inkscape::Util::Quantity::convert(value, "cm", "px"); - } else if (!strcmp(e, "in")) { - val->unit = SP_CSS_UNIT_IN; - val->computed = Inkscape::Util::Quantity::convert(value, "in", "px"); - } else if (!strcmp(e, "em")) { - /* EM square */ - val->unit = SP_CSS_UNIT_EM; - val->computed = value * SP_CSS_FONT_SIZE_DEFAULT; - } else if (!strcmp(e, "ex")) { - /* ex square */ - val->unit = SP_CSS_UNIT_EX; - val->computed = value * 0.5 * SP_CSS_FONT_SIZE_DEFAULT; - } else if (!strcmp(e, "%")) { - /* Percentage */ - val->unit = SP_CSS_UNIT_PERCENT; - val->value = value * 0.01; - } else { - /* Invalid */ - return; - } - val->set = TRUE; - val->inherit = FALSE; - } - } -} - -/** - * Set SPILengthOrNormal object from string. - */ -static void -sp_style_read_ilengthornormal(SPILengthOrNormal *val, gchar const *str) -{ - if (!strcmp(str, "normal")) { - val->set = TRUE; - val->inherit = FALSE; - val->normal = TRUE; - val->unit = SP_CSS_UNIT_NONE; - val->value = val->computed = 0.0; - } else { - SPILength length; - sp_style_read_ilength(&length, str); - val->set = length.set; - val->inherit = length.inherit; - val->normal = FALSE; - val->unit = length.unit; - val->value = length.value; - val->computed = length.computed; - } -} - -/** - * Set SPIPaintOrder object from string. - */ -static void -sp_style_read_ipaintorder(SPIPaintOrder *val, gchar const *str) -{ - g_free(val->value); - - if (!strcmp(str, "inherit")) { - // NEED TO CHECK FINAL SPEC - val->set = TRUE; - val->inherit = TRUE; - val->value = NULL; - } else { - val->set = TRUE; - val->inherit = FALSE; - val->value = g_strdup(str); - - if (!strcmp(str, "normal")) { - val->layer[0] = SP_CSS_PAINT_ORDER_NORMAL; - val->layer_set[0] = true; - } else { - // This certainly can be done more efficiently - gchar** c = g_strsplit(str, " ", PAINT_ORDER_LAYERS + 1); - bool used[3] = {false, false, false}; - unsigned int i = 0; - for( ; i < PAINT_ORDER_LAYERS; ++i ) { - if( c[i] ) { - val->layer_set[i] = false; - if( !strcmp( c[i], "fill")) { - val->layer[i] = SP_CSS_PAINT_ORDER_FILL; - val->layer_set[i] = true; - used[0] = true; - } else if( !strcmp( c[i], "stroke")) { - val->layer[i] = SP_CSS_PAINT_ORDER_STROKE; - val->layer_set[i] = true; - used[1] = true; - } else if( !strcmp( c[i], "markers")) { - val->layer[i] = SP_CSS_PAINT_ORDER_MARKER; - val->layer_set[i] = true; - used[2] = true; - } else { - break; - } - } else { - break; - } - } - g_strfreev(c); - - // Fill out rest of the layers using the default order - if( !used[0] && i < PAINT_ORDER_LAYERS ) { - val->layer[i] = SP_CSS_PAINT_ORDER_FILL; - val->layer_set[i] = false; - ++i; - } - if( !used[1] && i < PAINT_ORDER_LAYERS ) { - val->layer[i] = SP_CSS_PAINT_ORDER_STROKE; - val->layer_set[i] = false; - ++i; - } - if( !used[2] && i < PAINT_ORDER_LAYERS ) { - val->layer[i] = SP_CSS_PAINT_ORDER_MARKER; - val->layer_set[i] = false; - } - } - } -} - - - -/** - * Set SPITextDecoration object from string. - */ -static void -sp_style_read_itextdecoration(SPITextDecorationLine *line, SPITextDecorationStyle *style, SPIPaint *color, gchar const *str){ - sp_style_read_itextdecorationLine(line, str); // scans all tokens for line types - sp_style_read_itextdecorationStyle(style, str); // scans all tokens for style types - // the color routine must be fed one token at a time - if multiple colors are found the LAST one is used - const gchar *hstr = str; - while (1) { - if (*str == ' ' || *str == ',' || *str == '\0'){ - int slen = str - hstr; - gchar *frag = g_strndup(hstr,slen+1); // only send one piece at a time, since keywords may be intermixed - sp_style_read_itextdecorationColor(color, frag); - g_free(frag); - if(color->set)break; - if(*str == '\0')break; - hstr = str + 1; - } - str++; - } -} - -/** - * Set SPITextDecorationLine object from string. - * returns true if there was a match, false otherwise - */ -static void -sp_style_read_itextdecorationLine(SPITextDecorationLine *line, gchar const *str){ - if (!strcmp(str, "inherit")) { - line->set = true; - line->inherit = true; - } else if (!strcmp(str, "none")) { - line->set = true; - line->inherit = false; - line->underline = false; - line->overline = false; - line->line_through = false; - line->blink = false; - } else { - bool found_one = false; - bool hit_one = false; - - // CSS 2 keywords - bool found_underline = false; - bool found_overline = false; - bool found_line_through = false; - bool found_blink = false; - - // this method ignores inlineid keys and extra delimiters, so " ,,, blink hello" will set blink and ignore hello - const gchar *hstr = str; - while (1) { - if (*str == ' ' || *str == ',' || *str == '\0'){ - int slen = str - hstr; - // CSS 2 keywords - while(1){ // not really a loop, used to avoid a goto - hit_one = true; // most likely we will - if ((slen == 9) && strneq(hstr, "underline", slen)){ found_underline = true; break; } - if ((slen == 8) && strneq(hstr, "overline", slen)){ found_overline = true; break; } - if ((slen == 12) && strneq(hstr, "line-through", slen)){ found_line_through = true; break; } - if ((slen == 5) && strneq(hstr, "blink", slen)){ found_blink = true; break; } - if ((slen == 4) && strneq(hstr, "none", slen)){ break; } - - hit_one = false; // whatever this thing is, we do not recognize it - break; - } - found_one |= hit_one; - if(*str == '\0')break; - hstr = str + 1; - } - str++; - } - if (found_one) { - line->set = true; - line->inherit = false; - line->underline = found_underline; - line->overline = found_overline; - line->line_through = found_line_through; - line->blink = found_blink; - } - else { - line->set = false; - line->inherit = false; - } - } -} - -/** - * Set SPITextDecorationStyle object from string. - * returns true if there was a match, false otherwise -*/ -static void -sp_style_read_itextdecorationStyle(SPITextDecorationStyle *style, gchar const *str){ - if (!strcmp(str, "inherit")) { - style->set = true; - style->inherit = true; - } else if (!strcmp(str, "none")) { - style->set = true; - style->inherit = false; - style->solid = false; - style->isdouble = false; - style->dotted = false; - style->dashed = false; - style->wavy = false; - } else { - // note, these are CSS 3 keywords - bool found_solid = false; - bool found_double = false; - bool found_dotted = false; - bool found_dashed = false; - bool found_wavy = false; - bool found_one = false; - - // this method ignores inlineid keys and extra delimiters, so " ,,, style hello" will set style and ignore hello - // if more than one style is present, the first is used - const gchar *hstr = str; - while (1) { - if (*str == ' ' || *str == ',' || *str == '\0'){ - int slen = str - hstr; - if ( (slen == 5) && strneq(hstr, "solid", slen)){ found_solid = true; found_one = true; break; } - else if ((slen == 6) && strneq(hstr, "double", slen)){ found_double = true; found_one = true; break; } - else if ((slen == 6) && strneq(hstr, "dotted", slen)){ found_dotted = true; found_one = true; break; } - else if ((slen == 6) && strneq(hstr, "dashed", slen)){ found_dashed = true; found_one = true; break; } - else if ((slen == 4) && strneq(hstr, "wavy", slen)){ found_wavy = true; found_one = true; break; } - if(*str == '\0')break; // nothing more to test - hstr = str + 1; - } - str++; - } - if(found_one){ - style->set = true; - style->inherit = false; - style->solid = found_solid; - style->isdouble = found_double; - style->dotted = found_dotted; - style->dashed = found_dashed; - style->wavy = found_wavy; - } - else { - style->set = false; - style->inherit = false; - } - } -} - -/** - * Set SPIPaint object from string. - */ -static void -sp_style_read_itextdecorationColor(SPIPaint *color, gchar const *str){ - sp_style_read_icolor(color, str, NULL,NULL); -} - - -/** - * Set SPIPaint object from string containing an integer value. - * \param document Ignored - */ -static void -sp_style_read_icolor(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocument *document) -{ - (void)style; // TODO - (void)document; // TODO - paint->currentcolor = FALSE; /* currentColor not a valid <color>. */ - if (!strcmp(str, "inherit")) { - paint->set = TRUE; - paint->inherit = TRUE; - } else { - paint->inherit = FALSE; - guint32 const rgb0 = sp_svg_read_color(str, 0xff); - if (rgb0 != 0xff) { - paint->setColor(rgb0); - paint->set = TRUE; - } - } -} - - -/** - * Set SPIPaint object from string. - * - * \pre paint == \&style.fill || paint == \&style.stroke. - */ -void SPIPaint::read( gchar const *str, SPStyle &style, SPDocument *document ) -{ - while (g_ascii_isspace(*str)) { - ++str; - } - - clear(); - - if (streq(str, "inherit")) { - set = TRUE; - inherit = TRUE; - } else { - if ( strneq(str, "url", 3) ) { - gchar *uri = extract_uri( str, &str ); - while ( g_ascii_isspace(*str) ) { - ++str; - } - // TODO check on and comment the comparrison "paint != &style->color". - if ( uri && *uri && (this != &style.color) ) { - set = TRUE; - - // it may be that this style's SPIPaint has not yet created its URIReference; - // now that we have a document, we can create it here - if (!value.href && document) { - value.href = new SPPaintServerReference(document); - value.href->changedSignal().connect(sigc::bind(sigc::ptr_fun((this == &style.fill)? sp_style_fill_paint_server_ref_changed : sp_style_stroke_paint_server_ref_changed), &style)); - } - - // TODO check what this does in light of move away from union - sp_style_set_ipaint_to_uri_string (&style, this, uri); - } - g_free( uri ); - } - - if (streq(str, "currentColor") && (this != &style.color)) { - set = TRUE; - currentcolor = TRUE; - } else if (streq(str, "none") && (this != &style.color)) { - set = TRUE; - noneSet = TRUE; - } else { - guint32 const rgb0 = sp_svg_read_color(str, &str, 0xff); - if (rgb0 != 0xff) { - setColor( rgb0 ); - set = TRUE; - - while (g_ascii_isspace(*str)) { - ++str; - } - if (strneq(str, "icc-color(", 10)) { - SVGICCColor* tmp = new SVGICCColor(); - if ( ! sp_svg_read_icc_color( str, &str, tmp ) ) { - delete tmp; - tmp = 0; - } - value.color.icc = tmp; - } - } - } - } -} - - - -/** - * Set SPIFontSize object from string. - */ -static void -sp_style_read_ifontsize(SPIFontSize *val, gchar const *str) -{ - if (!strcmp(str, "inherit")) { - val->set = TRUE; - val->inherit = TRUE; - } else if ((*str == 'x') || (*str == 's') || (*str == 'm') || (*str == 'l')) { - // xx-small, x-small, etc. - for (unsigned i = 0; enum_font_size[i].key; i++) { - if (!strcmp(str, enum_font_size[i].key)) { - val->set = TRUE; - val->inherit = FALSE; - val->type = SP_FONT_SIZE_LITERAL; - val->literal = enum_font_size[i].value; - return; - } - } - /* Invalid */ - return; - } else { - SPILength length; - length.set = FALSE; - sp_style_read_ilength(&length, str); - if( length.set ) { - val->set = TRUE; - val->inherit = length.inherit; - val->unit = length.unit; - val->value = length.value; - val->computed = length.computed; - if( val->unit == SP_CSS_UNIT_PERCENT ) { - val->type = SP_FONT_SIZE_PERCENTAGE; - } else { - val->type = SP_FONT_SIZE_LENGTH; - } - } - return; - } -} - - -/** - * Set SPIBaselineShift object from string. - */ -static void -sp_style_read_ibaselineshift(SPIBaselineShift *val, gchar const *str) -{ - if (!strcmp(str, "inherit")) { - val->set = TRUE; - val->inherit = TRUE; - } else if ((*str == 'b') || (*str == 's')) { - // baseline or sub or super - for (unsigned i = 0; enum_baseline_shift[i].key; i++) { - if (!strcmp(str, enum_baseline_shift[i].key)) { - val->set = TRUE; - val->inherit = FALSE; - val->type = SP_BASELINE_SHIFT_LITERAL; - val->literal = enum_baseline_shift[i].value; - return; - } - } - /* Invalid */ - return; - } else { - SPILength length; - sp_style_read_ilength(&length, str); - val->set = length.set; - val->inherit = length.inherit; - val->unit = length.unit; - val->value = length.value; - val->computed = length.computed; - if( val->unit == SP_CSS_UNIT_PERCENT ) { - val->type = SP_BASELINE_SHIFT_PERCENTAGE; - } else { - val->type = SP_BASELINE_SHIFT_LENGTH; - } - return; - } -} - - -/** - * Set SPIFilter object from string. - */ -static void -sp_style_read_ifilter(gchar const *str, SPStyle * style, SPDocument *document) -{ - SPIFilter *f = &(style->filter); - /* Try all possible values: inherit, none, uri */ - if (streq(str, "inherit")) { - f->set = TRUE; - f->inherit = TRUE; - if (f->href){ - if (f->href->getObject()){ - f->href->detach(); - } - } - } else if(streq(str, "none")) { - f->set = TRUE; - f->inherit = FALSE; - if (f->href){ - if (f->href->getObject()){ - f->href->detach(); - } - } - } else if (strneq(str, "url", 3)) { - char *uri = extract_uri(str); - if(uri == NULL || uri[0] == '\0') { - g_warning("Specified filter url is empty"); - f->set = TRUE; - f->inherit = FALSE; - return; - } - f->set = TRUE; - f->inherit = FALSE; - if (f->href){ - if (f->href->getObject()){ - f->href->detach(); - } - } - - // it may be that this style has not yet created its SPFilterReference; - // now that we have a document, we can create it here - if (!f->href && document) { - f->href = new SPFilterReference(document); - f->href->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_style_filter_ref_changed), style)); - } - - try { - f->href->attach(Inkscape::URI(uri)); - } catch (Inkscape::BadURIException &e) { - g_warning("%s", e.what()); - f->href->detach(); - } - g_free (uri); - - } else { - /* We shouldn't reach this if SVG input is well-formed */ - f->set = FALSE; - f->inherit = FALSE; - if (f->href){ - if (f->href->getObject()){ - f->href->detach(); - } - } - } -} - -/** - * Set SPIEnum object from repr attribute. - */ -static void -sp_style_read_penum(SPIEnum *val, Inkscape::XML::Node *repr, - gchar const *key, SPStyleEnum const *dict, - bool const can_explicitly_inherit) -{ - gchar const *str = repr->attribute(key); - if (str) { - sp_style_read_ienum(val, str, dict, can_explicitly_inherit); - } -} - - - -/** - * Set SPILength object from repr attribute. - */ -static void -sp_style_read_plength(SPILength *val, Inkscape::XML::Node *repr, gchar const *key) -{ - gchar const *str = repr->attribute(key); - if (str) { - sp_style_read_ilength(val, str); - } -} - -/** - * Set SPIFontSize object from repr attribute. - */ -static void -sp_style_read_pfontsize(SPIFontSize *val, Inkscape::XML::Node *repr, gchar const *key) -{ - gchar const *str = repr->attribute(key); - if (str) { - sp_style_read_ifontsize(val, str); - } -} - - -/** - * Set SPIBaselineShift object from repr attribute. - */ -static void -sp_style_read_pbaselineshift(SPIBaselineShift *val, Inkscape::XML::Node *repr, gchar const *key) -{ - gchar const *str = repr->attribute(key); - if (str) { - sp_style_read_ibaselineshift(val, str); - } -} - - -/** - * Set SPIFloat object from repr attribute. - */ -static void -sp_style_read_pfloat(SPIFloat *val, Inkscape::XML::Node *repr, gchar const *key) -{ - gchar const *str = repr->attribute(key); - if (str) { - sp_style_read_ifloat(val, str); - } -} - - -/** - * Write SPIFloat object into string. - */ -static gint -sp_style_write_ifloat(gchar *p, gint const len, gchar const *const key, - SPIFloat const *const val, SPIFloat const *const base, guint const flags) -{ - Inkscape::CSSOStringStream os; - - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && val->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set - && (!base->set || (val->value != base->value)))) - { - if (val->inherit) { - return g_snprintf(p, len, "%s:inherit;", key); - } else { - os << key << ":" << val->value << ";"; - return g_strlcpy(p, os.str().c_str(), len); - } - } - return 0; -} - - -/** - * Write SPIScale24 object into string. - */ -static gint -sp_style_write_iscale24(gchar *p, gint const len, gchar const *const key, - SPIScale24 const *const val, SPIScale24 const *const base, - guint const flags) -{ - Inkscape::CSSOStringStream os; - - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && val->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set - && (!base->set || (val->value != base->value)))) - { - if (val->inherit) { - return g_snprintf(p, len, "%s:inherit;", key); - } else { - os << key << ":" << SP_SCALE24_TO_FLOAT(val->value) << ";"; - return g_strlcpy(p, os.str().c_str(), len); - } - } - return 0; -} - - -/** - * Write SPIEnum object into string. - */ -static gint -sp_style_write_ienum(gchar *p, gint const len, gchar const *const key, - SPStyleEnum const *const dict, - SPIEnum const *const val, SPIEnum const *const base, guint const flags) -{ - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && val->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set - && (!base->set || (val->computed != base->computed)))) - { - if (val->inherit) { - return g_snprintf(p, len, "%s:inherit;", key); - } - for (unsigned i = 0; dict[i].key; i++) { - if (dict[i].value == static_cast< gint > (val->value) ) { - return g_snprintf(p, len, "%s:%s;", key, dict[i].key); - } - } - } - return 0; -} - - - -/** - * Write SPIString object into string. - */ -static gint -sp_style_write_istring(gchar *p, gint const len, gchar const *const key, - SPIString const *const val, SPIString const *const base, guint const flags) -{ - gint res = 0; - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && val->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set - && (!base->set || strcmp(val->value, base->value)))) - { - if (val->inherit) { - res = g_snprintf(p, len, "%s:inherit;", key); - } else { - Glib::ustring val_quoted = css2_escape_quote(val->value); - if (~val_quoted.empty()) { - res = g_snprintf(p, len, "%s:%s;", key, val_quoted.c_str()); - } - } - } - return res; -} - - -/** - * - */ -static bool -sp_length_differ(SPILength const *const a, SPILength const *const b) -{ - if (a->unit != b->unit) { - if (a->unit == SP_CSS_UNIT_EM) return true; - if (a->unit == SP_CSS_UNIT_EX) return true; - if (a->unit == SP_CSS_UNIT_PERCENT) return true; - if (b->unit == SP_CSS_UNIT_EM) return true; - if (b->unit == SP_CSS_UNIT_EX) return true; - if (b->unit == SP_CSS_UNIT_PERCENT) return true; - } - - return (a->computed != b->computed); -} - - - -/** - * Write SPILength object into string. - */ -static gint -sp_style_write_ilength(gchar *p, gint const len, gchar const *const key, - SPILength const *const val, SPILength const *const base, guint const flags) -{ - Inkscape::CSSOStringStream os; - - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && val->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set - && (!base->set || sp_length_differ(val, base)))) - { - if (val->inherit) { - return g_snprintf(p, len, "%s:inherit;", key); - } else { - switch (val->unit) { - case SP_CSS_UNIT_NONE: - os << key << ":" << val->computed << ";"; - return g_strlcpy(p, os.str().c_str(), len); - break; - case SP_CSS_UNIT_PX: - os << key << ":" << val->computed << "px;"; - return g_strlcpy(p, os.str().c_str(), len); - break; - case SP_CSS_UNIT_PT: - os << key << ":" << Inkscape::Util::Quantity::convert(val->computed, "px", "pt") << "pt;"; - return g_strlcpy(p, os.str().c_str(), len); - break; - case SP_CSS_UNIT_PC: - os << key << ":" << Inkscape::Util::Quantity::convert(val->computed, "px", "pc") << "pc;"; - return g_strlcpy(p, os.str().c_str(), len); - break; - case SP_CSS_UNIT_MM: - os << key << ":" << Inkscape::Util::Quantity::convert(val->computed, "px", "mm") << "mm;"; - return g_strlcpy(p, os.str().c_str(), len); - break; - case SP_CSS_UNIT_CM: - os << key << ":" << Inkscape::Util::Quantity::convert(val->computed, "px", "cm") << "cm;"; - return g_strlcpy(p, os.str().c_str(), len); - break; - case SP_CSS_UNIT_IN: - os << key << ":" << Inkscape::Util::Quantity::convert(val->computed, "px", "in") << "in;"; - return g_strlcpy(p, os.str().c_str(), len); - break; - case SP_CSS_UNIT_EM: - os << key << ":" << val->value << "em;"; - return g_strlcpy(p, os.str().c_str(), len); - break; - case SP_CSS_UNIT_EX: - os << key << ":" << val->value << "ex;"; - return g_strlcpy(p, os.str().c_str(), len); - break; - case SP_CSS_UNIT_PERCENT: - os << key << ":" << (val->value * 100.0) << "%;"; - return g_strlcpy(p, os.str().c_str(), len); - break; - default: - /* Invalid */ - break; - } - } - } - return 0; -} - - -/** - * - */ -static bool -sp_lengthornormal_differ(SPILengthOrNormal const *const a, SPILengthOrNormal const *const b) -{ - if (a->normal != b->normal) return true; - if (a->normal) return false; - - if (a->unit != b->unit) { - if (a->unit == SP_CSS_UNIT_EM) return true; - if (a->unit == SP_CSS_UNIT_EX) return true; - if (a->unit == SP_CSS_UNIT_PERCENT) return true; - if (b->unit == SP_CSS_UNIT_EM) return true; - if (b->unit == SP_CSS_UNIT_EX) return true; - if (b->unit == SP_CSS_UNIT_PERCENT) return true; - } - - return (a->computed != b->computed); -} - -/** - * Write SPILengthOrNormal object into string. - */ -static gint -sp_style_write_ilengthornormal(gchar *p, gint const len, gchar const *const key, - SPILengthOrNormal const *const val, - SPILengthOrNormal const *const base, - guint const flags) -{ - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && val->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set - && (!base->set || sp_lengthornormal_differ(val, base)))) - { - if (val->normal) { - return g_snprintf(p, len, "%s:normal;", key); - } else { - SPILength length; - length.set = val->set; - length.inherit = val->inherit; - length.unit = val->unit; - length.value = val->value; - length.computed = val->computed; - return sp_style_write_ilength(p, len, key, &length, NULL, SP_STYLE_FLAG_ALWAYS); - } - } - return 0; -} - -/** - * Write SPIDashArray object into string. - */ -static gint -sp_style_write_idasharray(gchar *p, gint const len, gchar const *const /*key*/, - SPIDashArray const *const val, SPIDashArray const *const base, guint const flags) -{ - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && val->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set - && (!base->set || (val->values != base->values)))) - { - if (val->inherit) { - return g_snprintf(p, len, "stroke-dasharray:inherit;"); - } else if ( !val->values.empty() ) { - Inkscape::CSSOStringStream os; - os << "stroke-dasharray:"; - for (unsigned i = 0; i < val->values.size(); i++) { - if (i) { - os << ", "; - } - os << val->values[i]; - } - os << ";"; - return g_strlcpy(p, os.str().c_str(), len); - } else { - return g_snprintf(p, len, "stroke-dasharray:none;"); - } - } - return 0; -} - - -/** - * - */ -static bool -sp_textdecorationLine_differ(SPITextDecorationLine const *const a, SPITextDecorationLine const *const b) -{ - return( (a->underline != b->underline ) - || (a->overline != b->overline ) - || (a->line_through != b->line_through) - || (a->blink != b->blink ) - ); -} - -/** - * - */ -static bool -sp_textdecorationStyle_differ(SPITextDecorationStyle const *const a, SPITextDecorationStyle const *const b) -{ - return( (a->solid != b->solid ) - || (a->isdouble != b->isdouble ) - || (a->dotted != b->dotted ) - || (a->dashed != b->dashed ) - || (a->wavy != b->wavy ) - ); -} - -/** - * - */ -static bool -sp_textdecorationColor_differ(SPIPaint const *const a, SPIPaint const *const b) -{ - bool status = (a->isPaintserver() == b->isPaintserver()) && - (a->colorSet == b->colorSet) && - (a->currentcolor == b->currentcolor); - return(status); -} - -/** - * Write SPITextDecoration object into string. - */ -static gint -sp_style_write_itextdecoration(gchar *p, gint const len, gchar const *const key, - SPITextDecorationLine const *const line, - SPITextDecorationStyle const *const style, - SPIPaint const *const color, - SPITextDecorationLine const *const baseLine, - SPITextDecorationStyle const *const baseStyle, - SPIPaint const *const baseColor, - guint const flags) -{ - Inkscape::CSSOStringStream os; - - if ( (flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && line->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && line->set - && ( !baseLine->set || sp_textdecorationLine_differ(line, baseLine))) - || ((flags & SP_STYLE_FLAG_IFSET) && style->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && style->set - && ( !baseStyle->set || sp_textdecorationStyle_differ(style, baseStyle))) - || ((flags & SP_STYLE_FLAG_IFSET) && color->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && color->set - && ( !baseColor->set || sp_textdecorationColor_differ(color, baseColor))) - ){ - os << key << ":"; - if (line->inherit || style->inherit || color->inherit) { - os << " inherit"; - } - else if (line->underline || line->overline || line->line_through || line->blink) { - if (line->underline) os << " underline"; - if (line->overline) os << " overline"; - if (line->line_through) os << " line-through"; - if (line->blink) os << " blink"; - - if ( style->solid) os << " solid"; - else if (style->isdouble) os << " double"; - else if (style->dotted) os << " dotted"; - else if (style->dashed) os << " dashed"; - else if (style->wavy) os << " wavy"; - // color, if it is set, otherwise omit it - if(color->set){ - char color_buf[8]; - sp_svg_write_color(color_buf, sizeof(color_buf), color->value.color.toRGBA32( 0 )); - os << " "; - os << color_buf; - } - } - else { - os << "none"; - } - os << ";"; - return g_strlcpy(p, os.str().c_str(), len); - } - return 0; -} - -/** - * - */ -static bool -sp_paint_differ(SPIPaint const *const a, SPIPaint const *const b) -{ - if ( (a->isColor() != b->isColor()) - || (a->isPaintserver() != b->isPaintserver()) - || (a->set != b->set) - || (a->currentcolor != b->currentcolor) - || (a->inherit!= b->inherit) ) { - return true; - } - - // TODO refactor to allow for mixed paints (rgb() *and* url(), etc) - - if ( a->isPaintserver() ) { - return (a->value.href == NULL || b->value.href == NULL || a->value.href->getObject() != b->value.href->getObject()); - } - - if ( a->isColor() ) { - return !( (a->value.color == b->value.color) - && ((a->value.color.icc == b->value.color.icc) - || (a->value.color.icc && b->value.color.icc - && (a->value.color.icc->colorProfile == b->value.color.icc->colorProfile) - && (a->value.color.icc->colors == b->value.color.icc->colors)))); - /* todo: Allow for epsilon differences in iccColor->colors, e.g. changes small enough not to show up - * in the string representation. */ - } - - return false; -} - - - -/** - * Write SPIPaint object into string. - */ -static gint -sp_style_write_ipaint(gchar *b, gint const len, gchar const *const key, - SPIPaint const *const paint, SPIPaint const *const base, guint const flags) -{ - int retval = 0; - - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && paint->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && paint->set - && (!base->set || sp_paint_differ(paint, base)))) - { - CSSOStringStream css; - - if (paint->inherit) { - css << "inherit"; - } else { - if ( paint->value.href && paint->value.href->getURI() ) { - const gchar* uri = paint->value.href->getURI()->toString(); - css << "url(" << uri << ")"; - g_free((void *)uri); - } - - if ( paint->noneSet ) { - if ( !css.str().empty() ) { - css << " "; - } - css << "none"; - } - - if ( paint->currentcolor ) { - if ( !css.str().empty() ) { - css << " "; - } - css << "currentColor"; - } - - if ( paint->colorSet && !paint->currentcolor ) { - if ( !css.str().empty() ) { - css << " "; - } - char color_buf[8]; - sp_svg_write_color(color_buf, sizeof(color_buf), paint->value.color.toRGBA32( 0 )); - css << color_buf; - } - - if (paint->value.color.icc && !paint->currentcolor) { - if ( !css.str().empty() ) { - css << " "; - } - css << "icc-color(" << paint->value.color.icc->colorProfile; - for (vector<double>::const_iterator i(paint->value.color.icc->colors.begin()), - iEnd(paint->value.color.icc->colors.end()); - i != iEnd; ++i) { - css << ", " << *i; - } - css << ')'; - } - } - - if ( !css.str().empty() ) { - retval = g_snprintf( b, len, "%s:%s;", key, css.str().c_str() ); - } - } - - return retval; -} - - -/** - * - */ -static bool -sp_paint_order_differ(SPIPaintOrder const *const a, SPIPaintOrder const *const b) -{ - if( (a->set != b->set) || - (a->inherit!= b->inherit) ) { - return true; - } - - // Check this works when paint-order value is 'normal' - for (unsigned i = 0; i < PAINT_ORDER_LAYERS; ++i ) { - if( (a->layer[i] != b->layer[i]) || - (a->layer_set[i] != b->layer_set[i]) ) { - return true; - } - } - return false; -} - - - -/** - * Write SPIPaintOrder object into string. - */ -static gint -sp_style_write_ipaintorder(gchar *p, gint len, gchar const *key, SPIPaintOrder const *paint_order, SPIPaintOrder const *base, guint flags) -{ - int retval = 0; - - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && paint_order->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && paint_order->set - && (!base->set || sp_paint_order_differ(paint_order, base)))) - { - CSSOStringStream css; - - if (paint_order->inherit) { - css << "inherit"; - } else { - for( unsigned i = 0; i < PAINT_ORDER_LAYERS; ++i ) { - if( paint_order->layer_set[i] == true ) { - switch (paint_order->layer[i]) { - case SP_CSS_PAINT_ORDER_NORMAL: - css << "normal"; - assert( i == 0 ); - break; - case SP_CSS_PAINT_ORDER_FILL: - if (i!=0) css << " "; - css << "fill"; - break; - case SP_CSS_PAINT_ORDER_STROKE: - if (i!=0) css << " "; - css << "stroke"; - break; - case SP_CSS_PAINT_ORDER_MARKER: - if (i!=0) css << " "; - css << "markers"; - break; - } - } else { - break; - } - } - } - - if ( !css.str().empty() ) { - retval = g_snprintf( p, len, "%s:%s;", key, css.str().c_str() ); - } - } - - return retval; -} - -/** - * - */ -static bool -sp_fontsize_differ(SPIFontSize const *const a, SPIFontSize const *const b) -{ - if (a->type != b->type) - return true; - if (a->type == SP_FONT_SIZE_LENGTH) { - if (a->computed != b->computed) - return true; - } else { - if (a->value != b->value) - return true; - } - return false; -} - - -/** - * Write SPIFontSize object into string. - */ -static gint -sp_style_write_ifontsize(gchar *p, gint const len, gchar const *key, - SPIFontSize const *const val, SPIFontSize const *const base, - guint const flags) -{ - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && val->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set - && (!base->set || sp_fontsize_differ(val, base)))) - { - if (val->inherit) { - return g_snprintf(p, len, "%s:inherit;", key); - } else if (val->type == SP_FONT_SIZE_LITERAL) { - for (unsigned i = 0; enum_font_size[i].key; i++) { - if (enum_font_size[i].value == static_cast< gint > (val->literal) ) { - return g_snprintf(p, len, "%s:%s;", key, enum_font_size[i].key); - } - } - } else if (val->type == SP_FONT_SIZE_LENGTH) { - Inkscape::CSSOStringStream os; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); - if (prefs->getBool("/options/font/textOutputPx", true)) { - unit = SP_CSS_UNIT_PX; - } - os << key << ":" << sp_style_css_size_px_to_units(val->computed, unit) << sp_style_get_css_unit_string(unit) << ";"; - return g_strlcpy(p, os.str().c_str(), len); - } else if (val->type == SP_FONT_SIZE_PERCENTAGE) { - Inkscape::CSSOStringStream os; - os << key << ":" << (val->value * 100.0) << "%;"; - return g_strlcpy(p, os.str().c_str(), len); - } - } - return 0; -} - - -/* - * baseline-shift is relative to parent. The only time it should - * not be written out is if it is zero (or not set). - */ -static bool -sp_baseline_shift_notzero(SPIBaselineShift const *const a ) -{ - if( a->type == SP_BASELINE_SHIFT_LITERAL ) { - if( a->literal == SP_CSS_BASELINE_SHIFT_BASELINE ) { - return false; - } - } else { - if( a->value == 0.0 ) { - return false; - } - } - return true; -} - -/** - * Write SPIBaselineShift object into string. - */ -static gint -sp_style_write_ibaselineshift(gchar *p, gint const len, gchar const *key, - SPIBaselineShift const *const val, SPIBaselineShift const *const base, - guint const flags) -{ - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && val->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set - && (!base->set || sp_baseline_shift_notzero(val) ))) - { - if (val->inherit) { - return g_snprintf(p, len, "%s:inherit;", key); - } else if (val->type == SP_BASELINE_SHIFT_LITERAL) { - for (unsigned i = 0; enum_baseline_shift[i].key; i++) { - if (enum_baseline_shift[i].value == static_cast< gint > (val->literal) ) { - return g_snprintf(p, len, "%s:%s;", key, enum_baseline_shift[i].key); - } - } - } else if (val->type == SP_BASELINE_SHIFT_LENGTH) { - if( val->unit == SP_CSS_UNIT_EM || val->unit == SP_CSS_UNIT_EX ) { - Inkscape::CSSOStringStream os; - os << key << ":" << val->value << (val->unit == SP_CSS_UNIT_EM ? "em;" : "ex;"); - return g_strlcpy(p, os.str().c_str(), len); - } else { - Inkscape::CSSOStringStream os; - os << key << ":" << val->computed << "px;"; // must specify px, see inkscape bug 1221626, mozilla bug 234789 - return g_strlcpy(p, os.str().c_str(), len); - } - } else if (val->type == SP_BASELINE_SHIFT_PERCENTAGE) { - Inkscape::CSSOStringStream os; - os << key << ":" << (val->value * 100.0) << "%;"; - return g_strlcpy(p, os.str().c_str(), len); - } - } - return 0; -} - - - -/** - * Write SPIFilter object into string. - */ -static gint -sp_style_write_ifilter(gchar *p, gint const len, gchar const *key, - SPIFilter const *const val, SPIFilter const *const base, - guint const flags) -{ - (void)base; // TODO - if ((flags & SP_STYLE_FLAG_ALWAYS) - || ((flags & SP_STYLE_FLAG_IFSET) && val->set) - || ((flags & SP_STYLE_FLAG_IFDIFF) && val->set)) - { - if (val->inherit) { - return g_snprintf(p, len, "%s:inherit;", key); - } else if (val->href && val->href->getURI()) { - gchar *uri = val->href->getURI()->toString(); - gint ret = g_snprintf(p, len, "%s:url(%s);", key, uri); - g_free(uri); - return ret; - } - } - - - return 0; -} - -SPIPaint::SPIPaint() : - set(false), - inherit(0), - currentcolor(0), - colorSet(0), - noneSet(0), - value() -{ - value.color.set( 0 ); - value.href = 0; -} - -void SPIPaint::clear() -{ - set = false; - inherit = false; - currentcolor = false; - colorSet = false; - noneSet = false; - value.color.set( 0 ); - if (value.href){ - if (value.href->getObject()){ - value.href->detach(); - } - } -} - -/** - * Clear filter object, and disconnect style from paintserver (if present). - */ -static void -sp_style_filter_clear(SPStyle *style) -{ - if (style->filter.href){ - if (style->filter.href->getObject()){ - style->filter.href->detach(); - } - } + return g_strdup( from->write( SP_STYLE_FLAG_IFDIFF, to ).c_str() ); } @@ -4894,7 +1522,7 @@ sp_style_set_property_url (SPObject *item, gchar const *property, SPObject *link sp_repr_css_attr_unref(css); } - +// Called in sp-object.cpp /** * Clear all style property attributes in object. */ @@ -4948,16 +1576,16 @@ sp_style_unset_property_attrs(SPObject *o) if (style->stroke_linejoin.set) { repr->setAttribute("stroke-linejoin", NULL); } - if (style->marker[SP_MARKER_LOC].set) { + if (style->marker.set) { repr->setAttribute("marker", NULL); } - if (style->marker[SP_MARKER_LOC_START].set) { + if (style->marker_start.set) { repr->setAttribute("marker-start", NULL); } - if (style->marker[SP_MARKER_LOC_MID].set) { + if (style->marker_mid.set) { repr->setAttribute("marker-mid", NULL); } - if (style->marker[SP_MARKER_LOC_END].set) { + if (style->marker_end.set) { repr->setAttribute("marker-end", NULL); } if (style->stroke_opacity.set) { @@ -4972,10 +1600,10 @@ sp_style_unset_property_attrs(SPObject *o) if (style->paint_order.set) { repr->setAttribute("paint-order", NULL); } - if (style->text_private && style->text->font_specification.set) { + if (style->font_specification.set) { repr->setAttribute("-inkscape-font-specification", NULL); } - if (style->text_private && style->text->font_family.set) { + if (style->font_family.set) { repr->setAttribute("font-family", NULL); } if (style->text_anchor.set) { @@ -5025,7 +1653,8 @@ sp_css_attr_from_style(SPStyle const *const style, guint const flags) return css; } - +// Called in: selection-chemistry.cpp, widgets/stroke-marker-selector.cpp, widgets/stroke-style.cpp, +// ui/tools/freehand-base.cpp /** * \pre object != NULL * \pre flags in {IFSET, ALWAYS}. @@ -5042,13 +1671,14 @@ SPCSSAttr *sp_css_attr_from_object(SPObject *object, guint const flags) return result; } +// Called in: selection-chemistry.cpp, ui/dialog/inkscape-preferences.cpp /** * Unset any text-related properties */ SPCSSAttr * sp_css_attr_unset_text(SPCSSAttr *css) { - sp_repr_css_set_property(css, "font", NULL); // not implemented yet + sp_repr_css_set_property(css, "font", NULL); sp_repr_css_set_property(css, "-inkscape-font-specification", NULL); sp_repr_css_set_property(css, "font-size", NULL); sp_repr_css_set_property(css, "font-size-adjust", NULL); // not implemented yet @@ -5076,6 +1706,7 @@ sp_css_attr_unset_text(SPCSSAttr *css) return css; } +// Called in style.cpp static bool is_url(char const *p) { @@ -5088,6 +1719,7 @@ is_url(char const *p) return (g_ascii_strncasecmp(p, "url(", 4) == 0); } +// Called in: ui/dialog/inkscape-preferences.cpp, ui/tools/tweek-tool.cpp /** * Unset any properties that contain URI values. * @@ -5113,6 +1745,7 @@ sp_css_attr_unset_uris(SPCSSAttr *css) return css; } +// Called in style.cpp /** * Scale a single-value property. */ @@ -5137,6 +1770,7 @@ sp_css_attr_scale_property_single(SPCSSAttr *css, gchar const *property, } } +// Called in style.cpp for stroke-dasharray /** * Scale a list-of-values property. */ @@ -5169,6 +1803,7 @@ sp_css_attr_scale_property_list(SPCSSAttr *css, gchar const *property, double ex } } +// Called in: text-editing.cpp, /** * Scale any properties that may hold <length> by ex. */ @@ -5189,6 +1824,7 @@ sp_css_attr_scale(SPCSSAttr *css, double ex) } +// Called in style.cpp, xml/repr-css.cpp /** * Remove quotes and escapes from a string. Returned value must be g_free'd. * Note: in CSS (in style= and in stylesheets), unquoting and unescaping is done @@ -5215,6 +1851,7 @@ attribute_unquote(gchar const *val) return (val? g_strdup (val) : NULL); } +// Called in style.cpp, xml/repr-css.cpp /** * Quote and/or escape string for writing to CSS (style=). Returned value must be g_free'd. */ |
