[Libreoffice-commits] libcdr.git: 2 commits - src/lib

Fridrich Å trba fridrich.strba at bluewin.ch
Fri Mar 8 07:30:28 PST 2013


 src/lib/CDRContentCollector.cpp |   51 ++++++++++++++++++-
 src/lib/CDRParser.cpp           |  106 +++++++++++++++++++++++++++++++++-------
 src/lib/CDRTypes.h              |   22 ++++++--
 3 files changed, 153 insertions(+), 26 deletions(-)

New commits:
commit 6abe245c424474853c96ea74b7d8ebe57a35d9f0
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Fri Mar 8 16:29:56 2013 +0100

    Hackery for position of artistic text
    
    Adjust position, since we doubled the width of the
    bounding box, so that text does not wrap

diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp
index ac12601..a2a3808 100644
--- a/src/lib/CDRContentCollector.cpp
+++ b/src/lib/CDRContentCollector.cpp
@@ -408,10 +408,23 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
     }
     else if (m_currentBBox.getWidth() != 0.0 && m_currentBBox.getHeight() != 0.0)
     {
-      x1 = m_currentBBox.getMinX();
       y1 = m_currentBBox.getMinY();
-      x2 = m_currentBBox.getMinX() + m_currentBBox.getWidth();
       y2 = m_currentBBox.getMinY() + m_currentBBox.getHeight();
+      if ((*m_currentText)[0].m_charStyle.m_align == 2) // Center
+      {
+        x1 = m_currentBBox.getMinX() - m_currentBBox.getWidth() / 4.0;
+        x2 = m_currentBBox.getMinX() + (3.0 * m_currentBBox.getWidth() / 4.0);
+      }
+      else if ((*m_currentText)[0].m_charStyle.m_align == 3) // Right
+      {
+        x1 = m_currentBBox.getMinX() - m_currentBBox.getWidth() / 2.0;
+        x2 = m_currentBBox.getMinX() + m_currentBBox.getWidth() / 2.0;
+      }
+      else
+      {
+        x1 = m_currentBBox.getMinX();
+        x2 = m_currentBBox.getMinX() + m_currentBBox.getWidth();
+      }
     }
 
     CDRTransform tmpTrafo(1.0, 0.0, -m_page.offsetX, 0.0, 1.0, -m_page.offsetY);
commit 8be9728c54733bd357cc117a80547f582c827967
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Fri Mar 8 16:17:45 2013 +0100

    Some more text properties

diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp
index bd3beb4..ac12601 100644
--- a/src/lib/CDRContentCollector.cpp
+++ b/src/lib/CDRContentCollector.cpp
@@ -437,7 +437,39 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
     outputElement.addStartTextObject(textFrameProps, WPXPropertyListVector());
     for (unsigned i = 0; i < m_currentText->size(); ++i)
     {
-      outputElement.addStartTextLine(WPXPropertyList());
+      WPXPropertyList paraProps;
+      bool rtl = false;
+      switch ((*m_currentText)[i].m_charStyle.m_align)
+      {
+      case 1:  // Left
+        if (!rtl)
+          paraProps.insert("fo:text-align", "left");
+        else
+          paraProps.insert("fo:text-align", "end");
+        break;
+      case 2:  // Center
+        paraProps.insert("fo:text-align", "center");
+        break;
+      case 3:  // Right
+        if (!rtl)
+          paraProps.insert("fo:text-align", "end");
+        else
+          paraProps.insert("fo:text-align", "left");
+        break;
+      case 4:  // Full justify
+        paraProps.insert("fo:text-align", "justify");
+        break;
+      case 5:  // Force justify
+        paraProps.insert("fo:text-align", "full");
+        break;
+      case 0:  // None
+      default:
+        break;
+      }
+      paraProps.insert("fo:text-indent", (*m_currentText)[i].m_charStyle.m_firstIndent);
+      paraProps.insert("fo:margin-left", (*m_currentText)[i].m_charStyle.m_leftIndent);
+      paraProps.insert("fo:margin-right", (*m_currentText)[i].m_charStyle.m_rightIndent);
+      outputElement.addStartTextLine(paraProps);
       WPXPropertyList spanProps;
       double fontSize = (double)cdr_round(144.0*(*m_currentText)[i].m_charStyle.m_fontSize) / 2.0;
       spanProps.insert("fo:font-size", fontSize, WPX_POINT);
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index 9103507..cf38930 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -68,7 +68,7 @@ struct CDRStltRecord
   CDRStltRecord()
     : parentId(0), fillId(0), outlId(0), fontRecId(0), alignId(0),
       intervalId(0), set5Id(0), set11Id(0), tabId(0),
-      bulletId(0), identId(0), hyphenId(0), dropCapId(0) {}
+      bulletId(0), indentId(0), hyphenId(0), dropCapId(0) {}
   unsigned parentId;
   unsigned fillId;
   unsigned outlId;
@@ -79,7 +79,7 @@ struct CDRStltRecord
   unsigned set11Id;
   unsigned tabId;
   unsigned bulletId;
-  unsigned identId;
+  unsigned indentId;
   unsigned hyphenId;
   unsigned dropCapId;
 };
