Revert "[Tizen] Add DALi Autofill implementation"
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / text-abstraction / text-renderer.h
1 #ifndef DALI_TOOLKIT_TEXT_ABSTRACTION_TEXT_RENDERER_H
2 #define DALI_TOOLKIT_TEXT_ABSTRACTION_TEXT_RENDERER_H
3
4 /*
5  * Copyright (c) 2019 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/dali-vector.h>
23 #include <dali/public-api/object/base-handle.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/devel-api/text-abstraction/glyph-info.h>
27 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
28
29 namespace Dali
30 {
31
32 namespace TextAbstraction
33 {
34
35 namespace Internal
36 {
37
38   // Forward declaration
39   class TextRenderer;
40
41 } // namespace Internal
42
43 /**
44  * @brief Renders the given @e glyphs at the given @e positions into a pixel buffer.
45  *
46  * @note This class renders glyphs not characters.
47  *       Font selection, RTL reordering, shaping and layout
48  *       has to be done before calling the @e Render()
49  *       method of this class.
50  */
51 class DALI_ADAPTOR_API TextRenderer : public BaseHandle
52 {
53 public:
54   /**
55    * @brief Parameters to render the text.
56    */
57   struct Parameters
58   {
59     /**
60      * @brief Enum with the possible pixel formats of the output pixel buffer.
61      */
62     enum PixelFormat
63     {
64       A8,      ///< Alpha channel, 8-bit color depth.
65       RGBA8888 ///< Red, Green, Blue and Alpha channels, 8-bit color depth per channel.
66     };
67
68     /**
69      * @brief Whether the circular layout is clockwise.
70      */
71     enum CircularLayout
72     {
73       CLOCKWISE,        ///< The text is laid clockwise on a circular path.
74       COUNTER_CLOCKWISE ///< The text is laid counter clockwise on a circular path.
75     };
76
77     /**
78      * @brief Parameters for the text renderer function.
79      */
80     Parameters( Vector<GlyphInfo>& glyphs,
81                 Vector<Vector2>& positions,
82                 Vector<Vector4>& colors,
83                 Vector<ColorIndex>& colorIndices,
84                 Vector<ColorBlendingMode>& blendingMode,
85                 Vector<bool>& isEmoji )
86     : glyphs( glyphs ),
87       positions( positions ),
88       colors( colors ),
89       colorIndices( colorIndices ),
90       blendingMode( blendingMode ),
91       isEmoji( isEmoji ),
92       width{ 0u },
93       height{ 0u },
94       radius{ 0u },
95       circularWidth{ 0u },
96       circularHeight{ 0u },
97       centerX{ 0 },
98       centerY{ 0 },
99       beginAngle{ 0.f },
100       pixelFormat{ A8 },
101       circularLayout{ CLOCKWISE }
102     {}
103
104     Vector<GlyphInfo>& glyphs;               ///< The glyphs to be rendered.
105     Vector<Vector2>& positions;              ///< The position for each glyph.
106     Vector<Vector4>& colors;                 ///< Colors of the glyphs.
107     Vector<ColorIndex>& colorIndices;        ///< Indices to the vector of colors for each glyphs.
108     Vector<ColorBlendingMode>& blendingMode; ///< How each glyph is going to be blended with the color of the text.
109     Vector<bool>& isEmoji;                   ///< Whether each glyph is an emoji.
110     unsigned int width;                      ///< The width of the pixel buffer. @note Some implementations may change the width for performance reasons.
111     unsigned int height;                     ///< The height of the pixel buffer.
112     unsigned int radius;                     ///< The radius in pixels of the circular text.
113     unsigned int circularWidth;              ///< The width of the text laid out on an horizontal straight line.
114     unsigned int circularHeight;             ///< The height of the text laid out on an horizontal straight line.
115     int centerX;                             ///< The 'x' coordinate of the center. For circular layout.
116     int centerY;                             ///< The 'y' coordinate of the center. For circular layout.
117     float beginAngle;                        ///< The angle in radians where the circular text begins.
118     PixelFormat pixelFormat;                 ///< The pixel format of the pixel buffer.
119     CircularLayout circularLayout;           ///< The direction of the text's layout.
120   };
121
122 public:
123
124   /**
125    * @brief Create an uninitialized TextRenderer handle.
126    *
127    */
128   TextRenderer();
129
130   /**
131    * @brief Destructor
132    *
133    * This is non-virtual since derived Handle types must not contain data or virtual methods.
134    */
135   ~TextRenderer();
136
137   /**
138    * @brief Retrieve a handle to the TextRenderer instance.
139    *
140    * @return A handle to the TextRenderer.
141    */
142   static TextRenderer Get();
143
144   /**
145    * @brief Renders the given @e glyphs into a pixel buffer.
146    *
147    * @param[in] parameters Struct with the glyphs, positions and the size of the pixel buffer.
148    *
149    * @return The pixel buffer with the text rendered on it.
150    */
151   Devel::PixelBuffer Render(const Parameters& parameters);
152
153 public: // Not intended for application developers.
154
155   /// @cond internal
156   /**
157    * @brief This constructor is used by TextRenderer::Get().
158    *
159    * @param[in] implementation A pointer to the internal text renderer object.
160    */
161   explicit DALI_INTERNAL TextRenderer(Internal::TextRenderer* implementation);
162   /// @endcond
163 };
164
165 } // namespace TextAbstraction
166
167 } // namespace Dali
168
169 #endif // DALI_TOOLKIT_TEXT_ABSTRACTION_TEXT_RENDERER_H