Example #1
0
 def test_normalizes_curved_quotes_in_names(self):
     self.master.customParameters = [
         GSCustomParameter(name="‘bad’", value=1),
         GSCustomParameter(name="“also bad”", value=2),
     ]
     self.set_custom_params()
     self.assertIn(MASTER_CUSTOM_PARAM_PREFIX + "'bad'", self.ufo.lib)
     self.assertIn(MASTER_CUSTOM_PARAM_PREFIX + '"also bad"', self.ufo.lib)
Example #2
0
 def test_normalizes_curved_quotes_in_names(self):
     master = GSFontMaster()
     master.customParameters = [
         GSCustomParameter(name='‘bad’', value=1),
         GSCustomParameter(name='“also bad”', value=2)
     ]
     set_custom_params(self.ufo, data=master)
     self.assertIn(GLYPHS_PREFIX + "'bad'", self.ufo.lib)
     self.assertIn(GLYPHS_PREFIX + '"also bad"', self.ufo.lib)
Example #3
0
    def test_set_fsSelection_flags(self):
        self.assertEqual(self.ufo.info.openTypeOS2Selection, None)

        self.master.customParameters["Has WWS Names"] = False
        self.set_custom_params()
        self.assertEqual(self.ufo.info.openTypeOS2Selection, None)

        self.master.customParameters["Use Typo Metrics"] = True
        self.set_custom_params()
        self.assertEqual(self.ufo.info.openTypeOS2Selection, [7])

        self.ufo = Font()
        self.master.customParameters = [
            GSCustomParameter(name="Use Typo Metrics", value=True),
            GSCustomParameter(name="Has WWS Names", value=True),
        ]
        self.set_custom_params()
        self.assertEqual(self.ufo.info.openTypeOS2Selection, [7, 8])
Example #4
0
    def __init__(self, descriptor):
        self._descriptor = descriptor

        # Having a simple list is enough because `to_ufo_custom_params` does
        # not use the fake dictionary interface.
        self.customParameters = []
        if CUSTOM_PARAMETERS_KEY in descriptor.lib:
            for name, value in descriptor.lib[CUSTOM_PARAMETERS_KEY]:
                self.customParameters.append(GSCustomParameter(name, value))
Example #5
0
    def test_parse_glyphs_filter(self, mock_parse_glyphs_filter):
        pre_filter = 'AddExtremes'
        filter1 = 'Transformations;OffsetX:40;OffsetY:60;include:uni0334,uni0335'
        filter2 = 'Transformations;OffsetX:10;OffsetY:-10;exclude:uni0334,uni0335'
        self.master.customParameters.extend([
            GSCustomParameter(name='PreFilter', value=pre_filter),
            GSCustomParameter(name='Filter', value=filter1),
            GSCustomParameter(name='Filter', value=filter2),
        ])
        self.set_custom_params()

        self.assertEqual(mock_parse_glyphs_filter.call_count, 3)
        self.assertEqual(mock_parse_glyphs_filter.call_args_list[0],
                         mock.call(pre_filter, is_pre=True))
        self.assertEqual(mock_parse_glyphs_filter.call_args_list[1],
                         mock.call(filter1, is_pre=False))
        self.assertEqual(mock_parse_glyphs_filter.call_args_list[2],
                         mock.call(filter2, is_pre=False))
