LibreOffice Module vcl (master) 1
mapmod.cxx
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
20#include <vcl/mapmod.hxx>
21
22#include <o3tl/hash_combine.hxx>
23#include <tools/gen.hxx>
24#include <tools/fract.hxx>
25#include <tools/stream.hxx>
26#include <tools/vcompat.hxx>
28
30{
34 // NOTE: these Fraction must NOT have more than 32 bits precision
35 // because ReadFraction / WriteFraction do only 32 bits, so more than
36 // that cannot be stored in MetaFiles!
37 // => call ReduceInaccurate whenever setting these
40
42 ImplMapMode(MapUnit eMapUnit);
43 ImplMapMode(const ImplMapMode& rImpMapMode);
44
45 bool operator==( const ImplMapMode& rImpMapMode ) const;
46};
47
49 maOrigin( 0, 0 ),
50 maScaleX( 1, 1 ),
51 maScaleY( 1, 1 )
52{
53 meUnit = MapUnit::MapPixel;
54 mbSimple = true;
55}
56
58 maOrigin( 0, 0 ),
59 maScaleX( 1, 1 ),
60 maScaleY( 1, 1 )
61{
62 meUnit = eMapUnit;
63 mbSimple = true;
64}
65
67
68bool MapMode::ImplMapMode::operator==( const ImplMapMode& rImpMapMode ) const
69{
70 return meUnit == rImpMapMode.meUnit
71 && maOrigin == rImpMapMode.maOrigin
72 && maScaleX == rImpMapMode.maScaleX
73 && maScaleY == rImpMapMode.maScaleY;
74}
75
76namespace
77{
78
79 MapMode::ImplType& GetGlobalDefault()
80 {
81 static MapMode::ImplType gDefault;
82 return gDefault;
83 }
84 MapMode::ImplType GetUnitDefault(MapUnit mapUnit)
85 {
86 static MapMode::ImplType defaults[]
87 {
88 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::Map100thMM) ),
89 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::Map10thMM) ),
90 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::MapMM) ),
91 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::MapCM) ),
92 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::Map1000thInch) ),
93 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::Map100thInch) ),
94 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::Map10thInch) ),
95 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::MapInch) ),
96 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::MapPoint) ),
97 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::MapTwip) ),
98 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::MapPixel) ),
99 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::MapSysFont) ),
100 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::MapAppFont) ),
101 MapMode::ImplType( MapMode::ImplMapMode(MapUnit::MapRelative) ),
102 };
103 if (mapUnit <= MapUnit::MapRelative) {
104 return MapMode::ImplType(defaults[static_cast<int>(mapUnit)]); // [-loplugin:redundantfcast] false positive
105 }
106 // sometimes the SvmReader stuff will generate a bogus mapunit value
108 }
109}
110
111MapMode::MapMode() : mpImplMapMode(GetGlobalDefault())
112{
113}
114
115MapMode::MapMode( const MapMode& ) = default;
116
117MapMode::MapMode( MapUnit eUnit ) : mpImplMapMode(GetUnitDefault(eUnit))
118{
119}
120
121MapMode::MapMode( MapUnit eUnit, const Point& rLogicOrg,
122 const Fraction& rScaleX, const Fraction& rScaleY )
123{
124 mpImplMapMode->meUnit = eUnit;
125 mpImplMapMode->maOrigin = rLogicOrg;
126 mpImplMapMode->maScaleX = rScaleX;
127 mpImplMapMode->maScaleY = rScaleY;
128 mpImplMapMode->mbSimple = false;
129}
130
131MapMode::~MapMode() = default;
132
134{
135 mpImplMapMode->meUnit = eUnit;
136}
137
138void MapMode::SetOrigin( const Point& rLogicOrg )
139{
140 mpImplMapMode->maOrigin = rLogicOrg;
141 mpImplMapMode->mbSimple = false;
142}
143
144void MapMode::SetScaleX( const Fraction& rScaleX )
145{
146 mpImplMapMode->maScaleX = rScaleX;
147 mpImplMapMode->mbSimple = false;
148}
149
150void MapMode::SetScaleY( const Fraction& rScaleY )
151{
152 mpImplMapMode->maScaleY = rScaleY;
153 mpImplMapMode->mbSimple = false;
154}
155
156MapMode& MapMode::operator=( const MapMode& ) = default;
157
158MapMode& MapMode::operator=( MapMode&& ) = default;
159
160bool MapMode::operator==( const MapMode& rMapMode ) const
161{
162 return mpImplMapMode == rMapMode.mpImplMapMode;
163}
164
166{
167 return mpImplMapMode.same_object(GetGlobalDefault());
168}
169
171{
172 size_t hash = 0;
173 o3tl::hash_combine( hash, mpImplMapMode->meUnit );
174 o3tl::hash_combine( hash, mpImplMapMode->maOrigin.GetHashValue());
175 o3tl::hash_combine( hash, mpImplMapMode->maScaleX.GetHashValue());
176 o3tl::hash_combine( hash, mpImplMapMode->maScaleY.GetHashValue());
177 o3tl::hash_combine( hash, mpImplMapMode->mbSimple );
178 return hash;
179}
180
181MapUnit MapMode::GetMapUnit() const { return mpImplMapMode->meUnit; }
182
183const Point& MapMode::GetOrigin() const { return mpImplMapMode->maOrigin; }
184
185const Fraction& MapMode::GetScaleX() const { return mpImplMapMode->maScaleX; }
186
187const Fraction& MapMode::GetScaleY() const { return mpImplMapMode->maScaleY; }
188
189bool MapMode::IsSimple() const { return mpImplMapMode->mbSimple; }
190
191/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Any maOrigin
MapMode & operator=(const MapMode &rMapMode)
bool operator==(const MapMode &rMapMode) const
Definition: mapmod.cxx:160
void SetOrigin(const Point &rOrigin)
Definition: mapmod.cxx:138
void SetScaleY(const Fraction &rScaleY)
Definition: mapmod.cxx:150
const Fraction & GetScaleX() const
Definition: mapmod.cxx:185
MapUnit GetMapUnit() const
Definition: mapmod.cxx:181
bool IsSimple() const
Definition: mapmod.cxx:189
size_t GetHashValue() const
Definition: mapmod.cxx:170
MapMode()
Definition: mapmod.cxx:111
void SetMapUnit(MapUnit eUnit)
Definition: mapmod.cxx:133
const Point & GetOrigin() const
Definition: mapmod.cxx:183
const Fraction & GetScaleY() const
Definition: mapmod.cxx:187
o3tl::cow_wrapper< ImplMapMode, o3tl::ThreadSafeRefCountingPolicy > ImplType
Definition: mapmod.hxx:72
bool IsDefault() const
Definition: mapmod.cxx:165
ImplType mpImplMapMode
Definition: mapmod.hxx:78
void SetScaleX(const Fraction &rScaleX)
Definition: mapmod.cxx:144
bool same_object(const cow_wrapper &rOther) const
MapUnit
std::enable_if_t<(sizeof(N)==4)> hash_combine(N &nSeed, T const *pValue, size_t nCount)
Fraction maScaleY
Definition: mapmod.cxx:39
ImplMapMode(const ImplMapMode &rImpMapMode)
Fraction maScaleX
Definition: mapmod.cxx:38
bool operator==(const ImplMapMode &rImpMapMode) const
Definition: mapmod.cxx:68