g.getStringWidth is broken in 4.0.0 and g.setFont will not display Oxygen
-
Follow on from my previous post, but I was able to reproduce the bug in a simpler way once I figured out what was happening.
I've drawn a line 200 pixels wide, and then drawn text that exceeds the width of line. g.GetStringWidth() tells us that the text is 196.7 pixels wide, which is clearly false.
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.sgaoi29vY3RjxIhl96C4mZTYNeqZOIdaZbVu274EaCJgiG8l9kctjKpuUZVcAtARmuzo4Fe9xOe4xZ2otZWE+JzC9mAI.ONo1xs2Mfb84XbChJrPvLKuVwt+rx.VnVZV1NuJy4lY02u9crqo2stq4akhOzeB2DjbybrwMvQrD9+AGq1PeO+Chhf.yBBtt+neeUWG+UN9x0ZwGxvIZr4w+nhzoX2P.fmtDaovf660v1FWJ2yJay.SAYnS3R7Skw9VYuJi8majjxBzp2GTNdZuCXSmFjSR2UdMw6dQYZehajsddNEuR58AAKGpqAbmUE3iWUfOYUA9zUE3yVUf+3pB7m95.s+igcKLpzxwFB4vIG31w44cfjgcfttUxWPhDWpi
Further, g.setFont(Oxygen, fontSize) does not display the Oxygen font in a panel paint routine.
-
Do you have the Oxygen font installed on your system?
I just noticed also there is an
Engine.getStringWidth()
function which takes more parameters and might give you better results.HiseSnippet 921.3ocsV8uaaaCDlxIpH1scXEXO.D9ubvLLjSS6FPwvbhi8fQaRMly51vvPAizIItPQpQQkD2gh8N1mj8FjdTRNRd0cavX0.1P2O9N8oie2IOWq7grLkl3z97ko.w4AtKVJMwiiYbIY1IDmOy8TVlAzzRWGuLkkkAADGmc9NqCm16RJ97We6wLAS5C0tHjWo39vK3IbSs24idNWHlxBfy4IMx9vQy7UxwJgJG4yNtdjTl+krH3LlMsVtDm6MIfaT5EFlAxHN6drJX4hX00xx7eEOieg.rFCIKvBU5dpRDXYr0KYbLWDLe0ycFAqx75tvNkcguv8Td.+N+0ciOuH.sFQy9gSq0o2NqQugMomWC5sAJ4zfR6VRoG4tvWySM0Qr749tyj3gSHCa6MoRYtjVSa4NVgYHMCRXWBS0nwcH58TOu9T7m8eVmNXqOyPuhooIKmyjff9MzUPi.yXURpRhF85VDcXWKnpTGjAl4XKx78pbCWB8Byk9FtR1KZ+N+Qm1QCBwS7iDhdkmtYCXuIWCXEvPAZ10uvBB4xACeRe5PuxuO1FuSaKkBTQmC2XPJ00DCzeOm6eI8BM1Yogpan+VdRJDPUWgxTabA6MKsX5VTfHK8lprT+HMmI5hk+f568QBdjDBr0uW08oO8WrjwxAuhK909ztBHzzsjRXeISIfAoZtspET6ZdfIlxyncoeIchLBehr8sEFLmnezFrt5M3Qep2.uC2Gq6a2+YqZaTk7LkAdorWQ6qya6P+6gBC2XL6IlVIDfdigsCb5+If8j4IW.59nPPjC2kHpBWWZ69wk1Mm77KEPMRTImI4lWlBxO17HoR0gW8CyNgYX14gJeXdof1vsTv4D3Jb4R4zQa2SfrKMpzhbqjpDm8LEQe3pYGqXkvwIj8bKUwjaZtsZYSCtARVsLp88d2su6108dPS2Em92gdzeNJF3QwMV58yiHe3LMtMQEjKXl0WwX2qVE.ObVat1N6Jy3lkM269+1dm+qT7Qty4F+3MywVafi3Q3mBNVss9gtSBCAeSMA20c5O8oY0LobEWzoLbvFEOtmkmr.UC9.d2knjxNb3zxJiKs8r11NvBPFTXbK9oJ3PqsSUvgqBRRX9Z0q8KGIsuOXuBOHmjEuJrM9NYzlNjTLl1rOmfud5099qWpO.3AaKvGus.ObaA9jsE3S2Vfe01B7q+2AZ+2CGkaTIkiMDxoymTriywYhjgJvB0J48P4quJz
-
Oxygen works fine when I use it in a label so it's definitely on my system. If you run this snippet, are both strings in the same font? For me the top one (set as Oxygen in the paint routine) displays as Arial, but the bottom one (set as Oxygen in the font component of a label) displays correctly:
HiseSnippet 1007.3ocsV8uaaaCDlxILH1scXEXO.D9ubPMLrS6ZGPwPch+wfwxOLly51vvPAiDkLWjHUknRhSQw.5S3PeR5aP1cTx1xqNqaFqFvFh2cem93w69nGmncEoo5DhS0ylEKHN2mNYlxLs2TtTQF0m37Ezi4oFQBK2zgyh4ooBOhiyVeGZvo51D6mO7hC4gbkqXoIB4kZoq3HYjzrz53teuLLbH2SblLpTzOo6HWspmNTmA7YKZaRL28Bdf3DNFVEJwYmAdRiNYhgaDoDmsOT6MaxT8Up73eoLUddn.WzgLARTt4g5POjwnURuoxPuwy22oDHKiWVE1JuJ7UzikdxE1WVM9RqC1RDkqGNUVkdasB85TldsKQu0PImRTZ6bJ8P5D2DYrYoGjO2iNRAGN9bnrWlJ4wRp7tJzdZHBkoUD+BwvDXwBDMdZ61MYvO687Z0fRepgcIOgEMaLWIBYeKaNz.gomNJVqfEMpa81oNBpHzVoByXnDY9AclQpDM7yTtFoV0HXuZuoV0fV9vI9AggMxOcSawuIKQ.Y.b4kvu5HDDvk8QB0o36iQ+0phTxSGbl3ZCPo5loB1qyjtWvNOAprLe80reOKJV3wzWBson+P9MyPL0sIH.o2PMR8SudVfPUGx+9Ke4GDJCTBO7Ezn3E0j8qV1.jns8geqIqdnv2TOmSPgIUGJZEmHwzZ41UROyTlLkUm8HV.VylX.2A+DZedh2Cw+IQOPE.Ej6HE.SNHQxCs6hlr1XJe6dOedImoUmnMhSUMrk9ZusF6u6x2es9vS6DcXnHYstwg0j+IfMTYQmKRZBMQgYhEABcvqNVPu6whxSst4MekBTqFojlSiEp6ZVlTzwBO8ii5yMbbVpvFDWrHwHQJ3zWbIHLkOYUk1WjdgQGCZLKZyIN6Zrdev74NrQmHgoqco4S.jqKqzMq7BoQDMWHq5Nu+12e6pV2urY6Q+Bzc+itSExfokDL+ktjR7p1p75H94E759Tss89LQp4N4V+tFnGh3zh9eYPhffVtgf7XYtOTYyEm2klOZYMMQdSIY8FcWcC9muoKGm3hr6lcn3XEbovGI3ARsZurPtYU8W7RmBGP22JhdnvlJUZlU9Ro+2Dk+2RwGRGKMtSWOGqrFNB8neN3XwUYOfNv2W3ZVRvsoC+4OO2aQx0+CNlCxVPGH8jrnIPOiq.d6JXlAm9cpfyo4qaiqwJvDgxyt3V3SgyN3ZmBmcl6jDwcSzuxMWyAurbWqEfSJaqXU3Or.qYcHVcnx04H3t6W45tZp9Hf6uo.e7lB7IaJvudSA9zME3y1TfeymFH9WqNHynixGaHjiGOvJh63LPwgNPa2J4u.3e16iM
I get the same incorrect result from
Engine.getStringWidth()
unfortunately:Both say 196.7 when the text is visually longer than the 200 pixel line.
-
@cynthasiser Did you check the character spacing?
-
Yeah, drawAlignedText() uses a character spacing of 0, so that's the spacing I want to check for.
I checked by drawing the same string below the original using g.setFontWithSpacing with a spacing of 0 and they're identical.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Ja9sUt1nyn5av+3Min5QtHytYGrdtBtz48HTApboaVHUUmeWeoVgAn6qFopl3TjxUKpdo2+aj9erP7Q34bkSv5wXi0fQnG8SAFKtp7g3IddLGUI.2FO8m9zbuHJ+9E+Sn.sEzAhOMKxF5YbXvpKfYF8zuUC8bZt7.srtBXyDtFg6fmBiC0xVEFGtzHJh5jHekSNmi9x3cMZ.LILshMgOHBjICQFdnp04H3aCdkiS8T8dAt2lF3i2z.2eSC7q2z.exlF3S2z.+lObf5Oc6fLkLJerAgNY9DCItk0DAE5.Mcqn+FIr8EyA```
-
I notice in your snippet you haven't loaded the font, does it make any differnce when you
Engine.loadFontAs("{PROJECT_FOLDER}Oxygen-Regular.ttf", "Oxygen"); Engine.setGlobalFont("Oxygen");
Make sure your font is in the project Images folder
-
@cynthasiser said in g.getStringWidth is broken in 4.0.0 and g.setFont will not display Oxygen:
Oxygen works fine when I use it in a label so it's definitely on my system. If you run this snippet, are both strings in the same font? For me the top one (set as Oxygen in the paint routine) displays as Arial, but the bottom one (set as Oxygen in the font component of a label) displays correctly:
Both are the same when I open the snippet, but the spacing is different.
Neither of those fonts looks like Oxygen to me - same in your image. The top one looks more like Oxygen but it isn't. I'm assuming we're referring to this font - https://fonts.google.com/specimen/Oxygen
-
@d-healey perhaps because Oxygen isnt loaded?
-
You're right, your second one looks like Arial again with no spacing, and mine doesn't seem to be Arial OR Oxygen, its got the 'g' with a loop which neither font has (looking at the Google Fonts site). Is Oxygen definitely the selected font in your label? Do you have the option for Oxygen in the drop down menu? It's right at the top for me:
When I search for Oxygen in my HISE folder I find it in HISE-4.0.0\hi_core\hi_images along with a few other fonts. The date modified is the exact time it was compiled so it must be native, but it's in a different place to the other fonts.
I think it might be an old version of the Oxygen font that HISE uses in its own display. Image below shows the words "Interface Designer" as they appear in the HISE UI, and then below, a HISE label in Oxygen, 3.5, saying the same thing, they look the same to me!
So the Oxygen font shows up in the drop down font menu in labels, but cannot be accessed by
g.setFont()
, I guess because it doesn't look in the folder that Oxygen lives in.I'll download the current version of Oxygen and load it myself like @Lindon suggested to avoid any more trouble. Perhaps it's worth hiding the font from users in the drop down to avoid the confusion?
-
@cynthasiser yep it all renders the same if you load the font correctly:
HiseSnippet 1060.3ocsV8uaaaCDlxIJH1qcXEXO.D9uTv7LrS6ZGPwPsi+Qg2RhMh851vvP.sDkLWnHUknRhSPvdEG5Cw968FjcjR1Vd0YcyX0.1v7t66zGOd2G0nXoKMIQFirJOYdDEY8H6wyEpYclQXBzftHqO09DRhhFiyLcz7HRRB0CYYsyq0FrJuKx74Oe0QDNQ3RWYBgdij4ROlExTqrNp02w379DO5DVXgneVqAtRQGIWlB7YG6FnHh6Ej.5oDcXkrQV60yiojwiUDEMAYs6QRu4imIuRjE+aXIrobpdQSzXHQYl6K4dZFqsh5Liw8FsXemffrLZUUXmrpvmaeByisz9ppwmYbfWgnX8vpz5zam0nWyhzqQA5sAJYUfR6lQomXO1MlEoV4QymOwdf.Nb7IPYuHUxhEU5OJY2QBQHT0CIWP6GCKVhv44MZTCC+bvKqzSDvDz5bIwqODS6Dmp2N5rgeauNSNu+vi616r6Fd87.p3KOiFjxIw0UJ+p0vUyrVERwhbjPUulKmR35D4TL.33MQgujDiCmOhHnb72fWPu.ppiLLRJnZPFuMMfxCUm1Qvwf5LYpBdLN9oBWESJbBNnxsUJGT2G5pZy4NYcPI0I2jFSgL.t7hIWcrFDreOTuoal+8oZ+UJqojmLXB8ZEPoppYT7aSYtWfmFCmdXe403eMMLh5gkWBiBZ+bxMy0XpZRPfldqseg7e3pGdaNKPP8zO.m7GTM7OaXCPhFl+7KP0jS8UUy3DTXRjbZ8nXlNsFtcEySMCyRvUweANPWyFq.2A+f19hDefF+GDc9g0lSAvj1wLB2rKpganS4cG7xEkbrTbpTQGJbLk9J2UA+2c46uQe5S6XImSi2nasfP7+DPGQZ3TZbMnIhmRWFHLkr9nm8CO5UTYvMq4qPfRw.ASMLhJdH8BTdGK7uuePWhhnmWysAwEQiULMEr5RuDD+xldKa2klbgRFA5XKayQV6qLde7hYaciNhASv6amMAfttnZ57hKXJZ3Bwxx68t6e28qa8vhlMG8KQ252ZMixBlUPT9mZgJvqJqyqiISy40irkl16IzD0CxstsTPODxpt8+kAIjFzpMDjGCy8gJa1E.6amMZYLMlcSgqNbZs9F72usEQOwEZ1M6YqGqfKddOQUPNW5ApYp0030Wrk6.59VSXUKdJRXp4Eu36+Mg++sT7I1iXJ2Yalik1.GgdzOFbL+5xGa2y2m5pVQvcs6+iebtaDko+GbBAjsfNP6SSCGC8LtT3oKfYF8zuUI8bZ15F505JvXpvyr3d3Styl50V4NatvIJj3FKO2MSyQeg79FK.mDlVwxvKEAqwMQFcnh04P38CN20c8T8d.ObaA9zsE3y1Vfe01B74aKvWrs.+5OLP8qu0NUICyFaPnSF0yHhaY0SPfNPS2J5u.kBZGSC
-
Still seems like an issue that Oxygen shows up in the font drop-down menu. It makes the user think it's a native font that
g.setFont()
could render without trouble. -
@cynthasiser said in g.getStringWidth is broken in 4.0.0 and g.setFont will not display Oxygen:
Still seems like an issue that Oxygen shows up in the font drop-down menu. It makes the user think it's a native font that
g.setFont()
could render without trouble.Well you need to be a bit more sophisticated than that., when comparing these two examples : One is loading thru the HISE application itself and the other is loading and rendering in your application,.. So essentially the difference between running your application in HISE, and running it compiled.
Frankly this font loading is one of the first things I learned in HISE and I've been doing it ever since. I'm not sure if its part of the current learning resources for newbies, if not then it should be.
-
So is it normal practice to copy any fonts you want to use for a project from your system's Fonts folder into your HISE Projects Images folder and load them in code if you're using paint routines?
I can't remember where I learned to use
g.setFont()
but it always worked with all of the default Windows fonts without loading them like this so I never realised it was part of the process. -
@cynthasiser said in g.getStringWidth is broken in 4.0.0 and g.setFont will not display Oxygen:
So is it normal practice to copy any fonts you want to use for a project from your system's Fonts folder into your HISE Projects Images folder and load them in code if you're using paint routines?
Yes, even if you are not using paint routines, you have no way of assuring yourself that the user will have the specific font you are using - so you need to ship the font with your application, by placing it in the Images folder and calling Engine.loadFontAs
I can't remember where I learned to use
g.setFont()
but it always worked with all of the default Windows fonts without loading them like this so I never realised it was part of the process.And your MacOS users? - They will likely not have your default Windows fonts...
-
@Lindon That makes sense, thanks!
Loading fonts seems to have fixed the issue with
g.getStringWidth()
in 4.0.0 too.It's weird that it worked correctly even on unloaded fonts in 3.6.2, but in 4.0.0 using it on unloaded fonts gives you an incorrect pixel width. It's like the Windows fonts were loaded by default in 3.6.2, but in 4.0.0 they're loaded wrong. Could that difference in behaviour between versions indicate some kind of problem?
And is it worth adding a warning to users (whether in the software or in the documentation) when they use
g.setFont()
on unloaded fonts if the intention is that fonts should always be loaded in code? To me, the font loading part in the documentation reads as an option for adding your own fonts rather than a necessary step. I think I just read the correct syntax for setting a font, tried it and it worked, so I never had an indication that anything was wrong until now.Either way, it looks like neither method is bugged, they just misbehave when you don't load fonts properly, so problem solved!