Possible QFontDatabase missing feature



  • 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


  • Moderators

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



  • @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;
    }
    


  • 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?


  • Moderators

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


  • Moderators

    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.



  • @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?


  • Moderators

    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.



  • Thank you. Yes, we parse CSS manually.

    Where do I open a feature request?


  • Moderators




  • Moderators

    @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 ;)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.