ui/core/material/cfmaterial_fonttype.h¶
Material Design 3 Typography with EmbeddedTokenRegistry. More...
Namespaces¶
| Name |
|---|
| cf |
| cf::ui |
| cf::ui::core |
| cf::ui::core::tokens |
| cf::ui::core::lineHeightTokens |
Classes¶
| Name | |
|---|---|
| struct | cf::ui::core::DisplayFonts Display font styles group. |
| struct | cf::ui::core::HeadlineFonts Headline font styles group. |
| struct | cf::ui::core::TitleFonts Title font styles group. |
| struct | cf::ui::core::BodyFonts Body font styles group. |
| struct | cf::ui::core::LabelFonts Label font styles group. |
| class | cf::ui::core::MaterialTypography Material Design 3 Typography with EmbeddedTokenRegistry. |
Detailed Description¶
Material Design 3 Typography with EmbeddedTokenRegistry.
Author: Charliechen114514 (chengh1922@mails.jlu.edu.cn)
Version: 0.1
Date: 2026-02-26
Copyright: Copyright © 2026
Implements the complete Material Design 3 Type Scale system with 15 styles. Fonts are stored in an embedded registry for independent typography instances.
Font selection:
- Windows: Segoe UI (Chinese fallback to Microsoft YaHei UI)
- macOS: .SF NS Text (Chinese fallback to PingFang SC)
- Linux: Ubuntu (Chinese fallback to Noto Sans CJK SC)
Source code¶
#pragma once
#include <QByteArray>
#include <QFont>
#include <string>
#include <unordered_map>
#include "../export.h"
#include "base/hash/constexpr_fnv1a.hpp"
#include "font_type.h"
#include "token.hpp"
#include "token/typography/cfmaterial_typography_token_literals.h"
namespace cf::ui::core {
// =============================================================================
// Typography Token Type Aliases - Material Typography System
// =============================================================================
namespace tokens {
using namespace cf::ui::core::token::literals;
// Display tokens
using DisplayLargeToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_DISPLAY_LARGE)>;
using DisplayMediumToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_DISPLAY_MEDIUM)>;
using DisplaySmallToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_DISPLAY_SMALL)>;
// Headline tokens
using HeadlineLargeToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_HEADLINE_LARGE)>;
using HeadlineMediumToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_HEADLINE_MEDIUM)>;
using HeadlineSmallToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_HEADLINE_SMALL)>;
// Title tokens
using TitleLargeToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_TITLE_LARGE)>;
using TitleMediumToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_TITLE_MEDIUM)>;
using TitleSmallToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_TITLE_SMALL)>;
// Body tokens
using BodyLargeToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_BODY_LARGE)>;
using BodyMediumToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_BODY_MEDIUM)>;
using BodySmallToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_BODY_SMALL)>;
// Label tokens
using LabelLargeToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_LABEL_LARGE)>;
using LabelMediumToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_LABEL_MEDIUM)>;
using LabelSmallToken = StaticToken<QFont, cf::hash::fnv1a64(TYPOGRAPHY_LABEL_SMALL)>;
} // namespace tokens
// =============================================================================
// Line Height Token Type Aliases
// =============================================================================
namespace lineHeightTokens {
using namespace cf::ui::core::token::literals;
using DisplayLargeLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_DISPLAY_LARGE)>;
using DisplayMediumLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_DISPLAY_MEDIUM)>;
using DisplaySmallLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_DISPLAY_SMALL)>;
using HeadlineLargeLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_HEADLINE_LARGE)>;
using HeadlineMediumLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_HEADLINE_MEDIUM)>;
using HeadlineSmallLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_HEADLINE_SMALL)>;
using TitleLargeLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_TITLE_LARGE)>;
using TitleMediumLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_TITLE_MEDIUM)>;
using TitleSmallLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_TITLE_SMALL)>;
using BodyLargeLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_BODY_LARGE)>;
using BodyMediumLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_BODY_MEDIUM)>;
using BodySmallLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_BODY_SMALL)>;
using LabelLargeLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_LABEL_LARGE)>;
using LabelMediumLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_LABEL_MEDIUM)>;
using LabelSmallLineHeight = StaticToken<float, cf::hash::fnv1a64(LINEHEIGHT_LABEL_SMALL)>;
} // namespace lineHeightTokens
// =============================================================================
// Typography Group Structs - Material Typography System
// =============================================================================
struct DisplayFonts {
tokens::DisplayLargeToken large;
tokens::DisplayMediumToken medium;
tokens::DisplaySmallToken small;
};
struct HeadlineFonts {
tokens::HeadlineLargeToken large;
tokens::HeadlineMediumToken medium;
tokens::HeadlineSmallToken small;
};
struct TitleFonts {
tokens::TitleLargeToken large;
tokens::TitleMediumToken medium;
tokens::TitleSmallToken small;
};
struct BodyFonts {
tokens::BodyLargeToken large;
tokens::BodyMediumToken medium;
tokens::BodySmallToken small;
};
struct LabelFonts {
tokens::LabelLargeToken large;
tokens::LabelMediumToken medium;
tokens::LabelSmallToken small;
};
// =============================================================================
// Material Typography - 实现 IFontType 接口
// =============================================================================
class CF_UI_EXPORT MaterialTypography : public IFontType {
public:
MaterialTypography();
~MaterialTypography() override = default;
// Non-copyable, movable
MaterialTypography(const MaterialTypography&) = delete;
MaterialTypography& operator=(const MaterialTypography&) = delete;
MaterialTypography(MaterialTypography&&) noexcept = default;
MaterialTypography& operator=(MaterialTypography&&) noexcept = default;
QFont queryTargetFont(const char* name) override;
float getLineHeight(const char* styleName) const;
EmbeddedTokenRegistry& registry() { return registry_; }
const EmbeddedTokenRegistry& registry() const { return registry_; }
// Font group accessors - 返回包含 Token 类型的结构体
[[nodiscard]] DisplayFonts display() const { return {}; }
[[nodiscard]] HeadlineFonts headline() const { return {}; }
[[nodiscard]] TitleFonts title() const { return {}; }
[[nodiscard]] BodyFonts body() const { return {}; }
[[nodiscard]] LabelFonts label() const { return {}; }
private:
EmbeddedTokenRegistry registry_;
mutable std::unordered_map<std::string, QFont> font_cache_;
mutable std::unordered_map<std::string, float> line_height_cache_;
};
} // namespace cf::ui::core
Updated on 2026-03-09 at 10:14:01 +0000