1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef GRAPHIC_LITE_DEPICT_STROKE_H
17 #define GRAPHIC_LITE_DEPICT_STROKE_H
18 
19 #include "depict_adaptor_vertex_generate.h"
20 #include "gfx_utils/diagram/common/common_basics.h"
21 #include "gfx_utils/diagram/vertexgenerate/vertex_generate_stroke.h"
22 
23 namespace OHOS {
24 /**
25  * @template<class VertexSource,class Markers> struct DepictStroke
26  * @brief The structure is mainly a template structure for contour line transformation,
27  * including dotted line transformation
28  * @since 1.0
29  * @version 1.0
30  */
31 template <class VertexSource>
32 struct DepictStroke
33     : public DepictAdaptorVertexGenerate<VertexSource, VertexGenerateStroke> {
34     using BaseType = DepictAdaptorVertexGenerate<VertexSource, VertexGenerateStroke>;
35 
36     /**
37      * @brief DepictStroke Class constructor
38      * The construction parameter is the VertexSource property,
39      * which determines the processing of expanding or shrinking contour lines.
40      * @since 1.0
41      * @version 1.0
42      */
DepictStrokeDepictStroke43     DepictStroke(VertexSource& vs)
44         : DepictAdaptorVertexGenerate<VertexSource, VertexGenerateStroke>(vs)
45     {
46     }
47 #if defined(GRAPHIC_ENABLE_LINECAP_FLAG) && GRAPHIC_ENABLE_LINECAP_FLAG
48     /**
49      * ineCap Property sets the style of the line end cap.
50      * butt Default. Add a straight edge to each end of the line.
51      * round Add a circular cap to each end of the line.
52      * square Add a square cap to each end of the line.
53      * "round" And "square" make the line slightly longer
54      */
SetLineCapDepictStroke55     void SetLineCap(LineCap lineCap)
56     {
57         BaseType::GetGenerator().SetLineCap(lineCap);
58     }
59 
60     /**
61      * ineCap Property returns the style of the line end cap.
62      * butt Default. Add a straight edge to each end of the line.
63      * round Add a circular cap to each end of the line.
64      * square Add a square cap to each end of the line.
65      * "round" and "square" make the line slightly longer
66      */
GetLineCapDepictStroke67     LineCap GetLineCap() const
68     {
69         return BaseType::GetGenerator().GetLineCap();
70     }
71 #endif
72 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
73     /**
74      * lineJoin Property sets the type of corner created. When two lines meet,
75      * Mainly including bevel Create a bevel. round Create a fillet.
76      * miter Default. Create sharp corners.
77      */
SetLineJoinDepictStroke78     void SetLineJoin(LineJoin lineJoin)
79     {
80         BaseType::GetGenerator().SetLineJoin(lineJoin);
81     }
82 
83     /**
84      * lineJoin Property returns the type of corner created. When two lines meet,
85      * Mainly including bevel Create a bevel. round Create a fillet.
86      * miter Default. Create sharp corners.
87      */
GetLineJoinDepictStroke88     LineJoin GetLineJoin() const
89     {
90         return BaseType::GetGenerator().GetLineJoin();
91     }
92 
93     /**
94      * miterLimit Property to set the maximum miter length.
95      * Miter length refers to the distance between the inner and outer corners at the intersection of two lines
96      * Miterlimit is valid only when the linejoin attribute is "miter".
97      * To avoid the miter length being too long, we can use the miterlimit attribute.
98      */
SetMiterLimitDepictStroke99     void SetMiterLimit(float miterLimit)
100     {
101         BaseType::GetGenerator().SetMiterLimit(miterLimit);
102     }
103     /**
104      * miterLimit Property returns the maximum miter length.
105      * Miter length refers to the distance between the inner and outer corners at the intersection of two lines
106      * Miterlimit is valid only when the linejoin attribute is "miter".
107      * The smaller the angle of the corner, the greater the miter length.
108      * To avoid the miter length being too long, we can use the miterlimit attribute.
109      */
GetMiterLimitDepictStroke110     float GetMiterLimit() const
111     {
112         return BaseType::GetGenerator().GetMiterLimit();
113     }
114 #endif
115 
116     /** Contour line mainly sets the lineweight of geometric lines */
SetWidthDepictStroke117     void SetWidth(float width)
118     {
119         BaseType::GetGenerator().SetWidth(width);
120     }
121 
122     /**
123      * @brief Finally determine the accuracy of the estimation.
124      * In practical application, we need to convert the world coordinates of points to screen coordinates,
125      * so there will always be a certain scaling factor.
126      * Curves are usually processed in the world coordinate system and converted to pixel values when estimating.
127      * It usually looks like this: m_curved.approximation_scale(transform_.scale());
128      * Here, transform_is a matrix of affine mapping,
129      * which contains all transformations,
130      * including viewpoint and scaling.
131      * @since 1.0
132      * @version 1.0
133      */
ApproximationScaleDepictStroke134     void ApproximationScale(float aScale)
135     {
136         BaseType::GetGenerator().ApproximationScale(aScale);
137     }
138     // Contour lines mainly return the lineweight of geometric lines
GetWidthDepictStroke139     float GetWidth() const
140     {
141         return BaseType::GetGenerator().GetWidth();
142     }
143 
144     /**
145      * @brief Returns the precision of the final decision estimate
146      * In practical application, we need to convert the world coordinates of points to screen coordinates,
147      * so there will always be a certain scaling factor.
148      * Curves are usually processed in the world coordinate system and converted to pixel values when estimating.
149      * It usually looks like this: m_curved.approximation_scale(transform_.scale());
150      * Here, transform_is a matrix of affine mapping,
151      * which contains all transformations,
152      * including viewpoint and scaling.
153      * @since 1.0
154      * @version 1.0
155      */
GetApproximationScaleDepictStroke156     float GetApproximationScale() const
157     {
158         return BaseType::GetGenerator().GetApproximationScale();
159     }
160 
SetStrokeShortenDepictStroke161     void SetStrokeShorten(float strokeShorten)
162     {
163         BaseType::GetGenerator().SetStrokeShorten(strokeShorten);
164     }
GetStrokeShortenDepictStroke165     float GetStrokeShorten() const
166     {
167         return BaseType::GetGenerator().GetStrokeShorten();
168     }
169 };
170 } // namespace OHOS
171 #endif
172