How to convert pixels to centimeters in Cocoa
How to convert pixels to centimeters in Cocoa
- Subject: How to convert pixels to centimeters in Cocoa
- From: "Ewan Delanoy" <email@hidden>
- Date: Tue, 8 May 2007 11:33:22 +0200 (CEST)
- Importance: Normal
Hello all,
for my Cocoa text-editor I need to convert pixels to
centimeters in some place. When I googled "convert pixels
centimeters" or "convert pixels centimeters Cocoa" I found out
how to do this for many other operating systems, but not for
Cocoa in Mac OS X. I guess i just missed the right place
to look...
For a given Mac machine it is not difficult to make a separate
evaluation of the proportionality constant (e.g, in TextEdit, compare
the length displayed in the tooltips in the "Page Layout" menu item
with the value of [[NSPrintInfo sharedPrintInfo] paperSize] in gdb.
But for portability, is there a Mac machine-independent
way to do this, something like :
float proportionalityConstantBetweenPixelsAndCentimeters(void)
{
static float proportionalityConstant=(-1);`
if (proportionalityConstant<0) {
NSPrintInfo* pi=[NSPrintInfo
standardPrintInfoWithRegisteredPaperName:@"A4"];
// The width of an A4 sheet is 20.99 centimeters
proportionalityConstant=([pi paperSize].width)/20.99;
}
return proportionalityConstant;
}
The problem, of course, is that
standardPrintInfoWithRegisteredPaperName: does not exist ...
Any suggestions ?
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