import QtQuick import qs.Commons Item { id: root property string text: "" property string fontFamily: Style.font.family property real fontSize: Style.font.body property color color: Color.foreground property bool debugBounds: false readonly property int renderedFontSize: Math.max(1, Math.round(fontSize)) readonly property real tightWidth: Math.max(1, glyphMetrics.tightBoundingRect.width) readonly property real horizontalCorrection: glyph.implicitWidth / 2 - (glyphMetrics.tightBoundingRect.x + tightWidth / 2) readonly property real paintedCenterX: glyph.x + glyphMetrics.tightBoundingRect.x + tightWidth / 2 readonly property real baselineY: glyph.y + glyph.baselineOffset TextMetrics { id: glyphMetrics font.family: root.fontFamily font.pixelSize: root.renderedFontSize text: root.text } Text { id: glyph textFormat: Text.PlainText // Keep the shared line box and baseline intact. Correcting only the // horizontal painted bounds avoids per-glyph vertical drift. // The correction is fractional, so x is set exactly: centerIn would snap it // to a whole pixel and undo it. y still snaps, keeping the baseline crisp. x: (root.width - width) / 2 + root.horizontalCorrection y: Math.round((root.height - height) / 2) text: root.text color: root.color font.family: root.fontFamily font.pixelSize: root.renderedFontSize renderType: Text.NativeRendering } Rectangle { visible: root.debugBounds anchors.fill: parent color: "transparent" border.width: 1 border.color: "#4488ff" } Rectangle { visible: root.debugBounds x: 0 y: Math.round(root.baselineY) width: parent.width height: 1 color: "#44ff88" } }