From 0f94cdd727517ebf24244025beb01af8fd7cef25 Mon Sep 17 00:00:00 2001 From: Adam Fedor Date: Tue, 21 Jan 2003 05:11:28 +0000 Subject: [PATCH] Correct printing images git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@15667 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++ Source/gsc/GSStreamContext.m | 52 +++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0eafc1f..9989e73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-01-20 Adam Fedor + + * Source/gsc/GSStreamContext.m (-GSSetCTM:): Implement. + (-GSConcatCTM:): Idem. + (-NSDrawBitmap:::::::::::): Don't flip images in a flipped view. + Correct scaling of images. + Tue Jan 21 02:08:05 2003 Alexander Malmberg * Source/xlib/XGFont.m ([XGFontInfo -dealloc]): Fixed memory leak: diff --git a/Source/gsc/GSStreamContext.m b/Source/gsc/GSStreamContext.m index 9372131..ecfd71c 100644 --- a/Source/gsc/GSStreamContext.m +++ b/Source/gsc/GSStreamContext.m @@ -28,7 +28,9 @@ #include "gsc/GSStreamContext.h" #include "gsc/GSStreamGState.h" #include +#include #include +#include #include #include #include @@ -358,12 +360,18 @@ - (void) GSSetCTM: (NSAffineTransform *)ctm { - [self notImplemented: _cmd]; + float m[6]; + [ctm getMatrix: m]; + fprintf(gstream, "[%g %g %g %g %g %g] setmatrix\n", + m[0], m[1], m[2], m[3], m[4], m[5]); } - (void) GSConcatCTM: (NSAffineTransform *)ctm { - [self notImplemented: _cmd]; + float m[6]; + [ctm getMatrix: m]; + fprintf(gstream, "[%g %g %g %g %g %g] concat\n", + m[0], m[1], m[2], m[3], m[4], m[5]); } @@ -632,15 +640,22 @@ writeHex(FILE *gstream, const unsigned char *data, int count) : (BOOL)hasAlpha : (NSString *)colorSpaceName : (const unsigned char *const [5])data { - int bytes; - NSSize scale; + int bytes, spp; + float y; + BOOL flipped = NO; + + /* In a flipped view, we don't want to flip the image again, which would + make it come out upsidedown. FIXME: This can't be right, can it? */ + if ([[NSView focusView] isFlipped]) + flipped = YES; - scale = NSMakeSize(NSWidth(rect) / pixelsWide, - NSHeight(rect) / pixelsHigh); /* Save scaling */ fprintf(gstream, "matrix\ncurrentmatrix\n"); + y = NSMinY(rect); + if (flipped) + y += NSWidth(rect); fprintf(gstream, "%f %f translate %f %f scale\n", - NSMinX(rect), NSMinY(rect), scale.width, scale.height); + NSMinX(rect), y, NSWidth(rect), NSHeight(rect)); if (bitsPerSample == 0) bitsPerSample = 8; @@ -653,6 +668,10 @@ writeHex(FILE *gstream, const unsigned char *data, int count) bytesPerRow, pixelsHigh, bytes); return; } + if(hasAlpha) + spp = samplesPerPixel - 1; + else + spp = samplesPerPixel; if(samplesPerPixel > 1) { @@ -666,17 +685,16 @@ writeHex(FILE *gstream, const unsigned char *data, int count) } fprintf(gstream, "%d %d %d [%d 0 0 -%d 0 %d]\n", pixelsWide, pixelsHigh, bitsPerSample, pixelsWide, - pixelsHigh, pixelsHigh); + (flipped) ? pixelsHigh : -pixelsHigh, pixelsHigh); fprintf(gstream, "{currentfile %d string readhexstring pop}\n", - bytesPerRow); - fprintf(gstream, "false %d colorimage\n", - hasAlpha?(samplesPerPixel-1):samplesPerPixel); + pixelsWide*spp); + fprintf(gstream, "false %d colorimage\n", spp); } else { - fprintf(gstream, "%d %d %d [%d 0 0 -%d 0 %d]\n", + fprintf(gstream, "%d %d %d [%d 0 0 %d 0 %d]\n", pixelsWide, pixelsHigh, bitsPerSample, pixelsWide, - pixelsHigh, pixelsHigh); + (flipped) ? pixelsHigh : -pixelsHigh, pixelsHigh); fprintf(gstream, "currentfile image\n"); } @@ -686,13 +704,9 @@ writeHex(FILE *gstream, const unsigned char *data, int count) // We need to do a format conversion. // We do this on the fly, sending data to the context as soon as // it is computed. - int i, j, spp, alpha; + int i, j, alpha; unsigned char val; - if(hasAlpha) - spp = samplesPerPixel - 1; - else - spp = samplesPerPixel; - + for(j=0; j