| 1 |
%% This is part of the OpTeX project, see http://petr.olsak.net/optex |
| 2 |
|
| 3 |
\_codedecl \inspic {Graphics <2026-03-16>} % preloaded in format |
| 4 |
|
| 5 |
\_doc ----------------------------- |
| 6 |
\`\inspic` accepts old syntax `\inspic <filename><space>` |
| 7 |
or new syntax `\inspic{<filename>}`. So, we need to define |
| 8 |
two auxiliary macros \`\_inspicA` and \`\_inspicB`. |
| 9 |
|
| 10 |
All `\inspic` macros are surrounded in `\hbox` in order user can |
| 11 |
write `\moveright\inspic ...` or something similar. |
| 12 |
\_cod ----------------------------- |
| 13 |
|
| 14 |
\_def\_inspic{\_hbox\_bgroup\_isnextchar\_bgroup\_inspicB\_inspicA} |
| 15 |
\_def\_inspicA #1 {\_inspicB {#1}} |
| 16 |
\_def\_inspicB #1{% |
| 17 |
\_pdfximage \_ifdim\_picwidth=\_zo \_else width\_picwidth\_fi |
| 18 |
\_ifdim\_picheight=\_zo \_else height\_picheight\_fi |
| 19 |
\_the\_picparams {\_the\_picdir#1}% |
| 20 |
\_pdfrefximage\_pdflastximage\_egroup} |
| 21 |
|
| 22 |
\_public \inspic ; |
| 23 |
|
| 24 |
\_doc ----------------------------- |
| 25 |
Inkscape can save a picture to `*.pdf` file and labels for the picture |
| 26 |
to `*.pdf_tex` file. The second file is in \LaTeX/ format (unfortunately) |
| 27 |
and it is intended to read immediately after `*.pdf` is included |
| 28 |
in order to place labels of this picture in the same font as the document is printed. |
| 29 |
We need to read this \LaTeX/ file by plain \TeX/ macros when \`\inkinspic` is used. |
| 30 |
These macros are stored in the \`\_inkdefs` tokens list and it is used |
| 31 |
locally in the group. The solution is borrowed from OPmac trick 0032. |
| 32 |
\_cod ----------------------------- |
| 33 |
|
| 34 |
\_def\_inkinspic{\_hbox\_bgroup\_isnextchar\_bgroup\_inkinspicB\_inkinspicA} |
| 35 |
\_def\_inkinspicA #1 {\_inkinspicB {#1}} |
| 36 |
\_def\_inkinspicB #1{% |
| 37 |
\_ifdim\_picwidth=0pt \_setbox0=\_hbox{\_inspic{#1}}\_picwidth=\_wd0 \_fi |
| 38 |
\_tmptoks={#1}% |
| 39 |
\_the\_inkdefs |
| 40 |
\_opinput {\_the\_picdir #1_tex}% file with labels |
| 41 |
\_egroup} |
| 42 |
|
| 43 |
\_newtoks\_tmptoks |
| 44 |
\_newtoks\_inkdefs \_inkdefs={% |
| 45 |
\_def\makeatletter#1\makeatother{}% |
| 46 |
\_def\includegraphics[#1]#2{\_inkscanpage#1,page=,\_fin \_inspic{\_the\_tmptoks}\_hss}% |
| 47 |
\_def\_inkscanpage#1page=#2,#3\_fin{\_ifx,#2,\_else\_picparams{page#2}\_fi}% |
| 48 |
\_def\put(#1,#2)#3{\_nointerlineskip\_vbox to\_zo{\_vss\_hbox to\_zo{\_kern#1\_picwidth |
| 49 |
\_pdfsave\_hbox to\_zo{#3}\_pdfrestore\_hss}\_kern#2\_picwidth}}% |
| 50 |
\_def\begin#1{\_csname _begin#1\_endcsname}% |
| 51 |
\_def\_beginpicture(#1,#2){\_vbox\_bgroup |
| 52 |
\_hbox to\_picwidth{}\_kern#2\_picwidth \_def\end##1{\_egroup}}% |
| 53 |
\_def\_begintabular[#1]#2#3\end#4{% |
| 54 |
\_vtop{\_def\\{\_cr}\_tabiteml{}\_tabitemr{}\_table{#2}{#3}}}% |
| 55 |
\_def\color[#1]#2{\_scancolor #2,}% |
| 56 |
\_def\_scancolor#1,#2,#3,{\_pdfliteral{#1 #2 #3 rg}}% |
| 57 |
\_def\makebox(#1)[#2]#3{\_hbox to\_zo{\_csname _mbx:#2\_endcsname{#3}}}% |
| 58 |
\_sdef{_mbx:lb}#1{#1\_hss}\_sdef{_mbx:rb}#1{\_hss#1}\_sdef{_mbx:b}#1{\_hss#1\_hss}% |
| 59 |
\_sdef{_mbx:lt}#1{#1\_hss}\_sdef{_mbx:rt}#1{\_hss#1}\_sdef{_mbx:t}#1{\_hss#1\_hss}% |
| 60 |
\_def\rotatebox#1#2{\_pdfrotate{#1}#2}% |
| 61 |
\_def\lineheight#1{}% |
| 62 |
\_def\setlength#1#2{}% |
| 63 |
\_def\transparent#1{\_transparency\_exprA[0]{(1-#1)*255} }% |
| 64 |
% Inkscape may generate \textbf{\textit{\textsc{TEXT}}} |
| 65 |
\_def\textbf#1{\_begingroup\_let\_it\_bi\_bf #1\_endgroup}% |
| 66 |
\_def\textit#1{\_begingroup\_it #1\_endgroup}% |
| 67 |
\_def\textsl#1{\_begingroup\_trycs{slant}{}\_it #1\_endgroup}% |
| 68 |
} |
| 69 |
\_public \inkinspic ; |
| 70 |
|
| 71 |
\_doc ---------------------------- |
| 72 |
\`\pdfscale``{<x-scale>}{<y-scale>}` and \`\pdfrotate``{<degrees>}` |
| 73 |
macros are implemented by `\pdfsetmatrix` |
| 74 |
primitive. We need to know the values of sin, cos function in |
| 75 |
the `\pdfrotate`. We use Lua code for this. |
| 76 |
\_cod ---------------------------- |
| 77 |
|
| 78 |
\_def\_pdfscale#1#2{\_pdfsetmatrix{#1 0 0 #2}} |
| 79 |
|
| 80 |
\_def\_gonfunc#1#2{% |
| 81 |
\_directlua{tex.print(string.format('\_pcent.4f',math.#1(3.14159265*(#2)/180)))}% |
| 82 |
} |
| 83 |
\_def\_sin{\_gonfunc{sin}} |
| 84 |
\_def\_cos{\_gonfunc{cos}} |
| 85 |
|
| 86 |
\_def\_pdfrotate#1{\_pdfsetmatrix{\_cos{#1} \_sin{#1} \_sin{(#1)-180} \_cos{#1}}} |
| 87 |
|
| 88 |
\_public \pdfscale \pdfrotate ; |
| 89 |
|
| 90 |
\_doc ----------------------------- |
| 91 |
The \`\transformbox``{<transformation>}{<text>}` |
| 92 |
is copied from OPmac trick 0046.\nl |
| 93 |
The \`\rotbox``{<degrees>}{<text>}` is a combination of |
| 94 |
`\rotsimple` from OPmac trick 0101 and the `\transformbox`. |
| 95 |
Note, that `\rotbox{-90}` puts the rotated text to the height of the outer |
| 96 |
box (depth is zero) because code from `\rotsimple` is processed. |
| 97 |
But `\rotbox{-90.0}` puts the rotated text to |
| 98 |
the depth of the outer box (height is zero) because `\transformbox` is |
| 99 |
processed. |
| 100 |
\_cod ----------------------------- |
| 101 |
|
| 102 |
\_def\_multiplyMxV #1 #2 #3 #4 {% matrix * (vvalX, vvalY) |
| 103 |
\_tmpdim = #1\_vvalX \_advance\_tmpdim by #3\_vvalY |
| 104 |
\_vvalY = #4\_vvalY \_advance\_vvalY by #2\_vvalX |
| 105 |
\_vvalX = \_tmpdim |
| 106 |
} |
| 107 |
\_def\_multiplyMxM #1 #2 #3 #4 {% currmatrix := currmatrix * matrix |
| 108 |
\_vvalX=#1pt \_vvalY=#2pt \_ea\_multiplyMxV \_currmatrix |
| 109 |
\_edef\_tmpb{\_ea\_ignorept\_the\_vvalX\_space \_ea\_ignorept\_the\_vvalY}% |
| 110 |
\_vvalX=#3pt \_vvalY=#4pt \_ea\_multiplyMxV \_currmatrix |
| 111 |
\_edef\_currmatrix{\_tmpb\_space |
| 112 |
\_ea\_ignorept\_the\_vvalX\_space \_ea\_ignorept\_the\_vvalY\_space}% |
| 113 |
} |
| 114 |
\_def\_transformbox#1#2{\_hbox bdir0{\_setbox0=\_dirhbox{{#2}}% |
| 115 |
\_dimendef\_vvalX 11 \_dimendef\_vvalY 12 % we use these variables |
| 116 |
\_dimendef\_newHt 13 \_dimendef\_newDp 14 % only in this group |
| 117 |
\_dimendef\_newLt 15 \_dimendef\_newRt 16 |
| 118 |
\_ifnum\_inboxdirection>1 \_tbreset0\_fi |
| 119 |
\_setbox0=\_hbox{\_box0}\_preptransform{#1}% |
| 120 |
\_kern-\_newLt \_vrule height\_newHt depth\_newDp width\_zo |
| 121 |
\_ht0=\_zo \_dp0=\_zo |
| 122 |
\_pdfsave#1\_rlap{\_box0}\_pdfrestore \_kern\_newRt}% |
| 123 |
} |
| 124 |
\_def\_preptransform #1{\_def\_currmatrix{1 0 0 1 }% |
| 125 |
\_def\_pdfsetmatrix##1{\_edef\_tmpb{##1 }\_ea\_multiplyMxM \_tmpb\_unskip}% |
| 126 |
\_let\pdfsetmatrix=\_pdfsetmatrix #1% |
| 127 |
\_setnewHtDp 0pt \_ht0 \_setnewHtDp 0pt -\_dp0 |
| 128 |
\_setnewHtDp \_wd0 \_ht0 \_setnewHtDp \_wd0 -\_dp0 |
| 129 |
\_protected\_def \_pdfsetmatrix {\_pdfextension setmatrix}% |
| 130 |
\_let\pdfsetmatrix=\_pdfsetmatrix |
| 131 |
} |
| 132 |
\_def\_setnewHtDp #1 #2 {% |
| 133 |
\_vvalX=#1\_relax \_vvalY=#2\_relax \_ea\_multiplyMxV \_currmatrix |
| 134 |
\_ifdim\_vvalX<\_newLt \_newLt=\_vvalX \_fi \_ifdim\_vvalX>\_newRt \_newRt=\_vvalX \_fi |
| 135 |
\_ifdim\_vvalY>\_newHt \_newHt=\_vvalY \_fi \_ifdim-\_vvalY>\_newDp \_newDp=-\_vvalY \_fi |
| 136 |
} |
| 137 |
|
| 138 |
\_def\_rotbox#1#2{% |
| 139 |
\_isequal{90}{#1}\_iftrue \_rotboxA{#1}{\_kern\_ht0 \_tmpdim=\_dp0}{\_vfill}{#2}% |
| 140 |
\_else \_isequal{-90}{#1}\_iftrue \_rotboxA{#1}{\_kern\_dp0 \_tmpdim=\_ht0}{}{#2}% |
| 141 |
\_else \_transformbox{\_pdfrotate{#1}}{#2}% |
| 142 |
\_fi \_fi |
| 143 |
} |
| 144 |
\_def\_rotboxA #1#2#3#4{\_hbox bdir0{\_setbox0=\_dirhbox{{#4}}#2% |
| 145 |
\_vbox to\_wd0{#3\_wd0=\_zo \_dp0=\_zo \_ht0=\_zo |
| 146 |
\_pdfsave\_pdfrotate{#1}\_box0\_pdfrestore\vfil}% |
| 147 |
\_kern\_tmpdim |
| 148 |
}} |
| 149 |
\_public \transformbox \rotbox ; |
| 150 |
|
| 151 |
\_doc --------------------------- |
| 152 |
\`\_scantwodimens` scans two objects with the syntactic rule `<dimen>` |
| 153 |
and returns `{<number>}{<number>}` in `sp` unit. |
| 154 |
\nl |
| 155 |
\`\puttext` `<right> <up> {<text>}` puts the `<text>` to desired place: |
| 156 |
From current point moves <up> and <right>, puts the <text> and returns |
| 157 |
back. The current point is unchanged after this macro ends. |
| 158 |
The reference point of the <text> is the left edge of its baseline if |
| 159 |
\^`\inboxdirection`=0 else it is the right edge of the baseline of the <text>. |
| 160 |
This rule is ignored when the optional parameter `[l]` (left edge) or `[r]` |
| 161 |
(right edge) of the \^`\puttext` macro is given. For example |
| 162 |
`\puttext[r] -5mm 0mm {text}`. |
| 163 |
\nl |
| 164 |
\`\_tbreset`<number> supposes that the box <number> is created in |
| 165 |
dir modes 2 or 3 (top to bottom texts) and resets it to a `\hbox` in dirmode~1. |
| 166 |
I.e.\ it reverts the meaning of `\wd` and `\ht+\dp`. |
| 167 |
It is used in \^`\puttext` and similar macros and it decides, where the baseline of |
| 168 |
verticaly printed text is. You can re-define it, but this default macro |
| 169 |
puts the baseline 1em under the top of the resulting box. |
| 170 |
\_cod |
| 171 |
|
| 172 |
\_def\_scantwodimens{% |
| 173 |
\_directlua{tex.print(string.format('{\_pcent d}{\_pcent d}', |
| 174 |
token.scan_dimen(),token.scan_dimen()))}% |
| 175 |
} |
| 176 |
\_optdef\_puttext[]{\_ea\_ea\_ea\_puttextA\_scantwodimens} |
| 177 |
\_long\_def\_puttextA#1#2#3{{\_setbox0=\_dirhbox{{#3}}\_dimen1=#1sp \_dimen2=#2sp \_puttextB}} |
| 178 |
\_def\_puttextB{% |
| 179 |
\_ifvmode |
| 180 |
\_ifdim\_prevdepth>\_zo \_vskip-\_prevdepth \_relax \_fi |
| 181 |
\_nointerlineskip |
| 182 |
\_fi |
| 183 |
\_ifnum\_inboxdirection>1 \_tbreset0\_fi |
| 184 |
\_if r\_the\_opt\_relax \_setbox0=\_hbox bdir1{\_box0}\_fi |
| 185 |
\_if l\_the\_opt\_relax \_setbox0=\_hbox bdir0{\_box0}\_fi |
| 186 |
\_wd0=\_zo \_ht0=\_zo \_dp0=\_zo |
| 187 |
\_vbox bdir0 to\_zo{\_kern-\_dimen2 \_hbox to\_zo{\_kern\_dimen1 \_box0\_hss}\_vss}% |
| 188 |
} |
| 189 |
\_def\_tbreset#1{% |
| 190 |
\_ifnum\_inboxdirection=3 \_ifdim\_dimexpr \_ht#1+\_dp#1>1.2em % \vbox probably inside |
| 191 |
\_ht#1=\_dimexpr\_ht#1+\_dp#1-.3em \_dp#1=.3em \_fi\_fi % LuaTeX bug for dirmode 3 ?? |
| 192 |
\_setbox#1=\_hbox bdir1{\_lower\_dimexpr\_wd#1-1em\_box#1}% |
| 193 |
} |
| 194 |
|
| 195 |
\_doc |
| 196 |
\`\putpic` `<right> <up> <width> <height> {<image-file>}` |
| 197 |
does `\puttext` with the image scaled to desired <width> and <height>. |
| 198 |
If <with> or <height> is zero, natural dimension is used. |
| 199 |
The \`\nospec` is a shortcut to such a natural dimension. |
| 200 |
\nl |
| 201 |
\`\backgroundpic``{<image-file>}` puts the image to |
| 202 |
the background of each page. It is used in the \~`\slides` style, for example. |
| 203 |
\_cod --------------------------- |
| 204 |
|
| 205 |
\_def\_putpic{\_ea\_ea\_ea\_putpicA\_scantwodimens} |
| 206 |
\_def\_putpicA#1#2{\_dimen1=#1sp \_dimen2=#2sp \_ea\_ea\_ea\_putpicB\_scantwodimens} |
| 207 |
\_def\_putpicB#1#2#3{{\_setbox0=\_hbox{\_picwidth=#1sp \_picheight=#2sp \_inspic{#3}}\_puttextB}} |
| 208 |
|
| 209 |
\_newbox\_bgbox |
| 210 |
\_def\_backgroundpic#1{% |
| 211 |
\_setbox\_bgbox=\_hbox{\_picwidth=\_pdfpagewidth \_picheight=\_pdfpageheight \_inspic{#1}}% |
| 212 |
\_pgbackground={\_copy\_bgbox} |
| 213 |
} |
| 214 |
\_def\nospec{0pt} |
| 215 |
\_public \puttext \putpic \backgroundpic ; |
| 216 |
|
| 217 |
\_doc ----------------------------- |
| 218 |
\`\_circle``{<x>}{<y>}` creates an ellipse with `<x>` axis and `<y>` axis. |
| 219 |
The origin is in the center. |
| 220 |
\nl |
| 221 |
\`\_oval``{<x>}{<y>}{<roundness>}` creates an oval with `<x>`, `<y>` size and with |
| 222 |
the given `<roundness>`. The real size is bigger by 2`<roundness>`. The |
| 223 |
origin is at the left bottom corner. |
| 224 |
\nl |
| 225 |
\`\_mv``{<x>}{<y>}{<curve>}` moves current point to `<x>`, `<y>`, creates the |
| 226 |
`<curve>` and returns the current point back. |
| 227 |
All these macros are fully expandable and they can be used in the |
| 228 |
`\pdfliteral` argument. |
| 229 |
\_cod ----------------------------- |
| 230 |
|
| 231 |
\def\_circle#1#2{\_expr{.5*(#1)} 0 m |
| 232 |
\_expr{.5*(#1)} \_expr{.276*(#2)} \_expr{.276*(#1)} \_expr{.5*(#2)} 0 \_expr{.5*(#2)} c |
| 233 |
\_expr{-.276*(#1)} \_expr{.5*(#2)} \_expr{-.5*(#1)} \_expr{.276*(#2)} \_expr{-.5*(#1)} 0 c |
| 234 |
\_expr{-.5*(#1)} \_expr{-.276*(#2)} \_expr{-.276*(#1)} \_expr{-.5*(#2)} 0 \_expr{-.5*(#2)} c |
| 235 |
\_expr{.276*(#1)} \_expr{-.5*(#2)} \_expr{.5*(#1)} \_expr{-.276*(#2)} \_expr{.5*(#1)} 0 c h} |
| 236 |
|
| 237 |
\def\_oval#1#2#3{0 \_expr{-(#3)} m \_expr{#1} \_expr{-(#3)} l |
| 238 |
\_expr{(#1)+.552*(#3)} \_expr{-(#3)} \_expr{(#1)+(#3)} \_expr{-.552*(#3)} |
| 239 |
\_expr{(#1)+(#3)} 0 c |
| 240 |
\_expr{(#1)+(#3)} \_expr{#2} l |
| 241 |
\_expr{(#1)+(#3)} \_expr{(#2)+.552*(#3)} \_expr{(#1)+.552*(#3)} \_expr{(#2)+(#3)} |
| 242 |
\_expr{#1} \_expr{(#2)+(#3)} c |
| 243 |
0 \_expr{(#2)+(#3)} l |
| 244 |
\_expr{-.552*(#3)} \_expr{(#2)+(#3)} \_expr{-(#3)} \_expr{(#2)+.552*(#3)} |
| 245 |
\_expr{-(#3)} \_expr{#2} c |
| 246 |
\_expr{-(#3)} 0 l |
| 247 |
\_expr{-(#3)} \_expr{-.552*(#3)} \_expr{-.552*(#3)} \_expr{-(#3)} 0 \_expr{-(#3)} c h} |
| 248 |
|
| 249 |
\def\_mv#1#2#3{1 0 0 1 \_expr{#1} \_expr{#2} cm #3 1 0 0 1 \_expr{-(#1)} \_expr{-(#2)} cm} |
| 250 |
|
| 251 |
\_doc ----------------------------- |
| 252 |
The \`\inoval``{<text>}` is an example of \^`\_oval` usage.\nl |
| 253 |
The \`\incircle``{<text>}` is an example of \^`\_circle` usage.\nl |
| 254 |
The \`\ratio`, \`\lwidth`, \`\fcolor`, \`\lcolor`, \`\shadow` and \`\overlapmargins` |
| 255 |
are parameters, they can be set by user in optional brackets `[...]`. |
| 256 |
For example `\fcolor=\Red` does `\_let\_fcolorvalue=\Red` and it means |
| 257 |
filling color.\nl |
| 258 |
The \`\_setflcolors` uses the \^`\_setcolor` macro to separate filling (non-stroking) |
| 259 |
color and stroking color. |
| 260 |
The \`\_coc` macro means \"create oval or circle" and it expands to |
| 261 |
the stroking primitive `S` or filling primitive `f` or boh `B`. Only boundary |
| 262 |
stroking is performed after `\fcolor=\relax`. You cannot combine |
| 263 |
`\fcolor=\relax` with `\shadow=Y`. |
| 264 |
\_cod ----------------------------- |
| 265 |
|
| 266 |
\_newdimen \_lwidth |
| 267 |
\_def\_fcolor{\_let\_fcolorvalue} |
| 268 |
\_def\_lcolor{\_let\_lcolorvalue} |
| 269 |
\_def\_shadow{\_let\_shadowvalue} |
| 270 |
\_def\_overlapmargins{\_let\_overlapmarginsvalue} |
| 271 |
\_def\_ratio{\_isnextchar ={\_ratioA}{\_ratioA=}} |
| 272 |
\_def\_ratioA =#1 {\_def\_ratiovalue{#1}} |
| 273 |
\_def\_touppervalue#1{\_ifx#1n\_let#1=N\_fi} |
| 274 |
|
| 275 |
\_def\_setflcolors#1{% use only in a group |
| 276 |
\_def\_setcolor##1##2##3{##1 ##2}% |
| 277 |
\_edef#1{\_unless\_ifx\_fcolorvalue\_relax \_fcolorvalue \_fi}% |
| 278 |
\_def\_setcolor##1##2##3{##1 ##3}% |
| 279 |
\_edef#1{#1\_space\_lcolorvalue\_space}% |
| 280 |
} |
| 281 |
\_optdef\_inoval[]{\_vbox bdir0\_bgroup |
| 282 |
\_roundness=2pt \_fcolor=\Yellow \_lcolor=\Red \_lwidth=.5bp |
| 283 |
\_shadow=N \_overlapmargins=N \_hhkern=0pt \_vvkern=0pt |
| 284 |
\_the\_ovalparams \_relax \_the\_opt \_relax |
| 285 |
\_touppervalue\_overlapmarginsvalue \_touppervalue\_shadowvalue |
| 286 |
\_ifx\_overlapmarginsvalue N% |
| 287 |
\_advance\_hsize by-2\_hhkern \_advance\_hsize by-2\_roundness \_fi |
| 288 |
\_setbox0=\_dirhbox\_bgroup\_bgroup \_aftergroup\_inovalA \_kern\_hhkern \_let\_next=% |
| 289 |
} |
| 290 |
\_def\_inovalA{\_egroup % of \setbox0=\hbox\bgroup |
| 291 |
\_ifnum\_inboxdirection>1 \_tbreset0\_fi |
| 292 |
\_ifdim\_vvkern=\_zo \_else \_ht0=\_dimexpr\_ht0+\_vvkern \_relax |
| 293 |
\_dp0=\_dimexpr\_dp0+\_vvkern \_relax \_fi |
| 294 |
\_ifdim\_hhkern=\_zo \_else \_wd0=\_dimexpr\_wd0+\_hhkern \_relax \_fi |
| 295 |
\_ifx\_overlapmarginsvalue N\_dimen0=\_roundness \_dimen1=\_roundness |
| 296 |
\_else \_dimen0=-\_hhkern \_dimen1=-\_vvkern \_fi |
| 297 |
\_setflcolors\_tmp |
| 298 |
\_hbox{\_kern\_dimen0 |
| 299 |
\_vbox to\_zo{\_kern\_dp0 |
| 300 |
\_ifx\_shadowvalue N\_else |
| 301 |
\_edef\_tmpb{{\_bp{\_wd0+\_lwidth}}{\_bp{\_ht0+\_dp0+\_lwidth}}{\_bp{\_roundness}}}% |
| 302 |
\_doshadow\_oval |
| 303 |
\_fi |
| 304 |
\_pdfliteral{q \_bp{\_lwidth} w \_tmp |
| 305 |
\_oval{\_bp{\_wd0}}{\_bp{\_ht0+\_dp0}}{\_bp{\_roundness}} \_coc\_space Q}\_vss}% |
| 306 |
\_ht0=\_dimexpr\_ht0+\_dimen1 \_relax \_dp0=\_dimexpr\_dp0+\_dimen1 \_relax |
| 307 |
\_box0 |
| 308 |
\_kern\_dimen0}% |
| 309 |
\_egroup % of \vbox\bgroup |
| 310 |
} |
| 311 |
\_optdef\_incircle[]{\_vbox bdir0\_bgroup |
| 312 |
\_ratio=1 \_fcolor=\Yellow \_lcolor=\Red \_lwidth=.5bp |
| 313 |
\_shadow=N \_overlapmargins=N \_hhkern=3pt \_vvkern=3pt |
| 314 |
\_ea\_the \_ea\_circleparams \_space \_relax |
| 315 |
\_ea\_the \_ea\_opt \_space \_relax |
| 316 |
\_touppervalue\_overlapmarginsvalue \_touppervalue\_shadowvalue |
| 317 |
\_setbox0=\_dirhbox\_bgroup\_bgroup \_aftergroup\_incircleA \_kern\_hhkern \_let\_next=% |
| 318 |
} |
| 319 |
\_def\_incircleA {\_egroup % of \setbox0=\hbox\bgroup |
| 320 |
\_ifnum\_inboxdirection>1 \_tbreset0\_fi |
| 321 |
\_wd0=\_dimexpr \_wd0+\_hhkern \_relax |
| 322 |
\_ht0=\_dimexpr \_ht0+\_vvkern \_relax \_dp0=\_dimexpr \_dp0+\_vvkern \_relax |
| 323 |
\_ifdim \_ratiovalue\_dimexpr \_ht0+\_dp0 > \_wd0 |
| 324 |
\_dimen3=\_dimexpr \_ht0+\_dp0 \_relax \_dimen2=\_ratiovalue\_dimen3 |
| 325 |
\_else \_dimen2=\_wd0 \_dimen3=\_expr{1/\_ratiovalue}\_dimen2 \_fi |
| 326 |
\_setflcolors\_tmp |
| 327 |
\_ifx\_overlapmarginsvalue N\_dimen0=\_zo \_dimen1=\_zo |
| 328 |
\_else \_dimen0=-\_hhkern \_dimen1=-\_vvkern \_fi |
| 329 |
\_hbox{\_kern\_dimen0 |
| 330 |
\_ifx\_shadowvalue N\_else |
| 331 |
\_edef\_tmpb{{\_bp{\_dimen2+\_lwidth}}{\_bp{\_dimen3+\_lwidth}}{}}% |
| 332 |
\_doshadow\_circlet |
| 333 |
\_fi |
| 334 |
\_pdfliteral{q \_bp{\_lwidth} w \_tmp \_mv{\_bp{.5\_wd0}}{\_bp{(\_ht0-\_dp0)/2}} |
| 335 |
{\_circle{\_bp{\_dimen2}}{\_bp{\_dimen3}} \_coc} Q}% |
| 336 |
\_ifdim\_dimen1=\_zo \_else |
| 337 |
\_ht0=\_dimexpr \_ht0+\_dimen1 \_relax \_dp0=\_dimexpr \_dp0+\_dimen1 \_relax \_fi |
| 338 |
\_box0 |
| 339 |
\_kern\_dimen0} |
| 340 |
\_egroup % of \vbox\bgroup |
| 341 |
} |
| 342 |
\_def\_circlet#1#2#3{\_circle{#1}{#2}} |
| 343 |
\_def\_coc{\_ifx\_fcolorvalue\_relax S\_else \_ifdim\_lwidth=0pt f\_else B\_fi\_fi} |
| 344 |
|
| 345 |
\_public \inoval \incircle \ratio \lwidth \fcolor \lcolor \shadow \overlapmargins ; |
| 346 |
|
| 347 |
\_doc ----------------------------- |
| 348 |
Just before defining shadows, which require special graphics states, we |
| 349 |
define means for managing these graphics states and other PDF page resources |
| 350 |
(graphics states, patterns, shadings, etc.). Our mechanism, defined mostly |
| 351 |
in Lua (see \ref[lua-pdf-resources], uses single dictionary for each PDF page |
| 352 |
resource type (extgstate, etc.) for all pages (`\pdfpageresources` just |
| 353 |
points to it). |
| 354 |
|
| 355 |
The macro \`\addextgstate``{<PDF name>}{<PDF dictionary>}` is a use of that |
| 356 |
general mechanism and shall be used for adding more graphics states. It must |
| 357 |
be used {\em after} `\dump`. It's general variant defined in Lua is |
| 358 |
\^`\_addpageresource` `{<resource type>}{<PDF name>}{<PDF dictionary>}`. You can |
| 359 |
use `\pageresources` or \^`\_pageresources` if you need to insert resource |
| 360 |
entries to manually created PDF XObjects. |
| 361 |
\_cod ----------------------------- |
| 362 |
|
| 363 |
\_def\_addextgstate{\_addpageresource{ExtGState}} |
| 364 |
|
| 365 |
\_public \addextgstate ; |
| 366 |
\_def\pageresources{\_pageresources} |
| 367 |
\_def\addpageresource{\_addpageresource} |
| 368 |
|
| 369 |
\_doc ----------------------------- |
| 370 |
A shadow effect is implemented here. The shadow is equal to the |
| 371 |
silhouette of the given path in a gray-transparent color shifted by |
| 372 |
\`\_shadowmoveto` vector and with blurred boundary. |
| 373 |
A waistline with the width 2*\`\_shadowb` around the boundary is blurred. |
| 374 |
The \`\shadowlevels` levels of transparent shapes is used for creating |
| 375 |
this effect. The `\shadowlevels+1/2` level is equal to the shifted given path. |
| 376 |
\_cod ----------------------------- |
| 377 |
|
| 378 |
\_def\_shadowlevels{9} % number of layers for blur effect |
| 379 |
\_def\_shadowdarknessA{0.025} % transparency of first shadowlevels/2 layers |
| 380 |
\_def\_shadowdarknessB{0.07} % transparency of second half of layers |
| 381 |
\_def\_shadowmoveto{1.8 -2.5} % vector defines shifting layer (in bp) |
| 382 |
\_def\_shadowb{1} % 2*shadowb = blurring area thickness |
| 383 |
|
| 384 |
\_def\_insertshadowresources{% |
| 385 |
\_addextgstate{op1}{<</ca \_shadowdarknessA>>}% |
| 386 |
\_addextgstate{op2}{<</ca \_shadowdarknessB>>}% |
| 387 |
\_glet\_insertshadowresources=\_relax |
| 388 |
} |
| 389 |
|
| 390 |
\_doc ----------------------------- |
| 391 |
The \`\_doshadow``{<curve>}` does the shadow effect. |
| 392 |
\_cod ----------------------------- |
| 393 |
|
| 394 |
\_def\_doshadow#1{\_vbox{% |
| 395 |
\_insertshadowresources |
| 396 |
\_tmpnum=\_numexpr (\_shadowlevels-1)/2 \_relax |
| 397 |
\_edef\_tmpfin{\_the\_tmpnum}% |
| 398 |
\_ifnum\_tmpfin=0 \_def\_shadowb{0}\_def\_shadowstep{0}% |
| 399 |
\_else \_edef\_shadowstep{\_expr{\_shadowb/\_tmpfin}}\_fi |
| 400 |
\_def\_tmpa##1##2##3{\_def\_tmpb |
| 401 |
{#1{##1+2*\_the\_tmpnum*\_shadowstep}{##2+2*\_the\_tmpnum*\_shadowstep}{##3}}}% |
| 402 |
\_ea \_tmpa \_tmpb |
| 403 |
\_def\_shadowlayer{% |
| 404 |
\_ifnum\_tmpnum=0 /op2 gs \_fi |
| 405 |
\_tmpb\_space f |
| 406 |
\_immediateassignment\_advance\_tmpnum by-1 |
| 407 |
\_ifnum-\_tmpfin<\_tmpnum |
| 408 |
\_ifx#1\_oval 1 0 0 1 \_shadowstep\_space \_shadowstep\_space cm \_fi |
| 409 |
\_ea \_shadowlayer \_fi |
| 410 |
}% |
| 411 |
\_pdfliteral{q /op1 gs 0 g 1 0 0 1 \_shadowmoveto\_space cm |
| 412 |
\_ifx#1\_circlet 1 0 0 1 \_bp{.5\_wd0} \_bp{(\_ht0-\_dp0)/2} cm |
| 413 |
\_else 1 0 0 1 -\_shadowb\_space -\_shadowb\_space cm \_fi |
| 414 |
\_shadowlayer Q} |
| 415 |
}} |
| 416 |
|
| 417 |
\_doc ----------------------------- |
| 418 |
A generic macro \`\_clipinpath``<x> <y> <curve> <text>` declares |
| 419 |
a clipping path by the `<curve>` shifted by the `<x>`, `<y>`. The `<text>` is typeset |
| 420 |
when such clipping path is active. Dimensions are given by bp without the unit here. |
| 421 |
The macros \`\clipinoval` `<x> <y> <width> <height> {<text>}` and |
| 422 |
\`\clipincircle` `<x> <y> <width> <height> {<text>}` are defined here. |
| 423 |
These macros read normal \TeX/ dimensions in their parameters. |
| 424 |
\_cod ----------------------------- |
| 425 |
|
| 426 |
\_def\_clipinpath#1#2#3#4{% #1=x-pos[bp], #2=y-pos[bp], #3=curve, #4=text |
| 427 |
\_hbox bdir0 {\_setbox0=\_hbox{\_dirhbox{{#4}}}% |
| 428 |
\_tmpdim=\_wd0 \_wd0=\_zo |
| 429 |
\_pdfliteral{q \_mv{#1}{#2}{#3 W n}}% |
| 430 |
\_box0\_pdfliteral{Q}\_kern\_tmpdim |
| 431 |
}% |
| 432 |
} |
| 433 |
|
| 434 |
\_def\_clipinoval {\_ea\_ea\_ea\_clipinovalA\_scantwodimens} |
| 435 |
\_def\_clipinovalA #1#2{% |
| 436 |
\_def\_tmp{{#1/65781.76}{#2/65781.76}}% |
| 437 |
\_ea\_ea\_ea\_clipinovalB\_scantwodimens |
| 438 |
} |
| 439 |
\_def\_clipinovalB{\_ea\_clipinovalC\_tmp} |
| 440 |
\_def\_clipinovalC#1#2#3#4{% |
| 441 |
\_ea\_clipinpath{#1-(#3/131563.52)+(\_bp{\_roundness})}{#2-(#4/131563.52)+(\_bp{\_roundness})}% |
| 442 |
{\_oval{#3/65781.76-(\_bp{2\_roundness})}{#4/65781.76-(\_bp{2\_roundness})}{\_bp{\_roundness}}}% |
| 443 |
} |
| 444 |
\_def\_clipincircle {\_ea\_ea\_ea\_clipincircleA\_scantwodimens} |
| 445 |
\_def\_clipincircleA #1#2{% |
| 446 |
\_def\_tmp{{#1/65781.76}{#2/65781.76}}% |
| 447 |
\_ea\_ea\_ea\_clipincircleB\_scantwodimens |
| 448 |
} |
| 449 |
\_def\_clipincircleB#1#2{% |
| 450 |
\_ea\_clipinpath\_tmp{\_circle{#1/65781.76}{#2/65781.76}}% |
| 451 |
} |
| 452 |
\_public \clipinoval \clipincircle ; |
| 453 |
|
| 454 |
|
| 455 |
\_endcode % ------------------------------------- |
| 456 |
|
| 457 |
The \^`\inspic` is defined by `\pdfximage` and `\pdfrefximage` primitives. |
| 458 |
If you want to use one picture more than once in your document, then the |
| 459 |
following code is recommended: |
| 460 |
\begtt \catcode`\<=13 |
| 461 |
\newbox\mypic |
| 462 |
\setbox\mypic = \hbox{\picw=3cm \inspic{<picture>}} |
| 463 |
|
| 464 |
My picture: \copy\mypic, again my picture: \copy\mypic, etc. |
| 465 |
\endtt |
| 466 |
This code downloads the picture data to the PFD output only once (when |
| 467 |
`\setbox` is processed). Each usage of `\copy\mypic` puts only a pointer to |
| 468 |
the picture data in the PDF. |
| 469 |
|
| 470 |
If you want to copy the same picture in different sizes, then choose |
| 471 |
a \"basic size" used in `\setbox` and all different sizes can be realized by |
| 472 |
the \^`\transformbox{<transformation>}{\copy\mypic}`. |
| 473 |
|
| 474 |
\_endinput |
| 475 |
|
| 476 |
2026-03-16: \inoval etc: corrected for non L-R directions |
| 477 |
2025-06-05: \inoval, \incircle: \fcolor=\relax, bug fix |
| 478 |
2023-16-03: more \_inkdefs macros |
| 479 |
2022-11-05 \_doshadow: renduntant \_expr from \_expr{\_bp{...}} removed |
| 480 |
2022-10-18 \_puttextA defined \long, bug fixed |
| 481 |
2022-03-05: \_addextgstate, \pageresources, \addpageresources added |
| 482 |
2022-03-03: \_coc introduced |
| 483 |
2021-07-16: \inoval, \incircle are more simple, using attribitecolor features |
| 484 |
2021-03-19: \inkinspic: pictures in subdirectories, bug fixed |
| 485 |
2020-12-21: \puttext: \box0 in group, bugfix |
| 486 |
2020-04-12: \_public \clipinoval \clipincircle ; added, bug fixed |