pub struct Font<'a> {
pub filename: &'a str,
pub data_lines: Vec<&'a str>,
pub span: Span,
}Expand description
Embedded font from [Fonts\] section
Represents a font file embedded in the ASS script using UU-encoding. Provides lazy decoding to avoid processing overhead unless the font data is actually needed.
§Examples
use ass_core::parser::ast::{Font, Span};
let font = Font {
filename: "custom.ttf",
data_lines: vec!["begin 644 custom.ttf", "M'XL..."],
span: Span::new(0, 0, 0, 0),
};
// Decode when needed
let decoded = font.decode_data()?;Fields§
§filename: &'a strFont filename as it appears in the [Fonts\] section
data_lines: Vec<&'a str>UU-encoded font data lines as zero-copy spans
span: SpanSpan in source text where this font is defined
Implementations§
Source§impl Font<'_>
impl Font<'_>
Sourcepub fn decode_data(&self) -> Result<Vec<u8>, CoreError>
pub fn decode_data(&self) -> Result<Vec<u8>, CoreError>
Decode UU-encoded font data with lazy evaluation
Converts the UU-encoded data lines to raw binary font data. This is expensive so it’s only done when explicitly requested.
§Returns
Decoded binary font data on success, error if UU-decoding fails
§Errors
Returns an error if the UU-encoded data is malformed or cannot be decoded.
§Examples
match font.decode_data() {
Ok(data) => println!("Font size: {} bytes", data.len()),
Err(e) => eprintln!("Decode error: {}", e),
}Sourcepub fn to_ass_string(&self) -> String
pub fn to_ass_string(&self) -> String
Convert font to ASS string representation
Generates the font entry as it appears in the [Fonts\] section.
§Examples
let font = Font {
filename: "custom.ttf",
data_lines: vec!["begin 644 custom.ttf", "M'XL...", "end"],
span: Span::new(0, 0, 0, 0),
};
let ass_string = font.to_ass_string();
assert!(ass_string.starts_with("fontname: custom.ttf\n"));
assert!(ass_string.contains("M'XL..."));Sourcepub fn validate_spans(&self, source_range: &Range<usize>) -> bool
pub fn validate_spans(&self, source_range: &Range<usize>) -> bool
Validate all spans in this Font reference valid source
Debug helper to ensure zero-copy invariants are maintained. Validates that filename and all data line references point to memory within the specified source range.
Only available in debug builds to avoid performance overhead.