0

Some Chinese characters' strokes may be missing when I use QPainter.drawText under Windows platform.It happens when the size of font is within a range, usaually smaller.It seems like that it doesn't happen on English character.Only in Chinese does this happen.

Code:

void MainWindow::paintEvent(QPaintEvent*)
{
    const QString content = "宝贝盖房子啊"; // What I'm going to draw
    QFont font;
    font.setFamily("Arial");
   // font.setPixelSize(50);
    font.setPointSize(20); // fontsize.If it's too small, it won't draw properly
    QFontMetrics fm(font);
    QRect contentRect = fm.boundingRect(content);

    int width = (contentRect.width());
    int height = (contentRect.height());
    QImage pix(width, height, QImage::Format_MonoLSB); // It only happens when using this format    
    pix.fill(Qt::black);
    QPainter p(&pix);
    p.setFont(font);
    p.drawText(pix.rect(), Qt::AlignLeft | Qt::AlignVCenter, content);
    p.end();
    pix.save("D:\\pix.bmp");
}

Here's a picture of the results:
Here's a picture of the results

Why does this happen?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Cooooool
  • 11
  • 1
  • I believe this is a result of (poor) [**font rasterization**](https://en.wikipedia.org/wiki/Font_rasterization). The output into `Format_Mono` makes it even worse. (With gray levels, the thin strokes may at least result in shades of gray but thresholding into black/white replaces them by white pixels.) – Scheff's Cat Mar 15 '21 at 07:50
  • Thank you.Now I use Format_RGB32 and then conver to Format_MonoLSB. QImage bmp(bmpWidth, bmpHeight, QImage::Format_RGB32); bmp.convertToFormat(QImage::Format_MonoLSB, Qt::AvoidDither | Qt::ThresholdDither | Qt::ThresholdAlphaDither); – Cooooool Mar 16 '21 at 00:52
  • Does the result look better with dithering? (I'm asking out of curiosity as I just recently fiddled with dithering myself. I tried the common algorithms - ordered dithering and Floyd-Steinberg - and got satisfying results, but they were less satisfying concerning the flat-shaded samples of OP.) FYI: [SO: Better shading on BW display while rendering filled surfaces](https://stackoverflow.com/a/66518601/7478597). I really would appreciate a [self-answer](https://stackoverflow.com/help/self-answer). – Scheff's Cat Mar 16 '21 at 08:12

0 Answers0