afmtest.c - enscript - GNU Enscript
(HTM) git clone git://thinkerwim.org/enscript.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
afmtest.c (3948B)
---
1 /*
2 * Tester program for the AFM library.
3 * Copyright (c) 1995-1999 Markku Rossi.
4 *
5 * Author: Markku Rossi <mtr@iki.fi>
6 */
7
8 /*
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.
13 *
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.
18 *
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/>.
21 */
22
23 #include <stdio.h>
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #if STDC_HEADERS
30 #include <stdlib.h>
31 #endif
32
33 #if HAVE_STRING_H
34 #include <string.h>
35 #endif
36
37 #include "afm.h"
38
39 /*
40 * Types and definitions.
41 */
42
43 #define HANDLE_ERROR(msg) \
44 if (error != AFM_SUCCESS) \
45 { \
46 char buf[256]; \
47 afm_error_to_string (error, buf); \
48 fprintf (stderr, "afmtest: %s: %s\n", msg, buf); \
49 exit (1); \
50 }
51
52
53 /*
54 * Prototypes for static functions.
55 */
56
57 static void usage ();
58
59
60 /*
61 * Static variables
62 */
63
64 static char *program;
65
66
67 /*
68 * Global functions.
69 */
70
71 int
72 main (int argc, char *argv[])
73 {
74 AFMHandle afm;
75 AFMFont font;
76 AFMError error;
77 AFMNumber width, height;
78 char buf[256];
79
80 program = strrchr (argv[0], '/');
81 if (program)
82 program++;
83 else
84 program = argv[0];
85
86 error = afm_create (NULL, 0, &afm);
87 HANDLE_ERROR ("couldn't create library");
88
89 if (argc < 2)
90 {
91 usage ();
92 exit (1);
93 }
94
95 if (strcmp (argv[1], "dump") == 0 && argc == 3)
96 {
97 error = afm_open_file (afm, AFM_I_ALL, argv[2], &font);
98 if (error != AFM_SUCCESS)
99 {
100 fprintf (stderr, "%s: couldn't open font \"%s\", using default\n",
101 program, argv[2]);
102 error = afm_open_default_font (afm, &font);
103 HANDLE_ERROR ("couldn't open default font");
104 }
105
106 afm_font_dump (stdout, font);
107
108 error = afm_close_font (font);
109 HANDLE_ERROR ("couldn't close font");
110 }
111 else if (strcmp (argv[1], "stringwidth") == 0 && argc == 5)
112 {
113 error = afm_open_file (afm, AFM_I_ALL, argv[2], &font);
114 HANDLE_ERROR ("couldn't open font");
115
116 error = afm_font_encoding (font, AFM_ENCODING_ISO_8859_1, 0);
117 HANDLE_ERROR ("couldn't encode font");
118
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);
122
123 error = afm_close_font (font);
124 HANDLE_ERROR ("couldn't close font");
125 }
126 else if (strcmp (argv[1], "chardump") == 0 && argc > 2)
127 {
128 int i, j;
129
130 for (i = 2; i < argc; i++)
131 {
132 error = afm_open_file (afm, AFM_I_COMPOSITES, argv[i], &font);
133 if (error != AFM_SUCCESS)
134 {
135 afm_error_to_string (error, buf);
136 fprintf (stderr, "%s: couldn't open AFM file \"%s\": %s\n",
137 program, argv[i], buf);
138 continue;
139 }
140
141 for (j = 0; j < font->num_character_metrics; j++)
142 {
143 AFMIndividualCharacterMetrics *cm;
144 cm = &font->character_metrics[j];
145
146 printf ("/%-30s %3ld glyph %s\n", cm->name, cm->character_code,
147 font->global_info.FontName);
148 }
149
150 for (j = 0; j < font->num_composites; j++)
151 {
152 AFMComposite *cc;
153 cc = &font->composites[j];
154
155 printf ("/%-30s -1 composite %s\n", cc->name,
156 font->global_info.FontName);
157 }
158
159 (void) afm_close_font (font);
160 }
161 }
162 else
163 {
164 usage ();
165 exit (1);
166 }
167
168 return 0;
169 }
170
171
172 /*
173 * Static functions.
174 */
175
176 static void
177 usage ()
178 {
179 fprintf (stderr,
180 "Usage: %s dump file\n"
181 " %s stringwidth file ptsize string\n"
182 " %s chardump file [file ...]\n",
183 program, program, program);
184 }