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