Removes code comments

pull/283/head
Fakabbir Amin 2019-08-20 16:48:40 +05:30
parent 3f0f05def6
commit 3d549ea48c
2 changed files with 11 additions and 61 deletions

View File

@ -1,5 +1,3 @@
""" Adobe character mapping (CMap) support. """ Adobe character mapping (CMap) support.
CMaps provide the mapping between character codes and Unicode CMaps provide the mapping between character codes and Unicode
@ -40,8 +38,6 @@ class CMapError(Exception):
pass pass
## CMapBase
##
class CMapBase(object): class CMapBase(object):
debug = 0 debug = 0
@ -67,8 +63,6 @@ class CMapBase(object):
return return
## CMap
##
class CMap(CMapBase): class CMap(CMapBase):
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -119,8 +113,6 @@ class CMap(CMapBase):
return return
## IdentityCMap
##
class IdentityCMap(CMapBase): class IdentityCMap(CMapBase):
def decode(self, code): def decode(self, code):
@ -140,8 +132,7 @@ class IdentityCMapByte(IdentityCMap):
else: else:
return () return ()
## UnicodeMap
##
class UnicodeMap(CMapBase): class UnicodeMap(CMapBase):
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -162,8 +153,6 @@ class UnicodeMap(CMapBase):
return return
## FileCMap
##
class FileCMap(CMap): class FileCMap(CMap):
def add_code2cid(self, code, cid): def add_code2cid(self, code, cid):
@ -182,8 +171,6 @@ class FileCMap(CMap):
return return
## FileUnicodeMap
##
class FileUnicodeMap(UnicodeMap): class FileUnicodeMap(UnicodeMap):
def add_cid2unichr(self, cid, code): def add_cid2unichr(self, cid, code):
@ -201,8 +188,6 @@ class FileUnicodeMap(UnicodeMap):
return return
## PyCMap
##
class PyCMap(CMap): class PyCMap(CMap):
def __init__(self, name, module): def __init__(self, name, module):
@ -213,8 +198,6 @@ class PyCMap(CMap):
return return
## PyUnicodeMap
##
class PyUnicodeMap(UnicodeMap): class PyUnicodeMap(UnicodeMap):
def __init__(self, name, module, vertical): def __init__(self, name, module, vertical):
@ -227,8 +210,6 @@ class PyUnicodeMap(UnicodeMap):
return return
## CMapDB
##
class CMapDB(object): class CMapDB(object):
_cmap_cache = {} _cmap_cache = {}
@ -284,8 +265,6 @@ class CMapDB(object):
return umaps[vertical] return umaps[vertical]
## CMapParser
##
class CMapParser(PSStackParser): class CMapParser(PSStackParser):
def __init__(self, cmap, fp): def __init__(self, cmap, fp):
@ -373,7 +352,6 @@ class CMapParser(PSStackParser):
s1 = nunpack(svar) s1 = nunpack(svar)
e1 = nunpack(evar) e1 = nunpack(evar)
vlen = len(svar) vlen = len(svar)
#assert s1 <= e1, str((s1, e1))
for i in range(e1-s1+1): for i in range(e1-s1+1):
x = sprefix+struct.pack('>L', s1+i)[-vlen:] x = sprefix+struct.pack('>L', s1+i)[-vlen:]
self.cmap.add_code2cid(x, cid+i) self.cmap.add_code2cid(x, cid+i)
@ -400,7 +378,6 @@ class CMapParser(PSStackParser):
continue continue
s1 = nunpack(s) s1 = nunpack(s)
e1 = nunpack(e) e1 = nunpack(e)
#assert s1 <= e1, str((s1, e1))
if isinstance(code, list): if isinstance(code, list):
for i in range(e1-s1+1): for i in range(e1-s1+1):
self.cmap.add_cid2unichr(s1+i, code[i]) self.cmap.add_cid2unichr(s1+i, code[i])
@ -435,17 +412,16 @@ class CMapParser(PSStackParser):
return return
# test
def main(argv): def main(argv):
args = argv[1:] args = argv[1:]
for fname in args: for fname in args:
fp = open(fname, 'rb') fp = open(fname, 'rb')
cmap = FileUnicodeMap() cmap = FileUnicodeMap()
#cmap = FileCMap()
CMapParser(cmap, fp).run() CMapParser(cmap, fp).run()
fp.close() fp.close()
cmap.dump() cmap.dump()
return return
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))

