Add GetFontRuns and GetFontDescriptionRuns into ModelInterface 33/285133/2
authorssabah <s.sabah@samsung.com>
Mon, 5 Dec 2022 19:46:17 +0000 (22:46 +0300)
committerssabah <s.sabah@samsung.com>
Tue, 6 Dec 2022 16:34:46 +0000 (19:34 +0300)
Change-Id: Ibe0d4003ae5f523ba74e905686d8a38a1fa5a6a8

automated-tests/src/dali-toolkit-internal/utc-Dali-Text-ViewModel.cpp
dali-toolkit/internal/text/rendering/view-model.cpp
dali-toolkit/internal/text/rendering/view-model.h
dali-toolkit/internal/text/text-model-interface.h
dali-toolkit/internal/text/text-model.cpp
dali-toolkit/internal/text/text-model.h

index daabc0b..80f8092 100755 (executable)
@@ -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("<font family='TizenSansRegular' size='10'>Hello </font>Hello<font family='TizenSansRegular' size='15'>Hello</font>");
+  controller->Relayout(CONTROL_SIZE);
+
+  const Vector<FontRun>& 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("<font family='TizenSansRegular' size='10'>Hello </font>Hello<font family='TizenSansRegular' size='15'>Hello</font>");
+  controller->Relayout(CONTROL_SIZE);
+
+  const Vector<FontDescriptionRun>& 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
index 0c4aeb3..e743b36 100644 (file)
@@ -739,6 +739,16 @@ const Vector<CharacterSpacingGlyphRun>& ViewModel::GetCharacterSpacingGlyphRuns(
   return mModel->GetCharacterSpacingGlyphRuns();
 }
 
+const Vector<FontRun>& ViewModel::GetFontRuns() const
+{
+  return mModel->GetFontRuns();
+}
+
+const Vector<FontDescriptionRun>& ViewModel::GetFontDescriptionRuns() const
+{
+  return mModel->GetFontDescriptionRuns();
+}
+
 } // namespace Text
 
 } // namespace Toolkit
index c127ebb..71ad8bb 100644 (file)
@@ -358,6 +358,16 @@ public:
    */
   const Vector<CharacterSpacingGlyphRun>& GetCharacterSpacingGlyphRuns() const override;
 
+  /**
+   * @copydoc ModelInterface::GetFontRuns()
+   */
+  const Vector<FontRun>& GetFontRuns() const override;
+
+  /**
+   * @copydoc ModelInterface::GetFontDescriptionRuns()
+   */
+  const Vector<FontDescriptionRun>& GetFontDescriptionRuns() const override;
+
 private:
   const ModelInterface* const mModel;                           ///< Pointer to the text's model.
   Vector<GlyphInfo>           mElidedGlyphs;                    ///< Stores the glyphs of the elided text.
index 0ccbb45..df37c17 100644 (file)
@@ -25,6 +25,8 @@
 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
 #include <dali-toolkit/internal/text/bounded-paragraph-run.h>
 #include <dali-toolkit/internal/text/character-spacing-glyph-run.h>
+#include <dali-toolkit/internal/text/font-description-run.h>
+#include <dali-toolkit/internal/text/font-run.h>
 #include <dali-toolkit/internal/text/line-run.h>
 #include <dali-toolkit/internal/text/script-run.h>
 #include <dali-toolkit/internal/text/strikethrough-glyph-run.h>
@@ -462,6 +464,20 @@ public:
    * @return The GlyphsToCharacters.
    */
   virtual const Vector<CharacterIndex>& GetGlyphsToCharacters() const = 0;
+
+  /**
+   * @brief Retrieves the reference for font runs.
+   *
+   * @return The reference for font runs.
+   */
+  virtual const Vector<FontRun>& GetFontRuns() const = 0;
+
+  /**
+   * @brief Retrieves the reference for font description runs.
+   *
+   * @return The reference for font description runs.
+   */
+  virtual const Vector<FontDescriptionRun>& GetFontDescriptionRuns() const = 0;
 };
 
 } // namespace Text
index ba6dbcf..d6a26ed 100644 (file)
@@ -326,6 +326,16 @@ const Vector<CharacterIndex>& Model::GetGlyphsToCharacters() const
   return mVisualModel->mGlyphsToCharacters;
 }
 
+const Vector<FontRun>& Model::GetFontRuns() const
+{
+  return mLogicalModel->mFontRuns;
+}
+
+const Vector<FontDescriptionRun>& Model::GetFontDescriptionRuns() const
+{
+  return mLogicalModel->mFontDescriptionRuns;
+}
+
 Model::Model()
 : mLogicalModel(),
   mVisualModel(),
index a3a42a2..0e224e5 100644 (file)
@@ -344,6 +344,16 @@ public:
    */
   const Vector<CharacterSpacingGlyphRun>& GetCharacterSpacingGlyphRuns() const override;
 
+  /**
+   * @copydoc ModelInterface::GetFontRuns()
+   */
+  const Vector<FontRun>& GetFontRuns() const override;
+
+  /**
+   * @copydoc ModelInterface::GetFontDescriptionRuns()
+   */
+  const Vector<FontDescriptionRun>& GetFontDescriptionRuns() const override;
+
 private: // Private contructors & copy operator.
   /**
    * @brief Private constructor.