Debian Codegraph @

texk/ps2pk/t1info.c

raw
1 /* $XConsortium: t1info.c,v 1.9 92/03/20 16:00:13 eswu Exp $ */
2 /* Copyright International Business Machines,Corp. 1991
3 * All Rights Reserved
4 *
5 * License, subject to the license given below, to use,
6 * copy, modify, and distribute this software * and its
7 * documentation for any purpose and without fee is hereby
8 * granted, provided that the above copyright notice appear
9 * in all copies and that both that copyright notice and
10 * this permission notice appear in supporting documentation,
11 * and that the name of IBM not be used in advertising or
12 * publicity pertaining to distribution of the software
13 * without specific, written prior permission.
14 *
15 * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
16 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
17 * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
19 * THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE QUALITY AND
20 * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
21 * OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF
22 * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
23 * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN
24 * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
25 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
26 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
27 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
28 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29 * SOFTWARE.
30 *
31 * Author: Carol H. Thompson IBM Almaden Research Center
32 * Modeled on spinfo.c by Dave Lemke, Network Computing Devices, Inc
33 * which contains the following copyright and permission notices:
34 *
35 * Copyright 1990, 1991 Network Computing Devices;
36 * Portions Copyright 1987 by Digital Equipment Corporation and the
37 * Massachusetts Institute of Technology
38 *
39 * Permission to use, copy, modify, and distribute this protoype software
40 * and its documentation to Members and Affiliates of the MIT X Consortium
41 * any purpose and without fee is hereby granted, provided
42 * that the above copyright notice appear in all copies and that both that
43 * copyright notice and this permission notice appear in supporting
44 * documentation, and that the names of Network Computing Devices, Digital or
45 * MIT not be used in advertising or publicity pertaining to distribution of
46 * the software without specific, written prior permission.
47 *
48 * NETWORK COMPUTING DEVICES, DIGITAL AND MIT DISCLAIM ALL WARRANTIES WITH
49 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
50 * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, DIGITAL OR MIT BE
51 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
52 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
53 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
54 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
55 */
56
57 #include "types.h"
58 #include <stdio.h>
59 #include <string.h>
60 #include "util.h"
61 #include "ffilest.h"
62 #ifdef XSERVER
63 #include "FSproto.h"
64 #endif
65 #include "t1intf.h"
66
67 #ifdef WIN32
68 static void FontParseXLFDName(char *, FontScalablePtr, int);
69 #endif
70 static void FontComputeInfoAccelerators(FontInfoPtr);
71
72 #define DECIPOINTSPERINCH 722.7
73 #define DEFAULTRES 75
74 #define DEFAULTPOINTSIZE 120
75
76 enum scaleType {
77 atom, pixel_size, point_size, resolution_x, resolution_y,
78 average_width, scaledX, scaledY, unscaled, scaledXoverY,
79 uncomputed
80 };
81
82 typedef struct _fontProp {
83 const char *name;
84 int32_t atom;
85 enum scaleType type;
86 } fontProp;
87
88 static fontProp fontNamePropTable[] = { /* Example: */
89 { "FOUNDRY", 0, atom }, /* adobe */
90 { "FAMILY_NAME", 0, atom }, /* times roman */
91 { "WEIGHT_NAME", 0, atom }, /* bold */
92 { "SLANT", 0, atom }, /* i */
93 { "SETWIDTH_NAME", 0, atom }, /* normal */
94 { "ADD_STYLE_NAME", 0, atom }, /* */
95 { "PIXEL_SIZE", 0, pixel_size }, /* 18 */
96 { "POINT_SIZE", 0, point_size }, /* 180 */
97 { "RESOLUTION_X", 0, resolution_x }, /* 72 */
98 { "RESOLUTION_Y", 0, resolution_y }, /* 72 */
99 { "SPACING", 0, atom }, /* p */
100 { "AVERAGE_WIDTH", 0, average_width }, /* 0 */
101 { "CHARSET_REGISTRY", 0, atom }, /* ISO8859 */
102 { "CHARSET_ENCODING", 0, atom } /* 1 */
103 };
104
105 static fontProp extraProps[] = {
106 { "FONT", 0, atom },
107 { "COPYRIGHT", 0, atom }
108 };
109
110 /* this is a bit kludgy */
111 #define FONTPROP 0
112 #define COPYRIGHTPROP 1
113
114 #define NNAMEPROPS (sizeof(fontNamePropTable) / sizeof(fontProp))
115 #define NEXTRAPROPS (sizeof(extraProps) / sizeof(fontProp))
116
117 #define NPROPS (NNAMEPROPS + NEXTRAPROPS)
118
119 /*ARGSUSED*/
120 static void
121 FillHeader(
122 FontInfoPtr pInfo,
123 FontScalablePtr Vals)
124 {
125 /* OpenScalable in T1FUNCS sets the following:
126 pInfo->firstCol,
127 pInfo->firstRow,
128 pInfo->lastCol, and
129 pInfo->lastRow. */
130 /* the following are ununsed
131 pInfo->pad. */
132
133 /* Items we should handle better someday +++ */
134 pInfo->defaultCh = 0;
135 pInfo->drawDirection = LeftToRight;
136 /* our size is based only on Vals->pixel, so we won't
137 create an anamorphic font (yet) */
138 pInfo->anamorphic = 0;
139 pInfo->inkMetrics = 0; /* no ink metrics here */
140 pInfo->cachable = 1; /* no licensing (yet) */
141 }
142
143 static void
144 adjust_min_max(xCharInfo *minc, xCharInfo *maxc, xCharInfo *tmp)
145 {
146 #define MINMAX(field,ci) \
147 if (minc->field > (ci)->field) \
148 minc->field = (ci)->field; \
149 if (maxc->field < (ci)->field) \
150 maxc->field = (ci)->field;
151
152 MINMAX(ascent, tmp);
153 MINMAX(descent, tmp);
154 MINMAX(leftSideBearing, tmp);
155 MINMAX(rightSideBearing, tmp);
156 MINMAX(characterWidth, tmp);
157
158 #undef MINMAX
159 }
160
161 static void
162 ComputeBounds(
163 FontInfoPtr pInfo,
164 CharInfoPtr pChars,
165 FontScalablePtr Vals)
166 {
167 int i;
168 xCharInfo minchar, maxchar;
169 int32_t width = 0;
170 int numchars = 0;
171 int totchars;
172 int overlap;
173 int maxlap;
174
175 minchar.ascent = minchar.descent =
176 minchar.leftSideBearing = minchar.rightSideBearing =
177 minchar.characterWidth = 32767;
178 minchar.attributes = 0; /* What's this for? +++ */
179 maxchar.ascent = maxchar.descent =
180 maxchar.leftSideBearing = maxchar.rightSideBearing =
181 maxchar.characterWidth = -32767;
182 maxchar.attributes = 0;
183
184 maxlap = -32767;
185 totchars = pInfo->lastCol - pInfo->firstCol + 1;
186 pInfo->allExist = 1;
187 for (i = 0; i < totchars; i++,pChars++) {
188 xCharInfo *pmetrics = &pChars->metrics;
189
190 if (pmetrics->characterWidth) {
191 width += pmetrics->characterWidth;
192 numchars++;
193 adjust_min_max(&minchar, &maxchar, pmetrics);
194 overlap = pmetrics->rightSideBearing - pmetrics->characterWidth;
195 if (overlap > maxlap) maxlap = overlap;
196 }
197 else pInfo->allExist = 0;
198 }
199
200 Vals->width = ((width * 10)+((numchars+1)/2)) / numchars;
201 /* (We think the above average width value should be put into
202 the Vals structure. This may be wrong, and the proper
203 behavior might be to regard the values in Vals as sacred,
204 and for us to squirrel the computed number in a static, and
205 then use that static in ComputeStdProps.) */
206 pInfo->maxbounds = maxchar;
207 pInfo->minbounds = minchar;
208 pInfo->ink_maxbounds = maxchar;
209 pInfo->ink_minbounds = minchar;
210 pInfo->maxOverlap = maxlap + -(minchar.leftSideBearing);
211
212 /* Set the pInfo flags */
213 /* Properties set by FontComputeInfoAccelerators:
214 pInfo->noOverlap;
215 pInfo->terminalFont;
216 pInfo->constantMetrics;
217 pInfo->constantWidth;
218 pInfo->inkInside;
219
220 */
221 FontComputeInfoAccelerators (pInfo);
222 }
223
224 static void
225 ComputeProps(
226 FontInfoPtr pInfo,
227 FontScalablePtr Vals,
228 char *Filename)
229 {
230 int infoint;
231 int infoBBox[4];
232 int rc;
233
234 QueryFontLib(Filename, "isFixedPitch", &infoint, &rc);
235 if (!rc) {
236 pInfo->constantWidth = infoint;
237 }
238 QueryFontLib((char *)0, "FontBBox", infoBBox, &rc);
239 if (!rc) {
240 pInfo->fontAscent = (infoBBox[3] * Vals->pixel) / 1000;
241 pInfo->fontDescent = - (infoBBox[1] * Vals->pixel) / 1000;
242 }
243 }
244
245 static void
246 ComputeStdProps(
247 FontInfoPtr pInfo,
248 FontScalablePtr Vals,
249 char *Filename,
250 const char *Fontname)
251 {
252 FontPropPtr pp;
253 int i,
254 nprops;
255 fontProp *fpt;
256 char *is_str;
257 char *ptr1,
258 *ptr2;
259 const char *infostrP;
260 int rc;
261 char scaledName[MAXFONTNAMELEN];
262
263 strcpy (scaledName, Fontname);
264 #ifdef WIN32
265 /* Fill in our copy of the fontname from the Vals structure */
266 FontParseXLFDName (scaledName, Vals, FONT_XLFD_REPLACE_VALUE);
267 #endif
268
269 /* This form of the properties is used by the X-client; the X-server
270 doesn't care what they are. */
271 nprops = pInfo->nprops = NPROPS;
272 pInfo->isStringProp = (char *) Xalloc(sizeof(char) * nprops);
273 pInfo->props = (FontPropPtr) Xalloc(sizeof(FontPropRec) * nprops);
274 if (!pInfo->isStringProp || !pInfo->props) {
275 Xfree(pInfo->isStringProp);
276 pInfo->isStringProp = (char *) 0;
277 Xfree(pInfo->props);
278 pInfo->props = (FontPropPtr) 0;
279 return;
280 }
281 (void) memset(pInfo->isStringProp, 0, (sizeof(char) * nprops));
282
283 ptr2 = scaledName;
284 for (i = NNAMEPROPS, pp = pInfo->props, fpt = fontNamePropTable, is_str = pInfo->isStringProp;
285 i;
286 i--, pp++, fpt++, is_str++) {
287 ptr1 = ptr2 + 1;
288 if (*ptr1 == '-')
289 ptr2 = ptr1;
290 else {
291 if (i > 1)
292 ptr2 = strchr(ptr1 + 1, '-');
293 else
294 ptr2 = strchr(ptr1 + 1, '\0');
295 }
296 pp->name = fpt->atom;
297 switch (fpt->type) {
298 case atom: /* Just copy info from scaledName */
299 *is_str = TRUE;
300 pp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);
301 break;
302 case pixel_size:
303 pp->value = Vals->pixel;
304 break;
305 case point_size:
306 pp->value = Vals->point;
307 break;
308 case resolution_x:
309 pp->value = Vals->x;
310 break;
311 case resolution_y:
312 pp->value = Vals->y;
313 break;
314 case average_width:
315 pp->value = Vals->width;
316 break;
317 default: /* scaledX, scaledY, unscaled, scaledXoverY, and uncomputed */
318 break;
319 }
320 }
321
322 for (i = 0, fpt = extraProps;
323 i < NEXTRAPROPS;
324 i++, is_str++, pp++, fpt++) {
325 pp->name = fpt->atom;
326 switch (i) {
327 case FONTPROP:
328 /* Why do we need this property -- nice for debug anyway */
329 *is_str = TRUE;
330 pp->value = MakeAtom(scaledName, strlen(scaledName), TRUE);
331 break;
332 case COPYRIGHTPROP:
333 *is_str = TRUE;
334 QueryFontLib(Filename, "Notice", &infostrP, &rc);
335 if (rc || !infostrP) {
336 infostrP = "Copyright Notice not available";
337 }
338 pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
339 break;
340 }
341 }
342 }
343
344 void
345 T1FillFontInfo(
346 FontPtr pFont,
347 FontScalablePtr Vals,
348 char *Filename,
349 const char *Fontname)
350 {
351 FontInfoPtr pInfo = &pFont->info;
352 struct type1font *p = (struct type1font *)pFont->fontPrivate;
353
354 FillHeader(pInfo, Vals);
355
356 ComputeBounds(pInfo, p->glyphs, Vals);
357
358 ComputeProps(pInfo, Vals, Filename);
359 ComputeStdProps(pInfo, Vals, Filename, Fontname);
360 }
361
362 /* Called once, at renderer registration time */
363 void
364 T1InitStdProps(void)
365 {
366 int i;
367 fontProp *t;
368
369 i = sizeof(fontNamePropTable) / sizeof(fontProp);
370 for (t = fontNamePropTable; i; i--, t++)
371 t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
372 i = sizeof(extraProps) / sizeof(fontProp);
373 for (t = extraProps; i; i--, t++)
374 t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
375 }
376
377 #ifdef WIN32
378 static void FontParseXLFDName(char *scaledName, FontScalablePtr Vals, int foo) { ; }
379 #endif
380 static void FontComputeInfoAccelerators(FontInfoPtr foo) { ; }