1 /* $XConsortium: fontink.c,v 1.4 94/04/17 20:17:14 gildea Exp $ */
5 Copyright (c) 1990 X Consortium
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
26 Except as contained in this notice, the name of the X Consortium shall
27 not be used in advertising or otherwise to promote the sale, use or
28 other dealings in this Software without prior written authorization
29 from the X Consortium.
34 * Author: Keith Packard, MIT X Consortium
39 static unsigned char ink_mask_msb[8] = {
40 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01,
43 static unsigned char ink_mask_lsb[8] = {
44 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
47 FontCharInkMetrics(pFont, pCI, pInk)
59 bitmapByteWidthPadded;
62 register unsigned char *p;
63 unsigned char *ink_mask;
65 register unsigned char charbits;
67 if (pFont->bit == MSBFirst)
68 ink_mask = ink_mask_msb;
69 else if (pFont->bit == LSBFirst)
70 ink_mask = ink_mask_lsb;
71 pInk->characterWidth = pCI->metrics.characterWidth;
72 pInk->attributes = pCI->metrics.attributes;
74 leftBearing = pCI->metrics.leftSideBearing;
75 ascent = pCI->metrics.ascent;
76 descent = pCI->metrics.descent;
77 bitmapBitWidth = GLYPHWIDTHPIXELS(pCI);
78 bitmapByteWidth = GLYPHWIDTHBYTES(pCI);
79 bitmapByteWidthPadded = BYTES_PER_ROW(bitmapBitWidth, pFont->glyph);
80 span = bitmapByteWidthPadded - bitmapByteWidth;
82 p = (unsigned char *) pCI->bits;
83 for (vpos = descent + ascent; --vpos >= 0;) {
84 for (hpos = bitmapByteWidth; --hpos >= 0;) {
91 * special case -- font with no bits gets all zeros
93 pInk->leftSideBearing = leftBearing;
94 pInk->rightSideBearing = leftBearing;
99 pInk->ascent = vpos - descent + 1;
101 p = ((unsigned char *) pCI->bits) + bitmapByteWidthPadded *
102 (descent + ascent - 1) + bitmapByteWidth;
104 for (vpos = descent + ascent; --vpos >= 0;) {
105 for (hpos = bitmapByteWidth; --hpos >= 0;) {
112 pInk->descent = vpos - ascent + 1;
115 for (hpos = 0; hpos < bitmapByteWidth; hpos++) {
117 p = (unsigned char *) pCI->bits + hpos;
118 for (vpos = descent + ascent; --vpos >= 0; p += bitmapByteWidthPadded)
121 if (hpos == bitmapByteWidth - 1)
122 bmax = bitmapBitWidth - (hpos << 3);
124 for (bpos = bmax; --bpos >= 0;) {
131 pInk->leftSideBearing = leftBearing + (hpos << 3) + bmax - bpos - 1;
133 bmax = bitmapBitWidth - ((bitmapByteWidth - 1) << 3);
134 for (hpos = bitmapByteWidth; --hpos >= 0;) {
136 p = (unsigned char *) pCI->bits + hpos;
137 for (vpos = descent + ascent; --vpos >= 0; p += bitmapByteWidthPadded)
141 for (bpos = bmax; --bpos >= 0;) {
149 pInk->rightSideBearing = leftBearing + (hpos << 3) + bpos + 1;
152 #define ISBITONMSB(x, line) ((line)[(x)/8] & (1 << (7-((x)%8))))
153 #define SETBITMSB(x, line) ((line)[(x)/8] |= (1 << (7-((x)%8))))
154 #define ISBITONLSB(x, line) ((line)[(x)/8] & (1 << ((x)%8)))
155 #define SETBITLSB(x, line) ((line)[(x)/8] |= (1 << ((x)%8)))
157 #define Min(a,b) ((a)<(b)?(a):(b))
158 #define Max(a,b) ((a)>(b)?(a):(b))
160 FontCharReshape(pFont, pSrc, pDst)
167 unsigned char *in_line,
169 unsigned char *oldglyph,
181 newglyph = (unsigned char *) pDst->bits;
182 outwidth = pDst->metrics.rightSideBearing - pDst->metrics.leftSideBearing;
183 outheight = pDst->metrics.descent + pDst->metrics.ascent;
184 out_bytes = BYTES_PER_ROW(outwidth, pFont->glyph);
186 oldglyph = (unsigned char *) pSrc->bits;
187 inwidth = pSrc->metrics.rightSideBearing - pSrc->metrics.leftSideBearing;
188 in_bytes = BYTES_PER_ROW(inwidth, pFont->glyph);
190 bzero(newglyph, out_bytes * outheight);
193 y_min = Max(-pSrc->metrics.ascent, -pDst->metrics.ascent);
194 y_max = Min(pSrc->metrics.descent, pDst->metrics.descent);
195 x_min = Max(pSrc->metrics.leftSideBearing, pDst->metrics.leftSideBearing);
196 x_max = Min(pSrc->metrics.rightSideBearing, pDst->metrics.rightSideBearing);
197 in_line += (y_min + pSrc->metrics.ascent) * in_bytes;
198 out_line += (y_min + pDst->metrics.ascent) * out_bytes;
199 if (pFont->bit == MSBFirst) {
200 for (y = y_min; y < y_max; y++) {
201 for (x = x_min; x < x_max; x++) {
202 if (ISBITONMSB(x - pSrc->metrics.leftSideBearing, in_line))
203 SETBITMSB(x - pDst->metrics.leftSideBearing, out_line);
206 out_line += out_bytes;
209 for (y = y_min; y < y_max; y++) {
210 for (x = x_min; x < x_max; x++) {
211 if (ISBITONLSB(x - pSrc->metrics.leftSideBearing, in_line))
212 SETBITLSB(x - pDst->metrics.leftSideBearing, out_line);
215 out_line += out_bytes;