Cleanup: isinstance
parent
7849c8724a
commit
340387bfc6
|
@ -622,10 +622,8 @@ class LTLayoutContainer(LTContainer):
|
||||||
if c == 0 and isany(obj1, obj2):
|
if c == 0 and isany(obj1, obj2):
|
||||||
dists.append((1, d, obj1, obj2))
|
dists.append((1, d, obj1, obj2))
|
||||||
continue
|
continue
|
||||||
if (isinstance(obj1, LTTextBoxVertical) or
|
if (isinstance(obj1, (LTTextBoxVertical, LTTextGroupTBRL)) or
|
||||||
isinstance(obj1, LTTextGroupTBRL) or
|
isinstance(obj2, (LTTextBoxVertical, LTTextGroupTBRL))):
|
||||||
isinstance(obj2, LTTextBoxVertical) or
|
|
||||||
isinstance(obj2, LTTextGroupTBRL)):
|
|
||||||
group = LTTextGroupTBRL([obj1, obj2])
|
group = LTTextGroupTBRL([obj1, obj2])
|
||||||
else:
|
else:
|
||||||
group = LTTextGroupLRTB([obj1, obj2])
|
group = LTTextGroupLRTB([obj1, obj2])
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from utils import mult_matrix, translate_matrix
|
from utils import mult_matrix, translate_matrix
|
||||||
from utils import enc, bbox2str
|
from utils import enc, bbox2str, isnumber
|
||||||
from pdffont import PDFUnicodeNotDefined
|
from pdffont import PDFUnicodeNotDefined
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class PDFTextDevice(PDFDevice):
|
||||||
font, fontsize, scaling, charspace, wordspace, rise, dxscale):
|
font, fontsize, scaling, charspace, wordspace, rise, dxscale):
|
||||||
needcharspace = False
|
needcharspace = False
|
||||||
for obj in seq:
|
for obj in seq:
|
||||||
if isinstance(obj, int) or isinstance(obj, float):
|
if isnumber(obj):
|
||||||
x -= obj*dxscale
|
x -= obj*dxscale
|
||||||
needcharspace = True
|
needcharspace = True
|
||||||
else:
|
else:
|
||||||
|
@ -103,7 +103,7 @@ class PDFTextDevice(PDFDevice):
|
||||||
font, fontsize, scaling, charspace, wordspace, rise, dxscale):
|
font, fontsize, scaling, charspace, wordspace, rise, dxscale):
|
||||||
needcharspace = False
|
needcharspace = False
|
||||||
for obj in seq:
|
for obj in seq:
|
||||||
if isinstance(obj, int) or isinstance(obj, float):
|
if isnumber(obj):
|
||||||
y -= obj*dxscale
|
y -= obj*dxscale
|
||||||
needcharspace = True
|
needcharspace = True
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -15,7 +15,7 @@ from pdftypes import PDFException, resolve1
|
||||||
from pdftypes import int_value, num_value
|
from pdftypes import int_value, num_value
|
||||||
from pdftypes import list_value, dict_value, stream_value
|
from pdftypes import list_value, dict_value, stream_value
|
||||||
from fontmetrics import FONT_METRICS
|
from fontmetrics import FONT_METRICS
|
||||||
from utils import apply_matrix_norm, nunpack, choplist
|
from utils import apply_matrix_norm, nunpack, choplist, isnumber
|
||||||
|
|
||||||
|
|
||||||
def get_widths(seq):
|
def get_widths(seq):
|
||||||
|
@ -28,7 +28,7 @@ def get_widths(seq):
|
||||||
for (i, w) in enumerate(v):
|
for (i, w) in enumerate(v):
|
||||||
widths[char1+i] = w
|
widths[char1+i] = w
|
||||||
r = []
|
r = []
|
||||||
elif isinstance(v, int):
|
elif isnumber(v):
|
||||||
r.append(v)
|
r.append(v)
|
||||||
if len(r) == 3:
|
if len(r) == 3:
|
||||||
(char1, char2, w) = r
|
(char1, char2, w) = r
|
||||||
|
@ -51,7 +51,7 @@ def get_widths2(seq):
|
||||||
for (i, (w, vx, vy)) in enumerate(choplist(3, v)):
|
for (i, (w, vx, vy)) in enumerate(choplist(3, v)):
|
||||||
widths[char1+i] = (w, (vx, vy))
|
widths[char1+i] = (w, (vx, vy))
|
||||||
r = []
|
r = []
|
||||||
elif isinstance(v, int):
|
elif isnumber(v):
|
||||||
r.append(v)
|
r.append(v)
|
||||||
if len(r) == 5:
|
if len(r) == 5:
|
||||||
(char1, char2, w, vx, vy) = r
|
(char1, char2, w, vx, vy) = r
|
||||||
|
|
|
@ -6,7 +6,7 @@ from runlength import rldecode
|
||||||
from ccitt import ccittfaxdecode
|
from ccitt import ccittfaxdecode
|
||||||
from psparser import PSException, PSObject
|
from psparser import PSException, PSObject
|
||||||
from psparser import LIT, STRICT
|
from psparser import LIT, STRICT
|
||||||
from utils import apply_png_predictor
|
from utils import apply_png_predictor, isnumber
|
||||||
|
|
||||||
LITERAL_CRYPT = LIT('Crypt')
|
LITERAL_CRYPT = LIT('Crypt')
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ def float_value(x):
|
||||||
|
|
||||||
def num_value(x):
|
def num_value(x):
|
||||||
x = resolve1(x)
|
x = resolve1(x)
|
||||||
if not (isinstance(x, int) or isinstance(x, float)):
|
if not isnumber(x):
|
||||||
if STRICT:
|
if STRICT:
|
||||||
raise PDFTypeError('Int or Float required: %r' % x)
|
raise PDFTypeError('Int or Float required: %r' % x)
|
||||||
return 0
|
return 0
|
||||||
|
@ -144,7 +144,7 @@ def str_value(x):
|
||||||
|
|
||||||
def list_value(x):
|
def list_value(x):
|
||||||
x = resolve1(x)
|
x = resolve1(x)
|
||||||
if not (isinstance(x, list) or isinstance(x, tuple)):
|
if not isinstance(x, (list, tuple)):
|
||||||
if STRICT:
|
if STRICT:
|
||||||
raise PDFTypeError('List required: %r' % x)
|
raise PDFTypeError('List required: %r' % x)
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -556,11 +556,7 @@ class PSStackParser(PSBaseParser):
|
||||||
while not self.results:
|
while not self.results:
|
||||||
(pos, token) = self.nexttoken()
|
(pos, token) = self.nexttoken()
|
||||||
#print (pos,token), (self.curtype, self.curstack)
|
#print (pos,token), (self.curtype, self.curstack)
|
||||||
if (isinstance(token, int) or
|
if isinstance(token, (int, long, float, bool, str, PSLiteral)):
|
||||||
isinstance(token, float) or
|
|
||||||
isinstance(token, bool) or
|
|
||||||
isinstance(token, str) or
|
|
||||||
isinstance(token, PSLiteral)):
|
|
||||||
# normal token
|
# normal token
|
||||||
self.push((pos, token))
|
self.push((pos, token))
|
||||||
elif token == KEYWORD_ARRAY_BEGIN:
|
elif token == KEYWORD_ARRAY_BEGIN:
|
||||||
|
|
|
@ -79,6 +79,10 @@ def apply_matrix_norm((a, b, c, d, e, f), (p, q)):
|
||||||
## Utility functions
|
## Utility functions
|
||||||
##
|
##
|
||||||
|
|
||||||
|
# isnumber
|
||||||
|
def isnumber(x):
|
||||||
|
return isinstance(x, (int, long, float))
|
||||||
|
|
||||||
# uniq
|
# uniq
|
||||||
def uniq(objs):
|
def uniq(objs):
|
||||||
"""Eliminates duplicated elements."""
|
"""Eliminates duplicated elements."""
|
||||||
|
|
|
@ -13,6 +13,7 @@ from pdfminer.pdfdocument import PDFDocument, PDFNoOutlines
|
||||||
from pdfminer.pdftypes import PDFObjectNotFound, PDFValueError
|
from pdfminer.pdftypes import PDFObjectNotFound, PDFValueError
|
||||||
from pdfminer.pdftypes import PDFStream, PDFObjRef, resolve1, stream_value
|
from pdfminer.pdftypes import PDFStream, PDFObjRef, resolve1, stream_value
|
||||||
from pdfminer.pdfpage import PDFPage
|
from pdfminer.pdfpage import PDFPage
|
||||||
|
from pdfminer.utils import isnumber
|
||||||
|
|
||||||
|
|
||||||
ESC_PAT = re.compile(r'[\000-\037&<>()"\042\047\134\177-\377]')
|
ESC_PAT = re.compile(r'[\000-\037&<>()"\042\047\134\177-\377]')
|
||||||
|
@ -75,7 +76,7 @@ def dumpxml(out, obj, codec=None):
|
||||||
out.write('<literal>%s</literal>' % obj.name)
|
out.write('<literal>%s</literal>' % obj.name)
|
||||||
return
|
return
|
||||||
|
|
||||||
if isinstance(obj, int) or isinstance(obj, float):
|
if isnumber(obj):
|
||||||
out.write('<number>%s</number>' % obj)
|
out.write('<number>%s</number>' % obj)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue