2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _TVG_SW_SHAPE_H_
18 #define _TVG_SW_SHAPE_H_
20 #include "tvgSwCommon.h"
22 static void growOutlineContour(SwShape *sdata, size_t n)
24 sdata->outline.cntrsCnt = n;
27 free(sdata->outline.cntrs);
28 sdata->outline.cntrs = nullptr;
31 sdata->outline.cntrs = static_cast<short *>(realloc(sdata->outline.cntrs, n * sizeof(short)));
32 assert(sdata->outline.cntrs);
36 static void growOutlinePoint(SwShape *sdata, size_t n)
38 sdata->outline.ptsCnt = n;
41 free(sdata->outline.pts);
42 sdata->outline.pts = nullptr;
43 free(sdata->outline.tags);
44 sdata->outline.tags = nullptr;
48 sdata->outline.pts = static_cast<SwVector *>(realloc(sdata->outline.pts, n * sizeof(SwVector)));
49 assert(sdata->outline.pts);
50 sdata->outline.tags = static_cast<char*>(realloc(sdata->outline.tags, n * sizeof(char)));
51 assert(sdata->outline.tags);
55 static void outlineEnd(SwShape* sdata)
61 static void outlineMoveTo(SwShape* sdata, const Point* pt)
68 static void outlineLineTo(SwShape* sdata, const Point* pt)
74 static void outlineCubicTo(SwShape* sdata, const Point* ctrl1, const Point* ctrl2, const Point* pt)
80 static void outlineClose(SwShape* sdata)
86 bool shapeGenOutline(ShapeNode *shape, SwShape* sdata)
90 const PathCommand* cmds = nullptr;
91 auto cmdCnt = shape->pathCommands(&cmds);
93 const Point* pts = nullptr;
94 shape->pathCoords(&pts);
97 auto outlinePtsCnt = 0;
98 auto outlineCntrsCnt = 0;
100 for (auto i = 0; i < cmdCnt; ++i) {
102 case PathCommand::Close: {
106 case PathCommand::MoveTo: {
111 case PathCommand::LineTo: {
115 case PathCommand::CubicTo: {
122 ++outlinePtsCnt; //for close
124 growOutlinePoint(sdata, outlinePtsCnt);
125 growOutlineContour(sdata, outlineCntrsCnt);
128 while (cmdCnt-- > 0) {
130 case PathCommand::Close: {
134 case PathCommand::MoveTo: {
135 outlineMoveTo(sdata, pts);
139 case PathCommand::LineTo: {
140 outlineLineTo(sdata, pts);
144 case PathCommand::CubicTo: {
145 outlineCubicTo(sdata, pts, pts + 1, pts + 2);
159 #endif /* _TVG_SW_SHAPE_H_ */