Ofek Ron
Ofek Ron

Reputation: 8588

Fonts and their sizes on different machines

I am writing a gui PC program with java and I am using Java Swing, the question is, for a given Font, with a given size and style, on a given String, i compute the bounding box (in pixels) on some machine, is there a possibility that on some other machine, for the exact same Font and exact same String, the computed bounding box will turn out different?

if it is possible( which seems to be the case according to the results I get on my program ), then how can i define a font where for a given string, in every possible machine, it will return the exact same bounding box?

Upvotes: 1

Views: 828

Answers (2)

Giulio Franco
Giulio Franco

Reputation: 3230

You can't, because the rendering depends on several factors:

  1. The font itself: some computers may not have the font you requested, or the font may have the same name, but be different in its substance. You can avoid this by embedding custom fonts in your deployable package.
  2. The screen resolution: fonts are rendered accordingly to the screen resolution in DPI. On screens with higher density, fonts will be bigger (in pixel size), because they'd otherwise be unreadable. Think, for example, of Apple's retina displays, whose resolution is close to 400dpi, compared to a normal screen, with a 72dpi resolution. A string which is 72px high will take 1 inch on the normal screen, being perfectly readable, while will only occupy 0.18 in, being hardly readable.
  3. The user has the right to customize the size of his fonts. If I'm presbyopic I'll want a bigger font size.

EDIT

Or, you can fool the system by using pre-rendered strings (saved as raster graphics or even as SVG paths), but beware of the issues I presented you.

Upvotes: 2

mKorbel
mKorbel

Reputation: 109823

this is the intersection, setting :

  1. Native OS,

    • accesible, instaled Font (Native OS uses different Fonts, size, bold ....)

    • theme in Native OS

    • Font (its properties) used for theme

    • various users setting, customs themes

    • idiotics custom application that can change global properties in Native OS, not applications setting

  2. LookAndFeel

    • L&F uses own Font, are different

    • by default the same options as for Native OS

    • i**** custom application that can change global properties in Native OS.....

  3. very different and too hard job is to change Font based on screen ration (in pixels),

  4. any changes are about to iterating in UIManager and to change every key for FontUIResources

Upvotes: 1

Related Questions