@@ -2415,8 +2415,7 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
     }
     unsigned numFonts = readU32(input);
     CDR_DEBUG_MSG(("CDRParser::readStlt numFonts 0x%x\n", numFonts));
-    std::map<unsigned,unsigned short> fontIds;
-    std::map<unsigned,unsigned short> fontEncodings;
+    std::map<unsigned,unsigned short> fontIds, fontEncodings;
     std::map<unsigned,double> fontSizes;
     for (i=0; i<numFonts; ++i)
     {
@@ -2435,10 +2434,13 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
         input->seek(20, WPX_SEEK_CUR);
     }
     unsigned numAligns = readU32(input);
+    std::map<unsigned,unsigned> aligns;
     CDR_DEBUG_MSG(("CDRParser::readStlt numAligns 0x%x\n", numAligns));
     for (i=0; i<numAligns; ++i)
     {
-      input->seek(12, WPX_SEEK_CUR);
+      unsigned alignId = readU32(input);
+      input->seek(4, WPX_SEEK_CUR);
+      aligns[alignId] = readU32(input);
     }
     unsigned numIntervals = readU32(input);
     CDR_DEBUG_MSG(("CDRParser::readStlt numIntervals 0x%x\n", numIntervals));
@@ -2483,10 +2485,15 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
       }
     }
     unsigned numIndents = readU32(input);
+    std::map<unsigned, double> rightIndents, firstIndents, leftIndents;
     CDR_DEBUG_MSG(("CDRParser::readStlt numIndents 0x%x\n", numIndents));
     for (i=0; i<numIndents; ++i)
     {
-      input->seek(28, WPX_SEEK_CUR);
+      unsigned indentId = readU32(input);
+      input->seek(12, WPX_SEEK_CUR);
+      rightIndents[indentId] = readCoordinate(input);
+      firstIndents[indentId] = readCoordinate(input);
+      leftIndents[indentId] = readCoordinate(input);
     }
     unsigned numHypens = readU32(input);
     CDR_DEBUG_MSG(("CDRParser::readStlt numHypens 0x%x\n", numHypens));
@@ -2546,7 +2553,7 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
         {
           style.tabId = readU32(input);
           style.bulletId = readU32(input);
-          style.identId = readU32(input);
+          style.indentId = readU32(input);
           style.hyphenId = readU32(input);
           style.dropCapId = readU32(input);
         }
@@ -2578,17 +2585,80 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
               break;
           }
         }
