Convert the string *s* to vertices and codes using usetex mode.
(self, prop, s, glyph_map=None,
return_new_glyphs_only=False)
| 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 | |
| 269 | text_to_path = TextToPath() |