Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 198 additions & 58 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion piet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ kurbo = "0.11.3"
pico-args = { version = "0.5.0", optional = true, features = ["eq-separator"] }
png = { version = "0.17.16", optional = true }
os_info = { version = "3.12.0", optional = true, default-features = false }
unic-bidi = "0.9.0"
icu_properties = "2.1.1"

[features]
samples = ["pico-args", "png", "os_info"]
Expand Down
18 changes: 14 additions & 4 deletions piet/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::ops::{Bound, Range, RangeBounds};
use crate::kurbo::{Rect, Size};
use crate::{Color, Error, FontFamily, FontStyle, FontWeight, LineMetric, TextAttribute};

use unic_bidi::bidi_class::{BidiClass, BidiClassCategory};
use icu_properties::props::{BidiClass, EnumeratedProperty};

/// The default point size for text in piet.
pub const DEFAULT_FONT_SIZE: f64 = 12.0;
Expand Down Expand Up @@ -230,12 +230,22 @@ pub fn first_strong_rtl(text: &str) -> bool {
text.chars()
// an upper bound on how many chars we'll check
.take(200)
.map(BidiClass::of)
.find(|c| c.category() == BidiClassCategory::Strong)
.map(|c| c.is_rtl())
.map(BidiClass::for_char)
.find(|c| is_strong_bidi_class(*c))
.map(is_strong_rtl_bidi_class)
.unwrap_or(false)
}

fn is_strong_bidi_class(class: BidiClass) -> bool {
class == BidiClass::LeftToRight
|| class == BidiClass::RightToLeft
|| class == BidiClass::ArabicLetter
}

fn is_strong_rtl_bidi_class(class: BidiClass) -> bool {
class == BidiClass::RightToLeft || class == BidiClass::ArabicLetter
}

/// Returns the number of bytes needed to be read from the image buffer.
pub fn expected_image_buffer_size(row_size: usize, height: usize, stride: usize) -> usize {
if height == 0 {
Expand Down