diff --git a/components/gfx/tests/text_util.rs b/components/gfx/tests/text_util.rs index 2a973cd23110..cb5a1d5c2532 100644 --- a/components/gfx/tests/text_util.rs +++ b/components/gfx/tests/text_util.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use gfx::text::util::{transform_text, CompressionMode}; +use gfx::text::util::{is_cjk, transform_text, CompressionMode}; #[test] fn test_transform_compress_none() { @@ -104,3 +104,22 @@ fn test_transform_compress_whitespace_newline_no_incoming() { assert_eq!(trimmed_str, oracle) } } + +#[test] +fn test_is_cjk() { + // Test characters from different CJK blocks + assert_eq!(is_cjk('〇'), true); + assert_eq!(is_cjk('㐀'), true); + assert_eq!(is_cjk('あ'), true); + assert_eq!(is_cjk('ア'), true); + assert_eq!(is_cjk('㆒'), true); + assert_eq!(is_cjk('ㆣ'), true); + assert_eq!(is_cjk('龥'), true); + assert_eq!(is_cjk('𰾑'), true); + assert_eq!(is_cjk('𰻝'), true); + + // Test characters from outside CJK blocks + assert_eq!(is_cjk('a'), false); + assert_eq!(is_cjk('🙂'), false); + assert_eq!(is_cjk('©'), false); +} diff --git a/components/gfx/text/util.rs b/components/gfx/text/util.rs index be9ba144dca7..016e18f2b563 100644 --- a/components/gfx/text/util.rs +++ b/components/gfx/text/util.rs @@ -149,5 +149,6 @@ pub fn is_cjk(codepoint: char) -> bool { } // https://en.wikipedia.org/wiki/Plane_(Unicode)#Supplementary_Ideographic_Plane - unicode_plane(codepoint) == 2 + // https://en.wikipedia.org/wiki/Plane_(Unicode)#Tertiary_Ideographic_Plane + unicode_plane(codepoint) == 2 || unicode_plane(codepoint) == 3 }