Font readability across devices?

Started by
1 comment, last by Bregma 5 years, 9 months ago

I want to create a good all round font system I can use throughout my apps. So I did some research on how Google does there layout, especially font sizes for different elements. Turns out they introduced SP, a font size similar to DP but takes in a scaling unit so user can enlarge all the text if the want while still maintaining the general look. I figured I start by creating a couple font elements from the google design guide below, they use there own Roboto font for this and the image below for reference. Since it's an image, obviously the text is already in pixels so the actual sizes cannot be used for reference.

1*ixGmwiBtnhwWqBAOi2AJIQ.png

 

I am using LibgDX and since LibGDX works with bitmap fonts I use the Freetypefont library to generate them at runtime.DP or density independant pixels are relative to a 160 dpi screen. So to get the amount of pixels we need to divide the screens actual PPI/DPI by 160 (for mdpi screens) to get pixel density relative to mdpi and then multiply that pixel density by the DP amount listed in the above image as SP. In LibGDX there is a function to get the density factor right away: Gdx.graphics.getDensity() so to get the body font google is using I do:


parameter.size = (int)(14 * Gdx.graphics.getDensity() * scale);
BitmapFont body = regular.generateFont(parameter); // regular is the FreeTypeFontGenerator holding the Roboto Regular font.

And rendering this to my S8 screen is working great. The S8 has a pixel density of 3 so the DP/SP value gets multiplied by 3. Now I tested this on my monitor and the font is barely readable. I checked the PPI/DPI of my monitor and that is roughly 96 so 96/160 = 0.6 pixel density. So the body font on desktop will be 14 * 0.6 = 8.4 pixels so it is unreadable but funny enough the same size as my S8. But why? Shouldn't I end up with the same size font in CSS for both desktop and my S8?


body {
   font-family: 'Roboto', sans-serif;
   font-size: 14dp; // or sp
}

Yet the CSS is somewhat bigger and thus readable. I'm not sure comparing with HTML is the correct way but as far as I understand Google uses it for all it's layouts so also CSS. Anyway, when I just create my font with size 14 it will match the CSS. But obviously since the font is now 14 pixels on my S8 it will be really small since the pixels are so tightly packed.

So what am I doing wrong? Are the numbers wrong? Have I some setting somewhere that makes my website text bigger then it should? Do I have an error in my understanding or calculations?

Advertisement

You're forgetting viewing distance.  It's the important thing when it comes to apparent type size, pixel density is only important when it comes to rendering.

The goal is to render at a size such that 12-point type appears to be 12 points tall subtending the view arc.  There are 72.27 points to the inch (hey, the 12th century CE was pre-metric), so traditionally what gets done in the size of an inch gets stretched or shrunk appropriately so everything fits.

The general rule of thumb is handheld devices are viewed at about 30 cm, a computer monitor at about 60 cm, and a TV at about 300 cm. If you were rendering text on a 72 DPI standard computer monitor (until recently modern monitors were 96 DPI because Apple held patents on subpixel rendering and Microsoft compensated by requiring larger monitors so their text would look better, long sad story) you want to render a 12-point font 12 pixels high.  On a 300 DPI phone screen, you would want it about 25 pixels high, except it's half the distance from your eye so it need to be less.

What I'm trying to say is you need to take viewing distance into account, not pixel density of the display.

Stephen M. Webb
Professional Free Software Developer

This topic is closed to new replies.

Advertisement