/src/libreoffice/vcl/inc/CoordinateMapper.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
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 | | #pragma once |
21 | | |
22 | | #include <sal/types.h> |
23 | | #include <tools/long.hxx> |
24 | | |
25 | | #include <vcl/dllapi.h> |
26 | | #include <vcl/mapmod.hxx> |
27 | | |
28 | | class CoordinateMapper |
29 | | { |
30 | | private: |
31 | | bool mbMap = false; |
32 | | MapMode maMapMode; |
33 | | ImplMapRes maMapRes; |
34 | | |
35 | | // #i75163# |
36 | | mutable basegfx::B2DHomMatrix* mpViewTransform = nullptr; |
37 | | mutable basegfx::B2DHomMatrix* mpInverseViewTransform = nullptr; |
38 | | |
39 | | sal_Int32 mnDPIX = 0; |
40 | | sal_Int32 mnDPIY = 0; |
41 | | sal_Int32 mnDPIScalePercentage = 100; |
42 | | |
43 | | /// Output offset for device output in pixel (pseudo window offset within window system's frames) |
44 | | tools::Long mnOutOffX = 0; |
45 | | /// Output offset for device output in pixel (pseudo window offset within window system's frames) |
46 | | tools::Long mnOutOffY = 0; |
47 | | |
48 | | /// Additional output pixel offset, applied in LogicToPixel (used by SetPixelOffset/GetPixelOffset) |
49 | | tools::Long mnOutOffOrigX = 0; |
50 | | /// Additional output pixel offset, applied in LogicToPixel (used by SetPixelOffset/GetPixelOffset) |
51 | | tools::Long mnOutOffOrigY = 0; |
52 | | |
53 | | /// Additional output offset in _logical_ coordinates, applied in PixelToLogic (used by SetPixelOffset/GetPixelOffset) |
54 | | tools::Long mnOutOffLogicX = 0; |
55 | | /// Additional output offset in _logical_ coordinates, applied in PixelToLogic (used by SetPixelOffset/GetPixelOffset) |
56 | | tools::Long mnOutOffLogicY = 0; |
57 | | |
58 | | tools::Long mnOutWidth = 0; |
59 | | tools::Long mnOutHeight = 0; |
60 | | |
61 | | public: |
62 | 685M | bool IsMapModeEnabled() const { return mbMap; } |
63 | 4.11M | void EnableMapMode(bool bEnable = true) { mbMap = bEnable; } |
64 | | |
65 | | sal_Int32 GetDPIX() const; |
66 | | sal_Int32 GetDPIY() const; |
67 | | |
68 | | void SetDPIX(sal_Int32 nDPIX); |
69 | | void SetDPIY(sal_Int32 nDPIY); |
70 | | |
71 | | sal_Int32 GetDPIScalePercentage() const; |
72 | | float GetDPIScaleFactor() const; |
73 | | void SetDPIScalePercentage(sal_Int32 nPercentage); |
74 | | |
75 | | tools::Long GetDeviceOriginX() const; |
76 | | tools::Long GetDeviceOriginY() const; |
77 | | |
78 | | void SetDeviceOriginX(tools::Long nOutOffX); |
79 | | void SetOutOffYPixel(tools::Long nOutOffY); |
80 | | |
81 | | Point GetOutputOffPixel() const; |
82 | | |
83 | | tools::Long GetOutputWidthPixel() const; |
84 | | tools::Long GetOutputHeightPixel() const; |
85 | | Size GetOutputSizePixel() const; |
86 | | |
87 | 0 | Size GetPixelOffset() const { return Size(mnOutOffOrigX, mnOutOffOrigY); } |
88 | | void SetPixelOffset(const Size& rSize); |
89 | 3.59M | tools::Long GetPixelXOffset() const { return mnOutOffOrigX; } |
90 | 3.59M | tools::Long GetPixelYOffset() const { return mnOutOffOrigY; } |
91 | | |
92 | | void SetLogicalOffset(const Size& rSize); |
93 | 0 | tools::Long GetLogicalXOffset() const { return mnOutOffLogicX; } |
94 | 0 | tools::Long GetLogicalYOffset() const { return mnOutOffLogicY; } |
95 | | |
96 | | void SetOutputWidthPixel(tools::Long nWidth); |
97 | | void SetOutputHeightPixel(tools::Long nHeight); |
98 | | |
99 | 24.6M | const MapMode& GetMapMode() const { return maMapMode; } |
100 | 174 | bool IsDefaultMapMode() const { return maMapMode.IsDefault(); } |
101 | 87.1k | void ResetMapMode() { maMapMode = MapMode(); } |
102 | 2.91M | void ResetMapMode(const MapMode& rMapMode) { maMapMode = rMapMode; } |
103 | 2.81M | MapUnit GetMapUnit() const { return maMapMode.GetMapUnit(); } |
104 | | |
105 | 242k | double GetScaleX() const { return maMapMode.GetScaleX(); } |
106 | 242k | double GetScaleY() const { return maMapMode.GetScaleY(); } |
107 | 358 | void SetScaleX(double nX) { maMapMode.SetScaleX(nX); } |
108 | 358 | void SetScaleY(double nY) { maMapMode.SetScaleY(nY); } |
109 | | |
110 | 358 | void SetOrigin(const Point& rPt) { maMapMode.SetOrigin(rPt); } |
111 | | |
112 | 3.28k | tools::Long GetMappingXOffset() const { return maMapRes.mnMapOfsX; } |
113 | 3.28k | tools::Long GetMappingYOffset() const { return maMapRes.mnMapOfsY; } |
114 | 6.72M | double GetMapResolutionScaleX() const { return maMapRes.mfMapScX; } |
115 | 13.4M | double GetMapResolutionScaleY() const { return maMapRes.mfMapScY; } |
116 | | |
117 | 241k | void SetMappingXOffset(tools::Long nOffset) { maMapRes.mnMapOfsX = nOffset; } |
118 | 241k | void SetMappingYOffset(tools::Long nOffset) { maMapRes.mnMapOfsY = nOffset; } |
119 | 0 | void SetMapResolutionScaleX(double fX) { maMapRes.mfMapScX = fX; } |
120 | 0 | void SetMapResolutionScaleY(double fY) { maMapRes.mfMapScY = fY; } |
121 | | |
122 | | void CalcMapResolution(const MapMode& rMapMode, tools::Long nDPIX, tools::Long nDPIY); |
123 | | |
124 | | ImplMapRes ResolveMapRes(const MapMode* pMode); |
125 | | |
126 | | /** Invalidate the view transformation. |
127 | | |
128 | | @since AOO bug 75163 (OpenOffice.org 2.4.3 - OOH 680 milestone 212) |
129 | | */ |
130 | | void InvalidateViewTransform(); |
131 | | basegfx::B2DHomMatrix GetViewTransformation() const; |
132 | | basegfx::B2DHomMatrix GetViewTransformation(const MapMode& rMapMode) const; |
133 | | basegfx::B2DHomMatrix GetInverseViewTransformation() const; |
134 | | basegfx::B2DHomMatrix GetInverseViewTransformation(const MapMode& rMapMode) const; |
135 | | basegfx::B2DHomMatrix GetDeviceTransformation() const; |
136 | | |
137 | | // ======================================================================== |
138 | | // PIPELINE STAGES (Coordinate Transitions) |
139 | | // ======================================================================== |
140 | | |
141 | | // Device <-> Window (Integer) |
142 | | tools::Long DeviceToWindowUnitsX(tools::Long nX) const; |
143 | | tools::Long DeviceToWindowUnitsY(tools::Long nY) const; |
144 | | tools::Long WindowToDeviceUnitsX(tools::Long nX) const; |
145 | | tools::Long WindowToDeviceUnitsY(tools::Long nY) const; |
146 | | |
147 | | // Device <-> Window (Sub-pixel) |
148 | | double DeviceToWindowSubPixelX(double fX) const; |
149 | | double DeviceToWindowSubPixelY(double fY) const; |
150 | | double WindowToDeviceSubPixelX(double fX) const; |
151 | | double WindowToDeviceSubPixelY(double fY) const; |
152 | | |
153 | | // Window <-> View (Integer) |
154 | | tools::Long WindowToViewUnitsX(tools::Long nX) const; |
155 | | tools::Long WindowToViewUnitsY(tools::Long nY) const; |
156 | | tools::Long ViewToWindowUnitsX(tools::Long nX) const; |
157 | | tools::Long ViewToWindowUnitsY(tools::Long nY) const; |
158 | | |
159 | | // View <-> LogicUnits (Scale and apply Logical Mapping Offset) |
160 | | tools::Long ViewToLogicUnitsX(tools::Long nX) const; |
161 | | tools::Long ViewToLogicUnitsY(tools::Long nY) const; |
162 | | tools::Long LogicUnitsToViewUnitsX(tools::Long nX) const; |
163 | | tools::Long LogicUnitsToViewUnitsY(tools::Long nY) const; |
164 | | tools::Long LogicUnitsToViewUnitsX(tools::Long nX, const ImplMapRes& rRes) const; |
165 | | tools::Long LogicUnitsToViewUnitsY(tools::Long nY, const ImplMapRes& rRes) const; |
166 | | |
167 | | // View <-> LogicUnits (Sub-pixel) |
168 | | double ViewSubPixelToLogicUnitsX(double fX) const; |
169 | | double ViewSubPixelToLogicUnitsY(double fY) const; |
170 | | tools::Long ViewSubPixelToLogicUnitsIntX(double fX) const; |
171 | | tools::Long ViewSubPixelToLogicUnitsIntY(double fY) const; |
172 | | double LogicUnitsToViewSubPixelX(double fX) const; |
173 | | double LogicUnitsToViewSubPixelY(double fY) const; |
174 | | |
175 | | // ======================================================================== |
176 | | // MASTER WRAPPERS (Multi-space Positional Transformations) |
177 | | // ======================================================================== |
178 | | |
179 | | // Device <-> Logic (Full journey) |
180 | | tools::Long DevicePixelToLogicX(tools::Long nX) const; |
181 | | tools::Long DevicePixelToLogicY(tools::Long nY) const; |
182 | | tools::Long LogicToDevicePixelX(tools::Long nX) const; |
183 | | tools::Long LogicToDevicePixelY(tools::Long nY) const; |
184 | | |
185 | | double DevicePixelToLogicSubPixelX(double fX) const; |
186 | | double DevicePixelToLogicSubPixelY(double fY) const; |
187 | | double LogicToDeviceSubPixelX(double fX) const; |
188 | | double LogicToDeviceSubPixelY(double fY) const; |
189 | | |
190 | | // Window <-> Logic |
191 | | tools::Long WindowToLogicX(tools::Long nX) const; |
192 | | tools::Long WindowToLogicY(tools::Long nY) const; |
193 | | tools::Long LogicToWindowX(tools::Long nX) const; |
194 | | tools::Long LogicToWindowY(tools::Long nY) const; |
195 | | |
196 | | double WindowToLogicSubPixelX(double fX) const; |
197 | | double WindowToLogicSubPixelY(double fY) const; |
198 | | double LogicToWindowSubPixelX(double fX) const; |
199 | | double LogicToWindowSubPixelY(double fY) const; |
200 | | |
201 | | // View <-> Absolute Logic (Includes mnOutOffLogicX/Y) |
202 | | tools::Long ViewToLogicX(tools::Long nX) const; |
203 | | tools::Long ViewToLogicY(tools::Long nY) const; |
204 | | |
205 | | // To resolve the return-type conflict, these now return double |
206 | | double ViewSubPixelToLogicX(double fX) const; |
207 | | double ViewSubPixelToLogicY(double fY) const; |
208 | | // View (Sub-pixel) -> Absolute Logic (Integer) |
209 | | // Note: This rounds the distance before stripping offsets to satisfy legacy test parity. |
210 | | tools::Long ViewSubPixelToLogicIntX(double fX) const; |
211 | | tools::Long ViewSubPixelToLogicIntY(double fY) const; |
212 | | tools::Long ViewSubPixelToLogicIntX(double fX, const ImplMapRes& rRes) const; |
213 | | tools::Long ViewSubPixelToLogicIntY(double fY, const ImplMapRes& rRes) const; |
214 | | double LogicToViewSubPixelX(double fX) const; |
215 | | double LogicToViewSubPixelY(double fY) const; |
216 | | |
217 | | // Logic -> Window units (Commonly used in OutputDevice::LogicToPixel) |
218 | | tools::Long LogicToWindowUnitsX(tools::Long nX) const; |
219 | | tools::Long LogicToWindowUnitsY(tools::Long nY) const; |
220 | | tools::Long LogicToWindowUnitsX(tools::Long nX, const ImplMapRes& rRes) const; |
221 | | tools::Long LogicToWindowUnitsY(tools::Long nY, const ImplMapRes& rRes) const; |
222 | | |
223 | | // ======================================================================== |
224 | | // DISTANCE SCALING (Raw Scalar Conversion, NO offsets applied) |
225 | | // ======================================================================== |
226 | | |
227 | | // Integer Distances |
228 | | tools::Long LogicToViewDistanceX(tools::Long n) const; |
229 | | tools::Long LogicToViewDistanceY(tools::Long n) const; |
230 | | tools::Long LogicToViewDistanceX(tools::Long n, double fScale) const; |
231 | | tools::Long LogicToViewDistanceY(tools::Long n, double fScale) const; |
232 | | tools::Long ViewToLogicDistanceX(tools::Long n) const; |
233 | | tools::Long ViewToLogicDistanceY(tools::Long n) const; |
234 | | tools::Long ViewToLogicDistanceX(tools::Long n, double fScale) const; |
235 | | tools::Long ViewToLogicDistanceY(tools::Long n, double fScale) const; |
236 | | |
237 | | // Double/Sub-Pixel Distances |
238 | | double LogicToViewDistanceSubPixelX(tools::Long n) const; |
239 | | double LogicToViewDistanceSubPixelY(tools::Long n) const; |
240 | | double LogicToViewDistanceSubPixelX(tools::Long n, double fScale) const; |
241 | | double LogicToViewDistanceSubPixelY(tools::Long n, double fScale) const; |
242 | | double ViewToLogicDistanceDoubleX(double n) const; |
243 | | double ViewToLogicDistanceDoubleY(double n) const; |
244 | | double ViewToLogicDistanceDoubleX(double n, double fScale) const; |
245 | | double ViewToLogicDistanceDoubleY(double n, double fScale) const; |
246 | | tools::Long ViewSubPixelToLogicDistanceX(double n) const; |
247 | | tools::Long ViewSubPixelToLogicDistanceY(double n) const; |
248 | | tools::Long ViewSubPixelToLogicDistanceX(double n, double fScale) const; |
249 | | tools::Long ViewSubPixelToLogicDistanceY(double n, double fScale) const; |
250 | | |
251 | | private: |
252 | | tools::Long ImplCalcDevicePixelX(tools::Long nX) const; |
253 | | tools::Long ImplCalcDevicePixelY(tools::Long nY) const; |
254 | | }; |
255 | | |
256 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |