Skip to content

Commit 7745398

Browse files
committed
Add --single-par in tests as well
1 parent 1c0225a commit 7745398

File tree

2 files changed

+77
-63
lines changed

2 files changed

+77
-63
lines changed

scripts/gen-shaping-tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def convert_test(hb_dir, hb_shape_exe, tests_name, file_name, idx, data, fonts):
118118
glyphs_expected = subprocess.run(options_list, check=True, stdout=subprocess.PIPE)\
119119
.stdout.decode()
120120

121-
glyphs_expected = glyphs_expected[1:-2] # remove `[..]\n`
121+
glyphs_expected = glyphs_expected.strip()[1:-1] # remove leading and trailing whitespaces and `[..]`
122122
glyphs_expected = glyphs_expected.replace('|', '|\\\n ')
123123

124124
options = options.replace('"', '\\"')

tests/shaping/main.rs

+76-62
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct Args {
2626
no_clusters: bool,
2727
show_extents: bool,
2828
show_flags: bool,
29+
single_par: bool,
2930
ned: bool,
3031
bot: bool,
3132
eot: bool,
@@ -61,6 +62,7 @@ fn parse_args(args: Vec<std::ffi::OsString>) -> Result<Args, pico_args::Error> {
6162
no_clusters: parser.contains("--no-clusters"),
6263
show_extents: parser.contains("--show-extents"),
6364
show_flags: parser.contains("--show-flags"),
65+
single_par: parser.contains("--single-par"),
6466
ned: parser.contains("--ned"),
6567
bot: parser.contains("--bot"),
6668
eot: parser.contains("--eot"),
@@ -115,67 +117,79 @@ pub fn shape(font_path: &str, text: &str, options: &str) -> String {
115117
face.set_variations(&variations);
116118
}
117119

118-
let mut buffer = rustybuzz::UnicodeBuffer::new();
119-
if let Some(pre_context) = args.pre_context {
120-
buffer.set_pre_context(&pre_context);
121-
}
122-
buffer.push_str(text);
123-
if let Some(post_context) = args.post_context {
124-
buffer.set_post_context(&post_context);
125-
}
126-
127-
if let Some(d) = args.direction {
128-
buffer.set_direction(d);
129-
}
130-
131-
if let Some(lang) = args.language {
132-
buffer.set_language(lang);
133-
}
134-
135-
if let Some(script) = args.script {
136-
buffer.set_script(script);
137-
}
138-
139-
let mut buffer_flags = BufferFlags::default();
140-
buffer_flags.set(BufferFlags::BEGINNING_OF_TEXT, args.bot);
141-
buffer_flags.set(BufferFlags::END_OF_TEXT, args.eot);
142-
buffer.set_flags(buffer_flags);
143-
144-
buffer.set_cluster_level(args.cluster_level);
145-
buffer.reset_clusters();
146-
147-
let mut features = Vec::new();
148-
for feature_str in args.features {
149-
let feature = rustybuzz::Feature::from_str(&feature_str).unwrap();
150-
features.push(feature);
151-
}
152-
153-
let glyph_buffer = rustybuzz::shape(&face, &features, buffer);
154-
155-
let mut format_flags = rustybuzz::SerializeFlags::default();
156-
if args.no_glyph_names {
157-
format_flags |= rustybuzz::SerializeFlags::NO_GLYPH_NAMES;
158-
}
159-
160-
if args.no_clusters || args.ned {
161-
format_flags |= rustybuzz::SerializeFlags::NO_CLUSTERS;
162-
}
163-
164-
if args.no_positions {
165-
format_flags |= rustybuzz::SerializeFlags::NO_POSITIONS;
166-
}
167-
168-
if args.no_advances || args.ned {
169-
format_flags |= rustybuzz::SerializeFlags::NO_ADVANCES;
170-
}
171-
172-
if args.show_extents {
173-
format_flags |= rustybuzz::SerializeFlags::GLYPH_EXTENTS;
174-
}
175-
176-
if args.show_flags {
177-
format_flags |= rustybuzz::SerializeFlags::GLYPH_FLAGS;
178-
}
120+
let lines = if args.single_par {
121+
vec![text]
122+
} else {
123+
text.split("\n").filter(|s| !s.is_empty()).collect()
124+
};
179125

180-
glyph_buffer.serialize(&face, format_flags)
126+
lines
127+
.into_iter()
128+
.map(|text| {
129+
let mut buffer = rustybuzz::UnicodeBuffer::new();
130+
if let Some(ref pre_context) = args.pre_context {
131+
buffer.set_pre_context(pre_context);
132+
}
133+
buffer.push_str(text);
134+
if let Some(ref post_context) = args.post_context {
135+
buffer.set_post_context(post_context);
136+
}
137+
138+
if let Some(d) = args.direction {
139+
buffer.set_direction(d);
140+
}
141+
142+
if let Some(lang) = args.language.clone() {
143+
buffer.set_language(lang);
144+
}
145+
146+
if let Some(script) = args.script {
147+
buffer.set_script(script);
148+
}
149+
150+
let mut buffer_flags = BufferFlags::default();
151+
buffer_flags.set(BufferFlags::BEGINNING_OF_TEXT, args.bot);
152+
buffer_flags.set(BufferFlags::END_OF_TEXT, args.eot);
153+
buffer.set_flags(buffer_flags);
154+
155+
buffer.set_cluster_level(args.cluster_level);
156+
buffer.reset_clusters();
157+
158+
let mut features = Vec::new();
159+
for feature_str in &args.features {
160+
let feature = rustybuzz::Feature::from_str(feature_str).unwrap();
161+
features.push(feature);
162+
}
163+
164+
let glyph_buffer = rustybuzz::shape(&face, &features, buffer);
165+
166+
let mut format_flags = rustybuzz::SerializeFlags::default();
167+
if args.no_glyph_names {
168+
format_flags |= rustybuzz::SerializeFlags::NO_GLYPH_NAMES;
169+
}
170+
171+
if args.no_clusters || args.ned {
172+
format_flags |= rustybuzz::SerializeFlags::NO_CLUSTERS;
173+
}
174+
175+
if args.no_positions {
176+
format_flags |= rustybuzz::SerializeFlags::NO_POSITIONS;
177+
}
178+
179+
if args.no_advances || args.ned {
180+
format_flags |= rustybuzz::SerializeFlags::NO_ADVANCES;
181+
}
182+
183+
if args.show_extents {
184+
format_flags |= rustybuzz::SerializeFlags::GLYPH_EXTENTS;
185+
}
186+
187+
if args.show_flags {
188+
format_flags |= rustybuzz::SerializeFlags::GLYPH_FLAGS;
189+
}
190+
191+
glyph_buffer.serialize(&face, format_flags)
192+
})
193+
.collect::<Vec<String>>()
194+
.join("\n")
181195
}

0 commit comments

Comments
 (0)