Debian Codegraph @

podofo/tools/podofoimpose/impositionplan.h

raw
1 /**
2 * SPDX-FileCopyrightText: (C) 2008 Pierre Marchand <[email protected]>
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6 #ifndef IMPOSITIONPLAN_H
7 #define IMPOSITIONPLAN_H
8
9 #include <podofo/podofo.h>
10
11 #include <map>
12 #include <string>
13 #include <vector>
14 #include <cstdio>
15
16 namespace PoDoFo::Impose
17 {
18 enum PlanReader
19 {
20 Legacy = 0,
21 Lua = 1
22 };
23
24 struct SourceVars
25 {
26 unsigned PageCount;
27 double PageWidth;
28 double PageHeight;
29 };
30
31 class Util
32 {
33 public:
34 static void trimmed_str(std::string& s)
35 {
36 std::string::iterator si(s.begin());
37 while (si != s.end())
38 {
39 if ((*si) == 0x20)
40 si = s.erase(si);
41 else if ((*si) == 0x9)
42 si = s.erase(si);
43 else
44 ++si;
45 }
46
47 }
48
49 static std::string dToStr(double d)
50 {
51 char buffer[126];
52 sprintf(buffer, "%.5f", d);
53 std::string ret(buffer);
54 return ret;
55
56 }
57 static std::string uToStr(unsigned i)
58 {
59 char buffer[126];
60 sprintf(buffer, "%u", i);
61 std::string ret(buffer);
62 return ret;
63 }
64 };
65
66
67 /**
68 @author Pierre Marchand <[email protected]>
69 */
70 class PageRecord
71 {
72 public:
73 PageRecord(int s, int d, double r, double tx, double ty, int du = 0, double sx = 1.0, double sy = 1.0);
74 PageRecord();
75 ~PageRecord() {};
76 unsigned sourcePage;
77 unsigned destPage;
78 double rotate;
79 double transX;
80 double transY;
81 double scaleX;
82 double scaleY;
83 int duplicateOf;
84 bool isValid() const;
85
86 /// needed by legacy loader - should be removed soon
87 static double calc(const std::string& s, const std::map<std::string, std::string>& vars);
88 static double calc(const std::vector<std::string>& t);
89 void load(const std::string& s, const std::map<std::string, std::string>& vars);
90 };
91
92 class ImpositionPlan : public std::vector<PageRecord>
93 {
94 public:
95 ImpositionPlan(const SourceVars& sv);
96 ~ImpositionPlan();
97
98 // legacy
99 std::map<std::string, std::string> vars;
100
101 const SourceVars sourceVars;
102
103 private:
104 double m_destWidth;
105 double m_destHeight;
106 double m_scale;
107 std::string m_boundingBox;
108 public:
109 bool valid() const;
110
111 void setDestWidth(double theValue);
112 double destWidth() const { return m_destWidth; }
113
114 void setDestHeight(double theValue);
115 double destHeight() const { return m_destHeight; }
116
117 void setScale(double theValue);
118 double scale() const { return m_scale; }
119
120 void setBoundingBox(const std::string& theString);
121 std::string boundingBox()const { return m_boundingBox; }
122 };
123
124 }
125
126 #endif // IMPOSITIONPLAN_H