Adds Test Cases, Neater Code For CMap Assignment
parent
b4c261b647
commit
f1a4dcea88
|
@ -649,7 +649,7 @@ class PDFCIDFont(PDFFont):
|
||||||
self.cidsysteminfo = dict_value(spec.get('CIDSystemInfo', {}))
|
self.cidsysteminfo = dict_value(spec.get('CIDSystemInfo', {}))
|
||||||
self.cidcoding = '%s-%s' % (resolve1(self.cidsysteminfo.get('Registry', b'unknown')).decode("latin1"),
|
self.cidcoding = '%s-%s' % (resolve1(self.cidsysteminfo.get('Registry', b'unknown')).decode("latin1"),
|
||||||
resolve1(self.cidsysteminfo.get('Ordering', b'unknown')).decode("latin1"))
|
resolve1(self.cidsysteminfo.get('Ordering', b'unknown')).decode("latin1"))
|
||||||
self.cmap_setter(spec, strict)
|
self.cmap = self.get_cmap_from_spec(spec, strict)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
descriptor = dict_value(spec['FontDescriptor'])
|
descriptor = dict_value(spec['FontDescriptor'])
|
||||||
|
@ -697,7 +697,7 @@ class PDFCIDFont(PDFFont):
|
||||||
PDFFont.__init__(self, descriptor, widths, default_width=default_width)
|
PDFFont.__init__(self, descriptor, widths, default_width=default_width)
|
||||||
return
|
return
|
||||||
|
|
||||||
def cmap_setter(self, spec, strict):
|
def get_cmap_from_spec(self, spec, strict):
|
||||||
"""
|
"""
|
||||||
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
|
||||||
|
@ -723,9 +723,9 @@ class PDFCIDFont(PDFFont):
|
||||||
raise PDFFontError('CMapName unspecified for encoding')
|
raise PDFFontError('CMapName unspecified for encoding')
|
||||||
cmap_name = 'unknown'
|
cmap_name = 'unknown'
|
||||||
if cmap_name in IDENTITY_ENCODER:
|
if cmap_name in IDENTITY_ENCODER:
|
||||||
self.cmap = CMapDB.get_cmap(cmap_name)
|
return CMapDB.get_cmap(cmap_name)
|
||||||
else:
|
else:
|
||||||
self.cmap = CMap()
|
return CMap()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<PDFCIDFont: basefont=%r, cidcoding=%r>' % (self.basefont, self.cidcoding)
|
return '<PDFCIDFont: basefont=%r, cidcoding=%r>' % (self.basefont, self.cidcoding)
|
||||||
|
|
|
@ -44,6 +44,34 @@ class TestPDFEncoding():
|
||||||
font = PDFCIDFont(None, spec)
|
font = PDFCIDFont(None, spec)
|
||||||
assert isinstance(font.cmap, IdentityCMap)
|
assert isinstance(font.cmap, IdentityCMap)
|
||||||
|
|
||||||
|
def test_encoding_identityH_as_PSLiteral_stream(self):
|
||||||
|
stream = PDFStream({'CMapName':PSLiteral('Identity-H')}, '')
|
||||||
|
spec = {'Encoding': stream}
|
||||||
|
font = PDFCIDFont(None, spec)
|
||||||
|
assert isinstance(font.cmap, IdentityCMap)
|
||||||
|
|
||||||
|
def test_encoding_identityV_as_PSLiteral_stream(self):
|
||||||
|
stream = PDFStream({'CMapName':PSLiteral('Identity-V')}, '')
|
||||||
|
spec = {'Encoding': stream}
|
||||||
|
font = PDFCIDFont(None, spec)
|
||||||
|
assert isinstance(font.cmap, IdentityCMap)
|
||||||
|
|
||||||
|
def test_encoding_identityH_as_stream(self):
|
||||||
|
stream = PDFStream({'CMapName':'Identity-H'}, '')
|
||||||
|
spec = {'Encoding': stream}
|
||||||
|
font = PDFCIDFont(None, spec)
|
||||||
|
assert isinstance(font.cmap, IdentityCMap)
|
||||||
|
|
||||||
|
def test_encoding_identityV_as_stream(self):
|
||||||
|
stream = PDFStream({'CMapName':'Identity-V'}, '')
|
||||||
|
spec = {'Encoding': stream}
|
||||||
|
font = PDFCIDFont(None, spec)
|
||||||
|
assert isinstance(font.cmap, IdentityCMap)
|
||||||
|
|
||||||
|
def test_font_without_spec(self):
|
||||||
|
font = PDFCIDFont(None, {})
|
||||||
|
assert isinstance(font.cmap, CMap)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
nose.runmodule()
|
nose.runmodule()
|
||||||
|
|
Loading…
Reference in New Issue