[deploy] add FontStretch
This commit is contained in:
parent
7a263cd40a
commit
3d40f5cfe2
|
|
@ -143,7 +143,7 @@ void RenderContextImpl::DrawTextLayout(const TextLayout& layout, const Point& of
|
|||
|
||||
if (layout.GetOutlineStrokeStyle())
|
||||
{
|
||||
outline_width = layout.GetOutlineStrokeStyle()->GetStrokeWidth();
|
||||
outline_width = layout.GetOutlineStrokeStyle()->GetWidth();
|
||||
}
|
||||
|
||||
HRESULT hr = text_renderer_->DrawTextLayout(native.Get(), offset.x, offset.y, fill_brush.Get(),
|
||||
|
|
@ -170,7 +170,7 @@ void RenderContextImpl::DrawShape(const Shape& shape)
|
|||
auto geometry = NativePtr::Get<ID2D1Geometry>(shape);
|
||||
auto brush = NativePtr::Get<ID2D1Brush>(current_brush_);
|
||||
auto stroke_style = NativePtr::Get<ID2D1StrokeStyle>(current_stroke_);
|
||||
float stroke_width = current_stroke_ ? current_stroke_->GetStrokeWidth() : 1.0f;
|
||||
float stroke_width = current_stroke_ ? current_stroke_->GetWidth() : 1.0f;
|
||||
|
||||
render_target_->DrawGeometry(geometry.Get(), brush.Get(), stroke_width, stroke_style.Get());
|
||||
|
||||
|
|
@ -185,7 +185,7 @@ void RenderContextImpl::DrawLine(const Point& point1, const Point& point2)
|
|||
|
||||
auto brush = NativePtr::Get<ID2D1Brush>(current_brush_);
|
||||
auto stroke_style = NativePtr::Get<ID2D1StrokeStyle>(current_stroke_);
|
||||
float stroke_width = current_stroke_ ? current_stroke_->GetStrokeWidth() : 1.0f;
|
||||
float stroke_width = current_stroke_ ? current_stroke_->GetWidth() : 1.0f;
|
||||
|
||||
render_target_->DrawLine(DX::ConvertToPoint2F(point1), DX::ConvertToPoint2F(point2), brush.Get(), stroke_width,
|
||||
stroke_style.Get());
|
||||
|
|
@ -200,7 +200,7 @@ void RenderContextImpl::DrawRectangle(const Rect& rect)
|
|||
|
||||
auto brush = NativePtr::Get<ID2D1Brush>(current_brush_);
|
||||
auto stroke_style = NativePtr::Get<ID2D1StrokeStyle>(current_stroke_);
|
||||
float stroke_width = current_stroke_ ? current_stroke_->GetStrokeWidth() : 1.0f;
|
||||
float stroke_width = current_stroke_ ? current_stroke_->GetWidth() : 1.0f;
|
||||
|
||||
render_target_->DrawRectangle(DX::ConvertToRectF(rect), brush.Get(), stroke_width, stroke_style.Get());
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ void RenderContextImpl::DrawRoundedRectangle(const Rect& rect, const Vec2& radiu
|
|||
|
||||
auto brush = NativePtr::Get<ID2D1Brush>(current_brush_);
|
||||
auto stroke_style = NativePtr::Get<ID2D1StrokeStyle>(current_stroke_);
|
||||
float stroke_width = current_stroke_ ? current_stroke_->GetStrokeWidth() : 1.0f;
|
||||
float stroke_width = current_stroke_ ? current_stroke_->GetWidth() : 1.0f;
|
||||
|
||||
render_target_->DrawRoundedRectangle(D2D1::RoundedRect(DX::ConvertToRectF(rect), radius.x, radius.y), brush.Get(),
|
||||
stroke_width, stroke_style.Get());
|
||||
|
|
@ -229,7 +229,7 @@ void RenderContextImpl::DrawEllipse(const Point& center, const Vec2& radius)
|
|||
|
||||
auto brush = NativePtr::Get<ID2D1Brush>(current_brush_);
|
||||
auto stroke_style = NativePtr::Get<ID2D1StrokeStyle>(current_stroke_);
|
||||
float stroke_width = current_stroke_ ? current_stroke_->GetStrokeWidth() : 1.0f;
|
||||
float stroke_width = current_stroke_ ? current_stroke_->GetWidth() : 1.0f;
|
||||
|
||||
render_target_->DrawEllipse(D2D1::Ellipse(DX::ConvertToPoint2F(center), radius.x, radius.y), brush.Get(),
|
||||
stroke_width, stroke_style.Get());
|
||||
|
|
|
|||
|
|
@ -605,11 +605,11 @@ void RendererImpl::CreateTextLayout(TextLayout& layout, const String& content, c
|
|||
font = new Font;
|
||||
}
|
||||
|
||||
float font_size = font->GetSize();
|
||||
auto font_weight = DWRITE_FONT_WEIGHT(font->GetWeight());
|
||||
bool is_italic = (font->GetPosture() == FontPosture::Italic);
|
||||
auto font_style = is_italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
|
||||
auto collection = NativePtr::Get<IDWriteFontCollection>(font);
|
||||
float font_size = font->GetSize();
|
||||
auto font_weight = DWRITE_FONT_WEIGHT(font->GetWeight());
|
||||
auto font_style = DWRITE_FONT_STYLE(font->GetPosture());
|
||||
auto font_stretch = DWRITE_FONT_STRETCH(font->GetStretch());
|
||||
auto collection = NativePtr::Get<IDWriteFontCollection>(font);
|
||||
|
||||
WideString font_family;
|
||||
|
||||
|
|
@ -620,8 +620,8 @@ void RendererImpl::CreateTextLayout(TextLayout& layout, const String& content, c
|
|||
}
|
||||
|
||||
ComPtr<IDWriteTextFormat> format;
|
||||
hr = d2d_res_->CreateTextFormat(format, font_family.c_str(), collection, font_weight, font_style,
|
||||
DWRITE_FONT_STRETCH_NORMAL, font_size);
|
||||
hr = d2d_res_->CreateTextFormat(format, font_family.c_str(), collection, font_weight, font_style, font_stretch,
|
||||
font_size);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -87,14 +87,16 @@ FontPtr Font::Preload(const Resource& resource)
|
|||
Font::Font()
|
||||
: size_(18.0f)
|
||||
, weight_(FontWeight::Normal)
|
||||
, posture_(FontPosture::Regular)
|
||||
, posture_(FontPosture::Normal)
|
||||
, stretch_(FontStretch::Normal)
|
||||
{
|
||||
}
|
||||
|
||||
Font::Font(const String& family_name, float size, uint32_t weight, FontPosture posture)
|
||||
Font::Font(const String& family_name, float size, uint32_t weight, FontPosture posture, FontStretch stretch)
|
||||
: size_(size)
|
||||
, weight_(weight)
|
||||
, posture_(posture)
|
||||
, stretch_(stretch)
|
||||
{
|
||||
if (family_name.empty())
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ struct FontWeight
|
|||
Light = 300U,
|
||||
Normal = 400U, ///< Õý³£
|
||||
Medium = 500U,
|
||||
Bold = 700U,
|
||||
Bold = 700U, ///< 加粗
|
||||
ExtraBold = 800U,
|
||||
Black = 900U,
|
||||
ExtraBlack = 950U
|
||||
|
|
@ -59,10 +59,29 @@ struct FontWeight
|
|||
*/
|
||||
enum class FontPosture
|
||||
{
|
||||
Regular, ///< Õý³£
|
||||
Normal, ///< 正常
|
||||
Oblique, ///< 倾斜体
|
||||
Italic, ///< бÌå
|
||||
};
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 字体拉伸
|
||||
*/
|
||||
enum class FontStretch
|
||||
{
|
||||
Unknown,
|
||||
UltraCondensed,
|
||||
ExtraCondensed,
|
||||
Condensed, ///< 压缩
|
||||
SemiCondensed,
|
||||
Normal, ///< 正常
|
||||
SemiExpanded,
|
||||
Expanded, ///< 扩大
|
||||
ExtraExpanded,
|
||||
UltraExpanded,
|
||||
};
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief ×ÖÌå
|
||||
|
|
@ -91,7 +110,7 @@ public:
|
|||
/// @param weight ×ÖÌå´Öϸ
|
||||
/// @param posture ×ÖÌåÐÎ̬
|
||||
Font(const String& family_name, float size, uint32_t weight = FontWeight::Normal,
|
||||
FontPosture posture = FontPosture::Regular);
|
||||
FontPosture posture = FontPosture::Normal, FontStretch stretch = FontStretch::Normal);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief »ñÈ¡×ÖÌå×å
|
||||
|
|
@ -109,6 +128,10 @@ public:
|
|||
/// @brief »ñÈ¡×ÖÌåÐÎ̬
|
||||
FontPosture GetPosture() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取字体拉伸
|
||||
FontStretch GetStretch() const;
|
||||
|
||||
protected:
|
||||
/// \~chinese
|
||||
/// @brief »ñÈ¡×ÖÌå×å
|
||||
|
|
@ -118,6 +141,7 @@ protected:
|
|||
float size_;
|
||||
uint32_t weight_;
|
||||
FontPosture posture_;
|
||||
FontStretch stretch_;
|
||||
String family_name_;
|
||||
};
|
||||
|
||||
|
|
@ -195,6 +219,11 @@ inline FontPosture Font::GetPosture() const
|
|||
return posture_;
|
||||
}
|
||||
|
||||
inline FontStretch Font::GetStretch() const
|
||||
{
|
||||
return stretch_;
|
||||
}
|
||||
|
||||
inline void Font::SetFamilyName(const String& name)
|
||||
{
|
||||
family_name_ = name;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ StrokeStyle::StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join)
|
|||
StrokeStyle::StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, DashStyle dash, float dash_offset)
|
||||
: StrokeStyle()
|
||||
{
|
||||
SetStrokeWidth(width);
|
||||
SetWidth(width);
|
||||
SetCapStyle(cap);
|
||||
SetLineJoinStyle(line_join);
|
||||
SetDashStyle(dash);
|
||||
|
|
@ -43,7 +43,7 @@ StrokeStyle::StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, con
|
|||
float dash_offset)
|
||||
: StrokeStyle()
|
||||
{
|
||||
SetStrokeWidth(width);
|
||||
SetWidth(width);
|
||||
SetCapStyle(cap);
|
||||
SetLineJoinStyle(line_join);
|
||||
SetDashStyle(dash_array, dash_size);
|
||||
|
|
|
|||
|
|
@ -115,8 +115,7 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取线条宽度
|
||||
/// @param width ĎßĚőżíśČ
|
||||
float GetStrokeWidth() const;
|
||||
float GetWidth() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取线条端点样式
|
||||
|
|
@ -137,7 +136,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 设置线条宽度
|
||||
/// @param width 线条宽度
|
||||
void SetStrokeWidth(float width);
|
||||
void SetWidth(float width);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置线条端点样式
|
||||
|
|
@ -188,7 +187,7 @@ private:
|
|||
|
||||
/** @} */
|
||||
|
||||
inline float StrokeStyle::GetStrokeWidth() const
|
||||
inline float StrokeStyle::GetWidth() const
|
||||
{
|
||||
return stroke_width_;
|
||||
}
|
||||
|
|
@ -213,7 +212,7 @@ inline float StrokeStyle::GetDashOffset() const
|
|||
return dash_offset_;
|
||||
}
|
||||
|
||||
inline void StrokeStyle::SetStrokeWidth(float width)
|
||||
inline void StrokeStyle::SetWidth(float width)
|
||||
{
|
||||
stroke_width_ = width;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,16 +123,23 @@ void TextLayout::SetFont(FontPtr font)
|
|||
auto font_weight = DWRITE_FONT_WEIGHT(font->GetWeight());
|
||||
|
||||
hr = native->SetFontWeight(font_weight, { 0, content_length_ });
|
||||
KGE_THROW_IF_FAILED(hr, "IDWriteTextLayout::SetFontSize failed");
|
||||
KGE_THROW_IF_FAILED(hr, "IDWriteTextLayout::SetFontWeight failed");
|
||||
}
|
||||
|
||||
// reset font style
|
||||
{
|
||||
bool is_italic = (font->GetPosture() == FontPosture::Italic);
|
||||
auto font_style = is_italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
|
||||
auto font_style = DWRITE_FONT_STYLE(font->GetPosture());
|
||||
|
||||
hr = native->SetFontStyle(font_style, { 0, content_length_ });
|
||||
KGE_THROW_IF_FAILED(hr, "IDWriteTextLayout::SetFontSize failed");
|
||||
KGE_THROW_IF_FAILED(hr, "IDWriteTextLayout::SetFontStyle failed");
|
||||
}
|
||||
|
||||
// reset font stretch
|
||||
{
|
||||
auto font_stretch = DWRITE_FONT_STRETCH(font->GetStretch());
|
||||
|
||||
hr = native->SetFontStretch(font_stretch, { 0, content_length_ });
|
||||
KGE_THROW_IF_FAILED(hr, "IDWriteTextLayout::SetFontStretch failed");
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
|
|
|||
Loading…
Reference in New Issue