diff --git a/pdflib/pdfdevice.py b/pdflib/pdfdevice.py index 2cc8f37..3a8d154 100644 --- a/pdflib/pdfdevice.py +++ b/pdflib/pdfdevice.py @@ -80,8 +80,6 @@ class FigureItem(PageItem): ## class TextItem(object): - SPACE_WIDTH = 0.6 - def __init__(self, matrix, font, fontsize, charspace, scaling, text): self.matrix = matrix self.font = font @@ -93,7 +91,7 @@ class TextItem(object): size = (font.get_ascent() - font.get_descent()) * fontsize if not self.font.is_vertical(): # horizontal text - spwidth = font.char_width(32) * self.SPACE_WIDTH # space width + spwidth = font.space_width() self.direction = 1 w = 0 dx = 0 diff --git a/pdflib/pdffont.py b/pdflib/pdffont.py index d929bf7..bb311f8 100644 --- a/pdflib/pdffont.py +++ b/pdflib/pdffont.py @@ -66,6 +66,9 @@ class PDFFont(object): def string_width(self, s): return sum( self.char_width(cid) for cid in self.decode(s) ) + def space_width(self): + return max(self.char_width(32), self.char_width(44), self.char_width(46)) * 0.5 + # PDFSimpleFont class PDFSimpleFont(PDFFont): @@ -352,3 +355,6 @@ class PDFCIDFont(PDFFont): raise PDFUnicodeNotDefined(self.cidcoding, cid) chars = unpack('>%dH' % (len(code)/2), code) return ''.join( unichr(c) for c in chars ) + + def space_width(self): + return 0