From b1d33000fefe867909edf008e4d2bf947ada26a0 Mon Sep 17 00:00:00 2001 From: buliabyak <> Date: Wed, 6 Jan 2010 20:24:25 -0400 Subject: [PATCH] a better truncation detection, suggested by Richard Hughes --- src/libnrtype/Layout-TNG-Compute.cpp | 6 ++- src/libnrtype/Layout-TNG-Input.cpp | 68 ---------------------------- src/libnrtype/Layout-TNG-Output.cpp | 2 + src/libnrtype/Layout-TNG.h | 4 +- 4 files changed, 10 insertions(+), 70 deletions(-) diff --git a/src/libnrtype/Layout-TNG-Compute.cpp b/src/libnrtype/Layout-TNG-Compute.cpp index 7a2924d98..f6b9688bb 100644 --- a/src/libnrtype/Layout-TNG-Compute.cpp +++ b/src/libnrtype/Layout-TNG-Compute.cpp @@ -1467,8 +1467,12 @@ bool Layout::Calculator::calculate() } para.free(); - if (_scanline_maker) + if (_scanline_maker) { delete _scanline_maker; + _flow._input_truncated = false; + } else { + _flow._input_truncated = true; + } return true; } diff --git a/src/libnrtype/Layout-TNG-Input.cpp b/src/libnrtype/Layout-TNG-Input.cpp index 33371ab10..fb2769edc 100644 --- a/src/libnrtype/Layout-TNG-Input.cpp +++ b/src/libnrtype/Layout-TNG-Input.cpp @@ -19,8 +19,6 @@ #include "sp-string.h" #include "FontFactory.h" -#include "text-editing.h" // for inputTruncated() - namespace Inkscape { namespace Text { @@ -324,71 +322,5 @@ Layout::InputStreamTextSource::~InputStreamTextSource() sp_style_unref(style); } -bool -Layout::inputTruncated() const -{ - if (!inputExists()) - return false; - - // Find out the SPObject to which the last visible character corresponds: - Layout::iterator last = end(); - if (last == begin()) { - // FIXME: this returns a wrong "not truncated" when a flowtext is entirely - // truncated, so there are no visible characters. But how can I find out the - // originator SPObject without having anything to do getSourceOfCharacter - // from? - return false; - } - last.prevCharacter(); - void *source; - Glib::ustring::iterator offset; - getSourceOfCharacter(last, &source, &offset); - SPObject *obj = SP_OBJECT(source); - - // if that is SPString, see if it has further characters beyond the last visible - if (obj && SP_IS_STRING(obj)) { - Glib::ustring::iterator offset_next = offset; - offset_next ++; - if (offset_next != SP_STRING(obj)->string.end()) { - // truncated: source SPString has next char - return true; - } - } - - // otherwise, see if the SPObject at end() or any of its text-tree ancestors - // (excluding top-level SPText or SPFlowText) have a text-tree next sibling with - // visible text - if (obj) { - for (SPObject *ascend = obj; - ascend && (is_part_of_text_subtree (ascend) && !is_top_level_text_object(ascend)); - ascend = SP_OBJECT_PARENT(ascend)) { - if (SP_OBJECT_NEXT(ascend)) { - SPObject *next = SP_OBJECT_NEXT(ascend); - if (next && is_part_of_text_subtree(next) && has_visible_text(next)) { - // truncated: source text object has next text sibling - return true; - } - } - } - } - - // the above works for flowed text, but not for text on path. - // so now, we also check if the last of the _characters, if coming from a TEXT_SOURCE, - // has in_glyph different from -1 - unsigned last_char = _characters.size() - 1; - unsigned span_index = _characters[last_char].in_span; - Glib::ustring::const_iterator iter_char = _spans[span_index].input_stream_first_character; - - if (_input_stream[_spans[span_index].in_input_stream_item]->Type() == TEXT_SOURCE) { - if (_characters[last_char].in_glyph == -1) { - //truncated: last char has no glyph - return true; - } - } - - // not truncated - return false; -} - }//namespace Text }//namespace Inkscape diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp index 2b4b80e7c..d6b68ab40 100644 --- a/src/libnrtype/Layout-TNG-Output.cpp +++ b/src/libnrtype/Layout-TNG-Output.cpp @@ -513,8 +513,10 @@ void Layout::fitToPathAlign(SVGLength const &startOffset, Path const &path) _glyphs[glyph_index].y = midpoint[1] - _lines.front().baseline_y + tangent[1] * tangent_shift + tangent[0] * normal_shift; _glyphs[glyph_index].rotation += rotation; } + _input_truncated = false; } else { // outside the bounds of the path: hide the glyphs _characters[char_index].in_glyph = -1; + _input_truncated = true; } g_free(midpoint_otp); diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h index 05b5103fc..0a2463a56 100644 --- a/src/libnrtype/Layout-TNG.h +++ b/src/libnrtype/Layout-TNG.h @@ -212,7 +212,9 @@ public: bool inputExists() const {return !_input_stream.empty();} - bool inputTruncated() const; + bool _input_truncated; + bool inputTruncated() const + {return _input_truncated;} /** adds a new piece of text to the end of the current list of text to be processed. This method can only add text of a consistent style. -- 2.30.2