# Adjust Side Bearings by Percentage

Hi,

Is it possible to adjust side bearings by percentage? I see it is possible to make adjustments on the side bearings, but only with fixed units. I would like to to a percentual adjustment of side bearings.

I recently made a condensed/expanded version, and the metrics, though different, are very much proportional to the regular font, and I think that would be a good starting point for spacing.

Thanks

Percentage changes are probably a bad idea, because the SB value you have multiplies your change, e.g., a zero SB will not change at all, and a negative SB will reverse. I have yet to see a situation where this would make sense.

But if you really know what you are doing, you can use my Change Sidebearings by Percentage script. You will find it in the Metrics subfolder, installation instructions are in the Readme:
https://github.com/mekkablue/Glyphs-Scripts

Thanks mate!

Natanael, were you able to figure it out? I am in a situation where I’m trying to reduce or expand side bearings by percentage, but I can’t find a suitable solution—as per mekkablue’s earlier message, negative SB are reversing.

What about using factor? for example, if the Side Baring is negative, assign an 1 before the decimal point.

e.g., reduce by 50% would be:

``````LSB = ( 20 * 0.5) =>  10
RSB = (-20 * 1.5) => -30
``````

1 Like

I tired using factor, but had some issues. I think I was implementing it wrong, your version makes sense. Gracias!

1 Like

@bnards, @Natanael,
Maybe what I am going to suggest won’t have sense until doing some test, just now I don’t have time for do it, but what about testing the following function:

``````def changeSB(sideBaring, percentage):
factor = float(percentage)/100
if sideBaring < 0:
if factor > 1 < 1.5:
factorForNegatives = (1-factor)+1
print "(+)factor =", factor
print "(-)factor (f1~1.5) =", factorForNegatives
factor = factorForNegatives
elif factor > 1.5:
factorForNegatives = -(-factor+2)
print "(+)factor =", factor
print "(-)factor (f>1.5) =", factorForNegatives
factor = factorForNegatives
else:
factorForNegatives = (-factor+2)
print "(+)factor =", factor
print "(-)factor (else) =", factorForNegatives
factor = factorForNegatives
newSideBaring = sideBaring * factor
return newSideBaring
``````

You can test it with the following implementation:

``````# fictional glyphs
LSB =  20
RSB = -20
# Testing 10%, 20%, 30% … 200%
print "="*20
for percentage in range(5,401,5):
print "\n"+str(percentage)+"%"
# in both sidebaring
newLSB = changeSB(LSB, percentage)
newRSB = changeSB(RSB, percentage)
print "LSB: %s => %s" % (LSB, newLSB)
print "RSB: %s => %s" % (RSB, newRSB)
``````

Result are like the followings:

``````20%
(+)factor = 0.2 (-)factor (else) = 1.8
LSB:  20 =>   4.0
RSB: -20 => -36.0
=============
50%
(+)factor = 0.5 (-)factor (else) = 1.5
LSB:  20 =>  10.0
RSB: -20 => -30.0
============
80%
(+)factor = 0.8 (-)factor (else) = 1.2
LSB:  20 =>  16.0
RSB: -20 => -24.0
============
100%
(+)factor = 1.0 (-)factor (else) = 1.0
LSB:  20 =>  20.0
RSB: -20 => -20.0
============
120%
(+)factor = 1.2 (-)factor (f1~1.5) = 0.8
LSB:  20 =>  24.0
RSB: -20 => -16.0
============
150%
(+)factor = 1.5 (-)factor (f1~1.5) = 0.5
LSB:  20 =>  30.0
RSB: -20 => -10.0
===========
200%
(+)factor = 2.0 (-)factor (f1~1.5) = 0.0
LSB:  20 => 40.0
RSB: -20 => -0.0
===========
400%
(+)factor = 4.0 (-)factor (f1~1.5) = -2.0
LSB:  20 => 80.0
RSB: -20 => 40.0
``````

@Nicolas - This would be quite useful. I am wondering how difficult would be to implement this in Change Sidebearings by Percentage script.

1 Like
1 Like

Awesome. Thanks, Nicolas.

Thanks Nicolas … it’s great; though cautiousness needed because undo results crashes of Glyphs frequently.

I’ll have a look at the script to fix the undo problem.

1 Like

Mainly what I am doing is:

``````for layer in Glyphs.font.selectedLayers:
if all(bound != 0 for bound in [layer.bounds.size.width, layer.bounds.size.height]):
if any(Actived == True for Actived in [ActiveLSB, ActiveRSB, ActiveTSB, ActiveBSB]):
layer.parent.beginUndo() ## Here starts Undo action
print "\n"+layer.parent.name+":"
if ActiveLSB:
LSB = layer.LSB
newLSB = changeSB(LSB, percentage)
layer.LSB = newLSB
print "LSB: %s => %s" % (LSB, newLSB)
if ActiveRSB:
RSB = layer.RSB
newRSB = changeSB(RSB, percentage)
layer.RSB = newRSB
print "RSB: %s => %s" % (RSB, newRSB)
if ActiveTSB:
TSB = layer.TSB
newTSB = changeSB(TSB, percentage)
layer.TSB = newRSB
print "TSB: %s => %s" % (TSB, newRSB)
if ActiveBSB:
BSB = layer.BSB
newBSB = changeSB(BSB, percentage)
layer.BSB = newRSB
print "BSB: %s => %s" % (BSB, newRSB)
layer.parent.endUndo() ## Here is closed Undo action
if all(Actived == False for Actived in [ActiveLSB, ActiveRSB, ActiveTSB, ActiveBSB]):
print "You have not choosen sidebarings to modify"
else:
print "\n"+layer.parent.name+":\n", "It is a space character"
``````

And the script make possible a undo stept per glyph. If you have selected all glyphs and press `command` + `z` that will make undo glyphs by glyphs. It is only time to that Glyphs could react againg. I tried it, under Glyphs Version 2.1.1 (783) and I haven’t a crash. Thanks for telling me that there are issues with Undos in Glyphs.

The script works fine for me. There seems to be a different cause of the undo problem.