Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

thmlrtf.cpp

00001 /***************************************************************************
00002                      thmlrtf.cpp  -  ThML to RTF filter
00003                              -------------------
00004     begin                : 1999-10-27
00005     copyright            : 2001 by CrossWire Bible Society
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 
00017 #include <stdlib.h>
00018 #include <string.h>
00019 #include <thmlrtf.h>
00020 
00021 
00022 ThMLRTF::ThMLRTF()
00023 {
00024         setTokenStart("<");
00025         setTokenEnd(">");
00026 
00027         setEscapeStart("&");
00028         setEscapeEnd(";");
00029 
00030         setEscapeStringCaseSensitive(true);
00031 
00032         addEscapeStringSubstitute("nbsp", " ");
00033         addEscapeStringSubstitute("quot", "\"");
00034         addEscapeStringSubstitute("amp", "&");
00035         addEscapeStringSubstitute("lt", "<");
00036         addEscapeStringSubstitute("gt", ">");
00037         addEscapeStringSubstitute("brvbar", "|");
00038         addEscapeStringSubstitute("sect", "§");
00039         addEscapeStringSubstitute("copy", "©");
00040         addEscapeStringSubstitute("laquo", "«");
00041         addEscapeStringSubstitute("reg", "®");
00042         addEscapeStringSubstitute("acute", "´");
00043         addEscapeStringSubstitute("para", "¶");
00044         addEscapeStringSubstitute("raquo", "»");
00045 
00046         addEscapeStringSubstitute("Aacute", "Á");
00047         addEscapeStringSubstitute("Agrave", "À");
00048         addEscapeStringSubstitute("Acirc", "Â");
00049         addEscapeStringSubstitute("Auml", "Ä");
00050         addEscapeStringSubstitute("Atilde", "Ã");
00051         addEscapeStringSubstitute("Aring", "Å");
00052         addEscapeStringSubstitute("aacute", "á");
00053         addEscapeStringSubstitute("agrave", "à");
00054         addEscapeStringSubstitute("acirc", "â");
00055         addEscapeStringSubstitute("auml", "ä");
00056         addEscapeStringSubstitute("atilde", "ã");
00057         addEscapeStringSubstitute("aring", "å");
00058         addEscapeStringSubstitute("Eacute", "É");
00059         addEscapeStringSubstitute("Egrave", "È");
00060         addEscapeStringSubstitute("Ecirc", "Ê");
00061         addEscapeStringSubstitute("Euml", "Ë");
00062         addEscapeStringSubstitute("eacute", "é");
00063         addEscapeStringSubstitute("egrave", "è");
00064         addEscapeStringSubstitute("ecirc", "ê");
00065         addEscapeStringSubstitute("euml", "ë");
00066         addEscapeStringSubstitute("Iacute", "Í");
00067         addEscapeStringSubstitute("Igrave", "Ì");
00068         addEscapeStringSubstitute("Icirc", "Î");
00069         addEscapeStringSubstitute("Iuml", "Ï");
00070         addEscapeStringSubstitute("iacute", "í");
00071         addEscapeStringSubstitute("igrave", "ì");
00072         addEscapeStringSubstitute("icirc", "î");
00073         addEscapeStringSubstitute("iuml", "ï");
00074         addEscapeStringSubstitute("Oacute", "Ó");
00075         addEscapeStringSubstitute("Ograve", "Ò");
00076         addEscapeStringSubstitute("Ocirc", "Ô");
00077         addEscapeStringSubstitute("Ouml", "Ö");
00078         addEscapeStringSubstitute("Otilde", "Õ");
00079         addEscapeStringSubstitute("oacute", "ó");
00080         addEscapeStringSubstitute("ograve", "ò");
00081         addEscapeStringSubstitute("ocirc", "ô");
00082         addEscapeStringSubstitute("ouml", "ö");
00083         addEscapeStringSubstitute("otilde", "õ");
00084         addEscapeStringSubstitute("Uacute", "Ú");
00085         addEscapeStringSubstitute("Ugrave", "Ù");
00086         addEscapeStringSubstitute("Ucirc", "Û");
00087         addEscapeStringSubstitute("Uuml", "Ü");
00088         addEscapeStringSubstitute("uacute", "ú");
00089         addEscapeStringSubstitute("ugrave", "ù");
00090         addEscapeStringSubstitute("ucirc", "û");
00091         addEscapeStringSubstitute("uuml", "ü");
00092         addEscapeStringSubstitute("Yacute", "Ý");
00093         addEscapeStringSubstitute("yacute", "ý");
00094         addEscapeStringSubstitute("yuml", "ÿ");
00095 
00096         addEscapeStringSubstitute("deg", "°");
00097         addEscapeStringSubstitute("plusmn", "±");
00098         addEscapeStringSubstitute("sup2", "²");
00099         addEscapeStringSubstitute("sup3", "³");
00100         addEscapeStringSubstitute("sup1", "¹");
00101         addEscapeStringSubstitute("nbsp", "º");
00102         addEscapeStringSubstitute("pound", "£");
00103         addEscapeStringSubstitute("cent", "¢");
00104         addEscapeStringSubstitute("frac14", "¼");
00105         addEscapeStringSubstitute("frac12", "½");
00106         addEscapeStringSubstitute("frac34", "¾");
00107         addEscapeStringSubstitute("iquest", "¿");
00108         addEscapeStringSubstitute("iexcl", "¡");
00109         addEscapeStringSubstitute("ETH", "Ð");
00110         addEscapeStringSubstitute("eth", "ð");
00111         addEscapeStringSubstitute("THORN", "Þ");
00112         addEscapeStringSubstitute("thorn", "þ");
00113         addEscapeStringSubstitute("AElig", "Æ");
00114         addEscapeStringSubstitute("aelig", "æ");
00115         addEscapeStringSubstitute("Oslash", "Ø");
00116         addEscapeStringSubstitute("curren", "¤");
00117         addEscapeStringSubstitute("Ccedil", "Ç");
00118         addEscapeStringSubstitute("ccedil", "ç");
00119         addEscapeStringSubstitute("szlig", "ß");
00120         addEscapeStringSubstitute("Ntilde", "Ñ");
00121         addEscapeStringSubstitute("ntilde", "ñ");
00122         addEscapeStringSubstitute("yen", "¥");
00123         addEscapeStringSubstitute("not", "¬");
00124         addEscapeStringSubstitute("ordf", "ª");
00125         addEscapeStringSubstitute("uml", "¨");
00126         addEscapeStringSubstitute("shy", "­");
00127         addEscapeStringSubstitute("macr", "¯");
00128 
00129         setTokenCaseSensitive(true);
00130 
00131         addTokenSubstitute("/note", ") }");
00132 
00133         addTokenSubstitute("br", "\\line ");
00134         addTokenSubstitute("br /", "\\line ");
00135         addTokenSubstitute("i", "{\\i1 ");
00136         addTokenSubstitute("/i", "}");
00137         addTokenSubstitute("b", "{\\b1 ");
00138         addTokenSubstitute("/b", "}");
00139         addTokenSubstitute("p", "\\par ");
00140 
00141         //we need uppercase forms for the moment to support a few early ThML modules that aren't XHTML compliant
00142         addTokenSubstitute("BR", "\\line ");
00143         addTokenSubstitute("I", "{\\i1 ");
00144         addTokenSubstitute("/I", "}");
00145         addTokenSubstitute("B", "{\\b1 ");
00146         addTokenSubstitute("/B", "}");
00147         addTokenSubstitute("P", "\\par ");
00148 }
00149 
00150 bool ThMLRTF::handleToken(char **buf, const char *token, DualStringMap &userData) {
00151         if (!substituteToken(buf, token)) {
00152         // manually process if it wasn't a simple substitution
00153                 if (!strncmp(token, "sync type=\"Strongs\" value=\"", 27)) {
00154                         if (token[27] == 'H' || token[27] == 'G' || token[27] == 'A') {
00155                                 pushString(buf, " {\\fs15 <");
00156                                 for (unsigned int i = 28; token[i] != '\"'; i++)
00157                                         *(*buf)++ = token[i];
00158                                 pushString(buf, ">}");
00159                                     }
00160                                     else if (token[27] == 'T') {
00161                                                   pushString(buf, " {\\fs15 (");
00162                                 for (unsigned int i = 28; token[i] != '\"'; i++)
00163                                         *(*buf)++ = token[i];
00164                                 pushString(buf, ")}");
00165                                     }
00166                 }
00167                 else if (!strncmp(token, "sync type=\"morph\" ", 18)) {
00168                         pushString(buf, " {\\fs15 (");
00169                         for (const char *tok = token + 5; *tok; tok++) {
00170                                 if (!strncmp(tok, "value=\"", 7)) {
00171                                         tok += 7;
00172                                         for (;*tok != '\"'; tok++)
00173                                                 *(*buf)++ = *tok;
00174                                         break;
00175                                 }
00176                         }
00177 
00178                         pushString(buf, ")}");
00179                 }
00180                 else if (!strncmp(token, "sync type=\"lemma\" value=\"", 25)) {
00181                         pushString(buf, "{\\fs15 (");
00182                         for (unsigned int i = 25; token[i] != '\"'; i++)
00183                                 *(*buf)++ = token[i];
00184                         pushString(buf, ")}");
00185                 }
00186                 else if (!strncmp(token, "scripRef", 8)) {
00187 //                      pushString(buf, "{\\cf2 #");
00188                         pushString(buf, "<a href=\"\">");
00189                 }
00190                 else if (!strncmp(token, "/scripRef", 9)) {
00191                         pushString(buf, "</a>");
00192                 }
00193                 else if (!strncmp(token, "div", 3)) {
00194                         *(*buf)++ = '{';
00195                         if (!strncmp(token, "div class=\"title\"", 17)) {
00196                                 pushString(buf, "\\par\\i1\\b1 ");
00197                                 userData["sechead"] = "true";
00198                         }
00199                         else if (!strncmp(token, "div class=\"sechead\"", 19)) {
00200                                 pushString(buf, "\\par\\i1\\b1 ");
00201                                 userData["sechead"] = "true";
00202                         }
00203                 }
00204                 else if (!strncmp(token, "/div", 4)) {
00205                         *(*buf)++ = '}';
00206                         if (userData["sechead"] == "true") {
00207                                 pushString(buf, "\\par ");
00208                                 userData["sechead"] == "false";
00209                         }
00210                 }
00211                 else if (!strncmp(token, "note", 4)) {
00212                         pushString(buf, " {\\i1\\fs15 (");
00213                 }
00214 
00215                 else {
00216                         return false;  // we still didn't handle token
00217                 }
00218         }
00219         return true;
00220 }
00221 
00222 

Generated on Thu Jun 20 22:13:01 2002 for The Sword Project by doxygen1.2.15