]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/font/Type1/t1test.c
672da509a35e54fe8fc5a765df52f378b4eb6c72
[rdpsrv] / Xserver / lib / font / Type1 / t1test.c
1 /* $XConsortium: t1test.c /main/4 1996/09/28 16:47:53 rws $ */
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 "fntfilst.h"
32 #include "FSproto.h"
33  
34 void Display();
35  
36 #define DECIPOINTSPERINCH 722.7
37 #define DEFAULTRES 75
38 #define DEFAULTPOINTSIZE 120
39  
40 FontScalableRec vals;
41 FontEntryRec entry;
42  
43 int main(argc, argv)
44        int argc;
45        char *argv[];
46 {
47        int h;
48        char temp[80];
49        char file[80];
50        char glyphcode[1];
51        FontPtr fontptr;
52        CharInfoRec *glyphs[1];
53        int count;
54        int code;
55        int rc = -1;
56  
57        T1FillVals(&vals);
58        Type1RegisterFontFileFunctions();
59        entry.name.name = "-adobe-utopia-medium-r-normal--0-0-0-0-p-0-iso8859-1";
60  
61        for (;;) {
62                printf("T1TEST: ");
63                gets(temp);
64                glyphcode[0] = '\0';
65  
66                switch(temp[0]) {
67  
68                    case 'c':
69                        if (1 != sscanf(&temp[2], "%c", glyphcode))
70                                printf("glyph code?\n");
71                        break;
72  
73                    case 'x':
74                        if (1 != sscanf(&temp[2], "%x", &code))
75                                printf("glyph code?\n");
76                        else
77                                glyphcode[0] = code;
78                        break;
79  
80                    case 'd':
81                        if (1 != sscanf(&temp[2], "%d", &code))
82                                printf("glyph code?\n");
83                        else
84                                glyphcode[0] = code;
85                        break;
86  
87                    case 'h':
88                        if (1 != sscanf(&temp[2], "%d", &h))
89                                printf("height?\n");
90                        vals.pixel = h;
91                        rc = Type1OpenScalable(NULL, &fontptr, 0, &entry, file, &vals, 0, 0);
92                        break;
93  
94                    case 'f':
95                        if (1 != sscanf(&temp[2], "%s", file))
96                                printf("file name?\n");
97                        rc = Type1OpenScalable(NULL, &fontptr, 0, &entry, file, &vals, 0, 0);
98                        break;
99  
100                    case 't':
101                        if (1 != sscanf(&temp[2], "%s", file))
102                                printf("file name?\n");
103                        vals.pixel = 8;
104                        rc = Type1OpenScalable(NULL, &fontptr, 0, &entry, file, &vals, 0, 0);
105                        if (rc != Successful) break;
106                        vals.pixel = 20;
107                        rc = Type1OpenScalable(NULL, &fontptr, 0, &entry, file, &vals, 0, 0);
108                        if (rc != Successful) break;
109                        vals.pixel = 50;
110                        rc = Type1OpenScalable(NULL, &fontptr, 0, &entry, file, &vals, 0, 0);
111                        glyphcode[0] = 'A';
112                        printf("From font '%s':\n", file);
113                        break;
114  
115                    case 'q':
116                        return 0;
117  
118                    default:
119                        printf("unknown command '%c', must one of 'qfchdxt'\n", temp[0]);
120  
121                }
122                if (rc == Successful) {
123                       if (glyphcode[0] != '\0') {
124                               (*fontptr->get_glyphs)(fontptr, 1, glyphcode, 0, &count, glyphs);
125                               if (count > 0)
126                                       Display(glyphs[0]);
127                               else
128                                       printf("Code %x not valid in this font\n", glyphcode[0]);
129                       }
130                }
131                else
132                       printf("Bad font (rc = %d, file='%s')\n", rc, file);
133        }
134 }
135  
136 static void Display(glyph)
137        CharInfoRec *glyph;
138 {
139        int h,w;
140        unsigned char *p;
141        int data;
142        int i;
143  
144        p = glyph->bits;
145  
146        printf("Metrics: left=%d, right=%d, w=%d, above=%d, below=%d\n",
147                glyph->metrics.leftSideBearing,
148                glyph->metrics.rightSideBearing,
149                glyph->metrics.characterWidth,
150                glyph->metrics.ascent,
151                glyph->metrics.descent);
152  
153        for (h=glyph->metrics.ascent + glyph->metrics.descent; --h >= 0;) {
154                w = glyph->metrics.rightSideBearing - glyph->metrics.leftSideBearing;
155                while (w > 0) {
156                        data = *p++;
157                        for (i=0; i<8; i++) {
158                                if (--w < 0)
159                                        break;
160                                if (data & 0x80)
161                                        printf("X");
162                                else
163                                        printf(".");
164                                data <<= 1;
165                        }
166                }
167                printf("\n");
168        }
169 }
170  
171 T1FillVals(vals)
172     FontScalablePtr vals;
173 {
174     FontResolutionPtr res;
175     int         x_res = DEFAULTRES;
176     int         y_res = DEFAULTRES;
177     int         pointsize = DEFAULTPOINTSIZE;  /* decipoints */
178     int         num_res;
179  
180     /* Must have x, y, and pixel */
181     if (!vals->x || !vals->y || !vals->pixel) {
182         res = GetClientResolutions(&num_res);
183         if (num_res) {
184             if (res->x_resolution)
185                 x_res = res->x_resolution;
186             if (res->y_resolution)
187                 y_res = res->y_resolution;
188             if (res->point_size)
189                 pointsize = res->point_size;
190         }
191         if (!vals->x)
192             vals->x = x_res;
193         if (!vals->y)
194             vals->y = y_res;
195         if (!vals->point) {
196             if (!vals->pixel) vals->point = pointsize;
197             else vals->point = (vals->pixel * DECIPOINTSPERINCH) / vals->y;
198         }
199         if (!vals->pixel)
200             vals->pixel = (vals->point * vals->y) / DECIPOINTSPERINCH;
201         /* Make sure above arithmetic is normally in range and will
202            round properly. +++ */
203     }
204 }
205  
206 int CheckFSFormat(format, fmask, bit, byte, scan, glyph, image)
207        int format,fmask,*bit,*byte,*scan,*glyph,*image;
208 {
209        *bit = *byte = 1;
210        *glyph = *scan = *image = 1;
211        return Successful;
212  
213 }
214  
215 char *MakeAtom(p)
216        char *p;
217 {
218        return p;
219 }
220
221
222 FontResolutionPtr GetClientResolutions(resP)
223        int *resP;
224 {
225        *resP = 0;
226 };
227  
228 char *Xalloc(size)
229        int size;
230 {
231        extern char *malloc();
232        return(malloc(size));
233 }
234  
235 void Xfree()
236 {
237        free();
238 }
239  
240 FontDefaultFormat() { ; }
241  
242 FontFileRegisterRenderer() { ; }
243  
244 GenericGetBitmaps() { ; }
245 GenericGetExtents() { ; }
246  
247 FontParseXLFDName() { ; }
248 FontComputeInfoAccelerators() { ; }