YSTest: TextBase.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

TextBase.h
浏览该文件的文档.
1 /*
2 © 2009-2015 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 const Padding DefaultMargin(2, 2, 2, 2);
47
48
54 class YF_API PenStyle
55 {
56 public:
57 Drawing::Font Font;
58 Drawing::Color Color;
59
64 explicit
65 PenStyle(const Drawing::Font& fnt = {},
66 Drawing::Color c = Drawing::ColorSpace::White)
67 : Font(fnt), Color(c)
68 {}
69
70 DefGetterMem(const ynothrow, const FontFamily&, FontFamily, Font)
71 };
72
73
86 class YF_API TextState : protected PenStyle
87 {
88 public:
90 using PenStyle::Font;
92 using PenStyle::Color;
93 Padding Margin;
94
98 Point Pen{};
99 std::uint8_t LineGap = 0;
100
105 explicit
106 TextState(const Drawing::Font& = {}, const Padding& = DefaultMargin);
111 explicit
112 TextState(FontCache&, const Padding& = DefaultMargin);
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, char32_t c) const ynothrow
131 ImplRet(Rect(Pen.X, Pen.Y - Font.GetAscender(),
132 SDst(Font.GetAdvance(c)), 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 PDefH(SDst, GetTextLineHeightOf, const TextState& ts)
163 ImplRet(ts.Font.GetHeight())
164
165
169 inline PDefH(SDst, GetTextLineHeightExOf, const TextState& ts)
170 ImplRet(SDst(ts.Font.GetHeight() + ts.LineGap))
171
176 inline PDefH(ptrdiff_t, GetCurrentTextLineNOf, const TextState& ts)
177 ImplRet((ts.Pen.Y - ts.Margin.Top) / SPos(GetTextLineHeightExOf(ts)))
178
183 inline PDefH(SPos, GetTextLineBaseOf, const TextState& ts)
184 ImplRet(ts.Margin.Top + SPos(ts.Font.GetAscender()))
185
190 inline PDefH(void, SetPenOf, TextState& ts, SPos x, SPos y)
191 ImplExpr(ts.Pen = Point(x, y))
192
197 YF_API void
198 SetCurrentTextLineNOf(TextState&, std::uint16_t);
199
207 inline PDefH(void, AdjustEndOfLine, TextState& ts, const Rect& r, SDst w)
208 // XXX: Conversion to 'SPos' might be implementation-defined.
209 ImplExpr(ts.Margin.Right = SPos(w) - r.X - SPos(r.Width))
210 // ts.Margin = FetchMargin(r, s);
211
218 inline PDefH(void, CarriageReturn, TextState& ts)
219 ImplExpr(ts.Pen.X = ts.Margin.Left)
220
225 YF_API void
226 MovePen(TextState&, char32_t);
228
229 } // namespace Drawing;
230
231 } // namespace YSLib;
232
233 #endif
234
YSLib::Drawing::TextState
文本状态。
Definition: TextBase.h:87
YSLib::Drawing::Color
The boundary is out of the const Rect SDst SPos SPos SPos Color
Definition: YDraw.h:128
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:247
YSLib::Drawing::ImplRet
YB_ATTR_nodiscard YB_STATELESS yconstfn Rotation rot ImplRet(Rotation((size_t(rot)+1) % 4)) YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(Rotation
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
YSLib::Drawing::c
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect Color c
Definition: YDraw.h:174
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
YSLib::Drawing::x
const TextState &ts const TextState &ts const TextState &ts TextState SPos x
Definition: TextBase.h:190
YSLib::Drawing::ts
const TextState &ts const TextState &ts const TextState &ts TextState & ts
Definition: TextBase.h:190
YSLib::Drawing::GetTextLineHeightExOf
GetTextLineHeightExOf
Definition: TextBase.h:169
YSLib::Drawing::Right
YB_ATTR_nodiscard yconstfn YB_PURE x Right
Definition: YGDI.h:108
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::Drawing::FontCache
字体缓存。
Definition: Font.h:467
YSLib::Drawing::GetTextLineBaseOf
const TextState &ts const TextState &ts GetTextLineBaseOf
Definition: TextBase.h:183
YSLib::Drawing::PDefH
YB_ATTR_nodiscard YB_PURE yconstfn PDefH(Size, Transpose, const Size &s) ynothrow ImplRet(
转置。
Definition: YGDIBase.h:763
YSLib::Drawing::TextState::Font
Drawing::Font Font
Definition: TextBase.h:57
YSLib::Drawing::GetCurrentTextLineNOf
const TextState &ts GetCurrentTextLineNOf
Definition: TextBase.h:176
YSLib::Drawing::PenStyle::Color
Drawing::Color Color
笔颜色。
Definition: TextBase.h:58
YSLib::Drawing::FontFamily
字型家族。
Definition: Font.h:188
YSLib::Drawing::SetCurrentTextLineNOf
void SetCurrentTextLineNOf(TextState &ts, std::uint16_t n)
Definition: TextBase.cpp:75
YSLib::Drawing::PenStyle
笔样式：字体和笔颜色。
Definition: TextBase.h:55
YSLib::Drawing::Padding
空白样式。
Definition: YGDI.h:47
std
Definition: optional.h:982
YSLib::Drawing::GBinaryGroup< SPos >
platform::KeyCodes::DS::X
@ X
Definition: Keys.h:229
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::TextState::Margin
Padding Margin
边距：文本区域到显示区域的距离。
Definition: TextBase.h:93
YSLib::Drawing::PenStyle::Font
Drawing::Font Font
字体。
Definition: TextBase.h:57
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
platform::KeyCodes::DS::Y
@ Y
Definition: Keys.h:230
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YSLib::Drawing::PDefHOp
YB_ATTR_nodiscard yconstfn YB_PURE x x x Bottom YB_ATTR_nodiscard yconstfn YB_PURE PDefHOp(Padding,+, const Padding &x, const Padding &y) ynothrow ImplRet(Padding(x.Left+y.Left
加法：对应分量调用 operator+ 。
YModules.h
YSLib 用户界面模块配置文件。
YSLib::Drawing::MovePen
void MovePen(TextState &ts, char32_t c)
Definition: TextBase.cpp:82
YSLib::Drawing::ynothrow
YB_ATTR_nodiscard yconstfn YB_PURE x x x Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE const Padding & ynothrow
Definition: YGDI.h:132
YSLib::Drawing::ImplExpr
const TextState &ts const TextState &ts const TextState &ts TextState SPos SPos y ImplExpr(ts.Pen=Point(x, y)) YF_API void SetCurrentTextLineNOf(TextState &
设置笔的行位置。
YSLib::Drawing::Top
YB_ATTR_nodiscard yconstfn YB_PURE x x Top
Definition: YGDI.h:108
YSLib::Drawing::w
The boundary is out of the const Rect SDst w
Definition: YDraw.h:127
YSLib::Drawing::Font
字体：字模，包含字型、样式和大小。
Definition: Font.h:589
YSLib::Drawing::DefaultMargin
yconstexpr const Padding DefaultMargin(2, 2, 2, 2)
默认边距。
YSLib::Drawing::Font::GetHeight
YB_ATTR_nodiscard YB_PURE FontSize GetHeight() const ynothrow
取字体对应的字符高度。
Definition: Font.cpp:541
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
YSLib::Drawing::TextState::PDefH
#define PDefH(_t, _n,...)
取当前指定文本状态的字体设置对应的行高。
YSLib::Drawing::GetHeight
YB_ATTR_nodiscard YB_PURE tr GetHeight())) inline PDefH(void
按字体高度和行距调整文本区域的底边距。
YSLib::Drawing::char32_t
YB_ATTR_nodiscard YB_PURE tr TextRegion &tr char32_t
Definition: TextLayout.h:93
YSLib::Drawing::ColorSpace::White
@ White
Definition: YGDIBase.h:275
YSLib::Drawing::SetPenOf
const TextState &ts const TextState &ts const TextState &ts SetPenOf
Definition: TextBase.h:190
YSLib::Drawing::PenStyle::PenStyle
PenStyle(const Drawing::Font &fnt={}, Drawing::Color c=Drawing::ColorSpace::White)
构造：使用指定字体家族、字体大小和颜色。
Definition: TextBase.h:65