summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/meta-tex.mkiv
blob: 418ddc1966a10371c918130b45abb28528253b07 (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
%D \module
%D   [       file=meta-tex,
%D        version=2006.06.07,
%D          title=\CONTEXT\ Support Macros,
%D       subtitle=\METAPOST\ fast text insertion,
%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.

\registerctxluafile{meta-tex}{}

\unprotect

% Ok, we support this in MkIV because Mojca kept the pressure on. It
% looks a bit like a hack. But in fact this method is obsolete and
% eventually might go away.

\installcorenamespace{graphictextext}
\installcorenamespace{graphictexdepth}
\installcorenamespace{graphictexarguments}

\unexpanded\def\startTeXtexts#1\stopTeXtexts
  {#1}

\let\stopTeXtexts\relax

\unexpanded\def\TeXtext
  {\dosingleempty\meta_textext}

\def\meta_textext[#1]#2#3% contrary to mkii we don't process yet but we do expand
  {\setxvalue{\??graphictextext#2}{\meta_textext_indeed{#1}{#3}}}

\unexpanded\def\meta_textext_indeed#1#2%
  {\begingroup
   \setbox\nextbox\hbox{#2}%
   \ifcsname\??graphictexdepth#1\endcsname
     \lastnamedcs
   \else
     \syst_boxes_lower_nextbox_dp
   \fi
   \box\nextbox
   \endgroup}

\def\getTeXtext#1%
  {\begincsname\??graphictextext#1\endcsname}

\letvalue{\??graphictexdepth         d}\syst_boxes_lower_nextbox_dp
\letvalue{\??graphictexdepth  \s!depth}\syst_boxes_lower_nextbox_dp
\letvalue{\??graphictexdepth         n}\donothing
\letvalue{\??graphictexdepth\s!nodepth}\donothing

% \definetextext[framed]{\framed}
%
% \startMPcode
%     draw \sometxt[framed]{black} rotated 45 ;
% \stopMPcode
%
% But Mojca wanted more! Two arguments.
%
% \definetextext[framed]{\framed}
%
% \startMPcode
%     draw \sometxt{This is for} rotated 45 ;
%     draw \sometxt[framed][foregroundstyle=bold]{Mojca's};
%     draw \sometxt[framed]{eyes only!} rotated -45 ;
% \stopMPcode

\unexpanded\def\definetextext[#1]%
  {\def\currenttextext{#1}%
   \doifelsenextoptionalcs\meta_textext_define_one\meta_textext_define_zero}

\def\meta_textext_define_one {\setvalue{\??graphictexarguments1:\currenttextext}}
\def\meta_textext_define_zero{\setvalue{\??graphictexarguments0:\currenttextext}}

\def\sometxt#1#{\meta_some_txt{#1}}

\def\meta_some_txt#1#2% we need to capture embedded quotes (a bit messy as later on textext is filtered
  {textext.drt("\mpsometxt#1{\clf_metapostescaped{#2}}")}

\unexpanded\def\mpsometxt % no _ catcode
  {\doifelsenextoptionalcs\meta_some_txt_indeed_yes\meta_some_txt_indeed_nop}

\def\meta_some_txt_indeed_yes[#1]%
  {\def\currenttextext{#1}%
   \csname\??graphictexarguments
     \ifcsname\??graphictexarguments0:#1\endcsname0\else
     \ifcsname\??graphictexarguments1:#1\endcsname1\else
                                       ?\fi\fi
   \endcsname}

\def\meta_some_txt_indeed_nop
  {}

\setvalue{\??graphictexarguments ?}{}
\setvalue{\??graphictexarguments 0}{\csname\??graphictexarguments\currenttextext\endcsname}
\setvalue{\??graphictexarguments 1}{\dosingleempty\meta_gx_one}

\def\meta_gx_one{\csname\??graphictexarguments1:\currenttextext\endcsname}

% \definetextext[framed][#1]#2{\framed[width=4cm]{\switchtobodyfont[#1]#2}}
% \definetextext[simple]{\framed[width=8cm]}
%
%  \starttext
%
%  \startMPcode
%      draw \sometxt{This is for} rotated 45 ;
%      draw \sometxt[framed][ss,16pt] {Mojca's};
%      draw \sometxt[framed]{eyes only!} rotated -45 ;
%      draw \sometxt[simple]{Quotes "indeed" work!} rotated 180 ;
%  \stopMPcode
%
% \stoptext
%
% a lua one:
%
% \unexpanded\def\definetextext[#1]#2{\setvalue{@@st@@#1}{#2}}
%
%       \def\sometxt         #1#{\dosometxt{#1}}  % grab optional [args]
%       \def\dosometxt      #1#2{\ctxlua{metapost.sometxt(\!!bs#1\!!es,\!!bs#2\!!es)}}
%
%            \def\sometxta         #1{textext.drt("#1")}
%            \def\sometxtb       #1#2{textext.drt("\getvalue{@@st@@#1}{#2}")}
%            \def\sometxtc     #1#2#3{textext.drt("\getvalue{@@st@@#1}{\switchtobodyfont[#2]#3}")}

% Best use the mp macro instead since it provides positioning.
%
% \startuseMPgraphic{testgraphic}
% draw \sometxt{\ruledhbox{\strut hans hagen}} scaled 3;
% % draw textext.drt("\ruledhbox{\strut hans hagen}") scaled 3;
% % draw textext.dlft("\ruledhbox{\strut hans hagen}") scaled 3;
% % draw textext.lft("\ruledhbox{\strut hans hagen}") scaled 3;
% draw llcorner currentpicture -- urcorner currentpicture withcolor yellow;
% draw lrcorner currentpicture -- ulcorner currentpicture withcolor yellow;
% draw boundingbox currentpicture withcolor blue ;
% draw origin withcolor red withpen pencircle scaled 1pt;
% \stopuseMPgraphic
%
% {\showstruts\useMPgraphic{testgraphic}}

\unexpanded\def\MPexponent   #1#2{\mathematics{#1\times10^{#2}}}
\unexpanded\def\MPformatted  #1#2{\clf_metapostformatted{#1}{#2}}
\unexpanded\def\MPgraphformat#1#2{\clf_metapostgraphformat{#1}{#2}}

%D Some new fun (but exprimental for a while):

\unexpanded\def\MPLIBoutlinetext#1#2#3% index kind text
  {\begingroup
   \setbox\scratchbox\hbox{#3}%
   \clf_MPLIBconvertoutlinetext\numexpr#1\relax{#2}\scratchbox
   \endgroup}

%D For now here. We don't do the whole thing, because then one can as
%D well just export to pdf. We assume consistent integration.

\definefontsynonym[serif-normal-normal] [\s!Serif]
\definefontsynonym[serif-normal-italic] [\s!SerifItalic]
\definefontsynonym[serif-normal-oblique][\s!SerifSlanted]
\definefontsynonym[serif-bold-normal]   [\s!SerifBold]
\definefontsynonym[serif-bold-italic]   [\s!SerifBoldItalic]
\definefontsynonym[serif-bold-oblique]  [\s!SerifBoldSlanted]

\definefontsynonym[sans-normal-normal]  [\s!Sans]
\definefontsynonym[sans-normal-italic]  [\s!SansItalic]
\definefontsynonym[sans-normal-oblique] [\s!SansSlanted]
\definefontsynonym[sans-bold-normal]    [\s!SansBold]
\definefontsynonym[sans-bold-italic]    [\s!SansBoldItalic]
\definefontsynonym[sans-bold-oblique]   [\s!SansBoldSlanted]

\definefontsynonym[mono-normal-normal]  [\s!Mono]
\definefontsynonym[mono-normal-italic]  [\s!MonoItalic]
\definefontsynonym[mono-normal-oblique] [\s!MonoSlanted]
\definefontsynonym[mono-bold-normal]    [\s!MonoBold]
\definefontsynonym[mono-bold-italic]    [\s!MonoBoldItalic]
\definefontsynonym[mono-bold-oblique]   [\s!MonoBoldSlanted]

\installcorenamespace {svgfamily}

\setvalue{\??svgfamily      }{serif}
\setvalue{\??svgfamily serif}{serif}
\setvalue{\??svgfamily  sans}{sans}
\setvalue{\??svgfamily  mono}{mono}

%D This can't change because otherwise \type {\scale[width=4cm]{graphic}} fails.

\unexpanded\def\svgscaled#1%
  {\fastsxsy{#1}{#1}\svgnormal}

\unexpanded\def\svgnormal#1#2#3#4% family weight style text
  {\bgroup
   \edef\p_family{#1}%
   \ifx\p_family\empty\else
      \edef\p_font{\ifcsname\??svgfamily#1\endcsname\lastnamedcs\else#1\fi-#2-#3}%
      \predefinedfont[\s!spec:\p_font*\s!default\space @ 10bp]%
   \fi
   #4%
   \egroup}

\unexpanded\def\svgcolored#1#2#3#4% r g b text
  {\colored[r=#1,g=#2,b=#3]{#4}}

\unexpanded\def\svgplaced#1#2#3#4% dx dy width text
  {\doifelsenothing{#3}%
     {\hpack}%
     {\hpack to #3}%
     {\raise#2\onebasepoint\hbox{\kern#1\onebasepoint\relax#4}}}

\newdimen\grph_svg_scratchwidth % maybe \startsvgpos etc

\unexpanded\def\svgposchar#1#2#3% dx dy char
  {\setbox\scratchbox\hpack\bgroup
     \raise#2\onebasepoint\hbox\bgroup
        \kern\dimexpr#1\onebasepoint-\grph_svg_scratchwidth\relax
        \char#3\relax
     \egroup
   \egroup
   \advance\grph_svg_scratchwidth\wd\scratchbox
   \box\scratchbox}

\unexpanded\def\svgchar#1% char
  {\char#1\relax}

\definelayer[svgmps][\c!method=\v!fit]

\unexpanded\def\svgstartlayer
  {\resetlayer[svgmps]%
   \setlayer[svgmps]\bgroup}

\unexpanded\def\svgstoplayer
  {\egroup
   \flushlayer[svgmps]}

\unexpanded\def\svgsetlayer#1#2%
  {\setlayer[svgmps][\c!x=#1\onebasepoint,\c!y=#2\onebasepoint]} % {#3}

\protect \endinput