Skip to content

Commit

Permalink
Added external font definition and map files to enable dvi and ps sup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
xdanaux committed Jul 31, 2015
1 parent 23d7d5d commit d2903c8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 17 deletions.
58 changes: 49 additions & 9 deletions generate_tex_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
import argparse
import sys
import subprocess
import datetime
import re
import os, shutil
import fontforge

DEBUG=False;

COPYRIGHT="""\
%% Copyright 2015 Xavier Danaux ([email protected]).
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License version 1.3c,
% available at http://www.latex-project.org/lppl/.
""";

numbers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'];

pdftex_replace = {
Expand Down Expand Up @@ -498,8 +508,9 @@ def recurse_dictionary (dictionary, key):
ENC = "./"; #"texmf/fonts/enc/pdftex/public/fontawesome"
T1 = "./"; #"texmf/fonts/type1/public/fontawesome"
OTF = "./"; #"texmf/fonts/opentype/public/fontawesome"
MAP = "./"; #"texmf/fonts/map/dvips/fontawesome/"

for path in [TFM, ENC, T1, OTF]:
for path in [TFM, ENC, T1, OTF, MAP]:
os.makedirs(path, exist_ok=True);

# generate the t1 files
Expand All @@ -514,32 +525,61 @@ def recurse_dictionary (dictionary, key):
'--encoding-directory=' + ENC,
'--type1-directory=' + T1];
mapline = subprocess.check_output(command, stderr=otftotfm_errors, universal_newlines=True).strip();
maplines.append("\\pdfmapline{{+{}}}".format(mapline));
maplines.append("\\DeclareFontFamily{{U}}{{fontawesome{}}}{{}}".format(numbers[i]));
maplines.append("\\DeclareFontShape{{U}}{{fontawesome{}}}{{m}}{{n}}{{<->FontAwesome--fontawesome{}}}{{}}".format(numbers[i], numbers[i]));
maplines.append("\\DeclareRobustCommand{{\\FA{}}}{{\\usefont{{U}}{{fontawesome{}}}{{m}}{{n}}}}".format(numbers[i], numbers[i]));
# maplines.append("\\pdfmapline{{+{}}}".format(mapline));
# maplines.append("\\DeclareFontFamily{{U}}{{fontawesome{}}}{{}}".format(numbers[i]));
# maplines.append("\\DeclareFontShape{{U}}{{fontawesome{}}}{{m}}{{n}}{{<->FontAwesome--fontawesome{}}}{{}}".format(numbers[i], numbers[i]));
# maplines.append("\\DeclareRobustCommand{{\\FA{}}}{{\\usefont{{U}}{{fontawesome{}}}{{m}}{{n}}}}".format(numbers[i], numbers[i]));
maplines.append(mapline);
os.rename(encfile_name, os.path.join(ENC, encfile_name));
if OTF is not "./":
shutil.copy(FONT, os.path.join(OTF, FONT));
except:
sys.exit("[Error] Can't run otftotfm: {}".format(sys.exc_info()[1]))
sys.exit("[Error] Can't run otftotfm: {}".format(sys.exc_info()[1]));
otftotfm_errors.close();

# write the maplines to the package file
# generate the map file
map_filename = 'fontawesome.map';
map = open(os.path.join(MAP, map_filename), 'w');
map.write("%% start of file `{}'.\n".format(map_filename));
map.write(COPYRIGHT);
map.write("\n".join(maplines) + "\n");
map.write("\n%% end of file `{}'.\n".format(map_filename));
map.close();

# generate the font definition (.fd) files
for i in range(1, encfile_count+1):
fd_filename = 'ufontawesome{}.fd'.format(numbers[i]);
fd = open(fd_filename, 'w');
fd.write("%% start of file `{}'.\n".format(fd_filename));
fd.write(COPYRIGHT);
fd.write("\\ProvidesFile{{{}}}[{:%Y/%m/%d} Font definitions for U/fontawesome{}.]\n\n".format(fd_filename, datetime.date.today(), numbers[i]));
fd.write("\\DeclareFontFamily{{U}}{{fontawesome{}}}{{}}\n".format(numbers[i]));
fd.write("\\DeclareFontShape{{U}}{{fontawesome{}}}{{m}}{{n}}{{<-> FontAwesome--fontawesome{}}}{{}}\n\n".format(numbers[i], numbers[i]));
fd.write("\\endinput\n");
fd.write("\n%% end of file `{}'.\n".format(fd_filename));
fd.close();

# add the \FA... font definitions to the package file
with open('templates/fontawesome.sty.template', 'r') as template, open('fontawesome.sty', 'w') as sty:
for line in template:
if line == "% <maplines go here>\n":
sty.write('\n'.join(maplines) + "\n");
# sty.write('\n'.join(maplines) + "\n");
for i in range(1, encfile_count+1):
sty.write("\\DeclareRobustCommand\\FA{}{{\\fontencoding{{U}}\\fontfamily{{fontawesome{}}}\selectfont}}\n".format(numbers[i], numbers[i]));
# sty.write("\\newcommand*\\FA{}{{\\fontencoding{{U}}\\fontfamily{{fontawesome{}}}\selectfont}}\n".format(numbers[i], numbers[i]));
else:
sty.write(line);
template.close();
sty.close();

