diff --git a/.gitignore b/.gitignore index 20f0dbd368c0053c64044756630ac006a5e46619..0b27b776ac804a4e1152d0d92f38a5b5d9c98830 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ *.iml .idea/ CMakeLists.txt -adapter/* !adapter/ohos/ !adapter/preview/ cmake-build-debug/ diff --git a/adapter/ohos/entrance/BUILD.gn b/adapter/ohos/entrance/BUILD.gn index 6dee8629b1f15c403f3c1bf9c86dec0baa627342..d9d1c6fe18ad7f9f021c462bffe090a737b6d389 100644 --- a/adapter/ohos/entrance/BUILD.gn +++ b/adapter/ohos/entrance/BUILD.gn @@ -86,6 +86,7 @@ template("ace_ohos_standard_source_set") { "$ace_flutter_engine_root/skia:ace_skia_$platform", "$ace_root/adapter/ohos/capability:ace_capability_ohos", "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//third_party/zlib:shared_libz", ] diff --git a/adapter/ohos/entrance/utils.cpp b/adapter/ohos/entrance/utils.cpp index c084a04acc25abf901c09eb203a0b53c8b1734bd..255d33718d19006ee17feb2680a8847478e6962a 100644 --- a/adapter/ohos/entrance/utils.cpp +++ b/adapter/ohos/entrance/utils.cpp @@ -99,4 +99,4 @@ RefPtr CreateAssetProvider(const std::string& packagePath, } return nullptr; } -} // namespace OHOS::Ace +} // namespace OHOS::Ace \ No newline at end of file diff --git a/adapter/ohos/entrance/utils.h b/adapter/ohos/entrance/utils.h index 9301225fa1e2136a118724439bd5190ec37f5cef..d392e79bce86e2529dffb2cd3d2f292db508cc80 100644 --- a/adapter/ohos/entrance/utils.h +++ b/adapter/ohos/entrance/utils.h @@ -48,4 +48,4 @@ inline const std::string GenerateFullPath(const std::string& prePath, const std: } } // namespace OHOS::Ace -#endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_ENTRANCE_UTILS_H +#endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_ENTRANCE_UTILS_H \ No newline at end of file diff --git a/adapter/ohos/entrance/window/drag_window_ohos.cpp b/adapter/ohos/entrance/window/drag_window_ohos.cpp index 47ca134f72a524c7608b7b60bc136edf4df6d3a2..51dd1b58b14bef4a83ef728166f5be02f762b891 100644 --- a/adapter/ohos/entrance/window/drag_window_ohos.cpp +++ b/adapter/ohos/entrance/window/drag_window_ohos.cpp @@ -15,9 +15,12 @@ #include "drag_window_ohos.h" +#include "base/log/log_wrapper.h" +#include "core/components/text/render_text.h" + +#include "rosen_text/typography.h" #include "flutter/fml/memory/ref_counted.h" #include "flutter/lib/ui/painting/image.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" #include "fml/memory/ref_ptr.h" #include "base/geometry/ng/rect_t.h" @@ -298,7 +301,7 @@ void DragWindowOhos::DrawImage(void* skImage) } void DragWindowOhos::DrawText( - std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText) + std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText) { #ifdef ENABLE_ROSEN_BACKEND CHECK_NULL_VOID(paragraph); @@ -427,4 +430,4 @@ void DragWindowOhos::DrawTextNG(const RefPtr& paragraph, const Re context->RequestFrame(); #endif } -} // namespace OHOS::Ace \ No newline at end of file +} // namespace OHOS::Ace diff --git a/adapter/ohos/entrance/window/drag_window_ohos.h b/adapter/ohos/entrance/window/drag_window_ohos.h index 648d2b057c128277b5bb4070964d4a1dc04aedab..d9303989d183f4423e729163bba836e331f74c00 100644 --- a/adapter/ohos/entrance/window/drag_window_ohos.h +++ b/adapter/ohos/entrance/window/drag_window_ohos.h @@ -40,8 +40,8 @@ public: void DrawPixelMap(const RefPtr& pixelMap) override; void DrawFrameNode(const RefPtr& rootNode) override; void DrawImage(void* skImage) override; - void DrawText( - std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText) override; + void DrawText(std::shared_ptr paragraph, + const Offset& offset, const RefPtr& renderText) override; void DrawTextNG(const RefPtr& paragraph, const RefPtr& textPattern) override; private: diff --git a/frameworks/base/window/drag_window.h b/frameworks/base/window/drag_window.h index 7e568caabd0eaf71871e9f888e48fb12ed3514b3..badab190a91e07c2a0cdb58a11e0d1a04f297311 100644 --- a/frameworks/base/window/drag_window.h +++ b/frameworks/base/window/drag_window.h @@ -20,8 +20,8 @@ #include "base/image/pixel_map.h" #include "base/memory/ace_type.h" -namespace txt { -class Paragraph; +namespace OHOS::Rosen { +class Typography; } namespace OHOS::Ace { @@ -50,7 +50,7 @@ public: virtual void DrawFrameNode(const RefPtr& rootNode) = 0; virtual void DrawImage(void* skImage) = 0; virtual void DrawText( - std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText) = 0; + std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText) = 0; virtual void DrawTextNG(const RefPtr& paragraph, const RefPtr& textPattern) = 0; void SetOffset(int32_t offsetX, int32_t offsetY) diff --git a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp index 447ebc6a081493d77faa19b8cfb7e55260f9b285..f546e675b90684e53d58f0385aaa371792e0ee76 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp @@ -144,7 +144,7 @@ bool ArkJSRuntime::EvaluateJsCode(const uint8_t* buffer, int32_t size, const std { JSExecutionScope executionScope(vm_); LocalScope scope(vm_); - bool ret = JSNApi::Execute(vm_, buffer, size, PANDA_MAIN_FUNCTION, filePath, needUpdate); + bool ret = JSNApi::Execute(vm_, buffer, size, PANDA_MAIN_FUNCTION, filePath); HandleUncaughtException(); return ret; } diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 5a2a5e1d2e68810ee1335166b592d106486cfbf8..04050f4aec3db551740c1918c39b7ab8c1abdc18 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -357,6 +357,7 @@ template("ace_core_source_set") { ] deps += [ "$ace_root/frameworks/core/components_part_upd/foreach:ace_core_components_foreach_part_upd_$platform" ] + deps += [ "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text" ] deps += [ "$ace_root/frameworks/core/components_ng/animation:ace_core_components_animation_ng_$platform", diff --git a/frameworks/core/components/calendar/flutter_render_calendar.cpp b/frameworks/core/components/calendar/flutter_render_calendar.cpp index 21301464da3cbff320ab159aa820f67d51895043..b3933a5044255927726bd242d407bbfaf116c027 100644 --- a/frameworks/core/components/calendar/flutter_render_calendar.cpp +++ b/frameworks/core/components/calendar/flutter_render_calendar.cpp @@ -15,8 +15,7 @@ #include "core/components/calendar/flutter_render_calendar.h" -#include "flutter/lib/ui/text/font_collection.h" -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "base/i18n/localization.h" #include "base/utils/string_utils.h" @@ -37,22 +36,22 @@ constexpr double WEEKEND_TRANSPARENT = 0x7D; constexpr double SCHEDULE_MARKER_TRANSPARENT = 0x4B; constexpr Dimension CARD_CALENDAR_TITLE_HEIGHT = 68.0_vp; -std::unique_ptr GetTextParagraph(const std::string& text, const txt::TextStyle& textStyle) +std::unique_ptr GetTextParagraph(const std::string& text, const Rosen::TextStyle& textStyle) { - txt::ParagraphStyle style; + Rosen::TypographyStyle style; auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return nullptr; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); builder->PushStyle(textStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - return builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + return builder->CreateTypography(); } void DrawCalendarText( - ScopedCanvas& canvas, const std::string& text, const txt::TextStyle& textStyle, const Rect& boxRect, Rect& textRect) + ScopedCanvas& canvas, const std::string& text, const Rosen::TextStyle& textStyle, const Rect& boxRect, Rect& textRect) { // The lunar calendar description is truncated by more than three characters. std::string newText { text }; @@ -79,7 +78,7 @@ void DrawCalendarText( } void DrawCalendarText( - ScopedCanvas& canvas, const std::string& text, const txt::TextStyle& textStyle, const Rect& boxRect) + ScopedCanvas& canvas, const std::string& text, const Rosen::TextStyle& textStyle, const Rect& boxRect) { Rect textRect; DrawCalendarText(canvas, text, textStyle, boxRect, textRect); @@ -281,13 +280,13 @@ void FlutterRenderCalendar::DrawFocusedArea( void FlutterRenderCalendar::DrawWeek(ScopedCanvas& canvas, const Offset& offset) const { uint32_t totalWeek = weekNumbers_.size(); - txt::TextStyle weekTextStyle; - weekTextStyle.color = weekColor_; - weekTextStyle.font_size = weekFontSize_; + Rosen::TextStyle weekTextStyle; + weekTextStyle.color_ = weekColor_; + weekTextStyle.fontSize_ = weekFontSize_; if (cardCalendar_) { - weekTextStyle.font_weight = static_cast(FontWeight::W500); + weekTextStyle.fontWeight_ = static_cast(FontWeight::W500); } - weekTextStyle.locale = Localization::GetInstance()->GetFontLocale(); + weekTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); static const int32_t daysOfWeek = 7; auto startDayOfWeek = dataAdapter_->GetStartDayOfWeek(); for (uint32_t column = 0; column < totalWeek; column++) { @@ -325,25 +324,25 @@ void FlutterRenderCalendar::DrawBlurArea(ScopedCanvas& canvas, const Offset& off } void FlutterRenderCalendar::PaintDay( - ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, txt::TextStyle& textStyle) const + ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, Rosen::TextStyle& textStyle) const { // paint day Rect boxRect { offset.GetX(), offset.GetY(), dayWidth_, gregorianCalendarHeight_ }; Rect textRect; - txt::TextStyle workStateStyle; + Rosen::TextStyle workStateStyle; if (!day.dayMark.empty() && showHoliday_ && type_ == CalendarType::SIMPLE) { if (day.dayMark == "work") { - textStyle.color = SkColor(calendarTheme_.simpleWorkTextColor.GetValue()); + textStyle.color_ = SkColor(calendarTheme_.simpleWorkTextColor.GetValue()); } else if (day.dayMark == "off") { - textStyle.color = SkColor(calendarTheme_.simpleOffTextColor.GetValue()); + textStyle.color_ = SkColor(calendarTheme_.simpleOffTextColor.GetValue()); } } if ((SystemProperties::GetDeviceType() == DeviceType::WATCH || type_ == CalendarType::SIMPLE) && IsToday(day) && !day.dayMark.empty() && showHoliday_) { auto workStateOffset = offset + Offset(0, NormalizeToPx(calendarTheme_.workStateOffset)); boxRect.SetOffset(workStateOffset); - workStateStyle.color = Color::WHITE.GetValue(); - workStateStyle.font_size = dayFontSize_; + workStateStyle.color_ = Color::WHITE.GetValue(); + workStateStyle.fontSize_ = dayFontSize_; DrawCalendarText(canvas, day.dayMarkValue, workStateStyle, boxRect, textRect); return; } @@ -359,35 +358,35 @@ void FlutterRenderCalendar::PaintDay( if (cardCalendar_) { InitWorkStateStyle(day, offset, workStateStyle, boxRect); } else { - workStateStyle.font_weight = static_cast(workStateFontWeight_); - workStateStyle.locale = Localization::GetInstance()->GetFontLocale(); + workStateStyle.fontWeight_ = static_cast(workStateFontWeight_); + workStateStyle.locale_ = Localization::GetInstance()->GetFontLocale(); boxRect = { textRect.GetOffset().GetX() + textRect.Width() - workStateHorizontalMovingDistance_, textRect.GetOffset().GetY() + textRect.Height() - workStateVerticalMovingDistance_, workStateWidth_, workStateWidth_ }; if (day.month.month == currentMonth_.month) { if (day.dayMark == "work") { - workStateStyle.font_size = workDayMarkSize_; - workStateStyle.color = workDayMarkColor_; + workStateStyle.fontSize_ = workDayMarkSize_; + workStateStyle.color_ = workDayMarkColor_; } else if (day.dayMark == "off") { - workStateStyle.font_size = offDayMarkSize_; - workStateStyle.color = offDayMarkColor_; + workStateStyle.fontSize_ = offDayMarkSize_; + workStateStyle.color_ = offDayMarkColor_; } } else { if (day.dayMark == "work") { - workStateStyle.font_size = workDayMarkSize_; - workStateStyle.color = isV2Component_ ? SkColorSetA(workDayMarkColor_, WEEKEND_TRANSPARENT) + workStateStyle.fontSize_ = workDayMarkSize_; + workStateStyle.color_ = isV2Component_ ? SkColorSetA(workDayMarkColor_, WEEKEND_TRANSPARENT) : nonCurrentMonthWorkDayMarkColor_; } else if (day.dayMark == "off") { - workStateStyle.font_size = offDayMarkSize_; - workStateStyle.color = isV2Component_ ? SkColorSetA(offDayMarkColor_, WEEKEND_TRANSPARENT) + workStateStyle.fontSize_ = offDayMarkSize_; + workStateStyle.color_ = isV2Component_ ? SkColorSetA(offDayMarkColor_, WEEKEND_TRANSPARENT) : nonCurrentMonthOffDayMarkColor_; } } if (day.focused) { - workStateStyle.color = Color::BLACK.GetValue(); + workStateStyle.color_ = Color::BLACK.GetValue(); } if (isV2Component_ && IsToday(day) && day.touched) { - workStateStyle.color = focusedDayColor_; + workStateStyle.color_ = focusedDayColor_; } } DrawCalendarText(canvas, day.dayMarkValue, workStateStyle, boxRect); @@ -395,7 +394,7 @@ void FlutterRenderCalendar::PaintDay( } void FlutterRenderCalendar::PaintLunarDay( - ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, const txt::TextStyle& textStyle) const + ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, const Rosen::TextStyle& textStyle) const { Rect boxRect; cardCalendar_ || isV2Component_ @@ -405,7 +404,7 @@ void FlutterRenderCalendar::PaintLunarDay( } void FlutterRenderCalendar::SetNonFocusStyle( - const CalendarDay& day, txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle) + const CalendarDay& day, Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle) { SkColor dateTextColor; SkColor lunarTextColor; @@ -425,8 +424,8 @@ void FlutterRenderCalendar::SetNonFocusStyle( lunarTextColor = day.markLunarDay ? markLunarColor_ : lunarColor_; } - dateTextStyle.color = dateTextColor; - lunarTextStyle.color = lunarTextColor; + dateTextStyle.color_ = dateTextColor; + lunarTextStyle.color_ = lunarTextColor; } void FlutterRenderCalendar::DrawTouchedArea(RenderContext& context, Offset offset) const @@ -464,11 +463,11 @@ void FlutterRenderCalendar::DrawTouchedArea(RenderContext& context, Offset offse void FlutterRenderCalendar::DrawCardCalendar( ScopedCanvas& canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber) { - txt::TextStyle dateTextStyle; - txt::TextStyle lunarTextStyle; + Rosen::TextStyle dateTextStyle; + Rosen::TextStyle lunarTextStyle; InitTextStyle(dateTextStyle, lunarTextStyle); SetNonFocusStyle(day, dateTextStyle, lunarTextStyle); - dateTextStyle.locale = Localization::GetInstance()->GetFontLocale(); + dateTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); auto x = dayOffset.GetX(); auto y = dayOffset.GetY(); if (isV2Component_) { @@ -479,8 +478,8 @@ void FlutterRenderCalendar::DrawCardCalendar( } } if (IsToday(day) && (day.month.month == currentMonth_.month)) { - dateTextStyle.color = isV2Component_ ? focusedAreaBackgroundColor_ : focusedDayColor_; - lunarTextStyle.color = isV2Component_ ? focusedAreaBackgroundColor_ : focusedDayColor_; + dateTextStyle.color_ = isV2Component_ ? focusedAreaBackgroundColor_ : focusedDayColor_; + lunarTextStyle.color_ = isV2Component_ ? focusedAreaBackgroundColor_ : focusedDayColor_; if (!isV2Component_) { DrawFocusedArea(canvas, offset, day, x, y); } @@ -488,8 +487,8 @@ void FlutterRenderCalendar::DrawCardCalendar( if (isV2Component_ && day.touched) { if (IsToday(day) && (day.month.month == currentMonth_.month)) { - dateTextStyle.color = focusedDayColor_; - lunarTextStyle.color = focusedDayColor_; + dateTextStyle.color_ = focusedDayColor_; + lunarTextStyle.color_ = focusedDayColor_; DrawFocusedArea(canvas, offset, day, x, y); } } @@ -534,11 +533,11 @@ void FlutterRenderCalendar::DrawTvCalendar( day.month.month != currentMonth_.month) { return; } - txt::TextStyle dateTextStyle; - txt::TextStyle lunarTextStyle; + Rosen::TextStyle dateTextStyle; + Rosen::TextStyle lunarTextStyle; InitTextStyle(dateTextStyle, lunarTextStyle); - dateTextStyle.locale = Localization::GetInstance()->GetFontLocale(); - lunarTextStyle.locale = Localization::GetInstance()->GetFontLocale(); + dateTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); + lunarTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); auto renderSwiper = calendarController_->GetRenderSwiper(); if (!renderSwiper) { @@ -549,8 +548,8 @@ void FlutterRenderCalendar::DrawTvCalendar( auto y = dayOffset.GetY(); if (SystemProperties::GetDeviceType() == DeviceType::WATCH || type_ == CalendarType::SIMPLE) { if (IsToday(day) && (day.month.month == currentMonth_.month)) { - dateTextStyle.color = focusedDayColor_; - lunarTextStyle.color = focusedDayColor_; + dateTextStyle.color_ = focusedDayColor_; + lunarTextStyle.color_ = focusedDayColor_; DrawFocusedArea(canvas, offset, day, x, y); } else { SetNonFocusStyle(day, dateTextStyle, lunarTextStyle); @@ -558,8 +557,8 @@ void FlutterRenderCalendar::DrawTvCalendar( } else { if (day.focused && day.month.month == currentMonth_.month && !renderSwiper->GetMoveStatus() && indexOfContainer_ == calendarController_->GetCurrentIndex()) { - dateTextStyle.color = focusedDayColor_; - lunarTextStyle.color = focusedLunarColor_; + dateTextStyle.color_ = focusedDayColor_; + lunarTextStyle.color_ = focusedLunarColor_; DrawFocusedArea(canvas, offset, day, x, y); } else { SetNonFocusStyle(day, dateTextStyle, lunarTextStyle); @@ -586,13 +585,13 @@ void FlutterRenderCalendar::DrawTvCalendar( } } -void FlutterRenderCalendar::InitTextStyle(txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle) +void FlutterRenderCalendar::InitTextStyle(Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle) { - dateTextStyle.font_size = dayFontSize_; - dateTextStyle.font_weight = static_cast(dayFontWeight_); + dateTextStyle.fontSize_ = dayFontSize_; + dateTextStyle.fontWeight_ = static_cast(dayFontWeight_); - lunarTextStyle.font_size = lunarDayFontSize_; - lunarTextStyle.font_weight = static_cast(lunarDayFontWeight_); + lunarTextStyle.fontSize_ = lunarDayFontSize_; + lunarTextStyle.fontWeight_ = static_cast(lunarDayFontWeight_); } void FlutterRenderCalendar::PaintUnderscore(ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day) @@ -645,10 +644,10 @@ void FlutterRenderCalendar::PaintScheduleMarker(ScopedCanvas& canvas, const Offs } void FlutterRenderCalendar::InitWorkStateStyle( - const CalendarDay& day, const Offset& offset, txt::TextStyle& workStateStyle, Rect& boxRect) const + const CalendarDay& day, const Offset& offset, Rosen::TextStyle& workStateStyle, Rect& boxRect) const { - workStateStyle.font_weight = static_cast(FontWeight::W500); - workStateStyle.locale = Localization::GetInstance()->GetFontLocale(); + workStateStyle.fontWeight_ = static_cast(FontWeight::W500); + workStateStyle.locale_ = Localization::GetInstance()->GetFontLocale(); static const Dimension workStateWidth = 8.0_vp; static const int32_t twoDigitMaker = 10; static const Dimension OneDigitXAxisOffset = 26.0_vp; @@ -664,7 +663,7 @@ void FlutterRenderCalendar::InitWorkStateStyle( NormalizeToPx(workStateWidth) }; } - workStateStyle.font_size = NormalizeToPx(workStateWidth); + workStateStyle.fontSize_ = NormalizeToPx(workStateWidth); if (day.month.month != currentMonth_.month) { auto offColor = SkColorSetA(markLunarColor_, WEEKEND_TRANSPARENT); @@ -682,12 +681,12 @@ void FlutterRenderCalendar::InitWorkStateStyle( } void FlutterRenderCalendar::SetWorkStateStyle( - const CalendarDay& day, SkColor workColor, SkColor offColor, txt::TextStyle& workStateStyle) const + const CalendarDay& day, SkColor workColor, SkColor offColor, Rosen::TextStyle& workStateStyle) const { if (day.dayMark == "work") { - workStateStyle.color = workColor; + workStateStyle.color_ = workColor; } else if (day.dayMark == "off") { - workStateStyle.color = offColor; + workStateStyle.color_ = offColor; } } diff --git a/frameworks/core/components/calendar/flutter_render_calendar.h b/frameworks/core/components/calendar/flutter_render_calendar.h index cd39478c553df5a5f3211d5dcba0bc3627337e17..16d178761c3671b8fac351f1ccad49e1e23fd063 100644 --- a/frameworks/core/components/calendar/flutter_render_calendar.h +++ b/frameworks/core/components/calendar/flutter_render_calendar.h @@ -17,7 +17,7 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_FLUTTER_RENDER_CALENDAR_H #include "third_party/skia/include/core/SkColor.h" -#include "third_party/txt/src/txt/text_style.h" +#include "rosen_text/text_style.h" #include "core/components/calendar/render_calendar.h" #include "core/pipeline/layers/clip_layer.h" @@ -46,21 +46,21 @@ private: void DrawBlurArea(ScopedCanvas& canvas, const Offset& offset, double x, double y) const; void DrawTouchedArea(RenderContext& context, Offset offset) const; void PaintDay( - ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, txt::TextStyle& textStyle) const; + ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, Rosen::TextStyle& textStyle) const; void PaintLunarDay( - ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, const txt::TextStyle& textStyle) const; - void SetNonFocusStyle(const CalendarDay& day, txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle); + ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, const Rosen::TextStyle& textStyle) const; + void SetNonFocusStyle(const CalendarDay& day, Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle); void DrawCardCalendar(ScopedCanvas& canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber); void DrawTvCalendar(ScopedCanvas& canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber); - void InitTextStyle(txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle); + void InitTextStyle(Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle); void PaintUnderscore(ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day); void PaintScheduleMarker(ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day); void InitWorkStateStyle( - const CalendarDay& day, const Offset& offset, txt::TextStyle& workStateStyle, Rect& boxRect) const; + const CalendarDay& day, const Offset& offset, Rosen::TextStyle& workStateStyle, Rect& boxRect) const; void SetWorkStateStyle( - const CalendarDay& day, SkColor workColor, SkColor offColor, txt::TextStyle& workStateStyle) const; + const CalendarDay& day, SkColor workColor, SkColor offColor, Rosen::TextStyle& workStateStyle) const; void SetCalendarTheme(); bool IsOffDay(const CalendarDay& day) const; void AddContentLayer(); diff --git a/frameworks/core/components/calendar/rosen_render_calendar.cpp b/frameworks/core/components/calendar/rosen_render_calendar.cpp index e51f4ee2dcd4da8bf28cb56b15fe21417c769fbc..546af69e88ababa1b8ae4ed2bbbe00fa6415b38c 100644 --- a/frameworks/core/components/calendar/rosen_render_calendar.cpp +++ b/frameworks/core/components/calendar/rosen_render_calendar.cpp @@ -15,8 +15,7 @@ #include "core/components/calendar/rosen_render_calendar.h" -#include "flutter/lib/ui/text/font_collection.h" -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "render_service_client/core/ui/rs_node.h" #include "base/i18n/localization.h" @@ -37,22 +36,22 @@ constexpr double WEEKEND_TRANSPARENT = 0x7D; constexpr double SCHEDULE_MARKER_TRANSPARENT = 0x4B; constexpr Dimension CARD_CALENDAR_TITLE_HEIGHT = 68.0_vp; -std::unique_ptr GetTextParagraph(const std::string& text, const txt::TextStyle& textStyle) +std::unique_ptr GetTextParagraph(const std::string& text, const Rosen::TextStyle& textStyle) { - txt::ParagraphStyle style; + Rosen::TypographyStyle style; auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return nullptr; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); builder->PushStyle(textStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - return builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + return builder->CreateTypography(); } void DrawCalendarText( - SkCanvas* canvas, const std::string& text, const txt::TextStyle& textStyle, const Rect& boxRect, Rect& textRect) + SkCanvas* canvas, const std::string& text, const Rosen::TextStyle& textStyle, const Rect& boxRect, Rect& textRect) { // The lunar calendar description is truncated by more than three characters. std::string newText { text }; @@ -78,7 +77,7 @@ void DrawCalendarText( textRect.SetRect(offset.GetX() + textPaintOffsetX, offset.GetY() + textPaintOffsetY, textWidth, textHeight); } -void DrawCalendarText(SkCanvas* canvas, const std::string& text, const txt::TextStyle& textStyle, const Rect& boxRect) +void DrawCalendarText(SkCanvas* canvas, const std::string& text, const Rosen::TextStyle& textStyle, const Rect& boxRect) { Rect textRect; DrawCalendarText(canvas, text, textStyle, boxRect, textRect); @@ -268,13 +267,13 @@ void RosenRenderCalendar::DrawFocusedArea( void RosenRenderCalendar::DrawWeek(SkCanvas* canvas, const Offset& offset) const { uint32_t totalWeek = weekNumbers_.size(); - txt::TextStyle weekTextStyle; - weekTextStyle.color = weekColor_; - weekTextStyle.font_size = weekFontSize_; + Rosen::TextStyle weekTextStyle; + weekTextStyle.color_ = weekColor_; + weekTextStyle.fontSize_ = weekFontSize_; if (cardCalendar_) { - weekTextStyle.font_weight = static_cast(FontWeight::W500); + weekTextStyle.fontWeight_ = static_cast(FontWeight::W500); } - weekTextStyle.locale = Localization::GetInstance()->GetFontLocale(); + weekTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); static const int32_t daysOfWeek = 7; auto startDayOfWeek = dataAdapter_->GetStartDayOfWeek(); for (uint32_t column = 0; column < totalWeek; column++) { @@ -311,25 +310,25 @@ void RosenRenderCalendar::DrawBlurArea(SkCanvas* canvas, const Offset& offset, d } void RosenRenderCalendar::PaintDay( - SkCanvas* canvas, const Offset& offset, const CalendarDay& day, txt::TextStyle& textStyle) const + SkCanvas* canvas, const Offset& offset, const CalendarDay& day, Rosen::TextStyle& textStyle) const { // paint day Rect boxRect { offset.GetX(), offset.GetY(), dayWidth_, gregorianCalendarHeight_ }; Rect textRect; - txt::TextStyle workStateStyle; + Rosen::TextStyle workStateStyle; if (!day.dayMark.empty() && showHoliday_ && type_ == CalendarType::SIMPLE) { if (day.dayMark == "work") { - textStyle.color = SkColor(calendarTheme_.simpleWorkTextColor.GetValue()); + textStyle.color_ = SkColor(calendarTheme_.simpleWorkTextColor.GetValue()); } else if (day.dayMark == "off") { - textStyle.color = SkColor(calendarTheme_.simpleOffTextColor.GetValue()); + textStyle.color_ = SkColor(calendarTheme_.simpleOffTextColor.GetValue()); } } if ((SystemProperties::GetDeviceType() == DeviceType::WATCH || type_ == CalendarType::SIMPLE) && IsToday(day) && !day.dayMark.empty() && showHoliday_) { auto workStateOffset = offset + Offset(0, NormalizeToPx(calendarTheme_.workStateOffset)); boxRect.SetOffset(workStateOffset); - workStateStyle.color = Color::WHITE.GetValue(); - workStateStyle.font_size = dayFontSize_; + workStateStyle.color_ = Color::WHITE.GetValue(); + workStateStyle.fontSize_ = dayFontSize_; DrawCalendarText(canvas, day.dayMarkValue, workStateStyle, boxRect, textRect); return; } @@ -345,35 +344,35 @@ void RosenRenderCalendar::PaintDay( if (cardCalendar_) { InitWorkStateStyle(day, offset, workStateStyle, boxRect); } else { - workStateStyle.font_weight = static_cast(workStateFontWeight_); - workStateStyle.locale = Localization::GetInstance()->GetFontLocale(); + workStateStyle.fontWeight_ = static_cast(workStateFontWeight_); + workStateStyle.locale_ = Localization::GetInstance()->GetFontLocale(); boxRect = { textRect.GetOffset().GetX() + textRect.Width() - workStateHorizontalMovingDistance_, textRect.GetOffset().GetY() + textRect.Height() - workStateVerticalMovingDistance_, workStateWidth_, workStateWidth_ }; if (day.month.month == currentMonth_.month) { if (day.dayMark == "work") { - workStateStyle.font_size = workDayMarkSize_; - workStateStyle.color = workDayMarkColor_; + workStateStyle.fontSize_ = workDayMarkSize_; + workStateStyle.color_ = workDayMarkColor_; } else if (day.dayMark == "off") { - workStateStyle.font_size = offDayMarkSize_; - workStateStyle.color = offDayMarkColor_; + workStateStyle.fontSize_ = offDayMarkSize_; + workStateStyle.color_ = offDayMarkColor_; } } else { if (day.dayMark == "work") { - workStateStyle.font_size = workDayMarkSize_; - workStateStyle.color = isV2Component_ ? SkColorSetA(workDayMarkColor_, WEEKEND_TRANSPARENT) + workStateStyle.fontSize_ = workDayMarkSize_; + workStateStyle.color_ = isV2Component_ ? SkColorSetA(workDayMarkColor_, WEEKEND_TRANSPARENT) : nonCurrentMonthWorkDayMarkColor_; } else if (day.dayMark == "off") { - workStateStyle.font_size = offDayMarkSize_; - workStateStyle.color = isV2Component_ ? SkColorSetA(offDayMarkColor_, WEEKEND_TRANSPARENT) + workStateStyle.fontSize_ = offDayMarkSize_; + workStateStyle.color_ = isV2Component_ ? SkColorSetA(offDayMarkColor_, WEEKEND_TRANSPARENT) : nonCurrentMonthOffDayMarkColor_; } } if (day.focused) { - workStateStyle.color = Color::BLACK.GetValue(); + workStateStyle.color_ = Color::BLACK.GetValue(); } if (isV2Component_ && IsToday(day) && day.touched) { - workStateStyle.color = focusedDayColor_; + workStateStyle.color_ = focusedDayColor_; } } DrawCalendarText(canvas, day.dayMarkValue, workStateStyle, boxRect); @@ -381,7 +380,7 @@ void RosenRenderCalendar::PaintDay( } void RosenRenderCalendar::PaintLunarDay( - SkCanvas* canvas, const Offset& offset, const CalendarDay& day, const txt::TextStyle& textStyle) const + SkCanvas* canvas, const Offset& offset, const CalendarDay& day, const Rosen::TextStyle& textStyle) const { Rect boxRect; cardCalendar_ || isV2Component_ @@ -391,7 +390,7 @@ void RosenRenderCalendar::PaintLunarDay( } void RosenRenderCalendar::SetNonFocusStyle( - const CalendarDay& day, txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle) + const CalendarDay& day, Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle) { SkColor dateTextColor; SkColor lunarTextColor; @@ -410,8 +409,8 @@ void RosenRenderCalendar::SetNonFocusStyle( lunarTextColor = day.markLunarDay ? markLunarColor_ : lunarColor_; } - dateTextStyle.color = dateTextColor; - lunarTextStyle.color = lunarTextColor; + dateTextStyle.color_ = dateTextColor; + lunarTextStyle.color_ = lunarTextColor; } void RosenRenderCalendar::DrawTouchedArea(RenderContext& context, Offset offset) const @@ -447,11 +446,11 @@ void RosenRenderCalendar::DrawTouchedArea(RenderContext& context, Offset offset) void RosenRenderCalendar::DrawCardCalendar( SkCanvas* canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber) { - txt::TextStyle dateTextStyle; - txt::TextStyle lunarTextStyle; + Rosen::TextStyle dateTextStyle; + Rosen::TextStyle lunarTextStyle; InitTextStyle(dateTextStyle, lunarTextStyle); SetNonFocusStyle(day, dateTextStyle, lunarTextStyle); - dateTextStyle.locale = Localization::GetInstance()->GetFontLocale(); + dateTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); auto x = dayOffset.GetX(); auto y = dayOffset.GetY(); if (isV2Component_) { @@ -462,8 +461,8 @@ void RosenRenderCalendar::DrawCardCalendar( } } if (IsToday(day) && (day.month.month == currentMonth_.month)) { - dateTextStyle.color = isV2Component_ ? focusedAreaBackgroundColor_ : focusedDayColor_; - lunarTextStyle.color = isV2Component_ ? focusedAreaBackgroundColor_ : focusedDayColor_; + dateTextStyle.color_ = isV2Component_ ? focusedAreaBackgroundColor_ : focusedDayColor_; + lunarTextStyle.color_ = isV2Component_ ? focusedAreaBackgroundColor_ : focusedDayColor_; if (!isV2Component_) { DrawFocusedArea(canvas, offset, day, x, y); } @@ -471,8 +470,8 @@ void RosenRenderCalendar::DrawCardCalendar( if (isV2Component_ && day.touched) { if (IsToday(day) && (day.month.month == currentMonth_.month)) { - dateTextStyle.color = focusedDayColor_; - lunarTextStyle.color = focusedDayColor_; + dateTextStyle.color_ = focusedDayColor_; + lunarTextStyle.color_ = focusedDayColor_; DrawFocusedArea(canvas, offset, day, x, y); } } @@ -517,11 +516,11 @@ void RosenRenderCalendar::DrawTvCalendar( day.month.month != currentMonth_.month) { return; } - txt::TextStyle dateTextStyle; - txt::TextStyle lunarTextStyle; + Rosen::TextStyle dateTextStyle; + Rosen::TextStyle lunarTextStyle; InitTextStyle(dateTextStyle, lunarTextStyle); - dateTextStyle.locale = Localization::GetInstance()->GetFontLocale(); - lunarTextStyle.locale = Localization::GetInstance()->GetFontLocale(); + dateTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); + lunarTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); auto renderSwiper = calendarController_->GetRenderSwiper(); if (!renderSwiper) { @@ -532,8 +531,8 @@ void RosenRenderCalendar::DrawTvCalendar( auto y = dayOffset.GetY(); if (SystemProperties::GetDeviceType() == DeviceType::WATCH || type_ == CalendarType::SIMPLE) { if (IsToday(day) && (day.month.month == currentMonth_.month)) { - dateTextStyle.color = focusedDayColor_; - lunarTextStyle.color = focusedDayColor_; + dateTextStyle.color_ = focusedDayColor_; + lunarTextStyle.color_ = focusedDayColor_; DrawFocusedArea(canvas, offset, day, x, y); } else { SetNonFocusStyle(day, dateTextStyle, lunarTextStyle); @@ -541,8 +540,8 @@ void RosenRenderCalendar::DrawTvCalendar( } else { if (day.focused && day.month.month == currentMonth_.month && !renderSwiper->GetMoveStatus() && indexOfContainer_ == calendarController_->GetCurrentIndex()) { - dateTextStyle.color = focusedDayColor_; - lunarTextStyle.color = focusedLunarColor_; + dateTextStyle.color_ = focusedDayColor_; + lunarTextStyle.color_ = focusedLunarColor_; DrawFocusedArea(canvas, offset, day, x, y); } else { SetNonFocusStyle(day, dateTextStyle, lunarTextStyle); @@ -569,13 +568,13 @@ void RosenRenderCalendar::DrawTvCalendar( } } -void RosenRenderCalendar::InitTextStyle(txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle) +void RosenRenderCalendar::InitTextStyle(Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle) { - dateTextStyle.font_size = dayFontSize_; - dateTextStyle.font_weight = static_cast(dayFontWeight_); + dateTextStyle.fontSize_ = dayFontSize_; + dateTextStyle.fontWeight_ = static_cast(dayFontWeight_); - lunarTextStyle.font_size = lunarDayFontSize_; - lunarTextStyle.font_weight = static_cast(lunarDayFontWeight_); + lunarTextStyle.fontSize_ = lunarDayFontSize_; + lunarTextStyle.fontWeight_ = static_cast(lunarDayFontWeight_); } void RosenRenderCalendar::PaintUnderscore(SkCanvas* canvas, const Offset& offset, const CalendarDay& day) @@ -621,10 +620,10 @@ void RosenRenderCalendar::PaintScheduleMarker(SkCanvas* canvas, const Offset& of } void RosenRenderCalendar::InitWorkStateStyle( - const CalendarDay& day, const Offset& offset, txt::TextStyle& workStateStyle, Rect& boxRect) const + const CalendarDay& day, const Offset& offset, Rosen::TextStyle& workStateStyle, Rect& boxRect) const { - workStateStyle.font_weight = static_cast(FontWeight::W500); - workStateStyle.locale = Localization::GetInstance()->GetFontLocale(); + workStateStyle.fontWeight_ = static_cast(FontWeight::W500); + workStateStyle.locale_ = Localization::GetInstance()->GetFontLocale(); static const Dimension workStateWidth = 8.0_vp; static const int32_t twoDigitMaker = 10; static const Dimension OneDigitXAxisOffset = 26.0_vp; @@ -640,7 +639,7 @@ void RosenRenderCalendar::InitWorkStateStyle( NormalizeToPx(workStateWidth) }; } - workStateStyle.font_size = NormalizeToPx(workStateWidth); + workStateStyle.fontSize_ = NormalizeToPx(workStateWidth); if (day.month.month != currentMonth_.month) { auto offColor = SkColorSetA(markLunarColor_, WEEKEND_TRANSPARENT); @@ -658,12 +657,12 @@ void RosenRenderCalendar::InitWorkStateStyle( } void RosenRenderCalendar::SetWorkStateStyle( - const CalendarDay& day, SkColor workColor, SkColor offColor, txt::TextStyle& workStateStyle) const + const CalendarDay& day, SkColor workColor, SkColor offColor, Rosen::TextStyle& workStateStyle) const { if (day.dayMark == "work") { - workStateStyle.color = workColor; + workStateStyle.color_ = workColor; } else if (day.dayMark == "off") { - workStateStyle.color = offColor; + workStateStyle.color_ = offColor; } } diff --git a/frameworks/core/components/calendar/rosen_render_calendar.h b/frameworks/core/components/calendar/rosen_render_calendar.h index e98e63b752ba50a134e25fcd9a2cb03b2edfaca5..f6c6cc0ef036ab74d031deff598262e945e632e4 100644 --- a/frameworks/core/components/calendar/rosen_render_calendar.h +++ b/frameworks/core/components/calendar/rosen_render_calendar.h @@ -18,7 +18,8 @@ #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColor.h" -#include "third_party/txt/src/txt/text_style.h" +#include "rosen_text/text_style.h" +#include "rosen_text/text_style.h" #include "core/components/calendar/render_calendar.h" @@ -46,21 +47,21 @@ private: void DrawWeek(SkCanvas* canvas, const Offset& offset) const; void DrawBlurArea(SkCanvas* canvas, const Offset& offset, double x, double y) const; void DrawTouchedArea(RenderContext& context, Offset offset) const; - void PaintDay(SkCanvas* canvas, const Offset& offset, const CalendarDay& day, txt::TextStyle& textStyle) const; + void PaintDay(SkCanvas* canvas, const Offset& offset, const CalendarDay& day, Rosen::TextStyle& textStyle) const; void PaintLunarDay( - SkCanvas* canvas, const Offset& offset, const CalendarDay& day, const txt::TextStyle& textStyle) const; - void SetNonFocusStyle(const CalendarDay& day, txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle); + SkCanvas* canvas, const Offset& offset, const CalendarDay& day, const Rosen::TextStyle& textStyle) const; + void SetNonFocusStyle(const CalendarDay& day, Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle); void DrawCardCalendar( SkCanvas* canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber); void DrawTvCalendar( SkCanvas* canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber); - void InitTextStyle(txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle); + void InitTextStyle(Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle); void PaintUnderscore(SkCanvas* canvas, const Offset& offset, const CalendarDay& day); void PaintScheduleMarker(SkCanvas* canvas, const Offset& offset, const CalendarDay& day); void InitWorkStateStyle( - const CalendarDay& day, const Offset& offset, txt::TextStyle& workStateStyle, Rect& boxRect) const; + const CalendarDay& day, const Offset& offset, Rosen::TextStyle& workStateStyle, Rect& boxRect) const; void SetWorkStateStyle( - const CalendarDay& day, SkColor workColor, SkColor offColor, txt::TextStyle& workStateStyle) const; + const CalendarDay& day, SkColor workColor, SkColor offColor, Rosen::TextStyle& workStateStyle) const; void SetCalendarTheme(); bool IsOffDay(const CalendarDay& day) const; void AddContentLayer(RenderContext& context); diff --git a/frameworks/core/components/chart/flutter_render_chart.cpp b/frameworks/core/components/chart/flutter_render_chart.cpp index 32884cc938a3a58c18e018ef11cec3d5b372bc85..c565f51b1959a0fbc091acd74f4a525cdaf19962 100644 --- a/frameworks/core/components/chart/flutter_render_chart.cpp +++ b/frameworks/core/components/chart/flutter_render_chart.cpp @@ -17,7 +17,7 @@ #include "flutter/lib/ui/text/font_collection.h" #include "flutter/lib/ui/ui_dart_state.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/effects/Sk1DPathEffect.h" #include "third_party/skia/include/effects/SkGradientShader.h" @@ -156,23 +156,23 @@ void FlutterRenderChart::PaintText(const ScopedCanvas& canvas, const Rect& paint LOGW("PaintText: fontCollection is null"); return; } - txt::ParagraphStyle style; - txt::TextStyle txtStyle; - txtStyle.font_size = chartData.GetTextSize(); - txtStyle.font_families = chartData.GetFontFamily(); - txtStyle.font_weight = txt::FontWeight::w400; - std::unique_ptr builder; + Rosen::TypographyStyle style; + Rosen::TextStyle txtStyle; + txtStyle.fontSize_ = chartData.GetTextSize(); + txtStyle.fontFamilies_ = chartData.GetFontFamily(); + txtStyle.fontWeight_ = Rosen::FontWeight::W400; + std::unique_ptr builder; double paragraphSize = paintRegion.Width() / chartData.GetData().size(); - style.max_lines = 1; + style.maxLines_ = 1; for (const auto& point : chartData.GetData()) { const TextInfo& text = point.GetTextInfo(); const PointInfo& pointInfo = point.GetPointInfo(); Offset pointPosition = ConvertDataToPosition(paintRegion, pointInfo); - txtStyle.color = text.GetColor().GetValue(); - builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); + txtStyle.color_ = text.GetColor().GetValue(); + builder = Rosen::TypographyCreate::Create(style, fontCollection); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text.GetTextValue())); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text.GetTextValue())); + auto paragraph = builder->CreateTypography(); paragraph->Layout(paragraphSize); Size textSize = Size(paragraph->GetMinIntrinsicWidth(), paragraph->GetHeight()); if (text.GetPlacement() == Placement::TOP) { diff --git a/frameworks/core/components/chart/flutter_render_chart.h b/frameworks/core/components/chart/flutter_render_chart.h index e43adc697687d270f5edb4135b632b7b9e8947fe..ec15d45472e09c8906dcaddcd69852d27e8cf135 100644 --- a/frameworks/core/components/chart/flutter_render_chart.h +++ b/frameworks/core/components/chart/flutter_render_chart.h @@ -18,7 +18,7 @@ #include "flutter/lib/ui/painting/path.h" #include "flutter/lib/ui/text/font_collection.h" -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "base/geometry/offset.h" #include "base/geometry/rect.h" diff --git a/frameworks/core/components/chart/rosen_render_chart.cpp b/frameworks/core/components/chart/rosen_render_chart.cpp index 5c754e633403a13570b7c2e282c04a9a50e4daf9..11d8e7df3ec2ec7d23acdbac554f5a6deb05ff82 100644 --- a/frameworks/core/components/chart/rosen_render_chart.cpp +++ b/frameworks/core/components/chart/rosen_render_chart.cpp @@ -16,7 +16,7 @@ #include "core/components/chart/rosen_render_chart.h" #include "flutter/lib/ui/text/font_collection.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/effects/Sk1DPathEffect.h" @@ -138,23 +138,23 @@ void RosenRenderChart::PaintText(SkCanvas* canvas, const Rect& paintRegion, cons LOGW("PaintText: fontCollection is null"); return; } - txt::ParagraphStyle style; - txt::TextStyle txtStyle; - txtStyle.font_size = chartData.GetTextSize(); - txtStyle.font_families = chartData.GetFontFamily(); - txtStyle.font_weight = txt::FontWeight::w400; - std::unique_ptr builder; + Rosen::TypographyStyle style; + Rosen::TextStyle txtStyle; + txtStyle.fontSize_ = chartData.GetTextSize(); + txtStyle.fontFamilies_ = chartData.GetFontFamily(); + txtStyle.fontWeight_ = Rosen::FontWeight::W400; + std::unique_ptr builder; double paragraphSize = paintRegion.Width() / chartData.GetData().size(); - style.max_lines = 1; + style.maxLines_ = 1; for (const auto& point : chartData.GetData()) { const TextInfo& text = point.GetTextInfo(); const PointInfo& pointInfo = point.GetPointInfo(); Offset pointPosition = ConvertDataToPosition(paintRegion, pointInfo); - txtStyle.color = text.GetColor().GetValue(); - builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); + txtStyle.color_ = text.GetColor().GetValue(); + builder = Rosen::TypographyCreate::Create(style, fontCollection); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text.GetTextValue())); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text.GetTextValue())); + auto paragraph = builder->CreateTypography(); paragraph->Layout(paragraphSize); Size textSize = Size(paragraph->GetMinIntrinsicWidth(), paragraph->GetHeight()); if (text.GetPlacement() == Placement::TOP) { diff --git a/frameworks/core/components/chart/rosen_render_chart.h b/frameworks/core/components/chart/rosen_render_chart.h index f99c22b4990cc7d2a4a8002f06f8aa66558f685b..ed03cdabc6edbc5d229a4808874521214c554a3a 100644 --- a/frameworks/core/components/chart/rosen_render_chart.h +++ b/frameworks/core/components/chart/rosen_render_chart.h @@ -17,7 +17,7 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CHART_ROSEN_RENDER_CHART_H #include "flutter/lib/ui/text/font_collection.h" -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "base/geometry/offset.h" #include "base/geometry/rect.h" diff --git a/frameworks/core/components/common/painter/flutter_scroll_fade_painter.cpp b/frameworks/core/components/common/painter/flutter_scroll_fade_painter.cpp index 47ac7a6997f758a189338b188090d9c88f262caa..78cadce8ff179cc8dd9ba8fe66a6b6bb698d2ce1 100644 --- a/frameworks/core/components/common/painter/flutter_scroll_fade_painter.cpp +++ b/frameworks/core/components/common/painter/flutter_scroll_fade_painter.cpp @@ -15,7 +15,7 @@ #include "core/components/common/painter/flutter_scroll_fade_painter.h" -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "base/geometry/rect.h" #include "base/log/log.h" diff --git a/frameworks/core/components/components.gni b/frameworks/core/components/components.gni index caccc51cb277c85549d1b9f2ebf3617e445641f4..7889595cb51bdb03bde0ca4a8d1f5c11a506c804 100644 --- a/frameworks/core/components/components.gni +++ b/frameworks/core/components/components.gni @@ -56,6 +56,7 @@ template("build_component") { deps = [] deps += extra_deps deps += [ "$ace_root/frameworks/core/components/theme:build_theme_code" ] + deps += [ "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text" ] if (enable_ng_build) { deps += [ diff --git a/frameworks/core/components/custom_paint/flutter_render_custom_paint.cpp b/frameworks/core/components/custom_paint/flutter_render_custom_paint.cpp index 23c73fb876b02e0f933159e66fcbba5d234127eb..719a522628ab0546e7fc0fbe6819bfafd658d195 100644 --- a/frameworks/core/components/custom_paint/flutter_render_custom_paint.cpp +++ b/frameworks/core/components/custom_paint/flutter_render_custom_paint.cpp @@ -18,9 +18,8 @@ #include #include "flutter/lib/ui/text/font_collection.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" #include "third_party/bounds_checking_function/include/securec.h" +#include "rosen_text/typography_create.h" #include "third_party/skia/include/core/SkBlendMode.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColor.h" @@ -527,20 +526,20 @@ double FlutterRenderCustomPaint::MeasureTextInner(const MeasureContext& context) double FlutterRenderCustomPaint::MeasureText(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetMaxIntrinsicWidth(); } @@ -548,20 +547,20 @@ double FlutterRenderCustomPaint::MeasureText(const std::string& text, const Pain double FlutterRenderCustomPaint::MeasureTextHeight(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetHeight(); } @@ -569,20 +568,20 @@ double FlutterRenderCustomPaint::MeasureTextHeight(const std::string& text, cons TextMetrics FlutterRenderCustomPaint::MeasureTextMetrics(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); auto textAlign = state.GetTextAlign(); @@ -624,7 +623,7 @@ void FlutterRenderCustomPaint::PaintText(const Offset& offset, double x, double paragraph_->Paint(skCanvas_.get(), dx, dy); } -double FlutterRenderCustomPaint::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) +double FlutterRenderCustomPaint::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) { double x = 0.0; switch (align) { @@ -650,7 +649,7 @@ double FlutterRenderCustomPaint::GetAlignOffset(TextAlign align, std::unique_ptr return x; } -double FlutterRenderCustomPaint::GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph) +double FlutterRenderCustomPaint::GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph) { double y = 0.0; switch (baseline) { @@ -1227,67 +1226,65 @@ bool FlutterRenderCustomPaint::UpdateParagraph( const Offset& offset, const std::string& text, bool isStroke, bool hasShadow) { using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; if (isStroke) { - style.text_align = ConvertTxtTextAlign(strokeState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(strokeState_.GetTextAlign()); } else { - style.text_align = ConvertTxtTextAlign(fillState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(fillState_.GetTextAlign()); } auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("UpdateParagraph: fontCollection is null"); return false; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; if (!isStroke && hasShadow) { - txt::TextShadow txtShadow; - txtShadow.color = shadow_.GetColor().GetValue(); - txtShadow.offset.fX = shadow_.GetOffset().GetX(); - txtShadow.offset.fY = shadow_.GetOffset().GetY(); - txtShadow.blur_radius = shadow_.GetBlurRadius(); - txtStyle.text_shadows.emplace_back(txtShadow); - } - txtStyle.locale = Localization::GetInstance()->GetFontLocale(); + Rosen::TextShadow txtShadow; + txtShadow.color_ = shadow_.GetColor().GetValue(); + txtShadow.offset_.SetX(shadow_.GetOffset().GetX()); + txtShadow.offset_.SetY(shadow_.GetOffset().GetY()); + txtShadow.blurRadius_ = shadow_.GetBlurRadius(); + txtStyle.shadows_.emplace_back(txtShadow); + } + txtStyle.locale_ = Localization::GetInstance()->GetFontLocale(); UpdateTextStyleForeground(offset, isStroke, txtStyle, hasShadow); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - paragraph_ = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + paragraph_ = builder->CreateTypography(); return true; } void FlutterRenderCustomPaint::UpdateTextStyleForeground( - const Offset& offset, bool isStroke, txt::TextStyle& txtStyle, bool hasShadow) + const Offset& offset, bool isStroke, Rosen::TextStyle& txtStyle, bool hasShadow) { using namespace Constants; if (!isStroke) { - txtStyle.color = ConvertSkColor(fillState_.GetColor()); - txtStyle.font_size = fillState_.GetTextStyle().GetFontSize().Value(); + txtStyle.color_ = ConvertSkColor(fillState_.GetColor()); + txtStyle.fontSize_ = fillState_.GetTextStyle().GetFontSize().Value(); ConvertTxtStyle(fillState_.GetTextStyle(), context_, txtStyle); if (fillState_.GetGradient().IsValid()) { SkPaint paint; paint.setStyle(SkPaint::Style::kFill_Style); UpdatePaintShader(offset, paint, fillState_.GetGradient()); - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } if (globalState_.HasGlobalAlpha()) { - if (txtStyle.has_foreground) { - txtStyle.foreground.setColor(fillState_.GetColor().GetValue()); - txtStyle.foreground.setAlphaf(globalState_.GetAlpha()); // set alpha after color + if (txtStyle.foreground_.has_value()) { + txtStyle.foreground_->setColor(fillState_.GetColor().GetValue()); + txtStyle.foreground_->setAlphaf(globalState_.GetAlpha()); // set alpha after color } else { SkPaint paint; paint.setColor(fillState_.GetColor().GetValue()); paint.setAlphaf(globalState_.GetAlpha()); // set alpha after color - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } } else { // use foreground to draw stroke SkPaint paint = GetStrokePaint(); ConvertTxtStyle(strokeState_.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = strokeState_.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = strokeState_.GetTextStyle().GetFontSize().Value(); if (strokeState_.GetGradient().IsValid()) { UpdatePaintShader(offset, paint, strokeState_.GetGradient()); } @@ -1296,8 +1293,7 @@ void FlutterRenderCustomPaint::UpdateTextStyleForeground( paint.setMaskFilter(SkMaskFilter::MakeBlur(SkBlurStyle::kNormal_SkBlurStyle, FlutterDecorationPainter::ConvertRadiusToSigma(shadow_.GetBlurRadius()))); } - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } diff --git a/frameworks/core/components/custom_paint/flutter_render_custom_paint.h b/frameworks/core/components/custom_paint/flutter_render_custom_paint.h index bb13177586aea1c64eaa7e22680e53f5578a8fa6..94a62ad0d94c3fe851ed91f42c900ab6ab6cb29f 100644 --- a/frameworks/core/components/custom_paint/flutter_render_custom_paint.h +++ b/frameworks/core/components/custom_paint/flutter_render_custom_paint.h @@ -19,7 +19,8 @@ #include "base/utils/measure_util.h" #include "flutter/fml/memory/ref_ptr.h" #include "flutter/lib/ui/painting/path.h" -#include "flutter/third_party/txt/src/txt/paragraph.h" +#include "rosen_text/text_style.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/core/SkPath.h" #include "core/components/custom_paint/offscreen_canvas.h" @@ -95,16 +96,16 @@ public: private: void InitImagePaint(); void InitCachePaint(); - bool UpdateParagraph(const Offset& offset, const std::string& text, bool isStroke, bool hasShadow = false); - void PaintText(const Offset& offset, double x, double y, bool isStroke, bool hasShadow = false); - double GetAlignOffset(TextAlign align, std::unique_ptr& paragraph); - double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); + bool UpdateParagraph(const Offset& offset, const std::string& text, bool isStroke, bool hasShadow = true); + void PaintText(const Offset& offset, double x, double y, bool isStroke, bool hasShadow = true); + double GetAlignOffset(TextAlign align, std::unique_ptr& paragraph); + double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); SkPaint GetStrokePaint(); bool HasShadow() const; void UpdatePaintShader(const Offset& offset, SkPaint& paint, const Gradient& gradient); void UpdatePaintShader(const Pattern& pattern, SkPaint& paint); void UpdateLineDash(SkPaint& paint); - void UpdateTextStyleForeground(const Offset& offset, bool isStroke, txt::TextStyle& style, bool hasShadow); + void UpdateTextStyleForeground(const Offset& offset, bool isStroke, Rosen::TextStyle& style, bool hasShadow); void Path2DAddPath(const Offset& offset, const PathArgs& args); void Path2DSetTransform(const Offset& offset, const PathArgs& args); @@ -123,7 +124,7 @@ private: void ParsePath2D(const Offset& offset, const RefPtr& path); bool antiAlias_ = false; - std::unique_ptr paragraph_; + std::unique_ptr paragraph_; RefPtr layer_; SkPath skPath_; SkPath skPath2d_; diff --git a/frameworks/core/components/custom_paint/flutter_render_offscreen_canvas.cpp b/frameworks/core/components/custom_paint/flutter_render_offscreen_canvas.cpp index 02826e4e4f57be842eaca301d9a7cb08061a3a02..1727e66f4e844fcb2ccc54296d9d798737450fd9 100644 --- a/frameworks/core/components/custom_paint/flutter_render_offscreen_canvas.cpp +++ b/frameworks/core/components/custom_paint/flutter_render_offscreen_canvas.cpp @@ -18,8 +18,8 @@ #include #include -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" #include "third_party/skia/include/core/SkBlendMode.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColor.h" @@ -33,6 +33,7 @@ #include "third_party/skia/include/encode/SkWebpEncoder.h" #include "third_party/skia/include/utils/SkBase64.h" #include "third_party/skia/include/utils/SkParsePath.h" +#include "unicode/uchar.h" #include "base/i18n/localization.h" #include "base/image/pixel_map.h" @@ -1145,21 +1146,21 @@ void FlutterRenderOffscreenCanvas::StrokeText(const std::string& text, double x, double FlutterRenderOffscreenCanvas::MeasureText(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), pipelineContext_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetMaxIntrinsicWidth(); } @@ -1167,21 +1168,21 @@ double FlutterRenderOffscreenCanvas::MeasureText(const std::string& text, const double FlutterRenderOffscreenCanvas::MeasureTextHeight(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), pipelineContext_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetHeight(); } @@ -1189,21 +1190,21 @@ double FlutterRenderOffscreenCanvas::MeasureTextHeight(const std::string& text, TextMetrics FlutterRenderOffscreenCanvas::MeasureTextMetrics(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), pipelineContext_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); auto textAlign = state.GetTextAlign(); @@ -1245,7 +1246,7 @@ void FlutterRenderOffscreenCanvas::PaintText(const std::string& text, double x, } double FlutterRenderOffscreenCanvas::GetAlignOffset(const std::string& text, - TextAlign align, std::unique_ptr& paragraph) + TextAlign align, std::unique_ptr& paragraph) { double x = 0.0; switch (align) { @@ -1297,67 +1298,65 @@ bool FlutterRenderOffscreenCanvas::UpdateOffParagraph(const std::string& text, b const PaintState& state, bool hasShadow) { using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; if (isStroke) { - style.text_align = ConvertTxtTextAlign(strokeState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(strokeState_.GetTextAlign()); } else { - style.text_align = ConvertTxtTextAlign(fillState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(fillState_.GetTextAlign()); } - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { return false; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; if (!isStroke && hasShadow) { - txt::TextShadow txtShadow; - txtShadow.color = shadow_.GetColor().GetValue(); - txtShadow.offset.fX = shadow_.GetOffset().GetX(); - txtShadow.offset.fY = shadow_.GetOffset().GetY(); - txtShadow.blur_radius = shadow_.GetBlurRadius(); - txtStyle.text_shadows.emplace_back(txtShadow); - } - txtStyle.locale = Localization::GetInstance()->GetFontLocale(); + Rosen::TextShadow txtShadow; + txtShadow.color_ = shadow_.GetColor().GetValue(); + txtShadow.offset_.SetX(shadow_.GetOffset().GetX()); + txtShadow.offset_.SetY(shadow_.GetOffset().GetY()); + txtShadow.blurRadius_ = shadow_.GetBlurRadius(); + txtStyle.shadows_.emplace_back(txtShadow); + } + txtStyle.locale_ = Localization::GetInstance()->GetFontLocale(); UpdateTextStyleForeground(isStroke, txtStyle, hasShadow); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - paragraph_ = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + paragraph_ = builder->CreateTypography(); return true; } void FlutterRenderOffscreenCanvas::UpdateTextStyleForeground( - bool isStroke, txt::TextStyle& txtStyle, bool hasShadow) + bool isStroke, Rosen::TextStyle& txtStyle, bool hasShadow) { using namespace Constants; if (!isStroke) { - txtStyle.color = ConvertSkColor(fillState_.GetColor()); - txtStyle.font_size = fillState_.GetTextStyle().GetFontSize().Value(); + txtStyle.color_ = ConvertSkColor(fillState_.GetColor()); + txtStyle.fontSize_ = fillState_.GetTextStyle().GetFontSize().Value(); ConvertTxtStyle(fillState_.GetTextStyle(), pipelineContext_, txtStyle); if (fillState_.GetGradient().IsValid()) { SkPaint paint; paint.setStyle(SkPaint::Style::kFill_Style); UpdatePaintShader(paint, fillState_.GetGradient()); - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } if (globalState_.HasGlobalAlpha()) { - if (txtStyle.has_foreground) { - txtStyle.foreground.setColor(fillState_.GetColor().GetValue()); - txtStyle.foreground.setAlphaf(globalState_.GetAlpha()); // set alpha after color + if (txtStyle.foreground_.has_value()) { + txtStyle.foreground_->setColor(fillState_.GetColor().GetValue()); + txtStyle.foreground_->setAlphaf(globalState_.GetAlpha()); // set alpha after color } else { SkPaint paint; paint.setColor(fillState_.GetColor().GetValue()); paint.setAlphaf(globalState_.GetAlpha()); // set alpha after color - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } } else { // use foreground to draw stroke SkPaint paint = GetStrokePaint(); ConvertTxtStyle(strokeState_.GetTextStyle(), pipelineContext_, txtStyle); - txtStyle.font_size = strokeState_.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = strokeState_.GetTextStyle().GetFontSize().Value(); if (strokeState_.GetGradient().IsValid()) { UpdatePaintShader(paint, strokeState_.GetGradient()); } @@ -1366,13 +1365,12 @@ void FlutterRenderOffscreenCanvas::UpdateTextStyleForeground( paint.setMaskFilter(SkMaskFilter::MakeBlur(SkBlurStyle::kNormal_SkBlurStyle, FlutterDecorationPainter::ConvertRadiusToSigma(shadow_.GetBlurRadius()))); } - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } double FlutterRenderOffscreenCanvas::GetBaselineOffset(TextBaseline baseline, - std::unique_ptr& paragraph) + std::unique_ptr& paragraph) { double y = 0.0; switch (baseline) { diff --git a/frameworks/core/components/custom_paint/flutter_render_offscreen_canvas.h b/frameworks/core/components/custom_paint/flutter_render_offscreen_canvas.h index 4a1fd62ff40c2c193853a274d2c8af07f4f15be9..4d8a4baee23a3ab1fbe7074da0d1599ffae3a281 100644 --- a/frameworks/core/components/custom_paint/flutter_render_offscreen_canvas.h +++ b/frameworks/core/components/custom_paint/flutter_render_offscreen_canvas.h @@ -18,7 +18,8 @@ #include "flutter/fml/memory/ref_ptr.h" #include "flutter/lib/ui/painting/path.h" -#include "flutter/third_party/txt/src/txt/paragraph.h" +#include "rosen_text/text_style.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPath.h" @@ -99,12 +100,12 @@ private: void UpdatePaintShader(SkPaint& paint, const Gradient& gradient); void UpdatePaintShader(const Pattern& pattern, SkPaint& paint); void PaintText(const std::string& text, double x, double y, bool isStroke, bool hasShadow = false); - double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); - std::unique_ptr paragraph_; + double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); + std::unique_ptr paragraph_; bool HasShadow() const; bool HasImageShadow() const; - void UpdateTextStyleForeground(bool isStroke, txt::TextStyle& style, bool hasShadow); - double GetAlignOffset(const std::string& text, TextAlign align, std::unique_ptr& paragraph); + void UpdateTextStyleForeground(bool isStroke, Rosen::TextStyle& style, bool hasShadow); + double GetAlignOffset(const std::string& text, TextAlign align, std::unique_ptr& paragraph); TextDirection GetTextDirection(const std::string& text); bool UpdateOffParagraph(const std::string& text, bool isStroke, const PaintState& state, bool hasShadow = false); void UpdateLineDash(SkPaint& paint); diff --git a/frameworks/core/components/custom_paint/rosen_render_custom_paint.cpp b/frameworks/core/components/custom_paint/rosen_render_custom_paint.cpp index b3dbc14d114dc2cfef1cb5c6eff453d245d18146..05333b6ae72535196ca14bcde864fe69c656f1cd 100644 --- a/frameworks/core/components/custom_paint/rosen_render_custom_paint.cpp +++ b/frameworks/core/components/custom_paint/rosen_render_custom_paint.cpp @@ -18,9 +18,8 @@ #include #include "flutter/lib/ui/text/font_collection.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" #include "render_service_client/core/ui/rs_node.h" #include "third_party/bounds_checking_function/include/securec.h" #include "third_party/skia/include/core/SkBlendMode.h" @@ -406,39 +405,39 @@ void RosenRenderCustomPaint::StrokeText(const Offset& offset, const std::string& double RosenRenderCustomPaint::MeasureTextInner(const MeasureContext& context) { using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; std::vector fontFamilies; if (context.fontSize) { - txtStyle.font_size = context.fontSize.value().ConvertToPx(); + txtStyle.fontSize_ = context.fontSize.value().ConvertToPx(); } else { auto context = PipelineBase::GetCurrentContext(); auto textTheme = context->GetTheme(); - txtStyle.font_size = textTheme->GetTextStyle().GetFontSize().ConvertToPx(); + txtStyle.fontSize_ = textTheme->GetTextStyle().GetFontSize().ConvertToPx(); } - txtStyle.font_style = ConvertTxtFontStyle(context.fontStyle); + txtStyle.fontStyle_ = ConvertTxtFontStyle(context.fontStyle); FontWeight fontWeightStr = StringUtils::StringToFontWeight(context.fontWeight); - txtStyle.font_weight = ConvertTxtFontWeight(fontWeightStr); + txtStyle.fontWeight_ = ConvertTxtFontWeight(fontWeightStr); StringUtils::StringSplitter(context.fontFamily, ',', fontFamilies); - txtStyle.font_families = fontFamilies; + txtStyle.fontFamilies_ = fontFamilies; if (context.letterSpacing.has_value()) { - txtStyle.letter_spacing = context.letterSpacing.value().ConvertToPx(); + txtStyle.letterSpacing_ = context.letterSpacing.value().ConvertToPx(); } builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(context.textContent)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(context.textContent)); + auto paragraph = builder->CreateTypography(); if (!paragraph) { return 0.0; } paragraph->Layout(Size::INFINITE_SIZE); - return std::ceil(paragraph->GetLongestLine()); + return std::ceil(paragraph->GetActualWidth()); } Size RosenRenderCustomPaint::MeasureTextSizeInner(const MeasureContext& context) @@ -449,50 +448,51 @@ Size RosenRenderCustomPaint::MeasureTextSizeInner(const MeasureContext& context) LOGW("fontCollection is null"); return Size(0.0, 0.0); } - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(context.textAlign); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(context.textAlign); if (context.textOverlayFlow == TextOverflow::ELLIPSIS) { - style.ellipsis = ELLIPSIS; + style.ellipsis_ = ELLIPSIS; } if (GreatNotEqual(context.maxlines, 0.0)) { - style.max_lines = context.maxlines; + style.maxLines_ = context.maxlines; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = + Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; std::vector fontFamilies; if (context.fontSize.has_value()) { - txtStyle.font_size = context.fontSize.value().ConvertToPx(); + txtStyle.fontSize_ = context.fontSize.value().ConvertToPx(); } else { auto context = PipelineBase::GetCurrentContext(); auto textTheme = context->GetTheme(); - txtStyle.font_size = textTheme->GetTextStyle().GetFontSize().ConvertToPx(); + txtStyle.fontSize_ = textTheme->GetTextStyle().GetFontSize().ConvertToPx(); } - txtStyle.font_style = ConvertTxtFontStyle(context.fontStyle); + txtStyle.fontStyle_ = ConvertTxtFontStyle(context.fontStyle); FontWeight fontWeightStr = StringUtils::StringToFontWeight(context.fontWeight); - txtStyle.font_weight = ConvertTxtFontWeight(fontWeightStr); + txtStyle.fontWeight_ = ConvertTxtFontWeight(fontWeightStr); StringUtils::StringSplitter(context.fontFamily, ',', fontFamilies); - txtStyle.font_families = fontFamilies; + txtStyle.fontFamilies_ = fontFamilies; if (context.letterSpacing.has_value()) { - txtStyle.letter_spacing = context.letterSpacing.value().ConvertToPx(); + txtStyle.letterSpacing_ = context.letterSpacing.value().ConvertToPx(); } if (context.lineHeight.has_value()) { if (context.lineHeight->Unit() == DimensionUnit::PERCENT) { - txtStyle.has_height_override = true; - txtStyle.height = context.lineHeight->Value(); + txtStyle.heightOnly_ = true; + txtStyle.heightScale_ = context.lineHeight->Value(); } else { auto lineHeight = context.lineHeight.value().ConvertToPx(); - if (!NearEqual(lineHeight, txtStyle.font_size) && (lineHeight > 0.0) && (!NearZero(txtStyle.font_size))) { - txtStyle.height = lineHeight / txtStyle.font_size; - txtStyle.has_height_override = true; + if (!NearEqual(lineHeight, txtStyle.fontSize_) && (lineHeight > 0.0) && (!NearZero(txtStyle.fontSize_))) { + txtStyle.heightScale_ = lineHeight / txtStyle.fontSize_; + txtStyle.heightOnly_ = true; } } } builder->PushStyle(txtStyle); std::string content = context.textContent; StringUtils::TransformStrCase(content, static_cast(context.textCase)); - builder->AddText(StringUtils::Str8ToStr16(content)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(content)); + auto paragraph = builder->CreateTypography(); if (!paragraph) { return Size(0.0, 0.0); } @@ -502,11 +502,11 @@ Size RosenRenderCustomPaint::MeasureTextSizeInner(const MeasureContext& context) paragraph->Layout(Size::INFINITE_SIZE); } double textWidth = 0.0; - auto* paragraphTxt = static_cast(paragraph.get()); + auto* paragraphTxt = static_cast(paragraph.get()); if (paragraphTxt->GetLineCount() == 1) { - textWidth = std::max(paragraph->GetLongestLine(), paragraph->GetMaxIntrinsicWidth()); + textWidth = std::max(paragraph->GetActualWidth(), paragraph->GetMaxIntrinsicWidth()); } else { - textWidth = paragraph->GetLongestLine(); + textWidth = paragraph->GetActualWidth(); } auto sizeWidth = std::min(paragraph->GetMaxWidth(), textWidth); sizeWidth = @@ -524,20 +524,20 @@ Size RosenRenderCustomPaint::MeasureTextSizeInner(const MeasureContext& context) double RosenRenderCustomPaint::MeasureText(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetMaxIntrinsicWidth(); } @@ -545,20 +545,20 @@ double RosenRenderCustomPaint::MeasureText(const std::string& text, const PaintS double RosenRenderCustomPaint::MeasureTextHeight(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetHeight(); } @@ -566,20 +566,20 @@ double RosenRenderCustomPaint::MeasureTextHeight(const std::string& text, const TextMetrics RosenRenderCustomPaint::MeasureTextMetrics(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); auto textAlign = state.GetTextAlign(); @@ -621,7 +621,7 @@ void RosenRenderCustomPaint::PaintText(const Offset& offset, double x, double y, paragraph_->Paint(skCanvas_.get(), dx, dy); } -double RosenRenderCustomPaint::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) +double RosenRenderCustomPaint::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) { double x = 0.0; switch (align) { @@ -647,7 +647,7 @@ double RosenRenderCustomPaint::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) +double RosenRenderCustomPaint::GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph) { double y = 0.0; switch (baseline) { @@ -1224,61 +1224,59 @@ bool RosenRenderCustomPaint::UpdateParagraph( const Offset& offset, const std::string& text, bool isStroke, bool hasShadow) { using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; if (isStroke) { - style.text_align = ConvertTxtTextAlign(strokeState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(strokeState_.GetTextAlign()); } else { - style.text_align = ConvertTxtTextAlign(fillState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(fillState_.GetTextAlign()); } auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("UpdateParagraph: fontCollection is null"); return false; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; if (!isStroke && hasShadow) { - txt::TextShadow txtShadow; - txtShadow.color = shadow_.GetColor().GetValue(); - txtShadow.offset.fX = shadow_.GetOffset().GetX(); - txtShadow.offset.fY = shadow_.GetOffset().GetY(); - txtShadow.blur_radius = shadow_.GetBlurRadius(); - txtStyle.text_shadows.emplace_back(txtShadow); - } - txtStyle.locale = Localization::GetInstance()->GetFontLocale(); + Rosen::TextShadow txtShadow; + txtShadow.color_ = shadow_.GetColor().GetValue(); + txtShadow.offset_.SetX(shadow_.GetOffset().GetX()); + txtShadow.offset_.SetY(shadow_.GetOffset().GetY()); + txtShadow.blurRadius_ = shadow_.GetBlurRadius(); + txtStyle.shadows_.emplace_back(txtShadow); + } + txtStyle.locale_ = Localization::GetInstance()->GetFontLocale(); UpdateTextStyleForeground(offset, isStroke, txtStyle, hasShadow); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - paragraph_ = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + paragraph_ = builder->CreateTypography(); return true; } void RosenRenderCustomPaint::UpdateTextStyleForeground( - const Offset& offset, bool isStroke, txt::TextStyle& txtStyle, bool hasShadow) + const Offset& offset, bool isStroke, Rosen::TextStyle& txtStyle, bool hasShadow) { using namespace Constants; if (!isStroke) { - txtStyle.color = ConvertSkColor(fillState_.GetColor()); - txtStyle.font_size = fillState_.GetTextStyle().GetFontSize().Value(); + txtStyle.color_ = ConvertSkColor(fillState_.GetColor()); + txtStyle.fontSize_ = fillState_.GetTextStyle().GetFontSize().Value(); ConvertTxtStyle(fillState_.GetTextStyle(), context_, txtStyle); if (fillState_.GetGradient().IsValid()) { SkPaint paint; paint.setStyle(SkPaint::Style::kFill_Style); UpdatePaintShader(offset, paint, fillState_.GetGradient()); - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } if (globalState_.HasGlobalAlpha()) { - if (txtStyle.has_foreground) { - txtStyle.foreground.setColor(fillState_.GetColor().GetValue()); - txtStyle.foreground.setAlphaf(globalState_.GetAlpha()); // set alpha after color + if (txtStyle.foreground_.has_value()) { + txtStyle.foreground_->setColor(fillState_.GetColor().GetValue()); + txtStyle.foreground_->setAlphaf(globalState_.GetAlpha()); // set alpha after color } else { SkPaint paint; paint.setColor(fillState_.GetColor().GetValue()); paint.setAlphaf(globalState_.GetAlpha()); // set alpha after color InitPaintBlend(paint); - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } } else { @@ -1286,7 +1284,7 @@ void RosenRenderCustomPaint::UpdateTextStyleForeground( SkPaint paint = GetStrokePaint(); InitPaintBlend(paint); ConvertTxtStyle(strokeState_.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = strokeState_.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = strokeState_.GetTextStyle().GetFontSize().Value(); if (strokeState_.GetGradient().IsValid()) { UpdatePaintShader(offset, paint, strokeState_.GetGradient()); } @@ -1295,8 +1293,7 @@ void RosenRenderCustomPaint::UpdateTextStyleForeground( paint.setMaskFilter(SkMaskFilter::MakeBlur(SkBlurStyle::kNormal_SkBlurStyle, RosenDecorationPainter::ConvertRadiusToSigma(shadow_.GetBlurRadius()))); } - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } diff --git a/frameworks/core/components/custom_paint/rosen_render_custom_paint.h b/frameworks/core/components/custom_paint/rosen_render_custom_paint.h index c075a0bcffbb7ff31d11f3129e64d71efb5ab217..e2da288e7dd97eb2b8b5ec3ad9235a34525e968c 100644 --- a/frameworks/core/components/custom_paint/rosen_render_custom_paint.h +++ b/frameworks/core/components/custom_paint/rosen_render_custom_paint.h @@ -17,7 +17,8 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CUSTOM_PAINT_ROSEN_RENDER_CUSTOM_PAINT_H #include "experimental/svg/model/SkSVGDOM.h" -#include "flutter/third_party/txt/src/txt/paragraph.h" +#include "rosen_text/text_style.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPaint.h" @@ -101,16 +102,16 @@ public: private: void InitImagePaint(); void InitPaintBlend(SkPaint& paint); - bool UpdateParagraph(const Offset& offset, const std::string& text, bool isStroke, bool hasShadow = false); - void PaintText(const Offset& offset, double x, double y, bool isStroke, bool hasShadow = false); - double GetAlignOffset(TextAlign align, std::unique_ptr& paragraph); - double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); + bool UpdateParagraph(const Offset& offset, const std::string& text, bool isStroke, bool hasShadow = true); + void PaintText(const Offset& offset, double x, double y, bool isStroke, bool hasShadow = true); + double GetAlignOffset(TextAlign align, std::unique_ptr& paragraph); + double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); SkPaint GetStrokePaint(); bool HasShadow() const; void UpdatePaintShader(const Offset& offset, SkPaint& paint, const Gradient& gradient); void UpdatePaintShader(const Pattern& pattern, SkPaint& paint); void UpdateLineDash(SkPaint& paint); - void UpdateTextStyleForeground(const Offset& offset, bool isStroke, txt::TextStyle& style, bool hasShadow); + void UpdateTextStyleForeground(const Offset& offset, bool isStroke, Rosen::TextStyle& style, bool hasShadow); void Path2DAddPath(const Offset& offset, const PathArgs& args); void Path2DSetTransform(const Offset& offset, const PathArgs& args); @@ -136,7 +137,7 @@ private: bool CreateSurface(double viewScale); bool antiAlias_ = false; - std::unique_ptr paragraph_; + std::unique_ptr paragraph_; SkPath skPath_; // Specifically refers to the class Path2D in canvas.d.ts SkPath skPath2d_; diff --git a/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.cpp b/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.cpp index 113671e721970260ae4b47399b1ec265115d65be..acffa63106077a0725f0a30002e89e6121519c1d 100644 --- a/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.cpp +++ b/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.cpp @@ -18,8 +18,8 @@ #include #include -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" #include "third_party/skia/include/core/SkBlendMode.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkMaskFilter.h" @@ -32,6 +32,7 @@ #include "third_party/skia/include/encode/SkWebpEncoder.h" #include "third_party/skia/include/utils/SkBase64.h" #include "third_party/skia/include/utils/SkParsePath.h" +#include "unicode/uchar.h" #include "base/i18n/localization.h" #include "base/image/pixel_map.h" @@ -1217,21 +1218,21 @@ void RosenRenderOffscreenCanvas::StrokeText(const std::string& text, double x, d double RosenRenderOffscreenCanvas::MeasureText(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), pipelineContext_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetMaxIntrinsicWidth(); } @@ -1239,21 +1240,21 @@ double RosenRenderOffscreenCanvas::MeasureText(const std::string& text, const Pa double RosenRenderOffscreenCanvas::MeasureTextHeight(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), pipelineContext_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetHeight(); } @@ -1261,21 +1262,21 @@ double RosenRenderOffscreenCanvas::MeasureTextHeight(const std::string& text, co TextMetrics RosenRenderOffscreenCanvas::MeasureTextMetrics(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), pipelineContext_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); auto textAlign = state.GetTextAlign(); @@ -1317,7 +1318,7 @@ void RosenRenderOffscreenCanvas::PaintText(const std::string& text, double x, do } double RosenRenderOffscreenCanvas::GetAlignOffset(const std::string& text, TextAlign align, - std::unique_ptr& paragraph) + std::unique_ptr& paragraph) { double x = 0.0; switch (align) { @@ -1369,67 +1370,65 @@ bool RosenRenderOffscreenCanvas::UpdateOffParagraph(const std::string& text, boo const PaintState& state, bool hasShadow) { using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; if (isStroke) { - style.text_align = ConvertTxtTextAlign(strokeState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(strokeState_.GetTextAlign()); } else { - style.text_align = ConvertTxtTextAlign(fillState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(fillState_.GetTextAlign()); } - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { return false; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; if (!isStroke && hasShadow) { - txt::TextShadow txtShadow; - txtShadow.color = shadow_.GetColor().GetValue(); - txtShadow.offset.fX = shadow_.GetOffset().GetX(); - txtShadow.offset.fY = shadow_.GetOffset().GetY(); - txtShadow.blur_radius = shadow_.GetBlurRadius(); - txtStyle.text_shadows.emplace_back(txtShadow); - } - txtStyle.locale = Localization::GetInstance()->GetFontLocale(); + Rosen::TextShadow txtShadow; + txtShadow.color_ = shadow_.GetColor().GetValue(); + txtShadow.offset_.SetX(shadow_.GetOffset().GetX()); + txtShadow.offset_.SetY(shadow_.GetOffset().GetY()); + txtShadow.blurRadius_ = shadow_.GetBlurRadius(); + txtStyle.shadows_.emplace_back(txtShadow); + } + txtStyle.locale_ = Localization::GetInstance()->GetFontLocale(); UpdateTextStyleForeground(isStroke, txtStyle, hasShadow); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - paragraph_ = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + paragraph_ = builder->CreateTypography(); return true; } void RosenRenderOffscreenCanvas::UpdateTextStyleForeground( - bool isStroke, txt::TextStyle& txtStyle, bool hasShadow) + bool isStroke, Rosen::TextStyle& txtStyle, bool hasShadow) { using namespace Constants; if (!isStroke) { - txtStyle.color = ConvertSkColor(fillState_.GetColor()); - txtStyle.font_size = fillState_.GetTextStyle().GetFontSize().Value(); + txtStyle.color_ = ConvertSkColor(fillState_.GetColor()); + txtStyle.fontSize_ = fillState_.GetTextStyle().GetFontSize().Value(); ConvertTxtStyle(fillState_.GetTextStyle(), pipelineContext_, txtStyle); if (fillState_.GetGradient().IsValid()) { SkPaint paint; paint.setStyle(SkPaint::Style::kFill_Style); UpdatePaintShader(paint, fillState_.GetGradient()); - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } if (globalState_.HasGlobalAlpha()) { - if (txtStyle.has_foreground) { - txtStyle.foreground.setColor(fillState_.GetColor().GetValue()); - txtStyle.foreground.setAlphaf(globalState_.GetAlpha()); // set alpha after color + if (txtStyle.foreground_.has_value()) { + txtStyle.foreground_->setColor(fillState_.GetColor().GetValue()); + txtStyle.foreground_->setAlphaf(globalState_.GetAlpha()); // set alpha after color } else { SkPaint paint; paint.setColor(fillState_.GetColor().GetValue()); paint.setAlphaf(globalState_.GetAlpha()); // set alpha after color - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } } else { // use foreground to draw stroke SkPaint paint = GetStrokePaint(); ConvertTxtStyle(strokeState_.GetTextStyle(), pipelineContext_, txtStyle); - txtStyle.font_size = strokeState_.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = strokeState_.GetTextStyle().GetFontSize().Value(); if (strokeState_.GetGradient().IsValid()) { UpdatePaintShader(paint, strokeState_.GetGradient()); } @@ -1438,13 +1437,12 @@ void RosenRenderOffscreenCanvas::UpdateTextStyleForeground( paint.setMaskFilter(SkMaskFilter::MakeBlur(SkBlurStyle::kNormal_SkBlurStyle, FlutterDecorationPainter::ConvertRadiusToSigma(shadow_.GetBlurRadius()))); } - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } double RosenRenderOffscreenCanvas::GetBaselineOffset(TextBaseline baseline, - std::unique_ptr& paragraph) + std::unique_ptr& paragraph) { double y = 0.0; switch (baseline) { diff --git a/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.h b/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.h index 497ebdea89e2169ea9417cfc8cf13712bfe21ab9..81dfa069e810906730771a91442c2663aa6c6585 100644 --- a/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.h +++ b/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.h @@ -18,7 +18,8 @@ #include "experimental/svg/model/SkSVGDOM.h" #include "flutter/lib/ui/painting/path.h" -#include "flutter/third_party/txt/src/txt/paragraph.h" +#include "rosen_text/text_style.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPath.h" @@ -109,12 +110,12 @@ private: void UpdatePaintShader(SkPaint& paint, const Gradient& gradient); void UpdatePaintShader(const Pattern& pattern, SkPaint& paint); void PaintText(const std::string& text, double x, double y, bool isStroke, bool hasShadow = false); - double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); - std::unique_ptr paragraph_; + double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); + std::unique_ptr paragraph_; bool HasShadow() const; bool HasImageShadow() const; - void UpdateTextStyleForeground(bool isStroke, txt::TextStyle& style, bool hasShadow); - double GetAlignOffset(const std::string& text, TextAlign align, std::unique_ptr& paragraph); + void UpdateTextStyleForeground(bool isStroke, Rosen::TextStyle& style, bool hasShadow); + double GetAlignOffset(const std::string& text, TextAlign align, std::unique_ptr& paragraph); TextDirection GetTextDirection(const std::string& text); bool UpdateOffParagraph(const std::string& text, bool isStroke, const PaintState& state, bool hasShadow = false); void UpdateLineDash(SkPaint& paint); diff --git a/frameworks/core/components/font/constants_converter.cpp b/frameworks/core/components/font/constants_converter.cpp index 8cd8218b231bb2b9ec5b161d7c675926041c858b..f7043b1b7e35c14a65428aee9895dd5734f5384d 100644 --- a/frameworks/core/components/font/constants_converter.cpp +++ b/frameworks/core/components/font/constants_converter.cpp @@ -15,10 +15,7 @@ #include "constants_converter.h" -#include "flutter/third_party/txt/src/txt/font_style.h" -#include "flutter/third_party/txt/src/txt/font_weight.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" -#include "flutter/third_party/txt/src/txt/text_decoration.h" +#include "rosen_text/typography_style.h" #include "base/i18n/localization.h" #include "core/components/common/properties/color.h" @@ -26,130 +23,130 @@ namespace OHOS::Ace::Constants { -txt::FontWeight ConvertTxtFontWeight(FontWeight fontWeight) +OHOS::Rosen::FontWeight ConvertTxtFontWeight(FontWeight fontWeight) { - txt::FontWeight convertValue; + OHOS::Rosen::FontWeight convertValue; switch (fontWeight) { case FontWeight::W100: case FontWeight::LIGHTER: - convertValue = txt::FontWeight::w100; + convertValue = OHOS::Rosen::FontWeight::W100; break; case FontWeight::W200: - convertValue = txt::FontWeight::w200; + convertValue = OHOS::Rosen::FontWeight::W200; break; case FontWeight::W300: - convertValue = txt::FontWeight::w300; + convertValue = OHOS::Rosen::FontWeight::W300; break; case FontWeight::W400: case FontWeight::NORMAL: case FontWeight::REGULAR: - convertValue = txt::FontWeight::w400; + convertValue = OHOS::Rosen::FontWeight::W400; break; case FontWeight::W500: case FontWeight::MEDIUM: - convertValue = txt::FontWeight::w500; + convertValue = OHOS::Rosen::FontWeight::W500; break; case FontWeight::W600: - convertValue = txt::FontWeight::w600; + convertValue = OHOS::Rosen::FontWeight::W600; break; case FontWeight::W700: case FontWeight::BOLD: - convertValue = txt::FontWeight::w700; + convertValue = OHOS::Rosen::FontWeight::W700; break; case FontWeight::W800: - convertValue = txt::FontWeight::w800; + convertValue = OHOS::Rosen::FontWeight::W800; break; case FontWeight::W900: case FontWeight::BOLDER: - convertValue = txt::FontWeight::w900; + convertValue = OHOS::Rosen::FontWeight::W900; break; default: LOGW("FontWeight setting error! Now using default FontWeight."); - convertValue = txt::FontWeight::w400; + convertValue = OHOS::Rosen::FontWeight::W400; break; } return convertValue; } -txt::FontStyle ConvertTxtFontStyle(FontStyle fontStyle) +OHOS::Rosen::FontStyle ConvertTxtFontStyle(FontStyle fontStyle) { - txt::FontStyle convertValue; + OHOS::Rosen::FontStyle convertValue; switch (fontStyle) { case FontStyle::NORMAL: - convertValue = txt::FontStyle::normal; + convertValue = OHOS::Rosen::FontStyle::NORMAL; break; case FontStyle::ITALIC: - convertValue = txt::FontStyle::italic; + convertValue = OHOS::Rosen::FontStyle::ITALIC; break; default: LOGW("FontStyle setting error! Now using default FontStyle"); - convertValue = txt::FontStyle::normal; + convertValue = OHOS::Rosen::FontStyle::NORMAL; break; } return convertValue; } -txt::TextBaseline ConvertTxtTextBaseline(TextBaseline textBaseline) +OHOS::Rosen::TextBaseline ConvertTxtTextBaseline(TextBaseline textBaseline) { - txt::TextBaseline convertValue; + OHOS::Rosen::TextBaseline convertValue; switch (textBaseline) { case TextBaseline::ALPHABETIC: - convertValue = txt::TextBaseline::kAlphabetic; + convertValue = OHOS::Rosen::TextBaseline::ALPHABETIC; break; case TextBaseline::IDEOGRAPHIC: - convertValue = txt::TextBaseline::kIdeographic; + convertValue = OHOS::Rosen::TextBaseline::IDEOGRAPHIC; break; default: - LOGD("TextBaseline setting error! Now using default TextBaseline"); - convertValue = txt::TextBaseline::kAlphabetic; + LOGW("TextBaseline setting error! Now using default TextBaseline"); + convertValue = OHOS::Rosen::TextBaseline::ALPHABETIC; break; } return convertValue; } -txt::TextAlign ConvertTxtTextAlign(TextAlign textAlign) +OHOS::Rosen::TextAlign ConvertTxtTextAlign(TextAlign textAlign) { - txt::TextAlign convertValue; + OHOS::Rosen::TextAlign convertValue; switch (textAlign) { case TextAlign::LEFT: - convertValue = txt::TextAlign::left; + convertValue = OHOS::Rosen::TextAlign::LEFT; break; case TextAlign::RIGHT: - convertValue = txt::TextAlign::right; + convertValue = OHOS::Rosen::TextAlign::RIGHT; break; case TextAlign::CENTER: - convertValue = txt::TextAlign::center; + convertValue = OHOS::Rosen::TextAlign::CENTER; break; case TextAlign::JUSTIFY: - convertValue = txt::TextAlign::justify; + convertValue = OHOS::Rosen::TextAlign::JUSTIFY; break; case TextAlign::START: - convertValue = txt::TextAlign::start; + convertValue = OHOS::Rosen::TextAlign::START; break; case TextAlign::END: - convertValue = txt::TextAlign::end; + convertValue = OHOS::Rosen::TextAlign::END; break; default: LOGW("TextAlign setting error! Now using default TextAlign"); - convertValue = txt::TextAlign::start; + convertValue = OHOS::Rosen::TextAlign::START; break; } return convertValue; } -txt::TextDirection ConvertTxtTextDirection(TextDirection textDirection) +OHOS::Rosen::TextDirection ConvertTxtTextDirection(TextDirection textDirection) { - txt::TextDirection convertValue; + OHOS::Rosen::TextDirection convertValue; switch (textDirection) { case TextDirection::RTL: - convertValue = txt::TextDirection::rtl; + convertValue = OHOS::Rosen::TextDirection::RTL; break; case TextDirection::LTR: - convertValue = txt::TextDirection::ltr; + convertValue = OHOS::Rosen::TextDirection::LTR; break; default: LOGW("TextDirection setting error! Now using default TextDirection"); - convertValue = txt::TextDirection::ltr; + convertValue = OHOS::Rosen::TextDirection::LTR; break; } return convertValue; @@ -160,21 +157,21 @@ SkColor ConvertSkColor(Color color) return color.GetValue(); } -txt::TextDecoration ConvertTxtTextDecoration(TextDecoration textDecoration) +OHOS::Rosen::TextDecoration ConvertTxtTextDecoration(TextDecoration textDecoration) { - txt::TextDecoration convertValue = txt::TextDecoration::kNone; + OHOS::Rosen::TextDecoration convertValue = OHOS::Rosen::TextDecoration::NONE; switch (textDecoration) { case TextDecoration::NONE: - convertValue = txt::TextDecoration::kNone; + convertValue = OHOS::Rosen::TextDecoration::NONE; break; case TextDecoration::UNDERLINE: - convertValue = txt::TextDecoration::kUnderline; + convertValue = OHOS::Rosen::TextDecoration::UNDERLINE; break; case TextDecoration::OVERLINE: - convertValue = txt::TextDecoration::kOverline; + convertValue = OHOS::Rosen::TextDecoration::OVERLINE; break; case TextDecoration::LINE_THROUGH: - convertValue = txt::TextDecoration::kLineThrough; + convertValue = OHOS::Rosen::TextDecoration::LINETHROUGH; break; default: LOGW("TextDecoration setting error! Now using default TextDecoration"); @@ -183,73 +180,69 @@ txt::TextDecoration ConvertTxtTextDecoration(TextDecoration textDecoration) return convertValue; } -void ConvertTxtStyle(const TextStyle& textStyle, const WeakPtr& context, txt::TextStyle& txtStyle) +void ConvertTxtStyle(const TextStyle& textStyle, const WeakPtr& context, OHOS::Rosen::TextStyle& txtStyle) { - txtStyle.color = ConvertSkColor(textStyle.GetTextColor()); - txtStyle.font_weight = ConvertTxtFontWeight(textStyle.GetFontWeight()); - // Font size must be px when transferring to txt::TextStyle + txtStyle.color_ = ConvertSkColor(textStyle.GetTextColor()); + txtStyle.fontWeight_ = ConvertTxtFontWeight(textStyle.GetFontWeight()); + // Font size must be px when transferring to OHOS::Rosen::TextStyle auto pipelineContext = context.Upgrade(); if (pipelineContext) { - txtStyle.font_size = pipelineContext->NormalizeToPx(textStyle.GetFontSize()); + txtStyle.fontSize_ = pipelineContext->NormalizeToPx(textStyle.GetFontSize()); if (textStyle.IsAllowScale() || textStyle.GetFontSize().Unit() == DimensionUnit::FP) { - txtStyle.font_size = + txtStyle.fontSize_ = pipelineContext->NormalizeToPx(textStyle.GetFontSize() * pipelineContext->GetFontScale()); } } else { - txtStyle.font_size = textStyle.GetFontSize().Value(); + txtStyle.fontSize_ = textStyle.GetFontSize().Value(); } - txtStyle.font_style = ConvertTxtFontStyle(textStyle.GetFontStyle()); + txtStyle.fontStyle_ = ConvertTxtFontStyle(textStyle.GetFontStyle()); if (textStyle.GetWordSpacing().Unit() == DimensionUnit::PERCENT) { - txtStyle.word_spacing = textStyle.GetWordSpacing().Value() * txtStyle.font_size; + txtStyle.wordSpacing_ = textStyle.GetWordSpacing().Value() * txtStyle.fontSize_; } else { if (pipelineContext) { - txtStyle.word_spacing = pipelineContext->NormalizeToPx(textStyle.GetWordSpacing()); + txtStyle.wordSpacing_ = pipelineContext->NormalizeToPx(textStyle.GetWordSpacing()); } else { - txtStyle.word_spacing = textStyle.GetWordSpacing().Value(); + txtStyle.wordSpacing_ = textStyle.GetWordSpacing().Value(); } } if (pipelineContext) { - txtStyle.letter_spacing = pipelineContext->NormalizeToPx(textStyle.GetLetterSpacing()); + txtStyle.letterSpacing_ = pipelineContext->NormalizeToPx(textStyle.GetLetterSpacing()); } - txtStyle.text_baseline = ConvertTxtTextBaseline(textStyle.GetTextBaseline()); - txtStyle.decoration = ConvertTxtTextDecoration(textStyle.GetTextDecoration()); - txtStyle.decoration_color = ConvertSkColor(textStyle.GetTextDecorationColor()); - txtStyle.font_families = textStyle.GetFontFamilies(); - txtStyle.locale = Localization::GetInstance()->GetFontLocale(); + txtStyle.baseline_ = ConvertTxtTextBaseline(textStyle.GetTextBaseline()); + txtStyle.decoration_ = ConvertTxtTextDecoration(textStyle.GetTextDecoration()); + txtStyle.decorationColor_ = ConvertSkColor(textStyle.GetTextDecorationColor()); + txtStyle.fontFamilies_ = textStyle.GetFontFamilies(); + txtStyle.locale_ = Localization::GetInstance()->GetFontLocale(); for (auto& spanShadow : textStyle.GetTextShadows()) { - txt::TextShadow txtShadow; - txtShadow.color = spanShadow.GetColor().GetValue(); - txtShadow.offset.fX = static_cast(spanShadow.GetOffset().GetX()); - txtShadow.offset.fY = static_cast(spanShadow.GetOffset().GetY()); -#ifdef FLUTTER_2_5 - txtShadow.blur_sigma = spanShadow.GetBlurRadius(); -#else - txtShadow.blur_radius = spanShadow.GetBlurRadius(); -#endif - txtStyle.text_shadows.emplace_back(txtShadow); + OHOS::Rosen::TextShadow txtShadow; + txtShadow.color_ = spanShadow.GetColor().GetValue(); + txtShadow.offset_.SetX(spanShadow.GetOffset().GetX()); + txtShadow.offset_.SetY(spanShadow.GetOffset().GetY()); + txtShadow.blurRadius_ = spanShadow.GetBlurRadius(); + txtStyle.shadows_.emplace_back(txtShadow); } if (textStyle.GetLineHeight().Unit() == DimensionUnit::PERCENT) { - txtStyle.has_height_override = true; - txtStyle.height = textStyle.GetLineHeight().Value(); + txtStyle.heightOnly_ = true; + txtStyle.heightScale_ = textStyle.GetLineHeight().Value(); } else { - double fontSize = txtStyle.font_size; + double fontSize = txtStyle.fontSize_; double lineHeight = textStyle.GetLineHeight().Value(); if (pipelineContext) { lineHeight = pipelineContext->NormalizeToPx(textStyle.GetLineHeight()); } - txtStyle.has_height_override = textStyle.HasHeightOverride(); + txtStyle.heightOnly_ = textStyle.HasHeightOverride(); if (!NearEqual(lineHeight, fontSize) && (lineHeight > 0.0) && (!NearZero(fontSize))) { - txtStyle.height = lineHeight / fontSize; + txtStyle.heightScale_ = lineHeight / fontSize; } else { LOGD("use default text style height value."); - txtStyle.height = 1; + txtStyle.heightScale_ = 1; static const int32_t BEGIN_VERSION = 6; auto isBeginVersion = pipelineContext && pipelineContext->GetMinPlatformVersion() >= BEGIN_VERSION; if (NearZero(lineHeight) || (!isBeginVersion && NearEqual(lineHeight, fontSize))) { - txtStyle.has_height_override = false; + txtStyle.heightOnly_ = false; } } } @@ -257,11 +250,11 @@ void ConvertTxtStyle(const TextStyle& textStyle, const WeakPtr& co // set font variant auto fontFeatures = textStyle.GetFontFeatures(); if (!fontFeatures.empty()) { - txt::FontFeatures features; + OHOS::Rosen::FontFeatures features; for (auto iter = fontFeatures.begin(); iter != fontFeatures.end(); ++iter) { features.SetFeature(iter->first, iter->second); } - txtStyle.font_features = features; + txtStyle.fontFeatures_ = features; } } @@ -275,4 +268,14 @@ Rect ConvertSkRect(SkRect skRect) return result; } +Rect ConvertSkRect(const Rosen::Drawing::RectF &skRect) +{ + Rect result; + result.SetLeft(skRect.GetLeft()); + result.SetTop(skRect.GetTop()); + result.SetWidth(skRect.GetWidth()); + result.SetHeight(skRect.GetHeight()); + return result; +} + } // namespace OHOS::Ace::Constants diff --git a/frameworks/core/components/font/constants_converter.h b/frameworks/core/components/font/constants_converter.h index 37dc06c5ab70d1053b39d56022c0d748e57f7e17..88977988f611ff9368877641e25333ead4019226 100644 --- a/frameworks/core/components/font/constants_converter.h +++ b/frameworks/core/components/font/constants_converter.h @@ -16,20 +16,22 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_CONSTANTS_CONVERTER_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_CONSTANTS_CONVERTER_H -#include "flutter/third_party/txt/src/txt/text_baseline.h" -#include "flutter/third_party/txt/src/txt/text_decoration.h" -#include "flutter/third_party/txt/src/txt/text_style.h" +#include "rosen_text/typography_types.h" #include "third_party/skia/include/core/SkColor.h" #include "core/components/common/properties/text_style.h" #include "core/pipeline/pipeline_base.h" -namespace txt { +namespace OHOS::Rosen { enum class FontWeight; enum class FontStyle; enum class TextAlign; enum class TextDirection; -} // namespace txt +struct TextStyle; +namespace Drawing { +class RectF; +} // namespace Drawing +} // namespace OHOS::Rosen namespace OHOS::Ace { @@ -44,24 +46,26 @@ class Color; namespace Constants { -txt::FontWeight ConvertTxtFontWeight(FontWeight fontWeight); +OHOS::Rosen::FontWeight ConvertTxtFontWeight(FontWeight fontWeight); -txt::FontStyle ConvertTxtFontStyle(FontStyle fontStyle); +OHOS::Rosen::FontStyle ConvertTxtFontStyle(FontStyle fontStyle); -txt::TextBaseline ConvertTxtTextBaseline(TextBaseline textBaseline); +OHOS::Rosen::TextBaseline ConvertTxtTextBaseline(TextBaseline textBaseline); -txt::TextAlign ConvertTxtTextAlign(TextAlign textAlign); +OHOS::Rosen::TextAlign ConvertTxtTextAlign(TextAlign textAlign); -txt::TextDirection ConvertTxtTextDirection(TextDirection textDirection); +OHOS::Rosen::TextDirection ConvertTxtTextDirection(TextDirection textDirection); SkColor ConvertSkColor(Color color); -txt::TextDecoration ConvertTxtTextDecoration(TextDecoration textDecoration); +OHOS::Rosen::TextDecoration ConvertTxtTextDecoration(TextDecoration textDecoration); -void ConvertTxtStyle(const TextStyle& textStyle, const WeakPtr& context, txt::TextStyle& txtStyle); +void ConvertTxtStyle(const TextStyle& textStyle, const WeakPtr& context, OHOS::Rosen::TextStyle& txtStyle); Rect ConvertSkRect(SkRect skRect); +Rect ConvertSkRect(const Rosen::Drawing::RectF &skRect); + } // namespace Constants } // namespace OHOS::Ace diff --git a/frameworks/core/components/font/flutter_font_collection.cpp b/frameworks/core/components/font/flutter_font_collection.cpp index d4b38cfd7217bdca540a6eed1165e359b973a5d6..6136dc8771860d660c73de73d58ea172f5485abb 100644 --- a/frameworks/core/components/font/flutter_font_collection.cpp +++ b/frameworks/core/components/font/flutter_font_collection.cpp @@ -26,17 +26,19 @@ #include "base/utils/utils.h" #include "core/common/ace_engine.h" +#include "rosen_text/font_collection.h" + namespace OHOS::Ace { FlutterFontCollection FlutterFontCollection::instance; -std::shared_ptr FlutterFontCollection::GetFontCollection() +std::shared_ptr FlutterFontCollection::GetFontCollection() { if (!isUseFlutterEngine) { if (!isCompleted_) { isCompleted_ = future_.get(); } - return fontCollection_->GetFontCollection(); + return Rosen::FontCollection::From(fontCollection_->GetFontCollection()); } auto* windowClient = GetFlutterEngineWindowClient(); @@ -44,7 +46,7 @@ std::shared_ptr FlutterFontCollection::GetFontCollection() return nullptr; } auto& fontCollection = windowClient->GetFontCollection(); - return fontCollection.GetFontCollection(); + return Rosen::FontCollection::From(fontCollection.GetFontCollection()); } flutter::WindowClient* FlutterFontCollection::GetFlutterEngineWindowClient() diff --git a/frameworks/core/components/font/flutter_font_collection.h b/frameworks/core/components/font/flutter_font_collection.h index 057f8965379f00c3ad6786a9283756f6f9268c5f..b5cc3086ca7b8da4c3490adfafce269784cefe79 100644 --- a/frameworks/core/components/font/flutter_font_collection.h +++ b/frameworks/core/components/font/flutter_font_collection.h @@ -32,7 +32,7 @@ class ACE_EXPORT FlutterFontCollection : public FontCollection { public: static FlutterFontCollection& GetInstance(); - std::shared_ptr GetFontCollection() override; + std::shared_ptr GetFontCollection() override; void LoadFontFromList(const uint8_t* fontData, size_t length, std::string familyName); diff --git a/frameworks/core/components/font/font_collection.h b/frameworks/core/components/font/font_collection.h index 28ba93773655a0125f1844b0d0abfd56d6105930..5f18365357eb36f4c66a9e06b88f11760456ec7a 100644 --- a/frameworks/core/components/font/font_collection.h +++ b/frameworks/core/components/font/font_collection.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_FONT_COLLECTION_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_FONT_COLLECTION_H -#include "flutter/lib/ui/text/font_collection.h" +#include "rosen_text/font_collection.h" #include "base/utils/macros.h" #include "base/utils/noncopyable.h" @@ -27,8 +27,8 @@ class ACE_EXPORT FontCollection : public NonCopyable { public: static FontCollection* GetInstance(); - // TODO: Delete txt::FontCollection, using adapter. - virtual std::shared_ptr GetFontCollection() = 0; + // TODO: Delete Rosen::FontCollection, using adapter. + virtual std::shared_ptr GetFontCollection() = 0; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/font/rosen_font_collection.cpp b/frameworks/core/components/font/rosen_font_collection.cpp index 2c3e11079b9e13ba966ab36d2d807e4699c4bf59..5b5386bbe5a031e4e17ca8c719766bc8900ea919 100644 --- a/frameworks/core/components/font/rosen_font_collection.cpp +++ b/frameworks/core/components/font/rosen_font_collection.cpp @@ -26,18 +26,20 @@ #include "base/utils/utils.h" #include "core/common/ace_engine.h" +#include "rosen_text/font_collection.h" + namespace OHOS::Ace { RosenFontCollection RosenFontCollection::instance; #ifndef ENABLE_ROSEN_BACKEND -std::shared_ptr RosenFontCollection::GetFontCollection() +std::shared_ptr RosenFontCollection::GetFontCollection() { if (!isUseRosenEngine) { if (!isCompleted_) { isCompleted_ = future_.get(); } - return fontCollection_->GetFontCollection(); + return Rosen::FontCollection::From(fontCollection_->GetFontCollection()); } auto* windowClient = GetRosenEngineWindowClient(); @@ -45,16 +47,16 @@ std::shared_ptr RosenFontCollection::GetFontCollection() return nullptr; } auto& fontCollection = windowClient->GetFontCollection(); - return fontCollection.GetFontCollection(); + return Rosen::FontCollection::From(fontCollection.GetFontCollection()); } #else -std::shared_ptr RosenFontCollection::GetFontCollection() +std::shared_ptr RosenFontCollection::GetFontCollection() { auto collection = std::make_shared(); collection->SetupDefaultFontManager(); auto dfmanager = sk_make_sp(); collection->SetDynamicFontManager(dfmanager); - return collection; + return Rosen::FontCollection::From(collection); } #endif diff --git a/frameworks/core/components/font/rosen_font_collection.h b/frameworks/core/components/font/rosen_font_collection.h index 789a848fe804c3aab8741576fc077d73c2b91436..5d3c20cb1c97757cb1cb7056e0b97114a291c149 100644 --- a/frameworks/core/components/font/rosen_font_collection.h +++ b/frameworks/core/components/font/rosen_font_collection.h @@ -30,7 +30,7 @@ class ACE_EXPORT RosenFontCollection : public FontCollection { public: static RosenFontCollection& GetInstance(); - std::shared_ptr GetFontCollection() override; + std::shared_ptr GetFontCollection() override; void LoadFontFromList(const uint8_t* fontData, size_t length, std::string familyName); diff --git a/frameworks/core/components/multimodal/flutter_render_multimodal.cpp b/frameworks/core/components/multimodal/flutter_render_multimodal.cpp index 1ae5a9f728661b5351f421f1947600410475b00e..60838385072bb34e0a011c3a813c502e33ed36e3 100644 --- a/frameworks/core/components/multimodal/flutter_render_multimodal.cpp +++ b/frameworks/core/components/multimodal/flutter_render_multimodal.cpp @@ -18,8 +18,8 @@ #include #include "flutter/lib/ui/text/font_collection.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" #include "base/i18n/localization.h" #include "base/utils/string_utils.h" @@ -68,8 +68,8 @@ void FlutterRenderMultimodal::Paint(RenderContext& context, const Offset& offset UpdateParagraph(offset, subscript_.GetVoiceContent()); paragraph_->Layout(GetLayoutSize().Width()); - if (paragraph_->GetLongestLine() > NormalizeToPx(Dimension(LIMIT_WIDTH, DimensionUnit::VP))) { - width = height + (paragraph_->GetLongestLine() - NormalizeToPx(Dimension(LIMIT_WIDTH, DimensionUnit::VP))); + if (paragraph_->GetActualWidth() > NormalizeToPx(Dimension(LIMIT_WIDTH, DimensionUnit::VP))) { + width = height + (paragraph_->GetActualWidth() - NormalizeToPx(Dimension(LIMIT_WIDTH, DimensionUnit::VP))); } SkVector radii[] = { { corner, corner }, { 0, 0 }, { corner, corner }, { 0, 0 } }; @@ -77,7 +77,7 @@ void FlutterRenderMultimodal::Paint(RenderContext& context, const Offset& offset rrect.setRectRadii(SkRect::MakeXYWH(offset.GetX(), offset.GetY(), width, height), radii); skCanvas->drawRRect(rrect, paint); - auto leftOffset = paragraph_->GetLongestLine() / 2; + auto leftOffset = paragraph_->GetActualWidth() / 2; auto centerX = offset.GetX() + width / 2; auto centerY = offset.GetY() + height / 2; paragraph_->Paint(skCanvas, centerX - leftOffset, centerY - paragraph_->GetHeight() / 2); @@ -86,23 +86,23 @@ void FlutterRenderMultimodal::Paint(RenderContext& context, const Offset& offset void FlutterRenderMultimodal::UpdateParagraph(const Offset& offset, const std::string& text) { using namespace Constants; - txt::ParagraphStyle style; - style.max_lines = 1; - style.ellipsis = StringUtils::Str8ToStr16(ELLIPSIS); + Rosen::TypographyStyle style; + style.maxLines_ = 1; + style.ellipsis_= StringUtils::Str8ToStr16(ELLIPSIS); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("UpdateParagraph: fontCollection is null"); return; } - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; - txtStyle.font_size = NormalizeToPx(Dimension(FONT_SIZE, DimensionUnit::FP)); - txtStyle.color = Color::FromARGB(255, 255, 255, 255).GetValue(); - txtStyle.locale = Localization::GetInstance()->GetFontLocale(); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; + txtStyle.fontSize_ = NormalizeToPx(Dimension(FONT_SIZE, DimensionUnit::FP)); + txtStyle.color_ = Color::FromARGB(255, 255, 255, 255).GetValue(); + txtStyle.locale_ = Localization::GetInstance()->GetFontLocale(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - paragraph_ = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + paragraph_ = builder->CreateTypography(); } } // namespace OHOS::Ace \ No newline at end of file diff --git a/frameworks/core/components/multimodal/flutter_render_multimodal.h b/frameworks/core/components/multimodal/flutter_render_multimodal.h index 9e3df1c788ba291b2161864fd36dea4967cb246d..2c5650ee09f7757870c9a161532ba039c71f3e22 100644 --- a/frameworks/core/components/multimodal/flutter_render_multimodal.h +++ b/frameworks/core/components/multimodal/flutter_render_multimodal.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MULTIMODAL_FLUTTER_RENDER_MULTIMODAL_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MULTIMODAL_FLUTTER_RENDER_MULTIMODAL_H -#include "flutter/third_party/txt/src/txt/paragraph.h" +#include "rosen_text/typography.h" #include "core/components/multimodal/render_multimodal.h" @@ -31,7 +31,7 @@ public: private: void UpdateParagraph(const Offset& offset, const std::string& text); - std::unique_ptr paragraph_; + std::unique_ptr paragraph_; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/multimodal/rosen_render_multimodal.cpp b/frameworks/core/components/multimodal/rosen_render_multimodal.cpp index 7d6243686d436dc88859ccf0c3b6c2754ab13fe8..240625b2afb2e553c7f4d06862f46f04fe7ec080 100644 --- a/frameworks/core/components/multimodal/rosen_render_multimodal.cpp +++ b/frameworks/core/components/multimodal/rosen_render_multimodal.cpp @@ -17,8 +17,8 @@ #include #include "flutter/lib/ui/text/font_collection.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPoint.h" @@ -64,8 +64,8 @@ void RosenRenderMultimodal::Paint(RenderContext& context, const Offset& offset) UpdateParagraph(offset, subscript_.GetVoiceContent()); paragraph_->Layout(GetLayoutSize().Width()); - if (paragraph_->GetLongestLine() > NormalizeToPx(Dimension(LIMIT_WIDTH, DimensionUnit::VP))) { - width = height + (paragraph_->GetLongestLine() - NormalizeToPx(Dimension(LIMIT_WIDTH, DimensionUnit::VP))); + if (paragraph_->GetActualWidth() > NormalizeToPx(Dimension(LIMIT_WIDTH, DimensionUnit::VP))) { + width = height + (paragraph_->GetActualWidth() - NormalizeToPx(Dimension(LIMIT_WIDTH, DimensionUnit::VP))); } SkVector radii[] = { { corner, corner }, { 0, 0 }, { corner, corner }, { 0, 0 } }; @@ -73,7 +73,7 @@ void RosenRenderMultimodal::Paint(RenderContext& context, const Offset& offset) rrect.setRectRadii(SkRect::MakeXYWH(offset.GetX(), offset.GetY(), width, height), radii); canvas->drawRRect(rrect, paint); - auto leftOffset = paragraph_->GetLongestLine() / 2; + auto leftOffset = paragraph_->GetActualWidth() / 2; auto centerX = offset.GetX() + width / 2; auto centerY = offset.GetY() + height / 2; paragraph_->Paint(canvas, centerX - leftOffset, centerY - paragraph_->GetHeight() / 2); @@ -82,22 +82,22 @@ void RosenRenderMultimodal::Paint(RenderContext& context, const Offset& offset) void RosenRenderMultimodal::UpdateParagraph(const Offset& offset, const std::string& text) { using namespace Constants; - txt::ParagraphStyle style; - style.max_lines = 1; - style.ellipsis = StringUtils::Str8ToStr16(ELLIPSIS); + Rosen::TypographyStyle style; + style.maxLines_ = 1; + style.ellipsis_= StringUtils::Str8ToStr16(ELLIPSIS); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("UpdateParagraph: fontCollection is null"); return; } - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; - txtStyle.font_size = NormalizeToPx(Dimension(FONT_SIZE, DimensionUnit::FP)); - txtStyle.color = Color::FromARGB(255, 255, 255, 255).GetValue(); - txtStyle.locale = Localization::GetInstance()->GetFontLocale(); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; + txtStyle.fontSize_ = NormalizeToPx(Dimension(FONT_SIZE, DimensionUnit::FP)); + txtStyle.color_ = Color::FromARGB(255, 255, 255, 255).GetValue(); + txtStyle.locale_ = Localization::GetInstance()->GetFontLocale(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - paragraph_ = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + paragraph_ = builder->CreateTypography(); } } // namespace OHOS::Ace \ No newline at end of file diff --git a/frameworks/core/components/multimodal/rosen_render_multimodal.h b/frameworks/core/components/multimodal/rosen_render_multimodal.h index 997916287066a4383229b35a24756b1c87c81a41..e1850ab0d43ea59c7256ca291a7248f894d52aae 100644 --- a/frameworks/core/components/multimodal/rosen_render_multimodal.h +++ b/frameworks/core/components/multimodal/rosen_render_multimodal.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MULTIMODAL_ROSEN_RENDER_MULTIMODAL_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MULTIMODAL_ROSEN_RENDER_MULTIMODAL_H -#include "flutter/third_party/txt/src/txt/paragraph.h" +#include "rosen_text/typography.h" #include "core/components/multimodal/render_multimodal.h" namespace OHOS::Ace { @@ -28,7 +28,7 @@ public: private: void UpdateParagraph(const Offset& offset, const std::string& text); - std::unique_ptr paragraph_; + std::unique_ptr paragraph_; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/root/flutter_render_root.cpp b/frameworks/core/components/root/flutter_render_root.cpp index 27bfed50159c4034d7c0b492d96895c651eaf7e5..495d5fcb00d0dda487b60f5c353d8cad4875afea 100644 --- a/frameworks/core/components/root/flutter_render_root.cpp +++ b/frameworks/core/components/root/flutter_render_root.cpp @@ -16,7 +16,7 @@ #include "core/components/root/flutter_render_root.h" #include "flutter/lib/ui/text/font_collection.h" -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "flutter/runtime/window_manager.h" #include "core/pipeline/base/flutter_render_context.h" diff --git a/frameworks/core/components/text/flutter_render_text.cpp b/frameworks/core/components/text/flutter_render_text.cpp index 1e313dad7bc33cc1c9871b3f4c0781987ae3d631..2760aa2a6baf2e758ba9fa38674ce13f3e9b0e33 100644 --- a/frameworks/core/components/text/flutter_render_text.cpp +++ b/frameworks/core/components/text/flutter_render_text.cpp @@ -20,7 +20,7 @@ #include "flutter/lib/ui/text/font_collection.h" #include "flutter/lib/ui/ui_dart_state.h" #include "flutter/third_party/icu/source/common/unicode/uchar.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography_create.h" #include "base/geometry/dimension.h" #include "base/i18n/localization.h" @@ -359,9 +359,8 @@ bool FlutterRenderText::UpdateParagraphAndLayout(double paragraphMaxWidth) uint32_t FlutterRenderText::GetTextLines() { uint32_t textLines = 0; - auto paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr) { - textLines = paragraphTxt->GetLineCount(); + if (paragraph_ != nullptr) { + textLines = paragraph_->GetLineCount(); } return textLines; } @@ -371,7 +370,7 @@ int32_t FlutterRenderText::GetTouchPosition(const Offset& offset) if (!paragraph_) { return 0; } - return static_cast(paragraph_->GetGlyphPositionAtCoordinate(offset.GetX(), offset.GetY()).position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate(offset.GetX(), offset.GetY()).index_); } Size FlutterRenderText::GetSize() @@ -429,9 +428,8 @@ void FlutterRenderText::ApplyIndents(double width) indents.push_back(0.0); indents.push_back(-indent); } - auto* paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr) { - paragraphTxt->SetIndents(indents); + if (paragraph_ != nullptr) { + paragraph_->SetIndents(indents); } } @@ -443,7 +441,7 @@ bool FlutterRenderText::UpdateParagraph() using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; if (alignment_.has_value()) { textStyle_.SetTextAlign(alignment_.value()); } @@ -464,32 +462,31 @@ bool FlutterRenderText::UpdateParagraph() } } std::string displayData = ApplyWhiteSpace(); - style.text_direction = ConvertTxtTextDirection(defaultTextDirection_); - style.text_align = ConvertTxtTextAlign(textAlign); - style.max_lines = textStyle_.GetMaxLines(); - style.locale = Localization::GetInstance()->GetFontLocale(); + style.textDirection_ = ConvertTxtTextDirection(defaultTextDirection_); + style.textAlign_ = ConvertTxtTextAlign(textAlign); + style.maxLines_ = textStyle_.GetMaxLines(); + style.locale_ = Localization::GetInstance()->GetFontLocale(); if (textStyle_.GetTextOverflow() == TextOverflow::ELLIPSIS) { if (!IsCompatibleVersion() && textStyle_.GetMaxLines() == UINT32_MAX && !text_->GetAutoMaxLines()) { - style.max_lines = 1; + style.maxLines_ = 1; } - style.ellipsis = ELLIPSIS; + style.ellipsis_= ELLIPSIS; auto context = GetContext().Upgrade(); if (context && context->UseLiteStyle()) { - style.max_lines = 1; + style.maxLines_ = 1; } } - style.word_break_type = static_cast(textStyle_.GetWordBreak()); + style.wordBreakType_ = static_cast(textStyle_.GetWordBreak()); - std::unique_ptr builder; auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("UpdateParagraph: fontCollection is null"); return false; } - builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); + auto builder = Rosen::TypographyCreate::Create(style, fontCollection); std::string textValue = ""; - txt::TextStyle txtStyle; + Rosen::TextStyle txtStyle; ConvertTxtStyle(textStyle_, context_, txtStyle); builder->PushStyle(txtStyle); const auto& children = GetChildren(); @@ -503,9 +500,9 @@ bool FlutterRenderText::UpdateParagraph() } } else { StringUtils::TransformStrCase(displayData, (int32_t)textStyle_.GetTextCase()); - builder->AddText(StringUtils::Str8ToStr16(displayData)); + builder->AppendText(StringUtils::Str8ToStr16(displayData)); } - paragraph_ = builder->Build(); + paragraph_ = builder->CreateTypography(); ApplyIndents(GetLayoutParam().GetMaxSize().Width()); return true; @@ -519,18 +516,16 @@ double FlutterRenderText::GetTextWidth() if (!IsCompatibleVersion()) { return paragraph_->GetMaxIntrinsicWidth(); } - auto* paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr && paragraphTxt->GetLineCount() == 1) { - return std::max(paragraph_->GetLongestLine(), paragraph_->GetMaxIntrinsicWidth()); + if (paragraph_ != nullptr && paragraph_->GetLineCount() == 1) { + return std::max(paragraph_->GetActualWidth(), paragraph_->GetMaxIntrinsicWidth()); } - return paragraph_->GetLongestLine(); + return paragraph_->GetActualWidth(); } bool FlutterRenderText::DidExceedMaxLines(double paragraphMaxWidth) { - auto* paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr) { - bool didExceedMaxLines = paragraphTxt->DidExceedMaxLines() || + if (paragraph_ != nullptr) { + bool didExceedMaxLines = paragraph_->DidExceedMaxLines() || (textStyle_.GetAdaptHeight() && GreatNotEqual(paragraph_->GetHeight(), GetLayoutParam().GetMaxSize().Height())); if (textStyle_.GetMaxLines() == 1) { diff --git a/frameworks/core/components/text/flutter_render_text.h b/frameworks/core/components/text/flutter_render_text.h index ce63241b7262feb893eb1446d5b8a69232ae971a..6cbd45065314517daf4fb7387f55e7444f7fe62c 100644 --- a/frameworks/core/components/text/flutter_render_text.h +++ b/frameworks/core/components/text/flutter_render_text.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_FLUTTER_RENDER_TEXT_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_FLUTTER_RENDER_TEXT_H -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "core/components/text/render_text.h" #include "core/components/text_span/render_text_span.h" diff --git a/frameworks/core/components/text/rosen_render_text.cpp b/frameworks/core/components/text/rosen_render_text.cpp index fc015cbf2a7442efeff3727ee9fbf799f72258ca..d306746cc090ecfcc4c579951ac23d4c0dacb457 100644 --- a/frameworks/core/components/text/rosen_render_text.cpp +++ b/frameworks/core/components/text/rosen_render_text.cpp @@ -19,7 +19,7 @@ #include "flutter/lib/ui/text/font_collection.h" #include "flutter/third_party/icu/source/common/unicode/uchar.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography_create.h" #include "render_service_client/core/ui/rs_node.h" #include "base/geometry/dimension.h" @@ -368,9 +368,8 @@ bool RosenRenderText::UpdateParagraphAndLayout(double paragraphMaxWidth) uint32_t RosenRenderText::GetTextLines() { uint32_t textLines = 0; - auto paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr) { - textLines = paragraphTxt->GetLineCount(); + if (paragraph_ != nullptr) { + textLines = paragraph_->GetLineCount(); } return textLines; } @@ -380,7 +379,7 @@ int32_t RosenRenderText::GetTouchPosition(const Offset& offset) if (!paragraph_) { return 0; } - return static_cast(paragraph_->GetGlyphPositionAtCoordinate(offset.GetX(), offset.GetY()).position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate(offset.GetX(), offset.GetY()).index_); } Size RosenRenderText::GetSize() @@ -438,9 +437,8 @@ void RosenRenderText::ApplyIndents(double width) indents.push_back(0.0); indents.push_back(-indent); } - auto* paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr) { - paragraphTxt->SetIndents(indents); + if (paragraph_ != nullptr) { + paragraph_->SetIndents(indents); } } @@ -452,7 +450,7 @@ bool RosenRenderText::UpdateParagraph() using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; if (alignment_.has_value()) { textStyle_.SetTextAlign(alignment_.value()); @@ -474,32 +472,31 @@ bool RosenRenderText::UpdateParagraph() } } std::string displayData = ApplyWhiteSpace(); - style.text_direction = ConvertTxtTextDirection(defaultTextDirection_); - style.text_align = ConvertTxtTextAlign(textAlign); - style.max_lines = textStyle_.GetMaxLines(); - style.locale = Localization::GetInstance()->GetFontLocale(); + style.textDirection_ = ConvertTxtTextDirection(defaultTextDirection_); + style.textAlign_ = ConvertTxtTextAlign(textAlign); + style.maxLines_ = textStyle_.GetMaxLines(); + style.locale_ = Localization::GetInstance()->GetFontLocale(); if (textStyle_.GetTextOverflow() == TextOverflow::ELLIPSIS) { if (!IsCompatibleVersion() && textStyle_.GetMaxLines() == UINT32_MAX && !text_->GetAutoMaxLines()) { - style.max_lines = 1; + style.maxLines_ = 1; } - style.ellipsis = ELLIPSIS; + style.ellipsis_ = ELLIPSIS; auto context = GetContext().Upgrade(); if (context && context->UseLiteStyle()) { - style.max_lines = 1; + style.maxLines_ = 1; } } - style.word_break_type = static_cast(textStyle_.GetWordBreak()); + style.wordBreakType_ = static_cast(textStyle_.GetWordBreak()); - std::unique_ptr builder; auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("UpdateParagraph: fontCollection is null"); return false; } - builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); + auto builder = Rosen::TypographyCreate::Create(style, fontCollection); std::string textValue = ""; - txt::TextStyle txtStyle; + Rosen::TextStyle txtStyle; ConvertTxtStyle(textStyle_, context_, txtStyle); builder->PushStyle(txtStyle); const auto& children = GetChildren(); @@ -515,9 +512,9 @@ bool RosenRenderText::UpdateParagraph() textForDisplay_ = textValue; } else { StringUtils::TransformStrCase(displayData, (int32_t)textStyle_.GetTextCase()); - builder->AddText(StringUtils::Str8ToStr16(displayData)); + builder->AppendText(StringUtils::Str8ToStr16(displayData)); } - paragraph_ = builder->Build(); + paragraph_ = builder->CreateTypography(); ApplyIndents(GetLayoutParam().GetMaxSize().Width()); return true; @@ -531,18 +528,16 @@ double RosenRenderText::GetTextWidth() if (!IsCompatibleVersion()) { return paragraph_->GetMaxIntrinsicWidth(); } - auto* paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr && paragraphTxt->GetLineCount() == 1) { - return std::max(paragraph_->GetLongestLine(), paragraph_->GetMaxIntrinsicWidth()); + if (paragraph_ != nullptr && paragraph_->GetLineCount() == 1) { + return std::max(paragraph_->GetActualWidth(), paragraph_->GetMaxIntrinsicWidth()); } - return paragraph_->GetLongestLine(); + return paragraph_->GetActualWidth(); } bool RosenRenderText::DidExceedMaxLines(double paragraphMaxWidth) { - auto* paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr) { - bool didExceedMaxLines = paragraphTxt->DidExceedMaxLines() || + if (paragraph_ != nullptr) { + bool didExceedMaxLines = paragraph_->DidExceedMaxLines() || (textStyle_.GetAdaptHeight() && GreatNotEqual(paragraph_->GetHeight(), GetLayoutParam().GetMaxSize().Height())); if (textStyle_.GetMaxLines() == 1) { diff --git a/frameworks/core/components/text/rosen_render_text.h b/frameworks/core/components/text/rosen_render_text.h index f51c0b1786eaae7a29eb44c41f04318b432df7a8..5b9a09fc61017778c73a57f63a17cb80c80eabe9 100644 --- a/frameworks/core/components/text/rosen_render_text.h +++ b/frameworks/core/components/text/rosen_render_text.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_ROSEN_RENDER_TEXT_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_ROSEN_RENDER_TEXT_H -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "core/components/text/render_text.h" #include "core/components/text_span/render_text_span.h" diff --git a/frameworks/core/components/text_field/flutter_render_text_field.cpp b/frameworks/core/components/text_field/flutter_render_text_field.cpp index dd9057263c8c40b6c88edd4cc8b98bcd22311cd5..faeb41673d3c3d9f638f25c79c523a439ac7b5ff 100644 --- a/frameworks/core/components/text_field/flutter_render_text_field.cpp +++ b/frameworks/core/components/text_field/flutter_render_text_field.cpp @@ -18,9 +18,9 @@ #include #include "flutter/lib/ui/text/font_collection.h" -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "flutter/third_party/icu/source/common/unicode/uchar.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/effects/SkGradientShader.h" #include "base/i18n/localization.h" @@ -183,11 +183,11 @@ void FlutterRenderTextField::PaintSelectCaret(SkCanvas* canvas) int32_t start = selection.GetStart(); int32_t end = selection.GetEnd(); - const auto& boxes = paragraph_->GetRectsForRange(selection.GetStart(), selection.GetEnd(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(selection.GetStart(), selection.GetEnd(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (!boxes.empty()) { Offset startCaretOffset = Offset( - boxes.back().rect.fRight - boxes.front().rect.fLeft, boxes.back().rect.fTop - boxes.front().rect.fTop); + boxes.back().rect_.GetRight() - boxes.front().rect_.GetLeft(), boxes.back().rect_.GetTop() - boxes.front().rect_.GetTop()); if (start >= GetInitIndex() && end >= GetInitIndex()) { startCaretRect_ = caretRect + startCaretOffset; } else { @@ -278,8 +278,8 @@ void FlutterRenderTextField::PaintSelection(SkCanvas* canvas) const void FlutterRenderTextField::DrawSelection(unsigned start, unsigned end, SkCanvas* canvas) const { using namespace Constants; - const auto& boxes = paragraph_->GetRectsForRange(start, end, - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(start, end, + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return; } @@ -292,7 +292,7 @@ void FlutterRenderTextField::DrawSelection(unsigned start, unsigned end, SkCanva } Offset effectiveOffset = innerRect_.GetOffset() + textOffsetForShowCaret_; for (const auto& box : boxes) { - auto selectionRect = ConvertSkRect(box.rect) + effectiveOffset; + auto selectionRect = ConvertSkRect(box.rect_) + effectiveOffset; switch (inputStyle_) { case InputStyle::INLINE: selectionRect.SetHeight(GetLayoutSize().Height()); @@ -307,7 +307,7 @@ void FlutterRenderTextField::DrawSelection(unsigned start, unsigned end, SkCanva auto rect = SkRect::MakeLTRB(selectionRect.Right(), selectionRect.Top(), selectionRect.Left(), selectionRect.Bottom()); - if (box.direction == txt::TextDirection::ltr) { + if (box.direction_ == Rosen::TextDirection::LTR) { rect = SkRect::MakeLTRB(selectionRect.Left(), selectionRect.Top(), selectionRect.Right(), selectionRect.Bottom()); } @@ -358,7 +358,7 @@ void FlutterRenderTextField::PaintErrorText(SkCanvas* canvas) const Offset errorOffset = innerRect_.GetOffset(); if (errorIsInner_) { double errorSpacing = - GreatOrEqual(errorParagraph_->GetLongestLine(), originInnerWidth_ - errorSpacing_) ? 0.0 : errorSpacing_; + GreatOrEqual(errorParagraph_->GetActualWidth(), originInnerWidth_ - errorSpacing_) ? 0.0 : errorSpacing_; errorOffset += Offset(innerRect_.Width() + errorSpacing, (innerRect_.Height() - errorParagraph_->GetHeight()) / 2.0); } else { @@ -378,7 +378,7 @@ void FlutterRenderTextField::PaintCountText(SkCanvas* canvas) const } if (ShowCounter()) { Offset countOffset = innerRect_.GetOffset() + - Offset(innerRect_.Width() - countParagraph_->GetLongestLine(), innerRect_.Height()); + Offset(innerRect_.Width() - countParagraph_->GetActualWidth(), innerRect_.Height()); if (maxLines_ == 1) { double bottomPadding = 0.0; if (decoration_) { @@ -542,7 +542,7 @@ Size FlutterRenderTextField::Measure() } auto paragraphStyle = CreateParagraphStyle(); - std::unique_ptr txtStyle; + std::unique_ptr txtStyle; double textAreaWidth = MeasureParagraph(paragraphStyle, txtStyle); ComputeExtendHeight(decorationHeight); @@ -556,15 +556,14 @@ Size FlutterRenderTextField::Measure() } originInnerWidth_ = innerRect_.Width(); if (errorParagraph_ && errorIsInner_) { - double deflateWidth = innerRect_.Width() - errorParagraph_->GetLongestLine() - errorSpacing_; + double deflateWidth = innerRect_.Width() - errorParagraph_->GetActualWidth() - errorSpacing_; innerRect_.SetWidth(GreatOrEqual(deflateWidth, 0.0) ? deflateWidth : 0.0); } // Get height of text - auto paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr) { - textHeight_ = paragraphTxt->GetHeight(); - textLines_ = paragraphTxt->GetLineCount(); + if (paragraph_ != nullptr) { + textHeight_ = paragraph_->GetHeight(); + textLines_ = paragraph_->GetLineCount(); } else { textHeight_ = 0.0; textLines_ = 0; @@ -578,7 +577,7 @@ Size FlutterRenderTextField::Measure() } double FlutterRenderTextField::MeasureParagraph( - const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle) + const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle) { double maxWidth = GetLayoutParam().GetMaxSize().Width(); // If single-line, give it infinity for layout and text will auto scroll following with caret. @@ -614,51 +613,51 @@ double FlutterRenderTextField::MeasureParagraph( countParagraph_.reset(nullptr); placeholderParagraph_.reset(nullptr); if (!errorText_.empty()) { - std::unique_ptr errorBuilder = - txt::ParagraphBuilder::CreateTxtBuilder(*CreateParagraphStyle(true), GetFontCollection()); + std::unique_ptr errorBuilder = + Rosen::TypographyCreate::Create(*CreateParagraphStyle(true), GetFontCollection()); txtStyle = CreateTextStyle(errorTextStyle_); errorBuilder->PushStyle(*txtStyle); - errorBuilder->AddText(StringUtils::Str8ToStr16(errorText_)); - errorParagraph_ = errorBuilder->Build(); + errorBuilder->AppendText(StringUtils::Str8ToStr16(errorText_)); + errorParagraph_ = errorBuilder->CreateTypography(); errorParagraph_->Layout(textAreaWidth); - errorTextWidth = errorIsInner_ ? errorParagraph_->GetLongestLine() : 0.0; + errorTextWidth = errorIsInner_ ? errorParagraph_->GetActualWidth() : 0.0; } if (ShowCounter()) { - std::unique_ptr countBuilder = - txt::ParagraphBuilder::CreateTxtBuilder(*CreateParagraphStyle(), GetFontCollection()); + std::unique_ptr countBuilder = + Rosen::TypographyCreate::Create(*CreateParagraphStyle(), GetFontCollection()); if (overCount_) { txtStyle = CreateTextStyle(maxLines_ == 1 ? overCountStyleOuter_ : overCountStyle_); } else { txtStyle = CreateTextStyle(maxLines_ == 1 ? countTextStyleOuter_ : countTextStyle_); } countBuilder->PushStyle(*txtStyle); - countBuilder->AddText(StringUtils::Str8ToStr16( + countBuilder->AppendText(StringUtils::Str8ToStr16( std::to_string(GetEditingValue().GetWideText().size()) + "/" + std::to_string(maxLength_))); - countParagraph_ = countBuilder->Build(); + countParagraph_ = countBuilder->CreateTypography(); countParagraph_->Layout(textAreaWidth); } if (!showPlaceholder_) { - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(*paragraphStyle, GetFontCollection()); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(*paragraphStyle, GetFontCollection()); txtStyle = CreateTextStyle(style_); builder->PushStyle(*txtStyle); - builder->AddText(displayText); - paragraph_ = builder->Build(); + builder->AppendText(displayText); + paragraph_ = builder->CreateTypography(); paragraph_->Layout(textAreaWidth - errorTextWidth); if ((textDirection_ == TextDirection::RTL || realTextDirection_ == TextDirection::RTL) && - LessOrEqual(paragraph_->GetLongestLine(), innerRect_.Width())) { + LessOrEqual(paragraph_->GetActualWidth(), innerRect_.Width())) { paragraph_->Layout(limitWidth); } } else { - std::unique_ptr placeholderBuilder = - txt::ParagraphBuilder::CreateTxtBuilder(*paragraphStyle, GetFontCollection()); + std::unique_ptr placeholderBuilder = + Rosen::TypographyCreate::Create(*paragraphStyle, GetFontCollection()); txtStyle = CreateTextStyle(style_, true); placeholderBuilder->PushStyle(*txtStyle); - placeholderBuilder->AddText(StringUtils::Str8ToStr16(placeholder_)); - placeholderParagraph_ = placeholderBuilder->Build(); - placeholderParagraph_->Layout(limitWidth - errorTextWidth); + placeholderBuilder->AppendText(StringUtils::Str8ToStr16(placeholder_)); + placeholderParagraph_ = placeholderBuilder->CreateTypography(); + placeholderParagraph_->Layout(textAreaWidth - errorTextWidth); if (textDirection_ == TextDirection::RTL && - LessOrEqual(placeholderParagraph_->GetLongestLine(), innerRect_.Width())) { + LessOrEqual(placeholderParagraph_->GetActualWidth(), innerRect_.Width())) { placeholderParagraph_->Layout(limitWidth); } } @@ -822,7 +821,7 @@ sk_sp FlutterRenderTextField::MakeGradientShader(double shadeWidth) co } void FlutterRenderTextField::SetShaderIfNeeded( - std::unique_ptr paragraphStyle, std::unique_ptr txtStyle, double textAreaWidth) + std::unique_ptr paragraphStyle, std::unique_ptr txtStyle, double textAreaWidth) { if (maxLines_ != 1 || showPlaceholder_ || !paragraph_ || !needFade_) { // Not support placeHolder or multiline. @@ -840,13 +839,13 @@ void FlutterRenderTextField::SetShaderIfNeeded( return; } - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(*paragraphStyle, GetFontCollection()); - txtStyle->has_foreground = true; - txtStyle->foreground.setShader(shader); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(*paragraphStyle, GetFontCollection()); + txtStyle->foreground_ = SkPaint(); + txtStyle->foreground_->setShader(shader); builder->PushStyle(*txtStyle); - builder->AddText(GetTextForDisplay(GetEditingValue().text)); - paragraph_ = builder->Build(); + builder->AppendText(GetTextForDisplay(GetEditingValue().text)); + paragraph_ = builder->CreateTypography(); paragraph_->Layout(textAreaWidth); } @@ -871,24 +870,24 @@ Size FlutterRenderTextField::ComputeLayoutSize(const Size& size, double decorati return Size(maxWidth, innerRect_.Height() + decorationHeight); } -std::unique_ptr FlutterRenderTextField::CreateParagraphStyle(bool isErrorText) +std::unique_ptr FlutterRenderTextField::CreateParagraphStyle(bool isErrorText) { using namespace Constants; - auto style = std::make_unique(); + auto style = std::make_unique(); // If single-line, it shouldn't do soft-wrap for us. if (maxLines_ == 1 && resetToStart_) { - style->max_lines = 1; + style->maxLines_ = 1; if (showEllipsis_ && keyboard_ != TextInputType::VISIBLE_PASSWORD) { - style->ellipsis = StringUtils::Str8ToStr16(ELLIPSIS); + style->ellipsis_ = StringUtils::Str8ToStr16(ELLIPSIS); } } - style->text_align = ConvertTxtTextAlign(textAlign_); - style->font_size = NormalizeToPx(style_.GetFontSize()); + style->textAlign_ = ConvertTxtTextAlign(textAlign_); + style->fontSize_ = NormalizeToPx(style_.GetFontSize()); // If keyboard is password, don't change text_direction with first strong direction letter if (!isErrorText && keyboard_ == TextInputType::VISIBLE_PASSWORD && !GetEditingValue().text.empty()) { - style->text_direction = ConvertTxtTextDirection(textDirection_); + style->textDirection_ = ConvertTxtTextDirection(textDirection_); realTextDirection_ = textDirection_; UpdateDirectionStatus(); return style; @@ -908,13 +907,13 @@ std::unique_ptr FlutterRenderTextField::CreateParagraphStyl for (const auto& charOfShowingText : showingTextForWString) { auto charDirection = u_charDirection(charOfShowingText); if (charDirection == UCharDirection::U_LEFT_TO_RIGHT) { - style->text_direction = ConvertTxtTextDirection(TextDirection::LTR); + style->textDirection_ = ConvertTxtTextDirection(TextDirection::LTR); existStrongDirectionLetter_ = true; realTextDirection_ = TextDirection::LTR; } else if (charDirection == UCharDirection::U_RIGHT_TO_LEFT || charDirection == UCharDirection::U_RIGHT_TO_LEFT_ARABIC || charDirection == UCharDirection::U_ARABIC_NUMBER) { - style->text_direction = ConvertTxtTextDirection(TextDirection::RTL); + style->textDirection_ = ConvertTxtTextDirection(TextDirection::RTL); existStrongDirectionLetter_ = true; realTextDirection_ = TextDirection::RTL; } @@ -923,33 +922,33 @@ std::unique_ptr FlutterRenderTextField::CreateParagraphStyl } } if (!existStrongDirectionLetter_) { - style->text_direction = ConvertTxtTextDirection(textDirection_); + style->textDirection_ = ConvertTxtTextDirection(textDirection_); realTextDirection_ = textDirection_; } UpdateDirectionStatus(); if (keyboard_ != TextInputType::MULTILINE) { - style->word_break_type = minikin::WordBreakType::kWordBreakType_BreakAll; + style->wordBreakType_ = Rosen::WordBreakType::BREAKALL; } return style; } -std::unique_ptr FlutterRenderTextField::CreateTextStyle(const TextStyle& style, bool isPlaceholder) +std::unique_ptr FlutterRenderTextField::CreateTextStyle(const TextStyle& style, bool isPlaceholder) { using namespace Constants; - auto txtStyle = std::make_unique(); + auto txtStyle = std::make_unique(); if (isPlaceholder) { - txtStyle->color = ConvertSkColor(placeholderColor_); + txtStyle->color_ = ConvertSkColor(placeholderColor_); } else { - txtStyle->color = ConvertSkColor(style.GetTextColor()); + txtStyle->color_ = ConvertSkColor(style.GetTextColor()); } - txtStyle->font_families = style.GetFontFamilies(); - txtStyle->font_weight = ConvertTxtFontWeight(style.GetFontWeight()); - txtStyle->font_size = NormalizeToPx(style.GetFontSize()); - txtStyle->font_style = ConvertTxtFontStyle(style.GetFontStyle()); - txtStyle->text_baseline = ConvertTxtTextBaseline(style.GetTextBaseline()); - txtStyle->locale = Localization::GetInstance()->GetFontLocale(); + txtStyle->fontFamilies_ = style.GetFontFamilies(); + txtStyle->fontWeight_ = ConvertTxtFontWeight(style.GetFontWeight()); + txtStyle->fontSize_ = NormalizeToPx(style.GetFontSize()); + txtStyle->fontStyle_ = ConvertTxtFontStyle(style.GetFontStyle()); + txtStyle->baseline_ = ConvertTxtTextBaseline(style.GetTextBaseline()); + txtStyle->locale_ = Localization::GetInstance()->GetFontLocale(); return txtStyle; } @@ -964,23 +963,23 @@ double FlutterRenderTextField::GetBoundaryOfParagraph(bool isLeftBoundary) const if (!paragraph_ || GetEditingValue().text.empty()) { return 0.0; } - auto boxes = paragraph_->GetRectsForRange(0, GetEditingValue().GetWideText().length(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary(0, GetEditingValue().GetWideText().length(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return 0.0; } - double leftBoundaryOfParagraph = boxes.front().rect.fLeft; - double rightBoundaryOfParagraph = boxes.front().rect.fLeft; - double bottomBoundaryOfParagraph = boxes.front().rect.fBottom; + double leftBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double rightBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double bottomBoundaryOfParagraph = boxes.front().rect_.GetBottom(); for (const auto& box : boxes) { - if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect.fBottom, bottomBoundaryOfParagraph)) { - bottomBoundaryOfParagraph = box.rect.fBottom; - leftBoundaryOfParagraph = box.rect.fLeft; - rightBoundaryOfParagraph = box.rect.fRight; + if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect_.GetBottom(), bottomBoundaryOfParagraph)) { + bottomBoundaryOfParagraph = box.rect_.GetBottom(); + leftBoundaryOfParagraph = box.rect_.GetLeft(); + rightBoundaryOfParagraph = box.rect_.GetRight(); continue; } - leftBoundaryOfParagraph = std::min(static_cast(box.rect.fLeft), leftBoundaryOfParagraph); - rightBoundaryOfParagraph = std::max(static_cast(box.rect.fRight), rightBoundaryOfParagraph); + leftBoundaryOfParagraph = std::min(static_cast(box.rect_.GetLeft()), leftBoundaryOfParagraph); + rightBoundaryOfParagraph = std::max(static_cast(box.rect_.GetRight()), rightBoundaryOfParagraph); } return isLeftBoundary ? leftBoundaryOfParagraph : rightBoundaryOfParagraph; } @@ -1000,18 +999,18 @@ bool FlutterRenderTextField::ComputeOffsetForCaretUpstream(int32_t extent, Caret result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !GetEditingValue().text.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { return false; @@ -1023,22 +1022,22 @@ bool FlutterRenderTextField::ComputeOffsetForCaretUpstream(int32_t extent, Caret // Return the start of next line. auto emptyOffset = MakeEmptyOffset(); result.offset.SetX(emptyOffset.GetX()); - result.offset.SetY(textBox.rect.fBottom); + result.offset.SetY(textBox.rect_.GetBottom()); result.height = caretProto_.Height(); return true; } - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the upstream glyphs. - double caretEnd = isLtr ? textBox.rect.fRight : textBox.rect.fLeft; + double caretEnd = isLtr ? textBox.rect_.GetRight() : textBox.rect_.GetLeft(); if (cursorPositionType_ == CursorPositionType::END) { caretEnd = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretEnd : caretEnd - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -1051,24 +1050,24 @@ bool FlutterRenderTextField::ComputeOffsetForCaretDownstream(int32_t extent, Car result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - extent, next, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + extent, next, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return false; } const auto& textBox = *boxes.begin(); - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fLeft : textBox.rect.fRight; + double caretStart = isLtr ? textBox.rect_.GetLeft() : textBox.rect_.GetRight(); if (cursorPositionType_ == CursorPositionType::END) { caretStart = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretStart : caretStart - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -1127,23 +1126,23 @@ Offset FlutterRenderTextField::MakeEmptyOffset() const double FlutterRenderTextField::PreferredLineHeight() { if (!template_) { - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(*CreateParagraphStyle(), GetFontCollection()); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(*CreateParagraphStyle(), GetFontCollection()); builder->PushStyle(*CreateTextStyle(style_)); // Use a space for estimating line height if there is no placeholder. // Actually it has slight differ between cases. if (placeholder_.empty()) { - builder->AddText(u" "); + builder->AppendText(u" "); } else { - builder->AddText(StringUtils::Str8ToStr16(placeholder_)); + builder->AppendText(StringUtils::Str8ToStr16(placeholder_)); } - template_ = builder->Build(); + template_ = builder->CreateTypography(); template_->Layout(Size::INFINITE_SIZE); } return template_->GetHeight(); } -std::shared_ptr FlutterRenderTextField::GetFontCollection() +std::shared_ptr FlutterRenderTextField::GetFontCollection() { return FlutterFontCollection::GetInstance().GetFontCollection(); } @@ -1167,8 +1166,8 @@ int32_t FlutterRenderTextField::GetCursorPositionForMoveUp() return 0; } double verticalOffset = -textOffsetForShowCaret_.GetY() - PreferredLineHeight(); - return static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster( - caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate( + caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).index_); } int32_t FlutterRenderTextField::GetCursorPositionForMoveDown() @@ -1177,8 +1176,8 @@ int32_t FlutterRenderTextField::GetCursorPositionForMoveDown() return 0; } double verticalOffset = -textOffsetForShowCaret_.GetY() + PreferredLineHeight(); - return static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster( - caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate( + caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).index_); } int32_t FlutterRenderTextField::GetCursorPositionForClick(const Offset& offset) @@ -1194,7 +1193,7 @@ int32_t FlutterRenderTextField::GetCursorPositionForClick(const Offset& offset) return 0; } return static_cast( - paragraph_->GetGlyphPositionAtCoordinateWithCluster(clickOffset_.GetX(), clickOffset_.GetY()).position); + paragraph_->GetGlyphIndexByCoordinate(clickOffset_.GetX(), clickOffset_.GetY()).index_); } int32_t FlutterRenderTextField::AdjustCursorAndSelection(int32_t currentCursorPosition) @@ -1203,7 +1202,7 @@ int32_t FlutterRenderTextField::AdjustCursorAndSelection(int32_t currentCursorPo // Place cursor to the right boundary of paragraph when direction is LTR, // place to the left boundary of paragraph when direction is RTL. auto paragraphStyle = CreateParagraphStyle(); - std::unique_ptr txtStyle; + std::unique_ptr txtStyle; MeasureParagraph(paragraphStyle, txtStyle); Rect tempRect; GetCaretRect(currentCursorPosition, tempRect); diff --git a/frameworks/core/components/text_field/flutter_render_text_field.h b/frameworks/core/components/text_field/flutter_render_text_field.h index aa95b29856baa6f1d1de7182d3892d21306d851c..11ab67969640d6429d24c9f225db4da0a9b22183 100644 --- a/frameworks/core/components/text_field/flutter_render_text_field.h +++ b/frameworks/core/components/text_field/flutter_render_text_field.h @@ -23,12 +23,12 @@ #include "core/components/text_field/render_text_field.h" #include "core/pipeline/layers/clip_layer.h" -namespace txt { +namespace OHOS::Rosen { class FontCollection; -class Paragraph; -class ParagraphStyle; -class TextStyle; -} // namespace txt +class Typography; +struct TypographyStyle; +struct TextStyle; +} // namespace OHOS::Rosen namespace flutter { class Canvas; @@ -74,8 +74,8 @@ protected: void ResetStatus() override; private: - std::unique_ptr CreateParagraphStyle(bool isErrorText = false); - std::unique_ptr CreateTextStyle(const TextStyle& style, bool isPlaceholder = false); + std::unique_ptr CreateParagraphStyle(bool isErrorText = false); + std::unique_ptr CreateTextStyle(const TextStyle& style, bool isPlaceholder = false); double PreferredLineHeight() override; void UpdateCaretProto(); @@ -87,7 +87,7 @@ private: Offset MakeEmptyOffset() const; Size Measure() override; double MeasureParagraph( - const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle); + const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle); Size ComputeLayoutSize(const Size& size, double decorationHeight); Rect GetInnerRect(const Decoration& decoration, const Rect& outer, double dipScale) const; @@ -96,10 +96,10 @@ private: void ComputeOffsetAfterLayout(); // Compute the offset to align text and icon to vertical center. Offset ComputeVerticalOffsetForCenter(double outerHeight, double innerHeight) const; - void SetShaderIfNeeded(std::unique_ptr paragraphStyle, - std::unique_ptr txtStyle, double textAreaWidth); + void SetShaderIfNeeded(std::unique_ptr paragraphStyle, + std::unique_ptr txtStyle, double textAreaWidth); sk_sp MakeGradientShader(double shadeWidth) const; - std::shared_ptr GetFontCollection(); + std::shared_ptr GetFontCollection(); void ResetParagraphIfNeeded(); void ComputeExtendHeight(double decorationHeight); double GetBoundaryOfParagraph(bool isLeftBoundary) const; @@ -127,12 +127,12 @@ private: SkVector GetSkRadii(const Radius& radius) const; void PaintFocus(const Offset& offset, const Size& widthHeight, RenderContext& context); - std::unique_ptr paragraph_; - std::unique_ptr errorParagraph_; - std::unique_ptr countParagraph_; - std::unique_ptr placeholderParagraph_; + std::unique_ptr paragraph_; + std::unique_ptr errorParagraph_; + std::unique_ptr countParagraph_; + std::unique_ptr placeholderParagraph_; // Used to estimate size. - std::unique_ptr template_; + std::unique_ptr template_; Rect caretRect_; Rect startCaretRect_; diff --git a/frameworks/core/components/text_field/render_text_field.cpp b/frameworks/core/components/text_field/render_text_field.cpp index 4853b686b258c3bb4a1912c7052b806322c98d3f..8670f9e78d50c858999d8b5ca902cfa25bddb99c 100644 --- a/frameworks/core/components/text_field/render_text_field.cpp +++ b/frameworks/core/components/text_field/render_text_field.cpp @@ -1177,7 +1177,6 @@ bool RenderTextField::RequestKeyboard(bool isFocusViewChanged, bool needStartTwi if (softKeyboardEnabled_) { LOGI("Request open soft keyboard"); #if defined(ENABLE_STANDARD_INPUT) - UpdateConfiguration(); if (textChangeListener_ == nullptr) { textChangeListener_ = new OnTextChangedListenerImpl(WeakClaim(this), context_); } @@ -1191,10 +1190,7 @@ bool RenderTextField::RequestKeyboard(bool isFocusViewChanged, bool needStartTwi LOGI("RequestKeyboard set calling window id is : %{public}d", context->GetWindowId()); inputMethod->SetCallingWindow(context->GetWindowId()); } - MiscServices::InputAttribute inputAttribute; - inputAttribute.inputPattern = (int32_t)keyboard_; - inputAttribute.enterKeyType = (int32_t)action_; - inputMethod->Attach(textChangeListener_, needShowSoftKeyboard, inputAttribute); + inputMethod->Attach(textChangeListener_, needShowSoftKeyboard); #else if (!HasConnection()) { AttachIme(); diff --git a/frameworks/core/components/text_field/rosen_render_text_field.cpp b/frameworks/core/components/text_field/rosen_render_text_field.cpp index 0dd658590e7c49e2b92ba2897e9a3868c98ed52a..295fcad2ec23285a9734c38647fb601933d46ce2 100644 --- a/frameworks/core/components/text_field/rosen_render_text_field.cpp +++ b/frameworks/core/components/text_field/rosen_render_text_field.cpp @@ -17,10 +17,9 @@ #include -#include "flutter/lib/ui/text/font_collection.h" -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/font_collection.h" +#include "rosen_text/typography_create.h" #include "flutter/third_party/icu/source/common/unicode/uchar.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" #include "render_service_client/core/ui/rs_node.h" #include "third_party/skia/include/effects/SkGradientShader.h" @@ -174,11 +173,11 @@ void RosenRenderTextField::PaintSelectCaret(SkCanvas* canvas) int32_t start = selection.GetStart(); int32_t end = selection.GetEnd(); - const auto& boxes = paragraph_->GetRectsForRange(selection.GetStart(), selection.GetEnd(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(selection.GetStart(), selection.GetEnd(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (!boxes.empty()) { Offset startCaretOffset = Offset( - boxes.back().rect.fRight - boxes.front().rect.fLeft, boxes.back().rect.fTop - boxes.front().rect.fTop); + boxes.back().rect_.GetRight() - boxes.front().rect_.GetLeft(), boxes.back().rect_.GetTop() - boxes.front().rect_.GetTop()); if (start >= GetInitIndex() && end >= GetInitIndex()) { startCaretRect_ = caretRect + startCaretOffset; } else { @@ -265,8 +264,8 @@ void RosenRenderTextField::PaintSelection(SkCanvas* canvas) const if (GetEditingValue().text.empty() || selection.GetStart() == selection.GetEnd()) { return; } - const auto& boxes = paragraph_->GetRectsForRange(selection.GetStart(), selection.GetEnd(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(selection.GetStart(), selection.GetEnd(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return; } @@ -279,7 +278,7 @@ void RosenRenderTextField::PaintSelection(SkCanvas* canvas) const } Offset effectiveOffset = innerRect_.GetOffset() + textOffsetForShowCaret_; for (const auto& box : boxes) { - auto selectionRect = ConvertSkRect(box.rect) + effectiveOffset; + auto selectionRect = ConvertSkRect(box.rect_) + effectiveOffset; switch (inputStyle_) { case InputStyle::INLINE: selectionRect.SetHeight(GetLayoutSize().Height()); @@ -294,7 +293,7 @@ void RosenRenderTextField::PaintSelection(SkCanvas* canvas) const auto rect = SkRect::MakeLTRB(selectionRect.Right(), selectionRect.Top(), selectionRect.Left(), selectionRect.Bottom()); - if (box.direction == txt::TextDirection::ltr) { + if (box.direction_ == Rosen::TextDirection::LTR) { rect = SkRect::MakeLTRB(selectionRect.Left(), selectionRect.Top(), selectionRect.Right(), selectionRect.Bottom()); } @@ -325,7 +324,7 @@ void RosenRenderTextField::PaintErrorText(SkCanvas* canvas) const Offset errorOffset = innerRect_.GetOffset(); if (errorIsInner_) { double errorSpacing = - GreatOrEqual(errorParagraph_->GetLongestLine(), originInnerWidth_ - errorSpacing_) ? 0.0 : errorSpacing_; + GreatOrEqual(errorParagraph_->GetActualWidth(), originInnerWidth_ - errorSpacing_) ? 0.0 : errorSpacing_; errorOffset += Offset(innerRect_.Width() + errorSpacing, (innerRect_.Height() - errorParagraph_->GetHeight()) / 2.0); } else { @@ -345,7 +344,7 @@ void RosenRenderTextField::PaintCountText(SkCanvas* canvas) const } if (ShowCounter()) { Offset countOffset = innerRect_.GetOffset() + - Offset(innerRect_.Width() - countParagraph_->GetLongestLine(), innerRect_.Height()); + Offset(innerRect_.Width() - countParagraph_->GetActualWidth(), innerRect_.Height()); if (maxLines_ == 1) { double bottomPadding = 0.0; if (decoration_) { @@ -501,7 +500,7 @@ Size RosenRenderTextField::Measure() } auto paragraphStyle = CreateParagraphStyle(); - std::unique_ptr txtStyle; + std::unique_ptr txtStyle; double textAreaWidth = MeasureParagraph(paragraphStyle, txtStyle); ComputeExtendHeight(decorationHeight); @@ -515,15 +514,14 @@ Size RosenRenderTextField::Measure() } originInnerWidth_ = innerRect_.Width(); if (errorParagraph_ && errorIsInner_) { - double deflateWidth = innerRect_.Width() - errorParagraph_->GetLongestLine() - errorSpacing_; + double deflateWidth = innerRect_.Width() - errorParagraph_->GetActualWidth() - errorSpacing_; innerRect_.SetWidth(GreatOrEqual(deflateWidth, 0.0) ? deflateWidth : 0.0); } // Get height of text - auto paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr) { - textHeight_ = paragraphTxt->GetHeight(); - textLines_ = paragraphTxt->GetLineCount(); + if (paragraph_ != nullptr) { + textHeight_ = paragraph_->GetHeight(); + textLines_ = paragraph_->GetLineCount(); } else { textHeight_ = 0.0; textLines_ = 0; @@ -537,7 +535,7 @@ Size RosenRenderTextField::Measure() } double RosenRenderTextField::MeasureParagraph( - const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle) + const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle) { double maxWidth = GetLayoutParam().GetMaxSize().Width(); // If single-line, give it infinity for layout and text will auto scroll following with caret. @@ -573,51 +571,51 @@ double RosenRenderTextField::MeasureParagraph( countParagraph_.reset(nullptr); placeholderParagraph_.reset(nullptr); if (!errorText_.empty()) { - std::unique_ptr errorBuilder = - txt::ParagraphBuilder::CreateTxtBuilder(*CreateParagraphStyle(true), GetFontCollection()); + std::unique_ptr errorBuilder = + Rosen::TypographyCreate::Create(*CreateParagraphStyle(true), GetFontCollection()); txtStyle = CreateTextStyle(errorTextStyle_); errorBuilder->PushStyle(*txtStyle); - errorBuilder->AddText(StringUtils::Str8ToStr16(errorText_)); - errorParagraph_ = errorBuilder->Build(); + errorBuilder->AppendText(StringUtils::Str8ToStr16(errorText_)); + errorParagraph_ = errorBuilder->CreateTypography(); errorParagraph_->Layout(textAreaWidth); - errorTextWidth = errorIsInner_ ? errorParagraph_->GetLongestLine() : 0.0; + errorTextWidth = errorIsInner_ ? errorParagraph_->GetActualWidth() : 0.0; } if (ShowCounter()) { - std::unique_ptr countBuilder = - txt::ParagraphBuilder::CreateTxtBuilder(*CreateParagraphStyle(), GetFontCollection()); + std::unique_ptr countBuilder = + Rosen::TypographyCreate::Create(*CreateParagraphStyle(), GetFontCollection()); if (overCount_) { txtStyle = CreateTextStyle(maxLines_ == 1 ? overCountStyleOuter_ : overCountStyle_); } else { txtStyle = CreateTextStyle(maxLines_ == 1 ? countTextStyleOuter_ : countTextStyle_); } countBuilder->PushStyle(*txtStyle); - countBuilder->AddText(StringUtils::Str8ToStr16( + countBuilder->AppendText(StringUtils::Str8ToStr16( std::to_string(GetEditingValue().GetWideText().size()) + "/" + std::to_string(maxLength_))); - countParagraph_ = countBuilder->Build(); + countParagraph_ = countBuilder->CreateTypography(); countParagraph_->Layout(textAreaWidth); } if (!showPlaceholder_) { - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(*paragraphStyle, GetFontCollection()); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(*paragraphStyle, GetFontCollection()); txtStyle = CreateTextStyle(style_); builder->PushStyle(*txtStyle); - builder->AddText(displayText); - paragraph_ = builder->Build(); + builder->AppendText(displayText); + paragraph_ = builder->CreateTypography(); paragraph_->Layout(textAreaWidth - errorTextWidth); if ((textDirection_ == TextDirection::RTL || realTextDirection_ == TextDirection::RTL) && - LessOrEqual(paragraph_->GetLongestLine(), innerRect_.Width())) { + LessOrEqual(paragraph_->GetActualWidth(), innerRect_.Width())) { paragraph_->Layout(limitWidth); } } else { - std::unique_ptr placeholderBuilder = - txt::ParagraphBuilder::CreateTxtBuilder(*paragraphStyle, GetFontCollection()); + std::unique_ptr placeholderBuilder = + Rosen::TypographyCreate::Create(*paragraphStyle, GetFontCollection()); txtStyle = CreateTextStyle(style_, true); placeholderBuilder->PushStyle(*txtStyle); - placeholderBuilder->AddText(StringUtils::Str8ToStr16(placeholder_)); - placeholderParagraph_ = placeholderBuilder->Build(); - placeholderParagraph_->Layout(limitWidth - errorTextWidth); + placeholderBuilder->AppendText(StringUtils::Str8ToStr16(placeholder_)); + placeholderParagraph_ = placeholderBuilder->CreateTypography(); + placeholderParagraph_->Layout(textAreaWidth - errorTextWidth); if (textDirection_ == TextDirection::RTL && - LessOrEqual(placeholderParagraph_->GetLongestLine(), innerRect_.Width())) { + LessOrEqual(placeholderParagraph_->GetActualWidth(), innerRect_.Width())) { placeholderParagraph_->Layout(limitWidth); } } @@ -749,7 +747,7 @@ sk_sp RosenRenderTextField::MakeGradientShader(double shadeWidth) cons } void RosenRenderTextField::SetShaderIfNeeded( - std::unique_ptr paragraphStyle, std::unique_ptr txtStyle, double textAreaWidth) + std::unique_ptr paragraphStyle, std::unique_ptr txtStyle, double textAreaWidth) { if (maxLines_ != 1 || showPlaceholder_ || !paragraph_ || !needFade_) { // Not support placeHolder or multiline. @@ -767,13 +765,13 @@ void RosenRenderTextField::SetShaderIfNeeded( return; } - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(*paragraphStyle, GetFontCollection()); - txtStyle->has_foreground = true; - txtStyle->foreground.setShader(shader); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(*paragraphStyle, GetFontCollection()); + txtStyle->foreground_ = SkPaint(); + txtStyle->foreground_->setShader(shader); builder->PushStyle(*txtStyle); - builder->AddText(GetTextForDisplay(GetEditingValue().text)); - paragraph_ = builder->Build(); + builder->AppendText(GetTextForDisplay(GetEditingValue().text)); + paragraph_ = builder->CreateTypography(); paragraph_->Layout(textAreaWidth); } @@ -798,24 +796,24 @@ Size RosenRenderTextField::ComputeLayoutSize(const Size& size, double decoration return Size(maxWidth, innerRect_.Height() + decorationHeight); } -std::unique_ptr RosenRenderTextField::CreateParagraphStyle(bool isErrorText) +std::unique_ptr RosenRenderTextField::CreateParagraphStyle(bool isErrorText) { using namespace Constants; - auto style = std::make_unique(); + auto style = std::make_unique(); // If single-line, it shouldn't do soft-wrap for us. if (maxLines_ == 1 && resetToStart_) { - style->max_lines = 1; + style->maxLines_ = 1; if (showEllipsis_ && keyboard_ != TextInputType::VISIBLE_PASSWORD) { - style->ellipsis = StringUtils::Str8ToStr16(ELLIPSIS); + style->ellipsis_ = StringUtils::Str8ToStr16(ELLIPSIS); } } - style->text_align = ConvertTxtTextAlign(textAlign_); - style->font_size = NormalizeToPx(style_.GetFontSize()); + style->textAlign_ = ConvertTxtTextAlign(textAlign_); + style->fontSize_ = NormalizeToPx(style_.GetFontSize()); // If keyboard is password, don't change text_direction with first strong direction letter if (!isErrorText && keyboard_ == TextInputType::VISIBLE_PASSWORD && !GetEditingValue().text.empty()) { - style->text_direction = ConvertTxtTextDirection(textDirection_); + style->textDirection_ = ConvertTxtTextDirection(textDirection_); realTextDirection_ = textDirection_; UpdateDirectionStatus(); return style; @@ -835,13 +833,13 @@ std::unique_ptr RosenRenderTextField::CreateParagraphStyle( for (const auto& charOfShowingText : showingTextForWString) { auto charDirection = u_charDirection(charOfShowingText); if (charDirection == UCharDirection::U_LEFT_TO_RIGHT) { - style->text_direction = ConvertTxtTextDirection(TextDirection::LTR); + style->textDirection_ = ConvertTxtTextDirection(TextDirection::LTR); existStrongDirectionLetter_ = true; realTextDirection_ = TextDirection::LTR; } else if (charDirection == UCharDirection::U_RIGHT_TO_LEFT || charDirection == UCharDirection::U_RIGHT_TO_LEFT_ARABIC || charDirection == UCharDirection::U_ARABIC_NUMBER) { - style->text_direction = ConvertTxtTextDirection(TextDirection::RTL); + style->textDirection_ = ConvertTxtTextDirection(TextDirection::RTL); existStrongDirectionLetter_ = true; realTextDirection_ = TextDirection::RTL; } @@ -850,33 +848,33 @@ std::unique_ptr RosenRenderTextField::CreateParagraphStyle( } } if (!existStrongDirectionLetter_) { - style->text_direction = ConvertTxtTextDirection(textDirection_); + style->textDirection_ = ConvertTxtTextDirection(textDirection_); realTextDirection_ = textDirection_; } UpdateDirectionStatus(); if (keyboard_ != TextInputType::MULTILINE) { - style->word_break_type = minikin::WordBreakType::kWordBreakType_BreakAll; + style->wordBreakType_ = Rosen::WordBreakType::BREAKALL; } return style; } -std::unique_ptr RosenRenderTextField::CreateTextStyle(const TextStyle& style, bool isPlaceholder) +std::unique_ptr RosenRenderTextField::CreateTextStyle(const TextStyle& style, bool isPlaceholder) { using namespace Constants; - auto txtStyle = std::make_unique(); + auto txtStyle = std::make_unique(); if (isPlaceholder) { - txtStyle->color = ConvertSkColor(placeholderColor_); + txtStyle->color_ = ConvertSkColor(placeholderColor_); } else { - txtStyle->color = ConvertSkColor(style.GetTextColor()); + txtStyle->color_ = ConvertSkColor(style.GetTextColor()); } - txtStyle->font_families = style.GetFontFamilies(); - txtStyle->font_weight = ConvertTxtFontWeight(style.GetFontWeight()); - txtStyle->font_size = NormalizeToPx(style.GetFontSize()); - txtStyle->font_style = ConvertTxtFontStyle(style.GetFontStyle()); - txtStyle->text_baseline = ConvertTxtTextBaseline(style.GetTextBaseline()); - txtStyle->locale = Localization::GetInstance()->GetFontLocale(); + txtStyle->fontFamilies_ = style.GetFontFamilies(); + txtStyle->fontWeight_ = ConvertTxtFontWeight(style.GetFontWeight()); + txtStyle->fontSize_ = NormalizeToPx(style.GetFontSize()); + txtStyle->fontStyle_ = ConvertTxtFontStyle(style.GetFontStyle()); + txtStyle->baseline_ = ConvertTxtTextBaseline(style.GetTextBaseline()); + txtStyle->locale_ = Localization::GetInstance()->GetFontLocale(); return txtStyle; } @@ -891,23 +889,23 @@ double RosenRenderTextField::GetBoundaryOfParagraph(bool isLeftBoundary) const if (!paragraph_ || GetEditingValue().text.empty()) { return 0.0; } - auto boxes = paragraph_->GetRectsForRange(0, GetEditingValue().GetWideText().length(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary(0, GetEditingValue().GetWideText().length(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return 0.0; } - double leftBoundaryOfParagraph = boxes.front().rect.fLeft; - double rightBoundaryOfParagraph = boxes.front().rect.fLeft; - double bottomBoundaryOfParagraph = boxes.front().rect.fBottom; + double leftBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double rightBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double bottomBoundaryOfParagraph = boxes.front().rect_.GetBottom(); for (const auto& box : boxes) { - if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect.fBottom, bottomBoundaryOfParagraph)) { - bottomBoundaryOfParagraph = box.rect.fBottom; - leftBoundaryOfParagraph = box.rect.fLeft; - rightBoundaryOfParagraph = box.rect.fRight; + if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect_.GetBottom(), bottomBoundaryOfParagraph)) { + bottomBoundaryOfParagraph = box.rect_.GetBottom(); + leftBoundaryOfParagraph = box.rect_.GetLeft(); + rightBoundaryOfParagraph = box.rect_.GetRight(); continue; } - leftBoundaryOfParagraph = std::min(static_cast(box.rect.fLeft), leftBoundaryOfParagraph); - rightBoundaryOfParagraph = std::max(static_cast(box.rect.fRight), rightBoundaryOfParagraph); + leftBoundaryOfParagraph = std::min(static_cast(box.rect_.GetLeft()), leftBoundaryOfParagraph); + rightBoundaryOfParagraph = std::max(static_cast(box.rect_.GetRight()), rightBoundaryOfParagraph); } return isLeftBoundary ? leftBoundaryOfParagraph : rightBoundaryOfParagraph; } @@ -927,18 +925,18 @@ bool RosenRenderTextField::ComputeOffsetForCaretUpstream(int32_t extent, CaretMe result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !GetEditingValue().text.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { return false; @@ -950,22 +948,22 @@ bool RosenRenderTextField::ComputeOffsetForCaretUpstream(int32_t extent, CaretMe // Return the start of next line. auto emptyOffset = MakeEmptyOffset(); result.offset.SetX(emptyOffset.GetX()); - result.offset.SetY(textBox.rect.fBottom); + result.offset.SetY(textBox.rect_.GetBottom()); result.height = caretProto_.Height(); return true; } - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the upstream glyphs. - double caretEnd = isLtr ? textBox.rect.fRight : textBox.rect.fLeft; + double caretEnd = isLtr ? textBox.rect_.GetRight() : textBox.rect_.GetLeft(); if (cursorPositionType_ == CursorPositionType::END) { caretEnd = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretEnd : caretEnd - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -978,24 +976,24 @@ bool RosenRenderTextField::ComputeOffsetForCaretDownstream(int32_t extent, Caret result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - extent, next, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + extent, next, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return false; } const auto& textBox = *boxes.begin(); - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fLeft : textBox.rect.fRight; + double caretStart = isLtr ? textBox.rect_.GetLeft() : textBox.rect_.GetRight(); if (cursorPositionType_ == CursorPositionType::END) { caretStart = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretStart : caretStart - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -1054,23 +1052,23 @@ Offset RosenRenderTextField::MakeEmptyOffset() const double RosenRenderTextField::PreferredLineHeight() { if (!template_) { - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(*CreateParagraphStyle(), GetFontCollection()); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(*CreateParagraphStyle(), GetFontCollection()); builder->PushStyle(*CreateTextStyle(style_)); // Use a space for estimating line height if there is no placeholder. // Actually it has slight differ between cases. if (placeholder_.empty()) { - builder->AddText(u" "); + builder->AppendText(u" "); } else { - builder->AddText(StringUtils::Str8ToStr16(placeholder_)); + builder->AppendText(StringUtils::Str8ToStr16(placeholder_)); } - template_ = builder->Build(); + template_ = builder->CreateTypography(); template_->Layout(Size::INFINITE_SIZE); } return template_->GetHeight(); } -std::shared_ptr RosenRenderTextField::GetFontCollection() +std::shared_ptr RosenRenderTextField::GetFontCollection() { return RosenFontCollection::GetInstance().GetFontCollection(); } @@ -1094,8 +1092,8 @@ int32_t RosenRenderTextField::GetCursorPositionForMoveUp() return 0; } double verticalOffset = -textOffsetForShowCaret_.GetY() - PreferredLineHeight(); - return static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster( - caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate( + caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).index_); } int32_t RosenRenderTextField::GetCursorPositionForMoveDown() @@ -1104,8 +1102,8 @@ int32_t RosenRenderTextField::GetCursorPositionForMoveDown() return 0; } double verticalOffset = -textOffsetForShowCaret_.GetY() + PreferredLineHeight(); - return static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster( - caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate( + caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).index_); } int32_t RosenRenderTextField::GetCursorPositionForClick(const Offset& offset) @@ -1121,7 +1119,7 @@ int32_t RosenRenderTextField::GetCursorPositionForClick(const Offset& offset) return 0; } return static_cast( - paragraph_->GetGlyphPositionAtCoordinateWithCluster(clickOffset_.GetX(), clickOffset_.GetY()).position); + paragraph_->GetGlyphIndexByCoordinate(clickOffset_.GetX(), clickOffset_.GetY()).index_); } int32_t RosenRenderTextField::AdjustCursorAndSelection(int32_t currentCursorPosition) @@ -1130,7 +1128,7 @@ int32_t RosenRenderTextField::AdjustCursorAndSelection(int32_t currentCursorPosi // Place cursor to the right boundary of paragraph when direction is LTR, // place to the left boundary of paragraph when direction is RTL. auto paragraphStyle = CreateParagraphStyle(); - std::unique_ptr txtStyle; + std::unique_ptr txtStyle; MeasureParagraph(paragraphStyle, txtStyle); Rect tempRect; GetCaretRect(currentCursorPosition, tempRect); diff --git a/frameworks/core/components/text_field/rosen_render_text_field.h b/frameworks/core/components/text_field/rosen_render_text_field.h index 64d788f1ea2c20c1459068430abc9c6caaee4e73..56e790d8d95c518cb1ef3abddc1861e8f2ce4afd 100644 --- a/frameworks/core/components/text_field/rosen_render_text_field.h +++ b/frameworks/core/components/text_field/rosen_render_text_field.h @@ -19,18 +19,20 @@ #include #include -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/font_collection.h" +#include "rosen_text/typography.h" +#include "rosen_text/typography_style.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" #include "core/components/common/properties/decoration.h" #include "core/components/text_field/render_text_field.h" -namespace txt { +namespace OHOS::Rosen { class FontCollection; -class ParagraphStyle; -class TextStyle; -} // namespace txt +struct TypographyStyle; +struct TextStyle; +} // namespace OHOS::Rosen namespace OHOS::Ace { class Component; @@ -70,8 +72,8 @@ protected: void ResetStatus() override; private: - std::unique_ptr CreateParagraphStyle(bool isErrorText = false); - std::unique_ptr CreateTextStyle(const TextStyle& style, bool isPlaceholder = false); + std::unique_ptr CreateParagraphStyle(bool isErrorText = false); + std::unique_ptr CreateTextStyle(const TextStyle& style, bool isPlaceholder = false); double PreferredLineHeight() override; void UpdateCaretProto(); @@ -83,7 +85,7 @@ private: Offset MakeEmptyOffset() const; Size Measure() override; double MeasureParagraph( - const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle); + const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle); Size ComputeLayoutSize(const Size& size, double decorationHeight); Rect GetInnerRect(const Decoration& decoration, const Rect& outer, double dipScale) const; @@ -92,10 +94,10 @@ private: void ComputeOffsetAfterLayout(); // Compute the offset to align text and icon to vertical center. Offset ComputeVerticalOffsetForCenter(double outerHeight, double innerHeight) const; - void SetShaderIfNeeded(std::unique_ptr paragraphStyle, - std::unique_ptr txtStyle, double textAreaWidth); + void SetShaderIfNeeded(std::unique_ptr paragraphStyle, + std::unique_ptr txtStyle, double textAreaWidth); sk_sp MakeGradientShader(double shadeWidth) const; - std::shared_ptr GetFontCollection(); + std::shared_ptr GetFontCollection(); void ResetParagraphIfNeeded(); void ComputeExtendHeight(double decorationHeight); double GetBoundaryOfParagraph(bool isLeftBoundary) const; @@ -119,12 +121,12 @@ private: SkVector GetSkRadii(const Radius& radius) const; void PaintFocus(const Offset& offset, const Size& widthHeight, RenderContext& context); - std::unique_ptr paragraph_; - std::unique_ptr errorParagraph_; - std::unique_ptr countParagraph_; - std::unique_ptr placeholderParagraph_; + std::unique_ptr paragraph_; + std::unique_ptr errorParagraph_; + std::unique_ptr countParagraph_; + std::unique_ptr placeholderParagraph_; // Used to estimate size. - std::unique_ptr template_; + std::unique_ptr template_; Rect startCaretRect_; Size lastLayoutSize_; diff --git a/frameworks/core/components/text_overlay/text_overlay_manager.cpp b/frameworks/core/components/text_overlay/text_overlay_manager.cpp index 6f24b9565858878ad4a86245276495de6aae5310..aff4aa043568efceacd6ccd94bea02be0865744a 100644 --- a/frameworks/core/components/text_overlay/text_overlay_manager.cpp +++ b/frameworks/core/components/text_overlay/text_overlay_manager.cpp @@ -21,8 +21,9 @@ #include "core/components/font/constants_converter.h" #include "core/components/stack/stack_element.h" #include "core/components/text_overlay/text_overlay_component.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/core/SkCanvas.h" +#include "unicode/uchar.h" namespace OHOS::Ace { @@ -83,23 +84,23 @@ double TextOverlayBase::GetBoundaryOfParagraph(bool isLeftBoundary) const if (!paragraph_ || textValue_.text.empty()) { return 0.0; } - auto boxes = paragraph_->GetRectsForRange(0, textValue_.GetWideText().length(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary(0, textValue_.GetWideText().length(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return 0.0; } - double leftBoundaryOfParagraph = boxes.front().rect.fLeft; - double rightBoundaryOfParagraph = boxes.front().rect.fLeft; - double bottomBoundaryOfParagraph = boxes.front().rect.fBottom; + double leftBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double rightBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double bottomBoundaryOfParagraph = boxes.front().rect_.GetBottom(); for (const auto& box : boxes) { - if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect.fBottom, bottomBoundaryOfParagraph)) { - bottomBoundaryOfParagraph = box.rect.fBottom; - leftBoundaryOfParagraph = box.rect.fLeft; - rightBoundaryOfParagraph = box.rect.fRight; + if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect_.GetBottom(), bottomBoundaryOfParagraph)) { + bottomBoundaryOfParagraph = box.rect_.GetBottom(); + leftBoundaryOfParagraph = box.rect_.GetLeft(); + rightBoundaryOfParagraph = box.rect_.GetRight(); continue; } - leftBoundaryOfParagraph = std::min(static_cast(box.rect.fLeft), leftBoundaryOfParagraph); - rightBoundaryOfParagraph = std::max(static_cast(box.rect.fRight), rightBoundaryOfParagraph); + leftBoundaryOfParagraph = std::min(static_cast(box.rect_.GetLeft()), leftBoundaryOfParagraph); + rightBoundaryOfParagraph = std::max(static_cast(box.rect_.GetRight()), rightBoundaryOfParagraph); } return isLeftBoundary ? leftBoundaryOfParagraph : rightBoundaryOfParagraph; } @@ -119,18 +120,18 @@ bool TextOverlayBase::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !textValue_.text.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { return false; @@ -142,22 +143,22 @@ bool TextOverlayBase::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics // Return the start of next line. auto emptyOffset = MakeEmptyOffset(); result.offset.SetX(emptyOffset.GetX()); - result.offset.SetY(textBox.rect.fBottom); + result.offset.SetY(textBox.rect_.GetBottom()); result.height = caretProto_.Height(); return true; } - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the upstream glyphs. - double caretEnd = isLtr ? textBox.rect.fRight : textBox.rect.fLeft; + double caretEnd = isLtr ? textBox.rect_.GetRight() : textBox.rect_.GetLeft(); if (cursorPositionType_ == CursorPositionType::END) { caretEnd = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretEnd : caretEnd - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -171,24 +172,24 @@ bool TextOverlayBase::ComputeOffsetForCaretDownstream(int32_t extent, CaretMetri result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - extent, next, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + extent, next, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return false; } const auto& textBox = *boxes.begin(); - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fLeft : textBox.rect.fRight; + double caretStart = isLtr ? textBox.rect_.GetLeft() : textBox.rect_.GetRight(); if (cursorPositionType_ == CursorPositionType::END) { caretStart = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretStart : caretStart - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -281,13 +282,13 @@ int32_t TextOverlayBase::GetCursorPositionForClick(const Offset& offset, const O double rightBoundary = GetBoundaryOfParagraph(false); if (GreatOrEqual(clickOffset_.GetX(), rightBoundary)) { int32_t rightBoundaryPosition = - static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster( - rightBoundary - cursorWidth_, clickOffset_.GetY()).position); + static_cast(paragraph_->GetGlyphIndexByCoordinate( + rightBoundary - cursorWidth_, clickOffset_.GetY()).index_); return realTextDirection_ == TextDirection::RTL ? 0 : rightBoundaryPosition; } return static_cast( - paragraph_->GetGlyphPositionAtCoordinate(clickOffset_.GetX(), clickOffset_.GetY()).position); + paragraph_->GetGlyphIndexByCoordinate(clickOffset_.GetX(), clickOffset_.GetY()).index_); } int32_t TextOverlayBase::GetGraphemeClusterLength(int32_t extend, bool isPrefix) const @@ -367,8 +368,8 @@ void TextOverlayBase::PaintSelection(SkCanvas* canvas, const Offset& globalOffse if (textValue_.text.empty() || selection.GetStart() == selection.GetEnd()) { return; } - const auto& boxes = paragraph_->GetRectsForRange(selection.GetStart(), selection.GetEnd(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(selection.GetStart(), selection.GetEnd(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return; } @@ -377,9 +378,9 @@ void TextOverlayBase::PaintSelection(SkCanvas* canvas, const Offset& globalOffse paint.setColor(selectedColor_.GetValue()); Offset effectiveOffset = textOffsetForShowCaret_; for (const auto& box : boxes) { - auto selectionRect = ConvertSkRect(box.rect) + effectiveOffset; + auto selectionRect = ConvertSkRect(box.rect_) + effectiveOffset; selectedRect_.emplace_back(selectionRect + globalOffset); - if (box.direction == txt::TextDirection::ltr) { + if (box.direction_ == Rosen::TextDirection::LTR) { canvas->drawRect(SkRect::MakeLTRB(selectionRect.Left(), selectionRect.Top(), selectionRect.Right(), selectionRect.Bottom()), paint); diff --git a/frameworks/core/components/text_overlay/text_overlay_manager.h b/frameworks/core/components/text_overlay/text_overlay_manager.h index 5f9f17ca8ad8bebf884d616fa60a39d0c7dac7e5..b14417d4781ae005b52373c6a8c1ffe9fc868be2 100644 --- a/frameworks/core/components/text_overlay/text_overlay_manager.h +++ b/frameworks/core/components/text_overlay/text_overlay_manager.h @@ -24,8 +24,8 @@ #include "frameworks/core/common/ime/text_editing_value.h" #include "frameworks/core/pipeline/base/overlay_show_option.h" -namespace txt { -class Paragraph; +namespace OHOS::Rosen { +class Typography; } class SkCanvas; @@ -142,7 +142,7 @@ public: bool IsSelectedText(const Offset& pos, const Offset& globalOffset); protected: - std::shared_ptr paragraph_; + std::shared_ptr paragraph_; CursorPositionType cursorPositionType_ = CursorPositionType::NORMAL; DirectionStatus directionStatus_ = DirectionStatus::LEFT_LEFT; Offset clickOffset_; diff --git a/frameworks/core/components/text_span/flutter_render_text_span.cpp b/frameworks/core/components/text_span/flutter_render_text_span.cpp index 60cb2b35037c805283af3eab0a8d2964f612c62e..0b6ede8372ba036bbe463bb50441df50bcf2def1 100644 --- a/frameworks/core/components/text_span/flutter_render_text_span.cpp +++ b/frameworks/core/components/text_span/flutter_render_text_span.cpp @@ -21,7 +21,7 @@ namespace OHOS::Ace { -void FlutterRenderTextSpan::UpdateText(txt::ParagraphBuilder& builder, +void FlutterRenderTextSpan::UpdateText(Rosen::TypographyCreate& builder, std::map>& touchRegions, std::string& textValue) { if (!spanComponent_) { @@ -34,14 +34,14 @@ void FlutterRenderTextSpan::UpdateText(txt::ParagraphBuilder& builder, } if (spanComponent_->HasNewStyle()) { LOGD("test span has new style"); - txt::TextStyle style; + Rosen::TextStyle style; Constants::ConvertTxtStyle(spanStyle_, context_, style); builder.PushStyle(style); } UpdateTouchRegions(touchRegions); auto displayText = spanComponent_->GetSpanData(); StringUtils::TransformStrCase(displayText, (int32_t)spanStyle_.GetTextCase()); - builder.AddText(StringUtils::Str8ToStr16(displayText)); + builder.AppendText(StringUtils::Str8ToStr16(displayText)); textValue.append(displayText); for (const auto& child : GetChildren()) { auto flutterRenderTextSpan = AceType::DynamicCast(child); @@ -50,7 +50,7 @@ void FlutterRenderTextSpan::UpdateText(txt::ParagraphBuilder& builder, } } if (spanComponent_->HasNewStyle()) { - builder.Pop(); + builder.PopStyle(); } } diff --git a/frameworks/core/components/text_span/flutter_render_text_span.h b/frameworks/core/components/text_span/flutter_render_text_span.h index 6fbfdc971498978d5cee0ecab0343ab1437d4e6a..7e1873193ef5fbb513085fd2e9389615d9906e90 100644 --- a/frameworks/core/components/text_span/flutter_render_text_span.h +++ b/frameworks/core/components/text_span/flutter_render_text_span.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_SPAN_FLUTTER_RENDER_TEXT_SPAN_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_SPAN_FLUTTER_RENDER_TEXT_SPAN_H -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "core/components/text_span/render_text_span.h" #include "core/gestures/gesture_type.h" @@ -32,7 +32,7 @@ public: ~FlutterRenderTextSpan() override = default; // Called by parent to add text with style to builder. - void UpdateText(txt::ParagraphBuilder& builder, + void UpdateText(Rosen::TypographyCreate& builder, std::map>& touchRegions, std::string& textValue); private: diff --git a/frameworks/core/components/text_span/rosen_render_text_span.cpp b/frameworks/core/components/text_span/rosen_render_text_span.cpp index 17964ffb991fc4f30b9645cec736d17ba2a7239d..ce6b74563ef195f1e71978ff82f6283488684abc 100644 --- a/frameworks/core/components/text_span/rosen_render_text_span.cpp +++ b/frameworks/core/components/text_span/rosen_render_text_span.cpp @@ -21,7 +21,7 @@ namespace OHOS::Ace { -void RosenRenderTextSpan::UpdateText(txt::ParagraphBuilder& builder, +void RosenRenderTextSpan::UpdateText(Rosen::TypographyCreate& builder, std::map>& touchRegions, std::string& textValue) { if (!spanComponent_) { @@ -34,14 +34,14 @@ void RosenRenderTextSpan::UpdateText(txt::ParagraphBuilder& builder, } if (spanComponent_->HasNewStyle()) { LOGD("test span has new style"); - txt::TextStyle style; + Rosen::TextStyle style; Constants::ConvertTxtStyle(spanStyle_, context_, style); builder.PushStyle(style); } UpdateTouchRegions(touchRegions); auto displayText = spanComponent_->GetSpanData(); StringUtils::TransformStrCase(displayText, (int32_t)spanStyle_.GetTextCase()); - builder.AddText(StringUtils::Str8ToStr16(displayText)); + builder.AppendText(StringUtils::Str8ToStr16(displayText)); textValue.append(displayText); for (const auto& child : GetChildren()) { auto rosenRenderTextSpan = AceType::DynamicCast(child); @@ -50,7 +50,7 @@ void RosenRenderTextSpan::UpdateText(txt::ParagraphBuilder& builder, } } if (spanComponent_->HasNewStyle()) { - builder.Pop(); + builder.PopStyle(); } } diff --git a/frameworks/core/components/text_span/rosen_render_text_span.h b/frameworks/core/components/text_span/rosen_render_text_span.h index 6a3e3ba6e254038c5e8369accad6fc78f9cea650..b61b907dfbc8d6b0ec4599386167b9ad20a9ae3f 100644 --- a/frameworks/core/components/text_span/rosen_render_text_span.h +++ b/frameworks/core/components/text_span/rosen_render_text_span.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_SPAN_ROSEN_RENDER_TEXT_SPAN_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_SPAN_ROSEN_RENDER_TEXT_SPAN_H -#include "flutter/lib/ui/text/paragraph_builder.h" +#include "rosen_text/typography_create.h" #include "core/components/text_span/render_text_span.h" #include "core/gestures/gesture_type.h" @@ -31,7 +31,7 @@ public: ~RosenRenderTextSpan() override = default; // Called by parent to add text with style to builder. - void UpdateText(txt::ParagraphBuilder& builder, + void UpdateText(Rosen::TypographyCreate& builder, std::map>& touchRegions, std::string& textValue); private: diff --git a/frameworks/core/components/track/flutter_render_arc_track.cpp b/frameworks/core/components/track/flutter_render_arc_track.cpp index 9bb867344f80a7710d6527a4b9ef977b1c9aa5fc..366f43f7e736543f07e937a2c76457df38a690bf 100644 --- a/frameworks/core/components/track/flutter_render_arc_track.cpp +++ b/frameworks/core/components/track/flutter_render_arc_track.cpp @@ -18,8 +18,8 @@ #include "core/components/font/flutter_font_collection.h" #include "core/pipeline/base/scoped_canvas_state.h" #include "flutter/lib/ui/painting/path.h" -#include "flutter/lib/ui/text/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/core/SkClipOp.h" namespace OHOS::Ace { @@ -75,20 +75,20 @@ void SetTextStyle(const ScopedCanvas& canvas, const RenderRingInfo& trackInfo, } double pathStartVertexX = trackInfo.center.GetX(); double pathStartVertexY = trackInfo.center.GetY() - trackInfo.radius + (trackInfo.thickness / 2); - txt::ParagraphStyle style; - txt::TextStyle txtStyle; - txtStyle.font_size = 80; - txtStyle.font_weight = txt::FontWeight::w400; - txtStyle.color = markedColor.GetValue(); - std::unique_ptr builder; - style.max_lines = 1; - builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); + Rosen::TypographyStyle style; + Rosen::TextStyle txtStyle; + txtStyle.fontSize_ = 80; + txtStyle.fontWeight_ = Rosen::FontWeight::W400; + txtStyle.color_ = markedColor.GetValue(); + std::unique_ptr builder; + style.maxLines_ = 1; + builder = Rosen::TypographyCreate::Create(style, fontCollection); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(markedText)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(markedText)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(dataRegion.Width()); paragraph->Paint( - canvas->canvas(), pathStartVertexX - txtStyle.font_size, pathStartVertexY + EDGE + HEIGHT_OFFSET * 2); + canvas->canvas(), pathStartVertexX - txtStyle.fontSize_, pathStartVertexY + EDGE + HEIGHT_OFFSET * 2); } void DrawIndicator(RenderContext& context, const RenderRingInfo& trackInfo, diff --git a/frameworks/core/components/track/rosen_render_arc_track.cpp b/frameworks/core/components/track/rosen_render_arc_track.cpp index e547bd5c4606b59837e17187d652f98079b72bb6..50d29d371f75a3933a9be2097c7d339652ecbcf9 100644 --- a/frameworks/core/components/track/rosen_render_arc_track.cpp +++ b/frameworks/core/components/track/rosen_render_arc_track.cpp @@ -15,8 +15,8 @@ #include "core/components/track/rosen_render_arc_track.h" -#include "flutter/lib/ui/text/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkClipOp.h" #include "third_party/skia/include/core/SkPaint.h" @@ -77,19 +77,19 @@ void SetTextStyle(SkCanvas* canvas, const RenderRingInfo& trackInfo, const std:: } double pathStartVertexX = trackInfo.center.GetX(); double pathStartVertexY = trackInfo.center.GetY() - trackInfo.radius + (trackInfo.thickness / 2); - txt::ParagraphStyle style; - txt::TextStyle txtStyle; - txtStyle.font_size = 80; - txtStyle.font_weight = txt::FontWeight::w400; - txtStyle.color = markedColor.GetValue(); - std::unique_ptr builder; - style.max_lines = 1; - builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); + Rosen::TypographyStyle style; + Rosen::TextStyle txtStyle; + txtStyle.fontSize_ = 80; + txtStyle.fontWeight_ = Rosen::FontWeight::W400; + txtStyle.color_ = markedColor.GetValue(); + std::unique_ptr builder; + style.maxLines_ = 1; + builder = Rosen::TypographyCreate::Create(style, fontCollection); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(markedText)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(markedText)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(dataRegion.Width()); - paragraph->Paint(canvas, pathStartVertexX - txtStyle.font_size, pathStartVertexY + EDGE + HEIGHT_OFFSET * 2); + paragraph->Paint(canvas, pathStartVertexX - txtStyle.fontSize_, pathStartVertexY + EDGE + HEIGHT_OFFSET * 2); } void DrawIndicator(RenderContext& context, const RenderRingInfo& trackInfo, const std::string& markedText, diff --git a/frameworks/core/components_ng/components.gni b/frameworks/core/components_ng/components.gni index e4712fcdccf20d2c0e3bd2f128437389f5e8f44d..b8aa9ab07b179f7b97931b5e83330c633d0570ab 100644 --- a/frameworks/core/components_ng/components.gni +++ b/frameworks/core/components_ng/components.gni @@ -67,6 +67,7 @@ template("build_component_ng") { deps = [] deps += extra_deps deps += [ "$ace_root/frameworks/core/components/theme:build_theme_code" ] + deps += [ "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text" ] if (enable_ng_build) { deps += [ diff --git a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp index c5c5f58d9c5d1c93dbae63511769f0eb9262c44a..326e8e1103589976502689210b8225a9b2354ec2 100644 --- a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp @@ -30,6 +30,7 @@ #include "core/components_ng/render/canvas_image.h" #include "core/components_ng/render/drawing.h" #include "core/components_ng/render/drawing_prop_convertor.h" +#include "core/components/font/rosen_font_collection.h" #include "core/components_ng/render/paint_property.h" namespace OHOS::Ace::NG { @@ -39,15 +40,15 @@ namespace { const char ELLIPSIS[] = "..."; constexpr double WEEKEND_TRANSPARENT = 0x7D; -std::unique_ptr GetTextParagraph(const std::string& text, const rosen::TextStyle& textStyle) +std::unique_ptr GetTextParagraph(const std::string& text, const Rosen::TextStyle& textStyle) { RSParagraphStyle style; - auto fontCollection = RSFontCollection::GetInstance(false); + auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); CHECK_NULL_RETURN(fontCollection, nullptr); - std::unique_ptr builder = RSParagraphBuilder::CreateRosenBuilder(style, fontCollection); + std::unique_ptr builder = RSParagraphBuilder::Create(style, fontCollection); builder->PushStyle(textStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - return builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + return builder->CreateTypography(); } void DrawCalendarText( @@ -135,8 +136,8 @@ void CalendarPaintMethod::DrawWeekAndDates(RSCanvas& canvas, Offset offset) void CalendarPaintMethod::DrawCalendar( RSCanvas& canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day) { - rosen::TextStyle dateTextStyle; - rosen::TextStyle lunarTextStyle; + Rosen::TextStyle dateTextStyle; + Rosen::TextStyle lunarTextStyle; InitTextStyle(dateTextStyle, lunarTextStyle); dateTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); lunarTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); @@ -181,7 +182,7 @@ void CalendarPaintMethod::DrawTodayArea(RSCanvas& canvas, const Offset& offset, Offset circleCenter = Offset(x - (focusedAreaRadius_ * 2 - dayWidth_) / 2 + focusedAreaRadius_, y - (1.0_vp).ConvertToPx() + focusedAreaRadius_); Offset bgCircleStart = offset + circleCenter; - canvas.DrawCircle(rosen::Point(static_cast(bgCircleStart.GetX()), static_cast(bgCircleStart.GetY())), + canvas.DrawCircle(Rosen::Drawing::Point(static_cast(bgCircleStart.GetX()), static_cast(bgCircleStart.GetY())), static_cast(focusedAreaRadius_)); } @@ -196,33 +197,33 @@ void CalendarPaintMethod::DrawFocusedArea(RSCanvas& canvas, const Offset& offset Offset circleCenter = Offset(x - (focusedAreaRadius_ * 2 - dayWidth_) / 2 + focusedAreaRadius_, y - (1.0_vp).ConvertToPx() + focusedAreaRadius_); Offset bgCircleStart = offset + circleCenter; - canvas.DrawCircle(rosen::Point(static_cast(bgCircleStart.GetX()), static_cast(bgCircleStart.GetY())), + canvas.DrawCircle(Rosen::Drawing::Point(static_cast(bgCircleStart.GetX()), static_cast(bgCircleStart.GetY())), static_cast(focusedAreaRadius_)); } -void CalendarPaintMethod::InitTextStyle(rosen::TextStyle& dateTextStyle, rosen::TextStyle& lunarTextStyle) +void CalendarPaintMethod::InitTextStyle(Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle) { dateTextStyle.fontSize_ = dayFontSize_; - dateTextStyle.fontWeight_ = static_cast(dayFontWeight_); + dateTextStyle.fontWeight_ = static_cast(dayFontWeight_); lunarTextStyle.fontSize_ = lunarDayFontSize_; - lunarTextStyle.fontWeight_ = static_cast(lunarDayFontWeight_); + lunarTextStyle.fontWeight_ = static_cast(lunarDayFontWeight_); } void CalendarPaintMethod::PaintDay( - RSCanvas& canvas, const Offset& offset, const CalendarDay& day, rosen::TextStyle& textStyle) const + RSCanvas& canvas, const Offset& offset, const CalendarDay& day, Rosen::TextStyle& textStyle) const { // paint day Rect boxRect { offset.GetX(), offset.GetY(), dayWidth_, gregorianCalendarHeight_ }; Rect textRect; - rosen::TextStyle workStateStyle; + Rosen::TextStyle workStateStyle; auto dayStr = std::to_string(day.day); dayStr = Localization::GetInstance()->NumberFormat(day.day); DrawCalendarText(&canvas, dayStr, textStyle, boxRect, textRect); if (!day.dayMark.empty() && showHoliday_) { - workStateStyle.fontWeight_ = static_cast(workStateFontWeight_); + workStateStyle.fontWeight_ = static_cast(workStateFontWeight_); workStateStyle.locale_ = Localization::GetInstance()->GetFontLocale(); boxRect = { textRect.GetOffset().GetX() + textRect.Width() - workStateHorizontalMovingDistance_, textRect.GetOffset().GetY() + textRect.Height() - workStateVerticalMovingDistance_, workStateWidth_, @@ -257,7 +258,7 @@ void CalendarPaintMethod::PaintDay( } void CalendarPaintMethod::PaintLunarDay( - RSCanvas& canvas, const Offset& offset, const CalendarDay& day, const rosen::TextStyle& textStyle) const + RSCanvas& canvas, const Offset& offset, const CalendarDay& day, const Rosen::TextStyle& textStyle) const { Rect boxRect = { offset.GetX(), offset.GetY(), dayWidth_, lunarHeight_ }; DrawCalendarText(&canvas, day.lunarDay, textStyle, boxRect); @@ -266,7 +267,7 @@ void CalendarPaintMethod::PaintLunarDay( void CalendarPaintMethod::DrawWeek(RSCanvas& canvas, const Offset& offset) const { uint32_t totalWeek = weekNumbers_.size(); - rosen::TextStyle weekTextStyle; + Rosen::TextStyle weekTextStyle; weekTextStyle.color_ = weekColor_; weekTextStyle.fontSize_ = weekFontSize_; weekTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); @@ -413,4 +414,4 @@ bool CalendarPaintMethod::IsOffDay(const CalendarDay& dayInfo) const return false; } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.h b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.h index cb305a6b391e20556d6cfb2c526d79a74495ec7b..0001302f2a194124b39ba8ecf09e391313b5445c 100644 --- a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.h +++ b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.h @@ -47,10 +47,10 @@ private: void DrawCalendar(RSCanvas& canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day); void DrawTodayArea(RSCanvas& canvas, const Offset& offset, double x, double y) const; void DrawFocusedArea(RSCanvas& canvas, const Offset& offset, double x, double y) const; - void InitTextStyle(rosen::TextStyle& dateTextStyle, rosen::TextStyle& lunarTextStyle); - void PaintDay(RSCanvas& canvas, const Offset& offset, const CalendarDay& day, rosen::TextStyle& textStyle) const; + void InitTextStyle(Rosen::TextStyle& dateTextStyle,Rosen::TextStyle& lunarTextStyle); + void PaintDay(RSCanvas& canvas, const Offset& offset, const CalendarDay& day, Rosen::TextStyle& textStyle) const; void PaintLunarDay( - RSCanvas& canvas, const Offset& offset, const CalendarDay& day, const rosen::TextStyle& textStyle) const; + RSCanvas& canvas, const Offset& offset, const CalendarDay& day, const Rosen::TextStyle& textStyle) const; void PaintContent(RSCanvas& canvas, const RefPtr& paintProperty); bool IsOffDay(const CalendarDay& dayInfo) const; bool IsToday(const CalendarDay& day) const; @@ -113,4 +113,4 @@ private: }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CALENDAR_CALENDAR_PAINT_METHOD_H \ No newline at end of file +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CALENDAR_CALENDAR_PAINT_METHOD_H diff --git a/frameworks/core/components_ng/pattern/custom_paint/canvas_paint_method.cpp b/frameworks/core/components_ng/pattern/custom_paint/canvas_paint_method.cpp index e4e8cc12186c73d636b14e3532ff45e83cf533e3..ceeef77c9f2a9691d29cc12c2b4d2ff5595acbb5 100644 --- a/frameworks/core/components_ng/pattern/custom_paint/canvas_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/custom_paint/canvas_paint_method.cpp @@ -340,17 +340,17 @@ void CanvasPaintMethod::StrokeText(PaintWrapper* paintWrapper, const std::string double CanvasPaintMethod::MeasureText(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); CHECK_NULL_RETURN(fontCollection, 0.0); - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder =Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetMaxIntrinsicWidth(); } @@ -358,17 +358,17 @@ double CanvasPaintMethod::MeasureText(const std::string& text, const PaintState& double CanvasPaintMethod::MeasureTextHeight(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); CHECK_NULL_RETURN(fontCollection, 0.0); - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetHeight(); } @@ -377,17 +377,17 @@ TextMetrics CanvasPaintMethod::MeasureTextMetrics(const std::string& text, const { using namespace Constants; TextMetrics textMetrics = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); CHECK_NULL_RETURN(fontCollection, textMetrics); - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); auto textAlign = state.GetTextAlign(); @@ -427,7 +427,7 @@ void CanvasPaintMethod::PaintText( paragraph_->Paint(skCanvas_.get(), dx, dy); } -double CanvasPaintMethod::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) +double CanvasPaintMethod::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) { double x = 0.0; TextDirection textDirection = TextDirection::LTR; @@ -454,7 +454,7 @@ double CanvasPaintMethod::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) +double CanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph) { double y = 0.0; switch (baseline) { @@ -486,58 +486,56 @@ double CanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std::unique_p bool CanvasPaintMethod::UpdateParagraph(const OffsetF& offset, const std::string& text, bool isStroke, bool hasShadow) { using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; if (isStroke) { - style.text_align = ConvertTxtTextAlign(strokeState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(strokeState_.GetTextAlign()); } else { - style.text_align = ConvertTxtTextAlign(fillState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(fillState_.GetTextAlign()); } auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); CHECK_NULL_RETURN(fontCollection, false); - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; if (!isStroke && hasShadow) { - txt::TextShadow txtShadow; - txtShadow.color = shadow_.GetColor().GetValue(); - txtShadow.offset.fX = shadow_.GetOffset().GetX(); - txtShadow.offset.fY = shadow_.GetOffset().GetY(); - txtShadow.blur_radius = shadow_.GetBlurRadius(); - txtStyle.text_shadows.emplace_back(txtShadow); + Rosen::TextShadow txtShadow; + txtShadow.color_ = shadow_.GetColor().GetValue(); + txtShadow.offset_.SetX(shadow_.GetOffset().GetX()); + txtShadow.offset_.SetY(shadow_.GetOffset().GetY()); + txtShadow.blurRadius_ = shadow_.GetBlurRadius(); + txtStyle.shadows_.emplace_back(txtShadow); } - txtStyle.locale = Localization::GetInstance()->GetFontLocale(); + txtStyle.locale_ = Localization::GetInstance()->GetFontLocale(); UpdateTextStyleForeground(offset, isStroke, txtStyle, hasShadow); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - paragraph_ = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + paragraph_ = builder->CreateTypography(); return true; } void CanvasPaintMethod::UpdateTextStyleForeground( - const OffsetF& offset, bool isStroke, txt::TextStyle& txtStyle, bool hasShadow) + const OffsetF& offset, bool isStroke, Rosen::TextStyle& txtStyle, bool hasShadow) { using namespace Constants; if (!isStroke) { - txtStyle.color = ConvertSkColor(fillState_.GetColor()); - txtStyle.font_size = fillState_.GetTextStyle().GetFontSize().Value(); + txtStyle.color_ = ConvertSkColor(fillState_.GetColor()); + txtStyle.fontSize_ = fillState_.GetTextStyle().GetFontSize().Value(); ConvertTxtStyle(fillState_.GetTextStyle(), context_, txtStyle); if (fillState_.GetGradient().IsValid()) { SkPaint paint; paint.setStyle(SkPaint::Style::kFill_Style); UpdatePaintShader(offset, paint, fillState_.GetGradient()); - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } if (globalState_.HasGlobalAlpha()) { - if (txtStyle.has_foreground) { - txtStyle.foreground.setColor(fillState_.GetColor().GetValue()); - txtStyle.foreground.setAlphaf(globalState_.GetAlpha()); // set alpha after color + if (txtStyle.foreground_.has_value()) { + txtStyle.foreground_->setColor(fillState_.GetColor().GetValue()); + txtStyle.foreground_->setAlphaf(globalState_.GetAlpha()); // set alpha after color } else { SkPaint paint; paint.setColor(fillState_.GetColor().GetValue()); paint.setAlphaf(globalState_.GetAlpha()); // set alpha after color InitPaintBlend(paint); - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } } else { @@ -545,7 +543,7 @@ void CanvasPaintMethod::UpdateTextStyleForeground( SkPaint paint = GetStrokePaint(); InitPaintBlend(paint); ConvertTxtStyle(strokeState_.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = strokeState_.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = strokeState_.GetTextStyle().GetFontSize().Value(); if (strokeState_.GetGradient().IsValid()) { UpdatePaintShader(offset, paint, strokeState_.GetGradient()); } @@ -554,8 +552,7 @@ void CanvasPaintMethod::UpdateTextStyleForeground( paint.setMaskFilter(SkMaskFilter::MakeBlur(SkBlurStyle::kNormal_SkBlurStyle, RosenDecorationPainter::ConvertRadiusToSigma(shadow_.GetBlurRadius()))); } - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } diff --git a/frameworks/core/components_ng/pattern/custom_paint/canvas_paint_method.h b/frameworks/core/components_ng/pattern/custom_paint/canvas_paint_method.h index 5f847b5065548abd5b47c13beac16df6c314ea19..dd41fdfd2cd861f45112bba0b30a5897b9805880 100644 --- a/frameworks/core/components_ng/pattern/custom_paint/canvas_paint_method.h +++ b/frameworks/core/components_ng/pattern/custom_paint/canvas_paint_method.h @@ -86,10 +86,10 @@ private: void PaintText( const OffsetF& offset, const SizeF& contentSize, double x, double y, bool isStroke, bool hasShadow = false); - double GetAlignOffset(TextAlign align, std::unique_ptr& paragraph); - double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); + double GetAlignOffset(TextAlign align, std::unique_ptr& paragraph); + double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); bool UpdateParagraph(const OffsetF& offset, const std::string& text, bool isStroke, bool hasShadow = false); - void UpdateTextStyleForeground(const OffsetF& offset, bool isStroke, txt::TextStyle& txtStyle, bool hasShadow); + void UpdateTextStyleForeground(const OffsetF& offset, bool isStroke, Rosen::TextStyle& txtStyle, bool hasShadow); void PaintShadow(const SkPath& path, const Shadow& shadow, SkCanvas* canvas) override; OffsetF GetContentOffset(PaintWrapper* paintWrapper) const override { diff --git a/frameworks/core/components_ng/pattern/custom_paint/custom_paint_paint_method.h b/frameworks/core/components_ng/pattern/custom_paint/custom_paint_paint_method.h index a0dcc0b3552b9067850a8df94e3bdb966e4f133b..76fe3f69e7ac9b020a83391ed7009e328a1afee6 100644 --- a/frameworks/core/components_ng/pattern/custom_paint/custom_paint_paint_method.h +++ b/frameworks/core/components_ng/pattern/custom_paint/custom_paint_paint_method.h @@ -17,8 +17,9 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_PAINT_CUSTOM_PAINT_PAINT_METHOD_H #include "experimental/svg/model/SkSVGDOM.h" -#include "flutter/third_party/txt/src/txt/paragraph.h" #include "third_party/skia/include/core/SkPath.h" +#include "rosen_text/text_style.h" +#include "rosen_text/typography.h" #include "base/geometry/ng/offset_t.h" #include "base/memory/ace_type.h" @@ -292,7 +293,7 @@ protected: std::string smoothingQuality_ = "low"; bool antiAlias_ = false; Shadow shadow_; - std::unique_ptr paragraph_; + std::unique_ptr paragraph_; RefPtr context_; diff --git a/frameworks/core/components_ng/pattern/custom_paint/offscreen_canvas_paint_method.cpp b/frameworks/core/components_ng/pattern/custom_paint/offscreen_canvas_paint_method.cpp index 0075b4a2a35e718b4b3a9073321f65a3f72e9206..2de9b9a420970b19ab8148931a41a5bb778e68e6 100644 --- a/frameworks/core/components_ng/pattern/custom_paint/offscreen_canvas_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/custom_paint/offscreen_canvas_paint_method.cpp @@ -15,14 +15,14 @@ #include "core/components_ng/pattern/custom_paint/offscreen_canvas_paint_method.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" +#include "rosen_text/typography_create.h" #include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/effects/SkBlurImageFilter.h" #include "third_party/skia/include/encode/SkJpegEncoder.h" #include "third_party/skia/include/encode/SkPngEncoder.h" #include "third_party/skia/include/encode/SkWebpEncoder.h" #include "third_party/skia/include/utils/SkBase64.h" +#include "unicode/uchar.h" #include "base/geometry/ng/offset_t.h" #include "base/i18n/localization.h" @@ -634,18 +634,18 @@ void OffscreenCanvasPaintMethod::StrokeText(const std::string& text, double x, d double OffscreenCanvasPaintMethod::MeasureText(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); CHECK_NULL_RETURN(fontCollection, 0.0); - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + auto builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetMaxIntrinsicWidth(); } @@ -653,18 +653,18 @@ double OffscreenCanvasPaintMethod::MeasureText(const std::string& text, const Pa double OffscreenCanvasPaintMethod::MeasureTextHeight(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); CHECK_NULL_RETURN(fontCollection, 0.0); - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetHeight(); } @@ -673,18 +673,18 @@ TextMetrics OffscreenCanvasPaintMethod::MeasureTextMetrics(const std::string& te { using namespace Constants; TextMetrics textMetrics = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); CHECK_NULL_RETURN(fontCollection, textMetrics); - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); auto textAlign = state.GetTextAlign(); @@ -722,7 +722,7 @@ void OffscreenCanvasPaintMethod::PaintText( paragraph_->Paint(skCanvas_.get(), dx, dy); } -double OffscreenCanvasPaintMethod::GetAlignOffset(const std::string& text, TextAlign align, std::unique_ptr& paragraph) +double OffscreenCanvasPaintMethod::GetAlignOffset(const std::string& text, TextAlign align, std::unique_ptr& paragraph) { double x = 0.0; switch (align) { @@ -748,7 +748,7 @@ double OffscreenCanvasPaintMethod::GetAlignOffset(const std::string& text, TextA return x; } -double OffscreenCanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph) +double OffscreenCanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph) { double y = 0.0; switch (baseline) { @@ -780,64 +780,62 @@ double OffscreenCanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std: bool OffscreenCanvasPaintMethod::UpdateOffParagraph(const std::string& text, bool isStroke, const PaintState& state, bool hasShadow) { using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; if (isStroke) { - style.text_align = ConvertTxtTextAlign(strokeState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(strokeState_.GetTextAlign()); } else { - style.text_align = ConvertTxtTextAlign(fillState_.GetTextAlign()); + style.textAlign_ = ConvertTxtTextAlign(fillState_.GetTextAlign()); } - style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); CHECK_NULL_RETURN(fontCollection, false); - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; if (!isStroke && hasShadow) { - txt::TextShadow txtShadow; - txtShadow.color = shadow_.GetColor().GetValue(); - txtShadow.offset.fX = shadow_.GetOffset().GetX(); - txtShadow.offset.fY = shadow_.GetOffset().GetY(); - txtShadow.blur_radius = shadow_.GetBlurRadius(); - txtStyle.text_shadows.emplace_back(txtShadow); - } - txtStyle.locale = Localization::GetInstance()->GetFontLocale(); + Rosen::TextShadow txtShadow; + txtShadow.color_ = shadow_.GetColor().GetValue(); + txtShadow.offset_.SetX(shadow_.GetOffset().GetX()); + txtShadow.offset_.SetY (shadow_.GetOffset().GetY()); + txtShadow.blurRadius_ = shadow_.GetBlurRadius(); + txtStyle.shadows_.emplace_back(txtShadow); + } + txtStyle.locale_ = Localization::GetInstance()->GetFontLocale(); UpdateTextStyleForeground(isStroke, txtStyle, hasShadow); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - paragraph_ = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + paragraph_ = builder->CreateTypography(); return true; } -void OffscreenCanvasPaintMethod::UpdateTextStyleForeground(bool isStroke, txt::TextStyle& txtStyle, bool hasShadow) +void OffscreenCanvasPaintMethod::UpdateTextStyleForeground(bool isStroke, Rosen::TextStyle& txtStyle, bool hasShadow) { using namespace Constants; if (!isStroke) { - txtStyle.color = ConvertSkColor(fillState_.GetColor()); - txtStyle.font_size = fillState_.GetTextStyle().GetFontSize().Value(); + txtStyle.color_ = ConvertSkColor(fillState_.GetColor()); + txtStyle.fontSize_ = fillState_.GetTextStyle().GetFontSize().Value(); ConvertTxtStyle(fillState_.GetTextStyle(), context_, txtStyle); if (fillState_.GetGradient().IsValid()) { SkPaint paint; paint.setStyle(SkPaint::Style::kFill_Style); UpdatePaintShader(OffsetF(0, 0), paint, fillState_.GetGradient()); - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } if (globalState_.HasGlobalAlpha()) { - if (txtStyle.has_foreground) { - txtStyle.foreground.setColor(fillState_.GetColor().GetValue()); - txtStyle.foreground.setAlphaf(globalState_.GetAlpha()); // set alpha after color + if (txtStyle.foreground_.has_value()) { + txtStyle.foreground_->setColor(fillState_.GetColor().GetValue()); + txtStyle.foreground_->setAlphaf(globalState_.GetAlpha()); // set alpha after color } else { SkPaint paint; paint.setColor(fillState_.GetColor().GetValue()); paint.setAlphaf(globalState_.GetAlpha()); // set alpha after color - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } } else { // use foreground to draw stroke SkPaint paint = GetStrokePaint(); ConvertTxtStyle(strokeState_.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = strokeState_.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = strokeState_.GetTextStyle().GetFontSize().Value(); if (strokeState_.GetGradient().IsValid()) { UpdatePaintShader(OffsetF(0, 0), paint, strokeState_.GetGradient()); } @@ -846,8 +844,7 @@ void OffscreenCanvasPaintMethod::UpdateTextStyleForeground(bool isStroke, txt::T paint.setMaskFilter(SkMaskFilter::MakeBlur(SkBlurStyle::kNormal_SkBlurStyle, FlutterDecorationPainter::ConvertRadiusToSigma(shadow_.GetBlurRadius()))); } - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } @@ -936,4 +933,4 @@ std::string OffscreenCanvasPaintMethod::ToDataURL(const std::string& type, const SkBase64::Encode(result->data(), result->size(), info.writable_str()); return std::string(URL_PREFIX).append(mimeType).append(URL_SYMBOL).append(info.c_str()); } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/custom_paint/offscreen_canvas_paint_method.h b/frameworks/core/components_ng/pattern/custom_paint/offscreen_canvas_paint_method.h index 1fee5daa16e3af34f90dc4845c7c1d87a2502b5c..6fb4d37788776eee7e8c109ead01ee60ec47e76b 100644 --- a/frameworks/core/components_ng/pattern/custom_paint/offscreen_canvas_paint_method.h +++ b/frameworks/core/components_ng/pattern/custom_paint/offscreen_canvas_paint_method.h @@ -75,10 +75,10 @@ private: void SetPaintImage() override; void PaintText(const std::string& text, double x, double y, bool isStroke, bool hasShadow = false); - double GetAlignOffset(const std::string& text, TextAlign align, std::unique_ptr& paragraph); - double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); + double GetAlignOffset(const std::string& text, TextAlign align, std::unique_ptr& paragraph); + double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); bool UpdateOffParagraph(const std::string& text, bool isStroke, const PaintState& state, bool hasShadow = false); - void UpdateTextStyleForeground(bool isStroke, txt::TextStyle& txtStyle, bool hasShadow); + void UpdateTextStyleForeground(bool isStroke, Rosen::TextStyle& txtStyle, bool hasShadow); TextDirection GetTextDirection(const std::string& content); void PaintShadow(const SkPath& path, const Shadow& shadow, SkCanvas* canvas) override; void Path2DRect(const OffsetF& offset, const PathArgs& args) override; diff --git a/frameworks/core/components_ng/pattern/linear_split/linear_split_paint_method.cpp b/frameworks/core/components_ng/pattern/linear_split/linear_split_paint_method.cpp index 8b21103b599fd33132cbe1128c6c045c03383846..a190253d6f0f76c87bcbd7b2105c9091196a0d72 100644 --- a/frameworks/core/components_ng/pattern/linear_split/linear_split_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/linear_split/linear_split_paint_method.cpp @@ -70,4 +70,4 @@ void LinearSplitPaintMethod::PaintContent(RSCanvas& canvas) } } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/slider/slider_pattern.cpp b/frameworks/core/components_ng/pattern/slider/slider_pattern.cpp index b3b856fbc32ef051e51e6fabf42ee159c20f86e3..70d8ecf3ee267b03c455ade1d2f392ebf17676a6 100644 --- a/frameworks/core/components_ng/pattern/slider/slider_pattern.cpp +++ b/frameworks/core/components_ng/pattern/slider/slider_pattern.cpp @@ -574,7 +574,7 @@ bool SliderPattern::CreateParagraph(const TextStyle& textStyle, std::string cont .fontLocale = Localization::GetInstance()->GetFontLocale(), .wordBreak = textStyle.GetWordBreak(), .textOverflow = textStyle.GetTextOverflow() }; - paragraph_ = Paragraph::Create(paraStyle, FontCollection::Current()); + paragraph_ = Paragraph::Create(nullptr, paraStyle, FontCollection::Current()); CHECK_NULL_RETURN(paragraph_, false); paragraph_->PushStyle(textStyle); StringUtils::TransformStrCase(content, static_cast(textStyle.GetTextCase())); diff --git a/frameworks/core/components_ng/pattern/text/span_node.cpp b/frameworks/core/components_ng/pattern/text/span_node.cpp index edb79a0a312516cec450f4aaf24d058cacfd3ffc..1eb3939dba977b4733e6a370904c380e0025054d 100644 --- a/frameworks/core/components_ng/pattern/text/span_node.cpp +++ b/frameworks/core/components_ng/pattern/text/span_node.cpp @@ -125,4 +125,4 @@ void SpanItem::UpdateParagraph(const RefPtr& builder) builder->PopStyle(); } } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text/text_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/text/text_layout_algorithm.cpp index 7fd5c9140b4e7d3ea9cd098762ad6a2d40237447..2aee62ef16d0681e491bf9035041ecbe6f1f60f6 100644 --- a/frameworks/core/components_ng/pattern/text/text_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/text/text_layout_algorithm.cpp @@ -141,7 +141,7 @@ bool TextLayoutAlgorithm::CreateParagraph(const TextStyle& textStyle, std::strin .fontLocale = Localization::GetInstance()->GetFontLocale(), .wordBreak = textStyle.GetWordBreak(), .textOverflow = textStyle.GetTextOverflow() }; - paragraph_ = Paragraph::Create(paraStyle, FontCollection::Current()); + paragraph_ = Paragraph::Create(nullptr, paraStyle, FontCollection::Current()); CHECK_NULL_RETURN(paragraph_, false); paragraph_->PushStyle(textStyle); diff --git a/frameworks/core/components_ng/pattern/text/text_layout_algorithm.h b/frameworks/core/components_ng/pattern/text/text_layout_algorithm.h index 7574942a8ae23cb4f04ca7a5b7c826735287a020..bf149e7b5e9e4c153c45f1f972632be1de829fb7 100644 --- a/frameworks/core/components_ng/pattern/text/text_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/text/text_layout_algorithm.h @@ -50,7 +50,7 @@ public: const RefPtr& GetParagraph(); std::list>&& GetSpanItemChildren(); - + float GetBaselineOffset() const; private: diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp index 403661d65367c5e2fe22bb35d9e90e75dad84c7c..a89db6bf8508ba42ac352d2f3d97d5f9f30be193 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp @@ -139,7 +139,7 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( auto showPasswordIcon = textFieldLayoutProperty->GetShowPasswordIcon().value_or(true); // check password image size. if (!showPasswordIcon || !isPasswordType) { - textRect_.SetSize(SizeF(static_cast(paragraph_->GetLongestLine()), preferredHeight)); + textRect_.SetSize(SizeF(static_cast(paragraph_->GetActualWidth()), preferredHeight)); imageRect_.Reset(); if (textFieldLayoutProperty->GetWidthAutoValue(false)) { if (LessOrEqual(contentConstraint.minSize.Width(), 0.0f)) { @@ -162,7 +162,7 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( if (textStyle.GetMaxLines() > 1 || pattern->IsTextArea()) { // for textArea, need to delete imageWidth and remeasure. paragraph_->Layout(idealWidth - imageSize); - textRect_.SetSize(SizeF(static_cast(paragraph_->GetLongestLine()), preferredHeight)); + textRect_.SetSize(SizeF(static_cast(paragraph_->GetActualWidth()), preferredHeight)); imageRect_.SetSize(SizeF(0.0f, 0.0f)); return SizeF(idealWidth, imageSize); } @@ -173,7 +173,7 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( pattern->GetShowPasswordIconCtx()->MakeCanvasImage(imageRect_.GetSize(), true, ImageFit::NONE); } preferredHeight = std::min(static_cast(paragraph_->GetHeight()), idealHeight); - textRect_.SetSize(SizeF(static_cast(paragraph_->GetLongestLine()), static_cast(preferredHeight))); + textRect_.SetSize(SizeF(static_cast(paragraph_->GetActualWidth()), static_cast(preferredHeight))); return SizeF(idealWidth - imageSize, std::min(idealHeight, preferredHeight)); } @@ -321,18 +321,18 @@ void TextFieldLayoutAlgorithm::CreateParagraph(const TextStyle& textStyle, std:: if (textStyle.GetTextOverflow() == TextOverflow::ELLIPSIS) { paraStyle.ellipsis_ = StringUtils::Str8ToStr16(StringUtils::ELLIPSIS); } - auto builder = RSParagraphBuilder::CreateRosenBuilder(paraStyle, RSFontCollection::GetInstance(false)); + auto builder = RSParagraphBuilder::Create(paraStyle, RSFontCollection::Create()); builder->PushStyle(ToRSTextStyle(PipelineContext::GetCurrentContext(), textStyle)); StringUtils::TransformStrCase(content, static_cast(textStyle.GetTextCase())); if (!content.empty() && needObscureText) { - builder->AddText( + builder->AppendText( TextFieldPattern::CreateObscuredText(static_cast(StringUtils::ToWstring(content).length()))); } else { - builder->AddText(StringUtils::Str8ToStr16(content)); + builder->AppendText(StringUtils::Str8ToStr16(content)); } - builder->Pop(); + builder->PopStyle(); - auto paragraph = builder->Build(); + auto paragraph = builder->CreateTypography(); paragraph_.reset(paragraph.release()); } diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp index c5be01dc2c80436dcaa7a26c22f46e44c44ae802..462462f2a5ae636353846e65a3f7bfc08cf93d03 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp @@ -682,13 +682,13 @@ void TextFieldPattern::OnTextAreaScroll(float dy) } void TextFieldPattern::GetTextRectsInRange( - int32_t base, int32_t destination, std::vector& textBoxes) + int32_t base, int32_t destination, std::vector& textBoxes) { if (base > destination) { std::swap(base, destination); } - textBoxes = paragraph_->GetRectsForRange( - base, destination, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + textBoxes = paragraph_->GetTextRectsByBoundary( + base, destination, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } bool TextFieldPattern::ComputeOffsetForCaretDownstream(int32_t extent, CaretMetricsF& result) @@ -701,8 +701,8 @@ bool TextFieldPattern::ComputeOffsetForCaretDownstream(int32_t extent, CaretMetr result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto textBoxes = paragraph_->GetRectsForRange( - next, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + auto textBoxes = paragraph_->GetTextRectsByBoundary( + next, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (textBoxes.empty()) { LOGW("Box empty"); @@ -733,18 +733,18 @@ bool TextFieldPattern::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetric result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !textEditingValue_.text.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { LOGW("Empty box"); @@ -787,7 +787,7 @@ int32_t TextFieldPattern::ConvertTouchOffsetToCaretPosition(const Offset& localO { CHECK_NULL_RETURN(paragraph_, 0); return static_cast( - paragraph_->GetGlyphPositionAtCoordinateWithCluster(localOffset.GetX(), localOffset.GetY()).pos_); + paragraph_->GetGlyphIndexByCoordinate(localOffset.GetX(), localOffset.GetY()).index_); } bool TextFieldPattern::DisplayPlaceHolder() @@ -1552,7 +1552,7 @@ void TextFieldPattern::ProcessOverlay() UpdateSelection(textEditingValue_.caretPosition, textEditingValue_.caretPosition + 1); } } - std::vector tmp; + std::vector tmp; GetTextRectsInRange(textSelector_.GetStart(), textSelector_.GetEnd(), tmp); auto firstHandlePosition = CalcCursorOffsetByPosition(textSelector_.GetStart()); OffsetF firstHandleOffset(firstHandlePosition.offset.GetX() + parentGlobalOffset_.GetX(), @@ -1950,7 +1950,6 @@ bool TextFieldPattern::RequestKeyboard(bool isFocusViewChanged, bool needStartTw if (needShowSoftKeyboard) { LOGI("Start to request keyboard"); #if defined(ENABLE_STANDARD_INPUT) - UpdateConfiguration(); if (textChangeListener_ == nullptr) { textChangeListener_ = new OnTextChangedListenerImpl(WeakClaim(this)); } @@ -1963,10 +1962,7 @@ bool TextFieldPattern::RequestKeyboard(bool isFocusViewChanged, bool needStartTw LOGI("RequestKeyboard set calling window id is : %{public}d", context->GetWindowId()); inputMethod->SetCallingWindow(context->GetWindowId()); } - MiscServices::InputAttribute inputAttribute; - inputAttribute.inputPattern = (int32_t)keyboard_; - inputAttribute.enterKeyType = (int32_t)GetTextInputActionValue(TextInputAction::DONE); - inputMethod->Attach(textChangeListener_, needShowSoftKeyboard, inputAttribute); + inputMethod->Attach(textChangeListener_, needShowSoftKeyboard); #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) imeAttached_ = true; #endif @@ -2329,13 +2325,13 @@ float TextFieldPattern::PreferredLineHeight() if (lineHeightMeasureUtilTextStyle_.GetTextOverflow() == TextOverflow::ELLIPSIS) { paraStyle.ellipsis_ = RSParagraphStyle::ELLIPSIS; } - auto builder = RSParagraphBuilder::CreateRosenBuilder(paraStyle, RSFontCollection::GetInstance(false)); + auto builder = RSParagraphBuilder::Create(paraStyle, RSFontCollection::Create()); builder->PushStyle(ToRSTextStyle(PipelineContext::GetCurrentContext(), lineHeightMeasureUtilTextStyle_)); StringUtils::TransformStrCase( textEditingValue_.text, static_cast(lineHeightMeasureUtilTextStyle_.GetTextCase())); - builder->AddText(StringUtils::Str8ToStr16(textContent)); - builder->Pop(); - lineHeightMeasureUtilParagraph_ = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(textContent)); + builder->PopStyle(); + lineHeightMeasureUtilParagraph_ = builder->CreateTypography(); lineHeightMeasureUtilParagraph_->Layout(std::numeric_limits::infinity()); layoutProperty->UpdatePreferredLineHeightNeedToUpdate(false); return static_cast(lineHeightMeasureUtilParagraph_->GetHeight()); @@ -2380,7 +2376,7 @@ void TextFieldPattern::CursorMoveUp() CHECK_NULL_VOID_NOLOG(IsTextArea()); float verticalOffset = caretRect_.GetY() - PreferredLineHeight(); textEditingValue_.caretPosition = static_cast( - paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), verticalOffset).pos_); + paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), verticalOffset).index_); OnCursorMoveDone(); } @@ -2390,7 +2386,7 @@ void TextFieldPattern::CursorMoveDown() CHECK_NULL_VOID_NOLOG(IsTextArea()); float verticalOffset = caretRect_.GetY() + PreferredLineHeight(); textEditingValue_.caretPosition = static_cast( - paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), verticalOffset).pos_); + paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), verticalOffset).index_); OnCursorMoveDone(); } @@ -2575,7 +2571,7 @@ void TextFieldPattern::HandleSelectionUp() } auto newOffsetY = caretRect_.GetY() - PreferredLineHeight(); textEditingValue_.caretPosition = - static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), newOffsetY).pos_); + static_cast(paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), newOffsetY).index_); textSelector_.destinationOffset = textEditingValue_.caretPosition; if (textSelector_.baseOffset == textSelector_.destinationOffset) { selectionMode_ = SelectionMode::NONE; @@ -2594,7 +2590,7 @@ void TextFieldPattern::HandleSelectionDown() } auto newOffsetY = caretRect_.GetY() + PreferredLineHeight(); textEditingValue_.caretPosition = - static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), newOffsetY).pos_); + static_cast(paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), newOffsetY).index_); if (textSelector_.baseOffset == textSelector_.destinationOffset) { selectionMode_ = SelectionMode::NONE; } @@ -2884,4 +2880,4 @@ void TextFieldPattern::ToJsonValue(std::unique_ptr& json) const json->Put("inputFilter", GetInputFilter().c_str()); } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h index f95f423b31d42544d417765ba9d2b27c6ace7bde..98e64a74f58914d40fa41d2e997d6ee5410ec65c 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h @@ -348,7 +348,7 @@ public: void HandleExtendAction(int32_t action); void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip); - const std::vector& GetTextBoxes() + const std::vector& GetTextBoxes() { return textBoxes_; } @@ -579,7 +579,7 @@ private: bool FilterWithRegex( const std::string& filter, const std::string& valueToUpdate, std::string& result, bool needToEscape = false); void EditingValueFilter(std::string& valueToUpdate, std::string& result); - void GetTextRectsInRange(int32_t begin, int32_t end, std::vector& textBoxes); + void GetTextRectsInRange(int32_t begin, int32_t end, std::vector& textBoxes); bool CursorInContentRegion(); bool OffsetInContentRegion(const Offset& offset); void SetDisabledStyle(); @@ -662,7 +662,7 @@ private: TextEditingValueNG textEditingValue_; TextSelector textSelector_; RefPtr selectOverlayProxy_; - std::vector textBoxes_; + std::vector textBoxes_; ACE_DISALLOW_COPY_AND_MOVE(TextFieldPattern); RefPtr clipboard_; @@ -681,4 +681,4 @@ private: }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_PATTERN_H \ No newline at end of file +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_PATTERN_H diff --git a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp index d82b816d1701482d634dc05fec9db96d6f4503d6..32317db740c96117c90763fa9679c36a65eef576 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp @@ -80,11 +80,11 @@ void SwitchModifier::PaintSwitch(RSCanvas& canvas, const OffsetF& contentOffset, auto width = contentSize.Width(); auto height = contentSize.Height(); auto radius = height / 2; - auto actualGap = radiusGap_.ConvertToPx() * height / - (switchTheme->GetHeight() - switchTheme->GetHotZoneVerticalPadding() * 2).ConvertToPx(); + auto actualGap = + radiusGap_ * height / (switchTheme->GetHeight() - switchTheme->GetHotZoneVerticalPadding() * 2).ConvertToPx(); auto xOffset = contentOffset.GetX(); auto yOffset = contentOffset.GetY(); - pointRadius_ = radius - actualGap; + pointRadius_ = radius - actualGap.Value(); clickEffectColor_ = switchTheme->GetClickEffectColor(); hoverColor_ = switchTheme->GetHoverColor(); hoverRadius_ = switchTheme->GetHoverRadius(); @@ -127,7 +127,7 @@ void SwitchModifier::PaintSwitch(RSCanvas& canvas, const OffsetF& contentOffset, canvas.AttachBrush(brush); RSPoint point; - point.SetX(xOffset + actualGap + pointRadius_ + mainDelta_->Get()); + point.SetX(xOffset + actualGap.Value() + pointRadius_ + mainDelta_->Get()); point.SetY(yOffset + radius); canvas.DrawCircle(point, pointRadius_); } @@ -157,4 +157,4 @@ float SwitchModifier::GetSwitchWidth(const SizeF& contentSize) const return switchWidth; } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NGt diff --git a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.h b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.h index 77a0860a01d3ae902bfcac7fdeaf35cf9e54dd38..5842f6f93cd57e7682bb1049f793cfc0407c4154 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.h +++ b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.h @@ -112,4 +112,4 @@ private: }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWITCH_SWITCH_PAINT_METHOD_H \ No newline at end of file +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWITCH_SWITCH_PAINT_METHOD_H diff --git a/frameworks/core/components_ng/pattern/toggle/switch_pattern.cpp b/frameworks/core/components_ng/pattern/toggle/switch_pattern.cpp index 031d5d6549841b9ce861b18bfdd724c0e747be60..f976519e817b7ce032c8cd700e02eef0091e6b42 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_pattern.cpp +++ b/frameworks/core/components_ng/pattern/toggle/switch_pattern.cpp @@ -495,4 +495,4 @@ void SwitchPattern::AddHotZoneRect() host->AddHotZoneRect(hotZoneRegion); } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NGo diff --git a/frameworks/core/components_ng/pattern/toggle/switch_pattern.h b/frameworks/core/components_ng/pattern/toggle/switch_pattern.h index f3d8be9ec2a3f2af60ffafd0b206a85a8f5ca5d9..15159cc38fc75d929a14059dbfbb6b08480572af 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_pattern.h +++ b/frameworks/core/components_ng/pattern/toggle/switch_pattern.h @@ -158,4 +158,4 @@ private: }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWITCH_SWITCH_PATTERN_H \ No newline at end of file +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWITCH_SWITCH_PATTERN_Ho diff --git a/frameworks/core/components_ng/render/adapter/focus_state_modifier.h b/frameworks/core/components_ng/render/adapter/focus_state_modifier.h index 619cb11b330a4003e475f558cfa0d59f5446960b..4bc8edf5386fbda19f905ffcd0d1528a87c6ade4 100644 --- a/frameworks/core/components_ng/render/adapter/focus_state_modifier.h +++ b/frameworks/core/components_ng/render/adapter/focus_state_modifier.h @@ -52,17 +52,17 @@ public: rect.GetRect().Width() + borderWidth, rect.GetRect().Height() + borderWidth); RSOverlayStyleModifier::SetOverlayBounds(overlayRect); roundRect_.SetRect( - rosen::Rect(rect.GetRect().Left(), rect.GetRect().Top(), rect.GetRect().Right(), rect.GetRect().Bottom())); - roundRect_.SetCornerRadius(rosen::RoundRect::CornerPos::TOP_LEFT_POS, + Rosen::Drawing::Rect(rect.GetRect().Left(), rect.GetRect().Top(), rect.GetRect().Right(), rect.GetRect().Bottom())); + roundRect_.SetCornerRadius(Rosen::Drawing::RoundRect::CornerPos::TOP_LEFT_POS, rect.GetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS).x, rect.GetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS).y); - roundRect_.SetCornerRadius(rosen::RoundRect::CornerPos::TOP_RIGHT_POS, + roundRect_.SetCornerRadius(Rosen::Drawing::RoundRect::CornerPos::TOP_RIGHT_POS, rect.GetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS).x, rect.GetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS).y); - roundRect_.SetCornerRadius(rosen::RoundRect::CornerPos::BOTTOM_LEFT_POS, + roundRect_.SetCornerRadius(Rosen::Drawing::RoundRect::CornerPos::BOTTOM_LEFT_POS, rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS).x, rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS).y); - roundRect_.SetCornerRadius(rosen::RoundRect::CornerPos::BOTTOM_RIGHT_POS, + roundRect_.SetCornerRadius(Rosen::Drawing::RoundRect::CornerPos::BOTTOM_RIGHT_POS, rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS).x, rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS).y); } @@ -80,4 +80,4 @@ private: }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_FOCUS_STATE_MODIFIER_H \ No newline at end of file +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_FOCUS_STATE_MODIFIER_H diff --git a/frameworks/core/components_ng/render/adapter/overlay_modifier.h b/frameworks/core/components_ng/render/adapter/overlay_modifier.h index bb7fb2fae7ddbc7f03def30b4ced4316d30c5593..0d05ef31405869b92d8f44d364938f8f2937c6b7 100644 --- a/frameworks/core/components_ng/render/adapter/overlay_modifier.h +++ b/frameworks/core/components_ng/render/adapter/overlay_modifier.h @@ -74,18 +74,18 @@ public: paraStyle.locale_ = Localization::GetInstance()->GetFontLocale(); paraStyle.wordBreakType_ = ToRSWordBreakType(textStyle.GetWordBreak()); paraStyle.fontSize_ = fontSize.Value(); - auto builder = RSParagraphBuilder::CreateRosenBuilder(paraStyle, RSFontCollection::GetInstance(false)); + auto builder = RSParagraphBuilder::Create(paraStyle, RSFontCollection::Create()); CHECK_NULL_VOID(builder); auto pipelineContext = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); builder->PushStyle(ToRSTextStyle(pipelineContext, textStyle)); - builder->AddText(StringUtils::Str8ToStr16(overlayOptions.content)); - builder->Pop(); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(overlayOptions.content)); + builder->PopStyle(); + auto paragraph = builder->CreateTypography(); CHECK_NULL_VOID(paragraph); paragraph->Layout(context.width); OffsetF offset = OverlayTextModifier::GetTextPosition(SizeF(context.width, context.height), - SizeF(paragraph->GetLongestLine(), paragraph->GetHeight()), overlayOptions); + SizeF(paragraph->GetActualWidth(), paragraph->GetHeight()), overlayOptions); std::shared_ptr skCanvas { context.canvas, [](SkCanvas*) {} }; RSCanvas canvas(&skCanvas); CHECK_NULL_VOID(&canvas); @@ -122,4 +122,4 @@ private: } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_OVERLAY_MODIFIER_H \ No newline at end of file +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_OVERLAY_MODIFIER_H diff --git a/frameworks/core/components_ng/render/adapter/txt_font_collection.cpp b/frameworks/core/components_ng/render/adapter/txt_font_collection.cpp index 7ee9056e8f969627fe7cd3ab4353a2c872f64b42..8a4d15f263dbb985ac7c573ac4f4aad4cb0bb8b9 100644 --- a/frameworks/core/components_ng/render/adapter/txt_font_collection.cpp +++ b/frameworks/core/components_ng/render/adapter/txt_font_collection.cpp @@ -34,18 +34,20 @@ RefPtr FontCollection::Current() int32_t id = Container::CurrentId(); auto window = flutter::ace::WindowManager::GetWindow(id); CHECK_NULL_RETURN(window, nullptr); - return AceType::MakeRefPtr(window->GetFontCollection()); + return AceType::MakeRefPtr( + Rosen::FontCollection::From(window->GetFontCollection())); #else CHECK_NULL_RETURN(flutter::UIDartState::Current(), nullptr); auto window = flutter::UIDartState::Current()->window(); CHECK_NULL_RETURN(window, nullptr); CHECK_NULL_RETURN(window->client(), nullptr); auto& fontCollection = window->client()->GetFontCollection(); - return AceType::MakeRefPtr(fontCollection.GetFontCollection()); + return AceType::MakeRefPtr( + Rosen::FontCollection::From(fontCollection.GetFontCollection())); #endif } -TxtFontCollection::TxtFontCollection(const std::shared_ptr& fontCollection) +TxtFontCollection::TxtFontCollection(const std::shared_ptr& fontCollection) : collection_(fontCollection) {} diff --git a/frameworks/core/components_ng/render/adapter/txt_font_collection.h b/frameworks/core/components_ng/render/adapter/txt_font_collection.h index 20ced5dafae7236b376173f82915a942b4a43c11..a0ffa9230505d2f0e6205d0a766f7c948ff0bb18 100644 --- a/frameworks/core/components_ng/render/adapter/txt_font_collection.h +++ b/frameworks/core/components_ng/render/adapter/txt_font_collection.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_TXT_FONT_COLLECTION_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_TXT_FONT_COLLECTION_H -#include "txt/font_collection.h" +#include "rosen_text/font_collection.h" #include "base/memory/ace_type.h" #include "base/utils/macros.h" @@ -27,16 +27,16 @@ namespace OHOS::Ace::NG { class ACE_EXPORT TxtFontCollection : public FontCollection { DECLARE_ACE_TYPE(TxtFontCollection, FontCollection) public: - explicit TxtFontCollection(const std::shared_ptr& fontCollection); + explicit TxtFontCollection(const std::shared_ptr& fontCollection); ~TxtFontCollection() override = default; - const std::shared_ptr& GetRawFontCollection() + const std::shared_ptr& GetRawFontCollection() { return collection_; } private: - std::shared_ptr collection_; + std::shared_ptr collection_; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp b/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp index e51736e72e3ee564cb17d1a3074d94c2bc1fb800..f50439208f35b4983c325a23c60c3be6760ea93f 100644 --- a/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp +++ b/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp @@ -25,13 +25,14 @@ namespace OHOS::Ace::NG { namespace { const std::u16string ELLIPSIS = u"\u2026"; constexpr char16_t NEWLINE_CODE = u'\n'; -} // namespace -RefPtr Paragraph::Create(const ParagraphStyle& paraStyle, const RefPtr& fontCollection) +} +RefPtr Paragraph::Create(const WeakPtr &context, const ParagraphStyle ¶Style, + const RefPtr &fontCollection) { auto txtFontCollection = DynamicCast(fontCollection); CHECK_NULL_RETURN(txtFontCollection, nullptr); auto sharedFontCollection = txtFontCollection->GetRawFontCollection(); - return AceType::MakeRefPtr(paraStyle, sharedFontCollection); + return AceType::MakeRefPtr(context, paraStyle, sharedFontCollection); } bool TxtParagraph::IsValid() @@ -41,19 +42,19 @@ bool TxtParagraph::IsValid() void TxtParagraph::CreateBuilder() { - txt::ParagraphStyle style; - style.text_direction = Constants::ConvertTxtTextDirection(paraStyle_.direction); - style.text_align = Constants::ConvertTxtTextAlign(paraStyle_.align); - style.max_lines = paraStyle_.maxLines; - style.locale = paraStyle_.fontLocale; + Rosen::TypographyStyle style; + style.textDirection_ = Constants::ConvertTxtTextDirection(paraStyle_.direction); + style.textAlign_ = Constants::ConvertTxtTextAlign(paraStyle_.align); + style.maxLines_ = paraStyle_.maxLines; + style.locale_ = paraStyle_.fontLocale; if (paraStyle_.textOverflow == TextOverflow::ELLIPSIS) { - style.ellipsis = ELLIPSIS; + style.ellipsis_ = ELLIPSIS; } #ifndef FLUTTER_2_5 // keep WordBreak define same with WordBreakType in minikin - style.word_break_type = static_cast(paraStyle_.wordBreak); + style.wordBreakType_ = static_cast(paraStyle_.wordBreak); #endif - builder_ = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection_); + builder_ = Rosen::TypographyCreate::Create(style, fontCollection_); } void TxtParagraph::PushStyle(const TextStyle& style) @@ -62,15 +63,15 @@ void TxtParagraph::PushStyle(const TextStyle& style) CreateBuilder(); } - txt::TextStyle txtStyle; - Constants::ConvertTxtStyle(style, PipelineContext::GetCurrentContext(), txtStyle); + Rosen::TextStyle txtStyle; + Constants::ConvertTxtStyle(style, context_, txtStyle); builder_->PushStyle(txtStyle); } void TxtParagraph::PopStyle() { CHECK_NULL_VOID(builder_); - builder_->Pop(); + builder_->PopStyle(); } void TxtParagraph::AddText(const std::u16string& text) @@ -79,13 +80,14 @@ void TxtParagraph::AddText(const std::u16string& text) CreateBuilder(); } text_ = text; - builder_->AddText(text); + builder_->AppendText(text); } void TxtParagraph::Build() { - CHECK_NULL_VOID_NOLOG(builder_); - paragraph_ = builder_->Build(); + if (builder_) { + paragraph_ = builder_->CreateTypography(); + } } void TxtParagraph::Reset() @@ -111,9 +113,9 @@ float TxtParagraph::GetTextWidth() { CHECK_NULL_RETURN(paragraph_, 0.0f); if (GetLineCount() == 1) { - return std::max(paragraph_->GetLongestLine(), paragraph_->GetMaxIntrinsicWidth()); + return std::max(paragraph_->GetActualWidth(), paragraph_->GetMaxIntrinsicWidth()); } - return paragraph_->GetLongestLine(); + return paragraph_->GetActualWidth(); } float TxtParagraph::GetMaxIntrinsicWidth() @@ -131,7 +133,10 @@ bool TxtParagraph::DidExceedMaxLines() float TxtParagraph::GetLongestLine() { CHECK_NULL_RETURN(paragraph_, 0.0f); - return static_cast(paragraph_->GetLongestLine()); + if (GetLineCount() == 1) { + return std::max(paragraph_->GetActualWidth(), paragraph_->GetMaxIntrinsicWidth()); + } + return static_cast(paragraph_->GetActualWidth()); } float TxtParagraph::GetMaxWidth() @@ -148,9 +153,8 @@ float TxtParagraph::GetAlphabeticBaseline() size_t TxtParagraph::GetLineCount() { - auto* paragraphTxt = static_cast(paragraph_.get()); - CHECK_NULL_RETURN(paragraphTxt, 0); - return paragraphTxt->GetLineCount(); + CHECK_NULL_RETURN(paragraph_, 0); + return paragraph_->GetLineCount(); } void TxtParagraph::Paint(const RSCanvas& canvas, float x, float y) @@ -172,7 +176,7 @@ int32_t TxtParagraph::GetHandlePositionForClick(const Offset& offset) if (!paragraph_) { return 0; } - return static_cast(paragraph_->GetGlyphPositionAtCoordinate(offset.GetX(), offset.GetY()).position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate(offset.GetX(), offset.GetY()).index_); } bool TxtParagraph::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics& result) @@ -189,18 +193,18 @@ bool TxtParagraph::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics& r result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !text_.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { return false; @@ -211,17 +215,17 @@ bool TxtParagraph::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics& r if (prevChar == NEWLINE_CODE) { // Return the start of next line. result.offset.SetX(0.0); - result.offset.SetY(textBox.rect.fBottom); + result.offset.SetY(textBox.rect_.GetBottom()); return true; } - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fRight : textBox.rect.fLeft; + double caretStart = isLtr ? textBox.rect_.GetRight() : textBox.rect_.GetLeft(); double offsetX = std::min(caretStart, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -235,33 +239,33 @@ bool TxtParagraph::ComputeOffsetForCaretDownstream(int32_t extent, CaretMetrics& result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - extent, next, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + extent, next, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return false; } const auto& textBox = *boxes.begin(); - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fLeft : textBox.rect.fRight; + double caretStart = isLtr ? textBox.rect_.GetLeft() : textBox.rect_.GetRight(); double offsetX = std::min(caretStart, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } void TxtParagraph::GetRectsForRange(int32_t start, int32_t end, std::vector& selectedRects) { - const auto& boxes = paragraph_->GetRectsForRange( - start, end, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary( + start, end, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return; } for (const auto& box : boxes) { - auto selectionRect = Constants::ConvertSkRect(box.rect); + auto selectionRect = Constants::ConvertSkRect(box.rect_); selectedRects.emplace_back(selectionRect); } } diff --git a/frameworks/core/components_ng/render/adapter/txt_paragraph.h b/frameworks/core/components_ng/render/adapter/txt_paragraph.h index 8bd39be54d85712cd51cdab7c53ece249668d881..ad96f364dc8ede5545a975e3d9723ec5f3fb2610 100644 --- a/frameworks/core/components_ng/render/adapter/txt_paragraph.h +++ b/frameworks/core/components_ng/render/adapter/txt_paragraph.h @@ -16,9 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_TXT_PARAGRAPH_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_TXT_PARAGRAPH_H -#include "flutter/third_party/txt/src/txt/font_collection.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography_create.h" #include "base/utils/noncopyable.h" #include "core/components_ng/render/paragraph.h" @@ -30,8 +28,9 @@ class TxtParagraph : public Paragraph { DECLARE_ACE_TYPE(NG::TxtParagraph, NG::Paragraph) public: - TxtParagraph(const ParagraphStyle& paraStyle, std::shared_ptr fontCollection) - : paraStyle_(paraStyle), fontCollection_(std::move(fontCollection)) + TxtParagraph(const WeakPtr& context, const ParagraphStyle& paraStyle, + std::shared_ptr fontCollection) + : context_(context), paraStyle_(paraStyle), fontCollection_(fontCollection) {} ~TxtParagraph() override = default; @@ -69,10 +68,11 @@ public: private: void CreateBuilder(); + const WeakPtr& context_; ParagraphStyle paraStyle_; - std::unique_ptr paragraph_; - std::unique_ptr builder_; - std::shared_ptr fontCollection_; + std::unique_ptr paragraph_; + std::unique_ptr builder_; + std::shared_ptr fontCollection_; std::u16string text_; ACE_DISALLOW_COPY_AND_MOVE(TxtParagraph); diff --git a/frameworks/core/components_ng/render/drawing.h b/frameworks/core/components_ng/render/drawing.h index 2044a0509206007e0dd10d11dcf4ed789351112c..a90e47c81dc3aa6b71481a845ef7cbac32cc9d51 100644 --- a/frameworks/core/components_ng/render/drawing.h +++ b/frameworks/core/components_ng/render/drawing.h @@ -22,9 +22,9 @@ #include "drawing/engine_adapter/skia_adapter/skia_canvas.h" #include "image/image.h" #include "rosen_text/properties/text_style.h" -#include "rosen_text/ui/font_collection.h" -#include "rosen_text/ui/typography.h" -#include "rosen_text/ui/typography_create.h" +#include "rosen_text/font_collection.h" +#include "rosen_text/typography.h" +#include "rosen_text/typography_create.h" #include "utils/camera3d.h" #include "utils/point3.h" #include "utils/scalar.h" @@ -61,23 +61,22 @@ using RSCamera3D = Rosen::Drawing::Camera3D; using RSMaskFilter = Rosen::Drawing::MaskFilter; using RSBlurType = Rosen::Drawing::BlurType; -using RSPathEffect = rosen::PathEffect; -using RSPathDirection = rosen::PathDirection; -using RSPathDashStyle = rosen::PathDashStyle; -using RSParagraph = rosen::Typography; -using RSTypographyProperties = rosen::TypographyProperties; -using RSParagraphBuilder = rosen::TypographyCreate; -using RSFontCollection = rosen::FontCollection; -using RSParagraphStyle = rosen::TypographyStyle; -using RSColorQuad = rosen::ColorQuad; -using RSShaderEffect = rosen::ShaderEffect; -using RSTileMode = rosen::TileMode; -using RSTextDirection = rosen::TextDirection; -using RSTextAlign = rosen::TextAlign; -using RSWordBreakType = rosen::WordBreakType; -using RSTextStyle = rosen::TextStyle; -using RSTextDecoration = rosen::TextDecoration; -using RSFontWeight = rosen::FontWeight; +using RSPathEffect = Rosen::Drawing::PathEffect; +using RSPathDirection = Rosen::Drawing::PathDirection; +using RSPathDashStyle = Rosen::Drawing::PathDashStyle; +using RSParagraph = OHOS::Rosen::Typography; +using RSParagraphBuilder = Rosen::TypographyCreate; +using RSFontCollection = Rosen::FontCollection; +using RSParagraphStyle = Rosen::TypographyStyle; +using RSColorQuad = Rosen::Drawing::ColorQuad; +using RSShaderEffect = Rosen::Drawing::ShaderEffect; +using RSTileMode = Rosen::Drawing::TileMode; +using RSTextDirection = Rosen::TextDirection; +using RSTextAlign = Rosen::TextAlign; +using RSWordBreakType = Rosen::WordBreakType; +using RSTextStyle = Rosen::TextStyle; +using RSTextDecoration = Rosen::TextDecoration; +using RSFontWeight = Rosen::FontWeight; } // namespace OHOS::Ace #else #include "core/components_ng/render/drawing_mock.h" diff --git a/frameworks/core/components_ng/render/drawing_prop_convertor.cpp b/frameworks/core/components_ng/render/drawing_prop_convertor.cpp index ef75a9f586d5a02d74d606901dab5b9ab601305a..24e4e2cba3f16063c2a505d27bc6556436ddc0a2 100644 --- a/frameworks/core/components_ng/render/drawing_prop_convertor.cpp +++ b/frameworks/core/components_ng/render/drawing_prop_convertor.cpp @@ -121,7 +121,7 @@ RSFontWeight ToRSFontWeight(FontWeight fontWeight) RSWordBreakType ToRSWordBreakType(const WordBreak& wordBreak) { // should keep enum same with rosen. - return static_cast(wordBreak); + return static_cast(wordBreak); } RSTextDecoration ToRSTextDecoration(TextDecoration textDecoration) @@ -150,12 +150,11 @@ RSTextStyle ToRSTextStyle(const RefPtr& context, const TextStyle& rsTextStyle.color_ = ToRSColor(textStyle.GetTextColor()); rsTextStyle.decoration_ = ToRSTextDecoration(textStyle.GetTextDecoration()); rsTextStyle.decorationColor_ = ToRSColor(textStyle.GetTextDecorationColor()); - // TODO: convert fontFamily and other styles. // TODO: convert missing textBaseline - rsTextStyle.fontWeight_ = ToRSFontWeight(textStyle.GetFontWeight()); - rsTextStyle.fontStyle_ = static_cast(textStyle.GetFontStyle()); - rsTextStyle.textBaseline_ = static_cast(textStyle.GetTextBaseline()); + rsTextStyle.fontWeight_ = static_cast(textStyle.GetFontWeight()); + rsTextStyle.fontStyle_ = static_cast(textStyle.GetFontStyle()); + rsTextStyle.baseline_ = static_cast(textStyle.GetTextBaseline()); rsTextStyle.fontFamilies_ = textStyle.GetFontFamilies(); if (textStyle.GetTextOverflow() == TextOverflow::ELLIPSIS) { rsTextStyle.ellipsis_ = StringUtils::Str8ToStr16(StringUtils::ELLIPSIS); @@ -182,24 +181,24 @@ RSTextStyle ToRSTextStyle(const RefPtr& context, const TextStyle& } if (textStyle.GetLineHeight().Unit() == DimensionUnit::PERCENT) { - rsTextStyle.hasHeightOverride_ = true; - rsTextStyle.height_ = textStyle.GetLineHeight().Value(); + rsTextStyle.heightOnly_ = true; + rsTextStyle.heightScale_ = textStyle.GetLineHeight().Value(); } else { double fontSize = rsTextStyle.fontSize_; double lineHeight = textStyle.GetLineHeight().Value(); if (context) { lineHeight = context->NormalizeToPx(textStyle.GetLineHeight()); } - rsTextStyle.hasHeightOverride_ = textStyle.HasHeightOverride(); + rsTextStyle.heightOnly_ = textStyle.HasHeightOverride(); if (!NearEqual(lineHeight, fontSize) && (lineHeight > 0.0) && (!NearZero(fontSize))) { - rsTextStyle.height_ = lineHeight / fontSize; + rsTextStyle.heightScale_ = lineHeight / fontSize; } else { LOGD("use default text style height value."); - rsTextStyle.height_ = 1; + rsTextStyle.heightScale_ = 1; static const int32_t BEGIN_VERSION = 6; auto isBeginVersion = context && context->GetMinPlatformVersion() >= BEGIN_VERSION; if (NearZero(lineHeight) || (!isBeginVersion && NearEqual(lineHeight, fontSize))) { - rsTextStyle.hasHeightOverride_ = false; + rsTextStyle.heightOnly_ = false; } } } diff --git a/frameworks/core/components_ng/render/paragraph.h b/frameworks/core/components_ng/render/paragraph.h index 87853d0314c425168c8778aeb129c10d1e873372..208f3104b34f5e680b1f82e92808150fa521bf06 100644 --- a/frameworks/core/components_ng/render/paragraph.h +++ b/frameworks/core/components_ng/render/paragraph.h @@ -40,7 +40,8 @@ class Paragraph : public virtual AceType { DECLARE_ACE_TYPE(NG::Paragraph, AceType) public: - static RefPtr Create(const ParagraphStyle& paraStyle, const RefPtr& fontCollection); + static RefPtr Create(const WeakPtr& context, const ParagraphStyle& paraStyle, + const RefPtr& fontCollection); // whether the paragraph has been build virtual bool IsValid() = 0; diff --git a/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_manager/BUILD.gn b/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_manager/BUILD.gn index 4fe853b6eb61ba5f825e34feb2329edb949cd60f..6fa424107fdc62c70579565e2077f96c7eb89d92 100644 --- a/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_manager/BUILD.gn +++ b/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_manager/BUILD.gn @@ -101,6 +101,6 @@ ohos_unittest("drag_drop_manager_test_ng") { "$ace_root:ace_config", "$ace_flutter_engine_root/skia:skia_config", "//commonlibrary/c_utils/base:utils_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", ] } diff --git a/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_proxy/BUILD.gn b/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_proxy/BUILD.gn index bd983dd3528ad944f619e09ce0da5d8b94b4c492..e1bcbf377347e26e079404759036a16e3d6b5396 100644 --- a/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_proxy/BUILD.gn +++ b/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_proxy/BUILD.gn @@ -75,6 +75,6 @@ ohos_unittest("drag_drop_proxy_test_ng") { "$ace_root:ace_config", "$ace_flutter_engine_root/skia:skia_config", "//commonlibrary/c_utils/base:utils_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", ] } diff --git a/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_manager/BUILD.gn b/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_manager/BUILD.gn index e858faf8860d438694170c4a58d6a894ba9017b0..b8df4edcf57bc5380de9d5b39203673cec66e362 100644 --- a/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_manager/BUILD.gn +++ b/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_manager/BUILD.gn @@ -71,6 +71,6 @@ ohos_unittest("select_overlay_manager_test_ng") { "$ace_root:ace_config", "$ace_flutter_engine_root/skia:skia_config", "//commonlibrary/c_utils/base:utils_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", ] } diff --git a/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_proxy/BUILD.gn b/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_proxy/BUILD.gn index 2715d1eecf03b26f1ae48d6c52e4d2887f57896a..2c72b09202c09f7020e944207e1525ce54fd57d9 100644 --- a/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_proxy/BUILD.gn +++ b/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_proxy/BUILD.gn @@ -71,6 +71,6 @@ ohos_unittest("select_overlay_proxy_test_ng") { "$ace_root:ace_config", "$ace_flutter_engine_root/skia:skia_config", "//commonlibrary/c_utils/base:utils_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", ] } diff --git a/frameworks/core/components_ng/test/pattern/ability_component/BUILD.gn b/frameworks/core/components_ng/test/pattern/ability_component/BUILD.gn index 8a25bba2ceb7bf1ac659b69004289da4bed556ad..0da5b27fc93ff0630ed7cac8cfbf765a5a8794e5 100644 --- a/frameworks/core/components_ng/test/pattern/ability_component/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/ability_component/BUILD.gn @@ -115,7 +115,7 @@ ohos_unittest("ability_component_pattern_test_ng") { "//commonlibrary/c_utils/base:utils_config", "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:export_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:render_service_client_config", "//foundation/window/window_manager/extension/extension_connection:libwindow_extension_client_private_config", "//foundation/window/window_manager/extension/extension_connection:libextension_connection_public_config", diff --git a/frameworks/core/components_ng/test/pattern/image_animator/BUILD.gn b/frameworks/core/components_ng/test/pattern/image_animator/BUILD.gn index 05f015c8ff342c8cd74ef20e4031ecfa36078457..c928e9feedb1f19fa8c3c1cefcfffce7e94acec0 100644 --- a/frameworks/core/components_ng/test/pattern/image_animator/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/image_animator/BUILD.gn @@ -93,7 +93,7 @@ ohos_unittest("image_animator_pattern_test") { "//commonlibrary/c_utils/base:utils_config", "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:export_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:render_service_client_config", ] } diff --git a/frameworks/core/components_ng/test/pattern/option/BUILD.gn b/frameworks/core/components_ng/test/pattern/option/BUILD.gn index 9584f24cc39f163fe73f8df2db89ae744bfb243b..f7d17712286729c602c254355150585661eec227 100644 --- a/frameworks/core/components_ng/test/pattern/option/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/option/BUILD.gn @@ -105,7 +105,7 @@ ohos_unittest("panel_option_test_ng") { "//commonlibrary/c_utils/base:utils_config", "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:export_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:render_service_client_config", ] } diff --git a/frameworks/core/components_ng/test/render/adapter/BUILD.gn b/frameworks/core/components_ng/test/render/adapter/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b774758898e2fdcefb052f311c0295534f01264a --- /dev/null +++ b/frameworks/core/components_ng/test/render/adapter/BUILD.gn @@ -0,0 +1,169 @@ +# Copyright (c) 2022 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. + +import("//build/test.gni") +import("//foundation/arkui/ace_engine/ace_config.gni") + +ohos_unittest("rosen_border_image_painter_test") { + module_out_path = "$test_output_path/render" + + include_dirs = [ + "//third_party/flutter/skia/src", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include/draw", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src/drawing", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src/drawing/engine_adapter", + ] + + sources = [ + # inner + "$ace_root/adapter/ohos/osal/log_wrapper.cpp", + "$ace_root/adapter/preview/osal/frame_trace_adapter_impl.cpp", + "$ace_root/frameworks/base/geometry/animatable_dimension.cpp", + "$ace_root/frameworks/base/geometry/dimension.cpp", + "$ace_root/frameworks/base/log/dump_log.cpp", + "$ace_root/frameworks/base/memory/memory_monitor.cpp", + "$ace_root/frameworks/base/thread/background_task_executor.cpp", + "$ace_root/frameworks/base/utils/base_id.cpp", + "$ace_root/frameworks/core/animation/animator.cpp", + "$ace_root/frameworks/core/animation/anticipate_curve.cpp", + "$ace_root/frameworks/core/animation/cubic_curve.cpp", + "$ace_root/frameworks/core/animation/curves.cpp", + "$ace_root/frameworks/core/animation/scheduler.cpp", + "$ace_root/frameworks/core/common/ace_engine.cpp", + "$ace_root/frameworks/core/common/anr_thread.cpp", + "$ace_root/frameworks/core/common/container.cpp", + "$ace_root/frameworks/core/common/container_scope.cpp", + "$ace_root/frameworks/core/common/watch_dog.cpp", + "$ace_root/frameworks/core/components/common/properties/border_image.cpp", + "$ace_root/frameworks/core/components/common/properties/border_image_edge.cpp", + "$ace_root/frameworks/core/components/common/properties/color.cpp", + "$ace_root/frameworks/core/components/common/properties/decoration.cpp", + "$ace_root/frameworks/core/components/test/unittest/mock/ace_trace_mock.cpp", + "$ace_root/frameworks/core/components_ng/render/adapter/skia_decoration_painter.cpp", + "$ace_root/frameworks/core/components_ng/render/border_image_painter.cpp", + "$ace_root/frameworks/core/components_ng/render/render_context.cpp", + "$ace_root/frameworks/core/image/flutter_image_cache.cpp", + "$ace_root/frameworks/core/image/image_cache.cpp", + + # mock + "$ace_root/frameworks/base/test/mock/mock_system_properties.cpp", + "$ace_root/frameworks/core/pipeline/pipeline_base.cpp", + + # self + "rosen_border_image_painter_test.cpp", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + deps = [ + "$ace_flutter_engine_root:third_party_flutter_engine_ohos", + "$ace_flutter_engine_root/skia:ace_skia_ohos", + "$cjson_root:cjson_static", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + "//third_party/googletest:gmock_main", + ] + + configs = [ + "$ace_root:ace_test_coverage_config", + "$ace_root:ace_test_config", + "$ace_root:ace_config", + "$ace_flutter_engine_root:flutter_config", + "$ace_flutter_engine_root/skia:skia_config", + "//commonlibrary/c_utils/base:utils_config", + "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle_public_config", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:export_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:render_service_client_config", + ] +} + +ohos_unittest("rosen_border_image_painter_test_ng") { + module_out_path = "$test_output_path/render" + + include_dirs = [ + "//third_party/flutter/skia/src", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include/draw", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src/drawing", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src/drawing/engine_adapter", + ] + + sources = [ + # inner + "$ace_root/adapter/ohos/osal/log_wrapper.cpp", + "$ace_root/adapter/preview/osal/frame_trace_adapter_impl.cpp", + "$ace_root/frameworks/base/geometry/animatable_dimension.cpp", + "$ace_root/frameworks/base/geometry/dimension.cpp", + "$ace_root/frameworks/base/log/dump_log.cpp", + "$ace_root/frameworks/base/memory/memory_monitor.cpp", + "$ace_root/frameworks/base/thread/background_task_executor.cpp", + "$ace_root/frameworks/base/utils/base_id.cpp", + "$ace_root/frameworks/core/animation/animator.cpp", + "$ace_root/frameworks/core/animation/anticipate_curve.cpp", + "$ace_root/frameworks/core/animation/cubic_curve.cpp", + "$ace_root/frameworks/core/animation/curves.cpp", + "$ace_root/frameworks/core/animation/scheduler.cpp", + "$ace_root/frameworks/core/common/ace_engine.cpp", + "$ace_root/frameworks/core/common/anr_thread.cpp", + "$ace_root/frameworks/core/common/container.cpp", + "$ace_root/frameworks/core/common/container_scope.cpp", + "$ace_root/frameworks/core/common/watch_dog.cpp", + "$ace_root/frameworks/core/components/common/properties/border_image_edge.cpp", + "$ace_root/frameworks/core/components/common/properties/color.cpp", + "$ace_root/frameworks/core/components/common/properties/decoration.cpp", + "$ace_root/frameworks/core/components/test/unittest/mock/ace_trace_mock.cpp", + "$ace_root/frameworks/core/components_ng/render/adapter/skia_decoration_painter.cpp", + "$ace_root/frameworks/core/components_ng/render/border_image_painter.cpp", + "$ace_root/frameworks/core/components_ng/render/render_context.cpp", + "$ace_root/frameworks/core/components_ng/test/mock/render/mock_border_image.cpp", + "$ace_root/frameworks/core/image/flutter_image_cache.cpp", + "$ace_root/frameworks/core/image/image_cache.cpp", + + # mock + "$ace_root/frameworks/base/test/mock/mock_system_properties.cpp", + "$ace_root/frameworks/core/pipeline/pipeline_base.cpp", + + # self + "rosen_border_image_painter_test_ng.cpp", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + deps = [ + "$ace_flutter_engine_root:third_party_flutter_engine_ohos", + "$ace_flutter_engine_root/skia:ace_skia_ohos", + "$cjson_root:cjson_static", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + "//third_party/googletest:gmock_main", + ] + + configs = [ + "$ace_root:ace_test_coverage_config", + "$ace_root:ace_test_config", + "$ace_root:ace_config", + "$ace_flutter_engine_root:flutter_config", + "$ace_flutter_engine_root/skia:skia_config", + "//commonlibrary/c_utils/base:utils_config", + "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle_public_config", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:export_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:render_service_client_config", + ] +}