Translating from a CGRect in screen coordinates to a PTPDFRect in Page Coordinates

,

Question:

How do I translate a CGRect in screen coordinates to a PTPDFRect in Page Coordinates?

Answer:

This helper method will do it.

-(PTPDFRect*)CGRectScreen2PDFRectPage:(CGRect)cgRect PageNumber:(int)pageNumber
{
	CGPoint topLeft = cgRect.origin;
	CGPoint bottomRight = CGPointMake(CGRectGetMaxX(cgRect), CGRectGetMaxY(cgRect));
	
	[self ConvertScreenPtToPagePtX:&topLeft.x Y:&topLeft.y PageNumber:pageNumber];
	[self ConvertScreenPtToPagePtX:&bottomRight.x Y:&bottomRight.y PageNumber:pageNumber];
	
	PTPDFRect* ptRect = [[PTPDFRect alloc] initWithX1:topLeft.x y1:topLeft.y x2:bottomRight.x y2:bottomRight.y];
	
	[ptRect Normalize];
	
	return ptRect;
}
-(void)ConvertScreenPtToPagePtX:(CGFloat*)x Y:(CGFloat*)y PageNumber:(int)pageNumber
{
    [m_screenPt setX:*x];
    [m_screenPt setY:*y];
    
    
    m_pagePt = [m_pdfViewCtrl ConvScreenPtToPagePt:m_screenPt page_num:pageNumber];
    
    *x = (float)[m_pagePt getX];
    *y = (float)[m_pagePt getY];
}