From 6dfc8dd52ccd14495fbfd8c97f6807c906afb3ef Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 1 Jul 2019 14:53:44 +0800 Subject: [PATCH] Add text shaping rule for variation selector-16 --- src/font/font_manager.cpp | 19 ++++++++++++++++--- src/font/font_manager.hpp | 4 ++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/font/font_manager.cpp b/src/font/font_manager.cpp index 89d33df2b..8b8f23ba1 100644 --- a/src/font/font_manager.cpp +++ b/src/font/font_manager.cpp @@ -42,6 +42,7 @@ FontManager *font_manager = NULL; FontManager::FontManager() { #ifndef SERVER_ONLY + m_has_color_emoji = false; m_ft_library = NULL; m_digit_face = NULL; m_shaping_dpi = 128; @@ -364,7 +365,7 @@ void FontManager::shape(const std::u32string& text, for (int i = 0; i < length; i++) { FT_Face cur_face = m_faces.front(); - bool use_prev_face = false; + bool override_face = false; if (prev_face != NULL && i != 0) { hb_script_t prev_script = hb_unicode_script( @@ -380,10 +381,21 @@ void FontManager::shape(const std::u32string& text, // join marks), try to use the previous face so it is not // hb_shape separately cur_face = prev_face; - use_prev_face = true; + override_face = true; } } - if (!use_prev_face) + FT_Face emoji_face = m_faces.size() > 1 ? m_faces[1] : NULL; + if (m_has_color_emoji && !override_face && + length > 1 && i < length - 1 && + emoji_face != NULL && str[i + 1] == 0xfe0f) + { + // Rule for variation selector-16 (emoji presentation) + // It is used in for example Keycap Digit One + // (U+31, U+FE0F, U+20E3) + cur_face = emoji_face; + override_face = true; + } + if (!override_face) { for (unsigned j = 0; j < m_faces.size(); j++) { @@ -576,6 +588,7 @@ FT_Face FontManager::loadColorEmoji() m_shaping_dpi = face->available_sizes[face->num_fixed_sizes - 1].height; checkFTError(FT_Select_Size(face, face->num_fixed_sizes - 1), "setting color emoji size"); + m_has_color_emoji = true; return face; } // loadColorEmoji diff --git a/src/font/font_manager.hpp b/src/font/font_manager.hpp index b2d20cacf..81f63cd19 100644 --- a/src/font/font_manager.hpp +++ b/src/font/font_manager.hpp @@ -73,6 +73,8 @@ private: /** Text drawn to glyph layouts cache. */ std::map > m_cached_gls; + + bool m_has_color_emoji; #endif /** Map type for each \ref FontWithFace with a index, save getting time in @@ -113,6 +115,8 @@ public: } } // ------------------------------------------------------------------------ + bool hasColorEmoji() const { return m_has_color_emoji; } + // ------------------------------------------------------------------------ /** Return the \ref m_ft_library. */ FT_Library getFTLibrary() const { return m_ft_library; } // ------------------------------------------------------------------------