Typophile

How to add Dummy DSIG to OpenType TT font?

Adrian Williams

I need to add a Digital Signature to OpenType-TT fonts. I found some instructions but need to know how it gets into the font which I am making with FontLab on Mac (font is intended Windows)...
~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a ttx file with a dummy DSIG table, like so:

<?xml version="1.0" encoding="ISO-8859-1"?>

00000001 00000000

Then you can merge this into your OT/TTF like this:

ttx -m font.ttf dsig.ttx

This will decompile the ttf, add the DSIG table, and recompile in one step. Then the font will work as intended in MS Office (or so I have found in my testing thus far.) This is also easy to incorporate into other scripts.

~~~~~~~~~~~~~~~~~~~~~~~~
As a newbie to Python, XML and all that, can someone please just explain the process - without the coding. A step-by-step list of what happens, when. For example, do this, copy that, paste it there. Run this, build that. Otherwise all this coding talk is useless to me until I understand how the code gets into the font.

I'm using a Mac and FontLab and I'm guessing FontLab has to run this ttx script in order to get the dummy DSIG into the TT font? So it should mean I can do that on the Mac and the resulting TTF will work on Windows?

Thanks,
Adrian

Or, if you are willing to venture into the scary-scary place known by names like "Command Prompt" and "Terminal", you could do the typing yourself with the same result.

Trying to condense the 'magic' into a simple incantation:

1. Type that bit of XML you got into a text editor and save it as ASCII text to "dsig.ttx". You can use a word processor if it can save ASCII files, but it's too much like making a fifty-metre trip in a sport-ute.

2. Open the Terminal or Command Prompt window and type in "ttx -m ". Drag and drop the font file onto the terminal. Make sure there is a space after the just-appeared filename. Drag and drop dsig.ttx onto the terminal. Now Press Return.

3. Now the computer will either tell you ttx doesn't exist (meaning it just can't find it) or it'll go on to do the typotechnical jiggery-pokery needed to add the dummy DSIG to the font. If you know ttx exists, make it the first file to drag and drop onto the terminal.

4. If no text appears when you drag and drop stuff onto the terminal, you are in for a whole lot more typing. Ouch.

The very first thing to do is to get a terminal window. Click on the Launchpad icon and then type term; you should see this appear. Then you click on terminal


In the terminal window, after the "prompt" (probably %) you type "which ttx" as follows

% which ttx
/Users/boyer/bin/FDK/Tools/osx/ttx
% 

Here I got that ttx is installed in my FDK tools folder. If you get no answer, ttx is not installed and the first thing to do is to install ttx. You should have it if you properly installed AFDKO.

You can then copy the lines between the cut lines and paste them in the terminal window

------------- cut line
FLDR="${HOME}/Desktop/Dsig fldr"
mkdir -p "$FLDR"
cd "$FLDR"
cat > dsig.ttx<<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="2.3">

  <DSIG>
    <hexdata>
      00000001 00000000  
    </hexdata>
  </DSIG>

</ttFont>
EOF

open .
------------- cut line

After the paste, you may need to type a carriage return. That will create a folder on your desktop containing the file dsig.ttx and open the folder so that you can select and drop the file dsig.ttx as described above.

Note: I had to use &lt; and &gt; for < and > lines to show above else the corresponding lines were blank; now the dsig.ttx file produced by the copy paste works fine, I tested.

You can then do as explained by Té Rowan.

You can also do as follows.

First you copy the file dsig.ttx in the font folder containing the fonts you want to process.

After that, in the terminal window, you type "cd " (with a space after cd but no carriage return) and then do as if you wanted to drag into that terminal window the folder containing the ttf files to process and then type carriage return.

Now if you type "ls" (with a carriage return) in the terminal window, you should get a listing of your font files.

To add DSIG to all of the ttf files you can now paste in the terminal window the following lines (between the cut lines)

