[Libreoffice-commits] libcdr.git: src/lib
Fridrich Å trba
fridrich.strba at bluewin.ch
Wed Apr 10 12:32:38 PDT 2013
src/lib/CDRCollector.h | 4 +-
src/lib/CDRContentCollector.cpp | 37 ++++++++++++----------
src/lib/CDRContentCollector.h | 4 +-
src/lib/CDRParser.cpp | 65 ++++++++++++++--------------------------
src/lib/CDRStylesCollector.cpp | 53 +++++++++++++++++++++++++-------
src/lib/CDRStylesCollector.h | 4 +-
src/lib/CDRTypes.h | 25 ++++++++++-----
7 files changed, 109 insertions(+), 83 deletions(-)
New commits:
commit ce2c827e57851f8f81b349ac6905e0f02775be53
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date: Wed Apr 10 21:32:08 2013 +0200
Refactoring of text-related stuff
diff --git a/src/lib/CDRCollector.h b/src/lib/CDRCollector.h
index c481a53..9f9bb74 100644
--- a/src/lib/CDRCollector.h
+++ b/src/lib/CDRCollector.h
@@ -62,7 +62,7 @@ public:
std::vector<CDRPage> m_pages;
std::map<unsigned, CDRColor> m_documentPalette;
std::map<unsigned, CDRFont> m_fonts;
- std::map<unsigned, std::vector<CDRText> > m_texts;
+ std::map<unsigned, std::vector<CDRTextLine> > m_texts;
unsigned _getRGBColor(const CDRColor &color);
unsigned getBMPColor(const CDRColor &color);
@@ -128,7 +128,7 @@ public:
const std::vector<uint64_t> &charDescriptions, const std::map<unsigned, CDRCharacterStyle> &styleOverrides) = 0;
virtual void collectArtisticText(double x, double y) = 0;
virtual void collectParagraphText(double x, double y, double width, double height) = 0;
- virtual void collectStlt(const std::map<unsigned, CDRCharacterStyle> &charStyles) = 0;
+ virtual void collectStld(unsigned id, const CDRCharacterStyle &charStyle) = 0;
};
} // namespace libcdr
diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp
index fa905d3..769b3f7 100644
--- a/src/lib/CDRContentCollector.cpp
+++ b/src/lib/CDRContentCollector.cpp
@@ -410,12 +410,12 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
{
y1 = m_currentBBox.getMinY();
y2 = m_currentBBox.getMinY() + m_currentBBox.getHeight();
- if ((*m_currentText)[0].m_charStyle.m_align == 2) // Center
+ if ((*m_currentText)[0].m_line[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
+ else if ((*m_currentText)[0].m_line[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;
@@ -452,7 +452,7 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
{
WPXPropertyList paraProps;
bool rtl = false;
- switch ((*m_currentText)[i].m_charStyle.m_align)
+ switch ((*m_currentText)[i].m_line[0].m_charStyle.m_align)
{
case 1: // Left
if (!rtl)
@@ -483,18 +483,21 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
// 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);
- std::map<unsigned, CDRFont>::const_iterator iterFont = m_ps.m_fonts.find((*m_currentText)[i].m_charStyle.m_fontId);
- if (iterFont != m_ps.m_fonts.end())
- spanProps.insert("style:font-name", iterFont->second.m_name);
- std::map<unsigned, CDRFillStyle>::const_iterator iterFill = m_ps.m_fillStyles.find((*m_currentText)[i].m_charStyle.m_fillId);
- if (iterFill != m_ps.m_fillStyles.end())
- spanProps.insert("fo:color", m_ps.getRGBColorString(iterFill->second.color1));
- outputElement.addStartTextSpan(spanProps);
- outputElement.addInsertText((*m_currentText)[i].m_text);
- outputElement.addEndTextSpan();
+ for (unsigned j = 0; j < (*m_currentText)[i].m_line.size(); ++j)
+ {
+ WPXPropertyList spanProps;
+ double fontSize = (double)cdr_round(144.0*(*m_currentText)[i].m_line[j].m_charStyle.m_fontSize) / 2.0;
+ spanProps.insert("fo:font-size", fontSize, WPX_POINT);
+ std::map<unsigned, CDRFont>::const_iterator iterFont = m_ps.m_fonts.find((*m_currentText)[i].m_line[j].m_charStyle.m_fontId);
+ if (iterFont != m_ps.m_fonts.end())
+ spanProps.insert("style:font-name", iterFont->second.m_name);
+ std::map<unsigned, CDRFillStyle>::const_iterator iterFill = m_ps.m_fillStyles.find((*m_currentText)[i].m_line[j].m_charStyle.m_fillId);
+ if (iterFill != m_ps.m_fillStyles.end())
+ spanProps.insert("fo:color", m_ps.getRGBColorString(iterFill->second.color1));
+ outputElement.addStartTextSpan(spanProps);
+ outputElement.addInsertText((*m_currentText)[i].m_line[j].m_text);
+ outputElement.addEndTextSpan();
+ }
outputElement.addEndTextLine();
}
outputElement.addEndTextObject();
@@ -1207,7 +1210,7 @@ void libcdr::CDRContentCollector::collectArtisticText(double x, double y)
{
m_currentTextBox = CDRBox(x, y, x, y);
m_currentBBox.m_w *= 2.0;
- std::map<unsigned, std::vector<CDRText> >::const_iterator iter = m_ps.m_texts.find(m_spnd);
+ std::map<unsigned, std::vector<CDRTextLine> >::const_iterator iter = m_ps.m_texts.find(m_spnd);
if (iter != m_ps.m_texts.end())
m_currentText = &(iter->second);
}
@@ -1218,7 +1221,7 @@ void libcdr::CDRContentCollector::collectParagraphText(double x, double y, doubl
m_currentTextBox.m_y = y;
m_currentTextBox.m_w = width;
m_currentTextBox.m_h = height;
- std::map<unsigned, std::vector<CDRText> >::const_iterator iter = m_ps.m_texts.find(m_spnd);
+ std::map<unsigned, std::vector<CDRTextLine> >::const_iterator iter = m_ps.m_texts.find(m_spnd);
if (iter != m_ps.m_texts.end())
m_currentText = &(iter->second);
}
diff --git a/src/lib/CDRContentCollector.h b/src/lib/CDRContentCollector.h
index 0f8019c..1957a17 100644
--- a/src/lib/CDRContentCollector.h
+++ b/src/lib/CDRContentCollector.h
@@ -91,7 +91,7 @@ public:
const std::vector<uint64_t> &, const std::map<unsigned, CDRCharacterStyle> &) {}
void collectArtisticText(double x, double y);
void collectParagraphText(double x, double y, double width, double height);
- void collectStlt(const std::map<unsigned, CDRCharacterStyle> &) {}
+ void collectStld(unsigned, const CDRCharacterStyle &) {}
private:
CDRContentCollector(const CDRContentCollector &);
@@ -118,7 +118,7 @@ private:
unsigned m_spnd;
unsigned m_currentObjectLevel, m_currentGroupLevel, m_currentVectLevel, m_currentPageLevel;
CDRImage m_currentImage;
- const std::vector<CDRText> *m_currentText;
+ const std::vector<CDRTextLine> *m_currentText;
CDRBox m_currentBBox;
CDRBox m_currentTextBox;
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index 097226a..4f99566 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -47,33 +47,6 @@
#define M_PI 3.14159265358979323846
#endif
-// The local variable name and CDRStltRecord member name have to be identical
-// for this macro to work
-
-#define CDR_EXTRACT(membername) \
- if (iter->second.membername) \
- membername = iter->second.membername; \
- 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.membername) \
- { \
- membername = iter2->second.membername; \
- break; \
- } \
- if (iter2->second.parentId) \
- parentId = iter2->second.parentId; \
- else \
- break; \
- } \
- }
-
-
namespace
{
@@ -2425,6 +2398,7 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
try
{
#endif
+ std::map<unsigned, CDRCharacterStyle> charStyles;
if (m_version < 700)
return;
if (!_redirectX6Chunk(&input, length))
@@ -2551,7 +2525,6 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
{
input->seek(28, WPX_SEEK_CUR);
}
- std::map<unsigned, CDRCharacterStyle> charStyles;
try
{
bool set11Flag(false);
@@ -2601,12 +2574,11 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
}
styles[styleId] = style;
}
- CDRCharacterStyle tmpCharStyle;
for (std::map<unsigned, CDRStltRecord>::const_iterator iter = styles.begin();
iter != styles.end(); ++iter)
{
- unsigned fontRecId = 0;
- CDR_EXTRACT(fontRecId)
+ CDRCharacterStyle tmpCharStyle;
+ unsigned fontRecId = iter->second.fontRecId;
if (fontRecId)
{
std::map<unsigned, unsigned short>::const_iterator iterFontId = fontIds.find(fontRecId);
@@ -2619,16 +2591,14 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
if (iterFontSize != fontSizes.end())
tmpCharStyle.m_fontSize = iterFontSize->second;
}
- unsigned alignId = 0;
- CDR_EXTRACT(alignId);
+ unsigned alignId = iter->second.alignId;
if (alignId)
{
std::map<unsigned, unsigned>::const_iterator iterAlign = aligns.find(alignId);
if (iterAlign != aligns.end())
tmpCharStyle.m_align = iterAlign->second;
}
- unsigned indentId = 0;
- CDR_EXTRACT(indentId);
+ unsigned indentId = iter->second.indentId;
if (indentId)
{
std::map<unsigned, double>::const_iterator iterRight = rightIndents.find(indentId);
@@ -2641,22 +2611,24 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
if (iterLeft != leftIndents.end())
tmpCharStyle.m_leftIndent = iterLeft->second;
}
- unsigned fillId = 0;
- CDR_EXTRACT(fillId);
+ unsigned fillId = iter->second.fillId;
if (fillId)
{
std::map<unsigned, unsigned>::const_iterator iterFill = fillIds.find(fillId);
if (iterFill != fillIds.end())
tmpCharStyle.m_fillId = iterFill->second;
}
- unsigned outlId = 0;
- CDR_EXTRACT(outlId);
+ unsigned outlId = iter->second.outlId;
if (outlId)
{
std::map<unsigned, unsigned>::const_iterator iterOutl = outlIds.find(outlId);
if (iterOutl != outlIds.end())
tmpCharStyle.m_outlId = iterOutl->second;
}
+ unsigned parentId = iter->second.parentId;
+ if (parentId)
+ tmpCharStyle.m_parentId = parentId;
+ m_collector->collectStld(iter->first, tmpCharStyle);
charStyles[iter->first] = tmpCharStyle;
}
}
@@ -2676,7 +2648,6 @@ void libcdr::CDRParser::readStlt(WPXInputStream *input, unsigned length)
throw libcdr::EndOfStreamException();
}
}
- m_collector->collectStlt(charStyles);
#ifndef DEBUG
}
catch (...)
@@ -3005,6 +2976,8 @@ void libcdr::CDRParser::readStyd(WPXInputStream *input)
while (i>0)
argTypes[--i] = readUnsigned(input);
+ unsigned fillId = 0;
+ unsigned outlId = 0;
for (i=0; i < argTypes.size(); i++)
{
input->seek(startPosition+argOffsets[i], WPX_SEEK_SET);
@@ -3014,8 +2987,10 @@ void libcdr::CDRParser::readStyd(WPXInputStream *input)
case STYD_NAME:
break;
case STYD_FILL_ID:
+ fillId = readUnsigned(input);
break;
case STYD_OUTL_ID:
+ outlId = readUnsigned(input);
break;
case STYD_FONTS:
break;
@@ -3039,14 +3014,20 @@ void libcdr::CDRParser::readStyd(WPXInputStream *input)
break;
}
}
+ fillId++;
+ fillId--;
+ outlId++;
+ outlId--;
input->seek(startPosition+chunkLength, WPX_SEEK_SET);
}
-void libcdr::CDRParser::readArtisticText(WPXInputStream *input)
+void libcdr::CDRParser::readArtisticText(WPXInputStream * /*input*/)
{
+#if 0
double x = readCoordinate(input);
double y = readCoordinate(input);
- m_collector->collectArtisticText(x, y);
+#endif
+ m_collector->collectArtisticText(0.0, 0.0);
}
void libcdr::CDRParser::readParagraphText(WPXInputStream *input)
diff --git a/src/lib/CDRStylesCollector.cpp b/src/lib/CDRStylesCollector.cpp
index 8b45750..8c05227 100644
--- a/src/lib/CDRStylesCollector.cpp
+++ b/src/lib/CDRStylesCollector.cpp
@@ -28,6 +28,7 @@
*/
#include <math.h>
+#include <stack>
#include "CDRStylesCollector.h"
#include "CDRInternalStream.h"
#include "libcdr_utils.h"
@@ -40,6 +41,7 @@
#define DUMP_IMAGE 0
#endif
+
libcdr::CDRStylesCollector::CDRStylesCollector(libcdr::CDRParserState &ps) :
m_ps(ps), m_page(8.5, 11.0, -4.25, -5.5), m_charStyles()
{
@@ -255,21 +257,18 @@ void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId,
if (data.empty() || charDescriptions.empty())
return;
- WPXString text;
uint32_t tmpCharDescription = 0;
unsigned i = 0;
unsigned j = 0;
std::vector<unsigned char> tmpTextData;
- CDRCharacterStyle defaultCharStyle;
- CDRCharacterStyle tmpCharStyle;
+ CDRCharacterStyle defaultCharStyle, tmpCharStyle;
+ getRecursedStyle(defaultCharStyle, styleId);
- std::map<unsigned, CDRCharacterStyle>::const_iterator iter = m_charStyles.find(styleId);
- if (iter != m_charStyles.end())
- defaultCharStyle = iter->second;
+ CDRTextLine line;
for (i=0, j=0; i<charDescriptions.size() && j<data.size(); ++i)
{
tmpCharStyle = defaultCharStyle;
- iter = styleOverrides.find((tmpCharDescription >> 16) & 0xff);
+ std::map<unsigned, CDRCharacterStyle>::const_iterator iter = styleOverrides.find((tmpCharDescription >> 16) & 0xff);
if (iter != styleOverrides.end())
tmpCharStyle.overrideCharacterStyle(iter->second);
if (!tmpCharStyle.m_charSet)
@@ -280,6 +279,7 @@ void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId,
}
if ((uint32_t)(charDescriptions[i] & 0xffffff) != tmpCharDescription)
{
+ WPXString text;
if (!tmpTextData.empty())
{
if (tmpCharDescription & 0x01)
@@ -287,8 +287,10 @@ void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId,
else
appendCharacters(text, tmpTextData, tmpCharStyle.m_charSet);
}
+ line.append(CDRText(text, tmpCharStyle));
tmpTextData.clear();
tmpCharDescription = (uint32_t)(charDescriptions[i] & 0xffffff);
+
}
tmpTextData.push_back(data[j++]);
if (tmpCharDescription & 0x01)
@@ -296,20 +298,49 @@ void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId,
}
if (!tmpTextData.empty())
{
+ WPXString text;
if (tmpCharDescription & 0x01)
appendCharacters(text, tmpTextData);
else
appendCharacters(text, tmpTextData, tmpCharStyle.m_charSet);
+ line.append(CDRText(text, tmpCharStyle));
}
CDR_DEBUG_MSG(("CDRStylesCollector::collectText - Text: %s\n", text.cstr()));
- std::vector<CDRText> ¶graphVector = m_ps.m_texts[textId];
- paragraphVector.push_back(CDRText(text, tmpCharStyle));
+ std::vector<CDRTextLine> ¶graphVector = m_ps.m_texts[textId];
+ paragraphVector.push_back(line);
+}
+
+void libcdr::CDRStylesCollector::collectStld(unsigned id, const CDRCharacterStyle &charStyle)
+{
+ m_charStyles[id] = charStyle;
}
-void libcdr::CDRStylesCollector::collectStlt(const std::map<unsigned, CDRCharacterStyle> &charStyles)
+void libcdr::CDRStylesCollector::getRecursedStyle(CDRCharacterStyle &charStyle, unsigned styleId)
{
- m_charStyles = charStyles;
+ std::map<unsigned, CDRCharacterStyle>::const_iterator iter = m_charStyles.find(styleId);
+ if (iter == m_charStyles.end())
+ return;
+
+ std::stack<CDRCharacterStyle> styleStack;
+ styleStack.push(iter->second);
+ if (iter->second.m_parentId)
+ {
+ std::map<unsigned, CDRCharacterStyle>::const_iterator iter2 = m_charStyles.find(iter->second.m_parentId);
+ while (iter2 != m_charStyles.end())
+ {
+ styleStack.push(iter2->second);
+ if (iter2->second.m_parentId)
+ iter2 = m_charStyles.find(iter2->second.m_parentId);
+ else
+ iter2 = m_charStyles.end();
+ }
+ }
+ while (!styleStack.empty())
+ {
+ charStyle.overrideCharacterStyle(styleStack.top());
+ styleStack.pop();
+ }
}
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/CDRStylesCollector.h b/src/lib/CDRStylesCollector.h
index 2f7742a..e3d21d0 100644
--- a/src/lib/CDRStylesCollector.h
+++ b/src/lib/CDRStylesCollector.h
@@ -93,12 +93,14 @@ public:
const std::vector<uint64_t> &charDescriptions, const std::map<unsigned, CDRCharacterStyle> &styleOverrides);
void collectArtisticText(double, double) {}
void collectParagraphText(double, double, double, double) {}
- void collectStlt(const std::map<unsigned, CDRCharacterStyle> &charStyles);
+ void collectStld(unsigned id, const CDRCharacterStyle &charStyle);
private:
CDRStylesCollector(const CDRStylesCollector &);
CDRStylesCollector &operator=(const CDRStylesCollector &);
+ void getRecursedStyle(CDRCharacterStyle &charStyle, unsigned styleId);
+
CDRParserState &m_ps;
CDRPage m_page;
std::map<unsigned, CDRCharacterStyle> m_charStyles;
diff --git a/src/lib/CDRTypes.h b/src/lib/CDRTypes.h
index 4579df7..7d4e710 100644
--- a/src/lib/CDRTypes.h
+++ b/src/lib/CDRTypes.h
@@ -157,16 +157,10 @@ struct CDRCharacterStyle
double m_fontSize;
unsigned m_align;
double m_leftIndent, m_firstIndent, m_rightIndent;
- unsigned m_outlId, m_fillId;
+ unsigned m_outlId, m_fillId, m_parentId;
CDRCharacterStyle()
: 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), m_outlId(0), m_fillId(0) {}
- CDRCharacterStyle(unsigned short charSet, unsigned short fontId, double fontSize, unsigned align,
- double leftIndent, double firstIndent, double rightIndent, unsigned outlId,
- unsigned fillId)
- : m_charSet(charSet), m_fontId(fontId), m_fontSize(fontSize), m_align(align),
- m_leftIndent(leftIndent), m_firstIndent(firstIndent), m_rightIndent(rightIndent),
- m_outlId(outlId), m_fillId(fillId) {}
+ m_rightIndent(0.0), m_outlId(0), m_fillId(0), m_parentId(0) {}
void overrideCharacterStyle(const CDRCharacterStyle &override)
{
if (override.m_charSet || override.m_fontId)
@@ -364,6 +358,21 @@ struct CDRText
CDRCharacterStyle m_charStyle;
};
+struct CDRTextLine
+{
+ CDRTextLine() : m_line() {}
+ CDRTextLine(const CDRTextLine &line) : m_line(line.m_line) {}
+ void append(const CDRText &text)
+ {
+ m_line.push_back(text);
+ }
+ void clear()
+ {
+ m_line.clear();
+ }
+ std::vector<CDRText> m_line;
+};
+
struct CDRFont
{
CDRFont() : m_name(), m_encoding(0) {}
More information about the Libreoffice-commits
mailing list