1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
#include "readerview.h"
#include <gdkmm/rgba.h>
#include <algorithm>
#include <libbible.h>
#include <iostream>
using namespace std;
std::vector<libbible::passage> conf;
std::string getCurrMod() {
auto mods = libbible::getModuleNames();
std::string currMod = libbible::settingsRead("biblereader::currMod");
if(std::find(mods.begin(), mods.end(), currMod) == mods.end()) {
currMod = libbible::settingsRead("module");
if(std::find(mods.begin(), mods.end(), currMod) == mods.end()) {
if(! mods.empty()) {
// New default mod (previous was deleted)
currMod = *mods.begin();
libbible::settingsWrite("module", currMod);
libbible::settingsWrite("biblereader::currMod", currMod);
} else {
currMod = std::string();
}
}
}
return currMod;
}
ReaderView::ReaderView()
: text()
{
text.set_editable(false);
text.set_cursor_visible(false);
text.set_wrap_mode(Gtk::WrapMode::WRAP_WORD_CHAR);
//text.override_background_color(*(new Gdk::RGBA("#1d1f21")));
//text.override_color(*(new Gdk::RGBA("#c5c8c6")));
auto scroll = new Gtk::ScrolledWindow();
scroll->add(text);
add(*scroll);
// Open the passage we had last time
setBook(libbible::settingsRead("book"));
if(libbible::settingsRead("book").empty() || getChapter() == 0) {
setBook("Genesis");
}
refresh();
}
ReaderView::~ReaderView() {}
void ReaderView::setChapter(unsigned int chapter) {
libbible::settingsWriteInt("chapter", chapter);
}
unsigned int ReaderView::getChapter() {
if(conf.empty()) return 0;
return libbible::settingsReadInt("chapter");
}
unsigned int ReaderView::getChapterMax() {
if(conf.empty()) return 0;
return conf.back().chapterEnd;
}
void ReaderView::setBook(std::string book) {
libbible::settingsWrite("book", book);
conf = libbible::getPassages(getCurrMod(), book);
}
std::string ReaderView::getBook() {
if(conf.empty()) return "";
return conf[0].bookShort;
}
std::string ReaderView::getBookFull() {
if(conf.empty()) return "";
return conf[0].book;
}
std::vector<std::string> ReaderView::getAllBooks() {
string currMod = getCurrMod();
if(currMod.empty()) {
return vector<string>();
}
return libbible::getBooks(currMod);
}
void ReaderView::refresh() {
auto buf = text.get_buffer();
buf->set_text(""); // Clear contents
string currMod = getCurrMod();
if(currMod.empty()) {
auto iter = buf->get_iter_at_offset(0);
iter = buf->insert_markup(iter, "<big><b>No modules installed.</b></big>\n");
iter = buf->insert_markup(iter, "Please download some modules at:\n");
iter = buf->insert_markup(iter, "\thttp://crosswire.org/sword/modules/ModDisp.jsp?modType=Bibles\n");
iter = buf->insert_markup(iter, "Then install them using the menu in the upper right corner, or use the built-in installer to download and install modules.");
return;
}
conf = libbible::getPassages(getCurrMod(), getBook());
if(getChapter() > conf.size()) {
setChapter(1);
}
auto texts = libbible::getText(conf[getChapter()-1]);
auto iter = buf->get_iter_at_offset(0);
auto verseSize = buf->create_tag();
verseSize->property_size() = libbible::settingsReadInt("fontsize");
if(verseSize->property_size() == 0) {
verseSize->property_size() = 12000;
}
auto verseScale = buf->create_tag();
verseScale->property_scale() = 0.8;
auto titleScale = buf->create_tag();
titleScale->property_scale() = 1.5;
titleScale->property_weight() = 600;
auto verseOffset = buf->create_tag();
verseOffset->property_rise() = 3000;
auto indent = buf->create_tag();
indent->property_left_margin() = 40;
auto redletter = buf->create_tag();
redletter->property_foreground_gdk() = Gdk::Color("red");
int verse = 0;
string indentString = " ";
bool isNewline = true;
for(auto tex : texts) {
std::vector<Glib::RefPtr<Gtk::TextBuffer::Tag>> tags = {verseSize};
bool isParagraph = false;
bool isIndent = false;
bool isDivineName = false;
bool isPreverse = false;
for(string modifier : tex.modifiers) {
if(modifier == "paragraph") {
isParagraph = true;
} else if (modifier == "line indent0") {
isIndent = true;
} else if (modifier == "divineName") {
isDivineName = true;
} else if (modifier == "wordsOfJesus") {
tags.push_back(redletter);
} else if (modifier == "title") {
tags.push_back(titleScale);
// Ensure newline
if(!tex.text.empty() and tex.text.back() != '\n') {
tex.text.push_back('\n');
}
} else if (modifier == "preverse") {
isPreverse = true;
} else if (modifier == "parallel") {
// We don't support this (yet)
tex.text = "";
}
}
if(isIndent) {
isParagraph = false;
if(isNewline) {
tags.push_back(indent);
}
}
if(isParagraph) {
iter = buf->insert_with_tags(iter, indentString, tags);
}
if(tex.verse != verse && ! isPreverse) {
std::vector<Glib::RefPtr<Gtk::TextBuffer::Tag>> verseTags(tags.begin(), tags.end());
verseTags.push_back(verseScale);
verseTags.push_back(verseOffset);
iter = buf->insert_with_tags(iter, " " + std::to_string(tex.verse), verseTags);
verse = tex.verse;
}
if(isDivineName) {
// There's no small caps support. Sigh. We do fake small caps instead.
// Because i lazy, first letter is normal caps and rest small caps, always.
transform(tex.text.begin(), tex.text.end(), tex.text.begin(), ::toupper);
iter = buf->insert_with_tags(iter, tex.text.substr(0, 1), tags);
auto tag = buf->create_tag();
tag->property_scale() = 0.75;
tags.push_back(tag);
iter = buf->insert_with_tags(iter, tex.text.substr(1), tags);
} else {
iter = buf->insert_with_tags(iter, tex.text, tags);
}
if(!tex.text.empty() and tex.text.back() == '\n') {
isNewline = true;
} else {
isNewline = false;
}
}
}
|