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

source code of poppler/poppler/ViewerPreferences.cc