mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
embedded fonts support (in progress)
This commit is contained in:
parent
59639078ea
commit
be841282b4
8 changed files with 63 additions and 25 deletions
|
@ -123,6 +123,13 @@ void BookReader::addControl(FBTextKind kind, bool start) {
|
|||
}
|
||||
}
|
||||
|
||||
void BookReader::addStyleEntry(const ZLTextStyleEntry &entry, const std::vector<std::string> &fontFamilies) {
|
||||
if (paragraphIsOpen()) {
|
||||
flushTextBufferToParagraph();
|
||||
myCurrentTextModel->addStyleEntry(entry, fontFamilies);
|
||||
}
|
||||
}
|
||||
|
||||
void BookReader::addStyleEntry(const ZLTextStyleEntry &entry) {
|
||||
if (paragraphIsOpen()) {
|
||||
flushTextBufferToParagraph();
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
bool paragraphIsOpen() const;
|
||||
void addControl(FBTextKind kind, bool start);
|
||||
void addStyleEntry(const ZLTextStyleEntry &entry);
|
||||
void addStyleEntry(const ZLTextStyleEntry &entry, const std::vector<std::string> &fontFamilies);
|
||||
void addStyleCloseEntry();
|
||||
void addHyperlinkControl(FBTextKind kind, const std::string &label);
|
||||
void addHyperlinkLabel(const std::string &label);
|
||||
|
|
|
@ -194,11 +194,7 @@ shared_ptr<ZLTextStyleEntry> StyleSheetTable::createControl(const AttributeMap &
|
|||
|
||||
const std::string &fontFamily = value(styles, "font-family");
|
||||
if (!fontFamily.empty()) {
|
||||
std::vector<std::string> families = StyleSheetUtil::splitCommaSeparatedList(fontFamily);
|
||||
// TODO: use all families
|
||||
if (!families.empty()) {
|
||||
entry->setFontFamily(families[0]);
|
||||
}
|
||||
entry->setFontFamilies(StyleSheetUtil::splitCommaSeparatedList(fontFamily));
|
||||
}
|
||||
|
||||
const std::string &fontSize = value(styles, "font-size");
|
||||
|
|
|
@ -64,6 +64,9 @@ std::vector<std::string> StyleSheetUtil::splitCommaSeparatedList(const std::stri
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (data.size() > start) {
|
||||
split.push_back(strip(data.substr(start)));
|
||||
}
|
||||
|
||||
return split;
|
||||
}
|
||||
|
|
|
@ -671,19 +671,42 @@ bool XHTMLReader::addTextStyleEntry(const std::string tag, const std::string aCl
|
|||
}
|
||||
|
||||
void XHTMLReader::addTextStyleEntry(const ZLTextStyleEntry &entry) {
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
|
||||
ZLLogger::Instance().println("FONT", "Requested font family: " + entry.fontFamily());
|
||||
shared_ptr<FontEntry> fontEntry = myFontMap->get(entry.fontFamily());
|
||||
if (fontEntry.isNull()) {
|
||||
ZLLogger::Instance().println("FONT", "Font entry not found for " + entry.fontFamily());
|
||||
} else {
|
||||
const std::string realFamily = myFinalFontMap.put(entry.fontFamily(), fontEntry);
|
||||
ZLLogger::Instance().println("FONT", "Entry for " + entry.fontFamily() + " stored as " + realFamily);
|
||||
}
|
||||
}
|
||||
if (!entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
|
||||
myModelReader.addStyleEntry(entry);
|
||||
}
|
||||
|
||||
bool doFixFamiliesList = false;
|
||||
|
||||
const std::vector<std::string> &families = entry.fontFamilies();
|
||||
for (std::vector<std::string>::const_iterator it = families.begin(); it != families.end(); ++it) {
|
||||
ZLLogger::Instance().println("FONT", "Requested font family: " + *it);
|
||||
shared_ptr<FontEntry> fontEntry = myFontMap->get(*it);
|
||||
if (!fontEntry.isNull()) {
|
||||
const std::string realFamily = myFinalFontMap.put(*it, fontEntry);
|
||||
if (realFamily != *it) {
|
||||
ZLLogger::Instance().println("FONT", "Entry for " + *it + " stored as " + realFamily);
|
||||
doFixFamiliesList = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!doFixFamiliesList) {
|
||||
myModelReader.addStyleEntry(entry);
|
||||
} else {
|
||||
std::vector<std::string> realFamilies;
|
||||
for (std::vector<std::string>::const_iterator it = families.begin(); it != families.end(); ++it) {
|
||||
shared_ptr<FontEntry> fontEntry = myFontMap->get(*it);
|
||||
if (!fontEntry.isNull()) {
|
||||
realFamilies.push_back(myFinalFontMap.put(*it, fontEntry));
|
||||
} else {
|
||||
realFamilies.push_back(*it);
|
||||
}
|
||||
}
|
||||
myModelReader.addStyleEntry(entry, realFamilies);
|
||||
}
|
||||
}
|
||||
|
||||
void XHTMLReader::startElementHandler(const char *tag, const char **attributes) {
|
||||
static const std::string HASH = "#";
|
||||
const char *id = attributeValue(attributes, "id");
|
||||
|
|
|
@ -237,6 +237,10 @@ void ZLTextModel::addControl(ZLTextKind textKind, bool isStart) {
|
|||
//static int EntryLen = 0;
|
||||
|
||||
void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry) {
|
||||
addStyleEntry(entry, entry.fontFamilies());
|
||||
}
|
||||
|
||||
void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry, const std::vector<std::string> &fontFamilies) {
|
||||
// +++ calculating entry size
|
||||
std::size_t len = 4; // entry type + feature mask
|
||||
for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) {
|
||||
|
@ -247,10 +251,10 @@ void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry) {
|
|||
if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE)) {
|
||||
len += 2;
|
||||
}
|
||||
ZLUnicodeUtil::Ucs2String fontFamily;
|
||||
ZLUnicodeUtil::Ucs2String fontFamilyUcs2;
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
|
||||
ZLUnicodeUtil::utf8ToUcs2(fontFamily, entry.fontFamily());
|
||||
len += 2 + fontFamily.size() * 2;
|
||||
ZLUnicodeUtil::utf8ToUcs2(fontFamilyUcs2, fontFamilies[0]);
|
||||
len += 2 + fontFamilyUcs2.size() * 2;
|
||||
}
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) {
|
||||
len += 2;
|
||||
|
@ -288,7 +292,7 @@ void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry) {
|
|||
*address++ = 0;
|
||||
}
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
|
||||
address = ZLCachedMemoryAllocator::writeString(address, fontFamily);
|
||||
address = ZLCachedMemoryAllocator::writeString(address, fontFamilyUcs2);
|
||||
}
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) {
|
||||
*address++ = entry.mySupportedFontModifier;
|
||||
|
|
|
@ -67,6 +67,7 @@ public:
|
|||
*/
|
||||
void addControl(ZLTextKind textKind, bool isStart);
|
||||
void addStyleEntry(const ZLTextStyleEntry &entry);
|
||||
void addStyleEntry(const ZLTextStyleEntry &entry, const std::vector<std::string> &fontFamilies);
|
||||
void addStyleCloseEntry();
|
||||
void addHyperlinkControl(ZLTextKind textKind, ZLHyperlinkType hyperlinkType, const std::string &label);
|
||||
void addText(const std::string &text);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define __ZLTEXTSTYLEENTRY_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <ZLTextParagraph.h>
|
||||
#include <ZLTextAlignmentType.h>
|
||||
|
@ -95,8 +96,8 @@ public:
|
|||
ZLBoolean3 fontModifier(FontModifier modifier) const;
|
||||
void setFontModifier(FontModifier modifier, bool on);
|
||||
|
||||
const std::string &fontFamily() const;
|
||||
void setFontFamily(const std::string &fontFamily);
|
||||
const std::vector<std::string> &fontFamilies() const;
|
||||
void setFontFamilies(const std::vector<std::string> &fontFamilies);
|
||||
|
||||
private:
|
||||
const unsigned char myEntryKind;
|
||||
|
@ -106,7 +107,7 @@ private:
|
|||
ZLTextAlignmentType myAlignmentType;
|
||||
unsigned char mySupportedFontModifier;
|
||||
unsigned char myFontModifier;
|
||||
std::string myFontFamily;
|
||||
std::vector<std::string> myFontFamilies;
|
||||
|
||||
friend class ZLTextModel;
|
||||
};
|
||||
|
@ -151,10 +152,12 @@ inline void ZLTextStyleEntry::setFontModifier(FontModifier modifier, bool on) {
|
|||
}
|
||||
}
|
||||
|
||||
inline const std::string &ZLTextStyleEntry::fontFamily() const { return myFontFamily; }
|
||||
inline void ZLTextStyleEntry::setFontFamily(const std::string &fontFamily) {
|
||||
inline const std::vector<std::string> &ZLTextStyleEntry::fontFamilies() const { return myFontFamilies; }
|
||||
inline void ZLTextStyleEntry::setFontFamilies(const std::vector<std::string> &fontFamilies) {
|
||||
if (!fontFamilies.empty()) {
|
||||
myFeatureMask |= 1 << FONT_FAMILY;
|
||||
myFontFamily = fontFamily;
|
||||
myFontFamilies = fontFamilies;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __ZLTEXTSTYLEENTRY_H__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue