diff options
Diffstat (limited to 'src/backend/filters')
-rw-r--r-- | src/backend/filters/btosismorphsegmentation.cpp | 95 | ||||
-rw-r--r-- | src/backend/filters/btosismorphsegmentation.h | 47 | ||||
-rw-r--r-- | src/backend/filters/gbftohtml.cpp | 116 | ||||
-rw-r--r-- | src/backend/filters/gbftohtml.h | 18 | ||||
-rw-r--r-- | src/backend/filters/osistohtml.cpp | 54 | ||||
-rw-r--r-- | src/backend/filters/osistohtml.h | 12 | ||||
-rw-r--r-- | src/backend/filters/plaintohtml.cpp | 4 | ||||
-rw-r--r-- | src/backend/filters/plaintohtml.h | 8 | ||||
-rw-r--r-- | src/backend/filters/teitohtml.cpp | 48 | ||||
-rw-r--r-- | src/backend/filters/teitohtml.h | 8 | ||||
-rw-r--r-- | src/backend/filters/thmltohtml.cpp | 308 | ||||
-rw-r--r-- | src/backend/filters/thmltohtml.h | 22 | ||||
-rw-r--r-- | src/backend/filters/thmltoplain.cpp | 222 | ||||
-rw-r--r-- | src/backend/filters/thmltoplain.h | 35 |
14 files changed, 304 insertions, 693 deletions
diff --git a/src/backend/filters/btosismorphsegmentation.cpp b/src/backend/filters/btosismorphsegmentation.cpp deleted file mode 100644 index 1675476..0000000 --- a/src/backend/filters/btosismorphsegmentation.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/********* -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2014 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#include "backend/filters/btosismorphsegmentation.h" - -// Sword includes: -#include <utilxml.h> - - -const char Filters::BtOSISMorphSegmentation::oName[] = "Morph segmentation"; -const char Filters::BtOSISMorphSegmentation::oTip[] = "Toggles morph " - "segmentation On and Off " - "if they exist"; - -const sword::SWBuf Filters::BtOSISMorphSegmentation::choices[3] = { "Off", - "On", - "" }; - -const sword::StringList Filters::BtOSISMorphSegmentation::oValues(&choices[0], - &choices[2]); - -Filters::BtOSISMorphSegmentation::BtOSISMorphSegmentation() - : sword::SWOptionFilter(oName, oTip, &oValues) -{ - setOptionValue("Off"); -} - -char Filters::BtOSISMorphSegmentation::processText(sword::SWBuf & text, - const sword::SWKey * key, - const sword::SWModule * mod) -{ - (void) key; - (void) mod; - - sword::SWBuf token; - bool intoken = false; - bool hide = false; - - sword::SWBuf orig(text); - const char * from = orig.c_str(); - - sword::XMLTag tag; - - for (text = ""; *from; ++from) { - if (*from == '<') { - intoken = true; - token = ""; - continue; - } - - if (*from == '>') { // process tokens - intoken = false; - - if (!strncmp(token.c_str(), "seg ", 4) - || !strncmp(token.c_str(), "/seg", 4)) - { - tag = token; - - if (!tag.isEndTag() - && tag.getAttribute("type") - && !strcmp("morph", tag.getAttribute("type"))) - { // <seg type="morph"> start tag - hide = (option == 0); // only hide if option is Off - } - - if (hide) { // hides start and end tags as long as hide is set - if (tag.isEndTag()) //</seg> - hide = false; - continue; // leave out the current token - } - } // end of seg tag handling - - text.append('<'); - text.append(token); - text.append('>'); - // hide = false; // not right, because there may be child tags in seg. Only /seg may disable the seg hiding. - continue; - } // end of intoken part - - if (intoken) { - token.append(*from); // copy token - } else { - text.append(*from); // copy text which is not inside of a tag - } - } - - return 0; -} - diff --git a/src/backend/filters/btosismorphsegmentation.h b/src/backend/filters/btosismorphsegmentation.h deleted file mode 100644 index 66d4724..0000000 --- a/src/backend/filters/btosismorphsegmentation.h +++ /dev/null @@ -1,47 +0,0 @@ -/********* -* -* In the name of the Father, and of the Son, and of the Holy Spirit. -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2014 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#ifndef BTOSISMORPHSEGMENTATION_H -#define BTOSISMORPHSEGMENTATION_H - -// Sword includes: -#include <swbuf.h> -#include <swoptfilter.h> - - -namespace Filters { - -/** - \brief This Filter shows/hides headings in a OSIS text. - \author Martin Gruner -*/ -class BtOSISMorphSegmentation: public sword::SWOptionFilter { - -public: /* Methods: */ - - BtOSISMorphSegmentation(); - - virtual char processText(sword::SWBuf & text, - const sword::SWKey * key = 0, - const sword::SWModule * module = 0); - -private: /* Fields: */ - - static const char oName[]; - static const char oTip[]; - static const sword::SWBuf choices[3]; - static const sword::StringList oValues; - -}; - -} /* namespace Filters { */ - -#endif /* BTOSISMORPHSEGMENTATION_H */ diff --git a/src/backend/filters/gbftohtml.cpp b/src/backend/filters/gbftohtml.cpp index 8f2fcc5..fc9dd35 100644 --- a/src/backend/filters/gbftohtml.cpp +++ b/src/backend/filters/gbftohtml.cpp @@ -2,17 +2,19 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ -#include "backend/filters/gbftohtml.h" +#include "gbftohtml.h" +#include <cstdlib> #include <QRegExp> #include <QString> -#include "backend/drivers/cswordmoduleinfo.h" -#include "backend/managers/cswordbackend.h" +#include "../../util/btassert.h" +#include "../drivers/cswordmoduleinfo.h" +#include "../managers/cswordbackend.h" // Sword includes: #include <utilxml.h> @@ -219,68 +221,84 @@ char Filters::GbfToHtml::processText(sword::SWBuf& buf, const sword::SWKey * key result += e; } - if (list.count()) { - buf = (const char*)result.toUtf8().constData(); - } + if (list.count()) + buf = result.toUtf8().constData(); return 1; } +namespace { +int hexDigitValue(char const hex) { + switch (hex) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return hex - '0'; + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + return hex - 'a' + 10; + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + return hex - 'A' + 10; + default: + BT_ASSERT(false && "Invalid hex code in GBF"); + abort(); + } +} + +char hexToChar(char const * const hex) { + int const first = hexDigitValue(hex[0u]); + return (first * 16u) + hexDigitValue(hex[1u]); +} +} + bool Filters::GbfToHtml::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) { - if (!substituteToken(buf, token)) { //more than a simple replace - const unsigned int tokenLength = strlen(token); - - UserData* myUserData = dynamic_cast<UserData*>(userData); - sword::SWModule* myModule = const_cast<sword::SWModule*>(myUserData->module); //hack to be able to call stuff like Lang() - - if ( !strncmp(token, "WG", 2) - || !strncmp(token, "WH", 2) - || !strncmp(token, "WT", 2) ) { - buf.append('<'); - buf.append(token); - buf.append('>'); - } - else if (!strncmp(token, "RB", 2)) { + if (!substituteToken(buf, token)) { // More than a simple replace + size_t const tokenLength = strlen(token); + + BT_ASSERT(dynamic_cast<UserData *>(userData)); + UserData * const myUserData = static_cast<UserData *>(userData); + // Hack to be able to call stuff like Lang(): + sword::SWModule const * const myModule = + const_cast<sword::SWModule *>(myUserData->module); + + /* We use several append calls because appendFormatted slows down + filtering, which should be fast. */ + + if (!strncmp(token, "WG", 2u) + || !strncmp(token, "WH", 2u) + || !strncmp(token, "WT", 2u)) + { + buf.append('<').append(token).append('>'); + } else if (!strncmp(token, "RB", 2u)) { myUserData->hasFootnotePreTag = true; buf.append("<span class=\"footnotepre\">"); - } - else if (!strncmp(token, "RF", 2)) { - //we use several append calls because appendFormatted slows down filtering, which should be fast - + } else if (!strncmp(token, "RF", 2u)) { if (myUserData->hasFootnotePreTag) { // qWarning("inserted footnotepre end"); buf.append("</span>"); myUserData->hasFootnotePreTag = false; } - buf.append(" <span class=\"footnote\" note=\""); - buf.append(myModule->getName()); - buf.append('/'); - buf.append(myUserData->key->getShortText()); - buf.append('/'); - buf.append( QString::number(myUserData->swordFootnote++).toUtf8().constData() ); - buf.append("\">*</span> "); - + buf.append(" <span class=\"footnote\" note=\"") + .append(myModule->getName()) + .append('/') + .append(myUserData->key->getShortText()) + .append('/') + .append(QString::number(myUserData->swordFootnote).toUtf8().constData()) + .append("\">*</span> "); + myUserData->swordFootnote++; userData->suspendTextPassThru = true; - } - else if (!strncmp(token, "Rf", 2)) { //end of footnote + } else if (!strncmp(token, "Rf", 2u)) { // End of footnote userData->suspendTextPassThru = false; - } - else if (!strncmp(token, "FN", 2)) { //the end </font> tag is inserted in addTokenSubsitute + } else if (!strncmp(token, "FN", 2u)) { + // The end </font> tag is inserted in addTokenSubsitute buf.append("<font face=\""); - - for (unsigned long i = 2; i < tokenLength; i++) { - if (token[i] != '\"') { - buf.append( token[i] ); - } - } - + for (size_t i = 2u; i < tokenLength; i++) + if (token[i] != '\"') + buf.append(token[i]); buf.append("\">"); - } - else if (!strncmp(token, "CA", 2)) { // ASCII value - buf.append( (char)atoi(&token[2]) ); - } - else { + } else if (!strncmp(token, "CA", 2u)) { // ASCII value <CA##> in hex + BT_ASSERT(tokenLength == 4u); + buf.append(static_cast<char>(hexToChar(token + 2u))); + } else { return GBFHTML::handleToken(buf, token, userData); } } diff --git a/src/backend/filters/gbftohtml.h b/src/backend/filters/gbftohtml.h index bfe8501..9b8da9e 100644 --- a/src/backend/filters/gbftohtml.h +++ b/src/backend/filters/gbftohtml.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -40,19 +40,19 @@ class GbfToHtml: public sword::GBFHTML { GbfToHtml(); /** Reimplemented from sword::OSISHTMLHREF. */ - virtual bool handleToken(sword::SWBuf &buf, - const char *token, - sword::BasicFilterUserData *userData); + bool handleToken(sword::SWBuf &buf, + const char *token, + sword::BasicFilterUserData *userData) override; /** Reimplemented from sword::SWFilter. */ - virtual char processText(sword::SWBuf &buf, - const sword::SWKey *key, - const sword::SWModule *module = 0); + char processText(sword::SWBuf &buf, + const sword::SWKey *key, + const sword::SWModule *module = nullptr) override; protected: /* Methods: */ /** Reimplemented from sword::OSISHTMLHREF. */ - virtual inline sword::BasicFilterUserData *createUserData( - const sword::SWModule *module, const sword::SWKey *key) + inline sword::BasicFilterUserData *createUserData( + const sword::SWModule *module, const sword::SWKey *key) override { return new UserData(module, key); } diff --git a/src/backend/filters/osistohtml.cpp b/src/backend/filters/osistohtml.cpp index 3a8d65f..bca5670 100644 --- a/src/backend/filters/osistohtml.cpp +++ b/src/backend/filters/osistohtml.cpp @@ -2,19 +2,20 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ -#include "backend/filters/osistohtml.h" +#include "osistohtml.h" #include <QString> -#include "backend/config/btconfig.h" -#include "backend/drivers/cswordmoduleinfo.h" -#include "backend/managers/clanguagemgr.h" -#include "backend/managers/referencemanager.h" -#include "backend/managers/cswordbackend.h" +#include "../../util/btassert.h" +#include "../config/btconfig.h" +#include "../drivers/cswordmoduleinfo.h" +#include "../managers/clanguagemgr.h" +#include "../managers/cswordbackend.h" +#include "../managers/referencemanager.h" // Sword includes: #include <swbuf.h> @@ -272,7 +273,7 @@ bool Filters::OsisToHtml::handleToken(sword::SWBuf &buf, const char *token, swor } } else { //if (tag.isEndTag()) { - Q_ASSERT(myUserData->noteType != UserData::Unknown); + BT_ASSERT(myUserData->noteType != UserData::Unknown); if (myUserData->noteType == UserData::CrossReference) { buf.append("</span> "); @@ -540,7 +541,7 @@ bool Filters::OsisToHtml::handleToken(sword::SWBuf &buf, const char *token, swor void Filters::OsisToHtml::renderReference(const char *osisRef, sword::SWBuf &buf, sword::SWModule *myModule, UserData *myUserData) { QString ref( osisRef ); QString hrefRef( ref ); - //Q_ASSERT(!ref.isEmpty()); checked later + //BT_ASSERT(!ref.isEmpty()); checked later if (!ref.isEmpty()) { //find out the mod, using the current module makes sense if it's a bible or commentary because the refs link into a bible by default. @@ -548,14 +549,14 @@ void Filters::OsisToHtml::renderReference(const char *osisRef, sword::SWBuf &buf // modulename is given, so we'll use that one CSwordModuleInfo* mod = CSwordBackend::instance()->findSwordModuleByPointer(myModule); - //Q_ASSERT(mod); checked later + //BT_ASSERT(mod); checked later if (!mod || (mod->type() != CSwordModuleInfo::Bible && mod->type() != CSwordModuleInfo::Commentary)) { mod = btConfig().getDefaultSwordModuleByType("standardBible"); } - // Q_ASSERT(mod); There's no necessarily a module or standard Bible + // BT_ASSERT(mod); There's no necessarily a module or standard Bible //if the osisRef like "GerLut:key" contains a module, use that int pos = ref.indexOf(":"); @@ -570,23 +571,22 @@ void Filters::OsisToHtml::renderReference(const char *osisRef, sword::SWBuf &buf } if (mod) { - ReferenceManager::ParseOptions options; - options.refBase = QString::fromUtf8(myUserData->key->getText()); - options.refDestinationModule = QString(mod->name()); - options.sourceLanguage = QString(myModule->getLanguage()); - options.destinationLanguage = QString("en"); - - buf.append("<a href=\""); - buf.append( //create the hyperlink with key and mod - ReferenceManager::encodeHyperlink( + ReferenceManager::ParseOptions const options( mod->name(), - ReferenceManager::parseVerseReference(hrefRef, options), - ReferenceManager::typeFromModule(mod->type()) - ).toUtf8().constData() - ); - buf.append("\" crossrefs=\""); - buf.append((const char*)ReferenceManager::parseVerseReference(ref, options).toUtf8().constData()); //ref must contain the osisRef module marker if there was any - buf.append("\">"); + QString::fromUtf8(myUserData->key->getText()), + myModule->getLanguage()); + + buf.append("<a href=\"") + .append( //create the hyperlink with key and mod + ReferenceManager::encodeHyperlink( + mod->name(), + ReferenceManager::parseVerseReference(hrefRef, options), + ReferenceManager::typeFromModule(mod->type()) + ).toUtf8().constData() + ) + .append("\" crossrefs=\"") + .append(ReferenceManager::parseVerseReference(ref, options).toUtf8().constData()) //ref must contain the osisRef module marker if there was any + .append("\">"); } // should we add something if there were no referenced module available? } diff --git a/src/backend/filters/osistohtml.h b/src/backend/filters/osistohtml.h index 1c59ae1..c1ad9ba 100644 --- a/src/backend/filters/osistohtml.h +++ b/src/backend/filters/osistohtml.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -54,15 +54,15 @@ class OsisToHtml: public sword::OSISHTMLHREF { OsisToHtml(); /** Reimplemented from sword::OSISHTMLHREF. */ - virtual bool handleToken(sword::SWBuf &buf, - const char *token, - sword::BasicFilterUserData *userData); + bool handleToken(sword::SWBuf &buf, + const char *token, + sword::BasicFilterUserData *userData) override; protected: /* Methods: */ /** Reimplemented from sword::OSISHTMLHREF. */ - virtual inline sword::BasicFilterUserData *createUserData( + inline sword::BasicFilterUserData *createUserData( const sword::SWModule *module, - const sword::SWKey *key) + const sword::SWKey *key) override { return new UserData(module, key); } diff --git a/src/backend/filters/plaintohtml.cpp b/src/backend/filters/plaintohtml.cpp index edb6208..a1ead4d 100644 --- a/src/backend/filters/plaintohtml.cpp +++ b/src/backend/filters/plaintohtml.cpp @@ -2,12 +2,12 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ -#include "backend/filters/plaintohtml.h" +#include "plaintohtml.h" #include <QDebug> diff --git a/src/backend/filters/plaintohtml.h b/src/backend/filters/plaintohtml.h index e8ae570..0f077b6 100644 --- a/src/backend/filters/plaintohtml.h +++ b/src/backend/filters/plaintohtml.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -31,9 +31,9 @@ class PlainToHtml: public sword::SWFilter { protected: /* Methods: */ /** Reimplemented from sword::SWFilter. */ - virtual char processText(sword::SWBuf &buf, - const sword::SWKey *key, - const sword::SWModule *module = 0); + char processText(sword::SWBuf &buf, + const sword::SWKey *key, + const sword::SWModule *module = nullptr) override; }; diff --git a/src/backend/filters/teitohtml.cpp b/src/backend/filters/teitohtml.cpp index 6367e22..91902d8 100644 --- a/src/backend/filters/teitohtml.cpp +++ b/src/backend/filters/teitohtml.cpp @@ -2,19 +2,19 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ -#include "backend/filters/teitohtml.h" +#include "teitohtml.h" #include <QString> -#include "backend/config/btconfig.h" -#include "backend/drivers/cswordmoduleinfo.h" -#include "backend/managers/clanguagemgr.h" -#include "backend/managers/referencemanager.h" -#include "backend/managers/cswordbackend.h" +#include "../config/btconfig.h" +#include "../drivers/cswordmoduleinfo.h" +#include "../managers/clanguagemgr.h" +#include "../managers/cswordbackend.h" +#include "../managers/referencemanager.h" // Sword includes: #include <swbuf.h> @@ -111,7 +111,7 @@ void TeiToHtml::renderReference(const char *osisRef, sword::SWBuf &buf, CSwordModuleInfo* mod = btConfig().getDefaultSwordModuleByType( "standardBible" ); - // Q_ASSERT(mod); There's no necessarily a module or standard Bible + // BT_ASSERT(mod); There's no necessarily a module or standard Bible //if the osisRef like "GerLut:key" contains a module, use that int pos = ref.indexOf(":"); @@ -126,23 +126,23 @@ void TeiToHtml::renderReference(const char *osisRef, sword::SWBuf &buf, } if (mod) { - ReferenceManager::ParseOptions options; - options.refBase = QString::fromUtf8(myUserData->key->getText()); - options.refDestinationModule = QString(mod->name()); - options.sourceLanguage = QString(mod->module()->getLanguage()); - options.destinationLanguage = QString("en"); - - buf.append("<a href=\""); - buf.append( //create the hyperlink with key and mod - ReferenceManager::encodeHyperlink( + ReferenceManager::ParseOptions const options( mod->name(), - ReferenceManager::parseVerseReference(hrefRef, options), - ReferenceManager::typeFromModule(mod->type()) - ).toUtf8().constData() - ); - buf.append("\" crossrefs=\""); - buf.append((const char*)ReferenceManager::parseVerseReference(ref, options).toUtf8().constData()); //ref must contain the osisRef module marker if there was any - buf.append("\">"); + QString::fromUtf8(myUserData->key->getText()), + mod->module().getLanguage()); + + buf.append("<a href=\"") + .append( // create the hyperlink with key and mod + ReferenceManager::encodeHyperlink( + mod->name(), + ReferenceManager::parseVerseReference(hrefRef, options), + ReferenceManager::typeFromModule(mod->type()) + ).toUtf8().constData() + ) + .append("\" crossrefs=\"") + // ref must contain the osisRef module marker if there was any: + .append(ReferenceManager::parseVerseReference(ref, options).toUtf8().constData()) + .append("\">"); } // should we add something if there were no referenced module available? } diff --git a/src/backend/filters/teitohtml.h b/src/backend/filters/teitohtml.h index f365616..e5ba8f6 100644 --- a/src/backend/filters/teitohtml.h +++ b/src/backend/filters/teitohtml.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -25,9 +25,9 @@ class TeiToHtml: public sword::TEIHTMLHREF { public: /* Methods: */ TeiToHtml(); - /** Reimplemented from sword::OSISHTMLHREF. */ - virtual bool handleToken(sword::SWBuf &buf, const char *token, - sword::BasicFilterUserData *userData); + bool handleToken(sword::SWBuf &buf, + const char *token, + sword::BasicFilterUserData *userData) override; private: /* Methods: */ void renderReference(const char *osisRef, sword::SWBuf &buf, diff --git a/src/backend/filters/thmltohtml.cpp b/src/backend/filters/thmltohtml.cpp index 0bf6e63..5f85766 100644 --- a/src/backend/filters/thmltohtml.cpp +++ b/src/backend/filters/thmltohtml.cpp @@ -2,22 +2,23 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ -#include "backend/filters/thmltohtml.h" +#include "thmltohtml.h" -#include <QString> #include <QRegExp> -#include <QUrl> +#include <QString> #include <QTextCodec> -#include "backend/config/btconfig.h" -#include "backend/drivers/cswordmoduleinfo.h" -#include "backend/managers/clanguagemgr.h" -#include "backend/managers/referencemanager.h" -#include "backend/managers/cswordbackend.h" +#include <QUrl> +#include "../../util/btassert.h" +#include "../config/btconfig.h" +#include "../drivers/cswordmoduleinfo.h" +#include "../managers/clanguagemgr.h" +#include "../managers/cswordbackend.h" +#include "../managers/referencemanager.h" // Sword includes: #include <swmodule.h> @@ -191,9 +192,8 @@ char ThmlToHtml::processText(sword::SWBuf &buf, const sword::SWKey *key, result.append( e ); } - if (list.count()) { - buf = (const char*)result.toUtf8(); - } + if (list.count()) + buf = result.toUtf8(); return 1; } @@ -203,52 +203,51 @@ bool ThmlToHtml::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) { if (!substituteToken(buf, token) && !substituteEscapeString(buf, token)) { - sword::XMLTag tag(token); - UserData* myUserData = dynamic_cast<UserData*>(userData); - sword::SWModule* myModule = const_cast<sword::SWModule*>(myUserData->module); //hack to be able to call stuff like Lang() - - if ( tag.getName() && !sword::stricmp(tag.getName(), "foreign") ) { // a text part in another language, we have to set the right font - - if (tag.getAttribute("lang")) { - const char* abbrev = tag.getAttribute("lang"); - //const CLanguageMgr::Language* const language = CLanguageMgr::instance()->languageForAbbrev( QString::fromLatin1(abbrev) ); - - buf.append("<span class=\"foreign\" lang=\""); - buf.append(abbrev); - buf.append("\">"); - } - } - else if (tag.getName() && !sword::stricmp(tag.getName(), "sync")) { //lemmas, morph codes or strongs - - if (tag.getAttribute("type") && (!sword::stricmp(tag.getAttribute("type"), "morph") || !sword::stricmp(tag.getAttribute("type"), "Strongs") || !sword::stricmp(tag.getAttribute("type"), "lemma"))) { // Morph or Strong - buf.append('<'); - buf.append(token); - buf.append('>'); - } - } - else if (tag.getName() && !sword::stricmp(tag.getName(), "note")) { // <note> tag - - if (!tag.isEndTag() && !tag.isEmpty()) { - //appending is faster than appendFormatted - buf.append(" <span class=\"footnote\" note=\""); - buf.append(myModule->getName()); - buf.append('/'); - buf.append(myUserData->key->getShortText()); - buf.append('/'); - buf.append( QString::number(myUserData->swordFootnote++).toUtf8().constData() ); - buf.append("\">*</span> "); - - myUserData->suspendTextPassThru = true; - myUserData->inFootnoteTag = true; - } - else if (tag.isEndTag() && !tag.isEmpty()) { //end tag - //buf += ")</span>"; - myUserData->suspendTextPassThru = false; - myUserData->inFootnoteTag = false; + sword::XMLTag const tag(token); + BT_ASSERT(dynamic_cast<UserData *>(userData)); + UserData * const myUserData = static_cast<UserData *>(userData); + // Hack to be able to call stuff like Lang(): + sword::SWModule const * const myModule = + const_cast<sword::SWModule *>(myUserData->module); + char const * const tagName = tag.getName(); + if (!tagName) // unknown tag, pass through: + return sword::ThMLHTML::handleToken(buf, token, userData); + if (!sword::stricmp(tagName, "foreign")) { + // A text part in another language, we have to set the right font + + if (const char * const tagLang = tag.getAttribute("lang")) + buf.append("<span class=\"foreign\" lang=\"") + .append(tagLang) + .append("\">"); + } else if (!sword::stricmp(tagName, "sync")) { + // If Morph or Strong or Lemma: + if (const char * const tagType = tag.getAttribute("type")) + if (!sword::stricmp(tagType, "morph") + || !sword::stricmp(tagType, "Strongs") + || !sword::stricmp(tagType, "lemma")) + buf.append('<').append(token).append('>'); + } else if (!sword::stricmp(tagName, "note")) { // <note> tag + if (!tag.isEmpty()) { + if (!tag.isEndTag()) { + buf.append(" <span class=\"footnote\" note=\"") + .append(myModule->getName()) + .append('/') + .append(myUserData->key->getShortText()) + .append('/') + .append(QString::number(myUserData->swordFootnote).toUtf8().constData()) + .append("\">*</span> "); + + myUserData->swordFootnote++; + myUserData->suspendTextPassThru = true; + myUserData->inFootnoteTag = true; + } else if (tag.isEndTag()) { // end tag + // buf += ")</span>"; + myUserData->suspendTextPassThru = false; + myUserData->inFootnoteTag = false; + } } - } - else if (tag.getName() && !sword::stricmp(tag.getName(), "scripRef")) { // a scripRef - //scrip refs which are embeded in footnotes may not be displayed! + } else if (!sword::stricmp(tagName, "scripRef")) { // a scripRef + // scrip refs which are embeded in footnotes may not be displayed! if (!myUserData->inFootnoteTag) { if (tag.isEndTag()) { @@ -257,136 +256,131 @@ bool ThmlToHtml::handleToken(sword::SWBuf &buf, const char *token, myUserData->inscriptRef = false; myUserData->suspendTextPassThru = false; - } - else { // like "<scripRef>John 3:16</scripRef>" - - CSwordModuleInfo* mod = btConfig().getDefaultSwordModuleByType("standardBible"); - //Q_ASSERT(mod); tested later - if (mod) { - ReferenceManager::ParseOptions options; - options.refBase = QString::fromUtf8(myUserData->key->getText()); //current module key - options.refDestinationModule = QString(mod->name()); - options.sourceLanguage = QString(myModule->getLanguage()); - options.destinationLanguage = QString("en"); + } else { // like "<scripRef>John 3:16</scripRef>" + if (CSwordModuleInfo const * const mod = + btConfig().getDefaultSwordModuleByType( + "standardBible")) + { + ReferenceManager::ParseOptions options( + mod->name(), + // current module key: + QString::fromUtf8(myUserData->key->getText()), + myModule->getLanguage()); //it's ok to split the reference, because to descriptive text is given bool insertSemicolon = false; buf.append("<span class=\"crossreference\">"); - QStringList refs = QString::fromUtf8(myUserData->lastTextNode.c_str()).split(";"); - QString oldRef; //the previous reference to use as a base for the next refs - for (QStringList::iterator it(refs.begin()); it != refs.end(); ++it) { - - if (! oldRef.isEmpty() ) { - options.refBase = oldRef; //use the last ref as a base, e.g. Rom 1,2-3, when the next ref is only 3:3-10 - } - const QString completeRef( ReferenceManager::parseVerseReference((*it), options) ); - - oldRef = completeRef; //use the parsed result as the base for the next ref. - - if (insertSemicolon) { //prepend a ref divider if we're after the first one + QStringList const refs( + QString::fromUtf8( + myUserData->lastTextNode.c_str()).split(";")); + QString oldRef; // the previous reference to use as a base for the next refs + for (QStringList::const_iterator it(refs.begin()); + it != refs.end(); + ++it) + { + if (!oldRef.isEmpty()) + options.refBase = oldRef; // Use the last ref as a base, e.g. Rom 1,2-3, when the next ref is only 3:3-10 + + // Use the parsed result as the base for the next ref: + oldRef = ReferenceManager::parseVerseReference( + (*it), + options); + + // Prepend a ref divider if we're after the first one + if (insertSemicolon) buf.append("; "); - } - - buf.append("<a href=\""); - buf.append( - ReferenceManager::encodeHyperlink( - mod->name(), - completeRef, - ReferenceManager::typeFromModule(mod->type()) - ).toUtf8().constData() - ); - - buf.append("\" crossrefs=\""); - buf.append((const char*)completeRef.toUtf8()); - buf.append("\">"); - - buf.append((const char*)(*it).toUtf8()); - - buf.append("</a>"); + buf.append("<a href=\"") + .append( + ReferenceManager::encodeHyperlink( + mod->name(), + oldRef, + ReferenceManager::typeFromModule(mod->type()) + ).toUtf8().constData() + ) + .append("\" crossrefs=\"") + .append(oldRef.toUtf8().constData()) + .append("\">") + .append(it->toUtf8().constData()) + .append("</a>"); insertSemicolon = true; } buf.append("</span>"); //crossref end } - myUserData->suspendTextPassThru = false; } - } - else if (tag.getAttribute("passage") ) { //the passage was given as a parameter value + } else if (tag.getAttribute("passage") ) { + // The passage was given as a parameter value myUserData->inscriptRef = true; myUserData->suspendTextPassThru = false; - const char* ref = tag.getAttribute("passage"); - Q_ASSERT(ref); - - CSwordModuleInfo* mod = btConfig().getDefaultSwordModuleByType("standardBible"); - //Q_ASSERT(mod); tested later - - ReferenceManager::ParseOptions options; - options.refBase = QString::fromUtf8(myUserData->key->getText()); - - options.sourceLanguage = myModule->getLanguage(); - options.destinationLanguage = QString("en"); - - const QString completeRef = ReferenceManager::parseVerseReference(QString::fromUtf8(ref), options); - - if (mod) { - options.refDestinationModule = QString(mod->name()); - buf.append("<span class=\"crossreference\">"); - buf.append("<a href=\""); - buf.append( - ReferenceManager::encodeHyperlink( - mod->name(), - completeRef, - ReferenceManager::typeFromModule(mod->type()) - ).toUtf8().constData() - ); - buf.append("\" crossrefs=\""); - buf.append((const char*)completeRef.toUtf8()); - buf.append("\">"); - } - else { + if (CSwordModuleInfo const * const mod = + btConfig().getDefaultSwordModuleByType( + "standardBible")) + { + ; + BT_ASSERT(tag.getAttribute("passage")); + QString const completeRef( + ReferenceManager::parseVerseReference( + QString::fromUtf8( + tag.getAttribute("passage")), + ReferenceManager::ParseOptions( + mod->name(), + QString::fromUtf8( + myUserData->key->getText()), + myModule->getLanguage()))); + buf.append("<span class=\"crossreference\">") + .append("<a href=\"") + .append( + ReferenceManager::encodeHyperlink( + mod->name(), + completeRef, + ReferenceManager::typeFromModule( + mod->type()) + ).toUtf8().constData() + ) + .append("\" crossrefs=\"") + .append(completeRef.toUtf8().constData()) + .append("\">"); + } else { buf.append("<span><a>"); } - } - else if ( !tag.getAttribute("passage") ) { // we're starting a scripRef like "<scripRef>John 3:16</scripRef>" + } else { // We're starting a scripRef like "<scripRef>John 3:16</scripRef>" myUserData->inscriptRef = false; - - // let's stop text from going to output, the text get's added in the -tag handler + /* Let's stop text from going to output, the text get's + added in the -tag handler: */ myUserData->suspendTextPassThru = true; } } - } - else if (tag.getName() && !sword::stricmp(tag.getName(), "div")) { + } else if (!sword::stricmp(tagName, "div")) { if (tag.isEndTag()) { buf.append("</div>"); + } else if (char const * const tagClass = tag.getAttribute("class")){ + if (!sword::stricmp(tagClass, "sechead") ) { + buf.append("<div class=\"sectiontitle\">"); + } else if (!sword::stricmp(tagClass, "title")) { + buf.append("<div class=\"booktitle\">"); + } } - else if ( tag.getAttribute("class") && !sword::stricmp(tag.getAttribute("class"), "sechead") ) { - buf.append("<div class=\"sectiontitle\">"); - } - else if (tag.getAttribute("class") && !sword::stricmp(tag.getAttribute("class"), "title")) { - buf.append("<div class=\"booktitle\">"); - } - } - else if (tag.getName() && !sword::stricmp(tag.getName(), "img") && tag.getAttribute("src")) { - const char* value = tag.getAttribute("src"); + } else if (!sword::stricmp(tagName, "img") && tag.getAttribute("src")) { + const char * value = tag.getAttribute("src"); - if (value[0] == '/') { + if (value[0] == '/') value++; //strip the first / - } - buf.append("<img src=\""); - QString absPath(QTextCodec::codecForLocale()->toUnicode(myUserData->module->getConfigEntry("AbsoluteDataPath"))); - QString relPath(QString::fromUtf8(value)); - QString url(QUrl::fromLocalFile(absPath.append('/').append(relPath)).toString()); - buf.append(url.toUtf8().data()); - buf.append("\" />"); - } - else { // let unknown token pass thru + buf.append("<img src=\"") + .append( + QUrl::fromLocalFile( + QTextCodec::codecForLocale()->toUnicode( + myUserData->module->getConfigEntry( + "AbsoluteDataPath") + ).append('/').append(QString::fromUtf8(value)) + ).toString().toUtf8().constData()) + .append("\" />"); + } else { // Let unknown token pass thru: return sword::ThMLHTML::handleToken(buf, token, userData); } } - return true; } diff --git a/src/backend/filters/thmltohtml.h b/src/backend/filters/thmltohtml.h index ff40cf9..24b2e1a 100644 --- a/src/backend/filters/thmltohtml.h +++ b/src/backend/filters/thmltohtml.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2014 by the BibleTime developers. +* Copyright 1999-2016 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -40,20 +40,18 @@ class ThmlToHtml: public sword::ThMLHTML { public: /* Methods: */ ThmlToHtml(); - /** Reimplemented from sword::OSISHTMLHREF. */ - virtual bool handleToken(sword::SWBuf &buf, - const char *token, - sword::BasicFilterUserData *userData); + bool handleToken(sword::SWBuf &buf, + const char *token, + sword::BasicFilterUserData *userData) override; - /** Reimplemented from sword::SWFilter. */ - virtual char processText(sword::SWBuf &buf, - const sword::SWKey *key, - const sword::SWModule *module = 0); + char processText(sword::SWBuf &buf, + const sword::SWKey *key, + const sword::SWModule *module = nullptr) override; protected: /* Methods: */ - /** Reimplemented from sword::OSISHTMLHREF. */ - virtual inline sword::BasicFilterUserData *createUserData( - const sword::SWModule *module, const sword::SWKey *key) + + inline sword::BasicFilterUserData *createUserData( + const sword::SWModule *module, const sword::SWKey *key) override { return new UserData(module, key); } diff --git a/src/backend/filters/thmltoplain.cpp b/src/backend/filters/thmltoplain.cpp deleted file mode 100644 index 9f81173..0000000 --- a/src/backend/filters/thmltoplain.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/********* -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2014 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#include "backend/filters/thmltoplain.h" - -#include <QtGlobal> - - -namespace Filters { - -char ThmlToPlain::processText(sword::SWBuf &text, - const sword::SWKey *key, - const sword::SWModule *module) -{ - Q_UNUSED(key); - Q_UNUSED(module); - - char token[2048]; - int tokpos = 0; - bool intoken = false; - bool ampersand = false; - - const char *from; - sword::SWBuf orig = text; - from = orig.c_str(); - for (text = ""; *from; from++) { - if (*from == 10 || *from == 13) - from++; - if (*from == '<') { - intoken = true; - tokpos = 0; - token[0] = 0; - token[1] = 0; - token[2] = 0; - ampersand = false; - continue; - } - else if (*from == '&') { - intoken = true; - tokpos = 0; - token[0] = 0; - token[1] = 0; - token[2] = 0; - ampersand = true; - continue; - } - if (*from == ';' && ampersand) { - intoken = false; - ampersand = false; - - if (!strncmp("nbsp", token, 4)) text += " "; - else if (!strncmp("quot", token, 4)) text += "\""; - else if (!strncmp("amp", token, 3)) text += "&"; - else if (!strncmp("lt", token, 2)) text += "<"; - else if (!strncmp("gt", token, 2)) text += ">"; - else if (!strncmp("brvbar", token, 6)) text += "¦"; - else if (!strncmp("sect", token, 4)) text += "§"; - else if (!strncmp("copy", token, 4)) text += "©"; - else if (!strncmp("laquo", token, 5)) text += "«"; - else if (!strncmp("reg", token, 3)) text += "®"; - else if (!strncmp("acute", token, 5)) text += "´"; - else if (!strncmp("para", token, 4)) text += "¶"; - else if (!strncmp("raquo", token, 5)) text += "»"; - - else if (!strncmp("Aacute", token, 6)) text += "Á"; - else if (!strncmp("Agrave", token, 6)) text += "À"; - else if (!strncmp("Acirc", token, 5)) text += "Â"; - else if (!strncmp("Auml", token, 4)) text += "Ä"; - else if (!strncmp("Atilde", token, 6)) text += "Ã"; - else if (!strncmp("Aring", token, 5)) text += "Å"; - else if (!strncmp("aacute", token, 6)) text += "á"; - else if (!strncmp("agrave", token, 6)) text += "à"; - else if (!strncmp("acirc", token, 5)) text += "â"; - else if (!strncmp("auml", token, 4)) text += "ä"; - else if (!strncmp("atilde", token, 6)) text += "ã"; - else if (!strncmp("aring", token, 5)) text += "å"; - else if (!strncmp("Eacute", token, 6)) text += "É"; - else if (!strncmp("Egrave", token, 6)) text += "È"; - else if (!strncmp("Ecirc", token, 5)) text += "Ê"; - else if (!strncmp("Euml", token, 4)) text += "Ë"; - else if (!strncmp("eacute", token, 6)) text += "é"; - else if (!strncmp("egrave", token, 6)) text += "è"; - else if (!strncmp("ecirc", token, 5)) text += "ê"; - else if (!strncmp("euml", token, 4)) text += "ë"; - else if (!strncmp("Iacute", token, 6)) text += "Í"; - else if (!strncmp("Igrave", token, 6)) text += "Ì"; - else if (!strncmp("Icirc", token, 5)) text += "Î"; - else if (!strncmp("Iuml", token, 4)) text += "Ï"; - else if (!strncmp("iacute", token, 6)) text += "í"; - else if (!strncmp("igrave", token, 6)) text += "ì"; - else if (!strncmp("icirc", token, 5)) text += "î"; - else if (!strncmp("iuml", token, 4)) text += "ï"; - else if (!strncmp("Oacute", token, 6)) text += "Ó"; - else if (!strncmp("Ograve", token, 6)) text += "Ò"; - else if (!strncmp("Ocirc", token, 5)) text += "Ô"; - else if (!strncmp("Ouml", token, 4)) text += "Ö"; - else if (!strncmp("Otilde", token, 6)) text += "Õ"; - else if (!strncmp("oacute", token, 6)) text += "ó"; - else if (!strncmp("ograve", token, 6)) text += "ò"; - else if (!strncmp("ocirc", token, 5)) text += "ô"; - else if (!strncmp("ouml", token, 4)) text += "ö"; - else if (!strncmp("otilde", token, 6)) text += "õ"; - else if (!strncmp("Uacute", token, 6)) text += "Ú"; - else if (!strncmp("Ugrave", token, 6)) text += "Ù"; - else if (!strncmp("Ucirc", token, 5)) text += "Û"; - else if (!strncmp("Uuml", token, 4)) text += "Ü"; - else if (!strncmp("uacute", token, 6)) text += "ú"; - else if (!strncmp("ugrave", token, 6)) text += "ù"; - else if (!strncmp("ucirc", token, 5)) text += "û"; - else if (!strncmp("uuml", token, 4)) text += "ü"; - else if (!strncmp("Yacute", token, 6)) text += "Ý"; - else if (!strncmp("yacute", token, 6)) text += "ý"; - else if (!strncmp("yuml", token, 4)) text += "ÿ"; - - else if (!strncmp("deg", token, 3)) text += "°"; - else if (!strncmp("plusmn", token, 6)) text += "±"; - else if (!strncmp("sup2", token, 4)) text += "²"; - else if (!strncmp("sup3", token, 4)) text += "³"; - else if (!strncmp("sup1", token, 4)) text += "¹"; - else if (!strncmp("nbsp", token, 4)) text += "º"; - else if (!strncmp("pound", token, 5)) text += "£"; - else if (!strncmp("cent", token, 4)) text += "¢"; - else if (!strncmp("frac14", token, 6)) text += "¼"; - else if (!strncmp("frac12", token, 6)) text += "½"; - else if (!strncmp("frac34", token, 6)) text += "¾"; - else if (!strncmp("iquest", token, 6)) text += "¿"; - else if (!strncmp("iexcl", token, 5)) text += "¡"; - else if (!strncmp("ETH", token, 3)) text += "Ð"; - else if (!strncmp("eth", token, 3)) text += "ð"; - else if (!strncmp("THORN", token, 5)) text += "Þ"; - else if (!strncmp("thorn", token, 5)) text += "þ"; - else if (!strncmp("AElig", token, 5)) text += "Æ"; - else if (!strncmp("aelig", token, 5)) text += "æ"; - else if (!strncmp("Oslash", token, 6)) text += "Ø"; - else if (!strncmp("curren", token, 6)) text += "¤"; - else if (!strncmp("Ccedil", token, 6)) text += "Ç"; - else if (!strncmp("ccedil", token, 6)) text += "ç"; - else if (!strncmp("szlig", token, 5)) text += "ß"; - else if (!strncmp("Ntilde", token, 6)) text += "Ñ"; - else if (!strncmp("ntilde", token, 6)) text += "ñ"; - else if (!strncmp("yen", token, 3)) text += "¥"; - else if (!strncmp("not", token, 3)) text += "¬"; - else if (!strncmp("ordf", token, 4)) text += "ª"; - else if (!strncmp("uml", token, 3)) text += "¨"; - else if (!strncmp("shy", token, 3)) text += ""; - else if (!strncmp("macr", token, 4)) text += "¯"; - else if (!strncmp("micro", token, 5)) text += "µ"; - else if (!strncmp("middot", token, 6)) text += "·"; - else if (!strncmp("cedil", token, 5)) text += "¸"; - else if (!strncmp("ordm", token, 4)) text += "º"; - else if (!strncmp("times", token, 5)) text += "×"; - else if (!strncmp("divide", token, 6)) text += "÷"; - else if (!strncmp("oslash", token, 6)) text += "ø"; - continue; - - } - else if (*from == '>' && !ampersand) { - intoken = false; - // process desired tokens - if (!strncmp(token, "sync type=\"Strongs\" value=\"", 27)) { - text += ' '; - text += '<'; - for (unsigned int i = 27; token[i] != '\"'; i++) - text += token[i]; - text += '>'; - continue; - } - if (!strncmp(token, "sync type=\"morph\" value=\"", 25)) { - text += ' '; - text += '('; - for (unsigned int i = 25; token[i] != '\"'; i++) - text += token[i]; - text += ')'; - continue; - } - if (!strncmp("note", token, 4)) { - text += ' '; - text += '('; - } - else if (!strncmp("br", token, 2)) - text += '\n'; - else if (!strncmp("/p", token, 2)) - text += '\n'; - else if (!strncmp("/note", token, 5)) { - text += ')'; - text += ' '; - } - continue; - } - if (intoken) { - if (tokpos < 2045) - token[tokpos++] = *from; - token[tokpos+2] = 0; - } - else text += *from; - } - - orig = text; - from = orig.c_str(); - for (text = ""; *from; from++) { //loop to remove extra spaces - if ((strchr(" \t\n\r", *from))) { - while (*(from + 1) && (strchr(" \t\n\r", *(from + 1)))) { - from++; - } - text += " "; - } - else { - text += *from; - } - } - text += (char)0; - - return 0; -} - -} // namespace Filters diff --git a/src/backend/filters/thmltoplain.h b/src/backend/filters/thmltoplain.h deleted file mode 100644 index 68a5d95..0000000 --- a/src/backend/filters/thmltoplain.h +++ /dev/null @@ -1,35 +0,0 @@ -/********* -* -* In the name of the Father, and of the Son, and of the Holy Spirit. -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2014 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#ifndef FILTERS_THMLTOPLAIN_H -#define FILTERS_THMLTOPLAIN_H - -// Sword includes: -#include <swbuf.h> -#include <swfilter.h> - - -namespace Filters { - -/** - \brief ThML text to plain text conversion filter -*/ -class ThmlToPlain: public sword::SWFilter { - protected: /* Methods: */ - /** Reimplemented from sword::SWFilter. */ - virtual char processText(sword::SWBuf &text, - const sword::SWKey *key = 0, - const sword::SWModule *module = 0); -}; - -} // namespace Filters - -#endif |