diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj index 4d28a923..4c78e446 100644 --- a/projects/kiwano/kiwano.vcxproj +++ b/projects/kiwano/kiwano.vcxproj @@ -138,6 +138,7 @@ + diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters index 48dff23d..b6aca19a 100644 --- a/projects/kiwano/kiwano.vcxproj.filters +++ b/projects/kiwano/kiwano.vcxproj.filters @@ -476,5 +476,8 @@ 2d + + renderer + \ No newline at end of file diff --git a/src/kiwano/2d/Canvas.cpp b/src/kiwano/2d/Canvas.cpp index 0f009977..5c442773 100644 --- a/src/kiwano/2d/Canvas.cpp +++ b/src/kiwano/2d/Canvas.cpp @@ -27,7 +27,7 @@ namespace kiwano Canvas::Canvas() : cache_expired_(false) , stroke_width_(1.0f) - , stroke_style_(StrokeStyle::Miter) + , stroke_style_() { } diff --git a/src/kiwano/2d/Canvas.h b/src/kiwano/2d/Canvas.h index d1530ba2..c23d45e6 100644 --- a/src/kiwano/2d/Canvas.h +++ b/src/kiwano/2d/Canvas.h @@ -206,7 +206,7 @@ namespace kiwano /// \~chinese /// @brief 设置轮廓样式 /// @param stroke_style 轮廓样式 - void SetStrokeStyle(StrokeStyle stroke_style); + void SetStrokeStyle(const StrokeStyle& stroke_style); /// \~chinese /// @brief 设置文字画刷样式 @@ -289,7 +289,7 @@ namespace kiwano stroke_width_ = std::max(width, 0.f); } - inline void Canvas::SetStrokeStyle(StrokeStyle stroke_style) + inline void Canvas::SetStrokeStyle(const StrokeStyle& stroke_style) { stroke_style_ = stroke_style; } diff --git a/src/kiwano/2d/ShapeActor.cpp b/src/kiwano/2d/ShapeActor.cpp index 6e0d1cb2..f49dfa41 100644 --- a/src/kiwano/2d/ShapeActor.cpp +++ b/src/kiwano/2d/ShapeActor.cpp @@ -26,7 +26,7 @@ namespace kiwano { ShapeActor::ShapeActor() : stroke_width_(1.f) - , stroke_style_(StrokeStyle::Miter) + , stroke_style_() { } @@ -57,7 +57,7 @@ namespace kiwano stroke_width_ = std::max(width, 0.f); } - void ShapeActor::SetStrokeStyle(StrokeStyle stroke_style) + void ShapeActor::SetStrokeStyle(const StrokeStyle& stroke_style) { stroke_style_ = stroke_style; } diff --git a/src/kiwano/2d/ShapeActor.h b/src/kiwano/2d/ShapeActor.h index acf1b3df..5274d952 100644 --- a/src/kiwano/2d/ShapeActor.h +++ b/src/kiwano/2d/ShapeActor.h @@ -69,7 +69,7 @@ namespace kiwano /// \~chinese /// @brief 获取线条样式 - StrokeStyle SetStrokeStyle() const; + const StrokeStyle& GetStrokeStyle() const; /// \~chinese /// @brief 获取形状 @@ -113,7 +113,7 @@ namespace kiwano /// \~chinese /// @brief 设置线条样式 - void SetStrokeStyle(StrokeStyle stroke_style); + void SetStrokeStyle(const StrokeStyle& stroke_style); /// \~chinese /// @brief 设置几何形状 @@ -378,25 +378,25 @@ namespace kiwano fill_brush_->SetColor(color); } - inline void ShapeActor::SetFillBrush(BrushPtr brush) { fill_brush_ = brush; } - inline void ShapeActor::SetStrokeBrush(BrushPtr brush) { stroke_brush_ = brush; } - inline BrushPtr ShapeActor::GetFillBrush() const { return fill_brush_; } - inline BrushPtr ShapeActor::GetStrokeBrush() const { return stroke_brush_; } - inline float ShapeActor::GetStrokeWidth() const { return stroke_width_; } - inline StrokeStyle ShapeActor::SetStrokeStyle() const { return stroke_style_; } - inline Geometry ShapeActor::GetGeometry() const { return geo_; } + inline void ShapeActor::SetFillBrush(BrushPtr brush) { fill_brush_ = brush; } + inline void ShapeActor::SetStrokeBrush(BrushPtr brush) { stroke_brush_ = brush; } + inline BrushPtr ShapeActor::GetFillBrush() const { return fill_brush_; } + inline BrushPtr ShapeActor::GetStrokeBrush() const { return stroke_brush_; } + inline float ShapeActor::GetStrokeWidth() const { return stroke_width_; } + inline const StrokeStyle& ShapeActor::GetStrokeStyle() const { return stroke_style_; } + inline Geometry ShapeActor::GetGeometry() const { return geo_; } - inline Point const& LineActor::GetBeginPoint() const { return begin_; } - inline Point const& LineActor::GetEndPoint() const { return end_; } - inline void LineActor::SetBeginPoint(Point const& begin) { SetLine(begin, end_); } - inline void LineActor::SetEndPoint(Point const& end) { SetLine(begin_, end); } + inline Point const& LineActor::GetBeginPoint() const { return begin_; } + inline Point const& LineActor::GetEndPoint() const { return end_; } + inline void LineActor::SetBeginPoint(Point const& begin) { SetLine(begin, end_); } + inline void LineActor::SetEndPoint(Point const& end) { SetLine(begin_, end); } - inline Size const& RectActor::GetRectSize() const { return rect_size_; } + inline Size const& RectActor::GetRectSize() const { return rect_size_; } - inline Vec2 RoundRectActor::GetRadius() const { return radius_; } - inline Size RoundRectActor::GetRectSize() const { return GetSize(); } + inline Vec2 RoundRectActor::GetRadius() const { return radius_; } + inline Size RoundRectActor::GetRectSize() const { return GetSize(); } - inline float CircleActor::GetRadius() const { return radius_; } + inline float CircleActor::GetRadius() const { return radius_; } inline Vec2 EllipseActor::GetRadius() const { return radius_; } } diff --git a/src/kiwano/2d/TextActor.cpp b/src/kiwano/2d/TextActor.cpp index 999181e0..a0402182 100644 --- a/src/kiwano/2d/TextActor.cpp +++ b/src/kiwano/2d/TextActor.cpp @@ -94,6 +94,8 @@ namespace kiwano if (text_layout_.GetDirtyFlag() & TextLayout::DirtyFlag::Updated) { + text_layout_.SetDirtyFlag(TextLayout::DirtyFlag::Clean); + if (show_underline_) text_layout_.SetUnderline(true, 0, text_layout_.GetText().length()); diff --git a/src/kiwano/2d/TextActor.h b/src/kiwano/2d/TextActor.h index 47496d12..08bf2398 100644 --- a/src/kiwano/2d/TextActor.h +++ b/src/kiwano/2d/TextActor.h @@ -147,7 +147,7 @@ namespace kiwano /// \~chinese /// @brief 设置文字描边线相交样式 - void SetOutlineStroke(StrokeStyle outline_stroke); + void SetOutlineStroke(const StrokeStyle& outline_stroke); /// \~chinese /// @brief 设置是否显示下划线(默认值为 false) @@ -295,7 +295,7 @@ namespace kiwano text_layout_.SetOutlineWidth(outline_width); } - inline void TextActor::SetOutlineStroke(StrokeStyle outline_stroke) + inline void TextActor::SetOutlineStroke(const StrokeStyle& outline_stroke) { text_layout_.SetOutlineStroke(outline_stroke); } diff --git a/src/kiwano/renderer/RenderTarget.cpp b/src/kiwano/renderer/RenderTarget.cpp index d849dc49..172aa14a 100644 --- a/src/kiwano/renderer/RenderTarget.cpp +++ b/src/kiwano/renderer/RenderTarget.cpp @@ -59,53 +59,11 @@ namespace kiwano Resize(reinterpret_cast(GetRenderTarget()->GetSize())); } - if (SUCCEEDED(hr)) - { - ComPtr miter_stroke_style; - ComPtr bevel_stroke_style; - ComPtr round_stroke_style; - - D2D1_STROKE_STYLE_PROPERTIES stroke_style = D2D1::StrokeStyleProperties( - D2D1_CAP_STYLE_FLAT, - D2D1_CAP_STYLE_FLAT, - D2D1_CAP_STYLE_FLAT, - D2D1_LINE_JOIN_MITER, - 2.0f, - D2D1_DASH_STYLE_SOLID, - 0.0f - ); - - hr = factory->CreateStrokeStyle(stroke_style, nullptr, 0, &miter_stroke_style); - - if (SUCCEEDED(hr)) - { - stroke_style.lineJoin = D2D1_LINE_JOIN_BEVEL; - hr = factory->CreateStrokeStyle(stroke_style, nullptr, 0, &bevel_stroke_style); - } - - if (SUCCEEDED(hr)) - { - stroke_style.lineJoin = D2D1_LINE_JOIN_ROUND; - hr = factory->CreateStrokeStyle(stroke_style, nullptr, 0, &round_stroke_style); - } - - if (SUCCEEDED(hr)) - { - miter_stroke_style_ = miter_stroke_style; - bevel_stroke_style_ = bevel_stroke_style; - round_stroke_style_ = round_stroke_style; - } - } - return hr; } void RenderTarget::DiscardDeviceResources() { - miter_stroke_style_.reset(); - bevel_stroke_style_.reset(); - round_stroke_style_.reset(); - text_renderer_.reset(); render_target_.reset(); current_brush_.reset(); @@ -140,7 +98,7 @@ namespace kiwano } } - void RenderTarget::DrawGeometry(Geometry const& geometry, float stroke_width, StrokeStyle stroke) + void RenderTarget::DrawGeometry(Geometry const& geometry, float stroke_width, const StrokeStyle& stroke) { KGE_ASSERT(render_target_ && "Render target has not been initialized!"); KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); @@ -151,7 +109,7 @@ namespace kiwano geometry.GetGeometry().get(), current_brush_->GetBrush().get(), stroke_width, - GetStrokeStyle(stroke).get() + stroke.GetStrokeStyle().get() ); IncreasePrimitivesCount(); @@ -174,7 +132,7 @@ namespace kiwano } } - void RenderTarget::DrawLine(Point const& point1, Point const& point2, float stroke_width, StrokeStyle stroke) + void RenderTarget::DrawLine(Point const& point1, Point const& point2, float stroke_width, const StrokeStyle& stroke) { KGE_ASSERT(render_target_ && "Render target has not been initialized!"); KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); @@ -184,13 +142,13 @@ namespace kiwano DX::ConvertToPoint2F(point2), current_brush_->GetBrush().get(), stroke_width, - GetStrokeStyle(stroke).get() + stroke.GetStrokeStyle().get() ); IncreasePrimitivesCount(); } - void RenderTarget::DrawRectangle(Rect const& rect, float stroke_width, StrokeStyle stroke) + void RenderTarget::DrawRectangle(Rect const& rect, float stroke_width, const StrokeStyle& stroke) { KGE_ASSERT(render_target_ && "Render target has not been initialized!"); KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); @@ -199,7 +157,7 @@ namespace kiwano DX::ConvertToRectF(rect), current_brush_->GetBrush().get(), stroke_width, - GetStrokeStyle(stroke).get() + stroke.GetStrokeStyle().get() ); IncreasePrimitivesCount(); @@ -218,7 +176,7 @@ namespace kiwano IncreasePrimitivesCount(); } - void RenderTarget::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, float stroke_width, StrokeStyle stroke) + void RenderTarget::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, float stroke_width, const StrokeStyle& stroke) { KGE_ASSERT(render_target_ && "Render target has not been initialized!"); KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); @@ -231,7 +189,7 @@ namespace kiwano ), current_brush_->GetBrush().get(), stroke_width, - GetStrokeStyle(stroke).get() + stroke.GetStrokeStyle().get() ); IncreasePrimitivesCount(); @@ -254,7 +212,7 @@ namespace kiwano IncreasePrimitivesCount(); } - void RenderTarget::DrawEllipse(Point const& center, Vec2 const& radius, float stroke_width, StrokeStyle stroke) + void RenderTarget::DrawEllipse(Point const& center, Vec2 const& radius, float stroke_width, const StrokeStyle& stroke) { KGE_ASSERT(render_target_ && "Render target has not been initialized!"); KGE_ASSERT(current_brush_ && "The brush used for rendering has not been set!"); @@ -267,7 +225,7 @@ namespace kiwano ), current_brush_->GetBrush().get(), stroke_width, - GetStrokeStyle(stroke).get() + stroke.GetStrokeStyle().get() ); IncreasePrimitivesCount(); @@ -346,7 +304,7 @@ namespace kiwano fill_brush.get(), outline_brush.get(), style.outline_width, - GetStrokeStyle(style.outline_stroke).get() + style.outline_stroke.GetStrokeStyle().get() ); if (SUCCEEDED(hr)) @@ -449,17 +407,6 @@ namespace kiwano render_target_->Clear(DX::ConvertToColorF(clear_color)); } - ComPtr RenderTarget::GetStrokeStyle(StrokeStyle style) - { - switch (style) - { - case StrokeStyle::Miter: return miter_stroke_style_; - case StrokeStyle::Bevel: return bevel_stroke_style_; - case StrokeStyle::Round: return round_stroke_style_; - } - return nullptr; - } - void RenderTarget::SetTransform(const Matrix3x2& matrix) { KGE_ASSERT(render_target_ && "Render target has not been initialized!"); diff --git a/src/kiwano/renderer/RenderTarget.h b/src/kiwano/renderer/RenderTarget.h index 2e580cd4..acd210b6 100644 --- a/src/kiwano/renderer/RenderTarget.h +++ b/src/kiwano/renderer/RenderTarget.h @@ -77,7 +77,7 @@ namespace kiwano void DrawGeometry( Geometry const& geometry, float stroke_width, - StrokeStyle stroke = StrokeStyle::Miter + const StrokeStyle& stroke = StrokeStyle() ); /// \~chinese @@ -92,7 +92,7 @@ namespace kiwano Point const& point1, Point const& point2, float stroke_width, - StrokeStyle stroke = StrokeStyle::Miter + const StrokeStyle& stroke = StrokeStyle() ); /// \~chinese @@ -100,7 +100,7 @@ namespace kiwano void DrawRectangle( Rect const& rect, float stroke_width, - StrokeStyle stroke = StrokeStyle::Miter + const StrokeStyle& stroke = StrokeStyle() ); /// \~chinese @@ -115,7 +115,7 @@ namespace kiwano Rect const& rect, Vec2 const& radius, float stroke_width, - StrokeStyle stroke = StrokeStyle::Miter + const StrokeStyle& stroke = StrokeStyle() ); /// \~chinese @@ -131,7 +131,7 @@ namespace kiwano Point const& center, Vec2 const& radius, float stroke_width, - StrokeStyle stroke = StrokeStyle::Miter + const StrokeStyle& stroke = StrokeStyle() ); /// \~chinese @@ -288,8 +288,6 @@ namespace kiwano ComPtr GetTextRenderer() const; - ComPtr GetStrokeStyle(StrokeStyle style); - private: /// \~chinese /// @brief 创建设备依赖资源 @@ -310,9 +308,6 @@ namespace kiwano TextAntialiasMode text_antialias_; ComPtr text_renderer_; ComPtr render_target_; - ComPtr miter_stroke_style_; - ComPtr bevel_stroke_style_; - ComPtr round_stroke_style_; BrushPtr current_brush_; Rect visible_size_; Matrix3x2 global_transform_; diff --git a/src/kiwano/renderer/Renderer.cpp b/src/kiwano/renderer/Renderer.cpp index 4b81f6ad..efbaa99b 100644 --- a/src/kiwano/renderer/Renderer.cpp +++ b/src/kiwano/renderer/Renderer.cpp @@ -968,6 +968,38 @@ namespace kiwano win32::ThrowIfFailed(hr); } + void Renderer::CreateStrokeStyle(StrokeStyle& stroke_style, CapStyle cap, LineJoinStyle line_join, const float* dash_array, size_t dash_size, float dash_offset) + { + HRESULT hr = S_OK; + if (!d2d_res_) + { + hr = E_UNEXPECTED; + } + + if (SUCCEEDED(hr)) + { + D2D1_STROKE_STYLE_PROPERTIES style = D2D1::StrokeStyleProperties( + D2D1_CAP_STYLE(cap), + D2D1_CAP_STYLE(cap), + D2D1_CAP_STYLE(cap), + D2D1_LINE_JOIN(line_join), + 10.0f, + D2D1_DASH_STYLE_CUSTOM, + dash_offset + ); + + ComPtr output; + hr = d2d_res_->GetFactory()->CreateStrokeStyle(style, dash_array, dash_size, &output); + + if (SUCCEEDED(hr)) + { + stroke_style.SetStrokeStyle(output); + } + } + + win32::ThrowIfFailed(hr); + } + void Renderer::SetDpi(float dpi) { KGE_ASSERT(d3d_res_ && d2d_res_); diff --git a/src/kiwano/renderer/Renderer.h b/src/kiwano/renderer/Renderer.h index c0b27f39..a1212ea1 100644 --- a/src/kiwano/renderer/Renderer.h +++ b/src/kiwano/renderer/Renderer.h @@ -258,6 +258,23 @@ namespace kiwano RadialGradientStyle const& style ); + /// \~chinese + /// @brief 创建线条样式 + /// @param[out] stroke_style 线条样式 + /// @param[in] cap 线段端点样式 + /// @param[in] line_join 线段相交样式 + /// @param[in] dash_array 虚线长度与间隙数组 + /// @param[in] dash_size 虚线数组大小 + /// @param[in] dash_offset 虚线偏移量 + void CreateStrokeStyle( + StrokeStyle& stroke_style, + CapStyle cap, + LineJoinStyle line_join, + const float* dash_array, + size_t dash_size, + float dash_offset + ); + public: /// \~chinese /// @brief 获取目标窗口 diff --git a/src/kiwano/renderer/StrokeStyle.cpp b/src/kiwano/renderer/StrokeStyle.cpp new file mode 100644 index 00000000..afffd048 --- /dev/null +++ b/src/kiwano/renderer/StrokeStyle.cpp @@ -0,0 +1,77 @@ +// Copyright (c) 2016-2019 Kiwano - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include +#include + +namespace kiwano +{ + + StrokeStyle::StrokeStyle() + { + } + + StrokeStyle StrokeStyle::Create(CapStyle cap, LineJoinStyle line_join, DashStyle dash, float dash_offset) + { + switch (dash) + { + case DashStyle::Solid: + { + return StrokeStyle::Create(cap, line_join, nullptr, 0, dash_offset); + } + + case DashStyle::Dash: + { + float dash_array[] = { 2, 2 }; + return StrokeStyle::Create(cap, line_join, dash_array, dash_offset); + } + + case DashStyle::Dot: + { + float dash_array[] = { 0, 2 }; + return StrokeStyle::Create(cap, line_join, dash_array, dash_offset); + } + + case DashStyle::DashDot: + { + float dash_array[] = { 2, 2, 0, 2 }; + return StrokeStyle::Create(cap, line_join, dash_array, dash_offset); + } + + case DashStyle::DashDotDot: + { + float dash_array[] = { 2, 2, 0, 2, 0, 2 }; + return StrokeStyle::Create(cap, line_join, dash_array, dash_offset); + } + + default: + break; + } + return StrokeStyle(); + } + + StrokeStyle StrokeStyle::Create(CapStyle cap, LineJoinStyle line_join, const float* dash_array, size_t dash_size, float dash_offset) + { + StrokeStyle stroke_style; + Renderer::instance().CreateStrokeStyle(stroke_style, cap, line_join, dash_array, dash_size, dash_offset); + return stroke_style; + } + +} diff --git a/src/kiwano/renderer/StrokeStyle.h b/src/kiwano/renderer/StrokeStyle.h index 1696e274..6e52d3e9 100644 --- a/src/kiwano/renderer/StrokeStyle.h +++ b/src/kiwano/renderer/StrokeStyle.h @@ -19,23 +19,119 @@ // THE SOFTWARE. #pragma once +#include namespace kiwano { + class RenderTarget; + class Renderer; + /** * \addtogroup Render * @{ */ /// \~chinese - /// @brief 线条样式 - /// @details 线条样式表示渲染目标在绘制线条时,如何处理两条线相交部分 - enum class StrokeStyle + /// @brief 线条端点样式 + /// @details 线条端点样式表示线段端点部分的形状 + enum class CapStyle { - Miter = 0, ///< 斜切样式 - Bevel = 1, ///< 斜角样式 - Round = 2 ///< 圆角样式 + Flat, ///< 扁端点 + Square, ///< 方形端点,方形突出部分等于线段宽度的一半 + Round, ///< 圆形端点,圆直径等于线段宽度 + Triangle, ///< 三角样式,三角斜边长度等于线段宽度 + }; + + /// \~chinese + /// @brief 线条交点样式 + /// @details 线条交点样式表示两条线相交部分的形状 + enum class LineJoinStyle + { + Miter, ///< 斜切样式 + Bevel, ///< 斜角样式 + Round ///< 圆角样式 + }; + + /// \~chinese + /// @brief 线条虚线样式 + /// @details 线条虚线样式表示线段的间隙 + enum class DashStyle + { + Solid, ///< 无间断的实线 + Dash, ///< 斜角样式 + Dot, ///< 圆角样式 + DashDot, ///< 圆角样式 + DashDotDot, ///< 圆角样式 + }; + + /// \~chinese + /// @brief 线条样式 + class StrokeStyle + { + friend class RenderTarget; + friend class Renderer; + + public: + StrokeStyle(); + + /// \~chinese + /// @brief 是否有效 + bool IsValid() const; + + /// \~chinese + /// @brief 创建线条样式 + /// @param cap 线条端点样式 + /// @param line_join 线条交点样式 + /// @param dash 线条虚线样式 + /// @param dash_offset 线条虚线偏移量 + static StrokeStyle Create(CapStyle cap, LineJoinStyle line_join = LineJoinStyle::Miter, DashStyle dash = DashStyle::Solid, float dash_offset = 0.0f); + + /// \~chinese + /// @brief 创建线条样式 + /// @param cap 线条端点样式 + /// @param line_join 线条交点样式 + /// @param dash_array 线条虚线的长度与间隙数组 + /// @param dash_size 线条虚线数组大小 + /// @param dash_offset 线条虚线偏移量 + static StrokeStyle Create(CapStyle cap, LineJoinStyle line_join = LineJoinStyle::Miter, const float* dash_array = nullptr, size_t dash_size = 0, float dash_offset = 0.0f); + + /// \~chinese + /// @brief 创建线条样式 + /// @tparam _DashSize 线条虚线数组大小 + /// @param cap 线条端点样式 + /// @param line_join 线条交点样式 + /// @param dash_array 线条虚线的长度与间隙数组 + /// @param dash_offset 线条虚线偏移量 + template + static StrokeStyle Create(CapStyle cap, LineJoinStyle line_join = LineJoinStyle::Miter, float(&dash_array)[_DashSize] = nullptr, float dash_offset = 0.0f) + { + return StrokeStyle::Create(cap, line_join, dash_array, _DashSize, dash_offset); + } + + private: + ComPtr GetStrokeStyle() const; + + void SetStrokeStyle(ComPtr style); + + private: + ComPtr style_; }; /** @} */ + + inline bool StrokeStyle::IsValid() const + { + return true; // Always valid + } + + inline ComPtr StrokeStyle::GetStrokeStyle() const + { + return style_; + } + + inline void StrokeStyle::SetStrokeStyle(ComPtr style) + { + style_ = style; + } + } diff --git a/src/kiwano/renderer/TextLayout.h b/src/kiwano/renderer/TextLayout.h index b637f4f0..a17ff2e2 100644 --- a/src/kiwano/renderer/TextLayout.h +++ b/src/kiwano/renderer/TextLayout.h @@ -135,7 +135,7 @@ namespace kiwano /// \~chinese /// @brief 设置文字描边线相交样式 - void SetOutlineStroke(StrokeStyle outline_stroke); + void SetOutlineStroke(const StrokeStyle& outline_stroke); /// \~chinese /// @brief 设置下划线 @@ -261,7 +261,7 @@ namespace kiwano style_.outline_width = outline_width; } - inline void TextLayout::SetOutlineStroke(StrokeStyle outline_stroke) + inline void TextLayout::SetOutlineStroke(const StrokeStyle& outline_stroke) { style_.outline_stroke = outline_stroke; } diff --git a/src/kiwano/renderer/TextStyle.hpp b/src/kiwano/renderer/TextStyle.hpp index bad2e187..2c589d8e 100644 --- a/src/kiwano/renderer/TextStyle.hpp +++ b/src/kiwano/renderer/TextStyle.hpp @@ -80,7 +80,7 @@ namespace kiwano BrushPtr fill_brush; ///< 填充画刷 BrushPtr outline_brush; ///< 描边画刷 float outline_width; ///< 描边线宽 - StrokeStyle outline_stroke; ///< 描边线相交样式 + StrokeStyle outline_stroke; ///< 描边线样式 public: /** @@ -116,7 +116,7 @@ namespace kiwano , wrap_width(0) , line_spacing(0) , outline_width(1.0f) - , outline_stroke(StrokeStyle::Round) + , outline_stroke() { }