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

Skip to content

Commit 479e1c8

Browse files
committed
Merged revisions 3896-3905 via svnmerge from
http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r3898 | jdh2358 | 2007-09-28 08:41:08 -0400 (Fri, 28 Sep 2007) | 2 lines fixed some tick accessor bugs ........ r3899 | jouni | 2007-09-28 11:50:01 -0400 (Fri, 28 Sep 2007) | 3 lines Catch UnboundLocalError in checkdep_pdftops; it is raised if no output line of pdftops -v contains the word "version". ........ r3900 | jouni | 2007-09-28 11:57:49 -0400 (Fri, 28 Sep 2007) | 2 lines More debugging output when using TeX with the pdf backend ........ r3901 | jouni | 2007-09-30 16:08:50 -0400 (Sun, 30 Sep 2007) | 3 lines use_tex in pdf backend: don't use AFM files, which are not there in some TeX distros ........ r3902 | efiring | 2007-09-30 16:32:31 -0400 (Sun, 30 Sep 2007) | 4 lines bugfix by Zack, confirmed by Gary Ruben. http://sourceforge.net/mailarchive/forum.php?thread_name=d8cf9020703071339y43354eaerbfa1a47d272e5d26%40mail.gmail.com&forum_name=matplotlib-users ........ r3903 | efiring | 2007-09-30 16:47:55 -0400 (Sun, 30 Sep 2007) | 2 lines Apply patch by Leon Barrett, tracker #1798196 ........ r3904 | efiring | 2007-10-01 03:06:43 -0400 (Mon, 01 Oct 2007) | 2 lines Fixed bug in updating dataLim when an axis is reversed ........ svn path=/branches/transforms/; revision=3906
1 parent bde568c commit 479e1c8

7 files changed

Lines changed: 76 additions & 116 deletions

File tree

CHANGELOG

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
2007-09-30 Modified update* methods of Bbox and Interval so they
2+
work with reversed axes. Prior to this, trying to
3+
set the ticks on a reversed axis failed with an
4+
uninformative error message. - EF
5+
6+
2007-09-30 Applied patches to axes3d to fix index error problem - EF
7+
18
2007-09-24 Applied Eike Welk's patch reported on mpl-dev on 2007-09-22
29
Fixes a bug with multiple plot windows in the qt backend,
310
ported the changes to backend_qt4 as well - DSD
411

5-
2007-09-21 Changed cbook.reversed to yield the same result as the
12+
2007-09-21 Changed cbook.reversed to yield the same result as the
613
python reversed builtin - DSD
714

815
2007-09-13 The usetex support in the pdf backend is more usable now,

lib/matplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def checkdep_pdftops():
270270
v = line.split()[-1]
271271
float(v)
272272
return v
273-
except (IndexError, ValueError):
273+
except (IndexError, ValueError, UnboundLocalError):
274274
return None
275275

276276
def compare_versions(a, b):

lib/matplotlib/axes3d.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,16 +510,16 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
510510
#
511511
polys = []
512512
boxes = []
513-
for rs in npy.arange(0,rows,rstride):
514-
for cs in npy.arange(0,cols,cstride):
513+
for rs in npy.arange(0,rows-1,rstride):
514+
for cs in npy.arange(0,cols-1,cstride):
515515
ps = []
516516
corners = []
517517
for a,ta in [(X,tX),(Y,tY),(Z,tZ)]:
518-
ztop = a[rs][cs:min(cols-1,cs+cstride)]
518+
ztop = a[rs][cs:min(cols,cs+cstride+1)]
519519
zleft = ta[min(cols-1,cs+cstride)][rs:min(rows,rs+rstride+1)]
520520
zbase = a[min(rows-1,rs+rstride)][cs:min(cols,cs+cstride+1):]
521521
zbase = zbase[::-1]
522-
zright = ta[cs][rs:min(rows-1,rs+rstride):]
522+
zright = ta[cs][rs:min(rows,rs+rstride+1):]
523523
zright = zright[::-1]
524524
corners.append([ztop[0],ztop[-1],zbase[0],zbase[-1]])
525525
z = npy.concatenate((ztop,zleft,zbase,zright))

lib/matplotlib/axis.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,11 @@ def set_scale(self, value, **kwargs):
530530

531531
def get_children(self):
532532
children = [self.label]
533-
children.extend(self.majorTicks)
534-
children.extend(self.minorTicks)
533+
majorticks = self.get_major_ticks()
534+
minorticks = self.get_minor_ticks()
535+
536+
children.extend(majorticks)
537+
children.extend(minorticks)
535538
return children
536539

