Parse mathtext string *s* and convert it to a (vertices, codes) pair.
(self, prop, s, glyph_map=None,
return_new_glyphs_only=False)
| 165 | glyph_map_new, rects) |
| 166 | |
| 167 | def get_glyphs_mathtext(self, prop, s, glyph_map=None, |
| 168 | return_new_glyphs_only=False): |
| 169 | """ |
| 170 | Parse mathtext string *s* and convert it to a (vertices, codes) pair. |
| 171 | """ |
| 172 | |
| 173 | prop = prop.copy() |
| 174 | prop.set_size(self.FONT_SCALE) |
| 175 | |
| 176 | width, height, descent, glyphs, rects = self.mathtext_parser.parse( |
| 177 | s, self.DPI, prop) |
| 178 | |
| 179 | if not glyph_map: |
| 180 | glyph_map = OrderedDict() |
| 181 | |
| 182 | if return_new_glyphs_only: |
| 183 | glyph_map_new = OrderedDict() |
| 184 | else: |
| 185 | glyph_map_new = glyph_map |
| 186 | |
| 187 | xpositions = [] |
| 188 | ypositions = [] |
| 189 | glyph_reprs = [] |
| 190 | sizes = [] |
| 191 | |
| 192 | for font, fontsize, ccode, glyph_index, ox, oy in glyphs: |
| 193 | glyph_repr = self._get_glyph_repr(font, glyph_index) |
| 194 | if glyph_repr not in glyph_map: |
| 195 | font.clear() |
| 196 | font.set_size(self.FONT_SCALE, self.DPI) |
| 197 | font.load_glyph(glyph_index, flags=LoadFlags.NO_HINTING) |
| 198 | glyph_map_new[glyph_repr] = font.get_path() |
| 199 | |
| 200 | xpositions.append(ox) |
| 201 | ypositions.append(oy) |
| 202 | glyph_reprs.append(glyph_repr) |
| 203 | size = fontsize / self.FONT_SCALE |
| 204 | sizes.append(size) |
| 205 | |
| 206 | myrects = [] |
| 207 | for ox, oy, w, h in rects: |
| 208 | vert1 = [(ox, oy), (ox, oy + h), (ox + w, oy + h), |
| 209 | (ox + w, oy), (ox, oy), (0, 0)] |
| 210 | code1 = [Path.MOVETO, |
| 211 | Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO, |
| 212 | Path.CLOSEPOLY] |
| 213 | myrects.append((vert1, code1)) |
| 214 | |
| 215 | return (list(zip(glyph_reprs, xpositions, ypositions, sizes)), |
| 216 | glyph_map_new, myrects) |
| 217 | |
| 218 | def get_glyphs_tex(self, prop, s, glyph_map=None, |
| 219 | return_new_glyphs_only=False): |