upgraded fpdf to 1.7.1
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.4.1-alpha.2+timestamp.2013.02.17.09.49.04
|
Version 2.4.1-alpha.2+timestamp.2013.02.17.11.27.22
|
||||||
|
|||||||
@@ -14,5 +14,3 @@ except ImportError:
|
|||||||
warnings.warn("web2py gluon package not installed, required for html2pdf")
|
warnings.warn("web2py gluon package not installed, required for html2pdf")
|
||||||
|
|
||||||
from template import Template
|
from template import Template
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -154,4 +154,3 @@ fpdf_charwidths['zapfdingbats']={
|
|||||||
'\xdc':927,'\xdd':928,'\xde':928,'\xdf':834,'\xe0':873,'\xe1':828,'\xe2':924,'\xe3':924,'\xe4':917,'\xe5':930,'\xe6':931,'\xe7':463,'\xe8':883,'\xe9':836,'\xea':836,'\xeb':867,'\xec':867,'\xed':696,'\xee':696,'\xef':874,'\xf0':0,'\xf1':874,
|
'\xdc':927,'\xdd':928,'\xde':928,'\xdf':834,'\xe0':873,'\xe1':828,'\xe2':924,'\xe3':924,'\xe4':917,'\xe5':930,'\xe6':931,'\xe7':463,'\xe8':883,'\xe9':836,'\xea':836,'\xeb':867,'\xec':867,'\xed':696,'\xee':696,'\xef':874,'\xf0':0,'\xf1':874,
|
||||||
'\xf2':760,'\xf3':946,'\xf4':771,'\xf5':865,'\xf6':771,'\xf7':888,'\xf8':967,'\xf9':888,'\xfa':831,'\xfb':873,'\xfc':927,'\xfd':970,'\xfe':918,'\xff':0}
|
'\xf2':760,'\xf3':946,'\xf4':771,'\xf5':865,'\xf6':771,'\xf7':888,'\xf8':967,'\xf9':888,'\xfa':831,'\xfb':873,'\xfc':927,'\xfd':970,'\xfe':918,'\xff':0}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,13 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
# Check if PIL is available (tries importing both pypi version and corrected or manually installed versions).
|
||||||
|
# Necessary for JPEG and GIF support.
|
||||||
try:
|
try:
|
||||||
# Check if PIL is available, necessary for JPEG support.
|
try:
|
||||||
import Image
|
import Image
|
||||||
|
except:
|
||||||
|
from PIL import Image
|
||||||
except ImportError:
|
except ImportError:
|
||||||
Image = None
|
Image = None
|
||||||
|
|
||||||
@@ -680,7 +684,7 @@ class FPDF(object):
|
|||||||
for uni in UTF8StringToArray(txt):
|
for uni in UTF8StringToArray(txt):
|
||||||
self.current_font['subset'].append(uni)
|
self.current_font['subset'].append(uni)
|
||||||
else:
|
else:
|
||||||
txt2 = txt.replace('\\','\\\\').replace(')','\\)').replace('(','\\(')
|
txt2 = self._escape(txt)
|
||||||
s += sprintf('BT %.2f %.2f Td (%s) Tj ET',(self.x+dx)*k,(self.h-(self.y+.5*h+.3*self.font_size))*k,txt2)
|
s += sprintf('BT %.2f %.2f Td (%s) Tj ET',(self.x+dx)*k,(self.h-(self.y+.5*h+.3*self.font_size))*k,txt2)
|
||||||
|
|
||||||
if(self.underline):
|
if(self.underline):
|
||||||
@@ -1637,9 +1641,11 @@ class FPDF(object):
|
|||||||
# Use temporary file
|
# Use temporary file
|
||||||
f = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
f = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
||||||
tmp = f.name
|
tmp = f.name
|
||||||
transparency = im.info['transparency']
|
|
||||||
f.close()
|
f.close()
|
||||||
im.save(tmp, transparency=transparency)
|
if "transparency" in im.info:
|
||||||
|
im.save(tmp, transparency = im.info['transparency'])
|
||||||
|
else:
|
||||||
|
im.save(tmp)
|
||||||
info = self._parsepng(tmp)
|
info = self._parsepng(tmp)
|
||||||
os.unlink(tmp)
|
os.unlink(tmp)
|
||||||
return info
|
return info
|
||||||
@@ -1759,7 +1765,7 @@ class FPDF(object):
|
|||||||
def _freadint(self, f):
|
def _freadint(self, f):
|
||||||
#Read a 4-byte integer from file
|
#Read a 4-byte integer from file
|
||||||
try:
|
try:
|
||||||
return struct.unpack('>HH',f.read(4))[1]
|
return struct.unpack('>I', f.read(4))[0]
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -1769,7 +1775,7 @@ class FPDF(object):
|
|||||||
|
|
||||||
def _escape(self, s):
|
def _escape(self, s):
|
||||||
#Add \ before \, ( and )
|
#Add \ before \, ( and )
|
||||||
return s.replace('\\','\\\\').replace(')','\\)').replace('(','\\(')
|
return s.replace('\\','\\\\').replace(')','\\)').replace('(','\\(').replace('\r','\\r')
|
||||||
|
|
||||||
def _putstream(self, s):
|
def _putstream(self, s):
|
||||||
self._out('stream')
|
self._out('stream')
|
||||||
@@ -1879,4 +1885,3 @@ class FPDF(object):
|
|||||||
x += gap
|
x += gap
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,8 @@ def hex2dec(color = "#000000"):
|
|||||||
class HTML2FPDF(HTMLParser):
|
class HTML2FPDF(HTMLParser):
|
||||||
"Render basic HTML to FPDF"
|
"Render basic HTML to FPDF"
|
||||||
|
|
||||||
def __init__(self, pdf, image_map = None):
|
def __init__(self, pdf, image_map=None):
|
||||||
HTMLParser.__init__(self)
|
HTMLParser.__init__(self)
|
||||||
self.image_map = image_map or (lambda src: src)
|
|
||||||
self.style = {}
|
self.style = {}
|
||||||
self.pre = False
|
self.pre = False
|
||||||
self.href = ''
|
self.href = ''
|
||||||
@@ -38,6 +37,7 @@ class HTML2FPDF(HTMLParser):
|
|||||||
self.font = None
|
self.font = None
|
||||||
self.font_stack = []
|
self.font_stack = []
|
||||||
self.pdf = pdf
|
self.pdf = pdf
|
||||||
|
self.image_map = image_map or (lambda src: src)
|
||||||
self.r = self.g = self.b = 0
|
self.r = self.g = self.b = 0
|
||||||
self.indent = 0
|
self.indent = 0
|
||||||
self.bullet = []
|
self.bullet = []
|
||||||
@@ -396,4 +396,3 @@ class HTMLMixin(object):
|
|||||||
h2p = HTML2FPDF(self, image_map)
|
h2p = HTML2FPDF(self, image_map)
|
||||||
h2p.feed(text)
|
h2p.feed(text)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -299,4 +299,3 @@ if __name__ == "__main__":
|
|||||||
os.system("evince ./invoice.pdf")
|
os.system("evince ./invoice.pdf")
|
||||||
else:
|
else:
|
||||||
os.system("./invoice.pdf")
|
os.system("./invoice.pdf")
|
||||||
|
|
||||||
|
|||||||
@@ -412,25 +412,37 @@ class TTFontFile:
|
|||||||
self.skip(2)
|
self.skip(2)
|
||||||
cmapTableCount = self.read_ushort()
|
cmapTableCount = self.read_ushort()
|
||||||
unicode_cmap_offset = 0
|
unicode_cmap_offset = 0
|
||||||
|
unicode_cmap_offset12 = 0
|
||||||
|
|
||||||
for i in range(cmapTableCount):
|
for i in range(cmapTableCount):
|
||||||
platformID = self.read_ushort()
|
platformID = self.read_ushort()
|
||||||
encodingID = self.read_ushort()
|
encodingID = self.read_ushort()
|
||||||
offset = self.read_ulong()
|
offset = self.read_ulong()
|
||||||
save_pos = self._pos
|
save_pos = self._pos
|
||||||
|
if platformID == 3 and encodingID == 10: # Microsoft, UCS-4
|
||||||
|
format = self.get_ushort(cmap_offset + offset)
|
||||||
|
if (format == 12):
|
||||||
|
if not unicode_cmap_offset12:
|
||||||
|
unicode_cmap_offset12 = cmap_offset + offset
|
||||||
|
break
|
||||||
if ((platformID == 3 and encodingID == 1) or platformID == 0): # Microsoft, Unicode
|
if ((platformID == 3 and encodingID == 1) or platformID == 0): # Microsoft, Unicode
|
||||||
format = self.get_ushort(cmap_offset + offset)
|
format = self.get_ushort(cmap_offset + offset)
|
||||||
if (format == 4):
|
if (format == 4):
|
||||||
if (not unicode_cmap_offset):
|
if (not unicode_cmap_offset):
|
||||||
unicode_cmap_offset = cmap_offset + offset
|
unicode_cmap_offset = cmap_offset + offset
|
||||||
break
|
break
|
||||||
self.seek(save_pos )
|
|
||||||
|
|
||||||
if (not unicode_cmap_offset):
|
self.seek(save_pos)
|
||||||
die('Font (' + self.filename + ') does not have cmap for Unicode (platform 3, encoding 1, format 4, or platform 0, any encoding, format 4)')
|
|
||||||
|
if not unicode_cmap_offset and not unicode_cmap_offset12:
|
||||||
|
die('Font (' + self.filename + ') does not have cmap for Unicode (platform 3, encoding 1, format 4, or platform 3, encoding 10, format 12, or platform 0, any encoding, format 4)')
|
||||||
|
|
||||||
glyphToChar = {}
|
glyphToChar = {}
|
||||||
charToGlyph = {}
|
charToGlyph = {}
|
||||||
self.getCMAP4(unicode_cmap_offset, glyphToChar, charToGlyph )
|
if unicode_cmap_offset12:
|
||||||
|
self.getCMAP12(unicode_cmap_offset12, glyphToChar, charToGlyph)
|
||||||
|
else:
|
||||||
|
self.getCMAP4(unicode_cmap_offset, glyphToChar, charToGlyph)
|
||||||
|
|
||||||
#################/
|
#################/
|
||||||
# hmtx - Horizontal metrics table
|
# hmtx - Horizontal metrics table
|
||||||
@@ -486,11 +498,18 @@ class TTFontFile:
|
|||||||
self.skip(2)
|
self.skip(2)
|
||||||
cmapTableCount = self.read_ushort()
|
cmapTableCount = self.read_ushort()
|
||||||
unicode_cmap_offset = 0
|
unicode_cmap_offset = 0
|
||||||
|
unicode_cmap_offset12 = 0
|
||||||
for i in range(cmapTableCount):
|
for i in range(cmapTableCount):
|
||||||
platformID = self.read_ushort()
|
platformID = self.read_ushort()
|
||||||
encodingID = self.read_ushort()
|
encodingID = self.read_ushort()
|
||||||
offset = self.read_ulong()
|
offset = self.read_ulong()
|
||||||
save_pos = self._pos
|
save_pos = self._pos
|
||||||
|
if platformID == 3 and encodingID == 10: # Microsoft, UCS-4
|
||||||
|
format = self.get_ushort(cmap_offset + offset)
|
||||||
|
if (format == 12):
|
||||||
|
if not unicode_cmap_offset12:
|
||||||
|
unicode_cmap_offset12 = cmap_offset + offset
|
||||||
|
break
|
||||||
if ((platformID == 3 and encodingID == 1) or platformID == 0): # Microsoft, Unicode
|
if ((platformID == 3 and encodingID == 1) or platformID == 0): # Microsoft, Unicode
|
||||||
format = self.get_ushort(cmap_offset + offset)
|
format = self.get_ushort(cmap_offset + offset)
|
||||||
if (format == 4):
|
if (format == 4):
|
||||||
@@ -499,12 +518,15 @@ class TTFontFile:
|
|||||||
|
|
||||||
self.seek(save_pos )
|
self.seek(save_pos )
|
||||||
|
|
||||||
if (not unicode_cmap_offset):
|
if not unicode_cmap_offset and not unicode_cmap_offset12:
|
||||||
die('Font (' + self.filename + ') does not have cmap for Unicode (platform 3, encoding 1, format 4, or platform 0, any encoding, format 4)')
|
die('Font (' + self.filename + ') does not have cmap for Unicode (platform 3, encoding 1, format 4, or platform 3, encoding 10, format 12, or platform 0, any encoding, format 4)')
|
||||||
|
|
||||||
glyphToChar = {}
|
glyphToChar = {}
|
||||||
charToGlyph = {}
|
charToGlyph = {}
|
||||||
self.getCMAP4(unicode_cmap_offset, glyphToChar, charToGlyph )
|
if unicode_cmap_offset12:
|
||||||
|
self.getCMAP12(unicode_cmap_offset12, glyphToChar, charToGlyph)
|
||||||
|
else:
|
||||||
|
self.getCMAP4(unicode_cmap_offset, glyphToChar, charToGlyph)
|
||||||
|
|
||||||
self.charToGlyph = charToGlyph
|
self.charToGlyph = charToGlyph
|
||||||
|
|
||||||
@@ -923,7 +945,7 @@ class TTFontFile:
|
|||||||
die('Unknown location table format ' + indexToLocFormat)
|
die('Unknown location table format ' + indexToLocFormat)
|
||||||
|
|
||||||
# CMAP Format 4
|
# CMAP Format 4
|
||||||
def getCMAP4(self, unicode_cmap_offset, glyphToChar, charToGlyph ):
|
def getCMAP4(self, unicode_cmap_offset, glyphToChar, charToGlyph):
|
||||||
self.maxUniChar = 0
|
self.maxUniChar = 0
|
||||||
self.seek(unicode_cmap_offset + 2)
|
self.seek(unicode_cmap_offset + 2)
|
||||||
length = self.read_ushort()
|
length = self.read_ushort()
|
||||||
@@ -967,6 +989,34 @@ class TTFontFile:
|
|||||||
self.maxUniChar = max(unichar,self.maxUniChar)
|
self.maxUniChar = max(unichar,self.maxUniChar)
|
||||||
glyphToChar.setdefault(glyph, []).append(unichar)
|
glyphToChar.setdefault(glyph, []).append(unichar)
|
||||||
|
|
||||||
|
# CMAP Format 12
|
||||||
|
def getCMAP12(self, unicode_cmap_offset, glyphToChar, charToGlyph):
|
||||||
|
self.maxUniChar = 0
|
||||||
|
# table (skip format version, should be 12)
|
||||||
|
self.seek(unicode_cmap_offset + 2)
|
||||||
|
# reserved
|
||||||
|
self.skip(2)
|
||||||
|
# table length
|
||||||
|
length = self.read_ulong()
|
||||||
|
# language (should be 0)
|
||||||
|
self.skip(4)
|
||||||
|
# groups count
|
||||||
|
grpCount = self.read_ulong()
|
||||||
|
|
||||||
|
if 2 + 2 + 4 + 4 + 4 + grpCount * 3 * 4 > length:
|
||||||
|
die("TTF format 12 cmap table too small")
|
||||||
|
for n in range(grpCount):
|
||||||
|
startCharCode = self.read_ulong()
|
||||||
|
endCharCode = self.read_ulong()
|
||||||
|
glyph = self.read_ulong()
|
||||||
|
for unichar in range(startCharCode, endCharCode + 1):
|
||||||
|
charToGlyph[unichar] = glyph
|
||||||
|
if (unichar < 196608):
|
||||||
|
self.maxUniChar = max(unichar, self.maxUniChar)
|
||||||
|
glyphToChar.setdefault(glyph, []).append(unichar)
|
||||||
|
glyph += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Put the TTF file together
|
# Put the TTF file together
|
||||||
def endTTFile(self, stm):
|
def endTTFile(self, stm):
|
||||||
|
|||||||
Reference in New Issue
Block a user