compile
[kdegraphics.git] / okular / core / textpage.h
blob61c59b7f17d5215c2f1a2626cf377353c6a0698e
1 /***************************************************************************
2 * Copyright (C) 2005 by Piotr Szymanski <niedakh@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #ifndef _OKULAR_TEXTPAGE_H_
11 #define _OKULAR_TEXTPAGE_H_
13 #include <QtCore/QList>
14 #include <QtCore/QString>
16 #include <okular/core/okular_export.h>
17 #include <okular/core/global.h>
19 class QMatrix;
21 namespace Okular {
23 class NormalizedRect;
24 class Page;
25 class PagePrivate;
26 class TextPagePrivate;
27 class TextSelection;
28 class RegularAreaRect;
30 /*! @class TextEntity
31 * @short Abstract textentity of Okular
32 * @par The context
33 * A document can provide different forms of information about textual representation
34 * of its contents. It can include information about positions of every character on the
35 * page, this is the best possibility.
37 * But also it can provide information only about positions of every word on the page (not the character).
38 * Furthermore it can provide information only about the position of the whole page's text on the page.
40 * Also some document types have glyphes - sets of characters rendered as one, so in search they should
41 * appear as a text but are only one character when drawn on screen. We need to allow this.
43 class OKULAR_EXPORT TextEntity
45 public:
46 typedef QList<TextEntity*> List;
48 /**
49 * Creates a new text entity with the given @p text and the
50 * given @p area.
52 TextEntity( const QString &text, NormalizedRect *area );
54 /**
55 * Destroys the text entity.
57 ~TextEntity();
59 /**
60 * Returns the text of the text entity.
62 QString text() const;
64 /**
65 * Returns the bounding area of the text entity.
67 NormalizedRect* area() const;
69 /**
70 * Returns the transformed area of the text entity.
72 NormalizedRect transformedArea(const QMatrix &matrix) const;
74 private:
75 QString m_text;
76 NormalizedRect* m_area;
78 class Private;
79 const Private *d;
81 Q_DISABLE_COPY( TextEntity )
84 /**
85 * The TextPage class represents the text of a page by
86 * providing @see TextEntity items for every word/character of
87 * the page.
89 class OKULAR_EXPORT TextPage
91 /// @cond PRIVATE
92 friend class Page;
93 friend class PagePrivate;
94 /// @endcond
96 public:
97 /**
98 * Creates a new text page.
100 TextPage();
103 * Creates a new text page with the given @p words.
105 TextPage( const TextEntity::List &words );
108 * Destroys the text page.
110 ~TextPage();
113 * Appends the given @p text with the given @p area as new
114 * @ref TextEntity to the page.
116 void append( const QString &text, NormalizedRect *area );
119 * Returns the bounding rect of the text which matches the following criteria
120 * or 0 if the search is not successful.
122 * @param id An unique id for this search.
123 * @param text The search text.
124 * @param direction The direction of the search (@ref SearchDirection)
125 * @param caseSensitivity If Qt::CaseSensitive, the search is case sensitive; otherwise
126 * the search is case insensitive.
127 * @param lastRect If 0 the search starts at the beginning of the page, otherwise
128 * right/below the coordinates of the the given rect.
130 RegularAreaRect* findText( int id, const QString &text, SearchDirection direction,
131 Qt::CaseSensitivity caseSensitivity, const RegularAreaRect *lastRect );
134 * Text extraction function.
136 * Returns:
137 * - a null string if @p rect is a valid pointer to a null area
138 * - the whole page text if @p rect is a null pointer
139 * - the text which is included by rectangular area @p rect otherwise
141 QString text( const RegularAreaRect *rect = 0 ) const;
144 * Returns the rectangular area of the given @p selection.
146 RegularAreaRect *textArea( TextSelection *selection ) const;
148 private:
149 TextPagePrivate* const d;
151 Q_DISABLE_COPY( TextPage )
156 #endif