Batch amending specific word within Name Table?

Hey everyone. 

I usually use DTL OTMaster for setting up all my name records for all styles of a typeface, but I'm wondering if there may be a faster way to do one specific task.

Say I have a font called "Hello Sans", and I have all the correct name strings set up within each respective OTF file. Is there any sort of Adobe FDK script, TTX script, or any script that I could run that would say "find all instances of "Hello Sans" and replace with "Hello Sans Test", and then find all instances of "HelloSans" and replace with "HelloSansTest"?

This would essentially be a "find and replace", but I just have no clue how this would be done as a batch/bash to a folder full of OTF/TTF files (preferably), or TTX files.

If this is possible, it would save me so much time instead of opening a bunch of files in DTL OTMaster just to alter the font name.

If anyone has any recommendations or help I would really appreciate it!

Comments

  • Oops, after searching some more I found this post from 2015...

    http://typedrawers.com/discussion/1149/font-convertor/p1

    I'll try some of these suggestions, but if anyone else has something to add I'd be happy with any other help, thanks!
  • Mark SimonsonMark Simonson Posts: 788
    I usually use TTX and a text editor (BBEdit) for the find/replace part. BBEdit can do multi-file find/replace.
  • Alternatively you can export the name tables from OTM, use BBEdit for find/replace in batch as Mark suggests, and import the name tables. However, the naming stuff in the CFF table has to be altered per font still then.
  • Great, thanks for the suggestions. Didn't think about exporting/importing the name tables from OTM.
  • You can also write a python script to edit 'name' tables with the fontTools python library directly (which ttx and the XML format is a kind of mirror image of :) 

    Some examples:

    https://github.com/googlefonts/fontbakery/blob/master/fontbakery-check-name.py

    https://github.com/googlefonts/fontbakery/blob/master/fontbakery-fix-nameids.py
  • Michel BoyerMichel Boyer Posts: 55
    edited March 30
    That may be an overkill but it seems to me that Adam Twardoch's script pyftfeatfreeze.py (cf the "expert" font thread) could (in principle?) be used directly to do exactly what you need by simply using the parameters -R with the substitution strings. Both the name table and the CFF table are modified. Since my default python is python3.5, I modified the first line of pyftfeatfreeze.py, replacing python by AFDKOpython to use the AFDKO tools with python2.7.  In a folder containing source sans pro I created a subfolder called new and executed

    for i in Sour*otf
    do pyftfeatfreeze.py -R 'Source Serif Pro/Source Serif Pro Test,SourceSerifPro/SourceSerifProTest' $i new/Test$i
    done

    That produces six otf files in the subfolder new with Test before the name. Unfortunately I can't be sure of the names in the name table but I can see that the values in the CFF table have been modified.  Indeed, if I apply ttx on TestSourceSerifPro-ExtraLight.otf and grep the word Source, I get from the CFF table
        <CFFFont name="SourceSerifProTest-ExtraLight">
          <FullName value="Source Serif Pro Test ExtraLight Regular"/>
          <FamilyName value="Source Serif Pro Test ExtraLight"/>
    
    As for the name table, what I get from  SourceSerifPro-ExtraLight.otf,  with (nameID, platformID, langID) is

    ( 1,1,   0) Source Serif Pro ExtraLight
    ( 4,1,   0) Source Serif Pro ExtraLight
    ( 6,1,   0) SourceSerifPro-ExtraLight
    (16,1,   0) Source Serif Pro
    ( 1,3,1033) Source Serif Pro ExtraLight
    ( 4,3,1033) Source Serif Pro ExtraLight
    ( 6,3,1033) SourceSerifPro-ExtraLight
    (16,3,1033) Source Serif Pro
    and from the output font TestSourceSerifPro-ExtraLight.otf what I get is

    ( 1,1,   0) Source Serif Pro Test ExtraLight
    ( 4,1,   0) Source Serif Pro Test ExtraLight Regular
    ( 6,1,   0) SourceSerifProTest-ExtraLight
    (16,1,   0) Source Serif Pro Test
    ( 1,3,1033) Source Serif Pro Test ExtraLight
    ( 4,3,1033) SourceSerifProTest-ExtraLight
    ( 6,3,1033) SourceSerifProTest-ExtraLight
    (16,3,1033) Source Serif Pro Test
    Those are values I get from a script I wrote three years ago and appear to be consistent with those given by DTL OT Master Light.
  • That is about as far as I got as well Michel.

    The one thing I did notice is that pyftfeatfreeze.py takes nameID 1 and 2, and combines them to make nameID 4. As you can see on your post nameID 4 now has "Regular" tacked onto the end, most likely because nameID 2 is "Regular".

    I somehow managed to tweak the script with my tiny bit of python understanding (not much at all) and added a couple lines of code that basically say "if the word 'Regular' shows up in one of the nameIDs, only use nameID 1 for nameID4".

    Even though I figured that much out, it still seems like the CFF table isn't working correctly... 
  • Seems like Mark's TTX and then find and replace within a text editor is the best way to go. I didn't realize a lot of text editors can do find and replace across multiple files. I just tried it out and it seems to work well.

    Thanks everyone!
  • Michel BoyerMichel Boyer Posts: 55
    edited March 30
    What I did a few years ago is indeed using ttx and sed which is a stream editor that can be called from the line command and can thus be used for batch processing (either with for or with find -exec). Here is an example. Let me call that script "rename"

    #!/bin/sh
    TSTDIR=./new

    ttx -t name $1
    sed -e 's/Source Serif Pro/Source Serif Pro Test/g' \     -e 's/SourceSerifPro/SourceSerifProTest/g' ${1%.???}.ttx > ${TSTDIR}/${1%.???}.ttx ttx -m $1 ${TSTDIR}/${1%.???}.ttx rm -f ${1%.???}.ttx ${TSTDIR}/${1%.???}.ttx
    Then 
    for i in Sour*.otf
    do rename $i
    done
    gives the fonts and there is no glitch in the name table. Since only the name table is extracted, that is relatively fast. In fact, if you use
    ttx -t name -t CFF $1

    you get all the job done but that was too slow for my taste (and my needs). Of course you need to give yourself beforehand the test directory.
     

Sign In or Register to comment.