Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fonts: Consider Tertiary Ideographic Plane to be CJK #31670

Merged
merged 13 commits into from Mar 18, 2024
24 changes: 23 additions & 1 deletion components/gfx/tests/text_util.rs
Expand Up @@ -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() {
Expand Down Expand Up @@ -104,3 +104,25 @@ fn test_transform_compress_whitespace_newline_no_incoming() {
assert_eq!(trimmed_str, oracle)
}
}

#[test]
fn test_is_cjk() {
let test_strs = [
('〇', true),
('㐀', true),
('あ', true),
('ア', true),
('㆒', true),
('ㆣ', true),
('龥', true),
('𪣻', true),
('a', false),
('🙂', false),
('©', false),
];
delan marked this conversation as resolved.
Show resolved Hide resolved

for &(test, oracle) in test_strs.iter() {
let symbol: bool = is_cjk(test);
assert_eq!(symbol, oracle);
}
delan marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 2 additions & 1 deletion components/gfx/text/util.rs
Expand Up @@ -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
delan marked this conversation as resolved.
Show resolved Hide resolved
unicode_plane(codepoint) == 2 || unicode_plane(codepoint) == 3
}