12
12
13
13
#include < memory>
14
14
#include < cstdint>
15
+ #include < map>
15
16
16
17
#include " Common/Data/Text/WrapText.h"
17
18
#include " Common/Render/DrawBuffer.h"
@@ -33,6 +34,7 @@ struct TextStringEntry {
33
34
struct TextMeasureEntry {
34
35
int width;
35
36
int height;
37
+ int leading; // only used with Cocoa
36
38
int lastUsedFrame;
37
39
};
38
40
@@ -46,10 +48,14 @@ class TextDrawer {
46
48
void SetFontScale (float xscale, float yscale);
47
49
virtual void MeasureString (std::string_view str, float *w, float *h) = 0;
48
50
virtual void MeasureStringRect (std::string_view str, const Bounds &bounds, float *w, float *h, int align = ALIGN_TOPLEFT) = 0;
51
+
52
+ // TODO: This one we should be able to make a default implementation for, calling the specialized DrawBitmap.
53
+ // Only problem is that we need to make sure that the texFormats are all supported by all the backends, or we explicitly limit.
49
54
virtual void DrawString (DrawBuffer &target, std::string_view str, float x, float y, uint32_t color, int align = ALIGN_TOPLEFT) = 0;
55
+
50
56
void DrawStringRect (DrawBuffer &target, std::string_view str, const Bounds &bounds, uint32_t color, int align);
51
- virtual void DrawStringBitmap (std::vector<uint8_t > &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align = ALIGN_TOPLEFT) = 0;
52
- void DrawStringBitmapRect (std::vector<uint8_t > &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, const Bounds &bounds, int align);
57
+ virtual bool DrawStringBitmap (std::vector<uint8_t > &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align = ALIGN_TOPLEFT) = 0;
58
+ bool DrawStringBitmapRect (std::vector<uint8_t > &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, const Bounds &bounds, int align);
53
59
// Use for housekeeping like throwing out old strings.
54
60
virtual void OncePerFrame () = 0;
55
61
@@ -86,6 +92,9 @@ class TextDrawer {
86
92
float fontScaleY_ = 1 .0f ;
87
93
float dpiScale_ = 1 .0f ;
88
94
bool ignoreGlobalDpi_ = false ;
95
+
96
+ std::map<CacheKey, std::unique_ptr<TextStringEntry>> cache_;
97
+ std::map<CacheKey, std::unique_ptr<TextMeasureEntry>> sizeCache_;
89
98
};
90
99
91
100
class TextDrawerWordWrapper : public WordWrapper {
0 commit comments