mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
standard namespace processing mechanish everywhere in native code
This commit is contained in:
parent
9d782369b3
commit
0a19a10264
6 changed files with 117 additions and 108 deletions
16
TODO.1.5
16
TODO.1.5
|
@ -7,17 +7,12 @@ litres: author photos
|
|||
|
||||
* the SJ book:
|
||||
** empty pages at start (in emulator)
|
||||
* Network library initialization in ProcessHyperlinkAction :(
|
||||
* "Use embedded fonts" option
|
||||
* "Scan hidden directories" option
|
||||
* Start position mark in navigation widget
|
||||
* fb2 native: footnote id depth
|
||||
* test opensearch parser
|
||||
* update series data for ePubs
|
||||
* fb2 plugins: compare native & java
|
||||
* update series data for ePubs (?)
|
||||
* language codes in ZLTextHyphenator and ZLLanguageUtil (java & cpp)
|
||||
* resources synchronization
|
||||
* in library: search more on network
|
||||
* CSS:
|
||||
** @page
|
||||
** @import
|
||||
|
@ -26,9 +21,14 @@ litres: author photos
|
|||
** embedded fonts
|
||||
* Two-page view
|
||||
* image size option (cover only full-screen, all full-screen, etc.)
|
||||
* resources synchronization
|
||||
|
||||
1.6+:
|
||||
1.5.1+:
|
||||
|
||||
* Network library initialization in ProcessHyperlinkAction :(
|
||||
* fb2 native: footnote id depth
|
||||
* fb2 plugins: compare native & java
|
||||
* in library: search more on network
|
||||
* Link sharing
|
||||
* предупреждение "не могу открыть зашифрованный файл"
|
||||
* CSS:
|
||||
|
@ -50,7 +50,7 @@ litres: author photos
|
|||
* <hr/> tag
|
||||
* Better file name for shared file
|
||||
* java fb2 plugin: use Base64InputStream technique
|
||||
* - namespaceMapChangedHandler
|
||||
* - namespaceMapChangedHandler (java)
|
||||
* rtf:
|
||||
** underline & strikethrough
|
||||
** cover?
|
||||
|
|
|
@ -49,89 +49,124 @@ static const std::string REFERENCE = "reference";
|
|||
static const std::string COVER = "cover";
|
||||
static const std::string COVER_IMAGE = "other.ms-coverimage-standard";
|
||||
|
||||
bool OEBBookReader::isOPFTag(const std::string &expected, const std::string &tag) const {
|
||||
return expected == tag && testTag(ZLXMLNamespace::OpenPackagingFormat, expected, tag);
|
||||
}
|
||||
|
||||
void OEBBookReader::startElementHandler(const char *tag, const char **xmlattributes) {
|
||||
std::string tagString = ZLUnicodeUtil::toLower(tag);
|
||||
if (!myOPFSchemePrefix.empty() &&
|
||||
ZLStringUtil::stringStartsWith(tagString, myOPFSchemePrefix)) {
|
||||
tagString = tagString.substr(myOPFSchemePrefix.length());
|
||||
}
|
||||
if (MANIFEST == tagString) {
|
||||
myState = READ_MANIFEST;
|
||||
} else if (SPINE == tagString) {
|
||||
const char *toc = attributeValue(xmlattributes, "toc");
|
||||
if (toc != 0) {
|
||||
myNCXTOCFileName = myIdToHref[toc];
|
||||
}
|
||||
myState = READ_SPINE;
|
||||
} else if (GUIDE == tagString) {
|
||||
myState = READ_GUIDE;
|
||||
} else if (TOUR == tagString) {
|
||||
myState = READ_TOUR;
|
||||
} else if ((myState == READ_MANIFEST) && (ITEM == tagString)) {
|
||||
const char *id = attributeValue(xmlattributes, "id");
|
||||
const char *href = attributeValue(xmlattributes, "href");
|
||||
if ((id != 0) && (href != 0)) {
|
||||
myIdToHref[id] = MiscUtil::decodeHtmlURL(href);
|
||||
}
|
||||
} else if ((myState == READ_SPINE) && (ITEMREF == tagString)) {
|
||||
const char *id = attributeValue(xmlattributes, "idref");
|
||||
if (id != 0) {
|
||||
const std::string &fileName = myIdToHref[id];
|
||||
if (!fileName.empty()) {
|
||||
myHtmlFileNames.push_back(fileName);
|
||||
|
||||
switch (myState) {
|
||||
case READ_NONE:
|
||||
if (isOPFTag(MANIFEST, tagString)) {
|
||||
myState = READ_MANIFEST;
|
||||
} else if (isOPFTag(SPINE, tagString)) {
|
||||
const char *toc = attributeValue(xmlattributes, "toc");
|
||||
if (toc != 0) {
|
||||
myNCXTOCFileName = myIdToHref[toc];
|
||||
}
|
||||
myState = READ_SPINE;
|
||||
} else if (isOPFTag(GUIDE, tagString)) {
|
||||
myState = READ_GUIDE;
|
||||
} else if (isOPFTag(TOUR, tagString)) {
|
||||
myState = READ_TOUR;
|
||||
}
|
||||
}
|
||||
} else if ((myState == READ_GUIDE) && (REFERENCE == tagString)) {
|
||||
const char *type = attributeValue(xmlattributes, "type");
|
||||
const char *title = attributeValue(xmlattributes, "title");
|
||||
const char *href = attributeValue(xmlattributes, "href");
|
||||
if (href != 0) {
|
||||
const std::string reference = MiscUtil::decodeHtmlURL(href);
|
||||
if (title != 0) {
|
||||
myGuideTOC.push_back(std::make_pair(std::string(title), reference));
|
||||
}
|
||||
if (type != 0) {
|
||||
if (COVER == type) {
|
||||
ZLFile imageFile(myFilePrefix + reference);
|
||||
myCoverFileName = imageFile.path();
|
||||
const std::string imageName = imageFile.name(false);
|
||||
shared_ptr<const ZLImage> image = XHTMLImageFinder().readImage(imageFile);
|
||||
if (!image.isNull()) {
|
||||
myModelReader.setMainTextModel();
|
||||
myModelReader.addImageReference(imageName, (short)0, true);
|
||||
myModelReader.addImage(imageName, image);
|
||||
myModelReader.insertEndOfSectionParagraph();
|
||||
} else {
|
||||
myCoverFileName.erase();
|
||||
}
|
||||
} else if (COVER_IMAGE == type) {
|
||||
ZLFile imageFile(myFilePrefix + reference);
|
||||
myCoverFileName = imageFile.path();
|
||||
const std::string imageName = imageFile.name(false);
|
||||
myModelReader.setMainTextModel();
|
||||
myModelReader.addImageReference(imageName, 0, true);
|
||||
myModelReader.addImage(imageName, new ZLFileImage(imageFile, "", 0));
|
||||
myModelReader.insertEndOfSectionParagraph();
|
||||
break;
|
||||
case READ_MANIFEST:
|
||||
if (isOPFTag(ITEM, tagString)) {
|
||||
const char *id = attributeValue(xmlattributes, "id");
|
||||
const char *href = attributeValue(xmlattributes, "href");
|
||||
if (id != 0 && href != 0) {
|
||||
myIdToHref[id] = MiscUtil::decodeHtmlURL(href);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ((myState == READ_TOUR) && (SITE == tagString)) {
|
||||
const char *title = attributeValue(xmlattributes, "title");
|
||||
const char *href = attributeValue(xmlattributes, "href");
|
||||
if ((title != 0) && (href != 0)) {
|
||||
myTourTOC.push_back(std::make_pair(title, MiscUtil::decodeHtmlURL(href)));
|
||||
}
|
||||
break;
|
||||
case READ_SPINE:
|
||||
if (isOPFTag(ITEMREF, tagString)) {
|
||||
const char *id = attributeValue(xmlattributes, "idref");
|
||||
if (id != 0) {
|
||||
const std::string &fileName = myIdToHref[id];
|
||||
if (!fileName.empty()) {
|
||||
myHtmlFileNames.push_back(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case READ_GUIDE:
|
||||
if (isOPFTag(REFERENCE, tagString)) {
|
||||
const char *type = attributeValue(xmlattributes, "type");
|
||||
const char *title = attributeValue(xmlattributes, "title");
|
||||
const char *href = attributeValue(xmlattributes, "href");
|
||||
if (href != 0) {
|
||||
const std::string reference = MiscUtil::decodeHtmlURL(href);
|
||||
if (title != 0) {
|
||||
myGuideTOC.push_back(std::make_pair(std::string(title), reference));
|
||||
}
|
||||
if (type != 0) {
|
||||
if (COVER == type) {
|
||||
ZLFile imageFile(myFilePrefix + reference);
|
||||
myCoverFileName = imageFile.path();
|
||||
const std::string imageName = imageFile.name(false);
|
||||
shared_ptr<const ZLImage> image = XHTMLImageFinder().readImage(imageFile);
|
||||
if (!image.isNull()) {
|
||||
myModelReader.setMainTextModel();
|
||||
myModelReader.addImageReference(imageName, (short)0, true);
|
||||
myModelReader.addImage(imageName, image);
|
||||
myModelReader.insertEndOfSectionParagraph();
|
||||
} else {
|
||||
myCoverFileName.erase();
|
||||
}
|
||||
} else if (COVER_IMAGE == type) {
|
||||
ZLFile imageFile(myFilePrefix + reference);
|
||||
myCoverFileName = imageFile.path();
|
||||
const std::string imageName = imageFile.name(false);
|
||||
myModelReader.setMainTextModel();
|
||||
myModelReader.addImageReference(imageName, 0, true);
|
||||
myModelReader.addImage(imageName, new ZLFileImage(imageFile, "", 0));
|
||||
myModelReader.insertEndOfSectionParagraph();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case READ_TOUR:
|
||||
if (isOPFTag(SITE, tagString)) {
|
||||
const char *title = attributeValue(xmlattributes, "title");
|
||||
const char *href = attributeValue(xmlattributes, "href");
|
||||
if ((title != 0) && (href != 0)) {
|
||||
myTourTOC.push_back(std::make_pair(title, MiscUtil::decodeHtmlURL(href)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OEBBookReader::endElementHandler(const char *tag) {
|
||||
std::string tagString = ZLUnicodeUtil::toLower(tag);
|
||||
if (!myOPFSchemePrefix.empty() &&
|
||||
ZLStringUtil::stringStartsWith(tagString, myOPFSchemePrefix)) {
|
||||
tagString = tagString.substr(myOPFSchemePrefix.length());
|
||||
}
|
||||
if ((MANIFEST == tagString) || (SPINE == tagString) || (GUIDE == tagString) || (TOUR == tagString)) {
|
||||
myState = READ_NONE;
|
||||
|
||||
switch (myState) {
|
||||
case READ_MANIFEST:
|
||||
if (isOPFTag(MANIFEST, tagString)) {
|
||||
myState = READ_NONE;
|
||||
}
|
||||
break;
|
||||
case READ_SPINE:
|
||||
if (isOPFTag(SPINE, tagString)) {
|
||||
myState = READ_NONE;
|
||||
}
|
||||
break;
|
||||
case READ_GUIDE:
|
||||
if (isOPFTag(GUIDE, tagString)) {
|
||||
myState = READ_NONE;
|
||||
}
|
||||
break;
|
||||
case READ_TOUR:
|
||||
if (isOPFTag(TOUR, tagString)) {
|
||||
myState = READ_NONE;
|
||||
}
|
||||
break;
|
||||
case READ_NONE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,21 +252,6 @@ bool OEBBookReader::processNamespaces() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void OEBBookReader::namespaceListChangedHandler() {
|
||||
const std::map<std::string,std::string> &namespaceMap = namespaces();
|
||||
std::map<std::string,std::string>::const_iterator iter = namespaceMap.begin();
|
||||
for (; iter != namespaceMap.end(); ++iter) {
|
||||
if (iter->second == ZLXMLNamespace::OpenPackagingFormat) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (iter != namespaceMap.end()) {
|
||||
myOPFSchemePrefix = iter->first + ":";
|
||||
} else {
|
||||
myOPFSchemePrefix.erase();
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::string> &OEBBookReader::externalDTDs() const {
|
||||
return EntityFilesCollector::Instance().externalDTDs("xhtml");
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ private:
|
|||
void startElementHandler(const char *tag, const char **attributes);
|
||||
void endElementHandler(const char *tag);
|
||||
bool processNamespaces() const;
|
||||
void namespaceListChangedHandler();
|
||||
bool isOPFTag(const std::string &expected, const std::string &tag) const;
|
||||
const std::vector<std::string> &externalDTDs() const;
|
||||
|
||||
void generateTOC(const XHTMLReader &xhtmlReader);
|
||||
|
@ -57,8 +57,6 @@ private:
|
|||
BookReader myModelReader;
|
||||
ReaderState myState;
|
||||
|
||||
std::string myOPFSchemePrefix;
|
||||
|
||||
std::string myFilePrefix;
|
||||
std::map<std::string,std::string> myIdToHref;
|
||||
std::vector<std::string> myHtmlFileNames;
|
||||
|
|
|
@ -71,9 +71,6 @@ void ZLXMLReader::endElementHandler(const char*) {
|
|||
void ZLXMLReader::characterDataHandler(const char*, size_t) {
|
||||
}
|
||||
|
||||
void ZLXMLReader::namespaceListChangedHandler() {
|
||||
}
|
||||
|
||||
const ZLXMLReader::nsMap &ZLXMLReader::namespaces() const {
|
||||
return *myNamespaces.back();
|
||||
}
|
||||
|
|
|
@ -90,7 +90,6 @@ protected:
|
|||
virtual void endElementHandler(const char *tag);
|
||||
virtual void characterDataHandler(const char *text, size_t len);
|
||||
virtual bool processNamespaces() const;
|
||||
virtual void namespaceListChangedHandler();
|
||||
virtual const std::vector<std::string> &externalDTDs() const;
|
||||
virtual void collectExternalEntities(std::map<std::string,std::string> &entityMap);
|
||||
|
||||
|
|
|
@ -56,8 +56,6 @@ void ZLXMLReaderInternal::fStartElementHandler(void *userData, const char *name,
|
|||
}
|
||||
if (count == 0) {
|
||||
reader.myNamespaces.push_back(reader.myNamespaces.back());
|
||||
} else {
|
||||
reader.namespaceListChangedHandler();
|
||||
}
|
||||
}
|
||||
reader.startElementHandler(name, attributes);
|
||||
|
@ -71,9 +69,6 @@ void ZLXMLReaderInternal::fEndElementHandler(void *userData, const char *name) {
|
|||
if (reader.processNamespaces()) {
|
||||
shared_ptr<std::map<std::string,std::string> > oldMap = reader.myNamespaces.back();
|
||||
reader.myNamespaces.pop_back();
|
||||
if (reader.myNamespaces.back() != oldMap) {
|
||||
reader.namespaceListChangedHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue