Skip to content

Commit f9a68c1

Browse files
committed
Fix problems with funnily encoded fonts in PS backend.
svn path=/branches/v1_0_maint/; revision=8760
1 parent feb143a commit f9a68c1

File tree

2 files changed

+14
-78
lines changed

2 files changed

+14
-78
lines changed

lib/matplotlib/backends/backend_ps.py

+3-65
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
610610
draw a Text instance
611611
"""
612612
# local to avoid repeated attribute lookups
613-
614-
615613
write = self._pswriter.write
616614
if debugPS:
617615
write("% text\n")
@@ -622,69 +620,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
622620
elif ismath:
623621
return self.draw_mathtext(gc, x, y, s, prop, angle)
624622

625-
elif isinstance(s, unicode):
626-
return self.draw_unicode(gc, x, y, s, prop, angle)
627-
628623
elif rcParams['ps.useafm']:
629-
font = self._get_font_afm(prop)
630-
631-
l,b,w,h = font.get_str_bbox(s)
632-
633-
fontsize = prop.get_size_in_points()
634-
l *= 0.001*fontsize
635-
b *= 0.001*fontsize
636-
w *= 0.001*fontsize
637-
h *= 0.001*fontsize
638-
639-
if angle==90: l,b = -b, l # todo generalize for arb rotations
640-
641-
pos = _nums_to_str(x-l, y-b)
642-
thetext = '(%s)' % s
643-
fontname = font.get_fontname()
644-
fontsize = prop.get_size_in_points()
645-
rotate = '%1.1f rotate' % angle
646-
setcolor = '%1.3f %1.3f %1.3f setrgbcolor' % gc.get_rgb()[:3]
647-
#h = 0
648-
ps = """\
649-
gsave
650-
/%(fontname)s findfont
651-
%(fontsize)s scalefont
652-
setfont
653-
%(pos)s moveto
654-
%(rotate)s
655-
%(thetext)s
656-
%(setcolor)s
657-
show
658-
grestore
659-
""" % locals()
660-
self._draw_ps(ps, gc, None)
661-
662-
else:
663-
font = self._get_font_ttf(prop)
664-
font.set_text(s, 0, flags=LOAD_NO_HINTING)
665-
self.track_characters(font, s)
666-
667-
self.set_color(*gc.get_rgb())
668-
self.set_font(font.get_sfnt()[(1,0,0,6)], prop.get_size_in_points())
669-
write("%s m\n"%_nums_to_str(x,y))
670-
if angle:
671-
write("gsave\n")
672-
write("%s rotate\n"%_num_to_str(angle))
673-
descent = font.get_descent() / 64.0
674-
if descent:
675-
write("0 %s rmoveto\n"%_num_to_str(descent))
676-
write("(%s) show\n"%quote_ps_string(s))
677-
if angle:
678-
write("grestore\n")
679-
680-
def new_gc(self):
681-
return GraphicsContextPS()
682-
683-
def draw_unicode(self, gc, x, y, s, prop, angle):
684-
"""draw a unicode string. ps doesn't have unicode support, so
685-
we have to do this the hard way
686-
"""
687-
if rcParams['ps.useafm']:
688624
self.set_color(*gc.get_rgb())
689625

690626
font = self._get_font_afm(prop)
@@ -772,6 +708,9 @@ def draw_unicode(self, gc, x, y, s, prop, angle):
772708
""" % locals()
773709
self._pswriter.write(ps)
774710

711+
def new_gc(self):
712+
return GraphicsContextPS()
713+
775714
def draw_mathtext(self, gc,
776715
x, y, s, prop, angle):
777716
"""
@@ -1125,7 +1064,6 @@ def write(self, *kl, **kwargs):
11251064
if is_opentype_cff_font(font_filename):
11261065
raise RuntimeError("OpenType CFF fonts can not be saved using the internal Postscript backend at this time.\nConsider using the Cairo backend.")
11271066
else:
1128-
fonttype = rcParams['ps.fonttype']
11291067
convert_ttf_to_ps(font_filename, fh, fonttype, glyph_ids)
11301068
print >>fh, "end"
11311069
print >>fh, "%%EndProlog"

ttconv/pprdrv_tt.cpp

+11-13
Original file line numberDiff line numberDiff line change
@@ -420,21 +420,19 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
420420
-------------------------------------------------------------*/
421421
void ttfont_encoding(TTStreamWriter& stream, struct TTFONT *font, std::vector<int>& glyph_ids, font_type_enum target_type)
422422
{
423-
stream.putline("/Encoding StandardEncoding def");
423+
if (target_type == PS_TYPE_3) {
424+
stream.printf("/Encoding [ ");
424425

425-
// if (target_type == PS_TYPE_3) {
426-
// stream.printf("/Encoding [ ");
427-
428-
// for (std::vector<int>::const_iterator i = glyph_ids.begin();
429-
// i != glyph_ids.end(); ++i) {
430-
// const char* name = ttfont_CharStrings_getname(font, *i);
431-
// stream.printf("/%s ", name);
432-
// }
426+
for (std::vector<int>::const_iterator i = glyph_ids.begin();
427+
i != glyph_ids.end(); ++i) {
428+
const char* name = ttfont_CharStrings_getname(font, *i);
429+
stream.printf("/%s ", name);
430+
}
433431

434-
// stream.printf("] def\n");
435-
// } else {
436-
// stream.putline("/Encoding StandardEncoding def");
437-
// }
432+
stream.printf("] def\n");
433+
} else {
434+
stream.putline("/Encoding StandardEncoding def");
435+
}
438436
} /* end of ttfont_encoding() */
439437

440438
/*-----------------------------------------------------------

0 commit comments

Comments
 (0)