summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2013-04-11 14:42:45 +0200
committerFridrich Štrba <fridrich.strba@bluewin.ch>2013-04-11 14:42:45 +0200
commit50d1fe49e22f1a04fa3f32e70e5a58fe56dd7e9f (patch)
tree82782cee85ef861256cd4555f7a52583b525c6ff /src/lib
parent188956efa91e06b2196c2444ab4936b39405a33b (diff)
Refactor the character descriptions a bit
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/CDRCollector.h2
-rw-r--r--src/lib/CDRContentCollector.h2
-rw-r--r--src/lib/CDRParser.cpp17
-rw-r--r--src/lib/CDRStylesCollector.cpp10
-rw-r--r--src/lib/CDRStylesCollector.h2
5 files changed, 18 insertions, 15 deletions
diff --git a/src/lib/CDRCollector.h b/src/lib/CDRCollector.h
index 9f9bb74..c17cbb4 100644
--- a/src/lib/CDRCollector.h
+++ b/src/lib/CDRCollector.h
@@ -125,7 +125,7 @@ public:
virtual void collectPaletteEntry(unsigned colorId, unsigned userId, const CDRColor &color) = 0;
virtual void collectFont(unsigned fontId, unsigned short fontEncoding, const WPXString &font) = 0;
virtual void collectText(unsigned textId, unsigned styleId, const std::vector<unsigned char> &data,
- const std::vector<uint64_t> &charDescriptions, const std::map<unsigned, CDRCharacterStyle> &styleOverrides) = 0;
+ const std::vector<unsigned char> &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 collectStld(unsigned id, const CDRCharacterStyle &charStyle) = 0;
diff --git a/src/lib/CDRContentCollector.h b/src/lib/CDRContentCollector.h
index 1957a17..a1e3e33 100644
--- a/src/lib/CDRContentCollector.h
+++ b/src/lib/CDRContentCollector.h
@@ -88,7 +88,7 @@ public:
void collectPaletteEntry(unsigned, unsigned, const CDRColor &) {}
void collectFont(unsigned, unsigned short, const WPXString &) {}
void collectText(unsigned, unsigned, const std::vector<unsigned char> &,
- const std::vector<uint64_t> &, const std::map<unsigned, CDRCharacterStyle> &) {}
+ const std::vector<unsigned char> &, const std::map<unsigned, CDRCharacterStyle> &) {}
void collectArtisticText(double x, double y);
void collectParagraphText(double x, double y, double width, double height);
void collectStld(unsigned, const CDRCharacterStyle &) {}
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index 83fe45b..551eec5 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -2773,13 +2773,15 @@ void libcdr::CDRParser::readTxsm(WPXInputStream *input, unsigned length)
charStyles[2*i] = charStyle;
}
unsigned numChars = readU32(input);
- std::vector<uint64_t> charDescriptions(numChars);
+ std::vector<unsigned char> charDescriptions(numChars);
for (i=0; i<numChars; ++i)
{
+ unsigned tmpCharDescription = 0;
if (m_version >= 1200)
- charDescriptions[i] = readU64(input);
+ tmpCharDescription = readU64(input) & 0xffffffff;
else
- charDescriptions[i] = readU32(input);
+ tmpCharDescription = readU32(input);
+ charDescriptions[i] = (tmpCharDescription >> 16) | (tmpCharDescription & 0x01);
}
unsigned numBytes = numChars;
if (m_version >= 1200)
@@ -2793,7 +2795,8 @@ void libcdr::CDRParser::readTxsm(WPXInputStream *input, unsigned length)
memcpy(&textData[0], buffer, numBytesRead);
input->seek(1, WPX_SEEK_CUR); //skip the 0 ending character
- m_collector->collectText(textId, stlId, textData, charDescriptions, charStyles);
+ if (!textData.empty())
+ m_collector->collectText(textId, stlId, textData, charDescriptions, charStyles);
}
#ifndef DEBUG
}
@@ -2888,7 +2891,7 @@ void libcdr::CDRParser::readTxsm16(WPXInputStream *input)
std::map<unsigned, CDRCharacterStyle> charStyles;
unsigned numChars = readU32(input);
- std::vector<uint64_t> charDescriptions(numChars);
+ std::vector<unsigned char> charDescriptions(numChars);
for (i=0; i<numChars; ++i)
{
charDescriptions[i] = readU64(input);
@@ -2902,7 +2905,8 @@ void libcdr::CDRParser::readTxsm16(WPXInputStream *input)
if (numBytesRead)
memcpy(&textData[0], buffer, numBytesRead);
- m_collector->collectText(textId, stlId, textData, charDescriptions, charStyles);
+ if (!textData.empty())
+ m_collector->collectText(textId, stlId, textData, charDescriptions, charStyles);
#ifndef DEBUG
}
catch (...)
@@ -2913,7 +2917,6 @@ void libcdr::CDRParser::readTxsm16(WPXInputStream *input)
void libcdr::CDRParser::readTxsm6(WPXInputStream *input)
{
-
input->seek(0x28, WPX_SEEK_CUR);
input->seek(48, WPX_SEEK_CUR);
input->seek(4, WPX_SEEK_CUR);
diff --git a/src/lib/CDRStylesCollector.cpp b/src/lib/CDRStylesCollector.cpp
index 8c05227..7365ebb 100644
--- a/src/lib/CDRStylesCollector.cpp
+++ b/src/lib/CDRStylesCollector.cpp
@@ -252,12 +252,12 @@ void libcdr::CDRStylesCollector::collectFont(unsigned fontId, unsigned short enc
}
void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId, const std::vector<unsigned char> &data,
- const std::vector<uint64_t> &charDescriptions, const std::map<unsigned, CDRCharacterStyle> &styleOverrides)
+ const std::vector<unsigned char> &charDescriptions, const std::map<unsigned, CDRCharacterStyle> &styleOverrides)
{
if (data.empty() || charDescriptions.empty())
return;
- uint32_t tmpCharDescription = 0;
+ unsigned char tmpCharDescription = 0;
unsigned i = 0;
unsigned j = 0;
std::vector<unsigned char> tmpTextData;
@@ -268,7 +268,7 @@ void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId,
for (i=0, j=0; i<charDescriptions.size() && j<data.size(); ++i)
{
tmpCharStyle = defaultCharStyle;
- std::map<unsigned, CDRCharacterStyle>::const_iterator iter = styleOverrides.find((tmpCharDescription >> 16) & 0xff);
+ std::map<unsigned, CDRCharacterStyle>::const_iterator iter = styleOverrides.find(tmpCharDescription & 0xfe);
if (iter != styleOverrides.end())
tmpCharStyle.overrideCharacterStyle(iter->second);
if (!tmpCharStyle.m_charSet)
@@ -277,7 +277,7 @@ void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId,
if (iterFont != m_ps.m_fonts.end())
tmpCharStyle.m_charSet = iterFont->second.m_encoding;
}
- if ((uint32_t)(charDescriptions[i] & 0xffffff) != tmpCharDescription)
+ if (charDescriptions[i] != tmpCharDescription)
{
WPXString text;
if (!tmpTextData.empty())
@@ -289,7 +289,7 @@ void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId,
}
line.append(CDRText(text, tmpCharStyle));
tmpTextData.clear();
- tmpCharDescription = (uint32_t)(charDescriptions[i] & 0xffffff);
+ tmpCharDescription = charDescriptions[i];
}
tmpTextData.push_back(data[j++]);
diff --git a/src/lib/CDRStylesCollector.h b/src/lib/CDRStylesCollector.h
index e3d21d0..ecafd63 100644
--- a/src/lib/CDRStylesCollector.h
+++ b/src/lib/CDRStylesCollector.h
@@ -90,7 +90,7 @@ public:
void collectPaletteEntry(unsigned colorId, unsigned userId, const CDRColor &color);
void collectFont(unsigned fontId, unsigned short fontEncoding, const WPXString &font);
void collectText(unsigned textId, unsigned styleId, const std::vector<unsigned char> &data,
- const std::vector<uint64_t> &charDescriptions, const std::map<unsigned, CDRCharacterStyle> &styleOverrides);
+ const std::vector<unsigned char> &charDescriptions, const std::map<unsigned, CDRCharacterStyle> &styleOverrides);
void collectArtisticText(double, double) {}
void collectParagraphText(double, double, double, double) {}
void collectStld(unsigned id, const CDRCharacterStyle &charStyle);