Retrieve outline glyph from freetype
[platform/core/uifw/dali-adaptor.git] / text / dali / devel-api / text-abstraction / font-client.h
index a1ffcb5..8c8cfca 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__
-#define __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__
+#ifndef DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H
+#define DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -21,6 +21,7 @@
 // INTERNAL INCLUDES
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/images/buffer-image.h>
+#include <dali/public-api/images/pixel-data.h>
 #include <dali/public-api/object/base-handle.h>
 #include <dali/devel-api/text-abstraction/font-list.h>
 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
@@ -63,6 +64,29 @@ class DALI_IMPORT_API FontClient : public BaseHandle
 public:
   static const PointSize26Dot6 DEFAULT_POINT_SIZE; ///< The default point size.
 
+  /**
+   * @brief Struct used to retrieve the glyph's bitmap.
+   */
+  struct GlyphBufferData
+  {
+    /**
+     * @brief Constructor.
+     *
+     * Initializes struct members to their defaults.
+     */
+    GlyphBufferData();
+
+    /**
+     * @brief Destructor.
+     */
+    ~GlyphBufferData();
+
+    unsigned char* buffer; ///< The glyph's bitmap buffer data.
+    unsigned int   width;  ///< The width of the bitmap.
+    unsigned int   height; ///< The height of the bitmap.
+    Pixel::Format  format; ///< The pixel's format of the bitmap.
+  };
+
 public:
 
   /**
@@ -122,6 +146,15 @@ public:
   void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
 
   /**
+   * @brief Called by Dali to retrieve the default font size for the platform.
+   *
+   * This is an accessibility size, which is mapped to a UI Control specific point-size in stylesheets.
+   * For example if zero the smallest size, this could potentially map to TextLabel point-size 8.
+   * @return The default font size.
+   */
+  int GetDefaultFontSize();
+
+  /**
    * @brief Called when the user changes the system defaults.
    *
    * @post Previously cached system defaults are removed.
@@ -131,53 +164,65 @@ public:
   /**
    * @brief Retrieve the list of default fonts supported by the system.
    *
-   * @param[out] defaultFonts A list of default font paths, family & style strings.
+   * @param[out] defaultFonts A list of default font paths, family, width, weight and slant.
    */
   void GetDefaultFonts( FontList& defaultFonts );
 
   /**
-   * @brief Retrieve the active default font from the system
+   * @brief Retrieve the active default font from the system.
    *
-   * @param[out] fontDescription font structure describing the default font
+   * @param[out] fontDescription font structure describing the default font.
    */
   void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
 
   /**
    * @brief Retrieve the list of fonts supported by the system.
    *
-   * @param[out] systemFonts A list of font paths, family & style strings.
+   * @param[out] systemFonts A list of font paths, family, width, weight and slant.
    */
   void GetSystemFonts( FontList& systemFonts );
 
   /**
    * @brief Retrieves the font description of a given font @p id.
    *
-   * @param[in] id The font id.
-   * @param[out] fontDescription The path, family & style describing the font.
+   * @param[in] id The font identifier.
+   * @param[out] fontDescription The path, family & style (width, weight and slant) describing the font.
    */
   void GetDescription( FontId id, FontDescription& fontDescription );
 
   /**
    * @brief Retrieves the font point size of a given font @p id.
    *
-   * @param[in] id The font id.
+   * @param[in] id The font identifier.
    *
    * @return The point size in 26.6 fractional points.
    */
   PointSize26Dot6 GetPointSize( FontId id );
 
   /**
+   * @brief Whether the given @p character is supported by the font.
+   *
+   * @param[in] fontId The id of the font.
+   * @param[in] character The character.
+   *
+   * @return @e true if the character is supported by the font.
+   */
+  bool IsCharacterSupportedByFont( FontId fontId, Character character );
+
+  /**
    * @brief Find the default font for displaying a UTF-32 character.
    *
    * This is useful when localised strings are provided for multiple languages
    * i.e. when a single default font does not work for all languages.
+   *
    * @param[in] charcode The character for which a font is needed.
-   * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
-   * @param[in] preferColor True if a color font is preferred.
-   * @return A valid font ID, or zero if the font does not exist.
+   * @param[in] requestedPointSize The point size in 26.6 fractional points; the default point size is 12*64.
+   * @param[in] preferColor @e true if a color font is preferred.
+   *
+   * @return A valid font identifier, or zero if the font does not exist.
    */
   FontId FindDefaultFont( Character charcode,
-                          PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
+                          PointSize26Dot6 requestedPointSize = DEFAULT_POINT_SIZE,
                           bool preferColor = false );
 
   /**
@@ -185,42 +230,45 @@ public:
    *
    * This is useful when localised strings are provided for multiple languages
    * i.e. when a single default font does not work for all languages.
-   * @param[in] preferredFont The preferred font which may not provide a glyph for charcode.
-   * The fallback-font will be the closest match to preferredFont, which does support the required glyph.
+   *
    * @param[in] charcode The character for which a font is needed.
-   * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
-   * @param[in] preferColor True if a color font is preferred.
-   * @return A valid font ID, or zero if the font does not exist.
+   * @param[in] preferredFontDescription Description of the preferred font which may not provide a glyph for @p charcode.
+   *                                     The fallback-font will be the closest match to @p preferredFontDescription, which does support the required glyph.
+   * @param[in] requestedPointSize The point size in 26.6 fractional points; the default point size is 12*64.
+   * @param[in] preferColor @e true if a color font is preferred.
+   *
+   * @return A valid font identifier, or zero if the font does not exist.
    */
-  FontId FindFallbackFont( FontId preferredFont,
-                           Character charcode,
-                           PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
+  FontId FindFallbackFont( Character charcode,
+                           const FontDescription& preferredFontDescription,
+                           PointSize26Dot6 requestedPointSize = DEFAULT_POINT_SIZE,
                            bool preferColor = false );
 
   /**
    * @brief Retrieve the unique identifier for a font.
    *
    * @param[in] path The path to a font file.
-   * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
+   * @param[in] requestedPointSize The point size in 26.6 fractional points; the default point size is 12*64.
    * @param[in] faceIndex The index of the font face (optional).
-   * @return A valid font ID, or zero if the font does not exist.
+   *
+   * @return A valid font identifier, or zero if the font does not exist.
    */
   FontId GetFontId( const FontPath& path,
-                    PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
+                    PointSize26Dot6 requestedPointSize = DEFAULT_POINT_SIZE,
                     FaceIndex faceIndex = 0 );
 
   /**
-   * @brief Retrieve the unique identifier for a font.
+   * @brief Retrieves a unique font identifier for a given description.
    *
-   * @note It the font style is not empty, it will be used instead the font weight and font slant slant.
-   *
-   * @param[in] fontDescription A font description.
-   * @param[in] pointSize The point size in 26.6 fractional points; the default point size is 12*64.
+   * @param[in] preferredFontDescription Description of the preferred font.
+   *                                     The font will be the closest match to @p preferredFontDescription.
+   * @param[in] requestedPointSize The point size in 26.6 fractional points; the default point size is 12*64.
    * @param[in] faceIndex The index of the font face (optional).
-   * @return A valid font ID, or zero if the font does not exist.
+   *
+   * @return A valid font identifier, or zero if no font is found.
    */
-  FontId GetFontId( const FontDescription& fontDescription,
-                    PointSize26Dot6 pointSize = DEFAULT_POINT_SIZE,
+  FontId GetFontId( const FontDescription& preferredFontDescription,
+                    PointSize26Dot6 requestedPointSize = DEFAULT_POINT_SIZE,
                     FaceIndex faceIndex = 0 );
 
   /**
@@ -268,17 +316,17 @@ public:
   /**
    * @brief Query the metrics for a font.
    *
-   * @param[in] fontId The ID of the font for the required glyph.
+   * @param[in] fontId The identifier of the font for the required glyph.
    * @param[out] metrics The font metrics.
-   * @param[in] desiredFixedSize The metrics for fixed-size fonts will be scaled to this desired size (in pixels).
    */
-  void GetFontMetrics( FontId fontId, FontMetrics& metrics, int desiredFixedSize = 0 );
+  void GetFontMetrics( FontId fontId, FontMetrics& metrics );
 
   /**
    * @brief Retrieve the glyph index for a UTF-32 character code.
    *
-   * @param[in] fontId The ID of the font for the required glyph.
+   * @param[in] fontId The identifier of the font for the required glyph.
    * @param[in] charcode The UTF-32 character code.
+   *
    * @return The glyph index, or zero if the character code is undefined.
    */
   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
@@ -287,32 +335,75 @@ public:
    * @brief Retrieve the metrics for a series of glyphs.
    *
    * @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values.
-   * It may contain the advance and an offset set into the bearing from the shaping tool.
-   * On return, the glyph's size value will be initialized. The bearing value will be updated by adding the font's glyph bearing to the one set by the shaping tool.
+   *                      It may contain the advance and an offset set into the bearing from the shaping tool.
+   *                      On return, the glyph's size value will be initialized. The bearing value will be updated by adding the font's glyph bearing to the one set by the shaping tool.
    * @param[in] size The size of the array.
+   * @param[in] type The type of glyphs used for rendering; either bitmaps or vectors.
    * @param[in] horizontal True for horizontal layouts (set to false for vertical layouting).
-   * @param[in] desiredFixedSize The metrics for fixed-size fonts will be scaled to this desired size (in pixels).
-   * @return True if all of the requested metrics were found.
+   *
+   * @return @e true if all of the requested metrics were found.
+   */
+  bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal = true );
+
+  /**
+   * @brief Create a bitmap representation of a glyph.
+   *
+   * @note The caller is responsible for deallocating the bitmap data @p data.buffer using delete[].
+   *
+   * @param[in] fontId The identifier of the font.
+   * @param[in] glyphIndex The index of a glyph within the specified font.
+   * @param[out] data The bitmap data.
+   * @param[in] outlineWidth The width of the glyph outline in pixels.
    */
-  bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal = true, int desiredFixedSize = 0 );
+  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, GlyphBufferData& data, int outlineWidth );
 
   /**
-   * @brief Render a bitmap representation of a glyph.
+   * @brief Create a bitmap representation of a glyph.
    *
-   * @param[in] fontId The ID of the font.
+   * @param[in] fontId The identifier of the font.
    * @param[in] glyphIndex The index of a glyph within the specified font.
+   * @param[in] outlineWidth The width of the glyph outline in pixels.
+   *
    * @return A valid BufferImage, or an empty handle if the glyph could not be rendered.
    */
