lib

KoTextZoomHandler.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001-2005 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KoTextZoomHandler.h"
21#include <kdebug.h>
22#include <tqpaintdevice.h>
23#include <KoUnit.h>
24#include <KoGlobal.h>
25
26// Layout text at 1440 DPI
27// Well, not really always 1440 DPI, but always 20 times the point size
28// This is constant, no need to litterally apply 1440 DPI at all resolutions.
30
31#if 0
32int KoTextZoomHandler::fontSizeToLayoutUnit( double ptSizeFloat, bool forPrint ) const
33{
34 return ptToLayoutUnit( ptSizeFloat / ( m_zoomedResolutionY *
35 ( forPrint ? 1.0 : (72.0 / KoGlobal::dpiY()) ) ) );
36}
37#endif
38
39double KoTextZoomHandler::layoutUnitToFontSize( int luSize, bool /*forPrint*/ ) const
40{
41 // TQt will use TQPaintDevice::x11AppDpiY() to go from pt to pixel for fonts
42 return layoutUnitPtToPt( luSize ) * m_zoomedResolutionY
43#ifdef TQ_WS_X11
44 / POINT_TO_INCH(TQPaintDevice::x11AppDpiY())
45#endif
46 ;
47}
48
50{
51 // We call layoutUnitToPixelX on the right value, i.e. x+w-1,
52 // and then determine the height from the result (i.e. right-left+1).
53 // Calling layoutUnitToPixelX(w) leads to rounding problems.
54 return layoutUnitToPixelY( x + w - 1 ) - layoutUnitToPixelY( x ) + 1;
55}
56
57int KoTextZoomHandler::layoutUnitToPixelY( int y, int h ) const
58{
59 // We call layoutUnitToPixelY on the bottom value, i.e. y+h-1,
60 // and then determine the height from the result (i.e. bottom-top+1).
61 // Calling layoutUnitToPixelY(h) leads to rounding problems.
62 return layoutUnitToPixelY( y + h - 1 ) - layoutUnitToPixelY( y ) + 1;
63}
64
66{
67 return int( static_cast<double>( lupix * m_zoomedResolutionX )
68 / ( static_cast<double>( m_layoutUnitFactor ) * m_resolutionX ) );
69}
70
71int KoTextZoomHandler::layoutUnitToPixelY( int lupix ) const
72{
73 // tqRound replaced with a truncation, too many problems (e.g. bottom of parags)
74 return int( static_cast<double>( lupix * m_zoomedResolutionY )
75 / ( static_cast<double>( m_layoutUnitFactor ) * m_resolutionY ) );
76}
77
79{
80 return tqRound( static_cast<double>( x * m_layoutUnitFactor * m_resolutionX )
81 / m_zoomedResolutionX );
82}
83
84int KoTextZoomHandler::pixelToLayoutUnitY( int y ) const
85{
86 return tqRound( static_cast<double>( y * m_layoutUnitFactor * m_resolutionY )
87 / m_zoomedResolutionY );
88}
89
double layoutUnitToFontSize(int luSize, bool) const
Given the font size for the font in layout units, in pt (use pointSize()) this returns the font size ...
int layoutUnitToPixelX(int lupix) const
The "layout unit pixel" -> "[zoomed] view pixel" conversions.
static int m_layoutUnitFactor
This being static ensures that the same value is used by all KoTextZoomHandler instances.
int pixelToLayoutUnitX(int x) const
The "[zoomed] view pixel" -> "layout unit pixel" conversions.