• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
17  * @file depict_curve.cpp
18  *
19  * @brief Defines Building curve transformation pipes
20  * The curve drawing is usually approximated by a series of short line segments,
21  * which is the only efficient method to draw the curve
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 #include "gfx_utils/diagram/depiction/depict_curve.h"
27 
28 namespace OHOS {
29 /**
30  * Reset the status attribute of a path segment
31  * @path_id is a path ID, calculated from 0
32  * @since 1.0
33  * @version 1.0
34  */
Rewind(uint32_t pathId)35 void DepictCurve::Rewind(uint32_t pathId)
36 {
37     source_->Rewind(pathId);
38     lastX_ = 0.0f;
39     lastY_ = 0.0f;
40     quadraticBezier_.Reset();
41     cubicBezier_.Reset();
42 }
43 
44 /**
45  * According to PATH_CMD command returns the vertex coordinates generated in each stage
46  * @since 1.0
47  * @version 1.0
48  */
GenerateVertex(float * x,float * y)49 uint32_t DepictCurve::GenerateVertex(float* x, float* y)
50 {
51     if (!IsStop(quadraticBezier_.GenerateVertex(x, y))) {
52         lastX_ = *x;
53         lastY_ = *y;
54         return PATH_CMD_LINE_TO;
55     }
56 
57     if (!IsStop(cubicBezier_.GenerateVertex(x, y))) {
58         lastX_ = *x;
59         lastY_ = *y;
60         return PATH_CMD_LINE_TO;
61     }
62 
63     float control2X = 0;
64     float control2Y = 0;
65     float endX = 0;
66     float endY = 0;
67 
68     uint32_t cmd = source_->GenerateVertex(x, y);
69     switch (cmd) {
70         case PATH_CMD_CURVE3:
71             source_->GenerateVertex(&endX, &endY);
72 
73             quadraticBezier_.Init(lastX_, lastY_, *x, *y, endX, endY);
74 
75             quadraticBezier_.GenerateVertex(x, y); // First call returns path_cmd_move_to
76             quadraticBezier_.GenerateVertex(x, y); // This is the first vertex of the curve
77             cmd = PATH_CMD_LINE_TO;
78             break;
79 
80         case PATH_CMD_CURVE4:
81             source_->GenerateVertex(&control2X, &control2Y);
82             source_->GenerateVertex(&endX, &endY);
83 
84             cubicBezier_.Init(lastX_, lastY_, *x, *y, control2X, control2Y, endX, endY);
85 
86             cubicBezier_.GenerateVertex(x, y); // First call returns path_cmd_move_to
87             cubicBezier_.GenerateVertex(x, y); // This is the first vertex of the curve
88             cmd = PATH_CMD_LINE_TO;
89             break;
90     }
91     lastX_ = *x;
92     lastY_ = *y;
93     return cmd;
94 }
95 } // namespace OHOS
96