mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-01 21:57:12 -06:00
Type: Kerning has an Optical option that spaces characters by their shapes
Squashed from #4825 onto main.
This commit is contained in:
@@ -388,6 +388,18 @@ fn char_position_round_trips() {
|
||||
assert!((scale - 0.583).abs() < 1e-9 && (shift + 3.33).abs() < 1e-9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn optical_kerning_round_trips_and_old_style_defaults_to_auto() {
|
||||
let st = CharStyle { optical_kerning: true, kerning: Some(120.0), ..CharStyle::default() };
|
||||
let value = serde_json::to_value(&st).unwrap();
|
||||
assert_eq!(value["opticalKerning"], true);
|
||||
assert_eq!(serde_json::from_value::<CharStyle>(value.clone()).unwrap(), st);
|
||||
let mut old = value;
|
||||
old.as_object_mut().unwrap().remove("opticalKerning");
|
||||
assert!(!serde_json::from_value::<CharStyle>(old).unwrap().optical_kerning);
|
||||
assert!(serde_json::to_value(CharStyle::default()).unwrap().get("opticalKerning").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn units() {
|
||||
assert_eq!(Unit::Inches.parse("1"), Some(72.0));
|
||||
|
||||
@@ -25,9 +25,12 @@ pub struct CharStyle {
|
||||
/// Tracking in 1/1000 em.
|
||||
#[serde(default)]
|
||||
pub tracking: f64,
|
||||
/// Kerning: None = Auto (metrics), Some(v) = manual in 1/1000 em.
|
||||
/// Manual pair spacing in 1/1000 em; None uses the automatic mode.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub kerning: Option<f64>,
|
||||
/// Use glyph shapes for automatic pair spacing; false uses font metrics.
|
||||
#[serde(default, rename = "opticalKerning", skip_serializing_if = "crate::skip::is_default")]
|
||||
pub optical_kerning: bool,
|
||||
#[serde(default)]
|
||||
pub baseline_shift: f64,
|
||||
#[serde(default = "hundred")]
|
||||
@@ -266,6 +269,7 @@ impl Default for CharStyle {
|
||||
leading: None,
|
||||
tracking: 0.0,
|
||||
kerning: None,
|
||||
optical_kerning: false,
|
||||
baseline_shift: 0.0,
|
||||
h_scale: 100.0,
|
||||
v_scale: 100.0,
|
||||
|
||||
@@ -223,6 +223,7 @@ impl ParaList {
|
||||
position: CharPosition::Normal,
|
||||
tracking: 0.0,
|
||||
kerning: None,
|
||||
optical_kerning: first.optical_kerning,
|
||||
tate_chu_yoko: false,
|
||||
underline: false,
|
||||
strikethrough: false,
|
||||
|
||||
Reference in New Issue
Block a user