6 #include "../heapbuf.h"
8 #define LICE_FONT_FLAG_VERTICAL 1 // rotate text to vertical (do not set the windows font to vertical though)
9 #define LICE_FONT_FLAG_VERTICAL_BOTTOMUP 2
11 #define LICE_FONT_FLAG_PRECALCALL 4
12 //#define LICE_FONT_FLAG_ALLOW_NATIVE 8
13 #define LICE_FONT_FLAG_FORCE_NATIVE 1024
15 #define LICE_FONT_FLAG_FX_BLUR 16
16 #define LICE_FONT_FLAG_FX_INVERT 32
17 #define LICE_FONT_FLAG_FX_MONO 64 // faster but no AA/etc
19 #define LICE_FONT_FLAG_FX_SHADOW 128 // these imply MONO
20 #define LICE_FONT_FLAG_FX_OUTLINE 256
22 #define LICE_FONT_FLAG_OWNS_HFONT 512
24 // could do a mask for these flags
25 #define LICE_FONT_FLAGS_HAS_FX(flag) \
26 (flag&(LICE_FONT_FLAG_VERTICAL|LICE_FONT_FLAG_VERTICAL_BOTTOMUP| \
27 LICE_FONT_FLAG_FX_BLUR|LICE_FONT_FLAG_FX_INVERT|LICE_FONT_FLAG_FX_MONO| \
28 LICE_FONT_FLAG_FX_SHADOW|LICE_FONT_FLAG_FX_OUTLINE))
30 #define LICE_DT_NEEDALPHA 0x80000000 // include in DrawText() if the output alpha channel is important
31 #define LICE_DT_USEFGALPHA 0x40000000 // uses alpha channel in fg color
36 virtual ~LICE_IFont() {}
38 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)
40 virtual LICE_pixel
SetTextColor(LICE_pixel color
)=0;
41 virtual LICE_pixel
SetBkColor(LICE_pixel color
)=0;
42 virtual LICE_pixel
SetEffectColor(LICE_pixel color
)=0;
43 virtual int SetBkMode(int bkmode
)=0;
44 virtual void SetCombineMode(int combine
, float alpha
=1.0f
)=0;
46 virtual int DrawText(LICE_IBitmap
*bm
, const char *str
, int strcnt
, RECT
*rect
, UINT dtFlags
)=0;
48 virtual LICE_pixel
GetTextColor()=0;
49 virtual HFONT
GetHFont()=0;
50 virtual int GetLineHeight()=0;
54 class LICE_CachedFont
: public LICE_IFont
58 virtual ~LICE_CachedFont();
60 virtual void SetFromHFont(HFONT font
, int flags
=0);
62 virtual LICE_pixel
SetTextColor(LICE_pixel color
) { LICE_pixel ret
=m_fg
; m_fg
=color
; return ret
; }
63 virtual LICE_pixel
SetBkColor(LICE_pixel color
) { LICE_pixel ret
=m_bg
; m_bg
=color
; return ret
; }
64 virtual LICE_pixel
SetEffectColor(LICE_pixel color
) { LICE_pixel ret
=m_effectcol
; m_effectcol
=color
; return ret
; }
65 virtual int SetBkMode(int bkmode
) { int bk
= m_bgmode
; m_bgmode
=bkmode
; return bk
; }
66 virtual void SetCombineMode(int combine
, float alpha
=1.0f
) { m_comb
=combine
; m_alpha
=alpha
; }
68 virtual int DrawText(LICE_IBitmap
*bm
, const char *str
, int strcnt
, RECT
*rect
, UINT dtFlags
)
70 return DrawTextImpl(bm
,str
,strcnt
,rect
,dtFlags
);
73 virtual LICE_pixel
GetTextColor() { return m_fg
; }
74 virtual HFONT
GetHFont() { return m_font
; }
75 virtual int GetLineHeight() { return m_line_height
; }
77 void SetLineSpacingAdjust(int amt
) { m_lsadj
=amt
; }
81 virtual bool DrawGlyph(LICE_IBitmap
*bm
, unsigned short c
, int xpos
, int ypos
, RECT
*clipR
);
82 int DrawTextImpl(LICE_IBitmap
*bm
, const char *str
, int strcnt
, RECT
*rect
, UINT dtFlags
); // cause swell defines DrawText to SWELL_DrawText etc
84 bool RenderGlyph(unsigned short idx
);
86 LICE_pixel m_fg
,m_bg
,m_effectcol
;
92 int m_line_height
,m_lsadj
;
95 int base_offset
; // offset in m_cachestore+1, so 1=offset0, 0=unset, -1=failed to render
98 int charid
; // used by m_extracharlist
100 charEnt
*findChar(unsigned short c
);
102 charEnt m_lowchars
[128]; // first 128 chars cached here
103 WDL_TypedBuf
<charEnt
> m_extracharlist
;
104 WDL_TypedBuf
<unsigned char> m_cachestore
;
106 static int _charSortFunc(const void *a
, const void *b
);
112 #endif//_LICE_TEXT_H_