[TD]Dimension font clipping (fix #11452) (#18771)

* [TD]separate alignment and rendering bounding rectangles

* [TD]use alignment rectangle (fix #11452)
This commit is contained in:
WandererFan
2025-01-13 12:13:59 -05:00
committed by GitHub
parent 382d13ee77
commit e9c30cf370
3 changed files with 19 additions and 18 deletions

View File

@@ -183,17 +183,6 @@ void QGCustomText::paint ( QPainter * painter, const QStyleOptionGraphicsItem *
QGraphicsTextItem::paint (painter, &myOption, widget);
}
QRectF QGCustomText::boundingRect() const
{
if (toPlainText().isEmpty()) {
return QRectF();
} else if (tightBounding) {
return tightBoundingRect();
} else {
return QGraphicsTextItem::boundingRect();
}
}
QRectF QGCustomText::tightBoundingRect() const
{
QFontMetrics qfm(font());
@@ -204,11 +193,24 @@ QRectF QGCustomText::tightBoundingRect() const
// Adjust the bounding box 50% towards the Qt tightBoundingRect(),
// except chomp some extra empty space above the font (1.75*y_adj)
// wf: this does not work with all fonts. it depends on where the glyph is located within
// the em square. see https://github.com/FreeCAD/FreeCAD/issues/11452
// TODO: how to know where the glyph is going to be placed?
result.adjust(x_adj, 1.75*y_adj, -x_adj, -y_adj);
return result;
}
//! a boundingRect for text alignment, that does not adversely affect rendering.
QRectF QGCustomText::alignmentRect() const
{
if (tightBounding) {
return tightBoundingRect();
} else {
return boundingRect();
}
}
// Calculate the amount of difference between tight and relaxed bounding boxes
QPointF QGCustomText::tightBoundingAdjust() const
{