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>
24 #include <dali/public-api/math/vector2.h>
35 struct VisualModel::Impl
37 Vector<GlyphInfo> mGlyphs;
38 Vector<CharacterIndex> mGlyphsToCharacters;
39 Vector<Length> mCharactersPerGlyph;
40 std::vector<Vector2> mGlyphPositions;
43 VisualModelPtr VisualModel::New()
45 return VisualModelPtr( new VisualModel() );
48 void VisualModel::SetGlyphs( const GlyphInfo* glyphs,
49 const CharacterIndex* characterIndices,
50 const Length* charactersPerGlyph,
51 Length numberOfGlyphs )
53 Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
54 modelGlyphs.Resize( numberOfGlyphs );
55 memcpy( &modelGlyphs[0], glyphs, numberOfGlyphs*sizeof(GlyphInfo) );
57 Vector<CharacterIndex>& glyphsToCharacters = mImpl->mGlyphsToCharacters;
58 glyphsToCharacters.Resize( numberOfGlyphs );
59 memcpy( &glyphsToCharacters[0], characterIndices, numberOfGlyphs*sizeof(CharacterIndex) );
61 Vector<Length>& modelCharactersPerGlyph = mImpl->mCharactersPerGlyph;
62 modelCharactersPerGlyph.Resize( numberOfGlyphs );
63 memcpy( &modelCharactersPerGlyph[0], charactersPerGlyph, numberOfGlyphs*sizeof(Length) );
66 Length VisualModel::GetNumberOfGlyphs() const
68 return mImpl->mGlyphs.Count();
71 void VisualModel::GetGlyphs( GlyphIndex glyphIndex,
73 Length numberOfGlyphs ) const
75 Vector<GlyphInfo>& modelGlyphs = mImpl->mGlyphs;
76 memcpy( glyphs, &modelGlyphs[glyphIndex], numberOfGlyphs*sizeof(GlyphInfo) );
79 CharacterIndex VisualModel::GetCharacterIndex( GlyphIndex glyphIndex ) const
81 return mImpl->mGlyphsToCharacters[glyphIndex];
84 Length VisualModel::GetCharactersPerGlyph( GlyphIndex glyphIndex ) const
86 return mImpl->mCharactersPerGlyph[glyphIndex];
89 GlyphIndex VisualModel::GetGlyphIndex( CharacterIndex characterIndex ) const
91 GlyphIndex index( 0 );
93 for( unsigned int i=0; i<mImpl->mGlyphsToCharacters.Count(); ++i )
95 if( mImpl->mGlyphsToCharacters[i] == characterIndex )
105 void VisualModel::SetGlyphPositions( const Vector2* glyphPositions,
106 Length numberOfGlyphs )
108 std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
109 modelPositions.resize( numberOfGlyphs );
110 memcpy( &modelPositions[0], glyphPositions, numberOfGlyphs*sizeof(Vector2) );
113 void VisualModel::GetGlyphPositions( GlyphIndex glyphIndex,
114 Vector2* glyphPositions,
115 Length numberOfGlyphs ) const
117 std::vector<Vector2>& modelPositions = mImpl->mGlyphPositions;
118 memcpy( glyphPositions, &modelPositions[0], numberOfGlyphs*sizeof(Vector2) );
121 VisualModel::~VisualModel()
126 VisualModel::VisualModel()
129 mImpl = new VisualModel::Impl();
134 } // namespace Toolkit