From 0c4505a2fca5c7cc2d579f282f82872b8ab28021 Mon Sep 17 00:00:00 2001 From: "zhuoxian.dzx" Date: Mon, 11 Nov 2024 14:19:08 +0800 Subject: [PATCH] fix: use indexmap to keep order of fvar data --- Cargo.toml | 1 + src/font.rs | 7 ++++--- tests/basic.rs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6350322..550d0f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ unicode-script = { version = "0.5.4", optional = true } woff2-patched = { version = "0.3.0", optional = true } png = { version = "0.17.13", optional = true } inflections = "1.1.1" +indexmap = "2.6.0" [target.'cfg(target_arch = "wasm32")'.dependencies] wit-bindgen-rt = { version = "0.24.0", optional = true } diff --git a/src/font.rs b/src/font.rs index ad03d29..e9e7907 100644 --- a/src/font.rs +++ b/src/font.rs @@ -1,10 +1,10 @@ use arc_swap::ArcSwap; #[cfg(feature = "parse")] use byteorder::{BigEndian, ReadBytesExt}; +#[cfg(feature = "parse")] +use indexmap::IndexMap; use ordered_float::OrderedFloat; use ouroboros::self_referencing; -#[cfg(feature = "parse")] -use std::collections::HashMap; use std::fmt; use std::hash::Hash; #[cfg(feature = "parse")] @@ -154,6 +154,7 @@ pub fn is_otf(buf: &[u8]) -> bool { && buf[4] == 0x00 } +#[derive(Debug)] pub(crate) struct VariationData { pub key: FontKey, pub names: Vec, @@ -177,7 +178,7 @@ impl VariationData { .collect::>(); // get fvar if any - let mut instances: HashMap>, Vec> = HashMap::new(); + let mut instances: IndexMap>, Vec> = IndexMap::new(); if let (Some(_), Some(name_table)) = (face.tables().fvar, face.tables().name) { // currently ttf-parser is missing `fvar`'s instance records, we parse them // directly from `RawFace` diff --git a/tests/basic.rs b/tests/basic.rs index 61ef32f..6f643e0 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -101,6 +101,6 @@ pub fn test_complex_text_wrap() -> Result<(), Error> { }); area.unwrap_text(); area.wrap_text(64.4)?; - assert_eq!(area.value_string(), "商家\n热卖\n1234\n567\n8"); + assert_eq!(area.value_string(), "商家\n热卖\n123\n456\n78"); Ok(()) }