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
4 changes: 3 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions parley/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ core_maths = { version = "0.1.1", optional = true }
accesskit = { workspace = true, optional = true }
hashbrown = { workspace = true }
harfrust = { workspace = true }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we need to continue depending on harfrust in parley following the migration to parley_core?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! Currently we just need to name some types. In the ShapedText PR (#675), parley drop the harfrust dependency (along with some icu4x crates, all have moved to parley_core).

icu_normalizer = { workspace = true, features = ["compiled_data"] }
icu_properties = { workspace = true, features = ["compiled_data"] }

[dev-dependencies]
parley_dev = { workspace = true }
peniko = { workspace = true }

icu_properties = { workspace = true, features = ["compiled_data"] }

# We special-case android targets because oxipng doesn't build in Android CI.
[target.'cfg(not(target_os = "android"))'.dev-dependencies]
oxipng = { version = "9.1.5", default-features = false, features = ["freestanding"] }
24 changes: 1 addition & 23 deletions parley/src/analysis.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Copyright 2026 the Parley Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

pub(crate) mod cluster;

use crate::{Brush, LayoutContext};

use icu_properties::props::{GeneralCategory, Script};
use parley_core::break_overrides::LineBreakOverrideFn;

use parley_core::{AnalysisDataSources, AnalysisOptions};
use parley_core::AnalysisOptions;

use parlance::WordBreak;

Expand All @@ -34,22 +31,3 @@ pub(crate) fn analyze_text<B: Brush>(
};
lcx.analyzer.analyze(text, &options, &mut lcx.analysis);
}

/// All characters contribute to shaping except:
/// - Control characters
/// - Format characters, unless they use the "Inherited" script
// TODO: this function is duplicated at the time of writing, as it also exists in `parley_core`.
// Once more of `parley` is moved to `parley_core`, this function should be removable.
#[inline(always)]
pub(crate) fn contributes_to_shaping(general_category: GeneralCategory, script: Script) -> bool {
if matches!(
general_category,
GeneralCategory::Control
| GeneralCategory::LineSeparator
| GeneralCategory::ParagraphSeparator
) {
return false;
}

!(general_category == GeneralCategory::Format && script != Script::Inherited)
}
7 changes: 3 additions & 4 deletions parley/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::ops::Range;
use alloc::{vec, vec::Vec};

use parlance::WordBreak;
use parley_core::{Analysis, AnalysisDataSources, Analyzer};
use parley_core::{Analysis, AnalysisDataSources, Analyzer, Shaper};

use super::FontContext;
use super::builder::{RangedBuilder, StyleRunBuilder};
Expand All @@ -18,7 +18,6 @@ use super::style::{Brush, TextStyle};

use crate::builder::TreeBuilder;
use crate::inline_box::InlineBox;
use crate::shape::ShapeContext;

/// Shared scratch space used when constructing text layouts.
///
Expand All @@ -40,7 +39,7 @@ pub struct LayoutContext<B: Brush = [u8; 4]> {

/// Style index for each character, parallel to [`Analysis::char_info`].
pub(crate) char_style_indices: Vec<u16>,
pub(crate) scx: ShapeContext,
pub(crate) scx: Shaper,

// Unicode analysis data sources (provided by icu)
pub(crate) analysis_data_sources: AnalysisDataSources,
Expand All @@ -60,7 +59,7 @@ impl<B: Brush> LayoutContext<B> {
tree_style_builder: TreeStyleBuilder::default(),
char_style_indices: vec![],
analysis_data_sources: AnalysisDataSources::new(),
scx: ShapeContext::default(),
scx: Shaper::default(),
}
}

Expand Down
7 changes: 0 additions & 7 deletions parley/src/convert.rs

This file was deleted.

5 changes: 3 additions & 2 deletions parley/src/editing/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::BoundingBox;
#[cfg(feature = "accesskit")]
use crate::analysis::cluster::Whitespace;
use crate::layout::{Affinity, BreakReason, Cluster, ClusterSide, Layout, Line};
#[cfg(feature = "accesskit")]
use crate::layout::{ClusterPath, LayoutAccessibility};
use crate::style::Brush;

#[cfg(feature = "accesskit")]
use accesskit::TextPosition;
#[cfg(feature = "accesskit")]
use parley_core::shape::Whitespace;

/// Defines a position with a text layout.
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
Expand Down
7 changes: 3 additions & 4 deletions parley/src/layout/alignment.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright 2024 the Parley Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use super::{
BreakReason,
data::{ClusterData, LineItemData},
};
use super::{BreakReason, data::LineItemData};
use crate::data::LayoutData;
use crate::style::Brush;

use parley_core::shape::ClusterData;

/// Alignment of a layout.
#[derive(Copy, Clone, Default, PartialEq, Eq, Debug)]
#[repr(u8)]
Expand Down
11 changes: 6 additions & 5 deletions parley/src/layout/cluster.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright 2021 the Parley Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::analysis::cluster::Whitespace;
use crate::layout::Style;
use crate::layout::data::BreakReason;
use crate::layout::data::ClusterData;
use crate::layout::glyph::Glyph;
use crate::layout::layout::Layout;
use crate::layout::line::{Line, LineItem};
use crate::layout::run::Run;
use crate::style::Brush;

use core::ops::Range;
use parley_core::Glyph;
use parley_core::shape::{ClusterData, ClusterInfo, Whitespace};

/// Atomic unit of text.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -145,7 +145,8 @@ impl<'a, B: Brush> Cluster<'a, B> {

/// Returns the range of text that defines the cluster.
pub fn text_range(&self) -> Range<usize> {
self.data.text_range(self.run.data)
let start = self.run.data.text_range.start + self.data.text_offset as usize;
start..start + self.data.text_len as usize
}

/// Returns the style of the character this cluster represents.
Expand Down Expand Up @@ -439,7 +440,7 @@ impl<'a, B: Brush> Cluster<'a, B> {
Some(offset)
}

pub(crate) fn info(&self) -> &super::data::ClusterInfo {
pub(crate) fn info(&self) -> &ClusterInfo {
&self.data.info
}

Expand Down
108 changes: 3 additions & 105 deletions parley/src/layout/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,117 +2,15 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::inline_box::InlineBox;
use crate::layout::{ContentWidths, Glyph, LineMetrics, RunMetrics, Style};
use crate::layout::{ContentWidths, LineMetrics, RunMetrics, Style};
use crate::style::Brush;
use crate::util::nearly_zero;
use crate::{FontData, IndentOptions, InlineBoxKind, LineHeight, OverflowWrap, TextWrapMode};
use core::ops::Range;

use alloc::vec::Vec;
use parley_core::{Boundary, CharInfo};

use crate::analysis::cluster::Whitespace;

#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) struct ClusterData {
pub(crate) info: ClusterInfo,
/// Cluster flags (see impl methods for details).
pub(crate) flags: u16,
/// Style index for this cluster.
pub(crate) style_index: u16,
/// Number of glyphs in this cluster (0xFF = single glyph stored inline)
pub(crate) glyph_len: u8,
/// Number of text bytes in this cluster
pub(crate) text_len: u8,
/// If `glyph_len == 0xFF`, then `glyph_offset` is a glyph identifier,
/// otherwise, it's an offset into the glyph array with the base
/// taken from the owning run.
pub(crate) glyph_offset: u32,
/// Offset into the text for this cluster
pub(crate) text_offset: u16,
/// Advance width for this cluster
pub(crate) advance: f32,
}

impl ClusterData {
pub(crate) const LIGATURE_START: u16 = 1;
pub(crate) const LIGATURE_COMPONENT: u16 = 2;

#[inline(always)]
pub(crate) fn is_ligature_start(self) -> bool {
self.flags & Self::LIGATURE_START != 0
}

#[inline(always)]
pub(crate) fn is_ligature_component(self) -> bool {
self.flags & Self::LIGATURE_COMPONENT != 0
}

#[inline(always)]
pub(crate) fn text_range(self, run: &RunData) -> Range<usize> {
let start = run.text_range.start + self.text_offset as usize;
start..start + self.text_len as usize
}
}

#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) struct ClusterInfo {
boundary: Boundary,
source_char: char,
}

impl ClusterInfo {
pub(crate) fn new(boundary: Boundary, source_char: char) -> Self {
Self {
boundary,
source_char,
}
}

// Returns the boundary type of the cluster.
pub(crate) fn boundary(self) -> Boundary {
self.boundary
}

// Returns the whitespace type of the cluster.
pub(crate) fn whitespace(self) -> Whitespace {
to_whitespace(self.source_char)
}

/// Returns if the cluster is a line boundary.
pub(crate) fn is_boundary(self) -> bool {
self.boundary != Boundary::None
}

/// Returns if the cluster is an emoji.
pub(crate) fn is_emoji(self) -> bool {
// TODO: Defer to ICU4X properties (see: https://docs.rs/icu/latest/icu/properties/props/struct.Emoji.html).
matches!(self.source_char as u32, 0x1F600..=0x1F64F | 0x1F300..=0x1F5FF | 0x1F680..=0x1F6FF | 0x2600..=0x26FF | 0x2700..=0x27BF)
}

/// Returns if the cluster is any whitespace.
pub(crate) fn is_whitespace(self) -> bool {
self.source_char.is_whitespace()
}

/// Returns the cluster's original character.
pub(crate) fn source_char(self) -> char {
self.source_char
}
}

const fn to_whitespace(c: char) -> Whitespace {
const LINE_SEPARATOR: char = '\u{2028}';
const PARAGRAPH_SEPARATOR: char = '\u{2029}';

match c {
' ' => Whitespace::Space,
'\t' => Whitespace::Tab,
'\n' | '\r' | LINE_SEPARATOR | PARAGRAPH_SEPARATOR => Whitespace::Newline,
'\u{00A0}' => Whitespace::NoBreakSpace,
_ => Whitespace::None,
}
}
use parley_core::shape::{ClusterData, ClusterInfo, Whitespace, to_whitespace};
use parley_core::{Boundary, CharInfo, Glyph};

/// `HarfRust`-based run data
#[derive(Clone, Debug, PartialEq)]
Expand Down
3 changes: 2 additions & 1 deletion parley/src/layout/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
use crate::layout::Style;
use crate::layout::data::BreakReason;
use crate::layout::data::{LayoutItemKind, LineData};
use crate::layout::glyph::Glyph;
use crate::layout::layout::Layout;
use crate::layout::run::Run;
use crate::style::Brush;
use crate::{InlineBox, InlineBoxKind};

use core::ops::Range;
use parley_core::Glyph;

/// Line in a text layout.
#[derive(Copy, Clone)]
Expand Down
3 changes: 1 addition & 2 deletions parley/src/layout/line_break.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use alloc::vec::Vec;
#[allow(unused_imports)]
use core_maths::CoreFloat;

use crate::analysis::cluster::Whitespace;
use crate::data::ClusterData;
use crate::layout::{
BreakReason, Layout, LayoutData, LayoutItem, LayoutItemKind, LineData, LineItemData,
LineMetrics, Run, RunMetrics,
Expand All @@ -20,6 +18,7 @@ use crate::{InlineBoxKind, OverflowWrap, TextWrapMode};

use core::ops::Range;
use parley_core::Boundary;
use parley_core::shape::{ClusterData, Whitespace};

#[derive(Default)]
struct LineLayout {
Expand Down
4 changes: 2 additions & 2 deletions parley/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
mod accessibility;
mod alignment;
mod cluster;
mod glyph;
mod line;
mod line_break;
mod run;
Expand All @@ -19,14 +18,15 @@ mod run;
)]
mod layout;

pub use parley_core::Glyph;

pub(crate) mod data;

#[cfg(feature = "accesskit")]
pub use accessibility::LayoutAccessibility;
pub use alignment::{Alignment, AlignmentOptions};
pub use cluster::{Affinity, Cluster, ClusterPath, ClusterSide};
pub use data::BreakReason;
pub use glyph::Glyph;
pub use layout::Layout;
pub use line::{GlyphRun, Line, LineMetrics, PositionedInlineBox, PositionedLayoutItem};
pub use line_break::{
Expand Down
1 change: 1 addition & 0 deletions parley/src/layout/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::layout::cluster::{Cluster, ClusterPath};
use crate::layout::data::{LineItemData, RunData};
use crate::layout::layout::Layout;
use crate::style::Brush;

use core::ops::Range;
use fontique::Synthesis;

Expand Down
2 changes: 0 additions & 2 deletions parley/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ pub use fontique;
mod analysis;
mod builder;
mod context;
mod convert;
mod font;
mod inline_box;
mod lru_cache;
mod resolve;
mod shape;
mod util;
Expand Down
Loading
Loading