linebender / norad

Rust crate for working with Unified Font Object files
Apache License 2.0
43 stars 12 forks source link

Serialization of Designspaces mangles lib #338

Open madig opened 9 months ago

madig commented 9 months ago

I noticed that code like

serde_json::to_value(norad::designspace::DesignSpaceDocument::load(path).unwrap()).unwrap()

returned mangled libs, that look like

{array: {string: "_typoquote"}, dict: {dict: {key: "tH", string: "67"}, key: "F333AEC5-BB61-4D5E-9EDD-6124322D28F2"}, key: "public.skipExportGlyphs"}

when it should instead be https://gitlab.gnome.org/GNOME/cantarell-fonts/-/blob/cd2155cf5696082cc14706e0f93a9ad7a1b4dab1/src/Cantarell.designspace#L74-156. As in, it seems to mirror the verbatim plist structure of separate key and value elements. I don't understand why that happens...

madig commented 9 months ago

Huh. If you serialize the DesignSpaceDocument instance, you get a mess:

  "lib": {
    "dict": {
      "array": {
        "string": "_typoquote"
      },
      "dict": {
        "dict": {
          "key": "HV",
          "string": "176"
        },
        "key": "51C2DFEF-3776-4D13-9284-96485B799B57"
      },
      "key": "public.skipExportGlyphs"
    }
  },

and if you serialize the .lib specifically, you get the proper data:

{
  "GSDimensionPlugin.Dimensions": {
    "0B2E441B-685E-400D-9B9B-E078DEED62EF": {
      "HH": "19",
      "HV": "22"
    },
    "51C2DFEF-3776-4D13-9284-96485B799B57": {
      "HH": "156",
      "HV": "176"
    }
  },
  "public.skipExportGlyphs": [
    "_slash.zero",
    "_slash.zero.osf",
    "_typoquote"
  ]
} 
RickyDaMa commented 9 months ago

and if you serialize the .lib specifically, you get the proper data

That'll be because at that point you're serializing plist::Dictionary with plist's implementation, not norad's serde_xml_plist module, which doesn't rely on plist's implementation for the lib/anything AFAIK