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{
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
40
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
58bool 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
66namespace
67{
68 MapMode::ImplType& GetGlobalDefault()
69 {
70 static MapMode::ImplType gDefault;
71 return gDefault;
72 }
73}
74
75MapMode::MapMode() : mpImplMapMode(GetGlobalDefault())
76{
77}
78
79MapMode::MapMode( const MapMode& ) = default;
80
82{
83 mpImplMapMode->meUnit = eUnit;
84}
85
86MapMode::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->mbSimple = false;
94}
95
96MapMode::~MapMode() = default;
97
99{
100 mpImplMapMode->meUnit = eUnit;
101}
102
103void MapMode::SetOrigin( const Point& rLogicOrg )
104{
105 mpImplMapMode->maOrigin = rLogicOrg;
106 mpImplMapMode->mbSimple = false;
107}
108
109void MapMode::SetScaleX( const Fraction& rScaleX )
110{
111 mpImplMapMode->maScaleX = rScaleX;
112 mpImplMapMode->mbSimple = false;
113}
114
115void MapMode::SetScaleY( const Fraction& rScaleY )
116{
117 mpImplMapMode->maScaleY = rScaleY;
118 mpImplMapMode->mbSimple = false;
119}
120
121MapMode& MapMode::operator=( const MapMode& ) = default;
122
123MapMode& MapMode::operator=( MapMode&& ) = default;
124
125bool MapMode::operator==( const MapMode& rMapMode ) const
126{
127 return mpImplMapMode == rMapMode.mpImplMapMode;
128}
129
131{
132 return mpImplMapMode.same_object(GetGlobalDefault());
133}
134
136{
137 size_t hash = 0;
138 o3tl::hash_combine( hash, mpImplMapMode->meUnit );
139 o3tl::hash_combine( hash, mpImplMapMode->maOrigin.GetHashValue());
140 o3tl::hash_combine( hash, mpImplMapMode->maScaleX.GetHashValue());
141 o3tl::hash_combine( hash, mpImplMapMode->maScaleY.GetHashValue());
142 o3tl::hash_combine( hash, mpImplMapMode->mbSimple );
143 return hash;
144}
145
146MapUnit MapMode::GetMapUnit() const { return mpImplMapMode->meUnit; }
147
148const Point& MapMode::GetOrigin() const { return mpImplMapMode->maOrigin; }
149
150const Fraction& MapMode::GetScaleX() const { return mpImplMapMode->maScaleX; }
151
152const Fraction& MapMode::GetScaleY() const { return mpImplMapMode->maScaleY; }
153
154bool MapMode::IsSimple() const { return mpImplMapMode->mbSimple; }
155
156/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Any maOrigin
MapMode & operator=(const MapMode &rMapMode)
bool operator==(const MapMode &rMapMode) const
Definition: mapmod.cxx:125
void SetOrigin(const Point &rOrigin)
Definition: mapmod.cxx:103
void SetScaleY(const Fraction &rScaleY)
Definition: mapmod.cxx:115
const Fraction & GetScaleX() const
Definition: mapmod.cxx:150
MapUnit GetMapUnit() const
Definition: mapmod.cxx:146
bool IsSimple() const
Definition: mapmod.cxx:154
size_t GetHashValue() const
Definition: mapmod.cxx:135
MapMode()
Definition: mapmod.cxx:75
void SetMapUnit(MapUnit eUnit)
Definition: mapmod.cxx:98
const Point & GetOrigin() const
Definition: mapmod.cxx:148
const Fraction & GetScaleY() const
Definition: mapmod.cxx:152
bool IsDefault() const
Definition: mapmod.cxx:130
ImplType mpImplMapMode
Definition: mapmod.hxx:78
void SetScaleX(const Fraction &rScaleX)
Definition: mapmod.cxx:109
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:38
ImplMapMode(const ImplMapMode &rImpMapMode)
Fraction maScaleX
Definition: mapmod.cxx:37
bool operator==(const ImplMapMode &rImpMapMode) const
Definition: mapmod.cxx:58