Increase LSB and RSB of selected glyphs

I try to add some space left and right of selected glyphs, but I don’t want to change the sidebearings of the composites. (My tabular numbers for instance are composites of the regular numbers, but they should stay as they are.) Despite my poor python skills I tried to write a script which adds the space, and then moves the composites back. Surprisingly this works.
But now I have a font with no anchors, and I want to change the sidebearings of the base glyphs as well as the composites. When using the transformation tool, it moves the composite glyphs twice (is this a bug?)
Theoretically it should work also with my little script, but it doesn’t. It works when I select the base glyphs and the composites separately. But when base glyphs and composites are selected, it only adds RSB and LSB to the base glyph.
Any advice anyone?

Here’s the script (certainly there is a much more clever way to write it):

thisFont = Glyphs.font
list =[]
left = 10
right = 10

for g in thisFont.selectedLayers:  
	g.LSB = g.LSB + left
	g.RSB = g.RSB + right
	glyph = g.parent
	reused = thisFont.glyphsContainingComponentWithName_masterID_(glyph.name, thisFont.selectedFontMaster.id)
	list.append(reused)
	
for individuallist in list:
	for a in individuallist:
		b = a.layers[thisFont.selectedFontMaster.id]
		c = b.components[0]
		d = c.position[0]
		e = d - left
		c.transform = ((1, 0, 0, 1, e, 0.0))
1 Like

The script works for me. That is, unless you intend something else. If you select both glyphs with paths and with (unaligned) components, you are moving the components twice, and correcting them once.

The problem you have is that it does not anticipate the order in which the glyphs get processed. IOW, if B contains A as a component, it makes a difference if you run it with AB or BA selected.

Here is slightly cleaned-up version of the above:

thisFont = Glyphs.font
compoundList =[]
left = 10
right = 10

for g in thisFont.selectedLayers:  
	g.LSB = g.LSB + left
	g.RSB = g.RSB + right
	glyph = g.parent
	reused = thisFont.glyphsContainingComponentWithName_masterID_(glyph.name, thisFont.selectedFontMaster.id)
	compoundList.extend(reused)
	
for glyph in compoundList:
	layer = glyph.layers[thisFont.selectedFontMaster.id]
	comp = layer.components[0]
	comp.position.x -= left

But please tell me what exactly should happen with A and B after running this script, like an example: A (paths) LSB=40, RSB=40; B (contains component of A), LSB=30, RSB=30.

Thanks Rainer, but your script doesn’t work as expected, it doesn’t move the composite back.

What I want is simply add LSB and RSB to selected glyphs, but leave the composites (if not selected) as they were. And, if A and B selected, I want to add the same space to both (A and B LSB=40, RSB=40).
In my script it works for example when A (path; LSB=0, RSB=0) selected. It adds LSB=10, RSB=10, but moves Adieresis (unaligned component) back LSB=0, RSB=0.
But when I select both, it does the same: A LSB=10, RSB=10, Adieresis LSB=0, RSB=0.
But it should, as you write, move the components twice, and correcting them once.

btw, would be good if this would be implemented in the transformation filter, for example a checkbox in transformation metrics: do not change composites.