Skip to content

Change Units.fontMetrics to actually use FontMetrics

Noah Davis requested to merge work/ndavis/font-metrics into master

This change gives us access to a bunch of new font related metrics.

Compare TextMetrics (what this used before) with FontMetrics:

https://doc.qt.io/qt-5/qml-qtquick-textmetrics.html

https://doc.qt.io/qt-5/qml-qtquick-fontmetrics.html

I've also changed the gridUnit documentation to more accurately reflect what it represents. It never held the actual height of an 'M', It held the height of a boundingRect that happened to contain an 'M'. This is an important difference because the boundingRect is much taller than the 'M' it happened to contain. In order to get the real height of an 'M', you must use tightBoundingRect.height with a TextMetrics element or tightBoundingRect("M").height with a FontMetrics element.


I checked lxr.kde.org and it doesn't look like this change breaks anything. Units.gridUnit is still 18px with the default 10pt Noto Sans font.

https://lxr.kde.org/search?_filestring=&_string=Units.fontMetrics.&_casesensitive=1

plasma-dialer seems to have some code that shouldn't have worked in the first place: https://invent.kde.org/plasma-mobile/plasma-dialer/-/blob/master/src/qml/Call/CallPage.qml#L107

This is because TextMetrics has no pointSize property. You must use font.pointSize instead. Luckily, FontMetrics has a font property.


cc: @mart

Edited by Noah Davis

Merge request reports