fixed font size

This commit is contained in:
Geoffray Levasseur committed 2026-11-06 22:17:17 +01:00
1 parent eec0eb2a4b
commit 57fd9973a1
1 file changed
+20 -2
+20 -2
View File
@@ -71,6 +71,25 @@ void copyBlock(Dpi::Canvas &dst, int x, int y, int w, int h, Dpi::Canvas &src, i
dst.copyRect(QRect(x, y, w, h), src, QRect(xSrc, ySrc, w, h));
}
// TabSize (like several other layout constants here) is a fixed pixel
// width inherited from the original Windows build, sized for English
// text - longer translations (e.g. French "Nouveau livre") can overflow
// it and overlap the neighboring tab. Shrink the font just for this one
// label, rather than changing the fixed tab layout, so every language
// still fits without touching unrelated pixel-perfect positioning.
void risedTextOutFitted(Dpi::Canvas &canvas, int x, int y, int maxWidth, const QString &text)
{
constexpr int MinPixelSize = 8;
const Dpi::Font original = canvas.font();
int pixelSize = original.toQFont().pixelSize();
while (pixelSize > MinPixelSize && biColorTextWidth(canvas, text) > maxWidth) {
--pixelSize;
canvas.font().setHeight(pixelSize);
}
risedTextOut(canvas, x + (maxWidth - biColorTextWidth(canvas, text)) / 2, y, text);
canvas.font().assign(original);
}
} // namespace
void StartDlg::drawAction(int y, int iconIndex, const QString &headerItem, const QString &textItem)
@@ -146,8 +165,7 @@ void StartDlg::offscreenPaint()
canvas.font().assign(UniFont[static_cast<std::size_t>(FontType::Normal)]);
for (int tab2 = static_cast<int>(Tab::Map); tab2 <= static_cast<int>(Tab::PreviousGame); ++tab2) {
const QString s = startControl(tabNames[tab2]);
risedTextOut(canvas, TabOffset + tab2 * TabSize + 1 + (TabSize - biColorTextWidth(canvas, s)) / 2,
10 + 2 * (tabIndex != tab2 ? 1 : 0), s);
risedTextOutFitted(canvas, TabOffset + tab2 * TabSize + 1, 10 + 2 * (tabIndex != tab2 ? 1 : 0), TabSize, s);
}
frame(canvas, TabOffset + 4 * TabSize + 1, -1, clientWidth, TabHeight, Qt::black, Qt::black);
frame(canvas, 1, TabHeight + 1, clientWidth - 2, clientHeight - 2, light, shade);