Colour link annotation borders
This commit is contained in:
1 parent
352c44a9b1
commit
c95cfa5967
4 files changed
+48
-6
No files matched your search
@@ -647,6 +647,8 @@ pub struct PdfMetadata {
|
||||
pub subject: Option<String>,
|
||||
pub keywords: Option<String>,
|
||||
pub outline: Vec<PdfOutlineEntry>,
|
||||
/// Border and colour for URI link annotations, when set.
|
||||
pub link_border: Option<[u8; 3]>,
|
||||
}
|
||||
|
||||
/// One flat bookmark pointing at a page of the exported document.
|
||||
@@ -1071,11 +1073,20 @@ fn write_pdf(
|
||||
objects.push(object);
|
||||
}
|
||||
|
||||
let link_border = match metadata.link_border {
|
||||
Some([red, green, blue]) => format!(
|
||||
"/Border [0 0 1] /C [{:.3} {:.3} {:.3}]",
|
||||
red as f64 / 255.0,
|
||||
green as f64 / 255.0,
|
||||
blue as f64 / 255.0
|
||||
),
|
||||
None => "/Border [0 0 0]".to_string(),
|
||||
};
|
||||
for (index, (x, y, width, link_height, url)) in links.iter().enumerate() {
|
||||
let _ = index;
|
||||
objects.push(
|
||||
format!(
|
||||
"<< /Type /Annot /Subtype /Link /Rect [{:.3} {:.3} {:.3} {:.3}] /Border [0 0 0] /A << /S /URI /URI ({}) >> >>",
|
||||
"<< /Type /Annot /Subtype /Link /Rect [{:.3} {:.3} {:.3} {:.3}] {link_border} /A << /S /URI /URI ({}) >> >>",
|
||||
*x as f64 / 65_536.0,
|
||||
(height as f64 - *y as f64 - *link_height as f64) / 65_536.0,
|
||||
(*x + *width) as f64 / 65_536.0,
|
||||
@@ -1273,8 +1284,6 @@ mod type1_pdf_tests {
|
||||
assert!(cmap.contains(&format!("<{code:02X}> <03A9>")), "{cmap}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[test]
|
||||
#[test]
|
||||
fn outline_entries_become_pdf_bookmarks() {
|
||||
let pages = vec![
|
||||
@@ -1336,6 +1345,7 @@ mod type1_pdf_tests {
|
||||
subject: None,
|
||||
keywords: None,
|
||||
outline: Vec::new(),
|
||||
link_border: None,
|
||||
};
|
||||
let pdf = String::from_utf8_lossy(&display_lists_to_pdf_with_cm_type1_and_metadata(
|
||||
&pages,
|
||||
|
||||
Reference in new issue
Block a user