MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / Char

Class Char

site-packages/matplotlib/mathtext.py:1425–1501  ·  view source on GitHub ↗

Represents a single character. Unlike TeX, the font information and metrics are stored with each :class:`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

Source from the content-addressed store, hash-verified

1423 Box.__init__(self, width, 0., 0.)
1424
1425class Char(Node):
1426 """
1427 Represents a single character. Unlike TeX, the font information
1428 and metrics are stored with each :class:`Char` to make it easier
1429 to lookup the font metrics when needed. Note that TeX boxes have
1430 a width, height, and depth, unlike Type1 and Truetype which use a
1431 full bounding box and an advance in the x-direction. The metrics
1432 must be converted to the TeX way, and the advance (if different
1433 from width) must be converted into a :class:`Kern` node when the
1434 :class:`Char` is added to its parent :class:`Hlist`.
1435 """
1436 def __init__(self, c, state, math=True):
1437 Node.__init__(self)
1438 self.c = c
1439 self.font_output = state.font_output
1440 self.font = state.font
1441 self.font_class = state.font_class
1442 self.fontsize = state.fontsize
1443 self.dpi = state.dpi
1444 self.math = math
1445 # The real width, height and depth will be set during the
1446 # pack phase, after we know the real fontsize
1447 self._update_metrics()
1448
1449 def __repr__(self):
1450 return '`%s`' % self.c
1451
1452 def _update_metrics(self):
1453 metrics = self._metrics = self.font_output.get_metrics(
1454 self.font, self.font_class, self.c, self.fontsize, self.dpi, self.math)
1455 if self.c == ' ':
1456 self.width = metrics.advance
1457 else:
1458 self.width = metrics.width
1459 self.height = metrics.iceberg
1460 self.depth = -(metrics.iceberg - metrics.height)
1461
1462 def is_slanted(self):
1463 return self._metrics.slanted
1464
1465 def get_kerning(self, next):
1466 """
1467 Return the amount of kerning between this and the given
1468 character. Called when characters are strung together into
1469 :class:`Hlist` to create :class:`Kern` nodes.
1470 """
1471 advance = self._metrics.advance - self.width
1472 kern = 0.
1473 if isinstance(next, Char):
1474 kern = self.font_output.get_kern(
1475 self.font, self.font_class, self.c, self.fontsize,
1476 next.font, next.font_class, next.c, next.fontsize,
1477 self.dpi)
1478 return advance + kern
1479
1480 def render(self, x, y):
1481 """
1482 Render the character to the canvas

Callers 6

__init__Method · 0.70
non_mathMethod · 0.70
symbolMethod · 0.70
c_over_cMethod · 0.70
functionMethod · 0.70
sqrtMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected