pub(crate) mod paint;
use std::borrow::Cow;
use std::fmt;
use std::io::Write;
use std::ops::Deref;
use std::str::FromStr;
use fontique::Blob as FontiqueBlob;
use jiff::civil::Date;
use jiff::fmt::strtime::BrokenDownTime;
pub(crate) use paint::annotations::LinkAnnotation;
use paint::annotations::RenderedLink;
use paint::display_list::PagePaintTree;
pub(crate) use paint::geometry::PaintStrokeWidth;
use paint::geometry::{PaintPoint, PaintSize};
use paint::images::RenderedImage;
use paint::page::{OpaqueTextCoverage, PaintOperation, SvgTextOutline};
use paint::paths::{RenderedGradient, RenderedPath, RenderedPathPaint};
use paint::patterns::{RenderedGradientPattern, RenderedImagePattern, RenderedSvgPattern};
use paint::shapes::{RenderedRect, RenderedRoundedRect, RenderedStroke};
use paint::text::RenderedLine;
use crate::image_store::DocumentImageStore;
use crate::timing::DebugTimer;
use crate::{CssColor, Error, Result, pdf};
#[derive(Debug, Clone, PartialEq)]
pub struct Document {
pub(crate) pages: Vec<Page>,
pub(crate) metadata: DocumentMetadata,
pub(crate) fonts: Vec<DocumentFont>,
pub(crate) bookmarks: Vec<Bookmark>,
pub(crate) image_store: Box<DocumentImageStore>,
}
impl Document {
pub(crate) fn materialize_images_for_embedding(&mut self) {
for page in &mut self.pages {
for image in &mut page.images {
image.materialize_store_backing(&self.image_store);
}
}
}
pub fn metadata(&self) -> &DocumentMetadata {
&self.metadata
}
pub fn bookmarks(&self) -> &[Bookmark] {
&self.bookmarks
}
pub fn write_pdf<W: Write>(&self, writer: &mut W, options: &PdfOptions) -> Result<()> {
let _timer = DebugTimer::start(format!("writing {} page(s) to PDF", self.pages.len()));
if self.pages.is_empty() {
return Err(Error::InvalidInput("document has no pages".to_string()));
}
{
let _timer = DebugTimer::start("validating paint operations");
self.validate_paint_operations()?;
}
pdf::write_document(self, options, writer)
}
pub(crate) fn validate_paint_operations(&self) -> Result<()> {
for (page_index, page) in self.pages.iter().enumerate() {
page.validate_paint_operations(page_index)?;
}
Ok(())
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub enum PdfCompression {
#[default]
Compressed,
Uncompressed,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum FontEmbeddingMode {
#[default]
Subset,
Full,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub enum PdfProfile {
#[default]
Pdf,
PdfA1B,
}
impl PdfProfile {
pub const fn pdf_version(self) -> (u8, u8) {
match self {
Self::Pdf | Self::PdfA1B => (1, 4),
}
}
pub const fn is_pdfa(self) -> bool {
!matches!(self, Self::Pdf)
}
pub(crate) const fn pdfa_identification(self) -> Option<PdfAIdentification> {
match self {
Self::Pdf => None,
Self::PdfA1B => Some(PdfAIdentification {
part: 1,
conformance: "B",
}),
}
}
}
impl fmt::Display for PdfProfile {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(match self {
Self::Pdf => "pdf",
Self::PdfA1B => "pdf/a-1b",
})
}
}
impl FromStr for PdfProfile {
type Err = String;
fn from_str(value: &str) -> std::result::Result<Self, Self::Err> {
match value.to_ascii_lowercase().as_str() {
"pdf" => Ok(Self::Pdf),
"pdf/a-1b" => Ok(Self::PdfA1B),
_ => Err(format!(
"unsupported PDF profile {value:?}; expected one of pdf, pdf/a-1b"
)),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct PdfAIdentification {
pub part: u8,
pub conformance: &'static str,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PdfOptions {
pub profile: PdfProfile,
pub font_embedding: FontEmbeddingMode,
pub compression: PdfCompression,
pub producer: String,
}
impl Default for PdfOptions {
fn default() -> Self {
Self {
profile: PdfProfile::default(),
font_embedding: FontEmbeddingMode::default(),
compression: PdfCompression::default(),
producer: "spindrift 0.1.0".to_string(),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct DocumentMetadata {
pub(crate) title: Option<String>,
pub(crate) author: Option<String>,
pub(crate) creator: Option<String>,
pub(crate) language: Option<String>,
pub(crate) description: Option<String>,
pub(crate) keywords: Vec<String>,
pub(crate) created: Option<DocumentDate>,
pub(crate) modified: Option<DocumentDate>,
}
impl DocumentMetadata {
pub(crate) fn has_source_metadata(&self) -> bool {
self.title.is_some()
|| self.author.is_some()
|| self.creator.is_some()
|| self.language.is_some()
|| self.description.is_some()
|| !self.keywords.is_empty()
|| self.created.is_some()
|| self.modified.is_some()
}
pub fn title(&self) -> Option<&str> {
self.title.as_deref()
}
pub fn author(&self) -> Option<&str> {
self.author.as_deref()
}
pub fn creator(&self) -> Option<&str> {
self.creator.as_deref()
}
pub fn language(&self) -> Option<&str> {
self.language.as_deref()
}
pub fn description(&self) -> Option<&str> {
self.description.as_deref()
}
pub fn keywords(&self) -> &[String] {
&self.keywords
}
pub fn created(&self) -> Option<&DocumentDate> {
self.created.as_ref()
}
pub fn modified(&self) -> Option<&DocumentDate> {
self.modified.as_ref()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DocumentDate {
source: String,
components: DocumentDateComponents,
}
#[derive(Debug, Clone, PartialEq, Eq)]
enum DocumentDateComponents {
Year {
year: u16,
},
YearMonth {
year: u16,
month: u8,
},
Date {
year: u16,
month: u8,
day: u8,
},
DateTime {
year: u16,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
offset_seconds: i32,
offset_is_negative: bool,
},
}
impl DocumentDate {
pub fn as_str(&self) -> &str {
&self.source
}
pub(crate) fn parse(source: String) -> Option<Self> {
let value = source.trim_matches(is_html_space);
is_w3c_iso_8601_profile_form(value)?;
let datetime_value = value
.strip_suffix('Z')
.map(|prefix| format!("{prefix}+00:00"))
.unwrap_or_else(|| value.to_string());
let offset_is_negative = datetime_value
.as_bytes()
.get(datetime_value.len().saturating_sub(6))
.is_some_and(|sign| *sign == b'-');
if let Some(components) = Self::parse_datetime(
&datetime_value,
"%Y-%m-%dT%H:%M:%S%.f%:z",
offset_is_negative,
) {
return Some(Self { source, components });
}
if let Some(components) =
Self::parse_datetime(&datetime_value, "%Y-%m-%dT%H:%M%:z", offset_is_negative)
{
return Some(Self { source, components });
}
if let Some(components) = Self::parse_date(value, "%F") {
return Some(Self { source, components });
}
if let Some(components) = Self::parse_year_month(value) {
return Some(Self { source, components });
}
Self::parse_year(value).map(|components| Self { source, components })
}
pub(crate) fn pdf_info_value(&self) -> String {
match self.components {
DocumentDateComponents::Year { year } => format!("D:{year:04}"),
DocumentDateComponents::YearMonth { year, month } => {
format!("D:{year:04}{month:02}")
}
DocumentDateComponents::Date { year, month, day } => {
format!("D:{year:04}{month:02}{day:02}")
}
DocumentDateComponents::DateTime {
year,
month,
day,
hour,
minute,
second,
offset_seconds,
offset_is_negative,
} => {
let offset = if offset_seconds == 0 && !offset_is_negative {
"Z".to_string()
} else {
let sign = if offset_seconds < 0 || offset_is_negative {
'-'
} else {
'+'
};
let offset_minutes = offset_seconds.unsigned_abs() / 60;
format!(
"{sign}{:02}'{:02}",
offset_minutes / 60,
offset_minutes % 60
)
};
format!("D:{year:04}{month:02}{day:02}{hour:02}{minute:02}{second:02}{offset}")
}
}
}
fn parse_datetime(
value: &str,
format: &str,
offset_is_negative: bool,
) -> Option<DocumentDateComponents> {
let parsed = BrokenDownTime::parse(format, value).ok()?;
let (year, month, day) = parsed_date_parts(&parsed)?;
Date::new(
i16::try_from(year).ok()?,
i8::try_from(month).ok()?,
i8::try_from(day).ok()?,
)
.ok()?;
Some(DocumentDateComponents::DateTime {
year,
month,
day,
hour: u8::try_from(parsed.hour()?).ok()?,
minute: u8::try_from(parsed.minute()?).ok()?,
second: u8::try_from(parsed.second().unwrap_or(0)).ok()?,
offset_seconds: parsed.offset()?.seconds(),
offset_is_negative,
})
}
fn parse_date(value: &str, format: &str) -> Option<DocumentDateComponents> {
let parsed = BrokenDownTime::parse(format, value).ok()?;
let (year, month, day) = parsed_date_parts(&parsed)?;
Date::new(
i16::try_from(year).ok()?,
i8::try_from(month).ok()?,
i8::try_from(day).ok()?,
)
.ok()?;
Some(DocumentDateComponents::Date { year, month, day })
}
fn parse_year_month(value: &str) -> Option<DocumentDateComponents> {
let parsed = BrokenDownTime::parse("%Y-%m", value).ok()?;
Some(DocumentDateComponents::YearMonth {
year: u16::try_from(parsed.year()?).ok()?,
month: u8::try_from(parsed.month()?).ok()?,
})
}
fn parse_year(value: &str) -> Option<DocumentDateComponents> {
let parsed = BrokenDownTime::parse("%Y", value).ok()?;
Some(DocumentDateComponents::Year {
year: u16::try_from(parsed.year()?).ok()?,
})
}
}
impl fmt::Display for DocumentDate {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
fn parsed_date_parts(parsed: &BrokenDownTime) -> Option<(u16, u8, u8)> {
Some((
u16::try_from(parsed.year()?).ok()?,
u8::try_from(parsed.month()?).ok()?,
u8::try_from(parsed.day()?).ok()?,
))
}
fn is_html_space(character: char) -> bool {
matches!(character, ' ' | '\t' | '\n' | '\u{000C}' | '\r')
}
fn is_w3c_iso_8601_profile_form(value: &str) -> Option<()> {
fn digits(value: &[u8]) -> bool {
value.iter().all(u8::is_ascii_digit)
}
let bytes = value.as_bytes();
match bytes.len() {
4 if digits(bytes) => Some(()),
7 if digits(&bytes[..4]) && bytes[4] == b'-' && digits(&bytes[5..]) => Some(()),
10 if digits(&bytes[..4])
&& bytes[4] == b'-'
&& digits(&bytes[5..7])
&& bytes[7] == b'-'
&& digits(&bytes[8..]) =>
{
Some(())
}
_ => is_w3c_iso_8601_profile_datetime_form(bytes),
}
}
fn is_w3c_iso_8601_profile_datetime_form(bytes: &[u8]) -> Option<()> {
if bytes.len() < 17
|| !bytes[..4].iter().all(u8::is_ascii_digit)
|| bytes.get(4) != Some(&b'-')
|| !bytes[5..7].iter().all(u8::is_ascii_digit)
|| bytes.get(7) != Some(&b'-')
|| !bytes[8..10].iter().all(u8::is_ascii_digit)
|| bytes.get(10) != Some(&b'T')
|| !bytes[11..13].iter().all(u8::is_ascii_digit)
|| bytes.get(13) != Some(&b':')
|| !bytes[14..16].iter().all(u8::is_ascii_digit)
{
return None;
}
let time_end = match bytes.get(16) {
Some(b'Z') if bytes.len() == 17 => return Some(()),
Some(b'+') | Some(b'-') => 16,
Some(b':') if bytes.len() >= 19 && bytes[17..19].iter().all(u8::is_ascii_digit) => {
let mut end = 19;
if bytes.get(end) == Some(&b'.') {
end += 1;
let fraction_start = end;
while bytes.get(end).is_some_and(u8::is_ascii_digit) {
end += 1;
}
if end == fraction_start {
return None;
}
}
end
}
_ => return None,
};
match bytes.get(time_end..) {
Some([b'Z']) => Some(()),
Some(
[
sign @ (b'+' | b'-'),
hour_tens,
hour_ones,
b':',
minute_tens,
minute_ones,
],
) if sign.is_ascii()
&& hour_tens.is_ascii_digit()
&& hour_ones.is_ascii_digit()
&& minute_tens.is_ascii_digit()
&& minute_ones.is_ascii_digit() =>
{
Some(())
}
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::DocumentDate;
#[test]
fn metadata_dates_accept_w3c_iso_8601_profile_forms() {
let cases = [
("1997", "D:1997"),
("1997-07", "D:199707"),
("1997-07-16", "D:19970716"),
("1997-07-16T19:20+01:00", "D:19970716192000+01'00"),
("1997-07-16T19:20:30Z", "D:19970716192030Z"),
("1997-07-16T19:20:30.45-00:30", "D:19970716192030-00'30"),
];
for (source, expected_pdf_date) in cases {
let date = DocumentDate::parse(source.to_string()).expect("valid W3C profile date");
assert_eq!(date.as_str(), source);
assert_eq!(date.pdf_info_value(), expected_pdf_date);
}
}
#[test]
fn metadata_dates_reject_non_profile_values() {
for source in [
"1997-7-16",
"1997-07-16T19:20",
"1997-07-16T19:20:30+0100",
"1997-02-30",
] {
assert!(
DocumentDate::parse(source.to_string()).is_none(),
"{source:?} must not be accepted"
);
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Bookmark {
pub(crate) level: u32,
pub(crate) label: String,
pub(crate) page_index: usize,
target: PaintPoint,
pub(crate) state: BookmarkState,
}
impl Bookmark {
pub(crate) fn new(
level: u32,
label: String,
page_index: usize,
x: f32,
y: f32,
state: BookmarkState,
) -> Self {
Self {
level,
label,
page_index,
target: PaintPoint::new(x, y),
state,
}
}
pub(crate) fn replay_target(&self) -> PaintPoint {
self.target
}
pub(crate) fn set_replay_destination(&mut self, page_index: usize, target: PaintPoint) {
self.page_index = page_index;
self.target = target;
}
pub fn x(&self) -> f32 {
self.target.x
}
pub fn y(&self) -> f32 {
self.target.y
}
pub fn level(&self) -> u32 {
self.level
}
pub fn label(&self) -> &str {
&self.label
}
pub fn page_index(&self) -> usize {
self.page_index
}
pub fn state(&self) -> BookmarkState {
self.state
}
pub(crate) fn target(&self) -> PaintPoint {
self.target
}
pub(crate) fn translate_target(&mut self, x_offset: f32, y_offset: f32) {
self.target.x += x_offset;
self.target.y += y_offset;
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BookmarkState {
Open,
Closed,
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Page {
size: PaintSize,
pub(crate) rotation: i32,
pub(crate) rects: Vec<RenderedRect>,
pub(crate) rounded_rects: Vec<RenderedRoundedRect>,
pub(crate) paths: Vec<RenderedPath>,
pub(crate) strokes: Vec<RenderedStroke>,
pub(crate) lines: Vec<RenderedLine>,
pub(crate) links: Vec<RenderedLink>,
pub(crate) images: Vec<RenderedImage>,
pub(crate) svg_pattern_images: Vec<RenderedImage>,
pub(crate) image_patterns: Vec<RenderedImagePattern>,
pub(crate) gradient_patterns: Vec<RenderedGradientPattern>,
pub(crate) svg_patterns: Vec<RenderedSvgPattern>,
pub(crate) opaque_text_coverages: Vec<OpaqueTextCoverage>,
pub(crate) svg_text_outlines: Vec<SvgTextOutline>,
pub(crate) has_fragmentation_content: bool,
paint_tree: PagePaintTree,
}
#[allow(dead_code)]
impl Page {
pub(crate) fn new(width: f32, height: f32) -> Self {
Self {
size: PaintSize::new(width.max(0.0), height.max(0.0)),
rotation: 0,
rects: Vec::new(),
rounded_rects: Vec::new(),
paths: Vec::new(),
strokes: Vec::new(),
lines: Vec::new(),
links: Vec::new(),
images: Vec::new(),
svg_pattern_images: Vec::new(),
image_patterns: Vec::new(),
gradient_patterns: Vec::new(),
svg_patterns: Vec::new(),
opaque_text_coverages: Vec::new(),
svg_text_outlines: Vec::new(),
has_fragmentation_content: false,
paint_tree: PagePaintTree::new(),
}
}
pub(crate) fn width(&self) -> f32 {
self.size.width
}
pub(crate) fn height(&self) -> f32 {
self.size.height
}
pub(crate) fn operations(&self) -> Cow<'_, [PaintOperation]> {
Cow::Owned(self.paint_tree.flattened_operations())
}
pub(crate) fn rects(&self) -> &[RenderedRect] {
&self.rects
}
pub(crate) fn rounded_rects(&self) -> &[RenderedRoundedRect] {
&self.rounded_rects
}
pub(crate) fn paths(&self) -> &[RenderedPath] {
&self.paths
}
pub(crate) fn strokes(&self) -> &[RenderedStroke] {
&self.strokes
}
pub(crate) fn lines(&self) -> &[RenderedLine] {
&self.lines
}
pub(crate) fn links(&self) -> &[LinkAnnotation] {
&self.links
}
pub(crate) fn images(&self) -> &[RenderedImage] {
&self.images
}
pub(crate) fn image_patterns(&self) -> &[RenderedImagePattern] {
&self.image_patterns
}
pub(crate) fn gradient_patterns(&self) -> &[RenderedGradientPattern] {
&self.gradient_patterns
}
pub(crate) fn rotation(&self) -> i32 {
self.rotation
}
pub(crate) fn paint_size(&self) -> PaintSize {
self.size
}
pub(crate) fn has_paint_content(&self) -> bool {
!self.paint_tree.flattened_operations().is_empty()
}
pub(crate) fn has_transparency_group(&self) -> bool {
self.paint_tree.has_transparency_group()
}
pub(crate) fn mark_fragmentation_content(&mut self) {
self.has_fragmentation_content = true;
}
pub(crate) fn has_fragmentation_content(&self) -> bool {
self.has_fragmentation_content
}
pub(crate) fn vector_paint_colors(&self) -> Vec<CssColor> {
let mut colors = Vec::new();
for rect in &self.rects {
collect_optional_color(rect.fill, &mut colors);
collect_optional_color(rect.stroke, &mut colors);
}
for rect in &self.rounded_rects {
collect_optional_color(rect.fill, &mut colors);
collect_optional_color(rect.stroke, &mut colors);
}
for path in &self.paths {
collect_path_colors(path, &mut colors);
}
for stroke in &self.strokes {
colors.push(stroke.color);
}
for line in &self.lines {
colors.push(line.color);
}
for pattern in &self.gradient_patterns {
collect_gradient_colors(&pattern.gradient, &mut colors);
}
for pattern in &self.svg_patterns {
for path in &pattern.paths {
collect_path_colors(path, &mut colors);
}
}
colors
}
}
fn collect_optional_color(color: Option<CssColor>, colors: &mut Vec<CssColor>) {
if let Some(color) = color {
colors.push(color);
}
}
fn collect_gradient_colors(gradient: &RenderedGradient, colors: &mut Vec<CssColor>) {
colors.extend(gradient.stops.iter().map(|stop| stop.color));
if let Some(periodic) = &gradient.periodic {
colors.extend(periodic.stops.iter().map(|stop| stop.color));
}
}
fn collect_path_colors(path: &RenderedPath, colors: &mut Vec<CssColor>) {
collect_optional_color(path.fill, colors);
collect_optional_color(path.stroke, colors);
for paint in [path.fill_paint.as_ref(), path.stroke_paint.as_ref()]
.into_iter()
.flatten()
{
match paint {
RenderedPathPaint::Solid(color) => {
colors.push(*color);
}
RenderedPathPaint::Gradient(gradient) => collect_gradient_colors(gradient, colors),
RenderedPathPaint::SvgPattern(pattern) => {
collect_svg_scene_colors(&pattern.scene, colors);
}
}
}
}
fn collect_svg_scene_colors(scene: &crate::svg::SvgPaintGroup, colors: &mut Vec<CssColor>) {
for item in &scene.items {
match item {
crate::svg::SvgPaintItem::Path(path) => collect_path_colors(path, colors),
crate::svg::SvgPaintItem::Group(group) | crate::svg::SvgPaintItem::NestedSvg(group) => {
collect_svg_scene_colors(group, colors)
}
crate::svg::SvgPaintItem::OutlinedText(outlined) => {
collect_svg_scene_colors(&outlined.content, colors)
}
crate::svg::SvgPaintItem::RasterImage(_) => {}
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) enum FontProgramKind {
TrueType,
OpenTypeCff,
}
#[derive(Clone)]
pub(crate) struct DocumentFontData {
blob: FontiqueBlob<u8>,
}
#[allow(dead_code)]
impl DocumentFontData {
pub(crate) fn from_blob(blob: FontiqueBlob<u8>) -> Self {
Self { blob }
}
pub fn as_slice(&self) -> &[u8] {
self.blob.as_ref()
}
pub fn len(&self) -> usize {
self.blob.len()
}
pub fn is_empty(&self) -> bool {
self.blob.is_empty()
}
pub(crate) fn blob_id(&self) -> u64 {
self.blob.id()
}
}
impl AsRef<[u8]> for DocumentFontData {
fn as_ref(&self) -> &[u8] {
self.as_slice()
}
}
impl Deref for DocumentFontData {
type Target = [u8];
fn deref(&self) -> &Self::Target {
self.as_slice()
}
}
impl fmt::Debug for DocumentFontData {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter
.debug_struct("DocumentFontData")
.field("blob_id", &self.blob_id())
.field("len", &self.len())
.finish()
}
}
impl PartialEq for DocumentFontData {
fn eq(&self, other: &Self) -> bool {
self.blob == other.blob
}
}
impl Eq for DocumentFontData {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct OpenTypeVerticalMetrics {
pub(crate) ascender: i16,
pub(crate) descender: i16,
pub(crate) line_gap: i16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct CssFontVerticalMetrics {
pub(crate) ascender: i16,
pub(crate) descender: i16,
pub(crate) line_gap: i16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct SyntheticObliqueAngle(i8);
impl SyntheticObliqueAngle {
pub(crate) const fn from_fontique_degrees(degrees: i8) -> Option<Self> {
if degrees == 0 {
None
} else {
Some(Self(degrees))
}
}
pub(crate) const fn degrees(self) -> i8 {
self.0
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub(crate) struct DocumentFontSynthesis {
pub(crate) embolden: bool,
pub(crate) oblique: Option<SyntheticObliqueAngle>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
pub(crate) struct DocumentFontVariationCoordinates(pub(crate) Vec<([u8; 4], u32)>);
impl DocumentFontVariationCoordinates {
pub(crate) fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct OpenTypeBaselineCoordinate {
pub(crate) design_units: i16,
pub(crate) variation_index: Option<OpenTypeVariationIndex>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct OpenTypeVariationIndex {
pub(crate) outer: u16,
pub(crate) inner: u16,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct OpenTypeBaselineScript {
pub(crate) script: [u8; 4],
pub(crate) default_baseline: Option<[u8; 4]>,
pub(crate) coordinates: Vec<([u8; 4], OpenTypeBaselineCoordinate)>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub(crate) struct OpenTypeBaselineAxis {
pub(crate) scripts: Vec<OpenTypeBaselineScript>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub(crate) struct OpenTypeBaselineTable {
pub(crate) horizontal: OpenTypeBaselineAxis,
pub(crate) vertical: OpenTypeBaselineAxis,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct DocumentFont {
pub(crate) id: usize,
pub(crate) family: String,
pub(crate) post_script_name: String,
pub(crate) program_kind: FontProgramKind,
pub(crate) data: DocumentFontData,
pub(crate) face_index: u32,
pub(crate) units_per_em: u16,
pub(crate) program_metrics: OpenTypeVerticalMetrics,
pub(crate) layout_metrics: CssFontVerticalMetrics,
pub(crate) cap_height: i16,
pub(crate) italic_angle: i16,
pub(crate) bbox: [i16; 4],
pub(crate) baselines: OpenTypeBaselineTable,
pub(crate) variation_coordinates: DocumentFontVariationCoordinates,
pub(crate) synthesis: DocumentFontSynthesis,
}