Colour link annotation borders

This commit is contained in:
gloamxun committed 2026-10-26 02:48:57 +08:00
1 parent 352c44a9b1
commit c95cfa5967
4 files changed
+48 -6

No files matched your search

+32
View File
@@ -246,6 +246,10 @@ struct PageGeometry {
pdf_keywords: Option<String>,
/// Colour applied to `\href` labels (`xcolor`'s `urlcolor`/`linkcolor`).
link_color: Option<String>,
/// Border colour requested for URI link annotations.
link_border_color: Option<String>,
/// `\hypersetup{hidelinks}` drops the annotation border.
hide_links: bool,
/// `thebibliography` entries: label key and entry text, in order.
bibliography: Vec<(String, String)>,
/// `\newtheorem` definitions from the preamble.
@@ -1960,6 +1964,10 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
"pdfsubject" => geometry.pdf_subject = Some(value),
"pdfkeywords" => geometry.pdf_keywords = Some(value),
"urlcolor" | "linkcolor" => geometry.link_color = Some(value),
"linkbordercolor" | "urlbordercolor" => {
geometry.link_border_color = Some(value)
}
"hidelinks" => geometry.hide_links = true,
_ => {}
}
}
@@ -3637,6 +3645,14 @@ pub fn pdf_bytes_with_images(
subject: geometry.pdf_subject.clone(),
keywords: geometry.pdf_keywords.clone(),
outline,
link_border: if geometry.hide_links {
None
} else {
geometry
.link_border_color
.as_deref()
.and_then(|name| color_spec(name, &geometry.colors))
},
};
Ok(display_lists_to_pdf_with_cm_type1_and_metadata(
&pages,
@@ -11391,6 +11407,22 @@ A definition.
assert!(!json.contains("\\large"), "{json}");
}
#[test]
fn hypersetup_link_border_colors_annotations() {
let pdf = pdf_bytes(
"\\hypersetup{linkbordercolor=red}\n\nVisit \\href{https://example.com}{Example}.",
)
.expect("pdf");
let pdf = String::from_utf8_lossy(&pdf);
assert!(pdf.contains("/Border [0 0 1]"), "{pdf}");
assert!(pdf.contains("/C [1.000 0.000 0.000]"), "{pdf}");
let plain = pdf_bytes("Visit \\href{https://example.com}{Example}.").expect("pdf");
let plain = String::from_utf8_lossy(&plain);
assert!(plain.contains("/Border [0 0 0]"), "{plain}");
assert!(!plain.contains("/C [1.000"), "{plain}");
}
#[test]
fn hypersetup_urlcolor_paints_links() {
let json = preview_json(