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