Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first_style() getter to Cluster #264

Merged
merged 1 commit into from
Feb 5, 2025
Merged
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
8 changes: 7 additions & 1 deletion parley/src/layout/cluster.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021 the Parley Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use super::{BreakReason, Brush, Cluster, ClusterInfo, Glyph, Layout, Line, Range, Run};
use super::{BreakReason, Brush, Cluster, ClusterInfo, Glyph, Layout, Line, Range, Run, Style};
use swash::text::cluster::Whitespace;

/// Defines the visual side of the cluster for hit testing.
Expand Down Expand Up @@ -101,6 +101,12 @@ impl<'a, B: Brush> Cluster<'a, B> {
self.data.text_range(self.run.data)
}

/// Returns the first style that applies to the cluster. If the cluster contains multiple glyphs
/// then this style may not apply to all glyphs in the cluster (see the `DIVERGENT_STYLES` flag)
pub fn first_style(&self) -> &Style<B> {
&self.run.layout.styles()[usize::from(self.data.style_index)]
}

/// Returns the advance of the cluster.
pub fn advance(&self) -> f32 {
self.data.advance
Expand Down