move latexbackend into PdfDoc
svn: r12614
This commit is contained in:
@ -42,11 +42,134 @@ from gettext import gettext as _
|
||||
|
||||
from gen.plug import PluginManager, DocGenPlugin
|
||||
from gen.plug.docgen import BaseDoc, TextDoc, PAPER_LANDSCAPE, FONT_SANS_SERIF
|
||||
from gen.plug.docbackend import LateXBackend, latexescape
|
||||
from gen.plug.docbackend import DocBackend
|
||||
import ImgManip
|
||||
import Errors
|
||||
import Utils
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Functions for docbackend
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
def latexescape(text):
|
||||
"""
|
||||
change text in text that latex shows correctly
|
||||
special characters: \& \$ \% \# \_ \{ \}
|
||||
"""
|
||||
text = text.replace('&','\\&')
|
||||
text = text.replace('$','\\$')
|
||||
text = text.replace('%','\\%')
|
||||
text = text.replace('#','\\#')
|
||||
text = text.replace('_','\\_')
|
||||
text = text.replace('{','\\{')
|
||||
text = text.replace('}','\\}')
|
||||
return text
|
||||
|
||||
def latexescapeverbatim(text):
|
||||
"""
|
||||
change text in text that latex shows correctly respecting whitespace
|
||||
special characters: \& \$ \% \# \_ \{ \}
|
||||
Now also make sure space and newline is respected
|
||||
"""
|
||||
text = text.replace('&', '\\&')
|
||||
text = text.replace('$', '\\$')
|
||||
text = text.replace('%', '\\%')
|
||||
text = text.replace('#', '\\#')
|
||||
text = text.replace('_', '\\_')
|
||||
text = text.replace('{', '\\{')
|
||||
text = text.replace('}', '\\}')
|
||||
text = text.replace(' ', '\\ ')
|
||||
text = text.replace('\n', '\\newline\n')
|
||||
#spaces at begin are normally ignored, make sure they are not.
|
||||
#due to above a space at begin is now \newline\n\
|
||||
text = text.replace('\\newline\n\\ ', '\\newline\n\\hspace*{0.1cm}\\ ')
|
||||
return text
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Document Backend class for cairo docs
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
class LateXBackend(DocBackend):
|
||||
"""
|
||||
Implementation of docbackend for latex docs.
|
||||
File and File format management for latex docs
|
||||
"""
|
||||
# overwrite base class attributes, they become static var of LaTeXDoc
|
||||
SUPPORTED_MARKUP = [
|
||||
DocBackend.BOLD,
|
||||
DocBackend.ITALIC,
|
||||
DocBackend.UNDERLINE,
|
||||
DocBackend.FONTSIZE,
|
||||
DocBackend.FONTFACE,
|
||||
DocBackend.SUPERSCRIPT ]
|
||||
|
||||
STYLETAG_MARKUP = {
|
||||
DocBackend.BOLD : ("\\textbf{", "}"),
|
||||
DocBackend.ITALIC : ("\\textit{", "}"),
|
||||
DocBackend.UNDERLINE : ("\\underline{", "}"),
|
||||
DocBackend.SUPERSCRIPT : ("\\textsuperscript{", "}"),
|
||||
}
|
||||
|
||||
ESCAPE_FUNC = lambda x: latexescape
|
||||
|
||||
def setescape(self, preformatted=False):
|
||||
"""
|
||||
Latex needs two different escape functions depending on the type.
|
||||
This function allows to switch the escape function
|
||||
"""
|
||||
if not preformatted:
|
||||
LateXBackend.ESCAPE_FUNC = lambda x: latexescape
|
||||
else:
|
||||
LateXBackend.ESCAPE_FUNC = lambda x: latexescapeverbatim
|
||||
|
||||
def _create_xmltag(self, type, value):
|
||||
"""
|
||||
overwrites the method in DocBackend.
|
||||
creates the latex tags needed for non bool style types we support:
|
||||
FONTSIZE : use different \large denomination based
|
||||
on size
|
||||
: very basic, in mono in the font face
|
||||
then we use {\ttfamily }
|
||||
"""
|
||||
if type not in self.SUPPORTED_MARKUP:
|
||||
return None
|
||||
elif type == DocBackend.FONTSIZE:
|
||||
#translate size in point to something LaTeX can work with
|
||||
if value >= 22:
|
||||
return ("{\\Huge ", "}")
|
||||
elif value >= 20:
|
||||
return ("{\\huge ", "}")
|
||||
elif value >= 18:
|
||||
return ("{\\LARGE ", "}")
|
||||
elif value >= 16:
|
||||
return ("{\\Large ", "}")
|
||||
elif value >= 14:
|
||||
return ("{\\large ", "}")
|
||||
elif value < 8:
|
||||
return ("{\\scriptsize ", "}")
|
||||
elif value < 10:
|
||||
return ("{\\footnotesize ", "}")
|
||||
elif value < 12:
|
||||
return ("{\\small ", "}")
|
||||
else:
|
||||
return ("", "")
|
||||
elif type == DocBackend.FONTFACE:
|
||||
if 'MONO' in value.upper():
|
||||
return ("{\\ttfamily ", "}")
|
||||
elif 'ROMAN' in value.upper():
|
||||
return ("{\\rmfamily ", "}")
|
||||
return None
|
||||
|
||||
def _checkfilename(self):
|
||||
"""
|
||||
Check to make sure filename satisfies the standards for this filetype
|
||||
"""
|
||||
if self._filename[-4:] != ".tex":
|
||||
self._filename = self._filename + ".tex"
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Convert from roman to arabic numbers
|
||||
|
Reference in New Issue
Block a user