/src/libreoffice/vcl/source/outdev/ImplMapRes.cxx
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 | | #include <osl/diagnose.h> |
21 | | #include <tools/long.hxx> |
22 | | #include <tools/mapunit.hxx> |
23 | | |
24 | | #include <vcl/rendercontext/ImplMapRes.hxx> |
25 | | #include <vcl/mapmod.hxx> |
26 | | #include <vcl/vclptr.hxx> |
27 | | #include <vcl/virdev.hxx> |
28 | | #include <vcl/wrkwin.hxx> |
29 | | |
30 | | #include <svdata.hxx> |
31 | | |
32 | | void ImplMapRes::SetMapRes(const o3tl::Length eUnit) |
33 | 11.2M | { |
34 | 11.2M | const auto[nNum, nDen] = o3tl::getConversionMulDiv(eUnit, o3tl::Length::in); |
35 | 11.2M | mfMapScX = mfMapScY = double(nNum) / nDen; |
36 | 11.2M | }; |
37 | | |
38 | | void ImplMapRes::CalcMapResolution(const MapMode& rMapMode, tools::Long nDPIX, tools::Long nDPIY) |
39 | 11.3M | { |
40 | 11.3M | switch (rMapMode.GetMapUnit()) |
41 | 11.3M | { |
42 | 2.51k | case MapUnit::MapRelative: |
43 | 2.51k | break; |
44 | 1.02M | case MapUnit::Map100thMM: |
45 | 1.02M | SetMapRes(o3tl::Length::mm100); |
46 | 1.02M | break; |
47 | 12 | case MapUnit::Map10thMM: |
48 | 12 | SetMapRes(o3tl::Length::mm10); |
49 | 12 | break; |
50 | 87.9k | case MapUnit::MapMM: |
51 | 87.9k | SetMapRes(o3tl::Length::mm); |
52 | 87.9k | break; |
53 | 663 | case MapUnit::MapCM: |
54 | 663 | SetMapRes(o3tl::Length::cm); |
55 | 663 | break; |
56 | 0 | case MapUnit::Map1000thInch: |
57 | 0 | SetMapRes(o3tl::Length::in1000); |
58 | 0 | break; |
59 | 0 | case MapUnit::Map100thInch: |
60 | 0 | SetMapRes(o3tl::Length::in100); |
61 | 0 | break; |
62 | 0 | case MapUnit::Map10thInch: |
63 | 0 | SetMapRes(o3tl::Length::in10); |
64 | 0 | break; |
65 | 8.31k | case MapUnit::MapInch: |
66 | 8.31k | SetMapRes(o3tl::Length::in); |
67 | 8.31k | break; |
68 | 1.11M | case MapUnit::MapPoint: |
69 | 1.11M | SetMapRes(o3tl::Length::pt); |
70 | 1.11M | break; |
71 | 9.05M | case MapUnit::MapTwip: |
72 | 9.05M | SetMapRes(o3tl::Length::twip); |
73 | 9.05M | break; |
74 | 30.1k | case MapUnit::MapPixel: |
75 | 30.1k | mfMapScX = 1.0 / nDPIX; |
76 | 30.1k | mfMapScY = 1.0 / nDPIY; |
77 | 30.1k | break; |
78 | 0 | case MapUnit::MapSysFont: |
79 | 0 | case MapUnit::MapAppFont: |
80 | 0 | { |
81 | 0 | ImplSVData* pSVData = ImplGetSVData(); |
82 | 0 | if (!pSVData->maGDIData.mnAppFontX) |
83 | 0 | { |
84 | 0 | if (pSVData->maFrameData.mpFirstFrame) |
85 | 0 | vcl::Window::ImplInitAppFontData(pSVData->maFrameData.mpFirstFrame); |
86 | 0 | else |
87 | 0 | { |
88 | 0 | ScopedVclPtrInstance<WorkWindow> pWin(nullptr, 0); |
89 | 0 | vcl::Window::ImplInitAppFontData(pWin); |
90 | 0 | } |
91 | 0 | } |
92 | 0 | mfMapScX = double(pSVData->maGDIData.mnAppFontX) / (nDPIX * 40); |
93 | 0 | mfMapScY = double(pSVData->maGDIData.mnAppFontY) / (nDPIY * 80); |
94 | 0 | } |
95 | 0 | break; |
96 | 0 | default: |
97 | 0 | OSL_FAIL("unhandled MapUnit"); |
98 | 0 | break; |
99 | 11.3M | } |
100 | | |
101 | 11.3M | double fScaleX = rMapMode.GetScaleX(); |
102 | 11.3M | double fScaleY = rMapMode.GetScaleY(); |
103 | | |
104 | | // set offset according to MapMode |
105 | 11.3M | Point aOrigin = rMapMode.GetOrigin(); |
106 | 11.3M | if (rMapMode.GetMapUnit() != MapUnit::MapRelative) |
107 | 11.3M | { |
108 | 11.3M | mnMapOfsX = aOrigin.X(); |
109 | 11.3M | mnMapOfsY = aOrigin.Y(); |
110 | 11.3M | } |
111 | 2.51k | else |
112 | 2.51k | { |
113 | 5.03k | auto funcCalcOffset = [](double fScale, tools::Long& rnMapOffset, tools::Long nOrigin) { |
114 | 5.03k | assert(fScale != 0); |
115 | 5.03k | rnMapOffset = std::llround(double(rnMapOffset) / fScale) + nOrigin; |
116 | 5.03k | }; |
117 | | |
118 | 2.51k | funcCalcOffset(fScaleX, mnMapOfsX, aOrigin.X()); |
119 | 2.51k | funcCalcOffset(fScaleY, mnMapOfsY, aOrigin.Y()); |
120 | 2.51k | } |
121 | | |
122 | | // calculate scaling factor according to MapMode |
123 | | // aTemp? = rMapRes.mnMapSc? * aScale? |
124 | 11.3M | mfMapScX = fScaleX * mfMapScX; |
125 | 11.3M | mfMapScY = fScaleY * mfMapScY; |
126 | 11.3M | } |
127 | | |
128 | | ImplMapRes ImplMapRes::ResolveMapRes(const MapMode* pMode, const MapMode& rDefaultMapMode, |
129 | | bool bMap, tools::Long nDPIX, tools::Long nDPIY) |
130 | 24.7k | { |
131 | 24.7k | const MapMode* pEffectiveMode = pMode ? pMode : &rDefaultMapMode; |
132 | | |
133 | 24.7k | if (bMap && pEffectiveMode == &rDefaultMapMode) |
134 | 317 | return *this; |
135 | | |
136 | 24.4k | ImplMapRes aRes; |
137 | | |
138 | 24.4k | if (pEffectiveMode->GetMapUnit() == MapUnit::MapRelative) |
139 | 0 | aRes = *this; |
140 | | |
141 | 24.4k | aRes.CalcMapResolution(*pEffectiveMode, nDPIX, nDPIY); |
142 | | |
143 | 24.4k | return aRes; |
144 | 24.7k | } |
145 | | |
146 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |