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 ******************************************************************/
50 #ifdef HAVE_DIX_CONFIG_H
51 #include <dix-config.h>
56 #include <X11/Xproto.h>
58 #include <X11/fonts/fontstruct.h>
59 #include "dixfontstr.h"
61 #include "windowstr.h"
62 #include "scrnintstr.h"
63 #include "pixmapstr.h"
64 #include "regionstr.h"
68 this works for fonts with glyphs <= 32 bits wide.
70 the clipping calculations are done for worst-case fonts.
71 we make no assumptions about the heights, widths, or bearings
72 of the glyphs. if we knew that the glyphs are all the same height,
73 we could clip the tops and bottoms per clipping box, rather
74 than per character per clipping box. if we knew that the glyphs'
75 left and right bearings were wlle-behaved, we could clip a single
76 character at the start, output until the last unclipped
77 character, and then clip the last one. this is all straightforward
78 to determine based on max-bounds and min-bounds from the font.
79 there is some inefficiency introduced in the per-character
80 clipping to make what's going on clearer.
82 (it is possible, for example, for a font to be defined in which the
83 next-to-last character in a font would be clipped out, but the last
84 one wouldn't. the code below deals with this.)
89 afbPolyGlyphBlt (pDrawable
, pGC
, x
, y
, nglyph
, ppci
, pglyphBase
)
90 DrawablePtr pDrawable
;
94 CharInfoPtr
*ppci
; /* array of character info */
95 pointer pglyphBase
; /* start of array of glyphs */
97 ExtentInfoRec info
; /* used by QueryGlyphExtents() */
98 BoxRec bbox
; /* string's bounding box */
101 int xorg
, yorg
; /* origin of drawable in bitmap */
102 int widthDst
; /* width of dst in longwords */
104 /* these keep track of the character origin */
106 /* points to longword with character origin */
107 int xchar
; /* xorigin of char (mod 32) */
109 /* these are used for placing the glyph */
110 register int xoff
; /* x offset of left edge of glyph (mod 32) */
111 register PixelType
*pdst
; /* pointer to current longword in dst */
117 int w
; /* width of glyph in bits */
118 int h
; /* height of glyph */
119 int widthGlyph
; /* width of glyph, in bytes */
120 unsigned char *rrops
;
121 register unsigned char *pglyph
;
122 /* pointer to current row of glyph */
123 unsigned char *pglyphSave
;
125 /* used for putting down glyph */
126 register PixelType tmpSrc
;
127 /* for getting bits from glyph */
128 register PixelType startmask
;
129 register PixelType endmask
;
131 register int nFirst
; /* bits of glyph in current longword */
136 afbGetPixelWidthSizeDepthAndPointer(pDrawable
, widthDst
, sizeDst
, depthDst
,
139 QueryGlyphExtents(pGC
->font
, ppci
, (unsigned long)nglyph
, &info
);
144 bbox
.x1
= x
+ info
.overallLeft
;
145 bbox
.x2
= x
+ info
.overallRight
;
146 bbox
.y1
= y
- info
.overallAscent
;
147 bbox
.y2
= y
+ info
.overallDescent
;
149 rrops
= ((afbPrivGCPtr
) pGC
->devPrivates
[afbGCPrivateIndex
].ptr
)->rrops
;
151 switch (RECT_IN_REGION(pGC
->pScreen
, pGC
->pCompositeClip
, &bbox
)) {
155 pdstBase
= afbScanlineNoBankSwitch(pdstBase
, x
, y
, widthDst
);
160 pglyphSave
= FONTGLYPHBITS(pglyphBase
, pci
);
161 w
= pci
->metrics
.rightSideBearing
- pci
->metrics
.leftSideBearing
;
162 hSave
= pci
->metrics
.ascent
+ pci
->metrics
.descent
;
163 widthGlyph
= GLYPHWIDTHBYTESPADDED(pci
);
164 /* start at top scanline of glyph */
165 pdstSave
= afbScanlineDelta(pdstBase
, -pci
->metrics
.ascent
,
168 /* find correct word in scanline and x offset within it
169 for left edge of glyph
171 xoff
= xchar
+ pci
->metrics
.leftSideBearing
;
175 } else if (xoff
< 0) {
180 for (d
= 0; d
< depthDst
; d
++) {
183 pdstSave
+= sizeDst
; /* @@@ NEXT PLANE @@@ */
186 if ((xoff
+ w
) <= PPW
) {
187 /* glyph all in one longword */
188 maskpartialbits(xoff
, w
, startmask
);
192 getleftbits(pglyph
, w
, tmpSrc
);
193 *pdst
|= (SCRRIGHT(tmpSrc
, xoff
) & startmask
);
194 pglyph
+= widthGlyph
;
195 afbScanlineInc(pdst
, widthDst
);
200 getleftbits(pglyph
, w
, tmpSrc
);
201 *pdst
&= ~(SCRRIGHT(tmpSrc
, xoff
) & startmask
);
202 pglyph
+= widthGlyph
;
203 afbScanlineInc(pdst
, widthDst
);
208 getleftbits(pglyph
, w
, tmpSrc
);
209 *pdst
^= (SCRRIGHT(tmpSrc
, xoff
) & startmask
);
210 pglyph
+= widthGlyph
;
211 afbScanlineInc(pdst
, widthDst
);
216 /* glyph crosses longword boundary */
217 maskPPWbits(xoff
, w
, startmask
, endmask
);
222 getleftbits(pglyph
, w
, tmpSrc
);
223 *pdst
|= (SCRRIGHT(tmpSrc
, xoff
) & startmask
);
224 *(pdst
+1) |= (SCRLEFT(tmpSrc
, nFirst
) & endmask
);
225 pglyph
+= widthGlyph
;
226 afbScanlineInc(pdst
, widthDst
);
231 getleftbits(pglyph
, w
, tmpSrc
);
232 *pdst
&= ~(SCRRIGHT(tmpSrc
, xoff
) & startmask
);
233 *(pdst
+1) &= ~(SCRLEFT(tmpSrc
, nFirst
) & endmask
);
234 pglyph
+= widthGlyph
;
235 afbScanlineInc(pdst
, widthDst
);
240 getleftbits(pglyph
, w
, tmpSrc
);
241 *pdst
^= (SCRRIGHT(tmpSrc
, xoff
) & startmask
);
242 *(pdst
+1) ^= (SCRLEFT(tmpSrc
, nFirst
) & endmask
);
243 pglyph
+= widthGlyph
;
244 afbScanlineInc(pdst
, widthDst
);
248 } /* glyph crosses longwords boundary */
250 /* update character origin */
251 x
+= pci
->metrics
.characterWidth
;
252 xchar
+= pci
->metrics
.characterWidth
;
256 } else if (xchar
< 0) {
261 } /* while nglyph-- */
269 int xpos
; /* x position of char origin */
272 int leftEdge
, rightEdge
;
273 int topEdge
, bottomEdge
;
274 int glyphRow
; /* first row of glyph not wholly
276 int glyphCol
; /* leftmost visible column of glyph */
277 #if GETLEFTBITS_ALIGNMENT > 1
278 int getWidth
; /* bits to get from glyph */
281 if(!(ppos
= (afbTEXTPOS
*)ALLOCATE_LOCAL(nglyph
* sizeof(afbTEXTPOS
))))
284 pdstBase
= afbScanlineNoBankSwitch(pdstBase
, x
, y
, widthDst
);
288 for (i
= 0; i
< nglyph
; i
++) {
292 ppos
[i
].xchar
= xchar
;
293 ppos
[i
].leftEdge
= xpos
+ pci
->metrics
.leftSideBearing
;
294 ppos
[i
].rightEdge
= xpos
+ pci
->metrics
.rightSideBearing
;
295 ppos
[i
].topEdge
= y
- pci
->metrics
.ascent
;
296 ppos
[i
].bottomEdge
= y
+ pci
->metrics
.descent
;
297 ppos
[i
].pdstBase
= pdstBase
;
298 ppos
[i
].widthGlyph
= GLYPHWIDTHBYTESPADDED(pci
);
300 xpos
+= pci
->metrics
.characterWidth
;
301 xchar
+= pci
->metrics
.characterWidth
;
305 } else if (xchar
< 0) {
311 cclip
= pGC
->pCompositeClip
;
312 pbox
= REGION_RECTS(cclip
);
313 nbox
= REGION_NUM_RECTS(cclip
);
316 since we continue out of the loop below so often, it
317 is easier to increment pbox at the top than at the end.
318 don't try this at home.
323 clip
.x1
= max(bbox
.x1
, pbox
->x1
);
324 clip
.y1
= max(bbox
.y1
, pbox
->y1
);
325 clip
.x2
= min(bbox
.x2
, pbox
->x2
);
326 clip
.y2
= min(bbox
.y2
, pbox
->y2
);
327 if ((clip
.x2
<=clip
.x1
) || (clip
.y2
<=clip
.y1
))
330 for(i
=0; i
<nglyph
; i
++) {
332 xchar
= ppos
[i
].xchar
;
334 /* clip the left and right edges */
335 if (ppos
[i
].leftEdge
< clip
.x1
)
338 leftEdge
= ppos
[i
].leftEdge
;
340 if (ppos
[i
].rightEdge
> clip
.x2
)
343 rightEdge
= ppos
[i
].rightEdge
;
345 w
= rightEdge
- leftEdge
;
349 /* clip the top and bottom edges */
350 if (ppos
[i
].topEdge
< clip
.y1
)
353 topEdge
= ppos
[i
].topEdge
;
355 if (ppos
[i
].bottomEdge
> clip
.y2
)
356 bottomEdge
= clip
.y2
;
358 bottomEdge
= ppos
[i
].bottomEdge
;
360 hSave
= bottomEdge
- topEdge
;
364 glyphRow
= (topEdge
- y
) + pci
->metrics
.ascent
;
365 widthGlyph
= ppos
[i
].widthGlyph
;
366 pglyphSave
= FONTGLYPHBITS(pglyphBase
, pci
);
367 pglyphSave
+= (glyphRow
* widthGlyph
);
369 glyphCol
= (leftEdge
- ppos
[i
].xpos
) -
370 (pci
->metrics
.leftSideBearing
);
371 #if GETLEFTBITS_ALIGNMENT > 1
372 getWidth
= w
+ glyphCol
;
375 pdstSave
= afbScanlineDelta(ppos
[i
].pdstBase
, -(y
-topEdge
),
377 xoff
= xchar
+ (leftEdge
- ppos
[i
].xpos
);
381 } else if (xoff
< 0) {
386 for (d
= 0; d
< depthDst
; d
++) {
389 pdstSave
+= sizeDst
; /* @@@ NEXT PLANE @@@ */
392 if ((xoff
+ w
) <= PPW
) {
393 maskpartialbits(xoff
, w
, startmask
);
397 getshiftedleftbits(pglyph
, glyphCol
, getWidth
, tmpSrc
);
398 *pdst
|= (SCRRIGHT(tmpSrc
, xoff
) & startmask
);
399 pglyph
+= widthGlyph
;
400 afbScanlineInc(pdst
, widthDst
);
405 getshiftedleftbits(pglyph
, glyphCol
, getWidth
, tmpSrc
);
406 *pdst
&= ~(SCRRIGHT(tmpSrc
, xoff
) & startmask
);
407 pglyph
+= widthGlyph
;
408 afbScanlineInc(pdst
, widthDst
);
413 getshiftedleftbits(pglyph
, glyphCol
, getWidth
, tmpSrc
);
414 *pdst
^= (SCRRIGHT(tmpSrc
, xoff
) & startmask
);
415 pglyph
+= widthGlyph
;
416 afbScanlineInc(pdst
, widthDst
);
421 maskPPWbits(xoff
, w
, startmask
, endmask
);
426 getshiftedleftbits(pglyph
, glyphCol
, getWidth
, tmpSrc
);
427 *pdst
|= (SCRRIGHT(tmpSrc
, xoff
) & startmask
);
428 *(pdst
+1) |= (SCRLEFT(tmpSrc
, nFirst
) & endmask
);
429 pglyph
+= widthGlyph
;
430 afbScanlineInc(pdst
, widthDst
);
435 getshiftedleftbits(pglyph
, glyphCol
, getWidth
, tmpSrc
);
436 *pdst
&= ~(SCRRIGHT(tmpSrc
, xoff
) & startmask
);
437 *(pdst
+1) &= ~(SCRLEFT(tmpSrc
, nFirst
) & endmask
);
438 pglyph
+= widthGlyph
;
439 afbScanlineInc(pdst
, widthDst
);
444 getshiftedleftbits(pglyph
, glyphCol
, getWidth
, tmpSrc
);
445 *pdst
^= (SCRRIGHT(tmpSrc
, xoff
) & startmask
);
446 *(pdst
+1) ^= (SCRLEFT(tmpSrc
, nFirst
) & endmask
);
447 pglyph
+= widthGlyph
;
448 afbScanlineInc(pdst
, widthDst
);
454 } /* for each glyph */
456 DEALLOCATE_LOCAL(ppos
);