2 * Tester program for the AFM library.
3 * Copyright (c) 1995-1999 Markku Rossi.
5 * Author: Markku Rossi <mtr@iki.fi>
9 * Enscript is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * Enscript is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Enscript. If not, see <http://www.gnu.org/licenses/>.
40 * Types and definitions.
43 #define HANDLE_ERROR(msg) \
44 if (error != AFM_SUCCESS) \
47 afm_error_to_string (error, buf); \
48 fprintf (stderr, "afmtest: %s: %s\n", msg, buf); \
54 * Prototypes for static functions.
72 main (int argc, char *argv[])
77 AFMNumber width, height;
80 program = strrchr (argv[0], '/');
86 error = afm_create (NULL, 0, &afm);
87 HANDLE_ERROR ("couldn't create library");
95 if (strcmp (argv[1], "dump") == 0 && argc == 3)
97 error = afm_open_file (afm, AFM_I_ALL, argv[2], &font);
98 if (error != AFM_SUCCESS)
100 fprintf (stderr, "%s: couldn't open font \"%s\", using default\n",
102 error = afm_open_default_font (afm, &font);
103 HANDLE_ERROR ("couldn't open default font");
106 afm_font_dump (stdout, font);
108 error = afm_close_font (font);
109 HANDLE_ERROR ("couldn't close font");
111 else if (strcmp (argv[1], "stringwidth") == 0 && argc == 5)
113 error = afm_open_file (afm, AFM_I_ALL, argv[2], &font);
114 HANDLE_ERROR ("couldn't open font");
116 error = afm_font_encoding (font, AFM_ENCODING_ISO_8859_1, 0);
117 HANDLE_ERROR ("couldn't encode font");
119 error = afm_font_stringwidth (font, atof (argv[3]), argv[4],
120 strlen (argv[4]), &width, &height);
121 printf ("stringwidth is [%g %g]\n", width, height);
123 error = afm_close_font (font);
124 HANDLE_ERROR ("couldn't close font");
126 else if (strcmp (argv[1], "chardump") == 0 && argc > 2)
130 for (i = 2; i < argc; i++)
132 error = afm_open_file (afm, AFM_I_COMPOSITES, argv[i], &font);
133 if (error != AFM_SUCCESS)
135 afm_error_to_string (error, buf);
136 fprintf (stderr, "%s: couldn't open AFM file \"%s\": %s\n",
137 program, argv[i], buf);
141 for (j = 0; j < font->num_character_metrics; j++)
143 AFMIndividualCharacterMetrics *cm;
144 cm = &font->character_metrics[j];
146 printf ("/%-30s %3ld glyph %s\n", cm->name, cm->character_code,
147 font->global_info.FontName);
150 for (j = 0; j < font->num_composites; j++)
153 cc = &font->composites[j];
155 printf ("/%-30s -1 composite %s\n", cc->name,
156 font->global_info.FontName);
159 (void) afm_close_font (font);
180 "Usage: %s dump file\n"
181 " %s stringwidth file ptsize string\n"
182 " %s chardump file [file ...]\n",
183 program, program, program);