meta-tex.mkiv /size: 7958 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=meta-tex,
3%D        version=2006.06.07,
4%D          title=\CONTEXT\ Support Macros,
5%D       subtitle=\METAPOST\ fast text insertion,
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\registerctxluafile{meta-tex}{}
15
16\unprotect
17
18% Ok, we support this in MkIV because Mojca kept the pressure on. It
19% looks a bit like a hack. But in fact this method is obsolete and
20% eventually might go away.
21
22\installcorenamespace{graphictextext}
23\installcorenamespace{graphictexdepth}
24\installcorenamespace{graphictexarguments}
25
26\unexpanded\def\startTeXtexts#1\stopTeXtexts
27  {#1}
28
29\let\stopTeXtexts\relax
30
31\unexpanded\def\TeXtext
32  {\dosingleempty\meta_textext}
33
34\def\meta_textext[#1]#2#3% contrary to mkii we don't process yet but we do expand
35  {\setxvalue{\??graphictextext#2}{\meta_textext_indeed{#1}{#3}}}
36
37\unexpanded\def\meta_textext_indeed#1#2%
38  {\begingroup
39   \setbox\nextbox\hbox{#2}%
40   \ifcsname\??graphictexdepth#1\endcsname
41     \lastnamedcs
42   \else
43     \syst_boxes_lower_nextbox_dp
44   \fi
45   \box\nextbox
46   \endgroup}
47
48\def\getTeXtext#1%
49  {\begincsname\??graphictextext#1\endcsname}
50
51\letvalue{\??graphictexdepth         d}\syst_boxes_lower_nextbox_dp
52\letvalue{\??graphictexdepth  \s!depth}\syst_boxes_lower_nextbox_dp
53\letvalue{\??graphictexdepth         n}\donothing
54\letvalue{\??graphictexdepth\s!nodepth}\donothing
55
56% \definetextext[framed]{\framed}
57%
58% \startMPcode
59%     draw \sometxt[framed]{black} rotated 45 ;
60% \stopMPcode
61%
62% But Mojca wanted more! Two arguments.
63%
64% \definetextext[framed]{\framed}
65%
66% \startMPcode
67%     draw \sometxt{This is for} rotated 45 ;
68%     draw \sometxt[framed][foregroundstyle=bold]{Mojca's};
69%     draw \sometxt[framed]{eyes only!} rotated -45 ;
70% \stopMPcode
71
72\unexpanded\def\definetextext[#1]%
73  {\def\currenttextext{#1}%
74   \doifelsenextoptionalcs\meta_textext_define_one\meta_textext_define_zero}
75
76\def\meta_textext_define_one {\setvalue{\??graphictexarguments1:\currenttextext}}
77\def\meta_textext_define_zero{\setvalue{\??graphictexarguments0:\currenttextext}}
78
79\def\sometxt#1#{\meta_some_txt{#1}}
80
81\def\meta_some_txt#1#2% we need to capture embedded quotes (a bit messy as later on textext is filtered
82  {textext.drt("\mpsometxt#1{\clf_metapostescaped{#2}}")}
83
84\unexpanded\def\mpsometxt % no _ catcode
85  {\doifelsenextoptionalcs\meta_some_txt_indeed_yes\meta_some_txt_indeed_nop}
86
87\def\meta_some_txt_indeed_yes[#1]%
88  {\def\currenttextext{#1}%
89   \csname\??graphictexarguments
90     \ifcsname\??graphictexarguments0:#1\endcsname0\else
91     \ifcsname\??graphictexarguments1:#1\endcsname1\else
92                                       ?\fi\fi
93   \endcsname}
94
95\def\meta_some_txt_indeed_nop
96  {}
97
98\setvalue{\??graphictexarguments ?}{}
99\setvalue{\??graphictexarguments 0}{\csname\??graphictexarguments\currenttextext\endcsname}
100\setvalue{\??graphictexarguments 1}{\dosingleempty\meta_gx_one}
101
102\def\meta_gx_one{\csname\??graphictexarguments1:\currenttextext\endcsname}
103
104% \definetextext[framed][#1]#2{\framed[width=4cm]{\switchtobodyfont[#1]#2}}
105% \definetextext[simple]{\framed[width=8cm]}
106%
107%  \starttext
108%
109%  \startMPcode
110%      draw \sometxt{This is for} rotated 45 ;
111%      draw \sometxt[framed][ss,16pt] {Mojca's};
112%      draw \sometxt[framed]{eyes only!} rotated -45 ;
113%      draw \sometxt[simple]{Quotes "indeed" work!} rotated 180 ;
114%  \stopMPcode
115%
116% \stoptext
117%
118% a lua one:
119%
120% \unexpanded\def\definetextext[#1]#2{\setvalue{@@st@@#1}{#2}}
121%
122%       \def\sometxt         #1#{\dosometxt{#1}}  % grab optional [args]
123%       \def\dosometxt      #1#2{\ctxlua{metapost.sometxt(\!!bs#1\!!es,\!!bs#2\!!es)}}
124%
125%            \def\sometxta         #1{textext.drt("#1")}
126%            \def\sometxtb       #1#2{textext.drt("\getvalue{@@st@@#1}{#2}")}
127%            \def\sometxtc     #1#2#3{textext.drt("\getvalue{@@st@@#1}{\switchtobodyfont[#2]#3}")}
128
129% Best use the mp macro instead since it provides positioning.
130%
131% \startuseMPgraphic{testgraphic}
132% draw \sometxt{\ruledhbox{\strut hans hagen}} scaled 3;
133% % draw textext.drt("\ruledhbox{\strut hans hagen}") scaled 3;
134% % draw textext.dlft("\ruledhbox{\strut hans hagen}") scaled 3;
135% % draw textext.lft("\ruledhbox{\strut hans hagen}") scaled 3;
136% draw llcorner currentpicture -- urcorner currentpicture withcolor yellow;
137% draw lrcorner currentpicture -- ulcorner currentpicture withcolor yellow;
138% draw boundingbox currentpicture withcolor blue ;
139% draw origin withcolor red withpen pencircle scaled 1pt;
140% \stopuseMPgraphic
141%
142% {\showstruts\useMPgraphic{testgraphic}}
143
144\unexpanded\def\MPexponent   #1#2{\mathematics{#1\times10^{#2}}}
145\unexpanded\def\MPformatted  #1#2{\clf_metapostformatted{#1}{#2}}
146\unexpanded\def\MPgraphformat#1#2{\clf_metapostgraphformat{#1}{#2}}
147
148%D Some new fun (but exprimental for a while):
149
150\unexpanded\def\MPLIBoutlinetext#1#2#3% index kind text
151  {\begingroup
152   \setbox\scratchbox\hbox{#3}%
153   \clf_MPLIBconvertoutlinetext\numexpr#1\relax{#2}\scratchbox
154   \endgroup}
155
156%D For now here. We don't do the whole thing, because then one can as
157%D well just export to pdf. We assume consistent integration.
158
159\definefontsynonym[serif-normal-normal] [\s!Serif]
160\definefontsynonym[serif-normal-italic] [\s!SerifItalic]
161\definefontsynonym[serif-normal-oblique][\s!SerifSlanted]
162\definefontsynonym[serif-bold-normal]   [\s!SerifBold]
163\definefontsynonym[serif-bold-italic]   [\s!SerifBoldItalic]
164\definefontsynonym[serif-bold-oblique]  [\s!SerifBoldSlanted]
165
166\definefontsynonym[sans-normal-normal]  [\s!Sans]
167\definefontsynonym[sans-normal-italic]  [\s!SansItalic]
168\definefontsynonym[sans-normal-oblique] [\s!SansSlanted]
169\definefontsynonym[sans-bold-normal]    [\s!SansBold]
170\definefontsynonym[sans-bold-italic]    [\s!SansBoldItalic]
171\definefontsynonym[sans-bold-oblique]   [\s!SansBoldSlanted]
172
173\definefontsynonym[mono-normal-normal]  [\s!Mono]
174\definefontsynonym[mono-normal-italic]  [\s!MonoItalic]
175\definefontsynonym[mono-normal-oblique] [\s!MonoSlanted]
176\definefontsynonym[mono-bold-normal]    [\s!MonoBold]
177\definefontsynonym[mono-bold-italic]    [\s!MonoBoldItalic]
178\definefontsynonym[mono-bold-oblique]   [\s!MonoBoldSlanted]
179
180\installcorenamespace {svgfamily}
181
182\setvalue{\??svgfamily      }{serif}
183\setvalue{\??svgfamily serif}{serif}
184\setvalue{\??svgfamily  sans}{sans}
185\setvalue{\??svgfamily  mono}{mono}
186
187%D This can't change because otherwise \type {\scale[width=4cm]{graphic}} fails.
188
189\unexpanded\def\svgscaled#1%
190  {\fastsxsy{#1}{#1}\svgnormal}
191
192\unexpanded\def\svgnormal#1#2#3#4% family weight style text
193  {\bgroup
194   \edef\p_family{#1}%
195   \ifx\p_family\empty\else
196      \edef\p_font{\ifcsname\??svgfamily#1\endcsname\lastnamedcs\else#1\fi-#2-#3}%
197      \predefinedfont[\s!spec:\p_font*\s!default\space @ 10bp]%
198   \fi
199   #4%
200   \egroup}
201
202\unexpanded\def\svgcolored#1#2#3#4% r g b text
203  {\colored[r=#1,g=#2,b=#3]{#4}}
204
205\unexpanded\def\svgplaced#1#2#3#4% dx dy width text
206  {\doifelsenothing{#3}%
207     {\hpack}%
208     {\hpack to #3}%
209     {\raise#2\onebasepoint\hbox{\kern#1\onebasepoint\relax#4}}}
210
211\newdimen\grph_svg_scratchwidth % maybe \startsvgpos etc
212
213\unexpanded\def\svgposchar#1#2#3% dx dy char
214  {\setbox\scratchbox\hpack\bgroup
215     \raise#2\onebasepoint\hbox\bgroup
216        \kern\dimexpr#1\onebasepoint-\grph_svg_scratchwidth\relax
217        \char#3\relax
218     \egroup
219   \egroup
220   \advance\grph_svg_scratchwidth\wd\scratchbox
221   \box\scratchbox}
222
223\unexpanded\def\svgchar#1% char
224  {\char#1\relax}
225
226\definelayer[svgmps][\c!method=\v!fit]
227
228\unexpanded\def\svgstartlayer
229  {\resetlayer[svgmps]%
230   \setlayer[svgmps]\bgroup}
231
232\unexpanded\def\svgstoplayer
233  {\egroup
234   \flushlayer[svgmps]}
235
236\unexpanded\def\svgsetlayer#1#2%
237  {\setlayer[svgmps][\c!x=#1\onebasepoint,\c!y=#2\onebasepoint]} % {#3}
238
239\unexpanded\def\svghashed#1%
240  {\clf_svghashed#1\relax}
241
242\protect \endinput
243