10000 Committed Nicolas Grilly's pdf patch. -JKS · matplotlib/matplotlib@d750c95 · GitHub
[go: up one dir, main page]

Skip to content

Commit d750c95

Browse files
committed
Committed Nicolas Grilly's pdf patch. -JKS
svn path=/trunk/matplotlib/; revision=3027
1 parent cf29210 commit d750c95

21 files changed

+24012
-312
lines changed

CHANGELOG

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
2007-02-21 Applied the PDF backend patch by Nicolas Grilly.
2+
This impacts several files and directories in matplotlib:
3+
4+
- Created the directory lib/matplotlib/mpl-data/fonts/pdfcorefonts,
5+
holding AFM files for the 14 PDF core fonts. These fonts are
6+
embedded in every PDF viewing application.
7+
8+
- setup.py: Added the directory pdfcorefonts to package_data.
9+
10+
- lib/matplotlib/__init__.py: Added the default parameter
11+
'pdf.use14corefonts'. When True, the PDF backend uses
12+
only the 14 PDF core fonts.
13+
14+
- lib/matplotlib/afm.py: Added some keywords found in
15+
recent AFM files. Added a little workaround to handle
16+
Euro symbol.
17+
18+
- lib/matplotlib/fontmanager.py: Added support for the 14
19+
PDF core fonts. These fonts have a dedicated cache (file
20+
pdfcorefont.cache), not the same as for other AFM files
21+
(file .afmfont.cache). Also cleaned comments to conform
22+
to CODING_GUIDE.
23+
24+
- lib/matplotlib/backends/backend_pdf.py:
25+
Added support for 14 PDF core fonts.
26+
Fixed some issues with incorrect character widths and
27+
encodings (works only for the most common encoding,
28+
WinAnsiEncoding, defined by the official PDF Reference).
29+
Removed parameter 'dpi' because it causes alignment issues.
30+
31+
-JKS (patch by Nicolas Grilly)
32+
133
2007-02-17 Changed ft2font.get_charmap, and updated all the files where
234
get_charmap is mentioned - ES
335

lib/matplotlib/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,11 @@ def __call__(self, s):
855855
'ps.papersize' : [ 'letter', validate_ps_papersize], # Set the papersize/type
856856
'ps.useafm' : [ False, validate_bool], # Set PYTHONINSPECT
857857
'ps.usedistiller' : [ False, validate_ps_distiller], # use ghostscript or xpdf to distill ps output
858-
'ps.distiller.res' : [6000, validate_int], # dpi
859-
'pdf.compression' : [6, validate_int], # compression level from 0 to 9; 0 to disable
860-
'svg.image_inline' : [True, validate_bool], # write raster image data directly into the svg file
861-
'svg.image_noscale' : [False, validate_bool], # suppress scaling of raster data embedded in SVG
858+
'ps.distiller.res' : [6000, validate_int], # dpi
859+
'pdf.compression' : [6, validate_int], # compression level from 0 to 9; 0 to disable
860+
'pdf.use14corefonts' : [False, validate_bool], # use only the 14 PDF core fonts, embedded in every PDF viewing application
861+
'svg.image_inline' : [True, validate_bool], # write raster image data directly into the svg file
862+
'svg.image_noscale' : [False, validate_bool], # suppress scaling of raster data embedded in SVG
862863
'plugins.directory' : ['.matplotlib_plugins', str], # where plugin directory is locate
863864

864865
# mathtext settings

lib/matplotlib/afm.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ def _parse_header(fh):
8787
'XHeight': _to_float,
8888
'Ascender': _to_float,
8989
'Descender': _to_float,
90+
'StdHW': _to_float,
91+
'StdVW': _to_float,
9092
'StartCharMetrics': _to_int,
93+
'CharacterSet': _to_str,
9194
'Characters': _to_int,
9295
'Capheight': _to_int,
9396
}
@@ -111,7 +114,7 @@ def _parse_header(fh):
111114
print >>sys.stderr, 'Value error parsing header in AFM:', key, val
112115
continue
113116
except KeyError:
114-
print >>sys.stderr, 'Key error converting in AFM'
117+
print >>sys.stderr, 'Found an unknown keyword in AFM header (was %s)' % key
115118
continue
116119
if key=='StartCharMetrics': return d
117120
raise RuntimeError('Bad parse')
@@ -136,13 +139,17 @@ def _parse_char_metrics(fh):
136139
line = line.rstrip()
137140
if line.startswith('EndCharMetrics'): return d
138141
vals = line.split(';')[:4]
139-
if len(vals)!=4: raise RuntimeError('Bad char metrics line: %s'%line)
142+
if len(vals) !=4 : raise RuntimeError('Bad char metrics line: %s' % line)
140143
num = _to_int(vals[0].split()[1])
141-
if num==-1: continue
142144
wx = _to_float(vals[1].split()[1])
143145
name = vals[2].split()[1]
144146
bbox = _to_list_of_ints(vals[3][2:])
145-
d[num] = (wx, name, bbox)
147+
# Workaround: If the character name is 'Euro', give it the corresponding
148+
# character code, according to WinAnsiEncoding (see PDF Reference).
149+
if name == 'Euro':
150+
num = 128
151+
if num != -1:
152+
d[num] = (wx, name, bbox)
146153
raise RuntimeError('Bad parse')
147154

148155
def _parse_kern_pairs(fh):

0 commit comments

Comments
 (0)
0