Example #6
0
def to_glyphs_instances(self):
    if self.designspace is None:
        return

    for ufo_instance in self.designspace.instances:
        instance = self.glyphs_module.GSInstance()

        try:
            instance.active = ufo_instance.lib[EXPORT_KEY]
        except KeyError:
            # If not specified, the default is to export all instances
            instance.active = True

        instance.name = ufo_instance.styleName

        for axis_def in get_axis_definitions(self.font):
            design_loc = None
            try:
                design_loc = ufo_instance.location[axis_def.name]
                axis_def.set_design_loc(instance, design_loc)
            except KeyError:
                # The location does not have this axis?
                pass

            if axis_def.tag in ('wght', 'wdth'):
                # Retrieve the user location (weightClass/widthClass)
                # Generic way: read the axis mapping backwards.
                user_loc = design_loc
                mapping = None
                for axis in self.designspace.axes:
                    if axis.tag == axis_def.tag:
                        mapping = axis.map
                if mapping:
                    reverse_mapping = [(dl, ul) for ul, dl in mapping]
                    user_loc = interp(reverse_mapping, design_loc)
                if user_loc is not None:
                    axis_def.set_user_loc(instance, user_loc)

        try:
            # Restore the original weight name when there is an ambiguity based
            # on the value, e.g. Thin, ExtraLight, UltraLight all map to 250.
            # No problem with width, because 1:1 mapping in WIDTH_CODES.
            weight = ufo_instance.lib[WEIGHT_KEY]
            # Only use the lib value if:
            # 1. we don't have a weight for the instance already
            # 2. the value from lib is not "stale", i.e. it still maps to
            #    the current userLocation of the instance. This is in case the
            #    user changes the instance location of the instance by hand but
            #    does not update the weight value in lib.
            if (not instance.weight
                    or WEIGHT_CODES[instance.weight] == WEIGHT_CODES[weight]):
                instance.weight = weight
        except KeyError:
            # FIXME: what now
            pass

        try:
            if not instance.width:
                instance.width = ufo_instance.lib[WIDTH_KEY]
        except KeyError:
            # FIXME: what now
            pass

        if ufo_instance.familyName is not None:
            if ufo_instance.familyName != self.font.familyName:
                instance.familyName = ufo_instance.familyName

        smfn = ufo_instance.styleMapFamilyName
        if smfn is not None:
            if smfn.startswith(ufo_instance.familyName):
                smfn = smfn[len(ufo_instance.familyName):].strip()
            instance.linkStyle = smfn

        if ufo_instance.styleMapStyleName is not None:
            style = ufo_instance.styleMapStyleName
            instance.isBold = ('bold' in style)
            instance.isItalic = ('italic' in style)

        if ufo_instance.postScriptFontName is not None:
            instance.fontName = ufo_instance.postScriptFontName

        try:
            instance.manualInterpolation = ufo_instance.lib[
                MANUAL_INTERPOLATION_KEY]
        except KeyError:
            pass

        try:
            instance.instanceInterpolations = ufo_instance.lib[
                INSTANCE_INTERPOLATIONS_KEY]
        except KeyError:
            # TODO: (jany) compute instanceInterpolations from the location
            # if instance.manualInterpolation: warn about data loss
            pass

        if CUSTOM_PARAMETERS_KEY in ufo_instance.lib:
            for name, value in ufo_instance.lib[CUSTOM_PARAMETERS_KEY]:
                instance.customParameters.append(GSCustomParameter(
                    name, value))

        if self.minimize_ufo_diffs:
            instance.customParameters[
                FULL_FILENAME_KEY] = ufo_instance.filename

        # FIXME: (jany) cannot `.append()` because no proxy => no parent
        self.font.instances = self.font.instances + [instance]
Example #7
0
    def test_replace_prefix(self):
        self.ufo.features.text = dedent(
            """\
            # Prefix: AAA
            include(../aaa.fea);

            # Prefix: FOO
            # foo

            # Prefix: ZZZ
            include(../zzz.fea);

            # Prefix: BAR
            # bar

            feature liga {
            sub f i by f_i;
            } liga;

            table GDEF {
            GlyphClassDef
                [f i], # Base
                [f_i], # Liga
                , # Mark
                ;
            } GDEF;
            """
        )

        self.master.customParameters.append(
            GSCustomParameter("Replace Prefix", "FOO; include(../foo.fea);")
        )
        self.master.customParameters.append(
            GSCustomParameter("Replace Prefix", "BAR; include(../bar.fea);")
        )
        self.set_custom_params()

        self.assertEqual(
            self.ufo.features.text,
            dedent(
                """\
                # Prefix: AAA
                include(../aaa.fea);

                # Prefix: FOO
                include(../foo.fea);

                # Prefix: ZZZ
                include(../zzz.fea);

                # Prefix: BAR
                include(../bar.fea);

                table GDEF {
                GlyphClassDef
                    [f i], # Base
                    [f_i], # Liga
                    , # Mark
                    ;
                } GDEF;

                feature liga {
                sub f i by f_i;
                } liga;
                """
            ),
        )