Easy Slants Script

Thanks alexs. I found another solution, which is to search for mirrored components and slant them negative twice as much. I did some manual testing which works fine. But the angle is a bit off when I do it by script, which I don’t understand?
and when I slant the component by script it seems to ignore the middle x-height origin? again what works manually, but it’s ignored in the script.

# 6) Cursify all mirrored components in the Italic masters.
mirrored_component_layers = []
for master in new_masters:
	if master.internalAxesValues[italic_axis_id] == 1:
		for glyph in font.glyphs:
			layer = glyph.layers[master.id]
			
			x_height_half = master.xHeight / 2.0
			italic_angle_twice = -abs(italic_angle * 2.0)

			if not layer.components or not layer.isMasterLayer:
				continue
					
			# check for mirrored components
			for component in layer.components:
				if component.transform[0] == -1 and component.transform[3] != -1:
					# Apply the italic transformation to mirrored components
					layer.slantX_origin_doCorrection_checkSelection_(italic_angle_twice, x_height_half, True, True)
					break
				elif component.transform[0] != -1 and component.transform[3] == -1:
					# Apply the italic transformation to mirrored components
					layer.slantX_origin_doCorrection_checkSelection_(italic_angle_twice, x_height_half, True, True)
					break

And last question. All my kerning is not copied to the new italic layers, can you spot why? It should be included in this part right?

font.copyGlyphs_sourceFontMasterID_targetFontMasterID_addMissing_(font, master.id, new_master.id, addMissing)

The component of parents and such should be set up like this:

I would strongly recommend to also set alignment type to 3.

Instead of rotating 180°, it’s generally a good idea to vertically and horizontally flip once. That achieves the same result, but eliminates rounding errors.

Rotating 180° and flipping twice is exactly the same. If you flip, Glyphs will show 180° instead of -100%.

Yes, the result is the same, but I’ve found there to be rounding errors occasionally, because I often use the rotate palette with 90°, rotating 90° twice sometimes resulted in the vertical position not to be correct.

I’m not sure that would fix anything. I might be wrong. But as of now I’ve done my parens, brace, brackets, exclamdown and questiondown with flipped. Which works fine and my issue seems to be a bit different.

I have these issues:

I found another solution, which is to search for mirrored components and slant them negative twice as much. I did some manual testing which works fine. But the angle is a bit off when I do it by script, which I don’t understand?
and when I slant the component by script it seems to ignore the middle x-height origin? again what works manually, but it’s ignored in the script.

# 6) Cursify all mirrored components in the Italic masters.
mirrored_component_layers = []
for master in new_masters:
	if master.internalAxesValues[italic_axis_id] == 1:
		for glyph in font.glyphs:
			layer = glyph.layers[master.id]
			
			x_height_half = master.xHeight / 2.0
			italic_angle_twice = -abs(italic_angle * 2.0)

			if not layer.components or not layer.isMasterLayer:
				continue
					
			# check for mirrored components
			for component in layer.components:
				if component.transform[0] == -1 and component.transform[3] != -1:
					# Apply the italic transformation to mirrored components
					layer.slantX_origin_doCorrection_checkSelection_(italic_angle_twice, x_height_half, True, True)
					break
				elif component.transform[0] != -1 and component.transform[3] == -1:
					# Apply the italic transformation to mirrored components
					layer.slantX_origin_doCorrection_checkSelection_(italic_angle_twice, x_height_half, True, True)
					break

And last question. All my kerning is not copied to the new italic layers, can you spot why? It should be included in this part right?

font.copyGlyphs_sourceFontMasterID_targetFontMasterID_addMissing_(font, master.id, new_master.id, addMissing)

You should never slant/transform components. They will pick up the slanted shapes from the base glyph. Set up the components as I showed above (rotate 180° or click both slant buttons Bildschirmfoto 2023-09-05 um 12.48.50 in the transform panel).

You will run into problems once you start building italic/slanted parentheses. A flipped italic parenthesis will slant into the opposite direction if merely flipped instead of rotated. Please always rotate instead of flipping one-dimensionally.

Arhhh okay. Makes sense! Thanks.

Do you know why my kerning pairs are not copied? I guess the problem is this line:
font.copyGlyphs_sourceFontMasterID_targetFontMasterID_addMissing_(font, master.id, new_master.id, addMissing)

How is it going with your Italify script, is it still very buggy? Cause it would be awesome to be able to call from a script like this.

Kerning is not stored in your glyphs. It’s its own dictionary. You can find it as Font.kerning. Use the master IDs to access the kerning for each master.

I haven’t found the time to work on Italify much more, I’m okay with where it is right now (although I know it’s extremely far from being easily usable and reliable). It’s on my mind, though, thanks for the reminder.

you need both, the copyGlyphs and copyInfo methods.

Do you mean like this?

font.copyGlyphs_sourceFontMasterID_targetFontMasterID_addMissing_(font, master.id, new_master.id, addMissing)
font.copyInfo_sourceFontMasterID_targetFontMasterID_(master.id, new_master.id)

Or?

Yes. Something like this.

I cannot get it to work.
Is there a place where I can read about copyInfo method? Cause it doesn’t say anything here: https://docu.glyphsapp.com/

I found another way. But I don’t know if the copyInfo method includes more information than the Kerning. The alternative method is:

source_kerning = font.kerning[master.id]
font.kerning[new_master.id] = source_kerning

You should make a copy of the kerning. Or save and re-open the file.

I’m not really sure what you mean?

Copy the kerning, instead of referencing it.

source_kerning = Font.kerning[m.id].copy()
1 Like

Great! thanks :slight_smile:

Hi florian I’ve finally uploaded it to GitHub

Please let me know if you have any suggestions on how to improve it.
:grinning:

1 Like

Looks great. Just the code to copy the kerning was still not creating a proper copy. I have fixed that and opened a pull request here:

Once this fix is integrated, you can add your scripts collection to the Package Index. Or I can do it for you, if you want.