lib Library API Documentation

kozoomhandler.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include "kozoomhandler.h"
00021 #include <kdebug.h>
00022 #include <qpaintdevice.h>
00023 #include <koGlobal.h>
00024 
00025 // Layout text at 1440 DPI
00026 // Well, not really always 1440 DPI, but always 20 times the point size
00027 // This is constant, no need to litterally apply 1440 DPI at all resolutions.
00028 int KoTextZoomHandler::m_layoutUnitFactor = 20;
00029 
00030 KoZoomHandler::KoZoomHandler()
00031 {
00032     // Note that this calls the method below, not the derived one
00033     setZoomAndResolution( 100, QPaintDevice::x11AppDpiX(), QPaintDevice::x11AppDpiY() );
00034 }
00035 
00036 void KoZoomHandler::setZoomAndResolution( int zoom, int dpiX, int dpiY )
00037 {
00038     m_zoom = zoom;
00039     // m_resolution[XY] is in pixel per pt
00040     m_resolutionX = POINT_TO_INCH( static_cast<double>(dpiX) );
00041     m_resolutionY = POINT_TO_INCH( static_cast<double>(dpiY) );
00042     m_zoomedResolutionX = static_cast<double>(m_zoom) * m_resolutionX / 100.0;
00043     m_zoomedResolutionY = static_cast<double>(m_zoom) * m_resolutionY / 100.0;
00044     /*kdDebug(32500) << "KoZoomHandler::setZoomAndResolution " << zoom << " " << dpiX << "," << dpiY
00045               << " m_resolutionX=" << m_resolutionX
00046               << " m_zoomedResolutionX=" << m_zoomedResolutionX
00047               << " m_resolutionY=" << m_resolutionY
00048               << " m_zoomedResolutionY=" << m_zoomedResolutionY << endl;*/
00049 }
00050 
00051 void KoZoomHandler::setResolution( double resolutionX, double resolutionY )
00052 {
00053     m_zoomedResolutionX = resolutionX;
00054     m_zoomedResolutionY = resolutionY;
00055 }
00056 
00057 #if 0
00058 int KoZoomHandler::fontSizeToLayoutUnit( double ptSizeFloat, bool forPrint ) const
00059 {
00060     return ptToLayoutUnit( ptSizeFloat / ( m_zoomedResolutionY *
00061         ( forPrint ? 1.0 : (72.0 / QPaintDevice::x11AppDpiY()) ) ) );
00062 }
00063 #endif
00064 
00065 double KoZoomHandler::layoutUnitToFontSize( int luSize, bool /*forPrint*/ ) const
00066 {
00067     // Pt to pt conversion, we don't need to care about pixel sizes and x11AppDpiY ...
00068     return layoutUnitPtToPt( luSize ) * static_cast<double>(m_zoom) / 100.0;
00069     // ### Same calculation as layoutUnitToPixel !
00070 }
00071 
00072 int KoZoomHandler::layoutUnitToPixelX( int x, int w ) const
00073 {
00074     // We call layoutUnitToPixelX on the right value, i.e. x+w-1,
00075     // and then determine the height from the result (i.e. right-left+1).
00076     // Calling layoutUnitToPixelX(w) leads to rounding problems.
00077     return layoutUnitToPixelY( x + w - 1 ) - layoutUnitToPixelY( x ) + 1;
00078 }
00079 
00080 int KoZoomHandler::layoutUnitToPixelY( int y, int h ) const
00081 {
00082     // We call layoutUnitToPixelY on the bottom value, i.e. y+h-1,
00083     // and then determine the height from the result (i.e. bottom-top+1).
00084     // Calling layoutUnitToPixelY(h) leads to rounding problems.
00085     return layoutUnitToPixelY( y + h - 1 ) - layoutUnitToPixelY( y ) + 1;
00086 }
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Nov 17 13:19:27 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2003