Skip to content

Commit e00c702

Browse files
authored
Honour region subtags (#749)
<!-- Thanks for opening a PR for this Linebender project! --> <!-- If you used any LLM ("AI") tools in making this PR, please ensure that you have reviewed our LLM policy at https://linebender.org/wiki/llm-policy/. Please list how you used it (e.g. writing code, reviewing, fact finding) below. We expect you to have fully understood and self-reviewed your contributions to Linebender. If you did not use any LLM tools, please replace "Unspecified" with 'None'. --> LLM Contributions: Regression testing, CI changes (GPT 5.5 Sol). Fixes #748. | Before | After | | ------ | ------ | | Subtag not honoured (same glyphs throughout) | Subtag honoured | | <img width="205" height="215" alt="before_subtag" src="https://github.com/user-attachments/assets/be445fcb-ac7f-4183-9278-88c80aa2677a" /> | <img width="205" height="215" alt="after_subtag" src="https://github.com/user-attachments/assets/e8b1e782-fbaf-49f4-905c-770801019478" /> | <!-- If this change has any user facing effects, please describe them in the quote block below. What you write here will be edited by us later - it doesn't need to be perfect. If this change doesn't need a changelog entry, please replace the next line with `**Changelog: None**` and delete the quote block. Do not use an LLM to write the changelog entry. --> **Changelog** > ### Fixed > > - Honours script and region sub tags for correct shaping of, for example, zh-Hans and zh-Hant.
1 parent a0752c7 commit e00c702

7 files changed

Lines changed: 127 additions & 2 deletions

File tree

parley_dev/assets/fonts/noto_fonts/LICENSE.txt renamed to parley_dev/assets/fonts/noto_fonts/LICENSE-NotoKufiArabic.txt

File renamed without changes.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
This Font Software is licensed under the SIL Open Font License,
2+
Version 1.1.
3+
4+
This license is copied below, and is also available with a FAQ at:
5+
http://scripts.sil.org/OFL
6+
7+
-----------------------------------------------------------
8+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9+
-----------------------------------------------------------
10+
11+
PREAMBLE
12+
The goals of the Open Font License (OFL) are to stimulate worldwide
13+
development of collaborative font projects, to support the font
14+
creation efforts of academic and linguistic communities, and to
15+
provide a free and open framework in which fonts may be shared and
16+
improved in partnership with others.
17+
18+
The OFL allows the licensed fonts to be used, studied, modified and
19+
redistributed freely as long as they are not sold by themselves. The
20+
fonts, including any derivative works, can be bundled, embedded,
21+
redistributed and/or sold with any software provided that any reserved
22+
names are not used by derivative works. The fonts and derivatives,
23+
however, cannot be released under any other type of license. The
24+
requirement for fonts to remain under this license does not apply to
25+
any document created using the fonts or their derivatives.
26+
27+
DEFINITIONS
28+
"Font Software" refers to the set of files released by the Copyright
29+
Holder(s) under this license and clearly marked as such. This may
30+
include source files, build scripts and documentation.
31+
32+
"Reserved Font Name" refers to any names specified as such after the
33+
copyright statement(s).
34+
35+
"Original Version" refers to the collection of Font Software
36+
components as distributed by the Copyright Holder(s).
37+
38+
"Modified Version" refers to any derivative made by adding to,
39+
deleting, or substituting -- in part or in whole -- any of the
40+
components of the Original Version, by changing formats or by porting
41+
the Font Software to a new environment.
42+
43+
"Author" refers to any designer, engineer, programmer, technical
44+
writer or other person who contributed to the Font Software.
45+
46+
PERMISSION & CONDITIONS
47+
Permission is hereby granted, free of charge, to any person obtaining
48+
a copy of the Font Software, to use, study, copy, merge, embed,
49+
modify, redistribute, and sell modified and unmodified copies of the
50+
Font Software, subject to the following conditions:
51+
52+
1) Neither the Font Software nor any of its individual components, in
53+
Original or Modified Versions, may be sold by itself.
54+
55+
2) Original or Modified Versions of the Font Software may be bundled,
56+
redistributed and/or sold with any software, provided that each copy
57+
contains the above copyright notice and this license. These can be
58+
included either as stand-alone text files, human-readable headers or
59+
in the appropriate machine-readable metadata fields within text or
60+
binary files as long as those fields can be easily viewed by the user.
61+
62+
3) No Modified Version of the Font Software may use the Reserved Font
63+
Name(s) unless explicit written permission is granted by the
64+
corresponding Copyright Holder. This restriction only applies to the
65+
primary font name as presented to the users.
66+
67+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68+
Software shall not be used to promote, endorse or advertise any
69+
Modified Version, except to acknowledge the contribution(s) of the
70+
Copyright Holder(s) and the Author(s) or with their explicit written
71+
permission.
72+
73+
5) The Font Software, modified or unmodified, in part or in whole,
74+
must be distributed entirely under this license, and must not be
75+
distributed under any other license. The requirement for fonts to
76+
remain under this license does not apply to any document created using
77+
the Font Software.
78+
79+
TERMINATION
80+
This license becomes null and void if any of the above conditions are
81+
not met.
82+
83+
DISCLAIMER
84+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92+
OTHER DEALINGS IN THE FONT SOFTWARE.
15.7 MB
Binary file not shown.

