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
|
%D \module
%D [ file=grph-par,
%D version=2016.07.08,
%D title=\CONTEXT\ Graphic Macros,
%D subtitle=Patterns,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
%D This works ok in Okular and MuPDF but somehow xforms don't work in Acrobat
%D (full nor reader). Also the basic offset is kind of unspecified. So \unknown\
%D we're dealing with a fragile feature. So, don't rely on where the first (ulr)
%D tile occurs.
%D
%D The two commands introduced here are not documented (yet).
\writestatus{loading}{ConTeXt Graphic Macros / Patterns}
\unprotect
\registerctxluafile{grph-pat}{}
\unexpanded\def\registerpattern
{\begingroup
\letdummyparameter\c!name \s!dummy
\letdummyparameter\c!width \v!auto
\letdummyparameter\c!height \v!auto
\letdummyparameter\c!hoffset\zeropoint
\letdummyparameter\c!voffset\zeropoint
\dodoubleempty\syst_boxes_registerpattern}
\def\syst_boxes_registerpattern[#1][#2]%
{\ifsecondargument
\setdummyparameter\c!name{#1}%
\getdummyparameters[#2]%
\else\iffirstargument
\doifassignmentelse{#1}
{\getdummyparameters[#1]}%
{\setdummyparameter\c!name{#1}}%
\fi\fi
\dowithnextboxcs\syst_boxes_registerpattern_indeed\hbox}
\edef\v!auto_m{-\v!auto}
\def\syst_boxes_registerpattern_indeed
{%\finalizeobjectbox\nextbox
\edef\p_width {\dummyparameter\c!width}%
\edef\p_height {\dummyparameter\c!height}%
\edef\p_hoffset{\dummyparameter\c!hoffset}%
\edef\p_voffset{\dummyparameter\c!voffset}%
\scratchwidth \dimexpr\ifx\p_width \v!auto\wd \nextbox \else\p_width \fi\relax
\scratchheight \dimexpr\ifx\p_height \v!auto\htdp\nextbox \else\p_height \fi\relax
\scratchhoffset\dimexpr\ifx\p_hoffset\v!auto\scratchwidth /2\else\ifx\p_hoffset\v!auto_m-\scratchwidth /2\else\p_hoffset\fi\fi\relax
\scratchvoffset\dimexpr\ifx\p_voffset\v!auto\scratchheight/2\else\ifx\p_voffset\v!auto_m-\scratchheight/2\else\p_voffset\fi\fi\relax
\clf_registerpattern
name {\dummyparameter\c!name}
number \nextbox
width \scratchwidth
height \scratchheight
hoffset \scratchhoffset
voffset \scratchvoffset
\relax
\endgroup}
\unexpanded\def\applypattern
{\hbox\bgroup
\letdummyparameter\c!name \s!dummy
\letdummyparameter\c!width \zeropoint
\letdummyparameter\c!height\zeropoint
\dodoubleempty\syst_boxes_applypattern}
\def\syst_boxes_applypattern[#1][#2]%
{\ifsecondargument
\setdummyparameter\c!name{#1}%
\getdummyparameters[#2]%
\else\iffirstargument
\doifassignmentelse{#1}
{\getdummyparameters[#1]}%
{\setdummyparameter\c!name{#1}}%
\fi\fi
\clf_applypattern
name {\dummyparameter\c!name}
number \nextbox
width \dimexpr\dummyparameter\c!width\relax
height \dimexpr\dummyparameter\c!height\relax
\relax
\box\nextbox
\egroup}
\protect
\continueifinputfile{grph-pat.mkiv}
\nopdfcompression
\starttext
\registerpattern[demo]{It \darkred Works!}
\framed[offset=overlay]{\applypattern[demo][width=7cm,height=4cm]}
\blank
\registerpattern[name=more,hoffset=0bp,voffset=0pt]{\externalfigure[cow.pdf][width=1cm]}
\framed[offset=overlay]{\applypattern[name=more,width=7cm,height=4cm]}
\blank
\registerpattern[name=more,hoffset=auto,voffset=auto]{\externalfigure[cow.pdf][width=1cm]}
\framed[offset=overlay]{\applypattern[name=more,width=7cm,height=4cm]}
\blank
\registerpattern[name=more,hoffset=-auto,voffset=-auto]{\externalfigure[cow.pdf][width=1cm]}
\framed[offset=overlay]{\applypattern[name=more,width=7cm,height=4cm]}
\stoptext
|