[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / multi-language-helper-functions.cpp
index a5feaef..930cb8b 100644 (file)
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Text
 {
-
-void MergeFontDescriptions( const Vector<FontDescriptionRun>& fontDescriptions,
-                            Vector<FontId>& fontIds,
-                            const TextAbstraction::FontDescription& defaultFontDescription,
-                            TextAbstraction::PointSize26Dot6 defaultPointSize,
-                            CharacterIndex startIndex,
-                            Length numberOfCharacters )
+void MergeFontDescriptions(const Vector<FontDescriptionRun>&       fontDescriptions,
+                           const TextAbstraction::FontDescription& defaultFontDescription,
+                           TextAbstraction::PointSize26Dot6        defaultPointSize,
+                           float                                   fontSizeScale,
+                           CharacterIndex                          characterIndex,
+                           TextAbstraction::FontDescription&       fontDescription,
+                           TextAbstraction::PointSize26Dot6&       fontPointSize,
+                           bool&                                   isDefaultFont)
 {
-  // Get the handle to the font client.
-  TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
-
-  // Pointer to the font id buffer.
-  FontId* fontIdsBuffer = fontIds.Begin();
-
-  // Traverse all the characters.
-  for( CharacterIndex index = startIndex; index < numberOfCharacters; ++index )
+  // Initialize with the default font's point size.
+  fontPointSize = defaultPointSize;
+
+  // Initialize with the style parameters of the default font's style.
+  fontDescription = defaultFontDescription;
+
+  // Initialize as a default font.
+  isDefaultFont = true;
+
+  Length runIndex = 0u;
+
+  Length familyIndex = 0u;
+  Length weightIndex = 0u;
+  Length widthIndex  = 0u;
+  Length slantIndex  = 0u;
+  Length sizeIndex   = 0u;
+
+  bool familyOverriden = false;
+  bool weightOverriden = false;
+  bool widthOverriden  = false;
+  bool slantOverriden  = false;
+  bool sizeOverriden   = false;
+
+  // Traverse all the font descriptions.
+  const FontDescriptionRun* const fontDescriptionsBuffer = fontDescriptions.Begin();
+  for(Vector<FontDescriptionRun>::ConstIterator it    = fontDescriptionsBuffer,
+                                                endIt = fontDescriptions.End();
+      it != endIt;
+      ++it, ++runIndex)
   {
-    // The default font description and font point size.
-    TextAbstraction::FontDescription fontDescription = defaultFontDescription;
-    TextAbstraction::PointSize26Dot6 fontSize = defaultPointSize;
-    bool defaultFont = true;
-
-    // Traverse all the font descriptions.
-    for( Vector<FontDescriptionRun>::ConstIterator it = fontDescriptions.Begin(),
-           endIt = fontDescriptions.End();
-         it != endIt;
-         ++it )
+    // Check whether the character's font is modified by the current font description.
+    const FontDescriptionRun& fontRun = *it;
+    if((characterIndex >= fontRun.characterRun.characterIndex) &&
+       (characterIndex < fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters))
     {
-      // Check whether the character's font is modified by the current font description.
-      const FontDescriptionRun& fontRun = *it;
-      if( ( index >= fontRun.characterRun.characterIndex ) &&
-          ( index < fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters ) )
+      if(fontRun.familyDefined)
+      {
+        isDefaultFont   = false;
+        familyOverriden = true;
+        familyIndex     = runIndex;
+      }
+      if(fontRun.weightDefined)
       {
-        if( fontRun.familyDefined )
-        {
-          fontDescription.family = std::string( fontRun.familyName, fontRun.familyLength );
-          defaultFont = false;
-        }
-        if( fontRun.weightDefined )
-        {
-          fontDescription.weight = fontRun.weight;
-          defaultFont = false;
-        }
-        if( fontRun.widthDefined )
-        {
-          fontDescription.width = fontRun.width;
-          defaultFont = false;
-        }
-        if( fontRun.slantDefined )
-        {
-          fontDescription.slant = fontRun.slant;
-          defaultFont = false;
-        }
-        if( fontRun.sizeDefined )
-        {
-          fontSize = fontRun.size;
-          defaultFont = false;
-        }
+        isDefaultFont   = false;
+        weightOverriden = true;
+        weightIndex     = runIndex;
       }
+      if(fontRun.widthDefined)
+      {
+        isDefaultFont  = false;
+        widthOverriden = true;
+        widthIndex     = runIndex;
+      }
+      if(fontRun.slantDefined)
+      {
+        isDefaultFont  = false;
+        slantOverriden = true;
+        slantIndex     = runIndex;
+      }
+      if(fontRun.sizeDefined)
+      {
+        isDefaultFont = false;
+        sizeOverriden = true;
+        sizeIndex     = runIndex;
+      }
+    }
+  }
+
+  // Get the font's description if is not the default font.
+  if(!isDefaultFont)
+  {
+    if(familyOverriden)
+    {
+      const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + familyIndex);
+      fontDescription.family            = std::string(fontRun.familyName, fontRun.familyLength);
+    }
+
+    if(weightOverriden)
+    {
+      const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + weightIndex);
+      fontDescription.weight            = fontRun.weight;
+    }
+
+    if(widthOverriden)
+    {
+      const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + widthIndex);
+      fontDescription.width             = fontRun.width;
+    }
+
+    if(slantOverriden)
+    {
+      const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + slantIndex);
+      fontDescription.slant             = fontRun.slant;
     }
 
-    // Get the font id if is not the default font.
-    if( !defaultFont )
+    if(sizeOverriden)
     {
-      *( fontIdsBuffer + index - startIndex ) = fontClient.GetFontId( fontDescription, fontSize );
+      const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + sizeIndex);
+      fontPointSize                     = static_cast<PointSize26Dot6>(fontRun.size * fontSizeScale);
     }
   }
 }
 
-Script GetScript( Length index,
-                  Vector<ScriptRun>::ConstIterator& scriptRunIt,
-                  const Vector<ScriptRun>::ConstIterator& scriptRunEndIt )
+Script GetScript(Length                                  index,
+                 Vector<ScriptRun>::ConstIterator&       scriptRunIt,
+                 const Vector<ScriptRun>::ConstIterator& scriptRunEndIt)
 {
   Script script = TextAbstraction::UNKNOWN;
 
-  while( scriptRunIt != scriptRunEndIt )
+  while(scriptRunIt != scriptRunEndIt)
   {
     const ScriptRun& scriptRun = *scriptRunIt;
 
-    if( index >= scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters )
+    if(index >= scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters)
     {
       ++scriptRunIt;
     }
-    else if( index >= scriptRun.characterRun.characterIndex )
+    else if(index >= scriptRun.characterRun.characterIndex)
     {
       script = scriptRun.script;
 
-      if( index + 1u == scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters )
+      if(index + 1u == scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters)
       {
         // All the characters of the current run have been traversed. Get the next one for the next iteration.
         ++scriptRunIt;