Debian Codegraph @

texmf-dist/tex/plain/pitex/fonts.ptx

raw
1 \inputluafile fonts.ptxlua
2 \pdfadjustspacing=2
3
4 \def\currentfont{}
5 \def\currentsize{normal}
6 \def\currentstyle{rm}
7 \def\currentweight{rg}
8 \def\currentcase{lc}
9 \def\makecurrentfont{%
10 \csname\currentfont @\currentsize @\currentstyle @\currentweight @\currentcase\endcsname
11 }
12 \def\normalsize{%
13 \def\currentsize{normal}%
14 \makecurrentfont
15 }
16 \def\small{%
17 \def\currentsize{small}%
18 \makecurrentfont
19 }
20 \def\verysmall{%
21 \def\currentsize{verysmall}%
22 \makecurrentfont
23 }
24 \def\smaller{%
25 \passexpanded\ifstring\currentsize{normal}%
26 {\def\currentsize{small}}
27 {\def\currentsize{verysmall}}
28 \makecurrentfont
29 }
30 \def\big{%
31 \def\currentsize{big}%
32 \makecurrentfont
33 }
34 \def\verybig{%
35 \def\currentsize{verybig}%
36 \makecurrentfont
37 }
38 \def\bigger{%
39 \passexpanded\ifstring\currentsize{normal}%
40 {\def\currentsize{big}}
41 {\def\currentsize{verybig}}
42 \makecurrentfont
43 }
44 \def\it{%
45 \def\currentstyle{it}%
46 \makecurrentfont
47 }
48 \def\rm{%
49 \def\currentstyle{rm}%
50 \makecurrentfont
51 }
52 \def\rmstring{rm}
53 \def\emph{%
54 \ifx\currentstyle\rmstring
55 \expandafter\ital
56 \else
57 \expandafter\rom
58 \fi
59 }
60 \def\bf{%
61 \def\currentweight{bf}%
62 \makecurrentfont
63 }
64 %\def\normalweight{%
65 \def\rg{%
66 \def\currentweight{rg}%
67 \makecurrentfont
68 }
69 \def\sc{%
70 \def\currentcase{sc}%
71 \makecurrentfont
72 }
73 %\def\normalcase{%
74 \def\lc{%
75 \def\currentcase{lc}%
76 \makecurrentfont
77 }
78 \freedef\ital{{\it#1}}
79 \freedef\bold{{\bf#1}}
80 \freedef\scap{{\sc#1}}
81 \freedef\rom{{\rm#1}}
82
83
84 \restrictparameter font :
85 command % The command to be used to switch to that font.
86 name % Actually the part common to all files' names for that font.
87 size % Well, the size.
88 small % Smaller size.
89 verysmall % Smaller yet.
90 big % Bigger.
91 verybig % Insanely big.
92 bold % Modifier for bold font.
93 italic % Modifier for italic font.
94 math % If set to "true", then used for math font.
95 % small, verysmall and italic should be specified
96 % (which shows I don't use it very often).
97 features % Font features (e.g. +onum, etc.).
98 slant % A number representing an angle, loading an italic
99 % font if no real italic is a available.
100 slantsc % The same, for small caps.
101
102 % The font parameter should disappear some day, it's clumsy.
103 \def\setfont#1:{%
104 \setparameter font : command = #1%
105 }
106
107 \setparameter metafont : % No relation :)
108 size = 10pt
109 bold = Bold
110 italic = Italic
111 features = "+onum; +liga; +trep; +tlig; expansion=30 20 5;"
112
113 \setparameter font :
114 meta = metafont
115
116 \newdimen\ptx@fontsize
117 \luacode
118 ptx_fonts = {}
119 function ptx_getfont(Font, ...)
120 if ptx_fonts[Font] then
121 local tempfont = ptx_fonts[Font]
122 for _, style in ipairs(arg) do
123 if ptx_getstyle[style] then
124 tempfont = tempfont:gsub("(%w+)@(%w+)@(%w+)@(%w+)@(%w+)",ptx_getstyle[style])
125 else
126 tempfont = nil
127 texio.write_nl("! PiTeX error: Unknown font style `style'.")
128 return Font
129 end
130 end
131 return font.id(tempfont)
132 else
133 texio.write_nl("! PiTeX error: " .. Font .. " is not a PiTeX font. It can't be changed.")
134 end
135 end
136 ptx_getstyle = {
137 normal = "%1@normal@%3@%4@%5",
138 small = "%1@small@%3@%4@%5",
139 verysmall = "%1@verysmall@%3@%4@%5",
140 big = "%1@big@%3@%4@%5",
141 verybig = "%1@verybig@%3@%4@%5",
142 rm = "%1@%2@rm@%4@%5",
143 it = "%1@%2@it@%4@%5",
144 rg = "%1@%2@%3@rg@%5",
145 bf = "%1@%2@%3@bf@%5",
146 lc = "%1@%2@%3@%4@lc",
147 sc = "%1@%2@%3@%4@sc"
148 }
149 \luacode/
150
151 \newstring{+} \newstring{-}
152 \def\ptx@dofont#1#2#3#4#5{%
153 \edef\ptx@temp{\passvaluenobraces\commandtoname font : command }%
154 \ifexpression{ -\ifstring{#4}{normal} & { \ifprefix-{#5} | \ifprefix+{#5} } }
155 {\def\ptx@dofont_size{\dimexpr\usevalue font : size + #5\relax}}
156 {\def\ptx@dofont_size{#5}}%
157 \ptx@dofont_load{\ptx@temp @#4@#1@#2@lc}{#3}{}{\ptx@dofont_size}%
158 \ifstring{#1}{rm}
159 {\ptx@dofont_load{\ptx@temp @#4@#1@#2@sc}{#3}{+smcp;}{\ptx@dofont_size}%
160 \ifattribute font : slant % Loading a slanted version of the font if no italic was given
161 {\ptx@dofont_load{\ptx@temp @#4@it@#2@lc}{#3}{slant=\usevalue font: slant ;}{\ptx@dofont_size}
162 \ifattribute font : slantsc {}
163 {\ptx@dofont_load{\ptx@temp @#4@it@#2@sc}{#3}{+smcp;slant=\usevalue font: slant ;}{\ptx@dofont_size}}}{}%
164 \ifattribute font : slantsc
165 {\ptx@dofont_load{\ptx@temp @#4@it@#2@sc}{#3}{+smcp;slant=\usevalue font: slantsc ;}{\ptx@dofont_size}}{}}%
166 {\ifattribute font : slantsc {}{\ptx@dofont_load{\ptx@temp @#4@it@#2@sc}{#3}{+smcp;}{\ptx@dofont_size}}}
167 }
168
169 \def\ptx@dofont_load#1#2#3#4{%
170 \passcs\font{#1}="\usevalue font : name #2:#3\usevalue font : features " at #4\relax
171 \ptx@lua{ptx_fonts[font.id("#1")] = "#1"}%
172 }
173
174
175
176 \def\dofont#1#2#3{%
177 \passvalue{\ptx@dofont{#1}{#2}{#3}{normal}} font : size
178 \passvalue{\ptx@dofont{#1}{#2}{#3}{small}} font : small
179 \passvalue{\ptx@dofont{#1}{#2}{#3}{verysmall}} font : verysmall
180 \passvalue{\ptx@dofont{#1}{#2}{#3}{big}} font : big
181 \passvalue{\ptx@dofont{#1}{#2}{#3}{verybig}} font : verybig
182 %
183 \ifvalue font : math = true
184 {\ifstring{#1#2}{rmrg}
185 {\passcs{\textfont0=}{\passvalue\commandtoname font : command @normal@#1@#2@lc}%
186 \passcs{\scriptfont0=}{\passvalue\commandtoname font : command @small@#1@#2@lc}%
187 \passcs{\scriptscriptfont0=}{\passvalue\commandtoname font : command @verysmall@#1@#2@lc}
188 \passcs{\textfont2=}{\passvalue\commandtoname font : command @normal@#1@#2@lc}%
189 \passcs{\scriptfont2=}{\passvalue\commandtoname font : command @small@#1@#2@lc}%
190 \passcs{\scriptscriptfont2=}{\passvalue\commandtoname font : command @verysmall@#1@#2@lc}}
191 {\iffstring{#1#2}{itrg}
192 {\passcs{\textfont1=}{\passvalue\commandtoname font : command @normal@#1@#2@lc}%
193 \passcs{\scriptfont1=}{\passvalue\commandtoname font : command @verysmall@#1@#2@lc}%
194 \passcs{\scriptscriptfont1=}{\passvalue\commandtoname font : command @verysmall@#1@#2@lc}}}%
195 }{}%
196 }
197
198 \gates new \FontLoader {FontLoader}
199 \FontLoader list {fontloader}
200 [fl_command]
201 {%
202 \passvaluenobraces\edef font : command {%
203 \def\noexpand\currentfont{\passvalue\commandtoname font : command }%
204 \noexpand\makecurrentfont}}
205 (fl_load)
206 . ( fl_roman )
207 . . [ fl_doromanregular ]
208 {\dofont{rm}{rg}{}}
209 . . [ fl_doromanbold ] ? {conditional = -\ifvalue font : bold = none }
210 {\dofont{rm}{bf}{/\usevalue font : bold }}
211 . ( fl_italic ) ? {conditional = -\ifvalue font : italic = none }
212 . . [ fl_doitalicregular ]
213 {\dofont{it}{rg}{/\usevalue font : italic }}
214 . . [ fl_doitalicbold ] ? {conditional = -\ifvalue font : bold = none }
215 {\dofont{it}{bf}{/\usevalue font : italic /\usevalue font : bold }}
216 [fl_use] ? {conditional = \ifvalue font : command = {\mainfont} }
217 {\mainfont}
218 (fl_post)
219 . [fl_delete]
220 {\deleteparameter font:}
221 . [fl_meta]
222 {\setattribute font : meta = metafont }
223
224 \defactiveparameter font {%
225 \FontLoader execute {fontloader}%
226 }
227
228
229
230
231
232
233
234 \long\def\color#1#2{%
235 \pdfcolorstack0 push {#1 rg #1 RG}%
236 #2%
237 \pdfcolorstack0 pop%
238 }
239
240 \newattribute\ptx@underline_attribute
241 \luacode
242 local do_underline = function (head,order,ratio,sign)
243 local item, leader = head, false
244 while item do
245 leader = false
246 if node.has_attribute(item,\attributenumber\ptx@underline_attribute)
247 and not (item.id == 10 and (item.subtype == 8 or item.subtype == 9)) then
248 local item_line = node.new(2)
249 item_line.depth = tex.sp("1.4pt")
250 item_line.height = tex.sp("-1pt")
251 if node.has_field(item,"spec") then
252 item_line.width = item.spec.width
253 if order == 0 then
254 if sign == 1 then
255 item_line.width = item_line.width + ratio * item.spec.stretch
256 else
257 item_line.width = item_line.width - ratio * item.spec.shrink
258 end
259 else
260 if item.spec.stretch_order > 0 or item.spec.shrink_order > 0 then
261 lualog(item.spec.stretch_order)
262 item_line.width = 1
263 item.subtype = 100
264 item.leader = item_line
265 leader = true
266 end
267 end
268 elseif node.has_field(item,"width") then
269 item_line.width = item.width
270 elseif node.has_field(item,"kern") then
271 item_line.width = item.kern
272 end
273 if leader then
274 item = item.next
275 else
276 local item_kern = node.new(11)
277 item_kern.kern = -item_line.width
278 node.insert_after(head,item,item_line)
279 node.insert_after(head,item,item_kern)
280 item = item_line.next
281 end
282 else
283 item = item.next
284 end
285 end
286 end
287 pitex.misc.underline = function (head)
288 for line in node.traverse_id(0,head) do
289 do_underline(line.list,line.glue_order,line.glue_set,line.glue_sign)
290 end
291 return head
292 end
293 pitex.callback.register("post_linebreak_filter", "pitex.misc:underline")
294 pitex.callback.close("pitex.misc:underline", "post_linebreak_filter")
295 \luacode/
296
297 \freedef\underline{%
298 \ptx@lua{%
299 pitex.callback.ajar("pitex:underline", "post_linebreak_filter")
300 }
301 % local plf = callback.list_functions("post_linebreak_filter")
302 % if not plf or not plf["underline"] then
303 % callback.add_function(underline, "underline", "post_linebreak_filter")
304 % end}%
305 \quitvmode % Otherwise it might also underline the indentation box.
306 \ptx@underline_attribute=0\relax
307 #1\unsetattribute\ptx@underline_attribute
308 }