Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7d600f

Browse files
committed
Further development of dviread. It now attempts to read virtual fonts,
but the positioning is still somewhat off. svn path=/trunk/matplotlib/; revision=3834
1 parent 889a360 commit c7d600f

2 files changed

Lines changed: 217 additions & 49 deletions

File tree

lib/matplotlib/backends/backend_pdf.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ def _write_afm_font(self, filename):
491491
return fontdictObject
492492

493493
def embedType1(self, filename, fontinfo):
494+
# TODO: font effects such as SlantFont
494495
fh = open(filename, 'rb')
495496
matplotlib.verbose.report(
496497
'Embedding Type 1 font ' + filename, 'debug')
@@ -520,8 +521,15 @@ def embedType1(self, filename, fontinfo):
520521

521522
if fontinfo.encodingfile is not None:
522523
enc = dviread.Encoding(fontinfo.encodingfile)
523-
widths = [ afmdata.get_width_from_char_name(ch)
524-
for ch in enc ]
524+
widths = []
525+
for ch in enc:
526+
try:
527+
widths.append(afmdata.get_width_from_char_name(ch))
528+
except KeyError:
529+
matplotlib.verbose.report(
530+
'No width for %s in %s' % (ch, fullname), 'debug')
531+
widths.append(0)
532+
525533
differencesArray = [ Name(ch) for ch in enc ]
526534
differencesArray = [ 0 ] + differencesArray
527535
firstchar = 0
@@ -538,11 +546,24 @@ def embedType1(self, filename, fontinfo):
538546
firstchar = not_None.next()
539547
lastchar = max(not_None)
540548
widths = widths[firstchar:lastchar+1]
549+
for i,w in enumerate(widths):
550+
if w is None: widths[i] = 0
541551

542-
differencesArray = [ firstchar ]
552+
differencesArray = [ ]
553+
need_idx = True
543554
for ch in range(firstchar, lastchar+1):
544-
differencesArray.append(Name(
545-
afmdata.get_name_char(ch, isord=True)))
555+
try:
556+
name = afmdata.get_name_char(ch, isord=True)
557+
if need_idx:
558+
differencesArray.append(ch)
559+
need_idx = False
560+
differencesArray.append(Name(name))
561+
except KeyError:
562+
matplotlib.verbose.report(
563+
'No name for glyph %d in %s' % (ch, fullname),
564+
'debug')
565+
need_idx = True
566+
546567

547568
fontdict = {
548569
'Type': Name('Font'),
@@ -1448,17 +1469,16 @@ def mytrans(x1, y1, x=x, y=y, a=angle / 180.0 * pi):
14481469

14491470
# Gather font information and do some setup for combining
14501471
# characters into strings.
1451-
oldfontnum, seq = None, []
1452-
for x1, y1, fontnum, glyph, width in page.text:
1453-
if fontnum != oldfontnum:
1454-
texname, fontsize = dvi.fontinfo(fontnum)
1455-
fontinfo = self.tex_font_mapping(texname)
1472+
oldfont, seq = None, []
1473+
for x1, y1, dvifont, glyph, width in page.text:
1474+
if dvifont != oldfont:
1475+
fontinfo = self.tex_font_mapping(dvifont.texname)
14561476
pdfname = self.file.fontName(fontinfo.filename)
14571477
self.file.fontInfo[pdfname] = Bunch(
14581478
encodingfile=fontinfo.encoding,
14591479
afmfile=fontinfo.afm)
1460-
seq += [['font', pdfname, fontsize]]
1461-
oldfontnum = fontnum
1480+
seq += [['font', pdfname, dvifont.size]]
1481+
oldfont = dvifont
14621482
seq += [['text', x1, y1, [chr(glyph)], x1+width]]
14631483
seq += [('end',)]
14641484

0 commit comments

Comments
 (0)