diff --git a/OAT.xml b/OAT.xml new file mode 100644 index 00000000..4ac6621b --- /dev/null +++ b/OAT.xml @@ -0,0 +1,90 @@ + + + + LICENSE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/react-native-harmony-svg/LICENSE b/react-native-harmony-svg/LICENSE new file mode 100644 index 00000000..6b03fe67 --- /dev/null +++ b/react-native-harmony-svg/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) [2015-2016] [Horcrux] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/react-native-harmony-svg/rnoh-react-native-harmony-svg-0.0.4.tgz b/react-native-harmony-svg/rnoh-react-native-harmony-svg-0.0.4.tgz deleted file mode 100644 index 43e228a5..00000000 Binary files a/react-native-harmony-svg/rnoh-react-native-harmony-svg-0.0.4.tgz and /dev/null differ diff --git a/tester/harmony/dependencies/hvigor-4.3.0.tgz b/tester/harmony/dependencies/hvigor-4.3.0.tgz deleted file mode 100644 index 4331aad9..00000000 Binary files a/tester/harmony/dependencies/hvigor-4.3.0.tgz and /dev/null differ diff --git a/tester/harmony/dependencies/hvigor-ohos-arkui-x-plugin-3.3.0.tgz b/tester/harmony/dependencies/hvigor-ohos-arkui-x-plugin-3.3.0.tgz deleted file mode 100644 index 5b496f7d..00000000 Binary files a/tester/harmony/dependencies/hvigor-ohos-arkui-x-plugin-3.3.0.tgz and /dev/null differ diff --git a/tester/harmony/dependencies/hvigor-ohos-plugin-4.3.0.tgz b/tester/harmony/dependencies/hvigor-ohos-plugin-4.3.0.tgz deleted file mode 100644 index 6fb89f74..00000000 Binary files a/tester/harmony/dependencies/hvigor-ohos-plugin-4.3.0.tgz and /dev/null differ diff --git a/tester/harmony/svg/src/main/cpp/Attribute.h b/tester/harmony/svg/src/main/cpp/Attribute.h index 6316ec2b..c290d1d6 100644 --- a/tester/harmony/svg/src/main/cpp/Attribute.h +++ b/tester/harmony/svg/src/main/cpp/Attribute.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/SVGPackage.cpp b/tester/harmony/svg/src/main/cpp/SVGPackage.cpp index 3eeef675..d31114cc 100644 --- a/tester/harmony/svg/src/main/cpp/SVGPackage.cpp +++ b/tester/harmony/svg/src/main/cpp/SVGPackage.cpp @@ -65,10 +65,7 @@ std::vector SVGPackage::createComponentDescr }; } -ComponentNapiBinderByString SVGPackage::createComponentNapiBinderByName() -{ - return {}; -} +ComponentNapiBinderByString SVGPackage::createComponentNapiBinderByName() { return {}; } ComponentJSIBinderByString SVGPackage::createComponentJSIBinderByName() { return { diff --git a/tester/harmony/svg/src/main/cpp/SVGPackage.h b/tester/harmony/svg/src/main/cpp/SVGPackage.h index fbe764ba..848fb010 100644 --- a/tester/harmony/svg/src/main/cpp/SVGPackage.h +++ b/tester/harmony/svg/src/main/cpp/SVGPackage.h @@ -108,9 +108,8 @@ class SVGPackageComponentInstanceFactoryDelegate : public ComponentInstanceFacto class SVGPackage : public Package { public: explicit SVGPackage(Package::Context ctx) : Package(ctx) {} - - std::unique_ptr createTurboModuleFactoryDelegate() - override; + + std::unique_ptr createTurboModuleFactoryDelegate() override; ComponentInstanceFactoryDelegate::Shared createComponentInstanceFactoryDelegate() override { return std::make_shared(); diff --git a/tester/harmony/svg/src/main/cpp/SvgArkUINode.cpp b/tester/harmony/svg/src/main/cpp/SvgArkUINode.cpp index 4bfc0240..b3dd0089 100644 --- a/tester/harmony/svg/src/main/cpp/SvgArkUINode.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgArkUINode.cpp @@ -4,7 +4,6 @@ * found in the LICENSE file. */ -#include "arkui/native_interface.h" #include "arkui/native_node.h" #include "arkui/native_type.h" #include "RNOH/arkui/NativeNodeApi.h" @@ -20,6 +19,8 @@ namespace rnoh { namespace svg { +constexpr int NODE_EVENT_ID = 77; + // 对应SVGArkUINode SvgArkUINode::SvgArkUINode() : ArkUINode(NativeNodeApi::getInstance()->createNode(ArkUI_NodeType::ARKUI_NODE_CUSTOM)) { userCallback_ = new UserCallback(); @@ -35,7 +36,7 @@ SvgArkUINode::SvgArkUINode() : ArkUINode(NativeNodeApi::getInstance()->createNod } }; eventReceiver = [](ArkUI_NodeCustomEvent *event) { - if (OH_ArkUI_NodeCustomEvent_GetEventTargetId(event) == 77) { + if (OH_ArkUI_NodeCustomEvent_GetEventTargetId(event) == NODE_EVENT_ID) { auto *userData = reinterpret_cast(OH_ArkUI_NodeCustomEvent_GetUserData(event)); if (userData != nullptr && userData->callback != nullptr) { userData->callback(event); @@ -43,7 +44,7 @@ SvgArkUINode::SvgArkUINode() : ArkUINode(NativeNodeApi::getInstance()->createNod } }; maybeThrow(NativeNodeApi::getInstance()->addNodeCustomEventReceiver(m_nodeHandle, eventReceiver)); - maybeThrow(NativeNodeApi::getInstance()->registerNodeCustomEvent(m_nodeHandle, ARKUI_NODE_CUSTOM_EVENT_ON_DRAW, 77, + maybeThrow(NativeNodeApi::getInstance()->registerNodeCustomEvent(m_nodeHandle, ARKUI_NODE_CUSTOM_EVENT_ON_DRAW, NODE_EVENT_ID, userCallback_)); } diff --git a/tester/harmony/svg/src/main/cpp/SvgBaseAttribute.h b/tester/harmony/svg/src/main/cpp/SvgBaseAttribute.h index 14c3517f..58e4a099 100644 --- a/tester/harmony/svg/src/main/cpp/SvgBaseAttribute.h +++ b/tester/harmony/svg/src/main/cpp/SvgBaseAttribute.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/SvgDefs.h b/tester/harmony/svg/src/main/cpp/SvgDefs.h index b729a449..90b2ff35 100644 --- a/tester/harmony/svg/src/main/cpp/SvgDefs.h +++ b/tester/harmony/svg/src/main/cpp/SvgDefs.h @@ -13,10 +13,8 @@ namespace rnoh { namespace svg { class SvgDefs : public SvgNode { - public: SvgDefs() : SvgNode() { InitDefsFlag(); } - ~SvgDefs() override = default; void InitDefsFlag() { @@ -28,12 +26,14 @@ class SvgDefs : public SvgNode { drawing::Path AsPath() override { drawing::Path path; - DLOG(INFO) << "[SvgDfes:AsPath] : arrived Defs AsPath"; - for (auto child : children_) { + // Early return if there are no children + if (children_.empty()) { + return path; + } + for (const auto& child : children_) { if (!child) { - DLOG(INFO) << "[SvgDfes:AsPath] : childnode is a null ptr"; - } else { - DLOG(INFO) << "[SvgDfes:AsPath] : get child path:"; + DLOG(WARNING) << "[SvgDefs:AsPath] Encountered a null child node"; + continue; } auto childPath = child->AsPath(); path.Union(childPath); diff --git a/tester/harmony/svg/src/main/cpp/SvgGradient.cpp b/tester/harmony/svg/src/main/cpp/SvgGradient.cpp index 52ad7c2b..cc50a766 100644 --- a/tester/harmony/svg/src/main/cpp/SvgGradient.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgGradient.cpp @@ -11,6 +11,14 @@ namespace rnoh { namespace svg { +constexpr int TRANSFORM_SCALE_X_INDEX = 0; +constexpr int TRANSFORM_SKEW_Y_INDEX = 1; +constexpr int TRANSFORM_SKEW_X_INDEX = 2; +constexpr int TRANSFORM_SCALE_Y_INDEX = 3; +constexpr int TRANSFORM_TRANSLATE_X_INDEX = 4; +constexpr int TRANSFORM_TRANSLATE_Y_INDEX = 5; +constexpr size_t GRADIENT_TRANSFORM_MATRIX_SIZE = 6; + SvgGradient::SvgGradient(GradientType gradientType) { gradientAttr_.gradient.SetType(gradientType); @@ -88,13 +96,13 @@ void SvgGradient::SetAttrGradientTransforms(std::vector gradientTransform 0, 1, 0, 0, 0, 1, }; - if (gradientTransforms.size() == 6) { - newMatrix[0] = (Float) gradientTransforms[0]; - newMatrix[1] = (Float) gradientTransforms[2]; - newMatrix[2] = (Float) gradientTransforms[4] * scale_; - newMatrix[3] = (Float) gradientTransforms[1]; - newMatrix[4] = (Float) gradientTransforms[3]; - newMatrix[5] = (Float) gradientTransforms[5] * scale_; + if (gradientTransforms.size() == GRADIENT_TRANSFORM_MATRIX_SIZE) { + newMatrix[0] = (Float) gradientTransforms[TRANSFORM_SCALE_X_INDEX]; + newMatrix[1] = (Float) gradientTransforms[TRANSFORM_SKEW_X_INDEX]; + newMatrix[2] = (Float) gradientTransforms[TRANSFORM_TRANSLATE_X_INDEX] * scale_; + newMatrix[3] = (Float) gradientTransforms[TRANSFORM_SKEW_Y_INDEX]; + newMatrix[4] = (Float) gradientTransforms[TRANSFORM_SCALE_Y_INDEX]; + newMatrix[5] = (Float) gradientTransforms[TRANSFORM_TRANSLATE_Y_INDEX] * scale_; gradientAttr_.gradient.SetGradientTransform(std::move(newMatrix)); } } diff --git a/tester/harmony/svg/src/main/cpp/SvgGraphic.cpp b/tester/harmony/svg/src/main/cpp/SvgGraphic.cpp index 76667029..a2ef57cb 100644 --- a/tester/harmony/svg/src/main/cpp/SvgGraphic.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgGraphic.cpp @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -38,6 +38,16 @@ namespace rnoh { namespace svg { +constexpr int TRANSFORM_SCALE_X_INDEX = 0; +constexpr int TRANSFORM_SKEW_Y_INDEX = 1; +constexpr int TRANSFORM_SKEW_X_INDEX = 2; +constexpr int TRANSFORM_SCALE_Y_INDEX = 3; +constexpr int TRANSFORM_TRANSLATE_X_INDEX = 4; +constexpr int TRANSFORM_TRANSLATE_Y_INDEX = 5; +constexpr double MATRIX_Z_VALUE = 1.0; +constexpr int MIN_TRANSFORM_SIZE = 6; // 至少需要 6 个元素 +constexpr int MAX_TRANSFORM_SIZE = 9; // 至多 9 个元素 + void SvgGraphic::OnDraw(OH_Drawing_Canvas *canvas) { DLOG(INFO) << "[SVGGraphic] onDraw marker = " << attributes_.markerStart << " " << attributes_.markerMid << " " << attributes_.markerEnd; @@ -101,10 +111,12 @@ void SvgGraphic::OnGraphicStroke(OH_Drawing_Canvas *canvas) { OH_Drawing_MaskFilterDestroy(maskFilter); } else { const auto &transform = attributes_.transform; - if (attributes_.strokeState.GetVectorEffect() && transform.size() > 5) { + if (attributes_.strokeState.GetVectorEffect() && transform.size() >= MIN_TRANSFORM_SIZE) { auto matrix = drawing::Matrix(); - matrix.SetMatrix(transform[0], transform[2], transform[4] * scale_, transform[1], transform[3], - transform[5] * scale_, 0, 0, 1.0); + matrix.SetMatrix(transform[TRANSFORM_SCALE_X_INDEX], transform[TRANSFORM_SKEW_X_INDEX], + transform[TRANSFORM_TRANSLATE_X_INDEX] * scale_, transform[TRANSFORM_SKEW_Y_INDEX], + transform[TRANSFORM_SCALE_Y_INDEX], transform[TRANSFORM_TRANSLATE_Y_INDEX] * scale_, 0, 0, + MATRIX_Z_VALUE); path_.Transform(matrix); } OH_Drawing_CanvasAttachPen(canvas, strokePen_.get()); @@ -113,10 +125,8 @@ void SvgGraphic::OnGraphicStroke(OH_Drawing_Canvas *canvas) { } } -// todo implement bounds void SvgGraphic::UpdateGradient(std::optional &gradient) { CHECK_NULL_VOID(gradient); - // objectBoundingBox - 0(DEFAULT), userSpaceOnUse - 1 auto nodeBounds = (gradient->GetGradientUnits() == Unit::objectBoundingBox) ? AsBounds() : Rect(0, 0, context_->GetSvgSize().Width(), context_->GetSvgSize().Height()); @@ -418,10 +428,6 @@ bool SvgGraphic::SetPatternStyle() { bool SvgGraphic::UpdateStrokeStyle(bool antiAlias) { const auto &strokeState = attributes_.strokeState; - // auto colorFilter = GetColorFilter(); - // if (!colorFilter.has_value() && strokeState.GetColor() == Color::TRANSPARENT) { - // return false; - // } if (!GreatNotEqual(strokeState.GetLineWidth(), 0.0)) { return false; } @@ -452,9 +458,6 @@ bool SvgGraphic::UpdateStrokeStyle(bool antiAlias) { strokePen_.SetWidth(strokeState.GetLineWidth()); strokePen_.SetMiterLimit(strokeState.GetMiterLimit()); strokePen_.SetAntiAlias(antiAlias); - // auto filter = strokePen_.GetFilter(); - // UpdateColorFilter(filter); - // strokePen_.SetFilter(filter); UpdateLineDash(); return true; } diff --git a/tester/harmony/svg/src/main/cpp/SvgGraphic.h b/tester/harmony/svg/src/main/cpp/SvgGraphic.h index 623a1bd3..41650c07 100644 --- a/tester/harmony/svg/src/main/cpp/SvgGraphic.h +++ b/tester/harmony/svg/src/main/cpp/SvgGraphic.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -65,7 +65,7 @@ class SvgGraphic : virtual public SvgNode { private: void DrawMarker(OH_Drawing_Canvas *canvas); - // TODO void UpdateColorFilter(OH_Drawing_Filter *filter); + // to be done? Color Filter; }; } // namespace svg diff --git a/tester/harmony/svg/src/main/cpp/SvgImage.cpp b/tester/harmony/svg/src/main/cpp/SvgImage.cpp index 03135fdc..21e4a80f 100644 --- a/tester/harmony/svg/src/main/cpp/SvgImage.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgImage.cpp @@ -17,8 +17,8 @@ #include #include -const char * ASSET_PREFIX = "asset://"; -const char * RAWFILE_PREFIX = "assets/"; +const char *ASSET_PREFIX = "asset://"; +const char *RAWFILE_PREFIX = "assets/"; namespace rnoh { namespace svg { @@ -46,7 +46,7 @@ void SvgImage::OnDraw(OH_Drawing_Canvas *canvas) { char *srcUri = const_cast(uriString.c_str()); OH_DecodingOptions_Create(&options); - + Image_ErrorCode createFromUriStatus; if (uriString.find(ASSET_PREFIX, 0) == 0) { auto file = uriString.replace(0, 8, RAWFILE_PREFIX); @@ -71,7 +71,7 @@ void SvgImage::OnDraw(OH_Drawing_Canvas *canvas) { if (createPixelmapStatus == IMAGE_SUCCESS) { /* Temporarily disable the feature to set opacity. - * Currently, there is an issue where setting opacity on + * Currently, there is an issue where setting opacity on * transparent pixels results in them turning black. */ if (LessNotEqual(attributes_.opacity, 1.0f)) { @@ -89,8 +89,8 @@ void SvgImage::OnDraw(OH_Drawing_Canvas *canvas) { OH_PixelmapImageInfo_GetWidth(info, imageWidth_); OH_PixelmapImageInfo_GetHeight(info, imageHeight_); - auto imageWidth = (double)*imageWidth_; - auto imageHeight = (double)*imageHeight_; + auto imageWidth = static_cast(*imageWidth_); + auto imageHeight = static_cast(*imageHeight_); delete imageWidth_; delete imageHeight_; diff --git a/tester/harmony/svg/src/main/cpp/SvgImage.h b/tester/harmony/svg/src/main/cpp/SvgImage.h index 44d8cd2d..c51030d9 100644 --- a/tester/harmony/svg/src/main/cpp/SvgImage.h +++ b/tester/harmony/svg/src/main/cpp/SvgImage.h @@ -17,31 +17,35 @@ class SvgImage : public svg::SvgGraphic { public: SvgImage() = default; ~SvgImage() override = default; - + using SvgNode::relativeOnWidth; using SvgNode::relativeOnHeight; - + void SetX(const std::string &x) { imageAttribute_.x = SvgAttributesParser::ParseDimension(x, true); } - + void SetY(const std::string &y) { imageAttribute_.y = SvgAttributesParser::ParseDimension(y, true); } - - void SetHeight(const std::string &height) { imageAttribute_.height = SvgAttributesParser::ParseDimension(height, true); } - - void SetWidth(const std::string &width) { imageAttribute_.width = SvgAttributesParser::ParseDimension(width, true); } - + + void SetHeight(const std::string &height) { + imageAttribute_.height = SvgAttributesParser::ParseDimension(height, true); + } + + void SetWidth(const std::string &width) { + imageAttribute_.width = SvgAttributesParser::ParseDimension(width, true); + } + void SetAlign(const std::string &align) { imageAttribute_.align = align; } - + void SetMeetOrSlice(const int &meetOrSlice) { imageAttribute_.meetOrSlice = meetOrSlice; } - - void SetImageSource(const facebook::react::ImageSource &src ) { imageAttribute_.src = src; } - - void setNativeResourceManager(const NativeResourceManager* mgr) { mgr_ = mgr; } - + + void SetImageSource(const facebook::react::ImageSource &src) { imageAttribute_.src = src; } + + void setNativeResourceManager(const NativeResourceManager *mgr) { mgr_ = mgr; } + void OnDraw(OH_Drawing_Canvas *canvas) override; private: SvgImageAttribute imageAttribute_; - const NativeResourceManager* mgr_; + const NativeResourceManager *mgr_; }; } // namespace svg diff --git a/tester/harmony/svg/src/main/cpp/SvgLine.cpp b/tester/harmony/svg/src/main/cpp/SvgLine.cpp index adde3a20..95312b47 100644 --- a/tester/harmony/svg/src/main/cpp/SvgLine.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgLine.cpp @@ -18,7 +18,7 @@ drawing::Path SvgLine::AsPath() { path.MoveTo(x1, y1); path.LineTo(x2, y2); - + elements_ = {PathElement(ElementType::kCGPathElementMoveToPoint, {Point(x1, y1)}), PathElement(ElementType::kCGPathElementAddLineToPoint, {Point(x2, y2)})}; return path; diff --git a/tester/harmony/svg/src/main/cpp/SvgMarker.cpp b/tester/harmony/svg/src/main/cpp/SvgMarker.cpp index e091beec..3e7900e2 100644 --- a/tester/harmony/svg/src/main/cpp/SvgMarker.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgMarker.cpp @@ -14,48 +14,48 @@ namespace rnoh { namespace svg { - void SvgMarker::renderMarker(OH_Drawing_Canvas *canvas, const SvgMarkerPosition& position, float strokeWidth){ - const auto count = OH_Drawing_CanvasGetSaveCount(canvas); - saveAndSetupCanvas(canvas, cTM_); - - if(markerTransform.get() != nullptr) { - markerTransform.Reset(); - } - Point origin = position.origin; - markerTransform.Translate(origin.x, origin.y); - double markerAngle = (markerAttribute_.orient == "auto") ? -1 : std::atof(markerAttribute_.orient.c_str()); - float degrees = 180 + (markerAngle == -1 ? position.angle : static_cast(markerAngle)); - //fix me? float rad = deg2rad(angle); this code only in ios -// degrees = SvgMarkerPositionUtils::deg2rad(degrees); - markerTransform.PreRotate( degrees, 0, 0); - - if (markerAttribute_.markerUnits == "strokeWidth"){ - markerTransform.PreScale(strokeWidth / scale_, strokeWidth / scale_, 0, 0); - } - if (!markerAttribute_.align.empty()){ - double width = relativeOnWidth(markerAttribute_.markerWidth) / scale_; - double height = relativeOnHeight(markerAttribute_.markerHeight) / scale_; - Rect eRect(0, 0, width, height); - Rect vbRect(markerAttribute_.minX.ConvertToPx(scale_), markerAttribute_.minY.ConvertToPx(scale_), - markerAttribute_.minX.ConvertToPx(scale_) + markerAttribute_.vbWidth.ConvertToPx(scale_), - markerAttribute_.minY.ConvertToPx(scale_) + markerAttribute_.vbHeight.ConvertToPx(scale_)); - if (vbRect.IsValid()) { - drawing::Matrix viewBoxMatrix = ViewBox::getTransform(vbRect, eRect, markerAttribute_.align, markerAttribute_.meetOrSlice); - float sx = viewBoxMatrix.GetValue(0); - float sy = viewBoxMatrix.GetValue(4); - markerTransform.PreScale(sx, sy, 0, 0); - } +void SvgMarker::renderMarker(OH_Drawing_Canvas *canvas, const SvgMarkerPosition &position, float strokeWidth) { + const auto count = OH_Drawing_CanvasGetSaveCount(canvas); + saveAndSetupCanvas(canvas, cTM_); + + if (markerTransform.get() != nullptr) { + markerTransform.Reset(); + } + Point origin = position.origin; + markerTransform.Translate(origin.x, origin.y); + double markerAngle = (markerAttribute_.orient == "auto") ? -1 : std::atof(markerAttribute_.orient.c_str()); + float degrees = 180 + (markerAngle == -1 ? position.angle : static_cast(markerAngle)); + // fix me? float rad = deg2rad(angle); this code only in ios + markerTransform.PreRotate(degrees, 0, 0); + + if (markerAttribute_.markerUnits == "strokeWidth") { + markerTransform.PreScale(strokeWidth / scale_, strokeWidth / scale_, 0, 0); + } + if (!markerAttribute_.align.empty()) { + double width = relativeOnWidth(markerAttribute_.markerWidth) / scale_; + double height = relativeOnHeight(markerAttribute_.markerHeight) / scale_; + Rect eRect(0, 0, width, height); + Rect vbRect(markerAttribute_.minX.ConvertToPx(scale_), markerAttribute_.minY.ConvertToPx(scale_), + markerAttribute_.minX.ConvertToPx(scale_) + markerAttribute_.vbWidth.ConvertToPx(scale_), + markerAttribute_.minY.ConvertToPx(scale_) + markerAttribute_.vbHeight.ConvertToPx(scale_)); + if (vbRect.IsValid()) { + drawing::Matrix viewBoxMatrix = + ViewBox::getTransform(vbRect, eRect, markerAttribute_.align, markerAttribute_.meetOrSlice); + float sx = viewBoxMatrix.GetValue(0); + float sy = viewBoxMatrix.GetValue(4); + markerTransform.PreScale(sx, sy, 0, 0); } - - double x = relativeOnWidth(markerAttribute_.refX); - double y = relativeOnHeight(markerAttribute_.refY); - markerTransform.PreTranslate(-x, -y); - OH_Drawing_CanvasConcatMatrix(canvas, markerTransform.get()); - - OnDrawTraversed(canvas); - - OH_Drawing_CanvasRestoreToCount(canvas, count); } + double x = relativeOnWidth(markerAttribute_.refX); + double y = relativeOnHeight(markerAttribute_.refY); + markerTransform.PreTranslate(-x, -y); + OH_Drawing_CanvasConcatMatrix(canvas, markerTransform.get()); + + OnDrawTraversed(canvas); + + OH_Drawing_CanvasRestoreToCount(canvas, count); +} + } // namespace svg } // namespace rnoh \ No newline at end of file diff --git a/tester/harmony/svg/src/main/cpp/SvgMarker.h b/tester/harmony/svg/src/main/cpp/SvgMarker.h index 04633dd3..ce05c820 100644 --- a/tester/harmony/svg/src/main/cpp/SvgMarker.h +++ b/tester/harmony/svg/src/main/cpp/SvgMarker.h @@ -24,13 +24,9 @@ class SvgMarker : public SvgQuote { SvgMarker() = default; ~SvgMarker() override = default; - void setRefX(const std::string &refX) { - markerAttribute_.refX = SvgAttributesParser::ParseDimension(refX, true); - } + void setRefX(const std::string &refX) { markerAttribute_.refX = SvgAttributesParser::ParseDimension(refX, true); } - void setRefY(const std::string &refY) { - markerAttribute_.refY = SvgAttributesParser::ParseDimension(refY, true); - } + void setRefY(const std::string &refY) { markerAttribute_.refY = SvgAttributesParser::ParseDimension(refY, true); } void setMarkerWidth(const std::string &markerWidth) { markerAttribute_.markerWidth = SvgAttributesParser::ParseDimension(markerWidth, true); @@ -40,13 +36,9 @@ class SvgMarker : public SvgQuote { markerAttribute_.markerHeight = SvgAttributesParser::ParseDimension(markerHeight, true); } - void setMarkerUnits(const std::string &markerUnits) { - markerAttribute_.markerUnits = markerUnits; - } + void setMarkerUnits(const std::string &markerUnits) { markerAttribute_.markerUnits = markerUnits; } - void setOrient(const std::string &orient) { - markerAttribute_.orient = orient; - } + void setOrient(const std::string &orient) { markerAttribute_.orient = orient; } void setMinX(double minX) { markerAttribute_.minX = Dimension(minX, DimensionUnit::VP); } diff --git a/tester/harmony/svg/src/main/cpp/SvgMask.h b/tester/harmony/svg/src/main/cpp/SvgMask.h index 15a5b1b7..d6e67b4a 100644 --- a/tester/harmony/svg/src/main/cpp/SvgMask.h +++ b/tester/harmony/svg/src/main/cpp/SvgMask.h @@ -47,7 +47,6 @@ class SvgMask : public SvgQuote { maskAttribute_.maskContentUnits = ToUnit(maskContentUnits); isDefaultMaskContentUnits(maskAttribute_.maskContentUnits == Unit::userSpaceOnUse); } - protected: void OnInitStyle() override; diff --git a/tester/harmony/svg/src/main/cpp/SvgNode.cpp b/tester/harmony/svg/src/main/cpp/SvgNode.cpp index 58b017d3..06c466fe 100644 --- a/tester/harmony/svg/src/main/cpp/SvgNode.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgNode.cpp @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -31,6 +31,15 @@ namespace rnoh { namespace svg { +constexpr size_t MIN_TRANSFORM_SIZE = 6; +constexpr int TRANSFORM_SCALE_X_INDEX = 0; +constexpr int TRANSFORM_SKEW_Y_INDEX = 1; +constexpr int TRANSFORM_SKEW_X_INDEX = 2; +constexpr int TRANSFORM_SCALE_Y_INDEX = 3; +constexpr int TRANSFORM_TRANSLATE_X_INDEX = 4; +constexpr int TRANSFORM_TRANSLATE_Y_INDEX = 5; +constexpr double MATRIX_Z_VALUE = 1.0; + void SvgNode::InitStyle(const SvgBaseAttribute &attr) { // reset gradient to null attributes_.fillState.SetGradient(std::nullopt, false); @@ -79,7 +88,6 @@ void SvgNode::OnDrawTraversed(OH_Drawing_Canvas *canvas) { const Rect &SvgNode::GetRootViewBox() const { if (!context_) { - // DLOGE("Gradient failed, svgContext is null"); static Rect empty; return empty; } @@ -99,11 +107,7 @@ void SvgNode::OnClipPath(OH_Drawing_Canvas *canvas) { }; auto clipPath = refSvgNode->AsPath(); - // TODO: maybe return optional from AsPath? - // if (!clipPath) { - // DLOG(WARNING) << "[SvgNode] OnClipPath: Path is null!"; - // return; - // }; + // maybe return optional from AsPath? // Set clipRule through Drawing API clipPath.SetFillType(attributes_.clipState.GetClipRuleForDraw()); @@ -129,9 +133,11 @@ void SvgNode::OnTransform(OH_Drawing_Canvas *canvas) { /* (OH_Drawing_Matrix* , float scaleX, float skewX, float transX, float skewY, float scaleY, float transY, float persp0, float persp1, float persp2 ) */ - if (!attributes_.strokeState.GetVectorEffect() && transform.size() > 5) { - cTM_.SetMatrix(transform[0], transform[2], transform[4] * scale_, transform[1], transform[3], - transform[5] * scale_, 0, 0, 1.0); + if (!attributes_.strokeState.GetVectorEffect() && transform.size() >= MIN_TRANSFORM_SIZE) { + cTM_.SetMatrix(transform[TRANSFORM_SCALE_X_INDEX], transform[TRANSFORM_SKEW_X_INDEX], + transform[TRANSFORM_TRANSLATE_X_INDEX] * scale_, transform[TRANSFORM_SKEW_Y_INDEX], + transform[TRANSFORM_SCALE_Y_INDEX], transform[TRANSFORM_TRANSLATE_Y_INDEX] * scale_, 0, 0, + MATRIX_Z_VALUE); OH_Drawing_CanvasConcatMatrix(canvas, cTM_.get()); } } @@ -225,7 +231,7 @@ double SvgNode::getCanvasWidth() { if (canvasWidth_ != -1) { return canvasWidth_; } - // TODO if root is text root + // to be done? if root is text root if (context_) { canvasWidth_ = context_->getCanvasBounds().Width() / context_->getCanvasScaleX(); return canvasWidth_; @@ -237,7 +243,7 @@ double SvgNode::getCanvasHeight() { if (canvasHeight_ != -1) { return canvasHeight_; } - // TODO if root is text root + // to be done? if root is text root if (context_) { canvasHeight_ = context_->getCanvasBounds().Height() / context_->getCanvasScaleY(); return canvasHeight_; diff --git a/tester/harmony/svg/src/main/cpp/SvgNode.h b/tester/harmony/svg/src/main/cpp/SvgNode.h index 6ef26d6c..27a6595f 100644 --- a/tester/harmony/svg/src/main/cpp/SvgNode.h +++ b/tester/harmony/svg/src/main/cpp/SvgNode.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -40,6 +40,8 @@ namespace rnoh { namespace svg { +constexpr int INHERIT_TYPE = 2; + class SvgNode : public std::enable_shared_from_this { public: SvgNode() = default; @@ -95,23 +97,23 @@ class SvgNode : public std::enable_shared_from_this { set.insert(prop); } - if (props->fill.type == 2) { - Color color = Color((uint32_t)*props->fill.payload); + if (props->fill.type == INHERIT_TYPE) { + Color color = Color(static_cast(*props->fill.payload)); color.SetUseCurrentColor(true); attributes_.fillState.SetColor(color, true); } else if (facebook::react::isColorMeaningful(props->fill.payload)) { - attributes_.fillState.SetColor(Color((uint32_t)*props->fill.payload), set.count("fill")); + attributes_.fillState.SetColor(Color(static_cast(*props->fill.payload)), set.count("fill")); } else { attributes_.fillState.SetColor(Color::TRANSPARENT, set.count("fill")); } attributes_.fillState.SetHref(props->fill.brushRef); - if (props->stroke.type == 2) { - Color color = Color((uint32_t)*props->stroke.payload); + if (props->stroke.type == INHERIT_TYPE) { + Color color = Color(static_cast(*props->stroke.payload)); color.SetUseCurrentColor(true); attributes_.strokeState.SetColor(color, true); } else if (facebook::react::isColorMeaningful(props->stroke.payload)) { - attributes_.strokeState.SetColor(Color((uint32_t)*props->stroke.payload), set.count("stroke")); + attributes_.strokeState.SetColor(Color(static_cast(*props->stroke.payload)), set.count("stroke")); } else { attributes_.strokeState.SetColor(Color::TRANSPARENT, set.count("stroke")); } @@ -120,17 +122,17 @@ class SvgNode : public std::enable_shared_from_this { attributes_.fillState.SetOpacity(std::clamp(props->fillOpacity, 0.0, 1.0), set.count("fillOpacity")); // todo Inheritance situation attributes_.fillState.SetFillRule(static_cast(props->fillRule), true); - attributes_.strokeState.SetLineWidth(vpToPx(StringUtils::StringToDouble(props->strokeWidth)), + attributes_.strokeState.SetLineWidth(StringUtils::StringToDouble(props->strokeWidth) * scale_, set.count("strokeWidth")); - attributes_.strokeState.SetStrokeDashArray(StringUtils::stringVectorToDoubleVector(props->strokeDasharray), - set.count("strokeDasharray")); - attributes_.strokeState.SetStrokeDashOffset(vpToPx(props->strokeDashoffset), set.count("strokeDashoffset")); + attributes_.strokeState.SetStrokeDashArray( + StringUtils::stringVectorToDoubleVector(props->strokeDasharray, scale_), set.count("strokeDasharray")); + attributes_.strokeState.SetStrokeDashOffset(props->strokeDashoffset * scale_, set.count("strokeDashoffset")); attributes_.strokeState.SetLineCap(SvgAttributesParser::GetLineCapStyle(std::to_string(props->strokeLinecap)), set.count("strokeLinecap")); attributes_.strokeState.SetLineJoin( SvgAttributesParser::GetLineJoinStyle(std::to_string(props->strokeLinejoin)), set.count("strokeLinejoin")); attributes_.strokeState.SetVectorEffect(props->vectorEffect); - auto limit = vpToPx(props->strokeMiterlimit); + auto limit = props->strokeMiterlimit * scale_; if (GreatOrEqual(limit, 1.0)) { attributes_.strokeState.SetMiterLimit(limit, set.count("strokeMiterlimit")); } @@ -206,7 +208,6 @@ class SvgNode : public std::enable_shared_from_this { std::string hrefClipPath_; std::string imagePath_; - // TODO get densityPixels in CAPI double scale_ = 3.25; drawing::Matrix cTM_; diff --git a/tester/harmony/svg/src/main/cpp/SvgPattern.cpp b/tester/harmony/svg/src/main/cpp/SvgPattern.cpp index 12a0c897..7242522f 100644 --- a/tester/harmony/svg/src/main/cpp/SvgPattern.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgPattern.cpp @@ -9,6 +9,14 @@ namespace rnoh { namespace svg { +constexpr size_t PATTERN_TRANSFORM_MATRIX_SIZE = 6; +constexpr int TRANSFORM_SCALE_X_INDEX = 0; +constexpr int TRANSFORM_SKEW_Y_INDEX = 1; +constexpr int TRANSFORM_SKEW_X_INDEX = 2; +constexpr int TRANSFORM_SCALE_Y_INDEX = 3; +constexpr int TRANSFORM_TRANSLATE_X_INDEX = 4; +constexpr int TRANSFORM_TRANSLATE_Y_INDEX = 5; + SvgPattern::SvgPattern() { DLOG(INFO) << "[SvgPattern] init"; } void SvgPattern::OnDrawTraversedBefore(OH_Drawing_Canvas *canvas) { @@ -52,13 +60,13 @@ void SvgPattern::setPatternTransforms(std::vector patternTransforms) { std::vector newMatrix{ 1, 0, 0, 0, 1, 0, 0, 0, 1, }; - if (patternTransforms.size() == 6) { - newMatrix[0] = (Float)patternTransforms[0]; - newMatrix[1] = (Float)patternTransforms[2]; - newMatrix[2] = (Float)patternTransforms[4] * scale_; - newMatrix[3] = (Float)patternTransforms[1]; - newMatrix[4] = (Float)patternTransforms[3]; - newMatrix[5] = (Float)patternTransforms[5] * scale_; + if (patternTransforms.size() == PATTERN_TRANSFORM_MATRIX_SIZE) { + newMatrix[0] = (Float)patternTransforms[TRANSFORM_SCALE_X_INDEX]; + newMatrix[1] = (Float)patternTransforms[TRANSFORM_SKEW_X_INDEX]; + newMatrix[2] = (Float)patternTransforms[TRANSFORM_TRANSLATE_X_INDEX] * scale_; + newMatrix[3] = (Float)patternTransforms[TRANSFORM_SKEW_Y_INDEX]; + newMatrix[4] = (Float)patternTransforms[TRANSFORM_SCALE_Y_INDEX]; + newMatrix[5] = (Float)patternTransforms[TRANSFORM_TRANSLATE_Y_INDEX] * scale_; patternAttr->setPatternTransform(std::move(newMatrix)); } } diff --git a/tester/harmony/svg/src/main/cpp/SvgPattern.h b/tester/harmony/svg/src/main/cpp/SvgPattern.h index f5dad26b..50173a0a 100644 --- a/tester/harmony/svg/src/main/cpp/SvgPattern.h +++ b/tester/harmony/svg/src/main/cpp/SvgPattern.h @@ -18,10 +18,10 @@ class SvgPattern : public SvgQuote { public: using Float = facebook::react::Float; SvgPattern(); - ~SvgPattern() = default; + ~SvgPattern() override = default; - virtual void OnDrawTraversedBefore(OH_Drawing_Canvas *canvas) override; - virtual void OnDrawTraversedAfter(OH_Drawing_Canvas *canvas) override; + void OnDrawTraversedBefore(OH_Drawing_Canvas *canvas) override; + void OnDrawTraversedAfter(OH_Drawing_Canvas *canvas) override; void SaveDefinition(OH_Drawing_Canvas *canvas); void ConcatMatrix(OH_Drawing_Canvas *canvas); std::shared_ptr GetPatternAttr(); diff --git a/tester/harmony/svg/src/main/cpp/SvgQuote.h b/tester/harmony/svg/src/main/cpp/SvgQuote.h index d1f9280e..cf98946a 100644 --- a/tester/harmony/svg/src/main/cpp/SvgQuote.h +++ b/tester/harmony/svg/src/main/cpp/SvgQuote.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/SvgSvg.cpp b/tester/harmony/svg/src/main/cpp/SvgSvg.cpp index 2f32a26f..0c88fd69 100644 --- a/tester/harmony/svg/src/main/cpp/SvgSvg.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgSvg.cpp @@ -39,7 +39,6 @@ Rect SvgSvg::GetViewBox() const { drawing::Matrix SvgSvg::FitCanvas(OH_Drawing_Canvas *canvas) { const auto svgSize = GetSize(); - // TODO Since OH_Drawing API return px and RN pass vp const auto vbRect = GetViewBox(); // should be viewBox attribute const auto eRect = Rect(svgAttribute_.x.ConvertToPx(scale_), svgAttribute_.y.ConvertToPx(scale_), svgSize.Width(), svgSize.Height()); @@ -60,9 +59,6 @@ void SvgSvg::Draw(OH_Drawing_Canvas *canvas) { float height = OH_Drawing_CanvasGetHeight(canvas); context_->SetCanvasBounds(Rect(0.0f, 0.0f, width, height)); context_->SetRootViewBox(GetViewBox()); - - // width_ = relativeOnWidth(svgAttribute_.width); - // height_ = relativeOnHeight(svgAttribute_.height); width_ = width; height_ = height; DLOG(INFO) << "[svgView] bbHeight: " << svgAttribute_.height.Value(); @@ -75,7 +71,10 @@ void SvgSvg::Draw(OH_Drawing_Canvas *canvas) { // apply scale OH_Drawing_CanvasSave(canvas); auto canvasTransformMatrix = FitCanvas(canvas); - context_->SetCanvasScale(canvasTransformMatrix.GetValue(0), canvasTransformMatrix.GetValue(4)); + constexpr size_t matrixScaleXIndex = 0; + constexpr size_t matrixScaleYIndex = 4; + context_->SetCanvasScale(canvasTransformMatrix.GetValue(matrixScaleXIndex), + canvasTransformMatrix.GetValue(matrixScaleYIndex)); SvgNode::Draw(canvas); OH_Drawing_CanvasRestore(canvas); }; diff --git a/tester/harmony/svg/src/main/cpp/SvgSymbol.cpp b/tester/harmony/svg/src/main/cpp/SvgSymbol.cpp index 927966f7..0fc3f8de 100644 --- a/tester/harmony/svg/src/main/cpp/SvgSymbol.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgSymbol.cpp @@ -11,8 +11,8 @@ namespace svg { void SvgSymbol::drawSymbol(OH_Drawing_Canvas *canvas, float width, float height) { if (!mAlign.empty()) { - Rect vbRect(vpToPx(mMinX), vpToPx(mMinY), vpToPx(mMinX + mVbWidth), vpToPx(mMinY + mVbHeight)); - Rect eRect(0, 0, vpToPx(width), vpToPx(height)); + Rect vbRect(mMinX * scale_, mMinY * scale_, mMinX + mVbWidth * scale_, mMinY + mVbHeight * scale_); + Rect eRect(0, 0, width * scale_, height * scale_); if (vbRect.IsValid()) { drawing::Matrix viewBoxMatrix = ViewBox::getTransform(vbRect, eRect, mAlign, mMeetOrSlice); OH_Drawing_CanvasConcatMatrix(canvas, viewBoxMatrix.get()); diff --git a/tester/harmony/svg/src/main/cpp/SvgTSpan.cpp b/tester/harmony/svg/src/main/cpp/SvgTSpan.cpp index df67dbce..3fd5a10f 100644 --- a/tester/harmony/svg/src/main/cpp/SvgTSpan.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgTSpan.cpp @@ -17,6 +17,12 @@ namespace rnoh { namespace svg { +constexpr double MATHEMATICAL_BASELINE_SHIFT_FACTOR = 0.5; +constexpr double HANGING_BASELINE_SHIFT_FACTOR = 0.8; +constexpr double ALIGN_START = 0.0; +constexpr double ALIGN_MIDDLE = -0.5; +constexpr double ALIGN_END = -1.0; + void SvgTSpan::OnDraw(OH_Drawing_Canvas *canvas) { if (!glyphCtx_) { InitGlyph(canvas, scale_); @@ -130,13 +136,13 @@ double SvgTSpan::getTextAnchorOffset(TextAnchor textAnchor, const double &textMe switch (textAnchor) { default: case TextAnchor::start: - return 0; + return ALIGN_START; case TextAnchor::middle: - return -textMeasure / 2; + return ALIGN_MIDDLE * textMeasure; case TextAnchor::end: - return -textMeasure; + return ALIGN_END * textMeasure; } } @@ -332,11 +338,11 @@ double SvgTSpan::CalcBaselineShift(OH_Drawing_TypographyCreate *handler, OH_Draw break; case AlignmentBaseline::mathematical: - baselineShift = 0.5 * ascenderHeight; + baselineShift = MATHEMATICAL_BASELINE_SHIFT_FACTOR * ascenderHeight; break; case AlignmentBaseline::hanging: - baselineShift = 0.8 * ascenderHeight; + baselineShift = HANGING_BASELINE_SHIFT_FACTOR * ascenderHeight; break; case AlignmentBaseline::textTop: diff --git a/tester/harmony/svg/src/main/cpp/SvgText.cpp b/tester/harmony/svg/src/main/cpp/SvgText.cpp index a7a11779..0ff8d1c0 100644 --- a/tester/harmony/svg/src/main/cpp/SvgText.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgText.cpp @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved + * Use of this source code is governed by a MIT license that can be + * found in the LICENSE file. + */ + #include #include "SvgText.h" #include "drawing/TextStyle.h" diff --git a/tester/harmony/svg/src/main/cpp/SvgUse.cpp b/tester/harmony/svg/src/main/cpp/SvgUse.cpp index 7b1bc76a..657eb008 100644 --- a/tester/harmony/svg/src/main/cpp/SvgUse.cpp +++ b/tester/harmony/svg/src/main/cpp/SvgUse.cpp @@ -24,7 +24,7 @@ void SvgUse::OnDraw(OH_Drawing_Canvas *canvas) { } if (x != 0 || y != 0) { - OH_Drawing_CanvasTranslate(canvas, vpToPx(x), vpToPx(y)); + OH_Drawing_CanvasTranslate(canvas, x * scale_, y * scale_); } AttributeScope scope(refSvgNode); diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGBaseComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGBaseComponentInstance.h index fbd328f2..007b59cd 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGBaseComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGBaseComponentInstance.h @@ -24,7 +24,7 @@ template class RNSVGBaseComponentInstance : public CppComponentInst pointerEvents_ = props->pointerEvents.size() == 0 ? "auto" : props->pointerEvents; svgMarkDirty(); } - + void onFinalizeUpdates() override { if (GetSvgNode()) { GetSvgNode()->SetScale(CppComponentInstance::m_layoutMetrics.pointScaleFactor); @@ -87,13 +87,15 @@ template class RNSVGBaseComponentInstance : public CppComponentInst // For debug auto rect = node->AsBounds(); DLOG(INFO) << "[SvgTouch] asBound x: " << rect.Left() << ", y: " << rect.Top() << ", width: " << rect.Width() - << ", height: " << rect.Height(); + << ", height: " << rect.Height(); auto invertedTransform = node->lastCanvasMatrix_.Invert(); if (!invertedTransform.has_value()) { return false; } - auto transformed = invertedTransform.value().MapPoint({float(vpToPx(point.x)), float(vpToPx(point.y))}); + auto transformed = invertedTransform.value().MapPoint( + {float(CppComponentInstance::m_layoutMetrics.pointScaleFactor * point.x), + float(CppComponentInstance::m_layoutMetrics.pointScaleFactor * point.y)}); return node->AsPath().Contains(transformed.x, transformed.y); } @@ -181,7 +183,6 @@ template class RNSVGBaseComponentInstance : public CppComponentInst private: std::weak_ptr m_svgViewComponentInstance; std::string pointerEvents_ = "auto"; - }; } // namespace svg diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGCircleComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGCircleComponentInstance.h index b1454b85..87daa9b7 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGCircleComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGCircleComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGCircleComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGCircleComponentInstance(Context context); + explicit RNSVGCircleComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGClipPathComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGClipPathComponentInstance.h index 610bbe32..7fb7f72c 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGClipPathComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGClipPathComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGClipPathComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGClipPathComponentInstance(Context context); + explicit RNSVGClipPathComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGDefsComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGDefsComponentInstance.h index 8c436fae..df8d4fe2 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGDefsComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGDefsComponentInstance.h @@ -15,7 +15,7 @@ namespace svg { class RNSVGDefsComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGDefsComponentInstance(Context context); + explicit RNSVGDefsComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGEllipseComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGEllipseComponentInstance.h index 2267db77..f4b8fa07 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGEllipseComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGEllipseComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGEllipseComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGEllipseComponentInstance(Context context); + explicit RNSVGEllipseComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGGroupComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGGroupComponentInstance.h index 07b0f703..7e5a5dce 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGGroupComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGGroupComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGGroupComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGGroupComponentInstance(Context context); + explicit RNSVGGroupComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGImageComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGImageComponentInstance.h index 6b7912ae..3687a441 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGImageComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGImageComponentInstance.h @@ -15,7 +15,7 @@ namespace svg { class RNSVGImageComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGImageComponentInstance(Context context); + explicit RNSVGImageComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGLineComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGLineComponentInstance.h index 6f6ebaf2..1bd3d513 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGLineComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGLineComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGLineComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGLineComponentInstance(Context context); + explicit RNSVGLineComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGLinearGradientComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGLinearGradientComponentInstance.h index 710f2404..ebe87946 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGLinearGradientComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGLinearGradientComponentInstance.h @@ -15,7 +15,7 @@ namespace svg { class RNSVGLinearGradientComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGLinearGradientComponentInstance(Context context); + explicit RNSVGLinearGradientComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGMarkerComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGMarkerComponentInstance.h index cc86a3c6..7ba320bf 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGMarkerComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGMarkerComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGMarkerComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGMarkerComponentInstance(Context context); + explicit RNSVGMarkerComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGMaskComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGMaskComponentInstance.h index 70c6b8d2..f305caa7 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGMaskComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGMaskComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGMaskComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGMaskComponentInstance(Context context); + explicit RNSVGMaskComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGPathComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGPathComponentInstance.h index a994a0ef..e829dba7 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGPathComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGPathComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGPathComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGPathComponentInstance(Context context); + explicit RNSVGPathComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGPatternComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGPatternComponentInstance.h index 157b5c79..3702fd9d 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGPatternComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGPatternComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGPatternComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGPatternComponentInstance(Context context); + explicit RNSVGPatternComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGRadialGradientComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGRadialGradientComponentInstance.h index e971cde1..faa0bec3 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGRadialGradientComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGRadialGradientComponentInstance.h @@ -15,7 +15,7 @@ namespace svg { class RNSVGRadialGradientComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGRadialGradientComponentInstance(Context context); + explicit RNSVGRadialGradientComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGRectComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGRectComponentInstance.h index 19dfcb60..cb2dfff7 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGRectComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGRectComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGRectComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGRectComponentInstance(Context context); + explicit RNSVGRectComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGSvgViewComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGSvgViewComponentInstance.h index 9755c465..1d2889b0 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGSvgViewComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGSvgViewComponentInstance.h @@ -19,7 +19,7 @@ namespace svg { class RNSVGSvgViewComponentInstance : public CppComponentInstance, public SvgHost { public: - RNSVGSvgViewComponentInstance(Context context); + explicit RNSVGSvgViewComponentInstance(Context context); ~RNSVGSvgViewComponentInstance(); void onFinalizeUpdates() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGSymbolComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGSymbolComponentInstance.h index f273cceb..bcfd217c 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGSymbolComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGSymbolComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGSymbolComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGSymbolComponentInstance(Context context); + explicit RNSVGSymbolComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTSpanComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTSpanComponentInstance.h index 496c96fa..06124e09 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTSpanComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTSpanComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGTSpanComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGTSpanComponentInstance(Context context); + explicit RNSVGTSpanComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTextComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTextComponentInstance.h index b9a64180..b6e7cd21 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTextComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTextComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGTextComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGTextComponentInstance(Context context); + explicit RNSVGTextComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTextPathComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTextPathComponentInstance.h index 1b643612..5aed4ecb 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTextPathComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGTextPathComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGTextPathComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGTextPathComponentInstance(Context context); + explicit RNSVGTextPathComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGUseComponentInstance.h b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGUseComponentInstance.h index 33bf987a..9bdaeb12 100644 --- a/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGUseComponentInstance.h +++ b/tester/harmony/svg/src/main/cpp/componentInstances/RNSVGUseComponentInstance.h @@ -14,7 +14,7 @@ namespace svg { class RNSVGUseComponentInstance : public RNSVGBaseComponentInstance { public: - RNSVGUseComponentInstance(Context context); + explicit RNSVGUseComponentInstance(Context context); protected: void UpdateElementProps() override; diff --git a/tester/harmony/svg/src/main/cpp/drawing/Brush.cpp b/tester/harmony/svg/src/main/cpp/drawing/Brush.cpp index 0706f71a..ec9a52d3 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/Brush.cpp +++ b/tester/harmony/svg/src/main/cpp/drawing/Brush.cpp @@ -10,7 +10,8 @@ namespace rnoh::drawing { Brush::Brush() : brush_(UniqueNativeBrush(OH_Drawing_BrushCreate(), &OH_Drawing_BrushDestroy)) {} -Brush::Brush(Brush const &other) : brush_(UniqueNativeBrush(OH_Drawing_BrushCopy(other.brush_.get()), &OH_Drawing_BrushDestroy)) {} +Brush::Brush(Brush const &other) + : brush_(UniqueNativeBrush(OH_Drawing_BrushCopy(other.brush_.get()), &OH_Drawing_BrushDestroy)) {} Brush &Brush::operator=(Brush const &) { brush_ = UniqueNativeBrush(OH_Drawing_BrushCopy(brush_.get()), &OH_Drawing_BrushDestroy); @@ -23,22 +24,23 @@ void Brush::SetColor(uint32_t color) { OH_Drawing_BrushSetColor(brush_.get(), co void Brush::SetAlpha(uint8_t alpha) { OH_Drawing_BrushSetAlpha(brush_.get(), alpha); } -void Brush::SetLinearShaderEffect(const OH_Drawing_Point2D* startPt, const OH_Drawing_Point2D* endPt, - const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode mode, const OH_Drawing_Matrix* mat) { +void Brush::SetLinearShaderEffect(const OH_Drawing_Point2D *startPt, const OH_Drawing_Point2D *endPt, + const uint32_t *colors, const float *pos, uint32_t size, OH_Drawing_TileMode mode, + const OH_Drawing_Matrix *mat) { brushShaderEffect_.ShaderEffectCreateLinearGradient(startPt, endPt, colors, pos, size, mode, mat); OH_Drawing_BrushSetShaderEffect(brush_.get(), brushShaderEffect_.get()); } -void Brush::SetRadialShaderEffect(const OH_Drawing_Point2D* startPt, float startRadius, - const OH_Drawing_Point2D* endPt, float endRadius, const uint32_t* colors, const float* pos, uint32_t size, - OH_Drawing_TileMode mode, const OH_Drawing_Matrix* mat) { - brushShaderEffect_.ShaderEffectCreateRadialGradient( - startPt, startRadius, endPt,endRadius, colors, pos, size, mode, mat); +void Brush::SetRadialShaderEffect(const OH_Drawing_Point2D *startPt, float startRadius, const OH_Drawing_Point2D *endPt, + float endRadius, const uint32_t *colors, const float *pos, uint32_t size, + OH_Drawing_TileMode mode, const OH_Drawing_Matrix *mat) { + brushShaderEffect_.ShaderEffectCreateRadialGradient(startPt, startRadius, endPt, endRadius, colors, pos, size, mode, + mat); OH_Drawing_BrushSetShaderEffect(brush_.get(), brushShaderEffect_.get()); } -void Brush::SetImageShaderEffect(OH_Drawing_Image* image, OH_Drawing_TileMode tileX, - OH_Drawing_TileMode tileY, const OH_Drawing_SamplingOptions* opt, const OH_Drawing_Matrix* mat) { +void Brush::SetImageShaderEffect(OH_Drawing_Image *image, OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, + const OH_Drawing_SamplingOptions *opt, const OH_Drawing_Matrix *mat) { brushShaderEffect_.ShaderEffectCreateImageShader(image, tileX, tileY, opt, mat); OH_Drawing_BrushSetShaderEffect(brush_.get(), brushShaderEffect_.get()); } diff --git a/tester/harmony/svg/src/main/cpp/drawing/Brush.h b/tester/harmony/svg/src/main/cpp/drawing/Brush.h index fbea8678..1c2cabca 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/Brush.h +++ b/tester/harmony/svg/src/main/cpp/drawing/Brush.h @@ -31,14 +31,14 @@ class Brush final { void SetColor(uint32_t color); void SetAlpha(uint8_t alpha); - void SetLinearShaderEffect( - const OH_Drawing_Point2D* startPt, const OH_Drawing_Point2D* endPt, const uint32_t* colors, const float* pos, - uint32_t size, OH_Drawing_TileMode mode, const OH_Drawing_Matrix* mat); - void SetRadialShaderEffect( - const OH_Drawing_Point2D* startPt, float startRadius, const OH_Drawing_Point2D* endPt, float endRadius, - const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode mode, const OH_Drawing_Matrix* mat); - void SetImageShaderEffect(OH_Drawing_Image* image, OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, - const OH_Drawing_SamplingOptions* opt, const OH_Drawing_Matrix* mat); + void SetLinearShaderEffect(const OH_Drawing_Point2D *startPt, const OH_Drawing_Point2D *endPt, + const uint32_t *colors, const float *pos, uint32_t size, OH_Drawing_TileMode mode, + const OH_Drawing_Matrix *mat); + void SetRadialShaderEffect(const OH_Drawing_Point2D *startPt, float startRadius, const OH_Drawing_Point2D *endPt, + float endRadius, const uint32_t *colors, const float *pos, uint32_t size, + OH_Drawing_TileMode mode, const OH_Drawing_Matrix *mat); + void SetImageShaderEffect(OH_Drawing_Image *image, OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, + const OH_Drawing_SamplingOptions *opt, const OH_Drawing_Matrix *mat); void Reset(); diff --git a/tester/harmony/svg/src/main/cpp/drawing/GlyPathBag.cpp b/tester/harmony/svg/src/main/cpp/drawing/GlyPathBag.cpp index ca6d9d9e..b701e0f7 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/GlyPathBag.cpp +++ b/tester/harmony/svg/src/main/cpp/drawing/GlyPathBag.cpp @@ -15,8 +15,6 @@ int GlyPathBag::getIndex(char ch) { return it == data.end() ? 0 : it->second; } -drawing::Path GlyPathBag::getOrCreateAndCache(const char &ch, const std::string ¤t) { - return drawing::Path(); -} +drawing::Path GlyPathBag::getOrCreateAndCache(const char &ch, const std::string ¤t) { return drawing::Path(); } } // namespace rnoh::drawing \ No newline at end of file diff --git a/tester/harmony/svg/src/main/cpp/drawing/GlyPathBag.h b/tester/harmony/svg/src/main/cpp/drawing/GlyPathBag.h index 0fc8015a..9cbdc2a9 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/GlyPathBag.h +++ b/tester/harmony/svg/src/main/cpp/drawing/GlyPathBag.h @@ -14,19 +14,18 @@ namespace rnoh::drawing { class GlyPathBag { - private: - int getIndex(char ch); - std::vector paths; - std::unordered_map data; - drawing::Pen paint; - public: - GlyPathBag(drawing::Pen const &paint) { - // Make indexed-by-one, to allow zero to represent non-cached - paths.push_back(drawing::Path()); - } +private: + int getIndex(char ch); + std::vector paths; + std::unordered_map data; + drawing::Pen paint; + +public: + GlyPathBag(drawing::Pen const &paint) { + // Make indexed-by-one, to allow zero to represent non-cached + paths.push_back(drawing::Path()); + } drawing::Path getOrCreateAndCache(const char &ch, const std::string ¤t); - }; } // namespace rnoh::drawing - diff --git a/tester/harmony/svg/src/main/cpp/drawing/Path.cpp b/tester/harmony/svg/src/main/cpp/drawing/Path.cpp index 61b026fe..02d69dc7 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/Path.cpp +++ b/tester/harmony/svg/src/main/cpp/drawing/Path.cpp @@ -82,9 +82,7 @@ void Path::AddArc(const Rect &rect, float startAngle, float sweepAngle) { OH_Drawing_PathAddArc(get(), rect.get(), startAngle, sweepAngle); } -void Path::AddPath(const Path &src) { - OH_Drawing_PathAddPath(get(), src.get(), nullptr); -} +void Path::AddPath(const Path &src) { OH_Drawing_PathAddPath(get(), src.get(), nullptr); } void Path::AddPath(const Path &src, const Matrix &matrix) { OH_Drawing_PathAddPath(get(), src.get(), matrix.get()); } @@ -106,14 +104,14 @@ void Path::AddCircle(float x, float y, float radius, Direction direction) { OH_Drawing_PathAddCircle(get(), x, y, radius, direction); } -std::optional Path::BuildFromSvgString(const char *str) { +std::optional Path::BuildFromSvgString(const char *str) { Path path; if (OH_Drawing_PathBuildFromSvgString(path.get(), str)) { return path; } else { return std::nullopt; } - } +} bool Path::Contains(float x, float y) { return OH_Drawing_PathContains(get(), x, y); } @@ -160,9 +158,7 @@ bool Path::Union(Path &source) { return Op(source, PATH_OP_MODE_UNION); } bool Path::Xor(Path &source) { return Op(source, PATH_OP_MODE_XOR); } -bool Path::ReverseDifference(Path &source) { - return Op(source, PATH_OP_MODE_REVERSE_DIFFERENCE); -} +bool Path::ReverseDifference(Path &source) { return Op(source, PATH_OP_MODE_REVERSE_DIFFERENCE); } std::optional Path::GetMatrix(bool forceClosed, float distance, MeasureMatrixFlags flag) { Matrix matrix; diff --git a/tester/harmony/svg/src/main/cpp/drawing/Path.h b/tester/harmony/svg/src/main/cpp/drawing/Path.h index 6488b4a5..12b83d5f 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/Path.h +++ b/tester/harmony/svg/src/main/cpp/drawing/Path.h @@ -105,7 +105,7 @@ class Path final { OH_Drawing_Point2D *tangent); bool Op(Path &source, OpMode mode); - + bool Difference(Path &source); bool Intersect(Path &source); diff --git a/tester/harmony/svg/src/main/cpp/drawing/Pen.cpp b/tester/harmony/svg/src/main/cpp/drawing/Pen.cpp index c8ca8279..a5242734 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/Pen.cpp +++ b/tester/harmony/svg/src/main/cpp/drawing/Pen.cpp @@ -32,22 +32,22 @@ void Pen::SetLineCap(LineCapStyle lineCap) { OH_Drawing_PenSetCap(pen_.get(), li void Pen::SetLineJoin(LineJoinStyle lineJoin) { OH_Drawing_PenSetJoin(pen_.get(), lineJoin); } void Pen::SetLinearShaderEffect(const OH_Drawing_Point2D *startPt, const OH_Drawing_Point2D *endPt, - const uint32_t *colors, const float *pos, uint32_t size, OH_Drawing_TileMode mode, - const OH_Drawing_Matrix *mat) { + const uint32_t *colors, const float *pos, uint32_t size, OH_Drawing_TileMode mode, + const OH_Drawing_Matrix *mat) { penShaderEffect_.ShaderEffectCreateLinearGradient(startPt, endPt, colors, pos, size, mode, mat); OH_Drawing_PenSetShaderEffect(pen_.get(), penShaderEffect_.get()); } void Pen::SetRadialShaderEffect(const OH_Drawing_Point2D *startPt, float startRadius, const OH_Drawing_Point2D *endPt, - float endRadius, const uint32_t *colors, const float *pos, uint32_t size, - OH_Drawing_TileMode mode, const OH_Drawing_Matrix *mat) { + float endRadius, const uint32_t *colors, const float *pos, uint32_t size, + OH_Drawing_TileMode mode, const OH_Drawing_Matrix *mat) { penShaderEffect_.ShaderEffectCreateRadialGradient(startPt, startRadius, endPt, endRadius, colors, pos, size, mode, - mat); + mat); OH_Drawing_PenSetShaderEffect(pen_.get(), penShaderEffect_.get()); } void Pen::SetImageShaderEffect(OH_Drawing_Image *image, OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, - const OH_Drawing_SamplingOptions *opt, const OH_Drawing_Matrix *mat) { + const OH_Drawing_SamplingOptions *opt, const OH_Drawing_Matrix *mat) { penShaderEffect_.ShaderEffectCreateImageShader(image, tileX, tileY, opt, mat); OH_Drawing_PenSetShaderEffect(pen_.get(), penShaderEffect_.get()); } diff --git a/tester/harmony/svg/src/main/cpp/drawing/Rect.cpp b/tester/harmony/svg/src/main/cpp/drawing/Rect.cpp index e48db168..7934d863 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/Rect.cpp +++ b/tester/harmony/svg/src/main/cpp/drawing/Rect.cpp @@ -10,63 +10,38 @@ namespace rnoh { namespace drawing { Rect::Rect() : Rect(0, 0, 0, 0) {} -Rect::Rect(float left, float top, float right, float bottom) : rect_(UniqueNativeRect(OH_Drawing_RectCreate(left, top, right, bottom), &OH_Drawing_RectDestroy)) {} +Rect::Rect(float left, float top, float right, float bottom) + : rect_(UniqueNativeRect(OH_Drawing_RectCreate(left, top, right, bottom), &OH_Drawing_RectDestroy)) {} -Rect::Rect(Rect const &other) : Rect() { - *this = other; -} +Rect::Rect(Rect const &other) : Rect() { *this = other; } Rect &Rect::operator=(Rect const &other) { OH_Drawing_RectCopy(other.get(), get()); return *this; } -bool Rect::Intersect(const Rect &other) { - return OH_Drawing_RectIntersect(get(), other.get()); -} +bool Rect::Intersect(const Rect &other) { return OH_Drawing_RectIntersect(get(), other.get()); } -bool Rect::Join(const Rect &other) { - return OH_Drawing_RectJoin(get(), other.get()); -} +bool Rect::Join(const Rect &other) { return OH_Drawing_RectJoin(get(), other.get()); } -void Rect::SetLeft(float left) { - OH_Drawing_RectSetLeft(get(), left); -} +void Rect::SetLeft(float left) { OH_Drawing_RectSetLeft(get(), left); } -void Rect::SetTop(float top) { - OH_Drawing_RectSetTop(get(), top); -} +void Rect::SetTop(float top) { OH_Drawing_RectSetTop(get(), top); } -void Rect::SetRight(float right) { - OH_Drawing_RectSetRight(get(), right); -} +void Rect::SetRight(float right) { OH_Drawing_RectSetRight(get(), right); } -void Rect::SetBottom(float bottom) { - OH_Drawing_RectSetBottom(get(), bottom); -} +void Rect::SetBottom(float bottom) { OH_Drawing_RectSetBottom(get(), bottom); } -float Rect::GetLeft() { - return OH_Drawing_RectGetLeft(get()); -} +float Rect::GetLeft() { return OH_Drawing_RectGetLeft(get()); } -float Rect::GetTop() { - return OH_Drawing_RectGetTop(get()); -} +float Rect::GetTop() { return OH_Drawing_RectGetTop(get()); } -float Rect::GetRight() { - return OH_Drawing_RectGetRight(get()); -} +float Rect::GetRight() { return OH_Drawing_RectGetRight(get()); } -float Rect::GetBottom() { - return OH_Drawing_RectGetBottom(get()); -} +float Rect::GetBottom() { return OH_Drawing_RectGetBottom(get()); } -float Rect::GetHeight() { - return OH_Drawing_RectGetHeight(get()); -} +float Rect::GetHeight() { return OH_Drawing_RectGetHeight(get()); } -float Rect::GetWidth() { - return OH_Drawing_RectGetWidth(get()); -} +float Rect::GetWidth() { return OH_Drawing_RectGetWidth(get()); } } // namespace drawing } // namespace rnoh \ No newline at end of file diff --git a/tester/harmony/svg/src/main/cpp/drawing/ShaderEffect.cpp b/tester/harmony/svg/src/main/cpp/drawing/ShaderEffect.cpp index b4a51116..731dcacc 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/ShaderEffect.cpp +++ b/tester/harmony/svg/src/main/cpp/drawing/ShaderEffect.cpp @@ -10,25 +10,28 @@ namespace rnoh::drawing { ShaderEffect::ShaderEffect() : shaderEffect_(UniqueNativeShaderEffect(nullptr, &OH_Drawing_ShaderEffectDestroy)) {} -void ShaderEffect::ShaderEffectCreateLinearGradient(const OH_Drawing_Point2D* startPt, const OH_Drawing_Point2D* endPt, - const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode mode, const OH_Drawing_Matrix* mat) { +void ShaderEffect::ShaderEffectCreateLinearGradient(const OH_Drawing_Point2D *startPt, const OH_Drawing_Point2D *endPt, + const uint32_t *colors, const float *pos, uint32_t size, + OH_Drawing_TileMode mode, const OH_Drawing_Matrix *mat) { shaderEffect_ = UniqueNativeShaderEffect( OH_Drawing_ShaderEffectCreateLinearGradientWithLocalMatrix(startPt, endPt, colors, pos, size, mode, mat), &OH_Drawing_ShaderEffectDestroy); } -void ShaderEffect::ShaderEffectCreateRadialGradient(const OH_Drawing_Point2D* startPt, float startRadius, - const OH_Drawing_Point2D* endPt, float endRadius, const uint32_t* colors, const float* pos, uint32_t size, - OH_Drawing_TileMode mode, const OH_Drawing_Matrix* mat) { - shaderEffect_ = UniqueNativeShaderEffect( - OH_Drawing_ShaderEffectCreateTwoPointConicalGradient(startPt, startRadius, endPt, endRadius, colors, pos, size, - mode, mat), &OH_Drawing_ShaderEffectDestroy); +void ShaderEffect::ShaderEffectCreateRadialGradient(const OH_Drawing_Point2D *startPt, float startRadius, + const OH_Drawing_Point2D *endPt, float endRadius, + const uint32_t *colors, const float *pos, uint32_t size, + OH_Drawing_TileMode mode, const OH_Drawing_Matrix *mat) { + shaderEffect_ = UniqueNativeShaderEffect(OH_Drawing_ShaderEffectCreateTwoPointConicalGradient( + startPt, startRadius, endPt, endRadius, colors, pos, size, mode, mat), + &OH_Drawing_ShaderEffectDestroy); } -void ShaderEffect::ShaderEffectCreateImageShader(OH_Drawing_Image* image, OH_Drawing_TileMode tileX, - OH_Drawing_TileMode tileY, const OH_Drawing_SamplingOptions* opt, const OH_Drawing_Matrix* mat) { - shaderEffect_ = UniqueNativeShaderEffect( - OH_Drawing_ShaderEffectCreateImageShader(image, tileX, tileY, opt, mat), &OH_Drawing_ShaderEffectDestroy); +void ShaderEffect::ShaderEffectCreateImageShader(OH_Drawing_Image *image, OH_Drawing_TileMode tileX, + OH_Drawing_TileMode tileY, const OH_Drawing_SamplingOptions *opt, + const OH_Drawing_Matrix *mat) { + shaderEffect_ = UniqueNativeShaderEffect(OH_Drawing_ShaderEffectCreateImageShader(image, tileX, tileY, opt, mat), + &OH_Drawing_ShaderEffectDestroy); } } // namespace rnoh::drawing diff --git a/tester/harmony/svg/src/main/cpp/drawing/ShaderEffect.h b/tester/harmony/svg/src/main/cpp/drawing/ShaderEffect.h index dab9913f..538ae6e9 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/ShaderEffect.h +++ b/tester/harmony/svg/src/main/cpp/drawing/ShaderEffect.h @@ -16,27 +16,29 @@ namespace rnoh::drawing { class ShaderEffect final { - using UniqueNativeShaderEffect = std::unique_ptr; + using UniqueNativeShaderEffect = + std::unique_ptr; public: ShaderEffect(); - + ShaderEffect(ShaderEffect const &other) = delete; ShaderEffect &operator=(ShaderEffect const &other) = delete; - + ShaderEffect(ShaderEffect &&other) = default; ShaderEffect &operator=(ShaderEffect &&other) = default; - void ShaderEffectCreateLinearGradient( - const OH_Drawing_Point2D* startPt, const OH_Drawing_Point2D* endPt, const uint32_t* colors, const float* pos, - uint32_t size, OH_Drawing_TileMode mode, const OH_Drawing_Matrix* mat); + void ShaderEffectCreateLinearGradient(const OH_Drawing_Point2D *startPt, const OH_Drawing_Point2D *endPt, + const uint32_t *colors, const float *pos, uint32_t size, + OH_Drawing_TileMode mode, const OH_Drawing_Matrix *mat); - void ShaderEffectCreateRadialGradient( - const OH_Drawing_Point2D* startPt, float startRadius, const OH_Drawing_Point2D* endPt, float endRadius, - const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode mode, const OH_Drawing_Matrix* mat); + void ShaderEffectCreateRadialGradient(const OH_Drawing_Point2D *startPt, float startRadius, + const OH_Drawing_Point2D *endPt, float endRadius, const uint32_t *colors, + const float *pos, uint32_t size, OH_Drawing_TileMode mode, + const OH_Drawing_Matrix *mat); - void ShaderEffectCreateImageShader(OH_Drawing_Image* image, OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, - const OH_Drawing_SamplingOptions* opt, const OH_Drawing_Matrix* mat); + void ShaderEffectCreateImageShader(OH_Drawing_Image *image, OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, + const OH_Drawing_SamplingOptions *opt, const OH_Drawing_Matrix *mat); ~ShaderEffect() noexcept = default; diff --git a/tester/harmony/svg/src/main/cpp/drawing/TextStyle.h b/tester/harmony/svg/src/main/cpp/drawing/TextStyle.h index 7923a5f9..39469e1d 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/TextStyle.h +++ b/tester/harmony/svg/src/main/cpp/drawing/TextStyle.h @@ -14,7 +14,8 @@ namespace rnoh::drawing { class TextStyle final { -using UniqueTextStyle = std::unique_ptr; + using UniqueTextStyle = std::unique_ptr; + public: TextStyle(); ~TextStyle() noexcept = default; @@ -25,18 +26,16 @@ using UniqueTextStyle = std::unique_ptr& style); + void Update(const std::shared_ptr &style); // private: - UniqueTextStyle textStyle_; - friend class TypographyStyle; + UniqueTextStyle textStyle_; + friend class TypographyStyle; }; } // namespace rnoh::drawing \ No newline at end of file diff --git a/tester/harmony/svg/src/main/cpp/drawing/Typography.cpp b/tester/harmony/svg/src/main/cpp/drawing/Typography.cpp index a7328695..4d796dbf 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/Typography.cpp +++ b/tester/harmony/svg/src/main/cpp/drawing/Typography.cpp @@ -6,4 +6,4 @@ #include "Typography.h" -//NO-OP \ No newline at end of file +// NO-OP \ No newline at end of file diff --git a/tester/harmony/svg/src/main/cpp/drawing/Typography.h b/tester/harmony/svg/src/main/cpp/drawing/Typography.h index 69290fda..387f753b 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/Typography.h +++ b/tester/harmony/svg/src/main/cpp/drawing/Typography.h @@ -13,7 +13,8 @@ namespace rnoh::drawing { class Typography { public: - Typography(OH_Drawing_TypographyCreate* handler) : typ_(TypUPtr(OH_Drawing_CreateTypography(handler), OH_Drawing_DestroyTypography)) {} + Typography(OH_Drawing_TypographyCreate *handler) + : typ_(TypUPtr(OH_Drawing_CreateTypography(handler), OH_Drawing_DestroyTypography)) {} OH_Drawing_Typography *operator&() { return typ_.get(); } private: @@ -21,4 +22,4 @@ class Typography { TypUPtr typ_; }; -} // namespace rnoh \ No newline at end of file +} // namespace rnoh::drawing \ No newline at end of file diff --git a/tester/harmony/svg/src/main/cpp/drawing/TypographyStyle.cpp b/tester/harmony/svg/src/main/cpp/drawing/TypographyStyle.cpp index 0b8c6d75..6fd9ffdc 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/TypographyStyle.cpp +++ b/tester/harmony/svg/src/main/cpp/drawing/TypographyStyle.cpp @@ -20,12 +20,12 @@ void TypographyStyle::SetTextStyle(TextStyle textStyle) { } void TypographyStyle::Update(const std::shared_ptr &style) { - auto* ts = typographyStyle_.get(); + auto *ts = typographyStyle_.get(); OH_Drawing_SetTypographyTextFontWeight(ts, style->absoluteFontWeight); OH_Drawing_SetTypographyTextFontStyle(ts, static_cast(style->fontStyle)); OH_Drawing_SetTypographyTextFontFamily(ts, style->fontFamily.c_str()); OH_Drawing_SetTypographyTextFontSize(ts, style->fontSize); - // OH_Drawing_SetTypographyTextAlign(ts, static_cast(style->textAnchor)); + // to be done? TypographyTextAlign } } // namespace rnoh::drawing diff --git a/tester/harmony/svg/src/main/cpp/drawing/TypographyStyle.h b/tester/harmony/svg/src/main/cpp/drawing/TypographyStyle.h index ff6d2152..cb500dda 100644 --- a/tester/harmony/svg/src/main/cpp/drawing/TypographyStyle.h +++ b/tester/harmony/svg/src/main/cpp/drawing/TypographyStyle.h @@ -28,13 +28,12 @@ class TypographyStyle final { TypographyStyle &operator=(const TypographyStyle &) = delete; TypographyStyle(TypographyStyle &&other) = default; - TypographyStyle &operator=(TypographyStyle && other) = default; + TypographyStyle &operator=(TypographyStyle &&other) = default; void SetTextStyle(TextStyle textStyle); void Update(const std::shared_ptr &style); - // private: UniqueTypographyStyle typographyStyle_; TextStyle::UniqueTextStyle textStyle_ = {nullptr, OH_Drawing_DestroyTextStyle}; }; diff --git a/tester/harmony/svg/src/main/cpp/properties/Color.cpp b/tester/harmony/svg/src/main/cpp/properties/Color.cpp index ceb65f84..f668270e 100644 --- a/tester/harmony/svg/src/main/cpp/properties/Color.cpp +++ b/tester/harmony/svg/src/main/cpp/properties/Color.cpp @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/properties/Color.h b/tester/harmony/svg/src/main/cpp/properties/Color.h index 707a1bf1..dae952cc 100644 --- a/tester/harmony/svg/src/main/cpp/properties/Color.h +++ b/tester/harmony/svg/src/main/cpp/properties/Color.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/properties/Decoration.cpp b/tester/harmony/svg/src/main/cpp/properties/Decoration.cpp index bfbc1d18..b5e55a30 100755 --- a/tester/harmony/svg/src/main/cpp/properties/Decoration.cpp +++ b/tester/harmony/svg/src/main/cpp/properties/Decoration.cpp @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/properties/Decoration.h b/tester/harmony/svg/src/main/cpp/properties/Decoration.h index 7bcf2607..0f5fa697 100755 --- a/tester/harmony/svg/src/main/cpp/properties/Decoration.h +++ b/tester/harmony/svg/src/main/cpp/properties/Decoration.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/properties/Dimension.cpp b/tester/harmony/svg/src/main/cpp/properties/Dimension.cpp index f4f2c980..4fe39550 100644 --- a/tester/harmony/svg/src/main/cpp/properties/Dimension.cpp +++ b/tester/harmony/svg/src/main/cpp/properties/Dimension.cpp @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/properties/Dimension.h b/tester/harmony/svg/src/main/cpp/properties/Dimension.h index 2f9f8dd5..405108c1 100644 --- a/tester/harmony/svg/src/main/cpp/properties/Dimension.h +++ b/tester/harmony/svg/src/main/cpp/properties/Dimension.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -118,21 +118,9 @@ class Dimension { if (unit_ == DimensionUnit::VP) { return value_; } - -// auto pipeline = PipelineBase::GetCurrentContextSafely(); -// CHECK_NULL_RETURN(pipeline, 0.0); -// if (unit_ == DimensionUnit::NONE) { -// return value_ / pipeline->GetDipScale(); -// } if (unit_ == DimensionUnit::PX) { return value_ / scale; } -// if (unit_ == DimensionUnit::FP) { -// return value_ * pipeline->GetFontScale(); -// } -// if (unit_ == DimensionUnit::LPX) { -// return value_ * pipeline->GetLogicScale() / pipeline->GetDipScale(); -// } return 0.0; }; @@ -144,19 +132,12 @@ class Dimension { if (unit_ == DimensionUnit::PX) { return value_; } - -// auto pipeline = PipelineBase::GetCurrentContextSafely(); -// CHECK_NULL_RETURN(pipeline, 0.0); if (unit_ == DimensionUnit::VP) { return value_ * scale; } if (unit_ == DimensionUnit::FP) { -// return value_ * pipeline->GetDipScale() * pipeline->GetFontScale(); return value_ * scale; } -// if (unit_ == DimensionUnit::LPX) { -// return value_ * pipeline->GetLogicScale(); -// } return 0.0; }; diff --git a/tester/harmony/svg/src/main/cpp/properties/Font.cpp b/tester/harmony/svg/src/main/cpp/properties/Font.cpp index aa2f8ff2..62651268 100644 --- a/tester/harmony/svg/src/main/cpp/properties/Font.cpp +++ b/tester/harmony/svg/src/main/cpp/properties/Font.cpp @@ -10,9 +10,9 @@ namespace rnoh { namespace svg { -double FontData::toAbsolute(const std::string &value, double scale, double fontSize, double relative) { +double FontData::toAbsolute(const std::string &value, double scale, double fontSz, double relative) { auto val = StringUtils::FromString(value); - return val.RelativeConvertToPx(fontSize, scale); + return val.RelativeConvertToPx(fontSz, scale); } void FontData::setInheritedWeight(const FontData &parent) { @@ -72,7 +72,7 @@ FontData::FontData(const FontProps &props, const FontData &parent, double scale) !props.letterSpacing.empty() ? toAbsolute(props.letterSpacing, scale, fontSize, 0) : parent.letterSpacing; } -const double FontData::DEFAULT_FONT_SIZE = vpToPx(12.0); +const double FontData::DEFAULT_FONT_SIZE = 3.25 * 12.0; const double FontData::DEFAULT_KERNING = 0.0; const double FontData::DEFAULT_WORD_SPACING = 0.0; const double FontData::DEFAULT_LETTER_SPACING = 0.0; diff --git a/tester/harmony/svg/src/main/cpp/properties/Font.h b/tester/harmony/svg/src/main/cpp/properties/Font.h index e341abee..8f1cb393 100644 --- a/tester/harmony/svg/src/main/cpp/properties/Font.h +++ b/tester/harmony/svg/src/main/cpp/properties/Font.h @@ -11,6 +11,17 @@ namespace rnoh { namespace svg { +constexpr int LIGHTER_THRESHOLD_550 = 550; +constexpr int LIGHTER_THRESHOLD_750 = 750; +constexpr int BOLDER_THRESHOLD_350 = 350; +constexpr int BOLDER_THRESHOLD_550 = 550; +constexpr int BOLDER_THRESHOLD_900 = 900; +constexpr int DEFAULT_BOLDER_WEIGHT = 400; +constexpr int DEFAULT_LIGHTER_WEIGHT = 100; +constexpr int DEFAULT_MEDIUM_WEIGHT = 400; +constexpr int DEFAULT_BOLDER_WEIGHT_700 = 700; +constexpr int DEFAULT_BOLDER_WEIGHT_900 = 900; + enum class FontStyle { normal, italic, oblique }; enum class FontWeight { @@ -42,7 +53,6 @@ TextAnchor textAnchorFromStr(const std::string &str); TextDecoration textDecorationFromStr(const std::string &str); FontVariantLigatures fontVariantFromStr(const std::string &str); - // intermediate data to store in Svg nodes struct FontProps { std::string fontStyle; @@ -103,49 +113,48 @@ class FontData { void handleNumericWeight(const FontData &parent, double number); - private: static const int normal = 400; static const FontWeight WEIGHTS[]; - static FontWeight nearestFontWeight(int absoluteFontWeight) { - return WEIGHTS[static_cast(absoluteFontWeight / 100.0f)]; + static FontWeight nearestFontWeight(int abFontWeight) { + return WEIGHTS[static_cast(abFontWeight / 100.0f)]; } static const int absoluteFontWeights[]; - static int from(FontWeight fontWeight, const FontData &parent) { - if (fontWeight == FontWeight::bolder) { + static int from(FontWeight fontW, const FontData &parent) { + if (fontW == FontWeight::bolder) { return WeightToBolder(parent.absoluteFontWeight); - } else if (fontWeight == FontWeight::lighter) { + } else if (fontW == FontWeight::lighter) { return lighter(parent.absoluteFontWeight); } else { - return absoluteFontWeights[static_cast(fontWeight)]; + return absoluteFontWeights[static_cast(fontW)]; } } static int WeightToBolder(int inherited) { - if (inherited < 350) { - return 400; - } else if (inherited < 550) { - return 700; - } else if (inherited < 900) { - return 900; + if (inherited < BOLDER_THRESHOLD_350) { + return DEFAULT_BOLDER_WEIGHT; + } else if (inherited < BOLDER_THRESHOLD_550) { + return DEFAULT_BOLDER_WEIGHT_700; + } else if (inherited < BOLDER_THRESHOLD_900) { + return DEFAULT_BOLDER_WEIGHT_900; } else { return inherited; } } static int lighter(int inherited) { - if (inherited < 100) { + if (inherited < DEFAULT_LIGHTER_WEIGHT) { return inherited; - } else if (inherited < 550) { - return 100; - } else if (inherited < 750) { - return 400; + } else if (inherited < LIGHTER_THRESHOLD_550) { + return DEFAULT_LIGHTER_WEIGHT; + } else if (inherited < LIGHTER_THRESHOLD_750) { + return DEFAULT_MEDIUM_WEIGHT; } else { - return 700; + return DEFAULT_BOLDER_WEIGHT_700; } } }; diff --git a/tester/harmony/svg/src/main/cpp/properties/Offset.h b/tester/harmony/svg/src/main/cpp/properties/Offset.h index dd085f82..530ac6b5 100755 --- a/tester/harmony/svg/src/main/cpp/properties/Offset.h +++ b/tester/harmony/svg/src/main/cpp/properties/Offset.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -40,8 +40,6 @@ class Offset { void Reset() { deltaX_ = 0.0; deltaY_ = 0.0; -// deltaXAnimationOption_ = AnimationOption(); -// deltaYAnimationOption_ = AnimationOption(); } static Offset Zero() { return Offset(); } diff --git a/tester/harmony/svg/src/main/cpp/properties/PaintState.h b/tester/harmony/svg/src/main/cpp/properties/PaintState.h index ff2bc180..77207638 100644 --- a/tester/harmony/svg/src/main/cpp/properties/PaintState.h +++ b/tester/harmony/svg/src/main/cpp/properties/PaintState.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -101,17 +101,6 @@ struct CanvasImage { int32_t instanceId = 0; }; -// struct ImageData { -// RefPtr pixelMap; -// int32_t x = 0; -// int32_t y = 0; -// int32_t dirtyX = 0; -// int32_t dirtyY = 0; -// int32_t dirtyWidth = 0; -// int32_t dirtyHeight = 0; -// std::vector data; -// }; - struct TextMetrics { double width = 0; double height = 0; @@ -171,219 +160,54 @@ enum class CompositeOperation { XOR, }; -enum class PaintStyle { - NONE = 0, - Color, - Gradient, - ImagePattern -}; +enum class PaintStyle { NONE = 0, Color, Gradient, ImagePattern }; class PaintState { public: - const Color& GetColor() const - { - return color_; - } + const Color &GetColor() const { return color_; } - void SetColor(const Color& color) - { + void SetColor(const Color &color) { paintStyle_ = PaintStyle::Color; color_ = color; } -// const Gradient& GetGradient() const -// { -// return gradient_; -// } -// -// void SetGradient(const Gradient& gradient) -// { -// paintStyle_ = PaintStyle::Gradient; -// gradient_ = gradient; -// } - -// const TextStyle& GetTextStyle() const -// { -// return textStyle_; -// } -// -// void SetTextStyle(const TextStyle& textStyle) -// { -// textStyle_ = textStyle; -// } -// -// TextAlign GetTextAlign() const -// { -// return textAlign_; -// } -// -// void SetTextAlign(TextAlign textAlign) -// { -// textAlign_ = textAlign; -// } -// -// TextDirection GetOffTextDirection() const -// { -// return textDirection_; -// } -// -// void SetOffTextDirection(TextDirection textDirection) -// { -// textDirection_ = textDirection; -// } -// -// void SetTextColor(const Color& color) -// { -// textStyle_.SetTextColor(color); -// } -// -// void SetFontSize(const Dimension& size) -// { -// textStyle_.SetFontSize(size); -// } -// -// void SetFontStyle(FontStyle style) -// { -// textStyle_.SetFontStyle(style); -// } -// -// void SetFontWeight(FontWeight weight) -// { -// textStyle_.SetFontWeight(weight); -// } -// -// void SetFontFamilies(const std::vector& fontFamilies) -// { -// textStyle_.SetFontFamilies(fontFamilies); -// } -// -// void SetTextBaseline(TextBaseline baseline) -// { -// textStyle_.SetTextBaseline(baseline); -// } -// -// const Pattern& GetPattern() const -// { -// return pattern_; -// } -// -// void SetPattern(const Pattern& pattern) -// { -// paintStyle_ = PaintStyle::ImagePattern; -// pattern_ = pattern; -// } -// -// std::weak_ptr GetPatternNG() const -// { -// return patternNG_; -// } -// -// Ace::Pattern GetPatternValue() const -// { -// Pattern pattern; -// if (!patternNG_.expired()) { -// auto value = patternNG_.lock(); -// if (value) { -// pattern = *value; -// } -// } -// return pattern; -// } -// -// void SetPatternNG(const std::weak_ptr& pattern) -// { -// paintStyle_ = PaintStyle::ImagePattern; -// patternNG_ = pattern; -// } - - int32_t GetId() const - { - return id_; - } + int32_t GetId() const { return id_; } - void SetId(int32_t id) - { - id_ = id; - } + void SetId(int32_t id) { id_ = id; } - PaintStyle GetPaintStyle() const - { - return paintStyle_; - } + PaintStyle GetPaintStyle() const { return paintStyle_; } protected: Color color_ = Color::BLACK; -// Gradient gradient_; -// TextStyle textStyle_; -// TextAlign textAlign_ = TextAlign::LEFT; -// TextDirection textDirection_ = TextDirection::LTR; int32_t id_ = 0; PaintStyle paintStyle_ = PaintStyle::Color; -// Pattern pattern_; -// std::weak_ptr patternNG_; }; class StrokePaintState : public PaintState { public: - LineCapStyle GetLineCap() const - { - return lineCap_; - } + LineCapStyle GetLineCap() const { return lineCap_; } - void SetLineCap(LineCapStyle lineCap) - { - lineCap_ = lineCap; - } + void SetLineCap(LineCapStyle lineCap) { lineCap_ = lineCap; } - LineJoinStyle GetLineJoin() const - { - return lineJoin_; - } + LineJoinStyle GetLineJoin() const { return lineJoin_; } - void SetLineJoin(LineJoinStyle lineJoin) - { - lineJoin_ = lineJoin; - } + void SetLineJoin(LineJoinStyle lineJoin) { lineJoin_ = lineJoin; } - double GetLineWidth() const - { - return lineWidth_; - } + double GetLineWidth() const { return lineWidth_; } - void SetLineWidth(double lineWidth) - { - lineWidth_ = lineWidth; - } + void SetLineWidth(double lineWidth) { lineWidth_ = lineWidth; } - double GetMiterLimit() const - { - return miterLimit_; - } + double GetMiterLimit() const { return miterLimit_; } - void SetMiterLimit(double miterLimit) - { - miterLimit_ = miterLimit; - } + void SetMiterLimit(double miterLimit) { miterLimit_ = miterLimit; } - LineDashParam GetLineDash() const - { - return lineDash_; - } + LineDashParam GetLineDash() const { return lineDash_; } - void SetLineDash(const LineDashParam& lineDash) - { - lineDash_ = lineDash; - } + void SetLineDash(const LineDashParam &lineDash) { lineDash_ = lineDash; } - void SetLineDashOffset(double offset) - { - lineDash_.dashOffset = offset; - } + void SetLineDashOffset(double offset) { lineDash_.dashOffset = offset; } - void SetLineDash(const std::vector& segments) - { - lineDash_.lineDash = segments; - } + void SetLineDash(const std::vector &segments) { lineDash_.lineDash = segments; } private: LineCapStyle lineCap_ = LineCapStyle::BUTT; @@ -397,42 +221,20 @@ class StrokePaintState : public PaintState { class GlobalPaintState { public: - double GetAlpha() const - { - return alpha_; - } + double GetAlpha() const { return alpha_; } - void SetAlpha(double alpha) - { - alpha_ = alpha; - } + void SetAlpha(double alpha) { alpha_ = alpha; } - CompositeOperation GetType() const - { - return type_; - } + CompositeOperation GetType() const { return type_; } - void SetType(CompositeOperation type) - { - type_ = type; - } + void SetType(CompositeOperation type) { type_ = type; } - bool HasGlobalAlpha() const - { - return !NearEqual(alpha_, -1.0); - } + bool HasGlobalAlpha() const { return !NearEqual(alpha_, -1.0); } private: double alpha_ = -1.0; CompositeOperation type_ = CompositeOperation::SOURCE_OVER; }; -// struct PaintHolder { -// PaintState fillState; -// StrokePaintState strokeState; -// GlobalPaintState globalState; -// Shadow shadow; -// }; - } // namespace svg } // namespace rnoh diff --git a/tester/harmony/svg/src/main/cpp/properties/Rect.h b/tester/harmony/svg/src/main/cpp/properties/Rect.h index 00a22363..814aef4d 100644 --- a/tester/harmony/svg/src/main/cpp/properties/Rect.h +++ b/tester/harmony/svg/src/main/cpp/properties/Rect.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/properties/Size.h b/tester/harmony/svg/src/main/cpp/properties/Size.h index a6f21c5f..4d60cdd3 100644 --- a/tester/harmony/svg/src/main/cpp/properties/Size.h +++ b/tester/harmony/svg/src/main/cpp/properties/Size.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/properties/SvgPaintState.h b/tester/harmony/svg/src/main/cpp/properties/SvgPaintState.h index 17a209bb..e8de0f66 100644 --- a/tester/harmony/svg/src/main/cpp/properties/SvgPaintState.h +++ b/tester/harmony/svg/src/main/cpp/properties/SvgPaintState.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -46,11 +46,6 @@ const char ATTR_NAME_FILL_RULE_EVENODD[] = "evenodd"; class FillState { public: -// void SetContextAndCallback(const WeakPtr &context, const RenderNodeAnimationCallback &callback) { -// color_.SetContextAndCallback(context, callback); -// opacity_.SetContextAndCallback(context, callback); -// } -// enum class FillRule { FILL_RULE_EVEN_ODD = 0, FILL_RULE_NONZERO = 1 @@ -152,14 +147,6 @@ class FillState { class StrokeState { public: -// void SetContextAndCallback(const WeakPtr& context, const RenderNodeAnimationCallback& callback) -// { -// lineWidth_.SetContextAndCallback(context, callback); -// color_.SetContextAndCallback(context, callback); -// opacity_.SetContextAndCallback(context, callback); -// strokeDashOffset_.SetContextAndCallback(context, callback); -// } -// const Color& GetColor() const { return color_; diff --git a/tester/harmony/svg/src/main/cpp/properties/TextProperties.cpp b/tester/harmony/svg/src/main/cpp/properties/TextProperties.cpp index d39ae8ac..c34c998b 100644 --- a/tester/harmony/svg/src/main/cpp/properties/TextProperties.cpp +++ b/tester/harmony/svg/src/main/cpp/properties/TextProperties.cpp @@ -47,7 +47,6 @@ TextLengthAdjust textLengthAdjustFromStr(const std::string &str) { } else { return TextLengthAdjust::spacingAndGlyphs; } - } AlignmentBaseline alignmentBaselineFromStr(const std::string &str) { diff --git a/tester/harmony/svg/src/main/cpp/properties/ViewBox.h b/tester/harmony/svg/src/main/cpp/properties/ViewBox.h index cc8a9a40..089725a1 100644 --- a/tester/harmony/svg/src/main/cpp/properties/ViewBox.h +++ b/tester/harmony/svg/src/main/cpp/properties/ViewBox.h @@ -37,10 +37,10 @@ class ViewBox { double eHeight = eRect.Height(); // Initialize scale-x to e-width/vb-width. - double scaleX = eWidth / vbWidth; + double scaleX = (vbWidth != 0) ? eWidth / vbWidth : 0.0; // Initialize scale-y to e-height/vb-height. - double scaleY = eHeight / vbHeight; + double scaleY = (vbHeight != 0) ? eHeight / vbHeight : 0.0; // Initialize translate-x to e-x - (vb-x * scale-x). // Initialize translate-y to e-y - (vb-y * scale-y). diff --git a/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageComponentDescriptor.h b/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageComponentDescriptor.h index 87a29e39..5f50495e 100644 --- a/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageComponentDescriptor.h +++ b/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageComponentDescriptor.h @@ -19,26 +19,23 @@ namespace react { /* * Descriptor for component. */ -class RNSVGImageComponentDescriptor final - : public ConcreteComponentDescriptor { - public: - RNSVGImageComponentDescriptor(ComponentDescriptorParameters const ¶meters) - : ConcreteComponentDescriptor(parameters), - imageManager_(std::make_shared(contextContainer_)){}; - - void adopt(ShadowNode::Unshared const &shadowNode) const override { - ConcreteComponentDescriptor::adopt(shadowNode); - - auto imageShadowNode = - std::static_pointer_cast(shadowNode); - - // `RNSVGImageShadowNode` uses `ImageManager` to initiate image loading and - // communicate the loading state and results to mounting layer. - imageShadowNode->setImageManager(imageManager_); - } - - private: - const SharedImageManager imageManager_; +class RNSVGImageComponentDescriptor final : public ConcreteComponentDescriptor { +public: + RNSVGImageComponentDescriptor(ComponentDescriptorParameters const ¶meters) + : ConcreteComponentDescriptor(parameters), imageManager_(std::make_shared(contextContainer_)){}; + + void adopt(ShadowNode::Unshared const &shadowNode) const override { + ConcreteComponentDescriptor::adopt(shadowNode); + + auto imageShadowNode = std::static_pointer_cast(shadowNode); + + // `RNSVGImageShadowNode` uses `ImageManager` to initiate image loading and + // communicate the loading state and results to mounting layer. + imageShadowNode->setImageManager(imageManager_); + } + +private: + const SharedImageManager imageManager_; }; } // namespace react diff --git a/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.cpp b/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.cpp index 22d5f9c2..b2a47838 100644 --- a/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.cpp +++ b/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.cpp @@ -17,46 +17,45 @@ namespace react { const char RNSVGImageComponentName[] = "RNSVGImage"; -void RNSVGImageShadowNode::setImageManager( - const SharedImageManager &imageManager) { - ensureUnsealed(); - imageManager_ = imageManager; +void RNSVGImageShadowNode::setImageManager(const SharedImageManager &imageManager) { + ensureUnsealed(); + imageManager_ = imageManager; } ImageSource RNSVGImageShadowNode::getImageSource() const { - auto source = getConcreteProps().src; - - auto layoutMetrics = getLayoutMetrics(); - auto size = layoutMetrics.getContentFrame().size; - auto scale = layoutMetrics.pointScaleFactor; - source.size = size; - source.scale = scale; - return source; + auto source = getConcreteProps().src; + + auto layoutMetrics = getLayoutMetrics(); + auto size = layoutMetrics.getContentFrame().size; + auto scale = layoutMetrics.pointScaleFactor; + source.size = size; + source.scale = scale; + return source; } void RNSVGImageShadowNode::updateStateIfNeeded() { - ensureUnsealed(); + ensureUnsealed(); - auto imageSource = getImageSource(); - auto const ¤tState = getStateData(); - bool hasSameImageSource = currentState.getImageSource() == imageSource; + auto imageSource = getImageSource(); + auto const ¤tState = getStateData(); + bool hasSameImageSource = currentState.getImageSource() == imageSource; - if (hasSameImageSource) { - return; - } + if (hasSameImageSource) { + return; + } - auto state = RNSVGImageState{ - imageSource, - imageManager_->requestImage(imageSource, getSurfaceId()), - }; - setStateData(std::move(state)); + auto state = RNSVGImageState{ + imageSource, + imageManager_->requestImage(imageSource, getSurfaceId()), + }; + setStateData(std::move(state)); } #pragma mark - LayoutableShadowNode void RNSVGImageShadowNode::layout(LayoutContext layoutContext) { - updateStateIfNeeded(); - ConcreteViewShadowNode::layout(layoutContext); + updateStateIfNeeded(); + ConcreteViewShadowNode::layout(layoutContext); } } // namespace react diff --git a/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.h b/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.h index 01578a88..61445ae4 100644 --- a/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.h +++ b/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageShadowNode.h @@ -24,43 +24,39 @@ JSI_EXPORT extern const char RNSVGImageComponentName[]; /* * `ShadowNode` for component. */ -class JSI_EXPORT RNSVGImageShadowNode final : public ConcreteViewShadowNode< - RNSVGImageComponentName, - RNSVGImageProps, - ViewEventEmitter, - RNSVGImageState> { - public: - using ConcreteViewShadowNode::ConcreteViewShadowNode; - - static ShadowNodeTraits BaseTraits() { - auto traits = ConcreteViewShadowNode::BaseTraits(); - traits.set(ShadowNodeTraits::Trait::LeafYogaNode); - return traits; - } - - /* - * Associates a shared `ImageManager` with the node. - */ - void setImageManager(const SharedImageManager &imageManager); - - static RNSVGImageState initialStateData( - ShadowNodeFragment const &fragment, - ShadowNodeFamilyFragment const &familyFragment, - ComponentDescriptor const &componentDescriptor) { - auto imageSource = ImageSource{ImageSource::Type::Invalid}; - return {imageSource, {imageSource, nullptr, {}}}; - } +class JSI_EXPORT RNSVGImageShadowNode final + : public ConcreteViewShadowNode { +public: + using ConcreteViewShadowNode::ConcreteViewShadowNode; + + static ShadowNodeTraits BaseTraits() { + auto traits = ConcreteViewShadowNode::BaseTraits(); + traits.set(ShadowNodeTraits::Trait::LeafYogaNode); + return traits; + } + + /* + * Associates a shared `ImageManager` with the node. + */ + void setImageManager(const SharedImageManager &imageManager); + + static RNSVGImageState initialStateData(ShadowNodeFragment const &fragment, + ShadowNodeFamilyFragment const &familyFragment, + ComponentDescriptor const &componentDescriptor) { + auto imageSource = ImageSource{ImageSource::Type::Invalid}; + return {imageSource, {imageSource, nullptr, {}}}; + } #pragma mark - LayoutableShadowNode - void layout(LayoutContext layoutContext) override; + void layout(LayoutContext layoutContext) override; - private: - ImageSource getImageSource() const; +private: + ImageSource getImageSource() const; - SharedImageManager imageManager_; + SharedImageManager imageManager_; - void updateStateIfNeeded(); + void updateStateIfNeeded(); }; } // namespace react diff --git a/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.cpp b/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.cpp index ee42a2d4..cebd0e5b 100644 --- a/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.cpp +++ b/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.cpp @@ -10,12 +10,8 @@ namespace facebook { namespace react { -ImageSource RNSVGImageState::getImageSource() const { - return imageSource_; -} +ImageSource RNSVGImageState::getImageSource() const { return imageSource_; } -ImageRequest const &RNSVGImageState::getImageRequest() const { - return *imageRequest_; -} +ImageRequest const &RNSVGImageState::getImageRequest() const { return *imageRequest_; } } // namespace react } // namespace facebook diff --git a/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.h b/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.h index 746b8010..ed82c50c 100644 --- a/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.h +++ b/tester/harmony/svg/src/main/cpp/svgImage/RNSVGImageState.h @@ -23,41 +23,35 @@ namespace react { * State for component. */ class JSI_EXPORT RNSVGImageState final { - public: - RNSVGImageState(ImageSource const &imageSource, ImageRequest imageRequest) - : imageSource_(imageSource), - imageRequest_( - std::make_shared(std::move(imageRequest))){}; +public: + RNSVGImageState(ImageSource const &imageSource, ImageRequest imageRequest) + : imageSource_(imageSource), imageRequest_(std::make_shared(std::move(imageRequest))){}; - /* - * Returns stored ImageSource object. - */ - ImageSource getImageSource() const; + /* + * Returns stored ImageSource object. + */ + ImageSource getImageSource() const; - /* - * Exposes for reading stored `ImageRequest` object. - * `ImageRequest` object cannot be copied or moved from `ImageLocalData`. - */ - ImageRequest const &getImageRequest() const; + /* + * Exposes for reading stored `ImageRequest` object. + * `ImageRequest` object cannot be copied or moved from `ImageLocalData`. + */ + ImageRequest const &getImageRequest() const; #ifdef ANDROID - RNSVGImageState(RNSVGImageState const &previousState, folly::dynamic data){}; + RNSVGImageState(RNSVGImageState const &previousState, folly::dynamic data){}; - /* - * Empty implementation for Android because it doesn't use this class. - */ - folly::dynamic getDynamic() const { - return {}; - }; + /* + * Empty implementation for Android because it doesn't use this class. + */ + folly::dynamic getDynamic() const { return {}; }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + MapBuffer getMapBuffer() const { return MapBufferBuilder::EMPTY(); }; #endif - private: - ImageSource imageSource_; - std::shared_ptr imageRequest_; +private: + ImageSource imageSource_; + std::shared_ptr imageRequest_; }; } // namespace react diff --git a/tester/harmony/svg/src/main/cpp/turboModules/RNSVGImageModule.cpp b/tester/harmony/svg/src/main/cpp/turboModules/RNSVGImageModule.cpp index 444c9318..e5a9c07f 100644 --- a/tester/harmony/svg/src/main/cpp/turboModules/RNSVGImageModule.cpp +++ b/tester/harmony/svg/src/main/cpp/turboModules/RNSVGImageModule.cpp @@ -9,9 +9,7 @@ using namespace rnoh; using namespace facebook; -RNSVGImageModule::RNSVGImageModule( - const ArkTSTurboModule::Context ctx, - const std::string name) +RNSVGImageModule::RNSVGImageModule(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) { methodMap_ = { ARK_ASYNC_METHOD_METADATA(getBase64String, 1), diff --git a/tester/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.cpp b/tester/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.cpp index 5870aaf5..a8dc18c8 100644 --- a/tester/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.cpp +++ b/tester/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.cpp @@ -12,16 +12,26 @@ using namespace react; namespace rnoh { namespace svg { -bool RNSVGRenderableModule::isPointInFill(facebook::jsi::Runtime &rt, int32_t tag, std::optional options) { return false; } -bool RNSVGRenderableModule::isPointInStroke(facebook::jsi::Runtime &rt, int32_t tag, std::optional options) { return false; } -double RNSVGRenderableModule::getTotalLength(jsi::Runtime &rt, int32_t tag){return 0;} -jsi::Object RNSVGRenderableModule::getPointAtLength(jsi::Runtime &rt, int32_t tag, std::optional options){return jsi::Object(rt);}; -jsi::Object RNSVGRenderableModule::getBBox(jsi::Runtime &rt, int32_t tag, std::optional options){return jsi::Object(rt);}; -jsi::Object RNSVGRenderableModule::getCTM(jsi::Runtime &rt, int32_t tag){return jsi::Object(rt);}; -jsi::Object RNSVGRenderableModule::getScreenCTM(jsi::Runtime &rt, int32_t tag){return jsi::Object(rt);}; -jsi::Value RNSVGRenderableModule::getRawResource(jsi::Runtime &rt, jsi::String name){return jsi::Object(rt);}; +bool RNSVGRenderableModule::isPointInFill(facebook::jsi::Runtime &rt, int32_t tag, std::optional options) { + return false; +} +bool RNSVGRenderableModule::isPointInStroke(facebook::jsi::Runtime &rt, int32_t tag, + std::optional options) { + return false; +} +double RNSVGRenderableModule::getTotalLength(jsi::Runtime &rt, int32_t tag) { return 0; } +jsi::Object RNSVGRenderableModule::getPointAtLength(jsi::Runtime &rt, int32_t tag, std::optional options) { + return jsi::Object(rt); +}; +jsi::Object RNSVGRenderableModule::getBBox(jsi::Runtime &rt, int32_t tag, std::optional options) { + return jsi::Object(rt); +}; +jsi::Object RNSVGRenderableModule::getCTM(jsi::Runtime &rt, int32_t tag) { return jsi::Object(rt); }; +jsi::Object RNSVGRenderableModule::getScreenCTM(jsi::Runtime &rt, int32_t tag) { return jsi::Object(rt); }; +jsi::Value RNSVGRenderableModule::getRawResource(jsi::Runtime &rt, jsi::String name) { return jsi::Object(rt); }; -static jsi::Value __hostFunction_RNSVGRenderableModule_isPointInFill(jsi::Runtime &rt,react::TurboModule &turboModule,const jsi::Value *args,size_t count) { +static jsi::Value __hostFunction_RNSVGRenderableModule_isPointInFill(jsi::Runtime &rt, react::TurboModule &turboModule, + const jsi::Value *args, size_t count) { return static_cast(&turboModule) ->isPointInFill( rt, args[0].isNull() || args[0].isUndefined() ? 0 : std::make_optional(args[0].asNumber()).value(), @@ -30,59 +40,49 @@ static jsi::Value __hostFunction_RNSVGRenderableModule_isPointInFill(jsi::Runtim } static jsi::Value __hostFunction_RNSVGRenderableModule_isPointInStroke(jsi::Runtime &rt, - react::TurboModule &turboModule, - const jsi::Value *args, - size_t count) { + react::TurboModule &turboModule, + const jsi::Value *args, size_t count) { return static_cast(&turboModule) ->isPointInStroke( rt, args[0].isNull() || args[0].isUndefined() ? 0 : std::make_optional(args[0].asNumber()).value(), count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asObject(rt))); } -static jsi::Value __hostFunction_RNSVGRenderableModule_getTotalLength(jsi::Runtime &rt, - react::TurboModule &turboModule, - const jsi::Value *args, - size_t count) { +static jsi::Value __hostFunction_RNSVGRenderableModule_getTotalLength(jsi::Runtime &rt, react::TurboModule &turboModule, + const jsi::Value *args, size_t count) { return static_cast(&turboModule) - ->getTotalLength(rt, args[0].isNull() || args[0].isUndefined() ? 0 - : std::make_optional(args[0].asNumber()).value()); + ->getTotalLength( + rt, args[0].isNull() || args[0].isUndefined() ? 0 : std::make_optional(args[0].asNumber()).value()); } static jsi::Value __hostFunction_RNSVGRenderableModule_getPointAtLength(jsi::Runtime &rt, - react::TurboModule &turboModule, - const jsi::Value *args, - size_t count) { + react::TurboModule &turboModule, + const jsi::Value *args, size_t count) { return static_cast(&turboModule) ->getPointAtLength( rt, args[0].isNull() || args[0].isUndefined() ? 0 : std::make_optional(args[0].asNumber()).value(), count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asObject(rt))); } -static jsi::Value __hostFunction_RNSVGRenderableModule_getBBox(jsi::Runtime &rt, - react::TurboModule &turboModule, - const jsi::Value *args, size_t count) { +static jsi::Value __hostFunction_RNSVGRenderableModule_getBBox(jsi::Runtime &rt, react::TurboModule &turboModule, + const jsi::Value *args, size_t count) { return static_cast(&turboModule) ->getBBox(rt, args[0].isNull() || args[0].isUndefined() ? 0 : std::make_optional(args[0].asNumber()).value(), count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asObject(rt))); } -static jsi::Value __hostFunction_RNSVGRenderableModule_getCTM(jsi::Runtime &rt, - react::TurboModule &turboModule, - const jsi::Value *args, size_t count) { +static jsi::Value __hostFunction_RNSVGRenderableModule_getCTM(jsi::Runtime &rt, react::TurboModule &turboModule, + const jsi::Value *args, size_t count) { return static_cast(&turboModule) ->getCTM(rt, args[0].isNull() || args[0].isUndefined() ? 0 : std::make_optional(args[0].asNumber()).value()); } -static jsi::Value __hostFunction_RNSVGRenderableModule_getScreenCTM(jsi::Runtime &rt, - react::TurboModule &turboModule, - const jsi::Value *args, - size_t count) { +static jsi::Value __hostFunction_RNSVGRenderableModule_getScreenCTM(jsi::Runtime &rt, react::TurboModule &turboModule, + const jsi::Value *args, size_t count) { return static_cast(&turboModule) - ->getScreenCTM(rt, args[0].isNull() || args[0].isUndefined() ? 0 - : std::make_optional(args[0].asNumber()).value()); + ->getScreenCTM(rt, + args[0].isNull() || args[0].isUndefined() ? 0 : std::make_optional(args[0].asNumber()).value()); } -static jsi::Value __hostFunction_RNSVGRenderableModule_getRawResource(jsi::Runtime &rt, - react::TurboModule &turboModule, - const jsi::Value *args, - size_t count) { +static jsi::Value __hostFunction_RNSVGRenderableModule_getRawResource(jsi::Runtime &rt, react::TurboModule &turboModule, + const jsi::Value *args, size_t count) { return static_cast(&turboModule)->getRawResource(rt, args[0].asString(rt)); } diff --git a/tester/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.h b/tester/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.h index 9b4361c5..2813ce46 100644 --- a/tester/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.h +++ b/tester/harmony/svg/src/main/cpp/turboModules/RNSVGRenderableModule.h @@ -21,7 +21,7 @@ class JSI_EXPORT RNSVGRenderableModule : public ArkTSTurboModule { bool isPointInFill(jsi::Runtime &rt, int32_t tag, std::optional options); bool isPointInStroke(jsi::Runtime &rt, int32_t tag, std::optional options); double getTotalLength(jsi::Runtime &rt, int32_t tag); - jsi::Object getPointAtLength(jsi::Runtime &rt, int32_t tag,std::optional options); + jsi::Object getPointAtLength(jsi::Runtime &rt, int32_t tag, std::optional options); jsi::Object getBBox(jsi::Runtime &rt, int32_t tag, std::optional options); jsi::Object getCTM(jsi::Runtime &rt, int32_t tag); jsi::Object getScreenCTM(jsi::Runtime &rt, int32_t tag); diff --git a/tester/harmony/svg/src/main/cpp/utils/GlyphContext.cpp b/tester/harmony/svg/src/main/cpp/utils/GlyphContext.cpp index cbe21b99..547dc701 100644 --- a/tester/harmony/svg/src/main/cpp/utils/GlyphContext.cpp +++ b/tester/harmony/svg/src/main/cpp/utils/GlyphContext.cpp @@ -1,8 +1,11 @@ /* - * Copyright 2015-2016 The react-native-svg Authors. All rights reserved + * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved + * + * This file incorporates from the react-native-svg project, licensed under + * the MIT License. Specifically: + * - [software-mansion/react-native-svg] (https://github.com/software-mansion/react-native-svg) */ #include "GlyphContext.h" diff --git a/tester/harmony/svg/src/main/cpp/utils/GlyphContext.h b/tester/harmony/svg/src/main/cpp/utils/GlyphContext.h index c9cbd70e..557d06ef 100644 --- a/tester/harmony/svg/src/main/cpp/utils/GlyphContext.h +++ b/tester/harmony/svg/src/main/cpp/utils/GlyphContext.h @@ -1,8 +1,11 @@ /* - * Copyright 2015-2016 The react-native-svg Authors. All rights reserved + * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved + * + * This file incorporates from the react-native-svg project, licensed under + * the MIT License. Specifically: + * - [software-mansion/react-native-svg] (https://github.com/software-mansion/react-native-svg) */ #pragma once diff --git a/tester/harmony/svg/src/main/cpp/utils/LinearMap.h b/tester/harmony/svg/src/main/cpp/utils/LinearMap.h index 944f7eb4..bbb5efee 100644 --- a/tester/harmony/svg/src/main/cpp/utils/LinearMap.h +++ b/tester/harmony/svg/src/main/cpp/utils/LinearMap.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/utils/PathParserUtils.cpp b/tester/harmony/svg/src/main/cpp/utils/PathParserUtils.cpp index f85a9f07..ea193136 100644 --- a/tester/harmony/svg/src/main/cpp/utils/PathParserUtils.cpp +++ b/tester/harmony/svg/src/main/cpp/utils/PathParserUtils.cpp @@ -1,8 +1,11 @@ /* - * Copyright 2015-2016 The react-native-svg Authors. All rights reserved + * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved + * + * This file incorporates from the react-native-svg project, licensed under + * the MIT License. Specifically: + * - [software-mansion/react-native-svg] (https://github.com/software-mansion/react-native-svg) */ #include "PathParserUtils.h" @@ -164,8 +167,6 @@ drawing::Path PathParserUtils::parse(std::string d) { throw std::runtime_error("Unexpected command '" + std::string(1, cmd) + "' (s=" + s + ")"); } } - - if (is_implicit_move_to) { if (absolute) { prev_cmd = 'M'; @@ -239,14 +240,20 @@ void PathParserUtils::quadraticBezierCurve(float c1x, float c1y, float c2x, floa } void PathParserUtils::quadraticBezierCurveTo(float c1x, float c1y, float c2x, float c2y) { + constexpr float CONTROL_POINT_WEIGHT = 2.0f; + constexpr float NORMALIZATION_FACTOR = 3.0f; + mPivotX = c1x; mPivotY = c1y; + float ex = c2x; float ey = c2y; - c2x = (ex + c1x * 2) / 3; - c2y = (ey + c1y * 2) / 3; - c1x = (mPenX + c1x * 2) / 3; - c1y = (mPenY + c1y * 2) / 3; + + c2x = (ex + c1x * CONTROL_POINT_WEIGHT) / NORMALIZATION_FACTOR; + c2y = (ey + c1y * CONTROL_POINT_WEIGHT) / NORMALIZATION_FACTOR; + c1x = (mPenX + c1x * CONTROL_POINT_WEIGHT) / NORMALIZATION_FACTOR; + c1y = (mPenY + c1y * CONTROL_POINT_WEIGHT) / NORMALIZATION_FACTOR; + cubicTo(c1x, c1y, c2x, c2y, ex, ey); } @@ -255,7 +262,6 @@ void PathParserUtils::smoothQuadraticBezierCurve(float c1x, float c1y) { } void PathParserUtils::smoothQuadraticBezierCurveTo(float c1x, float c1y) { - // FLog.w(ReactConstants.TAG, "smoothquad c1x: " + c1x + " c1y: " + c1y); float c2x = c1x; float c2y = c1y; c1x = (mPenX * 2) - mPivotX; @@ -393,7 +399,7 @@ void PathParserUtils::arcToBezier(float cx, float cy, float rx, float ry, float float x = std::cos(sa); float y = std::sin(sa); - for (int i = 0; i < n; i++) { + for (int index = 0; index < n; index++) { float cp1x = x - k * y; float cp1y = y + k * x; diff --git a/tester/harmony/svg/src/main/cpp/utils/PathParserUtils.h b/tester/harmony/svg/src/main/cpp/utils/PathParserUtils.h index 25841b9e..7f87e766 100644 --- a/tester/harmony/svg/src/main/cpp/utils/PathParserUtils.h +++ b/tester/harmony/svg/src/main/cpp/utils/PathParserUtils.h @@ -1,8 +1,11 @@ /* - * Copyright 2015-2016 The react-native-svg Authors. All rights reserved + * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved + * + * This file incorporates from the react-native-svg project, licensed under + * the MIT License. Specifically: + * - [software-mansion/react-native-svg] (https://github.com/software-mansion/react-native-svg) */ #pragma once diff --git a/tester/harmony/svg/src/main/cpp/utils/StringUtils.cpp b/tester/harmony/svg/src/main/cpp/utils/StringUtils.cpp index e4fe9547..87b0a6bc 100644 --- a/tester/harmony/svg/src/main/cpp/utils/StringUtils.cpp +++ b/tester/harmony/svg/src/main/cpp/utils/StringUtils.cpp @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -20,6 +20,9 @@ */ #include "StringUtils.h" +#include "multimedia/image_framework/image/image_packer_native.h" +#include "multimedia/image_framework/image/image_source_native.h" +#include "multimedia/image_framework/image/pixelmap_native.h" namespace rnoh { namespace svg { diff --git a/tester/harmony/svg/src/main/cpp/utils/StringUtils.h b/tester/harmony/svg/src/main/cpp/utils/StringUtils.h index 627afcdd..a1df33d3 100644 --- a/tester/harmony/svg/src/main/cpp/utils/StringUtils.h +++ b/tester/harmony/svg/src/main/cpp/utils/StringUtils.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -33,9 +33,6 @@ #include "properties/Dimension.h" #include "utils/SvgUtils.h" #include "native_drawing/drawing_bitmap.h" -#include "multimedia/image_framework/image/image_packer_native.h" -#include "multimedia/image_framework/image/image_source_native.h" -#include "multimedia/image_framework/image/pixelmap_native.h" namespace rnoh { namespace svg { @@ -238,7 +235,7 @@ static Dimension FromString(const std::string &str) { }; static Dimension StringToDimensionWithUnit(const std::string &value, DimensionUnit defaultUnit = DimensionUnit::PX, - float defaultValue = 0.0f, bool isCalc = false) { + float defaultValue = 0.0f, bool isCalc = false) { errno = 0; if (std::strcmp(value.c_str(), "auto") == 0) { return Dimension(defaultValue, DimensionUnit::AUTO); @@ -275,38 +272,13 @@ static Dimension StringToDimensionWithUnit(const std::string &value, DimensionUn return Dimension(result, defaultUnit); } -// inline CalcDimension StringToCalcDimension( -// const std::string& value, bool useVp = false, DimensionUnit defaultUnit = DimensionUnit::PX) -// { -// if (value.find("calc") != std::string::npos) { -// return CalcDimension(value, DimensionUnit::CALC); -// } else { -// if (useVp) { -// return StringToDimensionWithUnit(value, DimensionUnit::VP); -// } -// return StringToDimensionWithUnit(value, defaultUnit); -// } -// } - inline Dimension StringToDimension(const std::string &value, bool useVp = false) { return StringToDimensionWithUnit(value, useVp ? DimensionUnit::VP : DimensionUnit::PX); } -// inline Dimension StringToDimensionWithThemeValue(const std::string& value, bool useVp, const Dimension& themeValue) -// { -// errno = 0; -// char* pEnd = nullptr; -// std::strtod(value.c_str(), &pEnd); -// if (pEnd == value.c_str() || errno == ERANGE) { -// return themeValue; -// } -// -// return StringToDimensionWithUnit(value, useVp ? DimensionUnit::VP : DimensionUnit::PX); -// } - static bool StringToDimensionWithUnitNG(const std::string &value, Dimension &dimensionResult, - DimensionUnit defaultUnit = DimensionUnit::PX, float defaultValue = 0.0f, - bool isCalc = false) { + DimensionUnit defaultUnit = DimensionUnit::PX, float defaultValue = 0.0f, + bool isCalc = false) { errno = 0; if (std::strcmp(value.c_str(), "auto") == 0) { dimensionResult = Dimension(defaultValue, DimensionUnit::AUTO); @@ -583,8 +555,6 @@ inline void SplitStr(const std::string &str, const std::string &sep, std::vector } } -// const std::string ACE_EXPORT FormatString(const char* fmt, ...); - inline bool StartWith(const std::string &dst, const std::string &prefix) { return dst.compare(0, prefix.size(), prefix) == 0; } @@ -621,12 +591,12 @@ inline void TransformStrCase(std::string &str, int32_t textCase) { bool IsAscii(const std::string &str); -inline std::vector stringVectorToDoubleVector(const std::vector &stringVec) { +inline std::vector stringVectorToDoubleVector(const std::vector &stringVec, const double pixelDensity) { std::vector doubleVec; doubleVec.reserve(stringVec.size()); // 预分配内存以提高效率 for (const std::string &str : stringVec) { auto value = StringToDouble(str); - doubleVec.push_back(vpToPx(value)); + doubleVec.push_back(pixelDensity * value); } return doubleVec; } diff --git a/tester/harmony/svg/src/main/cpp/utils/SvgAttributesParser.cpp b/tester/harmony/svg/src/main/cpp/utils/SvgAttributesParser.cpp index 5588b75d..2e941aef 100644 --- a/tester/harmony/svg/src/main/cpp/utils/SvgAttributesParser.cpp +++ b/tester/harmony/svg/src/main/cpp/utils/SvgAttributesParser.cpp @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/utils/SvgAttributesParser.h b/tester/harmony/svg/src/main/cpp/utils/SvgAttributesParser.h index ebad8be7..d3e7eadf 100644 --- a/tester/harmony/svg/src/main/cpp/utils/SvgAttributesParser.h +++ b/tester/harmony/svg/src/main/cpp/utils/SvgAttributesParser.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * diff --git a/tester/harmony/svg/src/main/cpp/utils/SvgMarkerPositionUtils.h b/tester/harmony/svg/src/main/cpp/utils/SvgMarkerPositionUtils.h index 8b876c5d..422545fc 100644 --- a/tester/harmony/svg/src/main/cpp/utils/SvgMarkerPositionUtils.h +++ b/tester/harmony/svg/src/main/cpp/utils/SvgMarkerPositionUtils.h @@ -12,6 +12,12 @@ namespace rnoh { namespace svg { +constexpr double RNSVG_DEG_TO_RAD = M_PI / 180.0; +constexpr double RNSVG_RAD_TO_DEG = 180.0 / M_PI; +constexpr double ANGLE_THRESHOLD = 180.0; +constexpr double FULL_CIRCLE = 360.0; +constexpr double BISECT_DIVISOR = 2.0; + enum class RNSVGMarkerType { kStartMarker, kMidMarker, @@ -72,16 +78,16 @@ namespace SvgMarkerPositionUtils{ static Point in_slope_ = {0, 0}; static Point out_slope_ = {0, 0}; - static bool auto_start_reverse_; // TODO + static bool auto_start_reverse_; //ios only, use in renderMarker. inline double deg2rad(double deg) { - const double RNSVG_degToRad = M_PI / 180.0; + const double RNSVG_degToRad = RNSVG_DEG_TO_RAD; return deg * RNSVG_degToRad; } inline double rad2deg(double rad) { - const double RNSVG_radToDeg = 180.0 / M_PI; + const double RNSVG_radToDeg = RNSVG_RAD_TO_DEG; return rad * RNSVG_radToDeg; } @@ -90,8 +96,8 @@ namespace SvgMarkerPositionUtils{ } inline double BisectingAngle(double in_angle, double out_angle) { - if (std::abs(in_angle - out_angle) > 180) in_angle += 360; - return (in_angle + out_angle) / 2.0; + if (std::abs(in_angle - out_angle) > ANGLE_THRESHOLD) in_angle += FULL_CIRCLE; + return (in_angle + out_angle) / BISECT_DIVISOR; } inline Point subtract(Point p1, Point p2) { @@ -107,7 +113,7 @@ namespace SvgMarkerPositionUtils{ double out_angle = rad2deg(SlopeAngleRadians(out_slope_)); switch (type) { case RNSVGMarkerType::kStartMarker: - if (auto_start_reverse_) out_angle += 180; + if (auto_start_reverse_) out_angle += ANGLE_THRESHOLD; return out_angle; case RNSVGMarkerType::kMidMarker: return BisectingAngle(in_angle, out_angle); diff --git a/tester/harmony/svg/src/main/cpp/utils/SvgUtils.h b/tester/harmony/svg/src/main/cpp/utils/SvgUtils.h index 38ac2466..43b7eba6 100644 --- a/tester/harmony/svg/src/main/cpp/utils/SvgUtils.h +++ b/tester/harmony/svg/src/main/cpp/utils/SvgUtils.h @@ -3,7 +3,7 @@ * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. * - * This file incorporates code from another team within Huawei Device Co., Ltd, licensed under + * This file incorporates from the OpenHarmony project, licensed under * the Apache License, Version 2.0. Specifically: * - [OpenHarmony/arkui_ace_engine] (https://gitee.com/openharmony/arkui_ace_engine) * @@ -56,173 +56,115 @@ namespace rnoh { namespace svg { -inline double vpToPx(double vp) { - //TODO get densityPixels in CAPI - return vp * 3.25; -} - -template -constexpr std::size_t ArraySize(T (&)[N]) noexcept -{ - return N; -} +template constexpr std::size_t ArraySize(T (&)[N]) noexcept { return N; } -template -T ConvertIntToEnum(int32_t index, const T (&values)[N], T defaultValue) -{ +template T ConvertIntToEnum(int32_t index, const T (&values)[N], T defaultValue) { if (index >= 0 && index < N) { return values[index]; } return defaultValue; } -template -constexpr T Infinity() -{ - return static_cast(1000000.0); -} +template constexpr T Infinity() { return static_cast(1000000.0); } -inline bool NearEqual(const double left, const double right, const double epsilon) -{ +inline bool NearEqual(const double left, const double right, const double epsilon) { return (std::abs(left - right) <= epsilon); } -template -constexpr bool NearEqual(const T& left, const T& right); +template constexpr bool NearEqual(const T &left, const T &right); -template<> -inline bool NearEqual(const float& left, const float& right) -{ +template <> inline bool NearEqual(const float &left, const float &right) { constexpr double epsilon = 0.001f; return NearEqual(left, right, epsilon); } -template<> -inline bool NearEqual(const double& left, const double& right) -{ +template <> inline bool NearEqual(const double &left, const double &right) { constexpr double epsilon = 0.00001f; return NearEqual(left, right, epsilon); } -template -constexpr bool NearEqual(const T& left, const T& right) -{ - return left == right; -} +template constexpr bool NearEqual(const T &left, const T &right) { return left == right; } -inline bool NearZero(const double value, const double epsilon) -{ - return NearEqual(value, 0.0, epsilon); -} +inline bool NearZero(const double value, const double epsilon) { return NearEqual(value, 0.0, epsilon); } -inline bool NearEqual(const double left, const double right) -{ +inline bool NearEqual(const double left, const double right) { constexpr double epsilon = 0.001f; return NearEqual(left, right, epsilon); } -inline bool NearZero(const double left) -{ +inline bool NearZero(const double left) { constexpr double epsilon = 0.001f; return NearZero(left, epsilon); } -inline bool LessOrEqual(double left, double right) -{ +inline bool LessOrEqual(double left, double right) { constexpr double epsilon = 0.001f; return (left - right) < epsilon; } -inline bool LessOrEqualCustomPrecision(double left, double right, double epsilon = 0.000001f) -{ +inline bool LessOrEqualCustomPrecision(double left, double right, double epsilon = 0.000001f) { return (left - right) < epsilon; } -inline bool LessNotEqual(double left, double right) -{ +inline bool LessNotEqual(double left, double right) { constexpr double epsilon = -0.001f; return (left - right) < epsilon; } -inline bool LessNotEqualCustomPrecision(double left, double right, double epsilon = -0.000001f) -{ +inline bool LessNotEqualCustomPrecision(double left, double right, double epsilon = -0.000001f) { return (left - right) < epsilon; } -inline bool GreatOrEqual(double left, double right) -{ +inline bool GreatOrEqual(double left, double right) { constexpr double epsilon = -0.001f; return (left - right) > epsilon; } -inline bool GreatOrEqualCustomPrecision(double left, double right, double epsilon = -0.000001f) -{ +inline bool GreatOrEqualCustomPrecision(double left, double right, double epsilon = -0.000001f) { return (left - right) > epsilon; } -inline bool GreatNotEqual(double left, double right) -{ +inline bool GreatNotEqual(double left, double right) { constexpr double epsilon = 0.001f; return (left - right) > epsilon; } -inline bool GreatNotEqualCustomPrecision(double left, double right, double epsilon = 0.000001f) -{ +inline bool GreatNotEqualCustomPrecision(double left, double right, double epsilon = 0.000001f) { return (left - right) > epsilon; } -inline double Round(double rawNum) -{ +inline double Round(double rawNum) { constexpr double epsilon = 0.001f; return std::round(rawNum + epsilon); } -inline bool Negative(double value) -{ - return LessNotEqual(value, 0); -} +inline bool Negative(double value) { return LessNotEqual(value, 0); } -inline bool NonNegative(double value) -{ - return GreatOrEqual(value, 0); -} +inline bool NonNegative(double value) { return GreatOrEqual(value, 0); } -inline bool Positive(double value) -{ - return GreatNotEqual(value, 0); -} +inline bool Positive(double value) { return GreatNotEqual(value, 0); } -inline bool NonPositive(double value) -{ - return LessOrEqual(value, 0); -} +inline bool NonPositive(double value) { return LessOrEqual(value, 0); } -inline bool InRegion(double lowerBound, double upperBound, double destNum) -{ +inline bool InRegion(double lowerBound, double upperBound, double destNum) { return LessOrEqual(lowerBound, destNum) && LessOrEqual(destNum, upperBound); } -inline bool GreaterOrEqualToInfinity(float num) -{ - return GreatOrEqual(num, Infinity() / 2.0f); -} +inline bool GreaterOrEqualToInfinity(float num) { return GreatOrEqual(num, Infinity() / 2.0f); } -inline uint64_t GetMilliseconds() -{ +inline uint64_t GetMilliseconds() { auto now = std::chrono::system_clock::now(); auto millisecs = std::chrono::duration_cast(now.time_since_epoch()); return millisecs.count(); } -inline uint64_t GetNanoseconds() -{ +inline uint64_t GetNanoseconds() { auto now = std::chrono::system_clock::now(); auto nanoseconds = std::chrono::duration_cast(now.time_since_epoch()); return nanoseconds.count(); } -inline float CalculateFriction(float gamma) -{ +inline float CalculateFriction(float gamma) { constexpr float SCROLL_RATIO = 0.72f; if (GreatOrEqual(gamma, 1.0)) { gamma = 1.0;