2018-04-21 21:24:46 +08:00
|
|
|
|
#include "..\e2dnode.h"
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-05-17 15:22:14 +08:00
|
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
// Style
|
|
|
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Text::Style::Style()
|
2018-05-24 20:37:34 +08:00
|
|
|
|
: color(Color::White)
|
|
|
|
|
|
, alignment(Align::Left)
|
2018-09-04 22:42:34 +08:00
|
|
|
|
, wrap(false)
|
|
|
|
|
|
, wrap_width(0.f)
|
|
|
|
|
|
, line_spacing(0.f)
|
|
|
|
|
|
, underline(false)
|
|
|
|
|
|
, strikethrough(false)
|
|
|
|
|
|
, outline(true)
|
|
|
|
|
|
, outline_color(Color(Color::Black, 0.5))
|
|
|
|
|
|
, outline_width(1.f)
|
|
|
|
|
|
, outline_stroke(Stroke::Round)
|
2018-05-17 15:22:14 +08:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Text::Style::Style(
|
|
|
|
|
|
Color color,
|
|
|
|
|
|
Align alignment,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool wrap,
|
|
|
|
|
|
float wrap_width,
|
|
|
|
|
|
float line_spacing,
|
|
|
|
|
|
bool underline,
|
|
|
|
|
|
bool strikethrough,
|
|
|
|
|
|
bool outline,
|
|
|
|
|
|
Color outline_color,
|
|
|
|
|
|
float outline_width,
|
|
|
|
|
|
Stroke outline_stroke
|
2018-04-22 00:33:20 +08:00
|
|
|
|
)
|
2018-05-17 15:22:14 +08:00
|
|
|
|
: color(color)
|
|
|
|
|
|
, alignment(alignment)
|
2018-09-04 22:42:34 +08:00
|
|
|
|
, wrap(wrap)
|
|
|
|
|
|
, wrap_width(wrap_width)
|
|
|
|
|
|
, line_spacing(line_spacing)
|
|
|
|
|
|
, underline(underline)
|
|
|
|
|
|
, strikethrough(strikethrough)
|
|
|
|
|
|
, outline(outline)
|
|
|
|
|
|
, outline_color(outline_color)
|
|
|
|
|
|
, outline_width(outline_width)
|
|
|
|
|
|
, outline_stroke(outline_stroke)
|
2018-05-17 15:22:14 +08:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
// Text
|
|
|
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Text::Text()
|
2018-09-04 22:42:34 +08:00
|
|
|
|
: font_()
|
|
|
|
|
|
, style_()
|
|
|
|
|
|
, text_layout_(nullptr)
|
|
|
|
|
|
, text_format_(nullptr)
|
2018-05-17 15:22:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Text::Text(const String & text, const Font & font, const Style & style)
|
2018-09-04 22:42:34 +08:00
|
|
|
|
: font_(font)
|
|
|
|
|
|
, style_(style)
|
|
|
|
|
|
, text_layout_(nullptr)
|
|
|
|
|
|
, text_format_(nullptr)
|
|
|
|
|
|
, text_(text)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
Reset();
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Text::~Text()
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
SafeRelease(text_format_);
|
|
|
|
|
|
SafeRelease(text_layout_);
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
const e2d::String& e2d::Text::GetText() const
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return text_;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
const e2d::Font& e2d::Text::GetFont() const
|
2018-05-17 15:22:14 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return font_;
|
2018-05-17 15:22:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
const e2d::Text::Style& e2d::Text::GetStyle() const
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return style_;
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
const e2d::String& e2d::Text::GetFontFamily() const
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return font_.family;
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Text::GetFontSize() const
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return font_.size;
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
UINT e2d::Text::GetFontWeight() const
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return font_.weight;
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
const e2d::Color& e2d::Text::GetColor() const
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return style_.color;
|
2018-04-22 00:33:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
const e2d::Color& e2d::Text::GetOutlineColor() const
|
2018-04-22 00:33:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return style_.outline_color;
|
2018-04-22 00:33:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Text::GetOutlineWidth() const
|
2018-04-22 00:33:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return style_.outline_width;
|
2018-04-22 00:33:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Stroke e2d::Text::GetOutlineStroke() const
|
2018-04-22 00:33:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return style_.outline_stroke;
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
int e2d::Text::GetLineCount() const
|
2018-04-09 01:07:49 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (text_layout_)
|
2018-04-09 18:41:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
DWRITE_TEXT_METRICS metrics;
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_layout_->GetMetrics(&metrics);
|
2018-04-09 18:41:56 +08:00
|
|
|
|
return static_cast<int>(metrics.lineCount);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2018-04-09 01:07:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Text::IsItalic() const
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return font_.italic;
|
2018-04-22 00:33:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Text::strikethrough() const
|
2018-04-22 00:33:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return style_.strikethrough;
|
2018-04-22 14:08:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Text::underline() const
|
2018-04-22 14:08:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return style_.underline;
|
2018-04-22 14:08:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Text::outline() const
|
2018-04-22 14:08:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return style_.outline;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetText(const String& text)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_ = text;
|
|
|
|
|
|
Reset();
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetStyle(const Style& style)
|
2018-05-17 15:22:14 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_ = style;
|
|
|
|
|
|
Reset();
|
2018-05-17 15:22:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetFont(const Font & font)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
font_ = font;
|
|
|
|
|
|
Reset();
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetFontFamily(const String& family)
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
font_.family = family;
|
|
|
|
|
|
Reset();
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetFontSize(float size)
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
font_.size = size;
|
|
|
|
|
|
Reset();
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetFontWeight(UINT weight)
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
font_.weight = weight;
|
|
|
|
|
|
Reset();
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetColor(Color color)
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.color = color;
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetItalic(bool value)
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
font_.italic = value;
|
|
|
|
|
|
Reset();
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetWrapEnabled(bool wrap)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.wrap != wrap)
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.wrap = wrap;
|
|
|
|
|
|
Reset();
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetWrapWidth(float wrap_width)
|
2018-04-24 21:22:34 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.wrap_width != wrap_width)
|
2018-04-24 21:22:34 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.wrap_width = std::max(wrap_width, 0.f);
|
2018-04-24 21:22:34 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.wrap)
|
2018-04-24 21:22:34 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
Reset();
|
2018-04-24 21:22:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetLineSpacing(float line_spacing)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.line_spacing != line_spacing)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.line_spacing = line_spacing;
|
|
|
|
|
|
Reset();
|
2018-03-30 01:41:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetAlignment(Align align)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.alignment != align)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.alignment = align;
|
|
|
|
|
|
Reset();
|
2018-03-30 01:41:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetUnderline(bool underline)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.underline != underline)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.underline = underline;
|
|
|
|
|
|
if (!text_format_)
|
|
|
|
|
|
CreateFormat();
|
|
|
|
|
|
CreateLayout();
|
2018-03-30 01:41:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetStrikethrough(bool strikethrough)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.strikethrough != strikethrough)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.strikethrough = strikethrough;
|
|
|
|
|
|
if (!text_format_)
|
|
|
|
|
|
CreateFormat();
|
|
|
|
|
|
CreateLayout();
|
2018-03-30 01:41:29 +08:00
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetOutline(bool outline)
|
2018-04-22 00:33:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.outline = outline;
|
2018-04-22 00:33:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetOutlineColor(Color outline_color)
|
2018-04-22 00:33:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.outline_color = outline_color;
|
2018-04-22 00:33:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetOutlineWidth(float outline_width)
|
2018-04-22 00:33:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.outline_width = outline_width;
|
2018-04-22 00:33:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::SetOutlineStroke(Stroke outline_stroke)
|
2018-04-22 00:33:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.outline_stroke = outline_stroke;
|
2018-04-22 00:33:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::Draw() const
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (text_layout_)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
auto renderer = Renderer::GetInstance();
|
2018-04-22 00:33:20 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, size_.width, size_.height);
|
2018-04-22 00:33:20 +08:00
|
|
|
|
// <20><><EFBFBD>û<EFBFBD>ˢ<EFBFBD><CBA2>ɫ<EFBFBD><C9AB><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
renderer->GetSolidBrush()->SetOpacity(display_opacity_);
|
2018-04-22 00:33:20 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>Ⱦ<EFBFBD><C8BE>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
auto textRenderer = renderer->GetTextRenderer();
|
2018-08-28 00:06:10 +08:00
|
|
|
|
textRenderer->SetTextStyle(
|
2018-09-04 22:42:34 +08:00
|
|
|
|
(D2D1_COLOR_F)style_.color,
|
|
|
|
|
|
style_.outline,
|
|
|
|
|
|
(D2D1_COLOR_F)style_.outline_color,
|
|
|
|
|
|
style_.outline_width,
|
|
|
|
|
|
D2D1_LINE_JOIN(style_.outline_stroke)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
);
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_layout_->Draw(nullptr, textRenderer, 0, 0);
|
2018-03-30 01:41:29 +08:00
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::Reset()
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-03-30 23:37:42 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ʽ<EFBFBD><CABD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
CreateFormat();
|
2018-03-30 23:37:42 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
CreateLayout();
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::CreateFormat()
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
SafeRelease(text_format_);
|
2018-03-30 23:37:42 +08:00
|
|
|
|
|
2018-08-28 00:06:10 +08:00
|
|
|
|
ThrowIfFailed(
|
2018-09-04 22:42:34 +08:00
|
|
|
|
Renderer::GetWriteFactory()->CreateTextFormat(
|
2018-09-04 22:57:40 +08:00
|
|
|
|
(const wchar_t *)font_.family,
|
2018-08-28 00:06:10 +08:00
|
|
|
|
nullptr,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
DWRITE_FONT_WEIGHT(font_.weight),
|
|
|
|
|
|
font_.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
|
2018-08-28 00:06:10 +08:00
|
|
|
|
DWRITE_FONT_STRETCH_NORMAL,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
font_.size,
|
2018-08-28 00:06:10 +08:00
|
|
|
|
L"",
|
2018-09-04 22:42:34 +08:00
|
|
|
|
&text_format_
|
2018-08-28 00:06:10 +08:00
|
|
|
|
)
|
2018-03-30 23:37:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2018-08-28 00:06:10 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6>뷽ʽ
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_format_->SetTextAlignment(DWRITE_TEXT_ALIGNMENT(style_.alignment));
|
2018-08-28 00:06:10 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.line_spacing == 0.f)
|
2018-05-24 12:24:39 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_format_->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, 0, 0);
|
2018-05-24 12:24:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_format_->SetLineSpacing(
|
2018-08-28 00:06:10 +08:00
|
|
|
|
DWRITE_LINE_SPACING_METHOD_UNIFORM,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
style_.line_spacing,
|
|
|
|
|
|
style_.line_spacing * 0.8f
|
2018-08-28 00:06:10 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.wrap)
|
2018-08-28 00:06:10 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_format_->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP);
|
2018-08-28 00:06:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_format_->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Text::CreateLayout()
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
SafeRelease(text_layout_);
|
2018-03-30 23:37:42 +08:00
|
|
|
|
|
|
|
|
|
|
// <20>ı<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (text_.IsEmpty())
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetSize(0, 0);
|
2018-03-30 23:37:42 +08:00
|
|
|
|
return;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
2018-03-30 23:37:42 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (text_format_ == nullptr)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
WARN("Text::CreateLayout failed! text_format_ NULL pointer exception.");
|
2018-03-30 23:37:42 +08:00
|
|
|
|
return;
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
UINT32 length = (UINT32)text_.GetLength();
|
|
|
|
|
|
auto writeFactory = Renderer::GetWriteFactory();
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-03-30 23:37:42 +08:00
|
|
|
|
// <20><><EFBFBD>ı<EFBFBD><C4B1>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><C2BD>д<EFBFBD><D0B4><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.wrap)
|
2018-03-30 23:37:42 +08:00
|
|
|
|
{
|
2018-08-28 00:06:10 +08:00
|
|
|
|
ThrowIfFailed(
|
|
|
|
|
|
writeFactory->CreateTextLayout(
|
2018-09-04 22:57:40 +08:00
|
|
|
|
(const wchar_t *)text_,
|
2018-08-28 00:06:10 +08:00
|
|
|
|
length,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_format_,
|
|
|
|
|
|
style_.wrap_width,
|
2018-08-28 00:06:10 +08:00
|
|
|
|
0,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
&text_layout_
|
2018-08-28 00:06:10 +08:00
|
|
|
|
)
|
2018-03-30 23:37:42 +08:00
|
|
|
|
);
|
2018-08-28 00:06:10 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ֵĿ<D6B5><C4BF>Ⱥ߶<CDB8>
|
|
|
|
|
|
DWRITE_TEXT_METRICS metrics;
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_layout_->GetMetrics(&metrics);
|
2018-08-28 00:06:10 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetSize(metrics.layoutWidth, metrics.height);
|
2018-03-30 23:37:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-08-28 00:06:10 +08:00
|
|
|
|
// Ϊ<><CEAA>ֹ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD> layout <20>Ի<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
ThrowIfFailed(
|
|
|
|
|
|
writeFactory->CreateTextLayout(
|
2018-09-04 22:57:40 +08:00
|
|
|
|
(const wchar_t *)text_,
|
2018-08-28 00:06:10 +08:00
|
|
|
|
length,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_format_,
|
2018-08-28 00:06:10 +08:00
|
|
|
|
0,
|
|
|
|
|
|
0,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
&text_layout_
|
2018-08-28 00:06:10 +08:00
|
|
|
|
)
|
|
|
|
|
|
);
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-08-28 00:06:10 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ֵĿ<D6B5><C4BF>Ⱥ߶<CDB8>
|
|
|
|
|
|
DWRITE_TEXT_METRICS metrics;
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_layout_->GetMetrics(&metrics);
|
2018-08-28 00:06:10 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetSize(metrics.width, metrics.height);
|
2018-08-28 00:06:10 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>´<EFBFBD><C2B4><EFBFBD> layout
|
2018-09-04 22:42:34 +08:00
|
|
|
|
SafeRelease(text_layout_);
|
2018-08-28 00:06:10 +08:00
|
|
|
|
ThrowIfFailed(
|
|
|
|
|
|
writeFactory->CreateTextLayout(
|
2018-09-04 22:57:40 +08:00
|
|
|
|
(const wchar_t *)text_,
|
2018-08-28 00:06:10 +08:00
|
|
|
|
length,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_format_,
|
|
|
|
|
|
size_.width,
|
2018-08-28 00:06:10 +08:00
|
|
|
|
0,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
&text_layout_
|
2018-08-28 00:06:10 +08:00
|
|
|
|
)
|
|
|
|
|
|
);
|
2018-05-24 12:24:39 +08:00
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
|
2018-03-30 01:41:29 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>»<EFBFBD><C2BB>ߺ<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
DWRITE_TEXT_RANGE Range = { 0, length };
|
|
|
|
|
|
if (style_.underline)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_layout_->SetUnderline(true, Range);
|
2018-03-30 01:41:29 +08:00
|
|
|
|
}
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (style_.strikethrough)
|
2018-03-30 01:41:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
text_layout_->SetStrikethrough(true, Range);
|
2018-03-30 01:41:29 +08:00
|
|
|
|
}
|
2017-10-18 22:13:20 +08:00
|
|
|
|
}
|