summaryrefslogtreecommitdiffstats
path: root/kpdf/core/page.h
blob: 1ec5add07dd2a56cc9efb042b0672b3c8c401489 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/***************************************************************************
 *   Copyright (C) 2004 by Enrico Ros <eros.kde@email.it>                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef _KPDF_PAGE_H_
#define _KPDF_PAGE_H_

#include <tqmap.h>
#include <tqvaluelist.h>

class TQPixmap;
class TQRect;
class TextPage;
class KPDFPageTransition;
class HighlightRect;
class Annotation;

/**
 * @short A rect in normalized [0,1] coordinates.
 */
class NormalizedRect
{
    public:
        double left, top, right, bottom;

        NormalizedRect();
        NormalizedRect( double l, double t, double r, double b );
        NormalizedRect( const TQRect & r, double xScale, double yScale );

        bool contains( double x, double y ) const;
        bool intersects( const NormalizedRect & normRect ) const;
        bool intersects( double l, double t, double r, double b ) const;

        TQRect tqgeometry( int xScale, int yScale ) const;
};

/**
 * @short NormalizedRect that contains a reference to an object.
 *
 * These rects contains a pointer to a kpdf object (such as a link or something
 * like that). The pointer is read and stored as 'void pointer' so cast is
 * performed by accessors based on the value returned by objectType(). Objects
 * are reparented to this class.
 *
 * Type / Class correspondency tab:
 *  - Link      : class KPDFLink  : description of a link
 *  - Image     : class KPDFImage : description of an image (n/a)
 */
class ObjectRect : public NormalizedRect
{
    public:
        // definition of the types of storable objects
        enum ObjectType { Link, Image };

        // default constructor: initialize all parameters
        ObjectRect( double l, double t, double r, double b, ObjectType typ, void * obj );
        ~ObjectRect();

        // query type and get a const pointer to the stored object
        inline ObjectType objectType() const { return m_objectType; }
        inline const void * pointer() const { return m_pointer; }

    private:
        ObjectType m_objectType;
        void * m_pointer;
};

/**
 * @short Collector for all the data belonging to a page.
 *
 * The KPDFPage class contains pixmaps (referenced using observers id as key),
 * a search page (a class used internally for retrieving text), rect classes
 * (that describe links or other active areas in the current page) and more.
 *
 * All coordinates are normalized to the page, so {x,y} are valid in [0,1]
 * range as long as NormalizedRect components.
 *
 * Note: The class takes ownership of all objects.
 */
class KPDFPage
{
    public:
        KPDFPage( uint number, float width, float height, int rotation );
        ~KPDFPage();

        // query properties (const read-only methods)
        inline int number() const { return m_number; }
        inline int rotation() const { return m_rotation; }
        inline float width() const { return m_width; }
        inline float height() const { return m_height; }
        inline float ratio() const { return m_height / m_width; }
        bool hasPixmap( int p_id, int width = -1, int height = -1 ) const;
        bool hasSearchPage() const;
        bool hasBookmark() const;
        bool hasObjectRect( double x, double y ) const;
        bool hasHighlights( int s_id = -1 ) const;
        //bool hasAnnotation( double x, double y ) const;
        bool hasTransition() const;

        NormalizedRect * findText( const TQString & text, bool keepCase, NormalizedRect * last = 0 ) const;
        const TQString getText( const NormalizedRect & rect ) const;
        const ObjectRect * hasObject( ObjectRect::ObjectType type, double x, double y ) const;
        //const Annotation * getAnnotation( double x, double y ) const;
        const KPDFPageTransition * getTransition() const;

        // operations: set/delete contents (by KPDFDocument)
        void setPixmap( int p_id, TQPixmap * pixmap );
        void setSearchPage( TextPage * text );
        void setBookmark( bool state );
        void setObjectRects( const TQValueList< ObjectRect * > rects );
        void setHighlight( int s_id, NormalizedRect * &r, const TQColor & color );
        //void setAnnotation( Annotation * annotation );
        void setTransition( KPDFPageTransition * transition );
        void deletePixmap( int p_id );
        void deletePixmapsAndRects();
        void deleteHighlights( int s_id = -1 );

        void setRotation( int r );
        void rotate90degrees();

    private:
        friend class PagePainter;
        int m_number, m_rotation;
        float m_width, m_height;
        bool m_bookmarked;

        TQMap< int, TQPixmap * > m_pixmaps;
        TextPage * m_text;
        TQValueList< ObjectRect * > m_rects;
        TQValueList< HighlightRect * > m_highlights;
        //TQValueList< Annotation * > m_annotations;
        KPDFPageTransition * m_transition;
};


/**
 * Internal Storage: normalized colored highlight owned by id
 */
struct HighlightRect : public NormalizedRect
{
    // searchID of the highlight owner
    int s_id;
    // color of the highlight
    TQColor color;
};

#endif