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

28 views
Skip to first unread message

James

unread,
Nov 2, 2016, 8:36:00 PM11/2/16
to pdfne...@googlegroups.com
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];
}
Reply all
Reply to author
Forward
0 new messages