summaryrefslogtreecommitdiff
path: root/src/doc.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-10-11 17:53:28 +0200
committerLaurenz <laurmaedje@gmail.com>2019-10-11 17:53:28 +0200
commitc0e4fd55e6fa738cfc5dcc851d0fc3ee2d0f2cd2 (patch)
treee5531e605d0ab9e06dc950b4cd9b7a8caa116d34 /src/doc.rs
parent8f788f9a4f5e970bbe6147987b711470d57aca8d (diff)
Create test runner which renders layouts to images 🗺
Diffstat (limited to 'src/doc.rs')
-rw-r--r--src/doc.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/doc.rs b/src/doc.rs
index d6a6096e..d83ae635 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -1,5 +1,6 @@
//! Representation of typesetted documents.
+use std::io::{self, Write};
use crate::size::{Size, Size2D};
@@ -31,3 +32,15 @@ pub enum LayoutAction {
/// Write text starting at the current position.
WriteText(String),
}
+
+impl LayoutAction {
+ /// Serialize this layout action into a string representation.
+ pub fn serialize<W: Write>(&self, f: &mut W) -> io::Result<()> {
+ use LayoutAction::*;
+ match self {
+ MoveAbsolute(s) => write!(f, "m {:.4} {:.4}", s.x.to_pt(), s.y.to_pt()),
+ SetFont(i, s) => write!(f, "f {} {}", i, s),
+ WriteText(s) => write!(f, "w {}", s),
+ }
+ }
+}