Support Emoji sequences
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / multi-language-support-impl.h
index 65933b5..cda767a 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H__
-#define __DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H__
+#ifndef DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H
+#define DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
-// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/text/multi-language-support.h>
-
 // EXTERNAL INCLUDES
 #include <dali/public-api/object/base-object.h>
 
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/multi-language-support.h>
+
 namespace Dali
 {
+namespace TextAbstraction
+{
+//Forward declaration
+class FontClient;
+} // namespace TextAbstraction
 
 namespace Toolkit
 {
-
 namespace Text
 {
-
 namespace Internal
 {
-
 /**
  * @brief Stores valid font ids per script.
  */
@@ -46,13 +48,15 @@ struct ValidateFontsPerScript
    */
   ValidateFontsPerScript()
   : mValidFonts()
-  {}
+  {
+  }
 
   /**
    * Default destructor.
    */
   ~ValidateFontsPerScript()
-  {}
+  {
+  }
 
   /**
    * @brief Whether the given @p fontId is in the vector of valid fonts.
@@ -61,18 +65,61 @@ struct ValidateFontsPerScript
    *
    * @return @e true if the font is in the vector of valid fonts.
    */
-  bool FindValidFont( FontId fontId ) const;
+  bool IsValidFont(FontId fontId) const;
 
   Vector<FontId> mValidFonts;
 };
 
 /**
+ * @brief Stores default font ids per script. It can be different sizes for a default font family.
+ */
+struct DefaultFonts
+{
+  struct CacheItem
+  {
+    TextAbstraction::FontDescription description;
+    FontId                           fontId;
+  };
+
+  /**
+   * Default constructor.
+   */
+  DefaultFonts()
+  : mFonts()
+  {
+  }
+
+  /**
+   * Default destructor.
+   */
+  ~DefaultFonts()
+  {
+  }
+
+  /**
+   * @brief Finds a default font for the given @p size.
+   *
+   * @param[in] fontClient The font client.
+   * @param[in] description The font's description.
+   * @param[in] size The given size.
+   *
+   * @return The font id of a default font for the given @p size. If there isn't any font cached it returns 0.
+   */
+  FontId FindFont(TextAbstraction::FontClient&            fontClient,
+                  const TextAbstraction::FontDescription& description,
+                  PointSize26Dot6                         size) const;
+
+  void Cache(const TextAbstraction::FontDescription& description, FontId fontId);
+
+  std::vector<CacheItem> mFonts;
+};
+
+/**
  * @brief Multi-language support implementation. @see Text::MultilanguageSupport.
  */
 class MultilanguageSupport : public BaseObject
 {
 public:
-
   /**
    * Constructor
    */
@@ -93,51 +140,64 @@ public:
   /**
    * @copydoc Dali::MultilanguageSupport::SetScripts()
    */
-  void SetScripts( const Vector<Character>& text,
-                   const Vector<LineBreakInfo>& lineBreakInfo,
-                   Vector<ScriptRun>& scripts );
-
-  /**
-   * @copydoc Dali::MultilanguageSupport::ReplaceScripts()
-   */
-  void ReplaceScripts( LogicalModel& model,
-                       CharacterIndex characterIndex,
-                       Length numberOfCharactersToRemove,
-                       Length numberOfCharactersToInsert );
+  void SetScripts(const Vector<Character>& text,
+                  CharacterIndex           startIndex,
+                  Length                   numberOfCharacters,
+                  Vector<ScriptRun>&       scripts);
 
   /**
-   * @copydoc Dali::MultilanguageSupport::ValidateFonts( const Vector<Character>& text, const Vector<ScriptRun>& scripts, Vector<FontRun>& fonts )
+   * @copydoc Dali::MultilanguageSupport::ValidateFonts()
    */
-  void ValidateFonts( const Vector<Character>& text,
-                      const Vector<ScriptRun>& scripts,
-                      Vector<FontRun>& fonts );
+  void ValidateFonts(const Vector<Character>&                text,
+                     const Vector<ScriptRun>&                scripts,
+                     const Vector<FontDescriptionRun>&       fontDescriptions,
+                     const TextAbstraction::FontDescription& defaultFontDescription,
+                     TextAbstraction::PointSize26Dot6        defaultFontPointSize,
+                     CharacterIndex                          startIndex,
+                     Length                                  numberOfCharacters,
+                     Vector<FontRun>&                        fonts);
 
-  /**
-   * @copydoc Dali::MultilanguageSupport::ValidateFonts( LogicalModel& model, CharacterIndex characterIndex, Length numberOfCharactersToRemove, Length numberOfCharactersToInsert )
-   */
-  void ValidateFonts( LogicalModel& model,
-                      CharacterIndex characterIndex,
-                      Length numberOfCharactersToRemove,
-                      Length numberOfCharactersToInsert );
 private:
-  Vector<FontId>                  mDefaultFontPerScriptCache; ///< Caches the default font for a script.
+  Vector<DefaultFonts*>           mDefaultFontPerScriptCache; ///< Caches default fonts for a script.
   Vector<ValidateFontsPerScript*> mValidFontsPerScriptCache;  ///< Caches valid fonts for a script.
+
+  //Methods
+
+  /**
+ * @brief Add the current script to scripts and create new script.
+ *
+ * @param[in] requestedScript The script of the new script run.
+ * @param[in] isRightToLeft The direction of the new script run.
+ * @param[in] addScriptCharactersToNewScript Whether to add the pending characters to the new script run or to the current script run.
+ * @param[inout] currentScriptRun The current character script run and it will be updated it to the new script run.
+ * @param[inout] numberOfAllScriptCharacters The pending characters.
+ * @param[inout] scripts The list of scripts.
+ * @param[inout] scriptIndex The current index of scripts.
+ *
+ */
+  void AddCurrentScriptAndCreatNewScript(const Script       requestedScript,
+                                         const bool         isRightToLeft,
+                                         const bool         addScriptCharactersToNewScript,
+                                         ScriptRun&         currentScriptRun,
+                                         Length&            numberOfAllScriptCharacters,
+                                         Vector<ScriptRun>& scripts,
+                                         ScriptRunIndex&    scriptIndex);
 };
 
 } // namespace Internal
 
-inline static Internal::MultilanguageSupport& GetImplementation( MultilanguageSupport& multilanguageSupport )
+inline static Internal::MultilanguageSupport& GetImplementation(MultilanguageSupport& multilanguageSupport)
 {
-  DALI_ASSERT_ALWAYS( multilanguageSupport && "multi-language handle is empty" );
+  DALI_ASSERT_ALWAYS(multilanguageSupport && "multi-language handle is empty");
   BaseObject& handle = multilanguageSupport.GetBaseObject();
-  return static_cast<Internal::MultilanguageSupport&>( handle );
+  return static_cast<Internal::MultilanguageSupport&>(handle);
 }
 
-inline static const Internal::MultilanguageSupport& GetImplementation( const MultilanguageSupport& multilanguageSupport )
+inline static const Internal::MultilanguageSupport& GetImplementation(const MultilanguageSupport& multilanguageSupport)
 {
-  DALI_ASSERT_ALWAYS( multilanguageSupport && "multi-language handle is empty" );
+  DALI_ASSERT_ALWAYS(multilanguageSupport && "multi-language handle is empty");
   const BaseObject& handle = multilanguageSupport.GetBaseObject();
-  return static_cast<const Internal::MultilanguageSupport&>( handle );
+  return static_cast<const Internal::MultilanguageSupport&>(handle);
 }
 
 } // namespace Text
@@ -146,4 +206,4 @@ inline static const Internal::MultilanguageSupport& GetImplementation( const Mul
 
 } // namespace Dali
 
-#endif // __DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H__
+#endif // DALI_TOOLKIT_TEXT_MULTI_LANGUAGE_SUPPORT_IMPL_H