MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / get_glyphs_tex

Method get_glyphs_tex

lib/matplotlib/textpath.py:218–266  ·  view source on GitHub ↗

Convert the string *s* to vertices and codes using usetex mode.

(self, prop, s, glyph_map=None,
                       return_new_glyphs_only=False)

Source from the content-addressed store, hash-verified

216 glyph_map_new, myrects)
217
218 def get_glyphs_tex(self, prop, s, glyph_map=None,
219 return_new_glyphs_only=False):
220 """Convert the string *s* to vertices and codes using usetex mode."""
221 # Mostly borrowed from pdf backend.
222
223 dvifile = TexManager().make_dvi(s, self.FONT_SCALE)
224 with dviread.Dvi(dvifile, self.DPI) as dvi:
225 page, = dvi
226
227 if glyph_map is None:
228 glyph_map = OrderedDict()
229
230 if return_new_glyphs_only:
231 glyph_map_new = OrderedDict()
232 else:
233 glyph_map_new = glyph_map
234
235 glyph_reprs, xpositions, ypositions, sizes = [], [], [], []
236
237 # Gather font information and do some setup for combining
238 # characters into strings.
239 for text in page.text:
240 font = get_font(text.font.resolve_path())
241 if text.font.subfont:
242 raise NotImplementedError("Indexing TTC fonts is not supported yet")
243 glyph_repr = self._get_glyph_repr(font, text.index)
244 if glyph_repr not in glyph_map:
245 font.clear()
246 font.set_size(self.FONT_SCALE, self.DPI)
247 font.load_glyph(text.index, flags=LoadFlags.TARGET_LIGHT)
248 glyph_map_new[glyph_repr] = font.get_path()
249
250 glyph_reprs.append(glyph_repr)
251 xpositions.append(text.x)
252 ypositions.append(text.y)
253 sizes.append(text.font_size / self.FONT_SCALE)
254
255 myrects = []
256
257 for ox, oy, h, w in page.boxes:
258 vert1 = [(ox, oy), (ox + w, oy), (ox + w, oy + h),
259 (ox, oy + h), (ox, oy), (0, 0)]
260 code1 = [Path.MOVETO,
261 Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO,
262 Path.CLOSEPOLY]
263 myrects.append((vert1, code1))
264
265 return (list(zip(glyph_reprs, xpositions, ypositions, sizes)),
266 glyph_map_new, myrects)
267
268
269text_to_path = TextToPath()

Callers 3

get_text_pathMethod · 0.95
test_unicode_sizingFunction · 0.95
_draw_text_as_pathMethod · 0.80

Calls 8

_get_glyph_reprMethod · 0.95
TexManagerClass · 0.90
get_fontFunction · 0.90
make_dviMethod · 0.80
resolve_pathMethod · 0.80
clearMethod · 0.45
set_sizeMethod · 0.45
get_pathMethod · 0.45

Tested by 1

test_unicode_sizingFunction · 0.76