1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 02:09:35 +02:00

* Some incorrect FB2 files support (li/i/b tags, href attributes with no namespace and with unknown namespace ids)

This commit is contained in:
Nikolay Pultsin 2013-02-17 03:38:57 +04:00
parent 9e771a22ed
commit ccfdf0cf04
6 changed files with 46 additions and 1 deletions

View file

@ -6,6 +6,7 @@
* Popup dictionary (https://play.google.com/store/apps/details?id=com.barisatamer.popupdictionary) integration
* Catalan localization (by Alfonso Montero)
* Open 'additional links in network library' with correct orientation
* Some incorrect FB2 files support (li/i/b tags, href attributes with no namespace and with unknown namespace ids) -- e.g. CoolReader manual
===== 1.6.9 (Jan 03, 2013) =====
* Added Bulgarian translation (by Ники Арсов)

View file

@ -80,6 +80,16 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
}
myModelReader.beginParagraph();
break;
case _LI:
{
if (mySectionStarted) {
mySectionStarted = false;
}
myModelReader.beginParagraph();
static const std::string BULLET_NBSP = "\xE2\x80\xA2\xC0\xA0";
myModelReader.addData(BULLET_NBSP);
break;
}
case _V:
myModelReader.pushKind(VERSE);
myModelReader.beginParagraph();
@ -163,6 +173,9 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
case _A:
{
const char *ref = attributeValue(xmlattributes, myHrefPredicate);
if (ref == 0) {
ref = attributeValue(xmlattributes, myBrokenHrefPredicate);
}
if (ref != 0) {
if (ref[0] == '#') {
const char *type = attributeValue(xmlattributes, "type");
@ -186,6 +199,9 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
case _IMAGE:
{
const char *ref = attributeValue(xmlattributes, myHrefPredicate);
if (ref == 0) {
ref = attributeValue(xmlattributes, myBrokenHrefPredicate);
}
const char *vOffset = attributeValue(xmlattributes, "voffset");
char offset = (vOffset != 0) ? atoi(vOffset) : 0;
if ((ref != 0) && (*ref == '#')) {
@ -232,6 +248,7 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
void FB2BookReader::endElementHandler(int tag) {
switch (tag) {
case _P:
case _LI:
myModelReader.endParagraph();
break;
case _V:

View file

@ -25,7 +25,7 @@
#include "FB2Reader.h"
FB2Reader::FB2Reader() : myHrefPredicate(ZLXMLNamespace::XLink, "href") {
FB2Reader::FB2Reader() : myHrefPredicate(ZLXMLNamespace::XLink, "href"), myBrokenHrefPredicate("href") {
}
void FB2Reader::startElementHandler(const char *t, const char **attributes) {
@ -38,6 +38,7 @@ void FB2Reader::endElementHandler(const char *t) {
static const FB2Reader::Tag TAGS[] = {
{"p", FB2Reader::_P},
{"li", FB2Reader::_LI},
{"subtitle", FB2Reader::_SUBTITLE},
{"cite", FB2Reader::_CITE},
{"text-author", FB2Reader::_TEXT_AUTHOR},
@ -54,7 +55,9 @@ static const FB2Reader::Tag TAGS[] = {
{"code", FB2Reader::_CODE},
{"strikethrough", FB2Reader::_STRIKETHROUGH},
{"strong", FB2Reader::_STRONG},
{"b", FB2Reader::_STRONG},
{"emphasis", FB2Reader::_EMPHASIS},
{"i", FB2Reader::_EMPHASIS},
{"a", FB2Reader::_A},
{"image", FB2Reader::_IMAGE},
{"binary", FB2Reader::_BINARY},

View file

@ -45,6 +45,7 @@ private:
public:
enum TagCode {
_P,
_LI,
_SUBTITLE,
_CITE,
_TEXT_AUTHOR,
@ -87,6 +88,7 @@ protected:
protected:
const FullNamePredicate myHrefPredicate;
const BrokenNamePredicate myBrokenHrefPredicate;
};
inline FB2Reader::~FB2Reader() {}

View file

@ -198,6 +198,17 @@ bool ZLXMLReader::FullNamePredicate::accepts(const ZLXMLReader &reader, const st
name.substr(index + 1) == myName;
}
ZLXMLReader::BrokenNamePredicate::BrokenNamePredicate(const std::string &name) : myName(name) {
}
bool ZLXMLReader::BrokenNamePredicate::accepts(const ZLXMLReader &reader, const char *name) const {
return accepts(reader, std::string(name));
}
bool ZLXMLReader::BrokenNamePredicate::accepts(const ZLXMLReader &reader, const std::string &name) const {
return myName == name.substr(name.find(':') + 1);
}
const char *ZLXMLReader::attributeValue(const char **xmlattributes, const NamePredicate &predicate) const {
while (*xmlattributes != 0) {
bool useNext = predicate.accepts(*this, *xmlattributes);

View file

@ -65,6 +65,17 @@ public:
const std::string myName;
};
class BrokenNamePredicate : public NamePredicate {
public:
BrokenNamePredicate(const std::string &name);
bool accepts(const ZLXMLReader &reader, const char *name) const;
bool accepts(const ZLXMLReader &reader, const std::string &name) const;
private:
const std::string myName;
};
protected:
ZLXMLReader(const char *encoding = 0);