View File

@ -35,7 +35,6 @@ from .utils import nunpack
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def get_widths(seq): def get_widths(seq):
widths = {} widths = {}
r = [] r = []
@ -54,10 +53,6 @@ def get_widths(seq):
widths[i] = w widths[i] = w
r = [] r = []
return widths return widths
#assert get_widths([1]) == {}
#assert get_widths([1,2,3]) == {1:3, 2:3}
#assert get_widths([1,[2,3],6,[7,8]]) == {1:2,2:3, 6:7,7:8}
def get_widths2(seq): def get_widths2(seq):
widths = {} widths = {}
@ -77,13 +72,8 @@ def get_widths2(seq):
widths[i] = (w, (vx, vy)) widths[i] = (w, (vx, vy))
r = [] r = []
return widths return widths
#assert get_widths2([1]) == {}
#assert get_widths2([1,2,3,4,5]) == {1:(3, (4,5)), 2:(3, (4,5))}
#assert get_widths2([1,[2,3,4,5],6,[7,8,9]]) == {1:(2, (3,4)), 6:(7, (8,9))}
## FontMetricsDB
##
class FontMetricsDB(object): class FontMetricsDB(object):
@classmethod @classmethod
@ -91,8 +81,6 @@ class FontMetricsDB(object):
return FONT_METRICS[fontname] return FONT_METRICS[fontname]
## Type1FontHeaderParser
##
class Type1FontHeaderParser(PSStackParser): class Type1FontHeaderParser(PSStackParser):
KEYWORD_BEGIN = KWD(b'begin') KEYWORD_BEGIN = KWD(b'begin')
@ -142,6 +130,10 @@ class Type1FontHeaderParser(PSStackParser):
NIBBLES = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'e', 'e-', None, '-') NIBBLES = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'e', 'e-', None, '-')
"""
Note: DLIdent-* isn't found in PDF Reference but is been kept as
it is harmless and have possibility of been a type. (induced from bug report/PR)
"""
IDENTITY_ENCODER = {'Identity-H':'Identity-H', IDENTITY_ENCODER = {'Identity-H':'Identity-H',
'Identity-V':'Identity-V', 'Identity-V':'Identity-V',
'DLIdent-H':'Identity-H', 'DLIdent-H':'Identity-H',
@ -150,10 +142,6 @@ IDENTITY_ENCODER = {'Identity-H':'Identity-H',
'OneByteIdentityV':'OneByteIdentityV', 'OneByteIdentityV':'OneByteIdentityV',
} }
## CFFFont
## (Format specified in Adobe Technical Note: #5176
## "The Compact Font Format Specification")
##
def getdict(data): def getdict(data):
d = {} d = {}
fp = BytesIO(data) fp = BytesIO(data)
@ -281,6 +269,7 @@ class CFFFont(object):
'Light', 'Medium', 'Regular', 'Roman', 'Semibold', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold',
) )
class INDEX(object): class INDEX(object):
def __init__(self, fp): def __init__(self, fp):
@ -381,9 +370,6 @@ class CFFFont(object):
assert False, str(('Unhandled', format)) assert False, str(('Unhandled', format))
else: else:
raise ValueError('unsupported charset format: %r' % format) raise ValueError('unsupported charset format: %r' % format)
#print self.code2gid
#print self.name2gid
#assert 0
return return
def getstr(self, sid): def getstr(self, sid):
@ -392,8 +378,6 @@ class CFFFont(object):
return self.string_index[sid-len(self.STANDARD_STRINGS)] return self.string_index[sid-len(self.STANDARD_STRINGS)]
## TrueTypeFont
##
class TrueTypeFont(object): class TrueTypeFont(object):
class CMapNotFound(Exception): class CMapNotFound(Exception):
@ -479,8 +463,6 @@ class TrueTypeFont(object):
return unicode_map return unicode_map
## Fonts
##
class PDFFontError(PDFException): class PDFFontError(PDFException):
pass pass
@ -492,7 +474,6 @@ LITERAL_STANDARD_ENCODING = LIT('StandardEncoding')
LITERAL_TYPE1C = LIT('Type1C') LITERAL_TYPE1C = LIT('Type1C')
# PDFFont
class PDFFont(object): class PDFFont(object):
def __init__(self, descriptor, widths, default_width=None): def __init__(self, descriptor, widths, default_width=None):
@ -557,7 +538,6 @@ class PDFFont(object):
return sum(self.char_width(cid) for cid in self.decode(s)) return sum(self.char_width(cid) for cid in self.decode(s))
# PDFSimpleFont
class PDFSimpleFont(PDFFont): class PDFSimpleFont(PDFFont):
def __init__(self, descriptor, widths, spec): def __init__(self, descriptor, widths, spec):
@ -594,7 +574,6 @@ class PDFSimpleFont(PDFFont):
raise PDFUnicodeNotDefined(None, cid) raise PDFUnicodeNotDefined(None, cid)
# PDFType1Font
class PDFType1Font(PDFSimpleFont): class PDFType1Font(PDFSimpleFont):
def __init__(self, rsrcmgr, spec): def __init__(self, rsrcmgr, spec):
@ -626,14 +605,12 @@ class PDFType1Font(PDFSimpleFont):
return '<PDFType1Font: basefont=%r>' % self.basefont return '<PDFType1Font: basefont=%r>' % self.basefont
# PDFTrueTypeFont
class PDFTrueTypeFont(PDFType1Font): class PDFTrueTypeFont(PDFType1Font):
def __repr__(self): def __repr__(self):
return '<PDFTrueTypeFont: basefont=%r>' % self.basefont return '<PDFTrueTypeFont: basefont=%r>' % self.basefont
# PDFType3Font
class PDFType3Font(PDFSimpleFont): class PDFType3Font(PDFSimpleFont):
def __init__(self, rsrcmgr, spec): def __init__(self, rsrcmgr, spec):
@ -656,7 +633,6 @@ class PDFType3Font(PDFSimpleFont):
return '<PDFType3Font>' return '<PDFType3Font>'
# PDFCIDFont
class PDFCIDFont(PDFFont): class PDFCIDFont(PDFFont):
def __init__(self, rsrcmgr, spec, strict=settings.STRICT): def __init__(self, rsrcmgr, spec, strict=settings.STRICT):
@ -721,9 +697,9 @@ class PDFCIDFont(PDFFont):
""" """
For certain PDFs, Encoding Type isn't mentioned as an attribute of For certain PDFs, Encoding Type isn't mentioned as an attribute of
Encoding but as an attribute of CMapName, where CMapName is an Encoding but as an attribute of CMapName, where CMapName is an
attribure of spec['Encoding']. attribute of spec['Encoding'].
The horizaontal/vertical modes are mentioned with diffrent name The horizontal/vertical modes are mentioned with different name
such as 'DLIdent-H/V','OneByteIdentityH/V','Identity-H/V' such as 'DLIdent-H/V','OneByteIdentityH/V','Identity-H/V'.
""" """
try: try:
spec_encoding = spec['Encoding'] spec_encoding = spec['Encoding']
@ -771,16 +747,14 @@ class PDFCIDFont(PDFFont):
except KeyError: except KeyError:
raise PDFUnicodeNotDefined(self.cidcoding, cid) raise PDFUnicodeNotDefined(self.cidcoding, cid)
# main
def main(argv): def main(argv):
for fname in argv[1:]: for fname in argv[1:]:
fp = open(fname, 'rb') fp = open(fname, 'rb')
#font = TrueTypeFont(fname, fp)
font = CFFFont(fname, fp) font = CFFFont(fname, fp)
print (font) print (font)
fp.close() fp.close()
return return
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))