space width guessing fixed.

git-svn-id: https://pdfminerr.googlecode.com/svn/trunk/pdfminer@66 1aa58f4a-7d42-0410-adbc-911cccaed67c
pull/1/head
yusuke.shinyama.dummy 2009-02-08 11:14:08 +00:00
parent 6b09fe2bc4
commit ca1783c956
2 changed files with 7 additions and 3 deletions

View File

@ -80,8 +80,6 @@ class FigureItem(PageItem):
## ##
class TextItem(object): class TextItem(object):
SPACE_WIDTH = 0.6
def __init__(self, matrix, font, fontsize, charspace, scaling, text): def __init__(self, matrix, font, fontsize, charspace, scaling, text):
self.matrix = matrix self.matrix = matrix
self.font = font self.font = font
@ -93,7 +91,7 @@ class TextItem(object):
size = (font.get_ascent() - font.get_descent()) * fontsize size = (font.get_ascent() - font.get_descent()) * fontsize
if not self.font.is_vertical(): if not self.font.is_vertical():
# horizontal text # horizontal text
spwidth = font.char_width(32) * self.SPACE_WIDTH # space width spwidth = font.space_width()
self.direction = 1 self.direction = 1
w = 0 w = 0
dx = 0 dx = 0

View File

@ -66,6 +66,9 @@ class PDFFont(object):
def string_width(self, s): def string_width(self, s):
return sum( self.char_width(cid) for cid in self.decode(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 # PDFSimpleFont
class PDFSimpleFont(PDFFont): class PDFSimpleFont(PDFFont):
@ -352,3 +355,6 @@ class PDFCIDFont(PDFFont):
raise PDFUnicodeNotDefined(self.cidcoding, cid) raise PDFUnicodeNotDefined(self.cidcoding, cid)
chars = unpack('>%dH' % (len(code)/2), code) chars = unpack('>%dH' % (len(code)/2), code)
return ''.join( unichr(c) for c in chars ) return ''.join( unichr(c) for c in chars )
def space_width(self):
return 0