1
/* $XFree86: xc/programs/Xserver/ilbm/ilbmimggblt.c,v 3.0 1996/08/18 01:53:57 dawes 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: ilbmimggblt.c,v 5.17 94/04/17 20:28:25 dpw Exp $ */
52
/* Modified jun 95 by Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
53
to use interleaved bitplanes instead of normal bitplanes */
55
#ifdef HAVE_DIX_CONFIG_H
56
#include <dix-config.h>
61
#include <X11/Xproto.h>
63
#include <X11/fonts/fontstruct.h>
64
#include "dixfontstr.h"
66
#include "windowstr.h"
67
#include "scrnintstr.h"
68
#include "pixmapstr.h"
69
#include "regionstr.h"
73
we should eventually special-case fixed-width fonts for ImageText.
75
this works for fonts with glyphs <= 32 bits wide.
77
the clipping calculations are done for worst-case fonts.
78
we make no assumptions about the heights, widths, or bearings
79
of the glyphs. if we knew that the glyphs are all the same height,
80
we could clip the tops and bottoms per clipping box, rather
81
than per character per clipping box. if we knew that the glyphs'
82
left and right bearings were wlle-behaved, we could clip a single
83
character at the start, output until the last unclipped
84
character, and then clip the last one. this is all straightforward
85
to determine based on max-bounds and min-bounds from the font.
86
there is some inefficiency introduced in the per-character
87
clipping to make what's going on clearer.
89
(it is possible, for example, for a font to be defined in which the
90
next-to-last character in a font would be clipped out, but the last
91
one wouldn't. the code below deals with this.)
93
Image text looks at the bits in the glyph and the fg and bg in the
94
GC. it paints a rectangle, as defined in the protocol dcoument,
95
and the paints the characters.
97
the register allocations for startmask and endmask may not
98
be the right thing. are there two other deserving candidates?
99
xoff, pdst, pglyph, and tmpSrc seem like the right things, though.
103
ilbmImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
104
DrawablePtr pDrawable;
108
CharInfoPtr *ppci; /* array of character info */
109
pointer pglyphBase; /* start of array of glyphs */
111
ExtentInfoRec info; /* used by QueryGlyphExtents() */
112
BoxRec bbox; /* string's bounding box */
113
xRectangle backrect;/* backing rectangle to paint.
114
in the general case, NOT necessarily
115
the same as the string's bounding box
119
int xorg, yorg; /* origin of drawable in bitmap */
120
int widthDst; /* width of dst in longwords */
122
/* these keep track of the character origin */
124
/* points to longword with character origin */
125
int xchar; /* xorigin of char (mod 32) */
127
/* these are used for placing the glyph */
128
register int xoff; /* x offset of left edge of glyph (mod 32) */
129
register PixelType *pdst;
130
/* pointer to current longword in dst */
136
int w; /* width of glyph in bits */
137
int h; /* height of glyph */
138
int widthGlyph; /* width of glyph, in bytes */
139
unsigned char rrops[AFB_MAX_DEPTH];
140
register unsigned char *pglyph;
141
/* pointer to current row of glyph */
142
unsigned char *pglyphSave;
144
/* used for putting down glyph */
145
register PixelType tmpSrc;
146
/* for getting bits from glyph */
147
register PixelType startmask;
148
register PixelType endmask;
150
register int nFirst;/* bits of glyph in current longword */
153
ilbmPrivGC *pPriv = (ilbmPrivGC *)(pGC->devPrivates[ilbmGCPrivateIndex].ptr);
157
ilbmGetPixelWidthAuxDepthAndPointer(pDrawable, widthDst, auxDst, depthDst,
160
QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
163
backrect.y = y - FONTASCENT(pGC->font);
164
backrect.width = info.overallWidth;
165
backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
170
bbox.x1 = x + info.overallLeft;
171
bbox.x2 = x + info.overallRight;
172
bbox.y1 = y - info.overallAscent;
173
bbox.y2 = y + info.overallDescent;
175
oldFill = pGC->fillStyle;
176
pGC->fillStyle = FillSolid;
177
ilbmReduceRop (pGC->alu, pGC->bgPixel, pGC->planemask, pGC->depth,
179
ilbmPolyFillRect(pDrawable, pGC, 1, &backrect);
180
pGC->fillStyle = oldFill;
181
ilbmReduceRop (pGC->alu, pGC->fgPixel, pGC->planemask, pGC->depth,
183
ilbmReduceRop (GXcopy, pGC->fgPixel, pGC->planemask, pGC->depth, rrops);
185
/* the faint-hearted can open their eyes now */
187
switch (RECT_IN_REGION(pGC->pScreen, pGC->pCompositeClip, &bbox)) {
191
pdstBase = ilbmScanlineNoBankSwitch(pdstBase, x, y, auxDst);
196
pglyphSave = FONTGLYPHBITS(pglyphBase, pci);
197
w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
198
hSave = pci->metrics.ascent + pci->metrics.descent;
199
widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
200
/* start at top scanline of glyph */
201
pdstSave = ilbmScanlineDelta(pdstBase, -pci->metrics.ascent,
204
/* find correct word in scanline and x offset within it
205
for left edge of glyph
207
xoff = xchar + pci->metrics.leftSideBearing;
211
} else if (xoff < 0) {
216
for (d = 0; d < depthDst; d++) {
219
pdstSave += widthDst; /* @@@ NEXT PLANE @@@ */
222
if ((xoff + w) <= PPW) {
223
/* glyph all in one longword */
224
maskpartialbits(xoff, w, startmask);
229
getleftbits(pglyph, w, tmpSrc);
230
*pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
231
pglyph += widthGlyph;
232
ilbmScanlineInc(pdst, auxDst);
237
getleftbits(pglyph, w, tmpSrc);
238
*pdst |= SCRRIGHT(tmpSrc, xoff) & startmask;
239
pglyph += widthGlyph;
240
ilbmScanlineInc(pdst, auxDst);
247
/* glyph crosses longword boundary */
248
maskPPWbits(xoff, w, startmask, endmask);
254
getleftbits(pglyph, w, tmpSrc);
255
*pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
256
*(pdst+1) &= ~(SCRLEFT(tmpSrc, nFirst) & endmask);
257
pglyph += widthGlyph;
258
ilbmScanlineInc(pdst, auxDst);
263
getleftbits(pglyph, w, tmpSrc);
264
*pdst |= SCRRIGHT(tmpSrc, xoff) & startmask;
265
*(pdst+1) |= SCRLEFT(tmpSrc, nFirst) & endmask;
266
pglyph += widthGlyph;
267
ilbmScanlineInc(pdst, auxDst);
273
} /* glyph crosses longwords boundary */
275
/* update character origin */
276
x += pci->metrics.characterWidth;
277
xchar += pci->metrics.characterWidth;
281
} else if (xchar < 0) {
286
} /* while nglyph-- */
294
int xpos; /* x position of char origin */
297
int leftEdge, rightEdge;
298
int topEdge, bottomEdge;
299
int glyphRow; /* first row of glyph not wholly
301
int glyphCol; /* leftmost visible column of glyph */
302
int getWidth; /* bits to get from glyph */
304
if (!(ppos = (ilbmTEXTPOS *)ALLOCATE_LOCAL(nglyph *
305
sizeof(ilbmTEXTPOS))))
308
pdstBase = ilbmScanlineNoBankSwitch(pdstBase, x, y, auxDst);
312
for (i = 0; i < nglyph; i++) {
316
ppos[i].xchar = xchar;
317
ppos[i].leftEdge = xpos + pci->metrics.leftSideBearing;
318
ppos[i].rightEdge = xpos + pci->metrics.rightSideBearing;
319
ppos[i].topEdge = y - pci->metrics.ascent;
320
ppos[i].bottomEdge = y + pci->metrics.descent;
321
ppos[i].pdstBase = pdstBase;
322
ppos[i].widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
324
xpos += pci->metrics.characterWidth;
325
xchar += pci->metrics.characterWidth;
329
} else if (xchar < 0) {
335
cclip = pGC->pCompositeClip;
336
pbox = REGION_RECTS(cclip);
337
nbox = REGION_NUM_RECTS(cclip);
340
since we continue out of the loop below so often, it
341
is easier to increment pbox at the top than at the end.
342
don't try this at home.
347
clip.x1 = max(bbox.x1, pbox->x1);
348
clip.y1 = max(bbox.y1, pbox->y1);
349
clip.x2 = min(bbox.x2, pbox->x2);
350
clip.y2 = min(bbox.y2, pbox->y2);
351
if ((clip.x2<=clip.x1) || (clip.y2<=clip.y1))
354
for (i = 0; i < nglyph; i++) {
356
xchar = ppos[i].xchar;
358
/* clip the left and right edges */
359
if (ppos[i].leftEdge < clip.x1)
362
leftEdge = ppos[i].leftEdge;
364
if (ppos[i].rightEdge > clip.x2)
367
rightEdge = ppos[i].rightEdge;
369
w = rightEdge - leftEdge;
373
/* clip the top and bottom edges */
374
if (ppos[i].topEdge < clip.y1)
377
topEdge = ppos[i].topEdge;
379
if (ppos[i].bottomEdge > clip.y2)
380
bottomEdge = clip.y2;
382
bottomEdge = ppos[i].bottomEdge;
384
hSave = bottomEdge - topEdge;
388
glyphRow = (topEdge - y) + pci->metrics.ascent;
389
widthGlyph = ppos[i].widthGlyph;
390
pglyphSave = FONTGLYPHBITS(pglyphBase, pci);
391
pglyphSave += (glyphRow * widthGlyph);
393
glyphCol = (leftEdge - ppos[i].xpos) -
394
(pci->metrics.leftSideBearing);
395
getWidth = w + glyphCol;
397
pdstSave = ilbmScanlineDelta(ppos[i].pdstBase, -(y-topEdge),
399
xoff = xchar + (leftEdge - ppos[i].xpos);
403
} else if (xoff < 0) {
408
for (d = 0; d < depthDst; d++) {
411
pdstSave += widthDst; /* @@@ NEXT PLANE @@@ */
414
if ((xoff + w) <= PPW) {
415
maskpartialbits(xoff, w, startmask);
420
getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
421
*pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
422
pglyph += widthGlyph;
423
ilbmScanlineInc(pdst, auxDst);
428
getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
429
*pdst |= SCRRIGHT(tmpSrc, xoff) & startmask;
430
pglyph += widthGlyph;
431
ilbmScanlineInc(pdst, auxDst);
438
maskPPWbits(xoff, w, startmask, endmask);
444
getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
445
*pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
446
*(pdst+1) &= ~(SCRLEFT(tmpSrc, nFirst) & endmask);
447
pglyph += widthGlyph;
448
ilbmScanlineInc(pdst, auxDst);
453
getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
454
*pdst |= SCRRIGHT(tmpSrc, xoff) & startmask;
455
*(pdst+1) |= SCRLEFT(tmpSrc, nFirst) & endmask;
456
pglyph += widthGlyph;
457
ilbmScanlineInc(pdst, auxDst);
465
} /* for each glyph */
467
DEALLOCATE_LOCAL(ppos);