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 <rtl/instance.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  struct theGlobalDefault :
68  public rtl::Static< MapMode::ImplType, theGlobalDefault > {};
69 }
70 
71 MapMode::MapMode() : mpImplMapMode(theGlobalDefault::get())
72 {
73 }
74 
75 MapMode::MapMode( const MapMode& ) = default;
76 
77 MapMode::MapMode( MapUnit eUnit ) : mpImplMapMode()
78 {
79  mpImplMapMode->meUnit = eUnit;
80 }
81 
82 MapMode::MapMode( MapUnit eUnit, const Point& rLogicOrg,
83  const Fraction& rScaleX, const Fraction& rScaleY )
84 {
85  mpImplMapMode->meUnit = eUnit;
86  mpImplMapMode->maOrigin = rLogicOrg;
87  mpImplMapMode->maScaleX = rScaleX;
88  mpImplMapMode->maScaleY = rScaleY;
89  mpImplMapMode->maScaleX.ReduceInaccurate(32);
90  mpImplMapMode->maScaleY.ReduceInaccurate(32);
91  mpImplMapMode->mbSimple = false;
92 }
93 
94 MapMode::~MapMode() = default;
95 
97 {
98  mpImplMapMode->meUnit = eUnit;
99 }
100 
101 void MapMode::SetOrigin( const Point& rLogicOrg )
102 {
103  mpImplMapMode->maOrigin = rLogicOrg;
104  mpImplMapMode->mbSimple = false;
105 }
106 
107 void MapMode::SetScaleX( const Fraction& rScaleX )
108 {
109  mpImplMapMode->maScaleX = rScaleX;
110  mpImplMapMode->maScaleX.ReduceInaccurate(32);
111  mpImplMapMode->mbSimple = false;
112 }
113 
114 void MapMode::SetScaleY( const Fraction& rScaleY )
115 {
116  mpImplMapMode->maScaleY = rScaleY;
117  mpImplMapMode->maScaleY.ReduceInaccurate(32);
118  mpImplMapMode->mbSimple = false;
119 }
120 
121 MapMode& MapMode::operator=( const MapMode& ) = default;
122 
123 MapMode& MapMode::operator=( MapMode&& ) = default;
124 
125 bool MapMode::operator==( const MapMode& rMapMode ) const
126 {
127  return mpImplMapMode == rMapMode.mpImplMapMode;
128 }
129 
130 bool MapMode::IsDefault() const
131 {
132  return mpImplMapMode.same_object(theGlobalDefault::get());
133 }
134 
135 SvStream& ReadMapMode( SvStream& rIStm, MapMode& rMapMode )
136 {
137  VersionCompat aCompat( rIStm, StreamMode::READ );
138  sal_uInt16 nTmp16;
139 
140  rIStm.ReadUInt16( nTmp16 ); rMapMode.mpImplMapMode->meUnit = static_cast<MapUnit>(nTmp16);
141  ReadPair( rIStm, rMapMode.mpImplMapMode->maOrigin );
142  ReadFraction( rIStm, rMapMode.mpImplMapMode->maScaleX );
143  ReadFraction( rIStm, rMapMode.mpImplMapMode->maScaleY );
144  rIStm.ReadCharAsBool( rMapMode.mpImplMapMode->mbSimple );
145 
146  return rIStm;
147 }
148 
149 SvStream& WriteMapMode( SvStream& rOStm, const MapMode& rMapMode )
150 {
151  VersionCompat aCompat( rOStm, StreamMode::WRITE, 1 );
152 
153  rOStm.WriteUInt16( static_cast<sal_uInt16>(rMapMode.mpImplMapMode->meUnit) );
154  WritePair( rOStm, rMapMode.mpImplMapMode->maOrigin );
155  WriteFraction( rOStm, rMapMode.mpImplMapMode->maScaleX );
156  WriteFraction( rOStm, rMapMode.mpImplMapMode->maScaleY );
157  rOStm.WriteBool( rMapMode.mpImplMapMode->mbSimple );
158 
159  return rOStm;
160 }
161 
162 
163 MapUnit MapMode::GetMapUnit() const { return mpImplMapMode->meUnit; }
164 
165 const Point& MapMode::GetOrigin() const { return mpImplMapMode->maOrigin; }
166 
167 const Fraction& MapMode::GetScaleX() const { return mpImplMapMode->maScaleX; }
168 
169 const Fraction& MapMode::GetScaleY() const { return mpImplMapMode->maScaleY; }
170 
171 bool MapMode::IsSimple() const { return mpImplMapMode->mbSimple; }
172 
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
SvStream & WriteBool(bool b)
const Fraction & GetScaleX() const
Definition: mapmod.cxx:167
MapMode & operator=(const MapMode &rMapMode)
SvStream & WriteUInt16(sal_uInt16 nUInt16)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
SvStream & WriteMapMode(SvStream &rOStm, const MapMode &rMapMode)
Definition: mapmod.cxx:149
SAL_DLLPRIVATE bool IsSimple() const
Definition: mapmod.cxx:171
SvStream & ReadCharAsBool(bool &rBool)
Fraction maScaleX
Definition: mapmod.cxx:36
bool IsDefault() const
Definition: mapmod.cxx:130
const Fraction & GetScaleY() const
Definition: mapmod.cxx:169
SvStream & ReadFraction(SvStream &rIStream, Fraction &rFract)
void SetMapUnit(MapUnit eUnit)
Definition: mapmod.cxx:96
Fraction maScaleY
Definition: mapmod.cxx:37
MapMode()
Definition: mapmod.cxx:71
void SetScaleX(const Fraction &rScaleX)
Definition: mapmod.cxx:107
void SetOrigin(const Point &rOrigin)
Definition: mapmod.cxx:101
bool same_object(const cow_wrapper &rOther) const
void SetScaleY(const Fraction &rScaleY)
Definition: mapmod.cxx:114
MapUnit GetMapUnit() const
Definition: mapmod.cxx:163
SvStream & WritePair(SvStream &rOStream, const Pair &rPair)
bool operator==(const ImplMapMode &rImpMapMode) const
Definition: mapmod.cxx:57
ImplType mpImplMapMode
Definition: mapmod.hxx:74
const Point & GetOrigin() const
Definition: mapmod.cxx:165
SvStream & WriteFraction(SvStream &rOStream, const Fraction &rFract)
MapUnit
SvStream & ReadMapMode(SvStream &rIStm, MapMode &rMapMode)
Definition: mapmod.cxx:135
SvStream & ReadPair(SvStream &rIStream, Pair &rPair)
bool operator==(const MapMode &rMapMode) const
Definition: mapmod.cxx:125