pack-obj.mkiv /size: 5580 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=pack-obj,
3
%D version=1998.01.15,
4
%D title=\CONTEXT\ Packaging Macros,
5
%D subtitle=Objects,
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
\writestatus
{
loading
}{
ConTeXt
Packaging
Macros
/
Objects
}
15 16
\unprotect
17 18
\registerctxluafile
{
pack
-
obj
}{}
19 20
%D \macros
21
%D {setobject,getobject,ifinobject}
22
%D
23
%D Boxes can be considered reuable objects. Traditionally once passed to the \DVI\
24
%D file, such objects cannot be reused. In \PDF\ however, reusing is possible and
25
%D sometimes even a necessity. Therefore, \CONTEXT\ supports reusable objects and
26
%D \LUATEX\ has native support for so called box resources.
27
%D
28
%D The first application of objects in \CONTEXT\ concerned \METAPOST\ graphics and
29
%D fill||in form fields. Reusing resources can save lots of bytes and sometimes also
30
%D runtime.
31
%D
32
%D \starttyping
33
%D \setobject{class}{name}\somebox{}
34
%D \getobject{class}{name}
35
%D \stoptyping
36
%D
37
%D Here \type {\somebox} can be whatever box specification suits \TEX. Although the
38
%D implementation in \MKIV\ is somewhat different the principles have not changed.
39 40
\installcorenamespace
{
objects
}
41 42
\newif
\ifinobject
43
\newbox
\objectbox
44 45
\def
\objectoffset
{
1
cm
}
46 47
\newdimen
\objectoff
\def
\objectmargin
{
\the
\objectoff
}
48
\newdimen
\objectwd
\def
\objectwidth
{
\the
\objectwd
}
49
\newdimen
\objectht
\def
\objectheight
{
\the
\objectht
}
50
\newdimen
\objectdp
\def
\objectdepth
{
\the
\objectdp
}
51 52
%D If I have time I will use the unreferenced variant for e.g. mp reuse. This can be
53
%D rewritten in \LUA\ anyway.
54 55
\unexpanded
\def
\setreferencedobject
#
1
#
2
{
\begingroup
\synctexpause
\objectoff
\objectoffset
\inobjecttrue
\dowithnextbox
{
\pack_objects_set_yes
{
#
1
}{
#
2
}}}
56
\unexpanded
\def
\settightreferencedobject
#
1
#
2
{
\begingroup
\synctexpause
\objectoff
\zeropoint
\inobjecttrue
\dowithnextbox
{
\pack_objects_set_yes
{
#
1
}{
#
2
}}}
57
\unexpanded
\def
\setunreferencedobject
#
1
#
2
{
\begingroup
\synctexpause
\objectoff
\objectoffset
\inobjecttrue
\dowithnextbox
{
\pack_objects_set_nop
{
#
1
}{
#
2
}}}
58
\unexpanded
\def
\settightunreferencedobject
#
1
#
2
{
\begingroup
\synctexpause
\objectoff
\zeropoint
\inobjecttrue
\dowithnextbox
{
\pack_objects_set_nop
{
#
1
}{
#
2
}}}
59 60
\let
\setobject
\setreferencedobject
61
\let
\settightobject\settightreferencedobject
62 63
%D We can get subtle differences in boundingboxes but both methods work ok.
64 65
\newconstant
\c_pack_objects_offset_mode
% 0=tex 1=box
66 67
\unexpanded
\def
\pack_objects_set_yes
#
1
#
2
%
68
{
\ifcase
\c_pack_objects_offset_mode
69
\ifzeropt
\objectoff
70
\pack_objects_package_nop
\nextbox
71
\else
72
\pack_objects_package_yes
\nextbox
73
\fi
74
\else
75
\pack_objects_package_nop
\nextbox
76
\fi
77
\clf_registerreferencedobject
{
#
1
}{
#
2
}
\objectbox
\objectoff
\c_pack_objects_offset_mode
78
\synctexresume
79
\endgroup
}
80 81
\unexpanded
\def
\pack_objects_set_nop
#
1
#
2
%
82
{
\ifcase
\c_pack_objects_offset_mode
83
\ifzeropt
\objectoff
84
\pack_objects_package_nop
\nextbox
85
\else
86
\pack_objects_package_yes
\nextbox
87
\fi
88
\else
89
\pack_objects_package_nop
\nextbox
90
\fi
91
\clf_registerobject
{
#
1
}{
#
2
}
\objectbox
\objectoff
\c_pack_objects_offset_mode
92
\synctexresume
93
\endgroup
}
94 95
\def
\pack_objects_package_nop
#
1
% we pack because otherwise \ruledhbox is still tight
96
{
\setbox
\objectbox
\hpack
{
\box
#
1
}}
97 98
\def
\pack_objects_package_yes
#
1
%
99
{
\objectwd
\dimexpr\wd
#
1
+
2
\objectoff
\relax
100
\objectht
\dimexpr\ht
#
1
+
\objectoff
\relax
101
\objectdp
\dimexpr\dp
#
1
+
\objectoff
\relax
102
\setbox
\objectbox
\hpack
103
{
\hskip
\objectoff
104
\box
#
1
}
%
105
\wd
\objectbox
\objectwd
106
\ht
\objectbox
\objectht
107
\dp
\objectbox
\objectdp
}
108 109
\unexpanded
\def
\getobject
#
1
#
2
%
110
{
\begingroup
111
\synctexpause
112
\clf_restoreobject
{
#
1
}{
#
2
}
%
113
\ifzeropt
\objectoff
\else
114
\objectoff
-
\objectoff
115
\pack_objects_package_yes
\objectbox
116
\fi
117
\box
\objectbox
118
\synctexresume
119
\endgroup
}
120 121
%D If needed one can ask for the dimensions of an object with:
122
%D
123
%D \starttyping
124
%D \getobjectdimensions{class}{name}
125
%D \stoptyping
126
%D
127
%D The results are reported in \type {\objectwidth}, \type {\objectheight} and \type
128
%D {\objectdepth} as well as \type {\objectoffset}.
129 130
\unexpanded
\def
\getobjectdimensions
#
1
#
2
%
131
{
\clf_getobjectdimensions
{
#
1
}{
#
2
}}
132 133
%D \macros
134
%D {doifobjectfoundelse,doifobjectreferencefoundelse}
135
%D
136
%D To prevent redundant definition of objects, one can use the next tests:
137
%D
138
%D \starttyping
139
%D \doifobjectfoundelse{class}{object}{do then}{do else}
140
%D \doifobjectreferencefoundelse{class}{object}{do then}{do else}
141
%D \stoptyping
142 143
\def
\defaultobjectreference
{
0
}
144
\def
\defaultobjectpage
{
\realfolio
}
145 146
\unexpanded
\def
\dogetobjectreference
{
\clf_getobjectreference
}
147
\unexpanded
\def
\dogetobjectreferencepage
{
\clf_getobjectreferencepage
}
148 149
\unexpanded
\def
\doifelseobjectfound
{
\clf_doifelseobject
}
150
\unexpanded
\def
\doifelseobjectreferencefound
{
\clf_doifelseobjectreference
}
151 152
\let
\doifobjectfoundelse
\doifelseobjectfound
153
\let
\doifobjectreferencefoundelse\doifelseobjectreferencefound
154 155
%D For the moment here:
156 157
\let
\lastpredefinedsymbol
\empty
% some day we can do more at the lua end
158 159
\unexpanded
\def
\predefinesymbol
[#
1
]
%
160
{
\begingroup
161
\xdef
\lastpredefinedsymbol
{
#
1
}
%
162
\settightobject
{
SYM
}{
#
1
}
\hbox
{
\symbol
[#
1
]
}
% to be checked ... maybe only fitting
163
\dogetobjectreference
{
SYM
}{
#
1
}
\m_back_object_reference
164
\clf_registerbackendsymbol
{
#
1
}
\m_back_object_reference
\relax
165
\endgroup
}
166 167
\protect
\endinput
168