11from collections import OrderedDict
2- import functools
32import logging
43import urllib .parse
54
@@ -242,25 +241,29 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
242241
243242# Gather font information and do some setup for combining
244243# characters into strings.
245- for x1 ,y1 ,dvifont ,glyph ,width in page .text :
246- font ,enc = self ._get_ps_font_and_encoding (dvifont .texname )
247- char_id = self ._get_char_id (font ,glyph )
248-
244+ for text in page .text :
245+ font = get_font (text .font_path )
246+ char_id = self ._get_char_id (font ,text .glyph )
249247if char_id not in glyph_map :
250248font .clear ()
251249font .set_size (self .FONT_SCALE ,self .DPI )
252- # See comments in _get_ps_font_and_encoding.
253- if enc is not None :
254- index = font .get_name_index (enc [ glyph ] )
250+ glyph_name_or_index = text . glyph_name_or_index
251+ if isinstance ( glyph_name_or_index , str ) :
252+ index = font .get_name_index (glyph_name_or_index )
255253font .load_glyph (index ,flags = LOAD_TARGET_LIGHT )
256- else :
257- font .load_char (glyph ,flags = LOAD_TARGET_LIGHT )
254+ elif isinstance (glyph_name_or_index ,int ):
255+ self ._select_native_charmap (font )
256+ font .load_char (
257+ glyph_name_or_index ,flags = LOAD_TARGET_LIGHT )
258+ else :# Should not occur.
259+ raise TypeError (f"Glyph spec of unexpected type: "
260+ f"{ glyph_name_or_index !r} " )
258261glyph_map_new [char_id ]= font .get_path ()
259262
260263glyph_ids .append (char_id )
261- xpositions .append (x1 )
262- ypositions .append (y1 )
263- sizes .append (dvifont . size / self .FONT_SCALE )
264+ xpositions .append (text . x )
265+ ypositions .append (text . y )
266+ sizes .append (text . font_size / self .FONT_SCALE )
264267
265268myrects = []
266269
@@ -276,48 +279,21 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
276279glyph_map_new ,myrects )
277280
278281@staticmethod
279- @functools .lru_cache (50 )
280- def _get_ps_font_and_encoding (texname ):
281- tex_font_map = dviread .PsfontsMap (dviread ._find_tex_file ('pdftex.map' ))
282- psfont = tex_font_map [texname ]
283- if psfont .filename is None :
284- raise ValueError (
285- f"No usable font file found for{ psfont .psname } ({ texname } ). "
286- f"The font may lack a Type-1 version." )
287-
288- font = get_font (psfont .filename )
289-
290- if psfont .encoding :
291- # If psfonts.map specifies an encoding, use it: it gives us a
292- # mapping of glyph indices to Adobe glyph names; use it to convert
293- # dvi indices to glyph names and use the FreeType-synthesized
294- # Unicode charmap to convert glyph names to glyph indices (with
295- # FT_Get_Name_Index/get_name_index), and load the glyph using
296- # FT_Load_Glyph/load_glyph. (That charmap has a coverage at least
297- # as good as, and possibly better than, the native charmaps.)
298- enc = dviread ._parse_enc (psfont .encoding )
299- else :
300- # If psfonts.map specifies no encoding, the indices directly
301- # map to the font's "native" charmap; so don't use the
302- # FreeType-synthesized charmap but the native ones (we can't
303- # directly identify it but it's typically an Adobe charmap), and
304- # directly load the dvi glyph indices using FT_Load_Char/load_char.
305- for charmap_code in [
306- 1094992451 ,# ADOBE_CUSTOM.
307- 1094995778 ,# ADOBE_STANDARD.
308- ]:
309- try :
310- font .select_charmap (charmap_code )
311- except (ValueError ,RuntimeError ):
312- pass
313- else :
314- break
282+ def _select_native_charmap (font ):
283+ # Select the native charmap. (we can't directly identify it but it's
284+ # typically an Adobe charmap).
285+ for charmap_code in [
286+ 1094992451 ,# ADOBE_CUSTOM.
287+ 1094995778 ,# ADOBE_STANDARD.
288+ ]:
289+ try :
290+ font .select_charmap (charmap_code )
291+ except (ValueError ,RuntimeError ):
292+ pass
315293else :
316- _log .warning ("No supported encoding in font (%s)." ,
317- psfont .filename )
318- enc = None
319-
320- return font ,enc
294+ break
295+ else :
296+ _log .warning ("No supported encoding in font (%s)." ,font .fname )
321297
322298
323299text_to_path = TextToPath ()