diff --git a/.gitignore b/.gitignore index 20f0dbd368c0053c64044756630ac006a5e46619..0b27b776ac804a4e1152d0d92f38a5b5d9c98830 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ *.iml .idea/ CMakeLists.txt -adapter/* !adapter/ohos/ !adapter/preview/ cmake-build-debug/ diff --git a/adapter/ohos/entrance/BUILD.gn b/adapter/ohos/entrance/BUILD.gn index 1daea7e3225c129f5accf714372e9fc33e5534b3..d531113a99117792017f76ef9a0cbeaddf953630 100644 --- a/adapter/ohos/entrance/BUILD.gn +++ b/adapter/ohos/entrance/BUILD.gn @@ -87,6 +87,7 @@ template("ace_ohos_standard_source_set") { "$ace_flutter_engine_root/skia:ace_skia_$platform", "$ace_root/adapter/ohos/capability:ace_capability_ohos", "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//third_party/zlib:shared_libz", ] diff --git a/adapter/ohos/entrance/window/drag_window_ohos.cpp b/adapter/ohos/entrance/window/drag_window_ohos.cpp index 2044bfb51a781117ea4da8c7608633b3b87e0c41..61d6e2e399392ac9dfba4a4ec1c1e90d19f22fac 100644 --- a/adapter/ohos/entrance/window/drag_window_ohos.cpp +++ b/adapter/ohos/entrance/window/drag_window_ohos.cpp @@ -29,6 +29,8 @@ #include "core/components_ng/render/adapter/skia_image.h" #include "core/pipeline_ng/pipeline_context.h" +#include "rosen_text/typography.h" + namespace OHOS::Ace { #ifdef ENABLE_ROSEN_BACKEND namespace { @@ -295,8 +297,8 @@ void DragWindowOhos::DrawImage(void* skImage) #endif } -void DragWindowOhos::DrawText( - std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText) +void DragWindowOhos::DrawText(std::shared_ptr paragraph, + const Offset& offset, const RefPtr& renderText) { #ifdef ENABLE_ROSEN_BACKEND CHECK_NULL_VOID(paragraph); @@ -425,4 +427,4 @@ void DragWindowOhos::DrawTextNG(const RefPtr& paragraph, const Re context->RequestFrame(); #endif } -} // namespace OHOS::Ace \ No newline at end of file +} // namespace OHOS::Ace diff --git a/adapter/ohos/entrance/window/drag_window_ohos.h b/adapter/ohos/entrance/window/drag_window_ohos.h index 648d2b057c128277b5bb4070964d4a1dc04aedab..eeb4b19a42d294a3a711ef6361f12fdd2af02c32 100644 --- a/adapter/ohos/entrance/window/drag_window_ohos.h +++ b/adapter/ohos/entrance/window/drag_window_ohos.h @@ -40,9 +40,9 @@ public: void DrawPixelMap(const RefPtr& pixelMap) override; void DrawFrameNode(const RefPtr& rootNode) override; void DrawImage(void* skImage) override; - void DrawText( - std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText) override; void DrawTextNG(const RefPtr& paragraph, const RefPtr& textPattern) override; + void DrawText(std::shared_ptr paragraph, + const Offset& offset, const RefPtr& renderText) override; private: OHOS::sptr dragWindow_; @@ -53,4 +53,4 @@ private: }; } // namespace OHOS::Ace -#endif // FOUNDATION_ACE_ADAPTER_OHOS_OSAL_DRAG_WINDOW_OHOS_H \ No newline at end of file +#endif // FOUNDATION_ACE_ADAPTER_OHOS_OSAL_DRAG_WINDOW_OHOS_H diff --git a/frameworks/base/window/drag_window.h b/frameworks/base/window/drag_window.h index 7e568caabd0eaf71871e9f888e48fb12ed3514b3..7547fdcacc611e17b426f72d9f69042b7deaf6ae 100644 --- a/frameworks/base/window/drag_window.h +++ b/frameworks/base/window/drag_window.h @@ -20,8 +20,8 @@ #include "base/image/pixel_map.h" #include "base/memory/ace_type.h" -namespace txt { -class Paragraph; +namespace OHOS::Rosen { +class Typography; } namespace OHOS::Ace { @@ -49,10 +49,10 @@ 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, const Offset& offset, const RefPtr& renderText) = 0; virtual void DrawTextNG(const RefPtr& paragraph, const RefPtr& textPattern) = 0; + virtual void DrawText(std::shared_ptr paragraph_, + const Offset& offset, const RefPtr& renderText) = 0; void SetOffset(int32_t offsetX, int32_t offsetY) { offsetX_ = offsetX; diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 27524dc5def3e6333825d9162ca77423438f2e06..084fb3d87c5966bd0179417a938de3ef2d641be1 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -359,6 +359,7 @@ template("ace_core_source_set") { ] deps += [ "$ace_root/frameworks/core/components_part_upd/foreach:ace_core_components_foreach_part_upd_$platform" ] + deps += [ "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text" ] deps += [ "$ace_root/frameworks/core/components_ng/animation:ace_core_components_animation_ng_$platform", diff --git a/frameworks/core/components/calendar/flutter_render_calendar.cpp b/frameworks/core/components/calendar/flutter_render_calendar.cpp index 05dbfaf5f77559dcf11e94b182356e58d4c08c43..9e5d6f78dd28d30bf51063ae534189341c035f6e 100644 --- a/frameworks/core/components/calendar/flutter_render_calendar.cpp +++ b/frameworks/core/components/calendar/flutter_render_calendar.cpp @@ -15,8 +15,8 @@ #include "core/components/calendar/flutter_render_calendar.h" -#include "flutter/third_party/txt/src/txt/paragraph.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" +#include "rosen_text/typography.h" +#include "rosen_text/typography_create.h" #include "base/i18n/localization.h" #include "base/utils/string_utils.h" @@ -37,22 +37,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 +79,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); @@ -280,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++) { @@ -324,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; } @@ -358,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); @@ -394,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_ @@ -404,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; @@ -423,8 +423,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 @@ -461,11 +461,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_) { @@ -476,8 +476,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); } @@ -485,8 +485,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); } } @@ -531,11 +531,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) { @@ -546,8 +546,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); @@ -555,8 +555,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); @@ -583,13 +583,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) @@ -642,10 +642,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; @@ -661,7 +661,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); @@ -679,12 +679,12 @@ void FlutterRenderCalendar::InitWorkStateStyle( } void FlutterRenderCalendar::SetWorkStateStyle( - const CalendarDay& day, SkColor workColor, SkColor offColor, txt::TextStyle& workStateStyle) const + const CalendarDay& day, SkColor workColor, SkColor offColor, Rosen::TextStyle& workStateStyle) const { if (day.dayMark == "work") { - workStateStyle.color = workColor; + workStateStyle.color_ = workColor; } else if (day.dayMark == "off") { - workStateStyle.color = offColor; + workStateStyle.color_ = offColor; } } diff --git a/frameworks/core/components/calendar/flutter_render_calendar.h b/frameworks/core/components/calendar/flutter_render_calendar.h index cd39478c553df5a5f3211d5dcba0bc3627337e17..16d178761c3671b8fac351f1ccad49e1e23fd063 100644 --- a/frameworks/core/components/calendar/flutter_render_calendar.h +++ b/frameworks/core/components/calendar/flutter_render_calendar.h @@ -17,7 +17,7 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_FLUTTER_RENDER_CALENDAR_H #include "third_party/skia/include/core/SkColor.h" -#include "third_party/txt/src/txt/text_style.h" +#include "rosen_text/text_style.h" #include "core/components/calendar/render_calendar.h" #include "core/pipeline/layers/clip_layer.h" @@ -46,21 +46,21 @@ private: void DrawBlurArea(ScopedCanvas& canvas, const Offset& offset, double x, double y) const; void DrawTouchedArea(RenderContext& context, Offset offset) const; void PaintDay( - ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, txt::TextStyle& textStyle) const; + ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, Rosen::TextStyle& textStyle) const; void PaintLunarDay( - ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, const txt::TextStyle& textStyle) const; - void SetNonFocusStyle(const CalendarDay& day, txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle); + ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day, const Rosen::TextStyle& textStyle) const; + void SetNonFocusStyle(const CalendarDay& day, Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle); void DrawCardCalendar(ScopedCanvas& canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber); void DrawTvCalendar(ScopedCanvas& canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber); - void InitTextStyle(txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle); + void InitTextStyle(Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle); void PaintUnderscore(ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day); void PaintScheduleMarker(ScopedCanvas& canvas, const Offset& offset, const CalendarDay& day); void InitWorkStateStyle( - const CalendarDay& day, const Offset& offset, txt::TextStyle& workStateStyle, Rect& boxRect) const; + const CalendarDay& day, const Offset& offset, Rosen::TextStyle& workStateStyle, Rect& boxRect) const; void SetWorkStateStyle( - const CalendarDay& day, SkColor workColor, SkColor offColor, txt::TextStyle& workStateStyle) const; + const CalendarDay& day, SkColor workColor, SkColor offColor, Rosen::TextStyle& workStateStyle) const; void SetCalendarTheme(); bool IsOffDay(const CalendarDay& day) const; void AddContentLayer(); diff --git a/frameworks/core/components/calendar/rosen_render_calendar.cpp b/frameworks/core/components/calendar/rosen_render_calendar.cpp index 6f2911bd886e2d307d729fccfa8d15e1da106176..0a9ad3ff3d84ccbdad5b617823c42e30a8c038f4 100644 --- a/frameworks/core/components/calendar/rosen_render_calendar.cpp +++ b/frameworks/core/components/calendar/rosen_render_calendar.cpp @@ -16,8 +16,8 @@ #include "core/components/calendar/rosen_render_calendar.h" #include "render_service_client/core/ui/rs_node.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" @@ -37,22 +37,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 +78,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 +268,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 +311,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 +345,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 +381,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 +391,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 +410,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 +447,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 +462,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 +471,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 +517,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 +532,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 +541,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 +569,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 +621,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 +640,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 +658,12 @@ void RosenRenderCalendar::InitWorkStateStyle( } void RosenRenderCalendar::SetWorkStateStyle( - const CalendarDay& day, SkColor workColor, SkColor offColor, txt::TextStyle& workStateStyle) const + const CalendarDay& day, SkColor workColor, SkColor offColor, Rosen::TextStyle& workStateStyle) const { if (day.dayMark == "work") { - workStateStyle.color = workColor; + workStateStyle.color_ = workColor; } else if (day.dayMark == "off") { - workStateStyle.color = offColor; + workStateStyle.color_ = offColor; } } diff --git a/frameworks/core/components/calendar/rosen_render_calendar.h b/frameworks/core/components/calendar/rosen_render_calendar.h index e98e63b752ba50a134e25fcd9a2cb03b2edfaca5..f6c6cc0ef036ab74d031deff598262e945e632e4 100644 --- a/frameworks/core/components/calendar/rosen_render_calendar.h +++ b/frameworks/core/components/calendar/rosen_render_calendar.h @@ -18,7 +18,8 @@ #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColor.h" -#include "third_party/txt/src/txt/text_style.h" +#include "rosen_text/text_style.h" +#include "rosen_text/text_style.h" #include "core/components/calendar/render_calendar.h" @@ -46,21 +47,21 @@ private: void DrawWeek(SkCanvas* canvas, const Offset& offset) const; void DrawBlurArea(SkCanvas* canvas, const Offset& offset, double x, double y) const; void DrawTouchedArea(RenderContext& context, Offset offset) const; - void PaintDay(SkCanvas* canvas, const Offset& offset, const CalendarDay& day, txt::TextStyle& textStyle) const; + void PaintDay(SkCanvas* canvas, const Offset& offset, const CalendarDay& day, Rosen::TextStyle& textStyle) const; void PaintLunarDay( - SkCanvas* canvas, const Offset& offset, const CalendarDay& day, const txt::TextStyle& textStyle) const; - void SetNonFocusStyle(const CalendarDay& day, txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle); + SkCanvas* canvas, const Offset& offset, const CalendarDay& day, const Rosen::TextStyle& textStyle) const; + void SetNonFocusStyle(const CalendarDay& day, Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle); void DrawCardCalendar( SkCanvas* canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber); void DrawTvCalendar( SkCanvas* canvas, const Offset& offset, const Offset& dayOffset, const CalendarDay& day, int32_t dateNumber); - void InitTextStyle(txt::TextStyle& dateTextStyle, txt::TextStyle& lunarTextStyle); + void InitTextStyle(Rosen::TextStyle& dateTextStyle, Rosen::TextStyle& lunarTextStyle); void PaintUnderscore(SkCanvas* canvas, const Offset& offset, const CalendarDay& day); void PaintScheduleMarker(SkCanvas* canvas, const Offset& offset, const CalendarDay& day); void InitWorkStateStyle( - const CalendarDay& day, const Offset& offset, txt::TextStyle& workStateStyle, Rect& boxRect) const; + const CalendarDay& day, const Offset& offset, Rosen::TextStyle& workStateStyle, Rect& boxRect) const; void SetWorkStateStyle( - const CalendarDay& day, SkColor workColor, SkColor offColor, txt::TextStyle& workStateStyle) const; + const CalendarDay& day, SkColor workColor, SkColor offColor, Rosen::TextStyle& workStateStyle) const; void SetCalendarTheme(); bool IsOffDay(const CalendarDay& day) const; void AddContentLayer(RenderContext& context); diff --git a/frameworks/core/components/chart/flutter_render_chart.cpp b/frameworks/core/components/chart/flutter_render_chart.cpp index 1c5441da4bb5ccf3cf311eb22dafdce89221e1c5..e9eea4282f2dfc95c0f21987f44895435732033a 100644 --- a/frameworks/core/components/chart/flutter_render_chart.cpp +++ b/frameworks/core/components/chart/flutter_render_chart.cpp @@ -18,13 +18,13 @@ #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/effects/Sk1DPathEffect.h" #include "third_party/skia/include/effects/SkGradientShader.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" #include "base/utils/string_utils.h" #include "core/components/calendar/flutter_render_calendar.h" #include "core/components/font/flutter_font_collection.h" +#include "rosen_text/typography.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" namespace OHOS::Ace { namespace { @@ -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/rosen_render_chart.cpp b/frameworks/core/components/chart/rosen_render_chart.cpp index cc346398eeeb8b64b7079adef83d92184c2eeac8..1fd7736a492f46c1cc4aac79f7849e668b5baae2 100644 --- a/frameworks/core/components/chart/rosen_render_chart.cpp +++ b/frameworks/core/components/chart/rosen_render_chart.cpp @@ -15,12 +15,12 @@ #include "core/components/chart/rosen_render_chart.h" +#include "rosen_text/typography.h" +#include "rosen_text/typography_create.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" #include "third_party/skia/include/effects/SkGradientShader.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" #include "base/utils/string_utils.h" #include "core/components/calendar/rosen_render_calendar.h" @@ -137,23 +137,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/common/painter/flutter_scroll_fade_painter.cpp b/frameworks/core/components/common/painter/flutter_scroll_fade_painter.cpp index 73be2d0bcff9eafb131099ee91d6064d5dfcdd28..a6d33516a5ccd0e6e1125f458cc64fa165bf876f 100644 --- a/frameworks/core/components/common/painter/flutter_scroll_fade_painter.cpp +++ b/frameworks/core/components/common/painter/flutter_scroll_fade_painter.cpp @@ -101,4 +101,4 @@ void FlutterScrollFadePainter::PaintSide(RenderContext& context, const Size& siz } } -} // namespace OHOS::Ace \ No newline at end of file +} // namespace OHOS::Ace diff --git a/frameworks/core/components/components.gni b/frameworks/core/components/components.gni index caccc51cb277c85549d1b9f2ebf3617e445641f4..7889595cb51bdb03bde0ca4a8d1f5c11a506c804 100644 --- a/frameworks/core/components/components.gni +++ b/frameworks/core/components/components.gni @@ -56,6 +56,7 @@ template("build_component") { deps = [] deps += extra_deps deps += [ "$ace_root/frameworks/core/components/theme:build_theme_code" ] + deps += [ "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text" ] if (enable_ng_build) { deps += [ diff --git a/frameworks/core/components/custom_paint/flutter_render_custom_paint.cpp b/frameworks/core/components/custom_paint/flutter_render_custom_paint.cpp index e27d294b300def50dffcc3b922da049ded05a5f4..3d9c9940042491338091b22cfa3a302aaf40e04d 100644 --- a/frameworks/core/components/custom_paint/flutter_render_custom_paint.cpp +++ b/frameworks/core/components/custom_paint/flutter_render_custom_paint.cpp @@ -17,8 +17,8 @@ #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/bounds_checking_function/include/securec.h" #include "third_party/skia/include/core/SkBlendMode.h" #include "third_party/skia/include/core/SkCanvas.h" @@ -512,20 +512,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(); } @@ -533,20 +533,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(); } @@ -554,20 +554,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(); @@ -609,7 +609,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) { @@ -635,7 +635,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) { @@ -1212,67 +1212,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()); } @@ -1281,8 +1279,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 b103d0e1cc22c9ecadc65933d4707da64ad6cb8a..64db99723aaf8dfc023ef4d4b7c738c05f89ad0c 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" @@ -97,14 +98,14 @@ private: 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); + 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 400337e7b9dd92a627ff2218c3f38aee47eb8004..c9f0144fd7f7517e74085b9bfcd2d80b5283c6b7 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" @@ -1086,21 +1087,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(); } @@ -1108,21 +1109,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(); } @@ -1130,21 +1131,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(); @@ -1186,7 +1187,7 @@ void FlutterRenderOffscreenCanvas::PaintText(const std::string& text, double x, } double FlutterRenderOffscreenCanvas::GetAlignOffset( - const std::string& text, TextAlign align, std::unique_ptr& paragraph) + const std::string& text, TextAlign align, std::unique_ptr& paragraph) { double x = 0.0; switch (align) { @@ -1238,66 +1239,64 @@ bool FlutterRenderOffscreenCanvas::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(); 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) +void FlutterRenderOffscreenCanvas::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(), 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()); } @@ -1306,13 +1305,12 @@ void FlutterRenderOffscreenCanvas::UpdateTextStyleForeground(bool isStroke, txt: 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) +double FlutterRenderOffscreenCanvas::GetBaselineOffset(TextBaseline baseline, + 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 c3490fc84eb6c87c65b1b74cd57373d39223e556..aa18fb79ffe23d1a4be034b758c960013fedb7e6 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" @@ -98,12 +99,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 7f1533d5cfb5585e0037d73e5c43eed80a879ac3..ad48b8f2986819984ef88f6f10badf4700c9880c 100644 --- a/frameworks/core/components/custom_paint/rosen_render_custom_paint.cpp +++ b/frameworks/core/components/custom_paint/rosen_render_custom_paint.cpp @@ -17,9 +17,9 @@ #include -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography.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" @@ -398,39 +398,39 @@ void RosenRenderCustomPaint::StrokeText(const Offset& offset, const std::string& double RosenRenderCustomPaint::MeasureTextInner(const MeasureContext& context) { using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; std::vector fontFamilies; if (context.fontSize) { - txtStyle.font_size = context.fontSize.value().ConvertToPx(); + txtStyle.fontSize_ = context.fontSize.value().ConvertToPx(); } else { auto context = PipelineBase::GetCurrentContext(); auto textTheme = context->GetTheme(); - txtStyle.font_size = textTheme->GetTextStyle().GetFontSize().ConvertToPx(); + txtStyle.fontSize_ = textTheme->GetTextStyle().GetFontSize().ConvertToPx(); } - txtStyle.font_style = ConvertTxtFontStyle(context.fontStyle); + txtStyle.fontStyle_ = ConvertTxtFontStyle(context.fontStyle); FontWeight fontWeightStr = StringUtils::StringToFontWeight(context.fontWeight); - txtStyle.font_weight = ConvertTxtFontWeight(fontWeightStr); + txtStyle.fontWeight_ = ConvertTxtFontWeight(fontWeightStr); StringUtils::StringSplitter(context.fontFamily, ',', fontFamilies); - txtStyle.font_families = fontFamilies; + txtStyle.fontFamilies_ = fontFamilies; if (context.letterSpacing.has_value()) { - txtStyle.letter_spacing = context.letterSpacing.value().ConvertToPx(); + txtStyle.letterSpacing_ = context.letterSpacing.value().ConvertToPx(); } builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(context.textContent)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(context.textContent)); + auto paragraph = builder->CreateTypography(); if (!paragraph) { return 0.0; } paragraph->Layout(Size::INFINITE_SIZE); - return std::ceil(paragraph->GetLongestLine()); + return std::ceil(paragraph->GetActualWidth()); } Size RosenRenderCustomPaint::MeasureTextSizeInner(const MeasureContext& context) @@ -441,50 +441,50 @@ Size RosenRenderCustomPaint::MeasureTextSizeInner(const MeasureContext& context) LOGW("fontCollection is null"); return Size(0.0, 0.0); } - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(context.textAlign); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(context.textAlign); if (context.textOverlayFlow == TextOverflow::ELLIPSIS) { - style.ellipsis = ELLIPSIS; + style.ellipsis_ = ELLIPSIS; } if (GreatNotEqual(context.maxlines, 0.0)) { - style.max_lines = context.maxlines; + style.maxLines_ = context.maxlines; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; std::vector fontFamilies; if (context.fontSize.has_value()) { - txtStyle.font_size = context.fontSize.value().ConvertToPx(); + txtStyle.fontSize_ = context.fontSize.value().ConvertToPx(); } else { auto context = PipelineBase::GetCurrentContext(); auto textTheme = context->GetTheme(); - txtStyle.font_size = textTheme->GetTextStyle().GetFontSize().ConvertToPx(); + txtStyle.fontSize_ = textTheme->GetTextStyle().GetFontSize().ConvertToPx(); } - txtStyle.font_style = ConvertTxtFontStyle(context.fontStyle); + txtStyle.fontStyle_ = ConvertTxtFontStyle(context.fontStyle); FontWeight fontWeightStr = StringUtils::StringToFontWeight(context.fontWeight); - txtStyle.font_weight = ConvertTxtFontWeight(fontWeightStr); + txtStyle.fontWeight_ = ConvertTxtFontWeight(fontWeightStr); StringUtils::StringSplitter(context.fontFamily, ',', fontFamilies); - txtStyle.font_families = fontFamilies; + txtStyle.fontFamilies_ = fontFamilies; if (context.letterSpacing.has_value()) { - txtStyle.letter_spacing = context.letterSpacing.value().ConvertToPx(); + txtStyle.letterSpacing_ = context.letterSpacing.value().ConvertToPx(); } if (context.lineHeight.has_value()) { if (context.lineHeight->Unit() == DimensionUnit::PERCENT) { - txtStyle.has_height_override = true; - txtStyle.height = context.lineHeight->Value(); + txtStyle.heightOnly_ = true; + txtStyle.heightScale_ = context.lineHeight->Value(); } else { auto lineHeight = context.lineHeight.value().ConvertToPx(); - if (!NearEqual(lineHeight, txtStyle.font_size) && (lineHeight > 0.0) && (!NearZero(txtStyle.font_size))) { - txtStyle.height = lineHeight / txtStyle.font_size; - txtStyle.has_height_override = true; + if (!NearEqual(lineHeight, txtStyle.fontSize_) && (lineHeight > 0.0) && (!NearZero(txtStyle.fontSize_))) { + txtStyle.heightScale_ = lineHeight / txtStyle.fontSize_; + txtStyle.heightOnly_ = true; } } } builder->PushStyle(txtStyle); std::string content = context.textContent; StringUtils::TransformStrCase(content, static_cast(context.textCase)); - builder->AddText(StringUtils::Str8ToStr16(content)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(content)); + auto paragraph = builder->CreateTypography(); if (!paragraph) { return Size(0.0, 0.0); } @@ -494,11 +494,11 @@ Size RosenRenderCustomPaint::MeasureTextSizeInner(const MeasureContext& context) paragraph->Layout(Size::INFINITE_SIZE); } double textWidth = 0.0; - auto* paragraphTxt = static_cast(paragraph.get()); + auto* paragraphTxt = static_cast(paragraph.get()); if (paragraphTxt->GetLineCount() == 1) { - textWidth = std::max(paragraph->GetLongestLine(), paragraph->GetMaxIntrinsicWidth()); + textWidth = std::max(paragraph->GetActualWidth(), paragraph->GetMaxIntrinsicWidth()); } else { - textWidth = paragraph->GetLongestLine(); + textWidth = paragraph->GetActualWidth(); } auto sizeWidth = std::min(paragraph->GetMaxWidth(), textWidth); sizeWidth = @@ -516,20 +516,20 @@ Size RosenRenderCustomPaint::MeasureTextSizeInner(const MeasureContext& context) double RosenRenderCustomPaint::MeasureText(const std::string& text, const PaintState& state) { using namespace Constants; - txt::ParagraphStyle style; - style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); if (!fontCollection) { LOGW("MeasureText: fontCollection is null"); return 0.0; } - std::unique_ptr builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); - txt::TextStyle txtStyle; + std::unique_ptr builder = Rosen::TypographyCreate::Create(style, fontCollection); + Rosen::TextStyle txtStyle; ConvertTxtStyle(state.GetTextStyle(), context_, txtStyle); - txtStyle.font_size = state.GetTextStyle().GetFontSize().Value(); + txtStyle.fontSize_ = state.GetTextStyle().GetFontSize().Value(); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(text)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(text)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(Size::INFINITE_SIZE); return paragraph->GetMaxIntrinsicWidth(); } @@ -537,20 +537,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(); } @@ -558,20 +558,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(); @@ -613,7 +613,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) { @@ -639,7 +639,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) { @@ -1216,61 +1216,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 { @@ -1278,7 +1276,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()); } @@ -1287,8 +1285,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 88d8705cd94b133f5a4b320f54d3e5e0b5d619c5..68eec9cd133e6c0e7dff494a6bd82f55b3cf7601 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" @@ -103,14 +104,14 @@ private: 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); + double GetAlignOffset(TextAlign align, std::unique_ptr& paragraph); + double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); SkPaint GetStrokePaint(); bool HasShadow() const; void UpdatePaintShader(const Offset& offset, SkPaint& paint, const Gradient& gradient); void UpdatePaintShader(const Pattern& pattern, SkPaint& paint); void UpdateLineDash(SkPaint& paint); - void UpdateTextStyleForeground(const Offset& offset, bool isStroke, txt::TextStyle& style, bool hasShadow); + void UpdateTextStyleForeground(const Offset& offset, bool isStroke, Rosen::TextStyle& style, bool hasShadow); void Path2DAddPath(const Offset& offset, const PathArgs& args); void Path2DSetTransform(const Offset& offset, const PathArgs& args); @@ -136,7 +137,7 @@ private: bool CreateSurface(double viewScale); bool antiAlias_ = false; - std::unique_ptr paragraph_; + std::unique_ptr paragraph_; SkPath skPath_; // Specifically refers to the class Path2D in canvas.d.ts SkPath skPath2d_; diff --git a/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.cpp b/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.cpp index 5b5a1bdba1f13f020589c68d37c5eaaa3718dfda..2d63b054d60ebcaba3ee1de393e4b73895da85ec 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" @@ -1199,21 +1200,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(); } @@ -1221,21 +1222,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(); } @@ -1243,21 +1244,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(); @@ -1299,7 +1300,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) { @@ -1351,67 +1352,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()); } @@ -1420,13 +1419,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 bfc20d9ecb661f8dbb350518f1e3d188a421d2be..835ad7a05ffb0d519accd30074f7a10371ae77be 100644 --- a/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.h +++ b/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.h @@ -17,7 +17,6 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CUSTOM_PAINT_ROSEN_RENDER_OFFSCREEN_CANVAS_H #include "experimental/svg/model/SkSVGDOM.h" -#include "flutter/third_party/txt/src/txt/paragraph.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPath.h" @@ -27,6 +26,8 @@ #include "core/image/image_object.h" #include "core/image/image_provider.h" #include "core/pipeline/base/scoped_canvas_state.h" +#include "rosen_text/text_style.h" +#include "rosen_text/typography.h" namespace OHOS::Ace { using setColorFunc = std::function; @@ -107,12 +108,12 @@ private: void UpdatePaintShader(SkPaint& paint, const Gradient& gradient); void UpdatePaintShader(const Pattern& pattern, SkPaint& paint); void PaintText(const std::string& text, double x, double y, bool isStroke, bool hasShadow = false); - double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); - std::unique_ptr paragraph_; + double GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph); + std::unique_ptr paragraph_; bool HasShadow() const; bool HasImageShadow() const; - void UpdateTextStyleForeground(bool isStroke, txt::TextStyle& style, bool hasShadow); - double GetAlignOffset(const std::string& text, TextAlign align, std::unique_ptr& paragraph); + void UpdateTextStyleForeground(bool isStroke, Rosen::TextStyle& style, bool hasShadow); + double GetAlignOffset(const std::string& text, TextAlign align, std::unique_ptr& paragraph); TextDirection GetTextDirection(const std::string& text); bool UpdateOffParagraph(const std::string& text, bool isStroke, const PaintState& state, bool hasShadow = false); void UpdateLineDash(SkPaint& paint); diff --git a/frameworks/core/components/font/constants_converter.cpp b/frameworks/core/components/font/constants_converter.cpp index 8cd8218b231bb2b9ec5b161d7c675926041c858b..1173463d02a92e8d95eaddba3e406fc89c928e92 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; + 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,74 @@ 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()); + OHOS::Rosen::TextShadow txtShadow; + txtShadow.color_ = spanShadow.GetColor().GetValue(); + txtShadow.offset_.SetX(spanShadow.GetOffset().GetX()); + txtShadow.offset_.SetY(spanShadow.GetOffset().GetY()); #ifdef FLUTTER_2_5 - txtShadow.blur_sigma = spanShadow.GetBlurRadius(); + txtShadow.blurRadius_ = spanShadow.GetBlurRadius(); #else - txtShadow.blur_radius = spanShadow.GetBlurRadius(); + txtShadow.blurRadius_ = spanShadow.GetBlurRadius(); #endif - txtStyle.text_shadows.emplace_back(txtShadow); + 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 +255,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 +273,14 @@ Rect ConvertSkRect(SkRect skRect) return result; } +Rect ConvertSkRect(const Rosen::Drawing::RectF &skRect) +{ + Rect result; + result.SetLeft(skRect.GetLeft()); + result.SetTop(skRect.GetTop()); + result.SetWidth(skRect.GetWidth()); + result.SetHeight(skRect.GetHeight()); + return result; +} + } // namespace OHOS::Ace::Constants diff --git a/frameworks/core/components/font/constants_converter.h b/frameworks/core/components/font/constants_converter.h index 37dc06c5ab70d1053b39d56022c0d748e57f7e17..88977988f611ff9368877641e25333ead4019226 100644 --- a/frameworks/core/components/font/constants_converter.h +++ b/frameworks/core/components/font/constants_converter.h @@ -16,20 +16,22 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_CONSTANTS_CONVERTER_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_CONSTANTS_CONVERTER_H -#include "flutter/third_party/txt/src/txt/text_baseline.h" -#include "flutter/third_party/txt/src/txt/text_decoration.h" -#include "flutter/third_party/txt/src/txt/text_style.h" +#include "rosen_text/typography_types.h" #include "third_party/skia/include/core/SkColor.h" #include "core/components/common/properties/text_style.h" #include "core/pipeline/pipeline_base.h" -namespace txt { +namespace OHOS::Rosen { enum class FontWeight; enum class FontStyle; enum class TextAlign; enum class TextDirection; -} // namespace txt +struct TextStyle; +namespace Drawing { +class RectF; +} // namespace Drawing +} // namespace OHOS::Rosen namespace OHOS::Ace { @@ -44,24 +46,26 @@ class Color; namespace Constants { -txt::FontWeight ConvertTxtFontWeight(FontWeight fontWeight); +OHOS::Rosen::FontWeight ConvertTxtFontWeight(FontWeight fontWeight); -txt::FontStyle ConvertTxtFontStyle(FontStyle fontStyle); +OHOS::Rosen::FontStyle ConvertTxtFontStyle(FontStyle fontStyle); -txt::TextBaseline ConvertTxtTextBaseline(TextBaseline textBaseline); +OHOS::Rosen::TextBaseline ConvertTxtTextBaseline(TextBaseline textBaseline); -txt::TextAlign ConvertTxtTextAlign(TextAlign textAlign); +OHOS::Rosen::TextAlign ConvertTxtTextAlign(TextAlign textAlign); -txt::TextDirection ConvertTxtTextDirection(TextDirection textDirection); +OHOS::Rosen::TextDirection ConvertTxtTextDirection(TextDirection textDirection); SkColor ConvertSkColor(Color color); -txt::TextDecoration ConvertTxtTextDecoration(TextDecoration textDecoration); +OHOS::Rosen::TextDecoration ConvertTxtTextDecoration(TextDecoration textDecoration); -void ConvertTxtStyle(const TextStyle& textStyle, const WeakPtr& context, txt::TextStyle& txtStyle); +void ConvertTxtStyle(const TextStyle& textStyle, const WeakPtr& context, OHOS::Rosen::TextStyle& txtStyle); Rect ConvertSkRect(SkRect skRect); +Rect ConvertSkRect(const Rosen::Drawing::RectF &skRect); + } // namespace Constants } // namespace OHOS::Ace diff --git a/frameworks/core/components/font/flutter_font_collection.cpp b/frameworks/core/components/font/flutter_font_collection.cpp index 840e3c5e43435003895d5bce688f25183d1f5e57..d3d58feb7f165624f211c20ad602fb55a7c38f1b 100644 --- a/frameworks/core/components/font/flutter_font_collection.cpp +++ b/frameworks/core/components/font/flutter_font_collection.cpp @@ -25,17 +25,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()); } std::call_once(fontFlag_, [this]() { @@ -47,7 +49,7 @@ std::shared_ptr FlutterFontCollection::GetFontCollection() fontCollection_->GetFontCollection()->GetMinikinFontCollectionForFamilies({ "sans-serif" }, emptyLocale); } }); - return fontCollection_->GetFontCollection(); + return Rosen::FontCollection::From(fontCollection_->GetFontCollection()); } void FlutterFontCollection::LoadFontFromList(const uint8_t* fontData, size_t length, std::string familyName) diff --git a/frameworks/core/components/font/flutter_font_collection.h b/frameworks/core/components/font/flutter_font_collection.h index acc8a19fa10eb28e96253dd1e88477b7fbe0a9b1..3594465eeae957fcd7c5957cdf42186d4282d2ad 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 9491e7e9d4214b15243221e76e7aa90a7b4f5d43..5f18365357eb36f4c66a9e06b88f11760456ec7a 100644 --- a/frameworks/core/components/font/font_collection.h +++ b/frameworks/core/components/font/font_collection.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_FONT_COLLECTION_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_FONT_COLLECTION_H -#include "flutter/third_party/txt/src/txt/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 66e212f4b05d474e76cffeaa645addcf943d8cdc..c17ce70665b77229bbcc31c9362996b4f96cec34 100644 --- a/frameworks/core/components/font/rosen_font_collection.cpp +++ b/frameworks/core/components/font/rosen_font_collection.cpp @@ -26,17 +26,16 @@ #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() { std::call_once(fontFlag_, [this]() { - fontCollection_ = std::make_shared(); - fontCollection_->SetupDefaultFontManager(); - dynamicFontManager_ = sk_make_sp(); - fontCollection_->SetDynamicFontManager(dynamicFontManager_); + fontCollection_ = Rosen::FontCollection::Create(); }); return fontCollection_; } @@ -51,15 +50,7 @@ void RosenFontCollection::LoadFontFromList(const uint8_t* fontData, size_t lengt families_.emplace_back(familyName); if (fontCollection_) { - std::unique_ptr font_stream = std::make_unique(fontData, length, true); - sk_sp typeface = SkTypeface::MakeFromStream(std::move(font_stream)); - txt::TypefaceFontAssetProvider& font_provider = dynamicFontManager_->font_provider(); - if (familyName.empty()) { - font_provider.RegisterTypeface(typeface); - } else { - font_provider.RegisterTypeface(typeface, familyName); - } - fontCollection_->ClearFontFamilyCache(); + fontCollection_->LoadFont(familyName, fontData, length); } } @@ -75,7 +66,7 @@ void RosenFontCollection::VaryFontCollectionWithFontWeightScale(float fontWeight } if (fontCollection_) { - fontCollection_->VaryFontCollectionWithFontWeightScale(fontWeightScale); + // fontCollection_->VaryFontCollectionWithFontWeightScale(fontWeightScale); } } @@ -84,7 +75,7 @@ void RosenFontCollection::LoadSystemFont() ACE_FUNCTION_TRACE(); if (fontCollection_) { - fontCollection_->LoadSystemFont(); + //fontCollection_->LoadSystemFont(); } } @@ -98,7 +89,7 @@ void RosenFontCollection::SetIsZawgyiMyanmar(bool isZawgyiMyanmar) isZawgyiMyanmar_ = isZawgyiMyanmar; if (fontCollection_) { - fontCollection_->SetIsZawgyiMyanmar(isZawgyiMyanmar); + //fontCollection_->SetIsZawgyiMyanmar(isZawgyiMyanmar); } AceEngine::Get().NotifyContainers([](const RefPtr& container) { diff --git a/frameworks/core/components/font/rosen_font_collection.h b/frameworks/core/components/font/rosen_font_collection.h index 053c7fbfe91ea45471d1d17ddfecf85eac9db026..79da92c5272958f962ea13862f7a40c716004c98 100644 --- a/frameworks/core/components/font/rosen_font_collection.h +++ b/frameworks/core/components/font/rosen_font_collection.h @@ -19,9 +19,9 @@ #include #include "flutter/common/task_runners.h" -#include "txt/font_collection.h" #include "core/components/font/font_collection.h" +#include "rosen_text/font_collection.h" namespace OHOS::Ace { @@ -29,7 +29,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); @@ -40,8 +40,8 @@ public: void SetIsZawgyiMyanmar(bool isZawgyiMyanmar); private: - std::shared_ptr fontCollection_; - sk_sp dynamicFontManager_; + std::shared_ptr fontCollection_; + //sk_sp dynamicFontManager_; std::vector families_; bool isZawgyiMyanmar_ = false; diff --git a/frameworks/core/components/multimodal/flutter_render_multimodal.cpp b/frameworks/core/components/multimodal/flutter_render_multimodal.cpp index ebea507bf039ab7791e2a0180c021e5f068d5a3d..f578e8b04fcc662ce61c75290ea4ea38d1172f6e 100644 --- a/frameworks/core/components/multimodal/flutter_render_multimodal.cpp +++ b/frameworks/core/components/multimodal/flutter_render_multimodal.cpp @@ -17,8 +17,8 @@ #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 "base/i18n/localization.h" #include "base/utils/string_utils.h" @@ -67,8 +67,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 } }; @@ -76,7 +76,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); @@ -85,23 +85,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 +} // namespace OHOS::Ace diff --git a/frameworks/core/components/multimodal/flutter_render_multimodal.h b/frameworks/core/components/multimodal/flutter_render_multimodal.h index 9e3df1c788ba291b2161864fd36dea4967cb246d..2c5650ee09f7757870c9a161532ba039c71f3e22 100644 --- a/frameworks/core/components/multimodal/flutter_render_multimodal.h +++ b/frameworks/core/components/multimodal/flutter_render_multimodal.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MULTIMODAL_FLUTTER_RENDER_MULTIMODAL_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MULTIMODAL_FLUTTER_RENDER_MULTIMODAL_H -#include "flutter/third_party/txt/src/txt/paragraph.h" +#include "rosen_text/typography.h" #include "core/components/multimodal/render_multimodal.h" @@ -31,7 +31,7 @@ public: private: void UpdateParagraph(const Offset& offset, const std::string& text); - std::unique_ptr paragraph_; + std::unique_ptr paragraph_; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/multimodal/rosen_render_multimodal.cpp b/frameworks/core/components/multimodal/rosen_render_multimodal.cpp index 56061ce546d9421efd3342f41662e108de106f39..c140c6d9a3fe83c05fcbd18a1b577f667fa5987a 100644 --- a/frameworks/core/components/multimodal/rosen_render_multimodal.cpp +++ b/frameworks/core/components/multimodal/rosen_render_multimodal.cpp @@ -16,13 +16,12 @@ #include -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" - #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPoint.h" #include "third_party/skia/include/core/SkRRect.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" #include "base/i18n/localization.h" #include "base/utils/string_utils.h" #include "core/components/calendar/rosen_render_calendar.h" @@ -63,8 +62,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 } }; @@ -72,7 +71,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); @@ -81,22 +80,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 +} // namespace OHOS::Ace diff --git a/frameworks/core/components/multimodal/rosen_render_multimodal.h b/frameworks/core/components/multimodal/rosen_render_multimodal.h index 997916287066a4383229b35a24756b1c87c81a41..e1850ab0d43ea59c7256ca291a7248f894d52aae 100644 --- a/frameworks/core/components/multimodal/rosen_render_multimodal.h +++ b/frameworks/core/components/multimodal/rosen_render_multimodal.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MULTIMODAL_ROSEN_RENDER_MULTIMODAL_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MULTIMODAL_ROSEN_RENDER_MULTIMODAL_H -#include "flutter/third_party/txt/src/txt/paragraph.h" +#include "rosen_text/typography.h" #include "core/components/multimodal/render_multimodal.h" namespace OHOS::Ace { @@ -28,7 +28,7 @@ public: private: void UpdateParagraph(const Offset& offset, const std::string& text); - std::unique_ptr paragraph_; + std::unique_ptr paragraph_; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/text/flutter_render_text.cpp b/frameworks/core/components/text/flutter_render_text.cpp index 71f1dc68f429e764822f772ee07c986c9d88628a..28bfbf9dfb0194047802e15b54cad530ecfe1c44 100644 --- a/frameworks/core/components/text/flutter_render_text.cpp +++ b/frameworks/core/components/text/flutter_render_text.cpp @@ -17,8 +17,6 @@ #include -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" #include "unicode/uchar.h" #include "base/geometry/dimension.h" @@ -33,6 +31,8 @@ #include "core/pipeline/base/flutter_render_context.h" #include "core/pipeline/base/scoped_canvas_state.h" #include "core/pipeline/pipeline_context.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography.h" namespace OHOS::Ace { namespace { @@ -358,9 +358,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; } @@ -370,7 +369,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/rosen_render_text.cpp b/frameworks/core/components/text/rosen_render_text.cpp index 5d2a2a23986c117bfd2db9629f2d36558025875f..572329501ca461903c05f20b387ba5c252477a6c 100644 --- a/frameworks/core/components/text/rosen_render_text.cpp +++ b/frameworks/core/components/text/rosen_render_text.cpp @@ -17,8 +17,6 @@ #include -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" #include "render_service_client/core/ui/rs_node.h" #include "unicode/uchar.h" @@ -34,6 +32,8 @@ #include "core/components/text_span/rosen_render_text_span.h" #include "core/pipeline/base/rosen_render_context.h" #include "core/pipeline/pipeline_context.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography.h" namespace OHOS::Ace { namespace { @@ -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() @@ -439,9 +438,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); } } @@ -453,7 +451,7 @@ bool RosenRenderText::UpdateParagraph() using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; if (alignment_.has_value()) { textStyle_.SetTextAlign(alignment_.value()); @@ -475,32 +473,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(); @@ -516,9 +513,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; @@ -532,18 +529,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_field/flutter_render_text_field.cpp b/frameworks/core/components/text_field/flutter_render_text_field.cpp index 62a0696489e081510792aae449e732246a75b345..71bd712946fe912c723e888552573cd638df97db 100644 --- a/frameworks/core/components/text_field/flutter_render_text_field.cpp +++ b/frameworks/core/components/text_field/flutter_render_text_field.cpp @@ -17,8 +17,6 @@ #include -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" #include "third_party/skia/include/effects/SkGradientShader.h" #include "unicode/uchar.h" @@ -33,6 +31,8 @@ #include "core/components/font/flutter_font_collection.h" #include "core/pipeline/base/flutter_render_context.h" #include "core/pipeline/base/scoped_canvas_state.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography.h" #if defined(ENABLE_STANDARD_INPUT) #include "core/components/text_field/on_text_changed_listener_impl.h" @@ -182,11 +182,11 @@ void FlutterRenderTextField::PaintSelectCaret(SkCanvas* canvas) int32_t start = selection.GetStart(); int32_t end = selection.GetEnd(); - const auto& boxes = paragraph_->GetRectsForRange(selection.GetStart(), selection.GetEnd(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(selection.GetStart(), selection.GetEnd(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (!boxes.empty()) { Offset startCaretOffset = Offset( - boxes.back().rect.fRight - boxes.front().rect.fLeft, boxes.back().rect.fTop - boxes.front().rect.fTop); + boxes.back().rect_.GetRight() - boxes.front().rect_.GetLeft(), boxes.back().rect_.GetTop() - boxes.front().rect_.GetTop()); if (start >= GetInitIndex() && end >= GetInitIndex()) { startCaretRect_ = caretRect + startCaretOffset; } else { @@ -277,8 +277,8 @@ void FlutterRenderTextField::PaintSelection(SkCanvas* canvas) const void FlutterRenderTextField::DrawSelection(unsigned start, unsigned end, SkCanvas* canvas) const { using namespace Constants; - const auto& boxes = paragraph_->GetRectsForRange( - start, end, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(start, end, + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return; } @@ -291,7 +291,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()); @@ -303,12 +303,12 @@ void FlutterRenderTextField::DrawSelection(unsigned start, unsigned end, SkCanva LOGE("Unknown textinput style"); break; } - auto rect = - SkRect::MakeLTRB(selectionRect.Right(), selectionRect.Top(), selectionRect.Left(), selectionRect.Bottom()); + auto rect = SkRect::MakeLTRB(selectionRect.Right(), selectionRect.Top(), selectionRect.Left(), + selectionRect.Bottom()); - if (box.direction == txt::TextDirection::ltr) { - rect = SkRect::MakeLTRB( - selectionRect.Left(), selectionRect.Top(), selectionRect.Right(), selectionRect.Bottom()); + if (box.direction_ == Rosen::TextDirection::LTR) { + rect = SkRect::MakeLTRB(selectionRect.Left(), selectionRect.Top(), selectionRect.Right(), + selectionRect.Bottom()); } canvas->drawRect(rect, paint); } @@ -357,7 +357,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 { @@ -377,7 +377,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(); + placeholderBuilder->AppendText(StringUtils::Str8ToStr16(placeholder_)); + placeholderParagraph_ = placeholderBuilder->CreateTypography(); placeholderParagraph_->Layout(limitWidth - errorTextWidth); if (textDirection_ == TextDirection::RTL && - LessOrEqual(placeholderParagraph_->GetLongestLine(), innerRect_.Width())) { + LessOrEqual(placeholderParagraph_->GetActualWidth(), innerRect_.Width())) { placeholderParagraph_->Layout(limitWidth); } } @@ -820,7 +819,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. @@ -838,13 +837,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); } @@ -869,24 +868,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; @@ -906,13 +905,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; } @@ -921,33 +920,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; } @@ -962,23 +961,23 @@ double FlutterRenderTextField::GetBoundaryOfParagraph(bool isLeftBoundary) const if (!paragraph_ || GetEditingValue().text.empty()) { return 0.0; } - auto boxes = paragraph_->GetRectsForRange(0, GetEditingValue().GetWideText().length(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary(0, GetEditingValue().GetWideText().length(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return 0.0; } - double leftBoundaryOfParagraph = boxes.front().rect.fLeft; - double rightBoundaryOfParagraph = boxes.front().rect.fLeft; - double bottomBoundaryOfParagraph = boxes.front().rect.fBottom; + double leftBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double rightBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double bottomBoundaryOfParagraph = boxes.front().rect_.GetBottom(); for (const auto& box : boxes) { - if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect.fBottom, bottomBoundaryOfParagraph)) { - bottomBoundaryOfParagraph = box.rect.fBottom; - leftBoundaryOfParagraph = box.rect.fLeft; - rightBoundaryOfParagraph = box.rect.fRight; + if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect_.GetBottom(), bottomBoundaryOfParagraph)) { + bottomBoundaryOfParagraph = box.rect_.GetBottom(); + leftBoundaryOfParagraph = box.rect_.GetLeft(); + rightBoundaryOfParagraph = box.rect_.GetRight(); continue; } - leftBoundaryOfParagraph = std::min(static_cast(box.rect.fLeft), leftBoundaryOfParagraph); - rightBoundaryOfParagraph = std::max(static_cast(box.rect.fRight), rightBoundaryOfParagraph); + leftBoundaryOfParagraph = std::min(static_cast(box.rect_.GetLeft()), leftBoundaryOfParagraph); + rightBoundaryOfParagraph = std::max(static_cast(box.rect_.GetRight()), rightBoundaryOfParagraph); } return isLeftBoundary ? leftBoundaryOfParagraph : rightBoundaryOfParagraph; } @@ -998,18 +997,18 @@ bool FlutterRenderTextField::ComputeOffsetForCaretUpstream(int32_t extent, Caret result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !GetEditingValue().text.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { return false; @@ -1021,22 +1020,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; } @@ -1049,24 +1048,24 @@ bool FlutterRenderTextField::ComputeOffsetForCaretDownstream(int32_t extent, Car result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - extent, next, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + extent, next, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return false; } const auto& textBox = *boxes.begin(); - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fLeft : textBox.rect.fRight; + double caretStart = isLtr ? textBox.rect_.GetLeft() : textBox.rect_.GetRight(); if (cursorPositionType_ == CursorPositionType::END) { caretStart = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretStart : caretStart - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -1125,23 +1124,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(); } @@ -1165,10 +1164,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,10 +1174,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) @@ -1196,7 +1191,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) @@ -1205,7 +1200,7 @@ int32_t FlutterRenderTextField::AdjustCursorAndSelection(int32_t currentCursorPo // Place cursor to the right boundary of paragraph when direction is LTR, // place to the left boundary of paragraph when direction is RTL. auto paragraphStyle = CreateParagraphStyle(); - std::unique_ptr txtStyle; + std::unique_ptr txtStyle; MeasureParagraph(paragraphStyle, txtStyle); Rect tempRect; GetCaretRect(currentCursorPosition, tempRect); diff --git a/frameworks/core/components/text_field/flutter_render_text_field.h b/frameworks/core/components/text_field/flutter_render_text_field.h index aa95b29856baa6f1d1de7182d3892d21306d851c..11ab67969640d6429d24c9f225db4da0a9b22183 100644 --- a/frameworks/core/components/text_field/flutter_render_text_field.h +++ b/frameworks/core/components/text_field/flutter_render_text_field.h @@ -23,12 +23,12 @@ #include "core/components/text_field/render_text_field.h" #include "core/pipeline/layers/clip_layer.h" -namespace txt { +namespace OHOS::Rosen { class FontCollection; -class Paragraph; -class ParagraphStyle; -class TextStyle; -} // namespace txt +class Typography; +struct TypographyStyle; +struct TextStyle; +} // namespace OHOS::Rosen namespace flutter { class Canvas; @@ -74,8 +74,8 @@ protected: void ResetStatus() override; private: - std::unique_ptr CreateParagraphStyle(bool isErrorText = false); - std::unique_ptr CreateTextStyle(const TextStyle& style, bool isPlaceholder = false); + std::unique_ptr CreateParagraphStyle(bool isErrorText = false); + std::unique_ptr CreateTextStyle(const TextStyle& style, bool isPlaceholder = false); double PreferredLineHeight() override; void UpdateCaretProto(); @@ -87,7 +87,7 @@ private: Offset MakeEmptyOffset() const; Size Measure() override; double MeasureParagraph( - const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle); + const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle); Size ComputeLayoutSize(const Size& size, double decorationHeight); Rect GetInnerRect(const Decoration& decoration, const Rect& outer, double dipScale) const; @@ -96,10 +96,10 @@ private: void ComputeOffsetAfterLayout(); // Compute the offset to align text and icon to vertical center. Offset ComputeVerticalOffsetForCenter(double outerHeight, double innerHeight) const; - void SetShaderIfNeeded(std::unique_ptr paragraphStyle, - std::unique_ptr txtStyle, double textAreaWidth); + void SetShaderIfNeeded(std::unique_ptr paragraphStyle, + std::unique_ptr txtStyle, double textAreaWidth); sk_sp MakeGradientShader(double shadeWidth) const; - std::shared_ptr GetFontCollection(); + std::shared_ptr GetFontCollection(); void ResetParagraphIfNeeded(); void ComputeExtendHeight(double decorationHeight); double GetBoundaryOfParagraph(bool isLeftBoundary) const; @@ -127,12 +127,12 @@ private: SkVector GetSkRadii(const Radius& radius) const; void PaintFocus(const Offset& offset, const Size& widthHeight, RenderContext& context); - std::unique_ptr paragraph_; - std::unique_ptr errorParagraph_; - std::unique_ptr countParagraph_; - std::unique_ptr placeholderParagraph_; + std::unique_ptr paragraph_; + std::unique_ptr errorParagraph_; + std::unique_ptr countParagraph_; + std::unique_ptr placeholderParagraph_; // Used to estimate size. - std::unique_ptr template_; + std::unique_ptr template_; Rect caretRect_; Rect startCaretRect_; diff --git a/frameworks/core/components/text_field/rosen_render_text_field.cpp b/frameworks/core/components/text_field/rosen_render_text_field.cpp index 06ff9448c35f0f74653d7105482842b4e1365c57..0c2985e73f679076e3c431e583062c669055c45c 100644 --- a/frameworks/core/components/text_field/rosen_render_text_field.cpp +++ b/frameworks/core/components/text_field/rosen_render_text_field.cpp @@ -17,8 +17,6 @@ #include -#include "flutter/third_party/txt/src/txt/paragraph_builder.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" #include "unicode/uchar.h" @@ -33,6 +31,8 @@ #include "core/components/font/constants_converter.h" #include "core/components/font/rosen_font_collection.h" #include "core/pipeline/base/rosen_render_context.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography.h" #if defined(ENABLE_STANDARD_INPUT) #include "core/components/text_field/on_text_changed_listener_impl.h" @@ -172,11 +172,11 @@ void RosenRenderTextField::PaintSelectCaret(SkCanvas* canvas) int32_t start = selection.GetStart(); int32_t end = selection.GetEnd(); - const auto& boxes = paragraph_->GetRectsForRange(selection.GetStart(), selection.GetEnd(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(selection.GetStart(), selection.GetEnd(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (!boxes.empty()) { Offset startCaretOffset = Offset( - boxes.back().rect.fRight - boxes.front().rect.fLeft, boxes.back().rect.fTop - boxes.front().rect.fTop); + boxes.back().rect_.GetRight() - boxes.front().rect_.GetLeft(), boxes.back().rect_.GetTop() - boxes.front().rect_.GetTop()); if (start >= GetInitIndex() && end >= GetInitIndex()) { startCaretRect_ = caretRect + startCaretOffset; } else { @@ -263,8 +263,8 @@ void RosenRenderTextField::PaintSelection(SkCanvas* canvas) const if (GetEditingValue().text.empty() || selection.GetStart() == selection.GetEnd()) { return; } - const auto& boxes = paragraph_->GetRectsForRange(selection.GetStart(), selection.GetEnd(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(selection.GetStart(), selection.GetEnd(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return; } @@ -277,7 +277,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()); @@ -292,7 +292,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()); } @@ -323,7 +323,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 { @@ -343,7 +343,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_) { @@ -500,7 +500,7 @@ Size RosenRenderTextField::Measure() } auto paragraphStyle = CreateParagraphStyle(); - std::unique_ptr txtStyle; + std::unique_ptr txtStyle; double textAreaWidth = MeasureParagraph(paragraphStyle, txtStyle); ComputeExtendHeight(decorationHeight); @@ -514,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; @@ -536,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. @@ -572,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(); + placeholderBuilder->AppendText(StringUtils::Str8ToStr16(placeholder_)); + placeholderParagraph_ = placeholderBuilder->CreateTypography(); placeholderParagraph_->Layout(limitWidth - errorTextWidth); if (textDirection_ == TextDirection::RTL && - LessOrEqual(placeholderParagraph_->GetLongestLine(), innerRect_.Width())) { + LessOrEqual(placeholderParagraph_->GetActualWidth(), innerRect_.Width())) { placeholderParagraph_->Layout(limitWidth); } } @@ -748,7 +747,7 @@ sk_sp RosenRenderTextField::MakeGradientShader(double shadeWidth) cons } void RosenRenderTextField::SetShaderIfNeeded( - std::unique_ptr paragraphStyle, std::unique_ptr txtStyle, double textAreaWidth) + std::unique_ptr paragraphStyle, std::unique_ptr txtStyle, double textAreaWidth) { if (maxLines_ != 1 || showPlaceholder_ || !paragraph_ || !needFade_) { // Not support placeHolder or multiline. @@ -766,13 +765,13 @@ void RosenRenderTextField::SetShaderIfNeeded( return; } - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(*paragraphStyle, GetFontCollection()); - txtStyle->has_foreground = true; - txtStyle->foreground.setShader(shader); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(*paragraphStyle, GetFontCollection()); + txtStyle->foreground_ = SkPaint(); + txtStyle->foreground_->setShader(shader); builder->PushStyle(*txtStyle); - builder->AddText(GetTextForDisplay(GetEditingValue().text)); - paragraph_ = builder->Build(); + builder->AppendText(GetTextForDisplay(GetEditingValue().text)); + paragraph_ = builder->CreateTypography(); paragraph_->Layout(textAreaWidth); } @@ -797,24 +796,24 @@ Size RosenRenderTextField::ComputeLayoutSize(const Size& size, double decoration return Size(maxWidth, innerRect_.Height() + decorationHeight); } -std::unique_ptr RosenRenderTextField::CreateParagraphStyle(bool isErrorText) +std::unique_ptr RosenRenderTextField::CreateParagraphStyle(bool isErrorText) { using namespace Constants; - auto style = std::make_unique(); + auto style = std::make_unique(); // If single-line, it shouldn't do soft-wrap for us. if (maxLines_ == 1 && resetToStart_) { - style->max_lines = 1; + style->maxLines_ = 1; if (showEllipsis_ && keyboard_ != TextInputType::VISIBLE_PASSWORD) { - style->ellipsis = StringUtils::Str8ToStr16(ELLIPSIS); + style->ellipsis_ = StringUtils::Str8ToStr16(ELLIPSIS); } } - style->text_align = ConvertTxtTextAlign(textAlign_); - style->font_size = NormalizeToPx(style_.GetFontSize()); + style->textAlign_ = ConvertTxtTextAlign(textAlign_); + style->fontSize_ = NormalizeToPx(style_.GetFontSize()); // If keyboard is password, don't change text_direction with first strong direction letter if (!isErrorText && keyboard_ == TextInputType::VISIBLE_PASSWORD && !GetEditingValue().text.empty()) { - style->text_direction = ConvertTxtTextDirection(textDirection_); + style->textDirection_ = ConvertTxtTextDirection(textDirection_); realTextDirection_ = textDirection_; UpdateDirectionStatus(); return style; @@ -834,13 +833,13 @@ std::unique_ptr RosenRenderTextField::CreateParagraphStyle( for (const auto& charOfShowingText : showingTextForWString) { auto charDirection = u_charDirection(charOfShowingText); if (charDirection == UCharDirection::U_LEFT_TO_RIGHT) { - style->text_direction = ConvertTxtTextDirection(TextDirection::LTR); + style->textDirection_ = ConvertTxtTextDirection(TextDirection::LTR); existStrongDirectionLetter_ = true; realTextDirection_ = TextDirection::LTR; } else if (charDirection == UCharDirection::U_RIGHT_TO_LEFT || charDirection == UCharDirection::U_RIGHT_TO_LEFT_ARABIC || charDirection == UCharDirection::U_ARABIC_NUMBER) { - style->text_direction = ConvertTxtTextDirection(TextDirection::RTL); + style->textDirection_ = ConvertTxtTextDirection(TextDirection::RTL); existStrongDirectionLetter_ = true; realTextDirection_ = TextDirection::RTL; } @@ -849,33 +848,33 @@ std::unique_ptr RosenRenderTextField::CreateParagraphStyle( } } if (!existStrongDirectionLetter_) { - style->text_direction = ConvertTxtTextDirection(textDirection_); + style->textDirection_ = ConvertTxtTextDirection(textDirection_); realTextDirection_ = textDirection_; } UpdateDirectionStatus(); if (keyboard_ != TextInputType::MULTILINE) { - style->word_break_type = minikin::WordBreakType::kWordBreakType_BreakAll; + style->wordBreakType_ = Rosen::WordBreakType::BREAKALL; } return style; } -std::unique_ptr RosenRenderTextField::CreateTextStyle(const TextStyle& style, bool isPlaceholder) +std::unique_ptr RosenRenderTextField::CreateTextStyle(const TextStyle& style, bool isPlaceholder) { using namespace Constants; - auto txtStyle = std::make_unique(); + auto txtStyle = std::make_unique(); if (isPlaceholder) { - txtStyle->color = ConvertSkColor(placeholderColor_); + txtStyle->color_ = ConvertSkColor(placeholderColor_); } else { - txtStyle->color = ConvertSkColor(style.GetTextColor()); + txtStyle->color_ = ConvertSkColor(style.GetTextColor()); } - txtStyle->font_families = style.GetFontFamilies(); - txtStyle->font_weight = ConvertTxtFontWeight(style.GetFontWeight()); - txtStyle->font_size = NormalizeToPx(style.GetFontSize()); - txtStyle->font_style = ConvertTxtFontStyle(style.GetFontStyle()); - txtStyle->text_baseline = ConvertTxtTextBaseline(style.GetTextBaseline()); - txtStyle->locale = Localization::GetInstance()->GetFontLocale(); + txtStyle->fontFamilies_ = style.GetFontFamilies(); + txtStyle->fontWeight_ = ConvertTxtFontWeight(style.GetFontWeight()); + txtStyle->fontSize_ = NormalizeToPx(style.GetFontSize()); + txtStyle->fontStyle_ = ConvertTxtFontStyle(style.GetFontStyle()); + txtStyle->baseline_ = ConvertTxtTextBaseline(style.GetTextBaseline()); + txtStyle->locale_ = Localization::GetInstance()->GetFontLocale(); return txtStyle; } @@ -890,23 +889,23 @@ double RosenRenderTextField::GetBoundaryOfParagraph(bool isLeftBoundary) const if (!paragraph_ || GetEditingValue().text.empty()) { return 0.0; } - auto boxes = paragraph_->GetRectsForRange(0, GetEditingValue().GetWideText().length(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary(0, GetEditingValue().GetWideText().length(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return 0.0; } - double leftBoundaryOfParagraph = boxes.front().rect.fLeft; - double rightBoundaryOfParagraph = boxes.front().rect.fLeft; - double bottomBoundaryOfParagraph = boxes.front().rect.fBottom; + double leftBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double rightBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double bottomBoundaryOfParagraph = boxes.front().rect_.GetBottom(); for (const auto& box : boxes) { - if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect.fBottom, bottomBoundaryOfParagraph)) { - bottomBoundaryOfParagraph = box.rect.fBottom; - leftBoundaryOfParagraph = box.rect.fLeft; - rightBoundaryOfParagraph = box.rect.fRight; + if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect_.GetBottom(), bottomBoundaryOfParagraph)) { + bottomBoundaryOfParagraph = box.rect_.GetBottom(); + leftBoundaryOfParagraph = box.rect_.GetLeft(); + rightBoundaryOfParagraph = box.rect_.GetRight(); continue; } - leftBoundaryOfParagraph = std::min(static_cast(box.rect.fLeft), leftBoundaryOfParagraph); - rightBoundaryOfParagraph = std::max(static_cast(box.rect.fRight), rightBoundaryOfParagraph); + leftBoundaryOfParagraph = std::min(static_cast(box.rect_.GetLeft()), leftBoundaryOfParagraph); + rightBoundaryOfParagraph = std::max(static_cast(box.rect_.GetRight()), rightBoundaryOfParagraph); } return isLeftBoundary ? leftBoundaryOfParagraph : rightBoundaryOfParagraph; } @@ -926,18 +925,18 @@ bool RosenRenderTextField::ComputeOffsetForCaretUpstream(int32_t extent, CaretMe result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !GetEditingValue().text.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { return false; @@ -949,22 +948,22 @@ bool RosenRenderTextField::ComputeOffsetForCaretUpstream(int32_t extent, CaretMe // Return the start of next line. auto emptyOffset = MakeEmptyOffset(); result.offset.SetX(emptyOffset.GetX()); - result.offset.SetY(textBox.rect.fBottom); + result.offset.SetY(textBox.rect_.GetBottom()); result.height = caretProto_.Height(); return true; } - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the upstream glyphs. - double caretEnd = isLtr ? textBox.rect.fRight : textBox.rect.fLeft; + double caretEnd = isLtr ? textBox.rect_.GetRight() : textBox.rect_.GetLeft(); if (cursorPositionType_ == CursorPositionType::END) { caretEnd = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretEnd : caretEnd - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -977,24 +976,24 @@ bool RosenRenderTextField::ComputeOffsetForCaretDownstream(int32_t extent, Caret result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - extent, next, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + extent, next, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return false; } const auto& textBox = *boxes.begin(); - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fLeft : textBox.rect.fRight; + double caretStart = isLtr ? textBox.rect_.GetLeft() : textBox.rect_.GetRight(); if (cursorPositionType_ == CursorPositionType::END) { caretStart = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretStart : caretStart - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -1053,23 +1052,23 @@ Offset RosenRenderTextField::MakeEmptyOffset() const double RosenRenderTextField::PreferredLineHeight() { if (!template_) { - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(*CreateParagraphStyle(), GetFontCollection()); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(*CreateParagraphStyle(), GetFontCollection()); builder->PushStyle(*CreateTextStyle(style_)); // Use a space for estimating line height if there is no placeholder. // Actually it has slight differ between cases. if (placeholder_.empty()) { - builder->AddText(u" "); + builder->AppendText(u" "); } else { - builder->AddText(StringUtils::Str8ToStr16(placeholder_)); + builder->AppendText(StringUtils::Str8ToStr16(placeholder_)); } - template_ = builder->Build(); + template_ = builder->CreateTypography(); template_->Layout(Size::INFINITE_SIZE); } return template_->GetHeight(); } -std::shared_ptr RosenRenderTextField::GetFontCollection() +std::shared_ptr RosenRenderTextField::GetFontCollection() { return RosenFontCollection::GetInstance().GetFontCollection(); } @@ -1093,10 +1092,8 @@ int32_t RosenRenderTextField::GetCursorPositionForMoveUp() return 0; } double verticalOffset = -textOffsetForShowCaret_.GetY() - PreferredLineHeight(); - return static_cast(paragraph_ - ->GetGlyphPositionAtCoordinateWithCluster( - caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset) - .position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate( + caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).index_); } int32_t RosenRenderTextField::GetCursorPositionForMoveDown() @@ -1105,10 +1102,8 @@ int32_t RosenRenderTextField::GetCursorPositionForMoveDown() return 0; } double verticalOffset = -textOffsetForShowCaret_.GetY() + PreferredLineHeight(); - return static_cast(paragraph_ - ->GetGlyphPositionAtCoordinateWithCluster( - caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset) - .position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate( + caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).index_); } int32_t RosenRenderTextField::GetCursorPositionForClick(const Offset& offset) @@ -1124,7 +1119,7 @@ int32_t RosenRenderTextField::GetCursorPositionForClick(const Offset& offset) return 0; } return static_cast( - paragraph_->GetGlyphPositionAtCoordinateWithCluster(clickOffset_.GetX(), clickOffset_.GetY()).position); + paragraph_->GetGlyphIndexByCoordinate(clickOffset_.GetX(), clickOffset_.GetY()).index_); } int32_t RosenRenderTextField::AdjustCursorAndSelection(int32_t currentCursorPosition) @@ -1133,7 +1128,7 @@ int32_t RosenRenderTextField::AdjustCursorAndSelection(int32_t currentCursorPosi // Place cursor to the right boundary of paragraph when direction is LTR, // place to the left boundary of paragraph when direction is RTL. auto paragraphStyle = CreateParagraphStyle(); - std::unique_ptr txtStyle; + std::unique_ptr txtStyle; MeasureParagraph(paragraphStyle, txtStyle); Rect tempRect; GetCaretRect(currentCursorPosition, tempRect); diff --git a/frameworks/core/components/text_field/rosen_render_text_field.h b/frameworks/core/components/text_field/rosen_render_text_field.h index 64d788f1ea2c20c1459068430abc9c6caaee4e73..56e790d8d95c518cb1ef3abddc1861e8f2ce4afd 100644 --- a/frameworks/core/components/text_field/rosen_render_text_field.h +++ b/frameworks/core/components/text_field/rosen_render_text_field.h @@ -19,18 +19,20 @@ #include #include -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/font_collection.h" +#include "rosen_text/typography.h" +#include "rosen_text/typography_style.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" #include "core/components/common/properties/decoration.h" #include "core/components/text_field/render_text_field.h" -namespace txt { +namespace OHOS::Rosen { class FontCollection; -class ParagraphStyle; -class TextStyle; -} // namespace txt +struct TypographyStyle; +struct TextStyle; +} // namespace OHOS::Rosen namespace OHOS::Ace { class Component; @@ -70,8 +72,8 @@ protected: void ResetStatus() override; private: - std::unique_ptr CreateParagraphStyle(bool isErrorText = false); - std::unique_ptr CreateTextStyle(const TextStyle& style, bool isPlaceholder = false); + std::unique_ptr CreateParagraphStyle(bool isErrorText = false); + std::unique_ptr CreateTextStyle(const TextStyle& style, bool isPlaceholder = false); double PreferredLineHeight() override; void UpdateCaretProto(); @@ -83,7 +85,7 @@ private: Offset MakeEmptyOffset() const; Size Measure() override; double MeasureParagraph( - const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle); + const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle); Size ComputeLayoutSize(const Size& size, double decorationHeight); Rect GetInnerRect(const Decoration& decoration, const Rect& outer, double dipScale) const; @@ -92,10 +94,10 @@ private: void ComputeOffsetAfterLayout(); // Compute the offset to align text and icon to vertical center. Offset ComputeVerticalOffsetForCenter(double outerHeight, double innerHeight) const; - void SetShaderIfNeeded(std::unique_ptr paragraphStyle, - std::unique_ptr txtStyle, double textAreaWidth); + void SetShaderIfNeeded(std::unique_ptr paragraphStyle, + std::unique_ptr txtStyle, double textAreaWidth); sk_sp MakeGradientShader(double shadeWidth) const; - std::shared_ptr GetFontCollection(); + std::shared_ptr GetFontCollection(); void ResetParagraphIfNeeded(); void ComputeExtendHeight(double decorationHeight); double GetBoundaryOfParagraph(bool isLeftBoundary) const; @@ -119,12 +121,12 @@ private: SkVector GetSkRadii(const Radius& radius) const; void PaintFocus(const Offset& offset, const Size& widthHeight, RenderContext& context); - std::unique_ptr paragraph_; - std::unique_ptr errorParagraph_; - std::unique_ptr countParagraph_; - std::unique_ptr placeholderParagraph_; + std::unique_ptr paragraph_; + std::unique_ptr errorParagraph_; + std::unique_ptr countParagraph_; + std::unique_ptr placeholderParagraph_; // Used to estimate size. - std::unique_ptr template_; + std::unique_ptr template_; Rect startCaretRect_; Size lastLayoutSize_; diff --git a/frameworks/core/components/text_overlay/text_overlay_manager.cpp b/frameworks/core/components/text_overlay/text_overlay_manager.cpp index 6f24b9565858878ad4a86245276495de6aae5310..aff4aa043568efceacd6ccd94bea02be0865744a 100644 --- a/frameworks/core/components/text_overlay/text_overlay_manager.cpp +++ b/frameworks/core/components/text_overlay/text_overlay_manager.cpp @@ -21,8 +21,9 @@ #include "core/components/font/constants_converter.h" #include "core/components/stack/stack_element.h" #include "core/components/text_overlay/text_overlay_component.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" +#include "rosen_text/typography.h" #include "third_party/skia/include/core/SkCanvas.h" +#include "unicode/uchar.h" namespace OHOS::Ace { @@ -83,23 +84,23 @@ double TextOverlayBase::GetBoundaryOfParagraph(bool isLeftBoundary) const if (!paragraph_ || textValue_.text.empty()) { return 0.0; } - auto boxes = paragraph_->GetRectsForRange(0, textValue_.GetWideText().length(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary(0, textValue_.GetWideText().length(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return 0.0; } - double leftBoundaryOfParagraph = boxes.front().rect.fLeft; - double rightBoundaryOfParagraph = boxes.front().rect.fLeft; - double bottomBoundaryOfParagraph = boxes.front().rect.fBottom; + double leftBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double rightBoundaryOfParagraph = boxes.front().rect_.GetLeft(); + double bottomBoundaryOfParagraph = boxes.front().rect_.GetBottom(); for (const auto& box : boxes) { - if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect.fBottom, bottomBoundaryOfParagraph)) { - bottomBoundaryOfParagraph = box.rect.fBottom; - leftBoundaryOfParagraph = box.rect.fLeft; - rightBoundaryOfParagraph = box.rect.fRight; + if (cursorPositionType_ == CursorPositionType::END && !NearEqual(box.rect_.GetBottom(), bottomBoundaryOfParagraph)) { + bottomBoundaryOfParagraph = box.rect_.GetBottom(); + leftBoundaryOfParagraph = box.rect_.GetLeft(); + rightBoundaryOfParagraph = box.rect_.GetRight(); continue; } - leftBoundaryOfParagraph = std::min(static_cast(box.rect.fLeft), leftBoundaryOfParagraph); - rightBoundaryOfParagraph = std::max(static_cast(box.rect.fRight), rightBoundaryOfParagraph); + leftBoundaryOfParagraph = std::min(static_cast(box.rect_.GetLeft()), leftBoundaryOfParagraph); + rightBoundaryOfParagraph = std::max(static_cast(box.rect_.GetRight()), rightBoundaryOfParagraph); } return isLeftBoundary ? leftBoundaryOfParagraph : rightBoundaryOfParagraph; } @@ -119,18 +120,18 @@ bool TextOverlayBase::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !textValue_.text.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { return false; @@ -142,22 +143,22 @@ bool TextOverlayBase::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics // Return the start of next line. auto emptyOffset = MakeEmptyOffset(); result.offset.SetX(emptyOffset.GetX()); - result.offset.SetY(textBox.rect.fBottom); + result.offset.SetY(textBox.rect_.GetBottom()); result.height = caretProto_.Height(); return true; } - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the upstream glyphs. - double caretEnd = isLtr ? textBox.rect.fRight : textBox.rect.fLeft; + double caretEnd = isLtr ? textBox.rect_.GetRight() : textBox.rect_.GetLeft(); if (cursorPositionType_ == CursorPositionType::END) { caretEnd = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretEnd : caretEnd - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -171,24 +172,24 @@ bool TextOverlayBase::ComputeOffsetForCaretDownstream(int32_t extent, CaretMetri result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - extent, next, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + extent, next, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return false; } const auto& textBox = *boxes.begin(); - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fLeft : textBox.rect.fRight; + double caretStart = isLtr ? textBox.rect_.GetLeft() : textBox.rect_.GetRight(); if (cursorPositionType_ == CursorPositionType::END) { caretStart = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretStart : caretStart - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -281,13 +282,13 @@ int32_t TextOverlayBase::GetCursorPositionForClick(const Offset& offset, const O double rightBoundary = GetBoundaryOfParagraph(false); if (GreatOrEqual(clickOffset_.GetX(), rightBoundary)) { int32_t rightBoundaryPosition = - static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster( - rightBoundary - cursorWidth_, clickOffset_.GetY()).position); + static_cast(paragraph_->GetGlyphIndexByCoordinate( + rightBoundary - cursorWidth_, clickOffset_.GetY()).index_); return realTextDirection_ == TextDirection::RTL ? 0 : rightBoundaryPosition; } return static_cast( - paragraph_->GetGlyphPositionAtCoordinate(clickOffset_.GetX(), clickOffset_.GetY()).position); + paragraph_->GetGlyphIndexByCoordinate(clickOffset_.GetX(), clickOffset_.GetY()).index_); } int32_t TextOverlayBase::GetGraphemeClusterLength(int32_t extend, bool isPrefix) const @@ -367,8 +368,8 @@ void TextOverlayBase::PaintSelection(SkCanvas* canvas, const Offset& globalOffse if (textValue_.text.empty() || selection.GetStart() == selection.GetEnd()) { return; } - const auto& boxes = paragraph_->GetRectsForRange(selection.GetStart(), selection.GetEnd(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(selection.GetStart(), selection.GetEnd(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return; } @@ -377,9 +378,9 @@ void TextOverlayBase::PaintSelection(SkCanvas* canvas, const Offset& globalOffse paint.setColor(selectedColor_.GetValue()); Offset effectiveOffset = textOffsetForShowCaret_; for (const auto& box : boxes) { - auto selectionRect = ConvertSkRect(box.rect) + effectiveOffset; + auto selectionRect = ConvertSkRect(box.rect_) + effectiveOffset; selectedRect_.emplace_back(selectionRect + globalOffset); - if (box.direction == txt::TextDirection::ltr) { + if (box.direction_ == Rosen::TextDirection::LTR) { canvas->drawRect(SkRect::MakeLTRB(selectionRect.Left(), selectionRect.Top(), selectionRect.Right(), selectionRect.Bottom()), paint); diff --git a/frameworks/core/components/text_overlay/text_overlay_manager.h b/frameworks/core/components/text_overlay/text_overlay_manager.h index 5f9f17ca8ad8bebf884d616fa60a39d0c7dac7e5..b14417d4781ae005b52373c6a8c1ffe9fc868be2 100644 --- a/frameworks/core/components/text_overlay/text_overlay_manager.h +++ b/frameworks/core/components/text_overlay/text_overlay_manager.h @@ -24,8 +24,8 @@ #include "frameworks/core/common/ime/text_editing_value.h" #include "frameworks/core/pipeline/base/overlay_show_option.h" -namespace txt { -class Paragraph; +namespace OHOS::Rosen { +class Typography; } class SkCanvas; @@ -142,7 +142,7 @@ public: bool IsSelectedText(const Offset& pos, const Offset& globalOffset); protected: - std::shared_ptr paragraph_; + std::shared_ptr paragraph_; CursorPositionType cursorPositionType_ = CursorPositionType::NORMAL; DirectionStatus directionStatus_ = DirectionStatus::LEFT_LEFT; Offset clickOffset_; diff --git a/frameworks/core/components/text_span/flutter_render_text_span.cpp b/frameworks/core/components/text_span/flutter_render_text_span.cpp index 60cb2b35037c805283af3eab0a8d2964f612c62e..0b6ede8372ba036bbe463bb50441df50bcf2def1 100644 --- a/frameworks/core/components/text_span/flutter_render_text_span.cpp +++ b/frameworks/core/components/text_span/flutter_render_text_span.cpp @@ -21,7 +21,7 @@ namespace OHOS::Ace { -void FlutterRenderTextSpan::UpdateText(txt::ParagraphBuilder& builder, +void FlutterRenderTextSpan::UpdateText(Rosen::TypographyCreate& builder, std::map>& touchRegions, std::string& textValue) { if (!spanComponent_) { @@ -34,14 +34,14 @@ void FlutterRenderTextSpan::UpdateText(txt::ParagraphBuilder& builder, } if (spanComponent_->HasNewStyle()) { LOGD("test span has new style"); - txt::TextStyle style; + Rosen::TextStyle style; Constants::ConvertTxtStyle(spanStyle_, context_, style); builder.PushStyle(style); } UpdateTouchRegions(touchRegions); auto displayText = spanComponent_->GetSpanData(); StringUtils::TransformStrCase(displayText, (int32_t)spanStyle_.GetTextCase()); - builder.AddText(StringUtils::Str8ToStr16(displayText)); + builder.AppendText(StringUtils::Str8ToStr16(displayText)); textValue.append(displayText); for (const auto& child : GetChildren()) { auto flutterRenderTextSpan = AceType::DynamicCast(child); @@ -50,7 +50,7 @@ void FlutterRenderTextSpan::UpdateText(txt::ParagraphBuilder& builder, } } if (spanComponent_->HasNewStyle()) { - builder.Pop(); + builder.PopStyle(); } } diff --git a/frameworks/core/components/text_span/flutter_render_text_span.h b/frameworks/core/components/text_span/flutter_render_text_span.h index 809777e2ba8c50c24bcb6ebebf86950f44c901a2..272fc55a2d8817a6628e7c8a464e0f58e9c52e4b 100644 --- a/frameworks/core/components/text_span/flutter_render_text_span.h +++ b/frameworks/core/components/text_span/flutter_render_text_span.h @@ -16,8 +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/third_party/txt/src/txt/paragraph_builder.h" - +#include "rosen_text/typography_create.h" #include "core/components/text_span/render_text_span.h" #include "core/gestures/gesture_type.h" #include "core/pipeline/base/render_node.h" @@ -32,7 +31,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 73307767fd63d021b8b2215bc9b3a3636a3a4cb5..aa308d979a7d5b736860f9a9c31ede13c87adab2 100644 --- a/frameworks/core/components/text_span/rosen_render_text_span.cpp +++ b/frameworks/core/components/text_span/rosen_render_text_span.cpp @@ -24,7 +24,7 @@ namespace OHOS::Ace { -void RosenRenderTextSpan::UpdateText(txt::ParagraphBuilder& builder, +void RosenRenderTextSpan::UpdateText(Rosen::TypographyCreate& builder, std::map>& touchRegions, std::string& textValue) { if (!spanComponent_) { @@ -37,14 +37,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); @@ -53,7 +53,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 7546050e2c6bec2707c6a313f0f7b7f6be34fdd3..57ed5a8a6cc6feecf5805925210f115e0cc768c1 100644 --- a/frameworks/core/components/text_span/rosen_render_text_span.h +++ b/frameworks/core/components/text_span/rosen_render_text_span.h @@ -16,8 +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/third_party/txt/src/txt/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 +30,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 e069e663e09e38f92ba0b9e519e6aece093110b3..4b539c29ec8092e33c0a1e10d7151694fc3bebe8 100644 --- a/frameworks/core/components/track/flutter_render_arc_track.cpp +++ b/frameworks/core/components/track/flutter_render_arc_track.cpp @@ -17,11 +17,11 @@ #include "flutter/lib/ui/painting/path.h" #include "third_party/skia/include/core/SkClipOp.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" #include "core/components/font/flutter_font_collection.h" #include "core/pipeline/base/scoped_canvas_state.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography.h" namespace OHOS::Ace { namespace { @@ -76,20 +76,20 @@ void SetTextStyle(const ScopedCanvas& canvas, const RenderRingInfo& trackInfo, c } 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, const std::string markedText, diff --git a/frameworks/core/components/track/rosen_render_arc_track.cpp b/frameworks/core/components/track/rosen_render_arc_track.cpp index ba425682577702f32651514cc2ab793613ca2ba0..f1c7836fc68c2d397c5e37f0d66cec94203ea274 100644 --- a/frameworks/core/components/track/rosen_render_arc_track.cpp +++ b/frameworks/core/components/track/rosen_render_arc_track.cpp @@ -19,11 +19,11 @@ #include "third_party/skia/include/core/SkClipOp.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPath.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_txt.h" #include "core/components/font/rosen_font_collection.h" #include "core/pipeline/base/rosen_render_context.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography.h" namespace OHOS::Ace { namespace { @@ -77,19 +77,19 @@ void SetTextStyle(SkCanvas* canvas, const RenderRingInfo& trackInfo, const std:: } double pathStartVertexX = trackInfo.center.GetX(); double pathStartVertexY = trackInfo.center.GetY() - trackInfo.radius + (trackInfo.thickness / 2); - txt::ParagraphStyle style; - txt::TextStyle txtStyle; - txtStyle.font_size = 80; - txtStyle.font_weight = txt::FontWeight::w400; - txtStyle.color = markedColor.GetValue(); - std::unique_ptr builder; - style.max_lines = 1; - builder = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection); + Rosen::TypographyStyle style; + Rosen::TextStyle txtStyle; + txtStyle.fontSize_ = 80; + txtStyle.fontWeight_ = Rosen::FontWeight::W400; + txtStyle.color_ = markedColor.GetValue(); + std::unique_ptr builder; + style.maxLines_ = 1; + builder = Rosen::TypographyCreate::Create(style, fontCollection); builder->PushStyle(txtStyle); - builder->AddText(StringUtils::Str8ToStr16(markedText)); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(markedText)); + auto paragraph = builder->CreateTypography(); paragraph->Layout(dataRegion.Width()); - paragraph->Paint(canvas, pathStartVertexX - txtStyle.font_size, pathStartVertexY + EDGE + HEIGHT_OFFSET * 2); + paragraph->Paint(canvas, pathStartVertexX - txtStyle.fontSize_, pathStartVertexY + EDGE + HEIGHT_OFFSET * 2); } void DrawIndicator(RenderContext& context, const RenderRingInfo& trackInfo, const std::string& markedText, diff --git a/frameworks/core/components_ng/components.gni b/frameworks/core/components_ng/components.gni index e4712fcdccf20d2c0e3bd2f128437389f5e8f44d..085d729368329c55bfa3ff23b667979693674bdf 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 += [ @@ -110,6 +111,7 @@ template("build_component_ng") { "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", "//foundation/graphic/graphic_2d/rosen/modules/2d_engine", "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text/export", "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include", "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src", "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src/drawing/engine_adapter", 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 25ccbfb7275d9af03c8b9be7dc437043d70d5a97..a28cb6219f2c2cc87c748c80e203dfe30464f118 100644 --- a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp @@ -39,15 +39,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 = RSFontCollection::Create(); 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 +135,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(); @@ -183,7 +183,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(RSPoint(static_cast(bgCircleStart.GetX()), static_cast(bgCircleStart.GetY())), static_cast(focusedAreaRadius_)); } @@ -198,33 +198,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(RSPoint(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_, @@ -259,7 +259,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); @@ -268,7 +268,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(); @@ -415,4 +415,4 @@ bool CalendarPaintMethod::IsOffDay(const CalendarDay& dayInfo) const return false; } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.h b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.h index cb305a6b391e20556d6cfb2c526d79a74495ec7b..d52e5cf61439ba33e1954523fc88c3221720060b 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; 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 6f4e97997da316523d7160936036a0d79a25ec19..105226ef49230cb9fd95a2593a92d33844fc2823 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 @@ -16,8 +16,6 @@ #include "core/components_ng/pattern/custom_paint/canvas_paint_method.h" #include "drawing/engine_adapter/skia_adapter/skia_canvas.h" -#include "flutter/third_party/txt/src/txt/paragraph_builder.h" -#include "flutter/third_party/txt/src/txt/paragraph_style.h" #include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/encode/SkJpegEncoder.h" #include "third_party/skia/include/encode/SkPngEncoder.h" @@ -34,6 +32,8 @@ #include "core/components_ng/image_provider/image_object.h" #include "core/components_ng/render/drawing.h" #include "core/image/flutter_image_cache.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" namespace OHOS::Ace::NG { namespace { @@ -328,17 +328,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(); } @@ -346,17 +346,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(); } @@ -365,17 +365,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(); @@ -415,7 +415,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; @@ -442,7 +442,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) { @@ -474,58 +474,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 { @@ -533,7 +531,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()); } @@ -542,8 +540,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 7c4f32117c25ab87e80a3df7a5ea31b0b47814e0..c088a3df36ce816d722a4573f349f8455f8af872 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 @@ -19,6 +19,8 @@ #include "core/components_ng/pattern/custom_paint/custom_paint_paint_method.h" #include "core/components_ng/pattern/custom_paint/offscreen_canvas_pattern.h" +#include "rosen_text/text_style.h" + namespace OHOS::Ace::NG { class CanvasPaintMethod; using TaskFunc = std::function; @@ -81,10 +83,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 fa571aeac9e65b4a211c5aafbceb412ceaf40db7..809cae1e55be10ef65efd587ba7482e8156c26e4 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,7 +17,6 @@ #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/SkCanvas.h" #include "third_party/skia/include/core/SkPath.h" @@ -29,6 +28,7 @@ #include "core/image/image_object.h" #include "core/image/image_source_info.h" #include "core/pipeline_ng/pipeline_context.h" +#include "rosen_text/typography.h" namespace OHOS::Ace::NG { class CustomPaintPaintMethod : public NodePaintMethod { @@ -293,7 +293,7 @@ protected: std::string smoothingQuality_ = "low"; bool antiAlias_ = false; Shadow shadow_; - std::unique_ptr paragraph_; + std::unique_ptr paragraph_; WeakPtr 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 b23898621d4c0b2124d26cb67cb3a4e11bed386a..288947aa7af01c837b2448875eed3304f48cb616 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,13 @@ #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 "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" @@ -33,6 +32,8 @@ #include "core/components/font/constants_converter.h" #include "core/components/font/flutter_font_collection.h" #include "core/components/font/rosen_font_collection.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" namespace OHOS::Ace::NG { namespace { @@ -626,18 +627,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; + 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(); } @@ -645,18 +646,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(); } @@ -665,18 +666,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(); @@ -714,7 +715,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) { @@ -740,7 +741,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) { @@ -772,64 +773,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()); } @@ -838,8 +837,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; } } @@ -931,4 +929,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 6d17fdaee16f72f4b745e11e586f1f169de17571..61e32f2137fe1c7f55902017351bba6e803bf4b0 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 @@ -18,6 +18,8 @@ #include "core/components_ng/pattern/custom_paint/custom_paint_paint_method.h" +#include "rosen_text/text_style.h" + namespace OHOS::Ace::NG { using setColorFunc = std::function; @@ -75,10 +77,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/text_field/text_field_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp index bd80723d6b390c75368794f592858e788f6c4920..7dda995e10e16d9144101f62ea0aca8c104751fc 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 @@ -103,7 +103,7 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( bool showPlaceHolder = false; auto idealWidth = contentConstraint.selfIdealSize.Width().value_or(contentConstraint.maxSize.Width()); auto idealHeight = contentConstraint.selfIdealSize.Height().value_or(contentConstraint.maxSize.Height()); - + if (!textFieldLayoutProperty->GetValueValue("").empty()) { UpdateTextStyle(frameNode, textFieldLayoutProperty, textFieldTheme, textStyle, pattern->IsDisabled()); textContent = textFieldLayoutProperty->GetValueValue(""); @@ -153,7 +153,7 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( auto showPasswordIcon = textFieldLayoutProperty->GetShowPasswordIcon().value_or(true); // check password image size. if (!showPasswordIcon || !isPasswordType) { - textRect_.SetSize(SizeF(static_cast(paragraph_->GetLongestLine()), preferredHeight)); + textRect_.SetSize(SizeF(static_cast(paragraph_->GetActualWidth()), preferredHeight)); imageRect_.Reset(); if (textFieldLayoutProperty->GetWidthAutoValue(false)) { if (LessOrEqual(contentConstraint.minSize.Width(), 0.0f)) { @@ -176,7 +176,7 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( if (textStyle.GetMaxLines() > 1 || pattern->IsTextArea()) { // for textArea, need to delete imageWidth and remeasure. paragraph_->Layout(idealWidth - imageSize); - textRect_.SetSize(SizeF(static_cast(paragraph_->GetLongestLine()), preferredHeight)); + textRect_.SetSize(SizeF(static_cast(paragraph_->GetActualWidth()), preferredHeight)); imageRect_.SetSize(SizeF(0.0f, 0.0f)); return SizeF(idealWidth, imageSize); } @@ -187,7 +187,7 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( pattern->GetShowPasswordIconCtx()->MakeCanvasImage(imageRect_.GetSize(), true, ImageFit::NONE); } preferredHeight = std::min(static_cast(paragraph_->GetHeight()), idealHeight); - textRect_.SetSize(SizeF(static_cast(paragraph_->GetLongestLine()), static_cast(preferredHeight))); + textRect_.SetSize(SizeF(static_cast(paragraph_->GetActualWidth()), static_cast(preferredHeight))); return SizeF(idealWidth - imageSize, std::min(idealHeight, preferredHeight)); } @@ -342,18 +342,18 @@ void TextFieldLayoutAlgorithm::CreateParagraph(const TextStyle& textStyle, std:: if (textStyle.GetTextOverflow() == TextOverflow::ELLIPSIS) { paraStyle.ellipsis_ = StringUtils::Str8ToStr16(StringUtils::ELLIPSIS); } - auto builder = RSParagraphBuilder::CreateRosenBuilder(paraStyle, RSFontCollection::GetInstance(false)); + auto builder = RSParagraphBuilder::Create(paraStyle, RSFontCollection::Create()); builder->PushStyle(ToRSTextStyle(PipelineContext::GetCurrentContext(), textStyle)); StringUtils::TransformStrCase(content, static_cast(textStyle.GetTextCase())); if (!content.empty() && needObscureText) { - builder->AddText( + builder->AppendText( TextFieldPattern::CreateObscuredText(static_cast(StringUtils::ToWstring(content).length()))); } else { - builder->AddText(StringUtils::Str8ToStr16(content)); + builder->AppendText(StringUtils::Str8ToStr16(content)); } - builder->Pop(); + builder->PopStyle(); - auto paragraph = builder->Build(); + auto paragraph = builder->CreateTypography(); paragraph_.reset(paragraph.release()); } diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp index 30eaf2f9e0d9e8ff32fe4da590a8eecca4f4a6ed..989c61cacce9262c60490ab5a0fa570b0d182697 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 @@ -691,12 +691,12 @@ void TextFieldPattern::OnTextAreaScroll(float offset) } void TextFieldPattern::GetTextRectsInRange( - int32_t base, int32_t destination, std::vector& textBoxes) + int32_t base, int32_t destination, std::vector& textBoxes) { SwapIfLarger(base, destination); if (paragraph_) { - textBoxes = paragraph_->GetRectsForRange(base, destination, RSTypographyProperties::RectHeightStyle::MAX, - RSTypographyProperties::RectWidthStyle::TIGHT); + textBoxes = paragraph_->GetTextRectsByBoundary(base, destination, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, + Rosen::TextRectWidthStyle::TIGHT); } } @@ -710,8 +710,8 @@ bool TextFieldPattern::ComputeOffsetForCaretDownstream(int32_t extent, CaretMetr result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto textBoxes = paragraph_->GetRectsForRange( - next, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + auto textBoxes = paragraph_->GetTextRectsByBoundary( + next, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (textBoxes.empty()) { LOGD("Box empty"); @@ -744,18 +744,18 @@ bool TextFieldPattern::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetric result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !textEditingValue_.text.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { LOGD("Empty box"); @@ -797,7 +797,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() @@ -1670,7 +1670,7 @@ void TextFieldPattern::ProcessOverlay() UpdateSelection(textEditingValue_.caretPosition, textEditingValue_.caretPosition + 1); } } - std::vector tmp; + std::vector tmp; GetTextRectsInRange(textSelector_.GetStart(), textSelector_.GetEnd(), tmp); auto firstHandlePosition = CalcCursorOffsetByPosition(textSelector_.GetStart()); OffsetF firstHandleOffset(firstHandlePosition.offset.GetX() + parentGlobalOffset_.GetX(), @@ -2504,18 +2504,18 @@ float TextFieldPattern::PreferredTextHeight(bool isPlaceholder) 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(textEditingValue_.text, static_cast(textStyle.GetTextCase())); - builder->AddText(StringUtils::Str8ToStr16(textContent)); - builder->Pop(); + builder->AppendText(StringUtils::Str8ToStr16(textContent)); + builder->PopStyle(); if (!isPlaceholder) { - textLineHeightUtilParagraph_ = builder->Build(); + textLineHeightUtilParagraph_ = builder->CreateTypography(); textLineHeightUtilParagraph_->Layout(std::numeric_limits::infinity()); layoutProperty->UpdatePreferredTextLineHeightNeedToUpdate(false); return static_cast(textLineHeightUtilParagraph_->GetHeight()); } - placeholderLineHeightUtilParagraph_ = builder->Build(); + placeholderLineHeightUtilParagraph_ = builder->CreateTypography(); placeholderLineHeightUtilParagraph_->Layout(std::numeric_limits::infinity()); layoutProperty->UpdatePreferredPlaceholderLineHeightNeedToUpdate(false); return static_cast(placeholderLineHeightUtilParagraph_->GetHeight()); @@ -2566,7 +2566,7 @@ void TextFieldPattern::CursorMoveUp() CHECK_NULL_VOID_NOLOG(IsTextArea()); float verticalOffset = caretRect_.GetY() - PreferredLineHeight(); textEditingValue_.caretPosition = static_cast( - paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), verticalOffset).pos_); + paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), verticalOffset).index_); OnCursorMoveDone(); } @@ -2576,7 +2576,7 @@ void TextFieldPattern::CursorMoveDown() CHECK_NULL_VOID_NOLOG(IsTextArea()); float verticalOffset = caretRect_.GetY() + PreferredLineHeight(); textEditingValue_.caretPosition = static_cast( - paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), verticalOffset).pos_); + paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), verticalOffset).index_); OnCursorMoveDone(); } @@ -2774,7 +2774,7 @@ void TextFieldPattern::HandleSelectionUp() } auto newOffsetY = caretRect_.GetY() - PreferredLineHeight() * 0.5 - textRect_.GetY(); textEditingValue_.caretPosition = - static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), newOffsetY).pos_); + static_cast(paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), newOffsetY).index_); textSelector_.destinationOffset = textEditingValue_.caretPosition; selectionMode_ = SelectionMode::SELECT; if (textSelector_.baseOffset == textSelector_.destinationOffset) { @@ -2795,7 +2795,7 @@ void TextFieldPattern::HandleSelectionDown() } auto newOffsetY = caretRect_.GetY() + PreferredLineHeight() * 1.5 - textRect_.GetY(); textEditingValue_.caretPosition = - static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), newOffsetY).pos_); + static_cast(paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), newOffsetY).index_); textSelector_.destinationOffset = textEditingValue_.caretPosition; selectionMode_ = SelectionMode::SELECT; if (textSelector_.baseOffset == textSelector_.destinationOffset) { 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 162b151f5ba3df6d79ba054fc0b8473e211480b8..5a491ad7595acffeb216ccc9a686348c6783bd16 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 @@ -367,7 +367,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_; } @@ -653,7 +653,7 @@ private: bool FilterWithRegex( const std::string& filter, const std::string& valueToUpdate, std::string& result, bool needToEscape = false); void EditingValueFilter(std::string& valueToUpdate, std::string& result); - void GetTextRectsInRange(int32_t begin, int32_t end, std::vector& textBoxes); + void GetTextRectsInRange(int32_t begin, int32_t end, std::vector& textBoxes); bool CursorInContentRegion(); bool OffsetInContentRegion(const Offset& offset); void SetDisabledStyle(); @@ -744,7 +744,7 @@ private: TextEditingValueNG textEditingValue_; TextSelector textSelector_; RefPtr selectOverlayProxy_; - std::vector textBoxes_; + std::vector textBoxes_; RefPtr textFieldOverlayModifier_; RefPtr textFieldContentModifier_; ACE_DISALLOW_COPY_AND_MOVE(TextFieldPattern); 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 12547e5b8edb83e2c86c75bcdc47abb67fecd697..6d02feffc76fb8126aa868c83d5c34c90cf82fc9 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp @@ -113,7 +113,8 @@ void SwitchModifier::PaintSwitch(RSCanvas& canvas, const OffsetF& contentOffset, hoverBoardOffset.SetX(xOffset - (actualWidth_ - width) / 2.0); hoverBoardOffset.SetY(yOffset - (actualHeight_ - height) / 2.0); DrawHoverBoard(canvas, hoverBoardOffset); - RSRect rect; + + Rosen::Drawing::Rect rect; rect.SetLeft(xOffset); rect.SetTop(yOffset); rect.SetRight(xOffset + width); 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 eb96a03b166e3cf20a52c87367d2626bd3d79c36..1e7db06b49ddfd664759f520eeadc17bbe46a04e 100644 --- a/frameworks/core/components_ng/render/adapter/focus_state_modifier.h +++ b/frameworks/core/components_ng/render/adapter/focus_state_modifier.h @@ -52,17 +52,17 @@ public: rect.GetRect().Width() + borderWidth, rect.GetRect().Height() + borderWidth); RSOverlayStyleModifier::SetOverlayBounds(overlayRect); roundRect_.SetRect( - rosen::Rect(rect.GetRect().Left(), rect.GetRect().Top(), rect.GetRect().Right(), rect.GetRect().Bottom())); - roundRect_.SetCornerRadius(rosen::RoundRect::CornerPos::TOP_LEFT_POS, + RSRect(rect.GetRect().Left(), rect.GetRect().Top(), rect.GetRect().Right(), rect.GetRect().Bottom())); + roundRect_.SetCornerRadius(RSRoundRect::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(RSRoundRect::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(RSRoundRect::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(RSRoundRect::CornerPos::BOTTOM_RIGHT_POS, rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS).x, rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS).y); } diff --git a/frameworks/core/components_ng/render/adapter/overlay_modifier.h b/frameworks/core/components_ng/render/adapter/overlay_modifier.h index bb7fb2fae7ddbc7f03def30b4ced4316d30c5593..0d05ef31405869b92d8f44d364938f8f2937c6b7 100644 --- a/frameworks/core/components_ng/render/adapter/overlay_modifier.h +++ b/frameworks/core/components_ng/render/adapter/overlay_modifier.h @@ -74,18 +74,18 @@ public: paraStyle.locale_ = Localization::GetInstance()->GetFontLocale(); paraStyle.wordBreakType_ = ToRSWordBreakType(textStyle.GetWordBreak()); paraStyle.fontSize_ = fontSize.Value(); - auto builder = RSParagraphBuilder::CreateRosenBuilder(paraStyle, RSFontCollection::GetInstance(false)); + auto builder = RSParagraphBuilder::Create(paraStyle, RSFontCollection::Create()); CHECK_NULL_VOID(builder); auto pipelineContext = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); builder->PushStyle(ToRSTextStyle(pipelineContext, textStyle)); - builder->AddText(StringUtils::Str8ToStr16(overlayOptions.content)); - builder->Pop(); - auto paragraph = builder->Build(); + builder->AppendText(StringUtils::Str8ToStr16(overlayOptions.content)); + builder->PopStyle(); + auto paragraph = builder->CreateTypography(); CHECK_NULL_VOID(paragraph); paragraph->Layout(context.width); OffsetF offset = OverlayTextModifier::GetTextPosition(SizeF(context.width, context.height), - SizeF(paragraph->GetLongestLine(), paragraph->GetHeight()), overlayOptions); + SizeF(paragraph->GetActualWidth(), paragraph->GetHeight()), overlayOptions); std::shared_ptr skCanvas { context.canvas, [](SkCanvas*) {} }; RSCanvas canvas(&skCanvas); CHECK_NULL_VOID(&canvas); @@ -122,4 +122,4 @@ private: } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_OVERLAY_MODIFIER_H \ No newline at end of file +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_OVERLAY_MODIFIER_H diff --git a/frameworks/core/components_ng/render/adapter/txt_font_collection.cpp b/frameworks/core/components_ng/render/adapter/txt_font_collection.cpp index e2dcfd442b4116d5da0c01a876c4cb4a795d49bf..26637f806ebba0d498bc2e01000216bcdfb3d23f 100644 --- a/frameworks/core/components_ng/render/adapter/txt_font_collection.cpp +++ b/frameworks/core/components_ng/render/adapter/txt_font_collection.cpp @@ -34,19 +34,19 @@ RefPtr FontCollection::Current() TxtFontCollection::TxtFontCollection() { - collection_ = std::make_shared(); - collection_->SetupDefaultFontManager(); - dynamicFontManager_ = sk_make_sp(); - collection_->SetDynamicFontManager(dynamicFontManager_); - if (collection_) { - std::string emptyLocale; - // 0x4e2d is unicode for '中'. - collection_->MatchFallbackFont(0x4e2d, emptyLocale); - collection_->GetMinikinFontCollectionForFamilies({ "sans-serif" }, emptyLocale); - } + collection_ = Rosen::FontCollection::Create(); + //collection_->SetupDefaultFontManager(); + //dynamicFontManager_ = sk_make_sp(); + //collection_->SetDynamicFontManager(dynamicFontManager_); + //if (collection_) { + // std::string emptyLocale; + // // 0x4e2d is unicode for '中'. + // collection_->MatchFallbackFont(0x4e2d, emptyLocale); + // collection_->GetMinikinFontCollectionForFamilies({ "sans-serif" }, emptyLocale); + //} } -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 44711b23575ff2957f688f708bca05bdad210fbb..19669b90a8cd3fb752742a3510b3ff159e2e7dce 100644 --- a/frameworks/core/components_ng/render/adapter/txt_font_collection.h +++ b/frameworks/core/components_ng/render/adapter/txt_font_collection.h @@ -18,31 +18,30 @@ #include -#include "txt/font_collection.h" - #include "base/memory/ace_type.h" #include "base/utils/macros.h" #include "core/components_ng/render/font_collection.h" +#include "rosen_text/font_collection.h" 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(); ~TxtFontCollection() override = default; static RefPtr GetInstance(); - const std::shared_ptr& GetRawFontCollection() + const std::shared_ptr& GetRawFontCollection() { return collection_; } private: - std::shared_ptr collection_; - sk_sp dynamicFontManager_; + std::shared_ptr collection_; + //sk_sp dynamicFontManager_; }; } // 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 9a64dffad9710d44bba4aa2c17474a99ff638e58..4bcd2c812f73f49dc65565bd0985797bb0ec426f 100644 --- a/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp +++ b/frameworks/core/components_ng/render/adapter/txt_paragraph.cpp @@ -41,19 +41,19 @@ bool TxtParagraph::IsValid() void TxtParagraph::CreateBuilder() { - txt::ParagraphStyle style; - style.text_direction = Constants::ConvertTxtTextDirection(paraStyle_.direction); - style.text_align = Constants::ConvertTxtTextAlign(paraStyle_.align); - style.max_lines = paraStyle_.maxLines; - style.locale = paraStyle_.fontLocale; + Rosen::TypographyStyle style; + style.textDirection_ = Constants::ConvertTxtTextDirection(paraStyle_.direction); + style.textAlign_ = Constants::ConvertTxtTextAlign(paraStyle_.align); + style.maxLines_ = paraStyle_.maxLines; + style.locale_ = paraStyle_.fontLocale; if (paraStyle_.textOverflow == TextOverflow::ELLIPSIS) { - style.ellipsis = ELLIPSIS; + style.ellipsis_ = ELLIPSIS; } #ifndef FLUTTER_2_5 // keep WordBreak define same with WordBreakType in minikin - style.word_break_type = static_cast(paraStyle_.wordBreak); + style.wordBreakType_ = static_cast(paraStyle_.wordBreak); #endif - builder_ = txt::ParagraphBuilder::CreateTxtBuilder(style, fontCollection_); + builder_ = Rosen::TypographyCreate::Create(style, fontCollection_); } void TxtParagraph::PushStyle(const TextStyle& style) @@ -62,7 +62,7 @@ void TxtParagraph::PushStyle(const TextStyle& style) CreateBuilder(); } - txt::TextStyle txtStyle; + Rosen::TextStyle txtStyle; Constants::ConvertTxtStyle(style, PipelineContext::GetCurrentContext(), txtStyle); builder_->PushStyle(txtStyle); } @@ -70,7 +70,7 @@ void TxtParagraph::PushStyle(const TextStyle& style) void TxtParagraph::PopStyle() { CHECK_NULL_VOID(builder_); - builder_->Pop(); + builder_->PopStyle(); } void TxtParagraph::AddText(const std::u16string& text) @@ -79,13 +79,13 @@ void TxtParagraph::AddText(const std::u16string& text) CreateBuilder(); } text_ = text; - builder_->AddText(text); + builder_->AppendText(text); } void TxtParagraph::Build() { CHECK_NULL_VOID_NOLOG(builder_); - paragraph_ = builder_->Build(); + paragraph_ = builder_->CreateTypography(); } void TxtParagraph::Reset() @@ -111,9 +111,9 @@ float TxtParagraph::GetTextWidth() { CHECK_NULL_RETURN(paragraph_, 0.0f); if (GetLineCount() == 1) { - return std::max(paragraph_->GetLongestLine(), paragraph_->GetMaxIntrinsicWidth()); + return std::max(paragraph_->GetActualWidth(), paragraph_->GetMaxIntrinsicWidth()); } - return paragraph_->GetLongestLine(); + return paragraph_->GetActualWidth(); } float TxtParagraph::GetMaxIntrinsicWidth() @@ -131,7 +131,7 @@ bool TxtParagraph::DidExceedMaxLines() float TxtParagraph::GetLongestLine() { CHECK_NULL_RETURN(paragraph_, 0.0f); - return static_cast(paragraph_->GetLongestLine()); + return static_cast(paragraph_->GetActualWidth()); } float TxtParagraph::GetMaxWidth() @@ -148,9 +148,8 @@ float TxtParagraph::GetAlphabeticBaseline() size_t TxtParagraph::GetLineCount() { - auto* paragraphTxt = static_cast(paragraph_.get()); - CHECK_NULL_RETURN(paragraphTxt, 0); - return paragraphTxt->GetLineCount(); + CHECK_NULL_RETURN(paragraph_, 0); + return paragraph_->GetLineCount(); } void TxtParagraph::Paint(const RSCanvas& canvas, float x, float y) @@ -172,7 +171,7 @@ int32_t TxtParagraph::GetHandlePositionForClick(const Offset& offset) if (!paragraph_) { return 0; } - return static_cast(paragraph_->GetGlyphPositionAtCoordinate(offset.GetX(), offset.GetY()).position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate(offset.GetX(), offset.GetY()).index_); } bool TxtParagraph::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics& result) @@ -189,18 +188,18 @@ bool TxtParagraph::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics& r result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !text_.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { return false; @@ -211,17 +210,17 @@ bool TxtParagraph::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetrics& r if (prevChar == NEWLINE_CODE) { // Return the start of next line. result.offset.SetX(0.0); - result.offset.SetY(textBox.rect.fBottom); + result.offset.SetY(textBox.rect_.GetBottom()); return true; } - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fRight : textBox.rect.fLeft; + double caretStart = isLtr ? textBox.rect_.GetLeft() : textBox.rect_.GetRight(); double offsetX = std::min(caretStart, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -235,33 +234,33 @@ bool TxtParagraph::ComputeOffsetForCaretDownstream(int32_t extent, CaretMetrics& result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - extent, next, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + extent, next, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return false; } const auto& textBox = *boxes.begin(); - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fLeft : textBox.rect.fRight; + double caretStart = isLtr ? textBox.rect_.GetLeft() : textBox.rect_.GetRight(); double offsetX = std::min(caretStart, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } void TxtParagraph::GetRectsForRange(int32_t start, int32_t end, std::vector& selectedRects) { - const auto& boxes = paragraph_->GetRectsForRange( - start, end, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary( + start, end, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return; } for (const auto& box : boxes) { - auto selectionRect = Constants::ConvertSkRect(box.rect); + auto selectionRect = Constants::ConvertSkRect(box.rect_); selectedRects.emplace_back(selectionRect); } } diff --git a/frameworks/core/components_ng/render/adapter/txt_paragraph.h b/frameworks/core/components_ng/render/adapter/txt_paragraph.h index 8bd39be54d85712cd51cdab7c53ece249668d881..9c711c65be12046084788d0fa3c32f3ad5d82d69 100644 --- a/frameworks/core/components_ng/render/adapter/txt_paragraph.h +++ b/frameworks/core/components_ng/render/adapter/txt_paragraph.h @@ -16,12 +16,9 @@ #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 "base/utils/noncopyable.h" #include "core/components_ng/render/paragraph.h" +#include "rosen_text/typography_create.h" namespace OHOS::Ace::NG { @@ -30,7 +27,7 @@ class TxtParagraph : public Paragraph { DECLARE_ACE_TYPE(NG::TxtParagraph, NG::Paragraph) public: - TxtParagraph(const ParagraphStyle& paraStyle, std::shared_ptr fontCollection) + TxtParagraph(const ParagraphStyle& paraStyle, std::shared_ptr fontCollection) : paraStyle_(paraStyle), fontCollection_(std::move(fontCollection)) {} ~TxtParagraph() override = default; @@ -70,9 +67,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_; std::u16string text_; ACE_DISALLOW_COPY_AND_MOVE(TxtParagraph); diff --git a/frameworks/core/components_ng/render/drawing.h b/frameworks/core/components_ng/render/drawing.h index fd1c537071d816de9fc84854e0c71170f7b2ca56..57e66b7db113feb1f29cf62a782665049b608f3f 100644 --- a/frameworks/core/components_ng/render/drawing.h +++ b/frameworks/core/components_ng/render/drawing.h @@ -22,12 +22,12 @@ #include "drawing/engine_adapter/skia_adapter/skia_canvas.h" #include "drawing/engine_adapter/skia_adapter/skia_path.h" #include "image/image.h" -#include "rosen_text/properties/text_style.h" -#include "rosen_text/ui/font_collection.h" -#include "rosen_text/ui/typography.h" -#include "rosen_text/ui/typography_create.h" #include "utils/camera3d.h" #include "utils/point3.h" +#include "rosen_text/font_collection.h" +#include "rosen_text/typography.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/text_style.h" #include "utils/scalar.h" namespace OHOS::Ace { @@ -48,7 +48,6 @@ using RSPoint3 = Rosen::Drawing::Point3; using RSShadowFlags = Rosen::Drawing::ShadowFlags; using RSBlendMode = Rosen::Drawing::BlendMode; using RSSamplingOptions = Rosen::Drawing::SamplingOptions; -using RSRoundRect = Rosen::Drawing::RoundRect; using RSPath = Rosen::Drawing::Path; using RSBitmap = Rosen::Drawing::Bitmap; using RSBitmapFormat = Rosen::Drawing::BitmapFormat; @@ -63,24 +62,24 @@ using RSMaskFilter = Rosen::Drawing::MaskFilter; using RSBlurType = Rosen::Drawing::BlurType; using RSPathFillType = Rosen::Drawing::PathFillType; using RSSkPath = Rosen::Drawing::SkiaPath; +using RSColorQuad = Rosen::Drawing::ColorQuad; +using RSShaderEffect = Rosen::Drawing::ShaderEffect; +using RSTileMode = Rosen::Drawing::TileMode; -using RSPathEffect = rosen::PathEffect; -using RSPathDirection = rosen::PathDirection; -using RSPathDashStyle = rosen::PathDashStyle; -using RSParagraph = rosen::Typography; -using RSTypographyProperties = rosen::TypographyProperties; -using RSParagraphBuilder = rosen::TypographyCreate; -using RSFontCollection = rosen::FontCollection; -using RSParagraphStyle = rosen::TypographyStyle; -using RSColorQuad = rosen::ColorQuad; -using RSShaderEffect = rosen::ShaderEffect; -using RSTileMode = rosen::TileMode; -using RSTextDirection = rosen::TextDirection; -using RSTextAlign = rosen::TextAlign; -using RSWordBreakType = rosen::WordBreakType; -using RSTextStyle = rosen::TextStyle; -using RSTextDecoration = rosen::TextDecoration; -using RSFontWeight = rosen::FontWeight; +using RSTextDirection = Rosen::TextDirection; +using RSTextAlign = Rosen::TextAlign; +using RSWordBreakType = Rosen::WordBreakType; +using RSTextStyle = Rosen::TextStyle; +using RSTextDecoration = Rosen::TextDecoration; +using RSFontWeight = Rosen::FontWeight; +using RSPathEffect = Rosen::Drawing::PathEffect; +using RSPathDirection = Rosen::Drawing::PathDirection; +using RSPathDashStyle = Rosen::Drawing::PathDashStyle; +using RSParagraph = 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 ef75a9f586d5a02d74d606901dab5b9ab601305a..242f30d9b15a8b158d661d0943df0fe0e11175f7 100644 --- a/frameworks/core/components_ng/render/drawing_prop_convertor.cpp +++ b/frameworks/core/components_ng/render/drawing_prop_convertor.cpp @@ -121,7 +121,7 @@ RSFontWeight ToRSFontWeight(FontWeight fontWeight) RSWordBreakType ToRSWordBreakType(const WordBreak& wordBreak) { // should keep enum same with rosen. - return static_cast(wordBreak); + return static_cast(wordBreak); } RSTextDecoration ToRSTextDecoration(TextDecoration textDecoration) @@ -154,8 +154,8 @@ RSTextStyle ToRSTextStyle(const RefPtr& context, const TextStyle& // TODO: convert missing textBaseline rsTextStyle.fontWeight_ = ToRSFontWeight(textStyle.GetFontWeight()); - rsTextStyle.fontStyle_ = static_cast(textStyle.GetFontStyle()); - rsTextStyle.textBaseline_ = static_cast(textStyle.GetTextBaseline()); + rsTextStyle.fontStyle_ = static_cast(textStyle.GetFontStyle()); + rsTextStyle.baseline_ = static_cast(textStyle.GetTextBaseline()); rsTextStyle.fontFamilies_ = textStyle.GetFontFamilies(); if (textStyle.GetTextOverflow() == TextOverflow::ELLIPSIS) { rsTextStyle.ellipsis_ = StringUtils::Str8ToStr16(StringUtils::ELLIPSIS); @@ -182,24 +182,24 @@ RSTextStyle ToRSTextStyle(const RefPtr& context, const TextStyle& } if (textStyle.GetLineHeight().Unit() == DimensionUnit::PERCENT) { - rsTextStyle.hasHeightOverride_ = true; - rsTextStyle.height_ = textStyle.GetLineHeight().Value(); + rsTextStyle.heightOnly_ = true; + rsTextStyle.heightScale_ = textStyle.GetLineHeight().Value(); } else { double fontSize = rsTextStyle.fontSize_; double lineHeight = textStyle.GetLineHeight().Value(); if (context) { lineHeight = context->NormalizeToPx(textStyle.GetLineHeight()); } - rsTextStyle.hasHeightOverride_ = textStyle.HasHeightOverride(); + rsTextStyle.heightOnly_ = textStyle.HasHeightOverride(); if (!NearEqual(lineHeight, fontSize) && (lineHeight > 0.0) && (!NearZero(fontSize))) { - rsTextStyle.height_ = lineHeight / fontSize; + rsTextStyle.heightScale_ = lineHeight / fontSize; } else { LOGD("use default text style height value."); - rsTextStyle.height_ = 1; + rsTextStyle.heightScale_ = 1; static const int32_t BEGIN_VERSION = 6; auto isBeginVersion = context && context->GetMinPlatformVersion() >= BEGIN_VERSION; if (NearZero(lineHeight) || (!isBeginVersion && NearEqual(lineHeight, fontSize))) { - rsTextStyle.hasHeightOverride_ = false; + rsTextStyle.heightOnly_ = false; } } } diff --git a/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_manager/BUILD.gn b/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_manager/BUILD.gn index 4f1a7f0f3633489211b19d3a47b8c4f49bc2dbcb..f32d67a91444bd61cf837556a5ddc58fe7ef95c5 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 @@ -104,6 +104,5 @@ 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", ] } 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 cb4ce5eff0b534e8591f58d41297c493e111b546..d4506407297323690ca1c408d4933145eb227b6d 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 @@ -76,6 +76,5 @@ 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", ] } 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 6505f6ba3f26709bb3363a2472b3d76e3ed4b50f..a7718b7895fe8ff6a49a725bf7812f7a1699c81c 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,5 @@ 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", ] } 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 d538e8b201bbf0ba8a32c35c684cadab3f5e5519..1c1fec673d377b21dd8232cfe168baebde1a655d 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 @@ -72,6 +72,5 @@ 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", ] } 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 c9a8d075f6e3f90c5842d6897c3c5c799db7226c..83056514a154c5a819d3c3ff8000be2504c206b6 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,6 @@ 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/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 9a9306b6c2a5f4ff3e817f6129f2e4aaff59beaa..f4bc3fe7f51a6b7e7fa88dec3a87a893178c8539 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,6 @@ 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/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 80f3c8a3ed7aa825c766ff4547b727543dc59b11..9075f9ee5b0ea704c309e47821815fdbcdb27250 100644 --- a/frameworks/core/components_ng/test/pattern/option/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/option/BUILD.gn @@ -104,7 +104,6 @@ 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/render_service_client:render_service_client_config", ] }