# generate the tex symbols list file
# ------------------------------------------------------------------------------
symbols = open('fontawesomesymbols-pdftex.tex', 'w');
symbols_filename = 'fontawesomesymbols-pdftex.tex';
symbols = open(symbols_filename, 'w');
symbols.write("%% start of file `{}'.\n".format(symbols_filename));
for glyph_count, glyph_name in enumerate(pdftex_glyphs_names):
symbols.write("\\expandafter\\def\\csname faicon@{}\\endcsname{{{{\\FA{}\\symbol{{{}}}}}}}\n".format(glyph_name, numbers[glyph_count//256 +1], glyph_count % 256));
symbols.write("\n%% end of file `{}'.\n".format(symbols_filename));
symbols.close();
print(" done");

Expand Down
2 changes: 1 addition & 1 deletion templates/fontawesome.sty.template
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
\input{fontawesomesymbols-xeluatex.tex}

%-------------------------------------------------------------------------------
% pdflatex implementation
% (pdf)latex implementation
%-------------------------------------------------------------------------------
\else
% definition of \FA... as a shortcut to load the Font Awesome font
Expand Down
15 changes: 8 additions & 7 deletions templates/fontawesome.tex.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

\documentclass{ltxdoc}
%\GetFileInfo{\jobname.sty}
\def\fileversion{4.3.0-1}
\def\filedate{July 10, 2015}
\def\fileversion{4.3.0-2}
\def\filedate{July 30, 2015}
\usepackage{lmodern}
\usepackage[numbered]{hypdoc}
\usepackage{hologo}
Expand All @@ -34,14 +34,15 @@
\begin{abstract}
The \textsf{\jobname} package grants access to 519 web-related icons provided by the included \emph{Font Awesome} free font, designed by Dave Gandy and released\footnote{See \url{http://fortawesome.github.com/Font-Awesome} for more details about the font itself} under the open SIL Open Font License\footnote{Available at \url{http://scripts.sil.org/OFL}.}.

This package works both with \hologo{Xe}\hologo{(La)TeX} and Lua\hologo{(La)TeX} (using \textsf{fontspec} to load the included original \textsf{otf} font), as well as pdf\hologo{(La)TeX} (using an included \textsf{type1} conversion and character mapping of the font).
This package works both with \hologo{Xe}\hologo{(La)TeX} and Lua\hologo{(La)TeX} (using \textsf{fontspec} to load the included original \textsf{otf} font), as well as (pdf)\hologo{(La)TeX} (using an included \textsf{type1} conversion and character mapping of the font).
\end{abstract}

\changes{v4.3.0-2}{2015/07/30}{Corrected the (pdf)\hologo{(La)TeX} font definitions to enable proper scaling, and enabled dvi/ps support.}
\changes{v4.3.0-1}{2015/07/10}{Converted the otf font to 1000upm to avoid a bug within xdvipdfmx.}
\changes{v4.3.0} {2015/07/07}{Update to match Font Awesome version 4.3.0, with a total of 519 icons.}
\changes{v4.3.0} {2015/07/07}{Update to match Font Awesome version 4.3.0, with a total of 519 icons, and enabled pdf\hologo{(La)TeX} support.}
\changes{v3.1.1} {2013/05/10}{Update to match Font Awesome version 3.1.1, with 53 new icons.}
\changes{v3.0.2-1}{2013/03/23}{Bigfix release: corrected the swap of the \cs{text-height} and \cs{text-width} icons.}
\changes{v3.0.2} {2013/03/21}{First public release (version number set to match the included FontAwesome.otf font version).}
\changes{v3.0.2-1}{2013/03/23}{Corrected the swap of the \cs{text-height} and \cs{text-width} icons.}
\changes{v3.0.2} {2013/03/21}{First public release (version number set to match the included FontAwesome.otf font version), requiring \hologo{Xe}- or Lua\hologo{(La)TeX}.}
\makeatletter
\let\PrintMacroName@original\PrintMacroName
%\let\PrintDescribeMacro\@gobble
Expand Down Expand Up @@ -94,7 +95,7 @@ pictograms.
It is a redistribution of the free (as in beer) \emph{Font Awesome} font with specific bindings for \hologo{(La)TeX}.

\section{Requirements}
The \textsf{\jobname} package requires the \textsf{fontspec} package when using the \hologo{Xe}\hologo{(La)TeX} or Lua\hologo{(La)TeX} engines to load the included otf font. When using the pdf\hologo{(La)TeX} engine, the \textsf{\jobname} package doesn't require any external package.
The \textsf{\jobname} package requires the \textsf{fontspec} package when using the \hologo{Xe}\hologo{(La)TeX} or Lua\hologo{(La)TeX} engines to load the included otf font. When using the (pdf)\hologo{(La)TeX} engine, the \textsf{\jobname} package doesn't require any external package.

\section{Usage}
\DescribeMacro{\faicon}
Expand Down

0 comments on commit d2903c8

Please sign in to comment.