1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! # klyff_msdf
//!
//! This is a reimplementation of [msdfgen](https://github.com/Chlumsky/msdfgen) by Chlumsky in
//! pure rust.
//!
//! By default generation is done on CPU, but for wgpu user it's recommended that you use the gpu
//! generator (gated behind feature flag `wgpu`) for much faster generation and avoiding texture
//! upload.
//!
//! Create a [`MsdfGenerator`] and store it throughout your application's lifetime. Use it to
//! process glyph and obtain a [`GlyphOutline`]. For incompatible glyphs (colored / bitmap), an
//! [`ReadGlyphOutlineError::ShouldRasterize`] is returned, so you can handle separately in your
//! application.
//!
//! To generate MSDF / MTSDF on the CPU, use
//! [`GlyphOutline::generate_msdf`] or [`GlyphOutline::generate_mtsdf`].
//!
//! ```rust
//! # #[cfg(feature = "skrifa")]
//! # {
//! use klyff_msdf::{AtlasRegionSize, MsdfGenerator, MsdfPixelFormat, SkrifaOutlineProvider};
//! use klyff_msdf::skrifa::{FontRef, GlyphId};
//!
//! fn gen_cpu(font: FontRef<'_>, glyph_id: GlyphId) {
//! let mut generator = MsdfGenerator::new();
//! let mut outline = generator
//! .read_glyph(&SkrifaOutlineProvider::new(font, glyph_id))
//! .expect("glyph is msdf-compatible");
//!
//! let size = AtlasRegionSize {
//! inner_width: 32,
//! inner_height: 32,
//! padding_x: 4,
//! padding_y: 4,
//! };
//!
//! // RGB MSDF, packed bytes suitable for writing to an image.
//! let _msdf: &[u8] = outline.generate_msdf(size, MsdfPixelFormat::PackedRgb8);
//! // Or the full MTSDF (RGBA), e.g. for uploading to a GPU texture.
//! let _mtsdf: &[u8] = outline.generate_mtsdf(size);
//! }
//! # }
//! ```
//!
//! GPU generation is done through [`MtsdfGpuWriter`].
//!
//! ```rust
//! # #[cfg(all(feature = "skrifa", feature = "wgpu"))]
//! # {
//! use klyff_msdf::{GpuAtlasRegion, MsdfGenerator, MtsdfGpuWriter, SkrifaOutlineProvider};
//! use klyff_msdf::skrifa::{FontRef, GlyphId};
//!
//! fn gen_gpu(
//! device: &wgpu::Device,
//! queue: &wgpu::Queue,
//! atlas: &wgpu::Texture,
//! writer: &mut MtsdfGpuWriter,
//! generator: &mut MsdfGenerator,
//! font: FontRef<'_>,
//! glyph_ids: &[GlyphId],
//! ) {
//! // Queue multiple glyphs
//! for glyph_id in glyph_ids {
//! let outline = generator
//! .read_glyph(&SkrifaOutlineProvider::new(font.clone(), *glyph_id))
//! .expect("glyph is msdf-compatible");
//!
//! let region = GpuAtlasRegion {
//! layer: 0,
//! min_x: 0,
//! min_y: 0,
//! width: 40,
//! height: 40,
//! padding_x: 4,
//! padding_y: 4,
//! };
//! writer.add_glyph(outline, region);
//! }
//!
//! // Then flush them all in a single set of render passes:
//! let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
//! writer.write_glyphs(device, queue, &mut encoder, atlas);
//! queue.submit(std::iter::once(encoder.finish()));
//! }
//! # }
//! ```
//!
//! ### Non-skrifa font reader
//! This crate provides interop with [skrifa] by default (feature flag `skrifa`). You can implement
//! the [`OutlineProvider`] trait yourself to use other font reader (or even work with other
//! formats like svg).
pub use ;
pub use ;
pub use Aabb;
pub use median;
pub use SegmentCollector;
pub use SkrifaOutlineProvider;
pub use skrifa;
pub use ;