Text cropped in GUI Controls [AGS 3.6]

Started by TheVolumeRemote, Fri 02/02/2024 07:43:43

Previous topic - Next topic

TheVolumeRemote

I'm currently in a rabbit hole trying to figure out what to do about 3.6 chopping the top of my text off in GUI's, which isn't an issue for me in 3.5.1 and I feel bad starting a thread about it so @Crimson Wizard can I ask, is this still a known issue? I'll be finishing my current game in 3.5.1 but will use the same font in the next one and I see it's still getting cut off in 3.6.1.18 RC and the latest beta and wanted to half bring it to attention and half see if it's being addressed, so that I can use 3.6x in the future. Thanks for any insights :)

Crimson Wizard

#1
Quote from: TheVolumeRemote on Fri 02/02/2024 07:43:43I'm currently in a rabbit hole trying to figure out what to do about 3.6 chopping the top of my text off in GUI's, which isn't an issue for me in 3.5.1

Please give more details; what kind of gui do you have where the text is being chopped? Is it a regular gui, textwindow gui or standard dialog options gui? Is the text on some control or drawn on a DrawingSurface?
Is the text's position changed compared to 3.5.1, or it's the same?
Post a screenshot of both 3.5.1 and 3.6.0 looks perhaps?

Laura Hunt

Quote from: TheVolumeRemote on Fri 02/02/2024 07:43:43I'm currently in a rabbit hole trying to figure out what to do about 3.6 chopping the top of my text off in GUI's

I think something like this happened to me when I moved my project from 3.5.1 to 3.6.0. Check out the Properties panel of your font, and if the "TTF font adjustment" property is set to "Resize ascender to the nominal font height", try changing it to "Nothing".

TheVolumeRemote

#3
Apologies for being vague @Crimson Wizard ! The issue with font being cut off is only happening in 3.6, including latest release 3.6.1.23-P1. The font and issue was not present in 3.5.0-27 and 3.5.1-27 which most of my game has been developed in.

If I change nothing with the font settings it is cutoff. Following @Laura Hunt 's suggestion to turn the TTF adjuster to Nothing unfortunately makes it much worse (thank you for trying to help Laura, I appreciate you!).

In 3.5.x I had my LineSpacing at 16, changing that in either direction in 3.6.1 doesn't help. In 3.5.x my vertical offset was set to 0. In 3.6.1 I can get the font to display without being cutoff if I set it to 2, but then the font is much too low and will not center in any of the GUI buttons (I assume the ideal outcome would be default settings from 3.5 would work in 3.6).

Lastly, the font is only cutoff in GUI's, especially/consistently in Display like, text banners. The problem doesn't arise in normal speech boxes.

I'm attaching example screenshots and a link to download the font I'm using- I have notifications on so if you have any follow-ups or if I can help you help me, I will be quick to respond. Thank you :)
Download the Font

what it looks like in 3.6.1
Screenshot-2024-04-17-at-6-29-03-PM" border="0
Screenshot-2024-04-17-at-6-29-31-PM" border="0

what it should look like
Screenshot-2024-04-17-at-6-54-44-PM" border="0
Screenshot-2024-04-17-at-6-53-45-PM" border="0

Khris

#4
I opened the font in FontForge and I noticed that the midline is relatively low. (It also has a bunch of wrong references.) In short, this is primarily the font's fault.

I'd recreate it as Bitmap font using Radiant's FontEdit

Not a font expert at all but I did try to fix the ttf one:
https://drive.google.com/file/d/1lD-noS5inc59PZX8pqtS4JJi37mnTHAQ/view?usp=drive_link

Crimson Wizard

#5
@TheVolumeRemote,  fixing the font, as Khris suggested, is one option, but I'd like to find out what the problem is exactly, and if there's a way to fix this within AGS, to be sure that nothing is missed.
It's also quite strange that your font is cut in some places, but not the others. There must be a reason for this.

EDIT: I suspect that maybe labels calculate the font size incorrectly, or simply do not have enough height for it.
Could you tell, how is this "Quick Saved" is made, is this a Display command, or a GUI?
What is the value of "GUI controls clip their contents" in General Settings -> Visual section?


EDIT2: I just realized, but this question is different from the original problem in this thread. May the mods split this out, starting with the first post here? (@Gilbert):
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/a-few-more-noob-questions-for-my-dialogue-gui/msg636660756/#msg636660756

eri0o

@Crimson Wizard you can find the same issue if you run my old version of Future Flashback. I think it's a double error in the engine of the labels positioning the text differently from before and they are incorrectly set to clip.

Snarky

Quote from: Crimson Wizard on Thu 18/04/2024 08:54:28EDIT2: I just realized, but this question is different from the original problem in this thread. May the mods split this out, starting with the first post here? (@Gilbert):
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/a-few-more-noob-questions-for-my-dialogue-gui/msg636660756/#msg636660756

Done.

