Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document lib keys modifying ufo2ft's behavior #286

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

madig
Copy link
Collaborator

@madig madig commented Oct 22, 2018

Tackle #240.

Stub stub.

PS: You can copy-paste it into e.g. https://livesphinx.herokuapp.com/ to get a rendered preview.

@madig madig requested review from anthrotype and removed request for anthrotype October 22, 2018 22:43
@madig madig force-pushed the document-lib-keys branch from 8a7a7e7 to e77743f Compare November 7, 2018 23:29
@madig
Copy link
Collaborator Author

madig commented Nov 7, 2018

Oops, missed conversionError and reverseDirection. I think I was looking for conversionError actually (googlefonts/cu2qu#158). The setup of the filter chain is... convoluted. compileTTF shadows TTFPreProcessor shadows CubicToQuadraticFilter...

@madig
Copy link
Collaborator Author

madig commented Nov 11, 2019

Oops once more, pre and post mean:

    Custom filters can be applied before or after the default filters.
    These are specified in the UFO lib.plist under the private key
    "com.github.googlei18n.ufo2ft.filters".

@arrowtype
Copy link

This is really helpful; thanks for starting it!

I have a question that I’m unsure about, even after looking at your docs and the UFO spec:

How would I add multiple ufo2ft filters?

For example, I’d like to add both the flattenComponents filter to nested components and the decomposeComponents filter to a specific list of glyphs.

This seems to work, mostly (but has a partially unexpected result for the flattenComponents filter, whether or not I use the decomposeComponents filter):

<key>com.github.googlei18n.ufo2ft.filters</key>
<array>
    <dict>
        <key>name</key>
        <string>flattenComponents</string>
        <key>pre</key>
        <integer>1</integer>
    </dict>
    <dict>
        <key>name</key>
        <string>decomposeComponents</string>
        <key>include</key>
        <array>
          <string>quotesingle</string>
          <string>quotedbl</string>
          <string>quoteleft</string>
          <string>quoteright</string>
          <string>quotedblleft</string>
          <string>quotedblright</string>
          <string>quotesinglbase</string>
          <string>quotedblbase</string>
        </array>
    </dict>
</array>

In Python:

    font.lib["com.github.googlei18n.ufo2ft.filters"] = [
            {
            'name': 'flattenComponents', 
            'pre': 1
            },
            {
            'name': 'decomposeComponents', 
            'include': "quotesingle quotedbl quoteleft quoteright quotedblleft quotedblright quotesinglbase quotedblbase".split()
            },
    ]

@madig
Copy link
Collaborator Author

madig commented Nov 25, 2020

Right on the money, except 'include' should be a ["list", "of", "str"]. I don't know how filters interact with each other. I think they are run in order?

@anthrotype
Copy link
Member

I think they are run in order?

yep

@chrissimpkins
Copy link
Member

Does it matter that pre key is defined with:

Stephen's approach

<key>pre</key>
<integer>1</integer>

instead of:

documentation approach

<key>pre</key>
<true />

?

@madig
Copy link
Collaborator Author

madig commented Nov 25, 2020

Don't think so. Both evaluate to True

@arrowtype
Copy link

arrowtype commented Nov 25, 2020

'include' should be a ["list", "of", "str"].

I ended my string with .split() and ran this in a RoboFont script, so it seems to work, though I am surprised by two things:

  1. include gets sorted before the name. Should it?
  2. The order I place things in my Python doesn’t get preserved in the lib.
		<key>com.github.googlei18n.ufo2ft.filters</key>
		<array>
			<dict>
				<key>include</key>
				<array>
					<string>quotesingle</string>
					<string>quotedbl</string>
					<string>quoteleft</string>
					<string>quoteright</string>
					<string>quotedblleft</string>
					<string>quotedblright</string>
					<string>quotesinglbase</string>
					<string>quotedblbase</string>
				</array>
				<key>name</key>
				<string>decomposeComponents</string>
			</dict>
			<dict>
				<key>name</key>
				<string>decomposeTransformedComponents</string>
				<key>pre</key>
				<integer>1</integer>
			</dict>
			<dict>
				<key>name</key>
				<string>flattenComponents</string>
				<key>pre</key>
				<integer>1</integer>
			</dict>
		</array>
My RoboFont script, in case it’s relevant (Click to expand)
from vanilla.dialogs import *

inputFonts = getFile("select UFOs", allowsMultipleSelection=True, fileTypes=["ufo"])

for fontPath in inputFonts:
    font = OpenFont(fontPath, showInterface=False)

    # for other font info attributes, see
    # http://unifiedfontobject.org/versions/ufo3/fontinfo.plist/

    font.info.openTypeOS2VendorID = "ARRW"

    font.info.copyright = "Copyright 2017-2020 Arrow Type"

    # un-nest nested components # https://github.com/googlefonts/fontbakery/issues/296
    font.lib["com.github.googlei18n.ufo2ft.filters"] = [
            {
            'name': 'decomposeComponents', 
            'include': "u b q d p arrowleft arrowup arrowright arrowdown arrowrighttail arrowlefttailfeather arrowlefttriangle \
                        nine Adieresis.titl Odieresis.titl Udieresis.titl Odieresis.RECT_titl Udieresis.RECT_titl \
                        quotesingle quotedbl quoteleft quoteright quotedblleft quotedblright quotesinglbase quotedblbase".split()
            },
            {
            'name': 'decomposeTransformedComponents', 
            'pre': 1
            },
            {
            'name': 'flattenComponents', 
            'pre': 1
            },
    ]

    print("Updated info for:")
    print("family: ", font.info.familyName, "\n ", "style: ", font.info.styleName)

    font.save()
    font.close()

@madig
Copy link
Collaborator Author

madig commented Nov 25, 2020

Plists keys are sorted alphabetically.

@anthrotype
Copy link
Member

Plists keys are sorted alphabetically.

right, but an array (of dicts, or whatever) should keep the order.And the filter order matters

@madig
Copy link
Collaborator Author

madig commented Nov 25, 2020

But looking at the script the filters are in order?

Base automatically changed from master to main March 1, 2021 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants