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>
27 #include <vcl/TypeSerializer.hxx>
28 
30 {
33  // NOTE: these Fraction must NOT have more than 32 bits precision
34  // because ReadFraction / WriteFraction do only 32 bits, so more than
35  // that cannot be stored in MetaFiles!
36  // => call ReduceInaccurate whenever setting these
39  bool mbSimple;
40 
41  ImplMapMode();
42  ImplMapMode(const ImplMapMode& rImpMapMode);
43 
44  bool operator==( const ImplMapMode& rImpMapMode ) const;
45 };
46 
48  maOrigin( 0, 0 ),
49  maScaleX( 1, 1 ),
50  maScaleY( 1, 1 )
51 {
52  meUnit = MapUnit::MapPixel;
53  mbSimple = true;
54 }
55 
57 
58 bool MapMode::ImplMapMode::operator==( const ImplMapMode& rImpMapMode ) const
59 {
60  return meUnit == rImpMapMode.meUnit
61  && maOrigin == rImpMapMode.maOrigin
62  && maScaleX == rImpMapMode.maScaleX
63  && maScaleY == rImpMapMode.maScaleY;
64 }
65 
66 namespace
67 {
68  MapMode::ImplType& GetGlobalDefault()
69  {
70  static MapMode::ImplType gDefault;
71  return gDefault;
72  }
73 }
74 
75 MapMode::MapMode() : mpImplMapMode(GetGlobalDefault())
76 {
77 }
78 
79 MapMode::MapMode( const MapMode& ) = default;
80 
82 {
83  mpImplMapMode->meUnit = eUnit;
84 }
85 
86 MapMode::MapMode( MapUnit eUnit, const Point& rLogicOrg,
87  const Fraction& rScaleX, const Fraction& rScaleY )
88 {
89  mpImplMapMode->meUnit = eUnit;
90  mpImplMapMode->maOrigin = rLogicOrg;
91  mpImplMapMode->maScaleX = rScaleX;
92  mpImplMapMode->maScaleY = rScaleY;
93  mpImplMapMode->maScaleX.ReduceInaccurate(32);
94  mpImplMapMode->maScaleY.ReduceInaccurate(32);
95  mpImplMapMode->mbSimple = false;
96 }
97 
98 MapMode::~MapMode() = default;
99 
101 {
102  mpImplMapMode->meUnit = eUnit;
103 }
104 
105 void MapMode::SetOrigin( const Point& rLogicOrg )
106 {
107  mpImplMapMode->maOrigin = rLogicOrg;
108  mpImplMapMode->mbSimple = false;
109 }
110 
111 void MapMode::SetScaleX( const Fraction& rScaleX )
112 {
113  mpImplMapMode->maScaleX = rScaleX;
114  mpImplMapMode->maScaleX.ReduceInaccurate(32);
115  mpImplMapMode->mbSimple = false;
116 }
117 
118 void MapMode::SetScaleY( const Fraction& rScaleY )
119 {
120  mpImplMapMode->maScaleY = rScaleY;
121  mpImplMapMode->maScaleY.ReduceInaccurate(32);
122  mpImplMapMode->mbSimple = false;
123 }
124 
125 MapMode& MapMode::operator=( const MapMode& ) = default;
126 
127 MapMode& MapMode::operator=( MapMode&& ) = default;
128 
129 bool MapMode::operator==( const MapMode& rMapMode ) const
130 {
131  return mpImplMapMode == rMapMode.mpImplMapMode;
132 }
133 
134 bool MapMode::IsDefault() const
135 {
136  return mpImplMapMode.same_object(GetGlobalDefault());
137 }
138 
139 size_t MapMode::GetHashValue() const
140 {
141  size_t hash = 0;
142  o3tl::hash_combine( hash, mpImplMapMode->meUnit );
143  o3tl::hash_combine( hash, mpImplMapMode->maOrigin.GetHashValue());
144  o3tl::hash_combine( hash, mpImplMapMode->maScaleX.GetHashValue());
145  o3tl::hash_combine( hash, mpImplMapMode->maScaleY.GetHashValue());
146  o3tl::hash_combine( hash, mpImplMapMode->mbSimple );
147  return hash;
148 }
149 
150 MapUnit MapMode::GetMapUnit() const { return mpImplMapMode->meUnit; }
151 
152 const Point& MapMode::GetOrigin() const { return mpImplMapMode->maOrigin; }
153 
154 const Fraction& MapMode::GetScaleX() const { return mpImplMapMode->maScaleX; }
155 
156 const Fraction& MapMode::GetScaleY() const { return mpImplMapMode->maScaleY; }
157 
158 bool MapMode::IsSimple() const { return mpImplMapMode->mbSimple; }
159 
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Fraction & GetScaleX() const
Definition: mapmod.cxx:154
MapMode & operator=(const MapMode &rMapMode)
bool IsSimple() const
Definition: mapmod.cxx:158
size_t GetHashValue() const
Definition: mapmod.cxx:139
Fraction maScaleX
Definition: mapmod.cxx:37
bool IsDefault() const
Definition: mapmod.cxx:134
const Fraction & GetScaleY() const
Definition: mapmod.cxx:156
void SetMapUnit(MapUnit eUnit)
Definition: mapmod.cxx:100
Fraction maScaleY
Definition: mapmod.cxx:38
MapMode()
Definition: mapmod.cxx:75
void SetScaleX(const Fraction &rScaleX)
Definition: mapmod.cxx:111
void SetOrigin(const Point &rOrigin)
Definition: mapmod.cxx:105
bool same_object(const cow_wrapper &rOther) const
void SetScaleY(const Fraction &rScaleY)
Definition: mapmod.cxx:118
std::enable_if_t<(sizeof(N)==4)> hash_combine(N &nSeed, T const *pValue, size_t nCount)
MapUnit GetMapUnit() const
Definition: mapmod.cxx:150
bool operator==(const ImplMapMode &rImpMapMode) const
Definition: mapmod.cxx:58
ImplType mpImplMapMode
Definition: mapmod.hxx:78
Any maOrigin
const Point & GetOrigin() const
Definition: mapmod.cxx:152
MapUnit
bool operator==(const MapMode &rMapMode) const
Definition: mapmod.cxx:129