|
|
1.1 root 1: /* $Header: XTextExt16.c,v 11.11 87/09/08 00:22:20 toddb Exp $ */
2: /************************************************************************
3: Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
4: and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
5:
6: All Rights Reserved
7:
8: Permission to use, copy, modify, and distribute this software and its
9: documentation for any purpose and without fee is hereby granted,
10: provided that the above copyright notice appear in all copies and that
11: both that copyright notice and this permission notice appear in
12: supporting documentation, and that the names of Digital or MIT not be
13: used in advertising or publicity pertaining to distribution of the
14: software without specific, written prior permission.
15:
16: DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
17: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
18: DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
19: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
22: SOFTWARE.
23:
24: ************************************************************************/
25:
26: #define NEED_REPLIES
27:
28: #include "Xlibint.h"
29:
30: /* text support routines. Three different access methods, a */
31: /* charinfo array builder, and a bounding box calculator */
32: /*ARGSUSED*/
33: static XCharStruct *GetCS16(min_bounds, pCS, firstCol, numCols,
34: firstRow, numRows, ind, chars, chDefault)
35: XCharStruct *min_bounds;
36: XCharStruct pCS[];
37: unsigned int firstCol, numCols, firstRow, numRows, ind, chDefault;
38: XChar2b *chars;
39: {
40: XCharStruct *cs;
41: unsigned int c;
42:
43: c = (chars[ind].byte1 << 8 + chars[ind].byte2) - firstCol;
44: if (c < numCols) {
45: if ( pCS == NULL ) return min_bounds;
46: cs = &pCS[c];
47: if (! (cs->attributes & CI_NONEXISTCHAR)) return cs;
48: }
49: c = chDefault - firstCol;
50: if (c >= numCols) return NULL;
51: if ( pCS == NULL ) return min_bounds;
52: cs = &pCS[c];
53: if (! (cs->attributes & CI_NONEXISTCHAR)) return cs;
54: return NULL;
55: }
56:
57:
58: static
59: XCharStruct *GetCS162d(min_bounds, pCS, firstCol, numCols, firstRow, numRows,
60: ind, chars, chDefault)
61: XCharStruct *min_bounds;
62: XCharStruct pCS[];
63: unsigned int firstCol, numCols, firstRow, numRows, ind, chDefault;
64: XChar2b *chars;
65: {
66: XCharStruct *cs;
67: unsigned int row, col, c;
68:
69: row = chars[ind].byte1 - firstRow;
70: col = chars[ind].byte2 - firstCol;
71: if ((row < numRows) && (col < numCols)) {
72: if ( pCS == NULL ) return min_bounds;
73: c = row*numCols + col;
74: cs = &pCS[c];
75: if (! (cs->attributes & CI_NONEXISTCHAR)) return cs;
76: }
77: row = (chDefault >> 8)-firstRow;
78: col = (chDefault & 0xff)-firstCol;
79: if ((row >= numRows) || (col >= numCols)) return NULL;
80: if ( pCS == NULL ) return min_bounds;
81: c = row*numCols + col;
82: cs = &pCS[c];
83: if (! (cs->attributes & CI_NONEXISTCHAR)) return cs;
84: return NULL;
85: }
86:
87:
88: static void
89: GetGlyphs(font, count, chars, getGlyph, glyphcount, glyphs)
90: XFontStruct *font;
91: int count;
92: XChar2b *chars;
93: XCharStruct *(*getGlyph)();
94: unsigned int *glyphcount; /* RETURN */
95: XCharStruct *glyphs[]; /* RETURN */
96: {
97: unsigned int firstCol = font->min_char_or_byte2;
98: unsigned int numCols = font->max_char_or_byte2 - firstCol + 1;
99: unsigned int firstRow = font->min_byte1;
100: unsigned int numRows = font->max_byte1 - firstRow + 1;
101: unsigned int chDefault = font->default_char;
102: int i, n;
103: XCharStruct *cs;
104:
105: n = 0;
106: for (i=0; i < count; i++) {
107: cs = (* getGlyph)(
108: &font->min_bounds, font->per_char, firstCol, numCols, firstRow, numRows,
109: i, chars, chDefault);
110: if (cs != NULL) glyphs[n++] = cs;
111: }
112: *glyphcount = n;
113: }
114:
115: XTextExtents16 (fontstruct, string, nchars, dir, font_ascent, font_descent,
116: overall)
117: XFontStruct *fontstruct;
118: XChar2b *string;
119: register int nchars;
120: int *dir;
121: int *font_ascent, *font_descent;
122: register XCharStruct *overall;
123: {
124: int i;
125: unsigned int n;
126:
127: *dir = fontstruct->direction;
128: *font_ascent = fontstruct->ascent;
129: *font_descent = fontstruct->descent;
130:
131: {
132: XCharStruct **charstruct =
133: (XCharStruct **)Xmalloc((unsigned) nchars*sizeof(XCharStruct *));
134:
135: if (fontstruct->max_byte1 == 0)
136: GetGlyphs(fontstruct, nchars, string, GetCS16, &n, charstruct);
137: else
138: GetGlyphs(fontstruct, nchars, string, GetCS162d, &n, charstruct);
139:
140: if (n != 0) {
141:
142: overall->ascent = charstruct[0]->ascent;
143: overall->descent = charstruct[0]->descent;
144: overall->width = charstruct[0]->width;
145: overall->lbearing = charstruct[0]->lbearing;
146: overall->rbearing = charstruct[0]->rbearing;
147:
148: for (i=1; i < n; i++) {
149: overall->ascent = max(
150: overall->ascent,
151: charstruct[i]->ascent);
152: overall->descent = max(
153: overall->descent,
154: charstruct[i]->descent);
155: overall->lbearing = min(
156: overall->lbearing,
157: overall->width+charstruct[i]->lbearing);
158: overall->rbearing = max(
159: overall->rbearing,
160: overall->width+charstruct[i]->rbearing);
161: overall->width += charstruct[i]->width;
162: }
163:
164: } else {
165:
166: overall->ascent = 0;
167: overall->descent = 0;
168: overall->width = 0;
169: overall->lbearing = 0;
170: overall->rbearing = 0;
171: }
172:
173: Xfree((char *)charstruct);
174: }
175:
176: return (1);
177: }
178:
179: int XTextWidth16 (fontstruct, string, count)
180: XFontStruct *fontstruct;
181: XChar2b *string;
182: int count;
183: {
184: int i, width;
185: unsigned int n;
186:
187: {
188: XCharStruct **charstruct =
189: (XCharStruct **)Xmalloc((unsigned)count*sizeof(XCharStruct *));
190:
191: if (fontstruct->max_byte1 == 0)
192: GetGlyphs(fontstruct, count, string, GetCS16, &n, charstruct);
193: else
194: GetGlyphs(fontstruct, count, string, GetCS162d, &n, charstruct);
195:
196: if (n != 0) {
197: width = 0;
198: for (i=0; i < n; i++) {
199: width += charstruct[i]->width;
200: }
201:
202: } else {
203: width = 0;
204: }
205:
206: Xfree((char *)charstruct);
207:
208: }
209: return (width);
210: }
211:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.