1use super::{
2 FontFeature, GlyphBuffer, GlyphMask, LookupRequest, LookupStatus, ScriptProvider, ShapeError,
3 ShapeRequest, TextRange,
4};
5use crate::unicode::{graphemes, Script};
6
7const ALL: GlyphMask = GlyphMask::ALL;
8
9fn enabled(request: &ShapeRequest<'_>, tag: [u8; 4], default: bool) -> bool {
10 request
11 .features
12 .iter()
13 .filter(|feature| feature.tag == tag && overlaps(feature, request))
14 .fold(default, |_, feature| feature.value != 0)
15}
16
17fn overlaps(feature: &FontFeature, request: &ShapeRequest<'_>) -> bool {
18 feature.range.end > request.range.start as u32 && feature.range.start < request.range.end as u32
19}
20
21fn substitute(
22 request: &ShapeRequest<'_>,
23 font: &dyn super::ShapingData,
24 glyphs: &mut GlyphBuffer<'_>,
25 tag: [u8; 4],
26 mask: GlyphMask,
27 default: bool,
28) -> Result<LookupStatus, ShapeError> {
29 if !enabled(request, tag, default) {
30 return Ok(LookupStatus::NotFound);
31 }
32 font.substitute(LookupRequest::new(request, tag, mask), glyphs)
33}
34
35fn position(
36 request: &ShapeRequest<'_>,
37 font: &dyn super::ShapingData,
38 glyphs: &mut GlyphBuffer<'_>,
39 tag: [u8; 4],
40 default: bool,
41) -> Result<LookupStatus, ShapeError> {
42 if !enabled(request, tag, default) {
43 return Ok(LookupStatus::NotFound);
44 }
45 font.position(LookupRequest::new(request, tag, ALL), glyphs)
46}
47
48fn normalize_clusters(request: &ShapeRequest<'_>, glyphs: &mut GlyphBuffer<'_>) {
49 let text = &request.text[request.range.clone()];
50 for cluster in graphemes(text) {
51 let range = TextRange::new(
52 (request.range.start + cluster.range.start) as u32,
53 (request.range.start + cluster.range.end) as u32,
54 );
55 let mut matched = 0;
56 for glyph in glyphs.glyphs_mut() {
57 if glyph.cluster.start >= range.start && glyph.cluster.start < range.end {
58 glyph.cluster = range;
59 matched += 1;
60 }
61 }
62 if matched > 1 {
63 for glyph in glyphs.glyphs_mut() {
64 if glyph.cluster == range {
65 glyph.set_unsafe_to_break(true);
66 }
67 }
68 }
69 }
70}
71
72#[cfg(feature = "script-arabic")]
73pub const ARABIC: Arabic = Arabic;
75
76#[cfg(feature = "script-arabic")]
77pub struct Arabic;
79
80#[cfg(feature = "script-arabic")]
81const ISOL: GlyphMask = GlyphMask::new(1 << 0);
82#[cfg(feature = "script-arabic")]
83const INIT: GlyphMask = GlyphMask::new(1 << 1);
84#[cfg(feature = "script-arabic")]
85const MEDI: GlyphMask = GlyphMask::new(1 << 2);
86#[cfg(feature = "script-arabic")]
87const FINA: GlyphMask = GlyphMask::new(1 << 3);
88
89#[cfg(feature = "script-arabic")]
90#[derive(Clone, Copy, Eq, PartialEq)]
91enum Joining {
92 None,
93 Right,
94 Dual,
95 Transparent,
96}
97
98#[cfg(feature = "script-arabic")]
99impl Joining {
100 const fn joins_previous(self) -> bool {
101 matches!(self, Self::Right | Self::Dual)
102 }
103
104 const fn joins_next(self) -> bool {
105 matches!(self, Self::Dual)
106 }
107}
108
109#[cfg(feature = "script-arabic")]
110fn joining(character: char) -> Joining {
111 let scalar = character as u32;
112 if matches!(
113 scalar,
114 0x0610..=0x061A | 0x064B..=0x065F | 0x0670 | 0x06D6..=0x06ED | 0x08D3..=0x08FF
115 ) {
116 return Joining::Transparent;
117 }
118 if matches!(
119 scalar,
120 0x0622..=0x0625
121 | 0x0627
122 | 0x0629
123 | 0x062F..=0x0632
124 | 0x0648
125 | 0x0671..=0x0673
126 | 0x0675..=0x0677
127 | 0x0688..=0x0699
128 | 0x06C0
129 | 0x06C3..=0x06CB
130 | 0x06CD
131 | 0x06CF
132 | 0x06D2..=0x06D3
133 ) {
134 return Joining::Right;
135 }
136 if matches!(
137 scalar,
138 0x0626
139 | 0x0628
140 | 0x062A..=0x062E
141 | 0x0633..=0x063A
142 | 0x0641..=0x0647
143 | 0x0649..=0x064A
144 | 0x066E..=0x066F
145 | 0x0678..=0x0687
146 | 0x069A..=0x06BF
147 | 0x06CC
148 | 0x06CE
149 | 0x06D0..=0x06D1
150 | 0x06FA..=0x06FC
151 ) {
152 return Joining::Dual;
153 }
154 Joining::None
155}
156
157#[cfg(feature = "script-arabic")]
158fn character_at(
159 request: &ShapeRequest<'_>,
160 glyphs: &GlyphBuffer<'_>,
161 index: usize,
162) -> Option<char> {
163 let start = usize::try_from(glyphs.get(index)?.cluster.start).ok()?;
164 request.text.get(start..)?.chars().next()
165}
166
167#[cfg(feature = "script-arabic")]
168fn neighbor(
169 request: &ShapeRequest<'_>,
170 glyphs: &GlyphBuffer<'_>,
171 index: usize,
172 previous: bool,
173) -> Option<Joining> {
174 if previous {
175 for slot in (0..index).rev() {
176 let class = joining(character_at(request, glyphs, slot)?);
177 if class != Joining::Transparent {
178 return Some(class);
179 }
180 }
181 } else {
182 for slot in index + 1..glyphs.len() {
183 let class = joining(character_at(request, glyphs, slot)?);
184 if class != Joining::Transparent {
185 return Some(class);
186 }
187 }
188 }
189 None
190}
191
192#[cfg(feature = "script-arabic")]
193fn assign_joining_masks(
194 request: &ShapeRequest<'_>,
195 glyphs: &mut GlyphBuffer<'_>,
196) -> Result<bool, ShapeError> {
197 let mut joined = false;
198 for index in 0..glyphs.len() {
199 let current =
200 joining(character_at(request, glyphs, index).ok_or(ShapeError::InvalidGlyphRange)?);
201 if current == Joining::Transparent {
202 glyphs.set_mask(index, GlyphMask::NONE)?;
203 continue;
204 }
205 let previous = neighbor(request, glyphs, index, true)
206 .is_some_and(|class| class.joins_next() && current.joins_previous());
207 let next = neighbor(request, glyphs, index, false)
208 .is_some_and(|class| current.joins_next() && class.joins_previous());
209 let mask = match (previous, next) {
210 (false, false) => ISOL,
211 (false, true) => INIT,
212 (true, true) => MEDI,
213 (true, false) => FINA,
214 };
215 joined |= previous || next;
216 if previous || next {
217 glyphs
218 .get_mut(index)
219 .expect("valid joining slot")
220 .set_unsafe_to_break(true);
221 }
222 glyphs.set_mask(index, mask)?;
223 }
224 Ok(joined)
225}
226
227#[cfg(feature = "script-arabic")]
228impl ScriptProvider for Arabic {
229 fn script(&self) -> Script {
230 Script::Arabic
231 }
232
233 fn substitute(
234 &self,
235 request: &ShapeRequest<'_>,
236 font: &dyn super::ShapingData,
237 glyphs: &mut GlyphBuffer<'_>,
238 ) -> Result<(), ShapeError> {
239 let joined = assign_joining_masks(request, glyphs)?;
240 normalize_clusters(request, glyphs);
241 substitute(request, font, glyphs, *b"ccmp", ALL, true)?;
242 substitute(request, font, glyphs, *b"locl", ALL, true)?;
243 let mut forms = 0;
244 for (tag, mask) in [
245 (*b"isol", ISOL),
246 (*b"fina", FINA),
247 (*b"medi", MEDI),
248 (*b"init", INIT),
249 ] {
250 forms += usize::from(
251 substitute(request, font, glyphs, tag, mask, true)? == LookupStatus::Applied,
252 );
253 }
254 if joined && forms == 0 {
255 return Err(ShapeError::ShapingUnavailable);
256 }
257 for tag in [*b"rlig", *b"calt", *b"liga"] {
258 substitute(request, font, glyphs, tag, ALL, true)?;
259 }
260 Ok(())
261 }
262
263 fn position(
264 &self,
265 request: &ShapeRequest<'_>,
266 font: &dyn super::ShapingData,
267 glyphs: &mut GlyphBuffer<'_>,
268 ) -> Result<(), ShapeError> {
269 position(request, font, glyphs, *b"curs", true)?;
270 position(request, font, glyphs, *b"kern", true)?;
271 let has_marks = request.text[request.range.clone()]
272 .chars()
273 .any(|character| joining(character) == Joining::Transparent);
274 let mark = position(request, font, glyphs, *b"mark", true)?;
275 let mkmk = position(request, font, glyphs, *b"mkmk", true)?;
276 if has_marks && mark == LookupStatus::NotFound && mkmk == LookupStatus::NotFound {
277 return Err(ShapeError::ShapingUnavailable);
278 }
279 Ok(())
280 }
281}
282
283#[cfg(feature = "script-thai")]
284pub const THAI: Thai = Thai;
286
287#[cfg(feature = "script-thai")]
288pub struct Thai;
290
291#[cfg(feature = "script-thai")]
292fn thai_mark(character: char) -> bool {
293 matches!(character as u32, 0x0E31 | 0x0E34..=0x0E3A | 0x0E47..=0x0E4E)
294}
295
296#[cfg(feature = "script-thai")]
297impl ScriptProvider for Thai {
298 fn script(&self) -> Script {
299 Script::Thai
300 }
301
302 fn substitute(
303 &self,
304 request: &ShapeRequest<'_>,
305 font: &dyn super::ShapingData,
306 glyphs: &mut GlyphBuffer<'_>,
307 ) -> Result<(), ShapeError> {
308 normalize_clusters(request, glyphs);
309 for tag in [*b"ccmp", *b"locl", *b"liga"] {
310 substitute(request, font, glyphs, tag, ALL, true)?;
311 }
312 Ok(())
313 }
314
315 fn position(
316 &self,
317 request: &ShapeRequest<'_>,
318 font: &dyn super::ShapingData,
319 glyphs: &mut GlyphBuffer<'_>,
320 ) -> Result<(), ShapeError> {
321 position(request, font, glyphs, *b"kern", true)?;
322 let has_marks = request.text[request.range.clone()].chars().any(thai_mark);
323 let mark = position(request, font, glyphs, *b"mark", true)?;
324 let mkmk = position(request, font, glyphs, *b"mkmk", true)?;
325 if has_marks && mark == LookupStatus::NotFound && mkmk == LookupStatus::NotFound {
326 return Err(ShapeError::ShapingUnavailable);
327 }
328 Ok(())
329 }
330}
331
332#[cfg(feature = "script-devanagari")]
333pub const DEVANAGARI: Devanagari = Devanagari;
335
336#[cfg(feature = "script-devanagari")]
337pub struct Devanagari;
339
340#[cfg(feature = "script-devanagari")]
341fn devanagari_consonant(character: char) -> bool {
342 matches!(
343 character as u32,
344 0x0915..=0x0939 | 0x0958..=0x095F | 0x0978..=0x097F
345 )
346}
347
348#[cfg(feature = "script-devanagari")]
349fn devanagari_mark(character: char) -> bool {
350 matches!(
351 character as u32,
352 0x0900..=0x0903
353 | 0x093A..=0x094C
354 | 0x094E..=0x0957
355 | 0x0962..=0x0963
356 | 0xA8E0..=0xA8F1
357 )
358}
359
360#[cfg(feature = "script-devanagari")]
361fn glyph_at_text_offset(glyphs: &GlyphBuffer<'_>, offset: u32) -> Option<usize> {
362 glyphs
363 .glyphs()
364 .iter()
365 .position(|glyph| glyph.cluster.start <= offset && offset < glyph.cluster.end)
366}
367
368#[cfg(feature = "script-devanagari")]
369fn reorder_devanagari_prebase_matra(request: &ShapeRequest<'_>, glyphs: &mut GlyphBuffer<'_>) {
370 let mut base = None;
371 let mut previous = None;
372 for (relative, character) in request.text[request.range.clone()].char_indices() {
373 let offset = (request.range.start + relative) as u32;
374 if devanagari_consonant(character) {
375 if character != '\u{0930}' || previous != Some('\u{094D}') {
376 base = Some(offset);
377 }
378 previous = Some(character);
379 continue;
380 }
381 if character != '\u{093F}' {
382 previous = Some(character);
383 continue;
384 }
385 let (Some(base_index), Some(matra_index)) = (
386 base.and_then(|base| glyph_at_text_offset(glyphs, base)),
387 glyph_at_text_offset(glyphs, offset),
388 ) else {
389 continue;
390 };
391 if base_index < matra_index {
392 glyphs.glyphs_mut()[base_index..=matra_index].rotate_right(1);
393 }
394 previous = Some(character);
395 }
396}
397
398#[cfg(feature = "script-devanagari")]
399impl ScriptProvider for Devanagari {
400 fn script(&self) -> Script {
401 Script::Devanagari
402 }
403
404 fn substitute(
405 &self,
406 request: &ShapeRequest<'_>,
407 font: &dyn super::ShapingData,
408 glyphs: &mut GlyphBuffer<'_>,
409 ) -> Result<(), ShapeError> {
410 for tag in [*b"locl", *b"ccmp", *b"nukt"] {
411 substitute(request, font, glyphs, tag, ALL, true)?;
412 }
413 reorder_devanagari_prebase_matra(request, glyphs);
414
415 let mut conjunct_forms = 0;
416 for tag in [
417 *b"akhn", *b"rphf", *b"rkrf", *b"pref", *b"blwf", *b"half", *b"pstf", *b"vatu",
418 *b"abvf", *b"cjct",
419 ] {
420 conjunct_forms += usize::from(
421 substitute(request, font, glyphs, tag, ALL, true)? == LookupStatus::Applied,
422 );
423 }
424 if request.text[request.range.clone()].contains('\u{094D}') && conjunct_forms == 0 {
425 return Err(ShapeError::ShapingUnavailable);
426 }
427 for tag in [*b"init", *b"pres", *b"abvs", *b"blws", *b"psts", *b"haln"] {
428 substitute(request, font, glyphs, tag, ALL, true)?;
429 }
430 normalize_clusters(request, glyphs);
431 Ok(())
432 }
433
434 fn position(
435 &self,
436 request: &ShapeRequest<'_>,
437 font: &dyn super::ShapingData,
438 glyphs: &mut GlyphBuffer<'_>,
439 ) -> Result<(), ShapeError> {
440 position(request, font, glyphs, *b"kern", true)?;
441 position(request, font, glyphs, *b"dist", true)?;
442 let has_marks = request.text[request.range.clone()]
443 .chars()
444 .any(devanagari_mark);
445 let abvm = position(request, font, glyphs, *b"abvm", true)?;
446 let blwm = position(request, font, glyphs, *b"blwm", true)?;
447 let mark = position(request, font, glyphs, *b"mark", true)?;
448 let mkmk = position(request, font, glyphs, *b"mkmk", true)?;
449 if has_marks
450 && [abvm, blwm, mark, mkmk]
451 .iter()
452 .all(|status| *status == LookupStatus::NotFound)
453 {
454 return Err(ShapeError::ShapingUnavailable);
455 }
456 Ok(())
457 }
458}
459
460#[cfg(test)]
461mod tests {
462 use super::*;
463 use crate::bidi::Direction;
464 use crate::shaping::{
465 FlowPoint, FontAccessError, FontId, GlyphId, GlyphSource, ShapedGlyph, ShapingData,
466 };
467
468 struct Font;
469
470 impl GlyphSource for Font {
471 fn id(&self) -> FontId {
472 FontId::new(1)
473 }
474 fn metrics(&self) -> Result<super::super::FontMetrics, FontAccessError> {
475 Ok(super::super::FontMetrics::default())
476 }
477 fn glyph_for(&self, character: char) -> Result<Option<GlyphId>, FontAccessError> {
478 Ok(Some(GlyphId::new(character as u16)))
479 }
480 fn glyph_advance(&self, _glyph: GlyphId) -> Result<FlowPoint, FontAccessError> {
481 Ok(FlowPoint { x: 10, y: 0 })
482 }
483 }
484
485 #[cfg(any(feature = "script-arabic", feature = "script-thai"))]
486 struct Data;
487
488 #[cfg(any(feature = "script-arabic", feature = "script-thai"))]
489 impl ShapingData for Data {
490 fn substitute(
491 &self,
492 request: LookupRequest<'_, '_>,
493 glyphs: &mut GlyphBuffer<'_>,
494 ) -> Result<LookupStatus, ShapeError> {
495 for index in 0..glyphs.len() {
496 if glyphs.mask(index).is_some_and(|mask| request.selects(mask)) {
497 glyphs.set_glyph(index, GlyphId::new(100 + request.feature()[0] as u16))?;
498 }
499 }
500 Ok(LookupStatus::Applied)
501 }
502 fn position(
503 &self,
504 _request: LookupRequest<'_, '_>,
505 _glyphs: &mut GlyphBuffer<'_>,
506 ) -> Result<LookupStatus, ShapeError> {
507 Ok(LookupStatus::Applied)
508 }
509 }
510
511 struct MissingData;
512
513 impl ShapingData for MissingData {
514 fn substitute(
515 &self,
516 _request: LookupRequest<'_, '_>,
517 _glyphs: &mut GlyphBuffer<'_>,
518 ) -> Result<LookupStatus, ShapeError> {
519 Ok(LookupStatus::NotFound)
520 }
521
522 fn position(
523 &self,
524 _request: LookupRequest<'_, '_>,
525 _glyphs: &mut GlyphBuffer<'_>,
526 ) -> Result<LookupStatus, ShapeError> {
527 Ok(LookupStatus::NotFound)
528 }
529 }
530
531 #[cfg(feature = "script-devanagari")]
532 struct DevanagariData;
533
534 #[cfg(feature = "script-devanagari")]
535 impl ShapingData for DevanagariData {
536 fn substitute(
537 &self,
538 _request: LookupRequest<'_, '_>,
539 _glyphs: &mut GlyphBuffer<'_>,
540 ) -> Result<LookupStatus, ShapeError> {
541 Ok(LookupStatus::Applied)
542 }
543
544 fn position(
545 &self,
546 _request: LookupRequest<'_, '_>,
547 _glyphs: &mut GlyphBuffer<'_>,
548 ) -> Result<LookupStatus, ShapeError> {
549 Ok(LookupStatus::Applied)
550 }
551 }
552
553 #[cfg(feature = "script-arabic")]
554 struct FormData;
555
556 #[cfg(feature = "script-arabic")]
557 impl ShapingData for FormData {
558 fn substitute(
559 &self,
560 request: LookupRequest<'_, '_>,
561 glyphs: &mut GlyphBuffer<'_>,
562 ) -> Result<LookupStatus, ShapeError> {
563 let Some(form) = [*b"isol", *b"init", *b"medi", *b"fina"]
564 .iter()
565 .position(|tag| *tag == request.feature())
566 else {
567 return Ok(LookupStatus::NotFound);
568 };
569 for index in 0..glyphs.len() {
570 if glyphs.mask(index).is_some_and(|mask| request.selects(mask)) {
571 glyphs.set_glyph(index, GlyphId::new(200 + form as u16))?;
572 }
573 }
574 Ok(LookupStatus::Applied)
575 }
576
577 fn position(
578 &self,
579 _request: LookupRequest<'_, '_>,
580 _glyphs: &mut GlyphBuffer<'_>,
581 ) -> Result<LookupStatus, ShapeError> {
582 Ok(LookupStatus::Applied)
583 }
584 }
585
586 #[cfg(feature = "script-arabic")]
587 #[test]
588 fn arabic_assigns_contextual_forms_without_allocating() {
589 let providers: [&dyn ScriptProvider; 1] = [&ARABIC];
590 let face = super::super::ScriptTypeface::new(&Font, &Data).with_scripts(&providers);
591 let text = "مرحبا";
592 let request =
593 ShapeRequest::new(text, 0..text.len(), Direction::RightToLeft, Script::Arabic);
594 let mut output = [ShapedGlyph::default(); 5];
595 let count = super::super::Typeface::shape_into(&face, &request, &mut output).unwrap();
596 assert_eq!(count, 5);
597 assert!(output
598 .iter()
599 .all(|glyph| glyph.glyph_id() == GlyphId::new(208)));
600 assert!(output.iter().all(|glyph| glyph.unsafe_to_break()));
601 }
602
603 #[cfg(feature = "script-arabic")]
604 #[test]
605 fn arabic_joining_masks_skip_transparent_marks() {
606 let text = "بَبب";
607 let request =
608 ShapeRequest::new(text, 0..text.len(), Direction::RightToLeft, Script::Arabic);
609 let mut output = [ShapedGlyph::default(); 4];
610 for (slot, (offset, character)) in output.iter_mut().zip(text.char_indices()) {
611 *slot = ShapedGlyph::new(
612 GlyphId::new(character as u16),
613 TextRange::new(offset as u32, (offset + character.len_utf8()) as u32),
614 );
615 }
616 let mut glyphs = GlyphBuffer::new(&mut output, 4).unwrap();
617
618 assert!(assign_joining_masks(&request, &mut glyphs).unwrap());
619 assert_eq!(glyphs.mask(0), Some(INIT));
620 assert_eq!(glyphs.mask(1), Some(GlyphMask::NONE));
621 assert_eq!(glyphs.mask(2), Some(MEDI));
622 assert_eq!(glyphs.mask(3), Some(FINA));
623 }
624
625 #[cfg(feature = "script-arabic")]
626 #[test]
627 fn arabic_marks_do_not_receive_joining_forms() {
628 let providers: [&dyn ScriptProvider; 1] = [&ARABIC];
629 let face = super::super::ScriptTypeface::new(&Font, &FormData).with_scripts(&providers);
630 let text = "بَب";
631 let request =
632 ShapeRequest::new(text, 0..text.len(), Direction::RightToLeft, Script::Arabic);
633 let mut output = [ShapedGlyph::default(); 3];
634
635 let count = super::super::Typeface::shape_into(&face, &request, &mut output).unwrap();
636
637 assert_eq!(count, 3);
638 assert_eq!(output[1].glyph_id(), GlyphId::new('\u{64e}' as u16));
639 assert_ne!(output[0].cluster, output[1].cluster);
640 assert_eq!(output[1].cluster, output[2].cluster);
641 }
642
643 #[cfg(feature = "script-arabic")]
644 #[test]
645 fn arabic_marks_require_positioning_data() {
646 let providers: [&dyn ScriptProvider; 1] = [&ARABIC];
647 let face = super::super::ScriptTypeface::new(&Font, &MissingData).with_scripts(&providers);
648 let text = "بَ";
649 let request =
650 ShapeRequest::new(text, 0..text.len(), Direction::RightToLeft, Script::Arabic);
651 let mut output = [ShapedGlyph::default(); 2];
652
653 assert_eq!(
654 super::super::Typeface::shape_into(&face, &request, &mut output),
655 Err(ShapeError::ShapingUnavailable)
656 );
657 }
658
659 #[cfg(feature = "script-thai")]
660 #[test]
661 fn thai_keeps_base_and_mark_in_one_cluster() {
662 let providers: [&dyn ScriptProvider; 1] = [&THAI];
663 let face = super::super::ScriptTypeface::new(&Font, &Data).with_scripts(&providers);
664 let text = "กิ";
665 let request = ShapeRequest::new(text, 0..text.len(), Direction::LeftToRight, Script::Thai);
666 let mut output = [ShapedGlyph::default(); 2];
667 let count = super::super::Typeface::shape_into(&face, &request, &mut output).unwrap();
668 assert_eq!(count, 2);
669 assert!(output
670 .iter()
671 .all(|glyph| glyph.glyph_id() == GlyphId::new(208)));
672 assert_eq!(output[0].cluster, output[1].cluster);
673 assert!(output.iter().all(|glyph| glyph.unsafe_to_break()));
674 }
675
676 #[cfg(feature = "script-thai")]
677 #[test]
678 fn thai_marks_require_positioning_data() {
679 let providers: [&dyn ScriptProvider; 1] = [&THAI];
680 let face = super::super::ScriptTypeface::new(&Font, &MissingData).with_scripts(&providers);
681 let text = "กิ";
682 let request = ShapeRequest::new(text, 0..text.len(), Direction::LeftToRight, Script::Thai);
683 let mut output = [ShapedGlyph::default(); 2];
684
685 assert_eq!(
686 super::super::Typeface::shape_into(&face, &request, &mut output),
687 Err(ShapeError::ShapingUnavailable)
688 );
689 }
690
691 #[cfg(feature = "script-devanagari")]
692 #[test]
693 fn devanagari_reorders_prebase_matra_without_allocating() {
694 let providers: [&dyn ScriptProvider; 1] = [&DEVANAGARI];
695 let face =
696 super::super::ScriptTypeface::new(&Font, &DevanagariData).with_scripts(&providers);
697 let text = "कि";
698 let request = ShapeRequest::new(
699 text,
700 0..text.len(),
701 Direction::LeftToRight,
702 Script::Devanagari,
703 );
704 let mut output = [ShapedGlyph::default(); 2];
705
706 let count = super::super::Typeface::shape_into(&face, &request, &mut output).unwrap();
707
708 assert_eq!(count, 2);
709 assert_eq!(output[0].glyph_id(), GlyphId::new('\u{093F}' as u16));
710 assert_eq!(output[1].glyph_id(), GlyphId::new('\u{0915}' as u16));
711 assert_eq!(output[0].cluster, output[1].cluster);
712 assert!(output.iter().all(|glyph| glyph.unsafe_to_break()));
713 }
714
715 #[cfg(feature = "script-devanagari")]
716 #[test]
717 fn devanagari_conjuncts_require_shaping_data() {
718 let providers: [&dyn ScriptProvider; 1] = [&DEVANAGARI];
719 let face = super::super::ScriptTypeface::new(&Font, &MissingData).with_scripts(&providers);
720 let text = "क्ष";
721 let request = ShapeRequest::new(
722 text,
723 0..text.len(),
724 Direction::LeftToRight,
725 Script::Devanagari,
726 );
727 let mut output = [ShapedGlyph::default(); 3];
728
729 assert_eq!(
730 super::super::Typeface::shape_into(&face, &request, &mut output),
731 Err(ShapeError::ShapingUnavailable)
732 );
733 }
734
735 #[cfg(feature = "script-devanagari")]
736 #[test]
737 fn devanagari_marks_require_positioning_data() {
738 let providers: [&dyn ScriptProvider; 1] = [&DEVANAGARI];
739 let face = super::super::ScriptTypeface::new(&Font, &MissingData).with_scripts(&providers);
740 let text = "कि";
741 let request = ShapeRequest::new(
742 text,
743 0..text.len(),
744 Direction::LeftToRight,
745 Script::Devanagari,
746 );
747 let mut output = [ShapedGlyph::default(); 2];
748
749 assert_eq!(
750 super::super::Typeface::shape_into(&face, &request, &mut output),
751 Err(ShapeError::ShapingUnavailable)
752 );
753 }
754}