#define DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H
/*
- * Copyright (c) 2021 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.
*/
~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.
- int outlineOffsetX; ///< The additional horizontal offset to be added for the glyph's position for outline.
- int outlineOffsetY; ///< The additional vertical offset to be added for the glyph's position for outline.
- Pixel::Format format; ///< The pixel's format of the bitmap.
- bool isColorEmoji : 1; ///< Whether the glyph is an emoji.
- bool isColorBitmap : 1; ///< Whether the glyph is a color bitmap.
+ /**
+ * @brief Move constructor.
+ *
+ * @param[in] rhs moved data.
+ */
+ GlyphBufferData(GlyphBufferData&& rhs) noexcept;
+
+ /**
+ * @brief Move assign operator.
+ *
+ * @param[in] rhs moved data.
+ * @return A reference to this.
+ */
+ GlyphBufferData& operator=(GlyphBufferData&& rhs) noexcept;
+
+ // Compression method of buffer. Each buffer compressed line by line
+ enum class CompressionType
+ {
+ NO_COMPRESSION = 0, // No compression
+ BPP_4 = 1, // Compress as 4 bit. Color become value * 17 (0x00, 0x11, 0x22, ... 0xee, 0xff).
+ // Only works for Pixel::L8 format
+ RLE_4 = 2, // Compress as 4 bit, and Run-Length-Encode. For more high compress rate, we store difference between previous scanline.
+ // Only works for Pixel::L8 format
+ };
+
+ /**
+ * @brief Helper static function to compress raw buffer from inBuffer to outBufferData.buffer.
+ * outBufferData will have it's own buffer.
+ *
+ * @pre outBufferData must not have it's own buffer.
+ * @param[in] inBuffer The input raw data.
+ * @param[in, out] outBufferData The output glyph buffer data.
+ * @return Size of compressed out buffer, Or 0 if compress failed.
+ */
+ static size_t Compress(const uint8_t* const inBuffer, GlyphBufferData& outBufferData);
+
+ /**
+ * @brief Helper static function to decompress raw buffer from inBuffer to outBufferPtr.
+ * If outBuffer is nullptr, Do nothing.
+ *
+ * @pre outBuffer memory should be allocated.
+ * @param[in] inBufferData The input glyph buffer data.
+ * @param[in, out] outBuffer The output pointer of raw buffer data.
+ */
+ static void Decompress(const GlyphBufferData& inBufferData, uint8_t* outBuffer);
+
+ /**
+ * @brief Special Helper static function to decompress raw buffer from inBuffer to outBuffer one scanline.
+ * After decompress one scanline successed, offset will be changed.
+ *
+ * @pre outBuffer memory should be allocated.
+ * @pre if inBufferData's compression type is RLE4, outBuffer memory should store the previous scanline data.
+ * @param[in] inBufferData The input glyph buffer data.
+ * @param[in, out] outBuffer The output pointer of raw buffer data.
+ * @param[in, out] offset The offset of input. It will be changed as next scanline's offset.
+ */
+ static void DecompressScanline(const GlyphBufferData& inBufferData, uint8_t* outBuffer, uint32_t& offset);
+
+ private:
+ // Delete copy operation.
+ GlyphBufferData(const GlyphBufferData& rhs) = delete;
+ GlyphBufferData& operator=(const GlyphBufferData& rhs) = delete;
+
+ public:
+ uint8_t* buffer; ///< The glyph's bitmap buffer data.
+ uint32_t width; ///< The width of the bitmap.
+ uint32_t height; ///< The height of the bitmap.
+ int outlineOffsetX; ///< The additional horizontal offset to be added for the glyph's position for outline.
+ int outlineOffsetY; ///< The additional vertical offset to be added for the glyph's position for outline.
+ Pixel::Format format; ///< The pixel's format of the bitmap.
+ CompressionType compressionType; ///< The type of buffer compression.
+ bool isColorEmoji : 1; ///< Whether the glyph is an emoji.
+ bool isColorBitmap : 1; ///< Whether the glyph is a color bitmap.
+ bool isBufferOwned : 1; ///< Whether the glyph's bitmap buffer data owned by this class or not. Becareful when you use non-owned buffer data.
};
/**
*/
FontClient& operator=(const FontClient& handle);
+ /**
+ * @brief This move constructor is required for (smart) pointer semantics.
+ *
+ * @param[in] handle A reference to the moved handle.
+ */
+ FontClient(FontClient&& handle);
+
+ /**
+ * @brief This move assignment operator is required for (smart) pointer semantics.
+ *
+ * @param [in] handle A reference to the moved handle.
+ * @return A reference to this.
+ */
+ FontClient& operator=(FontClient&& handle);
+
////////////////////////////////////////
// Font management and validation.
////////////////////////////////////////
void GetDefaultFonts(FontList& defaultFonts);
/**
+ * @brief Initializes and caches default font from the system.
+ */
+ void InitDefaultFontDescription();
+
+ /**
* @brief Retrieve the active default font from the system.
*
* @param[out] fontDescription font structure describing the default font.
void GetSystemFonts(FontList& systemFonts);
/**
- * @brief Retrieves the font description of a given font @p id.
+ * @brief Retrieves the font description of a given font @p fontId.
*
- * @param[in] id The font identifier.
+ * @param[in] fontId The font identifier.
* @param[out] fontDescription The path, family & style (width, weight and slant) describing the font.
*/
- void GetDescription(FontId id, FontDescription& fontDescription);
+ void GetDescription(FontId fontId, FontDescription& fontDescription);
/**
- * @brief Retrieves the font point size of a given font @p id.
+ * @brief Retrieves the font point size of a given font @p fontId.
*
- * @param[in] id The font identifier.
+ * @param[in] fontId The font identifier.
*
* @return The point size in 26.6 fractional points.
*/
- PointSize26Dot6 GetPointSize(FontId id);
+ PointSize26Dot6 GetPointSize(FontId fontId);
/**
* @brief Whether the given @p character is supported by the font.
/**
* @brief Retrieves a unique font identifier for a given bitmap font.
+ * If the font is not present, it will cache the given font, and give it a new font id.
*
* @param[in] bitmapFont A bitmap font.
*
- * @return A valid font identifier, or zero if no bitmap font is created.
+ * @return A valid font identifier.
*/
FontId GetFontId(const BitmapFont& bitmapFont);
GlyphIndex GetGlyphIndex(FontId fontId, Character charcode);
/**
+ * @brief Return the glyph index of a given character code as modified by the variation selector.
+ *
+ * @param[in] fontId The identifier of the font for the required glyph.
+ * @param[in] charcode The UTF-32 character code.
+ * @param[in] variantSelector The UTF-32 character code point of the variation selector.
+ *
+ * @return The glyph index, or zero if the character code is undefined.
+ */
+ GlyphIndex GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector);
+
+ /**
* @brief Retrieve the metrics for a series of glyphs.
*
* @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values.
*/
DALI_ADAPTOR_API FontClient FontClientPreInitialize();
+/**
+ * @brief This is used to pre-cache FontConfig in order to improve the runtime performance of the application.
+ *
+ * @param[in] fallbackFamilyList A list of fallback font families to be pre-cached.
+ * @param[in] extraFamilyList A list of additional font families to be pre-cached.
+ * @param[in] localeFamily A locale font family to be pre-cached.
+ * @param[in] useThread True if the font client should create thread and perform pre-caching, false otherwise.
+ * @param[in] syncCreation True if thread creation guarantees syncronization with the main thread, false async creation.
+ */
+DALI_ADAPTOR_API void FontClientPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useThread, bool syncCreation);
+
+/**
+ * @brief This is used to pre-load FreeType font face in order to improve the runtime performance of the application.
+ *
+ * @param[in] fontPathList A list of font paths to be pre-loaded.
+ * @param[in] memoryFontPathList A list of memory font paths to be pre-loaded.
+ * @param[in] useThread True if the font client should create thread and perform font pre-loading, false otherwise.
+ * @param[in] syncCreation True if thread creation guarantees syncronization with the main thread, false async creation.
+ *
+ * @note
+ * The fonts in the fontPathList perform FT_New_Face during pre-loading,
+ * which can provide some performace benefits.
+ *
+ * The fonts in the memoryFontPathList read the font file and cache the buffer in memory during pre-load.
+ * This enables the use of FT_New_Memory_Face during runtime and provides a performance boost.
+ * It requires memory equivalent to the size of each font file.
+ */
+DALI_ADAPTOR_API void FontClientFontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread, bool syncCreation);
+
+/**
+ * @brief Joins font threads, waiting for their execution to complete.
+ */
+DALI_ADAPTOR_API void FontClientJoinFontThreads();
+
} // namespace TextAbstraction
} // namespace Dali