1 /* $XConsortium: t1test.c,v 1.2 91/10/10 11:19:53 rws Exp $ */
2 /* Copyright International Business Machines,Corp. 1991
3  * All Rights Reserved
4  *
5  * License to use, copy, modify, and distribute this software
6  * and its documentation for any purpose and without fee is
7  * hereby granted, provided that the above copyright notice
8  * appear in all copies and that both that copyright notice and
9  * this permission notice appear in supporting documentation,
10  * and that the name of IBM not be used in advertising or
11  * publicity pertaining to distribution of the software without
12  * specific, written prior permission.
13  *
14  * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
15  * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
16  * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
18  * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
19  * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
20  * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
21  * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
22  * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
23  * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
24  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
25  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
26  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
27  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
28  * SOFTWARE.
29  */
30 
31 #include <stdlib.h>
32 #include "ffilest.h"
33 #ifdef XSERVER
34 #include "FSproto.h"
35 #endif
36 
37 void Display();
38 
39 #define DECIPOINTSPERINCH 722.7
40 #define DEFAULTRES 75
41 #define DEFAULTPOINTSIZE 120
42 
43 FontScalableRec vals;
44 FontEntryRec entry;
45 
46 typedef char *encoding[256];
47 
48 /* PostScript ISOLatin1Encoding */
49 
50 char *ISOLatin1[256] = {
51 	 /* '000  000  "00 */ NULL,
52 	 /* '001  001  "01 */ NULL,
53 	 /* '002  002  "02 */ NULL,
54 	 /* '003  003  "03 */ NULL,
55 	 /* '004  004  "04 */ NULL,
56 	 /* '005  005  "05 */ NULL,
57 	 /* '006  006  "06 */ NULL,
58 	 /* '007  007  "07 */ NULL,
59 	 /* '010  008  "08 */ NULL,
60 	 /* '011  009  "09 */ NULL,
61 	 /* '012  010  "0A */ NULL,
62 	 /* '013  011  "0B */ NULL,
63 	 /* '014  012  "0C */ NULL,
64 	 /* '015  013  "0D */ NULL,
65 	 /* '016  014  "0E */ NULL,
66 	 /* '017  015  "0F */ NULL,
67 	 /* '020  016  "10 */ NULL,
68 	 /* '021  017  "11 */ NULL,
69 	 /* '022  018  "12 */ NULL,
70 	 /* '023  019  "13 */ NULL,
71 	 /* '024  020  "14 */ NULL,
72 	 /* '025  021  "15 */ NULL,
73 	 /* '026  022  "16 */ NULL,
74 	 /* '027  023  "17 */ NULL,
75 	 /* '030  024  "18 */ NULL,
76 	 /* '031  025  "19 */ NULL,
77 	 /* '032  026  "1A */ NULL,
78 	 /* '033  027  "1B */ NULL,
79 	 /* '034  028  "1C */ NULL,
80 	 /* '035  029  "1D */ NULL,
81 	 /* '036  030  "1E */ NULL,
82 	 /* '037  031  "1F */ NULL,
83 	 /* '040  032  "20 */ "space",
84 	 /* '041  033  "21 */ "exclam",
85 	 /* '042  034  "22 */ "quotedbl",
86 	 /* '043  035  "23 */ "numbersign",
87 	 /* '044  036  "24 */ "dollar",
88 	 /* '045  037  "25 */ "percent",
89 	 /* '046  038  "26 */ "ampersand",
90 	 /* '047  039  "27 */ "quoteright",
91 	 /* '050  040  "28 */ "parenleft",
92 	 /* '051  041  "29 */ "parenright",
93 	 /* '052  042  "2A */ "asterisk",
94 	 /* '053  043  "2B */ "plus",
95 	 /* '054  044  "2C */ "comma",
96 	 /* '055  045  "2D */ "hyphen",
97 	 /* '056  046  "2E */ "period",
98 	 /* '057  047  "2F */ "slash",
99 	 /* '060  048  "30 */ "zero",
100 	 /* '061  049  "31 */ "one",
101 	 /* '062  050  "32 */ "two",
102 	 /* '063  051  "33 */ "three",
103 	 /* '064  052  "34 */ "four",
104 	 /* '065  053  "35 */ "five",
105 	 /* '066  054  "36 */ "six",
106 	 /* '067  055  "37 */ "seven",
107 	 /* '070  056  "38 */ "eight",
108 	 /* '071  057  "39 */ "nine",
109 	 /* '072  058  "3A */ "colon",
110 	 /* '073  059  "3B */ "semicolon",
111 	 /* '074  060  "3C */ "less",
112 	 /* '075  061  "3D */ "equal",
113 	 /* '076  062  "3E */ "greater",
114 	 /* '077  063  "3F */ "question",
115 	 /* '100  064  "40 */ "at",
116 	 /* '101  065  "41 */ "A",
117 	 /* '102  066  "42 */ "B",
118 	 /* '103  067  "43 */ "C",
119 	 /* '104  068  "44 */ "D",
120 	 /* '105  069  "45 */ "E",
121 	 /* '106  070  "46 */ "F",
122 	 /* '107  071  "47 */ "G",
123 	 /* '110  072  "48 */ "H",
124 	 /* '111  073  "49 */ "I",
125 	 /* '112  074  "4A */ "J",
126 	 /* '113  075  "4B */ "K",
127 	 /* '114  076  "4C */ "L",
128 	 /* '115  077  "4D */ "M",
129 	 /* '116  078  "4E */ "N",
130 	 /* '117  079  "4F */ "O",
131 	 /* '120  080  "50 */ "P",
132 	 /* '121  081  "51 */ "Q",
133 	 /* '122  082  "52 */ "R",
134 	 /* '123  083  "53 */ "S",
135 	 /* '124  084  "54 */ "T",
136 	 /* '125  085  "55 */ "U",
137 	 /* '126  086  "56 */ "V",
138 	 /* '127  087  "57 */ "W",
139 	 /* '130  088  "58 */ "X",
140 	 /* '131  089  "59 */ "Y",
141 	 /* '132  090  "5A */ "Z",
142 	 /* '133  091  "5B */ "bracketleft",
143 	 /* '134  092  "5C */ "backslash",
144 	 /* '135  093  "5D */ "bracketright",
145 	 /* '136  094  "5E */ "asciicircum",
146 	 /* '137  095  "5F */ "underscore",
147 	 /* '140  096  "60 */ "quoteleft",
148 	 /* '141  097  "61 */ "a",
149 	 /* '142  098  "62 */ "b",
150 	 /* '143  099  "63 */ "c",
151 	 /* '144  100  "64 */ "d",
152 	 /* '145  101  "65 */ "e",
153 	 /* '146  102  "66 */ "f",
154 	 /* '147  103  "67 */ "g",
155 	 /* '150  104  "68 */ "h",
156 	 /* '151  105  "69 */ "i",
157 	 /* '152  106  "6A */ "j",
158 	 /* '153  107  "6B */ "k",
159 	 /* '154  108  "6C */ "l",
160 	 /* '155  109  "6D */ "m",
161 	 /* '156  110  "6E */ "n",
162 	 /* '157  111  "6F */ "o",
163 	 /* '160  112  "70 */ "p",
164 	 /* '161  113  "71 */ "q",
165 	 /* '162  114  "72 */ "r",
166 	 /* '163  115  "73 */ "s",
167 	 /* '164  116  "74 */ "t",
168 	 /* '165  117  "75 */ "u",
169 	 /* '166  118  "76 */ "v",
170 	 /* '167  119  "77 */ "w",
171 	 /* '170  120  "78 */ "x",
172 	 /* '171  121  "79 */ "y",
173 	 /* '172  122  "7A */ "z",
174 	 /* '173  123  "7B */ "braceleft",
175 	 /* '174  124  "7C */ "bar",
176 	 /* '175  125  "7D */ "braceright",
177 	 /* '176  126  "7E */ "asciitilde",
178 	 /* '177  127  "7F */ NULL,
179 	 /* '200  128  "80 */ NULL,
180 	 /* '201  129  "81 */ NULL,
181 	 /* '202  130  "82 */ NULL,
182 	 /* '203  131  "83 */ NULL,
183 	 /* '204  132  "84 */ NULL,
184 	 /* '205  133  "85 */ NULL,
185 	 /* '206  134  "86 */ NULL,
186 	 /* '207  135  "87 */ NULL,
187 	 /* '210  136  "88 */ NULL,
188 	 /* '211  137  "89 */ NULL,
189 	 /* '212  138  "8A */ NULL,
190 	 /* '213  139  "8B */ NULL,
191 	 /* '214  140  "8C */ NULL,
192 	 /* '215  141  "8D */ NULL,
193 	 /* '216  142  "8E */ NULL,
194 	 /* '217  143  "8F */ NULL,
195 	 /* '220  144  "90 */ "dotlessi",
196 	 /* '221  145  "91 */ "grave",
197 	 /* '222  146  "92 */ "acute",
198 	 /* '223  147  "93 */ "circumflex",
199 	 /* '224  148  "94 */ "tilde",
200 	 /* '225  149  "95 */ "macron",
201 	 /* '226  150  "96 */ "breve",
202 	 /* '227  151  "97 */ "dotaccent",
203 	 /* '230  152  "98 */ "dieresis",
204 	 /* '231  153  "99 */ NULL,
205 	 /* '232  154  "9A */ "ring",
206 	 /* '233  155  "9B */ "cedilla",
207 	 /* '234  156  "9C */ NULL,
208 	 /* '235  157  "9D */ "hungarumlaut",
209 	 /* '236  158  "9E */ "ogonek",
210 	 /* '237  159  "9F */ "caron",
211 	 /* '240  160  "A0 */ "space",
212 	 /* '241  161  "A1 */ "exclamdown",
213 	 /* '242  162  "A2 */ "cent",
214 	 /* '243  163  "A3 */ "sterling",
215 	 /* '244  164  "A4 */ "currency",
216 	 /* '245  165  "A5 */ "yen",
217 	 /* '246  166  "A6 */ "brokenbar",
218 	 /* '247  167  "A7 */ "section",
219 	 /* '250  168  "A8 */ "dieresis",
220 	 /* '251  169  "A9 */ "copyright",
221 	 /* '252  170  "AA */ "ordfeminine",
222 	 /* '253  171  "AB */ "guillemotleft",
223 	 /* '254  172  "AC */ "logicalnot",
224 	 /* '255  173  "AD */ "hyphen",
225 	 /* '256  174  "AE */ "registered",
226 	 /* '257  175  "AF */ "macron",
227 	 /* '260  176  "B0 */ "degree",
228 	 /* '261  177  "B1 */ "plusminus",
229 	 /* '262  178  "B2 */ "twosuperior",
230 	 /* '263  179  "B3 */ "threesuperior",
231 	 /* '264  180  "B4 */ "acute",
232 	 /* '265  181  "B5 */ "mu",
233 	 /* '266  182  "B6 */ "paragraph",
234 	 /* '267  183  "B7 */ "periodcentered",
235 	 /* '270  184  "B8 */ "cedilla",
236 	 /* '271  185  "B9 */ "onesuperior",
237 	 /* '272  186  "BA */ "ordmasculine",
238 	 /* '273  187  "BB */ "guillemotright",
239 	 /* '274  188  "BC */ "onequarter",
240 	 /* '275  189  "BD */ "onehalf",
241 	 /* '276  190  "BE */ "threequarters",
242 	 /* '277  191  "BF */ "questiondown",
243 	 /* '300  192  "C0 */ "Agrave",
244 	 /* '301  193  "C1 */ "Aacute",
245 	 /* '302  194  "C2 */ "Acircumflex",
246 	 /* '303  195  "C3 */ "Atilde",
247 	 /* '304  196  "C4 */ "Adieresis",
248 	 /* '305  197  "C5 */ "Aring",
249 	 /* '306  198  "C6 */ "AE",
250 	 /* '307  199  "C7 */ "Ccedilla",
251 	 /* '310  200  "C8 */ "Egrave",
252 	 /* '311  201  "C9 */ "Eacute",
253 	 /* '312  202  "CA */ "Ecircumflex",
254 	 /* '313  203  "CB */ "Edieresis",
255 	 /* '314  204  "CC */ "Igrave",
256 	 /* '315  205  "CD */ "Iacute",
257 	 /* '316  206  "CE */ "Icircumflex",
258 	 /* '317  207  "CF */ "Idieresis",
259 	 /* '320  208  "D0 */ "Eth",
260 	 /* '321  209  "D1 */ "Ntilde",
261 	 /* '322  210  "D2 */ "Ograve",
262 	 /* '323  211  "D3 */ "Oacute",
263 	 /* '324  212  "D4 */ "Ocircumflex",
264 	 /* '325  213  "D5 */ "Otilde",
265 	 /* '326  214  "D6 */ "Odieresis",
266 	 /* '327  215  "D7 */ "multiply",
267 	 /* '330  216  "D8 */ "Oslash",
268 	 /* '331  217  "D9 */ "Ugrave",
269 	 /* '332  218  "DA */ "Uacute",
270 	 /* '333  219  "DB */ "Ucircumflex",
271 	 /* '334  220  "DC */ "Udieresis",
272 	 /* '335  221  "DD */ "Yacute",
273 	 /* '336  222  "DE */ "Thorn",
274 	 /* '337  223  "DF */ "Germandbls",
275 	 /* '340  224  "E0 */ "agrave",
276 	 /* '341  225  "E1 */ "aacute",
277 	 /* '342  226  "E2 */ "acircumflex",
278 	 /* '343  227  "E3 */ "atilde",
279 	 /* '344  228  "E4 */ "adieresis",
280 	 /* '345  229  "E5 */ "aring",
281 	 /* '346  230  "E6 */ "ae",
282 	 /* '347  231  "E7 */ "ccedilla",
283 	 /* '350  232  "E8 */ "egrave",
284 	 /* '351  233  "E9 */ "eacute",
285 	 /* '352  234  "EA */ "ecircumflex",
286 	 /* '353  235  "EB */ "edieresis",
287 	 /* '354  236  "EC */ "igrave",
288 	 /* '355  237  "ED */ "iacute",
289 	 /* '356  238  "EE */ "icircumflex",
290 	 /* '357  239  "EF */ "idieresis",
291 	 /* '360  240  "F0 */ "eth",
292 	 /* '361  241  "F1 */ "ntilde",
293 	 /* '362  242  "F2 */ "ograve",
294 	 /* '363  243  "F3 */ "oacute",
295 	 /* '364  244  "F4 */ "ocircumflex",
296 	 /* '365  245  "F5 */ "otilde",
297 	 /* '366  246  "F6 */ "odieresis",
298 	 /* '367  247  "F7 */ "divide",
299 	 /* '370  248  "F8 */ "oslash",
300 	 /* '371  249  "F9 */ "ugrave",
301 	 /* '372  250  "FA */ "uacute",
302 	 /* '373  251  "FB */ "ucircumflex",
303 	 /* '374  252  "FC */ "udieresis",
304 	 /* '375  253  "FD */ "yacute",
305 	 /* '376  254  "FE */ "thorn",
306 	 /* '377  255  "FF */ "ydieresis"};
307 
main(argc,argv)308 int main(argc, argv)
309        int argc;
310        char *argv[];
311 {
312        int h;
313        char temp[80];
314        char file[80];
315        char glyphcode[1];
316        FontPtr fontptr;
317        CharInfoRec *glyphs[1];
318        int count;
319        int code;
320        int rc = -1;
321        float efactor = 1.0, slant = 0.0;
322        encoding *ev = &ISOLatin1;
323 
324        T1FillVals(&vals);
325        Type1RegisterFontFileFunctions();
326        entry.name.name = "-adobe-utopia-medium-r-normal--0-0-0-0-p-0-iso8859-1";
327 
328        for (;;) {
329                printf("T1TEST: ");
330                gets(temp);
331                glyphcode[0] = '\0';
332 
333                switch(temp[0]) {
334 
335                    case 'E':
336                        if (1 != sscanf(&temp[2], "%f", &efactor))
337                                printf("expansion factor?\n");
338                        break;
339 
340                    case 'S':
341                        if (1 != sscanf(&temp[2], "%f", &slant))
342                                printf("slant?\n");
343                        break;
344 
345                    case 'c':
346                        if (1 != sscanf(&temp[2], "%c", glyphcode))
347                                printf("glyph code?\n");
348                        break;
349 
350                    case 'x':
351                        if (1 != sscanf(&temp[2], "%x", &code))
352                                printf("glyph code?\n");
353                        else
354                                glyphcode[0] = code;
355                        break;
356 
357                    case 'd':
358                        if (1 != sscanf(&temp[2], "%d", &code))
359                                printf("glyph code?\n");
360                        else
361                                glyphcode[0] = code;
362                        break;
363 
364                    case 'h':
365                        if (1 != sscanf(&temp[2], "%d", &h))
366                                printf("height?\n");
367                        vals.pixel = h;
368 		       vals.point = (vals.pixel * DECIPOINTSPERINCH) / vals.y;
369                        rc = Type1OpenScalable(*ev, &fontptr, 0, &entry,
370 			       file, &vals, 0, 0, efactor, slant);
371                        break;
372 
373                    case 'f':
374                        if (1 != sscanf(&temp[2], "%s", file))
375                                printf("file name?\n");
376                        rc = Type1OpenScalable(*ev, &fontptr, 0, &entry,
377 			       file, &vals, 0, 0, efactor, slant);
378                        break;
379 
380                    case 't':
381                        if (1 != sscanf(&temp[2], "%s", file))
382                                printf("file name?\n");
383                        vals.pixel = 8;
384                        rc = Type1OpenScalable(*ev, &fontptr, 0, &entry,
385 			       file, &vals, 0, 0, efactor, slant);
386                        if (rc != Successful) break;
387                        vals.pixel = 20;
388                        rc = Type1OpenScalable(*ev, &fontptr, 0, &entry,
389 			       file, &vals, 0, 0, efactor, slant);
390                        if (rc != Successful) break;
391                        vals.pixel = 50;
392                        rc = Type1OpenScalable(*ev, &fontptr, 0, &entry,
393 			       file, &vals, 0, 0, efactor, slant);
394                        glyphcode[0] = 'A';
395                        printf("From font '%s':\n", file);
396                        break;
397 
398                    case 'q':
399                        return 0;
400 
401                    default:
402                        printf("unknown command '%c', must one of 'ESqfchdxt'\n", temp[0]);
403 
404                }
405                if (rc == Successful) {
406                       if (glyphcode[0] != '\0') {
407                               (*fontptr->get_glyphs)(fontptr, 1, glyphcode, 0, &count, glyphs);
408                               if (count > 0)
409                                       Display(glyphs[0]);
410                               else
411                                       printf("Code %x not valid in this font\n", glyphcode[0]);
412                       }
413                }
414                else
415                       printf("Bad font (rc = %d, file='%s')\n", rc, file);
416        }
417 }
418 
Display(glyph)419 void Display(glyph)
420        CharInfoRec *glyph;
421 {
422        int h,w;
423        unsigned char *p;
424        int data;
425        int i;
426 
427        p = (unsigned char *) glyph->bits;
428 
429        printf("Metrics: left=%d, right=%d, w=%d, above=%d, below=%d\n",
430                glyph->metrics.leftSideBearing,
431                glyph->metrics.rightSideBearing,
432                glyph->metrics.characterWidth,
433                glyph->metrics.ascent,
434                glyph->metrics.descent);
435 
436        for (h=glyph->metrics.ascent + glyph->metrics.descent; --h >= 0;) {
437                w = glyph->metrics.rightSideBearing - glyph->metrics.leftSideBearing;
438                while (w > 0) {
439                        data = *p++;
440                        for (i=0; i<8; i++) {
441                                if (--w < 0)
442                                        break;
443                                if (data & 0x80)
444                                        printf("X");
445                                else
446                                        printf(".");
447                                data <<= 1;
448                        }
449                }
450                printf("\n");
451        }
452 }
453 
T1FillVals(vals)454 T1FillVals(vals)
455     FontScalablePtr vals;
456 {
457     fsResolution *res;
458     int         x_res = DEFAULTRES;
459     int         y_res = DEFAULTRES;
460     int         pointsize = DEFAULTPOINTSIZE;  /* decipoints */
461     int         num_res;
462 
463     /* Must have x, y, and pixel */
464     if (!vals->x || !vals->y || !vals->pixel) {
465         res = (fsResolution *) GetClientResolutions(&num_res);
466         if (num_res) {
467             if (res->x_resolution)
468                 x_res = res->x_resolution;
469             if (res->y_resolution)
470                 y_res = res->y_resolution;
471             if (res->point_size)
472                 pointsize = res->point_size;
473         }
474         if (!vals->x)
475             vals->x = x_res;
476         if (!vals->y)
477             vals->y = y_res;
478         if (!vals->point) {
479             if (!vals->pixel) vals->point = pointsize;
480             else vals->point = (vals->pixel * DECIPOINTSPERINCH) / vals->y;
481         }
482         if (!vals->pixel)
483             vals->pixel = (vals->point * vals->y) / DECIPOINTSPERINCH;
484         /* Make sure above arithmetic is normally in range and will
485            round properly. +++ */
486     }
487 }
488 
CheckFSFormat(format,fmask,bit,byte,scan,glyph,image)489 int CheckFSFormat(format, fmask, bit, byte, scan, glyph, image)
490        int format,fmask,*bit,*byte,*scan,*glyph,*image;
491 {
492        *bit = *byte = 1;
493        *glyph = *scan = *image = 1;
494        return Successful;
495 
496 }
497 
MakeAtom(p)498 char *MakeAtom(p)
499        char *p;
500 {
501        return p;
502 }
GetClientResolutions(resP)503 GetClientResolutions(resP)
504        int *resP;
505 {
506        *resP = 0;
507 };
508 
Xalloc(size)509 char *Xalloc(size)
510        int size;
511 {
512        extern char *malloc();
513        return(malloc(size));
514 }
515 
Xfree()516 void Xfree()
517 {
518        free();
519 }
520 
FontDefaultFormat()521 FontDefaultFormat() { ; }
522 
FontFileRegisterRenderer()523 FontFileRegisterRenderer() { ; }
524 
GenericGetBitmaps()525 GenericGetBitmaps() { ; }
GenericGetExtents()526 GenericGetExtents() { ; }
527 
FontParseXLFDName()528 FontParseXLFDName() { ; }
FontComputeInfoAccelerators()529 FontComputeInfoAccelerators() { ; }
530