def __init__(self):
        self.w = vanilla.FloatingWindow(
            (360, 350),
            "Insert weight instances",
            minSize=(360, 350),
            maxSize=(360, 500),
            autosaveName="com.mekkablue.InstanceMaker.mainwindow")

        self.w.text_1 = vanilla.TextBox((15 - 1, 12 + 2, 75, 14),
                                        "Insert",
                                        sizeStyle='small')
        self.w.numberOfInstances = vanilla.PopUpButton(
            (15 + 40, 12, 50, 17), [str(x) for x in range(3, 12)],
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.text_2 = vanilla.TextBox((15 + 40 + 55, 12 + 2, 120, 14),
                                        "instances with prefix",
                                        sizeStyle='small')
        self.w.prefix = vanilla.EditText((15 + 40 + 55 + 120, 12 - 1, -15, 19),
                                         "A-",
                                         callback=self.UpdateSample,
                                         sizeStyle='small')

        self.w.text_3 = vanilla.TextBox((15 - 1, 40 + 2, 60, 14),
                                        "from:",
                                        sizeStyle='small')
        self.w.master1 = vanilla.ComboBox((15 + 40, 40 - 1, 50, 19),
                                          self.MasterList(1),
                                          callback=self.UpdateSample,
                                          sizeStyle='small')
        self.w.text_4 = vanilla.TextBox((15 + 40 + 55, 40 + 2, 55, 14),
                                        "through:",
                                        sizeStyle='small')
        self.w.master2 = vanilla.ComboBox((15 + 40 + 55 + 55, 40 - 1, 50, 19),
                                          self.MasterList(-1),
                                          callback=self.UpdateSample,
                                          sizeStyle='small')
        self.w.text_5 = vanilla.TextBox(
            (15 + 40 + 55 + 55 + 55, 40 + 2, 55, 14),
            "at width:",
            sizeStyle='small')
        self.w.width = vanilla.EditText(
            (15 + 40 + 45 + 55 + 55 + 65, 40 - 1, -15, 19),
            "100",
            callback=self.SavePreferences,
            sizeStyle='small')

        self.w.text_6 = vanilla.TextBox((15 - 1, 68 + 2, 60, 14),
                                        "using",
                                        sizeStyle='small')
        self.w.algorithm = vanilla.PopUpButton((15 + 40, 68, 80, 17),
                                               ["Pablo", "Luc(as)", "linear"],
                                               callback=self.UpdateSample,
                                               sizeStyle='small')
        self.w.text_7 = vanilla.TextBox((15 + 40 + 85, 68 + 2, 110, 14),
                                        "distribution:",
                                        sizeStyle='small')
        self.w.help_instances = vanilla.HelpButton((-15 - 21, 68 + 2, -15, 20),
                                                   callback=self.openURL)

        self.w.existingInstances = vanilla.RadioGroup(
            (15 + 30, 100, -10, 60), [
                "Leave existing instances as they are",
                "Deactivate existing instances", "Delete existing instances"
            ],
            callback=self.SavePreferences,
            sizeStyle='small')
        self.w.existingInstances.set(0)

        self.w.maciej = vanilla.CheckBox((15, 170, 160, 19),
                                         "Maciej y distribution from:",
                                         value=False,
                                         callback=self.UpdateSample,
                                         sizeStyle='small')
        self.w.maciej_light = vanilla.ComboBox((15 + 165, 170 - 2, 50, 19),
                                               self.MasterList(1),
                                               callback=self.UpdateSample,
                                               sizeStyle='small')
        self.w.text_maciej_1 = vanilla.TextBox(
            (15 + 165 + 55, 170 + 2, 55, 19), "through:", sizeStyle='small')
        self.w.maciej_bold = vanilla.ComboBox(
            (15 + 165 + 55 + 55, 170 - 2, -15, 19),
            self.MasterList(-1),
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.text_maciej_2 = vanilla.TextBox(
            (15 + 15, 170 + 2 + 20, -40, 40),
            "Provide horizontal stem widths in extreme masters to interpolate contrast rather than stems.",
            sizeStyle='small',
            selectable=True)
        self.w.help_maciej = vanilla.HelpButton(
            (-15 - 21, 170 + 6 + 20, -15, 20), callback=self.openURL)

        self.w.sample = vanilla.Box((15, 170 + 30 + 40, -15, -30 - 15))
        self.w.sample.text = vanilla.TextBox((5, 5, -5, -5),
                                             "",
                                             sizeStyle='small')

        self.w.createButton = vanilla.Button((-80 - 15, -20 - 15, -15, -15),
                                             "Create",
                                             sizeStyle='regular',
                                             callback=self.CreateInstances)
        self.w.setDefaultButton(self.w.createButton)

        if not self.LoadPreferences():
            print "Error: Could not load preferences. Will resort to defaults."

        self.w.open()
        self.UpdateSample(self)
        self.w.makeKey()
Esempio n. 2
0
    def __init__(self):

        # Window 'self.w':
        windowWidth = 360
        windowHeight = 390
        windowWidthResize = 0  # user can resize width by this value
        windowHeightResize = 300  # user can resize height by this value
        self.w = vanilla.FloatingWindow(
            (windowWidth, windowHeight),  # default window size
            "Insert weight instances",  # window title
            minSize=(windowWidth, windowHeight),  # minimum size (for resizing)
            maxSize=(windowWidth + windowWidthResize, windowHeight +
                     windowHeightResize),  # maximum size (for resizing)
            autosaveName=
            "com.mekkablue.InstanceMaker.mainwindow"  # stores last window position and size
        )
        inset, lineheight = 15, 12

        self.w.text_1 = vanilla.TextBox((inset - 1, lineheight + 2, 75, 14),
                                        "Insert",
                                        sizeStyle='small')
        self.w.numberOfInstances = vanilla.PopUpButton(
            (inset + 40, lineheight, 50, 17), [str(x) for x in range(3, 12)],
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.numberOfInstances.getNSPopUpButton().setToolTip_(
            "Choose how many instances you want to add. A full weight spectrum has 9 weights."
        )
        self.w.text_2 = vanilla.TextBox(
            (inset + 40 + 55, lineheight + 2, 120, 14),
            "instances with prefix",
            sizeStyle='small')
        self.w.prefix = vanilla.EditText(
            (inset + 40 + 55 + 120, lineheight - 1, -inset, 19),
            "A-",
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.prefix.getNSTextField().setToolTip_(
            u"Choose text that is added at the beginning of each instance, e.g., ‘Condensed’."
        )
        lineheight += 28

        self.w.text_3 = vanilla.TextBox((inset - 1, lineheight + 2, 60, 14),
                                        "from:",
                                        sizeStyle='small')
        self.w.master1 = vanilla.ComboBox((inset + 35, lineheight - 1, 62, 19),
                                          self.MasterList(1),
                                          callback=self.UpdateSample,
                                          sizeStyle='small')
        self.w.master1.getNSComboBox().setToolTip_(
            "Weight value for the first instance being added, typically the stem width of your lightest weight."
        )
        self.w.text_4 = vanilla.TextBox(
            (inset + 50 + 55 * 1, lineheight + 2, 55, 14),
            "through:",
            sizeStyle='small')
        self.w.master2 = vanilla.ComboBox(
            (inset + 50 + 55 * 2, lineheight - 1, 62, 19),
            self.MasterList(-1),
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.master2.getNSComboBox().setToolTip_(
            "Weight value for the last instance being added, typically the stem width of your boldest weight."
        )
        self.w.text_5 = vanilla.TextBox(
            (inset + 65 + 55 * 3, lineheight + 2, 55, 14),
            "at width:",
            sizeStyle='small')
        self.w.width = vanilla.EditText(
            (inset + 65 + 55 * 4, lineheight - 1, -inset, 19),
            "100",
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.width.getNSTextField().setToolTip_(
            "The Width value for the instances being added. Default is 100. Adapt accordingly if you are adding condensed or extended instances."
        )
        lineheight += 28

        self.w.text_6 = vanilla.TextBox((inset - 1, lineheight + 2, 60, 14),
                                        "using",
                                        sizeStyle='small')
        self.w.algorithm = vanilla.PopUpButton(
            (inset + 35, lineheight, 90, 17),
            ("linear", "Pablo", "Schneider", "Abraham", "Luc(as)"),
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.algorithm.getNSPopUpButton().setToolTip_(
            "The way the Weight values are distributed between the first and last master values you entered above. Linear means equal steps between instances. Luc(as) (after Lucas de Groot) means the same growth percentage between instances. Pablo (after Pablo Impallari) is like Luc(as) at first, then becomes increasingly linear, i.e., flat in the periphery and steep in the middle. Schneider (after Lukas Schneider) is half way between Pablo and Luc(as) algorithms. Abraham (after Abraham Lee) is linear at first, then becomes incresingly like Luc(as), i.e. steep in the periphery, flat in the middle.\nFor a wide spectrum, try Pablo or Schneider. For spectrums that do not grow too bold, try Abraham or Luc(as). The latter tend to have large jumps at the end, which are usually found in the center of the weight spectrum (between Regular and Semibold). Smaller jumps are preferable in the periphery, i.e., for very light and very dark weights."
        )
        self.w.text_7 = vanilla.TextBox(
            (inset + 40 + 85 + 5, lineheight + 2, 110, 14),
            "distribution.",
            sizeStyle='small')
        self.w.help_instances = vanilla.HelpButton(
            (-15 - 21, lineheight + 2, -inset, 20), callback=self.openURL)
        lineheight += 32

        self.w.existingInstances = vanilla.RadioGroup(
            (inset + 20, lineheight, -10, 60),
            ("Leave existing instances as they are",
             "Deactivate existing instances", "Delete existing instances"),
            callback=self.SavePreferences,
            sizeStyle='small')
        self.w.existingInstances.set(0)
        lineheight += 70

        self.w.naturalNames = vanilla.CheckBox(
            (inset, lineheight, inset + 225, 19),
            u"Use ‘natural’ weight names, starting at:",
            value=False,
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.naturalNames.getNSButton().setToolTip_(
            "Prefill with standard names and style linking. If turned off, will use the Weight number as instance name."
        )
        self.w.firstName = vanilla.PopUpButton(
            (inset + 225, lineheight, -inset, 17),
            naturalNames,
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.firstName.getNSPopUpButton().setToolTip_(
            "If you use natural weight names, choose here the name of your lightest weight."
        )
        try:  # workaround for macOS 10.9
            self.w.firstName.enable(
                self.w.naturalNames.getNSButton().isEnabled())
        except:
            pass
        lineheight += 20

        self.w.italicStyle = vanilla.CheckBox(
            (inset + 20, lineheight, -inset, 20),
            u"Italic suffixes and style linking",
            value=False,
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.italicStyle.getNSButton().setToolTip_(
            u"If enabled, will add the word ‘Italic’ to all instances, and also add italic style linking."
        )
        lineheight += 24

        self.w.maciej = vanilla.CheckBox((inset, lineheight - 1, 160, 19),
                                         "Maciej y distribution from:",
                                         value=False,
                                         callback=self.UpdateSample,
                                         sizeStyle='small')
        self.w.maciej.getNSButton().setToolTip_(
            "An algorithm proposed by Maciej Ratajski, which introduces slightly different interpolation for y coordinates. Will add interpolationWeightY parameters to the instances. If these value differ greatly from the weight interpolation values, interpolation of your diagonals may suffer."
        )
        self.w.text_maciej_1 = vanilla.TextBox(
            (inset + 165 + 55, lineheight + 2, 55, 19),
            "through:",
            sizeStyle='small')
        self.w.text_maciej_2 = vanilla.TextBox(
            (inset + 15, lineheight + 2 + 20, -40, 40),
            "Provide horizontal stem widths in extreme masters to interpolate contrast rather than stems.",
            sizeStyle='small',
            selectable=True)
        self.w.maciej_light = vanilla.ComboBox(
            (inset + 160, lineheight - 1, 55, 19),
            self.MasterList(1),
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.maciej_bold = vanilla.ComboBox(
            (inset + 160 + 55 + 55, lineheight - 1, -inset, 19),
            self.MasterList(-1),
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.help_maciej = vanilla.HelpButton(
            (-inset - 21, lineheight + 6 + 20, -inset, 20),
            callback=self.openURL)
        self.w.help_maciej.getNSButton().setToolTip_(
            "Will open a website with a detailed description of the Maciej algorithm. Requires an internet connection."
        )
        lineheight += 60

        self.w.shouldRound = vanilla.CheckBox((inset, lineheight, -inset, 19),
                                              "Round all interpolation values",
                                              value=True,
                                              callback=self.UpdateSample,
                                              sizeStyle='small')
        self.w.shouldRound.getNSButton().setToolTip_(
            "If enabled, will round all calculated weight values to integers. Usually a good idea."
        )
        lineheight += 30

        self.w.sample = vanilla.Box((inset, lineheight, -inset, -30 - inset))
        self.w.sample.text = vanilla.TextBox((5, 5, -5, -5),
                                             "",
                                             sizeStyle='small')

        self.w.createButton = vanilla.Button(
            (-90 - inset, -20 - inset, -inset, -inset),
            "Insert",
            sizeStyle='regular',
            callback=self.CreateInstances)
        self.w.setDefaultButton(self.w.createButton)

        if not self.LoadPreferences():
            print(
                "Error: Could not load preferences. Will resort to defaults.")

        self.w.open()
        self.UpdateSample(self)
        self.w.makeKey()
    def __init__(self):

        # Window 'self.w':
        windowWidth = 360
        windowHeight = 390
        windowWidthResize = 0  # user can resize width by this value
        windowHeightResize = 300  # user can resize height by this value
        self.w = vanilla.FloatingWindow(
            (windowWidth, windowHeight),  # default window size
            "Insert weight instances",  # window title
            minSize=(windowWidth, windowHeight),  # minimum size (for resizing)
            maxSize=(windowWidth + windowWidthResize, windowHeight +
                     windowHeightResize),  # maximum size (for resizing)
            autosaveName=
            "com.mekkablue.InstanceMaker.mainwindow"  # stores last window position and size
        )
        inset, lineheight = 15, 12

        self.w.text_1 = vanilla.TextBox((inset - 1, lineheight + 2, 75, 14),
                                        "Insert",
                                        sizeStyle='small')
        self.w.numberOfInstances = vanilla.PopUpButton(
            (inset + 40, lineheight, 50, 17), [str(x) for x in range(3, 12)],
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.text_2 = vanilla.TextBox(
            (inset + 40 + 55, lineheight + 2, 120, 14),
            "instances with prefix",
            sizeStyle='small')
        self.w.prefix = vanilla.EditText(
            (inset + 40 + 55 + 120, lineheight - 1, -inset, 19),
            "A-",
            callback=self.UpdateSample,
            sizeStyle='small')
        lineheight += 28

        self.w.text_3 = vanilla.TextBox((inset - 1, lineheight + 2, 60, 14),
                                        "from:",
                                        sizeStyle='small')
        self.w.master1 = vanilla.ComboBox((inset + 35, lineheight - 1, 62, 19),
                                          self.MasterList(1),
                                          callback=self.UpdateSample,
                                          sizeStyle='small')
        self.w.text_4 = vanilla.TextBox(
            (inset + 50 + 55 * 1, lineheight + 2, 55, 14),
            "through:",
            sizeStyle='small')
        self.w.master2 = vanilla.ComboBox(
            (inset + 50 + 55 * 2, lineheight - 1, 62, 19),
            self.MasterList(-1),
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.text_5 = vanilla.TextBox(
            (inset + 65 + 55 * 3, lineheight + 2, 55, 14),
            "at width:",
            sizeStyle='small')
        self.w.width = vanilla.EditText(
            (inset + 65 + 55 * 4, lineheight - 1, -inset, 19),
            "100",
            callback=self.UpdateSample,
            sizeStyle='small')
        lineheight += 28

        self.w.text_6 = vanilla.TextBox((inset - 1, lineheight + 2, 60, 14),
                                        "using",
                                        sizeStyle='small')
        self.w.algorithm = vanilla.PopUpButton(
            (inset + 35, lineheight, 90, 17), (
                "linear",
                "Pablo",
                "Schneider",
                "Luc(as)",
            ),
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.text_7 = vanilla.TextBox(
            (inset + 40 + 85 + 5, lineheight + 2, 110, 14),
            "distribution.",
            sizeStyle='small')
        self.w.help_instances = vanilla.HelpButton(
            (-15 - 21, lineheight + 2, -inset, 20), callback=self.openURL)
        lineheight += 32

        self.w.existingInstances = vanilla.RadioGroup(
            (inset + 20, lineheight, -10, 60),
            ("Leave existing instances as they are",
             "Deactivate existing instances", "Delete existing instances"),
            callback=self.SavePreferences,
            sizeStyle='small')
        self.w.existingInstances.set(0)
        lineheight += 70

        self.w.naturalNames = vanilla.CheckBox(
            (inset, lineheight, inset + 225, 19),
            u"Use ‘natural’ weight names, starting at:",
            value=False,
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.firstName = vanilla.PopUpButton(
            (inset + 225, lineheight, -inset, 17),
            naturalNames,
            callback=self.UpdateSample,
            sizeStyle='small')
        try:  # workaround for macOS 10.9
            self.w.firstName.enable(
                self.w.naturalNames.getNSButton().isEnabled())
        except:
            pass
        lineheight += 20

        self.w.italicStyle = vanilla.CheckBox(
            (inset + 20, lineheight, -inset, 20),
            u"Italic suffixes and style linking",
            value=False,
            callback=self.UpdateSample,
            sizeStyle='small')
        lineheight += 24

        self.w.maciej = vanilla.CheckBox((inset, lineheight - 1, 160, 19),
                                         "Maciej y distribution from:",
                                         value=False,
                                         callback=self.UpdateSample,
                                         sizeStyle='small')
        self.w.text_maciej_1 = vanilla.TextBox(
            (inset + 165 + 55, lineheight + 2, 55, 19),
            "through:",
            sizeStyle='small')
        self.w.text_maciej_2 = vanilla.TextBox(
            (inset + 15, lineheight + 2 + 20, -40, 40),
            "Provide horizontal stem widths in extreme masters to interpolate contrast rather than stems.",
            sizeStyle='small',
            selectable=True)
        self.w.maciej_light = vanilla.ComboBox(
            (inset + 160, lineheight - 1, 55, 19),
            self.MasterList(1),
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.maciej_bold = vanilla.ComboBox(
            (inset + 160 + 55 + 55, lineheight - 1, -inset, 19),
            self.MasterList(-1),
            callback=self.UpdateSample,
            sizeStyle='small')
        self.w.help_maciej = vanilla.HelpButton(
            (-inset - 21, lineheight + 6 + 20, -inset, 20),
            callback=self.openURL)
        lineheight += 60

        self.w.shouldRound = vanilla.CheckBox((inset, lineheight, -inset, 19),
                                              "Round all interpolation values",
                                              value=True,
                                              callback=self.UpdateSample,
                                              sizeStyle='small')
        lineheight += 30

        self.w.sample = vanilla.Box((inset, lineheight, -inset, -30 - inset))
        self.w.sample.text = vanilla.TextBox((5, 5, -5, -5),
                                             "",
                                             sizeStyle='small')

        self.w.createButton = vanilla.Button(
            (-80 - inset, -20 - inset, -inset, -inset),
            "Create",
            sizeStyle='regular',
            callback=self.CreateInstances)
        self.w.setDefaultButton(self.w.createButton)

        if not self.LoadPreferences():
            print "Error: Could not load preferences. Will resort to defaults."

        self.w.open()
        self.UpdateSample(self)
        self.w.makeKey()
Esempio n. 4
0
    def __init__(self):
        # Window 'self.w':
        windowWidth = 330
        windowHeight = 375
        windowWidthResize = 100  # user can resize width by this value
        windowHeightResize = 0  # user can resize height by this value
        self.w = vanilla.FloatingWindow(
            (windowWidth, windowHeight),  # default window size
            "Vertical Metrics Manager",  # window title
            minSize=(windowWidth, windowHeight),  # minimum size (for resizing)
            maxSize=(windowWidth + windowWidthResize, windowHeight +
                     windowHeightResize),  # maximum size (for resizing)
            autosaveName=
            "com.mekkablue.VerticalMetricsManager.mainwindow"  # stores last window position and size
        )

        # UI elements:
        linePos, inset, lineHeight = 12, 15, 22

        self.w.descriptionText = vanilla.TextBox(
            (inset, linePos + 2, -inset, 14),
            u"Manage and sync hhea, typo and win values.",
            sizeStyle='small',
            selectable=True)
        linePos += lineHeight

        self.w.titleAscent = vanilla.TextBox((inset + 70, linePos + 4, 70, 14),
                                             u"Ascender",
                                             sizeStyle='small',
                                             selectable=True)
        self.w.titleDescent = vanilla.TextBox(
            (inset + 140, linePos + 4, 70, 14),
            u"Descender",
            sizeStyle='small',
            selectable=True)
        self.w.titleLineGap = vanilla.TextBox(
            (inset + 210, linePos + 4, 70, 14),
            u"Line Gap",
            sizeStyle='small',
            selectable=True)
        linePos += lineHeight

        self.w.titleWin = vanilla.TextBox((inset, linePos + 3, 70, 14),
                                          u"OS/2 usWin",
                                          sizeStyle='small',
                                          selectable=True)
        self.w.winAsc = vanilla.EditText((inset + 70, linePos, 65, 19),
                                         "",
                                         callback=self.SavePreferences,
                                         sizeStyle='small')
        self.w.winAsc.getNSTextField().setToolTip_(
            "OS/2 usWinAscent. Should be the maximum height in your font. Expect clipping or rendering artefacts beyond this point."
        )
        self.w.winDesc = vanilla.EditText((inset + 140, linePos, 65, 19),
                                          "",
                                          callback=self.SavePreferences,
                                          sizeStyle='small')
        self.w.winDesc.getNSTextField().setToolTip_(
            "OS/2 usWinDescent (unsigned integer). Should be the maximum depth in your font, like the lowest descender you have. Expect clipping or rendering artefacts beyond this point."
        )
        self.w.winGap = vanilla.EditText((inset + 210, linePos, 65, 19),
                                         "",
                                         callback=None,
                                         sizeStyle='small',
                                         readOnly=True,
                                         placeholder=u"n/a")
        self.w.winGap.getNSTextField().setToolTip_(
            "OS/2 usWinLineGap does not exist, hence greyed out here.")
        self.w.winUpdate = vanilla.SquareButton((inset + 280, linePos, 20, 19),
                                                u"↺",
                                                sizeStyle='small',
                                                callback=self.update)
        self.w.winUpdate.getNSButton().setToolTip_(
            "Will recalculate the OS/2 usWin values in the fields to the left. Takes the measurement settings below into account, except for the Limit options."
        )
        linePos += lineHeight

        self.w.titleTypo = vanilla.TextBox((inset, linePos + 3, 70, 14),
                                           u"OS/2 sTypo",
                                           sizeStyle='small',
                                           selectable=True)
        self.w.typoAsc = vanilla.EditText((inset + 70, linePos, 65, 19),
                                          "",
                                          callback=self.SavePreferences,
                                          sizeStyle='small')
        self.w.typoAsc.getNSTextField().setToolTip_(
            "OS/2 sTypoAscender (positive value), should be the same as hheaAscender. Should be the maximum height of the glyphs relevant for horizontal text setting in your font, like the highest accented uppercase letter, typically Aring or Ohungarumlaut. Used for first baseline offset in DTP and office apps and together with the line gap value, also in browsers."
        )
        self.w.typoDesc = vanilla.EditText((inset + 140, linePos, 65, 19),
                                           "",
                                           callback=self.SavePreferences,
                                           sizeStyle='small')
        self.w.typoDesc.getNSTextField().setToolTip_(
            "OS/2 sTypoDescender (negative value), should be the same as hheaDescender. Should be the maximum depth of the glyphs relevant for horizontal text setting in your font, like the lowest descender or bottom accent, typically Gcommaccent, Ccedilla, or one of the lowercase descenders (gjpqy). Together with the line gap value, used for line distance calculation in office apps and browsers."
        )
        self.w.typoGap = vanilla.EditText((inset + 210, linePos, 65, 19),
                                          "",
                                          callback=self.SavePreferences,
                                          sizeStyle='small')
        self.w.typoGap.getNSTextField().setToolTip_(
            "OS/2 sTypoLineGap (positive value), should be the same as hheaLineGap. Should be either zero or a value for padding between lines that makes sense visually. Office apps insert this distance between the lines, browsers add half on top and half below each line, also for determining text object boundaries."
        )
        self.w.typoUpdate = vanilla.SquareButton(
            (inset + 280, linePos, 20, 19),
            u"↺",
            sizeStyle='small',
            callback=self.update)
        self.w.typoUpdate.getNSButton().setToolTip_(
            "Will recalculate the OS/2 sTypo values in the fields to the left. Takes the measurement settings below into account."
        )
        linePos += lineHeight

        self.w.titleHhea = vanilla.TextBox((inset, linePos + 3, 70, 14),
                                           u"hhea",
                                           sizeStyle='small',
                                           selectable=True)
        self.w.hheaAsc = vanilla.EditText((inset + 70, linePos, 65, 19),
                                          "",
                                          callback=self.SavePreferences,
                                          sizeStyle='small')
        self.w.hheaAsc.getNSTextField().setToolTip_(
            "hheaAscender (positive value), should be the same as OS/2 sTypoAscender. Should be the maximum height of the glyphs relevant for horizontal text setting in your font, like the highest accented uppercase letter, typically Aring or Ohungarumlaut. Used for first baseline offset in Mac office apps and together with the line gap value, also in Mac browsers."
        )
        self.w.hheaDesc = vanilla.EditText((inset + 140, linePos, 65, 19),
                                           "",
                                           callback=self.SavePreferences,
                                           sizeStyle='small')
        self.w.hheaDesc.getNSTextField().setToolTip_(
            "hheaDescender (negative value), should be the same as OS/2 sTypoDescender. Should be the maximum depth of the glyphs relevant for horizontal text setting in your font, like the lowest descender or bottom accent, typically Gcommaccent, Ccedilla, or one of the lowercase descenders (gjpqy). Together with the line gap value, used for line distance calculation in office apps and browsers."
        )
        self.w.hheaGap = vanilla.EditText((inset + 210, linePos, 65, 19),
                                          "",
                                          callback=self.SavePreferences,
                                          sizeStyle='small')
        self.w.hheaGap.getNSTextField().setToolTip_(
            "hheaLineGap (positive value), should be the same as OS/2 sTypoLineGap. Should be either zero or a value for padding between lines that makes sense visually. Mac office apps insert this distance between the lines, Mac browsers add half on top and half below each line, also for determining text object boundaries."
        )
        self.w.hheaUpdate = vanilla.SquareButton(
            (inset + 280, linePos, 20, 19),
            u"↺",
            sizeStyle='small',
            callback=self.update)
        self.w.hheaUpdate.getNSButton().setToolTip_(
            "Will recalculate the hhea values in the fields to the left. Takes the measurement settings below into account."
        )
        linePos += lineHeight

        self.w.useTypoMetrics = vanilla.CheckBox(
            (inset + 70, linePos, -inset, 20),
            u"Use Typo Metrics (fsSelection bit 7)",
            value=True,
            callback=self.SavePreferences,
            sizeStyle='small')
        self.w.useTypoMetrics.getNSButton().setToolTip_(
            "Should ALWAYS BE ON. Only uncheck if you really know what you are doing. If unchecked, line behaviour will be not consistent between apps and browsers because some apps prefer win values to sTypo values for determining line distances."
        )
        self.w.useTypoMetricsUpdate = vanilla.SquareButton(
            (inset + 280, linePos, 20, 19),
            u"↺",
            sizeStyle='small',
            callback=self.update)
        self.w.useTypoMetricsUpdate.getNSButton().setToolTip_(
            "Will reset the checkbox to the left to ON, because it should ALWAYS be on. Strongly recommended."
        )
        linePos += lineHeight * 1.5

        self.w.descriptionMeasurements = vanilla.TextBox(
            (inset, linePos + 2, -inset, 14),
            u"Taking Measurements (see tooltips for info):",
            sizeStyle='small',
            selectable=True)
        linePos += lineHeight

        self.w.round = vanilla.CheckBox((inset, linePos, 70, 20),
                                        u"Round by:",
                                        value=True,
                                        callback=self.SavePreferences,
                                        sizeStyle='small')
        self.w.round.getNSButton().setToolTip_(
            "Turn on if you want your values rounded. Recommended.")
        self.w.roundValue = vanilla.EditText((inset + 75, linePos, 60, 19),
                                             "10",
                                             callback=self.SavePreferences,
                                             sizeStyle='small')
        self.w.roundValue.getNSTextField().setToolTip_(
            "All value calculations will be rounded up to the next multiple of this value. Recommended: 10."
        )
        linePos += lineHeight

        self.w.includeAllMasters = vanilla.CheckBox(
            (inset, linePos, -inset, 20),
            u"Include all masters (otherwise current master only)",
            value=True,
            callback=self.SavePreferences,
            sizeStyle='small')
        self.w.includeAllMasters.getNSButton().setToolTip_(
            "If checked, all masters will be measured. If unchecked, only the current master will be measured. Since vertical metrics should be the same throughout all masters, it also makes sense to measure on all masters."
        )
        linePos += lineHeight

        self.w.ignoreNonExporting = vanilla.CheckBox(
            (inset, linePos, -inset, 20),
            u"Ignore non-exporting glyphs",
            value=False,
            callback=self.SavePreferences,
            sizeStyle='small')
        self.w.ignoreNonExporting.getNSButton().setToolTip_(
            "If checked, glyphs that do not export will be excluded from measuring. Recommended. (Ignored for calculating the OS/2 usWin values.)"
        )
        linePos += lineHeight

        self.w.preferSelectedGlyphs = vanilla.CheckBox(
            (inset, linePos, -inset, 20),
            u"Limit to selected glyphs",
            value=False,
            callback=self.SavePreferences,
            sizeStyle='small')
        self.w.preferSelectedGlyphs.getNSButton().setToolTip_(
            "If checked, only the current glyphs will be measured. Can be combined with the other Limit options. May make sense if you want your metrics to be e.g. Latin-CE-centric."
        )
        linePos += lineHeight

        self.w.preferScript = vanilla.CheckBox(
            (inset, linePos, inset + 110, 20),
            u"Limit to script:",
            value=False,
            callback=self.SavePreferences,
            sizeStyle='small')
        self.w.preferScript.getNSButton().setToolTip_(
            "If checked, only measures glyphs belonging to the selected writing system. Can be combined with the other Limit options. (Ignored for calculating the OS/2 usWin values.)"
        )
        self.w.preferScriptPopup = vanilla.PopUpButton(
            (inset + 115, linePos + 1, -inset - 25, 17), (u"latin", u"greek"),
            sizeStyle='small',
            callback=self.SavePreferences)
        self.w.preferScriptPopup.getNSPopUpButton().setToolTip_(
            "Choose a writing system ('script') you want the measurements to be limited to. May make sense to ignore other scripts if the font is intended only for e.g. Cyrillic."
        )
        self.w.preferScriptUpdate = vanilla.SquareButton(
            (-inset - 20, linePos + 1, -inset, 18),
            u"↺",
            sizeStyle='small',
            callback=self.update)
        self.w.preferScriptUpdate.getNSButton().setToolTip_(
            "Update the script popup to the left with all scripts (writing systems) found in the current font."
        )
        linePos += lineHeight

        self.w.preferCategory = vanilla.CheckBox(
            (inset, linePos, inset + 110, 20),
            u"Limit to category:",
            value=False,
            callback=self.SavePreferences,
            sizeStyle='small')
        self.w.preferCategory.getNSButton().setToolTip_(
            "If checked, only measures glyphs belonging to the selected glyph category. Can be combined with the other Limit options. (Ignored for calculating the OS/2 usWin values.)"
        )
        self.w.preferCategoryPopup = vanilla.PopUpButton(
            (inset + 115, linePos + 1, -inset - 25, 17),
            (u"Letter", u"Number"),
            sizeStyle='small',
            callback=self.SavePreferences)
        self.w.preferCategoryPopup.getNSPopUpButton().setToolTip_(
            "Choose a glyph category you want the measurements to be limited to. It may make sense to limit only to Letter."
        )
        self.w.preferCategoryUpdate = vanilla.SquareButton(
            (-inset - 20, linePos + 1, -inset, 18),
            u"↺",
            sizeStyle='small',
            callback=self.update)
        self.w.preferCategoryUpdate.getNSButton().setToolTip_(
            "Update the category popup to the left with all glyph categories found in the current font."
        )
        linePos += lineHeight

        # Run Button:
        self.w.helpButton = vanilla.HelpButton(
            (inset - 2, -20 - inset, 21, -inset + 2), callback=self.openURL)
        self.w.helpButton.getNSButton().setToolTip_(
            "Opens the Vertical Metrics tutorial (highly recommended) in your web browser."
        )

        self.w.runButton = vanilla.Button(
            (-120 - inset, -20 - inset, -inset, -inset),
            "Apply to Font",
            sizeStyle='regular',
            callback=self.VerticalMetricsManagerMain)
        self.w.runButton.getNSButton().setToolTip_(
            "Insert the OS/2, hhea and fsSelection values above as custom parameters in the font. The number values will be inserted into each master. Blank values will delete the respective parameters."
        )
        self.w.setDefaultButton(self.w.runButton)

        # Load Settings:
        if not self.LoadPreferences():
            print(
                "Note: 'Vertical Metrics Manager' could not load preferences. Will resort to defaults"
            )

        # Open window and focus on it:
        self.w.open()
        self.w.makeKey()
    def __init__(self):
        # Window 'self.w':
        windowWidth = 470
        windowHeight = 110
        windowWidthResize = 300  # user can resize width by this value
        windowHeightResize = 0  # user can resize height by this value
        self.w = vanilla.FloatingWindow(
            (windowWidth, windowHeight),  # default window size
            "Set in All TTF Autohint Options",  # window title
            minSize=(windowWidth, windowHeight),  # minimum size (for resizing)
            maxSize=(windowWidth + windowWidthResize, windowHeight +
                     windowHeightResize),  # maximum size (for resizing)
            autosaveName=
            "com.mekkablue.SetTTFAutohintOptions.mainwindow"  # stores last window position and size
        )

        # UI elements:
        self.w.helpButton = vanilla.HelpButton((13, 12, 21, 20),
                                               callback=self.openURL)
        self.w.helpButton.getNSButton().setToolTip_(
            "Opens the ttfAutohint documentation for the currently selected option on freetype.org."
        )

        self.w.ttfAutohintOption = vanilla.PopUpButton(
            (38, 13, 175, 17),
            availableOptions,
            callback=self.SavePreferences,
            sizeStyle='small')
        self.w.ttfAutohintOption.getNSPopUpButton().setToolTip_(
            "Available ttfAutohint options. Pick one from the list. Careful: also contains deprecated options. Refer to the documentation (click on the Help Button on the left), know what you are doing."
        )

        self.w.optionValue = vanilla.EditText((220, 12, -67 - 50, 20),
                                              "value",
                                              callback=self.SavePreferences,
                                              sizeStyle='small')
        self.w.optionValue.getNSTextField().setToolTip_(
            "Value for the currently selected option, if any. Some options can only be set or removed, some have a value."
        )

        self.w.explanation = vanilla.TextBox(
            (15 - 1, 40, -5, -5),
            "Adds or sets this option in all TTF Autohint Options parameters in the current font. For fallback-stem-width, use * for entering the respective instance weight value, and idotless for measuring the width of the interpolated dotless i. The Del button removes this TTFA option from all instances.",
            sizeStyle='small')

        # Run Button:
        self.w.runButton = vanilla.Button(
            (-60 - 50, 10, -15 - 50, 22),
            "Set",
            sizeStyle='regular',
            callback=self.SetTTFAutohintOptionsMain)
        self.w.runButton.getNSButton().setToolTip_(
            "Updates all TTF Autohint Options parameters with the current option (and value, if any) to all instances in the font."
        )

        self.w.delButton = vanilla.Button((-60, 10, -15, 22),
                                          "Del",
                                          sizeStyle='regular',
                                          callback=self.RemoveOption)
        self.w.delButton.getNSButton().setToolTip_(
            "Removes the current option from all TTF Autohint Options parameters in all instances in the font."
        )

        self.w.setDefaultButton(self.w.runButton)

        # Load Settings:
        if not self.LoadPreferences():
            print(
                "Note: 'Set TTF Autohint Options' could not load preferences. Will resort to defaults"
            )

        # enable or disable the edit box
        self.editValueField()

        # Open window and focus on it:
        self.w.open()
        self.w.makeKey()
    def __init__(self):
        if Font is None:
            Message("No font selected", "Select a font project!")
            return

        self.font = Font

        self.smallNums = [
            number for number in self.font.glyphs if number.case == 4
        ]

        self.prefs = {}

        if Glyphs.defaults["com.eweracs.CopyKOtoSC.prefs"]:
            for key in Glyphs.defaults["com.eweracs.CopyKOtoSC.prefs"]:
                self.prefs[key] = Glyphs.defaults[
                    "com.eweracs.CopyKOtoSC.prefs"][key]
        else:
            self.prefs = {"allMasters": 1, "UCtoSC": 1, "numToSmallFigures": 0}

        self.allMasters = self.prefs["allMasters"]
        self.UCtoSC = self.prefs["UCtoSC"]
        self.numToSmallFigures = self.prefs["numToSmallFigures"]

        try:
            self.master_cap_kern_values = {
                master: int(self.font.kerning[master.id][
                    self.font.glyphs["H"].id][self.font.glyphs["H"].id])
                for master in self.font.masters
            }
        except Exception as e:
            print(e)
            self.master_cap_kern_values = {
                master: 0
                for master in self.font.masters
            }

        self.w = vanilla.FloatingWindow(
            (0, 0),
            "Copy zero models",
            minSize=(210, len(self.font.masters) * 28 + 247),
            maxSize=(300, len(self.font.masters) * 28 + 247))

        self.ypos = 10

        self.w.UCtoSC = vanilla.CheckBox((10, self.ypos, -10, 18),
                                         "Uppercase to smallcaps",
                                         sizeStyle="small",
                                         value=self.UCtoSC,
                                         callback=self.select_uc_to_sc)

        self.ypos += 22

        self.w.numToSmallFigures = vanilla.CheckBox(
            (10, self.ypos, -10, 18),
            "Numbers to small figures",
            sizeStyle="small",
            value=self.numToSmallFigures,
            callback=self.select_num_to_small_figures)

        self.ypos += 26

        self.w.divider = vanilla.HorizontalLine((10, self.ypos, -10, 1))

        self.ypos += 10

        self.w.capitalKerningTitle = vanilla.TextBox(
            (10, self.ypos, -10, 14),
            "Uppercase base kerning (H H):",
            sizeStyle="small")
        self.w.capitalKerningHelp = vanilla.HelpButton(
            (180, self.ypos - 2, 21, 20))
        self.w.capitalKerningHelp.getNSButton().setToolTip_(
            "The amount of kerning you might have set as the standard capital spacing. "
            "Is read from the model HH, if it exists.")

        self.ypos += 28

        for i, master in enumerate(self.font.masters):
            try:
                master_cap_kern = int(self.font.kerning[master.id][
                    self.font.glyphs["H"].id][self.font.glyphs["H"].id])
            except:
                master_cap_kern = 0
            setattr(
                self.w, "master" + str(i),
                vanilla.TextBox((10, self.ypos, -80, 17),
                                str(i + 1) + ": " + master.name,
                                sizeStyle="regular"))
            setattr(
                self.w, "kern" + str(i),
                vanilla.EditText((-60, self.ypos - 1, -10, 22),
                                 text=str(master_cap_kern),
                                 callback=self.set_master_cap_kern))

            if master.userData["KernOnIsInterpolated"]:
                getattr(self.w, "master" + str(i)).enable(0)
                getattr(self.w, "kern" + str(i)).show(0)
                setattr(
                    self.w, "interpolate" + str(i),
                    vanilla.TextBox((10, self.ypos + 1, -10, 14),
                                    "Interpolated",
                                    alignment="right",
                                    sizeStyle="small"))

            self.master_cap_kern_values[master] = master_cap_kern
            self.ypos += 28

        self.w.dividerTwo = vanilla.HorizontalLine((10, self.ypos + 2, -10, 1))

        self.ypos += 10

        self.w.numberTitle = vanilla.TextBox((10, self.ypos, -10, 14),
                                             "Copy from numbers:",
                                             sizeStyle="small")

        self.ypos += 26

        self.w.defaultNumberSelector = vanilla.PopUpButton(
            (10, self.ypos, -10, 17), ["Default", "Lining", "Oldstyle"])

        self.ypos += 30

        self.w.numberTargetTitle = vanilla.TextBox((10, self.ypos, -10, 14),
                                                   "To small figure base set:",
                                                   sizeStyle="small")

        self.ypos += 26

        self.w.targetNumberSelector = vanilla.PopUpButton(
            (10, self.ypos, -10, 17),
            [".dnom", "inferior", ".numr", "superior"])

        self.ypos += 30

        self.w.dividerThree = vanilla.HorizontalLine((10, self.ypos, -10, 1))

        self.ypos += 10

        self.w.allMasters = vanilla.CheckBox((10, self.ypos, -10, 18),
                                             "Apply to all masters",
                                             sizeStyle="small",
                                             value=self.allMasters)

        self.w.copyModelsButton = vanilla.Button((10, -30, -10, 20),
                                                 "Copy zero models",
                                                 callback=self.copy_models)

        self.ypos += 56

        for i, master in enumerate(self.font.masters):
            getattr(self.w, "kern" + str(i)).enable(self.w.UCtoSC.get())
        self.w.defaultNumberSelector.enable(self.w.numToSmallFigures.get())
        self.w.copyModelsButton.enable(
            self.w.UCtoSC.get() + self.w.numToSmallFigures.get() != 0)

        self.w.setDefaultButton(self.w.copyModelsButton)

        self.w.resize(210, self.ypos)
        self.w.open()
        self.w.makeKey()