code sync

Signed-off-by: ustc-tianyu <dutianyu4@huawei.com>
This commit is contained in:
ustc-tianyu 2024-09-11 16:39:09 +08:00
parent cc6bf37ef8
commit 1f9527e400
3 changed files with 48 additions and 47 deletions

View File

@ -478,6 +478,50 @@ napi_value JsFont::OnIsForceAutoHinting(napi_env env, napi_callback_info info)
return CreateJsValue(env, isForceAutoHinting);
}
napi_value JsFont::OnGetWidths(napi_env env, napi_callback_info info)
{
if (m_font == nullptr) {
ROSEN_LOGE("JsFont::OnGetWidths font is nullptr");
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
}
napi_value argv[ARGC_ONE] = { nullptr };
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
uint32_t fontSize = 0;
napi_get_array_length(env, argv[ARGC_ZERO], &fontSize);
if (fontSize == 0) {
return nullptr;
}
std::unique_ptr<uint16_t[]> glyphPtr = std::make_unique<uint16_t[]>(fontSize);
for (uint32_t i = 0; i < fontSize; i++) {
napi_value tempglyph = nullptr;
napi_get_element(env, argv[ARGC_ZERO], i, &tempglyph);
uint32_t glyph_t = 0;
bool isColorOk = ConvertFromJsValue(env, tempglyph, glyph_t);
if (!isColorOk) {
ROSEN_LOGE("JsFont::OnGetWidths Argv[ARGC_ZERO] is invalid");
return nullptr;
}
glyphPtr[i] = glyph_t;
}
std::unique_ptr<float[]> widthPtr = std::make_unique<float[]>(fontSize);
m_font->GetWidths(glyphPtr.get(), fontSize, widthPtr.get());
napi_value widthJsArray;
napi_status status = napi_create_array(env, &widthJsArray);
if (status != napi_ok) {
ROSEN_LOGE("failed to napi_create_array");
return nullptr;
}
for (size_t i = 0; i < fontSize; i++) {
napi_value element = CreateJsValue(env, widthPtr[i]);
napi_set_element(env, widthJsArray, i, element);
}
return widthJsArray;
}
napi_value JsFont::OnSetSize(napi_env env, napi_callback_info info)
{
if (m_font == nullptr) {
@ -545,50 +589,6 @@ napi_value JsFont::OnGetTypeface(napi_env env, napi_callback_info info)
return JsTypeface::CreateJsTypeface(env, typeface);
}
napi_value JsFont::OnGetWidths(napi_env env, napi_callback_info info)
{
if (m_font == nullptr) {
ROSEN_LOGE("JsFont::OnGetWidths font is nullptr");
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
}
napi_value argv[ARGC_ONE] = { nullptr };
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_ONE);
uint32_t fontSize = 0;
napi_get_array_length(env, argv[ARGC_ZERO], &fontSize);
if (fontSize == 0) {
return nullptr;
}
std::unique_ptr<uint16_t[]> glyphPtr = std::make_unique<uint16_t[]>(fontSize);
for (uint32_t i = 0; i < fontSize; i++) {
napi_value tempglyph = nullptr;
napi_get_element(env, argv[ARGC_ZERO], i, &tempglyph);
uint32_t glyph_t = 0;
bool isColorOk = ConvertFromJsValue(env, tempglyph, glyph_t);
if (!isColorOk) {
ROSEN_LOGE("JsFont::OnGetWidths Argv[ARGC_ZERO] is invalid");
return nullptr;
}
glyphPtr[i] = glyph_t;
}
std::unique_ptr<float[]> widthPtr = std::make_unique<float[]>(fontSize);
m_font->GetWidths(glyphPtr.get(), fontSize, widthPtr.get());
napi_value widthJsArray;
napi_status status = napi_create_array(env, &widthJsArray);
if (status != napi_ok) {
ROSEN_LOGE("failed to napi_create_array");
return nullptr;
}
for (size_t i = 0; i < fontSize; i++) {
napi_value element = CreateJsValue(env, widthPtr[i]);
napi_set_element(env, widthJsArray, i, element);
}
return widthJsArray;
}
napi_value JsFont::OnGetBounds(napi_env env, napi_callback_info info)
{
if (m_font == nullptr) {

View File

@ -82,11 +82,11 @@ private:
napi_value OnGetTypeface(napi_env env, napi_callback_info info);
napi_value OnGetSize(napi_env env, napi_callback_info info);
napi_value OnGetMetrics(napi_env env, napi_callback_info info);
napi_value OnMeasureSingleCharacter(napi_env env, napi_callback_info info);
napi_value OnGetWidths(napi_env env, napi_callback_info info);
napi_value OnIsBaselineSnap(napi_env env, napi_callback_info info);
napi_value OnIsEmbeddedBitmaps(napi_env env, napi_callback_info info);
napi_value OnIsForceAutoHinting(napi_env env, napi_callback_info info);
napi_value OnMeasureSingleCharacter(napi_env env, napi_callback_info info);
napi_value OnMeasureText(napi_env env, napi_callback_info info);
napi_value OnSetScaleX(napi_env env, napi_callback_info info);
napi_value OnSetSkewX(napi_env env, napi_callback_info info);

View File

@ -100,8 +100,9 @@ void OH_Drawing_TypefaceDestroy(OH_Drawing_Typeface* cTypeface)
if (cTypeface == nullptr) {
return;
}
if (Drawing::Typeface::GetTypefaceUnRegisterCallBack() != nullptr) {
Drawing::Typeface::GetTypefaceUnRegisterCallBack()(TypefaceMgr::GetInstance().Find(cTypeface));
auto typeface = TypefaceMgr::GetInstance().Find(cTypeface);
if (Drawing::Typeface::GetTypefaceUnRegisterCallBack() != nullptr && typeface) {
Drawing::Typeface::GetTypefaceUnRegisterCallBack()(typeface);
}
TypefaceMgr::GetInstance().Remove(cTypeface);
}