-  BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
+  PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth );
+
+  /**
+   * @brief Create a vector representation of a glyph.
+   *
+   * @note This feature requires highp shader support and is not available on all platforms
+   * @param[in] fontId The identifier of the font.
+   * @param[in] glyphIndex The index of a glyph within the specified font.
+   * @param[out] blob A blob of data; this is owned by FontClient and should be copied by the caller of CreateVectorData().
+   * @param[out] blobLength The length of the blob data, or zero if the blob creation failed.
+   * @param[out] nominalWidth The width of the blob.
+   * @param[out] nominalHeight The height of the blob.
+   */
+  void CreateVectorBlob( FontId fontId,
+                         GlyphIndex glyphIndex,
+                         VectorBlob*& blob,
+                         unsigned int& blobLength,
+                         unsigned int& nominalWidth,
+                         unsigned int& nominalHeight );
 
   /**
    * @brief Retrieves the ellipsis glyph for a requested point size.
    *
-   * @param[in] pointSize The requested point size.
+   * @param[in] requestedPointSize The requested point size.
    *
    * @return The ellipsis glyph.
    */
-  const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize );
+  const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 requestedPointSize );
+
+  /**
+   * @brief Whether the given glyph @p glyphIndex is a color glyph.
+   *
+   * @param[in] fontId The font id.
+   * @param[in] glyphIndex The glyph index.
+   *
+   * @return @e true if the glyph is a color one.
+   */
+  bool IsColorGlyph( FontId fontId, GlyphIndex glyphIndex );
 
 public: // Not intended for application developers
   /**
@@ -327,4 +418,4 @@ public: // Not intended for application developers
 
 } // namespace Dali
 
-#endif // __DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H__
+#endif // DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H