@react-native-ohos/react-native-svg 15.12.1-rc.1 → 15.12.1-rc.3

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.
Files changed (70) hide show
  1. package/LICENSE +21 -21
  2. package/README.OpenSource +10 -10
  3. package/README.md +13 -13
  4. package/css/package.json +5 -5
  5. package/harmony/svg/BuildProfile.ets +16 -16
  6. package/harmony/svg/build-profile.json5 +9 -9
  7. package/harmony/svg/hvigorfile.ts +1 -1
  8. package/harmony/svg/index.ets +6 -6
  9. package/harmony/svg/oh-package.json5 +13 -13
  10. package/harmony/svg/src/main/cpp/SVGPackage.h +4 -0
  11. package/harmony/svg/src/main/cpp/SvgArkUINode.cpp +3 -0
  12. package/harmony/svg/src/main/cpp/SvgArkUINode.h +15 -9
  13. package/harmony/svg/src/main/cpp/SvgFilter.cpp +505 -505
  14. package/harmony/svg/src/main/cpp/SvgFilter.h +112 -112
  15. package/harmony/svg/src/main/cpp/SvgForeignObjectNode.cpp +74 -0
  16. package/harmony/svg/src/main/cpp/SvgForeignObjectNode.h +54 -0
  17. package/harmony/svg/src/main/cpp/SvgForeignObjectNodeDelegate.h +30 -0
  18. package/harmony/svg/src/main/cpp/SvgNode.cpp +64 -0
  19. package/harmony/svg/src/main/cpp/SvgNode.h +17 -1
  20. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeBlendComponentInstance.cpp +40 -40
  21. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeBlendComponentInstance.h +48 -48
  22. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeColorMatrixComponentInstance.cpp +33 -33
  23. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeColorMatrixComponentInstance.h +48 -48
  24. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeCompositeComponentInstance.cpp +39 -39
  25. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeCompositeComponentInstance.h +55 -55
  26. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeFloodComponentInstance.cpp +33 -33
  27. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeFloodComponentInstance.h +49 -49
  28. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeGaussianBlurComponentInstance.cpp +34 -34
  29. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeGaussianBlurComponentInstance.h +48 -48
  30. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeOffsetComponentInstance.cpp +35 -35
  31. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeOffsetComponentInstance.h +45 -45
  32. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFilterComponentInstance.cpp +198 -198
  33. package/harmony/svg/src/main/cpp/componentInstances/RNSVGFilterComponentInstance.h +48 -48
  34. package/harmony/svg/src/main/cpp/componentInstances/RNSVGForeignObjectComponentInstance.cpp +65 -0
  35. package/harmony/svg/src/main/cpp/componentInstances/RNSVGForeignObjectComponentInstance.h +50 -0
  36. package/harmony/svg/src/main/cpp/componentInstances/RNSVGGroupComponentInstance.h +8 -4
  37. package/harmony/svg/src/main/cpp/componentInstances/RNSVGImageComponentInstance.cpp +4 -1
  38. package/harmony/svg/src/main/cpp/componentInstances/RNSVGSvgViewComponentInstance.cpp +37 -0
  39. package/harmony/svg/src/main/cpp/componentInstances/RNSVGSvgViewComponentInstance.h +10 -2
  40. package/harmony/svg/src/main/cpp/downloadUtils/ImageSourceResolver.cpp +36 -15
  41. package/harmony/svg/src/main/cpp/downloadUtils/ImageSourceResolver.h +6 -10
  42. package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeBlendJSIBinder.h +26 -26
  43. package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeColorMatrixJSIBinder.h +26 -26
  44. package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeCompositeJSIBinder.h +30 -30
  45. package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeFloodJSIBinder.h +26 -26
  46. package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeGaussianBlurJSIBinder.h +26 -26
  47. package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeOffsetJSIBinder.h +26 -26
  48. package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFilterJSIBinder.h +44 -44
  49. package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/Props.cpp +977 -977
  50. package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/Props.h +1280 -1280
  51. package/harmony/svg/src/main/cpp/utils/DynamicUtils.h +55 -55
  52. package/harmony/svg/src/main/cpp/utils/FilterManager.h +190 -190
  53. package/harmony/svg/src/main/ets/RNSVGImageModule.ts +21 -21
  54. package/harmony/svg/src/main/ets/RNSVGRenderableModule.ts +16 -16
  55. package/harmony/svg/src/main/ets/RNSVGSvgViewModule.ts +18 -18
  56. package/harmony/svg/src/main/ets/SvgPackage.ts +57 -57
  57. package/harmony/svg/src/main/module.json5 +7 -7
  58. package/harmony/svg/src/main/resources/base/element/string.json +8 -8
  59. package/harmony/svg/src/main/resources/en_US/element/string.json +8 -8
  60. package/harmony/svg/src/main/resources/zh_CN/element/string.json +8 -8
  61. package/harmony/svg/ts.ts +7 -7
  62. package/harmony/svg.har +0 -0
  63. package/lib/commonjs/css/index.js.map +1 -1
  64. package/lib/commonjs/index.js.map +1 -1
  65. package/lib/module/css/index.js.map +1 -1
  66. package/lib/module/index.js.map +1 -1
  67. package/package.json +53 -54
  68. package/src/css/index.tsx +19 -19
  69. package/src/index.tsx +2 -2
  70. package/tsconfig.json +11 -11
