[Fonts] Keep CardText call sites on the app font and fix px sizes

- CardText's unset fallback is qApp->font() again: only the three counter
  painters (paintNumberEllipse, GeneralCounter, PlayerCounter) were Serif
  before the role existed, and they now ask for it through
  ThemeManager::cardTextFont(). Card names, player names, counters, the
  overlay, the Archidekt and EDHREC labels and the completer delegate keep the
  app font they used before.
- Use setPixelSize for the EDHREC card name (20px) and commander name (28px)
  and details (16px) sizes: the stylesheets said px, and setPointSize made
  them about a third larger.
This commit is contained in:
Lukas Brübach 2026-11-01 14:12:35 +01:00
parent 6b566af94e
commit d4f0b75e87
7 changed files with 28 additions and 18 deletions

View file

@ -22,7 +22,7 @@ void AbstractGraphicsItem::paintNumberEllipse(int number,
painter->save(); painter->save();
QString numStr = QString::number(number); QString numStr = QString::number(number);
QFont font = themeManager->appFont(AppFont::CardText); QFont font = themeManager->cardTextFont();
font.setPixelSize(fontSize); font.setPixelSize(fontSize);
font.setWeight(QFont::Bold); font.setWeight(QFont::Bold);

View file

@ -42,7 +42,7 @@ void GeneralCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /
painter->drawPixmap(QPoint(0, 0), pixmap); painter->drawPixmap(QPoint(0, 0), pixmap);
if (value) { if (value) {
QFont f = themeManager->appFont(AppFont::CardText); QFont f = themeManager->cardTextFont();
f.setPixelSize(qMax((int)(radius * scaleFactor), 10)); f.setPixelSize(qMax((int)(radius * scaleFactor), 10));
f.setWeight(QFont::Bold); f.setWeight(QFont::Bold);
painter->setPen(Qt::black); painter->setPen(Qt::black);

View file

@ -77,7 +77,7 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
QRectF translatedRect = path.controlPointRect(); QRectF translatedRect = path.controlPointRect();
QSize translatedSize = translatedRect.size().toSize(); QSize translatedSize = translatedRect.size().toSize();
QFont font = themeManager->appFont(AppFont::CardText); QFont font = themeManager->cardTextFont();
font.setWeight(QFont::Bold); font.setWeight(QFont::Bold);
font.setPixelSize(qMax(qRound(translatedSize.height() / 1.3), 9)); font.setPixelSize(qMax(qRound(translatedSize.height() / 1.3), 9));
painter->setFont(font); painter->setFont(font);

View file

@ -660,15 +660,10 @@ QFont ThemeManager::appFont(AppFont::Role role) const
} }
// Role fallbacks preserve the pre-theme defaults when no fonts.toml is // Role fallbacks preserve the pre-theme defaults when no fonts.toml is
// present: card text starts from a serif basis, everything else from the // present: an unset role resolves to the application font, so the result is
// application font. The report dialogs that used to hardcode monospace ask // identical to before. The report dialogs that used to hardcode monospace
// for it explicitly (report_utils::reportLogFont). // ask for it explicitly (report_utils::reportLogFont), and the counter
if (role == AppFont::CardText) { // painters that used to hardcode Serif ask for it through cardTextFont().
return QFont(QStringLiteral("Serif"));
}
// No per-role scaling: every other unset role resolves to the application
// font, so with no fonts.toml present the result is identical to before.
return qApp->font(); return qApp->font();
} }
@ -677,6 +672,16 @@ bool ThemeManager::hasAppFont(AppFont::Role role) const
return currentFonts.fonts.contains(role); return currentFonts.fonts.contains(role);
} }
QFont ThemeManager::cardTextFont() const
{
if (hasAppFont(AppFont::CardText)) {
return appFont(AppFont::CardText);
}
QFont serifFont(QStringLiteral("Serif"));
serifFont.setStyleHint(QFont::Serif);
return serifFont;
}
QFont ThemeManager::defaultAppFont(AppFont::Role /*role*/) const QFont ThemeManager::defaultAppFont(AppFont::Role /*role*/) const
{ {
// No per-role scaling and no preview: an unset role resolves to the font // No per-role scaling and no preview: an unset role resolves to the font

View file

@ -155,6 +155,9 @@ public:
QFont appFont(AppFont::Role role) const; QFont appFont(AppFont::Role role) const;
/** @brief Whether the active theme defines this role in fonts.toml. */ /** @brief Whether the active theme defines this role in fonts.toml. */
bool hasAppFont(AppFont::Role role) const; bool hasAppFont(AppFont::Role role) const;
/** @brief The CardText role with its historical Serif fallback. Used by the
* counter painters, which were Serif before the role existed. */
QFont cardTextFont() const;
/** @brief Resolves an application font role against the startup font only, /** @brief Resolves an application font role against the startup font only,
* ignoring any previewed config in currentFonts. Editors that show * ignoring any previewed config in currentFonts. Editors that show
* "what this role resolves to" must use this, because appFont() * "what this role resolves to" must use this, because appFont()

View file

@ -94,9 +94,10 @@ void EdhrecApiResponseCardDetailsDisplayWidget::actRequestPageNavigation()
void EdhrecApiResponseCardDetailsDisplayWidget::applyCardTextFont() void EdhrecApiResponseCardDetailsDisplayWidget::applyCardTextFont()
{ {
// Family comes from the CardText theme role; the 20px size and bold // Family comes from the CardText theme role; the 20px size and bold
// weight previously carried by the stylesheet stay caller-side. // weight previously carried by the stylesheet stay caller-side. Pixel
// size, not point size: the stylesheet said 20px, and 20pt is ~27px.
QFont cardFont = themeManager->appFont(AppFont::CardText); QFont cardFont = themeManager->appFont(AppFont::CardText);
cardFont.setPointSize(20); cardFont.setPixelSize(20);
cardFont.setWeight(QFont::Bold); cardFont.setWeight(QFont::Bold);
nameLabel->setFont(cardFont); nameLabel->setFont(cardFont);
} }

View file

@ -89,15 +89,16 @@ void EdhrecCommanderResponseCommanderDetailsDisplayWidget::retranslateUi()
void EdhrecCommanderResponseCommanderDetailsDisplayWidget::applyCardTextFont() void EdhrecCommanderResponseCommanderDetailsDisplayWidget::applyCardTextFont()
{ {
// Family comes from the CardText theme role; the point sizes and the // Family comes from the CardText theme role; the sizes and the bold
// bold weight previously carried by the stylesheets stay caller-side. // weight previously carried by the stylesheets stay caller-side. Pixel
// sizes, not point sizes: the stylesheets said 28px and 16px.
QFont nameFont = themeManager->appFont(AppFont::CardText); QFont nameFont = themeManager->appFont(AppFont::CardText);
nameFont.setPointSize(28); nameFont.setPixelSize(28);
nameFont.setWeight(QFont::Bold); nameFont.setWeight(QFont::Bold);
commanderName->setFont(nameFont); commanderName->setFont(nameFont);
QFont detailsFont = themeManager->appFont(AppFont::CardText); QFont detailsFont = themeManager->appFont(AppFont::CardText);
detailsFont.setPointSize(16); detailsFont.setPixelSize(16);
label->setFont(detailsFont); label->setFont(detailsFont);
salt->setFont(detailsFont); salt->setFont(detailsFont);
} }