16template <
typename T>
class TextWriterBase :
public CharWriter {
20 DRAWFLAG_ALIGN_TEXT_BASELINE = 0,
21 DRAWFLAG_ALIGN_TEXT_CENTER = (1 << 0),
22 DRAWFLAG_ALIGN_TEXT_RIGHT = (1 << 1),
25 DRAWFLAG_ALIGN_H_BASELINE = 0,
26 DRAWFLAG_ALIGN_H_CENTER = (1 << 4),
27 DRAWFLAG_ALIGN_H_RIGHT = (1 << 5),
30 DRAWFLAG_ALIGN_V_BASELINE = 0,
31 DRAWFLAG_ALIGN_V_CENTER = (1 << 8),
32 DRAWFLAG_ALIGN_V_TOP = (1 << 9),
35 DRAWFLAG_MASK_ALIGN_TEXT = DRAWFLAG_ALIGN_TEXT_BASELINE |
36 DRAWFLAG_ALIGN_TEXT_CENTER |
37 DRAWFLAG_ALIGN_TEXT_RIGHT,
39 DRAWFLAG_MASK_ALIGN_H = DRAWFLAG_ALIGN_H_BASELINE |
40 DRAWFLAG_ALIGN_H_CENTER |
41 DRAWFLAG_ALIGN_H_RIGHT,
43 DRAWFLAG_MASK_ALIGN_V = DRAWFLAG_ALIGN_V_BASELINE |
44 DRAWFLAG_ALIGN_V_CENTER | DRAWFLAG_ALIGN_V_TOP,
51 f32 GetWidthLimit()
const {
54 void SetWidthLimit(f32 limit) {
57 void ResetWidthLimit() {
58 mWidthLimit = NW4R_MATH_FLT_MAX;
61 f32 GetCharSpace()
const {
64 void SetCharSpace(f32 space) {
68 f32 GetLineSpace()
const {
71 void SetLineSpace(f32 space) {
75 int GetTabWidth()
const {
78 void SetTabWidth(
int width) {
82 ulong GetDrawFlag()
const {
85 void SetDrawFlag(ulong flag) {
93 mTagProcessor = pProcessor;
95 void ResetTagProcessor() {
96 mTagProcessor = &mDefaultTagProcessor;
99 f32 GetLineHeight()
const;
101 f32 CalcLineWidth(
const T* pStr,
int len);
102 f32 CalcStringWidth(
const T* pStr,
int len)
const;
103 void CalcStringRect(
Rect* pRect,
const T* pStr,
int len)
const;
105 int VSNPrintf(T* buffer, ulong count,
const T* pStr, std::va_list args);
106 f32 VPrintf(
const T* pStr, std::va_list args);
107 f32 Print(
const T* pStr,
int len);
109 static T* GetBuffer() {
110 return mFormatBuffer;
112 static T* SetBuffer(T* pBuffer, ulong size) {
113 T* pOldBuffer = mFormatBuffer;
114 mFormatBuffer = pBuffer;
115 mFormatBufferSize = size;
119 static ulong GetBufferSize() {
120 return mFormatBufferSize;
124 static const int DEFAULT_FORMAT_BUFFER_SIZE = 256;
126 static const ulong DRAWFLAG_MASK_ALL = DRAWFLAG_MASK_ALIGN_TEXT |
127 DRAWFLAG_MASK_ALIGN_H |
128 DRAWFLAG_MASK_ALIGN_V;
131 bool IsDrawFlagSet(ulong mask, ulong flag)
const {
132 return (mDrawFlag & mask) == flag;
135 bool CalcLineRectImpl(
Rect* pRect,
const T** ppStr,
int len);
136 void CalcStringRectImpl(
Rect* pRect,
const T* pStr,
int len);
138 f32 PrintImpl(
const T* pStr,
int len);
139 f32 AdjustCursor(f32* pX, f32* pY,
const T* pStr,
int len);
149 static T* mFormatBuffer;
150 static ulong mFormatBufferSize;