[Libreoffice-commits] libcdr.git: src/lib
Fridrich Å trba
fridrich.strba at bluewin.ch
Wed Feb 27 06:31:36 PST 2013
src/lib/CDRCollector.h | 2 -
src/lib/CDRContentCollector.cpp | 4 +-
src/lib/CDRParser.cpp | 61 ++++++++++++++++++++++++++++++++++++++--
src/lib/CDRStylesCollector.cpp | 10 +++++-
src/lib/CDRTypes.h | 11 +++++++
5 files changed, 81 insertions(+), 7 deletions(-)
New commits:
commit 6522ca9fc4ffa63e6d3020903fd4c3869012fc32
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date: Wed Feb 27 15:31:10 2013 +0100
Extract encoding from font name
diff --git a/src/lib/CDRCollector.h b/src/lib/CDRCollector.h
index 6621730..4ddddb6 100644
--- a/src/lib/CDRCollector.h
+++ b/src/lib/CDRCollector.h
@@ -61,7 +61,7 @@ public:
std::map<unsigned, WPXBinaryData> m_vects;
std::vector<CDRPage> m_pages;
std::map<unsigned, CDRColor> m_documentPalette;
- std::map<unsigned, WPXString> m_fonts;
+ std::map<unsigned, CDRFont> m_fonts;
std::map<unsigned, CDRText> m_texts;
unsigned _getRGBColor(const CDRColor &color);
diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp
index 8dbd4ac..e407fff 100644
--- a/src/lib/CDRContentCollector.cpp
+++ b/src/lib/CDRContentCollector.cpp
@@ -421,9 +421,9 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
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, WPXString>::const_iterator iterFont = m_ps.m_fonts.find(m_currentText.m_charStyle.m_fontId);
+ 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);
+ spanProps.insert("style:font-name", iterFont->second.m_name);
outputElement.addStartTextSpan(spanProps);
outputElement.addInsertText(m_currentText.m_text);
outputElement.addEndTextSpan();
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index 3e9f6c3..ec2045d 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -84,8 +84,65 @@ struct CDRStltRecord
unsigned dropCapId;
};
-static void processNameForEncoding(WPXString & /* name */, unsigned short & /* encoding */)
+static void processNameForEncoding(WPXString &name, unsigned short &encoding)
{
+ std::string fontName(name.cstr());
+ size_t found;
+ if ((found=fontName.rfind(" CE")) != std::string::npos)
+ {
+ encoding = 0xee;
+ fontName.replace(found, 3, "");
+ name = fontName.c_str();
+ }
+ else if ((found=fontName.rfind(" Cyrillic")) != std::string::npos)
+ {
+ encoding = 0xcc;
+ fontName.replace(found, 9, "");
+ name = fontName.c_str();
+ }
+ else if ((found=fontName.rfind(" Cyr")) != std::string::npos)
+ {
+ encoding = 0xcc;
+ fontName.replace(found, 4, "");
+ name = fontName.c_str();
+ }
+ else if ((found=fontName.rfind(" Baltic")) != std::string::npos)
+ {
+ encoding = 0xba;
+ fontName.replace(found, 7, "");
+ name = fontName.c_str();
+ }
+ else if ((found=fontName.rfind(" Greek")) != std::string::npos)
+ {
+ encoding = 0xa1;
+ fontName.replace(found, 6, "");
+ name = fontName.c_str();
+ }
+ else if ((found=fontName.rfind(" Tur")) != std::string::npos)
+ {
+ encoding = 0xa2;
+ fontName.replace(found, 4, "");
+ name = fontName.c_str();
+ }
+ else if ((found=fontName.rfind(" Hebrew")) != std::string::npos)
+ {
+ encoding = 0xb1;
+ fontName.replace(found, 7, "");
+ name = fontName.c_str();
+ }
+ else if ((found=fontName.rfind(" Arabic")) != std::string::npos)
+ {
+ encoding = 0xb2;
+ fontName.replace(found, 7, "");
+ name = fontName.c_str();
+ }
+ else if ((found=fontName.rfind(" Thai")) != std::string::npos)
+ {
+ encoding = 0xde;
+ fontName.replace(found, 5, "");
+ name = fontName.c_str();
+ }
+ return;
}
} // anonymous namespace
@@ -2347,8 +2404,8 @@ void libcdr::CDRParser::readFont(WPXInputStream *input, unsigned length)
else
break;
}
- processNameForEncoding(name, fontEncoding);
}
+ processNameForEncoding(name, fontEncoding);
m_collector->collectFont(fontId, fontEncoding, name);
}
diff --git a/src/lib/CDRStylesCollector.cpp b/src/lib/CDRStylesCollector.cpp
index 16ed133..9c86efb 100644
--- a/src/lib/CDRStylesCollector.cpp
+++ b/src/lib/CDRStylesCollector.cpp
@@ -239,9 +239,9 @@ void libcdr::CDRStylesCollector::collectPaletteEntry(unsigned colorId, unsigned
m_ps.m_documentPalette[colorId] = color;
}
-void libcdr::CDRStylesCollector::collectFont(unsigned fontId, unsigned short, const WPXString &font)
+void libcdr::CDRStylesCollector::collectFont(unsigned fontId, unsigned short encoding, const WPXString &font)
{
- m_ps.m_fonts[fontId] = font;
+ m_ps.m_fonts[fontId] = CDRFont(font, encoding);
}
void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId, const std::vector<unsigned char> &data,
@@ -267,6 +267,12 @@ void libcdr::CDRStylesCollector::collectText(unsigned textId, unsigned styleId,
iter = styleOverrides.find((tmpCharDescription >> 16) & 0xff);
if (iter != styleOverrides.end())
tmpCharStyle.overrideCharacterStyle(iter->second);
+ if (!tmpCharStyle.m_charSet)
+ {
+ std::map<unsigned, CDRFont>::const_iterator iterFont = m_ps.m_fonts.find(tmpCharStyle.m_fontId);
+ if (iterFont != m_ps.m_fonts.end())
+ tmpCharStyle.m_charSet = iterFont->second.m_encoding;
+ }
if ((uint32_t)(charDescriptions[i] & 0xffffff) != tmpCharDescription)
{
if (!tmpTextData.empty())
diff --git a/src/lib/CDRTypes.h b/src/lib/CDRTypes.h
index aeb2e87..ff371ba 100644
--- a/src/lib/CDRTypes.h
+++ b/src/lib/CDRTypes.h
@@ -344,6 +344,17 @@ struct CDRText
CDRCharacterStyle m_charStyle;
};
+struct CDRFont
+{
+ CDRFont() : m_name(), m_encoding(0) {}
+ CDRFont(const WPXString &name, unsigned short encoding)
+ : m_name(name), m_encoding(encoding) {}
+ CDRFont(const CDRFont &font)
+ : m_name(font.m_name), m_encoding(font.m_encoding) {}
+ WPXString m_name;
+ unsigned short m_encoding;
+};
+
} // namespace libcdr
#endif /* __CDRTYPES_H__ */
More information about the Libreoffice-commits
mailing list