1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 01:39:18 +02:00

fixed <ul>/<ol> top/bottom margin behaviour

This commit is contained in:
Nikolay Pultsin 2014-09-18 23:38:51 +01:00
parent aae8cd8365
commit 83e3cb355d
5 changed files with 60 additions and 7 deletions

View file

@ -7,6 +7,7 @@
===== 2.1.4 (Sep ??, 2014) ===== ===== 2.1.4 (Sep ??, 2014) =====
* (planned) Fixed authors list/tags list editing * (planned) Fixed authors list/tags list editing
* CSS: fixed <ul>/<ol> top/bottom margin behaviour
===== 2.1.3 (Sep 18, 2014) ===== ===== 2.1.3 (Sep 18, 2014) =====
* CSS: fixed multiple entries for same selector * CSS: fixed multiple entries for same selector

View file

@ -329,17 +329,25 @@ XHTMLTagListAction::XHTMLTagListAction(int startIndex) : myStartIndex(startIndex
void XHTMLTagListAction::doAtStart(XHTMLReader &reader, const char**) { void XHTMLTagListAction::doAtStart(XHTMLReader &reader, const char**) {
reader.myListNumStack.push(myStartIndex); reader.myListNumStack.push(myStartIndex);
beginParagraph(reader);
} }
void XHTMLTagListAction::doAtEnd(XHTMLReader &reader) { void XHTMLTagListAction::doAtEnd(XHTMLReader &reader) {
endParagraph(reader);
if (!reader.myListNumStack.empty()) { if (!reader.myListNumStack.empty()) {
reader.myListNumStack.pop(); reader.myListNumStack.pop();
} }
} }
void XHTMLTagItemAction::doAtStart(XHTMLReader &reader, const char**) { void XHTMLTagItemAction::doAtStart(XHTMLReader &reader, const char**) {
endParagraph(reader); bool restart = true;
beginParagraph(reader); if (reader.myTagDataStack.size() >= 2) {
restart = reader.myTagDataStack[reader.myTagDataStack.size() - 2]->ChildCount > 1;
}
if (restart) {
endParagraph(reader);
beginParagraph(reader);
}
if (!reader.myListNumStack.empty()) { if (!reader.myListNumStack.empty()) {
bookReader(reader).addFixedHSpace(3 * reader.myListNumStack.size()); bookReader(reader).addFixedHSpace(3 * reader.myListNumStack.size());
int &index = reader.myListNumStack.top(); int &index = reader.myListNumStack.top();
@ -355,7 +363,6 @@ void XHTMLTagItemAction::doAtStart(XHTMLReader &reader, const char**) {
} }
void XHTMLTagItemAction::doAtEnd(XHTMLReader &reader) { void XHTMLTagItemAction::doAtEnd(XHTMLReader &reader) {
endParagraph(reader);
} }
bool XHTMLTagVideoAction::isEnabled(XHTMLReadingState state) { bool XHTMLTagVideoAction::isEnabled(XHTMLReadingState state) {
@ -673,7 +680,7 @@ bool XHTMLReader::readFile(const ZLFile &file, const std::string &referenceName)
bool XHTMLReader::addTextStyleEntry(const std::string tag, const std::string aClass) { bool XHTMLReader::addTextStyleEntry(const std::string tag, const std::string aClass) {
shared_ptr<ZLTextStyleEntry> entry = myStyleSheetTable.control(tag, aClass); shared_ptr<ZLTextStyleEntry> entry = myStyleSheetTable.control(tag, aClass);
if (!entry.isNull()) { if (!entry.isNull()) {
addTextStyleEntry(*entry); addTextStyleEntry(*(entry->start()));
myTagDataStack.back()->StyleEntries.push_back(entry); myTagDataStack.back()->StyleEntries.push_back(entry);
return true; return true;
} }
@ -725,6 +732,9 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes)
return; return;
} }
if (!myTagDataStack.empty()) {
myTagDataStack.back()->ChildCount += 1;
}
myTagDataStack.push_back(new TagData()); myTagDataStack.push_back(new TagData());
static const std::string HASH = "#"; static const std::string HASH = "#";
@ -783,17 +793,28 @@ void XHTMLReader::endElementHandler(const char *tag) {
return; return;
} }
const TagData &tagData = *myTagDataStack.back();
const std::vector<shared_ptr<ZLTextStyleEntry> > &entries = tagData.StyleEntries;
size_t entryCount = entries.size();
for (std::vector<shared_ptr<ZLTextStyleEntry> >::const_iterator jt = entries.begin(); jt != entries.end(); ++jt) {
shared_ptr<ZLTextStyleEntry> endEntry = (*jt)->end();
if (!endEntry.isNull()) {
addTextStyleEntry(*endEntry);
++entryCount;
}
}
XHTMLTagAction *action = getAction(sTag); XHTMLTagAction *action = getAction(sTag);
if (action != 0 && action->isEnabled(myReadState)) { if (action != 0 && action->isEnabled(myReadState)) {
action->doAtEnd(*this); action->doAtEnd(*this);
myNewParagraphInProgress = false; myNewParagraphInProgress = false;
} }
for (int i = myTagDataStack.back()->StyleEntries.size(); i > 0; --i) { for (; entryCount > 0; --entryCount) {
myModelReader.addStyleCloseEntry(); myModelReader.addStyleCloseEntry();
} }
if (myTagDataStack.back()->PageBreakAfter) { if (tagData.PageBreakAfter) {
myModelReader.insertEndOfSectionParagraph(); myModelReader.insertEndOfSectionParagraph();
} }
@ -811,7 +832,7 @@ void XHTMLReader::beginParagraph(bool restarted) {
const std::vector<shared_ptr<ZLTextStyleEntry> > &entries = (*it)->StyleEntries; const std::vector<shared_ptr<ZLTextStyleEntry> > &entries = (*it)->StyleEntries;
bool inheritedOnly = !restarted || it + 1 != myTagDataStack.end(); bool inheritedOnly = !restarted || it + 1 != myTagDataStack.end();
for (std::vector<shared_ptr<ZLTextStyleEntry> >::const_iterator jt = entries.begin(); jt != entries.end(); ++jt) { for (std::vector<shared_ptr<ZLTextStyleEntry> >::const_iterator jt = entries.begin(); jt != entries.end(); ++jt) {
shared_ptr<ZLTextStyleEntry> entry = inheritedOnly ? (*jt)->inherited() : *jt; shared_ptr<ZLTextStyleEntry> entry = inheritedOnly ? (*jt)->inherited() : (*jt)->start();
addTextStyleEntry(*entry); addTextStyleEntry(*entry);
} }
} }
@ -929,3 +950,6 @@ const std::string &XHTMLReader::fileAlias(const std::string &fileName) const {
it = myFileNumbers.find(correctedFileName); it = myFileNumbers.find(correctedFileName);
return it->second; return it->second;
} }
XHTMLReader::TagData::TagData() : PageBreakAfter(false), ChildCount(0) {
}

View file

@ -70,6 +70,9 @@ public:
std::vector<FBTextKind> TextKinds; std::vector<FBTextKind> TextKinds;
std::vector<shared_ptr<ZLTextStyleEntry> > StyleEntries; std::vector<shared_ptr<ZLTextStyleEntry> > StyleEntries;
bool PageBreakAfter; bool PageBreakAfter;
size_t ChildCount;
TagData();
}; };
public: public:

