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