Skip to content

Commit 08d11b9

Browse files
committed
feat: add include_path option
1 parent 272ad73 commit 08d11b9

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

crates/c2pdf-gui/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn app_view() -> impl IntoView {
129129
Dimensions::default(),
130130
12.0,
131131
None,
132+
true,
132133
&logger_for_thread,
133134
None,
134135
);

crates/c2pdf/src/bin/c2pdf.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ struct Arguments {
3333
)]
3434
exclude: StringVec,
3535

36+
/// whether to include the path at the top of each page
37+
///
38+
/// defaults to true
39+
#[argh(option, default = "true")]
40+
include_path: bool,
41+
3642
/// name of PDF
3743
#[argh(option, default = "String::from(\"Project Code\")")]
3844
name: String,
@@ -102,6 +108,7 @@ fn main() {
102108
page_dimensions,
103109
args.font_size,
104110
args.page_text,
111+
args.include_path,
105112
&logger,
106113
args.threads,
107114
);

crates/c2pdf/src/lib/code_to_pdf.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub struct CodeToPdf {
106106
page_dimensions: Dimensions,
107107
text_wrapper: TextWrapper,
108108
processed_file_count: usize,
109+
include_path: bool,
109110
// Text to put at the top of every page
110111
page_text: Option<ProcessedText>,
111112
}
@@ -117,6 +118,7 @@ impl CodeToPdf {
117118
page_dimensions: Dimensions,
118119
text_wrapper: TextWrapper,
119120
page_text: Option<ProcessedText>,
121+
include_path: bool,
120122
) -> Self {
121123
Self {
122124
current_page_contents: vec![],
@@ -126,6 +128,7 @@ impl CodeToPdf {
126128
text_wrapper,
127129
processed_file_count: 0,
128130
page_text,
131+
include_path,
129132
}
130133
}
131134
/// Saves the current page contents to the document, and clears [`CodeToPdf::current_page_contents`]
@@ -154,6 +157,7 @@ impl CodeToPdf {
154157
self.text_wrapper.font_size(),
155158
path,
156159
self.page_text.as_ref(),
160+
self.include_path,
157161
&mut self.text_wrapper,
158162
);
159163
}

crates/c2pdf/src/lib/helpers.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn init_page(
3434
font_size: f32,
3535
path: &Path,
3636
additional_text: Option<&ProcessedText>,
37+
include_path: bool,
3738
wrapper: &mut TextWrapper,
3839
) {
3940
contents.extend_from_slice(&[
@@ -66,31 +67,33 @@ pub fn init_page(
6667
contents.push(Op::AddLineBreak);
6768
}
6869
}
69-
contents.extend_from_slice(&[
70-
Op::SetTextMatrix {
71-
matrix: TextMatrix::Translate(Pt(0.0), Pt(0.0)),
72-
},
73-
// Write metadata
74-
Op::SetTextCursor {
75-
pos: Point {
76-
x: page_dimensions.margin_left.into(),
77-
y: (page_dimensions.height - Mm(7.5)).into(),
70+
if include_path {
71+
contents.extend_from_slice(&[
72+
Op::SetTextMatrix {
73+
matrix: TextMatrix::Translate(Pt(0.0), Pt(0.0)),
7874
},
79-
},
80-
]);
81-
let max_path_width = (page_dimensions.max_text_width()
82-
- if let Some(text) = &additional_text {
83-
Mm::from(Pt(text.width)) + Mm(5.0)
84-
} else {
85-
Mm(0.0)
86-
})
87-
.into_pt();
88-
for (line, _) in wrapper.split_into_lines(&path.display().to_string(), |_| max_path_width) {
89-
contents.push(Op::WriteText {
90-
items: vec![TextItem::Text(line)],
91-
font: font_id.clone(),
92-
});
93-
contents.push(Op::AddLineBreak);
75+
// Write metadata
76+
Op::SetTextCursor {
77+
pos: Point {
78+
x: page_dimensions.margin_left.into(),
79+
y: (page_dimensions.height - Mm(7.5)).into(),
80+
},
81+
},
82+
]);
83+
let max_path_width = (page_dimensions.max_text_width()
84+
- if let Some(text) = &additional_text {
85+
Mm::from(Pt(text.width)) + Mm(5.0)
86+
} else {
87+
Mm(0.0)
88+
})
89+
.into_pt();
90+
for (line, _) in wrapper.split_into_lines(&path.display().to_string(), |_| max_path_width) {
91+
contents.push(Op::WriteText {
92+
items: vec![TextItem::Text(line)],
93+
font: font_id.clone(),
94+
});
95+
contents.push(Op::AddLineBreak);
96+
}
9497
}
9598

9699
// Set cursor to main body

crates/c2pdf/src/lib/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl CodeToPdf {
4444
page_dimensions: Dimensions,
4545
font_size: f32,
4646
page_text: Option<String>,
47+
include_path: bool,
4748
logger: &Logger,
4849
threads: Option<NonZeroU8>,
4950
) -> (Arc<Mutex<DocumentSubset>>, usize) {
@@ -96,6 +97,7 @@ impl CodeToPdf {
9697
page_dimensions.clone(),
9798
wrapper.clone(),
9899
additional_text.clone(),
100+
include_path,
99101
)))
100102
});
101103
let highlight_config_mutex = local_highlighter_config.get_or(|| {

0 commit comments

Comments
 (0)