mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +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:
parent
9e771a22ed
commit
ccfdf0cf04
6 changed files with 46 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
||||||
* Popup dictionary (https://play.google.com/store/apps/details?id=com.barisatamer.popupdictionary) integration
|
* Popup dictionary (https://play.google.com/store/apps/details?id=com.barisatamer.popupdictionary) integration
|
||||||
* Catalan localization (by Alfonso Montero)
|
* Catalan localization (by Alfonso Montero)
|
||||||
* Open 'additional links in network library' with correct orientation
|
* 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) =====
|
===== 1.6.9 (Jan 03, 2013) =====
|
||||||
* Added Bulgarian translation (by Ники Арсов)
|
* Added Bulgarian translation (by Ники Арсов)
|
||||||
|
|
|
@ -80,6 +80,16 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
|
||||||
}
|
}
|
||||||
myModelReader.beginParagraph();
|
myModelReader.beginParagraph();
|
||||||
break;
|
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:
|
case _V:
|
||||||
myModelReader.pushKind(VERSE);
|
myModelReader.pushKind(VERSE);
|
||||||
myModelReader.beginParagraph();
|
myModelReader.beginParagraph();
|
||||||
|
@ -163,6 +173,9 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
|
||||||
case _A:
|
case _A:
|
||||||
{
|
{
|
||||||
const char *ref = attributeValue(xmlattributes, myHrefPredicate);
|
const char *ref = attributeValue(xmlattributes, myHrefPredicate);
|
||||||
|
if (ref == 0) {
|
||||||
|
ref = attributeValue(xmlattributes, myBrokenHrefPredicate);
|
||||||
|
}
|
||||||
if (ref != 0) {
|
if (ref != 0) {
|
||||||
if (ref[0] == '#') {
|
if (ref[0] == '#') {
|
||||||
const char *type = attributeValue(xmlattributes, "type");
|
const char *type = attributeValue(xmlattributes, "type");
|
||||||
|
@ -186,6 +199,9 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
|
||||||
case _IMAGE:
|
case _IMAGE:
|
||||||
{
|
{
|
||||||
const char *ref = attributeValue(xmlattributes, myHrefPredicate);
|
const char *ref = attributeValue(xmlattributes, myHrefPredicate);
|
||||||
|
if (ref == 0) {
|
||||||
|
ref = attributeValue(xmlattributes, myBrokenHrefPredicate);
|
||||||
|
}
|
||||||
const char *vOffset = attributeValue(xmlattributes, "voffset");
|
const char *vOffset = attributeValue(xmlattributes, "voffset");
|
||||||
char offset = (vOffset != 0) ? atoi(vOffset) : 0;
|
char offset = (vOffset != 0) ? atoi(vOffset) : 0;
|
||||||
if ((ref != 0) && (*ref == '#')) {
|
if ((ref != 0) && (*ref == '#')) {
|
||||||
|
@ -232,6 +248,7 @@ void FB2BookReader::startElementHandler(int tag, const char **xmlattributes) {
|
||||||
void FB2BookReader::endElementHandler(int tag) {
|
void FB2BookReader::endElementHandler(int tag) {
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case _P:
|
case _P:
|
||||||
|
case _LI:
|
||||||
myModelReader.endParagraph();
|
myModelReader.endParagraph();
|
||||||
break;
|
break;
|
||||||
case _V:
|
case _V:
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#include "FB2Reader.h"
|
#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) {
|
void FB2Reader::startElementHandler(const char *t, const char **attributes) {
|
||||||
|
@ -38,6 +38,7 @@ void FB2Reader::endElementHandler(const char *t) {
|
||||||
|
|
||||||
static const FB2Reader::Tag TAGS[] = {
|
static const FB2Reader::Tag TAGS[] = {
|
||||||
{"p", FB2Reader::_P},
|
{"p", FB2Reader::_P},
|
||||||
|
{"li", FB2Reader::_LI},
|
||||||
{"subtitle", FB2Reader::_SUBTITLE},
|
{"subtitle", FB2Reader::_SUBTITLE},
|
||||||
{"cite", FB2Reader::_CITE},
|
{"cite", FB2Reader::_CITE},
|
||||||
{"text-author", FB2Reader::_TEXT_AUTHOR},
|
{"text-author", FB2Reader::_TEXT_AUTHOR},
|
||||||
|
@ -54,7 +55,9 @@ static const FB2Reader::Tag TAGS[] = {
|
||||||
{"code", FB2Reader::_CODE},
|
{"code", FB2Reader::_CODE},
|
||||||
{"strikethrough", FB2Reader::_STRIKETHROUGH},
|
{"strikethrough", FB2Reader::_STRIKETHROUGH},
|
||||||
{"strong", FB2Reader::_STRONG},
|
{"strong", FB2Reader::_STRONG},
|
||||||
|
{"b", FB2Reader::_STRONG},
|
||||||
{"emphasis", FB2Reader::_EMPHASIS},
|
{"emphasis", FB2Reader::_EMPHASIS},
|
||||||
|
{"i", FB2Reader::_EMPHASIS},
|
||||||
{"a", FB2Reader::_A},
|
{"a", FB2Reader::_A},
|
||||||
{"image", FB2Reader::_IMAGE},
|
{"image", FB2Reader::_IMAGE},
|
||||||
{"binary", FB2Reader::_BINARY},
|
{"binary", FB2Reader::_BINARY},
|
||||||
|
|
|
@ -45,6 +45,7 @@ private:
|
||||||
public:
|
public:
|
||||||
enum TagCode {
|
enum TagCode {
|
||||||
_P,
|
_P,
|
||||||
|
_LI,
|
||||||
_SUBTITLE,
|
_SUBTITLE,
|
||||||
_CITE,
|
_CITE,
|
||||||
_TEXT_AUTHOR,
|
_TEXT_AUTHOR,
|
||||||
|
@ -87,6 +88,7 @@ protected:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const FullNamePredicate myHrefPredicate;
|
const FullNamePredicate myHrefPredicate;
|
||||||
|
const BrokenNamePredicate myBrokenHrefPredicate;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline FB2Reader::~FB2Reader() {}
|
inline FB2Reader::~FB2Reader() {}
|
||||||
|
|
|
@ -198,6 +198,17 @@ bool ZLXMLReader::FullNamePredicate::accepts(const ZLXMLReader &reader, const st
|
||||||
name.substr(index + 1) == myName;
|
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 {
|
const char *ZLXMLReader::attributeValue(const char **xmlattributes, const NamePredicate &predicate) const {
|
||||||
while (*xmlattributes != 0) {
|
while (*xmlattributes != 0) {
|
||||||
bool useNext = predicate.accepts(*this, *xmlattributes);
|
bool useNext = predicate.accepts(*this, *xmlattributes);
|
||||||
|
|
|
@ -65,6 +65,17 @@ public:
|
||||||
const std::string myName;
|
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:
|
protected:
|
||||||
ZLXMLReader(const char *encoding = 0);
|
ZLXMLReader(const char *encoding = 0);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue