From 17a09ee693b440bdf2f1a0649de5cceebc2abc51 Mon Sep 17 00:00:00 2001 From: tavmjong-free Date: Wed, 28 Jul 2010 11:12:57 +0200 Subject: [PATCH] Fix rendering of "plain" SVG text. --- src/libnrtype/Layout-TNG-Compute.cpp | 41 ++++++++++++++++++++-------- src/sp-text.cpp | 2 +- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/libnrtype/Layout-TNG-Compute.cpp b/src/libnrtype/Layout-TNG-Compute.cpp index 192596ecf..77e21ef56 100644 --- a/src/libnrtype/Layout-TNG-Compute.cpp +++ b/src/libnrtype/Layout-TNG-Compute.cpp @@ -445,22 +445,32 @@ class Layout::Calculator // we may also have y move orders to deal with here (dx, dy and rotate are done per span) - // Comment added: 1 June 2010: - // The first line in a normal object is placed by the read-in "y" value. The rest are - // determined by Inkscape. This is to allow insertation of new lines in the middle - // of a object. New "y" values are then stored in each that represents - // a new line. The line spacing should depend only on font-size and line-height (and not - // on any y-kerning). Line spacing is already handled by the calling routine. Note that - // this may render improperly any SVG with s created/edited by other programs. + // Comment updated: 23 July 2010: + // We must handle two cases: + // + // 1. Inkscape SVG where the first line is placed by the read-in "y" value and the + // rest are determined by 'font-size' and 'line-height' (and not by any + // y-kerning). s in this case are marked by sodipodi:role="line". This + // allows new lines to be inserted in the middle of a object. On output, + // new "y" values are calculated for each that represents a new line. Line + // spacing is already handled by the calling routine. + // + // 2. Plain SVG where each or is placed by its own "x" and "y" values. + // Note that in this case Inkscape treats each object with any included + // s as a single line of text. This can be confusing in the code below. + if (!it_chunk->broken_spans.empty() // Not empty paragraph && it_chunk->broken_spans.front().start.char_byte == 0 ) { // Beginning of unbroken span - // If empty or new line + // If empty or new line (sodipode:role="line") if( _flow._characters.empty() || _flow._characters.back().chunk(&_flow).in_line != _flow._lines.size() - 1) { + // This is the Inkscape SVG case. + // // If "y" attribute is set, use it (initial "y" attributes in - // other than the first have already been stripped). + // other than the first have already been stripped for + // marked with role="line", see sp-text.cpp: SPText::_buildLayoutInput). if( it_chunk->broken_spans.front().start.iter_span->y._set ) { // Use set "y" attribute @@ -475,9 +485,17 @@ class Layout::Calculator } // Reset relative y_offset ("dy" attribute is relative but should be reset at - // the beginning of each .) + // the beginning of each line since each line will have a new "y" written out.) _y_offset = 0.0; + } else { + + // This is the plain SVG case + // + // "x" and "y" are used to place text, simulating lines as necessary + if( it_chunk->broken_spans.front().start.iter_span->y._set ) { + _y_offset = it_chunk->broken_spans.front().start.iter_span->y.computed - new_line.baseline_y; + } } } _flow._chunks.push_back(new_chunk); @@ -1243,8 +1261,9 @@ bool Layout::Calculator::_findChunksForLine(ParagraphInfo const ¶, UnbrokenSpanPosition span_pos; for( ; ; ) { std::vector scan_runs; - scan_runs = _scanline_maker->makeScanline(*line_height); + scan_runs = _scanline_maker->makeScanline(*line_height); // Only one line with "InfiniteScanlineMaker while (scan_runs.empty()) { + // Only used by ShapeScanlineMaker if (!_goToNextWrapShape()) return false; // no more shapes to wrap in to scan_runs = _scanline_maker->makeScanline(*line_height); } diff --git a/src/sp-text.cpp b/src/sp-text.cpp index bae625f58..36f67aa88 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -528,7 +528,7 @@ unsigned SPText::_buildLayoutInput(SPObject *root, Inkscape::Text::Layout::Optio } else if (SP_IS_TSPAN(root)) { SPTSpan *tspan = SP_TSPAN(root); - // x, y attributes are stripped from some tspans as we do our own line layout + // x, y attributes are stripped from some tspans marked with role="line" as we do our own line layout. // This should be checked carefully, as it can undo line layout in imported SVG files. bool use_xy = !in_textpath && (tspan->role == SP_TSPAN_ROLE_UNSPECIFIED || !tspan->attributes.singleXYCoordinates()); tspan->attributes.mergeInto(&optional_attrs, parent_optional_attrs, parent_attrs_offset, use_xy, true); -- 2.30.2