TextModel 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
49 VisualModelPtr VisualModel::New()
50 {
51   return VisualModelPtr( new VisualModel() );
52 }
53
54 void VisualModel::SetGlyphs( const GlyphInfo* glyphs,
55                              const CharacterIndex* characterIndices,
56                              const Length* charactersPerGlyph,
57                              Length numberOfGlyphs )
58 {
59   Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
60   modelGlyphs.Resize( numberOfGlyphs );
61   memcpy( &modelGlyphs[0], glyphs, numberOfGlyphs*sizeof(GlyphInfo) );
62
63   Vector<CharacterIndex>& glyphsToCharacters = mImpl->mGlyphsToCharacters;
64   glyphsToCharacters.Resize( numberOfGlyphs );
65   memcpy( &glyphsToCharacters[0], characterIndices, numberOfGlyphs*sizeof(CharacterIndex) );
66
67   Vector<Length>& modelCharactersPerGlyph = mImpl->mCharactersPerGlyph;
68   modelCharactersPerGlyph.Resize( numberOfGlyphs );
69   memcpy( &modelCharactersPerGlyph[0], charactersPerGlyph, numberOfGlyphs*sizeof(Length) );
70 }
71
72 Length VisualModel::GetNumberOfGlyphs() const
73 {
74   return mImpl->mGlyphs.Count();
75 }
76
77 void VisualModel::GetGlyphs( GlyphIndex glyphIndex,
78                              GlyphInfo* glyphs,
79                              Length numberOfGlyphs ) const
80 {
81   Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
82   memcpy( glyphs, &modelGlyphs[glyphIndex], numberOfGlyphs*sizeof(GlyphInfo) );
83 }
84
85 const GlyphInfo& VisualModel::GetGlyphInfo( GlyphIndex glyphIndex ) const
86 {
87   return GLYPH_INFO;
88 }
89
90 CharacterIndex VisualModel::GetCharacterIndex( GlyphIndex glyphIndex ) const
91 {
92   return mImpl->mGlyphsToCharacters[glyphIndex];
93 }
94
95 Length VisualModel::GetCharactersPerGlyph( GlyphIndex glyphIndex ) const
96 {
97   return mImpl->mCharactersPerGlyph[glyphIndex];
98 }
99
100 GlyphIndex VisualModel::GetGlyphIndex( CharacterIndex characterIndex ) const
101 {
102   GlyphIndex index( 0 );
103
104   for( unsigned int i=0; i<mImpl->mGlyphsToCharacters.Count(); ++i )
105   {
106     if( mImpl->mGlyphsToCharacters[i] == characterIndex )
107     {
108       index = i;
109       break;
110     }
111   }
112
113   return index;
114 }
115
116 void VisualModel::GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
117                                           CharacterIndex characterIndex,
118                                           Length numberOfCharacters ) const
119 {
120 }
121
122 void VisualModel::GetCharactersPerGlyphMap( Length* charactersPerGlyph,
123                                             GlyphIndex glyphIndex,
124                                             Length numberOfGlyphs ) const
125 {
126 }
127
128 void VisualModel::GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
129                                           GlyphIndex glyphIndex,
130                                           Length numberOfGlyphs ) const
131 {
132 }
133
134 void VisualModel::SetGlyphPositions( const Vector2* glyphPositions,
135                                      Length numberOfGlyphs )
136 {
137   std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
138   modelPositions.resize( numberOfGlyphs );
139   memcpy( &modelPositions[0], glyphPositions, numberOfGlyphs*sizeof(Vector2) );
140 }
141
142 void VisualModel::GetGlyphPositions( GlyphIndex glyphIndex,
143                                      Vector2* glyphPositions,
144                                      Length numberOfGlyphs ) const
145 {
146   std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
147   memcpy( glyphPositions, &modelPositions[0], numberOfGlyphs*sizeof(Vector2) );
148 }
149
150 const Vector2& VisualModel::GetGlyphPosition( GlyphIndex glyphIndex ) const
151 {
152   return Vector2::ZERO;
153 }
154
155 void VisualModel::SetLines( const LineRun* const lines,
156                             Length numberOfLines )
157 {
158 }
159
160 Length VisualModel::GetNumberOfLines() const
161 {
162   return 0u;
163 }
164
165 void VisualModel::GetLines( LineRun* lines,
166                             LineIndex lineIndex,
167                             Length numberOfLines ) const
168 {
169 }
170
171 Length VisualModel::GetNumberOfLines( GlyphIndex glyphIndex,
172                                       Length numberOfGlyphs ) const
173 {
174   return 0u;
175 }
176
177 void VisualModel::GetLinesOfGlyphRange( LineRun* lines,
178                                         GlyphIndex glyphIndex,
179                                         Length numberOfGlyphs ) const
180 {
181 }
182
183 void VisualModel::SetNaturalSize( const Vector2& size  )
184 {
185 }
186
187 const Vector2& VisualModel::GetNaturalSize() const
188 {
189   return Vector2::ZERO;
190 }
191
192 void VisualModel::SetActualSize( const Vector2& size )
193 {
194 }
195
196 const Vector2& VisualModel::GetActualSize() const
197 {
198   return Vector2::ZERO;
199 }
200
201 VisualModel::~VisualModel()
202 {
203   delete mImpl;
204 }
205
206 VisualModel::VisualModel()
207 : mImpl( NULL )
208 {
209   mImpl = new VisualModel::Impl();
210 }
211
212 } // namespace Text
213
214 } // namespace Toolkit
215
216 } // namespace Dali