YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
TextBase.h
浏览该文件的文档.
1 /*
2  © 2009-2014 FrankHB.
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_TextBase_h_
29 #define YSL_INC_Service_TextBase_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_Service_YGDI
33 #include YFM_YSLib_Adaptor_Font
34 #include YFM_YSLib_Core_YStorage
35 
36 namespace YSLib
37 {
38 
39 namespace Drawing
40 {
41 
46 yconstexpr Padding DefaultMargin(2, 2, 2, 2);
47 
48 
55 {
56 public:
59 
64  explicit
65  PenStyle(const Drawing::Font& fnt = {},
67  : Font(fnt), Color(c)
68  {}
69 
72 };
73 
74 
87 class YF_API TextState : protected PenStyle
88 {
89 public:
91  using PenStyle::Font;
93  using PenStyle::Color;
95 
101 
106  explicit
107  TextState(const Drawing::Font& = {});
111  explicit
112  TextState(FontCache&);
113 
117  PDefHOp(TextState&, =, const PenStyle& ps)
118  ImplRet(PenStyle::operator=(ps), *this)
122  PDefHOp(TextState&, =, const Padding& ms)
123  ImplRet(Margin = ms, *this)
124 
130  PDefH(Rect, GetCharBounds, ucs4_t c) const ynothrow
131  ImplRet(Rect(Pen.X, Pen.Y - Font.GetAscender(), Font.GetAdvance(c),
132  Font.GetHeight()))
133 
137  void
138  PutNewline();
139 
144  void
145  ResetPen();
152  void
153  ResetPen(const Point&, const Padding& = {});
154 };
155 
157 
158 
162 inline SDst
164 {
165  return ts.Font.GetHeight();
166 }
167 
172 inline SDst
174 {
175  return ts.Font.GetHeight() + ts.LineGap;
176 }
177 
182 inline u16
184 {
185  return (ts.Pen.Y - ts.Margin.Top) / GetTextLineHeightExOf(ts);
186 }
187 
192 inline SPos
194 {
195  return ts.Margin.Top + ts.Font.GetAscender();
196 }
197 
202 inline void
204 {
205  ts.Pen = Point(x, y);
206 }
207 
212 YF_API void
214 
222 inline void
224 {
225 // ts.Margin = FetchMargin(r, s);
226  ts.Margin.Right = w - r.X - r.Width;
227 }
228 
235 inline void
237 {
238  ts.Pen.X = ts.Margin.Left;
239 }
240 
245 YF_API void
248 
249 } // namespace Drawing;
250 
251 } // namespace YSLib;
252 
253 #endif
254 
s8 GetAscender() const
取升部。
Definition: Font.cpp:509
Point Pen
笔坐标。
Definition: TextBase.h:99
yconstexpr Padding DefaultMargin(2, 2, 2, 2)
默认边距。
u8 LineGap
行距。
Definition: TextBase.h:100
void SetPenOf(TextState &ts, SPos x, SPos y)
设置笔位置。
Definition: TextBase.h:203
#define ImplRet(...)
Definition: YBaseMacro.h:97
#define YF_API
Definition: Platform.h:64
笔样式:字体和笔颜色。
Definition: TextBase.h:54
void MovePen(TextState &ts, ucs4_t c)
Definition: TextBase.cpp:80
PenStyle(const Drawing::Font &fnt={}, Drawing::Color c=Drawing::ColorSpace::White)
构造:使用指定字体家族、字体大小和颜色。
Definition: TextBase.h:65
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:38
SDst GetTextLineHeightOf(const TextState &ts)
取当前指定文本状态的字体设置对应的行高。
Definition: TextBase.h:163
Padding Margin
边距:文本区域到显示区域的距离。
Definition: TextBase.h:94
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
Definition: ygdibase.h:235
字体缓存。
Definition: Font.h:415
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
文本状态。
Definition: TextBase.h:87
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
Drawing::Font Font
字体。
Definition: TextBase.h:57
u16 GetCurrentTextLineNOf(const TextState &ts)
取笔所在的当前行数。
Definition: TextBase.h:183
Drawing::Color Color
笔颜色。
Definition: TextBase.h:58
void SetCurrentTextLineNOf(TextState &ts, u16 n)
Definition: TextBase.cpp:74
p1 p1 Y
Definition: ydraw.h:188
Color
控制台颜色枚举。
Definition: Video.h:458
std::uint8_t u8
通用数据类型。
Definition: yadaptor.h:67
SPos GetTextLineBaseOf(const TextState &ts)
取第一行的基线位置(纵坐标)。
Definition: TextBase.h:193
空白样式。
Definition: ygdi.h:46
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
void CarriageReturn(TextState &ts)
回车。
Definition: TextBase.h:236
void AdjustEndOfLine(TextState &ts, const Rect &r, SDst w)
按指定显示区域和文本区域的宽重新设置右边距。
Definition: TextBase.h:223
char32_t ucs4_t
UCS-4 字符类型。
Definition: chrdef.h:45
bounds & r
Definition: ydraw.h:220
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:185
PDefH(void, DrawLineSeg, const Graphics &g, const Rect &bounds, const Point &p1, const Point &p2, Color c) ImplExpr(DrawLineSeg(g
字体:字模,包含字型、样式和大小。
Definition: Font.h:546
std::uint16_t u16
Definition: yadaptor.h:68
颜色。
Definition: Video.h:339
FontSize GetHeight() const ynothrow
取字体对应的字符高度。
Definition: Font.cpp:527
字型家族 (Typeface Family) 标识。
Definition: Font.h:170
SDst GetTextLineHeightExOf(const TextState &ts)
取当前指定文本状态的字体设置对应的行高与行距之和。
Definition: TextBase.h:173