[sword-svn] r3072 - in trunk: include src/modules/filters

refdoc at crosswire.org refdoc at crosswire.org
Tue Mar 4 17:22:27 MST 2014


Author: refdoc
Date: 2014-03-04 17:22:26 -0700 (Tue, 04 Mar 2014)
New Revision: 3072

Modified:
   trunk/include/gbflatex.h
   trunk/src/modules/filters/gbflatex.cpp
Log:
GBF to LaTeX filters 


Modified: trunk/include/gbflatex.h
===================================================================
--- trunk/include/gbflatex.h	2014-03-05 00:10:10 UTC (rev 3071)
+++ trunk/include/gbflatex.h	2014-03-05 00:22:26 UTC (rev 3072)
@@ -1,10 +1,10 @@
-/***************************************************************************
+/******************************************************************************
  *
  *  gbflatex.h -	Implementation of GBFLaTeX
  *
  * $Id$
  *
- * Copyright 2013 CrossWire Bible Society (http://www.crosswire.org)
+ * Copyright 2011-2013 CrossWire Bible Society (http://www.crosswire.org)
  *	CrossWire Bible Society
  *	P. O. Box 2528
  *	Tempe, AZ  85280-2528
@@ -20,23 +20,33 @@
  *
  */
 
-#ifndef GBFLATEX_H
-#define GBFLATEX_H
+#ifndef GBFLaTeX_H
+#define GBFLaTeX_H
 
-#include <swfilter.h>
+#include <swbasicfilter.h>
 
 SWORD_NAMESPACE_START
 
-/** This filter converts GBF text to LaTeX text
+/** this filter converts GBF text to classed LaTeX text
  */
