Skip to content

Commit 62d4178

Browse files
committed
Fix long Unicode characters in SVG backend (fixes mathtext_stixsans test on narrow Python builds.)
svn path=/trunk/matplotlib/; revision=8986
1 parent c2ae0b7 commit 62d4178

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

lib/matplotlib/backends/backend_svg.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
603603
if rcParams['svg.embed_char_paths']:
604604
new_chars = []
605605
for c in s:
606-
path = self._add_char_def(prop, c)
606+
path = self._add_char_def(prop, ord(c))
607607
if path is not None:
608608
new_chars.append(path)
609609
if len(new_chars):
@@ -628,7 +628,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
628628
lastgind = None
629629
currx = 0
630630
for c in s:
631-
charnum = self._get_char_def_id(prop, c)
631+
charnum = self._get_char_def_id(prop, ord(c))
632632
ccode = ord(c)
633633
gind = cmap.get(ccode)
634634
if gind is None:
@@ -680,13 +680,13 @@ def _add_char_def(self, prop, char):
680680
font = prop
681681
font.set_size(self.FONT_SCALE, 72)
682682
ps_name = font.get_sfnt()[(1,0,0,6)]
683-
char_id = urllib.quote('%s-%d' % (ps_name, ord(char)))
683+
char_id = urllib.quote('%s-%d' % (ps_name, char))
684684
char_num = self._char_defs.get(char_id, None)
685685
if char_num is not None:
686686
return None
687687

688688
path_data = []
689-
glyph = font.load_char(ord(char), flags=LOAD_NO_HINTING)
689+
glyph = font.load_char(char, flags=LOAD_NO_HINTING)
690690
currx, curry = 0.0, 0.0
691691
for step in glyph.path:
692692
if step[0] == 0: # MOVE_TO
@@ -724,7 +724,7 @@ def _get_char_def_id(self, prop, char):
724724
font = prop
725725
font.set_size(self.FONT_SCALE, 72)
726726
ps_name = font.get_sfnt()[(1,0,0,6)]
727-
char_id = urllib.quote('%s-%d' % (ps_name, ord(char)))
727+
char_id = urllib.quote('%s-%d' % (ps_name, char))
728728
return self._char_defs[char_id]
729729

730730
def _draw_mathtext(self, gc, x, y, s, prop, angle):
@@ -742,8 +742,8 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
742742

743743
if rcParams['svg.embed_char_paths']:
744744
new_chars = []
745-
for font, fontsize, thetext, new_x, new_y_mtc, metrics in svg_glyphs:
746-
path = self._add_char_def(font, thetext)
745+
for font, fontsize, char, new_x, new_y_mtc, metrics in svg_glyphs:
746+
path = self._add_char_def(font, char)
747747
if path is not None:
748748
new_chars.append(path)
749749
if len(new_chars):
@@ -760,8 +760,8 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
760760
svg.append('translate(%f,%f)' % (x, y))
761761
svg.append('">\n')
762762

763-
for font, fontsize, thetext, new_x, new_y_mtc, metrics in svg_glyphs:
764-
charid = self._get_char_def_id(font, thetext)
763+
for font, fontsize, char, new_x, new_y_mtc, metrics in svg_glyphs:
764+
charid = self._get_char_def_id(font, char)
765765

766766
svg.append('<use xlink:href="#%s" transform="translate(%f,%f)scale(%f)"/>\n' %
767767
(charid, new_x, -new_y_mtc, fontsize / self.FONT_SCALE))

lib/matplotlib/mathtext.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,9 @@ def __init__(self):
329329

330330
def render_glyph(self, ox, oy, info):
331331
oy = self.height - oy + info.offset
332-
thetext = unichr_safe(info.num)
333332

334333
self.svg_glyphs.append(
335-
(info.font, info.fontsize, thetext, ox, oy, info.metrics))
334+
(info.font, info.fontsize, info.num, ox, oy, info.metrics))
336335

337336
def render_rect_filled(self, x1, y1, x2, y2):
338337
self.svg_rects.append(

0 commit comments

Comments
 (0)