static bool trySetLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Feature featureId, const std::string &value) { short size; ZLTextStyleEntry::SizeUnit unit; if (::parseLength(value, size, unit)) { entry.setLength(featureId, size, unit); return true; } return false; }
void XHTMLReader::beginParagraph() { myCurrentParagraphIsEmpty = true; myModelReader.beginParagraph(); bool doBlockSpaceBefore = false; for (std::vector<shared_ptr<ZLTextStyleEntry> >::const_iterator it = myStyleEntryStack.begin(); it != myStyleEntryStack.end(); ++it) { myModelReader.addStyleEntry(**it); doBlockSpaceBefore = doBlockSpaceBefore || (*it)->isFeatureSupported(ZLTextStyleEntry::LENGTH_SPACE_BEFORE); } if (doBlockSpaceBefore) { ZLTextStyleEntry blockingEntry; blockingEntry.setLength( ZLTextStyleEntry::LENGTH_SPACE_BEFORE, 0, ZLTextStyleEntry::SIZE_UNIT_PIXEL ); myModelReader.addStyleEntry(blockingEntry); } }
void ZLTextModel::addControl(const ZLTextStyleEntry &entry) { int len = sizeof(int) + 5 + ZLTextStyleEntry::NUMBER_OF_LENGTHS * (sizeof(short) + 1); if (entry.fontFamilySupported()) { len += entry.fontFamily().length() + 1; } myLastEntryStart = myAllocator.allocate(len); char *address = myLastEntryStart; *address++ = ZLTextParagraphEntry::STYLE_ENTRY; memcpy(address, &entry.myMask, sizeof(int)); address += sizeof(int); for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) { *address++ = entry.myLengths[i].Unit; memcpy(address, &entry.myLengths[i].Size, sizeof(short)); address += sizeof(short); } *address++ = entry.mySupportedFontModifier; *address++ = entry.myFontModifier; *address++ = entry.myAlignmentType; *address++ = entry.myFontSizeMag; if (entry.fontFamilySupported()) { memcpy(address, entry.fontFamily().data(), entry.fontFamily().length()); address += entry.fontFamily().length(); *address++ = '\0'; } myParagraphs.back()->addEntry(myLastEntryStart); }
void XHTMLReader::endParagraph() { bool doBlockSpaceAfter = false; for (std::vector<shared_ptr<ZLTextStyleEntry> >::const_iterator it = myStyleEntryStack.begin(); it != myStyleEntryStack.end() - myStylesToRemove; ++it) { doBlockSpaceAfter = doBlockSpaceAfter || (*it)->isFeatureSupported(ZLTextStyleEntry::LENGTH_SPACE_AFTER); } if (doBlockSpaceAfter) { ZLTextStyleEntry blockingEntry; blockingEntry.setLength( ZLTextStyleEntry::LENGTH_SPACE_AFTER, 0, ZLTextStyleEntry::SIZE_UNIT_PIXEL ); myModelReader.addStyleEntry(blockingEntry); } for (; myStylesToRemove > 0; --myStylesToRemove) { myModelReader.addStyleEntry(*myStyleEntryStack.back()); myStyleEntryStack.pop_back(); } myModelReader.endParagraph(); }
void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Length name, const AttributeMap &map, const std::string &attributeName) { StyleSheetTable::AttributeMap::const_iterator it = map.find(attributeName); if (it == map.end()) { return; } const std::vector<std::string> &values = it->second; if (!values.empty() && !values[0].empty()) { short size; ZLTextStyleEntry::SizeUnit unit; parseLength(values[0], size, unit); entry.setLength(name, size, unit); } }
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 XHTMLReader::haveContent() { if (!myParseStack.back().haveContent) { // Create empty paragraphs for other parent entries that haven't // had any content yet, in order to apply their top margins. Skip // the last entry as it will be applied for the paragraph we are // about to start. bool skippedLastEntry = false; for (std::vector<ParseContext>::reverse_iterator it = myParseStack.rbegin(); it != myParseStack.rend() && !it->haveContent; ++it) { it->haveContent = true; if (elementHasTopMargin(*it)) { if (!skippedLastEntry) { skippedLastEntry = true; } else { ZLTextStyleEntry::SizeUnit unit = ZLTextStyleEntry::SIZE_UNIT_PIXEL; short size = 0; if (it->styleIndex >= 0 && myStyleStack[it->styleIndex].TextStyle.lengthSupported(ZLTextStyleEntry::LENGTH_SPACE_BEFORE)) { size = myStyleStack[it->styleIndex].TextStyle.length(ZLTextStyleEntry::LENGTH_SPACE_BEFORE, unit); } else if (it->decoration) { const ZLTextFullStyleDecoration *decoration = it->decoration->fullDecoration(); if (decoration) { size = decoration->SpaceBeforeOption.value(); unit = decoration->SpaceBeforeOptionUnit; } } if (size > 0) { ZLTextStyleEntry style; style.setLength(ZLTextStyleEntry::LENGTH_SPACE_BEFORE, size, unit); addStyleParagraph(style); } } } } } myBottomMargins.resize(0); beginParagraph(); }
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, unsigned char depth) { addStyleEntry(entry, entry.fontFamilies(), depth); }
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(); }
void RtfBookReader::setAlignment() { ZLTextStyleEntry entry; entry.setAlignmentType(myState.Alignment); myBookReader.addControl(entry); }