1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/mapmod.hxx>
22 #include <tools/gen.hxx>
23 #include <tools/fract.hxx>
24 #include <tools/stream.hxx>
25 #include <tools/vcompat.hxx>
26 #include <rtl/instance.hxx>
27 #include <vcl/TypeSerializer.hxx>
29 struct MapMode::ImplMapMode
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
42 ImplMapMode(const ImplMapMode
& rImpMapMode
);
44 bool operator==( const ImplMapMode
& rImpMapMode
) const;
47 MapMode::ImplMapMode::ImplMapMode() :
52 meUnit
= MapUnit::MapPixel
;
56 MapMode::ImplMapMode::ImplMapMode( const ImplMapMode
& ) = default;
58 bool MapMode::ImplMapMode::operator==( const ImplMapMode
& rImpMapMode
) const
60 return meUnit
== rImpMapMode
.meUnit
61 && maOrigin
== rImpMapMode
.maOrigin
62 && maScaleX
== rImpMapMode
.maScaleX
63 && maScaleY
== rImpMapMode
.maScaleY
;
68 struct theGlobalDefault
:
69 public rtl::Static
< MapMode::ImplType
, theGlobalDefault
> {};
72 MapMode::MapMode() : mpImplMapMode(theGlobalDefault::get())
76 MapMode::MapMode( const MapMode
& ) = default;
78 MapMode::MapMode( MapUnit eUnit
) : mpImplMapMode()
80 mpImplMapMode
->meUnit
= eUnit
;
83 MapMode::MapMode( MapUnit eUnit
, const Point
& rLogicOrg
,
84 const Fraction
& rScaleX
, const Fraction
& rScaleY
)
86 mpImplMapMode
->meUnit
= eUnit
;
87 mpImplMapMode
->maOrigin
= rLogicOrg
;
88 mpImplMapMode
->maScaleX
= rScaleX
;
89 mpImplMapMode
->maScaleY
= rScaleY
;
90 mpImplMapMode
->maScaleX
.ReduceInaccurate(32);
91 mpImplMapMode
->maScaleY
.ReduceInaccurate(32);
92 mpImplMapMode
->mbSimple
= false;
95 MapMode::~MapMode() = default;
97 void MapMode::SetMapUnit( MapUnit eUnit
)
99 mpImplMapMode
->meUnit
= eUnit
;
102 void MapMode::SetOrigin( const Point
& rLogicOrg
)
104 mpImplMapMode
->maOrigin
= rLogicOrg
;
105 mpImplMapMode
->mbSimple
= false;
108 void MapMode::SetScaleX( const Fraction
& rScaleX
)
110 mpImplMapMode
->maScaleX
= rScaleX
;
111 mpImplMapMode
->maScaleX
.ReduceInaccurate(32);
112 mpImplMapMode
->mbSimple
= false;
115 void MapMode::SetScaleY( const Fraction
& rScaleY
)
117 mpImplMapMode
->maScaleY
= rScaleY
;
118 mpImplMapMode
->maScaleY
.ReduceInaccurate(32);
119 mpImplMapMode
->mbSimple
= false;
122 MapMode
& MapMode::operator=( const MapMode
& ) = default;
124 MapMode
& MapMode::operator=( MapMode
&& ) = default;
126 bool MapMode::operator==( const MapMode
& rMapMode
) const
128 return mpImplMapMode
== rMapMode
.mpImplMapMode
;
131 bool MapMode::IsDefault() const
133 return mpImplMapMode
.same_object(theGlobalDefault::get());
136 MapUnit
MapMode::GetMapUnit() const { return mpImplMapMode
->meUnit
; }
138 const Point
& MapMode::GetOrigin() const { return mpImplMapMode
->maOrigin
; }
140 const Fraction
& MapMode::GetScaleX() const { return mpImplMapMode
->maScaleX
; }
142 const Fraction
& MapMode::GetScaleY() const { return mpImplMapMode
->maScaleY
; }
144 bool MapMode::IsSimple() const { return mpImplMapMode
->mbSimple
; }
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */