PoDoFo 1.0.0-dev
Loading...
Searching...
No Matches
PdfConvert.h
1
7#ifndef PDF_CONVERT_H
8#define PDF_CONVERT_H
9
11
12namespace PoDoFo
13{
14 template<typename T>
15 struct Convert final
16 {
17 static std::string_view ToString(T value)
18 {
19 (void)value;
20 static_assert(always_false<T>, "Unsupported type");
21 return { };
22 }
23
24 static bool TryParse(const std::string_view& str, T& value)
25 {
26 (void)str;
27 (void)value;
28 static_assert(always_false<T>, "Unsupported type");
29 return false;
30 }
31 };
32
33 template<>
34 struct Convert<PdfColorSpaceType>
35 {
36 static std::string_view ToString(PdfColorSpaceType value)
37 {
38 using namespace std;
39 switch (value)
40 {
41 case PdfColorSpaceType::DeviceGray:
42 return "DeviceGray"sv;
43 case PdfColorSpaceType::DeviceRGB:
44 return "DeviceRGB"sv;
45 case PdfColorSpaceType::DeviceCMYK:
46 return "DeviceCMYK"sv;
47 case PdfColorSpaceType::CalGray:
48 return "CalGray"sv;
49 case PdfColorSpaceType::CalRGB:
50 return "CalRGB"sv;
52 return "Lab"sv;
53 case PdfColorSpaceType::ICCBased:
54 return "ICCBased"sv;
55 case PdfColorSpaceType::Indexed:
56 return "Indexed"sv;
57 case PdfColorSpaceType::Pattern:
58 return "Pattern"sv;
59 case PdfColorSpaceType::Separation:
60 return "Separation"sv;
61 case PdfColorSpaceType::DeviceN:
62 return "DeviceN"sv;
63 case PdfColorSpaceType::Unknown:
64 default:
65 throw PdfError(PdfErrorCode::InvalidEnumValue, __FILE__, __LINE__);
66 }
67 }
68
69 static bool TryParse(const std::string_view& str, PdfColorSpaceType& value)
70 {
71 if (str == "DeviceGray")
72 {
73 value = PdfColorSpaceType::DeviceGray;
74 return true;
75 }
76 else if (str == "DeviceRGB")
77 {
78 value = PdfColorSpaceType::DeviceRGB;
79 return true;
80 }
81 else if (str == "DeviceCMYK")
82 {
83 value = PdfColorSpaceType::DeviceCMYK;
84 return true;
85 }
86 else if (str == "CalGray")
87 {
88 value = PdfColorSpaceType::CalGray;
89 return true;
90 }
91 else if (str == "CalRGB")
92 {
93 value = PdfColorSpaceType::CalRGB;
94 return true;
95 }
96 else if (str == "Lab")
97 {
99 return true;
100 }
101 else if (str == "ICCBased")
102 {
103 value = PdfColorSpaceType::ICCBased;
104 return true;
105 }
106 else if (str == "Indexed")
107 {
108 value = PdfColorSpaceType::Indexed;
109 return true;
110 }
111 else if (str == "Pattern")
112 {
113 value = PdfColorSpaceType::Pattern;
114 return true;
115 }
116 else if (str == "Separation")
117 {
118 value = PdfColorSpaceType::Separation;
119 return true;
120 }
121 else if (str == "DeviceN")
122 {
123 value = PdfColorSpaceType::DeviceN;
124 return true;
125 }
126
127 return false;
128 }
129 };
130
131 template<>
132 struct Convert<PdfAnnotationType>
133 {
134 static std::string_view ToString(PdfAnnotationType value)
135 {
136 using namespace std;
137 switch (value)
138 {
139 case PdfAnnotationType::Text:
140 return "Text"sv;
141 case PdfAnnotationType::Link:
142 return "Link"sv;
143 case PdfAnnotationType::FreeText:
144 return "FreeText"sv;
145 case PdfAnnotationType::Line:
146 return "Line"sv;
147 case PdfAnnotationType::Square:
148 return "Square"sv;
149 case PdfAnnotationType::Circle:
150 return "Circle"sv;
151 case PdfAnnotationType::Polygon:
152 return "Polygon"sv;
153 case PdfAnnotationType::PolyLine:
154 return "PolyLine"sv;
155 case PdfAnnotationType::Highlight:
156 return "Highlight"sv;
157 case PdfAnnotationType::Underline:
158 return "Underline"sv;
159 case PdfAnnotationType::Squiggly:
160 return "Squiggly"sv;
161 case PdfAnnotationType::StrikeOut:
162 return "StrikeOut"sv;
163 case PdfAnnotationType::Stamp:
164 return "Stamp"sv;
165 case PdfAnnotationType::Caret:
166 return "Caret"sv;
167 case PdfAnnotationType::Ink:
168 return "Ink"sv;
169 case PdfAnnotationType::Popup:
170 return "Popup"sv;
171 case PdfAnnotationType::FileAttachement:
172 return "FileAttachment"sv;
173 case PdfAnnotationType::Sound:
174 return "Sound"sv;
175 case PdfAnnotationType::Movie:
176 return "Movie"sv;
177 case PdfAnnotationType::Widget:
178 return "Widget"sv;
179 case PdfAnnotationType::Screen:
180 return "Screen"sv;
181 case PdfAnnotationType::PrinterMark:
182 return "PrinterMark"sv;
183 case PdfAnnotationType::TrapNet:
184 return "TrapNet"sv;
185 case PdfAnnotationType::Watermark:
186 return "Watermark"sv;
187 case PdfAnnotationType::Model3D:
188 return "3D"sv;
189 case PdfAnnotationType::RichMedia:
190 return "RichMedia"sv;
191 case PdfAnnotationType::WebMedia:
192 return "WebMedia"sv;
193 case PdfAnnotationType::Redact:
194 return "Redact"sv;
195 case PdfAnnotationType::Projection:
196 return "Projection"sv;
197 default:
198 throw PdfError(PdfErrorCode::InvalidEnumValue, __FILE__, __LINE__);
199 }
200 }
201
202 static bool TryParse(const std::string_view& str, PdfAnnotationType& value)
203 {
204 using namespace std;
205 if (str == "Text"sv)
206 {
207 value = PdfAnnotationType::Text;
208 return true;
209 }
210 else if (str == "Link"sv)
211 {
212 value = PdfAnnotationType::Link;
213 return true;
214 }
215 else if (str == "FreeText"sv)
216 {
217 value = PdfAnnotationType::FreeText;
218 return true;
219 }
220 else if (str == "Line"sv)
221 {
222 value = PdfAnnotationType::Line;
223 return true;
224 }
225 else if (str == "Square"sv)
226 {
227 value = PdfAnnotationType::Square;
228 return true;
229 }
230 else if (str == "Circle"sv)
231 {
232 value = PdfAnnotationType::Circle;
233 return true;
234 }
235 else if (str == "Polygon"sv)
236 {
237 value = PdfAnnotationType::Polygon;
238 return true;
239 }
240 else if (str == "PolyLine"sv)
241 {
242 value = PdfAnnotationType::PolyLine;
243 return true;
244 }
245 else if (str == "Highlight"sv)
246 {
247 value = PdfAnnotationType::Highlight;
248 return true;
249 }
250 else if (str == "Underline"sv)
251 {
252 value = PdfAnnotationType::Underline;
253 return true;
254 }
255 else if (str == "Squiggly"sv)
256 {
257 value = PdfAnnotationType::Squiggly;
258 return true;
259 }
260 else if (str == "StrikeOut"sv)
261 {
262 value = PdfAnnotationType::StrikeOut;
263 return true;
264 }
265 else if (str == "Stamp"sv)
266 {
267 value = PdfAnnotationType::Stamp;
268 return true;
269 }
270 else if (str == "Caret"sv)
271 {
272 value = PdfAnnotationType::Caret;
273 return true;
274 }
275 else if (str == "Ink"sv)
276 {
277 value = PdfAnnotationType::Ink;
278 return true;
279 }
280 else if (str == "Popup"sv)
281 {
282 value = PdfAnnotationType::Popup;
283 return true;
284 }
285 else if (str == "FileAttachment"sv)
286 {
287 value = PdfAnnotationType::FileAttachement;
288 return true;
289 }
290 else if (str == "Sound"sv)
291 {
292 value = PdfAnnotationType::Sound;
293 return true;
294 }
295 else if (str == "Movie"sv)
296 {
297 value = PdfAnnotationType::Movie;
298 return true;
299 }
300 else if (str == "Widget"sv)
301 {
302 value = PdfAnnotationType::Widget;
303 return true;
304 }
305 else if (str == "Screen"sv)
306 {
307 value = PdfAnnotationType::Screen;
308 return true;
309 }
310 else if (str == "PrinterMark"sv)
311 {
312 value = PdfAnnotationType::PrinterMark;
313 return true;
314 }
315 else if (str == "TrapNet"sv)
316 {
317 value = PdfAnnotationType::TrapNet;
318 return true;
319 }
320 else if (str == "Watermark"sv)
321 {
322 value = PdfAnnotationType::Watermark;
323 return true;
324 }
325 else if (str == "3D"sv)
326 {
327 value = PdfAnnotationType::Model3D;
328 return true;
329 }
330 else if (str == "RichMedia"sv)
331 {
332 value = PdfAnnotationType::RichMedia;
333 return true;
334 }
335 else if (str == "WebMedia"sv)
336 {
337 value = PdfAnnotationType::WebMedia;
338 return true;
339 }
340 else if (str == "Redact"sv)
341 {
342 value = PdfAnnotationType::Redact;
343 return true;
344 }
345 else if (str == "Projection"sv)
346 {
347 value = PdfAnnotationType::Projection;
348 return true;
349 }
350 else
351 {
352 return false;
353 }
354 }
355 };
356
357 template<>
358 struct Convert<PdfRenderingIntent>
359 {
360 static std::string_view ToString(PdfRenderingIntent value)
361 {
362 using namespace std;
363 switch (value)
364 {
365 case PdfRenderingIntent::AbsoluteColorimetric:
366 return "AbsoluteColorimetric"sv;
367 case PdfRenderingIntent::RelativeColorimetric:
368 return "RelativeColorimetric"sv;
369 case PdfRenderingIntent::Perceptual:
370 return "Perceptual"sv;
371 case PdfRenderingIntent::Saturation:
372 return "Saturation"sv;
373 case PdfRenderingIntent::Unknown:
374 default:
375 throw PdfError(PdfErrorCode::InvalidEnumValue, __FILE__, __LINE__);
376 }
377 }
378
379 static bool TryParse(const std::string_view& str, PdfRenderingIntent& value)
380 {
381 if (str == "AbsoluteColorimetric")
382 {
383 value = PdfRenderingIntent::AbsoluteColorimetric;
384 return true;
385 }
386 else if (str == "RelativeColorimetric")
387 {
388 value = PdfRenderingIntent::RelativeColorimetric;
389 return true;
390 }
391 else if (str == "Perceptual")
392 {
393 value = PdfRenderingIntent::Perceptual;
394 return true;
395 }
396 else if (str == "Saturation")
397 {
398 value = PdfRenderingIntent::Saturation;
399 return true;
400 }
401
402 return false;
403 }
404 };
405
406 template<>
407 struct Convert<PdfBlendMode>
408 {
409 static std::string_view ToString(PdfBlendMode value)
410 {
411 using namespace std;
412 switch (value)
413 {
414 case PdfBlendMode::Normal:
415 return "Normal"sv;
416 case PdfBlendMode::Multiply:
417 return "Multiply"sv;
418 case PdfBlendMode::Screen:
419 return "Screen"sv;
420 case PdfBlendMode::Overlay:
421 return "Overlay"sv;
422 case PdfBlendMode::Darken:
423 return "Darken"sv;
424 case PdfBlendMode::Lighten:
425 return "Lighten"sv;
426 case PdfBlendMode::ColorDodge:
427 return "ColorDodge"sv;
428 case PdfBlendMode::ColorBurn:
429 return "ColorBurn"sv;
430 case PdfBlendMode::HardLight:
431 return "HardLight"sv;
432 case PdfBlendMode::SoftLight:
433 return "SoftLight"sv;
434 case PdfBlendMode::Difference:
435 return "Difference"sv;
436 case PdfBlendMode::Exclusion:
437 return "Exclusion"sv;
438 case PdfBlendMode::Hue:
439 return "Hue"sv;
440 case PdfBlendMode::Saturation:
441 return "Saturation"sv;
442 case PdfBlendMode::Color:
443 return "Color"sv;
444 case PdfBlendMode::Luminosity:
445 return "Luminosity"sv;
446 case PdfBlendMode::Unknown:
447 default:
448 throw PdfError(PdfErrorCode::InvalidEnumValue, __FILE__, __LINE__);
449 }
450 }
451
452 static bool TryParse(const std::string_view& str, PdfBlendMode& value)
453 {
454 if (str == "Normal")
455 {
456 value = PdfBlendMode::Normal;
457 return true;
458 }
459 else if (str == "Multiply")
460 {
461 value = PdfBlendMode::Multiply;
462 return true;
463 }
464 else if (str == "Screen")
465 {
466 value = PdfBlendMode::Screen;
467 return true;
468 }
469 else if (str == "Overlay")
470 {
471 value = PdfBlendMode::Overlay;
472 return true;
473 }
474 else if (str == "Darken")
475 {
476 value = PdfBlendMode::Darken;
477 return true;
478 }
479 else if (str == "Lighten")
480 {
481 value = PdfBlendMode::Lighten;
482 return true;
483 }
484 else if (str == "ColorDodge")
485 {
486 value = PdfBlendMode::ColorDodge;
487 return true;
488 }
489 else if (str == "ColorBurn")
490 {
491 value = PdfBlendMode::ColorBurn;
492 return true;
493 }
494 else if (str == "HardLight")
495 {
496 value = PdfBlendMode::HardLight;
497 return true;
498 }
499 else if (str == "SoftLight")
500 {
501 value = PdfBlendMode::SoftLight;
502 return true;
503 }
504 else if (str == "Difference")
505 {
506 value = PdfBlendMode::Difference;
507 return true;
508 }
509 else if (str == "Exclusion")
510 {
511 value = PdfBlendMode::Exclusion;
512 return true;
513 }
514 else if (str == "Hue")
515 {
516 value = PdfBlendMode::Hue;
517 return true;
518 }
519 else if (str == "Saturation")
520 {
521 value = PdfBlendMode::Saturation;
522 return true;
523 }
524 else if (str == "Color")
525 {
526 value = PdfBlendMode::Color;
527 return true;
528 }
529 else if (str == "Luminosity")
530 {
531 value = PdfBlendMode::Luminosity;
532 return true;
533 }
534
535 return false;
536 }
537 };
538
539 template<>
540 struct Convert<PdfOperator>
541 {
542 static std::string_view ToString(PdfOperator value)
543 {
544 using namespace std;
545 switch (value)
546 {
547 case PdfOperator::w:
548 return "w"sv;
549 case PdfOperator::J:
550 return "J"sv;
551 case PdfOperator::j:
552 return "j"sv;
553 case PdfOperator::M:
554 return "M"sv;
555 case PdfOperator::d:
556 return "d"sv;
557 case PdfOperator::ri:
558 return "ri"sv;
559 case PdfOperator::i:
560 return "i"sv;
561 case PdfOperator::gs:
562 return "gs"sv;
563 case PdfOperator::q:
564 return "q"sv;
565 case PdfOperator::Q:
566 return "Q"sv;
567 case PdfOperator::cm:
568 return "cm"sv;
569 case PdfOperator::m:
570 return "m"sv;
571 case PdfOperator::l:
572 return "l"sv;
573 case PdfOperator::c:
574 return "c"sv;
575 case PdfOperator::v:
576 return "v"sv;
577 case PdfOperator::y:
578 return "y"sv;
579 case PdfOperator::h:
580 return "h"sv;
581 case PdfOperator::re:
582 return "re"sv;
583 case PdfOperator::S:
584 return "S"sv;
585 case PdfOperator::s:
586 return "s"sv;
587 case PdfOperator::f:
588 return "f"sv;
589 case PdfOperator::F:
590 return "F"sv;
591 case PdfOperator::f_Star:
592 return "f*"sv;
593 case PdfOperator::B:
594 return "B"sv;
595 case PdfOperator::B_Star:
596 return "B*"sv;
597 case PdfOperator::b:
598 return "b"sv;
599 case PdfOperator::b_Star:
600 return "b*"sv;
601 case PdfOperator::n:
602 return "n"sv;
603 case PdfOperator::W:
604 return "W"sv;
605 case PdfOperator::W_Star:
606 return "W*"sv;
607 case PdfOperator::BT:
608 return "BT"sv;
609 case PdfOperator::ET:
610 return "ET"sv;
611 case PdfOperator::Tc:
612 return "Tc"sv;
613 case PdfOperator::Tw:
614 return "Tw"sv;
615 case PdfOperator::Tz:
616 return "Tz"sv;
617 case PdfOperator::TL:
618 return "TL"sv;
619 case PdfOperator::Tf:
620 return "Tf"sv;
621 case PdfOperator::Tr:
622 return "Tr"sv;
623 case PdfOperator::Ts:
624 return "Ts"sv;
625 case PdfOperator::Td:
626 return "Td"sv;
627 case PdfOperator::TD:
628 return "TD"sv;
629 case PdfOperator::Tm:
630 return "Tm"sv;
631 case PdfOperator::T_Star:
632 return "T*"sv;
633 case PdfOperator::Tj:
634 return "Tj"sv;
635 case PdfOperator::TJ:
636 return "TJ"sv;
637 case PdfOperator::Quote:
638 return "'"sv;
639 case PdfOperator::DoubleQuote:
640 return "\""sv;
641 case PdfOperator::d0:
642 return "d0"sv;
643 case PdfOperator::d1:
644 return "d1"sv;
645 case PdfOperator::CS:
646 return "CS"sv;
647 case PdfOperator::cs:
648 return "cs"sv;
649 case PdfOperator::SC:
650 return "SC"sv;
651 case PdfOperator::SCN:
652 return "SCN"sv;
653 case PdfOperator::sc:
654 return "sc"sv;
655 case PdfOperator::scn:
656 return "scn"sv;
657 case PdfOperator::G:
658 return "G"sv;
659 case PdfOperator::g:
660 return "g"sv;
661 case PdfOperator::RG:
662 return "RG"sv;
663 case PdfOperator::rg:
664 return "rg"sv;
665 case PdfOperator::K:
666 return "K"sv;
667 case PdfOperator::k:
668 return "k"sv;
669 case PdfOperator::sh:
670 return "sh"sv;
671 case PdfOperator::BI:
672 return "BI"sv;
673 case PdfOperator::ID:
674 return "ID"sv;
675 case PdfOperator::EI:
676 return "EI"sv;
677 case PdfOperator::Do:
678 return "Do"sv;
679 case PdfOperator::MP:
680 return "MP"sv;
681 case PdfOperator::DP:
682 return "DP"sv;
683 case PdfOperator::BMC:
684 return "BMC"sv;
685 case PdfOperator::BDC:
686 return "BDC"sv;
687 case PdfOperator::EMC:
688 return "EMC"sv;
689 case PdfOperator::BX:
690 return "BX"sv;
691 case PdfOperator::EX:
692 return "EX"sv;
693 case PdfOperator::Unknown:
694 default:
695 throw PdfError(PdfErrorCode::InvalidEnumValue, __FILE__, __LINE__);
696 }
697 }
698
699 static bool TryParse(const std::string_view& str, PdfOperator& value)
700 {
701 if (str == "w")
702 {
703 value = PdfOperator::w;
704 return true;
705 }
706 else if (str == "J")
707 {
708 value = PdfOperator::J;
709 return true;
710 }
711 else if (str == "j")
712 {
713 value = PdfOperator::j;
714 return true;
715 }
716 else if (str == "M")
717 {
718 value = PdfOperator::M;
719 return true;
720 }
721 else if (str == "d")
722 {
723 value = PdfOperator::d;
724 return true;
725 }
726 else if (str == "ri")
727 {
728 value = PdfOperator::ri;
729 return true;
730 }
731 else if (str == "i")
732 {
733 value = PdfOperator::i;
734 return true;
735 }
736 else if (str == "gs")
737 {
738 value = PdfOperator::gs;
739 return true;
740 }
741 else if (str == "q")
742 {
743 value = PdfOperator::q;
744 return true;
745 }
746 else if (str == "Q")
747 {
748 value = PdfOperator::Q;
749 return true;
750 }
751 else if (str == "cm")
752 {
753 value = PdfOperator::cm;
754 return true;
755 }
756 else if (str == "m")
757 {
758 value = PdfOperator::m;
759 return true;
760 }
761 else if (str == "l")
762 {
763 value = PdfOperator::l;
764 return true;
765 }
766 else if (str == "c")
767 {
768 value = PdfOperator::c;
769 return true;
770 }
771 else if (str == "v")
772 {
773 value = PdfOperator::v;
774 return true;
775 }
776 else if (str == "y")
777 {
778 value = PdfOperator::y;
779 return true;
780 }
781 else if (str == "h")
782 {
783 value = PdfOperator::h;
784 return true;
785 }
786 else if (str == "re")
787 {
788 value = PdfOperator::re;
789 return true;
790 }
791 else if (str == "S")
792 {
793 value = PdfOperator::S;
794 return true;
795 }
796 else if (str == "s")
797 {
798 value = PdfOperator::s;
799 return true;
800 }
801 else if (str == "f")
802 {
803 value = PdfOperator::f;
804 return true;
805 }
806 else if (str == "F")
807 {
808 value = PdfOperator::F;
809 return true;
810 }
811 else if (str == "f*")
812 {
813 value = PdfOperator::f_Star;
814 return true;
815 }
816 else if (str == "B")
817 {
818 value = PdfOperator::B;
819 return true;
820 }
821 else if (str == "B*")
822 {
823 value = PdfOperator::B_Star;
824 return true;
825 }
826 else if (str == "b")
827 {
828 value = PdfOperator::b;
829 return true;
830 }
831 else if (str == "b*")
832 {
833 value = PdfOperator::b_Star;
834 return true;
835 }
836 else if (str == "n")
837 {
838 value = PdfOperator::n;
839 return true;
840 }
841 else if (str == "W")
842 {
843 value = PdfOperator::W;
844 return true;
845 }
846 else if (str == "W*")
847 {
848 value = PdfOperator::W_Star;
849 return true;
850 }
851 else if (str == "BT")
852 {
853 value = PdfOperator::BT;
854 return true;
855 }
856 else if (str == "ET")
857 {
858 value = PdfOperator::ET;
859 return true;
860 }
861 else if (str == "Tc")
862 {
863 value = PdfOperator::Tc;
864 return true;
865 }
866 else if (str == "Tw")
867 {
868 value = PdfOperator::Tw;
869 return true;
870 }
871 else if (str == "Tz")
872 {
873 value = PdfOperator::Tz;
874 return true;
875 }
876 else if (str == "TL")
877 {
878 value = PdfOperator::TL;
879 return true;
880 }
881 else if (str == "Tf")
882 {
883 value = PdfOperator::Tf;
884 return true;
885 }
886 else if (str == "Tr")
887 {
888 value = PdfOperator::Tr;
889 return true;
890 }
891 else if (str == "Ts")
892 {
893 value = PdfOperator::Ts;
894 return true;
895 }
896 else if (str == "Td")
897 {
898 value = PdfOperator::Td;
899 return true;
900 }
901 else if (str == "TD")
902 {
903 value = PdfOperator::TD;
904 return true;
905 }
906 else if (str == "Tm")
907 {
908 value = PdfOperator::Tm;
909 return true;
910 }
911 else if (str == "T*")
912 {
913 value = PdfOperator::T_Star;
914 return true;
915 }
916 else if (str == "Tj")
917 {
918 value = PdfOperator::Tj;
919 return true;
920 }
921 else if (str == "TJ")
922 {
923 value = PdfOperator::TJ;
924 return true;
925 }
926 else if (str == "'")
927 {
928 value = PdfOperator::Quote;
929 return true;
930 }
931 else if (str == "\"")
932 {
933 value = PdfOperator::DoubleQuote;
934 return true;
935 }
936 else if (str == "d0")
937 {
938 value = PdfOperator::d0;
939 return true;
940 }
941 else if (str == "d1")
942 {
943 value = PdfOperator::d1;
944 return true;
945 }
946 else if (str == "CS")
947 {
948 value = PdfOperator::CS;
949 return true;
950 }
951 else if (str == "cs")
952 {
953 value = PdfOperator::cs;
954 return true;
955 }
956 else if (str == "SC")
957 {
958 value = PdfOperator::SC;
959 return true;
960 }
961 else if (str == "SCN")
962 {
963 value = PdfOperator::SCN;
964 return true;
965 }
966 else if (str == "sc")
967 {
968 value = PdfOperator::sc;
969 return true;
970 }
971 else if (str == "scn")
972 {
973 value = PdfOperator::scn;
974 return true;
975 }
976 else if (str == "G")
977 {
978 value = PdfOperator::G;
979 return true;
980 }
981 else if (str == "g")
982 {
983 value = PdfOperator::g;
984 return true;
985 }
986 else if (str == "RG")
987 {
988 value = PdfOperator::RG;
989 return true;
990 }
991 else if (str == "rg")
992 {
993 value = PdfOperator::rg;
994 return true;
995 }
996 else if (str == "K")
997 {
998 value = PdfOperator::K;
999 return true;
1000 }
1001 else if (str == "k")
1002 {
1003 value = PdfOperator::k;
1004 return true;
1005 }
1006 else if (str == "sh")
1007 {
1008 value = PdfOperator::sh;
1009 return true;
1010 }
1011 else if (str == "BI")
1012 {
1013 value = PdfOperator::BI;
1014 return true;
1015 }
1016 else if (str == "ID")
1017 {
1018 value = PdfOperator::ID;
1019 return true;
1020 }
1021 else if (str == "EI")
1022 {
1023 value = PdfOperator::EI;
1024 return true;
1025 }
1026 else if (str == "Do")
1027 {
1028 value = PdfOperator::Do;
1029 return true;
1030 }
1031 else if (str == "MP")
1032 {
1033 value = PdfOperator::MP;
1034 return true;
1035 }
1036 else if (str == "DP")
1037 {
1038 value = PdfOperator::DP;
1039 return true;
1040 }
1041 else if (str == "BMC")
1042 {
1043 value = PdfOperator::BMC;
1044 return true;
1045 }
1046 else if (str == "BDC")
1047 {
1048 value = PdfOperator::BDC;
1049 return true;
1050 }
1051 else if (str == "EMC")
1052 {
1053 value = PdfOperator::EMC;
1054 return true;
1055 }
1056 else if (str == "BX")
1057 {
1058 value = PdfOperator::BX;
1059 return true;
1060 }
1061 else if (str == "EX")
1062 {
1063 value = PdfOperator::EX;
1064 return true;
1065 }
1066 else
1067 {
1068 value = PdfOperator::Unknown;
1069 return false;
1070 }
1071 }
1072 };
1073
1074 template<>
1075 struct Convert<PdfALevel>
1076 {
1077 static std::string_view ToString(PdfALevel value)
1078 {
1079 using namespace std;
1080 switch (value)
1081 {
1082 case PdfALevel::L1B:
1083 return "L1B"sv;
1084 case PdfALevel::L1A:
1085 return "L1A"sv;
1086 case PdfALevel::L2B:
1087 return "L2B"sv;
1088 case PdfALevel::L2A:
1089 return "L2A"sv;
1090 case PdfALevel::L2U:
1091 return "L2U"sv;
1092 case PdfALevel::L3B:
1093 return "L3B"sv;
1094 case PdfALevel::L3A:
1095 return "L3A"sv;
1096 case PdfALevel::L3U:
1097 return "L3U"sv;
1098 case PdfALevel::L4:
1099 return "L4"sv;
1100 case PdfALevel::L4E:
1101 return "L4E"sv;
1102 case PdfALevel::L4F:
1103 return "L4F"sv;
1104 default:
1105 throw PdfError(PdfErrorCode::InvalidEnumValue, __FILE__, __LINE__);
1106 }
1107 }
1108
1109 static bool TryParse(const std::string_view& str, PdfALevel& value)
1110 {
1111 if (str == "L1B")
1112 {
1113 value = PdfALevel::L1B;
1114 return true;
1115 }
1116 else if (str == "L1A")
1117 {
1118 value = PdfALevel::L1A;
1119 return true;
1120 }
1121 else if (str == "L2B")
1122 {
1123 value = PdfALevel::L2B;
1124 return true;
1125 }
1126 else if (str == "L2A")
1127 {
1128 value = PdfALevel::L2A;
1129 return true;
1130 }
1131 else if (str == "L2U")
1132 {
1133 value = PdfALevel::L2U;
1134 return true;
1135 }
1136 else if (str == "L3B")
1137 {
1138 value = PdfALevel::L3B;
1139 return true;
1140 }
1141 else if (str == "L3A")
1142 {
1143 value = PdfALevel::L3A;
1144 return true;
1145 }
1146 else if (str == "L3U")
1147 {
1148 value = PdfALevel::L3U;
1149 return true;
1150 }
1151 else if (str == "L4")
1152 {
1153 value = PdfALevel::L4;
1154 return true;
1155 }
1156 else if (str == "L4E")
1157 {
1158 value = PdfALevel::L4E;
1159 return true;
1160 }
1161 else if (str == "L4F")
1162 {
1163 value = PdfALevel::L4F;
1164 return true;
1165 }
1166
1167 return false;
1168 }
1169 };
1170
1171 template<>
1172 struct Convert<PdfUALevel>
1173 {
1174 static std::string_view ToString(PdfUALevel value)
1175 {
1176 using namespace std;
1177 switch (value)
1178 {
1179 case PdfUALevel::L1:
1180 return "L1"sv;
1181 case PdfUALevel::L2:
1182 return "L2"sv;
1183 default:
1184 throw PdfError(PdfErrorCode::InvalidEnumValue, __FILE__, __LINE__);
1185 }
1186 }
1187
1188 static bool TryParse(const std::string_view& str, PdfUALevel& value)
1189 {
1190 if (str == "L1")
1191 {
1192 value = PdfUALevel::L1;
1193 return true;
1194 }
1195 else if (str == "L2")
1196 {
1197 value = PdfUALevel::L2;
1198 return true;
1199 }
1200
1201 return false;
1202 }
1203 };
1204
1205 template<typename T>
1206 std::string_view ToString(T value)
1207 {
1208 return Convert<T>::ToString(value);
1209 }
1210
1211 template<typename T>
1212 bool TryConvertTo(const std::string_view& str, T& value)
1213 {
1214 value = { };
1215 return Convert<T>::TryParse(str, value);
1216 }
1217
1218 template<typename T>
1219 T ConvertTo(const std::string_view& str)
1220 {
1221 T value;
1222 if (!Convert<T>::TryParse(str, value))
1223 throw PdfError(PdfErrorCode::InvalidEnumValue, __FILE__, __LINE__);
1224
1225 return value;
1226 }
1227}
1228
1229#endif // PDF_CONVERT_H
SPDX-FileCopyrightText: (C) 2006 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
PdfAnnotationType
The type of the annotation.
Definition PdfDeclarations.h:595
PdfBlendMode
List of defined transparency blending modes.
Definition PdfDeclarations.h:836
PdfRenderingIntent
List of defined Rendering intents.
Definition PdfDeclarations.h:824
@ InvalidEnumValue
An invalid enum value was specified.
PdfOperator
List of PDF stream content operators.
Definition PdfDeclarations.h:726
PdfColorSpaceType
Enum for the colorspaces supported by PDF.
Definition PdfDeclarations.h:359