1 /***********************************************************
3 Copyright (c) 1987 X Consortium
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 ******************************************************************/
49 /* $XConsortium: miglblt.c,v 5.9 94/04/17 20:27:37 dpw Exp $ */
55 #include "fontstruct.h"
56 #include "dixfontstr.h"
58 #include "windowstr.h"
59 #include "scrnintstr.h"
64 machine-independent glyph blt.
65 assumes that glyph bits in snf are written in bytes,
66 have same bit order as the server's bitmap format,
67 and are byte padded. this corresponds to the snf distributed
68 with the sample server.
71 in the scratch GC set alu = GXcopy, fg = 1, bg = 0
72 allocate a bitmap big enough to hold the largest glyph in the font
73 validate the scratch gc with the bitmap
75 carefully put the bits of the glyph in a buffer,
76 padded to the server pixmap scanline padding rules
77 fake a call to PutImage from the buffer into the bitmap
78 use the bitmap in a call to PushPixels
82 miPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
83 DrawablePtr pDrawable;
87 CharInfoPtr *ppci; /* array of character info */
88 unsigned char *pglyphBase; /* start of array of glyphs */
92 int nbyLine; /* bytes per line of padded pixmap */
97 unsigned char *pbits; /* buffer for PutImage */
98 register unsigned char *pb; /* temp pointer into buffer */
99 register CharInfoPtr pci; /* currect char info */
100 register unsigned char *pglyph; /* pointer bits in glyph */
101 int gWidth, gHeight; /* width and height of glyph */
102 register int nbyGlyphWidth; /* bytes per scanline of glyph */
103 int nbyPadGlyph; /* server padded line of glyph */
107 if (pGC->miTranslate)
114 width = FONTMAXBOUNDS(pfont,rightSideBearing) -
115 FONTMINBOUNDS(pfont,leftSideBearing);
116 height = FONTMAXBOUNDS(pfont,ascent) +
117 FONTMAXBOUNDS(pfont,descent);
119 pPixmap = (*pDrawable->pScreen->CreatePixmap)(pDrawable->pScreen,
124 pGCtmp = GetScratchGC(1, pDrawable->pScreen);
127 (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
135 DoChangeGC(pGCtmp, GCFunction|GCForeground|GCBackground, gcvals, 0);
137 nbyLine = BitmapBytePad(width);
138 pbits = (unsigned char *)ALLOCATE_LOCAL(height*nbyLine);
141 (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
142 FreeScratchGC(pGCtmp);
148 pglyph = FONTGLYPHBITS(pglyphBase, pci);
149 gWidth = GLYPHWIDTHPIXELS(pci);
150 gHeight = GLYPHHEIGHTPIXELS(pci);
151 if (gWidth && gHeight)
153 nbyGlyphWidth = GLYPHWIDTHBYTESPADDED(pci);
154 nbyPadGlyph = BitmapBytePad(gWidth);
156 if (nbyGlyphWidth == nbyPadGlyph
157 #if GLYPHPADBYTES != 4
158 && (((int) pglyph) & 3) == 0
166 for (i=0, pb = pbits; i<gHeight; i++, pb = pbits+(i*nbyPadGlyph))
167 for (j = 0; j < nbyGlyphWidth; j++)
172 if ((pGCtmp->serialNumber) != (pPixmap->drawable.serialNumber))
173 ValidateGC((DrawablePtr)pPixmap, pGCtmp);
174 (*pGCtmp->ops->PutImage)((DrawablePtr)pPixmap, pGCtmp,
175 pPixmap->drawable.depth,
176 0, 0, gWidth, gHeight,
177 0, XYBitmap, (char *)pb);
179 if ((pGC->serialNumber) != (pDrawable->serialNumber))
180 ValidateGC(pDrawable, pGC);
181 (*pGC->ops->PushPixels)(pGC, pPixmap, pDrawable,
183 x + pci->metrics.leftSideBearing,
184 y - pci->metrics.ascent);
186 x += pci->metrics.characterWidth;
188 (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
189 DEALLOCATE_LOCAL(pbits);
190 FreeScratchGC(pGCtmp);
195 miImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
196 DrawablePtr pDrawable;
200 CharInfoPtr *ppci; /* array of character info */
201 unsigned char *pglyphBase; /* start of array of glyphs */
203 ExtentInfoRec info; /* used by QueryGlyphExtents() */
209 QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
211 if (info.overallWidth >= 0)
214 backrect.width = info.overallWidth;
218 backrect.x = x + info.overallWidth;
219 backrect.width = -info.overallWidth;
221 backrect.y = y - FONTASCENT(pGC->font);
222 backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
225 oldFG = pGC->fgPixel;
226 oldFS = pGC->fillStyle;
228 /* fill in the background */
230 gcvals[1] = pGC->bgPixel;
231 gcvals[2] = FillSolid;
232 DoChangeGC(pGC, GCFunction|GCForeground|GCFillStyle, gcvals, 0);
233 ValidateGC(pDrawable, pGC);
234 (*pGC->ops->PolyFillRect)(pDrawable, pGC, 1, &backrect);
236 /* put down the glyphs */
238 DoChangeGC(pGC, GCForeground, gcvals, 0);
239 ValidateGC(pDrawable, pGC);
240 (*pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci,
243 /* put all the toys away when done playing */
247 DoChangeGC(pGC, GCFunction|GCForeground|GCFillStyle, gcvals, 0);