1 /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
2 /***********************************************************
4 Copyright (c) 1987 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
28 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
32 Permission to use, copy, modify, and distribute this software and its
33 documentation for any purpose and without fee is hereby granted,
34 provided that the above copyright notice appear in all copies and that
35 both that copyright notice and this permission notice appear in
36 supporting documentation, and that the name of Digital not be
37 used in advertising or publicity pertaining to distribution of the
38 software without specific, written prior permission.
40 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
48 ******************************************************************/
49 /* $XConsortium: mfbimggblt.c,v 5.17 94/04/17 20:28:25 dpw Exp $ */
50 /* $XFree86: xc/programs/Xserver/mfb/mfbimggblt.c,v 3.0 1995/06/14 12:43:46 dawes Exp $ */
55 #include "fontstruct.h"
56 #include "dixfontstr.h"
58 #include "windowstr.h"
59 #include "scrnintstr.h"
60 #include "pixmapstr.h"
61 #include "regionstr.h"
65 we should eventually special-case fixed-width fonts for ImageText.
67 this works for fonts with glyphs <= 32 bits wide.
69 the clipping calculations are done for worst-case fonts.
70 we make no assumptions about the heights, widths, or bearings
71 of the glyphs. if we knew that the glyphs are all the same height,
72 we could clip the tops and bottoms per clipping box, rather
73 than per character per clipping box. if we knew that the glyphs'
74 left and right bearings were wlle-behaved, we could clip a single
75 character at the start, output until the last unclipped
76 character, and then clip the last one. this is all straightforward
77 to determine based on max-bounds and min-bounds from the font.
78 there is some inefficiency introduced in the per-character
79 clipping to make what's going on clearer.
81 (it is possible, for example, for a font to be defined in which the
82 next-to-last character in a font would be clipped out, but the last
83 one wouldn't. the code below deals with this.)
85 Image text looks at the bits in the glyph and the fg and bg in the
86 GC. it paints a rectangle, as defined in the protocol dcoument,
87 and the paints the characters.
89 to avoid source proliferation, this file is compiled
92 mfbImageGlyphBltWhite |=
93 mfbImageGlyphBltBlack &=~
95 the register allocations for startmask and endmask may not
96 be the right thing. are there two other deserving candidates?
97 xoff, pdst, pglyph, and tmpSrc seem like the right things, though.
101 MFBIMAGEGLYPHBLT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
102 DrawablePtr pDrawable;
106 CharInfoPtr *ppci; /* array of character info */
107 pointer pglyphBase; /* start of array of glyphs */
109 ExtentInfoRec info; /* used by QueryGlyphExtents() */
110 BoxRec bbox; /* string's bounding box */
111 xRectangle backrect;/* backing rectangle to paint.
112 in the general case, NOT necessarily
113 the same as the string's bounding box
117 int xorg, yorg; /* origin of drawable in bitmap */
118 int widthDst; /* width of dst in longwords */
120 /* these keep track of the character origin */
122 /* points to longword with character origin */
123 int xchar; /* xorigin of char (mod 32) */
125 /* these are used for placing the glyph */
126 register int xoff; /* x offset of left edge of glyph (mod 32) */
127 register PixelType *pdst;
128 /* pointer to current longword in dst */
130 int w; /* width of glyph in bits */
131 int h; /* height of glyph */
132 int widthGlyph; /* width of glyph, in bytes */
133 register unsigned char *pglyph;
134 /* pointer to current row of glyph */
136 /* used for putting down glyph */
137 register PixelType tmpSrc;
138 /* for getting bits from glyph */
139 register PixelType startmask;
140 register PixelType endmask;
142 register int nFirst;/* bits of glyph in current longword */
143 void (* oldFillArea)();
144 /* we might temporarily usurp this
147 if (!(pGC->planemask & 1))
152 mfbGetPixelWidthAndPointer(pDrawable, widthDst, pdstBase);
154 QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
157 backrect.y = y - FONTASCENT(pGC->font);
158 backrect.width = info.overallWidth;
159 backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
164 bbox.x1 = x + info.overallLeft;
165 bbox.x2 = x + info.overallRight;
166 bbox.y1 = y - info.overallAscent;
167 bbox.y2 = y + info.overallDescent;
170 we know the mfbPolyFillRect uses only three fields in
171 devPrivate[mfbGCPrivateIndex].ptr, two of which (the rotated
172 tile/stipple and the ropFillArea) are
173 irrelevant for solid filling, so we just poke the FillArea
174 field. the GC is now in an inconsistent state, but we'll fix
175 it as soon as PolyFillRect returns. fortunately, the server
179 if you are not using the standard mfbFillRectangle code, you
180 need to poke any fields in the GC the rectangle stuff need
181 (probably alu, fgPixel, and fillStyle) and in devPrivate[mfbGCPrivateIndex].ptr
182 (probably rop or ropFillArea.) You could just call ValidateGC,
183 but that is usually not a cheap thing to do.
186 oldFillArea = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea;
188 /* pcc doesn't like this. why?
189 ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea =
190 ((pGC->bgPixel & 1) ? mfbSolidWhiteArea : mfbSolidBlackArea);
192 if (pGC->bgPixel & 1)
193 ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = mfbSolidWhiteArea;
195 ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = mfbSolidBlackArea;
197 mfbPolyFillRect(pDrawable, pGC, 1, &backrect);
198 ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = oldFillArea;
200 /* the faint-hearted can open their eyes now */
201 switch (RECT_IN_REGION(pGC->pScreen,
202 ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
207 pdstBase = mfbScanlineNoBankSwitch(pdstBase, x, y, widthDst);
213 pglyph = FONTGLYPHBITS(pglyphBase, pci);
214 w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
215 h = pci->metrics.ascent + pci->metrics.descent;
216 widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
218 /* start at top scanline of glyph */
221 /* find correct word in scanline and x offset within it
222 for left edge of glyph
224 xoff = xchar + pci->metrics.leftSideBearing;
236 pdst = mfbScanlineDelta(pdst, -pci->metrics.ascent, widthDst);
238 if ((xoff + w) <= PPW)
240 /* glyph all in one longword */
241 maskpartialbits(xoff, w, startmask);
244 getleftbits(pglyph, w, tmpSrc);
245 *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
246 pglyph += widthGlyph;
247 mfbScanlineInc(pdst, widthDst);
252 /* glyph crosses longword boundary */
253 maskPPWbits(xoff, w, startmask, endmask);
257 getleftbits(pglyph, w, tmpSrc);
258 *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
259 *(pdst+1) OPEQ (SCRLEFT(tmpSrc, nFirst) & endmask);
260 pglyph += widthGlyph;
261 mfbScanlineInc(pdst, widthDst);
263 } /* glyph crosses longwords boundary */
265 /* update character origin */
266 x += pci->metrics.characterWidth;
267 xchar += pci->metrics.characterWidth;
279 } /* while nglyph-- */
287 int xpos; /* x position of char origin */
290 int leftEdge, rightEdge;
291 int topEdge, bottomEdge;
292 int glyphRow; /* first row of glyph not wholly
294 int glyphCol; /* leftmost visible column of glyph */
295 int getWidth; /* bits to get from glyph */
297 if(!(ppos = (TEXTPOS *)ALLOCATE_LOCAL(nglyph * sizeof(TEXTPOS))))
300 pdstBase = mfbScanlineNoBankSwitch(pdstBase, x, y, widthDst);
304 for (i=0; i<nglyph; i++)
309 ppos[i].xchar = xchar;
310 ppos[i].leftEdge = xpos + pci->metrics.leftSideBearing;
311 ppos[i].rightEdge = xpos + pci->metrics.rightSideBearing;
312 ppos[i].topEdge = y - pci->metrics.ascent;
313 ppos[i].bottomEdge = y + pci->metrics.descent;
314 ppos[i].pdstBase = pdstBase;
315 ppos[i].widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
317 xpos += pci->metrics.characterWidth;
318 xchar += pci->metrics.characterWidth;
331 cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
332 pbox = REGION_RECTS(cclip);
333 nbox = REGION_NUM_RECTS(cclip);
336 since we continue out of the loop below so often, it
337 is easier to increment pbox at the top than at the end.
338 don't try this at home.
344 clip.x1 = max(bbox.x1, pbox->x1);
345 clip.y1 = max(bbox.y1, pbox->y1);
346 clip.x2 = min(bbox.x2, pbox->x2);
347 clip.y2 = min(bbox.y2, pbox->y2);
348 if ((clip.x2<=clip.x1) || (clip.y2<=clip.y1))
351 for(i=0; i<nglyph; i++)
354 xchar = ppos[i].xchar;
356 /* clip the left and right edges */
357 if (ppos[i].leftEdge < clip.x1)
360 leftEdge = ppos[i].leftEdge;
362 if (ppos[i].rightEdge > clip.x2)
365 rightEdge = ppos[i].rightEdge;
367 w = rightEdge - leftEdge;
371 /* clip the top and bottom edges */
372 if (ppos[i].topEdge < clip.y1)
375 topEdge = ppos[i].topEdge;
377 if (ppos[i].bottomEdge > clip.y2)
378 bottomEdge = clip.y2;
380 bottomEdge = ppos[i].bottomEdge;
382 h = bottomEdge - topEdge;
386 glyphRow = (topEdge - y) + pci->metrics.ascent;
387 widthGlyph = ppos[i].widthGlyph;
388 pglyph = FONTGLYPHBITS(pglyphBase, pci);
389 pglyph += (glyphRow * widthGlyph);
391 pdst = ppos[i].pdstBase;
393 glyphCol = (leftEdge - ppos[i].xpos) -
394 (pci->metrics.leftSideBearing);
395 getWidth = w + glyphCol;
396 xoff = xchar + (leftEdge - ppos[i].xpos);
408 pdst = mfbScanlineDelta(pdst, -(y-topEdge), widthDst);
410 if ((xoff + w) <= PPW)
412 maskpartialbits(xoff, w, startmask);
415 getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
416 *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
417 pglyph += widthGlyph;
418 mfbScanlineInc(pdst, widthDst);
423 maskPPWbits(xoff, w, startmask, endmask);
427 getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
428 *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
429 *(pdst+1) OPEQ (SCRLEFT(tmpSrc, nFirst) & endmask);
430 pglyph += widthGlyph;
431 mfbScanlineInc(pdst, widthDst);
434 } /* for each glyph */
436 DEALLOCATE_LOCAL(ppos);