How to copy a glyph to another font

I would like to copy a glyph from sourceFont to newFont and following script works fine before the last line.

Without the last line (i.e. commented out), a glyph is copied as a new glyph with .001 suffix in sourceFont and create newFont with no glyph cell.

But with the last line, the script could create newFont with a glyph cell named uni4E9C but only Glyph Note copied, and strangely, outline of the new glyph with .001 suffix in sourceFont disappears.

How can I copy a glyph from sourceFont to newFont?

import GlyphsApp

sourceFont = Glyphs.font

targetGlyph = sourceFont.glyphs['uni4E9C'].copy()
sourceFont.glyphs.append(targetGlyph)

newFont = GSFont()
newFont.familyName = "My New Fonts"
Glyphs.fonts.append(newFont)

newFont.glyphs.append(targetGlyph)

you should not add the glyph to two different fonts at the same time. Why do you add it to the sourceFont?

Georg,

I really would like to do is subsetting/merging the the glyphs of the sourceFont according to its glyph category etc., and that script is for checking the behavior of the glyph copy function.

When working on a font project contains many glyphs such as Hiragana, Katakana, Kanji (JIS Level 1, Level 2 etc.) and symbols, I would like to generate subset fonts for each project member to design like

  • Hiragana, Katakana subset
  • Kanji (JIS Level 1) subset
  • Kanji (JIS Level 2) subset
  • Symbols 1 subset
  • Symbols 2 subset

Is there any solution or work around to do this?

Why not use the Keep Glyphs or Remove Glyphs parameter for that?

Unfortunately those custom parameters are active at Instance tab only and does not affect on Font View, and that is not what I would like to do.

I would like to make the production flow like as follow:

  1. Cheif designer designs core Kanji glyphs.
  2. Junior designers design rest of the Kanji glyphs referencing or reusing parts of 1. glyphs (Day 1)
  3. Junior designers design rest of the Kanji glyphs referencing or reusing parts of 1. and 2. glyphs (Day 2)
    Cont.

Assigned glyph range for the each Junior designers to be designed are fixed at start, and at the end of each day, merging the designed glyphs together and subsetting it (w/ reference glyphs) for each designers preparing for the next day’s production.

I hope this makes sense.

Would color-coding the different sets of glyphs accomplish your goal?

I’m not really sure what glyphs you prepare and need to remove (subset) later. I would think that you can keep all the prepared parts and just set them to not export.

this should work:

import GlyphsApp

sourceFont = Glyphs.font

targetGlyph = sourceFont.glyphs['d'].copy()

newFont = GSFont()
newFont.familyName = "My New Fonts"
newFont.masters[0].id = sourceFont.masters[0].id
Glyphs.fonts.append(newFont)

newFont.glyphs.append(targetGlyph)

The problem is that the layers in each glyph need to be connected to a master. That is done by setting the associatedMasterId and layerId. In this case it is easier to just use the same master ID so they automatically match.

And remove this line:

sourceFont.glyphs.append(targetGlyph)

eliason,
Do you mean using different glyph colors for each design ranges?

Georg,
Thanks. This is what I would like to do.
I’ll try to extend this for 2-master font.

Then you need to copy the masters to the new font first.

import GlyphsApp

sourceFont = Glyphs.font

targetGlyph = sourceFont.glyphs['d'].copy()

newFont = GSFont()
newFont.familyName = "My New Fonts"
newMasters = []
for sourceMaster in sourceFont.masters:
	newMasters.append(sourceMaster.copy())
newFont.masters = newMasters
Glyphs.fonts.append(newFont)

newFont.glyphs.append(targetGlyph)

Thanks. I got newFont with the same masters in sourceFont.

And I also could copy the sourceFont instances to the newFont with the same way.

newInstances = []
for sourceInstance in sourceFont.instances:
    newInstances.append(sourceInstance.copy())
newFont.instances = newInstances