[dali_1.0.31] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / dali / internal / event / text / text-request-helper.h
1 #ifndef __DALI_INTERNAL_TEXT_REQUEST_HELPER_H__
2 #define __DALI_INTERNAL_TEXT_REQUEST_HELPER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/internal/event/text/font-declarations.h>
24 #include <dali/internal/event/text/text-format.h>
25 #include <dali/internal/common/text-vertex-buffer.h>
26 #include <dali/internal/event/text/resource/glyph-texture-observer.h>
27 #include <dali/integration-api/text-array.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 /**
36  * Used to control text requests passed to a font object.
37  * Characters are reference counted by the font object. This
38  * class ensures the correct characters are reference / unreferenced.
39  *
40  */
41 class TextRequestHelper
42 {
43
44 public:
45
46   /**
47    * constructor
48    * @param[in] observer glyph texture observer
49    */
50   TextRequestHelper( GlyphTextureObserver& observer );
51
52   /**
53    * destructor
54    */
55   ~TextRequestHelper();
56
57
58   /**
59    * Set the text to request
60    * @param [in] text text string
61    * @param [in] format text format
62    * @return the vertex data required to draw the text
63    */
64   TextVertexBuffer* SetText(const Integration::TextArray& text, const TextFormat& format );
65
66   /**
67    * Set the font
68    * @param [in] font
69    * @param [in] format text format
70    * @return the vertex data required to draw the text
71    */
72   TextVertexBuffer* SetFont( const FontPointer&  font, const TextFormat& format );
73
74   /**
75    * Set the text and font to request
76    * @param [in] text the text string
77    * @param [in] font new font to request from
78    * @param [in] format text format
79    * @return the vertex data required to draw the text
80    */
81   TextVertexBuffer* SetTextAndFont(const Integration::TextArray& text, const FontPointer& font, const TextFormat& format );
82
83   /**
84    * Called when the texture id has changed
85    * @param[in] old texture id
86    * @param[in] new texture id
87    */
88   void TextureChanged( unsigned int oldTextureId, unsigned int newTextureId );
89
90   /**
91    * Check if the text is loaded
92    * @return true if text is loaded
93    */
94   bool IsTextLoaded() const;
95
96 private:
97
98   /**
99    * Tell the font we have stopped using a string of characters
100    */
101   void TextNotRequired();
102
103   /**
104    * Tell the font we require some text
105    * @param[in] format the text format
106    * @return the vertex data required to draw the text
107    */
108   TextVertexBuffer* TextRequired(  const TextFormat& format  );
109
110   /**
111    * start observing global atlas changes such as atlas resize / split
112    */
113   void AddTextureObserver();
114
115   unsigned int mTextureId;                ///< the texture id of the glyph atlas being used
116   Integration::TextArray mText;           ///< text string
117   TextFormat mFormat;                     ///< text format
118   FontPointer mFont;                      ///< the font
119   bool mTextureObserverInstalled:1;       ///< whether texture observer is installed
120   GlyphTextureObserver& mTextureObserver; ///< texture observer
121
122 };
123
124 } // namespace Internal
125
126 } // namespace Dali
127
128 #endif // __DALI_INTERNAL_TEXT_REQUEST_HELPER_H__