1 #ifndef DALI_TOOLKIT_TEXT_TYPESETTER_H
2 #define DALI_TOOLKIT_TEXT_TYPESETTER_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
23 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
24 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
25 #include <dali/public-api/common/intrusive-ptr.h>
26 #include <dali/public-api/images/pixel-data.h>
27 #include <dali/public-api/images/pixel.h>
28 #include <dali/public-api/object/ref-object.h>
40 typedef IntrusivePtr<Typesetter> TypesetterPtr;
43 * @brief This class is responsible of controlling the data flow of the text's rendering process.
45 class Typesetter : public RefObject
49 * @brief Behaviours of how to render the text.
53 RENDER_TEXT_AND_STYLES, ///< Render both the text and its styles
54 RENDER_NO_TEXT, ///< Do not render the text itself
55 RENDER_NO_STYLES, ///< Do not render any styles
56 RENDER_MASK ///< Render an alpha mask (for color glyphs with no color animation, e.g. emoji)
60 * @brief Styles of the text.
64 STYLE_NONE, ///< No style
65 STYLE_MASK, ///< Alpha mask
66 STYLE_SHADOW, ///< Hard shadow
67 STYLE_SOFT_SHADOW, ///< Soft shadow
68 STYLE_UNDERLINE, ///< Underline
69 STYLE_OUTLINE, ///< Outline
70 STYLE_BACKGROUND ///< Text background
73 public: // Constructor.
75 * @brief Creates a Typesetter instance.
77 * The typesetter composes the final text retrieving the glyphs and the
78 * styles from the text's model.
80 * @param[in] model Pointer to the text's data model.
82 static TypesetterPtr New(const ModelInterface* const model);
86 * @brief Retrieves the pointer to the view model.
88 * @return A pointer to the view model.
90 ViewModel* GetViewModel();
93 * @brief Renders the text.
95 * Does the following operations:
96 * - Finds the visible pages needed to be rendered.
97 * - Elide glyphs if needed.
98 * - Creates image buffers for diffrent text styles with the given size.
99 * - Combines different image buffers to create the pixel data used to generate the final image
101 * @param[in] size The renderer size.
102 * @param[in] textDirection The direction of the text.
103 * @param[in] behaviour The behaviour of how to render the text (i.e. whether to render the text only or the styles only or both).
104 * @param[in] ignoreHorizontalAlignment Whether to ignore the horizontal alignment (i.e. always render as if HORIZONTAL_ALIGN_BEGIN).
105 * @param[in] pixelFormat The format of the pixel in the image that the text is rendered as (i.e. either Pixel::BGRA8888 or Pixel::L8).
107 * @return A pixel data with the text rendered.
109 PixelData Render(const Vector2& size, Toolkit::DevelText::TextDirection::Type textDirection, RenderBehaviour behaviour = RENDER_TEXT_AND_STYLES, bool ignoreHorizontalAlignment = false, Pixel::Format pixelFormat = Pixel::RGBA8888);
113 * @brief Private constructor.
115 * @param[in] model Pointer to the text's data model.
117 Typesetter(const ModelInterface* const model);
119 // Declared private and left undefined to avoid copies.
120 Typesetter(const Typesetter& handle);
122 // Declared private and left undefined to avoid copies.
123 Typesetter& operator=(const Typesetter& handle);
126 * @brief Create the image buffer for the given range of the glyphs in the given style.
128 * Does the following operations:
129 * - Retrieves the data buffers from the text model.
130 * - Creates the pixel data used to generate the final image with the given size.
131 * - Traverse the visible glyphs, retrieve their bitmaps and compose the final pixel data.
133 * @param[in] bufferWidth The width of the image buffer.
134 * @param[in] bufferHeight The height of the image buffer.
135 * @param[in] style The style of the text.
136 * @param[in] ignoreHorizontalAlignment Whether to ignore the horizontal alignment, not ignored by default.
137 * @param[in] pixelFormat The format of the pixel in the image that the text is rendered as (i.e. either Pixel::BGRA8888 or Pixel::L8).
138 * @param[in] horizontalOffset The horizontal offset to be added to the glyph's position.
139 * @param[in] verticalOffset The vertical offset to be added to the glyph's position.
140 * @param[in] fromGlyphIndex The index of the first glyph within the text to be drawn
141 * @param[in] toGlyphIndex The index of the last glyph within the text to be drawn
143 * @return An image buffer with the text.
145 Devel::PixelBuffer CreateImageBuffer(const unsigned int bufferWidth, const unsigned int bufferHeight, Typesetter::Style style, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset, TextAbstraction::GlyphIndex fromGlyphIndex, TextAbstraction::GlyphIndex toGlyphIndex);
148 * @brief Combine the two RGBA image buffers together.
150 * The top layer buffer will blend over the bottom layer buffer:
151 * - If the pixel is not fully opaque from either buffer, it will be blended with
152 * the pixel from the other buffer and copied to the combined buffer.
153 * - If the pixels from both buffers are fully opaque, the pixels from the top layer
154 * buffer will be copied to the combined buffer.
156 * @param[in] topPixelBuffer The top layer buffer.
157 * @param[in] bottomPixelBuffer The bottom layer buffer.
158 * @param[in] bufferWidth The width of the image buffer.
159 * @param[in] bufferHeight The height of the image buffer.
161 * @return The combined image buffer with the text.
164 Devel::PixelBuffer CombineImageBuffer(Devel::PixelBuffer topPixelBuffer, Devel::PixelBuffer bottomPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeightbool);
167 * @brief Apply behaviour of tags if the markup-processor is enabled.
169 * The properties on TextLabel override the behavior of Markup.
170 * Because the markup will be the bottom layer buffer
171 * - i.e: If you set property UNDERLINE to enabled and blue.
172 * And the TEXT is "<color value='green'>Hello</color> <u>World</u> <i>Hello</i> <b>World</b>".
173 * Then the output of the whole text is underlined by blue line.
175 * @param[in] topPixelBuffer The top layer buffer.
176 * @param[in] bufferWidth The width of the image buffer.
177 * @param[in] bufferHeight The height of the image buffer.
178 * @param[in] ignoreHorizontalAlignment Whether to ignore the horizontal alignment, not ignored by default.
179 * @param[in] pixelFormat The format of the pixel in the image that the text is rendered as (i.e. either Pixel::BGRA8888 or Pixel::L8).
180 * @param[in] horizontalOffset The horizontal offset to be added to the glyph's position.
181 * @param[in] verticalOffset The vertical offset to be added to the glyph's position.
183 * @return The image buffer with the markup.
185 Devel::PixelBuffer ApplyMarkupProcessorOnPixelBuffer(Devel::PixelBuffer topPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeight, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset);
189 * @brief A reference counted object may only be deleted by calling Unreference().
191 * Destroys the visual model.
193 virtual ~Typesetter();
201 } // namespace Toolkit
205 #endif // DALI_TOOLKIT_TEXT_TYPESETTER_H