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

Method get_font

pattern/web/pdf/pdfinterp.py:157–200  ·  view source on GitHub ↗
(self, objid, spec)

Source from the content-addressed store, hash-verified

155 return CMap()
156
157 def get_font(self, objid, spec):
158 if objid and objid in self._cached_fonts:
159 font = self._cached_fonts[objid]
160 else:
161 if 2 <= self.debug:
162 print >>sys.stderr, 'get_font: create: objid=%r, spec=%r' % (objid, spec)
163 if STRICT:
164 if spec['Type'] is not LITERAL_FONT:
165 raise PDFFontError('Type is not /Font')
166 # Create a Font object.
167 if 'Subtype' in spec:
168 subtype = literal_name(spec['Subtype'])
169 else:
170 if STRICT:
171 raise PDFFontError('Font Subtype is not specified.')
172 subtype = 'Type1'
173 if subtype in ('Type1', 'MMType1'):
174 # Type1 Font
175 font = PDFType1Font(self, spec)
176 elif subtype == 'TrueType':
177 # TrueType Font
178 font = PDFTrueTypeFont(self, spec)
179 elif subtype == 'Type3':
180 # Type3 Font
181 font = PDFType3Font(self, spec)
182 elif subtype in ('CIDFontType0', 'CIDFontType2'):
183 # CID Font
184 font = PDFCIDFont(self, spec)
185 elif subtype == 'Type0':
186 # Type0 Font
187 dfonts = list_value(spec['DescendantFonts'])
188 assert dfonts
189 subspec = dict_value(dfonts[0]).copy()
190 for k in ('Encoding', 'ToUnicode'):
191 if k in spec:
192 subspec[k] = resolve1(spec[k])
193 font = self.get_font(None, subspec)
194 else:
195 if STRICT:
196 raise PDFFontError('Invalid Font spec: %r' % spec)
197 font = PDFType1Font(self, spec) # this is so wrong!
198 if objid and self.caching:
199 self._cached_fonts[objid] = font
200 return font
201
202
203## PDFContentParser

Callers 1

init_resourcesMethod · 0.80

Calls 10

PDFFontErrorClass · 0.90
literal_nameFunction · 0.90
PDFType1FontClass · 0.90
PDFTrueTypeFontClass · 0.90
PDFType3FontClass · 0.90
PDFCIDFontClass · 0.90
list_valueFunction · 0.90
dict_valueFunction · 0.90
resolve1Function · 0.90
copyMethod · 0.45

Tested by

no test coverage detected