@react-native-ohos/react-native-svg 15.12.1-rc.1
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/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/README.md +13 -0
- package/css/package.json +6 -0
- package/harmony/svg/BuildProfile.ets +17 -0
- package/harmony/svg/build-profile.json5 +9 -0
- package/harmony/svg/hvigorfile.ts +2 -0
- package/harmony/svg/index.ets +7 -0
- package/harmony/svg/oh-package.json5 +13 -0
- package/harmony/svg/src/main/cpp/Attribute.h +52 -0
- package/harmony/svg/src/main/cpp/CMakeLists.txt +32 -0
- package/harmony/svg/src/main/cpp/FallbackProps.h +0 -0
- package/harmony/svg/src/main/cpp/FontHolderBase.cpp +22 -0
- package/harmony/svg/src/main/cpp/FontHolderBase.h +54 -0
- package/harmony/svg/src/main/cpp/SVGPackage.cpp +135 -0
- package/harmony/svg/src/main/cpp/SVGPackage.h +153 -0
- package/harmony/svg/src/main/cpp/SvgArkUINode.cpp +75 -0
- package/harmony/svg/src/main/cpp/SvgArkUINode.h +45 -0
- package/harmony/svg/src/main/cpp/SvgBaseAttribute.h +83 -0
- package/harmony/svg/src/main/cpp/SvgCircle.cpp +29 -0
- package/harmony/svg/src/main/cpp/SvgCircle.h +29 -0
- package/harmony/svg/src/main/cpp/SvgClipPath.h +22 -0
- package/harmony/svg/src/main/cpp/SvgContext.cpp +56 -0
- package/harmony/svg/src/main/cpp/SvgContext.h +71 -0
- package/harmony/svg/src/main/cpp/SvgDefs.h +46 -0
- package/harmony/svg/src/main/cpp/SvgEllipse.cpp +32 -0
- package/harmony/svg/src/main/cpp/SvgEllipse.h +34 -0
- package/harmony/svg/src/main/cpp/SvgFilter.cpp +505 -0
- package/harmony/svg/src/main/cpp/SvgFilter.h +112 -0
- package/harmony/svg/src/main/cpp/SvgGradient.cpp +116 -0
- package/harmony/svg/src/main/cpp/SvgGradient.h +49 -0
- package/harmony/svg/src/main/cpp/SvgGraphic.cpp +553 -0
- package/harmony/svg/src/main/cpp/SvgGraphic.h +77 -0
- package/harmony/svg/src/main/cpp/SvgGroup.cpp +86 -0
- package/harmony/svg/src/main/cpp/SvgGroup.h +41 -0
- package/harmony/svg/src/main/cpp/SvgHost.cpp +27 -0
- package/harmony/svg/src/main/cpp/SvgHost.h +38 -0
- package/harmony/svg/src/main/cpp/SvgImage.cpp +168 -0
- package/harmony/svg/src/main/cpp/SvgImage.h +52 -0
- package/harmony/svg/src/main/cpp/SvgLine.cpp +28 -0
- package/harmony/svg/src/main/cpp/SvgLine.h +32 -0
- package/harmony/svg/src/main/cpp/SvgMarker.cpp +61 -0
- package/harmony/svg/src/main/cpp/SvgMarker.h +86 -0
- package/harmony/svg/src/main/cpp/SvgMask.cpp +72 -0
- package/harmony/svg/src/main/cpp/SvgMask.h +68 -0
- package/harmony/svg/src/main/cpp/SvgNode.cpp +289 -0
- package/harmony/svg/src/main/cpp/SvgNode.h +347 -0
- package/harmony/svg/src/main/cpp/SvgPath.cpp +42 -0
- package/harmony/svg/src/main/cpp/SvgPath.h +29 -0
- package/harmony/svg/src/main/cpp/SvgPattern.cpp +77 -0
- package/harmony/svg/src/main/cpp/SvgPattern.h +64 -0
- package/harmony/svg/src/main/cpp/SvgQuote.h +87 -0
- package/harmony/svg/src/main/cpp/SvgRect.cpp +58 -0
- package/harmony/svg/src/main/cpp/SvgRect.h +33 -0
- package/harmony/svg/src/main/cpp/SvgSvg.cpp +83 -0
- package/harmony/svg/src/main/cpp/SvgSvg.h +52 -0
- package/harmony/svg/src/main/cpp/SvgSymbol.cpp +25 -0
- package/harmony/svg/src/main/cpp/SvgSymbol.h +37 -0
- package/harmony/svg/src/main/cpp/SvgTSpan.cpp +501 -0
- package/harmony/svg/src/main/cpp/SvgTSpan.h +101 -0
- package/harmony/svg/src/main/cpp/SvgText.cpp +48 -0
- package/harmony/svg/src/main/cpp/SvgText.h +29 -0
- package/harmony/svg/src/main/cpp/SvgTextPath.cpp +35 -0
- package/harmony/svg/src/main/cpp/SvgTextPath.h +51 -0
- package/harmony/svg/src/main/cpp/SvgUse.cpp +65 -0
- package/harmony/svg/src/main/cpp/SvgUse.h +46 -0
- package/harmony/svg/src/main/cpp/SvgViewManager.cpp +36 -0
- package/harmony/svg/src/main/cpp/SvgViewManager.h +37 -0
- package/harmony/svg/src/main/cpp/TextBase.cpp +20 -0
- package/harmony/svg/src/main/cpp/TextBase.h +114 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGBaseComponentInstance.h +212 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGCircleComponentInstance.cpp +31 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGCircleComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGClipPathComponentInstance.cpp +23 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGClipPathComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGDefsComponentInstance.cpp +23 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGDefsComponentInstance.h +28 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGEllipseComponentInstance.cpp +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGEllipseComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeBlendComponentInstance.cpp +40 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeBlendComponentInstance.h +48 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeColorMatrixComponentInstance.cpp +33 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeColorMatrixComponentInstance.h +48 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeCompositeComponentInstance.cpp +39 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeCompositeComponentInstance.h +55 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeFloodComponentInstance.cpp +33 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeFloodComponentInstance.h +49 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeGaussianBlurComponentInstance.cpp +34 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeGaussianBlurComponentInstance.h +48 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeOffsetComponentInstance.cpp +35 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFeOffsetComponentInstance.h +46 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFilterComponentInstance.cpp +199 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGFilterComponentInstance.h +48 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGGroupComponentInstance.cpp +32 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGGroupComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGImageComponentInstance.cpp +100 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGImageComponentInstance.h +43 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGLineComponentInstance.cpp +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGLineComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGLinearGradientComponentInstance.cpp +30 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGLinearGradientComponentInstance.h +28 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGMarkerComponentInstance.cpp +35 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGMarkerComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGMaskComponentInstance.cpp +30 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGMaskComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGPathComponentInstance.cpp +33 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGPathComponentInstance.h +29 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGPatternComponentInstance.cpp +40 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGPatternComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGRadialGradientComponentInstance.cpp +32 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGRadialGradientComponentInstance.h +28 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGRectComponentInstance.cpp +36 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGRectComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGSvgViewComponentInstance.cpp +86 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGSvgViewComponentInstance.h +47 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGSymbolComponentInstance.cpp +30 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGSymbolComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTSpanComponentInstance.cpp +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTSpanComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTextComponentInstance.cpp +25 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTextComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTextPathComponentInstance.cpp +32 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGTextPathComponentInstance.h +27 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGUseComponentInstance.cpp +32 -0
- package/harmony/svg/src/main/cpp/componentInstances/RNSVGUseComponentInstance.h +32 -0
- package/harmony/svg/src/main/cpp/downloadUtils/HttpTaskProcessor.cpp +207 -0
- package/harmony/svg/src/main/cpp/downloadUtils/HttpTaskProcessor.h +88 -0
- package/harmony/svg/src/main/cpp/downloadUtils/ImageSourceResolver.cpp +106 -0
- package/harmony/svg/src/main/cpp/downloadUtils/ImageSourceResolver.h +97 -0
- package/harmony/svg/src/main/cpp/downloadUtils/LRUCache.h +98 -0
- package/harmony/svg/src/main/cpp/drawing/Brush.cpp +50 -0
- package/harmony/svg/src/main/cpp/drawing/Brush.h +52 -0
- package/harmony/svg/src/main/cpp/drawing/GlyPathBag.cpp +20 -0
- package/harmony/svg/src/main/cpp/drawing/GlyPathBag.h +31 -0
- package/harmony/svg/src/main/cpp/drawing/Matrix.cpp +100 -0
- package/harmony/svg/src/main/cpp/drawing/Matrix.h +68 -0
- package/harmony/svg/src/main/cpp/drawing/Path.cpp +173 -0
- package/harmony/svg/src/main/cpp/drawing/Path.h +127 -0
- package/harmony/svg/src/main/cpp/drawing/Pen.cpp +57 -0
- package/harmony/svg/src/main/cpp/drawing/Pen.h +59 -0
- package/harmony/svg/src/main/cpp/drawing/Rect.cpp +47 -0
- package/harmony/svg/src/main/cpp/drawing/Rect.h +56 -0
- package/harmony/svg/src/main/cpp/drawing/RoundRect.cpp +24 -0
- package/harmony/svg/src/main/cpp/drawing/RoundRect.h +39 -0
- package/harmony/svg/src/main/cpp/drawing/ShaderEffect.cpp +37 -0
- package/harmony/svg/src/main/cpp/drawing/ShaderEffect.h +51 -0
- package/harmony/svg/src/main/cpp/drawing/TextStyle.cpp +49 -0
- package/harmony/svg/src/main/cpp/drawing/TextStyle.h +41 -0
- package/harmony/svg/src/main/cpp/drawing/Typography.cpp +9 -0
- package/harmony/svg/src/main/cpp/drawing/Typography.h +25 -0
- package/harmony/svg/src/main/cpp/drawing/TypographyStyle.cpp +31 -0
- package/harmony/svg/src/main/cpp/drawing/TypographyStyle.h +41 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGCircleJSIBinder.h +54 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGClipPathJSIBinder.h +54 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGDefsJSIBinder.h +38 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGEllipseJSIBinder.h +55 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeBlendJSIBinder.h +26 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeColorMatrixJSIBinder.h +26 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeCompositeJSIBinder.h +30 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeFloodJSIBinder.h +26 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeGaussianBlurJSIBinder.h +27 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFeOffsetJSIBinder.h +26 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGFilterJSIBinder.h +44 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGForeignObjectJSIBinder.h +57 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGGroupJSIBinder.h +54 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGImageJSIBinder.h +58 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGLineJSIBinder.h +55 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGLinearGradientJSIBinder.h +45 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGMarkerJSIBinder.h +66 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGMaskJSIBinder.h +60 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGPathJSIBinder.h +52 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGPatternJSIBinder.h +67 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGRadialGradientJSIBinder.h +47 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGRectJSIBinder.h +57 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGSvgViewAndroidJSIBinder.h +67 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGSvgViewJSIBinder.h +36 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGSymbolJSIBinder.h +60 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGTSpanJSIBinder.h +66 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGTextJSIBinder.h +65 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGTextPathJSIBinder.h +71 -0
- package/harmony/svg/src/main/cpp/generated/RNOH/generated/components/RNSVGUseJSIBinder.h +56 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/ComponentDescriptors.h +48 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/EventEmitters.cpp +20 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/EventEmitters.h +253 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/Props.cpp +977 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/Props.h +1280 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/ShadowNodes.cpp +45 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/ShadowNodes.h +331 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/States.cpp +18 -0
- package/harmony/svg/src/main/cpp/generated/react/renderer/components/react_native_svg/States.h +441 -0
- package/harmony/svg/src/main/cpp/properties/Color.cpp +458 -0
- package/harmony/svg/src/main/cpp/properties/Color.h +144 -0
- package/harmony/svg/src/main/cpp/properties/Decoration.cpp +41 -0
- package/harmony/svg/src/main/cpp/properties/Decoration.h +483 -0
- package/harmony/svg/src/main/cpp/properties/Dimension.cpp +64 -0
- package/harmony/svg/src/main/cpp/properties/Dimension.h +243 -0
- package/harmony/svg/src/main/cpp/properties/Font.cpp +166 -0
- package/harmony/svg/src/main/cpp/properties/Font.h +163 -0
- package/harmony/svg/src/main/cpp/properties/Offset.h +119 -0
- package/harmony/svg/src/main/cpp/properties/PaintState.h +240 -0
- package/harmony/svg/src/main/cpp/properties/Rect.h +423 -0
- package/harmony/svg/src/main/cpp/properties/Size.h +246 -0
- package/harmony/svg/src/main/cpp/properties/SvgPaintState.h +452 -0
- package/harmony/svg/src/main/cpp/properties/TextProperties.cpp +91 -0
- package/harmony/svg/src/main/cpp/properties/TextProperties.h +56 -0
- package/harmony/svg/src/main/cpp/properties/ViewBox.h +108 -0
- package/harmony/svg/src/main/cpp/svgImage/RNSVGImageComponentDescriptor.h +41 -0
- package/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.cpp +62 -0
- package/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.h +63 -0
- package/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.cpp +17 -0
- package/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.h +58 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGImageModule.cpp +54 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGImageModule.h +32 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.cpp +101 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.h +32 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGSvgViewModule.cpp +71 -0
- package/harmony/svg/src/main/cpp/turboModules/RNSVGSvgViewModule.h +32 -0
- package/harmony/svg/src/main/cpp/utils/DynamicUtils.h +55 -0
- package/harmony/svg/src/main/cpp/utils/FilterManager.h +190 -0
- package/harmony/svg/src/main/cpp/utils/GlyphContext.cpp +221 -0
- package/harmony/svg/src/main/cpp/utils/GlyphContext.h +106 -0
- package/harmony/svg/src/main/cpp/utils/LinearMap.h +69 -0
- package/harmony/svg/src/main/cpp/utils/PathParserUtils.cpp +591 -0
- package/harmony/svg/src/main/cpp/utils/PathParserUtils.h +93 -0
- package/harmony/svg/src/main/cpp/utils/StringUtils.cpp +134 -0
- package/harmony/svg/src/main/cpp/utils/StringUtils.h +644 -0
- package/harmony/svg/src/main/cpp/utils/SvgAttributesParser.cpp +239 -0
- package/harmony/svg/src/main/cpp/utils/SvgAttributesParser.h +277 -0
- package/harmony/svg/src/main/cpp/utils/SvgMarkerPositionUtils.h +200 -0
- package/harmony/svg/src/main/cpp/utils/SvgUtils.h +176 -0
- package/harmony/svg/src/main/cpp/utils/TextPathHelper.cpp +94 -0
- package/harmony/svg/src/main/cpp/utils/TextPathHelper.h +61 -0
- package/harmony/svg/src/main/ets/RNSVGImageModule.ts +21 -0
- package/harmony/svg/src/main/ets/RNSVGRenderableModule.ts +16 -0
- package/harmony/svg/src/main/ets/RNSVGSvgViewModule.ts +18 -0
- package/harmony/svg/src/main/ets/SvgPackage.ts +58 -0
- package/harmony/svg/src/main/module.json5 +7 -0
- package/harmony/svg/src/main/resources/base/element/string.json +8 -0
- package/harmony/svg/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/svg/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/svg/ts.ts +8 -0
- package/harmony/svg.har +0 -0
- package/lib/commonjs/css/index.js +55 -0
- package/lib/commonjs/css/index.js.map +1 -0
- package/lib/commonjs/index.js +26 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/css/index.js +4 -0
- package/lib/module/css/index.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/babel.config.d.ts +8 -0
- package/lib/typescript/babel.config.d.ts.map +1 -0
- package/lib/typescript/example/babel.config.d.ts +3 -0
- package/lib/typescript/example/babel.config.d.ts.map +1 -0
- package/lib/typescript/example/contexts.d.ts +3 -0
- package/lib/typescript/example/contexts.d.ts.map +1 -0
- package/lib/typescript/example/harmony/entry/hvigorfile.d.ts +2 -0
- package/lib/typescript/example/harmony/entry/hvigorfile.d.ts.map +1 -0
- package/lib/typescript/example/harmony/hvigorfile.d.ts +2 -0
- package/lib/typescript/example/harmony/hvigorfile.d.ts.map +1 -0
- package/lib/typescript/example/index.d.ts +2 -0
- package/lib/typescript/example/index.d.ts.map +1 -0
- package/lib/typescript/example/jest.config.d.ts +3 -0
- package/lib/typescript/example/jest.config.d.ts.map +1 -0
- package/lib/typescript/example/metro.config.d.ts +3 -0
- package/lib/typescript/example/metro.config.d.ts.map +1 -0
- package/lib/typescript/example/react-native.config.d.ts +3 -0
- package/lib/typescript/example/react-native.config.d.ts.map +1 -0
- package/lib/typescript/example/scripts/create-build-profile.d.ts +2 -0
- package/lib/typescript/example/scripts/create-build-profile.d.ts.map +1 -0
- package/lib/typescript/example/src/index.d.ts +3 -0
- package/lib/typescript/example/src/index.d.ts.map +1 -0
- package/lib/typescript/src/css/index.d.ts +4 -0
- package/lib/typescript/src/css/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +54 -0
- package/src/css/index.tsx +20 -0
- package/src/index.tsx +3 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,591 @@
|
|
|
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
|
+
* This file incorporates from the react-native-svg project, licensed under
|
|
7
|
+
* the MIT License. Specifically:
|
|
8
|
+
* - [software-mansion/react-native-svg] (https://github.com/software-mansion/react-native-svg)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "PathParserUtils.h"
|
|
12
|
+
#include <cmath>
|
|
13
|
+
#include <stdexcept>
|
|
14
|
+
#include <cctype>
|
|
15
|
+
#include <glog/logging.h>
|
|
16
|
+
|
|
17
|
+
namespace rnoh {
|
|
18
|
+
namespace svg {
|
|
19
|
+
|
|
20
|
+
drawing::Path PathParserUtils::parse(std::string d) {
|
|
21
|
+
mPath = drawing::Path();
|
|
22
|
+
elements.clear();
|
|
23
|
+
if (d.empty()) {
|
|
24
|
+
return mPath;
|
|
25
|
+
}
|
|
26
|
+
char prev_cmd = ' ';
|
|
27
|
+
l = d.length();
|
|
28
|
+
s = d;
|
|
29
|
+
i = 0;
|
|
30
|
+
|
|
31
|
+
mPenX = 0.0;
|
|
32
|
+
mPenY = 0.0;
|
|
33
|
+
mPivotX = 0.0;
|
|
34
|
+
mPivotY = 0.0;
|
|
35
|
+
mPenDownX = 0.0;
|
|
36
|
+
mPenDownY = 0.0;
|
|
37
|
+
mPenDown = false;
|
|
38
|
+
|
|
39
|
+
while (i < l) {
|
|
40
|
+
skip_spaces();
|
|
41
|
+
|
|
42
|
+
if (i >= l) {
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
bool has_prev_cmd = prev_cmd != ' ';
|
|
47
|
+
char first_char = s[i];
|
|
48
|
+
|
|
49
|
+
if (!has_prev_cmd && first_char != 'M' && first_char != 'm') {
|
|
50
|
+
// The first segment must be a MoveTo.
|
|
51
|
+
throw std::runtime_error("Unexpected character '" + std::string(1, first_char) +
|
|
52
|
+
"' (i=" + std::to_string(i) + ", s=" + s + ")");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// TODO: simplify
|
|
56
|
+
bool is_implicit_move_to;
|
|
57
|
+
char cmd;
|
|
58
|
+
if (is_cmd(first_char)) {
|
|
59
|
+
is_implicit_move_to = false;
|
|
60
|
+
cmd = first_char;
|
|
61
|
+
i += 1;
|
|
62
|
+
} else if (is_number_start(first_char) && has_prev_cmd) {
|
|
63
|
+
if (prev_cmd == 'Z' || prev_cmd == 'z') {
|
|
64
|
+
// ClosePath cannot be followed by a number.
|
|
65
|
+
throw std::runtime_error("Unexpected number after 'z' (s=" + s + ")");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (prev_cmd == 'M' || prev_cmd == 'm') {
|
|
69
|
+
// 'If a moveto is followed by multiple pairs of coordinates,
|
|
70
|
+
// the subsequent pairs are treated as implicit lineto commands.'
|
|
71
|
+
// So we parse them as LineTo.
|
|
72
|
+
is_implicit_move_to = true;
|
|
73
|
+
cmd = is_absolute(prev_cmd) ? 'L' : 'l';
|
|
74
|
+
} else {
|
|
75
|
+
is_implicit_move_to = false;
|
|
76
|
+
cmd = prev_cmd;
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
throw std::runtime_error("Unexpected character '" + std::string(1, first_char) +
|
|
80
|
+
"' (i=" + std::to_string(i) + ", s=" + s + ")");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
bool absolute = is_absolute(cmd);
|
|
84
|
+
switch (cmd) {
|
|
85
|
+
case 'm': {
|
|
86
|
+
move(parse_list_number(), parse_list_number());
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case 'M': {
|
|
90
|
+
moveTo(parse_list_number(), parse_list_number());
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case 'l': {
|
|
94
|
+
line(parse_list_number(), parse_list_number());
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case 'L': {
|
|
98
|
+
lineTo(parse_list_number(), parse_list_number());
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case 'h': {
|
|
102
|
+
line(parse_list_number(), 0);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case 'H': {
|
|
106
|
+
lineTo(parse_list_number(), mPenY);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'v': {
|
|
110
|
+
line(0, parse_list_number());
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case 'V': {
|
|
114
|
+
lineTo(mPenX, parse_list_number());
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'c': {
|
|
118
|
+
curve(parse_list_number(), parse_list_number(), parse_list_number(), parse_list_number(),
|
|
119
|
+
parse_list_number(), parse_list_number());
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 'C': {
|
|
123
|
+
curveTo(parse_list_number(), parse_list_number(), parse_list_number(), parse_list_number(),
|
|
124
|
+
parse_list_number(), parse_list_number());
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case 's': {
|
|
128
|
+
smoothCurve(parse_list_number(), parse_list_number(), parse_list_number(), parse_list_number());
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case 'S': {
|
|
132
|
+
smoothCurveTo(parse_list_number(), parse_list_number(), parse_list_number(), parse_list_number());
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'q': {
|
|
136
|
+
quadraticBezierCurve(parse_list_number(), parse_list_number(), parse_list_number(), parse_list_number());
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case 'Q': {
|
|
140
|
+
quadraticBezierCurveTo(parse_list_number(), parse_list_number(), parse_list_number(), parse_list_number());
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case 't': {
|
|
144
|
+
smoothQuadraticBezierCurve(parse_list_number(), parse_list_number());
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
case 'T': {
|
|
148
|
+
smoothQuadraticBezierCurveTo(parse_list_number(), parse_list_number());
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case 'a': {
|
|
152
|
+
arc(parse_list_number(), parse_list_number(), parse_list_number(), parse_flag(), parse_flag(),
|
|
153
|
+
parse_list_number(), parse_list_number());
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case 'A': {
|
|
157
|
+
arcTo(parse_list_number(), parse_list_number(), parse_list_number(), parse_flag(), parse_flag(),
|
|
158
|
+
parse_list_number(), parse_list_number());
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
case 'z':
|
|
162
|
+
case 'Z': {
|
|
163
|
+
close();
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
default: {
|
|
167
|
+
throw std::runtime_error("Unexpected command '" + std::string(1, cmd) + "' (s=" + s + ")");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (is_implicit_move_to) {
|
|
171
|
+
if (absolute) {
|
|
172
|
+
prev_cmd = 'M';
|
|
173
|
+
} else {
|
|
174
|
+
prev_cmd = 'm';
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
prev_cmd = cmd;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return mPath;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
void PathParserUtils::move(float x, float y) { moveTo(x + mPenX, y + mPenY); }
|
|
184
|
+
|
|
185
|
+
void PathParserUtils::moveTo(float x, float y) {
|
|
186
|
+
// LOG(INFO) << "[Svg PathParserUtils] move x: " << x << " y: " << y;
|
|
187
|
+
mPenDownX = mPivotX = mPenX = x;
|
|
188
|
+
mPenDownY = mPivotY = mPenY = y;
|
|
189
|
+
mPath.MoveTo(x * mScale, y * mScale);
|
|
190
|
+
elements.push_back(PathElement(ElementType::kCGPathElementMoveToPoint, {Point(x, y)}));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
void PathParserUtils::line(float x, float y) { lineTo(x + mPenX, y + mPenY); }
|
|
194
|
+
|
|
195
|
+
void PathParserUtils::lineTo(float x, float y) {
|
|
196
|
+
// LOG(INFO) << "[Svg PathParserUtils] line x: " << x << " y: " << y;
|
|
197
|
+
setPenDown();
|
|
198
|
+
mPivotX = mPenX = x;
|
|
199
|
+
mPivotY = mPenY = y;
|
|
200
|
+
mPath.LineTo(x * mScale, y * mScale);
|
|
201
|
+
elements.push_back(PathElement(ElementType::kCGPathElementAddLineToPoint, {Point(x, y)}));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
void PathParserUtils::curve(float c1x, float c1y, float c2x, float c2y, float ex, float ey) {
|
|
205
|
+
curveTo(c1x + mPenX, c1y + mPenY, c2x + mPenX, c2y + mPenY, ex + mPenX, ey + mPenY);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
void PathParserUtils::curveTo(float c1x, float c1y, float c2x, float c2y, float ex, float ey) {
|
|
209
|
+
// LOG(INFO) << "[Svg PathParserUtils] curve c1x: " << c1x << " c1y: " << c1y << "ex: " << ex << " ey: " << ey;
|
|
210
|
+
mPivotX = c2x;
|
|
211
|
+
mPivotY = c2y;
|
|
212
|
+
cubicTo(c1x, c1y, c2x, c2y, ex, ey);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
void PathParserUtils::cubicTo(float c1x, float c1y, float c2x, float c2y, float ex, float ey) {
|
|
216
|
+
setPenDown();
|
|
217
|
+
mPenX = ex;
|
|
218
|
+
mPenY = ey;
|
|
219
|
+
mPath.CubicTo(c1x * mScale, c1y * mScale, c2x * mScale, c2y * mScale, ex * mScale, ey * mScale);
|
|
220
|
+
elements.push_back(
|
|
221
|
+
PathElement(ElementType::kCGPathElementAddCurveToPoint, {Point(c1x, c1y), Point(c2x, c2y), Point(ex, ey)}));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
void PathParserUtils::smoothCurve(float c1x, float c1y, float ex, float ey) {
|
|
225
|
+
smoothCurveTo(c1x + mPenX, c1y + mPenY, ex + mPenX, ey + mPenY);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
void PathParserUtils::smoothCurveTo(float c1x, float c1y, float ex, float ey) {
|
|
229
|
+
float c2x = c1x;
|
|
230
|
+
float c2y = c1y;
|
|
231
|
+
c1x = (mPenX * 2) - mPivotX;
|
|
232
|
+
c1y = (mPenY * 2) - mPivotY;
|
|
233
|
+
mPivotX = c2x;
|
|
234
|
+
mPivotY = c2y;
|
|
235
|
+
cubicTo(c1x, c1y, c2x, c2y, ex, ey);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
void PathParserUtils::quadraticBezierCurve(float c1x, float c1y, float c2x, float c2y) {
|
|
239
|
+
quadraticBezierCurveTo(c1x + mPenX, c1y + mPenY, c2x + mPenX, c2y + mPenY);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
void PathParserUtils::quadraticBezierCurveTo(float c1x, float c1y, float c2x, float c2y) {
|
|
243
|
+
constexpr float CONTROL_POINT_WEIGHT = 2.0f;
|
|
244
|
+
constexpr float NORMALIZATION_FACTOR = 3.0f;
|
|
245
|
+
|
|
246
|
+
mPivotX = c1x;
|
|
247
|
+
mPivotY = c1y;
|
|
248
|
+
|
|
249
|
+
float ex = c2x;
|
|
250
|
+
float ey = c2y;
|
|
251
|
+
|
|
252
|
+
c2x = (ex + c1x * CONTROL_POINT_WEIGHT) / NORMALIZATION_FACTOR;
|
|
253
|
+
c2y = (ey + c1y * CONTROL_POINT_WEIGHT) / NORMALIZATION_FACTOR;
|
|
254
|
+
c1x = (mPenX + c1x * CONTROL_POINT_WEIGHT) / NORMALIZATION_FACTOR;
|
|
255
|
+
c1y = (mPenY + c1y * CONTROL_POINT_WEIGHT) / NORMALIZATION_FACTOR;
|
|
256
|
+
|
|
257
|
+
cubicTo(c1x, c1y, c2x, c2y, ex, ey);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
void PathParserUtils::smoothQuadraticBezierCurve(float c1x, float c1y) {
|
|
261
|
+
smoothQuadraticBezierCurveTo(c1x + mPenX, c1y + mPenY);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
void PathParserUtils::smoothQuadraticBezierCurveTo(float c1x, float c1y) {
|
|
265
|
+
float c2x = c1x;
|
|
266
|
+
float c2y = c1y;
|
|
267
|
+
c1x = (mPenX * 2) - mPivotX;
|
|
268
|
+
c1y = (mPenY * 2) - mPivotY;
|
|
269
|
+
quadraticBezierCurveTo(c1x, c1y, c2x, c2y);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
void PathParserUtils::arc(float rx, float ry, float rotation, bool outer, bool clockwise, float x, float y) {
|
|
273
|
+
arcTo(rx, ry, rotation, outer, clockwise, x + mPenX, y + mPenY);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
void PathParserUtils::arcTo(float rx, float ry, float rotation, bool outer, bool clockwise, float x, float y) {
|
|
277
|
+
float tX = mPenX;
|
|
278
|
+
float tY = mPenY;
|
|
279
|
+
|
|
280
|
+
ry = std::abs(ry == 0 ? (rx == 0 ? (y - tY) : rx) : ry);
|
|
281
|
+
rx = std::abs(rx == 0 ? (x - tX) : rx);
|
|
282
|
+
|
|
283
|
+
if (rx == 0 || ry == 0 || (x == tX && y == tY)) {
|
|
284
|
+
lineTo(x, y);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
float rad = static_cast<float>(std::atan2(y - tY, x - tX));
|
|
289
|
+
float cos = std::cos(rad);
|
|
290
|
+
float sin = std::sin(rad);
|
|
291
|
+
x -= tX;
|
|
292
|
+
y -= tY;
|
|
293
|
+
|
|
294
|
+
// Ellipse Center
|
|
295
|
+
float cx = cos * x / 2 + sin * y / 2;
|
|
296
|
+
float cy = -sin * x / 2 + cos * y / 2;
|
|
297
|
+
float rxry = rx * rx * ry * ry;
|
|
298
|
+
float rycx = ry * ry * cx * cx;
|
|
299
|
+
float rxcy = rx * rx * cy * cy;
|
|
300
|
+
float a = rxry - rxcy - rycx;
|
|
301
|
+
|
|
302
|
+
if (a < 0) {
|
|
303
|
+
a = static_cast<float>(std::sqrt(1 - a / rxry));
|
|
304
|
+
rx *= a;
|
|
305
|
+
ry *= a;
|
|
306
|
+
cx = x / 2;
|
|
307
|
+
cy = y / 2;
|
|
308
|
+
} else {
|
|
309
|
+
a = static_cast<float>(std::sqrt(a / (rxcy + rycx)));
|
|
310
|
+
|
|
311
|
+
if (outer == clockwise) {
|
|
312
|
+
a = -a;
|
|
313
|
+
}
|
|
314
|
+
float cxd = -a * cy * rx / ry;
|
|
315
|
+
float cyd = a * cx * ry / rx;
|
|
316
|
+
cx = cos * cxd - sin * cyd + x / 2;
|
|
317
|
+
cy = sin * cxd + cos * cyd + y / 2;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Rotation + Scale Transform
|
|
321
|
+
float xx = cos / rx;
|
|
322
|
+
float yx = sin / rx;
|
|
323
|
+
float xy = -sin / ry;
|
|
324
|
+
float yy = cos / ry;
|
|
325
|
+
|
|
326
|
+
// Start and End Angle
|
|
327
|
+
float sa = static_cast<float>(std::atan2(xy * -cx + yy * -cy, xx * -cx + yx * -cy));
|
|
328
|
+
float ea = static_cast<float>(std::atan2(xy * (x - cx) + yy * (y - cy), xx * (x - cx) + yx * (y - cy)));
|
|
329
|
+
|
|
330
|
+
cx += tX;
|
|
331
|
+
cy += tY;
|
|
332
|
+
x += tX;
|
|
333
|
+
y += tY;
|
|
334
|
+
|
|
335
|
+
setPenDown();
|
|
336
|
+
|
|
337
|
+
mPenX = mPivotX = x;
|
|
338
|
+
mPenY = mPivotY = y;
|
|
339
|
+
|
|
340
|
+
if (rx != ry || rad != 0.0f) {
|
|
341
|
+
arcToBezier(cx, cy, rx, ry, sa, ea, clockwise, rad);
|
|
342
|
+
} else {
|
|
343
|
+
float start = static_cast<float>(sa * 180.0 / M_PI);
|
|
344
|
+
float end = static_cast<float>(ea * 180.0 / M_PI);
|
|
345
|
+
float sweep = std::fabs(std::fmod((start - end), 360.0f));
|
|
346
|
+
|
|
347
|
+
if (outer) {
|
|
348
|
+
if (sweep < 180) {
|
|
349
|
+
sweep = 360 - sweep;
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
if (sweep > 180) {
|
|
353
|
+
sweep = 360 - sweep;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (!clockwise) {
|
|
358
|
+
sweep = -sweep;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
mPath.ArcTo((cx - rx) * mScale, (cy - rx) * mScale, (cx + rx) * mScale, (cy + rx) * mScale, start, sweep);
|
|
362
|
+
elements.push_back(PathElement(ElementType::kCGPathElementAddQuadCurveToPoint, {Point(x, y)}));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
void PathParserUtils::close() {
|
|
367
|
+
if (mPenDown) {
|
|
368
|
+
mPenX = mPenDownX;
|
|
369
|
+
mPenY = mPenDownY;
|
|
370
|
+
mPenDown = false;
|
|
371
|
+
mPath.Close();
|
|
372
|
+
elements.push_back(PathElement(ElementType::kCGPathElementCloseSubpath, {{mPenX, mPenY}}));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
void PathParserUtils::arcToBezier(float cx, float cy, float rx, float ry, float sa, float ea, bool clockwise,
|
|
377
|
+
float rad) {
|
|
378
|
+
// Inverse Rotation + Scale Transform
|
|
379
|
+
float cos = std::cos(rad);
|
|
380
|
+
float sin = std::sin(rad);
|
|
381
|
+
float xx = cos * rx;
|
|
382
|
+
float yx = -sin * ry;
|
|
383
|
+
float xy = sin * rx;
|
|
384
|
+
float yy = cos * ry;
|
|
385
|
+
|
|
386
|
+
// Bezier Curve Approximation
|
|
387
|
+
float arc = ea - sa;
|
|
388
|
+
if (arc < 0 && clockwise) {
|
|
389
|
+
arc += M_PI * 2;
|
|
390
|
+
} else if (arc > 0 && !clockwise) {
|
|
391
|
+
arc -= M_PI * 2;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
int n = static_cast<int>(std::ceil(std::abs(roundVal(arc / (M_PI / 2)))));
|
|
395
|
+
|
|
396
|
+
float step = arc / n;
|
|
397
|
+
float k = (4.0f / 3.0f) * std::tan(step / 4);
|
|
398
|
+
|
|
399
|
+
float x = std::cos(sa);
|
|
400
|
+
float y = std::sin(sa);
|
|
401
|
+
|
|
402
|
+
for (int index = 0; index < n; index++) {
|
|
403
|
+
float cp1x = x - k * y;
|
|
404
|
+
float cp1y = y + k * x;
|
|
405
|
+
|
|
406
|
+
sa += step;
|
|
407
|
+
x = std::cos(sa);
|
|
408
|
+
y = std::sin(sa);
|
|
409
|
+
|
|
410
|
+
float cp2x = x + k * y;
|
|
411
|
+
float cp2y = y - k * x;
|
|
412
|
+
|
|
413
|
+
float c1x = (cx + xx * cp1x + yx * cp1y);
|
|
414
|
+
float c1y = (cy + xy * cp1x + yy * cp1y);
|
|
415
|
+
float c2x = (cx + xx * cp2x + yx * cp2y);
|
|
416
|
+
float c2y = (cy + xy * cp2x + yy * cp2y);
|
|
417
|
+
float ex = (cx + xx * x + yx * y);
|
|
418
|
+
float ey = (cy + xy * x + yy * y);
|
|
419
|
+
|
|
420
|
+
mPath.CubicTo(c1x * mScale, c1y * mScale, c2x * mScale, c2y * mScale, ex * mScale, ey * mScale);
|
|
421
|
+
elements.push_back(
|
|
422
|
+
PathElement(ElementType::kCGPathElementMoveToPoint, {Point(c1x, c1y), Point(c2x, c2y), Point(ex, ey)}));
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
void PathParserUtils::setPenDown() {
|
|
427
|
+
if (!mPenDown) {
|
|
428
|
+
mPenDownX = mPenX;
|
|
429
|
+
mPenDownY = mPenY;
|
|
430
|
+
mPenDown = true;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
double PathParserUtils::roundVal(double val) {
|
|
435
|
+
double multiplier = pow(10, 4);
|
|
436
|
+
return round(val * multiplier) / multiplier;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
void PathParserUtils::skip_spaces() {
|
|
440
|
+
while (i < l && std::isspace(s[i]))
|
|
441
|
+
i++;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
bool PathParserUtils::is_cmd(char c) {
|
|
445
|
+
switch (c) {
|
|
446
|
+
case 'M':
|
|
447
|
+
case 'm':
|
|
448
|
+
case 'Z':
|
|
449
|
+
case 'z':
|
|
450
|
+
case 'L':
|
|
451
|
+
case 'l':
|
|
452
|
+
case 'H':
|
|
453
|
+
case 'h':
|
|
454
|
+
case 'V':
|
|
455
|
+
case 'v':
|
|
456
|
+
case 'C':
|
|
457
|
+
case 'c':
|
|
458
|
+
case 'S':
|
|
459
|
+
case 's':
|
|
460
|
+
case 'Q':
|
|
461
|
+
case 'q':
|
|
462
|
+
case 'T':
|
|
463
|
+
case 't':
|
|
464
|
+
case 'A':
|
|
465
|
+
case 'a':
|
|
466
|
+
return true;
|
|
467
|
+
}
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
bool PathParserUtils::is_number_start(char c) { return (c >= '0' && c <= '9') || c == '.' || c == '-' || c == '+'; }
|
|
472
|
+
|
|
473
|
+
bool PathParserUtils::is_absolute(char c) { return std::isupper(c); }
|
|
474
|
+
|
|
475
|
+
bool PathParserUtils::parse_flag() {
|
|
476
|
+
skip_spaces();
|
|
477
|
+
|
|
478
|
+
char c = s[i];
|
|
479
|
+
switch (c) {
|
|
480
|
+
case '0':
|
|
481
|
+
case '1': {
|
|
482
|
+
i += 1;
|
|
483
|
+
if (i < l && s[i] == ',') {
|
|
484
|
+
i += 1;
|
|
485
|
+
}
|
|
486
|
+
skip_spaces();
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
default:
|
|
490
|
+
throw std::runtime_error("Unexpected flag '" + std::string(1, c) + "' (i=" + std::to_string(i) + ", s=" + s +
|
|
491
|
+
")");
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
return c == '1';
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
float PathParserUtils::parse_list_number() {
|
|
498
|
+
if (i == l) {
|
|
499
|
+
throw std::runtime_error("Unexpected end s=(" + s + ")");
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
float n = parse_number();
|
|
503
|
+
skip_spaces();
|
|
504
|
+
parse_list_separator();
|
|
505
|
+
|
|
506
|
+
return n;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
float PathParserUtils::parse_number() {
|
|
510
|
+
// Strip off leading whitespaces.
|
|
511
|
+
skip_spaces();
|
|
512
|
+
|
|
513
|
+
if (i == l) {
|
|
514
|
+
throw std::runtime_error("Unexpected end (s=" + s + ")");
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
int start = i;
|
|
518
|
+
|
|
519
|
+
char c = s[i];
|
|
520
|
+
|
|
521
|
+
// Consume sign.
|
|
522
|
+
if (c == '-' || c == '+') {
|
|
523
|
+
i += 1;
|
|
524
|
+
c = s[i];
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// Consume integer.
|
|
528
|
+
if (c >= '0' && c <= '9') {
|
|
529
|
+
skip_digits();
|
|
530
|
+
if (i < l) {
|
|
531
|
+
c = s[i];
|
|
532
|
+
}
|
|
533
|
+
} else if (c != '.') {
|
|
534
|
+
throw std::runtime_error("Invalid number formatting character '" + std::string(1, c) +
|
|
535
|
+
"' (i=" + std::to_string(i) + ", s=" + s + ")");
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// Consume fraction.
|
|
539
|
+
if (c == '.') {
|
|
540
|
+
i += 1;
|
|
541
|
+
skip_digits();
|
|
542
|
+
if (i < l) {
|
|
543
|
+
c = s[i];
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if ((c == 'e' || c == 'E') && i + 1 < l) {
|
|
548
|
+
char c2 = s[i + 1];
|
|
549
|
+
// Check for `em`/`ex`.
|
|
550
|
+
if (c2 != 'm' && c2 != 'x') {
|
|
551
|
+
i += 1;
|
|
552
|
+
c = s[i];
|
|
553
|
+
|
|
554
|
+
if (c == '+' || c == '-') {
|
|
555
|
+
i += 1;
|
|
556
|
+
skip_digits();
|
|
557
|
+
} else if (c >= '0' && c <= '9') {
|
|
558
|
+
skip_digits();
|
|
559
|
+
} else {
|
|
560
|
+
throw std::runtime_error("Invalid number formatting character '" + std::string(1, c) +
|
|
561
|
+
"' (i=" + std::to_string(i) + ", s=" + s + ")");
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
std::string num = s.substr(start, i - start);
|
|
567
|
+
float n = std::stof(num);
|
|
568
|
+
|
|
569
|
+
// inf, nan, etc. are an error.
|
|
570
|
+
if (std::isinf(n) || std::isnan(n)) {
|
|
571
|
+
throw std::runtime_error("Invalid number '" + num + "' (start=" + std::to_string(start) +
|
|
572
|
+
", i=" + std::to_string(i) + ", s=" + s + ")");
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return n;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
void PathParserUtils::parse_list_separator() {
|
|
579
|
+
if (i < l && s[i] == ',') {
|
|
580
|
+
i += 1;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
void PathParserUtils::skip_digits() {
|
|
585
|
+
while (i < l && std::isdigit(s[i])) {
|
|
586
|
+
i++;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
} // namespace svg
|
|
591
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
* This file incorporates from the react-native-svg project, licensed under
|
|
7
|
+
* the MIT License. Specifically:
|
|
8
|
+
* - [software-mansion/react-native-svg] (https://github.com/software-mansion/react-native-svg)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include "SvgMarkerPositionUtils.h"
|
|
14
|
+
#include "drawing/Path.h"
|
|
15
|
+
#include <vector>
|
|
16
|
+
#include <string>
|
|
17
|
+
|
|
18
|
+
namespace rnoh {
|
|
19
|
+
namespace svg {
|
|
20
|
+
class PathParserUtils {
|
|
21
|
+
|
|
22
|
+
public:
|
|
23
|
+
float mScale;
|
|
24
|
+
std::vector<PathElement> elements;
|
|
25
|
+
|
|
26
|
+
drawing::Path parse(std::string d);
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
int i;
|
|
30
|
+
int l;
|
|
31
|
+
std::string s;
|
|
32
|
+
drawing::Path mPath;
|
|
33
|
+
float mPenX, mPenY, mPenDownX, mPenDownY, mPivotX, mPivotY;
|
|
34
|
+
bool mPenDown;
|
|
35
|
+
|
|
36
|
+
void parse_list_separator();
|
|
37
|
+
|
|
38
|
+
void skip_digits();
|
|
39
|
+
|
|
40
|
+
void close();
|
|
41
|
+
|
|
42
|
+
void setPenDown();
|
|
43
|
+
|
|
44
|
+
void moveTo(float x, float y);
|
|
45
|
+
|
|
46
|
+
void move(float x, float y);
|
|
47
|
+
|
|
48
|
+
void lineTo(float x, float y);
|
|
49
|
+
|
|
50
|
+
void line(float x, float y);
|
|
51
|
+
|
|
52
|
+
void cubicTo(float c1x, float c1y, float c2x, float c2y, float ex, float ey);
|
|
53
|
+
|
|
54
|
+
void curveTo(float c1x, float c1y, float c2x, float c2y, float ex, float ey);
|
|
55
|
+
|
|
56
|
+
void curve(float c1x, float c1y, float c2x, float c2y, float ex, float ey);
|
|
57
|
+
|
|
58
|
+
void smoothCurveTo(float c1x, float c1y, float ex, float ey);
|
|
59
|
+
|
|
60
|
+
void smoothCurve(float c1x, float c1y, float ex, float ey);
|
|
61
|
+
|
|
62
|
+
void quadraticBezierCurveTo(float c1x, float c1y, float c2x, float c2y);
|
|
63
|
+
|
|
64
|
+
void quadraticBezierCurve(float c1x, float c1y, float c2x, float c2y);
|
|
65
|
+
|
|
66
|
+
void smoothQuadraticBezierCurveTo(float c1x, float c1y);
|
|
67
|
+
|
|
68
|
+
void smoothQuadraticBezierCurve(float c1x, float c1y);
|
|
69
|
+
|
|
70
|
+
void arcToBezier(float cx, float cy, float rx, float ry, float sa, float ea, bool clockwise, float rad);
|
|
71
|
+
|
|
72
|
+
void arcTo(float rx, float ry, float rotation, bool outer, bool clockwise, float x, float y);
|
|
73
|
+
|
|
74
|
+
void arc(float rx, float ry, float rotation, bool outer, bool clockwise, float x, float y);
|
|
75
|
+
|
|
76
|
+
double roundVal(double val);
|
|
77
|
+
|
|
78
|
+
void skip_spaces();
|
|
79
|
+
|
|
80
|
+
bool is_cmd(char c);
|
|
81
|
+
|
|
82
|
+
bool is_number_start(char c);
|
|
83
|
+
|
|
84
|
+
bool is_absolute(char c);
|
|
85
|
+
|
|
86
|
+
bool parse_flag();
|
|
87
|
+
|
|
88
|
+
float parse_number();
|
|
89
|
+
|
|
90
|
+
float parse_list_number();
|
|
91
|
+
};
|
|
92
|
+
} // namespace svg
|
|
93
|
+
} // namespace rnoh
|