@react-native-ohos/react-native-clippathview 1.1.9-rc.2 → 1.2.0

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