537540
def cla(self):
@@ -654,7 +657,8 @@ def _get_offset_text(self):
654657

655658
def get_gridlines(self):
656659
'Return the grid lines as a list of Line2D instance'
657-
return silent_list('Line2D gridline', [tick.gridline for tick in self.majorTicks])
660+
ticks = self.get_major_ticks()
661+
return silent_list('Line2D gridline', [tick.gridline for tick in ticks])
658662

659663
def get_label(self):
660664
'Return the axis label as a Text instance'
@@ -670,14 +674,16 @@ def get_pickradius(self):
670674

671675
def get_ticklabels(self):
672676
'Return a list of Text instances for ticklabels'
673-
labels1 = [tick.label1 for tick in self.majorTicks if tick.label1On]
674-
labels2 = [tick.label2 for tick in self.majorTicks if tick.label2On]
677+
ticks = self.get_major_ticks()
678+
labels1 = [tick.label1 for tick in ticks if tick.label1On]
679+
labels2 = [tick.label2 for tick in ticks if tick.label2On]
675680
return silent_list('Text ticklabel', labels1+labels2)
676681

677682
def get_ticklines(self):
678683
'Return the ticklines lines as a list of Line2D instance'
679684
lines = []
680-
for tick in self.majorTicks:
685+
ticks = self.get_major_ticks()
686+
for tick in ticks:
681687
lines.append(tick.tick1line)
682688
lines.append(tick.tick2line)
683689
return silent_list('Line2D ticklines', lines)
@@ -1087,8 +1093,9 @@ def set_ticks_position(self, position):
10871093
"""
10881094
assert position == 'top' or position == 'bottom' or position == 'both' or position == 'default'
10891095

1090-
ticks = list(self.majorTicks) # a copy
1091-
ticks.extend( self.minorTicks )
1096+
1097+
ticks = list( self.get_major_ticks() ) # a copy
1098+
ticks.extend( self.get_minor_ticks() )
10921099

10931100
if position == 'top':
10941101
for t in ticks:
@@ -1287,8 +1294,8 @@ def set_ticks_position(self, position):
12871294
"""
12881295
assert position == 'left' or position == 'right' or position == 'both' or position == 'default'
12891296

1290-
ticks = list(self.majorTicks) # a copy
1291-
ticks.extend( self.minorTicks )
1297+
ticks = list( self.get_major_ticks() ) # a copy
1298+
ticks.extend( self.get_minor_ticks() )
12921299

12931300
if position == 'right':
12941301
self.set_offset_position('right')

lib/matplotlib/backends/backend_pdf.py

Lines changed: 26 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -500,70 +500,15 @@ def embedType1(self, filename, fontinfo):
500500
finally:
501501
fh.close()
502502

503-
fh = open(fontinfo.afmfile, 'rb')
504-
matplotlib.verbose.report(
505-
'Reading metrics from ' + fontinfo.afmfile, 'debug')
506-
try:
507-
afmdata = AFM(fh)
508-
finally:
509-
fh.close()
510-
511503
font = FT2Font(filename)
512-
font.attach_file(fontinfo.afmfile)
513504

514505
widthsObject, fontdescObject, fontdictObject, fontfileObject = \
515506
[ self.reserveObject(n) for n in
516507
('font widths', 'font descriptor',
517508
'font dictionary', 'font file') ]
518509

519-
_, _, fullname, familyname, weight, italic_angle, fixed_pitch, \
520-
ul_position, ul_thickness = font.get_ps_font_info()
521-
522-
if fontinfo.encodingfile is not None:
523-
enc = dviread.Encoding(fontinfo.encodingfile)
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-annoying')
531-
widths.append(0)
532-
533-
differencesArray = [ Name(ch) for ch in enc ]
534-
differencesArray = [ 0 ] + differencesArray
535-
firstchar = 0
536-
lastchar = len(differencesArray) - 2
537-
else:
538-
widths = [ None for i in range(256) ]
539-
for ch in range(256):
540-
try:
541-
widths[ch] = afmdata.get_width_char(ch, isord=True)
542-
except KeyError:
543-
pass
544-
not_None = [ch for ch in range(256)
545-
if widths[ch] is not None]
546-
firstchar = not_None[0]
547-
lastchar = not_None[-1]
548-
widths = widths[firstchar:lastchar+1]
549-
for i,w in enumerate(widths):
550-
if w is None: widths[i] = 0
551-
552-
differencesArray = [ ]
553-
need_idx = True
554-
for ch in range(firstchar, lastchar+1):
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-annoying')
565-
need_idx = True
566-
510+
firstchar = 0
511+
lastchar = len(fontinfo.widths) - 1
567512

