comparison toolboxes/graph_visualisation/share/graphviz/doc/fontfaq.txt @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 Graphviz and fonts.
2 ===================
3
4 Before we launch into the gory details, we would like to explain
5 why this is a hard problem. The naming and rendering of text fonts
6 in Graphviz (and other programs) is complicated. There are several reasons:
7
8 - Graphviz runs on a wide range of systems: Linux and other Unix
9 variants, Microsoft Windows, and Mac.
10 - Graphviz has a wide range of output formats: raster-oriented formats
11 like PNG and GIF; path-based ones like Postscript, PDF and SVG; some
12 idiosyncractic legacy formats, like troff PIC and HPGL.
13 - Often, output will be downloaded and displayed on a computer or other
14 device, different than the one where the layout was created.
15 - Graphviz layouts should be identical in size and appearance,
16 regardless of the output format.
17 - Graphviz can run on external libraries that help with naming and
18 rendering text fonts, but they are not required, and stripped-down
19 Graphviz tools can be built without them. In fact, Graphviz may have
20 to run on systems with no font files installed.
21 - There are several major font file formats to be supported.
22 - Non-Western, international character sets should be supported.
23 - Graphviz should provide a good set of standard fonts.
24 - It should be easy to specify standard fonts.
25 - Users should be able to load their own custom fonts.
26 - Output should be small to download quickly.
27 - Output should allow the best rendering possible in a given format.
28 - Output files should be easy to postprocess, for example, retaining
29 the objects of the original graph if possible.
30 - It is very helpful to work around known bugs or missing features
31 in support libraries and popular external tools.
32
33 This is a tall order. Some of the goals conflict. Generally our
34 approach has been to define defaults that favor convenience and good
35 looking output, and give the user options to override the defaults.
36
37 ===Overview===
38
39 In the following, we will assume a ''standard'' version of Graphviz
40 with the full set of support libraries (fontconfig, gd, Cairo and Pango),
41 running on a desktop system or server with a standard installation of
42 font files.
43
44 The graphviz layout engines (dot, neato, etc) create layouts with nodes
45 sized to enclose the text labels. This requires knowing the size of
46 the text blocks, which in turn requires knowing the metrics of the font
47 glyphs and their composition into words, taking into account wordspacing,
48 kerning, hinting, etc. So the overall process is: font specification,
49 then text layout, followed by Graphviz output (and final rendering on
50 the target display or device, which may or may not be by a Graphviz tool.)
51
52
53 A font is usually selected by family name ("fontname") and other properties
54 (see below: "Font selection"). Then fontconfig matches the request
55 to a system font. [Note: in older versions of Graphviz, fontname was
56 simply a file name. This required exact file name matching (with a little
57 bit of helpful name mangling under the hood, e.g. translating Times-Roman
58 to Times, or Helvetica to Arial on Windows systems (and yes we know
59 there is a difference). Under fontconfig, fontnames are family names,
60 which fontconfig matches to the closest font it finds. This always
61 "succeeds", but unfortunately produces surprising results if fontconfig's
62 idea of "close" doesn't match yours. This can happen when you specify
63 a custom (or just nonexistent) font, like Steve-North-Handwriting,
64 and fontconfig silently falls back to something safe like a typewriter
65 font.]
66
67 Text layout is performed by pango, which accepts text and computes a
68 layout with metrics that determine node sizes.
69
70 Though line drawing is provided by cairo for many output formats (and
71 likely more in the future), for raster output formats, font rendering
72 is passed though cairo to freetype. Freetype is also called if gd is
73 used for drawing. (gd can also be requested explicitly, e.g. dot -Tpng:gd,
74 or by default when Graphviz is built without cairo). Freetype provides
75 antialiasing, hinting, kerning, and other low-level font features.
76
77 Font metrics are obtained from the fonts installed on the system running
78 Graphviz. Results are guaranteed when Graphviz outputs raster formats,
79 because freetype immediately renders the fonts into pixels. On the
80 other hand, with path-based formats like Postscript (-Tps) and SVG (-Tsvg),
81 final rendering may be done on a different platform altogether, with
82 different font files installed. Clearly, Your Milage May Vary. In the
83 case of Postscript, the driver in Graphviz passes the expected metrics
84 of the text block down to the renderer, and asks it to make a final stretch
85 (or squeeze) to force the text to fit the metrics that were in effect at
86 layout time. In Graphviz SVG, there is only a hope and a prayer that
87 the SVG rendering program's fonts match the ones fontconfig and freetype
88 used when Graphviz was run. (More about this later.)
89
90 Default fonts and PostScript fonts. ===================================
91
92 The default font in graphviz is, and always has been, Times-Roman.
93
94 Graphviz has historically supported some ``standard'' Postscript
95 fonts, initially, Times-Roman, Helvetica, Courier and Symbol.
96 This list was later enlarged by Adobe to include 35 fonts, which are:
97 AvantGarde-Book AvantGarde-BookOblique AvantGarde-Demi
98 AvantGarde-DemiOblique Bookman-Demi Bookman-DemiItalic
99 Bookman-Light Bookman-LightItalic Courier Courier-Bold
100 Courier-BoldOblique Courier-Oblique Helvetica
101 Helvetica-Bold Helvetica-BoldOblique Helvetica-Narrow
102 Helvetica-Narrow-Bold Helvetica-Narrow-BoldOblique
103 Helvetica-Narrow-Oblique Helvetica-Oblique NewCenturySchlbk-Bold
104 NewCenturySchlbk-BoldItalic NewCenturySchlbk-Italic
105 NewCenturySchlbk-Roman Palatino-Bold Palatino-BoldItalic
106 Palatino-Italic Palatino-Roman Symbol Times-Bold Times-BoldItalic
107 Times-Italic Times-Roman ZapfChancery-MediumItalic ZapfDingbats
108
109 Unfortunately, fontconfig doesn't recognize PostScript-style font
110 names directly, so Graphviz makes custom mappings from its list of
111 PostScipt names into fontconfig family names for use in all cairo
112 and gd based renderers. In -Tps output, these fonts are used without
113 name translation.
114
115 Font selection. ===============
116
117 The fontname attribute in .dot graphs is a fontconfig style specification.
118 From: http://www.fontconfig.org/fontconfig-user.html
119
120 Fontconfig provides a textual representation for patterns that
121 the library can both accept and generate. The representation is
122 in three parts, first a family name list, second list of point sizes,
123 and finally a list of additional properties:
124
125 <families>-<point sizes>:<name1>=<values1>:<name2>=<values2>...
126
127 Values in a list are separated with commas. The name needn't
128 include either a family or point size; they can be elided. In
129 addition, there are symbolic constants that simultaneously
130 indicate both a name and a value. Here are some examples:
131
132 Name Meaning
133 ----------------------------------------------------------
134 Times-12 12 point Times Roman
135 Times-12:bold 12 point Times Bold
136 Courier:italic Courier Italic in the default size
137 Monospace:matrix=1 .1 0 The users preferred monospace font
138 with artificial obliquing
139
140 Graphviz currently has a seperate attribute for specififying fontsize.
141
142 [ FIXME
143 We should allow the fontconfig style specification. "Times-20" does
144 not currently result in a 20pt font.
145
146 This is probably because of special treatment of '-' for postscript
147 font names.
148 ]
149
150 [ FIXME
151 We seem to have a bug with use of ':' in fontnames, probably because
152 of special treatment for filenames in Windows.
153
154 In fontnames, use <space> instead of ':' to separate values.
155
156 -Nfontname="Courier:italic" doesn't produce an italic font in
157 graphviz-2.16.1, but: -Nfontname="Courier italic" works, but
158 -Nfontname="Monospace matrix=1 .1 0 1" doesn't.
159 ]
160
161
162 Font management with fontconfig. ================================
163
164 How can I tell what fonts are available?
165 $ fc-list
166
167 How can I tell what fonts dot is using;
168 $ dot foo.dot -Tpng -o foo.png -v 2>&1 | grep font
169
170 How can I add a custom font?
171 In the current version of Graphviz with fontconfig, Cairo and
172 Pango, this cannot be done by simply putting a file in the
173 current directory or setting the DOTFONTPATH path variable.
174 Your custom font must be explicitly installed by fontconfig tools.
175
176 For a single font, e.g., foo.ttf:
177 $ mkdir -p ~/.fonts
178 $ cp foo.ttf ~/.fonts/
179
180 One can run fc-cache to speed up the use of fontconfig.
181 $ fc-cache
182
183 For Windows users, one can go to the C:\windows\fonts
184 folder and use File -> Install New Font from the pull-down menus
185 to install the font.
186
187 For a new font directory, e.g., /Library/Fonts, add a new <dir> element
188
189 <dir>/Library/Fonts</dir>
190
191 to a .conf file. Note that the file must have a correct xml structure
192 as specified by the fontconfig fonts.dtd. Possible choices for the
193 .conf file are local.conf in the same directory as the system-wide
194 fonts.conf file, or .fonts.conf in your home directory.
195
196 How can I ... font?
197 See: http://www.fontconfig.org/fontconfig-user.html
198
199 Can I specifiy a font by filename instead of by familyname?
200 Sorry, the answer is no. {The reason is that for this to
201 work, Graphviz has to intercept the font lookup before
202 fontconfig is called, and this can't be done when fonts
203 are being looked up by Pango.)
204
205 Some versions of fontconfig appear to recognize pathnames and
206 attempt to use that, but this isn't always the case.
207
208 How can I be sure that a specific font is selected?
209 Provide enough specification in the fontname, and test it
210 with fc-match to ensure that your desired font is selected.
211 (Note, this will not ensure that the same font is used in -Tps
212 or -Tsvg renderings where we rely on the fonts available on the
213 final printer or computer.)
214
215 Note the downside, as mentioned previously, is that Graphviz cannot
216 do much to warn you when fontconfig didn't find a very
217 good match, because fontconfig just cheerfully falls back
218 to some standard font. It would be really nice if the
219 fontconfig developers could provide a metric reflecting the
220 quality of the font match in their API.
221
222 What about SVG fonts?
223 Graphviz has a native SVG driver that we wrote (which is the
224 default), and cairo's SVG driver (which you get with -Tsvg:cairo).
225
226 Graphviz' native SVG driver generates Windows compliant names
227 like "Times New Roman" or Arial by default. The names work in a
228 lot of situations (like Firefox running on Windows), but are
229 not guaranteed to be portable. If you set -Gfontnames=ps,
230 you get Postscript names like Times-Roman. If you set -Gfontnames=svg
231 you are guaranteed to get rock solid standards compliant SVG.
232 The SVG standard says that the legal generic font names
233 are Serif, Sans-Serif, and Monospace (plus Cursive and
234 Fantasy which we don't use in Graphviz). We generate those names.
235 The bad news is that various downstream renderers and editors
236 may resolve the generic font names differently, so it's not
237 quite clear how your SVG will look. Many W3C examples show
238 how to use CSS (Cascading Style Sheets) to get around this
239 problem by giving a list of font family names in order of
240 lookup precedence, but some downstream processors (like the
241 inkscape editor in Linux) don't implement CSS, so we're up a tree here.
242
243 The cairo SVG driver solves this in an effective though brute
244 force way: it simply encodes embeds the needed fonts as lines and
245 curves in the target SVG. For small examples, -Tsvg:cairo is
246 about 10 times bigger than -Tsvg, but maybe it's worth it for
247 correctness. The other problem is that such SVG is much much
248 slower to render, no doubt because it bypasses any system
249 font rendering services, and does it the old fashioned way.
250
251 What about Postscript fonts?
252
253 say something here. What about non-ASCII like Latin1.
254 what about loading your own fonts via -L like in the old
255 days with the weird outline font example.
256
257 ==="What if" issues for nonstandard Graphviz builds===
258 The following only apply if you build your own version of Graphviz
259 by configuring and compiling the source code to build your own
260 custom executable. If you don't know what this means, it
261 definitely does not mean you.
262
263 No freetype. ============
264
265 When graphviz is built on systems without freetype, then only the gd
266 renderer will be available for bitmap outputs, and the only available
267 fonts are a small set of builtin bitmap fonts. The poor quality of
268 these fonts will be evident, also, "dot ... -v 2>&1 | grep font" will
269 say that the font is "<internal>". This may actually be desirable
270 for installing minimal graphviz programs on a server where fonts
271 may not even be installed.
272
273
274 No fontconfig. ==============
275
276 If graphviz is built on systems without fontconfig (e.g. Redhat-7) then
277 the fontname attribute will be interpreted as a font file name. The
278 system directories will be searched for this, or the directories can
279 be specified with the GDFONTPATH environment variable (or DOTFONTPATH
280 for historical reasons). Graphviz will use gd and freetype to obtain
281 metrics and render text. No pango/cairo renderers will be available
282 without fontconfig support.
283
284
285 Disabling fontconfig. =====================
286
287 Pango/cairo depends on fontconfig, so to disable fontconfig you also have
288 to disable pango/cairo. The easiest way to do this temporarily is to
289 edit /usr/lib/graphviz/config and remove the entire "libpango" block.
290 [Note that any changes to this file will be lost the next time graphviz
291 is updated, or "dot -c" is run with installer priviledges.]
292
293 With pango disabled, graphviz will use gd which, even if it was built with
294 fontconfig support, will still allow fontnames to be given as filenames.
295
296 You can also disable cairopango at build time with configure script options.
297
298
299 No gd. =====
300
301 Cairopango works without gd. We are moving graphviz to the pango/cairo
302 libraries, but gd still offers some features that are hard to replace,
303 such as JPEGs, GIFs and paletted color bitmap outputs. However, font support
304 is fully functional without gd so long as pango, cairo, fontconfig,
305 freetype are available.
306
307 No pango/cairo. ===============
308
309 Without pango/cairo, some of the key renderers are only available
310 with gd, which produces lower quality (but smaller) output.
311
312 Looking forward, we expect to depend more on pango for things like:
313 line wrapping, multiple fonts per label, bidirectional text and
314 other internationalization features.
315
316 No gd and no cairopango =====
317 This is basically the original Graphviz without any external fonts.
318 It cannot render any raster formats, so it's mainly good for Postscript.
319 It relies on a few internal font tables