Generate a TeX string that renders string *s* with font properties *prop*, also applying any required escapes to *s*.
(s, prop)
| 102 | |
| 103 | |
| 104 | def _escape_and_apply_props(s, prop): |
| 105 | """ |
| 106 | Generate a TeX string that renders string *s* with font properties *prop*, |
| 107 | also applying any required escapes to *s*. |
| 108 | """ |
| 109 | commands = [] |
| 110 | |
| 111 | families = {"serif": r"\rmfamily", "sans": r"\sffamily", |
| 112 | "sans-serif": r"\sffamily", "monospace": r"\ttfamily"} |
| 113 | family = prop.get_family()[0] |
| 114 | if family in families: |
| 115 | commands.append(families[family]) |
| 116 | elif not mpl.rcParams["pgf.rcfonts"]: |
| 117 | commands.append(r"\fontfamily{\familydefault}") |
| 118 | elif any(font.name == family for font in fm.fontManager.ttflist): |
| 119 | commands.append( |
| 120 | r"\ifdefined\pdftexversion\else\setmainfont{%s}\rmfamily\fi" % family) |
| 121 | else: |
| 122 | _log.warning("Ignoring unknown font: %s", family) |
| 123 | |
| 124 | size = prop.get_size_in_points() |
| 125 | commands.append(r"\fontsize{%f}{%f}" % (size, size * 1.2)) |
| 126 | |
| 127 | styles = {"normal": r"", "italic": r"\itshape", "oblique": r"\slshape"} |
| 128 | commands.append(styles[prop.get_style()]) |
| 129 | |
| 130 | boldstyles = ["semibold", "demibold", "demi", "bold", "heavy", |
| 131 | "extra bold", "black"] |
| 132 | if prop.get_weight() in boldstyles: |
| 133 | commands.append(r"\bfseries") |
| 134 | |
| 135 | commands.append(r"\selectfont") |
| 136 | return ( |
| 137 | "{" |
| 138 | + "".join(commands) |
| 139 | + r"\catcode`\^=\active\def^{\ifmmode\sp\else\^{}\fi}" |
| 140 | # It should normally be enough to set the catcode of % to 12 ("normal |
| 141 | # character"); this works on TeXLive 2021 but not on 2018, so we just |
| 142 | # make it active too. |
| 143 | + r"\catcode`\%=\active\def%{\%}" |
| 144 | + _tex_escape(s) |
| 145 | + "}" |
| 146 | ) |
| 147 | |
| 148 | |
| 149 | def _metadata_to_str(key, value): |
no test coverage detected
searching dependent graphs…