Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.

Commit

Permalink
fixing issues with set-margins and set-width
Browse files Browse the repository at this point in the history
  • Loading branch information
gferreira committed Mar 4, 2014
1 parent 943205e commit b3eec8f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 66 deletions.
4 changes: 2 additions & 2 deletions README.md
@@ -1,5 +1,5 @@
# hTools2 RoboFont extension
# hTools2 extension

hTools2 bundled as a RoboFont extension. Install with one click!
hTools2 bundled as a [RoboFont](http://robofont.com/) extension. Install with one click!

For more info and the source code, visit [hTools2](http://github.com/gferreira/hTools2/).
2 changes: 1 addition & 1 deletion hTools2.roboFontExt/info.plist
Expand Up @@ -23,7 +23,7 @@
<key>requiresVersionMinor</key>
<string>5</string>
<key>timeStamp</key>
<real>1393883867.9635291</real>
<real>1393922756.7716579</real>
<key>version</key>
<string>1.6</string>
</dict>
Expand Down
@@ -1,11 +1,6 @@
# [h] set margins dialog

'''Set left/right side-bearings of selected glyphs.'''
import hTools2.dialogs.glyphs.set_margins
reload(hTools2.dialogs.glyphs.set_margins)

# import

from hTools2.dialogs.glyphs import setMarginsDialog

# run

setMarginsDialog()
hTools2.dialogs.glyphs.set_margins.setMarginsDialog()
@@ -1,11 +1,6 @@
# [h] set width dialog

'''Set the advance width of the selected glyphs.'''
import hTools2.dialogs.glyphs.set_width
reload(hTools2.dialogs.glyphs.set_width)

# import

from hTools2.dialogs.glyphs import setWidthDialog

# run

setWidthDialog()
hTools2.dialogs.glyphs.set_width.setWidthDialog()
2 changes: 1 addition & 1 deletion hTools2.roboFontExt/lib/hTools2/__init__.py
Expand Up @@ -41,7 +41,7 @@ class hConstants(object):
square_button = 35

#: Can nummerical text input be edited directly with the keyboard? A boolean. Set to ``True`` as default.
read_only = True
read_only = False

#: The size style of text and standard dialog elements. Possible options are ``small``, ``regular``, ``mini``.
size_style = 'small'
Expand Down
29 changes: 19 additions & 10 deletions hTools2.roboFontExt/lib/hTools2/dialogs/glyphs/set_margins.py
Expand Up @@ -37,9 +37,7 @@ def __init__(self):
self.title = 'margins'
self.width = 123
self.height = (self.text_height * 5) + (self.padding_y * 9) + (self.nudge_button * 2) + self.button_height
self.w = FloatingWindow(
(self.width, self.height),
self.title)
self.w = FloatingWindow((self.width, self.height), self.title)
#-------------
# left margin
#-------------
Expand Down Expand Up @@ -70,7 +68,7 @@ def __init__(self):
self.text_height),
self._left_value,
sizeStyle=self.size_style,
readOnly=False)
readOnly=self.read_only)
# spinners
x = self.padding_x
y += (self.text_height + 10)
Expand Down Expand Up @@ -152,7 +150,7 @@ def __init__(self):
self.text_height),
self._right_value,
sizeStyle=self.size_style,
readOnly=False)
readOnly=self.read_only)
x = self.padding_x
y += (self.text_height + 10)
# spinners
Expand Down Expand Up @@ -310,6 +308,7 @@ def right_mode_callback(self, sender):

def set_margins(self, glyph, (left, left_value, left_mode), (right, right_value, right_mode)):
glyph.prepareUndo('set margins')

# left margin
if left:
# increase by
Expand All @@ -324,6 +323,7 @@ def set_margins(self, glyph, (left, left_value, left_mode), (right, right_value,
# set left margin
glyph.leftMargin = _left_value_new
glyph.update()

# right margin
if right:
# increase by
Expand All @@ -338,39 +338,48 @@ def set_margins(self, glyph, (left, left_value, left_mode), (right, right_value,
# set right margin
glyph.rightMargin = _right_value_new
glyph.update()

# done glyph
glyph.performUndo()
glyph.update()

def apply_callback(self, sender):

f = CurrentFont()

if f is not None:
boolstring = [ 'False', 'True' ]

# get parameters
_left = self.w.left_checkbox.get()
_left_mode = self.w.left_mode.get()
_left_value = int(self.w.left_value.get())
_right = self.w.right_checkbox.get()
_right_mode = self.w.right_mode.get()
_right_value = int(self.w.right_value.get())

# iterate over glyphs
glyph_names = get_glyphs(f)
if len(glyph_names) > 0:

# print info
print 'setting margins for selected glyphs...\n'
print '\tleft: %s %s [%s]' % (self._modes[_left_mode], self._left_value, boolstring[_left])
print '\tright: %s %s [%s]' % (self._modes[_right_mode], self._right_value, boolstring[_right])
print '\tleft: %s %s [%s]' % (self._modes[_left_mode], _left_value, boolstring[_left])
print '\tright: %s %s [%s]' % (self._modes[_right_mode], _right_value, boolstring[_right])
print
print '\t\t',

# set margins
for glyph_name in glyph_names:
print glyph_name,
self.set_margins(f[glyph_name],
(_left, self._left_value, _left_mode),
(_right, self._right_value, _right_mode))
self.set_margins(f[glyph_name], (_left, _left_value, _left_mode), (_right, _right_value, _right_mode))
f.update()
print '\n...done.\n'

# no glyph selected
else:
print no_glyph_selected

# no font open
else:
print no_font_open
Expand Down
67 changes: 31 additions & 36 deletions hTools2.roboFontExt/lib/hTools2/dialogs/glyphs/set_width.py
Expand Up @@ -10,7 +10,9 @@
from vanilla import *

from hTools2 import hConstants
from hTools2.modules.fontutils import get_glyphs
from hTools2.modules.glyphutils import center_glyph
from hTools2.modules.messages import no_font_open, no_glyph_selected

# objects

Expand All @@ -33,9 +35,7 @@ def __init__(self):
self.col_3 = 70
self.width = 123
self.height = self.button_height + (self.text_height * 5) + self.nudge_button + (self.padding_y * 6) + 1
self.w = FloatingWindow(
(self.width, self.height),
self.title)
self.w = FloatingWindow((self.width, self.height), self.title)
# left
x = self.padding_x
y = self.padding_y
Expand Down Expand Up @@ -65,7 +65,8 @@ def __init__(self):
self.text_height),
placeholder='set value',
text=self._width_,
sizeStyle=self.size_style)
sizeStyle=self.size_style,
readOnly=self.read_only)
# nudge spinners
x = self.padding_x
y += (self.nudge_button + self.padding_y)
Expand Down Expand Up @@ -219,17 +220,16 @@ def _split_relative_callback(self, sender):
# apply

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
#---------------

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

# add value
if self._mode == 1:
_width = _old_width + width
Expand All @@ -239,14 +239,12 @@ def set_width(self, glyph, width, mode=None):
# 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
Expand All @@ -258,7 +256,7 @@ def set_width(self, glyph, width, mode=None):
# set margins
glyph.leftMargin = _new_left
glyph.width = _width
#----------------

# split relative
elif mode == 'split relative':
# calculate new left margin
Expand All @@ -270,26 +268,29 @@ def set_width(self, glyph, width, mode=None):
# set margins
glyph.leftMargin = _new_left
glyph.width = _width
#-----------

# set width
else:
glyph.width = _width
#-------

# done!
#-------
glyph.update()
glyph.performUndo()

def apply_callback(self, sender):

f = CurrentFont()

if f is not None:

# get parameters
_width = int(self.w.width_value.get())
_center = self.w.center_checkbox.get()
_split = self.w.split_checkbox.get()
_split_relative = self.w.split_relative_checkbox.get()
_gNames = f.selection
boolstring = ( False, True )

# set sidebearings mode
if _center:
_w_mode = 'center'
Expand All @@ -299,34 +300,28 @@ def apply_callback(self, sender):
_w_mode = 'split relative'
else:
_w_mode = None

# print info
print 'setting character widths...\n'
print '\t%s %s' % (self._modes[self._mode], _width)
print '\tmode: %s' % _w_mode
print
print '\t',
# current glyph
glyph = CurrentGlyph()
if glyph is not None:
print glyph.name,
self.set_width(glyph, _width, _w_mode)

# iterate over glyphs
glyph_names = get_glyphs(f)
if len(glyph_names) > 0:
for glyph_name in glyph_names:
print glyph_name,
self.set_width(f[glyph_name], _width, _w_mode)
f.update()
print
print '\n...done.\n'
# selected glyphs

# no glyph selected
else:
glyph_names = f.selection
if len(glyph_names) > 0:
for glyph_name in glyph_names:
print glyph_name,
self.set_width(f[glyph_name], _width, _w_mode)
f.update()
print
print '\n...done.\n'
# no glyph selected
else:
print 'please select one or more glyphs first.\n'
print no_glyph_selected

# no font open
else:
print 'please open a font first.\n'

print no_font_open

0 comments on commit b3eec8f

Please sign in to comment.