1 /* $TOG: spinfo.c /main/17 1997/06/09 14:19:24 barstow $ */
3 * Copyright 1990, 1991 Network Computing Devices;
4 * Portions Copyright 1987 by Digital Equipment Corporation
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the names of Network Computing Devices or Digital
11 * not be used in advertising or publicity pertaining to distribution of
12 * the software without specific, written prior permission.
14 * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
15 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16 * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
17 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 * Author: Dave Lemke, Network Computing Devices, Inc
27 Copyright (c) 1987 X Consortium
29 Permission is hereby granted, free of charge, to any person obtaining
30 a copy of this software and associated documentation files (the
31 "Software"), to deal in the Software without restriction, including
32 without limitation the rights to use, copy, modify, merge, publish,
33 distribute, sublicense, and/or sell copies of the Software, and to
34 permit persons to whom the Software is furnished to do so, subject to
35 the following conditions:
37 The above copyright notice and this permission notice shall be included
38 in all copies or substantial portions of the Software.
40 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
41 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
43 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
44 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
45 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
46 OTHER DEALINGS IN THE SOFTWARE.
48 Except as contained in this notice, the name of the X Consortium shall
49 not be used in advertising or otherwise to promote the sale, use or
50 other dealings in this Software without prior written authorization
51 from the X Consortium.
59 /* percentage of pointsize used to specify ascent & descent */
60 #define STRETCH_FACTOR 120
63 atom, truncate_atom, pixel_size, point_size, resolution_x,
64 resolution_y, average_width
67 typedef struct _fontProp {
73 static fontProp fontNamePropTable[] = {
75 "FAMILY_NAME", 0, atom,
76 "WEIGHT_NAME", 0, atom,
78 "SETWIDTH_NAME", 0, atom,
79 "ADD_STYLE_NAME", 0, atom,
80 "PIXEL_SIZE", 0, pixel_size,
81 "POINT_SIZE", 0, point_size,
82 "RESOLUTION_X", 0, resolution_x,
83 "RESOLUTION_Y", 0, resolution_y,
85 "AVERAGE_WIDTH", 0, average_width,
86 "CHARSET_REGISTRY", 0, atom,
87 "CHARSET_ENCODING", 0, truncate_atom,
90 /* Warning: following array is closely related to the sequence of
93 static fontProp extraProps[] = {
96 "RAW_PIXEL_SIZE", 0, 0,
97 "RAW_POINT_SIZE", 0, 0,
100 "RAW_AVERAGE_WIDTH", 0, 0,
103 /* this is a bit kludgy */
105 #define COPYRIGHTPROP 1
106 #define RAWPIXELPROP 2
107 #define RAWPOINTPROP 3
108 #define RAWASCENTPROP 4
109 #define RAWDESCENTPROP 5
110 #define RAWWIDTHPROP 6
113 #define NNAMEPROPS (sizeof(fontNamePropTable) / sizeof(fontProp))
114 #define NEXTRAPROPS (sizeof(extraProps) / sizeof(fontProp))
116 #define NPROPS (NNAMEPROPS + NEXTRAPROPS)
119 sp_make_standard_props()
124 i = sizeof(fontNamePropTable) / sizeof(fontProp);
125 for (t = fontNamePropTable; i; i--, t++)
126 t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
127 i = sizeof(extraProps) / sizeof(fontProp);
128 for (t = extraProps; i; i--, t++)
129 t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
133 sp_make_header(spf, pinfo)
138 SpeedoMasterFontPtr spmf = spf->master;
140 pinfo->firstCol = spmf->first_char_id & 0xff;
141 pinfo->firstRow = spmf->first_char_id >> 8;
142 pinfo->lastCol = spmf->max_id & 0xff;
143 pinfo->lastRow = spmf->max_id >> 8;
145 /* XXX -- hackery here */
146 pinfo->defaultCh = 0;
147 /* computed by FontComputeInfoAccelerators:
154 pinfo->inkMetrics = 0;
156 pinfo->drawDirection = LeftToRight;
158 if (spf->specs.xxmult != spf->specs.yymult)
159 pinfo->anamorphic = TRUE;
161 pinfo->anamorphic = FALSE;
162 /* computed by sp_compute_bounds:
169 pixel_size = spf->vals.pixel_matrix[3] * STRETCH_FACTOR / 100;
170 pinfo->fontAscent = pixel_size * 764 / 1000; /* 764 == EM_TOP */
171 pinfo->fontDescent = pixel_size - pinfo->fontAscent;
175 adjust_min_max(minc, maxc, tmp)
180 #define MINMAX(field,ci) \
181 if (minc->field > (ci)->field) \
182 minc->field = (ci)->field; \
183 if (maxc->field < (ci)->field) \
184 maxc->field = (ci)->field;
187 MINMAX(descent, tmp);
188 MINMAX(leftSideBearing, tmp);
189 MINMAX(rightSideBearing, tmp);
190 MINMAX(characterWidth, tmp);
192 if ((INT16)minc->attributes > (INT16)tmp->attributes)
193 minc->attributes = tmp->attributes;
194 if ((INT16)maxc->attributes < (INT16)tmp->attributes)
195 maxc->attributes = tmp->attributes;
202 sp_compute_bounds(spf, pinfo, flags, sWidth)
220 SpeedoMasterFontPtr spmf = spf->master;
224 firstChar = spmf->first_char_id;
225 minchar.ascent = minchar.descent =
226 minchar.leftSideBearing = minchar.rightSideBearing =
227 minchar.characterWidth = minchar.attributes = 32767;
228 maxchar.ascent = maxchar.descent =
229 maxchar.leftSideBearing = maxchar.rightSideBearing =
230 maxchar.characterWidth = maxchar.attributes = -32767;
233 for (i = 0; i < spmf->num_chars; i++) {
237 index = spmf->enc[i * 2 + 1];
238 char_id = spmf->enc[i * 2];
240 * See if this character is in the list of ranges specified in the
243 for (j = 0; j < spf->vals.nranges; j++)
244 if (char_id >= mincharno(spf->vals.ranges[j]) &&
245 char_id <= maxcharno(spf->vals.ranges[j]))
247 if (spf->vals.nranges && j == spf->vals.nranges)
251 if (!(flags & ComputeBoundsOnly)) {
253 width = sp_get_char_width(index);
255 /* convert to pixel coords */
256 pix_width = (int)width * (spf->specs.xxmult / 65536L) +
257 ((int) width * (spf->specs.xxmult % 65536L))
261 (void) sp_get_char_bbox(index, &bbox);
262 bbox.ymax = (bbox.ymax + 32768L) >> 16;
263 bbox.ymin = (bbox.ymin + 32768L) >> 16;
264 bbox.xmin = (bbox.xmin + 32768L) >> 16;
265 bbox.xmax = (bbox.xmax + 32768L) >> 16;
266 tmpchar.ascent = bbox.ymax;
267 tmpchar.descent = -bbox.ymin;
268 tmpchar.characterWidth = (int)(pix_width + /* round */
269 (pix_width > 0 ? 0.5 : -0.5));
270 tmpchar.rightSideBearing = bbox.xmax;
271 tmpchar.leftSideBearing = bbox.xmin;
273 if (!tmpchar.characterWidth &&
274 tmpchar.ascent == -tmpchar.descent &&
275 tmpchar.rightSideBearing == tmpchar.leftSideBearing)
277 /* Character appears non-existent, probably as a result
278 of the transformation. Let's give it one pixel in
279 the universe so it's not mistaken for non-existent. */
280 tmpchar.leftSideBearing = tmpchar.descent = 0;
281 tmpchar.rightSideBearing = tmpchar.ascent = 1;
284 tmpchar.attributes = (int)((double)(int)width / 65.536 + .5);
287 tmpchar = spf->encoding[char_id - firstChar].metrics;
289 adjust_min_max(&minchar, &maxchar, &tmpchar);
290 overlap = tmpchar.rightSideBearing - tmpchar.characterWidth;
291 if (maxOverlap < overlap)
292 maxOverlap = overlap;
294 total_width += ((int)(INT16)tmpchar.attributes);
295 *sWidth += abs((int)(INT16)tmpchar.attributes);
297 if (flags & SaveMetrics) {
298 id = spmf->enc[i * 2] - firstChar;
299 assert(id <= spmf->max_id - firstChar);
300 spf->encoding[id].metrics = tmpchar;
307 *sWidth = (int)(((double)*sWidth * 10.0 + (double)num_chars / 2.0) /
311 /* Predominant direction is R->L */
314 spf->vals.width = (int)((double)*sWidth * spf->vals.pixel_matrix[0] /
316 (spf->vals.pixel_matrix[0] > 0 ? .5 : -.5));
322 pinfo->maxbounds = maxchar;
323 pinfo->minbounds = minchar;
324 pinfo->ink_maxbounds = maxchar;
325 pinfo->ink_minbounds = minchar;
326 pinfo->maxOverlap = maxOverlap;
330 sp_compute_props(spf, fontname, pinfo, sWidth)
345 FontScalableRec tmpvals;
347 nprops = pinfo->nprops = NPROPS;
348 pinfo->isStringProp = (char *) xalloc(sizeof(char) * nprops);
349 pinfo->props = (FontPropPtr) xalloc(sizeof(FontPropRec) * nprops);
350 if (!pinfo->isStringProp || !pinfo->props) {
351 xfree(pinfo->isStringProp);
352 pinfo->isStringProp = (char *) 0;
354 pinfo->props = (FontPropPtr) 0;
357 bzero(pinfo->isStringProp, (sizeof(char) * nprops));
360 for (i = NNAMEPROPS, pp = pinfo->props, fpt = fontNamePropTable,
361 is_str = pinfo->isStringProp;
363 i--, pp++, fpt++, is_str++) {
368 if (!(ptr2 = strchr(ptr1, '-'))) ptr2 = strchr(ptr1, '\0');
371 pp->name = fpt->atom;
375 pp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);
379 for (ptr3 = ptr1; *ptr3; ptr3++)
382 pp->value = MakeAtom(ptr1, ptr3 - ptr1, TRUE);
385 pp->value = (int)(spf->vals.pixel_matrix[3] +
386 (spf->vals.pixel_matrix[3] > 0 ? .5 : -.5));
389 pp->value = (int)(spf->vals.point_matrix[3] * 10.0 +
390 (spf->vals.point_matrix[3] > 0 ? .5 : -.5));
393 pp->value = spf->vals.x;
396 pp->value = spf->vals.y;
399 pp->value = spf->vals.width;
404 for (i = 0, fpt = extraProps; i < NEXTRAPROPS; i++, is_str++, pp++, fpt++) {
405 pp->name = fpt->atom;
409 strcpy(tmpname, fontname);
410 FontParseXLFDName(tmpname, &tmpvals, FONT_XLFD_REPLACE_ZERO);
411 FontParseXLFDName(tmpname, &spf->vals, FONT_XLFD_REPLACE_VALUE);
412 pp->value = MakeAtom(tmpname, strlen(tmpname), TRUE);
416 pp->value = MakeAtom(spf->master->copyright,
417 strlen(spf->master->copyright), TRUE);
425 pp->value = (long)(72270.0 / (double)spf->vals.y + .5);
429 pp->value = STRETCH_FACTOR * 764 / 100;
433 pp->value = STRETCH_FACTOR * 236 / 100;