Ejemplo n.º 1
0
bool HtmlBookReader::tagHandler(const HtmlTag &tag) {
	myConverter->reset();

	if (tag.Start) {
		shared_ptr<TagData> tagData = new TagData();
		tagData->addEntry(myStyleSheetTable.control(tag.Name, ""));
		const std::string *cls = tag.find("class");
		if (cls != 0) {
			tagData->addEntry(myStyleSheetTable.control("", *cls));
			tagData->addEntry(myStyleSheetTable.control(tag.Name, *cls));
		}
		myTagDataStack.push_back(tagData);
	} else if (!myTagDataStack.empty()) {
		for (int i = myTagDataStack.back()->StyleEntries.size(); i > 0; --i) {
			myBookReader.addStyleCloseEntry();
		}
		myTagDataStack.pop_back();
	}
	const std::string *id = tag.find("id");
	if (id != 0) {
		myBookReader.addHyperlinkLabel(*id);
	}
	shared_ptr<HtmlTagAction> action = myActionMap[tag.Name];
	if (action.isNull()) {
		action = createAction(tag.Name);
		myActionMap[tag.Name] = action;
	}
	action->run(tag);

	if (tag.Start) {
		for (std::vector<shared_ptr<TagData> >::const_iterator it = myTagDataStack.begin(); it != myTagDataStack.end(); ++it) {
			const unsigned char depth = it - myTagDataStack.begin() + 1;
			const std::vector<shared_ptr<ZLTextStyleEntry> > &entries = (*it)->StyleEntries;
			const bool inheritedOnly = 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;
				myBookReader.addStyleEntry(*entry, depth);
			}
		}
	}

	return true;
}