wineps: better pattern brushes
Huw D M Davies
h.davies1 at physics.ox.ac.uk
Tue Nov 2 09:34:55 CST 2004
Huw Davies <huw at codeweavers.com>
Scale the patterns so that they're rendered at 300dpi
Create the image dictionary once, rather than every time the PaintProc
is called - should speed printing up somewhat.
--
Huw Davies
huw at codeweavers.com
Index: dlls/wineps/bitmap.c
===================================================================
RCS file: /home/wine/wine/dlls/wineps/bitmap.c,v
retrieving revision 1.11
diff -u -r1.11 bitmap.c
--- dlls/wineps/bitmap.c 8 Dec 2003 21:40:27 -0000 1.11
+++ dlls/wineps/bitmap.c 2 Nov 2004 15:25:49 -0000
@@ -149,8 +149,8 @@
break;
}
- PSDRV_WriteImageDict(physDev, info->bmiHeader.biBitCount, xDst, yDst,
- widthDst, heightDst, widthSrc, heightSrc, NULL, FALSE);
+ PSDRV_WriteImage(physDev, info->bmiHeader.biBitCount, xDst, yDst,
+ widthDst, heightDst, widthSrc, heightSrc, FALSE);
return TRUE;
}
@@ -198,8 +198,8 @@
PSDRV_WriteGRestore(physDev);
PSDRV_WriteSetColor(physDev, &foregnd);
- PSDRV_WriteImageDict(physDev, 1, xDst, yDst, widthDst, heightDst,
- widthSrc, heightSrc, NULL, TRUE);
+ PSDRV_WriteImage(physDev, 1, xDst, yDst, widthDst, heightDst,
+ widthSrc, heightSrc, TRUE);
return TRUE;
}
Index: dlls/wineps/ps.c
===================================================================
RCS file: /home/wine/wine/dlls/wineps/ps.c,v
retrieving revision 1.29
diff -u -r1.29 ps.c
--- dlls/wineps/ps.c 5 Oct 2004 22:31:14 -0000 1.29
+++ dlls/wineps/ps.c 2 Nov 2004 15:25:49 -0000
@@ -647,26 +647,22 @@
return TRUE;
}
-
-BOOL PSDRV_WriteImageDict(PSDRV_PDEVICE *physDev, WORD depth, INT xDst, INT yDst,
- INT widthDst, INT heightDst, INT widthSrc,
- INT heightSrc, char *bits, BOOL mask)
+static BOOL PSDRV_WriteImageDict(PSDRV_PDEVICE *physDev, WORD depth,
+ INT widthSrc, INT heightSrc, char *bits)
{
- static const char start[] = "%d %d translate\n%d %d scale\n<<\n"
+ static const char start[] = "<<\n"
" /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
" /ImageMatrix [%d 0 0 %d 0 %d]\n";
static const char decode1[] = " /Decode [0 %d]\n";
static const char decode3[] = " /Decode [0 1 0 1 0 1]\n";
- static const char end[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>> image\n";
- static const char endmask[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>> imagemask\n";
-
- static const char endbits[] = " /DataSource <%s>\n>> image\n";
+ static const char end[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
+ static const char endbits[] = " /DataSource <%s>\n>>\n";
char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
- sprintf(buf, start, xDst, yDst, widthDst, heightDst, widthSrc, heightSrc,
+ sprintf(buf, start, widthSrc, heightSrc,
(depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
PSDRV_WriteSpool(physDev, buf, strlen(buf));
@@ -692,10 +688,7 @@
PSDRV_WriteSpool(physDev, buf, strlen(buf));
if(!bits) {
- if(!mask)
- PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
- else
- PSDRV_WriteSpool(physDev, endmask, sizeof(endmask) - 1);
+ PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
} else {
sprintf(buf, endbits, bits);
PSDRV_WriteSpool(physDev, buf, strlen(buf));
@@ -705,6 +698,25 @@
return TRUE;
}
+BOOL PSDRV_WriteImage(PSDRV_PDEVICE *physDev, WORD depth, INT xDst, INT yDst,
+ INT widthDst, INT heightDst, INT widthSrc,
+ INT heightSrc, BOOL mask)
+{
+ static const char start[] = "%d %d translate\n%d %d scale\n";
+ static const char image[] = "image\n";
+ static const char imagemask[] = "imagemask\n";
+ char buf[100];
+
+ sprintf(buf, start, xDst, yDst, widthDst, heightDst);
+ PSDRV_WriteSpool(physDev, buf, strlen(buf));
+ PSDRV_WriteImageDict(physDev, depth, widthSrc, heightSrc, NULL);
+ if(mask)
+ PSDRV_WriteSpool(physDev, imagemask, sizeof(imagemask) - 1);
+ else
+ PSDRV_WriteSpool(physDev, image, sizeof(image) - 1);
+ return TRUE;
+}
+
BOOL PSDRV_WriteBytes(PSDRV_PDEVICE *physDev, const BYTE *bytes, DWORD number)
{
@@ -784,25 +796,19 @@
BOOL PSDRV_WritePatternDict(PSDRV_PDEVICE *physDev, BITMAP *bm, BYTE *bits)
{
- static const 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";
+ static const char mypat[] = "/mypat\n";
+ static const char do_pattern[] = "<<\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 0 0 translate\n"
+ " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
- static const char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
char *buf, *ptr;
- INT w, h, x, y;
+ INT w, h, x, y, w_mult, h_mult;
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(physDev, buf, strlen(buf));
- PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
- map[0] = GetTextColor( physDev->hdc );
- map[1] = GetBkColor( physDev->hdc );
- PSDRV_WriteRGB(physDev, map, 2);
- PSDRV_WriteIndexColorSpaceEnd(physDev);
+ buf = HeapAlloc(PSDRV_Heap, 0, sizeof(do_pattern) + 100);
ptr = buf;
for(y = h-1; y >= 0; y--) {
for(x = 0; x < w/8; x++) {
@@ -810,21 +816,35 @@
ptr += 2;
}
}
- PSDRV_WriteImageDict(physDev, 1, 0, 0, 8, 8, 8, 8, buf, FALSE);
- PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
+ PSDRV_WriteSpool(physDev, mypat, sizeof(mypat) - 1);
+ PSDRV_WriteImageDict(physDev, 1, 8, 8, buf);
+ PSDRV_WriteSpool(physDev, "def\n", 4);
+
+ PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
+ map[0] = GetTextColor( physDev->hdc );
+ map[1] = GetBkColor( physDev->hdc );
+ PSDRV_WriteRGB(physDev, map, 2);
+ PSDRV_WriteIndexColorSpaceEnd(physDev);
+
+ /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
+ w_mult = (physDev->logPixelsX + 150) / 300;
+ h_mult = (physDev->logPixelsY + 150) / 300;
+ sprintf(buf, do_pattern, w * w_mult, h * h_mult, w * w_mult, h * h_mult, w * w_mult, h * h_mult);
+ PSDRV_WriteSpool(physDev, buf, strlen(buf));
+
HeapFree(PSDRV_Heap, 0, buf);
return TRUE;
}
BOOL PSDRV_WriteDIBPatternDict(PSDRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage)
{
- static const 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";
-
- static const char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
+ static const char mypat[] = "/mypat\n";
+ static const char do_pattern[] = "<<\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 0 0 translate\n"
+ " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
char *buf, *ptr;
BYTE *bits;
- INT w, h, x, y, colours;
+ INT w, h, x, y, colours, w_mult, h_mult;
COLORREF map[2];
if(bmi->bmiHeader.biBitCount != 1) {
@@ -842,14 +862,7 @@
w = bmi->bmiHeader.biWidth & ~0x7;
h = bmi->bmiHeader.biHeight & ~0x7;
- buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
- sprintf(buf, start, w, h, w, h);
- PSDRV_WriteSpool(physDev, buf, strlen(buf));
- PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
- map[0] = GetTextColor( physDev->hdc );
- map[1] = GetBkColor( physDev->hdc );
- PSDRV_WriteRGB(physDev, map, 2);
- PSDRV_WriteIndexColorSpaceEnd(physDev);
+ buf = HeapAlloc(PSDRV_Heap, 0, sizeof(do_pattern) + 100);
ptr = buf;
for(y = h-1; y >= 0; y--) {
for(x = 0; x < w/8; x++) {
@@ -858,8 +871,21 @@
ptr += 2;
}
}
- PSDRV_WriteImageDict(physDev, 1, 0, 0, 8, 8, 8, 8, buf, FALSE);
- PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
+ PSDRV_WriteSpool(physDev, mypat, sizeof(mypat) - 1);
+ PSDRV_WriteImageDict(physDev, 1, 8, 8, buf);
+ PSDRV_WriteSpool(physDev, "def\n", 4);
+
+ PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
+ map[0] = GetTextColor( physDev->hdc );
+ map[1] = GetBkColor( physDev->hdc );
+ PSDRV_WriteRGB(physDev, map, 2);
+ PSDRV_WriteIndexColorSpaceEnd(physDev);
+
+ /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
+ w_mult = (physDev->logPixelsX + 150) / 300;
+ h_mult = (physDev->logPixelsY + 150) / 300;
+ sprintf(buf, do_pattern, w * w_mult, h * h_mult, w * w_mult, h * h_mult, w * w_mult, h * h_mult);
+ PSDRV_WriteSpool(physDev, buf, strlen(buf));
HeapFree(PSDRV_Heap, 0, buf);
return TRUE;
}
Index: dlls/wineps/psdrv.h
===================================================================
RCS file: /home/wine/wine/dlls/wineps/psdrv.h,v
retrieving revision 1.53
diff -u -r1.53 psdrv.h
--- dlls/wineps/psdrv.h 5 Oct 2004 22:31:14 -0000 1.53
+++ dlls/wineps/psdrv.h 2 Nov 2004 15:25:49 -0000
@@ -447,9 +447,9 @@
extern BOOL PSDRV_WriteIndexColorSpaceBegin(PSDRV_PDEVICE *physDev, int size);
extern BOOL PSDRV_WriteIndexColorSpaceEnd(PSDRV_PDEVICE *physDev);
extern BOOL PSDRV_WriteRGB(PSDRV_PDEVICE *physDev, COLORREF *map, int number);
-extern BOOL PSDRV_WriteImageDict(PSDRV_PDEVICE *physDev, WORD depth, INT xDst, INT yDst,
- INT widthDst, INT heightDst, INT widthSrc,
- INT heightSrc, char *bits, BOOL mask);
+extern BOOL PSDRV_WriteImage(PSDRV_PDEVICE *physDev, WORD depth, INT xDst, INT yDst,
+ INT widthDst, INT heightDst, INT widthSrc,
+ INT heightSrc, BOOL mask);
extern BOOL PSDRV_WriteBytes(PSDRV_PDEVICE *physDev, const BYTE *bytes, DWORD number);
extern BOOL PSDRV_WriteData(PSDRV_PDEVICE *physDev, const BYTE *byte, DWORD number);
extern DWORD PSDRV_WriteSpool(PSDRV_PDEVICE *physDev, LPCSTR lpData, DWORD cch);
More information about the wine-patches
mailing list