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