From c04dcd128dbd34e25f33a8b3ac29e7351f58062f Mon Sep 17 00:00:00 2001 From: The-Nice-One Date: Wed, 6 May 2026 20:59:01 -0400 Subject: [PATCH 1/6] Port core module to use bitflags crate --- Cargo.lock | 98 +++++++++++++----------- Cargo.toml | 5 +- src/core/mod.rs | 76 +++++++++++++++++- src/core/tables/character/deserialize.rs | 39 +++++----- src/core/tables/character/mod.rs | 32 ++++++-- src/core/tables/character/serialize.rs | 47 +++++------- src/core/tables/color/mod.rs | 50 ++++++------ src/core/tables/font/deserialize.rs | 8 +- src/core/tables/font/serialize.rs | 14 ++-- src/core/tables/pixmap/deserialize.rs | 26 +++++-- src/core/tables/pixmap/serialize.rs | 38 ++++----- 11 files changed, 264 insertions(+), 169 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af36f97..213bd51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.21" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" dependencies = [ "anstyle", "anstyle-parse", @@ -28,15 +28,15 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" [[package]] name = "anstyle-parse" -version = "0.2.7" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" dependencies = [ "utf8parse", ] @@ -61,17 +61,26 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "bitflags" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" +dependencies = [ + "serde_core", +] + [[package]] name = "colorchoice" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" [[package]] name = "env_filter" -version = "0.1.4" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" +checksum = "32e90c2accc4b07a8456ea0debdc2e7587bdd890680d71173a15d4ae604f6eef" dependencies = [ "log", "regex", @@ -79,9 +88,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.8" +version = "0.11.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f" +checksum = "0621c04f2196ac3f488dd583365b9c09be011a4ab8b9f37248ffcc8f6198b56a" dependencies = [ "anstream", "anstyle", @@ -98,9 +107,9 @@ checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] name = "jiff" -version = "0.2.16" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49cce2b81f2098e7e3efc35bc2e0a6b7abec9d34128283d7a26fa8f32a6dbb35" +checksum = "1a3546dc96b6d42c5f24902af9e2538e82e39ad350b0c766eb3fbf2d8f3d8359" dependencies = [ "jiff-static", "log", @@ -111,9 +120,9 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.16" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "980af8b43c3ad5d8d349ace167ec8170839f753a42d233ba19e08afe1850fa69" +checksum = "2a8c8b344124222efd714b73bb41f8b5120b27a7cc1c75593a6ff768d9d05aa4" dependencies = [ "proc-macro2", "quote", @@ -122,15 +131,15 @@ dependencies = [ [[package]] name = "log" -version = "0.4.27" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "memchr" -version = "2.7.6" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "once_cell_polyfill" @@ -140,42 +149,42 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "portable-atomic" -version = "1.11.1" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" [[package]] name = "portable-atomic-util" -version = "0.2.4" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" +checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" dependencies = [ "portable-atomic", ] [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.40" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] [[package]] name = "regex" -version = "1.12.2" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" dependencies = [ "aho-corasick", "memchr", @@ -185,9 +194,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" dependencies = [ "aho-corasick", "memchr", @@ -196,15 +205,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" [[package]] name = "serde" -version = "1.0.225" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6c24dee235d0da097043389623fb913daddf92c76e9f5a1db88607a0bcbd1d" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ "serde_core", "serde_derive", @@ -212,18 +221,18 @@ dependencies = [ [[package]] name = "serde_core" -version = "1.0.225" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "659356f9a0cb1e529b24c01e43ad2bdf520ec4ceaf83047b83ddcc2251f96383" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.225" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea936adf78b1f766949a4977b91d2f5595825bd6ec079aa9543ad2685fc4516" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -234,6 +243,7 @@ dependencies = [ name = "spf" version = "0.8.0-alpha.0" dependencies = [ + "bitflags", "env_logger", "log", "serde", @@ -241,9 +251,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.101" +version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", @@ -252,9 +262,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "utf8parse" diff --git a/Cargo.toml b/Cargo.toml index ea2a07c..3e9331c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,14 +21,15 @@ rustdoc-args = ["--cfg", "docsrs"] default = ["std", "log", "serde", "ffi", "articles", "tagging"] std = [] log = ["dep:log"] -serde = ["dep:serde"] +serde = ["dep:serde", "bitflags/serde"] ffi = [] articles = [] tagging = [] [dependencies] +bitflags = { version = "2.11.1" } log = { version = "0.4.27", optional = true } -serde = { version = "1.0.225", features = ["derive"], optional = true } +serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] env_logger = "0.11.8" diff --git a/src/core/mod.rs b/src/core/mod.rs index ecef6f7..9285404 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -25,6 +25,7 @@ pub(crate) mod deserialize; pub(crate) mod serialize; pub(crate) mod tables; +use bitflags::bitflags; use byte::{ByteReader, ByteReaderImpl}; #[cfg(not(feature = "tagging"))] @@ -38,6 +39,60 @@ pub(crate) use tagging_stub::*; use crate::{String, Vec}; use core::marker::PhantomData; +bitflags! { + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct PixmapTableConfigurationFlags: u8 { + const ConstantWidth = 0b00000001; + const ConstantHeight = 0b00000010; + const ConstantBitsPerPixel = 0b00000100; + } + + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct PixmapTableLinkFlags: u8 { + const LinkColorTables = 0b00000001; + } + + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct CharacterTableModifierFlags: u8 { + const UseAdvanceX = 0b00000001; + const UsePixmapIndex = 0b00000010; + const UsePixmapTableIndex = 0b00000100; + } + + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct CharacterTableLinkFlags: u8 { + const LinkPixmapTables = 0b00000001; + } + + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct CharacterTableConfigurationFlags: u8 { + const ConstantClusterCodePoints = 0b00000001; + } + + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct ColorTableModifierFlags: u8 { + const UseColorType = 0b00000001; + } + + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct ColorTableConfigurationFlags: u8 { + const ConstantAlpha = 0b00000001; + } + + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + pub struct FontTableLinkFlags: u8 { + const LinkCharacterTables = 0b00000001; + } +} + #[repr(u8)] #[non_exhaustive] #[derive(Default, Debug, Clone, Copy)] @@ -54,6 +109,7 @@ impl core::fmt::Display for Version { } } +#[non_exhaustive] #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Layout { @@ -67,18 +123,22 @@ pub struct Layout { pub font_tables: Vec, } +#[non_exhaustive] #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct PixmapTable { + pub configuration_flags: PixmapTableConfigurationFlags, pub constant_width: Option, pub constant_height: Option, pub constant_bits_per_pixel: Option, + pub link_flags: PixmapTableLinkFlags, pub color_table_indexes: Option>, pub pixmaps: Vec, } +#[non_exhaustive] #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Pixmap { @@ -88,20 +148,22 @@ pub struct Pixmap { pub data: Vec, } +#[non_exhaustive] #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct CharacterTable { - pub use_advance_x: bool, - pub use_pixmap_index: bool, - pub use_pixmap_table_index: bool, + pub modifier_flags: CharacterTableModifierFlags, + pub configuration_flags: CharacterTableConfigurationFlags, pub constant_cluster_codepoints: Option, + pub link_flags: CharacterTableLinkFlags, pub pixmap_table_indexes: Option>, pub characters: Vec, } +#[non_exhaustive] #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Character { @@ -112,11 +174,13 @@ pub struct Character { pub grapheme_cluster: String, } +#[non_exhaustive] #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ColorTable { - pub use_color_type: bool, + pub modifier_flags: ColorTableModifierFlags, + pub configuration_flags: ColorTableConfigurationFlags, pub constant_alpha: Option, pub colors: Vec, @@ -132,6 +196,7 @@ pub enum ColorType { Absolute, } +#[non_exhaustive] #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Color { @@ -153,14 +218,17 @@ pub enum FontType { Italic, } +#[non_exhaustive] #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FontTable { + pub link_flags: FontTableLinkFlags, pub character_table_indexes: Option>, pub fonts: Vec, } +#[non_exhaustive] #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Font { diff --git a/src/core/tables/character/deserialize.rs b/src/core/tables/character/deserialize.rs index e371785..fc045e1 100644 --- a/src/core/tables/character/deserialize.rs +++ b/src/core/tables/character/deserialize.rs @@ -16,7 +16,8 @@ use crate::core::byte::ByteReader; use crate::core::{ - byte, Character, CharacterTable, DeserializeEngine, DeserializeError, TagWriter, + Character, CharacterTable, CharacterTableConfigurationFlags, CharacterTableLinkFlags, + CharacterTableModifierFlags, DeserializeEngine, DeserializeError, TagWriter, }; use crate::{vec, String, Vec}; @@ -31,16 +32,7 @@ impl CharacterTable { &mut self, engine: &mut DeserializeEngine, ) { - let modifier_flags = engine.bytes.next(); - if byte::get_bit(modifier_flags, 0) { - self.use_advance_x = true; - } - if byte::get_bit(modifier_flags, 1) { - self.use_pixmap_index = true; - } - if byte::get_bit(modifier_flags, 2) { - self.use_pixmap_table_index = true; - } + self.modifier_flags = CharacterTableModifierFlags::from_bits_retain(engine.bytes.next()); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::CharacterTableModifierFlags { @@ -50,15 +42,21 @@ impl CharacterTable { vec![ TagKind::CharacterTableUseAdvanceX { table_index: engine.tagging_data.current_table_index, - value: self.use_advance_x, + value: self + .modifier_flags + .contains(CharacterTableModifierFlags::UseAdvanceX), }, TagKind::CharacterTableUsePixmapIndex { table_index: engine.tagging_data.current_table_index, - value: self.use_pixmap_index, + value: self + .modifier_flags + .contains(CharacterTableModifierFlags::UsePixmapIndex), }, TagKind::CharacterTableUsePixmapTableIndex { table_index: engine.tagging_data.current_table_index, - value: self.use_pixmap_table_index, + value: self + .modifier_flags + .contains(CharacterTableModifierFlags::UsePixmapTableIndex), }, ], engine.bytes.byte_index(), @@ -71,8 +69,11 @@ impl CharacterTable { #[cfg(feature = "tagging")] let configurations_start = engine.bytes.byte_index(); - let configuration_flags = engine.bytes.next(); - let use_constant_cluster_codepoints = byte::get_bit(configuration_flags, 0); + self.configuration_flags = + CharacterTableConfigurationFlags::from_bits_retain(engine.bytes.next()); + let use_constant_cluster_codepoints = self + .configuration_flags + .contains(CharacterTableConfigurationFlags::ConstantClusterCodePoints); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( @@ -123,8 +124,10 @@ impl CharacterTable { #[cfg(feature = "tagging")] let links_start = engine.bytes.byte_index(); - let link_flags = engine.bytes.next(); - let link_pixmap_tables = byte::get_bit(link_flags, 0); + self.link_flags = CharacterTableLinkFlags::from_bits_retain(engine.bytes.next()); + let link_pixmap_tables = self + .link_flags + .contains(CharacterTableLinkFlags::LinkPixmapTables); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( diff --git a/src/core/tables/character/mod.rs b/src/core/tables/character/mod.rs index 610d410..c861744 100644 --- a/src/core/tables/character/mod.rs +++ b/src/core/tables/character/mod.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use crate::core::byte::ByteReader; +use crate::core::{byte::ByteReader, CharacterTableModifierFlags}; #[cfg(feature = "tagging")] use crate::core::{ByteIndex, Span, TableType, TagKind}; use crate::core::{ @@ -67,7 +67,10 @@ impl Table for CharacterTable { let character_start = engine.bytes.byte_index(); let mut character = Character::default(); - if character_table.use_advance_x { + if character_table + .modifier_flags + .contains(CharacterTableModifierFlags::UseAdvanceX) + { character.advance_x = Some(engine.bytes.next()); #[cfg(feature = "tagging")] engine.tags.tag_byte( @@ -79,7 +82,10 @@ impl Table for CharacterTable { engine.bytes.byte_index(), ); } - if character_table.use_pixmap_index { + if character_table + .modifier_flags + .contains(CharacterTableModifierFlags::UsePixmapIndex) + { character.pixmap_index = Some(engine.bytes.next()); #[cfg(feature = "tagging")] engine.tags.tag_byte( @@ -91,7 +97,10 @@ impl Table for CharacterTable { engine.bytes.byte_index(), ); } - if character_table.use_pixmap_table_index { + if character_table + .modifier_flags + .contains(CharacterTableModifierFlags::UsePixmapTableIndex) + { character.pixmap_table_index = Some(engine.bytes.next()); #[cfg(feature = "tagging")] engine.tags.tag_byte( @@ -168,7 +177,10 @@ impl Table for CharacterTable { #[cfg(feature = "tagging")] let character_start = engine.bytes.byte_index(); - if self.use_advance_x { + if self + .modifier_flags + .contains(CharacterTableModifierFlags::UseAdvanceX) + { engine.bytes.push(character.advance_x.unwrap()); #[cfg(feature = "tagging")] engine.tags.tag_byte( @@ -180,7 +192,10 @@ impl Table for CharacterTable { engine.bytes.byte_index(), ); } - if self.use_pixmap_index { + if self + .modifier_flags + .contains(CharacterTableModifierFlags::UsePixmapIndex) + { engine.bytes.push(character.pixmap_index.unwrap()); #[cfg(feature = "tagging")] engine.tags.tag_byte( @@ -192,7 +207,10 @@ impl Table for CharacterTable { engine.bytes.byte_index(), ); } - if self.use_pixmap_table_index { + if self + .modifier_flags + .contains(CharacterTableModifierFlags::UsePixmapTableIndex) + { engine.bytes.push(character.pixmap_table_index.unwrap()); #[cfg(feature = "tagging")] engine.tags.tag_byte( diff --git a/src/core/tables/character/serialize.rs b/src/core/tables/character/serialize.rs index 5478c99..f3c7b59 100644 --- a/src/core/tables/character/serialize.rs +++ b/src/core/tables/character/serialize.rs @@ -14,6 +14,9 @@ * limitations under the License. */ +#[cfg(feature = "tagging")] +use crate::core::CharacterTableLinkFlags; +use crate::core::CharacterTableModifierFlags; use crate::core::{CharacterTable, SerializeEngine, SerializeError, TableIdentifier, TagWriter}; use crate::{vec, String}; @@ -37,18 +40,7 @@ impl CharacterTable { ); } pub(crate) fn push_modifier_flags(&self, engine: &mut SerializeEngine) { - let mut modifier_flags = 0b00000000; - if self.use_advance_x { - modifier_flags |= 0b00000001; - } - if self.use_pixmap_index { - modifier_flags |= 0b00000010; - } - if self.use_pixmap_table_index { - modifier_flags |= 0b00000100; - } - - engine.bytes.push(modifier_flags); + engine.bytes.push(self.modifier_flags.bits()); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::CharacterTableModifierFlags { @@ -58,15 +50,21 @@ impl CharacterTable { vec![ TagKind::CharacterTableUseAdvanceX { table_index: engine.tagging_data.current_table_index, - value: self.use_advance_x, + value: self + .modifier_flags + .contains(CharacterTableModifierFlags::UseAdvanceX), }, TagKind::CharacterTableUsePixmapIndex { table_index: engine.tagging_data.current_table_index, - value: self.use_pixmap_index, + value: self + .modifier_flags + .contains(CharacterTableModifierFlags::UsePixmapIndex), }, TagKind::CharacterTableUsePixmapTableIndex { table_index: engine.tagging_data.current_table_index, - value: self.use_pixmap_table_index, + value: self + .modifier_flags + .contains(CharacterTableModifierFlags::UsePixmapTableIndex), }, ], engine.bytes.byte_index(), @@ -76,12 +74,7 @@ impl CharacterTable { #[cfg(feature = "tagging")] let configurations_start = engine.bytes.byte_index(); - let mut configuration_flags = 0b00000000; - if self.constant_cluster_codepoints.is_some() { - configuration_flags |= 0b00000001; - } - - engine.bytes.push(configuration_flags); // Configuration flags byte + engine.bytes.push(self.configuration_flags.bits()); // Configuration flags byte #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::CharacterTableConfigurationFlags { @@ -134,14 +127,8 @@ impl CharacterTable { #[cfg(feature = "tagging")] let links_start = engine.bytes.byte_index(); - // Table Links - let mut link_flags = 0b00000000; - if self.pixmap_table_indexes.is_some() { - link_flags |= 0b00000001; - } - // Table relations - engine.bytes.push(link_flags); + engine.bytes.push(self.link_flags.bits()); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::CharacterTableLinkFlags { @@ -149,7 +136,9 @@ impl CharacterTable { }, vec![TagKind::CharacterTableLinkPixmapTables { table_index: engine.tagging_data.current_table_index, - value: self.pixmap_table_indexes.is_some(), + value: self + .link_flags + .contains(CharacterTableLinkFlags::LinkPixmapTables), }], engine.bytes.byte_index(), ); diff --git a/src/core/tables/color/mod.rs b/src/core/tables/color/mod.rs index a4f935f..560770d 100644 --- a/src/core/tables/color/mod.rs +++ b/src/core/tables/color/mod.rs @@ -16,8 +16,9 @@ use crate::core::byte::ByteReader; use crate::core::{ - byte, Color, ColorTable, ColorType, DeserializeEngine, DeserializeError, SerializeEngine, - SerializeError, Table, TableIdentifier, TagWriter, + Color, ColorTable, ColorTableConfigurationFlags, ColorTableModifierFlags, ColorType, + DeserializeEngine, DeserializeError, SerializeEngine, SerializeError, Table, TableIdentifier, + TagWriter, }; use crate::{vec, Vec}; @@ -29,9 +30,7 @@ impl ColorTable { &mut self, engine: &mut DeserializeEngine, ) { - let modifier_flags = engine.bytes.next(); - self.use_color_type = byte::get_bit(modifier_flags, 0); - + self.modifier_flags = ColorTableModifierFlags::from_bits_retain(engine.bytes.next()); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::ColorTableModifierFlags { @@ -40,7 +39,9 @@ impl ColorTable { #[cfg(feature = "tagging")] vec![TagKind::ColorTableUseColorType { table_index: engine.tagging_data.current_table_index, - value: self.use_color_type, + value: self + .modifier_flags + .contains(ColorTableModifierFlags::UseColorType), }], engine.bytes.byte_index(), ); @@ -52,8 +53,11 @@ impl ColorTable { #[cfg(feature = "tagging")] let configurations_start = engine.bytes.byte_index(); - let configuration_flags = engine.bytes.next(); - let use_constant_alpha = byte::get_bit(configuration_flags, 0); + self.configuration_flags = + ColorTableConfigurationFlags::from_bits_retain(engine.bytes.next()); + let use_constant_alpha = self + .configuration_flags + .contains(ColorTableConfigurationFlags::ConstantAlpha); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( @@ -104,7 +108,7 @@ impl ColorTable { #[cfg(feature = "tagging")] let links_start = engine.bytes.byte_index(); - let _link_flags = engine.bytes.next(); + let _link_flags = engine.bytes.next(); // will need to be updated later to use bitflags #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::ColorTableLinkFlags { @@ -165,7 +169,10 @@ impl Table for ColorTable { let color_start = engine.bytes.byte_index(); let mut color = Color::default(); - if color_table.use_color_type { + if color_table + .modifier_flags + .contains(ColorTableModifierFlags::UseColorType) + { color.color_type = Some(ColorType::try_from(engine.bytes.next())?); #[cfg(feature = "tagging")] engine.tags.tag_byte( @@ -276,7 +283,10 @@ impl Table for ColorTable { #[cfg(feature = "tagging")] let color_start = engine.bytes.byte_index(); - if self.use_color_type { + if self + .modifier_flags + .contains(ColorTableModifierFlags::UseColorType) + { engine.bytes.push(color.color_type.unwrap() as u8); #[cfg(feature = "tagging")] engine.tags.tag_byte( @@ -366,12 +376,7 @@ impl ColorTable { ); } pub(crate) fn push_modifier_flags(&self, engine: &mut SerializeEngine) { - let mut modifier_flags = 0b00000000; - if self.use_color_type { - modifier_flags |= 0b00000001; - } - - engine.bytes.push(modifier_flags); + engine.bytes.push(self.modifier_flags.bits()); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::ColorTableModifierFlags { @@ -380,7 +385,9 @@ impl ColorTable { #[cfg(feature = "tagging")] vec![TagKind::ColorTableUseColorType { table_index: engine.tagging_data.current_table_index, - value: self.use_color_type, + value: self + .modifier_flags + .contains(ColorTableModifierFlags::UseColorType), }], engine.bytes.byte_index(), ); @@ -389,12 +396,7 @@ impl ColorTable { #[cfg(feature = "tagging")] let configurations_start = engine.bytes.byte_index(); - let mut configuration_flags = 0; - if self.constant_alpha.is_some() { - configuration_flags |= 0b00000001; - } - - engine.bytes.push(configuration_flags); // configuration flags + engine.bytes.push(self.configuration_flags.bits()); // configuration flags #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::ColorTableConfigurationFlags { diff --git a/src/core/tables/font/deserialize.rs b/src/core/tables/font/deserialize.rs index 6b8bfb2..2b5ed30 100644 --- a/src/core/tables/font/deserialize.rs +++ b/src/core/tables/font/deserialize.rs @@ -16,7 +16,7 @@ use crate::core::byte::ByteReader; use crate::core::{ - byte, DeserializeEngine, DeserializeError, Font, FontTable, FontType, TagWriter, + DeserializeEngine, DeserializeError, Font, FontTable, FontTableLinkFlags, FontType, TagWriter, }; use crate::{vec, String, Vec}; @@ -59,8 +59,10 @@ impl FontTable { #[cfg(feature = "tagging")] let links_start = engine.bytes.byte_index(); - let link_flags = engine.bytes.next(); - let link_character_tables = byte::get_bit(link_flags, 0); + self.link_flags = FontTableLinkFlags::from_bits_retain(engine.bytes.next()); + let link_character_tables = self + .link_flags + .contains(FontTableLinkFlags::LinkCharacterTables); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( diff --git a/src/core/tables/font/serialize.rs b/src/core/tables/font/serialize.rs index 00a2db7..f91b814 100644 --- a/src/core/tables/font/serialize.rs +++ b/src/core/tables/font/serialize.rs @@ -14,6 +14,8 @@ * limitations under the License. */ +#[cfg(feature = "tagging")] +use crate::core::FontTableLinkFlags; use crate::core::{ FontTable, FontType, SerializeEngine, SerializeError, TableIdentifier, TagWriter, }; @@ -63,14 +65,8 @@ impl FontTable { #[cfg(feature = "tagging")] let links_start = engine.bytes.byte_index(); - // Table Links - let mut link_flags = 0b00000000; - if self.character_table_indexes.is_some() { - link_flags |= 0b00000001; - } - // Table relations - engine.bytes.push(link_flags); + engine.bytes.push(self.link_flags.bits()); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::FontTableLinkFlags { @@ -78,7 +74,9 @@ impl FontTable { }, vec![TagKind::FontTableLinkCharacterTables { table_index: engine.tagging_data.current_table_index, - value: self.character_table_indexes.is_some(), + value: self + .link_flags + .contains(FontTableLinkFlags::LinkCharacterTables), }], engine.bytes.byte_index(), ); diff --git a/src/core/tables/pixmap/deserialize.rs b/src/core/tables/pixmap/deserialize.rs index 3beb8d3..40c5044 100644 --- a/src/core/tables/pixmap/deserialize.rs +++ b/src/core/tables/pixmap/deserialize.rs @@ -15,7 +15,10 @@ */ use crate::core::byte::ByteReader; -use crate::core::{byte, DeserializeEngine, Pixmap, PixmapTable, TagWriter}; +use crate::core::{ + DeserializeEngine, Pixmap, PixmapTable, PixmapTableConfigurationFlags, PixmapTableLinkFlags, + TagWriter, +}; use crate::{vec, Vec}; #[cfg(feature = "tagging")] @@ -46,10 +49,17 @@ impl PixmapTable { #[cfg(feature = "tagging")] let configurations_start = engine.bytes.byte_index(); - let configuration_flags = engine.bytes.next(); - let use_constant_width = byte::get_bit(configuration_flags, 0); - let use_constant_height = byte::get_bit(configuration_flags, 1); - let use_constant_bits_per_pixel = byte::get_bit(configuration_flags, 2); + self.configuration_flags = + PixmapTableConfigurationFlags::from_bits_retain(engine.bytes.next()); + let use_constant_width = self + .configuration_flags + .contains(PixmapTableConfigurationFlags::ConstantWidth); + let use_constant_height = self + .configuration_flags + .contains(PixmapTableConfigurationFlags::ConstantHeight); + let use_constant_bits_per_pixel = self + .configuration_flags + .contains(PixmapTableConfigurationFlags::ConstantBitsPerPixel); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( @@ -133,8 +143,10 @@ impl PixmapTable { #[cfg(feature = "tagging")] let links_start = engine.bytes.byte_index(); - let link_flags = engine.bytes.next(); - let link_color_tables = byte::get_bit(link_flags, 0); + self.link_flags = PixmapTableLinkFlags::from_bits_retain(engine.bytes.next()); + let link_color_tables = self + .link_flags + .contains(PixmapTableLinkFlags::LinkColorTables); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( diff --git a/src/core/tables/pixmap/serialize.rs b/src/core/tables/pixmap/serialize.rs index 1947824..8eb14a0 100644 --- a/src/core/tables/pixmap/serialize.rs +++ b/src/core/tables/pixmap/serialize.rs @@ -20,7 +20,7 @@ use crate::core::{ use crate::{format, vec, String}; #[cfg(feature = "tagging")] -use crate::core::{Span, TableType, TagKind}; +use crate::core::{PixmapTableConfigurationFlags, PixmapTableLinkFlags, Span, TableType, TagKind}; #[cfg(feature = "log")] pub(crate) use log::*; @@ -51,18 +51,7 @@ impl PixmapTable { #[cfg(feature = "tagging")] let configurations_start = engine.bytes.byte_index(); - let mut configuration_flags = 0; // configuration flags - if self.constant_width.is_some() { - configuration_flags |= 0b00000001; - } - if self.constant_height.is_some() { - configuration_flags |= 0b00000010; - } - if self.constant_bits_per_pixel.is_some() { - configuration_flags |= 0b00000100; - } - - engine.bytes.push(configuration_flags); + engine.bytes.push(self.configuration_flags.bits()); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::PixmapTableConfigurationFlags { @@ -71,15 +60,21 @@ impl PixmapTable { vec![ TagKind::PixmapTableUseConstantWidth { table_index: engine.tagging_data.current_table_index, - value: self.constant_width.is_some(), + value: self + .configuration_flags + .contains(PixmapTableConfigurationFlags::ConstantWidth), }, TagKind::PixmapTableUseConstantHeight { table_index: engine.tagging_data.current_table_index, - value: self.constant_height.is_some(), + value: self + .configuration_flags + .contains(PixmapTableConfigurationFlags::ConstantHeight), }, TagKind::PixmapTableUseConstantBitsPerPixel { table_index: engine.tagging_data.current_table_index, - value: self.constant_bits_per_pixel.is_some(), + value: self + .configuration_flags + .contains(PixmapTableConfigurationFlags::ConstantBitsPerPixel), }, ], engine.bytes.byte_index(), @@ -146,13 +141,8 @@ impl PixmapTable { #[cfg(feature = "tagging")] let table_links_start = engine.bytes.byte_index(); - let mut link_flags = 0b00000000; - if self.color_table_indexes.is_some() { - link_flags |= 0b00000001; - } - // Table relations - engine.bytes.push(link_flags); + engine.bytes.push(self.link_flags.bits()); #[cfg(feature = "tagging")] engine.tags.tag_bitflag( TagKind::PixmapTableLinkFlags { @@ -160,7 +150,9 @@ impl PixmapTable { }, vec![TagKind::PixmapTableLinkColorTables { table_index: engine.tagging_data.current_table_index, - value: self.color_table_indexes.is_some(), + value: self + .link_flags + .contains(PixmapTableLinkFlags::LinkColorTables), }], engine.bytes.byte_index(), ); From 115f7b7ab8bb480a4c02ba7495c30f86799e676e Mon Sep 17 00:00:00 2001 From: Alexis Osorio <113266346+The-Nice-One@users.noreply.github.com> Date: Fri, 22 May 2026 18:15:11 +0000 Subject: [PATCH 2/6] Add .devcontainer/devcontainer.json file --- .devcontainer/devcontainer.json | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..3c68db6 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,31 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/rust +{ + "name": "Rust", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + "settings": {}, + "extensions": [ + "streetsidesoftware.code-spell-checker" + ] + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "rustc --version", + "postCreateCommand": "sudo apt update && sudo apt install -y git-lfs && git lfs install" + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file From f5cbcbdde8d15a034cb13d2e828c18be9cab4934 Mon Sep 17 00:00:00 2001 From: Alexis Osorio <113266346+The-Nice-One@users.noreply.github.com> Date: Fri, 22 May 2026 18:33:44 +0000 Subject: [PATCH 3/6] Add constant variables for flags --- .vscode/settings.json | 5 +++++ src/ffi/mod.rs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4ab4cbe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "PIXMAP" + ] +} \ No newline at end of file diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index 3587100..a0d34db 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -95,6 +95,24 @@ pub struct SPFPixmapTable { pub pixmaps_length: c_ulong, } +pub const SPF_PIXMAP_TABLE_CONFIGURATION_FLAGS_CONSTANT_WIDTH: u8 = 1 << 0; +pub const SPF_PIXMAP_TABLE_CONFIGURATION_FLAGS_CONSTANT_HEIGHT: u8 = 1 << 1; +pub const SPF_PIXMAP_TABLE_CONFIGURATION_FLAGS_CONSTANT_BITS_PER_PIXEL: u8 = 1 << 2; +pub const SPF_PIXMAP_TABLE_LINK_FLAGS_LINK_COLOR_TABLES: u8 = 1 << 0; + +pub const SPF_CHARACTER_TABLE_MODIFIER_FLAGS_USE_ADVANCE_X: u8 = 1 << 0; +pub const SPF_CHARACTER_TABLE_MODIFIER_FLAGS_USE_PIXMAP_INDEX: u8 = 1 << 1; +pub const SPF_CHARACTER_TABLE_MODIFIER_FLAGS_USE_PIXMAP_TABLE_INDEX: u8 = 1 << 2; + +pub const SPF_CHARACTER_TABLE_CONFIGURATION_FLAGS_CONSTANT_CLUSTER_CODEPOINTS: u8 = 1 << 0; + +pub const SPF_CHARACTER_TABLE_LINK_FLAGS_LINK_PIXMAP_TABLES: u8 = 1 << 0; + +pub const SPF_COLOR_TABLE_MODIFIER_FLAGS_USE_COLOR_TYPE: u8 = 1 << 0; +pub const SPF_COLOR_TABLE_CONFIGURATION_FLAGS_CONSTANT_ALPHA: u8 = 1 << 0; + +const SPF_FONT_TABLE_LINK_FLAGS_LINK_CHARACTER_TABLES: u8 = 1 << 0; + #[derive(Debug, Clone)] #[repr(C)] pub struct SPFPixmap { From a0835b05204b815b352bf5ade501c42c0dda17f7 Mon Sep 17 00:00:00 2001 From: Alexis Osorio <113266346+The-Nice-One@users.noreply.github.com> Date: Fri, 22 May 2026 18:39:06 +0000 Subject: [PATCH 4/6] Add bitflags fields to ABI structs --- src/ffi/mod.rs | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index a0d34db..e0d2c9d 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -60,6 +60,24 @@ pub use converters::*; #[doc(inline)] pub use free::*; +pub const SPF_PIXMAP_TABLE_CONFIGURATION_FLAGS_CONSTANT_WIDTH: u8 = 1 << 0; +pub const SPF_PIXMAP_TABLE_CONFIGURATION_FLAGS_CONSTANT_HEIGHT: u8 = 1 << 1; +pub const SPF_PIXMAP_TABLE_CONFIGURATION_FLAGS_CONSTANT_BITS_PER_PIXEL: u8 = 1 << 2; +pub const SPF_PIXMAP_TABLE_LINK_FLAGS_LINK_COLOR_TABLES: u8 = 1 << 0; + +pub const SPF_CHARACTER_TABLE_MODIFIER_FLAGS_USE_ADVANCE_X: u8 = 1 << 0; +pub const SPF_CHARACTER_TABLE_MODIFIER_FLAGS_USE_PIXMAP_INDEX: u8 = 1 << 1; +pub const SPF_CHARACTER_TABLE_MODIFIER_FLAGS_USE_PIXMAP_TABLE_INDEX: u8 = 1 << 2; + +pub const SPF_CHARACTER_TABLE_CONFIGURATION_FLAGS_CONSTANT_CLUSTER_CODEPOINTS: u8 = 1 << 0; + +pub const SPF_CHARACTER_TABLE_LINK_FLAGS_LINK_PIXMAP_TABLES: u8 = 1 << 0; + +pub const SPF_COLOR_TABLE_MODIFIER_FLAGS_USE_COLOR_TYPE: u8 = 1 << 0; +pub const SPF_COLOR_TABLE_CONFIGURATION_FLAGS_CONSTANT_ALPHA: u8 = 1 << 0; + +const SPF_FONT_TABLE_LINK_FLAGS_LINK_CHARACTER_TABLES: u8 = 1 << 0; + #[derive(Debug, Clone)] #[repr(C)] pub struct SPFLayout { @@ -80,6 +98,7 @@ pub struct SPFLayout { #[derive(Debug, Clone)] #[repr(C)] pub struct SPFPixmapTable { + pub configuration_flags: c_uchar, pub has_constant_width: c_uchar, pub constant_width: c_uchar, pub has_constant_height: c_uchar, @@ -87,6 +106,7 @@ pub struct SPFPixmapTable { pub has_constant_bits_per_pixel: c_uchar, pub constant_bits_per_pixel: c_uchar, + pub link_flags: c_uchar, pub has_color_table_indexes: c_uchar, pub color_table_indexes: *mut c_uchar, pub color_table_indexes_length: c_ulong, @@ -95,24 +115,6 @@ pub struct SPFPixmapTable { pub pixmaps_length: c_ulong, } -pub const SPF_PIXMAP_TABLE_CONFIGURATION_FLAGS_CONSTANT_WIDTH: u8 = 1 << 0; -pub const SPF_PIXMAP_TABLE_CONFIGURATION_FLAGS_CONSTANT_HEIGHT: u8 = 1 << 1; -pub const SPF_PIXMAP_TABLE_CONFIGURATION_FLAGS_CONSTANT_BITS_PER_PIXEL: u8 = 1 << 2; -pub const SPF_PIXMAP_TABLE_LINK_FLAGS_LINK_COLOR_TABLES: u8 = 1 << 0; - -pub const SPF_CHARACTER_TABLE_MODIFIER_FLAGS_USE_ADVANCE_X: u8 = 1 << 0; -pub const SPF_CHARACTER_TABLE_MODIFIER_FLAGS_USE_PIXMAP_INDEX: u8 = 1 << 1; -pub const SPF_CHARACTER_TABLE_MODIFIER_FLAGS_USE_PIXMAP_TABLE_INDEX: u8 = 1 << 2; - -pub const SPF_CHARACTER_TABLE_CONFIGURATION_FLAGS_CONSTANT_CLUSTER_CODEPOINTS: u8 = 1 << 0; - -pub const SPF_CHARACTER_TABLE_LINK_FLAGS_LINK_PIXMAP_TABLES: u8 = 1 << 0; - -pub const SPF_COLOR_TABLE_MODIFIER_FLAGS_USE_COLOR_TYPE: u8 = 1 << 0; -pub const SPF_COLOR_TABLE_CONFIGURATION_FLAGS_CONSTANT_ALPHA: u8 = 1 << 0; - -const SPF_FONT_TABLE_LINK_FLAGS_LINK_CHARACTER_TABLES: u8 = 1 << 0; - #[derive(Debug, Clone)] #[repr(C)] pub struct SPFPixmap { @@ -129,13 +131,13 @@ pub struct SPFPixmap { #[derive(Debug, Clone)] #[repr(C)] pub struct SPFCharacterTable { - pub use_advance_x: c_uchar, - pub use_pixmap_index: c_uchar, - pub use_pixmap_table_index: c_uchar, + pub modifier_flags: c_uchar, + pub configuration_flags: c_uchar, pub has_constant_cluster_codepoints: c_uchar, pub constant_cluster_codepoints: c_uchar, + pub link_flags: c_uchar, pub has_pixmap_table_indexes: c_uchar, pub pixmap_table_indexes: *mut c_uchar, pub pixmap_table_indexes_length: c_ulong, @@ -160,8 +162,9 @@ pub struct SPFCharacter { #[derive(Debug, Clone)] #[repr(C)] pub struct SPFColorTable { - pub use_color_type: c_uchar, + pub modifier_flags: c_uchar, + pub configuration_flags: c_uchar, pub has_constant_alpha: c_uchar, pub constant_alpha: c_uchar, @@ -186,6 +189,7 @@ pub struct SPFColor { #[derive(Debug, Clone)] #[repr(C)] pub struct SPFFontTable { + pub link_flags: c_uchar, pub has_character_table_indexes: c_uchar, pub character_table_indexes: *mut c_uchar, pub character_table_indexes_length: c_ulong, From dd14944673dd931bd877e87bf2aa10b50def7865 Mon Sep 17 00:00:00 2001 From: Alexis Osorio <113266346+The-Nice-One@users.noreply.github.com> Date: Fri, 22 May 2026 19:00:14 +0000 Subject: [PATCH 5/6] Fix ffi errors and warnings --- src/ffi/converters/character_table.rs | 14 ++++++++------ src/ffi/converters/color_table.rs | 7 +++++-- src/ffi/converters/font_table.rs | 2 ++ src/ffi/converters/pixmap_table.rs | 5 +++++ src/ffi/defaults.rs | 16 ++++++++++++---- src/ffi/mod.rs | 2 +- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/ffi/converters/character_table.rs b/src/ffi/converters/character_table.rs index 57c34b6..bf6022b 100644 --- a/src/ffi/converters/character_table.rs +++ b/src/ffi/converters/character_table.rs @@ -27,11 +27,13 @@ impl TryFrom for SPFCharacterTable { vec_to_raw_with_conversion!(table.characters, SPFCharacter); Ok(SPFCharacterTable { - use_advance_x: table.use_advance_x as c_uchar, - use_pixmap_index: table.use_pixmap_index as c_uchar, - use_pixmap_table_index: table.use_pixmap_table_index as c_uchar, + modifier_flags: table.modifier_flags.bits(), + + configuration_flags: table.configuration_flags.bits(), has_constant_cluster_codepoints: table.constant_cluster_codepoints.is_some() as c_uchar, constant_cluster_codepoints: table.constant_cluster_codepoints.unwrap_or(0) as c_uchar, + + link_flags: table.link_flags.bits(), has_pixmap_table_indexes: table.pixmap_table_indexes.is_some() as c_uchar, pixmap_table_indexes: pixmap_table_indexes_ptr, pixmap_table_indexes_length: pixmap_table_indexes_len as c_ulong, @@ -66,10 +68,10 @@ impl TryInto for &SPFCharacterTable { ffi_to_option!(self.has_pixmap_table_indexes, pixmap_table_indexes); Ok(CharacterTable { - use_advance_x: self.use_advance_x != 0, - use_pixmap_index: self.use_pixmap_index != 0, - use_pixmap_table_index: self.use_pixmap_table_index != 0, + modifier_flags: CharacterTableModifierFlags::from_bits_retain(self.modifier_flags), + configuration_flags: CharacterTableConfigurationFlags::from_bits_retain(self.configuration_flags), constant_cluster_codepoints, + link_flags: CharacterTableLinkFlags::from_bits_retain(self.link_flags), pixmap_table_indexes, characters, }) diff --git a/src/ffi/converters/color_table.rs b/src/ffi/converters/color_table.rs index 141b3b8..1153a18 100644 --- a/src/ffi/converters/color_table.rs +++ b/src/ffi/converters/color_table.rs @@ -23,7 +23,9 @@ impl TryFrom for SPFColorTable { let (colors_ptr, colors_len) = vec_to_raw_with_conversion!(table.colors, SPFColor); Ok(SPFColorTable { - use_color_type: table.use_color_type as c_uchar, + modifier_flags: table.modifier_flags.bits(), + + configuration_flags: table.configuration_flags.bits(), has_constant_alpha: table.constant_alpha.is_some() as c_uchar, constant_alpha: table.constant_alpha.unwrap_or(0) as c_uchar, colors: colors_ptr, @@ -41,7 +43,8 @@ impl TryInto for &SPFColorTable { let constant_alpha = ffi_to_option!(self.has_constant_alpha, self.constant_alpha); Ok(ColorTable { - use_color_type: self.use_color_type != 0, + modifier_flags: ColorTableModifierFlags::from_bits_retain(self.modifier_flags), + configuration_flags: ColorTableConfigurationFlags::from_bits_retain(self.configuration_flags), constant_alpha, colors, }) diff --git a/src/ffi/converters/font_table.rs b/src/ffi/converters/font_table.rs index 4a13006..0bf0507 100644 --- a/src/ffi/converters/font_table.rs +++ b/src/ffi/converters/font_table.rs @@ -26,6 +26,7 @@ impl TryFrom for SPFFontTable { let (fonts_ptr, fonts_len) = vec_to_raw_with_conversion!(table.fonts, SPFFont); Ok(SPFFontTable { + link_flags: table.link_flags.bits(), has_character_table_indexes: table.character_table_indexes.is_some() as c_uchar, character_table_indexes: character_table_indexes_ptr, character_table_indexes_length: character_table_indexes_len as c_ulong, @@ -55,6 +56,7 @@ impl TryInto for &SPFFontTable { let fonts = vec_from_raw_with_conversion!(self.fonts, self.fonts_length); Ok(FontTable { + link_flags: FontTableLinkFlags::from_bits_retain(self.link_flags), character_table_indexes, fonts, }) diff --git a/src/ffi/converters/pixmap_table.rs b/src/ffi/converters/pixmap_table.rs index 5d238ed..ce532a8 100644 --- a/src/ffi/converters/pixmap_table.rs +++ b/src/ffi/converters/pixmap_table.rs @@ -26,12 +26,15 @@ impl TryFrom for SPFPixmapTable { let (pixmaps_ptr, pixmaps_len) = vec_to_raw_with_conversion!(table.pixmaps, SPFPixmap); Ok(SPFPixmapTable { + configuration_flags: table.configuration_flags.bits(), has_constant_width: table.constant_width.is_some() as c_uchar, constant_width: table.constant_width.unwrap_or(0) as c_uchar, has_constant_height: table.constant_height.is_some() as c_uchar, constant_height: table.constant_height.unwrap_or(0) as c_uchar, has_constant_bits_per_pixel: table.constant_bits_per_pixel.is_some() as c_uchar, constant_bits_per_pixel: table.constant_bits_per_pixel.unwrap_or(0) as c_uchar, + + link_flags: table.link_flags.bits(), has_color_table_indexes: table.color_table_indexes.is_some() as c_uchar, color_table_indexes: color_table_indexes_ptr, color_table_indexes_length: color_table_indexes_len as c_ulong, @@ -67,9 +70,11 @@ impl TryInto for &SPFPixmapTable { ); Ok(PixmapTable { + configuration_flags: PixmapTableConfigurationFlags::from_bits_retain(self.configuration_flags), constant_width, constant_height, constant_bits_per_pixel, + link_flags: PixmapTableLinkFlags::from_bits_retain(self.link_flags), color_table_indexes, pixmaps, }) diff --git a/src/ffi/defaults.rs b/src/ffi/defaults.rs index 6dabfd5..382d6ac 100644 --- a/src/ffi/defaults.rs +++ b/src/ffi/defaults.rs @@ -38,11 +38,13 @@ impl Default for SPFLayout { impl Default for SPFCharacterTable { fn default() -> Self { SPFCharacterTable { - use_advance_x: u8::default(), - use_pixmap_index: u8::default(), - use_pixmap_table_index: u8::default(), + modifier_flags: u8::default(), has_constant_cluster_codepoints: u8::default(), + + configuration_flags: u8::default(), constant_cluster_codepoints: u8::default(), + + link_flags: u8::default(), has_pixmap_table_indexes: u8::default(), pixmap_table_indexes: core::ptr::null_mut(), pixmap_table_indexes_length: 0, @@ -69,7 +71,9 @@ impl Default for SPFCharacter { impl Default for SPFColorTable { fn default() -> Self { SPFColorTable { - use_color_type: u8::default(), + modifier_flags: u8::default(), + + configuration_flags: u8::default(), has_constant_alpha: u8::default(), constant_alpha: u8::default(), colors: core::ptr::null_mut(), @@ -96,12 +100,15 @@ impl Default for SPFColor { impl Default for SPFPixmapTable { fn default() -> Self { SPFPixmapTable { + configuration_flags: u8::default(), has_constant_width: u8::default(), constant_width: u8::default(), has_constant_height: u8::default(), constant_height: u8::default(), has_constant_bits_per_pixel: u8::default(), constant_bits_per_pixel: u8::default(), + + link_flags: u8::default(), has_color_table_indexes: u8::default(), color_table_indexes: core::ptr::null_mut(), color_table_indexes_length: 0, @@ -129,6 +136,7 @@ impl Default for SPFPixmap { impl Default for SPFFontTable { fn default() -> Self { SPFFontTable { + link_flags: u8::default(), has_character_table_indexes: u8::default(), character_table_indexes: core::ptr::null_mut(), character_table_indexes_length: 0, diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index e0d2c9d..8c3c30e 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -76,7 +76,7 @@ pub const SPF_CHARACTER_TABLE_LINK_FLAGS_LINK_PIXMAP_TABLES: u8 = 1 << 0; pub const SPF_COLOR_TABLE_MODIFIER_FLAGS_USE_COLOR_TYPE: u8 = 1 << 0; pub const SPF_COLOR_TABLE_CONFIGURATION_FLAGS_CONSTANT_ALPHA: u8 = 1 << 0; -const SPF_FONT_TABLE_LINK_FLAGS_LINK_CHARACTER_TABLES: u8 = 1 << 0; +pub const SPF_FONT_TABLE_LINK_FLAGS_LINK_CHARACTER_TABLES: u8 = 1 << 0; #[derive(Debug, Clone)] #[repr(C)] From ec8f71295a928de732877c3e15cbf99156191376 Mon Sep 17 00:00:00 2001 From: Alexis Osorio <113266346+The-Nice-One@users.noreply.github.com> Date: Fri, 22 May 2026 19:25:53 +0000 Subject: [PATCH 6/6] Refractor tests --- tests/integration_tests.rs | 192 ++++++++++++++++--------------------- 1 file changed, 85 insertions(+), 107 deletions(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 751285f..466ae89 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -18,127 +18,105 @@ mod tests { .try_init(); } fn second_sample_pixmap_table() -> PixmapTable { - PixmapTable { - constant_width: None, - constant_height: Some(4), - constant_bits_per_pixel: Some(7), - color_table_indexes: Some(vec![0]), - pixmaps: vec![Pixmap { - custom_width: Some(1), - custom_height: None, - custom_bits_per_pixel: None, - data: vec![0b01000010, 0b01000010, 0b01000010, 0b00001111], - }], - } + let mut pixmap = Pixmap::default(); + pixmap.custom_width = Some(1); + pixmap.custom_height = None; + pixmap.custom_bits_per_pixel = None; + pixmap.data = vec![0b01000010, 0b01000010, 0b01000010, 0b00001111]; + + let mut pixmap_table = PixmapTable::default(); + pixmap_table.configuration_flags = PixmapTableConfigurationFlags::ConstantWidth | + PixmapTableConfigurationFlags::ConstantHeight | + PixmapTableConfigurationFlags::ConstantBitsPerPixel; + pixmap_table.constant_width = None; + pixmap_table.constant_height = Some(4); + pixmap_table.constant_bits_per_pixel = Some(7); + + pixmap_table.link_flags = PixmapTableLinkFlags::LinkColorTables; + pixmap_table.color_table_indexes = Some(vec![0]); + pixmap_table.pixmaps = vec![pixmap]; + pixmap_table } fn sample_pixmap_table() -> PixmapTable { - PixmapTable { - constant_width: None, - constant_height: Some(4), - constant_bits_per_pixel: Some(1), - color_table_indexes: Some(vec![0]), - pixmaps: vec![ - Pixmap { - custom_width: Some(4), - custom_height: None, - custom_bits_per_pixel: None, - data: vec![0b10011111, 0b11111001], - }, - Pixmap { - custom_width: Some(5), - custom_height: None, - custom_bits_per_pixel: None, - data: vec![0b10110101, 0b11010110, 0b00001111], - }, - Pixmap { - custom_width: Some(4), - custom_height: None, - custom_bits_per_pixel: None, - data: vec![0b00000110, 0b01101001], - }, - Pixmap { - custom_width: Some(4), - custom_height: None, - custom_bits_per_pixel: None, - data: vec![0b11110001, 0b10001111], - }, - ], - } + let mut pixmap1 = Pixmap::default(); + pixmap1.custom_width = Some(4); + pixmap1.data = vec![0b10011111, 0b11111001]; + + let mut pixmap2 = Pixmap::default(); + pixmap2.custom_width = Some(5); + pixmap2.data = vec![0b10110101, 0b11010110, 0b00001111]; + + let mut pixmap3 = Pixmap::default(); + pixmap3.custom_width = Some(4); + pixmap3.data = vec![0b00000110, 0b01101001]; + + let mut pixmap4 = Pixmap::default(); + pixmap4.custom_width = Some(4); + pixmap4.data = vec![0b11110001, 0b10001111]; + + let mut pixmap_table = PixmapTable::default(); + pixmap_table.constant_height = Some(4); + pixmap_table.constant_bits_per_pixel = Some(1); + pixmap_table.color_table_indexes = Some(vec![0]); + pixmap_table.pixmaps = vec![pixmap1, pixmap2, pixmap3, pixmap4]; + pixmap_table } fn sample_color_table() -> ColorTable { - ColorTable { - use_color_type: false, - constant_alpha: None, - colors: vec![ - Color { - color_type: None, - custom_alpha: Some(0), - r: 0, - g: 0, - b: 0, - }, - Color { - color_type: None, - custom_alpha: Some(255), - r: 36, - g: 174, - b: 214, - }, - ], - } + let mut transparent_color = Color::default(); + transparent_color.color_type = None; + transparent_color.custom_alpha = Some(0); + transparent_color.r = 0; + transparent_color.g = 0; + transparent_color.b = 0; + + let mut opaque_color = Color::default(); + opaque_color.color_type = None; + opaque_color.custom_alpha = Some(255); + opaque_color.r = 36; + opaque_color.g = 174; + opaque_color.b = 214; + + let mut color_table = ColorTable::default(); + color_table.colors = vec![transparent_color, opaque_color]; + color_table } fn sample_font_table() -> FontTable { - FontTable { - character_table_indexes: Some(vec![0]), - fonts: vec![Font { - name: "SampleToyFont".into(), - author: "The-Nice-One".into(), - version: 0, - font_type: FontType::Regular, - character_table_indexes: vec![0], - }], - } + let mut font = Font::default(); + font.name = "SampleToyFont".into(); + font.author = "The-Nice-One".into(); + font.version = 0; + font.font_type = FontType::Regular; + font.character_table_indexes = vec![0]; + + let mut font_table = FontTable::default(); + font_table.character_table_indexes = Some(vec![0]); + font_table.fonts = vec![font]; + font_table } fn sample_layout() -> Layout { let mut font = Layout::default(); - font.character_tables = vec![CharacterTable { - use_advance_x: false, - use_pixmap_index: false, - use_pixmap_table_index: false, - constant_cluster_codepoints: None, - pixmap_table_indexes: Some(vec![0]), - characters: vec![ - Character { - advance_x: None, - pixmap_index: None, - pixmap_table_index: None, - grapheme_cluster: "o".to_string(), - }, - Character { - advance_x: None, - pixmap_index: None, - pixmap_table_index: None, - grapheme_cluster: "w".to_string(), - }, - Character { - advance_x: None, - pixmap_index: None, - pixmap_table_index: None, - grapheme_cluster: "😊".to_string(), - }, - Character { - advance_x: None, - pixmap_index: None, - pixmap_table_index: None, - grapheme_cluster: "!=".to_string(), - }, - ], - }]; + let mut char1 = Character::default(); + char1.grapheme_cluster = "o".to_string(); + + let mut char2 = Character::default(); + char2.grapheme_cluster = "w".to_string(); + + let mut char3 = Character::default(); + char3.grapheme_cluster = "😊".to_string(); + + let mut char4 = Character::default(); + char4.grapheme_cluster = "!=".to_string(); + + let mut character_table = CharacterTable::default(); + character_table.pixmap_table_indexes = Some(vec![0]); + character_table.characters = vec![char1, char2, char3, char4]; + + font.character_tables = vec![character_table]; font.pixmap_tables = vec![sample_pixmap_table(), second_sample_pixmap_table()]; font.color_tables = vec![sample_color_table()]; font.font_tables = vec![sample_font_table()];