Draw rounded ORCID badges in PDFs

This commit is contained in:
gloamxun committed 2026-10-19 21:25:31 +08:00
1 parent 5d6d51536f
commit e4c5b0cb32
5 files changed
+56 -11

No files matched your search

+1 -1
View File
@@ -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 green `iD` badge linked to `orcid.org`. Visible `\url` text also
renders a rounded green `iD` badge 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.
+7 -7
View File
@@ -68,13 +68,13 @@ the printpdf writer.
`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 textual green `iD`
badge is the fallback until that image path exists. An inline
`PositionedPageItem::Badge` experiment with a 256 px PNG was reverted:
genpdf emitted a 12x12 px (about 0.5 mm) image regardless of
`Image::with_scale`, so the badge was invisible. The next attempt should
either vendor printpdf's image writer or draw a vector rounded rectangle
with a white iD instead of going through `genpdf::elements::Image`.
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.
### First-page paragraph break
+3 -2
View File
@@ -108,8 +108,9 @@ See `docs/ROADMAP.md` for concrete implementation plans.
- 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 (ORCID green square with a white iD) before the author name; the
original bitmap ORCID logo is not embedded.
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 emits a
PDF `/Link` URI annotation (`/Annots`). `\href`/ORCID-name labels still
carry only colour, because their target URL is not yet stored on the run.
+2 -1
View File
@@ -777,9 +777,10 @@ impl Element for PositionedPages {
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_rect(
badge_area.fill_rounded_rect(
Position::default(),
Size::new(4.0, 4.0),
0.8,
Style::new().with_color(genpdf::style::Color::Rgb(166, 206, 57)),
);
badge_area.print_str(
+43
View File
@@ -365,6 +365,49 @@ impl<'a> Area<'a> {
self.draw_rectangle(position, size, style, false, true);
}
/// Draws a filled rectangle with rounded corners (polygonal arc approximation).
pub fn fill_rounded_rect(&self, position: Position, size: Size, radius: f64, style: Style) {
let px = position.x.0;
let py = position.y.0;
let width = size.width.0;
let height = size.height.0;
let r = radius.min(width / 2.0).min(height / 2.0);
let corners = [
(px + width - r, py + r, -90.0),
(px + width - r, py + height - r, 0.0),
(px + r, py + height - r, 90.0),
(px + r, py + r, 180.0),
];
let mut points = Vec::new();
for (cx, cy, start) in corners {
for step in 0..=6 {
let angle = (start + step as f64 * 15.0).to_radians();
points.push(Position::new(
Mm(cx + r * angle.cos()),
Mm(cy + r * angle.sin()),
));
}
}
let line_points: Vec<_> = points
.into_iter()
.map(|pos| (self.transform_position(pos).into(), false))
.collect();
let line = printpdf::Line {
points: line_points,
is_closed: true,
has_fill: true,
has_stroke: false,
is_clipping_path: false,
};
if let Some(color) = style.color() {
self.layer().set_fill_color(color.into());
}
self.layer().add_shape(line);
if style.color().is_some() {
self.layer().set_fill_color(Color::Rgb(0, 0, 0).into());
}
}
/// Draws a filled axis-aligned rectangle.
///
/// The position is relative to the upper left corner of the area.