@@ -1,112 +1,112 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
- * Use of this source code is governed by a MIT license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- #pragma once
8
-
9
- #include "SvgNode.h"
10
- #include "drawing/Brush.h"
11
- #include "drawing/Pen.h"
12
- #include <native_drawing/drawing_canvas.h>
13
- #include <native_drawing/drawing_filter.h>
14
-
15
- namespace rnoh {
16
- namespace svg {
17
-
18
- enum class FilterType {
19
- BLUR,
20
- GAUSSIAN_BLUR,
21
- DROP_SHADOW,
22
- COLOR_MATRIX,
23
- FEOFFSET,
24
- FEFLOOD,
25
- BLEND,
26
- COMPOSITE,
27
- MERGE,
28
- UNKNOWN
29
- };
30
-
31
- struct FilterEffect {
32
- FilterType filterType = FilterType::UNKNOWN;
33
- std::vector<float> values;
34
- std::string type = "";
35
- std::string in = "SourceGraphic";
36
- std::string in2 = "";
37
- std::string result = "";
38
-
39
- std::string mode = "";
40
- std::string operator_ = "";
41
- std::string floodColor = "black";
42
- float floodOpacity = 1.0f;
43
-
44
- float dx_ = 0.0f;
45
- float dy_ = 0.0f;
46
- float stdDeviationX_ = 0.0f;
47
- float stdDeviationY_ = 0.0f;
48
- std::string edgeMode_ = "duplicate";
49
- std::string k1 = "";
50
- std::string k2 = "";
51
- std::string k3 = "";
52
- std::string k4 = "";
53
-
54
- FilterEffect() = default;
55
- FilterEffect(FilterType t, const std::vector<float>& v) : filterType(t), values(v) {}
56
- FilterEffect(FilterType t, const std::vector<float>& v, const std::string& inputSource, const std::string& inputType, const std::string& resultId)
57
- : filterType(t), values(v), in(inputSource), type(inputType), result(resultId) {}
58
- FilterEffect(FilterType t, const std::string& inputSource, const std::string& inputSource2, const std::string& blendMode, const std::string& resultId)
59
- : filterType(t), in(inputSource), in2(inputSource2), mode(blendMode), result(resultId) {}
60
- FilterEffect(FilterType t, const std::string& inputSource, const std::string& color, float opacity, const std::string& resultId)
61
- : filterType(t), in(inputSource), floodColor(color), floodOpacity(opacity), result(resultId) {}
62
- FilterEffect(FilterType t, const std::string& inputSource, float dx, float dy, const std::string& resultId)
63
- : filterType(t), in(inputSource), dx_(dx), dy_(dy), result(resultId) {}
64
- FilterEffect(FilterType t, const std::string& inputSource, const std::string& inputSource2, const std::string& op,
65
- const std::string& k1_, const std::string& k2_, const std::string& k3_, const std::string& k4_, const std::string& resultId)
66
- : filterType(t), in(inputSource), in2(inputSource2), operator_(op), k1(k1_), k2(k2_), k3(k3_), k4(k4_), result(resultId) {}
67
- FilterEffect(FilterType t, const std::string& inputSource, float stdDeviationX, float stdDeviationY, const std::string& edgeMode, const std::string& resultId)
68
- : filterType(t), in(inputSource), stdDeviationX_(stdDeviationX), stdDeviationY_(stdDeviationY), edgeMode_(edgeMode), result(resultId) {}
69
-
70
- // DropShadow specific constructor
71
- FilterEffect(FilterType t, const std::string& inputSource, float dx, float dy, float stdDeviation, const std::string& color, float opacity)
72
- : filterType(t), in(inputSource), dx_(dx), dy_(dy), stdDeviationX_(stdDeviation), floodColor(color), floodOpacity(opacity) {}
73
- };
74
-
75
- class SvgFilter : virtual public SvgNode {
76
- public:
77
- SvgFilter() : SvgNode() {}
78
- ~SvgFilter() noexcept override = default;
79
- void ApplyToBrush(rnoh::drawing::Brush& brush, const std::string& extra = "");
80
- void ApplyToPen(rnoh::drawing::Pen& pen);
81
-
82
- void AddFilterEffect(const FilterEffect& effect);
83
- void ClearFilterEffects() {
84
- effects_.clear();
85
- }
86
-
87
- void Draw(OH_Drawing_Canvas *canvas) override {}
88
- private:
89
- std::vector<FilterEffect> effects_;
90
- void ApplySingleEffectToFilter(OH_Drawing_Filter* filter, const FilterEffect& effect,
91
- rnoh::drawing::Brush* brush = nullptr, rnoh::drawing::Pen* pen = nullptr, const std::string& extra = "");
92
-
93
- OH_Drawing_ImageFilter* CreateGaussianBlurFilter(const FilterEffect& effect);
94
- OH_Drawing_MaskFilter* CreateBlurFilter(const FilterEffect& effect);
95
- OH_Drawing_ColorFilter* CreateColorMatrixFilter(const FilterEffect& effect);
96
- OH_Drawing_ShadowLayer* CreateDropShadowFilter(const FilterEffect& effect);
97
-
98
- OH_Drawing_ColorFilter* CreateMatrixFilter(const std::vector<float>& values);
99
- OH_Drawing_ColorFilter* CreateSaturateFilter(const std::vector<float>& values);
100
- OH_Drawing_ColorFilter* CreateHueRotateFilter(const std::vector<float>& values);
101
- OH_Drawing_ColorFilter* CreateLuminanceToAlphaFilter();
102
-
103
- OH_Drawing_ImageFilter* GetInputImageFilter(const std::string& inputName);
104
- OH_Drawing_ColorFilter* GetInputColorFilter(const std::string& inputName);
105
- OH_Drawing_Filter* GetInputFilter(const std::string& inputName);
106
- OH_Drawing_ColorFilter* CombineWithInputColor(OH_Drawing_ColorFilter* newFilter, const std::string& inputName);
107
- void RegisterFilterResult(const std::string& resultId, OH_Drawing_ImageFilter* imageFilter = nullptr,
108
- OH_Drawing_ColorFilter* colorFilter = nullptr, OH_Drawing_MaskFilter* maskFilter = nullptr);
109
- };
110
-
111
- } // namespace svg
112
- } // namespace rnoh
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ #pragma once
8
+
9
+ #include "SvgNode.h"
10
+ #include "drawing/Brush.h"
11
+ #include "drawing/Pen.h"
12
+ #include <native_drawing/drawing_canvas.h>
13
+ #include <native_drawing/drawing_filter.h>
14
+
15
+ namespace rnoh {
16
+ namespace svg {
17
+
18
+ enum class FilterType {
19
+ BLUR,
20
+ GAUSSIAN_BLUR,
21
+ DROP_SHADOW,
22
+ COLOR_MATRIX,
23
+ FEOFFSET,
24
+ FEFLOOD,
25
+ BLEND,
26
+ COMPOSITE,
27
+ MERGE,
28
+ UNKNOWN
29
+ };
30
+
31
+ struct FilterEffect {
32
+ FilterType filterType = FilterType::UNKNOWN;
33
+ std::vector<float> values;
34
+ std::string type = "";
35
+ std::string in = "SourceGraphic";
36
+ std::string in2 = "";
37
+ std::string result = "";
38
+
39
+ std::string mode = "";
40
+ std::string operator_ = "";
41
+ std::string floodColor = "black";
42
+ float floodOpacity = 1.0f;
43
+
44
+ float dx_ = 0.0f;
45
+ float dy_ = 0.0f;
46
+ float stdDeviationX_ = 0.0f;
47
+ float stdDeviationY_ = 0.0f;
48
+ std::string edgeMode_ = "duplicate";
49
+ std::string k1 = "";
50
+ std::string k2 = "";
51
+ std::string k3 = "";
52
+ std::string k4 = "";
53
+
54
+ FilterEffect() = default;
55
+ FilterEffect(FilterType t, const std::vector<float>& v) : filterType(t), values(v) {}
56
+ FilterEffect(FilterType t, const std::vector<float>& v, const std::string& inputSource, const std::string& inputType, const std::string& resultId)
57
+ : filterType(t), values(v), in(inputSource), type(inputType), result(resultId) {}
58
+ FilterEffect(FilterType t, const std::string& inputSource, const std::string& inputSource2, const std::string& blendMode, const std::string& resultId)
59
+ : filterType(t), in(inputSource), in2(inputSource2), mode(blendMode), result(resultId) {}
60
+ FilterEffect(FilterType t, const std::string& inputSource, const std::string& color, float opacity, const std::string& resultId)
61
+ : filterType(t), in(inputSource), floodColor(color), floodOpacity(opacity), result(resultId) {}
62
+ FilterEffect(FilterType t, const std::string& inputSource, float dx, float dy, const std::string& resultId)
63
+ : filterType(t), in(inputSource), dx_(dx), dy_(dy), result(resultId) {}
64
+ FilterEffect(FilterType t, const std::string& inputSource, const std::string& inputSource2, const std::string& op,
65
+ const std::string& k1_, const std::string& k2_, const std::string& k3_, const std::string& k4_, const std::string& resultId)
66
+ : filterType(t), in(inputSource), in2(inputSource2), operator_(op), k1(k1_), k2(k2_), k3(k3_), k4(k4_), result(resultId) {}
67
+ FilterEffect(FilterType t, const std::string& inputSource, float stdDeviationX, float stdDeviationY, const std::string& edgeMode, const std::string& resultId)
68
+ : filterType(t), in(inputSource), stdDeviationX_(stdDeviationX), stdDeviationY_(stdDeviationY), edgeMode_(edgeMode), result(resultId) {}
69
+
70
+ // DropShadow specific constructor
71
+ FilterEffect(FilterType t, const std::string& inputSource, float dx, float dy, float stdDeviation, const std::string& color, float opacity)
72
+ : filterType(t), in(inputSource), dx_(dx), dy_(dy), stdDeviationX_(stdDeviation), floodColor(color), floodOpacity(opacity) {}
73
+ };
74
+
75
+ class SvgFilter : virtual public SvgNode {
76
+ public:
77
+ SvgFilter() : SvgNode() {}
78
+ ~SvgFilter() noexcept override = default;
79
+ void ApplyToBrush(rnoh::drawing::Brush& brush, const std::string& extra = "");
80
+ void ApplyToPen(rnoh::drawing::Pen& pen);
81
+
82
+ void AddFilterEffect(const FilterEffect& effect);
83
+ void ClearFilterEffects() {
84
+ effects_.clear();
85
+ }
86
+
87
+ void Draw(OH_Drawing_Canvas *canvas) override {}
88
+ private:
89
+ std::vector<FilterEffect> effects_;
90
+ void ApplySingleEffectToFilter(OH_Drawing_Filter* filter, const FilterEffect& effect,
91
+ rnoh::drawing::Brush* brush = nullptr, rnoh::drawing::Pen* pen = nullptr, const std::string& extra = "");
92
+
93
+ OH_Drawing_ImageFilter* CreateGaussianBlurFilter(const FilterEffect& effect);
94
+ OH_Drawing_MaskFilter* CreateBlurFilter(const FilterEffect& effect);
95
+ OH_Drawing_ColorFilter* CreateColorMatrixFilter(const FilterEffect& effect);
96
+ OH_Drawing_ShadowLayer* CreateDropShadowFilter(const FilterEffect& effect);
97
+
98
+ OH_Drawing_ColorFilter* CreateMatrixFilter(const std::vector<float>& values);
99
+ OH_Drawing_ColorFilter* CreateSaturateFilter(const std::vector<float>& values);
100
+ OH_Drawing_ColorFilter* CreateHueRotateFilter(const std::vector<float>& values);
101
+ OH_Drawing_ColorFilter* CreateLuminanceToAlphaFilter();
102
+
103
+ OH_Drawing_ImageFilter* GetInputImageFilter(const std::string& inputName);
104
+ OH_Drawing_ColorFilter* GetInputColorFilter(const std::string& inputName);
105
+ OH_Drawing_Filter* GetInputFilter(const std::string& inputName);
106
+ OH_Drawing_ColorFilter* CombineWithInputColor(OH_Drawing_ColorFilter* newFilter, const std::string& inputName);
107
+ void RegisterFilterResult(const std::string& resultId, OH_Drawing_ImageFilter* imageFilter = nullptr,
108
+ OH_Drawing_ColorFilter* colorFilter = nullptr, OH_Drawing_MaskFilter* maskFilter = nullptr);
109
+ };
110
+
111
+ } // namespace svg
112
+ } // namespace rnoh
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ *
6
+ * This file incorporates from the OpenHarmony project, licensed under
7
+ * the Apache License, Version 2.0. Specifically:
8
+ * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine)
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
11
+ * use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at:
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
+ * License for the specific language governing permissions and limitations
19
+ * under the License.
20
+ */
21
+
22
+ #include "SvgForeignObjectNode.h"
23
+ #include "RNOH/arkui/NativeNodeApi.h"
24
+ namespace rnoh {
25
+ namespace svg {
26
+ SvgForeignObjectNode::SvgForeignObjectNode()
27
+ : ArkUINode(NativeNodeApi::getInstance()->createNode(ArkUI_NodeType::ARKUI_NODE_STACK)) {
28
+ mStackNode.setVisibility(ArkUI_Visibility::ARKUI_VISIBILITY_HIDDEN);
29
+ mStackNode.setClip(true);
30
+ maybeThrow(NativeNodeApi::getInstance()->addChild(m_nodeHandle, mStackNode.getArkUINodeHandle()));
31
+ }
32
+
33
+ SvgForeignObjectNode::~SvgForeignObjectNode() {
34
+ if (m_NodeDelegate) {
35
+ m_NodeDelegate = nullptr;
36
+ }
37
+ }
38
+ void SvgForeignObjectNode::insertChild(ArkUINode &child, std::size_t index) { mStackNode.insertChild(child, index); }
39
+
40
+ void SvgForeignObjectNode::SetSnapHeight(float height) { _height = height; }
41
+
42
+ void SvgForeignObjectNode::SetSnapWidth(float width) { _width = width; }
43
+
44
+ void SvgForeignObjectNode::SetSnapPosition(float x, float y) {
45
+ _positionX = x;
46
+ _positionY = y;
47
+ }
48
+
49
+ void SvgForeignObjectNode::onNodeEvent(ArkUI_NodeEventType eventType, EventArgs &eventArgs) {
50
+ if (eventType == ArkUI_NodeEventType::NODE_EVENT_ON_AREA_CHANGE) {
51
+ if (m_NodeDelegate) {
52
+ OH_PixelmapNative *pixelMap = GetNodePixelMap();
53
+ if (!pixelMap) {
54
+ LOG(ERROR) << "[svgForeignNode] get node snapshot pixelMap is null";
55
+ return;
56
+ }
57
+ m_NodeDelegate->onDrawForeignImage(pixelMap, _width, _height, _positionX, _positionY);
58
+ }
59
+ }
60
+ }
61
+
62
+ OH_PixelmapNative *SvgForeignObjectNode::GetNodePixelMap() {
63
+ OH_PixelmapNative *pixelMap;
64
+ ArkUI_SnapshotOptions *options = OH_ArkUI_CreateSnapshotOptions();
65
+ OH_ArkUI_SnapshotOptions_SetScale(options, 1);
66
+ int32_t code = OH_ArkUI_GetNodeSnapshot(mStackNode.getArkUINodeHandle(), options, &pixelMap);
67
+ if (code == ARKUI_ERROR_CODE_NO_ERROR) {
68
+ return pixelMap;
69
+ }
70
+ return nullptr;
71
+ }
72
+
73
+ } // namespace svg
74
+ } // namespace rnoh
@@ -0,0 +1,54 @@
1
+ /*
2
+ * Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ *
6
+ * This file incorporates from the OpenHarmony project, licensed under
7
+ * the Apache License, Version 2.0. Specifically:
8
+ * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine)
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
11
+ * use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at:
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
+ * License for the specific language governing permissions and limitations
19
+ * under the License.
20
+ */
21
+
22
+ #ifndef HARMONY_SVGFOREIGNOBJECTNODE_H
23
+ #define HARMONY_SVGFOREIGNOBJECTNODE_H
24
+ #include "RNOH/arkui/ArkUINode.h"
25
+ #include "RNOH/arkui/StackNode.h"
26
+ #include "SvgForeignObjectNodeDelegate.h"
27
+
28
+ namespace rnoh {
29
+ namespace svg {
30
+ class SvgForeignObjectNode : public ArkUINode {
31
+ public:
32
+ SvgForeignObjectNode();
33
+ ~SvgForeignObjectNode() override;
34
+ void onNodeEvent(ArkUI_NodeEventType eventType, EventArgs &eventArgs) override;
35
+ StackNode &getSnapNode() { return mStackNode; }
36
+ void insertChild(ArkUINode &child, std::size_t index);
37
+ void SetSnapPosition(float x, float y);
38
+ void SetSnapWidth(float width);
39
+ void SetSnapHeight(float height);
40
+ OH_PixelmapNative *GetNodePixelMap();
41
+ void SetForeignNodeDelegate(SvgForeignObjectNodeDelegate *delegate) { m_NodeDelegate = delegate; };
42
+
43
+ private:
44
+ StackNode mStackNode;
45
+ SvgForeignObjectNodeDelegate *m_NodeDelegate;
46
+ float _width{0};
47
+ float _height{0};
48
+ float _positionX{0};
49
+ float _positionY{0};
50
+ };
51
+
52
+ } // namespace svg
53
+ } // namespace rnoh
54
+ #endif // HARMONY_SVGFOREIGNOBJECTNODE_H
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ *
6
+ * This file incorporates from the OpenHarmony project, licensed under
7
+ * the Apache License, Version 2.0. Specifically:
8
+ * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine)
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
11
+ * use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at:
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
+ * License for the specific language governing permissions and limitations
19
+ * under the License.
20
+ */
21
+
22
+ #ifndef HARMONY_SVGFOREIGNOBJECTNODEDELEGATE_H
23
+ #define HARMONY_SVGFOREIGNOBJECTNODEDELEGATE_H
24
+ #include <multimedia/image_framework/image/pixelmap_native.h>
25
+ class SvgForeignObjectNodeDelegate {
26
+ public:
27
+ virtual ~SvgForeignObjectNodeDelegate() = default;
28
+ virtual void onDrawForeignImage(OH_PixelmapNative *foreignPixelMap,float width,float height,float x,float y){};
29
+ };
30
+ #endif //HARMONY_SVGFOREIGNOBJECTNODEDELEGATE_H
@@ -23,11 +23,13 @@
23
23
  #include "utils/SvgUtils.h"
