From f0b0773ecf0249c576e58059864f3a0ecbac64ec Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 30 May 2014 15:38:31 +0200 Subject: Unquote names in 'font-family' lists. Partial fix for #1029080 (bzr r13341.1.42) --- src/style.cpp | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index 11b1dc440..8e4c89839 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -58,6 +58,8 @@ #include <2geom/math-utils.h> +#include + using Inkscape::CSSOStringStream; using std::vector; @@ -1824,31 +1826,43 @@ sp_css_attr_scale(SPCSSAttr *css, double ex) } -// Called in style.cpp, xml/repr-css.cpp +// Called in style-internal.cpp, xml/repr-css.cpp /** - * Remove quotes and escapes from a string. Returned value must be g_free'd. + * Remove paired single and double quotes from a string, changing string in place. * Note: in CSS (in style= and in stylesheets), unquoting and unescaping is done * by libcroco, our CSS parser, though it adds a new pair of "" quotes for the strings - * it parsed for us. So this function is only used to remove those quotes and for - * presentation attributes, without any unescaping. (XML unescaping - * (& etc) is done by XML parser.) + * it parsed for us. */ -gchar * -attribute_unquote(gchar const *val) +void +css_unquote(Glib::ustring &val) { - if (val) { - if (*val == '\'' || *val == '"') { - int l = strlen(val); - if (l >= 2) { - if ( ( val[0] == '"' && val[l - 1] == '"' ) || - ( val[0] == '\'' && val[l - 1] == '\'' ) ) { - return (g_strndup (val+1, l-2)); - } - } - } - } + if( val.size() > 1 && + ( (val[0] == '"' && val[val.size()-1] == '"' ) || + (val[0] == '\'' && val[val.size()-1] == '\'' ) ) ) { - return (val? g_strdup (val) : NULL); + val.erase( 0, 1 ); + val.erase( val.size()-1 ); + } +} + +// Called in style-internal.cpp, text-toolbar.cpp +/** + * Remove paired single and double quotes from font names in font-family lists, + * changing string in place. + * Pango expects unquoted font family names. We use unquoted names in interface. + */ +void +css_font_family_unquote(Glib::ustring &val) +{ + std::vector tokens = Glib::Regex::split_simple("\\s*,\\s*", val ); + + val.erase(); + for( unsigned i=0; i < tokens.size(); ++i ) { + css_unquote( tokens[i] ); + val += tokens[i] + ", "; + } + if( val.size() > 1 ) + val.erase( val.size() - 2 ); // Remove trailing ", " } // Called in style.cpp, xml/repr-css.cpp -- cgit v1.2.3 From 3252b41582b781c90648c0ad892f45751377b57c Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 10 Jun 2014 11:40:10 +0200 Subject: Proper quoting of CSS 'font-family' fallback lists. (bzr r13341.1.56) --- src/style.cpp | 114 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 59 insertions(+), 55 deletions(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index 8e4c89839..c6a98e7f4 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -1826,12 +1826,67 @@ sp_css_attr_scale(SPCSSAttr *css, double ex) } +/** + * Quote and/or escape string for writing to CSS, changing strings in place. + * See: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier + */ +void +css_quote(Glib::ustring &val) +{ + Glib::ustring out; + bool quote = false; + + // Can't wait for C++11! + for( Glib::ustring::iterator it = val.begin(); it != val.end(); ++it) { + if(g_ascii_isalnum(*it) || *it=='-' || *it=='_' || *it > 0xA0) { + out += *it; + } else if (*it == '\'') { + // Single quotes require escaping and quotes. + out += '\\'; + out += *it; + quote = true; + } else { + // Quote everything else including spaces. + // (CSS Fonts Level 3 recommends quoting with spaces.) + out += *it; + quote = true; + } + if( it == val.begin() && !g_ascii_isalpha(*it) ) { + // A non-ASCII/non-alpha initial value on any indentifier needs quotes. + // (Actually it's a bit more complicated but as it never hurts to quote...) + quote = true; + } + } + if( quote ) { + out.insert( out.begin(), '\'' ); + out += '\''; + } + val = out; +} + + +/** + * Quote font names in font-family lists, changing string in place. + * We use unquoted names internally but some need to be quoted in CSS. + */ +void +css_font_family_quote(Glib::ustring &val) +{ + std::vector tokens = Glib::Regex::split_simple("\\s*,\\s*", val ); + + val.erase(); + for( unsigned i=0; i < tokens.size(); ++i ) { + css_quote( tokens[i] ); + val += tokens[i] + ", "; + } + if( val.size() > 1 ) + val.erase( val.size() - 2 ); // Remove trailing ", " +} + + // Called in style-internal.cpp, xml/repr-css.cpp /** * Remove paired single and double quotes from a string, changing string in place. - * Note: in CSS (in style= and in stylesheets), unquoting and unescaping is done - * by libcroco, our CSS parser, though it adds a new pair of "" quotes for the strings - * it parsed for us. */ void css_unquote(Glib::ustring &val) @@ -1849,7 +1904,7 @@ css_unquote(Glib::ustring &val) /** * Remove paired single and double quotes from font names in font-family lists, * changing string in place. - * Pango expects unquoted font family names. We use unquoted names in interface. + * We use unquoted family names internally but CSS sometimes uses quoted names. */ void css_font_family_unquote(Glib::ustring &val) @@ -1865,57 +1920,6 @@ css_font_family_unquote(Glib::ustring &val) val.erase( val.size() - 2 ); // Remove trailing ", " } -// 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. - */ -Glib::ustring css2_escape_quote(gchar const *val) { - - Glib::ustring t; - bool quote = false; - bool last_was_space = false; - - for (gchar const *i = val; *i; i++) { - bool is_space = ( *i == ' ' ); - if (g_ascii_isalnum(*i) || *i=='-' || *i=='_') { - // ASCII alphanumeric, - and _ don't require quotes - t.push_back(*i); - } else if ( is_space && !last_was_space ) { - // non-consecutive spaces don't require quotes - t.push_back(*i); - } else if (*i=='\'') { - // single quotes require escaping and quotes - t.push_back('\\'); - t.push_back(*i); - quote = true; - } else { - // everything else requires quotes - t.push_back(*i); - quote = true; - } - if (i == val && !g_ascii_isalpha(*i)) { - // a non-ASCII/non-alpha initial character requires quotes - quote = true; - } - last_was_space = is_space; - } - - if (last_was_space) { - // a trailing space requires quotes - quote = true; - } - - if (quote) { - // we use single quotes so the result can be stored in an XML - // attribute without incurring un-aesthetic additional quoting - // (our XML emitter always uses double quotes) - t.insert(t.begin(), '\''); - t.push_back('\''); - } - - return t; -} - /* Local Variables: mode:c++ -- cgit v1.2.3 From b784997fa7a911f53b1ad9386f8ac631d85143b2 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 24 Jul 2014 11:43:00 +0200 Subject: Basic support for element (rendring only as a paint server). (bzr r13341.1.98) --- src/style.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index c6a98e7f4..3691a3e48 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -153,6 +153,10 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : 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), + // Solid color properties + solid_color( "solid-color" ), // SPIColor + solid_opacity( "solid-opacity", SP_SCALE24_MAX ), + // Fill properties fill( "fill" ), // SPIPaint fill_opacity( "fill-opacity", SP_SCALE24_MAX ), @@ -311,6 +315,9 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : _properties.push_back( &color_interpolation ); _properties.push_back( &color_interpolation_filters ); + _properties.push_back( &solid_color ); + _properties.push_back( &solid_opacity ); + _properties.push_back( &fill ); _properties.push_back( &fill_opacity ); _properties.push_back( &fill_rule ); @@ -390,10 +397,14 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : // _propmap.insert( std::make_pair( color_interpolation.name, reinterpret_cast(&SPStyle::color_interpolation ) ) ); // _propmap.insert( std::make_pair( color_interpolation_filters.name, reinterpret_cast(&SPStyle::color_interpolation_filters ) ) ); + // _propmap.insert( std::make_pair( solid_color.name, reinterpret_cast(&SPStyle::solid_color ) ) ); + // _propmap.insert( std::make_pair( solid_opacity.name, reinterpret_cast(&SPStyle::solid_opacity ) ) ); + // _propmap.insert( std::make_pair( fill.name, reinterpret_cast(&SPStyle::fill ) ) ); // _propmap.insert( std::make_pair( fill_opacity.name, reinterpret_cast(&SPStyle::fill_opacity ) ) ); // _propmap.insert( std::make_pair( fill_rule.name, reinterpret_cast(&SPStyle::fill_rule ) ) ); + // _propmap.insert( std::make_pair( stroke.name, reinterpret_cast(&SPStyle::stroke ) ) ); // _propmap.insert( std::make_pair( stroke_width.name, reinterpret_cast(&SPStyle::stroke_width ) ) ); // _propmap.insert( std::make_pair( stroke_linecap.name, reinterpret_cast(&SPStyle::stroke_linecap ) ) ); @@ -790,6 +801,12 @@ SPStyle::readIfUnset( gint id, gchar const *val ) { case SP_PROP_COLOR_RENDERING: color_rendering.readIfUnset( val ); break; + case SP_PROP_SOLID_COLOR: + solid_color.readIfUnset( val ); + break; + case SP_PROP_SOLID_OPACITY: + solid_opacity.readIfUnset( val ); + break; case SP_PROP_FILL: fill.readIfUnset( val ); break; @@ -1557,6 +1574,12 @@ sp_style_unset_property_attrs(SPObject *o) if (style->color_interpolation_filters.set) { repr->setAttribute("color-interpolation-filters", NULL); } + if (style->solid_color.set) { + repr->setAttribute("solid-color", NULL); + } + if (style->solid_opacity.set) { + repr->setAttribute("solid-opacity", NULL); + } if (style->fill.set) { repr->setAttribute("fill", NULL); } -- cgit v1.2.3 From b7ebc313abd7f6aa501370d58ba54e6169e4218e Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 30 Jul 2014 10:31:31 +0200 Subject: Read CSS Text 3 'white-space' property, SVG 2 'width', 'height' attributes. (bzr r13341.1.110) --- src/style.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index f0710e404..97aae016a 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -135,6 +135,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : 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 ), + white_space( "white-space", enum_white_space, SP_CSS_WHITE_SPACE_NORMAL ), // General visual properties clip_rule( "clip-rule", enum_clip_rule, SP_WIND_RULE_NONZERO ), @@ -297,6 +298,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : _properties.push_back( &writing_mode ); _properties.push_back( &baseline_shift ); _properties.push_back( &text_anchor ); + _properties.push_back( &white_space ); _properties.push_back( &clip_rule ); _properties.push_back( &display ); @@ -379,6 +381,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : // _propmap.insert( std::make_pair( writing_mode.name, reinterpret_cast(&SPStyle::writing_mode ) ) ); // _propmap.insert( std::make_pair( baseline_shift.name, reinterpret_cast(&SPStyle::baseline_shift ) ) ); // _propmap.insert( std::make_pair( text_anchor.name, reinterpret_cast(&SPStyle::text_anchor ) ) ); + // _propmap.insert( std::make_pair( white_space.name, reinterpret_cast(&SPStyle::white_space ) ) ); // _propmap.insert( std::make_pair( clip_rule.name, reinterpret_cast(&SPStyle::clip_rule ) ) ); // _propmap.insert( std::make_pair( display.name, reinterpret_cast(&SPStyle::display ) ) ); @@ -670,6 +673,9 @@ SPStyle::readIfUnset( gint id, gchar const *val ) { case SP_PROP_TEXT_ANCHOR: text_anchor.readIfUnset( val ); break; + case SP_PROP_WHITE_SPACE: + white_space.readIfUnset( val ); + break; case SP_PROP_BASELINE_SHIFT: baseline_shift.readIfUnset( val ); break; @@ -1623,6 +1629,9 @@ sp_style_unset_property_attrs(SPObject *o) if (style->text_anchor.set) { repr->setAttribute("text-anchor", NULL); } + if (style->white_space.set) { + repr->setAttribute("white_space", NULL); + } if (style->writing_mode.set) { repr->setAttribute("writing_mode", NULL); } @@ -1712,6 +1721,7 @@ sp_css_attr_unset_text(SPCSSAttr *css) sp_repr_css_set_property(css, "block-progression", NULL); sp_repr_css_set_property(css, "writing-mode", NULL); sp_repr_css_set_property(css, "text-anchor", NULL); + sp_repr_css_set_property(css, "white_space", NULL); sp_repr_css_set_property(css, "kerning", NULL); // not implemented yet sp_repr_css_set_property(css, "dominant-baseline", NULL); // not implemented yet sp_repr_css_set_property(css, "alignment-baseline", NULL); // not implemented yet -- cgit v1.2.3 From 8b31d0e28a6cf0f916f5267c54fed76c712c48a3 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 1 Aug 2014 10:13:43 +0200 Subject: Rename 'blend-mode' property to 'mix-blend-mode' per CSS spec. (bzr r13341.1.113) --- src/style.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index 97aae016a..5f8a8d82e 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -145,7 +145,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : 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 ), + mix_blend_mode( "mix_blend_mode", enum_blend_mode, SP_CSS_BLEND_NORMAL ), paint_order(), // SPIPaintOrder @@ -307,7 +307,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : _properties.push_back( &opacity ); _properties.push_back( &isolation ); - _properties.push_back( &blend_mode ); + _properties.push_back( &mix_blend_mode ); _properties.push_back( &color_interpolation ); _properties.push_back( &color_interpolation_filters ); @@ -390,7 +390,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : // _propmap.insert( std::make_pair( opacity.name, reinterpret_cast(&SPStyle::opacity ) ) ); // _propmap.insert( std::make_pair( isolation.name, reinterpret_cast(&SPStyle::isolation ) ) ); - // _propmap.insert( std::make_pair( blend_mode.name, reinterpret_cast(&SPStyle::blend_mode ) ) ); + // _propmap.insert( std::make_pair( mix_blend_mode.name, reinterpret_cast(&SPStyle::mix_blend_mode ) ) ); // _propmap.insert( std::make_pair( color_interpolation.name, reinterpret_cast(&SPStyle::color_interpolation ) ) ); // _propmap.insert( std::make_pair( color_interpolation_filters.name, reinterpret_cast(&SPStyle::color_interpolation_filters ) ) ); @@ -719,8 +719,8 @@ SPStyle::readIfUnset( gint id, gchar const *val ) { case SP_PROP_ISOLATION: isolation.readIfUnset( val ); break; - case SP_PROP_BLEND_MODE: - blend_mode.readIfUnset( val ); + case SP_PROP_MIX_BLEND_MODE: + mix_blend_mode.readIfUnset( val ); break; /* SVG */ -- cgit v1.2.3 From 6dde092cd67702688e9c5e243c5b1fcf8a46d8f9 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 1 Aug 2014 11:02:54 +0200 Subject: Fix type in 'mix-blend-mode'. (bzr r13341.1.114) --- src/style.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index 5f8a8d82e..a91611d89 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -145,7 +145,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : opacity( "opacity", SP_SCALE24_MAX, false ), isolation( "isolation", enum_isolation, SP_CSS_ISOLATION_AUTO ), - mix_blend_mode( "mix_blend_mode", enum_blend_mode, SP_CSS_BLEND_NORMAL ), + mix_blend_mode( "mix-blend-mode", enum_blend_mode, SP_CSS_BLEND_NORMAL ), paint_order(), // SPIPaintOrder -- cgit v1.2.3 From db7a8fdb0e8141c84886129ff2344c1959a26c49 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Mon, 4 Aug 2014 13:07:28 -0400 Subject: Warnings cleanup. (bzr r13341.1.117) --- src/style.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index a91611d89..66672e949 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -121,10 +121,6 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : // 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 @@ -137,6 +133,11 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : text_anchor( "text-anchor", enum_text_anchor, SP_CSS_TEXT_ANCHOR_START ), white_space( "white-space", enum_white_space, SP_CSS_WHITE_SPACE_NORMAL ), + text_decoration(), + text_decoration_line(), + text_decoration_style(), + text_decoration_color( "text-decoration-color" ), // SPIColor + // General visual properties clip_rule( "clip-rule", enum_clip_rule, SP_WIND_RULE_NONZERO ), display( "display", enum_display, SP_CSS_DISPLAY_INLINE, false ), @@ -190,7 +191,6 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : 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; -- cgit v1.2.3