]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/mi/miglblt.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / mi / miglblt.c
1 /***********************************************************
2
3 Copyright (c) 1987  X Consortium
4
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:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
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.
21
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.
25
26
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28
29                         All Rights Reserved
30
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.  
38
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
45 SOFTWARE.
46
47 ******************************************************************/
48
49 /* $XConsortium: miglblt.c,v 5.9 94/04/17 20:27:37 dpw Exp $ */
50
51 #include        "X.h"
52 #include        "Xmd.h"
53 #include        "Xproto.h"
54 #include        "misc.h"
55 #include        "fontstruct.h"
56 #include        "dixfontstr.h"
57 #include        "gcstruct.h"
58 #include        "windowstr.h"
59 #include        "scrnintstr.h"
60 #include        "pixmap.h"
61 #include        "servermd.h"
62
63 /*
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.
69
70     get a scratch GC.
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
74     for each glyph
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
79 */
80
81 void
82 miPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
83     DrawablePtr pDrawable;
84     GC          *pGC;
85     int         x, y;
86     unsigned int nglyph;
87     CharInfoPtr *ppci;          /* array of character info */
88     unsigned char *pglyphBase;  /* start of array of glyphs */
89 {
90     int width, height;
91     PixmapPtr pPixmap;
92     int nbyLine;                        /* bytes per line of padded pixmap */
93     FontPtr pfont;
94     GCPtr pGCtmp;
95     register int i;
96     register int j;
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 */
104
105     XID gcvals[3];
106
107     if (pGC->miTranslate)
108     {
109         x += pDrawable->x;
110         y += pDrawable->y;
111     }
112
113     pfont = pGC->font;
114     width = FONTMAXBOUNDS(pfont,rightSideBearing) - 
115             FONTMINBOUNDS(pfont,leftSideBearing);
116     height = FONTMAXBOUNDS(pfont,ascent) +
117              FONTMAXBOUNDS(pfont,descent);
118
119     pPixmap = (*pDrawable->pScreen->CreatePixmap)(pDrawable->pScreen,
120                                                   width, height, 1);
121     if (!pPixmap)
122         return;
123
124     pGCtmp = GetScratchGC(1, pDrawable->pScreen);
125     if (!pGCtmp)
126     {
127         (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
128         return;
129     }
130
131     gcvals[0] = GXcopy;
132     gcvals[1] = 1;
133     gcvals[2] = 0;
134
135     DoChangeGC(pGCtmp, GCFunction|GCForeground|GCBackground, gcvals, 0);
136
137     nbyLine = BitmapBytePad(width);
138     pbits = (unsigned char *)ALLOCATE_LOCAL(height*nbyLine);
139     if (!pbits)
140     {
141         (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
142         FreeScratchGC(pGCtmp);
143         return;
144     }
145     while(nglyph--)
146     {
147         pci = *ppci++;
148         pglyph = FONTGLYPHBITS(pglyphBase, pci);
149         gWidth = GLYPHWIDTHPIXELS(pci);
150         gHeight = GLYPHHEIGHTPIXELS(pci);
151         if (gWidth && gHeight)
152         {
153             nbyGlyphWidth = GLYPHWIDTHBYTESPADDED(pci);
154             nbyPadGlyph = BitmapBytePad(gWidth);
155
156             if (nbyGlyphWidth == nbyPadGlyph
157 #if GLYPHPADBYTES != 4
158                 && (((int) pglyph) & 3) == 0
159 #endif
160                 )
161             {
162                 pb = pglyph;
163             }
164             else
165             {
166                 for (i=0, pb = pbits; i<gHeight; i++, pb = pbits+(i*nbyPadGlyph))
167                     for (j = 0; j < nbyGlyphWidth; j++)
168                         *pb++ = *pglyph++;
169                 pb = pbits;
170             }
171
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);
178
179             if ((pGC->serialNumber) != (pDrawable->serialNumber))
180                 ValidateGC(pDrawable, pGC);
181             (*pGC->ops->PushPixels)(pGC, pPixmap, pDrawable,
182                                gWidth, gHeight,
183                                x + pci->metrics.leftSideBearing,
184                                y - pci->metrics.ascent);
185         }
186         x += pci->metrics.characterWidth;
187     }
188     (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
189     DEALLOCATE_LOCAL(pbits);
190     FreeScratchGC(pGCtmp);
191 }
192
193
194 void
195 miImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
196     DrawablePtr pDrawable;
197     GC          *pGC;
198     int         x, y;
199     unsigned int nglyph;
200     CharInfoPtr *ppci;          /* array of character info */
201     unsigned char *pglyphBase;  /* start of array of glyphs */
202 {
203     ExtentInfoRec info;         /* used by QueryGlyphExtents() */
204     XID gcvals[3];
205     int oldAlu, oldFS;
206     unsigned long       oldFG;
207     xRectangle backrect;
208
209     QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
210
211     if (info.overallWidth >= 0)
212     {
213         backrect.x = x;
214         backrect.width = info.overallWidth;
215     }
216     else
217     {
218         backrect.x = x + info.overallWidth;
219         backrect.width = -info.overallWidth;
220     }
221     backrect.y = y - FONTASCENT(pGC->font);
222     backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
223
224     oldAlu = pGC->alu;
225     oldFG = pGC->fgPixel;
226     oldFS = pGC->fillStyle;
227
228     /* fill in the background */
229     gcvals[0] = GXcopy;
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);
235
236     /* put down the glyphs */
237     gcvals[0] = oldFG;
238     DoChangeGC(pGC, GCForeground, gcvals, 0);
239     ValidateGC(pDrawable, pGC);
240     (*pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci,
241                               (char *)pglyphBase);
242
243     /* put all the toys away when done playing */
244     gcvals[0] = oldAlu;
245     gcvals[1] = oldFG;
246     gcvals[2] = oldFS;
247     DoChangeGC(pGC, GCFunction|GCForeground|GCFillStyle, gcvals, 0);
248
249 }