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