From a93b1355710435ae6820c960947b5c08b667e3c0 Mon Sep 17 00:00:00 2001 From: b200200 Date: Mon, 26 Sep 2022 11:04:19 +0800 Subject: [PATCH 1/2] using rosen_text Change-Id: I620364d88fdd5df3dc2e868bbbff9e3291cf85fa Signed-off-by: b200200 --- .gitignore | 1 - adapter/ohos/entrance/BUILD.gn | 1 + .../ohos/entrance/window/drag_window_ohos.cpp | 9 +- .../ohos/entrance/window/drag_window_ohos.h | 2 +- frameworks/base/window/drag_window.h | 6 +- frameworks/core/BUILD.gn | 1 + .../calendar/flutter_render_calendar.cpp | 125 +++++------ .../calendar/flutter_render_calendar.h | 14 +- .../calendar/rosen_render_calendar.cpp | 125 +++++------ .../calendar/rosen_render_calendar.h | 15 +- .../components/chart/flutter_render_chart.cpp | 24 +- .../components/chart/flutter_render_chart.h | 2 +- .../components/chart/rosen_render_chart.cpp | 24 +- .../components/chart/rosen_render_chart.h | 2 +- .../painter/flutter_scroll_fade_painter.cpp | 2 +- frameworks/core/components/components.gni | 1 + .../flutter_render_custom_paint.cpp | 102 ++++----- .../flutter_render_custom_paint.h | 15 +- .../flutter_render_offscreen_canvas.cpp | 112 +++++---- .../flutter_render_offscreen_canvas.h | 11 +- .../rosen_render_custom_paint.cpp | 103 +++++---- .../custom_paint/rosen_render_custom_paint.h | 17 +- .../rosen_render_offscreen_canvas.cpp | 112 +++++---- .../rosen_render_offscreen_canvas.h | 11 +- .../components/font/constants_converter.cpp | 169 +++++++------- .../components/font/constants_converter.h | 28 ++- .../font/flutter_font_collection.cpp | 8 +- .../components/font/flutter_font_collection.h | 2 +- .../core/components/font/font_collection.h | 6 +- .../components/font/rosen_font_collection.cpp | 8 +- .../components/font/rosen_font_collection.h | 2 +- .../multimodal/flutter_render_multimodal.cpp | 32 +-- .../multimodal/flutter_render_multimodal.h | 4 +- .../multimodal/rosen_render_multimodal.cpp | 32 +-- .../multimodal/rosen_render_multimodal.h | 4 +- .../components/root/flutter_render_root.cpp | 2 +- .../components/text/flutter_render_text.cpp | 53 ++--- .../components/text/flutter_render_text.h | 2 +- .../components/text/rosen_render_text.cpp | 53 ++--- .../core/components/text/rosen_render_text.h | 2 +- .../text_field/flutter_render_text_field.cpp | 211 +++++++++-------- .../text_field/flutter_render_text_field.h | 32 +-- .../text_field/rosen_render_text_field.cpp | 212 +++++++++--------- .../text_field/rosen_render_text_field.h | 34 +-- .../text_overlay/text_overlay_manager.cpp | 73 +++--- .../text_overlay/text_overlay_manager.h | 6 +- .../text_span/flutter_render_text_span.cpp | 8 +- .../text_span/flutter_render_text_span.h | 4 +- .../text_span/rosen_render_text_span.cpp | 8 +- .../text_span/rosen_render_text_span.h | 4 +- .../track/flutter_render_arc_track.cpp | 26 +-- .../track/rosen_render_arc_track.cpp | 26 +-- frameworks/core/components_ng/components.gni | 1 + .../components_ng/pattern/text/span_node.cpp | 2 +- .../pattern/text/text_layout_algorithm.cpp | 20 +- .../pattern/toggle/switch_paint_method.cpp | 24 +- .../render/adapter/txt_font_collection.cpp | 8 +- .../render/adapter/txt_font_collection.h | 8 +- .../render/adapter/txt_paragraph.cpp | 36 +-- .../render/adapter/txt_paragraph.h | 15 +- .../core/components_ng/render/drawing.h | 29 +-- .../render/drawing_prop_convertor.cpp | 47 ++-- .../render/drawing_prop_convertor.h | 8 +- 63 files changed, 1040 insertions(+), 1046 deletions(-) diff --git a/.gitignore b/.gitignore index 20f0dbd368c..0b27b776ac8 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 dbbd765e761..cec69fab978 100644 --- a/adapter/ohos/entrance/BUILD.gn +++ b/adapter/ohos/entrance/BUILD.gn @@ -80,6 +80,7 @@ template("ace_ohos_standard_source_set") { "$ace_flutter_engine_root:third_party_flutter_engine_$platform", "$ace_flutter_engine_root/skia:ace_skia_$platform", "$ace_root/adapter/ohos/capability:ace_capability_ohos", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", diff --git a/adapter/ohos/entrance/window/drag_window_ohos.cpp b/adapter/ohos/entrance/window/drag_window_ohos.cpp index 73b9faf1624..d6b960979a3 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" @@ -250,7 +253,7 @@ void DragWindowOhos::DrawImage(void* skImage) #endif } -void DragWindowOhos::DrawText(std::shared_ptr paragraph, +void DragWindowOhos::DrawText(std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText) { #ifdef ENABLE_ROSEN_BACKEND @@ -308,4 +311,4 @@ void DragWindowOhos::DrawText(std::shared_ptr paragraph, rsUiDirector_->SendMessages(); #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 22747711e2a..b66080170d1 100644 --- a/adapter/ohos/entrance/window/drag_window_ohos.h +++ b/adapter/ohos/entrance/window/drag_window_ohos.h @@ -39,7 +39,7 @@ public: void DrawPixelMap(const RefPtr& pixelMap) override; void DrawFrameNode(const RefPtr& rootNode) override; void DrawImage(void* skImage) override; - void DrawText(std::shared_ptr paragraph, + void DrawText(std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText) override; private: diff --git a/frameworks/base/window/drag_window.h b/frameworks/base/window/drag_window.h index a01c7f4a1ca..655c324309b 100644 --- a/frameworks/base/window/drag_window.h +++ b/frameworks/base/window/drag_window.h @@ -20,8 +20,8 @@ #include "base/geometry/offset.h" #include "base/memory/ace_type.h" -namespace txt { -class Paragraph; +namespace OHOS::Rosen { +class Typography; } namespace OHOS::Ace { @@ -43,7 +43,7 @@ public: virtual void DrawPixelMap(const RefPtr& pixelmap) = 0; virtual void DrawFrameNode(const RefPtr& rootNode) = 0; virtual void DrawImage(void* skImage) = 0; - virtual void DrawText(std::shared_ptr paragraph_, + virtual void DrawText(std::shared_ptr paragraph_, const Offset& offset, const RefPtr& renderText) = 0; void SetOffset(int32_t offsetX, int32_t offsetY) { diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 7e27ded6221..34797d807ea 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/base:ace_core_components_base_ng_$platform", diff --git a/frameworks/core/components/calendar/flutter_render_calendar.cpp b/frameworks/core/components/calendar/flutter_render_calendar.cpp index 21301464da3..b3933a50442 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 cd39478c553..16d178761c3 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 e51f4ee2dcd..546af69e88a 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 e98e63b752b..f6c6cc0ef03 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 32884cc938a..c565f51b195 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 e43adc69768..ec15d45472e 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 5c754e63340..11d8e7df3ec 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 f99c22b4990..ed03cdabc6e 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 47ac7a6997f..78cadce8ff1 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 19841f9dfe0..ad9fb202f93 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 23c73fb876b..719a522628a 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 bb13177586a..94a62ad0d94 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 02826e4e4f5..1727e66f4e8 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 4a1fd62ff40..4d8a4baee23 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 89c0cabae69..1ef7cc039ac 100644 --- a/frameworks/core/components/custom_paint/rosen_render_custom_paint.cpp +++ b/frameworks/core/components/custom_paint/rosen_render_custom_paint.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 "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" @@ -552,20 +552,20 @@ double RosenRenderCustomPaint::MeasureTextInner(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(); } @@ -573,20 +573,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(); } @@ -594,20 +594,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(); @@ -649,7 +649,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) { @@ -675,7 +675,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) { @@ -1252,61 +1252,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 { @@ -1314,7 +1312,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()); } @@ -1323,8 +1321,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 dce40418c1e..b464c7577f9 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" @@ -105,16 +106,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); @@ -140,7 +141,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_; @@ -174,4 +175,4 @@ private: } // namespace OHOS::Ace -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CUSTOM_PAINT_ROSEN_RENDER_CUSTOM_PAINT_H \ No newline at end of file +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CUSTOM_PAINT_ROSEN_RENDER_CUSTOM_PAINT_H 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 113671e7219..acffa631060 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 497ebdea89e..81dfa069e81 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 b84937bcfd0..0f4879d7078 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 NG_BUILD - 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 37dc06c5ab7..88977988f61 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 d4b38cfd721..6136dc87718 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 057f8965379..b5cc3086ca7 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 28ba9377365..5f18365357e 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 c1285aa8d0b..fa30009d0a9 100644 --- a/frameworks/core/components/font/rosen_font_collection.cpp +++ b/frameworks/core/components/font/rosen_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 { RosenFontCollection RosenFontCollection::instance; -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(); @@ -44,7 +46,7 @@ std::shared_ptr RosenFontCollection::GetFontCollection() return nullptr; } auto& fontCollection = windowClient->GetFontCollection(); - return fontCollection.GetFontCollection(); + return Rosen::FontCollection::From(fontCollection.GetFontCollection()); } flutter::WindowClient* RosenFontCollection::GetRosenEngineWindowClient() diff --git a/frameworks/core/components/font/rosen_font_collection.h b/frameworks/core/components/font/rosen_font_collection.h index 789a848fe80..5d3c20cb1c9 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 1ae5a9f7286..60838385072 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 9e3df1c788b..2c5650ee09f 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 7d6243686d4..240625b2afb 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 99791628706..e1850ab0d43 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 27bfed50159..495d5fcb00d 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 1e313dad7bc..2760aa2a6ba 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 ce63241b726..6cbd4506531 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 fc015cbf2a7..d306746cc09 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 f51c0b1786e..5b9a09fc610 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 dd9057263c8..108074cb52f 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::CoverTopAndBottom, 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::CoverTopAndBottom, 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::CoverTopAndBottom, 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::CoverTopAndBottom, 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::CoverTopAndBottom, Rosen::TextRectWidthStyle::Tight); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::CoverTopAndBottom, 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::CoverTopAndBottom, 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 aa95b29856b..11ab6796964 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/rosen_render_text_field.cpp b/frameworks/core/components/text_field/rosen_render_text_field.cpp index 0ed871f2b2b..08a282f41fb 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::CoverTopAndBottom, 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::CoverTopAndBottom, 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); } } @@ -781,7 +779,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. @@ -799,13 +797,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); } @@ -830,24 +828,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; @@ -867,13 +865,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; } @@ -882,33 +880,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; } @@ -923,23 +921,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::CoverTopAndBottom, 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; } @@ -959,18 +957,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::CoverTopAndBottom, 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::CoverTopAndBottom, Rosen::TextRectWidthStyle::Tight); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::CoverTopAndBottom, Rosen::TextRectWidthStyle::Tight); } if (boxes.empty()) { return false; @@ -982,22 +980,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; } @@ -1010,24 +1008,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::CoverTopAndBottom, 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; } @@ -1086,23 +1084,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(); } @@ -1126,8 +1124,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() @@ -1136,8 +1134,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) @@ -1153,7 +1151,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) @@ -1162,7 +1160,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 e6e7ec0b1ef..c383e9f71f0 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 caretRect_; Rect startCaretRect_; diff --git a/frameworks/core/components/text_overlay/text_overlay_manager.cpp b/frameworks/core/components/text_overlay/text_overlay_manager.cpp index 6f24b956585..daa0527998e 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::CoverTopAndBottom, 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::CoverTopAndBottom, 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::CoverTopAndBottom, Rosen::TextRectWidthStyle::Tight); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::CoverTopAndBottom, 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::CoverTopAndBottom, 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::CoverTopAndBottom, 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 155d59b085d..7395a604a8b 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; @@ -134,7 +134,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 60cb2b35037..0b6ede8372b 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 6fbfdc97149..7e1873193ef 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 17964ffb991..ce6b74563ef 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 6a3e3ba6e25..b61b907dfbc 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 9bb867344f8..366f43f7e73 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 e547bd5c460..50d29d371f7 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 7fca83de826..ec4b383c8d1 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/text/span_node.cpp b/frameworks/core/components_ng/pattern/text/span_node.cpp index edb79a0a312..0db816ffc6b 100644 --- a/frameworks/core/components_ng/pattern/text/span_node.cpp +++ b/frameworks/core/components_ng/pattern/text/span_node.cpp @@ -115,7 +115,7 @@ void SpanItem::UpdateParagraph(const RefPtr& builder) auto displayText = content; auto textCase = fontStyle ? fontStyle->GetTextCase().value_or(TextCase::NORMAL) : TextCase::NORMAL; StringUtils::TransformStrCase(displayText, static_cast(textCase)); - builder->AddText(StringUtils::Str8ToStr16(displayText)); + builder->AppendText(StringUtils::Str8ToStr16(displayText)); for (const auto& child : children) { if (child) { child->UpdateParagraph(builder); 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 2b47efd8dfd..2f8ec28a0f1 100644 --- a/frameworks/core/components_ng/pattern/text/text_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/text/text_layout_algorithm.cpp @@ -140,13 +140,13 @@ bool TextLayoutAlgorithm::CreateParagraph(const TextStyle& textStyle, std::strin .fontLocale = Localization::GetInstance()->GetFontLocale(), .wordBreak = textStyle.GetWordBreak(), .textOverflow = textStyle.GetTextOverflow() }; - paragraph_ = Paragraph::Create(paraStyle, FontCollection::Current()); - CHECK_NULL_RETURN(paragraph_, false); - paragraph_->PushStyle(textStyle); + + auto builder = RSParagraphBuilder::Create(paraStyle, RSFontCollection::Create()); + builder->PushStyle(ToRSTextStyle(PipelineContext::GetCurrentContext(), textStyle)); if (spanItemChildren_.empty()) { StringUtils::TransformStrCase(content, static_cast(textStyle.GetTextCase())); - paragraph_->AddText(StringUtils::Str8ToStr16(content)); + builder->AppendText(StringUtils::Str8ToStr16(content)); } else { for (const auto& child : spanItemChildren_) { if (child) { @@ -154,7 +154,10 @@ bool TextLayoutAlgorithm::CreateParagraph(const TextStyle& textStyle, std::strin } } } - paragraph_->Build(); + builder->PopStyle(); + + auto paragraph = builder->CreateTypography(); + paragraph_.reset(paragraph.release()); return true; } @@ -214,8 +217,9 @@ bool TextLayoutAlgorithm::DidExceedMaxLines(const SizeF& maxSize) { CHECK_NULL_RETURN(paragraph_, false); bool didExceedMaxLines = paragraph_->DidExceedMaxLines(); - didExceedMaxLines = didExceedMaxLines || GreatNotEqual(paragraph_->GetHeight(), maxSize.Height()); - didExceedMaxLines = didExceedMaxLines || GreatNotEqual(paragraph_->GetLongestLine(), maxSize.Width()); + didExceedMaxLines = didExceedMaxLines || GreatNotEqual(paragraph_->GetHeight(), contentConstraint.maxSize.Height()); + didExceedMaxLines = + didExceedMaxLines || GreatNotEqual(paragraph_->GetActualWidth(), contentConstraint.maxSize.Width()); return didExceedMaxLines; } @@ -239,7 +243,7 @@ float TextLayoutAlgorithm::GetTextWidth() const { CHECK_NULL_RETURN(paragraph_, 0.0); // TODO: need check Line count - return paragraph_->GetMaxIntrinsicWidth(); + return paragraph_->GetActualWidth(); } const RefPtr& TextLayoutAlgorithm::GetParagraph() 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 9cdd9d2aca3..80b720ae1d3 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp @@ -106,12 +106,12 @@ void SwitchPaintMethod::PaintContent( brush.SetAntiAlias(true); canvas.AttachBrush(brush); - RSRect rect; + Rosen::Drawing::Rect rect; rect.SetLeft(xOffset); rect.SetTop(yOffset); rect.SetRight(xOffset + width); rect.SetBottom(yOffset + height); - RSRoundRect roundRect(rect, radius, radius); + Rosen::Drawing::RoundRect roundRect(rect, radius, radius); canvas.DrawRoundRect(roundRect); auto innerRadius = pointRadius_ + actualGap * mainDelta_ / GetSwitchWidth(contentSize); @@ -124,21 +124,19 @@ void SwitchPaintMethod::PaintContent( } brush.SetAntiAlias(true); canvas.AttachBrush(brush); - RSRect rectCover; - float moveRitio = mainDelta_ / GetSwitchWidth(contentSize); - rectCover.SetLeft(xOffset + actualGap * (1 - moveRitio)); - rectCover.SetTop(yOffset + actualGap * (1 - moveRitio)); - rectCover.SetRight(xOffset + mainDelta_ + 2 * pointRadius_ + actualGap * (1 + moveRitio)); - rectCover.SetBottom(yOffset + height - actualGap * (1 - moveRitio)); - RSRoundRect roundRectCover(rectCover, innerRadius, innerRadius); + Rosen::Drawing::Rect rectCover; + rectCover.SetLeft(xOffset); + rectCover.SetTop(yOffset); + rectCover.SetRight(xOffset + mainDelta_ + height - radiusGap_); + rectCover.SetBottom(yOffset + height); + Rosen::Drawing::RoundRect roundRectCover(rectCover, radius, radius); canvas.DrawRoundRect(roundRectCover); } brush.SetColor(ToRSColor(paintProperty->GetSwitchPointColor().value_or(switchTheme->GetPointColor()))); brush.SetAntiAlias(true); canvas.AttachBrush(brush); - - RSPoint point; - point.SetX(xOffset + actualGap + pointRadius_ + mainDelta_); + Rosen::Drawing::Point point; + point.SetX(xOffset + borderWidth_ + hoverRadius_ + mainDelta_); point.SetY(yOffset + radius); canvas.DrawCircle(point, pointRadius_); } @@ -181,4 +179,4 @@ float SwitchPaintMethod::GetSwitchWidth(const SizeF& contentSize) const return switchWidth; } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG 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 149a0fd89c4..f07652ed1f7 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 20ced5dafae..a0ffa923050 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 202716605cb..52c297ee894 100644 --- a/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp +++ b/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp @@ -40,19 +40,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; } #ifndef NG_BUILD // 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) @@ -61,15 +61,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) @@ -77,13 +77,14 @@ void TxtParagraph::AddText(const std::u16string& text) if (!builder_) { CreateBuilder(); } - 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() @@ -109,9 +110,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() @@ -146,9 +147,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) diff --git a/frameworks/core/components_ng/render/adapter/txt_paragraph.h b/frameworks/core/components_ng/render/adapter/txt_paragraph.h index 9d52c95eb9a..60cbd2a18a3 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; @@ -63,9 +62,9 @@ public: private: void CreateBuilder(); 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_; 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 805bcad904a..48d70a1b153 100644 --- a/frameworks/core/components_ng/render/drawing.h +++ b/frameworks/core/components_ng/render/drawing.h @@ -20,9 +20,9 @@ #include "draw/canvas.h" #include "drawing/engine_adapter/skia_adapter/skia_canvas.h" #include "image/image.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/scalar.h" @@ -56,21 +56,14 @@ 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 RSPathEffect = Rosen::Drawing::PathEffect; +using RSPathDirection = Rosen::Drawing::PathDirection; +using RSPathDashStyle = Rosen::Drawing::PathDashStyle; +using RSParagraph = Rosen::Typography; +using RSParagraphBuilder = Rosen::TypographyCreate; +using RSFontCollection = Rosen::FontCollection; +using RSParagraphStyle = Rosen::TypographyStyle; +using RSTextStyle = Rosen::TextStyle; } // 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 597a69a866b..70cc9ee7098 100644 --- a/frameworks/core/components_ng/render/drawing_prop_convertor.cpp +++ b/frameworks/core/components_ng/render/drawing_prop_convertor.cpp @@ -57,26 +57,26 @@ RSPen::CapStyle ToRSCapStyle(const LineCap& lineCap) return capStyle; } -rosen::TextDirection ToRSTextDirection(const TextDirection& txtDir) +Rosen::TextDirection ToRSTextDirection(const TextDirection& txtDir) { - rosen::TextDirection rsTxtDir = rosen::TextDirection::LTR; + Rosen::TextDirection rsTxtDir = Rosen::TextDirection::LTR; if (txtDir == TextDirection::LTR) { - rsTxtDir = rosen::TextDirection::LTR; + rsTxtDir = Rosen::TextDirection::LTR; } else if (txtDir == TextDirection::RTL) { - rsTxtDir = rosen::TextDirection::RTL; + rsTxtDir = Rosen::TextDirection::RTL; } return rsTxtDir; } -rosen::TextAlign ToRSTextAlign(const TextAlign& align) +Rosen::TextAlign ToRSTextAlign(const TextAlign& align) { // should keep enum same with rosen. - return static_cast(align); + return static_cast(align); } -rosen::FontWeight ToRSFontWeight(FontWeight fontWeight) +Rosen::FontWeight ToRSFontWeight(FontWeight fontWeight) { - rosen::FontWeight rsFontWeight = rosen::FontWeight::W400; + Rosen::FontWeight rsFontWeight = Rosen::FontWeight::W400; switch (fontWeight) { case FontWeight::W100: case FontWeight::LIGHTER: @@ -118,15 +118,15 @@ rosen::FontWeight ToRSFontWeight(FontWeight fontWeight) return rsFontWeight; } -rosen::WordBreakType ToRSWordBreakType(const WordBreak& wordBreak) +Rosen::WordBreakType ToRSWordBreakType(const WordBreak& wordBreak) { // should keep enum same with rosen. - return static_cast(wordBreak); + return static_cast(wordBreak); } -rosen::TextDecoration ToRSTextDecoration(TextDecoration textDecoration) +Rosen::TextDecoration ToRSTextDecoration(TextDecoration textDecoration) { - rosen::TextDecoration rsTextDecoration = rosen::TextDecoration::NONE; + Rosen::TextDecoration rsTextDecoration = Rosen::TextDecoration::NONE; switch (textDecoration) { case TextDecoration::OVERLINE: rsTextDecoration = rosen::TextDecoration::OVERLINE; @@ -144,18 +144,17 @@ rosen::TextDecoration ToRSTextDecoration(TextDecoration textDecoration) return rsTextDecoration; } -rosen::TextStyle ToRSTextStyle(const RefPtr& context, const TextStyle& textStyle) +Rosen::TextStyle ToRSTextStyle(const RefPtr& context, const TextStyle& textStyle) { - rosen::TextStyle rsTextStyle; + Rosen::TextStyle rsTextStyle; 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 (context) { rsTextStyle.fontSize_ = context->NormalizeToPx(textStyle.GetFontSize()); @@ -179,24 +178,24 @@ rosen::TextStyle ToRSTextStyle(const RefPtr& context, const TextSt } 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/drawing_prop_convertor.h b/frameworks/core/components_ng/render/drawing_prop_convertor.h index 6e80853291b..07041bf3827 100644 --- a/frameworks/core/components_ng/render/drawing_prop_convertor.h +++ b/frameworks/core/components_ng/render/drawing_prop_convertor.h @@ -30,9 +30,9 @@ RSColor ToRSColor(const Color& color); RSColor ToRSColor(const LinearColor& color); RSRect ToRSRect(const NG::RectF& rect); RSPen::CapStyle ToRSCapStyle(const LineCap& lineCap); -RSTextDirection ToRSTextDirection(const TextDirection& txtDir); -RSTextAlign ToRSTextAlign(const TextAlign& align); -RSWordBreakType ToRSWordBreakType(const WordBreak& wordBreak); -RSTextStyle ToRSTextStyle(const RefPtr& context, const TextStyle& textStyle); +Rosen::TextDirection ToRSTextDirection(const TextDirection& txtDir); +Rosen::TextAlign ToRSTextAlign(const TextAlign& align); +Rosen::WordBreakType ToRSWordBreakType(const WordBreak& wordBreak); +Rosen::TextStyle ToRSTextStyle(const RefPtr& context, const TextStyle& textStyle); } // namespace OHOS::Ace #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_DRAWING_PROP_CONVERTOR_H -- Gitee From 8778995fd776e248195c8a5df8894a04057770a1 Mon Sep 17 00:00:00 2001 From: "xueyu.li" Date: Thu, 22 Dec 2022 10:32:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=9C=A84937=E5=9F=BA=E7=A1=80=E4=B8=8A?= =?UTF-8?q?=EF=BC=8C=E4=B8=BAtexgine=E9=80=82=E9=85=8D=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E5=9F=BA=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I29cd37502ba9b2ab7137cdaa7dc65e61836f801b --- adapter/ohos/entrance/hap_asset_provider.cpp | 4 +- adapter/ohos/entrance/utils.cpp | 8 +- .../js_frontend/engine/jsi/ark_js_runtime.cpp | 2 +- .../rosen_render_custom_paint.cpp | 20 +-- .../on_text_changed_listener_impl.cpp | 45 +---- .../on_text_changed_listener_impl.h | 3 - .../text_field/render_text_field.cpp | 6 +- .../calendar/calendar_paint_method.cpp | 37 ++-- .../pattern/calendar/calendar_paint_method.h | 8 +- .../custom_paint/canvas_paint_method.cpp | 97 +++++----- .../custom_paint/canvas_paint_method.h | 6 +- .../custom_paint/custom_paint_paint_method.h | 5 +- .../offscreen_canvas_paint_method.cpp | 113 ++++++------ .../offscreen_canvas_paint_method.h | 6 +- .../linear_split_paint_method.cpp | 6 +- .../swiper_indicator_paint_method.cpp | 2 +- .../components_ng/pattern/text/span_node.cpp | 6 +- .../components_ng/pattern/text/span_node.h | 2 +- .../pattern/text/text_layout_algorithm.cpp | 32 ++-- .../pattern/text/text_layout_algorithm.h | 13 +- .../pattern/text/text_paint_method.h | 6 +- .../pattern/text/text_pattern.cpp | 2 +- .../components_ng/pattern/text/text_pattern.h | 4 +- .../on_text_changed_listener_impl.cpp | 44 +---- .../on_text_changed_listener_impl.h | 3 - .../text_field_layout_algorithm.cpp | 16 +- .../pattern/text_field/text_field_pattern.cpp | 34 ++-- .../pattern/text_field/text_field_pattern.h | 8 +- .../pattern/toggle/switch_paint_method.cpp | 28 +-- .../pattern/toggle/switch_paint_method.h | 4 +- .../pattern/toggle/switch_pattern.cpp | 2 +- .../pattern/toggle/switch_pattern.h | 2 +- .../render/adapter/focus_state_modifier.h | 12 +- .../render/adapter/overlay_modifier.h | 12 +- .../render/adapter/txt_paragraph.cpp | 12 +- .../render/adapter/txt_paragraph.h | 1 + .../core/components_ng/render/drawing.h | 5 +- .../render/drawing_prop_convertor.cpp | 28 +-- .../core/components_ng/render/paragraph.h | 2 +- .../drag_drop/drag_drop_manager/BUILD.gn | 2 +- .../drag_drop/drag_drop_proxy/BUILD.gn | 2 +- .../select_overlay_manager/BUILD.gn | 2 +- .../select_overlay_proxy/BUILD.gn | 2 +- .../test/pattern/ability_component/BUILD.gn | 2 +- .../test/pattern/image_animator/BUILD.gn | 2 +- .../test/pattern/option/BUILD.gn | 2 +- .../test/render/adapter/BUILD.gn | 169 ++++++++++++++++++ 47 files changed, 449 insertions(+), 380 deletions(-) create mode 100644 frameworks/core/components_ng/test/render/adapter/BUILD.gn diff --git a/adapter/ohos/entrance/hap_asset_provider.cpp b/adapter/ohos/entrance/hap_asset_provider.cpp index 74e0379680e..ca5788490dc 100644 --- a/adapter/ohos/entrance/hap_asset_provider.cpp +++ b/adapter/ohos/entrance/hap_asset_provider.cpp @@ -29,9 +29,7 @@ bool HapAssetProvider::Initialize(const std::string& hapPath, const std::vector< return false; } - bool newCreate = false; - std::string loadPath = AbilityBase::ExtractorUtil::GetLoadFilePath(hapPath); - runtimeExtractor_ = AbilityBase::ExtractorUtil::GetExtractor(loadPath, newCreate); + runtimeExtractor_ = AbilityBase::Extractor::Create(hapPath); CHECK_NULL_RETURN_NOLOG(runtimeExtractor_, false); assetBasePaths_ = assetBasePaths; hapPath_ = hapPath; diff --git a/adapter/ohos/entrance/utils.cpp b/adapter/ohos/entrance/utils.cpp index c084a04acc2..98910eeb016 100644 --- a/adapter/ohos/entrance/utils.cpp +++ b/adapter/ohos/entrance/utils.cpp @@ -65,16 +65,14 @@ std::string GetStringFromFile(const std::string& packagePathStr, const std::stri std::string GetStringFromHap(const std::string& hapPath, const std::string& fileName) { - bool newCreate = false; - std::string loadPath = AbilityBase::ExtractorUtil::GetLoadFilePath(hapPath); - std::shared_ptr extractor = AbilityBase::ExtractorUtil::GetExtractor(loadPath, newCreate); - if (!extractor) { + std::shared_ptr runtimeExtractor = AbilityBase::Extractor::Create(hapPath); + if (!runtimeExtractor) { LOGE("read file %{public}s error\n", hapPath.c_str()); return ""; } std::ostringstream osstream; - bool hasFile = extractor->GetFileBuffer(fileName, osstream); + bool hasFile = runtimeExtractor->GetFileBuffer(fileName, osstream); if (!hasFile) { LOGE("read file %{public}s /config.json error\n", hapPath.c_str()); return ""; 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 f5cce838366..af76dbe21f6 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp @@ -131,7 +131,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/components/custom_paint/rosen_render_custom_paint.cpp b/frameworks/core/components/custom_paint/rosen_render_custom_paint.cpp index 1ef7cc039ac..5069f3f22ff 100644 --- a/frameworks/core/components/custom_paint/rosen_render_custom_paint.cpp +++ b/frameworks/core/components/custom_paint/rosen_render_custom_paint.cpp @@ -522,26 +522,26 @@ 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; - txtStyle.font_size = context.fontSize; + txtStyle.fontSize_ = context.fontSize; FontStyle fontStyleInt = OHOS::Ace::Framework::ConvertStrToFontStyle(std::to_string(context.fontStyle)); - txtStyle.font_style = ConvertTxtFontStyle(fontStyleInt); + txtStyle.fontStyle_ = ConvertTxtFontStyle(fontStyleInt); 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.letter_spacing = context.letterSpacing; + txtStyle.fontFamilies_ = fontFamilies; + txtStyle.letterSpacing_ = context.letterSpacing; 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; } diff --git a/frameworks/core/components/text_field/on_text_changed_listener_impl.cpp b/frameworks/core/components/text_field/on_text_changed_listener_impl.cpp index c0a08056ac0..58e0e90511f 100644 --- a/frameworks/core/components/text_field/on_text_changed_listener_impl.cpp +++ b/frameworks/core/components/text_field/on_text_changed_listener_impl.cpp @@ -182,48 +182,6 @@ void OnTextChangedListenerImpl::MoveCursor(MiscServices::Direction direction) PostTaskToUI(task); } -void OnTextChangedListenerImpl::HandleSetSelection(int32_t start, int32_t end) -{ - auto task = [textField = field_, start, end] { - auto client = textField.Upgrade(); - if (!client) { - LOGE("text field is null"); - return; - } - ContainerScope scope(client->instanceId_); - client->HandleSetSelection(start, end); - }; - PostTaskToUI(task); -} - -void OnTextChangedListenerImpl::HandleExtendAction(int32_t action) -{ - auto task = [textField = field_, action] { - auto client = textField.Upgrade(); - if (!client) { - LOGE("text field is null"); - return; - } - ContainerScope scope(client->instanceId_); - client->HandleExtendAction(action); - }; - PostTaskToUI(task); -} - -void OnTextChangedListenerImpl::HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) -{ - auto task = [textField = field_, keyCode, cursorMoveSkip] { - auto client = textField.Upgrade(); - if (!client) { - LOGE("text field is null"); - return; - } - ContainerScope scope(client->instanceId_); - client->HandleSelect(keyCode, cursorMoveSkip); - }; - PostTaskToUI(task); -} - void OnTextChangedListenerImpl::PostTaskToUI(const std::function& task) { if (!task) { @@ -245,4 +203,5 @@ void OnTextChangedListenerImpl::PostTaskToUI(const std::function& task) taskExecutor->PostTask(task, TaskExecutor::TaskType::UI); } -} // namespace OHOS::Ace + +} // namespace OHOS::Acer diff --git a/frameworks/core/components/text_field/on_text_changed_listener_impl.h b/frameworks/core/components/text_field/on_text_changed_listener_impl.h index 8af6cc5ac68..31f8990f485 100644 --- a/frameworks/core/components/text_field/on_text_changed_listener_impl.h +++ b/frameworks/core/components/text_field/on_text_changed_listener_impl.h @@ -35,9 +35,6 @@ public: void SendKeyEventFromInputMethod(const MiscServices::KeyEvent& event) override; void SendKeyboardInfo(const MiscServices::KeyboardInfo& info) override; void MoveCursor(MiscServices::Direction direction) override; - void HandleSetSelection(int32_t start, int32_t end) override; - void HandleExtendAction(int32_t action) override; - void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override; private: void PostTaskToUI(const std::function& task); diff --git a/frameworks/core/components/text_field/render_text_field.cpp b/frameworks/core/components/text_field/render_text_field.cpp index accd93643d3..c0a52a1e018 100644 --- a/frameworks/core/components/text_field/render_text_field.cpp +++ b/frameworks/core/components/text_field/render_text_field.cpp @@ -1076,7 +1076,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_); } @@ -1090,10 +1089,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_ng/pattern/calendar/calendar_paint_method.cpp b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp index c5c5f58d9c5..326e8e11035 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 cb305a6b391..0001302f2a1 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 05a5f6a5fc5..8b0b8fa933b 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 5f847b50655..dd41fdfd2cd 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 402e91cbcfa..676fd9cac84 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" @@ -293,7 +294,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 0075b4a2a35..2de9b9a4209 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 1fee5daa16e..6fb4d377887 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 ae54f95e456..ffda8e1f07e 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 @@ -59,7 +59,7 @@ void LinearSplitPaintMethod::PaintContent(RSCanvas& canvas) float startPointY = childOffset.GetY(); float endPointX = startPointX; float endPointY = startPointY + splitLength_; - canvas.DrawLine(rosen::Point(startPointX, startPointY), rosen::Point(endPointX, endPointY)); + canvas.DrawLine(Rosen::Drawing::Point(startPointX, startPointY), Rosen::Drawing::Point(endPointX, endPointY)); } } else if (splitType_ == SplitType::COLUMN_SPLIT) { for (auto childOffset : childrenOffset_) { @@ -67,9 +67,9 @@ void LinearSplitPaintMethod::PaintContent(RSCanvas& canvas) float startPointX = childOffset.GetX(); float endPointX = startPointX + splitLength_; float endPointY = startPointY; - canvas.DrawLine(rosen::Point(startPointX, startPointY), rosen::Point(endPointX, endPointY)); + canvas.DrawLine(Rosen::Drawing::Point(startPointX, startPointY), Rosen::Drawing::Point(endPointX, endPointY)); } } } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/swiper_indicator/swiper_indicator_paint_method.cpp b/frameworks/core/components_ng/pattern/swiper_indicator/swiper_indicator_paint_method.cpp index 43b85c305eb..ef3bb1cee30 100644 --- a/frameworks/core/components_ng/pattern/swiper_indicator/swiper_indicator_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/swiper_indicator/swiper_indicator_paint_method.cpp @@ -136,7 +136,7 @@ void SwiperIndicatorPaintMethod::PaintContent( RSBrush brush; brush.SetColor(ToRSColor(paintProperty->GetColor().value_or(swiperTheme->GetColor()))); canvas.AttachBrush(brush); - rosen::Point point; + Rosen::Drawing::Point point; if (axis_ == Axis::HORIZONTAL) { point.SetX(center.GetX()); point.SetY(center.GetY()); diff --git a/frameworks/core/components_ng/pattern/text/span_node.cpp b/frameworks/core/components_ng/pattern/text/span_node.cpp index 0db816ffc6b..ad74e34d356 100644 --- a/frameworks/core/components_ng/pattern/text/span_node.cpp +++ b/frameworks/core/components_ng/pattern/text/span_node.cpp @@ -103,14 +103,14 @@ void SpanNode::RequestTextFlushDirty() LOGE("fail to find Text or Parent Span"); } -void SpanItem::UpdateParagraph(const RefPtr& builder) +void SpanItem::UpdateParagraph(RSParagraphBuilder* builder) { CHECK_NULL_VOID(builder); if (fontStyle) { auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); TextStyle textStyle = CreateTextStyleUsingTheme(fontStyle, nullptr, pipelineContext->GetTheme()); - builder->PushStyle(textStyle); + builder->PushStyle(ToRSTextStyle(PipelineContext::GetCurrentContext(), textStyle)); } auto displayText = content; auto textCase = fontStyle ? fontStyle->GetTextCase().value_or(TextCase::NORMAL) : TextCase::NORMAL; @@ -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/span_node.h b/frameworks/core/components_ng/pattern/text/span_node.h index db049d25195..2df33d8986d 100644 --- a/frameworks/core/components_ng/pattern/text/span_node.h +++ b/frameworks/core/components_ng/pattern/text/span_node.h @@ -71,7 +71,7 @@ struct SpanItem : public Referenced { GestureEventFunc onClick; std::list> children; - void UpdateParagraph(const RefPtr& builder); + void UpdateParagraph(RSParagraphBuilder* builder); void ToJsonValue(std::unique_ptr& json) const; }; 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 2f8ec28a0f1..01bf9ed555e 100644 --- a/frameworks/core/components_ng/pattern/text/text_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/text/text_layout_algorithm.cpp @@ -98,13 +98,6 @@ std::optional TextLayoutAlgorithm::MeasureContent( } } - double paragraphNewWidth = std::min(GetTextWidth(), paragraph_->GetMaxWidth()); - if (!contentConstraint.selfIdealSize.Width()) { - paragraphNewWidth = std::clamp(GetTextWidth(), 0.0f, contentConstraint.maxSize.Width()); - } - if (!NearEqual(paragraphNewWidth, paragraph_->GetMaxWidth())) { - paragraph_->Layout(std::ceil(paragraphNewWidth)); - } } auto height = static_cast(paragraph_->GetHeight()); @@ -134,12 +127,14 @@ void TextLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) bool TextLayoutAlgorithm::CreateParagraph(const TextStyle& textStyle, std::string content) { - ParagraphStyle paraStyle = { .direction = GetTextDirection(content), - .align = textStyle.GetTextAlign(), - .maxLines = textStyle.GetMaxLines(), - .fontLocale = Localization::GetInstance()->GetFontLocale(), - .wordBreak = textStyle.GetWordBreak(), - .textOverflow = textStyle.GetTextOverflow() }; + RSParagraphStyle paraStyle = {.textAlign_ = ToRSTextAlign(textStyle.GetTextAlign()), + .textDirection_ = ToRSTextDirection(GetTextDirection(content)), + .maxLines_ = textStyle.GetMaxLines(), + .locale_ = Localization::GetInstance()->GetFontLocale(), + .wordBreakType_ = ToRSWordBreakType(textStyle.GetWordBreak()),}; + if (textStyle.GetTextOverflow() == TextOverflow::ELLIPSIS) { + paraStyle.ellipsis_ = RSParagraphStyle::ELLIPSIS; + } auto builder = RSParagraphBuilder::Create(paraStyle, RSFontCollection::Create()); builder->PushStyle(ToRSTextStyle(PipelineContext::GetCurrentContext(), textStyle)); @@ -150,7 +145,7 @@ bool TextLayoutAlgorithm::CreateParagraph(const TextStyle& textStyle, std::strin } else { for (const auto& child : spanItemChildren_) { if (child) { - child->UpdateParagraph(paragraph_); + child->UpdateParagraph(builder.get()); } } } @@ -199,13 +194,12 @@ bool TextLayoutAlgorithm::AdaptMinTextSize(TextStyle& textStyle, const std::stri contentConstraint.maxSize.Height(), stepSize)) { return false; } - auto maxSize = GetMaxMeasureSize(contentConstraint); while (GreatOrEqual(maxFontSize, minFontSize)) { textStyle.SetFontSize(Dimension(maxFontSize)); if (!CreateParagraphAndLayout(textStyle, content, contentConstraint)) { return false; } - if (!DidExceedMaxLines(maxSize)) { + if (!DidExceedMaxLines(contentConstraint)) { break; } maxFontSize -= stepSize; @@ -213,7 +207,7 @@ bool TextLayoutAlgorithm::AdaptMinTextSize(TextStyle& textStyle, const std::stri return true; } -bool TextLayoutAlgorithm::DidExceedMaxLines(const SizeF& maxSize) +bool TextLayoutAlgorithm::DidExceedMaxLines(const LayoutConstraintF& contentConstraint) { CHECK_NULL_RETURN(paragraph_, false); bool didExceedMaxLines = paragraph_->DidExceedMaxLines(); @@ -239,14 +233,14 @@ TextDirection TextLayoutAlgorithm::GetTextDirection(const std::string& content) return textDirection; } -float TextLayoutAlgorithm::GetTextWidth() const +double TextLayoutAlgorithm::GetTextWidth() const { CHECK_NULL_RETURN(paragraph_, 0.0); // TODO: need check Line count return paragraph_->GetActualWidth(); } -const RefPtr& TextLayoutAlgorithm::GetParagraph() +const std::shared_ptr& TextLayoutAlgorithm::GetParagraph() { return paragraph_; } 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 5733bd94ff0..8dfb6be398a 100644 --- a/frameworks/core/components_ng/pattern/text/text_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/text/text_layout_algorithm.h @@ -23,6 +23,7 @@ #include "core/components_ng/layout/layout_wrapper.h" #include "core/components_ng/pattern/text/span_node.h" #include "core/components_ng/pattern/text/text_styles.h" +#include "core/components_ng/render/drawing.h" #include "core/components_ng/render/paragraph.h" namespace OHOS::Ace::NG { @@ -35,8 +36,8 @@ class ACE_EXPORT TextLayoutAlgorithm : public BoxLayoutAlgorithm { public: TextLayoutAlgorithm(); - TextLayoutAlgorithm(std::list> spanItemChildren, const RefPtr& paragraph) - : spanItemChildren_(std::move(spanItemChildren)), paragraph_(paragraph) + explicit TextLayoutAlgorithm(std::list> spanItemChildren) + : spanItemChildren_(std::move(spanItemChildren)) {} ~TextLayoutAlgorithm() override = default; @@ -48,7 +49,7 @@ public: std::optional MeasureContent( const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) override; - const RefPtr& GetParagraph(); + const std::shared_ptr& GetParagraph(); float GetBaselineOffset() const; private: @@ -57,13 +58,13 @@ private: const TextStyle& textStyle, const std::string& content, const LayoutConstraintF& contentConstraint); bool AdaptMinTextSize(TextStyle& textStyle, const std::string& content, const LayoutConstraintF& contentConstraint, const RefPtr& pipeline); - bool DidExceedMaxLines(const SizeF& maxSize); + bool DidExceedMaxLines(const LayoutConstraintF& contentConstraint); static TextDirection GetTextDirection(const std::string& content); - float GetTextWidth() const; + double GetTextWidth() const; SizeF GetMaxMeasureSize(const LayoutConstraintF& contentConstraint) const; std::list> spanItemChildren_; - RefPtr paragraph_; + std::shared_ptr paragraph_; float baselineOffset_ = 0.0f; ACE_DISALLOW_COPY_AND_MOVE(TextLayoutAlgorithm); diff --git a/frameworks/core/components_ng/pattern/text/text_paint_method.h b/frameworks/core/components_ng/pattern/text/text_paint_method.h index 5793972bd13..21730f9942f 100644 --- a/frameworks/core/components_ng/pattern/text/text_paint_method.h +++ b/frameworks/core/components_ng/pattern/text/text_paint_method.h @@ -29,7 +29,7 @@ namespace OHOS::Ace::NG { class ACE_EXPORT TextPaintMethod : public NodePaintMethod { DECLARE_ACE_TYPE(TextPaintMethod, NodePaintMethod) public: - TextPaintMethod(RefPtr paragraph, float baselineOffset) + TextPaintMethod(std::shared_ptr paragraph, float baselineOffset) : paragraph_(std::move(paragraph)), baselineOffset_(baselineOffset) {} ~TextPaintMethod() override = default; @@ -40,12 +40,12 @@ public: auto offset = paintWrapper->GetContentOffset(); auto paintOffset = offset - OffsetF(0.0, baselineOffset_); return [paragraph = paragraph_, paintOffset](RSCanvas& canvas) { - paragraph->Paint(canvas, paintOffset.GetX(), paintOffset.GetY()); + paragraph->Paint(&canvas, paintOffset.GetX(), paintOffset.GetY()); }; } private: - RefPtr paragraph_; + std::shared_ptr paragraph_; float baselineOffset_; ACE_DISALLOW_COPY_AND_MOVE(TextPaintMethod); diff --git a/frameworks/core/components_ng/pattern/text/text_pattern.cpp b/frameworks/core/components_ng/pattern/text/text_pattern.cpp index 9d172bfd95a..f46c238b7a3 100644 --- a/frameworks/core/components_ng/pattern/text/text_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text/text_pattern.cpp @@ -155,7 +155,7 @@ void TextPattern::OnModifyDone() if (CheckNeedMeasure(textLayoutProperty->GetPropertyChangeFlag())) { // measure flag changed, reset paragraph. - paragraph_.Reset(); + paragraph_.reset(); } bool shouldClipToContent = textLayoutProperty->GetTextOverflow().value_or(TextOverflow::NONE) == TextOverflow::CLIP; diff --git a/frameworks/core/components_ng/pattern/text/text_pattern.h b/frameworks/core/components_ng/pattern/text/text_pattern.h index fe09479b370..e55636c8c11 100644 --- a/frameworks/core/components_ng/pattern/text/text_pattern.h +++ b/frameworks/core/components_ng/pattern/text/text_pattern.h @@ -53,7 +53,7 @@ public: RefPtr CreateLayoutAlgorithm() override { - return MakeRefPtr(spanItemChildren_, paragraph_); + return MakeRefPtr(spanItemChildren_); } RefPtr CreateAccessibilityProperty() override @@ -96,7 +96,7 @@ private: void ShowSelectOverlay(const RectF& firstHandle, const RectF& secondHandle); std::list> spanItemChildren_; - RefPtr paragraph_; + std::shared_ptr paragraph_; RefPtr longPressEvent_; RefPtr selectOverlayProxy_; diff --git a/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.cpp b/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.cpp index 48e0f0dc371..25499ffbfe9 100644 --- a/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.cpp +++ b/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.cpp @@ -140,48 +140,6 @@ void OnTextChangedListenerImpl::MoveCursor(MiscServices::Direction direction) PostTaskToUI(task); } -void OnTextChangedListenerImpl::HandleSetSelection(int32_t start, int32_t end) -{ - auto task = [textField = pattern_, start, end] { - auto client = textField.Upgrade(); - if (!client) { - LOGE("text field is null"); - return; - } - ContainerScope scope(client->GetInstanceId()); - client->HandleSetSelection(start, end); - }; - PostTaskToUI(task); -} - -void OnTextChangedListenerImpl::HandleExtendAction(int32_t action) -{ - auto task = [textField = pattern_, action] { - auto client = textField.Upgrade(); - if (!client) { - LOGE("text field is null"); - return; - } - ContainerScope scope(client->GetInstanceId()); - client->HandleExtendAction(action); - }; - PostTaskToUI(task); -} - -void OnTextChangedListenerImpl::HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) -{ - auto task = [textField = pattern_, keyCode, cursorMoveSkip] { - auto client = textField.Upgrade(); - if (!client) { - LOGE("text field is null"); - return; - } - ContainerScope scope(client->GetInstanceId()); - client->HandleSelect(keyCode, cursorMoveSkip); - }; - PostTaskToUI(task); -} - void OnTextChangedListenerImpl::PostTaskToUI(const std::function& task) { CHECK_NULL_VOID(task); @@ -200,4 +158,4 @@ void OnTextChangedListenerImpl::PostTaskToUI(const std::function& task) taskExecutor->PostTask(task, TaskExecutor::TaskType::UI); } -} // namespace OHOS::Ace::NG +} // namespace OHOS::Ace::NG_ diff --git a/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.h b/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.h index 6038cf6302d..8116b3e10e2 100644 --- a/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.h +++ b/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.h @@ -34,9 +34,6 @@ public: void SendKeyEventFromInputMethod(const MiscServices::KeyEvent& event) override; void SendKeyboardInfo(const MiscServices::KeyboardInfo& info) override; void MoveCursor(MiscServices::Direction direction) override; - void HandleSetSelection(int32_t start, int32_t end) override; - void HandleExtendAction(int32_t action) override; - void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override; private: void PostTaskToUI(const std::function& task); 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 01426dd8308..15172e1c391 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 @@ -111,7 +111,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_.SetSize(SizeF()); return SizeF(contentConstraint.maxSize.Width() - horizontalPaddingSum, preferredHeight); } @@ -124,7 +124,7 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( if (textStyle.GetMaxLines() > 1 || pattern->IsTextArea()) { // for textArea, need to delete imageWidth and remeasure. paragraph_->Layout(contentConstraint.maxSize.Width() - 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(contentConstraint.maxSize.Width(), imageSize); } @@ -135,7 +135,7 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( pattern->GetShowPasswordIconCtx()->MakeCanvasImage(imageRect_.GetSize(), true, ImageFit::NONE); } preferredHeight = std::min(static_cast(paragraph_->GetHeight()), contentConstraint.maxSize.Height()); - textRect_.SetSize(SizeF(static_cast(paragraph_->GetLongestLine()), static_cast(preferredHeight))); + textRect_.SetSize(SizeF(static_cast(paragraph_->GetActualWidth()), static_cast(preferredHeight))); return SizeF(contentConstraint.maxSize.Width() - horizontalPaddingSum - imageSize, std::min(contentConstraint.maxSize.Height() - pattern->GetVerticalPaddingSum(), preferredHeight)); } @@ -260,17 +260,17 @@ void TextFieldLayoutAlgorithm::CreateParagraph(const TextStyle& textStyle, std:: if (textStyle.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(), textStyle)); StringUtils::TransformStrCase(content, static_cast(textStyle.GetTextCase())); if (!content.empty() && needObscureText) { - builder->AddText(TextFieldPattern::CreateObscuredText(static_cast(content.length()))); + builder->AppendText(TextFieldPattern::CreateObscuredText(static_cast(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 f7beb73846b..870cd09130a 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 @@ -590,10 +590,10 @@ 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) { - textBoxes = paragraph_->GetRectsForRange( - base, destination, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + textBoxes = paragraph_->GetTextRectsByBoundary( + base, destination, Rosen::TextRectHeightStyle::CoverTopAndBottom, Rosen::TextRectWidthStyle::Tight); } bool TextFieldPattern::ComputeOffsetForCaretDownstream( @@ -617,7 +617,7 @@ bool TextFieldPattern::ComputeOffsetForCaretDownstream( const auto& textBox = *textBoxes_.begin(); // Caret is within width of the downstream glyphs. float caretStart = textBox.rect_.GetLeft(); - float offsetX = std::min(caretStart, static_cast(paragraph_->GetLongestLine())); + float offsetX = std::min(caretStart, static_cast(paragraph_->GetActualWidth())); result.offset.SetX(offsetX); result.offset.SetY(textBox.rect_.GetTop()); result.height = textBox.rect_.GetHeight(); @@ -628,7 +628,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() @@ -1651,7 +1651,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)); } @@ -1664,10 +1663,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 @@ -2012,13 +2008,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()); @@ -2058,7 +2054,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_); } void TextFieldPattern::CursorMoveDown() @@ -2067,7 +2063,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_); } void TextFieldPattern::Delete(int32_t start, int32_t end) @@ -2237,7 +2233,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; @@ -2256,7 +2252,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; } @@ -2542,4 +2538,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 0136c0a012c..7c239ff4184 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 @@ -305,7 +305,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_; } @@ -491,7 +491,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 ProcessPadding(); @@ -567,7 +567,7 @@ private: TextEditingValueNG textEditingValue_; TextSelector textSelector_; RefPtr selectOverlayProxy_; - std::vector textBoxes_; + std::vector textBoxes_; ACE_DISALLOW_COPY_AND_MOVE(TextFieldPattern); RefPtr clipboard_; @@ -586,4 +586,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 80b720ae1d3..8b0455092cc 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp @@ -56,8 +56,8 @@ void SwitchPaintMethod::PaintContent( 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(); @@ -106,12 +106,12 @@ void SwitchPaintMethod::PaintContent( brush.SetAntiAlias(true); canvas.AttachBrush(brush); - Rosen::Drawing::Rect rect; + RSRect rect; rect.SetLeft(xOffset); rect.SetTop(yOffset); rect.SetRight(xOffset + width); rect.SetBottom(yOffset + height); - Rosen::Drawing::RoundRect roundRect(rect, radius, radius); + RSRoundRect roundRect(rect, radius, radius); canvas.DrawRoundRect(roundRect); auto innerRadius = pointRadius_ + actualGap * mainDelta_ / GetSwitchWidth(contentSize); @@ -124,19 +124,21 @@ void SwitchPaintMethod::PaintContent( } brush.SetAntiAlias(true); canvas.AttachBrush(brush); - Rosen::Drawing::Rect rectCover; - rectCover.SetLeft(xOffset); - rectCover.SetTop(yOffset); - rectCover.SetRight(xOffset + mainDelta_ + height - radiusGap_); - rectCover.SetBottom(yOffset + height); - Rosen::Drawing::RoundRect roundRectCover(rectCover, radius, radius); + RSRect rectCover; + float moveRitio = mainDelta_ / GetSwitchWidth(contentSize); + rectCover.SetLeft(xOffset + actualGap * (1 - moveRitio)); + rectCover.SetTop(yOffset + actualGap * (1 - moveRitio)); + rectCover.SetRight(xOffset + mainDelta_ + 2 * pointRadius_ + actualGap * (1 + moveRitio)); + rectCover.SetBottom(yOffset + height - actualGap * (1 - moveRitio)); + RSRoundRect roundRectCover(rectCover, innerRadius, innerRadius); canvas.DrawRoundRect(roundRectCover); } brush.SetColor(ToRSColor(paintProperty->GetSwitchPointColor().value_or(switchTheme->GetPointColor()))); brush.SetAntiAlias(true); canvas.AttachBrush(brush); - Rosen::Drawing::Point point; - point.SetX(xOffset + borderWidth_ + hoverRadius_ + mainDelta_); + + RSPoint point; + point.SetX(xOffset + actualGap + pointRadius_ + mainDelta_); point.SetY(yOffset + radius); canvas.DrawCircle(point, pointRadius_); } @@ -179,4 +181,4 @@ float SwitchPaintMethod::GetSwitchWidth(const SizeF& contentSize) const return switchWidth; } -} // namespace OHOS::Ace::NG +} // 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 0a79d685b30..a82334e5138 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.h +++ b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.h @@ -44,7 +44,7 @@ private: float actualWidth_ = 0.0f; float actualHeight_ = 0.0f; float pointRadius_ = 0.0f; - const Dimension radiusGap_ = 2.0_vp; + const float radiusGap_ = 2.0f; bool enabled_ = true; Color clickEffectColor_ = Color::WHITE; Color hoverColor_ = Color::WHITE; @@ -57,4 +57,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 a74f603d525..151f3b6dd1a 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_pattern.cpp +++ b/frameworks/core/components_ng/pattern/toggle/switch_pattern.cpp @@ -511,4 +511,4 @@ RectF SwitchPattern::GetHotZoneRect(bool isOriginal) const return RectF(offset, SizeF(actualWidth, actualHeight)); } -} // 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 50d0de0ff1f..ce0d21e15dc 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_pattern.h +++ b/frameworks/core/components_ng/pattern/toggle/switch_pattern.h @@ -136,4 +136,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 115a442804a..71ec1dc4267 100644 --- a/frameworks/core/components_ng/render/adapter/focus_state_modifier.h +++ b/frameworks/core/components_ng/render/adapter/focus_state_modifier.h @@ -48,17 +48,17 @@ public: void SetRoundRect(const RoundRect& rect) { 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); } @@ -76,4 +76,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 bb7fb2fae7d..0d05ef31405 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_paragraph.cpp b/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp index 52c297ee894..c491fd96127 100644 --- a/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp +++ b/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp @@ -25,12 +25,13 @@ namespace OHOS::Ace::NG { namespace { const std::u16string ELLIPSIS = u"\u2026"; } -RefPtr Paragraph::Create(const ParagraphStyle& paraStyle, const RefPtr& fontCollection) +RefPtr Paragraph::Create(const WeakPtr& context, const ParagraphStyle& paraStyle, + 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() @@ -46,7 +47,7 @@ void TxtParagraph::CreateBuilder() style.maxLines_ = paraStyle_.maxLines; style.locale_ = paraStyle_.fontLocale; if (paraStyle_.textOverflow == TextOverflow::ELLIPSIS) { - style.ellipsis = ELLIPSIS; + style.ellipsis_ = ELLIPSIS; } #ifndef NG_BUILD // keep WordBreak define same with WordBreakType in minikin @@ -130,7 +131,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() diff --git a/frameworks/core/components_ng/render/adapter/txt_paragraph.h b/frameworks/core/components_ng/render/adapter/txt_paragraph.h index 60cbd2a18a3..c8d30459181 100644 --- a/frameworks/core/components_ng/render/adapter/txt_paragraph.h +++ b/frameworks/core/components_ng/render/adapter/txt_paragraph.h @@ -61,6 +61,7 @@ public: private: void CreateBuilder(); + const WeakPtr& context_; ParagraphStyle paraStyle_; std::unique_ptr paragraph_; std::unique_ptr builder_; diff --git a/frameworks/core/components_ng/render/drawing.h b/frameworks/core/components_ng/render/drawing.h index 48d70a1b153..0a33ee9f041 100644 --- a/frameworks/core/components_ng/render/drawing.h +++ b/frameworks/core/components_ng/render/drawing.h @@ -59,11 +59,14 @@ using RSBlurType = Rosen::Drawing::BlurType; using RSPathEffect = Rosen::Drawing::PathEffect; using RSPathDirection = Rosen::Drawing::PathDirection; using RSPathDashStyle = Rosen::Drawing::PathDashStyle; -using RSParagraph = Rosen::Typography; +using RSParagraph = OHOS::Rosen::Typography; using RSParagraphBuilder = Rosen::TypographyCreate; using RSFontCollection = Rosen::FontCollection; using RSParagraphStyle = Rosen::TypographyStyle; using RSTextStyle = Rosen::TextStyle; +using RSColorQuad = Rosen::Drawing::ColorQuad; +using RSShaderEffect = Rosen::Drawing::ShaderEffect; +using RSTileMode = Rosen::Drawing::TileMode; } // 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 70cc9ee7098..0cd07827a0d 100644 --- a/frameworks/core/components_ng/render/drawing_prop_convertor.cpp +++ b/frameworks/core/components_ng/render/drawing_prop_convertor.cpp @@ -80,39 +80,39 @@ Rosen::FontWeight ToRSFontWeight(FontWeight fontWeight) switch (fontWeight) { case FontWeight::W100: case FontWeight::LIGHTER: - rsFontWeight = rosen::FontWeight::W100; + rsFontWeight = Rosen::FontWeight::W100; break; case FontWeight::W200: - rsFontWeight = rosen::FontWeight::W200; + rsFontWeight = Rosen::FontWeight::W200; break; case FontWeight::W300: - rsFontWeight = rosen::FontWeight::W300; + rsFontWeight = Rosen::FontWeight::W300; break; case FontWeight::W400: case FontWeight::NORMAL: case FontWeight::REGULAR: - rsFontWeight = rosen::FontWeight::W400; + rsFontWeight = Rosen::FontWeight::W400; break; case FontWeight::W500: case FontWeight::MEDIUM: - rsFontWeight = rosen::FontWeight::W500; + rsFontWeight = Rosen::FontWeight::W500; break; case FontWeight::W600: - rsFontWeight = rosen::FontWeight::W600; + rsFontWeight = Rosen::FontWeight::W600; break; case FontWeight::W700: case FontWeight::BOLD: - rsFontWeight = rosen::FontWeight::W700; + rsFontWeight = Rosen::FontWeight::W700; break; case FontWeight::W800: - rsFontWeight = rosen::FontWeight::W800; + rsFontWeight = Rosen::FontWeight::W800; break; case FontWeight::W900: case FontWeight::BOLDER: - rsFontWeight = rosen::FontWeight::W900; + rsFontWeight = Rosen::FontWeight::W900; break; default: - rsFontWeight = rosen::FontWeight::W400; + rsFontWeight = Rosen::FontWeight::W400; break; } return rsFontWeight; @@ -129,16 +129,16 @@ Rosen::TextDecoration ToRSTextDecoration(TextDecoration textDecoration) Rosen::TextDecoration rsTextDecoration = Rosen::TextDecoration::NONE; switch (textDecoration) { case TextDecoration::OVERLINE: - rsTextDecoration = rosen::TextDecoration::OVERLINE; + rsTextDecoration = Rosen::TextDecoration::OVERLINE; break; case TextDecoration::LINE_THROUGH: - rsTextDecoration = rosen::TextDecoration::LINETHROUGH; + rsTextDecoration = Rosen::TextDecoration::LINETHROUGH; break; case TextDecoration::UNDERLINE: - rsTextDecoration = rosen::TextDecoration::UNDERLINE; + rsTextDecoration = Rosen::TextDecoration::UNDERLINE; break; default: - rsTextDecoration = rosen::TextDecoration::NONE; + rsTextDecoration = Rosen::TextDecoration::NONE; break; } return rsTextDecoration; diff --git a/frameworks/core/components_ng/render/paragraph.h b/frameworks/core/components_ng/render/paragraph.h index 84d474794d9..440d624f920 100644 --- a/frameworks/core/components_ng/render/paragraph.h +++ b/frameworks/core/components_ng/render/paragraph.h @@ -40,7 +40,7 @@ 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 79c7b7ff9fe..79a7f97c52b 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 @@ -100,6 +100,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 69d14a48445..bb7189e09e1 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 87b1b3c9ca6..56635b8d145 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 0382bc34ccb..eaeb4ac48e9 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 7fda1440d04..765d1e22d1f 100644 --- a/frameworks/core/components_ng/test/pattern/ability_component/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/ability_component/BUILD.gn @@ -116,7 +116,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 71edce42abc..987cb661b61 100644 --- a/frameworks/core/components_ng/test/pattern/image_animator/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/image_animator/BUILD.gn @@ -95,7 +95,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 2eb9ad0b25d..16f1d804490 100644 --- a/frameworks/core/components_ng/test/pattern/option/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/option/BUILD.gn @@ -108,7 +108,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 00000000000..b774758898e --- /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", + ] +} -- Gitee