Synopsis
Loads a font file from disk for use with any ChIPS text element.
Syntax
load_font(name, fontfile, style=chips_normal)
Description
The function arguments.
Argument | Description |
---|---|
name | The name used to identify the font in ChIPS. |
fontfile | The location of the file containing the font data; supported formats are .pfa, .pfb, or .ttf. |
style | The font style for the file. The values are chips_normal (default), chips_bold, chips_italic, and chips_bolditalic. |
The load_font command allows the user to load their own font files for formatting labels. Support is provided for .pfa, .pfb and .ttf format font files. This command is part of the advanced ChIPS module; refer to "ahelp chips" for information. To load the module:
from pychips.advanced import *
The user specifies a name to be used when accessing the font; the same name may be used for each of the four supported font styles (normal, bold, italic, and bolditalic). If the same name is used for the same font style more than once, the earlier entry is overwritten. The following font names are predefined and may not be used: courier, greek, times, and helvetica.
If the "style" is not specified, the font is loaded as normal font style. If all supported font styles are not loaded, the following fallbacks are utilized:
- if bold is not loaded, use normal font.
- if italic is not loaded, use normal font.
- if bolditalic is not loaded, try italic, then bold, then normal font.
If the font cannot be accessed at all, e.g. it is not loaded or the name is misspelled, Helvetica is used.
Currently, user-loaded fonts are only supported for the on-screen display. They cannot be used in hardcopy output formats. The fallback when creating hardcopies is:
- If the user adds a label and sets the user-loaded font at creation time, the hardcopy uses Helvetica.
- If the font is set after the label is created, however, the hardcopy uses the last system-recognized font.
For instance, after:
chips> load_font("batang", "/usr/share/fonts/ko/TrueType/batang.ttf") chips> add_label(0.4, 0.4, "Hello World!", "font=batang") chips> print_window("example1.ps")
and
chips> load_font("batang", "/usr/share/fonts/ko/TrueType/batang.ttf") chips> add_label(0.4, 0.4, "Hello World!", "font=greek") chips> set_label("font=batang") chips> print_window("example2.ps")
The label in example1.ps will be printed in Helvetica, since the font was set in the add_label command. The label in example2.ps will use greek, the most recent system font used before the print_window command.
Examples
Example 1
chips> add_label(0.4, 0.4, 'Hello World!') chips> load_font('batang','/usr/share/fonts/ko/TrueType/batang.ttf') chips> set_label(["font", "batang"])
Add a label. Load the true type font "batang.ttf" as a normal font style; set the label to use that font.
Example 2
chips> load_font('gothic', '/data/fonts/gothic.pfb') chips> load_font('gothic', '/data/fonts/gothic_i.pfb', chips_italic) chips> load_font('gothic', '/data/fonts/gothic_b.pfb', chips_bold) chips> load_font('gothic', '/data/fonts/gothic_bi.pfb', chips_bolditalic)
Load the gothic font files for the four supported font styles.
OS-X support for True Type fonts
True Type fonts are not supported in the vector output formats (i.e. EPS, PS, and PDF) for OS-X systems (they are on Linux). The fonts will be included in bitmap outputs (i.e. PNG and JPEG). The fonts supplied with ChIPS are not in True Type format, and so this only affects fonts loaded with the load_font function from the pychips.advanced module.
Bugs
PDF output with TTF files
TTF fonts loaded using load_font() may cause PDF generation to fail.
See the bugs pages on the ChIPS website for an up-to-date listing of known bugs.