From: ssabah Date: Mon, 5 Dec 2022 19:46:17 +0000 (+0300) Subject: Add GetFontRuns and GetFontDescriptionRuns into ModelInterface X-Git-Tag: dali_2.2.5~2^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=7e4ed6b62e50216e6141b4834b907e226c7f4a4d Add GetFontRuns and GetFontDescriptionRuns into ModelInterface Change-Id: Ibe0d4003ae5f523ba74e905686d8a38a1fa5a6a8 --- diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-ViewModel.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-ViewModel.cpp index daabc0b..80f8092 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-ViewModel.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-ViewModel.cpp @@ -669,3 +669,89 @@ int UtcDaliTextViewModelElideText02(void) tet_result(TET_PASS); END_TEST; } + +int UtcDaliTextViewModelGetFontRuns(void) +{ + tet_infoline(" UtcDaliTextViewModelGetFontRuns"); + ToolkitTestApplication application; + + // Load some fonts. + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.SetDpi(93u, 93u); + + char* pathNamePtr = get_current_dir_name(); + const std::string pathName(pathNamePtr); + free(pathNamePtr); + + fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf"); + + // Creates a text controller. + ControllerPtr controller = Controller::New(); + + // Tests the rendering controller has been created. + TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel()); + DALI_TEST_CHECK(typesetter); + + // Tests the view model has been created. + ViewModel* model = typesetter->GetViewModel(); + DALI_TEST_CHECK(NULL != model); + + // Configures the text controller similarly to the text-editor. + ConfigureTextEditor(controller); + + // Sets a text and relais-out. + controller->SetMarkupProcessorEnabled(true); + controller->SetText("Hello HelloHello"); + controller->Relayout(CONTROL_SIZE); + + const Vector& validFonts = model->GetFontRuns(); + + // The font-runs should be equal to number of segments have different fonts. + DALI_TEST_EQUALS(validFonts.Count(), 3u, TEST_LOCATION); + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliTextViewModelGetFontDescriptionRuns(void) +{ + tet_infoline(" UtcDaliTextViewModelGetFontDescriptionRuns"); + ToolkitTestApplication application; + + // Load some fonts. + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.SetDpi(93u, 93u); + + char* pathNamePtr = get_current_dir_name(); + const std::string pathName(pathNamePtr); + free(pathNamePtr); + + fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf"); + + // Creates a text controller. + ControllerPtr controller = Controller::New(); + + // Tests the rendering controller has been created. + TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel()); + DALI_TEST_CHECK(typesetter); + + // Tests the view model has been created. + ViewModel* model = typesetter->GetViewModel(); + DALI_TEST_CHECK(NULL != model); + + // Configures the text controller similarly to the text-editor. + ConfigureTextEditor(controller); + + // Sets a text and relais-out. + controller->SetMarkupProcessorEnabled(true); + controller->SetText("Hello HelloHello"); + controller->Relayout(CONTROL_SIZE); + + const Vector& validFonts = model->GetFontDescriptionRuns(); + + // The font-description-runs should be equal number of the used fonts. + DALI_TEST_EQUALS(validFonts.Count(), 2u, TEST_LOCATION); + + tet_result(TET_PASS); + END_TEST; +} \ No newline at end of file diff --git a/dali-toolkit/internal/text/rendering/view-model.cpp b/dali-toolkit/internal/text/rendering/view-model.cpp index 0c4aeb3..e743b36 100644 --- a/dali-toolkit/internal/text/rendering/view-model.cpp +++ b/dali-toolkit/internal/text/rendering/view-model.cpp @@ -739,6 +739,16 @@ const Vector& ViewModel::GetCharacterSpacingGlyphRuns( return mModel->GetCharacterSpacingGlyphRuns(); } +const Vector& ViewModel::GetFontRuns() const +{ + return mModel->GetFontRuns(); +} + +const Vector& ViewModel::GetFontDescriptionRuns() const +{ + return mModel->GetFontDescriptionRuns(); +} + } // namespace Text } // namespace Toolkit diff --git a/dali-toolkit/internal/text/rendering/view-model.h b/dali-toolkit/internal/text/rendering/view-model.h index c127ebb..71ad8bb 100644 --- a/dali-toolkit/internal/text/rendering/view-model.h +++ b/dali-toolkit/internal/text/rendering/view-model.h @@ -358,6 +358,16 @@ public: */ const Vector& GetCharacterSpacingGlyphRuns() const override; + /** + * @copydoc ModelInterface::GetFontRuns() + */ + const Vector& GetFontRuns() const override; + + /** + * @copydoc ModelInterface::GetFontDescriptionRuns() + */ + const Vector& GetFontDescriptionRuns() const override; + private: const ModelInterface* const mModel; ///< Pointer to the text's model. Vector mElidedGlyphs; ///< Stores the glyphs of the elided text. diff --git a/dali-toolkit/internal/text/text-model-interface.h b/dali-toolkit/internal/text/text-model-interface.h index 0ccbb45..df37c17 100644 --- a/dali-toolkit/internal/text/text-model-interface.h +++ b/dali-toolkit/internal/text/text-model-interface.h @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -462,6 +464,20 @@ public: * @return The GlyphsToCharacters. */ virtual const Vector& GetGlyphsToCharacters() const = 0; + + /** + * @brief Retrieves the reference for font runs. + * + * @return The reference for font runs. + */ + virtual const Vector& GetFontRuns() const = 0; + + /** + * @brief Retrieves the reference for font description runs. + * + * @return The reference for font description runs. + */ + virtual const Vector& GetFontDescriptionRuns() const = 0; }; } // namespace Text diff --git a/dali-toolkit/internal/text/text-model.cpp b/dali-toolkit/internal/text/text-model.cpp index ba6dbcf..d6a26ed 100644 --- a/dali-toolkit/internal/text/text-model.cpp +++ b/dali-toolkit/internal/text/text-model.cpp @@ -326,6 +326,16 @@ const Vector& Model::GetGlyphsToCharacters() const return mVisualModel->mGlyphsToCharacters; } +const Vector& Model::GetFontRuns() const +{ + return mLogicalModel->mFontRuns; +} + +const Vector& Model::GetFontDescriptionRuns() const +{ + return mLogicalModel->mFontDescriptionRuns; +} + Model::Model() : mLogicalModel(), mVisualModel(), diff --git a/dali-toolkit/internal/text/text-model.h b/dali-toolkit/internal/text/text-model.h index a3a42a2..0e224e5 100644 --- a/dali-toolkit/internal/text/text-model.h +++ b/dali-toolkit/internal/text/text-model.h @@ -344,6 +344,16 @@ public: */ const Vector& GetCharacterSpacingGlyphRuns() const override; + /** + * @copydoc ModelInterface::GetFontRuns() + */ + const Vector& GetFontRuns() const override; + + /** + * @copydoc ModelInterface::GetFontDescriptionRuns() + */ + const Vector& GetFontDescriptionRuns() const override; + private: // Private contructors & copy operator. /** * @brief Private constructor.