lib

KoTextZoomHandler.h
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#ifndef kotextzoomhandler_h
21#define kotextzoomhandler_h
22
23#include <KoZoomHandler.h>
24
28class KOTEXT_EXPORT KoTextZoomHandler : public KoZoomHandler
29{
30public:
32 virtual ~KoTextZoomHandler() {}
33
35
37 int pixelToLayoutUnitX( int x ) const;
38 int pixelToLayoutUnitY( int y ) const;
39 TQPoint pixelToLayoutUnit( const TQPoint &p ) const
40 { return TQPoint( pixelToLayoutUnitX( p.x() ),
41 pixelToLayoutUnitY( p.y() ) ); }
42 TQRect pixelToLayoutUnit( const TQRect &r ) const
43 { return TQRect( pixelToLayoutUnit( r.topLeft() ),
44 pixelToLayoutUnit( r.bottomRight() ) ); }
45
47 int layoutUnitToPixelX( int lupix ) const;
48 int layoutUnitToPixelY( int lupix ) const;
49
52 int layoutUnitToPixelX( int x, int w ) const;
55 int layoutUnitToPixelY( int y, int h ) const;
56
57 TQPoint layoutUnitToPixel( const TQPoint &p ) const
58 { return TQPoint( layoutUnitToPixelX( p.x() ),
59 layoutUnitToPixelY( p.y() ) ); }
60 TQRect layoutUnitToPixel( const TQRect &r ) const
61 { return TQRect( layoutUnitToPixel( r.topLeft() ),
62 layoutUnitToPixel( r.bottomRight() ) ); }
63
67 int ptToPixelX( double pt ) const
68 { return tqRound( pt * m_resolutionX ); }
69 int ptToPixelY( double pt ) const
70 { return tqRound( pt * m_resolutionY ); }
71 TQPoint ptToPixel( const KoPoint & p ) const {
72 return TQPoint( ptToPixelX( p.x() ), ptToPixelY( p.y() ) );
73 }
74 double pixelXToPt( int x ) const
75 { return static_cast<double>(x) / m_resolutionX; }
76 double pixelYToPt( int y ) const
77 { return static_cast<double>(y) / m_resolutionY; }
78 KoPoint pixelToPt( const TQPoint& p ) const {
79 return KoPoint( pixelXToPt( p.x() ), pixelYToPt( p.y() ) );
80 }
81
83 int ptToLayoutUnitPixX( double x_pt ) const
84 { return ptToPixelX( ptToLayoutUnitPt( x_pt ) ); }
85 int ptToLayoutUnitPixY( double y_pt ) const
86 { return ptToPixelY( ptToLayoutUnitPt( y_pt ) ); }
87 TQPoint ptToLayoutUnitPix( const KoPoint & p ) const {
88 return TQPoint( ptToLayoutUnitPixX( p.x() ), ptToLayoutUnitPixY( p.y() ) );
89 }
90
95 double layoutUnitToFontSize( int luSize, bool /*forPrint*/ ) const;
96
97 // Note: For converting fontsizes from/to layout units and zoom-independent
98 // pt sizes (like the one the user sees, e.g. 12pt),
99 // use ptToLayoutUnit and layoutUnitToPt, not layoutToFontSize.
100
101
102 // The conversions below convert between an internal text layout resolution of
103 // ~1440 DPI (by default) and the point-size for the fonts (those known by the user).
104 // Those conversions don't depend on the zoom level.
105
108 static void setPtToLayoutUnitFactor( int factor ) { m_layoutUnitFactor = factor; }
109
112 static double ptToLayoutUnitPt( double pt )
113 { return pt * static_cast<double>( m_layoutUnitFactor ); }
115 static int ptToLayoutUnitPt( int ptSize )
116 { return ptSize * m_layoutUnitFactor; }
117
118 static KoPoint ptToLayoutUnitPt( const KoPoint &p )
119 { return KoPoint( ptToLayoutUnitPt( p.x() ),
120 ptToLayoutUnitPt( p.y() ) ); }
121 static KoRect ptToLayoutUnitPt( const KoRect &r )
122 { return KoRect( ptToLayoutUnitPt( r.topLeft() ),
123 ptToLayoutUnitPt( r.bottomRight() ) ); }
124
125 static double layoutUnitPtToPt( double lupt )
126 { return lupt / static_cast<double>( m_layoutUnitFactor ); }
127 static KoPoint layoutUnitPtToPt( const KoPoint& p )
128 { return KoPoint( layoutUnitPtToPt( p.x() ),
129 layoutUnitPtToPt( p.y() ) ); }
130
131protected:
134};
135
136#endif
A point whose coordinates are floating-point values ( "double"s ).
Definition KoPoint.h:30
A rect whose coordinates are floating-point values ( "double"s ).
Definition KoRect.h:31
This class extends KoZoomHandler to add support for WYSIWYG text layouting.
int ptToPixelX(double pt) const
Basic pt to pixel and pixel to pt conversions, valid at any zoom level, as well as at the Layout Unit...
static double ptToLayoutUnitPt(double pt)
Not zoom dependent.
int ptToLayoutUnitPixX(double x_pt) const
The "document pt" -> "Layout Unit pixels" conversions, for convenience.
static int ptToLayoutUnitPt(int ptSize)
Same thing for integer values, e.g.
static void setPtToLayoutUnitFactor(int factor)
Change the factor that converts between pointsizes and layout units (by default 20 - for 1440 DPI at ...
static int m_layoutUnitFactor
This being static ensures that the same value is used by all KoTextZoomHandler instances.
This class handles the zooming and DPI stuff (conversions between pt values and pixels).