Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fixed bug 6028 #6073

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

Merged
merged 4 commits into from
Mar 6, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fixed bug 6028
  • Loading branch information
crazyo committed Feb 29, 2016
commit ad8533ce95ed6ffefaf95b64f47c4aa1d2768d47
41 changes: 23 additions & 18 deletions 41 lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,21 @@
##############################################################################
# FONTS

def get_unicode_index(symbol):
"""get_unicode_index(symbol) -> integer
def get_unicode_index(symbol, nonMath=False):
"""get_unicode_index(symbol, [bool]) -> integer

Return the integer index (from the Unicode table) of symbol. *symbol*
can be a single unicode character, a TeX command (i.e. r'\pi'), or a
Type1 symbol name (i.e. 'phi').
If nonMath is True, the current symbol should be treated as a non-math symbol.
"""
# From UTF #25: U+2212 minus sign is the preferred
# representation of the unary and binary minus sign rather than
# the ASCII-derived U+002D hyphen-minus, because minus sign is
# unambiguous and because it is rendered with a more desirable
# length, usually longer than a hyphen.
if symbol == '-':
# Hyphens in texts will not be affected.
if not nonMath and symbol == '-':
return 0x2212
try:# This will succeed if symbol is a single unicode char
return ord(symbol)
Expand Down Expand Up @@ -438,7 +440,7 @@ def get_kern(self, font1, fontclass1, sym1, fontsize1,
"""
return 0.

def get_metrics(self, font, font_class, sym, fontsize, dpi):
def get_metrics(self, font, font_class, sym, fontsize, dpi, nonMath=False):
"""
*font*: one of the TeX font names::

Expand All @@ -452,6 +454,8 @@ def get_metrics(self, font, font_class, sym, fontsize, dpi):

*dpi*: current dots-per-inch

*nonMath*: whether sym is a nonMath character

Returns an object with the following attributes:

- *advance*: The advance distance (in points) of the glyph.
Expand All @@ -466,7 +470,7 @@ def get_metrics(self, font, font_class, sym, fontsize, dpi):
the glyph. This corresponds to TeX's definition of
"height".
"""
info = self._get_info(font, font_class, sym, fontsize, dpi)
info = self._get_info(font, font_class, sym, fontsize, dpi, nonMath)
return info.metrics

def set_canvas_size(self, w, h, d):
Expand Down Expand Up @@ -582,14 +586,14 @@ def _get_offset(self, font, glyph, fontsize, dpi):
return ((glyph.height/64.0/2.0) + (fontsize/3.0 * dpi/72.0))
return 0.

def _get_info(self, fontname, font_class, sym, fontsize, dpi):
def _get_info(self, fontname, font_class, sym, fontsize, dpi, nonMath=False):
key = fontname, font_class, sym, fontsize, dpi
bunch = self.glyphd.get(key)
if bunch is not None:
return bunch

font, num, symbol_name, fontsize, slanted = \
self._get_glyph(fontname, font_class, sym, fontsize)
self._get_glyph(fontname, font_class, sym, fontsize, nonMath)

font.set_size(fontsize, dpi)
glyph = font.load_char(
Expand Down Expand Up @@ -679,7 +683,7 @@ def __init__(self, *args, **kwargs):

_slanted_symbols = set(r"\int \oint".split())

def _get_glyph(self, fontname, font_class, sym, fontsize):
def _get_glyph(self, fontname, font_class, sym, fontsize, nonMath=False):
symbol_name = None
font = None
if fontname in self.fontmap and sym in latex_to_bakoma:
Expand All @@ -699,7 +703,7 @@ def _get_glyph(self, fontname, font_class, sym, fontsize):

if symbol_name is None:
return self._stix_fallback._get_glyph(
fontname, font_class, sym, fontsize)
fontname, font_class, sym, fontsize, nonMath)

return font, num, symbol_name, fontsize, slanted

Expand Down Expand Up @@ -796,7 +800,7 @@ def __init__(self, *args, **kwargs):
def _map_virtual_font(self, fontname, font_class, uniindex):
return fontname, uniindex

def _get_glyph(self, fontname, font_class, sym, fontsize):
def _get_glyph(self, fontname, font_class, sym, fontsize, nonMath=False):
found_symbol = False

if self.use_cmex:
Expand All @@ -807,7 +811,7 @@ def _get_glyph(self, fontname, font_class, sym, fontsize):

if not found_symbol:
try:
uniindex = get_unicode_index(sym)
uniindex = get_unicode_index(sym, nonMath)
found_symbol = True
except ValueError:
uniindex = ord('?')
Expand Down Expand Up @@ -900,11 +904,11 @@ def __init__(self, *args, **kwargs):
self.fontmap[key] = fullpath
self.fontmap[name] = fullpath

def _get_glyph(self, fontname, font_class, sym, fontsize):
def _get_glyph(self, fontname, font_class, sym, fontsize, nonMath=False):
""" Override prime symbol to use Bakoma """
if sym == r'\prime':
return self.bakoma._get_glyph(fontname,
font_class, sym, fontsize)
font_class, sym, fontsize, nonMath)
else:
# check whether the glyph is available in the display font
uniindex = get_unicode_index(sym)
Expand All @@ -913,10 +917,10 @@ def _get_glyph(self, fontname, font_class, sym, fontsize):
glyphindex = font.get_char_index(uniindex)
if glyphindex != 0:
return super(DejaVuFonts, self)._get_glyph('ex',
font_class, sym, fontsize)
font_class, sym, fontsize, nonMath)
# otherwise return regular glyph
return super(DejaVuFonts, self)._get_glyph(fontname,
font_class, sym, fontsize)
font_class, sym, fontsize, nonMath)


class DejaVuSerifFonts(DejaVuFonts):
Expand Down Expand Up @@ -1450,14 +1454,15 @@ class Char(Node):
from width) must be converted into a :class:`Kern` node when the
:class:`Char` is added to its parent :class:`Hlist`.
"""
def __init__(self, c, state):
def __init__(self, c, state, nonMath=False):
Node.__init__(self)
self.c = c
self.font_output = state.font_output
self.font = state.font
self.font_class = state.font_class
self.fontsize = state.fontsize
self.dpi = state.dpi
self.nonMath = nonMath
# The real width, height and depth will be set during the
# pack phase, after we know the real fontsize
self._update_metrics()
Expand All @@ -1467,7 +1472,7 @@ def __internal_repr__(self):

def _update_metrics(self):
metrics = self._metrics = self.font_output.get_metrics(
self.font, self.font_class, self.c, self.fontsize, self.dpi)
self.font, self.font_class, self.c, self.fontsize, self.dpi, self.nonMath)
if self.c == ' ':
self.width = metrics.advance
else:
Expand Down Expand Up @@ -2589,7 +2594,7 @@ def math(self, s, loc, toks):
def non_math(self, s, loc, toks):
#~ print "non_math", toks
s = toks[0].replace(r'\$', '$')
symbols = [Char(c, self.get_state()) for c in s]
symbols = [Char(c, self.get_state(), nonMath=True) for c in s]
hlist = Hlist(symbols)
# We're going into math now, so set font to 'it'
self.push_state()
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.