/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 | | // |
11 | | //======================================================================== |
12 | | |
13 | | #include <config.h> |
14 | | |
15 | | #include "ViewerPreferences.h" |
16 | | |
17 | | #include "Object.h" |
18 | | #include "Dict.h" |
19 | | |
20 | | ViewerPreferences::ViewerPreferences(const Dict &prefDict) |
21 | 0 | { |
22 | 0 | hideToolbar = prefDict.lookup("HideToolbar").getBoolWithDefaultValue(false); |
23 | |
|
24 | 0 | hideMenubar = prefDict.lookup("HideMenubar").getBoolWithDefaultValue(false); |
25 | |
|
26 | 0 | hideWindowUI = prefDict.lookup("HideWindowUI").getBoolWithDefaultValue(false); |
27 | |
|
28 | 0 | fitWindow = prefDict.lookup("FitWindow").getBoolWithDefaultValue(false); |
29 | |
|
30 | 0 | centerWindow = prefDict.lookup("CenterWindow").getBoolWithDefaultValue(false); |
31 | |
|
32 | 0 | displayDocTitle = prefDict.lookup("DisplayDocTitle").getBoolWithDefaultValue(false); |
33 | |
|
34 | 0 | Object obj = prefDict.lookup("NonFullScreenPageMode"); |
35 | 0 | if (obj.isName()) { |
36 | 0 | const char *mode = obj.getName(); |
37 | 0 | if (!strcmp(mode, "UseNone")) { |
38 | 0 | nonFullScreenPageMode = nfpmUseNone; |
39 | 0 | } else if (!strcmp(mode, "UseOutlines")) { |
40 | 0 | nonFullScreenPageMode = nfpmUseOutlines; |
41 | 0 | } else if (!strcmp(mode, "UseThumbs")) { |
42 | 0 | nonFullScreenPageMode = nfpmUseThumbs; |
43 | 0 | } else if (!strcmp(mode, "UseOC")) { |
44 | 0 | nonFullScreenPageMode = nfpmUseOC; |
45 | 0 | } |
46 | 0 | } |
47 | |
|
48 | 0 | obj = prefDict.lookup("Direction"); |
49 | 0 | if (obj.isName()) { |
50 | 0 | const char *dir = obj.getName(); |
51 | 0 | if (!strcmp(dir, "L2R")) { |
52 | 0 | direction = directionL2R; |
53 | 0 | } else if (!strcmp(dir, "R2L")) { |
54 | 0 | direction = directionR2L; |
55 | 0 | } |
56 | 0 | } |
57 | |
|
58 | 0 | obj = prefDict.lookup("PrintScaling"); |
59 | 0 | if (obj.isName()) { |
60 | 0 | const char *ps = obj.getName(); |
61 | 0 | if (!strcmp(ps, "None")) { |
62 | 0 | printScaling = printScalingNone; |
63 | 0 | } else if (!strcmp(ps, "AppDefault")) { |
64 | 0 | printScaling = printScalingAppDefault; |
65 | 0 | } |
66 | 0 | } |
67 | |
|
68 | 0 | obj = prefDict.lookup("Duplex"); |
69 | 0 | if (obj.isName()) { |
70 | 0 | const char *d = obj.getName(); |
71 | 0 | if (!strcmp(d, "Simplex")) { |
72 | 0 | duplex = duplexSimplex; |
73 | 0 | } else if (!strcmp(d, "DuplexFlipShortEdge")) { |
74 | 0 | duplex = duplexDuplexFlipShortEdge; |
75 | 0 | } else if (!strcmp(d, "DuplexFlipLongEdge")) { |
76 | 0 | duplex = duplexDuplexFlipLongEdge; |
77 | 0 | } |
78 | 0 | } |
79 | |
|
80 | 0 | pickTrayByPDFSize = prefDict.lookup("PickTrayByPDFSize").getBoolWithDefaultValue(false); |
81 | |
|
82 | 0 | obj = prefDict.lookup("NumCopies"); |
83 | 0 | if (obj.isInt()) { |
84 | 0 | numCopies = obj.getInt(); |
85 | 0 | if (numCopies < 2) { |
86 | 0 | numCopies = 1; |
87 | 0 | } |
88 | 0 | } |
89 | |
|
90 | 0 | obj = prefDict.lookup("PrintPageRange"); |
91 | 0 | if (obj.isArray()) { |
92 | 0 | Array *range = obj.getArray(); |
93 | 0 | int length = range->getLength(); |
94 | 0 | int pageNumber1, pageNumber2; |
95 | |
|
96 | 0 | if (length % 2 == 1) { |
97 | 0 | length--; |
98 | 0 | } |
99 | |
|
100 | 0 | for (int i = 0; i < length; i += 2) { |
101 | 0 | Object obj2 = range->get(i); |
102 | 0 | Object obj3 = range->get(i + 1); |
103 | |
|
104 | 0 | if (obj2.isInt() && (pageNumber1 = obj2.getInt()) >= 1 && obj3.isInt() && (pageNumber2 = obj3.getInt()) >= 1 && pageNumber1 < pageNumber2) { |
105 | 0 | printPageRange.emplace_back(pageNumber1, pageNumber2); |
106 | 0 | } else { |
107 | 0 | printPageRange.clear(); |
108 | 0 | break; |
109 | 0 | } |
110 | 0 | } |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | 0 | ViewerPreferences::~ViewerPreferences() = default; |