1use crate::content::Operator;
4
5#[derive(Debug, PartialEq, Clone)]
6pub struct BeginCompatibility;
7op0!(BeginCompatibility, "BX");
8
9#[derive(Debug, PartialEq, Clone)]
10pub struct EndCompatibility;
11op0!(EndCompatibility, "EX");
12
13#[derive(Debug, PartialEq, Clone)]
14pub struct SaveState;
15op0!(SaveState, "q");
16
17#[derive(Debug, PartialEq, Clone)]
18pub struct RestoreState;
19op0!(RestoreState, "Q");
20
21#[derive(Debug, PartialEq, Clone)]
22pub struct Transform(
23 pub Number,
24 pub Number,
25 pub Number,
26 pub Number,
27 pub Number,
28 pub Number,
29);
30op6!(Transform, "cm");
31
32#[derive(Debug, PartialEq, Clone)]
33pub struct LineWidth(pub Number);
34op1!(LineWidth, "w");
35
36#[derive(Debug, PartialEq, Clone)]
37pub struct LineCap(pub Number);
38op1!(LineCap, "J");
39
40#[derive(Debug, PartialEq, Clone)]
41pub struct LineJoin(pub Number);
42op1!(LineJoin, "j");
43
44#[derive(Debug, PartialEq, Clone)]
45pub struct MiterLimit(pub Number);
46op1!(MiterLimit, "M");
47
48#[derive(Debug, PartialEq, Clone)]
49pub struct DashPattern<'a>(
50 pub Array<'a>,
51 pub Number,
52);
53op2!(DashPattern<'a>, "d");
54
55#[derive(Debug, PartialEq, Clone)]
56pub struct RenderingIntent(pub Name);
57op1!(RenderingIntent, "ri");
58
59#[derive(Debug, PartialEq, Clone)]
60pub struct FlatnessTolerance(pub Number);
61op1!(FlatnessTolerance, "i");
62
63#[derive(Debug, PartialEq, Clone)]
64pub struct SetGraphicsState(pub Name);
65op1!(SetGraphicsState, "gs");
66
67#[derive(Debug, PartialEq, Clone)]
68pub struct MoveTo(
69 pub Number,
70 pub Number,
71);
72op2!(MoveTo, "m");
73
74#[derive(Debug, PartialEq, Clone)]
75pub struct LineTo(
76 pub Number,
77 pub Number,
78);
79op2!(LineTo, "l");
80
81#[derive(Debug, PartialEq, Clone)]
82pub struct CubicTo(
83 pub Number,
84 pub Number,
85 pub Number,
86 pub Number,
87 pub Number,
88 pub Number,
89);
90op6!(CubicTo, "c");
91
92#[derive(Debug, PartialEq, Clone)]
93pub struct CubicStartTo(
94 pub Number,
95 pub Number,
96 pub Number,
97 pub Number,
98);
99op4!(CubicStartTo, "v");
100
101#[derive(Debug, PartialEq, Clone)]
102pub struct CubicEndTo(
103 pub Number,
104 pub Number,
105 pub Number,
106 pub Number,
107);
108op4!(CubicEndTo, "y");
109
110#[derive(Debug, PartialEq, Clone)]
111pub struct ClosePath;
112op0!(ClosePath, "h");
113
114#[derive(Debug, PartialEq, Clone)]
115pub struct RectPath(
116 pub Number,
117 pub Number,
118 pub Number,
119 pub Number,
120);
121op4!(RectPath, "re");
122
123#[derive(Debug, PartialEq, Clone)]
124pub struct StrokePath;
125op0!(StrokePath, "S");
126
127#[derive(Debug, PartialEq, Clone)]
128pub struct CloseAndStrokePath;
129op0!(CloseAndStrokePath, "s");
130
131#[derive(Debug, PartialEq, Clone)]
132pub struct FillPathNonZero;
133op0!(FillPathNonZero, "f");
134
135#[derive(Debug, PartialEq, Clone)]
136pub struct FillPathNonZeroCompatibility;
137op0!(FillPathNonZeroCompatibility, "F");
138
139#[derive(Debug, PartialEq, Clone)]
140pub struct FillPathEvenOdd;
141op0!(FillPathEvenOdd, "f*");
142
143#[derive(Debug, PartialEq, Clone)]
144pub struct FillAndStrokeNonZero;
145op0!(FillAndStrokeNonZero, "B");
146
147#[derive(Debug, PartialEq, Clone)]
148pub struct FillAndStrokeEvenOdd;
149op0!(FillAndStrokeEvenOdd, "B*");
150
151#[derive(Debug, PartialEq, Clone)]
152pub struct CloseFillAndStrokeNonZero;
153op0!(CloseFillAndStrokeNonZero, "b");
154
155#[derive(Debug, PartialEq, Clone)]
156pub struct CloseFillAndStrokeEvenOdd;
157op0!(CloseFillAndStrokeEvenOdd, "b*");
158
159#[derive(Debug, PartialEq, Clone)]
160pub struct EndPath;
161op0!(EndPath, "n");
162
163#[derive(Debug, PartialEq, Clone)]
164pub struct ClipNonZero;
165op0!(ClipNonZero, "W");
166
167#[derive(Debug, PartialEq, Clone)]
168pub struct ClipEvenOdd;
169op0!(ClipEvenOdd, "W*");
170
171#[derive(Debug, PartialEq, Clone)]
172pub struct ColorSpaceStroke(pub Name);
173op1!(ColorSpaceStroke, "CS");
174
175#[derive(Debug, PartialEq, Clone)]
176pub struct ColorSpaceNonStroke(pub Name);
177op1!(ColorSpaceNonStroke, "cs");
178
179#[derive(Debug, PartialEq, Clone)]
180pub struct StrokeColor(pub SmallVec<[Number; OPERANDS_THRESHOLD]>);
181op_all!(StrokeColor, "SC");
182
183#[derive(Debug, PartialEq, Clone)]
184pub struct NonStrokeColor(pub SmallVec<[Number; OPERANDS_THRESHOLD]>);
185op_all!(NonStrokeColor, "sc");
186
187#[derive(Debug, PartialEq, Clone)]
188pub struct StrokeColorDeviceGray(pub Number);
189op1!(StrokeColorDeviceGray, "G");
190
191#[derive(Debug, PartialEq, Clone)]
192pub struct NonStrokeColorDeviceGray(pub Number);
193op1!(NonStrokeColorDeviceGray, "g");
194
195#[derive(Debug, PartialEq, Clone)]
196pub struct StrokeColorDeviceRgb(
197 pub Number,
198 pub Number,
199 pub Number,
200);
201op3!(StrokeColorDeviceRgb, "RG");
202
203#[derive(Debug, PartialEq, Clone)]
204pub struct NonStrokeColorDeviceRgb(
205 pub Number,
206 pub Number,
207 pub Number,
208);
209op3!(NonStrokeColorDeviceRgb, "rg");
210
211#[derive(Debug, PartialEq, Clone)]
212pub struct StrokeColorCmyk(
213 pub Number,
214 pub Number,
215 pub Number,
216 pub Number,
217);
218op4!(StrokeColorCmyk, "K");
219
220#[derive(Debug, PartialEq, Clone)]
221pub struct NonStrokeColorCmyk(
222 pub Number,
223 pub Number,
224 pub Number,
225 pub Number,
226);
227op4!(NonStrokeColorCmyk, "k");
228
229#[derive(Debug, PartialEq, Clone)]
230pub struct Shading(pub Name);
231op1!(Shading, "sh");
232
233#[derive(Debug, PartialEq, Clone)]
234pub struct XObject(pub Name);
235op1!(XObject, "Do");
236
237#[derive(Debug, PartialEq, Clone)]
238pub struct InlineImage<'a>(pub Stream<'a>);
239op1!(InlineImage<'a>, "BI");
240
241#[derive(Debug, PartialEq, Clone)]
242pub struct CharacterSpacing(pub Number);
243op1!(CharacterSpacing, "Tc");
244
245#[derive(Debug, PartialEq, Clone)]
246pub struct WordSpacing(pub Number);
247op1!(WordSpacing, "Tw");
248
249#[derive(Debug, PartialEq, Clone)]
250pub struct HorizontalScaling(pub Number);
251op1!(HorizontalScaling, "Tz");
252
253#[derive(Debug, PartialEq, Clone)]
254pub struct TextLeading(pub Number);
255op1!(TextLeading, "TL");
256
257#[derive(Debug, PartialEq, Clone)]
258pub struct TextFont(
259 pub Name,
260 pub Number,
261);
262op2!(TextFont, "Tf");
263
264#[derive(Debug, PartialEq, Clone)]
265pub struct TextRenderingMode(pub Number);
266op1!(TextRenderingMode, "Tr");
267
268#[derive(Debug, PartialEq, Clone)]
269pub struct TextRise(pub Number);
270op1!(TextRise, "Ts");
271
272#[derive(Debug, PartialEq, Clone)]
273pub struct BeginText;
274op0!(BeginText, "BT");
275
276#[derive(Debug, PartialEq, Clone)]
277pub struct EndText;
278op0!(EndText, "ET");
279
280#[derive(Debug, PartialEq, Clone)]
281pub struct NextLine(
282 pub Number,
283 pub Number,
284);
285op2!(NextLine, "Td");
286
287#[derive(Debug, PartialEq, Clone)]
288pub struct NextLineAndSetLeading(
289 pub Number,
290 pub Number,
291);
292op2!(NextLineAndSetLeading, "TD");
293
294#[derive(Debug, PartialEq, Clone)]
295pub struct SetTextMatrix(
296 pub Number,
297 pub Number,
298 pub Number,
299 pub Number,
300 pub Number,
301 pub Number,
302);
303op6!(SetTextMatrix, "Tm");
304
305#[derive(Debug, PartialEq, Clone)]
306pub struct NextLineUsingLeading;
307op0!(NextLineUsingLeading, "T*");
308
309#[derive(Debug, PartialEq, Clone)]
310pub struct ShowText(pub object::String);
311op1!(ShowText, "Tj");
312
313#[derive(Debug, PartialEq, Clone)]
314pub struct NextLineAndShowText(pub object::String);
315op1!(NextLineAndShowText, "'");
316
317#[derive(Debug, PartialEq, Clone)]
318pub struct ShowTextWithParameters(
319 pub Number,
320 pub Number,
321 pub object::String,
322);
323op3!(ShowTextWithParameters, "\"");
324
325#[derive(Debug, PartialEq, Clone)]
326pub struct ShowTexts<'a>(pub Array<'a>);
327op1!(ShowTexts<'a>, "TJ");
328
329#[derive(Debug, PartialEq, Clone)]
330pub struct ColorGlyph(
331 pub Number,
332 pub Number,
333);
334op2!(ColorGlyph, "d0");
335
336#[derive(Debug, PartialEq, Clone)]
337pub struct ShapeGlyph(
338 pub Number,
339 pub Number,
340 pub Number,
341 pub Number,
342 pub Number,
343 pub Number,
344);
345op6!(ShapeGlyph, "d1");
346
347#[derive(Debug, PartialEq, Clone)]
348pub struct MarkedContentPoint(pub Name);
349op1!(MarkedContentPoint, "MP");
350
351#[derive(Debug, PartialEq, Clone)]
352pub struct MarkedContentPointWithProperties<'a>(
353 pub Name,
354 pub Object<'a>,
355);
356op2!(MarkedContentPointWithProperties<'a>, "DP");
357
358#[derive(Debug, PartialEq, Clone)]
359pub struct BeginMarkedContent(pub Name);
360op1!(BeginMarkedContent, "BMC");
361
362#[derive(Debug, PartialEq, Clone)]
363pub struct BeginMarkedContentWithProperties<'a>(
364 pub Name,
365 pub Object<'a>,
366);
367op2!(BeginMarkedContentWithProperties<'a>, "BDC");
368
369#[derive(Debug, PartialEq, Clone)]
370pub struct EndMarkedContent;
371op0!(EndMarkedContent, "EMC");
372
373#[derive(Debug, PartialEq, Clone)]
374pub enum TypedInstruction<'a> {
375 BeginCompatibility(BeginCompatibility),
376 EndCompatibility(EndCompatibility),
377 SaveState(SaveState),
378 RestoreState(RestoreState),
379 Transform(Transform),
380 LineWidth(LineWidth),
381 LineCap(LineCap),
382 LineJoin(LineJoin),
383 MiterLimit(MiterLimit),
384 DashPattern(DashPattern<'a>),
385 RenderingIntent(RenderingIntent),
386 FlatnessTolerance(FlatnessTolerance),
387 SetGraphicsState(SetGraphicsState),
388 MoveTo(MoveTo),
389 LineTo(LineTo),
390 CubicTo(CubicTo),
391 CubicStartTo(CubicStartTo),
392 CubicEndTo(CubicEndTo),
393 ClosePath(ClosePath),
394 RectPath(RectPath),
395 StrokePath(StrokePath),
396 CloseAndStrokePath(CloseAndStrokePath),
397 FillPathNonZero(FillPathNonZero),
398 FillPathNonZeroCompatibility(FillPathNonZeroCompatibility),
399 FillPathEvenOdd(FillPathEvenOdd),
400 FillAndStrokeNonZero(FillAndStrokeNonZero),
401 FillAndStrokeEvenOdd(FillAndStrokeEvenOdd),
402 CloseFillAndStrokeNonZero(CloseFillAndStrokeNonZero),
403 CloseFillAndStrokeEvenOdd(CloseFillAndStrokeEvenOdd),
404 EndPath(EndPath),
405 ClipNonZero(ClipNonZero),
406 ClipEvenOdd(ClipEvenOdd),
407 ColorSpaceStroke(ColorSpaceStroke),
408 ColorSpaceNonStroke(ColorSpaceNonStroke),
409 StrokeColor(StrokeColor),
410 StrokeColorNamed(StrokeColorNamed),
411 NonStrokeColor(NonStrokeColor),
412 NonStrokeColorNamed(NonStrokeColorNamed),
413 StrokeColorDeviceGray(StrokeColorDeviceGray),
414 NonStrokeColorDeviceGray(NonStrokeColorDeviceGray),
415 StrokeColorDeviceRgb(StrokeColorDeviceRgb),
416 NonStrokeColorDeviceRgb(NonStrokeColorDeviceRgb),
417 StrokeColorCmyk(StrokeColorCmyk),
418 NonStrokeColorCmyk(NonStrokeColorCmyk),
419 Shading(Shading),
420 XObject(XObject),
421 InlineImage(InlineImage<'a>),
422 CharacterSpacing(CharacterSpacing),
423 WordSpacing(WordSpacing),
424 HorizontalScaling(HorizontalScaling),
425 TextLeading(TextLeading),
426 TextFont(TextFont),
427 TextRenderingMode(TextRenderingMode),
428 TextRise(TextRise),
429 BeginText(BeginText),
430 EndText(EndText),
431 NextLine(NextLine),
432 NextLineAndSetLeading(NextLineAndSetLeading),
433 SetTextMatrix(SetTextMatrix),
434 NextLineUsingLeading(NextLineUsingLeading),
435 ShowText(ShowText),
436 NextLineAndShowText(NextLineAndShowText),
437 ShowTextWithParameters(ShowTextWithParameters),
438 ShowTexts(ShowTexts<'a>),
439 ColorGlyph(ColorGlyph),
440 ShapeGlyph(ShapeGlyph),
441 MarkedContentPoint(MarkedContentPoint),
442 MarkedContentPointWithProperties(MarkedContentPointWithProperties<'a>),
443 BeginMarkedContent(BeginMarkedContent),
444 BeginMarkedContentWithProperties(BeginMarkedContentWithProperties<'a>),
445 EndMarkedContent(EndMarkedContent),
446 Fallback(Operator),
447}
448
449impl<'a> TypedInstruction<'a> {
450 #[inline(always)]
451 pub(crate) fn dispatch(instruction: &Instruction<'a>) -> Option<Self> {
452 let op_name = instruction.operator.as_ref();
453 Some(match op_name {
454 b"BX" => BeginCompatibility::from_stack(&instruction.operands)?.into(),
455 b"EX" => EndCompatibility::from_stack(&instruction.operands)?.into(),
456 b"q" => SaveState::from_stack(&instruction.operands)?.into(),
457 b"Q" => RestoreState::from_stack(&instruction.operands)?.into(),
458 b"cm" => Transform::from_stack(&instruction.operands)?.into(),
459 b"w" => LineWidth::from_stack(&instruction.operands)?.into(),
460 b"J" => LineCap::from_stack(&instruction.operands)?.into(),
461 b"j" => LineJoin::from_stack(&instruction.operands)?.into(),
462 b"M" => MiterLimit::from_stack(&instruction.operands)?.into(),
463 b"d" => DashPattern::from_stack(&instruction.operands)?.into(),
464 b"ri" => RenderingIntent::from_stack(&instruction.operands)?.into(),
465 b"i" => FlatnessTolerance::from_stack(&instruction.operands)?.into(),
466 b"gs" => SetGraphicsState::from_stack(&instruction.operands)?.into(),
467 b"m" => MoveTo::from_stack(&instruction.operands)?.into(),
468 b"l" => LineTo::from_stack(&instruction.operands)?.into(),
469 b"c" => CubicTo::from_stack(&instruction.operands)?.into(),
470 b"v" => CubicStartTo::from_stack(&instruction.operands)?.into(),
471 b"y" => CubicEndTo::from_stack(&instruction.operands)?.into(),
472 b"h" => ClosePath::from_stack(&instruction.operands)?.into(),
473 b"re" => RectPath::from_stack(&instruction.operands)?.into(),
474 b"S" => StrokePath::from_stack(&instruction.operands)?.into(),
475 b"s" => CloseAndStrokePath::from_stack(&instruction.operands)?.into(),
476 b"f" => FillPathNonZero::from_stack(&instruction.operands)?.into(),
477 b"F" => FillPathNonZeroCompatibility::from_stack(&instruction.operands)?.into(),
478 b"f*" => FillPathEvenOdd::from_stack(&instruction.operands)?.into(),
479 b"B" => FillAndStrokeNonZero::from_stack(&instruction.operands)?.into(),
480 b"B*" => FillAndStrokeEvenOdd::from_stack(&instruction.operands)?.into(),
481 b"b" => CloseFillAndStrokeNonZero::from_stack(&instruction.operands)?.into(),
482 b"b*" => CloseFillAndStrokeEvenOdd::from_stack(&instruction.operands)?.into(),
483 b"n" => EndPath::from_stack(&instruction.operands)?.into(),
484 b"W" => ClipNonZero::from_stack(&instruction.operands)?.into(),
485 b"W*" => ClipEvenOdd::from_stack(&instruction.operands)?.into(),
486 b"CS" => ColorSpaceStroke::from_stack(&instruction.operands)?.into(),
487 b"cs" => ColorSpaceNonStroke::from_stack(&instruction.operands)?.into(),
488 b"SC" => StrokeColor::from_stack(&instruction.operands)?.into(),
489 b"SCN" => StrokeColorNamed::from_stack(&instruction.operands)?.into(),
490 b"sc" => NonStrokeColor::from_stack(&instruction.operands)?.into(),
491 b"scn" => NonStrokeColorNamed::from_stack(&instruction.operands)?.into(),
492 b"G" => StrokeColorDeviceGray::from_stack(&instruction.operands)?.into(),
493 b"g" => NonStrokeColorDeviceGray::from_stack(&instruction.operands)?.into(),
494 b"RG" => StrokeColorDeviceRgb::from_stack(&instruction.operands)?.into(),
495 b"rg" => NonStrokeColorDeviceRgb::from_stack(&instruction.operands)?.into(),
496 b"K" => StrokeColorCmyk::from_stack(&instruction.operands)?.into(),
497 b"k" => NonStrokeColorCmyk::from_stack(&instruction.operands)?.into(),
498 b"sh" => Shading::from_stack(&instruction.operands)?.into(),
499 b"Do" => XObject::from_stack(&instruction.operands)?.into(),
500 b"BI" => InlineImage::from_stack(&instruction.operands)?.into(),
501 b"Tc" => CharacterSpacing::from_stack(&instruction.operands)?.into(),
502 b"Tw" => WordSpacing::from_stack(&instruction.operands)?.into(),
503 b"Tz" => HorizontalScaling::from_stack(&instruction.operands)?.into(),
504 b"TL" => TextLeading::from_stack(&instruction.operands)?.into(),
505 b"Tf" => TextFont::from_stack(&instruction.operands)?.into(),
506 b"Tr" => TextRenderingMode::from_stack(&instruction.operands)?.into(),
507 b"Ts" => TextRise::from_stack(&instruction.operands)?.into(),
508 b"BT" => BeginText::from_stack(&instruction.operands)?.into(),
509 b"ET" => EndText::from_stack(&instruction.operands)?.into(),
510 b"Td" => NextLine::from_stack(&instruction.operands)?.into(),
511 b"TD" => NextLineAndSetLeading::from_stack(&instruction.operands)?.into(),
512 b"Tm" => SetTextMatrix::from_stack(&instruction.operands)?.into(),
513 b"T*" => NextLineUsingLeading::from_stack(&instruction.operands)?.into(),
514 b"Tj" => ShowText::from_stack(&instruction.operands)?.into(),
515 b"'" => NextLineAndShowText::from_stack(&instruction.operands)?.into(),
516 b"\"" => ShowTextWithParameters::from_stack(&instruction.operands)?.into(),
517 b"TJ" => ShowTexts::from_stack(&instruction.operands)?.into(),
518 b"d0" => ColorGlyph::from_stack(&instruction.operands)?.into(),
519 b"d1" => ShapeGlyph::from_stack(&instruction.operands)?.into(),
520 b"MP" => MarkedContentPoint::from_stack(&instruction.operands)?.into(),
521 b"DP" => MarkedContentPointWithProperties::from_stack(&instruction.operands)?.into(),
522 b"BMC" => BeginMarkedContent::from_stack(&instruction.operands)?.into(),
523 b"BDC" => BeginMarkedContentWithProperties::from_stack(&instruction.operands)?.into(),
524 b"EMC" => EndMarkedContent::from_stack(&instruction.operands)?.into(),
525 _ => return Self::Fallback(instruction.operator.clone()).into(),
526 })
527 }
528}