Debian Codegraph @

podofo/tools/podofocolor/podofocolor.cpp

raw
1 /**
2 * SPDX-FileCopyrightText: (C) 2010 Dominik Seichter <[email protected]>
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6 #include <podofo/podofo.h>
7
8 #include <cstdlib>
9 #include <string>
10 #include <iostream>
11
12 #include "colorchanger.h"
13 #include "dummyconverter.h"
14 #include "grayscaleconverter.h"
15 #ifdef PODOFO_HAVE_LUA
16 #include "luaconverter.h"
17 #endif // PODOFO_HAVE_LUA
18
19 using namespace std;
20 using namespace PoDoFo;
21
22 static void print_help()
23 {
24 cerr << "Usage: podofocolor [converter] [inputfile] [outpufile]\n";
25 #ifdef PODOFO_HAVE_LUA
26 cerr << "\t[converter] can be one of: dummy|grayscale|lua [planfile]\n";
27 #else
28 cerr << "\t[converter] can be one of: dummy|grayscale\n";
29 #endif // PODOFO_HAVE_LUA
30 cerr << "\tpodofocolor is a tool to change all colors in a PDF file based on a predefined or Lua description.\n";
31 cerr << "\nPoDoFo Version: " << PODOFO_VERSION_STRING << "\n\n";
32 }
33
34 /**
35 * @return a converter implementation or NULL if unknown
36 */
37 static IConverter* ConverterForName(const string_view& converterName, const string_view& lua)
38 {
39 IConverter* converter = NULL;
40 if (converterName == "dummy")
41 {
42 converter = new DummyConverter();
43 }
44 else if (converterName == "grayscale")
45 {
46 converter = new GrayscaleConverter();
47 }
48 #ifdef PODOFO_HAVE_LUA
49 else if (converterName == "lua")
50 {
51 converter = new LuaConverter(lua);
52 }
53 #else
54 (void)lua;
55 #endif // PODOFO_HAVE_LUA
56
57 return converter;
58 }
59
60 void Main(const cspan<string_view>& args)
61 {
62 if (!(args.size() == 4 || args.size() == 5))
63 {
64 print_help();
65 exit(-1);
66 }
67
68 string_view converterName = args[1];
69 string_view input = args[2];
70 string_view output = args[3];
71 string_view lua;
72
73 if (args.size() == 4 && converterName != "lua")
74 {
75 input = args[2];
76 output = args[3];
77 }
78 #ifdef PODOFO_HAVE_LUA
79 else if (args.size() == 5 && converterName == "lua")
80 {
81 lua = argv[2];
82 input = argv[3];
83 output = argv[4];
84 }
85 #endif // PODOFO_HAVE_LUA
86 else
87 {
88 print_help();
89 exit(-3);
90 }
91
92 IConverter* converter = ConverterForName(converterName, lua);
93 if (!converter)
94 {
95 cerr << "Aborting! Unknown converter: " << converterName << endl;
96 print_help();
97 exit(-2);
98 }
99
100 ColorChanger cc(converter, input, output);
101 cc.start();
102 delete converter;
103 }