Struct cosmic_text::ShapeSpan
source · Expand description
A shaped span (for bidirectional processing)
Fields§
§level: Level§words: Vec<ShapeWord>Implementations§
source§impl ShapeSpan
impl ShapeSpan
sourcepub fn new<'a>(
font_system: &'a FontSystem,
line: &str,
attrs_list: &AttrsList,
span_range: Range<usize>,
line_rtl: bool,
level: Level
) -> Self
pub fn new<'a>(
font_system: &'a FontSystem,
line: &str,
attrs_list: &AttrsList,
span_range: Range<usize>,
line_rtl: bool,
level: Level
) -> Self
Examples found in repository?
src/shape.rs (lines 464-471)
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
pub fn new<'a>(
font_system: &'a FontSystem,
line: &str,
attrs_list: &AttrsList
) -> Self {
let mut spans = Vec::new();
let bidi = unicode_bidi::BidiInfo::new(line, None);
let rtl = if bidi.paragraphs.is_empty() {
false
} else {
assert_eq!(bidi.paragraphs.len(), 1);
let para_info = &bidi.paragraphs[0];
let line_rtl = para_info.level.is_rtl();
log::trace!("Line {}: '{}'", if line_rtl { "RTL" } else { "LTR" }, line);
let line_range = para_info.range.clone();
let levels = Self::adjust_levels(&unicode_bidi::Paragraph::new(&bidi, para_info));
// Find consecutive level runs. We use this to create Spans.
// Each span is a set of characters with equal levels.
let mut start = line_range.start;
let mut run_level = levels[start];
for (i, &new_level) in levels.iter().enumerate().take(line_range.end).skip(start + 1) {
if new_level != run_level {
// End of the previous run, start of a new one.
spans.push(ShapeSpan::new(
font_system,
line,
attrs_list,
start..i,
line_rtl,
run_level,
));
start = i;
run_level = new_level;
}
}
spans.push(ShapeSpan::new(
font_system,
line,
attrs_list,
start..line_range.end,
line_rtl,
run_level,
));
line_rtl
};
Self { rtl, spans}
}