/src/poppler/poppler/ViewerPreferences.cc
Line | Count | Source |
1 | | //======================================================================== |
2 | | // |
3 | | // ViewerPreferences.cc |
4 | | // |
5 | | // This file is licensed under the GPLv2 or later |
6 | | // |
7 | | // Copyright 2011 Pino Toscano <pino@kde.org> |
8 | | // Copyright 2017, 2020, 2022, 2025 Albert Astals Cid <aacid@kde.org> |
9 | | // Copyright 2019 Marek Kasik <mkasik@redhat.com> |
10 | | // Copyright 2026 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de> |
11 | | // |
12 | | //======================================================================== |
13 | | |
14 | | #include <config.h> |
15 | | |
16 | | #include "ViewerPreferences.h" |
17 | | |
18 | | #include "Object.h" |
19 | | #include "Dict.h" |
20 | | |
21 | | ViewerPreferences::ViewerPreferences(const Dict &prefDict) |
22 | 0 | { |
23 | 0 | hideToolbar = prefDict.lookup("HideToolbar").getBoolWithDefaultValue(false); |
24 | |
|
25 | 0 | hideMenubar = prefDict.lookup("HideMenubar").getBoolWithDefaultValue(false); |
26 | |
|
27 | 0 | hideWindowUI = prefDict.lookup("HideWindowUI").getBoolWithDefaultValue(false); |
28 | |
|
29 | 0 | fitWindow = prefDict.lookup("FitWindow").getBoolWithDefaultValue(false); |
30 | |
|
31 | 0 | centerWindow = prefDict.lookup("CenterWindow").getBoolWithDefaultValue(false); |
32 | |
|
33 | 0 | displayDocTitle = prefDict.lookup("DisplayDocTitle").getBoolWithDefaultValue(false); |
34 | |
|
35 | 0 | Object obj = prefDict.lookup("NonFullScreenPageMode"); |
36 | 0 | if (obj.isName()) { |
37 | 0 | const std::string &mode = obj.getNameString(); |
38 | 0 | if (mode == "UseNone") { |
39 | 0 | nonFullScreenPageMode = nfpmUseNone; |
40 | 0 | } else if (mode == "UseOutlines") { |
41 | 0 | nonFullScreenPageMode = nfpmUseOutlines; |
42 | 0 | } else if (mode == "UseThumbs") { |
43 | 0 | nonFullScreenPageMode = nfpmUseThumbs; |
44 | 0 | } else if (mode == "UseOC") { |
45 | 0 | nonFullScreenPageMode = nfpmUseOC; |
46 | 0 | } |
47 | 0 | } |
48 | |
|
49 | 0 | obj = prefDict.lookup("Direction"); |
50 | 0 | if (obj.isName()) { |
51 | 0 | const std::string &dir = obj.getNameString(); |
52 | 0 | if (dir == "L2R") { |
53 | 0 | direction = directionL2R; |
54 | 0 | } else if (dir == "R2L") { |
55 | 0 | direction = directionR2L; |
56 | 0 | } |
57 | 0 | } |
58 | |
|
59 | 0 | obj = prefDict.lookup("PrintScaling"); |
60 | 0 | if (obj.isName()) { |
61 | 0 | const std::string &ps = obj.getNameString(); |
62 | 0 | if (ps == "None") { |
63 | 0 | printScaling = printScalingNone; |
64 | 0 | } else if (ps == "AppDefault") { |
65 | 0 | printScaling = printScalingAppDefault; |
66 | 0 | } |
67 | 0 | } |
68 | |
|
69 | 0 | obj = prefDict.lookup("Duplex"); |
70 | 0 | if (obj.isName()) { |
71 | 0 | const std::string &d = obj.getNameString(); |
72 | 0 | if (d == "Simplex") { |
73 | 0 | duplex = duplexSimplex; |
74 | 0 | } else if (d == "DuplexFlipShortEdge") { |
75 | 0 | duplex = duplexDuplexFlipShortEdge; |
76 | 0 | } else if (d == "DuplexFlipLongEdge") { |
77 | 0 | duplex = duplexDuplexFlipLongEdge; |
78 | 0 | } |
79 | 0 | } |
80 | |
|
81 | 0 | pickTrayByPDFSize = prefDict.lookup("PickTrayByPDFSize").getBoolWithDefaultValue(false); |
82 | |
|
83 | 0 | obj = prefDict.lookup("NumCopies"); |
84 | 0 | if (obj.isInt()) { |
85 | 0 | numCopies = obj.getInt(); |
86 | 0 | if (numCopies < 2) { |
87 | 0 | numCopies = 1; |
88 | 0 | } |
89 | 0 | } |
90 | |
|
91 | 0 | obj = prefDict.lookup("PrintPageRange"); |
92 | 0 | if (obj.isArray()) { |
93 | 0 | Array *range = obj.getArray(); |
94 | 0 | int length = range->getLength(); |
95 | 0 | int pageNumber1, pageNumber2; |
96 | |
|
97 | 0 | if (length % 2 == 1) { |
98 | 0 | length--; |
99 | 0 | } |
100 | |
|
101 | 0 | for (int i = 0; i < length; i += 2) { |
102 | 0 | Object obj2 = range->get(i); |
103 | 0 | Object obj3 = range->get(i + 1); |
104 | |
|
105 | 0 | if (obj2.isInt() && (pageNumber1 = obj2.getInt()) >= 1 && obj3.isInt() && (pageNumber2 = obj3.getInt()) >= 1 && pageNumber1 < pageNumber2) { |
106 | 0 | printPageRange.emplace_back(pageNumber1, pageNumber2); |
107 | 0 | } else { |
108 | 0 | printPageRange.clear(); |
109 | 0 | break; |
110 | 0 | } |
111 | 0 | } |
112 | 0 | } |
113 | 0 | } |
114 | | |
115 | 0 | ViewerPreferences::~ViewerPreferences() = default; |