changeset 23259:abb9d0cfdf2f

fix the anchor position in the info text of the doc browser (bug #50422) * parser.cc (append_line): new function calculating the real length of a line read from an info file taking multi-byte chars into account; (get_next_node): update text length correction in the case of image tags, append method replaced by new function append_line * parser.h: new function append_line
author Torsten <mttl@mailbox.org>
date Fri, 10 Mar 2017 21:47:20 +0100
parents 218a49aea031
children 589e4e4548e1
files libgui/src/qtinfo/parser.cc libgui/src/qtinfo/parser.h
diffstat 2 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/qtinfo/parser.cc	Fri Mar 10 12:16:40 2017 -0800
+++ b/libgui/src/qtinfo/parser.cc	Fri Mar 10 21:47:20 2017 +0100
@@ -198,6 +198,17 @@
   return QString ();
 }
 
+void
+parser::append_line (QString *text, const char *line)
+{
+  QString line_converted = QString::fromLatin1 (line);
+  int len = line_converted.length ();
+  line_converted = QString::fromUtf8 (line);
+  for (int i = len - line_converted.length (); i > 0; i--)
+    line_converted.insert (line_converted.size () - 1, QByteArray (" "));
+  text->append (line_converted);
+}
+
 QString
 parser::get_next_node (QIODevice *io)
 {
@@ -217,20 +228,25 @@
         }
       else
         {
-          // 0 was read -> image -> text length changes
-          line_buffer = io->readLine ();  // image tag that is not needed
-          line = io->readLine ();         // firsts line of text message
-          for (i = 1; i < line_buffer.size ()+6; i++)  // correct the size
-            line.insert (line.size ()-1,QByteArray (" "));  // by adding blanks
+          // 0 was read -> image -> handle text replacement (length changes)
+          line_buffer = io->readLine ();  // start of image tag -> drop it
+          int len = line_buffer.size ();
+          line = io->readLine ();         // get first line of its text
+          line_buffer = line;             // and store it
+          append_line (&text, line);
+          line = io->readLine ();         // get next line of text
+          append_line (&text, line);
+          line = io->readLine ();         // drop last line (unneeded chars)
+          line = line_buffer;             // and take the first instead
+          // now correct the size of the dropped line and 5 additional chars
+          for (i = 1; i < len + 6; i++)
+            line.insert (line.size ()-1,QByteArray (" "));  // adding blanks
         }
 
-      if (line.at (0) == '"' && line.size () == 5)  // end of image construct
-        line = " ";
-
       if (line.at(0) == 31)
         break;
       else
-        text.append (QString::fromUtf8 (line));
+        append_line (&text, line);
     }
   return text;
 }
--- a/libgui/src/qtinfo/parser.h	Fri Mar 10 12:16:40 2017 -0800
+++ b/libgui/src/qtinfo/parser.h	Fri Mar 10 21:47:20 2017 +0100
@@ -98,6 +98,7 @@
   QString get_node_up (const QString& text);
   QString get_node_next (const QString& text);
   QString get_node_prev (const QString& text);
+  void append_line (QString *test, const char *line);
 
   /** Parses info files and gets map of node positions.*/
   void parse_info_map ();