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(myReferenceName + HASH + id); } const std::string sTag = ZLUnicodeUtil::toLower(tag); const char *aClass = attributeValue(attributes, "class"); const std::string sClass = (aClass != 0) ? aClass : ""; if (myStyleSheetTable.doBreakBefore(sTag, sClass)) { myModelReader.insertEndOfSectionParagraph(); } myDoPageBreakAfterStack.push_back(myStyleSheetTable.doBreakAfter(sTag, sClass)); XHTMLTagAction *action = ourTagActions[sTag]; if (action != 0) { action->doAtStart(*this, attributes); } const int sizeBefore = myStyleEntryStack.size(); addStyleEntry(sTag, ""); addStyleEntry("", sClass); addStyleEntry(sTag, sClass); const char *style = attributeValue(attributes, "style"); if (style != 0) { shared_ptr<ZLTextStyleEntry> entry = myStyleParser.parseString(style); myModelReader.addControl(*entry); myStyleEntryStack.push_back(entry); } myCSSStack.push_back(myStyleEntryStack.size() - sizeBefore); }
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); }
void XHTMLReader::startElementHandler(const char *tag, const char **attributes) { static const std::string HASH = "#"; const char *id = attributeValue(attributes, "id"); const char *inlineStyle = attributeValue(attributes, "style"); const char *klass = attributeValue(attributes, "class"); if (id != 0) { myModelReader.addHyperlinkLabel(myReferenceName + HASH + id); } const std::string sTag = ZLUnicodeUtil::toLower(tag); myElementStack.push_back(StyleSheetTable::Element(sTag, klass, id)); myStyleStack.resize(myStyleStack.size() + 1); StyleSheetTable::Style *style = &myStyleStack.back(); if (myStyleStack.size() > 1) { style->inherit(myStyleStack.at(myStyleStack.size()-2)); } myStyleSheetTable.applyStyles(myElementStack, *style); if (inlineStyle) { style->apply(myStyleParser.parseString(inlineStyle)); } myParseStack.resize(myParseStack.size() + 1); ParseContext &prev(myParseStack.at(myParseStack.size()-2)); ParseContext &context(myParseStack.back()); if (style->TextStyle.opacitySupported()) { int opacity = prev.opacity; opacity *= style->TextStyle.opacity(); opacity /= 255; context.opacity = opacity; } else { context.opacity = prev.opacity; } // Don't collect empty styles if (style->empty()) { myStyleStack.resize(myStyleStack.size()-1); style = NULL; } else { context.styleIndex = myStyleStack.size() - 1; if (style->PageBreakBefore == B3_TRUE) { addPageBreak(); } } XHTMLTagAction *action = ourTagActions[sTag]; if (action != 0) { action->doAtStart(*this, attributes); } if (context.kind >= 0) { context.decoration = ZLTextStyleCollection::Instance().decoration(context.kind); } if (myModelReader.paragraphIsOpen()) { applyStyles(myParseStack.back()); } }
void XHTMLReader::endElementHandler(const char *tag) { bool pageBreak = false; ParseContext &context(myParseStack.back()); if (context.styleIndex >= 0) { if (myStyleStack[context.styleIndex].PageBreakAfter == B3_TRUE) { // If we are about to have a page break, we don't want // endParagraph() to apply pending bottom margins. myBottomMargins.resize(0); pageBreak = true; } } XHTMLTagAction *action = ourTagActions[ZLUnicodeUtil::toLower(tag)]; if (action != 0) { action->doAtEnd(*this); } if (pageBreak) { addPageBreak(); } if (myModelReader.paragraphIsOpen()) { if (context.styleIndex >= 0) { myModelReader.addControl(REGULAR, false); } if (context.kind >= 0) { myModelReader.addControl((FBTextKind)context.kind, false); } } if (!context.bottomMarginApplied && elementHasBottomMargin(context)) { ZLTextStyleEntry::SizeUnit unit = ZLTextStyleEntry::SIZE_UNIT_PIXEL; short size = 0; if (context.styleIndex >= 0 && myStyleStack[context.styleIndex].TextStyle.lengthSupported(ZLTextStyleEntry::LENGTH_SPACE_AFTER)) { size = myStyleStack[context.styleIndex].TextStyle.length(ZLTextStyleEntry::LENGTH_SPACE_AFTER, unit); } else if (context.decoration) { const ZLTextFullStyleDecoration *decoration = context.decoration->fullDecoration(); if (decoration) { size = decoration->SpaceAfterOption.value(); unit = decoration->SpaceAfterOptionUnit; } } if (size > 0) { addBottomMargin(size, unit); } } if (!myModelReader.paragraphIsOpen()) { applyBottomMargins(); } if (context.styleIndex >= 0) { myStyleStack.pop_back(); } myElementStack.pop_back(); myParseStack.pop_back(); }
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(myReferenceName + HASH + id); } XHTMLTagAction *action = ourTagActions[ZLUnicodeUtil::toLower(tag)]; if (action != 0) { action->doAtStart(*this, attributes); } }
void XHTMLReader::endElementHandler(const char *tag) { for (int i = myCSSStack.back(); i > 0; --i) { myModelReader.addStyleCloseEntry(); } myStylesToRemove = myCSSStack.back(); myCSSStack.pop_back(); XHTMLTagAction *action = ourTagActions[ZLUnicodeUtil::toLower(tag)]; if (action != 0) { action->doAtEnd(*this); myNewParagraphInProgress = false; } for (; myStylesToRemove > 0; --myStylesToRemove) { myStyleEntryStack.pop_back(); } if (myDoPageBreakAfterStack.back()) { myModelReader.insertEndOfSectionParagraph(); } myDoPageBreakAfterStack.pop_back(); }
void XHTMLReader::endElementHandler(const char *tag) { const std::string sTag = ZLUnicodeUtil::toLower(tag); if (sTag == "br") { return; } XHTMLTagAction *action = getAction(sTag); if (action != 0 && action->isEnabled(myReadState)) { action->doAtEnd(*this); myNewParagraphInProgress = false; } for (int i = myTagDataStack.back()->StyleEntries.size(); i > 0; --i) { myModelReader.addStyleCloseEntry(); } if (myTagDataStack.back()->PageBreakAfter) { myModelReader.insertEndOfSectionParagraph(); } myTagDataStack.pop_back(); }
void XHTMLReader::endElementHandler(const char *tag) { XHTMLTagAction *action = ourTagActions[ZLUnicodeUtil::toLower(tag)]; if (action != 0) { action->doAtEnd(*this); } }