Inaccuracy with g.getStringWidth()?
-
@aaronventure Thanks for confirming, will do! It's just an aesthetic thing, I don't like the squashed look you get with drawFittedText()
-
@cynthasiser I think spaces might be misbehaving? Does it always fit correctly if you don't have the spaces in the string?
-
@cynthasiser Okay I'm very confused now, was just about to bug report when I tried the broken snippet again and it works now, it's displaying the correct amount of tests, with no ellipsis:
The code is identical as before, but it works now.
One important realisation though - the font being displayed in both the original broken version, and the current working (despite being identical) one, is Arial, not Oxygen as I specified.
Comparison using labels:
So it seems the behaviour is coming from a confusion between Arial and Oxygen, even though the code explicitly says to use Oxygen.
I'm using version 3.6.2 btw
-
@aaronventure No, I thought that too when I was getting the initial wrong behaviour, but I tried it and it still cut the text off
-
@cynthasiser I've also tried various other fonts in g.setFont, and they all display. I tried typing random words as the font, and they default to Arial when not recognised, so it seems my issue is that g.setFont cannot find Oxygen by name. The font exists on my system though, as labels can successfully display it.
-
Is the text something that is going to change at run time?
-
@d-healey it is yeah
-
Yeah that definitely makes it more problematic. Also be aware that fonts often render at different sizes on Windows and MacOS, so you might have more fun to come.
-
@d-healey Looking forward to it haha!
I've also realised I have two versions of HISE on my PC; 3.6.2 and 4.0.0 which is what caused my confusion. One's a desktop shortcut and the other was coming up when I searched HISE in the start menu!
The random difference in behaviour that I posted about earlier was a result of using different versions. In 4.0.0, I get the cut-off text with the ellipsis, whereas in 3.6.2 I get the "working" version, but BOTH versions fail to display the text in Oxygen when I say g.setFont("Oxygen", 20), and display Arial instead.
In 3.6.2, my code works with all fonts; even when I ask for Oxygen and get given Arial instead, g.getStringWidth knows we're in Arial now and scales correctly. Interestingly, if I put g.setFont("Default", 20) (the default being Oxygen), HISE crashes. Typing in font names that don't exist just makes the text display in Arial, so something about specifically "Default" really upsets g.setFont() in 3.6.2.
In 4.0.0, my code produces the cut-off text in every font I try. Using g.setFont("Oxygen", 20) still doesn't work and gives me text cut-off and in Arial. BUT when I try g.setFont("Default", 20) in 4.0.0, I no longer crash, but get Oxygen.
So what we've learned is:
- g.setFont("Default", 20) causes a crash in 3.6.2, which seems to have been fixed by 4.0.0
- g.getStringWidth() did work in 3.6.2, but doesn't anymore in 4.0.0
- Neither version can correctly display Oxygen using setFont(), at least in a paint routine on a panel.
I was able to replicate this in a fresh project; I draw a line 200 pixels long, draw text that clearly exceeds the line, and g.getStringWidth() tells us that the text is only 196.7 pixels. In 3.6.2, it says the text is 215.5 pixels which seems about right.
HiseSnippet 903.3ocsVstaaaCElxIJH18BZA5C.g+kCVfgc5kMfhh5Dm3Ai1jZLm0shggBFoijXCEoFEURbGJ16XeR1aP5gTxwxKAosFXFvF5b46vOctQOQqBf7bkl3073YY.w6t9SmIMICSXbIY79Du66eHK2.ZZop8lkwxygPhm2Z+rUgWy0ItO+6K2iIXx.XgJB4sJd.7ZdJ2rP6jAuhKDiXgvw7zZd+jAiCTxgJgp.4yZ98HYrfSYwvQLqaM7IdabPH2nzSMLCji9rmJb1zD04xR+eKOmeh.rB8ISw.UplLLgKBmL+cMmP7Vexh270Jeyej+g7P9U5WjAdfy.cAh54.uF2Fk5+cPIuZTZ8RJ8P+oAZdlYgEKeti+XIVPhXXptNUJ8kznaC+gJzCooaJ6TXjFEtBQmm0q21T7msddqVX5N2POioooylvjff9B5bnwfYnJMSIQgNscV621Bpx0t4fYBlhL+hpvvkPmnBYfgqjch2p0e2pYb2HrJuqPzorhl2k8wBMfQ.MEpYm+ZKHjK6XIT+puO1ZuUSKkBUwGCWXPJ01j.z+pfGbJ8DMlYoQpKnenHMCBopyvVSqcA6iyrXZ6BPrkdiTVpuqlyDswvuyhydWAOVBg132o5b1l9GNxfbnm6g+baZaADYZWRILujqDP2LM2FUG0NmGZRn7bZa5OPisoroFzb7uY0OOvag3+zVOed5gpjGoLvajcbooVepE8+ZJJ5FsYqLZkP.5azrcXRea.6HKROAzaiEbQAbkiX21xsva7s0BGT1nTyQkbrjadSFTIORIBssl1mudCOopSCe5WGuOyvry.U5P+x.sgaoi29vY3RjxIhl96C4mZTYNeqZOIdaZbVu274EaCJ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