On-the-fly font substitution is awesome! How to turn it off?



  • Is it possible to turn off on-the-fly font substitution? How does it even work?

    I'm trying to pick a font that supports a unicode subscript two: ₂ (U+2082). I am putting chemical formulas like H₂O in translatable text and need to find a good looking font that I can embed in my QtQuick application.

    My favorite font manager shows an empty box when a font does not support subscript two, but I have to click through the fonts one at a time... I want to go through about 300 fonts. This is tedious.

    So I had the bright idea to write a QML font viewer. Amazingly, every font supports subscript two. I look closer and many fonts are using the same glyph for the subscript two.

    It seems that QtQuick substitutes a suitable font when a glyph is missing from the requested font. It is amazing that the framework is capable of this on-the-fly without any code on my part. But I still don't know what font to embed in my application to that it will display consistently on another system.

    Can anyone tell me how to turn off on-the-fly font substitution in a QtQuick application? If not, can someone point me in the right direction so I can understand this magic?

    For reference, here is my font viewer code:

    import QtQuick 2.0
    import QtQuick.Window 2.0
    import QtQuick.Controls 1.0
    
    Window {
        visible: true
        width: 600; height: 800
    
        TextField {
            id: sampleText
            anchors { left: parent.left; right: parent.right; top: parent.top }
            text: qsTr('H₂O + C₁₂H₂₂O₁₁ = sugar water')
        }
        ListView {
            anchors { left: parent.left; right: parent.right; top: sampleText.bottom; bottom: parent.bottom }
            model: Qt.fontFamilies()
            clip: true
    
            delegate: Rectangle {
                height: Math.max(output.contentHeight, name.contentHeight)
                width: ListView.view.width
                color: (index % 2) ? '#DEF' : 'white'
    
                Text {
                    id: name
                    anchors { left: parent.left; verticalCenter: parent.verticalCenter }
                    width: parent.width / 4
                    elide: Text.ElideRight
                    font.pointSize: 12
                    text: modelData
                }
                Text {
                    id: output
                    anchors { left: name.right; right: parent.right; verticalCenter: parent.verticalCenter }
                    elide: Text.ElideRight
                    font { pointSize: 24; family: modelData }
                    text: sampleText.text
                }
            }
        }
    }
    

Log in to reply
 

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