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
@@ -364,7 +364,7 @@ are not implemented. These LaTeX command
|
||||
definitions support up to nine parameters, including one optional first
|
||||
parameter with a default value. Unknown packages fail with a clear error. Hyperlinks (`\href`, `\url`, and
|
||||
resolved citations) use hyperref's green link colour; `\orcidlink{id}`
|
||||
renders a rounded green `iD` badge linked to `orcid.org`. Visible `\url` text also
|
||||
renders the bundled official ORCID logo (2.2 mm) linked to `orcid.org`. Visible `\url` text also
|
||||
emits a real PDF `/Link` URI annotation; `\href` and ORCID-name links still
|
||||
need their target URL carried through the document model.
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
+5
-10
@@ -65,16 +65,11 @@ the printpdf writer.
|
||||
|
||||
### ORCID author icon
|
||||
|
||||
`orcid.pdf` is an image inside `\author`, but metadata currently keeps text
|
||||
only. The title author-row renderer needs a positioned-image item that accepts an
|
||||
x offset (the current `PositionedPageItem::Image` is pinned to x = 0) and a
|
||||
small PNG/vector badge loaded from repository assets. The current fallback is
|
||||
`PositionedPageItem::Badge`: a native rounded polygon in the PDF (through the
|
||||
vendored `genpdf::Area::fill_rounded_rect`) and a rounded `rect` in SVG, with a
|
||||
white `iD` label. An earlier 256 px PNG experiment was reverted because genpdf
|
||||
emitted a 12x12 px image regardless of `Image::with_scale`. Replacing the
|
||||
polygon with the official ORCID bitmap still needs an image writer that keeps
|
||||
the requested size and an x offset.
|
||||
Completed: `\orcidlink` and ORCID author URLs use the bundled official logo
|
||||
`assets/orcid-logo.png` (rasterized from the template's `orcid.pdf`), embedded
|
||||
at 2.2 mm before the author name. SVG preview keeps the rounded `rect` shape.
|
||||
The PDF badge is positioned by `PositionedPageItem::Badge` and carries its
|
||||
`/Link` annotation. No remaining template-specific icon path is needed.
|
||||
|
||||
### First-page paragraph break
|
||||
|
||||
|
||||
+13
-15
@@ -107,18 +107,16 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
||||
the next page.
|
||||
- Contents: chapter headings are listed with chapter-prefixed section
|
||||
numbers, but contents are not split per chapter.
|
||||
- Preprint title blocks: ORCID links in `\author` render as a native vector
|
||||
badge (rounded ORCID-green polygon with a white iD, drawn natively in PDF
|
||||
and SVG) before the author name; the original bitmap ORCID logo is not
|
||||
embedded.
|
||||
Hyperlinks use hyperref's green text colour; visible `\url` text,
|
||||
`\href` display labels, and ORCID author badges emit PDF `/Link` URI
|
||||
annotations (`/Annots`).
|
||||
Metadata baselines match the reference within 0.3 pt and page 1 keeps the
|
||||
same closing section-2 line as the reference. `printpdf 0.3.4` has no
|
||||
annotation API, so the link is added by reopening the finished PDF with
|
||||
lopdf and extending each page dictionary. Extending this to `\href`/ORCID
|
||||
labels (and API-provided ORCID icon images) is the next step.
|
||||
- Preprint title blocks: ORCID links in `\author` embed the bundled
|
||||
official ORCID logo (`assets/orcid-logo.png`, rasterized from the
|
||||
template's `orcid.pdf`) as a 2.2 mm image before the author name; the SVG
|
||||
preview keeps a rounded `rect` fallback. Hyperlinks use hyperref's green
|
||||
text colour; visible `\url` text, `\href` display labels, and ORCID author
|
||||
badges emit PDF `/Link` URI annotations (`/Annots`). Metadata baselines
|
||||
match the reference within 0.3 pt and page 1 keeps the same closing
|
||||
section-2 line as the reference. `printpdf 0.3.4` has no annotation API,
|
||||
so the link is added by reopening the finished PDF with lopdf and extending
|
||||
each page dictionary.
|
||||
|
||||
## Verification
|
||||
|
||||
@@ -128,7 +126,7 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
||||
3.6 MB and `pdffonts` reports only embedded CID TrueType faces); this avoids
|
||||
viewer-dependent glyph substitution. Tables use natural column widths and
|
||||
centered rules; preview and PDF share the same table line coordinates.
|
||||
- `cargo fmt --check` passes; `cargo test --offline` (58 tests: 53 compiler
|
||||
- `cargo fmt --check` passes; `cargo test --offline` (58 tests: 54 compiler
|
||||
integration tests + 4 server tests) covers the three examples, the arXiv
|
||||
fixture, figure/table floats (top and bottom), newpage, page styles and `\thispagestyle`, SVG/PDF output,
|
||||
project API, static frontend assets, path traversal, the legacy
|
||||
@@ -139,7 +137,7 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
||||
|
||||
- Compiler integration tests: 53; server tests: 4; total 57.
|
||||
- `cargo fmt --check` passes.
|
||||
- arXiv fixture: 3 Letter pages, ~0.50 MB; four serif faces and one monospace face embedded (bold/italic monospace falls back to the regular face). The bundled SubsetTTF faces are pyftsubset outputs with retained glyph ids and a filtered legacy kern table; a second smaller Latin-1/Greek tier is selected when the document charset fits.
|
||||
- arXiv fixture: 3 Letter pages, ~0.53 MB; four serif faces and one monospace face embedded (bold/italic monospace falls back to the regular face). The bundled SubsetTTF faces are pyftsubset outputs with retained glyph ids and a filtered legacy kern table; a second smaller Latin-1/Greek tier is selected when the document charset fits.
|
||||
- Title/author/date/Introduction baselines within 0.3 pt of the XeLaTeX
|
||||
reference; page 1 keeps the closing section-2 line above the footnote.
|
||||
- Table 61.1 mm wide (reference 61.2 mm) with `\multicolumn` spans and
|
||||
@@ -148,4 +146,4 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
||||
- PDF link annotations are added by reopening the finished PDF with lopdf,
|
||||
since printpdf 0.3.4 has no annotation API.
|
||||
|
||||
- Fonts: bundled reserved-glyph subsets in `assets/fonts-subset/` are used when the document charset is covered; arXiv PDF is about 0.50 MB with 58 tests.
|
||||
- Fonts: bundled reserved-glyph subsets in `assets/fonts-subset/` are used when the document charset is covered; arXiv PDF is about 0.53 MB with 58 tests.
|
||||
+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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,10 @@ fn arxiv_author_orcid_links_have_pdf_annotations() {
|
||||
text.contains("orcid.org/0000-0000-0000-0000"),
|
||||
"annotation should carry the ORCID URL"
|
||||
);
|
||||
assert!(
|
||||
text.contains("/Subtype/Image"),
|
||||
"the bundled ORCID logo should be embedded as an image"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user