Code

a better truncation detection, suggested by Richard Hughes
authorbuliabyak <>
Thu, 7 Jan 2010 00:24:25 +0000 (20:24 -0400)
committerbuliabyak <>
Thu, 7 Jan 2010 00:24:25 +0000 (20:24 -0400)
src/libnrtype/Layout-TNG-Compute.cpp
src/libnrtype/Layout-TNG-Input.cpp
src/libnrtype/Layout-TNG-Output.cpp
src/libnrtype/Layout-TNG.h

index 7a2924d985d294196e10481e188f1257d7a174f5..f6b9688bb17ca6659b97a54be8239a73b9fe01a1 100644 (file)
@@ -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;
 }
index 33371ab1008928e1ff4751cc7054e2f224995fe8..fb2769edc6f80e32377658529051f030cb8e3892 100644 (file)
@@ -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
index 2b4b80e7c4cfc01f5f30b0d72997c956a7100016..d6b68ab40585b4549affc04766282f1a056a2f83 100644 (file)
@@ -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);
 
index 05b5103fcc1407442063b9e3db7f7eba023c86c5..0a2463a562614aa6d4d83ea2967c4044beff8ade 100644 (file)
@@ -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.