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_LTE_VERTEX_GENERATE_STROKE_H
17 #define GRAPHIC_LTE_VERTEX_GENERATE_STROKE_H
18 
19 #include "gfx_utils/diagram/vertexprimitive/geometry_math_stroke.h"
20 namespace OHOS {
21 class VertexGenerateStroke {
22     enum Status {
23         /** init state */
24         INITIAL,
25         /** ready state */
26         READY,
27         /** linecap start draw state */
28         LINECAP_START,
29         /** linecap end draw state */
30         LINECAP_END,
31         /** linejoin start draw state */
32         LINEJOIN_START,
33         /** close first curve state */
34         CLOSE_FIRST,
35         /** linejoin end draw state */
36         LINEJOIN_END,
37         /** closing end state */
38         OUT_VERTICES,
39         /** Clockwise needle end polygon */
40         CLOCKWISE_ENDPOLY,
41         /** Clockwise needle end polygon */
42         ANTI_CLOCKWISE_ENDPOLY,
43         /** end drawing state */
44         STOP
45     };
46 
47 public:
48     VertexGenerateStroke();
49 
50 #if defined(GRAPHIC_ENABLE_LINECAP_FLAG) && GRAPHIC_ENABLE_LINECAP_FLAG
SetLineCap(LineCap lc)51     void SetLineCap(LineCap lc)
52     {
53         stroker_.SetLineCap(lc);
54     }
GetLineCap()55     LineCap GetLineCap() const
56     {
57         return stroker_.GetLineCap();
58     }
59 #endif
60 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
SetLineJoin(LineJoin lj)61     void SetLineJoin(LineJoin lj)
62     {
63         stroker_.SetLineJoin(lj);
64     }
65 
SetMiterLimit(float ml)66     void SetMiterLimit(float ml)
67     {
68         stroker_.SetMiterLimit(ml);
69     }
GetLineJoin()70     LineJoin GetLineJoin() const
71     {
72         return stroker_.GetLineJoin();
73     }
GetMiterLimit()74     float GetMiterLimit() const
75     {
76         return stroker_.GetMiterLimit();
77     }
78 #endif
SetWidth(float width)79     void SetWidth(float width)
80     {
81         stroker_.SetWidth(width);
82     }
83 
SetApproximationScale(float approximationScale)84     void SetApproximationScale(float approximationScale)
85     {
86         stroker_.SetApproximationScale(approximationScale);
87     }
88 
GetWidth()89     float GetWidth() const
90     {
91         return stroker_.GetWidth();
92     }
93 
GetApproximationScale()94     float GetApproximationScale() const
95     {
96         return stroker_.GetApproximationScale();
97     }
98 
SetStrokeShorten(float strokeShorten)99     void SetStrokeShorten(float strokeShorten)
100     {
101         strokeShorten_ = strokeShorten;
102     }
103 
GetStrokeShorten()104     float GetStrokeShorten() const
105     {
106         return strokeShorten_;
107     }
108 
109     void RemoveAll();
110 
111     void AddVertex(float x, float y, uint32_t cmd);
112 
113     void Rewind(uint32_t pathId);
114     uint32_t GenerateVertex(float* x, float* y);
GetGenerateFlags()115     VertexGenerateFlags GetGenerateFlags()
116     {
117         return GENERATE_STROKE;
118     }
119 private:
120     VertexGenerateStroke(const VertexGenerateStroke&);
121     const VertexGenerateStroke& operator=(const VertexGenerateStroke&);
122     GeometryMathStroke stroker_;
123     GeometryVertexSequence srcVertices_;
124     Graphic::Vector<PointF> outVertices_;
125     float strokeShorten_;
126     uint32_t closed_;
127     Status status_;
128     Status prevStatus_;
129     uint32_t srcVertex_;
130     uint32_t outVertex_;
131 
132     void VertexReady(const uint32_t& verticesNum, uint32_t& cmd);
133     void VertexLineCapStart();
134     void VertexLineCapEnd(const uint32_t& verticesNum);
135     void VertexLineJoinStart();
136     void VertexLineJoinEnd();
137     void VertexCloseFirst(uint32_t& cmd);
138     bool IsVertexOutVertices(float* x, float* y);
139 };
140 } // namespace OHOS
141 
142 #endif
143