From 98e1dc69d91ecb2deb2ae66980b2398b30f33c7e Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 16 Dec 2014 12:28:09 +0100 Subject: Read 'context-fill' and 'context-stroke' keywords. (bzr r13801) --- src/display/nr-style.cpp | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index 96d16bf06..70382ef50 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -95,22 +95,37 @@ NRStyle::~NRStyle() void NRStyle::set(SPStyle *style) { - if ( style->fill.isPaintserver() ) { + // Handle 'context-fill' and 'context-stroke': Work in progress + SPIPaint &style_fill = style->fill; + if( style_fill.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + // std::cout << "NRStyle::set: fill: context-fill" << std::endl; + // style_fill = context_fill; + } else if ( style_fill.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + //std::cout << "NRStyle::set: fill: context-stroke" << std::endl; + // style_fill = context_stroke; + } + + if ( style_fill.isPaintserver() ) { SPPaintServer* server = style->getFillPaintServer(); if ( server && server->isValid() ) { fill.set(server); - } else if ( style->fill.colorSet ) { - fill.set(style->fill.value.color); + } else if ( style_fill.colorSet ) { + fill.set(style_fill.value.color); } else { fill.clear(); } - } else if ( style->fill.isColor() ) { - fill.set(style->fill.value.color); - } else if ( style->fill.isNone() ) { + } else if ( style_fill.isColor() ) { + fill.set(style_fill.value.color); + } else if ( style_fill.isNone() ) { fill.clear(); + } else if ( style_fill.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + // std::cout << "NRStyle::set: fill: context-fill DOUBLE" << std::endl; + } else if ( style_fill.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + // std::cout << "NRStyle::set: fill: context-stroke DOUBLE" << std::endl; } else { g_assert_not_reached(); } + fill.opacity = SP_SCALE24_TO_FLOAT(style->fill_opacity.value); switch (style->fill_rule.computed) { @@ -137,6 +152,10 @@ void NRStyle::set(SPStyle *style) stroke.set(style->stroke.value.color); } else if ( style->stroke.isNone() ) { stroke.clear(); + } else if ( style->stroke.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + // std::cout << "NRStyle::set: stroke: context-fill" << std::endl; + } else if ( style->stroke.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + // std::cout << "NRStyle::set: stroke: context-stroke" << std::endl; } else { g_assert_not_reached(); } @@ -266,7 +285,7 @@ void NRStyle::set(SPStyle *style) } else if ( style_td->fill.isNone() ) { text_decoration_fill.clear(); } else { - g_assert_not_reached(); + //g_assert_not_reached(); } if ( style_td->stroke.isPaintserver() ) { @@ -276,7 +295,7 @@ void NRStyle::set(SPStyle *style) } else if ( style_td->stroke.isNone() ) { text_decoration_stroke.clear(); } else { - g_assert_not_reached(); + //g_assert_not_reached(); } } -- cgit v1.2.3 From b6d303d11e572d8888d29c44e11d06d256821a03 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 21 Dec 2014 15:29:02 +0100 Subject: Implement rendering for 'context-fill' and 'context-stroke' (text not handled yet). (bzr r13807) --- src/display/nr-style.cpp | 89 +++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 32 deletions(-) (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index 70382ef50..9dadaf3f1 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -93,35 +93,41 @@ NRStyle::~NRStyle() text_decoration_stroke.clear(); } -void NRStyle::set(SPStyle *style) +void NRStyle::set(SPStyle *style, SPStyle *context_style) { // Handle 'context-fill' and 'context-stroke': Work in progress - SPIPaint &style_fill = style->fill; - if( style_fill.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { - // std::cout << "NRStyle::set: fill: context-fill" << std::endl; - // style_fill = context_fill; - } else if ( style_fill.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { - //std::cout << "NRStyle::set: fill: context-stroke" << std::endl; - // style_fill = context_stroke; + const SPIPaint *style_fill = &(style->fill); + if( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + if( context_style != NULL ) { + style_fill = &(context_style->fill); + } else { + std::cerr << "NRStyle::set: 'context-fill': 'context_style' is NULL" << std::endl; + } + } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + if( context_style != NULL ) { + style_fill = &(context_style->stroke); + } else { + std::cerr << "NRStyle::set: 'context-stroke': 'context_style' is NULL" << std::endl; + } } - - if ( style_fill.isPaintserver() ) { + + if ( style_fill->isPaintserver() ) { SPPaintServer* server = style->getFillPaintServer(); if ( server && server->isValid() ) { fill.set(server); - } else if ( style_fill.colorSet ) { - fill.set(style_fill.value.color); + } else if ( style_fill->colorSet ) { + fill.set(style_fill->value.color); } else { fill.clear(); } - } else if ( style_fill.isColor() ) { - fill.set(style_fill.value.color); - } else if ( style_fill.isNone() ) { + } else if ( style_fill->isColor() ) { + fill.set(style_fill->value.color); + } else if ( style_fill->isNone() ) { fill.clear(); - } else if ( style_fill.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { - // std::cout << "NRStyle::set: fill: context-fill DOUBLE" << std::endl; - } else if ( style_fill.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { - // std::cout << "NRStyle::set: fill: context-stroke DOUBLE" << std::endl; + } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + std::cerr << "NRStyle::set: fill: context-fill: Double" << std::endl; + } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + std::cerr << "NRStyle::set: fill: context-stroke: Double" << std::endl; } else { g_assert_not_reached(); } @@ -139,26 +145,42 @@ void NRStyle::set(SPStyle *style) g_assert_not_reached(); } - if ( style->stroke.isPaintserver() ) { + const SPIPaint *style_stroke = &(style->stroke); + if( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + if( context_style != NULL ) { + style_stroke = &(context_style->fill); + } else { + std::cerr << "NRStyle::set: 'context-fill': 'context_style' is NULL" << std::endl; + } + } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + if( context_style != NULL ) { + style_stroke = &(context_style->stroke); + } else { + std::cerr << "NRStyle::set: 'context-stroke': 'context_style' is NULL" << std::endl; + } + } + + if ( style_stroke->isPaintserver() ) { SPPaintServer* server = style->getStrokePaintServer(); if ( server && server->isValid() ) { stroke.set(server); - } else if ( style->stroke.isColor() ) { - stroke.set(style->stroke.colorSet); + } else if ( style_stroke->isColor() ) { + stroke.set(style_stroke->colorSet); } else { stroke.clear(); } - } else if ( style->stroke.isColor() ) { - stroke.set(style->stroke.value.color); - } else if ( style->stroke.isNone() ) { + } else if ( style_stroke->isColor() ) { + stroke.set(style_stroke->value.color); + } else if ( style_stroke->isNone() ) { stroke.clear(); - } else if ( style->stroke.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { - // std::cout << "NRStyle::set: stroke: context-fill" << std::endl; - } else if ( style->stroke.paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { - // std::cout << "NRStyle::set: stroke: context-stroke" << std::endl; + } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { + std::cerr << "NRStyle::set: stroke: context-fill: Double" << std::endl; + } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { + std::cerr << "NRStyle::set: stroke: context-stroke: Double" << std::endl; } else { g_assert_not_reached(); } + stroke.opacity = SP_SCALE24_TO_FLOAT(style->stroke_opacity.value); stroke_width = style->stroke_width.computed; switch (style->stroke_linecap.computed) { @@ -329,13 +351,16 @@ bool NRStyle::prepareFill(Inkscape::DrawingContext &dc, Geom::OptRect const &pai fill_pattern = pattern->renderPattern(fill.opacity); } else { fill_pattern = fill.server->pattern_new(dc.raw(), paintbox, fill.opacity); - } break; + } + break; case PAINT_COLOR: { SPColor const &c = fill.color; fill_pattern = cairo_pattern_create_rgba( c.v.c[0], c.v.c[1], c.v.c[2], fill.opacity); - } break; - default: break; + } + break; + default: + break; } } if (!fill_pattern) return false; -- cgit v1.2.3 From f01a18216e26fd87a53188018e03527c7fdf8a57 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 23 Dec 2014 10:25:08 +0100 Subject: Use gray for 'context-fill' and 'context-stroke' in marker selector. Fix rendering bug when elements with 'context-fill' and 'context-stroke' are inside groups. (bzr r13822) --- src/display/nr-style.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/display/nr-style.cpp') diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index 9dadaf3f1..1740785e2 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -101,13 +101,14 @@ void NRStyle::set(SPStyle *style, SPStyle *context_style) if( context_style != NULL ) { style_fill = &(context_style->fill); } else { - std::cerr << "NRStyle::set: 'context-fill': 'context_style' is NULL" << std::endl; + // A marker in the defs section will result in ending up here. + //std::cerr << "NRStyle::set: 'context-fill': 'context_style' is NULL" << std::endl; } } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { if( context_style != NULL ) { style_fill = &(context_style->stroke); } else { - std::cerr << "NRStyle::set: 'context-stroke': 'context_style' is NULL" << std::endl; + //std::cerr << "NRStyle::set: 'context-stroke': 'context_style' is NULL" << std::endl; } } @@ -125,9 +126,10 @@ void NRStyle::set(SPStyle *style, SPStyle *context_style) } else if ( style_fill->isNone() ) { fill.clear(); } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { - std::cerr << "NRStyle::set: fill: context-fill: Double" << std::endl; + // A marker in the defs section will result in ending up here. + //std::cerr << "NRStyle::set: fill: context-fill: Double" << std::endl; } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { - std::cerr << "NRStyle::set: fill: context-stroke: Double" << std::endl; + //std::cerr << "NRStyle::set: fill: context-stroke: Double" << std::endl; } else { g_assert_not_reached(); } @@ -150,13 +152,13 @@ void NRStyle::set(SPStyle *style, SPStyle *context_style) if( context_style != NULL ) { style_stroke = &(context_style->fill); } else { - std::cerr << "NRStyle::set: 'context-fill': 'context_style' is NULL" << std::endl; + //std::cerr << "NRStyle::set: 'context-fill': 'context_style' is NULL" << std::endl; } } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { if( context_style != NULL ) { style_stroke = &(context_style->stroke); } else { - std::cerr << "NRStyle::set: 'context-stroke': 'context_style' is NULL" << std::endl; + //std::cerr << "NRStyle::set: 'context-stroke': 'context_style' is NULL" << std::endl; } } @@ -174,9 +176,9 @@ void NRStyle::set(SPStyle *style, SPStyle *context_style) } else if ( style_stroke->isNone() ) { stroke.clear(); } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) { - std::cerr << "NRStyle::set: stroke: context-fill: Double" << std::endl; + //std::cerr << "NRStyle::set: stroke: context-fill: Double" << std::endl; } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) { - std::cerr << "NRStyle::set: stroke: context-stroke: Double" << std::endl; + //std::cerr << "NRStyle::set: stroke: context-stroke: Double" << std::endl; } else { g_assert_not_reached(); } -- cgit v1.2.3