grph-pat.mkxl /size: 3707 b    last modification: 2023-12-21 09:44
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\permanent\tolerant\protected\def\registerpattern[#S#1]#*[#S#2]%
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   \unless\ifempty{#2}%
35     \setdummyparameter\c!name{#1}%
36     \getdummyparameters[#2]%
37   \orelse\ifhastok={#1}%
38     \getdummyparameters[#1]%
39   \else
40     \setdummyparameter\c!name{#1}%
41   \fi
42   \dowithnextboxcs\syst_boxes_registerpattern_indeed\hbox}
43
44\immutable\edef\v!auto_m{-\v!auto}
45
46\def\syst_boxes_registerpattern_indeed
47  {%\finalizeobjectbox\nextbox
48   \edef\p_width  {\dummyparameter\c!width}%
49   \edef\p_height {\dummyparameter\c!height}%
50   \edef\p_hoffset{\dummyparameter\c!hoffset}%
51   \edef\p_voffset{\dummyparameter\c!voffset}%
52   \scratchwidth  \dimexpr\ifx\p_width  \v!auto\wd  \nextbox\else\p_width  \fi\relax
53   \scratchheight \dimexpr\ifx\p_height \v!auto\htdp\nextbox\else\p_height \fi\relax
54   \scratchhoffset\dimexpr\ifx\p_hoffset\v!auto\scratchwidth /2\orelse\ifx\p_hoffset\v!auto_m-\scratchwidth /2\else\p_hoffset\fi\relax
55   \scratchvoffset\dimexpr\ifx\p_voffset\v!auto\scratchheight/2\orelse\ifx\p_voffset\v!auto_m-\scratchheight/2\else\p_voffset\fi\relax
56   \clf_registerpattern
57      name    {\dummyparameter\c!name}
58      number  \nextbox
59      width   \scratchwidth
60      height  \scratchheight
61      hoffset \scratchhoffset
62      voffset \scratchvoffset
63   \relax
64   \endgroup}
65
66\permanent\tolerant\protected\def\applypattern[#S#1]#*[#S#2]%
67  {\hpack\bgroup
68   \letdummyparameter\c!name  \s!dummy
69   \letdummyparameter\c!width \zeropoint
70   \letdummyparameter\c!height\zeropoint
71   \unless\ifempty{#2}%
72     \setdummyparameter\c!name{#1}%
73     \getdummyparameters[#2]%
74   \orelse\ifhastok={#1}%
75     \getdummyparameters[#1]%
76   \else
77     \setdummyparameter\c!name{#1}%
78   \fi
79   \clf_applypattern
80      name   {\dummyparameter\c!name}
81      number \nextbox
82      width  \dimexpr\dummyparameter\c!width\relax
83      height \dimexpr\dummyparameter\c!height\relax
84   \relax
85   \box\nextbox
86   \egroup}
87
88\protect
89
90\continueifinputfile{grph-pat.mkxl}
91
92\nopdfcompression
93
94\starttext
95
96    \registerpattern[demo]{It \darkred Works!}
97
98    \framed[offset=overlay]{\applypattern[demo][width=7cm,height=4cm]}
99
100    \blank
101
102    \registerpattern[name=more,hoffset=0bp,voffset=0pt]{\externalfigure[cow.pdf][width=1cm]}
103
104    \framed[offset=overlay]{\applypattern[name=more,width=7cm,height=4cm]}
105
106    \blank
107
108    \registerpattern[name=more,hoffset=auto,voffset=auto]{\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\stoptext
119
120