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

  • Josh_FJosh_F Posts: 52
    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: 1,652
    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.
  • Josh_FJosh_F Posts: 52
    Great, thanks for the suggestions. Didn't think about exporting/importing the name tables from OTM.
  • Dave CrosslandDave Crossland Posts: 1,389
    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: 120
    edited March 2017
    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

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

    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
    <p>&nbsp; &nbsp; <CFFFont name="SourceSerifProTest-ExtraLight"></p><p>
    </p><p>&nbsp; &nbsp; &nbsp; <FullName value="Source Serif Pro Test ExtraLight Regular"/></p><p>
    </p><p>&nbsp; &nbsp; &nbsp; <FamilyName value="Source Serif Pro Test ExtraLight"/></p><p>
    </p><div></div>
    As for the name table, what I get from  SourceSerifPro-ExtraLight.otf,  with (nameID, platformID, langID) is

    <div><p>( 1,1, &nbsp; 0) Source Serif Pro ExtraLight</p>
    <p>( 4,1, &nbsp; 0) Source Serif Pro ExtraLight</p>
    <p>( 6,1, &nbsp; 0) SourceSerifPro-ExtraLight</p>
    <p>(16,1, &nbsp; 0) Source Serif Pro</p>
    <p>( 1,3,1033) Source Serif Pro ExtraLight</p>
    <p>( 4,3,1033) Source Serif Pro ExtraLight</p>
    <p>( 6,3,1033) SourceSerifPro-ExtraLight</p>
    <p>(16,3,1033) Source Serif Pro</p></div>
    and from the output font TestSourceSerifPro-ExtraLight.otf what I get is

    <div><p>( 1,1, &nbsp; 0) Source Serif Pro Test ExtraLight</p>
    <p>( 4,1, &nbsp; 0) Source Serif Pro Test ExtraLight Regular</p>
    <p>( 6,1, &nbsp; 0) SourceSerifProTest-ExtraLight</p>
    <p>(16,1, &nbsp; 0) Source Serif Pro Test</p>
    <p>( 1,3,1033) Source Serif Pro Test ExtraLight</p>
    <p>( 4,3,1033) SourceSerifProTest-ExtraLight</p>
    <p>( 6,3,1033) SourceSerifProTest-ExtraLight</p>
    <p>(16,3,1033) Source Serif Pro Test</p></div><div></div>
    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.
  • Josh_FJosh_F Posts: 52
    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... 
  • Josh_FJosh_F Posts: 52
    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: 120
    edited March 2017
    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"

    <p>#!/bin/sh</p>
    <p>TSTDIR=./new<br></p><p><br></p><p>ttx -t name  $1<br></p><p>sed -e 's/Source Serif Pro/Source Serif Pro Test/g' \</p>
    <p>&nbsp; &nbsp; -e 's/SourceSerifPro/SourceSerifProTest/g' ${1%.???}.ttx > ${TSTDIR}/${1%.???}.ttx</p>
    <p>ttx -m $1 ${TSTDIR}/${1%.???}.ttx</p>
    <p>rm -f ${1%.???}.ttx ${TSTDIR}/${1%.???}.ttx</p><div></div>
    Then 
    for i in Sour*.otf<br>do rename $i<br>done<br>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<br>
    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.
     

  • Batch editing of ‘name’ table entries has been made much easier in version 7 of OTM, which will be released in September. This screen recording shows briefly how one can use OTM for adding and changing ‘name’ table entries in multiple fonts. It works identically for the ‘CFF’ top dictionary.
Sign In or Register to comment.