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>
28 struct MapMode::ImplMapMode
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
41 ImplMapMode(const ImplMapMode
& rImpMapMode
);
43 bool operator==( const ImplMapMode
& rImpMapMode
) const;
46 MapMode::ImplMapMode::ImplMapMode() :
51 meUnit
= MapUnit::MapPixel
;
55 MapMode::ImplMapMode::ImplMapMode( const ImplMapMode
& rImplMapMode
) :
56 meUnit( rImplMapMode
.meUnit
),
57 maOrigin( rImplMapMode
.maOrigin
),
58 maScaleX( rImplMapMode
.maScaleX
),
59 maScaleY( rImplMapMode
.maScaleY
),
60 mbSimple( rImplMapMode
.mbSimple
)
64 bool MapMode::ImplMapMode::operator==( const ImplMapMode
& rImpMapMode
) const
66 return meUnit
== rImpMapMode
.meUnit
67 && maOrigin
== rImpMapMode
.maOrigin
68 && maScaleX
== rImpMapMode
.maScaleX
69 && maScaleY
== rImpMapMode
.maScaleY
;
74 struct theGlobalDefault
:
75 public rtl::Static
< MapMode::ImplType
, theGlobalDefault
> {};
78 MapMode::MapMode() : mpImplMapMode(theGlobalDefault::get())
82 MapMode::MapMode( const MapMode
& rMapMode
) : mpImplMapMode( rMapMode
.mpImplMapMode
)
86 MapMode::MapMode( MapUnit eUnit
) : mpImplMapMode()
88 mpImplMapMode
->meUnit
= eUnit
;
91 MapMode::MapMode( MapUnit eUnit
, const Point
& rLogicOrg
,
92 const Fraction
& rScaleX
, const Fraction
& rScaleY
)
94 mpImplMapMode
->meUnit
= eUnit
;
95 mpImplMapMode
->maOrigin
= rLogicOrg
;
96 mpImplMapMode
->maScaleX
= rScaleX
;
97 mpImplMapMode
->maScaleY
= rScaleY
;
98 mpImplMapMode
->maScaleX
.ReduceInaccurate(32);
99 mpImplMapMode
->maScaleY
.ReduceInaccurate(32);
100 mpImplMapMode
->mbSimple
= false;
107 void MapMode::SetMapUnit( MapUnit eUnit
)
109 mpImplMapMode
->meUnit
= eUnit
;
112 void MapMode::SetOrigin( const Point
& rLogicOrg
)
114 mpImplMapMode
->maOrigin
= rLogicOrg
;
115 mpImplMapMode
->mbSimple
= false;
118 void MapMode::SetScaleX( const Fraction
& rScaleX
)
120 mpImplMapMode
->maScaleX
= rScaleX
;
121 mpImplMapMode
->maScaleX
.ReduceInaccurate(32);
122 mpImplMapMode
->mbSimple
= false;
125 void MapMode::SetScaleY( const Fraction
& rScaleY
)
127 mpImplMapMode
->maScaleY
= rScaleY
;
128 mpImplMapMode
->maScaleY
.ReduceInaccurate(32);
129 mpImplMapMode
->mbSimple
= false;
132 double MapMode::GetUnitMultiplier() const
135 switch ( GetMapUnit() )
137 case MapUnit::MapPixel
:
138 case MapUnit::MapSysFont
:
139 case MapUnit::MapAppFont
:
141 case MapUnit::Map100thMM
:
144 case MapUnit::Map10thMM
:
147 case MapUnit::MapMM
:
150 case MapUnit::MapCM
:
153 case MapUnit::Map1000thInch
:
156 case MapUnit::Map100thInch
:
159 case MapUnit::Map10thInch
:
162 case MapUnit::MapInch
:
165 case MapUnit::MapTwip
:
168 case MapUnit::MapPoint
:
178 MapMode
& MapMode::operator=( const MapMode
& rMapMode
)
180 mpImplMapMode
= rMapMode
.mpImplMapMode
;
184 MapMode
& MapMode::operator=( MapMode
&& rMapMode
)
186 mpImplMapMode
= std::move(rMapMode
.mpImplMapMode
);
190 bool MapMode::operator==( const MapMode
& rMapMode
) const
192 return mpImplMapMode
== rMapMode
.mpImplMapMode
;
195 bool MapMode::IsDefault() const
197 return mpImplMapMode
.same_object(theGlobalDefault::get());
200 SvStream
& ReadMapMode( SvStream
& rIStm
, MapMode
& rMapMode
)
202 VersionCompat
aCompat( rIStm
, StreamMode::READ
);
205 rIStm
.ReadUInt16( nTmp16
); rMapMode
.mpImplMapMode
->meUnit
= (MapUnit
) nTmp16
;
206 ReadPair( rIStm
, rMapMode
.mpImplMapMode
->maOrigin
);
207 ReadFraction( rIStm
, rMapMode
.mpImplMapMode
->maScaleX
);
208 ReadFraction( rIStm
, rMapMode
.mpImplMapMode
->maScaleY
);
209 rIStm
.ReadCharAsBool( rMapMode
.mpImplMapMode
->mbSimple
);
214 SvStream
& WriteMapMode( SvStream
& rOStm
, const MapMode
& rMapMode
)
216 VersionCompat
aCompat( rOStm
, StreamMode::WRITE
, 1 );
218 rOStm
.WriteUInt16( (sal_uInt16
)rMapMode
.mpImplMapMode
->meUnit
);
219 WritePair( rOStm
, rMapMode
.mpImplMapMode
->maOrigin
);
220 WriteFraction( rOStm
, rMapMode
.mpImplMapMode
->maScaleX
);
221 WriteFraction( rOStm
, rMapMode
.mpImplMapMode
->maScaleY
);
222 rOStm
.WriteBool( rMapMode
.mpImplMapMode
->mbSimple
);
228 MapUnit
MapMode::GetMapUnit() const { return mpImplMapMode
->meUnit
; }
230 const Point
& MapMode::GetOrigin() const { return mpImplMapMode
->maOrigin
; }
232 const Fraction
& MapMode::GetScaleX() const { return mpImplMapMode
->maScaleX
; }
234 const Fraction
& MapMode::GetScaleY() const { return mpImplMapMode
->maScaleY
; }
236 bool MapMode::IsSimple() const { return mpImplMapMode
->mbSimple
; }
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */