Rise
The Vieneo Province
Loading...
Searching...
No Matches
Font11.h
Go to the documentation of this file.
1#pragma once
2#include "Sprite11.h"
3#include <list>
4#include <bitset>
5
6namespace Rendering
7{
8 // GDI owns the existing font selection/layout semantics; native textures and
9 // Sprite11 own all GPU work. The 16 MiB run cache also retains shaped text;
10 // an opt-in fixed-width atlas has a separate 4 MiB ceiling per font.
11 class Font11
12 {
13 public:
14 Font11()=default;
15 Font11(const Font11&)=delete;
16 Font11& operator=(const Font11&)=delete;
18 HRESULT Initialize(ID3D11Device* device,const LOGFONTW& description);
19 int Draw(Sprite11* sprite,const wchar_t* text,int count,RECT* rectangle,UINT format,uint32_t color);
20 // Opt-in for rapidly changing fixed-width readouts. Other text/layouts
21 // retain the shaped run cache and its existing GDI semantics.
22 int DrawFixed(Sprite11* sprite,const wchar_t* text,int count,RECT* rectangle,UINT format,uint32_t color);
23 int DrawAnsi(Sprite11* sprite,const char* text,int count,RECT* rectangle,UINT format,uint32_t color);
24 HDC DC() const {return dc;}
25 bool Metrics(TEXTMETRICW& result) const {return dc && GetTextMetricsW(dc,&result);}
26 void Reset();
27 size_t CachedBytes() const {return cachedBytes+fixedBytes;}
28 size_t CachedRuns() const {return runs.size();}
29 size_t FixedAtlasBytes() const {return fixedBytes;}
30 private:
31 struct Run
32 {
33 std::wstring text;
34 LONG width=0,height=0;
35 UINT format=0;
36 RECT source{};
37 POINT offset{};
38 int result=0;
39 size_t bytes=0;
40 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> texture;
41 };
42 struct Line {std::wstring text;LONG x=0,y=0,width=0;};
43 bool Words(const std::wstring& text,std::vector<Line>& words);
44 int Layout(const std::wstring& text,LONG width,LONG height,UINT format,std::vector<Line>& lines,RECT& bounds);
45 HRESULT Rasterize(Run& run);
46 bool PrepareFixedAtlas();
47 struct Glyph {RECT source{};POINT offset{};bool independent=true;};
48 std::array<Glyph,95> fixedGlyphs{};
49 std::bitset<95*95> fixedPairOverlap;
50 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> fixedAtlas;
52 size_t fixedBytes=0;
53 bool fixedAttempted=false;
54 Microsoft::WRL::ComPtr<ID3D11Device> device;
55 HDC dc=nullptr;
56 HFONT font=nullptr;
57 HGDIOBJ previousFont=nullptr;
58 std::list<Run> runs;
59 size_t cachedBytes=0;
60 static constexpr size_t CacheLimit=16*1024*1024;
61 };
62}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
int DrawFixed(Sprite11 *sprite, const wchar_t *text, int count, RECT *rectangle, UINT format, uint32_t color)
Definition Font11.cpp:346
HRESULT Rasterize(Run &run)
Definition Font11.cpp:129
bool Words(const std::wstring &text, std::vector< Line > &words)
Definition Font11.cpp:33
std::list< Run > runs
Definition Font11.h:58
int Draw(Sprite11 *sprite, const wchar_t *text, int count, RECT *rectangle, UINT format, uint32_t color)
Definition Font11.cpp:215
bool Metrics(TEXTMETRICW &result) const
Definition Font11.h:25
static constexpr size_t CacheLimit
Definition Font11.h:60
int Layout(const std::wstring &text, LONG width, LONG height, UINT format, std::vector< Line > &lines, RECT &bounds)
Definition Font11.cpp:55
size_t cachedBytes
Definition Font11.h:59
Font11 & operator=(const Font11 &)=delete
LONG fixedAdvance
Definition Font11.h:51
size_t FixedAtlasBytes() const
Definition Font11.h:29
bool fixedAttempted
Definition Font11.h:53
HDC DC() const
Definition Font11.h:24
size_t CachedRuns() const
Definition Font11.h:28
std::array< Glyph, 95 > fixedGlyphs
Definition Font11.h:48
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > fixedAtlas
Definition Font11.h:50
std::bitset< 95 *95 > fixedPairOverlap
Definition Font11.h:49
int DrawAnsi(Sprite11 *sprite, const char *text, int count, RECT *rectangle, UINT format, uint32_t color)
Definition Font11.cpp:383
HGDIOBJ previousFont
Definition Font11.h:57
Microsoft::WRL::ComPtr< ID3D11Device > device
Definition Font11.h:54
bool PrepareFixedAtlas()
Definition Font11.cpp:254
HRESULT Initialize(ID3D11Device *device, const LOGFONTW &description)
Definition Font11.cpp:22
size_t fixedBytes
Definition Font11.h:52
Font11(const Font11 &)=delete
size_t CachedBytes() const
Definition Font11.h:27
std::wstring text
Definition Font11.h:42
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > texture
Definition Font11.h:40
std::wstring text
Definition Font11.h:33