1
2
3
4
5
6
7
8
9
10
11
12
13
14\registerctxluafile{mescrito}{}
15
16
17
18
19
20
21
22
23
24
25
26
27
28\unprotect
29
30\unexpanded\def\startESCRITOgraphic#1#2#3#4
31 {\dontleavehmode
32 \begingroup
33 \MPllx#1\onebasepoint
34 \MPlly#2\onebasepoint
35 \MPurx#3\onebasepoint
36 \MPury#4\onebasepoint
37 \setbox\b_meta_graphic\hbox\bgroup}
38
39\unexpanded\def\stopESCRITOgraphic
40 {\egroup
41 \setbox\b_meta_graphic\ruledhbox\bgroup
42 \kern\MPllx\raise\MPlly\box\b_meta_graphic
43 \egroup
44 \wd\b_meta_graphic\dimexpr\MPurx\MPllx\relax
45 \ht\b_meta_graphic\dimexpr\MPury\MPlly\relax
46 \dp\b_meta_graphic\zeropoint
47 \box\b_meta_graphic
48 \endgroup}
49
50\unexpanded\def\flushESCRITOtext#1#2#3
51 {\smash{\rlap{\definedfont[#1 at #2bp]#3}}}
52
53\unexpanded\def\stopESCRITO
54 {\edef\p_option{\namedbufferparameter{ESCRITO}\c!option}
55 \ctxlua{escrito.convert {
56 buffer = "\thedefinedbuffer{ESCRITO}",
57 calculatebox = \ifx\p_option\v!fit true\else false\fi,
58 }}}
59
60\unexpanded\def\processESCRITO[#1]
61 {\begingroup
62 \getdummyparameters[\c!file=,\c!option=,#1]
63 \edef\p_option{\dummyparameter\c!option}
64 \ctxlua{escrito.convert {
65 filename = "\dummyparameter\c!file",
66 calculatebox = \ifx\p_option\v!fit true\else false\fi,
67 }}
68 \endgroup}
69
70\definebuffer
71 [ESCRITO]
72
73\setupbuffer
74 [ESCRITO]
75 [\c!option=,
76 \c!after=\processESCRITO]
77
78\protect
79
80
81
82
83\startluacode
84
85 local p = escrito.devices.pdf
86
87 function p.startpage(llx,lly,urx,ury)
88 context.startESCRITOgraphic(llx,lly,urx,ury)
89 end
90
91 function p.stoppage()
92 context.stopESCRITOgraphic()
93 end
94
95 function p.flushpage(result)
96 context.pdfliteral(result)
97 end
98
99
100
101 local fontnames = { }
102 local fontfiles = { }
103
104 fontnames['NimbusSanL-Regu'] = 'Sans'
105 fontnames['StandardSymL'] = 'rpsyr'
106 fontnames['dejavuserif-regular'] = 'dejavuserif-regular'
107
108 function p.showfont(object)
109 local color = object.color
110 local ctype = object.colortype
111 local matrix = object.matrix
112 local text = object.string
113 local size = object.fontmatrix[1] * 1000
114 local result = { "q" }
115 context(newliteral(formatters['%f %f %f %f %f %f cm'](matrix[1],matrix[2],matrix[3],matrix[4],matrix[5],matrix[6])))
116 if ctype == "rgb" then
117 local r, g, b = color[1], color[2], color[3]
118 context(newliteral(formatters["%f %f %f rg %f %f %f RG"](r,g,b,r,g,b)))
119 elseif ctype == "cmyk" then
120 local c, m, y, k = color[1], color[2], color[3], color[4]
121 context(newliteral(formatters["%f %f %f k %f %f %f K"](c,m,y,k,c,m,y,k)))
122 elseif ctype == "gray" then
123 context(newliteral(formatters["%f g %f G"](color,color)))
124 end
125 context.flushESCRITOtext(fontnames[object.fontname],size,text)
126 context(newliteral("Q"))
127 end
128
129 local function findfont(fontname)
130 return fontfiles[fontname]
131 end
132
133\stopluacode
134
135\continueifinputfile{mescrito.mkiv}
136
137\starttext
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157\startTEXpage
158 \startESCRITO
159 (tiger.eps) run
160 \stopESCRITO
161\stopTEXpage
162
163\startTEXpage
164 \setupbuffer[ESCRITO][option=fit]
165 \startESCRITO
166 (tiger.eps) run
167 \stopESCRITO
168\stopTEXpage
169
170\startTEXpage
171 \processESCRITO[file=tiger.eps]
172\stopTEXpage
173
174\startTEXpage
175 \processESCRITO[file=tiger.eps,option=fit]
176\stopTEXpage
177
178\stoptext
179
180 |