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/public-api/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/public-api/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;
49 VisualModelPtr VisualModel::New()
51 return VisualModelPtr( new VisualModel() );
54 void VisualModel::SetGlyphs( const GlyphInfo* glyphs,
55 const CharacterIndex* characterIndices,
56 const Length* charactersPerGlyph,
57 Length numberOfGlyphs )
59 Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
60 modelGlyphs.Resize( numberOfGlyphs );
61 memcpy( &modelGlyphs[0], glyphs, numberOfGlyphs*sizeof(GlyphInfo) );
63 Vector<CharacterIndex>& glyphsToCharacters = mImpl->mGlyphsToCharacters;
64 glyphsToCharacters.Resize( numberOfGlyphs );
65 memcpy( &glyphsToCharacters[0], characterIndices, numberOfGlyphs*sizeof(CharacterIndex) );
67 Vector<Length>& modelCharactersPerGlyph = mImpl->mCharactersPerGlyph;
68 modelCharactersPerGlyph.Resize( numberOfGlyphs );
69 memcpy( &modelCharactersPerGlyph[0], charactersPerGlyph, numberOfGlyphs*sizeof(Length) );
72 Length VisualModel::GetNumberOfGlyphs() const
74 return mImpl->mGlyphs.Count();
77 void VisualModel::GetGlyphs( GlyphIndex glyphIndex,
79 Length numberOfGlyphs ) const
81 Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
82 memcpy( glyphs, &modelGlyphs[glyphIndex], numberOfGlyphs*sizeof(GlyphInfo) );
85 const GlyphInfo& VisualModel::GetGlyphInfo( GlyphIndex glyphIndex ) const
90 CharacterIndex VisualModel::GetCharacterIndex( GlyphIndex glyphIndex ) const
92 return mImpl->mGlyphsToCharacters[glyphIndex];
95 Length VisualModel::GetCharactersPerGlyph( GlyphIndex glyphIndex ) const
97 return mImpl->mCharactersPerGlyph[glyphIndex];
100 GlyphIndex VisualModel::GetGlyphIndex( CharacterIndex characterIndex ) const
102 GlyphIndex index( 0 );
104 for( unsigned int i=0; i<mImpl->mGlyphsToCharacters.Count(); ++i )
106 if( mImpl->mGlyphsToCharacters[i] == characterIndex )
116 void VisualModel::GetCharacterToGlyphMap( GlyphIndex* characterToGlyphMap,
117 CharacterIndex characterIndex,
118 Length numberOfCharacters ) const
122 void VisualModel::GetCharactersPerGlyphMap( Length* charactersPerGlyph,
123 GlyphIndex glyphIndex,
124 Length numberOfGlyphs ) const
128 void VisualModel::GetGlyphToCharacterMap( CharacterIndex* glyphToCharacter,
129 GlyphIndex glyphIndex,
130 Length numberOfGlyphs ) const
134 void VisualModel::SetGlyphPositions( const Vector2* glyphPositions,
135 Length numberOfGlyphs )
137 std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
138 modelPositions.resize( numberOfGlyphs );
139 memcpy( &modelPositions[0], glyphPositions, numberOfGlyphs*sizeof(Vector2) );
142 void VisualModel::GetGlyphPositions( GlyphIndex glyphIndex,
143 Vector2* glyphPositions,
144 Length numberOfGlyphs ) const
146 std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
147 memcpy( glyphPositions, &modelPositions[0], numberOfGlyphs*sizeof(Vector2) );
150 const Vector2& VisualModel::GetGlyphPosition( GlyphIndex glyphIndex ) const
152 return Vector2::ZERO;
155 void VisualModel::SetLines( const LineRun* const lines,
156 Length numberOfLines )
160 Length VisualModel::GetNumberOfLines() const
165 void VisualModel::GetLines( LineRun* lines,
167 Length numberOfLines ) const
171 Length VisualModel::GetNumberOfLines( GlyphIndex glyphIndex,
172 Length numberOfGlyphs ) const
177 void VisualModel::GetLinesOfGlyphRange( LineRun* lines,
178 GlyphIndex glyphIndex,
179 Length numberOfGlyphs ) const
183 void VisualModel::SetNaturalSize( const Vector2& size )
187 const Vector2& VisualModel::GetNaturalSize() const
189 return Vector2::ZERO;
192 void VisualModel::SetActualSize( const Vector2& size )
196 const Vector2& VisualModel::GetActualSize() const
198 return Vector2::ZERO;
201 VisualModel::~VisualModel()
206 VisualModel::VisualModel()
209 mImpl = new VisualModel::Impl();
214 } // namespace Toolkit