src/vfldisol.c
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- main
- usage
- DisVFData
- EmptyLine
- PrintCCode
- PrintToken
- PrintHeaderI
- PrintHeaderR
- Print
- Newline
- PrintEnd
- PrintXY
1 /*
2 * vfldisol.c - Disassemble Vector Font Data
3 * by Hirotsugu Kakugawa
4 *
5 * 31 Dec 1993
6 * 20 Jan 1994 New output format
7 * 10 Jan 1997 for VFlib version 3
8 * 22 Mar 1997 Upgraded for VFlib 3.2
9 *
10 */
11 /*
12 * Copyright (C) 1993-1997 Hirotsugu Kakugawa.
13 * All rights reserved.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
18 * any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <varargs.h>
34 #include "VFlib-3_6.h"
35
36 #define CommentLine printf
37
38 void usage(void);
39 void DisVFData(VF_OUTLINE,int);
40 void EmptyLine(void);
41 void PrintCCode(long);
42 void PrintToken(void);
43 void PrintHeaderI(char*,long);
44 void PrintHeaderR(char*,long);
45 void Print(int*,char*);
46 void Newline(void);
47 void PrintEnd(void);
48 void PrintXY(int,int);
49
50
51 int
52 main(int argc, char **argv)
/* [<][>][^][v][top][bottom][index][help] */
53 {
54 int Fd, i;
55 int Ch, HexDump;
56 long CharCode;
57 double MagX, MagY, Point, Dpi;
58 char *FontName, *Vfcap;
59 VF_OUTLINE VFData;
60
61 Vfcap = NULL;
62 HexDump = 0;
63 Point = -1;
64 MagX = 1;
65 MagY = 1;
66 Dpi = -1;
67 FontName = NULL;
68
69 Ch = argc + 2001;
70 for (i = 1; i < argc; i++){
71 if (argv[i][0] == '-'){
72 switch (argv[i][1]){
73 case 'v': Vfcap = argv[++i]; break;
74 case 'x': HexDump = 1; break;
75 case 'd': Dpi = atof(argv[++i]); break;
76 case 'p': Point = atof(argv[++i]); break;
77 case 'm':
78 if (strcmp(argv[i], "-mx") == 0)
79 MagX = atof(argv[++i]);
80 else if (strcmp(argv[i], "-my") == 0)
81 MagY = atof(argv[++i]);
82 else
83 MagX = MagY = atof(argv[++i]);
84 break;
85 case 'h':
86 default:
87 usage();
88 }
89 } else {
90 FontName = argv[i++];
91 Ch = i;
92 break;
93 }
94 }
95
96 if ((FontName == NULL) || (Ch >= argc))
97 usage(); /* no char codes */
98
99 /* Init VFlib */
100 if (VF_Init(Vfcap, NULL) < 0){
101 fprintf(stderr, "VFlib init error.\n");
102 exit(1);
103 }
104
105 /* OPEN THE FONT */
106 if ((Fd = VF_OpenFont1(FontName, Dpi, Dpi, Point, MagX, MagY)) < 0){
107 fprintf(stderr, "Open Error: %s\n", FontName);
108 fprintf(stderr, "VFlib error code: %d\n", vf_error);
109 exit(1);
110 }
111
112 printf(";; OUTLINES OF FONT ENTRY %s\n\n", FontName);
113
114 while (Ch < argc){
115 sscanf(argv[Ch], "%li", &CharCode);
116 Ch++;
117
118 /* GET VECTOR FONT DATA */
119 if ((VFData = VF_GetOutline(Fd, CharCode, 1, 1)) == NULL){
120 printf(";; CAN'T GET OUTLINE FOR CHARACTER 0x%lX OF FONT %s\n",
121 CharCode, FontName);
122 printf(";; VFlib error code: %d\n", vf_error);
123 continue;
124 }
125
126 PrintCCode(CharCode);
127 if (HexDump == 0){
128 /* DISASSEMBLE IT */
129 DisVFData(VFData, Fd);
130 } else {
131 /* Hex Dump */
132 for (i = 0; ; i++){
133 printf("%04x %08lx\n", i, (long)VFData[i]);
134 if ((i >= VF_OL_OUTLINE_HEADER_SIZE_TYPE0) && (VFData[i] == 0))
135 break;
136 }
137 }
138
139 /* RELEASE OUTLINE */
140 VF_FreeOutline(VFData);
141 }
142
143 printf("END\n");
144
145 /* CLOSE THE FONT */
146 VF_CloseFont(Fd);
147
148 return 0;
149 }
150
151 void
152 usage()
/* [<][>][^][v][top][bottom][index][help] */
153 {
154 printf("vfldisol --- disassemble outline data\n");
155 printf("Usage vfldisol [options] font code1 code2 ...\n");
156 printf("Options: \n");
157 printf(" -v VFLIBCAP : vflibcap absolute path.\n");
158 printf(" -d DPI : device resolution in dpi.\n");
159 printf(" -p POINT : character point size.\n");
160 printf(" -x : hex dump instead of disas.\n");
161 printf("Example 1: vfldisol -f timR24.pcf 0x67 0x68 0x69\n");
162 printf("Example 2: vfldisol -f goth 0x2124\n");
163 exit(0);
164 }
165
166
167
168 /*
169 * Disassemble Vector Font Data returned by VF_GetOutline()
170 */
171
172 void
173 DisVFData(VF_OUTLINE vfdata, int fd)
/* [<][>][^][v][top][bottom][index][help] */
174 {
175 long cmd, *ptr;
176 unsigned int x, y;
177 int m;
178
179 if (vfdata == NULL)
180 return;
181 PrintHeaderI("FORMAT ", vfdata[VF_OL_HEADER_INDEX_HEADER_TYPE]);
182 PrintHeaderI("DATA_SIZE ", vfdata[VF_OL_HEADER_INDEX_DATA_SIZE]);
183 PrintHeaderR("DPI_X ", vfdata[VF_OL_HEADER_INDEX_DPI_X]);
184 PrintHeaderR("DPI_Y ", vfdata[VF_OL_HEADER_INDEX_DPI_Y]);
185 PrintHeaderR("POINT_SIZE", vfdata[VF_OL_HEADER_INDEX_POINT_SIZE]);
186 PrintHeaderI("EM ", vfdata[VF_OL_HEADER_INDEX_EM]);
187 PrintHeaderI("MAX_X ", vfdata[VF_OL_HEADER_INDEX_MAX_X]);
188 PrintHeaderI("MAX_Y ", vfdata[VF_OL_HEADER_INDEX_MAX_Y]);
189 PrintHeaderI("REF_X ", vfdata[VF_OL_HEADER_INDEX_REF_X]);
190 PrintHeaderI("REF_Y ", vfdata[VF_OL_HEADER_INDEX_REF_Y]);
191 PrintHeaderI("MV_X ", vfdata[VF_OL_HEADER_INDEX_MV_X]);
192 PrintHeaderI("MV_Y ", vfdata[VF_OL_HEADER_INDEX_MV_Y]);
193
194 ptr = &vfdata[VF_OL_OUTLINE_HEADER_SIZE_TYPE0];
195 do {
196 m = 0;
197 cmd = *ptr;
198 ptr++;
199 if (cmd == 0L){
200 PrintEnd();
201 EmptyLine();
202 } else if ((cmd & VF_OL_INSTR_TOKEN) != 0){
203 PrintToken();
204 if ((cmd & VF_OL_INSTR_CHAR) != 0)
205 Print(&m, "CH");
206 if ((cmd & VF_OL_INSTR_CWCURV) != 0)
207 Print(&m, "C1");
208 if ((cmd & VF_OL_INSTR_CCWCURV) != 0)
209 Print(&m, "C2");
210 if ((cmd & VF_OL_INSTR_LINE) != 0)
211 Print(&m, "LI");
212 if ((cmd & VF_OL_INSTR_ARC) != 0)
213 Print(&m, "AR");
214 if ((cmd & VF_OL_INSTR_BEZ) != 0)
215 Print(&m, "BE");
216 Newline();
217 } else {
218 x = VF_OL_GET_X(cmd);
219 y = VF_OL_GET_Y(cmd);
220 PrintXY(x, y);
221 }
222 } while (cmd != 0L);
223 }
224
225
226 void
227 EmptyLine(void)
/* [<][>][^][v][top][bottom][index][help] */
228 {
229 printf("\n");
230 }
231
232 void
233 PrintCCode(long n)
/* [<][>][^][v][top][bottom][index][help] */
234 {
235 printf("CHAR ");
236 printf("0x%lX\n", (long)n);
237 }
238
239 void
240 PrintToken(void)
/* [<][>][^][v][top][bottom][index][help] */
241 {
242 printf(" ");
243 printf("TOKEN ");
244 }
245
246 void
247 PrintHeaderI(char *label, long val)
/* [<][>][^][v][top][bottom][index][help] */
248 {
249 printf(" ");
250 printf("%s %ld\n", label, val);
251 }
252
253 void
254 PrintHeaderR(char *label, long val)
/* [<][>][^][v][top][bottom][index][help] */
255 {
256 printf(" ");
257 printf("%s %f\n", label, (double)VF_OL_HEADER_DECODE(val));
258 }
259
260 void
261 Print(int *mp, char *str)
/* [<][>][^][v][top][bottom][index][help] */
262 {
263 if (*mp == 0)
264 printf("[");
265 if (*mp > 0)
266 printf(",");
267 printf("%s", str);
268 (*mp)++;
269 }
270
271 void
272 Newline(void)
/* [<][>][^][v][top][bottom][index][help] */
273 {
274 printf("]\n");
275 }
276
277 void
278 PrintEnd(void)
/* [<][>][^][v][top][bottom][index][help] */
279 {
280 printf(" ");
281 printf("END \n");
282 }
283
284 void
285 PrintXY(int x, int y)
/* [<][>][^][v][top][bottom][index][help] */
286 {
287 printf(" ");
288 printf("XY %d %d\n", x,y);
289 }
290
291 /*EOF*/