mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 01:03:08 +00:00
modify text u16string
Signed-off-by: gzwhdd <ganzhiwei2@huawei.com> Change-Id: I200ddbfe9e759992905f830081db0343879ee46e
This commit is contained in:
parent
e07e53f2b9
commit
11617f4030
@ -273,6 +273,8 @@ frameworks/base/subwindow/ @arkuipopupwindow
|
||||
frameworks/base/system_bar/system_bar_style.h @arkuievent
|
||||
frameworks/base/thread/ @arkuiframework
|
||||
frameworks/base/utils/ @arkuiframework
|
||||
frameworks/base/utils/utf_helper.cpp @huawei_g_five
|
||||
frameworks/base/utils/utf_helper.h @huawei_g_five
|
||||
frameworks/base/view_data/ @huawei_g_five
|
||||
frameworks/base/want/want_wrap.h @arkui_superman
|
||||
frameworks/base/window/drag_window.h @arkuievent
|
||||
|
@ -102,6 +102,7 @@
|
||||
OHOS::Ace::ViewPartialUpdateModel::*;
|
||||
OHOS::Ace::AlertDialogModel::*;
|
||||
OHOS::Ace::StringUtils::*;
|
||||
OHOS::Ace::UtfUtils::*;
|
||||
OHOS::Ace::IndexerModel::*;
|
||||
OHOS::Ace::BadgeModel::*;
|
||||
OHOS::Ace::BlankModel::*;
|
||||
|
@ -74,6 +74,7 @@ template("ace_base_source_set") {
|
||||
"utils/string_utils.cpp",
|
||||
"utils/time_util.cpp",
|
||||
"utils/utf.cpp",
|
||||
"utils/utf_helper.cpp",
|
||||
"utils/utils.cpp",
|
||||
]
|
||||
|
||||
|
@ -705,7 +705,8 @@ inline bool EndWith(const std::string& str, const char* suffix, size_t suffixLen
|
||||
return ((len >= suffixLen) && (str.compare(len - suffixLen, suffixLen, suffix) == 0));
|
||||
}
|
||||
|
||||
inline void TransformStrCase(std::string& str, int32_t textCase)
|
||||
template<typename T>
|
||||
inline void TransformStrCase(T& str, int32_t textCase)
|
||||
{
|
||||
if (str.empty()) {
|
||||
return;
|
||||
|
453
frameworks/base/utils/utf_helper.cpp
Normal file
453
frameworks/base/utils/utf_helper.cpp
Normal file
@ -0,0 +1,453 @@
|
||||
/*
|
||||
* 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 "base/utils/utf_helper.h"
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
namespace OHOS::Ace::UtfUtils {
|
||||
|
||||
const std::string DEFAULT_STR = "error";
|
||||
const std::u16string DEFAULT_U16STR = u"error";
|
||||
const std::u32string DEFAULT_U32STR = U"error";
|
||||
|
||||
constexpr size_t HI_SURROGATE_MIN = 0xd800;
|
||||
constexpr size_t HI_SURROGATE_MAX = 0xdbff;
|
||||
constexpr size_t LO_SURROGATE_MIN = 0xdc00;
|
||||
constexpr size_t LO_SURROGATE_MAX = 0xdfff;
|
||||
|
||||
static constexpr size_t CONST_2 = 2;
|
||||
static constexpr size_t CONST_3 = 3;
|
||||
static constexpr size_t LOW_3BITS = 0x7;
|
||||
static constexpr size_t LOW_4BITS = 0xF;
|
||||
static constexpr size_t LOW_5BITS = 0x1F;
|
||||
static constexpr size_t LOW_6BITS = 0x3F;
|
||||
static constexpr size_t L_SURROGATE_START = 0xDC00;
|
||||
static constexpr size_t H_SURROGATE_START = 0xD800;
|
||||
static constexpr size_t SURROGATE_RAIR_START = 0x10000;
|
||||
static constexpr size_t OFFSET_18POS = 18;
|
||||
static constexpr size_t OFFSET_12POS = 12;
|
||||
static constexpr size_t OFFSET_10POS = 10;
|
||||
static constexpr size_t OFFSET_6POS = 6;
|
||||
static constexpr uint16_t DECODE_LEAD_LOW = 0xD800;
|
||||
static constexpr uint16_t DECODE_LEAD_HIGH = 0xDBFF;
|
||||
static constexpr uint16_t DECODE_TRAIL_LOW = 0xDC00;
|
||||
static constexpr uint16_t DECODE_TRAIL_HIGH = 0xDFFF;
|
||||
static constexpr uint32_t DECODE_SECOND_FACTOR = 0x10000;
|
||||
static constexpr uint32_t UTF8_OFFSET = 6;
|
||||
static constexpr uint32_t UTF16_OFFSET = 10;
|
||||
static constexpr uint16_t SURROGATE_MASK = 0xF800;
|
||||
static constexpr uint16_t UTF16_REPLACEMENT_CHARACTER = 0xFFFD;
|
||||
|
||||
static constexpr uint8_t UTF8_1B_MAX = 0x7f;
|
||||
static constexpr uint16_t UTF8_2B_MAX = 0x7ff;
|
||||
static constexpr uint16_t UTF8_3B_MAX = 0xffff;
|
||||
|
||||
static constexpr uint8_t BYTE_MASK = 0xbf;
|
||||
static constexpr uint8_t BYTE_MARK = 0x80;
|
||||
|
||||
enum UtfLength : uint8_t { ONE = 1, TWO = 2, THREE = 3, FOUR = 4 };
|
||||
|
||||
static const unsigned char FIRST_BYTE_MARK[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC};
|
||||
|
||||
bool IsUTF16HighSurrogate(uint16_t ch)
|
||||
{
|
||||
return DECODE_LEAD_LOW <= ch && ch <= DECODE_LEAD_HIGH;
|
||||
}
|
||||
|
||||
bool IsUTF16LowSurrogate(uint16_t ch)
|
||||
{
|
||||
return DECODE_TRAIL_LOW <= ch && ch <= DECODE_TRAIL_HIGH;
|
||||
}
|
||||
|
||||
// Methods for decode utf16 to unicode
|
||||
uint32_t DecodeUTF16(uint16_t const *utf16, size_t len, size_t *index)
|
||||
{
|
||||
uint16_t high = utf16[*index];
|
||||
if ((high & SURROGATE_MASK) != DECODE_LEAD_LOW || !IsUTF16HighSurrogate(high) || *index == len - 1) {
|
||||
return high;
|
||||
}
|
||||
uint16_t low = utf16[*index + 1];
|
||||
if (!IsUTF16LowSurrogate(low)) {
|
||||
return high;
|
||||
}
|
||||
(*index)++;
|
||||
return ((high - DECODE_LEAD_LOW) << UTF16_OFFSET) + (low - DECODE_TRAIL_LOW) + DECODE_SECOND_FACTOR;
|
||||
}
|
||||
|
||||
uint32_t HandleAndDecodeInvalidUTF16(uint16_t const *utf16, size_t len, size_t *index)
|
||||
{
|
||||
uint16_t first = utf16[*index];
|
||||
// A valid surrogate pair should always start with a High Surrogate
|
||||
if (IsUTF16LowSurrogate(first)) {
|
||||
return UTF16_REPLACEMENT_CHARACTER;
|
||||
}
|
||||
if (IsUTF16HighSurrogate(first) || (first & SURROGATE_MASK) == DECODE_LEAD_LOW) {
|
||||
if (*index == len - 1) {
|
||||
// A High surrogate not paired with another surrogate
|
||||
return UTF16_REPLACEMENT_CHARACTER;
|
||||
}
|
||||
uint16_t second = utf16[*index + 1];
|
||||
if (!IsUTF16LowSurrogate(second)) {
|
||||
// A High surrogate not followed by a low surrogate
|
||||
return UTF16_REPLACEMENT_CHARACTER;
|
||||
}
|
||||
// A valid surrogate pair, decode normally
|
||||
(*index)++;
|
||||
return ((first - DECODE_LEAD_LOW) << UTF16_OFFSET) + (second - DECODE_TRAIL_LOW) + DECODE_SECOND_FACTOR;
|
||||
}
|
||||
// A unicode not fallen into the range of representing by surrogate pair, return as it is
|
||||
return first;
|
||||
}
|
||||
|
||||
static void RepalceUnpairedSurrogates(uint16_t *utf16, size_t end, size_t *index)
|
||||
{
|
||||
uint16_t first = utf16[*index];
|
||||
// A valid surrogate pair should always start with a High Surrogate
|
||||
if (IsUTF16LowSurrogate(first)) {
|
||||
utf16[*index] = UTF16_REPLACEMENT_CHARACTER;
|
||||
return;
|
||||
}
|
||||
if (IsUTF16HighSurrogate(first) || (first & SURROGATE_MASK) == DECODE_LEAD_LOW) {
|
||||
if (*index == end - 1) {
|
||||
// A High surrogate not paired with another surrogate
|
||||
utf16[*index] = UTF16_REPLACEMENT_CHARACTER;
|
||||
return;
|
||||
}
|
||||
uint16_t second = utf16[*index + 1];
|
||||
if (!IsUTF16LowSurrogate(second)) {
|
||||
// A High surrogate not followed by a low surrogate
|
||||
utf16[*index] = UTF16_REPLACEMENT_CHARACTER;
|
||||
return;
|
||||
}
|
||||
// A valid surrogate pair, decode normally
|
||||
(*index)++;
|
||||
return;
|
||||
}
|
||||
// A unicode not fallen into the range of representing by surrogate pair, return as it is
|
||||
return;
|
||||
}
|
||||
|
||||
void HandleInvalidUTF16(uint16_t* utf16In, size_t utf16Len, size_t start)
|
||||
{
|
||||
if (utf16In == nullptr) {
|
||||
return;
|
||||
}
|
||||
size_t end = start + utf16Len;
|
||||
for (size_t i = start; i < end; ++i) {
|
||||
RepalceUnpairedSurrogates(utf16In, end, &i);
|
||||
}
|
||||
}
|
||||
|
||||
inline size_t UTF8Length(uint32_t codepoint)
|
||||
{
|
||||
if (codepoint <= UTF8_1B_MAX) {
|
||||
return UtfLength::ONE;
|
||||
}
|
||||
if (codepoint <= UTF8_2B_MAX) {
|
||||
return UtfLength::TWO;
|
||||
}
|
||||
if (codepoint <= UTF8_3B_MAX) {
|
||||
return UtfLength::THREE;
|
||||
}
|
||||
return UtfLength::FOUR;
|
||||
}
|
||||
|
||||
// Methods for encode unicode to unicode
|
||||
size_t EncodeUTF8(uint32_t codepoint, uint8_t* utf8, size_t len, size_t index)
|
||||
{
|
||||
size_t size = UTF8Length(codepoint);
|
||||
if (index + size > len) {
|
||||
return 0;
|
||||
}
|
||||
for (size_t j = size - 1; j > 0; j--) {
|
||||
uint8_t cont = ((codepoint | BYTE_MARK) & BYTE_MASK);
|
||||
utf8[index + j] = cont;
|
||||
codepoint >>= UTF8_OFFSET;
|
||||
}
|
||||
utf8[index] = codepoint | FIRST_BYTE_MARK[size];
|
||||
return size;
|
||||
}
|
||||
|
||||
size_t Utf16ToUtf8Size(const uint16_t *utf16, uint32_t length)
|
||||
{
|
||||
size_t res = 1; // zero byte
|
||||
// when utf16 data length is only 1 and code in 0xd800-0xdfff,
|
||||
// means that is a single code point, it needs to be represented by three UTF8 code.
|
||||
if (length == 1 && utf16[0] >= HI_SURROGATE_MIN &&
|
||||
utf16[0] <= LO_SURROGATE_MAX) {
|
||||
res += UtfLength::THREE;
|
||||
return res;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
if (utf16[i] == 0) {
|
||||
// do nothing
|
||||
} else if (utf16[i] <= UTF8_1B_MAX) {
|
||||
res += 1;
|
||||
} else if (utf16[i] <= UTF8_2B_MAX) {
|
||||
res += UtfLength::TWO;
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
} else if (utf16[i] < HI_SURROGATE_MIN || utf16[i] > HI_SURROGATE_MAX) {
|
||||
res += UtfLength::THREE;
|
||||
} else {
|
||||
if (i < length - 1 &&
|
||||
utf16[i + 1] >= LO_SURROGATE_MIN &&
|
||||
utf16[i + 1] <= LO_SURROGATE_MAX) {
|
||||
res += UtfLength::FOUR;
|
||||
++i;
|
||||
} else {
|
||||
res += UtfLength::THREE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
size_t ConvertRegionUtf16ToUtf8(const uint16_t *utf16In, uint8_t *utf8Out, size_t utf16Len, size_t utf8Len,
|
||||
size_t start)
|
||||
{
|
||||
if (utf16In == nullptr || utf8Out == nullptr || utf8Len == 0) {
|
||||
return 0;
|
||||
}
|
||||
size_t utf8Pos = 0;
|
||||
size_t end = start + utf16Len;
|
||||
for (size_t i = start; i < end; ++i) {
|
||||
uint32_t codepoint = DecodeUTF16(utf16In, end, &i);
|
||||
if (codepoint == 0) {
|
||||
continue;
|
||||
}
|
||||
utf8Pos += EncodeUTF8(codepoint, utf8Out, utf8Len, utf8Pos);
|
||||
}
|
||||
return utf8Pos;
|
||||
}
|
||||
|
||||
size_t DebuggerConvertRegionUtf16ToUtf8(const uint16_t* utf16In, uint8_t* utf8Out, size_t utf16Len, size_t utf8Len,
|
||||
size_t start)
|
||||
{
|
||||
if (utf16In == nullptr || utf8Out == nullptr || utf8Len == 0) {
|
||||
return 0;
|
||||
}
|
||||
size_t utf8Pos = 0;
|
||||
size_t end = start + utf16Len;
|
||||
for (size_t i = start; i < end; ++i) {
|
||||
uint32_t codepoint = HandleAndDecodeInvalidUTF16(utf16In, end, &i);
|
||||
if (codepoint == 0) {
|
||||
continue;
|
||||
}
|
||||
utf8Pos += EncodeUTF8(codepoint, utf8Out, utf8Len, utf8Pos);
|
||||
}
|
||||
return utf8Pos;
|
||||
}
|
||||
|
||||
// drop the tail bytes if the remain length can't fill the length it represents.
|
||||
static size_t FixUtf8Len(const uint8_t* utf8, size_t utf8Len)
|
||||
{
|
||||
size_t trimSize = 0;
|
||||
if (utf8Len >= 1 && utf8[utf8Len - 1] >= 0xC0) {
|
||||
// The last one char claim there are more than 1 byte next to it, it's invalid, so drop the last one.
|
||||
trimSize = 1;
|
||||
}
|
||||
if (utf8Len >= CONST_2 && utf8[utf8Len - CONST_2] >= 0xE0) {
|
||||
// The second to last char claim there are more than 2 bytes next to it, it's invalid, so drop the last two.
|
||||
trimSize = CONST_2;
|
||||
}
|
||||
if (utf8Len >= CONST_3 && utf8[utf8Len - CONST_3] >= 0xF0) {
|
||||
// The third to last char claim there are more than 3 bytes next to it, it's invalid, so drop the last three.
|
||||
trimSize = CONST_3;
|
||||
}
|
||||
return utf8Len - trimSize;
|
||||
}
|
||||
|
||||
size_t Utf8ToUtf16Size(const uint8_t *utf8, size_t utf8Len)
|
||||
{
|
||||
size_t safeUtf8Len = FixUtf8Len(utf8, utf8Len);
|
||||
size_t in_pos = 0;
|
||||
size_t res = 0;
|
||||
while (in_pos < safeUtf8Len) {
|
||||
uint8_t src = utf8[in_pos];
|
||||
switch (src & 0xF0) {
|
||||
case 0xF0: {
|
||||
const uint8_t c2 = utf8[++in_pos];
|
||||
const uint8_t c3 = utf8[++in_pos];
|
||||
const uint8_t c4 = utf8[++in_pos];
|
||||
uint32_t codePoint = ((src & LOW_3BITS) << OFFSET_18POS) | ((c2 & LOW_6BITS) << OFFSET_12POS) |
|
||||
((c3 & LOW_6BITS) << OFFSET_6POS) | (c4 & LOW_6BITS);
|
||||
if (codePoint >= SURROGATE_RAIR_START) {
|
||||
res += CONST_2;
|
||||
} else {
|
||||
res++;
|
||||
}
|
||||
in_pos++;
|
||||
break;
|
||||
}
|
||||
case 0xE0: {
|
||||
in_pos += CONST_3;
|
||||
res++;
|
||||
break;
|
||||
}
|
||||
case 0xD0:
|
||||
case 0xC0: {
|
||||
in_pos += CONST_2;
|
||||
res++;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
do {
|
||||
in_pos++;
|
||||
res++;
|
||||
} while (in_pos < safeUtf8Len && utf8[in_pos] < 0x80);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// The remain chars should be treated as single byte char.
|
||||
res += utf8Len - in_pos;
|
||||
return res;
|
||||
}
|
||||
|
||||
#define CHECK_OUT_POS_RETURN(out_pos, utf16Len) \
|
||||
do { \
|
||||
if ((out_pos) >= (utf16Len) - 1) { \
|
||||
return out_pos; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
size_t ConvertRegionUtf8ToUtf16(const uint8_t *utf8In, uint16_t *utf16Out, size_t utf8Len, size_t utf16Len)
|
||||
{
|
||||
size_t safeUtf8Len = FixUtf8Len(utf8In, utf8Len);
|
||||
size_t in_pos = 0;
|
||||
size_t out_pos = 0;
|
||||
while (in_pos < safeUtf8Len && out_pos < utf16Len) {
|
||||
uint8_t src = utf8In[in_pos];
|
||||
switch (src & 0xF0) {
|
||||
case 0xF0: {
|
||||
const uint8_t c2 = utf8In[++in_pos];
|
||||
const uint8_t c3 = utf8In[++in_pos];
|
||||
const uint8_t c4 = utf8In[++in_pos];
|
||||
uint32_t codePoint = ((src & LOW_3BITS) << OFFSET_18POS) | ((c2 & LOW_6BITS) << OFFSET_12POS) |
|
||||
((c3 & LOW_6BITS) << OFFSET_6POS) | (c4 & LOW_6BITS);
|
||||
if (codePoint >= SURROGATE_RAIR_START) {
|
||||
CHECK_OUT_POS_RETURN(out_pos, utf16Len);
|
||||
codePoint -= SURROGATE_RAIR_START;
|
||||
utf16Out[out_pos++] = static_cast<uint16_t>((codePoint >> OFFSET_10POS) | H_SURROGATE_START);
|
||||
utf16Out[out_pos++] = static_cast<uint16_t>((codePoint & 0x3FF) | L_SURROGATE_START);
|
||||
} else {
|
||||
utf16Out[out_pos++] = static_cast<uint16_t>(codePoint);
|
||||
}
|
||||
in_pos++;
|
||||
break;
|
||||
}
|
||||
case 0xE0: {
|
||||
const uint8_t c2 = utf8In[++in_pos];
|
||||
const uint8_t c3 = utf8In[++in_pos];
|
||||
utf16Out[out_pos++] = static_cast<uint16_t>(((src & LOW_4BITS) << OFFSET_12POS) |
|
||||
((c2 & LOW_6BITS) << OFFSET_6POS) | (c3 & LOW_6BITS));
|
||||
in_pos++;
|
||||
break;
|
||||
}
|
||||
case 0xD0:
|
||||
case 0xC0: {
|
||||
const uint8_t c2 = utf8In[++in_pos];
|
||||
utf16Out[out_pos++] = static_cast<uint16_t>(((src & LOW_5BITS) << OFFSET_6POS) | (c2 & LOW_6BITS));
|
||||
in_pos++;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
do {
|
||||
utf16Out[out_pos++] = static_cast<uint16_t>(utf8In[in_pos++]);
|
||||
} while (in_pos < safeUtf8Len && out_pos < utf16Len && utf8In[in_pos] < 0x80);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// The remain chars should be treated as single byte char.
|
||||
while (in_pos < utf8Len && out_pos < utf16Len) {
|
||||
utf16Out[out_pos++] = static_cast<uint16_t>(utf8In[in_pos++]);
|
||||
}
|
||||
return out_pos;
|
||||
}
|
||||
|
||||
std::u16string Str8ToStr16(const std::string& str)
|
||||
{
|
||||
if (str.empty()) {
|
||||
return u"";
|
||||
}
|
||||
if (str == DEFAULT_STR) {
|
||||
return DEFAULT_U16STR;
|
||||
}
|
||||
const uint8_t* buf8 = reinterpret_cast<const uint8_t*>(str.c_str());
|
||||
size_t utf8Len = str.size();
|
||||
auto utf16Len = Utf8ToUtf16Size(buf8, utf8Len);
|
||||
std::unique_ptr<uint16_t[]> pBuf16 = std::make_unique<uint16_t[]>(utf16Len);
|
||||
uint16_t *buf16 = pBuf16.get();
|
||||
auto resultLen = ConvertRegionUtf8ToUtf16(buf8, buf16, utf8Len, utf16Len);
|
||||
if (resultLen == utf16Len) {
|
||||
return std::u16string(reinterpret_cast<const char16_t*>(buf16), utf16Len);
|
||||
}
|
||||
return u"";
|
||||
}
|
||||
|
||||
// Illegal bytes are replaced with U+FFFD
|
||||
std::u16string Str8DebugToStr16(const std::string& str)
|
||||
{
|
||||
if (str.empty()) {
|
||||
return u"";
|
||||
}
|
||||
if (str == DEFAULT_STR) {
|
||||
return DEFAULT_U16STR;
|
||||
}
|
||||
icu::UnicodeString ustring = icu::UnicodeString::fromUTF8(str);
|
||||
return std::u16string(ustring.getBuffer(), static_cast<size_t>(ustring.length()));
|
||||
}
|
||||
|
||||
std::string Str16ToStr8(const std::u16string& str)
|
||||
{
|
||||
if (str.empty()) {
|
||||
return "";
|
||||
}
|
||||
if (str == DEFAULT_U16STR) {
|
||||
return DEFAULT_STR;
|
||||
}
|
||||
const uint16_t* buf16 = reinterpret_cast<const uint16_t*>(str.c_str());
|
||||
size_t utf16Len = str.size();
|
||||
auto utf8Len = Utf16ToUtf8Size(buf16, utf16Len) - 1;
|
||||
std::unique_ptr<uint8_t[]> pBuf8 = std::make_unique<uint8_t[]>(utf8Len);
|
||||
uint8_t *buf8 = pBuf8.get();
|
||||
auto resultLen = ConvertRegionUtf16ToUtf8(buf16, buf8, utf16Len, utf8Len, 0);
|
||||
if (resultLen == utf8Len) {
|
||||
return std::string(reinterpret_cast<const char*>(buf8), utf8Len);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Unpaired surrogates are replace with U+FFFD
|
||||
std::string Str16DebugToStr8(const std::u16string& str)
|
||||
{
|
||||
if (str.empty()) {
|
||||
return "";
|
||||
}
|
||||
if (str == DEFAULT_U16STR) {
|
||||
return DEFAULT_STR;
|
||||
}
|
||||
const uint16_t* buf16 = reinterpret_cast<const uint16_t*>(str.c_str());
|
||||
size_t utf16Len = str.size();
|
||||
auto utf8Len = Utf16ToUtf8Size(buf16, utf16Len) - 1;
|
||||
std::unique_ptr<uint8_t[]> pBuf8 = std::make_unique<uint8_t[]>(utf8Len);
|
||||
uint8_t *buf8 = pBuf8.get();
|
||||
auto resultLen = DebuggerConvertRegionUtf16ToUtf8(buf16, buf8, utf16Len, utf8Len, 0);
|
||||
if (resultLen == utf8Len) {
|
||||
return std::string(reinterpret_cast<const char*>(buf8), utf8Len);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
} // namespace OHOS::Ace::UtfUtils
|
61
frameworks/base/utils/utf_helper.h
Normal file
61
frameworks/base/utils/utf_helper.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_UTF_HELPER_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_UTF_HELPER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "base/utils/macros.h"
|
||||
|
||||
namespace OHOS::Ace::UtfUtils {
|
||||
ACE_EXPORT extern const std::string DEFAULT_STR;
|
||||
ACE_EXPORT extern const std::u16string DEFAULT_U16STR;
|
||||
ACE_EXPORT extern const std::u32string DEFAULT_U32STR;
|
||||
|
||||
uint32_t DecodeUTF16(uint16_t const *utf16, size_t len, size_t *index);
|
||||
|
||||
size_t EncodeUTF8(uint32_t codepoint, uint8_t* utf8, size_t len, size_t index);
|
||||
|
||||
size_t Utf16ToUtf8Size(const uint16_t *utf16, uint32_t length);
|
||||
|
||||
size_t ConvertRegionUtf16ToUtf8(const uint16_t *utf16In, uint8_t *utf8Out, size_t utf16Len,
|
||||
size_t utf8Len, size_t start);
|
||||
|
||||
size_t DebuggerConvertRegionUtf16ToUtf8(const uint16_t *utf16In, uint8_t *utf8Out, size_t utf16Len, size_t utf8Len,
|
||||
size_t start);
|
||||
|
||||
uint32_t HandleAndDecodeInvalidUTF16(uint16_t const *utf16, size_t len, size_t *index);
|
||||
|
||||
size_t Utf8ToUtf16Size(const uint8_t *utf8, size_t utf8Len);
|
||||
|
||||
size_t ConvertRegionUtf8ToUtf16(const uint8_t *utf8In, uint16_t *utf16Out, size_t utf8Len, size_t utf16Len);
|
||||
|
||||
std::u16string ACE_FORCE_EXPORT Str8ToStr16(const std::string& str);
|
||||
|
||||
std::u16string ACE_FORCE_EXPORT Str8DebugToStr16(const std::string& str);
|
||||
|
||||
std::string ACE_FORCE_EXPORT Str16ToStr8(const std::u16string& str);
|
||||
|
||||
std::string ACE_FORCE_EXPORT Str16DebugToStr8(const std::u16string& str);
|
||||
|
||||
void HandleInvalidUTF16(uint16_t* utf16In, size_t utf16Len, size_t start);
|
||||
|
||||
} // namespace OHOS::Ace::UtfUtils
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_UTF_HELPER_H
|
@ -135,6 +135,23 @@ std::string JsiValue::ToString() const
|
||||
return GetHandle()->ToString(vm)->ToString(vm);
|
||||
}
|
||||
|
||||
std::u16string JsiValue::ToU16String() const
|
||||
{
|
||||
auto vm = GetEcmaVM();
|
||||
Local<StringRef> stringRef;
|
||||
panda::LocalScope scope(vm);
|
||||
if (IsObject()) {
|
||||
stringRef = JSON::Stringify(vm, GetLocalHandle())->ToString(vm);
|
||||
} else {
|
||||
stringRef = GetHandle()->ToString(vm);
|
||||
}
|
||||
auto utf16Len = stringRef->Length(vm);
|
||||
std::unique_ptr<char16_t[]> pBuf16 = std::make_unique<char16_t[]>(utf16Len);
|
||||
char16_t *buf16 = pBuf16.get();
|
||||
auto resultLen = stringRef->WriteUtf16(vm, buf16, utf16Len);
|
||||
return std::u16string(buf16, resultLen);
|
||||
}
|
||||
|
||||
bool JsiValue::ToBoolean() const
|
||||
{
|
||||
return GetHandle()->BooleaValue(GetEcmaVM());
|
||||
|
@ -97,6 +97,7 @@ public:
|
||||
bool IsUndefined() const;
|
||||
bool IsNull() const;
|
||||
std::string ToString() const;
|
||||
std::u16string ToU16String() const;
|
||||
bool ToBoolean() const;
|
||||
|
||||
template<typename T>
|
||||
|
@ -77,6 +77,8 @@ panda::Local<panda::JSValueRef> toJsiValueWithVM(const EcmaVM* vm, T val)
|
||||
return panda::StringRef::NewFromUtf8(vm, val.c_str());
|
||||
} else if constexpr (std::is_same_v<T, const char*>) {
|
||||
return panda::StringRef::NewFromUtf8(vm, val);
|
||||
} else if constexpr (std::is_same_v<T, std::u16string>) {
|
||||
return panda::StringRef::NewFromUtf16(vm, val.c_str());
|
||||
}
|
||||
|
||||
return panda::JSValueRef::Undefined(vm);
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "base/log/ace_scoring_log.h"
|
||||
#include "base/log/log_wrapper.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "bridge/declarative_frontend/engine/functions/js_click_function.h"
|
||||
#include "bridge/declarative_frontend/engine/functions/js_hover_function.h"
|
||||
#include "bridge/declarative_frontend/engine/functions/js_key_function.h"
|
||||
@ -408,19 +409,19 @@ std::function<void()> JSInteractableView::GetRemoteMessageEventCallback(const JS
|
||||
}
|
||||
|
||||
#if !defined(PREVIEW) && defined(OHOS_PLATFORM)
|
||||
void JSInteractableView::ReportClickEvent(const WeakPtr<NG::FrameNode>& node, const std::string text)
|
||||
void JSInteractableView::ReportClickEvent(const WeakPtr<NG::FrameNode>& node, const std::u16string text)
|
||||
{
|
||||
if (UiSessionManager::GetInstance().GetClickEventRegistered()) {
|
||||
auto data = JsonUtil::Create();
|
||||
data->Put("event", "onClick");
|
||||
std::string content = text;
|
||||
std::u16string content = text;
|
||||
if (!node.Invalid()) {
|
||||
data->Put("id", node.GetRawPtr()->GetId());
|
||||
auto children = node.GetRawPtr()->GetChildren();
|
||||
if (!children.empty()) {
|
||||
node.GetRawPtr()->GetContainerComponentText(content);
|
||||
}
|
||||
data->Put("text", content.data());
|
||||
data->Put("text", UtfUtils::Str16ToStr8(content).data());
|
||||
data->Put("position", node.GetRawPtr()->GetGeometryNode()->GetFrameRect().ToString().data());
|
||||
}
|
||||
UiSessionManager::GetInstance().ReportClickEvent(data->ToString());
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
|
||||
static std::function<void()> GetRemoteMessageEventCallback(const JSCallbackInfo& info);
|
||||
#if !defined(PREVIEW) && defined(OHOS_PLATFORM)
|
||||
static void ReportClickEvent(const WeakPtr<NG::FrameNode>& node, const std::string text = "");
|
||||
static void ReportClickEvent(const WeakPtr<NG::FrameNode>& node, const std::u16string text = u"");
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
@ -684,13 +684,13 @@ void JSText::JsOnClick(const JSCallbackInfo& info)
|
||||
PipelineContext::SetCallBackNode(node);
|
||||
func->Execute(*clickInfo);
|
||||
#if !defined(PREVIEW) && defined(OHOS_PLATFORM)
|
||||
std::string label = "";
|
||||
std::u16string label = u"";
|
||||
if (!node.Invalid()) {
|
||||
auto pattern = node.GetRawPtr()->GetPattern();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
auto layoutProperty = pattern->GetLayoutProperty<NG::TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
label = layoutProperty->GetContent().value_or("");
|
||||
label = layoutProperty->GetContent().value_or(u"");
|
||||
}
|
||||
JSInteractableView::ReportClickEvent(node, label);
|
||||
#endif
|
||||
@ -750,7 +750,7 @@ void JSText::JsRemoteMessage(const JSCallbackInfo& info)
|
||||
|
||||
void JSText::Create(const JSCallbackInfo& info)
|
||||
{
|
||||
std::string data;
|
||||
std::u16string data;
|
||||
if (info.Length() <= 0) {
|
||||
TextModel::GetInstance()->Create(data);
|
||||
return;
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "base/memory/referenced.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "bridge/common/utils/engine_helper.h"
|
||||
#include "bridge/declarative_frontend/engine/functions/js_click_function.h"
|
||||
#include "bridge/declarative_frontend/engine/functions/js_clipboard_function.h"
|
||||
@ -5751,12 +5752,8 @@ bool JSViewAbstract::ParseJsFontFamilies(const JSRef<JSVal>& jsValue, std::vecto
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JSViewAbstract::ParseJsString(const JSRef<JSVal>& jsValue, std::string& result)
|
||||
bool JSViewAbstract::ParseJsStringObj(const JSRef<JSVal>& jsValue, std::string& result)
|
||||
{
|
||||
if (jsValue->IsString()) {
|
||||
result = jsValue->ToString();
|
||||
return true;
|
||||
}
|
||||
if (!jsValue->IsObject()) {
|
||||
return false;
|
||||
}
|
||||
@ -5829,6 +5826,30 @@ bool JSViewAbstract::ParseJsString(const JSRef<JSVal>& jsValue, std::string& res
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JSViewAbstract::ParseJsString(const JSRef<JSVal>& jsValue, std::string& result)
|
||||
{
|
||||
if (jsValue->IsString()) {
|
||||
result = jsValue->ToString();
|
||||
return true;
|
||||
}
|
||||
return ParseJsStringObj(jsValue, result);
|
||||
}
|
||||
|
||||
bool JSViewAbstract::ParseJsString(const JSRef<JSVal>& jsValue, std::u16string& result)
|
||||
{
|
||||
std::string u8Result;
|
||||
if (jsValue->IsString()) {
|
||||
result = jsValue->ToU16String();
|
||||
return true;
|
||||
}
|
||||
bool ret = ParseJsStringObj(jsValue, u8Result);
|
||||
if (ret) {
|
||||
result = UtfUtils::Str8ToStr16(u8Result);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool JSViewAbstract::ParseJsMedia(const JSRef<JSVal>& jsValue, std::string& result)
|
||||
{
|
||||
if (!jsValue->IsObject() && !jsValue->IsString()) {
|
||||
|
@ -325,6 +325,7 @@ public:
|
||||
static bool ParseJsonDouble(const std::unique_ptr<JsonValue>& jsonValue, double& result);
|
||||
static bool ParseJsonColor(const std::unique_ptr<JsonValue>& jsonValue, Color& result);
|
||||
static bool ParseJsString(const JSRef<JSVal>& jsValue, std::string& result);
|
||||
static bool ParseJsString(const JSRef<JSVal>& jsValue, std::u16string& result);
|
||||
static bool ParseJsMedia(const JSRef<JSVal>& jsValue, std::string& result);
|
||||
static bool ParseJsMediaWithBundleName(const JSRef<JSVal>& jsValue, std::string& result, std::string& bundleName,
|
||||
std::string& moduleName, int32_t& resId);
|
||||
@ -639,6 +640,7 @@ public:
|
||||
const std::optional<Dimension>& radiusBottomEnd);
|
||||
|
||||
private:
|
||||
static bool ParseJsStringObj(const JSRef<JSVal>& jsValue, std::string& result);
|
||||
static bool ParseJSMediaInternal(const JSRef<JSObject>& jsValue, std::string& result);
|
||||
static bool ParseResourceToDoubleByName(
|
||||
const JSRef<JSObject>& jsObj, int32_t resType, const RefPtr<ResourceWrapper>& resourceWrapper, double& result);
|
||||
|
@ -39,6 +39,11 @@ void TextModelImpl::Create(const std::string& content)
|
||||
textComponent->SetTextStyle(textStyle);
|
||||
}
|
||||
|
||||
void TextModelImpl::Create(const std::u16string& content)
|
||||
{
|
||||
Create(UtfUtils::Str16ToStr8(content));
|
||||
}
|
||||
|
||||
void TextModelImpl::SetFont(const Font& value) {}
|
||||
|
||||
void TextModelImpl::SetFontSize(const Dimension& value)
|
||||
|
@ -27,6 +27,7 @@ namespace OHOS::Ace::Framework {
|
||||
class ACE_EXPORT TextModelImpl : public TextModel {
|
||||
public:
|
||||
void Create(const std::string& content) override;
|
||||
void Create(const std::u16string& content) override;
|
||||
void Create(const RefPtr<SpanStringBase>& spanString) override {}
|
||||
void SetFont(const Font& value) override;
|
||||
void SetFontSize(const Dimension& value) override;
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "base/json/json_util.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/common/ace_engine.h"
|
||||
#include "core/components_ng/base/inspector_filter.h"
|
||||
#include "core/components_ng/pattern/button/button_layout_property.h"
|
||||
@ -310,7 +311,7 @@ bool GetTextByLayoutProperty(const RefPtr<NG::FrameNode>& frameNode, std::string
|
||||
} else if (AceType::InstanceOf<NG::TextLayoutProperty>(layoutProperty)) {
|
||||
auto textLayoutProperty = AceType::DynamicCast<NG::TextLayoutProperty>(layoutProperty);
|
||||
if (textLayoutProperty) {
|
||||
text = textLayoutProperty->GetContent().value();
|
||||
text = UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/common/agingadapation/aging_adapation_dialog_util.h"
|
||||
|
||||
#include "core/common/agingadapation/aging_adapation_dialog_theme.h"
|
||||
#include "core/components_ng/pattern/text/text_pattern.h"
|
||||
namespace OHOS::Ace::NG {
|
||||
|
||||
RefPtr<FrameNode> AgingAdapationDialogUtil::ShowLongPressDialog(
|
||||
const std::string& message, ImageSourceInfo& imageSourceInfo)
|
||||
{
|
||||
return ShowLongPressDialog(UtfUtils::Str8ToStr16(message), imageSourceInfo);
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> AgingAdapationDialogUtil::ShowLongPressDialog(
|
||||
const std::u16string& message, ImageSourceInfo& imageSourceInfo)
|
||||
{
|
||||
RefPtr<FrameNode> columnNode = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG,
|
||||
ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<LinearLayoutPattern>(true));
|
||||
@ -69,6 +75,12 @@ RefPtr<FrameNode> AgingAdapationDialogUtil::ShowLongPressDialog(
|
||||
|
||||
RefPtr<FrameNode> AgingAdapationDialogUtil::ShowLongPressDialog(
|
||||
const std::string& message, const RefPtr<FrameNode>& iconNode)
|
||||
{
|
||||
return ShowLongPressDialog(UtfUtils::Str8ToStr16(message), iconNode);
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> AgingAdapationDialogUtil::ShowLongPressDialog(
|
||||
const std::u16string& message, const RefPtr<FrameNode>& iconNode)
|
||||
{
|
||||
auto context = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_RETURN(context, nullptr);
|
||||
@ -154,7 +166,7 @@ RefPtr<FrameNode> AgingAdapationDialogUtil::CreateCustomDialog(const RefPtr<Fram
|
||||
return overlayManager->ShowDialogWithNode(dialogProperties, columnNode, isRightToLeft);
|
||||
}
|
||||
|
||||
void AgingAdapationDialogUtil::CreateDialogTextNode(const RefPtr<FrameNode>& columnNode, const std::string& message)
|
||||
void AgingAdapationDialogUtil::CreateDialogTextNode(const RefPtr<FrameNode>& columnNode, const std::u16string& message)
|
||||
{
|
||||
CHECK_NULL_VOID(columnNode);
|
||||
auto context = PipelineBase::GetCurrentContext();
|
||||
|
@ -27,14 +27,16 @@ namespace OHOS::Ace::NG {
|
||||
|
||||
class AgingAdapationDialogUtil {
|
||||
public:
|
||||
static RefPtr<FrameNode> ShowLongPressDialog(const std::string& message, ImageSourceInfo& imageSourceInfo);
|
||||
static RefPtr<FrameNode> ShowLongPressDialog(const std::string& message, const RefPtr<FrameNode>& iconNode);
|
||||
static RefPtr<FrameNode> ShowLongPressDialog(const std::u16string& message, const RefPtr<FrameNode>& iconNode);
|
||||
static RefPtr<FrameNode> ShowLongPressDialog(const std::string& message, ImageSourceInfo& imageSourceInfo);
|
||||
static RefPtr<FrameNode> ShowLongPressDialog(const std::u16string& message, ImageSourceInfo& imageSourceInfo);
|
||||
static float GetDialogBigFontSizeScale();
|
||||
static float GetDialogLargeFontSizeScale();
|
||||
static float GetDialogMaxFontSizeScale();
|
||||
|
||||
private:
|
||||
static void CreateDialogTextNode(const RefPtr<FrameNode>& columnNode, const std::string& message);
|
||||
static void CreateDialogTextNode(const RefPtr<FrameNode>& columnNode, const std::u16string& message);
|
||||
static RefPtr<FrameNode> CreateCustomDialog(const RefPtr<FrameNode>& columnNode);
|
||||
};
|
||||
|
||||
|
@ -1750,7 +1750,7 @@ void UINode::NotifyWebPattern(bool isRegister)
|
||||
}
|
||||
}
|
||||
|
||||
void UINode::GetContainerComponentText(std::string& text)
|
||||
void UINode::GetContainerComponentText(std::u16string& text)
|
||||
{
|
||||
for (const auto& child : GetChildren()) {
|
||||
if (InstanceOf<FrameNode>(child) && child->GetTag() == V2::TEXT_ETS_TAG) {
|
||||
@ -1759,7 +1759,7 @@ void UINode::GetContainerComponentText(std::string& text)
|
||||
CHECK_NULL_VOID(pattern);
|
||||
auto layoutProperty = pattern->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
text = layoutProperty->GetContent().value_or("");
|
||||
text = layoutProperty->GetContent().value_or(u"");
|
||||
break;
|
||||
}
|
||||
child->GetContainerComponentText(text);
|
||||
|
@ -757,7 +757,7 @@ public:
|
||||
|
||||
virtual void GetInspectorValue();
|
||||
virtual void NotifyWebPattern(bool isRegister);
|
||||
void GetContainerComponentText(std::string& text);
|
||||
void GetContainerComponentText(std::u16string& text);
|
||||
|
||||
enum class NotificationType : int32_t {
|
||||
START_CHANGE_POSITION = 0,
|
||||
|
@ -107,7 +107,7 @@ void BadgeLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
|
||||
layoutProperty->HasBadgeMaxCount() ? layoutProperty->GetBadgeMaxCountValue() : badgeTheme->GetMaxCount();
|
||||
auto badgeCircleRadius = badgeCircleDiameter / 2;
|
||||
|
||||
std::string textData;
|
||||
std::u16string textData;
|
||||
if (textLayoutProperty->HasContent()) {
|
||||
textData = textLayoutProperty->GetContentValue();
|
||||
}
|
||||
@ -258,7 +258,7 @@ void BadgeLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper)
|
||||
auto textGeometryNode = textWrapper->GetGeometryNode();
|
||||
CHECK_NULL_VOID(textGeometryNode);
|
||||
|
||||
std::string textData;
|
||||
std::u16string textData;
|
||||
if (textLayoutProperty->HasContent()) {
|
||||
textData = textLayoutProperty->GetContentValue();
|
||||
}
|
||||
@ -299,7 +299,7 @@ void BadgeLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper)
|
||||
OffsetF textOffset;
|
||||
if (layoutProperty->GetIsPositionXy().has_value() && !layoutProperty->GetIsPositionXy().value()) {
|
||||
textOffset = GetTextDataOffset(layoutProperty, badgeCircleDiameter, badgeCircleRadius,
|
||||
geometryNode, textData == " ");
|
||||
geometryNode, textData == u" ");
|
||||
} else {
|
||||
textOffset = GetTextOffsetByPosition(layoutProperty, geometryNode);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ void BadgePattern::OnModifyDone()
|
||||
textLayoutProperty->UpdateContent(badgeValue.value());
|
||||
if (badgeValue.value().empty()) {
|
||||
TAG_LOGI(AceLogTag::ACE_BADGE, "Badge content is empty");
|
||||
textLayoutProperty->UpdateContent(" ");
|
||||
textLayoutProperty->UpdateContent(u" ");
|
||||
}
|
||||
badgeVisible = true;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/button/toggle_button_pattern.h"
|
||||
|
||||
#include "core/components/toggle/toggle_theme.h"
|
||||
@ -326,7 +327,7 @@ void ToggleButtonPattern::InitButtonAndText()
|
||||
if (textLayoutProperty->HasFontSize()) {
|
||||
layoutProperty->UpdateFontSize(textLayoutProperty->GetFontSizeValue(textFontSize_));
|
||||
}
|
||||
layoutProperty->UpdateLabel(textLayoutProperty->GetContentValue(""));
|
||||
layoutProperty->UpdateLabel(UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue(u"")));
|
||||
if (!textLayoutProperty->GetTextColor().has_value()) {
|
||||
textLayoutProperty->UpdateTextColor(textColor_);
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ RefPtr<FrameNode> CalendarDialogView::CreateTitleNode(const RefPtr<FrameNode>& c
|
||||
CHECK_NULL_RETURN(textTitleNode, nullptr);
|
||||
auto textLayoutProperty = textTitleNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, nullptr);
|
||||
textLayoutProperty->UpdateContent("");
|
||||
textLayoutProperty->UpdateContent(u"");
|
||||
MarginProperty textMargin;
|
||||
textMargin.left = CalcLength(theme->GetCalendarTitleTextPadding());
|
||||
textMargin.right = CalcLength(theme->GetCalendarTitleTextPadding());
|
||||
@ -617,7 +617,7 @@ RefPtr<FrameNode> CalendarDialogView::CreateButtonNode(bool isConfirm, const std
|
||||
CHECK_NULL_RETURN(textLayoutProperty, nullptr);
|
||||
textLayoutProperty->UpdateContent(
|
||||
Localization::GetInstance()->GetEntryLetters(isConfirm ? "common.ok" : "common.cancel"));
|
||||
|
||||
|
||||
auto fontSizeScale = pipeline->GetFontScale();
|
||||
auto fontSize = pickerTheme->GetOptionStyle(false, false).GetFontSize();
|
||||
if (fontSizeScale < calendarTheme->GetCalendarPickerLargeScale() || CheckOrientationChange()) {
|
||||
@ -682,7 +682,7 @@ void CalendarDialogView::UpdateButtonLayoutProperty(const RefPtr<FrameNode>& but
|
||||
} else {
|
||||
width = CalcLength(pickerTheme->GetButtonWidth());
|
||||
}
|
||||
|
||||
|
||||
auto fontSizeScale = pipeline->GetFontScale();
|
||||
if (fontSizeScale >= calendarTheme->GetCalendarPickerLargerScale() &&
|
||||
(!(GetPreviousOrientation() == SystemProperties::GetDeviceOrientation())
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/i18n/localization.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components/calendar/calendar_theme.h"
|
||||
#include "core/components_ng/pattern/calendar_picker/calendar_dialog_view.h"
|
||||
#include "core/components_ng/pattern/container_modal/container_modal_pattern.h"
|
||||
@ -78,7 +79,7 @@ void CalendarPickerPattern::UpdateAccessibilityText()
|
||||
CHECK_NULL_VOID(textFrameNode);
|
||||
auto textLayoutProperty = textFrameNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(textLayoutProperty);
|
||||
message += textLayoutProperty->GetContent().value_or("");
|
||||
message += UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u""));
|
||||
}
|
||||
auto textAccessibilityProperty = contentNode->GetAccessibilityProperty<AccessibilityProperty>();
|
||||
CHECK_NULL_VOID(textAccessibilityProperty);
|
||||
@ -164,7 +165,7 @@ void CalendarPickerPattern::UpdateEntryButtonBorderWidth()
|
||||
CHECK_NULL_VOID(addButtonNode);
|
||||
auto subButtonNode = AceType::DynamicCast<FrameNode>(buttonFlexNode->GetChildAtIndex(SUB_BUTTON_INDEX));
|
||||
CHECK_NULL_VOID(subButtonNode);
|
||||
|
||||
|
||||
auto textDirection = host->GetLayoutProperty()->GetNonAutoLayoutDirection();
|
||||
BorderWidthProperty addBorderWidth;
|
||||
BorderWidthProperty subBorderWidth;
|
||||
@ -1155,19 +1156,22 @@ std::string CalendarPickerPattern::GetEntryDateInfo()
|
||||
CHECK_NULL_RETURN(yearNode, "");
|
||||
auto textLayoutProperty = yearNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, "");
|
||||
json->Put("year", StringUtils::StringToInt(textLayoutProperty->GetContent().value_or("1970")));
|
||||
json->Put("year",
|
||||
StringUtils::StringToInt(UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u"1970"))));
|
||||
|
||||
auto monthNode = AceType::DynamicCast<FrameNode>(contentNode->GetChildAtIndex(monthIndex_));
|
||||
CHECK_NULL_RETURN(monthNode, "");
|
||||
textLayoutProperty = monthNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, "");
|
||||
json->Put("month", StringUtils::StringToInt(textLayoutProperty->GetContent().value_or("01")));
|
||||
json->Put("month",
|
||||
StringUtils::StringToInt(UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u"01"))));
|
||||
|
||||
auto dayNode = AceType::DynamicCast<FrameNode>(contentNode->GetChildAtIndex(dayIndex_));
|
||||
CHECK_NULL_RETURN(dayNode, "");
|
||||
textLayoutProperty = dayNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, "");
|
||||
json->Put("day", StringUtils::StringToInt(textLayoutProperty->GetContent().value_or("01")));
|
||||
json->Put("day",
|
||||
StringUtils::StringToInt(UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u"01"))));
|
||||
|
||||
return json->ToString();
|
||||
}
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
constexpr char sub[] = "-";
|
||||
constexpr char add[] = "+";
|
||||
constexpr char16_t SUB[] = u"-";
|
||||
constexpr char16_t ADD[] = u"+";
|
||||
} // namespace
|
||||
void CounterModelNG::Create()
|
||||
{
|
||||
@ -52,7 +52,7 @@ void CounterModelNG::Create()
|
||||
auto contentId = counterPattern->GetContentId();
|
||||
auto addId = counterPattern->GetAddId();
|
||||
if (!hasSubNode) {
|
||||
auto subNode = CreateButtonChild(subId, sub, counterTheme);
|
||||
auto subNode = CreateButtonChild(subId, SUB, counterTheme);
|
||||
subNode->MountToParent(counterNode);
|
||||
}
|
||||
if (!hasContentNode) {
|
||||
@ -60,14 +60,14 @@ void CounterModelNG::Create()
|
||||
contentNode->MountToParent(counterNode);
|
||||
}
|
||||
if (!hasAddNode) {
|
||||
auto addNode = CreateButtonChild(addId, add, counterTheme);
|
||||
auto addNode = CreateButtonChild(addId, ADD, counterTheme);
|
||||
addNode->MountToParent(counterNode);
|
||||
}
|
||||
stack->Push(counterNode);
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> CounterModelNG::CreateButtonChild(
|
||||
int32_t id, const std::string& symbol, const RefPtr<CounterTheme>& counterTheme)
|
||||
int32_t id, const std::u16string& symbol, const RefPtr<CounterTheme>& counterTheme)
|
||||
{
|
||||
auto buttonNode =
|
||||
FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, id, []() { return AceType::MakeRefPtr<ButtonPattern>(); });
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
|
||||
private:
|
||||
RefPtr<FrameNode> CreateButtonChild(
|
||||
int32_t id, const std::string& symbol, const RefPtr<CounterTheme>& counterTheme);
|
||||
int32_t id, const std::u16string& symbol, const RefPtr<CounterTheme>& counterTheme);
|
||||
static RefPtr<FrameNode> CreateContentNodeChild(int32_t contentId, const RefPtr<CounterTheme>& counterTheme);
|
||||
};
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/base/inspector_filter.h"
|
||||
#include "core/components_ng/layout/layout_property.h"
|
||||
#include "core/components_ng/pattern/text/text_layout_property.h"
|
||||
@ -52,7 +53,8 @@ public:
|
||||
void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
|
||||
{
|
||||
LayoutProperty::ToJsonValue(json, filter);
|
||||
json->PutFixedAttr("content", propContent_.value_or("").c_str(), filter, FIXED_ATTR_CONTENT);
|
||||
json->PutFixedAttr("content", UtfUtils::Str16ToStr8(propContent_.value_or(u"")).c_str(), filter,
|
||||
FIXED_ATTR_CONTENT);
|
||||
/* no fixed attr below, just return */
|
||||
if (filter.IsFastFilter()) {
|
||||
return;
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/marquee/marquee_accessibility_property.h"
|
||||
|
||||
#include "core/components_ng/pattern/marquee/marquee_pattern.h"
|
||||
@ -25,7 +26,7 @@ std::string MarqueeAccessibilityProperty::GetText() const
|
||||
CHECK_NULL_RETURN(textChild, "");
|
||||
auto textLayoutProperty = textChild->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, "");
|
||||
return textLayoutProperty->GetContent().value_or("");
|
||||
return UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u""));
|
||||
}
|
||||
|
||||
std::string MarqueeAccessibilityProperty::GetGroupText(bool) const
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "base/geometry/dimension.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/base/frame_node.h"
|
||||
#include "core/components_ng/base/inspector_filter.h"
|
||||
#include "core/components_ng/layout/layout_property.h"
|
||||
@ -77,7 +78,8 @@ public:
|
||||
CHECK_NULL_VOID(textChild);
|
||||
auto textLayoutProperty = textChild->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(textLayoutProperty);
|
||||
json->PutFixedAttr("src", textLayoutProperty->GetContent().value_or("").c_str(), filter, FIXED_ATTR_SRC);
|
||||
json->PutFixedAttr("src", UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u"")).c_str(), filter,
|
||||
FIXED_ATTR_SRC);
|
||||
/* no fixed attr below, just return */
|
||||
if (filter.IsFastFilter()) {
|
||||
return;
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/marquee/marquee_pattern.h"
|
||||
|
||||
#include "core/components/marquee/marquee_theme.h"
|
||||
@ -562,8 +563,8 @@ void MarqueePattern::DumpInfo()
|
||||
CHECK_NULL_VOID(textChild);
|
||||
auto textLayoutProperty = textChild->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(textLayoutProperty);
|
||||
DumpLog::GetInstance().AddDesc(
|
||||
std::string("Marquee text content: ").append(textLayoutProperty->GetContent().value_or("")));
|
||||
DumpLog::GetInstance().AddDesc(std::string("Marquee text content: ").append(
|
||||
UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u""))));
|
||||
DumpLog::GetInstance().AddDesc(std::string("Play status: ").append(std::to_string(playStatus_)));
|
||||
DumpLog::GetInstance().AddDesc(std::string("loop: ").append(std::to_string(loop_)));
|
||||
DumpLog::GetInstance().AddDesc(std::string("step: ").append(std::to_string(scrollAmount_)));
|
||||
@ -622,7 +623,7 @@ void MarqueePattern::DumpInfo(std::unique_ptr<JsonValue>& json)
|
||||
CHECK_NULL_VOID(textChild);
|
||||
auto textLayoutProperty = textChild->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(textLayoutProperty);
|
||||
json->Put("Marquee text content", textLayoutProperty->GetContent().value_or("").c_str());
|
||||
json->Put("Marquee text content", UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u"")).c_str());
|
||||
json->Put("Play status", playStatus_);
|
||||
json->Put("loop", loop_);
|
||||
json->Put("step", scrollAmount_);
|
||||
|
@ -1988,7 +1988,7 @@ std::string MenuItemPattern::GetText()
|
||||
CHECK_NULL_RETURN(text_, std::string());
|
||||
auto textProps = text_->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textProps, std::string());
|
||||
return textProps->GetContentValue();
|
||||
return UtfUtils::Str16ToStr8(textProps->GetContentValue());
|
||||
}
|
||||
|
||||
std::string MenuItemPattern::InspectorGetFont()
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_accessibility_property.h"
|
||||
|
||||
#include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_pattern.h"
|
||||
@ -24,6 +25,6 @@ std::string MenuItemGroupAccessibilityProperty::GetText() const
|
||||
CHECK_NULL_RETURN(frameNode, "");
|
||||
auto menuItemGroupPattern = frameNode->GetPattern<MenuItemGroupPattern>();
|
||||
CHECK_NULL_RETURN(menuItemGroupPattern, "");
|
||||
return menuItemGroupPattern->GetHeaderContent();
|
||||
return UtfUtils::Str16ToStr8(menuItemGroupPattern->GetHeaderContent());
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -117,12 +117,12 @@ RefPtr<FrameNode> MenuItemGroupPattern::GetMenu()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string MenuItemGroupPattern::GetHeaderContent()
|
||||
std::u16string MenuItemGroupPattern::GetHeaderContent()
|
||||
{
|
||||
CHECK_NULL_RETURN(headerContent_, "");
|
||||
CHECK_NULL_RETURN(headerContent_, u"");
|
||||
auto content = headerContent_->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(content, "");
|
||||
return content->GetContentValue("");
|
||||
CHECK_NULL_RETURN(content, u"");
|
||||
return content->GetContentValue(u"");
|
||||
}
|
||||
|
||||
void MenuItemGroupPattern::UpdateMenuItemIconInfo()
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
|
||||
RefPtr<FrameNode> GetMenu();
|
||||
|
||||
std::string GetHeaderContent();
|
||||
std::u16string GetHeaderContent();
|
||||
|
||||
bool HasSelectIcon() const
|
||||
{
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/navigation/bar_item_pattern.h"
|
||||
#include "core/components_ng/pattern/text/text_pattern.h"
|
||||
|
||||
@ -204,6 +205,6 @@ void BarItemPattern::ToJsonValue(std::unique_ptr<JsonValue>& json, const Inspect
|
||||
CHECK_NULL_VOID(textNode);
|
||||
auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(textLayoutProperty);
|
||||
json->PutExtAttr("label", textLayoutProperty->GetContentValue("").c_str(), filter);
|
||||
json->PutExtAttr("label", (UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue(u""))).c_str(), filter);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "core/components_ng/pattern/navigation/navdestination_node_base.h"
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "base/json/json_util.h"
|
||||
#include "core/components_ng/pattern/navigation/bar_item_node.h"
|
||||
#include "core/components_ng/pattern/image/image_layout_property.h"
|
||||
@ -57,7 +58,7 @@ std::string NavDestinationNodeBase::GetBarItemsString(bool isMenu) const
|
||||
if (!textLayoutProperty) {
|
||||
jsonToolBarItem->Put("value", "");
|
||||
} else {
|
||||
jsonToolBarItem->Put("value", textLayoutProperty->GetContentValue("").c_str());
|
||||
jsonToolBarItem->Put("value", UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue(u"")).c_str());
|
||||
}
|
||||
} else {
|
||||
jsonToolBarItem->Put("value", "");
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "core/components_ng/pattern/navigation/navigation_title_util.h"
|
||||
|
||||
#include "base/i18n/localization.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/common/agingadapation/aging_adapation_dialog_theme.h"
|
||||
#include "core/common/agingadapation/aging_adapation_dialog_util.h"
|
||||
#include "core/common/container.h"
|
||||
@ -561,7 +562,7 @@ std::string NavigationTitleUtil::GetTitleString(const RefPtr<TitleBarNode>& titl
|
||||
}
|
||||
auto textLayoutProperty = title->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, "");
|
||||
return textLayoutProperty->GetContentValue("");
|
||||
return UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue(u""));
|
||||
}
|
||||
|
||||
std::string NavigationTitleUtil::GetSubtitleString(const RefPtr<TitleBarNode>& titleBarNode)
|
||||
@ -574,7 +575,7 @@ std::string NavigationTitleUtil::GetSubtitleString(const RefPtr<TitleBarNode>& t
|
||||
}
|
||||
auto textLayoutProperty = subtitle->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, "");
|
||||
return textLayoutProperty->GetContentValue("");
|
||||
return UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue(u""));
|
||||
}
|
||||
|
||||
float NavigationTitleUtil::ParseCalcDimensionToPx(const std::optional<CalcDimension>& value, const float titleBarWidth)
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/components_ng/pattern/navigation/title_bar_node.h"
|
||||
#include "core/components_ng/pattern/text/text_layout_property.h"
|
||||
@ -42,7 +43,7 @@ public:
|
||||
CHECK_NULL_RETURN(title, "");
|
||||
auto textLayoutProperty = title->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, "");
|
||||
return textLayoutProperty->GetContentValue("");
|
||||
return UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue(u""));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/navigation/title_bar_layout_algorithm.h"
|
||||
|
||||
#include "core/components_ng/base/frame_node.h"
|
||||
@ -728,7 +729,7 @@ void TitleBarLayoutAlgorithm::LayoutTitle(LayoutWrapper* layoutWrapper, const Re
|
||||
return;
|
||||
}
|
||||
MeasureContext context;
|
||||
context.textContent = textLayoutProperty->GetContentValue();
|
||||
context.textContent = UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue());
|
||||
context.fontSize = titleFontSize_;
|
||||
#ifdef ENABLE_ROSEN_BACKEND
|
||||
minTitleHeight_ = static_cast<float>(RosenRenderCustomPaint::MeasureTextSizeInner(context).Height());
|
||||
|
@ -490,9 +490,9 @@ void TitleBarPattern::ResetMainTitleProperty(const RefPtr<FrameNode>& textNode,
|
||||
auto titleLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(titleLayoutProperty);
|
||||
|
||||
std::string contentStr;
|
||||
std::u16string contentStr;
|
||||
if (titleLayoutProperty->HasContent()) {
|
||||
contentStr = titleLayoutProperty->GetContentValue(std::string());
|
||||
contentStr = titleLayoutProperty->GetContentValue(std::u16string());
|
||||
}
|
||||
titleLayoutProperty->Reset();
|
||||
titleLayoutProperty->UpdateContent(contentStr);
|
||||
@ -568,9 +568,9 @@ void TitleBarPattern::ResetSubTitleProperty(const RefPtr<FrameNode>& textNode,
|
||||
CHECK_NULL_VOID(textNode);
|
||||
auto titleLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(titleLayoutProperty);
|
||||
std::string contentStr;
|
||||
std::u16string contentStr;
|
||||
if (titleLayoutProperty->HasContent()) {
|
||||
contentStr = titleLayoutProperty->GetContentValue(std::string());
|
||||
contentStr = titleLayoutProperty->GetContentValue(std::u16string());
|
||||
}
|
||||
titleLayoutProperty->Reset();
|
||||
titleLayoutProperty->UpdateContent(contentStr);
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "core/components_ng/pattern/navigation/tool_bar_pattern.h"
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "base/i18n/localization.h"
|
||||
#include "core/common/agingadapation/aging_adapation_dialog_util.h"
|
||||
#include "core/components_ng/pattern/navigation/tool_bar_node.h"
|
||||
@ -182,7 +183,7 @@ void NavToolbarPattern::ShowDialogWithNode(const RefPtr<BarItemNode>& barItemNod
|
||||
CHECK_NULL_VOID(textLayoutProperty);
|
||||
auto textValue = textLayoutProperty->GetContent();
|
||||
if (!textValue.value().empty()) {
|
||||
message = textValue.value();
|
||||
message = UtfUtils::Str16ToStr8(textValue.value());
|
||||
}
|
||||
}
|
||||
if (imageNode != nullptr) {
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/option/option_pattern.h"
|
||||
|
||||
#include "core/components/common/layout/grid_system_manager.h"
|
||||
@ -497,7 +498,7 @@ std::string OptionPattern::GetText()
|
||||
CHECK_NULL_RETURN(text_, std::string());
|
||||
auto textProps = text_->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textProps, std::string());
|
||||
return textProps->GetContentValue();
|
||||
return UtfUtils::Str16ToStr8(textProps->GetContentValue());
|
||||
}
|
||||
|
||||
void OptionPattern::UpdateText(const std::string& content)
|
||||
|
@ -424,7 +424,7 @@ void DatePickerColumnPattern::FlushCurrentOptions(
|
||||
int32_t virtualIndex = static_cast<int32_t>(currentIndex) + diffIndex;
|
||||
bool virtualIndexValidate = virtualIndex >= 0 && virtualIndex < static_cast<int32_t>(totalOptionCount);
|
||||
if (NotLoopOptions() && !virtualIndexValidate) {
|
||||
textLayoutProperty->UpdateContent("");
|
||||
textLayoutProperty->UpdateContent(u"");
|
||||
textNode->MarkModifyDone();
|
||||
textNode->MarkDirtyNode();
|
||||
continue;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "base/geometry/dimension.h"
|
||||
#include "base/i18n/date_time_sequence.h"
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/components/theme/icon_theme.h"
|
||||
#include "core/components_ng/base/view_stack_processor.h"
|
||||
@ -251,7 +252,7 @@ RefPtr<FrameNode> DatePickerDialogView::CreateTitleButtonNode(const RefPtr<Frame
|
||||
CHECK_NULL_RETURN(textTitleNode, nullptr);
|
||||
auto textLayoutProperty = textTitleNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, nullptr);
|
||||
textLayoutProperty->UpdateContent("");
|
||||
textLayoutProperty->UpdateContent(u"");
|
||||
textLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT_MAIN_AXIS);
|
||||
textLayoutProperty->UpdateTextColor(pickerTheme->GetTitleStyle().GetTextColor());
|
||||
textLayoutProperty->UpdateFontSize(ConvertTitleFontScaleValue(pickerTheme->GetTitleStyle().GetFontSize()));
|
||||
@ -1958,7 +1959,8 @@ std::function<void(const GestureEvent&)> DatePickerDialogView::CreateNextPrevCli
|
||||
} else {
|
||||
SwitchDatePickerPage(dateNode);
|
||||
}
|
||||
if (textLayoutProperty->GetContent() == Localization::GetInstance()->GetEntryLetters("common.next")) {
|
||||
if (textLayoutProperty->GetContent() ==
|
||||
UtfUtils::Str8ToStr16(Localization::GetInstance()->GetEntryLetters("common.next"))) {
|
||||
if (!isShowTime_) {
|
||||
ShowContentRowButton(contentRow, false);
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ bool RichEditorLayoutAlgorithm::BuildParagraph(TextStyle& textStyle, const RefPt
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
auto maxSize = MultipleParagraphLayoutAlgorithm::GetMaxMeasureSize(contentConstraint);
|
||||
if (!CreateParagraph(textStyle, layoutProperty->GetContent().value_or(""), layoutWrapper, maxSize.Width())) {
|
||||
if (!CreateParagraph(textStyle, layoutProperty->GetContent().value_or(u""), layoutWrapper, maxSize.Width())) {
|
||||
return false;
|
||||
}
|
||||
CHECK_NULL_RETURN(paragraphManager_, false);
|
||||
@ -162,7 +162,7 @@ bool RichEditorLayoutAlgorithm::BuildParagraph(TextStyle& textStyle, const RefPt
|
||||
}
|
||||
|
||||
bool RichEditorLayoutAlgorithm::CreateParagraph(
|
||||
const TextStyle& textStyle, std::string content, LayoutWrapper* layoutWrapper, double maxWidth)
|
||||
const TextStyle& textStyle, std::u16string content, LayoutWrapper* layoutWrapper, double maxWidth)
|
||||
{
|
||||
CHECK_NULL_RETURN(!spans_.empty(), false);
|
||||
if (!paragraphManager_) {
|
||||
@ -260,7 +260,7 @@ OffsetF RichEditorLayoutAlgorithm::GetContentOffset(LayoutWrapper* layoutWrapper
|
||||
}
|
||||
|
||||
ParagraphStyle RichEditorLayoutAlgorithm::GetParagraphStyle(
|
||||
const TextStyle& textStyle, const std::string& content, LayoutWrapper* layoutWrapper) const
|
||||
const TextStyle& textStyle, const std::u16string& content, LayoutWrapper* layoutWrapper) const
|
||||
{
|
||||
auto style = MultipleParagraphLayoutAlgorithm::GetParagraphStyle(textStyle, content, layoutWrapper);
|
||||
style.fontSize = textStyle.GetFontSize().ConvertToPx();
|
||||
|
@ -51,12 +51,12 @@ protected:
|
||||
|
||||
private:
|
||||
OffsetF GetContentOffset(LayoutWrapper* layoutWrapper) override;
|
||||
bool CreateParagraph(
|
||||
const TextStyle& textStyle, std::string content, LayoutWrapper* layoutWrapper, double maxWidth = 0.0) override;
|
||||
bool CreateParagraph(const TextStyle& textStyle, std::u16string content, LayoutWrapper* layoutWrapper,
|
||||
double maxWidth = 0.0) override;
|
||||
bool BuildParagraph(TextStyle& textStyle, const RefPtr<TextLayoutProperty>& layoutProperty,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper);
|
||||
ParagraphStyle GetParagraphStyle(
|
||||
const TextStyle& textStyle, const std::string& content, LayoutWrapper* layoutWrapper) const override;
|
||||
const TextStyle& textStyle, const std::u16string& content, LayoutWrapper* layoutWrapper) const override;
|
||||
float GetShadowOffset(const std::list<RefPtr<SpanItem>>& group) override;
|
||||
void UpdateRichTextRect(const SizeF& textSize, LayoutWrapper* layoutWrapper);
|
||||
RefPtr<RichEditorPattern> GetRichEditorPattern(LayoutWrapper* layoutWrapper);
|
||||
|
@ -864,7 +864,7 @@ void SearchModelNG::CreateButton(const RefPtr<SearchNode>& parentNode, bool hasB
|
||||
buttonRenderContext->UpdateClipEdge(true);
|
||||
auto textFrameNode = AceType::DynamicCast<FrameNode>(frameNode->GetChildren().front());
|
||||
auto textLayoutProperty = textFrameNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
std::string defaultText = "Search";
|
||||
std::u16string defaultText = u"Search";
|
||||
textLayoutProperty->UpdateContent(defaultText);
|
||||
textLayoutProperty->UpdateTextColor(searchTheme->GetSearchButtonTextColor());
|
||||
textLayoutProperty->UpdateFontSize(searchTheme->GetFontSize());
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/security_component/security_component_accessibility_property.h"
|
||||
|
||||
#include "core/components_ng/pattern/security_component/security_component_log.h"
|
||||
@ -36,7 +37,7 @@ std::string SecurityComponentAccessibilityProperty::GetText() const
|
||||
if (textLayoutProperty == nullptr) {
|
||||
break;
|
||||
}
|
||||
value = textLayoutProperty->GetContentValue(value);
|
||||
value = UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue(std::u16string(u"")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ TextDirection SecurityComponentLayoutAlgorithm::GetTextDirection(LayoutWrapper*
|
||||
auto frameNode = layoutWrapper->GetHostNode();
|
||||
// default return LTR
|
||||
CHECK_NULL_RETURN(frameNode, TextDirection::LTR);
|
||||
std::string text = "";
|
||||
std::u16string text = u"";
|
||||
// get button string
|
||||
for (const auto& child : frameNode->GetChildren()) {
|
||||
auto node = AceType::DynamicCast<FrameNode, UINode>(child);
|
||||
@ -792,8 +792,7 @@ TextDirection SecurityComponentLayoutAlgorithm::GetTextDirection(LayoutWrapper*
|
||||
if (text.empty()) {
|
||||
return TextDirection::LTR;
|
||||
}
|
||||
auto wString = StringUtils::ToWstring(text);
|
||||
for (const auto& charInStr : wString) {
|
||||
for (const auto& charInStr : text) {
|
||||
auto direction = u_charDirection(charInStr);
|
||||
if (direction == UCharDirection::U_LEFT_TO_RIGHT) {
|
||||
return TextDirection::LTR;
|
||||
|
@ -12,6 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/security_component/security_component_layout_element.h"
|
||||
|
||||
#include "core/components_ng/pattern/security_component/security_component_layout_property.h"
|
||||
@ -181,7 +182,7 @@ void TextLayoutElement::ChooseExactFontSize(RefPtr<TextLayoutProperty>& property
|
||||
Dimension step = ADAPT_UNIT;
|
||||
Dimension fontSize = (property->GetFontSize().has_value()) ? property->GetFontSize().value() : defaultFontSize_;
|
||||
while (fontSize > minFontSize_) {
|
||||
auto tempSize = GetMeasureTextSize(property->GetContent().value_or(""),
|
||||
auto tempSize = GetMeasureTextSize(UtfUtils::Str16ToStr8(property->GetContent().value_or(u"")),
|
||||
fontSize,
|
||||
property->GetFontWeight().value_or(FontWeight::NORMAL), 0.0);
|
||||
if (!tempSize.has_value()) {
|
||||
@ -237,8 +238,8 @@ bool TextLayoutElement::GetCurrentTextSize(std::optional<SizeF>& currentTextSize
|
||||
if (!textProp->GetContent().has_value()) {
|
||||
return false;
|
||||
}
|
||||
currentTextSize = GetMeasureTextSize(textProp->GetContent().value(), textProp->GetFontSize().value(),
|
||||
textProp->GetFontWeight().value_or(FontWeight::NORMAL), width_);
|
||||
currentTextSize = GetMeasureTextSize(UtfUtils::Str16ToStr8(textProp->GetContent().value()),
|
||||
textProp->GetFontSize().value(), textProp->GetFontWeight().value_or(FontWeight::NORMAL), width_);
|
||||
if (!currentTextSize.has_value()) {
|
||||
return false;
|
||||
}
|
||||
@ -262,8 +263,8 @@ bool TextLayoutElement::TryShrinkTextWidth(SizeF& point, SizeF& circlePoint, boo
|
||||
}
|
||||
tempWidth -= stepPx;
|
||||
currentRectWidth -= stepPx;
|
||||
auto tempSize = GetMeasureTextSize(textProp->GetContent().value(), textProp->GetFontSize().value(),
|
||||
textProp->GetFontWeight().value_or(FontWeight::NORMAL), tempWidth);
|
||||
auto tempSize = GetMeasureTextSize(UtfUtils::Str16ToStr8(textProp->GetContent().value()),
|
||||
textProp->GetFontSize().value(), textProp->GetFontWeight().value_or(FontWeight::NORMAL), tempWidth);
|
||||
if (!tempSize.has_value()) {
|
||||
return false;
|
||||
}
|
||||
@ -304,7 +305,7 @@ void TextLayoutElement::MeasureMinTextSize()
|
||||
{
|
||||
auto textProp = AceType::DynamicCast<TextLayoutProperty>(textWrap_->GetLayoutProperty());
|
||||
CHECK_NULL_VOID(textProp);
|
||||
minTextSize_ = GetMeasureTextSize(textProp->GetContent().value_or(""),
|
||||
minTextSize_ = GetMeasureTextSize(UtfUtils::Str16ToStr8(textProp->GetContent().value_or(u"")),
|
||||
minFontSize_,
|
||||
textProp->GetFontWeight().value_or(FontWeight::NORMAL), 0.0);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ SizeF SelectLayoutAlgorithm::MeasureSelectText(
|
||||
auto textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(textWrapper->GetLayoutProperty());
|
||||
CHECK_NULL_RETURN(textLayoutProperty, SizeF());
|
||||
auto textLayoutConstraint = textLayoutProperty->CreateContentConstraint();
|
||||
auto contentValue = textLayoutProperty->GetContentValue("");
|
||||
auto contentValue = textLayoutProperty->GetContentValue(u"");
|
||||
|
||||
SizeF textSize;
|
||||
if (!contentValue.empty()) {
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "base/json/json_util.h"
|
||||
#include "base/utils/system_properties.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/animation/curves.h"
|
||||
#include "core/common/recorder/event_recorder.h"
|
||||
#include "core/common/recorder/node_data_cache.h"
|
||||
@ -1008,7 +1009,7 @@ void SelectPattern::ToJsonArrowAndText(std::unique_ptr<JsonValue>& json, const I
|
||||
|
||||
auto props = text_->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(props);
|
||||
json->PutExtAttr("value", props->GetContent().value_or("").c_str(), filter);
|
||||
json->PutExtAttr("value", UtfUtils::Str16ToStr8(props->GetContent().value_or(u"")).c_str(), filter);
|
||||
Color fontColor = props->GetTextColor().value_or(Color::BLACK);
|
||||
json->PutExtAttr("fontColor", fontColor.ColorToString().c_str(), filter);
|
||||
json->PutExtAttr("font", props->InspectorGetTextFont().c_str(), filter);
|
||||
@ -1166,7 +1167,7 @@ std::string SelectPattern::GetValue()
|
||||
CHECK_NULL_RETURN(text_, "");
|
||||
auto textProps = text_->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textProps, "");
|
||||
return textProps->GetContentValue("");
|
||||
return UtfUtils::Str16ToStr8(textProps->GetContentValue(u""));
|
||||
}
|
||||
|
||||
void SelectPattern::SetMenuAlign(const MenuAlign& menuAlign)
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "base/geometry/offset.h"
|
||||
#include "base/i18n/localization.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/common/container.h"
|
||||
#include "core/components/slider/slider_theme.h"
|
||||
#include "core/components/theme/app_theme.h"
|
||||
@ -371,7 +372,7 @@ void SliderPattern::UpdateStepPointsAccessibilityVirtualNodeSelected()
|
||||
|
||||
auto pointNodeProperty = pointNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(pointNodeProperty);
|
||||
auto valueTxt = pointNodeProperty->GetContent().value_or("");
|
||||
auto valueTxt = UtfUtils::Str16ToStr8(pointNodeProperty->GetContent().value_or(u""));
|
||||
if (currentStepIndex == i) {
|
||||
SetStepPointsAccessibilityVirtualNodeEvent(pointNode, i, false, reverse);
|
||||
pointAccessibilityProperty->SetAccessibilityText(selectedTxt + valueTxt);
|
||||
|
@ -1386,12 +1386,12 @@ void TabBarPattern::ShowDialogWithNode(int32_t index)
|
||||
CHECK_NULL_VOID(textLayoutProperty);
|
||||
auto textValue = textLayoutProperty->GetContent();
|
||||
if (imageNode->GetTag() == V2::SYMBOL_ETS_TAG) {
|
||||
dialogNode_ = AgingAdapationDialogUtil::ShowLongPressDialog(textValue.value_or(""), imageNode);
|
||||
dialogNode_ = AgingAdapationDialogUtil::ShowLongPressDialog(textValue.value_or(u""), imageNode);
|
||||
} else {
|
||||
auto imageProperty = imageNode->GetLayoutProperty<ImageLayoutProperty>();
|
||||
CHECK_NULL_VOID(imageProperty);
|
||||
ImageSourceInfo imageSourceInfo = imageProperty->GetImageSourceInfoValue();
|
||||
dialogNode_ = AgingAdapationDialogUtil::ShowLongPressDialog(textValue.value_or(""), imageSourceInfo);
|
||||
dialogNode_ = AgingAdapationDialogUtil::ShowLongPressDialog(textValue.value_or(u""), imageSourceInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.h"
|
||||
|
||||
#include "text_layout_adapter.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "base/geometry/dimension.h"
|
||||
#include "base/log/ace_performance_monitor.h"
|
||||
#include "base/i18n/localization.h"
|
||||
@ -366,7 +367,7 @@ void MultipleParagraphLayoutAlgorithm::SetAdaptFontSizeStepToTextStyle(
|
||||
}
|
||||
|
||||
ParagraphStyle MultipleParagraphLayoutAlgorithm::GetParagraphStyle(
|
||||
const TextStyle& textStyle, const std::string& content, LayoutWrapper* layoutWrapper) const
|
||||
const TextStyle& textStyle, const std::u16string& content, LayoutWrapper* layoutWrapper) const
|
||||
{
|
||||
return { .direction = GetTextDirection(content, layoutWrapper),
|
||||
.align = textStyle.GetTextAlign(),
|
||||
@ -380,26 +381,11 @@ ParagraphStyle MultipleParagraphLayoutAlgorithm::GetParagraphStyle(
|
||||
};
|
||||
}
|
||||
|
||||
TextDirection MultipleParagraphLayoutAlgorithm::GetTextDirection(
|
||||
const std::string& content, LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
auto textLayoutProperty = DynamicCast<TextLayoutProperty>(layoutWrapper->GetLayoutProperty());
|
||||
CHECK_NULL_RETURN(textLayoutProperty, TextDirection::LTR);
|
||||
|
||||
auto direction = textLayoutProperty->GetLayoutDirection();
|
||||
if (direction == TextDirection::LTR || direction == TextDirection::RTL) {
|
||||
return direction;
|
||||
}
|
||||
|
||||
return GetTextDirectionByContent(content);
|
||||
}
|
||||
|
||||
TextDirection MultipleParagraphLayoutAlgorithm::GetTextDirectionByContent(const std::string& content)
|
||||
TextDirection MultipleParagraphLayoutAlgorithm::GetTextDirectionByContent(const std::u16string& content)
|
||||
{
|
||||
bool isRTL = AceApplicationInfo::GetInstance().IsRightToLeft();
|
||||
auto textDirection = isRTL ? TextDirection::RTL : TextDirection::LTR;
|
||||
auto showingTextForWString = StringUtils::ToWstring(content);
|
||||
for (const auto& charOfShowingText : showingTextForWString) {
|
||||
for (const auto& charOfShowingText : content) {
|
||||
if (TextLayoutadapter::IsLeftToRight(charOfShowingText)) {
|
||||
return TextDirection::LTR;
|
||||
} else if (TextLayoutadapter::IsRightToLeft(charOfShowingText)) {
|
||||
@ -411,6 +397,11 @@ TextDirection MultipleParagraphLayoutAlgorithm::GetTextDirectionByContent(const
|
||||
return textDirection;
|
||||
}
|
||||
|
||||
TextDirection MultipleParagraphLayoutAlgorithm::GetTextDirectionByContent(const std::string& content)
|
||||
{
|
||||
return GetTextDirectionByContent(UtfUtils::Str8ToStr16(content));
|
||||
}
|
||||
|
||||
bool MultipleParagraphLayoutAlgorithm::ParagraphReLayout(const LayoutConstraintF& contentConstraint)
|
||||
{
|
||||
ACE_TEXT_SCOPED_TRACE("ParagraphReLayout");
|
||||
|
@ -54,9 +54,9 @@ public:
|
||||
protected:
|
||||
void GetSpanParagraphStyle(LayoutWrapper* layoutWrapper, const RefPtr<SpanItem>& spanItem, ParagraphStyle& pStyle);
|
||||
virtual ParagraphStyle GetParagraphStyle(
|
||||
const TextStyle& textStyle, const std::string& content, LayoutWrapper* layoutWrapper) const;
|
||||
const TextStyle& textStyle, const std::u16string& content, LayoutWrapper* layoutWrapper) const;
|
||||
virtual bool CreateParagraph(
|
||||
const TextStyle& textStyle, std::string content, LayoutWrapper* layoutWrapper, double maxWidth = 0.0) = 0;
|
||||
const TextStyle& textStyle, std::u16string content, LayoutWrapper* layoutWrapper, double maxWidth = 0.0) = 0;
|
||||
virtual void HandleEmptyParagraph(RefPtr<Paragraph> paragraph, const std::list<RefPtr<SpanItem>>& spanGroup) {}
|
||||
virtual RefPtr<SpanItem> GetParagraphStyleSpanItem(const std::list<RefPtr<SpanItem>>& spanGroup)
|
||||
{
|
||||
@ -112,7 +112,9 @@ private:
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
static TextDirection GetTextDirection(const std::string& content, LayoutWrapper* layoutWrapper);
|
||||
template<typename T>
|
||||
static TextDirection GetTextDirection(const T& content, LayoutWrapper* layoutWrapper);
|
||||
static TextDirection GetTextDirectionByContent(const std::u16string& content);
|
||||
static TextDirection GetTextDirectionByContent(const std::string& content);
|
||||
|
||||
void UpdateSymbolSpanEffect(
|
||||
@ -150,6 +152,20 @@ private:
|
||||
|
||||
ACE_DISALLOW_COPY_AND_MOVE(MultipleParagraphLayoutAlgorithm);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
TextDirection MultipleParagraphLayoutAlgorithm::GetTextDirection(const T& content, LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
auto textLayoutProperty = DynamicCast<TextLayoutProperty>(layoutWrapper->GetLayoutProperty());
|
||||
CHECK_NULL_RETURN(textLayoutProperty, TextDirection::LTR);
|
||||
|
||||
auto direction = textLayoutProperty->GetLayoutDirection();
|
||||
if (direction == TextDirection::LTR || direction == TextDirection::RTL) {
|
||||
return direction;
|
||||
}
|
||||
|
||||
return GetTextDirectionByContent(content);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_MULTIPLE_PARAGRAPH_LAYOUT_ALGORITHM_H
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/text/text_accessibility_property.h"
|
||||
|
||||
#include "core/components_ng/pattern/text/text_pattern.h"
|
||||
@ -27,7 +28,7 @@ std::string TextAccessibilityProperty::GetText() const
|
||||
if (children.empty()) {
|
||||
auto textLayoutProperty = frameNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, value);
|
||||
value = textLayoutProperty->GetContentValue(value);
|
||||
value = UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue(std::u16string(u"")));
|
||||
} else {
|
||||
auto textPattern = frameNode->GetPattern<TextPattern>();
|
||||
CHECK_NULL_RETURN(textPattern, value);
|
||||
|
@ -16,80 +16,6 @@
|
||||
#include "core/components_ng/pattern/text/text_adapt_font_sizer.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
bool TextAdaptFontSizer::AdaptMaxFontSize(TextStyle& textStyle, const std::string& content,
|
||||
const Dimension& stepUnit, const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
double maxFontSize = 0.0;
|
||||
double minFontSize = 0.0;
|
||||
GetAdaptMaxMinFontSize(textStyle, maxFontSize, minFontSize, contentConstraint);
|
||||
if (LessNotEqual(maxFontSize, minFontSize) || LessOrEqual(minFontSize, 0.0)) {
|
||||
// minFontSize or maxFontSize is invalid
|
||||
return CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper, false);
|
||||
}
|
||||
double stepSize = 0.0;
|
||||
GetAdaptFontSizeStep(textStyle, stepSize, stepUnit, contentConstraint);
|
||||
auto maxSize = GetMaxMeasureSize(contentConstraint);
|
||||
GetSuitableSize(maxSize, layoutWrapper);
|
||||
// Use the minFontSize to layout the paragraph. While using the minFontSize, if the paragraph could be layout in 1
|
||||
// line, then increase the font size and try to layout using the maximum available fontsize.
|
||||
textStyle.SetFontSize(Dimension(minFontSize));
|
||||
if (!CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper)) {
|
||||
return false;
|
||||
}
|
||||
if (IsAdaptExceedLimit(maxSize)) {
|
||||
return true;
|
||||
}
|
||||
auto tag = static_cast<int32_t>((maxFontSize - minFontSize) / stepSize);
|
||||
auto length = tag + 1 + (GreatNotEqual(maxFontSize, minFontSize + stepSize * tag) ? 1 : 0);
|
||||
int32_t left = 0;
|
||||
int32_t right = length - 1;
|
||||
float fontSize = 0.0f;
|
||||
while (left <= right) {
|
||||
int32_t mid = left + (right - left) / 2;
|
||||
fontSize = static_cast<float>((mid == length - 1) ? (maxFontSize) : (minFontSize + stepSize * mid));
|
||||
textStyle.SetFontSize(Dimension(fontSize));
|
||||
if (!CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper)) {
|
||||
return false;
|
||||
}
|
||||
if (!IsAdaptExceedLimit(maxSize)) {
|
||||
left = mid + 1;
|
||||
} else {
|
||||
right = mid - 1;
|
||||
}
|
||||
}
|
||||
fontSize = static_cast<float>((left - 1 == length - 1) ? (maxFontSize) : (minFontSize + stepSize * (left - 1)));
|
||||
fontSize = LessNotEqual(fontSize, minFontSize) ? minFontSize : fontSize;
|
||||
fontSize = GreatNotEqual(fontSize, maxFontSize) ? maxFontSize : fontSize;
|
||||
textStyle.SetFontSize(Dimension(fontSize));
|
||||
return CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper);
|
||||
}
|
||||
|
||||
bool TextAdaptFontSizer::AdaptMinFontSize(TextStyle& textStyle, const std::string& content,
|
||||
const Dimension& stepUnit, const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
double maxFontSize = 0.0;
|
||||
double minFontSize = 0.0;
|
||||
GetAdaptMaxMinFontSize(textStyle, maxFontSize, minFontSize, contentConstraint);
|
||||
if (LessNotEqual(maxFontSize, minFontSize) || LessOrEqual(minFontSize, 0.0)) {
|
||||
return CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper, false);
|
||||
}
|
||||
double stepSize = 0.0;
|
||||
GetAdaptFontSizeStep(textStyle, stepSize, stepUnit, contentConstraint);
|
||||
auto maxSize = GetMaxMeasureSize(contentConstraint);
|
||||
GetSuitableSize(maxSize, layoutWrapper);
|
||||
while (GreatOrEqual(maxFontSize, minFontSize)) {
|
||||
textStyle.SetFontSize(Dimension(maxFontSize));
|
||||
if (!CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper)) {
|
||||
return false;
|
||||
}
|
||||
if (!DidExceedMaxLines(maxSize)) {
|
||||
break;
|
||||
}
|
||||
maxFontSize -= stepSize;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextAdaptFontSizer::GetAdaptMaxMinFontSize(const TextStyle& textStyle, double& maxFontSize, double& minFontSize,
|
||||
const LayoutConstraintF& contentConstraint)
|
||||
{
|
||||
|
@ -30,14 +30,23 @@ class PipelineContext;
|
||||
class TextAdaptFontSizer : public virtual AceType {
|
||||
DECLARE_ACE_TYPE(TextAdaptFontSizer, AceType);
|
||||
public:
|
||||
virtual bool CreateParagraphAndLayout(const TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, bool needLayout = true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool CreateParagraphAndLayout(const TextStyle& textStyle, const std::string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, bool needLayout = true) = 0;
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, bool needLayout = true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual RefPtr<Paragraph> GetParagraph() const = 0;
|
||||
virtual void GetSuitableSize(SizeF& maxSize, LayoutWrapper* layoutWrapper) = 0;
|
||||
|
||||
bool AdaptMaxFontSize(TextStyle& textStyle, const std::string& content, const Dimension& stepUnit,
|
||||
template<typename T>
|
||||
bool AdaptMaxFontSize(TextStyle& textStyle, T& content, const Dimension& stepUnit,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper);
|
||||
bool AdaptMinFontSize(TextStyle& textStyle, const std::string& content, const Dimension& stepUnit,
|
||||
template<typename T>
|
||||
bool AdaptMinFontSize(TextStyle& textStyle, T& content, const Dimension& stepUnit,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper);
|
||||
virtual bool AdaptInlineFocusFontSize(TextStyle& textStyle, const std::string& content, const Dimension& stepUnit,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper)
|
||||
@ -62,6 +71,82 @@ private:
|
||||
virtual bool IsAdaptExceedLimit(const SizeF& maxSize);
|
||||
double lineHeight_ = 0.0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
bool TextAdaptFontSizer::AdaptMaxFontSize(TextStyle& textStyle, T& content,
|
||||
const Dimension& stepUnit, const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
double maxFontSize = 0.0;
|
||||
double minFontSize = 0.0;
|
||||
GetAdaptMaxMinFontSize(textStyle, maxFontSize, minFontSize, contentConstraint);
|
||||
if (LessNotEqual(maxFontSize, minFontSize) || LessOrEqual(minFontSize, 0.0)) {
|
||||
// minFontSize or maxFontSize is invalid
|
||||
return CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper, false);
|
||||
}
|
||||
double stepSize = 0.0;
|
||||
GetAdaptFontSizeStep(textStyle, stepSize, stepUnit, contentConstraint);
|
||||
auto maxSize = GetMaxMeasureSize(contentConstraint);
|
||||
GetSuitableSize(maxSize, layoutWrapper);
|
||||
// Use the minFontSize to layout the paragraph. While using the minFontSize, if the paragraph could be layout in 1
|
||||
// line, then increase the font size and try to layout using the maximum available fontsize.
|
||||
textStyle.SetFontSize(Dimension(minFontSize));
|
||||
if (!CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper)) {
|
||||
return false;
|
||||
}
|
||||
if (IsAdaptExceedLimit(maxSize)) {
|
||||
return true;
|
||||
}
|
||||
auto tag = static_cast<int32_t>((maxFontSize - minFontSize) / stepSize);
|
||||
auto length = tag + 1 + (GreatNotEqual(maxFontSize, minFontSize + stepSize * tag) ? 1 : 0);
|
||||
int32_t left = 0;
|
||||
int32_t right = length - 1;
|
||||
float fontSize = 0.0f;
|
||||
while (left <= right) {
|
||||
int32_t mid = left + (right - left) / 2;
|
||||
fontSize = static_cast<float>((mid == length - 1) ? (maxFontSize) : (minFontSize + stepSize * mid));
|
||||
textStyle.SetFontSize(Dimension(fontSize));
|
||||
if (!CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper)) {
|
||||
return false;
|
||||
}
|
||||
if (!IsAdaptExceedLimit(maxSize)) {
|
||||
left = mid + 1;
|
||||
} else {
|
||||
right = mid - 1;
|
||||
}
|
||||
}
|
||||
fontSize = static_cast<float>((left - 1 == length - 1) ? (maxFontSize) : (minFontSize + stepSize * (left - 1)));
|
||||
fontSize = LessNotEqual(fontSize, minFontSize) ? minFontSize : fontSize;
|
||||
fontSize = GreatNotEqual(fontSize, maxFontSize) ? maxFontSize : fontSize;
|
||||
textStyle.SetFontSize(Dimension(fontSize));
|
||||
return CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool TextAdaptFontSizer::AdaptMinFontSize(TextStyle& textStyle, T& content,
|
||||
const Dimension& stepUnit, const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
double maxFontSize = 0.0;
|
||||
double minFontSize = 0.0;
|
||||
GetAdaptMaxMinFontSize(textStyle, maxFontSize, minFontSize, contentConstraint);
|
||||
if (LessNotEqual(maxFontSize, minFontSize) || LessOrEqual(minFontSize, 0.0)) {
|
||||
return CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper, false);
|
||||
}
|
||||
double stepSize = 0.0;
|
||||
GetAdaptFontSizeStep(textStyle, stepSize, stepUnit, contentConstraint);
|
||||
auto maxSize = GetMaxMeasureSize(contentConstraint);
|
||||
GetSuitableSize(maxSize, layoutWrapper);
|
||||
while (GreatOrEqual(maxFontSize, minFontSize)) {
|
||||
textStyle.SetFontSize(Dimension(maxFontSize));
|
||||
if (!CreateParagraphAndLayout(textStyle, content, contentConstraint, layoutWrapper)) {
|
||||
return false;
|
||||
}
|
||||
if (!DidExceedMaxLines(maxSize)) {
|
||||
break;
|
||||
}
|
||||
maxFontSize -= stepSize;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_TEXT_ADAPT_FONT_SIZER_H
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "core/components/common/properties/alignment.h"
|
||||
#include "core/components/hyperlink/hyperlink_theme.h"
|
||||
#include "core/components_ng/pattern/text/text_pattern.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
@ -144,7 +145,7 @@ std::optional<SizeF> TextLayoutAlgorithm::MeasureContent(
|
||||
} else {
|
||||
heightFinal = std::min(heightFinal, contentConstraint.maxSize.Height());
|
||||
}
|
||||
if (host->GetTag() == V2::TEXT_ETS_TAG && textLayoutProperty->GetContent().value_or("").empty() &&
|
||||
if (host->GetTag() == V2::TEXT_ETS_TAG && textLayoutProperty->GetContent().value_or(u"").empty() &&
|
||||
NonPositive(longestLine)) {
|
||||
ACE_SCOPED_TRACE("TextHeightFinal [%f], TextContentWidth [%f], FontSize [%lf]", heightFinal, maxWidth,
|
||||
textStyle.GetFontSize().ConvertToPxDistribute(
|
||||
@ -263,7 +264,7 @@ std::string TextLayoutAlgorithm::StringOutBoundProtection(int32_t position, int3
|
||||
}
|
||||
|
||||
bool TextLayoutAlgorithm::CreateParagraph(
|
||||
const TextStyle& textStyle, std::string content, LayoutWrapper* layoutWrapper, double maxWidth)
|
||||
const TextStyle& textStyle, std::u16string content, LayoutWrapper* layoutWrapper, double maxWidth)
|
||||
{
|
||||
if (!paragraphManager_) {
|
||||
paragraphManager_ = AceType::MakeRefPtr<ParagraphManager>();
|
||||
@ -360,7 +361,7 @@ void TextLayoutAlgorithm::CreateParagraphDrag(
|
||||
}
|
||||
}
|
||||
|
||||
bool TextLayoutAlgorithm::CreateParagraphAndLayout(const TextStyle& textStyle, const std::string& content,
|
||||
bool TextLayoutAlgorithm::CreateParagraphAndLayout(const TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, bool needLayout)
|
||||
{
|
||||
auto maxSize = MultipleParagraphLayoutAlgorithm::GetMaxMeasureSize(contentConstraint);
|
||||
@ -384,7 +385,7 @@ OffsetF TextLayoutAlgorithm::GetContentOffset(LayoutWrapper* layoutWrapper)
|
||||
return SetContentOffset(layoutWrapper);
|
||||
}
|
||||
|
||||
bool TextLayoutAlgorithm::AdaptMinTextSize(TextStyle& textStyle, const std::string& content,
|
||||
bool TextLayoutAlgorithm::AdaptMinTextSize(TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
ACE_TEXT_SCOPED_TRACE("TextLayoutAlgorithm::AdaptMinTextSize[Length:%d]", static_cast<int32_t>(content.length()));
|
||||
@ -421,7 +422,7 @@ bool TextLayoutAlgorithm::AdaptMinTextSize(TextStyle& textStyle, const std::stri
|
||||
* - first: A boolean indicating whether a suitable size was found (true if found, false otherwise).
|
||||
* - second: The optimal font size if found, valid only when first is true.
|
||||
*/
|
||||
std::pair<bool, double> TextLayoutAlgorithm::GetSuitableSize(TextStyle& textStyle, const std::string& content,
|
||||
std::pair<bool, double> TextLayoutAlgorithm::GetSuitableSize(TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
double maxFontSize = 0.0;
|
||||
@ -447,7 +448,7 @@ std::pair<bool, double> TextLayoutAlgorithm::GetSuitableSize(TextStyle& textStyl
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<bool, double> TextLayoutAlgorithm::GetSuitableSizeLD(TextStyle& textStyle, const std::string& content,
|
||||
std::pair<bool, double> TextLayoutAlgorithm::GetSuitableSizeLD(TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, double stepSize)
|
||||
{
|
||||
double maxFontSize = 0.0;
|
||||
@ -482,7 +483,7 @@ std::pair<bool, double> TextLayoutAlgorithm::GetSuitableSizeLD(TextStyle& textSt
|
||||
return {false, 0.0};
|
||||
}
|
||||
|
||||
std::pair<bool, double> TextLayoutAlgorithm::GetSuitableSizeBS(TextStyle& textStyle, const std::string& content,
|
||||
std::pair<bool, double> TextLayoutAlgorithm::GetSuitableSizeBS(TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, double stepSize)
|
||||
{
|
||||
double maxFontSize = 0.0;
|
||||
@ -540,7 +541,7 @@ float TextLayoutAlgorithm::GetBaselineOffset() const
|
||||
}
|
||||
|
||||
bool TextLayoutAlgorithm::UpdateSingleParagraph(LayoutWrapper* layoutWrapper, ParagraphStyle paraStyle,
|
||||
const TextStyle& textStyle, const std::string& content, double maxWidth)
|
||||
const TextStyle& textStyle, const std::u16string& content, double maxWidth)
|
||||
{
|
||||
auto host = layoutWrapper->GetHostNode();
|
||||
CHECK_NULL_RETURN(host, false);
|
||||
@ -568,8 +569,8 @@ bool TextLayoutAlgorithm::UpdateSingleParagraph(LayoutWrapper* layoutWrapper, Pa
|
||||
} else {
|
||||
auto value = content;
|
||||
StringUtils::TransformStrCase(value, static_cast<int32_t>(textStyle.GetTextCase()));
|
||||
std::u16string result = TextBase::ConvertStr8toStr16(value);
|
||||
paragraph->AddText(result);
|
||||
UtfUtils::HandleInvalidUTF16(reinterpret_cast<uint16_t*>(value.data()), value.length(), 0);
|
||||
paragraph->AddText(value);
|
||||
}
|
||||
}
|
||||
paragraph->Build();
|
||||
@ -577,7 +578,7 @@ bool TextLayoutAlgorithm::UpdateSingleParagraph(LayoutWrapper* layoutWrapper, Pa
|
||||
paragraphManager_->AddParagraph({ .paragraph = paragraph,
|
||||
.paragraphStyle = paraStyle,
|
||||
.start = 0,
|
||||
.end = TextBase::ConvertStr8toStr16(content).length() });
|
||||
.end = content.length() });
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -590,14 +591,15 @@ bool TextLayoutAlgorithm::BuildParagraph(TextStyle& textStyle, const RefPtr<Text
|
||||
CHECK_NULL_RETURN(pattern, false);
|
||||
pattern->DumpRecord("TextLayout BuildParagraph id:" + std::to_string(host->GetId()));
|
||||
if (!textStyle.GetAdaptTextSize() || !spans_.empty()) {
|
||||
if (!CreateParagraphAndLayout(
|
||||
textStyle, layoutProperty->GetContent().value_or(""), contentConstraint, layoutWrapper)) {
|
||||
if (!CreateParagraphAndLayout(textStyle, layoutProperty->GetContent().value_or(u""), contentConstraint,
|
||||
layoutWrapper)) {
|
||||
TAG_LOGW(AceLogTag::ACE_TEXT, "BuildParagraph fail, contentConstraint:%{public}s",
|
||||
contentConstraint.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!AdaptMinTextSize(textStyle, layoutProperty->GetContent().value_or(""), contentConstraint, layoutWrapper)) {
|
||||
if (!AdaptMinTextSize(textStyle, layoutProperty->GetContent().value_or(u""), contentConstraint,
|
||||
layoutWrapper)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -608,7 +610,7 @@ bool TextLayoutAlgorithm::BuildParagraphAdaptUseMinFontSize(TextStyle& textStyle
|
||||
const RefPtr<TextLayoutProperty>& layoutProperty, const LayoutConstraintF& contentConstraint,
|
||||
LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
if (!AdaptMaxTextSize(textStyle, layoutProperty->GetContent().value_or(""), contentConstraint, layoutWrapper)) {
|
||||
if (!AdaptMaxTextSize(textStyle, layoutProperty->GetContent().value_or(u""), contentConstraint, layoutWrapper)) {
|
||||
return false;
|
||||
}
|
||||
auto paragraph = GetSingleParagraph();
|
||||
@ -680,8 +682,8 @@ std::optional<SizeF> TextLayoutAlgorithm::BuildTextRaceParagraph(TextStyle& text
|
||||
textStyle.SetTextOverflow(TextOverflow::CLIP);
|
||||
textStyle.SetMaxLines(1);
|
||||
textStyle.SetTextIndent(Dimension(0.0f));
|
||||
std::string content = layoutProperty->GetContent().value_or("");
|
||||
std::replace(content.begin(), content.end(), '\n', ' ');
|
||||
std::u16string content = layoutProperty->GetContent().value_or(u"");
|
||||
std::replace(content.begin(), content.end(), u'\n', u' ');
|
||||
if (!textStyle.GetAdaptTextSize()) {
|
||||
if (!CreateParagraph(textStyle, content, layoutWrapper)) {
|
||||
return std::nullopt;
|
||||
@ -725,7 +727,7 @@ std::optional<SizeF> TextLayoutAlgorithm::BuildTextRaceParagraph(TextStyle& text
|
||||
return SizeF(widthFinal, heightFinal);
|
||||
}
|
||||
|
||||
bool TextLayoutAlgorithm::AdaptMaxTextSize(TextStyle& textStyle, const std::string& content,
|
||||
bool TextLayoutAlgorithm::AdaptMaxTextSize(TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
constexpr Dimension ADAPT_UNIT = 1.0_fp;
|
||||
@ -735,15 +737,13 @@ bool TextLayoutAlgorithm::AdaptMaxTextSize(TextStyle& textStyle, const std::stri
|
||||
return AdaptMaxFontSize(textStyle, content, step, contentConstraint, layoutWrapper);
|
||||
}
|
||||
|
||||
void TextLayoutAlgorithm::UpdateSensitiveContent(std::string& content)
|
||||
void TextLayoutAlgorithm::UpdateSensitiveContent(std::u16string& content)
|
||||
{
|
||||
auto wContent = StringUtils::ToWstring(content);
|
||||
std::replace_if(
|
||||
wContent.begin(), wContent.end(),
|
||||
[](wchar_t ch) {
|
||||
return ch != L'\n';
|
||||
}, L'-');
|
||||
content = StringUtils::ToString(wContent);
|
||||
content.begin(), content.end(),
|
||||
[](char16_t ch) {
|
||||
return ch != u'\n';
|
||||
}, u'-');
|
||||
}
|
||||
|
||||
std::optional<TextStyle> TextLayoutAlgorithm::GetTextStyle() const
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) override;
|
||||
|
||||
void GetSuitableSize(SizeF& maxSize, LayoutWrapper* layoutWrapper) override {};
|
||||
bool CreateParagraphAndLayout(const TextStyle& textStyle, const std::string& content,
|
||||
bool CreateParagraphAndLayout(const TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, bool needLayout = true) override;
|
||||
|
||||
float GetBaselineOffset() const override;
|
||||
@ -92,18 +92,18 @@ protected:
|
||||
private:
|
||||
OffsetF GetContentOffset(LayoutWrapper* layoutWrapper) override;
|
||||
bool UpdateSingleParagraph(LayoutWrapper* layoutWrapper, ParagraphStyle paraStyle, const TextStyle& textStyle,
|
||||
const std::string& content, double maxWidth);
|
||||
const std::u16string& content, double maxWidth);
|
||||
bool UpdateSymbolTextStyle(const TextStyle& textStyle, const ParagraphStyle& paraStyle,
|
||||
LayoutWrapper* layoutWrapper, RefPtr<FrameNode>& frameNode);
|
||||
void CreateParagraphDrag(
|
||||
const TextStyle& textStyle, const std::vector<std::string>& contents, const RefPtr<Paragraph>& paragraph);
|
||||
void ConstructParagraphSpanGroup(std::list<RefPtr<SpanItem>>& spans);
|
||||
bool AdaptMinTextSize(TextStyle& textStyle, const std::string& content, const LayoutConstraintF& contentConstraint,
|
||||
LayoutWrapper* layoutWrapper);
|
||||
bool AdaptMinTextSize(TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper);
|
||||
bool AddPropertiesAndAnimations(TextStyle& textStyle, const RefPtr<TextLayoutProperty>& textLayoutProperty,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper);
|
||||
bool CreateParagraph(
|
||||
const TextStyle& textStyle, std::string content, LayoutWrapper* layoutWrapper, double maxWidth = 0.0) override;
|
||||
bool CreateParagraph(const TextStyle& textStyle, std::u16string content, LayoutWrapper* layoutWrapper,
|
||||
double maxWidth = 0.0) override;
|
||||
bool BuildParagraph(TextStyle& textStyle, const RefPtr<TextLayoutProperty>& layoutProperty,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper);
|
||||
bool BuildParagraphAdaptUseMinFontSize(TextStyle& textStyle, const RefPtr<TextLayoutProperty>& layoutProperty,
|
||||
@ -112,14 +112,14 @@ private:
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper);
|
||||
std::optional<SizeF> BuildTextRaceParagraph(TextStyle& textStyle, const RefPtr<TextLayoutProperty>& layoutProperty,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper);
|
||||
bool AdaptMaxTextSize(TextStyle& textStyle, const std::string& content, const LayoutConstraintF& contentConstraint,
|
||||
LayoutWrapper* layoutWrapper);
|
||||
void UpdateSensitiveContent(std::string& content);
|
||||
std::pair<bool, double> GetSuitableSize(TextStyle& textStyle, const std::string& content,
|
||||
bool AdaptMaxTextSize(TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper);
|
||||
std::pair<bool, double> GetSuitableSizeLD(TextStyle& textStyle, const std::string& content,
|
||||
void UpdateSensitiveContent(std::u16string& content);
|
||||
std::pair<bool, double> GetSuitableSize(TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper);
|
||||
std::pair<bool, double> GetSuitableSizeLD(TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, double stepSize);
|
||||
std::pair<bool, double> GetSuitableSizeBS(TextStyle& textStyle, const std::string& content,
|
||||
std::pair<bool, double> GetSuitableSizeBS(TextStyle& textStyle, const std::u16string& content,
|
||||
const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper, double stepSize);
|
||||
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/text/text_layout_property.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
@ -72,7 +73,8 @@ std::string TextLayoutProperty::GetCopyOptionString() const
|
||||
void TextLayoutProperty::ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const
|
||||
{
|
||||
LayoutProperty::ToJsonValue(json, filter);
|
||||
json->PutFixedAttr("content", GetContent().value_or("").c_str(), filter, FIXED_ATTR_CONTENT);
|
||||
json->PutFixedAttr("content", UtfUtils::Str16ToStr8(GetContent().value_or(u"")).c_str(), filter,
|
||||
FIXED_ATTR_CONTENT);
|
||||
/* no fixed attr below, just return */
|
||||
if (filter.IsFastFilter()) {
|
||||
return;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components/common/layout/constants.h"
|
||||
#include "core/components/common/properties/color.h"
|
||||
#include "core/components_ng/layout/layout_property.h"
|
||||
@ -99,7 +100,12 @@ public:
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, LineBreakStrategy, LineBreakStrategy, PROPERTY_UPDATE_MEASURE);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, HalfLeading, bool, PROPERTY_UPDATE_MEASURE_SELF);
|
||||
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Content, std::string, PROPERTY_UPDATE_MEASURE);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Content, std::u16string, PROPERTY_UPDATE_MEASURE);
|
||||
public:
|
||||
void UpdateContent(const std::string& value)
|
||||
{
|
||||
UpdateContent(UtfUtils::Str8ToStr16(value));
|
||||
}
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CopyOption, CopyOptions, PROPERTY_UPDATE_MEASURE);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(AdaptFontSizeStep, Dimension, PROPERTY_UPDATE_MEASURE_SELF);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CursorColor, Color, PROPERTY_UPDATE_MEASURE_SELF);
|
||||
|
@ -87,7 +87,8 @@ public:
|
||||
static TextModel* GetInstance();
|
||||
virtual ~TextModel() = default;
|
||||
|
||||
virtual void Create(const std::string& content) = 0;
|
||||
virtual void Create(const std::u16string& content) {};
|
||||
virtual void Create(const std::string& content) {};
|
||||
virtual void Create(const RefPtr<SpanStringBase>& spanString) = 0;
|
||||
virtual void SetFont(const Font& value) = 0;
|
||||
virtual void SetFontSize(const Dimension& value) = 0;
|
||||
|
@ -31,7 +31,7 @@ namespace OHOS::Ace::NG {
|
||||
constexpr int32_t DEFAULT_ALPHA = 255;
|
||||
constexpr float DEFAULT_OPACITY = 0.2;
|
||||
|
||||
void TextModelNG::Create(const std::string& content)
|
||||
void TextModelNG::Create(const std::u16string& content)
|
||||
{
|
||||
auto* stack = ViewStackProcessor::GetInstance();
|
||||
auto nodeId = stack->ClaimNodeId();
|
||||
@ -60,7 +60,7 @@ void TextModelNG::Create(const std::string& content)
|
||||
|
||||
void TextModelNG::Create(const RefPtr<SpanStringBase>& spanBase)
|
||||
{
|
||||
TextModelNG::Create("");
|
||||
TextModelNG::Create(u"");
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
auto textPattern = frameNode->GetPattern<TextPattern>();
|
||||
@ -73,7 +73,7 @@ void TextModelNG::Create(const RefPtr<SpanStringBase>& spanBase)
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> TextModelNG::CreateFrameNode(int32_t nodeId, const std::string& content)
|
||||
RefPtr<FrameNode> TextModelNG::CreateFrameNode(int32_t nodeId, const std::u16string& content)
|
||||
{
|
||||
auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, nodeId, AceType::MakeRefPtr<TextPattern>());
|
||||
CHECK_NULL_RETURN(frameNode, nullptr);
|
||||
@ -464,7 +464,7 @@ void TextModelNG::SetOnDrop(NG::OnDragDropFunc&& onDrop)
|
||||
ViewAbstract::SetOnDrop(std::move(onDrop));
|
||||
}
|
||||
|
||||
void TextModelNG::InitText(FrameNode* frameNode, std::string& value)
|
||||
void TextModelNG::InitText(FrameNode* frameNode, std::u16string& value)
|
||||
{
|
||||
ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextLayoutProperty, Content, value, frameNode);
|
||||
}
|
||||
@ -643,12 +643,12 @@ void TextModelNG::SetFontFeature(FrameNode* frameNode, const FONT_FEATURES_LIST&
|
||||
ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextLayoutProperty, FontFeature, value, frameNode);
|
||||
}
|
||||
|
||||
std::string TextModelNG::GetContent(FrameNode* frameNode)
|
||||
std::u16string TextModelNG::GetContent(FrameNode* frameNode)
|
||||
{
|
||||
CHECK_NULL_RETURN(frameNode, "");
|
||||
CHECK_NULL_RETURN(frameNode, u"");
|
||||
auto layoutProperty = frameNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(layoutProperty, "");
|
||||
return layoutProperty->GetContent().value_or("");
|
||||
CHECK_NULL_RETURN(layoutProperty, u"");
|
||||
return layoutProperty->GetContent().value_or(u"");
|
||||
}
|
||||
|
||||
float TextModelNG::GetLineHeight(FrameNode* frameNode)
|
||||
|
@ -28,7 +28,7 @@ namespace OHOS::Ace::NG {
|
||||
|
||||
class ACE_EXPORT TextModelNG : public TextModel {
|
||||
public:
|
||||
void Create(const std::string& content) override;
|
||||
void Create(const std::u16string& content) override;
|
||||
void Create(const RefPtr<SpanStringBase>& spanString) override;
|
||||
void SetFont(const Font& value) override;
|
||||
void SetFontSize(const Dimension& value) override;
|
||||
@ -87,8 +87,8 @@ public:
|
||||
void SetHalfLeading(bool halfLeading) override;
|
||||
void SetEnableHapticFeedback(bool state) override;
|
||||
|
||||
static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId, const std::string& content);
|
||||
static void InitText(FrameNode* frameNode, std::string& value);
|
||||
static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId, const std::u16string& content);
|
||||
static void InitText(FrameNode* frameNode, std::u16string& value);
|
||||
static void InitSpanStringController(FrameNode* frameNode, const RefPtr<SpanStringBase>& spanBase);
|
||||
static RefPtr<TextControllerBase> InitTextController(FrameNode* frameNode);
|
||||
static void SetFontWeight(FrameNode* frameNode, Ace::FontWeight value);
|
||||
@ -138,7 +138,7 @@ public:
|
||||
static Dimension GetAdaptMinFontSize(FrameNode* frameNode);
|
||||
static Dimension GetAdaptMaxFontSize(FrameNode* frameNode);
|
||||
static Font GetFont(FrameNode* frameNode);
|
||||
static std::string GetContent(FrameNode* frameNode);
|
||||
static std::u16string GetContent(FrameNode* frameNode);
|
||||
static float GetLineHeight(FrameNode* frameNode);
|
||||
static float GetLineSpacing(FrameNode* frameNode);
|
||||
static TextDecoration GetDecoration(FrameNode* frameNode);
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "base/geometry/offset.h"
|
||||
#include "base/log/dump_log.h"
|
||||
#include "base/log/log_wrapper.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "base/utils/string_utils.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "base/window/drag_window.h"
|
||||
@ -2627,7 +2628,7 @@ void TextPattern::OnModifyDone()
|
||||
|
||||
std::string textCache = textForDisplay_;
|
||||
if (!isSpanStringMode_) {
|
||||
textForDisplay_ = textLayoutProperty->GetContent().value_or("");
|
||||
textForDisplay_ = UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u""));
|
||||
}
|
||||
if (textCache != textForDisplay_) {
|
||||
host->OnAccessibilityEvent(AccessibilityEventType::TEXT_CHANGE, textCache, textForDisplay_);
|
||||
@ -3134,7 +3135,7 @@ void TextPattern::InitSpanItem(std::stack<SpanNodeInfo> nodes)
|
||||
auto textLayoutProperty = GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(textLayoutProperty);
|
||||
if (childNodes_.empty()) {
|
||||
textForDisplay_ = textLayoutProperty->GetContent().value_or("");
|
||||
textForDisplay_ = UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u""));
|
||||
}
|
||||
if (oldPlaceholderCount != placeholderCount_) {
|
||||
CloseSelectOverlay();
|
||||
@ -3160,7 +3161,7 @@ void TextPattern::InitSpanItem(std::stack<SpanNodeInfo> nodes)
|
||||
dataDetectorAdapter_->aiDetectInitialized_ = false;
|
||||
}
|
||||
if (CanStartAITask() && !dataDetectorAdapter_->aiDetectInitialized_) {
|
||||
ParseOriText(textLayoutProperty->GetContent().value_or(""));
|
||||
ParseOriText(UtfUtils::Str16ToStr8(textLayoutProperty->GetContent().value_or(u"")));
|
||||
if (!dataDetectorAdapter_->aiDetectInitialized_) {
|
||||
dataDetectorAdapter_->StartAITask();
|
||||
}
|
||||
@ -3478,7 +3479,8 @@ void TextPattern::DumpInfo()
|
||||
dumpLog.AddDesc(std::string("frameRecord: ").append(frameRecord_));
|
||||
dumpLog.AddDesc(std::string("time: ").append(std::to_string(nowTime)));
|
||||
if (!IsSetObscured()) {
|
||||
dumpLog.AddDesc(std::string("Content: ").append(textLayoutProp->GetContent().value_or(" ")));
|
||||
dumpLog.AddDesc(std::string("Content: ").append(
|
||||
UtfUtils::Str16ToStr8(textLayoutProp->GetContent().value_or(u" "))));
|
||||
}
|
||||
DumpTextStyleInfo();
|
||||
dumpLog.AddDesc(
|
||||
@ -4635,7 +4637,7 @@ void TextPattern::DumpInfo(std::unique_ptr<JsonValue>& json)
|
||||
auto nowTime = GetSystemTimestamp();
|
||||
json->Put("time", std::to_string(nowTime).c_str());
|
||||
if (!IsSetObscured()) {
|
||||
json->Put("Content", textLayoutProp->GetContent().value_or(" ").c_str());
|
||||
json->Put("Content", UtfUtils::Str16ToStr8(textLayoutProp->GetContent().value_or(u" ")).c_str());
|
||||
}
|
||||
json->Put("ConteFontColornt",
|
||||
(textStyle_.has_value() ? textStyle_->GetTextColor() : Color::BLACK).ColorToString().c_str());
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/text_clock/text_clock_accessibility_property.h"
|
||||
|
||||
#include "core/components_ng/pattern/text_clock/text_clock_pattern.h"
|
||||
@ -24,6 +25,6 @@ std::string TextClockAccessibilityProperty::GetText() const
|
||||
CHECK_NULL_RETURN(frameNode, "");
|
||||
auto textLayoutProperty = frameNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, "");
|
||||
return textLayoutProperty->GetContentValue("");
|
||||
return UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue(u""));
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -466,7 +466,7 @@ void TextPickerColumnPattern::ClearCurrentTextOptions(
|
||||
CHECK_NULL_VOID(textPattern);
|
||||
auto textLayoutProperty = textPattern->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(textLayoutProperty);
|
||||
textLayoutProperty->UpdateContent("");
|
||||
textLayoutProperty->UpdateContent(u"");
|
||||
textNode->GetRenderContext()->SetClipToFrame(true);
|
||||
textNode->MarkModifyDone();
|
||||
textNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
|
||||
@ -510,7 +510,7 @@ void TextPickerColumnPattern::FlushCurrentTextOptions(
|
||||
UpdatePickerTextProperties(textLayoutProperty, textPickerLayoutProperty, index, middleIndex, showCount);
|
||||
}
|
||||
if (NotLoopOptions() && !virtualIndexValidate) {
|
||||
textLayoutProperty->UpdateContent("");
|
||||
textLayoutProperty->UpdateContent(u"");
|
||||
} else {
|
||||
textLayoutProperty->UpdateContent(optionValue.text_);
|
||||
textLayoutProperty->UpdateTextAlign(TextAlign::CENTER);
|
||||
@ -634,7 +634,7 @@ void TextPickerColumnPattern::FlushCurrentMixtureOptions(
|
||||
}
|
||||
if (NotLoopOptions() && !virtualIndexValidate) {
|
||||
iconLayoutProperty->UpdateVisibility(VisibleType::INVISIBLE);
|
||||
textLayoutProperty->UpdateContent("");
|
||||
textLayoutProperty->UpdateContent(u"");
|
||||
} else {
|
||||
textLayoutProperty->UpdateContent(optionValue.text_);
|
||||
iconLayoutProperty->UpdateVisibility(VisibleType::VISIBLE);
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/pattern/texttimer/text_timer_accessibility_property.h"
|
||||
|
||||
#include "core/components_ng/pattern/texttimer/text_timer_pattern.h"
|
||||
@ -24,6 +25,6 @@ std::string TextTimerAccessibilityProperty::GetText() const
|
||||
CHECK_NULL_RETURN(frameNode, "");
|
||||
auto textLayoutProperty = frameNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, "");
|
||||
return textLayoutProperty->GetContentValue("");
|
||||
return UtfUtils::Str16ToStr8(textLayoutProperty->GetContentValue(u""));
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -489,7 +489,7 @@ void TimePickerColumnPattern::FlushCurrentOptions(bool isDown, bool isUpateTextC
|
||||
int32_t virtualIndex = static_cast<int32_t>(currentIndex) + diffIndex;
|
||||
bool virtualIndexValidate = virtualIndex >= 0 && virtualIndex < static_cast<int32_t>(totalOptionCount);
|
||||
if ((NotLoopOptions() || !wheelModeEnabled_) && !virtualIndexValidate) {
|
||||
textLayoutProperty->UpdateContent("");
|
||||
textLayoutProperty->UpdateContent(u"");
|
||||
} else {
|
||||
auto optionValue = timePickerRowPattern->GetOptionsValue(host, optionIndex);
|
||||
textLayoutProperty->UpdateContent(optionValue);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "core/components_ng/pattern/time_picker/timepicker_dialog_view.h"
|
||||
|
||||
#include "base/utils/utils.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "core/components_ng/base/view_stack_processor.h"
|
||||
#include "core/components_ng/pattern/button/button_pattern.h"
|
||||
#include "core/components_ng/pattern/dialog/dialog_view.h"
|
||||
@ -336,7 +337,8 @@ std::function<void(const GestureEvent&)> TimePickerDialogView::UpdateTimePickerS
|
||||
CHECK_NULL_VOID(buttonNextPrevLayoutProperty);
|
||||
timePickerEventHub->FireDialogAcceptEvent(pickerPattern->GetSelectedObject(true));
|
||||
func();
|
||||
if (textLayoutProperty->GetContent() == Localization::GetInstance()->GetEntryLetters("common.next")) {
|
||||
if (textLayoutProperty->GetContent() ==
|
||||
UtfUtils::Str8ToStr16(Localization::GetInstance()->GetEntryLetters("common.next"))) {
|
||||
UpdateCancelButtonMargin(buttonNextPrevLayoutProperty, dialogTheme);
|
||||
textLayoutProperty->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.prev"));
|
||||
} else {
|
||||
@ -437,7 +439,7 @@ RefPtr<FrameNode> TimePickerDialogView::CreateTitleButtonNode(const RefPtr<Frame
|
||||
CHECK_NULL_RETURN(textTitleNode, nullptr);
|
||||
auto textLayoutProperty = textTitleNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, nullptr);
|
||||
textLayoutProperty->UpdateContent("");
|
||||
textLayoutProperty->UpdateContent(u"");
|
||||
textLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT_MAIN_AXIS);
|
||||
auto titleNodeRenderContext = textTitleNode->GetRenderContext();
|
||||
titleNodeRenderContext->UpdateBackgroundColor(Color::TRANSPARENT);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "core/interfaces/native/node/node_text_modifier.h"
|
||||
|
||||
#include "base/utils/utils.h"
|
||||
#include "base/utils/utf_helper.h"
|
||||
#include "bridge/common/utils/utils.h"
|
||||
#include "core/components/common/layout/constants.h"
|
||||
#include "core/components/common/properties/text_style.h"
|
||||
@ -82,12 +83,11 @@ FontWeight ConvertStrToFontWeight(const char* weight, FontWeight defaultFontWeig
|
||||
namespace {
|
||||
|
||||
std::string g_strValue;
|
||||
|
||||
void SetTextContent(ArkUINodeHandle node, ArkUI_CharPtr value)
|
||||
{
|
||||
auto* frameNode = reinterpret_cast<FrameNode*>(node);
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
std::string content(value);
|
||||
std::u16string content = UtfUtils::Str8ToStr16(std::string(value));
|
||||
TextModelNG::InitText(frameNode, content);
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ const char* GetTextContent(ArkUINodeHandle node)
|
||||
{
|
||||
auto* frameNode = reinterpret_cast<FrameNode*>(node);
|
||||
CHECK_NULL_RETURN(frameNode, nullptr);
|
||||
g_strValue = TextModelNG::GetContent(frameNode);
|
||||
g_strValue = UtfUtils::Str16ToStr8(TextModelNG::GetContent(frameNode));
|
||||
return g_strValue.c_str();
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ ArkUIAPICallbackMethod* callbacks = nullptr;
|
||||
|
||||
void* createTextNode(ArkUI_Int32 nodeId)
|
||||
{
|
||||
auto frameNode = TextModelNG::CreateFrameNode(nodeId, "");
|
||||
auto frameNode = TextModelNG::CreateFrameNode(nodeId, u"");
|
||||
CHECK_NULL_RETURN(frameNode, nullptr);
|
||||
frameNode->IncRefCount();
|
||||
return AceType::RawPtr(frameNode);
|
||||
|
@ -374,6 +374,7 @@ ohos_source_set("ace_base") {
|
||||
"$ace_root/frameworks/base/utils/string_utils.cpp",
|
||||
"$ace_root/frameworks/base/utils/time_util.cpp",
|
||||
"$ace_root/frameworks/base/utils/utf.cpp",
|
||||
"$ace_root/frameworks/base/utils/utf_helper.cpp",
|
||||
"$ace_root/frameworks/base/utils/utils.cpp",
|
||||
]
|
||||
|
||||
|
@ -1048,7 +1048,7 @@ HWTEST_F(DragEventTestNg, DragEventShowBadgeTest01, TestSize.Level1)
|
||||
auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_NE(textLayoutProperty, nullptr);
|
||||
auto content = textLayoutProperty->GetContent();
|
||||
EXPECT_EQ(content, std::to_string(childSize));
|
||||
EXPECT_EQ(content, StringUtils::Str8ToStr16(std::to_string(childSize)));
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Invoke MountPixelMap function.
|
||||
@ -1123,7 +1123,7 @@ HWTEST_F(DragEventTestNg, DragEventShowBadgeTest02, TestSize.Level1)
|
||||
auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_NE(textLayoutProperty, nullptr);
|
||||
auto content = textLayoutProperty->GetContent();
|
||||
EXPECT_EQ(content, std::to_string(overlayManager->gatherNodeChildrenInfo_.size() + 1));
|
||||
EXPECT_EQ(content, StringUtils::Str8ToStr16(std::to_string(overlayManager->gatherNodeChildrenInfo_.size() + 1)));
|
||||
|
||||
/**
|
||||
* @tc.steps: step5. Get dragDropManager and invoke IsShowBadgeAnimation function.
|
||||
|
@ -255,7 +255,8 @@ HWTEST_F(DragAnimationHelperTestNg, CalcBadgeTextPosition001, TestSize.Level1)
|
||||
|
||||
auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_TRUE(textLayoutProperty != nullptr);
|
||||
auto content = textLayoutProperty->GetContentValue("2");
|
||||
EXPECT_STREQ(content.c_str(), std::to_string(overlayManager->GetGatherNodeChildrenInfo().size() + 1).c_str());
|
||||
auto content = textLayoutProperty->GetContentValue(u"2");
|
||||
EXPECT_STREQ(StringUtils::Str16ToStr8(content).c_str(),
|
||||
std::to_string(overlayManager->GetGatherNodeChildrenInfo().size() + 1).c_str());
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -333,7 +333,7 @@ HWTEST_F(BadgeTestNg, BadgePatternTest002, TestSize.Level1)
|
||||
|
||||
auto textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(firstChildFrameNode->GetLayoutProperty());
|
||||
ASSERT_NE(textLayoutProperty, nullptr);
|
||||
textLayoutProperty->UpdateContent("");
|
||||
textLayoutProperty->UpdateContent(u"");
|
||||
LayoutConstraintF parentLayoutConstraint;
|
||||
parentLayoutConstraint.maxSize = CONTAINER_SIZE;
|
||||
layoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(parentLayoutConstraint);
|
||||
@ -341,12 +341,12 @@ HWTEST_F(BadgeTestNg, BadgePatternTest002, TestSize.Level1)
|
||||
badgeLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
|
||||
badgeLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
|
||||
|
||||
textLayoutProperty->UpdateContent("x");
|
||||
textLayoutProperty->UpdateContent(u"x");
|
||||
badgeLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
|
||||
badgeLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
|
||||
|
||||
layoutProperty_->UpdateBadgeMaxCount(5);
|
||||
textLayoutProperty->UpdateContent("hello");
|
||||
textLayoutProperty->UpdateContent(u"hello");
|
||||
badgeLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
|
||||
badgeLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
|
||||
|
||||
@ -357,7 +357,7 @@ HWTEST_F(BadgeTestNg, BadgePatternTest002, TestSize.Level1)
|
||||
badgeLayoutAlgorithm->Layout(AccessibilityManager::RawPtr(layoutWrapper));
|
||||
}
|
||||
|
||||
textLayoutProperty->UpdateContent(" ");
|
||||
textLayoutProperty->UpdateContent(u" ");
|
||||
for (int32_t i = 0; i < 3; ++i) {
|
||||
auto badgePosition = static_cast<BadgePosition>(i);
|
||||
layoutProperty_->UpdateBadgePosition(badgePosition);
|
||||
@ -543,7 +543,7 @@ HWTEST_F(BadgeTestNg, BadgePatternTest006, TestSize.Level1)
|
||||
* @tc.steps: step5. call Measure with layoutWrapper.
|
||||
* @tc.expected: layoutAlgorithm->hasFontSize_ is true.
|
||||
*/
|
||||
textLayoutProperty->UpdateContent("1");
|
||||
textLayoutProperty->UpdateContent(u"1");
|
||||
badgeLayoutAlgorithm->Measure(AccessibilityManager::RawPtr(layoutWrapper));
|
||||
EXPECT_TRUE(layoutAlgorithm->hasFontSize_);
|
||||
|
||||
@ -652,7 +652,7 @@ HWTEST_F(BadgeTestNg, BadgePatternTest008, TestSize.Level1)
|
||||
layoutWrapper->AppendChild(firstChildLayoutWrapper);
|
||||
auto textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(firstChildFrameNode->GetLayoutProperty());
|
||||
ASSERT_NE(textLayoutProperty, nullptr);
|
||||
textLayoutProperty->UpdateContent("badge value");
|
||||
textLayoutProperty->UpdateContent(u"badge value");
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. update layoutWrapper and go to different branch.
|
||||
@ -785,7 +785,7 @@ HWTEST_F(BadgeTestNg, BadgeLayoutAlgorithmTestNg001, TestSize.Level1)
|
||||
badge.Create(badgeParameters);
|
||||
{
|
||||
TextModelNG model;
|
||||
model.Create("text");
|
||||
model.Create(u"text");
|
||||
ViewStackProcessor::GetInstance()->Pop();
|
||||
ViewStackProcessor::GetInstance()->StopGetAccessRecording();
|
||||
}
|
||||
@ -817,7 +817,7 @@ HWTEST_F(BadgeTestNg, BadgeLayoutAlgorithmTestNg002, TestSize.Level1)
|
||||
badge.Create(badgeParameters);
|
||||
{
|
||||
TextModelNG model;
|
||||
model.Create("text");
|
||||
model.Create(u"text");
|
||||
ViewStackProcessor::GetInstance()->Pop();
|
||||
ViewStackProcessor::GetInstance()->StopGetAccessRecording();
|
||||
}
|
||||
@ -849,7 +849,7 @@ HWTEST_F(BadgeTestNg, BadgeLayoutAlgorithmTestNg003, TestSize.Level1)
|
||||
badge.Create(badgeParameters);
|
||||
{
|
||||
TextModelNG model;
|
||||
model.Create("text");
|
||||
model.Create(u"text");
|
||||
ViewStackProcessor::GetInstance()->Pop();
|
||||
ViewStackProcessor::GetInstance()->StopGetAccessRecording();
|
||||
}
|
||||
@ -884,7 +884,7 @@ HWTEST_F(BadgeTestNg, BadgeLayoutAlgorithmTestNg004, TestSize.Level1)
|
||||
badge.Create(badgeParameters);
|
||||
{
|
||||
TextModelNG model;
|
||||
model.Create("text");
|
||||
model.Create(u"text");
|
||||
ViewStackProcessor::GetInstance()->Pop();
|
||||
ViewStackProcessor::GetInstance()->StopGetAccessRecording();
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ constexpr float BUTTON_ONLY_HAS_WIDTH_VALUE = 100.0f;
|
||||
const SizeF BUTTON_SIZE(BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
const SizeF TEXT_SIZE(TEXT_WIDTH, TEXT_HEIGHT);
|
||||
const std::string CREATE_VALUE = "Hello World";
|
||||
const std::u16string CREATE_U16VALUE = u"Hello World";
|
||||
const std::string BUTTON_VALUE = "Test";
|
||||
const std::string TEST_RESULT = "result_ok";
|
||||
const std::string TEST_RESULT_CAPSULE = "capsule";
|
||||
@ -586,7 +587,7 @@ HWTEST_F(ButtonTestNg, ButtonPatternTest006, TestSize.Level1)
|
||||
auto textLayoutProp = text->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textLayoutProp, nullptr);
|
||||
|
||||
EXPECT_EQ(textLayoutProp->GetContent(), CREATE_VALUE);
|
||||
EXPECT_EQ(textLayoutProp->GetContent(), CREATE_U16VALUE);
|
||||
EXPECT_EQ(textLayoutProp->GetFontSize(), BUTTON_FONT_SIZE_VALUE);
|
||||
EXPECT_EQ(textLayoutProp->GetFontWeight(), BUTTON_BOLD_FONT_WEIGHT_VALUE);
|
||||
EXPECT_EQ(textLayoutProp->GetTextColor(), FONT_COLOR);
|
||||
|
@ -298,15 +298,15 @@ HWTEST_F(CalendarPickerTestNg, CalendarPickerModelNGTest004, TestSize.Level1)
|
||||
pickerPattern->SetDate(json->ToString());
|
||||
auto yearTextNode = calendarPickerModel.GetYearNode(AceType::RawPtr(frameNode));
|
||||
auto yearTextLayoutProperty = yearTextNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_EQ(yearTextLayoutProperty->GetContentValue(), "2000");
|
||||
EXPECT_EQ(yearTextLayoutProperty->GetContentValue(), u"2000");
|
||||
|
||||
auto monthTextNode = calendarPickerModel.GetMonthNode(AceType::RawPtr(frameNode));
|
||||
auto monthTextLayoutProperty = monthTextNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_EQ(monthTextLayoutProperty->GetContentValue(), "02");
|
||||
EXPECT_EQ(monthTextLayoutProperty->GetContentValue(), u"02");
|
||||
|
||||
auto dayTextNode = calendarPickerModel.GetDayNode(AceType::RawPtr(frameNode));
|
||||
auto dayTextLayoutProperty = dayTextNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_EQ(dayTextLayoutProperty->GetContentValue(), "29");
|
||||
EXPECT_EQ(dayTextLayoutProperty->GetContentValue(), u"29");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -342,15 +342,15 @@ HWTEST_F(CalendarPickerTestNg, CalendarPickerModelNGTest005, TestSize.Level1)
|
||||
|
||||
auto yearTextNode = calendarPickerModel.GetYearNode(AceType::RawPtr(frameNode));
|
||||
auto yearTextLayoutProperty = yearTextNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_EQ(yearTextLayoutProperty->GetContentValue(), "2000");
|
||||
EXPECT_EQ(yearTextLayoutProperty->GetContentValue(), u"2000");
|
||||
|
||||
auto monthTextNode = calendarPickerModel.GetMonthNode(AceType::RawPtr(frameNode));
|
||||
auto monthTextLayoutProperty = monthTextNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_EQ(monthTextLayoutProperty->GetContentValue(), "02");
|
||||
EXPECT_EQ(monthTextLayoutProperty->GetContentValue(), u"02");
|
||||
|
||||
auto dayTextNode = calendarPickerModel.GetDayNode(AceType::RawPtr(frameNode));
|
||||
auto dayTextLayoutProperty = dayTextNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_EQ(dayTextLayoutProperty->GetContentValue(), "29");
|
||||
EXPECT_EQ(dayTextLayoutProperty->GetContentValue(), u"29");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -386,15 +386,15 @@ HWTEST_F(CalendarPickerTestNg, CalendarPickerModelNGTest006, TestSize.Level1)
|
||||
|
||||
auto yearTextNode = calendarPickerModel.GetYearNode(AceType::RawPtr(frameNode));
|
||||
auto yearTextLayoutProperty = yearTextNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_EQ(yearTextLayoutProperty->GetContentValue(), "2000");
|
||||
EXPECT_EQ(yearTextLayoutProperty->GetContentValue(), u"2000");
|
||||
|
||||
auto monthTextNode = calendarPickerModel.GetMonthNode(AceType::RawPtr(frameNode));
|
||||
auto monthTextLayoutProperty = monthTextNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_EQ(monthTextLayoutProperty->GetContentValue(), "02");
|
||||
EXPECT_EQ(monthTextLayoutProperty->GetContentValue(), u"02");
|
||||
|
||||
auto dayTextNode = calendarPickerModel.GetDayNode(AceType::RawPtr(frameNode));
|
||||
auto dayTextLayoutProperty = dayTextNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
EXPECT_EQ(dayTextLayoutProperty->GetContentValue(), "29");
|
||||
EXPECT_EQ(dayTextLayoutProperty->GetContentValue(), u"29");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ const OffsetF OFFSET_TOP_LEFT = OffsetF(ZERO, ZERO);
|
||||
} // namespace
|
||||
class FlexNewTestNG : public FlexBaseTestNG {
|
||||
public:
|
||||
RefPtr<FrameNode> CreateNormalFrameNode(const std::string& content, const std::string& tag)
|
||||
RefPtr<FrameNode> CreateNormalFrameNode(const std::u16string& content, const std::string& tag)
|
||||
{
|
||||
auto* stack = ViewStackProcessor::GetInstance();
|
||||
auto nodeId = stack->ClaimNodeId();
|
||||
@ -83,11 +83,11 @@ HWTEST_F(FlexNewTestNG, Example, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(300.0f));
|
||||
|
||||
// // step: create child nodes
|
||||
auto text1 = CreateText("text1", [this](TextModelNG model) {
|
||||
auto text1 = CreateText(u"text1", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
auto text2 = CreateText("text2", [this](TextModelNG model) {
|
||||
auto text2 = CreateText(u"text2", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
@ -147,7 +147,7 @@ HWTEST_F(FlexNewTestNG, HandleBlankFirstTimeMeasure001, TestSize.Level1)
|
||||
ViewAbstract::SetWidth(CalcLength(300.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(300.0f));
|
||||
|
||||
blankFrameNode = CreateNormalFrameNode("blank", V2::BLANK_ETS_TAG);
|
||||
blankFrameNode = CreateNormalFrameNode(u"blank", V2::BLANK_ETS_TAG);
|
||||
});
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
CreateLayoutTask(frameNode);
|
||||
@ -205,7 +205,7 @@ HWTEST_F(FlexNewTestNG, PlaceChildren001, TestSize.Level1)
|
||||
ViewAbstract::SetWidth(CalcLength(300.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(300.0f));
|
||||
|
||||
textFrameNode = CreateNormalFrameNode("text", V2::TEXT_ETS_TAG);
|
||||
textFrameNode = CreateNormalFrameNode(u"text", V2::TEXT_ETS_TAG);
|
||||
});
|
||||
CreateLayoutTask(frameNode);
|
||||
auto pattern = AceType::DynamicCast<FlexLayoutPattern>(frameNode->GetPattern());
|
||||
@ -271,8 +271,8 @@ HWTEST_F(FlexNewTestNG, SecondaryMeasureByProperty001, TestSize.Level1)
|
||||
ViewAbstract::SetWidth(CalcLength(300.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(300.0f));
|
||||
|
||||
auto textFrameNode1 = CreateNormalFrameNode("text1", V2::TEXT_ETS_TAG);
|
||||
auto textFrameNode2 = CreateNormalFrameNode("text2", V2::BLANK_ETS_TAG);
|
||||
auto textFrameNode1 = CreateNormalFrameNode(u"text1", V2::TEXT_ETS_TAG);
|
||||
auto textFrameNode2 = CreateNormalFrameNode(u"text2", V2::BLANK_ETS_TAG);
|
||||
});
|
||||
CreateLayoutTask(frameNode);
|
||||
auto pattern = AceType::DynamicCast<FlexLayoutPattern>(frameNode->GetPattern());
|
||||
@ -341,11 +341,11 @@ HWTEST_F(FlexNewTestNG, MeasureAndCleanMagicNodes001, TestSize.Level1)
|
||||
ViewAbstract::SetWidth(CalcLength(300.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(300.0f));
|
||||
|
||||
auto text1 = CreateText("text1", [this](TextModelNG model) {
|
||||
auto text1 = CreateText(u"text1", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
auto text2 = CreateText("text2", [this](TextModelNG model) {
|
||||
auto text2 = CreateText(u"text2", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
@ -408,11 +408,11 @@ HWTEST_F(FlexNewTestNG, MeasureAndCleanMagicNodes002, TestSize.Level1)
|
||||
ViewAbstract::SetWidth(CalcLength(300.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(300.0f));
|
||||
|
||||
auto text1 = CreateText("text1", [this](TextModelNG model) {
|
||||
auto text1 = CreateText(u"text1", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
auto text2 = CreateText("text2", [this](TextModelNG model) {
|
||||
auto text2 = CreateText(u"text2", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
@ -471,7 +471,7 @@ HWTEST_F(FlexNewTestNG, ReverseFlexDirection001, TestSize.Level1)
|
||||
ViewAbstract::SetWidth(CalcLength(300.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(300.0f));
|
||||
|
||||
auto text = CreateText("text", [this](TextModelNG model) {
|
||||
auto text = CreateText(u"text", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
@ -522,7 +522,7 @@ HWTEST_F(FlexNewTestNG, CheckIsGrowOrShrink001, TestSize.Level1)
|
||||
ViewAbstract::SetWidth(CalcLength(300.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(300.0f));
|
||||
|
||||
textFrameNode = CreateText("text", [this](TextModelNG model) {
|
||||
textFrameNode = CreateText(u"text", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
@ -626,7 +626,7 @@ HWTEST_F(FlexNewTestNG, UpdateLayoutConstraintOnCrossAxis001, TestSize.Level1)
|
||||
ViewAbstract::SetWidth(CalcLength(300.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(300.0f));
|
||||
|
||||
textFrameNode = CreateText("text", [this](TextModelNG model) {
|
||||
textFrameNode = CreateText(u"text", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
@ -679,11 +679,11 @@ HWTEST_F(FlexNewTestNG, MeasureAndCleanMagicNodes003, TestSize.Level1)
|
||||
ViewAbstract::SetWidth(CalcLength(300.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(300.0f));
|
||||
|
||||
auto text1 = CreateText("text1", [this](TextModelNG model) {
|
||||
auto text1 = CreateText(u"text1", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
auto text2 = CreateText("text2", [this](TextModelNG model) {
|
||||
auto text2 = CreateText(u"text2", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
});
|
||||
|
@ -64,7 +64,7 @@ public:
|
||||
modelNG.Create(builder.Build());
|
||||
|
||||
TextModelNG text;
|
||||
text.Create("child");
|
||||
text.Create(u"child");
|
||||
textNode_ = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode());
|
||||
textNode_->GetLayoutProperty()->UpdateGridProperty(1, 1);
|
||||
ViewStackProcessor::GetInstance()->Pop();
|
||||
|
@ -39,14 +39,14 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetArrayValueTexts()
|
||||
std::u16string GetArrayValueTexts()
|
||||
{
|
||||
std::string arrayValueTexts;
|
||||
std::u16string arrayValueTexts;
|
||||
int32_t totalChildCount = frameNode_->GetTotalChildCount();
|
||||
for (int32_t index = 0; index < totalChildCount; index++) {
|
||||
auto textLayoutProperty = GetChildLayoutProperty<TextLayoutProperty>(frameNode_, index);
|
||||
std::string text = textLayoutProperty->GetContent().value_or("");
|
||||
arrayValueTexts += text == "•" ? "." : text; // avoid EXPECT error
|
||||
std::u16string text = textLayoutProperty->GetContent().value_or(u"");
|
||||
arrayValueTexts += text == u"•" ? u"." : text; // avoid EXPECT error
|
||||
}
|
||||
return arrayValueTexts;
|
||||
}
|
||||
@ -653,7 +653,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse001, TestSize.Level1)
|
||||
model.SetAutoCollapse(false);
|
||||
CreateDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::INVALID);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. AutoCollapse is true, Set Height enough to contain short fold mode items
|
||||
@ -665,7 +665,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse001, TestSize.Level1)
|
||||
FlushLayoutTask(frameNode_);
|
||||
frameNode_->MarkModifyDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::FIVE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "A.G.M.S.Z");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"A.G.M.S.Z");
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Set Height enough to contain long fold mode items
|
||||
@ -676,7 +676,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse001, TestSize.Level1)
|
||||
FlushLayoutTask(frameNode_);
|
||||
frameNode_->MarkModifyDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::SEVEN);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "A.E.I.M.Q.U.Z");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"A.E.I.M.Q.U.Z");
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Set Height enough to contain all items
|
||||
@ -688,7 +688,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse001, TestSize.Level1)
|
||||
FlushLayoutTask(frameNode_);
|
||||
frameNode_->MarkModifyDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::NONE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -708,7 +708,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse002, TestSize.Level1)
|
||||
model.SetAutoCollapse(false);
|
||||
CreateDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::INVALID);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "#ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"#ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. AutoCollapse is true
|
||||
@ -720,7 +720,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse002, TestSize.Level1)
|
||||
FlushLayoutTask(frameNode_);
|
||||
frameNode_->MarkModifyDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::FIVE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "#A.G.M.S.Z");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"#A.G.M.S.Z");
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Set Height enough to contain long fold mode items
|
||||
@ -731,7 +731,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse002, TestSize.Level1)
|
||||
FlushLayoutTask(frameNode_);
|
||||
frameNode_->MarkModifyDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::SEVEN);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "#A.E.I.M.Q.U.Z");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"#A.E.I.M.Q.U.Z");
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Set Height enough to contain all items
|
||||
@ -743,7 +743,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse002, TestSize.Level1)
|
||||
FlushLayoutTask(frameNode_);
|
||||
frameNode_->MarkModifyDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::NONE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "#ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"#ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -762,7 +762,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse003, TestSize.Level1)
|
||||
model.SetAutoCollapse(true);
|
||||
CreateDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::NONE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "ABCDEFGHIJKLM");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"ABCDEFGHIJKLM");
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Set Height enough to contain short fold mode items
|
||||
@ -773,7 +773,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse003, TestSize.Level1)
|
||||
FlushLayoutTask(frameNode_);
|
||||
frameNode_->MarkModifyDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::FIVE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "A.D.G.J.M");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"A.D.G.J.M");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -792,7 +792,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse004, TestSize.Level1)
|
||||
model.SetAutoCollapse(true);
|
||||
CreateDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::NONE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "ABCDEFGHI");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"ABCDEFGHI");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -811,7 +811,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse005, TestSize.Level1)
|
||||
model.SetAutoCollapse(true);
|
||||
CreateDone();
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::NONE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "ABCDEFGHIJKLM");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"ABCDEFGHIJKLM");
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Set Height more than the height of all item
|
||||
@ -824,7 +824,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse005, TestSize.Level1)
|
||||
frameNode_->MarkModifyDone();
|
||||
FlushLayoutTask(frameNode_);
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::NONE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "ABCDEFGHIJKLM");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"ABCDEFGHIJKLM");
|
||||
EXPECT_EQ(pattern_->maxContentHeight_, (INDEXER_ITEM_SIZE + 1) * INDEXER_THIRTEEN_CHARACTERS_CHECK);
|
||||
EXPECT_EQ(pattern_->itemHeight_, INDEXER_ITEM_SIZE);
|
||||
|
||||
@ -841,7 +841,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse005, TestSize.Level1)
|
||||
frameNode_->MarkModifyDone();
|
||||
FlushLayoutTask(frameNode_);
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::FIVE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "A.D.G.J.M");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"A.D.G.J.M");
|
||||
EXPECT_EQ(pattern_->maxContentHeight_, (INDEXER_ITEM_SIZE - 1) * INDEXER_THIRTEEN_CHARACTERS_CHECK);
|
||||
EXPECT_EQ(pattern_->itemHeight_, INDEXER_ITEM_SIZE);
|
||||
|
||||
@ -856,7 +856,7 @@ HWTEST_F(IndexerLayoutTestNg, AutoCollapse005, TestSize.Level1)
|
||||
frameNode_->MarkModifyDone();
|
||||
FlushLayoutTask(frameNode_);
|
||||
EXPECT_EQ(pattern_->lastCollapsingMode_, IndexerCollapsingMode::FIVE);
|
||||
EXPECT_EQ(GetArrayValueTexts(), "A.D.G.J.M");
|
||||
EXPECT_EQ(GetArrayValueTexts(), u"A.D.G.J.M");
|
||||
EXPECT_EQ(pattern_->maxContentHeight_, (INDEXER_ITEM_SIZE - 1) * INDEXER_NINE_CHARACTERS_CHECK);
|
||||
EXPECT_EQ(pattern_->itemHeight_, INDEXER_ITEM_SIZE - 1);
|
||||
}
|
||||
|
@ -1262,7 +1262,7 @@ HWTEST_F(MarqueeTestNg, MarqueeTest017, TestSize.Level1)
|
||||
marqueeLayoutProperty->UpdateFontColor(Color(2));
|
||||
frameNode->SetLayoutProperty(marqueeLayoutProperty);
|
||||
pattern->OnModifyDone();
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), "test");
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), u"test");
|
||||
EXPECT_EQ(textLayoutProperty->GetFontSize().value(), Dimension(2.0));
|
||||
EXPECT_EQ(textLayoutProperty->GetFontWeight().value(), Ace::FontWeight::W200);
|
||||
EXPECT_EQ(textLayoutProperty->GetFontFamily().value(), fontFamily);
|
||||
|
@ -1295,7 +1295,7 @@ HWTEST_F(MarqueeTestUpdateStrategyNg, MarqueeTestUpdateStrategy017, TestSize.Lev
|
||||
marqueeLayoutProperty->UpdateMarqueeUpdateStrategy(Ace::MarqueeUpdateStrategy::PRESERVE_POSITION);
|
||||
frameNode->SetLayoutProperty(marqueeLayoutProperty);
|
||||
pattern->OnModifyDone();
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), "test");
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), u"test");
|
||||
EXPECT_EQ(textLayoutProperty->GetFontSize().value(), Dimension(2.0));
|
||||
EXPECT_EQ(textLayoutProperty->GetFontWeight().value(), Ace::FontWeight::W200);
|
||||
EXPECT_EQ(textLayoutProperty->GetFontFamily().value(), fontFamily);
|
||||
|
@ -860,7 +860,7 @@ HWTEST_F(MenuTestNg, MenuViewTestNgCreate002, TestSize.Level1)
|
||||
auto textProperty = titleChild->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textProperty, nullptr);
|
||||
EXPECT_TRUE(textProperty->GetContent().has_value());
|
||||
EXPECT_EQ(textProperty->GetContent().value(), "Title");
|
||||
EXPECT_EQ(textProperty->GetContent().value(), u"Title");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -382,7 +382,7 @@ HWTEST_F(MenuPattern1TestNg, MenuPatternTestNg007, TestSize.Level1)
|
||||
auto textProperty = contentNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textProperty, nullptr);
|
||||
ASSERT_TRUE(textProperty->GetContent().has_value());
|
||||
EXPECT_EQ(textProperty->GetContent().value(), "content");
|
||||
EXPECT_EQ(textProperty->GetContent().value(), u"content");
|
||||
ASSERT_TRUE(textProperty->GetFontSize().has_value());
|
||||
EXPECT_EQ(textProperty->GetFontSize().value(), Dimension(25.0));
|
||||
ASSERT_TRUE(textProperty->GetFontWeight().has_value());
|
||||
@ -395,7 +395,7 @@ HWTEST_F(MenuPattern1TestNg, MenuPatternTestNg007, TestSize.Level1)
|
||||
auto labelProperty = labelNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(labelProperty, nullptr);
|
||||
ASSERT_TRUE(labelProperty->GetContent().has_value());
|
||||
EXPECT_EQ(labelProperty->GetContent().value(), "label");
|
||||
EXPECT_EQ(labelProperty->GetContent().value(), u"label");
|
||||
ASSERT_TRUE(labelProperty->GetFontSize().has_value());
|
||||
EXPECT_EQ(labelProperty->GetFontSize().value(), Dimension(25.0));
|
||||
ASSERT_TRUE(labelProperty->GetFontWeight().has_value());
|
||||
@ -510,7 +510,7 @@ HWTEST_F(MenuPattern1TestNg, MenuPatternTestNg009, TestSize.Level1)
|
||||
auto textProperty = contentNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textProperty, nullptr);
|
||||
ASSERT_TRUE(textProperty->GetContent().has_value());
|
||||
EXPECT_EQ(textProperty->GetContent().value(), "content");
|
||||
EXPECT_EQ(textProperty->GetContent().value(), u"content");
|
||||
ASSERT_TRUE(textProperty->GetFontSize().has_value());
|
||||
EXPECT_EQ(textProperty->GetFontSize().value(), Dimension(25.0));
|
||||
ASSERT_TRUE(textProperty->GetFontWeight().has_value());
|
||||
@ -523,7 +523,7 @@ HWTEST_F(MenuPattern1TestNg, MenuPatternTestNg009, TestSize.Level1)
|
||||
auto labelProperty = labelNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(labelProperty, nullptr);
|
||||
ASSERT_TRUE(labelProperty->GetContent().has_value());
|
||||
EXPECT_EQ(labelProperty->GetContent().value(), "label");
|
||||
EXPECT_EQ(labelProperty->GetContent().value(), u"label");
|
||||
ASSERT_TRUE(labelProperty->GetFontSize().has_value());
|
||||
EXPECT_EQ(labelProperty->GetFontSize().value(), Dimension(25.0));
|
||||
ASSERT_TRUE(labelProperty->GetFontWeight().has_value());
|
||||
@ -582,7 +582,7 @@ HWTEST_F(MenuPattern1TestNg, MenuPatternTestNg010, TestSize.Level1)
|
||||
auto textProperty = contentNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textProperty, nullptr);
|
||||
ASSERT_TRUE(textProperty->GetContent().has_value());
|
||||
EXPECT_EQ(textProperty->GetContent().value(), "content");
|
||||
EXPECT_EQ(textProperty->GetContent().value(), u"content");
|
||||
ASSERT_TRUE(textProperty->GetFontSize().has_value());
|
||||
ASSERT_TRUE(textProperty->GetFontWeight().has_value());
|
||||
EXPECT_EQ(textProperty->GetFontWeight().value(), FontWeight::REGULAR);
|
||||
@ -657,7 +657,7 @@ HWTEST_F(MenuPattern1TestNg, MenuPatternTestNg012, TestSize.Level1)
|
||||
auto textProps = optionPattern->text_->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textProps, nullptr);
|
||||
auto param = CREATE_VALUE.at(i);
|
||||
EXPECT_EQ(textProps->GetContent().value_or(""), param.text);
|
||||
EXPECT_EQ(textProps->GetContent().value_or(u""), StringUtils::Str8ToStr16(param.text));
|
||||
if (param.icon.empty()) {
|
||||
ASSERT_EQ(optionPattern->icon_, nullptr);
|
||||
} else {
|
||||
@ -705,7 +705,7 @@ HWTEST_F(MenuPattern1TestNg, MenuPatternTestNg013, TestSize.Level1)
|
||||
auto textProps = optionPattern->text_->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textProps, nullptr);
|
||||
auto param = CREATE_VALUE.at(i);
|
||||
EXPECT_EQ(textProps->GetContent().value_or(""), param.text);
|
||||
EXPECT_EQ(textProps->GetContent().value_or(u""), StringUtils::Str8ToStr16(param.text));
|
||||
if (param.icon.empty()) {
|
||||
ASSERT_EQ(optionPattern->icon_, nullptr);
|
||||
} else {
|
||||
@ -769,7 +769,7 @@ HWTEST_F(MenuPattern1TestNg, MenuPatternTestNg015, TestSize.Level1)
|
||||
auto textProps = optionPattern->text_->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textProps, nullptr);
|
||||
auto param = CREATE_VALUE_NEW.at(i);
|
||||
EXPECT_EQ(textProps->GetContent().value_or(""), param.text);
|
||||
EXPECT_EQ(textProps->GetContent().value_or(u""), StringUtils::Str8ToStr16(param.text));
|
||||
if (param.icon.empty()) {
|
||||
ASSERT_EQ(optionPattern->icon_, nullptr);
|
||||
} else {
|
||||
@ -817,7 +817,7 @@ HWTEST_F(MenuPattern1TestNg, MenuPatternTestNg016, TestSize.Level1)
|
||||
auto textProps = optionPattern->text_->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textProps, nullptr);
|
||||
auto param = params.at(i);
|
||||
EXPECT_EQ(textProps->GetContent().value_or(""), param.text);
|
||||
EXPECT_EQ(textProps->GetContent().value_or(u""), StringUtils::Str8ToStr16(param.text));
|
||||
if (param.icon.empty()) {
|
||||
ASSERT_EQ(optionPattern->icon_, nullptr);
|
||||
} else {
|
||||
@ -866,7 +866,7 @@ HWTEST_F(MenuPattern1TestNg, MenuPatternTestNg017, TestSize.Level1)
|
||||
auto textProps = optionPattern->text_->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textProps, nullptr);
|
||||
auto param = CREATE_VALUE_NEW.at(i);
|
||||
EXPECT_EQ(textProps->GetContent().value_or(""), param.text);
|
||||
EXPECT_EQ(textProps->GetContent().value_or(u""), StringUtils::Str8ToStr16(param.text));
|
||||
if (param.icon.empty()) {
|
||||
ASSERT_EQ(optionPattern->icon_, nullptr);
|
||||
} else {
|
||||
|
@ -194,7 +194,7 @@ void CheckTestResult(RefPtr<MenuItemPattern> itemPattern)
|
||||
auto textProperty = contentNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(textProperty, nullptr);
|
||||
ASSERT_TRUE(textProperty->GetContent().has_value());
|
||||
EXPECT_EQ(textProperty->GetContent().value(), "content");
|
||||
EXPECT_EQ(textProperty->GetContent().value(), u"content");
|
||||
ASSERT_TRUE(textProperty->GetFontSize().has_value());
|
||||
EXPECT_EQ(textProperty->GetFontSize().value(), Dimension(TARGET_FONT));
|
||||
ASSERT_TRUE(textProperty->GetFontWeight().has_value());
|
||||
@ -207,7 +207,7 @@ void CheckTestResult(RefPtr<MenuItemPattern> itemPattern)
|
||||
auto labelProperty = labelNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(labelProperty, nullptr);
|
||||
ASSERT_TRUE(labelProperty->GetContent().has_value());
|
||||
EXPECT_EQ(labelProperty->GetContent().value(), "label");
|
||||
EXPECT_EQ(labelProperty->GetContent().value(), u"label");
|
||||
ASSERT_TRUE(labelProperty->GetFontSize().has_value());
|
||||
EXPECT_EQ(labelProperty->GetFontSize().value(), Dimension(TARGET_FONT));
|
||||
ASSERT_TRUE(labelProperty->GetFontWeight().has_value());
|
||||
|
@ -541,7 +541,7 @@ HWTEST_F(MenuItemPatternTestNg, MenuItemPatternTestNgUpdateText001, TestSize.Lev
|
||||
ASSERT_NE(textLayoutProperty, nullptr);
|
||||
auto content = textLayoutProperty->GetContent();
|
||||
ASSERT_TRUE(content.has_value());
|
||||
EXPECT_EQ(content.value(), "content");
|
||||
EXPECT_EQ(content.value(), u"content");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -579,7 +579,7 @@ HWTEST_F(MenuItemPatternTestNg, MenuItemPatternTestNgUpdateText002, TestSize.Lev
|
||||
ASSERT_NE(textLayoutProperty, nullptr);
|
||||
auto content = textLayoutProperty->GetContent();
|
||||
ASSERT_TRUE(content.has_value());
|
||||
EXPECT_EQ(content.value(), "label");
|
||||
EXPECT_EQ(content.value(), u"label");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -629,7 +629,7 @@ HWTEST_F(MenuItemPatternTestNg, MenuItemPatternTestNgUpdateText003, TestSize.Lev
|
||||
ASSERT_NE(textLayoutProperty, nullptr);
|
||||
auto content = textLayoutProperty->GetContent();
|
||||
ASSERT_TRUE(content.has_value());
|
||||
EXPECT_EQ(content.value(), "item content");
|
||||
EXPECT_EQ(content.value(), u"item content");
|
||||
auto textRenderContext = contentNode->GetRenderContext();
|
||||
EXPECT_EQ(textRenderContext->GetOpacity(), selectTheme->GetDisabledFontColorAlpha());
|
||||
}
|
||||
|
@ -687,7 +687,7 @@ HWTEST_F(MenuItemPatternTestOneNg, UpdateSymbolIcon001, TestSize.Level1)
|
||||
ASSERT_NE(textLayoutProperty, nullptr);
|
||||
auto content = textLayoutProperty->GetContent();
|
||||
ASSERT_TRUE(content.has_value());
|
||||
EXPECT_EQ(content.value(), "label");
|
||||
EXPECT_EQ(content.value(), u"label");
|
||||
|
||||
ImageSourceInfo imageSourceInfo;
|
||||
std::function<void(WeakPtr<NG::FrameNode>)> symbol = [](const WeakPtr<NG::FrameNode>& node) {};
|
||||
|
@ -581,7 +581,7 @@ HWTEST_F(ToolBarTestNg, NavToolbarPatternShowDialogWithNode001, TestSize.Level1)
|
||||
auto textNode = FrameNode::CreateFrameNode("Text", 0, AceType::MakeRefPtr<TextPattern>());
|
||||
auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(textLayoutProperty);
|
||||
textLayoutProperty->propContent_ = "";
|
||||
textLayoutProperty->propContent_ = u"";
|
||||
barItem1->SetTextNode(textNode);
|
||||
auto imageNode = FrameNode::GetOrCreateFrameNode(
|
||||
"Image", 1, []() { return AceType::MakeRefPtr<ImagePattern>(); });
|
||||
@ -593,7 +593,7 @@ HWTEST_F(ToolBarTestNg, NavToolbarPatternShowDialogWithNode001, TestSize.Level1)
|
||||
EXPECT_NE(imageNode->GetTag(), V2::SYMBOL_ETS_TAG);
|
||||
toolbarPattern->ShowDialogWithNode(barItem1);
|
||||
|
||||
textLayoutProperty->propContent_ = "test";
|
||||
textLayoutProperty->propContent_ = u"test";
|
||||
imageNode->tag_ = V2::SYMBOL_ETS_TAG;
|
||||
ASSERT_TRUE(textLayoutProperty->GetContent().has_value());
|
||||
EXPECT_FALSE(textLayoutProperty->GetContent().value().empty());
|
||||
|
@ -956,7 +956,7 @@ HWTEST_F(NavrouterModelTestNg, NavrouterTestNg0035, TestSize.Level1)
|
||||
|
||||
layoutProperty->propTitleBarParentType_ = TitleBarParentType::NAVBAR;
|
||||
layoutProperty->propTitleMode_ = NavigationTitleMode::FREE;
|
||||
titleLayoutProperty->propContent_ = "content";
|
||||
titleLayoutProperty->propContent_ = u"content";
|
||||
algorithm->Layout(AceType::RawPtr(layoutWrapper));
|
||||
ASSERT_EQ(layoutProperty->propTitleBarParentType_.value(), TitleBarParentType::NAVBAR);
|
||||
ASSERT_EQ(layoutProperty->propTitleMode_.value(), NavigationTitleMode::FREE);
|
||||
@ -1544,7 +1544,7 @@ HWTEST_F(NavrouterModelTestNg, NavrouterTestNg0043, TestSize.Level1)
|
||||
algorithm->isInitialTitle_ = true;
|
||||
auto temp = title->GetLayoutProperty<TextLayoutProperty>();
|
||||
ASSERT_NE(temp, nullptr);
|
||||
temp->propContent_ = "content";
|
||||
temp->propContent_ = u"content";
|
||||
algorithm->LayoutTitle(AceType::RawPtr(layoutWrapper), titleBarNode, titleBarLayoutProperty, 40);
|
||||
ASSERT_FALSE(algorithm->isInitialTitle_);
|
||||
|
||||
|
@ -289,7 +289,8 @@ HWTEST_F(DatePickerOrderTest, DatePickerOrder001, TestSize.Level1)
|
||||
DateTime date;
|
||||
date.month = DEFAULT_MONTH_DAY.at(YEARINDEX);
|
||||
date.day = DEFAULT_MONTH_DAY.at(YEARINDEX);
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), Localization::GetInstance()->FormatDateTime(date, "MMdd"));
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(),
|
||||
StringUtils::Str8ToStr16(Localization::GetInstance()->FormatDateTime(date, "MMdd")));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -351,7 +352,8 @@ HWTEST_F(DatePickerOrderTest, DatePickerOrder002, TestSize.Level1)
|
||||
DateTime date;
|
||||
date.month = DEFAULT_MONTH_DAY.at(YEARINDEX);
|
||||
date.day = DEFAULT_MONTH_DAY.at(YEARINDEX);
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), Localization::GetInstance()->FormatDateTime(date, "MMdd"));
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(),
|
||||
StringUtils::Str8ToStr16(Localization::GetInstance()->FormatDateTime(date, "MMdd")));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -413,7 +415,8 @@ HWTEST_F(DatePickerOrderTest, DatePickerOrder003, TestSize.Level1)
|
||||
DateTime date;
|
||||
date.month = DEFAULT_MONTH_DAY.at(YEARINDEX);
|
||||
date.day = DEFAULT_MONTH_DAY.at(YEARINDEX);
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(), Localization::GetInstance()->FormatDateTime(date, "MMdd"));
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(),
|
||||
StringUtils::Str8ToStr16(Localization::GetInstance()->FormatDateTime(date, "MMdd")));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -861,17 +861,17 @@ HWTEST_F(ProgressTestNg, ProgressSetValue002, TestSize.Level1)
|
||||
|
||||
pattern_->SetTextFromUser(false);
|
||||
progressModel.SetValue(10.0);
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(""), "10%");
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(u""), u"10%");
|
||||
EXPECT_EQ(paintProperty_->GetTextValue(""), "10%");
|
||||
progressModel.SetTextDefaultStyle(textNode, VALUE_OF_PROGRESS, MAX_VALUE_OF_PROGRESS);
|
||||
EXPECT_EQ(paintProperty_->GetTextValue(""), textLayoutProperty->GetContentValue(""));
|
||||
EXPECT_EQ(StringUtils::Str8ToStr16(paintProperty_->GetTextValue("")), textLayoutProperty->GetContentValue(u""));
|
||||
|
||||
paintProperty_->UpdateEnableShowText(false);
|
||||
progressModel.SetValue(20.0);
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(""), "");
|
||||
EXPECT_EQ(textLayoutProperty->GetContentValue(u""), u"");
|
||||
EXPECT_EQ(paintProperty_->GetTextValue(""), "");
|
||||
progressModel.SetTextDefaultStyle(textNode, VALUE_OF_PROGRESS, MAX_VALUE_OF_PROGRESS);
|
||||
EXPECT_EQ(paintProperty_->GetTextValue(""), textLayoutProperty->GetContentValue(""));
|
||||
EXPECT_EQ(StringUtils::Str8ToStr16(paintProperty_->GetTextValue("")), textLayoutProperty->GetContentValue(u""));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +82,7 @@ RefreshModelNG RefreshTestNg::CreateRefresh()
|
||||
void RefreshTestNg::CreateText()
|
||||
{
|
||||
TextModelNG model;
|
||||
model.Create("text");
|
||||
model.Create(u"text");
|
||||
ViewAbstract::SetWidth(CalcLength(REFRESH_WIDTH));
|
||||
ViewAbstract::SetHeight(CalcLength(TEXT_HEIGHT));
|
||||
ViewStackProcessor::GetInstance()->Pop();
|
||||
|
@ -135,7 +135,7 @@ HWTEST_F(RelativeContainerGuideTestNg, GuidelineTest001, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
TextModelNG textModelFirst;
|
||||
textModelFirst.Create("text1");
|
||||
textModelFirst.Create(u"text1");
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
@ -183,7 +183,7 @@ HWTEST_F(RelativeContainerGuideTestNg, GuidelineTest002, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
TextModelNG textModelFirst;
|
||||
textModelFirst.Create("text1");
|
||||
textModelFirst.Create(u"text1");
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
@ -224,7 +224,7 @@ HWTEST_F(RelativeContainerGuideTestNg, GuidelineTest003, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
TextModelNG textModelFirst;
|
||||
textModelFirst.Create("text1");
|
||||
textModelFirst.Create(u"text1");
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
@ -262,7 +262,7 @@ HWTEST_F(RelativeContainerGuideTestNg, GuidelineTest004, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
TextModelNG textModelFirst;
|
||||
textModelFirst.Create("text1");
|
||||
textModelFirst.Create(u"text1");
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
@ -302,7 +302,7 @@ HWTEST_F(RelativeContainerGuideTestNg, GuidelineTest005, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
TextModelNG textModelFirst;
|
||||
textModelFirst.Create("text1");
|
||||
textModelFirst.Create(u"text1");
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
@ -342,7 +342,7 @@ HWTEST_F(RelativeContainerGuideTestNg, GuidelineTest006, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
TextModelNG textModelFirst;
|
||||
textModelFirst.Create("text1");
|
||||
textModelFirst.Create(u"text1");
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
@ -388,7 +388,7 @@ HWTEST_F(RelativeContainerGuideTestNg, GuidelineTest007, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
TextModelNG textModelFirst;
|
||||
textModelFirst.Create("text1");
|
||||
textModelFirst.Create(u"text1");
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
@ -435,7 +435,7 @@ HWTEST_F(RelativeContainerGuideTestNg, GuidelineTest008, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
TextModelNG textModelFirst;
|
||||
textModelFirst.Create("text1");
|
||||
textModelFirst.Create(u"text1");
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
@ -482,7 +482,7 @@ HWTEST_F(RelativeContainerGuideTestNg, GuidelineTestRtl001, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
TextModelNG textModelFirst;
|
||||
textModelFirst.Create("text1");
|
||||
textModelFirst.Create(u"text1");
|
||||
ViewAbstract::SetWidth(CalcLength(ITEM_WIDTH));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
@ -534,7 +534,7 @@ HWTEST_F(RelativeContainerGuideTestNg, GuidelineTestRtl002, TestSize.Level1)
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
TextModelNG textModelFirst;
|
||||
textModelFirst.Create("text1");
|
||||
textModelFirst.Create(u"text1");
|
||||
ViewAbstract::SetWidth(CalcLength(ITEM_WIDTH));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
|
@ -125,7 +125,7 @@ void RelativeContainerTestNg::CreateInstance(const std::function<void(RelativeCo
|
||||
|
||||
void RelativeContainerTestNg::SetComponentParam(TextModelNG& textModelNG, std::string id, float width, float height)
|
||||
{
|
||||
textModelNG.Create(id);
|
||||
textModelNG.Create(StringUtils::Str8ToStr16(id));
|
||||
ViewAbstract::SetWidth(CalcLength(width));
|
||||
ViewAbstract::SetHeight(CalcLength(height));
|
||||
ViewAbstract::SetInspectorId(id);
|
||||
@ -1876,4 +1876,4 @@ HWTEST_F(RelativeContainerTestNg, BiasRulesTestRtl001, TestSize.Level1)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::NG
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -489,7 +489,7 @@ HWTEST_F(RelativeContainerNewTestNG, RelativeContainerLayoutAlgorithm013, TestSi
|
||||
ViewAbstract::SetWidth(CalcLength(CONTAINER_WIDTH));
|
||||
ViewAbstract::SetHeight(CalcLength(CONTAINER_HEIGHT));
|
||||
ViewAbstract::SetInspectorId(CONTAINER_ID);
|
||||
auto text1 = CreateText("text1", [this](TextModelNG model) {
|
||||
auto text1 = CreateText(u"text1", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text1");
|
||||
@ -498,7 +498,7 @@ HWTEST_F(RelativeContainerNewTestNG, RelativeContainerLayoutAlgorithm013, TestSi
|
||||
CONTAINER_ID, static_cast<AlignDirection>(-1), static_cast<HorizontalAlign>(-1), firstTextAlignRules);
|
||||
ViewAbstract::SetAlignRules(firstTextAlignRules);
|
||||
});
|
||||
auto text2 = CreateText("text2", [this](TextModelNG model) {
|
||||
auto text2 = CreateText(u"text2", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text2");
|
||||
@ -507,7 +507,7 @@ HWTEST_F(RelativeContainerNewTestNG, RelativeContainerLayoutAlgorithm013, TestSi
|
||||
"text1", AlignDirection::LEFT, HorizontalAlign::END, secondTextAlignRules);
|
||||
ViewAbstract::SetAlignRules(secondTextAlignRules);
|
||||
});
|
||||
auto text3 = CreateText("text3", [this](TextModelNG model) {
|
||||
auto text3 = CreateText(u"text3", [this](TextModelNG model) {
|
||||
ViewAbstract::SetWidth(CalcLength(100.0f));
|
||||
ViewAbstract::SetHeight(CalcLength(50.0f));
|
||||
ViewAbstract::SetInspectorId("text3");
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user