YSTest: CharRenderer.cpp 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
CharRenderer.cpp
浏览该文件的文档.
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 #include "YSLib/Service/YModules.h"
29 #include YFM_YSLib_Service_CharRenderer
30 #include YFM_YSLib_Service_YPixel
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 namespace
44 {
45
47 const AlphaType BLT_TEXT_ALPHA_THRESHOLD(16);
48 PixelType char_color;
49
55 struct BlitTextPoint
56 {
58 template<typename _tOut, typename _tIn>
59 void
60 operator()(_tOut dst_iter, _tIn src_iter)
61 {
62 if(*src_iter >= BLT_TEXT_ALPHA_THRESHOLD)
63 yunseq(*dst_iter.base().second = *src_iter,
64 *dst_iter = char_color);
65 }
66 };
67
69
70 template<unsigned char _vN>
71 struct tr_seg
72 {
73 static_assert(_vN < CHAR_BIT, "Specified bits should be within a byte.");
74
75 byte v;
76
77 const byte&
78 operator()(const bitseg_iterator<_vN, true>& i) ynothrow
79 {
80 return v = byte(*i << (CHAR_BIT - _vN) | ((1U << _vN) - 1));
81 }
82 };
83
84
85 using PixelIt = pseudo_iterator<const PixelType>;
86
87 using BIt_1 = bitseg_iterator<1, true>;
88 using BIt_2 = bitseg_iterator<2, true>;
89 using BIt_4 = bitseg_iterator<4, true>;
90
91 using TIt_1 = transformed_iterator<BIt_1, tr_seg<1>>;
92 using TIt_2 = transformed_iterator<BIt_2, tr_seg<2>>;
93 using TIt_4 = transformed_iterator<BIt_4, tr_seg<4>>;
94
99 using MonoItPair = pair_iterator<PixelIt, const AlphaType*>;
100 using MonoItPair_1 = pair_iterator<PixelIt, TIt_1>;
101 using MonoItPair_2 = pair_iterator<PixelIt, TIt_2>;
102 using MonoItPair_4 = pair_iterator<PixelIt, TIt_4>;
103
105 using PairIt = pair_iterator<BitmapPtr, AlphaType*>;
106
107
108 template<unsigned char _vN>
109 auto
110 tr_buf(byte* p)
111 -> decltype(make_transform(bitseg_iterator<_vN, true>(p), tr_seg<_vN>()))
112 {
113 return make_transform(bitseg_iterator<_vN, true>(p), tr_seg<_vN>());
114 }
116
117 } // unnamed namespace;
118
119 void
120 RenderChar(PaintContext&& pc, Color c, bool neg_pitch,
121 CharBitmap::BufferType cbuf, CharBitmap::FormatType fmt, const Size& ss)
122 {
123 using namespace Shaders;
124
125 YAssert(cbuf, "Invalid buffer found.");
126 switch(fmt)
127 {
128 case CharBitmap::Mono:
129 BlitGlyphPixels(BlitAlphaPoint(), pc.Target.GetBufferPtr(),
130 MonoItPair_1(PixelIt(c), tr_buf<1>(cbuf)), ss, pc, neg_pitch);
131 break;
132 case CharBitmap::Gray2:
133 BlitGlyphPixels(BlitAlphaPoint(), pc.Target.GetBufferPtr(),
134 MonoItPair_2(PixelIt(c), tr_buf<2>(cbuf)), ss, pc, neg_pitch);
135 break;
136 case CharBitmap::Gray4:
137 BlitGlyphPixels(BlitAlphaPoint(), pc.Target.GetBufferPtr(),
138 MonoItPair_4(PixelIt(c), tr_buf<4>(cbuf)), ss, pc, neg_pitch);
139 break;
140 case CharBitmap::Gray:
141 BlitGlyphPixels(BlitAlphaPoint(), pc.Target.GetBufferPtr(),
142 MonoItPair(PixelIt(c), cbuf), ss, pc, neg_pitch);
143 default:
144 break;
145 }
146 }
147
148 void
149 RenderCharAlpha(PaintContext&& pc, Color c, bool neg_pitch,
150 CharBitmap::BufferType cbuf, CharBitmap::FormatType fmt, const Size& ss,
151 AlphaType* alpha)
152 {
153 YAssert(cbuf, "Invalid buffer found.");
154 char_color = c;
155 switch(fmt)
156 {
157 case CharBitmap::Mono:
158 BlitGlyphPixels(BlitTextPoint(), PairIt(pc.Target.GetBufferPtr(),
159 alpha), tr_buf<1>(cbuf), ss, pc, neg_pitch);
160 break;
161 case CharBitmap::Gray2:
162 BlitGlyphPixels(BlitTextPoint(), PairIt(pc.Target.GetBufferPtr(),
163 alpha), tr_buf<2>(cbuf), ss, pc, neg_pitch);
164 break;
165 case CharBitmap::Gray4:
166 BlitGlyphPixels(BlitTextPoint(), PairIt(pc.Target.GetBufferPtr(),
167 alpha), tr_buf<4>(cbuf), ss, pc, neg_pitch);
168 break;
169 case CharBitmap::Gray:
170 BlitGlyphPixels(BlitTextPoint(), PairIt(pc.Target.GetBufferPtr(),
171 alpha), cbuf, ss, pc, neg_pitch);
172 default:
173 break;
174 }
175 }
176
177
178 u8
179 PutCharBase(TextState& ts, SDst eol, ucs4_t c)
180 {
181 if(c == '\n')
182 {
183 ts.PutNewline();
184 return 0;
185 }
186 if(YB_UNLIKELY(!std::iswprint(c)))
187 return 0;
188 #if 0
189 const int max_w(GetBufferWidthN() - 1),
190 space_w(ts.GetCache().GetAdvance(' '));
191
192 if(max_w < space_w)
193 return line_breaks_l = 1;
194 #endif
195 if(YB_UNLIKELY(ts.Pen.X + ts.Font.GetAdvance(c) > eol))
196 {
197 ts.PutNewline();
198 return 1;
199 }
200 return 2;
201 }
202
203 } // namespace Drawing;
204
205 } // namespace YSLib;
206
YSLib::Drawing::TextState::Pen
Point Pen
笔坐标。
Definition: TextBase.h:99
ystdex::transformed_iterator
转换迭代器。
Definition: iterator.hpp:514
YSLib::Drawing::BlitGlyphPixels
void BlitGlyphPixels(_fPixelShader blit, _tOut dst, _tIn src, const Size &ss, const PaintContext &pc, bool neg_pitch)
字符按像素块传输。
Definition: CharRenderer.h:91
YSLib::Drawing::PutCharBase
YF_API u8 PutCharBase(TextState &, SDst, ucs4_t)
使用指定的文本状态和行末位置（横坐标）按需打印换行并判断是否需要渲染单个字符。
Definition: CharRenderer.cpp:179
ystdex::byte
unsigned char byte
字节类型。
Definition: ydef.h:555
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
YB_UNLIKELY
#define YB_UNLIKELY(expr)
分支预测提示。
Definition: ydef.h:298
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::Drawing::TextState
文本状态。
Definition: TextBase.h:87
YSLib::Drawing::PenStyle::Font
Drawing::Font Font
字体。
Definition: TextBase.h:57
YSLib::Drawing::CharBitmap::BufferType
::FT_Byte * BufferType
Definition: Font.h:360
YSLib::Drawing::GBinaryGroup::X
_type X
Definition: ygdibase.h:59
YSLib::Drawing::RenderChar
YF_API void RenderChar(PaintContext &&pc, Color, bool, CharBitmap::BufferType, CharBitmap::FormatType, const Size &)
渲染单个字符。
Definition: CharRenderer.cpp:120
YSLib::u8
std::uint8_t u8
通用数据类型。
Definition: yadaptor.h:67
platform::Consoles::Gray
Definition: Video.h:467
ystdex::pseudo_iterator
伪迭代器。
Definition: iterator.hpp:351
CHRLib::ucs4_t
char32_t ucs4_t
UCS-4 字符类型。
Definition: chrdef.h:45
CHRLib::c
c
Definition: chrproc.h:76
platform::Color
颜色。
Definition: Video.h:339
YModules.h
YSLib::Drawing::Size
屏幕区域大小。
Definition: ygdibase.h:249
YSLib::Drawing::CharBitmap::FormatType
FormatType
Definition: Font.h:362
v
byte v
Definition: CharRenderer.cpp:73
platform::AlphaType
ystdex::octet AlphaType
Definition: Video.h:186
ystdex::bitseg_iterator
位段迭代器。
Definition: iterator.hpp:1167
YAssert
#define YAssert(_expr, _msg)
Definition: cassert.h:73
ystdex::pair_iterator
成对迭代器。
Definition: iterator.hpp:835
YSLib::Drawing::RenderCharAlpha
YF_API void RenderCharAlpha(PaintContext &&pc, Color, bool, CharBitmap::BufferType, CharBitmap::FormatType, const Size &, AlphaType *)
渲染带 Alpha 缓冲的单个字符。
Definition: CharRenderer.cpp:149