Skip to content

Commit

Permalink
fix: use indexmap to keep order of fvar data
Browse files Browse the repository at this point in the history
  • Loading branch information
zimond committed Nov 11, 2024
1 parent 60cb517 commit 0c4505a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
7 changes: 4 additions & 3 deletions src/font.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -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<Name>,
Expand All @@ -177,7 +178,7 @@ impl VariationData {
.collect::<Vec<_>>();

// get fvar if any
let mut instances: HashMap<Vec<OrderedFloat<f32>>, Vec<FvarInstance>> = HashMap::new();
let mut instances: IndexMap<Vec<OrderedFloat<f32>>, Vec<FvarInstance>> = 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`
Expand Down
2 changes: 1 addition & 1 deletion tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit 0c4505a

Please sign in to comment.