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 #ifdef ENABLE_TEXT_ENHANCE
18 #include "include/core/HMSymbol.h"
19
PathOutlineDecompose(const SkPath & path,std::vector<SkPath> & paths)20 void HMSymbol::PathOutlineDecompose(const SkPath& path, std::vector<SkPath>& paths)
21 {
22 SkPath::RawIter iter = SkPath::RawIter(path);
23 SkPoint pts[4]; // the 4 is number of points
24 SkPath::Verb verb;
25 SkPath path_stemp;
26 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
27 switch (verb) {
28 case SkPath::kMove_Verb:
29 if (!path_stemp.isEmpty()) {
30 paths.push_back(path_stemp);
31 }
32 path_stemp.reset();
33 path_stemp.moveTo(pts[0]); // the 0 is first point
34 break;
35 case SkPath::kLine_Verb:
36 path_stemp.lineTo(pts[1]); // the 1 is second point
37 break;
38 case SkPath::kQuad_Verb:
39 path_stemp.quadTo(pts[1], pts[2]); // the 1 and 2 is second and third point
40 break;
41 case SkPath::kCubic_Verb:
42 path_stemp.cubicTo(pts[1], pts[2], pts[3]); // the 1, 2 and 3 if the second, third and fourth point
43 break;
44 case SkPath::kConic_Verb:
45 path_stemp.conicTo(pts[1], pts[2], iter.conicWeight()); // the 1 and 2 is second and third point
46 break;
47 case SkPath::kClose_Verb:
48 path_stemp.close();
49 break;
50 case SkPath::kDone_Verb:
51 if (!path_stemp.isEmpty()) {
52 paths.push_back(path_stemp);
53 }
54 path_stemp.reset();
55 SkUNREACHABLE;
56 default:
57 break;
58 }
59 }
60 if (!path_stemp.isEmpty()) {
61 paths.push_back(path_stemp);
62 }
63 }
64
MultilayerPath(const std::vector<std::vector<size_t>> & multMap,const std::vector<SkPath> & paths,std::vector<SkPath> & multPaths)65 void HMSymbol::MultilayerPath(const std::vector<std::vector<size_t>>& multMap,
66 const std::vector<SkPath>& paths, std::vector<SkPath>& multPaths)
67 {
68 if (multMap.empty()) {
69 SkPath path;
70 for (size_t i = 0; i < paths.size(); i++) {
71 path.addPath(paths[i]);
72 }
73 multPaths.push_back(path);
74 return;
75 }
76 for (size_t i = 0; i < multMap.size(); i++) {
77 SkPath path;
78 for (size_t j = 0; j < multMap[i].size(); j++) {
79 if (multMap[i][j] < paths.size()) {
80 path.addPath(paths[multMap[i][j]]);
81 }
82 }
83 multPaths.push_back(path);
84 }
85 }
86 #endif // ENABLE_TEXT_ENHANCE