LibreOffice Module sd (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#define SDPAGE_NO_MARGIN 0
22#define SDPAGE_NARROW_VALUE 635
23#define SDPAGE_MODERATE_LR 955
24#define SDPAGE_NORMAL_VALUE 1000
25#define SDPAGE_WIDE_VALUE1 1270
26#define SDPAGE_WIDE_VALUE2 2540
27#define SDPAGE_WIDE_VALUE3 1590
28#define SDPAGE_UNIT_THRESHOLD 5
29
30namespace sd::sidebar{
31
32bool IsNone( const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin,
33 const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin )
34{
35 return( std::abs(nPageLeftMargin - SDPAGE_NO_MARGIN) <= SDPAGE_UNIT_THRESHOLD &&
36 std::abs(nPageRightMargin - SDPAGE_NO_MARGIN ) <= SDPAGE_UNIT_THRESHOLD &&
37 std::abs(nPageTopMargin - SDPAGE_NO_MARGIN) <= SDPAGE_UNIT_THRESHOLD &&
38 std::abs(nPageBottomMargin - SDPAGE_NO_MARGIN) <= SDPAGE_UNIT_THRESHOLD );
39}
40
41void SetNone( ::tools::Long& nPageLeftMargin, ::tools::Long& nPageRightMargin,
42 ::tools::Long& nPageTopMargin, ::tools::Long& nPageBottomMargin )
43{
44 nPageLeftMargin = SDPAGE_NO_MARGIN;
45 nPageRightMargin = SDPAGE_NO_MARGIN;
46 nPageTopMargin = SDPAGE_NO_MARGIN;
47 nPageBottomMargin = SDPAGE_NO_MARGIN;
48}
49
50bool IsNarrow( const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin,
51 const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin )
52{
53 return( std::abs(nPageLeftMargin - SDPAGE_NARROW_VALUE) <= SDPAGE_UNIT_THRESHOLD &&
54 std::abs(nPageRightMargin - SDPAGE_NARROW_VALUE) <= SDPAGE_UNIT_THRESHOLD &&
55 std::abs(nPageTopMargin - SDPAGE_NARROW_VALUE) <= SDPAGE_UNIT_THRESHOLD &&
56 std::abs(nPageBottomMargin - SDPAGE_NARROW_VALUE) <= SDPAGE_UNIT_THRESHOLD );
57}
58
59void SetNarrow( ::tools::Long& nPageLeftMargin, ::tools::Long& nPageRightMargin,
60 ::tools::Long& nPageTopMargin, ::tools::Long& nPageBottomMargin )
61{
62 nPageLeftMargin = SDPAGE_NARROW_VALUE;
63 nPageRightMargin = SDPAGE_NARROW_VALUE;
64 nPageTopMargin = SDPAGE_NARROW_VALUE;
65 nPageBottomMargin = SDPAGE_NARROW_VALUE;
66}
67
68bool IsModerate( const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin,
69 const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin )
70{
71 return( std::abs(nPageLeftMargin - SDPAGE_MODERATE_LR) <= SDPAGE_UNIT_THRESHOLD &&
72 std::abs(nPageRightMargin - SDPAGE_MODERATE_LR) <= SDPAGE_UNIT_THRESHOLD &&
73 std::abs(nPageTopMargin - SDPAGE_WIDE_VALUE1) <= SDPAGE_UNIT_THRESHOLD &&
74 std::abs(nPageBottomMargin - SDPAGE_WIDE_VALUE1) <= SDPAGE_UNIT_THRESHOLD );
75}
76
77void SetModerate( ::tools::Long& nPageLeftMargin, ::tools::Long& nPageRightMargin,
78 ::tools::Long& nPageTopMargin, ::tools::Long& nPageBottomMargin )
79{
80 nPageLeftMargin = SDPAGE_MODERATE_LR;
81 nPageRightMargin = SDPAGE_MODERATE_LR;
82 nPageTopMargin = SDPAGE_WIDE_VALUE1;
83 nPageBottomMargin = SDPAGE_WIDE_VALUE1;
84}
85
86bool IsNormal075( const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin,
87 const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin )
88{
89 return( std::abs(nPageLeftMargin - SDPAGE_NORMAL_VALUE) <= SDPAGE_UNIT_THRESHOLD &&
90 std::abs(nPageRightMargin - SDPAGE_NORMAL_VALUE) <= SDPAGE_UNIT_THRESHOLD &&
91 std::abs(nPageTopMargin - SDPAGE_NORMAL_VALUE) <= SDPAGE_UNIT_THRESHOLD &&
92 std::abs(nPageBottomMargin - SDPAGE_NORMAL_VALUE) <= SDPAGE_UNIT_THRESHOLD );
93}
94
95void SetNormal075( ::tools::Long& nPageLeftMargin, ::tools::Long& nPageRightMargin,
96 ::tools::Long& nPageTopMargin, ::tools::Long& nPageBottomMargin )
97{
98 nPageLeftMargin = SDPAGE_NORMAL_VALUE;
99 nPageRightMargin = SDPAGE_NORMAL_VALUE;
100 nPageTopMargin = SDPAGE_NORMAL_VALUE;
101 nPageBottomMargin = SDPAGE_NORMAL_VALUE;
102}
103
104bool IsNormal100( const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin,
105 const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin )
106{
107 return( std::abs(nPageLeftMargin - SDPAGE_WIDE_VALUE1) <= SDPAGE_UNIT_THRESHOLD &&
108 std::abs(nPageRightMargin - SDPAGE_WIDE_VALUE1) <= SDPAGE_UNIT_THRESHOLD &&
109 std::abs(nPageTopMargin - SDPAGE_WIDE_VALUE1) <= SDPAGE_UNIT_THRESHOLD &&
110 std::abs(nPageBottomMargin - SDPAGE_WIDE_VALUE1) <= SDPAGE_UNIT_THRESHOLD );
111}
112
113void SetNormal100( ::tools::Long& nPageLeftMargin, ::tools::Long& nPageRightMargin,
114 ::tools::Long& nPageTopMargin, ::tools::Long& nPageBottomMargin )
115{
116 nPageLeftMargin = SDPAGE_WIDE_VALUE1;
117 nPageRightMargin = SDPAGE_WIDE_VALUE1;
118 nPageTopMargin = SDPAGE_WIDE_VALUE1;
119 nPageBottomMargin = SDPAGE_WIDE_VALUE1;
120}
121
122bool IsNormal125( const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin,
123 const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin )
124{
125 return( std::abs(nPageLeftMargin - SDPAGE_WIDE_VALUE3) <= SDPAGE_UNIT_THRESHOLD &&
126 std::abs(nPageRightMargin - SDPAGE_WIDE_VALUE3) <= SDPAGE_UNIT_THRESHOLD &&
127 std::abs(nPageTopMargin - SDPAGE_WIDE_VALUE1) <= SDPAGE_UNIT_THRESHOLD &&
128 std::abs(nPageBottomMargin - SDPAGE_WIDE_VALUE1) <= SDPAGE_UNIT_THRESHOLD );
129}
130
131void SetNormal125( ::tools::Long& nPageLeftMargin, ::tools::Long& nPageRightMargin,
132 ::tools::Long& nPageTopMargin, ::tools::Long& nPageBottomMargin )
133{
134 nPageLeftMargin = SDPAGE_WIDE_VALUE3;
135 nPageRightMargin = SDPAGE_WIDE_VALUE3;
136 nPageTopMargin = SDPAGE_WIDE_VALUE1;
137 nPageBottomMargin = SDPAGE_WIDE_VALUE1;
138}
139
140bool IsWide( const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin,
141 const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin )
142{
143 return( std::abs(nPageLeftMargin - SDPAGE_WIDE_VALUE2) <= SDPAGE_UNIT_THRESHOLD &&
144 std::abs(nPageRightMargin - SDPAGE_WIDE_VALUE2) <= SDPAGE_UNIT_THRESHOLD &&
145 std::abs(nPageTopMargin - SDPAGE_WIDE_VALUE1) <= SDPAGE_UNIT_THRESHOLD &&
146 std::abs(nPageBottomMargin - SDPAGE_WIDE_VALUE1) <= SDPAGE_UNIT_THRESHOLD );
147}
148
149void SetWide( ::tools::Long& nPageLeftMargin, ::tools::Long& nPageRightMargin,
150 ::tools::Long& nPageTopMargin, ::tools::Long& nPageBottomMargin )
151{
152 nPageLeftMargin = SDPAGE_WIDE_VALUE2;
153 nPageRightMargin = SDPAGE_WIDE_VALUE2;
154 nPageTopMargin = SDPAGE_WIDE_VALUE1;
155 nPageBottomMargin = SDPAGE_WIDE_VALUE1;
156}
157}
158
159/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SDPAGE_UNIT_THRESHOLD
#define SDPAGE_MODERATE_LR
#define SDPAGE_NO_MARGIN
#define SDPAGE_NORMAL_VALUE
#define SDPAGE_WIDE_VALUE2
#define SDPAGE_WIDE_VALUE3
#define SDPAGE_NARROW_VALUE
#define SDPAGE_WIDE_VALUE1
bool IsNormal075(const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin, const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin)
bool IsModerate(const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin, const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin)
void SetNone(::tools::Long &nPageLeftMargin, ::tools::Long &nPageRightMargin, ::tools::Long &nPageTopMargin, ::tools::Long &nPageBottomMargin)
bool IsWide(const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin, const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin)
bool IsNone(const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin, const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin)
void SetNarrow(::tools::Long &nPageLeftMargin, ::tools::Long &nPageRightMargin, ::tools::Long &nPageTopMargin, ::tools::Long &nPageBottomMargin)
bool IsNarrow(const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin, const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin)
bool IsNormal125(const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin, const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin)
void SetNormal125(::tools::Long &nPageLeftMargin, ::tools::Long &nPageRightMargin, ::tools::Long &nPageTopMargin, ::tools::Long &nPageBottomMargin)
void SetNormal075(::tools::Long &nPageLeftMargin, ::tools::Long &nPageRightMargin, ::tools::Long &nPageTopMargin, ::tools::Long &nPageBottomMargin)
void SetModerate(::tools::Long &nPageLeftMargin, ::tools::Long &nPageRightMargin, ::tools::Long &nPageTopMargin, ::tools::Long &nPageBottomMargin)
void SetNormal100(::tools::Long &nPageLeftMargin, ::tools::Long &nPageRightMargin, ::tools::Long &nPageTopMargin, ::tools::Long &nPageBottomMargin)
void SetWide(::tools::Long &nPageLeftMargin, ::tools::Long &nPageRightMargin, ::tools::Long &nPageTopMargin, ::tools::Long &nPageBottomMargin)
bool IsNormal100(const ::tools::Long nPageLeftMargin, const ::tools::Long nPageRightMargin, const ::tools::Long nPageTopMargin, const ::tools::Long nPageBottomMargin)
long Long