summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/novel/novel-DropCap.sty
blob: 3a6233e3f5d49642608a26ffe22f2bbd805522f8 (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
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
%%
%% This is file `novel-DropCap.sty', part of `novel' document class.
%% Copyright (C) 2017-2018 Robert Allgeyer.
%%
%% It is based on `lettrine.sty', part of `lettrine' package,
%% Copyright (C) 1999-2015 Daniel Flipo.
%%
%% The license for this file is that same for `lettrine':
%
% This program can be distributed and/or modified under the terms
% of the LaTeX Project Public License either version 1.3c of this
% license or (at your option) any later version.
% The latest version of this license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
%%
% This file is new in `novel' version 1.50.
%
\ProvidesFile{novel-DropCap.sty}%
  [2018/04/26 v1.52 (Drop Caps)]
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%
%

%
\newcounter{NDCDefaultLines}
\setcounter{NDCDefaultLines}{3}
\newcounter{NDCDefaultDepth}
\newdimen\NDCDefaultVoffset
\newdimen\NDCDefaultHoffset
\newcommand*{\NDCDefaultScale}{1}
\newcommand*{\NDCDefaultBloat}{1}
\newdimen\NDCDefaultGap
\gsetlength{\NDCDefaultGap}{0.25em} % approx. width of normal space
\newsavebox{\NDC@dropcapbox}
\newsavebox{\NDC@normalXbox}
\newcounter{NDC@lines}
\newcounter{NDC@depth}
\newdimen\NDC@antewidth
\newdimen\NDC@Pindent
\newdimen\NDC@Gap % equivalent to lettrine findent
\newdimen\NDC@Nindent % not a user setting
\newdimen\NDC@voffset
\newdimen\NDC@hoffset
\newdimen\NDC@first
\newdimen\NDC@next
\newdimen\NDC@height
\newcommand*{\NDC@ante}{}
\newcommand*{\NDC@bloat}{}
\newcommand*{\NDC@scale}{}
\def\@getNDCheight{% offsets do not affect height:
  \@tempdima=\baselineskip
  \setlength{\NDC@height}{\value{NDC@lines}\@tempdima}% local
  \addtolength{\NDC@height}{-\@tempdima}%
  \sbox{\NDC@normalXbox}{X}% Normal capital X, rather than something else.
  \addtolength{\NDC@height}{\ht\NDC@normalXbox}%
  \setlength{\NDC@height}{\NDC@scale\NDC@height}% local
} %
\newcommand*{\NDC@char}{%
  \@getNDCheight%
  % Measures drop cap capital X, rather than something else:
  \sbox{\@tempboxa}{%
     \NDC@charstyle\fontsize{\NDC@height}{\NDC@height}\selectfont X%
  }%
  \@tempcntb=\ht\@tempboxa%
  \@tempcnta=\NDC@height%
  \multiply\@tempcnta by 100%
  \divide\@tempcntb by 100%
  \divide\@tempcnta by \@tempcntb%
  \advance\@tempcnta by -9999%
  \ifnum\@tempcnta>0%
    \def\@tempa{1.\the\@tempcnta}%
  \else%
    \def\@tempa{1}%
  \fi%
  \NDC@charstyle\fontsize{\@tempa\NDC@height}{\@tempa\NDC@height}\selectfont
} %
\define@key{NDC}{lines}{\setcounter{NDC@lines}{#1}}
\define@key{NDC}{depth}{\setcounter{NDC@depth}{#1}}
\define@key{NDC}{hoffset}{\setlength{\NDC@hoffset}{#1}}
\define@key{NDC}{voffset}{\setlength{\NDC@voffset}{#1}}
\define@key{NDC}{ante}{\renewcommand*{\NDC@ante}{#1}} % Like `lettrine' ante,
\define@key{NDC}{ante*}{\renewcommand*{\NDC@ante}{% Like `lettrine' ante, but
  \setlength\NDC@antewidth{\widthof{#1}}% auto-hangs the ante in left margin.
  \addtolength\NDC@antewidth{0.2em}% provides breathing room
  \stake\hspace{-\NDC@antewidth}#1\hspace{0.2em}}% restores alignment
}
\define@key{NDC}{gap}{\setlength{\NDC@Gap}{#1}}
\define@key{NDC}{bloat}{\renewcommand*{\NDC@bloat}{#1}}
\define@key{NDC}{scale}{\renewcommand*{\NDC@scale}{#1}}
\newdimen\NDCboxwidth
\newdimen\NDCboxheight
\newdimen\NDCboxdepth
%
\DeclareDocumentCommand \NDC@boxcap { m }{%
  \begingroup%
  % The model letter has no upper diacritical.
  \def\@NDCmodel{}%
  \IfSubStr{ÀÁÂÃÄÅĀĂ}{#1}{\def\@NDCmodel{A}}{}%
  \IfSubStr{ĆĈĊČ}{#1}{\def\@NDCmodel{C}}{}%
  \IfSubStr{Ď}{#1}{\def\@NDCmodel{D}}{}%
  \IfSubStr{ÈÉÊËĒĔĖĚ}{#1}{\def\@NDCmodel{E}}{}%
  \IfSubStr{ĜĞĠ}{#1}{\def\@NDCmodel{G}}{}%
  \IfSubStr{Ĥ}{#1}{\def\@NDCmodel{H}}{}%
  \IfSubStr{ÌÍÎÏĨĪĬİ}{#1}{\def\@NDCmodel{I}}{}%
  \IfSubStr{Ĵ}{#1}{\def\@NDCmodel{J}}{}%
  \IfSubStr{Ĺ}{#1}{\def\@NDCmodel{L}}{}%
  \IfSubStr{ÑŃŇ}{#1}{\def\@NDCmodel{N}}{}%
  \IfSubStr{ÒÓÔÕÖŌŎŐ}{#1}{\def\@NDCmodel{O}}{}%
  \IfSubStr{ŔŘ}{#1}{\def\@NDCmodel{R}}{}%
  \IfSubStr{ŚŜŠ}{#1}{\def\@NDCmodel{S}}{}%
  \IfSubStr{Ť}{#1}{\def\@NDCmodel{T}}{}%
  \IfSubStr{ÙÚÛÜŨŪŬŮŰ}{#1}{\def\@NDCmodel{U}}{}%
  \IfSubStr{Ŵ}{#1}{\def\@NDCmodel{W}}{}%
  \IfSubStr{ÝŶŸ}{#1}{\def\@NDCmodel{Y}}{}%
  \IfSubStr{ŹŻŽ}{#1}{\def\@NDCmodel{Z}}{}%
  \IfSubStr{DŽ}{#1}{\def\@NDCmodel{DZ}}{}% diglyph
  \setlength\fboxsep{0.16\@SetFontSize}%
  \setlength\fboxrule{0.02\@SetFontSize}%
  \ifthenelse{\equal{\@NDCmodel}{}}{%
    \framebox{\phantom{|}#1\phantom{|}}%
  }{%
    \framebox{\phantom{|\@NDCmodel}\llap{\smash{#1}}\phantom{|}}%
  }%
  \endgroup%
}% end boxcap
%
\DeclareDocumentCommand \dropcap { s O{} m } {%
  \@tempTFfalse%
  \IfSubStr{#3}{png}{\@tempTFtrue}{}%
  \IfSubStr{#3}{PNG}{\@tempTFtrue}{}%
  \IfSubStr{#3}{jpg}{\@tempTFtrue}{}%
  \IfSubStr{#3}{JPG}{\@tempTFtrue}{}%
  \IfSubStr{#3}{jpeg}{\@tempTFtrue}{}%
  \IfSubStr{#3}{JPEG}{\@tempTFtrue}{}%
  \setcounter{NDC@lines}{\value{NDCDefaultLines}}%
  \setcounter{NDC@depth}{\value{NDCDefaultDepth}}%
  \setlength{\NDC@hoffset}{\NDCDefaultHoffset}%
  \renewcommand*{\NDC@bloat}{\NDCDefaultBloat}%
  \renewcommand*{\NDC@scale}{\NDCDefaultScale}%
  \setlength{\NDC@voffset}{\NDCDefaultVoffset}%
  \renewcommand*{\NDC@ante}{}%
  \setlength{\NDC@Gap}{\NDCDefaultGap}%
  \setlength{\NDC@Nindent}{0pt}%
  \setkeys{NDC}{#2}%
  \if@tempTF%
    \def\@dropthisthing{\InlineImage[0em,b]{#3}}%
  \else%
    \IfBooleanTF{#1}%
      {\def\@dropthisthing{\NDC@boxcap{#3}}}%
      {\def\@dropthisthing{#3}}%
  \fi%
  \ifnum\value{NDC@lines}=1%
    \par\noindent%
    \NDC@ante%
    \@dropthisthing%
  \else%
    % Compensate for effect of using \Rework:
    \if@ReworkTrimSize%
      \FPdiv{\@tempN}{\strip@pt\textwidth}{\strip@pt\@OriginalTextWidth}%
      \FPmul{\NDC@bloat}{\NDC@bloat}{\@tempN}%
    \else%
      \if@ReworkMargins%
        \FPdiv{\@tempN}{\strip@pt\textwidth}{\strip@pt\@OriginalTextWidth}%
        \FPmul{\NDC@bloat}{\NDC@bloat}{\@tempN}%
      \fi%
    \fi%
    \sbox{\NDC@normalXbox}{X}% Normal capital X.
    \sbox{\NDC@dropcapbox}{\scalebox{\NDC@bloat}[1]{\NDC@char\@dropthisthing}}%
    \@tempdima=\baselineskip%
    \setlength{\NDC@first}{-\value{NDC@lines}\@tempdima}%
    \addtolength{\NDC@first}{\@tempdima}%
    \sbox{\@tempboxa}{X}%
    \addtolength{\NDC@first}{-\ht\@tempboxa}%
    \addtolength{\NDC@first}{\NDC@voffset}%
    \addtolength{\NDC@first}{\ht\NDC@dropcapbox}%
    \addtolength{\NDC@voffset}{-\value{NDC@lines}\@tempdima}%
    \addtolength{\NDC@voffset}{\@tempdima}%
    \par%
    \setlength{\NDC@Pindent}{\wd\NDC@dropcapbox}%
    \addtolength{\NDC@Pindent}{\NDC@hoffset}%
    \settowidth{\NDC@first}{\NDC@ante}%
    \addtolength{\NDC@Pindent}{\NDC@first}%
    \addtolength{\NDC@Pindent}{\NDC@Gap}%
    \setlength{\NDC@first}{\linewidth}%
    \addtolength{\NDC@first}{-\NDC@Pindent}%
    \addtolength{\NDC@Nindent}{\NDC@Pindent}%
    \setlength{\NDC@next}{\linewidth}%
    \addtolength{\NDC@next}{-\NDC@Nindent}%
    \addtolength{\NDC@Pindent}{\rightmargin}%
    \addtolength{\NDC@Nindent}{\rightmargin}%
    \setlength{\NDCboxwidth}{\wd\NDC@dropcapbox}%
    \setlength{\NDCboxheight}{\ht\NDC@dropcapbox}%
    \setlength{\NDCboxdepth}{\dp\NDC@dropcapbox}%
    \addtocounter{NDC@lines}{1}%
    \addtocounter{NDC@lines}{\value{NDC@depth}}%
    \def\NDC@parshape{\c@NDC@lines \the\NDC@Pindent \the\NDC@first}%
    \@tempcnta=\tw@%
    \@whilenum \@tempcnta<\c@NDC@lines\do{%
       \edef\NDC@parshape{\NDC@parshape \the\NDC@Nindent \the\NDC@next}%
       \advance\@tempcnta\@ne}%
    \edef\NDC@parshape{\NDC@parshape \rightmargin \the\linewidth}%
    \noindent%
    \parshape=\NDC@parshape\relax%
    \smash{%
      \llap{%
        \mbox{\NDC@ante}%
        \raisebox{\NDC@voffset}{\usebox{\NDC@dropcapbox}}%
        \hskip\the\NDC@Gap%
      }%
    }%
  \fi%
}% end @NDCdropcap
%%


%% In case the user prefers `lettrine':
\gdef\@ActivateDropCaps{% called by `novel.cls' \AtBeginDocument
  \@ifpackageloaded{lettrine}{%
    \global\LettrineOnGridtrue % Necessary.
    \gsetlength\DiscardVskip{10\nbs} % effectively infinite
  }{ % For test purposes only:
   \providecommand\lettrine[3][]{##2##3} % echoes its mandatory arguments
  }%
}% end \@ActivateDropCaps



%%
\endinput
%%
%% End of file `novel-DropCap.sty'.