568513
fontdict = {
569514
'Type': Name('Font'),
@@ -575,15 +520,22 @@ def embedType1(self, filename, fontinfo):
575520
'FontDescriptor': fontdescObject,
576521
}
577522

578-
fontdict.update({
579-
'Encoding': { 'Type': Name('Encoding'),
580-
'Differences': differencesArray },
581-
})
523+
if fontinfo.encodingfile is not None:
524+
enc = dviread.Encoding(fontinfo.encodingfile)
525+
differencesArray = [ Name(ch) for ch in enc ]
526+
differencesArray = [ 0 ] + differencesArray
527+
fontdict.update({
528+
'Encoding': { 'Type': Name('Encoding'),
529+
'Differences': differencesArray },
530+
})
531+
532+
_, _, fullname, familyname, weight, italic_angle, fixed_pitch, \
533+
ul_position, ul_thickness = font.get_ps_font_info()
582534

583535
flags = 0
584536
if fixed_pitch: flags |= 1 << 0 # fixed width
585537
if 0: flags |= 1 << 1 # TODO: serif
586-
if 1: flags |= 1 << 2 # TODO: symbolic
538+
if 1: flags |= 1 << 2 # TODO: symbolic (most TeX fonts are)
587539
else: flags |= 1 << 5 # non-symbolic
588540
if italic_angle: flags |= 1 << 6 # italic
589541
if 0: flags |= 1 << 16 # TODO: all caps
@@ -598,33 +550,17 @@ def embedType1(self, filename, fontinfo):
598550
'ItalicAngle': italic_angle,
599551
'Ascent': font.ascender,
600552
'Descent': font.descender,
601-
'CapHeight': 1000, # default guess if missing from AFM file
602-
'XHeight': afmdata.get_xheight(),
553+
'CapHeight': 1000, # TODO: find this out
554+
'XHeight': 500, # TODO: this one too
603555
'FontFile': fontfileObject,
604556
'FontFamily': familyname,
557+
'StemV': 50, # TODO
558+
# (see also revision 3874; but not all TeX distros have AFM files!)
605559
#'FontWeight': a number where 400 = Regular, 700 = Bold
606560
}
607-
try:
608-
descriptor['CapHeight'] = afmdata.get_capheight()
609-
except KeyError:
610-
pass
611-
612-
# StemV is obligatory in PDF font descriptors but optional in
613-
# AFM files. The collection of AFM files in my TeX Live 2007
614-
# collection has values ranging from 22 to 219, with both
615-
# median and mode 50, so if the AFM file is silent, I'm
616-
# guessing 50. -JKS
617-
StemV = afmdata.get_vertical_stem_width()
618-
if StemV is None: StemV = 50
619-
descriptor['StemV'] = StemV
620-
621-
# StemH is entirely optional:
622-
StemH = afmdata.get_horizontal_stem_width()
623-
if StemH is not None:
624-
descriptor['StemH'] = StemH
625561

626562
self.writeObject(fontdictObject, fontdict)
627-
self.writeObject(widthsObject, widths)
563+
self.writeObject(widthsObject, fontinfo.widths)
628564
self.writeObject(fontdescObject, descriptor)
629565

630566
t1font = type1font.Type1Font(filename)
@@ -1470,11 +1406,13 @@ def mytrans(x1, y1, x=x, y=y, a=angle / 180.0 * pi):
14701406
oldfont, seq = None, []
14711407
for x1, y1, dvifont, glyph, width in page.text:
14721408
if dvifont != oldfont:
1473-
fontinfo = self.tex_font_mapping(dvifont.texname)
1474-
pdfname = self.file.fontName(fontinfo.filename)
1475-
self.file.fontInfo[pdfname] = Bunch(
1476-
encodingfile=fontinfo.encoding,
1477-
afmfile=fontinfo.afm)
1409+
psfont = self.tex_font_mapping(dvifont.texname)
1410+
pdfname = self.file.fontName(psfont.filename)
1411+
if self.file.fontInfo.get(pdfname, None) is None:
1412+
self.file.fontInfo[pdfname] = Bunch(
1413+
encodingfile=psfont.encoding,
1414+
widths=dvifont.widths,
1415+
dvifont=dvifont)
14781416
seq += [['font', pdfname, dvifont.size]]
14791417
oldfont = dvifont
14801418
seq += [['text', x1, y1, [chr(glyph)], x1+width]]

