Nest PDF bookmarks by heading level
This commit is contained in:
1 parent
5f98c199a5
commit
a4c4864d2b
5 files changed
+135
-20
No files matched your search
+16
-6
@@ -2161,10 +2161,11 @@ pub fn pdf_bytes_with_images(
|
||||
}
|
||||
let outline: Vec<PdfOutlineEntry> = outline_units
|
||||
.iter()
|
||||
.filter_map(|(title, unit)| {
|
||||
.filter_map(|(title, level, unit)| {
|
||||
page_of.get(unit).map(|page| PdfOutlineEntry {
|
||||
title: title.clone(),
|
||||
page: *page,
|
||||
level: *level,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
@@ -6072,7 +6073,7 @@ fn build_document_with_labels(
|
||||
paragraphs: &[SourceParagraph],
|
||||
geometry: &PageGeometry,
|
||||
label_units: &mut HashMap<String, u64>,
|
||||
outline_units: &mut Vec<(String, u64)>,
|
||||
outline_units: &mut Vec<(String, u8, u64)>,
|
||||
) -> Document {
|
||||
let mut paragraphs = expand_maketitle(paragraphs, geometry);
|
||||
if let Some(name) = geometry.abstract_name.as_deref() {
|
||||
@@ -6523,8 +6524,13 @@ fn build_document_with_labels(
|
||||
}
|
||||
}
|
||||
for (index, paragraph) in paragraphs.iter().enumerate() {
|
||||
if paragraph.heading_level.is_some() && paragraph.heading_number.is_some() {
|
||||
outline_units.push((paragraph.text.clone(), unit_for_paragraph[index] as u64));
|
||||
if let (Some(level), Some(_)) = (paragraph.heading_level, paragraph.heading_number.as_ref())
|
||||
{
|
||||
outline_units.push((
|
||||
paragraph.text.clone(),
|
||||
level,
|
||||
unit_for_paragraph[index] as u64,
|
||||
));
|
||||
}
|
||||
}
|
||||
let mut document = Document::new(700 * SCALE, units);
|
||||
@@ -7627,12 +7633,16 @@ a & b
|
||||
#[test]
|
||||
#[test]
|
||||
fn headings_become_pdf_bookmarks() {
|
||||
let pdf = pdf_bytes("\\section{One}\n\nFirst.\n\n\\newpage\n\n\\section{Two}\n\nSecond.")
|
||||
.expect("pdf");
|
||||
let pdf = pdf_bytes(
|
||||
"\\section{One}\n\n\\subsection{Sub}\n\n\\newpage\n\n\\section{Two}\n\nSecond.",
|
||||
)
|
||||
.expect("pdf");
|
||||
let text = String::from_utf8_lossy(&pdf);
|
||||
assert!(text.contains("/Type /Outlines"));
|
||||
assert!(text.contains("/Title (1 One)"));
|
||||
assert!(text.contains("/Title (1.1 Sub)"));
|
||||
assert!(text.contains("/Title (2 Two)"));
|
||||
assert!(text.contains("/Count 3"));
|
||||
}
|
||||
|
||||
fn hypersetup_writes_the_pdf_info_dictionary() {
|
||||
|
||||
Reference in new issue
Block a user