Adding text to a glyph – as outlines

42 views
Skip to first unread message

Frank Grießhammer

unread,
Oct 2, 2014, 8:59:34 PM10/2/14
to rob...@googlegroups.com
This question could be posted in multiple different mailing lists, but this one somehow seems the most appropriate:

Inspired by a solution Jim Wasco described at ATypI this year, I would like to create a “labeled” version of a font – that means that each glyph has its glyph name written out within itself, as an outline.
This labeled font is then used to see what actually happens during a substitution, and if the result is as was intended.

I was first thinking of using DrawBot within Robofont to create a text box, but there are several obstacles:
– How can I tell DrawBot to use the current glyph (or any glyph) as its canvas?
– Can text composed via DrawBot be converted to outlines?

I also had a quick chat with DJR who suggested using a pen.
I have used pens before, but not for composing text – any pointers?

Maybe there are other solutions I am simply not thinking about at this point; I would appreciate any suggestion.


Thanks!
Frank

Frederik Berlaen

unread,
Oct 3, 2014, 4:41:06 AM10/3/14
to rob...@googlegroups.com
He Frank

Best option: a simple textsetter isnt that difficult, even with support for kerning and OT features with Tal's compositor...
you can add the paths to a glyph with a pen + a transformPen

difficult option: use drawbot by adding text as paths in a pdf and extract the contours from the pdf data afterwards

simple example:

"""
from compositor import Font as CompositorFont
from fontTools.pens.transformPen import TransformPen
from fontTools.misc.transform import Transform


# some text
text = "my text"

# get the current glyph
destGlyph = CurrentGlyph()

# load the binary font
sourceFont = CompositorFont("path/to/binaryFont.otf")

# process the text to glyph records, optionally enable some features
glyphRecords = sourceFont.process(stringOrGlyphList=text)

# setup a transform object
t = Transform()

# set a scale
t = t.scale(.3)

# loop over all glyph records
for glyphRecord in glyphRecords:
    
    # set the placement of the glyph
    t = t.translate(glyphRecord.xPlacement, glyphRecord.yPlacement)
    
    # put the dest glyph pen into the transform pen
    pen = TransformPen(destGlyph.getPen(), t)
    
    # get the source glyph from the binary font
    sourceGlyph = sourceFont[glyphRecord.glyphName]
    
    # draw the binary glyph into the pen
    sourceGlyph.draw(pen)
    
    # reset the placement
    t = t.translate(-glyphRecord.xPlacement, -glyphRecord.yPlacement)
    # set the advance width
    t = t.translate(glyphRecord.advanceWidth, glyphRecord.advanceHeight)
    # some kerning
    t = t.translate(glyphRecord.xAdvance, glyphRecord.yAdvance)
"""

good luck

gr Frederik



--
--
You received this message because you are subscribed to the Google Groups "RoboFab" group.
To post to this group, send email to rob...@googlegroups.com
To unsubscribe from this group, send email to robofab-u...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/robofab?hl=en
 
Messages from newly joined members are subject to moderation.
Download RoboFab and documentation at http://robofab.com
---
You received this message because you are subscribed to the Google Groups "RoboFab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robofab+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Behdad Esfahbod

unread,
Oct 3, 2014, 1:41:08 PM10/3/14
to rob...@googlegroups.com
On 14-10-02 08:59 PM, Frank Grießhammer wrote:
> This question could be posted in multiple different mailing lists, but this
> one somehow seems the most appropriate:
>
> Inspired by a solution Jim Wasco described at ATypI this year, I would like to
> create a “labeled” version of a font – that means that each glyph has its
> glyph name written out within itself, as an outline.
> This labeled font is then used to see what actually happens during a
> substitution, and if the result is as was intended.

What an interesting idea!


> I was first thinking of using DrawBot within Robofont to create a text box,
> but there are several obstacles:
> – How can I tell DrawBot to use the current glyph (or any glyph) as its canvas?
> – Can text composed via DrawBot be converted to outlines?
>
> I also had a quick chat with DJR who suggested using a pen.
> I have used pens before, but not for composing text – any pointers?
>
> Maybe there are other solutions I am simply not thinking about at this point;
> I would appreciate any suggestion.

For TrueType-flavored fonts here's a simple approach using fontTools:

- Find glyphs for ASCII characters that can appear in glyph names. If your
font doesn't have them, add to the font from another font,

- For each pre-existing glyph X in the font, create a new glyph Y that is a
composite glyph, referencing glyph X at full size, but also referencing the
ASCII glyphs, with scale and translation, to spell out the name,

- Update cmap to point to glyph Y where glyph X was pointed at.

I might prototype this.

behdad

>
> Thanks!
> Frank
>
> --
> --
> You received this message because you are subscribed to the Google Groups
> "RoboFab" group.
> To post to this group, send email to rob...@googlegroups.com
> To unsubscribe from this group, send email to robofab-u...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/robofab?hl=en
>
> Messages from newly joined members are subject to moderation.
> Download RoboFab and documentation at http://robofab.com
> ---
> You received this message because you are subscribed to the Google Groups
> "RoboFab" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to robofab+u...@googlegroups.com
> <mailto:robofab+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--
behdad
http://behdad.org/

Frank Grießhammer

unread,
Oct 3, 2014, 3:38:50 PM10/3/14
to rob...@googlegroups.com
Thank you Georg, David, Paul and Frederik for your code examples.
Thank you also Behdad; it sounds interesting to add this to FontTools, but I think it is a rather specialized use case.

At first, I was also thinking of using the same font within itself (like one example suggested), but since I am working with a very expressive script font, this solution wouldn’t be that convenient. That is why I built on Frederik’s example – I didn’t really have to change it. 

I think showing an image of the result makes clear what I wanted to do:

calt off:
Inline image 1

calt on:
Inline image 2

The marked version of the font makes it much easier to see what is actually happening in a particular feature.
Find the final code I used attached.

Thank you all again,
have a nice weekend!

Frank




To unsubscribe from this group and stop receiving emails from it, send an email to robofab+u...@googlegroups.com.
addGlyphNameAsOutline.py
Reply all
Reply to author
Forward
0 new messages