{
public:
// Constructor
- GlyphCacheManager(FT_Face ftFace, std::size_t maxNumberOfGlyphCache);
+ GlyphCacheManager(std::size_t maxNumberOfGlyphCache);
// Destructor
~GlyphCacheManager();
/**
* @brief Load GlyphCacheData from face. The result will be cached.
*
+ * @param[in] freeTypeFace The freetype face handle.
* @param[in] index Index of glyph in this face.
* @param[in] flag Flag when we load the glyph.
* @param[in] isBoldRequired True if we require some software bold.
* @return True if load successfully. False if something error occured.
*/
bool GetGlyphCacheDataFromIndex(
+ const FT_Face freeTypeFace,
const GlyphIndex index,
const FT_Int32 flag,
const bool isBoldRequired,
* @brief Load GlyphCacheData from face. The result will not be cached.
* @note If we call this API, We should release GlyphCacheData manually.
*
+ * @param[in] freeTypeFace The freetype face handle.
* @param[in] index Index of glyph in this face.
* @param[in] flag Flag when we load the glyph.
* @param[in] isBoldRequired True if we require some software bold.
* @return True if load successfully. False if something error occured.
*/
bool LoadGlyphDataFromIndex(
+ const FT_Face freeTypeFace,
const GlyphIndex index,
const FT_Int32 flag,
const bool isBoldRequired,
* @brief Resize bitmap glyph. The result will change cached glyph bitmap information.
* If glyph is not bitmap glyph, nothing happened.
*
+ * @param[in] freeTypeFace The freetype face handle.
* @param[in] index Index of glyph in this face.
* @param[in] flag Flag when we load the glyph.
* @param[in] isBoldRequired True if we require some software bold.
* @param[in] desiredHeight Desired height of bitmap.
*/
void ResizeBitmapGlyph(
+ const FT_Face freeTypeFace,
const GlyphIndex index,
const FT_Int32 flag,
const bool isBoldRequired,
* @brief Cache rendered glyph bitmap. The result will change cached glyph information.
* If glyph is not single color glyph, or we already cached buffer before, nothing happened.
*
+ * @param[in] freeTypeFace The freetype face handle.
* @param[in] index Index of glyph in this face.
* @param[in] flag Flag when we load the glyph.
* @param[in] isBoldRequired True if we require some software bold.
* @param[in] policy Compress behavior policy.
*/
void CacheRenderedGlyphBuffer(
+ const FT_Face freeTypeFace,
const GlyphIndex index,
const FT_Int32 flag,
const bool isBoldRequired,
const FT_Bitmap& srcBitmap,
const CompressionPolicyType policy);
+ /**
+ * @brief Clear all cached glyph informations which has inputed FreeTypeFace.
+ *
+ * @note This API iterate all cached glyph. Should be called rarely.
+ * @param[in] freeTypeFace The freetype face handle.
+ */
+ void RemoveGlyphFromFace(const FT_Face freeTypeFace);
+
+ /**
+ * @brief Clear all cached glyph informations.
+ *
+ * @param[in] remainCount The number of remained cache items after call this API. Default is 0, clear all items.
+ */
+ void ClearCache(const std::size_t remainCount = 0u);
+
private:
// Private struct area.
/**
struct GlyphCacheKey
{
GlyphCacheKey()
- : mIndex(0u),
+ : mFreeTypeFace(nullptr),
+ mIndex(0u),
mFlag(0),
mIsBoldRequired(false)
{
}
- GlyphCacheKey(const GlyphIndex index, const FT_Int32 flag, const bool boldRequired)
- : mIndex(index),
+ GlyphCacheKey(const FT_Face freeTypeFace, const GlyphIndex index, const FT_Int32 flag, const bool boldRequired)
+ : mFreeTypeFace(freeTypeFace),
+ mIndex(index),
mFlag(flag),
mIsBoldRequired(boldRequired)
{
}
+
+ FT_Face mFreeTypeFace;
GlyphIndex mIndex;
FT_Int32 mFlag;
bool mIsBoldRequired : 1;
bool operator==(GlyphCacheKey const& rhs) const noexcept
{
- return mIndex == rhs.mIndex && mFlag == rhs.mFlag && mIsBoldRequired == rhs.mIsBoldRequired;
+ return mFreeTypeFace == rhs.mFreeTypeFace && mIndex == rhs.mIndex && mFlag == rhs.mFlag && mIsBoldRequired == rhs.mIsBoldRequired;
}
};
{
std::size_t operator()(GlyphCacheKey const& key) const noexcept
{
- return static_cast<std::size_t>(key.mIndex) ^ static_cast<std::size_t>(key.mFlag) ^ (static_cast<std::size_t>(key.mIsBoldRequired) << 29);
+ return static_cast<std::size_t>(reinterpret_cast<std::uintptr_t>(key.mFreeTypeFace)) ^
+ static_cast<std::size_t>(key.mIndex) ^
+ static_cast<std::size_t>(key.mFlag) ^
+ (static_cast<std::size_t>(key.mIsBoldRequired) << 29);
}
};
private:
// Private member value area.
- FT_Face mFreeTypeFace; ///< The FreeType face. Owned from font-face-cache-item
-
std::size_t mGlyphCacheMaxSize; ///< The maximum capacity of glyph cache.
using CacheContainer = LRUCacheContainer<GlyphCacheKey, GlyphCacheData, GlyphCacheKeyHash>;