parley_dev/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn font_dirs() -> impl Iterator<Item = PathBuf> {
2323
pub const FONT_FAMILIES: &[&str] = &[
2424
"Arimo",
2525
"Roboto",
26+
"Noto Sans CJK SC",
2627
"Noto Kufi Arabic",
2728
"Noto Color Emoji",
2829
"Noto Color Emoji CBTF",

parley_engine/src/shape/shaper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ fn shape_segment(
303303
let language = options
304304
.language
305305
.as_ref()
306-
.and_then(|lang| lang.language().parse::<harfrust::Language>().ok());
306+
.and_then(|lang| lang.as_str().parse::<harfrust::Language>().ok());
307307
scx.features.clear();
308308
for feature in options.features {
309309
scx.features.push(harfrust::Feature::new(
4.02 KB
Loading

parley_tests/tests/issues.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
66
use crate::test_name;
77
use crate::util::TestEnv;
8-
use parley::{Alignment, AlignmentOptions, PositionedLayoutItem, StyleProperty, TextWrapMode};
8+
use parley::{
9+
Alignment, AlignmentOptions, FontFamily, PositionedLayoutItem, StyleProperty, TextWrapMode,
10+
};
911

1012
/// Test that rendering RTL text doesn't affect subsequent LTR layouts.
1113
/// See <https://github.com/linebender/parley/issues/489>.
@@ -114,3 +116,33 @@ Third line that ends with newlines\n\n";
114116
env.with_name("max_context_with_mandatory_breaks")
115117
.check_layout_snapshot(&layout);
116118
}
119+
120+
/// Test that script and region subtags select the corresponding OpenType language system.
121+
/// See <https://github.com/linebender/parley/issues/748>.
122+
#[test]
123+
fn issue_748_language_subtags() {
124+
let mut env = TestEnv::new(test_name!(), None);
125+
let text = "zh: 骨\nzh-Hans: 骨\nzh-Hant: 骨\nzh-TW: 骨\nzh-HK: 骨";
126+
127+
let mut builder = env.ranged_builder(text);
128+
builder.push_default(StyleProperty::FontSize(32.0));
129+
for ((start, marker), language) in text
130+
.match_indices('骨')
131+
.zip(["zh", "zh-Hans", "zh-Hant", "zh-TW", "zh-HK"])
132+
{
133+
let range = start..start + marker.len();
134+
builder.push(
135+
StyleProperty::FontFamily(FontFamily::named("Noto Sans CJK SC")),
136+
range.clone(),
137+
);
138+
builder.push(
139+
StyleProperty::Locale(Some(language.parse().unwrap())),
140+
range,
141+
);
142+
}
143+
144+
let mut layout = builder.build(text);
145+
layout.break_all_lines(None);
146+
layout.align(Alignment::Start, AlignmentOptions::default());
147+
env.check_layout_snapshot(&layout);
148+
}

0 commit comments

Comments
 (0)