diff --git a/fbreader/fbreader/fbreader/src/formats/css/StyleSheetTable.cpp b/fbreader/fbreader/fbreader/src/formats/css/StyleSheetTable.cpp index 906ed39..17f5fa2 100644 --- a/fbreader/fbreader/fbreader/src/formats/css/StyleSheetTable.cpp +++ b/fbreader/fbreader/fbreader/src/formats/css/StyleSheetTable.cpp @@ -76,10 +76,15 @@ void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Lengt return; } const std::vector &values = it->second; - if (!values.empty() && !values[0].empty()) { + if (!values.empty()) + setLength(entry, name, values[0]); +} + +void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Length name, const std::string &value) { + if (!value.empty()) { short size; ZLTextStyleEntry::SizeUnit unit; - parseLength(values[0], size, unit); + parseLength(value, size, unit); entry.setLength(name, size, unit); } } @@ -208,6 +213,34 @@ shared_ptr StyleSheetTable::createControl(const AttributeMap & } } + const std::vector &margins = values(styles, "margin"); + switch (margins.size()) { + case 1: + setLength(*entry, ZLTextStyleEntry::LENGTH_SPACE_BEFORE, margins[0]); + setLength(*entry, ZLTextStyleEntry::LENGTH_RIGHT_INDENT, margins[0]); + setLength(*entry, ZLTextStyleEntry::LENGTH_SPACE_AFTER, margins[0]); + setLength(*entry, ZLTextStyleEntry::LENGTH_LEFT_INDENT, margins[0]); + break; + case 2: + setLength(*entry, ZLTextStyleEntry::LENGTH_SPACE_BEFORE, margins[0]); + setLength(*entry, ZLTextStyleEntry::LENGTH_SPACE_AFTER, margins[0]); + setLength(*entry, ZLTextStyleEntry::LENGTH_RIGHT_INDENT, margins[1]); + setLength(*entry, ZLTextStyleEntry::LENGTH_LEFT_INDENT, margins[1]); + break; + case 3: + setLength(*entry, ZLTextStyleEntry::LENGTH_SPACE_BEFORE, margins[0]); + setLength(*entry, ZLTextStyleEntry::LENGTH_RIGHT_INDENT, margins[1]); + setLength(*entry, ZLTextStyleEntry::LENGTH_LEFT_INDENT, margins[1]); + setLength(*entry, ZLTextStyleEntry::LENGTH_SPACE_AFTER, margins[2]); + break; + case 4: + setLength(*entry, ZLTextStyleEntry::LENGTH_SPACE_BEFORE, margins[0]); + setLength(*entry, ZLTextStyleEntry::LENGTH_RIGHT_INDENT, margins[1]); + setLength(*entry, ZLTextStyleEntry::LENGTH_SPACE_AFTER, margins[2]); + setLength(*entry, ZLTextStyleEntry::LENGTH_LEFT_INDENT, margins[3]); + break; + } + 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_DELTA, styles, "text-indent"); diff --git a/fbreader/fbreader/fbreader/src/formats/css/StyleSheetTable.h b/fbreader/fbreader/fbreader/src/formats/css/StyleSheetTable.h index ba4ef6a..e4210e7 100644 --- a/fbreader/fbreader/fbreader/src/formats/css/StyleSheetTable.h +++ b/fbreader/fbreader/fbreader/src/formats/css/StyleSheetTable.h @@ -38,6 +38,7 @@ private: void addMap(const std::string &tag, const std::string &aClass, const AttributeMap &map); static void setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Length name, const AttributeMap &map, const std::string &attributeName); + static void setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Length name, const std::string &value); static const std::vector &values(const AttributeMap &map, const std::string &name); public: