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 offline   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 68030
 
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

Similar Threads
thread Thread Starter Forum Replies Last Post
How do you get used to the DPI scaling on rMBP WorldIRC MacBook Pro 23 Mar 14, 2014 05:58 PM
Scanner DPI? 300dpi or higher or what? DramaLLama Community Discussion 1 Jan 25, 2014 02:32 PM
Custom DPI scaling dusk007 Windows, Linux & Others on the Mac 0 Nov 13, 2013 05:15 PM
Best DPI for scanning textbooks? kylera Design and Graphics 9 Nov 25, 2012 08:55 PM
Does Mac OS X offer Dpi Scaling? plasticsman MacBook Air 7 Sep 14, 2012 11:04 AM

Forum Jump

All times are GMT -5. The time now is 11:22 PM.

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

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