lib/matplotlib/dviread.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _output(self):
8484
e = 0 # zero depth
8585
else: # glyph
8686
x,y,font,g,w = elt
87-
h = _mul2012(font._scale, font._tfm.height[g])
87+
h = _mul2012(font._scale, font._tfm.height[g])
8888
e = _mul2012(font._scale, font._tfm.depth[g])
8989
minx = min(minx, x)
9090
miny = min(miny, y - h)
@@ -380,19 +380,21 @@ def _post_post(self):
380380

381381
class DviFont(object):
382382
"""
383-
Object that holds a font's texname and size and supports comparison.
383+
Object that holds a font's texname and size, supports comparison,
384+
and knows the widths of glyphs in the same units as the AFM file.
384385
There are also internal attributes (for use by dviread.py) that
385386
are _not_ used for comparison.
386387
387388
The size is in Adobe points (converted from TeX points).
388389
"""
389-
__slots__ = ('texname', 'size', '_scale', '_vf', '_tfm')
390+
__slots__ = ('texname', 'size', 'widths', '_scale', '_vf', '_tfm')
390391

391392
def __init__(self, scale, tfm, texname, vf):
392393
self._scale, self._tfm, self.texname, self._vf = \
393394
scale, tfm, texname, vf
394-
# TODO: would it make more sense to have the size in dpi units?
395395
self.size = scale * (72.0 / (72.27 * 2**16))
396+
self.widths = [ (1000*tfm.width.get(char, 0)) >> 20
397+
for char in range(0, max(tfm.width)) ]
396398

397399
def __eq__(self, other):
398400
return self.__class__ == other.__class__ and \
@@ -402,6 +404,10 @@ def __ne__(self, other):
402404
return not self.__eq__(other)
403405

404406
def _width_of(self, char):
407+
"""
408+
Width of char in dvi units. For internal use by dviread.py.
409+
"""
410+
405411
width = self._tfm.width.get(char, None)
406412
if width is not None:
407413
return _mul2012(width, self._scale)
@@ -598,7 +604,6 @@ def __getitem__(self, texname):
598604
fn, enc = result.filename, result.encoding
599605
if fn is not None and not fn.startswith('/'):
600606
result.filename = find_tex_file(fn)
601-
result.afm = find_tex_file(fn[:-4] + '.afm')
602607
if enc is not None and not enc.startswith('/'):
603608
result.encoding = find_tex_file(result.encoding)
604609
return result
@@ -734,6 +739,9 @@ def find_tex_file(filename, format=None):
734739
result = pipe.readline().rstrip()
735740
pipe.close()
736741

742+
matplotlib.verbose.report('find_tex_file: %s -> %s' \
743+
% (filename, result),
744+
'debug')
737745
return result
738746

739747
# With multiple text objects per figure (e.g. tick labels) we may end

lib/matplotlib/widgets.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -971,23 +971,23 @@ def onselect(eclick, erelease):
971971
print ' endposition : (%f, %f)' % (erelease.xdata, erelease.ydata)
972972
print ' used button : ', eclick.button
973973
974-
def toggle_Selector(event):
974+
def toggle_selector(event):
975975
print ' Key pressed.'
976-
if event.key in ['Q', 'q'] and toggle_Selector.RS.active:
976+
if event.key in ['Q', 'q'] and toggle_selector.RS.active:
977977
print ' RectangleSelector deactivated.'
978-
toggle_Selector.RS.set_active(False)
979-
if event.key in ['A', 'a'] and not toggle_Selector.RS.active:
978+
toggle_selector.RS.set_active(False)
979+
if event.key in ['A', 'a'] and not toggle_selector.RS.active:
980980
print ' RectangleSelector activated.'
981-
toggle_Selector.RS.set_active(True)
981+
toggle_selector.RS.set_active(True)
982982
983983
x = arange(100)/(99.0)
984984
y = sin(x)
985985
fig = figure
986986
ax = subplot(111)
987987
ax.plot(x,y)
988988
989-
toggle_Selector.RS = RectangleSelector(ax, onselect, drawtype='line')
990-
connect('key_press_event', toggle_Selector)
989+
toggle_selector.RS = RectangleSelector(ax, onselect, drawtype='line')
990+
connect('key_press_event', toggle_selector)
991991
show()
992992
"""
993993
def __init__(self, ax, onselect, drawtype='box',

0 commit comments

Comments
 (0)