LibreOffice Module sw (master) 1
PageMarginUtils.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#include <cmath>
20#include <tools/long.hxx>
21
22#define SWPAGE_NO_MARGIN 0
23#define SWPAGE_NARROW_VALUE 720
24#define SWPAGE_MODERATE_LR 1080
25#define SWPAGE_NORMAL_VALUE 1136
26#define SWPAGE_WIDE_VALUE1 1440
27#define SWPAGE_WIDE_VALUE2 2880
28#define SWPAGE_WIDE_VALUE3 1800
29#define SWPAGE_UNIT_THRESHOLD 5
30
31namespace sw::sidebar{
32
33bool IsNone( const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin,
34 const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
35{
36 return( std::abs(nPageLeftMargin - SWPAGE_NO_MARGIN) <= SWPAGE_UNIT_THRESHOLD &&
37 std::abs(nPageRightMargin - SWPAGE_NO_MARGIN ) <= SWPAGE_UNIT_THRESHOLD &&
38 std::abs(nPageTopMargin - SWPAGE_NO_MARGIN) <= SWPAGE_UNIT_THRESHOLD &&
39 std::abs(nPageBottomMargin - SWPAGE_NO_MARGIN) <= SWPAGE_UNIT_THRESHOLD &&
40 !bMirrored );
41}
42
43void SetNone( tools::Long& nPageLeftMargin, tools::Long& nPageRightMargin,
44 tools::Long& nPageTopMargin, tools::Long& nPageBottomMargin, bool& bMirrored)
45{
46 nPageLeftMargin = SWPAGE_NO_MARGIN;
47 nPageRightMargin = SWPAGE_NO_MARGIN;
48 nPageTopMargin = SWPAGE_NO_MARGIN;
49 nPageBottomMargin = SWPAGE_NO_MARGIN;
50 bMirrored = false;
51}
52
53bool IsNarrow( const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin,
54 const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
55{
56 return( std::abs(nPageLeftMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
57 std::abs(nPageRightMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
59 std::abs(nPageBottomMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
60 !bMirrored );
61}
62
63void SetNarrow( tools::Long& nPageLeftMargin, tools::Long& nPageRightMargin,
64 tools::Long& nPageTopMargin, tools::Long& nPageBottomMargin, bool& bMirrored)
65{
66 nPageLeftMargin = SWPAGE_NARROW_VALUE;
67 nPageRightMargin = SWPAGE_NARROW_VALUE;
68 nPageTopMargin = SWPAGE_NARROW_VALUE;
69 nPageBottomMargin = SWPAGE_NARROW_VALUE;
70 bMirrored = false;
71}
72
73bool IsModerate( const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin,
74 const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
75{
76 return( std::abs(nPageLeftMargin - SWPAGE_MODERATE_LR) <= SWPAGE_UNIT_THRESHOLD &&
77 std::abs(nPageRightMargin - SWPAGE_MODERATE_LR) <= SWPAGE_UNIT_THRESHOLD &&
79 std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
80 !bMirrored );
81}
82
83void SetModerate( tools::Long& nPageLeftMargin, tools::Long& nPageRightMargin,
84 tools::Long& nPageTopMargin, tools::Long& nPageBottomMargin, bool& bMirrored)
85{
86 nPageLeftMargin = SWPAGE_MODERATE_LR;
87 nPageRightMargin = SWPAGE_MODERATE_LR;
88 nPageTopMargin = SWPAGE_WIDE_VALUE1;
89 nPageBottomMargin = SWPAGE_WIDE_VALUE1;
90 bMirrored = false;
91}
92
93bool IsNormal075( const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin,
94 const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
95{
96 return( std::abs(nPageLeftMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
97 std::abs(nPageRightMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
99 std::abs(nPageBottomMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
100 !bMirrored );
101}
102
103void SetNormal075( tools::Long& nPageLeftMargin, tools::Long& nPageRightMargin,
104 tools::Long& nPageTopMargin, tools::Long& nPageBottomMargin, bool& bMirrored)
105{
106 nPageLeftMargin = SWPAGE_NORMAL_VALUE;
107 nPageRightMargin = SWPAGE_NORMAL_VALUE;
108 nPageTopMargin = SWPAGE_NORMAL_VALUE;
109 nPageBottomMargin = SWPAGE_NORMAL_VALUE;
110 bMirrored = false;
111}
112
113bool IsNormal100( const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin,
114 const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
115{
116 return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
117 std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
119 std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
120 !bMirrored );
121}
122
123void SetNormal100( tools::Long& nPageLeftMargin, tools::Long& nPageRightMargin,
124 tools::Long& nPageTopMargin, tools::Long& nPageBottomMargin, bool& bMirrored)
125{
126 nPageLeftMargin = SWPAGE_WIDE_VALUE1;
127 nPageRightMargin = SWPAGE_WIDE_VALUE1;
128 nPageTopMargin = SWPAGE_WIDE_VALUE1;
129 nPageBottomMargin = SWPAGE_WIDE_VALUE1;
130 bMirrored = false;
131}
132
133bool IsNormal125( const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin,
134 const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
135{
136 return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE3) <= SWPAGE_UNIT_THRESHOLD &&
137 std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE3) <= SWPAGE_UNIT_THRESHOLD &&
139 std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
140 !bMirrored );
141}
142
143void SetNormal125( tools::Long& nPageLeftMargin, tools::Long& nPageRightMargin,
144 tools::Long& nPageTopMargin, tools::Long& nPageBottomMargin, bool& bMirrored)
145{
146 nPageLeftMargin = SWPAGE_WIDE_VALUE3;
147 nPageRightMargin = SWPAGE_WIDE_VALUE3;
148 nPageTopMargin = SWPAGE_WIDE_VALUE1;
149 nPageBottomMargin = SWPAGE_WIDE_VALUE1;
150 bMirrored = false;
151}
152
153bool IsWide( const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin,
154 const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
155{
156 return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE2) <= SWPAGE_UNIT_THRESHOLD &&
157 std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE2) <= SWPAGE_UNIT_THRESHOLD &&
159 std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
160 !bMirrored );
161}
162
163void SetWide( tools::Long& nPageLeftMargin, tools::Long& nPageRightMargin,
164 tools::Long& nPageTopMargin, tools::Long& nPageBottomMargin, bool& bMirrored)
165{
166 nPageLeftMargin = SWPAGE_WIDE_VALUE2;
167 nPageRightMargin = SWPAGE_WIDE_VALUE2;
168 nPageTopMargin = SWPAGE_WIDE_VALUE1;
169 nPageBottomMargin = SWPAGE_WIDE_VALUE1;
170 bMirrored = false;
171}
172
173bool IsMirrored( const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin,
174 const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
175{
176 return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE3) <= SWPAGE_UNIT_THRESHOLD &&
177 std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
179 std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
180 bMirrored );
181}
182
183void SetMirrored( tools::Long& nPageLeftMargin, tools::Long& nPageRightMargin,
184 tools::Long& nPageTopMargin, tools::Long& nPageBottomMargin, bool& bMirrored)
185{
186 nPageLeftMargin = SWPAGE_WIDE_VALUE3;
187 nPageRightMargin = SWPAGE_WIDE_VALUE1;
188 nPageTopMargin = SWPAGE_WIDE_VALUE1;
189 nPageBottomMargin = SWPAGE_WIDE_VALUE1;
190 bMirrored = true;
191}
192}
193
194/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SWPAGE_WIDE_VALUE3
#define SWPAGE_NARROW_VALUE
#define SWPAGE_MODERATE_LR
#define SWPAGE_WIDE_VALUE2
#define SWPAGE_NORMAL_VALUE
#define SWPAGE_UNIT_THRESHOLD
#define SWPAGE_WIDE_VALUE1
#define SWPAGE_NO_MARGIN
void SetNone(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
bool IsNarrow(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
bool IsWide(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
bool IsMirrored(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
void SetModerate(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
bool IsModerate(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
void SetWide(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
void SetNormal125(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
void SetNarrow(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
bool IsNone(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
void SetNormal100(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
bool IsNormal125(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
bool IsNormal100(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
void SetNormal075(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
bool IsNormal075(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
void SetMirrored(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
long Long
SwNodeOffset abs(const SwNodeOffset &a)
Definition: nodeoffset.hxx:34