Skip to content

Commit

Permalink
fix: wrap_text invalid eq
Browse files Browse the repository at this point in the history
  • Loading branch information
zimond committed May 27, 2024
1 parent e21ed12 commit 2f2dcca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fontkit"
version = "0.6.0-beta.1"
version = "0.6.0-beta.2"
edition = "2021"
authors = ["Zimon Dai <[email protected]>"]
description = "A simple library for font loading and indexing"
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ where
if rtl {
std::mem::swap(span, &mut new_span);
}
if !span.metrics.count() == 0 {
if span.metrics.count() != 0 {
current_line.spans.push(span.clone());
}
// Create a new line
Expand Down
29 changes: 26 additions & 3 deletions tests/basic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fontkit::{Error, FontKey};
use fontkit::{Area, Error, FontKey, FontKit, Line, Span, TextMetrics};
use std::fs;
use std::io::Read;

Expand All @@ -7,7 +7,7 @@ pub fn test_font_loading() -> Result<(), Error> {
let mut buf = vec![];
let mut f = fs::File::open("examples/OpenSans-Italic.ttf")?;
f.read_to_end(&mut buf)?;
let fontkit = fontkit::FontKit::new();
let fontkit = FontKit::new();
let _ = fontkit.add_font_from_buffer(buf)?;
Ok(())
}
Expand All @@ -17,7 +17,7 @@ pub fn test_variable_font_loading() -> Result<(), Error> {
let mut buf = vec![];
let mut f = fs::File::open("examples/AlimamaFangYuanTiVF.ttf")?;
f.read_to_end(&mut buf)?;
let fontkit = fontkit::FontKit::new();
let fontkit = FontKit::new();
let _ = fontkit.add_font_from_buffer(buf)?;
let mut key = FontKey::default();
key.family = "AlimamaFangYuanTiVF-Medium-Round".into();
Expand All @@ -33,3 +33,26 @@ pub fn test_variable_font_loading() -> Result<(), Error> {
assert!(bitmap_1 > bitmap_2);
Ok(())
}

#[test]
pub fn test_text_wrap() -> Result<(), Error> {
let fontkit = FontKit::new();
fontkit.search_fonts_from_path("examples/AlimamaFangYuanTiVF.ttf")?;
let key = fontkit.font_keys().next().unwrap();
let mut area = Area::<(), TextMetrics>::new();
let metrics = fontkit
.measure(&key, " 傲冬黑色真皮皮衣 穿着舒适显瘦")
.unwrap();
let mut span = Span::default();
span.font_key = key.clone();
span.size = 66.0;
span.metrics = metrics;
area.lines.push(Line {
spans: vec![span],
hard_break: true,
});
area.unwrap_text();
area.wrap_text(576.0)?;
assert_eq!(area.width(), 549.12);
Ok(())
}

0 comments on commit 2f2dcca

Please sign in to comment.