summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrennan Vincent <brennanv@email.arizona.edu>2012-08-14 19:54:26 -0700
committerBrennan Vincent <brennanv@email.arizona.edu>2012-08-14 19:54:26 -0700
commit9c42ea0a2557f22f930fe994692a2541e7ef7750 (patch)
treefe0feb7a59522aefd272470aa32a7cd77888d391
parent20005e30a693514c8b4d7bb4458756b6f054a228 (diff)
pub2k2+: parse font index in default styles
-rw-r--r--src/lib/MSPUBCollector.cpp20
-rw-r--r--src/lib/MSPUBParser.cpp11
-rw-r--r--src/lib/MSPUBParser.h2
-rw-r--r--src/lib/MSPUBTypes.h8
4 files changed, 28 insertions, 13 deletions
diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index ea0ae33..ab7441b 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -1085,10 +1085,26 @@ WPXPropertyList libmspub::MSPUBCollector::getCharStyleProps(const CharacterStyle
{
ret.insert("fo:color", getColorString(Color(0, 0, 0))); // default color is black
}
- if (style.fontIndex < m_fonts.size())
+ if (style.fontIndex.is_initialized() &&
+ style.fontIndex.get() < m_fonts.size())
{
WPXString str;
- appendCharacters(str, m_fonts[style.fontIndex],
+ appendCharacters(str, m_fonts[style.fontIndex.get()],
+ m_encoding.get_value_or(UTF_16));
+ ret.insert("style:font-name", str);
+ }
+ else if (defaultCharStyle.fontIndex.is_initialized() &&
+ defaultCharStyle.fontIndex.get() < m_fonts.size())
+ {
+ WPXString str;
+ appendCharacters(str, m_fonts[defaultCharStyle.fontIndex.get()],
+ m_encoding.get_value_or(UTF_16));
+ ret.insert("style:font-name", str);
+ }
+ else if (!m_fonts.empty())
+ {
+ WPXString str;
+ appendCharacters(str, m_fonts[0],
m_encoding.get_value_or(UTF_16));
ret.insert("style:font-name", str);
}
diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index dc8598d..7f5953f 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -997,7 +997,7 @@ void libmspub::MSPUBParser::parseDefaultStyle(WPXInputStream *input, const Quill
if (i % 2 == 0)
{
//FIXME: Does STSH2 hold information for associating style indices in FDPP to indices in STSH1 ?
- m_collector->addDefaultCharacterStyle(getCharacterStyle(input, true));
+ m_collector->addDefaultCharacterStyle(getCharacterStyle(input));
}
else
{
@@ -1188,11 +1188,11 @@ libmspub::ParagraphStyle libmspub::MSPUBParser::getParagraphStyle(WPXInputStream
firstLineIndentEmu, leftIndentEmu, rightIndentEmu, listInfo);
}
-libmspub::CharacterStyle libmspub::MSPUBParser::getCharacterStyle(WPXInputStream *input, bool inStsh)
+libmspub::CharacterStyle libmspub::MSPUBParser::getCharacterStyle(WPXInputStream *input)
{
bool seenUnderline = false, seenBold1 = false, seenBold2 = false, seenItalic1 = false, seenItalic2 = false;
int textSize1 = -1, /* textSize2 = -1,*/ colorIndex = -1;
- unsigned fontIndex = 0;
+ boost::optional<unsigned> fontIndex;
SuperSubType sst = NO_SUPER_SUB;
unsigned offset = input->tell();
unsigned len = readU32(input);
@@ -1229,10 +1229,7 @@ libmspub::CharacterStyle libmspub::MSPUBParser::getCharacterStyle(WPXInputStream
colorIndex = getColorIndex(input, info);
break;
case FONT_INDEX_CONTAINER_ID:
- if (! inStsh)
- {
- fontIndex = getFontIndex(input, info);
- }
+ fontIndex = getFontIndex(input, info);
break;
case SUPER_SUB_TYPE_ID:
sst = static_cast<SuperSubType>(info.data);
diff --git a/src/lib/MSPUBParser.h b/src/lib/MSPUBParser.h
index 01968fc..dca2f31 100644
--- a/src/lib/MSPUBParser.h
+++ b/src/lib/MSPUBParser.h
@@ -158,7 +158,7 @@ protected:
unsigned geoWidth, unsigned geoHeight);
int getColorIndex(WPXInputStream *input, const MSPUBBlockInfo &info);
unsigned getFontIndex(WPXInputStream *input, const MSPUBBlockInfo &info);
- CharacterStyle getCharacterStyle(WPXInputStream *input, bool inStsh = false);
+ CharacterStyle getCharacterStyle(WPXInputStream *input);
ParagraphStyle getParagraphStyle(WPXInputStream *input);
boost::shared_ptr<Fill> getNewFill(const std::map<unsigned short, unsigned> &foptValues, bool &skipIfNotBg);
diff --git a/src/lib/MSPUBTypes.h b/src/lib/MSPUBTypes.h
index a542319..4fffd1b 100644
--- a/src/lib/MSPUBTypes.h
+++ b/src/lib/MSPUBTypes.h
@@ -109,19 +109,21 @@ struct CharacterStyle
{
CharacterStyle() :
underline(), italic(), bold(),
- textSizeInPt(), colorIndex(-1), fontIndex(0), superSubType(NO_SUPER_SUB)
+ textSizeInPt(), colorIndex(-1), fontIndex(), superSubType(NO_SUPER_SUB)
{
}
CharacterStyle(bool u, bool i, bool b,
boost::optional<double> tSIP = boost::optional<double>(),
- int cI = -1, unsigned fI = 0, SuperSubType sst = NO_SUPER_SUB) :
+ int cI = -1,
+ boost::optional<unsigned> fI = boost::optional<unsigned>(),
+ SuperSubType sst = NO_SUPER_SUB) :
underline(u), italic(i), bold(b), textSizeInPt(tSIP), colorIndex(cI), fontIndex(fI), superSubType(sst) { }
bool underline;
bool italic;
bool bold;
boost::optional<double> textSizeInPt;
int colorIndex;
- unsigned fontIndex;
+ boost::optional<unsigned> fontIndex;
SuperSubType superSubType;
};