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?
You can't, because the rendering depends on several factors:
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.
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.
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.
this is the intersection, setting :
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
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.....
very different and too hard job is to change Font based on screen ration (in pixels),
any changes are about to iterating in UIManager and to change every key for FontUIResources
Related
BACKGROUND:
JavaFX offers multiple layout classes in order to design responsive applications. Sometimes, things like paddings and spacings have to be specified (in px) in order to keep application in good visual shape. Things like fonts are dpi-aware, so we don't have to worry about the sizes of such.
PROBLEM:
Paddings specified in pixels are not dpi-aware, will be always the same.
POTENTIAL SOLUTIONS:
Calculate paddings and spacings in relation to screen size, eg.
public static double calculate(double sizeOnFullHdScreen) {
return (SCREEN_PIXELS / FULL_HD_SCREEN_PIXELS) * sizeOnFullHdScreen;
}
Using invisible texts (as mentioned earlier, fonts and texts are dpi-aware)
QUESTION:
Is there any better solution than proposed?
Assuming you are using a stylesheet to define the padding, you can use units of em to solve this problem.
This is how this is handled internally for JavaFX controls. From the comments in the header section of the modena.css stylesheet:
RESIZING FOR DIFFERENT SCREEN DPI
When the screen DPI changes Windows will use a different font size by default. The default is 12px and can
change to 15px or 18px depending on user preference or screen DPI. On
Mac the default is 13px and embedded will depend on hardware. To make
UI controls scale and be the right proportions for each of these font
sizes we base the padding (which controls size of control) on the font
size. This is done using the CSS measurement unit of a "em" where (1em
= font size). The default sizes are based on Windows default of 12px, as a quick reference here are common px sizes in em units on windows.
(My emphasis.)
Whenever I test these accessibility settings with a larger display size or font size, it seems to almost always break parts of my layout and make it look awful. I really like the feature of autosizing text but these settings being changed seem to making autosizing text useless. Changing the display size also creates issues like weird holes in my table rows for reasons I can't figure out. Weighted views seem to break down in how they should work as well.
I have seen there are a couple of ways to work around these settings and making it so that the user's preferences of these settings do not affect your app. Do you all do this?
I understand the utility of the settings for the users. But, it seems kind of arbitrarily implemented because in order to make the layout work with these settings as a developer you might have to make your text size smaller from the beginning (in order to fit a larger font if user chooses to do this), which would lead to the exact same text size you, as a developer, would have chosen in the first place if you weren't trying to accommodate a larger font size being able to fit. I also believe I have heard that IOS doesn't allow for these accessibility settings to affect third party apps.
I am just curious how you all go about dealing with this. Thanks.
It is possible to ignore the user's preferred font sizing, by using dp instead of sp. Same for display size, if you really want to, you could check the current density and draw something according to that, still sizing things smaller. That's not a good approach. While your layouts will not break that way, the user who prefers a larger font/display sizes will still not be able to use your app, as they need a bigger text size.
There are some different techniques you can use to make layouts scale better:
Use minHeight/minWidth attributes in layouts, instead of hardcoding the sizes of the views.
Check that the constraints in constraint layouts are bound in both directions, not just start.
Allow text views to take up multiple lines, add ellipsis option where user can click through to see more information.
I wrote a blog post covering some of these in a bit more detail: Accessible Text Scaling for Android
Sometimes, however, fixing it for all scenarios will involve rethinking the design.
For iOS, the font settings also affect all third-party apps, it's not just an Android thing.
In general, you should always used scale-independent pixels, especially for a large body of text.
However if your text has to fit into a bounding-box of known size then you should use density independent pixels in order to ensure that the text always fits properly and that all characters are visible regardless of the users' setting.
Actually, Settings font size affects only sizes in sp. So all You need to do - define textSize in dp instead of sp, then settings won't change text size in Your app.
Here's a link to the documentation: Dimensions
I am running RAP(RemoteApplicationPlatform) on a Windows machine.
There is a default theme applied to most RAP widgets.
TableItem.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_MAGENTA))
This code results in lime green font color when applied to a TableItem. For every system-based color code the expected output color is incorrect. I noticed that when applying the same code to a different widget (eg: Button) I get a different color that the TableItem.
Anyone know what is happening here? I have not modified my system color theme in any manner, and the change in colors across different widgets leads me to believe that the GC used in painting is having some problems replicating these colors - as if there were an overlay?
I have a general fear of having to manage resources since I have so many, and need to color match across OS, even if in the SWTResourceManager class and would very much prefer to stick to OS dependent colors.
I will try to find the generated html code for the tableitems. Unfortunately RAP, being generated html/js does not make this easy.
I am writing a game using libgdx, and I borrowed the skin.json (and related files) from a tutorial.
The font being used (default) was scaling in an ugly manner on denser screens, so I generated by own very large font - and in the game itself, I scale it to a reasonable size (basically I use BitmapFont.scale). The font I'm now using is 3 times as large as the previous one.
I changed the reference to which font to use in the skin.json file, and as a result, all my buttons, titles and other things have a massive font being shown.
Is there a way of scaling the font in the .json file? Or anywhere else in the code? Skin doesn't have a setFont() functionality, so I can't create a scaled BitmapFont and assign it)
Libgdx changed this back in April 2015 so that the set answer doesn't work anymore. Took a little bit to find the answer, so I thought I'd leave it here for others since this answer pops up first in Google.
this.getSkin().getFont("default-font").getData().setScale(0.33f,0.33f);
Documentation says that any gets will return a handle to the actual object. So changes will persist.
So I changed the font in skin.json to point to my new font.
Then I used this code
this.getSkin().getFont("default-font").setScale(0.33f, 0.33f);
To scale the 'default-font' (as defined in the skin.json) to the scale I wanted (in my case its 0.33f)
As of 2017 i had to use
skin.getFont("default-font").getData().setScale(0.5f);
for future users.
We have developed a huge application using Java Swings, this is well exceuting and running on all systems, but the problem is the resolution , if the resolution is 1260/768 it works well means all the components including the scrollbar will be visible, even application will fit to the width and height of the screen, but when its below 1280/768 its not fitting the screen, what i do is manually change the system resolution to 1280/768 and also wrote program which will change the resolution, but the problem is most systems does not support more than 1024/768,on old systems its max VGA Cards-1024/768.
What is the way to resolve this?Which layout manager to change?
Update
Our application will be going live in next 5 days, so need something much quicker, tried with FlowLayout but it will not be good UI.
Or how to resize components when maximized or minimized? how is it implememted?
The answer basically depends on how your GUI is designed.
In some cases, a FlowLayout will allow components to wrap around.
JScrollPane wrappers can be added around sections to make them independently scrollable. Along this line of thought, the entire current GUI could be placed in a JScrollPane and set never to be less than 1280x768 such that scrollbars will appear on smaller displays.
JTabbedPanel could also be used to stack sections of the GUI which are not commonly used in unison.
The smaller resolution could use a smaller and especially a more narrow font. It is a huge task to substitute hard coordinates with scaled ones; something like Scale.x(80). But it is a "dumb" dependable solution. If you still can use a smaller font (Arial Narrow?).
Mind, smaller resolution is often displayed on the same physical size monitor. Or with today's tablets tininess is acceptable.