-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After much frustration with
glif::write
bugs, I rewrote it.
This time I focused on code hygeine etc. I'm much more confident in this version of glifparser's writer. New traits: `IntoXML`, `FromXML`.
- Loading branch information
1 parent
7c5fe52
commit 46a7540
Showing
30 changed files
with
492 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use crate::glif::IntoXML; | ||
use crate::xml::Element; | ||
|
||
use super::{Anchor, PointData}; | ||
|
||
impl<PD: PointData> IntoXML for Anchor<PD> { | ||
fn xml(&self) -> Element { | ||
let mut anchor_node = xmltree::Element::new("anchor"); | ||
anchor_node.attributes.insert("x".to_owned(), self.x.to_string()); | ||
anchor_node.attributes.insert("y".to_owned(), self.y.to_string()); | ||
anchor_node.attributes.insert("name".to_owned(), self.class.to_string()); | ||
anchor_node | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod xml; | ||
|
||
use crate::error::GlifParserError; | ||
use crate::glif::{self, Glif}; | ||
#[cfg(feature = "mfek")] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::matrix; | ||
use crate::xml::{Element, IntoXML}; | ||
|
||
use super::GlifComponent; | ||
|
||
impl IntoXML for GlifComponent { | ||
fn xml(&self) -> Element { | ||
let mut component_node = Element::new("component"); | ||
component_node | ||
.attributes | ||
.insert("base".to_string(), self.base.clone()); | ||
matrix::write!(component_node, self); | ||
component_node | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::xml; | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum Lib { | ||
None, | ||
Plist(plist::Dictionary), | ||
/// This variant is highly undesirable to see as output and means that the user's glif file has | ||
/// validity issues. However, to prevent data loss, we attempt to store the broken plist as | ||
/// XML, as XML is the parent of plist. | ||
Xml(xml::Element), | ||
} | ||
|
||
impl Default for Lib { | ||
fn default() -> Self { | ||
Self::None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use crate::error::GlifParserResult; | ||
|
||
pub trait FromXML: super::super::write::IntoXML + Sized { | ||
fn from_xml(xml: &[u8]) -> GlifParserResult<Self>; | ||
fn from_xml_string(xml: &String) -> GlifParserResult<Self> { | ||
Self::from_xml(xml.as_bytes()) | ||
} | ||
} |
Oops, something went wrong.