\documentclass[a4paper,11pt]{article}
\usepackage{rojud}
\title{rojud \\[.25cm]
    \normalsize{a Type-1 Font for the 42 counties of Romania}
}
\author{Vlad Bazon\footnote{\texttt{vlad.bazon@gmail.com}}
}
\date{\normalsize{November 2020}}

    \newcommand{\setFont}[1]{\fontfamily{#1}\selectfont}
    \newcommand\Sj[1]{\setFont{rojud}\Huge\paintt{#1}}
    \newcommand\Sn[1]{\footnotesize\texttt{#1}}

\usepackage{ifthen}

\usepackage[no-math]{fontspec}
\setmainfont{texgyrepagella-regular.otf}[
    BoldFont = texgyrepagella-bold.otf ,
    ItalicFont = texgyrepagella-italic.otf ,
    BoldItalicFont = texgyrepagella-bolditalic.otf,
    Scale=MatchUppercase,
    Mapping=tex-text 
]
\setsansfont{texgyreheros-regular.otf}[
    BoldFont = texgyreheros-bold.otf,
    ItalicFont = texgyreheros-italic.otf,
    BoldItalicFont = texgyreheros-bolditalic.otf,
    SmallCapsFont = texgyreheroscn-regular.otf,
    SmallCapsFeatures={Letters=SmallCaps},
    Scale=1 
]
\setmonofont{DejaVu Sans Mono}[Scale=MatchLowercase]
\strongfontdeclare{\bfseries,\fontseries{m}\selectfont}

\begin{document}
\maketitle

\begin{abstract}
The idea of a font with the "images" of a given set of geographic regions is seeded in the \textsf{CountriesOfEurope} font (see \cite{CoE}), which---as other about 3700 Type-1 fonts in TexLive distribution---is stamped as "\emph{\% Generated by FontForge}". But how one can \emph{construct} a such font? We describe and apply a general procedure for that.
\end{abstract}

\section{The counties as glyphs}

From \textsf{GADM} (\cite{GADM}) we obtain the administrative map of the country, as a \emph{shapefile} file; this file contain ''polygons'' for each county, which are closed \emph{paths} {\small(speaking as in Postscript)} expressed in geographic coordinates. With a \strong{R} program (\cite{R}), using the \strong{\textsf{sp}} package, we extract the counties contours and project them to cartezian coordinates by \textsf{UTM}\footnote{https://en.wikipedia.org/wiki/Universal\_Transverse\_Mercator\_coordinate\_system} {\small(having into account that not all counties maps to the same \textsf{UTM}-zone)}. The respective paths usually contains very many points {\small(and we will have to keep in mind the Postscript \textsf{\emph{limitcheck}} barrier)}; so we use the javaScript \strong{\textsf{mapshaper}} library (\cite{mapshaper}) for to simplify the contours {\small(in the Romania case is sufficient 18\% of the initial vertices)}.

The contours so obtained could be traced or painted in a Ghostscript session, using \texttt{moveto} and \texttt{lineto}; but in the Type-1 font-file we need to use the relative alternative of these, \texttt{rmoveto} and \texttt{rlineto}. So by a \strong{R} program we transform the coordinates matrix of each contour, replacing each line with its difference from the previous one; therewith by this \strong{R} program, we formulate a ''\textsf{.raw}'' file, in which we write these matrixes completed on every line by a "rlineto" word {\small(excepting the first line, where we have "rmoveto", and the last line which is replaced by word "closepath")}. 

More precisely, in this ''\textsf{.raw}'' file we obtain, for each county, the needed glyph definition in the terms of the Type-1 format, for example:

{\small  
\begin{verbatim}
/jAB { % judeţul Alba (Alba county)
0 1204 hsbw  % "horizontal sidebearing and width"
74881 100 div 4378 100 div rmoveto
-634 100 div -958 100 div rlineto
-492 100 div -105 100 div rlineto
    % etc.
861 100 div -86 100 div rlineto
1067 100 div 293 100 div rlineto
closepath
endchar
} ND  %% total: 979 rows
\end{verbatim}
}

Then we insert in this ''\textsf{.raw}'' file the \texttt{/CharStrings} dictionary definition, the \texttt{/Encoding} definition, etc. -- having at beginning {\small(see \cite{PLRM})}:

{\small
\begin{verbatim}
7 dict begin
/FontType 1 def
/FontMatrix [0.001 0 0 0.001 0 0] readonly def
/FontName /rojud def
/FontBBox {0 0 1776 1375} readonly def
/PaintType 0 def
\end{verbatim}
}

and ending the ''\textsf{.raw}'' file {\small(about 77700 lines)} by:

{\small
\begin{verbatim}
end end
readonly put
put
dup/FontName get exch definefont pop
mark currentfile closefile
cleartomark
\end{verbatim}
}

From this ''\textsf{.raw}'' file we obtain the desired \textsf{.pfb} file, using the \strong{\textsf{t1asm}} program (\cite{t1asm}).

\smallskip
Using \textsf{pf2afm.ps} from \cite{GS} {\small(or an ''on-line converter'')} we obtain the corresponding metric file ''\textsf{.afm}'', from which using \textsf{afm2pl} and \textsf{pltotf}, we obtain the needed for TeX metric file ''\textsf{.tfm}''. For the package definition of the new font what else is needed is to add the ''\textsf{.fd}'' and ''\textsf{.sty}'' files; of course, these files {\small(\texttt{.pfb}, \texttt{.tfm}, \texttt{.map}, \texttt{.fd} and \texttt{.sty})} must be incorporated in the appropriate places of the TeXLive directory structure.

\smallskip
Actually we add two minimal ''\textsf{.fd}'' files, ''\texttt{TUrojud.fd}'' for \textsf{xelatex} and ''\texttt{OT1rojud.fd}'' for \textsf{pdflatex}; in the ''\textsf{.sty}'' file we separate by these cases the symbol declarations and we add a single new command, ''\texttt{\textbackslash{}paintt}'', which use the \texttt{\textbackslash{}special} TeX primitive for to paint the glyph in the PDF ''\emph{FillAndStroke}'' rendering mode {\small(but fixing the colours, at a perhaps decent level)}.

\section{Tests (simple examples)}

We don't see a practical use for such a font, whose glyphs shape some geographical regions\ldots{} the interesting issue is their very definition in the font file, described above.

\smallskip
But for simple tests or some examples, consider in the preamble of a LaTeX file \texttt{usepackage\{rojud\}} and let's say, these simplifying commands:

{\small
\begin{verbatim}
    \newcommand{\setFont}[1]{\fontfamily{#1}\selectfont}
    \newcommand\Sj[1]{\setFont{rojud}\Huge\paintt{#1}}
    \newcommand\Sn[1]{\footnotesize\texttt{#1}}
\end{verbatim}
}

It is easy to write a litle Python script to generate a TeX file "rows.tex", giving the rows and columns {\small(with cells \texttt{\textbackslash{}Sj} and \texttt{\textbackslash{}Sn}, applied to glyphs)} of a \texttt{\textbackslash{}tabular} environment; then \texttt{\textbackslash{}include rows.tex} in this environment of the initial LaTeX file {\small(see the TeX source of this document)}, to present the glyphs as follows:

{\centerline{Fontul \textbf{rojud} {\small(judeţele României)}}}
\fbox{
\begin{tabular}{*{7}{c}}
    \input{rows.tex}
\end{tabular}
}

\bigskip 
Repeating \verb!{\fbox{\paintt{\symbol{\value{N}}}}}!, with \texttt{N} from 167 to 208 {\small(the codes from the \texttt{/Encoding} table of the font)} we could produce the glyphs engraved in his bounding boxes {\small(here with \verb!\huge!)}:

\smallskip
{
\setFont{rojud}
\fboxsep=0pt
\newcounter{N}
\setcounter{N}{167}
\huge\noindent
\whiledo{\value{N}<181}{%
    \fbox{\paintt{\symbol{\value{N}}}}%
    \stepcounter{N}}%
\par\smallskip\noindent
\whiledo{\value{N}<195}{%
    \fbox{\paintt{\symbol{\value{N}}}}%
    \stepcounter{N}}%
\par\smallskip\noindent
\whiledo{\value{N}<209}{%
    \fbox{\paintt{\symbol{\value{N}}}}%
    \stepcounter{N}}%
}

\medskip
Lastly, we produce a litle paragraph of text---in romanian language, at \verb!\small!, \verb!\normalsize! and \verb!\large!---integrating a few glyphs:

\renewcommand\Sj[1]{{\fontfamily{rojud}\selectfont\paintt{#1}}}

\smallskip 
{\small
,,\paintt{Judeţul Iaşi} \Sj{\jIS} se învecinează cu judeţele Botoşani \Sj{\jBT} spre nord, Suceava \Sj{\jSV} spre nord-vest, Neamţ \Sj{\jNT} spre vest şi cu Vaslui \Sj{\jVS} spre sud.''}

\smallskip
{\normalsize
,,\paintt{Judeţul Iaşi} \Sj{\jIS} se învecinează cu judeţele Botoşani \Sj{\jBT} spre nord, Suceava \Sj{\jSV} spre nord-vest, Neamţ \Sj{\jNT} spre vest şi cu Vaslui \Sj{\jVS} spre sud.''}

\smallskip
{\large
,,\paintt{Judeţul Iaşi} \Sj{\jIS} se învecinează cu judeţele Botoşani \Sj{\jBT} spre nord, Suceava \Sj{\jSV} spre nord-vest, Neamţ \Sj{\jNT} spre vest ...''}

\smallskip
\renewcommand\Sj[1]{{\setFont{rojud}{#1}}}
{\noindent\normalsize
,,\emph{The neighboring counties with \Sj{\jIS} are: \Sj{\jBT}, \Sj{\jSV}, \Sj{\jNT} and \Sj{\jVS}.}''}

\medskip
We must note here that in the bounding boxes of the county glyphs we did not leave the usual extra horizontal space {\small(to separate two neighboring glyphs)}; usually these irregular glyphs will appear in a text interspersed with characters of an another font {\small(an not as neighbors)}. \\
Also note that (implicitly by the above construction) the county glyphs respects {\small(as possible)} the cartographic proportions of the counties.


\begin{thebibliography}{10}
\addtolength{\leftmargin}{0.2in} 
\setlength{\itemindent}{-0.2in}

\bibitem{CoE} \textsf{https://ctan.org/pkg/countriesofeurope} \\
{\small\emph{A font with the images of the countries of Europe}}

\bibitem{GADM} \textsf{https://gadm.org} \quad{\small\emph{the Database of Global Administrative Areas}}

\bibitem{R} \textsf{https://www.r-project.org/} \\
{\small\emph{a free software environment for statistical computing and graphics}}

\bibitem{mapshaper} \textsf{https://github.com/mbloch/mapshaper} \\
\quad{\small\emph{A tool for topologically aware shape simplification}}

\bibitem{t1asm} \textsf{https://ctan.org/pkg/t1utils} \\
{\small\emph{Simple Type 1 font manipulation programs}}

\bibitem{PLRM} \textsf{https://www.adobe.com/jp/print/postscript/pdfs/PLRM.pdf}

\bibitem{GS} \textsf{https://www.ghostscript.com/}

\end{thebibliography}

\end{document}