From e28224f0ea10d1076fafb4a7fc27124efa196d47 Mon Sep 17 00:00:00 2001 From: Huw D M Davies Date: Sat, 10 Jul 1999 10:21:03 +0000 Subject: [PATCH] Added patterned brushes (level 2 PostScript only). Simple PatBlt for PATCOPY, WHITENESS and BLACKNESS. --- graphics/psdrv/Makefile.in | 1 + graphics/psdrv/bitblt.c | 51 ++++++++++++++++++++++++++++++++++++++ graphics/psdrv/bitmap.c | 2 +- graphics/psdrv/brush.c | 23 +++++++++++++++++ graphics/psdrv/init.c | 2 +- graphics/psdrv/ps.c | 50 +++++++++++++++++++++++++++++++++++-- include/psdrv.h | 7 +++--- 7 files changed, 129 insertions(+), 7 deletions(-) create mode 100644 graphics/psdrv/bitblt.c diff --git a/graphics/psdrv/Makefile.in b/graphics/psdrv/Makefile.in index 206966d0143..5bd5ed15319 100644 --- a/graphics/psdrv/Makefile.in +++ b/graphics/psdrv/Makefile.in @@ -7,6 +7,7 @@ MODULE = psdrv C_SRCS = \ afm.c \ + bitblt.c \ bitmap.c \ brush.c \ color.c \ diff --git a/graphics/psdrv/bitblt.c b/graphics/psdrv/bitblt.c new file mode 100644 index 00000000000..e4752e2eae3 --- /dev/null +++ b/graphics/psdrv/bitblt.c @@ -0,0 +1,51 @@ +/* + * PostScript driver BitBlt, StretchBlt and PatBlt + * + * Copyright 1999 Huw D M Davies + * + */ + +#include "gdi.h" +#include "psdrv.h" +#include "debugtools.h" +#include "winbase.h" + +DEFAULT_DEBUG_CHANNEL(psdrv) + + +/*********************************************************************** + * + * PSDRV_PatBlt + */ +BOOL PSDRV_PatBlt(DC *dc, INT x, INT y, INT width, INT height, DWORD dwRop) +{ + PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev; + switch(dwRop) { + case PATCOPY: + PSDRV_WriteGSave(dc); + PSDRV_WriteRectangle(dc, XLPTODP(dc, x), YLPTODP(dc, y), + XLSTODS(dc, width), YLSTODS(dc, height)); + PSDRV_Brush(dc, FALSE); + PSDRV_WriteGRestore(dc); + return TRUE; + + case BLACKNESS: + case WHITENESS: + { + PSCOLOR pscol; + + PSDRV_WriteGSave(dc); + PSDRV_WriteRectangle(dc, XLPTODP(dc, x), YLPTODP(dc, y), + XLSTODS(dc, width), YLSTODS(dc, height)); + PSDRV_CreateColor( physDev, &pscol, (dwRop == BLACKNESS) ? + RGB(0,0,0) : RGB(0xff,0xff,0xff) ); + PSDRV_WriteSetColor(dc, &pscol); + PSDRV_WriteFill(dc); + PSDRV_WriteGRestore(dc); + return TRUE; + } + default: + FIXME("Unsupported rop %ld\n", dwRop); + return FALSE; + } +} diff --git a/graphics/psdrv/bitmap.c b/graphics/psdrv/bitmap.c index 46987391eda..1b44f14445a 100644 --- a/graphics/psdrv/bitmap.c +++ b/graphics/psdrv/bitmap.c @@ -83,7 +83,7 @@ static BOOL PSDRV_WriteImageHeader(DC *dc, const BITMAPINFO *info, INT xDst, } PSDRV_WriteImageDict(dc, info->bmiHeader.biBitCount, xDst, yDst, - widthDst, heightDst, widthSrc, heightSrc); + widthDst, heightDst, widthSrc, heightSrc, NULL); return TRUE; } diff --git a/graphics/psdrv/brush.c b/graphics/psdrv/brush.c index 5a3c103658c..4a7b1be17b9 100644 --- a/graphics/psdrv/brush.c +++ b/graphics/psdrv/brush.c @@ -9,6 +9,7 @@ #include "brush.h" #include "debugtools.h" #include "gdi.h" +#include "winbase.h" DEFAULT_DEBUG_CHANNEL(psdrv) @@ -192,6 +193,28 @@ BOOL PSDRV_Brush(DC *dc, BOOL EO) return TRUE; break; + case BS_PATTERN: + { + BITMAP bm; + BYTE *bits; + GetObjectA(brush->logbrush.lbHatch, sizeof(BITMAP), &bm); + TRACE("BS_PATTERN %dx%d %d bpp\n", bm.bmWidth, bm.bmHeight, + bm.bmBitsPixel); + bits = HeapAlloc(PSDRV_Heap, 0, bm.bmWidthBytes * bm.bmHeight); + GetBitmapBits(brush->logbrush.lbHatch, + bm.bmWidthBytes * bm.bmHeight, bits); + + PSDRV_WriteGSave(dc); + PSDRV_WritePatternDict(dc, &bm, bits); + HeapFree(PSDRV_Heap, 0, bits); + PSDRV_Fill(dc, EO); + PSDRV_WriteGRestore(dc); + return TRUE; + } + break; + + + default: return FALSE; break; diff --git a/graphics/psdrv/init.c b/graphics/psdrv/init.c index 226327ee727..3295f62d88a 100644 --- a/graphics/psdrv/init.c +++ b/graphics/psdrv/init.c @@ -58,7 +58,7 @@ static const DC_FUNCTIONS PSDRV_Funcs = NULL, /* pOffsetViewportOrg (optional) */ NULL, /* pOffsetWindowOrg (optional) */ NULL, /* pPaintRgn */ - NULL, /* pPatBlt */ + PSDRV_PatBlt, /* pPatBlt */ PSDRV_Pie, /* pPie */ PSDRV_PolyPolygon, /* pPolyPolygon */ PSDRV_PolyPolyline, /* pPolyPolyline */ diff --git a/graphics/psdrv/ps.c b/graphics/psdrv/ps.c index 6092c3e5e4d..3a5d27563ce 100644 --- a/graphics/psdrv/ps.c +++ b/graphics/psdrv/ps.c @@ -741,7 +741,7 @@ BOOL PSDRV_WriteRGB(DC *dc, COLORREF *map, int number) BOOL PSDRV_WriteImageDict(DC *dc, WORD depth, INT xDst, INT yDst, INT widthDst, INT heightDst, INT widthSrc, - INT heightSrc) + INT heightSrc, char *bits) { char start[] = "%d %d translate\n%d %d scale\n<<\n" " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n" @@ -751,6 +751,7 @@ BOOL PSDRV_WriteImageDict(DC *dc, WORD depth, INT xDst, INT yDst, char decode3[] = " /Decode [0 1 0 1 0 1]\n"; char end[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n"; + char endbits[] = " /DataSource <%s>\n>> image\n"; char *buf = HeapAlloc(PSDRV_Heap, 0, 1000); @@ -779,12 +780,18 @@ BOOL PSDRV_WriteImageDict(DC *dc, WORD depth, INT xDst, INT yDst, PSDRV_WriteSpool(dc, buf, strlen(buf)); - PSDRV_WriteSpool(dc, end, sizeof(end) - 1); + if(!bits) + PSDRV_WriteSpool(dc, end, sizeof(end) - 1); + else { + sprintf(buf, endbits, bits); + PSDRV_WriteSpool(dc, buf, strlen(buf)); + } HeapFree(PSDRV_Heap, 0, buf); return TRUE; } + BOOL PSDRV_WriteBytes(DC *dc, const BYTE *bytes, int number) { char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1); @@ -872,3 +879,42 @@ BOOL PSDRV_WriteDIBits32(DC *dc, const BYTE *bits, int number) HeapFree(PSDRV_Heap, 0, buf); return TRUE; } + + +BOOL PSDRV_WritePatternDict(DC *dc, BITMAP *bm, BYTE *bits) +{ + char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n " + "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n"; + + char end[] = " end\n }\n>>\n matrix makepattern setpattern\n"; + char *buf, *ptr; + INT w, h, x, y; + COLORREF map[2]; + + w = bm->bmWidth & ~0x7; + h = bm->bmHeight & ~0x7; + + buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100); + sprintf(buf, start, w, h, w, h); + PSDRV_WriteSpool(dc, buf, strlen(buf)); + PSDRV_WriteIndexColorSpaceBegin(dc, 1); + map[0] = dc->w.textColor; + map[1] = dc->w.backgroundColor; + PSDRV_WriteRGB(dc, map, 2); + PSDRV_WriteIndexColorSpaceEnd(dc); + ptr = buf; + for(y = h-1; y >= 0; y--) { + for(x = 0; x < w/8; x++) { + sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes)); + ptr += 2; + } + } + PSDRV_WriteImageDict(dc, 1, 0, 0, 8, 8, 8, 8, buf); + PSDRV_WriteSpool(dc, end, sizeof(end) - 1); + HeapFree(PSDRV_Heap, 0, buf); + return TRUE; +} + + + + diff --git a/include/psdrv.h b/include/psdrv.h index bb06e67b672..fe7767a2ebc 100644 --- a/include/psdrv.h +++ b/include/psdrv.h @@ -296,14 +296,13 @@ extern BOOL PSDRV_WriteIndexColorSpaceEnd(DC *dc); extern BOOL PSDRV_WriteRGB(DC *dc, COLORREF *map, int number); extern BOOL PSDRV_WriteImageDict(DC *dc, WORD depth, INT xDst, INT yDst, INT widthDst, INT heightDst, INT widthSrc, - INT heightSrc); + INT heightSrc, char *bits); extern BOOL PSDRV_WriteBytes(DC *dc, const BYTE *bytes, int number); extern BOOL PSDRV_WriteDIBits16(DC *dc, const WORD *words, int number); extern BOOL PSDRV_WriteDIBits24(DC *dc, const BYTE *bits, int number); extern BOOL PSDRV_WriteDIBits32(DC *dc, const BYTE *bits, int number); extern int PSDRV_WriteSpool(DC *dc, LPSTR lpData, WORD cch); - - +extern BOOL PSDRV_WritePatternDict(DC *dc, BITMAP *bm, BYTE *bits); extern BOOL PSDRV_Arc( DC *dc, INT left, INT top, INT right, INT bottom, INT xstart, INT ystart, @@ -327,6 +326,8 @@ extern BOOL PSDRV_GetTextExtentPoint( DC *dc, LPCSTR str, INT count, extern BOOL PSDRV_GetTextMetrics( DC *dc, TEXTMETRICA *metrics ); extern BOOL PSDRV_LineTo( DC *dc, INT x, INT y ); extern BOOL PSDRV_MoveToEx( DC *dc, INT x, INT y, LPPOINT pt ); +extern BOOL PSDRV_PatBlt( DC *dc, INT x, INT y, INT width, INT height, DWORD + dwRop); extern BOOL PSDRV_Pie( DC *dc, INT left, INT top, INT right, INT bottom, INT xstart, INT ystart, INT xend, INT yend );