mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
do not split css values in parser
This commit is contained in:
parent
5cea231a6a
commit
ccdb527030
3 changed files with 75 additions and 92 deletions
|
@ -29,27 +29,21 @@ bool StyleSheetTable::isEmpty() const {
|
|||
|
||||
void StyleSheetTable::addMap(const std::string &tag, const std::string &aClass, const AttributeMap &map) {
|
||||
if ((!tag.empty() || !aClass.empty()) && !map.empty()) {
|
||||
Key key(tag, aClass);
|
||||
const Key key(tag, aClass);
|
||||
myControlMap[key] = createControl(map);
|
||||
const std::vector<std::string> &pbb = values(map, "page-break-before");
|
||||
if (!pbb.empty()) {
|
||||
if ((pbb[0] == "always") ||
|
||||
(pbb[0] == "left") ||
|
||||
(pbb[0] == "right")) {
|
||||
myPageBreakBeforeMap[key] = true;
|
||||
} else if (pbb[0] == "avoid") {
|
||||
myPageBreakBeforeMap[key] = false;
|
||||
}
|
||||
|
||||
const std::string &pbb = value(map, "page-break-before");
|
||||
if (pbb == "always" || pbb == "left" || pbb == "right") {
|
||||
myPageBreakBeforeMap[key] = true;
|
||||
} else if (pbb == "avoid") {
|
||||
myPageBreakBeforeMap[key] = false;
|
||||
}
|
||||
const std::vector<std::string> &pba = values(map, "page-break-after");
|
||||
if (!pba.empty()) {
|
||||
if ((pba[0] == "always") ||
|
||||
(pba[0] == "left") ||
|
||||
(pba[0] == "right")) {
|
||||
myPageBreakAfterMap[key] = true;
|
||||
} else if (pba[0] == "avoid") {
|
||||
myPageBreakAfterMap[key] = false;
|
||||
}
|
||||
|
||||
const std::string &pba = value(map, "page-break-after");
|
||||
if (pba == "always" || pba == "left" || pba == "right") {
|
||||
myPageBreakAfterMap[key] = true;
|
||||
} else if (pba == "avoid") {
|
||||
myPageBreakAfterMap[key] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,13 +78,10 @@ void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Featu
|
|||
if (it == map.end()) {
|
||||
return;
|
||||
}
|
||||
const std::vector<std::string> &values = it->second;
|
||||
if (!values.empty() && !values[0].empty()) {
|
||||
short size;
|
||||
ZLTextStyleEntry::SizeUnit unit;
|
||||
if (parseLength(values[0], size, unit)) {
|
||||
entry.setLength(featureId, size, unit);
|
||||
}
|
||||
short size;
|
||||
ZLTextStyleEntry::SizeUnit unit;
|
||||
if (parseLength(it->second, size, unit)) {
|
||||
entry.setLength(featureId, size, unit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,106 +129,103 @@ shared_ptr<ZLTextStyleEntry> StyleSheetTable::control(const std::string &tag, co
|
|||
return (it != myControlMap.end()) ? it->second : 0;
|
||||
}
|
||||
|
||||
const std::vector<std::string> &StyleSheetTable::values(const AttributeMap &map, const std::string &name) {
|
||||
const std::string &StyleSheetTable::value(const AttributeMap &map, const std::string &name) {
|
||||
const AttributeMap::const_iterator it = map.find(name);
|
||||
if (it != map.end()) {
|
||||
return it->second;
|
||||
}
|
||||
static const std::vector<std::string> emptyVector;
|
||||
return emptyVector;
|
||||
static const std::string emptyString;
|
||||
return emptyString;
|
||||
}
|
||||
|
||||
shared_ptr<ZLTextStyleEntry> StyleSheetTable::createControl(const AttributeMap &styles) {
|
||||
shared_ptr<ZLTextStyleEntry> entry = new ZLTextStyleEntry(ZLTextStyleEntry::STYLE_CSS_ENTRY);
|
||||
|
||||
const std::vector<std::string> &alignment = values(styles, "text-align");
|
||||
if (!alignment.empty()) {
|
||||
if (alignment[0] == "justify") {
|
||||
entry->setAlignmentType(ALIGN_JUSTIFY);
|
||||
} else if (alignment[0] == "left") {
|
||||
entry->setAlignmentType(ALIGN_LEFT);
|
||||
} else if (alignment[0] == "right") {
|
||||
entry->setAlignmentType(ALIGN_RIGHT);
|
||||
} else if (alignment[0] == "center") {
|
||||
entry->setAlignmentType(ALIGN_CENTER);
|
||||
}
|
||||
const std::string &alignment = value(styles, "text-align");
|
||||
if (alignment == "justify") {
|
||||
entry->setAlignmentType(ALIGN_JUSTIFY);
|
||||
} else if (alignment == "left") {
|
||||
entry->setAlignmentType(ALIGN_LEFT);
|
||||
} else if (alignment == "right") {
|
||||
entry->setAlignmentType(ALIGN_RIGHT);
|
||||
} else if (alignment == "center") {
|
||||
entry->setAlignmentType(ALIGN_CENTER);
|
||||
}
|
||||
|
||||
const std::vector<std::string> &deco = values(styles, "text-decoration");
|
||||
for (std::vector<std::string>::const_iterator it = deco.begin(); it != deco.end(); ++it) {
|
||||
if (*it == "underline") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_UNDERLINED, true);
|
||||
} else if (*it == "line-through") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_STRIKEDTHROUGH, true);
|
||||
} else if (*it == "none") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_UNDERLINED, false);
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_STRIKEDTHROUGH, false);
|
||||
}
|
||||
const std::string &deco = value(styles, "text-decoration");
|
||||
if (deco == "underline") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_UNDERLINED, true);
|
||||
} else if (deco == "line-through") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_STRIKEDTHROUGH, true);
|
||||
} else if (deco == "none") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_UNDERLINED, false);
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_STRIKEDTHROUGH, false);
|
||||
}
|
||||
|
||||
const std::vector<std::string> &bold = values(styles, "font-weight");
|
||||
const std::string bold = value(styles, "font-weight");
|
||||
if (!bold.empty()) {
|
||||
int num = -1;
|
||||
if (bold[0] == "bold") {
|
||||
if (bold == "bold") {
|
||||
num = 700;
|
||||
} else if (bold[0] == "normal") {
|
||||
} else if (bold == "normal") {
|
||||
num = 400;
|
||||
} else if (bold[0] == "bolder") {
|
||||
} else if (bold == "bolder") {
|
||||
// TODO: implement
|
||||
} else if (bold[0] == "lighter") {
|
||||
} else if (bold == "lighter") {
|
||||
// TODO: implement
|
||||
} else {
|
||||
num = ZLStringUtil::stringToInteger(bold[0], -1);
|
||||
num = ZLStringUtil::stringToInteger(bold, -1);
|
||||
}
|
||||
if (num != -1) {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_BOLD, num >= 600);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::string> &italic = values(styles, "font-style");
|
||||
const std::string &italic = value(styles, "font-style");
|
||||
if (!italic.empty()) {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_ITALIC, italic[0] == "italic");
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_ITALIC, italic == "italic" || italic == "oblique");
|
||||
}
|
||||
|
||||
const std::vector<std::string> &variant = values(styles, "font-variant");
|
||||
const std::string &variant = value(styles, "font-variant");
|
||||
if (!variant.empty()) {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_SMALLCAPS, variant[0] == "small-caps");
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_SMALLCAPS, variant == "small-caps");
|
||||
}
|
||||
|
||||
const std::vector<std::string> &fontFamily = values(styles, "font-family");
|
||||
if (!fontFamily.empty() && !fontFamily[0].empty()) {
|
||||
entry->setFontFamily(fontFamily[0]);
|
||||
const std::string &fontFamily = value(styles, "font-family");
|
||||
// TODO: split(',')
|
||||
if (!fontFamily.empty()) {
|
||||
entry->setFontFamily(fontFamily);
|
||||
}
|
||||
|
||||
const std::vector<std::string> &fontSize = values(styles, "font-size");
|
||||
const std::string &fontSize = value(styles, "font-size");
|
||||
if (!fontSize.empty()) {
|
||||
bool doSetFontSize = true;
|
||||
short size = 100;
|
||||
ZLTextStyleEntry::SizeUnit unit = ZLTextStyleEntry::SIZE_UNIT_PERCENT;
|
||||
if (fontSize[0] == "xx-small") {
|
||||
if (fontSize == "xx-small") {
|
||||
size = 58;
|
||||
} else if (fontSize[0] == "x-small") {
|
||||
} else if (fontSize == "x-small") {
|
||||
size = 69;
|
||||
} else if (fontSize[0] == "small") {
|
||||
} else if (fontSize == "small") {
|
||||
size = 83;
|
||||
} else if (fontSize[0] == "medium") {
|
||||
} else if (fontSize == "medium") {
|
||||
size = 100;
|
||||
} else if (fontSize[0] == "large") {
|
||||
} else if (fontSize == "large") {
|
||||
size = 120;
|
||||
} else if (fontSize[0] == "x-large") {
|
||||
} else if (fontSize == "x-large") {
|
||||
size = 144;
|
||||
} else if (fontSize[0] == "xx-large") {
|
||||
} else if (fontSize == "xx-large") {
|
||||
size = 173;
|
||||
} else if (fontSize[0] == "inherit") {
|
||||
} else if (fontSize == "inherit") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_INHERIT, true);
|
||||
doSetFontSize = false;
|
||||
} else if (fontSize[0] == "smaller") {
|
||||
} else if (fontSize == "smaller") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_SMALLER, true);
|
||||
doSetFontSize = false;
|
||||
} else if (fontSize[0] == "larger") {
|
||||
} else if (fontSize == "larger") {
|
||||
entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_LARGER, true);
|
||||
doSetFontSize = false;
|
||||
} else if (!parseLength(fontSize[0], size, unit)) {
|
||||
} else if (!parseLength(fontSize, size, unit)) {
|
||||
doSetFontSize = false;
|
||||
}
|
||||
if (doSetFontSize) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue