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. Possible QFontDatabase missing feature

Possible QFontDatabase missing feature

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 2.6k Views
  • 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.
  • G Offline
    G Offline
    geometer
    wrote on last edited by
    #1

    Hello,

    We're developing an ePub book reader based on Qt.

    ePub file is just a zip archive, that includes book text as well as some assets, including ttf/otf fonts. We load these fonts via QFontDatabase::addApplicationFontFromData(), but the only way to access the loaded font that we found is to call QFontDatabase::applicationFontFamilies(fontId), and then to create font object as QFont(family). The problem is that some ePub files contain several font files with the same family, and Qt does not provide access to all of them.

    Do we miss something? That would be great to have a way to access the application font by fontId rather than by family.

    The ePub file that contains two fonts is https://github.com/IDPF/epub3-samples/releases/download/20170606/cc-shared-culture.epub

    raven-worxR 1 Reply Last reply
    0
    • G geometer

      Hello,

      We're developing an ePub book reader based on Qt.

      ePub file is just a zip archive, that includes book text as well as some assets, including ttf/otf fonts. We load these fonts via QFontDatabase::addApplicationFontFromData(), but the only way to access the loaded font that we found is to call QFontDatabase::applicationFontFamilies(fontId), and then to create font object as QFont(family). The problem is that some ePub files contain several font files with the same family, and Qt does not provide access to all of them.

      Do we miss something? That would be great to have a way to access the application font by fontId rather than by family.

      The ePub file that contains two fonts is https://github.com/IDPF/epub3-samples/releases/download/20170606/cc-shared-culture.epub

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @geometer
      The one font is called Quicksand Bold Oblique and the other Quicksand light.
      So the family may be the same, but their rendering and style are not!
      Means you create a QFont from the family "Quicksand" and which final font is loaded depends on if either you set it to bold or not.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      G 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @geometer
        The one font is called Quicksand Bold Oblique and the other Quicksand light.
        So the family may be the same, but their rendering and style are not!
        Means you create a QFont from the family "Quicksand" and which final font is loaded depends on if either you set it to bold or not.

        G Offline
        G Offline
        geometer
        wrote on last edited by
        #3

        @raven-worx Unfortunately, it does not depend. If I load both, it uses Light not depending on 'bold' attribute is set, or on the loading order. Qt 5.10, MacOS 10.13.3.

        On the other hand, even I do as you describe, this is not a complete solution. CSS file defines own family name and style and there is no guarantee that it would be the same as defined in the font file. In the sample file, there is the definition that changes the family name; I'm afraid they could change the styles as well.

        @font-face {
            font-family: 'QuicksandLight';
            src: url('../fonts/Quicksand_Light.otf') format('truetype');
            font-weight: normal;
            font-style: normal;
        }
        
        @font-face {
            font-family: 'QuicksandLight';
            src: url('../fonts/Quicksand_Bold_Oblique.otf') format('truetype');
            font-weight: bold;
            font-style: normal;
        }
        
        1 Reply Last reply
        0
        • G Offline
          G Offline
          geometer
          wrote on last edited by
          #4

          Heh, it seems like the sample file is the sample of CSS-changed attributes too. "Bold Oblique" means "bold AND italic", but the CSS defines "just bold". And this is why my code does not work. This is not a Qt bug, QFont("QuickSand", .., true, true) loads bold oblique version.

          However, there is no way for me to know which font style was loaded, is it?

          raven-worxR 1 Reply Last reply
          0
          • G geometer

            Heh, it seems like the sample file is the sample of CSS-changed attributes too. "Bold Oblique" means "bold AND italic", but the CSS defines "just bold". And this is why my code does not work. This is not a Qt bug, QFont("QuickSand", .., true, true) loads bold oblique version.

            However, there is no way for me to know which font style was loaded, is it?

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by raven-worx
            #5

            @geometer said in Possible QFontDatabase missing feature:

            However, there is no way for me to know which font style was loaded, is it?

            not that i am aware of.
            As you can see the different font faces can be loaded combined in a single file or in separate files.

            What are you trying to achieve exactly?
            You want to display the contents of the epub using Qt widgets, right?
            Are you parsing all the information from the HTML files?

            (nvm i think i figured it out myself)

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              A wild and most probably wrong thought: can you select proper font using font foundry perhaps?

              QFont myFont("Quicksand [Light]");
              

              Maybe that info can be extracted from the otf file.

              (Z(:^

              G 1 Reply Last reply
              0
              • sierdzioS sierdzio

                A wild and most probably wrong thought: can you select proper font using font foundry perhaps?

                QFont myFont("Quicksand [Light]");
                

                Maybe that info can be extracted from the otf file.

                G Offline
                G Offline
                geometer
                wrote on last edited by geometer
                #7

                @sierdzio said in Possible QFontDatabase missing feature:

                QFont myFont("Quicksand [Light]");

                Sorry, not sure I understand. I can access both loaded fonts, one as QFont("Quicksand", size, false, false), the second one as QFont("Quicksand", size, true, true). The problem is that I need to access exactly "the font loaded according the CSS specification". How do I know that the font loaded for

                @font-face {
                    font-family: 'QuicksandLight';
                    src: url('../fonts/Quicksand_Bold_Oblique.otf') format('truetype');
                    font-weight: bold;
                    font-style: normal;
                }
                

                from the file "Quicksand_Bold_Oblique.otf" is bold and italic? I can know that its family name on Qt level is "Quicksand", via

                QFontDatabase::applicationFontFamilies(fontId)
                

                call, that's fine. But how do I take its style?

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  Ah, ok, I understood this the other way around :-) So the font is being loaded by some CSS parser and thus you don't have direct access to that info? You've mentioned you are loading it yourself... so I'm a bit confused. If you are loading yourself and you have all the info mentioned in the CSS snippet, then it should be possible to extract all the details, even if it means parsing the CSS manually. Sure, it would have been better if Qt extended font ID functionality, you can open a feature request for that or contribute yourself if you feel like it.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    geometer
                    wrote on last edited by
                    #9

                    Thank you. Yes, we parse CSS manually.

                    Where do I open a feature request?

                    1 Reply Last reply
                    0
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #10

                      In Qt bug tracker: https://bugreports.qt.io/secure/Dashboard.jspa

                      (Z(:^

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        geometer
                        wrote on last edited by
                        #11

                        Thanks, done: https://bugreports.qt.io/browse/QTBUG-66382

                        raven-worxR 1 Reply Last reply
                        1
                        • G geometer

                          Thanks, done: https://bugreports.qt.io/browse/QTBUG-66382

                          raven-worxR Offline
                          raven-worxR Offline
                          raven-worx
                          Moderators
                          wrote on last edited by
                          #12

                          @geometer
                          anyway, since waiting to your feature request to be implemented will most probably take some time, you are welcome to make the change yourself and contribute it to Qt source ;)

                          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                          If you have a question please use the forum so others can benefit from the solution in the future

                          1 Reply Last reply
                          1

                          • Login

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