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