### Generate 3D Glyph Mesh Example Source: https://docs.rs/meshtext/latest/meshtext/trait.Glyph.html Example of generating a 3D mesh for a character using the generate_glyph method. Ensure font data is correctly included and the generator is initialized. ```rust use meshtext::{MeshGenerator, MeshText, Glyph}; let font_data = include_bytes!("../../../assets/font/FiraMono-Regular.ttf"); let mut generator = MeshGenerator::new(font_data); let result: MeshText = generator .generate_glyph('A', true, None) .expect("Failed to generate mesh."); ``` -------------------------------- ### Generate 2D Glyph Mesh Example Source: https://docs.rs/meshtext/latest/meshtext/trait.Glyph.html Example of generating a 2D mesh for a character using the generate_glyph_2d method. This method is suitable for 2D rendering contexts. ```rust use meshtext::{MeshGenerator, MeshText, Glyph}; let font_data = include_bytes!("../../../assets/font/FiraMono-Regular.ttf"); let mut generator = MeshGenerator::new(font_data); let result: MeshText = generator .generate_glyph_2d('A', None) .expect("Failed to generate mesh."); ``` -------------------------------- ### Create an empty BoundingBox Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Creates a new BoundingBox initialized with zero vectors for both minimum and maximum points. This is useful for starting with an empty bounding box. ```rust pub(crate) fn empty() -> Self { Self { max: Vec3A::ZERO, min: Vec3A::ZERO, } } ``` -------------------------------- ### Implement OutlineBuilder: quad_to Source: https://docs.rs/meshtext/latest/src/meshtext/util/outline_builder.rs.html Handles quadratic Bézier curves by interpolating points based on quality settings. Skips the first interpolation step as the start point is already added. ```rust fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) { let p1 = (x1, y1); let p2 = (x, y); // We deliberately omit the first interpolation segment, because the // start point of the curve is already in the list. for step in 1..=self.quality.quad_interpolation_steps { let t = step as f32 / self.quality.quad_interpolation_steps as f32; let p = point_on_quad(&self.current_point, &p1, &p2, t); self.line_to(p.0, p.1); } } ``` -------------------------------- ### Implement OutlineBuilder: move_to Source: https://docs.rs/meshtext/latest/src/meshtext/util/outline_builder.rs.html Handles the 'move_to' command from the OutlineBuilder trait, setting the start index for a new contour and adding the initial point. ```rust fn move_to(&mut self, x: f32, y: f32) { self.start_index = self.index; self.contours.push(vec![self.start_index]); self.add_point((x, y)); } ``` -------------------------------- ### Implement OutlineBuilder: curve_to Source: https://docs.rs/meshtext/latest/src/meshtext/util/outline_builder.rs.html Handles cubic Bézier curves by interpolating points based on quality settings. Skips the first interpolation step as the start point is already added. ```rust fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) { let p1 = (x1, y1); let p2 = (x2, y2); let p3 = (x, y); // We deliberately omit the first interpolation segment, because the // start point of the curve is already in the list. for step in 1..=self.quality.cubic_interpolation_steps { let t = step as f32 / self.quality.cubic_interpolation_steps as f32; let p = point_on_cubic(&self.current_point, &p1, &p2, &p3, t); self.line_to(p.0, p.1); } } ``` -------------------------------- ### Get FontFace Source: https://docs.rs/meshtext/latest/src/meshtext/mesh_generator.rs.html Retrieves a reference to the currently loaded FontFace, allowing access to its properties like height and glyph information. ```APIDOC ## GET /meshgenerator/font ### Description Gets a reference to the currently loaded FontFace. This allows reading out properties like the FontFace::height or retrieving the FontFace::glyph_index of a certain char. ### Method GET ### Endpoint /meshgenerator/font ### Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **font_face** (object) - A reference to the FontFace object. #### Response Example ```json { "font_face": { "height": 100, "ascent": 80, "descent": -20, "units_per_em": 1000, "glyph_count": 500 } } ``` ``` -------------------------------- ### Get FontFace Reference Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshGenerator.html Retrieves a reference to the currently loaded FontFace, allowing access to properties like height or glyph index. ```rust pub fn font(&self) -> &T ``` -------------------------------- ### Initialize Face Source: https://docs.rs/meshtext/latest/meshtext/struct.Face.html Methods to create a Face instance from raw data or existing tables. ```rust pub fn from_slice( data: &'a [u8], index: u32, ) -> Result, FaceParsingError> ``` ```rust pub fn parse(data: &'a [u8], index: u32) -> Result, FaceParsingError> ``` ```rust pub fn from_raw_tables( raw_tables: RawFaceTables<'a>, ) -> Result, FaceParsingError> ``` -------------------------------- ### Face Initialization Source: https://docs.rs/meshtext/latest/meshtext/struct.Face.html Methods for creating a new Face instance from raw data or tables. ```APIDOC ## impl<'a> Face<'a> ### pub fn from_slice( data: &'a [u8], index: u32, ) -> Result, FaceParsingError> **Deprecated since 0.16.0**: use `parse` instead Creates a new `Face` from a raw data. `index` indicates the specific font face in a font collection. Use `fonts_in_collection` to get the total number of font faces. Set to 0 if unsure. This method will do some parsing and sanitization, but in general can be considered free. No significant performance overhead. Required tables: `head`, `hhea` and `maxp`. If an optional table has invalid data it will be skipped. ``` ```APIDOC ### pub fn parse(data: &'a [u8], index: u32) -> Result, FaceParsingError> Creates a new `Face` from a raw data. `index` indicates the specific font face in a font collection. Use `fonts_in_collection` to get the total number of font faces. Set to 0 if unsure. This method will do some parsing and sanitization, but in general can be considered free. No significant performance overhead. Required tables: `head`, `hhea` and `maxp`. If an optional table has invalid data it will be skipped. ``` ```APIDOC ### pub fn from_raw_tables( raw_tables: RawFaceTables<'a>, ) -> Result, FaceParsingError> Creates a new `Face` from provided `RawFaceTables`. ``` -------------------------------- ### BoundingBox::new Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Creates a new BoundingBox with specified minimum and maximum points. ```APIDOC ## BoundingBox::new ### Description Creates a new [BoundingBox]. ### Method Associated function (constructor) ### Parameters #### Arguments - **min** (Vec3A) - Required - The minimum vertex of this bounding box. - **max** (Vec3A) - Required - The maximum vertex of this bounding box. ### Returns - The new [BoundingBox]. ``` -------------------------------- ### GET /variation_coordinates Source: https://docs.rs/meshtext/latest/meshtext/struct.Face.html Retrieves the current normalized variation coordinates. ```APIDOC ## GET /variation_coordinates ### Description Returns the current normalized variation coordinates. ### Method GET ### Response #### Success Response (200) - **coordinates** (&[NormalizedCoordinate]) - The current normalized coordinates. ``` -------------------------------- ### GET /variation_axes Source: https://docs.rs/meshtext/latest/meshtext/struct.Face.html Returns an iterator over the variation axes of the font. ```APIDOC ## GET /variation_axes ### Description Returns an iterator over variation axes defined in the font. ### Method GET ### Response #### Success Response (200) - **axes** (LazyArray16) - An iterator over the font's variation axes. ``` -------------------------------- ### BoundingBox::default Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Provides the default initialization for a BoundingBox. ```APIDOC ## BoundingBox::default ### Description Initializes a BoundingBox with default values. ### Method `default` ### Parameters None ### Request Example ```rust use meshtext::BoundingBox; let bbox: BoundingBox = Default::default(); ``` ### Response A BoundingBox instance with default min and max values. ### Response Example ```rust // Example of the default BoundingBox values: // min: Vec3A::new(-0.5, -0.5, -0.5) // max: Vec3A::new(0.5, 0.5, 0.5) ``` ``` -------------------------------- ### GET /glyph_phantom_points Source: https://docs.rs/meshtext/latest/meshtext/struct.Face.html Parses the phantom points for a specific glyph in a variable font. ```APIDOC ## GET /glyph_phantom_points ### Description Parses glyph’s phantom points. Available only for variable fonts with the gvar table. ### Method GET ### Parameters #### Query Parameters - **glyph_id** (GlyphId) - Required - The ID of the glyph. ### Response #### Success Response (200) - **points** (Option) - The parsed phantom points. ``` -------------------------------- ### Create a new BoundingBox Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Use this constructor to create a new BoundingBox with specified minimum and maximum points. Ensure the points are valid Vec3A types. ```rust pub fn new(min: Vec3A, max: Vec3A) -> Self { Self { max, min } } ``` -------------------------------- ### Get BoundingBox Size Source: https://docs.rs/meshtext/latest/meshtext/struct.BoundingBox.html Retrieves the extent of the bounding box along each axis. ```rust use glam::Vec3A; use meshtext::BoundingBox; let bbox = BoundingBox::new( Vec3A::new(0f32, 0f32, 1f32), Vec3A::new(1f32, 1f32, 3f32), ); assert_eq!(bbox.size(), Vec3A::new(1f32, 1f32, 2f32)); ``` -------------------------------- ### Get Mesh Bounding Box Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshText.html Retrieves the bounding box of the generated mesh. ```rust fn bbox(&self) -> BoundingBox ``` -------------------------------- ### Initialize GlyphOutlineBuilder Source: https://docs.rs/meshtext/latest/src/meshtext/util/outline_builder.rs.html Creates a new instance of GlyphOutlineBuilder with specified font height and quality settings. Requires `ttf_parser::OutlineBuilder` trait. ```rust pub(crate) fn new(font_height: f32, quality: QualitySettings) -> Self { Self { contours: Vec::new(), current_point: (0f32, 0f32), font_height, index: 0, points: Vec::new(), quality, start_index: 0, } } ``` -------------------------------- ### Get Mesh Vertices Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshText.html Retrieves the raw vertex data of the mesh as a vector of f32 values. ```rust fn vertices(&self) -> Vec ``` -------------------------------- ### Implement OutlineBuilder for FontFace Source: https://docs.rs/meshtext/latest/src/meshtext/types/traits/font_face.rs.html Demonstrates how to implement the OutlineBuilder trait to process glyph outlines and capture bounding box information. Requires a font file and parsing it with ttf_parser. ```rust use std::fmt::Write; use ttf_parser; struct Builder(String); impl ttf_parser::OutlineBuilder for Builder { fn move_to(&mut self, x: f32, y: f32) { write!(&mut self.0, "M {} {} ", x, y).unwrap(); } fn line_to(&mut self, x: f32, y: f32) { write!(&mut self.0, "L {} {} ", x, y).unwrap(); } fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) { write!(&mut self.0, "Q {} {} {} {} ", x1, y1, x, y).unwrap(); } fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) { write!(&mut self.0, "C {} {} {} {} {} {} ", x1, y1, x2, y2, x, y).unwrap(); } fn close(&mut self) { write!(&mut self.0, "Z ").unwrap(); } } let data = std::fs::read("assets/font/FiraMono-Regular.ttf").unwrap(); let face = ttf_parser::Face::parse(&data, 0).unwrap(); let mut builder = Builder(String::new()); let bbox = face.outline_glyph(ttf_parser::GlyphId(36), &mut builder).unwrap(); assert_eq!(builder.0, "M 161 176 L 106 0 L 20 0 L 245 689 L 355 689 L 579 0 L 489 0 \ L 434 176 L 161 176 Z M 411 248 L 298 615 L 184 248 L 411 248 Z "); assert_eq!(bbox, ttf_parser::Rect { x_min: 20, y_min: 0, x_max: 579, y_max: 689 }); ``` -------------------------------- ### GET /color_palettes Source: https://docs.rs/meshtext/latest/meshtext/struct.Face.html Retrieves the number of color palettes available in the font's COLR and CPAL tables. ```APIDOC ## GET /color_palettes ### Description Returns the number of palettes stored in the COLR and CPAL tables. ### Method GET ### Response #### Success Response (200) - **palettes** (Option>) - The number of palettes available. ``` -------------------------------- ### Get Mesh Indices Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshText.html Retrieves the optional indices for the mesh, which define how vertices are connected to form triangles. ```rust fn indices(&self) -> Option> ``` -------------------------------- ### Initialize MeshGenerator Source: https://docs.rs/meshtext/latest/src/meshtext/mesh_generator.rs.html Constructors for MeshGenerator providing options for default settings, custom quality, and caching behavior. ```rust pub fn new(font: Vec) -> Self { let face = OwnedFace::from_vec(font, 0).expect("Failed to generate font from data."); Self { cache: HashMap::new(), font: face, indexed_cache: HashMap::new(), quality: QualitySettings::default(), use_cache: true, } } ``` ```rust pub fn new_with_quality(font: Vec, quality: QualitySettings) -> Self { let face = OwnedFace::from_vec(font, 0).expect("Failed to generate font from data."); Self { cache: HashMap::new(), font: face, indexed_cache: HashMap::new(), quality, use_cache: true, } } ``` ```rust pub fn new_without_cache(font: Vec, quality: QualitySettings) -> Self { let face = OwnedFace::from_vec(font, 0).expect("Failed to generate font from data."); Self { cache: HashMap::new(), font: face, indexed_cache: HashMap::new(), quality, use_cache: false, } } ``` -------------------------------- ### MeshGenerator Initialization Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshGenerator.html Methods to create a new instance of MeshGenerator with various configuration options. ```APIDOC ## MeshGenerator::new ### Description Creates a new MeshGenerator instance using the provided font data. ### Parameters - **font** (&'static [u8]) - Required - The font data used for rasterizing. ## MeshGenerator::new_with_quality ### Description Creates a new MeshGenerator with custom quality settings. ### Parameters - **font** (&'static [u8]) - Required - The font data used for rasterizing. - **quality** (QualitySettings) - Required - The quality settings to apply. ## MeshGenerator::new_without_cache ### Description Creates a new MeshGenerator with custom quality settings and disables internal caching. ### Parameters - **font** (&'static [u8]) - Required - The font data used for rasterizing. - **quality** (QualitySettings) - Required - The quality settings to apply. ``` -------------------------------- ### Get Glyph ID of Char Source: https://docs.rs/meshtext/latest/src/meshtext/mesh_generator.rs.html Retrieves the GlyphId for a given character. Returns GlyphId(0) if the character is not found in the font. ```rust self.font .glyph_index(glyph) .unwrap_or(ttf_parser::GlyphId(0)) ``` -------------------------------- ### Get Glyph Outline Data Source: https://docs.rs/meshtext/latest/src/meshtext/util/outline_builder.rs.html Retrieves the constructed GlyphOutline, containing contours and points. This method clones the internal data. ```rust pub(crate) fn get_glyph_outline(&mut self) -> GlyphOutline { GlyphOutline { contours: self.contours.clone(), points: self.points.clone(), } } ``` -------------------------------- ### MeshGenerator Constructors Source: https://docs.rs/meshtext/latest/src/meshtext/mesh_generator.rs.html Provides details on how to create and initialize a MeshGenerator instance with various configurations for font rasterization. ```APIDOC ## MeshGenerator Constructors ### Description This section details the constructors available for the `MeshGenerator` struct, allowing for initialization with default or custom quality settings, and with or without caching enabled. ### `new` Creates a new `MeshGenerator` with default quality settings and caching enabled. **Arguments:** * `font`: A static byte slice representing the font data (e.g., TTF file). ### `new_with_quality` Creates a new `MeshGenerator` with specified quality settings and caching enabled. **Arguments:** * `font`: A static byte slice representing the font data. * `quality`: The `QualitySettings` to be used for rasterization. ### `new_without_cache` Creates a new `MeshGenerator` with specified quality settings and caching disabled. **Arguments:** * `font`: A static byte slice representing the font data. * `quality`: The `QualitySettings` to be used for rasterization. ``` -------------------------------- ### Get BoundingBox size Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Calculates the extent of the bounding box along each axis. This is the absolute difference between the maximum and minimum coordinates for each dimension. ```rust pub fn size(&self) -> Vec3A { (self.max - self.min).abs() } ``` -------------------------------- ### Create MeshGenerator with Quality Settings Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshGenerator.html Creates a MeshGenerator with specified font and custom quality settings. ```rust pub fn new_with_quality(font: &'static [u8], quality: QualitySettings) -> Self ``` -------------------------------- ### Default BoundingBox Initialization Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Initializes a BoundingBox with default min and max values, typically centered around the origin. ```rust Self { max: Vec3A::new(-0.5f32, -0.5f32, -0.5f32), min: Vec3A::new(0.5f32, 0.5f32, 0.5f32), } ``` -------------------------------- ### Implement ToString for T Source: https://docs.rs/meshtext/latest/meshtext/error/struct.GlyphOutlineError.html Converts a value of type T into a String, provided T implements the Display trait. This is a convenient way to get a string representation of a value. ```rust fn to_string(&self) -> String ``` -------------------------------- ### BoundingBox::empty Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Creates a new, empty BoundingBox initialized with zero vectors. ```APIDOC ## BoundingBox::empty ### Description Creates a new empty [BoundingBox]. ### Method Associated function ### Returns - The empty [BoundingBox] with min and max set to Vec3A::ZERO. ``` -------------------------------- ### New MeshGenerator with Quality Settings Source: https://docs.rs/meshtext/latest/src/meshtext/mesh_generator.rs.html Creates a new MeshGenerator with custom quality settings. Requires font data and QualitySettings. ```rust pub fn new_with_quality(font: &'static [u8], quality: QualitySettings) -> Self { let face = ttf_parser::Face::parse(font, 0).expect("Failed to generate font from data."); Self { cache: HashMap::new(), font: face, indexed_cache: HashMap::new(), quality, use_cache: true, } } ``` -------------------------------- ### Calculate Point on Line Segment Source: https://docs.rs/meshtext/latest/src/meshtext/util/outline_builder.rs.html Calculates the coordinates of a point on a line segment given a normalized distance `t` from the start. Used as a helper for spline interpolation. ```rust fn point_on_line(a: &Point, b: &Point, t: f32) -> Point { (a.0 - (a.0 - b.0) * t, a.1 - (a.1 - b.1) * t) } ``` -------------------------------- ### IndexedMeshText::new Constructor Source: https://docs.rs/meshtext/latest/src/meshtext/types/indexed_mesh_text.rs.html Creates a new IndexedMeshText instance. It calculates the bounding box from the provided vertices. Ensure indices and vertices are valid for mesh generation. ```rust pub fn new(indices: Vec, vertices: Vec) -> Result> { let bbox = BoundingBox::from_vertices(&vertices)?; Ok(Self { bbox, indices, vertices, }) } ``` -------------------------------- ### Implement OutlineBuilder: close Source: https://docs.rs/meshtext/latest/src/meshtext/util/outline_builder.rs.html Closes the current contour by removing the duplicate last point and re-adding the start index. Adjusts the point count and index accordingly. ```rust fn close(&mut self) { // The last point is a duplicate so we remove it. // At this point there should be at least two points in the contour. let current_contour = self .contours .last_mut() .expect("Contour has no start point."); current_contour.pop(); current_contour.push(self.start_index); self.points.pop(); self.index -= 1; } ``` -------------------------------- ### Define QualitySettings struct and default implementation Source: https://docs.rs/meshtext/latest/src/meshtext/types/quality_settings.rs.html Defines the configuration for glyph generation quality and provides default values for interpolation steps. ```rust 1/// Controls the quality of generated glyphs. 2/// 3/// Generally each setting can be tweaked to generate better 4/// looking glyphs at the cost of a certain performance impact. 5#[derive(Debug, Clone, Copy)] 6pub struct QualitySettings { 7 /// The number of linear interpolation steps performed 8 /// on a _quadratic Bézier curve_. 9 /// 10 /// If the specified font does not use _quadratic splines_ 11 /// this setting will have no effect. 12 /// 13 /// Higher values result in higher polygon count. 14 pub quad_interpolation_steps: u32, 15 16 /// The number of quadratic interpolation steps performed 17 /// on a _cubic Bézier curve_. 18 /// 19 /// If the specified font does not use _cubic splines_ 20 /// this setting will have no effect. 21 /// 22 /// Higher values result in higher polygon count. 23 pub cubic_interpolation_steps: u32, 24} 25 26impl Default for QualitySettings { 27 fn default() -> Self { 28 Self { 29 quad_interpolation_steps: 5, 30 cubic_interpolation_steps: 3, 31 } 32 } 33} ``` -------------------------------- ### New MeshGenerator Source: https://docs.rs/meshtext/latest/src/meshtext/mesh_generator.rs.html Creates a new MeshGenerator with default quality settings. Requires font data as a static byte slice. ```rust pub fn new(font: &'static [u8]) -> Self { let face = ttf_parser::Face::parse(font, 0).expect("Failed to generate font from data."); Self { cache: HashMap::new(), font: face, indexed_cache: HashMap::new(), quality: QualitySettings::default(), use_cache: true, } } ``` -------------------------------- ### QualitySettings Struct Source: https://docs.rs/meshtext/latest/src/meshtext/types/quality_settings.rs.html Configuration structure for defining the interpolation quality of quadratic and cubic Bézier curves during glyph generation. ```APIDOC ## Struct: QualitySettings ### Description Controls the quality of generated glyphs. Each setting can be tweaked to generate better looking glyphs at the cost of a performance impact. ### Fields - **quad_interpolation_steps** (u32) - The number of linear interpolation steps performed on a quadratic Bézier curve. Higher values result in higher polygon count. - **cubic_interpolation_steps** (u32) - The number of quadratic interpolation steps performed on a cubic Bézier curve. Higher values result in higher polygon count. ### Default Values - **quad_interpolation_steps**: 5 - **cubic_interpolation_steps**: 3 ``` -------------------------------- ### IndexedMeshText::new Source: https://docs.rs/meshtext/latest/meshtext/struct.IndexedMeshText.html Creates a new instance of IndexedMeshText using provided indices and vertices. ```APIDOC ## POST /IndexedMeshText/new ### Description Creates a new IndexedMeshText instance from a set of indices and vertices. ### Parameters #### Request Body - **indices** (Vec) - Required - The indices used to construct a triangle mesh from the supplied vertices. - **vertices** (Vec) - Required - The vertices forming the mesh. Each vertex is composed of three f32 values in the order XYZ. ### Response #### Success Response (200) - **IndexedMeshText** (Object) - The newly created mesh data structure. #### Error Response - **MeshTextError** - Returned if the operation fails. ``` -------------------------------- ### Outline Glyph and Get Bounding Box in Rust Source: https://docs.rs/meshtext/latest/meshtext/struct.Face.html Outlines a glyph and returns its tight bounding box. This method is affected by variation axes and supports multiple font tables. Ensure to validate the OutlineBuilder's output as it may emit segments even for malformed outlines. ```rust use std::fmt::Write; use ttf_parser; struct Builder(String); impl ttf_parser::OutlineBuilder for Builder { fn move_to(&mut self, x: f32, y: f32) { write!(&mut self.0, "M {} {} ", x, y).unwrap(); } fn line_to(&mut self, x: f32, y: f32) { write!(&mut self.0, "L {} {} ", x, y).unwrap(); } fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) { write!(&mut self.0, "Q {} {} {} {} ", x1, y1, x, y).unwrap(); } fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) { write!(&mut self.0, "C {} {} {} {} {} {} ", x1, y1, x2, y2, x, y).unwrap(); } fn close(&mut self) { write!(&mut self.0, "Z ").unwrap(); } } let data = std::fs::read("tests/fonts/demo.ttf").unwrap(); let face = ttf_parser::Face::parse(&data, 0).unwrap(); let mut builder = Builder(String::new()); let bbox = face.outline_glyph(ttf_parser::GlyphId(1), &mut builder).unwrap(); assert_eq!(builder.0, "M 173 267 L 369 267 L 270 587 L 173 267 Z M 6 0 L 224 656 L 320 656 L 541 0 L 452 0 L 390 200 L 151 200 L 85 0 L 6 0 Z "); assert_eq!(bbox, ttf_parser::Rect { x_min: 6, y_min: 0, x_max: 541, y_max: 656 }); ``` -------------------------------- ### Generate Text Section Methods Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshGenerator.html Methods for generating meshes from strings of text, supporting both 2D and 3D transformations. ```rust fn generate_section( &mut self, text: &str, flat: bool, transform: Option<&[f32; 16]>, ) -> Result> ``` ```rust fn generate_section_2d( &mut self, text: &str, transform: Option<&[f32; 9]>, ) -> Result> ``` ```rust fn generate_section( &mut self, text: &str, flat: bool, transform: Option<&[f32; 16]>, ) -> Result> ``` ```rust fn generate_section_2d( &mut self, text: &str, transform: Option<&[f32; 9]>, ) -> Result> ``` -------------------------------- ### Implement CloneToUninit for Generic Type T (Nightly) Source: https://docs.rs/meshtext/latest/meshtext/enum.CacheType.html An experimental, nightly-only API that implements CloneToUninit for a generic type T that implements Clone. It allows copying data to an uninitialized memory location. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### make_flat_bbox Source: https://docs.rs/meshtext/latest/src/meshtext/util/mesh_to_flat_2d.rs.html Converts any BoundingBox to a flat BoundingBox by setting Z components to 0. ```APIDOC ## make_flat_bbox ### Description Converts any [BoundingBox] to a **flat** [BoundingBox]. Essentially sets all z-components to `0`. ### Method (Not applicable - this is a Rust function) ### Endpoint (Not applicable - this is a Rust function) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body - **bbox** (BoundingBox) - Required - The original [BoundingBox] which might have an extent in the z-direction. ### Request Example (Not applicable - this is a Rust function) ### Response #### Success Response (200) - **BoundingBox** (BoundingBox) - A **flat** [BoundingBox] that has no depth. #### Response Example (Not applicable - this is a Rust function) ``` -------------------------------- ### Create BoundingBox from vertices Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Constructs a BoundingBox that encloses a given set of vertices. It handles cases with insufficient vertices by returning an empty box and validates that the vertex data is a multiple of 3 components. Returns a MeshTextError if the vertex data is invalid. ```rust pub(crate) fn from_vertices(vertices: &[f32]) -> Result> { let component_count = vertices.len(); // There must be at least one vertex present to form a bounding box that is not empty. if component_count < 3 { return Ok(BoundingBox::empty()); } if !component_count.is_multiple_of(3) { return Err(Box::new(VertexError)); } let origin = Vec3A::new(vertices[0], vertices[1], vertices[2]); let mut bbox = BoundingBox::new(origin, origin); for vertex in vertices .chunks_exact(3) .map(|v| Vec3A::new(v[0], v[1], v[2])) { bbox.max = bbox.max.max(vertex); bbox.min = bbox.min.min(vertex); } Ok(bbox) } ``` -------------------------------- ### Query font properties Source: https://docs.rs/meshtext/latest/meshtext/struct.Face.html Methods to inspect font characteristics like style, weight, and metrics. ```rust pub fn names(&self) -> Names<'a> ``` ```rust pub fn is_regular(&self) -> bool ``` ```rust pub fn is_italic(&self) -> bool ``` ```rust pub fn is_bold(&self) -> bool ``` ```rust pub fn is_oblique(&self) -> bool ``` ```rust pub fn style(&self) -> Style ``` ```rust pub fn is_monospaced(&self) -> bool ``` ```rust pub fn is_variable(&self) -> bool ``` ```rust pub fn weight(&self) -> Weight ``` ```rust pub fn width(&self) -> Width ``` ```rust pub fn italic_angle(&self) -> f32 ``` ```rust pub fn ascender(&self) -> i16 ``` ```rust pub fn descender(&self) -> i16 ``` ```rust pub fn height(&self) -> i16 ``` ```rust pub fn line_gap(&self) -> i16 ``` ```rust pub fn typographic_ascender(&self) -> Option ``` -------------------------------- ### Data Structures Source: https://docs.rs/meshtext/latest/index.html Overview of the core structs used to hold generated mesh data and configuration. ```APIDOC ## Structs - **BoundingBox**: A bounding box or bounding rectangle in the case of a flat mesh. - **Face**: A font face. - **IndexedMeshText**: Holds the generated mesh data for the given text input. - **MeshText**: Holds the generated mesh data for the given text input. - **QualitySettings**: Controls the quality of generated glyphs. ``` -------------------------------- ### Implement Any for T Source: https://docs.rs/meshtext/latest/meshtext/error/struct.GlyphOutlineError.html Provides runtime type information for any type T. This is a blanket implementation useful for dynamic trait object handling. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### BoundingBox::from_vertices Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Constructs a BoundingBox that encloses a given set of vertices. ```APIDOC ## BoundingBox::from_vertices ### Description Creates a new [BoundingBox] enclosing the given `vertices`. ### Method Associated function ### Parameters #### Arguments - **vertices** ([]f32) - Required - The vertices forming a mesh around which the bounding box is constructed. Expected to be a flat array of floats representing (x, y, z) coordinates. ### Returns - Result> - The new [BoundingBox] or a [MeshTextError] if the input vertices are invalid (e.g., not a multiple of 3 components). ``` -------------------------------- ### TriangleMesh Implementations Source: https://docs.rs/meshtext/latest/meshtext/trait.TriangleMesh.html Shows the types that implement the TriangleMesh trait. ```APIDOC ### Implementors #### `impl TriangleMesh for IndexedMeshText` #### `impl TriangleMesh for MeshText` ``` -------------------------------- ### Create MeshGenerator Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshGenerator.html Instantiates a MeshGenerator for a given font. Each MeshGenerator supports only one font. ```rust pub struct MeshGenerator where T: FontFace, { /* private fields */ } ``` -------------------------------- ### Implement OutlineBuilder: line_to Source: https://docs.rs/meshtext/latest/src/meshtext/util/outline_builder.rs.html Handles the 'line_to' command, adding the current point's index to the last contour and then adding the point itself. ```rust fn line_to(&mut self, x: f32, y: f32) { self.contours.last_mut().unwrap().push(self.index); self.add_point((x, y)); } ``` -------------------------------- ### Create New MeshText Instance Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshText.html Constructs a new MeshText instance from a vector of vertices. Ensure vertices are in XYZ order; for flat meshes, the Z component should be zero. ```rust pub fn new(vertices: Vec) -> Result> ``` -------------------------------- ### QualitySettings Struct Source: https://docs.rs/meshtext/latest/meshtext/struct.QualitySettings.html Configuration settings for controlling the quality of generated glyphs in the meshtext library. ```APIDOC ## QualitySettings ### Description Controls the quality of generated glyphs. Each setting can be tweaked to generate better looking glyphs at the cost of a certain performance impact. ### Fields - **quad_interpolation_steps** (u32) - The number of linear interpolation steps performed on a quadratic Bézier curve. If the font does not use quadratic splines, this has no effect. - **cubic_interpolation_steps** (u32) - The number of quadratic interpolation steps performed on a cubic Bézier curve. If the font does not use cubic splines, this has no effect. ``` -------------------------------- ### Generate Glyph Mesh Methods Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshGenerator.html Methods for generating meshes from individual characters, supporting both 2D and 3D transformations. ```rust fn generate_glyph( &mut self, glyph: char, flat: bool, transform: Option<&[f32; 16]>, ) -> Result> ``` ```rust fn generate_glyph_2d( &mut self, glyph: char, transform: Option<&[f32; 9]>, ) -> Result> ``` ```rust fn generate_glyph( &mut self, glyph: char, flat: bool, transform: Option<&[f32; 16]>, ) -> Result> ``` ```rust fn generate_glyph_2d( &mut self, glyph: char, transform: Option<&[f32; 9]>, ) -> Result> ``` -------------------------------- ### Generate 2D Section (IndexedMeshText) Source: https://docs.rs/meshtext/latest/src/meshtext/mesh_generator.rs.html Generates a 2D text section for IndexedMeshText. Requires a transformation matrix. ```rust self.generate_section_2d(text, transform) ``` -------------------------------- ### BoundingBox::combine Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Combines the current bounding box with another bounding box into a new, larger bounding box. ```APIDOC ## BoundingBox::combine ### Description Combines this and another [BoundingBox] into a new one and returns it. ### Method Instance method ### Parameters #### Arguments - **other** (&BoundingBox) - Required - The [BoundingBox] with which this bounding box will be combined. ### Returns - BoundingBox - The combined [BoundingBox]. ### Example ```rust use glam::Vec3A; use meshtext::BoundingBox; let bbox1 = BoundingBox::new( Vec3A::new(0f32, 0f32, 0f32), Vec3A::new(1f32, 1f32, 1f32), ); let bbox2 = BoundingBox::new( Vec3A::new(2f32, 2f32, 0f32), Vec3A::new(3f32, 3f32, 1f32), ); let combination = BoundingBox::new( Vec3A::new(0f32, 0f32, 0f32), Vec3A::new(3f32, 3f32, 1f32), ); assert_eq!(bbox1.combine(&bbox2), combination); ``` ``` -------------------------------- ### BoundingBox Struct API Source: https://docs.rs/meshtext/latest/meshtext/struct.BoundingBox.html Methods for interacting with the BoundingBox struct. ```APIDOC ## BoundingBox ### Description A bounding box or bounding rectangle in the case of a flat mesh. ### Fields - **max** (Vec3A) - The coordinates of the maximum point. - **min** (Vec3A) - The coordinates of the minimum point. ### Methods - **new(min: Vec3A, max: Vec3A) -> Self** Creates a new BoundingBox. - **center(&self) -> Vec3A** Calculates the center of this BoundingBox. - **combine(&self, other: &BoundingBox) -> BoundingBox** Combines this and another BoundingBox into a new one. - **size(&self) -> Vec3A** Gets the size of this BoundingBox. - **transform(&mut self, transformation: &Mat4)** Applies the given transformation to this BoundingBox. ``` -------------------------------- ### Generate 2D Glyph (IndexedMeshText) Source: https://docs.rs/meshtext/latest/src/meshtext/mesh_generator.rs.html Generates a 2D glyph as IndexedMeshText. Requires a transformation matrix. ```rust self.generate_glyph_indexed_2d(glyph, transform) ``` -------------------------------- ### Transform BoundingBox with 2D Matrix Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Applies a 2D transformation matrix to the X and Y components of a BoundingBox, setting the Z component to 0. Requires the `glam` crate. ```rust let mut min = glam::Vec2::new(self.min.x, self.min.y); let mut max = glam::Vec2::new(self.max.x, self.max.y); min = transformation.transform_point2(min); max = transformation.transform_point2(max); self.min = Vec3A::new(min.x, min.y, 0f32); self.max = Vec3A::new(max.x, max.y, 0f32); ``` -------------------------------- ### Convert 3D Mesh and Bounding Box to 2D Source: https://docs.rs/meshtext/latest/src/meshtext/util/mesh_to_flat_2d.rs.html Functions to transform 3D mesh data into 2D equivalents by extracting x and y coordinates and flattening bounding boxes. ```rust 1use glam::{Vec2, Vec3A}; 2 3use crate::BoundingBox; 4 5type Mesh = (Vec, BoundingBox); 6type Mesh2D = (Vec, BoundingBox); 7 8type IndexedMesh = (Vec, Vec, BoundingBox); 9type IndexedMesh2D = (Vec, Vec, BoundingBox); 10 11/// Converts a [Mesh] composed of three-component vertices to 12/// a mesh composed of two-component vertices. 13/// 14/// Arguments: 15/// 16/// * `mesh_3d`: The original mesh using three-component vertices. 17/// 18/// Returns: 19/// 20/// A [Mesh2D] that is composed of two-component vertices. 21pub(crate) fn mesh_to_flat_2d(mesh_3d: Mesh) -> Mesh2D { 22 let positions = mesh_3d.0; 23 let mut positions_2d = Vec::new(); 24 25 for pos in positions.iter() { 26 positions_2d.push(Vec2::new(pos.x, pos.y)) 27 } 28 29 let bounding_rect = make_flat_bbox(&mesh_3d.1); 30 31 (positions_2d, bounding_rect) 32} 33 34/// Converts an [IndexedMesh] composed of three-component vertices to 35/// a mesh composed of two-component vertices. 36/// 37/// Arguments: 38/// 39/// * `mesh_3d`: The original indexed mesh using three-component vertices. 40/// 41/// Returns: 42/// 43/// A [IndexedMesh2D] that is composed of two-component vertices. 44pub(crate) fn mesh_to_indexed_flat_2d(mesh_3d: IndexedMesh) -> IndexedMesh2D { 45 let positions = mesh_3d.1; 46 let mut positions_2d = Vec::new(); 47 48 for pos in positions.iter() { 49 positions_2d.push(Vec2::new(pos.x, pos.y)) 50 } 51 52 let bounding_rect = make_flat_bbox(&mesh_3d.2); 53 54 (mesh_3d.0, positions_2d, bounding_rect) 55} 56 57/// Converts any [BoundingBox] to a **flat** [BoundingBox]. 58/// 59/// Essentially sets all z-components to `0`. 60/// 61/// Arguments: 62/// 63/// * `bbox`: The original [BoundingBox] which might have an extent in 64/// the z-direction. 65/// 66/// Returns: 67/// 68/// A **flat** [BoundingBox] that has no depth. 69fn make_flat_bbox(bbox: &BoundingBox) -> BoundingBox { 70 BoundingBox::new( 71 Vec3A::new(bbox.min.x, bbox.min.y, 0f32), 72 Vec3A::new(bbox.max.x, bbox.max.y, 0f32), 73 ) 74} ``` -------------------------------- ### Generate Section (IndexedMeshText) Source: https://docs.rs/meshtext/latest/src/meshtext/mesh_generator.rs.html Generates a text section for IndexedMeshText. Supports flat and non-flat generation with an optional transform. ```rust self.generate_section(text, flat, transform) ``` -------------------------------- ### POST /paint_color_glyph Source: https://docs.rs/meshtext/latest/meshtext/struct.Face.html Paints a color glyph from the COLR table using specified palette and foreground color. ```APIDOC ## POST /paint_color_glyph ### Description Paints a color glyph from the COLR table. If the glyph has no COLR definition, this method returns None. ### Method POST ### Parameters #### Request Body - **glyph_id** (GlyphId) - Required - The ID of the glyph to paint. - **palette** (u16) - Required - The palette index to use. - **foreground_color** (RgbaColor) - Required - The foreground color to apply. - **painter** (Painter) - Required - The painter instance to use for rendering. ### Response #### Success Response (200) - **result** (Option<()>) - Returns None if the glyph has no COLR definition or is malformed. ``` -------------------------------- ### Combine two BoundingBoxes Source: https://docs.rs/meshtext/latest/src/meshtext/types/bounding_box.rs.html Merges the current BoundingBox with another one to create a new BoundingBox that encompasses both. The resulting box will have the minimum bounds of both and the maximum bounds of both. ```rust pub fn combine(&self, other: &BoundingBox) -> BoundingBox { BoundingBox::new(self.min.min(other.min), self.max.max(other.max)) } ``` -------------------------------- ### Precache Glyphs Source: https://docs.rs/meshtext/latest/meshtext/struct.MeshGenerator.html Fills the internal cache with specified characters. Call twice with `flat` set to `true` and `false` to pre-cache both variants. ```rust use meshtext::MeshGenerator; let font_data = include_bytes!("../assets/font/FiraMono-Regular.ttf"); let mut generator = MeshGenerator::new(font_data); let common = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".to_string(); // Pre-cache both flat and three-dimensional glyphs both for indexed and non-indexed meshes. generator.precache_glyphs(&common, false, None); generator.precache_glyphs(&common, true, None); ``` -------------------------------- ### glam_vecs_from_raw Source: https://docs.rs/meshtext/latest/src/meshtext/util/glam_conversions.rs.html Converts a raw vector of f32 components into a vector of glam::Vec3A. ```APIDOC ## glam_vecs_from_raw ### Description Converts a raw vector of f32 components (assumed to be in chunks of 3 for x, y, z) into a vector of `glam::Vec3A`. ### Method Rust Function ### Endpoint meshtext/util/glam_conversions.rs ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **raw** (Vec) - Required - A vector of f32 representing the components of 3D vectors. ### Request Example ```rust let raw_data = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]; let glam_vectors = glam_vecs_from_raw(raw_data); // glam_vectors will be vec![Vec3A::new(1.0, 2.0, 3.0), Vec3A::new(4.0, 5.0, 6.0)] ``` ### Response #### Success Response (Vec) - **glam_vecs** (Vec) - A vector of `glam::Vec3A` created from the raw data. #### Response Example ```rust // Example output for input vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0] vec![glam::Vec3A::new(1.0, 2.0, 3.0), glam::Vec3A::new(4.0, 5.0, 6.0)] ``` ``` -------------------------------- ### Generate 2D Text Section (MeshText) Source: https://docs.rs/meshtext/latest/src/meshtext/mesh_generator.rs.html Generates a 2D text section for MeshText. Requires a transformation matrix. ```rust self.generate_text_section_2d(text, transform) ```