Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CGPDFPageGetDrawingTransform refuses to upscale



I maybe mis-interpreting your case, but you should be able to do this :

Assuming the pdf's artbox is artbox (x, y, w, h) and the rectangle you want to draw into is rect (x, y, w, h)

CGContextTranslateCTM(rect.x, rect.y);
CGContextScaleCTM(rect.w / artbox.w, rect.h / artbox.h);
CGContextTranslateCTM(-artbox.x, -artbox.y);

To verify this, take the point (artbox.x,artbox.y) and move bottom to top (code wise) applying the transforms and it will map it to point (rect.x, rect.y):
    Shown for x only: (artbox.x -artbox.x) * (rect.w / artbox.w) + rect.x
Similarly the point (artbox.x + artbox.w, artbox.y + artbox.h) multiplied upwards through the transforms should yield (rect.x + rect.w, rect.y + rect.h):
    for x only :  ((artbox.x + artbox.w) - artbox.x) * (rect.w / artbox.w) + rect.x

Hope that helps. In general one can use this technique to map an arbitrary rectangle to another rectangle in another space (in the simplified case of translates and scales). 
__
haroon sheikh هارون شيخ

On Mar 31, 2005, at 12:40 PM, David Niemeijer wrote:

That makes sense, but the rectangle into which I want to draw, itself has a non-zero origin and then we get the transform that CGPDFPageGetDrawingTransform does. I wish there was some straight forward example on how to achieve proper translation and scaling when going from one rectangle with its coordinates to another rectangle with its own coordinates. For example, the art box of the PDF looks like this:

x 258.215 y 371.517
width 82.9009 height 104.702

and the rectangle I want to draw into looks like this:

x 4.9 y 12.375
width 88.2 height 129.25

What transforms would one use to properly scale and translate to get the PDF art to draw into that rectangle?

I am already using this code to make sure the image does not appear upside down:

CGContextTranslateCTM(inContext, 0, myRect.origin.y + CGRectGetMaxY(myRect));
CGContextScaleCTM(inContext,1.0f,-1.0f);

david.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden

References: 
 >CGPDFPageGetDrawingTransform refuses to upscale (From: David Niemeijer <email@hidden>)
 >Re: CGPDFPageGetDrawingTransform refuses to upscale (From: Derek Clegg <email@hidden>)
 >Re: CGPDFPageGetDrawingTransform refuses to upscale (From: David Niemeijer <email@hidden>)
 >Re: CGPDFPageGetDrawingTransform refuses to upscale (From: Derek Clegg <email@hidden>)
 >Re: CGPDFPageGetDrawingTransform refuses to upscale (From: David Niemeijer <email@hidden>)
 >Re: CGPDFPageGetDrawingTransform refuses to upscale (From: Nick Nallick <email@hidden>)
 >Re: CGPDFPageGetDrawingTransform refuses to upscale (From: David Niemeijer <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.