void XHTMLReader::addTextStyleEntry(const ZLTextStyleEntry &entry) { if (!entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) { myModelReader.addStyleEntry(entry); return; } 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 = myModelReader.putFontEntry(*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(myModelReader.putFontEntry(*it, fontEntry)); } else { realFamilies.push_back(*it); } } myModelReader.addStyleEntry(entry, realFamilies); } }
void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry, const std::vector<std::string> &fontFamilies, unsigned char depth) { // +++ calculating entry size std::size_t len = 4; // entry type + feature mask for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) { if (entry.isFeatureSupported((ZLTextStyleEntry::Feature)i)) { len += 4; // each supported length } } if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE) || entry.isFeatureSupported(ZLTextStyleEntry::NON_LENGTH_VERTICAL_ALIGN)) { len += 2; } if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) { len += 2; } if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) { len += 2; } // --- calculating entry size /* EntryCount += 1; EntryLen += len; std::string debug = "style entry counter: "; ZLStringUtil::appendNumber(debug, EntryCount); debug += "/"; ZLStringUtil::appendNumber(debug, EntryLen); ZLLogger::Instance().println(ZLLogger::DEFAULT_CLASS, debug); */ // +++ writing entry myLastEntryStart = myAllocator->allocate(len); char *address = myLastEntryStart; *address++ = entry.entryKind(); *address++ = depth; address = ZLCachedMemoryAllocator::writeUInt16(address, entry.myFeatureMask); for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) { if (entry.isFeatureSupported((ZLTextStyleEntry::Feature)i)) { const ZLTextStyleEntry::LengthType &len = entry.myLengths[i]; address = ZLCachedMemoryAllocator::writeUInt16(address, len.Size); *address++ = len.Unit; *address++ = 0; } } if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE) || entry.isFeatureSupported(ZLTextStyleEntry::NON_LENGTH_VERTICAL_ALIGN)) { *address++ = entry.myAlignmentType; *address++ = entry.myVerticalAlignCode; } if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) { address = ZLCachedMemoryAllocator::writeUInt16(address, myFontManager.familyListIndex(fontFamilies)); } if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) { *address++ = entry.mySupportedFontModifier; *address++ = entry.myFontModifier; } // --- writing entry myParagraphs.back()->addEntry(myLastEntryStart); ++myParagraphLengths.back(); }
void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry) { // +++ calculating entry size std::size_t len = 4; // entry type + feature mask for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) { if (entry.isFeatureSupported((ZLTextStyleEntry::Feature)i)) { len += 4; // each supported length } } if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE)) { len += 2; } ZLUnicodeUtil::Ucs2String fontFamily; if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) { ZLUnicodeUtil::utf8ToUcs2(fontFamily, entry.fontFamily()); len += 2 + fontFamily.size() * 2; } if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) { len += 2; } // --- calculating entry size /* EntryCount += 1; EntryLen += len; std::string debug = "style entry counter: "; ZLStringUtil::appendNumber(debug, EntryCount); debug += "/"; ZLStringUtil::appendNumber(debug, EntryLen); ZLLogger::Instance().println(ZLLogger::DEFAULT_CLASS, debug); */ // +++ writing entry myLastEntryStart = myAllocator->allocate(len); char *address = myLastEntryStart; *address++ = entry.entryKind(); *address++ = 0; address = ZLCachedMemoryAllocator::writeUInt16(address, entry.myFeatureMask); for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) { if (entry.isFeatureSupported((ZLTextStyleEntry::Feature)i)) { const ZLTextStyleEntry::LengthType &len = entry.myLengths[i]; address = ZLCachedMemoryAllocator::writeUInt16(address, len.Size); *address++ = len.Unit; *address++ = 0; } } if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE)) { *address++ = entry.myAlignmentType; *address++ = 0; } if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) { address = ZLCachedMemoryAllocator::writeString(address, fontFamily); } if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) { *address++ = entry.mySupportedFontModifier; *address++ = entry.myFontModifier; } // --- writing entry myParagraphs.back()->addEntry(myLastEntryStart); ++myParagraphLengths.back(); }