grph-pat.mkiv /size: 3862 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=grph-par,
3%D        version=2016.07.08,
4%D          title=\CONTEXT\ Graphic Macros,
5%D       subtitle=Patterns,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D This works ok in Okular and MuPDF but somehow xforms don't work in Acrobat
15%D (full nor reader). Also the basic offset is kind of unspecified. So \unknown\
16%D we're dealing with a fragile feature. So, don't rely on where the first (ulr)
17%D tile occurs.
18%D
19%D The two commands introduced here are not documented (yet).
20
21\writestatus{loading}{ConTeXt Graphic Macros / Patterns}
22
23\unprotect
24
25\registerctxluafile{grph-pat}{}
26
27\unexpanded\def\registerpattern
28  {\begingroup
29   \letdummyparameter\c!name   \s!dummy
30   \letdummyparameter\c!width  \v!auto
31   \letdummyparameter\c!height \v!auto
32   \letdummyparameter\c!hoffset\zeropoint
33   \letdummyparameter\c!voffset\zeropoint
34   \dodoubleempty\syst_boxes_registerpattern}
35
36\def\syst_boxes_registerpattern[#1][#2]%
37  {\ifsecondargument
38     \setdummyparameter\c!name{#1}%
39     \getdummyparameters[#2]%
40   \else\iffirstargument
41     \doifassignmentelse{#1}
42       {\getdummyparameters[#1]}%
43       {\setdummyparameter\c!name{#1}}%
44   \fi\fi
45   \dowithnextboxcs\syst_boxes_registerpattern_indeed\hbox}
46
47\edef\v!auto_m{-\v!auto}
48
49\def\syst_boxes_registerpattern_indeed
50  {%\finalizeobjectbox\nextbox
51   \edef\p_width  {\dummyparameter\c!width}%
52   \edef\p_height {\dummyparameter\c!height}%
53   \edef\p_hoffset{\dummyparameter\c!hoffset}%
54   \edef\p_voffset{\dummyparameter\c!voffset}%
55   \scratchwidth  \dimexpr\ifx\p_width  \v!auto\wd  \nextbox   \else\p_width  \fi\relax
56   \scratchheight \dimexpr\ifx\p_height \v!auto\htdp\nextbox   \else\p_height \fi\relax
57   \scratchhoffset\dimexpr\ifx\p_hoffset\v!auto\scratchwidth /2\else\ifx\p_hoffset\v!auto_m-\scratchwidth /2\else\p_hoffset\fi\fi\relax
58   \scratchvoffset\dimexpr\ifx\p_voffset\v!auto\scratchheight/2\else\ifx\p_voffset\v!auto_m-\scratchheight/2\else\p_voffset\fi\fi\relax
59   \clf_registerpattern
60      name    {\dummyparameter\c!name}
61      number  \nextbox
62      width   \scratchwidth
63      height  \scratchheight
64      hoffset \scratchhoffset
65      voffset \scratchvoffset
66   \relax
67   \endgroup}
68
69\unexpanded\def\applypattern
70  {\hbox\bgroup
71   \letdummyparameter\c!name  \s!dummy
72   \letdummyparameter\c!width \zeropoint
73   \letdummyparameter\c!height\zeropoint
74   \dodoubleempty\syst_boxes_applypattern}
75
76\def\syst_boxes_applypattern[#1][#2]%
77  {\ifsecondargument
78     \setdummyparameter\c!name{#1}%
79     \getdummyparameters[#2]%
80   \else\iffirstargument
81     \doifassignmentelse{#1}
82       {\getdummyparameters[#1]}%
83       {\setdummyparameter\c!name{#1}}%
84   \fi\fi
85   \clf_applypattern
86      name   {\dummyparameter\c!name}
87      number \nextbox
88      width  \dimexpr\dummyparameter\c!width\relax
89      height \dimexpr\dummyparameter\c!height\relax
90   \relax
91   \box\nextbox
92   \egroup}
93
94\protect
95
96\continueifinputfile{grph-pat.mkiv}
97
98\nopdfcompression
99
100\starttext
101
102    \registerpattern[demo]{It \darkred Works!}
103
104    \framed[offset=overlay]{\applypattern[demo][width=7cm,height=4cm]}
105
106    \blank
107
108    \registerpattern[name=more,hoffset=0bp,voffset=0pt]{\externalfigure[cow.pdf][width=1cm]}
109
110    \framed[offset=overlay]{\applypattern[name=more,width=7cm,height=4cm]}
111
112    \blank
113
114    \registerpattern[name=more,hoffset=auto,voffset=auto]{\externalfigure[cow.pdf][width=1cm]}
115
116    \framed[offset=overlay]{\applypattern[name=more,width=7cm,height=4cm]}
117
118    \blank
119
120    \registerpattern[name=more,hoffset=-auto,voffset=-auto]{\externalfigure[cow.pdf][width=1cm]}
121
122    \framed[offset=overlay]{\applypattern[name=more,width=7cm,height=4cm]}
123
124\stoptext
125
126