-
Notifications
You must be signed in to change notification settings - Fork 4
/
microtype-logo.dtx
484 lines (484 loc) · 15.1 KB
/
microtype-logo.dtx
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
%
\ProvidesFile{microtype-logo.dtx}[2009/06/08]
%
% ^^A don't count the backslashes in this document
%\makeatletter
%\let\orig@step@checksum\step@checksum
%\let\step@checksum\relax
%\makeatother
%
% \section{The title logo}
% \label{sec:title-logo}
%
%^^A\iffalse meta-comment
% ^^A ========================================================================
% This is \file{microtype-logo.dtx}.
% You may treat this file in three different ways:
%\begin{itemize}
% \item compile it by itself
% \item \verb|\input| it in the body of a \file{dtx} file
% \item \verb|\input| it in the preamble: it then provides the command
% \verb|\printlogo|, which will do just that
%\end{itemize}
% The first two cases require the style file \file{microtype-doc.sty}, which can
% be generated from \file{microtype.ins} with:
%\begin{verbatim}
%\makefile{microtype-doc.sty}{docsty}
%\end{verbatim}
% ^^A ========================================================================
%^^A\fi
%
% \begin{macrocode}
%<*logo>
% \end{macrocode}
% Here's how the logo on the title page was created.\footnote{
% Note that the |logo| module will not be created when installing
% \microtype. Instead, the source file \file{microtype-logo.dtx}
% is included as an attachment in the \acronym{PDF} file.
% If your \acronym{PDF} reader supports this, you can
% \textattachfile
% [color={0.02 0.04 0.48},mimetype=text/plain]{microtype-logo.dtx}
% {click here}
% to extract it; alternatively, you may use the |pdftk| tool.}
% It has nothing to do with \microtype, actually, but uses \pkg{fontinst}. It is
% based on an experiment I posted to the \url{de.comp.text.tex} newsgroup.\footnote{
% Message ID: \nolinkurl{42aa3687$0$24366$9b4e6d93@newsread2.arcor-online.net}}
% It will show:
%\begin{itemize}
% \item the character
% \item the \TeX\ box
% \item the bounding box
% \item kerns
%\end{itemize}
%
% \subsection{Macros}
%
% To run this file, \TeX\ needs to find the \file{afm} file (either in the
% |TEXINPUTS| path, or in the current working directory).
%
% First input \pkg{fontinst}.
% \begin{macrocode}
\input fontinst.sty
% \end{macrocode}
% \file{bbox.sty} is an addition to \pkg{fontinst}, which makes dimensions of
% the bounding boxes available (and was written by \thanh, by the way). These
% dimensions are specified in the \file{afm} file, but not used by \TeX, which
% is why \pkg{fontinst} will discard them otherwise.
% \begin{macrocode}
\input bbox.sty
% \end{macrocode}
%\begin{macro}{\tempdim}
% Allocate some dimen registers.
% \begin{macrocode}
\newdimen\tempdim
% \end{macrocode}
%\end{macro}
%\begin{macro}{\fboxrulei}
% Frame width of the box as \TeX\ sees it.
% \begin{macrocode}
\newdimen\fboxrulei
\fboxrulei=0.1pt
% \end{macrocode}
%\end{macro}
%\begin{macro}{\fboxruleii}
% Frame width of the bounding box.
% \begin{macrocode}
\newdimen\fboxruleii
\fboxruleii=0.1pt
% \end{macrocode}
%\end{macro}
%\begin{macro}{\kernboxheight}
% Height of the box indicating the kern.
% \begin{macrocode}
\newdimen\kernboxheight
\kernboxheight=5pt
% \end{macrocode}
%\end{macro}
%\begin{macro}{\scaletoem}
% An auxiliary macro. Return a dimension relative to the |em|-width of the font.
% Requires \etex.
% \begin{macrocode}
\setcommand\scaletoem#1{\dimexpr #1 sp*\fontdimen6\font/1000\relax}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\showlogo}
% A \pkg{fontinst} incantation whose sole purpose is to produce the logo.
% Its argument is a string (letters only).
% \begin{macrocode}
\fontinstcc
\def\showlogo#1{%
% \end{macrocode}
% Some fonts do not specify the \fontdim6 (width of an |em|) in the |afm|
% file. In this case, use the font size, which is correct in most cases.
% \begin{macrocode}
\ifdim\fontdimen6\font = 0pt
\typeout{***~Warning:~no~fontdimen~6~specified~***^^J%
***~setting~it~to~\pdffontsize\font \ifnum\pdftexversion < 130 pt\fi~***}
\fontdimen6\font=\pdffontsize\font \ifnum\pdftexversion < 130 pt\fi\relax
\fi
\installfonts
\input_metrics{}{\logofont,\metrics\printbbs{#1}\relax}
\endinstallfonts
}
\normalcc
% \end{macrocode}
%\end{macro}
% Layers.
% \begin{macrocode}
\makeatletter
\def\mtl@layer#1#2{\pdfliteral{/OC/#1 BDC}#2\pdfliteral{EMC}}
\ifx\mt@objects\@undefined\let\mt@objects\@empty\fi
\ifx\mt@order \@undefined\let\mt@order \@empty\fi
\xdef\mt@order{\mt@order[(Logo)}
\let\mtl@resources\@empty
\def\mtl@register#1{%
\immediate\pdfobj{<< /Type/OCG /Name(#1) >>}
\expandafter\xdef\csname mtl@#1\endcsname{\the\pdflastobj\space 0 R }
\xdef\mt@objects{\mt@objects\csname mtl@#1\endcsname}
\xdef\mt@order{\mt@order\csname mtl@#1\endcsname}
\xdef\mtl@resources{\mtl@resources/#1 \csname mtl@#1\endcsname}}
\mtl@register{canvas}
\mtl@register{characters}
\mtl@register{bounding-boxes}
\mtl@register{TeX-boxes}
\xdef\mt@order{\mt@order]}
\global\let\mtl@objects\mt@objects
\def\togglelayer#1#2{%
\pdfstartlink width \wd\logobox height \ht\logobox depth \dp\logobox
user{/Subtype/Link
/BS << /Type/Border/W 0 >> /H/O
/A << /S/SetOCGState
/State[/Toggle \csname mtl@#1\endcsname] >>
}#2\pdfendlink
}
% \end{macrocode}
%\begin{macro}{\printbbs}
% Preparation.
% \begin{macrocode}
\setcommand\printbbs#1{%
\setbox0\hbox{#1}%
\leavevmode
\kern-\fboxrulei
% \end{macrocode}
% The canvas in the natural width of the text minus protrusion, in color
% |bgcolor|.
% \begin{macrocode}
\mtl@layer{canvas}{%
\getboundarychars#1\relax
\tempdim=\dimexpr\wd0 - (\scaletoem{\lpcode\font\firstchar}+
\scaletoem{\rpcode\font\lastchar})\relax
\kern\dimexpr\scaletoem{\lpcode\font\firstchar}\relax
\lower\dimexpr\dp0+0.05em \relax \vbox{\color{bgcolor}%
\hrule width \tempdim
height \dimexpr\dp0+\ht0+0.15em\relax}%
\kern-\tempdim
% \end{macrocode}
% The baseline, in color |blcolor|.
% \begin{macrocode}
\vbox{\color{blcolor}%
\hrule width \tempdim
height \fboxrulei}%
}%
\kern-\dimexpr\wd0 -\scaletoem{\rpcode\font\lastchar}\relax
% \end{macrocode}
% The string.
% \begin{macrocode}
\printbbss #1\relax\relax
}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\getboundarychars}
% Get first~\dots.
% \begin{macrocode}
\def\getboundarychars#1#2\relax{%
\def\firstchar{`#1}%
\getlastchar#1#2\relax
}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\getlastchar}
% \dots~and last character.
% \begin{macrocode}
\def\getlastchar#1#2{%
\ifx\relax#2\relax
\def\lastchar{`#1}%
\else
\expandafter\getlastchar
\fi #2%
}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\printbbss}
% Loop over all characters of the string.
% \begin{macrocode}
\def\printbbss#1#2#3\relax{%
\ifx\relax#1\relax
\else
\ifx\relax#2\relax
\printbb{#1}{}%
\else
\printbb{#1}{#2}%
\fi
\expandafter\printbbss
\fi #2#3\relax
}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\printbb}
% Record the kern between the current and the following character, then print the
% character. \cmd{\kerning} is a \pkg{fontinst} command.
% \begin{macrocode}
\setcommand\printbb#1#2{%
\setbox0\hbox{\kerning{#1}{#2}\xdef\thekern{\number\result}}%
\showboxes{#1}%
% \end{macrocode}
% This could be another application.
% \begin{macrocode}
% \quad
% w: \the\scaletoem{\width{#1}},
% bb: \the\scaletoem{\bbleft{#1}}/%
% \the\scaletoem{\bbright{#1}},
% \the\scaletoem{\number\numexpr\width{#1}-\bbright{#1}\relax}
% h: \height{#1}/\bbtop{#1}, \bbbottom{#1}/\depth{#1}\par
}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\showboxes}
% Print the boxes for char \meta{\#1}. This won't work if \meta{\#1} isn't
% also the PostScript name of the glyph (\eg, `comma' =\llap{/\,} `,').
% \begin{macrocode}
\setcommand\showboxes#1{%
\leavevmode
\color{texcolor}%
% \end{macrocode}
% We have to record the width of the glyph.
% \begin{macrocode}
\setbox0\hbox{{\color{textcolor}#1}}%
\global\tempdim=\wd0\relax
\kern-\fboxrulei
% \end{macrocode}
%\begin{enumerate}
%\item \textit{The \TeX\ box:}
% Print a frame in color |texcolor|. This frame shows the glyph as \TeX\ sees
% it.
% \begin{macrocode}
\mtl@layer{TeX-boxes}{%
\hbox{%
\lower\dimexpr \dp0 + \fboxrulei\relax
\hbox{%
\vbox{%
\hrule height\fboxrulei
\hbox{%
\vrule width\fboxrulei height \dimexpr\ht0 + 2\fboxrulei\relax
\phantom{\unhcopy0}%
\vrule width\fboxrulei
}%
\hrule height\fboxrulei}}}%
}%
% \end{macrocode}
%\item \textit{The character:}
% Now we step back and print the actual glyph. We hold it back until now, so
% that it will be printed \emph{on top} of its box.
% \begin{macrocode}
\kern-\wd0
\mtl@layer{characters}{\hbox{\box0}}%
% \end{macrocode}
% Step back by the amount that the character's bounding box differs from the
% \TeX\ box on the left side.
% \begin{macrocode}
\kern\dimexpr\scaletoem{\bbleft{#1}}-\tempdim-\fboxruleii\relax
% \end{macrocode}
%\item \textit{The bounding box:}
% will be printed in color |bbcolor|.
% \begin{macrocode}
\mtl@layer{bounding-boxes}{%
{\color{bbcolor}%
\hbox{%
\lower\dimexpr-\scaletoem{\bbbottom{#1}}+\fboxruleii\relax
\hbox{%
\vbox{%
\hrule height\fboxruleii
\hbox to \dimexpr\scaletoem{\numexpr
\bbright{#1}-\bbleft{#1}\relax}+2\fboxruleii\relax{%
\vrule height \dimexpr\scaletoem{\numexpr
\bbtop{#1}-\bbbottom{#1}\relax}%
width\fboxruleii
\hfill
\vrule width\fboxruleii}%
\hrule height\fboxruleii}}}%
}%
\kern-\dimexpr\fboxruleii+\fboxrulei\relax
}%
% \end{macrocode}
%\item \textit{The kern:}
% We also print a small box in color |kerncolor| indicating the kerning between
% the current and the next character; filled for negative kerns, empty for
% positive kerns.
% \begin{macrocode}
\kern\scaletoem{\numexpr\width{#1}-\bbright{#1}\relax}%
\mtl@layer{TeX-boxes}{%
{\ifnum\thekern<0
\color{kerncolor}%
\kern\scaletoem{\thekern}%
\lower\kernboxheight\hbox{\vrule width -\dimexpr\scaletoem{\thekern}\relax
height \kernboxheight}%
\kern\scaletoem{\thekern}%
\else
\color{texcolor}%
\ifnum\thekern=0 \else
\lower\kernboxheight
\hbox{%
\vbox{%
% \hrule height\fboxrulei
\hbox{%
\vrule height \kernboxheight width\fboxrulei
\kern\dimexpr\scaletoem{\thekern}-2\fboxrulei\relax
\vrule width\fboxrulei
}%
\hrule height\fboxrulei}}%
\fi
\fi
}%
}%
% \kern-\fboxrulei
}
% \end{macrocode}
%\end{enumerate}
%\end{macro}
%\begin{macro}{\printlogo}
% \begin{macrocode}
\newbox\logobox
\def\printlogo{%
\setbox\logobox=\hbox{\vbox{%
\MakePercentComment
% \end{macrocode}
% This is the Kepler MM font used in the logo.
% \begin{macrocode}
\def\logofont{pkpri9e10}
\transformfont{\logofont}{\reencodefont{8r}{\fromafm{pkpmmri8a10}}}
\font\thelogofont=\logofont\space at 82pt
% \end{macrocode}
% This would load the italic Palatino font instead.
% \begin{macrocode}
%\def\logofont{pplri}
%\transformfont{\logofont8r}{\reencodefont{8r}{\fromafm{\logofont8a}}}
%\edef\logofont{\logofont8r}
%\font\thelogofont=\logofont\space at 78pt
% \end{macrocode}
% Load the font.
% \begin{macrocode}
\thelogofont
% \end{macrocode}
% Protrusion values (overdone for didactic reasons).
% \begin{macrocode}
\lpcode\font`M=96
\rpcode\font`e=46
% \end{macrocode}
% Now we can generate the logo.
% \begin{macrocode}
\pdfliteral direct{/SXS gs}%
\showlogo{Microtype}%
% \rlap{\normalfont\normalsize\raisebox{55pt}{\footnotemark[1]}}%
% \kern5pt\\[3\baselineskip]
% \long\def\@makefntext##1{%
% \leftskip 0pt
% \parindent 0pt
% \everypar{\parindent 0pt}%
% \leavevmode\hbox to 15pt{\@thefnmark\hss}##1}
% \footnotetext[1]{This graphic displays on a
% \togglelayer{canvas}{canvas} the \togglelayer{characters}{characters},
% their \togglelayer{bounding-boxes}{bounding boxes}
% and \togglelayer{TeX-boxes}{\TeX\ boxes}.}
}}%
\edef\logodimens{width \the\wd\logobox height \the\ht\logobox depth \the\dp\logobox}
\immediate\pdfobj{<</Type/ExtGState /CA 0.6 /ca 0.6 /BM/Normal >>}%
\immediate\pdfxform
attr {/Group <</Type/Group /S/Transparency /I true /CS/DeviceRGB >>}
resources {/Properties <<\mtl@resources>>
/ExtGState << /SXS \the\pdflastobj\space 0 R >> }
\logobox
% \vskip-2.5\baselineskip
% \leavevmode
% \togglelayer{characters}{%
% \pdfrefxform\pdflastxform
% }%
\pdfannot\logodimens{%
/Subtype/Widget /FT/Btn /T(Logo)
%/F 4 % why did I say this?
/AP << /N \the\pdflastxform\space 0 R >>
/AA << /E << /S/SetOCGState /State[/Toggle \mtl@characters] >>
/X << /S/SetOCGState /State[/Toggle \mtl@characters] >>
/D << /S/SetOCGState /State[/Toggle \csname mtl@bounding-boxes\endcsname] >>
/U << /S/SetOCGState /State[/Toggle \csname mtl@TeX-boxes\endcsname] >>
>> }%
\vspace{3\baselineskip}
}
\IfFileExists{pkpmmri8a10.afm}\relax{\def\printlogo{\MT@warning{File pkpmmri8a10.afm not found.
\MessageBreak Cannot create logo}}}
% \end{macrocode}
%\end{macro}
% Our font.
% \begin{macrocode}
\pdfmapline{+pkpmmri8r10 KeplMM-It_385_575_10_ " TeXBase1Encoding ReEncodeFont " <8r.enc <pkpmmri8a10.pfb}
% \end{macrocode}
% Define colours (|thered| and |thegreen| are copied from \file{microtype.dtx}).
% \begin{macrocode}
\def\mtdefinecolors{
\definecolor{thered}{rgb}{0.65,0.04,0.07}
\definecolor{thegreen}{rgb}{0.06,0.44,0.08}
\colorlet{texcolor}{thegreen!50} % TeX boxes
\colorlet{kerncolor}{texcolor} % negative kerns
\colorlet{bbcolor}{thered!50} % bounding box
\colorlet{bgcolor}{black!8} % canvas
\colorlet{blcolor}{black!50} % baseline
\colorlet{textcolor}{black!40} % text
}
% \end{macrocode}
% Use with \file{microtype.dtx}
% \begin{macrocode}
\ifx\documentclass\@twoclasseserror
\usepackage[xcdraw]{xcolor}
\mtdefinecolors
\else
% \end{macrocode}
%
%\subsection{Document}
%
% Now we can start the document.
% \begin{macrocode}
\documentclass[10pt,a4paper]{ltxdoc}
\providecommand\MakePercentComment{\relax}
\expandafter\def\csname ver@microtype.dtx\endcsname{2999/99/99}
% \end{macrocode}
% Re-use the preamble from \file{microtype.dtx}.
% \begin{macrocode}
\usepackage{microtype-doc}
\usepackage{attachfile}
\makeatletter
\pdfcatalog{/OCProperties << /OCGs [\mt@objects] /D << /Order [\mt@order] >> >>}
\makeatother
\begin{document}
% \end{macrocode}
% You are currently reading this.
% \begin{macrocode}
\DocInput{microtype-logo.dtx}
\newpage
And here it is:\vspace{6\baselineskip}
\begin{center}
\printlogo
\end{center}
\expandafter\enddocument
\fi
% \end{macrocode}
% That's it.
%
%^^A resume counting backslashes
%\makeatletter
%\let\step@checksum\orig@step@checksum
%^^A\makeatother
%
% \begin{macrocode}
%</logo>
% \end{macrocode}
%
\endinput