From c0e4fd55e6fa738cfc5dcc851d0fc3ee2d0f2cd2 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 11 Oct 2019 17:53:28 +0200 Subject: =?UTF-8?q?Create=20test=20runner=20which=20renders=20layouts=20to?= =?UTF-8?q?=20images=20=F0=9F=97=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/doc.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/doc.rs') 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(&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), + } + } +} -- cgit v1.2.3