summaryrefslogtreecommitdiff
path: root/src/modules/filters/gbfrtf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/filters/gbfrtf.cpp')
-rw-r--r--src/modules/filters/gbfrtf.cpp294
1 files changed, 153 insertions, 141 deletions
diff --git a/src/modules/filters/gbfrtf.cpp b/src/modules/filters/gbfrtf.cpp
index 5f7d064..4a18fbf 100644
--- a/src/modules/filters/gbfrtf.cpp
+++ b/src/modules/filters/gbfrtf.cpp
@@ -1,35 +1,42 @@
/******************************************************************************
*
- * gbfrtf - SWFilter decendant to convert all GBF tags to RTF tags
+ * gbfrtf - SWFilter descendant to convert all GBF tags to RTF tags
*/
-#include <stdlib.h>
-#include <string.h>
#include <gbfrtf.h>
#include <ctype.h>
+SWORD_NAMESPACE_START
+
GBFRTF::GBFRTF() {
}
-char GBFRTF::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
+char GBFRTF::processText(SWBuf &text, const SWKey *key, const SWModule *module)
{
- unsigned char *to, *from;
char token[2048];
+ char val[128];
+ char *valto;
+ char *num;
int tokpos = 0;
bool intoken = false;
int len;
const char *tok;
+ SWBuf strongnum;
+ SWBuf strongtense;
+ bool hideText = false;
+ int wordLen = 0;
+ int wordCount = 0;
+ int i;
- len = strlen(text) + 1; // shift string to right of buffer
- if (len < maxlen) {
- memmove(&text[maxlen - len], text, len);
- from = (unsigned char *)&text[maxlen - len];
- }
- else from = (unsigned char *)text; // -------------------------------
- for (to = (unsigned char *)text; *from; from++) {
+ const char *from;
+ SWBuf orig = text;
+ from = orig.c_str();
+ for (text = ""; *from; from++) {
if (*from == '<') {
+ wordLen = wordCount;
+ wordCount = 0;
intoken = true;
tokpos = 0;
token[0] = 0;
@@ -40,39 +47,80 @@ char GBFRTF::ProcessText(char *text, int maxlen, const SWKey *key, const SWModul
if (*from == '>') {
intoken = false;
// process desired tokens
+ // deal with OSIS note tags. Just hide till OSISRTF
+ if (!strncmp(token, "note ", 5)) {
+ hideText = true;
+ }
+ if (!strncmp(token, "/note", 5)) {
+ hideText = false;
+ }
+
switch (*token) {
+ case 'w': // OSIS Word (temporary until OSISRTF is done)
+ strongnum = "";
+ strongtense = "";
+ valto = val;
+ num = strstr(token, "lemma=\"x-Strongs:");
+ if (num) {
+ for (num+=17; ((*num) && (*num != '\"')); num++)
+ *valto++ = *num;
+ *valto = 0;
+ if (atoi((!isdigit(*val))?val+1:val) < 5627) {
+ // normal strongs number
+ strongnum += "{\\cf3 \\sub <";
+ for (tok = (!isdigit(*val))?val+1:val; *tok; tok++)
+ strongnum += *tok;
+ strongnum += ">}";
+ }
+ /* forget these for now
+ else {
+ // verb morph
+ sprintf(wordstr, "%03d", word-1);
+ module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
+ }
+ */
+ }
+ valto = val;
+ num = strstr(token, "morph=\"x-Robinson:");
+ if (num) {
+ for (num+=18; ((*num) && (*num != '\"')); num++)
+ *valto++ = *num;
+ *valto = 0;
+ // normal robinsons tense
+ strongtense += "{\\cf4 \\sub (";
+ for (tok = val; *tok; tok++)
+ strongtense += *tok;
+ strongtense += ")}";
+ }
+ continue;
+
+ case '/':
+ if (token[1] == 'w') {
+ if ((wordCount > 0) || (strongnum != "{\\cf3 \\sub <3588>}")) {
+ //for (i = 0; i < strongnum.length(); i++)
+ text += strongnum;
+ //for (i = 0; i < strongtense.length(); i++)
+ text += strongtense;
+ }
+ }
+ continue;
+
case 'W': // Strongs
switch(token[1]) {
case 'G': // Greek
case 'H': // Hebrew
- *to++ = '{';
- *to++ = '\\';
- *to++ = 'f';
- *to++ = 's';
- *to++ = '1';
- *to++ = '7';
- *to++ = ' ';
- *to++ = '<';
+ text += "{\\cf3 \\sub <";
for (tok = token + 2; *tok; tok++)
- *to++ = *tok;
- *to++ = '>';
- *to++ = '}';
+ text += *tok;
+ text += ">}";
continue;
case 'T': // Tense
- *to++ = '{';
- *to++ = '\\';
- *to++ = 'f';
- *to++ = 's';
- *to++ = '1';
- *to++ = '7';
- *to++ = ' ';
- *to++ = '(';
+ text += "{\\cf4 \\sub (";
bool separate = false;
for (tok = token + 2; *tok; tok++) {
if (separate) {
- *to++ = ';';
- *to++ = ' ';
+ text += "; ";
separate = false;
}
switch (*tok) {
@@ -80,7 +128,7 @@ char GBFRTF::ProcessText(char *text, int maxlen, const SWKey *key, const SWModul
case 'H':
for (tok++; *tok; tok++) {
if (isdigit(*tok)) {
- *to++ = *tok;
+ text += *tok;
separate = true;
}
else {
@@ -91,176 +139,134 @@ char GBFRTF::ProcessText(char *text, int maxlen, const SWKey *key, const SWModul
break;
default:
for (; *tok; tok++) {
- *to++ = *tok;
+ text += *tok;
}
}
}
- *to++ = ')';
- *to++ = '}';
+ text += ")}";
continue;
}
break;
case 'R':
switch(token[1]) {
case 'X':
- *to++ = '#';
+ text += "<a href=\"\">";
continue;
case 'x':
- *to++ = '|';
+ text += "</a>";
continue;
case 'F': // footnote begin
- *to++ = '{';
- *to++ = '\\';
- *to++ = 'i';
- *to++ = '1';
- *to++ = ' ';
- *to++ = '\\';
- *to++ = 'f';
- *to++ = 's';
- *to++ = '1';
- *to++ = '7';
- *to++ = ' ';
- *to++ = '(';
+ text += "{\\i1 \\sub (";
continue;
case 'f': // footnote end
- *to++ = ')';
- *to++ = ' ';
- *to++ = '}';
+ text += ") }";
continue;
}
break;
case 'F': // font tags
switch(token[1]) {
case 'I': // italic start
- *to++ = '\\';
- *to++ = 'i';
- *to++ = '1';
- *to++ = ' ';
+ text += "\\i1 ";
continue;
case 'i': // italic end
- *to++ = '\\';
- *to++ = 'i';
- *to++ = '0';
- *to++ = ' ';
+ text += "\\i0 ";
continue;
case 'B': // bold start
- *to++ = '\\';
- *to++ = 'b';
- *to++ = '1';
- *to++ = ' ';
+ text += "\\b1 ";
continue;
case 'b': // bold end
- *to++ = '\\';
- *to++ = 'b';
- *to++ = '0';
- *to++ = ' ';
+ text += "\\b0 ";
continue;
case 'N':
- *to++ = '{';
- if (!strnicmp(token+2, "Symbol", 6)) {
- *to++ = '\\';
- *to++ = 'f';
- *to++ = '7';
- *to++ = ' ';
- }
+ text += '{';
+ if (!strnicmp(token+2, "Symbol", 6))
+ text += "\\f7 ";
+ if (!strnicmp(token+2, "Courier", 7))
+ text += "\\f8 ";
continue;
case 'n':
- *to++ = '}';
+ text += '}';
continue;
case 'S':
- *to++ = '{';
- *to++ = '\\';
- *to++ = 's';
- *to++ = 'u';
- *to++ = 'p';
- *to++ = 'e';
- *to++ = 'r';
- *to++ = ' ';
+ text += "{\\super ";
continue;
case 's':
- *to++ = '}';
+ text += '}';
continue;
case 'R':
- *to++ = '{';
- *to++ = '\\';
- *to++ = 'c';
- *to++ = 'f';
- *to++ = '6';
- *to++ = ' ';
+ text += "{\\cf6 ";
continue;
case 'r':
- *to++ = '}';
+ text += '}';
+ continue;
+ case 'O':
+ case 'C':
+ text += "\\scaps1 ";
+ continue;
+ case 'o':
+ case 'c':
+ text += "\\scaps0 ";
+ continue;
+ case 'V':
+ text += "{\\sub ";
+ continue;
+ case 'v':
+ text += '}';
+ continue;
+ case 'U':
+ text += "\\ul1 ";
+ continue;
+ case 'u':
+ text += "\\ul0 ";
continue;
}
break;
case 'C': // special character tags
switch(token[1]) {
case 'A': // ASCII value
- *to++ = (char)atoi(&token[2]);
+ text += (char)atoi(&token[2]);
continue;
case 'G':
- *to++ = '>';
+ text += '>';
continue;
case 'L': // line break
- *to++ = '\\';
- *to++ = 'l';
- *to++ = 'i';
- *to++ = 'n';
- *to++ = 'e';
- *to++ = ' ';
+ text += "\\line ";
continue;
case 'M': // new paragraph
- *to++ = '\\';
- *to++ = 'p';
- *to++ = 'a';
- *to++ = 'r';
- *to++ = ' ';
+ text += "\\par ";
continue;
case 'T':
- *to++ = '<';
+ text += '<';
}
break;
case 'T': // title formatting
switch(token[1])
{
case 'T': // Book title begin
- *to++ = '{';
- *to++ = '\\';
- *to++ = 'f';
- *to++ = 's';
- *to++ = '2';
- *to++ = '2';
- *to++ = ' ';
- continue;
+ text += "{\\large ";
+ continue;
case 't':
- *to++ = '}';
- continue;
+ text += '}';
+ continue;
case 'S':
- *to++ = '\\';
- *to++ = 'p';
- *to++ = 'a';
- *to++ = 'r';
- *to++ = ' ';
- *to++ = '{';
- *to++ = '\\';
- *to++ = 'i';
- *to++ = '1';
- *to++ = '\\';
- *to++ = 'b';
- *to++ = '1';
- *to++ = ' ';
+ text += "\\par {\\i1\\b1 ";
continue;
case 's':
- *to++ = '}';
- *to++ = '\\';
- *to++ = 'p';
- *to++ = 'a';
- *to++ = 'r';
- *to++ = ' ';
+ text += "}\\par ";
continue;
}
break;
-
+ case 'J': // Strongs
+ switch(token[1]) {
+ case 'L':
+ text += "\\ql ";
+ case 'C':
+ text += "\\qc ";
+ case 'R':
+ text += "\\qr ";
+ case 'F':
+ text += "\\qj ";
+ }
}
continue;
}
@@ -269,9 +275,15 @@ char GBFRTF::ProcessText(char *text, int maxlen, const SWKey *key, const SWModul
token[tokpos++] = *from;
token[tokpos+2] = 0;
}
- else *to++ = *from;
+ else {
+ if (!hideText) {
+ wordCount++;
+ text += *from;
+ }
+ }
}
- *to++ = 0;
- *to = 0;
return 0;
}
+
+SWORD_NAMESPACE_END
+