예제 #1
0
    def list_callback(self, sender):
        if not sender.getSelection() and len(self.w.display_list) is 0:
            # list is empty, don’t attempt any selection

            print('empty list')
            pass

        else:
            if not sender.getSelection():
                # list is new, select first item in new list
                sel_index = 0
                self.w.display_list.setSelection([sel_index])
            else:
                # normal -- just select the next item
                sel_index = sender.getSelection()[0]

            self.pair = self.pair_list[sel_index]
            new_values = self.cmb_kern_dict.get(self.pair)
            self.values = new_values
            self.w.c.update()
            self.update_display(new_values)
            self.update_textBoxes()

            print(self.pair, new_values)
            for f_index, f in enumerate(self.fonts):
                repr_pair = kerningHelper.get_repr_pair(f, self.pair)
                repr_glyphs = [f[g_name] for g_name in repr_pair]
                kern_value = f.kerning.get(self.pair, 0)
                pair_obj = getattr(self.w.pairPreview,
                                   'pair_{}'.format(f_index))
                pair_obj.setGlyphData_kerning(repr_glyphs, kern_value)
예제 #2
0
    def __init__(self, fonts):
        self.fonts = fonts
        self.w = vanilla.Window((1200, 600), minSize=(100, 100))
        _, _, w_width, w_height = self.w.getPosSize()
        prev_height = w_height / 3
        self.w.allFontsGroup = vanilla.Group((0, 0, -0, prev_height))
        self.steps = len(self.fonts)
        step = w_width / self.steps
        for f_index, f in enumerate(self.fonts):
            x = step * f_index
            control = DrawPair((x, 0, step, -0))

            self.kern_list = list(f.kerning.keys())
            initial_pair = self.kern_list[0]
            kern_value = f.kerning.get(initial_pair, 0)
            repr_pair = get_repr_pair(f, initial_pair)
            repr_glyphs = [f[g_name] for g_name in repr_pair]
            control.setGlyphData_kerning(repr_glyphs, kern_value)

            setattr(self.w.allFontsGroup, 'pair_{}'.format(f_index), control)

        display_list = [', '.join(pair) for pair in self.kern_list]
        list_height = w_height - prev_height

        self.w.myList = vanilla.List(
            (0, -list_height, -0, -0),
            display_list,
            allowsMultipleSelection=False,
            selectionCallback=self.list_callback,
        )

        self.w.bind('resize', self.resize_callback)
        self.w.open()
예제 #3
0
 def list_callback(self, sender):
     pair_index = sender.getSelection()[0]
     pair = self.kern_list[pair_index]
     for f_index, f in enumerate(self.fonts):
         repr_pair = get_repr_pair(f, pair)
         repr_glyphs = [f[g_name] for g_name in repr_pair]
         kern_value = f.kerning.get(pair, 0)
         pair_obj = getattr(self.w.allFontsGroup, 'pair_{}'.format(f_index))
         pair_obj.setGlyphData_kerning(repr_glyphs, kern_value)
