Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address minor issues #20

Merged
merged 7 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.pyc
*.pyc
.DS_Store
*/.DS_Store
4 changes: 2 additions & 2 deletions ScaleFast.roboFontExt/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<key>requiresVersionMinor</key>
<string>2</string>
<key>timeStamp</key>
<real>1433764325.401228</real>
<real>1695153315</real>
<key>version</key>
<string>1.0.6</string>
<string>1.1</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ def _formatValue(self, value):
if self.numType == 'int':
value = int(round(value))
elif self.numType == 'float':
value = round(value, 2)
if value == int(value):
value = int(value)
else:
value = round(value, 2)
return value

# Testing stuff
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# coding=utf-8
# Loïc Sander — 2014
from .baseParameter import SingleValueParameter
from vanilla import Group, Slider, EditText, TextBox, CheckBox
from vanilla import Group, Slider, TextBox, CheckBox
from mojo.UI import NumberEditText

class BaseParameterVanillaInput:

Expand Down Expand Up @@ -44,7 +45,7 @@ def __init__(self, parameter, posSize, text='', callback=None, continuous=False,
self.parameter = parameter
rel = self._relValue()
self.callback = callback
self.textInput = EditText((0, 0, -40, -0), text=text, callback=self._valueInput, continuous=continuous)
self.textInput = NumberEditText((0, 0, -40, -0), text=parameter.value, callback=self._valueInput, allowEmpty=False, continuous=continuous, decimals=1)
self.relInfo = TextBox((-35, 5, -0, -0), rel, alignment='left', sizeStyle='small')
self.showRelativeValue(showRelativeValue)
self.vanillaInputs = [self.textInput]
Expand All @@ -71,6 +72,7 @@ def _valueInput(self, sender):
self.callback(self)
return
elif value != '*':
if value == int(value): value = int(value)
parameter.setInput(value, sender=sender)
parameter.update()
if self.callback is not None:
Expand All @@ -87,7 +89,7 @@ def setFree(self, sender):

def update(self, sender):
value = self.parameter.get()
self.textInput.set(str(value))
self.textInput.set(value)
self._updateRelValue()

def _updateRelValue(self):
Expand All @@ -101,7 +103,7 @@ def _relValue(self):
if parameter.mode == 'ratio':
rel = '%s' % (parameter.getRatio())
elif parameter.mode == 'offset':
offsetValue = int(parameter.getOffset())
offsetValue = round(parameter.getOffset(), 1)
sign = '+' if offsetValue >= 0 else ''
rel = '%s%s' % (sign, offsetValue)
return rel
Expand All @@ -127,7 +129,7 @@ def __init__(self, parameter, posSize, title=None, callback=None):
editTextPosSize = (-65, 0, 40, 22)
self.checkBox = CheckBox((-22, 0, 22, 22), u'∞', callback=self.setFree, value=True, sizeStyle='mini')
self.slider = Slider(sliderPosSize, minValue=parameter.limits[0], maxValue=parameter.limits[1], value=parameter.value, callback=self.valueInput, sizeStyle='small')
self.textInput = EditText(editTextPosSize, str(parameter.value), callback=self.valueInput, continuous=False, sizeStyle='small')
self.textInput = NumberEditText(editTextPosSize, text=parameter.value, callback=self.valueInput, allowEmpty=False, continuous=False, sizeStyle='small')
self.parameter.bind(self)

def get(self):
Expand Down Expand Up @@ -156,7 +158,7 @@ def valueInput(self, sender):

def update(self, sender):
value = self.parameter.get()
self.textInput.set(str(value))
self.textInput.set(value)
if (value != '*'):
self.slider.set(value)
if hasattr(self, 'checkBox'):
Expand Down
54 changes: 29 additions & 25 deletions ScaleFast.roboFontExt/lib/scaleFast.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#coding=utf-8
from __future__ import division

__version__ = '1.0.1'
__version__ = '1.1'

"""
Written by Loïc Sander
Version history
1. november 2014
2. march 2015
3. june 2015
4. august/october 2018 (RF3 updates by @gferreira)
1. November 2014
2. March 2015
3. June 2015
4. August/October 2018 (RF3 updates by @gferreira)
5. September 2023
ScaleFast is a Robofont extension with a simple mission:
trying to maintain stem width while you transform a glyph.
To do that, the tool relies on masters (you need at least two),
analyses them and does its best to keep stems consistent
through interpolation, powered by Erik van Blokland’s MutatorMath.
ScaleFast is a RoboFont extension with a simple mission:
Try to maintain stem width while transforming a glyph.
To do that, the tool relies on multiple UFO sources,
analyses them, and does its best to keep stems consistent
using interpolation, powered by Erik van Blokland’s MutatorMath.

Thanks to Frederik Berlaen for the inspiration.
"""
Expand All @@ -35,14 +36,14 @@
from mutatorScale.objects.scaler import MutatorScaleEngine
from mutatorScale.utilities.fontUtils import makeListFontName, getRefStems

from dynamicParameters.vanillaParameterObjects import VanillaSingleValueParameter, ParameterTextInput
from dynamicParameters.baseParameter import SingleValueParameter

from vanilla import *
from mojo.events import addObserver, removeObserver
from mojo.UI import MultiLineView
from mojo.UI import MultiLineView, NumberEditText
from mojo.drawingTools import *

from dynamicParameters.vanillaParameterObjects import VanillaSingleValueParameter, ParameterTextInput
from dynamicParameters.baseParameter import SingleValueParameter

from AppKit import NSColor, NSBoxCustom
# NSTableViewAnimationSlideLeft, NSIndexSet, NSAnimationTriggerOrderOut
from defconAppKit.tools.textSplitter import splitText
Expand Down Expand Up @@ -202,7 +203,7 @@ def __init__(self):
controls.stemBox.vTitle = TextBox((-210, 15, 60, 22), 'Vertical', sizeStyle='small')
controls.stemBox.hTitle = TextBox((-210, 40, 60, 22), 'Horizontal', sizeStyle='small')
controls.stemBox.vstem = ParameterTextInput(self.definedStems['vstem'], (-140, 10, 95, 22), callback=self._stemsUpdated, showRelativeValue=True)
controls.stemBox.hstem = ParameterTextInput(self.definedStems['hstem'], (-140, 35, 95, 22), callback=self._stemsUpdated, showRelativeValue=True)
controls.stemBox.hstem = ParameterTextInput(self.definedStems['hstem'], (-140, 35, 95, 22), callback=self._stemsUpdated, showRelativeValue=False)
controls.stemBox.hstem.enable(False)
controls.stemBox.isotropic = CheckBox((-40, 22, -0, 22), u'∞', value=True, callback=self._switchIsotropicCallback)

Expand All @@ -228,21 +229,21 @@ def __init__(self):
controls.verticalScaleBox.referenceHeight.set('capHeight')
controls.verticalScaleBox.toSize = TextBox((110, 10, 20, 22), u'▹', alignment='center')
controls.verticalScaleBox.targetHeightSlider = Slider((130, 10, -70, 22), value=1, minValue=0.1, maxValue=2, callback=self._setTargetHeight)
controls.verticalScaleBox.targetHeightInput = EditText((-60, 10, -10, 22), continuous=False, callback=self._setTargetHeight)
controls.verticalScaleBox.targetHeightInput = NumberEditText((-60, 10, -10, 22), minimum=1, allowFloat=False, allowNegative=False, allowEmpty=False, callback=self._setTargetHeight)

# Horizontal scale
controls.horizontalScaleBox = Box((0, 150, -0, 52))
controls.horizontalScaleBox.widthSlider = Slider((10, 10, -100, 22), value=1, minValue=0, maxValue=3, callback=self._setWidth)
controls.horizontalScaleBox.widthInput = EditText((-90, 10, -40, 22), continuous=False, callback=self._setWidth)
controls.horizontalScaleBox.widthSlider = Slider((10, 10, -100, 22), value=1, minValue=0.01, maxValue=3, callback=self._setWidth)
controls.horizontalScaleBox.widthInput = NumberEditText((-90, 10, -40, 22), minimum=1, allowFloat=False, allowNegative=False, allowEmpty=False, callback=self._setWidth, continuous=False)
controls.horizontalScaleBox.unit = TextBox((-30, 10, -10, 22), '%')

# Position shift
controls.posShift = Box((0, 212, 85, 84))
controls.posShift.xShiftTitle = TextBox((5, 15, 10, 17), 'X', sizeStyle='small')
controls.posShift.xShift = EditText((20, 10, 50, 22), self.transformations['posX'], self._changePosition, continuous=False)
controls.posShift.xShift = NumberEditText((20, 10, 50, 22), text=self.transformations['posX'], allowFloat=False, allowNegative=True, allowEmpty=False, callback=self._changePosition, continuous=False)
controls.posShift.xShift.key = 'posX'
controls.posShift.yShiftTitle = TextBox((5, 47, 10, 17), 'Y', sizeStyle='small')
controls.posShift.yShift = EditText((20, 42, 50, 22), self.transformations['posY'], self._changePosition, continuous=False)
controls.posShift.yShift = NumberEditText((20, 42, 50, 22), text=self.transformations['posY'], allowFloat=False, allowNegative=True, allowEmpty=False, callback=self._changePosition, continuous=False)
controls.posShift.yShift.key = 'posY'

# Sticky
Expand All @@ -260,7 +261,7 @@ def __init__(self):

# Tracking
controls.tracking = Box((0, 306, -0, 52))
controls.tracking.input = EditText((10, 10, 50, 22), '0', self._changeTracking)
controls.tracking.input = NumberEditText((10, 10, 50, 22), text='0', allowFloat=False, allowNegative=True, callback=self._changeTracking)
controls.tracking.units = PopUpButton((70, 10, 60, 22), ['upm','%'], self._changeTrackingUnits)
controls.tracking.dontScaleSpacing = CheckBox((145, 13, -10, 17), u'Keep initial sidebearings', value=self.transformations['keepSidebearings'], sizeStyle='small', callback=self._keepSidebearings)

Expand Down Expand Up @@ -452,7 +453,8 @@ def _buildGenerationSheet(self, sender):
batch = self.sheet.inner.options[1]

current.glyphsetTitle = TextBox((10, 10, 100, 22), 'Glyphset')
current.glyphset = ComboBox((110, 10, -10, 22), ['','All glyphs'])
current.glyphset = ComboBox((110, 10, -10, 22), ['', 'All glyphs'])
current.glyphset.set('All glyphs')

current.suffixTitle = TextBox((10, 42, 100, 22), 'Suffix')
current.suffix = EditText((110, 42, -10, 22))
Expand Down Expand Up @@ -525,7 +527,7 @@ def _generationCallback(self, sender):
if selectedTabIndex == 0:
rawGlyphNames = self.sheet.inner.options[0].glyphset.get()
if rawGlyphNames == 'All glyphs' and self.currentFont is not None:
glyphset = self.currentFont.keys()
glyphset = self.currentFont.glyphOrder
else:
glyphset = self._stringToGlyphNames(rawGlyphNames)

Expand Down Expand Up @@ -594,7 +596,7 @@ def _setTargetHeight(self, sender):
height_targetValue = height_referenceValue * float(targetHeight)
self.controls.verticalScaleBox.targetHeightInput.set(int(round(height_targetValue)))

elif isinstance(sender, EditText) and len(targetHeight):
elif isinstance(sender, EditText):
try:
height_targetValue = float(targetHeight)
ratio = height_targetValue / height_referenceValue
Expand Down Expand Up @@ -685,6 +687,7 @@ def _switchIsotropicCallback(self, sender):

def _switchIsotropic(self, value):
self.controls.stemBox.hstem.enable(value)
self.controls.stemBox.hstem.showRelativeValue(value)
self._updatePreview(True)


Expand All @@ -702,7 +705,8 @@ def _switchParameterMode_(self, parameterMode):
if parameterMode in ['offset','ratio']:
parameter.setFree(False)
parameter.setMode(parameterMode)
control.showRelativeValue(True)
if key == 'vstem' or self.controls.stemBox.isotropic.get() == False:
control.showRelativeValue(True)
elif parameterMode == 'absolute':
parameter.setFree(True)
control.showRelativeValue(False)
Expand Down