1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +02:00

multiple css classes for single xhtml tag

This commit is contained in:
Nikolay Pultsin 2014-03-17 15:16:35 +02:00
parent f1043daea9
commit 2f5e28d325
2 changed files with 38 additions and 12 deletions

View file

@ -1,6 +1,7 @@
===== 1.9.7 (Mar ??, 2014) ===== ===== 1.9.7 (Mar ??, 2014) =====
* Experimental video support * Experimental video support
* CSS parsing optimization for ePubs (do not parse css files multiple times) * CSS parsing optimization for ePubs (do not parse css files multiple times)
* CSS support improvement: added support for space-separated classes list
===== 1.9.6.1 (Feb 24, 2014) ===== ===== 1.9.6.1 (Feb 24, 2014) =====
* Fixed some config vaues reading (e.g. background) * Fixed some config vaues reading (e.g. background)

View file

@ -664,13 +664,36 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes)
const std::string sTag = ZLUnicodeUtil::toLower(tag); const std::string sTag = ZLUnicodeUtil::toLower(tag);
const char *aClass = attributeValue(attributes, "class"); std::vector<std::string> classesList;
const std::string sClass = (aClass != 0) ? aClass : ""; 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("");
}
if (myStyleSheetTable.doBreakBefore(sTag, sClass)) { 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(); myModelReader.insertEndOfSectionParagraph();
} }
myDoPageBreakAfterStack.push_back(myStyleSheetTable.doBreakAfter(sTag, sClass)); myDoPageBreakAfterStack.push_back(breakAfter);
XHTMLTagAction *action = getAction(sTag); XHTMLTagAction *action = getAction(sTag);
if (action != 0 && action->isEnabled(myReadState)) { if (action != 0 && action->isEnabled(myReadState)) {
@ -679,14 +702,16 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes)
const int sizeBefore = myStyleEntryStack.size(); const int sizeBefore = myStyleEntryStack.size();
addStyleEntry(sTag, ""); addStyleEntry(sTag, "");
addStyleEntry("", sClass); for (std::vector<std::string>::const_iterator it = classesList.begin(); it != classesList.end(); ++it) {
addStyleEntry(sTag, sClass); addStyleEntry("", *it);
const char *style = attributeValue(attributes, "style"); addStyleEntry(sTag, *it);
if (style != 0) { const char *style = attributeValue(attributes, "style");
ZLLogger::Instance().println("CSS", std::string("parsing style attribute: ") + style); if (style != 0) {
shared_ptr<ZLTextStyleEntry> entry = myStyleParser->parseString(style); ZLLogger::Instance().println("CSS", std::string("parsing style attribute: ") + style);
myModelReader.addStyleEntry(*entry); shared_ptr<ZLTextStyleEntry> entry = myStyleParser->parseString(style);
myStyleEntryStack.push_back(entry); myModelReader.addStyleEntry(*entry);
myStyleEntryStack.push_back(entry);
}
} }
myCSSStack.push_back(myStyleEntryStack.size() - sizeBefore); myCSSStack.push_back(myStyleEntryStack.size() - sizeBefore);
} }