fix: font builder vaxis incompatible type

QFont::Tag can't be passed directly from QML
Also add logging if unable to convert
And make MaterialIcon inherit vaxes from fontStyle
This commit is contained in:
2 * r + 2 * t 2026-04-22 19:37:11 +10:00
parent 70ee7e754d
commit 3443b6fee3
3 changed files with 18 additions and 6 deletions

View file

@ -7,5 +7,5 @@ StyledText {
property int grade: Colours.light ? 0 : -25
property font fontStyle: Tokens.font.icon.small
font: Tokens.font.icon.size(fontStyle.pointSize).weight(fontStyle.weight).fill(fill.toFixed(1)).grade(grade).build()
font: Tokens.font.icon.size(fontStyle.pointSize).weight(fontStyle.weight).vaxes(fontStyle.variableAxes).fill(fill.toFixed(1)).grade(grade).build()
}

View file

@ -1,7 +1,10 @@
#include "fontbuilder.hpp"
#include <qloggingcategory.h>
namespace caelestia::config {
Q_LOGGING_CATEGORY(lcFontBuilder, "caelestia.fontbuilder", QtInfoMsg)
FontBuilder::FontBuilder(QFont font)
: m_font(std::move(font)) {}
@ -44,15 +47,24 @@ FontBuilder FontBuilder::capitalisation(QFont::Capitalization cap) {
return *this;
}
FontBuilder FontBuilder::vaxis(QFont::Tag tag, float value) {
m_font.setVariableAxis(tag, value);
FontBuilder FontBuilder::vaxis(const QString& tag, float value) {
if (auto t = QFont::Tag::fromString(tag))
m_font.setVariableAxis(*t, value);
else
qCWarning(lcFontBuilder) << "Unable to convert tag" << tag << "to QFont::Tag";
return *this;
}
FontBuilder FontBuilder::vaxes(QVariantMap axes) {
for (auto it = axes.constBegin(); it != axes.constEnd(); ++it) {
if (auto tag = QFont::Tag::fromString(it.key()))
m_font.setVariableAxis(*tag, it.value().toFloat());
if (it.value().canConvert<float>()) {
if (auto tag = QFont::Tag::fromString(it.key()))
m_font.setVariableAxis(*tag, it.value().toFloat());
else
qCWarning(lcFontBuilder) << "Unable to convert tag" << it.key() << "to QFont::Tag";
} else {
qCWarning(lcFontBuilder) << "Unable to convert value" << it.value() << "to float";
}
}
return *this;
}

View file

@ -20,7 +20,7 @@ public:
[[nodiscard]] Q_INVOKABLE FontBuilder stretch(int stretch);
[[nodiscard]] Q_INVOKABLE FontBuilder letterSpacing(qreal spacing, bool absolute = true);
[[nodiscard]] Q_INVOKABLE FontBuilder capitalisation(QFont::Capitalization cap);
[[nodiscard]] Q_INVOKABLE FontBuilder vaxis(QFont::Tag tag, float value);
[[nodiscard]] Q_INVOKABLE FontBuilder vaxis(const QString& tag, float value);
[[nodiscard]] Q_INVOKABLE FontBuilder vaxes(QVariantMap axes);
[[nodiscard]] Q_INVOKABLE QFont build() const;