@react-native-ohos/react-native-clippathview 1.1.9-rc.1 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{harmony/clipPath/README.OpenSource → README.OpenSource} +2 -2
- package/README.md +15 -15
- package/harmony/clipPath/index.ets +2 -0
- package/harmony/clipPath/oh-package.json5 +1 -1
- package/harmony/clipPath/src/main/cpp/ClipPathProps.h +120 -63
- package/harmony/clipPath/src/main/cpp/ClipPathViewComponentInstance.cpp +43 -37
- package/harmony/clipPath/src/main/cpp/ClipPathViewComponentInstance.h +6 -1
- package/harmony/clipPath/src/main/cpp/ClipPathViewNoneComponentInstance.cpp +43 -36
- package/harmony/clipPath/src/main/cpp/ClipPathViewNoneNode.cpp +166 -90
- package/harmony/clipPath/src/main/cpp/ClipPathViewNoneNode.h +100 -84
- package/harmony/clipPath/src/main/cpp/RNCClipPathTurboModule.cpp +2 -2
- package/harmony/clipPath/src/main/cpp/RNCClipPathTurboModule.h +10 -7
- package/harmony/clipPath/src/main/cpp/SVGPathParser.cpp +261 -222
- package/harmony/clipPath/src/main/cpp/SVGPathParser.h +4 -4
- package/harmony/clipPath/src/main/cpp/SVGViewBox.cpp +9 -9
- package/harmony/clipPath/src/main/cpp/ShadowNodes.cpp +4 -2
- package/harmony/clipPath/src/main/cpp/pen_style_node.h +20 -4
- package/harmony/clipPath/src/main/ets/{ClipPathPackage.ts → ClipPathPackage.ets} +2 -1
- package/harmony/clipPath.har +0 -0
- package/package.json +10 -8
- package/harmony/clipPath/BuildProfile.ets +0 -6
- package/harmony/clipPath/OAT.xml +0 -39
- package/react-native-clippath.podspec +0 -30
- /package/harmony/clipPath/{ts.ts → ts.ets} +0 -0
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
*/
|
|
4
15
|
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
|
|
5
16
|
// please include "napi/native_api.h".
|
|
6
17
|
|
|
@@ -22,45 +33,51 @@
|
|
|
22
33
|
|
|
23
34
|
namespace rnoh {
|
|
24
35
|
ClipPathViewNoneNode::ClipPathViewNoneNode()
|
|
25
|
-
: ArkUINode(NativeNodeApi::getInstance()->createNode(ArkUI_NodeType::ARKUI_NODE_CUSTOM))
|
|
36
|
+
: ArkUINode(NativeNodeApi::getInstance()->createNode(ArkUI_NodeType::ARKUI_NODE_CUSTOM))
|
|
37
|
+
{
|
|
26
38
|
canvasCallback_ = new CanvasCallback();
|
|
27
39
|
canvasCallback_->callback = [this](ArkUI_NodeCustomEvent *event) {
|
|
28
40
|
auto type = OH_ArkUI_NodeCustomEvent_GetEventType(event);
|
|
29
41
|
switch (type) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
case ARKUI_NODE_CUSTOM_EVENT_ON_FOREGROUND_DRAW:
|
|
43
|
+
OnDraw(event);
|
|
44
|
+
break;
|
|
45
|
+
case ARKUI_NODE_CUSTOM_EVENT_ON_MEASURE: {
|
|
46
|
+
int32_t width = getSavedWidth();
|
|
47
|
+
int32_t height = getSavedHeight();
|
|
48
|
+
maybeThrow(NativeNodeApi::getInstance()->setMeasuredSize(m_nodeHandle, width, height));
|
|
49
|
+
setRectF(mBounds, 0, 0, width, height);
|
|
50
|
+
} break;
|
|
51
|
+
default:
|
|
52
|
+
break;
|
|
41
53
|
}
|
|
42
54
|
};
|
|
43
55
|
eventReceiver = [](ArkUI_NodeCustomEvent *event) {
|
|
44
56
|
int32_t targetId = OH_ArkUI_NodeCustomEvent_GetEventTargetId(event);
|
|
45
|
-
|
|
57
|
+
int count10001 = 10001;
|
|
58
|
+
int count10002 = 10002;
|
|
59
|
+
if (targetId == count10001 || targetId == count10002) {
|
|
46
60
|
auto *userData = reinterpret_cast<CanvasCallback *>(OH_ArkUI_NodeCustomEvent_GetUserData(event));
|
|
47
61
|
if (userData != nullptr && userData->callback != nullptr) {
|
|
48
62
|
userData->callback(event);
|
|
49
63
|
}
|
|
50
64
|
}
|
|
51
65
|
};
|
|
66
|
+
int count101 = 10001;
|
|
67
|
+
int count102 = 10002;
|
|
52
68
|
maybeThrow(NativeNodeApi::getInstance()->addNodeCustomEventReceiver(m_nodeHandle, eventReceiver));
|
|
53
|
-
maybeThrow(NativeNodeApi::getInstance()->registerNodeCustomEvent(
|
|
54
|
-
|
|
69
|
+
maybeThrow(NativeNodeApi::getInstance()->registerNodeCustomEvent(m_nodeHandle,
|
|
70
|
+
ARKUI_NODE_CUSTOM_EVENT_ON_FOREGROUND_DRAW, count101, canvasCallback_));
|
|
55
71
|
maybeThrow(NativeNodeApi::getInstance()->registerNodeCustomEvent(m_nodeHandle, ARKUI_NODE_CUSTOM_EVENT_ON_MEASURE,
|
|
56
|
-
|
|
72
|
+
count102, canvasCallback_));
|
|
57
73
|
OH_Drawing_PenIsAntiAlias(mPaint);
|
|
58
74
|
OH_Drawing_PenIsAntiAlias(mPaintStroke);
|
|
59
75
|
OH_Drawing_PenSetColor(mPaint, 0xffffffff);
|
|
60
76
|
OH_Drawing_PenSetColor(mPaintStroke, 0xffffffff);
|
|
61
77
|
}
|
|
62
78
|
|
|
63
|
-
ClipPathViewNoneNode::~ClipPathViewNoneNode()
|
|
79
|
+
ClipPathViewNoneNode::~ClipPathViewNoneNode()
|
|
80
|
+
{
|
|
64
81
|
NativeNodeApi::getInstance()->removeNodeCustomEventReceiver(m_nodeHandle, eventReceiver);
|
|
65
82
|
NativeNodeApi::getInstance()->unregisterNodeCustomEvent(m_nodeHandle, ARKUI_NODE_CUSTOM_EVENT_ON_FOREGROUND_DRAW);
|
|
66
83
|
NativeNodeApi::getInstance()->unregisterNodeCustomEvent(m_nodeHandle, ARKUI_NODE_CUSTOM_EVENT_ON_MEASURE);
|
|
@@ -77,35 +94,38 @@ ClipPathViewNoneNode::~ClipPathViewNoneNode() {
|
|
|
77
94
|
delete mProps;
|
|
78
95
|
canvasCallback_ = nullptr;
|
|
79
96
|
mProps = nullptr;
|
|
80
|
-
canvas =nullptr;
|
|
97
|
+
canvas = nullptr;
|
|
81
98
|
}
|
|
82
99
|
|
|
83
|
-
void ClipPathViewNoneNode::
|
|
100
|
+
void ClipPathViewNoneNode::InsertChild(ArkUINode &child, std::size_t index)
|
|
101
|
+
{
|
|
84
102
|
maybeThrow(NativeNodeApi::getInstance()->insertChildAt(m_nodeHandle, child.getArkUINodeHandle(), index));
|
|
85
103
|
}
|
|
86
104
|
|
|
87
|
-
void ClipPathViewNoneNode::
|
|
105
|
+
void ClipPathViewNoneNode::RemoveChild(ArkUINode &child)
|
|
106
|
+
{
|
|
88
107
|
maybeThrow(NativeNodeApi::getInstance()->removeChild(m_nodeHandle, child.getArkUINodeHandle()));
|
|
89
108
|
}
|
|
90
109
|
|
|
91
|
-
void ClipPathViewNoneNode::setPanStyleMode(OH_Drawing_Canvas *canvas, int type)
|
|
92
|
-
|
|
110
|
+
void ClipPathViewNoneNode::setPanStyleMode(OH_Drawing_Canvas *canvas, int type)
|
|
111
|
+
{
|
|
93
112
|
auto cBrush = OH_Drawing_BrushCreate();
|
|
94
113
|
switch (type) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
114
|
+
case CLIP_PEN_STYLE_FILL:
|
|
115
|
+
OH_Drawing_BrushSetColor(cBrush, OH_Drawing_ColorSetArgb(0xff, 0xff, 0xff, 0xff));
|
|
116
|
+
break;
|
|
117
|
+
case CLIP_PEN_STYLE_STROKE:
|
|
118
|
+
OH_Drawing_BrushSetColor(cBrush, OH_Drawing_ColorSetArgb(0x00, 0x00, 0x00, 0x00));
|
|
119
|
+
break;
|
|
120
|
+
default:
|
|
121
|
+
break;
|
|
103
122
|
}
|
|
104
123
|
OH_Drawing_CanvasAttachBrush(canvas, cBrush);
|
|
105
124
|
OH_Drawing_BrushDestroy(cBrush);
|
|
106
125
|
}
|
|
107
126
|
|
|
108
|
-
void ClipPathViewNoneNode::OnDraw(ArkUI_NodeCustomEvent *event)
|
|
127
|
+
void ClipPathViewNoneNode::OnDraw(ArkUI_NodeCustomEvent *event)
|
|
128
|
+
{
|
|
109
129
|
auto *drawContext = OH_ArkUI_NodeCustomEvent_GetDrawContextInDraw(event);
|
|
110
130
|
canvas = reinterpret_cast<OH_Drawing_Canvas *>(OH_ArkUI_DrawContext_GetCanvas(drawContext));
|
|
111
131
|
auto width_ = OH_Drawing_CanvasGetWidth(canvas);
|
|
@@ -127,7 +147,8 @@ void ClipPathViewNoneNode::OnDraw(ArkUI_NodeCustomEvent *event) {
|
|
|
127
147
|
OH_Drawing_BrushDestroy(cBrush_);
|
|
128
148
|
}
|
|
129
149
|
|
|
130
|
-
void ClipPathViewNoneNode::drawPath(OH_Drawing_Canvas *canvas)
|
|
150
|
+
void ClipPathViewNoneNode::drawPath(OH_Drawing_Canvas *canvas)
|
|
151
|
+
{
|
|
131
152
|
setupPath(canvas);
|
|
132
153
|
viewBoxTransform();
|
|
133
154
|
setPaintStrokeProps();
|
|
@@ -151,7 +172,8 @@ void ClipPathViewNoneNode::drawPath(OH_Drawing_Canvas *canvas) {
|
|
|
151
172
|
OH_Drawing_CanvasRestore(canvas);
|
|
152
173
|
}
|
|
153
174
|
|
|
154
|
-
void ClipPathViewNoneNode::setupPath(OH_Drawing_Canvas *canvas)
|
|
175
|
+
void ClipPathViewNoneNode::setupPath(OH_Drawing_Canvas *canvas)
|
|
176
|
+
{
|
|
155
177
|
if (!canvas || mD.empty()) {
|
|
156
178
|
return;
|
|
157
179
|
}
|
|
@@ -161,155 +183,209 @@ void ClipPathViewNoneNode::setupPath(OH_Drawing_Canvas *canvas) {
|
|
|
161
183
|
SVGPathParser::mScale = ModUtil::getDensity();
|
|
162
184
|
mPath = SVGPathParser::parse(mD);
|
|
163
185
|
}
|
|
164
|
-
void ClipPathViewNoneNode::
|
|
186
|
+
void ClipPathViewNoneNode::SetD(const std::string d)
|
|
187
|
+
{
|
|
165
188
|
mD = d;
|
|
166
189
|
markDirty();
|
|
167
190
|
}
|
|
168
|
-
void ClipPathViewNoneNode::
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
void ClipPathViewNoneNode::
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
void ClipPathViewNoneNode::
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
191
|
+
void ClipPathViewNoneNode::SetStrokeWidth(float const width)
|
|
192
|
+
{
|
|
193
|
+
mProps->mStrokeWidth = width;
|
|
194
|
+
}
|
|
195
|
+
void ClipPathViewNoneNode::SetStrokeCap(std::string const cap)
|
|
196
|
+
{
|
|
197
|
+
mProps->mStrokeCap = cap;
|
|
198
|
+
}
|
|
199
|
+
void ClipPathViewNoneNode::SetStrokeJoin(std::string const join)
|
|
200
|
+
{
|
|
201
|
+
mProps->mStrokeJoin = join;
|
|
202
|
+
}
|
|
203
|
+
void ClipPathViewNoneNode::SetStrokeMiter(float const miter)
|
|
204
|
+
{
|
|
205
|
+
mProps->mStrokeMiter = miter;
|
|
206
|
+
}
|
|
207
|
+
void ClipPathViewNoneNode::SetStrokeStart(float const start)
|
|
208
|
+
{
|
|
209
|
+
mProps->mStrokeStart = start;
|
|
210
|
+
}
|
|
211
|
+
void ClipPathViewNoneNode::SetStrokeEnd(float const end)
|
|
212
|
+
{
|
|
213
|
+
mProps->mStrokeEnd = end;
|
|
214
|
+
}
|
|
215
|
+
float ClipPathViewNoneNode::toDip(float value)
|
|
216
|
+
{
|
|
217
|
+
return value * ModUtil::getDensity();
|
|
218
|
+
}
|
|
219
|
+
void ClipPathViewNoneNode::SetFillRule(std::string v)
|
|
220
|
+
{
|
|
221
|
+
mProps->mFillRule = v.empty() ? "none" : v;
|
|
222
|
+
}
|
|
223
|
+
void ClipPathViewNoneNode::SetAlign(std::string v)
|
|
224
|
+
{
|
|
225
|
+
mAlign = v.empty() ? "xMidYMid" : v;
|
|
226
|
+
}
|
|
227
|
+
void ClipPathViewNoneNode::SetAspect(std::string v)
|
|
228
|
+
{
|
|
229
|
+
mAspect = v.empty() ?
|
|
230
|
+
SVGViewBox::MOS_MEET :
|
|
231
|
+
(v.compare("slice") == 0 ? SVGViewBox::MOS_SLICE :
|
|
232
|
+
(v.compare("none") == 0 ? SVGViewBox::MOS_NONE : SVGViewBox::MOS_MEET));
|
|
233
|
+
}
|
|
234
|
+
void ClipPathViewNoneNode::setRect(OH_Drawing_Rect *target, OH_Drawing_Rect *src)
|
|
235
|
+
{
|
|
184
236
|
OH_Drawing_RectSetLeft(target, OH_Drawing_RectGetLeft(src));
|
|
185
237
|
OH_Drawing_RectSetTop(target, OH_Drawing_RectGetTop(src));
|
|
186
238
|
OH_Drawing_RectSetRight(target, OH_Drawing_RectGetRight(src));
|
|
187
239
|
OH_Drawing_RectSetBottom(target, OH_Drawing_RectGetBottom(src));
|
|
188
240
|
}
|
|
189
241
|
|
|
190
|
-
void ClipPathViewNoneNode::setRectF(OH_Drawing_Rect *target, float left, float top, float right, float bottom)
|
|
242
|
+
void ClipPathViewNoneNode::setRectF(OH_Drawing_Rect *target, float left, float top, float right, float bottom)
|
|
243
|
+
{
|
|
191
244
|
setRect(target, OH_Drawing_RectCreate(left, top, right, bottom));
|
|
192
245
|
}
|
|
193
246
|
|
|
194
|
-
void ClipPathViewNoneNode::
|
|
247
|
+
void ClipPathViewNoneNode::SetTranslateZ(float z)
|
|
248
|
+
{
|
|
195
249
|
ArkUI_NumberValue translateValue[] = {{.f32 = z}};
|
|
196
|
-
ArkUI_AttributeItem translateItem = {translateValue, sizeof(translateValue) / sizeof(ArkUI_NumberValue)};
|
|
250
|
+
ArkUI_AttributeItem translateItem = { translateValue, sizeof(translateValue) / sizeof(ArkUI_NumberValue) };
|
|
197
251
|
uint32_t code = NativeNodeApi::getInstance()->setAttribute(m_nodeHandle, NODE_Z_INDEX, &translateItem);
|
|
198
252
|
}
|
|
199
|
-
void ClipPathViewNoneNode::
|
|
253
|
+
void ClipPathViewNoneNode::SetTransX(float v)
|
|
254
|
+
{
|
|
200
255
|
if (mTranslationX != v) {
|
|
201
256
|
mTranslationX = v;
|
|
202
257
|
}
|
|
203
258
|
}
|
|
204
|
-
void ClipPathViewNoneNode::
|
|
259
|
+
void ClipPathViewNoneNode::SetTransY(float v)
|
|
260
|
+
{
|
|
205
261
|
if (mTranslationY != v) {
|
|
206
262
|
mTranslationY = v;
|
|
207
263
|
}
|
|
208
264
|
}
|
|
209
|
-
void ClipPathViewNoneNode::
|
|
265
|
+
void ClipPathViewNoneNode::SetTransPercentageValue(bool v)
|
|
266
|
+
{
|
|
210
267
|
if (mTranslationIsPercent != v) {
|
|
211
268
|
mTranslationIsPercent = v;
|
|
212
269
|
}
|
|
213
270
|
}
|
|
214
271
|
|
|
215
|
-
void ClipPathViewNoneNode::
|
|
272
|
+
void ClipPathViewNoneNode::SetRot(float v)
|
|
273
|
+
{
|
|
216
274
|
if (mRotation != v) {
|
|
217
275
|
mRotation = v;
|
|
218
276
|
}
|
|
219
277
|
}
|
|
220
|
-
void ClipPathViewNoneNode::
|
|
278
|
+
void ClipPathViewNoneNode::SetRotO(float v)
|
|
279
|
+
{
|
|
221
280
|
if (mRotationOx != v || mRotationOy != v) {
|
|
222
281
|
mRotationOx = v;
|
|
223
282
|
mRotationOy = v;
|
|
224
283
|
}
|
|
225
284
|
}
|
|
226
|
-
void ClipPathViewNoneNode::
|
|
285
|
+
void ClipPathViewNoneNode::SetRotOx(float v)
|
|
286
|
+
{
|
|
227
287
|
if (mRotationOx != v) {
|
|
228
288
|
mRotationOx = v;
|
|
229
289
|
}
|
|
230
290
|
}
|
|
231
|
-
void ClipPathViewNoneNode::
|
|
291
|
+
void ClipPathViewNoneNode::SetRotOy(float v)
|
|
292
|
+
{
|
|
232
293
|
if (mRotationOy != v) {
|
|
233
294
|
mRotationOy = v;
|
|
234
295
|
}
|
|
235
296
|
}
|
|
236
|
-
void ClipPathViewNoneNode::
|
|
297
|
+
void ClipPathViewNoneNode::SetRotPercentageValue(bool v)
|
|
298
|
+
{
|
|
237
299
|
if (mRotationIsPercent != v) {
|
|
238
300
|
mRotationIsPercent = v;
|
|
239
301
|
}
|
|
240
302
|
}
|
|
241
|
-
void ClipPathViewNoneNode::
|
|
303
|
+
void ClipPathViewNoneNode::SetSc(float v)
|
|
304
|
+
{
|
|
242
305
|
if (mScaleX != v || mScaleY != v) {
|
|
243
306
|
mScaleX = v;
|
|
244
307
|
mScaleY = v;
|
|
245
308
|
}
|
|
246
309
|
}
|
|
247
|
-
void ClipPathViewNoneNode::
|
|
310
|
+
void ClipPathViewNoneNode::SetScX(float v)
|
|
311
|
+
{
|
|
248
312
|
if (mScaleX != v) {
|
|
249
313
|
mScaleX = v;
|
|
250
314
|
}
|
|
251
315
|
}
|
|
252
316
|
|
|
253
|
-
void ClipPathViewNoneNode::
|
|
317
|
+
void ClipPathViewNoneNode::SetScY(float v)
|
|
318
|
+
{
|
|
254
319
|
if (mScaleY != v) {
|
|
255
320
|
mScaleY = v;
|
|
256
321
|
}
|
|
257
322
|
}
|
|
258
323
|
|
|
259
|
-
void ClipPathViewNoneNode::
|
|
324
|
+
void ClipPathViewNoneNode::SetScO(float v)
|
|
325
|
+
{
|
|
260
326
|
if (mScaleOriginX != v || mScaleOriginY != v) {
|
|
261
327
|
mScaleOriginX = v;
|
|
262
328
|
mScaleOriginY = v;
|
|
263
329
|
}
|
|
264
330
|
}
|
|
265
|
-
void ClipPathViewNoneNode::
|
|
331
|
+
void ClipPathViewNoneNode::SetScOx(float v)
|
|
332
|
+
{
|
|
266
333
|
if (mScaleOriginX != v) {
|
|
267
334
|
mScaleOriginX = v;
|
|
268
335
|
}
|
|
269
336
|
}
|
|
270
|
-
void ClipPathViewNoneNode::
|
|
337
|
+
void ClipPathViewNoneNode::SetScOy(float v)
|
|
338
|
+
{
|
|
271
339
|
if (mScaleOriginY != v) {
|
|
272
340
|
mScaleOriginY = v;
|
|
273
341
|
}
|
|
274
342
|
}
|
|
275
|
-
void ClipPathViewNoneNode::
|
|
343
|
+
void ClipPathViewNoneNode::SetScPercentageValue(bool v)
|
|
344
|
+
{
|
|
276
345
|
if (mScaleIsPercent != v) {
|
|
277
346
|
mScaleIsPercent = v;
|
|
278
347
|
}
|
|
279
348
|
}
|
|
280
349
|
|
|
281
|
-
void ClipPathViewNoneNode::
|
|
350
|
+
void ClipPathViewNoneNode::SetViewBox(std::vector<float> viewBox)
|
|
351
|
+
{
|
|
282
352
|
if (viewBox.empty()) {
|
|
283
353
|
return;
|
|
284
354
|
}
|
|
285
355
|
float density = ModUtil::getDensity();
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
356
|
+
int count0 = 0;
|
|
357
|
+
int count1 = 1;
|
|
358
|
+
int count2 = 2;
|
|
359
|
+
int count3 = 3;
|
|
360
|
+
setRectF(mRectVb, viewBox[count0], viewBox[count1], (viewBox[count0] + viewBox[count2]),
|
|
361
|
+
(viewBox[count1] + viewBox[count3]));
|
|
362
|
+
setRectF(mRectVbDensity, viewBox[count0] * density, viewBox[count1] * density,
|
|
363
|
+
(viewBox[count0] + viewBox[count2]) * density, (viewBox[count1] + viewBox[count3]) * density);
|
|
289
364
|
}
|
|
290
365
|
|
|
291
|
-
void ClipPathViewNoneNode::viewBoxTransform()
|
|
366
|
+
void ClipPathViewNoneNode::viewBoxTransform()
|
|
367
|
+
{
|
|
292
368
|
float density = ModUtil::getDensity();
|
|
293
369
|
if (validateViewBox()) {
|
|
294
370
|
setRect(mRectPath, mRectVbDensity);
|
|
295
371
|
SVGViewBox::transform(mRectVb, mBounds, mAlign, mAspect, density, mMatrix);
|
|
296
372
|
OH_Drawing_PathTransform(mPath, mMatrix);
|
|
297
373
|
OH_Drawing_MatrixMapRect(mMatrix, mRectPath, mRectPath);
|
|
298
|
-
|
|
299
374
|
} else {
|
|
300
375
|
setRect(mRectPath, mBounds);
|
|
301
376
|
}
|
|
302
377
|
}
|
|
303
|
-
bool ClipPathViewNoneNode::validateViewBox()
|
|
378
|
+
bool ClipPathViewNoneNode::validateViewBox()
|
|
379
|
+
{
|
|
304
380
|
return OH_Drawing_RectGetWidth(mRectVb) >= 0.0f && OH_Drawing_RectGetHeight(mRectVb) >= 0.0f;
|
|
305
381
|
}
|
|
306
382
|
|
|
307
|
-
void ClipPathViewNoneNode::setPaintStrokeProps()
|
|
383
|
+
void ClipPathViewNoneNode::setPaintStrokeProps()
|
|
384
|
+
{
|
|
308
385
|
OH_Drawing_PathSetFillType(mPath, mProps->getFillRule());
|
|
309
|
-
float sw = validateViewBox()
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
: toDip(mProps->getStrokeWidth());
|
|
386
|
+
float sw = validateViewBox() ? ModUtil::viewBoxToMax(mProps->getStrokeWidth(), mRectVb,
|
|
387
|
+
OH_Drawing_RectGetWidth(mRectPath), OH_Drawing_RectGetHeight(mRectPath)) :
|
|
388
|
+
toDip(mProps->getStrokeWidth());
|
|
313
389
|
OH_Drawing_PenSetWidth(mPaintStroke, sw);
|
|
314
390
|
OH_Drawing_PenSetCap(mPaintStroke, mProps->getStrokeCap());
|
|
315
391
|
OH_Drawing_PenSetJoin(mPaintStroke, mProps->getStrokeJoin());
|
|
@@ -318,12 +394,13 @@ void ClipPathViewNoneNode::setPaintStrokeProps() {
|
|
|
318
394
|
mPath2 = OH_Drawing_PathCopy(mPath);
|
|
319
395
|
if (mProps->getStrokeStart() != 0.0f || mProps->getStrokeEnd() != 1.0f) {
|
|
320
396
|
OH_Drawing_PathMoveTo(mPath2, OH_Drawing_PathGetLength(mPath2, false) * mProps->getStrokeStart(),
|
|
321
|
-
|
|
397
|
+
OH_Drawing_PathGetLength(mPath2, false) * mProps->getStrokeEnd());
|
|
322
398
|
OH_Drawing_PathLineTo(mPath2, 0.0f, 0.0f);
|
|
323
399
|
}
|
|
324
400
|
}
|
|
325
401
|
|
|
326
|
-
void ClipPathViewNoneNode::canvasTransform()
|
|
402
|
+
void ClipPathViewNoneNode::canvasTransform()
|
|
403
|
+
{
|
|
327
404
|
OH_Drawing_MatrixReset(mMatrix);
|
|
328
405
|
if (mRotation != 0.0f) {
|
|
329
406
|
float rotX;
|
|
@@ -333,9 +410,9 @@ void ClipPathViewNoneNode::canvasTransform() {
|
|
|
333
410
|
rotY = (mRotationOy * getSavedHeight());
|
|
334
411
|
} else if (validateViewBox()) {
|
|
335
412
|
rotX = OH_Drawing_RectGetLeft(mRectPath) +
|
|
336
|
-
|
|
413
|
+
ModUtil::viewBoxToWidth(mRotationOx, mRectVb, OH_Drawing_RectGetWidth(mRectPath));
|
|
337
414
|
rotY = OH_Drawing_RectGetTop(mRectPath) +
|
|
338
|
-
|
|
415
|
+
ModUtil::viewBoxToHeight(mRotationOy, mRectVb, OH_Drawing_RectGetHeight(mRectPath));
|
|
339
416
|
} else {
|
|
340
417
|
rotX = toDip(mRotationOx);
|
|
341
418
|
rotY = toDip(mRotationOy);
|
|
@@ -351,9 +428,9 @@ void ClipPathViewNoneNode::canvasTransform() {
|
|
|
351
428
|
oY = (mScaleOriginY * getSavedHeight());
|
|
352
429
|
} else if (validateViewBox()) {
|
|
353
430
|
oX = OH_Drawing_RectGetLeft(mRectPath) +
|
|
354
|
-
|
|
431
|
+
ModUtil::viewBoxToWidth(mScaleOriginX, mRectVb, OH_Drawing_RectGetWidth(mRectPath));
|
|
355
432
|
oY = OH_Drawing_RectGetTop(mRectPath) +
|
|
356
|
-
|
|
433
|
+
ModUtil::viewBoxToHeight(mScaleOriginY, mRectVb, OH_Drawing_RectGetHeight(mRectPath));
|
|
357
434
|
} else {
|
|
358
435
|
oX = toDip(mScaleOriginX);
|
|
359
436
|
oY = toDip(mScaleOriginY);
|
|
@@ -377,5 +454,4 @@ void ClipPathViewNoneNode::canvasTransform() {
|
|
|
377
454
|
OH_Drawing_MatrixPostTranslate(mMatrix, transX, transY);
|
|
378
455
|
}
|
|
379
456
|
}
|
|
380
|
-
|
|
381
457
|
} // namespace rnoh
|
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
*/
|
|
4
15
|
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
|
|
5
16
|
// please include "napi/native_api.h".
|
|
17
|
+
#ifndef CLIPPATHVIEWNONENODE_H
|
|
18
|
+
#define CLIPPATHVIEWNONENODE_H
|
|
19
|
+
|
|
6
20
|
#pragma once
|
|
7
21
|
|
|
8
22
|
#include "RNOH/arkui/ArkUINode.h"
|
|
@@ -13,86 +27,88 @@
|
|
|
13
27
|
#include "ClipPathProps.h"
|
|
14
28
|
#include "SVGViewBox.h"
|
|
15
29
|
namespace rnoh {
|
|
30
|
+
struct CanvasCallback {
|
|
31
|
+
std::function<void(ArkUI_NodeCustomEvent *event)> callback;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
class ClipPathViewNoneNode : public ArkUINode {
|
|
35
|
+
public:
|
|
36
|
+
ClipPathViewNoneNode();
|
|
37
|
+
~ClipPathViewNoneNode() override;
|
|
38
|
+
void InsertChild(ArkUINode &child, std::size_t index);
|
|
39
|
+
void RemoveChild(ArkUINode &child);
|
|
40
|
+
void SetD(const std::string d);
|
|
41
|
+
void SetStrokeWidth(float const width);
|
|
42
|
+
void SetStrokeCap(std::string const cap);
|
|
43
|
+
void SetStrokeJoin(std::string const join);
|
|
44
|
+
void SetStrokeMiter(float const miter);
|
|
45
|
+
void SetStrokeStart(float const start);
|
|
46
|
+
void SetStrokeEnd(float const end);
|
|
47
|
+
void SetViewBox(std::vector<float> viewBox);
|
|
48
|
+
void SetAlign(std::string v);
|
|
49
|
+
void SetAspect(std::string v);
|
|
50
|
+
void SetFillRule(std::string v);
|
|
51
|
+
// transFrom
|
|
52
|
+
void SetTransX(float v);
|
|
53
|
+
void SetTransY(float v);
|
|
54
|
+
void SetTransPercentageValue(bool v);
|
|
55
|
+
void SetRot(float v);
|
|
56
|
+
void SetRotO(float v);
|
|
57
|
+
void SetRotOx(float v);
|
|
58
|
+
void SetRotOy(float v);
|
|
59
|
+
void SetRotPercentageValue(bool v);
|
|
60
|
+
void SetSc(float v);
|
|
61
|
+
void SetScX(float v);
|
|
62
|
+
void SetScY(float v);
|
|
63
|
+
void SetScO(float v);
|
|
64
|
+
void SetScOx(float v);
|
|
65
|
+
void SetScOy(float v);
|
|
66
|
+
void SetTranslateZ(float z);
|
|
67
|
+
void SetScPercentageValue(bool v);
|
|
68
|
+
|
|
69
|
+
private:
|
|
70
|
+
void (*eventReceiver)(ArkUI_NodeCustomEvent *event);
|
|
71
|
+
void OnDraw(ArkUI_NodeCustomEvent *event);
|
|
72
|
+
void setupPath(OH_Drawing_Canvas *canvas);
|
|
73
|
+
void viewBoxTransform();
|
|
74
|
+
bool validateViewBox();
|
|
75
|
+
void setRect(OH_Drawing_Rect *target, OH_Drawing_Rect *src);
|
|
76
|
+
void setRectF(OH_Drawing_Rect *target, float left, float top, float right, float bottom);
|
|
77
|
+
void setPaintStrokeProps();
|
|
78
|
+
float toDip(float value);
|
|
79
|
+
void canvasTransform();
|
|
80
|
+
void drawPath(OH_Drawing_Canvas *canvas);
|
|
81
|
+
void setPanStyleMode(OH_Drawing_Canvas *canvas, int type);
|
|
16
82
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
83
|
+
private:
|
|
84
|
+
std::string mD{ "" };
|
|
85
|
+
std::string mAlign{ "xMinYMin" };
|
|
86
|
+
CanvasCallback *canvasCallback_{ nullptr };
|
|
87
|
+
int mAspect{ SVGViewBox::MOS_MEET };
|
|
88
|
+
ClipPathProps *mProps{ new ClipPathProps() };
|
|
89
|
+
OH_Drawing_Rect *mRectVb{ OH_Drawing_RectCreate(0.0f, 0.0f, -1.0f, -1.0f) };
|
|
90
|
+
OH_Drawing_Rect *mRectVbDensity{ OH_Drawing_RectCreate(0.0f, 0.0f, -1.0f, -1.0f) };
|
|
91
|
+
OH_Drawing_Rect *mRectPath{ OH_Drawing_RectCreate(0.0f, 0.0f, 0.0f, 0.0f) };
|
|
92
|
+
OH_Drawing_Rect *mBounds{ OH_Drawing_RectCreate(0.0f, 0.0f, 0.0f, 0.0f) };
|
|
93
|
+
OH_Drawing_Matrix *mMatrix{ OH_Drawing_MatrixCreate() };
|
|
94
|
+
OH_Drawing_Path *mPath{};
|
|
95
|
+
OH_Drawing_Path *mPath2{ OH_Drawing_PathCreate() };
|
|
96
|
+
OH_Drawing_Pen *mPaint{ OH_Drawing_PenCreate() };
|
|
97
|
+
OH_Drawing_Pen *mPaintStroke{ OH_Drawing_PenCreate() };
|
|
98
|
+
OH_Drawing_Canvas *canvas{ nullptr };
|
|
99
|
+
float mTranslationX{ 0.0f };
|
|
100
|
+
float mTranslationY{ 0.0f };
|
|
101
|
+
bool mTranslationIsPercent{ false };
|
|
102
|
+
float mRotation{ 0.0f };
|
|
103
|
+
float mRotationOx{ 0.0f };
|
|
104
|
+
float mRotationOy{ 0.0f };
|
|
105
|
+
bool mRotationIsPercent{ false };
|
|
106
|
+
float mScaleX{ 1.0f };
|
|
107
|
+
float mScaleY{ 1.0f };
|
|
108
|
+
float mScaleOriginX{ 0.0f };
|
|
109
|
+
float mScaleOriginY{ 0.0f };
|
|
110
|
+
bool mScaleIsPercent{ false };
|
|
111
|
+
};
|
|
112
|
+
} // namespace rnoh
|
|
20
113
|
|
|
21
|
-
|
|
22
|
-
public:
|
|
23
|
-
ClipPathViewNoneNode();
|
|
24
|
-
~ClipPathViewNoneNode() override;
|
|
25
|
-
void insertChild(ArkUINode &child, std::size_t index);
|
|
26
|
-
void removeChild(ArkUINode &child);
|
|
27
|
-
void setD(const std::string d);
|
|
28
|
-
void setStrokeWidth(float const width);
|
|
29
|
-
void setStrokeCap(std::string const cap);
|
|
30
|
-
void setStrokeJoin(std::string const join);
|
|
31
|
-
void setStrokeMiter(float const miter);
|
|
32
|
-
void setStrokeStart(float const start);
|
|
33
|
-
void setStrokeEnd(float const end);
|
|
34
|
-
void setViewBox(std::vector<float> viewBox);
|
|
35
|
-
void setAlign(std::string v);
|
|
36
|
-
void setAspect(std::string v);
|
|
37
|
-
void setFillRule(std::string v);
|
|
38
|
-
// transFrom
|
|
39
|
-
void setTransX(float v);
|
|
40
|
-
void setTransY(float v);
|
|
41
|
-
void setTransPercentageValue(bool v);
|
|
42
|
-
void setRot(float v);
|
|
43
|
-
void setRotO(float v);
|
|
44
|
-
void setRotOx(float v);
|
|
45
|
-
void setRotOy(float v);
|
|
46
|
-
void setRotPercentageValue(bool v);
|
|
47
|
-
void setSc(float v);
|
|
48
|
-
void setScX(float v);
|
|
49
|
-
void setScY(float v);
|
|
50
|
-
void setScO(float v);
|
|
51
|
-
void setScOx(float v);
|
|
52
|
-
void setScOy(float v);
|
|
53
|
-
void setTranslateZ(float z);
|
|
54
|
-
void setScPercentageValue(bool v);
|
|
55
|
-
private:
|
|
56
|
-
void (*eventReceiver)(ArkUI_NodeCustomEvent *event);
|
|
57
|
-
void OnDraw(ArkUI_NodeCustomEvent *event);
|
|
58
|
-
void setupPath(OH_Drawing_Canvas *canvas);
|
|
59
|
-
void viewBoxTransform();
|
|
60
|
-
bool validateViewBox();
|
|
61
|
-
void setRect(OH_Drawing_Rect *target, OH_Drawing_Rect *src);
|
|
62
|
-
void setRectF(OH_Drawing_Rect *target, float left, float top, float right, float bottom);
|
|
63
|
-
void setPaintStrokeProps();
|
|
64
|
-
float toDip(float value);
|
|
65
|
-
void canvasTransform();
|
|
66
|
-
void drawPath(OH_Drawing_Canvas *canvas);
|
|
67
|
-
void setPanStyleMode(OH_Drawing_Canvas *canvas,int type);
|
|
68
|
-
|
|
69
|
-
private:
|
|
70
|
-
std::string mD{""};
|
|
71
|
-
std::string mAlign{"xMinYMin"};
|
|
72
|
-
CanvasCallback *canvasCallback_{nullptr};
|
|
73
|
-
int mAspect{SVGViewBox::MOS_MEET};
|
|
74
|
-
ClipPathProps *mProps{new ClipPathProps()};
|
|
75
|
-
OH_Drawing_Rect *mRectVb{OH_Drawing_RectCreate(0.0f, 0.0f, -1.0f, -1.0f)};
|
|
76
|
-
OH_Drawing_Rect *mRectVbDensity{OH_Drawing_RectCreate(0.0f, 0.0f, -1.0f, -1.0f)};
|
|
77
|
-
OH_Drawing_Rect *mRectPath{OH_Drawing_RectCreate(0.0f, 0.0f, 0.0f, 0.0f)};
|
|
78
|
-
OH_Drawing_Rect *mBounds{OH_Drawing_RectCreate(0.0f, 0.0f, 0.0f, 0.0f)};
|
|
79
|
-
OH_Drawing_Matrix *mMatrix{OH_Drawing_MatrixCreate()};
|
|
80
|
-
OH_Drawing_Path *mPath{};
|
|
81
|
-
OH_Drawing_Path *mPath2{OH_Drawing_PathCreate()};
|
|
82
|
-
OH_Drawing_Pen *mPaint{OH_Drawing_PenCreate()};
|
|
83
|
-
OH_Drawing_Pen *mPaintStroke{OH_Drawing_PenCreate()};
|
|
84
|
-
OH_Drawing_Canvas *canvas{nullptr};
|
|
85
|
-
float mTranslationX{0.0f};
|
|
86
|
-
float mTranslationY{0.0f};
|
|
87
|
-
bool mTranslationIsPercent{false};
|
|
88
|
-
float mRotation{0.0f};
|
|
89
|
-
float mRotationOx{0.0f};
|
|
90
|
-
float mRotationOy{0.0f};
|
|
91
|
-
bool mRotationIsPercent{false};
|
|
92
|
-
float mScaleX{1.0f};
|
|
93
|
-
float mScaleY{1.0f};
|
|
94
|
-
float mScaleOriginX{0.0f};
|
|
95
|
-
float mScaleOriginY{0.0f};
|
|
96
|
-
bool mScaleIsPercent{false};
|
|
97
|
-
};
|
|
98
|
-
} // namespace rnoh
|
|
114
|
+
#endif
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
using namespace rnoh;
|
|
28
28
|
using namespace facebook;
|
|
29
29
|
|
|
30
|
-
static jsi::Value
|
|
30
|
+
static jsi::Value hostFunction_RNCClipPathTurboModule_getDensity(jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
31
31
|
const jsi::Value *args, size_t count) {
|
|
32
32
|
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "getDensity", args, count);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
RNCClipPathTurboModule::RNCClipPathTurboModule(const ArkTSTurboModule::Context ctx, const std::string name)
|
|
36
36
|
: ArkTSTurboModule(ctx, name) {
|
|
37
|
-
methodMap_["getDensity"] = MethodMetadata{0,
|
|
37
|
+
methodMap_["getDensity"] = MethodMetadata{0, hostFunction_RNCClipPathTurboModule_getDensity};
|
|
38
38
|
}
|