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

Class Char

lib/matplotlib/_mathtext.py:1182–1250  ·  view source on GitHub ↗

A single character. Unlike TeX, the font information and metrics are stored with each `Char` to make it easier to lookup the font metrics when needed. Note that TeX boxes have a width, height, and depth, unlike Type1 and TrueType which use a full bounding box and an advance in

Source from the content-addressed store, hash-verified

1180
1181
1182class Char(Node):
1183 """
1184 A single character.
1185
1186 Unlike TeX, the font information and metrics are stored with each `Char`
1187 to make it easier to lookup the font metrics when needed. Note that TeX
1188 boxes have a width, height, and depth, unlike Type1 and TrueType which use
1189 a full bounding box and an advance in the x-direction. The metrics must
1190 be converted to the TeX model, and the advance (if different from width)
1191 must be converted into a `Kern` node when the `Char` is added to its parent
1192 `Hlist`.
1193 """
1194
1195 def __init__(self, c: str, state: ParserState):
1196 super().__init__()
1197 self.c = c
1198 self.fontset = state.fontset
1199 self.font = state.font
1200 self.font_class = state.font_class
1201 self.fontsize = state.fontsize
1202 self.dpi = state.dpi
1203 # The real width, height and depth will be set during the
1204 # pack phase, after we know the real fontsize
1205 self._update_metrics()
1206
1207 def __repr__(self) -> str:
1208 return '`%s`' % self.c
1209
1210 def _update_metrics(self) -> None:
1211 metrics = self._metrics = self.fontset.get_metrics(
1212 self.font, self.font_class, self.c, self.fontsize, self.dpi)
1213 if self.c == ' ':
1214 self.width = metrics.advance
1215 else:
1216 self.width = metrics.width
1217 self.height = metrics.iceberg
1218 self.depth = -(metrics.iceberg - metrics.height)
1219
1220 def is_slanted(self) -> bool:
1221 return self._metrics.slanted
1222
1223 def get_kerning(self, next: Node | None) -> float:
1224 """
1225 Return the amount of kerning between this and the given character.
1226
1227 This method is called when characters are strung together into `Hlist`
1228 to create `Kern` nodes.
1229 """
1230 advance = self._metrics.advance - self.width
1231 kern = 0.
1232 if isinstance(next, Char):
1233 kern = self.fontset.get_kern(
1234 self.font, self.font_class, self.c, self.fontsize,
1235 next.font, next.font_class, next.c, next.fontsize,
1236 self.dpi)
1237 return advance + kern
1238
1239 def render(self, output: Output, x: float, y: float) -> None:

Callers 5

__init__Method · 0.85
non_mathMethod · 0.85
textMethod · 0.85
symbolMethod · 0.85
operatornameMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…