Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
void XHTMLReader::endElementHandler(const char *tag) {
	for (int i = myCSSStack.back(); i > 0; --i) {
		myModelReader.addStyleCloseEntry();
	}
	myStylesToRemove = myCSSStack.back();
	myCSSStack.pop_back();

	XHTMLTagAction *action = getAction(tag);
	if (action != 0 && action->isEnabled(myReadState)) {
		action->doAtEnd(*this);
		myNewParagraphInProgress = false;
	}

	for (; myStylesToRemove > 0; --myStylesToRemove) {
		myStyleEntryStack.pop_back();
	}

	if (myDoPageBreakAfterStack.back()) {
		myModelReader.insertEndOfSectionParagraph();
	}
	myDoPageBreakAfterStack.pop_back();
}
Ejemplo n.º 3
0
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();
}