24
24
  #include "SvgGradient.h"
25
25
  #include "SvgPattern.h"
26
+ #include "properties/ViewBox.h"
26
27
  #include "SvgFilter.h"
27
28
  #include <native_drawing/drawing_matrix.h>
28
29
  #include <native_drawing/drawing_path.h>
29
30
  #include <regex>
30
31
  #include <string>
32
+ #include <native_drawing/drawing_pixel_map.h>
31
33
 
32
34
  namespace rnoh {
33
35
  namespace svg {
@@ -204,6 +206,13 @@ void SvgNode::Draw(OH_Drawing_Canvas *canvas) {
204
206
  // on marker
205
207
 
206
208
  OnDrawTraversed(canvas);
209
+
210
+ if (_foreignPropsArray.size() > 0) {
211
+ for (ForeignProps _foreignProps : _foreignPropsArray) {
212
+ DrawForeignPixelMap(canvas, _foreignProps);
213
+ }
214
+ _foreignPropsArray.clear();
215
+ }
207
216
  OH_Drawing_CanvasRestoreToCount(canvas, count);
208
217
  }
209
218
 
@@ -285,5 +294,60 @@ double SvgNode::getCanvasDiagonal() {
285
294
  canvasDiagonal_ = sqrt(powX + powY) * M_SQRT1_2l;
286
295
  return canvasDiagonal_;
287
296
  }
297
+
298
+ void SvgNode::DrawForeignPixelMap(OH_Drawing_Canvas *canvas, ForeignProps _foreignProps) {
299
+ if (!_foreignProps.foreignPixelMap) {
300
+ DLOG(INFO) << "[svgForeignNode] foreignPixelMap is null";
301
+ return;
302
+ }
303
+ DLOG(INFO) << "[svgForeignNode] DrawForeignPixelMap start , width:" << _foreignProps.width;
304
+ OH_Pixelmap_ImageInfo *imageInfo;
305
+ OH_PixelmapImageInfo_Create(&imageInfo);
306
+
307
+ OH_PixelmapNative_GetImageInfo(_foreignProps.foreignPixelMap, imageInfo);
308
+ uint32_t originalWidth = 0, originalHeight = 0;
309
+ OH_PixelmapImageInfo_GetWidth(imageInfo, &originalWidth);
310
+ OH_PixelmapImageInfo_GetHeight(imageInfo, &originalHeight);
311
+ OH_PixelmapImageInfo_Release(imageInfo);
312
+
313
+ if (originalWidth == 0 || originalHeight == 0) {
314
+ DLOG(WARNING) << "[svgForeignNode] Invalid pixelmap size";
315
+ OH_PixelmapNative_Release(_foreignProps.foreignPixelMap);
316
+ return;
317
+ }
318
+
319
+ OH_Drawing_PixelMap *ohPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(_foreignProps.foreignPixelMap);
320
+ if (!ohPixelMap) {
321
+ DLOG(WARNING) << "[svgForeignNode] Failed to get OH_Drawing_PixelMap";
322
+ OH_PixelmapNative_Release(_foreignProps.foreignPixelMap);
323
+ return;
324
+ }
325
+
326
+ OH_Drawing_CanvasSave(canvas);
327
+
328
+ OH_Drawing_CanvasTranslate(canvas, _foreignProps.x, _foreignProps.y);
329
+
330
+
331
+ float scaleX = static_cast<float>(_foreignProps.width) / originalWidth;
332
+ float scaleY = static_cast<float>(_foreignProps.height) / originalHeight;
333
+ OH_Drawing_CanvasScale(canvas, 1, 1);
334
+
335
+ OH_Drawing_Rect *srcRect = OH_Drawing_RectCreate(0, 0, originalWidth, originalHeight);
336
+ OH_Drawing_Rect *dstRect = OH_Drawing_RectCreate(0, 0, originalWidth, originalHeight);
337
+ OH_Drawing_SamplingOptions *sampling = OH_Drawing_SamplingOptionsCreate(FILTER_MODE_LINEAR, MIPMAP_MODE_LINEAR);
338
+ OH_Drawing_CanvasDrawPixelMapRect(canvas, ohPixelMap, srcRect, dstRect, sampling);
339
+
340
+
341
+ OH_Drawing_CanvasRestore(canvas);
342
+ OH_Drawing_PixelMapDissolve(ohPixelMap);
343
+ OH_PixelmapNative_Release(_foreignProps.foreignPixelMap);
344
+ OH_Drawing_RectDestroy(srcRect);
345
+ OH_Drawing_RectDestroy(dstRect);
346
+ OH_Drawing_SamplingOptionsDestroy(sampling);
347
+
348
+ _foreignProps.foreignPixelMap = nullptr;
349
+ DLOG(INFO) << "[svgForeignNode] DrawForeignPixelMap end";
350
+ }
351
+
288
352
  } // namespace svg
289
353
  } // namespace rnoh