-class SWDLLEXPORT GBFLaTeX : public SWFilter {
+class SWDLLEXPORT GBFLaTeX : public SWBasicFilter {
+	bool renderNoteNumbers;
+protected:
+	class MyUserData : public BasicFilterUserData {
+	public:
+		MyUserData(const SWModule *module, const SWKey *key);
+		bool hasFootnotePreTag;
+		SWBuf version;
+	};
+	virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key) {
+		return new MyUserData(module, key);
+	}
+	virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
 public:
 	GBFLaTeX();
-	virtual char processText(SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
+	virtual const char *getHeader() const;
+	void setRenderNoteNumbers(bool val = true) { renderNoteNumbers = val; }
 };
 
 SWORD_NAMESPACE_END
 #endif
-
-
-

Modified: trunk/src/modules/filters/gbflatex.cpp
===================================================================
--- trunk/src/modules/filters/gbflatex.cpp	2014-03-05 00:10:10 UTC (rev 3071)
+++ trunk/src/modules/filters/gbflatex.cpp	2014-03-05 00:22:26 UTC (rev 3072)
@@ -1,10 +1,10 @@
 /******************************************************************************
  *
- *  gbflatex.cpp -	SWFilter descendant to create LaTeX mark up
+ *  gbflatex.cpp -	GBF to LaTeX
  *
  * $Id$
  *
- * Copyright 2013 CrossWire Bible Society (http://www.crosswire.org)
+ * Copyright 2011-2013 CrossWire Bible Society (http://www.crosswire.org)
  *	CrossWire Bible Society
  *	P. O. Box 2528
  *	Tempe, AZ  85280-2528
@@ -20,96 +20,213 @@
  *
  */
 
+ 
 #include <stdlib.h>
 #include <gbflatex.h>
-#include <swbuf.h>
+#include <swmodule.h>
+#include <utilxml.h>
+#include <versekey.h>
+#include <ctype.h>
+#include <url.h>
 
-
 SWORD_NAMESPACE_START
 
+const char *GBFLaTeX::getHeader() const {
+	return "\\usepackage{color}";
+}
 
+GBFLaTeX::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {
+	if (module) {
+		version = module->getName(); 
+	}	
+}
+
 GBFLaTeX::GBFLaTeX() {
+	setTokenStart("<");
+	setTokenEnd(">");
+	
+	setTokenCaseSensitive(true);
+
+	//addTokenSubstitute("Rf", ")</small></font>");
+	addTokenSubstitute("FA", "{\\color{maroon}"); // for ASV footnotes to mark text
+	addTokenSubstitute("Rx", "}");
+	addTokenSubstitute("FI", "\\emph{"); // italics begin
+	addTokenSubstitute("Fi", "}");
+	addTokenSubstitute("FB", "\\bold{"); // bold begin
+	addTokenSubstitute("Fb", "}");
+	addTokenSubstitute("FR", "{\\color{red}"); // words of Jesus begin
+	addTokenSubstitute("Fr", "}");
+	addTokenSubstitute("FU", "\\underline{"); // underline begin
+	addTokenSubstitute("Fu", "}");
+	addTokenSubstitute("FO", "\\begin{quote}"); //  Old Testament quote begin
+	addTokenSubstitute("Fo", "\\end{quote}");
+	addTokenSubstitute("FS", "\\textsuperscript{"); // Superscript begin// Subscript begin
+	addTokenSubstitute("Fs", "}");
+	addTokenSubstitute("FV", "\\textsubscript{"); // Subscript begin
+	addTokenSubstitute("Fv", "}");
+	addTokenSubstitute("TT", "\\section*{"); // Book title begin
+	addTokenSubstitute("Tt", "}");
+	addTokenSubstitute("PP", "\\begin{quote}"); //  poetry  begin
+	addTokenSubstitute("Pp", "\\end{quote}");
+	addTokenSubstitute("Fn", ""); //  font  end
+	addTokenSubstitute("CL", "\\\\"); //  new line
+	addTokenSubstitute("CM", "\\\\"); //  paragraph <!P> is a non showing comment that can be changed in the front end to <P> if desired
+	addTokenSubstitute("CG", ""); //  ???
+	addTokenSubstitute("CT", ""); // ???
+	addTokenSubstitute("JR", "{\\raggedright{}"); // right align begin
+	addTokenSubstitute("JC", "{\\raggedcenter{}"); // center align begin
+	addTokenSubstitute("JL", "}"); // align end
+	
+	renderNoteNumbers = false;
 }
 
 
-char GBFLaTeX::processText (SWBuf &text, const SWKey *key, const SWModule *module)
-{
-	char token[2048];
-	int tokpos = 0;
-	bool intoken = false;
-	SWBuf orig = text;
-	const char* from = orig.c_str();
-	
-	for (text = ""; *from; ++from) {
-		if (*from == '<') {
-			intoken = true;
-			tokpos = 0;
-			token[0] = 0;
-			token[1] = 0;
-			token[2] = 0;
-			continue;
+bool GBFLaTeX::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
+	const char *tok;
+	MyUserData *u = (MyUserData *)userData;
+
+	if (!substituteToken(buf, token)) {
+		XMLTag tag(token);
+		
+		if (!strncmp(token, "WG", 2)) { // strong's numbers
+			//buf += " <small><em>&lt;<a href=\"type=Strongs value=";
+			buf += " <small><em class=\"strongs\">&lt;<a href=\"passagestudy.jsp?action=showStrongs&type=Greek&value=";
+			for (tok = token+2; *tok; tok++)
+				//if(token[i] != '\"')
+					buf += *tok;
+			buf += "\" class=\"strongs\">";
+			for (tok = token + 2; *tok; tok++)
+				//if(token[i] != '\"')
+					buf += *tok;
+			buf += "</a>&gt;</em></small>";
 		}
-		if (*from == '>') {
-			intoken = false;
-						// process desired tokens
-			switch (*token) {
-			case 'W':	// Strongs
-				switch(token[1]) {
-				case 'G':               // Greek
-				case 'H':               // Hebrew
-				case 'T':               // Tense
-					text.append(" <");
-					//for (char *tok = token + 2; *tok; tok++)
-					//	text += *tok;
-					text.append(token+2);
-					text.append("> ");
-					continue;
-				}
-				break;
-			case 'R':
-				switch(token[1]) {
-				case 'F':               // footnote begin
-					text += " \\footnote{";
-					continue;
-				case 'f':               // footnote end
-					text.append("} ");
-					continue;
-				}
-				break;
-			case 'C':
-				switch(token[1]) {
-				case 'A':               // ASCII value
-					text.append((char)atoi(&token[2]));
-					continue;
-				case 'G':
-					text.append('>');
-					continue;
-/*								Bug in WEB
-				case 'L':
-					*to++ = '<';
-					continue;
-*/
-				case 'L':	//        Bug in WEB.  Use above entry when fixed
-				case 'N':               // new line
-					text.append('\n');
-					continue;
-				case 'M':               // new paragraph
-					text += "\\paragraph";
-					continue;
-				}
-				break;
+		else if (!strncmp(token, "WH", 2)) { // strong's numbers
+			//buf += " <small><em>&lt;<a href=\"type=Strongs value=";
+			buf += " <small><em class=\"strongs\">&lt;<a href=\"passagestudy.jsp?action=showStrongs&type=Hebrew&value=";
+			for (tok = token+2; *tok; tok++)
+				//if(token[i] != '\"')
+					buf += *tok;
+			buf += "\" class=\"strongs\">";
+			for (tok = token + 2; *tok; tok++)
+				//if(token[i] != '\"')
+					buf += *tok;
+			buf += "</a>&gt;</em></small>";
+		}
+		else if (!strncmp(token, "WTG", 3)) { // strong's numbers tense
+			//buf += " <small><em>(<a href=\"type=Strongs value=";
+			buf += " <small><em class=\"strongs\">(<a href=\"passagestudy.jsp?action=showStrongs&type=Greek&value=";
+			for (tok = token + 3; *tok; tok++)
+				if(*tok != '\"')
+					buf += *tok;
+			buf += "\" class=\"strongs\">";
+			for (tok = token + 3; *tok; tok++)
+				if(*tok != '\"')
+					buf += *tok;
+			buf += "</a>)</em></small>";
+		}
+		else if (!strncmp(token, "WTH", 3)) { // strong's numbers tense
+			//buf += " <small><em>(<a href=\"type=Strongs value=";
+			buf += " <small><em class=\"strongs\">(<a href=\"passagestudy.jsp?action=showStrongs&type=Hebrew&value=";
+			for (tok = token + 3; *tok; tok++)
+				if(*tok != '\"')
+					buf += *tok;
+			buf += "\" class=\"strongs\">";
+			for (tok = token + 3; *tok; tok++)
+				if(*tok != '\"')
+					buf += *tok;
+			buf += "</a>)</em></small>";
+		}
+
+		else if (!strncmp(token, "WT", 2) && strncmp(token, "WTH", 3) && strncmp(token, "WTG", 3)) { // morph tags
+			//buf += " <small><em>(<a href=\"type=morph class=none value=";
+			buf += " <small><em class=\"morph\">(<a href=\"passagestudy.jsp?action=showMorph&type=Greek&value=";
+			
+			for (tok = token + 2; *tok; tok++)
+				if(*tok != '\"')
+					buf += *tok;
+			buf += "\" class=\"morph\">";
+			for (tok = token + 2; *tok; tok++)				
+				if(*tok != '\"') 			
+					buf += *tok;		
+			buf += "</a>)</em></small>";
+		}
+
+		else if (!strcmp(tag.getName(), "RX")) {
+			buf += "<a href=\"";
+			for (tok = token + 3; *tok; tok++) {
+			  if(*tok != '<' && *tok+1 != 'R' && *tok+2 != 'x') {
+			    buf += *tok;
+			  }
+			  else {
+			    break;
+			  }
 			}
-			continue;
+			buf += "\">";
 		}
-		if (intoken) {
-			if (tokpos < 2045)
-				token[tokpos++] = *from;
-				token[tokpos+2] = 0;
+		else if (!strcmp(tag.getName(), "RF")) {
+			SWBuf type = tag.getAttribute("type");
+			SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
+			SWBuf noteName = tag.getAttribute("n");
+			VerseKey *vkey = NULL;
+			// see if we have a VerseKey * or descendant
+			SWTRY {
+				vkey = SWDYNAMIC_CAST(VerseKey, u->key);
+			}
+			SWCATCH ( ... ) {	}
+			if (vkey) {
+				// leave this special osis type in for crossReference notes types?  Might thml use this some day? Doesn't hurt.
+				//char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n');
+				buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=n&value=%s&module=%s&passage=%s\"><small><sup class=\"n\">*n%s</sup></small></a> ", 
+					URL::encode(footnoteNumber.c_str()).c_str(),
+					URL::encode(u->version.c_str()).c_str(), 
+					URL::encode(vkey->getText()).c_str(), 
+					(renderNoteNumbers ? URL::encode(noteName.c_str()).c_str(): ""));
+			}
+			u->suspendTextPassThru = true;
 		}
-		else	text.append(*from);
+		else if (!strcmp(tag.getName(), "Rf")) {
+			u->suspendTextPassThru = false;
+		}
+/*
+		else if (!strncmp(token, "RB", 2)) {
+			buf += "<i> ";
+			u->hasFootnotePreTag = true;
+		}
+
+		else if (!strncmp(token, "Rf", 2)) {
+			buf += "&nbsp<a href=\"note=";
+			buf += u->lastTextNode.c_str();
+			buf += "\">";
+			buf += "<small><sup>*n</sup></small></a>&nbsp";
+			// let's let text resume to output again
+			u->suspendTextPassThru = false;
+		}
+		
+		else if (!strncmp(token, "RF", 2)) {
+			if (u->hasFootnotePreTag) {
+				u->hasFootnotePreTag = false;
+				buf += "</i> ";
+			}
+			u->suspendTextPassThru = true;
+		}
+*/
+		else if (!strncmp(token, "FN", 2)) {
+			buf += "<font face=\"";
+			for (tok = token + 2; *tok; tok++)				
+				if(*tok != '\"') 			
+					buf += *tok;
+			buf += "\">";
+		}
+
+		else if (!strncmp(token, "CA", 2)) {	// ASCII value
+			buf += (char)atoi(&token[2]);
+		}
+		
+		else {
+			return false;
+		}
 	}
-	return 0;
+	return true;
 }
 
-
 SWORD_NAMESPACE_END




More information about the sword-cvs mailing list