This is mainly a problem of the AGG backends. Quartz and QPainter backends already have the correct behavior.
Basically, user code should be able to call show_text on the following string: "Kiva Graphics一番😎" and have it render correctly even if the currently selected font only supports Latin characters.
To get to this point, we need to do a few things:
This is roughly what Qt does, based on a quick skim of the code: https://code.qt.io/cgit/qt/qtbase.git/
QFreeTypeFontDatabase::addTTFile (qtbase.git/tree/src/gui/text/freetype/qfreetypefontdatabase.cpp):
Scans a font for the following information: weight, style, fixed-width, supported writing systems (unicode range, codepage range), family name
QPlatformFontDatabase::fallbacksForFamily (qtbase.git/tree/src/gui/text/qfontdatabase.cpp):
Takes a style and script ID and returns a list of fonts which support that script with that style (or just support the script)
QPainter::drawText (qtbase.git/tree/src/gui/painting/qpainter.cpp): Basically Qt's show_text.
Uses QStackTextEngine for shaping, breaking of input string. Breaks into QScriptItem objects. Picks the font per item and draws it.
QStackTextEngine/QScriptItem/QTextItemInt (qtbase.git/tree/src/gui/text/qtextengine.cpp)
These are the components which break up a string into chunks which can be shaped and drawn as a unit.
This is mainly a problem of the AGG backends. Quartz and QPainter backends already have the correct behavior.
Basically, user code should be able to call
show_texton the following string:"Kiva Graphics一番😎"and have it render correctly even if the currently selected font only supports Latin characters.To get to this point, we need to do a few things:
get_text_extenton every chunk of a string before drawing)show_textmethod so that mixed strings can be drawnThis is roughly what Qt does, based on a quick skim of the code: https://code.qt.io/cgit/qt/qtbase.git/
QFreeTypeFontDatabase::addTTFile(qtbase.git/tree/src/gui/text/freetype/qfreetypefontdatabase.cpp):Scans a font for the following information: weight, style, fixed-width, supported writing systems (unicode range, codepage range), family name
QPlatformFontDatabase::fallbacksForFamily(qtbase.git/tree/src/gui/text/qfontdatabase.cpp):Takes a style and script ID and returns a list of fonts which support that script with that style (or just support the script)
QPainter::drawText(qtbase.git/tree/src/gui/painting/qpainter.cpp): Basically Qt'sshow_text.Uses
QStackTextEnginefor shaping, breaking of input string. Breaks intoQScriptItemobjects. Picks the font per item and draws it.QStackTextEngine/QScriptItem/QTextItemInt(qtbase.git/tree/src/gui/text/qtextengine.cpp)These are the components which break up a string into chunks which can be shaped and drawn as a unit.