LMMS
Loading...
Searching...
No Matches
lice_text.h
Go to the documentation of this file.
1#ifndef _LICE_TEXT_H_
2#define _LICE_TEXT_H_
3
4#include "lice.h"
5
6#ifndef _WIN32
7#include "../swell/swell.h"
8#endif
9#include "../heapbuf.h"
10
11#define LICE_FONT_FLAG_VERTICAL 1 // rotate text to vertical (do not set the windows font to vertical though)
12#define LICE_FONT_FLAG_VERTICAL_BOTTOMUP 2
13
14#define LICE_FONT_FLAG_PRECALCALL 4
15//#define LICE_FONT_FLAG_ALLOW_NATIVE 8
16#define LICE_FONT_FLAG_FORCE_NATIVE 1024
17
18#define LICE_FONT_FLAG_FX_BLUR 16
19#define LICE_FONT_FLAG_FX_INVERT 32
20#define LICE_FONT_FLAG_FX_MONO 64 // faster but no AA/etc
21
22#define LICE_FONT_FLAG_FX_SHADOW 128 // these imply MONO
23#define LICE_FONT_FLAG_FX_OUTLINE 256
24
25#define LICE_FONT_FLAG_OWNS_HFONT 512
26
27// could do a mask for these flags
28#define LICE_FONT_FLAGS_HAS_FX(flag) \
29 (flag&(LICE_FONT_FLAG_VERTICAL|LICE_FONT_FLAG_VERTICAL_BOTTOMUP| \
30 LICE_FONT_FLAG_FX_BLUR|LICE_FONT_FLAG_FX_INVERT|LICE_FONT_FLAG_FX_MONO| \
31 LICE_FONT_FLAG_FX_SHADOW|LICE_FONT_FLAG_FX_OUTLINE))
32
33#define LICE_DT_NEEDALPHA 0x80000000 // include in DrawText() if the output alpha channel is important
34#define LICE_DT_USEFGALPHA 0x40000000 // uses alpha channel in fg color
35
37{
38 public:
39 virtual ~LICE_IFont() {}
40
41 virtual void SetFromHFont(HFONT font, int flags=0)=0; // hfont must REMAIN valid, unless LICE_FONT_FLAG_PRECALCALL or LICE_FONT_FLAG_OWNS_HFONT set (OWNS means LICE_IFont will clean up hfont on font change or exit)
42
46 virtual int SetBkMode(int bkmode)=0;
47 virtual void SetCombineMode(int combine, float alpha=1.0f)=0;
48
49 virtual int DrawText(LICE_IBitmap *bm, const char *str, int strcnt, RECT *rect, UINT dtFlags)=0;
50
52 virtual HFONT GetHFont()=0;
53 virtual int GetLineHeight()=0;
54 virtual void SetLineSpacingAdjust(int amt)=0;
55};
56
57
58#ifndef LICE_TEXT_NO_DECLARE_CACHEDFONT
59
61{
62 public:
64 virtual ~LICE_CachedFont();
65
66 virtual void SetFromHFont(HFONT font, int flags=0);
67
68 virtual LICE_pixel SetTextColor(LICE_pixel color) { LICE_pixel ret=m_fg; m_fg=color; return ret; }
69 virtual LICE_pixel SetBkColor(LICE_pixel color) { LICE_pixel ret=m_bg; m_bg=color; return ret; }
70 virtual LICE_pixel SetEffectColor(LICE_pixel color) { LICE_pixel ret=m_effectcol; m_effectcol=color; return ret; }
71 virtual int SetBkMode(int bkmode) { int bk = m_bgmode; m_bgmode=bkmode; return bk; }
72 virtual void SetCombineMode(int combine, float alpha=1.0f) { m_comb=combine; m_alpha=alpha; }
73
74 virtual int DrawText(LICE_IBitmap *bm, const char *str, int strcnt, RECT *rect, UINT dtFlags)
75 {
76 return DrawTextImpl(bm,str,strcnt,rect,dtFlags);
77 }
78
79 virtual LICE_pixel GetTextColor() { return m_fg; }
80 virtual HFONT GetHFont() { return m_font; }
81 virtual int GetLineHeight() { return m_line_height; }
82
83 virtual void SetLineSpacingAdjust(int amt) { m_lsadj=amt; }
84
85 protected:
86
87 virtual bool DrawGlyph(LICE_IBitmap *bm, unsigned short c, int xpos, int ypos, RECT *clipR);
88 int DrawTextImpl(LICE_IBitmap *bm, const char *str, int strcnt, RECT *rect, UINT dtFlags); // cause swell defines DrawText to SWELL_DrawText etc
89
90 bool RenderGlyph(unsigned short idx);
91
92 const char *NextWordBreak(const char *str, int strcnt, int w);
93
96 int m_comb;
97 float m_alpha;
99
101 struct charEnt
102 {
103 int base_offset; // offset in m_cachestore+1, so 1=offset0, 0=unset, -1=failed to render
106 int charid; // used by m_extracharlist
108 };
109 charEnt *findChar(unsigned short c);
110
111 charEnt m_lowchars[128]; // first 128 chars cached here
114
115 static int _charSortFunc(const void *a, const void *b);
116
118
119};
120
121#endif // !LICE_TEXT_NO_DECLARE_CACHEDFONT
122
123#ifndef LICE_TEXT_NO_MULTIDPI
125{
126 struct rec {
128 int sz;
129 };
130 WDL_TypedBuf<rec> m_list; // used entries are at end of list, most recently used last. sz=0 for unused
131
136 float m_alpha;
138
139public:
141
142
143 // LICE_IFont interface
144 virtual void SetFromHFont(HFONT font, int flags=0) { }
145
146 virtual LICE_pixel SetTextColor(LICE_pixel color) { LICE_pixel ret=m_fg; m_fg=color; return ret; }
147 virtual LICE_pixel SetBkColor(LICE_pixel color) { LICE_pixel ret=m_bg; m_bg=color; return ret; }
148 virtual LICE_pixel SetEffectColor(LICE_pixel color) { LICE_pixel ret=m_effectcol; m_effectcol=color; return ret; }
149 virtual int SetBkMode(int bkmode) { int bk = m_bgmode; m_bgmode=bkmode; return bk; }
150 virtual void SetCombineMode(int combine, float alpha=1.0f) { m_comb=combine; m_alpha=alpha; }
151
152 virtual int DrawText(LICE_IBitmap *bm, const char *str, int strcnt, RECT *rect, UINT dtFlags)
153 {
154 LICE_IFont *f = get(bm);
155 if (!f) return 0;
156 if (!(dtFlags & DT_CALCRECT))
157 {
158 f->SetTextColor(m_fg);
159 f->SetBkColor(m_bg);
160 f->SetEffectColor(m_effectcol);
161 f->SetBkMode(m_bgmode);
162 f->SetCombineMode(m_comb,m_alpha);
163 f->SetLineSpacingAdjust(m_lsadj);
164 }
165 return f->DrawText(bm,str,strcnt,rect,dtFlags);
166 }
167
168 virtual LICE_pixel GetTextColor() { return m_fg; }
169 virtual HFONT GetHFont() { return NULL; }
170 virtual int GetLineHeight() { return GetLineHeightDPI(NULL); }
171
172 virtual void SetLineSpacingAdjust(int amt) { m_lsadj=amt; }
173
175 {
176 memset(&m_lf,0,sizeof(m_lf));
178 m_flags=0;
181 m_comb=0;
182 m_alpha=1.0;
183 m_lsadj=0;
184
185 rec *l = m_list.ResizeOK(maxsz);
186 if (l) memset(l,0,sizeof(*l)*maxsz);
187 }
189 {
190 for (int x = 0; x < m_list.GetSize(); x ++) delete m_list.Get()[x].cache;
191 }
192 void SetFromLogFont(LOGFONT *lf, int (*get_flags)(int))
193 {
194 m_lf = *lf;
195 m_getflags = get_flags;
196 m_flags = get_flags ? get_flags(0) : 0;
197 clear();
198 }
199
200 void clear()
201 {
202 int x = m_list.GetSize()-1;
203 rec *t = m_list.Get();
204 while (x>=0 && t[x].sz) t[x--].sz=0;
205 }
206
208 {
209 int use_flag = m_getflags ? m_getflags(0) & ~LICE_FONT_FLAG_PRECALCALL : 0;
210 if (m_flags != use_flag)
211 {
212 m_flags = use_flag;
213 clear();
214 }
215
216 int ht = m_lf.lfHeight, ht2 = m_lf.lfWidth;
217 if (bm)
218 {
220 if (sz)
221 {
222 ht = (ht * sz) / 256;
223 ht2 = (ht2 * sz) / 256;
224 if (sz != 256)
225 use_flag |= LICE_FONT_FLAG_FORCE_NATIVE;
226 }
227 }
228
229 int x = m_list.GetSize()-1;
230 rec *t = m_list.Get();
231 while (x>=0 && t[x].sz != ht && t[x].sz) x--;
232 if (x<0) t[x=0].sz = 0; // if list full, use oldest item
233
234 // move to end of list
235 if (x != m_list.GetSize()-1)
236 {
237 rec tmp = t[x];
238 m_list.Delete(x);
239 m_list.Add(tmp);
240 }
241
242 t = m_list.Get() + m_list.GetSize() - 1;
243 if (!t->cache) t->cache = __CreateFont();
244 if (!t->sz && t->cache)
245 {
246 t->sz = ht;
247 LOGFONT lf = m_lf;
248 lf.lfHeight = ht;
249 lf.lfWidth = ht2;
250 #ifdef _WIN32
252 #endif
253 t->cache->SetFromHFont(CreateFontIndirect(&lf), LICE_FONT_FLAG_OWNS_HFONT | use_flag);
254 }
255
256 return t->cache;
257 }
258
260 {
261 LICE_IFont *f = get(bm);
262 return f ? f->GetLineHeight() : 10;
263 }
265};
266
267template<class BASEFONT> class LICE_dpiAwareFont : public __LICE_dpiAwareFont {
268 public:
270 virtual LICE_IFont *__CreateFont() { return new BASEFONT; }
271};
272#endif//LICE_TEXT_NO_MULTIDPI
273
274#endif//_LICE_TEXT_H_
#define NULL
Definition CarlaBridgeFormat.cpp:30
uint8_t a
Definition Spc_Cpu.h:141
float abs(const fft_t *freqs, off_t x)
Definition OscilGen.cpp:52
LICE_IFont * get(LICE_IBitmap *bm)
Definition lice_text.h:207
int m_lsadj
Definition lice_text.h:137
float m_alpha
Definition lice_text.h:136
LICE_pixel m_fg
Definition lice_text.h:134
void SetFromLogFont(LOGFONT *lf, int(*get_flags)(int))
Definition lice_text.h:192
virtual int DrawText(LICE_IBitmap *bm, const char *str, int strcnt, RECT *rect, UINT dtFlags)
Definition lice_text.h:152
virtual LICE_pixel GetTextColor()
Definition lice_text.h:168
void clear()
Definition lice_text.h:200
virtual int GetLineHeight()
Definition lice_text.h:170
LICE_pixel m_bg
Definition lice_text.h:134
__LICE_dpiAwareFont(int maxsz)
Definition lice_text.h:174
virtual LICE_IFont * __CreateFont()=0
virtual LICE_pixel SetEffectColor(LICE_pixel color)
Definition lice_text.h:148
int(* m_getflags)(int)
Definition lice_text.h:132
virtual int SetBkMode(int bkmode)
Definition lice_text.h:149
LICE_pixel m_effectcol
Definition lice_text.h:134
int GetLineHeightDPI(LICE_IBitmap *bm)
Definition lice_text.h:259
int m_comb
Definition lice_text.h:135
virtual LICE_pixel SetTextColor(LICE_pixel color)
Definition lice_text.h:146
int m_bgmode
Definition lice_text.h:135
virtual void SetCombineMode(int combine, float alpha=1.0f)
Definition lice_text.h:150
LOGFONT m_lf
Definition lice_text.h:140
~__LICE_dpiAwareFont()
Definition lice_text.h:188
virtual HFONT GetHFont()
Definition lice_text.h:169
WDL_TypedBuf< rec > m_list
Definition lice_text.h:130
virtual void SetLineSpacingAdjust(int amt)
Definition lice_text.h:172
virtual LICE_pixel SetBkColor(LICE_pixel color)
Definition lice_text.h:147
virtual void SetFromHFont(HFONT font, int flags=0)
Definition lice_text.h:144
int m_flags
Definition lice_text.h:133
virtual LICE_pixel SetBkColor(LICE_pixel color)
Definition lice_text.h:69
virtual void SetCombineMode(int combine, float alpha=1.0f)
Definition lice_text.h:72
virtual void SetFromHFont(HFONT font, int flags=0)
Definition lice_textnew.cpp:122
bool RenderGlyph(unsigned short idx)
Definition lice_textnew.cpp:163
LICE_CachedFont()
Definition lice_textnew.cpp:93
LICE_pixel m_fg
Definition lice_text.h:94
int DrawTextImpl(LICE_IBitmap *bm, const char *str, int strcnt, RECT *rect, UINT dtFlags)
Definition lice_textnew.cpp:765
virtual void SetLineSpacingAdjust(int amt)
Definition lice_text.h:83
float m_alpha
Definition lice_text.h:97
int m_lsadj
Definition lice_text.h:100
int m_comb
Definition lice_text.h:96
int m_bgmode
Definition lice_text.h:95
LICE_pixel m_bg
Definition lice_text.h:94
virtual int GetLineHeight()
Definition lice_text.h:81
WDL_TypedBuf< charEnt > m_extracharlist
Definition lice_text.h:112
virtual ~LICE_CachedFont()
Definition lice_textnew.cpp:108
const char * NextWordBreak(const char *str, int strcnt, int w)
Definition lice_textnew.cpp:741
virtual LICE_pixel SetTextColor(LICE_pixel color)
Definition lice_text.h:68
virtual LICE_pixel SetEffectColor(LICE_pixel color)
Definition lice_text.h:70
charEnt m_lowchars[128]
Definition lice_text.h:111
LICE_pixel m_effectcol
Definition lice_text.h:94
static int _charSortFunc(const void *a, const void *b)
Definition lice_textnew.cpp:86
charEnt * findChar(unsigned short c)
Definition lice_textnew.cpp:525
virtual LICE_pixel GetTextColor()
Definition lice_text.h:79
virtual bool DrawGlyph(LICE_IBitmap *bm, unsigned short c, int xpos, int ypos, RECT *clipR)
Definition lice_textnew.cpp:534
WDL_TypedBuf< unsigned char > m_cachestore
Definition lice_text.h:113
HFONT m_font
Definition lice_text.h:117
virtual HFONT GetHFont()
Definition lice_text.h:80
virtual int DrawText(LICE_IBitmap *bm, const char *str, int strcnt, RECT *rect, UINT dtFlags)
Definition lice_text.h:74
int m_flags
Definition lice_text.h:98
int m_line_height
Definition lice_text.h:100
virtual int SetBkMode(int bkmode)
Definition lice_text.h:71
Definition lice.h:84
virtual INT_PTR Extended(int id, void *data)
Definition lice.h:98
Definition lice_text.h:37
virtual LICE_pixel GetTextColor()=0
virtual LICE_pixel SetEffectColor(LICE_pixel color)=0
virtual void SetFromHFont(HFONT font, int flags=0)=0
virtual LICE_pixel SetBkColor(LICE_pixel color)=0
virtual int SetBkMode(int bkmode)=0
virtual ~LICE_IFont()
Definition lice_text.h:39
virtual LICE_pixel SetTextColor(LICE_pixel color)=0
virtual void SetLineSpacingAdjust(int amt)=0
virtual HFONT GetHFont()=0
virtual int DrawText(LICE_IBitmap *bm, const char *str, int strcnt, RECT *rect, UINT dtFlags)=0
virtual void SetCombineMode(int combine, float alpha=1.0f)=0
virtual int GetLineHeight()=0
virtual LICE_IFont * __CreateFont()
Definition lice_text.h:270
LICE_dpiAwareFont(int max)
Definition lice_text.h:269
Definition heapbuf.h:259
UINT_D64 w
Definition inflate.c:942
int * l
Definition inflate.c:1579
G bk
Definition inflate.c:1058
struct huft * t
Definition inflate.c:943
unsigned x[BMAX+1]
Definition inflate.c:1586
unsigned f
Definition inflate.c:1572
#define LICE_EXT_GET_ANY_SCALING
Definition lice.h:105
unsigned int LICE_pixel
Definition lice.h:54
#define LICE_FONT_FLAG_PRECALCALL
Definition lice_text.h:14
#define LICE_FONT_FLAG_OWNS_HFONT
Definition lice_text.h:25
#define LICE_FONT_FLAG_FORCE_NATIVE
Definition lice_text.h:16
#define max(x, y)
Definition os.h:78
Definition lice_text.h:126
int sz
Definition lice_text.h:128
LICE_IFont * cache
Definition lice_text.h:127
Definition lice_text.h:102
int base_offset
Definition lice_text.h:103
int advance
Definition lice_text.h:105
int height
Definition lice_text.h:104
int width
Definition lice_text.h:104
int left_extra
Definition lice_text.h:107
int charid
Definition lice_text.h:106
Definition swell-types.h:519
char lfQuality
Definition swell-types.h:522
int lfHeight
Definition swell-types.h:520
int lfWidth
Definition swell-types.h:520
Definition swell-types.h:231
#define TRANSPARENT
#define DT_CALCRECT
#define NONANTIALIASED_QUALITY
HFONT CreateFontIndirect(LOGFONT *lf)
Definition swell-gdi-generic.cpp:160
unsigned int UINT
Definition swell-types.h:166
struct HGDIOBJ__ * HFONT
Definition swell-types.h:272
return c
Definition crypt.c:175
b
Definition crypt.c:628
typedef int(UZ_EXP MsgFn)()