2021-05-24 07:25:56 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2005 Piotr Szymanski <niedakh@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2005-07-15 18:20:57 +00:00
|
|
|
|
2007-07-29 14:53:31 +00:00
|
|
|
#ifndef _OKULAR_TEXTPAGE_H_
|
|
|
|
#define _OKULAR_TEXTPAGE_H_
|
2005-07-15 18:20:57 +00:00
|
|
|
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QList>
|
|
|
|
#include <QString>
|
2007-07-10 23:15:53 +00:00
|
|
|
|
2011-06-25 05:11:33 +00:00
|
|
|
#include "global.h"
|
2014-10-27 21:35:06 +00:00
|
|
|
#include "okularcore_export.h"
|
2006-09-21 08:45:36 +00:00
|
|
|
|
2012-09-08 15:06:02 +00:00
|
|
|
class QTransform;
|
2007-07-10 23:15:53 +00:00
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
namespace Okular
|
|
|
|
{
|
2012-03-25 21:48:07 +00:00
|
|
|
class NormalizedPoint;
|
2007-07-10 23:15:53 +00:00
|
|
|
class NormalizedRect;
|
2007-09-03 19:58:30 +00:00
|
|
|
class Page;
|
|
|
|
class PagePrivate;
|
2007-09-03 19:52:46 +00:00
|
|
|
class TextPagePrivate;
|
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
|
|
|
class TextSelection;
|
2007-07-10 23:15:53 +00:00
|
|
|
class RegularAreaRect;
|
2005-07-15 18:20:57 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/*! @class TextEntity
|
2019-07-21 08:49:24 +00:00
|
|
|
* @short Represents a piece of text on a TextPage, containing its textual representation and its bounding box.
|
2006-11-23 17:56:03 +00:00
|
|
|
*
|
2019-07-21 08:49:24 +00:00
|
|
|
* To enable searching and text selection, a generator can give information about the textual
|
|
|
|
* content of a Page using a TextPage.
|
|
|
|
* A TextPage is created using TextEntity objects.
|
|
|
|
* A TextEntity can represent a single character/glyph, a word, a line, or even the whole page.
|
2006-11-23 17:56:03 +00:00
|
|
|
*
|
2019-07-21 08:49:24 +00:00
|
|
|
* Ideally, every single glyph is represented by its own TextEntity.
|
|
|
|
* If the textual representation of a graphical glyph contains more than one character,
|
|
|
|
* the TextEntity must contain the whole string which represents the glyph.
|
|
|
|
*
|
|
|
|
* When the Generator has created the TextPage, and it is added to a Page,
|
|
|
|
* the text entities are reordered to words, lines, and paragraphs, to optimize search and text selection.
|
|
|
|
* This way, the Generator does not need to care about the logical order of lines or paragraphs.
|
|
|
|
*
|
|
|
|
* @par Text Selection/Highlighting
|
|
|
|
* A TextEntity is the smallest piece of text, which the user can select, or which can be highlighted.
|
|
|
|
* That is, if the TextEntity represents a word, only the whole word can be selected.
|
|
|
|
* It would not be possible to select a single glyph of the word, because its bounding box is not known.
|
|
|
|
*
|
|
|
|
* @see TextPage, Generator
|
2005-07-15 18:20:57 +00:00
|
|
|
*/
|
2014-10-27 21:35:06 +00:00
|
|
|
class OKULARCORE_EXPORT TextEntity
|
2005-07-15 18:20:57 +00:00
|
|
|
{
|
2006-11-23 17:56:03 +00:00
|
|
|
public:
|
|
|
|
typedef QList<TextEntity *> List;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
|
|
|
* Creates a new text entity with the given @p text and the
|
2019-12-20 15:40:59 +00:00
|
|
|
* given @p area.
|
2006-11-23 17:56:03 +00:00
|
|
|
*/
|
2019-12-20 15:40:59 +00:00
|
|
|
TextEntity(const QString &text, NormalizedRect *area);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
|
|
|
* Destroys the text entity.
|
|
|
|
*/
|
|
|
|
~TextEntity();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
|
|
|
* Returns the text of the text entity.
|
|
|
|
*/
|
|
|
|
QString text() const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
|
|
|
* Returns the bounding area of the text entity.
|
|
|
|
*/
|
|
|
|
NormalizedRect *area() const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 22:14:04 +00:00
|
|
|
/**
|
|
|
|
* Returns the transformed area of the text entity.
|
|
|
|
*/
|
2012-09-08 15:06:02 +00:00
|
|
|
NormalizedRect transformedArea(const QTransform &matrix) const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
private:
|
|
|
|
QString m_text;
|
|
|
|
NormalizedRect *m_area;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
class Private;
|
2007-04-15 19:11:10 +00:00
|
|
|
const Private *d;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
Q_DISABLE_COPY(TextEntity)
|
2005-07-15 18:20:57 +00:00
|
|
|
};
|
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
2019-07-21 08:49:24 +00:00
|
|
|
* @short Represents the textual information of a Page. Makes search and text selection possible.
|
|
|
|
*
|
|
|
|
* A Generator with text support should add a TextPage to every Page.
|
|
|
|
* For every piece of text, a TextEntity is added, holding the string representation and the bounding box.
|
|
|
|
*
|
|
|
|
* Ideally, every TextEntity describes only one glyph.
|
|
|
|
* A "glyph" is one character in the graphical representation, but the textual representation may consist of multiple characters (like diacritic modifiers).
|
|
|
|
*
|
|
|
|
* When the TextPage is added to the Page, the TextEntitys are restructured to optimize text selection.
|
|
|
|
*
|
|
|
|
* @see TextEntity
|
2006-11-23 17:56:03 +00:00
|
|
|
*/
|
2014-10-27 21:35:06 +00:00
|
|
|
class OKULARCORE_EXPORT TextPage
|
2006-09-21 08:45:36 +00:00
|
|
|
{
|
2007-09-03 19:58:30 +00:00
|
|
|
/// @cond PRIVATE
|
|
|
|
friend class Page;
|
|
|
|
friend class PagePrivate;
|
|
|
|
/// @endcond
|
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
public:
|
2009-11-12 21:48:43 +00:00
|
|
|
/**
|
|
|
|
* Defines the behaviour of adding characters to text() result
|
|
|
|
* @since 0.10 (KDE 4.4)
|
|
|
|
*/
|
|
|
|
enum TextAreaInclusionBehaviour {
|
|
|
|
AnyPixelTextAreaInclusionBehaviour, ///< A character is included into text() result if any pixel of his bounding box is in the given area
|
|
|
|
CentralPixelTextAreaInclusionBehaviour ///< A character is included into text() result if the central pixel of his bounding box is in the given area
|
|
|
|
};
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
|
|
|
* Creates a new text page.
|
|
|
|
*/
|
|
|
|
TextPage();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
|
|
|
* Creates a new text page with the given @p words.
|
|
|
|
*/
|
2020-04-04 09:17:50 +00:00
|
|
|
explicit TextPage(const TextEntity::List &words);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
|
|
|
* Destroys the text page.
|
|
|
|
*/
|
|
|
|
~TextPage();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
|
|
|
* Appends the given @p text with the given @p area as new
|
2007-01-13 22:55:00 +00:00
|
|
|
* @ref TextEntity to the page.
|
2006-11-23 17:56:03 +00:00
|
|
|
*/
|
|
|
|
void append(const QString &text, NormalizedRect *area);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
|
|
|
* Returns the bounding rect of the text which matches the following criteria
|
|
|
|
* or 0 if the search is not successful.
|
|
|
|
*
|
2019-12-20 15:40:59 +00:00
|
|
|
* @param searchID An unique id for this search.
|
|
|
|
* @param query The search text.
|
2007-01-13 22:55:00 +00:00
|
|
|
* @param direction The direction of the search (@ref SearchDirection)
|
2006-11-23 17:56:03 +00:00
|
|
|
* @param caseSensitivity If Qt::CaseSensitive, the search is case sensitive; otherwise
|
|
|
|
* the search is case insensitive.
|
2019-12-20 15:40:59 +00:00
|
|
|
* @param area If null the search starts at the beginning of the page, otherwise
|
2008-09-25 15:05:22 +00:00
|
|
|
* right/below the coordinates of the given rect.
|
2006-11-23 17:56:03 +00:00
|
|
|
*/
|
2019-12-20 15:40:59 +00:00
|
|
|
RegularAreaRect *findText(int searchID, const QString &query, SearchDirection direction, Qt::CaseSensitivity caseSensitivity, const RegularAreaRect *area);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
2019-07-21 08:49:24 +00:00
|
|
|
* Text extraction function. Looks for text in the given @p area.
|
2007-01-13 22:55:00 +00:00
|
|
|
*
|
2019-07-21 08:49:24 +00:00
|
|
|
* @return
|
|
|
|
* - If @p area points to a valid null area, a null string.
|
|
|
|
* - If @p area is nullptr, the whole page text as a single string.
|
|
|
|
* - Otherwise, the text which is included by @p area, as a single string.
|
2009-11-12 21:48:43 +00:00
|
|
|
* Uses AnyPixelTextAreaInclusionBehaviour
|
2006-11-23 17:56:03 +00:00
|
|
|
*/
|
2019-07-21 08:49:24 +00:00
|
|
|
QString text(const RegularAreaRect *area = nullptr) const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2009-11-12 21:48:43 +00:00
|
|
|
/**
|
2019-07-21 08:49:24 +00:00
|
|
|
* Text extraction function. Looks for text in the given @p area.
|
2009-11-12 21:48:43 +00:00
|
|
|
*
|
2019-07-21 08:49:24 +00:00
|
|
|
* @return
|
|
|
|
* - If @p area points to a valid null area, a null string.
|
|
|
|
* - If @p area is nullptr, the whole page text as a single string.
|
|
|
|
* - Otherwise, the text which is included by @p area, as a single string.
|
2009-11-12 21:48:43 +00:00
|
|
|
* @since 0.10 (KDE 4.4)
|
|
|
|
*/
|
2019-07-21 08:49:24 +00:00
|
|
|
QString text(const RegularAreaRect *area, TextAreaInclusionBehaviour b) const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2011-10-31 15:33:03 +00:00
|
|
|
/**
|
|
|
|
* Text entity extraction function. Similar to text() but returns
|
|
|
|
* the words including their bounding rectangles. Note that
|
|
|
|
* ownership of the contents of the returned list belongs to the
|
|
|
|
* caller.
|
|
|
|
* @since 0.14 (KDE 4.8)
|
|
|
|
*/
|
2019-12-20 15:40:59 +00:00
|
|
|
TextEntity::List words(const RegularAreaRect *area, TextAreaInclusionBehaviour b) const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-03-25 21:48:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the area and text of the word at the given point
|
|
|
|
* Note that ownership of the returned area belongs to the caller.
|
|
|
|
* @since 0.15 (KDE 4.9)
|
|
|
|
*/
|
2017-09-05 21:27:18 +00:00
|
|
|
RegularAreaRect *wordAt(const NormalizedPoint &p, QString *word = nullptr) const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
/**
|
|
|
|
* Returns the rectangular area of the given @p selection.
|
|
|
|
*/
|
|
|
|
RegularAreaRect *textArea(TextSelection *selection) const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
private:
|
2007-09-03 19:52:46 +00:00
|
|
|
TextPagePrivate *const d;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-23 17:56:03 +00:00
|
|
|
Q_DISABLE_COPY(TextPage)
|
2006-09-21 08:45:36 +00:00
|
|
|
};
|
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
}
|
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
|
|
|
|
2011-08-17 04:45:46 +00:00
|
|
|
#endif
|