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 <vcl/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 MapUnit MapMode::GetMapUnit() const { return mpImplMapMode->meUnit; }
137 
138 const Point& MapMode::GetOrigin() const { return mpImplMapMode->maOrigin; }
139 
140 const Fraction& MapMode::GetScaleX() const { return mpImplMapMode->maScaleX; }
141 
142 const Fraction& MapMode::GetScaleY() const { return mpImplMapMode->maScaleY; }
143 
144 bool MapMode::IsSimple() const { return mpImplMapMode->mbSimple; }
145 
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
const Fraction & GetScaleX() const
Definition: mapmod.cxx:140
MapMode & operator=(const MapMode &rMapMode)
bool IsSimple() const
Definition: mapmod.cxx:144
Fraction maScaleX
Definition: mapmod.cxx:37
bool IsDefault() const
Definition: mapmod.cxx:131
const Fraction & GetScaleY() const
Definition: mapmod.cxx:142
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:136
bool operator==(const ImplMapMode &rImpMapMode) const
Definition: mapmod.cxx:58
ImplType mpImplMapMode
Definition: mapmod.hxx:75
Any maOrigin
const Point & GetOrigin() const
Definition: mapmod.cxx:138
MapUnit
bool operator==(const MapMode &rMapMode) const
Definition: mapmod.cxx:126