From 3aa089f6d62908a38a874ba0c31383ba78eb6b47 Mon Sep 17 00:00:00 2001 From: Rod S Date: Fri, 21 Oct 2022 16:41:29 -0700 Subject: [PATCH] Drop BigEndian from codegen input --- font-codegen/Cargo.toml | 2 + font-codegen/src/fields.rs | 144 +++++--- font-codegen/src/lib.rs | 46 ++- font-codegen/src/main.rs | 14 +- font-codegen/src/parsing.rs | 267 +++++++++++++-- font-codegen/src/record.rs | 6 +- font-codegen/src/table.rs | 6 +- read-fonts/generated/generated_cmap.rs | 8 +- read-fonts/generated/generated_cpal.rs | 16 +- read-fonts/generated/generated_glyf.rs | 2 +- resources/codegen_inputs/cmap.rs | 154 ++++----- resources/codegen_inputs/colr.rs | 452 ++++++++++++------------- resources/codegen_inputs/cpal.rs | 26 +- resources/codegen_inputs/font.rs | 32 +- resources/codegen_inputs/gdef.rs | 54 +-- resources/codegen_inputs/glyf.rs | 42 +-- resources/codegen_inputs/gpos.rs | 154 ++++----- resources/codegen_inputs/gsub.rs | 88 ++--- resources/codegen_inputs/head.rs | 34 +- resources/codegen_inputs/hhea.rs | 34 +- resources/codegen_inputs/hmtx.rs | 6 +- resources/codegen_inputs/layout.rs | 278 +++++++-------- resources/codegen_inputs/maxp.rs | 30 +- resources/codegen_inputs/name.rs | 24 +- resources/codegen_inputs/post.rs | 22 +- resources/codegen_inputs/stat.rs | 84 ++--- resources/codegen_inputs/test.rs | 28 +- 27 files changed, 1182 insertions(+), 871 deletions(-) diff --git a/font-codegen/Cargo.toml b/font-codegen/Cargo.toml index 9006b9b21..c1f935e78 100644 --- a/font-codegen/Cargo.toml +++ b/font-codegen/Cargo.toml @@ -21,3 +21,5 @@ quote = "1.0" toml = "0.5" serde = {version = "1.0", features = ["derive"] } xflags = "0.2.4" +log = "0.4" +env_logger = "0.9.0" diff --git a/font-codegen/src/fields.rs b/font-codegen/src/fields.rs index d779fba70..c2d3ddda4 100644 --- a/font-codegen/src/fields.rs +++ b/font-codegen/src/fields.rs @@ -5,7 +5,7 @@ use std::ops::Deref; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; -use crate::parsing::{Attr, FieldValidation, OffsetTarget}; +use crate::parsing::{Attr, FieldValidation, OffsetTarget, Phase}; use super::parsing::{ Count, CustomCompile, Field, FieldReadArgs, FieldType, Fields, NeededWhen, Record, @@ -31,7 +31,7 @@ impl Fields { }) } - pub(crate) fn sanity_check(&self) -> syn::Result<()> { + pub(crate) fn sanity_check(&self, phase: Phase) -> syn::Result<()> { let mut custom_offset_data_fld: Option<&Field> = None; let mut normal_offset_data_fld = None; for (i, fld) in self.fields.iter().enumerate() { @@ -54,7 +54,7 @@ impl Fields { "#[count(..)] or VarLenArray fields can only be last field in table.", )); } - fld.sanity_check()?; + fld.sanity_check(phase)?; } if let (Some(custom), Some(normal)) = (custom_offset_data_fld, normal_offset_data_fld) { @@ -211,6 +211,13 @@ impl Fields { } } +fn big_endian(typ: &syn::Ident) -> TokenStream { + if typ == "u8" { + return quote!(#typ); + } + quote!(BigEndian<#typ>) +} + fn traversal_arm_for_field( fld: &Field, in_record: bool, @@ -227,7 +234,7 @@ fn traversal_arm_for_field( FieldType::Offset { target: Some(OffsetTarget::Array(inner)), .. - } if matches!(inner.deref(), FieldType::Other { .. }) => { + } if matches!(inner.deref(), FieldType::Struct { .. }) => { let typ = inner.cooked_type_tokens(); let getter = fld.offset_getter_name(); let offset_data = fld.offset_getter_data_src(); @@ -260,10 +267,10 @@ fn traversal_arm_for_field( FieldType::Array { inner_typ } => match inner_typ.as_ref() { FieldType::Scalar { .. } => quote!(Field::new(#name_str, self.#name()#maybe_unwrap)), //HACK: glyf has fields that are [u8] - FieldType::Other { typ } if typ.is_ident("u8") => { + FieldType::Struct { typ } if typ == "u8" => { quote!(Field::new( #name_str, self.#name()#maybe_unwrap)) } - FieldType::Other { typ } if !in_record => { + FieldType::Struct { typ } if !in_record => { let offset_data = fld.offset_getter_data_src(); quote!(Field::new( #name_str, @@ -306,9 +313,10 @@ fn traversal_arm_for_field( FieldType::Offset { target: Some(OffsetTarget::Array(_)), .. - } => quote!(compile_error!( - "achievement unlocked: 'added arrays of offsets to arrays to OpenType spec'" - )), + } => panic!( + "achievement unlocked: 'added arrays of offsets to arrays to OpenType spec' {:#?}", + fld + ), FieldType::Offset { .. } => quote!(Field::new(#name_str, self.#name()#maybe_unwrap)), _ => quote!(compile_error!("unhandled traversal case")), }, @@ -334,14 +342,32 @@ fn traversal_arm_for_field( FieldType::VarLenArray(_) => { quote!(Field::new(#name_str, traversal::FieldType::var_array(self.#name()#maybe_unwrap))) } - FieldType::Other { typ } if typ.is_ident("ValueRecord") => { + // HACK: who wouldn't want to hard-code ValueRecord handling + FieldType::Struct { typ } if typ == "ValueRecord" => { let clone = in_record.then(|| quote!(.clone())); quote!(Field::new(#name_str, self.#name() #clone #maybe_unwrap)) } - FieldType::Other { .. } => { + FieldType::Struct { .. } => { quote!(compile_error!(concat!("another weird type: ", #name_str))) } + FieldType::PendingResolution { .. } => panic!("Should have resolved {:#?}", fld), + } +} + +fn check_resolution(phase: Phase, field_type: &FieldType) -> syn::Result<()> { + if let Phase::Parse = phase { + return Ok(()); + } + if let FieldType::PendingResolution { typ } = field_type { + return Err(syn::Error::new( + typ.span(), + format!( + "{}: be ye struct or scalar? - we certainly don't know.", + typ + ), + )); } + Ok(()) } impl Field { @@ -350,8 +376,8 @@ impl Field { FieldType::Offset { typ, .. } if self.is_nullable() => { quote!(BigEndian>) } - FieldType::Offset { typ, .. } | FieldType::Scalar { typ } => quote!(BigEndian<#typ>), - FieldType::Other { typ } => typ.to_token_stream(), + FieldType::Offset { typ, .. } | FieldType::Scalar { typ } => big_endian(typ), + FieldType::Struct { typ } => typ.to_token_stream(), FieldType::ComputedArray(array) => { let inner = array.type_with_lifetime(); quote!(ComputedArray<'a, #inner>) @@ -362,11 +388,18 @@ impl Field { quote!(&'a [BigEndian>]) } FieldType::Offset { typ, .. } | FieldType::Scalar { typ } => { - quote!(&'a [BigEndian<#typ>]) + let be = big_endian(typ); + quote!(&'a [#be]) + } + FieldType::Struct { typ } => quote!( &[#typ] ), + FieldType::PendingResolution { typ } => { + panic!("Should have resolved {}", quote! { #typ }) } - FieldType::Other { typ } => quote!( &[#typ] ), _ => unreachable!("no nested arrays"), }, + FieldType::PendingResolution { typ } => { + panic!("Should have resolved {}", quote! { #typ }) + } } } @@ -403,9 +436,9 @@ impl Field { self.attrs.available.is_some() } - /// Ensure attributes are sane; this is run after parsing, so we can report - /// any errors in a reasonable way. - fn sanity_check(&self) -> syn::Result<()> { + /// Sanity check we are in a sane state for the end of phase + fn sanity_check(&self, phase: Phase) -> syn::Result<()> { + check_resolution(phase, &self.typ)?; if let FieldType::Array { inner_typ } = &self.typ { if matches!( inner_typ.as_ref(), @@ -416,6 +449,14 @@ impl Field { "nested arrays are not allowed", )); } + check_resolution(phase, inner_typ)?; + } + if let FieldType::Offset { + target: Some(OffsetTarget::Array(inner_typ)), + .. + } = &self.typ + { + check_resolution(phase, inner_typ)?; } if self.is_array() && self.attrs.count.is_none() { return Err(syn::Error::new( @@ -440,6 +481,7 @@ impl Field { _ => (), } } + Ok(()) } @@ -468,7 +510,7 @@ impl Field { FieldType::Offset { typ, .. } | FieldType::Scalar { typ } => { quote!(#typ::RAW_BYTE_LEN) } - FieldType::Other { .. } + FieldType::Struct { .. } | FieldType::Array { .. } | FieldType::ComputedArray { .. } | FieldType::VarLenArray(_) => { @@ -476,6 +518,7 @@ impl Field { let try_op = self.is_version_dependent().then(|| quote!(?)); quote!(self.#len_field #try_op) } + FieldType::PendingResolution { .. } => panic!("Should have resolved {:?}", self), } } @@ -517,17 +560,20 @@ impl Field { pub(crate) fn raw_getter_return_type(&self) -> TokenStream { match &self.typ { FieldType::Offset { typ, .. } if self.is_nullable() => quote!(Nullable<#typ>), - FieldType::Offset { typ, .. } | FieldType::Scalar { typ } => typ.to_token_stream(), - FieldType::Other { typ } => typ.to_token_stream(), + FieldType::Offset { typ, .. } + | FieldType::Scalar { typ } + | FieldType::Struct { typ } => typ.to_token_stream(), FieldType::Array { inner_typ } => match inner_typ.as_ref() { FieldType::Offset { typ, .. } if self.is_nullable() => { quote!(&'a [BigEndian>]) } FieldType::Offset { typ, .. } | FieldType::Scalar { typ } => { - quote!(&'a [BigEndian<#typ>]) + let be = big_endian(typ); + quote!(&'a [#be]) } - FieldType::Other { typ } => quote!( &'a [#typ] ), - _ => unreachable!(), + FieldType::Struct { typ } => quote!(&'a [#typ]), + FieldType::PendingResolution { typ } => quote!( &'a [#typ] ), + _ => unreachable!("An array should never contain {:#?}", inner_typ), }, FieldType::ComputedArray(array) => { let inner = array.type_with_lifetime(); @@ -537,6 +583,7 @@ impl Field { let inner = array.type_with_lifetime(); quote!(VarLenArray<'a, #inner>) } + FieldType::PendingResolution { .. } => panic!("Should have resolved {:?}", self), } } @@ -604,16 +651,25 @@ impl Field { // their fields on access. let add_borrow_just_for_record = matches!( self.typ, - FieldType::Other { .. } | FieldType::ComputedArray { .. } + FieldType::Struct { .. } | FieldType::ComputedArray { .. } ) .then(|| quote!(&)); let getter_expr = match &self.typ { - FieldType::Scalar { .. } | FieldType::Offset { .. } => quote!(self.#name.get()), - FieldType::Other { .. } + FieldType::Scalar { typ } | FieldType::Offset { typ, .. } => { + if typ == "u8" { + quote!(self.#name) + } else { + quote!(self.#name.get()) + } + } + FieldType::Struct { .. } | FieldType::ComputedArray { .. } | FieldType::VarLenArray(_) => quote!(&self.#name), FieldType::Array { .. } => quote!(self.#name), + FieldType::PendingResolution { .. } => { + panic!("Should have resolved {:?}", self) + } }; let offset_getter = self.typed_offset_field_getter(None, Some(record)); @@ -841,10 +897,12 @@ impl Field { .as_deref() .map(FieldReadArgs::to_tokens_for_validation); - if let FieldType::Other { typ } = &self.typ { + if let FieldType::Struct { typ } = &self.typ { return Some(quote!( <#typ as ComputeSize>::compute_size(&#read_args))); } - + if let FieldType::PendingResolution { .. } = &self.typ { + panic!("Should have resolved {:?}", self) + } let len_expr = match self.attrs.count.as_deref() { Some(Count::All) => quote!(cursor.remaining_bytes()), Some(other) => { @@ -981,7 +1039,7 @@ impl Field { fn gets_recursive_validation(&self) -> bool { match &self.typ { - FieldType::Scalar { .. } | FieldType::Other { .. } => false, + FieldType::Scalar { .. } | FieldType::Struct { .. } => false, FieldType::Offset { target: None, .. } => false, FieldType::Offset { target: Some(OffsetTarget::Array(elem)), @@ -992,8 +1050,11 @@ impl Field { | FieldType::VarLenArray(_) => true, FieldType::Array { inner_typ } => matches!( inner_typ.as_ref(), - FieldType::Offset { .. } | FieldType::Other { .. } + FieldType::Offset { .. } | FieldType::Struct { .. } ), + FieldType::PendingResolution { typ } => { + panic!("Should have resolved {}", quote! { #typ }); + } } } @@ -1003,10 +1064,10 @@ impl Field { _ if self.attrs.to_owned.is_some() => false, FieldType::Offset { .. } => in_record, FieldType::ComputedArray(_) | FieldType::VarLenArray(_) => true, - FieldType::Other { .. } => true, + FieldType::Struct { .. } => true, FieldType::Array { inner_typ } => match inner_typ.as_ref() { FieldType::Offset { .. } => in_record, - FieldType::Other { .. } => true, + FieldType::Struct { .. } => true, _ => false, }, _ => false, @@ -1026,7 +1087,7 @@ impl Field { self.attrs.to_owned.as_ref().unwrap().expr.to_token_stream() } FieldType::Scalar { .. } => quote!(obj.#name()), - FieldType::Other { .. } => quote!(obj.#name().to_owned_obj(offset_data)), + FieldType::Struct { .. } => quote!(obj.#name().to_owned_obj(offset_data)), FieldType::Offset { target: Some(_), .. } => { @@ -1051,7 +1112,7 @@ impl Field { quote!(.map(|x| x.into()).collect()), ) } - FieldType::Other { .. } => ( + FieldType::Struct { .. } => ( quote!(obj.#name()), quote!(.iter().map(|x| FromObjRef::from_obj_ref(x, offset_data)).collect()), ), @@ -1086,10 +1147,12 @@ impl FieldType { /// 'cooked', as in now 'raw', i.e no 'BigEndian' wrapper pub(crate) fn cooked_type_tokens(&self) -> &syn::Ident { match &self { - FieldType::Offset { typ, .. } | FieldType::Scalar { typ } => typ, - FieldType::Other { typ } => typ - .get_ident() - .expect("non-trivial custom types never cooked"), + FieldType::Offset { typ, .. } + | FieldType::Scalar { typ } + | FieldType::Struct { typ } => typ, + FieldType::PendingResolution { .. } => { + panic!("Should never cook a type pending resolution {:#?}", self); + } FieldType::Array { .. } | FieldType::ComputedArray { .. } | FieldType::VarLenArray(_) => { @@ -1101,7 +1164,7 @@ impl FieldType { fn compile_type(&self, nullable: bool, version_dependent: bool) -> TokenStream { let raw_type = match self { FieldType::Scalar { typ } => typ.into_token_stream(), - FieldType::Other { typ } => typ.into_token_stream(), + FieldType::Struct { typ } => typ.into_token_stream(), FieldType::Offset { typ, target } => { let target = target .as_ref() @@ -1125,6 +1188,7 @@ impl FieldType { quote!( Vec<#inner_tokens> ) } FieldType::ComputedArray(array) | FieldType::VarLenArray(array) => array.compile_type(), + FieldType::PendingResolution { .. } => panic!("Should have resolved {:?}", self), }; if version_dependent { quote!( Option<#raw_type> ) diff --git a/font-codegen/src/lib.rs b/font-codegen/src/lib.rs index fc455b3f0..2a658f988 100644 --- a/font-codegen/src/lib.rs +++ b/font-codegen/src/lib.rs @@ -1,5 +1,6 @@ //! Generating types from the opentype spec +use log::debug; use quote::quote; mod error; @@ -13,6 +14,8 @@ use parsing::{Item, Items}; pub use error::ErrorReport; +use crate::parsing::Phase; + /// Codegeneration mode. #[derive(Debug, Clone, Copy, serde::Deserialize)] #[serde(rename_all = "lowercase")] @@ -23,11 +26,7 @@ pub enum Mode { Compile, } -pub fn generate_code(code_str: &str, mode: Mode) -> Result { - let tables = match mode { - Mode::Parse => generate_parse_module(code_str), - Mode::Compile => generate_compile_module(code_str), - }?; +fn touchup_code(tables: proc_macro2::TokenStream) -> Result { // if this is not valid code just pass it through directly, and then we // can see the compiler errors let source_str = match rustfmt_wrapper::rustfmt(&tables) { @@ -43,7 +42,31 @@ pub fn generate_code(code_str: &str, mode: Mode) -> Result { // add newlines after top-level items let re2 = regex::Regex::new(r"\n\}").unwrap(); let source_str = re2.replace_all(&source_str, "\n}\n\n"); - let source_str = rustfmt_wrapper::rustfmt(source_str).unwrap(); + Ok(rustfmt_wrapper::rustfmt(source_str).unwrap()) +} + +pub fn generate_code(code_str: &str, mode: Mode) -> Result { + // Generation is done in phases (https://github.com/googlefonts/fontations/issues/71): + // 1. Parse + debug!("Parse (mode {:?})", mode); + let mut items: Items = syn::parse_str(code_str)?; + items.sanity_check(Phase::Parse)?; + + // 2. Contemplate (semantic analysis) + debug!("Analyze (mode {:?})", mode); + items.resolve_pending()?; + items.sanity_check(Phase::Analysis)?; + + // 3. Generate + debug!("Generate (mode {:?})", mode); + let tables = match &mode { + Mode::Parse => generate_parse_module(&items), + Mode::Compile => generate_compile_module(&items), + }?; + + // 4. Touchup + debug!("Touchup (mode {:?})", mode); + let source_str = touchup_code(tables)?; Ok(format!( "\ @@ -54,9 +77,7 @@ pub fn generate_code(code_str: &str, mode: Mode) -> Result { )) } -pub fn generate_parse_module(code: &str) -> Result { - let items: Items = syn::parse_str(code)?; - items.sanity_check()?; +pub(crate) fn generate_parse_module(items: &Items) -> Result { let mut code = Vec::new(); for item in &items.items { let item_code = match item { @@ -77,10 +98,9 @@ pub fn generate_parse_module(code: &str) -> Result Result { - let items: Items = syn::parse_str(code)?; - items.sanity_check()?; - +pub(crate) fn generate_compile_module( + items: &Items, +) -> Result { let code = items .items .iter() diff --git a/font-codegen/src/main.rs b/font-codegen/src/main.rs index 74e978953..b6034c3b5 100644 --- a/font-codegen/src/main.rs +++ b/font-codegen/src/main.rs @@ -5,10 +5,12 @@ use std::path::{Path, PathBuf}; use font_codegen::{ErrorReport, Mode}; +use log::{debug, error}; use miette::miette; use serde::Deserialize; fn main() -> miette::Result<()> { + env_logger::init(); match flags::Args::from_env() { Ok(args) => match args.subcommand { flags::ArgsCmd::Plan(plan) => run_plan(&plan.path), @@ -19,7 +21,7 @@ fn main() -> miette::Result<()> { } }, Err(e) => { - eprintln!("{e}"); + error!("{e}"); std::process::exit(1); } } @@ -33,15 +35,15 @@ fn run_plan(path: &Path) -> miette::Result<()> { for path in &plan.clean { if path.exists() { - println!("removing {}", path.display()); + debug!("removing {}", path.display()); if path.is_dir() { std::fs::remove_dir_all(path) .map_err(|e| miette!("failed to clean dir '{}': {e}", path.display()))?; - println!("creating {}", path.display()); + debug!("creating {}", path.display()); std::fs::create_dir_all(path) .map_err(|e| miette!("failed to create directory '{}': {e}", path.display()))?; } else { - std::fs::remove_file(&path) + std::fs::remove_file(path) .map_err(|e| miette!("failed to clean path '{}': {e}", path.display()))?; } } @@ -54,7 +56,7 @@ fn run_plan(path: &Path) -> miette::Result<()> { .collect::, _>>()?; for (op, generated) in plan.generate.iter().zip(results.iter()) { - println!( + debug!( "writing {} bytes to {}", generated.len(), op.target.display() @@ -88,7 +90,7 @@ struct CodegenOp { } fn read_contents(path: &Path) -> miette::Result { - std::fs::read_to_string(&path).map_err(|e| { + std::fs::read_to_string(path).map_err(|e| { { ErrorReport::message(format!("error reading '{}': {}", path.display(), e)) }.into() }) } diff --git a/font-codegen/src/parsing.rs b/font-codegen/src/parsing.rs index ae46591a8..5ef5e1902 100644 --- a/font-codegen/src/parsing.rs +++ b/font-codegen/src/parsing.rs @@ -1,7 +1,8 @@ //! raw parsing code -use std::{collections::HashMap, ops::Deref}; +use std::{collections::HashMap, ops::Deref, str::FromStr}; +use log::{debug, trace}; use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; use syn::{ @@ -12,11 +13,13 @@ use syn::{ Attribute, Token, }; +#[derive(Debug)] pub(crate) struct Items { pub(crate) parse_module_path: syn::Path, pub(crate) items: Vec, } +#[derive(Debug, Clone)] pub(crate) enum Item { Table(Table), Record(Record), @@ -26,6 +29,12 @@ pub(crate) enum Item { Flags(BitFlags), } +#[derive(Debug, Copy, Clone)] +pub(crate) enum Phase { + Parse, + Analysis, +} + #[derive(Debug, Clone)] pub(crate) struct Table { pub(crate) attrs: TableAttrs, @@ -275,8 +284,15 @@ pub(crate) enum FieldType { Scalar { typ: syn::Ident, }, - Other { - typ: syn::Path, + Struct { + typ: syn::Ident, + }, + /// A type that may be a struct or a scalar. + /// + /// This only exists at parse time; when parsing is finished this will be + /// resolved (or be an error). + PendingResolution { + typ: syn::Ident, }, Array { inner_typ: Box, @@ -598,8 +614,77 @@ impl Parse for FieldType { } } +// https://learn.microsoft.com/en-us/typography/opentype/spec/otff#data-types +// Offset(16,24,32) get special handling, not listed here +// GlyphId and MajorMinor are *not* spec names for scalar but are captured here +#[derive(Debug, PartialEq)] +enum WellKnownScalar { + UInt8, + Int8, + UInt16, + Int16, + UInt24, + UInt32, + Int32, + Fixed, + FWord, + UFWord, + F2Dot14, + LongDateTime, + Tag, + Version16Dot16, + GlyphId, + MajorMinor, +} + +impl FromStr for WellKnownScalar { + type Err = (); + + // TODO(https://github.com/googlefonts/fontations/issues/84) use spec names + fn from_str(str: &str) -> Result { + match str { + "u8" => Ok(WellKnownScalar::UInt8), + "i8" => Ok(WellKnownScalar::Int8), + "u16" => Ok(WellKnownScalar::UInt16), + "i16" => Ok(WellKnownScalar::Int16), + "u24" => Ok(WellKnownScalar::UInt24), + "u32" => Ok(WellKnownScalar::UInt32), + "i32" => Ok(WellKnownScalar::Int32), + "Fixed" => Ok(WellKnownScalar::Fixed), + "FWord" => Ok(WellKnownScalar::FWord), + "UFWord" => Ok(WellKnownScalar::UFWord), + "F2Dot14" => Ok(WellKnownScalar::F2Dot14), + "LongDateTime" => Ok(WellKnownScalar::LongDateTime), + "Tag" => Ok(WellKnownScalar::Tag), + "Version16Dot16" => Ok(WellKnownScalar::Version16Dot16), + "GlyphId" => Ok(WellKnownScalar::GlyphId), + "MajorMinor" => Ok(WellKnownScalar::MajorMinor), + _ => Err(()), + } + } +} + +impl WellKnownScalar { + fn from_path(path: &syn::PathSegment) -> Result { + if !path.arguments.is_empty() { + return Err(()); + } + WellKnownScalar::from_str(path.ident.to_string().as_str()) + } +} + +// TODO use an explicit declaration of user defined types and delete this +fn is_wellknown_struct(path: &syn::PathSegment) -> bool { + if !path.arguments.is_empty() { + return false; + } + matches!(path.ident.to_string().as_str(), "ValueRecord") +} + impl FieldType { fn from_syn_type(type_: &syn::Type) -> syn::Result { + // Figure out any "obvious" types, leave anything non-obvious for later + if let syn::Type::Slice(slice) = type_ { let inner_type = FieldType::from_syn_type(&slice.elem)?; if matches!(inner_type, FieldType::Array { .. }) { @@ -636,25 +721,34 @@ impl FieldType { } } - if last.ident != "BigEndian" { - return Ok(FieldType::Other { typ: path.clone() }); + if WellKnownScalar::from_path(last).is_ok() { + return Ok(FieldType::Scalar { + typ: last.ident.clone(), + }); + } + + if is_wellknown_struct(last) { + return Ok(FieldType::Struct { + typ: last.ident.clone(), + }); } - let inner = get_single_generic_type_arg(&last.arguments)?; - let last = inner.segments.last().unwrap(); if ["Offset16", "Offset24", "Offset32"].contains(&last.ident.to_string().as_str()) { let target = get_offset_target(&last.arguments)?; - Ok(FieldType::Offset { + return Ok(FieldType::Offset { typ: last.ident.clone(), target, - }) - } else if last.arguments.is_empty() { - Ok(FieldType::Scalar { - typ: last.ident.clone(), - }) - } else { - Err(syn::Error::new(last.span(), "unexpected arguments")) + }); + } + + // We'll figure it out later, what could go wrong? + if !last.arguments.is_empty() { + return Err(syn::Error::new(path.span(), "Not sure how to handle this")); } + debug!("Pending {}", quote! { #last }); + Ok(FieldType::PendingResolution { + typ: last.ident.clone(), + }) } } @@ -670,7 +764,12 @@ fn get_offset_target(input: &syn::PathArguments) -> syn::Result { let inner = FieldType::from_syn_type(&t.elem)?; - if matches!(inner, FieldType::Scalar { .. } | FieldType::Other { .. }) { + if matches!( + inner, + FieldType::Scalar { .. } + | FieldType::Struct { .. } + | FieldType::PendingResolution { .. } + ) { Ok(Some(OffsetTarget::Array(Box::new(inner)))) } else { Err(syn::Error::new( @@ -883,20 +982,142 @@ impl Parse for TableReadArg { } } +fn build_type_map(items: &Items) -> HashMap { + return items + .items + .iter() + .filter(|item| !matches!(item, Item::Format(..) | Item::GenericGroup(..))) + // clone like crazy to avoid holding an immutable borrow of the items + .map(|item| match item { + // We're "forgetting" this is a record, could keep if we find a need + Item::Record(data) => ( + data.name.to_string(), + FieldType::Struct { + typ: data.name.clone(), + }, + ), + // We're "forgetting" this is a table, could keep if we find a need + Item::Table(data) => ( + data.raw_name().to_string(), + FieldType::Struct { + typ: data.raw_name().clone(), + }, + ), + // We're "forgetting" the underlying type, could keep if we find a need + Item::RawEnum(data) => ( + data.name.to_string(), + FieldType::Scalar { + typ: data.name.clone(), + }, + ), + // We're "forgetting" the underlying type, could keep if we find a need + Item::Flags(data) => ( + data.name.to_string(), + FieldType::Scalar { + typ: data.name.clone(), + }, + ), + Item::Format(..) | Item::GenericGroup(..) => unreachable!("We filtered you out!!"), + }) + .collect(); +} + +fn resolve_ident<'a>( + known: &'a HashMap, + field_name: &syn::Ident, + ident: &syn::Ident, +) -> Result<&'a FieldType, syn::Error> { + if let Some(item) = known.get(&ident.to_string()) { + debug!("Resolve {}: {} to {:?}", field_name, ident, item); + Ok(item) + } else { + Err(syn::Error::new( + field_name.span(), + format!( + "I don't know what this is, do you? {}: {}", + field_name.to_string().as_str(), + ident + ), + )) + } +} + +fn resolve_field(known: &HashMap, field: &mut Field) -> Result<(), syn::Error> { + if let FieldType::PendingResolution { typ } = &field.typ { + let resolved_typ = resolve_ident(known, &field.name, typ)?; + *field = Field { + typ: resolved_typ.clone(), + ..field.clone() + } + } + + // Array and offsets can nest FieldType, pursue the rabbit + if let FieldType::Array { inner_typ } = &field.typ { + if let FieldType::PendingResolution { typ } = inner_typ.as_ref() { + let resolved_typ = resolve_ident(known, &field.name, typ)?; + *field = Field { + typ: FieldType::Array { + inner_typ: Box::new(resolved_typ.clone()), + }, + ..field.clone() + } + } + } + + if let FieldType::Offset { typ, target } = &field.typ { + let offset_typ = typ; + if let Some(OffsetTarget::Array(array_of)) = target { + if let FieldType::PendingResolution { typ } = array_of.as_ref() { + let resolved_typ = resolve_ident(known, &field.name, typ)?; + *field = Field { + typ: FieldType::Offset { + typ: offset_typ.clone(), + target: Some(OffsetTarget::Array(Box::new(resolved_typ.clone()))), + }, + ..field.clone() + } + } + } + } + Ok(()) +} + impl Items { - pub(crate) fn sanity_check(&self) -> syn::Result<()> { + pub(crate) fn sanity_check(&self, phase: Phase) -> syn::Result<()> { for item in &self.items { - item.sanity_check()?; + item.sanity_check(phase)?; + } + Ok(()) + } + + pub(crate) fn resolve_pending(&mut self) -> Result<(), syn::Error> { + // We should know what some stuff is now + // In theory we could repeat resolution until we succeed or stop learning + // but I don't think ever need that currently + let known = build_type_map(self); + + known.iter().for_each(|(k, v)| trace!("{} => {:?}", k, v)); + + // Try to resolve everything pending against the known world + for item in &mut self.items { + let fields = match item { + Item::Record(item) => &mut item.fields.fields, + Item::Table(item) => &mut item.fields.fields, + _ => continue, + }; + for field in fields { + resolve_field(&known, field)?; + } } Ok(()) } } impl Item { - fn sanity_check(&self) -> syn::Result<()> { + fn sanity_check(&self, phase: Phase) -> syn::Result<()> { match self { - Item::Table(item) => item.sanity_check(), - Item::Record(item) => item.sanity_check(), + Item::Table(item) => item.sanity_check(phase), + Item::Record(item) => item.sanity_check(phase), Item::Format(_) => Ok(()), Item::RawEnum(_) => Ok(()), Item::Flags(_) => Ok(()), @@ -1050,7 +1271,7 @@ impl OffsetTarget { OffsetTarget::Array(inner) => { let elem_type = match inner.deref() { FieldType::Scalar { typ } => quote!(BigEndian<#typ>), - FieldType::Other { typ } => typ.to_token_stream(), + FieldType::Struct { typ } => typ.to_token_stream(), _ => panic!("we should have returned a humane error before now"), }; quote!(Result<&'a [#elem_type], ReadError>) @@ -1187,7 +1408,7 @@ mod tests { #[test] fn offset_target() { - let array_target = make_path_seg("Offset16<[BigEndian]>"); + let array_target = make_path_seg("Offset16<[u16]>"); assert!(get_offset_target(&array_target.arguments) .unwrap() .is_some()); diff --git a/font-codegen/src/record.rs b/font-codegen/src/record.rs index 2a89ecd30..d1bb6f62c 100644 --- a/font-codegen/src/record.rs +++ b/font-codegen/src/record.rs @@ -3,6 +3,8 @@ use proc_macro2::TokenStream; use quote::quote; +use crate::parsing::Phase; + use super::parsing::{CustomCompile, Field, Fields, Record, TableAttrs}; pub(crate) fn generate(item: &Record) -> syn::Result { @@ -244,8 +246,8 @@ fn generate_from_obj_impl(item: &Record, parse_module: &syn::Path) -> syn::Resul } impl Record { - pub(crate) fn sanity_check(&self) -> syn::Result<()> { - self.fields.sanity_check()?; + pub(crate) fn sanity_check(&self, phase: Phase) -> syn::Result<()> { + self.fields.sanity_check(phase)?; let field_needs_lifetime = self .fields .iter() diff --git a/font-codegen/src/table.rs b/font-codegen/src/table.rs index 9d179f6c7..5f8d426b6 100644 --- a/font-codegen/src/table.rs +++ b/font-codegen/src/table.rs @@ -3,7 +3,7 @@ use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; -use crate::parsing::{Attr, GenericGroup}; +use crate::parsing::{Attr, GenericGroup, Phase}; use super::parsing::{Field, ReferencedFields, Table, TableFormat, TableReadArg, TableReadArgs}; @@ -574,8 +574,8 @@ pub(crate) fn generate_format_group(item: &TableFormat) -> syn::Result syn::Result<()> { - self.fields.sanity_check() + pub(crate) fn sanity_check(&self, phase: Phase) -> syn::Result<()> { + self.fields.sanity_check(phase) } fn marker_name(&self) -> syn::Ident { diff --git a/read-fonts/generated/generated_cmap.rs b/read-fonts/generated/generated_cmap.rs index bdd927b1d..42309f3a5 100644 --- a/read-fonts/generated/generated_cmap.rs +++ b/read-fonts/generated/generated_cmap.rs @@ -331,7 +331,7 @@ impl<'a> Cmap0<'a> { } /// An array that maps character codes to glyph index values. - pub fn glyph_id_array(&self) -> &'a [BigEndian] { + pub fn glyph_id_array(&self) -> &'a [u8] { let range = self.shape.glyph_id_array_byte_range(); self.data.read_array(range).unwrap() } @@ -940,7 +940,7 @@ impl<'a> Cmap8<'a> { /// Tightly packed array of bits (8K bytes total) indicating /// whether the particular 16-bit (index) value is the start of a /// 32-bit character code - pub fn is32(&self) -> &'a [BigEndian] { + pub fn is32(&self) -> &'a [u8] { let range = self.shape.is32_byte_range(); self.data.read_array(range).unwrap() } @@ -1758,7 +1758,7 @@ pub struct UnicodeRange { /// First value in this range pub start_unicode_value: BigEndian, /// Number of additional values in this range - pub additional_count: BigEndian, + pub additional_count: u8, } impl UnicodeRange { @@ -1769,7 +1769,7 @@ impl UnicodeRange { /// Number of additional values in this range pub fn additional_count(&self) -> u8 { - self.additional_count.get() + self.additional_count } } diff --git a/read-fonts/generated/generated_cpal.rs b/read-fonts/generated/generated_cpal.rs index f2af8dd50..5447e1328 100644 --- a/read-fonts/generated/generated_cpal.rs +++ b/read-fonts/generated/generated_cpal.rs @@ -266,34 +266,34 @@ impl<'a> std::fmt::Debug for Cpal<'a> { #[repr(packed)] pub struct ColorRecord { /// Blue value (B0). - pub blue: BigEndian, + pub blue: u8, /// Green value (B1). - pub green: BigEndian, + pub green: u8, /// Red value (B2). - pub red: BigEndian, + pub red: u8, /// Alpha value (B3). - pub alpha: BigEndian, + pub alpha: u8, } impl ColorRecord { /// Blue value (B0). pub fn blue(&self) -> u8 { - self.blue.get() + self.blue } /// Green value (B1). pub fn green(&self) -> u8 { - self.green.get() + self.green } /// Red value (B2). pub fn red(&self) -> u8 { - self.red.get() + self.red } /// Alpha value (B3). pub fn alpha(&self) -> u8 { - self.alpha.get() + self.alpha } } diff --git a/read-fonts/generated/generated_glyf.rs b/read-fonts/generated/generated_glyf.rs index 06538e888..37ff47404 100644 --- a/read-fonts/generated/generated_glyf.rs +++ b/read-fonts/generated/generated_glyf.rs @@ -169,7 +169,7 @@ impl<'a> SimpleGlyph<'a> { } /// Array of instruction byte code for the glyph. - pub fn instructions(&self) -> &'a [BigEndian] { + pub fn instructions(&self) -> &'a [u8] { let range = self.shape.instructions_byte_range(); self.data.read_array(range).unwrap() } diff --git a/resources/codegen_inputs/cmap.rs b/resources/codegen_inputs/cmap.rs index 5fa602779..da6d0ecb9 100644 --- a/resources/codegen_inputs/cmap.rs +++ b/resources/codegen_inputs/cmap.rs @@ -3,10 +3,10 @@ /// [cmap](https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#overview) table Cmap { /// Table version number (0). - version: BigEndian, + version: u16, /// Number of encoding tables that follow. #[compile(array_len($encoding_records))] - num_tables: BigEndian, + num_tables: u16, #[count($num_tables)] encoding_records: [EncodingRecord], } @@ -14,12 +14,12 @@ table Cmap { /// [Encoding Record](https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#encoding-records-and-encodings) record EncodingRecord { /// Platform ID. - platform_id: BigEndian, + platform_id: PlatformId, /// Platform-specific encoding ID. - encoding_id: BigEndian, + encoding_id: u16, /// Byte offset from beginning of table to the subtable for this /// encoding. - subtable_offset: BigEndian>, + subtable_offset: Offset32, } /// @@ -48,33 +48,33 @@ format u16 CmapSubtable { table Cmap0 { /// Format number is set to 0. #[format = 0] - format: BigEndian, + format: u16, /// This is the length in bytes of the subtable. #[compile(256 + 6)] - length: BigEndian, + length: u16, /// For requirements on use of the language field, see “Use of /// the language field in 'cmap' subtables” in this document. - language: BigEndian, + language: u16, /// An array that maps character codes to glyph index values. #[count(256)] - glyph_id_array: [BigEndian], + glyph_id_array: [u8], } /// [cmap Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-2-high-byte-mapping-through-table): High-byte mapping through table table Cmap2 { /// Format number is set to 2. #[format = 2] - format: BigEndian, + format: u16, /// This is the length in bytes of the subtable. #[compile(panic!("not implemented"))] - length: BigEndian, + length: u16, /// For requirements on use of the language field, see “Use of /// the language field in 'cmap' subtables” in this document. - language: BigEndian, + language: u16, /// Array that maps high bytes to subHeaders: value is subHeader /// index × 8. #[count(256)] - sub_header_keys: [BigEndian], + sub_header_keys: [u16], //FIXME: these two fields will require some custom handling ///// Variable-length array of SubHeader records. @@ -83,103 +83,103 @@ table Cmap2 { ///// Variable-length array containing subarrays used for mapping the ///// low byte of 2-byte characters. //#[count( )] - //glyph_id_array: [BigEndian], + //glyph_id_array: [u16], } /// Part of [Cmap2] record SubHeader { /// First valid low byte for this SubHeader. - first_code: BigEndian, + first_code: u16, /// Number of valid low bytes for this SubHeader. - entry_count: BigEndian, + entry_count: u16, /// See text below. - id_delta: BigEndian, + id_delta: i16, /// See text below. - id_range_offset: BigEndian, + id_range_offset: u16, } /// [cmap Format 4](https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-4-segment-mapping-to-delta-values): Segment mapping to delta values table Cmap4 { /// Format number is set to 4. #[format = 4] - format: BigEndian, + format: u16, /// This is the length in bytes of the subtable. - length: BigEndian, + length: u16, /// For requirements on use of the language field, see “Use of /// the language field in 'cmap' subtables” in this document. - language: BigEndian, + language: u16, /// 2 × segCount. - seg_count_x2: BigEndian, + seg_count_x2: u16, /// Maximum power of 2 less than or equal to segCount, times 2 /// ((2**floor(log2(segCount))) * 2, where “**” is an /// exponentiation operator) - search_range: BigEndian, + search_range: u16, /// Log2 of the maximum power of 2 less than or equal to numTables /// (log2(searchRange/2), which is equal to floor(log2(segCount))) - entry_selector: BigEndian, + entry_selector: u16, /// segCount times 2, minus searchRange ((segCount * 2) - /// searchRange) - range_shift: BigEndian, + range_shift: u16, /// End characterCode for each segment, last=0xFFFF. #[count($seg_count_x2 as usize / 2)] - end_code: [BigEndian], + end_code: [u16], /// Set to 0. #[skip_getter] - reserved_pad: BigEndian, + reserved_pad: u16, /// Start character code for each segment. #[count($seg_count_x2 as usize / 2)] - start_code: [BigEndian], + start_code: [u16], /// Delta for all character codes in segment. #[count($seg_count_x2 as usize / 2)] - id_delta: [BigEndian], + id_delta: [i16], /// Offsets into glyphIdArray or 0 #[count($seg_count_x2 as usize / 2)] - id_range_offsets: [BigEndian], + id_range_offsets: [u16], /// Glyph index array (arbitrary length) #[count(..)] - glyph_id_array: [BigEndian], + glyph_id_array: [u16], } /// [cmap Format 6](https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-6-trimmed-table-mapping): Trimmed table mapping table Cmap6 { /// Format number is set to 6. #[format = 6] - format: BigEndian, + format: u16, /// This is the length in bytes of the subtable. - length: BigEndian, + length: u16, /// For requirements on use of the language field, see “Use of /// the language field in 'cmap' subtables” in this document. - language: BigEndian, + language: u16, /// First character code of subrange. - first_code: BigEndian, + first_code: u16, /// Number of character codes in subrange. - entry_count: BigEndian, + entry_count: u16, /// Array of glyph index values for character codes in the range. #[count($entry_count)] - glyph_id_array: [BigEndian], + glyph_id_array: [u16], } /// [cmap Format 8](https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-8-mixed-16-bit-and-32-bit-coverage): mixed 16-bit and 32-bit coverage table Cmap8 { /// Subtable format; set to 8. #[format = 8] - format: BigEndian, + format: u16, /// Reserved; set to 0 #[skip_getter] - reserved: BigEndian, + reserved: u16, /// Byte length of this subtable (including the header) - length: BigEndian, + length: u32, /// For requirements on use of the language field, see “Use of /// the language field in 'cmap' subtables” in this document. - language: BigEndian, + language: u32, /// Tightly packed array of bits (8K bytes total) indicating /// whether the particular 16-bit (index) value is the start of a /// 32-bit character code #[count(8192)] - is32: [BigEndian], + is32: [u8], /// Number of groupings which follow - num_groups: BigEndian, + num_groups: u32, /// Array of SequentialMapGroup records. #[count($num_groups)] groups: [SequentialMapGroup], @@ -191,51 +191,51 @@ record SequentialMapGroup { /// for one or more 16-bit character codes (which is determined /// from the is32 array), this 32-bit value will have the high /// 16-bits set to zero - start_char_code: BigEndian, + start_char_code: u32, /// Last character code in this group; same condition as listed /// above for the startCharCode - end_char_code: BigEndian, + end_char_code: u32, /// Glyph index corresponding to the starting character code - start_glyph_id: BigEndian, + start_glyph_id: u32, } /// [cmap Format 10](https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-10-trimmed-array): Tr table Cmap10 { /// Subtable format; set to 10. #[format = 10] - format: BigEndian, + format: u16, /// Reserved; set to 0 #[skip_getter] - reserved: BigEndian, + reserved: u16, /// Byte length of this subtable (including the header) - length: BigEndian, + length: u32, /// For requirements on use of the language field, see “Use of /// the language field in 'cmap' subtables” in this document. - language: BigEndian, + language: u32, /// First character code covered - start_char_code: BigEndian, + start_char_code: u32, /// Number of character codes covered - num_chars: BigEndian, + num_chars: u32, /// Array of glyph indices for the character codes covered #[count(..)] - glyph_id_array: [BigEndian], + glyph_id_array: [u16], } /// [cmap Format 12](https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-12-segmented-coverage): Segmented coverage table Cmap12 { /// Subtable format; set to 12. #[format = 12] - format: BigEndian, + format: u16, /// Reserved; set to 0 #[skip_getter] - reserved: BigEndian, + reserved: u16, /// Byte length of this subtable (including the header) - length: BigEndian, + length: u32, /// For requirements on use of the language field, see “Use of /// the language field in 'cmap' subtables” in this document. - language: BigEndian, + language: u32, /// Number of groupings which follow - num_groups: BigEndian, + num_groups: u32, /// Array of SequentialMapGroup records. #[count($num_groups)] groups: [SequentialMapGroup], @@ -245,17 +245,17 @@ table Cmap12 { table Cmap13 { /// Subtable format; set to 13. #[format = 13] - format: BigEndian, + format: u16, /// Reserved; set to 0 #[skip_getter] - reserved: BigEndian, + reserved: u16, /// Byte length of this subtable (including the header) - length: BigEndian, + length: u32, /// For requirements on use of the language field, see “Use of /// the language field in 'cmap' subtables” in this document. - language: BigEndian, + language: u32, /// Number of groupings which follow - num_groups: BigEndian, + num_groups: u32, /// Array of ConstantMapGroup records. #[count($num_groups)] groups: [ConstantMapGroup], @@ -264,23 +264,23 @@ table Cmap13 { /// Part of [Cmap13] record ConstantMapGroup { /// First character code in this group - start_char_code: BigEndian, + start_char_code: u32, /// Last character code in this group - end_char_code: BigEndian, + end_char_code: u32, /// Glyph index to be used for all the characters in the group’s /// range. - glyph_id: BigEndian, + glyph_id: u32, } /// [cmap Format 14](https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-14-unicode-variation-sequences): Unicode Variation Sequences table Cmap14 { /// Subtable format. Set to 14. #[format = 14] - format: BigEndian, + format: u16, /// Byte length of this subtable (including this header) - length: BigEndian, + length: u32, /// Number of variation Selector Records - num_var_selector_records: BigEndian, + num_var_selector_records: u32, /// Array of VariationSelector records. #[count($num_var_selector_records)] var_selector: [VariationSelector], @@ -289,19 +289,19 @@ table Cmap14 { /// Part of [Cmap14] record VariationSelector { /// Variation selector - var_selector: BigEndian, + var_selector: Uint24, /// Offset from the start of the format 14 subtable to Default UVS /// Table. May be 0. - default_uvs_offset: BigEndian, + default_uvs_offset: Offset32, /// Offset from the start of the format 14 subtable to Non-Default /// UVS Table. May be 0. - non_default_uvs_offset: BigEndian, + non_default_uvs_offset: Offset32, } /// [Default UVS table](https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#default-uvs-table) table DefaultUvs { /// Number of Unicode character ranges. - num_unicode_value_ranges: BigEndian, + num_unicode_value_ranges: u32, /// Array of UnicodeRange records. #[count($num_unicode_value_ranges)] ranges: [UnicodeRange], @@ -310,15 +310,15 @@ table DefaultUvs { /// Part of [Cmap14] record UVSMapping { /// Base Unicode value of the UVS - unicode_value: BigEndian, + unicode_value: Uint24, /// Glyph ID of the UVS - glyph_id: BigEndian, + glyph_id: u16, } /// Part of [Cmap14] record UnicodeRange { /// First value in this range - start_unicode_value: BigEndian, + start_unicode_value: Uint24, /// Number of additional values in this range - additional_count: BigEndian, + additional_count: u8, } diff --git a/resources/codegen_inputs/colr.rs b/resources/codegen_inputs/colr.rs index a6631c353..5132fb0dc 100644 --- a/resources/codegen_inputs/colr.rs +++ b/resources/codegen_inputs/colr.rs @@ -5,62 +5,62 @@ table Colr { /// Table version number - set to 0 or 1. #[version] - version: BigEndian, + version: u16, /// Number of BaseGlyph records; may be 0 in a version 1 table. - num_base_glyph_records: BigEndian, + num_base_glyph_records: u16, /// Offset to baseGlyphRecords array (may be NULL). #[nullable] #[read_offset_with($num_base_glyph_records)] - base_glyph_records_offset: BigEndian>, + base_glyph_records_offset: Offset32<[BaseGlyph]>, /// Offset to layerRecords array (may be NULL). #[nullable] #[read_offset_with($num_layer_records)] - layer_records_offset: BigEndian>, + layer_records_offset: Offset32<[Layer]>, /// Number of Layer records; may be 0 in a version 1 table. - num_layer_records: BigEndian, + num_layer_records: u16, /// Offset to BaseGlyphList table. #[available(1)] #[nullable] - base_glyph_list_offset: BigEndian>, + base_glyph_list_offset: Offset32, /// Offset to LayerList table (may be NULL). #[available(1)] #[nullable] - layer_list_offset: BigEndian>, + layer_list_offset: Offset32, /// Offset to ClipList table (may be NULL). #[available(1)] #[nullable] - clip_list_offset: BigEndian>, + clip_list_offset: Offset32, /// Offset to DeltaSetIndexMap table (may be NULL). #[available(1)] #[nullable] - var_index_map_offset: BigEndian, + var_index_map_offset: Offset32, /// Offset to ItemVariationStore (may be NULL). #[available(1)] #[nullable] - item_variation_store_offset: BigEndian, + item_variation_store_offset: Offset32, } /// [BaseGlyph](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyph-and-layer-records) record record BaseGlyph { /// Glyph ID of the base glyph. - glyph_id: BigEndian, + glyph_id: GlyphId, /// Index (base 0) into the layerRecords array. - first_layer_index: BigEndian, + first_layer_index: u16, /// Number of color layers associated with this glyph. - num_layers: BigEndian, + num_layers: u16, } /// [Layer](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyph-and-layer-records) record record Layer { /// Glyph ID of the glyph used for a given layer. - glyph_id: BigEndian, + glyph_id: GlyphId, /// Index (base 0) for a palette entry in the CPAL table. - palette_index: BigEndian, + palette_index: u16, } /// [BaseGlyphList](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table table BaseGlyphList { - num_base_glyph_paint_records: BigEndian, + num_base_glyph_paint_records: u32, #[count($num_base_glyph_paint_records)] base_glyph_paint_records: [BaseGlyphPaint], } @@ -68,25 +68,25 @@ table BaseGlyphList { /// [BaseGlyphPaint](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record record BaseGlyphPaint { /// Glyph ID of the base glyph. - glyph_id: BigEndian, + glyph_id: GlyphId, /// Offset to a Paint table. - paint_offset: BigEndian>, + paint_offset: Offset32, } /// [LayerList](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table table LayerList { - num_layers: BigEndian, + num_layers: u32, /// Offsets to Paint tables. #[count($num_layers)] - paint_offsets: [BigEndian>], + paint_offsets: [Offset32], } /// [ClipList](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table table ClipList { /// Set to 1. - format: BigEndian, + format: u8, /// Number of Clip records. - num_clips: BigEndian, + num_clips: u32, /// Clip records. Sorted by startGlyphID. #[count($num_clips)] clips: [Clip], @@ -95,11 +95,11 @@ table ClipList { /// [Clip](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record record Clip { /// First glyph ID in the range. - start_glyph_id: BigEndian, + start_glyph_id: GlyphId, /// Last glyph ID in the range. - end_glyph_id: BigEndian, + end_glyph_id: GlyphId, /// Offset to a ClipBox table. - clip_box_offset: BigEndian>, + clip_box_offset: Offset24, } /// [ClipBox](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table @@ -112,80 +112,80 @@ format u8 ClipBox { table ClipBoxFormat1 { /// Set to 1. #[format = 1] - format: BigEndian, + format: u8, /// Minimum x of clip box. - x_min: BigEndian, + x_min: FWord, /// Minimum y of clip box. - y_min: BigEndian, + y_min: FWord, /// Maximum x of clip box. - x_max: BigEndian, + x_max: FWord, /// Maximum y of clip box. - y_max: BigEndian, + y_max: FWord, } /// [ClipBoxFormat2](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record table ClipBoxFormat2 { /// Set to 2. #[format = 2] - format: BigEndian, + format: u8, /// Minimum x of clip box. For variation, use varIndexBase + 0. - x_min: BigEndian, + x_min: FWord, /// Minimum y of clip box. For variation, use varIndexBase + 1. - y_min: BigEndian, + y_min: FWord, /// Maximum x of clip box. For variation, use varIndexBase + 2. - x_max: BigEndian, + x_max: FWord, /// Maximum y of clip box. For variation, use varIndexBase + 3. - y_max: BigEndian, + y_max: FWord, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [ColorIndex](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record record ColorIndex { /// Index for a CPAL palette entry. - palette_index: BigEndian, + palette_index: u16, /// Alpha value. - alpha: BigEndian, + alpha: F2Dot14, } /// [VarColorIndex](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record record VarColorIndex { /// Index for a CPAL palette entry. - palette_index: BigEndian, + palette_index: u16, /// Alpha value. For variation, use varIndexBase + 0. - alpha: BigEndian, + alpha: F2Dot14, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [ColorStop](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record record ColorStop { /// Position on a color line. - stop_offset: BigEndian, + stop_offset: F2Dot14, /// Index for a CPAL palette entry. - palette_index: BigEndian, + palette_index: u16, /// Alpha value. - alpha: BigEndian, + alpha: F2Dot14, } /// [VarColorStop](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record record VarColorStop { /// Position on a color line. For variation, use varIndexBase + 0. - stop_offset: BigEndian, + stop_offset: F2Dot14, /// Index for a CPAL palette entry. - palette_index: BigEndian, + palette_index: u16, /// Alpha value. For variation, use varIndexBase + 1. - alpha: BigEndian, + alpha: F2Dot14, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [ColorLine](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) table table ColorLine { /// An Extend enum value. - extend: BigEndian, + extend: Extend, /// Number of ColorStop records. - num_stops: BigEndian, + num_stops: u16, #[count($num_stops)] color_stops: [ColorStop], } @@ -193,9 +193,9 @@ table ColorLine { /// [VarColorLine](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) table table VarColorLine { /// An Extend enum value. - extend: BigEndian, + extend: Extend, /// Number of ColorStop records. - num_stops: BigEndian, + num_stops: u16, /// Allows for variations. #[count($num_stops)] color_stops: [VarColorStop], @@ -248,566 +248,566 @@ format u8 Paint { table PaintColrLayers { /// Set to 1. #[format = 1] - format: BigEndian, + format: u8, /// Number of offsets to paint tables to read from LayerList. - num_layers: BigEndian, + num_layers: u8, /// Index (base 0) into the LayerList. - first_layer_index: BigEndian, + first_layer_index: u32, } /// [PaintSolid](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-2-and-3-paintsolid-paintvarsolid) table table PaintSolid { /// Set to 2. #[format = 2] - format: BigEndian, + format: u8, /// Index for a CPAL palette entry. - palette_index: BigEndian, + palette_index: u16, /// Alpha value. - alpha: BigEndian, + alpha: F2Dot14, } /// [PaintVarSolid](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-2-and-3-paintsolid-paintvarsolid) table table PaintVarSolid { /// Set to 3. #[format = 3] - format: BigEndian, + format: u8, /// Index for a CPAL palette entry. - palette_index: BigEndian, + palette_index: u16, /// Alpha value. For variation, use varIndexBase + 0. - alpha: BigEndian, + alpha: F2Dot14, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintLinearGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-4-and-5-paintlineargradient-paintvarlineargradient) table table PaintLinearGradient { /// Set to 4. #[format = 4] - format: BigEndian, + format: u8, /// Offset to ColorLine table. - color_line_offset: BigEndian>, + color_line_offset: Offset24, /// Start point (p₀) x coordinate. - x0: BigEndian, + x0: FWord, /// Start point (p₀) y coordinate. - y0: BigEndian, + y0: FWord, /// End point (p₁) x coordinate. - x1: BigEndian, + x1: FWord, /// End point (p₁) y coordinate. - y1: BigEndian, + y1: FWord, /// Rotation point (p₂) x coordinate. - x2: BigEndian, + x2: FWord, /// Rotation point (p₂) y coordinate. - y2: BigEndian, + y2: FWord, } /// [PaintVarLinearGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-4-and-5-paintlineargradient-paintvarlineargradient) table table PaintVarLinearGradient { /// Set to 5. #[format = 5] - format: BigEndian, + format: u8, /// Offset to VarColorLine table. - color_line_offset: BigEndian>, + color_line_offset: Offset24, /// Start point (p₀) x coordinate. For variation, use /// varIndexBase + 0. - x0: BigEndian, + x0: FWord, /// Start point (p₀) y coordinate. For variation, use /// varIndexBase + 1. - y0: BigEndian, + y0: FWord, /// End point (p₁) x coordinate. For variation, use varIndexBase /// + 2. - x1: BigEndian, + x1: FWord, /// End point (p₁) y coordinate. For variation, use varIndexBase /// + 3. - y1: BigEndian, + y1: FWord, /// Rotation point (p₂) x coordinate. For variation, use /// varIndexBase + 4. - x2: BigEndian, + x2: FWord, /// Rotation point (p₂) y coordinate. For variation, use /// varIndexBase + 5. - y2: BigEndian, + y2: FWord, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintRadialGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-6-and-7-paintradialgradient-paintvarradialgradient) table table PaintRadialGradient { /// Set to 6. #[format = 6] - format: BigEndian, + format: u8, /// Offset to ColorLine table. - color_line_offset: BigEndian>, + color_line_offset: Offset24, /// Start circle center x coordinate. - x0: BigEndian, + x0: FWord, /// Start circle center y coordinate. - y0: BigEndian, + y0: FWord, /// Start circle radius. - radius0: BigEndian, + radius0: UfWord, /// End circle center x coordinate. - x1: BigEndian, + x1: FWord, /// End circle center y coordinate. - y1: BigEndian, + y1: FWord, /// End circle radius. - radius1: BigEndian, + radius1: UfWord, } /// [PaintVarRadialGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-6-and-7-paintradialgradient-paintvarradialgradient) table table PaintVarRadialGradient { /// Set to 7. #[format = 7] - format: BigEndian, + format: u8, /// Offset to VarColorLine table. - color_line_offset: BigEndian>, + color_line_offset: Offset24, /// Start circle center x coordinate. For variation, use /// varIndexBase + 0. - x0: BigEndian, + x0: FWord, /// Start circle center y coordinate. For variation, use /// varIndexBase + 1. - y0: BigEndian, + y0: FWord, /// Start circle radius. For variation, use varIndexBase + 2. - radius0: BigEndian, + radius0: UfWord, /// End circle center x coordinate. For variation, use varIndexBase /// + 3. - x1: BigEndian, + x1: FWord, /// End circle center y coordinate. For variation, use varIndexBase /// + 4. - y1: BigEndian, + y1: FWord, /// End circle radius. For variation, use varIndexBase + 5. - radius1: BigEndian, + radius1: UfWord, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintSweepGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-8-and-9-paintsweepgradient-paintvarsweepgradient) table table PaintSweepGradient { /// Set to 8. #[format = 8] - format: BigEndian, + format: u8, /// Offset to ColorLine table. - color_line_offset: BigEndian>, + color_line_offset: Offset24, /// Center x coordinate. - center_x: BigEndian, + center_x: FWord, /// Center y coordinate. - center_y: BigEndian, + center_y: FWord, /// Start of the angular range of the gradient, 180° in /// counter-clockwise degrees per 1.0 of value. - start_angle: BigEndian, + start_angle: F2Dot14, /// End of the angular range of the gradient, 180° in /// counter-clockwise degrees per 1.0 of value. - end_angle: BigEndian, + end_angle: F2Dot14, } /// [PaintVarSweepGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-8-and-9-paintsweepgradient-paintvarsweepgradient) table table PaintVarSweepGradient { /// Set to 9. #[format = 9] - format: BigEndian, + format: u8, /// Offset to VarColorLine table. - color_line_offset: BigEndian>, + color_line_offset: Offset24, /// Center x coordinate. For variation, use varIndexBase + 0. - center_x: BigEndian, + center_x: FWord, /// Center y coordinate. For variation, use varIndexBase + 1. - center_y: BigEndian, + center_y: FWord, /// Start of the angular range of the gradient, 180° in /// counter-clockwise degrees per 1.0 of value. For variation, use /// varIndexBase + 2. - start_angle: BigEndian, + start_angle: F2Dot14, /// End of the angular range of the gradient, 180° in /// counter-clockwise degrees per 1.0 of value. For variation, use /// varIndexBase + 3. - end_angle: BigEndian, + end_angle: F2Dot14, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintGlyph](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-10-paintglyph) table table PaintGlyph { /// Set to 10. #[format = 10] - format: BigEndian, + format: u8, /// Offset to a Paint table. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Glyph ID for the source outline. - glyph_id: BigEndian, + glyph_id: GlyphId, } /// [PaintColrGlyph](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-11-paintcolrglyph) table table PaintColrGlyph { /// Set to 11. #[format = 11] - format: BigEndian, + format: u8, /// Glyph ID for a BaseGlyphList base glyph. - glyph_id: BigEndian, + glyph_id: GlyphId, } /// [PaintTransform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) table table PaintTransform { /// Set to 12. #[format = 12] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Offset to an Affine2x3 table. - transform_offset: BigEndian>, + transform_offset: Offset24, } /// [PaintVarTransform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) table table PaintVarTransform { /// Set to 13. #[format = 13] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Offset to a VarAffine2x3 table. - transform_offset: BigEndian>, + transform_offset: Offset24, } /// [Affine2x3](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) record table Affine2x3 { /// x-component of transformed x-basis vector. - xx: BigEndian, + xx: Fixed, /// y-component of transformed x-basis vector. - yx: BigEndian, + yx: Fixed, /// x-component of transformed y-basis vector. - xy: BigEndian, + xy: Fixed, /// y-component of transformed y-basis vector. - yy: BigEndian, + yy: Fixed, /// Translation in x direction. - dx: BigEndian, + dx: Fixed, /// Translation in y direction. - dy: BigEndian, + dy: Fixed, } /// [VarAffine2x3](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) record table VarAffine2x3 { /// x-component of transformed x-basis vector. For variation, use /// varIndexBase + 0. - xx: BigEndian, + xx: Fixed, /// y-component of transformed x-basis vector. For variation, use /// varIndexBase + 1. - yx: BigEndian, + yx: Fixed, /// x-component of transformed y-basis vector. For variation, use /// varIndexBase + 2. - xy: BigEndian, + xy: Fixed, /// y-component of transformed y-basis vector. For variation, use /// varIndexBase + 3. - yy: BigEndian, + yy: Fixed, /// Translation in x direction. For variation, use varIndexBase + 4. - dx: BigEndian, + dx: Fixed, /// Translation in y direction. For variation, use varIndexBase + 5. - dy: BigEndian, + dy: Fixed, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintTranslate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-14-and-15-painttranslate-paintvartranslate) table table PaintTranslate { /// Set to 14. #[format = 14] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Translation in x direction. - dx: BigEndian, + dx: FWord, /// Translation in y direction. - dy: BigEndian, + dy: FWord, } /// [PaintVarTranslate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-14-and-15-painttranslate-paintvartranslate) table table PaintVarTranslate { /// Set to 15. #[format = 15] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Translation in x direction. For variation, use varIndexBase + 0. - dx: BigEndian, + dx: FWord, /// Translation in y direction. For variation, use varIndexBase + 1. - dy: BigEndian, + dy: FWord, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintScale](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table table PaintScale { /// Set to 16. #[format = 16] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Scale factor in x direction. - scale_x: BigEndian, + scale_x: F2Dot14, /// Scale factor in y direction. - scale_y: BigEndian, + scale_y: F2Dot14, } /// [PaintVarScale](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table table PaintVarScale { /// Set to 17. #[format = 17] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Scale factor in x direction. For variation, use varIndexBase + /// 0. - scale_x: BigEndian, + scale_x: F2Dot14, /// Scale factor in y direction. For variation, use varIndexBase + /// 1. - scale_y: BigEndian, + scale_y: F2Dot14, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintScaleAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table table PaintScaleAroundCenter { /// Set to 18. #[format = 18] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Scale factor in x direction. - scale_x: BigEndian, + scale_x: F2Dot14, /// Scale factor in y direction. - scale_y: BigEndian, + scale_y: F2Dot14, /// x coordinate for the center of scaling. - center_x: BigEndian, + center_x: FWord, /// y coordinate for the center of scaling. - center_y: BigEndian, + center_y: FWord, } /// [PaintVarScaleAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table table PaintVarScaleAroundCenter { /// Set to 19. #[format = 19] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Scale factor in x direction. For variation, use varIndexBase + /// 0. - scale_x: BigEndian, + scale_x: F2Dot14, /// Scale factor in y direction. For variation, use varIndexBase + /// 1. - scale_y: BigEndian, + scale_y: F2Dot14, /// x coordinate for the center of scaling. For variation, use /// varIndexBase + 2. - center_x: BigEndian, + center_x: FWord, /// y coordinate for the center of scaling. For variation, use /// varIndexBase + 3. - center_y: BigEndian, + center_y: FWord, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintScaleUniform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table table PaintScaleUniform { /// Set to 20. #[format = 20] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Scale factor in x and y directions. - scale: BigEndian, + scale: F2Dot14, } /// [PaintVarScaleUniform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table table PaintVarScaleUniform { /// Set to 21. #[format = 21] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Scale factor in x and y directions. For variation, use /// varIndexBase + 0. - scale: BigEndian, + scale: F2Dot14, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintScaleUniformAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table table PaintScaleUniformAroundCenter { /// Set to 22. #[format = 22] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Scale factor in x and y directions. - scale: BigEndian, + scale: F2Dot14, /// x coordinate for the center of scaling. - center_x: BigEndian, + center_x: FWord, /// y coordinate for the center of scaling. - center_y: BigEndian, + center_y: FWord, } /// [PaintVarScaleUniformAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table table PaintVarScaleUniformAroundCenter { /// Set to 23. #[format = 23] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Scale factor in x and y directions. For variation, use /// varIndexBase + 0. - scale: BigEndian, + scale: F2Dot14, /// x coordinate for the center of scaling. For variation, use /// varIndexBase + 1. - center_x: BigEndian, + center_x: FWord, /// y coordinate for the center of scaling. For variation, use /// varIndexBase + 2. - center_y: BigEndian, + center_y: FWord, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintRotate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table table PaintRotate { /// Set to 24. #[format = 24] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of /// value. - angle: BigEndian, + angle: F2Dot14, } /// [PaintVarRotate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table table PaintVarRotate { /// Set to 25. #[format = 25] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of /// value. For variation, use varIndexBase + 0. - angle: BigEndian, + angle: F2Dot14, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintRotateAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table table PaintRotateAroundCenter { /// Set to 26. #[format = 26] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of /// value. - angle: BigEndian, + angle: F2Dot14, /// x coordinate for the center of rotation. - center_x: BigEndian, + center_x: FWord, /// y coordinate for the center of rotation. - center_y: BigEndian, + center_y: FWord, } /// [PaintVarRotateAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table table PaintVarRotateAroundCenter { /// Set to 27. #[format = 27] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of /// value. For variation, use varIndexBase + 0. - angle: BigEndian, + angle: F2Dot14, /// x coordinate for the center of rotation. For variation, use /// varIndexBase + 1. - center_x: BigEndian, + center_x: FWord, /// y coordinate for the center of rotation. For variation, use /// varIndexBase + 2. - center_y: BigEndian, + center_y: FWord, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintSkew](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table table PaintSkew { /// Set to 28. #[format = 28] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Angle of skew in the direction of the x-axis, 180° in /// counter-clockwise degrees per 1.0 of value. - x_skew_angle: BigEndian, + x_skew_angle: F2Dot14, /// Angle of skew in the direction of the y-axis, 180° in /// counter-clockwise degrees per 1.0 of value. - y_skew_angle: BigEndian, + y_skew_angle: F2Dot14, } /// [PaintVarSkew](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table table PaintVarSkew { /// Set to 29. #[format = 29] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Angle of skew in the direction of the x-axis, 180° ┬░ in /// counter-clockwise degrees per 1.0 of value. For variation, use /// varIndexBase + 0. - x_skew_angle: BigEndian, + x_skew_angle: F2Dot14, /// Angle of skew in the direction of the y-axis, 180° in /// counter-clockwise degrees per 1.0 of value. For variation, use /// varIndexBase + 1. - y_skew_angle: BigEndian, + y_skew_angle: F2Dot14, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintSkewAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table table PaintSkewAroundCenter { /// Set to 30. #[format = 30] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Angle of skew in the direction of the x-axis, 180° in /// counter-clockwise degrees per 1.0 of value. - x_skew_angle: BigEndian, + x_skew_angle: F2Dot14, /// Angle of skew in the direction of the y-axis, 180° in /// counter-clockwise degrees per 1.0 of value. - y_skew_angle: BigEndian, + y_skew_angle: F2Dot14, /// x coordinate for the center of rotation. - center_x: BigEndian, + center_x: FWord, /// y coordinate for the center of rotation. - center_y: BigEndian, + center_y: FWord, } /// [PaintVarSkewAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table table PaintVarSkewAroundCenter { /// Set to 31. #[format = 31] - format: BigEndian, + format: u8, /// Offset to a Paint subtable. - paint_offset: BigEndian>, + paint_offset: Offset24, /// Angle of skew in the direction of the x-axis, 180° in /// counter-clockwise degrees per 1.0 of value. For variation, use /// varIndexBase + 0. - x_skew_angle: BigEndian, + x_skew_angle: F2Dot14, /// Angle of skew in the direction of the y-axis, 180° in /// counter-clockwise degrees per 1.0 of value. For variation, use /// varIndexBase + 1. - y_skew_angle: BigEndian, + y_skew_angle: F2Dot14, /// x coordinate for the center of rotation. For variation, use /// varIndexBase + 2. - center_x: BigEndian, + center_x: FWord, /// y coordinate for the center of rotation. For variation, use /// varIndexBase + 3. - center_y: BigEndian, + center_y: FWord, /// Base index into DeltaSetIndexMap. - var_index_base: BigEndian, + var_index_base: u32, } /// [PaintComposite](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-32-paintcomposite) table table PaintComposite { /// Set to 32. #[format = 32] - format: BigEndian, + format: u8, /// Offset to a source Paint table. - source_paint_offset: BigEndian>, + source_paint_offset: Offset24, /// A CompositeMode enumeration value. - composite_mode: BigEndian, + composite_mode: CompositeMode, /// Offset to a backdrop Paint table. - backdrop_paint_offset: BigEndian>, + backdrop_paint_offset: Offset24, } /// [CompositeMode](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-32-paintcomposite) enumeration diff --git a/resources/codegen_inputs/cpal.rs b/resources/codegen_inputs/cpal.rs index c523345aa..e56c14ab8 100644 --- a/resources/codegen_inputs/cpal.rs +++ b/resources/codegen_inputs/cpal.rs @@ -4,22 +4,22 @@ table Cpal { /// Table version number (=0). #[version] - version: BigEndian, + version: u16, /// Number of palette entries in each palette. - num_palette_entries: BigEndian, + num_palette_entries: u16, /// Number of palettes in the table. - num_palettes: BigEndian, + num_palettes: u16, /// Total number of color records, combined for all palettes. - num_color_records: BigEndian, + num_color_records: u16, /// Offset from the beginning of CPAL table to the first /// ColorRecord. #[nullable] #[read_offset_with($num_color_records)] - color_records_array_offset: BigEndian>, + color_records_array_offset: Offset32<[ColorRecord]>, /// Index of each palette’s first color record in the combined /// color record array. #[count($num_palettes)] - color_record_indices: [BigEndian], + color_record_indices: [u16], /// Offset from the beginning of CPAL table to the [Palette Types Array][]. /// @@ -29,7 +29,7 @@ table Cpal { #[available(1)] #[nullable] #[read_offset_with($num_palettes)] - palette_types_array_offset: BigEndian]>>, + palette_types_array_offset: Offset32<[u32]>, /// Offset from the beginning of CPAL table to the [Palette Labels Array][]. /// /// This is an array of 'name' table IDs (typically in the font-specific name @@ -40,7 +40,7 @@ table Cpal { #[available(1)] #[nullable] #[read_offset_with($num_palettes)] - palette_labels_array_offset: BigEndian]>>, + palette_labels_array_offset: Offset32<[u16]>, /// Offset from the beginning of CPAL table to the [Palette Entry Labels Array][]. /// /// This is an array of 'name' table IDs (typically in the font-specific name @@ -53,17 +53,17 @@ table Cpal { #[available(1)] #[nullable] #[read_offset_with($num_palette_entries)] - palette_entry_labels_array_offset: BigEndian]>>, + palette_entry_labels_array_offset: Offset32<[u16]>, } /// [CPAL (Color Record)](https://learn.microsoft.com/en-us/typography/opentype/spec/cpal#palette-entries-and-color-records) record record ColorRecord { /// Blue value (B0). - blue: BigEndian, + blue: u8, /// Green value (B1). - green: BigEndian, + green: u8, /// Red value (B2). - red: BigEndian, + red: u8, /// Alpha value (B3). - alpha: BigEndian, + alpha: u8, } diff --git a/resources/codegen_inputs/font.rs b/resources/codegen_inputs/font.rs index 0de1df474..56964ccee 100644 --- a/resources/codegen_inputs/font.rs +++ b/resources/codegen_inputs/font.rs @@ -4,13 +4,13 @@ #[skip_from_obj] table TableDirectory { /// 0x00010000 or 0x4F54544F - sfnt_version: BigEndian, + sfnt_version: u32, /// Number of tables. #[compile(array_len($table_records))] - num_tables: BigEndian, - search_range: BigEndian, - entry_selector: BigEndian, - range_shift: BigEndian, + num_tables: u16, + search_range: u16, + entry_selector: u16, + range_shift: u16, /// Table records array—one for each top-level table in the font #[count($num_tables)] table_records: [ TableRecord ], @@ -20,36 +20,36 @@ table TableDirectory { #[skip_from_obj] record TableRecord { /// Table identifier. - tag: BigEndian, + tag: Tag, /// Checksum for the table. - checksum: BigEndian, + checksum: u32, /// Offset from the beginning of the font data. #[compile_type(u32)] // we set these manually - offset: BigEndian, + offset: Offset32, /// Length of the table. - length: BigEndian, + length: u32, } /// [TTC Header](https://learn.microsoft.com/en-us/typography/opentype/spec/otff#ttc-header) table TTCHeader { /// Font Collection ID string: "ttcf" - ttc_tag: BigEndian, + ttc_tag: Tag, /// Major/minor version of the TTC Header #[version] - version: BigEndian, + version: MajorMinor, /// Number of fonts in TTC - num_fonts: BigEndian, + num_fonts: u32, /// Array of offsets to the TableDirectory for each font from the beginning of the file #[count($num_fonts)] - table_directory_offsets: [BigEndian], + table_directory_offsets: [u32], /// Tag indicating that a DSIG table exists, 0x44534947 ('DSIG') (null if no signature) #[available(MajorMinor::VERSION_2_0)] - dsig_tag: BigEndian, + dsig_tag: u32, /// The length (in bytes) of the DSIG table (null if no signature) #[available(MajorMinor::VERSION_2_0)] - dsig_length: BigEndian, + dsig_length: u32, /// The offset (in bytes) of the DSIG table from the beginning of the TTC file (null if no signature) #[available(MajorMinor::VERSION_2_0)] - dsig_offset: BigEndian, + dsig_offset: u32, } diff --git a/resources/codegen_inputs/gdef.rs b/resources/codegen_inputs/gdef.rs index 10cc2abfa..8773e0585 100644 --- a/resources/codegen_inputs/gdef.rs +++ b/resources/codegen_inputs/gdef.rs @@ -5,33 +5,33 @@ table Gdef { /// The major/minor version of the GDEF table #[version] #[compile(self.compute_version())] - version: BigEndian, + version: MajorMinor, /// Offset to class definition table for glyph type, from beginning /// of GDEF header (may be NULL) #[nullable] - glyph_class_def_offset: BigEndian>, + glyph_class_def_offset: Offset16, /// Offset to attachment point list table, from beginning of GDEF /// header (may be NULL) #[nullable] - attach_list_offset: BigEndian>, + attach_list_offset: Offset16, /// Offset to ligature caret list table, from beginning of GDEF /// header (may be NULL) #[nullable] - lig_caret_list_offset: BigEndian>, + lig_caret_list_offset: Offset16, /// Offset to class definition table for mark attachment type, from /// beginning of GDEF header (may be NULL) #[nullable] - mark_attach_class_def_offset: BigEndian>, + mark_attach_class_def_offset: Offset16, /// Offset to the table of mark glyph set definitions, from /// beginning of GDEF header (may be NULL) #[available(MajorMinor::VERSION_1_2)] #[nullable] - mark_glyph_sets_def_offset: BigEndian>, + mark_glyph_sets_def_offset: Offset16, /// Offset to the Item Variation Store table, from beginning of /// GDEF header (may be NULL) #[available(MajorMinor::VERSION_1_3)] #[nullable] - item_var_store_offset: BigEndian>, + item_var_store_offset: Offset32, } /// Used in the [Glyph Class Definition Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#glyph-class-definition-table) @@ -45,48 +45,48 @@ enum u16 GlyphClassDef { /// [Attachment Point List Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#attachment-point-list-table) table AttachList { /// Offset to Coverage table - from beginning of AttachList table - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Number of glyphs with attachment points #[compile(array_len($attach_point_offsets))] - glyph_count: BigEndian, + glyph_count: u16, /// Array of offsets to AttachPoint tables-from beginning of /// AttachList table-in Coverage Index order #[count($glyph_count)] - attach_point_offsets: [BigEndian>], + attach_point_offsets: [Offset16], } /// Part of [AttachList] table AttachPoint { /// Number of attachment points on this glyph #[compile(array_len($point_indices))] - point_count: BigEndian, + point_count: u16, /// Array of contour point indices -in increasing numerical order #[count($point_count)] - point_indices: [BigEndian], + point_indices: [u16], } /// [Ligature Caret List Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#ligature-caret-list-table) table LigCaretList { /// Offset to Coverage table - from beginning of LigCaretList table - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Number of ligature glyphs #[compile(array_len($lig_glyph_offsets))] - lig_glyph_count: BigEndian, + lig_glyph_count: u16, /// Array of offsets to LigGlyph tables, from beginning of /// LigCaretList table —in Coverage Index order #[count($lig_glyph_count)] - lig_glyph_offsets: [BigEndian>], + lig_glyph_offsets: [Offset16], } /// [Ligature Glyph Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#ligature-glyph-table) table LigGlyph { /// Number of CaretValue tables for this ligature (components - 1) #[compile(array_len($caret_value_offsets))] - caret_count: BigEndian, + caret_count: u16, /// Array of offsets to CaretValue tables, from beginning of /// LigGlyph table — in increasing coordinate order #[count($caret_count)] - caret_value_offsets: [BigEndian>], + caret_value_offsets: [Offset16], } /// [Caret Value Tables](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#caret-value-tables) @@ -100,18 +100,18 @@ format u16 CaretValue { table CaretValueFormat1 { /// Format identifier: format = 1 #[format = 1] - caret_value_format: BigEndian, + caret_value_format: u16, /// X or Y value, in design units - coordinate: BigEndian, + coordinate: i16, } /// [CaretValue Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#caretvalue-format-2) table CaretValueFormat2 { /// Format identifier: format = 2 #[format = 2] - caret_value_format: BigEndian, + caret_value_format: u16, /// Contour point index on glyph - caret_value_point_index: BigEndian, + caret_value_point_index: u16, } /// [CaretValue Format 3](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#caretvalue-format-3) @@ -119,25 +119,25 @@ table CaretValueFormat2 { table CaretValueFormat3 { /// Format identifier-format = 3 #[format = 3] - caret_value_format: BigEndian, + caret_value_format: u16, /// X or Y value, in design units - coordinate: BigEndian, + coordinate: i16, /// Offset to Device table (non-variable font) / Variation Index /// table (variable font) for X or Y value-from beginning of /// CaretValue table - device_offset: BigEndian>, + device_offset: Offset16, } /// [Mark Glyph Sets Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gdef#mark-glyph-sets-table) table MarkGlyphSets { /// Format identifier == 1 #[format = 1] - format: BigEndian, + format: u16, /// Number of mark glyph sets defined #[compile(array_len($coverage_offsets))] - mark_glyph_set_count: BigEndian, + mark_glyph_set_count: u16, /// Array of offsets to mark glyph set coverage tables, from the /// start of the MarkGlyphSets table. #[count($mark_glyph_set_count)] - coverage_offsets: [BigEndian>], + coverage_offsets: [Offset32], } diff --git a/resources/codegen_inputs/glyf.rs b/resources/codegen_inputs/glyf.rs index 74d7e574b..b533570ac 100644 --- a/resources/codegen_inputs/glyf.rs +++ b/resources/codegen_inputs/glyf.rs @@ -7,15 +7,15 @@ table Glyf {} ///// If the number of contours is greater than or equal to zero, ///// this is a simple glyph. If negative, this is a composite glyph ///// — the value -1 should be used for composite glyphs. - //number_of_contours: BigEndian, + //number_of_contours: i16, ///// Minimum x for coordinate data. - //x_min: BigEndian, + //x_min: i16, ///// Minimum y for coordinate data. - //y_min: BigEndian, + //y_min: i16, ///// Maximum x for coordinate data. - //x_max: BigEndian, + //x_max: i16, ///// Maximum y for coordinate data. - //y_max: BigEndian, + //y_max: i16, //} @@ -24,26 +24,26 @@ table SimpleGlyph { /// If the number of contours is greater than or equal to zero, /// this is a simple glyph. If negative, this is a composite glyph /// — the value -1 should be used for composite glyphs. - number_of_contours: BigEndian, + number_of_contours: i16, /// Minimum x for coordinate data. - x_min: BigEndian, + x_min: i16, /// Minimum y for coordinate data. - y_min: BigEndian, + y_min: i16, /// Maximum x for coordinate data. - x_max: BigEndian, + x_max: i16, /// Maximum y for coordinate data. - y_max: BigEndian, + y_max: i16, /// Array of point indices for the last point of each contour, /// in increasing numeric order #[count($number_of_contours.max(0) as usize)] - end_pts_of_contours: [BigEndian], + end_pts_of_contours: [u16], /// Total number of bytes for instructions. If instructionLength is /// zero, no instructions are present for this glyph, and this /// field is followed directly by the flags field. - instruction_length: BigEndian, + instruction_length: u16, /// Array of instruction byte code for the glyph. #[count($instruction_length)] - instructions: [BigEndian], + instructions: [u8], #[count(..)] //#[hidden] /// the raw data for flags & x/y coordinates @@ -52,7 +52,7 @@ table SimpleGlyph { ///// Array of flag elements. See below for details regarding the ///// number of flag array elements. //#[count(variable)] - //flags: [BigEndian], + //flags: [SimpleGlyphFlags], ///// Contour point x-coordinates. See below for details regarding ///// the number of coordinate array elements. Coordinate for the ///// first point is relative to (0,0); others are relative to @@ -143,20 +143,20 @@ table CompositeGlyph { /// If the number of contours is greater than or equal to zero, /// this is a simple glyph. If negative, this is a composite glyph /// — the value -1 should be used for composite glyphs. - number_of_contours: BigEndian, + number_of_contours: i16, /// Minimum x for coordinate data. - x_min: BigEndian, + x_min: i16, /// Minimum y for coordinate data. - y_min: BigEndian, + y_min: i16, /// Maximum x for coordinate data. - x_max: BigEndian, + x_max: i16, /// Maximum y for coordinate data. - y_max: BigEndian, + y_max: i16, //header: GlyphHeader, /// component flag - //flags: BigEndian, + //flags: CompositeGlyphFlags, /// glyph index of component - //glyph_index: BigEndian, + //glyph_index: u16, #[count(..)] component_data: [u8], diff --git a/resources/codegen_inputs/gpos.rs b/resources/codegen_inputs/gpos.rs index bbe669056..86bbef781 100644 --- a/resources/codegen_inputs/gpos.rs +++ b/resources/codegen_inputs/gpos.rs @@ -7,16 +7,16 @@ table Gpos { /// The major and minor version of the GPOS table, as a tuple (u16, u16) #[version] #[compile(self.compute_version())] - version: BigEndian, + version: MajorMinor, /// Offset to ScriptList table, from beginning of GPOS table - script_list_offset: BigEndian>, + script_list_offset: Offset16, /// Offset to FeatureList table, from beginning of GPOS table - feature_list_offset: BigEndian>, + feature_list_offset: Offset16, /// Offset to LookupList table, from beginning of GPOS table - lookup_list_offset: BigEndian>, + lookup_list_offset: Offset16, #[available(MajorMinor::VERSION_1_1)] #[nullable] - feature_variations_offset: BigEndian>, + feature_variations_offset: Offset32, } /// A [GPOS Lookup](https://learn.microsoft.com/en-us/typography/opentype/spec/gpos#gsubLookupTypeEnum) subtable. @@ -68,52 +68,52 @@ format u16 AnchorTable { table AnchorFormat1 { /// Format identifier, = 1 #[format = 1] - anchor_format: BigEndian, + anchor_format: u16, /// Horizontal value, in design units - x_coordinate: BigEndian, + x_coordinate: i16, /// Vertical value, in design units - y_coordinate: BigEndian, + y_coordinate: i16, } /// [Anchor Table Format 2](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#anchor-table-format-2-design-units-plus-contour-point): Design Units Plus Contour Point table AnchorFormat2 { /// Format identifier, = 2 #[format = 2] - anchor_format: BigEndian, + anchor_format: u16, /// Horizontal value, in design units - x_coordinate: BigEndian, + x_coordinate: i16, /// Vertical value, in design units - y_coordinate: BigEndian, + y_coordinate: i16, /// Index to glyph contour point - anchor_point: BigEndian, + anchor_point: u16, } /// [Anchor Table Format 3](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#anchor-table-format-3-design-units-plus-device-or-variationindex-tables): Design Units Plus Device or VariationIndex Tables table AnchorFormat3 { /// Format identifier, = 3 #[format = 3] - anchor_format: BigEndian, + anchor_format: u16, /// Horizontal value, in design units - x_coordinate: BigEndian, + x_coordinate: i16, /// Vertical value, in design units - y_coordinate: BigEndian, + y_coordinate: i16, /// Offset to Device table (non-variable font) / VariationIndex /// table (variable font) for X coordinate, from beginning of /// Anchor table (may be NULL) #[nullable] - x_device_offset: BigEndian>, + x_device_offset: Offset16, /// Offset to Device table (non-variable font) / VariationIndex /// table (variable font) for Y coordinate, from beginning of /// Anchor table (may be NULL) #[nullable] - y_device_offset: BigEndian>, + y_device_offset: Offset16, } /// [Mark Array Table](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#mark-array-table) table MarkArray { /// Number of MarkRecords #[compile(array_len($mark_records))] - mark_count: BigEndian, + mark_count: u16, /// Array of MarkRecords, ordered by corresponding glyphs in the /// associated mark Coverage table. #[count($mark_count)] @@ -123,9 +123,9 @@ table MarkArray { /// Part of [MarkArray] record MarkRecord { /// Class defined for the associated mark. - mark_class: BigEndian, + mark_class: u16, /// Offset to Anchor table, from beginning of MarkArray table. - mark_anchor_offset: BigEndian>, + mark_anchor_offset: Offset16, } /// [Lookup Type 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-1-single-adjustment-positioning-subtable): Single Adjustment Positioning Subtable @@ -138,12 +138,12 @@ format u16 SinglePos { table SinglePosFormat1 { /// Format identifier: format = 1 #[format = 1] - pos_format: BigEndian, + pos_format: u16, /// Offset to Coverage table, from beginning of SinglePos subtable. - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Defines the types of data in the ValueRecord. #[compile(self.compute_value_format())] - value_format: BigEndian, + value_format: ValueFormat, /// Defines positioning value(s) — applied to all glyphs in the /// Coverage table. #[read_with($value_format)] @@ -154,16 +154,16 @@ table SinglePosFormat1 { table SinglePosFormat2 { /// Format identifier: format = 2 #[format = 2] - pos_format: BigEndian, + pos_format: u16, /// Offset to Coverage table, from beginning of SinglePos subtable. - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Defines the types of data in the ValueRecords. #[compile(self.compute_value_format())] - value_format: BigEndian, + value_format: ValueFormat, /// Number of ValueRecords — must equal glyphCount in the /// Coverage table. #[compile(array_len($value_records))] - value_count: BigEndian, + value_count: u16, /// Array of ValueRecords — positioning values applied to glyphs. #[count($value_count)] #[read_with($value_format)] @@ -180,25 +180,25 @@ format u16 PairPos { table PairPosFormat1 { /// Format identifier: format = 1 #[format = 1] - pos_format: BigEndian, + pos_format: u16, /// Offset to Coverage table, from beginning of PairPos subtable. - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Defines the types of data in valueRecord1 — for the first /// glyph in the pair (may be zero). #[compile(self.compute_value_format1())] - value_format1: BigEndian, + value_format1: ValueFormat, /// Defines the types of data in valueRecord2 — for the second /// glyph in the pair (may be zero). #[compile(self.compute_value_format2())] - value_format2: BigEndian, + value_format2: ValueFormat, /// Number of PairSet tables #[compile(array_len($pair_set_offsets))] - pair_set_count: BigEndian, + pair_set_count: u16, /// Array of offsets to PairSet tables. Offsets are from beginning /// of PairPos subtable, ordered by Coverage Index. #[count($pair_set_count)] #[read_offset_with($value_format1, $value_format2)] - pair_set_offsets: [BigEndian>], + pair_set_offsets: [Offset16], } /// Part of [PairPosFormat1] @@ -206,7 +206,7 @@ table PairPosFormat1 { table PairSet { /// Number of PairValueRecords #[compile(array_len($pair_value_records))] - pair_value_count: BigEndian, + pair_value_count: u16, /// Array of PairValueRecords, ordered by glyph ID of the second /// glyph. #[count($pair_value_count)] @@ -219,7 +219,7 @@ table PairSet { record PairValueRecord { /// Glyph ID of second glyph in the pair (first glyph is listed in /// the Coverage table). - second_glyph: BigEndian, + second_glyph: GlyphId, /// Positioning data for the first glyph in the pair. #[read_with($value_format1)] value_record1: ValueRecord, @@ -232,29 +232,29 @@ record PairValueRecord { table PairPosFormat2 { /// Format identifier: format = 2 #[format = 2] - pos_format: BigEndian, + pos_format: u16, /// Offset to Coverage table, from beginning of PairPos subtable. - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// ValueRecord definition — for the first glyph of the pair (may /// be zero). #[compile(self.compute_value_format1())] - value_format1: BigEndian, + value_format1: ValueFormat, /// ValueRecord definition — for the second glyph of the pair /// (may be zero). #[compile(self.compute_value_format2())] - value_format2: BigEndian, + value_format2: ValueFormat, /// Offset to ClassDef table, from beginning of PairPos subtable /// — for the first glyph of the pair. - class_def1_offset: BigEndian>, + class_def1_offset: Offset16, /// Offset to ClassDef table, from beginning of PairPos subtable /// — for the second glyph of the pair. - class_def2_offset: BigEndian>, + class_def2_offset: Offset16, /// Number of classes in classDef1 table — includes Class 0. #[compile(self.compute_class1_count())] - class1_count: BigEndian, + class1_count: u16, /// Number of classes in classDef2 table — includes Class 0. #[compile(self.compute_class2_count())] - class2_count: BigEndian, + class2_count: u16, /// Array of Class1 records, ordered by classes in classDef1. #[read_with($class2_count, $value_format1, $value_format2)] #[count($class1_count)] @@ -291,12 +291,12 @@ record Class2Record { table CursivePosFormat1 { /// Format identifier: format = 1 #[format = 1] - pos_format: BigEndian, + pos_format: u16, /// Offset to Coverage table, from beginning of CursivePos subtable. - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Number of EntryExit records #[compile(array_len($entry_exit_record))] - entry_exit_count: BigEndian, + entry_exit_count: u16, /// Array of EntryExit records, in Coverage index order. #[count($entry_exit_count)] entry_exit_record: [EntryExitRecord], @@ -307,11 +307,11 @@ record EntryExitRecord { /// Offset to entryAnchor table, from beginning of CursivePos /// subtable (may be NULL). #[nullable] - entry_anchor_offset: BigEndian>, + entry_anchor_offset: Offset16, /// Offset to exitAnchor table, from beginning of CursivePos /// subtable (may be NULL). #[nullable] - exit_anchor_offset: BigEndian>, + exit_anchor_offset: Offset16, } /////// [Lookup Type 4](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-4-mark-to-base-attachment-positioning-subtable): Mark-to-Base Attachment Positioning Subtable @@ -324,23 +324,23 @@ record EntryExitRecord { table MarkBasePosFormat1 { /// Format identifier: format = 1 #[format = 1] - pos_format: BigEndian, + pos_format: u16, /// Offset to markCoverage table, from beginning of MarkBasePos /// subtable. - mark_coverage_offset: BigEndian>, + mark_coverage_offset: Offset16, /// Offset to baseCoverage table, from beginning of MarkBasePos /// subtable. - base_coverage_offset: BigEndian>, + base_coverage_offset: Offset16, /// Number of classes defined for marks #[compile(self.compute_mark_class_count())] - mark_class_count: BigEndian, + mark_class_count: u16, /// Offset to MarkArray table, from beginning of MarkBasePos /// subtable. - mark_array_offset: BigEndian>, + mark_array_offset: Offset16, /// Offset to BaseArray table, from beginning of MarkBasePos /// subtable. #[read_offset_with($mark_class_count)] - base_array_offset: BigEndian>, + base_array_offset: Offset16, } /// Part of [MarkBasePosFormat1] @@ -348,7 +348,7 @@ table MarkBasePosFormat1 { table BaseArray { /// Number of BaseRecords #[compile(array_len($base_records))] - base_count: BigEndian, + base_count: u16, /// Array of BaseRecords, in order of baseCoverage Index. #[count($base_count)] #[read_with($mark_class_count)] @@ -363,30 +363,30 @@ record BaseRecord<'a> { /// (offsets may be NULL). #[nullable] #[count($mark_class_count)] - base_anchor_offsets: [BigEndian>], + base_anchor_offsets: [Offset16], } /// [Mark-to-Ligature Positioning Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#mark-to-ligature-attachment-positioning-format-1-mark-to-ligature-attachment): Mark-to-Ligature Attachment table MarkLigPosFormat1 { /// Format identifier: format = 1 #[format = 1] - pos_format: BigEndian, + pos_format: u16, /// Offset to markCoverage table, from beginning of MarkLigPos /// subtable. - mark_coverage_offset: BigEndian>, + mark_coverage_offset: Offset16, /// Offset to ligatureCoverage table, from beginning of MarkLigPos /// subtable. - ligature_coverage_offset: BigEndian>, + ligature_coverage_offset: Offset16, /// Number of defined mark classes #[compile(self.compute_mark_class_count())] - mark_class_count: BigEndian, + mark_class_count: u16, /// Offset to MarkArray table, from beginning of MarkLigPos /// subtable. - mark_array_offset: BigEndian>, + mark_array_offset: Offset16, /// Offset to LigatureArray table, from beginning of MarkLigPos /// subtable. #[read_offset_with($mark_class_count)] - ligature_array_offset: BigEndian>, + ligature_array_offset: Offset16, } /// Part of [MarkLigPosFormat1] @@ -394,13 +394,13 @@ table MarkLigPosFormat1 { table LigatureArray { /// Number of LigatureAttach table offsets #[compile(array_len($ligature_attach_offsets))] - ligature_count: BigEndian, + ligature_count: u16, /// Array of offsets to LigatureAttach tables. Offsets are from /// beginning of LigatureArray table, ordered by ligatureCoverage /// index. #[count($ligature_count)] #[read_offset_with($mark_class_count)] - ligature_attach_offsets: [BigEndian>], + ligature_attach_offsets: [Offset16], } /// Part of [MarkLigPosFormat1] @@ -408,7 +408,7 @@ table LigatureArray { table LigatureAttach { /// Number of ComponentRecords in this ligature #[compile(array_len($component_records))] - component_count: BigEndian, + component_count: u16, /// Array of Component records, ordered in writing direction. #[count($component_count)] #[read_with($mark_class_count)] @@ -423,30 +423,30 @@ record ComponentRecord<'a> { /// (offsets may be NULL). #[nullable] #[count($mark_class_count)] - ligature_anchor_offsets: [BigEndian>], + ligature_anchor_offsets: [Offset16], } /// [Mark-to-Mark Attachment Positioning Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#mark-to-mark-attachment-positioning-format-1-mark-to-mark-attachment): Mark-to-Mark Attachment table MarkMarkPosFormat1 { /// Format identifier: format = 1 #[format = 1] - pos_format: BigEndian, + pos_format: u16, /// Offset to Combining Mark Coverage table, from beginning of /// MarkMarkPos subtable. - mark1_coverage_offset: BigEndian>, + mark1_coverage_offset: Offset16, /// Offset to Base Mark Coverage table, from beginning of /// MarkMarkPos subtable. - mark2_coverage_offset: BigEndian>, + mark2_coverage_offset: Offset16, /// Number of Combining Mark classes defined #[compile(self.compute_mark_class_count())] - mark_class_count: BigEndian, + mark_class_count: u16, /// Offset to MarkArray table for mark1, from beginning of /// MarkMarkPos subtable. - mark1_array_offset: BigEndian>, + mark1_array_offset: Offset16, /// Offset to Mark2Array table for mark2, from beginning of /// MarkMarkPos subtable. #[read_offset_with($mark_class_count)] - mark2_array_offset: BigEndian>, + mark2_array_offset: Offset16, } /// Part of [MarkMarkPosFormat1]Class2Record @@ -454,7 +454,7 @@ table MarkMarkPosFormat1 { table Mark2Array { /// Number of Mark2 records #[compile(array_len($mark2_records))] - mark2_count: BigEndian, + mark2_count: u16, /// Array of Mark2Records, in Coverage order. #[count($mark2_count)] #[read_with($mark_class_count)] @@ -469,7 +469,7 @@ record Mark2Record<'a> { /// be NULL). #[count($mark_class_count)] #[nullable] - mark2_anchor_offsets: [BigEndian>], + mark2_anchor_offsets: [Offset16], } /// [Extension Positioning Subtable Format 1](https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#extension-positioning-subtable-format-1) @@ -478,14 +478,14 @@ record Mark2Record<'a> { table ExtensionPosFormat1 { /// Format identifier: format = 1 #[format = 1] - pos_format: BigEndian, + pos_format: u16, /// Lookup type of subtable referenced by extensionOffset (i.e. the /// extension subtable). - extension_lookup_type: BigEndian, + extension_lookup_type: u16, /// Offset to the extension subtable, of lookup type /// extensionLookupType, relative to the start of the /// ExtensionPosFormat1 subtable. - extension_offset: BigEndian>, + extension_offset: Offset32, } /// A [GPOS Extension Positioning](https://learn.microsoft.com/en-us/typography/opentype/spec/gpos#lookuptype-9-extension-positioning) subtable diff --git a/resources/codegen_inputs/gsub.rs b/resources/codegen_inputs/gsub.rs index 9a3464dfc..d50e9bfa6 100644 --- a/resources/codegen_inputs/gsub.rs +++ b/resources/codegen_inputs/gsub.rs @@ -6,18 +6,18 @@ table Gsub { /// The major and minor version of the GSUB table, as a tuple (u16, u16) #[version] #[compile(self.compute_version())] - version: BigEndian, + version: MajorMinor, /// Offset to ScriptList table, from beginning of GSUB table - script_list_offset: BigEndian>, + script_list_offset: Offset16, /// Offset to FeatureList table, from beginning of GSUB table - feature_list_offset: BigEndian>, + feature_list_offset: Offset16, /// Offset to LookupList table, from beginning of GSUB table - lookup_list_offset: BigEndian>, + lookup_list_offset: Offset16, /// Offset to FeatureVariations table, from beginning of the GSUB /// table (may be NULL) #[available(MajorMinor::VERSION_1_1)] #[nullable] - feature_variations_offset: BigEndian>, + feature_variations_offset: Offset32, } /// A [GSUB Lookup](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#gsubLookupTypeEnum) subtable. @@ -42,45 +42,45 @@ format u16 SingleSubst { table SingleSubstFormat1 { /// Format identifier: format = 1 #[format = 1] - subst_format: BigEndian, + subst_format: u16, /// Offset to Coverage table, from beginning of substitution /// subtable - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Add to original glyph ID to get substitute glyph ID - delta_glyph_id: BigEndian, + delta_glyph_id: i16, } /// [Single Substitution Format 2](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#12-single-substitution-format-2) table SingleSubstFormat2 { /// Format identifier: format = 2 #[format = 2] - subst_format: BigEndian, + subst_format: u16, /// Offset to Coverage table, from beginning of substitution /// subtable - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Number of glyph IDs in the substituteGlyphIDs array #[compile(array_len($substitute_glyph_ids))] - glyph_count: BigEndian, + glyph_count: u16, /// Array of substitute glyph IDs — ordered by Coverage index #[count($glyph_count)] - substitute_glyph_ids: [BigEndian], + substitute_glyph_ids: [GlyphId], } /// [Multiple Substitution Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#21-multiple-substitution-format-1) table MultipleSubstFormat1 { /// Format identifier: format = 1 #[format = 1] - subst_format: BigEndian, + subst_format: u16, /// Offset to Coverage table, from beginning of substitution /// subtable - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Number of Sequence table offsets in the sequenceOffsets array #[compile(array_len($sequence_offsets))] - sequence_count: BigEndian, + sequence_count: u16, /// Array of offsets to Sequence tables. Offsets are from beginning /// of substitution subtable, ordered by Coverage index #[count($sequence_count)] - sequence_offsets: [BigEndian>], + sequence_offsets: [Offset16], } /// Part of [MultipleSubstFormat1] @@ -88,78 +88,78 @@ table Sequence { /// Number of glyph IDs in the substituteGlyphIDs array. This must /// always be greater than 0. #[compile(array_len($substitute_glyph_ids))] - glyph_count: BigEndian, + glyph_count: u16, /// String of glyph IDs to substitute #[count($glyph_count)] - substitute_glyph_ids: [BigEndian], + substitute_glyph_ids: [GlyphId], } /// [Alternate Substitution Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#31-alternate-substitution-format-1) table AlternateSubstFormat1 { /// Format identifier: format = 1 #[format = 1] - subst_format: BigEndian, + subst_format: u16, /// Offset to Coverage table, from beginning of substitution /// subtable - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Number of AlternateSet tables #[compile(array_len($alternate_set_offsets))] - alternate_set_count: BigEndian, + alternate_set_count: u16, /// Array of offsets to AlternateSet tables. Offsets are from /// beginning of substitution subtable, ordered by Coverage index #[count($alternate_set_count)] - alternate_set_offsets: [BigEndian>], + alternate_set_offsets: [Offset16], } /// Part of [AlternateSubstFormat1] table AlternateSet { /// Number of glyph IDs in the alternateGlyphIDs array #[compile(array_len($alternate_glyph_ids))] - glyph_count: BigEndian, + glyph_count: u16, /// Array of alternate glyph IDs, in arbitrary order #[count($glyph_count)] - alternate_glyph_ids: [BigEndian], + alternate_glyph_ids: [GlyphId], } /// [Ligature Substitution Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#41-ligature-substitution-format-1) table LigatureSubstFormat1 { /// Format identifier: format = 1 #[format = 1] - subst_format: BigEndian, + subst_format: u16, /// Offset to Coverage table, from beginning of substitution /// subtable - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Number of LigatureSet tables #[compile(array_len($ligature_set_offsets))] - ligature_set_count: BigEndian, + ligature_set_count: u16, /// Array of offsets to LigatureSet tables. Offsets are from /// beginning of substitution subtable, ordered by Coverage index #[count($ligature_set_count)] - ligature_set_offsets: [BigEndian>], + ligature_set_offsets: [Offset16], } /// Part of [LigatureSubstFormat1] table LigatureSet { /// Number of Ligature tables #[compile(array_len($ligature_offsets))] - ligature_count: BigEndian, + ligature_count: u16, /// Array of offsets to Ligature tables. Offsets are from beginning /// of LigatureSet table, ordered by preference. #[count($ligature_count)] - ligature_offsets: [BigEndian>], + ligature_offsets: [Offset16], } /// Part of [LigatureSubstFormat1] table Ligature { /// glyph ID of ligature to substitute - ligature_glyph: BigEndian, + ligature_glyph: GlyphId, /// Number of components in the ligature #[compile(plus_one($component_glyph_ids.len()))] - component_count: BigEndian, + component_count: u16, /// Array of component glyph IDs — start with the second /// component, ordered in writing direction #[count(minus_one($component_count))] - component_glyph_ids: [BigEndian], + component_glyph_ids: [GlyphId], } /// [Extension Substitution Subtable Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#71-extension-substitution-subtable-format-1) @@ -168,14 +168,14 @@ table Ligature { table ExtensionSubstFormat1 { /// Format identifier. Set to 1. #[format = 1] - subst_format: BigEndian, + subst_format: u16, /// Lookup type of subtable referenced by extensionOffset (that is, /// the extension subtable). - extension_lookup_type: BigEndian, + extension_lookup_type: u16, /// Offset to the extension subtable, of lookup type /// extensionLookupType, relative to the start of the /// ExtensionSubstFormat1 subtable. - extension_offset: BigEndian>, + extension_offset: Offset32, } /// A [GSUB Extension Substitution](https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#ES) subtable @@ -193,29 +193,29 @@ table ExtensionSubstFormat1 { table ReverseChainSingleSubstFormat1 { /// Format identifier: format = 1 #[format = 1] - subst_format: BigEndian, + subst_format: u16, /// Offset to Coverage table, from beginning of substitution /// subtable. - coverage_offset: BigEndian>, + coverage_offset: Offset16, /// Number of glyphs in the backtrack sequence. #[compile(array_len($backtrack_coverage_offsets))] - backtrack_glyph_count: BigEndian, + backtrack_glyph_count: u16, /// Array of offsets to coverage tables in backtrack sequence, in /// glyph sequence order. #[count($backtrack_glyph_count)] - backtrack_coverage_offsets: [BigEndian>], + backtrack_coverage_offsets: [Offset16], /// Number of glyphs in lookahead sequence. #[compile(array_len($lookahead_coverage_offsets))] - lookahead_glyph_count: BigEndian, + lookahead_glyph_count: u16, /// Array of offsets to coverage tables in lookahead sequence, in /// glyph sequence order. #[count($lookahead_glyph_count)] - lookahead_coverage_offsets: [BigEndian>], + lookahead_coverage_offsets: [Offset16], /// Number of glyph IDs in the substituteGlyphIDs array. #[compile(array_len($substitute_glyph_ids))] - glyph_count: BigEndian, + glyph_count: u16, /// Array of substitute glyph IDs — ordered by Coverage index. #[count($glyph_count)] - substitute_glyph_ids: [BigEndian], + substitute_glyph_ids: [GlyphId], } diff --git a/resources/codegen_inputs/head.rs b/resources/codegen_inputs/head.rs index fb604e0f7..ed617d476 100644 --- a/resources/codegen_inputs/head.rs +++ b/resources/codegen_inputs/head.rs @@ -4,49 +4,49 @@ table Head { /// Version number of the font header table, set to (1, 0) #[compile(MajorMinor::VERSION_1_0)] - version: BigEndian, + version: MajorMinor, /// Set by font manufacturer. - font_revision: BigEndian, + font_revision: Fixed, /// To compute: set it to 0, sum the entire font as uint32, then /// store 0xB1B0AFBA - sum. If the font is used as a component in a /// font collection file, the value of this field will be /// invalidated by changes to the file structure and font table /// directory, and must be ignored. - checksum_adjustment: BigEndian, + checksum_adjustment: u32, /// Set to 0x5F0F3CF5. #[compile(0x5F0F3CF5)] - magic_number: BigEndian, + magic_number: u32, /// See the flags enum - flags: BigEndian, + flags: u16, /// Set to a value from 16 to 16384. Any value in this range is /// valid. In fonts that have TrueType outlines, a power of 2 is /// recommended as this allows performance optimizations in some /// rasterizers. - units_per_em: BigEndian, + units_per_em: u16, /// Number of seconds since 12:00 midnight that started January 1st /// 1904 in GMT/UTC time zone. - created: BigEndian, + created: LongDateTime, /// Number of seconds since 12:00 midnight that started January 1st /// 1904 in GMT/UTC time zone. - modified: BigEndian, + modified: LongDateTime, /// Minimum x coordinate across all glyph bounding boxes. - x_min: BigEndian, + x_min: i16, /// Minimum y coordinate across all glyph bounding boxes. - y_min: BigEndian, + y_min: i16, /// Maximum x coordinate across all glyph bounding boxes. - x_max: BigEndian, + x_max: i16, /// Maximum y coordinate across all glyph bounding boxes. - y_max: BigEndian, + y_max: i16, /// see somewhere else - mac_style: BigEndian, + mac_style: u16, /// Smallest readable size in pixels. - lowest_rec_ppem: BigEndian, + lowest_rec_ppem: u16, /// Deprecated (Set to 2). #[compile(2)] - font_direction_hint: BigEndian, + font_direction_hint: i16, /// 0 for short offsets (Offset16), 1 for long (Offset32). - index_to_loc_format: BigEndian, + index_to_loc_format: i16, /// 0 for current format. #[compile(0)] - glyph_data_format: BigEndian, + glyph_data_format: i16, } diff --git a/resources/codegen_inputs/hhea.rs b/resources/codegen_inputs/hhea.rs index 3e66d858f..309ba7bcb 100644 --- a/resources/codegen_inputs/hhea.rs +++ b/resources/codegen_inputs/hhea.rs @@ -4,53 +4,53 @@ table Hhea { /// The major/minor version (1, 0) #[compile(MajorMinor::VERSION_1_0)] - version: BigEndian, + version: MajorMinor, /// Typographic ascent—see note below. - ascender: BigEndian, + ascender: FWord, /// Typographic descent—see note below. - descender: BigEndian, + descender: FWord, /// Typographic line gap. Negative LineGap values are treated as /// zero in some legacy platform implementations. - line_gap: BigEndian, + line_gap: FWord, /// Maximum advance width value in 'hmtx' table. - advance_width_max: BigEndian, + advance_width_max: UfWord, /// Minimum left sidebearing value in 'hmtx' table for glyphs with /// contours (empty glyphs should be ignored). - min_left_side_bearing: BigEndian, + min_left_side_bearing: FWord, /// Minimum right sidebearing value; calculated as min(aw - (lsb + /// xMax - xMin)) for glyphs with contours (empty glyphs should be /// ignored). - min_right_side_bearing: BigEndian, + min_right_side_bearing: FWord, /// Max(lsb + (xMax - xMin)). - x_max_extent: BigEndian, + x_max_extent: FWord, /// Used to calculate the slope of the cursor (rise/run); 1 for /// vertical. - caret_slope_rise: BigEndian, + caret_slope_rise: i16, /// 0 for vertical. - caret_slope_run: BigEndian, + caret_slope_run: i16, /// The amount by which a slanted highlight on a glyph needs to be /// shifted to produce the best appearance. Set to 0 for /// non-slanted fonts - caret_offset: BigEndian, + caret_offset: i16, /// set to 0 #[skip_getter] #[compile(0)] - reserved1: BigEndian, + reserved1: i16, /// set to 0 #[skip_getter] #[compile(0)] - reserved2: BigEndian, + reserved2: i16, /// set to 0 #[skip_getter] #[compile(0)] - reserved3: BigEndian, + reserved3: i16, /// set to 0 #[skip_getter] #[compile(0)] - reserved4: BigEndian, + reserved4: i16, /// 0 for current format. #[compile(0)] - metric_data_format: BigEndian, + metric_data_format: i16, /// Number of hMetric entries in 'hmtx' table - number_of_h_metrics: BigEndian, + number_of_h_metrics: u16, } diff --git a/resources/codegen_inputs/hmtx.rs b/resources/codegen_inputs/hmtx.rs index 8d178746e..c99b171db 100644 --- a/resources/codegen_inputs/hmtx.rs +++ b/resources/codegen_inputs/hmtx.rs @@ -10,13 +10,13 @@ table Hmtx { /// Left side bearings for glyph IDs greater than or equal to /// numberOfHMetrics. #[count($num_glyphs.saturating_sub($number_of_h_metrics) as usize)] - left_side_bearings: [BigEndian], + left_side_bearings: [i16], } record LongHorMetric { /// Advance width, in font design units. - advance_width: BigEndian, + advance_width: u16, /// Glyph left side bearing, in font design units. - lsb: BigEndian, + lsb: i16, } diff --git a/resources/codegen_inputs/layout.rs b/resources/codegen_inputs/layout.rs index 3804c1723..73ddc44a2 100644 --- a/resources/codegen_inputs/layout.rs +++ b/resources/codegen_inputs/layout.rs @@ -5,7 +5,7 @@ table ScriptList { /// Number of ScriptRecords #[compile(array_len($script_records))] - script_count: BigEndian, + script_count: u16, /// Array of ScriptRecords, listed alphabetically by script tag #[count($script_count)] script_records: [ScriptRecord], @@ -14,9 +14,9 @@ table ScriptList { /// [Script Record](https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#script-list-table-and-script-record) record ScriptRecord { /// 4-byte script tag identifier - script_tag: BigEndian, + script_tag: Tag, /// Offset to Script table, from beginning of ScriptList - script_offset: BigEndian>, + script_offset: Offset16