------------- cut line
for i in *.ttf
do 
  newname="${i%.ttf}win"
  cp dsig.ttx "${newname}".ttx
  ttx -m "$i" "${newname}".ttx
  rm -f "${newname}".ttx
done 
------------- cut line

That will create a ...win.ttf file for each ttf font you have there. The win.ttf file contains the DSIG stub.

Thanks Michel for the comprehensive instructions - but I fall at the very first hurdle. I downloaded AFDK which landed in the Downloads Folder, so I moved the whole FDK Folder to an Applications Folder I have in my home Folder (~home/Applications). I launched Terminal and typed "which ttx" Return, but got this

Last login: Wed Oct 22 14:42:40 on ttys000
adrians-imac:~ adrianshome$ which ttx
/usr/local/bin/ttx

It only shows the home Folder and no path to... Tools/osx/ttx

What now?

Thanks Té, I understand this process. Tried it but knowing nothing of how xml coding works, I don't think I pasted the correct code. Here's what I get:

- - - - - - -
Last login: Wed Oct 22 15:04:16 on ttys000
adrians-imac:~ adrianshome$ ttx-m/Users/adrianshome/Documents/\ SASSOON/Sassoon\ Fonts\ DEV/Current\ Versions/font+installer\ builds/Sassoon\ TTX\ scripts/SassoFelReg.ttf <?xml version="1.0" encoding="ISO-8859-1"?>
-bash: syntax error near unexpected token `newline'
adrians-imac:~ adrianshome$
-bash: syntax error near unexpected token `newline'
adrians-imac:~ adrianshome$
-bash: syntax error near unexpected token `newline'
adrians-imac:~ adrianshome$
-bash: syntax error near unexpected token `newline'
adrians-imac:~ adrianshome$ 00000001 00000000
-bash: 00000001: command not found
adrians-imac:~ adrianshome$
-bash: syntax error near unexpected token `newline'
adrians-imac:~ adrianshome$
-bash: syntax error near unexpected token `newline'
adrians-imac:~ adrianshome$
-bash: syntax error near unexpected token `newline'
adrians-imac:~ adrianshome$
- - - - - - -

I pasted this...

<?xml version="1.0" encoding="ISO-8859-1"?>

00000001 00000000

BUT WHERE DOES THIS BELONG..?
ttx -m font.ttf dsig.ttx
AND, does "font.ttf" have to be the actual name of the font file?

Cheers,
Adrian

The code

<?xml version="1.0" encoding="ISO-8859-1"?>

00000001 00000000

does not work. You need the DSIG tag, and the hexdata else ttx does not know what to do with your stub.

font.ttf is the actual name of the font file.

I also see that my stub which worked at home does not work on my machine in the office.

Here is what I pasted in Terminal , but when I post on this forum the whole code does not appear for some reason? Do I always need to bracket it like so " blah, blah"

<?xml version="1.0" encoding="ISO-8859-1"?>

00000001 00000000

and still the question:
BUT WHERE DOES THIS BELONG..?
ttx -m font.ttf dsig.ttx

Here's what my code snippet looks like, but I've had to replace < and > with "-" in order to display it in these posts! How on earth does everyone display code snippets. Mine keep getting chopped off? I've tried bracketing code with 'pre' and 'code' but no joy.

-?xml version="1.0" encoding="ISO-8859-1"?-
-ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="2.2"-
-DSIG-
-hexdata-
00000001 00000000
-/hexdata-
-/DSIG-
-/ttFont-

Still have no idea how/when to use this:
ttx -m font.ttf dsig.ttx

I just reinstalled AFDKO at home and the current version of ttx is no longer 2.3 but 2.4. Here is a trace of execution that shows the version:

M-660 % ttx | head -3
usage: ttx [options] inputfile1 [... inputfileN]

    TTX 2.4 -- From OpenType To XML And Back
M-661 % 

The snippet for 2.3 no longer works with ttx 2.4. Here is a snippet that works with TTX 2.4

<?xml version="1.0" encoding="utf-8"?>
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="2.4">
  <DSIG>
    <tableHeader flag="0x0" numSigs="0" version="1"/>
  </DSIG>
</ttFont>

For whatever version of ttx you are using, the corresponding snippet needs to be put in a text file. It was assumed above that the file name is dsig.ttx.

OK, I have version 2.4 of Fonttools. Something is happening but I don't know exactly how I arrived there. I get a new file entitled 'dsig#1.ttf', 'dsig#2.ttf' etc, in Dsig fldr but only 36k file size. So now I guess I just need to know exactly which steps to take.
- - - - - - - -
Last login: Thu Oct 23 07:00:26 on console
adrians-imac:Dsig fldr adrianshome$ which ttx
/usr/local/bin/ttx
adrians-imac:Dsig fldr adrianshome$ /Users/adrianshome/Downloads/fonttools-2.4/Tools/ttx /Users/adrianshome/Downloads/fonttools-2.4/Tools/dsig.ttx /Users/adrianshome/Downloads/fonttools-2.4/Tools/SassoBoo.ttf
Compiling "/Users/adrianshome/Downloads/fonttools-2.4/Tools/dsig.ttx" to "/Users/adrianshome/Downloads/fonttools-2.4/Tools/dsig.ttf"...
Parsing 'DSIG' table...
Dumping "/Users/adrianshome/Downloads/fonttools-2.4/Tools/SassoBoo.ttf" to "/Users/adrianshome/Downloads/fonttools-2.4/Tools/SassoBoo.ttx"...
Dumping 'GlyphOrder' table...
Dumping 'head' table...
Dumping 'hhea' table...
Dumping 'maxp' table...
Dumping 'OS/2' table...
Dumping 'hmtx' table...
Dumping 'LTSH' table...
Dumping 'VDMX' table...
Dumping 'hdmx' table...
Dumping 'cmap' table...
Dumping 'fpgm' table...
Dumping 'prep' table...
Dumping 'cvt ' table...
Dumping 'loca' table...
Dumping 'glyf' table...
wDumping 'kern' table...
Dumping 'name' table...
Dumping 'post' table...
Dumping 'gasp' table...
Dumping 'GPOS' table...
Dumping 'GSUB' table...

- - - - - - - - -
Can you please explain the steps something like this so that I understand the process. This is what I did in Terminal:

Enter which ttx, Return.
Drag ttx app to Terminal (displays the path to the app).
Drag dsig.ttx to Terminal (displays the path to the text file).
Drag SassoBoo.ttx file to Terminal (displays actual TrueType font file path).
Return.
Compiling begins... (result is a dsig.ttf file).

The ttx you dragged is not the ttx returned by which ttx so I don't know if your /usr/local/bin/ttx is 2.3 or 2.4. Anyway here are the steps to get "ttx -m font.ttf dsig.ttx" with that kind of recipe. First remove all of the dsig.ttf files you got. Then for each font file

1. drag ttx app to terminal (since it appears to have accepted your snippet)
2. type -m
3. drag the ttf font file to terminal (say SassoBoo.ttf)
4. drag dsig.ttx to terminal
5. return

That will compile only dsig.ttx, merge the DSIG into SassoBoo.ttf and produce a file named dsig.ttf; so here is point 6

6. rename dsig.ttf as SassoBoo something.ttf

There are much better ways to proceed using scripts.

PS Don't switch steps 3 and 4. You need to put the .ttf file before the .ttx file.

Well, it worked. I install the resulting TrueType font in Windows and have access to its features - hooray!

But I then instead of deleting just dsig.ttf files, I deleted the 'Dsig fldr' from the Desktop and tried again but no joy. Now I cannot get the Dsig fldr back again. Reinstating it does not work either. How do I create the Dsig fldr again? I'm guessing that's why the same routine won't work again?

Scratch that - have created it again and am trying to duplicate the first result... No joy "Permission denied".

Pasted the snippet again and got the Dsig fldr back. But the routine won't work now. Aaarrrggghhh!!!

Think it works now. I did not have a space after "-m" and a trigger-happy Return key messed things up.


adrians-imac:Dsig fldr adrianshome$ /Users/adrianshome/Downloads/fonttools-2.4/Tools/ttx -m /Users/adrianshome/Desktop/Dsig\ fldr/SassoBooIta.ttf /Users/adrianshome/Desktop/Dsig\ fldr/dsig.ttx
Compiling "/Users/adrianshome/Desktop/Dsig fldr/dsig.ttx" to "/Users/adrianshome/Desktop/Dsig fldr/dsig.ttf"...
Parsing 'DSIG' table...
adrians-imac:Dsig fldr adrianshome$

After this, renaming the dsig.ttf file makes the font work in Windows. Thank you so much. Just to be able to get 'features' working in TT fonts , no-matter how its done is a great relief. There may be more elegant ways to do this, like a batch process as I have 70 fonts to do, but I'm a happy. So here's my final routine:

1. Launch Terminal.

2. Type ‘which ttx’, Return:
/usr/local/bin/ttx
adrians-imac:Dsig fldr adrianshome$

3. Drag TTX app to Terminal (since it accepted your Dsig fldr snippet):
/Users/adrianshome/Downloads/fonttools-2.4/Tools/ttx

4. Type: -m (not forgetting a space after the m).
/Users/adrianshome/Desktop/Dsig\ fldr/SassoBooIta.ttf /Users/adrianshome/Desktop/Dsig\ fldr/dsig.ttx

First remove all of the dsig#.ttf files in the Dsig fldr if there are any.
Then for each font file:

5. Drag the ttf font file to Terminal (say SassoBoo.ttf)

6. Drag dsig.ttx to terminal

7. Return

That will compile only dsig.ttx, merge the DSIG into SassoBoo.ttf and produce a file named dsig.ttf in the Dsig fldr, so now…

8. Rename dsig.ttf as SassoBoo something.ttf (original TrueType filename something)

Don't switch steps 3 and 4. You need to put the .ttf file before the .ttx file.

You shouldn't need to type "which ttx" and drag ttx onto the terminal every time you use ttx. If ttx is installed properly, you should be able to just type "ttx" at the prompt, followed by whatever stuff you want to do with it.

You can test whether you have it installed properly by typing "ttx -h" at the command prompt. If you get "command not found", then it's not installed properly. If you get the ttx help text, then it should work to just type "ttx" at the prompt, etc.

Mark, there is a ttx that is installed but there are at least two versions of ttx on his system. There is ttx 2.4 in ~/Downloads/fonttools-2.4/Tools and there is some other ttx in /usr/local/bin. If ttx is typed directly in the terminal window it is /usr/local/bin/ttx that will be executed and if that ttx is not ttx 2.4 then the dsig.ttx file will be incompatible. Executing

ttx -h | head -4

should however give the version.

To be sure that the ttx 2.4 in Downloads is executed when ttx is called from a terminal window, ${HOME}/Downloads/fonttools-2.4/Tools need to be put before /usr/local/bin in his PATH and such things are tricky for newbies.

Ah, right. Ugh.

It is possible to do it with the more recent version of ttx, as Ben Kiel's comment at TypeDrawers shows:

http://typedrawers.com/discussion/comment/9651/#Comment_9651

He made me a script that incorporates this, so I know it works, but it's a bit above my head (which is why I hired him to do it for me).

Another way is to define a variable TTX that contains the full path of the application. For instance, to handle 70 fonts in some folder with Adrian's current configuration, what can be done is this (make sure there is no dsig.ttf font in those 70 fonts).

1. type cd with a space in the terminal window
2. drag the folder (not the fonts) containing the ttf fonts in the terminal window
3. return

4. paste the following lines in the terminal window

FLDR="$HOME/Desktop/Dsig fldr"
TTX=$HOME/Downloads/fonttools-2.4/Tools/ttx 
for i in *.ttf 
do 
  DSIG="$FLDR/${i%.ttf}.ttx"
  cp "$FLDR"/dsig.ttx "$DSIG"
  $TTX -m $i "$DSIG"
  rm -f "$DSIG"
done

5. return

The 70 font files should now be in Dsig fldr with the name they previously had but with a DSIG thing.

The dsig.ttx snippet you have on typedrawers is however different from the one I got after decompiling the dummy DSIG produced by (an old version of) fontforge using ttx 2.4. I have no clue what the "right" snippet should be but what I got seems to be working for Adrian.*

To be complete, I should add that it is assumed that the Dsig folder already exists on the desktop and contains dsig.ttx for ttx 2.4. Such a folder had previously been created by pasting in a terminal window the following lines

FLDR="${HOME}/Desktop/Dsig fldr"
mkdir -p "$FLDR"
cd "$FLDR"
cat > dsig.ttx<<EOF
<?xml version="1.0" encoding="utf-8"?>
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="2.4">
  <DSIG>
    <tableHeader flag="0x0" numSigs="0" version="1"/>
  </DSIG>
</ttFont>
EOF

*That is also the ttx file I get when I decompile with ttx 2.4 the dummy signature generated by ttx 2.3 using the previous dsig.ttx file.

And at this moment I feel tempted to suggest a reference and tutorial on shell scripts...

http://www.vectorsite.net/tsshell.html and http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html are the beginners’ guides I currently have on file.

http://tldp.org/LDP/abs/html/index.html is an intermediate/advanced guide.

Some of this (http://rute.2038bug.com/) may be applicable on BSD-type systems as well.

I have another 100 or so to do also, so will get into your batch processing method later Té - thanks. But right now - Having complied about a dozen fonts using Michel's method a couple of fonts complied into two files: font.ttf (of 36k) and font.ttx (of 1.2 Mb). Instead of compiling and parsing it's now 'Dumping'. Any ideas why are these compiling differently?

adrians-imac:~ adrianshome$ /Users/adrianshome/Downloads/fonttools-2.4/Tools/ttx /Users/adrianshome/Desktop/Dsig\ fldr/SassoMonMed.ttf /Users/adrianshome/Desktop/Dsig\ fldr/dsig.ttx
Dumping "/Users/adrianshome/Desktop/Dsig fldr/SassoMonMed.ttf" to "/Users/adrianshome/Desktop/Dsig fldr/SassoMonMed.ttx"...
Dumping 'GlyphOrder' table...
Dumping 'head' table...
Dumping 'hhea' table...
Dumping 'maxp' table...
Dumping 'OS/2' table...
Dumping 'hmtx' table...
Dumping 'LTSH' table...
Dumping 'VDMX' table...
Dumping 'hdmx' table...
Dumping 'cmap' table...
Dumping 'fpgm' table...
Dumping 'prep' table...
Dumping 'cvt ' table...
Dumping 'loca' table...
Dumping 'glyf' table...
Dumping 'kern' table...
Dumping 'name' table...
Dumping 'post' table...
Dumping 'gasp' table...
Dumping 'GPOS' table...
Dumping 'GSUB' table...
Compiling "/Users/adrianshome/Desktop/Dsig fldr/dsig.ttx" to "/Users/adrianshome/Desktop/Dsig fldr/dsig.ttf"...
Parsing 'DSIG' table...
adrians-imac:~ adrianshome$

you forgot to type -m.

That is another reason batch commands are better; they are less prone to "typos".

Ooops! Back on track now. Thanks for pointing that out. When I've finished this clutch of fonts I'll investigate batch commands.

Captured from web.archive.org on 27 Oct 2014. view this capture