From ce92cbd392ea92b4f725f349d00343b0f1546dcc Mon Sep 17 00:00:00 2001 From: Fredrick Brennan Date: Thu, 20 May 2021 20:48:02 -0400 Subject: [PATCH] Finalize export --- .../glyphs.MFEK/{Q_wtf.glif => art.glif} | 0 src/editor/export.rs | 17 +++++++++++--- src/io.rs | 22 ++----------------- src/main.rs | 21 +++++++++++++++++- 4 files changed, 36 insertions(+), 24 deletions(-) rename examples/ExportTestUfo.ufo/glyphs.MFEK/{Q_wtf.glif => art.glif} (100%) diff --git a/examples/ExportTestUfo.ufo/glyphs.MFEK/Q_wtf.glif b/examples/ExportTestUfo.ufo/glyphs.MFEK/art.glif similarity index 100% rename from examples/ExportTestUfo.ufo/glyphs.MFEK/Q_wtf.glif rename to examples/ExportTestUfo.ufo/glyphs.MFEK/art.glif diff --git a/src/editor/export.rs b/src/editor/export.rs index 809e8e1d..72b2dc97 100644 --- a/src/editor/export.rs +++ b/src/editor/export.rs @@ -5,12 +5,23 @@ use glifparser::glif::{self, mfek::{MFEKGlif, MFEKPointData, Layer}}; use log; use plist::{self, Value as PlistValue}; -use std::{fs, io, path, process}; +use std::{fs, io, path}; use crate::filedialog; -use crate::io as glif_io; impl Editor { + pub fn save_glif(&mut self) { + self.with_glyph(|glyph| { + let filename: std::path::PathBuf = glyph.filename.clone().unwrap(); + + let glif_string = { + glifparser::write(&glyph.clone().into()) + }; + + fs::write(filename, glif_string.unwrap()).expect("Unable to write file"); + }); + } + pub fn flatten_glif(&mut self) { self.mark_preview_dirty(); self.rebuild(); @@ -21,7 +32,7 @@ impl Editor { } let glif_struct = self.glyph.as_ref().unwrap().to_exported(&layer); - let target = filedialog::save_filename(Some("glif"), None).map(|f| { + filedialog::save_filename(Some("glif"), None).map(|f| { glif::write_to_filename(&glif_struct, &f).map(|()|log::info!("Requested flatten to {:?}", &f)).unwrap_or_else(|e|panic!("Failed to write glif: {:?}", e)); }).unwrap_or_else(||log::warn!("Requested flatten cancelled due to failed dialog")); } diff --git a/src/io.rs b/src/io.rs index 880e7e3b..2e9822ee 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,8 +1,9 @@ +use crate::filedialog; use crate::ipc; use crate::editor::Editor; use mfek_ipc; -use glifparser::{Glif, MFEKGlif, glif::MFEKPointData}; +use glifparser::{MFEKGlif, glif::MFEKPointData}; use log::debug; use std::{env, fs}; use std::path::Path; @@ -41,22 +42,3 @@ pub fn load_glif + Clone>(v: &mut Editor, filename: F) { }); */ } - -pub fn save_glif(v: &mut Editor) { - v.with_glyph(|glyph| { - let filename: std::path::PathBuf = glyph.filename.clone().unwrap(); - - let glif_string = { - glifparser::write(&glyph.clone().into()) - }; - - fs::write(filename, glif_string.unwrap()).expect("Unable to write file"); - }); -} - -use crate::filedialog; - -pub fn export_glif(v: &Editor) { - let cur_file = v.with_glyph(|glyph| { glyph.filename.clone() }); - let filename = filedialog::save_filename(Some("glif"), None); -} diff --git a/src/main.rs b/src/main.rs index 03e16b2e..12ed9c1c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,6 +147,7 @@ fn main() { // we're gonna handle some of these events before handling commands so that we don't have the logic for this stuff // intertwined in command handling match &event { + // Quit Event::KeyDown { keycode: Some(Keycode::Q), keymod: km, @@ -156,16 +157,19 @@ fn main() { break 'main_loop; } } + // Save Event::KeyDown { keycode: Some(Keycode::S), keymod: km, .. } => { if km.contains(Mod::LCTRLMOD) || km.contains(Mod::RCTRLMOD) { - io::save_glif(&mut editor); + editor.save_glif(); + log::info!("Saved current glyph in-place"); continue; } } + // Flatten Event::KeyDown { keycode: Some(Keycode::U), // Unlink Reference in FontForge, by default, is U. keymod: km, @@ -176,6 +180,18 @@ fn main() { continue; } } + // Export + Event::KeyDown { + keycode: Some(Keycode::E), + keymod: km, + .. + } => { + if km.contains(Mod::LCTRLMOD) || km.contains(Mod::RCTRLMOD) { + editor.export_glif(); + continue; + } + } + // Undo Event::KeyDown { keycode: Some(Keycode::Z), keymod: km, @@ -186,6 +202,7 @@ fn main() { continue; } } + // Redo Event::KeyDown { keycode: Some(Keycode::Y), keymod: km, @@ -196,6 +213,7 @@ fn main() { continue; } } + // Copy Event::KeyDown { keycode: Some(Keycode::C), keymod: km, @@ -206,6 +224,7 @@ fn main() { continue; } } + // Paste Event::KeyDown { keycode: Some(Keycode::V), keymod: km,