3 Copyright 1990, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
30 * Author: Keith Packard, MIT X Consortium
37 #include <X11/fonts/fntfilst.h>
38 #include <X11/fonts/bitmap.h>
39 #include <X11/fonts/bdfint.h>
41 static unsigned char ink_mask_msb[8] = {
42 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01,
45 static unsigned char ink_mask_lsb[8] = {
46 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
50 FontCharInkMetrics(FontPtr pFont, CharInfoPtr pCI, xCharInfo *pInk)
59 bitmapByteWidthPadded;
62 register unsigned char *p;
63 unsigned char *ink_mask = 0;
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))
161 FontCharReshape(FontPtr pFont, CharInfoPtr pSrc, CharInfoPtr pDst)
165 unsigned char *in_line,
167 unsigned char *oldglyph,
179 newglyph = (unsigned char *) pDst->bits;
180 outwidth = pDst->metrics.rightSideBearing - pDst->metrics.leftSideBearing;
181 outheight = pDst->metrics.descent + pDst->metrics.ascent;
182 out_bytes = BYTES_PER_ROW(outwidth, pFont->glyph);
184 oldglyph = (unsigned char *) pSrc->bits;
185 inwidth = pSrc->metrics.rightSideBearing - pSrc->metrics.leftSideBearing;
186 in_bytes = BYTES_PER_ROW(inwidth, pFont->glyph);
188 bzero(newglyph, out_bytes * outheight);
191 y_min = Max(-pSrc->metrics.ascent, -pDst->metrics.ascent);
192 y_max = Min(pSrc->metrics.descent, pDst->metrics.descent);
193 x_min = Max(pSrc->metrics.leftSideBearing, pDst->metrics.leftSideBearing);
194 x_max = Min(pSrc->metrics.rightSideBearing, pDst->metrics.rightSideBearing);
195 in_line += (y_min + pSrc->metrics.ascent) * in_bytes;
196 out_line += (y_min + pDst->metrics.ascent) * out_bytes;
197 if (pFont->bit == MSBFirst) {
198 for (y = y_min; y < y_max; y++) {
199 for (x = x_min; x < x_max; x++) {
200 if (ISBITONMSB(x - pSrc->metrics.leftSideBearing, in_line))
201 SETBITMSB(x - pDst->metrics.leftSideBearing, out_line);
204 out_line += out_bytes;
207 for (y = y_min; y < y_max; y++) {
208 for (x = x_min; x < x_max; x++) {
209 if (ISBITONLSB(x - pSrc->metrics.leftSideBearing, in_line))
210 SETBITLSB(x - pDst->metrics.leftSideBearing, out_line);
213 out_line += out_bytes;