Embed the official ORCID logo as a PDF image
This commit is contained in:
1 parent
69edbf56b6
commit
769e3cdf17
8 files changed
+49
-46
No files matched your search
+22
-16
@@ -16,6 +16,7 @@ use genpdf::{
|
||||
fonts::{self, FontData, FontFamily},
|
||||
style::{self, Style},
|
||||
};
|
||||
use image::GenericImageView;
|
||||
use rusttype::Font as RustFont;
|
||||
|
||||
use super::page_builder::{GlueOrder, PageAnchor};
|
||||
@@ -587,10 +588,10 @@ impl PositionedPages {
|
||||
url: Some(url),
|
||||
} => {
|
||||
let left = scaled_units_to_mm(*x);
|
||||
let bottom = page_height_mm - (scaled_units_to_mm(*y) + 4.0);
|
||||
let bottom = page_height_mm - (scaled_units_to_mm(*y) + 2.2);
|
||||
annotations.push(LinkAnnotation {
|
||||
page: index as u32 + 1,
|
||||
rect: [left, bottom, left + 4.0, bottom + 4.0],
|
||||
rect: [left, bottom, left + 2.2, bottom + 2.2],
|
||||
url: url.clone(),
|
||||
});
|
||||
}
|
||||
@@ -810,22 +811,18 @@ impl Element for PositionedPages {
|
||||
let y = scaled_units_to_mm(*y);
|
||||
let mut badge_area = body_area.clone();
|
||||
badge_area.add_offset(Position::new(x, y));
|
||||
badge_area.set_width(Mm::from(4.0));
|
||||
badge_area.set_height(Mm::from(4.0));
|
||||
badge_area.fill_rounded_rect(
|
||||
badge_area.set_width(Mm::from(2.2));
|
||||
badge_area.set_height(Mm::from(2.2));
|
||||
let logo = orcid_logo();
|
||||
let dpi = 600.0;
|
||||
let scale = 2.2 * dpi / (25.4 * logo.width() as f64);
|
||||
badge_area.add_image(
|
||||
logo,
|
||||
Position::default(),
|
||||
Size::new(4.0, 4.0),
|
||||
0.8,
|
||||
Style::new().with_color(genpdf::style::Color::Rgb(166, 206, 57)),
|
||||
genpdf::Scale::new(scale, scale),
|
||||
genpdf::Rotation::from(0.0),
|
||||
Some(dpi),
|
||||
);
|
||||
badge_area.print_str(
|
||||
&context.font_cache,
|
||||
Position::new(1.3, 0.95),
|
||||
Style::new()
|
||||
.with_font_size(5)
|
||||
.with_color(genpdf::style::Color::Rgb(255, 255, 255)),
|
||||
"iD",
|
||||
)?;
|
||||
(RenderResult::default(), y)
|
||||
}
|
||||
PositionedPageItem::FramedBox { element, y, .. } => {
|
||||
@@ -982,6 +979,15 @@ fn box_font_variant(family: &BoxFontFamily, bold: bool, italic: bool) -> &Rc<Rus
|
||||
}
|
||||
}
|
||||
|
||||
fn orcid_logo() -> &'static image::DynamicImage {
|
||||
static LOGO: std::sync::LazyLock<image::DynamicImage> = std::sync::LazyLock::new(|| {
|
||||
let decoded = image::load_from_memory(include_bytes!("../../assets/orcid-logo.png"))
|
||||
.expect("bundled ORCID logo");
|
||||
image::DynamicImage::ImageRgb8(decoded.to_rgb8())
|
||||
});
|
||||
&LOGO
|
||||
}
|
||||
|
||||
fn load_box_font_family(
|
||||
directory: &Path,
|
||||
name: &str,
|
||||
|
||||
@@ -1990,7 +1990,7 @@ pub(super) fn build_positioned_pages(
|
||||
.copied()
|
||||
.unwrap_or(false);
|
||||
let column_start = column as f64 * column_width;
|
||||
let badge_size = 4.0_f64;
|
||||
let badge_size = 2.2_f64;
|
||||
let badge_gap = 1.0_f64;
|
||||
let badge_space = if has_badge {
|
||||
badge_size + badge_gap
|
||||
|
||||
@@ -265,11 +265,11 @@ fn write_table_rule(
|
||||
fn write_badge(output: &mut String, x: i64, y: i64) {
|
||||
let _ = write!(
|
||||
output,
|
||||
"<rect x=\"{:.4}\" y=\"{:.4}\" width=\"4.0000\" height=\"4.0000\" rx=\"0.8\" ry=\"0.8\" fill=\"#A6CE39\" /><text x=\"{:.4}\" y=\"{:.4}\" font-size=\"2.6\" fill=\"#FFFFFF\" font-family=\"serif\">iD</text>",
|
||||
"<rect x=\"{:.4}\" y=\"{:.4}\" width=\"2.2000\" height=\"2.2000\" rx=\"0.45\" ry=\"0.45\" fill=\"#A6CE39\" /><text x=\"{:.4}\" y=\"{:.4}\" font-size=\"1.45\" fill=\"#FFFFFF\" font-family=\"serif\">iD</text>",
|
||||
scaled_units_to_mm(x),
|
||||
scaled_units_to_mm(y),
|
||||
scaled_units_to_mm(x) + 0.7,
|
||||
scaled_units_to_mm(y) + 1.4,
|
||||
scaled_units_to_mm(x) + 0.35,
|
||||
scaled_units_to_mm(y) + 0.78,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user