void XHTMLReader::startElementHandler(const char *tag, const char **attributes) { static const std::string HASH = "#"; const char *id = attributeValue(attributes, "id"); if (id != 0) { myModelReader.addHyperlinkLabel(myReferenceAlias + HASH + id); } const std::string sTag = ZLUnicodeUtil::toLower(tag); std::vector<std::string> classesList; const char *aClasses = attributeValue(attributes, "class"); if (aClasses != 0) { const std::vector<std::string> split = ZLStringUtil::split(aClasses, " "); for (std::vector<std::string>::const_iterator it = split.begin(); it != split.end(); ++it) { if (!it->empty()) { classesList.push_back(*it); } } } if (classesList.empty()) { classesList.push_back(""); } bool breakBefore = false; bool breakAfter = false; for (std::vector<std::string>::const_iterator it = classesList.begin(); it != classesList.end(); ++it) { // TODO: use 3-value logic (yes, no, inherit) if (myStyleSheetTable.doBreakBefore(sTag, *it)) { breakBefore = true; } // TODO: use 3-value logic (yes, no, inherit) if (myStyleSheetTable.doBreakAfter(sTag, *it)) { breakAfter = true; } } if (breakBefore) { myModelReader.insertEndOfSectionParagraph(); } myDoPageBreakAfterStack.push_back(breakAfter); XHTMLTagAction *action = getAction(sTag); if (action != 0 && action->isEnabled(myReadState)) { action->doAtStart(*this, attributes); } const int sizeBefore = myStyleEntryStack.size(); addTextStyleEntry(sTag, ""); for (std::vector<std::string>::const_iterator it = classesList.begin(); it != classesList.end(); ++it) { addTextStyleEntry("", *it); addTextStyleEntry(sTag, *it); const char *style = attributeValue(attributes, "style"); if (style != 0) { //ZLLogger::Instance().println("CSS", std::string("parsing style attribute: ") + style); shared_ptr<ZLTextStyleEntry> entry = myStyleParser->parseSingleEntry(style); addTextStyleEntry(*entry); myStyleEntryStack.push_back(entry); } } myCSSStack.push_back(myStyleEntryStack.size() - sizeBefore); }
bool XHTMLReader::addTextStyleEntry(const std::string tag, const std::string aClass) { shared_ptr<ZLTextStyleEntry> entry = myStyleSheetTable.control(tag, aClass); if (!entry.isNull()) { addTextStyleEntry(*entry); myStyleEntryStack.push_back(entry); 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) { addTextStyleEntry(**it); doBlockSpaceBefore = doBlockSpaceBefore || (*it)->isFeatureSupported(ZLTextStyleEntry::LENGTH_SPACE_BEFORE); } if (doBlockSpaceBefore) { ZLTextStyleEntry blockingEntry(ZLTextStyleEntry::STYLE_OTHER_ENTRY); blockingEntry.setLength( ZLTextStyleEntry::LENGTH_SPACE_BEFORE, 0, ZLTextStyleEntry::SIZE_UNIT_PIXEL ); addTextStyleEntry(blockingEntry); } }
void XHTMLReader::restartParagraph() { if (myCurrentParagraphIsEmpty) { myModelReader.addFixedHSpace(1); } ZLTextStyleEntry spaceAfterBlocker(ZLTextStyleEntry::STYLE_OTHER_ENTRY); spaceAfterBlocker.setLength( ZLTextStyleEntry::LENGTH_SPACE_AFTER, 0, ZLTextStyleEntry::SIZE_UNIT_PIXEL ); addTextStyleEntry(spaceAfterBlocker); endParagraph(); beginParagraph(true); ZLTextStyleEntry spaceBeforeBlocker(ZLTextStyleEntry::STYLE_OTHER_ENTRY); spaceBeforeBlocker.setLength( ZLTextStyleEntry::LENGTH_SPACE_BEFORE, 0, ZLTextStyleEntry::SIZE_UNIT_PIXEL ); addTextStyleEntry(spaceBeforeBlocker); }
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(ZLTextStyleEntry::STYLE_OTHER_ENTRY); blockingEntry.setLength( ZLTextStyleEntry::LENGTH_SPACE_AFTER, 0, ZLTextStyleEntry::SIZE_UNIT_PIXEL ); addTextStyleEntry(blockingEntry); } for (; myStylesToRemove > 0; --myStylesToRemove) { addTextStyleEntry(*myStyleEntryStack.back()); myStyleEntryStack.pop_back(); } myModelReader.endParagraph(); }
void XHTMLReader::beginParagraph(bool restarted) { myCurrentParagraphIsEmpty = true; myModelReader.beginParagraph(); for (std::vector<shared_ptr<TagData> >::const_iterator it = myTagDataStack.begin(); it != myTagDataStack.end(); ++it) { const std::vector<FBTextKind> &kinds = (*it)->TextKinds; for (std::vector<FBTextKind>::const_iterator jt = kinds.begin(); jt != kinds.end(); ++jt) { myModelReader.addControl(*jt, true); } const std::vector<shared_ptr<ZLTextStyleEntry> > &entries = (*it)->StyleEntries; bool inheritedOnly = !restarted || it + 1 != myTagDataStack.end(); for (std::vector<shared_ptr<ZLTextStyleEntry> >::const_iterator jt = entries.begin(); jt != entries.end(); ++jt) { shared_ptr<ZLTextStyleEntry> entry = inheritedOnly ? (*jt)->inherited() : *jt; addTextStyleEntry(*entry); } } }