daltonmaag / statmake

Generate STAT tables for variable fonts from .stylespace files
MIT License
39 stars 11 forks source link

`yaplon`, because I hate .plist :) #7

Closed twardoch closed 5 years ago

twardoch commented 5 years ago

I’ve written a small commandline tool yaplon that comes with a CLI command yaml22plist, because I truly hate writing .plist (including .stylespace) by hand.

So now I can write my stylespace like this:

{axes: [{name: Weight, tag: wght, locations: [{name: Hairline, value: 100}, {name: Thin,
          value: 200}, {name: Light, value: 300}, {name: Regular, value: 400, linked_value: 700,
          flags: [ElidableAxisValueName]}, {name: Medium, value: 500}, {name: Semibold,
          value: 600}, {name: Bold, value: 700}, {name: Heavy, value: 800}, {name: Black,
          value: 900}]}, {name: Italic, tag: ital, locations: [{name: Upright, value: 0,
          linked_value: 1, flags: [ElidableAxisValueName]}]}]}

or this:

axes:
-   name: Weight
    tag: wght
    locations:
    -   name: Hairline
        value: 100
    -   name: Thin
        value: 200
    -   name: Light
        value: 300
    -   name: Regular
        value: 400
        linked_value: 700
        flags:
        - ElidableAxisValueName
    -   name: Medium
        value: 500
    -   name: Semibold
        value: 600
    -   name: Bold
        value: 700
    -   name: Heavy
        value: 800
    -   name: Black
        value: 900
-   name: Italic
    tag: ital
    locations:
    -   name: Upright
        value: 0
        linked_value: 1
        flags:
        - ElidableAxisValueName

and via yaml2plist -i Lato.stylespace.yaml -o Lato.stylespace, I get

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>axes</key>
        <array>
            <dict>
                <key>name</key>
                <string>Weight</string>
                <key>tag</key>
                <string>wght</string>
                <key>locations</key>
                <array>
                    <dict>
                        <key>name</key>
                        <string>Hairline</string>
                        <key>value</key>
                        <integer>100</integer>
                    </dict>
                    <dict>
                        <key>name</key>
                        <string>Thin</string>
                        <key>value</key>
                        <integer>200</integer>
                    </dict>
                    <dict>
                        <key>name</key>
                        <string>Light</string>
                        <key>value</key>
                        <integer>300</integer>
                    </dict>
                    <dict>
                        <key>name</key>
                        <string>Regular</string>
                        <key>value</key>
                        <integer>400</integer>
                        <key>linked_value</key>
                        <integer>700</integer>
                        <key>flags</key>
                        <array>
                            <string>ElidableAxisValueName</string>
                        </array>
                    </dict>
                    <dict>
                        <key>name</key>
                        <string>Medium</string>
                        <key>value</key>
                        <integer>500</integer>
                    </dict>
                    <dict>
                        <key>name</key>
                        <string>Semibold</string>
                        <key>value</key>
                        <integer>600</integer>
                    </dict>
                    <dict>
                        <key>name</key>
                        <string>Bold</string>
                        <key>value</key>
                        <integer>700</integer>
                    </dict>
                    <dict>
                        <key>name</key>
                        <string>Heavy</string>
                        <key>value</key>
                        <integer>800</integer>
                    </dict>
                    <dict>
                        <key>name</key>
                        <string>Black</string>
                        <key>value</key>
                        <integer>900</integer>
                    </dict>
                </array>
            </dict>
            <dict>
                <key>name</key>
                <string>Italic</string>
                <key>tag</key>
                <string>ital</string>
                <key>locations</key>
                <array>
                    <dict>
                        <key>name</key>
                        <string>Upright</string>
                        <key>value</key>
                        <integer>0</integer>
                        <key>linked_value</key>
                        <integer>1</integer>
                        <key>flags</key>
                        <array>
                            <string>ElidableAxisValueName</string>
                        </array>
                    </dict>
                </array>
            </dict>
        </array>
    </dict>
</plist>
twardoch commented 5 years ago

And Test.stylespace in YAML is:

axes:
-   name: Weight
    tag: wght
    locations:
    -   name: XLight
        value: 200
    -   name: Light
        value: 300
    -   name:
            en: Regular
            de: Regulär
        value: 400
        linked_value: 700
        flags:
        - ElidableAxisValueName
    -   name: Semi Bold
        value: 600
    -   name:
            en: Bold
        value: 700
    -   name: Black
        value: 900
        range:
        - 701
        - 900
-   name: Italic
    tag: ital
    locations:
    -   name: Upright
        value: 0
        linked_value: 1
        flags:
        - ElidableAxisValueName
    -   name: Italic
        value: 1
locations:
-   name: ASDF
    axis_values:
        Weight: 333
        Italic: 1
-   name: fgfg
    axis_values:
        Weight: 650
        Italic: 0.5
    flags:
    - ElidableAxisValueName

(You can of course have comments there.)

madig commented 5 years ago

plist are somewhat ugh, yes. I kept that because UFOs use plists and I didn't want to introduce yet another format. Now I was actually thinking of implementing a try/except thing that loads a .designspace with the yaml, json and plistlib modules until something returns something. The caveat would be that your file has to load in at least one module 😁

twardoch commented 5 years ago

Well, I actually think a good "filter" could work as well. I made my yaplon to work with piping, but even without that, I think font=Lato3UprMM; yaml22plist -i $font.stylespace.yaml -o $font.stylespace && statmake $font.stylespace $font.designspace $font-VF.ttf; works decently.

madig commented 5 years ago

Sure, if your build system is set up to use that. Do you need anything from statmake's side for this?

twardoch commented 5 years ago

No, not really. I kind of agree that it should stay plist (esp. since then it really is compatible with being included in .designspace lib). I thought for human readability, the YAML notation is just easier to follow, so I posted the issue for other people's benefit. This might be some wiki entry.

madig commented 5 years ago

yaplon is mentioned in the Readme now.