Add float placement and page headers/footers
This commit is contained in:
1 parent
1da46c61d6
commit
ed1da06685
16 files changed
+974
-90
No files matched your search
@@ -75,6 +75,8 @@ pub struct DocumentModel {
|
||||
pub labels: HashMap<String, String>,
|
||||
pub citations: HashMap<String, usize>,
|
||||
pub footnotes: Vec<Footnote>,
|
||||
pub page_style: PageStyle,
|
||||
pub page_style_overrides: Vec<PageStyleOverride>,
|
||||
}
|
||||
|
||||
impl Default for DocumentModel {
|
||||
@@ -93,10 +95,81 @@ impl Default for DocumentModel {
|
||||
labels: HashMap::new(),
|
||||
citations: HashMap::new(),
|
||||
footnotes: Vec::new(),
|
||||
page_style: PageStyle::default(),
|
||||
page_style_overrides: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Page style selected by `\pagestyle`.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub enum PageStyleKind {
|
||||
Empty,
|
||||
/// LaTeX's default: a centered page number in the footer.
|
||||
#[default]
|
||||
Plain,
|
||||
/// fancyhdr-style header/footer declared with `\fancyhead`/`\fancyfoot`.
|
||||
Fancy,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub enum PageDecorationPosition {
|
||||
#[default]
|
||||
Center,
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
/// Header or footer runs for one edge of the page.
|
||||
#[derive(Clone, Default, PartialEq, Eq, Hash)]
|
||||
pub struct PageDecoration {
|
||||
pub left: Vec<Run>,
|
||||
pub center: Vec<Run>,
|
||||
pub right: Vec<Run>,
|
||||
}
|
||||
|
||||
impl PageDecoration {
|
||||
pub fn slot_mut(&mut self, position: PageDecorationPosition) -> &mut Vec<Run> {
|
||||
match position {
|
||||
PageDecorationPosition::Left => &mut self.left,
|
||||
PageDecorationPosition::Center => &mut self.center,
|
||||
PageDecorationPosition::Right => &mut self.right,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.left.is_empty() && self.center.is_empty() && self.right.is_empty()
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.left.clear();
|
||||
self.center.clear();
|
||||
self.right.clear();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Eq, Hash)]
|
||||
pub struct PageStyle {
|
||||
pub kind: PageStyleKind,
|
||||
pub header: PageDecoration,
|
||||
pub footer: PageDecoration,
|
||||
}
|
||||
|
||||
/// A `\thispagestyle` override, anchored at the block it was issued before.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct PageStyleOverride {
|
||||
pub anchor: usize,
|
||||
pub kind: PageStyleKind,
|
||||
}
|
||||
|
||||
/// Marker character used by `\thepage` inside header/footer runs; the page
|
||||
/// renderer substitutes the concrete page number before measuring and painting.
|
||||
pub const PAGE_NUMBER_MARKER: char = '\u{F5000}';
|
||||
|
||||
pub fn page_number_marker_text() -> String {
|
||||
PAGE_NUMBER_MARKER.to_string()
|
||||
}
|
||||
|
||||
pub struct ParsedDocument(pub DocumentModel);
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -137,11 +210,15 @@ pub enum Block {
|
||||
caption: Option<Vec<Run>>,
|
||||
alignments: Vec<ColumnAlignment>,
|
||||
rules: Vec<usize>,
|
||||
/// Float placement hints from `[htbp]`.
|
||||
placement: String,
|
||||
},
|
||||
Image {
|
||||
path: String,
|
||||
options: String,
|
||||
caption: Option<Vec<Run>>,
|
||||
/// Float placement hints from `[htbp]`.
|
||||
placement: String,
|
||||
},
|
||||
Bibliography(Vec<(String, Vec<Run>)>),
|
||||
/// A box such as `\fbox{...}` (framed) or `\parbox{width}{...}`.
|
||||
|
||||
Reference in new issue
Block a user