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