/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "frameworks/bridge/declarative_frontend/jsview/js_symbol.h" #include "frameworks/bridge/declarative_frontend/engine/bindings.h" #include "frameworks/bridge/declarative_frontend/engine/js_ref_ptr.h" #include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" #include "frameworks/core/components_ng/pattern/symbol/symbol_model.h" #include "frameworks/core/components_ng/pattern/symbol/symbol_model_ng.h" namespace OHOS::Ace { std::unique_ptr SymbolModel::instance_ = nullptr; std::mutex SymbolModel::mutex_; SymbolModel* SymbolModel::GetInstance() { if (!instance_) { std::lock_guard lock(mutex_); if (!instance_) { instance_.reset(new NG::SymbolModelNG()); } } return instance_.get(); } } // namespace OHOS::Ace namespace OHOS::Ace::Framework { void JSSymbol::JSBind(BindingTarget globalObj) { JSClass::Declare("SymbolGlyph"); MethodOptions opt = MethodOptions::NONE; JSClass::StaticMethod("create", &JSSymbol::Create, opt); JSClass::StaticMethod("fontWeight", &JSSymbol::SetFontWeight, opt); JSClass::StaticMethod("fontSize", &JSSymbol::SetFontSize, opt); JSClass::StaticMethod("renderingStrategy", &JSSymbol::SetSymbolRenderingStrategy, opt); JSClass::StaticMethod("fontColor", &JSSymbol::SetFontColor, opt); JSClass::StaticMethod("effectStrategy", &JSSymbol::SetSymbolEffect, opt); JSClass::StaticMethod("onTouch", &JSInteractableView::JsOnTouch); JSClass::StaticMethod("onAppear", &JSInteractableView::JsOnAppear); JSClass::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear); JSClass::StaticMethod("clip", &JSSymbol::JsClip); JSClass::InheritAndBind(globalObj); } void JSSymbol::Create(const JSCallbackInfo& info) { if (info[0]->IsUndefined()) { SymbolModel::GetInstance()->Create(0); return; } uint32_t symbolId; RefPtr resourceObject; ParseJsSymbolId(info[0], symbolId, resourceObject); SymbolModel::GetInstance()->Create(symbolId); } void JSSymbol::SetFontSize(const JSCallbackInfo& info) { if (info.Length() < 1) { return; } auto theme = GetTheme(); CHECK_NULL_VOID(theme); CalcDimension fontSize = theme->GetTextStyle().GetFontSize(); if (!ParseJsDimensionFpNG(info[0], fontSize, false)) { fontSize = theme->GetTextStyle().GetFontSize(); SymbolModel::GetInstance()->SetFontSize(fontSize); return; } if (fontSize.IsNegative()) { fontSize = theme->GetTextStyle().GetFontSize(); } SymbolModel::GetInstance()->SetFontSize(fontSize); } void JSSymbol::SetFontWeight(const std::string& value) { SymbolModel::GetInstance()->SetFontWeight(ConvertStrToFontWeight(value)); } void JSSymbol::SetSymbolRenderingStrategy(const JSCallbackInfo& info) { uint32_t strategy = 0; ParseJsInteger(info[0], strategy); SymbolModel::GetInstance()->SetSymbolRenderingStrategy(strategy); } void JSSymbol::SetFontColor(const JSCallbackInfo& info) { std::vector symbolColor; if (!ParseJsSymbolColor(info[0], symbolColor)) { return; } SymbolModel::GetInstance()->SetFontColor(symbolColor); } void JSSymbol::SetSymbolEffect(const JSCallbackInfo& info) { uint32_t strategy = 0; ParseJsInteger(info[0], strategy); SymbolModel::GetInstance()->SetSymbolEffect(strategy); } void JSSymbol::JsClip(const JSCallbackInfo& info) { JSViewAbstract::JsClip(info); if (info[0]->IsBoolean()) { SymbolModel::GetInstance()->SetClipEdge(); } } } // namespace OHOS::Ace::Framework