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.
18 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h>
21 #include <dali/public-api/actors/image-actor.h>
22 #include <dali/public-api/common/stage.h>
33 //#define DISPLAY_ATLAS
35 AtlasGlyphManager::AtlasGlyphManager()
38 mAtlasManager = Dali::Toolkit::AtlasManager::New();
41 AtlasGlyphManager::~AtlasGlyphManager()
45 AtlasGlyphManagerPtr AtlasGlyphManager::New()
47 AtlasGlyphManagerPtr internal = new AtlasGlyphManager();
51 void AtlasGlyphManager::Add( const Text::GlyphInfo& glyph,
52 const BufferImage& bitmap,
53 Dali::Toolkit::AtlasManager::AtlasSlot& slot )
56 record.mFontId = glyph.fontId;
57 record.mIndex = glyph.index;
59 mAtlasManager.Add( bitmap, slot );
60 record.mImageId = slot.mImageId;
61 mGlyphRecords.PushBack( record );
65 uint32_t atlasCount = mAtlasManager.GetAtlasCount();
66 if ( atlasCount > mCount )
68 for ( uint32_t i = 0; i < atlasCount; ++i )
70 ImageActor actor = ImageActor::New( mAtlasManager.GetAtlasContainer( i + 1u ) );
71 actor.SetParentOrigin( Vector3( 0.5f, 0.25f + ( static_cast< float >( i ) * 0.25f ), 0.5f ) );
72 actor.SetAnchorPoint( AnchorPoint::CENTER );
73 actor.SetSize( 256.0f, 256.0f );
74 Stage::GetCurrent().Add( actor );
82 void AtlasGlyphManager::GenerateMeshData( uint32_t imageId,
83 const Vector2& position,
86 mAtlasManager.GenerateMeshData( imageId, position, meshData );
89 void AtlasGlyphManager::StitchMesh( MeshData& first,
90 const MeshData& second )
92 mAtlasManager.StitchMesh( first, second );
95 void AtlasGlyphManager::Cached( Text::FontId fontId,
97 Dali::Toolkit::AtlasManager::AtlasSlot& slot )
99 for ( uint32_t i = 0; i < mGlyphRecords.Size(); ++i )
101 if ( fontId == mGlyphRecords[ i ].mFontId && index == mGlyphRecords[ i ].mIndex )
103 slot.mImageId = mGlyphRecords[ i ].mImageId;
104 slot.mAtlasId = mAtlasManager.GetAtlas( slot.mImageId );
111 Vector2 AtlasGlyphManager::GetAtlasSize( uint32_t atlasId )
113 return mAtlasManager.GetAtlasSize( atlasId );
116 void AtlasGlyphManager::SetNewAtlasSize( const Vector2& size,
117 const Vector2& blockSize )
119 mAtlasManager.SetNewAtlasSize( size, blockSize );
122 void AtlasGlyphManager::Remove( uint32_t imageId )
124 if ( mAtlasManager.Remove( imageId ) )
126 for ( uint32_t i = 0; i < mGlyphRecords.Size(); ++i )
128 if ( mGlyphRecords[ i ].mImageId == imageId )
130 mGlyphRecords.Remove( mGlyphRecords.Begin() + i );
137 Pixel::Format AtlasGlyphManager::GetPixelFormat( uint32_t atlasId )
139 return mAtlasManager.GetPixelFormat( atlasId );
142 const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics()
144 mMetrics.mGlyphCount = mGlyphRecords.Size();
145 mAtlasManager.GetMetrics( mMetrics.mAtlasMetrics );
149 } // namespace Internal
151 } // namespace Toolkit