Exemplo n.º 1
0
    def test_write_class(self):
        class_ = classes.GSClass()
        class_.name = "e"
        class_.code = "e eacute egrave"
        class_.automatic = True
        self.assertWrites(
            class_,
            dedent("""\
            {
            automatic = 1;
            code = "e eacute egrave";
            name = e;
            }
        """))

        # When the code is an empty string, write an empty string
        class_.code = ""
        self.assertWrites(
            class_,
            dedent("""\
            {
            automatic = 1;
            code = "";
            name = e;
            }
        """))
Exemplo n.º 2
0
def to_glyphs_groups(self):
    # Build the GSClasses from the groups of the first UFO.
    groups = []
    for source in self._sources.values():
        for name, glyphs in source.font.groups.items():
            # Filter out all BRACKET glyphs first, as they are created at
            # to_designspace time to inherit glyph kerning to their bracket
            # variants. They need to be removed because Glpyhs.app handles that
            # on its own.
            glyphs = [
                name for name in glyphs if not BRACKET_GLYPH_RE.match(name)
            ]
            if _is_kerning_group(name):
                _to_glyphs_kerning_group(self, name, glyphs)
            else:
                gsclass = classes.GSClass(name, " ".join(glyphs))
                self.font.classes.append(gsclass)
                groups.append(name)
        if self.minimize_ufo_diffs:
            self.font.userData[UFO_GROUPS_NOT_IN_FEATURE_KEY] = groups
        break

    # Check that other UFOs are identical and print a warning if not.
    for index, source in enumerate(self._sources.values()):
        if index == 0:
            reference_ufo = source.font
        else:
            _assert_groups_are_identical(self, reference_ufo, source.font)
Exemplo n.º 3
0
def to_glyphs_groups(self):
    # Build the GSClasses from the groups of the first UFO.
    groups = []
    for source in self._sources.values():
        for name, glyphs in source.font.groups.items():
            if _is_kerning_group(name):
                _to_glyphs_kerning_group(self, name, glyphs)
            else:
                gsclass = classes.GSClass(name, " ".join(glyphs))
                self.font.classes.append(gsclass)
                groups.append(name)
        if self.minimize_ufo_diffs:
            self.font.userData[UFO_GROUPS_NOT_IN_FEATURE_KEY] = groups
        break

    # Check that other UFOs are identical and print a warning if not.
    for index, source in enumerate(self._sources.values()):
        if index == 0:
            reference_ufo = source.font
        else:
            _assert_groups_are_identical(self, reference_ufo, source.font)
Exemplo n.º 4
0
    def test_write_font_attributes(self):
        """Test the writer on all GSFont attributes"""
        font = classes.GSFont()
        # List of properties from https://docu.glyphsapp.com/#gsfont
        # parent: not handled because it's internal and read-only
        # masters
        m1 = classes.GSFontMaster()
        m1.id = "M1"
        font.masters.insert(0, m1)
        m2 = classes.GSFontMaster()
        m2.id = "M2"
        font.masters.insert(1, m2)
        # instances
        i1 = classes.GSInstance()
        i1.name = "MuchBold"
        font.instances.append(i1)
        # glyphs
        g1 = classes.GSGlyph()
        g1.name = 'G1'
        font.glyphs.append(g1)
        # classes
        c1 = classes.GSClass()
        c1.name = "C1"
        font.classes.append(c1)
        # features
        f1 = classes.GSFeature()
        f1.name = "F1"
        font.features.append(f1)
        # featurePrefixes
        fp1 = classes.GSFeaturePrefix()
        fp1 = "FP1"
        font.featurePrefixes.append(fp1)
        # copyright
        font.copyright = "Copyright Bob"
        # designer
        font.designer = "Bob"
        # designerURL
        font.designerURL = "bob.me"
        # manufacturer
        font.manufacturer = "Manu"
        # manufacturerURL
        font.manufacturerURL = "manu.com"
        # versionMajor
        font.versionMajor = 2
        # versionMinor
        font.versionMinor = 104
        # date
        font.date = glyphs_datetime('2017-10-03 07:35:46 +0000')
        # familyName
        font.familyName = "Sans Rien"
        # upm
        font.upm = 2000
        # note
        font.note = "Was bored, made this"
        # kerning
        font.kerning = OrderedDict([
            ('M1', OrderedDict([
                ('@MMK_L_G1', OrderedDict([
                    ('@MMK_R_G1', 0.1)
                ]))
            ]))
        ])
        # userData
        font.userData = {
            'a': 'test',
            'b': [1, {'c': 2}],
            'd': [1, "1"],
        }
        # grid -> gridLength
        font.grid = 35
        # gridSubDivisions
        font.gridSubDivisions = 5
        # keyboardIncrement
        font.keyboardIncrement = 1.2
        # disablesNiceNames
        font.disablesNiceNames = True
        # customParameters
        font.customParameters['ascender'] = 300
        # selection: not written
        # selectedLayers: not written
        # selectedFontMaster: not written
        # masterIndex: not written
        # currentText: not written
        # tabs: not written
        # currentTab: not written
        # filepath: not written
        # tool: not written
        # tools: not handled because it is a read-only list of GUI features
        # .appVersion (extra property that is not in the docs!)
        font.appVersion = "895"
        self.assertWrites(font, dedent("""\
            {
            .appVersion = "895";
            classes = (
            {
            code = "";
            name = C1;
            }
            );
            copyright = "Copyright Bob";
            customParameters = (
            {
            name = note;
            value = "Was bored, made this";
            },
            {
            name = ascender;
            value = 300;
            }
            );
            date = "2017-10-03 07:35:46 +0000";
            designer = Bob;
            designerURL = bob.me;
            disablesNiceNames = 1;
            familyName = "Sans Rien";
            featurePrefixes = (
            FP1
            );
            features = (
            {
            code = "";
            name = F1;
            }
            );
            fontMaster = (
            {
            ascender = 800;
            capHeight = 700;
            id = M1;
            xHeight = 500;
            },
            {
            ascender = 800;
            capHeight = 700;
            id = M2;
            xHeight = 500;
            }
            );
            glyphs = (
            {
            glyphname = G1;
            }
            );
            gridLength = 35;
            gridSubDivision = 5;
            instances = (
            {
            name = MuchBold;
            }
            );
            kerning = {
            M1 = {
            "@MMK_L_G1" = {
            "@MMK_R_G1" = 0.1;
            };
            };
            };
            keyboardIncrement = 1.2;
            manufacturer = Manu;
            manufacturerURL = manu.com;
            unitsPerEm = 2000;
            userData = {
            a = test;
            b = (
            1,
            {
            c = 2;
            }
            );
            d = (
            1,
            "1"
            );
            };
            versionMajor = 2;
            versionMinor = 104;
            }
        """))

        # Don't write the keyboardIncrement if it's 1 (default)
        font.keyboardIncrement = 1
        written = test_helpers.write_to_lines(font)
        self.assertFalse(any("keyboardIncrement" in line for line in written))