1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-11-15 13:55:03 -05:00

Add support for inline images to gen.py's PDF output. (Thanks to m&m and intosi for their help.)

This commit is contained in:
Tobias Markmann 2014-03-13 17:20:07 +01:00
parent 30ddd5102f
commit 9d8722a1aa
2 changed files with 45 additions and 2 deletions

34
gen.py
View File

@ -45,6 +45,10 @@ from xeputil import getLatestXEPFilename
from xml.dom.minidom import parse,parseString,Document,getDOMImplementation
# for serializing inline images
import base64
import urlparse
XEPPATH = "/var/www/vhosts/xmpp.org/extensions"
CONFIGPATH = "/var/local/xsf"
@ -54,6 +58,33 @@ last_build = {}
files_to_delete = [];
def serializeInlineImage(output_dir, no, attrValue):
up = urlparse.urlparse(attrValue)
head, data = up.path.split(',')
bits = head.split(';')
mime_type = bits[0] if bits[0] else 'text/plain'
charset, b64 = 'ASCII', False
for bit in bits[1]:
if bit.startswith('charset='):
charset = bit[8:]
elif bit == 'base64':
b64 = True
# Do something smart with charset and b64 instead of assuming
plaindata = base64.b64decode(data)
# Do something smart with mime_type
if mime_type in ('image/png'):
file_ext = mime_type.split('/')[1]
with open(output_dir + '/' + 'inlineimage-' + str(no) + '.' + file_ext, 'wb') as f:
f.write(plaindata)
def serializeXEPInlineImages(output_dir, filename):
dom = parse(filename)
imgs = dom.getElementsByTagName('img')
for (no, img) in enumerate(imgs):
serializeInlineImage(output_dir, no, img.attributes["src"].value)
def getText(nodelist):
thisText = ""
for node in nodelist:
@ -239,6 +270,7 @@ def buildXHTML( file, nr ):
return True
def buildPDF( file, nr ):
serializeXEPInlineImages("/tmp/xepbuilder", file)
error, desc = executeCommand("xsltproc -o /tmp/xepbuilder/xep-" + nr + ".tex.xml xep2texml.xsl " + file)
if not checkError(error, desc):
@ -386,7 +418,7 @@ def main(argv):
executeCommand("sed -e '1s/<?[^?]*?>//' " + CONFIGPATH + "/extensions.xml > " + XEPPATH + "/../includes/xeplist.txt")
executeCommand("rm -rfd /tmp/xepbuilder")
#executeCommand("rm -rfd /tmp/xepbuilder")
makeBundle()

View File

@ -91,6 +91,8 @@
\usepackage{varwidth}
\usepackage{titling}
\usepackage{titletoc}
\usepackage{float}
\usepackage{adjustbox}
\usepackage{hyphenat}
@ -403,6 +405,15 @@
</xsl:if>
</xsl:template>
<!-- img -->
<xsl:template match="img">
<env name="figure"><opt>H</opt>
<cmd name="centering" />
<!--<cmd name="includegraphics"><opt><TeXML escape="0">width=.9\textwidth</TeXML></opt><parm>inlineimage-<xsl:value-of select="count(preceding::img)" /></parm></cmd>-->
<cmd name="adjustimage"><parm><TeXML escape="0">max size={.9\textwidth}{.9\textheight}</TeXML></parm><parm>inlineimage-<xsl:value-of select="count(preceding::img)" /></parm></cmd>
</env>
</xsl:template>
<!-- section3 -->
<xsl:template match="section3">
<cmd name="subsubsection" nl2="1">