SDLPainter 1.4.0
SDL3 + OpenGL/Vulkan 2D çizim kütüphanesi
Yüklüyor...
Arıyor...
Eşleşme Yok
font.h
1#pragma once
2
3#include "sdl_painter/export.h"
4#include "sdl_painter/texture.h"
5
6#include <cstdint>
7#include <memory>
8#include <string>
9#include <unordered_map>
10
11namespace sdl_painter {
12
13class IRenderer;
14class GlyphAtlas;
15
21struct Glyph {
23 TextureHandle texture{kInvalidTexture};
24
25 // Atlas içindeki normalize doku koordinatları.
26 float u0{0.0F};
27 float v0{0.0F};
28 float u1{0.0F};
29 float v1{0.0F};
30
31 int32_t width{0};
32 int32_t height{0};
33 int32_t advance{0};
34 int32_t bearing_x{0};
35 int32_t bearing_y{0};
36
38 [[nodiscard]] bool IsValid() const noexcept {
39 return texture != kInvalidTexture;
40 }
41};
42
44enum class Alignment : uint8_t {
45 kLeft,
46 kCenter,
47 kRight,
48};
49
51enum class TextWrap : uint8_t {
53 kNone,
56 kWord,
57};
58
76class SDLPAINTER_API Font {
77 public:
78 // Govde .cpp'de: sinif dllexport edildiginde derleyici bu ctor'u her
79 // TU'da emit eder ve temizlik yolu icin unique_ptr<GlyphAtlas>'in
80 // yikicisini ornekler — GlyphAtlas burada eksik tip.
81 Font();
82
86 Font(const std::string& file_path, int32_t point_size);
87
88 ~Font();
89
90 // Non-copyable, movable
91 Font(const Font&) = delete;
92 Font& operator=(const Font&) = delete;
93 Font(Font&& other) noexcept;
94 Font& operator=(Font&& other) noexcept;
95
97 [[nodiscard]] bool IsValid() const noexcept { return mHandle != nullptr; }
98
100 [[nodiscard]] int32_t PointSize() const noexcept { return mPointSize; }
101
103 [[nodiscard]] int32_t Ascent() const;
104
110 [[nodiscard]] int32_t LineHeight() const;
111
113 [[nodiscard]] void* Handle() const noexcept { return mHandle; }
114
129 bool MeasureText(const std::string& text, int32_t& out_width,
130 int32_t& out_height) const;
131
136 [[nodiscard]] int32_t Kerning(char32_t previous, char32_t current) const;
137
142 const Glyph* GetGlyph(IRenderer& renderer, char32_t codepoint) const;
143
145 [[nodiscard]] std::size_t AtlasPageCount() const;
146
147 private:
148 void* mHandle{nullptr};
149 int32_t mPointSize{0};
150
151 // Karakter önbelleği (mutable çünkü mantıksal const'u bozmuyoruz)
152 mutable std::unordered_map<char32_t, Glyph> mGlyphCache;
153
156 mutable std::unique_ptr<GlyphAtlas> mAtlas;
157
163 mutable IRenderer* mOwner{nullptr};
164};
165
166} // namespace sdl_painter
std::size_t AtlasPageCount() const
Glyph atlasının açtığı sayfa sayısı (teşhis/test).
Font(const std::string &file_path, int32_t point_size)
TTF dosyasından font yükle.
int32_t PointSize() const noexcept
Punto boyutunu döndür.
Definition font.h:100
const Glyph * GetGlyph(IRenderer &renderer, char32_t codepoint) const
Karakter için Glyph al; yoksa oluşturur.
int32_t Ascent() const
Font ascent (baseline'dan yukariya olan maksimum piksel) degerini dondur.
bool IsValid() const noexcept
Font başarıyla yüklendi mi?
Definition font.h:97
int32_t LineHeight() const
İki satır arasındaki önerilen dikey mesafe (piksel).
void * Handle() const noexcept
SDL_ttf font handle'ı döndür (opak pointer).
Definition font.h:113
bool MeasureText(const std::string &text, int32_t &out_width, int32_t &out_height) const
Verilen metnin piksel boyutunu ölç.
int32_t Kerning(char32_t previous, char32_t current) const
İki ardışık karakter arasındaki kerning düzeltmesi (piksel).
Backend-agnostik soyut renderer arayüzü.
Definition renderer.h:77
Tek bir karakterin metrikleri ve atlas içindeki konumu.
Definition font.h:21
bool IsValid() const noexcept
Glyph çizilebilir bir görüntüye sahip mi?
Definition font.h:38
TextureHandle texture
Glyph'i içeren atlas sayfasının texture'ı (sahiplik atlasta).
Definition font.h:23