Coverage Report

Created: 2025-12-31 10:39

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