Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Custom font behaviour when Windows system locale changed
Forum Updated to NodeBB v4.3 + New Features

Custom font behaviour when Windows system locale changed

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 428 Views 2 Watching
  • 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.
  • B Offline
    B Offline
    Bob64
    wrote on last edited by
    #1

    I have an issue in a QML application, but I don't know whether it is specific to QML or indeed to Qt, but I am hoping that someone might be able to point me in the right direction.

    I am using a custom font that contains some special icon characters. I use this to embed the icons into rich text in a QML Text component using markup like this '<font face="%1" size="4" >%2</font> '. Here %1 is the name of my custom font, and %2 is the unicode character from the font that corresponds to the icon I want to display.

    The custom font is only used for these few characters, and they are all in the "Private Use Area" of the font. So, for example, %2 in the above holds codes such as "\ue902".

    What has been reported to me is that if the System Locale is changed (this is on Windows), the icons disappear from the places in the GUI where these icons are meant to appear.

    I would have expected that the combination of using a custom font, and referencing only characters in the Private Use Area of the font, should mean that a locale change has no effect here.

    Does anyone have any idea what could be happening and whether it might be a Qt-specific issue?

    1 Reply Last reply
    1
    • B Offline
      B Offline
      Bob64
      wrote on last edited by Bob64
      #8

      The solution to this turned out to be straightforward.

      When debugging with the Chinese locale set, I noticed that the text parsing code was not going into the rich text branch and that the face specification was simply being ignored. Therefore it would not have been reading the specified unicode character from my custom font but from whatever font was in effect for the text.

      Recalling that I am working in QML, I noticed I did not have an explicit textFormat setting in my Text components. According to the docs, the default is Text.AutoText which uses a heuristic to detect rich text. I assume that in the US locale this was setting the format to rich text. It is still a mystery as to why this does not always work, but I have not had chance to delve into it further. In any case, ensuring an explicit textFormat: Text.RichText setting in all the relevant places fixes the issue.

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Sounds pretty strange indeed.
        Do you have dynamic translation in place ?
        Does your font gets unloaded for some reason ?
        Does it happen while the application is running or during the next start ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        B 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Sounds pretty strange indeed.
          Do you have dynamic translation in place ?
          Does your font gets unloaded for some reason ?
          Does it happen while the application is running or during the next start ?

          B Offline
          B Offline
          Bob64
          wrote on last edited by
          #3

          @SGaist there is no dynamic translation in place. The other questions I don't know have answers to yet, but they are good suggestions for things for me to look into. Thank you.

          1 Reply Last reply
          0
          • KH-219DesignK Offline
            KH-219DesignK Offline
            KH-219Design
            wrote on last edited by
            #4

            I love a good mystery (sorry if this makes me seem like a "rubber-necker", which on this thread I suppose I mostly am).

            Another "obvious" question or two.

            (You say this was reported to you.) Can you reproduce it?

            Does it matter which 2 locales we are talking about when switching locales?

            www.219design.com
            Software | Electrical | Mechanical | Product Design

            1 Reply Last reply
            0
            • B Offline
              B Offline
              Bob64
              wrote on last edited by
              #5

              I haven't had a lot of chance to investigate yet but I have been able to reproduce it. The bug was reported for a switch from US to Chinese (Simplified) and this is what I tried (I'm in the UK but my locale was already set to US apparently - this is a work machine).

              Switching locale requires a reboot so this is what I did, and I then see the issue when I run the application. This answers the second of SGaist's questions above. I'm not sure yet about the font unloading question that he asked.

              FWIW, while I have the Chinese locale active, I can load my custom font in FontForge (a free application) and can see the expected symbols in the Private Use Area.

              1 Reply Last reply
              0
              • KH-219DesignK Offline
                KH-219DesignK Offline
                KH-219Design
                wrote on last edited by
                #6

                Interesting. (Good that you can reproduce!)

                When you run the app in Chinese (Simplified), are you sure it is even using your custom font? It sounds to me (just an intuitive guess) that maybe something about the environment (or even something in Qt, though I would hope not) could be "overruling" your choice of custom font and essentially trying to say "i know better. the only font that works in this locale is font ABCDEF, so i'm going to force that font instead of yours."

                www.219design.com
                Software | Electrical | Mechanical | Product Design

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Bob64
                  wrote on last edited by
                  #7

                  I have spent some time in the debugger today. First, while I had the Chinese locale activated I put some breakpoints in qfontdatabase.cpp, specifically in the match function. I observed that when my custom font was requested, it was not matching it and appeared to be falling back to a different font. I assumed that this was some progress in narrowing down the issue. Unfortunately when I switched back to US locale I saw exactly the same behaviour when stepping through the code!

                  I can't spend a lot more time on this at the moment as it's not a high priority defect but I will update here as and when I find more information.

                  1 Reply Last reply
                  1
                  • B Offline
                    B Offline
                    Bob64
                    wrote on last edited by Bob64
                    #8

                    The solution to this turned out to be straightforward.

                    When debugging with the Chinese locale set, I noticed that the text parsing code was not going into the rich text branch and that the face specification was simply being ignored. Therefore it would not have been reading the specified unicode character from my custom font but from whatever font was in effect for the text.

                    Recalling that I am working in QML, I noticed I did not have an explicit textFormat setting in my Text components. According to the docs, the default is Text.AutoText which uses a heuristic to detect rich text. I assume that in the US locale this was setting the format to rich text. It is still a mystery as to why this does not always work, but I have not had chance to delve into it further. In any case, ensuring an explicit textFormat: Text.RichText setting in all the relevant places fixes the issue.

                    1 Reply Last reply
                    2
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      Nice !

                      Thanks for the feedback !

                      Since you have it working now, please mark the thread as solved so other forum users may know a solution has been found :-)

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • B Bob64 has marked this topic as solved on

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved