Enabling the TTF Font 'Embeddable' Permission

A couple of weeks ago I was ramping up on HTML5/JS/CSS, and building a little Windows 8 App to get used to the syntax. I was building a Team Fortress 2 Backpack Viewer, and wanted to use the official TF2 Build Font for a bit of fun flavour.

The Problem

However, no matter what I tried, the font would not work in the Windows 8 Application.

The error I was getting was:

CSS3114: @font-face failed OpenType embedding permission check. Permission must be Installable.

The weird thing is, I know that there are sites out there that use the font, and it seemed to be working perfectly. So why was I getting this error and they weren't? Why did it work in the browser, but not a Windows 8 Application?

TTF Font Permission levels

TTF, or TrueType Format fonts have permission levels embedded into the font file itself, as a way for the font author to control the use of their font. These font levels are:

  1. No Embedding (The strictest)
  2. View and Print (You can view/print a document using the font, but can't edit/type with it yourself)
  3. View, Print and Edit (The default, and what most people would be used to in terms of using fonts in Office products and document editing)
  4. View, Print, Edit and Install (You can provide the font along with your program so that it can be used)
Web Browsers and TTF Fonts

So the font worked on TF2 Backpack Examiner, in Mozilla Firefox, Google Chrome, and Opera:

TF2 Build - Font working in Mozilla Firefox

However, It did not work in Internet Explorer or Microsoft Edge, instead defaulting to the browser's fallback font in both cases. Taking a look at the TF2 Backpack Examiner website with the Javascript console open, you can see the exact same error message as I was getting:

CSS3114: @font-face failed OpenType embedding permission check. Permission must be Installable.

So it seems that the Microsoft Browsers (and by extension, HTML 5 Win 8 Apps) actually respect the 'embeddable' permission level, whereas other browsers don't, and no other TF2 site seems to have solved the issue, resorting to using either images of textual content, or blithely ignoring Internet Explorer users (and why wouldn't you?). But that didn't help me or my dreams of a Windows 8 TF2 Backpack App, so I thought there had to be a better solution.

The Solution

Being unable to find a version of the font that had the embeddable flag set on DaFont, in the TF2 folder itself, or elsewhere, I had to resort to changing the permission level on the font file in order to get it to work. I searched around and tried a few different solutions before stumbling across Tom7's Embeddable Font solution.

Unfortunately the executable he provided was 16-bit, which won't natively work on a 64-bit Windows 8.1 PC. Luckily he provided the code in C, which I was able to convert and recompile using Visual C++ into a native Win32 executable.

Downloads

You can download the Win32 executable:
EmbedTTF.exe (13KB)

The code file:
EmbedTTF.cpp (4KB)

Or the entire zipped Visual C++ Project:
EmbedTTF.7z (2,252KB)

Usage

The program will overwrite the same file as you provide it, so make a backup copy of your font file first. Then either drag and drop your font file onto the executable, or from the command line run:

EmbedTTF.exe <nameOfYourFontFile.ttf>

The code

In case the files are not available, here is the code inlined for your convenience:

#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
using namespace std;

void fatal();

int main(int argc, char**argv) {
	FILE * inways;
	if (argc != 2) {
		cout << "Usage: " << argv[0] << " font.ttf\n" << endl;
		cout << "Public Domain software - Tom 7." << endl;
		cout << "\nRebuilt for 32-bit systems By Ryan Worthington." << endl;
		cout << "Use at your own risk." << endl;
	}
	else if (inways = fopen(argv[1], "rb+")) {
		int x;
		char type[5];
		type[4] = 0;
		fseek(inways, 12, 0);
		for (;;) 
		{
			for (x = 0; x < 4; x++) {
				type[x] = getc(inways);
				if (EOF == type[x])
					fatal();
			}

			if (!_tcscmp((const char*)type, (const char*)"OS/2"))
			{
				int length;
				unsigned long checksumLocation, fstype, sum = 0;
				checksumLocation = ftell(inways);
				for (x = 4; x--;) {
					if (EOF == getc(inways))
						fatal();
				}
				fstype = fgetc(inways) << 24;
				fstype |= fgetc(inways) << 16;
				fstype |= fgetc(inways) << 8;
				fstype |= fgetc(inways);
				length = fgetc(inways) << 24;
				length |= fgetc(inways) << 16;
				length |= fgetc(inways) << 8;
				length |= fgetc(inways);
				//printf("fstype: %d length: %d\n",fstype,length);

				if (fseek(inways, fstype + 8, 0)) 
					fatal();

				fputc(0, inways);
				fputc(0, inways);
				fseek(inways, fstype, 0);
				for (x = length; x--;)
					sum += fgetc(inways);

				//Write Checksum
				fseek(inways, checksumLocation, 0);
				fputc(sum >> 24, inways);
				fputc(255 & (sum >> 16), inways);
				fputc(255 & (sum >> 8), inways);
				fputc(255 & sum, inways);

				fclose(inways);
				cout << "File Updated successfully" << endl;
				exit(0);
			}

			for (x = 12; x--;) {
				if (EOF == getc(inways)) {
					fatal();
				}
			}
		}
	}
	else {
		cout << "I wasn't able to open the file " << argv[1] << endl;
	}

	return 0;
}    

void fatal() {
	cerr << "Malformed TTF file." << endl;
	exit(-1);
}

Enjoy!

Licensing & Caveats

The original code and executable on Tom's site is provided in the Public Domain, as is the executable, code and solution files I've provided here, so feel free to use and modify them freely in that regard. Having said that, Tom7 has had to fight DMCA Takedown notices for his embed program before, therefore I will clarify some points of contention:

  • This article (and the writing of) is a purely academic exercise in order to share knowledge and learn more about TTF fonts how they are created. The TrueType format (TTF) is a public specification developed by Apple Computer and Microsoft Corporation; and anyone can write programs that manipulate or create TrueType fonts.

  • Flipping embedding bits does nothing to keep consumers from copying/distributing fonts and therefore is not a 'Technological Measure' of Digital Rights Management (DRM) or otherwise a means of 'enforcing copyright'. Embed bits simply inform other programs (browsers, documents etc) how to use the font, it is up to those programs to honor those embed permissions.

  • This program (and Tom7's original) have substantial commercially significant use in font creation businesses and communities. It is not primarily designed or produced as a 'circumvention tool'. My updated version is provided for newer systems, as due to technical limitations outlined in the article, Tom7's is no longer supported on newer versions of Microsoft Windows.

For any other concerns please see Tom7's correspondence with Stack & Filpi Chtd and the associated DMCA Takedown notice on lumendatabase.org (formerly chillingeffects.org). Note that as of writing, Tom7's page is still up and the program available, despite these legal matters back in 2002.

Final Words

I will not be providing the TF2 Build font, sorry. I am not the license holder therefore I do not have the rights to redistribute it. It was used in this article as an example only (and my Windows 8 app was purely for learning and probably won't be released): You should only change this embedded permission level if you are the font creator, own the license to the font, or have been given explicit permission from the license holder to do so. Use at your own risk.