mlib-int.lmt /size: 10 Kb    last modification: 2021-10-28 13:51
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
mlib-int
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to mlib-ctx.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
,
7
}
8 9
local
factor
=
number
.
dimenfactors
.
bp
10
local
mpstring
=
mp
.
string
11
local
mpboolean
=
mp
.
boolean
12
local
getdimen
=
tex
.
getdimen
13
local
getcount
=
tex
.
getcount
14
local
getmacro
=
tokens
.
getters
.
macro
15
local
get
=
tex
.
get
16
local
emwidths
=
fonts
.
hashes
.
emwidths
17
local
exheights
=
fonts
.
hashes
.
exheights
18 19
local
registerdirect
=
metapost
.
registerdirect
20 21
local
on_right_page
=
structures
.
pages
.
on_right
22
local
is_odd_page
=
structures
.
pages
.
is_odd
23
local
in_body_page
=
structures
.
pages
.
in_body
24
local
page_fraction
=
structures
.
pages
.
fraction
25
local
layout_has_changed
=
structures
.
pages
.
has_changed
26 27
local
function
defaultcolormodel
(
)
-- can be helper
28
local
colormethod
=
getcount
(
"
MPcolormethod
"
)
29
return
(
colormethod
=
=
0
or
colormethod
=
=
1
)
and
1
or
3
30
end
31 32
do
33 34
local
t
=
os
.
date
(
"
*t
"
)
-- maybe this should be a very early on global
35 36
-- If we want to do a vardef then we first need to catch an endgroup and
37
-- that then fails because we have a variable sitting there, so they need
38
-- to be def's at the mp end.
39 40
local
assignment_code
=
metapost
.
codes
.
assignment
41 42
local
mpscannext
=
mp
.
scan
.
next
43
local
mpscaninteger
=
mp
.
scan
.
integer
44 45
local
function
item
(
name
)
46
local
n
=
mpscannext
(
true
)
-- keep
47
if
n
=
=
assignment_code
then
48
mpscannext
(
)
49
t
[
name
]
=
mpscaninteger
(
)
50
else
51
return
t
[
name
]
52
end
53
end
54 55
registerdirect
(
"
year
"
,
function
(
)
return
item
(
"
year
"
)
end
)
56
registerdirect
(
"
month
"
,
function
(
)
return
item
(
"
month
"
)
end
)
57
registerdirect
(
"
day
"
,
function
(
)
return
item
(
"
day
"
)
end
)
58
registerdirect
(
"
hour
"
,
function
(
)
return
item
(
"
hour
"
)
end
)
59
registerdirect
(
"
minute
"
,
function
(
)
return
item
(
"
min
"
)
end
)
60
registerdirect
(
"
second
"
,
function
(
)
return
item
(
"
sec
"
)
end
)
61 62
end
63 64
local
injectnumeric
=
mp
.
inject
.
numeric
65 66
registerdirect
(
"
PaperHeight
"
,
function
(
)
return
getdimen
(
"
paperheight
"
)
*
factor
end
)
67
registerdirect
(
"
PaperWidth
"
,
function
(
)
return
getdimen
(
"
paperwidth
"
)
*
factor
end
)
68
registerdirect
(
"
PrintPaperHeight
"
,
function
(
)
return
getdimen
(
"
printpaperheight
"
)
*
factor
end
)
69
registerdirect
(
"
PrintPaperWidth
"
,
function
(
)
return
getdimen
(
"
printpaperwidth
"
)
*
factor
end
)
70
registerdirect
(
"
TopSpace
"
,
function
(
)
return
getdimen
(
"
topspace
"
)
*
factor
end
)
71
registerdirect
(
"
BottomSpace
"
,
function
(
)
return
getdimen
(
"
bottomspace
"
)
*
factor
end
)
72
registerdirect
(
"
BackSpace
"
,
function
(
)
return
getdimen
(
"
backspace
"
)
*
factor
end
)
73
registerdirect
(
"
CutSpace
"
,
function
(
)
return
getdimen
(
"
cutspace
"
)
*
factor
end
)
74
registerdirect
(
"
MakeupHeight
"
,
function
(
)
return
getdimen
(
"
makeupheight
"
)
*
factor
end
)
75
registerdirect
(
"
MakeupWidth
"
,
function
(
)
return
getdimen
(
"
makeupwidth
"
)
*
factor
end
)
76
registerdirect
(
"
TopHeight
"
,
function
(
)
return
getdimen
(
"
topheight
"
)
*
factor
end
)
77
registerdirect
(
"
TopDistance
"
,
function
(
)
return
getdimen
(
"
topdistance
"
)
*
factor
end
)
78
registerdirect
(
"
HeaderHeight
"
,
function
(
)
return
getdimen
(
"
headerheight
"
)
*
factor
end
)
79
registerdirect
(
"
HeaderDistance
"
,
function
(
)
return
getdimen
(
"
headerdistance
"
)
*
factor
end
)
80
registerdirect
(
"
TextHeight
"
,
function
(
)
return
getdimen
(
"
textheight
"
)
*
factor
end
)
81
registerdirect
(
"
FooterDistance
"
,
function
(
)
return
getdimen
(
"
footerdistance
"
)
*
factor
end
)
82
registerdirect
(
"
FooterHeight
"
,
function
(
)
return
getdimen
(
"
footerheight
"
)
*
factor
end
)
83
registerdirect
(
"
BottomDistance
"
,
function
(
)
return
getdimen
(
"
bottomdistance
"
)
*
factor
end
)
84
registerdirect
(
"
BottomHeight
"
,
function
(
)
return
getdimen
(
"
bottomheight
"
)
*
factor
end
)
85
registerdirect
(
"
LeftEdgeWidth
"
,
function
(
)
return
getdimen
(
"
leftedgewidth
"
)
*
factor
end
)
86
registerdirect
(
"
LeftEdgeDistance
"
,
function
(
)
return
getdimen
(
"
leftedgedistance
"
)
*
factor
end
)
87
registerdirect
(
"
LeftMarginWidth
"
,
function
(
)
return
getdimen
(
"
leftmarginwidth
"
)
*
factor
end
)
88
registerdirect
(
"
LeftMarginDistance
"
,
function
(
)
return
getdimen
(
"
leftmargindistance
"
)
*
factor
end
)
89
registerdirect
(
"
TextWidth
"
,
function
(
)
return
getdimen
(
"
textwidth
"
)
*
factor
end
)
90
registerdirect
(
"
RightMarginDistance
"
,
function
(
)
return
getdimen
(
"
rightmargindistance
"
)
*
factor
end
)
91
registerdirect
(
"
RightMarginWidth
"
,
function
(
)
return
getdimen
(
"
rightmarginwidth
"
)
*
factor
end
)
92
registerdirect
(
"
RightEdgeDistance
"
,
function
(
)
return
getdimen
(
"
rightedgedistance
"
)
*
factor
end
)
93
registerdirect
(
"
RightEdgeWidth
"
,
function
(
)
return
getdimen
(
"
rightedgewidth
"
)
*
factor
end
)
94
registerdirect
(
"
InnerMarginDistance
"
,
function
(
)
return
getdimen
(
"
innermargindistance
"
)
*
factor
end
)
95
registerdirect
(
"
InnerMarginWidth
"
,
function
(
)
return
getdimen
(
"
innermarginwidth
"
)
*
factor
end
)
96
registerdirect
(
"
OuterMarginDistance
"
,
function
(
)
return
getdimen
(
"
outermargindistance
"
)
*
factor
end
)
97
registerdirect
(
"
OuterMarginWidth
"
,
function
(
)
return
getdimen
(
"
outermarginwidth
"
)
*
factor
end
)
98
registerdirect
(
"
InnerEdgeDistance
"
,
function
(
)
return
getdimen
(
"
inneredgedistance
"
)
*
factor
end
)
99
registerdirect
(
"
InnerEdgeWidth
"
,
function
(
)
return
getdimen
(
"
inneredgewidth
"
)
*
factor
end
)
100
registerdirect
(
"
OuterEdgeDistance
"
,
function
(
)
return
getdimen
(
"
outeredgedistance
"
)
*
factor
end
)
101
registerdirect
(
"
OuterEdgeWidth
"
,
function
(
)
return
getdimen
(
"
outeredgewidth
"
)
*
factor
end
)
102
registerdirect
(
"
PageOffset
"
,
function
(
)
return
getdimen
(
"
pagebackgroundoffset
"
)
*
factor
end
)
103
registerdirect
(
"
PageDepth
"
,
function
(
)
return
getdimen
(
"
pagebackgrounddepth
"
)
*
factor
end
)
104
registerdirect
(
"
LayoutColumns
"
,
function
(
)
return
getcount
(
"
layoutcolumns
"
)
end
)
105
registerdirect
(
"
LayoutColumnDistance
"
,
function
(
)
return
getdimen
(
"
layoutcolumndistance
"
)
*
factor
end
)
106
registerdirect
(
"
LayoutColumnWidth
"
,
function
(
)
return
getdimen
(
"
layoutcolumnwidth
"
)
*
factor
end
)
107
registerdirect
(
"
SpineWidth
"
,
function
(
)
return
getdimen
(
"
spinewidth
"
)
*
factor
end
)
108
registerdirect
(
"
PaperBleed
"
,
function
(
)
return
getdimen
(
"
paperbleed
"
)
*
factor
end
)
109 110
registerdirect
(
"
RealPageNumber
"
,
function
(
)
return
getcount
(
"
realpageno
"
)
end
)
111
registerdirect
(
"
LastPageNumber
"
,
function
(
)
return
getcount
(
"
lastpageno
"
)
end
)
112 113
registerdirect
(
"
PageNumber
"
,
function
(
)
return
getcount
(
"
pageno
"
)
end
)
114
registerdirect
(
"
NOfPages
"
,
function
(
)
return
getcount
(
"
lastpageno
"
)
end
)
115 116
registerdirect
(
"
SubPageNumber
"
,
function
(
)
return
getcount
(
"
subpageno
"
)
end
)
117
registerdirect
(
"
NOfSubPages
"
,
function
(
)
return
getcount
(
"
lastsubpageno
"
)
end
)
118 119
registerdirect
(
"
CurrentColumn
"
,
function
(
)
return
getcount
(
"
mofcolumns
"
)
end
)
120
registerdirect
(
"
NOfColumns
"
,
function
(
)
return
getcount
(
"
nofcolumns
"
)
end
)
121 122
registerdirect
(
"
BaseLineSkip
"
,
function
(
)
return
get
(
"
baselineskip
"
,
true
)
*
factor
end
)
123
registerdirect
(
"
LineHeight
"
,
function
(
)
return
getdimen
(
"
lineheight
"
)
*
factor
end
)
124
registerdirect
(
"
BodyFontSize
"
,
function
(
)
return
getdimen
(
"
bodyfontsize
"
)
*
factor
end
)
125 126
registerdirect
(
"
TopSkip
"
,
function
(
)
return
get
(
"
topskip
"
,
true
)
*
factor
end
)
127
registerdirect
(
"
StrutHeight
"
,
function
(
)
return
getdimen
(
"
strutht
"
)
*
factor
end
)
128
registerdirect
(
"
StrutDepth
"
,
function
(
)
return
getdimen
(
"
strutdp
"
)
*
factor
end
)
129 130
registerdirect
(
"
PageNumber
"
,
function
(
)
return
getcount
(
"
pageno
"
)
end
)
131
registerdirect
(
"
RealPageNumber
"
,
function
(
)
return
getcount
(
"
realpageno
"
)
end
)
132
registerdirect
(
"
NOfPages
"
,
function
(
)
return
getcount
(
"
lastpageno
"
)
end
)
133 134
registerdirect
(
"
CurrentWidth
"
,
function
(
)
return
get
(
"
hsize
"
)
*
factor
end
)
135
registerdirect
(
"
CurrentHeight
"
,
function
(
)
return
get
(
"
vsize
"
)
*
factor
end
)
136 137
registerdirect
(
"
EmWidth
"
,
function
(
)
return
emwidths
[
false
]
*
factor
end
)
138
registerdirect
(
"
ExHeight
"
,
function
(
)
return
exheights
[
false
]
*
factor
end
)
139 140
registerdirect
(
"
HSize
"
,
function
(
)
return
get
(
"
hsize
"
)
*
factor
end
)
141
registerdirect
(
"
VSize
"
,
function
(
)
return
get
(
"
vsize
"
)
*
factor
end
)
142
registerdirect
(
"
LastPageNumber
"
,
function
(
)
return
getcount
(
"
lastpageno
"
)
end
)
143 144
registerdirect
(
"
OverlayWidth
"
,
function
(
)
return
getdimen
(
"
d_overlay_width
"
)
*
factor
end
)
145
registerdirect
(
"
OverlayHeight
"
,
function
(
)
return
getdimen
(
"
d_overlay_height
"
)
*
factor
end
)
146
registerdirect
(
"
OverlayDepth
"
,
function
(
)
return
getdimen
(
"
d_overlay_depth
"
)
*
factor
end
)
147
registerdirect
(
"
OverlayLineWidth
"
,
function
(
)
return
getdimen
(
"
d_overlay_linewidth
"
)
*
factor
end
)
148
registerdirect
(
"
OverlayOffset
"
,
function
(
)
return
getdimen
(
"
d_overlay_offset
"
)
*
factor
end
)
149
registerdirect
(
"
OverlayRegion
"
,
function
(
)
return
getmacro
(
"
m_overlay_region
"
)
end
)
150
--------------("CurrentLayout", function() return getmacro("currentlayout") end)
151 152
-- registerscript("PageFraction", function() return mpboolean(page_fraction ()) end)
153
-- registerscript("OnRightPage", function() return mpboolean(on_right_page ()) end)
154
-- registerscript("OnOddPage", function() return mpboolean(is_odd_page ()) end)
155
-- registerscript("InPageBody", function() return mpboolean(in_body_page ()) end)
156
-- registerscript("LayoutHasChanged", function() return mpboolean(layout_has_changed()) end)
157 158
registerdirect
(
"
PageFraction
"
,
function
(
)
return
page_fraction
(
)
end
)
159
registerdirect
(
"
OnRightPage
"
,
function
(
)
return
on_right_page
(
)
end
)
160
registerdirect
(
"
OnOddPage
"
,
function
(
)
return
is_odd_page
(
)
end
)
161
registerdirect
(
"
InPageBody
"
,
function
(
)
return
in_body_page
(
)
end
)
162
registerdirect
(
"
LayoutHasChanged
"
,
function
(
)
return
layout_has_changed
(
)
end
)
163 164
registerdirect
(
"
PageFraction
"
,
page_fraction
)
165
registerdirect
(
"
OnRightPage
"
,
on_right_page
)
166
registerdirect
(
"
OnOddPage
"
,
is_odd_page
)
167
registerdirect
(
"
InPageBody
"
,
in_body_page
)
168
registerdirect
(
"
LayoutHasChanged
"
,
layout_has_changed
)
169 170
registerdirect
(
"
defaultcolormodel
"
,
defaultcolormodel
)
171