1
/* $XFree86: xc/programs/Xserver/afb/afbplygblt.c,v 3.2tsi Exp $ */
2
/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
3
/***********************************************************
5
Copyright (c) 1987 X Consortium
7
Permission is hereby granted, free of charge, to any person obtaining a copy
8
of this software and associated documentation files (the "Software"), to deal
9
in the Software without restriction, including without limitation the rights
10
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
copies of the Software, and to permit persons to whom the Software is
12
furnished to do so, subject to the following conditions:
14
The above copyright notice and this permission notice shall be included in
15
all copies or substantial portions of the Software.
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
Except as contained in this notice, the name of the X Consortium shall not be
25
used in advertising or otherwise to promote the sale, use or other dealings
26
in this Software without prior written authorization from the X Consortium.
29
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
33
Permission to use, copy, modify, and distribute this software and its
34
documentation for any purpose and without fee is hereby granted,
35
provided that the above copyright notice appear in all copies and that
36
both that copyright notice and this permission notice appear in
37
supporting documentation, and that the name of Digital not be
38
used in advertising or publicity pertaining to distribution of the
39
software without specific, written prior permission.
41
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
42
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
43
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
44
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
45
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
46
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
49
******************************************************************/
50
/* $XConsortium: afbimggblt.c,v 5.17 94/04/17 20:28:25 dpw Exp $ */
52
#ifdef HAVE_DIX_CONFIG_H
53
#include <dix-config.h>
58
#include <X11/Xproto.h>
60
#include <X11/fonts/fontstruct.h>
61
#include "dixfontstr.h"
63
#include "windowstr.h"
64
#include "scrnintstr.h"
65
#include "pixmapstr.h"
66
#include "regionstr.h"
70
this works for fonts with glyphs <= 32 bits wide.
72
the clipping calculations are done for worst-case fonts.
73
we make no assumptions about the heights, widths, or bearings
74
of the glyphs. if we knew that the glyphs are all the same height,
75
we could clip the tops and bottoms per clipping box, rather
76
than per character per clipping box. if we knew that the glyphs'
77
left and right bearings were wlle-behaved, we could clip a single
78
character at the start, output until the last unclipped
79
character, and then clip the last one. this is all straightforward
80
to determine based on max-bounds and min-bounds from the font.
81
there is some inefficiency introduced in the per-character
82
clipping to make what's going on clearer.
84
(it is possible, for example, for a font to be defined in which the
85
next-to-last character in a font would be clipped out, but the last
86
one wouldn't. the code below deals with this.)
91
afbPolyGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
92
DrawablePtr pDrawable;
96
CharInfoPtr *ppci; /* array of character info */
97
pointer pglyphBase; /* start of array of glyphs */
99
ExtentInfoRec info; /* used by QueryGlyphExtents() */
100
BoxRec bbox; /* string's bounding box */
103
int xorg, yorg; /* origin of drawable in bitmap */
104
int widthDst; /* width of dst in longwords */
106
/* these keep track of the character origin */
108
/* points to longword with character origin */
109
int xchar; /* xorigin of char (mod 32) */
111
/* these are used for placing the glyph */
112
register int xoff; /* x offset of left edge of glyph (mod 32) */
113
register PixelType *pdst; /* pointer to current longword in dst */
119
int w; /* width of glyph in bits */
120
int h; /* height of glyph */
121
int widthGlyph; /* width of glyph, in bytes */
122
unsigned char *rrops;
123
register unsigned char *pglyph;
124
/* pointer to current row of glyph */
125
unsigned char *pglyphSave;
127
/* used for putting down glyph */
128
register PixelType tmpSrc;
129
/* for getting bits from glyph */
130
register PixelType startmask;
131
register PixelType endmask;
133
register int nFirst; /* bits of glyph in current longword */
138
afbGetPixelWidthSizeDepthAndPointer(pDrawable, widthDst, sizeDst, depthDst,
141
QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
146
bbox.x1 = x + info.overallLeft;
147
bbox.x2 = x + info.overallRight;
148
bbox.y1 = y - info.overallAscent;
149
bbox.y2 = y + info.overallDescent;
151
rrops = ((afbPrivGCPtr) pGC->devPrivates[afbGCPrivateIndex].ptr)->rrops;
153
switch (RECT_IN_REGION(pGC->pScreen, pGC->pCompositeClip, &bbox)) {
157
pdstBase = afbScanlineNoBankSwitch(pdstBase, x, y, widthDst);
162
pglyphSave = FONTGLYPHBITS(pglyphBase, pci);
163
w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
164
hSave = pci->metrics.ascent + pci->metrics.descent;
165
widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
166
/* start at top scanline of glyph */
167
pdstSave = afbScanlineDelta(pdstBase, -pci->metrics.ascent,
170
/* find correct word in scanline and x offset within it
171
for left edge of glyph
173
xoff = xchar + pci->metrics.leftSideBearing;
177
} else if (xoff < 0) {
182
for (d = 0; d < depthDst; d++) {
185
pdstSave += sizeDst; /* @@@ NEXT PLANE @@@ */
188
if ((xoff + w) <= PPW) {
189
/* glyph all in one longword */
190
maskpartialbits(xoff, w, startmask);
194
getleftbits(pglyph, w, tmpSrc);
195
*pdst |= (SCRRIGHT(tmpSrc, xoff) & startmask);
196
pglyph += widthGlyph;
197
afbScanlineInc(pdst, widthDst);
202
getleftbits(pglyph, w, tmpSrc);
203
*pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
204
pglyph += widthGlyph;
205
afbScanlineInc(pdst, widthDst);
210
getleftbits(pglyph, w, tmpSrc);
211
*pdst ^= (SCRRIGHT(tmpSrc, xoff) & startmask);
212
pglyph += widthGlyph;
213
afbScanlineInc(pdst, widthDst);
218
/* glyph crosses longword boundary */
219
maskPPWbits(xoff, w, startmask, endmask);
224
getleftbits(pglyph, w, tmpSrc);
225
*pdst |= (SCRRIGHT(tmpSrc, xoff) & startmask);
226
*(pdst+1) |= (SCRLEFT(tmpSrc, nFirst) & endmask);
227
pglyph += widthGlyph;
228
afbScanlineInc(pdst, widthDst);
233
getleftbits(pglyph, w, tmpSrc);
234
*pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
235
*(pdst+1) &= ~(SCRLEFT(tmpSrc, nFirst) & endmask);
236
pglyph += widthGlyph;
237
afbScanlineInc(pdst, widthDst);
242
getleftbits(pglyph, w, tmpSrc);
243
*pdst ^= (SCRRIGHT(tmpSrc, xoff) & startmask);
244
*(pdst+1) ^= (SCRLEFT(tmpSrc, nFirst) & endmask);
245
pglyph += widthGlyph;
246
afbScanlineInc(pdst, widthDst);
250
} /* glyph crosses longwords boundary */
252
/* update character origin */
253
x += pci->metrics.characterWidth;
254
xchar += pci->metrics.characterWidth;
258
} else if (xchar < 0) {
263
} /* while nglyph-- */
271
int xpos; /* x position of char origin */
274
int leftEdge, rightEdge;
275
int topEdge, bottomEdge;
276
int glyphRow; /* first row of glyph not wholly
278
int glyphCol; /* leftmost visible column of glyph */
279
#if GETLEFTBITS_ALIGNMENT > 1
280
int getWidth; /* bits to get from glyph */
283
if(!(ppos = (afbTEXTPOS *)ALLOCATE_LOCAL(nglyph * sizeof(afbTEXTPOS))))
286
pdstBase = afbScanlineNoBankSwitch(pdstBase, x, y, widthDst);
290
for (i = 0; i < nglyph; i++) {
294
ppos[i].xchar = xchar;
295
ppos[i].leftEdge = xpos + pci->metrics.leftSideBearing;
296
ppos[i].rightEdge = xpos + pci->metrics.rightSideBearing;
297
ppos[i].topEdge = y - pci->metrics.ascent;
298
ppos[i].bottomEdge = y + pci->metrics.descent;
299
ppos[i].pdstBase = pdstBase;
300
ppos[i].widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
302
xpos += pci->metrics.characterWidth;
303
xchar += pci->metrics.characterWidth;
307
} else if (xchar < 0) {
313
cclip = pGC->pCompositeClip;
314
pbox = REGION_RECTS(cclip);
315
nbox = REGION_NUM_RECTS(cclip);
318
since we continue out of the loop below so often, it
319
is easier to increment pbox at the top than at the end.
320
don't try this at home.
325
clip.x1 = max(bbox.x1, pbox->x1);
326
clip.y1 = max(bbox.y1, pbox->y1);
327
clip.x2 = min(bbox.x2, pbox->x2);
328
clip.y2 = min(bbox.y2, pbox->y2);
329
if ((clip.x2<=clip.x1) || (clip.y2<=clip.y1))
332
for(i=0; i<nglyph; i++) {
334
xchar = ppos[i].xchar;
336
/* clip the left and right edges */
337
if (ppos[i].leftEdge < clip.x1)
340
leftEdge = ppos[i].leftEdge;
342
if (ppos[i].rightEdge > clip.x2)
345
rightEdge = ppos[i].rightEdge;
347
w = rightEdge - leftEdge;
351
/* clip the top and bottom edges */
352
if (ppos[i].topEdge < clip.y1)
355
topEdge = ppos[i].topEdge;
357
if (ppos[i].bottomEdge > clip.y2)
358
bottomEdge = clip.y2;
360
bottomEdge = ppos[i].bottomEdge;
362
hSave = bottomEdge - topEdge;
366
glyphRow = (topEdge - y) + pci->metrics.ascent;
367
widthGlyph = ppos[i].widthGlyph;
368
pglyphSave = FONTGLYPHBITS(pglyphBase, pci);
369
pglyphSave += (glyphRow * widthGlyph);
371
glyphCol = (leftEdge - ppos[i].xpos) -
372
(pci->metrics.leftSideBearing);
373
#if GETLEFTBITS_ALIGNMENT > 1
374
getWidth = w + glyphCol;
377
pdstSave = afbScanlineDelta(ppos[i].pdstBase, -(y-topEdge),
379
xoff = xchar + (leftEdge - ppos[i].xpos);
383
} else if (xoff < 0) {
388
for (d = 0; d < depthDst; d++) {
391
pdstSave += sizeDst; /* @@@ NEXT PLANE @@@ */
394
if ((xoff + w) <= PPW) {
395
maskpartialbits(xoff, w, startmask);
399
getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
400
*pdst |= (SCRRIGHT(tmpSrc, xoff) & startmask);
401
pglyph += widthGlyph;
402
afbScanlineInc(pdst, widthDst);
407
getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
408
*pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
409
pglyph += widthGlyph;
410
afbScanlineInc(pdst, widthDst);
415
getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
416
*pdst ^= (SCRRIGHT(tmpSrc, xoff) & startmask);
417
pglyph += widthGlyph;
418
afbScanlineInc(pdst, widthDst);
423
maskPPWbits(xoff, w, startmask, endmask);
428
getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
429
*pdst |= (SCRRIGHT(tmpSrc, xoff) & startmask);
430
*(pdst+1) |= (SCRLEFT(tmpSrc, nFirst) & endmask);
431
pglyph += widthGlyph;
432
afbScanlineInc(pdst, widthDst);
437
getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
438
*pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
439
*(pdst+1) &= ~(SCRLEFT(tmpSrc, nFirst) & endmask);
440
pglyph += widthGlyph;
441
afbScanlineInc(pdst, widthDst);
446
getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
447
*pdst ^= (SCRRIGHT(tmpSrc, xoff) & startmask);
448
*(pdst+1) ^= (SCRLEFT(tmpSrc, nFirst) & endmask);
449
pglyph += widthGlyph;
450
afbScanlineInc(pdst, widthDst);
456
} /* for each glyph */
458
DEALLOCATE_LOCAL(ppos);