Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/src/emit/mod.rs

1.6 KiB, 27 runs

created by r1870400018:35661, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! Page writers.
2//!
3//! A writer turns a placed frame into an output artefact. The architecture keeps the frame neutral
4//! -- owing nothing to any one format -- so a second writer is a new arm here, not a change to the
5//! engine. Phase 0 has one, SVG. PDF and Pearl are later arms over the same frames.
6
7pub mod svg;
8pub mod pdf;
9pub mod pearl;
10
11use crate::page::Page;
12
13use oxedyne_fe2o3_core::prelude::*;
14
15/// A choice of page writer. An enum rather than a trait object, per the house preference for
16/// concrete types; a new format is a new variant.
17#[derive(Clone, Copy, Debug)]
18pub enum Emitter {
19 Svg,
20 Pdf,
21 Pearl, // content-addressed blocks with the ledger shipping inside the file
22}
23
24impl Emitter {
25 /// Renders one page to a string. SVG only: a PDF is one binary file across every page, and Pearl is
26 /// one content-addressed document across every page, so each is written whole with its own writer
27 /// ([`pdf::render_document`], [`pearl::PearlBuilder`]) rather than a string per page.
28 pub fn render(&self, page: &Page) -> Outcome<String> {
29 match self {
30 Emitter::Svg => svg::render_page(page),
31 Emitter::Pdf => Err(err!(
32 "PDF is a whole-document format; call emit::pdf::render_document, not \
33 Emitter::render."; Invalid, Input)),
34 Emitter::Pearl => Err(err!(
35 "Pearl is a whole-document format; build it with emit::pearl::PearlBuilder, not \
36 Emitter::render."; Invalid, Input)),
37 }
38 }
39
40 /// The file extension a page written by this emitter should carry.
41 pub fn extension(&self) -> &'static str {
42 match self {
43 Emitter::Svg => "svg",
44 Emitter::Pdf => "pdf",
45 Emitter::Pearl => "prl",
46 }
47 }
48}