void XHTMLTagLinkAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { static const std::string REL = "stylesheet"; const char *rel = reader.attributeValue(xmlattributes, "rel"); if ((rel == 0) || (REL != rel)) { return; } static const std::string TYPE = "text/css"; const char *type = reader.attributeValue(xmlattributes, "type"); if ((type == 0) || (TYPE != type)) { return; } const char *href = reader.attributeValue(xmlattributes, "href"); if (href == 0) { return; } ZLLogger::Instance().println("CSS", "style file: " + reader.myPathPrefix + MiscUtil::decodeHtmlURL(href)); shared_ptr<ZLInputStream> cssStream = ZLFile(reader.myPathPrefix + MiscUtil::decodeHtmlURL(href)).inputStream(); if (cssStream.isNull()) { return; } ZLLogger::Instance().println("CSS", "parsing file"); StyleSheetTableParser parser(reader.myStyleSheetTable); parser.parse(*cssStream); //reader.myStyleSheetTable.dump(); }
void XHTMLTagParagraphAction::doAtStart(XHTMLReader &reader, const char**) { if (!reader.myNewParagraphInProgress) { reader.pushTextKind(myTextKind); reader.beginParagraph(); reader.myNewParagraphInProgress = true; } }
void XHTMLTagImageAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { // Ignore transparent images if (!reader.myParseStack.back().opacity) { return; } const char *fileName = reader.attributeValue(xmlattributes, *myPredicate); if (fileName == 0) { return; } const std::string fullfileName = pathPrefix(reader) + MiscUtil::decodeHtmlURL(fileName); if (!ZLFile(fullfileName).exists()) { return; } if ((strlen(fileName) > 2) && strncmp(fileName, "./", 2) == 0) { fileName +=2; } reader.myParseStack.back().kind = IMAGE; reader.haveContent(); reader.myModelReader.addImageReference(fullfileName); reader.myModelReader.addImage(fullfileName, new ZLFileImage(ZLFile(fullfileName), 0)); }
void XHTMLTagSourceAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { const char *mime = reader.attributeValue(xmlattributes, "type"); const char *href = reader.attributeValue(xmlattributes, "src"); if (mime != 0 && href != 0) { reader.myVideoEntry->addSource( mime, ZLFile(pathPrefix(reader) + MiscUtil::decodeHtmlURL(href)).path() ); } }
void XHTMLTagHyperlinkAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { const char *href = reader.attributeValue(xmlattributes, "href"); if (href != 0) { const std::string link = (*href == '#') ? (reader.myReferenceName + href) : href; FBTextKind hyperlinkType = MiscUtil::isReference(link) ? EXTERNAL_HYPERLINK : INTERNAL_HYPERLINK; myHyperlinkStack.push(hyperlinkType); bookReader(reader).addHyperlinkControl(hyperlinkType, link); } else { myHyperlinkStack.push(REGULAR); } const char *name = reader.attributeValue(xmlattributes, "name"); if (name != 0) { bookReader(reader).addHyperlinkLabel(reader.myReferenceName + "#" + name); } }
void XHTMLTagImageAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { const char *fileName = reader.attributeValue(xmlattributes, *myPredicate); if (fileName == 0) { return; } const std::string fullfileName = pathPrefix(reader) + MiscUtil::decodeHtmlURL(fileName); ZLFile imageFile(fullfileName); if (!imageFile.exists()) { return; } bool flag = bookReader(reader).paragraphIsOpen(); if (flag) { endParagraph(reader); } if (std::strlen(fileName) > 2 && std::strncmp(fileName, "./", 2) == 0) { fileName +=2; } bookReader(reader).addImageReference(fullfileName); bookReader(reader).addImage(fullfileName, new ZLFileImage(ZLFile(fullfileName), 0)); if (flag) { beginParagraph(reader); } }
void XHTMLTagParagraphWithControlAction::doAtStart(XHTMLReader &reader, const char**) { if (myControl == TITLE && bookReader(reader).model().bookTextModel()->paragraphsNumber() > 1) { bookReader(reader).insertEndOfSectionParagraph(); } reader.pushTextKind(myControl); beginParagraph(reader); }
void XHTMLTagImageAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { const char *fileName = reader.attributeValue(xmlattributes, *myPredicate); if (fileName == 0) { return; } const std::string fullfileName = pathPrefix(reader) + MiscUtil::decodeHtmlURL(fileName); ZLFile imageFile(fullfileName); if (!imageFile.exists()) { return; } const bool flagParagraphIsOpen = bookReader(reader).paragraphIsOpen(); if (flagParagraphIsOpen) { if (reader.myCurrentParagraphIsEmpty) { bookReader(reader).addControl(IMAGE, true); } else { endParagraph(reader); } } const std::string imageName = imageFile.name(false); bookReader(reader).addImageReference(imageName, 0, reader.myMarkNextImageAsCover); bookReader(reader).addImage(imageName, new ZLFileImage(imageFile, "", 0, 0, reader.myEncryptionMap->info(imageFile.path()))); reader.myMarkNextImageAsCover = false; if (flagParagraphIsOpen && reader.myCurrentParagraphIsEmpty) { bookReader(reader).addControl(IMAGE, false); endParagraph(reader); } }
void XHTMLTagStyleAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { const char *type = reader.attributeValue(xmlattributes, "type"); if (!type || strcmp(type, "text/css")) { return; } if (reader.myReadState == XHTMLReader::READ_NOTHING) { reader.myReadState = XHTMLReader::READ_STYLE; reader.myTableParser = new StyleSheetTableParser(reader.myStyleSheetTable); } }
void XHTMLTagLinkAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { static const std::string REL = "stylesheet"; const char *rel = reader.attributeValue(xmlattributes, "rel"); if (rel == 0 || REL != rel) { return; } static const std::string TYPE = "text/css"; const char *type = reader.attributeValue(xmlattributes, "type"); if (type == 0 || TYPE != type) { return; } const char *href = reader.attributeValue(xmlattributes, "href"); if (href == 0) { return; } std::string cssFilePath = reader.myPathPrefix + MiscUtil::decodeHtmlURL(href); //ZLLogger::Instance().registerClass("CSS"); ZLLogger::Instance().println("CSS", "style file: " + cssFilePath); const ZLFile cssFile(cssFilePath); cssFilePath = cssFile.path(); shared_ptr<StyleSheetParserWithCache> parser = reader.myFileParsers[cssFilePath]; if (parser.isNull()) { parser = new StyleSheetParserWithCache( cssFile, MiscUtil::htmlDirectoryPrefix(cssFilePath), 0, reader.myEncryptionMap ); reader.myFileParsers[cssFilePath] = parser; ZLLogger::Instance().println("CSS", "creating stream"); shared_ptr<ZLInputStream> cssStream = cssFile.inputStream(reader.myEncryptionMap); if (!cssStream.isNull()) { ZLLogger::Instance().println("CSS", "parsing file"); parser->parseStream(cssStream); } } parser->applyToTables(reader.myStyleSheetTable, *reader.myFontMap); }
void XHTMLTagStyleAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { static const std::string TYPE = "text/css"; const char *type = reader.attributeValue(xmlattributes, "type"); if ((type == 0) || (TYPE != type)) { return; } if (reader.myReadState == XHTMLReader::READ_NOTHING) { reader.myReadState = XHTMLReader::READ_STYLE; reader.myTableParser = new StyleSheetTableParser(reader.myStyleSheetTable); } }
void XHTMLTagStyleAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { static const std::string TYPE = "text/css"; const char *type = reader.attributeValue(xmlattributes, "type"); if ((type == 0) || (TYPE != type)) { return; } if (reader.myReadState == XHTML_READ_NOTHING) { reader.myReadState = XHTML_READ_STYLE; reader.myTableParser = new StyleSheetTableParser(reader.myPathPrefix, reader.myStyleSheetTable, reader.myFontMap); ZLLogger::Instance().println("CSS", "parsing style tag content"); } }
void XHTMLTagHyperlinkAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { const char *href = reader.attributeValue(xmlattributes, "href"); if (href != 0 && href[0] != '\0') { const FBTextKind hyperlinkType = MiscUtil::referenceType(href); std::string link = MiscUtil::decodeHtmlURL(href); if (hyperlinkType == INTERNAL_HYPERLINK) { link = (link[0] == '#') ? reader.myReferenceName + link : reader.myReferenceDirName + link; link = ZLFileUtil::normalizeUnixPath(link); } myHyperlinkStack.push(hyperlinkType); bookReader(reader).addHyperlinkControl(hyperlinkType, link); } else { myHyperlinkStack.push(REGULAR); } const char *name = reader.attributeValue(xmlattributes, "name"); if (name != 0) { bookReader(reader).addHyperlinkLabel( reader.myReferenceName + "#" + MiscUtil::decodeHtmlURL(name) ); } }
void XHTMLTagLinkAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { const char *rel = reader.attributeValue(xmlattributes, "rel"); if (!rel || strcmp(rel, "stylesheet")) { return; } const char *type = reader.attributeValue(xmlattributes, "type"); if (!type || strcmp(type, "text/css")) { return; } const char *href = reader.attributeValue(xmlattributes, "href"); if (href == 0) { return; } shared_ptr<ZLInputStream> cssStream = ZLFile(reader.myPathPrefix + MiscUtil::decodeHtmlURL(href)).inputStream(); if (cssStream.isNull()) { return; } StyleSheetTableParser parser(reader.myStyleSheetTable); parser.parse(*cssStream); //reader.myStyleSheetTable.dump(); }
void XHTMLTagImageAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { const char *fileName = reader.attributeValue(xmlattributes, myNameAttribute.c_str()); if (fileName != 0) { bool flag = bookReader(reader).paragraphIsOpen(); if (flag) { bookReader(reader).endParagraph(); } if ((strlen(fileName) > 2) && strncmp(fileName, "./", 2) == 0) { fileName +=2; } const std::string fullfileName = pathPrefix(reader) + fileName; bookReader(reader).addImageReference(fullfileName); bookReader(reader).addImage(fullfileName, new ZLFileImage("image/auto", fullfileName, 0)); if (flag) { bookReader(reader).beginParagraph(); } } }
void OEBBookReader::generateTOC(const XHTMLReader &xhtmlReader) { if (!myNCXTOCFileName.empty()) { NCXReader ncxReader(myModelReader); const ZLFile ncxFile(myFilePrefix + myNCXTOCFileName); if (ncxReader.readDocument(ncxFile.inputStream(myEncryptionMap))) { const std::map<int,NCXReader::NavPoint> navigationMap = ncxReader.navigationMap(); if (!navigationMap.empty()) { std::size_t level = 0; for (std::map<int,NCXReader::NavPoint>::const_iterator it = navigationMap.begin(); it != navigationMap.end(); ++it) { const NCXReader::NavPoint &point = it->second; int index = myModelReader.model().label(xhtmlReader.normalizedReference(point.ContentHRef)).ParagraphNumber; while (level > point.Level) { myModelReader.endContentsParagraph(); --level; } while (++level <= point.Level) { myModelReader.beginContentsParagraph(-2); myModelReader.addContentsData("..."); } myModelReader.beginContentsParagraph(index); myModelReader.addContentsData(point.Text); } while (level > 0) { myModelReader.endContentsParagraph(); --level; } return; } } } std::vector<std::pair<std::string,std::string> > &toc = myTourTOC.empty() ? myGuideTOC : myTourTOC; for (std::vector<std::pair<std::string,std::string> >::const_iterator it = toc.begin(); it != toc.end(); ++it) { int index = myModelReader.model().label(it->second).ParagraphNumber; if (index != -1) { myModelReader.beginContentsParagraph(index); myModelReader.addContentsData(it->first); myModelReader.endContentsParagraph(); } } }
void XHTMLTagAction::endParagraph(XHTMLReader &reader) { reader.endParagraph(); }
void XHTMLTagAction::beginParagraph(XHTMLReader &reader) { reader.beginParagraph(); }
void XHTMLTagControlAction::doAtStart(XHTMLReader &reader, const char**) { reader.pushTextKind(myControl); bookReader(reader).addControl(myControl, true); }
void XHTMLTagParagraphAction::doAtEnd(XHTMLReader &reader) { reader.endParagraph(); }
void XHTMLTagPreAction::doAtStart(XHTMLReader &reader, const char**) { reader.myPreformatted = true; reader.pushTextKind(PREFORMATTED); beginParagraph(reader); }