summaryrefslogtreecommitdiff
path: root/src/export/pdf
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-28 12:40:16 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-28 12:40:16 +0100
commit989d170dc7318ca3cbaa5b76760eb14f4e6a8605 (patch)
tree0a486ddb4d339b8a43313f7c6e18b9595b8fd955 /src/export/pdf
parent7caf98fe42797eab59a39ef71071030c9790245a (diff)
Fragments
Diffstat (limited to 'src/export/pdf')
-rw-r--r--src/export/pdf/mod.rs2
-rw-r--r--src/export/pdf/outline.rs33
-rw-r--r--src/export/pdf/page.rs23
3 files changed, 15 insertions, 43 deletions
diff --git a/src/export/pdf/mod.rs b/src/export/pdf/mod.rs
index 7e5a3c06..8f9d9637 100644
--- a/src/export/pdf/mod.rs
+++ b/src/export/pdf/mod.rs
@@ -12,7 +12,7 @@ use std::hash::Hash;
use pdf_writer::types::Direction;
use pdf_writer::{Finish, Name, PdfWriter, Ref, TextStr};
-use self::outline::{Heading, HeadingNode};
+use self::outline::HeadingNode;
use self::page::Page;
use crate::doc::{Document, Lang, Metadata};
use crate::font::Font;
diff --git a/src/export/pdf/outline.rs b/src/export/pdf/outline.rs
index add167b4..e7a356c1 100644
--- a/src/export/pdf/outline.rs
+++ b/src/export/pdf/outline.rs
@@ -4,43 +4,34 @@ use super::{AbsExt, PdfContext, RefExt};
use crate::geom::{Abs, Point};
use crate::util::EcoString;
-/// A heading that can later be linked in the outline panel.
+/// A heading in the outline panel.
#[derive(Debug, Clone)]
-pub struct Heading {
+pub struct HeadingNode {
pub content: EcoString,
pub level: usize,
pub position: Point,
pub page: Ref,
-}
-
-/// A node in the outline tree.
-#[derive(Debug, Clone)]
-pub struct HeadingNode {
- pub heading: Heading,
pub children: Vec<HeadingNode>,
}
impl HeadingNode {
- pub fn leaf(heading: Heading) -> Self {
- HeadingNode { heading, children: Vec::new() }
- }
-
pub fn len(&self) -> usize {
1 + self.children.iter().map(Self::len).sum::<usize>()
}
- pub fn insert(&mut self, other: Heading, level: usize) -> bool {
- if level >= other.level {
+ #[allow(unused)]
+ pub fn try_insert(&mut self, child: Self, level: usize) -> bool {
+ if level >= child.level {
return false;
}
- if let Some(child) = self.children.last_mut() {
- if child.insert(other.clone(), level + 1) {
+ if let Some(last) = self.children.last_mut() {
+ if last.try_insert(child.clone(), level + 1) {
return true;
}
}
- self.children.push(Self::leaf(other));
+ self.children.push(child);
true
}
}
@@ -74,10 +65,10 @@ pub fn write_outline_item(
outline.count(-(node.children.len() as i32));
}
- outline.title(TextStr(&node.heading.content));
- outline.dest_direct().page(node.heading.page).xyz(
- node.heading.position.x.to_f32(),
- (node.heading.position.y + Abs::pt(3.0)).to_f32(),
+ outline.title(TextStr(&node.content));
+ outline.dest_direct().page(node.page).xyz(
+ node.position.x.to_f32(),
+ (node.position.y + Abs::pt(3.0)).to_f32(),
None,
);
diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs
index 7c479425..fc714e7a 100644
--- a/src/export/pdf/page.rs
+++ b/src/export/pdf/page.rs
@@ -2,10 +2,8 @@ use pdf_writer::types::{ActionType, AnnotationType, ColorSpaceOperand};
use pdf_writer::writers::ColorSpace;
use pdf_writer::{Content, Filter, Finish, Name, Rect, Ref, Str};
-use super::{
- deflate, AbsExt, EmExt, Heading, HeadingNode, PdfContext, RefExt, D65_GRAY, SRGB,
-};
-use crate::doc::{Destination, Element, Frame, Group, Role, Text};
+use super::{deflate, AbsExt, EmExt, PdfContext, RefExt, D65_GRAY, SRGB};
+use crate::doc::{Destination, Element, Frame, Group, Text};
use crate::font::Font;
use crate::geom::{
self, Abs, Color, Em, Geometry, Numeric, Paint, Point, Ratio, Shape, Size, Stroke,
@@ -281,23 +279,6 @@ impl PageContext<'_, '_> {
/// Encode a frame into the content stream.
fn write_frame(ctx: &mut PageContext, frame: &Frame) {
- if let Some(Role::Heading { level, outlined: true }) = frame.role() {
- let heading = Heading {
- position: Point::new(ctx.state.transform.tx, ctx.state.transform.ty),
- content: frame.text(),
- page: ctx.page_ref,
- level: level.get(),
- };
-
- if let Some(last) = ctx.parent.heading_tree.last_mut() {
- if !last.insert(heading.clone(), 1) {
- ctx.parent.heading_tree.push(HeadingNode::leaf(heading))
- }
- } else {
- ctx.parent.heading_tree.push(HeadingNode::leaf(heading))
- }
- }
-
for &(pos, ref element) in frame.elements() {
let x = pos.x.to_f32();
let y = pos.y.to_f32();