From 6a0c44e21967ec8f4170993b7ec7506e3c0c5e5e Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 7 May 2014 14:25:58 +0200 Subject: Style rewrite: prevent crash when fill/stroke set to "currentColor". (bzr r13341.1.1) --- src/style-internal.cpp | 122 ++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) (limited to 'src/style-internal.cpp') diff --git a/src/style-internal.cpp b/src/style-internal.cpp index df08d0adf..c74683a7a 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -65,13 +65,13 @@ SPIFloat::read( gchar const *str ) { if( !str ) return; if ( !strcmp(str, "inherit") ) { - set = TRUE; - inherit = TRUE; + set = true; + inherit = true; } else { gfloat value_tmp; if (sp_svg_number_read_f(str, &value_tmp)) { - set = TRUE; - inherit = FALSE; + set = true; + inherit = false; value = value_tmp; } } @@ -140,13 +140,13 @@ SPIScale24::read( gchar const *str ) { if( !str ) return; if ( !strcmp(str, "inherit") ) { - set = TRUE; - inherit = TRUE; + set = true; + inherit = true; } else { gfloat value_in; if (sp_svg_number_read_f(str, &value_in)) { - set = TRUE; - inherit = FALSE; + set = true; + inherit = false; value_in = CLAMP(value_in, 0.0, 1.0); value = SP_SCALE24_FROM_FLOAT( value_in ); } @@ -228,8 +228,8 @@ SPILength::read( gchar const *str ) { if( !str ) return; if (!strcmp(str, "inherit")) { - set = TRUE; - inherit = TRUE; + set = true; + inherit = true; unit = SP_CSS_UNIT_NONE; value = computed = 0.0; } else { @@ -291,8 +291,8 @@ SPILength::read( gchar const *str ) { /* Invalid */ return; } - set = TRUE; - inherit = FALSE; + set = true; + inherit = false; } } } @@ -439,11 +439,11 @@ SPILengthOrNormal::read( gchar const *str ) { if( !str ) return; if ( !strcmp(str, "normal") ) { - set = TRUE; - inherit = FALSE; + set = true; + inherit = false; unit = SP_CSS_UNIT_NONE; value = computed = 0.0; - normal = TRUE; + normal = true; } else { SPILength::read( str ); normal = false; @@ -501,13 +501,13 @@ SPIEnum::read( gchar const *str ) { if( !str ) return; if( !strcmp(str, "inherit") ) { - set = TRUE; - inherit = TRUE; + set = true; + inherit = true; } else { for (unsigned i = 0; enums[i].key; i++) { if (!strcmp(str, enums[i].key)) { - set = TRUE; - inherit = FALSE; + set = true; + inherit = false; value = enums[i].value; /* Save copying for values not needing it */ computed = value; @@ -651,12 +651,12 @@ SPIString::read( gchar const *str ) { g_free(value); if (!strcmp(str, "inherit")) { - set = TRUE; - inherit = TRUE; + set = true; + inherit = true; value = NULL; } else { - set = TRUE; - inherit = FALSE; + set = true; + inherit = false; value = g_strdup(str); } } @@ -762,13 +762,13 @@ void SPIColor::read( gchar const *str ) { if( name.compare( "color") == 0 ) { inherit = true; // CSS3 } else { - value.color = style->color.value.color; + setColor( style->color.value.color ); } } else { guint32 const rgb0 = sp_svg_read_color(str, 0xff); if (rgb0 != 0xff) { setColor(rgb0); - set = TRUE; + set = true; } } } @@ -821,7 +821,7 @@ SPIColor::cascade( const SPIBase* const parent ) { if( const SPIColor* p = dynamic_cast(parent) ) { if( (inherits && !set) || inherit) { // FIXME verify for 'color' if( !(inherit && currentcolor) ) currentcolor = p->currentcolor; - value.color = p->value.color; + setColor( p->value.color ); } else { // Add CSS4 Color: Lighter, Darker } @@ -910,8 +910,8 @@ SPIPaint::read( gchar const *str ) { } if (streq(str, "inherit")) { - set = TRUE; - inherit = TRUE; + set = true; + inherit = true; } else { // Read any URL first. The other values can be stand-alone or backup to the URL. @@ -924,7 +924,7 @@ SPIPaint::read( gchar const *str ) { } else if (!style ) { std::cerr << "SPIPaint::read: url with empty SPStyle pointer" << std::endl; } else { - set = TRUE; + set = true; SPDocument *document = (style->object) ? style->object->document : NULL; // Create href if not done already @@ -946,17 +946,17 @@ SPIPaint::read( gchar const *str ) { } if (streq(str, "currentColor")) { - set = TRUE; - currentcolor = TRUE; - value.color = style->color.value.color; + set = true; + currentcolor = true; + setColor( style->color.value.color ); } else if (streq(str, "none")) { - set = TRUE; - noneSet = TRUE; + set = true; + noneSet = true; } else { guint32 const rgb0 = sp_svg_read_color(str, &str, 0xff); if (rgb0 != 0xff) { setColor( rgb0 ); - set = TRUE; + set = true; while (g_ascii_isspace(*str)) { ++str; @@ -1076,7 +1076,7 @@ SPIPaint::reset( bool init ) { setColor(0.0, 0.0, 0.0); } if( name.compare( "text-decoration-color" ) == 0 ) { - currentcolor = true; + // currentcolor = true; } } } @@ -1100,10 +1100,10 @@ SPIPaint::cascade( const SPIBase* const parent ) { } else if( p->isColor() ) { setColor( p->value.color ); } else if( p->isNoneSet() ) { - noneSet = TRUE; + noneSet = true; } else if( p->currentcolor ) { - currentcolor = TRUE; - value.color = style->color.value.color; + currentcolor = true; + setColor( style->color.value.color ); } else if( isNone() ) { // } else { @@ -1112,7 +1112,7 @@ SPIPaint::cascade( const SPIBase* const parent ) { } else { if( currentcolor ) { // Update in case color value changed. - value.color = style->color.value.color; + setColor( style->color.value.color ); } } @@ -1179,14 +1179,14 @@ SPIPaintOrder::read( gchar const *str ) { if( !str ) return; g_free(value); - set = FALSE; - inherit = FALSE; + set = false; + inherit = false; if (!strcmp(str, "inherit")) { - set = TRUE; - inherit = TRUE; + set = true; + inherit = true; } else { - set = TRUE; + set = true; value = g_strdup(str); if (!strcmp(value, "normal")) { @@ -1347,10 +1347,10 @@ SPIFilter::read( gchar const *str ) { clear(); if ( streq(str, "inherit") ) { - set = TRUE; - inherit = TRUE; + set = true; + inherit = true; } else if(streq(str, "none")) { - set = TRUE; + set = true; } else if (strneq(str, "url", 3)) { gchar *uri = extract_uri(str); if(uri == NULL || uri[0] == '\0') { @@ -1360,7 +1360,7 @@ SPIFilter::read( gchar const *str ) { std::cerr << "SPIFilter::read: url with empty SPStyle pointer" << std::endl; return; } - set = TRUE; + set = true; // Create href if not already done. if (!href && style->object) { @@ -1592,14 +1592,14 @@ SPIFontSize::read( gchar const *str ) { if( !str ) return; if (!strcmp(str, "inherit")) { - set = TRUE; - inherit = TRUE; + set = true; + 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)) { - set = TRUE; - inherit = FALSE; + set = true; + inherit = false; type = SP_FONT_SIZE_LITERAL; literal = enum_font_size[i].value; return; @@ -1609,10 +1609,10 @@ SPIFontSize::read( gchar const *str ) { return; } else { SPILength length("temp"); - length.set = FALSE; + length.set = false; length.read( str ); if( length.set ) { - set = TRUE; + set = true; inherit = length.inherit; unit = length.unit; value = length.value; @@ -1824,8 +1824,8 @@ SPIFont::read( gchar const *str ) { } if ( !strcmp(str, "inherit") ) { - set = TRUE; - inherit = TRUE; + set = true; + inherit = true; } else { // Break string into white space separated tokens @@ -1957,14 +1957,14 @@ SPIBaselineShift::read( gchar const *str ) { if( !str ) return; if (!strcmp(str, "inherit")) { - set = TRUE; - inherit = TRUE; + set = true; + 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)) { - set = TRUE; - inherit = FALSE; + set = true; + inherit = false; type = SP_BASELINE_SHIFT_LITERAL; literal = enum_baseline_shift[i].value; return; -- cgit v1.2.3 From d9496e287b19b63ad567b2ef95bc97f5b3100f6f Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 9 May 2014 15:06:22 +0200 Subject: Style rewrite: Correct 'text-decoration' CSS2 vs. CSS3 behavior. (bzr r13341.1.3) --- src/style-internal.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/style-internal.cpp') diff --git a/src/style-internal.cpp b/src/style-internal.cpp index c74683a7a..bfe708e7a 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -2425,11 +2425,21 @@ SPITextDecoration::read( gchar const *str ) { free(frag); if( style->text_decoration_color.set ) break; style->text_decoration_color.read( "currentColor" ); // Default value + style->text_decoration_color.set = false; if( *str == '\0' )break; hstr = str + 1; } str++; } + + // If we read a style or color then we have CSS3 which require any non-set values to be + // set to their default values. + if( style->text_decoration_style.set == true || + style->text_decoration_style.set == true ) { + style->text_decoration_line.set = true; + style->text_decoration_style.set = true; + style->text_decoration_color.set = true; + } } // Returns CSS2 'text-decoration' (using settings in SPTextDecorationLine) -- cgit v1.2.3 From 4302660fe98b575843bde77a0d7ded72920a701c Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 10 May 2014 12:32:28 +0200 Subject: Style rewrite: 'text-decoration' requires access to style of ancestor element which set property. (bzr r13341.1.4) --- src/style-internal.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/style-internal.cpp') diff --git a/src/style-internal.cpp b/src/style-internal.cpp index bfe708e7a..508fb677c 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -2440,6 +2440,11 @@ SPITextDecoration::read( gchar const *str ) { style->text_decoration_style.set = true; style->text_decoration_color.set = true; } + + // If we set text_decoration_line, then update style_td (for CSS2 text-decoration) + if( style->text_decoration_line.set == true ) { + style_td = style; + } } // Returns CSS2 'text-decoration' (using settings in SPTextDecorationLine) @@ -2474,10 +2479,17 @@ SPITextDecoration::write( guint const flags, SPIBase const *const base) const { return Glib::ustring(""); } -// Done in SPITextDecorationLine -// void -// SPITextDecoration::cascade( const SPIBase* const parent ) { -// } +void +SPITextDecoration::cascade( const SPIBase* const parent ) { + if( const SPITextDecoration* p = dynamic_cast(parent) ) { + if( style_td == NULL ) { + style_td = p->style_td; + } + } else { + std::cerr << "SPITextDecoration::cascade(): Incorrect parent type" << std::endl; + } + +} // void // SPITextDecoration::merge( const SPIBase* const parent ) { -- cgit v1.2.3 From fe03965ac74349efcc592bee4a9b05542de613eb Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 13 May 2014 15:32:45 +0200 Subject: Style rewrite: Prevent CSS2 'text-decoration' from overwriting CSS3 'text-decoration-xxx'. Suppress unused variable warnings. (bzr r13341.1.15) --- src/style-internal.cpp | 55 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 14 deletions(-) (limited to 'src/style-internal.cpp') diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 508fb677c..2c488105b 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -2405,27 +2405,47 @@ SPITextDecoration::read( gchar const *str ) { if( !str ) return; - style->text_decoration_line.read( str ); - style->text_decoration_style.read( str ); + bool is_css3 = false; + + SPITextDecorationLine test_line; + test_line.read( str ); + if( test_line.set ) { + style->text_decoration_line = test_line; + } + + SPITextDecorationStyle test_style; + test_style.read( str ); + if( test_style.set ) { + style->text_decoration_style = test_style; + is_css3 = true; + } + // the color routine must be fed one token at a time - if multiple colors are found the LAST // one is used ???? then why break on set? - const gchar *hstr = str; - style->text_decoration_color.read( "currentColor" ); // Default value - style->text_decoration_color.set = false; + // This could certainly be designed better + SPIColor test_color("text-decoration-color"); + test_color.setStylePointer( style ); + test_color.read( "currentColor" ); // Default value + test_color.set = false; + 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 if( strcmp( frag, "none" ) != 0 ) { // 'none' not allowed - style->text_decoration_color.read( frag ); + test_color.read( frag ); } free(frag); - if( style->text_decoration_color.set ) break; - style->text_decoration_color.read( "currentColor" ); // Default value - style->text_decoration_color.set = false; + if( test_color.set ) { + style->text_decoration_color = test_color; + is_css3 = true; + break; + } + test_color.read( "currentColor" ); // Default value + test_color.set = false; if( *str == '\0' )break; hstr = str + 1; } @@ -2434,8 +2454,7 @@ SPITextDecoration::read( gchar const *str ) { // If we read a style or color then we have CSS3 which require any non-set values to be // set to their default values. - if( style->text_decoration_style.set == true || - style->text_decoration_style.set == true ) { + if( is_css3 ) { style->text_decoration_line.set = true; style->text_decoration_style.set = true; style->text_decoration_color.set = true; @@ -2491,9 +2510,17 @@ SPITextDecoration::cascade( const SPIBase* const parent ) { } -// void -// SPITextDecoration::merge( const SPIBase* const parent ) { -// } +void +SPITextDecoration::merge( const SPIBase* const parent ) { + if( const SPITextDecoration* p = dynamic_cast(parent) ) { + if( style_td == NULL ) { + style_td = p->style_td; + } + } else { + std::cerr << "SPITextDecoration::merge(): Incorrect parent type" << std::endl; + } + +} // Use CSS2 value bool -- cgit v1.2.3 From d1022d88770ba85ab55285f8d59e0d3ee94ec153 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 15 May 2014 12:22:12 +0200 Subject: Style rewrite: Unquote strings from libcroco. Fixes 1303422. Fixed bugs: - https://launchpad.net/bugs/1303422 (bzr r13341.1.23) --- src/style-internal.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/style-internal.cpp') diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 2c488105b..b15892128 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -648,7 +648,8 @@ SPIString::read( gchar const *str ) { if( !str ) return; - g_free(value); + // libcroco puts quotes around some strings... remove + gchar *str_unquoted = attribute_unquote(str); if (!strcmp(str, "inherit")) { set = true; @@ -657,8 +658,10 @@ SPIString::read( gchar const *str ) { } else { set = true; inherit = false; - value = g_strdup(str); + value = g_strdup(str_unquoted); } + + g_free( str_unquoted ); } -- cgit v1.2.3