Convert text *s* to path (a tuple of vertices and codes for matplotlib.path.Path). Parameters ---------- prop : `~matplotlib.font_manager.FontProperties` The font properties for the text. s : str The text to be converted.
(self, prop, s, ismath=False, *, features=None, language=None)
| 68 | return w * scale, h * scale, d * scale |
| 69 | |
| 70 | def get_text_path(self, prop, s, ismath=False, *, features=None, language=None): |
| 71 | """ |
| 72 | Convert text *s* to path (a tuple of vertices and codes for |
| 73 | matplotlib.path.Path). |
| 74 | |
| 75 | Parameters |
| 76 | ---------- |
| 77 | prop : `~matplotlib.font_manager.FontProperties` |
| 78 | The font properties for the text. |
| 79 | s : str |
| 80 | The text to be converted. |
| 81 | ismath : {False, True, "TeX"} |
| 82 | If True, use mathtext parser. If "TeX", use tex for rendering. |
| 83 | language : str, optional |
| 84 | The language of the text in a format accepted by libraqm, namely `a BCP47 |
| 85 | language code <https://www.w3.org/International/articles/language-tags/>`_. |
| 86 | |
| 87 | Returns |
| 88 | ------- |
| 89 | verts : list |
| 90 | A list of arrays containing the (x, y) coordinates of the vertices. |
| 91 | codes : list |
| 92 | A list of path codes. |
| 93 | |
| 94 | Examples |
| 95 | -------- |
| 96 | Create a list of vertices and codes from a text, and create a `.Path` |
| 97 | from those:: |
| 98 | |
| 99 | from matplotlib.path import Path |
| 100 | from matplotlib.text import TextToPath |
| 101 | from matplotlib.font_manager import FontProperties |
| 102 | |
| 103 | fp = FontProperties(family="Comic Neue", style="italic") |
| 104 | verts, codes = TextToPath().get_text_path(fp, "ABC") |
| 105 | path = Path(verts, codes, closed=False) |
| 106 | |
| 107 | Also see `TextPath` for a more direct way to create a path from a text. |
| 108 | """ |
| 109 | if ismath == "TeX": |
| 110 | glyph_info, glyph_map, rects = self.get_glyphs_tex(prop, s) |
| 111 | elif not ismath: |
| 112 | font = self._get_font(prop) |
| 113 | glyph_info, glyph_map, rects = self.get_glyphs_with_font( |
| 114 | font, s, features=features, language=language) |
| 115 | else: |
| 116 | glyph_info, glyph_map, rects = self.get_glyphs_mathtext(prop, s) |
| 117 | |
| 118 | verts, codes = [], [] |
| 119 | for glyph_repr, xposition, yposition, scale in glyph_info: |
| 120 | verts1, codes1 = glyph_map[glyph_repr] |
| 121 | verts.extend(verts1 * scale + [xposition, yposition]) |
| 122 | codes.extend(codes1) |
| 123 | for verts1, codes1 in rects: |
| 124 | verts.extend(verts1) |
| 125 | codes.extend(codes1) |
| 126 | |
| 127 | # Make sure an empty string or one with nothing to print |
no test coverage detected