[Libreoffice-commits] libcdr.git: src/lib
Fridrich Å trba
fridrich.strba at bluewin.ch
Thu Feb 28 06:15:14 PST 2013
src/lib/CDRCollector.h | 2
src/lib/CDRContentCollector.cpp | 39 +++++-----
src/lib/CDRContentCollector.h | 2
src/lib/CDRParser.cpp | 153 ++++++++++++++++++++--------------------
src/lib/CDRStylesCollector.cpp | 3
5 files changed, 104 insertions(+), 95 deletions(-)
New commits:
commit dd762061856bf745891a9952bd06106ec22d2b67
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date: Thu Feb 28 15:14:40 2013 +0100
Handle multiple paragraphs of text
diff --git a/src/lib/CDRCollector.h b/src/lib/CDRCollector.h
index 4ddddb6..e2cac1f 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, CDRText> m_texts;
+ std::map<unsigned, std::vector<CDRText> > m_texts;
unsigned _getRGBColor(const CDRColor &color);
unsigned getBMPColor(const CDRColor &color);
diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp
index e407fff..3e9669f 100644
--- a/src/lib/CDRContentCollector.cpp
+++ b/src/lib/CDRContentCollector.cpp
@@ -52,7 +52,7 @@ libcdr::CDRContentCollector::CDRContentCollector(libcdr::CDRParserState &ps, lib
m_isPageProperties(false), m_isPageStarted(false), m_ignorePage(false),
m_page(ps.m_pages[0]), m_pageIndex(0), m_currentFildId(0), m_currentOutlId(0), m_spnd(0),
m_currentObjectLevel(0), m_currentGroupLevel(0), m_currentVectLevel(0), m_currentPageLevel(0),
- m_currentImage(), m_currentText(), m_currentTextOffsetX(0.0), m_currentTextOffsetY(0.0),
+ m_currentImage(), m_currentText(0), m_currentTextOffsetX(0.0), m_currentTextOffsetY(0.0),
m_currentBBox(), m_currentPath(), m_currentTransforms(), m_fillTransforms(),
m_polygon(0), m_isInPolygon(false), m_isInSpline(false), m_outputElements(0),
m_contentOutputElements(), m_fillOutputElements(),
@@ -391,7 +391,7 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
outputElement.addGraphicObject(propList, m_currentImage.getImage());
}
- if (m_currentText.m_text.len())
+ if (m_currentText && !m_currentText->empty())
{
double currentTextOffsetX = 0.0;
double currentTextOffsetY = 0.0;
@@ -417,17 +417,20 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
textFrameProps.insert("fo:padding-left", 0.0);
textFrameProps.insert("fo:padding-right", 0.0);
outputElement.addStartTextObject(textFrameProps, WPXPropertyListVector());
- outputElement.addStartTextLine(WPXPropertyList());
- WPXPropertyList spanProps;
- double fontSize = (double)cdr_round(144.0*m_currentText.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.m_charStyle.m_fontId);
- if (iterFont != m_ps.m_fonts.end())
- spanProps.insert("style:font-name", iterFont->second.m_name);
- outputElement.addStartTextSpan(spanProps);
- outputElement.addInsertText(m_currentText.m_text);
- outputElement.addEndTextSpan();
- outputElement.addEndTextLine();
+ for (unsigned i = 0; i < m_currentText->size(); ++i)
+ {
+ outputElement.addStartTextLine(WPXPropertyList());
+ 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);
+ outputElement.addStartTextSpan(spanProps);
+ outputElement.addInsertText((*m_currentText)[i].m_text);
+ outputElement.addEndTextSpan();
+ outputElement.addEndTextLine();
+ }
outputElement.addEndTextObject();
}
m_currentImage = libcdr::CDRImage();
@@ -436,7 +439,7 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
m_currentTransforms.clear();
m_fillTransforms = libcdr::CDRTransforms();
m_fillOpacity = 1.0;
- m_currentText = CDRText();
+ m_currentText = 0;
}
void libcdr::CDRContentCollector::collectTransform(const CDRTransforms &transforms, bool considerGroupTransform)
@@ -1136,16 +1139,16 @@ void libcdr::CDRContentCollector::collectVectorPattern(unsigned id, const WPXBin
void libcdr::CDRContentCollector::collectArtisticText()
{
- std::map<unsigned, CDRText>::const_iterator iter = m_ps.m_texts.find(m_spnd);
+ std::map<unsigned, std::vector<CDRText> >::const_iterator iter = m_ps.m_texts.find(m_spnd);
if (iter != m_ps.m_texts.end())
- m_currentText = iter->second;
+ m_currentText = &(iter->second);
}
void libcdr::CDRContentCollector::collectParagraphText()
{
- std::map<unsigned, CDRText>::const_iterator iter = m_ps.m_texts.find(m_spnd);
+ std::map<unsigned, std::vector<CDRText> >::const_iterator iter = m_ps.m_texts.find(m_spnd);
if (iter != m_ps.m_texts.end())
- m_currentText = iter->second;
+ m_currentText = &(iter->second);
}
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/CDRContentCollector.h b/src/lib/CDRContentCollector.h
index 5523db3..56fc5ce 100644
--- a/src/lib/CDRContentCollector.h
+++ b/src/lib/CDRContentCollector.h
@@ -118,7 +118,7 @@ private:
unsigned m_spnd;
unsigned m_currentObjectLevel, m_currentGroupLevel, m_currentVectLevel, m_currentPageLevel;
CDRImage m_currentImage;
- CDRText m_currentText;
+ const std::vector<CDRText> *m_currentText;
double m_currentTextOffsetX;
double m_currentTextOffsetY;
CDRBBox m_currentBBox;
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index cfb035e..1ce77ae 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -2648,6 +2648,7 @@ void libcdr::CDRParser::readTxsm(WPXInputStream *input, unsigned length)
if (m_version >= 1500)
input->seek(12, WPX_SEEK_CUR);
unsigned num = readU32(input);
+ unsigned num4 = 1;
if (!num)
{
if (m_version >= 800)
@@ -2659,92 +2660,96 @@ void libcdr::CDRParser::readTxsm(WPXInputStream *input, unsigned length)
input->seek(24, WPX_SEEK_CUR);
if (m_version < 800)
input->seek(8, WPX_SEEK_CUR);
- input->seek(4, WPX_SEEK_CUR);
+ num4 = readU32(input);
}
- unsigned stlId = readU32(input);
- if (m_version >= 1300 && num)
- input->seek(1, WPX_SEEK_CUR);
- input->seek(1, WPX_SEEK_CUR);
- unsigned numRecords = readU32(input);
- std::map<unsigned, CDRCharacterStyle> charStyles;
- unsigned i = 0;
- for (i=0; i<numRecords; ++i)
+ for (unsigned j = 0; j < num4; ++j)
{
- readU8(input);
- readU8(input);
- unsigned char fl2 = readU8(input);
- unsigned char fl3 = 0;
- if (m_version >= 800)
- fl3 = readU8(input);
-
- CDRCharacterStyle charStyle;
- // Read more information depending on the flags
- if (fl2&1) // Font
- {
- unsigned flag = readU32(input);
- charStyle.m_charSet = (flag >> 16);
- charStyle.m_fontId = flag & 0xff;
- }
- if (fl2&2) // Bold/Italic, etc.
- input->seek(4, WPX_SEEK_CUR);
- if (fl2&4) // Font Size
- charStyle.m_fontSize = readCoordinate(input);
- if (fl2&8) // assumption
- input->seek(4, WPX_SEEK_CUR);
- if (fl2&0x10) // Offset X
- input->seek(4, WPX_SEEK_CUR);
- if (fl2&0x20) // Offset Y
- input->seek(4, WPX_SEEK_CUR);
- if (fl2&0x40) // Font Colour
- {
- input->seek(4, WPX_SEEK_CUR);
- if (m_version >= 1500)
- input->seek(48, WPX_SEEK_CUR);
- }
- if (fl2&0x80) // Font Outl Colour
- input->seek(4, WPX_SEEK_CUR);
-
- if (fl3&8) // Encoding
+ unsigned stlId = readU32(input);
+ if (m_version >= 1300 && num)
+ input->seek(1, WPX_SEEK_CUR);
+ input->seek(1, WPX_SEEK_CUR);
+ unsigned numRecords = readU32(input);
+ std::map<unsigned, CDRCharacterStyle> charStyles;
+ unsigned i = 0;
+ for (i=0; i<numRecords; ++i)
{
- if (m_version >= 1300)
+ readU8(input);
+ readU8(input);
+ unsigned char fl2 = readU8(input);
+ unsigned char fl3 = 0;
+ if (m_version >= 800)
+ fl3 = readU8(input);
+
+ CDRCharacterStyle charStyle;
+ // Read more information depending on the flags
+ if (fl2&1) // Font
{
- unsigned tlen = readU32(input);
- input->seek(tlen*2, WPX_SEEK_CUR);
+ unsigned flag = readU32(input);
+ charStyle.m_charSet = (flag >> 16);
+ charStyle.m_fontId = flag & 0xff;
}
- else
+ if (fl2&2) // Bold/Italic, etc.
+ input->seek(4, WPX_SEEK_CUR);
+ if (fl2&4) // Font Size
+ charStyle.m_fontSize = readCoordinate(input);
+ if (fl2&8) // assumption
+ input->seek(4, WPX_SEEK_CUR);
+ if (fl2&0x10) // Offset X
+ input->seek(4, WPX_SEEK_CUR);
+ if (fl2&0x20) // Offset Y
+ input->seek(4, WPX_SEEK_CUR);
+ if (fl2&0x40) // Font Colour
+ {
input->seek(4, WPX_SEEK_CUR);
+ if (m_version >= 1500)
+ input->seek(48, WPX_SEEK_CUR);
+ }
+ if (fl2&0x80) // Font Outl Colour
+ input->seek(4, WPX_SEEK_CUR);
+
+ if (fl3&8) // Encoding
+ {
+ if (m_version >= 1300)
+ {
+ unsigned tlen = readU32(input);
+ input->seek(tlen*2, WPX_SEEK_CUR);
+ }
+ else
+ input->seek(4, WPX_SEEK_CUR);
+ }
+ if (fl3&0x20) // Something
+ {
+ unsigned flag = readU8(input);
+ if (flag)
+ input->seek(52, WPX_SEEK_CUR);
+ }
+
+ charStyles[2*i] = charStyle;
}
- if (fl3&0x20) // Something
+ unsigned numChars = readU32(input);
+ std::vector<uint64_t> charDescriptions(numChars);
+ for (i=0; i<numChars; ++i)
{
- unsigned flag = readU8(input);
- if (flag)
- input->seek(52, WPX_SEEK_CUR);
+ if (m_version >= 1200)
+ charDescriptions[i] = readU64(input);
+ else
+ charDescriptions[i] = readU32(input);
}
-
- charStyles[2*i] = charStyle;
- }
- unsigned numChars = readU32(input);
- std::vector<uint64_t> charDescriptions(numChars);
- for (i=0; i<numChars; ++i)
- {
+ unsigned numBytes = numChars;
if (m_version >= 1200)
- charDescriptions[i] = readU64(input);
- else
- charDescriptions[i] = readU32(input);
- }
- unsigned numBytes = numChars;
- if (m_version >= 1200)
- numBytes = readU32(input);
- unsigned long numBytesRead = 0;
- const unsigned char *buffer = input->read(numBytes, numBytesRead);
- if (numBytesRead != numBytes)
- throw GenericException();
- std::vector<unsigned char> textData(numBytesRead);
- if (numBytesRead)
- memcpy(&textData[0], buffer, numBytesRead);
+ numBytes = readU32(input);
+ unsigned long numBytesRead = 0;
+ const unsigned char *buffer = input->read(numBytes, numBytesRead);
+ if (numBytesRead != numBytes)
+ throw GenericException();
+ std::vector<unsigned char> textData(numBytesRead);
+ if (numBytesRead)
+ memcpy(&textData[0], buffer, numBytesRead);
+ input->seek(1, WPX_SEEK_CUR); //skip the 0 ending character
- m_collector->collectText(textId, stlId, textData, charDescriptions, charStyles);
+ m_collector->collectText(textId, stlId, textData, charDescriptions, charStyles);
+ }
#ifndef DEBUG
}
catch (...)
diff --git a/src/lib/CDRStylesCollector.cpp b/src/lib/CDRStylesCollector.cpp
index 9c86efb..1bbb1ea 100644
--- a/src/lib/CDRStylesCollector.cpp
+++ b/src/lib/CDRStylesCollector.cpp
@@ -298,7 +298,8 @@ void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId,
}
CDR_DEBUG_MSG(("CDRStylesCollector::collectText - Text: %s\n", text.cstr()));
- m_ps.m_texts[textId] = CDRText(text, tmpCharStyle);
+ std::vector<CDRText> ¶graphVector = m_ps.m_texts[textId];
+ paragraphVector.push_back(CDRText(text, tmpCharStyle));
}
void libcdr::CDRStylesCollector::collectStlt(const std::map<unsigned, CDRCharacterStyle> &charStyles)
More information about the Libreoffice-commits
mailing list