Skip to content

Commit

Permalink
Address remaining issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Jan 15, 2025
1 parent 3383999 commit e303ebd
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions examples/scenes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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
9 changes: 1 addition & 8 deletions examples/scenes/src/simple_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use std::sync::Arc;

use skrifa::prelude::NormalizedCoord;
use skrifa::{
raw::{FileRef, FontRef},
MetadataProvider,
Expand Down Expand Up @@ -161,13 +160,7 @@ impl SimpleText {
.font_size(size)
.transform(transform)
.glyph_transform(glyph_transform)
.normalized_coords(
var_loc
.coords()
.iter()
.copied()
.map(NormalizedCoord::to_bits),
)
.normalized_coords(bytemuck::cast_slice(var_loc.coords()))
.brush(brush)
.hint(false)
.draw(
Expand Down
2 changes: 1 addition & 1 deletion vello/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub use peniko::kurbo;
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
15 changes: 8 additions & 7 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 @@ -406,7 +406,7 @@ impl<'a> DrawGlyphs<'a> {

/// Sets the normalized design space coordinates for a variable font instance.
#[must_use]
pub fn normalized_coords(mut self, coords: impl Iterator<Item = i16>) -> Self {
pub fn normalized_coords(mut self, coords: &[NormalizedCoord]) -> Self {
self.scene
.encoding
.resources
Expand All @@ -416,7 +416,7 @@ impl<'a> DrawGlyphs<'a> {
.encoding
.resources
.normalized_coords
.extend(coords.map(NormalizedCoord::from_bits));
.extend(coords);
self.run.normalized_coords.end = self.scene.encoding.resources.normalized_coords.len();
self
}
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::<_, skrifa::instance::NormalizedCoord>(
&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

0 comments on commit e303ebd

Please sign in to comment.