Ejemplo n.º 1
0
    def set_width(self, glyph, width, mode=None):

        # store old values
        old_left = glyph.leftMargin
        old_right = glyph.rightMargin
        old_width = glyph.width
        glyph_width = old_width - (old_left + old_right)

        # save undo state
        glyph.prepareUndo('set glyph width')

        # add value
        if self._mode == 1:
            new_width = old_width + width

        # subtract value
        elif self._mode == 2:
            new_width = old_width - width

        # equal to value
        else:
            new_width = width

        # center glyph
        if mode == 'center':
            glyph.width = new_width
            center_glyph(glyph)

        # split difference
        elif mode == 'split difference':
            # calculate new left margin
            try:
                diff = new_width - old_width
                new_left = old_left + (diff / 2)
            except:
                new_left = 0
            # set margins
            glyph.leftMargin = new_left
            glyph.width = new_width

        # split relative
        elif mode == 'split relative':
            # calculate new left margin
            try:
                whitespace = new_width - glyph_width
                new_left = whitespace / (1 + (old_right / old_left))
            except:
                new_left = 0
            # set margins
            glyph.leftMargin = new_left
            glyph.width = new_width

        # set width
        else:
            glyph.width = new_width

        # done!
        glyph.update()
        glyph.performUndo()
Ejemplo n.º 2
0
    def set_width(self, glyph, width, mode=None):

        # store old values
        old_left = glyph.leftMargin
        old_right = glyph.rightMargin
        old_width = glyph.width
        glyph_width = old_width - (old_left + old_right)

        # save undo state
        glyph.prepareUndo('set glyph width')

        # add value
        if self._mode == 1:
            new_width = old_width + width

        # subtract value
        elif self._mode == 2:
            new_width = old_width - width

        # equal to value
        else:
            new_width = width

        # center glyph
        if mode == 'center':
            glyph.width = new_width
            center_glyph(glyph)

        # split difference
        elif mode == 'split difference':
            # calculate new left margin
            try:
                diff = new_width - old_width
                new_left = old_left + (diff / 2)
            except:
                new_left = 0
            # set margins
            glyph.leftMargin = new_left
            glyph.width = new_width

        # split relative
        elif mode == 'split relative':
            # calculate new left margin
            try:
                whitespace = new_width - glyph_width
                new_left = whitespace / ( 1 + (old_right / old_left) )
            except:
                new_left = 0
            # set margins
            glyph.leftMargin = new_left
            glyph.width = new_width

        # set width
        else:
            glyph.width = new_width

        # done!
        glyph.update()
        glyph.performUndo()
Ejemplo n.º 3
0
 def apply_callback(self, sender):
     # no font open
     if len(self.all_fonts) == 0:
         print(no_font_open)
     # only one font open
     elif len(self.all_fonts) == 1:
         print(no_other_fonts)
     # two or more fonts open
     else:
         boolstring = [False, True]
         # source font
         _source_font_index = self.w._source_value.get()
         _source_font = self.all_fonts[_source_font_index]
         _source_font_name = self.all_fonts_names[_source_font_index]
         # dest font
         _dest_font_index = self.w._dest_value.get()
         _dest_font = self.all_fonts[_dest_font_index]
         _dest_font_name = self.all_fonts_names[_dest_font_index]
         # center
         _center = self.w.center_checkbox.get()
         # print info
         print('copying widths...\n')
         print('\tsource font: %s' % _source_font_name)
         print('\ttarget font: %s' % _dest_font_name)
         print('\tcenter: %s' % boolstring[_center])
         print()
         print('\t', end=' ')
         # batch copy side-bearings
         for glyph_name in get_glyphs(_source_font):
             if glyph_name in _dest_font:
                 # set undo
                 _dest_font[glyph_name].prepareUndo('copy width')
                 # copy
                 print(glyph_name, end=' ')
                 _dest_font[glyph_name].width = _source_font[
                     glyph_name].width
                 # center
                 if _center:
                     center_glyph(_dest_font[glyph_name])
                 # call undo
                 _dest_font[glyph_name].performUndo()
                 _dest_font[glyph_name].update()
         _dest_font.update()
         print()
         print('\n...done.\n')
Ejemplo n.º 4
0
 def apply_callback(self, sender):
     # no font open
     if len(self.all_fonts) == 0:
         print no_font_open
     # only one font open
     elif len(self.all_fonts) == 1:
         print no_other_fonts
     # two or more fonts open
     else:
         boolstring = [False, True]
         # source font
         _source_font_index = self.w._source_value.get()
         _source_font = self.all_fonts[_source_font_index]
         _source_font_name = self.all_fonts_names[_source_font_index]
         # dest font
         _dest_font_index = self.w._dest_value.get()
         _dest_font = self.all_fonts[_dest_font_index]
         _dest_font_name = self.all_fonts_names[_dest_font_index]
         # center
         _center = self.w.center_checkbox.get()
         # print info
         print 'copying widths...\n'
         print '\tsource font: %s' % _source_font_name
         print '\ttarget font: %s' % _dest_font_name
         print '\tcenter: %s' % boolstring[_center]
         print
         print '\t',
         # batch copy side-bearings
         for glyph_name in get_glyphs(_source_font):
             if _dest_font.has_key(glyph_name):
                  # set undo
                 _dest_font[glyph_name].prepareUndo('copy width')
                 # copy
                 print glyph_name,
                 _dest_font[glyph_name].width = _source_font[glyph_name].width
                 # center
                 if _center:
                     center_glyph(_dest_font[glyph_name])
                 # call undo
                 _dest_font[glyph_name].performUndo()
                 _dest_font[glyph_name].update()
         _dest_font.update()
         print
         print '\n...done.\n'
Ejemplo n.º 5
0
 def apply_callback(self, sender):
     boolstring = [False, True]
     # source font
     _source_font_index = self.w._source_value.get()
     _source_font = self._all_fonts[_source_font_index]
     _source_font_name = self._all_fonts_names[_source_font_index]
     # dest font
     _dest_font_index = self.w._dest_value.get()
     _dest_font = self._all_fonts[_dest_font_index]
     _dest_font_name = self._all_fonts_names[_dest_font_index]
     # center
     _center = self.w.center_checkbox.get()
     # print info
     print "copying widths...\n"
     print "\tsource font: %s" % _source_font_name
     print "\ttarget font: %s" % _dest_font_name
     print "\tcenter: %s" % boolstring[_center]
     print
     print "\t",
     # batch copy side-bearings
     for glyph_name in get_glyphs(_source_font):
         if _dest_font.has_key(glyph_name):
             # set undo
             _dest_font[glyph_name].prepareUndo("copy width")
             # copy
             print glyph_name,
             _dest_font[glyph_name].width = _source_font[glyph_name].width
             # center
             if _center:
                 center_glyph(_dest_font[glyph_name])
             # call undo
             _dest_font[glyph_name].performUndo()
             _dest_font[glyph_name].update()
     _dest_font.update()
     print
     print "\n...done.\n"
Ejemplo n.º 6
0
 def set_width(self, glyph, width, mode=None):
     #------------------
     # store old values
     #------------------
     _old_left = glyph.leftMargin
     _old_right = glyph.rightMargin
     _old_width = glyph.width
     _glyph_width = _old_width - (_old_left + _old_right)
     #---------------
     # compute width
     #---------------
     glyph.prepareUndo('set glyph width')
     # add value
     if self._mode == 1:
         _width = _old_width + width
     # subtract value
     elif self._mode == 2:
         _width = _old_width - width
     # equal to value
     else:
         _width = width
     #-------------
     # set margins
     #-------------
     # center glyph
     if mode == 'center':
         glyph.width = _width
         center_glyph(glyph)
     #------------------
     # split difference
     elif mode == 'split difference':
         # calculate new left margin
         try:
             _diff = _width - _old_width
             _new_left = _old_left + (_diff / 2)
         except:
             _new_left = 0
         # set margins
         glyph.leftMargin = _new_left
         glyph.width = _width
     #------------------
     # split difference
     elif mode == 'split relative':
         # calculate new left margin
         try:
             _whitespace = _width - _glyph_width
             _new_left = _whitespace / ( 1 + (_old_right / _old_left) )
         except:
             _new_left = 0
         # set margins
         glyph.leftMargin = _new_left
         glyph.width = _width
     #-----------
     # set width
     else:
         glyph.width = _width
     #-------
     # done!
     #-------
     glyph.update()
     glyph.performUndo()