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

Method transform

lib/matplotlib/_type1font.py:711–777  ·  view source on GitHub ↗

Return a new font that is slanted and/or extended. Parameters ---------- effects : dict A dict with optional entries: - 'slant' : float, default: 0 Tangent of the angle that the font is to be slanted to the ri

(self, effects)

Source from the content-addressed store, hash-verified

709 return data[init_pos:token.endpos()], token.endpos()
710
711 def transform(self, effects):
712 """
713 Return a new font that is slanted and/or extended.
714
715 Parameters
716 ----------
717 effects : dict
718 A dict with optional entries:
719
720 - 'slant' : float, default: 0
721 Tangent of the angle that the font is to be slanted to the
722 right. Negative values slant to the left.
723 - 'extend' : float, default: 1
724 Scaling factor for the font width. Values less than 1 condense
725 the glyphs.
726
727 Returns
728 -------
729 `Type1Font`
730 """
731 fontname = self.prop['FontName']
732 italicangle = self.prop['ItalicAngle']
733
734 array = [
735 float(x) for x in (self.prop['FontMatrix']
736 .lstrip('[').rstrip(']').split())
737 ]
738 oldmatrix = np.eye(3, 3)
739 oldmatrix[0:3, 0] = array[::2]
740 oldmatrix[0:3, 1] = array[1::2]
741 modifier = np.eye(3, 3)
742
743 if 'slant' in effects:
744 slant = effects['slant']
745 fontname += f'_Slant_{int(1000 * slant)}'
746 italicangle = round(
747 float(italicangle) - np.arctan(slant) / np.pi * 180,
748 5
749 )
750 modifier[1, 0] = slant
751
752 if 'extend' in effects:
753 extend = effects['extend']
754 fontname += f'_Extend_{int(1000 * extend)}'
755 modifier[0, 0] = extend
756
757 newmatrix = np.dot(modifier, oldmatrix)
758 array[::2] = newmatrix[0:3, 0]
759 array[1::2] = newmatrix[0:3, 1]
760 fontmatrix = (
761 f"[{' '.join(_format_approx(x, 6) for x in array)}]"
762 )
763 newparts = self._replace(
764 [(x, f'/FontName/{fontname} def')
765 for x in self._pos['FontName']]
766 + [(x, f'/ItalicAngle {italicangle} def')
767 for x in self._pos['ItalicAngle']]
768 + [(x, f'/FontMatrix {fontmatrix} readonly def')

Callers 3

_embedTeXFontMethod · 0.95
test_Type1FontFunction · 0.95
test_overprecisionFunction · 0.95

Calls 7

_replaceMethod · 0.95
_encryptMethod · 0.95
_format_approxFunction · 0.90
Type1FontClass · 0.85
dotMethod · 0.80
joinMethod · 0.80
getMethod · 0.45

Tested by 2

test_Type1FontFunction · 0.76
test_overprecisionFunction · 0.76