diff options
| author | Thomas Holder <thomas@thomas-holder.de> | 2019-10-28 11:32:35 +0000 |
|---|---|---|
| committer | Thomas Holder <thomas@thomas-holder.de> | 2019-10-28 11:32:35 +0000 |
| commit | 98cbf65b029df0cfb9f6b7d34538258fe4ee96c5 (patch) | |
| tree | 43153dccc9e85e8aafb9288fc08521d35161e739 | |
| parent | refactor: private SPIBase::_name (diff) | |
| download | inkscape-98cbf65b029df0cfb9f6b7d34538258fe4ee96c5.tar.gz inkscape-98cbf65b029df0cfb9f6b7d34538258fe4ee96c5.zip | |
refactor: TypedSPI
| -rw-r--r-- | src/desktop-style.cpp | 4 | ||||
| -rw-r--r-- | src/gradient-chemistry.cpp | 2 | ||||
| -rw-r--r-- | src/id-clash.cpp | 4 | ||||
| -rw-r--r-- | src/object/sp-solid-color.cpp | 2 | ||||
| -rwxr-xr-x | src/selection-chemistry.cpp | 4 | ||||
| -rw-r--r-- | src/style-internal.cpp | 18 | ||||
| -rw-r--r-- | src/style-internal.h | 27 | ||||
| -rw-r--r-- | src/style.cpp | 3 | ||||
| -rw-r--r-- | src/style.h | 171 | ||||
| -rw-r--r-- | src/widgets/fill-style.cpp | 8 | ||||
| -rw-r--r-- | src/widgets/gradient-vector.cpp | 2 | ||||
| -rw-r--r-- | src/widgets/paint-selector.cpp | 2 | ||||
| -rw-r--r-- | src/widgets/stroke-style.cpp | 2 |
13 files changed, 143 insertions, 106 deletions
diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index dc4f0d774..260b442ef 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -503,7 +503,7 @@ objects_query_fillstroke (const std::vector<SPItem*> &objects, SPStyle *style_re return QUERY_STYLE_NOTHING; } - SPIPaint *paint_res = isfill? &style_res->fill : &style_res->stroke; + SPIPaint *paint_res = style_res->getFillOrStroke(isfill); bool paintImpossible = true; paint_res->set = true; @@ -527,7 +527,7 @@ objects_query_fillstroke (const std::vector<SPItem*> &objects, SPStyle *style_re continue; } - SPIPaint *paint = isfill? &style->fill : &style->stroke; + SPIPaint *paint = style->getFillOrStroke(isfill); if (!paint) { continue; } diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index d7b5ccd63..23d909d23 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1574,7 +1574,7 @@ SPGradient *sp_gradient_vector_for_object( SPDocument *const doc, SPDesktop *con } else { // take the color of the object SPStyle const &style = *(o->style); - SPIPaint const &paint = ( (fill_or_stroke == Inkscape::FOR_FILL) ? style.fill : style.stroke ); + SPIPaint const &paint = *style.getFillOrStroke(fill_or_stroke == Inkscape::FOR_FILL); if (paint.isPaintserver()) { SPObject *server = (fill_or_stroke == Inkscape::FOR_FILL) ? o->style->getFillPaintServer() : o->style->getStrokePaintServer(); if ( SP_IS_LINEARGRADIENT(server) || SP_IS_RADIALGRADIENT(server) ) { diff --git a/src/id-clash.cpp b/src/id-clash.cpp index 95c43166c..7ba021985 100644 --- a/src/id-clash.cpp +++ b/src/id-clash.cpp @@ -54,8 +54,8 @@ const char *href_like_attributes[] = { const SPIPaint SPStyle::* SPIPaint_members[] = { //&SPStyle::color, - &SPStyle::fill, - &SPStyle::stroke, + reinterpret_cast<SPIPaint SPStyle::*>(&SPStyle::fill), + reinterpret_cast<SPIPaint SPStyle::*>(&SPStyle::stroke), }; const char* SPIPaint_properties[] = { //"color", diff --git a/src/object/sp-solid-color.cpp b/src/object/sp-solid-color.cpp index a5cf24010..53c206b8a 100644 --- a/src/object/sp-solid-color.cpp +++ b/src/object/sp-solid-color.cpp @@ -63,7 +63,7 @@ Inkscape::XML::Node* SPSolidColor::write(Inkscape::XML::Document* xml_doc, Inksc cairo_pattern_t* SPSolidColor::pattern_new(cairo_t * /*ct*/, Geom::OptRect const & /*bbox*/, double opacity) { - SPIColor *c = &(this->style->solid_color); + auto *c = &(this->style->solid_color); cairo_pattern_t *cp = cairo_pattern_create_rgba ( c->value.color.v.c[0], c->value.color.v.c[1], c->value.color.v.c[2], SP_SCALE24_TO_FLOAT(this->style->solid_opacity.value) * opacity ); return cp; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 4543de57b..26b406dbe 100755 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -2007,12 +2007,12 @@ std::vector<SPItem*> sp_get_same_fill_or_stroke_color(SPItem *sel, std::vector<S std::vector<SPItem*> matches ; gboolean match = false; - SPIPaint *sel_paint = (type == SP_FILL_COLOR) ? &(sel->style->fill) : &(sel->style->stroke); + SPIPaint *sel_paint = sel->style->getFillOrStroke(type == SP_FILL_COLOR); for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();++i) { SPItem *iter = *i; if (iter) { - SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke); + SPIPaint *iter_paint = iter->style->getFillOrStroke(type == SP_FILL_COLOR); match = false; if (sel_paint->isColor() && iter_paint->isColor() // color == color comparison doesn't seem to work here. && (sel_paint->value.color.toRGBA32(1.0) == iter_paint->value.color.toRGBA32(1.0))) { diff --git a/src/style-internal.cpp b/src/style-internal.cpp index a4569bf84..464369d28 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -54,6 +54,8 @@ using Inkscape::CSSOStringStream; // SPIBase -------------------------------------------------------------- +Glib::ustring const &SPIBase::name() const { return _name; } + // Standard criteria for writing a property // dfp == different from parent inline bool should_write( guint const flags, bool set, bool dfp, bool src) { @@ -2272,7 +2274,7 @@ SPIFont::read( gchar const *str ) { } else { // Try to parse each property in turn - SPIEnum<SPCSSFontStyle> test_style("font-style", enum_font_style); + decltype(style->font_style) test_style("font-style", enum_font_style); test_style.read( lparam.c_str() ); if( test_style.set ) { style->font_style = test_style; @@ -2280,7 +2282,7 @@ SPIFont::read( gchar const *str ) { } // font-variant (Note: only CSS2.1 value small-caps is valid in shortcut.) - SPIEnum<SPCSSFontVariant> test_variant("font-variant", enum_font_variant); + decltype(style->font_variant) test_variant("font-variant", enum_font_variant); test_variant.read( lparam.c_str() ); if( test_variant.set ) { style->font_variant = test_variant; @@ -2288,7 +2290,7 @@ SPIFont::read( gchar const *str ) { } // font-weight - SPIEnum<SPCSSFontWeight> test_weight("font-weight", enum_font_weight); + decltype(style->font_weight) test_weight("font-weight", enum_font_weight); test_weight.read( lparam.c_str() ); if( test_weight.set ) { style->font_weight = test_weight; @@ -2296,7 +2298,7 @@ SPIFont::read( gchar const *str ) { } // font-stretch (added in CSS 3 Fonts) - SPIEnum<SPCSSFontStretch> test_stretch("font-stretch", enum_font_stretch); + decltype(style->font_stretch) test_stretch("font-stretch", enum_font_stretch); test_stretch.read( lparam.c_str() ); if( test_stretch.set ) { style->font_stretch = test_stretch; @@ -2304,7 +2306,7 @@ SPIFont::read( gchar const *str ) { } // font-size - SPIFontSize test_size; + decltype(style->font_size) test_size; test_size.read( lparam.c_str() ); if( test_size.set ) { style->font_size = test_size; @@ -2792,13 +2794,13 @@ SPITextDecoration::read( gchar const *str ) { bool is_css3 = false; - SPITextDecorationLine test_line; + decltype(style->text_decoration_line) test_line; test_line.read( str ); if( test_line.set ) { style->text_decoration_line = test_line; } - SPITextDecorationStyle test_style; + decltype(style->text_decoration_style) test_style; test_style.read( str ); if( test_style.set ) { style->text_decoration_style = test_style; @@ -2809,7 +2811,7 @@ SPITextDecoration::read( gchar const *str ) { // one is used ???? then why break on set? // This could certainly be designed better - SPIColor test_color("text-decoration-color"); + decltype(style->text_decoration_color) test_color("text-decoration-color"); test_color.setStylePointer( style ); test_color.read( "currentColor" ); // Default value test_color.set = false; diff --git a/src/style-internal.h b/src/style-internal.h index 2b6e2802b..8975072cd 100644 --- a/src/style-internal.h +++ b/src/style-internal.h @@ -22,6 +22,7 @@ #include <vector> #include <map> +#include "attributes.h" #include "style-enums.h" #include "color.h" @@ -207,7 +208,8 @@ public: return !(*this == rhs); } - Glib::ustring const &name() const { return _name; } + virtual SPAttributeEnum id() const { return SP_ATTR_INVALID; } + Glib::ustring const &name() const; private: Glib::ustring _name; @@ -225,6 +227,29 @@ public: SPStyle* style; // Used by SPIPaint, SPIFilter... to find values of other properties }; + +/** + * Decorator which overrides SPIBase::id() + */ +template <SPAttributeEnum Id, class Base> +class TypedSPI : public Base { + public: + using Base::Base; + + /** + * Get the attribute enum + */ + SPAttributeEnum id() const override { return Id; } + static SPAttributeEnum static_id() { return Id; } + + /** + * Upcast to the base class + */ + Base *upcast() { return static_cast<Base *>(this); } + Base const *upcast() const { return static_cast<Base const *>(this); } +}; + + /// Float type internal to SPStyle. (Only 'stroke-miterlimit') class SPIFloat : public SPIBase { diff --git a/src/style.cpp b/src/style.cpp index a67732ffd..85371dae8 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -76,6 +76,7 @@ static CRSelEng *sp_repr_sel_eng(); class SPStylePropHelper { SPStylePropHelper() { #define REGISTER_PROPERTY(id, member, name) \ + g_assert(decltype(SPStyle::member)::static_id() == id); \ _register(reinterpret_cast<SPIBasePtr>(&SPStyle::member), id) /* name unused */ // SVG 2: Attributes promoted to properties @@ -1289,7 +1290,7 @@ sp_style_set_ipaint_to_uri_string (SPStyle *style, SPIPaint *paint, const gchar // Called in: desktop-style.cpp void sp_style_set_to_uri(SPStyle *style, bool isfill, Inkscape::URI const *uri) { - sp_style_set_ipaint_to_uri(style, isfill ? &style->fill : &style->stroke, uri, style->document); + sp_style_set_ipaint_to_uri(style, style->getFillOrStroke(isfill), uri, style->document); } // Called in: widgets/font-selector.cpp, widgets/text-toolbar.cpp, ui/dialog/text-edit.cpp diff --git a/src/style.h b/src/style.h index c2213f308..5a527f886 100644 --- a/src/style.h +++ b/src/style.h @@ -89,6 +89,10 @@ private: /// Pointers to all the properties (for looping through them) std::vector<SPIBase *> _properties; + // Shorthand for better readability + template <SPAttributeEnum Id, class Base> + using T = TypedSPI<Id, Base>; + public: /* ----------------------- THE PROPERTIES ------------------------- */ @@ -97,197 +101,197 @@ public: /* SVG 2 attributes promoted to properties. */ /** Path data */ - SPIString d; + T<SP_ATTR_D, SPIString> d; /* Font ---------------------------- */ /** Font style */ - SPIEnum<SPCSSFontStyle> font_style; + T<SP_PROP_FONT_STYLE, SPIEnum<SPCSSFontStyle>> font_style; /** Which substyle of the font (CSS 2. CSS 3 redefines as shorthand) */ - SPIEnum<SPCSSFontVariant> font_variant; + T<SP_PROP_FONT_VARIANT, SPIEnum<SPCSSFontVariant>> font_variant; /** Weight of the font */ - SPIEnum<SPCSSFontWeight> font_weight; + T<SP_PROP_FONT_WEIGHT, SPIEnum<SPCSSFontWeight>> font_weight; /** Stretch of the font */ - SPIEnum<SPCSSFontStretch> font_stretch; + T<SP_PROP_FONT_STRETCH, SPIEnum<SPCSSFontStretch>> font_stretch; /** Size of the font */ - SPIFontSize font_size; + T<SP_PROP_FONT_SIZE, SPIFontSize> font_size; /** Line height (css2 10.8.1) */ - SPILengthOrNormal line_height; + T<SP_PROP_LINE_HEIGHT, SPILengthOrNormal> line_height; /** Font family */ - SPIString font_family; + T<SP_PROP_FONT_FAMILY, SPIString> font_family; /** Font shorthand */ - SPIFont font; + T<SP_PROP_FONT, SPIFont> font; /** Full font name, as font_factory::ConstructFontSpecification would give, for internal use. */ - SPIString font_specification; + T<SP_PROP_INKSCAPE_FONT_SPEC, SPIString> font_specification; /* Font variants -------------------- */ /** Font variant ligatures */ - SPILigatures font_variant_ligatures; + T<SP_PROP_FONT_VARIANT_LIGATURES, SPILigatures> font_variant_ligatures; /** Font variant position (subscript/superscript) */ - SPIEnum<SPCSSFontVariantPosition> font_variant_position; + T<SP_PROP_FONT_VARIANT_POSITION, SPIEnum<SPCSSFontVariantPosition>> font_variant_position; /** Font variant caps (small caps) */ - SPIEnum<SPCSSFontVariantCaps> font_variant_caps; + T<SP_PROP_FONT_VARIANT_CAPS, SPIEnum<SPCSSFontVariantCaps>> font_variant_caps; /** Font variant numeric (numerical formatting) */ - SPINumeric font_variant_numeric; + T<SP_PROP_FONT_VARIANT_NUMERIC, SPINumeric> font_variant_numeric; /** Font variant alternates (alternates/swatches) */ - SPIEnum<SPCSSFontVariantAlternates> font_variant_alternates; + T<SP_PROP_FONT_VARIANT_ALTERNATES, SPIEnum<SPCSSFontVariantAlternates>> font_variant_alternates; /** Font variant East Asian */ - SPIEastAsian font_variant_east_asian; + T<SP_PROP_FONT_VARIANT_EAST_ASIAN, SPIEastAsian> font_variant_east_asian; /** Font feature settings (Low level access to TrueType tables) */ - SPIString font_feature_settings; + T<SP_PROP_FONT_FEATURE_SETTINGS, SPIString> font_feature_settings; /** Font variation settings (Low level access to OpenType variable font design-coordinate values) */ - SPIFontVariationSettings font_variation_settings; + T<SP_PROP_FONT_VARIATION_SETTINGS, SPIFontVariationSettings> font_variation_settings; /* Text ----------------------------- */ /** First line indent of paragraphs (css2 16.1) */ - SPILength text_indent; + T<SP_PROP_TEXT_INDENT, SPILength> text_indent; /** text alignment (css2 16.2) (not to be confused with text-anchor) */ - SPIEnum<SPCSSTextAlign> text_align; + T<SP_PROP_TEXT_ALIGN, SPIEnum<SPCSSTextAlign>> text_align; /** letter spacing (css2 16.4) */ - SPILengthOrNormal letter_spacing; + T<SP_PROP_LETTER_SPACING, SPILengthOrNormal> letter_spacing; /** word spacing (also css2 16.4) */ - SPILengthOrNormal word_spacing; + T<SP_PROP_WORD_SPACING, SPILengthOrNormal> word_spacing; /** capitalization (css2 16.5) */ - SPIEnum<SPCSSTextTransform> text_transform; + T<SP_PROP_TEXT_TRANSFORM, SPIEnum<SPCSSTextTransform>> text_transform; /* CSS3 Text */ /** text direction (svg1.1) */ - SPIEnum<SPCSSDirection> direction; + T<SP_PROP_DIRECTION, SPIEnum<SPCSSDirection>> direction; /** Writing mode (svg1.1 10.7.2, CSS Writing Modes 3) */ - SPIEnum<SPCSSWritingMode> writing_mode; + T<SP_PROP_WRITING_MODE, SPIEnum<SPCSSWritingMode>> writing_mode; /** Text orientation (CSS Writing Modes 3) */ - SPIEnum<SPCSSTextOrientation> text_orientation; + T<SP_PROP_TEXT_ORIENTATION, SPIEnum<SPCSSTextOrientation>> text_orientation; /** Dominant baseline (svg1.1) */ - SPIEnum<SPCSSBaseline> dominant_baseline; + T<SP_PROP_DOMINANT_BASELINE, SPIEnum<SPCSSBaseline>> dominant_baseline; /** Baseline shift (svg1.1 10.9.2) */ - SPIBaselineShift baseline_shift; + T<SP_PROP_BASELINE_SHIFT, SPIBaselineShift> baseline_shift; /* SVG */ /** Anchor of the text (svg1.1 10.9.1) */ - SPIEnum<SPTextAnchor> text_anchor; + T<SP_PROP_TEXT_ANCHOR, SPIEnum<SPTextAnchor>> text_anchor; /** white space (svg2) */ - SPIEnum<SPWhiteSpace> white_space; + T<SP_PROP_WHITE_SPACE, SPIEnum<SPWhiteSpace>> white_space; /** SVG2 Text Wrapping */ - SPIShapes shape_inside; - SPIShapes shape_subtract; - SPILength shape_padding; - SPILength shape_margin; - SPILength inline_size; + T<SP_PROP_SHAPE_INSIDE, SPIShapes> shape_inside; + T<SP_PROP_SHAPE_SUBTRACT, SPIShapes> shape_subtract; + T<SP_PROP_SHAPE_PADDING, SPILength> shape_padding; + T<SP_PROP_SHAPE_MARGIN, SPILength> shape_margin; + T<SP_PROP_INLINE_SIZE, SPILength> inline_size; /* Text Decoration ----------------------- */ /** text decoration (css2 16.3.1) */ - SPITextDecoration text_decoration; + T<SP_PROP_TEXT_DECORATION, SPITextDecoration> text_decoration; /** CSS 3 2.1, 2.2, 2.3 */ /** Not done yet, test_decoration3 = css3 2.4*/ - SPITextDecorationLine text_decoration_line; - SPITextDecorationStyle text_decoration_style; // SPIEnum? Only one can be set at time. - SPIColor text_decoration_color; - SPIPaint text_decoration_fill; - SPIPaint text_decoration_stroke; + T<SP_PROP_TEXT_DECORATION_LINE, SPITextDecorationLine> text_decoration_line; + T<SP_PROP_TEXT_DECORATION_STYLE, SPITextDecorationStyle> text_decoration_style; // SPIEnum? Only one can be set at time. + T<SP_PROP_TEXT_DECORATION_COLOR, SPIColor> text_decoration_color; + T<SP_PROP_TEXT_DECORATION_FILL, SPIPaint> text_decoration_fill; + T<SP_PROP_TEXT_DECORATION_STROKE, SPIPaint> text_decoration_stroke; // used to implement text_decoration, not saved to or read from SVG file - SPITextDecorationData text_decoration_data; + SPITextDecorationData text_decoration_data; // 16.3.2 is text-shadow. That's complicated. /* General visual properties ------------- */ /** clip-rule: 0 nonzero, 1 evenodd */ - SPIEnum<SPWindRule> clip_rule; + T<SP_PROP_CLIP_RULE, SPIEnum<SPWindRule>> clip_rule; /** display */ - SPIEnum<SPCSSDisplay> display; + T<SP_PROP_DISPLAY, SPIEnum<SPCSSDisplay>> display; /** overflow */ - SPIEnum<SPOverflow> overflow; + T<SP_PROP_OVERFLOW, SPIEnum<SPOverflow>> overflow; /** visibility */ - SPIEnum<SPVisibility> visibility; + T<SP_PROP_VISIBILITY, SPIEnum<SPVisibility>> visibility; /** opacity */ - SPIScale24 opacity; + T<SP_PROP_OPACITY, SPIScale24> opacity; /** mix-blend-mode: CSS Compositing and Blending Level 1 */ - SPIEnum<SPIsolation> isolation; - SPIEnum<SPBlendMode> mix_blend_mode; + T<SP_PROP_ISOLATION, SPIEnum<SPIsolation>> isolation; + T<SP_PROP_MIX_BLEND_MODE, SPIEnum<SPBlendMode>> mix_blend_mode; - SPIPaintOrder paint_order; + T<SP_PROP_PAINT_ORDER, SPIPaintOrder> paint_order; /** color */ - SPIColor color; + T<SP_PROP_COLOR, SPIColor> color; /** color-interpolation */ - SPIEnum<SPColorInterpolation> color_interpolation; + T<SP_PROP_COLOR_INTERPOLATION, SPIEnum<SPColorInterpolation>> color_interpolation; /** color-interpolation-filters */ - SPIEnum<SPColorInterpolation> color_interpolation_filters; + T<SP_PROP_COLOR_INTERPOLATION_FILTERS, SPIEnum<SPColorInterpolation>> color_interpolation_filters; /** solid-color */ - SPIColor solid_color; + T<SP_PROP_SOLID_COLOR, SPIColor> solid_color; /** solid-opacity */ - SPIScale24 solid_opacity; + T<SP_PROP_SOLID_OPACITY, SPIScale24> solid_opacity; /** vector effect */ - SPIVectorEffect vector_effect; + T<SP_PROP_VECTOR_EFFECT, SPIVectorEffect> vector_effect; /** fill */ - SPIPaint fill; + T<SP_PROP_FILL, SPIPaint> fill; /** fill-opacity */ - SPIScale24 fill_opacity; + T<SP_PROP_FILL_OPACITY, SPIScale24> fill_opacity; /** fill-rule: 0 nonzero, 1 evenodd */ - SPIEnum<SPWindRule> fill_rule; + T<SP_PROP_FILL_RULE, SPIEnum<SPWindRule>> fill_rule; /** stroke */ - SPIPaint stroke; + T<SP_PROP_STROKE, SPIPaint> stroke; /** stroke-width */ - SPILength stroke_width; + T<SP_PROP_STROKE_WIDTH, SPILength> stroke_width; /** stroke-linecap */ - SPIEnum<SPStrokeCapType> stroke_linecap; + T<SP_PROP_STROKE_LINECAP, SPIEnum<SPStrokeCapType>> stroke_linecap; /** stroke-linejoin */ - SPIEnum<SPStrokeJoinType> stroke_linejoin; + T<SP_PROP_STROKE_LINEJOIN, SPIEnum<SPStrokeJoinType>> stroke_linejoin; /** stroke-miterlimit */ - SPIFloat stroke_miterlimit; + T<SP_PROP_STROKE_MITERLIMIT, SPIFloat> stroke_miterlimit; /** stroke-dasharray */ - SPIDashArray stroke_dasharray; + T<SP_PROP_STROKE_DASHARRAY, SPIDashArray> stroke_dasharray; /** stroke-dashoffset */ - SPILength stroke_dashoffset; + T<SP_PROP_STROKE_DASHOFFSET, SPILength> stroke_dashoffset; /** stroke-opacity */ - SPIScale24 stroke_opacity; + T<SP_PROP_STROKE_OPACITY, SPIScale24> stroke_opacity; /** Marker list */ - SPIString marker; - SPIString marker_start; - SPIString marker_mid; - SPIString marker_end; + T<SP_PROP_MARKER, SPIString> marker; + T<SP_PROP_MARKER_START, SPIString> marker_start; + T<SP_PROP_MARKER_MID, SPIString> marker_mid; + T<SP_PROP_MARKER_END, SPIString> marker_end; SPIString* marker_ptrs[SP_MARKER_LOC_QTY]; /* Filter effects ------------------------ */ /** Filter effect */ - SPIFilter filter; + T<SP_PROP_FILTER, SPIFilter> filter; /** Filter blend mode */ - SPIEnum<SPBlendMode> filter_blend_mode; + T<SP_ATTR_INVALID, SPIEnum<SPBlendMode>> filter_blend_mode; /** normally not used, but duplicates the Gaussian blur deviation (if any) from the attached filter when the style is used for querying */ - SPILength filter_gaussianBlur_deviation; + T<SP_ATTR_INVALID, SPILength> filter_gaussianBlur_deviation; /** enable-background, used for defining where filter effects get their background image */ - SPIEnum<SPEnableBackground> enable_background; + T<SP_PROP_ENABLE_BACKGROUND, SPIEnum<SPEnableBackground>> enable_background; /** gradient-stop */ - SPIColor stop_color; - SPIScale24 stop_opacity; + T<SP_PROP_STOP_COLOR, SPIColor> stop_color; + T<SP_PROP_STOP_OPACITY, SPIScale24> stop_opacity; /* Rendering hints ----------------------- */ /** hints on how to render: e.g. speed vs. accuracy. * As of April, 2013, only image_rendering used. */ - SPIEnum<SPColorRendering> color_rendering; - SPIEnum<SPImageRendering> image_rendering; - SPIEnum<SPShapeRendering> shape_rendering; - SPIEnum<SPTextRendering> text_rendering; + T<SP_PROP_COLOR_RENDERING, SPIEnum<SPColorRendering>> color_rendering; + T<SP_PROP_IMAGE_RENDERING, SPIEnum<SPImageRendering>> image_rendering; + T<SP_PROP_SHAPE_RENDERING, SPIEnum<SPShapeRendering>> shape_rendering; + T<SP_PROP_TEXT_RENDERING, SPIEnum<SPTextRendering>> text_rendering; /* ----------------------- END PROPERTIES ------------------------- */ @@ -333,6 +337,11 @@ public: */ std::string getFontFeatureString(); + /** + * Get either the fill or the stroke property + */ + SPIPaint *getFillOrStroke(bool fill_) { return fill_ ? fill.upcast() : stroke.upcast(); } + SPIPaint const *getFillOrStroke(bool fill_) const { return fill_ ? fill.upcast() : stroke.upcast(); } }; SPStyle *sp_style_ref(SPStyle *style); // SPStyle::ref(); diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index f8eb00d7a..114cbb1b3 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -248,8 +248,8 @@ void FillNStroke::performUpdate() // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection int result = sp_desktop_query_style(desktop, &query, (kind == FILL) ? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE); - SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke; - SPIScale24 &targOpacity = (kind == FILL) ? query.fill_opacity : query.stroke_opacity; + SPIPaint &targPaint = *query.getFillOrStroke(kind == FILL); + SPIScale24 &targOpacity = *(kind == FILL ? query.fill_opacity.upcast() : query.stroke_opacity.upcast()); switch (result) { case QUERY_STYLE_NOTHING: @@ -561,7 +561,7 @@ void FillNStroke::updateFromPaint() SPStyle query(desktop->doc()); int result = objects_query_fillstroke(items, &query, kind == FILL); if (result == QUERY_STYLE_MULTIPLE_SAME) { - SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke; + SPIPaint &targPaint = *query.getFillOrStroke(kind == FILL); SPColor common; if (!targPaint.isColor()) { common = sp_desktop_get_color(desktop, kind == FILL); @@ -755,7 +755,7 @@ void FillNStroke::updateFromPaint() SPObject *selobj = item; SPStyle *style = selobj->style; - if (style && ((kind == FILL) ? style->fill : style->stroke).isPaintserver()) { + if (style && ((kind == FILL) ? style->fill.isPaintserver() : style->stroke.isPaintserver())) { SPPaintServer *server = (kind == FILL) ? selobj->style->getFillPaintServer() : selobj->style->getStrokePaintServer(); diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index cc5fe0185..b9bd99bd8 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -346,7 +346,7 @@ static void get_all_doc_items(std::vector<SPItem*> &list, SPObject *from) */ static SPGradient * gr_item_get_gradient(SPItem *item, gboolean fillorstroke) { - SPIPaint *item_paint = (fillorstroke) ? &(item->style->fill) : &(item->style->stroke); + SPIPaint *item_paint = item->style->getFillOrStroke(fillorstroke); if (item_paint->isPaintserver()) { SPPaintServer *item_server = (fillorstroke) ? diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index e80951928..e108fa504 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -1545,7 +1545,7 @@ void SPPaintSelector::setFlatColor( SPDesktop *desktop, gchar const *color_prope SPPaintSelector::Mode SPPaintSelector::getModeForStyle(SPStyle const & style, FillOrStroke kind) { Mode mode = MODE_UNSET; - SPIPaint const & target = (kind == FILL) ? style.fill : style.stroke; + SPIPaint const &target = *style.getFillOrStroke(kind == FILL); if ( !target.set ) { mode = MODE_UNSET; diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 48f0e3d78..44f9ac714 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -877,7 +877,7 @@ StrokeStyle::updateLine() int result_order = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_PAINTORDER); - SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke; + SPIPaint &targPaint = *query.getFillOrStroke(kind == FILL); if (!sel || sel->isEmpty()) { // Nothing selected, grey-out all controls in the stroke-style dialog |
