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

'margin' property support

This commit is contained in:
Nikolay Pultsin 2014-09-18 06:25:23 +01:00
parent 81e2abe85d
commit fce3eda3a7
2 changed files with 39 additions and 3 deletions

View file

@ -223,7 +223,12 @@ void StyleSheetParser::processWord(const std::string &word) {
{
std::string stripped = word;
ZLStringUtil::stripWhiteSpaces(stripped);
myMap[myAttributeName] = stripped;
std::string &current = myMap[myAttributeName];
if (current.size() == 0) {
current = stripped;
} else {
current += ' ' + stripped;
}
break;
}
}
@ -256,7 +261,7 @@ void StyleSheetMultiStyleParser::storeData(const std::string &selector, const St
return;
}
const std::vector<std::string> ids = ZLStringUtil::split(s, ",");
const std::vector<std::string> ids = ZLStringUtil::split(s, ",", true);
for (std::vector<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it) {
std::string id = *it;
ZLStringUtil::stripWhiteSpaces(id);
@ -293,7 +298,7 @@ void StyleSheetMultiStyleParser::processAtRule(const std::string &name, const St
std::string path;
if (it != attributes.end()) {
// TODO: better split
const std::vector<std::string> ids = ZLStringUtil::split(it->second, " ");
const std::vector<std::string> ids = ZLStringUtil::split(it->second, " ", true);
for (std::vector<std::string>::const_iterator jt = ids.begin(); jt != ids.end(); ++jt) {
if (ZLStringUtil::stringStartsWith(*jt, "url(") &&
ZLStringUtil::stringEndsWith(*jt, ")")) {

View file

@ -243,6 +243,37 @@ shared_ptr<ZLTextStyleEntry> StyleSheetTable::createOrUpdateControl(const Attrib
}
}
StyleSheetTable::AttributeMap::const_iterator it = styles.find("margin");
if (it != styles.end()) {
std::vector<std::string> split = ZLStringUtil::split(it->second, " ", true);
if (split.size() > 0) {
switch (split.size()) {
case 1:
split.push_back(split[0]);
// go through
case 2:
split.push_back(split[0]);
// go through
case 3:
split.push_back(split[1]);
break;
}
}
short size;
ZLTextStyleEntry::SizeUnit unit;
if (parseLength(split[0], size, unit)) {
entry->setLength(ZLTextStyleEntry::LENGTH_SPACE_BEFORE, size, unit);
}
if (parseLength(split[1], size, unit)) {
entry->setLength(ZLTextStyleEntry::LENGTH_RIGHT_INDENT, size, unit);
}
if (parseLength(split[2], size, unit)) {
entry->setLength(ZLTextStyleEntry::LENGTH_SPACE_AFTER, size, unit);
}
if (parseLength(split[3], size, unit)) {
entry->setLength(ZLTextStyleEntry::LENGTH_LEFT_INDENT, size, unit);
}
}
setLength(*entry, ZLTextStyleEntry::LENGTH_LEFT_INDENT, styles, "margin-left");
setLength(*entry, ZLTextStyleEntry::LENGTH_RIGHT_INDENT, styles, "margin-right");
setLength(*entry, ZLTextStyleEntry::LENGTH_FIRST_LINE_INDENT, styles, "text-indent");