[Development] Why on Linux using FreeType engine fonts are rendered in 72 dpi instead of Screen DPI?

Tomasz Olszak olszak.tomasz at gmail.com
Wed Oct 17 19:04:50 CEST 2018


Here you can find and example of what I believe is true:

śr., 17 paź 2018 o 18:48 Tomasz Olszak <olszak.tomasz at gmail.com> napisał(a):
>
> If I understand correctly font.pixelSize is actually not the same as
> pixels user for with and height of items. So if you render rectangle
> of height e.g 100 pixels on 96 dpi screen, and render Text with
> font.pixelSize = 100 on 96 screen the iheight of text will be exactly
> 100 * 72/96 which is exactly 75% of rectangle's height. If you render
> the same example on screen with 72 dpi they will be exactly the same,
> on 192 dpi text will be ~37% of rectangle's height. It is just a
> guess, all my 4 screens I have currently access to are 96 dpi. It is
> just a guess and if Qt doesn't do something under the hood, FT engine
> renders fonts in 72 dpi which means that actually on screen text with
> a font with 100 pixels size is smaller than item with 100 pixel size .
> That's why I'm asking here not on Interest.
>
> Device pixel ratio can be used to calculate screen DPI in Qt Quick - I
> use it now to correctly render fonts using pixelSize (fontPixelSize
> factor == Screen.dpi / 72). Pixel size is given by ocring image in 300
> dpi. But pixel is pixel and it should work. Text however always was a
> bit smaller. When I calculated pointSize then the text was correct. I
> dug more and ended up with conclusions as described above.
>
> śr., 17 paź 2018 o 18:21 Jason H <jhihn at gmx.com> napisał(a):
> >
> > A pixel is a pixel, regardless of DPI.
> >
> > However things matter when you use point sizes (which assumes 72 points per inch) there are also Screen.devicePixelRatio  ( http://doc.qt.io/qt-5/qml-qtquick-window-screen.html#devicePixelRatio-attached-prop ) to contend with. I haven't had to worry about this for some time, so my intel may be out of date. It was a mess around 5.6...
> >
> > I'm assuming the 72 has something to do with the point size, and being able to calculate scaling relative to 72.
> >
> >
> > > Sent: Wednesday, October 17, 2018 at 11:59 AM
> > > From: "Tomasz Olszak" <olszak.tomasz at gmail.com>
> > > To: development at qt-project.org
> > > Subject: [Development] Why on Linux using FreeType engine fonts are rendered in 72 dpi instead of Screen DPI?
> > >
> > > Hi,
> > >
> > > I would like just to ensure that I missed something and there is
> > > documentation somewhere informing that Linux fonts are rendered
> > > *always* in 72 dpi
> > > (https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Set_Char_Size)
> > > (which makes font.pixelSize inaccurate for regular screens).
> > >
> > > I found: https://bugreports.qt.io/browse/QTBUG-8890 which fixes the
> > > problem but it was rejected. I see the default 72 dpi is also used in
> > > current Qt 5.11 FT engine
> > > (https://code.woboq.org/qt5/qtbase/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp.html#297).
> > >
> > > Does it surprise any of Qt developers or is it only me? Am I right
> > > thinking that when we do following:
> > > Rectangle {
> > >    height: 100
> > >    Text {font.pixelSize: 100}
> > > }
> > > then the relation between height of text and height of rectangle will
> > > differ depending on screen dpi (don't have a way to test it
> > > currently)?
> > >
> > > Moreover I'm pretty sure that's the cause I very often use
> > > Text.fontSizeMode: Text.Fit  because setting pixelSize to height of
> > > desired text size never worked correctly :)
> > >
> > > tl;dr: Is it a bug?
> > > _______________________________________________
> > > Development mailing list
> > > Development at qt-project.org
> > > http://lists.qt-project.org/mailman/listinfo/development
> > >



More information about the Development mailing list