Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Add support for more accents in mathtext#23189
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -220,7 +220,7 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi): | ||
if bunch is not None: | ||
return bunch | ||
font, num, slanted, substituted_glyph = self._get_glyph( | ||
fontname, font_class, sym, fontsize) | ||
font.set_size(fontsize, dpi) | ||
@@ -239,7 +239,8 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi): | ||
ymax = ymax+offset, | ||
# iceberg is the equivalent of TeX's "height" | ||
iceberg = glyph.horiBearingY/64.0 + offset, | ||
slanted = slanted, | ||
substituted_glyph = substituted_glyph | ||
) | ||
result = self.glyphd[key] = types.SimpleNamespace( | ||
@@ -323,7 +324,7 @@ def _get_glyph(self, fontname, font_class, sym, fontsize): | ||
if font is not None: | ||
num = ord(sym) | ||
if font is not None and font.get_char_index(num) != 0: | ||
return font, num, slanted, False | ||
else: | ||
return self._stix_fallback._get_glyph( | ||
fontname, font_class, sym, fontsize) | ||
@@ -448,6 +449,8 @@ def _get_glyph(self, fontname, font_class, sym, fontsize): | ||
found_symbol = False | ||
_log.warning("No TeX to Unicode mapping for {!a}.".format(sym)) | ||
substituted_glyph = False | ||
fontname, uniindex = self._map_virtual_font( | ||
fontname, font_class, uniindex) | ||
@@ -499,8 +502,9 @@ def _get_glyph(self, fontname, font_class, sym, fontsize): | ||
font = self._get_font('rm') | ||
uniindex = 0xA4 # currency char, for lack of anything better | ||
slanted = False | ||
substituted_glyph = True | ||
return font, uniindex, slanted, substituted_glyph | ||
def get_sized_alternatives_for_symbol(self, fontname, sym): | ||
if self._fallback_font: | ||
@@ -935,6 +939,9 @@ def _update_metrics(self): | ||
def is_slanted(self): | ||
return self._metrics.slanted | ||
def is_substituted(self): | ||
return self._metrics.substituted_glyph | ||
def get_kerning(self, next): | ||
""" | ||
Return the amount of kerning between this and the given character. | ||
@@ -2011,7 +2018,7 @@ def unknown_symbol(self, s, loc, toks): | ||
raise ParseFatalException(s, loc, f"Unknown symbol: {toks['name']}") | ||
_accent_map = { | ||
r'hat': r'\combiningcircumflexaccent', | ||
r'breve': r'\combiningbreve', | ||
r'bar': r'\combiningoverline', | ||
r'grave': r'\combininggraveaccent', | ||
@@ -2027,10 +2034,13 @@ def unknown_symbol(self, s, loc, toks): | ||
r"'": r'\combiningacuteaccent', | ||
r'~': r'\combiningtilde', | ||
r'.': r'\combiningdotabove', | ||
r'^': r'\combiningcircumflexaccent', | ||
r'overrightarrow': r'\combiningrightarrowabove', | ||
r'overleftarrow': r'\combiningleftarrowabove', | ||
r'mathring': r'\combiningringabove', | ||
r'=': r'\combiningmacron', | ||
r'H': r'\combiningdoubleacuteaccent', | ||
r'check': r'\combiningcaron', | ||
} | ||
_wide_accents = set(r"widehat widetilde widebar".split()) | ||
@@ -2050,10 +2060,27 @@ def accent(self, s, loc, toks): | ||
accent_box = AutoWidthChar( | ||
'\\' + accent, sym.width, state, char_class=Accent) | ||
else: | ||
# Check if accent and character can be combined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. One can possibly consider splitting the accents into those that may have precomposed characters and those that may not. Possibly one should check that the character is one of the standard latin characters as well, although that may lead to that those precomposed with two accents may not work (which should be checked if they even do to start with...). | ||
a = get_unicode_index(self._accent_map[accent]) | ||
if isinstance(sym, Char): | ||
c = sym.c | ||
else: | ||
c = sym.children[0].c | ||
if c == chr(305): # Dotless i, but normal i combines | ||
c = 'i' | ||
comb = unicodedata.normalize('NFC', c + chr(a)) | ||
if len(comb) == 1: # Check that they did combine | ||
newsym = Char(comb, state) | ||
# Check that glyph exists | ||
if not newsym.is_substituted(): | ||
return newsym | ||
if c == 'i': # Turn i into dotless i | ||
sym = Char(chr(305), state) | ||
if sym.is_substituted(): | ||
# Dotless i does not exist | ||
sym = Char('i', state) | ||
# Cannot be combined | ||
accent_box = Accent(self._accent_map[accent], state) | ||
centered = HCentered([Hbox(sym.width / 4.0), accent_box]) | ||
centered.hpack(sym.width, 'exactly') | ||
return Vlist([ | ||
@@ -2137,9 +2164,6 @@ def is_slanted(self, nucleus): | ||
return nucleus.is_slanted() | ||
return False | ||
def subsuper(self, s, loc, toks): | ||
nucleus = toks.get("nucleus", Hbox(0)) | ||
subsuper = toks.get("subsuper", []) | ||
Uh oh!
There was an error while loading.Please reload this page.