[Libreoffice-commits] libmspub.git: src/lib

Fridrich Å trba fridrich.strba at bluewin.ch
Tue Dec 3 04:53:11 PST 2013


 src/lib/MSPUBCollector.cpp |   86 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 85 insertions(+), 1 deletion(-)

New commits:
commit 3e9dfdccfa58447677d8e6404933229282bd6ae4
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Tue Dec 3 13:52:48 2013 +0100

    Separate tabs, spaces and line-breaks from text
    
    Change-Id: I11a1405914fcc38400c5ce28cb37e4330e72b0aa

diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index b961c6e..fa28b0e 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -39,6 +39,90 @@
 #include "PolygonUtils.h"
 #include "Coordinate.h"
 
+namespace
+{
+
+static void separateTabsAndInsertText(librevenge::RVNGDrawingInterface *iface, const librevenge::RVNGString &text)
+{
+  if (!iface || text.empty())
+    return;
+  librevenge::RVNGString tmpText;
+  librevenge::RVNGString::Iter i(text);
+  for (i.rewind(); i.next();)
+  {
+    if (*(i()) == '\t')
+    {
+      if (!tmpText.empty())
+      {
+        if (iface)
+          iface->insertText(tmpText);
+        tmpText.clear();
+      }
+
+      if (iface)
+        iface->insertTab();
+    }
+    else if (*(i()) == '\n')
+    {
+      if (!tmpText.empty())
+      {
+        if (iface)
+          iface->insertText(tmpText);
+        tmpText.clear();
+      }
+
+      if (iface)
+        iface->insertLineBreak();
+    }
+    else
+    {
+      tmpText.append(i());
+    }
+  }
+  if (iface && !tmpText.empty())
+    iface->insertText(tmpText);
+}
+
+static void separateSpacesAndInsertText(librevenge::RVNGDrawingInterface *iface, const librevenge::RVNGString &text)
+{
+  if (!iface)
+    return;
+  if (text.empty())
+  {
+    iface->insertText(text);
+    return;
+  }
+  librevenge::RVNGString tmpText;
+  int numConsecutiveSpaces = 0;
+  librevenge::RVNGString::Iter i(text);
+  for (i.rewind(); i.next();)
+  {
+    if (*(i()) == ' ')
+      numConsecutiveSpaces++;
+    else
+      numConsecutiveSpaces = 0;
+
+    if (numConsecutiveSpaces > 1)
+    {
+      if (!tmpText.empty())
+      {
+        separateTabsAndInsertText(iface, tmpText);
+        tmpText.clear();
+      }
+
+      if (iface)
+        iface->insertSpace();
+    }
+    else
+    {
+      tmpText.append(i());
+    }
+  }
+  separateTabsAndInsertText(iface, tmpText);
+}
+
+} // anonymous namespace
+
 librevenge::RVNGBinaryData &libmspub::MSPUBCollector::addEOTFont(const librevenge::RVNGString &name)
 {
   m_embeddedFonts.push_back(EmbeddedFontInfo(name));
@@ -843,7 +927,7 @@ boost::function<void(void)> libmspub::MSPUBCollector::paintShape(const ShapeInfo
                          getCalculatedEncoding());
         librevenge::RVNGPropertyList charProps = getCharStyleProps(text[i_lines].spans[i_spans].style, text[i_lines].style.m_defaultCharStyleIndex);
         m_painter->openSpan(charProps);
-        m_painter->insertText(textString);
+        separateSpacesAndInsertText(m_painter, textString);
         m_painter->closeSpan();
       }
       m_painter->closeParagraph();


More information about the Libreoffice-commits mailing list