src/vfltest.c
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- main
- usage
- display
- display_mode1
- display_mode1_ol
- display_mode2
1 /*
2 * vfltest.c - a test program for VFlib
3 * by Hirotsugu Kakugawa
4 *
5 * 22 Mar 1997 Upgraded for VFlib 3.2
6 * 6 Aug 1997 Upgraded for VFlib 3.3
7 */
8 /*
9 * Copyright (C) 1996-1998 Hirotsugu Kakugawa.
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include "VFlib-3_6.h"
31
32 #define PROG_NAME "vfltest"
33
34 void usage(void);
35 int display(long);
36 int display_mode1(long);
37 int display_mode1_ol(long);
38 int display_mode2(long);
39
40 extern double atof();
41
42
43 char *FontName;
44 int Mode;
45 int Outline;
46 double MagX, MagY;
47 int Pixel;
48 double Point;
49 double Dpi;
50 int FontId;
51
52
53 int
54 main(int argc, char **argv)
/* [<][>][^][v][top][bottom][index][help] */
55 {
56 int i, j;
57 long code, code1, code2;
58 char *vflibcap;
59
60 Mode = 1;
61 Outline = 0;
62 MagX = MagY = 1.0;
63 Point = -1.0;
64 Pixel = -1;
65 Dpi = -1;
66
67 vflibcap = NULL;
68 argc--; argv++;
69 while ((argc > 0) && (*argv[0] == '-')){
70 if (strcmp(argv[0], "-f") == 0){
71 argc--; argv++;
72 break;
73 } else if (strcmp(argv[0], "-v") == 0){
74 vflibcap = argv[1];
75 argc--; argv++;
76 } else if (strcmp(argv[0], "-m") == 0){
77 MagX = MagY = atof(argv[1]);
78 argc--; argv++;
79 } else if (strcmp(argv[0], "-mx") == 0){
80 MagX = atof(argv[1]);
81 argc--; argv++;
82 } else if (strcmp(argv[0], "-my") == 0){
83 MagY = atof(argv[1]);
84 argc--; argv++;
85 } else if (strcmp(argv[0], "-p") == 0){
86 Pixel = atoi(argv[1]);
87 Point = atof(argv[1]);
88 argc--; argv++;
89 } else if (strcmp(argv[0], "-d") == 0){
90 Dpi = atof(argv[1]);
91 argc--; argv++;
92 } else if (strcmp(argv[0], "-mode1") == 0){
93 Mode = 1;
94 argc--; argv++;
95 } else if (strcmp(argv[0], "-mode2") == 0){
96 Mode = 2;
97 argc--; argv++;
98 } else if (strcmp(argv[0], "-ol") == 0){
99 Outline = 1;
100 argc--; argv++;
101 } if ((strcmp(argv[0], "-h") == 0)|| (strcmp(argv[0], "-h") == 0)){
102 usage();
103 } else if (strcmp(argv[0], "--help") == 0){
104 usage();
105 } else if (strcmp(argv[0], "-help") == 0){
106 usage();
107 }
108
109 argc--; argv++;
110 }
111
112 if (argc <= 1)
113 usage();
114
115 FontName = argv[0];
116 argv++; argc--;
117
118 if (VF_Init(vflibcap, NULL) < 0){
119 fprintf(stderr, "Error %d in VF_Init().\n", vf_error);
120 exit(0);
121 }
122
123 if (Mode == 1)
124 FontId = VF_OpenFont1(FontName, Dpi, Dpi, Point, MagX, MagY);
125 else
126 FontId = VF_OpenFont2(FontName, Pixel, MagX, MagY);
127
128 if (FontId < 0){
129 fprintf(stderr, "Error %d in VF_OpenFont1()\n", vf_error);
130 exit(0);
131 }
132
133 while (argc > 0){
134 if (argv[0][0] == '='){
135 for (i = 1; argv[0][i] != '\0'; i++){
136 if ( (argv[0][i+1] != '\0') && (argv[0][i+1] == '-')
137 && (argv[0][i+2] != '\0') && (argv[0][i] < argv[0][i+2]) ){
138 for (j = (int)argv[0][i]; j <= (int)argv[0][i+2]; j++){
139 display(j);
140 }
141 i = i+2;
142 } else {
143 display((long)argv[0][i]);
144 }
145 }
146 argv++;
147 argc--;
148 } else if ((argv[1] != NULL) && (argv[2] != NULL)
149 && (strcmp(argv[1], "-") == 0)){
150 sscanf(argv[0], "%li", &code1);
151 sscanf(argv[2], "%li", &code2);
152 for (code = code1; code <= code2; code++)
153 display(code);
154 argv = &argv[3];
155 argc -= 3;
156 } else {
157 sscanf(argv[0], "%li", &code);
158 display(code);
159 argv++;
160 argc--;
161 }
162 }
163
164 return 0;
165 }
166
167
168 void
169 usage(void)
/* [<][>][^][v][top][bottom][index][help] */
170 {
171 printf("%s --- A test program for VFlib\n", PROG_NAME);
172 printf("Usage: %s [OPTIONS] FONT %s\n",
173 PROG_NAME,
174 "[CHAR_CODE ...] [=CHAR_LIST ...] [CHAR_FROM - CHAR_TO ...]");
175 printf(" Options: -mode1 select mode 1\n");
176 printf(" -mode2 select mode 2\n");
177 printf(" -mx MAG_X horizontal magnification\n");
178 printf(" -my MAG_Y vertical magnification\n");
179 printf(" -v VFLIBCAP vflibcap file\n");
180 printf(" -ol (mode 1) rasterize by outline APIs\n");
181 printf(" -d DPI (mode 1) device resolution\n");
182 printf(" -p POINT (mode 1) point size\n");
183 printf(" -p PIXEL (mode 2) pixel size\n");
184 printf(" Example 1: %s timR24 33 34 35 0x61 0x62\n", PROG_NAME);
185 printf(" Example 2: %s jiskan16 0x2123 0x2124\n", PROG_NAME);
186 printf(" Example 3: %s timR24 =abcdefg\n", PROG_NAME);
187 printf(" Example 4: %s timR24 0x21 - 0x7e\n", PROG_NAME);
188 exit(0);
189 }
190
191
192 int
193 display(long code_point)
/* [<][>][^][v][top][bottom][index][help] */
194 {
195 int r;
196
197 if (Mode == 1){
198 if (Outline == 0){
199 r = display_mode1(code_point);
200 } else {
201 r = display_mode1_ol(code_point);
202 }
203 } else {
204 r = display_mode2(code_point);
205 }
206
207 return r;
208 }
209
210
211 int
212 display_mode1(long code_point)
/* [<][>][^][v][top][bottom][index][help] */
213 {
214 VF_BITMAP bm;
215
216 printf("Char Code: 0x%lx\n", code_point);
217 if ((bm = VF_GetBitmap1(FontId, code_point, 1, 1)) == NULL){
218 fprintf(stderr, "Error %d in VF_GetBitmap1()\n", vf_error);
219 return -1;
220 }
221 VF_DumpBitmap(bm);
222 printf("\n");
223 VF_FreeBitmap(bm);
224 return 0;
225 }
226
227 int
228 display_mode1_ol(long code_point)
/* [<][>][^][v][top][bottom][index][help] */
229 {
230 VF_OUTLINE outline;
231 VF_BITMAP bm;
232
233 printf("Char Code: 0x%lx\n", code_point);
234 if ((outline = VF_GetOutline(FontId, code_point, 1, 1)) == NULL){
235 fprintf(stderr, "Error %d in VF_GetOutline()\n", vf_error);
236 return -1;
237 }
238 if ((bm = VF_OutlineToBitmap(outline, -1, -1, -1, 1.0, 1.0)) == NULL){
239 fprintf(stderr, "Error %d in VF_GetOutline1()\n", vf_error);
240 return -1;
241 }
242 VF_FreeOutline(outline);
243 VF_DumpBitmap(bm);
244 printf("\n");
245 VF_FreeBitmap(bm);
246 return 0;
247 }
248
249 int
250 display_mode2(long code_point)
/* [<][>][^][v][top][bottom][index][help] */
251 {
252 VF_BITMAP bm;
253
254 printf("Char Code: 0x%lx\n", code_point);
255 if ((bm = VF_GetBitmap2(FontId, code_point, 1, 1)) == NULL){
256 fprintf(stderr, "Error %d in VF_GetBitmap2()\n", vf_error);
257 return -1;
258 }
259 VF_DumpBitmap(bm);
260 printf("\n");
261 VF_FreeBitmap(bm);
262 return 0;
263 }
264
265 /*EOF*/