2 * Copyright (c) 2014 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 "text-request-helper.h"
22 #include <dali/internal/event/text/font-impl.h>
30 TextRequestHelper::TextRequestHelper( GlyphTextureObserver& observer)
32 mTextureObserverInstalled( false ),
33 mTextureObserver( observer )
37 TextRequestHelper::~TextRequestHelper()
41 if( mTextureObserverInstalled && mFont )
43 mFont->RemoveTextureObserver( mTextureObserver);
47 TextVertexBuffer* TextRequestHelper::SetText(const Integration::TextArray& text, const TextFormat& format)
49 // current text no longer required.
54 return TextRequired( format );
57 TextVertexBuffer* TextRequestHelper::SetFont( const FontPointer& font, const TextFormat& format )
59 // current text no longer required.
64 // request text with new font
65 return TextRequired( format );
68 TextVertexBuffer* TextRequestHelper::SetTextAndFont( const Integration::TextArray& text,
69 const FontPointer& font,
70 const TextFormat& format )
72 // current text no longer required.
79 // request new text with new font
80 return TextRequired( format );
83 void TextRequestHelper::TextNotRequired()
85 if( mFont && ( 0u < mText.Count() ) )
87 mFont->TextNotRequired( mText, mFormat, mTextureId );
91 TextVertexBuffer* TextRequestHelper::TextRequired( const TextFormat& format )
95 if( mFont && ( 0u < mText.Count() ) )
97 // watch out for texture resizes / splits
100 // get the vertex buffer required to display the text
101 TextVertexBuffer* buffer = mFont->TextRequired( mText, format );
104 // keep track of the texture id, ( texture id == atlas id)
105 mTextureId = buffer->mTextureId;
110 else if( 0u == mText.Count() )
112 // create an empty vertex buffer
113 TextVertexBuffer* buffer = new TextVertexBuffer;
114 buffer->mVertexMax = Vector2::ZERO;
115 buffer->mTextureId = 0;
122 void TextRequestHelper::TextureChanged( unsigned int oldTextureId, unsigned int newTextureId )
124 DALI_ASSERT_DEBUG( oldTextureId == mTextureId);
125 mTextureId = newTextureId;
128 bool TextRequestHelper::IsTextLoaded() const
130 if( mTextureId == 0 || (!mFont) || ( 0u == mText.Count() ) )
134 return mFont->IsTextLoaded( mText, mFormat, mTextureId );
137 void TextRequestHelper::AddTextureObserver()
139 if( !mTextureObserverInstalled )
141 mTextureObserverInstalled = true;
142 mFont->AddTextureObserver( mTextureObserver);
146 } // namespace Internal