Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 4, 2009, 04:39 PM   #1
Thomas Harte
macrumors 6502
 
Join Date: Nov 2005
What DPI is used by NSString sizeWithFont/etc?

sizeWithFont returns the size of an NSString if you were to draw it in pixels using the font specified. I was wondering: does anybody know what DPI is assumed by this method, or how I can query the DPI at runtime?
Thomas Harte is offline   0 Reply With Quote
Old Nov 4, 2009, 05:40 PM   #2
Niiro13
macrumors 68000
 
Join Date: Feb 2008
Location: Illinois
Send a message via AIM to Niiro13 Send a message via MSN to Niiro13 Send a message via Yahoo to Niiro13
The DPI is whatever the iPhone's resolution is within it's screen physical size. So the normal iPhone window is 320 x 480. If sizeWithFont returns CGSizeMake(320, 480) then the text fills the entire screen.
Niiro13 is offline   0 Reply With Quote
Old Nov 4, 2009, 05:54 PM   #3
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
The DPI on the iPhone is constant: ~160 DPI.
__________________
dejo is online now   0 Reply With Quote
Old Nov 4, 2009, 06:55 PM   #4
Thomas Harte
Thread Starter
macrumors 6502
 
Join Date: Nov 2005
I'm not drawing to the phone's screen, I'm drawing to a CGContext previously created with CGBitmapContextCreate. So it seems the DPI is set by the CGContext and, for now, you don't actually set that — it's just magically picked internally? I guess Apple's sample code in Texture2D initWithString is a good variant on the sort of situation I'm talking about

Experimentally, I'm getting something broadly close to 80dpi. The best docs I can find online is that Desktop OS X's CGBitmapContextCreate will always create contexts with 72dpi, which could actually be what I'm getting, for all I can tell.

So, I guess the corrected question is:
  • if I create a graphics context with CGBitmapContextCreate, what DPI will it have?
Thomas Harte is offline   0 Reply With Quote
Old Nov 4, 2009, 09:12 PM   #5
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
Almost certainly the same as the screen.

I've done this. Make a bitmap that's the size of a string. Draw the string into it. Later draw the bitmap to a view. The text looked as expected.
PhoneyDeveloper is offline   0 Reply With Quote
Old Nov 5, 2009, 04:51 AM   #6
Thomas Harte
Thread Starter
macrumors 6502
 
Join Date: Nov 2005
If it's the screen then the results are very odd. For example, size 24 Helvetica is reported as 29 pixels high. If the reported height was in pixels, the thing was actually working in 160 dpi and Helvetica follows the usual convention that one em = the height of the font then size 24 Helvetica should be 24/72ths of an inch high, which should be 24/72 * 160 pixels, i.e. 53 pixels when rounded to the nearest integer.

As a result, I can say definitively that the reported height is not at 160dpi.

The output is eventually streamed to OpenGL and used for the presentation of a vector thing that uses proper typographic coordinates throughout. So I do really need this information.
Thomas Harte is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Check if mounted volume is in use? / what it's in use by? noire anqa Mac Programming 4 Dec 4, 2010 02:09 PM
What Panel is used in the 24 inch iMac? XLcomm iMac 5 Mar 12, 2008 09:19 AM
what program is used for creating icons? ohio state fan iPod touch Hacks 1 Oct 28, 2007 02:15 PM
How to find out what font is used on a website? Souljas Mac Applications and Mac App Store 8 Aug 16, 2006 09:23 PM
Ipod - anybody know what material is used for the back? phonic pol Macintosh Computers 11 Dec 30, 2004 02:39 PM


All times are GMT -5. The time now is 12:41 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC