File indexing completed on 2024-05-12 16:06:39

0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
0002 // SimplePageSize.cpp
0003 //
0004 // Part of KVIEWSHELL - A framework for multipage text/gfx viewers
0005 //
0006 // SPDX-FileCopyrightText: 2002-2005 Stefan Kebekus
0007 // SPDX-License-Identifier: GPL-2.0-or-later
0008 
0009 #include <config.h>
0010 
0011 #include "debug_dvi.h"
0012 #include "simplePageSize.h"
0013 
0014 #include <QLoggingCategory>
0015 #include <QPaintDevice>
0016 
0017 double SimplePageSize::zoomForHeight(quint32 height, const QPaintDevice &pd) const
0018 {
0019     if (!isValid()) {
0020         qCCritical(OkularDviShellDebug) << "SimplePageSize::zoomForHeight() called when paper height was invalid";
0021         return 0.1;
0022     }
0023 
0024     return double(height) / (pd.logicalDpiY() * pageHeight.getLength_in_inch());
0025 }
0026 
0027 double SimplePageSize::zoomForWidth(quint32 width, const QPaintDevice &pd) const
0028 {
0029     if (!isValid()) {
0030         qCCritical(OkularDviShellDebug) << "SimplePageSize::zoomForWidth() called when paper width was invalid";
0031         return 0.1;
0032     }
0033 
0034     return double(width) / (pd.logicalDpiX() * pageWidth.getLength_in_inch());
0035 }
0036 
0037 double SimplePageSize::zoomToFitInto(const SimplePageSize &target) const
0038 {
0039     if (!isValid() || isSmall() || !target.isValid()) {
0040         qCWarning(OkularDviShellDebug) << "SimplePageSize::zoomToFitInto(...) with unsuitable source of target";
0041         return 1.0;
0042     }
0043 
0044     double z1 = target.width() / pageWidth;
0045     double z2 = target.height() / pageHeight;
0046 
0047     return qMin(z1, z2);
0048 }