[dali_1.1.15] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / color-segmentation.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // FILE HEADER
19 #include <dali-toolkit/internal/text/color-segmentation.h>
20
21 // EXTERNAL INCLUDES
22
23 // INTERNAL INCLUDES
24
25 #include <iostream>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Text
34 {
35
36 void SetColorSegmentationInfo( const Vector<ColorRun>& characterColorRuns,
37                                const Vector<GlyphIndex>& charactersToGlyph,
38                                const Vector<Length>& glyphsPerCharacter,
39                                Vector<ColorGlyphRun>& glyphColorRuns )
40 {
41   const VectorBase::SizeType numberOfColorRuns = characterColorRuns.Count();
42
43   if( 0u == numberOfColorRuns )
44   {
45     // Nothing to do.
46     return;
47   }
48
49   // Resize the color runs for the glyphs.
50   glyphColorRuns.Resize( numberOfColorRuns );
51
52   // Get pointers to the buffers.
53   ColorGlyphRun* glyphColorRunsBuffer = glyphColorRuns.Begin();
54   const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
55   const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
56
57   // Convert from characters to glyphs.
58   Length index = 0u;
59   for( Vector<ColorRun>::ConstIterator it = characterColorRuns.Begin(),
60          endIt = characterColorRuns.End();
61        it != endIt;
62        ++it, ++index )
63   {
64     const ColorRun& colorRun = *it;
65
66     if( 0u < colorRun.characterRun.numberOfCharacters )
67     {
68       // Get the next color glyph run.
69       ColorGlyphRun& colorGlyphRun = *( glyphColorRunsBuffer + index );
70       colorGlyphRun.color = colorRun.color;
71
72       // Convert the color run index from character to glyph.
73       colorGlyphRun.glyphRun.glyphIndex = *( charactersToGlyphBuffer + colorRun.characterRun.characterIndex );
74
75       // Get the index to the last character of the run.
76       const CharacterIndex lastIndex = colorRun.characterRun.characterIndex + colorRun.characterRun.numberOfCharacters - 1u;
77
78       // Calculate the number of glyphs.
79       colorGlyphRun.glyphRun.numberOfGlyphs = *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - colorGlyphRun.glyphRun.glyphIndex;
80     }
81   }
82 }
83
84 } // namespace Text
85
86 } // namespace Toolkit
87
88 } // namespace Dali