예제 #4
0
    def __init__(self, fonts):

        self.fonts = fonts
        if len(self.fonts) in range(4):
            self.min_unit_width = 350
            self.p_point_size = 160
        elif len(self.fonts) in range(4, 7):
            self.min_unit_width = 200
            self.p_point_size = 120
        else:
            self.min_unit_width = 150
            self.p_point_size = 100

        # by default, all checkboxes are unchecked
        self.checked = [0 for i in range(len(self.fonts))]

        self.min_w_width = len(self.fonts) * self.min_unit_width
        # cmb_kern_dict is an ordered dict
        self.cmb_kern_dict = kerningHelper.get_combined_kern_dict(fonts)
        self.pair_list = list(self.cmb_kern_dict.keys())
        self.filtered_pairlists = self.make_filtered_pairlists(
            self.cmb_kern_dict)

        # initial value for the first pair to show
        initial_pair = self.pair_list[0]
        self.pair = initial_pair
        initial_value = self.cmb_kern_dict[initial_pair]
        self.values = initial_value
        self.steps = len(self.values)
        self.update_display(self.values)
        self.drag_index = None

        self.w = vanilla.Window(
            (self.min_w_width, self.min_w_height),
            title='Kern-A-Lytics',
            minSize=(self.min_w_width / 2, self.min_w_height / 2),
        )

        _, _, self.w_width, self.w_height = self.w.getPosSize()
        self.graph_height = self.w_height / 3
        self.graph_width = (self.w_width - 2 * self.padding)
        self.step_dist = self.graph_width / self.steps
        graph_margin = self.step_dist / 2
        self.canvas_delegate = CanvasDelegate(self)
        self.w.c = Canvas(
            (self.padding, self.padding, -self.padding, self.graph_height),
            delegate=self.canvas_delegate,
            canvasSize=(self.graph_width, self.graph_height),
            # backgroundColor=AppKit.NSColor.orangeColor(),
            backgroundColor=AppKit.NSColor.clearColor(),
            drawsBackground=False,
        )

        # buttons
        buttons = [
            # button label, callback name
            ('Delete Pairs', 'delete_button_callback'),
            ('Average Pairs', 'average_button_callback'),
            ('Equalize Pairs', 'transfer_button_callback'),
            ('Interpolate Pair', 'interpolate_button_callback'),
            # ('Transfer Pair', 'transfer_button_callback'),
            ('+10', 'plus_button_callback'),
            ('-10', 'minus_button_callback'),
            ('+10%', 'dummy_button_callback'),
            ('-10%', 'dummy_button_callback'),
        ]

        button_top = -210
        # list starts at 210 and has 10 padding at bottom
        # total whitespace: 200 height - 8 * 20 = 40
        # individual_whitespace = 40 / (len(buttons) - 1)
        button_height = 20
        button_space = len(buttons) * button_height
        button_whitespace = (abs(button_top) - self.padding) - button_space
        button_step_space = button_whitespace / (len(buttons) - 1)
        for i, (b_label, b_callback_name) in enumerate(buttons):
            button = vanilla.Button(
                (self.w_width - self.padding - self.button_width, button_top +
                 i * button_height, self.button_width, button_height),
                b_label,
                callback=getattr(self, b_callback_name))
            setattr(self.w, 'button_{}'.format(i), button)
            # button_top += self.padding / 2
            button_top += button_step_space

        # graph labels with monospaced digits
        nsfont = AppKit.NSFont.monospacedDigitSystemFontOfSize_weight_(14, 0.0)
        for i, number in enumerate(self.label_values):
            tb_x = self.padding + graph_margin + i * self.step_dist
            self.tb_y = self.padding * 2 + self.graph_height
            self.tb_height = 20
            self.tb_width = 100

            tb_control = vanilla.TextBox(
                (tb_x - self.tb_width / 2, self.tb_y, self.tb_width,
                 self.tb_height),
                number,
                alignment='center',
                sizeStyle='small',
                selectable=True,
            )

            tb_control.getNSTextField().setFont_(nsfont)
            setattr(self.w, 'textbox_{}'.format(i), tb_control)

        # pair preview
        pp_origin_x = self.padding
        pp_origin_y = self.padding * 4 + self.graph_height + self.tb_height
        self.w.pairPreview = vanilla.Group(
            (pp_origin_x, pp_origin_y, self.w_width, self.p_point_size))
        for f_index, f in enumerate(self.fonts):
            x = self.step_dist * f_index
            pair_preview = DrawPair((x, 0, self.step_dist, -0))

            initial_pair = self.pair_list[0]
            kern_value = self.cmb_kern_dict.get(initial_pair)[f_index]
            if kern_value is None:
                kern_value = 0

            repr_pair = kerningHelper.get_repr_pair(f, initial_pair)
            # XXXX the following line is problematic
            # if UFOs with different group structures are opened
            repr_glyphs = [f[g_name] for g_name in repr_pair]
            pair_preview.setGlyphData_kerning(repr_glyphs, kern_value)

            setattr(self.w.pairPreview, 'pair_{}'.format(f_index),
                    pair_preview)

        # checkboxes
        for i, f in enumerate(self.fonts):
            cb_x = self.padding + graph_margin + i * self.step_dist
            cb_control = vanilla.CheckBox(
                (cb_x - 6, pp_origin_y + self.p_point_size + self.padding * 2,
                 22, 22),
                '',
                value=False,
                sizeStyle='regular',
                callback=self.checkbox_callback)

            setattr(self.w, 'checkbox_{}'.format(i), cb_control)

        # pop-up button for list filtering
        list_width = self.w_width - self.button_width - self.padding * 3

        self.w.list_filter = vanilla.PopUpButton((10, -240, list_width, 20),
                                                 self.filter_options,
                                                 callback=self.filter_callback)

        # list of kerning pairs (bottom)
        column_pairs = self.make_columns(self.pair_list)
        self.w.display_list = vanilla.List(
            (10, -210, list_width, -10),
            column_pairs,
            columnDescriptions=[{
                'title': 'L'
            }, {
                'title': 'R'
            }],
            allowsMultipleSelection=False,
            selectionCallback=self.list_callback)

        self.w.bind('resize', self.resize_callback)
        self.w.open()