#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif
#include "misc.h"
#include "xf86.h"
#include "xf86_OSproc.h"
#include <X11/X.h>
#include <X11/fonts/font.h>
#include "scrnintstr.h"
#include "dixfontstr.h"
#include "xf86str.h"
#include "xaa.h"
#include "xaalocal.h"
#include "gcstruct.h"
#include "pixmapstr.h"
static void XAAGlyphBltTEColorExpansion(ScrnInfoPtr pScrn, int xInit,
int yInit, FontPtr font, int fg, int bg, int rop,
unsigned int planemask, RegionPtr cclip, int nglyph,
unsigned char* gBase, CharInfoPtr *ppci);
int
XAAPolyText8TEColorExpansion(
DrawablePtr pDraw,
GCPtr pGC,
int x, int y,
int count,
char *chars )
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
unsigned long n;
(*pGC->font->get_glyphs)(pGC->font, (unsigned long)count,
(unsigned char *)chars, Linear8Bit, &n, infoRec->CharInfo);
if(n) XAAGlyphBltTEColorExpansion(
infoRec->pScrn, x + pDraw->x, y + pDraw->y,
pGC->font, pGC->fgPixel, -1, pGC->alu, pGC->planemask,
pGC->pCompositeClip, n, FONTGLYPHS(pGC->font), infoRec->CharInfo);
return (x + (n * FONTMAXBOUNDS(pGC->font, characterWidth)));
}
int
XAAPolyText16TEColorExpansion(
DrawablePtr pDraw,
GCPtr pGC,
int x, int y,
int count,
unsigned short *chars )
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
unsigned long n;
(*pGC->font->get_glyphs)(
pGC->font, (unsigned long)count, (unsigned char *)chars,
(FONTLASTROW(pGC->font) == 0) ? Linear16Bit : TwoD16Bit,
&n, infoRec->CharInfo);
if(n) XAAGlyphBltTEColorExpansion(
infoRec->pScrn, x + pDraw->x, y + pDraw->y,
pGC->font, pGC->fgPixel, -1, pGC->alu, pGC->planemask,
pGC->pCompositeClip, n, FONTGLYPHS(pGC->font), infoRec->CharInfo);
return (x + (n * FONTMAXBOUNDS(pGC->font, characterWidth)));
}
void
XAAImageText8TEColorExpansion(
DrawablePtr pDraw,
GCPtr pGC,
int x, int y,
int count,
char *chars )
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
unsigned long n;
if(!RegionNumRects(pGC->pCompositeClip))
return;
(*pGC->font->get_glyphs)(pGC->font, (unsigned long)count,
(unsigned char *)chars, Linear8Bit, &n, infoRec->CharInfo);
if(n) XAAGlyphBltTEColorExpansion(
infoRec->pScrn, x + pDraw->x, y + pDraw->y,
pGC->font, pGC->fgPixel, pGC->bgPixel, GXcopy, pGC->planemask,
pGC->pCompositeClip, n, FONTGLYPHS(pGC->font), infoRec->CharInfo);
}
void
XAAImageText16TEColorExpansion(
DrawablePtr pDraw,
GCPtr pGC,
int x, int y,
int count,
unsigned short *chars )
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
unsigned long n;
if(!RegionNumRects(pGC->pCompositeClip))
return;
(*pGC->font->get_glyphs)(
pGC->font, (unsigned long)count, (unsigned char *)chars,
(FONTLASTROW(pGC->font) == 0) ? Linear16Bit : TwoD16Bit,
&n, infoRec->CharInfo);
if(n) XAAGlyphBltTEColorExpansion(
infoRec->pScrn, x + pDraw->x, y + pDraw->y,
pGC->font, pGC->fgPixel, pGC->bgPixel, GXcopy, pGC->planemask,
pGC->pCompositeClip, n, FONTGLYPHS(pGC->font), infoRec->CharInfo);
}
void
XAAImageGlyphBltTEColorExpansion(
DrawablePtr pDrawable,
GCPtr pGC,
int xInit, int yInit,
unsigned int nglyph,
CharInfoPtr *ppci,
pointer pglyphBase )
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
if(!RegionNumRects(pGC->pCompositeClip))
return;
XAAGlyphBltTEColorExpansion(
infoRec->pScrn, xInit + pDrawable->x, yInit + pDrawable->y,
pGC->font, pGC->fgPixel, pGC->bgPixel, GXcopy, pGC->planemask,
pGC->pCompositeClip, nglyph, (unsigned char*)pglyphBase, ppci);
}
void
XAAPolyGlyphBltTEColorExpansion(
DrawablePtr pDrawable,
GCPtr pGC,
int xInit, int yInit,
unsigned int nglyph,
CharInfoPtr *ppci,
pointer pglyphBase )
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
if(!RegionNumRects(pGC->pCompositeClip))
return;
XAAGlyphBltTEColorExpansion(
infoRec->pScrn, xInit + pDrawable->x, yInit + pDrawable->y,
pGC->font, pGC->fgPixel, -1, pGC->alu, pGC->planemask,
pGC->pCompositeClip, nglyph, (unsigned char*)pglyphBase, ppci);
}
static void
XAAGlyphBltTEColorExpansion(
ScrnInfoPtr pScrn,
int xInit, int yInit,
FontPtr font,
int fg, int bg,
int rop,
unsigned int planemask,
RegionPtr cclip,
int nglyph,
unsigned char* gBase,
CharInfoPtr *ppci )
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
int skippix, skipglyphs;
int Left, Right, Top, Bottom;
int LeftEdge, RightEdge, ytop, ybot;
int nbox = RegionNumRects(cclip);
BoxPtr pbox = RegionRects(cclip);
unsigned int **glyphs = NULL;
int glyphWidth = FONTMAXBOUNDS(font, characterWidth);
Left = xInit;
Right = Left + (glyphWidth * nglyph);
Top = yInit - FONTASCENT(font);
Bottom = yInit + FONTDESCENT(font);
while(nbox && (Top >= pbox->y2)) {
pbox++; nbox--;
}
while(nbox && (Bottom > pbox->y1)) {
LeftEdge = max(Left, pbox->x1);
RightEdge = min(Right, pbox->x2);
if(RightEdge > LeftEdge) {
unsigned int *fallbackBits = NULL;
ytop = max(Top, pbox->y1);
ybot = min(Bottom, pbox->y2);
if((skippix = LeftEdge - Left)) {
skipglyphs = skippix/glyphWidth;
skippix %= glyphWidth;
} else skipglyphs = 0;
if(!glyphs) {
int count;
glyphs = (unsigned int**)(infoRec->PreAllocMem);
for(count = 0; count < nglyph; count++) {
glyphs[count] = (unsigned int*)
FONTGLYPHBITS(gBase,*ppci++);
if (!glyphs[count]) {
if (!fallbackBits) {
int fontHeight = Bottom - Top + 1;
fallbackBits = calloc(glyphWidth * fontHeight, 1);
if (!fallbackBits)
return;
}
glyphs[count] = fallbackBits;
}
}
glyphs[count + 0] = glyphs[0];
glyphs[count + 1] = glyphs[0];
glyphs[count + 2] = glyphs[0];
glyphs[count + 3] = glyphs[0];
glyphs[count + 4] = glyphs[0];
glyphs[count + 5] = glyphs[0];
}
(*infoRec->TEGlyphRenderer)( pScrn,
LeftEdge, ytop, RightEdge - LeftEdge, ybot - ytop,
skippix, ytop - Top, glyphs + skipglyphs, glyphWidth,
fg, bg, rop, planemask);
free(fallbackBits);
}
nbox--; pbox++;
}
}