1 /***********************************************************
2
3 Copyright 1987, 1998 The Open Group
4
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
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
26
27 All Rights Reserved
28
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
36
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43 SOFTWARE.
44
45 ******************************************************************/
46
47 #ifdef HAVE_DIX_CONFIG_H
48 #include <dix-config.h>
49 #endif
50
51 #include <X11/X.h>
52 #include <X11/Xmd.h>
53 #include <X11/Xproto.h>
54 #include "misc.h"
55 #include <X11/fonts/fontstruct.h>
56 #include <X11/fonts/libxfont2.h>
57 #include "dixfontstr.h"
58 #include "gcstruct.h"
59 #include "windowstr.h"
60 #include "scrnintstr.h"
61 #include "pixmap.h"
62 #include "servermd.h"
63 #include "mi.h"
64
65 /*
66 machine-independent glyph blt.
67 assumes that glyph bits in snf are written in bytes,
68 have same bit order as the server's bitmap format,
69 and are byte padded. this corresponds to the snf distributed
70 with the sample server.
71
72 get a scratch GC.
73 in the scratch GC set alu = GXcopy, fg = 1, bg = 0
74 allocate a bitmap big enough to hold the largest glyph in the font
75 validate the scratch gc with the bitmap
76 for each glyph
77 carefully put the bits of the glyph in a buffer,
78 padded to the server pixmap scanline padding rules
79 fake a call to PutImage from the buffer into the bitmap
80 use the bitmap in a call to PushPixels
81 */
82
83 void
miPolyGlyphBlt(DrawablePtr pDrawable,GC * pGC,int x,int y,unsigned int nglyph,CharInfoPtr * ppci,void * pglyphBase)84 miPolyGlyphBlt(DrawablePtr pDrawable, GC * pGC, int x, int y, unsigned int nglyph, CharInfoPtr * ppci, /* array of character info */
85 void *pglyphBase /* start of array of glyphs */
86 )
87 {
88 int width, height;
89 PixmapPtr pPixmap;
90 int nbyLine; /* bytes per line of padded pixmap */
91 FontPtr pfont;
92 GCPtr pGCtmp;
93 int i;
94 int j;
95 unsigned char *pbits; /* buffer for PutImage */
96 unsigned char *pb; /* temp pointer into buffer */
97 CharInfoPtr pci; /* current char info */
98 unsigned char *pglyph; /* pointer bits in glyph */
99 int gWidth, gHeight; /* width and height of glyph */
100 int nbyGlyphWidth; /* bytes per scanline of glyph */
101 int nbyPadGlyph; /* server padded line of glyph */
102
103 ChangeGCVal gcvals[3];
104
105 if (pGC->miTranslate) {
106 x += pDrawable->x;
107 y += pDrawable->y;
108 }
109
110 pfont = pGC->font;
111 width = FONTMAXBOUNDS(pfont, rightSideBearing) -
112 FONTMINBOUNDS(pfont, leftSideBearing);
113 height = FONTMAXBOUNDS(pfont, ascent) + FONTMAXBOUNDS(pfont, descent);
114
115 pPixmap = (*pDrawable->pScreen->CreatePixmap) (pDrawable->pScreen,
116 width, height, 1,
117 CREATE_PIXMAP_USAGE_SCRATCH);
118 if (!pPixmap)
119 return;
120
121 pGCtmp = GetScratchGC(1, pDrawable->pScreen);
122 if (!pGCtmp) {
123 (*pDrawable->pScreen->DestroyPixmap) (pPixmap);
124 return;
125 }
126
127 gcvals[0].val = GXcopy;
128 gcvals[1].val = 1;
129 gcvals[2].val = 0;
130
131 ChangeGC(NullClient, pGCtmp, GCFunction | GCForeground | GCBackground,
132 gcvals);
133
134 nbyLine = BitmapBytePad(width);
135 pbits = xallocarray(height, nbyLine);
136 if (!pbits) {
137 (*pDrawable->pScreen->DestroyPixmap) (pPixmap);
138 FreeScratchGC(pGCtmp);
139 return;
140 }
141 while (nglyph--) {
142 pci = *ppci++;
143 pglyph = FONTGLYPHBITS(pglyphBase, pci);
144 gWidth = GLYPHWIDTHPIXELS(pci);
145 gHeight = GLYPHHEIGHTPIXELS(pci);
146 if (gWidth && gHeight) {
147 nbyGlyphWidth = GLYPHWIDTHBYTESPADDED(pci);
148 nbyPadGlyph = BitmapBytePad(gWidth);
149
150 if (nbyGlyphWidth == nbyPadGlyph
151 #if GLYPHPADBYTES != 4
152 && (((int) pglyph) & 3) == 0
153 #endif
154 ) {
155 pb = pglyph;
156 }
157 else {
158 for (i = 0, pb = pbits; i < gHeight;
159 i++, pb = pbits + (i * nbyPadGlyph))
160 for (j = 0; j < nbyGlyphWidth; j++)
161 *pb++ = *pglyph++;
162 pb = pbits;
163 }
164
165 if ((pGCtmp->serialNumber) != (pPixmap->drawable.serialNumber))
166 ValidateGC((DrawablePtr) pPixmap, pGCtmp);
167 (*pGCtmp->ops->PutImage) ((DrawablePtr) pPixmap, pGCtmp,
168 pPixmap->drawable.depth,
169 0, 0, gWidth, gHeight,
170 0, XYBitmap, (char *) pb);
171
172 (*pGC->ops->PushPixels) (pGC, pPixmap, pDrawable,
173 gWidth, gHeight,
174 x + pci->metrics.leftSideBearing,
175 y - pci->metrics.ascent);
176 }
177 x += pci->metrics.characterWidth;
178 }
179 (*pDrawable->pScreen->DestroyPixmap) (pPixmap);
180 free(pbits);
181 FreeScratchGC(pGCtmp);
182 }
183
184 void
miImageGlyphBlt(DrawablePtr pDrawable,GC * pGC,int x,int y,unsigned int nglyph,CharInfoPtr * ppci,void * pglyphBase)185 miImageGlyphBlt(DrawablePtr pDrawable, GC * pGC, int x, int y, unsigned int nglyph, CharInfoPtr * ppci, /* array of character info */
186 void *pglyphBase /* start of array of glyphs */
187 )
188 {
189 ExtentInfoRec info; /* used by xfont2_query_glyph_extents() */
190 ChangeGCVal gcvals[3];
191 int oldAlu, oldFS;
192 unsigned long oldFG;
193 xRectangle backrect;
194
195 xfont2_query_glyph_extents(pGC->font, ppci, (unsigned long) nglyph, &info);
196
197 if (info.overallWidth >= 0) {
198 backrect.x = x;
199 backrect.width = info.overallWidth;
200 }
201 else {
202 backrect.x = x + info.overallWidth;
203 backrect.width = -info.overallWidth;
204 }
205 backrect.y = y - FONTASCENT(pGC->font);
206 backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
207
208 oldAlu = pGC->alu;
209 oldFG = pGC->fgPixel;
210 oldFS = pGC->fillStyle;
211
212 /* fill in the background */
213 gcvals[0].val = GXcopy;
214 gcvals[1].val = pGC->bgPixel;
215 gcvals[2].val = FillSolid;
216 ChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFillStyle, gcvals);
217 ValidateGC(pDrawable, pGC);
218 (*pGC->ops->PolyFillRect) (pDrawable, pGC, 1, &backrect);
219
220 /* put down the glyphs */
221 gcvals[0].val = oldFG;
222 ChangeGC(NullClient, pGC, GCForeground, gcvals);
223 ValidateGC(pDrawable, pGC);
224 (*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
225
226 /* put all the toys away when done playing */
227 gcvals[0].val = oldAlu;
228 gcvals[1].val = oldFG;
229 gcvals[2].val = oldFS;
230 ChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFillStyle, gcvals);
231 ValidateGC(pDrawable, pGC);
232
233 }
234