From a7d3fb8867dffc0a688b215c2b553b3ba8243065 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 13 May 2012 11:00:40 +0200 Subject: patch by zcgucas for Bug #941597 (Text objects with fill and stroke 'None' are invisible in outline mode) (bzr r11359) --- src/display/drawing-text.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src/display/drawing-text.cpp') diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index 94a9690fb..7f63c555a 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -53,12 +53,11 @@ DrawingGlyphs::setGlyph(font_instance *font, int glyph, Geom::Affine const &tran unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext const &ctx, unsigned /*flags*/, unsigned /*reset*/) { DrawingText *ggroup = dynamic_cast(_parent); - if (!ggroup) throw InvalidItemException(); + if (!ggroup) { + throw InvalidItemException(); + } - if (!_font || !ggroup->_style) return STATE_ALL; - if (ggroup->_nrstyle.fill.type == NRStyle::PAINT_NONE && - ggroup->_nrstyle.stroke.type == NRStyle::PAINT_NONE) - { + if (!_font || !ggroup->_style) { return STATE_ALL; } @@ -66,10 +65,12 @@ unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext _bbox = Geom::IntRect(); Geom::OptRect b = bounds_exact_transformed(*_font->PathVector(_glyph), ctx.ctm); - if (b && ggroup->_nrstyle.stroke.type != NRStyle::PAINT_NONE) { + if (b && (ggroup->_nrstyle.stroke.type != NRStyle::PAINT_NONE)) { float width, scale; scale = ctx.ctm.descrim(); - if (_transform) scale /= _transform->descrim(); // FIXME temporary hack + if (_transform) { + scale /= _transform->descrim(); // FIXME temporary hack + } width = MAX(0.125, ggroup->_nrstyle.stroke_width * scale); if ( fabs(ggroup->_nrstyle.stroke_width * scale) > 0.01 ) { // FIXME: this is always true b->expandBy(0.5 * width); @@ -95,7 +96,15 @@ unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext DrawingItem * DrawingGlyphs::_pickItem(Geom::Point const &p, double delta, unsigned /*flags*/) { - if (!_font || !_bbox) return NULL; + DrawingText *ggroup = dynamic_cast(_parent); + if (!ggroup) { + throw InvalidItemException(); + } + bool invisible = (ggroup->_nrstyle.fill.type == NRStyle::PAINT_NONE) && + (ggroup->_nrstyle.stroke.type == NRStyle::PAINT_NONE); + if (!_font || !_bbox || (!_drawing.outline() && invisible) ) { + return NULL; + } // With text we take a simple approach: pick if the point is in a characher bbox Geom::Rect expanded(_pick_bbox); @@ -123,7 +132,9 @@ DrawingText::clear() void DrawingText::addComponent(font_instance *font, int glyph, Geom::Affine const &trans) { - if (!font || !font->PathVector(glyph)) return; + if (!font || !font->PathVector(glyph)) { + return; + } _markForRendering(); DrawingGlyphs *ng = new DrawingGlyphs(_drawing); @@ -214,7 +225,9 @@ void DrawingText::_clipItem(DrawingContext &ct, Geom::IntRect const &/*area*/) for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { DrawingGlyphs *g = dynamic_cast(&*i); - if (!g) throw InvalidItemException(); + if (!g) { + throw InvalidItemException(); + } Inkscape::DrawingContext::Save save(ct); ct.transform(g->_ctm); @@ -227,7 +240,9 @@ DrawingItem * DrawingText::_pickItem(Geom::Point const &p, double delta, unsigned flags) { DrawingItem *picked = DrawingGroup::_pickItem(p, delta, flags); - if (picked) return this; + if (picked) { + return this; + } return NULL; } -- cgit v1.2.3 From 6ecbc96f5ef1960388e3fa0f42dcceaac1e40d69 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Tue, 6 Nov 2012 19:36:17 +0100 Subject: Change outline mode rendering tolerance from 1.25 to 0.5. Fixes disappearing lines in newer versions of Cairo. (bzr r11862) --- src/display/drawing-text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/display/drawing-text.cpp') diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index 7f63c555a..2a6505c67 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -162,7 +162,7 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are guint32 rgba = _drawing.outlinecolor; Inkscape::DrawingContext::Save save(ct); ct.setSource(rgba); - ct.setTolerance(1.25); // low quality, but good enough for outline mode + ct.setTolerance(0.5); // low quality, but good enough for outline mode for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { DrawingGlyphs *g = dynamic_cast(&*i); -- cgit v1.2.3 From d19db89e2e22d4e09c539bd42823d511aebb669f Mon Sep 17 00:00:00 2001 From: David Mathog <> Date: Wed, 19 Jun 2013 19:20:33 +0200 Subject: changes_2013_05_22a.patch: 1. Resolves issue of bug #988601 message 170 (Support of 'Unset' styles in EMF export). 2. Implements CSS 3 (and CSS 2) text-decoration support. Note that it does not yet provide any method of adding these features - at present it just shows whatever is in the SVG. This new code is also used to display EMF/WMF strike-through and underline text decorations when these files are read in. Those decorations may also be written out to EMF/WMF. Other text decoration features, like overline, or dotted lines, are dropped. For SVG text-decoration -line, -style, -color are all implemented. CSS3 provides two ways to represent the same state, this code uses the compound text-decoration method rather than the 3 fields method. Also it leaves out keywords that are not needed and would break backwards compatibility. For instance: text-decoration: underline solid is valid, but would break CSS2. Solid is the default, so that sort of case is written as: text-decoration: underline If the state is CSS3 specific all of the needed fields are of course include, like text-decoration: underline wavy red 3. It incorporates the fix for bug 1181326 (Text edit mishandles span of just colored spaces) 4. It incorporates further changes to text editing so that style can be changed on spans consisting of only spaces when text decorations are present in the span. 5. It incorporates code to disable text decorations when text so marked is mapped onto a path. 6. Fixed more bugs in Hebrew language support than I can remember. Hebrew language export/import to EMF now works quite well. (See the examples in libTERE v 0.7.) WMF does not support unicode and for all intents and purposes Inkscape has no way to read or write Hebrew to it. Some of more important things that now work that didn't (or didn't always): Hebrew diacritical marks, R/L/center justification, and bidirectional text. The Hebrew fonts "Ezra SIL" and "EZRA SIL SR" should be installed before viewing the libTERE examples, otherwise font substitutions will cause some text shifts. 7. Implemented font failover in Text Reassemble, which makes the process more robust. (Again, see the examples in libTERE. ) (bzr r11668.1.71) --- src/display/drawing-text.cpp | 304 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 287 insertions(+), 17 deletions(-) (limited to 'src/display/drawing-text.cpp') diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index 2a6505c67..234006983 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -18,9 +18,11 @@ #include "helper/geom.h" #include "libnrtype/font-instance.h" #include "style.h" +#include "2geom/pathvector.h" namespace Inkscape { + DrawingGlyphs::DrawingGlyphs(Drawing &drawing) : DrawingItem(drawing) , _font(NULL) @@ -61,12 +63,34 @@ unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext return STATE_ALL; } + _pick_bbox = Geom::IntRect(); _bbox = Geom::IntRect(); - Geom::OptRect b = bounds_exact_transformed(*_font->PathVector(_glyph), ctx.ctm); + Geom::OptRect b; + +/* orignally it did the one line below, + but it did not handle ws characters at all, and it had problems with scaling for overline/underline. + Replaced with the section below, which seems to be much more stable. + + b = bounds_exact_transformed(*_font->PathVector(_glyph), ctx.ctm); +*/ + /* Make a bounding box that is a little taller and lower (currently 10% extra) than the font's drawing box. Extra space is + to hold overline or underline, if present. All characters in a font use the same ascent and descent, + but different widths. This lets leading and trailing spaces have text decorations. If it is not done + the bounding box is limited to the box surrounding the drawn parts of visible glyphs only, and draws outside are ignored. + */ + + float scale = 1.0; + if(_transform){ scale /= _transform->descrim(); } + + Geom::Rect bigbox(Geom::Point(0.0, _asc*scale*1.1),Geom::Point(_width*scale, -_dsc*scale*1.1)); + b = bigbox * ctx.ctm; + if (b && (ggroup->_nrstyle.stroke.type != NRStyle::PAINT_NONE)) { float width, scale; + + // this expands the selection box for cases where the stroke is "thick" scale = ctx.ctm.descrim(); if (_transform) { scale /= _transform->descrim(); // FIXME temporary hack @@ -75,7 +99,8 @@ unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext if ( fabs(ggroup->_nrstyle.stroke_width * scale) > 0.01 ) { // FIXME: this is always true b->expandBy(0.5 * width); } - // save bbox without miters for picking + + // save bbox without miters for picking _pick_bbox = b->roundOutwards(); float miterMax = width * ggroup->_nrstyle.miter_limit; @@ -89,7 +114,12 @@ unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext _bbox = b->roundOutwards(); _pick_bbox = *_bbox; } - +/* +std::cout << "DEBUG _bbox" +<< " { " << _bbox->min()[Geom::X] << " , " << _bbox->min()[Geom::Y] +<< " } , { " << _bbox->max()[Geom::X] << " , " << _bbox->max()[Geom::Y] +<< " }" << std::endl; +*/ return STATE_ALL; } @@ -106,7 +136,7 @@ DrawingGlyphs::_pickItem(Geom::Point const &p, double delta, unsigned /*flags*/) return NULL; } - // With text we take a simple approach: pick if the point is in a characher bbox + // With text we take a simple approach: pick if the point is in a character bbox Geom::Rect expanded(_pick_bbox); expanded.expandBy(delta); if (expanded.contains(p)) return this; @@ -129,17 +159,28 @@ DrawingText::clear() _children.clear_and_dispose(DeleteDisposer()); } -void -DrawingText::addComponent(font_instance *font, int glyph, Geom::Affine const &trans) +bool +DrawingText::addComponent(font_instance *font, int glyph, Geom::Affine const &trans, + float width, float ascent, float descent, float phase_length) { +/* original, did not save a glyph for white space characters, causes problems for text-decoration if (!font || !font->PathVector(glyph)) { - return; + return(false); } +*/ + if (!font)return(false); _markForRendering(); DrawingGlyphs *ng = new DrawingGlyphs(_drawing); ng->setGlyph(font, glyph, trans); + if(font->PathVector(glyph)){ ng->_drawable = true; } + else { ng->_drawable = false; } + ng->_width = width; // only used when _drawable = false + ng->_asc = ascent; // of font, not of this one character + ng->_dsc = descent; // of font, not of this one character + ng->_pl = phase_length; // used for phase of dots, dashes, and wavy appendChild(ng); + return(true); } void @@ -156,9 +197,175 @@ DrawingText::_updateItem(Geom::IntRect const &area, UpdateContext const &ctx, un return DrawingGroup::_updateItem(area, ctx, flags, reset); } +void DrawingText::decorateStyle(DrawingContext &ct, double vextent, double xphase, Geom::Point p1, Geom::Point p2) +{ + double wave[16]={ + 0.000000, 0.382499, 0.706825, 0.923651, 1.000000, 0.923651, 0.706825, 0.382499, + 0.000000, -0.382499, -0.706825, -0.923651, -1.000000, -0.923651, -0.706825, -0.382499, + }; + int dashes[16]={ + 8, 7, 6, 5, + 4, 3, 2, 1, + -8, -7, -6, -5 + -4, -3, -2, -1 + }; + int dots[16]={ + 4, 3, 2, 1, + -4, -3, -2, -1, + 4, 3, 2, 1, + -4, -3, -2, -1 + }; + Geom::Point p3,p4,ps,pf; + double step = vextent/32.0; + unsigned i = 15 & (unsigned) round(xphase/step); // xphase is >= 0.0 + + /* For most spans draw the last little bit right to p2 or even a little beyond. + This allows decoration continuity within the line, and does not step outside the clip box off the end + For the first/last section on the line though, stay well clear of the edge, or when the + text is dragged it may "spray" pixels. + if(_nrstyle.tspan_line_end){ pf = p2 - Geom::Point(2*step, 0.0); } + else { pf = p2; } + if(_nrstyle.tspan_line_start){ ps = p1 + Geom::Point(2*step, 0.0); + i = 15 & (i + 2); + } + else { ps = p1; } + */ + /* snap to nearest step in X */ +ps = Geom::Point(step * round(p1[Geom::X]/step),p1[Geom::Y]); +pf = Geom::Point(step * round(p2[Geom::X]/step),p2[Geom::Y]); + + if(_nrstyle.text_decoration_style & TEXT_DECORATION_STYLE_ISDOUBLE){ + ps -= Geom::Point(0, vextent/12.0); + pf -= Geom::Point(0, vextent/12.0); + ct.moveTo(ps); + ct.lineTo(pf); + ps += Geom::Point(0, vextent/6.0); + pf += Geom::Point(0, vextent/6.0); + ct.moveTo(ps); + ct.lineTo(pf); + } + /* The next three have a problem in that they are phase dependent. The bits of a line are not + necessarily passing through this routine in order, so we have to use the xphase information + to figure where in each of their cycles to start. Only accurate to 1 part in 16. + Huge possitive offset should keep the phase calculation from ever being negative. + */ + else if(_nrstyle.text_decoration_style & TEXT_DECORATION_STYLE_DOTTED){ + while(1){ + if(dots[i]>0){ + if(ps[Geom::X]> pf[Geom::X])break; + ct.moveTo(ps); + ps += Geom::Point(step * (double)dots[i], 0.0); + if(ps[Geom::X]>= pf[Geom::X]){ + ct.lineTo(pf); + break; + } + else { + ct.lineTo(ps); + } + ps += Geom::Point(step * 4.0, 0.0); + } + else { + ps += Geom::Point(step * -(double)dots[i], 0.0); + } + i = 0; // once in phase, it stays in phase + } + } + else if(_nrstyle.text_decoration_style & TEXT_DECORATION_STYLE_DASHED){ + while(1){ + if(dashes[i]>0){ + if(ps[Geom::X]> pf[Geom::X])break; + ct.moveTo(ps); + ps += Geom::Point(step * (double)dashes[i], 0.0); + if(ps[Geom::X]>= pf[Geom::X]){ + ct.lineTo(pf); + break; + } + else { + ct.lineTo(ps); + } + ps += Geom::Point(step * 8.0, 0.0); + } + else { + ps += Geom::Point(step * -(double)dashes[i], 0.0); + } + i = 0; // once in phase, it stays in phase + } + } + else if(_nrstyle.text_decoration_style & TEXT_DECORATION_STYLE_WAVY){ + double amp = vextent/10.0; + double x = ps[Geom::X]; + double y = ps[Geom::Y]; + ct.moveTo(Geom::Point(x, y + amp * wave[i])); + while(1){ + i = ((i + 1) & 15); + x += step; + ct.lineTo(Geom::Point(x, y + amp * wave[i])); + if(x >= pf[Geom::X])break; + } + } + else { // TEXT_DECORATION_STYLE_SOLID, also default in case it was not set for some reason + ct.moveTo(ps); + ct.lineTo(pf); +// ct.revrectangle(Geom::Rect(ps,pf)); + } +} + +/* returns scaled line thickness */ +double DrawingText::decorateItem(DrawingContext &ct, Geom::Affine aff, double phase_length) +{ + double tsp_width_adj, tsp_asc_adj, tsp_size_adj; + double final_underline_thickness, final_line_through_thickness; + double thickness; + + tsp_width_adj = _nrstyle.tspan_width / _nrstyle.font_size; + tsp_asc_adj = _nrstyle.ascender / _nrstyle.font_size; + tsp_size_adj = (_nrstyle.ascender + _nrstyle.descender) / _nrstyle.font_size; +#define VALTRUNC(A,B,C) (A < B ? B : ( A > C ? C : A )) + final_underline_thickness = VALTRUNC(_nrstyle.underline_thickness, tsp_size_adj/30.0, tsp_size_adj/10.0); + final_line_through_thickness = VALTRUNC(_nrstyle.line_through_thickness, tsp_size_adj/30.0, tsp_size_adj/10.0); + Inkscape::DrawingContext::Save save(ct); + + double scale = aff.descrim(); + double xphase = phase_length/ _nrstyle.font_size; // used to figure out phase of patterns + + ct.transform(aff); // must be leftmost affine in span + Geom::Point p1; + Geom::Point p2; + // All lines must be the same thickness, in combinations, line_through trumps underline + thickness = final_underline_thickness; + if(_nrstyle.text_decoration_line & TEXT_DECORATION_LINE_UNDERLINE){ + p1 = Geom::Point(0.0, -_nrstyle.underline_position); + p2 = Geom::Point(tsp_width_adj,-_nrstyle.underline_position); + decorateStyle(ct, tsp_size_adj, xphase, p1, p2); + } + if(_nrstyle.text_decoration_line & TEXT_DECORATION_LINE_OVERLINE){ + p1 = Geom::Point(0.0, tsp_asc_adj -_nrstyle.underline_position + 1 * final_underline_thickness); + p2 = Geom::Point(tsp_width_adj,tsp_asc_adj -_nrstyle.underline_position + 1 * final_underline_thickness); + decorateStyle(ct, tsp_size_adj, xphase, p1, p2); + } + if(_nrstyle.text_decoration_line & TEXT_DECORATION_LINE_LINETHROUGH){ + thickness = final_line_through_thickness; + p1 = Geom::Point(0.0, _nrstyle.line_through_position); + p2 = Geom::Point(tsp_width_adj,_nrstyle.line_through_position); + decorateStyle(ct, tsp_size_adj, xphase, p1, p2); + } + // Obviously this does not blink, but it does indicate which text has been set with that attribute + if(_nrstyle.text_decoration_line & TEXT_DECORATION_LINE_BLINK){ + thickness = final_line_through_thickness; + p1 = Geom::Point(0.0, _nrstyle.line_through_position - 2*final_line_through_thickness); + p2 = Geom::Point(tsp_width_adj,_nrstyle.line_through_position - 2*final_line_through_thickness); + decorateStyle(ct, tsp_size_adj, xphase, p1, p2); + p1 = Geom::Point(0.0, _nrstyle.line_through_position + 2*final_line_through_thickness); + p2 = Geom::Point(tsp_width_adj,_nrstyle.line_through_position + 2*final_line_through_thickness); + decorateStyle(ct, tsp_size_adj, xphase, p1, p2); + } + thickness *= scale; + return(thickness); +} + unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*area*/, unsigned /*flags*/, DrawingItem * /*stop_at*/) { - if (_drawing.outline()) { + if (_drawing.outline()) { guint32 rgba = _drawing.outlinecolor; Inkscape::DrawingContext::Save save(ct); ct.setSource(rgba); @@ -169,34 +376,72 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are if (!g) throw InvalidItemException(); Inkscape::DrawingContext::Save save(ct); - // skip glpyhs with singular transforms + // skip glyphs with singular transforms if (g->_ctm.isSingular()) continue; ct.transform(g->_ctm); - ct.path(*g->_font->PathVector(g->_glyph)); - ct.fill(); + if(g->_drawable){ + ct.path(*g->_font->PathVector(g->_glyph)); + ct.fill(); + } } return RENDER_OK; } // NOTE: this is very similar to drawing-shape.cpp; the only difference is in path feeding - bool has_stroke, has_fill; - - has_fill = _nrstyle.prepareFill(ct, _item_bbox); + double leftmost = DBL_MAX; + double phase_length = 0.0; + bool firsty = true; + bool decorate = true; + double starty = 0.0; + bool has_stroke, has_fill; + Geom::Affine aff; + using Geom::X; + using Geom::Y; + + has_fill = _nrstyle.prepareFill( ct, _item_bbox); has_stroke = _nrstyle.prepareStroke(ct, _item_bbox); if (has_fill || has_stroke) { + Geom::Affine rotinv; + bool invset=false; for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { DrawingGlyphs *g = dynamic_cast(&*i); if (!g) throw InvalidItemException(); + if(!invset){ + rotinv = g->_ctm.withoutTranslation().inverse(); + invset = true; + } Inkscape::DrawingContext::Save save(ct); if (g->_ctm.isSingular()) continue; ct.transform(g->_ctm); - ct.path(*g->_font->PathVector(g->_glyph)); + if(g->_drawable){ + ct.path(*g->_font->PathVector(g->_glyph)); + } + // get the leftmost affine transform (leftmost defined with respect to the x axis of the first transform). + // That way the decoration will work no matter what mix of L->R, R->L text is in the span. + if(_nrstyle.text_decoration_line != TEXT_DECORATION_LINE_CLEAR){ + Geom::Point pt =g->_ctm.translation() * rotinv; + if(pt[X] < leftmost){ + leftmost = pt[X]; + aff = g->_ctm; + phase_length = g->_pl; + } + /* If the text has been mapped onto a path, which causes y to vary, drop the text decorations. + To handle that properly would need a conformal map + */ + if(firsty){ + firsty = false; + starty = pt[Y]; + } + else { + if(fabs(pt[Y] - starty) > 1.0e-6)decorate=false; + } + } } Inkscape::DrawingContext::Save save(ct); - ct.transform(_ctm); +// ct.transform(_ctm); // Seems to work fine without this line, which was in the original. if (has_fill) { _nrstyle.applyFill(ct); ct.fillPreserve(); @@ -206,6 +451,29 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are ct.strokePreserve(); } ct.newPath(); // clear path + if(_nrstyle.text_decoration_line != TEXT_DECORATION_LINE_CLEAR && decorate){ + guint32 ergba; + if(_nrstyle.text_decoration_useColor){ // color different from the glyph + ergba = SP_RGBA32_F_COMPOSE( + _nrstyle.text_decoration_color.color.v.c[0], + _nrstyle.text_decoration_color.color.v.c[1], + _nrstyle.text_decoration_color.color.v.c[2], + 1.0); + } + else { // whatever the current fill color is + ergba = SP_RGBA32_F_COMPOSE( + _nrstyle.fill.color.v.c[0], + _nrstyle.fill.color.v.c[1], + _nrstyle.fill.color.v.c[2], + 1.0); + } + ct.setSource(ergba); + ct.setTolerance(0.5); + double thickness = decorateItem(ct, aff, phase_length); + ct.setLineWidth(thickness); + ct.strokePreserve(); + ct.newPath(); // clear path + } } return RENDER_OK; } @@ -231,7 +499,9 @@ void DrawingText::_clipItem(DrawingContext &ct, Geom::IntRect const &/*area*/) Inkscape::DrawingContext::Save save(ct); ct.transform(g->_ctm); - ct.path(*g->_font->PathVector(g->_glyph)); + if(g->_drawable){ + ct.path(*g->_font->PathVector(g->_glyph)); + } } ct.fill(); } -- cgit v1.2.3 From 54482403aebd77dc3fadcc5cc99740defda51aeb Mon Sep 17 00:00:00 2001 From: Diederik van Lierop <> Date: Sun, 15 Sep 2013 21:27:42 +0200 Subject: Scale rendering of pattern fill of text when chaning zoom level; partial fix for blocker bug #1005892; this reinstates a line that was commented out in rev. 12488 Fixed bugs: - https://launchpad.net/bugs/1005892 (bzr r12523) --- src/display/drawing-text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/display/drawing-text.cpp') diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index 234006983..55d54b770 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -441,7 +441,7 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are } Inkscape::DrawingContext::Save save(ct); -// ct.transform(_ctm); // Seems to work fine without this line, which was in the original. + ct.transform(_ctm); // For one thing, this is needed to scale a fill-pattern when zooming in if (has_fill) { _nrstyle.applyFill(ct); ct.fillPreserve(); -- cgit v1.2.3 From 0f85e2c60c4406eaddc7a96d8ddcc05d36d458f2 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 18 Sep 2013 14:46:36 -0400 Subject: Remove setItemBounds and _item_bbox because aren't sensible, replace with bbox. Fixed bugs: - https://launchpad.net/bugs/243729 (bzr r12528) --- src/display/drawing-text.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/display/drawing-text.cpp') diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index 55d54b770..fa9ce4ff8 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -398,8 +398,8 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are using Geom::X; using Geom::Y; - has_fill = _nrstyle.prepareFill( ct, _item_bbox); - has_stroke = _nrstyle.prepareStroke(ct, _item_bbox); + has_fill = _nrstyle.prepareFill( ct, _bbox); + has_stroke = _nrstyle.prepareStroke(ct, _bbox); if (has_fill || has_stroke) { Geom::Affine rotinv; -- cgit v1.2.3 From 87d93e27330577c2fd632dbaccbd3103884aa590 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Tue, 1 Oct 2013 15:25:44 +0200 Subject: Comprehensive fix for the issues with disappearing filtered objects. Fixes #304407 and possibly a few other bugs. Revert incorrect _item_bbox changes from r12528. Fixed bugs: - https://launchpad.net/bugs/304407 (bzr r12648) --- src/display/drawing-text.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/display/drawing-text.cpp') diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index fa9ce4ff8..55d54b770 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -398,8 +398,8 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are using Geom::X; using Geom::Y; - has_fill = _nrstyle.prepareFill( ct, _bbox); - has_stroke = _nrstyle.prepareStroke(ct, _bbox); + has_fill = _nrstyle.prepareFill( ct, _item_bbox); + has_stroke = _nrstyle.prepareStroke(ct, _item_bbox); if (has_fill || has_stroke) { Geom::Affine rotinv; -- cgit v1.2.3 From 099f8e8a3d2da88cf2e71eb04aa7c7dfd9097f7b Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Fri, 1 Nov 2013 22:12:16 +0100 Subject: Fix blurry pattern fills on text objects (blocker bug #1005892). Fixed bugs: - https://launchpad.net/bugs/1005892 (bzr r12760) --- src/display/drawing-text.cpp | 70 ++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 29 deletions(-) (limited to 'src/display/drawing-text.cpp') diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index 55d54b770..f37f4d3c4 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -197,7 +197,7 @@ DrawingText::_updateItem(Geom::IntRect const &area, UpdateContext const &ctx, un return DrawingGroup::_updateItem(area, ctx, flags, reset); } -void DrawingText::decorateStyle(DrawingContext &ct, double vextent, double xphase, Geom::Point p1, Geom::Point p2) +void DrawingText::decorateStyle(DrawingContext &ct, double vextent, double xphase, Geom::Point const &p1, Geom::Point const &p2) { double wave[16]={ 0.000000, 0.382499, 0.706825, 0.923651, 1.000000, 0.923651, 0.706825, 0.382499, @@ -311,28 +311,25 @@ pf = Geom::Point(step * round(p2[Geom::X]/step),p2[Geom::Y]); } /* returns scaled line thickness */ -double DrawingText::decorateItem(DrawingContext &ct, Geom::Affine aff, double phase_length) +double DrawingText::decorateItem(DrawingContext &ct, Geom::Affine const &aff, double phase_length) { - double tsp_width_adj, tsp_asc_adj, tsp_size_adj; - double final_underline_thickness, final_line_through_thickness; - double thickness; - - tsp_width_adj = _nrstyle.tspan_width / _nrstyle.font_size; - tsp_asc_adj = _nrstyle.ascender / _nrstyle.font_size; - tsp_size_adj = (_nrstyle.ascender + _nrstyle.descender) / _nrstyle.font_size; -#define VALTRUNC(A,B,C) (A < B ? B : ( A > C ? C : A )) - final_underline_thickness = VALTRUNC(_nrstyle.underline_thickness, tsp_size_adj/30.0, tsp_size_adj/10.0); - final_line_through_thickness = VALTRUNC(_nrstyle.line_through_thickness, tsp_size_adj/30.0, tsp_size_adj/10.0); - Inkscape::DrawingContext::Save save(ct); + double tsp_width_adj = _nrstyle.tspan_width / _nrstyle.font_size; + double tsp_asc_adj = _nrstyle.ascender / _nrstyle.font_size; + double tsp_size_adj = (_nrstyle.ascender + _nrstyle.descender) / _nrstyle.font_size; + + double final_underline_thickness = CLAMP(_nrstyle.underline_thickness, tsp_size_adj/30.0, tsp_size_adj/10.0); + double final_line_through_thickness = CLAMP(_nrstyle.line_through_thickness, tsp_size_adj/30.0, tsp_size_adj/10.0); double scale = aff.descrim(); double xphase = phase_length/ _nrstyle.font_size; // used to figure out phase of patterns + Inkscape::DrawingContext::Save save(ct); ct.transform(aff); // must be leftmost affine in span + Geom::Point p1; Geom::Point p2; // All lines must be the same thickness, in combinations, line_through trumps underline - thickness = final_underline_thickness; + double thickness = final_underline_thickness; if(_nrstyle.text_decoration_line & TEXT_DECORATION_LINE_UNDERLINE){ p1 = Geom::Point(0.0, -_nrstyle.underline_position); p2 = Geom::Point(tsp_width_adj,-_nrstyle.underline_position); @@ -393,21 +390,32 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are bool firsty = true; bool decorate = true; double starty = 0.0; - bool has_stroke, has_fill; Geom::Affine aff; using Geom::X; using Geom::Y; - has_fill = _nrstyle.prepareFill( ct, _item_bbox); - has_stroke = _nrstyle.prepareStroke(ct, _item_bbox); + // NOTE: + // prepareFill / prepareStroke need to be called with _ctm in effect. + // However, we might need to apply a different ctm for glyphs. + // Therefore, only apply this ctm temporarily. + bool has_stroke, has_fill; + { + Inkscape::DrawingContext::Save save(ct); + ct.transform(_ctm); + + has_fill = _nrstyle.prepareFill( ct, _item_bbox); + has_stroke = _nrstyle.prepareStroke(ct, _item_bbox); + } if (has_fill || has_stroke) { Geom::Affine rotinv; - bool invset=false; + bool invset = false; + + // accumulate the path that represents the glyphs for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { DrawingGlyphs *g = dynamic_cast(&*i); if (!g) throw InvalidItemException(); - if(!invset){ + if (!invset) { rotinv = g->_ctm.withoutTranslation().inverse(); invset = true; } @@ -415,14 +423,14 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are Inkscape::DrawingContext::Save save(ct); if (g->_ctm.isSingular()) continue; ct.transform(g->_ctm); - if(g->_drawable){ + if (g->_drawable) { ct.path(*g->_font->PathVector(g->_glyph)); } // get the leftmost affine transform (leftmost defined with respect to the x axis of the first transform). // That way the decoration will work no matter what mix of L->R, R->L text is in the span. - if(_nrstyle.text_decoration_line != TEXT_DECORATION_LINE_CLEAR){ - Geom::Point pt =g->_ctm.translation() * rotinv; - if(pt[X] < leftmost){ + if (_nrstyle.text_decoration_line != TEXT_DECORATION_LINE_CLEAR) { + Geom::Point pt = g->_ctm.translation() * rotinv; + if (pt[X] < leftmost) { leftmost = pt[X]; aff = g->_ctm; phase_length = g->_pl; @@ -430,18 +438,20 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are /* If the text has been mapped onto a path, which causes y to vary, drop the text decorations. To handle that properly would need a conformal map */ - if(firsty){ + if (firsty) { firsty = false; starty = pt[Y]; } - else { - if(fabs(pt[Y] - starty) > 1.0e-6)decorate=false; + else if (fabs(pt[Y] - starty) > 1.0e-6) { + decorate = false; } } } + // draw the text itself + // we need to apply this object's ctm again Inkscape::DrawingContext::Save save(ct); - ct.transform(_ctm); // For one thing, this is needed to scale a fill-pattern when zooming in + ct.transform(_ctm); if (has_fill) { _nrstyle.applyFill(ct); ct.fillPreserve(); @@ -451,9 +461,11 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are ct.strokePreserve(); } ct.newPath(); // clear path - if(_nrstyle.text_decoration_line != TEXT_DECORATION_LINE_CLEAR && decorate){ + + // draw text decoration + if (_nrstyle.text_decoration_line != TEXT_DECORATION_LINE_CLEAR && decorate) { guint32 ergba; - if(_nrstyle.text_decoration_useColor){ // color different from the glyph + if (_nrstyle.text_decoration_useColor) { // color different from the glyph ergba = SP_RGBA32_F_COMPOSE( _nrstyle.text_decoration_color.color.v.c[0], _nrstyle.text_decoration_color.color.v.c[1], -- cgit v1.2.3 From ff715dd493c9bef771513c5384809c6ce00d1efe Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Wed, 8 Jan 2014 20:35:36 +0100 Subject: glyph drawing: improve code (bzr r12889) --- src/display/drawing-text.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/display/drawing-text.cpp') diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index f37f4d3c4..f652a2970 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -67,13 +67,11 @@ unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext _pick_bbox = Geom::IntRect(); _bbox = Geom::IntRect(); - Geom::OptRect b; - /* orignally it did the one line below, but it did not handle ws characters at all, and it had problems with scaling for overline/underline. Replaced with the section below, which seems to be much more stable. - b = bounds_exact_transformed(*_font->PathVector(_glyph), ctx.ctm); + Geom::OptRect b = bounds_exact_transformed(*_font->PathVector(_glyph), ctx.ctm); */ /* Make a bounding box that is a little taller and lower (currently 10% extra) than the font's drawing box. Extra space is to hold overline or underline, if present. All characters in a font use the same ascent and descent, @@ -81,37 +79,37 @@ unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext the bounding box is limited to the box surrounding the drawn parts of visible glyphs only, and draws outside are ignored. */ - float scale = 1.0; - if(_transform){ scale /= _transform->descrim(); } - - Geom::Rect bigbox(Geom::Point(0.0, _asc*scale*1.1),Geom::Point(_width*scale, -_dsc*scale*1.1)); - b = bigbox * ctx.ctm; + float scale_bigbox = 1.0; + if (_transform) { + scale_bigbox /= _transform->descrim(); + } - if (b && (ggroup->_nrstyle.stroke.type != NRStyle::PAINT_NONE)) { - float width, scale; + Geom::Rect bigbox(Geom::Point(0.0, _asc*scale_bigbox*1.1),Geom::Point(_width*scale_bigbox, -_dsc*scale_bigbox*1.1)); + Geom::Rect b = bigbox * ctx.ctm; + if (ggroup->_nrstyle.stroke.type != NRStyle::PAINT_NONE) { // this expands the selection box for cases where the stroke is "thick" - scale = ctx.ctm.descrim(); + float scale = ctx.ctm.descrim(); if (_transform) { scale /= _transform->descrim(); // FIXME temporary hack } - width = MAX(0.125, ggroup->_nrstyle.stroke_width * scale); + float width = MAX(0.125, ggroup->_nrstyle.stroke_width * scale); if ( fabs(ggroup->_nrstyle.stroke_width * scale) > 0.01 ) { // FIXME: this is always true - b->expandBy(0.5 * width); + b.expandBy(0.5 * width); } // save bbox without miters for picking - _pick_bbox = b->roundOutwards(); + _pick_bbox = b.roundOutwards(); float miterMax = width * ggroup->_nrstyle.miter_limit; if ( miterMax > 0.01 ) { // grunt mode. we should compute the various miters instead // (one for each point on the curve) - b->expandBy(miterMax); + b.expandBy(miterMax); } - _bbox = b->roundOutwards(); - } else if (b) { - _bbox = b->roundOutwards(); + _bbox = b.roundOutwards(); + } else { + _bbox = b.roundOutwards(); _pick_bbox = *_bbox; } /* -- cgit v1.2.3 From d4ba8eaa4a621ac60d99a4aad7531d080cece2cd Mon Sep 17 00:00:00 2001 From: David Mathog Date: Sat, 8 Feb 2014 09:44:12 +0100 Subject: DrawingContext: change variable names ct to dc (bug #1272073) Fixed bugs: - https://launchpad.net/bugs/1272073 (bzr r13009) --- src/display/drawing-text.cpp | 120 +++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 60 deletions(-) (limited to 'src/display/drawing-text.cpp') diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index f652a2970..f5a0f0af5 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -195,7 +195,7 @@ DrawingText::_updateItem(Geom::IntRect const &area, UpdateContext const &ctx, un return DrawingGroup::_updateItem(area, ctx, flags, reset); } -void DrawingText::decorateStyle(DrawingContext &ct, double vextent, double xphase, Geom::Point const &p1, Geom::Point const &p2) +void DrawingText::decorateStyle(DrawingContext &dc, double vextent, double xphase, Geom::Point const &p1, Geom::Point const &p2) { double wave[16]={ 0.000000, 0.382499, 0.706825, 0.923651, 1.000000, 0.923651, 0.706825, 0.382499, @@ -235,12 +235,12 @@ pf = Geom::Point(step * round(p2[Geom::X]/step),p2[Geom::Y]); if(_nrstyle.text_decoration_style & TEXT_DECORATION_STYLE_ISDOUBLE){ ps -= Geom::Point(0, vextent/12.0); pf -= Geom::Point(0, vextent/12.0); - ct.moveTo(ps); - ct.lineTo(pf); + dc.moveTo(ps); + dc.lineTo(pf); ps += Geom::Point(0, vextent/6.0); pf += Geom::Point(0, vextent/6.0); - ct.moveTo(ps); - ct.lineTo(pf); + dc.moveTo(ps); + dc.lineTo(pf); } /* The next three have a problem in that they are phase dependent. The bits of a line are not necessarily passing through this routine in order, so we have to use the xphase information @@ -251,14 +251,14 @@ pf = Geom::Point(step * round(p2[Geom::X]/step),p2[Geom::Y]); while(1){ if(dots[i]>0){ if(ps[Geom::X]> pf[Geom::X])break; - ct.moveTo(ps); + dc.moveTo(ps); ps += Geom::Point(step * (double)dots[i], 0.0); if(ps[Geom::X]>= pf[Geom::X]){ - ct.lineTo(pf); + dc.lineTo(pf); break; } else { - ct.lineTo(ps); + dc.lineTo(ps); } ps += Geom::Point(step * 4.0, 0.0); } @@ -272,14 +272,14 @@ pf = Geom::Point(step * round(p2[Geom::X]/step),p2[Geom::Y]); while(1){ if(dashes[i]>0){ if(ps[Geom::X]> pf[Geom::X])break; - ct.moveTo(ps); + dc.moveTo(ps); ps += Geom::Point(step * (double)dashes[i], 0.0); if(ps[Geom::X]>= pf[Geom::X]){ - ct.lineTo(pf); + dc.lineTo(pf); break; } else { - ct.lineTo(ps); + dc.lineTo(ps); } ps += Geom::Point(step * 8.0, 0.0); } @@ -293,23 +293,23 @@ pf = Geom::Point(step * round(p2[Geom::X]/step),p2[Geom::Y]); double amp = vextent/10.0; double x = ps[Geom::X]; double y = ps[Geom::Y]; - ct.moveTo(Geom::Point(x, y + amp * wave[i])); + dc.moveTo(Geom::Point(x, y + amp * wave[i])); while(1){ i = ((i + 1) & 15); x += step; - ct.lineTo(Geom::Point(x, y + amp * wave[i])); + dc.lineTo(Geom::Point(x, y + amp * wave[i])); if(x >= pf[Geom::X])break; } } else { // TEXT_DECORATION_STYLE_SOLID, also default in case it was not set for some reason - ct.moveTo(ps); - ct.lineTo(pf); -// ct.revrectangle(Geom::Rect(ps,pf)); + dc.moveTo(ps); + dc.lineTo(pf); +// dc.revrectangle(Geom::Rect(ps,pf)); } } /* returns scaled line thickness */ -double DrawingText::decorateItem(DrawingContext &ct, Geom::Affine const &aff, double phase_length) +double DrawingText::decorateItem(DrawingContext &dc, Geom::Affine const &aff, double phase_length) { double tsp_width_adj = _nrstyle.tspan_width / _nrstyle.font_size; double tsp_asc_adj = _nrstyle.ascender / _nrstyle.font_size; @@ -321,8 +321,8 @@ double DrawingText::decorateItem(DrawingContext &ct, Geom::Affine const &aff, do double scale = aff.descrim(); double xphase = phase_length/ _nrstyle.font_size; // used to figure out phase of patterns - Inkscape::DrawingContext::Save save(ct); - ct.transform(aff); // must be leftmost affine in span + Inkscape::DrawingContext::Save save(dc); + dc.transform(aff); // must be leftmost affine in span Geom::Point p1; Geom::Point p2; @@ -331,52 +331,52 @@ double DrawingText::decorateItem(DrawingContext &ct, Geom::Affine const &aff, do if(_nrstyle.text_decoration_line & TEXT_DECORATION_LINE_UNDERLINE){ p1 = Geom::Point(0.0, -_nrstyle.underline_position); p2 = Geom::Point(tsp_width_adj,-_nrstyle.underline_position); - decorateStyle(ct, tsp_size_adj, xphase, p1, p2); + decorateStyle(dc, tsp_size_adj, xphase, p1, p2); } if(_nrstyle.text_decoration_line & TEXT_DECORATION_LINE_OVERLINE){ p1 = Geom::Point(0.0, tsp_asc_adj -_nrstyle.underline_position + 1 * final_underline_thickness); p2 = Geom::Point(tsp_width_adj,tsp_asc_adj -_nrstyle.underline_position + 1 * final_underline_thickness); - decorateStyle(ct, tsp_size_adj, xphase, p1, p2); + decorateStyle(dc, tsp_size_adj, xphase, p1, p2); } if(_nrstyle.text_decoration_line & TEXT_DECORATION_LINE_LINETHROUGH){ thickness = final_line_through_thickness; p1 = Geom::Point(0.0, _nrstyle.line_through_position); p2 = Geom::Point(tsp_width_adj,_nrstyle.line_through_position); - decorateStyle(ct, tsp_size_adj, xphase, p1, p2); + decorateStyle(dc, tsp_size_adj, xphase, p1, p2); } // Obviously this does not blink, but it does indicate which text has been set with that attribute if(_nrstyle.text_decoration_line & TEXT_DECORATION_LINE_BLINK){ thickness = final_line_through_thickness; p1 = Geom::Point(0.0, _nrstyle.line_through_position - 2*final_line_through_thickness); p2 = Geom::Point(tsp_width_adj,_nrstyle.line_through_position - 2*final_line_through_thickness); - decorateStyle(ct, tsp_size_adj, xphase, p1, p2); + decorateStyle(dc, tsp_size_adj, xphase, p1, p2); p1 = Geom::Point(0.0, _nrstyle.line_through_position + 2*final_line_through_thickness); p2 = Geom::Point(tsp_width_adj,_nrstyle.line_through_position + 2*final_line_through_thickness); - decorateStyle(ct, tsp_size_adj, xphase, p1, p2); + decorateStyle(dc, tsp_size_adj, xphase, p1, p2); } thickness *= scale; return(thickness); } -unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*area*/, unsigned /*flags*/, DrawingItem * /*stop_at*/) +unsigned DrawingText::_renderItem(DrawingContext &dc, Geom::IntRect const &/*area*/, unsigned /*flags*/, DrawingItem * /*stop_at*/) { if (_drawing.outline()) { guint32 rgba = _drawing.outlinecolor; - Inkscape::DrawingContext::Save save(ct); - ct.setSource(rgba); - ct.setTolerance(0.5); // low quality, but good enough for outline mode + Inkscape::DrawingContext::Save save(dc); + dc.setSource(rgba); + dc.setTolerance(0.5); // low quality, but good enough for outline mode for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { DrawingGlyphs *g = dynamic_cast(&*i); if (!g) throw InvalidItemException(); - Inkscape::DrawingContext::Save save(ct); + Inkscape::DrawingContext::Save save(dc); // skip glyphs with singular transforms if (g->_ctm.isSingular()) continue; - ct.transform(g->_ctm); + dc.transform(g->_ctm); if(g->_drawable){ - ct.path(*g->_font->PathVector(g->_glyph)); - ct.fill(); + dc.path(*g->_font->PathVector(g->_glyph)); + dc.fill(); } } return RENDER_OK; @@ -398,11 +398,11 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are // Therefore, only apply this ctm temporarily. bool has_stroke, has_fill; { - Inkscape::DrawingContext::Save save(ct); - ct.transform(_ctm); + Inkscape::DrawingContext::Save save(dc); + dc.transform(_ctm); - has_fill = _nrstyle.prepareFill( ct, _item_bbox); - has_stroke = _nrstyle.prepareStroke(ct, _item_bbox); + has_fill = _nrstyle.prepareFill( dc, _item_bbox); + has_stroke = _nrstyle.prepareStroke(dc, _item_bbox); } if (has_fill || has_stroke) { @@ -418,11 +418,11 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are invset = true; } - Inkscape::DrawingContext::Save save(ct); + Inkscape::DrawingContext::Save save(dc); if (g->_ctm.isSingular()) continue; - ct.transform(g->_ctm); + dc.transform(g->_ctm); if (g->_drawable) { - ct.path(*g->_font->PathVector(g->_glyph)); + dc.path(*g->_font->PathVector(g->_glyph)); } // get the leftmost affine transform (leftmost defined with respect to the x axis of the first transform). // That way the decoration will work no matter what mix of L->R, R->L text is in the span. @@ -448,17 +448,17 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are // draw the text itself // we need to apply this object's ctm again - Inkscape::DrawingContext::Save save(ct); - ct.transform(_ctm); + Inkscape::DrawingContext::Save save(dc); + dc.transform(_ctm); if (has_fill) { - _nrstyle.applyFill(ct); - ct.fillPreserve(); + _nrstyle.applyFill(dc); + dc.fillPreserve(); } if (has_stroke) { - _nrstyle.applyStroke(ct); - ct.strokePreserve(); + _nrstyle.applyStroke(dc); + dc.strokePreserve(); } - ct.newPath(); // clear path + dc.newPath(); // clear path // draw text decoration if (_nrstyle.text_decoration_line != TEXT_DECORATION_LINE_CLEAR && decorate) { @@ -477,27 +477,27 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are _nrstyle.fill.color.v.c[2], 1.0); } - ct.setSource(ergba); - ct.setTolerance(0.5); - double thickness = decorateItem(ct, aff, phase_length); - ct.setLineWidth(thickness); - ct.strokePreserve(); - ct.newPath(); // clear path + dc.setSource(ergba); + dc.setTolerance(0.5); + double thickness = decorateItem(dc, aff, phase_length); + dc.setLineWidth(thickness); + dc.strokePreserve(); + dc.newPath(); // clear path } } return RENDER_OK; } -void DrawingText::_clipItem(DrawingContext &ct, Geom::IntRect const &/*area*/) +void DrawingText::_clipItem(DrawingContext &dc, Geom::IntRect const &/*area*/) { - Inkscape::DrawingContext::Save save(ct); + Inkscape::DrawingContext::Save save(dc); // handle clip-rule if (_style) { if (_style->clip_rule.computed == SP_WIND_RULE_EVENODD) { - ct.setFillRule(CAIRO_FILL_RULE_EVEN_ODD); + dc.setFillRule(CAIRO_FILL_RULE_EVEN_ODD); } else { - ct.setFillRule(CAIRO_FILL_RULE_WINDING); + dc.setFillRule(CAIRO_FILL_RULE_WINDING); } } @@ -507,13 +507,13 @@ void DrawingText::_clipItem(DrawingContext &ct, Geom::IntRect const &/*area*/) throw InvalidItemException(); } - Inkscape::DrawingContext::Save save(ct); - ct.transform(g->_ctm); + Inkscape::DrawingContext::Save save(dc); + dc.transform(g->_ctm); if(g->_drawable){ - ct.path(*g->_font->PathVector(g->_glyph)); + dc.path(*g->_font->PathVector(g->_glyph)); } } - ct.fill(); + dc.fill(); } DrawingItem * -- cgit v1.2.3 From acbf8ef832c0891fde2935911968e52a02516c37 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 18 Feb 2014 22:07:03 +0100 Subject: Implement 'paint-order' for text. (bzr r13039) --- src/display/drawing-text.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/display/drawing-text.cpp') diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index f5a0f0af5..a280e221a 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -450,7 +450,20 @@ unsigned DrawingText::_renderItem(DrawingContext &dc, Geom::IntRect const &/*are // we need to apply this object's ctm again Inkscape::DrawingContext::Save save(dc); dc.transform(_ctm); + +#ifdef WITH_SVG2 + // Text doesn't have markers, we can do paint-order quick and dirty. + bool fill_first = false; + if( _nrstyle.paint_order_layer[0] == NRStyle::PAINT_ORDER_NORMAL || + _nrstyle.paint_order_layer[0] == NRStyle::PAINT_ORDER_FILL || + _nrstyle.paint_order_layer[2] == NRStyle::PAINT_ORDER_STROKE ) { + fill_first = true; + } // Won't get "stroke fill stroke" but that isn't 'valid' + + if (has_fill && fill_first) { +#else if (has_fill) { +#endif _nrstyle.applyFill(dc); dc.fillPreserve(); } @@ -458,6 +471,12 @@ unsigned DrawingText::_renderItem(DrawingContext &dc, Geom::IntRect const &/*are _nrstyle.applyStroke(dc); dc.strokePreserve(); } +#ifdef WITH_SVG2 + if (has_fill && !fill_first) { + _nrstyle.applyFill(dc); + dc.fillPreserve(); + } +#endif dc.newPath(); // clear path // draw text decoration -- cgit v1.2.3