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);
|
return readDocument(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XHTMLReader::addStyleEntry(const std::string &tag, const std::string &aClass) {
|
shared_ptr<ZLTextStyleEntry> XHTMLReader::addStyleEntry(shared_ptr<ZLTextStyleEntry> entry, shared_ptr<ZLTextStyleEntry> styleEntry) {
|
||||||
shared_ptr<ZLTextStyleEntry> entry = myStyleSheetTable.control(tag, aClass);
|
if (!styleEntry.isNull() && !styleEntry->isEmpty()) {
|
||||||
if (!entry.isNull()) {
|
if (entry.isNull()) entry = new ZLTextStyleEntry;
|
||||||
myModelReader.addControl(*entry);
|
entry->apply(*styleEntry);
|
||||||
myStyleEntryStack.push_back(entry);
|
|
||||||
}
|
}
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XHTMLReader::startElementHandler(const char *tag, const char **attributes) {
|
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);
|
action->doAtStart(*this, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int sizeBefore = myStyleEntryStack.size();
|
shared_ptr<ZLTextStyleEntry> entry;
|
||||||
addStyleEntry(sTag, "");
|
entry = addStyleEntry(entry, myStyleSheetTable.control(sTag, ""));
|
||||||
addStyleEntry("", sClass);
|
entry = addStyleEntry(entry, myStyleSheetTable.control("", sClass));
|
||||||
addStyleEntry(sTag, sClass);
|
entry = addStyleEntry(entry, myStyleSheetTable.control(sTag, sClass));
|
||||||
const char *style = attributeValue(attributes, "style");
|
const char *style = attributeValue(attributes, "style");
|
||||||
if (style != 0) {
|
if (style != 0) {
|
||||||
shared_ptr<ZLTextStyleEntry> entry = myStyleParser.parseString(style);
|
entry = addStyleEntry(entry, myStyleParser.parseString(style));
|
||||||
|
}
|
||||||
|
if (!entry.isNull()) {
|
||||||
myModelReader.addControl(*entry);
|
myModelReader.addControl(*entry);
|
||||||
myStyleEntryStack.push_back(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) {
|
void XHTMLReader::endElementHandler(const char *tag) {
|
||||||
|
|
|
@ -73,7 +73,7 @@ private:
|
||||||
|
|
||||||
void beginParagraph();
|
void beginParagraph();
|
||||||
void endParagraph();
|
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:
|
private:
|
||||||
BookReader &myModelReader;
|
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 {
|
const shared_ptr<ZLTextParagraphEntry> ZLTextParagraph::Iterator::entry() const {
|
||||||
if (myEntry.isNull()) {
|
if (myEntry.isNull()) {
|
||||||
switch (*myPointer) {
|
switch (*myPointer) {
|
||||||
|
|
|
@ -96,6 +96,8 @@ public:
|
||||||
ZLTextStyleEntry(char *address);
|
ZLTextStyleEntry(char *address);
|
||||||
~ZLTextStyleEntry();
|
~ZLTextStyleEntry();
|
||||||
|
|
||||||
|
void apply(const ZLTextStyleEntry &entry);
|
||||||
|
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|
||||||
bool lengthSupported(Length name) 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 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 bool ZLTextStyleEntry::lengthSupported(Length name) const { return (myMask & (1 << name)) != 0; }
|
||||||
inline void ZLTextStyleEntry::setLength(Length name, short length, SizeUnit unit) {
|
inline void ZLTextStyleEntry::setLength(Length name, short length, SizeUnit unit) {
|
||||||
|
|
Loading…
Reference in a new issue