2 * Tester program for the AFM library.
3 * Copyright (c) 1995-1999 Markku Rossi.
5 * Author: Markku Rossi <mtr@iki.fi>
9 * This program 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 2, or (at your option)
14 * This program 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 this program; see the file COPYING. If not, write to
21 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
42 * Types and definitions.
45 #define HANDLE_ERROR(msg) \
46 if (error != AFM_SUCCESS) \
49 afm_error_to_string (error, buf); \
50 fprintf (stderr, "afmtest: %s: %s\n", msg, buf); \
56 * Prototypes for static functions.
74 main (int argc, char *argv[])
79 AFMNumber width, height;
82 program = strrchr (argv[0], '/');
88 error = afm_create (NULL, 0, &afm);
89 HANDLE_ERROR ("couldn't create library");
97 if (strcmp (argv[1], "dump") == 0 && argc == 3)
99 error = afm_open_file (afm, AFM_I_ALL, argv[2], &font);
100 if (error != AFM_SUCCESS)
102 fprintf (stderr, "%s: couldn't open font \"%s\", using default\n",
104 error = afm_open_default_font (afm, &font);
105 HANDLE_ERROR ("couldn't open default font");
108 afm_font_dump (stdout, font);
110 error = afm_close_font (font);
111 HANDLE_ERROR ("couldn't close font");
113 else if (strcmp (argv[1], "stringwidth") == 0 && argc == 5)
115 error = afm_open_file (afm, AFM_I_ALL, argv[2], &font);
116 HANDLE_ERROR ("couldn't open font");
118 error = afm_font_encoding (font, AFM_ENCODING_ISO_8859_1, 0);
119 HANDLE_ERROR ("couldn't encode font");
121 error = afm_font_stringwidth (font, atof (argv[3]), argv[4],
122 strlen (argv[4]), &width, &height);
123 printf ("stringwidth is [%g %g]\n", width, height);
125 error = afm_close_font (font);
126 HANDLE_ERROR ("couldn't close font");
128 else if (strcmp (argv[1], "chardump") == 0 && argc > 2)
132 for (i = 2; i < argc; i++)
134 error = afm_open_file (afm, AFM_I_COMPOSITES, argv[i], &font);
135 if (error != AFM_SUCCESS)
137 afm_error_to_string (error, buf);
138 fprintf (stderr, "%s: couldn't open AFM file \"%s\": %s\n",
139 program, argv[i], buf);
143 for (j = 0; j < font->num_character_metrics; j++)
145 AFMIndividualCharacterMetrics *cm;
146 cm = &font->character_metrics[j];
148 printf ("/%-30s %3ld glyph %s\n", cm->name, cm->character_code,
149 font->global_info.FontName);
152 for (j = 0; j < font->num_composites; j++)
155 cc = &font->composites[j];
157 printf ("/%-30s -1 composite %s\n", cc->name,
158 font->global_info.FontName);
161 (void) afm_close_font (font);
182 "Usage: %s dump file\n"
183 " %s stringwidth file ptsize string\n"
184 " %s chardump file [file ...]\n",
185 program, program, program);