1use crate::engine::commands::CLOSE_FONT;
2use crate::engine::{CSName, Font, Types};
3use tex_engine::commands::primitives::{PrimitiveCommands, PrimitiveIdentifier};
4use tex_engine::commands::{PrimitiveCommand, TeXCommand};
5use tex_engine::engine::mouth::Mouth;
6use tex_engine::engine::state::{GroupType, State, StateChangeTracker, StateStack};
7use tex_engine::engine::{state, EngineAux, EngineTypes};
8use tex_engine::prelude::*;
9use tex_engine::tex::catcodes::{CategoryCode, CategoryCodeScheme};
10use tex_engine::tex::nodes::boxes::TeXBox;
11use tex_engine::tex::numerics::{Dim32, Mu, MuSkip, Skip};
12use tex_engine::tex::tokens::control_sequences::CSNameVec;
13use tex_engine::tex::tokens::CompactToken;
14use tex_engine::tex::tokens::Token;
15
16#[derive(Clone)]
17pub struct RusTeXState(state::tex_state::DefaultState<Types>);
18impl RusTeXState {
19 pub fn destruct(self) -> CSNameVec<u8, TeXCommand<Types>> {
20 self.0.commands
21 }
22 pub fn set_command_direct(&mut self, name: CSName, cmd: Option<TeXCommand<Types>>) {
23 self.0.set_command_direct(name, cmd)
24 }
25}
26impl StateChangeTracker<Types> for RusTeXState {
27 fn stack(&mut self) -> &mut StateStack<Types> {
28 self.0.stack()
29 }
30}
31impl State<Types> for RusTeXState {
32 fn new(nullfont: Font, aux: &mut EngineAux<Types>) -> Self {
33 Self(state::tex_state::DefaultState::new(nullfont, aux))
34 }
35 fn register_primitive(
36 &mut self,
37 aux: &mut EngineAux<Types>,
38 name: &'static str,
39 cmd: PrimitiveCommand<Types>,
40 ) {
41 self.0.register_primitive(aux, name, cmd)
42 }
43
44 fn primitives(&self) -> &PrimitiveCommands<Types> {
45 self.0.primitives()
46 }
47
48 fn aftergroup(&mut self, token: CompactToken) {
49 self.0.aftergroup(token)
50 }
51
52 fn push(&mut self, aux: &mut EngineAux<Types>, group_type: GroupType, line_number: usize) {
53 self.0.push(aux, group_type, line_number);
54 aux.extension.push();
55 }
56
57 fn pop(&mut self, aux: &mut EngineAux<Types>, mouth: &mut <Types as EngineTypes>::Mouth) {
58 self.0.pop(aux, mouth);
59 let closefont = CompactToken::from_cs(aux.memory.cs_interner_mut().cs_from_str(CLOSE_FONT));
60 for _ in 0..aux.extension.pop() {
61 mouth.requeue(closefont);
62 }
63 }
64
65 fn get_group_type(&self) -> Option<GroupType> {
66 self.0.get_group_type()
67 }
68
69 fn get_group_level(&self) -> usize {
70 self.0.get_group_level()
71 }
72
73 fn get_current_font(&self) -> &Font {
74 self.0.get_current_font()
75 }
76
77 fn get_textfont(&self, i: u8) -> &<Types as EngineTypes>::Font {
78 self.0.get_textfont(i)
79 }
80
81 fn set_textfont(
82 &mut self,
83 aux: &mut EngineAux<Types>,
84 idx: u8,
85 fnt: <Types as EngineTypes>::Font,
86 globally: bool,
87 ) {
88 self.0.set_textfont(aux, idx, fnt, globally)
89 }
90
91 fn get_scriptfont(&self, i: u8) -> &<Types as EngineTypes>::Font {
92 self.0.get_scriptfont(i)
93 }
94
95 fn set_scriptfont(
96 &mut self,
97 aux: &mut EngineAux<Types>,
98 idx: u8,
99 fnt: <Types as EngineTypes>::Font,
100 globally: bool,
101 ) {
102 self.0.set_scriptfont(aux, idx, fnt, globally)
103 }
104
105 fn get_scriptscriptfont(&self, i: u8) -> &<Types as EngineTypes>::Font {
106 self.0.get_scriptscriptfont(i)
107 }
108
109 fn set_scriptscriptfont(
110 &mut self,
111 aux: &mut EngineAux<Types>,
112 idx: u8,
113 fnt: <Types as EngineTypes>::Font,
114 globally: bool,
115 ) {
116 self.0.set_scriptscriptfont(aux, idx, fnt, globally)
117 }
118
119 fn set_current_font(&mut self, aux: &mut EngineAux<Types>, fnt: Font, globally: bool) {
120 self.0.set_current_font(aux, fnt, globally)
121 }
122
123 fn get_catcode_scheme(&self) -> &CategoryCodeScheme<u8> {
124 self.0.get_catcode_scheme()
125 }
126
127 fn set_catcode(&mut self, aux: &EngineAux<Types>, c: u8, cc: CategoryCode, globally: bool) {
128 self.0.set_catcode(aux, c, cc, globally)
129 }
130
131 fn get_sfcode(&self, c: u8) -> u16 {
132 self.0.get_sfcode(c)
133 }
134
135 fn set_sfcode(&mut self, aux: &EngineAux<Types>, c: u8, sfcode: u16, globally: bool) {
136 self.0.set_sfcode(aux, c, sfcode, globally)
137 }
138
139 fn get_lccode(&self, c: u8) -> u8 {
140 self.0.get_lccode(c)
141 }
142
143 fn set_lccode(&mut self, aux: &EngineAux<Types>, c: u8, lccode: u8, globally: bool) {
144 self.0.set_lccode(aux, c, lccode, globally)
145 }
146
147 fn get_uccode(&self, c: u8) -> u8 {
148 self.0.get_uccode(c)
149 }
150
151 fn set_uccode(&mut self, aux: &EngineAux<Types>, c: u8, uccode: u8, globally: bool) {
152 self.0.set_uccode(aux, c, uccode, globally)
153 }
154
155 fn get_delcode(&self, c: u8) -> i32 {
156 self.0.get_delcode(c)
157 }
158
159 fn set_delcode(&mut self, aux: &EngineAux<Types>, c: u8, delcode: i32, globally: bool) {
160 self.0.set_delcode(aux, c, delcode, globally)
161 }
162
163 fn get_mathcode(&self, c: u8) -> u32 {
164 self.0.get_mathcode(c)
165 }
166
167 fn set_mathcode(&mut self, aux: &EngineAux<Types>, c: u8, mathcode: u32, globally: bool) {
168 self.0.set_mathcode(aux, c, mathcode, globally)
169 }
170
171 fn get_endline_char(&self) -> Option<u8> {
172 self.0.get_endline_char()
173 }
174
175 fn set_endline_char(&mut self, aux: &EngineAux<Types>, c: Option<u8>, globally: bool) {
176 self.0.set_endline_char(aux, c, globally)
177 }
178
179 fn get_escape_char(&self) -> Option<u8> {
180 self.0.get_escape_char()
181 }
182
183 fn set_escape_char(&mut self, aux: &EngineAux<Types>, c: Option<u8>, globally: bool) {
184 self.0.set_escape_char(aux, c, globally)
185 }
186
187 fn get_newline_char(&self) -> Option<u8> {
188 self.0.get_newline_char()
189 }
190
191 fn set_newline_char(&mut self, aux: &EngineAux<Types>, c: Option<u8>, globally: bool) {
192 self.0.set_newline_char(aux, c, globally)
193 }
194
195 fn get_parshape(&self) -> &Vec<(Dim32, Dim32)> {
196 self.0.get_parshape()
197 }
198
199 fn take_parshape(&mut self) -> Vec<(Dim32, Dim32)> {
200 self.0.take_parshape()
201 }
202
203 fn set_parshape(
204 &mut self,
205 aux: &EngineAux<Types>,
206 parshape: Vec<(Dim32, Dim32)>,
207 globally: bool,
208 ) {
209 self.0.set_parshape(aux, parshape, globally)
210 }
211
212 fn get_int_register(&self, idx: usize) -> i32 {
213 self.0.get_int_register(idx)
214 }
215
216 fn set_int_register(&mut self, aux: &EngineAux<Types>, idx: usize, v: i32, globally: bool) {
217 self.0.set_int_register(aux, idx, v, globally)
218 }
219
220 fn get_primitive_int(&self, name: PrimitiveIdentifier) -> i32 {
221 self.0.get_primitive_int(name)
222 }
223
224 fn set_primitive_int(
225 &mut self,
226 aux: &EngineAux<Types>,
227 name: PrimitiveIdentifier,
228 v: i32,
229 globally: bool,
230 ) {
231 self.0.set_primitive_int(aux, name, v, globally)
232 }
233
234 fn get_dim_register(&self, idx: usize) -> Dim32 {
235 self.0.get_dim_register(idx)
236 }
237
238 fn set_dim_register(&mut self, aux: &EngineAux<Types>, idx: usize, v: Dim32, globally: bool) {
239 self.0.set_dim_register(aux, idx, v, globally)
240 }
241
242 fn get_skip_register(&self, idx: usize) -> Skip<Dim32> {
243 self.0.get_skip_register(idx)
244 }
245
246 fn set_skip_register(
247 &mut self,
248 aux: &EngineAux<Types>,
249 idx: usize,
250 v: Skip<Dim32>,
251 globally: bool,
252 ) {
253 self.0.set_skip_register(aux, idx, v, globally)
254 }
255
256 fn get_muskip_register(&self, idx: usize) -> MuSkip<Mu> {
257 self.0.get_muskip_register(idx)
258 }
259
260 fn set_muskip_register(
261 &mut self,
262 aux: &EngineAux<Types>,
263 idx: usize,
264 v: MuSkip<Mu>,
265 globally: bool,
266 ) {
267 self.0.set_muskip_register(aux, idx, v, globally)
268 }
269 fn get_toks_register(&self, idx: usize) -> &TokenList<CompactToken> {
270 self.0.get_toks_register(idx)
271 }
272 fn set_toks_register(
273 &mut self,
274 aux: &EngineAux<Types>,
275 idx: usize,
276 v: TokenList<CompactToken>,
277 globally: bool,
278 ) {
279 self.0.set_toks_register(aux, idx, v, globally)
280 }
281
282 fn get_box_register(&self, idx: usize) -> Option<&TeXBox<Types>> {
283 self.0.get_box_register(idx)
284 }
285
286 fn get_box_register_mut(&mut self, idx: usize) -> Option<&mut TeXBox<Types>> {
287 self.0.get_box_register_mut(idx)
288 }
289
290 fn take_box_register(&mut self, idx: usize) -> Option<TeXBox<Types>> {
291 self.0.take_box_register(idx)
292 }
293
294 fn set_box_register(
295 &mut self,
296 aux: &EngineAux<Types>,
297 idx: usize,
298 v: Option<TeXBox<Types>>,
299 globally: bool,
300 ) {
301 self.0.set_box_register(aux, idx, v, globally)
302 }
303
304 fn get_primitive_dim(&self, name: PrimitiveIdentifier) -> Dim32 {
305 self.0.get_primitive_dim(name)
306 }
307
308 fn set_primitive_dim(
309 &mut self,
310 aux: &EngineAux<Types>,
311 name: PrimitiveIdentifier,
312 v: Dim32,
313 globally: bool,
314 ) {
315 self.0.set_primitive_dim(aux, name, v, globally)
316 }
317
318 fn get_primitive_skip(&self, name: PrimitiveIdentifier) -> Skip<Dim32> {
319 self.0.get_primitive_skip(name)
320 }
321
322 fn set_primitive_skip(
323 &mut self,
324 aux: &EngineAux<Types>,
325 name: PrimitiveIdentifier,
326 v: Skip<Dim32>,
327 globally: bool,
328 ) {
329 self.0.set_primitive_skip(aux, name, v, globally)
330 }
331
332 fn get_primitive_muskip(&self, name: PrimitiveIdentifier) -> MuSkip<Mu> {
333 self.0.get_primitive_muskip(name)
334 }
335
336 fn set_primitive_muskip(
337 &mut self,
338 aux: &EngineAux<Types>,
339 name: PrimitiveIdentifier,
340 v: MuSkip<Mu>,
341 globally: bool,
342 ) {
343 self.0.set_primitive_muskip(aux, name, v, globally)
344 }
345
346 fn get_primitive_tokens(&self, name: PrimitiveIdentifier) -> &TokenList<CompactToken> {
347 self.0.get_primitive_tokens(name)
348 }
349
350 fn set_primitive_tokens(
351 &mut self,
352 aux: &EngineAux<Types>,
353 name: PrimitiveIdentifier,
354 v: TokenList<CompactToken>,
355 globally: bool,
356 ) {
357 self.0.set_primitive_tokens(aux, name, v, globally)
358 }
359
360 fn get_command(&self, name: &CSName) -> Option<&TeXCommand<Types>> {
361 self.0.get_command(name)
362 }
363
364 fn set_command(
365 &mut self,
366 aux: &EngineAux<Types>,
367 name: CSName,
368 cmd: Option<TeXCommand<Types>>,
369 globally: bool,
370 ) {
371 self.0.set_command(aux, name, cmd, globally)
372 }
373
374 fn get_ac_command(&self, c: u8) -> Option<&TeXCommand<Types>> {
375 self.0.get_ac_command(c)
376 }
377
378 fn set_ac_command(
379 &mut self,
380 aux: &EngineAux<Types>,
381 c: u8,
382 cmd: Option<TeXCommand<Types>>,
383 globally: bool,
384 ) {
385 self.0.set_ac_command(aux, c, cmd, globally)
386 }
387}