View file

@ -19,6 +19,29 @@
#include "ZLTextStyleEntry.h" #include "ZLTextStyleEntry.h"
shared_ptr<ZLTextStyleEntry> ZLTextStyleEntry::start() const {
ZLTextStyleEntry *clone = new ZLTextStyleEntry(myEntryKind);
clone->myFeatureMask = myFeatureMask & ~(1 << LENGTH_SPACE_AFTER);
for (int i = 0; i < NUMBER_OF_LENGTHS; ++i) {
clone->myLengths[i] = myLengths[i];
}
clone->myAlignmentType = myAlignmentType;
clone->mySupportedFontModifier = mySupportedFontModifier;
clone->myFontModifier = myFontModifier;
clone->myFontFamilies = myFontFamilies;
return clone;
}
shared_ptr<ZLTextStyleEntry> ZLTextStyleEntry::end() const {
if ((myFeatureMask & (1 << LENGTH_SPACE_AFTER)) == 0) {
return 0;
}
ZLTextStyleEntry *clone = new ZLTextStyleEntry(myEntryKind);
clone->myFeatureMask = 1 << LENGTH_SPACE_AFTER;
clone->myLengths[LENGTH_SPACE_AFTER] = myLengths[LENGTH_SPACE_AFTER];
return clone;
}
shared_ptr<ZLTextStyleEntry> ZLTextStyleEntry::inherited() const { shared_ptr<ZLTextStyleEntry> ZLTextStyleEntry::inherited() const {
ZLTextStyleEntry *clone = new ZLTextStyleEntry(myEntryKind); ZLTextStyleEntry *clone = new ZLTextStyleEntry(myEntryKind);
clone->myFeatureMask = myFeatureMask & ~(1 << LENGTH_SPACE_BEFORE) & ~(1 << LENGTH_SPACE_AFTER); clone->myFeatureMask = myFeatureMask & ~(1 << LENGTH_SPACE_BEFORE) & ~(1 << LENGTH_SPACE_AFTER);

View file

@ -102,6 +102,8 @@ public:
const std::vector<std::string> &fontFamilies() const; const std::vector<std::string> &fontFamilies() const;
void setFontFamilies(const std::vector<std::string> &fontFamilies); void setFontFamilies(const std::vector<std::string> &fontFamilies);
shared_ptr<ZLTextStyleEntry> start() const;
shared_ptr<ZLTextStyleEntry> end() const;
shared_ptr<ZLTextStyleEntry> inherited() const; shared_ptr<ZLTextStyleEntry> inherited() const;
private: private: