29 #include YFM_YSLib_Service_TextRenderer
30 #include YFM_YSLib_Service_YBlit
31 #include YFM_YSLib_Service_TextLayout // for FetchLastLineBasePosition;
33 using namespace ystdex;
38 using namespace Drawing;
49 ClipChar(
const Graphics&
g,
const Point& pen,
const CharBitmap& cbmp, Rect
r)
51 YAssert(
bool(g),
"Invalid graphics context found.");
53 const auto pt(
ClipBounds(r, Rect(pen.X + cbmp.GetLeft(),
54 pen.Y - cbmp.GetTop(), cbmp.GetWidth(), cbmp.GetHeight())));
61 FetchBMPSrcWidth(
const CharBitmap& cbmp)
63 const SDst abs_pitch(std::abs(cbmp.GetPitch()));
65 switch(cbmp.GetFormat())
67 case CharBitmap::Mono:
69 case CharBitmap::Gray2:
71 case CharBitmap::Gray4:
80 template<
typename _tCharRenderer, _tCharRenderer& _fCharRenderer,
83 RenderCharFrom(
ucs4_t c,
const Graphics& g, TextState& ts,
const Rect& clip,
86 const auto cbmp(ts.Font.GetGlyph(c));
95 if(
const auto cbuf = cbmp.GetBuffer())
97 auto&& pc(ClipChar(g, ts.Pen, cbmp, clip));
100 if(!pc.ClipArea.IsUnstrictlyEmpty())
101 _fCharRenderer(std::move(pc), ts.Color, cbmp.GetPitch() < 0,
102 cbuf, cbmp.GetFormat(), {FetchBMPSrcWidth(cbmp),
105 ts.Pen.X += cbmp.GetXAdvance();
114 RenderCharFrom<decltype(RenderChar), RenderChar>(
c, GetContext(), State,
119 TextRenderer::ClearLine(
u16 l,
SDst n)
121 const auto&
g(GetContext());
122 const auto h(g.GetHeight());
126 if(n == 0 || l + n > h)
133 TextRegion::TextRegion()
140 TextRegion::operator()(
ucs4_t c)
142 RenderCharFrom<decltype(RenderCharAlpha), RenderCharAlpha>(
c,
143 TextRegion::GetContext(), GetTextState(),
Rect(GetSize())
144 + GetTextState().Margin, GetBufferAlphaPtr());
157 const auto&
g(GetContext());
166 (l + n > g.GetHeight() ? g.GetHeight() - l : n) * g.GetWidth());
169 ClearPixel(&pBufferAlpha[l * g.GetWidth()], t));
176 auto& ts(GetTextState());
195 -
Margin.
Top - std::abs(n)) * GetWidth());
205 yunseq(s *= GetWidth(), d *= GetWidth());
215 const String& str,
bool line_wrap)
227 const Rect txt_bounds(bounds + m);
248 const String& str,
bool line_wrap)
251 BlitTo(g.GetBufferPtr(), tr, g.GetSize(),
Point(), pt,
s);
YF_API Padding FetchMargin(const Rect &, const Size &)
取内边界相对于外边界的边距。
yconstfn const string _tParams && args
void ClearLine(u16 l, SDst n)
清除缓冲区第 l 行起始的 n 行像素。
YF_API void DrawClippedText(const Graphics &g, const Rect &mask, TextState &ts, const String &str, bool line_wrap)
绘制剪切区域的文本。
_tOut ClearPixel(_tOut dst, size_t n) ynothrow
清除指定位置的 n 个连续像素。
void ClearTextLine(u16)
清除缓冲区中的指定行号的文本行。
YF_API Point ClipBounds(Rect &, const Rect &)
根据指定源的边界优化绘制上下文的剪切区域。
std::uint16_t SDst
屏幕坐标距离。
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
CompactPixmapEx(ConstBitmapPtr, SDst, SDst)
构造:使用指定位图指针和大小。
Padding Margin
边距:文本区域到显示区域的距离。
#define YB_UNLIKELY(expr)
分支预测提示。
YSLib 标准字符串(使用 UCS-2 作为内部编码)。
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
#define yunseq
无序列依赖表达式组求值。
YF_API void DrawText(const Graphics &g, TextState &ts, const String &str, bool line_wrap)
绘制文本。
void InitializeFont()
初始化字体。
char32_t ucs4_t
UCS-4 字符类型。
_type * pod_move_n(const _type *first, size_t n, _type *result)
void PutText(bool multi, _tParams &&...args)
打印文本。
static yconstexpr FontSize DefaultSize
void Scroll(ptrdiff_t n)
缓冲区特效:整体移动 n 像素。
SDst GetTextLineHeightExOf(const TextState &ts)
取当前指定文本状态的字体设置对应的行高与行距之和。
PDefHOp(TextState &,=, const PenStyle &ps) ImplRet(PenStyle void ResetPen()
赋值:笔样式。
#define YAssert(_expr, _msg)
YF_API bool BlitTo(BitmapPtr, const CompactPixmapEx &, const Size &, const Point &, const Point &, const Size &, Rotation=RDeg0)
贴图:位图缓冲区向指针指定的缓冲区以贴图算法复制。