LibreOffice Module basegfx (master) 1
zoomtools.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
11
13{
14
20const double ZOOM_FACTOR = 1.12246205;
21
29static sal_uInt16 roundMultiple(sal_uInt16 nCurrent, int nMultiple)
30{
31 // round zoom to a multiple of nMultiple
32 return (( nCurrent + nMultiple / 2 ) - ( nCurrent + nMultiple / 2 ) % nMultiple);
33}
34
42static sal_uInt16 roundZoom(double nCurrent)
43{
44 // convert nCurrent properly to int
45 sal_uInt16 nNew = nCurrent + 0.5;
46
47 // round to more common numbers above 50
48 if (nNew > 1000) {
49 nNew = roundMultiple(nNew, 100);
50 } else if ( nNew > 500 ) {
51 nNew = roundMultiple(nNew, 50);
52 } else if ( nNew > 100 ) {
53 nNew = roundMultiple(nNew, 10);
54 } else if ( nNew > 50 ) {
55 nNew = roundMultiple(nNew, 5);
56 }
57
58 return nNew;
59}
60
69static sal_uInt16 enforceStep(sal_uInt16 nCurrent, sal_uInt16 nPrevious, unsigned int nStep)
70{
71 if ((( nCurrent > nStep ) && ( nPrevious < nStep ))
72 || (( nCurrent < nStep ) && ( nPrevious > nStep )))
73 return nStep;
74 else
75 return nCurrent;
76}
77
83sal_uInt16 zoomIn(sal_uInt16 nCurrent)
84{
85 sal_uInt16 nNew = roundZoom( nCurrent * ZOOM_FACTOR );
86 // make sure some values are not skipped
87 nNew = enforceStep(nNew, nCurrent, 200);
88 nNew = enforceStep(nNew, nCurrent, 100);
89 nNew = enforceStep(nNew, nCurrent, 75);
90 nNew = enforceStep(nNew, nCurrent, 50);
91 nNew = enforceStep(nNew, nCurrent, 25);
92 return nNew;
93}
94
100sal_uInt16 zoomOut(sal_uInt16 nCurrent)
101{
102 sal_uInt16 nNew = roundZoom( nCurrent / ZOOM_FACTOR );
103 // make sure some values are not skipped
104 nNew = enforceStep(nNew, nCurrent, 200);
105 nNew = enforceStep(nNew, nCurrent, 100);
106 nNew = enforceStep(nNew, nCurrent, 75);
107 nNew = enforceStep(nNew, nCurrent, 50);
108 nNew = enforceStep(nNew, nCurrent, 25);
109 return nNew;
110}
111} // namespace
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 zoomIn(sal_uInt16 nCurrent)
Increasing the zoom level.
Definition: zoomtools.cxx:83
static sal_uInt16 enforceStep(sal_uInt16 nCurrent, sal_uInt16 nPrevious, unsigned int nStep)
Make sure that a certain step isn't skipped during the zooming progress.
Definition: zoomtools.cxx:69
const double ZOOM_FACTOR
2^(1/6) as the default step
Definition: zoomtools.cxx:20
static sal_uInt16 roundZoom(double nCurrent)
Convert geometric progression results into more common values by rounding them against certain multip...
Definition: zoomtools.cxx:42
sal_uInt16 zoomOut(sal_uInt16 nCurrent)
Decreasing the zoom level.
Definition: zoomtools.cxx:100
static sal_uInt16 roundMultiple(sal_uInt16 nCurrent, int nMultiple)
Round a value against a specified multiple.
Definition: zoomtools.cxx:29