Merge "fix issue in negative line spacing with key arrow down" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / characters-helper-functions.cpp
1 // FILE HEADER
2 #include <dali-toolkit/internal/text/characters-helper-functions.h>
3
4 // INTERNAL INCLUDES
5 #include <dali-toolkit/internal/text/emoji-helper.h>
6
7 namespace Dali
8 {
9 namespace Toolkit
10 {
11 namespace Text
12 {
13 CharacterRun RetrieveClusteredCharactersOfCharacterIndex(const VisualModelPtr&  visualModel,
14                                                          const LogicalModelPtr& logicalModel,
15                                                          const CharacterIndex&  characterIndex)
16 {
17   // Initialization
18   CharacterRun clusteredCharacters;
19   clusteredCharacters.characterIndex     = characterIndex;
20   clusteredCharacters.numberOfCharacters = 1u;
21
22   const GlyphIndex* const     charactersToGlyphBuffer  = visualModel->mCharactersToGlyph.Begin();
23   const Length* const         charactersPerGlyphBuffer = visualModel->mCharactersPerGlyph.Begin();
24   const CharacterIndex* const glyphsToCharacters       = visualModel->mGlyphsToCharacters.Begin();
25
26   GlyphIndex glyphIndex               = *(charactersToGlyphBuffer + characterIndex);
27   Length     actualNumberOfCharacters = *(charactersPerGlyphBuffer + glyphIndex);
28
29   if(actualNumberOfCharacters > 1u)
30   {
31     const Script script = logicalModel->GetScript(characterIndex);
32     // Prevents to break the Latin ligatures like fi, ff, or Arabic ﻻ, ...
33     // Keep actual index of character as is. Because these characters cannot be clustered.
34
35     if(!HasLigatureMustBreak(script))
36     {
37       clusteredCharacters.numberOfCharacters = actualNumberOfCharacters;
38       clusteredCharacters.characterIndex     = *(glyphsToCharacters + glyphIndex); // firstCharacterIndex
39     }
40   }
41   else
42   {
43     while(0u == actualNumberOfCharacters)
44     {
45       ++glyphIndex;
46       actualNumberOfCharacters = *(charactersPerGlyphBuffer + glyphIndex);
47     }
48
49     clusteredCharacters.characterIndex     = *(glyphsToCharacters + glyphIndex); // firstCharacterIndex
50     clusteredCharacters.numberOfCharacters = actualNumberOfCharacters;
51   }
52
53   return clusteredCharacters;
54 }
55
56 } // namespace Text
57
58 } // namespace Toolkit
59
60 } // namespace Dali