@@ -36,6 +36,7 @@
36
36
  #include "utils/StringUtils.h"
37
37
  #include "utils/SvgAttributesParser.h"
38
38
  #include <glog/logging.h>
39
+ #include <multimedia/image_framework/image/pixelmap_native.h>
39
40
  #include <native_drawing/drawing_canvas.h>
40
41
  #include <native_drawing/drawing_rect.h>
41
42
  #include "utils/DynamicUtils.h"
@@ -43,6 +44,15 @@
43
44
  namespace rnoh {
44
45
  namespace svg {
45
46
 
47
+ struct ForeignProps {
48
+ OH_PixelmapNative *foreignPixelMap{nullptr};
49
+ float width;
50
+ float height;
51
+ float x;
52
+ float y;
53
+ };
54
+
55
+
46
56
  constexpr int INHERIT_TYPE = 2;
47
57
 
48
58
  class SvgNode : public std::enable_shared_from_this<SvgNode> {
@@ -275,6 +285,10 @@ public:
275
285
  double getCanvasHeight();
276
286
  double getCanvasDiagonal();
277
287
 
288
+ void SetForeignObject(ForeignProps foreignProps) {
289
+ _foreignPropsArray.emplace_back(foreignProps);
290
+ }
291
+
278
292
  protected:
279
293
  // override as need by derived class
280
294
  // called by function AppendChild
@@ -296,7 +310,7 @@ protected:
296
310
  std::optional<Gradient> GetGradient(const std::string &href);
297
311
 
298
312
  std::shared_ptr<PatternAttr> GetPatternAttr(const std::string &href);
299
-
313
+ void DrawForeignPixelMap(OH_Drawing_Canvas *canvas,ForeignProps _foreignProps);
300
314
  void InitNoneFlag() {
301
315
  hrefFill_ = false;
302
316
  hrefRender_ = false;
@@ -341,6 +355,8 @@ protected:
341
355
  Provide enough digits for the 128-bit IEEE quad (36 significant digits).
342
356
  */
343
357
  const double M_SQRT1_2l = 0.707106781186547524400844362104849039;
358
+
359
+ std::vector<ForeignProps> _foreignPropsArray;
344
360
  };
345
361
 
346
362
  } // namespace svg
@@ -1,40 +1,40 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
- * Use of this source code is governed by a MIT license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- #include "RNSVGFeBlendComponentInstance.h"
8
- #include "utils/DynamicUtils.h"
9
- #include <glog/logging.h>
10
-
11
- namespace facebook::react {
12
- // Forward declaration for toString function
13
- static inline std::string toString(const RNSVGFeBlendMode &value);
14
- }
15
-
16
- namespace rnoh {
17
- namespace svg {
18
-
19
- RNSVGFeBlendComponentInstance::RNSVGFeBlendComponentInstance(Context context)
20
- : RNSVGBaseComponentInstance(std::move(context)) {}
21
-
22
- void RNSVGFeBlendComponentInstance::onPropsChanged(SharedConcreteProps const &props) {
23
- if (props) {
24
- x_ = DynamicUtils::DynamicToString(props->x);
25
- y_ = DynamicUtils::DynamicToString(props->y);
26
- width_ = DynamicUtils::DynamicToString(props->width);
27
- height_ = DynamicUtils::DynamicToString(props->height);
28
- in_ = props->in1;
29
- in2_ = props->in2;
30
- mode_ = facebook::react::toString(props->mode);
31
- result_ = props->result;
32
- }
33
- }
34
-
35
- void RNSVGFeBlendComponentInstance::UpdateElementProps() {}
36
-
37
- void RNSVGFeBlendComponentInstance::extractAttributes() {}
38
-
39
- } // namespace svg
40
- } // namespace rnoh
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ #include "RNSVGFeBlendComponentInstance.h"
8
+ #include "utils/DynamicUtils.h"
9
+ #include <glog/logging.h>
10
+
11
+ namespace facebook::react {
12
+ // Forward declaration for toString function
13
+ static inline std::string toString(const RNSVGFeBlendMode &value);
14
+ }
15
+
16
+ namespace rnoh {
17
+ namespace svg {
18
+
19
+ RNSVGFeBlendComponentInstance::RNSVGFeBlendComponentInstance(Context context)
20
+ : RNSVGBaseComponentInstance(std::move(context)) {}
21
+
22
+ void RNSVGFeBlendComponentInstance::onPropsChanged(SharedConcreteProps const &props) {
23
+ if (props) {
24
+ x_ = DynamicUtils::DynamicToString(props->x);
25
+ y_ = DynamicUtils::DynamicToString(props->y);
26
+ width_ = DynamicUtils::DynamicToString(props->width);
27
+ height_ = DynamicUtils::DynamicToString(props->height);
28
+ in_ = props->in1;
29
+ in2_ = props->in2;
30
+ mode_ = facebook::react::toString(props->mode);
31
+ result_ = props->result;
32
+ }
33
+ }
34
+
35
+ void RNSVGFeBlendComponentInstance::UpdateElementProps() {}
36
+
37
+ void RNSVGFeBlendComponentInstance::extractAttributes() {}
38
+
39
+ } // namespace svg
40
+ } // namespace rnoh