43

I am a visual designer, working on an android design and I"m trying to spec my PSD file for our engineers. I cannot seem to find any documentation regarding the conversion of point size to SP for the type in any Android documentation. (Just that SP should be used for type).

Megatallica
  • 431
  • 1
  • 4
  • 3
  • 1
    i don't know its correct or not.. In that formula is working for me. sp=(pt/72)*densitydpi. example(sp=(9/72)*160).. – Arul Pandian Mar 05 '14 at 12:19
  • 1
    See my post on this here http://systemdotrun.blogspot.co.uk/2014/09/whats-point-in-font-sizing.html – Dori Oct 01 '14 at 08:23

6 Answers6

45

The problem is that it depends on the density. Really, they're not good measurements to try to compare.

  • Points: There are 12 points in a pica, 6 picas per inch, so 72 (more accurately 72.27) points per inch.

  • Device-Independent Pixels (DP): These will be equal to the pixel size for MDPI displays, 1.5x the pixel size for HDPI displays, and 2x the pixel size for XHDPI displays. (e.g. 12dp = 12px MDPI, 18px HDPI, 24px XHDPI).

  • Scaled Pixels: These will be equivalent to the DP value, but scaled according to the user preference to be smaller or larger.

If you're designing at 72 dpi (Photoshop default DPI setting), an 8pt font would be equivalent to 8px, which would be 8px at MDPI, 12px at HDPI, and 16px at XHDPI, or more simply 8dp for all densities. I don't know how much scaling gets applied to different SP settings, so you'd have to hunt that out, but basically I would just give them the mockup and let them size it appropriately from there -- surely they can get it pretty close visually from that.

Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
  • dp is supposed to be the same as sp , just that it can change according to the user's preference: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension . Also, since most devices out there work on XHDPI, and designers wouldn't probably want to change values for each file (yet work for XHDPI), I think it's better to just divide by 2. – android developer Feb 22 '15 at 14:27
  • This information is very useful. I use this [calc](http://angrytools.com/android/pixelcalc/) to calculate the ratio between photoshop pt to android sp but it didn't make any sense until I saw this answer and realised that 72 dpi photoshop image makes 1pt to be 1dp and the photoshop image I got from my designer is 300 dpi so it makes 1pt to be 4.16dp and we all know that 1dp = 1sp. So now it does make sense :) – Rotem Jul 28 '15 at 21:48
13

In contrast to dp (and sp with minus the user text sizing factor), pt has pretty much the exact same physical measurement. Dp is more or less a rough approximation, since it uses the same factor for a wide dpi range.

You cannot convert pt to sp, like said by Flavio. You can, however convert pt to dp roughly (+/- 30% in extreme cases, but at least expect +/-10%).

Using the dpi buckets (ldp=120,mdpi=160,hdpi=240,xhdpi=320) the most generic conversion factor would be x0.45 (= 72/120*0.75 = 72/160*1 = 72/240*1,5 = 72/320*2) if using the exact dpi bucket values.

For more precise factors:

  • mdpi (scaling factor: 1.0) 10.1" WXGA Screen (149dpi) is 0.483076923 (= 72/149 * 1.0)
  • hdpi (scaling factor: 1.5) Nexus 7 (216dpi) is 0.5 (= 72/216 * 1.5)
  • xhdpi (scaling factor: 2.0) Nexus 10 (300dpi) is 0.48 (= 72/300 * 2)

So 12 pt would be on...

  • 10.1" WXGA: 24.84dp
  • Nexus 7: 24 dp
  • Nexus 10: 25dp
  • dpi bucket value: 26.666dp

You could use the same values for sp, but keep in mind, that these could be in/decreased by the users settings.

Patrick
  • 33,984
  • 10
  • 106
  • 126
  • So to convert from pt to sp/dp, it's (approximately ) a calculation of division by 2 , right? How come many online converters out there get a huge value for sp/dp in this case? – android developer Feb 22 '15 at 14:23
  • They probably use different densities. The one that I use here is the android pt unit, i.e. how android displays x pt which is 72 pts per inch. So its depened upon the density, if you have 300 pt per inch your factors will differ. – Patrick Feb 22 '15 at 14:27
  • Could it be because of the density configuration of PPI ? The default on PS (and other image editing tools) is 72. Maybe you need to change it according to the density you wish to work with, and then it will give you correct values? – android developer Feb 22 '15 at 14:31
  • Yes propably (See edited comment). I did not use this to convert from PS to dp, but to convert dp to android-pt, so I have no experience how good it works with PS. – Patrick Feb 22 '15 at 14:33
  • I don't use PS either. The designer asked me how to convert, since the online tools gives me huge-value results. So how much DPI (or PPI?) you say I should tell the designer to use for images, assuming it's for XHDPI devices? Some websites say it's 300, but I remember that XHDPI is 320... – android developer Feb 22 '15 at 14:37
  • Tell your designer to create a canvas with one of your target devices e.g. nexus 5 1920×1080 px (445 ppi). Then let'em desing the UI. You know that a nexus 5 has 640 x 360 dp, so you can convert the designer PS pixel to dp easily which will work with all densities then (approx) – Patrick Feb 22 '15 at 14:40
  • I think I will just divide PT by 2, and get SP by doing so. I think it's enough, no? – android developer Feb 22 '15 at 14:54
  • Do as you think. For me it paid off to teach our designers how android dpi buckets etc. works. – Patrick Feb 22 '15 at 16:01
  • Suppose I want them to target to XHDPI, I should tell them the use 320 PPI right? – android developer Feb 22 '15 at 16:49
  • You should not "target" any dpi bucket, it should work on all dpi buckets. But if you want a xhdpi baseline use Nexus 4 with 1280 x 768 px / 318 ppi / 640 x 384 dp / xhdpi / Normal screen. You have a good overview of these specs for different devices here: http://www.emirweb.com/ScreenDeviceStatistics.php – Patrick Feb 22 '15 at 16:53
  • I didn't mean to target only it, but use is as the baseline since it's impossible for the designer to work with all possible resolutions and densities out there. – android developer Feb 22 '15 at 17:01
  • @patrickf how you calculated 12 pt conversion here on all three devices. what you multiplied? – Ravi Yadav Mar 20 '20 at 10:09
1

There's no direct mapping between pixels and sp, since sps are dynamically set as the users change the device font size in system settings. The user may want to see all the app fonts in smaller or larger sizes. It's an accessibility feature provided by the OS.

Flávio Faria
  • 6,575
  • 3
  • 39
  • 59
  • Roger that, but when designing the ideal layout of the screen in my PSD...I specify point sizes as this determines the relationship of the type to all other elements on my design...we don't have an SP unit of measurement in Photoshop...so if I pick 22pts for a font...I'm asking how I would mark that up in a spec in SP units. Is there a ways to translate that 22pt to sp for spec-ing purposes? – Megatallica Nov 15 '12 at 19:14
  • also...I do realize that the type will be changed by the user...I'm mainly asking how to communicate my pt size as SP...there has to be some way to convey this as most graphic designers work with typography in pts (not pixels) – Megatallica Nov 15 '12 at 19:18
  • In this case I think that an 1 for 1 mapping fits well. – Flávio Faria Nov 15 '12 at 19:36
1

^What Flavio said. but check out the display metrics class overview on the Android Developers site. You might find what you need here... http://developer.android.com/reference/android/util/DisplayMetrics.html#

ItsGeorge
  • 2,060
  • 3
  • 17
  • 33
  • 1
    sorry I still don't see anything specific to point size --> sp size conversion...I'm looking for a ratio, etc. – Megatallica Nov 15 '12 at 19:22
  • also when I opened up a gui doc from the android dev site (The provided PSD with all the android elements) I clicked on some type, openend up the font palette and the pt size was a 1:1 ratio with the spec provided in the GUI doc... – Megatallica Nov 15 '12 at 19:24
1

This is a great tool to help convert between the various measurements - put in what you know and it'll calculate the rest!

http://angrytools.com/android/pixelcalc/

MarcusTucker
  • 275
  • 2
  • 4
0

There are 72 pts per inch, and 160 sp per inch (with standard font size in the device settings). this means there are 160sp per 72pts. 160sp/72pts simplifies to 20/9. So when converting pts to sp or dp use pts*20/9. As mentioned by others here already, sp does vary by the user's settings so if you don't want the text size to change with the device settings, then use dp.

Ethan
  • 179
  • 1
  • 9
  • Do you have a reference for your statement that there are "160 sp per inch"? [Sp includes scaling based on the user's font size preferences](http://stackoverflow.com/a/2025541/622391), so there isn't a constant conversion factor from sp to inches. – Simon MᶜKenzie Dec 09 '15 at 23:41
  • Yes, but it's the same base 160 per inch as dp, if the user has normal font size in their settings. If the OP doesn't want the font to change with the users prefs then they shouldn't be using sp, they should be using dp. "A dp is a density-independent pixel that corresponds to the physical size of a pixel at 160 dpi. An sp is the same base unit, but is scaled by the user's preferred text size (it’s a scale-independent pixel), so you should use this measurement unit when defining text size (but never for layout sizes)." http://developer.android.com/training/multiscreen/screendensities.html – Ethan Dec 11 '15 at 00:02
  • Then you should clarify your answer to "There are 72 pts per inch, and 160 sp per inch _with standard font size settings_". You currently only mention this at the end of your answer in an aside. – Simon MᶜKenzie Dec 11 '15 at 00:06