Multi-language support interface
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / text / visual-model.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 // CLASS HEADER
19 #include <dali-toolkit/public-api/text/visual-model.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali-toolkit/public-api/text/line-run.h>
25
26 // EXTERNAL INCLUDES
27 #include <memory.h>
28 #include <vector>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Text
37 {
38
39 const GlyphInfo GLYPH_INFO; // VCC to be removed.
40
41 struct VisualModel::Impl
42 {
43   Vector<GlyphInfo>      mGlyphs;
44   Vector<CharacterIndex> mGlyphsToCharacters;
45   Vector<Length>         mCharactersPerGlyph;
46   std::vector<Vector2>   mGlyphPositions;
47
48   Size                   mNaturalSize;
49   Size                   mActualSize;
50 };
51
52 VisualModelPtr VisualModel::New()
53 {
54   return VisualModelPtr( new VisualModel() );
55 }
56
57 void VisualModel::SetGlyphs( const GlyphInfo* glyphs,
58                              const CharacterIndex* characterIndices,
59                              const Length* charactersPerGlyph,
60                              Length numberOfGlyphs )
61 {
62   Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
63   modelGlyphs.Resize( numberOfGlyphs );
64   memcpy( &modelGlyphs[0], glyphs, numberOfGlyphs*sizeof(GlyphInfo) );
65
66   Vector<CharacterIndex>& glyphsToCharacters = mImpl->mGlyphsToCharacters;
67   glyphsToCharacters.Resize( numberOfGlyphs );
68   memcpy( &glyphsToCharacters[0], characterIndices, numberOfGlyphs*sizeof(CharacterIndex) );
69
70   Vector<Length>& modelCharactersPerGlyph = mImpl->mCharactersPerGlyph;
71   modelCharactersPerGlyph.Resize( numberOfGlyphs );
72   memcpy( &modelCharactersPerGlyph[0], charactersPerGlyph, numberOfGlyphs*sizeof(Length) );
73 }
74
75 Length VisualModel::GetNumberOfGlyphs() const
76 {
77   return mImpl->mGlyphs.Count();
78 }
79
80 void VisualModel::GetGlyphs( GlyphInfo* glyphs,
81                              GlyphIndex glyphIndex,
82                              Length numberOfGlyphs ) const
83 {
84   Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
85   memcpy( glyphs, &modelGlyphs[glyphIndex], numberOfGlyphs*sizeof(GlyphInfo) );
86 }
87
88 const GlyphInfo& VisualModel::GetGlyphInfo( GlyphIndex glyphIndex ) const
89 {
90   return GLYPH_INFO;
91 }
92
93 CharacterIndex VisualModel::GetCharacterIndex( GlyphIndex glyphIndex ) const
94 {
95   return mImpl->mGlyphsToCharacters[glyphIndex];
96 }
97
98 Length VisualModel::GetCharactersPerGlyph( GlyphIndex glyphIndex ) const
99 {
100   return mImpl->mCharactersPerGlyph[glyphIndex];
101 }
102
103 GlyphIndex VisualModel::GetGlyphIndex( CharacterIndex characterIndex ) const
104 {
105   GlyphIndex index( 0 );
106
107   for( unsigned int i=0; i<mImpl->mGlyphsToCharacters.Count(); ++i )
108   {
109     if( mImpl->mGlyphsToCharacters[i] == characterIndex )
110     {
111       index = i;
112       break;
113     }
114   }
115
116   return index;
117 }
118
119 void VisualModel::GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
120                                           CharacterIndex characterIndex,
121                                           Length numberOfCharacters ) const
122 {
123 }
124
125 void VisualModel::GetCharactersPerGlyphMap( Length* charactersPerGlyph,
126                                             GlyphIndex glyphIndex,
127                                             Length numberOfGlyphs ) const
128 {
129 }
130
131 void VisualModel::GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
132                                           GlyphIndex glyphIndex,
133                                           Length numberOfGlyphs ) const
134 {
135 }
136
137 void VisualModel::SetGlyphPositions( const Vector2* glyphPositions,
138                                      Length numberOfGlyphs )
139 {
140   std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
141   modelPositions.resize( numberOfGlyphs );
142   memcpy( &modelPositions[0], glyphPositions, numberOfGlyphs*sizeof(Vector2) );
143 }
144
145 void VisualModel::GetGlyphPositions( Vector2* glyphPositions,
146                                      GlyphIndex glyphIndex,
147                                      Length numberOfGlyphs ) const
148 {
149   std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
150   memcpy( glyphPositions, &modelPositions[0], numberOfGlyphs*sizeof(Vector2) );
151 }
152
153 const Vector2& VisualModel::GetGlyphPosition( GlyphIndex glyphIndex ) const
154 {
155   return Vector2::ZERO;
156 }
157
158 void VisualModel::SetLines( const LineRun* const lines,
159                             Length numberOfLines )
160 {
161 }
162
163 Length VisualModel::GetNumberOfLines() const
164 {
165   return 0u;
166 }
167
168 void VisualModel::GetLines( LineRun* lines,
169                             LineIndex lineIndex,
170                             Length numberOfLines ) const
171 {
172 }
173
174 Length VisualModel::GetNumberOfLines( GlyphIndex glyphIndex,
175                                       Length numberOfGlyphs ) const
176 {
177   return 0u;
178 }
179
180 void VisualModel::GetLinesOfGlyphRange( LineRun* lines,
181                                         GlyphIndex glyphIndex,
182                                         Length numberOfGlyphs ) const
183 {
184 }
185
186 void VisualModel::SetNaturalSize( const Vector2& size  )
187 {
188   mImpl->mNaturalSize = size;
189 }
190
191 const Vector2& VisualModel::GetNaturalSize() const
192 {
193   return mImpl->mNaturalSize;
194 }
195
196 void VisualModel::SetActualSize( const Vector2& size )
197 {
198   mImpl->mActualSize = size;
199 }
200
201 const Vector2& VisualModel::GetActualSize() const
202 {
203   return mImpl->mActualSize;
204 }
205
206 VisualModel::~VisualModel()
207 {
208   delete mImpl;
209 }
210
211 VisualModel::VisualModel()
212 : mImpl( NULL )
213 {
214   mImpl = new VisualModel::Impl();
215 }
216
217 } // namespace Text
218
219 } // namespace Toolkit
220
221 } // namespace Dali