YSTest
PreAlpha_b400_20130424
The YSLib Test Project
首页
相关页面
模块
命名空间
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
TextLayout.h
浏览该文件的文档.
1
/*
2
Copyright by FrankHB 2009 - 2013.
3
4
This file is part of the YSLib project, and may only be used,
5
modified, and distributed under the terms of the YSLib project
6
license, LICENSE.TXT. By continuing to use, modify, or distribute
7
this file you indicate that you have read the license and
8
understand and accept it fully.
9
*/
10
28
#ifndef YSL_INC_SERVICE_TEXTLAYOUT_H_
29
#define YSL_INC_SERVICE_TEXTLAYOUT_H_ 1
30
31
#include "
TextRenderer.h
"
32
33
YSL_BEGIN
34
35
YSL_BEGIN_NAMESPACE
(Drawing)
36
37
44
YF_API
SDst
45
FetchResizedBottomMargin
(const TextState&,
SDst
);
46
53
YF_API
u16
54
FetchResizedLineN
(const TextState& ts, SDst);
55
62
YF_API
SPos
63
FetchLastLineBasePosition
(const TextState&, SDst);
64
65
70
inline SDst
71
FetchResizedBottomMargin
(const
TextRegion
& tr)
72
{
73
return
FetchResizedBottomMargin
(tr, tr.GetHeight());
74
}
75
80
inline
SDst
81
AdjustBottomMarginOf
(
TextRegion
& tr)
82
{
83
return
tr.
Margin
.
Bottom
=
FetchResizedBottomMargin
(tr);
84
}
85
86
92
YF_API
SDst
93
FetchCharWidth
(
const
Font&,
ucs4_t
);
94
95
101
template
<
typename
_tIn>
102
SDst
103
FetchStringWidth
(
const
Font
& fnt, _tIn s)
104
{
105
SDst
w
(0);
106
107
while
(*s !=
'\0'
)
108
w +=
FetchCharWidth
(fnt, *s++);
109
return
w
;
110
}
116
template
<
typename
_tIn>
117
SDst
118
FetchStringWidth
(
const
Font
& fnt, _tIn s, _tIn g,
ucs4_t
c = {})
119
{
120
SDst
w
(0);
121
122
while
(s != g && *s != c)
123
w
+=
FetchCharWidth
(fnt, *s++);
124
return
w
;
125
}
130
inline
SDst
131
FetchStringWidth
(
const
Font
& fnt,
const
String& str)
132
{
133
return
FetchStringWidth
(fnt, str.c_str());
134
}
141
template
<
typename
_tIn>
142
SDst
143
FetchStringWidth
(
TextState
& ts,
SDst
h
, _tIn s)
144
{
145
const
SPos
x(ts.
Pen
.
X
);
146
EmptyTextRenderer
r(ts, h);
147
148
PrintString
(r, s);
149
return
ts.
Pen
.
X
- x;
150
}
157
template
<
typename
_tIn>
158
SDst
159
FetchStringWidth
(
TextState
& ts,
SDst
h
, _tIn s, _tIn g,
ucs4_t
c = {})
160
{
161
const
SPos
x(ts.
Pen
.
X
);
162
EmptyTextRenderer r(ts, h);
163
164
PrintString
(r, s, g, c);
165
return
ts.
Pen
.
X
- x;
166
}
172
inline
SDst
173
FetchStringWidth
(
TextState
& ts,
SDst
h,
const
String& str)
174
{
175
return
FetchStringWidth
(ts, h, str.c_str());
176
}
177
178
183
template
<
typename
_tIn>
184
SDst
185
FetchMaxTextWidth
(
const
Font
& font, _tIn
first
, _tIn last)
186
{
187
SDst
max_width(0);
188
189
std::for_each(first, last,
190
[&](decltype(*first)& str){
191
SDst
ln_width(
FetchStringWidth
(font, str));
192
193
if
(ln_width > max_width)
194
max_width = ln_width;
195
});
196
return
max_width;
197
}
198
199
YSL_END_NAMESPACE
(Drawing)
200
201
YSL_END
202
203
#endif
204
YFramework
include
YSLib
Service
TextLayout.h
生成于 2013年 四月 24日 星期三 18:41:28 , 为 YSTest使用
1.8.2