Modify alarm issues

Signed-off-by: changleipeng <changleipeng4@huawei.com>
Change-Id: I108d1e9f65b55d6988cf5be3a42700aebac6b2b4
This commit is contained in:
changleipeng 2024-10-21 10:32:20 +08:00
parent a54236b8ca
commit 3c4e3ca9e7
15 changed files with 181 additions and 100 deletions

View File

@ -18,7 +18,6 @@
#include "ability.h"
#include "napi_async_work.h"
#include "utils/text_log.h"
namespace OHOS::Rosen {
namespace {

View File

@ -148,7 +148,7 @@ napi_value JsLineTypeset::OnGetLineBreak(napi_env env, napi_callback_info info)
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Argv convert failed.");
}
size_t limitSize = lineTypography_->GetUnicodeSize();
if (index < 0 || index >= limitSize || width <= 0) {
if (index < 0 || limitSize <= static_cast<size_t>(index) || width <= 0) {
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Params exceeds reasonable range.");
}
size_t count = static_cast<size_t>(lineTypography_->GetLineBreak(static_cast<size_t>(index), width));
@ -178,7 +178,7 @@ napi_value JsLineTypeset::OnCreateLine(napi_env env, napi_callback_info info)
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Argv convert failed");
}
size_t limitSize = lineTypography_->GetUnicodeSize();
if (index < 0 || index >= limitSize || count < 0 || count + index > limitSize) {
if (index < 0 || limitSize <= static_cast<size_t>(index) || count < 0 || count + index > limitSize) {
return NapiThrowError(env, TextErrorCode::ERROR_INVALID_PARAM, "Params exceeds reasonable range.");
}
auto textLineBase = lineTypography_->CreateLine(static_cast<size_t>(index), static_cast<size_t>(count));

View File

@ -15,12 +15,11 @@
#include "napi_async_work.h"
#include "napi_common.h"
#include "utils/text_log.h"
namespace OHOS::Rosen {
ContextBase::~ContextBase()
{
TEXT_LOGI("No memory leak after callback or promise[resolved/rejected]");
TEXT_LOGD("Entry");
TEXT_CHECK(env != nullptr, return);
TEXT_CHECK(work == nullptr, status = napi_delete_async_work(env, work));
TEXT_ERROR_CHECK(status == napi_ok, return, "Failed to delete async work, status:%{public}d",

View File

@ -24,6 +24,7 @@
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "napi/native_node_api.h"
#include "utils/text_log.h"
namespace OHOS::Rosen {
#define MAX_LOG_SIZE 1024

View File

@ -93,7 +93,7 @@ void RunImpl::GetStringRange(uint64_t* location, uint64_t* length) const
if (location == nullptr || length == nullptr) {
return;
} else if (run_ == nullptr) {
*location= 0;
*location = 0;
*length = 0;
return;
}

View File

@ -28,6 +28,7 @@ namespace Rosen {
struct TextTab {
TextTab() = default;
TextTab(TextAlign alignment, float location) : alignment(alignment), location(location) {};
TextTab(const TextTab& other) : alignment(other.alignment), location(other.location) {};
TextTab& operator=(const TextTab&) = default;
bool operator==(const TextTab& rhs) const

View File

@ -96,7 +96,7 @@ void RunImpl::GetStringRange(uint64_t* location, uint64_t* length) const
if (location == nullptr || length == nullptr) {
return;
} else if (runBase_ == nullptr) {
*location= 0;
*location = 0;
*length = 0;
return;
}

View File

@ -40,6 +40,7 @@ enum class BreakStrategy {
struct TextTab {
TextTab() = default;
TextTab(TextAlign alignment, float location) : alignment(alignment), location(location) {};
TextTab(const TextTab& other) : alignment(other.alignment), location(other.location) {};
TextTab& operator=(const TextTab&) = default;
TextAlign alignment = TextAlign::LEFT;
static constexpr float INVALID_LOCATION = -1.0f;

View File

@ -95,6 +95,7 @@ template("drawing_ndk_source_set") {
"$drawing_ndk_src_dir/drawing_text_run.cpp",
"$drawing_ndk_src_dir/drawing_text_typography.cpp",
"$drawing_ndk_src_dir/drawing_typeface.cpp",
"$drawing_ndk_src_dir/font_utils.cpp",
"$drawing_utils_root/drawing_canvas_utils.cpp",
"$drawing_utils_root/native_pixel_map_manager.cpp",
]

View File

@ -17,9 +17,41 @@
#include "array_mgr.h"
#include "font_descriptor_mgr.h"
#include "font_utils.h"
#include "text/common_utils.h"
using namespace OHOS::Rosen;
namespace {
size_t CalculateDrawingStringSize(const std::string& fullName, std::u16string& utf16String)
{
if (fullName.empty()) {
return 0;
}
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
utf16String = converter.from_bytes(fullName);
return utf16String.size() * sizeof(char16_t);
}
bool ConvertToDrawingString(std::u16string& utf16String, OH_Drawing_String& fullNameString)
{
if (utf16String.empty() || fullNameString.strData == nullptr || fullNameString.strLen == 0) {
return false;
}
char16_t* u16Data = const_cast<char16_t*>(utf16String.c_str());
if (!Drawing::IsBigEndian()) {
for (uint32_t i = 0; i < fullNameString.strLen / sizeof(char16_t); i++) {
uint16_t temp = static_cast<uint16_t>(u16Data[i]);
u16Data[i] = static_cast<char16_t>((temp & Drawing::LOW_BYTE_MASK) << Drawing::BYTE_SHIFT |
(temp & Drawing::HIGH_BYTE_MASK) >> Drawing::BYTE_SHIFT);
}
}
if (memcpy_s(fullNameString.strData, fullNameString.strLen, u16Data, fullNameString.strLen) == EOK) {
return true;
}
return false;
}
}
template<typename T1, typename T2>
inline T1* ConvertToOriginalText(T2* ptr)
@ -57,20 +89,19 @@ OH_Drawing_FontDescriptor* OH_Drawing_MatchFontDescriptors(OH_Drawing_FontDescri
*num = 0;
return nullptr;
}
int i = 0;
size_t i = 0;
for (const auto& item : result) {
descriptors[i].path = strdup(item->path.c_str());
descriptors[i].postScriptName = strdup(item->postScriptName.c_str());
descriptors[i].fullName = strdup(item->fullName.c_str());
descriptors[i].fontFamily = strdup(item->fontFamily.c_str());
descriptors[i].fontSubfamily = strdup(item->fontSubfamily.c_str());
descriptors[i].weight = item->weight;
descriptors[i].width = item->width;
descriptors[i].italic = item->italic;
descriptors[i].monoSpace = item->monoSpace;
descriptors[i].symbolic = item->symbolic;
if (!OHOS::Rosen::Drawing::CopyFontDescriptor(&descriptors[i], *item)) {
break;
}
++i;
}
if (i != result.size()) {
OH_Drawing_DestroyFontDescriptors(descriptors, i);
*num = 0;
return nullptr;
}
return descriptors;
}
@ -89,45 +120,6 @@ void OH_Drawing_DestroyFontDescriptors(OH_Drawing_FontDescriptor* descriptors, s
delete[] descriptors;
}
bool ConvertToDrawingString(const std::string& fullName, OH_Drawing_String& fullNameString)
{
if (fullName.empty()) {
fullNameString.strData = nullptr;
fullNameString.strLen = 0;
return false;
}
std::u16string utf16String;
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
utf16String = converter.from_bytes(fullName);
char16_t* u16Data = const_cast<char16_t*>(utf16String.c_str());
size_t strByteLen = utf16String.size() * sizeof(char16_t);
if (strByteLen == 0) {
fullNameString.strData = nullptr;
fullNameString.strLen = 0;
return false;
}
using namespace OHOS::Rosen::Drawing;
if (!IsBigEndian()) {
for (uint32_t i = 0; i < strByteLen / sizeof(char16_t); i++) {
uint16_t temp = static_cast<uint16_t>(u16Data[i]);
u16Data[i] = static_cast<char16_t>((temp & LOW_BYTE_MASK) << BYTE_SHIFT |
(temp & HIGH_BYTE_MASK) >> BYTE_SHIFT);
}
}
uint8_t* strData = new (std::nothrow)uint8_t[strByteLen];
if (strData == nullptr) {
return false;
}
if (memcpy_s(strData, strByteLen, u16Data, strByteLen) == EOK) {
fullNameString.strData = strData;
fullNameString.strLen = static_cast<uint32_t>(strByteLen);
return true;
}
delete[] strData;
strData = nullptr;
return false;
}
OH_Drawing_FontDescriptor* OH_Drawing_GetFontDescriptorByFullName(const OH_Drawing_String* fullName,
OH_Drawing_SystemFontType fontType)
{
@ -145,20 +137,14 @@ OH_Drawing_FontDescriptor* OH_Drawing_GetFontDescriptorByFullName(const OH_Drawi
if (result == nullptr) {
return nullptr;
}
OH_Drawing_FontDescriptor* descriptor = new (std::nothrow)OH_Drawing_FontDescriptor();
OH_Drawing_FontDescriptor* descriptor = OH_Drawing_CreateFontDescriptor();
if (descriptor == nullptr) {
return nullptr;
}
descriptor->path = strdup(result->path.c_str());
descriptor->postScriptName = strdup(result->postScriptName.c_str());
descriptor->fullName = strdup(result->fullName.c_str());
descriptor->fontFamily = strdup(result->fontFamily.c_str());
descriptor->fontSubfamily = strdup(result->fontSubfamily.c_str());
descriptor->weight = result->weight;
descriptor->width = result->width;
descriptor->italic = result->italic;
descriptor->monoSpace = result->monoSpace;
descriptor->symbolic = result->symbolic;
if (!OHOS::Rosen::Drawing::CopyFontDescriptor(descriptor, *result)) {
OH_Drawing_DestroyFontDescriptor(descriptor);
return nullptr;
}
return descriptor;
}
@ -181,8 +167,16 @@ OH_Drawing_Array* OH_Drawing_GetSystemFontFullNamesByType(OH_Drawing_SystemFontT
}
size_t index = 0;
for (const auto& fullName : fullNameList) {
if (!ConvertToDrawingString(fullName, drawingStringArray[index])) {
for (size_t i = 0; i < index; ++i) {
std::u16string utf16String;
size_t strByteLen = CalculateDrawingStringSize(fullName, utf16String);
if (strByteLen > 0) {
drawingStringArray[index].strData = new (std::nothrow) uint8_t[strByteLen];
drawingStringArray[index].strLen = static_cast<uint32_t>(strByteLen);
}
if (strByteLen == 0 || drawingStringArray[index].strData == nullptr ||
!ConvertToDrawingString(utf16String, drawingStringArray[index])) {
for (size_t i = 0; i <= index; ++i) {
delete[] drawingStringArray[i].strData;
}
delete[] drawingStringArray;

View File

@ -26,6 +26,7 @@
#include "array_mgr.h"
#include "font_config.h"
#include "font_parser.h"
#include "font_utils.h"
#include "rosen_text/font_collection.h"
#include "rosen_text/typography.h"
#include "rosen_text/typography_create.h"
@ -303,25 +304,33 @@ void OH_Drawing_SetTextStyleDecoration(OH_Drawing_TextStyle* style, int decorati
void OH_Drawing_AddTextStyleDecoration(OH_Drawing_TextStyle* style, int decoration)
{
if (style == nullptr || (decoration & ~(TextDecoration::UNDERLINE | TextDecoration::OVERLINE |
TextDecoration::LINE_THROUGH))) {
if (decoration < 0) {
return;
}
unsigned int uintDecoration = static_cast<unsigned int>(decoration);
if (style == nullptr || (uintDecoration & (~(TextDecoration::UNDERLINE | TextDecoration::OVERLINE |
TextDecoration::LINE_THROUGH)))) {
return;
}
TextStyle* rosenTextStyle = ConvertToOriginalText<TextStyle>(style);
if (rosenTextStyle) {
rosenTextStyle->decoration = static_cast<TextDecoration>(rosenTextStyle->decoration | decoration);
rosenTextStyle->decoration = static_cast<TextDecoration>(rosenTextStyle->decoration | uintDecoration);
}
}
void OH_Drawing_RemoveTextStyleDecoration(OH_Drawing_TextStyle* style, int decoration)
{
if (style == nullptr || (decoration & ~(TextDecoration::UNDERLINE | TextDecoration::OVERLINE |
TextDecoration::LINE_THROUGH))) {
if (decoration < 0) {
return;
}
unsigned int uintDecoration = static_cast<unsigned int>(decoration);
if (style == nullptr || (uintDecoration & (~(TextDecoration::UNDERLINE | TextDecoration::OVERLINE |
TextDecoration::LINE_THROUGH)))) {
return;
}
TextStyle* rosenTextStyle = ConvertToOriginalText<TextStyle>(style);
if (rosenTextStyle) {
rosenTextStyle->decoration = static_cast<TextDecoration>(rosenTextStyle->decoration & ~decoration);
rosenTextStyle->decoration = static_cast<TextDecoration>(rosenTextStyle->decoration & ~uintDecoration);
}
}
@ -1263,21 +1272,14 @@ OH_Drawing_FontDescriptor* OH_Drawing_FontParserGetFontByName(OH_Drawing_FontPar
if (strcmp(name, systemFontList[i].fullName.c_str()) != 0) {
continue;
}
OH_Drawing_FontDescriptor* descriptor = new (std::nothrow) OH_Drawing_FontDescriptor();
OH_Drawing_FontDescriptor* descriptor = OH_Drawing_CreateFontDescriptor();
if (descriptor == nullptr) {
return nullptr;
}
descriptor->path = strdup(systemFontList[i].path.c_str());
descriptor->postScriptName = strdup(systemFontList[i].postScriptName.c_str());
descriptor->fullName = strdup(systemFontList[i].fullName.c_str());
descriptor->fontFamily = strdup(systemFontList[i].fontFamily.c_str());
descriptor->fontSubfamily = strdup(systemFontList[i].fontSubfamily.c_str());
descriptor->weight = systemFontList[i].weight;
descriptor->width = systemFontList[i].width;
descriptor->italic = systemFontList[i].italic;
descriptor->monoSpace = systemFontList[i].monoSpace;
descriptor->symbolic = systemFontList[i].symbolic;
if (!OHOS::Rosen::Drawing::CopyFontDescriptor(descriptor, systemFontList[i])) {
OH_Drawing_DestroyFontDescriptor(descriptor);
return nullptr;
}
return descriptor;
}
return nullptr;

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2024 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 "font_utils.h"
#include "drawing_text_font_descriptor.h"
namespace OHOS::Rosen::Drawing {
bool CopyFontDescriptor(OH_Drawing_FontDescriptor* dst, const FontParser::FontDescriptor& src)
{
if (dst == nullptr) {
return false;
}
dst->path = strdup(src.path.c_str());
dst->postScriptName = strdup(src.postScriptName.c_str());
dst->fullName = strdup(src.fullName.c_str());
dst->fontFamily = strdup(src.fontFamily.c_str());
dst->fontSubfamily = strdup(src.fontSubfamily.c_str());
if (dst->path == NULL || dst->postScriptName == NULL || dst->fullName == NULL || dst->fontFamily == NULL ||
dst->fontSubfamily == NULL) {
free(dst->path);
free(dst->postScriptName);
free(dst->fullName);
free(dst->fontFamily);
free(dst->fontSubfamily);
return false;
}
dst->weight = src.weight;
dst->width = src.width;
dst->italic = src.italic;
dst->monoSpace = src.monoSpace;
dst->symbolic = src.symbolic;
return true;
}
} // namespace OHOS::Rosen::Drawing

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 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.
*/
#ifndef DRAWING_COMMON_H
#define DRAWING_COMMON_H
#include "drawing_text_typography.h"
#include "font_parser.h"
namespace OHOS::Rosen::Drawing {
using OHOS::Rosen::TextEngine::FontParser;
bool CopyFontDescriptor(OH_Drawing_FontDescriptor* dst, const FontParser::FontDescriptor& src);
} // namespace OHOS::Rosen::Drawing
#endif // DRAWING_COMMON_H

View File

@ -103,6 +103,10 @@ bool FontDescriptorCache::ParseInstalledConfigFile(const std::string& fontPath,
bool FontDescriptorCache::ProcessInstalledFontPath(const std::string& path)
{
std::shared_ptr<Drawing::FontMgr> fontMgr = Drawing::FontMgr::CreateDefaultFontMgr();
if (access(path.c_str(), F_OK) != 0) {
TEXT_LOGE("path does not exist");
return false;
}
int fd = open(path.c_str(), O_RDONLY);
if (fd == -1) {
return false;
@ -134,7 +138,7 @@ void FontDescriptorCache::FontDescriptorScatter(FontDescSharedPtr desc)
return;
}
auto handleMapScatter = [&](auto& map, const auto& key) {
auto handleMapScatter = [desc](auto& map, const auto& key) {
map[key].emplace(desc);
};
@ -143,7 +147,7 @@ void FontDescriptorCache::FontDescriptorScatter(FontDescSharedPtr desc)
handleMapScatter(postScriptNameMap_, desc->postScriptName);
handleMapScatter(fontSubfamilyNameMap_, desc->fontSubfamily);
if (desc->weight > WEIGHT_400) {
if (static_cast<uint32_t>(desc->weight) > WEIGHT_400) {
boldCache_.emplace(desc);
}
@ -192,7 +196,10 @@ std::unordered_set<std::string> FontDescriptorCache::GetGenericFontList()
bool FontDescriptorCache::ProcessSystemFontType(const int32_t& systemFontType, int32_t& fontType)
{
if ((systemFontType & (TextEngine::FontParser::SystemFontType::ALL |
if (systemFontType < 0) {
return false;
}
if ((static_cast<uint32_t>(systemFontType) & (TextEngine::FontParser::SystemFontType::ALL |
TextEngine::FontParser::SystemFontType::GENERIC |
TextEngine::FontParser::SystemFontType::STYLISH |
TextEngine::FontParser::SystemFontType::INSTALLED)) != systemFontType) {
@ -211,7 +218,7 @@ bool FontDescriptorCache::ProcessSystemFontType(const int32_t& systemFontType, i
void FontDescriptorCache::GetSystemFontFullNamesByType(const int32_t& systemFontType,
std::unordered_set<std::string>& fontList)
{
int32_t fontType;
int32_t fontType = 0;
if (!ProcessSystemFontType(systemFontType, fontType)) {
fontList.clear();
return;
@ -271,7 +278,7 @@ void FontDescriptorCache::GetFontDescSharedPtrByFullName(const std::string& full
result = nullptr;
return;
}
int32_t fontType;
int32_t fontType = 0;
if (!ProcessSystemFontType(systemFontType, fontType)) {
result = nullptr;
return;
@ -285,14 +292,16 @@ void FontDescriptorCache::GetFontDescSharedPtrByFullName(const std::string& full
}
return false;
};
if ((fontType & TextEngine::FontParser::SystemFontType::GENERIC) && tryFindFontDescriptor(fullNameMap_)) {
if ((static_cast<uint32_t>(fontType) & TextEngine::FontParser::SystemFontType::GENERIC)
&& tryFindFontDescriptor(fullNameMap_)) {
return;
}
if ((fontType & TextEngine::FontParser::SystemFontType::STYLISH) && tryFindFontDescriptor(stylishFullNameMap_)) {
if ((static_cast<uint32_t>(fontType) & TextEngine::FontParser::SystemFontType::STYLISH)
&& tryFindFontDescriptor(stylishFullNameMap_)) {
return;
}
if ((fontType & TextEngine::FontParser::SystemFontType::INSTALLED) &&
ParseInstallFontDescSharedPtrByName(fullName, result)) {
if ((static_cast<uint32_t>(fontType) & TextEngine::FontParser::SystemFontType::INSTALLED)
&& ParseInstallFontDescSharedPtrByName(fullName, result)) {
return;
}
TEXT_LOGD("Failed to get fontDescriptor by fullName: %{public}s", fullName.c_str());
@ -339,7 +348,7 @@ bool FontDescriptorCache::FilterBoldCache(int weight, std::set<FontDescSharedPtr
if (!finishRet.empty()) {
begin = finishRet.begin();
end = finishRet.end();
} else if (weight > WEIGHT_400) {
} else if (static_cast<uint32_t>(weight) > WEIGHT_400) {
begin = boldCache_.begin();
end = boldCache_.end();
} else {

View File

@ -405,7 +405,7 @@ std::vector<std::shared_ptr<FontParser::FontDescriptor>> FontParser::GetSystemFo
descriptors.reserve(typefaces.size());
for (auto& item : typefaces) {
FontDescriptor desc;
desc.requestedLid = GetLanguageId(locale);
desc.requestedLid = static_cast<unsigned int>(GetLanguageId(locale));
desc.path = item->GetFontPath();
auto fontStyle = item->GetFontStyle();
desc.weight = fontStyle.GetWeight();
@ -424,7 +424,7 @@ bool FontParser::ParserFontDescriptorFromPath(const std::string& path,
std::shared_ptr<Drawing::Typeface> typeface;
int index = 0;
FontDescriptor desc;
desc.requestedLid = GetLanguageId(locale);
desc.requestedLid = static_cast<unsigned int>(GetLanguageId(locale));
desc.path = path;
while ((typeface = Drawing::Typeface::MakeFromFile(path.c_str(), index)) != nullptr) {
index++;