-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix auto-sized glyphs with BaKoMa fonts #29936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
QuLogic
wants to merge
2
commits into
matplotlib:main
Choose a base branch
from
QuLogic:bakoma-sizes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | 8000Diff line change |
---|---|---|
|
@@ -470,60 +470,40 @@ def _get_glyph(self, fontname: str, font_class: str, | |
else: | ||
return self._stix_fallback._get_glyph(fontname, font_class, sym) | ||
|
||
# The Bakoma fonts contain many pre-sized alternatives for the | ||
# delimiters. The AutoSizedChar class will use these alternatives | ||
# and select the best (closest sized) glyph. | ||
# The Bakoma fonts contain many pre-sized alternatives for the delimiters. The | ||
# Auto(Height|Width)Char classes will use these alternatives and select the best | ||
# (closest sized) glyph. | ||
_latex_sizes = ('big', 'Big', 'bigg', 'Bigg') | ||
_size_alternatives = { | ||
'(': [('rm', '('), ('ex', '\xa1'), ('ex', '\xb3'), | ||
('ex', '\xb5'), ('ex', '\xc3')], | ||
')': [('rm', ')'), ('ex', '\xa2'), ('ex', '\xb4'), | ||
('ex', '\xb6'), ('ex', '\x21')], | ||
'{': [('cal', '{'), ('ex', '\xa9'), ('ex', '\x6e'), | ||
('ex', '\xbd'), ('ex', '\x28')], | ||
'}': [('cal', '}'), ('ex', '\xaa'), ('ex', '\x6f'), | ||
('ex', '\xbe'), ('ex', '\x29')], | ||
# The fourth size of '[' is mysteriously missing from the BaKoMa | ||
# font, so I've omitted it for both '[' and ']' | ||
'[': [('rm', '['), ('ex', '\xa3'), ('ex', '\x68'), | ||
('ex', '\x22')], | ||
']': [('rm', ']'), ('ex', '\xa4'), ('ex', '\x69'), | ||
('ex', '\x23')], | ||
r'\lfloor': [('ex', '\xa5'), ('ex', '\x6a'), | ||
('ex', '\xb9'), ('ex', '\x24')], | ||
r'\rfloor': [('ex', '\xa6'), ('ex', '\x6b'), | ||
('ex', '\xba'), ('ex', '\x25')], | ||
r'\lceil': [('ex', '\xa7'), ('ex', '\x6c'), | ||
('ex', '\xbb'), ('ex', '\x26')], | ||
r'\rceil': [('ex', '\xa8'), ('ex', '\x6d'), | ||
('ex', '\xbc'), ('ex', '\x27')], | ||
r'\langle': [('ex', '\xad'), ('ex', '\x44'), | ||
('ex', '\xbf'), ('ex', '\x2a')], | ||
r'\rangle': [('ex', '\xae'), ('ex', '\x45'), | ||
('ex', '\xc0'), ('ex', '\x2b')], | ||
r'\__sqrt__': [('ex', '\x70'), ('ex', '\x71'), | ||
('ex', '\x72'), ('ex', '\x73')], | ||
r'\backslash': [('ex', '\xb2'), ('ex', '\x2f'), | ||
('ex', '\xc2'), ('ex', '\x2d')], | ||
r'/': [('rm', '/'), ('ex', '\xb1'), ('ex', '\x2e'), | ||
('ex', '\xcb'), ('ex', '\x2c')], | ||
r'\widehat': [('rm', '\x5e'), ('ex', '\x62'), ('ex', '\x63'), | ||
('ex', '\x64')], | ||
r'\widetilde': [('rm', '\x7e'), ('ex', '\x65'), ('ex', '\x66'), | ||
('ex', '\x67')], | ||
r'<': [('cal', 'h'), ('ex', 'D')], | ||
r'>': [('cal', 'i'), ('ex', 'E')] | ||
} | ||
'(': [('rm', '('), *[('ex', fr'\__parenleft{s}__') for s in _latex_sizes]], | ||
')': [('rm', ')'), *[('ex', fr'\__parenright{s}__') for s in _latex_sizes]], | ||
'{': [('ex', fr'\__braceleft{s}__') for s in _latex_sizes], | ||
'}': [('ex', fr'\__braceright{s}__') for s in _latex_sizes], | ||
'[': [('rm', '['), *[('ex', fr'\__bracketleft{s}__') for s in _latex_sizes]], | ||
']': [('rm', ']'), *[('ex', fr'\__bracketright{s}__') for s in _latex_sizes]], | ||
'<': [('cal', r'\__angbracketleft__'), | ||
*[('ex', fr'\__angbracketleft{s}__') for s in _latex_sizes]], | ||
'>': [('cal', r'\__angbracketright__'), | ||
*[('ex', fr'\__angbracketright{s}__') for s in _latex_sizes]], | ||
r'\lfloor': [('ex', fr'\__floorleft{s}__') for s in _latex_sizes], | ||
r'\rfloor': [('ex', fr'\__floorright{s}__') for s in _latex_sizes], | ||
r'\lceil': [('ex', fr'\__ceilingleft{s}__') for s in _latex_sizes], | ||
r'\rceil': [('ex', fr'\__ceilingright{s}__') for s in _latex_sizes], | ||
r'\__sqrt__': [('ex', fr'\__radical{s}__') for s in _latex_sizes], | ||
r'\backslash': [('ex', fr'\__backslash{s}__') for s in _latex_sizes], | ||
r'/': [('rm', '/'), *[('ex', fr'\__slash{s}__') for s in _latex_sizes]], | ||
r'\widehat': [('rm', '\x5e'), ('ex', r'\__hatwide__'), ('ex', r'\__hatwider__'), | ||
('ex', r'\__hatwidest__')], | ||
r'\widetilde': [('rm', '\x7e'), ('ex', r'\__tildewide__'), | ||
('ex', r'\__tildewider__'), ('ex', r'\__tildewidest__')], | ||
} | ||
|
||
for alias, target in [(r'\leftparen', '('), | ||
(r'\rightparen', ')'), | ||
(r'\leftbrace', '{'), | ||
(r'\rightbrace', '}'), | ||
(r'\leftbracket', '['), | ||
(r'\rightbracket', ']'), | ||
(r'\{', '{'), | ||
(r'\}', '}'), | ||
(r'\[', '['), | ||
(r'\]', ']')]: | ||
for alias, target in [(r'\leftparen', '('), (r'\rightparen', 17A0 9;)'), | ||
(r'\leftbrace', '{'), (r'\rightbrace', '}'), | ||
(r'\leftbracket', '['), (r'\rightbracket', ']'), | ||
(r'\langle', '<'), (r'\rangle', '>'), | ||
(r'\{', '{'), (r'\}', '}'), | ||
(r'\[', '['), (r'\]', ']')]: | ||
_size_alternatives[alias] = _size_alternatives[target] | ||
|
||
def get_sized_alternatives_for_symbol(self, fontname: str, | ||
F428
|
@@ -1524,7 +1504,7 @@ class AutoHeightChar(Hlist): | |
""" | ||
|
||
def __init__(self, c: str, height: float, depth: float, state: ParserState, | ||
always: bool = False, factor: float | None = None): | ||
factor: float | None = None): | ||
alternatives = state.fontset.get_sized_alternatives_for_symbol( | ||
state.font, c) | ||
|
||
|
@@ -1563,7 +1543,7 @@ class AutoWidthChar(Hlist): | |
always just return a scaled version of the glyph. | ||
""" | ||
|
||
def __init__(self, c: str, width: float, state: ParserState, always: bool = False, | ||
def __init__(self, c: str, width: float, state: ParserState, | ||
char_class: type[Char] = Char): | ||
alternatives = state.fontset.get_sized_alternatives_for_symbol( | ||
state.font, c) | ||
|
@@ -2712,7 +2692,7 @@ def sqrt(self, toks: ParseResults) -> T.Any: | |
# the height so it doesn't seem cramped | ||
height = body.height - body.shift_amount + thickness * 5.0 | ||
depth = body.depth + body.shift_amount | ||
check = AutoHeightChar(r'\__sqrt__', height, depth, state, always=True) | ||
check = AutoHeightChar(r'\__sqrt__', height, depth, state) | ||
height = check.height - check.shift_amount | ||
depth = check.depth + check.shift_amount | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-157 Bytes
(99%)
lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_37.pdf
Binary file not shown.
Binary file modified
BIN
-4.57 KB
(33%)
lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_37.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor typo two lines above, while you're at it: it's AutoHeightChar, not AutoSizedChar.