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

Class TtfMetrics

lib/matplotlib/dviread.py:1027–1045  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1025
1026
1027class TtfMetrics:
1028 def __init__(self, filename):
1029 self._face = font_manager.get_font(filename)
1030
1031 def get_metrics(self, idx):
1032 # _mul1220 uses a truncating bitshift for compatibility with dvitype.
1033 # When upem is 2048 the conversion to 12.20 is exact, but when
1034 # upem is 1000 (e.g. lmroman10-regular.otf) the metrics themselves
1035 # are not exactly representable as 12.20 fp. Manual testing via
1036 # \sbox0{x}\count0=\wd0\typeout{\the\count0} suggests that metrics
1037 # are rounded (not truncated) after conversion to 12.20 and before
1038 # multiplication by the scale.
1039 upem = self._face.units_per_EM # Usually 2048 or 1000.
1040 g = self._face.load_glyph(idx, LoadFlags.NO_SCALE)
1041 return TexMetrics(
1042 tex_width=round(g.horiAdvance / upem * 2**20),
1043 tex_height=round(g.horiBearingY / upem * 2**20),
1044 tex_depth=round((g.height - g.horiBearingY) / upem * 2**20),
1045 )
1046
1047
1048PsFont = namedtuple('PsFont', 'texname psname effects encoding filename')

Callers 2

from_luatexMethod · 0.85
from_xetexMethod · 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…