summaryrefslogtreecommitdiff
path: root/fonts/rojud/doc/rojud.tex
blob: 97c7b976b88d1f202129ab96594644c4177e5454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
\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}