Skip to content

Instantly share code, notes, and snippets.

@rbrito rbrito/dejavubb.sty
Created Oct 22, 2011

Embed
What would you like to do?
Generation of a TeX font with fontforge
%% Stolen from the bbold package.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{dejavubb}[2011/10/08 dejavubb package]
\newcommand{\bbfamily}{\fontencoding{T1}\fontfamily{dejavubb}\selectfont}
\newcommand{\textbb}[1]{{\bbfamily#1}}
\DeclareMathAlphabet{\mathbb}{T1}{dejavubb}{m}{n}
\endinput
\input fontinst.sty
\latinfamily{fdj}{}
\bye
#!/usr/bin/env python
import glob
import os
import os.path
import subprocess
import sys
import fontforge
### Definition of constants
FNT_NAME = 'dejavubb'
FNT_BERRY_NAME = 'fdjr8a'
FNT_EXTENSION = 'pfb'
FNT_CONF_FILE = FNT_NAME + '.cfg'
FNT_MAP_FILE = FNT_NAME + '.map'
PATH_PREFIX = os.path.join('texmf', 'fonts')
PATH_SUFFIX = os.path.join('public', FNT_NAME)
file_placement = {
'*.afm': 'afm',
'*.fd': 'latex',
'*.pf*': 'type1',
'*.tfm': 'tfm',
'*.vf': 'vf',
}
### Auxiliary functions
def create_type1(font_source):
'''Create Type 1 font from the source font.'''
font = fontforge.open(font_source)
font.generate(FNT_BERRY_NAME + '.pfb')
font.close()
def call_fontinst():
'''Create tex-specific font files.'''
subprocess.call(['tex', 'tex/generator'])
for f in glob.iglob('*.vpl'):
subprocess.call(['vptovf', f])
for f in glob.iglob('*.pl'):
subprocess.call(['pltotf', f])
def create_texmf():
'''Create the texmf directory tree.'''
for component in ['afm', 'tfm', 'type1', 'latex', 'vf']:
os.makedirs(os.path.join(PATH_PREFIX, component, PATH_SUFFIX))
os.makedirs(os.path.join(PATH_PREFIX, 'map', 'dvips', FNT_NAME))
def populate_texmf():
'''Move files to appropriate subdirs of the texmf tree.'''
for what, where in file_placement.iteritems():
for file in glob.iglob(what):
os.rename(file, os.path.join(PATH_PREFIX, where, PATH_SUFFIX, file))
def clean_aux_files():
globs = ['*.vpl', '*.mtx', '*.pl', '*.log']
for what in globs:
for file in glob.iglob(what):
os.unlink(file)
# print 'fdjr8r dejavubb " TeXBase1Encoding ReEncodeFont " <8r.enc <fdjr8a.pfb' \
# > os.path.join(PATH_PREFIX, "map", "dvips", FNT_NAME, FNT_MAP_FILE)
# print "Map " + FNT_MAP_FILE > FNT_CONF_FILE
# user_dir = os.path.expanduser(os.path.join('~', '.texmf-config', 'updmap.d'))
# os.makedirs(user_dir)
# os.rename(FNT_CONF_FILE, os.path.join(user_dir, FNT_CONF_FILE))
# print "Don't forget to move the texmf directory to an appropriate place and, then,"
# print "to call 'update-updmap && updmap'."
if __name__ == "__main__":
create_type1('sfd/dejavubb.sfd')
call_fontinst()
create_texmf()
populate_texmf()
clean_aux_files()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.