MCPcopy Index your code
hub / github.com/clips/pattern / __init__

Method __init__

pattern/web/pdf/pdffont.py:600–666  ·  view source on GitHub ↗
(self, rsrcmgr, spec)

Source from the content-addressed store, hash-verified

598class PDFCIDFont(PDFFont):
599
600 def __init__(self, rsrcmgr, spec):
601 try:
602 self.basefont = literal_name(spec['BaseFont'])
603 except KeyError:
604 if STRICT:
605 raise PDFFontError('BaseFont is missing')
606 self.basefont = 'unknown'
607 self.cidsysteminfo = dict_value(spec.get('CIDSystemInfo', {}))
608 self.cidcoding = '%s-%s' % (self.cidsysteminfo.get('Registry', 'unknown'),
609 self.cidsysteminfo.get('Ordering', 'unknown'))
610 try:
611 name = literal_name(spec['Encoding'])
612 except KeyError:
613 if STRICT:
614 raise PDFFontError('Encoding is unspecified')
615 name = 'unknown'
616 try:
617 self.cmap = CMapDB.get_cmap(name)
618 except CMapDB.CMapNotFound, e:
619 if STRICT:
620 raise PDFFontError(e)
621 self.cmap = CMap()
622 try:
623 descriptor = dict_value(spec['FontDescriptor'])
624 except KeyError:
625 if STRICT:
626 raise PDFFontError('FontDescriptor is missing')
627 descriptor = {}
628 ttf = None
629 if 'FontFile2' in descriptor:
630 self.fontfile = stream_value(descriptor.get('FontFile2'))
631 ttf = TrueTypeFont(self.basefont,
632 StringIO(self.fontfile.get_data()))
633 self.unicode_map = None
634 if 'ToUnicode' in spec:
635 strm = stream_value(spec['ToUnicode'])
636 self.unicode_map = FileUnicodeMap()
637 CMapParser(self.unicode_map, StringIO(strm.get_data())).run()
638 elif self.cidcoding == 'Adobe-Identity':
639 if ttf:
640 try:
641 self.unicode_map = ttf.create_unicode_map()
642 except TrueTypeFont.CMapNotFound:
643 pass
644 else:
645 try:
646 self.unicode_map = CMapDB.get_unicode_map(self.cidcoding, self.cmap.is_vertical())
647 except CMapDB.CMapNotFound, e:
648 pass
649
650 self.vertical = self.cmap.is_vertical()
651 if self.vertical:
652 # writing mode: vertical
653 widths = get_widths2(list_value(spec.get('W2', [])))
654 self.disps = dict( (cid,(vx,vy)) for (cid,(_,(vx,vy))) in widths.iteritems() )
655 (vy,w) = spec.get('DW2', [880, -1000])
656 self.default_disp = (None,vy)
657 widths = dict( (cid,w) for (cid,(w,_)) in widths.iteritems() )

Callers

nothing calls this directly

Calls 15

create_unicode_mapMethod · 0.95
literal_nameFunction · 0.90
dict_valueFunction · 0.90
CMapClass · 0.90
stream_valueFunction · 0.90
FileUnicodeMapClass · 0.90
CMapParserClass · 0.90
list_valueFunction · 0.90
PDFFontErrorClass · 0.85
TrueTypeFontClass · 0.85
get_widths2Function · 0.85
get_widthsFunction · 0.85

Tested by

no test coverage detected