[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / glyph-metrics-helper.h
index 6856d27..0c996db 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXT_GLYPH_METRICS_HELPER_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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/internal/text/logical-model-impl.h>
 #include <dali-toolkit/internal/text/metrics.h>
+#include <dali-toolkit/internal/text/visual-model-impl.h>
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Text
 {
-
 /**
  * @brief Some characters can be shaped in more than one glyph.
  * This struct is used to retrieve metrics from these group of glyphs.
@@ -37,16 +36,18 @@ namespace Text
 struct GlyphMetrics
 {
   GlyphMetrics()
-  : fontId( 0u ),
-    fontHeight( 0.f ),
-    width( 0.f ),
-    advance( 0.f ),
-    ascender( 0.f ),
-    xBearing( 0.f )
-  {}
+  : fontId(0u),
+    fontHeight(0.f),
+    width(0.f),
+    advance(0.f),
+    ascender(0.f),
+    xBearing(0.f)
+  {
+  }
 
   ~GlyphMetrics()
-  {}
+  {
+  }
 
   FontId fontId;     ///< The font id of the glyphs.
   float  fontHeight; ///< The font's height of those glyphs.
@@ -65,9 +66,9 @@ struct GlyphMetrics
  *
  * @return The number of glyphs of the group.
  */
-Length GetNumberOfGlyphsOfGroup( GlyphIndex glyphIndex,
-                                 GlyphIndex lastGlyphPlusOne,
-                                 const Length* const charactersPerGlyphBuffer );
+Length GetNumberOfGlyphsOfGroup(GlyphIndex          glyphIndex,
+                                GlyphIndex          lastGlyphPlusOne,
+                                const Length* const charactersPerGlyphBuffer);
 
 /**
  * @brief Get some glyph's metrics of a group of glyphs formed as a result of shaping one character.
@@ -77,12 +78,46 @@ Length GetNumberOfGlyphsOfGroup( GlyphIndex glyphIndex,
  * @param[out] glyphMetrics Some glyph metrics (font height, advance, ascender and x bearing).
  * @param[in] glyphsBuffer The glyphs buffer.
  * @param[in] metrics Used to access metrics from FontClient.
+ * @param[in] calculatedAdvance The final advance value obtained by adding the CharacterSpacing value to the original advance. In some cases the CharacterSpacing should not be added. Ex: when the glyph is a ZWSP (Zero Width Space)
+ */
+void GetGlyphsMetrics(GlyphIndex             glyphIndex,
+                      Length                 numberOfGlyphs,
+                      GlyphMetrics&          glyphMetrics,
+                      const GlyphInfo* const glyphsBuffer,
+                      MetricsPtr&            metrics,
+                      float                  calculatedAdvance);
+
+/**
+ * @brief Gets the final advance value by adding the CharacterSpacing value to it
+ *In some cases the CharacterSpacing should not be added. Ex: when the glyph is a ZWSP (Zero Width Space)
+ *
+ * @param[in] character The character of which the advance is to be calculated.
+ * @param[in] characterSpacing The character spacing to be added to the advance.
+ * @param[in] advance The original advance.
+ *
+ * @return The calculated advance
+ */
+float GetCalculatedAdvance(unsigned int character, float characterSpacing, float advance);
+
+/**
+ * @brief Takes the character index, obtains the glyph index (and the number of Glyphs) from it and finally gets the glyph metrics.
+ *
+ * @param[in] index The character index.
+ * @param[in] visualModel The visual model.
+ * @param[in] logicalModel The logical model.
+ * @param[in] metrics Used to access metrics from FontClient.
+ * @param[out] glyphMetrics Some glyph metrics (font height, advance, ascender and x bearing).
+ * @param[out] glyphIndex The glyph index obtained from the character index.
+ * @param[out] numberOfGlyphs The number of glyphs in the character of which the index was passed to the function.
+ *
  */
-void GetGlyphsMetrics( GlyphIndex glyphIndex,
-                       Length numberOfGlyphs,
-                       GlyphMetrics& glyphMetrics,
-                       const GlyphInfo* const glyphsBuffer,
-                       MetricsPtr& metrics );
+void GetGlyphMetricsFromCharacterIndex(CharacterIndex         index,
+                                       const VisualModelPtr&  visualModel,
+                                       const LogicalModelPtr& logicalModel,
+                                       MetricsPtr&            metrics,
+                                       GlyphMetrics&          glyphMetrics,
+                                       GlyphIndex&            glyphIndex,
+                                       Length&                numberOfGlyphs);
 
 } // namespace Text