UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FontCacheCompositeFont.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Async/AsyncWork.h"
6#include "CoreMinimal.h"
8
9class FFreeTypeFace;
11struct FSlateFontInfo;
12
17{
18public:
21
23 FCachedTypefaceData(const FTypeface& InTypeface, const float InScalingFactor = 1.0f);
24
27 {
28 check(Typeface);
29 return *Typeface;
30 }
31
33 const FFontData* GetPrimaryFontData() const;
34
36 const FFontData* GetFontData(const FName& InName) const;
37
40 {
41 return ScalingFactor;
42 }
43
46
47private:
49 struct FCachedFontData
50 {
52 FCachedFontData()
53 : Name()
54 , FontData(nullptr)
55 {
56 }
57
59 FCachedFontData(const FName InName, const FFontData* InFontData)
60 : Name(InName)
61 , FontData(InFontData)
62 {
63 }
64
66 static FName BinarySearchKey(const FCachedFontData& InCachedFontData)
67 {
68 return InCachedFontData.Name;
69 }
70
72 static bool KeySortPredicate(const FName& InOne, const FName& InTwo)
73 {
74 // CompareIndexes is much faster than Compare since we don't care about these being sorted alphabetically
75 return InOne.CompareIndexes(InTwo) < 0;
76 }
77
79 static bool SortPredicate(const FCachedFontData& InOne, const FCachedFontData& InTwo)
80 {
81 return KeySortPredicate(InOne.Name, InTwo.Name);
82 }
83
85 FName Name;
86
88 const FFontData* FontData;
89 };
90
92 const FTypeface* Typeface;
93
96
98 float ScalingFactor;
99};
100
101
106{
107public:
110
113
116 {
117 check(CompositeFont);
118 return *CompositeFont;
119 }
120
123 {
124 return CachedTypefaces[CachedTypeface_DefaultIndex].Get();
125 }
126
129 {
130 return CachedTypefaces[CachedTypeface_FallbackIndex].Get();
131 }
132
135
138
140 void RefreshFontRanges();
141
142private:
144 struct FCachedFontRange
145 {
147 FCachedFontRange()
148 : Range(FInt32Range::Empty())
149 , CachedTypeface()
150 {
151 }
152
154 FCachedFontRange(const FInt32Range& InRange, TSharedPtr<FCachedTypefaceData> InCachedTypeface)
155 : Range(InRange)
156 , CachedTypeface(MoveTemp(InCachedTypeface))
157 {
158 }
159
161 static int32 BinarySearchKey(const FCachedFontRange& InCachedFontRange)
162 {
163 return InCachedFontRange.Range.GetLowerBoundValue();
164 }
165
167 static bool SortPredicate(const FCachedFontRange& InOne, const FCachedFontRange& InTwo)
168 {
169 check(!InOne.Range.IsEmpty() && !InTwo.Range.IsEmpty());
170 return InOne.Range.GetLowerBoundValue() < InTwo.Range.GetLowerBoundValue();
171 }
172
175
177 TSharedPtr<FCachedTypefaceData> CachedTypeface;
178 };
179
181 static const int32 CachedTypeface_DefaultIndex = 0;
182 static const int32 CachedTypeface_FallbackIndex = 1;
183 static const int32 CachedTypeface_FirstSubTypefaceIndex = 2;
184
186 const FCompositeFont* CompositeFont;
187
190
192 TArray<FCachedFontRange> CachedPriorityFontRanges;
193
195 TArray<FCachedFontRange> CachedFontRanges;
196};
197
198
203{
204public:
207
210
213
216
219
222
225
228
230 void FlushCache();
231
233 void Update();
234
239
240private:
242 const FCachedCompositeFontData* GetCachedCompositeFont(const FCompositeFont* const InCompositeFont);
243
245 FORCEINLINE const FCachedTypefaceData* GetDefaultCachedTypeface(const FCompositeFont* const InCompositeFont)
246 {
247 const FCachedCompositeFontData* const CachedCompositeFont = GetCachedCompositeFont(InCompositeFont);
248 return (CachedCompositeFont) ? CachedCompositeFont->GetDefaultTypeface() : nullptr;
249 }
250
252 FORCEINLINE const FCachedTypefaceData* GetFallbackCachedTypeface(const FCompositeFont* const InCompositeFont)
253 {
254 const FCachedCompositeFontData* const CachedCompositeFont = GetCachedCompositeFont(InCompositeFont);
255 return (CachedCompositeFont) ? CachedCompositeFont->GetFallbackTypeface() : nullptr;
256 }
257
259 FORCEINLINE const FCachedTypefaceData* GetCachedTypefaceForCodepoint(const FCompositeFont* const InCompositeFont, const UTF32CHAR InCodepoint)
260 {
261 const FCachedCompositeFontData* const CachedCompositeFont = GetCachedCompositeFont(InCompositeFont);
262 return (CachedCompositeFont) ? CachedCompositeFont->GetTypefaceForCodepoint(InCodepoint) : nullptr;
263 }
264
266 const FFontData* GetBestMatchFontForAttributes(const FCachedTypefaceData* const InCachedTypefaceData, const TSet<FName>& InFontAttributes);
267
269 bool DoesFontDataSupportCodepoint(const FFontData& InFontData, const UTF32CHAR InCodepoint);
270
272 void HandleCultureChanged();
273
275 const FFreeTypeLibrary* FTLibrary;
276
279
282
285
287};
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::UTF32CHAR UTF32CHAR
A 32-bit character containing a UTF32 (Unicode, 32-bit, fixed-width) code unit.
Definition Platform.h:1143
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
bool SortPredicate(const FCompileOnTheFlyData &A, const FCompileOnTheFlyData &B)
Definition MovieSceneCompiledDataManager.cpp:364
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition FontCacheCompositeFont.cpp:26
Definition FontCacheCompositeFont.h:106
void GetCachedFontData(TArray< const FFontData * > &OutFontData) const
Definition FontCacheCompositeFont.cpp:188
const FCachedTypefaceData * GetTypefaceForCodepoint(const UTF32CHAR InCodepoint) const
Definition FontCacheCompositeFont.cpp:139
FORCEINLINE const FCachedTypefaceData * GetDefaultTypeface() const
Definition FontCacheCompositeFont.h:122
FCachedCompositeFontData()
Definition FontCacheCompositeFont.cpp:113
FORCEINLINE const FCachedTypefaceData * GetFallbackTypeface() const
Definition FontCacheCompositeFont.h:128
void RefreshFontRanges()
Definition FontCacheCompositeFont.cpp:196
FORCEINLINE const FCompositeFont & GetCompositeFont() const
Definition FontCacheCompositeFont.h:115
Definition FontCacheCompositeFont.h:17
FORCEINLINE float GetScalingFactor() const
Definition FontCacheCompositeFont.h:39
const FFontData * GetFontData(const FName &InName) const
Definition FontCacheCompositeFont.cpp:82
void GetCachedFontData(TArray< const FFontData * > &OutFontData) const
Definition FontCacheCompositeFont.cpp:88
const FFontData * GetPrimaryFontData() const
Definition FontCacheCompositeFont.cpp:76
FORCEINLINE const FTypeface & GetTypeface() const
Definition FontCacheCompositeFont.h:26
FCachedTypefaceData()
Definition FontCacheCompositeFont.cpp:54
Definition FontCacheCompositeFont.h:203
void Update()
Definition FontCacheCompositeFont.cpp:603
TSharedPtr< FFreeTypeFace > GetFontFace(const FFontData &InFontData)
Definition FontCacheCompositeFont.cpp:485
void FlushCompositeFont(const FCompositeFont &InCompositeFont)
Definition FontCacheCompositeFont.cpp:592
SIZE_T GetFontDataAssetResidentMemory(const UObject *FontDataAsset) const
Definition FontCacheCompositeFont.cpp:663
const FFontData & GetDefaultFontData(const FSlateFontInfo &InFontInfo)
Definition FontCacheCompositeFont.cpp:295
bool HasLoadedFontForCodepoint(const FSlateFontInfo &InFontInfo, const UTF32CHAR InCodepoint)
Definition FontCacheCompositeFont.cpp:321
void FlushCache()
Definition FontCacheCompositeFont.cpp:597
const TSet< FName > & GetFontAttributes(const FFontData &InFontData)
Definition FontCacheCompositeFont.cpp:584
const FFontData & GetFontDataForCodepoint(const FSlateFontInfo &InFontInfo, const UTF32CHAR InCodepoint, float &OutScalingFactor)
Definition FontCacheCompositeFont.cpp:401
~FCompositeFontCache()
Definition FontCacheCompositeFont.cpp:283
Definition FontCacheFreeType.h:228
Definition FontCacheFreeType.h:199
Definition NameTypes.h:617
FORCEINLINE int32 CompareIndexes(const FName &Other) const
Definition NameTypes.h:935
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition ContainerAllocationPolicies.h:894
Definition Object.h:95
@ Range
Definition EnvQueryTypes.h:81
const TCHAR * Name
Definition OodleDataCompression.cpp:30
Definition CompositeFont.h:428
Definition CompositeFont.h:145
Definition SlateFontInfo.h:147
Definition CompositeFont.h:354