1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OH_ROSEN_JS_TYPEFACE_ARGUMENTS_H 17 #define OH_ROSEN_JS_TYPEFACE_ARGUMENTS_H 18 19 #include <memory> 20 #include <native_engine/native_engine.h> 21 #include <native_engine/native_value.h> 22 23 #include "text/font_arguments.h" 24 25 struct TypeFaceArgumentsHelper { 26 struct Coordinate { 27 uint32_t axis; 28 float value; 29 }; 30 31 int fontCollectionIndex = 0; 32 std::vector<Coordinate> coordinate; 33 }; 34 35 namespace OHOS::Rosen { 36 namespace Drawing { 37 class JsTypeFaceArguments final { 38 public: JsTypeFaceArguments(std::shared_ptr<TypeFaceArgumentsHelper> typeFaceArguments)39 explicit JsTypeFaceArguments(std::shared_ptr<TypeFaceArgumentsHelper> typeFaceArguments) 40 : m_typeFaceArguments(typeFaceArguments) {} 41 ~JsTypeFaceArguments(); 42 43 static napi_value Init(napi_env env, napi_value exportObj); 44 static napi_value Constructor(napi_env env, napi_callback_info info); 45 static void Destructor(napi_env env, void* nativeObject, void* finalize); 46 47 std::shared_ptr<TypeFaceArgumentsHelper> GetTypeFaceArgumentsHelper(); 48 static void ConvertToFontArguments(std::shared_ptr<TypeFaceArgumentsHelper> typeFaceArgumentsHelper, 49 FontArguments& fontArguments); 50 static uint32_t ConvertAxisToNumber(const std::string& axis); 51 52 static napi_value AddVariation(napi_env env, napi_callback_info info); 53 private: 54 static thread_local napi_ref constructor_; 55 std::shared_ptr<TypeFaceArgumentsHelper> m_typeFaceArguments = nullptr; 56 }; 57 } // namespace Drawing 58 } // namespace OHOS::Rosen 59 #endif //OH_ROSEN_JS_TYPEFACE_ARGUMENTS_H