[Development] Font rendering depending on the QPA plugin?

Michał 'Khorne' Lowas-Rzechonek michalrz at socialbicycles.com
Fri Oct 7 14:34:01 CEST 2016


Hi,

I have a question about font rendering, Qt 5.6.1 on Linux.

I am using QPainter to drawText() onto a monochromatic offscreen
QPixmap, which then gets saved to a file.

What bothers me is that it seems that pixel layout of letters changes
depending on QPA plugin I use... with -platform xcb the bitmap renders
fine, but with other QPAs the font metrics are completely off. I've
inspected them via QFontMetrics and got different results of
boundingRect() for the same letter with the same font:

  QImage image(34, 15, QImage::Format_Mono);
  QPainter painter(&image);

  QFont font("fixed", 6);
  QFontMetrics metrics(font);
  qDebug() << "f=" << metrics.boundingRect('f') <<
              "j=" << metrics.boundingRect('j') <<
              "W=" << metrics.boundingRect('W');

  painter.setFont(font);
  painter.setPen(Qt::black);

  painter.eraseRect(0, 0, 34, 15);
  painter.drawText(0, 0, 34, 15, 0, "fjW");

  image.save("test.png", "png");


The result for 'xcb' QPA on linux is fine (font is monospace and
bitmapped, size '6 pt' should result in 5x8 px glyphs)
  f= QRect(0,-7 5x8) j= QRect(0,-7 5x8) W= QRect(0,-7 5x8)

but for others I get different results, 'offscreen' yields
  f= QRect(0,-7 3x7) j= QRect(-1,-6 3x8) W= QRect(0,-6 7x6)

and for 'minimal' it's
  f= QRect(0,-8 8x8) j= QRect(0,-8 8x8) W= QRect(0,-8 8x8)

What I would like to get is consistent 5x8 pixel glyphs.

I have my own QPA (it's an embedded device) so I am able to manipulate
values reported by QPlatformScreen. I've noticed that the DPI has *some*
impact on font metrics, but I can't put my finger on it.


regards
-- 
Michał 'Khorne' Lowas-Rzechonek
Social Bicycles Inc.



More information about the Development mailing list