YSTest: CharRenderer.cpp 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
CharRenderer.cpp
浏览该文件的文档.
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 #include "YSLib/Service/CharRenderer.h"
29
30 using namespace ystdex;
31
32 YSL_BEGIN
33
34 using namespace Drawing;
35 using namespace Text;
36
37 YSL_BEGIN_NAMESPACE(Drawing)
38
39 namespace
40 {
41
42 const u8 BLT_TEXT_ALPHA_THRESHOLD(16);
43 PixelType char_color;
44
45 template<bool _bPositiveScan>
46 struct BlitTextLoop
47 {
49 void
50 operator()(int delta_x, int delta_y,
51 pair_iterator<BitmapPtr, u8*> dst_iter, u8* src_iter,
52 int dst_inc, int src_inc)
53 {
54 for(; delta_y > 0; --delta_y)
55 {
56 for(int x(0); x < delta_x; ++x)
57 {
58 if(*src_iter >= BLT_TEXT_ALPHA_THRESHOLD)
59 yunseq(*dst_iter.base().second = *src_iter,
60 *dst_iter = char_color);
61 yunseq(++src_iter, xcrease<_bPositiveScan>(dst_iter));
62 }
63 src_iter += src_inc;
64 delta_assign<_bPositiveScan>(dst_iter, dst_inc);
65 }
66 }
67 };
68
69 } // unnamed namespace;
70
71 void
72 RenderChar(PaintContext&& pc, Color c, CharBitmap::BufferType cbuf,
73 const Size& ss)
74 {
75 YAssert(cbuf, "Invalid buffer found.");
76
77 BlitChar<BlitBlendLoop>(pc.Target.GetBufferPtr(), MonoIteratorPair(
78 pseudo_iterator<const PixelType>(c), cbuf), ss, pc);
79 }
80
81 void
82 RenderCharAlpha(PaintContext&& pc, Color c, CharBitmap::BufferType cbuf,
83 const Size& ss, u8* alpha)
84 {
85 YAssert(cbuf, "Invalid buffer found.");
86
87 char_color = c;
88 BlitChar<BlitTextLoop>(pair_iterator<BitmapPtr, u8*>(
89 pc.Target.GetBufferPtr(), alpha), cbuf, ss, pc);
90 }
91
92
93 u8
94 PutCharBase(TextState& ts, SDst eol, ucs4_t c)
95 {
96 if(c == '\n')
97 {
98 ts.PutNewline();
99 return 0;
100 }
101 if(YB_UNLIKELY(!std::iswprint(c)))
102 return 0;
103 #if 0
104 const int max_w(GetBufferWidthN() - 1),
105 space_w(ts.GetCache().GetAdvance(' '));
106
107 if(max_w < space_w)
108 return line_breaks_l = 1;
109 #endif
110 if(YB_UNLIKELY(ts.Pen.X + ts.Font.GetAdvance(c) > eol))
111 {
112 ts.PutNewline();
113 return 1;
114 }
115 return 2;
116 }
117
118 YSL_END_NAMESPACE(Drawing)
119
120 YSL_END
121