Original thread here.

Crimson Wizard

#8
So, this happens because engine incorrectly calculates future text position with this font, and it's getting cut off by being drawn outside of a texture.
This font's issue may be observed in 3.5.1 editor as well, if you select the label and compare its bounds and text position: a text will be drawn above the topmost label's border.

It works "correctly" with the Software renderer, because software renderer draws everything on a parent GUI bitmap.
But other renderers in 3.6.0 prepare each label as a separate texture, and so are affected by this.
Setting "Clip gui controls" to false won't help here, because engine does not realize that the font is positioned too high.

This cannot be fixed universally by any editor setting alone (rather than changing font itself).
I suppose, as a workaround, you could try duplicating the font, and assigning a separate "version" of it with a different VerticalOffset to labels only. And maybe adjust label's vertical position.

In order to have this fixed in the engine, engine will need to be able to detect that the font is drawn bit higher.
I recall trying to fix this for another font reported by Radiant on github, but failed for some reason, or maybe thought that it's going to complicate the code much. I shall look into this again.

TheVolumeRemote

#9
@Khris thank you so so much for the font, I'll let you know if it works but regardless I really appreciate you taking the time to do that, incredibly kind of you :)

@Crimson Wizard thank you for your help!
"Quick Save" is indeed a GUI, normal gui (height 25, width 75) with a label for the text (height 27 width 76).
The GUI Clip setting in Visual settings was set to False, I did try it on True and nothing changed, but it was False and n/a  over in 3.5.1 where the font is working.

I'll try Khris' font first thing in the morning and if that doesn't work I may stay on 3.5.1 for now, but when beta testing concludes I'll try your very creative solution bc I do want to try the Android compiler and audio pause/resume features in 3.6. Either way I appreciate you so much and lmk if I can be of help w this issue in anyway. Thank you :)

Crimson Wizard

#10
While analysing this font, I found that some glyphs there have "top draw position" higher than ascender. In other words, they ought to be drawn slightly outside the normal font's area (ascender + descender). I was not aware that this is allowed by the TTF, but apparently there's no restriction to this.

I suppose that, if a better way is not found *, the solution could be to run through all available glyphs and measure the maximal found extent of a glyph upwards and downwards, then use this knowledge to report "graphical font's extent" for the engine.

* - meaning, if this is not already cached somewhere inside the font data.


EDIT: this is from FreeType library:
Code: cpp
  /*    The values of `ascender', `descender', and `height' are <...>
  /*                                                                       */
  /*    Unfortunately, due to glyph hinting, these values might not be     */
  /*    exact for certain fonts, they thus must be treated as unreliable   */
  /*    with an error margin of at least one pixel!                        */
  /*                                                                       */
  /*    Indeed, the only way to get the exact pixel ascender and descender */
  /*    is to render _all_ glyphs.  As this would be a definite            */
  /*    performance hit, it is up to client applications to perform such   */
  /*    computations.                                                      */   

Crimson Wizard

#11
Alright, I have a seeming success, at least judging by values I see under debugger.

Opened a PR: https://github.com/adventuregamestudio/ags/pull/2388

I might post a link to a test build here, as soon as it's ready.

EDIT:
https://cirrus-ci.com/task/5215983743270912

eri0o

Hey if it works it's great, but later I think it will be useful to move some the metrics things out of alfont if using SDL_ttf is intended in the future.

I have a weird memory of seeing somewhere a string like "ikl8gjdpq1Tb" used to figure the height extension of a font but can't figure in which code I saw this...

Crimson Wizard

Quote from: eri0o on Fri 19/04/2024 20:03:07I have a weird memory of seeing somewhere a string like "ikl8gjdpq1Tb" used to figure the height extension of a font but can't figure in which code I saw this...

We use a similar line, but only if no real height is reported (WFN, plugin fonts).
https://github.com/adventuregamestudio/ags/blob/1f356b5172a769951d8184e00e66fcf5ab7d1226/Common/font/fonts.cpp#L124-L129

The problem with such magic strings is that you cannot predict which glyph will be "bad", and also, some fonts may not have latin letters at all, for example.

TheVolumeRemote

Quote from: Crimson Wizard on Fri 19/04/2024 19:27:03Alright, I have a seeming success

What a wonderful thread to wake up to! Thank you so much CW, I would very much appreciate a link to the build when it's ready and will get right to testing it :)

As it stands the tweaked font @Khris  kindly made for me works... enough! If not for this news I would have spent a few hours gently adjusting some GUI labels bc the tweak works if the font is adjusted to 10pt instead of 8 so long story short, it would have gotten me across the line but with your update to the engine it perhaps won't be necessary. Thanks to all involved!

Crimson Wizard

Here's the test build. But it is based on 3.6.1. I'm done patching 3.6.0 for now, since 3.6.1 is out.

https://cirrus-ci.com/task/5215983743270912

SMF spam blocked by CleanTalk