1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-05-14 13:22:16 -04:00

freqdisplay: fix font sizing to respect both width and height constraints

Agent-Logs-Url: https://github.com/srcejon/sdrangel/sessions/8205839a-4dad-46b0-8fbf-02dd31499bb7

Co-authored-by: srcejon <57259258+srcejon@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-19 10:58:06 +00:00 committed by GitHub
parent ffe32eb1a0
commit 2bbe19af46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -515,7 +515,7 @@ void FreqDisplayGUI::updateFrequencyFont()
for (const QString& line : lines) {
maxLineWidth = qMax(maxLineWidth, fm.horizontalAdvance(line));
}
const int lineHeight = fm.height();
const int lineHeight = fm.lineSpacing();
if (maxLineWidth <= 0 || lineHeight <= 0) {
return;
@ -523,29 +523,35 @@ void FreqDisplayGUI::updateFrequencyFont()
maxLineWidth += 5; // Add some space for a border
const int heightPerLine = availableHeight / numLines;
const int maxFromWidth = fontProbePointSize * availableWidth / maxLineWidth;
const int maxFromHeight = fontProbePointSize * heightPerLine / lineHeight;
const int maxFromHeight = fontProbePointSize * availableHeight / (lineHeight * numLines);
int pointSize = qMax(minimumFrequencyFontPointSize, qMin(maxFromWidth, maxFromHeight));
font.setPointSize(pointSize);
// Verify the text actually fits at the calculated point size. The linear
// interpolation from fontProbePointSize can be slightly inaccurate due to
// font hinting or non-linear glyph metrics at the target size; if the text
// would overflow and trigger word-wrap, reduce by one point. This is a
// single-step correction that is sufficient because the interpolation error
// is at most a fraction of one point size.
if (pointSize > minimumFrequencyFontPointSize)
// would overflow either horizontally or vertically, reduce by one point at a
// time until it fits.
while (pointSize > minimumFrequencyFontPointSize)
{
const QFontMetrics verifyFm(font);
bool overflow = false;
for (const QString& line : lines)
{
if (verifyFm.horizontalAdvance(line) > availableWidth)
{
font.setPointSize(--pointSize);
overflow = true;
break;
}
}
if (!overflow && (verifyFm.lineSpacing() * numLines > availableHeight)) {
overflow = true;
}
if (!overflow) {
break;
}
font.setPointSize(--pointSize);
}
label->setFont(font);