Font Size Calculation

Find quick help here to get you started with Hollywood
Post Reply
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Font Size Calculation

Post by oceanarts »

I'm trying to find a way to adapt the font size to the display resolution.

I tried (and I'm just playing around here):

Code: Select all

Local fontSize = GetAttribute(#DISPLAY, 1, #ATTRHEIGHT / 10)
	DebugPrint(fontSize)
But it seems like division won't work, however multiplication does work.
Any tips?

Thanks!
Development System : Imac G5, MorphOs 3.19
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Font Size Calculation

Post by jPV »

You have the division in the wrong place. You should first query the height attribute with the GetAttribute(), and then divide it. If multiplying does work in the wrong way, you are probably getting some unintented value by luck.

So, like this:

Code: Select all

Local fontSize = GetAttribute(#DISPLAY, 1, #ATTRHEIGHT) / 10
DebugPrint(fontSize)
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Font Size Calculation

Post by oceanarts »

jPV wrote: Tue Jul 15, 2025 7:51 pm You have the division in the wrong place. You should first query the height attribute with the GetAttribute(), and then divide it. If multiplying does work in the wrong way, you are probably getting some unintented value by luck.

So, like this:

Code: Select all

Local fontSize = GetAttribute(#DISPLAY, 1, #ATTRHEIGHT) / 10
DebugPrint(fontSize)
Can I blame the heat on this one?... Please? :lol:

Thanks, man, :)
Development System : Imac G5, MorphOs 3.19
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Font Size Calculation

Post by oceanarts »

Well, this was a dumb idea anyway. Couldn't be that simple.
Development System : Imac G5, MorphOs 3.19
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Re: Font Size Calculation

Post by Bugala »

@oceanarts what do you mean by dumb idea? The fixed version works. It takes the screenheight of display and divides it by ten, and then saves the result to the variable "fontsize".
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Font Size Calculation

Post by oceanarts »

Bugala wrote: Wed Jul 16, 2025 5:00 pm @oceanarts what do you mean by dumb idea? The fixed version works. It takes the screenheight of display and divides it by ten, and then saves the result to the variable "fontsize".
If it came across as me calling anyone but myself and the initial idea "dumb" then I am truly sorry. That was not at all what I meant. Forgive me if that's the case.

It does indeed work, but the font ends up too big or too small in certain resolutions. It needs refinement, but that's going to be too complicated for me at this point.
Development System : Imac G5, MorphOs 3.19
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Re: Font Size Calculation

Post by Bugala »

Ah, no wonder you misunderstood my message wrong, since I misread the reply too. Somehow I read as jPV pointing the error and then instead of jPV also having posted the corrected code, I thought you posted the version of code based upon jPVs instructions.

Therefore I read as you posting a new version of the code (which was actually jPVs) and thought you meant by your "dumb idea" that "this is the code I tried, but it didnt work".

So no, didnt think you called anyone or anyones idea dumb, just thought you were calling your own working code a dumb idea, as in meaning - not working. So was just pointing out that the code actually works, in case you had erroneously thought it didnt.


One thing you need to take into consideration is also the width of the screen. Having 10 percent size of height for a 320x256 or 640x256, will look very different, and similarly 640x256 and 640x512 will look different, as the font size is both WIDTH and HEIGHT, hence in other case WIDTH will span double the amount, while height may stay the same.
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Font Size Calculation

Post by oceanarts »

Yeah, there's a lot more to consider than what I initially thought. Right now it's just better to adjust the font manually for each display, but it'd be cool if i could find a method that works.
Development System : Imac G5, MorphOs 3.19
Flinx
Posts: 342
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Font Size Calculation

Post by Flinx »

To give you something to experiment with, here are some of the first lines of the function I use to adjust the font size to window changes. Maybe it helps.
gConfig["DisplayHeight"] and so on are the default values from my configuration file.

Code: Select all

Const #MAXFONTSIZEFACTOR=0.15

Function p_AdaptToWindow()

	p_RemoveAllMessages(0)

	gDisplayHeight=GetAttribute(#DISPLAY, gLRCdisplay, #ATTRHEIGHT)
	gDisplayWidth=GetAttribute(#DISPLAY, gLRCdisplay, #ATTRWIDTH)
	gRightBorder=GetAttribute(#DISPLAY, gLRCdisplay, #ATTRBORDERRIGHT)

	If gDisplayHeight<10 Then Return ; wenn zu klein, hat das keinen Sinn mehr

	; Faktor für Schriftgrößenveränderung ermitteln
	Local FontSizeFactor=Min(gDisplayHeight/ToNumber(gConfig["DisplayHeight"]),gDisplayWidth/ToNumber(gConfig["DisplayWidth"]))
	Local maxFSize=Limit(gDisplayHeight*#MAXFONTSIZEFACTOR,1,1e9) ; maxFSize ist der Maximalwert
	; neue Schriftgrößen festlegen
	gLRCFontSize=Limit(FontSizeFactor*ToNumber(gConfig["LRCFontSize"]),1,maxFSize)
	gTxtFontSize=Limit(FontSizeFactor*ToNumber(gConfig["TxtFontSize"]),1,maxFSize)
	gTagFontSize=Limit(FontSizeFactor*ToNumber(gConfig["TagFontSize"]),1,maxFSize)
	gMsgFontSize=Limit(FontSizeFactor*ToNumber(gConfig["MsgFontSize"]),1,maxFSize)
You can try out the effect by starting LyricsJukebox with at least one music file with matching lyrics.
oceanarts
Posts: 111
Joined: Mon May 27, 2024 10:42 pm

Re: Font Size Calculation

Post by oceanarts »

Thanks, I'll have a look. I'm trying to do a menu screen and make it as flexible as possible. But I have to worry about the placement of text elements and their sizes too. I wasn't prepared for the complexity of something as simple as a menu screen. :lol:
Development System : Imac G5, MorphOs 3.19
Post Reply