#![doc = include_str!("../README.md")]
#![allow(non_camel_case_types)]
#![allow(clippy::too_many_arguments)]
pub mod block;
mod convert;
pub mod engine;
pub mod input;
pub mod notes;
pub mod paginator;
pub mod style_resolver;
pub mod table;
pub use input::{ImageData, LayoutInput, MediaRegistry, RevisionView};
pub use oxml_layout::{
Color, DocumentMetadata, FontData, FontFile, FontId, GlyphRun, LayoutError, LayoutResult,
PageFrame, Point, PositionedElement, Rect, Result, SourceNodeId, SourceSpan,
};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WordStory {
Document,
Header { relationship_id: String },
Footer { relationship_id: String },
Footnote { id: i32 },
Endnote { id: i32 },
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WordSourcePath {
pub story: WordStory,
pub children: Vec<usize>,
}
#[derive(Debug)]
pub struct WordLayoutResult {
pub layout: LayoutResult,
pub revision_view: RevisionView,
source_nodes: Vec<WordSourcePath>,
}
impl WordLayoutResult {
pub fn source_node(&self, id: SourceNodeId) -> Option<&WordSourcePath> {
self.source_nodes.get(id.get() as usize - 1)
}
pub fn into_layout_result(self) -> LayoutResult {
self.layout
}
}
pub fn layout_document(input: &LayoutInput) -> Result<LayoutResult> {
engine::Engine::new().layout(input)
}
pub fn layout_document_with_provenance(input: &LayoutInput) -> Result<WordLayoutResult> {
let (layout, source_nodes) = engine::Engine::new().layout_with_provenance(input)?;
Ok(WordLayoutResult {
layout,
revision_view: input.revision_view,
source_nodes,
})
}
#[doc(hidden)]
pub fn layout_document_with_reusable_engine(
engine: &mut engine::Engine,
input: &LayoutInput,
) -> Result<WordLayoutResult> {
let (layout, source_nodes) = engine.layout_with_provenance(input)?;
Ok(WordLayoutResult {
layout,
revision_view: input.revision_view,
source_nodes,
})
}
#[doc(hidden)]
pub fn layout_document_with_caller_fonts_and_provenance(
input: &LayoutInput,
) -> Result<WordLayoutResult> {
let (layout, source_nodes) =
engine::Engine::new_with_caller_fonts().layout_with_provenance(input)?;
Ok(WordLayoutResult {
layout,
revision_view: input.revision_view,
source_nodes,
})
}
pub fn layout_document_deterministic(input: &LayoutInput) -> Result<LayoutResult> {
engine::Engine::new_deterministic()?.layout(input)
}
pub fn layout_document_deterministic_with_provenance(
input: &LayoutInput,
) -> Result<WordLayoutResult> {
let (layout, source_nodes) =
engine::Engine::new_deterministic()?.layout_with_provenance(input)?;
Ok(WordLayoutResult {
layout,
revision_view: input.revision_view,
source_nodes,
})
}