mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
StyleSheetTable::Key replaced with CSSSelector
This commit is contained in:
parent
4d4a096e3f
commit
4de9d69bc0
4 changed files with 51 additions and 40 deletions
|
@ -21,6 +21,11 @@
|
|||
|
||||
#include "CSSSelector.h"
|
||||
|
||||
CSSSelector::CSSSelector(const std::string &tag, const std::string &clazz) {
|
||||
Tag = tag;
|
||||
Class = clazz;
|
||||
}
|
||||
|
||||
CSSSelector::CSSSelector(const std::string &simple) {
|
||||
const std::size_t index = simple.find('.');
|
||||
if (index == std::string::npos) {
|
||||
|
@ -84,3 +89,25 @@ shared_ptr<CSSSelector> CSSSelector::parse(const std::string &data) {
|
|||
|
||||
return selector;
|
||||
}
|
||||
|
||||
bool CSSSelector::operator < (const CSSSelector &selector) const {
|
||||
int diff = Tag.compare(selector.Tag);
|
||||
if (diff != 0) {
|
||||
return diff < 0;
|
||||
}
|
||||
diff = Class.compare(selector.Class);
|
||||
if (diff != 0) {
|
||||
return diff < 0;
|
||||
}
|
||||
if (selector.Next.isNull()) {
|
||||
return false;
|
||||
}
|
||||
if (Next.isNull()) {
|
||||
return true;
|
||||
}
|
||||
diff = Next->Delimiter - selector.Next->Delimiter;
|
||||
if (diff != 0) {
|
||||
return diff < 0;
|
||||
}
|
||||
return *(Next->Selector) < *(selector.Next->Selector);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,10 @@ private:
|
|||
private:
|
||||
CSSSelector(const std::string &simple);
|
||||
|
||||
public:
|
||||
CSSSelector(const std::string &tag, const std::string &clazz);
|
||||
bool operator < (const CSSSelector &selector) const;
|
||||
|
||||
public:
|
||||
std::string Tag;
|
||||
std::string Class;
|
||||
|
|
|
@ -29,23 +29,23 @@ bool StyleSheetTable::isEmpty() const {
|
|||
return myControlMap.empty() && myPageBreakBeforeMap.empty() && myPageBreakAfterMap.empty();
|
||||
}
|
||||
|
||||
void StyleSheetTable::addMap(shared_ptr<CSSSelector> selector, const AttributeMap &map) {
|
||||
if (!selector.isNull() && selector->Next.isNull() && !map.empty()) {
|
||||
const Key key(selector->Tag, selector->Class);
|
||||
myControlMap[key] = createOrUpdateControl(map, myControlMap[key]);
|
||||
void StyleSheetTable::addMap(shared_ptr<CSSSelector> selectorPtr, const AttributeMap &map) {
|
||||
if (!selectorPtr.isNull() && !map.empty()) {
|
||||
const CSSSelector &selector = *selectorPtr;
|
||||
myControlMap[selector] = createOrUpdateControl(map, myControlMap[selector]);
|
||||
|
||||
const std::string &pbb = value(map, "page-break-before");
|
||||
if (pbb == "always" || pbb == "left" || pbb == "right") {
|
||||
myPageBreakBeforeMap[key] = true;
|
||||
myPageBreakBeforeMap[selector] = true;
|
||||
} else if (pbb == "avoid") {
|
||||
myPageBreakBeforeMap[key] = false;
|
||||
myPageBreakBeforeMap[selector] = false;
|
||||
}
|
||||
|
||||
const std::string &pba = value(map, "page-break-after");
|
||||
if (pba == "always" || pba == "left" || pba == "right") {
|
||||
myPageBreakAfterMap[key] = true;
|
||||
myPageBreakAfterMap[selector] = true;
|
||||
} else if (pba == "avoid") {
|
||||
myPageBreakAfterMap[key] = false;
|
||||
myPageBreakAfterMap[selector] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,17 +96,17 @@ void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Featu
|
|||
}
|
||||
|
||||
bool StyleSheetTable::doBreakBefore(const std::string &tag, const std::string &aClass) const {
|
||||
std::map<Key,bool>::const_iterator it = myPageBreakBeforeMap.find(Key(tag, aClass));
|
||||
std::map<CSSSelector,bool>::const_iterator it = myPageBreakBeforeMap.find(CSSSelector(tag, aClass));
|
||||
if (it != myPageBreakBeforeMap.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
it = myPageBreakBeforeMap.find(Key("", aClass));
|
||||
it = myPageBreakBeforeMap.find(CSSSelector("", aClass));
|
||||
if (it != myPageBreakBeforeMap.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
it = myPageBreakBeforeMap.find(Key(tag, ""));
|
||||
it = myPageBreakBeforeMap.find(CSSSelector(tag, ""));
|
||||
if (it != myPageBreakBeforeMap.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
@ -115,17 +115,17 @@ bool StyleSheetTable::doBreakBefore(const std::string &tag, const std::string &a
|
|||
}
|
||||
|
||||
bool StyleSheetTable::doBreakAfter(const std::string &tag, const std::string &aClass) const {
|
||||
std::map<Key,bool>::const_iterator it = myPageBreakAfterMap.find(Key(tag, aClass));
|
||||
std::map<CSSSelector,bool>::const_iterator it = myPageBreakAfterMap.find(CSSSelector(tag, aClass));
|
||||
if (it != myPageBreakAfterMap.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
it = myPageBreakAfterMap.find(Key("", aClass));
|
||||
it = myPageBreakAfterMap.find(CSSSelector("", aClass));
|
||||
if (it != myPageBreakAfterMap.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
it = myPageBreakAfterMap.find(Key(tag, ""));
|
||||
it = myPageBreakAfterMap.find(CSSSelector(tag, ""));
|
||||
if (it != myPageBreakAfterMap.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
@ -134,8 +134,8 @@ bool StyleSheetTable::doBreakAfter(const std::string &tag, const std::string &aC
|
|||
}
|
||||
|
||||
shared_ptr<ZLTextStyleEntry> StyleSheetTable::control(const std::string &tag, const std::string &aClass) const {
|
||||
std::map<Key,shared_ptr<ZLTextStyleEntry> >::const_iterator it =
|
||||
myControlMap.find(Key(tag, aClass));
|
||||
std::map<CSSSelector,shared_ptr<ZLTextStyleEntry> >::const_iterator it =
|
||||
myControlMap.find(CSSSelector(tag, aClass));
|
||||
return it != myControlMap.end() ? it->second : 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <ZLTextParagraph.h>
|
||||
#include <ZLTextStyleEntry.h>
|
||||
|
||||
class CSSSelector;
|
||||
#include "CSSSelector.h"
|
||||
|
||||
class StyleSheetTable {
|
||||
|
||||
|
@ -52,32 +52,12 @@ public:
|
|||
void clear();
|
||||
|
||||
private:
|
||||
struct Key {
|
||||
Key(const std::string &tag, const std::string &aClass);
|
||||
|
||||
const std::string TagName;
|
||||
const std::string ClassName;
|
||||
|
||||
bool operator < (const Key &key) const;
|
||||
};
|
||||
|
||||
std::map<Key,shared_ptr<ZLTextStyleEntry> > myControlMap;
|
||||
std::map<Key,bool> myPageBreakBeforeMap;
|
||||
std::map<Key,bool> myPageBreakAfterMap;
|
||||
std::map<CSSSelector,shared_ptr<ZLTextStyleEntry> > myControlMap;
|
||||
std::map<CSSSelector,bool> myPageBreakBeforeMap;
|
||||
std::map<CSSSelector,bool> myPageBreakAfterMap;
|
||||
|
||||
friend class StyleSheetTableParser;
|
||||
friend class StyleSheetParserWithCache;
|
||||
};
|
||||
|
||||
inline StyleSheetTable::Key::Key(const std::string &tag, const std::string &aClass) : TagName(tag), ClassName(aClass) {
|
||||
}
|
||||
|
||||
inline bool StyleSheetTable::Key::operator < (const StyleSheetTable::Key &key) const {
|
||||
const int diff = TagName.compare(key.TagName);
|
||||
if (diff != 0) {
|
||||
return diff < 0;
|
||||
}
|
||||
return ClassName < key.ClassName;
|
||||
}
|
||||
|
||||
#endif /* __STYLESHEETTABLE_H__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue