HISE Logo Forum
    • Categories
    • Register
    • Login

    Inaccuracy with g.getStringWidth()?

    Scheduled Pinned Locked Moved Unsolved Scripting
    12 Posts 3 Posters 398 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      aaronventure @cynthasiser
      last edited by

      Yep, something is definitely wrong. Gave your snippet a whirl and the method just won't behave.

      Report it.

      On a design note, why aren't you using drawFittedText()?

      C 1 Reply Last reply Reply Quote 1
      • C
        cynthasiser @aaronventure
        last edited by

        @aaronventure Thanks for confirming, will do! It's just an aesthetic thing, I don't like the squashed look you get with drawFittedText()

        A C 2 Replies Last reply Reply Quote 0
        • A
          aaronventure @cynthasiser
          last edited by

          @cynthasiser I think spaces might be misbehaving? Does it always fit correctly if you don't have the spaces in the string?

          C 1 Reply Last reply Reply Quote 0
          • C
            cynthasiser @cynthasiser
            last edited by cynthasiser

            @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:

            e8c92d34-2300-44a7-b102-97695632a5ee-image.png

            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:

            e457876e-d95a-489a-9ce1-ddfd0234b269-image.png

            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

            C 1 Reply Last reply Reply Quote 0
            • C
              cynthasiser @aaronventure
              last edited by

              @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

              d.healeyD 1 Reply Last reply Reply Quote 0
              • C
                cynthasiser @cynthasiser
                last edited by

                @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.

                1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey @cynthasiser
                  last edited by

                  Is the text something that is going to change at run time?

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  C 1 Reply Last reply Reply Quote 0
                  • C
                    cynthasiser @d.healey
                    last edited by

                    @d-healey it is yeah

                    1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey
                      last edited by

                      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.

                      Libre Wave - Freedom respecting instruments and effects
                      My Patreon - HISE tutorials
                      YouTube Channel - Public HISE tutorials

                      C 1 Reply Last reply Reply Quote 0
                      • C
                        cynthasiser @d.healey
                        last edited by

                        @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:

                        1. g.setFont("Default", 20) causes a crash in 3.6.2, which seems to have been fixed by 4.0.0
                        2. g.getStringWidth() did work in 3.6.2, but doesn't anymore in 4.0.0
                        3. 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.

                        72fcdc29-4a00-4678-a9f6-1b3e7e553127-image.png

                        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
                        
                        1 Reply Last reply Reply Quote 0
                        • C cynthasiser referenced this topic on
                        • d.healeyD
                          d.healey
                          last edited by

                          Build HISE from source, use the develop branch.

                          Libre Wave - Freedom respecting instruments and effects
                          My Patreon - HISE tutorials
                          YouTube Channel - Public HISE tutorials

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post

                          52

                          Online

                          1.7k

                          Users

                          11.7k

                          Topics

                          101.8k

                          Posts