1
2 /*
3 * Copyright (c) 2023 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "include/core/HMSymbol.h"
18
PathOutlineDecompose(const SkPath & path,std::vector<SkPath> & paths)19 void HMSymbol::PathOutlineDecompose(const SkPath& path, std::vector<SkPath>& paths)
20 {
21 SkPath::RawIter iter = SkPath::RawIter(path);
22 SkPoint pts[4]; // the 4 is number of points
23 SkPath::Verb verb;
24 SkPath path_stemp;
25 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
26 switch (verb) {
27 case SkPath::kMove_Verb:
28 if (!path_stemp.isEmpty()) {
29 paths.push_back(path_stemp);
30 }
31 path_stemp.reset();
32 path_stemp.moveTo(pts[0]); // the 0 is first point
33 break;
34 case SkPath::kLine_Verb:
35 path_stemp.lineTo(pts[1]); // the 1 is second point
36 break;
37 case SkPath::kQuad_Verb:
38 path_stemp.quadTo(pts[1], pts[2]); // the 1 and 2 is second and third point
39 break;
40 case SkPath::kCubic_Verb:
41 path_stemp.cubicTo(pts[1], pts[2], pts[3]); // the 1, 2 and 3 if the second, third and fourth point
42 break;
43 case SkPath::kConic_Verb:
44 path_stemp.conicTo(pts[1], pts[2], iter.conicWeight()); // the 1 and 2 is second and third point
45 break;
46 case SkPath::kClose_Verb:
47 path_stemp.close();
48 break;
49 case SkPath::kDone_Verb:
50 if (!path_stemp.isEmpty()) {
51 paths.push_back(path_stemp);
52 }
53 path_stemp.reset();
54 SkUNREACHABLE;
55 default:
56 break;
57 }
58 }
59 if (!path_stemp.isEmpty()) {
60 paths.push_back(path_stemp);
61 }
62 }
63
MultilayerPath(const std::vector<std::vector<size_t>> & multMap,const std::vector<SkPath> & paths,std::vector<SkPath> & multPaths)64 void HMSymbol::MultilayerPath(const std::vector<std::vector<size_t>>& multMap,
65 const std::vector<SkPath>& paths, std::vector<SkPath>& multPaths)
66 {
67 if (multMap.empty()) {
68 SkPath path;
69 for (size_t i = 0; i < paths.size(); i++) {
70 path.addPath(paths[i]);
71 }
72 multPaths.push_back(path);
73 return;
74 }
75 for (size_t i = 0; i < multMap.size(); i++) {
76 SkPath path;
77 for (size_t j = 0; j < multMap[i].size(); j++) {
78 if (multMap[i][j] < paths.size()) {
79 path.addPath(paths[multMap[i][j]]);
80 }
81 }
82 multPaths.push_back(path);
83 }
84 }