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

Remove skrifa from vello's public API #747

Merged
merged 8 commits into from
Jan 15, 2025
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
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This is the first step towards providing richer color functionality, better hand
- Breaking: The `full` feature is no longer present as the full pipeline is now always built ([#754][] by [@waywardmonkeys])
- The `r8` permutation of the shaders is no longer available ([#756][] by [@waywardmonkeys])
- Breaking: The `buffer_labels` feature is no longer present as the labels are always configured ([#757][] by [@waywardmonkeys])
- Breaking: Use a type alias for `i16` rather than `skrifa::NormalizedCoord` in the public API ([#747][] by [@nicoburns][])

### Fixed

Expand Down Expand Up @@ -142,15 +143,16 @@ This release has an [MSRV][] of 1.75.
[@dfrg]: https://github.com/drfg
[@DJMcNab]: https://github.com/DJMcNab
[@kmoon2437]: https://github.com/kmoon2437
[@LaurenzV]: https://github.com/LaurenzV
[@msiglreith]: https://github.com/msiglreith
[@nicoburns]: https://github.com/nicoburns
[@ratmice]: https://github.com/ratmice
[@simbleau]: https://github.com/simbleau
[@TheNachoBIT]: https://github.com/TheNachoBIT
[@timtom-dev]: https://github.com/timtom-dev
[@TrueDoctor]: https://github.com/TrueDoctor
[@waywardmonkeys]: https://github.com/waywardmonkeys
[@yutannihilation]: https://github.com/yutannihilation
[@LaurenzV]: https://github.com/LaurenzV
[@ratmice]: https://github.com/ratmice

[#416]: https://github.com/linebender/vello/pull/416
[#435]: https://github.com/linebender/vello/pull/435
Expand Down Expand Up @@ -213,6 +215,7 @@ This release has an [MSRV][] of 1.75.
[#740]: https://github.com/linebender/vello/pull/740
[#742]: https://github.com/linebender/vello/pull/742
[#743]: https://github.com/linebender/vello/pull/743
[#747]: https://github.com/linebender/vello/pull/747
[#754]: https://github.com/linebender/vello/pull/754
[#756]: https://github.com/linebender/vello/pull/756

Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions examples/scenes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ workspace = true

[dependencies]
vello = { workspace = true }
skrifa = { workspace = true }
anyhow = { workspace = true }
clap = { workspace = true, features = ["derive"] }
image = { workspace = true, features = ["jpeg"] }
rand = "0.8.5"

# for pico_svg
roxmltree = "0.20.0"
bytemuck.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-time = { workspace = true }
Expand Down
13 changes: 7 additions & 6 deletions examples/scenes/src/simple_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

use std::sync::Arc;

use skrifa::{
raw::{FileRef, FontRef},
MetadataProvider,
};
use vello::kurbo::Affine;
use vello::peniko::{color::palette, Blob, Brush, BrushRef, Font, StyleRef};
use vello::skrifa::{raw::FontRef, MetadataProvider};
use vello::peniko::{color::palette, Blob, Brush, BrushRef, Fill, Font, StyleRef};
use vello::{Glyph, Scene};

// This is very much a hack to get things working.
Expand Down Expand Up @@ -144,7 +147,7 @@ impl SimpleText {
let brush = brush.into();
let style = style.into();
let axes = font_ref.axes();
let font_size = vello::skrifa::instance::Size::new(size);
let font_size = skrifa::instance::Size::new(size);
let var_loc = axes.location(variations.iter().copied());
let charmap = font_ref.charmap();
let metrics = font_ref.metrics(font_size, &var_loc);
Expand All @@ -157,7 +160,7 @@ impl SimpleText {
.font_size(size)
.transform(transform)
.glyph_transform(glyph_transform)
.normalized_coords(var_loc.coords())
.normalized_coords(bytemuck::cast_slice(var_loc.coords()))
.brush(brush)
.hint(false)
.draw(
Expand Down Expand Up @@ -190,7 +193,6 @@ impl SimpleText {
transform: Affine,
text: &str,
) {
use vello::peniko::Fill;
let brush = brush.unwrap_or(&Brush::Solid(palette::css::WHITE));
self.add_run(
scene,
Expand All @@ -206,7 +208,6 @@ impl SimpleText {
}

fn to_font_ref(font: &Font) -> Option<FontRef<'_>> {
use vello::skrifa::raw::FileRef;
let file_ref = FileRef::new(font.data.as_ref()).ok()?;
match file_ref {
FileRef::Font(font) => Some(font),
Expand Down
3 changes: 1 addition & 2 deletions vello/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,12 @@ pub mod low_level {
pub use peniko;
/// 2D geometry, with a focus on curves.
pub use peniko::kurbo;
pub use skrifa;

#[cfg(feature = "wgpu")]
pub use wgpu;

pub use scene::{DrawGlyphs, Scene};
pub use vello_encoding::Glyph;
pub use vello_encoding::{Glyph, NormalizedCoord};

use low_level::ShaderId;
#[cfg(feature = "wgpu")]
Expand Down
11 changes: 6 additions & 5 deletions vello/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use peniko::{
use png::{BitDepth, ColorType, Transformations};
use skrifa::{
color::{ColorGlyph, ColorPainter},
instance::{LocationRef, NormalizedCoord},
instance::LocationRef,
outline::{DrawSettings, OutlinePen},
prelude::Size,
raw::{tables::cpal::Cpal, TableProvider},
GlyphId, MetadataProvider, OutlineGlyphCollection,
};
#[cfg(feature = "bump_estimate")]
use vello_encoding::BumpAllocatorMemory;
use vello_encoding::{Encoding, Glyph, GlyphRun, Patch, Transform};
use vello_encoding::{Encoding, Glyph, GlyphRun, NormalizedCoord, Patch, Transform};

// TODO - Document invariants and edge cases (#470)
// - What happens when we pass a transform matrix with NaN values to the Scene?
Expand Down Expand Up @@ -508,10 +508,11 @@ impl<'a> DrawGlyphs<'a> {
let mut final_glyph = None;
let mut outline_count = 0;
// We copy out of the variable font coords here because we need to call an exclusive self method
let coords = &self.scene.encoding.resources.normalized_coords
[self.run.normalized_coords.clone()]
let coords = bytemuck::cast_slice(
&self.scene.encoding.resources.normalized_coords[self.run.normalized_coords.clone()],
)
.to_vec();
let location = LocationRef::new(coords);
let location = LocationRef::new(&coords);
loop {
let ppem = self.run.font_size;
let outline_glyphs = (&mut glyphs).take_while(|glyph| {
Expand Down
4 changes: 2 additions & 2 deletions vello_encoding/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

use super::{
DrawBlurRoundedRect, DrawColor, DrawImage, DrawLinearGradient, DrawRadialGradient,
DrawSweepGradient, DrawTag, Glyph, GlyphRun, Patch, PathEncoder, PathTag, Style, Transform,
DrawSweepGradient, DrawTag, Glyph, GlyphRun, NormalizedCoord, Patch, PathEncoder, PathTag,
Style, Transform,
};

use peniko::color::{palette, DynamicColor};
use peniko::kurbo::{Shape, Stroke};
use peniko::{BlendMode, BrushRef, ColorStop, Extend, Fill, GradientKind, Image};
use skrifa::instance::NormalizedCoord;

/// Encoded data streams for a scene.
///
Expand Down
18 changes: 18 additions & 0 deletions vello_encoding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,21 @@ pub use resolve::{resolve_solid_paths_only, Layout, Patch, Resolver};

#[cfg(feature = "bump_estimate")]
pub use estimate::BumpEstimator;

/// A normalized variation coordinate (for variable fonts) in 2.14 fixed point format.
///
/// In most cases, this can be [cast](bytemuck::cast_slice) from the
/// normalised coords provided by your text layout library.
///
/// Equivalent to [`skrifa::instance::NormalizedCoord`], but defined
/// in Vello so that Skrifa is not part of Vello's public API.
/// This allows Vello to update its Skrifa in a patch release, and limits
/// the need for updates only to align Skrifa versions.
pub type NormalizedCoord = i16;

#[cfg(test)]
mod tests {
const _NORMALISED_COORD_SIZE_MATCHES: () = assert!(
size_of::<skrifa::prelude::NormalizedCoord>() == size_of::<crate::NormalizedCoord>()
);
}
11 changes: 7 additions & 4 deletions vello_encoding/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,13 @@ impl Resolver {
hint = false;
}
}
let Some(mut session) = self
.glyph_cache
.session(&run.font, coords, font_size, hint, &run.style)
else {
let Some(mut session) = self.glyph_cache.session(
&run.font,
bytemuck::cast_slice(coords),
font_size,
hint,
&run.style,
) else {
continue;
};
let glyph_start = self.glyphs.len();
Expand Down
Loading