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 5d6b1ec818be07c3137811a2047a4f4fd3156a5f..e34e18ba343ba8ad7aa04ea6fad9dcbc60600a9c 100644 --- a/adapter/ohos/entrance/BUILD.gn +++ b/adapter/ohos/entrance/BUILD.gn @@ -105,6 +105,7 @@ template("ace_ohos_standard_source_set") { "$ability_runtime_path/frameworks/native/ability/native:data_ability_helper", "$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 67ecbe7a759355bdb92d5aec0e02ec97b3363b29..8b1c54a4aee5d2a8325c811afc784a76752c7aeb 100644 --- a/adapter/ohos/entrance/window/drag_window_ohos.cpp +++ b/adapter/ohos/entrance/window/drag_window_ohos.cpp @@ -34,6 +34,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/test/mock/mock_drag_window.h b/frameworks/base/test/mock/mock_drag_window.h index 9952299bb973e2970daaa9aa64d0b71d1bc259bd..36f8d381b2575913837dd644864202d41547a247 100644 --- a/frameworks/base/test/mock/mock_drag_window.h +++ b/frameworks/base/test/mock/mock_drag_window.h @@ -30,7 +30,7 @@ public: MOCK_METHOD1(DrawImage, void(void* skImage)); MOCK_METHOD3(DrawText, - void(std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText)); + void(std::shared_ptr paragraph, const Offset& offset, const RefPtr& renderText)); MOCK_METHOD2(DrawTextNG, void(const RefPtr& paragraph, const RefPtr& textPattern)); MOCK_METHOD1(DrawPixelMap, void(const RefPtr&)); MOCK_METHOD1(DrawFrameNode, void(const RefPtr&)); 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 cfcef079ffd5bc84a645c568b8d50408febe0c80..771b79decb6ad71b2bceb3b09f196c30063ebbcf 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -382,6 +382,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 62fd7a503b60c01ea323d5dd082fe4ad4bffdb3b..74d420f8711af5fbd61ef8ba9e2c709b5b1abe5e 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 "txt/paragraph.h" -#include "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) +void DrawCalendarText(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 40328415aae831fd282de03adaa6b0c01fa834a3..16d178761c3671b8fac351f1ccad49e1e23fd063 100644 --- a/frameworks/core/components/calendar/flutter_render_calendar.h +++ b/frameworks/core/components/calendar/flutter_render_calendar.h @@ -16,8 +16,8 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_FLUTTER_RENDER_CALENDAR_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_FLUTTER_RENDER_CALENDAR_H -#include "include/core/SkColor.h" -#include "third_party/txt/src/txt/text_style.h" +#include "third_party/skia/include/core/SkColor.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 8cfea9fe962028d387f75aaecc0f3f514b593fde..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 "txt/paragraph_builder.h" -#include "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 bb05e6611c137a8684d180efb2204d437ef04d21..961033e2106d15dea6f7b96696dbaec79e37bd3c 100644 --- a/frameworks/core/components/calendar/rosen_render_calendar.h +++ b/frameworks/core/components/calendar/rosen_render_calendar.h @@ -16,9 +16,9 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_ROSEN_RENDER_CALENDAR_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_ROSEN_RENDER_CALENDAR_H -#include "include/core/SkCanvas.h" -#include "include/core/SkColor.h" -#include "third_party/txt/src/txt/text_style.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkColor.h" +#include "rosen_text/text_style.h" #include "core/components/calendar/render_calendar.h" @@ -46,21 +46,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 56765c33f1ec216b173fc895db197fd238dabaf4..e9eea4282f2dfc95c0f21987f44895435732033a 100644 --- a/frameworks/core/components/chart/flutter_render_chart.cpp +++ b/frameworks/core/components/chart/flutter_render_chart.cpp @@ -15,16 +15,16 @@ #include "core/components/chart/flutter_render_chart.h" -#include "include/core/SkColor.h" -#include "include/effects/Sk1DPathEffect.h" -#include "include/effects/SkGradientShader.h" -#include "txt/paragraph_builder.h" -#include "txt/paragraph_style.h" -#include "txt/paragraph_txt.h" +#include "third_party/skia/include/core/SkColor.h" +#include "third_party/skia/include/effects/Sk1DPathEffect.h" +#include "third_party/skia/include/effects/SkGradientShader.h" #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 e736b3e5d4818f8945c2f5c44522737c69494bf7..f1fe5c38698aad9db66ca5dac7d51a501f2ecc68 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 "include/core/SkColor.h" -#include "include/core/SkPaint.h" -#include "include/effects/Sk1DPathEffect.h" -#include "include/effects/SkGradientShader.h" -#include "txt/paragraph_builder.h" -#include "txt/paragraph_txt.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 "base/utils/string_utils.h" #include "core/components/calendar/rosen_render_calendar.h" @@ -145,23 +145,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 d760d595f7fe8347515b9c8debfb03ea4e081be3..b93d53e77e611a6be5be72c1eef20ff58ec78c4b 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 (ace_use_new_skia) { 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 71556f83385a580704bec96e3afe8dd6adfd1c96..62b36fb428645b4e26a3a3712900a732d542a443 100644 --- a/frameworks/core/components/custom_paint/flutter_render_custom_paint.cpp +++ b/frameworks/core/components/custom_paint/flutter_render_custom_paint.cpp @@ -18,8 +18,8 @@ #include #include "securec.h" -#include "txt/paragraph_builder.h" -#include "txt/paragraph_style.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" #include "include/core/SkBlendMode.h" #include "include/core/SkCanvas.h" @@ -513,20 +513,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(); } @@ -534,20 +534,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(); } @@ -555,20 +555,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(); @@ -610,7 +610,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) { @@ -636,7 +636,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) { @@ -1213,67 +1213,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()); } @@ -1282,8 +1280,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 7948f5563d8ceb9b07a05dde521f9e92daf0d6e7..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,8 +19,9 @@ #include "base/utils/measure_util.h" #include "flutter/fml/memory/ref_ptr.h" #include "flutter/lib/ui/painting/path.h" -#include "txt/paragraph.h" -#include "include/core/SkPath.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" #include "core/components/custom_paint/render_custom_paint.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 7f4a72274487c009f0e43e4fc7ff7399e0f5912f..9d2e9f63e7ac1f7a745b30ea42520f1177079fd8 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 "txt/paragraph_builder.h" -#include "txt/paragraph_style.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" #include "include/core/SkBlendMode.h" #include "include/core/SkCanvas.h" #include "include/core/SkColor.h" @@ -1090,21 +1090,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(); } @@ -1112,21 +1112,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(); } @@ -1134,21 +1134,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(); @@ -1190,7 +1190,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) { @@ -1242,66 +1242,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()); } @@ -1310,13 +1308,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 f74ef6452c5f9994b5a6501bd82ed59034bd8ae2..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,9 +18,10 @@ #include "flutter/fml/memory/ref_ptr.h" #include "flutter/lib/ui/painting/path.h" -#include "txt/paragraph.h" -#include "include/core/SkCanvas.h" -#include "include/core/SkPath.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" #include "core/components/custom_paint/offscreen_canvas.h" #include "core/components/custom_paint/render_custom_paint.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 ae83549c9f43c5e2008934f40084ed5eacca65ac..ae050c48d94a224a8121dba869c981096dcb2cbe 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 "txt/paragraph_builder.h" -#include "txt/paragraph_style.h" -#include "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 "securec.h" @@ -415,39 +415,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) @@ -458,50 +458,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); } @@ -511,11 +511,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 = @@ -533,20 +533,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(); } @@ -554,20 +554,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(); } @@ -575,20 +575,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(); @@ -630,7 +630,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) { @@ -656,7 +656,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) { @@ -1281,65 +1281,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(); -#ifndef NEW_SKIA - txtShadow.blur_radius = shadow_.GetBlurRadius(); -#else - txtShadow.blur_sigma = shadow_.GetBlurRadius(); -#endif - 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 { @@ -1347,7 +1341,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()); } @@ -1356,8 +1350,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 86cfdf42f4c703cd43dd9d5384cc58e201bee8f9..58d4269d566f1c6bcc5afa4b7c030999404829f0 100644 --- a/frameworks/core/components/custom_paint/rosen_render_custom_paint.h +++ b/frameworks/core/components/custom_paint/rosen_render_custom_paint.h @@ -21,6 +21,8 @@ #else #include "experimental/svg/model/SkSVGDOM.h" #endif +#include "rosen_text/text_style.h" +#include "rosen_text/typography.h" #include "txt/paragraph.h" #include "include/core/SkBitmap.h" #include "include/core/SkCanvas.h" @@ -107,14 +109,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); @@ -140,7 +142,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 9d0616a6c0734b38b0aa8b191bc5b2c57cdb9424..bc6d4512fc84c10a027a9970c4f3d97dda075f17 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 "txt/paragraph_builder.h" -#include "txt/paragraph_style.h" +#include "rosen_text/typography_create.h" +#include "rosen_text/typography_style.h" #include "include/core/SkBlendMode.h" #include "include/core/SkColor.h" #include "include/core/SkMaskFilter.h" @@ -1335,10 +1335,16 @@ void RosenRenderOffscreenCanvas::StrokeText(const std::string& text, double x, d double RosenRenderOffscreenCanvas::MeasureText(const std::string& text, const PaintState& state) { using namespace Constants; +<<<<<<< HEAD txt::ParagraphStyle style; style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); #ifndef NEW_SKIA +======= + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); +>>>>>>> using rosen_text auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); #else auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); @@ -1347,13 +1353,13 @@ double RosenRenderOffscreenCanvas::MeasureText(const std::string& text, const Pa 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(); } @@ -1361,10 +1367,16 @@ double RosenRenderOffscreenCanvas::MeasureText(const std::string& text, const Pa double RosenRenderOffscreenCanvas::MeasureTextHeight(const std::string& text, const PaintState& state) { using namespace Constants; +<<<<<<< HEAD txt::ParagraphStyle style; style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); #ifndef NEW_SKIA +======= + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); +>>>>>>> using rosen_text auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); #else auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); @@ -1373,13 +1385,13 @@ double RosenRenderOffscreenCanvas::MeasureTextHeight(const std::string& text, co 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(); } @@ -1387,10 +1399,16 @@ double RosenRenderOffscreenCanvas::MeasureTextHeight(const std::string& text, co TextMetrics RosenRenderOffscreenCanvas::MeasureTextMetrics(const std::string& text, const PaintState& state) { using namespace Constants; +<<<<<<< HEAD txt::ParagraphStyle style; style.text_align = ConvertTxtTextAlign(state.GetTextAlign()); style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); #ifndef NEW_SKIA +======= + Rosen::TypographyStyle style; + style.textAlign_ = ConvertTxtTextAlign(state.GetTextAlign()); + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); +>>>>>>> using rosen_text auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); #else auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); @@ -1399,13 +1417,13 @@ TextMetrics RosenRenderOffscreenCanvas::MeasureTextMetrics(const std::string& te 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(); @@ -1447,7 +1465,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) { @@ -1499,14 +1517,18 @@ 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()); } +<<<<<<< HEAD style.text_direction = ConvertTxtTextDirection(state.GetOffTextDirection()); #ifndef NEW_SKIA +======= + style.textDirection_ = ConvertTxtTextDirection(state.GetOffTextDirection()); +>>>>>>> using rosen_text auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); #else auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); @@ -1514,9 +1536,10 @@ bool RosenRenderOffscreenCanvas::UpdateOffParagraph(const std::string& text, boo 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) { +<<<<<<< HEAD txt::TextShadow txtShadow; txtShadow.color = shadow_.GetColor().GetValue(); txtShadow.offset.fX = shadow_.GetOffset().GetX(); @@ -1529,45 +1552,53 @@ bool RosenRenderOffscreenCanvas::UpdateOffParagraph(const std::string& text, boo 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(); +>>>>>>> using rosen_text 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()); } @@ -1581,13 +1612,12 @@ void RosenRenderOffscreenCanvas::UpdateTextStyleForeground( RosenDecorationPainter::ConvertRadiusToSigma(shadow_.GetBlurRadius()))); #endif } - 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 a5a6ccb92cc9236cef82b174653be4252f35a79b..55c0aca0afeb903b6968d1e812ef467b022d9976 100644 --- a/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.h +++ b/frameworks/core/components/custom_paint/rosen_render_offscreen_canvas.h @@ -21,7 +21,9 @@ #else #include "experimental/svg/model/SkSVGDOM.h" #endif -#include "txt/paragraph.h" +#include "rosen_text/text_style.h" +#include "rosen_text/typography.h" +#include "rosen_text/text_style.h" #include "include/core/SkCanvas.h" #include "include/core/SkPath.h" @@ -116,12 +118,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, OHOS::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 a8c47e947f7258db804d27be46e300d996d74483..69e1d4c20370d93252fad71e8d20bb1f8e9087cc 100644 --- a/frameworks/core/components/font/constants_converter.cpp +++ b/frameworks/core/components/font/constants_converter.cpp @@ -15,10 +15,8 @@ #include "constants_converter.h" -#include "txt/font_style.h" -#include "txt/font_weight.h" -#include "txt/paragraph_style.h" -#include "txt/text_decoration.h" +#include "rosen_text/typography_style.h" +#include "rosen_text/typography_create.h" #include "base/i18n/localization.h" #include "core/components/common/properties/color.h" @@ -26,130 +24,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 +158,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::LINE_THROUGH; break; default: LOGW("TextDecoration setting error! Now using default TextDecoration"); @@ -183,73 +181,73 @@ 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()); #if defined (FLUTTER_2_5) || defined (NEW_SKIA) - txtShadow.blur_sigma = 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,45 +255,45 @@ 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; } } -Rect ConvertSkRect(SkRect skRect) +Rect ConvertSkRect(const Rosen::Drawing::RectF &skRect) { Rect result; - result.SetLeft(skRect.fLeft); - result.SetTop(skRect.fTop); - result.SetWidth(skRect.width()); - result.SetHeight(skRect.height()); + result.SetLeft(skRect.GetLeft()); + result.SetTop(skRect.GetTop()); + result.SetWidth(skRect.GetWidth()); + result.SetHeight(skRect.GetHeight()); return result; } -txt::PlaceholderAlignment ConvertPlaceholderAlignment(PlaceholderAlignment textDecoration) +OHOS::Rosen::PlaceholderVerticalAlignment ConvertPlaceholderAlignment(PlaceholderAlignment textDecoration) { - txt::PlaceholderAlignment convertValue = txt::PlaceholderAlignment::kBaseline; + OHOS::Rosen::PlaceholderVerticalAlignment convertValue = OHOS::Rosen::PlaceholderVerticalAlignment::OFFSET_AT_BASELINE; switch (textDecoration) { case PlaceholderAlignment::BASELINE: - convertValue = txt::PlaceholderAlignment::kBaseline; + convertValue = OHOS::Rosen::PlaceholderVerticalAlignment::OFFSET_AT_BASELINE; break; case PlaceholderAlignment::ABOVEBASELINE: - convertValue = txt::PlaceholderAlignment::kAboveBaseline; + convertValue = OHOS::Rosen::PlaceholderVerticalAlignment::ABOVE_BASELINE; break; case PlaceholderAlignment::BELOWBASELINE: - convertValue = txt::PlaceholderAlignment::kBelowBaseline; + convertValue = OHOS::Rosen::PlaceholderVerticalAlignment::BELOW_BASELINE; break; case PlaceholderAlignment::TOP: - convertValue = txt::PlaceholderAlignment::kTop; + convertValue = OHOS::Rosen::PlaceholderVerticalAlignment::TOP_OF_ROW_BOX; break; case PlaceholderAlignment::BOTTOM: - convertValue = txt::PlaceholderAlignment::kBottom; + convertValue = OHOS::Rosen::PlaceholderVerticalAlignment::BOTTOM_OF_ROW_BOX; break; case PlaceholderAlignment::MIDDLE: - convertValue = txt::PlaceholderAlignment::kMiddle; + convertValue = OHOS::Rosen::PlaceholderVerticalAlignment::CENTER_OF_ROW_BOX; break; default: LOGW("PlaceholderAlignment setting error! Now using default PlaceholderAlignment"); @@ -304,13 +302,12 @@ txt::PlaceholderAlignment ConvertPlaceholderAlignment(PlaceholderAlignment textD return convertValue; } -void ConvertPlaceholderRun(const PlaceholderRun& span, txt::PlaceholderRun& txtSpan) +void ConvertPlaceholderRun(const PlaceholderRun& span, OHOS::Rosen::PlaceholderSpan& txtSpan) { txtSpan.width = span.width; txtSpan.height = span.height; txtSpan.alignment = ConvertPlaceholderAlignment(span.alignment); txtSpan.baseline = ConvertTxtTextBaseline(span.baseline); - txtSpan.baseline_offset = span.baseline_offset; + txtSpan.baselineOffset = span.baseline_offset; } - } // namespace OHOS::Ace::Constants diff --git a/frameworks/core/components/font/constants_converter.h b/frameworks/core/components/font/constants_converter.h index f570492756bcbb5c333492a846132195f129b1f4..9fb7256a85ac756ea4add33a152e74ed802775ab 100644 --- a/frameworks/core/components/font/constants_converter.h +++ b/frameworks/core/components/font/constants_converter.h @@ -16,21 +16,26 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_CONSTANTS_CONVERTER_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_CONSTANTS_CONVERTER_H -#include "txt/placeholder_run.h" -#include "txt/text_baseline.h" -#include "txt/text_decoration.h" -#include "txt/text_style.h" -#include "include/core/SkColor.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 TextBaseline; enum class TextDirection; -} // namespace txt +enum class PlaceholderVerticalAlignment; +struct TextStyle; +struct PlaceholderSpan; + +namespace Drawing { +class RectF; +} // namespace Drawing +} // namespace OHOS::Rosen namespace OHOS::Ace { @@ -45,27 +50,28 @@ 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); -txt::PlaceholderAlignment ConvertPlaceholderAlignment(PlaceholderAlignment textDecoration); +OHOS::Rosen::PlaceholderVerticalAlignment ConvertPlaceholderAlignment(PlaceholderAlignment textDecoration); -void ConvertPlaceholderRun(const PlaceholderRun& span, txt::PlaceholderRun& txtSpan); +void ConvertPlaceholderRun(const PlaceholderRun& span, OHOS::Rosen::PlaceholderSpan& txtSpan); } // namespace Constants diff --git a/frameworks/core/components/font/flutter_font_collection.cpp b/frameworks/core/components/font/flutter_font_collection.cpp index ff46e0f2c1e35321682df376ef61e85a6d701a3c..e541d0eee8590f6421757cec713a0fb675ca7d68 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]() { fontCollection_ = std::make_unique(); @@ -46,7 +48,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 43ab8347ca5b20aa6a4397d0b7fb5d7acb5a6161..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 "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 5df023201e8f26ab3bf8d385d25058effe4356a7..a817d4b18a074004688e86a107c833bf213e5724 100644 --- a/frameworks/core/components/font/rosen_font_collection.cpp +++ b/frameworks/core/components/font/rosen_font_collection.cpp @@ -25,17 +25,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_; } @@ -50,15 +49,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); } } @@ -73,18 +64,12 @@ void RosenFontCollection::VaryFontCollectionWithFontWeightScale(float fontWeight return; } - if (fontCollection_) { - fontCollection_->VaryFontCollectionWithFontWeightScale(fontWeightScale); - } } void RosenFontCollection::LoadSystemFont() { ACE_FUNCTION_TRACE(); - if (fontCollection_) { - fontCollection_->LoadSystemFont(); - } } void RosenFontCollection::SetIsZawgyiMyanmar(bool isZawgyiMyanmar) @@ -96,10 +81,6 @@ void RosenFontCollection::SetIsZawgyiMyanmar(bool isZawgyiMyanmar) } isZawgyiMyanmar_ = isZawgyiMyanmar; - if (fontCollection_) { - fontCollection_->SetIsZawgyiMyanmar(isZawgyiMyanmar); - } - AceEngine::Get().NotifyContainers([](const RefPtr& container) { if (container) { container->NotifyFontNodes(); diff --git a/frameworks/core/components/font/rosen_font_collection.h b/frameworks/core/components/font/rosen_font_collection.h index 053c7fbfe91ea45471d1d17ddfecf85eac9db026..eb72e0f3346ada593e5e771a59e0fc9da94f63ba 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,7 @@ public: void SetIsZawgyiMyanmar(bool isZawgyiMyanmar); private: - std::shared_ptr fontCollection_; - sk_sp dynamicFontManager_; + std::shared_ptr fontCollection_; 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 04f3bbcd48242fc3e13f15608e68daaf0a3f68d8..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 "txt/paragraph_builder.h" -#include "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 diff --git a/frameworks/core/components/multimodal/flutter_render_multimodal.h b/frameworks/core/components/multimodal/flutter_render_multimodal.h index a0ce5d96251edc0d7c8f9321d1b05eb190d316c0..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 "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 d1a92ce19e87d11f3b0f39c45b64ad20cfa4a42f..b0ce750d0f6d1ed664aa50f4b17aee068faabc81 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 "txt/paragraph_builder.h" -#include "txt/paragraph_style.h" - -#include "include/core/SkPaint.h" -#include "include/core/SkPoint.h" -#include "include/core/SkRRect.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" @@ -67,8 +66,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 } }; @@ -76,7 +75,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); @@ -85,9 +84,9 @@ 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); #ifndef NEW_SKIA auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); #else @@ -97,14 +96,14 @@ void RosenRenderMultimodal::UpdateParagraph(const Offset& offset, const std::str 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 diff --git a/frameworks/core/components/multimodal/rosen_render_multimodal.h b/frameworks/core/components/multimodal/rosen_render_multimodal.h index 259c061c4285b85ff2374e5ef6623a76ac951b96..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 "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 c956b19a17c06346a822ec953e3f6de4a90eac08..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 "txt/paragraph_builder.h" -#include "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 5a66b023a5a866784cb8ba95b57b804ab6352983..e70c1be4e3891b3306a206b30499a536b7301b8f 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 "txt/paragraph_builder.h" -#include "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 { @@ -371,9 +371,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; } @@ -383,7 +382,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() @@ -442,11 +441,11 @@ void RosenRenderText::ApplyIndents(double width) indents.push_back(0.0); indents.push_back(-indent); } + #ifndef NEW_SKIA // TODO SetIndents need must - auto* paragraphTxt = static_cast(paragraph_.get()); - if (paragraphTxt != nullptr) { - paragraphTxt->SetIndents(indents); + if (paragraph_ != nullptr) { + paragraph_->SetIndents(indents); } #endif } @@ -459,7 +458,7 @@ bool RosenRenderText::UpdateParagraph() using namespace Constants; - txt::ParagraphStyle style; + Rosen::TypographyStyle style; if (alignment_.has_value()) { textStyle_.SetTextAlign(alignment_.value()); @@ -481,34 +480,33 @@ 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; } } #ifndef NEW_SKIA - style.word_break_type = static_cast(textStyle_.GetWordBreak()); + style.wordBreakType_ = static_cast(textStyle_.GetWordBreak()); #endif - 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(); @@ -524,9 +522,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; @@ -540,18 +538,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 449edc7653be61a13e2be51fc231b79560be4df0..042544bc203c9dfe08e7ee511eec9c2255eb0c4c 100644 --- a/frameworks/core/components/text_field/flutter_render_text_field.cpp +++ b/frameworks/core/components/text_field/flutter_render_text_field.cpp @@ -17,9 +17,7 @@ #include -#include "txt/paragraph_builder.h" -#include "txt/paragraph_txt.h" -#include "include/effects/SkGradientShader.h" +#include "third_party/skia/include/effects/SkGradientShader.h" #include "unicode/uchar.h" #include "base/i18n/localization.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,12 @@ 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 +278,8 @@ void FlutterRenderTextField::PaintSelection(SkCanvas* canvas) const void FlutterRenderTextField::DrawSelection(unsigned start, unsigned end, SkCanvas* canvas) const { using namespace Constants; - const auto& boxes = paragraph_->GetRectsForRange( - start, end, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(start, end, + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return; } @@ -291,7 +292,7 @@ void FlutterRenderTextField::DrawSelection(unsigned start, unsigned end, SkCanva } Offset effectiveOffset = innerRect_.GetOffset() + textOffsetForShowCaret_; for (const auto& box : boxes) { - auto selectionRect = ConvertSkRect(box.rect) + effectiveOffset; + auto selectionRect = ConvertSkRect(box.rect_) + effectiveOffset; switch (inputStyle_) { case InputStyle::INLINE: selectionRect.SetHeight(GetLayoutSize().Height()); @@ -303,12 +304,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 +358,7 @@ void FlutterRenderTextField::PaintErrorText(SkCanvas* canvas) const Offset errorOffset = innerRect_.GetOffset(); if (errorIsInner_) { double errorSpacing = - GreatOrEqual(errorParagraph_->GetLongestLine(), originInnerWidth_ - errorSpacing_) ? 0.0 : errorSpacing_; + GreatOrEqual(errorParagraph_->GetActualWidth(), originInnerWidth_ - errorSpacing_) ? 0.0 : errorSpacing_; errorOffset += Offset(innerRect_.Width() + errorSpacing, (innerRect_.Height() - errorParagraph_->GetHeight()) / 2.0); } else { @@ -377,7 +378,7 @@ void FlutterRenderTextField::PaintCountText(SkCanvas* canvas) const } if (ShowCounter()) { Offset countOffset = innerRect_.GetOffset() + - Offset(innerRect_.Width() - countParagraph_->GetLongestLine(), innerRect_.Height()); + Offset(innerRect_.Width() - countParagraph_->GetActualWidth(), innerRect_.Height()); if (maxLines_ == 1) { double bottomPadding = 0.0; if (decoration_) { @@ -542,7 +543,7 @@ Size FlutterRenderTextField::Measure() } auto paragraphStyle = CreateParagraphStyle(); - std::unique_ptr txtStyle; + std::unique_ptr txtStyle; double textAreaWidth = MeasureParagraph(paragraphStyle, txtStyle); ComputeExtendHeight(decorationHeight); @@ -556,15 +557,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 +578,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 +614,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); } } @@ -819,8 +819,8 @@ sk_sp FlutterRenderTextField::MakeGradientShader(double shadeWidth) co #endif } -void FlutterRenderTextField::SetShaderIfNeeded( - std::unique_ptr paragraphStyle, std::unique_ptr txtStyle, double textAreaWidth) +void FlutterRenderTextField::SetShaderIfNeeded(std::unique_ptr paragraphStyle, + std::unique_ptr txtStyle, double textAreaWidth) { if (maxLines_ != 1 || showPlaceholder_ || !paragraph_ || !needFade_) { // Not support placeHolder or multiline. @@ -838,13 +838,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 +869,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 +906,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 +921,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::BREAK_ALL; } 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 +962,24 @@ 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 +999,18 @@ bool FlutterRenderTextField::ComputeOffsetForCaretUpstream(int32_t extent, Caret result.Reset(); int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); while (boxes.empty() && !GetEditingValue().text.empty()) { graphemeClusterLength *= 2; prev = extent - graphemeClusterLength; if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + 0, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); } if (boxes.empty()) { return false; @@ -1021,22 +1022,22 @@ bool FlutterRenderTextField::ComputeOffsetForCaretUpstream(int32_t extent, Caret // Return the start of next line. auto emptyOffset = MakeEmptyOffset(); result.offset.SetX(emptyOffset.GetX()); - result.offset.SetY(textBox.rect.fBottom); + result.offset.SetY(textBox.rect_.GetBottom()); result.height = caretProto_.Height(); return true; } - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the upstream glyphs. - double caretEnd = isLtr ? textBox.rect.fRight : textBox.rect.fLeft; + double caretEnd = isLtr ? textBox.rect_.GetRight() : textBox.rect_.GetLeft(); if (cursorPositionType_ == CursorPositionType::END) { caretEnd = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretEnd : caretEnd - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -1049,24 +1050,24 @@ bool FlutterRenderTextField::ComputeOffsetForCaretDownstream(int32_t extent, Car result.Reset(); const int32_t graphemeClusterLength = 1; const int32_t next = extent + graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - extent, next, txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + auto boxes = paragraph_->GetTextRectsByBoundary( + extent, next, Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return false; } const auto& textBox = *boxes.begin(); - bool isLtr = textBox.direction == txt::TextDirection::ltr; + bool isLtr = textBox.direction_ == Rosen::TextDirection::LTR; // Caret is within width of the downstream glyphs. - double caretStart = isLtr ? textBox.rect.fLeft : textBox.rect.fRight; + double caretStart = isLtr ? textBox.rect_.GetLeft() : textBox.rect_.GetRight(); if (cursorPositionType_ == CursorPositionType::END) { caretStart = GetBoundaryOfParagraph(realTextDirection_ != TextDirection::LTR); } double dx = isLtr ? caretStart : caretStart - caretProto_.Width(); double offsetX = std::min(dx, paragraph_->GetMaxWidth()); result.offset.SetX(offsetX); - result.offset.SetY(textBox.rect.fTop); - result.height = textBox.rect.fBottom - textBox.rect.fTop; + result.offset.SetY(textBox.rect_.GetTop()); + result.height = textBox.rect_.GetBottom() - textBox.rect_.GetTop(); return true; } @@ -1125,23 +1126,23 @@ Offset FlutterRenderTextField::MakeEmptyOffset() const double FlutterRenderTextField::PreferredLineHeight() { if (!template_) { - std::unique_ptr builder = - txt::ParagraphBuilder::CreateTxtBuilder(*CreateParagraphStyle(), GetFontCollection()); + std::unique_ptr builder = + Rosen::TypographyCreate::Create(*CreateParagraphStyle(), GetFontCollection()); builder->PushStyle(*CreateTextStyle(style_)); // Use a space for estimating line height if there is no placeholder. // Actually it has slight differ between cases. if (placeholder_.empty()) { - builder->AddText(u" "); + builder->AppendText(u" "); } else { - builder->AddText(StringUtils::Str8ToStr16(placeholder_)); + builder->AppendText(StringUtils::Str8ToStr16(placeholder_)); } - template_ = builder->Build(); + template_ = builder->CreateTypography(); template_->Layout(Size::INFINITE_SIZE); } return template_->GetHeight(); } -std::shared_ptr FlutterRenderTextField::GetFontCollection() +std::shared_ptr FlutterRenderTextField::GetFontCollection() { return FlutterFontCollection::GetInstance().GetFontCollection(); } @@ -1165,10 +1166,8 @@ int32_t FlutterRenderTextField::GetCursorPositionForMoveUp() return 0; } double verticalOffset = -textOffsetForShowCaret_.GetY() - PreferredLineHeight(); - return static_cast(paragraph_ - ->GetGlyphPositionAtCoordinateWithCluster( - caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset) - .position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate( + caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).index_); } int32_t FlutterRenderTextField::GetCursorPositionForMoveDown() @@ -1177,10 +1176,8 @@ int32_t FlutterRenderTextField::GetCursorPositionForMoveDown() return 0; } double verticalOffset = -textOffsetForShowCaret_.GetY() + PreferredLineHeight(); - return static_cast(paragraph_ - ->GetGlyphPositionAtCoordinateWithCluster( - caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset) - .position); + return static_cast(paragraph_->GetGlyphIndexByCoordinate( + caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).index_); } int32_t FlutterRenderTextField::GetCursorPositionForClick(const Offset& offset) @@ -1196,7 +1193,7 @@ int32_t FlutterRenderTextField::GetCursorPositionForClick(const Offset& offset) return 0; } return static_cast( - paragraph_->GetGlyphPositionAtCoordinateWithCluster(clickOffset_.GetX(), clickOffset_.GetY()).position); + paragraph_->GetGlyphIndexByCoordinate(clickOffset_.GetX(), clickOffset_.GetY()).index_); } int32_t FlutterRenderTextField::AdjustCursorAndSelection(int32_t currentCursorPosition) @@ -1205,7 +1202,7 @@ int32_t FlutterRenderTextField::AdjustCursorAndSelection(int32_t currentCursorPo // Place cursor to the right boundary of paragraph when direction is LTR, // place to the left boundary of paragraph when direction is RTL. auto paragraphStyle = CreateParagraphStyle(); - std::unique_ptr txtStyle; + std::unique_ptr txtStyle; MeasureParagraph(paragraphStyle, txtStyle); Rect tempRect; GetCaretRect(currentCursorPosition, tempRect); diff --git a/frameworks/core/components/text_field/flutter_render_text_field.h b/frameworks/core/components/text_field/flutter_render_text_field.h index aa95b29856baa6f1d1de7182d3892d21306d851c..11ab67969640d6429d24c9f225db4da0a9b22183 100644 --- a/frameworks/core/components/text_field/flutter_render_text_field.h +++ b/frameworks/core/components/text_field/flutter_render_text_field.h @@ -23,12 +23,12 @@ #include "core/components/text_field/render_text_field.h" #include "core/pipeline/layers/clip_layer.h" -namespace txt { +namespace OHOS::Rosen { class FontCollection; -class Paragraph; -class ParagraphStyle; -class TextStyle; -} // namespace txt +class Typography; +struct TypographyStyle; +struct TextStyle; +} // namespace OHOS::Rosen namespace flutter { class Canvas; @@ -74,8 +74,8 @@ protected: void ResetStatus() override; private: - std::unique_ptr CreateParagraphStyle(bool isErrorText = false); - std::unique_ptr CreateTextStyle(const TextStyle& style, bool isPlaceholder = false); + std::unique_ptr CreateParagraphStyle(bool isErrorText = false); + std::unique_ptr CreateTextStyle(const TextStyle& style, bool isPlaceholder = false); double PreferredLineHeight() override; void UpdateCaretProto(); @@ -87,7 +87,7 @@ private: Offset MakeEmptyOffset() const; Size Measure() override; double MeasureParagraph( - const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle); + const std::unique_ptr& paragraphStyle, std::unique_ptr& txtStyle); Size ComputeLayoutSize(const Size& size, double decorationHeight); Rect GetInnerRect(const Decoration& decoration, const Rect& outer, double dipScale) const; @@ -96,10 +96,10 @@ private: void ComputeOffsetAfterLayout(); // Compute the offset to align text and icon to vertical center. Offset ComputeVerticalOffsetForCenter(double outerHeight, double innerHeight) const; - void SetShaderIfNeeded(std::unique_ptr paragraphStyle, - std::unique_ptr txtStyle, double textAreaWidth); + void SetShaderIfNeeded(std::unique_ptr paragraphStyle, + std::unique_ptr txtStyle, double textAreaWidth); sk_sp MakeGradientShader(double shadeWidth) const; - std::shared_ptr GetFontCollection(); + std::shared_ptr GetFontCollection(); void ResetParagraphIfNeeded(); void ComputeExtendHeight(double decorationHeight); double GetBoundaryOfParagraph(bool isLeftBoundary) const; @@ -127,12 +127,12 @@ private: SkVector GetSkRadii(const Radius& radius) const; void PaintFocus(const Offset& offset, const Size& widthHeight, RenderContext& context); - std::unique_ptr paragraph_; - std::unique_ptr errorParagraph_; - std::unique_ptr countParagraph_; - std::unique_ptr placeholderParagraph_; + std::unique_ptr paragraph_; + std::unique_ptr errorParagraph_; + std::unique_ptr countParagraph_; + std::unique_ptr placeholderParagraph_; // Used to estimate size. - std::unique_ptr template_; + std::unique_ptr template_; Rect caretRect_; Rect startCaretRect_; diff --git a/frameworks/core/components/text_field/rosen_render_text_field.cpp b/frameworks/core/components/text_field/rosen_render_text_field.cpp index ea715a7502ea69268ebd3fa8f8d92b55ff7ddb7a..4b930c33ff01ff8baac5612b7b8f606f40ce481b 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 "txt/paragraph_builder.h" -#include "txt/paragraph_txt.h" #include "render_service_client/core/ui/rs_node.h" #include "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,12 @@ 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 +264,8 @@ void RosenRenderTextField::PaintSelection(SkCanvas* canvas) const if (GetEditingValue().text.empty() || selection.GetStart() == selection.GetEnd()) { return; } - const auto& boxes = paragraph_->GetRectsForRange(selection.GetStart(), selection.GetEnd(), - txt::Paragraph::RectHeightStyle::kMax, txt::Paragraph::RectWidthStyle::kTight); + const auto& boxes = paragraph_->GetTextRectsByBoundary(selection.GetStart(), selection.GetEnd(), + Rosen::TextRectHeightStyle::COVER_TOP_AND_BOTTOM, Rosen::TextRectWidthStyle::TIGHT); if (boxes.empty()) { return; } @@ -277,7 +278,7 @@ void RosenRenderTextField::PaintSelection(SkCanvas* canvas) const } Offset effectiveOffset = innerRect_.GetOffset() + textOffsetForShowCaret_; for (const auto& box : boxes) { - auto selectionRect = ConvertSkRect(box.rect) + effectiveOffset; + auto selectionRect = ConvertSkRect(box.rect_) + effectiveOffset; switch (inputStyle_) { case InputStyle::INLINE: selectionRect.SetHeight(GetLayoutSize().Height()); @@ -292,7 +293,7 @@ void RosenRenderTextField::PaintSelection(SkCanvas* canvas) const auto rect = SkRect::MakeLTRB(selectionRect.Right(), selectionRect.Top(), selectionRect.Left(), selectionRect.Bottom()); - if (box.direction == txt::TextDirection::ltr) { + if (box.direction_ == Rosen::TextDirection::LTR) { rect = SkRect::MakeLTRB( selectionRect.Left(), selectionRect.Top(), selectionRect.Right(), selectionRect.Bottom()); } @@ -323,7 +324,7 @@ void RosenRenderTextField::PaintErrorText(SkCanvas* canvas) const Offset errorOffset = innerRect_.GetOffset(); if (errorIsInner_) { double errorSpacing = - GreatOrEqual(errorParagraph_->GetLongestLine(), originInnerWidth_ - errorSpacing_) ? 0.0 : errorSpacing_; + GreatOrEqual(errorParagraph_->GetActualWidth(), originInnerWidth_ - errorSpacing_) ? 0.0 : errorSpacing_; errorOffset += Offset(innerRect_.Width() + errorSpacing, (innerRect_.Height() - errorParagraph_->GetHeight()) / 2.0); } else { @@ -343,7 +344,7 @@ void RosenRenderTextField::PaintCountText(SkCanvas* canvas) const } if (ShowCounter()) { Offset countOffset = innerRect_.GetOffset() + - Offset(innerRect_.Width() - countParagraph_->GetLongestLine(), innerRect_.Height()); + Offset(innerRect_.Width() - countParagraph_->GetActualWidth(), innerRect_.Height()); if (maxLines_ == 1) { double bottomPadding = 0.0; if (decoration_) { @@ -500,7 +501,7 @@ Size RosenRenderTextField::Measure() } auto paragraphStyle = CreateParagraphStyle(); - std::unique_ptr txtStyle; + std::unique_ptr txtStyle; double textAreaWidth = MeasureParagraph(paragraphStyle, txtStyle); ComputeExtendHeight(decorationHeight); @@ -514,15 +515,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 +536,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 +572,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); } } @@ -747,8 +747,8 @@ sk_sp RosenRenderTextField::MakeGradientShader(double shadeWidth) cons #endif } -void RosenRenderTextField::SetShaderIfNeeded( - std::unique_ptr paragraphStyle, std::unique_ptr txtStyle, double textAreaWidth) +void RosenRenderTextField::SetShaderIfNeeded(std::unique_ptr paragraphStyle, + std::unique_ptr txtStyle, double textAreaWidth) { if (maxLines_ != 1 || showPlaceholder_ || !paragraph_ || !needFade_) { // Not support placeHolder or multiline. @@ -766,13 +766,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 +797,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 +834,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,7 +849,7 @@ std::unique_ptr RosenRenderTextField::CreateParagraphStyle( } } if (!existStrongDirectionLetter_) { - style->text_direction = ConvertTxtTextDirection(textDirection_); + style->textDirection_ = ConvertTxtTextDirection(textDirection_); realTextDirection_ = textDirection_; } UpdateDirectionStatus(); @@ -857,27 +857,28 @@ std::unique_ptr RosenRenderTextField::CreateParagraphStyle( #ifndef NEW_SKIA style->word_break_type = minikin::WordBreakType::kWordBreakType_BreakAll; #endif + style->wordBreakType_ = Rosen::WordBreakType::BREAK_ALL; } 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; } @@ -892,23 +893,24 @@ 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; } @@ -928,18 +930,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; @@ -951,22 +953,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; } @@ -979,24 +981,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; } @@ -1055,23 +1057,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(); } @@ -1101,8 +1103,7 @@ int32_t RosenRenderTextField::GetCursorPositionForMoveUp() #else ->GetGlyphPositionAtCoordinate( #endif - caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset) - .position); + caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).index_); } int32_t RosenRenderTextField::GetCursorPositionForMoveDown() @@ -1117,8 +1118,7 @@ int32_t RosenRenderTextField::GetCursorPositionForMoveDown() #else ->GetGlyphPositionAtCoordinate( #endif - caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset) - .position); + caretRect_.Left() - innerRect_.Left(), caretRect_.Top() + verticalOffset).index_); } int32_t RosenRenderTextField::GetCursorPositionForClick(const Offset& offset) @@ -1137,7 +1137,7 @@ int32_t RosenRenderTextField::GetCursorPositionForClick(const Offset& offset) #ifndef NEW_SKIA paragraph_->GetGlyphPositionAtCoordinateWithCluster(clickOffset_.GetX(), clickOffset_.GetY()).position); #else - paragraph_->GetGlyphPositionAtCoordinate(clickOffset_.GetX(), clickOffset_.GetY()).position); + paragraph_->GetGlyphIndexByCoordinate(clickOffset_.GetX(), clickOffset_.GetY()).index_); #endif } @@ -1147,7 +1147,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 ba3ae69f963e65825420ba36bbfea0d5083eac38..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 "txt/paragraph_txt.h" -#include "include/core/SkBitmap.h" -#include "include/core/SkCanvas.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 d3ed11093ebace69903f2c4566c5e0acfeed8256..4ffa86fc41e811395713767844fea8ef9874683e 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 "txt/paragraph_txt.h" +#include "rosen_text/typography.h" #include "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; } @@ -286,14 +287,14 @@ int32_t TextOverlayBase::GetCursorPositionForClick(const Offset& offset, const O rightBoundary - cursorWidth_, clickOffset_.GetY()).position); #else int32_t rightBoundaryPosition = - static_cast(paragraph_->GetGlyphPositionAtCoordinate( - rightBoundary - cursorWidth_, clickOffset_.GetY()).position); + static_cast(paragraph_->GetGlyphIndexByCoordinate( + rightBoundary - cursorWidth_, clickOffset_.GetY()).index_); #endif 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 @@ -373,8 +374,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; } @@ -383,9 +384,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 8b4593d626f0d48389ac43d6c8c7ec4aa0529100..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 "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 80ad6b1ce3b70e245b0f1a6599995e47c905656d..e791cee39935995cca8534dfa92113dfba48ae83 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 daf7a204a6755d9d28911285c27bf5d39f5cc811..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 "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 e28fc01114330e783013dbe7b788ba96c629e553..4b539c29ec8092e33c0a1e10d7151694fc3bebe8 100644 --- a/frameworks/core/components/track/flutter_render_arc_track.cpp +++ b/frameworks/core/components/track/flutter_render_arc_track.cpp @@ -16,12 +16,12 @@ #include "core/components/track/flutter_render_arc_track.h" #include "flutter/lib/ui/painting/path.h" -#include "include/core/SkClipOp.h" -#include "txt/paragraph_builder.h" -#include "txt/paragraph_txt.h" +#include "third_party/skia/include/core/SkClipOp.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 5ce8878536695a739c361fde8738f098f4407300..f1c7836fc68c2d397c5e37f0d66cec94203ea274 100644 --- a/frameworks/core/components/track/rosen_render_arc_track.cpp +++ b/frameworks/core/components/track/rosen_render_arc_track.cpp @@ -15,15 +15,15 @@ #include "core/components/track/rosen_render_arc_track.h" -#include "include/core/SkCanvas.h" -#include "include/core/SkClipOp.h" -#include "include/core/SkPaint.h" -#include "include/core/SkPath.h" -#include "txt/paragraph_builder.h" -#include "txt/paragraph_txt.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkClipOp.h" +#include "third_party/skia/include/core/SkPaint.h" +#include "third_party/skia/include/core/SkPath.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 6a4a5c97ad708e1f3a974575a80d70345c3f7916..af6b86132544195828dc72230e21fafd5b95a3b9 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 (defined(invoker.public_configs)) { public_configs = [] @@ -93,6 +94,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/manager/BUILD.gn b/frameworks/core/components_ng/manager/BUILD.gn index d5cc88e9b50508ac0e968efb693f17761009aab6..90210bbe5e6af9033c959e958c9db005a2d7494f 100644 --- a/frameworks/core/components_ng/manager/BUILD.gn +++ b/frameworks/core/components_ng/manager/BUILD.gn @@ -15,7 +15,7 @@ import( "//foundation/arkui/ace_engine/frameworks/core/components_ng/components.gni") build_component_ng("manager_ng") { - sources = [ + sources = [ "drag_drop/drag_drop_manager.cpp", "drag_drop/drag_drop_proxy.cpp", "full_screen/full_screen_manager.cpp", 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 19d8bc050bc288bdec6383e7076bc02eaae09df9..ad578df234cdaadbd7def9a7540c7bb05280d508 100644 --- a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp @@ -31,6 +31,7 @@ #include "core/components_ng/render/drawing.h" #include "core/components_ng/render/drawing_prop_convertor.h" #include "core/components_ng/render/paint_property.h" +#include "rosen_text/typography_types.h" namespace OHOS::Ace::NG { @@ -43,15 +44,15 @@ constexpr int32_t TEXT_END_INDEX = 2; constexpr int32_t WEEK_TEXT_END_INDEX = 3; constexpr double WEEKEND_TRANSPARENT = 0x7D; -std::unique_ptr GetTextParagraph(const std::string& text, const RSTextStyle& 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( @@ -296,6 +297,7 @@ void CalendarPaintMethod::PaintDay( } void CalendarPaintMethod::PaintLunarDay( +<<<<<<< HEAD RSCanvas& canvas, const Offset& offset, const CalendarDay& day, const RSTextStyle& textStyle) const { Rect boxRect = { offset.GetX(), offset.GetY(), dayWidth_, lunarDayHeight_ }; @@ -306,6 +308,7 @@ void CalendarPaintMethod::DrawWeek(RSCanvas& canvas, const Offset& offset) const { uint32_t totalWeek = weekNumbers_.size(); RSTextStyle weekTextStyle; + Rosen::TextStyle weekTextStyle; weekTextStyle.color_ = weekColor_; weekTextStyle.fontSize_ = weekFontSize_; weekTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); 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 08a5173f6e8653ec6f50b479629b3e542c26dbd8..7528a9012c355ad20fe242944a2b3b77f54107ec 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 "txt/paragraph_builder.h" -#include "txt/paragraph_style.h" #include "include/core/SkImage.h" #include "include/core/SkMaskFilter.h" #include "include/encode/SkJpegEncoder.h" @@ -37,6 +35,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 { @@ -384,21 +384,21 @@ 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()); #ifndef NEW_SKIA auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); #else auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); #endif 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(); } @@ -406,21 +406,21 @@ 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()); #ifndef NEW_SKIA auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); #else auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); #endif 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(); } @@ -429,21 +429,21 @@ 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()); #ifndef NEW_SKIA auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); #else auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); #endif 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(); @@ -484,7 +484,34 @@ void CanvasPaintMethod::PaintText( paragraph_->Paint(skCanvas_.get(), dx, dy); } -double CanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph) +double CanvasPaintMethod::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) +{ + double x = 0.0; + TextDirection textDirection = TextDirection::LTR; + switch (align) { + case TextAlign::LEFT: + x = 0.0; + break; + case TextAlign::START: + x = (textDirection == TextDirection::LTR) ? 0.0 : -paragraph->GetMaxIntrinsicWidth(); + break; + case TextAlign::RIGHT: + x = -paragraph->GetMaxIntrinsicWidth(); + break; + case TextAlign::END: + x = (textDirection == TextDirection::LTR) ? -paragraph->GetMaxIntrinsicWidth() : 0.0; + break; + case TextAlign::CENTER: + x = -paragraph->GetMaxIntrinsicWidth() / 2; + break; + default: + x = 0.0; + break; + } + return x; +} + +double CanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph) { double y = 0.0; switch (baseline) { @@ -516,29 +543,30 @@ 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()); } if (fillState_.GetOffTextDirection() == TextDirection::RTL) { - style.text_direction = txt::TextDirection::rtl; + style.textDirection_ = OHOS::Rosen::TextDirection::RTL; } - style.text_align = GetEffectiveAlign(style.text_align, style.text_direction); -#ifndef NEW_SKIA + style.textAlign_ = GetEffectiveAlign(style.textAlign_, style.textDirection_); auto fontCollection = FlutterFontCollection::GetInstance().GetFontCollection(); #else auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); #endif 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(); + 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); #ifndef NEW_SKIA txtShadow.blur_radius = shadow_.GetBlurRadius(); #else @@ -546,21 +574,21 @@ bool CanvasPaintMethod::UpdateParagraph(const OffsetF& offset, const std::string #endif txtStyle.text_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; @@ -572,13 +600,12 @@ void CanvasPaintMethod::UpdateTextStyleForeground( #endif 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; #ifndef NEW_SKIA @@ -590,8 +617,7 @@ void CanvasPaintMethod::UpdateTextStyleForeground( 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 { @@ -605,7 +631,7 @@ void CanvasPaintMethod::UpdateTextStyleForeground( #endif 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()); } @@ -614,8 +640,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 63254ddf4bb2e77fb4f6387775c75addaa621e28..5c6d06ccda7be45e5a11c2e401a08ddb3c8423ca 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; @@ -82,9 +84,9 @@ private: void PaintText( const OffsetF& offset, const SizeF& contentSize, double x, double y, bool isStroke, bool hasShadow = false); - double GetBaselineOffset(TextBaseline baseline, 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.cpp b/frameworks/core/components_ng/pattern/custom_paint/custom_paint_paint_method.cpp index 7b1a92dc025bdb78310a8b56b8331fa583d8ab47..ead5f2ad7b197f66f4d9d94fd49d1e7a05c4a9d2 100644 --- a/frameworks/core/components_ng/pattern/custom_paint/custom_paint_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/custom_paint/custom_paint_paint_method.cpp @@ -1208,7 +1208,7 @@ void CustomPaintPaintMethod::Translate(double x, double y) skCanvas_->translate(x, y); } -double CustomPaintPaintMethod::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) +double CustomPaintPaintMethod::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph) { double x = 0.0; TextDirection textDirection = fillState_.GetOffTextDirection(); @@ -1235,14 +1235,14 @@ double CustomPaintPaintMethod::GetAlignOffset(TextAlign align, std::unique_ptr& paragraph); - txt::TextAlign GetEffectiveAlign(txt::TextAlign align, txt::TextDirection direction) const; + double GetAlignOffset(TextAlign align, std::unique_ptr& paragraph); + OHOS::Rosen::TextAlign GetEffectiveAlign(OHOS::Rosen::TextAlign align, OHOS::Rosen::TextDirection direction) const; PaintState fillState_; StrokePaintState strokeState_; @@ -375,7 +375,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 54e2acad2b4edb9190a3433af0e837fa58f11049..4c937c460da2b53f62740168d144a18dffdb7271 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,8 +15,6 @@ #include "core/components_ng/pattern/custom_paint/offscreen_canvas_paint_method.h" -#include "txt/paragraph_builder.h" -#include "txt/paragraph_style.h" #include "include/core/SkMaskFilter.h" #ifndef NEW_SKIA #include "include/effects/SkBlurImageFilter.h" @@ -42,6 +40,8 @@ #include "core/components/font/flutter_font_collection.h" #endif #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 { @@ -312,18 +312,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()); - auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); + 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(); } @@ -331,18 +331,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()); - auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); + 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(); } @@ -351,18 +351,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()); - auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); + 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(); @@ -400,7 +400,34 @@ void OffscreenCanvasPaintMethod::PaintText( paragraph_->Paint(skCanvas_.get(), dx, dy); } -double OffscreenCanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph) +double OffscreenCanvasPaintMethod::GetAlignOffset(const std::string& text, TextAlign align, + std::unique_ptr& paragraph) +{ + double x = 0.0; + switch (align) { + case TextAlign::LEFT: + x = 0.0; + break; + case TextAlign::START: + x = (GetTextDirection(text) == TextDirection::LTR) ? 0.0 : -paragraph->GetMaxIntrinsicWidth(); + break; + case TextAlign::RIGHT: + x = -paragraph->GetMaxIntrinsicWidth(); + break; + case TextAlign::END: + x = (GetTextDirection(text) == TextDirection::LTR) ? -paragraph->GetMaxIntrinsicWidth() : 0.0; + break; + case TextAlign::CENTER: + x = -paragraph->GetMaxIntrinsicWidth() / 2; + break; + default: + x = 0.0; + break; + } + return x; +} + +double OffscreenCanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std::unique_ptr& paragraph) { double y = 0.0; switch (baseline) { @@ -429,49 +456,50 @@ double OffscreenCanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std: return y; } -bool OffscreenCanvasPaintMethod::UpdateOffParagraph(const std::string& text, bool isStroke, const PaintState& state, bool hasShadow) +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()); } if (fillState_.GetOffTextDirection() == TextDirection::RTL) { - style.text_direction = txt::TextDirection::rtl; + style.textDirection_ = OHOS::Rosen::TextDirection::RTL; } - style.text_align = GetEffectiveAlign(style.text_align, style.text_direction); - auto fontCollection = RosenFontCollection::GetInstance().GetFontCollection(); + style.textAlign_ = GetEffectiveAlign(style.textAlign_, style.textDirection_); + 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(); + Rosen::TextShadow txtShadow; + txtShadow.color_ = shadow_.GetColor().GetValue(); + txtShadow.offset_.SetX(shadow_.GetOffset().GetX()); + txtShadow.offset_.SetY(shadow_.GetOffset().GetY()); #ifndef NEW_SKIA - txtShadow.blur_radius = shadow_.GetBlurRadius(); + txtShadow.blurRadius_ = shadow_.GetBlurRadius(); #else - txtShadow.blur_sigma = shadow_.GetBlurRadius(); + //TODO txtShadow.blur_sigma #endif - txtStyle.text_shadows.emplace_back(txtShadow); + txtStyle.shadows_.emplace_back(txtShadow); } - txtStyle.locale = Localization::GetInstance()->GetFontLocale(); + 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; @@ -483,13 +511,12 @@ void OffscreenCanvasPaintMethod::UpdateTextStyleForeground(bool isStroke, txt::T #endif 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; #ifndef NEW_SKIA @@ -500,8 +527,7 @@ void OffscreenCanvasPaintMethod::UpdateTextStyleForeground(bool isStroke, txt::T #endif paint.setColor(fillState_.GetColor().GetValue()); paint.setAlphaf(globalState_.GetAlpha()); // set alpha after color - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } } else { @@ -514,7 +540,7 @@ void OffscreenCanvasPaintMethod::UpdateTextStyleForeground(bool isStroke, txt::T GetStrokePaint(paint, options); #endif 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()); } @@ -523,8 +549,7 @@ void OffscreenCanvasPaintMethod::UpdateTextStyleForeground(bool isStroke, txt::T paint.setMaskFilter(SkMaskFilter::MakeBlur(SkBlurStyle::kNormal_SkBlurStyle, NG::SkiaDecorationPainter::ConvertRadiusToSigma(shadow_.GetBlurRadius()))); } - txtStyle.foreground = paint; - txtStyle.has_foreground = true; + txtStyle.foreground_ = paint; } } 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 59cd6891c9ff63bbfa526b488baae7c5affa20b6..498c2fec2066475369d80a0018010e89e7391687 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; @@ -55,9 +57,9 @@ private: sk_sp GetImage(const std::string& src) override { return sk_sp(); } void PaintText(const std::string& text, double x, double y, bool isStroke, bool hasShadow = false); - double GetBaselineOffset(TextBaseline baseline, 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, OHOS::Rosen::TextStyle& txtStyle, bool hasShadow); void PaintShadow(const SkPath& path, const Shadow& shadow, SkCanvas* canvas) override; void Path2DRect(const OffsetF& offset, const PathArgs& args) override; SkCanvas* GetRawPtrOfSkCanvas() 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 afc8aca64b91f05d13dc6221b9438043842fab5d..72ad6584adde149df748f4959ac670d1298d1737 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 @@ -246,7 +246,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)) { @@ -266,7 +266,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); } @@ -277,9 +277,9 @@ 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))); auto imageHotZoneWidth = imageSize + pattern->GetIconRightOffset(); - return SizeF(idealWidth - imageHotZoneWidth, std::min(idealHeight, preferredHeight)); + return SizeF(idealWidth - imageSize, std::min(idealHeight, preferredHeight)); } void TextFieldLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) @@ -455,18 +455,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()); } @@ -487,7 +487,7 @@ void TextFieldLayoutAlgorithm::CreateParagraph(const std::vector& tex 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()); for (size_t i = 0; i < contents.size(); i++) { std::string splitStr = contents[i]; if (splitStr.empty()) { @@ -497,15 +497,15 @@ void TextFieldLayoutAlgorithm::CreateParagraph(const std::vector& tex builder->PushStyle(ToRSTextStyle(PipelineContext::GetCurrentContext(), style)); StringUtils::TransformStrCase(splitStr, static_cast(style.GetTextCase())); if (needObscureText) { - builder->AddText( + builder->AppendText( TextFieldPattern::CreateObscuredText(static_cast(StringUtils::ToWstring(splitStr).length()))); } else { - builder->AddText(StringUtils::Str8ToStr16(splitStr)); + builder->AppendText(StringUtils::Str8ToStr16(splitStr)); } } - 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 b60e1a8c5598950a792ec058143b6644e13093cb..053a428c3c1a205fade36ded552effa018299284 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 @@ -743,12 +743,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, + RSTextRectHeightStyle::COVER_TOP_AND_BOTTOM, RSTextRectWidthStyle::TIGHT); } } @@ -763,8 +763,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( - extent, next, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + auto textBoxes = paragraph_->GetTextRectsByBoundary( + next, extent, RSTextRectHeightStyle::COVER_TOP_AND_BOTTOM, RSTextRectWidthStyle::TIGHT); if (textBoxes.empty()) { LOGD("Box empty"); @@ -808,18 +808,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, RSTextRectHeightStyle::COVER_TOP_AND_BOTTOM, RSTextRectWidthStyle::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, RSTextRectHeightStyle::COVER_TOP_AND_BOTTOM, RSTextRectWidthStyle::TIGHT); break; } - boxes = paragraph_->GetRectsForRange( - prev, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); + boxes = paragraph_->GetTextRectsByBoundary( + prev, extent, RSTextRectHeightStyle::COVER_TOP_AND_BOTTOM, RSTextRectWidthStyle::TIGHT); } if (boxes.empty()) { LOGD("Empty box"); @@ -862,7 +862,8 @@ OffsetF TextFieldPattern::MakeEmptyOffset() const int32_t TextFieldPattern::ConvertTouchOffsetToCaretPosition(const Offset& localOffset) { CHECK_NULL_RETURN(paragraph_, 0); - return static_cast(paragraph_->GetGlyphPositionAtCoordinate(localOffset.GetX(), localOffset.GetY()).pos_); + return static_cast( + paragraph_->GetGlyphIndexByCoordinate(localOffset.GetX(), localOffset.GetY()).index_); } bool TextFieldPattern::DisplayPlaceHolder() @@ -2008,7 +2009,7 @@ void TextFieldPattern::ProcessOverlay() void TextFieldPattern::CreateHandles() { - std::vector tmp; + std::vector tmp; GetTextRectsInRange(textSelector_.GetStart(), textSelector_.GetEnd(), tmp); auto firstHandlePosition = CalcCursorOffsetByPosition(textSelector_.GetStart()); OffsetF firstHandleOffset(firstHandlePosition.offset.GetX() + parentGlobalOffset_.GetX(), @@ -2914,18 +2915,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()); @@ -2994,7 +2995,7 @@ bool TextFieldPattern::CursorMoveUp() #ifndef NEW_SKIA paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), verticalOffset).pos_); #else - paragraph_->GetGlyphPositionAtCoordinate(caretRect_.GetX(), verticalOffset).pos_); + paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), verticalOffset).index_); #endif OnCursorMoveDone(); if (originCaretPosition == textEditingValue_.caretPosition) { @@ -3013,7 +3014,7 @@ bool TextFieldPattern::CursorMoveDown() #ifndef NEW_SKIA paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), verticalOffset).pos_); #else - paragraph_->GetGlyphPositionAtCoordinate(caretRect_.GetX(), verticalOffset).pos_); + paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), verticalOffset).index_); #endif OnCursorMoveDone(); if (originCaretPosition == textEditingValue_.caretPosition) { @@ -3313,7 +3314,7 @@ void TextFieldPattern::HandleSelectionUp() #ifndef NEW_SKIA static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), newOffsetY).pos_); #else - static_cast(paragraph_->GetGlyphPositionAtCoordinate(caretRect_.GetX(), newOffsetY).pos_); + static_cast(paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), newOffsetY).index_); #endif textSelector_.destinationOffset = textEditingValue_.caretPosition; selectionMode_ = SelectionMode::SELECT; @@ -3338,7 +3339,7 @@ void TextFieldPattern::HandleSelectionDown() #ifndef NEW_SKIA static_cast(paragraph_->GetGlyphPositionAtCoordinateWithCluster(caretRect_.GetX(), newOffsetY).pos_); #else - static_cast(paragraph_->GetGlyphPositionAtCoordinate(caretRect_.GetX(), newOffsetY).pos_); + static_cast(paragraph_->GetGlyphIndexByCoordinate(caretRect_.GetX(), newOffsetY).index_); #endif textSelector_.destinationOffset = textEditingValue_.caretPosition; selectionMode_ = SelectionMode::SELECT; 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 177d7aa85ed69190657f6ca0584da96cc420f347..55ecda48c245f0d3672da2a7e633455dc451d581 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 @@ -52,6 +52,7 @@ #include "core/components_ng/pattern/text_field/text_selector.h" #include "core/components_ng/property/property.h" #include "core/gestures/gesture_info.h" +#include "rosen_text/typography.h" #if not defined(ACE_UNITTEST) #if defined(ENABLE_STANDARD_INPUT) @@ -412,7 +413,7 @@ public: void HandleExtendAction(int32_t action); void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip); - std::vector GetTextBoxes() override + std::vector& GetTextBoxes() override { return textBoxes_; } @@ -819,7 +820,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(); @@ -929,7 +930,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 8dc3506065c1c38908fc08b586a886848d7391c9..99b157ad583c8fa44a18230f901dfc20ac616d66 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp @@ -113,6 +113,7 @@ void SwitchModifier::PaintSwitch(RSCanvas& canvas, const OffsetF& contentOffset, hoverBoardOffset.SetX(xOffset - (actualWidth_ - width) / 2.0); hoverBoardOffset.SetY(yOffset - (actualHeight_ - height) / 2.0); DrawTouchAndHoverBoard(canvas, hoverBoardOffset); + RSRect rect; rect.SetLeft(xOffset); rect.SetTop(yOffset); 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 2a221cf557f6c4eed1f389a2c5b39a1fbf5d94f3..7b57733a15dcbac23276bf12d261d61c0119e6c9 100644 --- a/frameworks/core/components_ng/render/adapter/focus_state_modifier.h +++ b/frameworks/core/components_ng/render/adapter/focus_state_modifier.h @@ -48,17 +48,17 @@ public: void SetRoundRect(const RoundRect& rect, float borderWidth) { 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..7a6a7c0ae1847c140bf73714a8eb2c9b4696af6e 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,10 @@ 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(); } -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..e321a9c46ce17695a2c59dcdd2ffe91bf36717f1 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,29 @@ #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_; }; } // 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 7800f203c44091904ed1ec0225d53b537099e8b6..9f735542be2205ac73d4bff3b7adc9ecc2faae3f 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; } #if !defined(FLUTTER_2_5) && !defined(NEW_SKIA) // 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,7 +79,7 @@ void TxtParagraph::AddText(const std::u16string& text) CreateBuilder(); } text_ = text; - builder_->AddText(text); + builder_->AppendText(text); } int32_t TxtParagraph::AddPlaceholder(const PlaceholderRun& span) @@ -87,16 +87,16 @@ int32_t TxtParagraph::AddPlaceholder(const PlaceholderRun& span) if (!builder_) { CreateBuilder(); } - txt::PlaceholderRun txtSpan; + OHOS::Rosen::PlaceholderSpan txtSpan; Constants::ConvertPlaceholderRun(span, txtSpan); - builder_->AddPlaceholder(txtSpan); + builder_->AppendPlaceholder(txtSpan); return ++placeHolderIndex_; } void TxtParagraph::Build() { CHECK_NULL_VOID_NOLOG(builder_); - paragraph_ = builder_->Build(); + paragraph_ = builder_->CreateTypography(); } void TxtParagraph::Reset() @@ -122,9 +122,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() @@ -142,7 +142,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() @@ -159,9 +159,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) @@ -183,7 +182,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) @@ -200,18 +199,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; @@ -222,17 +221,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; } @@ -246,34 +245,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) { - CHECK_NULL_VOID(paragraph_); - 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); } } @@ -281,12 +279,12 @@ void TxtParagraph::GetRectsForRange(int32_t start, int32_t end, std::vector& selectedRects) { CHECK_NULL_VOID(paragraph_); - const auto& boxes = paragraph_->GetRectsForPlaceholders(); + const auto& boxes = paragraph_->GetTextRectsOfPlaceholders(); 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); } } @@ -294,7 +292,7 @@ void TxtParagraph::GetRectsForPlaceholders(std::vector& selectedRects) void TxtParagraph::SetIndents(const std::vector& indents) { #ifndef NEW_SKIA - auto* paragraphTxt = static_cast(paragraph_.get()); + auto* paragraphTxt = static_cast(paragraph_.get()); CHECK_NULL_VOID(paragraphTxt); paragraphTxt->SetIndents(indents); #endif diff --git a/frameworks/core/components_ng/render/adapter/txt_paragraph.h b/frameworks/core/components_ng/render/adapter/txt_paragraph.h index 987f56657a5b618381154bd34e44bad390b54945..ff140027e582a4ea282c8a3424a1665e123b52eb 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 "txt/font_collection.h" -#include "txt/paragraph_builder.h" -#include "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; @@ -73,9 +70,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_; int32_t placeHolderIndex_ = -1; diff --git a/frameworks/core/components_ng/render/drawing.h b/frameworks/core/components_ng/render/drawing.h index 83b8a0bbbf9b17f78fe32a4c68505c2b2afe55c0..045e0ee46e5717e64fa11b230c1678e432f55b0a 100644 --- a/frameworks/core/components_ng/render/drawing.h +++ b/frameworks/core/components_ng/render/drawing.h @@ -22,12 +22,13 @@ #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/typography_types.h" +#include "rosen_text/text_style.h" #include "utils/scalar.h" namespace OHOS::Ace { @@ -48,7 +49,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 RSPathOp = Rosen::Drawing::PathOp; using RSBitmap = Rosen::Drawing::Bitmap; @@ -64,25 +64,28 @@ using RSMaskFilter = Rosen::Drawing::MaskFilter; using RSBlurType = Rosen::Drawing::BlurType; using RSPathFillType = Rosen::Drawing::PathFillType; using RSSkPath = Rosen::Drawing::SkiaPath; -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 RSFontStyle = rosen::FontStyle; -using RSTextBaseline = rosen::TextBaseline; +using RSColorQuad = Rosen::Drawing::ColorQuad; +using RSShaderEffect = Rosen::Drawing::ShaderEffect; +using RSTileMode = Rosen::Drawing::TileMode; + +using RSTextDirection = Rosen::TextDirection; +using RSTextAlign = Rosen::TextAlign; +using RSWordBreakType = Rosen::WordBreakType; +using RSTextBaseline = Rosen::TextBaseline; +using RSTextStyle = Rosen::TextStyle; +using RSTextDecoration = Rosen::TextDecoration; +using RSFontWeight = Rosen::FontWeight; +using RSFontStyle = Rosen::FontStyle; +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 RSTextRectHeightStyle = Rosen::TextRectHeightStyle; +using RSTextRectWidthStyle = Rosen::TextRectWidthStyle; +using RSTextRect = Rosen::TextRect; } // namespace OHOS::Ace #else #include "core/components_ng/render/drawing_mock.h" diff --git a/frameworks/core/components_ng/render/drawing_mock.h b/frameworks/core/components_ng/render/drawing_mock.h index f7ee9d2bc2a2824014897f4bcf49bf6124f7589b..b71e319c061f1ef8618c5ce18a9822791db82dc1 100644 --- a/frameworks/core/components_ng/render/drawing_mock.h +++ b/frameworks/core/components_ng/render/drawing_mock.h @@ -80,6 +80,9 @@ using RSScalar = float; using RSPathFillType = Testing::TestingPathFillType; using RSParagraph = Testing::TestingTypography; using RSTypographyProperties = Testing::TestingTypographyProperties; +using RSTextRectHeightStyle = Testing::TestingTypographyProperties::TextRectHeightStyle; +using RSTextRectWidthStyle = Testing::TestingTypographyProperties::TextRectWidthStyle; +using RSTextRect = Testing::TestingTypographyProperties::TextRect; using RSParagraphStyle = Testing::TestingTypographyStyle; using RSParagraphBuilder = Testing::TestingTypographyCreate; using RSFontCollection = Testing::TestingFontCollection; diff --git a/frameworks/core/components_ng/render/drawing_prop_convertor.cpp b/frameworks/core/components_ng/render/drawing_prop_convertor.cpp index e0f4d06b9b1c2852d9428dae04cf10e04962bf6f..61b089eb42c1f49046a66a642ad81c796f541f01 100644 --- a/frameworks/core/components_ng/render/drawing_prop_convertor.cpp +++ b/frameworks/core/components_ng/render/drawing_prop_convertor.cpp @@ -140,7 +140,7 @@ RSTextDecoration ToRSTextDecoration(TextDecoration textDecoration) rsTextDecoration = RSTextDecoration::OVERLINE; break; case TextDecoration::LINE_THROUGH: - rsTextDecoration = RSTextDecoration::LINETHROUGH; + rsTextDecoration = RSTextDecoration::LINE_THROUGH; break; case TextDecoration::UNDERLINE: rsTextDecoration = RSTextDecoration::UNDERLINE; @@ -163,7 +163,7 @@ 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.baseline_ = static_cast(textStyle.GetTextBaseline()); rsTextStyle.fontFamilies_ = textStyle.GetFontFamilies(); if (textStyle.GetTextOverflow() == TextOverflow::ELLIPSIS) { rsTextStyle.ellipsis_ = StringUtils::Str8ToStr16(StringUtils::ELLIPSIS); @@ -190,24 +190,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/base/view_abstract/BUILD.gn b/frameworks/core/components_ng/test/base/view_abstract/BUILD.gn index ac5d4bdf635efa00b0c58296bd4156aeb1dd9b00..4f92b9ee8f378b50b553a8d385f780d3bc7f0187 100755 --- a/frameworks/core/components_ng/test/base/view_abstract/BUILD.gn +++ b/frameworks/core/components_ng/test/base/view_abstract/BUILD.gn @@ -16,6 +16,12 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("view_abstract_test") { module_out_path = base_test_output_path + include_dirs = [ + "//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", + "//third_party/flutter/skia", +] sources = [ "$ace_root/frameworks/base/geometry/dimension.cpp", diff --git a/frameworks/core/components_ng/test/base/view_abstract_model/BUILD.gn b/frameworks/core/components_ng/test/base/view_abstract_model/BUILD.gn index 3f1a7d52dc73a4928b6d71d37c6c2de19151f81d..c55a4e7a561a8f6f511b3a23c03f6513d08d67da 100755 --- a/frameworks/core/components_ng/test/base/view_abstract_model/BUILD.gn +++ b/frameworks/core/components_ng/test/base/view_abstract_model/BUILD.gn @@ -17,6 +17,12 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("view_abstract_model_test_ng") { module_out_path = base_test_output_path + include_dirs = [ + "//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", + "//third_party/flutter/skia", +] sources = [ "$ace_root/frameworks/base/geometry/dimension.cpp", diff --git a/frameworks/core/components_ng/test/event/gesture_event_hub/BUILD.gn b/frameworks/core/components_ng/test/event/gesture_event_hub/BUILD.gn index 343ae92ceaff554f0d1008027bf6f3750489920d..a9e17fa436ce6265b6919bb3ff75c2571bf00e7a 100644 --- a/frameworks/core/components_ng/test/event/gesture_event_hub/BUILD.gn +++ b/frameworks/core/components_ng/test/event/gesture_event_hub/BUILD.gn @@ -17,6 +17,13 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("gesture_event_hub_test_ng") { module_out_path = event_test_output_path + include_dirs = [ + "//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", + "//third_party/flutter/skia" + ] + sources = [ # inner "$ace_root/frameworks/base/geometry/dimension.cpp", 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 0a12f6d29544c70da216e95c49131a43cd5703bb..e3b1ec722f169e46a42bc5a81fa12d82e341f5bf 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 @@ -87,6 +87,6 @@ ohos_unittest("drag_drop_manager_test_ng") { "$ace_root:ace_test_config", "$ace_root:ace_config", "//commonlibrary/c_utils/base:utils_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", ] } diff --git a/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_proxy/BUILD.gn b/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_proxy/BUILD.gn index a5dd85d603b28bdd1649f307e3147715129274ee..1319b8f48414b89a76665eb99a9dcfec8ca31add 100644 --- a/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_proxy/BUILD.gn +++ b/frameworks/core/components_ng/test/manager/drag_drop/drag_drop_proxy/BUILD.gn @@ -75,6 +75,6 @@ ohos_unittest("drag_drop_proxy_test_ng") { "$ace_root:ace_test_config", "$ace_root:ace_config", "//commonlibrary/c_utils/base:utils_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", ] } diff --git a/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_manager/BUILD.gn b/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_manager/BUILD.gn index 1636932e2ebfef1a983429beea215819b8f0dc2c..f66ffb05ef6500148ddf1a6afb300a3d3e412629 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 @@ -72,6 +72,6 @@ ohos_unittest("select_overlay_manager_test_ng") { "$ace_root:ace_test_config", "$ace_root:ace_config", "//commonlibrary/c_utils/base:utils_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", ] } diff --git a/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_proxy/BUILD.gn b/frameworks/core/components_ng/test/manager/select_overlay/select_overlay_proxy/BUILD.gn index 793a4dfb77555fe003dda924164ca4c47667bd82..518270c404e7cbca9bc6fcb220079bd77c47fb3a 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,6 @@ ohos_unittest("select_overlay_proxy_test_ng") { "$ace_root:ace_test_config", "$ace_root:ace_config", "//commonlibrary/c_utils/base:utils_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", ] } diff --git a/frameworks/core/components_ng/test/mock/rosen/testing_font_collection.h b/frameworks/core/components_ng/test/mock/rosen/testing_font_collection.h index 53c7095ec92cc96389ba9fb3b32c80331ad4cc6c..1be4de716d4553eb498ee36ed04f2eb53b4e6373 100644 --- a/frameworks/core/components_ng/test/mock/rosen/testing_font_collection.h +++ b/frameworks/core/components_ng/test/mock/rosen/testing_font_collection.h @@ -32,6 +32,15 @@ public: { return std::make_shared(); } + + static std::shared_ptr Create() + { + return std::make_shared(); + } + + +private: + static std::shared_ptr instance; }; } // namespace OHOS::Ace::Testing #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_FONT_COLLECTION_H diff --git a/frameworks/core/components_ng/test/mock/rosen/testing_text_style.h b/frameworks/core/components_ng/test/mock/rosen/testing_text_style.h index d2cebf4dbc6c96789f429e98e084a8cfd27f6c47..9a3d8f80157f0df276a40b10e28bf7c616582415 100644 --- a/frameworks/core/components_ng/test/mock/rosen/testing_text_style.h +++ b/frameworks/core/components_ng/test/mock/rosen/testing_text_style.h @@ -40,7 +40,7 @@ enum class TestingTextDecoration { NONE = 0x0, UNDERLINE = 0x1, OVERLINE = 0x2, - LINETHROUGH = 0x4, + LINE_THROUGH = 0x4, }; enum class TestingTextDecorationStyle { @@ -96,8 +96,8 @@ public: double fontSize_ = 14.0; double letterSpacing_ = 0.0; double wordSpacing_ = 0.0; - double height_ = 1.0; - bool hasHeightOverride_ = false; + double heightScale_ = 1.0; + bool heightOnly_ = false; bool hasBackground_ = false; bool hasForeground_ = false; std::u16string ellipsis_; @@ -111,7 +111,7 @@ public: TestingTextDecorationStyle decorationStyle_ = TestingTextDecorationStyle::SOLID; TestingFontWeight fontWeight_ = TestingFontWeight::W400; TestingFontStyle fontStyle_ = TestingFontStyle::NORMAL; - TestingTextBaseline textBaseline_ = TestingTextBaseline::ALPHABETIC; + TestingTextBaseline baseline_ = TestingTextBaseline::ALPHABETIC; std::vector textShadows_; TestingFontFeatures fontFeatures_; }; diff --git a/frameworks/core/components_ng/test/mock/rosen/testing_typography.h b/frameworks/core/components_ng/test/mock/rosen/testing_typography.h index 754178a9e798674596044aa7e64805919990a8ea..24910745311e44f99dc150f74a5a4bdecb2cc54f 100644 --- a/frameworks/core/components_ng/test/mock/rosen/testing_typography.h +++ b/frameworks/core/components_ng/test/mock/rosen/testing_typography.h @@ -55,7 +55,7 @@ public: return 1.0; } - virtual double GetLongestLine() + virtual double GetActualWidth() { return 1.0; } @@ -67,22 +67,22 @@ public: virtual void Paint(TestingCanvas* canvas, double x, double y) {} - virtual std::vector GetRectsForRange(size_t /* start */, size_t /* end */, - TestingTypographyProperties::RectHeightStyle /* height */, - TestingTypographyProperties::RectWidthStyle /* width */) + virtual std::vector GetTextRectsByBoundary(size_t /* start */, size_t /* end */, + TestingTypographyProperties::TextRectHeightStyle /* height */, + TestingTypographyProperties::TextRectWidthStyle /* width */) { return {}; } - virtual TestingTypographyProperties::PositionAndAffinity GetGlyphPositionAtCoordinateWithCluster(double x, double y) + virtual TestingTypographyProperties::IndexAndAffinity GetGlyphIndexByCoordinate(double x, double y) { - TestingTypographyProperties::PositionAndAffinity res(1, TestingTypographyProperties::Affinity::UPSTREAM); + TestingTypographyProperties::IndexAndAffinity res(1, TestingTypographyProperties::Affinity::PREV); return res; } - virtual TestingTypographyProperties::PositionAndAffinity GetGlyphPositionAtCoordinate(double x, double y) + virtual TestingTypographyProperties::IndexAndAffinity GetGlyphPositionAtCoordinate(double x, double y) { - TestingTypographyProperties::PositionAndAffinity res(1, TestingTypographyProperties::Affinity::UPSTREAM); + TestingTypographyProperties::IndexAndAffinity res(1, TestingTypographyProperties::Affinity::PREV); return res; } }; diff --git a/frameworks/core/components_ng/test/mock/rosen/testing_typography_create.h b/frameworks/core/components_ng/test/mock/rosen/testing_typography_create.h index 68ba86ee2812ae33be093efbe3d6d5c7086fef91..1bcc3a16eca9d9e991639f6375720fca5850314f 100644 --- a/frameworks/core/components_ng/test/mock/rosen/testing_typography_create.h +++ b/frameworks/core/components_ng/test/mock/rosen/testing_typography_create.h @@ -36,11 +36,22 @@ public: return std::make_unique(); } + static std::unique_ptr Create(const TestingTypographyStyle& style, + std::shared_ptr collection) + { + return std::make_unique(); + } + + std::unique_ptr CreateTypography() + { + return std::make_unique(); + } + virtual void PushStyle(const TestingTextStyle& style) {} - virtual void Pop() {} + virtual void PopStyle() {} - virtual void AddText(const std::u16string& text) {} + virtual void AppendText(const std::u16string& text) {} virtual std::unique_ptr Build() { diff --git a/frameworks/core/components_ng/test/mock/rosen/testing_typography_properties.h b/frameworks/core/components_ng/test/mock/rosen/testing_typography_properties.h index 02c68ac55314189aaf6bb355ac0334f6ae37b08c..f80d8555bd6a8896af7e63f21f37a3375db5cc2f 100644 --- a/frameworks/core/components_ng/test/mock/rosen/testing_typography_properties.h +++ b/frameworks/core/components_ng/test/mock/rosen/testing_typography_properties.h @@ -28,57 +28,57 @@ enum class TextDirection { class TestingTypographyProperties { public: - enum class RectWidthStyle { + enum class TextRectWidthStyle { TIGHT, MAX, }; enum class Affinity { - UPSTREAM, - DOWNSTREAM, + PREV, + NEXT, }; - enum class RectHeightStyle { + enum class TextRectHeightStyle { TIGHT, - MAX, - INCLUDELINESPACEMIDDLE, - INCLUDELINESPACETOP, - INCLUDELINESPACEBOTTOM, - STRUCT, + COVER_TOP_AND_BOTTOM, + COVER_HALF_TOP_AND_BOTTOM, + COVER_TOP, + COVER_BOTTOM, + FOLLOW_BY_STRUT, }; - struct TextBox { + struct TextRect { TextDirection direction_; TestingRect rect_; TextBox() = default; TextBox(TestingRect rect, TextDirection direction) : direction_(direction), rect_(rect) {} }; - struct PositionAndAffinity { - const size_t pos_; + struct IndexAndAffinity { + const size_t index_; const Affinity affinity_; - PositionAndAffinity(size_t pos, Affinity affinity) : pos_(pos), affinity_(affinity) {} + IndexAndAffinity(size_t pos, Affinity affinity) : index_(pos), affinity_(affinity) {} }; template - struct Range { - T start_, end_; - Range() : start_(), end_() {} - Range(T a, T b) : start_(a), end_(b) {} - bool operator==(const Range& rhs) const + struct Boundary { + T leftIndex_, rightIndex_; + Boundary() : leftIndex_(), rightIndex_() {} + Boundary(T a, T b) : leftIndex_(a), rightIndex_(b) {} + bool operator==(const Boundary& rhs) const { - return start_ == rhs.start_ && end_ == rhs.end_; + return leftIndex_ == rhs.leftIndex_ && rightIndex_ == rhs.rightIndex_; } T Width() const { - return end_ - start_; + return rightIndex_ - leftIndex_; } void Shift(T offset) { - start_ += offset; - end_ += offset; + leftIndex_ += offset; + rightIndex_ += offset; } }; }; 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 6832b96a65e35d32259851c68b782118d92d2f3b..c87ab9496656d52404dc4b98b30c3c6a04e874a5 100644 --- a/frameworks/core/components_ng/test/pattern/ability_component/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/ability_component/BUILD.gn @@ -116,7 +116,7 @@ ohos_unittest("ability_component_pattern_test_ng") { "//commonlibrary/c_utils/base:utils_config", "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:export_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:render_service_client_config", "//foundation/window/window_manager/extension/extension_connection:libwindow_extension_client_private_config", "//foundation/window/window_manager/extension/extension_connection:libextension_connection_public_config", diff --git a/frameworks/core/components_ng/test/pattern/badge/BUILD.gn b/frameworks/core/components_ng/test/pattern/badge/BUILD.gn index 1e66db83210d79edf8c4324a8b16807836a326e6..bef0908d84a6aa192f523ac042df43ffc49e8f4a 100644 --- a/frameworks/core/components_ng/test/pattern/badge/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/badge/BUILD.gn @@ -16,6 +16,11 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("badge_pattern_test_ng") { module_out_path = pattern_test_output_path + include_dirs = [ + "//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", + ] sources = [ "$ace_root/frameworks/base/geometry/least_square_impl.cpp", diff --git a/frameworks/core/components_ng/test/pattern/calendar/BUILD.gn b/frameworks/core/components_ng/test/pattern/calendar/BUILD.gn index c1920f256effbf8fb9c97cdabf862b1a329be661..fef66fcdb00a67369c9b8cb6631ebd500e6bbe79 100644 --- a/frameworks/core/components_ng/test/pattern/calendar/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/calendar/BUILD.gn @@ -17,6 +17,13 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("calendar_pattern_test_ng") { module_out_path = pattern_test_output_path + include_dirs = [ + "//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", + "//third_party/flutter/skia", +] + sources = [ # animation "$ace_root/frameworks/base/geometry/least_square_impl.cpp", @@ -150,6 +157,7 @@ ohos_unittest("calendar_pattern_test_ng") { "$ace_root/test/unittest:ace_unittest_log", "$cjson_root:cjson_static", "//third_party/googletest:gmock_main", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text" ] configs = [ "$ace_root/test/unittest:ace_unittest_config" ] diff --git a/frameworks/core/components_ng/test/pattern/container_modal/BUILD.gn b/frameworks/core/components_ng/test/pattern/container_modal/BUILD.gn index f78f9629b94593d05f7e0d9c85e4d296c0079759..f42c5d47e3685539ee35484061ad32ba880dd530 100644 --- a/frameworks/core/components_ng/test/pattern/container_modal/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/container_modal/BUILD.gn @@ -16,6 +16,12 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("container_modal_test_ng") { module_out_path = pattern_test_output_path + include_dirs = [ + "//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", + "//third_party/flutter/skia", +] sources = [ "$ace_root/adapter/preview/osal/ressched_report.cpp", diff --git a/frameworks/core/components_ng/test/pattern/custom_dialog/BUILD.gn b/frameworks/core/components_ng/test/pattern/custom_dialog/BUILD.gn index f6edfa283dc53b1f1bd5fde00428f6c3572c0e4a..6f1b0287709c3aca79b0bd03b14fabfdef9a4efe 100644 --- a/frameworks/core/components_ng/test/pattern/custom_dialog/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/custom_dialog/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("custom_dialog_test_ng") { include_dirs = [ "$ace_hitrace/interfaces/native/innerkits/include/hitrace_meter", "$ace_graphic/rosen/modules/2d_graphics/src/drawing/engine_adapter", - "$ace_graphic/rosen/modules/2d_engine/rosen_text", + "$ace_graphic/rosen/modules/2d_engine/rosen_text/export", "$ace_graphic/rosen/modules/2d_engine/rosen_text/properties", "$ace_graphic/rosen/modules/2d_engine", "$ace_root/frameworks/base/log", diff --git a/frameworks/core/components_ng/test/pattern/custom_paint/BUILD.gn b/frameworks/core/components_ng/test/pattern/custom_paint/BUILD.gn index 1fd59f1f1130746aae39ffa35add962036d14e2c..de055806af232ce2f2c89c3aac523861322f68f7 100644 --- a/frameworks/core/components_ng/test/pattern/custom_paint/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/custom_paint/BUILD.gn @@ -17,6 +17,19 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("custom_paint_test_ng") { module_out_path = pattern_test_output_path + include_dirs = [ + "//commonlibrary/c_utils/base/include", + "$ace_root", + "$ace_root/frameworks", + "$flutter_root/skia", + "$flutter_root/engine", + "$flutter_root/engine/flutter", + "$flutter_root/engine/flutter/third_party/txt/src", + "$flutter_root/skia/third_party/externals/harfbuzz/src", + "$ace_graphic/rosen/modules/2d_engine/rosen_text/export", + "$ace_graphic/rosen/modules/2d_graphics/include", + "$ace_graphic/rosen/modules/2d_graphics/src", + ] sources = [ "canvas_paint_method_test_ng.cpp", "common_constants.cpp", diff --git a/frameworks/core/components_ng/test/pattern/custom_paint/canvas_paint_method_test_ng.cpp b/frameworks/core/components_ng/test/pattern/custom_paint/canvas_paint_method_test_ng.cpp index 717434e886377be67e25a1564917e6b289efd8ca..c5da1cfcf543592142867185a045518f9505781d 100644 --- a/frameworks/core/components_ng/test/pattern/custom_paint/canvas_paint_method_test_ng.cpp +++ b/frameworks/core/components_ng/test/pattern/custom_paint/canvas_paint_method_test_ng.cpp @@ -353,7 +353,7 @@ HWTEST_F(CanvasPaintMethodTestNg, CanvasPaintMethodTestNg006, TestSize.Level1) EXPECT_CALL(*mockParagraph, GetAlphabeticBaseline()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); EXPECT_CALL(*mockParagraph, GetIdeographicBaseline()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); EXPECT_CALL(*mockParagraph, GetHeight()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); - std::unique_ptr paragraph(std::move(mockParagraph)); + std::unique_ptr paragraph(std::move(mockParagraph)); /** * @tc.steps2: Test functions GetAlignOffset. @@ -383,7 +383,7 @@ HWTEST_F(CanvasPaintMethodTestNg, CanvasPaintMethodTestNg007, TestSize.Level1) EXPECT_CALL(*mockParagraph, GetAlphabeticBaseline()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); EXPECT_CALL(*mockParagraph, GetIdeographicBaseline()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); EXPECT_CALL(*mockParagraph, GetHeight()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); - std::unique_ptr paragraph(std::move(mockParagraph)); + std::unique_ptr paragraph(std::move(mockParagraph)); /** * @tc.steps2: Test functions GetBaselineOffset. diff --git a/frameworks/core/components_ng/test/pattern/custom_paint/mock/mock_paragraph.h b/frameworks/core/components_ng/test/pattern/custom_paint/mock/mock_paragraph.h index 5a37d74d006e929b98125486cebfe46780ce5e1b..d2ecb226de2ecd613d7e743b9b050659c7aa5453 100644 --- a/frameworks/core/components_ng/test/pattern/custom_paint/mock/mock_paragraph.h +++ b/frameworks/core/components_ng/test/pattern/custom_paint/mock/mock_paragraph.h @@ -16,36 +16,40 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_TEST_PATTERN_CUSTOM_PAINT_MOCK_PARAGRAPH_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_TEST_PATTERN_CUSTOM_PAINT_MOCK_PARAGRAPH_H +#include + #include "gmock/gmock.h" -#include "txt/paragraph.h" +#include "rosen_text/typography.h" #include "include/core/SkCanvas.h" namespace OHOS::Ace::NG { -class MockParagraph : public txt::Paragraph { +class MockParagraph : public Rosen::Typography { public: - MOCK_METHOD0(GetMaxWidth, double()); - MOCK_METHOD0(GetHeight, double()); - MOCK_METHOD0(GetLongestLine, double()); + MOCK_CONST_METHOD0(GetMaxWidth, double()); + MOCK_CONST_METHOD0(GetHeight, double()); + MOCK_CONST_METHOD0(GetActualWidth, double()); MOCK_METHOD0(GetMinIntrinsicWidth, double()); MOCK_METHOD0(GetMaxIntrinsicWidth, double()); MOCK_METHOD0(GetAlphabeticBaseline, double()); MOCK_METHOD0(GetIdeographicBaseline, double()); - MOCK_METHOD0(DidExceedMaxLines, bool()); - MOCK_METHOD0(GetRectsForPlaceholders, std::vector()); + MOCK_CONST_METHOD0(DidExceedMaxLines, bool()); + MOCK_METHOD0(GetTextRectsOfPlaceholders, std::vector()); + MOCK_CONST_METHOD0(GetLineCount, int()); + MOCK_METHOD1(SetIndents, void(const std::vector &indents)); MOCK_METHOD1(Layout, void(double width)); - MOCK_METHOD1(GetWordBoundary, Range(size_t offset)); + MOCK_METHOD1(GetWordBoundaryByIndex, Rosen::Boundary(size_t offset)); - MOCK_METHOD2(GetGlyphPositionAtCoordinate, PositionWithAffinity(double dx, double dy)); - MOCK_METHOD2(GetGlyphPositionAtCoordinateWithCluster, PositionWithAffinity(double dx, double dy)); + MOCK_METHOD2(GetGlyphIndexByCoordinate, Rosen::IndexAndAffinity(double x, double y)); MOCK_METHOD3(Paint, void(SkCanvas* canvas, double x, double y)); + MOCK_METHOD3(Paint, void(Rosen::Drawing::Canvas* canvas, double x, double y)); - MOCK_METHOD4(GetRectsForRange, std::vector(size_t start, + MOCK_METHOD4(GetTextRectsByBoundary, std::vector(size_t start, size_t end, - RectHeightStyle rect_height_style, - RectWidthStyle rect_width_style)); + Rosen::TextRectHeightStyle rect_height_style, + Rosen::TextRectWidthStyle rect_width_style)); #ifdef NEW_SKIA MOCK_METHOD0(GetLineMetrics, std::vector&()); #endif diff --git a/frameworks/core/components_ng/test/pattern/custom_paint/offscreen_canvas_paint_method_test_ng.cpp b/frameworks/core/components_ng/test/pattern/custom_paint/offscreen_canvas_paint_method_test_ng.cpp index 18953167252a5fa4ca25ec0e4336564fe9e5d26a..859b754a69793d9d1abe6683a2630a9ce53d9141 100644 --- a/frameworks/core/components_ng/test/pattern/custom_paint/offscreen_canvas_paint_method_test_ng.cpp +++ b/frameworks/core/components_ng/test/pattern/custom_paint/offscreen_canvas_paint_method_test_ng.cpp @@ -690,7 +690,7 @@ HWTEST_F(OffscreenCanvasPaintMethodTestNg, OffscreenCanvasPaintMethodTestNg016, EXPECT_CALL(*mockParagraph, GetAlphabeticBaseline()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); EXPECT_CALL(*mockParagraph, GetIdeographicBaseline()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); EXPECT_CALL(*mockParagraph, GetHeight()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); - std::unique_ptr paragraph(std::move(mockParagraph)); + std::unique_ptr paragraph(std::move(mockParagraph)); /** * @tc.steps2: Test functions GetAlignOffset. @@ -722,7 +722,7 @@ HWTEST_F(OffscreenCanvasPaintMethodTestNg, OffscreenCanvasPaintMethodTestNg017, EXPECT_CALL(*mockParagraph, GetAlphabeticBaseline()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); EXPECT_CALL(*mockParagraph, GetIdeographicBaseline()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); EXPECT_CALL(*mockParagraph, GetHeight()).WillRepeatedly(testing::Return(DEFAULT_DOUBLE10)); - std::unique_ptr paragraph(std::move(mockParagraph)); + std::unique_ptr paragraph(std::move(mockParagraph)); /** * @tc.steps2: Test functions GetBaselineOffset. 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 6bd2df3302fc95cd836c824a4072ba3ff8010e62..1efb5039989d752cc04ac3a0876cc5759ca72411 100644 --- a/frameworks/core/components_ng/test/pattern/image_animator/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/image_animator/BUILD.gn @@ -92,7 +92,7 @@ ohos_unittest("image_animator_pattern_test") { "//commonlibrary/c_utils/base:utils_config", "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:export_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:render_service_client_config", ] } diff --git a/frameworks/core/components_ng/test/pattern/menu/BUILD.gn b/frameworks/core/components_ng/test/pattern/menu/BUILD.gn index 02aaea62ec05203800145f9f07ab55266cbf8f2f..d6e859aea6eff25d14eef3907380c5ca5d947327 100644 --- a/frameworks/core/components_ng/test/pattern/menu/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/menu/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("menu_test_ng") { include_dirs = [ "//commonlibrary/c_utils/base/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/test/pattern/navigation/BUILD.gn b/frameworks/core/components_ng/test/pattern/navigation/BUILD.gn index 784fce1e5461df34f6de9025a87afa881c4e8f6f..f643c6148d1aed92a524b4449bba3c571e6b9d31 100755 --- a/frameworks/core/components_ng/test/pattern/navigation/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/navigation/BUILD.gn @@ -17,6 +17,13 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("navigation_test_ng") { module_out_path = pattern_test_output_path + include_dirs = [ + "//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", + "//third_party/flutter/skia", + ] + sources = [ # inner "$ace_root/frameworks/base/geometry/dimension.cpp", diff --git a/frameworks/core/components_ng/test/pattern/option/BUILD.gn b/frameworks/core/components_ng/test/pattern/option/BUILD.gn index 248735c67572f45b0ded804f085866864f01c656..90ab2aa3364d659029011e1fc6abdee03349a8dc 100644 --- a/frameworks/core/components_ng/test/pattern/option/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/option/BUILD.gn @@ -133,7 +133,7 @@ ohos_unittest("panel_option_test_ng") { "//commonlibrary/c_utils/base:utils_config", "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:export_config", - "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_config", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine/rosen_text:rosen_text_public_config", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:render_service_client_config", ] } diff --git a/frameworks/core/components_ng/test/pattern/picker/BUILD.gn b/frameworks/core/components_ng/test/pattern/picker/BUILD.gn index 44650810be309adede995de7d4c5461e57043b16..7590d4a2a90990cd346e657fcd86d2218e453a98 100644 --- a/frameworks/core/components_ng/test/pattern/picker/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/picker/BUILD.gn @@ -16,6 +16,13 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("picker_test_ng") { module_out_path = pattern_test_output_path + include_dirs = [ + "//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", + "//third_party/flutter/skia", +] + sources = [ # inner "$ace_root/frameworks/base/geometry/dimension.cpp", diff --git a/frameworks/core/components_ng/test/pattern/refresh/BUILD.gn b/frameworks/core/components_ng/test/pattern/refresh/BUILD.gn index bc604faea2ef08aa036e4fcc75e8a74d1cf3c5a8..5312e295858d1f00e71cee76add443802225e532 100644 --- a/frameworks/core/components_ng/test/pattern/refresh/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/refresh/BUILD.gn @@ -27,7 +27,7 @@ ohos_unittest("refresh_pattern_test_ng") { "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src/drawing", "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src/drawing/engine_adapter", "//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/arkui/ace_engine/frameworks/base/memory", "//third_party/bounds_checking_function/include", "//foundation/arkui/ace_engine/frameworks", diff --git a/frameworks/core/components_ng/test/pattern/scroll/BUILD.gn b/frameworks/core/components_ng/test/pattern/scroll/BUILD.gn index d89e5d67bb49067921183858a33eee1818b3da0b..656bf93fe5ea0fdb3464a8498f6dab01ed618710 100644 --- a/frameworks/core/components_ng/test/pattern/scroll/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/scroll/BUILD.gn @@ -18,6 +18,15 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("scroll_test_ng") { module_out_path = pattern_test_output_path + include_dirs = [ + "//commonlibrary/c_utils/base/include", + "//foundation/graphic/graphic_2d/rosen/modules/2d_engine", + "//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", + "//third_party/flutter/skia", + ] sources = [ # special "$ace_root/frameworks/base/geometry/animatable_dimension.cpp", diff --git a/frameworks/core/components_ng/test/pattern/search/BUILD.gn b/frameworks/core/components_ng/test/pattern/search/BUILD.gn index c14ea0adcc2dacad105205df70c32535d1ca1537..c06abb7789db1b97d0cae9e9be744e51bac4f754 100644 --- a/frameworks/core/components_ng/test/pattern/search/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/search/BUILD.gn @@ -17,6 +17,13 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("search_test_ng") { module_out_path = pattern_test_output_path + include_dirs = [ + "//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", + "//third_party/skia", + ] + sources = [ "$ace_root/frameworks/core/components_ng/pattern/image/image_layout_algorithm.cpp", "$ace_root/frameworks/core/components_ng/pattern/image/image_paint_method.cpp", diff --git a/frameworks/core/components_ng/test/pattern/shape/BUILD.gn b/frameworks/core/components_ng/test/pattern/shape/BUILD.gn index 7d403b97ac613e5016d45faf5107e89212e3be3b..50b1acf32d106e230c1a6d1c8af18d8ca58a47d2 100644 --- a/frameworks/core/components_ng/test/pattern/shape/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/shape/BUILD.gn @@ -22,7 +22,7 @@ config("config_shape_test") { include_dirs = [ "//commonlibrary/c_utils/base/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/test/pattern/slider/BUILD.gn b/frameworks/core/components_ng/test/pattern/slider/BUILD.gn index bb8d51ba0b5bcb3bd5f492acbae58041f09e183e..0a2487a0baaf97b23c07230e745481f2f2e85b44 100644 --- a/frameworks/core/components_ng/test/pattern/slider/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/slider/BUILD.gn @@ -11,10 +11,26 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//foundation/arkui/ace_engine/ace_config.gni") import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ace_unittest("slider_pattern_test_ng") { ace_animation = true + + include_dirs = [ + "//commonlibrary/c_utils/base/include", + "//foundation/window/window_manager/interfaces/innerkits/extension", + "//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", + "//third_party/flutter/engine", + "//third_party/flutter/skia", + "//third_party/flutter/engine/flutter/third_party/txt/src/txt", + "//third_party/flutter/engine/flutter/third_party/txt/src", + "//third_party/flutter/skia/third_party/externals/harfbuzz/src", + "//third_party/flutter/skia/third_party/externals/icu/source/common", + ] sources = [ "$ace_root/frameworks/core/components_ng/pattern/grid_container/grid_container_layout_property.cpp", "$ace_root/frameworks/core/components_ng/pattern/image/image_layout_algorithm.cpp", diff --git a/frameworks/core/components_ng/test/pattern/swiper/BUILD.gn b/frameworks/core/components_ng/test/pattern/swiper/BUILD.gn index af3ef084a6e66cba0d4dd51ab59a5954fbece7bb..d7c6b314e9e28db2a800070a878854e89818f70a 100644 --- a/frameworks/core/components_ng/test/pattern/swiper/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/swiper/BUILD.gn @@ -176,7 +176,7 @@ config("config_swiper_indicator_test") { "$flutter_root/skia", "$flutter_root/skia/include/core", "//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/test/pattern/text/BUILD.gn b/frameworks/core/components_ng/test/pattern/text/BUILD.gn index 2ae881afa11fd6fc06ffdaa5613b66ccd533cbab..72310268d443df836c2b535b45a43f13a87a765e 100644 --- a/frameworks/core/components_ng/test/pattern/text/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/text/BUILD.gn @@ -17,8 +17,12 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("text_test_ng") { module_out_path = pattern_test_output_path - include_dirs = - [ "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include" ] + include_dirs = [ + "//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", + "//third_party/flutter/skia", +] sources = [ "$ace_root/adapter/preview/osal/ressched_report.cpp", diff --git a/frameworks/core/components_ng/test/pattern/text/mock/mock_txt_font_collection.cpp b/frameworks/core/components_ng/test/pattern/text/mock/mock_txt_font_collection.cpp index e78f2f84cebcf468aa2d5de04193d9adaafffa52..01395b78ee497c7cf42dbe337faca9014d393d07 100644 --- a/frameworks/core/components_ng/test/pattern/text/mock/mock_txt_font_collection.cpp +++ b/frameworks/core/components_ng/test/pattern/text/mock/mock_txt_font_collection.cpp @@ -17,12 +17,12 @@ #include "core/components_ng/render/font_collection.h" namespace OHOS::Ace::NG { -TxtFontCollection::TxtFontCollection(const std::shared_ptr& fontCollection) +TxtFontCollection::TxtFontCollection(const std::shared_ptr& fontCollection) : collection_(fontCollection) {} RefPtr FontCollection::Current() { - std::shared_ptr fontCollection; + std::shared_ptr fontCollection; return AceType::MakeRefPtr(fontCollection); } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/test/pattern/text_clock/BUILD.gn b/frameworks/core/components_ng/test/pattern/text_clock/BUILD.gn index 3e258798dae9373e1787f65b24d6db936506f988..4c9c24ab4d520f0fd26f824353d97812f7b80026 100644 --- a/frameworks/core/components_ng/test/pattern/text_clock/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/text_clock/BUILD.gn @@ -88,7 +88,7 @@ ohos_unittest("text_clock_pattern_test_ng") { include_dirs = [ "//commonlibrary/c_utils/base/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/test/pattern/textfield/BUILD.gn b/frameworks/core/components_ng/test/pattern/textfield/BUILD.gn index ac61127e77ec48a8a71423cf67ea881d1ff32f28..b8d0942e6ab892c1c37626cf0d8fddd6ef307fdb 100644 --- a/frameworks/core/components_ng/test/pattern/textfield/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/textfield/BUILD.gn @@ -16,6 +16,12 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("textfield_test_ng") { module_out_path = pattern_test_output_path + include_dirs = [ + "//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", + "//third_party/flutter/skia", +] sources = [ "$ace_root/frameworks/base/geometry/animatable_dimension.cpp", diff --git a/frameworks/core/components_ng/test/pattern/textfield/textfield_test_ng.cpp b/frameworks/core/components_ng/test/pattern/textfield/textfield_test_ng.cpp index 6061e9ff483bbcd23380cd666d639175ae1fe233..2757c44a8a3d24d6baf6a980e862c80a65f7f3fc 100644 --- a/frameworks/core/components_ng/test/pattern/textfield/textfield_test_ng.cpp +++ b/frameworks/core/components_ng/test/pattern/textfield/textfield_test_ng.cpp @@ -1268,10 +1268,10 @@ HWTEST_F(TextFieldPatternTestNg, PaintSelection003, TestSize.Level1) pattern->selectionMode_ = SelectionMode::SELECT; pattern->textSelector_.baseOffset = 1; pattern->textSelector_.destinationOffset = 0; - std::vector textBoxes; - RSTypographyProperties::TextBox textBox; - textBoxes.emplace_back(textBox); - pattern->textBoxes_ = textBoxes; + std::vector textBoxs; + RSTypographyProperties::TextRect textBox; + textBoxs.emplace_back(textBox); + pattern->textBoxes_ = textBoxs; auto scrollBar = AceType::MakeRefPtr(); EdgeEffect edgeEffect; auto scrollEdgeEffect = AceType::MakeRefPtr(edgeEffect); @@ -2467,7 +2467,7 @@ HWTEST_F(TextFieldPatternTestNg, AdjustTextSelectionRectOffsetX, TestSize.Level1 textFieldPattern->contentRect_.SetLeft(0.0f); textFieldPattern->contentRect_.SetWidth(100.0f); textFieldPattern->textRect_.SetLeft(0.0f); - RSTypographyProperties::TextBox textBox; + RSTypographyProperties::TextRect textBox; textFieldPattern->textBoxes_.emplace_back(textBox); textFieldPattern->textBoxes_.begin()->rect_.SetRight(50.0f); diff --git a/frameworks/core/components_ng/test/pattern/texttimer/BUILD.gn b/frameworks/core/components_ng/test/pattern/texttimer/BUILD.gn index 465769e4846bf2f3d22acd86bb485b63246bcef4..8bcb0ee0b7f90e4e6e90302bee0510492afd2c49 100644 --- a/frameworks/core/components_ng/test/pattern/texttimer/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/texttimer/BUILD.gn @@ -88,7 +88,7 @@ ohos_unittest("text_timer_pattern_test_ng") { include_dirs = [ "//commonlibrary/c_utils/base/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/test/pattern/toggle/BUILD.gn b/frameworks/core/components_ng/test/pattern/toggle/BUILD.gn index 0f7050d17140601f030287bfe28019a503e09fad..5a93e88d6d85cd39b0747b5eb4e562da8c2de80c 100644 --- a/frameworks/core/components_ng/test/pattern/toggle/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/toggle/BUILD.gn @@ -21,6 +21,7 @@ ohos_unittest("toggle_pattern_test_ng") { include_dirs = [ "//commonlibrary/c_utils/base/include", "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include/utils", ] sources = [ diff --git a/frameworks/core/components_ng/test/pattern/video/BUILD.gn b/frameworks/core/components_ng/test/pattern/video/BUILD.gn index c30380dc2acc12975d4486ba86639d2b2abfd7b2..60c7bb66373a98c723b3c3d1d38fe6746e17189a 100644 --- a/frameworks/core/components_ng/test/pattern/video/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/video/BUILD.gn @@ -27,7 +27,7 @@ ohos_unittest("video_pattern_test_ng") { "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src/drawing", "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src/drawing/engine_adapter", "//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/arkui/ace_engine/frameworks/base/memory", "//third_party/bounds_checking_function/include", "//foundation/arkui/ace_engine/frameworks", diff --git a/frameworks/core/components_ng/test/property/grid_property/BUILD.gn b/frameworks/core/components_ng/test/property/grid_property/BUILD.gn index 0d03ac863406b2ccbde670c897981f37c5203867..4ed8d01da186cce285d360fa9269e9fcdfcc1ff5 100755 --- a/frameworks/core/components_ng/test/property/grid_property/BUILD.gn +++ b/frameworks/core/components_ng/test/property/grid_property/BUILD.gn @@ -15,6 +15,12 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("grid_property_test_ng") { module_out_path = property_test_output_path + include_dirs = [ + "//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", + "//third_party/flutter/skia", +] sources = [ "$ace_root/frameworks/base/geometry/dimension.cpp", diff --git a/frameworks/core/components_ng/test/svg/parse/BUILD.gn b/frameworks/core/components_ng/test/svg/parse/BUILD.gn index f95b1b38ffbc56df83aa23b6c56f550d3ec94dfe..5aa9829ae1896f9e1c8e4007f7f37e3581631a98 100644 --- a/frameworks/core/components_ng/test/svg/parse/BUILD.gn +++ b/frameworks/core/components_ng/test/svg/parse/BUILD.gn @@ -22,7 +22,7 @@ config("config_svg_parse_test") { include_dirs = [ "//commonlibrary/c_utils/base/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/test/unittest/core/pipeline/BUILD.gn b/test/unittest/core/pipeline/BUILD.gn index c97c97af37b18803cd5a7869a34d7a367a0213e9..1182b19972dde9766bd555412851ddf25111ab81 100644 --- a/test/unittest/core/pipeline/BUILD.gn +++ b/test/unittest/core/pipeline/BUILD.gn @@ -16,6 +16,11 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni") ohos_unittest("pipeline_context_test_ng") { module_out_path = "$basic_test_output_path/pipeline" + include_dirs = [ + "//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", + ] sources = [ # animation