-        if (!fontRecordId)
-          continue;
-        std::map<unsigned, unsigned short>::const_iterator iterFontId = fontIds.find(fontRecordId);
-        if (iterFontId != fontIds.end())
-          tmpCharStyle.m_fontId = iterFontId->second;
-        std::map<unsigned, unsigned short>::const_iterator iterCharSet = fontEncodings.find(fontRecordId);
-        if (iterCharSet != fontEncodings.end())
-          tmpCharStyle.m_charSet = iterCharSet->second;
-        std::map<unsigned, double>::const_iterator iterFontSize = fontSizes.find(fontRecordId);
-        if (iterFontSize != fontSizes.end())
-          tmpCharStyle.m_fontSize = iterFontSize->second;
+        unsigned alignId = 0;
+        if (iter->second.alignId)
+          alignId = iter->second.alignId;
+        else if (iter->second.parentId)
+        {
+          unsigned parentId = iter->second.parentId;
+          while (true)
+          {
+            std::map<unsigned, CDRStltRecord>::const_iterator iter2 = styles.find(parentId);
+            if (iter2 == styles.end())
+              break;
+            if (iter2->second.alignId)
+            {
+              alignId = iter2->second.alignId;
+              break;
+            }
+            if (iter2->second.parentId)
+              parentId = iter2->second.parentId;
+            else
+              break;
+          }
+        }
+        unsigned indentId = 0;
+        if (iter->second.indentId)
+          indentId = iter->second.indentId;
+        else if (iter->second.parentId)
+        {
+          unsigned parentId = iter->second.parentId;
+          while (true)
+          {
+            std::map<unsigned, CDRStltRecord>::const_iterator iter2 = styles.find(parentId);
+            if (iter2 == styles.end())
+              break;
+            if (iter2->second.indentId)
+            {
+              indentId = iter2->second.indentId;
+              break;
+            }
+            if (iter2->second.parentId)
+              parentId = iter2->second.parentId;
+            else
+              break;
+          }
+        }
+        if (fontRecordId)
+        {
+          std::map<unsigned, unsigned short>::const_iterator iterFontId = fontIds.find(fontRecordId);
+          if (iterFontId != fontIds.end())
+            tmpCharStyle.m_fontId = iterFontId->second;
+          std::map<unsigned, unsigned short>::const_iterator iterCharSet = fontEncodings.find(fontRecordId);
+          if (iterCharSet != fontEncodings.end())
+            tmpCharStyle.m_charSet = iterCharSet->second;
+          std::map<unsigned, double>::const_iterator iterFontSize = fontSizes.find(fontRecordId);
+          if (iterFontSize != fontSizes.end())
+            tmpCharStyle.m_fontSize = iterFontSize->second;
+        }
+        if (alignId)
+        {
+          std::map<unsigned, unsigned>::const_iterator iterAlign = aligns.find(alignId);
+          if (iterAlign != aligns.end())
+            tmpCharStyle.m_align = iterAlign->second;
+        }
+        if (indentId)
+        {
+          std::map<unsigned, double>::const_iterator iterRight = rightIndents.find(indentId);
+          if (iterRight != rightIndents.end())
+            tmpCharStyle.m_rightIndent = iterRight->second;
+          std::map<unsigned, double>::const_iterator iterFirst = firstIndents.find(indentId);
+          if (iterFirst != firstIndents.end())
+            tmpCharStyle.m_firstIndent = iterFirst->second;
+          std::map<unsigned, double>::const_iterator iterLeft = leftIndents.find(indentId);
+          if (iterLeft != leftIndents.end())
+            tmpCharStyle.m_leftIndent = iterLeft->second;
+        }
         charStyles[iter->first] = tmpCharStyle;
       }
     }
diff --git a/src/lib/CDRTypes.h b/src/lib/CDRTypes.h
index b6e19c7..c8cb533 100644
--- a/src/lib/CDRTypes.h
+++ b/src/lib/CDRTypes.h
@@ -153,13 +153,17 @@ struct CDRLineStyle
 
 struct CDRCharacterStyle
 {
-  unsigned short m_charSet;
-  unsigned short m_fontId;
+  unsigned short m_charSet, m_fontId;
   double m_fontSize;
+  unsigned m_align;
+  double m_leftIndent, m_firstIndent, m_rightIndent;
   CDRCharacterStyle()
-    : m_charSet(0), m_fontId(0), m_fontSize(0.0) {}
-  CDRCharacterStyle(unsigned short charSet, unsigned short fontId, double fontSize)
-    : m_charSet(charSet), m_fontId(fontId), m_fontSize(fontSize) {}
+    : m_charSet(0), m_fontId(0), m_fontSize(0.0), m_align(0), m_leftIndent(0.0), m_firstIndent(0.0),
+      m_rightIndent(0.0) {}
+  CDRCharacterStyle(unsigned short charSet, unsigned short fontId, double fontSize, unsigned align,
+                    double leftIndent, double firstIndent, double rightIndent)
+    : m_charSet(charSet), m_fontId(fontId), m_fontSize(fontSize), m_align(align),
+      m_leftIndent(leftIndent), m_firstIndent(firstIndent), m_rightIndent(rightIndent) {}
   void overrideCharacterStyle(const CDRCharacterStyle &override)
   {
     if (override.m_charSet)
@@ -168,6 +172,14 @@ struct CDRCharacterStyle
       m_fontId = override.m_fontId;
     if (override.m_fontSize > 0.0)
       m_fontSize = override.m_fontSize;
+    if (override.m_align)
+      m_align = override.m_align;
+    if (override.m_leftIndent != 0.0 && override.m_firstIndent != 0.0 && override.m_rightIndent != 0.0)
+    {
+      m_leftIndent = override.m_leftIndent;
+      m_firstIndent = override.m_firstIndent;
+      m_rightIndent = override.m_rightIndent;
+    }
   }
 };
 


More information about the Libreoffice-commits mailing list