2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/text/visual-model.h>
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali-toolkit/internal/text/line-run.h>
39 const GlyphInfo GLYPH_INFO; // VCC to be removed.
41 struct VisualModel::Impl
43 Vector<GlyphInfo> mGlyphs;
44 Vector<CharacterIndex> mGlyphsToCharacters;
45 Vector<Length> mCharactersPerGlyph;
46 std::vector<Vector2> mGlyphPositions;
52 VisualModelPtr VisualModel::New()
54 return VisualModelPtr( new VisualModel() );
57 void VisualModel::SetGlyphs( const GlyphInfo* glyphs,
58 const CharacterIndex* characterIndices,
59 const Length* charactersPerGlyph,
60 Length numberOfGlyphs )
62 Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
63 modelGlyphs.Resize( numberOfGlyphs );
64 memcpy( &modelGlyphs[0], glyphs, numberOfGlyphs*sizeof(GlyphInfo) );
66 Vector<CharacterIndex>& glyphsToCharacters = mImpl->mGlyphsToCharacters;
67 glyphsToCharacters.Resize( numberOfGlyphs );
68 memcpy( &glyphsToCharacters[0], characterIndices, numberOfGlyphs*sizeof(CharacterIndex) );
70 Vector<Length>& modelCharactersPerGlyph = mImpl->mCharactersPerGlyph;
71 modelCharactersPerGlyph.Resize( numberOfGlyphs );
72 memcpy( &modelCharactersPerGlyph[0], charactersPerGlyph, numberOfGlyphs*sizeof(Length) );
75 Length VisualModel::GetNumberOfGlyphs() const
77 return mImpl->mGlyphs.Count();
80 void VisualModel::GetGlyphs( GlyphInfo* glyphs,
81 GlyphIndex glyphIndex,
82 Length numberOfGlyphs ) const
84 Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
85 memcpy( glyphs, &modelGlyphs[glyphIndex], numberOfGlyphs*sizeof(GlyphInfo) );
88 const GlyphInfo& VisualModel::GetGlyphInfo( GlyphIndex glyphIndex ) const
93 CharacterIndex VisualModel::GetCharacterIndex( GlyphIndex glyphIndex ) const
95 return mImpl->mGlyphsToCharacters[glyphIndex];
98 Length VisualModel::GetCharactersPerGlyph( GlyphIndex glyphIndex ) const
100 return mImpl->mCharactersPerGlyph[glyphIndex];
103 GlyphIndex VisualModel::GetGlyphIndex( CharacterIndex characterIndex ) const
105 GlyphIndex index( 0 );
107 for( unsigned int i=0; i<mImpl->mGlyphsToCharacters.Count(); ++i )
109 if( mImpl->mGlyphsToCharacters[i] == characterIndex )
119 void VisualModel::GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
120 CharacterIndex characterIndex,
121 Length numberOfCharacters ) const
125 void VisualModel::GetCharactersPerGlyphMap( Length* charactersPerGlyph,
126 GlyphIndex glyphIndex,
127 Length numberOfGlyphs ) const
131 void VisualModel::GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
132 GlyphIndex glyphIndex,
133 Length numberOfGlyphs ) const
137 void VisualModel::SetGlyphPositions( const Vector2* glyphPositions,
138 Length numberOfGlyphs )
140 std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
141 modelPositions.resize( numberOfGlyphs );
142 memcpy( &modelPositions[0], glyphPositions, numberOfGlyphs*sizeof(Vector2) );
145 void VisualModel::GetGlyphPositions( Vector2* glyphPositions,
146 GlyphIndex glyphIndex,
147 Length numberOfGlyphs ) const
149 std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
150 memcpy( glyphPositions, &modelPositions[0], numberOfGlyphs*sizeof(Vector2) );
153 const Vector2& VisualModel::GetGlyphPosition( GlyphIndex glyphIndex ) const
155 return Vector2::ZERO;
158 void VisualModel::SetLines( const LineRun* const lines,
159 Length numberOfLines )
163 Length VisualModel::GetNumberOfLines() const
168 void VisualModel::GetLines( LineRun* lines,
170 Length numberOfLines ) const
174 Length VisualModel::GetNumberOfLines( GlyphIndex glyphIndex,
175 Length numberOfGlyphs ) const
180 void VisualModel::GetLinesOfGlyphRange( LineRun* lines,
181 GlyphIndex glyphIndex,
182 Length numberOfGlyphs ) const
186 void VisualModel::SetNaturalSize( const Vector2& size )
188 mImpl->mNaturalSize = size;
191 const Vector2& VisualModel::GetNaturalSize() const
193 return mImpl->mNaturalSize;
196 void VisualModel::SetActualSize( const Vector2& size )
198 mImpl->mActualSize = size;
201 const Vector2& VisualModel::GetActualSize() const
203 return mImpl->mActualSize;
206 VisualModel::~VisualModel()
211 VisualModel::VisualModel()
214 mImpl = new VisualModel::Impl();
219 } // namespace Toolkit