Skip to main content

diffenator3_lib/
structs.rs

1use serde::Serialize;
2
3/// Represents a difference between two renderings, whether words or glyphs
4#[derive(Debug, Serialize)]
5#[cfg_attr(feature = "typescript", derive(typescript_type_def::TypeDef))]
6pub struct Difference {
7    /// The text string which was rendered
8    pub word: String,
9    /// A string representation of the shaped buffer in the first font
10    pub buffer_a: String,
11    /// A string representation of the shaped buffer in the second font, if different
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub buffer_b: Option<String>,
14    /// The number of differing pixels
15    pub differing_pixels: usize,
16    /// The OpenType features applied to the text
17    #[serde(skip_serializing_if = "String::is_empty")]
18    pub ot_features: String,
19    /// The OpenType language tag applied to the text
20    #[serde(skip_serializing_if = "String::is_empty")]
21    pub lang: String,
22}
23
24#[derive(Serialize)]
25#[cfg_attr(feature = "typescript", derive(typescript_type_def::TypeDef))]
26pub struct EncodedGlyph {
27    /// The character, as a string
28    pub string: String,
29    /// Name of the character from the Unicode database, if available
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub name: Option<String>,
32}
33/// Represents changes to the cmap table - added or removed glyphs
34#[derive(Serialize)]
35#[cfg_attr(feature = "typescript", derive(typescript_type_def::TypeDef))]
36pub struct CmapDiff {
37    #[serde(skip_serializing_if = "Vec::is_empty")]
38    pub missing: Vec<EncodedGlyph>,
39    #[serde(skip_serializing_if = "Vec::is_empty")]
40    pub new: Vec<EncodedGlyph>,
41}
42
43/// Represents a difference between two encoded glyphs
44#[derive(Debug, Serialize)]
45#[cfg_attr(feature = "typescript", derive(typescript_type_def::TypeDef))]
46pub struct GlyphDiff {
47    /// The string representation of the glyph
48    pub string: String,
49    /// The Unicode name of the glyph
50    pub name: String,
51    /// The Unicode codepoint of the glyph
52    pub unicode: String,
53    /// The number of differing pixels
54    pub differing_pixels: usize,
55}
56
57#[cfg(feature = "typescript")]
58pub type Api = (Difference, GlyphDiff, CmapDiff);