blob: 1e5a959422dc552e208c184ad796b77e095da2d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "printing/nup_parameters.h"
#include <algorithm>
#include <cmath>
#include "base/logging.h"
namespace printing {
NupParameters::NupParameters() {
Clear();
}
void NupParameters::Clear() {
landscape_ = false;
num_pages_on_x_axis_ = 1;
num_pages_on_y_axis_ = 1;
}
// static
bool NupParameters::IsSupported(int num_pages_per_sheet) {
// Supports N-up: 1 2 4 6 9 16
return num_pages_per_sheet == 1 || num_pages_per_sheet == 2 ||
num_pages_per_sheet == 4 || num_pages_per_sheet == 6 ||
num_pages_per_sheet == 9 || num_pages_per_sheet == 16;
}
void NupParameters::SetParameters(int num_pages_per_sheet,
bool is_source_landscape) {
DCHECK(IsSupported(num_pages_per_sheet));
switch (num_pages_per_sheet) {
case 1:
num_pages_on_x_axis_ = 1;
num_pages_on_y_axis_ = 1;
break;
case 2:
if (!is_source_landscape) {
num_pages_on_x_axis_ = 2;
num_pages_on_y_axis_ = 1;
landscape_ = true;
} else {
num_pages_on_x_axis_ = 1;
num_pages_on_y_axis_ = 2;
}
break;
case 6:
if (!is_source_landscape) {
num_pages_on_x_axis_ = 3;
num_pages_on_y_axis_ = 2;
landscape_ = true;
} else {
num_pages_on_x_axis_ = 2;
num_pages_on_y_axis_ = 3;
}
break;
case 4:
case 9:
case 16:
num_pages_on_x_axis_ = std::sqrt(num_pages_per_sheet);
num_pages_on_y_axis_ = std::sqrt(num_pages_per_sheet);
if (is_source_landscape)
landscape_ = true;
break;
default:
NOTREACHED();
}
}
} // namespace printing
|