From b57544fb6e6edaf95493dc0d3acd7b899219003d Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 22 May 2024 12:18:19 +0100 Subject: [PATCH] Make tiny_skia_render output location invariant of CWD --- .gitignore | 1 + examples/tiny_skia_render/main.rs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ea8c4bf7..82469bec 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/examples/_output \ No newline at end of file diff --git a/examples/tiny_skia_render/main.rs b/examples/tiny_skia_render/main.rs index 86e8cacb..33d653aa 100644 --- a/examples/tiny_skia_render/main.rs +++ b/examples/tiny_skia_render/main.rs @@ -4,6 +4,8 @@ //! A simple example that lays out some text using Parley, extracts outlines using Skrifa and //! then paints those outlines using Tiny-Skia. +use std::path::PathBuf; + use parley::layout::{Alignment, GlyphRun, Layout}; use parley::style::{FontStack, FontWeight, StyleProperty}; use parley::{FontContext, LayoutContext}; @@ -94,8 +96,18 @@ fn main() { } } - // Write image to PNG file - img.save_png("output.png").unwrap(); + // Write image to PNG file in examples/_output dir + let output_path: PathBuf = { + let path = std::path::PathBuf::from(file!()); + let mut path = std::fs::canonicalize(path).unwrap(); + path.pop(); + path.pop(); + path.push("_output"); + let _ = std::fs::create_dir(path.clone()); + path.push("tiny_skia_render.png"); + path + }; + img.save_png(output_path).unwrap(); } fn to_tiny_skia(color: PenikoColor) -> TinySkiaColor {