Skip to content

Commit

Permalink
Finalize export
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlcctrlv committed May 21, 2021
1 parent 5934ce4 commit ce92cbd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
17 changes: 14 additions & 3 deletions src/editor/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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"));
}
Expand Down
22 changes: 2 additions & 20 deletions src/io.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,22 +42,3 @@ pub fn load_glif<F: AsRef<Path> + 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);
}
21 changes: 20 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -186,6 +202,7 @@ fn main() {
continue;
}
}
// Redo
Event::KeyDown {
keycode: Some(Keycode::Y),
keymod: km,
Expand All @@ -196,6 +213,7 @@ fn main() {
continue;
}
}
// Copy
Event::KeyDown {
keycode: Some(Keycode::C),
keymod: km,
Expand All @@ -206,6 +224,7 @@ fn main() {
continue;
}
}
// Paste
Event::KeyDown {
keycode: Some(Keycode::V),
keymod: km,
Expand Down

0 comments on commit ce92cbd

Please sign in to comment.