Create one combined CSS entry per XHTML element
This commit is contained in:
parent
c9419843cc
commit
e8914786d1
4 changed files with 41 additions and 13 deletions
|
@ -506,12 +506,12 @@ bool XHTMLReader::readFile(const ZLFile &file, const std::string &referenceName)
|
|||
return readDocument(file);
|
||||
}
|
||||
|
||||
void XHTMLReader::addStyleEntry(const std::string &tag, const std::string &aClass) {
|
||||
shared_ptr<ZLTextStyleEntry> entry = myStyleSheetTable.control(tag, aClass);
|
||||
if (!entry.isNull()) {
|
||||
myModelReader.addControl(*entry);
|
||||
myStyleEntryStack.push_back(entry);
|
||||
shared_ptr<ZLTextStyleEntry> XHTMLReader::addStyleEntry(shared_ptr<ZLTextStyleEntry> entry, shared_ptr<ZLTextStyleEntry> styleEntry) {
|
||||
if (!styleEntry.isNull() && !styleEntry->isEmpty()) {
|
||||
if (entry.isNull()) entry = new ZLTextStyleEntry;
|
||||
entry->apply(*styleEntry);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
void XHTMLReader::startElementHandler(const char *tag, const char **attributes) {
|
||||
|
@ -536,17 +536,21 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes)
|
|||
action->doAtStart(*this, attributes);
|
||||
}
|
||||
|
||||
const int sizeBefore = myStyleEntryStack.size();
|
||||
addStyleEntry(sTag, "");
|
||||
addStyleEntry("", sClass);
|
||||
addStyleEntry(sTag, sClass);
|
||||
shared_ptr<ZLTextStyleEntry> entry;
|
||||
entry = addStyleEntry(entry, myStyleSheetTable.control(sTag, ""));
|
||||
entry = addStyleEntry(entry, myStyleSheetTable.control("", sClass));
|
||||
entry = addStyleEntry(entry, myStyleSheetTable.control(sTag, sClass));
|
||||
const char *style = attributeValue(attributes, "style");
|
||||
if (style != 0) {
|
||||
shared_ptr<ZLTextStyleEntry> entry = myStyleParser.parseString(style);
|
||||
entry = addStyleEntry(entry, myStyleParser.parseString(style));
|
||||
}
|
||||
if (!entry.isNull()) {
|
||||
myModelReader.addControl(*entry);
|
||||
myStyleEntryStack.push_back(entry);
|
||||
myCSSStack.push_back(1);
|
||||
} else {
|
||||
myCSSStack.push_back(0);
|
||||
}
|
||||
myCSSStack.push_back(myStyleEntryStack.size() - sizeBefore);
|
||||
}
|
||||
|
||||
void XHTMLReader::endElementHandler(const char *tag) {
|
||||
|
|
|
@ -73,7 +73,7 @@ private:
|
|||
|
||||
void beginParagraph();
|
||||
void endParagraph();
|
||||
void addStyleEntry(const std::string &tag, const std::string &aClass);
|
||||
static shared_ptr<ZLTextStyleEntry> addStyleEntry(shared_ptr<ZLTextStyleEntry> entry, shared_ptr<ZLTextStyleEntry> styleEntry);
|
||||
|
||||
private:
|
||||
BookReader &myModelReader;
|
||||
|
|
|
@ -74,6 +74,28 @@ ZLTextStyleEntry::ZLTextStyleEntry(char *address) {
|
|||
}
|
||||
}
|
||||
|
||||
void ZLTextStyleEntry::apply(const ZLTextStyleEntry &entry) {
|
||||
for (int i = 0; i < NUMBER_OF_LENGTHS; ++i) {
|
||||
if (entry.lengthSupported((Length)i)) {
|
||||
myLengths[i] = entry.myLengths[i];
|
||||
myMask |= 1 << i;
|
||||
}
|
||||
}
|
||||
if (entry.alignmentTypeSupported()) {
|
||||
setAlignmentType(entry.alignmentType());
|
||||
}
|
||||
if (entry.mySupportedFontModifier) {
|
||||
myFontModifier &= ~entry.mySupportedFontModifier;
|
||||
myFontModifier |= (entry.myFontModifier & entry.mySupportedFontModifier);
|
||||
}
|
||||
if (entry.fontSizeSupported()) {
|
||||
setFontSizeMag(entry.fontSizeMag());
|
||||
}
|
||||
if (entry.fontFamilySupported()) {
|
||||
setFontFamily(entry.fontFamily());
|
||||
}
|
||||
}
|
||||
|
||||
const shared_ptr<ZLTextParagraphEntry> ZLTextParagraph::Iterator::entry() const {
|
||||
if (myEntry.isNull()) {
|
||||
switch (*myPointer) {
|
||||
|
|
|
@ -96,6 +96,8 @@ public:
|
|||
ZLTextStyleEntry(char *address);
|
||||
~ZLTextStyleEntry();
|
||||
|
||||
void apply(const ZLTextStyleEntry &entry);
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
bool lengthSupported(Length name) const;
|
||||
|
@ -336,7 +338,7 @@ inline ZLTextStyleEntry::~ZLTextStyleEntry() {}
|
|||
|
||||
inline ZLTextStyleEntry::Metrics::Metrics(int fontSize, int fontXHeight, int fullWidth, int fullHeight) : FontSize(fontSize), FontXHeight(fontXHeight), FullWidth(fullWidth), FullHeight(fullHeight) {}
|
||||
|
||||
inline bool ZLTextStyleEntry::isEmpty() const { return myMask == 0; }
|
||||
inline bool ZLTextStyleEntry::isEmpty() const { return myMask == 0 && mySupportedFontModifier == 0; }
|
||||
|
||||
inline bool ZLTextStyleEntry::lengthSupported(Length name) const { return (myMask & (1 << name)) != 0; }
|
||||
inline void ZLTextStyleEntry::setLength(Length name, short length, SizeUnit unit) {
|
||||
|
|
Loading…
Reference in a new issue