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 XHTMLTagPreAction::doAtStart(XHTMLReader &reader, const char**) { endParagraph(reader); reader.myParseStack.back().kind = PREFORMATTED; if (++reader.myPreformatted == 1) { beginParagraph(reader); } }
void XHTMLTagParagraphWithControlAction::doAtStart(XHTMLReader &reader, const char**) { if ((myControl == TITLE) && (bookReader(reader).model().bookTextModel()->paragraphsNumber() > 1)) { bookReader(reader).insertEndOfSectionParagraph(); } bookReader(reader).pushKind(myControl); beginParagraph(reader); }
bool TxtBookReader::characterDataHandler(std::string &str) { const char *ptr = str.data(); const char *end = ptr + str.length(); for (; ptr != end; ++ptr) { if (isspace((unsigned char)*ptr)) { if (*ptr != '\t') { ++mySpaceCounter; } else { mySpaceCounter += myFormat.ignoredIndent() + 1; // TODO: implement single option in PlainTextFormat } } else { myLastLineIsEmpty = false; break; } } if (ptr != end) { if ((myFormat.breakType() & PlainTextFormat::BREAK_PARAGRAPH_AT_LINE_WITH_INDENT) && myNewLine && (mySpaceCounter > myFormat.ignoredIndent())) { internalEndParagraph(); beginParagraph(); } addData(str); if (myInsideContentsParagraph) { addContentsData(str); } myNewLine = false; } return true; }
void XHTMLTagRestartParagraphAction::doAtStart(XHTMLReader &reader, const char**) { if (reader.myCurrentParagraphIsEmpty) { bookReader(reader).addData(" "); } endParagraph(reader); beginParagraph(reader); }
void XHTMLTagItemAction::doAtStart(XHTMLReader &reader, const char**) { endParagraph(reader); // TODO: increase left indent beginParagraph(reader); // TODO: replace bullet sign by number inside OL tag const std::string bullet = "\xE2\x80\xA2\xC0\xA0"; bookReader(reader).addData(bullet); }
void BookReader::addVideoEntry(const ZLVideoEntry &entry) { if (myCurrentTextModel != 0) { mySectionContainsRegularContents = true; endParagraph(); beginParagraph(); myCurrentTextModel->addVideoEntry(entry); endParagraph(); } }
bool TxtBookReader::characterDataHandler(std::string &str) { const char *ptr = str.data(); const char *end = ptr + str.length(); for (; ptr != end; ++ptr) { if (std::isspace((unsigned char)*ptr)) { if (*ptr != '\t') { ++mySpaceCounter; } else { mySpaceCounter += myFormat.ignoredIndent() + 1; // TODO: implement single option in PlainTextFormat } } else { myLastLineIsEmpty = false; break; } } if (ptr != end) { if ((myFormat.breakType() & PlainTextFormat::BREAK_PARAGRAPH_AT_LINE_WITH_INDENT) && myNewLine && (mySpaceCounter > myFormat.ignoredIndent())) { internalEndParagraph(); beginParagraph(); } if (myInsideContentsParagraph && str.length() <= 30) { if(!myHasAddedTitle) { internalEndParagraph(); insertEndOfSectionParagraph(); beginContentsParagraph(); enterTitle(); pushKind(SECTION_TITLE); beginParagraph(); myHasAddedTitle = true; } if(str[str.size() -1] == '\n') { myHasAddedTitle = false; } addContentsData(str); } addData(str); myNewLine = false; } return true; }
void XHTMLTagLineBreakAction::doAtEnd(XHTMLReader& reader) { BookReader &br = bookReader(reader); if (br.paragraphIsOpen()) { br.addLineBreak(); } else { beginParagraph(reader); br.addLineBreak(); endParagraph(reader); } }
void TxtBookReader::startDocumentHandler() { setMainTextModel(); pushKind(REGULAR); beginParagraph(); myLineFeedCounter = 0; myInsideContentsParagraph = false; enterTitle(); myLastLineIsEmpty = true; myNewLine = true; mySpaceCounter = 0; }
bool TxtBookReader::newLineHandler() { if (!myLastLineIsEmpty) { myLineFeedCounter = -1; } myLastLineIsEmpty = true; ++myLineFeedCounter; myNewLine = true; mySpaceCounter = 0; bool paragraphBreak = (myFormat.breakType() & PlainTextFormat::BREAK_PARAGRAPH_AT_NEW_LINE) || ((myFormat.breakType() & PlainTextFormat::BREAK_PARAGRAPH_AT_EMPTY_LINE) && (myLineFeedCounter > 0)); if (myFormat.createContentsTable()) { // if (!myInsideContentsParagraph && (myLineFeedCounter == myFormat.emptyLinesBeforeNewSection() + 1)) { /* Fixed by Hatred: remove '+ 1' for emptyLinesBeforeNewSection, it looks like very strange when we should point count of empty string decrised by 1 in settings dialog */ if (!myInsideContentsParagraph && (myLineFeedCounter == myFormat.emptyLinesBeforeNewSection())) { myInsideContentsParagraph = true; internalEndParagraph(); insertEndOfSectionParagraph(); beginContentsParagraph(); enterTitle(); pushKind(SECTION_TITLE); beginParagraph(); paragraphBreak = false; } if (myInsideContentsParagraph && (myLineFeedCounter == 1)) { exitTitle(); endContentsParagraph(); popKind(); myInsideContentsParagraph = false; paragraphBreak = true; } } if (paragraphBreak) { internalEndParagraph(); beginParagraph(); } return true; }
bool TxtBookReader::newLineHandler() { if (!myLastLineIsEmpty) { myLineFeedCounter = -1; } myLastLineIsEmpty = true; ++myLineFeedCounter; myNewLine = true; mySpaceCounter = 0; bool paragraphBreak = (myFormat.breakType() & PlainTextFormat::BREAK_PARAGRAPH_AT_NEW_LINE) || ((myFormat.breakType() & PlainTextFormat::BREAK_PARAGRAPH_AT_EMPTY_LINE) && (myLineFeedCounter > 0)); if (myFormat.createContentsTable()) { if (!myInsideContentsParagraph && (myLineFeedCounter == myFormat.emptyLinesBeforeNewSection() + 1)) { myInsideContentsParagraph = true; internalEndParagraph(); insertEndOfSectionParagraph(); beginContentsParagraph(); enterTitle(); pushKind(SECTION_TITLE); beginParagraph(); paragraphBreak = false; } if (myInsideContentsParagraph && (myLineFeedCounter == 1)) { exitTitle(); endContentsParagraph(); popKind(); myInsideContentsParagraph = false; paragraphBreak = true; } } if (paragraphBreak) { internalEndParagraph(); beginParagraph(); } return true; }
void DocBookBookReader::startElementHandler(int tag, const char **) { switch (tag) { case _SECT1: myReadText = true; pushKind(REGULAR); beginContentsParagraph(); break; case _PARA: if (myReadText) { beginParagraph(); } break; case _TITLE: enterTitle(); pushKind(SECTION_TITLE); if (myReadText) { beginParagraph(); } break; case _EMPHASIS: addControl(EMPHASIS, true); break; case _CITETITLE: addControl(CITE, true); break; case _ULINK: case _EMAIL: addControl(CODE, true); break; case _BLOCKQUOTE: pushKind(STRONG); break; default: break; } }
void BookReader::addImageReference(const std::string &id, short vOffset, bool isCover) { if (myCurrentTextModel != 0) { mySectionContainsRegularContents = true; if (paragraphIsOpen()) { flushTextBufferToParagraph(); myCurrentTextModel->addImage(id, vOffset, isCover); } else { beginParagraph(); myCurrentTextModel->addControl(IMAGE, true); myCurrentTextModel->addImage(id, vOffset, isCover); myCurrentTextModel->addControl(IMAGE, false); endParagraph(); } } }
void BookReader::addImageReference(const std::string &id, short vOffset) { if (myCurrentTextModel != 0) { mySectionContainsRegularContents = true; if (myTextParagraphExists) { flushTextBufferToParagraph(); myCurrentTextModel->addImage(id, myModel.imageMap(), vOffset); } else { beginParagraph(); myCurrentTextModel->addControl(IMAGE, true); myCurrentTextModel->addImage(id, myModel.imageMap(), vOffset); myCurrentTextModel->addControl(IMAGE, false); endParagraph(); } } }
void XHTMLTagItemAction::doAtStart(XHTMLReader &reader, const char**) { endParagraph(reader); beginParagraph(reader); if (!reader.myListNumStack.empty()) { bookReader(reader).addFixedHSpace(3 * reader.myListNumStack.size()); int &index = reader.myListNumStack.top(); if (index == 0) { static const std::string bullet = "\xE2\x80\xA2\xC0\xA0"; bookReader(reader).addData(bullet); } else { bookReader(reader).addData(ZLStringUtil::numberToString(index++) + "."); } bookReader(reader).addFixedHSpace(1); } reader.myNewParagraphInProgress = true; }
void XHTMLReader::characterDataHandler(const char *text, std::size_t len) { switch (myReadState) { case XHTML_READ_NOTHING: case XHTML_READ_VIDEO: break; case XHTML_READ_STYLE: if (!myTableParser.isNull()) { myTableParser->parseString(text, len); } break; case XHTML_READ_BODY: if (myPreformatted) { if (*text == '\r' || *text == '\n') { endParagraph(); text += 1; len -= 1; beginParagraph(); myModelReader.addControl(PREFORMATTED, true); } std::size_t spaceCounter = 0; while (spaceCounter < len && std::isspace((unsigned char)*(text + spaceCounter))) { ++spaceCounter; } myModelReader.addFixedHSpace(spaceCounter); text += spaceCounter; len -= spaceCounter; } else if (myNewParagraphInProgress || !myModelReader.paragraphIsOpen()) { while (std::isspace((unsigned char)*text)) { ++text; if (--len == 0) { break; } } } if (len > 0) { myCurrentParagraphIsEmpty = false; if (!myModelReader.paragraphIsOpen()) { myModelReader.beginParagraph(); } myModelReader.addData(std::string(text, len)); myNewParagraphInProgress = false; } break; } }
void XHTMLReader::restartParagraph() { if (myCurrentParagraphIsEmpty) { myModelReader.addFixedHSpace(1); } ZLTextStyleEntry spaceAfterBlocker(ZLTextStyleEntry::STYLE_OTHER_ENTRY); spaceAfterBlocker.setLength( ZLTextStyleEntry::LENGTH_SPACE_AFTER, 0, ZLTextStyleEntry::SIZE_UNIT_PIXEL ); addTextStyleEntry(spaceAfterBlocker); endParagraph(); beginParagraph(true); ZLTextStyleEntry spaceBeforeBlocker(ZLTextStyleEntry::STYLE_OTHER_ENTRY); spaceBeforeBlocker.setLength( ZLTextStyleEntry::LENGTH_SPACE_BEFORE, 0, ZLTextStyleEntry::SIZE_UNIT_PIXEL ); addTextStyleEntry(spaceBeforeBlocker); }
void PluckerBookReader::safeBeginParagraph() { if (!myParagraphStarted) { myParagraphStarted = true; myBufferIsEmpty = true; beginParagraph(); if (!myParagraphStored) { myParagraphVector->push_back(model().bookTextModel()->paragraphsNumber() - 1); myParagraphStored = true; } for (std::vector<std::pair<FBTextKind,bool> >::const_iterator it = myDelayedControls.begin(); it != myDelayedControls.end(); ++it) { addControl(it->first, it->second); } if (myForcedEntry != 0) { addControl(*myForcedEntry); } else { addControl(REGULAR, true); } for (std::vector<std::string>::const_iterator it = myDelayedHyperlinks.begin(); it != myDelayedHyperlinks.end(); ++it) { addHyperlinkControl(INTERNAL_HYPERLINK, *it); } myDelayedHyperlinks.clear(); } }
void XHTMLReader::haveContent() { if (!myParseStack.back().haveContent) { // Create empty paragraphs for other parent entries that haven't // had any content yet, in order to apply their top margins. Skip // the last entry as it will be applied for the paragraph we are // about to start. bool skippedLastEntry = false; for (std::vector<ParseContext>::reverse_iterator it = myParseStack.rbegin(); it != myParseStack.rend() && !it->haveContent; ++it) { it->haveContent = true; if (elementHasTopMargin(*it)) { if (!skippedLastEntry) { skippedLastEntry = true; } else { ZLTextStyleEntry::SizeUnit unit = ZLTextStyleEntry::SIZE_UNIT_PIXEL; short size = 0; if (it->styleIndex >= 0 && myStyleStack[it->styleIndex].TextStyle.lengthSupported(ZLTextStyleEntry::LENGTH_SPACE_BEFORE)) { size = myStyleStack[it->styleIndex].TextStyle.length(ZLTextStyleEntry::LENGTH_SPACE_BEFORE, unit); } else if (it->decoration) { const ZLTextFullStyleDecoration *decoration = it->decoration->fullDecoration(); if (decoration) { size = decoration->SpaceBeforeOption.value(); unit = decoration->SpaceBeforeOptionUnit; } } if (size > 0) { ZLTextStyleEntry style; style.setLength(ZLTextStyleEntry::LENGTH_SPACE_BEFORE, size, unit); addStyleParagraph(style); } } } } } myBottomMargins.resize(0); beginParagraph(); }
bool TxtBookReader::newLineHandler() { if (!myLastLineIsEmpty) { myLineFeedCounter = -1; } myLastLineIsEmpty = true; ++myLineFeedCounter; myNewLine = true; mySpaceCounter = 0; bool paragraphBreak = (myFormat.breakType() & PlainTextFormat::BREAK_PARAGRAPH_AT_NEW_LINE) || ((myFormat.breakType() & PlainTextFormat::BREAK_PARAGRAPH_AT_EMPTY_LINE) && (myLineFeedCounter > 0)); if (myFormat.createContentsTable()) { // if (!myInsideContentsParagraph && (myLineFeedCounter == myFormat.emptyLinesBeforeNewSection() + 1)) { /* Fixed by Hatred: remove '+ 1' for emptyLinesBeforeNewSection, it looks like very strange when we should point count of empty string decrised by 1 in settings dialog */ //__android_log_print(ANDROID_LOG_INFO, "love", "!!!!!,,,%d!!!!!!%d", myLineFeedCounter, myFormat.emptyLinesBeforeNewSection()); if (!myInsideContentsParagraph && (myLineFeedCounter >= myFormat.emptyLinesBeforeNewSection())) { myInsideContentsParagraph = true; paragraphBreak = false; } else if (myInsideContentsParagraph && (myLineFeedCounter <= 1)) { exitTitle(); endContentsParagraph(); popKind(); myInsideContentsParagraph = false; paragraphBreak = true; } } if (true) { internalEndParagraph(); beginParagraph(); } return true; }
void XHTMLTagPreAction::doAtStart(XHTMLReader &reader, const char**) { reader.myPreformatted = true; beginParagraph(reader); bookReader(reader).addControl(CODE, true); }
void XHTMLTagParagraphAction::doAtStart(XHTMLReader &reader, const char**) { if (!reader.myNewParagraphInProgress) { beginParagraph(reader); reader.myNewParagraphInProgress = true; } }
void XHTMLTagPreAction::doAtStart(XHTMLReader &reader, const char**) { reader.myPreformatted = true; reader.pushTextKind(PREFORMATTED); beginParagraph(reader); }
void BookReader::insertEncryptedSectionParagraph() { beginParagraph(ZLTextParagraph::ENCRYPTED_SECTION_PARAGRAPH); endParagraph(); beginParagraph(ZLTextParagraph::END_OF_SECTION_PARAGRAPH); endParagraph(); }