YSTest: TextLayout.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

TextLayout.cpp
浏览该文件的文档.
1 /*
2 © 2009-2016 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 #include "YSLib/Service/YModules.h"
29 #include YFM_YSLib_Service_TextLayout
30 #include YFM_YSLib_Service_YBlit
31
32 using namespace ystdex;
33
34 namespace YSLib
35 {
36
37 using namespace Drawing;
38 using namespace Text;
39
40 namespace Drawing
41 {
42
43 SDst
44 FetchResizedBottomMargin(const TextState& ts, SDst h)
45 {
46 YAssert(GetTextLineHeightExOf(ts) != 0, "Zero line height found.");
47 return SDst(max<SPos>(0, ts.Margin.Bottom)) + (h + ts.LineGap
48 - GetVerticalOf(ts.Margin)) % GetTextLineHeightExOf(ts);
49 }
50
51 std::uint16_t
52 FetchResizedLineN(const TextState& ts, SDst h)
53 {
54 YAssert(GetTextLineHeightExOf(ts) != 0, "Zero line height found.");
55 return (h + ts.LineGap - GetVerticalOf(ts.Margin))
56 / GetTextLineHeightExOf(ts);
57 }
58
59 SPos
60 FetchLastLineBasePosition(const TextState& ts, SDst h)
61 {
62 const auto n(FetchResizedLineN(ts, h));
63
64 // XXX: Conversion to 'SPos' might be implementation-defined.
65 return GetTextLineBaseOf(ts) + SPos(GetTextLineHeightExOf(ts))
66 * SPos(n > 0 ? n - 1 : n);
67 // return h - ts.Margin.Bottom + ts.GetCache().GetDescender() + 1;
68 }
69
70
71 SDst
72 FetchCharWidth(const Font& fnt, char32_t c)
73 {
74 // TODO: Support negtive horizontal advance.
75 return CheckNonnegative<SDst>(fnt.GetAdvance(c, fnt.GetGlyph(c)));
76 }
77
78 } // namespace Drawing;
79
80 } // namespace YSLib;
81
YSLib::Drawing::Font
字体：字模，包含字型、样式和大小。
Definition: Font.h:583
YModules.h
YSLib::Drawing::TextState::Margin
Padding Margin
边距：文本区域到显示区域的距离。
Definition: TextBase.h:93
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Drawing::Padding::Bottom
SPos Bottom
Definition: YGDI.h:52
Text
YSLib::Drawing::TextState::LineGap
std::uint8_t LineGap
行距。
Definition: TextBase.h:99
YAssert
#define YAssert(_expr, _msg)
Definition: cassert.h:111
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::TextState
文本状态。
Definition: TextBase.h:86
ystdex
特性测试宏。
Definition: ydef.h:822
YSLib::Drawing::FetchCharWidth
SDst FetchCharWidth(const Font &fnt, char32_t c)
Definition: TextLayout.cpp:72
Drawing
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
YSLib::Drawing::FetchResizedLineN
YF_API std::uint16_t FetchResizedLineN(const TextState &ts, SDst)
取指定文本状态和文本区域高所能显示的最大文本行数。
Definition: TextLayout.cpp:52
YSLib::Drawing::FetchLastLineBasePosition
YF_API SPos FetchLastLineBasePosition(const TextState &, SDst)
取指定文本状态在指定高的区域中表示的最底行的基线位置（纵坐标）。
Definition: TextLayout.cpp:60
CHRLib::c
c
Definition: CharacterProcessing.h:81
YSLib::Drawing::char32_t
tr TextRegion &tr char32_t
Definition: TextLayout.h:92
YSLib::Drawing::FetchResizedBottomMargin
YF_API SDst FetchResizedBottomMargin(const TextState &, SDst)
取指定文本状态和文本区域高调整的底边距。
Definition: TextLayout.cpp:44