2
// C++ Implementation: cdisplayrendering
7
// Author: The BibleTime team <info@bibletime.info>, (C) 2004
9
// Copyright: See COPYING file that comes with this distribution
14
#include "cdisplayrendering.h"
16
#include "cdisplaytemplatemgr.h"
17
#include "creferencemanager.h"
18
#include "cswordkey.h"
19
#include "cswordversekey.h"
27
CDisplayRendering::CDisplayRendering(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
28
: CHTMLExportRendering(CHTMLExportRendering::Settings(true), displayOptions, filterOptions) {}
30
const QString CDisplayRendering::entryLink( const KeyTreeItem& item, CSwordModuleInfo* module ) {
33
const bool isBible = module && (module->type() == CSwordModuleInfo::Bible);
34
CSwordVerseKey vk(module); //only valid for bible modules, i.e. isBible == true
41
if (isBible && (vk.Verse() == 0)) {
42
return QString::null; //Warning: return already here
45
switch (item.settings().keyRenderingFace) {
47
case KeyTreeItem::Settings::NoKey: {
48
linkText = QString::null;
49
break; //no key is valid for all modules
52
case KeyTreeItem::Settings::CompleteShort: {
54
linkText = QString::fromUtf8(vk.getShortText());
58
//fall through for non-Bible modules
61
case KeyTreeItem::Settings::CompleteLong: {
67
//fall through for non-Bible modules
70
case KeyTreeItem::Settings::SimpleKey: {
72
linkText = QString::number(vk.Verse());
76
//fall through for non-Bible modules
79
default: { //default behaviour to return the passed key
80
linkText = item.key();
85
if (linkText.isEmpty()) {
86
return QString("<a name=\"").append(keyToHTMLAnchor(item.key())).append("\" />");
89
return QString("<a name=\"").append(keyToHTMLAnchor(item.key())).append("\" ")
91
.append(CReferenceManager::encodeHyperlink(
92
module->name(), item.key(), CReferenceManager::typeFromModule(module->type()))
94
.append("\">").append(linkText).append("</a>\n");
100
const QString CDisplayRendering::keyToHTMLAnchor(const QString& key) {
102
ret = ret.stripWhiteSpace().remove(QRegExp("[^A-Za-z0-9]+"));
103
ret = ret.remove(QRegExp("^\\d+|"));
108
const QString CDisplayRendering::finishText( const QString& oldText, KeyTree& tree ) {
109
ListCSwordModuleInfo modules = tree.collectModules();
112
//marking words is very slow, we have to find a better solution
115
//mark all words by spans
117
QString text = oldText;
119
QRegExp re("(\\b)(?=\\w)"); //word begin marker
120
int pos = text.find(re, 0);
122
while (pos != -1) { //word begin found
123
//qWarning("found word at %i in %i", pos, text.length());
124
int endPos = pos + 1;
125
if (!CToolClass::inHTMLTag(pos+1, text)) { //the re has a positive look ahead which matches one char before the word start
126
//qWarning("matched %s", text.mid(pos+1, 4).latin1());
128
//find end of word and put a marker around it
129
endPos = text.find(QRegExp("\\b|[,.:]"), pos+1);
130
if ((endPos != -1) && !CToolClass::inHTMLTag(endPos, text) && (endPos - pos >= 3)) { //reuire wordslonger than 3 chars
131
text.insert(endPos, "</span>");
132
text.insert(pos, "<span class=\"word\">");
137
pos = text.find(re, endPos);
140
const CLanguageMgr::Language* const lang =
141
(modules.count() >= 1)
142
? modules.first()->language()
143
: CPointers::languageMgr()->defaultLanguage();
145
CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager();
147
Q_ASSERT(modules.count() >= 1);
149
CDisplayTemplateMgr::Settings settings;
150
settings.modules = modules;
151
settings.langAbbrev = ((modules.count() == 1) && lang->isValid())
154
settings.pageDirection = (modules.count() == 1)
155
? ((modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl")
158
return tMgr->fillTemplate(CBTConfig::get
159
(CBTConfig::displayStyle), oldText, settings);