Important: Please read the Qt Code of Conduct -

Numbers not getting rendered

  • Hi,

    I have a text rendering application that converts text to images. We support multiple languages and usually do not have any issues with rendering but recently we saw a weird issue where if we used a Noto Sans Thai font, normal numbers got rendered as square tofu boxes

    The first character of this string is the number 1
    0_1568382190931_Screen Shot 2019-09-13 at 2.40.21 PM.png

    With the same text and same font, if I remove the thai part, it get correctly rendered.
    0_1568382232939_Screen Shot 2019-09-13 at 2.40.31 PM.png

    Also if I add some text after the number then it renders correctly as well
    0_1568382162397_Screen Shot 2019-09-13 at 2.40.02 PM.png

    The code I'm using is

    const QSize& imgSize = QSize(1080, 1080);
      QImage image(imgSize, QImage::Format_ARGB32_Premultiplied);
      image.fill(qRgba(0, 0, 0, 0)); // Make background transparent.
      QPainter painter(&image);
     QFont textFont(
            QString("Noto Sans Thai"),
            false // Not using italics.
            0, 0, imgSize.width(), imgSize.height(), Qt::AlignLeft, text);

    I have other Noto Sans fonts installed on my machine as well that should be used as a fallback if the number is not present in Noto Sans Thai. For the same request if I change the Font to just "Noto Sans" it works correctly in all cases.

    My guess is that due to some reason the correct font is not being chosen for the digit characters. How can I debug this issue? Is there any way to find out which font is used to render the text, not the entire string but just single character.

    Any help on this will be greatly appreciated!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you sure that the font is correctly found ?

  • Yes it is rendering everything correctly if I add an english letter next to the number. But if I remove that character the number does not get rendered, everything else is still fine. And I have only 1 thai supporting font and thai characters are getting rendered correctly. All my fonts are in the same place: /usr/share/fonts/

  • Lifetime Qt Champion

    Can you provide a minimal compilable example including the font ?

Log in to reply