Copyless glyph bitmap creation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / text-typesetter.h
index 285348e..3a71c31 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_TEXT_TYPESETTER_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // EXTERNAL INCLUDES
+#include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
+#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
 #include <dali/public-api/common/intrusive-ptr.h>
-#include <dali/public-api/object/ref-object.h>
-#include <dali/public-api/images/pixel.h>
 #include <dali/public-api/images/pixel-data.h>
-#include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
-#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/public-api/images/pixel.h>
+#include <dali/public-api/object/ref-object.h>
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Text
 {
-
 class ModelInterface;
 class ViewModel;
 class Typesetter;
@@ -47,16 +45,16 @@ typedef IntrusivePtr<Typesetter> TypesetterPtr;
 class Typesetter : public RefObject
 {
 public:
-
   /**
    * @brief Behaviours of how to render the text.
    */
   enum RenderBehaviour
   {
-    RENDER_TEXT_AND_STYLES,  ///< Render both the text and its styles
-    RENDER_NO_TEXT,          ///< Do not render the text itself
-    RENDER_NO_STYLES,        ///< Do not render any styles
-    RENDER_MASK              ///< Render an alpha mask (for color glyphs with no color animation, e.g. emoji)
+    RENDER_TEXT_AND_STYLES, ///< Render both the text and its styles
+    RENDER_NO_TEXT,         ///< Do not render the text itself but render the background styles such as outline and background.
+    RENDER_NO_STYLES,       ///< Do not render any styles
+    RENDER_MASK,            ///< Render an alpha mask (for color glyphs with no color animation, e.g. emoji)
+    RENDER_OVERLAY_STYLE    ///< Do not render the text itself but render the style but overlay the style on the text (foreground styles such as strikethrough and underline)
   };
 
   /**
@@ -64,13 +62,14 @@ public:
    */
   enum Style
   {
-    STYLE_NONE,              ///< No style
-    STYLE_MASK,              ///< Alpha mask
-    STYLE_SHADOW,            ///< Hard shadow
-    STYLE_SOFT_SHADOW,       ///< Soft shadow
-    STYLE_UNDERLINE,         ///< Underline
-    STYLE_OUTLINE,           ///< Outline
-    STYLE_BACKGROUND         ///< Text background
+    STYLE_NONE,         ///< No style
+    STYLE_MASK,         ///< Alpha mask
+    STYLE_SHADOW,       ///< Hard shadow
+    STYLE_SOFT_SHADOW,  ///< Soft shadow
+    STYLE_UNDERLINE,    ///< Underline
+    STYLE_OUTLINE,      ///< Outline
+    STYLE_BACKGROUND,   ///< Text background
+    STYLE_STRIKETHROUGH ///< Strikethrough
   };
 
 public: // Constructor.
@@ -82,7 +81,7 @@ public: // Constructor.
    *
    * @param[in] model Pointer to the text's data model.
    */
-  static TypesetterPtr New( const ModelInterface* const model );
+  static TypesetterPtr New(const ModelInterface* const model);
 
 public:
   /**
@@ -102,13 +101,14 @@ public:
    * - Combines different image buffers to create the pixel data used to generate the final image
    *
    * @param[in] size The renderer size.
+   * @param[in] textDirection The direction of the text.
    * @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).
    * @param[in] ignoreHorizontalAlignment Whether to ignore the horizontal alignment (i.e. always render as if HORIZONTAL_ALIGN_BEGIN).
    * @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).
    *
    * @return A pixel data with the text rendered.
    */
-  PixelData Render( const Vector2& size, RenderBehaviour behaviour = RENDER_TEXT_AND_STYLES, bool ignoreHorizontalAlignment = false, Pixel::Format pixelFormat = Pixel::RGBA8888 );
+  PixelData Render(const Vector2& size, Toolkit::DevelText::TextDirection::Type textDirection, RenderBehaviour behaviour = RENDER_TEXT_AND_STYLES, bool ignoreHorizontalAlignment = false, Pixel::Format pixelFormat = Pixel::RGBA8888);
 
 private:
   /**
@@ -116,16 +116,16 @@ private:
    *
    * @param[in] model Pointer to the text's data model.
    */
-  Typesetter( const ModelInterface* const model );
+  Typesetter(const ModelInterface* const model);
 
   // Declared private and left undefined to avoid copies.
-  Typesetter( const Typesetter& handle );
+  Typesetter(const Typesetter& handle);
 
   // Declared private and left undefined to avoid copies.
-  Typesetter& operator=( const Typesetter& handle );
+  Typesetter& operator=(const Typesetter& handle);
 
   /**
-   * @brief Create the image buffer for the given range of the glyphs in the given style.
+   * @brief Create & draw the image buffer for the given range of the glyphs in the given style.
    *
    * Does the following operations:
    * - Retrieves the data buffers from the text model.
@@ -137,35 +137,73 @@ private:
    * @param[in] style The style of the text.
    * @param[in] ignoreHorizontalAlignment Whether to ignore the horizontal alignment, not ignored by default.
    * @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).
+   * @param[in] horizontalOffset The horizontal offset to be added to the glyph's position.
    * @param[in] verticalOffset The vertical offset to be added to the glyph's position.
    * @param[in] fromGlyphIndex The index of the first glyph within the text to be drawn
    * @param[in] toGlyphIndex The index of the last glyph within the text to be drawn
    *
    * @return An image buffer with the text.
    */
-  Devel::PixelBuffer CreateImageBuffer( const unsigned int bufferWidth, const unsigned int bufferHeight, Typesetter::Style style, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int verticalOffset, TextAbstraction::GlyphIndex fromGlyphIndex, TextAbstraction::GlyphIndex toGlyphIndex );
+  Devel::PixelBuffer CreateImageBuffer(const uint32_t bufferWidth, const uint32_t bufferHeight, const Typesetter::Style style, const bool ignoreHorizontalAlignment, const Pixel::Format pixelFormat, const int32_t horizontalOffset, const int32_t verticalOffset, const TextAbstraction::GlyphIndex fromGlyphIndex, const TextAbstraction::GlyphIndex toGlyphIndex);
 
   /**
-   * @brief Combine the two RGBA image buffers together.
+   * @brief Apply behaviour of tags if the markup-processor is enabled.
    *
-   * The top layer buffer will blend over the bottom layer buffer:
-   * - If the pixel is not fully opaque from either buffer, it will be blended with
-   *   the pixel from the other buffer and copied to the combined buffer.
-   * - If the pixels from both buffers are fully opaque, the pixels from the top layer
-   *   buffer will be copied to the combined buffer.
+   * @param[in] topPixelBuffer The top layer buffer.
+   * @param[in] bufferWidth The width of the image buffer.
+   * @param[in] bufferHeight The height of the image buffer.
+   * @param[in] ignoreHorizontalAlignment Whether to ignore the horizontal alignment, not ignored by default.
+   * @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).
+   * @param[in] horizontalOffset The horizontal offset to be added to the glyph's position.
+   * @param[in] verticalOffset The vertical offset to be added to the glyph's position.
+   *
+   * @return The image buffer with the markup.
+   */
+  Devel::PixelBuffer ApplyMarkupProcessorOnPixelBuffer(Devel::PixelBuffer topPixelBuffer, const uint32_t bufferWidth, const uint32_t bufferHeight, const bool ignoreHorizontalAlignment, const Pixel::Format pixelFormat, const int32_t horizontalOffset, const int32_t verticalOffset);
+
+  /**
+   * @brief Apply markup underline tags.
+   *
+   * The properties on TextLabel override the behavior of Markup.
+   * Because the markup will be the bottom layer buffer
+   *  - i.e: If you set property UNDERLINE to enabled and blue.
+   *    And the TEXT is "<color value='green'>Hello</color> <u>World</u> <i>Hello</i> <b>World</b>".
+   *    Then the output of the whole text is underlined by blue line.
    *
    * @param[in] topPixelBuffer The top layer buffer.
-   * @param[in] bottomPixelBuffer The bottom layer buffer.
    * @param[in] bufferWidth The width of the image buffer.
    * @param[in] bufferHeight The height of the image buffer.
+   * @param[in] ignoreHorizontalAlignment Whether to ignore the horizontal alignment, not ignored by default.
+   * @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).
+   * @param[in] horizontalOffset The horizontal offset to be added to the glyph's position.
+   * @param[in] verticalOffset The vertical offset to be added to the glyph's position.
+   *
+   * @return The image buffer with the markup.
+   */
+  Devel::PixelBuffer ApplyUnderlineMarkupImageBuffer(Devel::PixelBuffer topPixelBuffer, const uint32_t bufferWidth, const uint32_t bufferHeight, const bool ignoreHorizontalAlignment, const Pixel::Format pixelFormat, const int32_t horizontalOffset, const int32_t verticalOffset);
+
+  /**
+   * @brief Apply markup strikethrough tags.
    *
-   * @return The combined image buffer with the text.
+   * The properties on TextLabel override the behavior of Markup.
+   * Because the markup will be the bottom layer buffer
+   *  - i.e: If you set property STRIKETHROUGH to enabled and blue.
+   *    And the TEXT is "<color value='green'>Hello</color> <s>World</s> <i>Hello</i> <b>World</b>".
+   *    Then the whole text will have a blue line strikethrough.
    *
+   * @param[in] topPixelBuffer The top layer buffer.
+   * @param[in] bufferWidth The width of the image buffer.
+   * @param[in] bufferHeight The height of the image buffer.
+   * @param[in] ignoreHorizontalAlignment Whether to ignore the horizontal alignment, not ignored by default.
+   * @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).
+   * @param[in] horizontalOffset The horizontal offset to be added to the glyph's position.
+   * @param[in] verticalOffset The vertical offset to be added to the glyph's position.
+   *
+   * @return The image buffer with the markup.
    */
-  Devel::PixelBuffer CombineImageBuffer( Devel::PixelBuffer topPixelBuffer, Devel::PixelBuffer bottomPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeightbool );
+  Devel::PixelBuffer ApplyStrikethroughMarkupImageBuffer(Devel::PixelBuffer topPixelBuffer, const uint32_t bufferWidth, const uint32_t bufferHeight, const bool ignoreHorizontalAlignment, const Pixel::Format pixelFormat, const int32_t horizontalOffset, const int32_t verticalOffset);
 
 protected:
-
   /**
    * @brief A reference counted object may only be deleted by calling Unreference().
    *
@@ -174,8 +212,7 @@ protected:
   virtual ~Typesetter();
 
 private:
-
-   ViewModel* mModel;
+  ViewModel* mModel;
 };
 
 } // namespace Text
@@ -184,4 +221,4 @@ private:
 
 } // namespace Dali
 
-#endif // DALI_TOOLKIT_TEXT_TYPESETTER_H
+#endif // DALI_TOOLKIT_TEXT_TYPESETTER_H
\ No newline at end of file