summaryrefslogtreecommitdiffstats
path: root/vendor/plotters/src/style/font/naive.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/plotters/src/style/font/naive.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/plotters/src/style/font/naive.rs')
-rw-r--r--vendor/plotters/src/style/font/naive.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/plotters/src/style/font/naive.rs b/vendor/plotters/src/style/font/naive.rs
new file mode 100644
index 000000000..99530401b
--- /dev/null
+++ b/vendor/plotters/src/style/font/naive.rs
@@ -0,0 +1,40 @@
+use super::{FontData, FontFamily, FontStyle, LayoutBox};
+
+#[derive(Debug, Clone)]
+pub struct FontError;
+
+impl std::fmt::Display for FontError {
+ fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+ write!(fmt, "General Error")?;
+ Ok(())
+ }
+}
+
+impl std::error::Error for FontError {}
+
+#[derive(Clone)]
+pub struct FontDataInternal(String, String);
+
+impl FontData for FontDataInternal {
+ type ErrorType = FontError;
+ fn new(family: FontFamily, style: FontStyle) -> Result<Self, FontError> {
+ Ok(FontDataInternal(
+ family.as_str().into(),
+ style.as_str().into(),
+ ))
+ }
+
+ /// Note: This is only a crude estimatation, since for some backend such as SVG, we have no way to
+ /// know the real size of the text anyway. Thus using font-kit is an overkill and doesn't helps
+ /// the layout.
+ fn estimate_layout(&self, size: f64, text: &str) -> Result<LayoutBox, Self::ErrorType> {
+ let em = size / 1.24 / 1.24;
+ Ok((
+ (0, -em.round() as i32),
+ (
+ (em * 0.7 * text.len() as f64).round() as i32,
+ (em * 0.24).round() as i32,
+ ),
+ ))
+ }
+}