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 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::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 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 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(); }