New TextUtilities interface.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / text / visual-model.h
1 #ifndef __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__
2 #define __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__
3
4 /*
5  * Copyright (c) 2015 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/common/intrusive-ptr.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali-toolkit/public-api/text/text-definitions.h>
25
26 namespace Dali
27 {
28
29 struct Vector2;
30
31 namespace Toolkit
32 {
33
34 namespace Text
35 {
36
37 class VisualModel;
38 typedef IntrusivePtr<VisualModel> VisualModelPtr;
39
40 /**
41  * @brief A visual text model contains layout specific information.
42  *
43  * This includes:
44  * - A series of glyphs in visual order i.e. after the bidirectional reordering.
45  * - The position of each glyph within a 2D bounding box.
46  */
47 class VisualModel : public RefObject
48 {
49 public:
50
51   /**
52    * @brief Create a new instance of a VisualModel.
53    *
54    * @return A pointer to a new VisualModel.
55    */
56   static VisualModelPtr New();
57
58   // Glyph interface.
59
60   /**
61    * @brief Replaces any glyphs previously set.
62    *
63    * @param[in] glyphs An array of glyphs in the visual order.
64    * @param[in] characterIndices An array containing the first character in the logical model that each glyph relates to.
65    * @param[in] charactersPerGlyph An array containing the number of characters per glyph.
66    * @param[in] numberOfGlyphs The number of glyphs.
67    */
68   void SetGlyphs( const GlyphInfo* glyphs,
69                   const CharacterIndex* characterIndices,
70                   const Length* charactersPerGlyph,
71                   Length numberOfGlyphs );
72
73   /**
74    * Retrieves the number of glyphs.
75    *
76    * @return The number of glyphs.
77    */
78   Length GetNumberOfGlyphs() const;
79
80   /**
81    * @brief Retrieves glyphs in the given buffer.
82    *
83    * The size of the @p glyphs buffer needs to be big enough to copy the @p numberOfGlyphs.
84    * @param[out] glyphs Pointer to a buffer where the glyphs are copied.
85    * @param[in] glyphIndex Index to the first glyph.
86    * @param[in] numberOfGlyphs Number of glyphs to be copied.
87    */
88   void GetGlyphs( GlyphIndex glyphIndex,
89                   GlyphInfo* glyphs,
90                   Length numberOfGlyphs ) const;
91
92   // Character <--> Glyph conversion
93
94   /**
95    * @brief Retrieves the first character in the logical model which a glyph represents.
96    *
97    * @note After shaping several characters may be represented by the same glyph.
98    * Alternatively several glyphs may be required to display a character.
99    * @param[in] glyphIndex The glyph index.
100    * @return The character index.
101    */
102   CharacterIndex GetCharacterIndex( GlyphIndex glyphIndex ) const;
103
104   /**
105    * @brief Query the number of characters the glyph represents.
106    *
107    * @param[in] glyphIndex The glyph index.
108    * @return The number of characters represented by the glyph.
109    */
110   Length GetCharactersPerGlyph( GlyphIndex glyphIndex ) const;
111
112   /**
113    * Retrieves the first glyph in the visual model which represents a given character.
114    *
115    * @note After shaping several characters may be represented by the same glyph.
116    * Alternatively several glyphs may be required to display a character.
117    * @param[in] characterIndex The character index.
118    * @return The glyph index.
119    */
120   GlyphIndex GetGlyphIndex( CharacterIndex characterIndex ) const;
121
122   // Position interface
123
124   /**
125    * @brief Replaces any glyph positions previously set.
126    *
127    * @param[in] glyphPositions An array of visual positions for each glyph.
128    * @param[in] numberOfGlyphs The number of positions.
129    */
130   void SetGlyphPositions( const Vector2* glyphPositions,
131                           Length numberOfGlyphs );
132
133   /**
134    * @brief Retrieves the glyph positions.
135    *
136    * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
137    * @param[in] glyphIndex Index to the first glyph position.
138    * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
139    * @param[in] numberOfGlyphs The number of positions to be copied.
140    */
141   void GetGlyphPositions( GlyphIndex glyphIndex,
142                           Vector2* glyphPositions,
143                           Length numberOfGlyphs ) const;
144
145 protected:
146
147   /**
148    * @brief A reference counted object may only be deleted by calling Unreference().
149    */
150   virtual ~VisualModel();
151
152 private:
153
154   /**
155    * @brief Private constructor.
156    */
157   VisualModel();
158
159   // Undefined
160   VisualModel( const VisualModel& handle );
161
162   // Undefined
163   VisualModel& operator=( const VisualModel& handle );
164
165 private:
166
167   struct Impl;
168   Impl* mImpl;
169 };
170 } // namespace Text
171
172 } // namespace Toolkit
173
174 } // namespace Dali
175
176 #endif // __DALI_TOOLKIT_TEXT_VISUAL_MODEL_H__