Re: NSImage quality, blurred characters
Re: NSImage quality, blurred characters
- Subject: Re: NSImage quality, blurred characters
- From: "Ewan Delanoy" <email@hidden>
- Date: Thu, 24 May 2007 20:59:50 +0200 (CEST)
- Importance: Normal
>
> This could be caused by a couple of things. I suggest you post the
> relevant code you use to compose the image.
>
> --
> I.S.
>
Right. It's a little complicated, and I think I'll explain it best by
explaining the process backwards :
1) The final PDF is obtained via a "printable" NSView subclass
(called GGAdHocViewForPrinting) with the usual
-rectForPage: and knowsPageRange: overriding. GGAdHocViewForPrinting
has an NSMutableArray* ivar called "images" that stores images.
The -drawRect: method of GGAdHocViewForPrinting contains the following
lines :
-(void) drawRect: (NSRect) r
{
(...)
unsigned smallRotatedPageIndex;
for
(smallRotatedPageIndex=1;smallRotatedPageIndex<=numberOfSmallRotatedPages;smallRotatedPageIndex++)
{
NSRect currentRect=[self
rectForSmallRotatedPageWithNaiveIndexation:smallRotatedPageIndex];
if (NSIntersectsRect(r,currentRect)) {
NSImage* image=[images objectAtIndex:(i-1)];
NSRect sourceRect=NSZeroRect;
sourceRect.size=[image size];
NSRect destinationRect=[self
rectForSmallRotatedPageWithNaiveIndexation:smallRotatedPageIndex];
[image drawInRect:destinationRect
fromRect:sourceRect
operation:NSCompositeSourceOver
fraction:1.0];
}
}
(...)
}
2) The "images" array is filled as follows : the initializing method of
GGAdHocViewForPrinting
contains the following lines :
unsigned cnt;
for (cnt=1;cnt<=numberOfSmallRotatedPages;cnt++) {
NSRect sourceRect=[originalView pancakeRectForPancakeNumber: cnt];
NSData* data=[originalView dataWithPDFInsideRect:sourceRect];
NSImage* image1=[[NSImage alloc] initWithData:data];
NSImage* image2=[GGImageAdditions
flippedImageWhichIsThenTurnedLeft:image1];
[images addObject:image2];
[image1 release];
}
Here "originalView" is a view containing many ordinary NSTextViews where
the end user
can type, and sourceRect is wholly contained inside a single text view.
3) Eventually, the "flippedImageWhichIsThenTurnedLeft" method of
GGImageAdditions is as follows :
+(NSImage*) flippedImageWhichIsThenTurnedLeft: (NSImage*) oldImage
{
NSSize oldSize=[oldImage size];
NSRect oldRect=NSMakeRect(0,0,oldSize.width,oldSize.height);
NSSize newSize=NSMakeSize(oldSize.height,oldSize.width);
NSImage* newImage=[[NSImage alloc] initWithSize:newSize];
[newImage lockFocus];
[[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
NSAffineTransform* xform=[NSAffineTransform transform];
NSAffineTransformStruct sym= {0,-1,-1,0,oldSize.height,oldSize.width};
[xform setTransformStruct:sym];
[xform concat];
[oldImage drawInRect:oldRect
fromRect:oldRect
operation:NSCompositeSourceOver
fraction:1.0];
[newImage unlockFocus];
return [newImage autorelease];
}
Ewan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden