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

Refactor module structure #237

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
12 changes: 6 additions & 6 deletions examples/swash_render/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
reason = "Deferred"
)]

use std::fs::File;

use image::codecs::png::PngEncoder;
use image::{self, Pixel, Rgba, RgbaImage};
use parley::layout::{Alignment, Glyph, GlyphRun, Layout, PositionedLayoutItem};
use parley::style::{FontStack, FontWeight, StyleProperty, TextStyle};
use parley::{FontContext, InlineBox, LayoutContext};
use std::fs::File;
use parley::inputs::{FontContext, FontStack, FontWeight, LayoutContext, StyleProperty, TextStyle};
use parley::outputs::{Alignment, Glyph, GlyphRun, Layout, PositionedLayoutItem};
use parley::InlineBox;
use swash::scale::image::Content;
use swash::scale::{Render, ScaleContext, Scaler, Source, StrikeWith};
use swash::zeno;
use swash::FontRef;
use swash::{zeno, FontRef};
use zeno::{Format, Vector};

#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down
5 changes: 3 additions & 2 deletions examples/tiny_skia_render/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
)]

use parley::{
Alignment, FontContext, FontWeight, GenericFamily, GlyphRun, InlineBox, Layout, LayoutContext,
PositionedLayoutItem, StyleProperty,
inputs::{FontContext, FontWeight, GenericFamily, LayoutContext, StyleProperty},
outputs::{Alignment, GlyphRun, Layout, PositionedLayoutItem},
InlineBox,
};
use skrifa::{
instance::{LocationRef, NormalizedCoord, Size},
Expand Down
3 changes: 2 additions & 1 deletion examples/vello_editor/src/access_ids.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2024 the Parley Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use accesskit::NodeId;
use core::sync::atomic::{AtomicU64, Ordering};

use accesskit::NodeId;

pub const WINDOW_ID: NodeId = NodeId(0);
pub const TEXT_INPUT_ID: NodeId = NodeId(1);

Expand Down
16 changes: 8 additions & 8 deletions examples/vello_editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
reason = "Deferred"
)]

use accesskit::{Node, Role, Tree, TreeUpdate};
use anyhow::Result;
use std::num::NonZeroUsize;
use std::sync::Arc;
use vello::kurbo;

use accesskit::{Node, Role, Tree, TreeUpdate};
use anyhow::Result;
use parley::editing::Generation;
use vello::peniko::Color;
use vello::util::{RenderContext, RenderSurface};
use vello::wgpu;
use vello::{AaConfig, Renderer, RendererOptions, Scene};
use vello::{kurbo, wgpu, AaConfig, Renderer, RendererOptions, Scene};
use winit::application::ApplicationHandler;
use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize};
use winit::event::{StartCause, WindowEvent};
Expand Down Expand Up @@ -97,7 +97,7 @@ struct SimpleVelloApp<'s> {
editor: text::Editor,

/// The last generation of the editor layout that we drew.
last_drawn_generation: text::Generation,
last_drawn_generation: Generation,

/// The IME cursor area we last sent to the platform.
last_sent_ime_cursor_area: kurbo::Rect,
Expand Down Expand Up @@ -185,7 +185,7 @@ impl ApplicationHandler<accesskit_winit::Event> for SimpleVelloApp<'_> {
self.editor.cursor_blink();

if let Some(next_time) = self.editor.next_blink_time() {
self.last_drawn_generation = text::Generation::default();
self.last_drawn_generation = Generation::default();
if let RenderState::Active(state) = &self.state {
state.window.request_redraw();
}
Expand Down Expand Up @@ -260,7 +260,7 @@ impl ApplicationHandler<accesskit_winit::Event> for SimpleVelloApp<'_> {
WindowEvent::Focused(false) => {
self.editor.disable_blink();
self.editor.cursor_blink();
self.last_drawn_generation = text::Generation::default();
self.last_drawn_generation = Generation::default();
if let RenderState::Active(state) = &self.state {
state.window.request_redraw();
}
Expand Down
6 changes: 3 additions & 3 deletions examples/vello_editor/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use accesskit::{Node, TreeUpdate};
use core::default::Default;
use parley::{editor::SplitString, layout::PositionedLayoutItem, GenericFamily, StyleProperty};
use std::time::{Duration, Instant};
use vello::{
kurbo::{Affine, Line, Stroke},
Expand All @@ -16,8 +15,9 @@ use winit::{
keyboard::{Key, NamedKey},
};

pub use parley::layout::editor::Generation;
use parley::{FontContext, LayoutContext, PlainEditor, PlainEditorDriver};
use parley::editing::{Generation, PlainEditor, PlainEditorDriver, SplitString};
use parley::inputs::{FontContext, GenericFamily, LayoutContext, StyleProperty};
use parley::outputs::PositionedLayoutItem;

use crate::access_ids::next_node_id;

Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions parley/src/algos/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2024 the Parley Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// TODO - Remove pub(crate)

pub(crate) mod bidi;
pub(crate) mod resolve;
pub(crate) mod shape;
pub(crate) mod swash_convert;
28 changes: 14 additions & 14 deletions parley/src/resolve/mod.rs → parley/src/algos/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ pub(crate) mod tree;

pub(crate) use range::RangedStyleBuilder;

use alloc::{vec, vec::Vec};

use super::style::{
Brush, FontFamily, FontFeature, FontSettings, FontStack, FontStyle, FontVariation, FontWeight,
FontWidth, StyleProperty,
};
use crate::font::FontContext;
use crate::layout;
use crate::style::TextStyle;
use crate::util::nearly_eq;
use alloc::vec;
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::ops::Range;

use fontique::FamilyId;
use swash::text::Language;

use crate::inputs::{
Brush, FontContext, FontFamily, FontFeature, FontSettings, FontStack, FontStyle, FontVariation,
FontWeight, FontWidth, StyleProperty, TextStyle,
};
use crate::outputs;
use crate::util::nearly_eq;

/// Style with an associated range.
#[derive(Debug, Clone)]
pub(crate) struct RangedStyle<B: Brush> {
Expand Down Expand Up @@ -476,8 +476,8 @@ impl<B: Brush> ResolvedStyle<B> {
}
}

pub(crate) fn as_layout_style(&self) -> layout::Style<B> {
layout::Style {
pub(crate) fn as_layout_style(&self) -> outputs::Style<B> {
outputs::Style {
brush: self.brush.clone(),
underline: self.underline.as_layout_decoration(&self.brush),
strikethrough: self.strikethrough.as_layout_decoration(&self.brush),
Expand All @@ -501,9 +501,9 @@ pub(crate) struct ResolvedDecoration<B: Brush> {

impl<B: Brush> ResolvedDecoration<B> {
/// Convert into a layout Decoration (filtering out disabled decorations)
pub(crate) fn as_layout_decoration(&self, default_brush: &B) -> Option<layout::Decoration<B>> {
pub(crate) fn as_layout_decoration(&self, default_brush: &B) -> Option<outputs::Decoration<B>> {
if self.enabled {
Some(layout::Decoration {
Some(outputs::Decoration {
brush: self.brush.clone().unwrap_or_else(|| default_brush.clone()),
offset: self.offset,
size: self.size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//! Range based style application.

use alloc::vec;
use core::ops::{Bound, Range, RangeBounds};

use super::{Brush, RangedProperty, RangedStyle, ResolvedProperty, ResolvedStyle, Vec};
use core::ops::{Bound, Range, RangeBounds};

/// Builder for constructing an ordered sequence of non-overlapping ranged
/// styles from a collection of ranged style properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

//! Hierarchical tree based style application.
use alloc::borrow::Cow;
use alloc::{string::String, vec::Vec};

use crate::style::WhiteSpaceCollapse;
use alloc::string::String;
use alloc::vec::Vec;

use super::{Brush, RangedStyle, ResolvedProperty, ResolvedStyle};
use crate::inputs::WhiteSpaceCollapse;

#[derive(Debug, Clone)]
struct StyleTreeNode<B: Brush> {
Expand Down
23 changes: 11 additions & 12 deletions parley/src/shape.rs → parley/src/algos/shape.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright 2021 the Parley Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use super::layout::Layout;
use super::resolve::{RangedStyle, ResolveContext, Resolved};
use super::style::{Brush, FontFeature, FontVariation};
use crate::util::nearly_eq;
use crate::Font;
use fontique::QueryFamily;
use fontique::{self, Query, QueryFont};
use alloc::vec::Vec;

use fontique::{self, Query, QueryFamily, QueryFont};
use swash::shape::{partition, Direction, ShapeContext};
use swash::text::cluster::{CharCluster, CharInfo, Token};
use swash::text::{Language, Script};
use swash::{FontRef, Synthesis};

use alloc::vec::Vec;

use crate::algos::resolve::{RangedStyle, ResolveContext, Resolved};
use crate::algos::swash_convert::{locale_to_fontique, script_to_fontique, synthesis_to_swash};
use crate::inline_box::InlineBox;
use crate::inputs::{Brush, FontFeature, FontVariation};
use crate::outputs::Layout;
use crate::util::nearly_eq;
use crate::Font;

struct Item {
style_index: u16,
Expand Down Expand Up @@ -248,8 +248,8 @@ impl<'a, 'b, B: Brush> FontSelector<'a, 'b, B> {
let variations = rcx.variations(style.font_variations).unwrap_or(&[]);
let features = rcx.features(style.font_features).unwrap_or(&[]);
query.set_families(fonts.iter().copied());
let fb_script = crate::swash_convert::script_to_fontique(script);
let fb_language = locale.and_then(crate::swash_convert::locale_to_fontique);
let fb_script = script_to_fontique(script);
let fb_language = locale.and_then(locale_to_fontique);
query.set_fallbacks(fontique::FallbackKey::new(fb_script, fb_language.as_ref()));
query.set_attributes(attrs);
Self {
Expand Down Expand Up @@ -306,7 +306,6 @@ impl<B: Brush> partition::Selector for FontSelector<'_, '_, B> {
let mut selected_font = None;
self.query.matches_with(|font| {
if let Ok(font_ref) = skrifa::FontRef::from_index(font.blob.as_ref(), font.index) {
use crate::swash_convert::synthesis_to_swash;
use skrifa::MetadataProvider;
use swash::text::cluster::Status as MapStatus;
let charmap = font_ref.charmap();
Expand Down
File renamed without changes.
Loading
Loading