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>
38 struct VisualModel::Impl
40 Vector<GlyphInfo> mGlyphs;
41 Vector<CharacterIndex> mGlyphsToCharacters;
42 Vector<Length> mCharactersPerGlyph;
43 std::vector<Vector2> mGlyphPositions;
46 VisualModelPtr VisualModel::New()
48 return VisualModelPtr( new VisualModel() );
51 void VisualModel::SetGlyphs( const GlyphInfo* glyphs,
52 const CharacterIndex* characterIndices,
53 const Length* charactersPerGlyph,
54 Length numberOfGlyphs )
56 Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
57 modelGlyphs.Resize( numberOfGlyphs );
58 memcpy( &modelGlyphs[0], glyphs, numberOfGlyphs*sizeof(GlyphInfo) );
60 Vector<CharacterIndex>& glyphsToCharacters = mImpl->mGlyphsToCharacters;
61 glyphsToCharacters.Resize( numberOfGlyphs );
62 memcpy( &glyphsToCharacters[0], characterIndices, numberOfGlyphs*sizeof(CharacterIndex) );
64 Vector<Length>& modelCharactersPerGlyph = mImpl->mCharactersPerGlyph;
65 modelCharactersPerGlyph.Resize( numberOfGlyphs );
66 memcpy( &modelCharactersPerGlyph[0], charactersPerGlyph, numberOfGlyphs*sizeof(Length) );
69 Length VisualModel::GetNumberOfGlyphs() const
71 return mImpl->mGlyphs.Count();
74 void VisualModel::GetGlyphs( GlyphIndex glyphIndex,
76 Length numberOfGlyphs ) const
78 Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
79 memcpy( glyphs, &modelGlyphs[glyphIndex], numberOfGlyphs*sizeof(GlyphInfo) );
82 CharacterIndex VisualModel::GetCharacterIndex( GlyphIndex glyphIndex ) const
84 return mImpl->mGlyphsToCharacters[glyphIndex];
87 Length VisualModel::GetCharactersPerGlyph( GlyphIndex glyphIndex ) const
89 return mImpl->mCharactersPerGlyph[glyphIndex];
92 GlyphIndex VisualModel::GetGlyphIndex( CharacterIndex characterIndex ) const
94 GlyphIndex index( 0 );
96 for( unsigned int i=0; i<mImpl->mGlyphsToCharacters.Count(); ++i )
98 if( mImpl->mGlyphsToCharacters[i] == characterIndex )
108 void VisualModel::SetGlyphPositions( const Vector2* glyphPositions,
109 Length numberOfGlyphs )
111 std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
112 modelPositions.resize( numberOfGlyphs );
113 memcpy( &modelPositions[0], glyphPositions, numberOfGlyphs*sizeof(Vector2) );
116 void VisualModel::GetGlyphPositions( GlyphIndex glyphIndex,
117 Vector2* glyphPositions,
118 Length numberOfGlyphs ) const
120 std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
121 memcpy( glyphPositions, &modelPositions[0], numberOfGlyphs*sizeof(Vector2) );
124 VisualModel::~VisualModel()
129 VisualModel::VisualModel()
132 mImpl = new VisualModel::Impl();
137 } // namespace Toolkit