From 57330ea341d44314747b57648544f980d836e1dd Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Fri, 12 Jul 2024 19:47:29 +0900 Subject: [PATCH] Add async text natural size RequestAsyncNaturalSize : Requests asynchronous text natural size computation. AsyncNaturalSizeComputedSignal : Signal is emitted when the async natural size computed. Change-Id: Iaf9a7b757d623e24faf025a43fa861983f6c7616 Signed-off-by: Bowon Ryu --- .../controls/text-controls/text-label-devel.cpp | 10 +++ .../controls/text-controls/text-label-devel.h | 28 +++++++++ .../controls/text-controls/text-label-impl.cpp | 72 +++++++++++++++++++++- .../controls/text-controls/text-label-impl.h | 22 +++++++ .../text/async-text/async-text-interface.h | 5 ++ .../text/async-text/async-text-loader-impl.cpp | 24 +++++--- .../text/async-text/async-text-loader-impl.h | 5 ++ .../internal/text/async-text/async-text-loader.cpp | 5 ++ .../internal/text/async-text/async-text-loader.h | 35 ++++++++--- .../internal/text/async-text/text-loading-task.cpp | 62 ++++++++++++++----- dali-toolkit/internal/visuals/text/text-visual.cpp | 27 +++++++- dali-toolkit/internal/visuals/text/text-visual.h | 16 +++++ 12 files changed, 276 insertions(+), 35 deletions(-) diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp index 6e2e741..8766f01 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp @@ -40,6 +40,11 @@ AsyncTextRenderedSignalType& AsyncTextRenderedSignal(TextLabel textLabel) return GetImpl(textLabel).AsyncTextRenderedSignal(); } +AsyncNaturalSizeComputedSignalType& AsyncNaturalSizeComputedSignal(TextLabel textLabel) +{ + return GetImpl(textLabel).AsyncNaturalSizeComputedSignal(); +} + Vector GetTextSize(TextLabel textLabel, const uint32_t startIndex, const uint32_t endIndex) { return GetImpl(textLabel).GetTextSize(startIndex, endIndex); @@ -105,6 +110,11 @@ void RequestAsyncRenderWithConstraint(TextLabel textLabel, float widthConstraint GetImpl(textLabel).RequestAsyncRenderWithConstraint(widthConstraint, heightConstraint); } +void RequestAsyncNaturalSize(TextLabel textLabel) +{ + GetImpl(textLabel).RequestAsyncNaturalSize(); +} + } // namespace DevelTextLabel } // namespace Toolkit diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h index f3a66c1..a62255e 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h @@ -427,6 +427,13 @@ DALI_TOOLKIT_API void RequestAsyncRenderWithFixedWidth(TextLabel textLabel, floa DALI_TOOLKIT_API void RequestAsyncRenderWithConstraint(TextLabel textLabel, float widthConstraint, float heightConstraint); /** + * @brief Requests asynchronous text natural size computation. + * + * @param[in] textLabel The instance of TextLabel. + */ +DALI_TOOLKIT_API void RequestAsyncNaturalSize(TextLabel textLabel); + +/** * @brief Anchor clicked signal type. * * @note Signal @@ -450,6 +457,15 @@ using TextFitChangedSignalType = Signal; using AsyncTextRenderedSignalType = Signal; /** + * @brief Async natural size computed signal type. + * + * @note Signal + * - float : computed width. + * - float : computed height. + */ +using AsyncNaturalSizeComputedSignalType = Signal; + +/** * @brief This signal is emitted when the anchor is clicked. * * A callback of the following type may be connected: @@ -485,6 +501,18 @@ DALI_TOOLKIT_API TextFitChangedSignalType& TextFitChangedSignal(TextLabel textLa */ DALI_TOOLKIT_API AsyncTextRenderedSignalType& AsyncTextRenderedSignal(TextLabel textLabel); +/** + * @brief This signal is emitted when the async natural size computed. + * + * A callback of the following type may be connected: + * @code + * void YourCallbackName(TextLabel textLabel); + * @endcode + * @param[in] textLabel The instance of TextLabel. + * @return The signal to connect to. + */ +DALI_TOOLKIT_API AsyncNaturalSizeComputedSignalType& AsyncNaturalSizeComputedSignal(TextLabel textLabel); + } // namespace DevelTextLabel } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index b04f808..386bdc4 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -160,6 +160,7 @@ DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColo DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "anchorClicked", SIGNAL_ANCHOR_CLICKED) DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "textFitChanged", SIGNAL_TEXT_FIT_CHANGED) DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "asyncTextRendered", SIGNAL_ASYNC_TEXT_RENDERED) +DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "asyncNaturalSizeComputed", SIGNAL_ASYNC_NATURAL_SIZE_COMPUTED) DALI_TYPE_REGISTRATION_END() // clang-format on @@ -1000,6 +1001,14 @@ bool TextLabel::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* labelImpl.AsyncTextRenderedSignal().Connect(tracker, functor); } } + else if(0 == strcmp(signalName.c_str(), SIGNAL_ASYNC_NATURAL_SIZE_COMPUTED)) + { + if(label) + { + Internal::TextLabel& labelImpl(GetImpl(label)); + labelImpl.AsyncNaturalSizeComputedSignal().Connect(tracker, functor); + } + } else { // signalName does not match any signal @@ -1024,6 +1033,11 @@ DevelTextLabel::AsyncTextRenderedSignalType& TextLabel::AsyncTextRenderedSignal( return mAsyncTextRenderedSignal; } +DevelTextLabel::AsyncNaturalSizeComputedSignalType& TextLabel::AsyncNaturalSizeComputedSignal() +{ + return mAsyncNaturalSizeComputedSignal; +} + void TextLabel::OnInitialize() { Actor self = Self(); @@ -1617,6 +1631,37 @@ void TextLabel::AsyncTextFitChanged(float pointSize) } } +void TextLabel::AsyncSizeComputed(Text::AsyncTextRenderInfo renderInfo) +{ + switch (renderInfo.requestType) + { + case Async::COMPUTE_NATURAL_SIZE: + { + DALI_LOG_RELEASE_INFO("Natural size : %f, %f\n", renderInfo.renderedSize.width, renderInfo.renderedSize.height); + EmitAsyncNaturalSizeComputedSignal(renderInfo.renderedSize.width, renderInfo.renderedSize.height); + } + break; + + case Async::COMPUTE_HEIGHT_FOR_WIDTH: + { + // TODO + } + break; + + case Async::COMPUTE_LINE_COUNT: + { + // TODO + } + break; + + default: + { + DALI_LOG_ERROR("Unexpected request type recieved : %d\n", renderInfo.requestType); + } + break; + } +} + void TextLabel::AsyncLoadComplete(Text::AsyncTextRenderInfo renderInfo) { // Pure Virtual from AsyncTextInterface @@ -1672,6 +1717,14 @@ void TextLabel::EmitAsyncTextRenderedSignal(float width, float height) mAsyncTextRenderedSignal.Emit(handle, width, height); } +void TextLabel::EmitAsyncNaturalSizeComputedSignal(float width, float height) +{ + Dali::Toolkit::TextLabel handle(GetOwner()); + Extents padding; + padding = Self().GetProperty(Toolkit::Control::Property::PADDING); + mAsyncNaturalSizeComputedSignal.Emit(handle, width + (padding.start + padding.end), height + (padding.top + padding.bottom)); +} + void TextLabel::OnAccessibilityStatusChanged() { CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors); @@ -1783,6 +1836,19 @@ void TextLabel::EnableControlBackground(const bool enable) } } +void TextLabel::RequestAsyncNaturalSize() +{ + Actor self = Self(); + Extents padding(0u, 0u, 0u, 0u); + Vector2 contentSize(0.0f, 0.0f); + Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self); + + AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection); + parameters.requestType = Async::COMPUTE_NATURAL_SIZE; + + TextVisual::RequestAsyncSizeComputation(mVisual, parameters); +} + void TextLabel::RequestAsyncRenderWithFixedSize(float width, float height) { DALI_LOG_RELEASE_INFO("Request size : %f, %f\n", width, height); @@ -1812,7 +1878,7 @@ void TextLabel::RequestAsyncRenderWithFixedSize(float width, float height) } AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection); - parameters.renderType = AsyncTextParameters::FIXED_SIZE; + parameters.requestType = Async::RENDER_FIXED_SIZE; parameters.manualRender = true; TextVisual::UpdateAsyncRenderer(mVisual, parameters); @@ -1849,7 +1915,7 @@ void TextLabel::RequestAsyncRenderWithFixedWidth(float width, float heightConstr } AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection); - parameters.renderType = AsyncTextParameters::FIXED_WIDTH; + parameters.requestType = Async::RENDER_FIXED_WIDTH; parameters.manualRender = true; TextVisual::UpdateAsyncRenderer(mVisual, parameters); @@ -1886,7 +1952,7 @@ void TextLabel::RequestAsyncRenderWithConstraint(float widthConstraint, float he } AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection); - parameters.renderType = AsyncTextParameters::CONSTRAINT; + parameters.requestType = Async::RENDER_CONSTRAINT; parameters.manualRender = true; TextVisual::UpdateAsyncRenderer(mVisual, parameters); diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.h b/dali-toolkit/internal/controls/text-controls/text-label-impl.h index f3640c2..3cd8c6e 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -92,6 +92,11 @@ public: DevelTextLabel::AsyncTextRenderedSignalType& AsyncTextRenderedSignal(); /** + * @copydoc Dali::Toollkit::TextLabel::AsyncNaturalSizeComputedSignal() + */ + DevelTextLabel::AsyncNaturalSizeComputedSignalType& AsyncNaturalSizeComputedSignal(); + + /** * Connects a callback function with the object's signals. * @param[in] object The object providing the signal. * @param[in] tracker Used to disconnect the signal. @@ -271,6 +276,11 @@ public: */ void RequestAsyncRenderWithConstraint(float widthConstraint, float heightConstraint); + /** + * @brief Requests asynchronous text natural size computation. + */ + void RequestAsyncNaturalSize(); + private: // From Control /** @@ -359,6 +369,12 @@ private: // from AsyncTextInterface */ void AsyncLoadComplete(Text::AsyncTextRenderInfo renderInfo); + /** + * @copydoc Text::AsyncTextInterface::AsyncSizeComputed() + */ + void AsyncSizeComputed(Text::AsyncTextRenderInfo renderInfo); + + private: // Implementation /** * Construct a new TextLabel. @@ -429,6 +445,11 @@ private: */ void EmitAsyncTextRenderedSignal(float width, float height); + /** + * @brief Emits AsyncNaturalSizeComputed signal. + */ + void EmitAsyncNaturalSizeComputedSignal(float width, float height); + void OnAccessibilityStatusChanged(); private: // Data @@ -443,6 +464,7 @@ private: // Data Toolkit::DevelTextLabel::AnchorClickedSignalType mAnchorClickedSignal; Toolkit::DevelTextLabel::TextFitChangedSignalType mTextFitChangedSignal; Toolkit::DevelTextLabel::AsyncTextRenderedSignalType mAsyncTextRenderedSignal; + Toolkit::DevelTextLabel::AsyncNaturalSizeComputedSignalType mAsyncNaturalSizeComputedSignal; std::string mLocale; Vector2 mSize; diff --git a/dali-toolkit/internal/text/async-text/async-text-interface.h b/dali-toolkit/internal/text/async-text/async-text-interface.h index 0deaf8d..0bf1aa4 100644 --- a/dali-toolkit/internal/text/async-text/async-text-interface.h +++ b/dali-toolkit/internal/text/async-text/async-text-interface.h @@ -58,6 +58,11 @@ public: * @brief Called when the async load complete. */ virtual void AsyncLoadComplete(Text::AsyncTextRenderInfo renderInfo) = 0; + + /** + * @brief Called when the async size computed. + */ + virtual void AsyncSizeComputed(Text::AsyncTextRenderInfo renderInfo) = 0; }; } // namespace Text diff --git a/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp b/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp index 623b26e..22e9c23 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp +++ b/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp @@ -1071,7 +1071,7 @@ AsyncTextRenderInfo AsyncTextLoader::RenderText(AsyncTextParameters& parameters) { DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::RenderText\n"); - if(parameters.renderType == AsyncTextParameters::CONSTRAINT) + if(parameters.requestType == Async::RENDER_CONSTRAINT) { Size textNaturalSize = ComputeNaturalSize(parameters); // textWidth is widthConstraint @@ -1081,12 +1081,12 @@ AsyncTextRenderInfo AsyncTextLoader::RenderText(AsyncTextParameters& parameters) } } - if(parameters.renderType == AsyncTextParameters::FIXED_WIDTH || parameters.renderType == AsyncTextParameters::CONSTRAINT) + if(parameters.requestType == Async::RENDER_FIXED_WIDTH || parameters.requestType == Async::RENDER_CONSTRAINT) { // In case of CONSTRAINT, the natural size has already been calculated. // So we can skip Initialize and Update at this stage. // Only the layout is newly calculated to obtain the height. - bool layoutOnly = (parameters.renderType == AsyncTextParameters::CONSTRAINT); + bool layoutOnly = (parameters.requestType == Async::RENDER_CONSTRAINT); float height = ComputeHeightForWidth(parameters, parameters.textWidth, layoutOnly); // textHeight is heightConstraint. @@ -1166,6 +1166,16 @@ Size AsyncTextLoader::ComputeNaturalSize(AsyncTextParameters& parameters) return naturalSize; } +AsyncTextRenderInfo AsyncTextLoader::GetNaturalSize(AsyncTextParameters& parameters) +{ + Size textNaturalSize = ComputeNaturalSize(parameters); + AsyncTextRenderInfo renderInfo; + renderInfo.renderedSize = textNaturalSize; + renderInfo.requestType = Async::COMPUTE_NATURAL_SIZE; + + return renderInfo; +} + AsyncTextRenderInfo AsyncTextLoader::RenderAutoScroll(AsyncTextParameters& parameters) { DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::RenderAutoScroll\n"); @@ -1177,7 +1187,7 @@ AsyncTextRenderInfo AsyncTextLoader::RenderAutoScroll(AsyncTextParameters& param textNaturalSize.width += (parameters.padding.start + parameters.padding.end); textNaturalSize.height += (parameters.padding.top + parameters.padding.bottom); - if(parameters.renderType == AsyncTextParameters::FIXED_WIDTH || parameters.renderType == AsyncTextParameters::CONSTRAINT) + if(parameters.requestType == Async::RENDER_FIXED_WIDTH || parameters.requestType == Async::RENDER_CONSTRAINT) { // The real height calculated during layout should be set. parameters.textHeight = textNaturalSize.height - (parameters.padding.top + parameters.padding.bottom); @@ -1254,7 +1264,7 @@ bool AsyncTextLoader::CheckForTextFit(AsyncTextParameters& parameters, float poi AsyncTextRenderInfo AsyncTextLoader::RenderTextFit(AsyncTextParameters& parameters) { - if(parameters.renderType == AsyncTextParameters::CONSTRAINT) + if(parameters.requestType == Async::RENDER_CONSTRAINT) { Size textNaturalSize = ComputeNaturalSize(parameters); // textWidth is widthConstraint @@ -1264,12 +1274,12 @@ AsyncTextRenderInfo AsyncTextLoader::RenderTextFit(AsyncTextParameters& paramete } } - if(parameters.renderType == AsyncTextParameters::FIXED_WIDTH || parameters.renderType == AsyncTextParameters::CONSTRAINT) + if(parameters.requestType == Async::RENDER_FIXED_WIDTH || parameters.requestType == Async::RENDER_CONSTRAINT) { // In case of CONSTRAINT, the natural size has already been calculated. // So we can skip Initialize and Update at this stage. // Only the layout is newly calculated to obtain the height. - bool layoutOnly = (parameters.renderType == AsyncTextParameters::CONSTRAINT); + bool layoutOnly = (parameters.requestType == Async::RENDER_CONSTRAINT); float height = ComputeHeightForWidth(parameters, parameters.textWidth, layoutOnly); // textHeight is heightConstraint diff --git a/dali-toolkit/internal/text/async-text/async-text-loader-impl.h b/dali-toolkit/internal/text/async-text/async-text-loader-impl.h index 432a695..f1cefb5 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader-impl.h +++ b/dali-toolkit/internal/text/async-text/async-text-loader-impl.h @@ -89,6 +89,11 @@ public: */ AsyncTextRenderInfo RenderAutoScroll(AsyncTextParameters& parameters); + /** + * @copydoc Dali::AsyncTextLoader::GetNaturalSize() + */ + AsyncTextRenderInfo GetNaturalSize(AsyncTextParameters& parameters); + private: // Worker thread /** diff --git a/dali-toolkit/internal/text/async-text/async-text-loader.cpp b/dali-toolkit/internal/text/async-text/async-text-loader.cpp index 2f8db7f..4143af7 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader.cpp +++ b/dali-toolkit/internal/text/async-text/async-text-loader.cpp @@ -77,6 +77,11 @@ AsyncTextRenderInfo AsyncTextLoader::RenderAutoScroll(AsyncTextParameters& param return GetImplementation(*this).RenderAutoScroll(parameters); } +AsyncTextRenderInfo AsyncTextLoader::GetNaturalSize(AsyncTextParameters& parameters) +{ + return GetImplementation(*this).GetNaturalSize(parameters); +} + Text::AsyncTextModule& AsyncTextLoader::GetModule() { return GetImplementation(*this).GetModule(); diff --git a/dali-toolkit/internal/text/async-text/async-text-loader.h b/dali-toolkit/internal/text/async-text/async-text-loader.h index dd71c00..c370b98 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader.h +++ b/dali-toolkit/internal/text/async-text/async-text-loader.h @@ -43,17 +43,23 @@ class AsyncTextLoader; } // namespace DALI_INTERNAL -struct AsyncTextParameters +namespace Async { - enum RenderType + enum RequestType { - FIXED_SIZE, - FIXED_WIDTH, - CONSTRAINT + RENDER_FIXED_SIZE, + RENDER_FIXED_WIDTH, + RENDER_CONSTRAINT, + COMPUTE_NATURAL_SIZE, + COMPUTE_HEIGHT_FOR_WIDTH, + COMPUTE_LINE_COUNT }; +} // namespace Async +struct AsyncTextParameters +{ AsyncTextParameters() - : renderType{FIXED_SIZE}, + : requestType{Async::RENDER_FIXED_SIZE}, manualRender{false}, maxTextureSize{0}, text{}, @@ -122,8 +128,8 @@ struct AsyncTextParameters { } - RenderType renderType; - bool manualRender : 1; + Async::RequestType requestType; + bool manualRender : 1; int maxTextureSize; ///< The maximum size of texture. @@ -221,7 +227,8 @@ struct AsyncTextRenderInfo isOverlayStyle(false), isTextDirectionRTL(false), isCutout(false), - manualRendered(false) + manualRendered(false), + requestType(Async::RENDER_FIXED_SIZE) { } @@ -246,6 +253,7 @@ struct AsyncTextRenderInfo bool isTextDirectionRTL; bool isCutout; bool manualRendered; + Async::RequestType requestType; }; /** @@ -329,6 +337,15 @@ public: * @return An AsyncTextRenderInfo. */ AsyncTextRenderInfo RenderAutoScroll(AsyncTextParameters& parameters); + + /** + * @brief Gets the natural size of text. + * + * @param[in] parameters All options required to compute text. + * + * @return An AsyncTextRenderInfo. + */ + AsyncTextRenderInfo GetNaturalSize(AsyncTextParameters& parameters); /** * @brief Get AsyncTextModule to used in text visual. diff --git a/dali-toolkit/internal/text/async-text/text-loading-task.cpp b/dali-toolkit/internal/text/async-text/text-loading-task.cpp index 937baed..5e20227 100644 --- a/dali-toolkit/internal/text/async-text/text-loading-task.cpp +++ b/dali-toolkit/internal/text/async-text/text-loading-task.cpp @@ -24,8 +24,6 @@ #include #include -// FOR TEST -#include namespace Dali { @@ -91,20 +89,54 @@ bool TextLoadingTask::IsReady() void TextLoadingTask::Load() { - if(mParameters.isAutoScrollEnabled && !mParameters.isMultiLine) + switch (mParameters.requestType) { - DALI_LOG_RELEASE_INFO("-->TextLoadingTask::Load RenderAutoScroll\n"); - mRenderInfo = mLoader.RenderAutoScroll(mParameters); - } - else if(mParameters.isTextFitEnabled || mParameters.isTextFitArrayEnabled) - { - DALI_LOG_RELEASE_INFO("-->TextLoadingTask::Load RenderTextFit\n"); - mRenderInfo = mLoader.RenderTextFit(mParameters); - } - else - { - DALI_LOG_RELEASE_INFO("-->TextLoadingTask::Load RenderText\n"); - mRenderInfo = mLoader.RenderText(mParameters); + case Text::Async::RENDER_FIXED_SIZE: + case Text::Async::RENDER_FIXED_WIDTH: + case Text::Async::RENDER_CONSTRAINT: + { + if(mParameters.isAutoScrollEnabled && !mParameters.isMultiLine) + { + DALI_LOG_RELEASE_INFO("-->TextLoadingTask::Load RenderAutoScroll\n"); + mRenderInfo = mLoader.RenderAutoScroll(mParameters); + } + else if(mParameters.isTextFitEnabled || mParameters.isTextFitArrayEnabled) + { + DALI_LOG_RELEASE_INFO("-->TextLoadingTask::Load RenderTextFit\n"); + mRenderInfo = mLoader.RenderTextFit(mParameters); + } + else + { + DALI_LOG_RELEASE_INFO("-->TextLoadingTask::Load RenderText\n"); + mRenderInfo = mLoader.RenderText(mParameters); + } + } + break; + + case Text::Async::COMPUTE_NATURAL_SIZE: + { + DALI_LOG_RELEASE_INFO("-->TextLoadingTask::Load GetNaturalSize\n"); + mRenderInfo = mLoader.GetNaturalSize(mParameters); + } + break; + + case Text::Async::COMPUTE_HEIGHT_FOR_WIDTH: + { + // TODO + } + break; + + case Text::Async::COMPUTE_LINE_COUNT: + { + // TODO + } + break; + + default: + { + DALI_LOG_ERROR("Unexpected request type recieved : %d\n", mParameters.requestType); + } + break; } } diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index 52d5c8a..c4c3c77 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -729,6 +729,17 @@ void TextVisual::LoadComplete(bool loadingSuccess, TextInformation textInformati Text::AsyncTextRenderInfo renderInfo = textInformation.renderInfo; Text::AsyncTextParameters parameters = textInformation.parameters; + if(parameters.requestType == Text::Async::COMPUTE_NATURAL_SIZE || + parameters.requestType == Text::Async::COMPUTE_HEIGHT_FOR_WIDTH || + parameters.requestType == Text::Async::COMPUTE_LINE_COUNT) + { + if(mAsyncTextInterface) + { + mAsyncTextInterface->AsyncSizeComputed(renderInfo); + return; + } + } + // Calculate the size of the visual that can fit the text. // The size of the text after it has been laid-out, size of pixel data buffer. Size layoutSize(static_cast(renderInfo.width), static_cast(renderInfo.height)); @@ -968,6 +979,20 @@ void TextVisual::SetAsyncTextInterface(Text::AsyncTextInterface* asyncTextInterf mAsyncTextInterface = asyncTextInterface; } +void TextVisual::RequestAsyncSizeComputation(Text::AsyncTextParameters& parameters) +{ + Actor control = mControl.GetHandle(); + if(!control) + { + // Nothing to do. + return; + } + + TextLoadObserver* textLoadObserver = this; + Text::AsyncTextManager::Get().RequestLoad(parameters, textLoadObserver); + DALI_LOG_RELEASE_INFO("-->TextVisual::RequestAsyncSizeComputation RequestLoad\n"); +} + void TextVisual::UpdateAsyncRenderer(Text::AsyncTextParameters& parameters) { Actor control = mControl.GetHandle(); @@ -978,7 +1003,7 @@ void TextVisual::UpdateAsyncRenderer(Text::AsyncTextParameters& parameters) return; } - if(parameters.renderType == Text::AsyncTextParameters::FIXED_SIZE && + if(parameters.requestType == Text::Async::RENDER_FIXED_SIZE && ((fabsf(parameters.textWidth) < Math::MACHINE_EPSILON_1000) || (fabsf(parameters.textHeight) < Math::MACHINE_EPSILON_1000) || parameters.text.empty())) { // Remove the texture set and any renderer previously set. diff --git a/dali-toolkit/internal/visuals/text/text-visual.h b/dali-toolkit/internal/visuals/text/text-visual.h index 7fba6de..55f46e3 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.h +++ b/dali-toolkit/internal/visuals/text/text-visual.h @@ -147,6 +147,16 @@ public: }; /** + * @brief Instantly requests the async size computation. + * @param[in] visual The text visual. + * @param[in] parameters The async text parameters. + */ + static void RequestAsyncSizeComputation(Toolkit::Visual::Base visual, Text::AsyncTextParameters& parameters) + { + GetVisualObject(visual).RequestAsyncSizeComputation(parameters); + }; + + /** * @brief Set the control's async text interface. * @param[in] visual The text visual. * @param[in] asyncTextInterface The async text interface. @@ -273,6 +283,12 @@ private: void UpdateAsyncRenderer(Text::AsyncTextParameters& parameters); /** + * @brief Requests the async size computation. + * @param[in] parameters The async text parameters. + */ + void RequestAsyncSizeComputation(Text::AsyncTextParameters& parameters); + + /** * @brief Set the control's async text interface. * @param[in] asyncTextInterface The async text interface. */ -- 2.7.4