mp-asnc.mpiv /size: 3352 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=mp-asnc.mpiv,
3
%D version=2012.02.19, % was mp-core: 1999.08.01, anchoring
4
%D title=\CONTEXT\ \METAPOST\ graphics,
5
%D subtitle=anchored background macros,
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
if
known
context_asnc
:
endinput
;
fi
;
15 16
boolean
context_asnc
;
context_asnc
:
=
true
;
17 18
%D This is a rather old mechanism that we once needed in an actually nice
19
%D design. Those were the times that processing a rather complex xml file
20
%D with pdftex into a 400 page document took 45 minutes (a few runs) while
21
%D nowadays with luatex and mkiv we express runtime in seconds.
22
%D
23
%D The logic is mostly the same but some work is delegated to Lua so that
24
%D we save memory and also run faster. As this was not really a used module
25
%D the interface also was upgraded. As we know the bottlenecks in mp we also
26
%D work around it a bit.
27 28
numeric
mfun_sync_count
;
29
numeric
mfun_sync_page
;
30 31
vardef
StartSync
(
expr
n
)
=
32
numeric
CurrentSyncClass
;
CurrentSyncClass
:
=
n
;
33
numeric
SyncHOffset
;
SyncHOffset
:
=
0
;
34
numeric
SyncVOffset
;
SyncVOffset
:
=
0
;
35
numeric
SyncWidth
;
SyncWidth
:
=
0
;
36
path
SyncPaths
[
]
;
37
numeric
SyncTasks
[
]
;
38
numeric
SyncKinds
[
]
;
39
%
40
mfun_sync_page
:
=
RealPageNumber
;
41
mfun_sync_count
:
=
0
;
42
enddef
;
43 44
def
StopSync
=
45
% maybe some cleanup
46
enddef
;
47 48
vardef
CollectSyncDataPage
=
49
mfun_sync_count
:
=
lua.mp.sync_collect
(
CurrentSyncClass
,
mfun_sync_page
)
;
50
enddef
;
51 52
vardef
CollectSyncDataRegion
(
expr
region
)
=
53
mfun_sync_count
:
=
lua.mp.sync_collect
(
CurrentSyncClass
,
mfun_sync_page
,
region
)
;
54
enddef
;
55 56
vardef
MakeSyncPaths
=
57
if
mfun_sync_count
>
0
:
58
save
k
,
t
,
b
;
59
save
l
;
l
:
=
SyncHOffset
;
60
save
r
;
r
:
=
SyncHOffset
+
SyncWidth
;
61
save
y
;
y
:
=
lua.mp.sync_get_y
(
)
+
SyncVOffset
;
62
for
i
=
1
upto
mfun_sync_count
:
63
k
:
=
lua.mp.sync_get_kind
(
i
)
;
64
t
:
=
lua.mp.sync_get_top
(
i
)
-
y
;
65
b
:
=
lua.mp.sync_get_bottom
(
i
)
-
y
;
66
SyncPaths
[
i
]
=
(
(
l
,
t
)
--
(
r
,
t
)
--
(
r
,
b
)
--
(
l
,
b
)
--
cycle
)
;
67
SyncTasks
[
i
]
=
lua.mp.sync_get_task
(
i
)
;
68
SyncKinds
[
i
]
=
k
;
69
endfor
;
70
fi
;
71
enddef
;
72 73
% Extend to the top of the text area.
74 75
vardef
ExtendSyncPaths
=
76
mfun_sync_count
:
=
lua.mp.sync_extend
(
)
;
77
enddef
;
78 79
% Clip to the text area.
80 81
vardef
PruneSyncPaths
=
82
mfun_sync_count
:
=
lua.mp.sync_prune
(
)
;
83
enddef
;
84 85
% Remove duplicate tasks
86 87
vardef
CollapseSyncPaths
=
88
mfun_sync_count
:
=
lua.mp.sync_collapse
(
)
;
89
enddef
;
90 91
def
SetSyncColor
(
expr
n
,
i
,
c
)
=
92
lua.mp.sync_set_color
(
n
,
i
,
c
)
;
93
enddef
;
94 95
vardef
TheSyncColor
(
expr
n
,
i
)
=
96
lua.mp.sync_get_color
(
n
,
i
)
97
enddef
;
98 99
vardef
SyncPathColor
(
expr
i
)
=
100
lua.mp.sync_get_color
(
CurrentSyncClass
,
SyncTasks
[
i
]
)
101
enddef
;
102 103
def
DrawSyncPaths
=
104
for
i
=
1
upto
NOfSyncPaths
:
105
draw
SyncPaths
[
i
]
withcolor
SyncPathColor
(
i
)
;
106
endfor
;
107
enddef
;
108 109
def
FillSyncPaths
=
110
for
i
=
1
upto
NOfSyncPaths
:
111
fill
SyncPaths
[
i
]
withcolor
SyncPathColor
(
i
)
;
112
endfor
;
113
enddef
;
114 115
vardef
NOfSyncPaths
=
116
mfun_sync_count
117
enddef
;
118