mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Remove dependencies on itoa and ryu ⬇️
This commit is contained in:
parent
36adbe4b80
commit
45abcf6b2b
@ -15,10 +15,8 @@ fs = ["fontdock/fs"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
fontdock = { path = "../fontdock", default-features = false }
|
fontdock = { path = "../fontdock", default-features = false }
|
||||||
image = { version = "0.23", default-features = false, features = ["jpeg", "png"] }
|
image = { version = "0.23", default-features = false, features = ["jpeg", "png"] }
|
||||||
itoa = "0.4"
|
|
||||||
miniz_oxide = "0.3"
|
miniz_oxide = "0.3"
|
||||||
pdf-writer = { path = "../pdf-writer" }
|
pdf-writer = { path = "../pdf-writer" }
|
||||||
ryu = "1.0"
|
|
||||||
ttf-parser = "0.8.2"
|
ttf-parser = "0.8.2"
|
||||||
unicode-xid = "0.2"
|
unicode-xid = "0.2"
|
||||||
anyhow = { version = "1", optional = true }
|
anyhow = { version = "1", optional = true }
|
||||||
|
@ -58,14 +58,13 @@ impl Display for Angle {
|
|||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
// Format with the unit that yields the shortest output, preferring
|
// Format with the unit that yields the shortest output, preferring
|
||||||
// degrees when tied.
|
// degrees when tied.
|
||||||
let mut buf = ryu::Buffer::new();
|
|
||||||
let unit = [AngularUnit::Deg, AngularUnit::Rad]
|
let unit = [AngularUnit::Deg, AngularUnit::Rad]
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.min_by_key(|&unit| buf.format(self.to_unit(unit)).len())
|
.min_by_key(|&unit| self.to_unit(unit).to_string().len())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
write!(f, "{}{}", buf.format(self.to_unit(unit)), unit)
|
write!(f, "{}{}", self.to_unit(unit), unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,14 +108,13 @@ impl Display for Length {
|
|||||||
|
|
||||||
// Format with the unit that yields the shortest output, preferring
|
// Format with the unit that yields the shortest output, preferring
|
||||||
// larger / metric units when tied.
|
// larger / metric units when tied.
|
||||||
let mut buf = ryu::Buffer::new();
|
|
||||||
let unit = [Cm, Mm, In, Pt]
|
let unit = [Cm, Mm, In, Pt]
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.min_by_key(|&unit| buf.format(self.to_unit(unit)).len())
|
.min_by_key(|&unit| self.to_unit(unit).to_string().len())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
write!(f, "{}{}", buf.format(self.to_unit(unit)), unit)
|
write!(f, "{}{}", self.to_unit(unit), unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,9 +238,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_length_formatting() {
|
fn test_length_formatting() {
|
||||||
assert_eq!(Length::pt(23.0).to_string(), "23.0pt");
|
assert_eq!(Length::pt(23.0).to_string(), "23pt");
|
||||||
assert_eq!(Length::pt(-28.3465).to_string(), "-1.0cm");
|
assert_eq!(Length::pt(-28.3465).to_string(), "-1cm");
|
||||||
assert_eq!(Length::cm(12.728).to_string(), "12.728cm");
|
assert_eq!(Length::cm(12.728).to_string(), "12.728cm");
|
||||||
assert_eq!(Length::cm(4.5).to_string(), "4.5cm");
|
assert_eq!(Length::cm(4.5).to_string(), "45mm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ impl Relative {
|
|||||||
|
|
||||||
impl Display for Relative {
|
impl Display for Relative {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
write!(f, "{}%", ryu::Buffer::new().format(100.0 * self.0))
|
write!(f, "{}%", 100.0 * self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,15 +240,9 @@ impl Pretty for LitKind {
|
|||||||
Self::Bool(v) => v.pretty(p),
|
Self::Bool(v) => v.pretty(p),
|
||||||
Self::Int(v) => v.pretty(p),
|
Self::Int(v) => v.pretty(p),
|
||||||
Self::Float(v) => v.pretty(p),
|
Self::Float(v) => v.pretty(p),
|
||||||
Self::Length(v, u) => {
|
Self::Length(v, u) => write!(p, "{}{}", v, u).unwrap(),
|
||||||
write!(p, "{}{}", ryu::Buffer::new().format(*v), u).unwrap();
|
Self::Angle(v, u) => write!(p, "{}{}", v, u).unwrap(),
|
||||||
}
|
Self::Percent(v) => write!(p, "{}%", v).unwrap(),
|
||||||
Self::Angle(v, u) => {
|
|
||||||
write!(p, "{}{}", ryu::Buffer::new().format(*v), u).unwrap();
|
|
||||||
}
|
|
||||||
Self::Percent(v) => {
|
|
||||||
write!(p, "{}%", ryu::Buffer::new().format(*v)).unwrap();
|
|
||||||
}
|
|
||||||
Self::Color(v) => v.pretty(p),
|
Self::Color(v) => v.pretty(p),
|
||||||
Self::Str(v) => v.pretty(p),
|
Self::Str(v) => v.pretty(p),
|
||||||
}
|
}
|
||||||
@ -561,13 +555,13 @@ impl Pretty for ValueArg {
|
|||||||
|
|
||||||
impl Pretty for i64 {
|
impl Pretty for i64 {
|
||||||
fn pretty(&self, p: &mut Printer) {
|
fn pretty(&self, p: &mut Printer) {
|
||||||
p.push_str(itoa::Buffer::new().format(*self));
|
write!(p, "{}", self).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pretty for f64 {
|
impl Pretty for f64 {
|
||||||
fn pretty(&self, p: &mut Printer) {
|
fn pretty(&self, p: &mut Printer) {
|
||||||
p.push_str(ryu::Buffer::new().format(*self));
|
write!(p, "{}", self).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -681,9 +675,9 @@ mod tests {
|
|||||||
roundtrip("{true}");
|
roundtrip("{true}");
|
||||||
roundtrip("{10}");
|
roundtrip("{10}");
|
||||||
roundtrip("{3.14}");
|
roundtrip("{3.14}");
|
||||||
roundtrip("{10.0pt}");
|
roundtrip("{10pt}");
|
||||||
roundtrip("{14.1deg}");
|
roundtrip("{14.1deg}");
|
||||||
roundtrip("{20.0%}");
|
roundtrip("{20%}");
|
||||||
roundtrip("{#abcdef}");
|
roundtrip("{#abcdef}");
|
||||||
roundtrip(r#"{"hi"}"#);
|
roundtrip(r#"{"hi"}"#);
|
||||||
test_parse(r#"{"let's \" go"}"#, r#"{"let's \" go"}"#);
|
test_parse(r#"{"let's \" go"}"#, r#"{"let's \" go"}"#);
|
||||||
@ -749,9 +743,9 @@ mod tests {
|
|||||||
test_value(12i64, "12");
|
test_value(12i64, "12");
|
||||||
test_value(3.14, "3.14");
|
test_value(3.14, "3.14");
|
||||||
test_value(Length::pt(5.5), "5.5pt");
|
test_value(Length::pt(5.5), "5.5pt");
|
||||||
test_value(Angle::deg(90.0), "90.0deg");
|
test_value(Angle::deg(90.0), "90deg");
|
||||||
test_value(Relative::ONE / 2.0, "50.0%");
|
test_value(Relative::ONE / 2.0, "50%");
|
||||||
test_value(Relative::new(0.3) + Length::cm(2.0), "30.0% + 2.0cm");
|
test_value(Relative::new(0.3) + Length::cm(2.0), "30% + 2cm");
|
||||||
test_value(Color::Rgba(RgbaColor::new(1, 1, 1, 0xff)), "#010101");
|
test_value(Color::Rgba(RgbaColor::new(1, 1, 1, 0xff)), "#010101");
|
||||||
test_value("hello", r#""hello""#);
|
test_value("hello", r#""hello""#);
|
||||||
test_value("\n", r#""\n""#);
|
test_value("\n", r#""\n""#);
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 9.1 KiB |
Loading…
x
Reference in New Issue
Block a user