diff --git a/core/page.cpp b/core/page.cpp index 0b16c3b9a..bd279391e 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -276,6 +276,11 @@ RegularAreaRect * Page::findText( int id, const QString & text, SearchDirection } QString Page::text( const RegularAreaRect * area ) const +{ + return text( area, TextPage::AnyPixelTextAreaInclusionBehaviour ); +} + +QString Page::text( const RegularAreaRect * area, TextPage::TextAreaInclusionBehaviour b ) const { QString ret; @@ -287,10 +292,10 @@ QString Page::text( const RegularAreaRect * area ) const RegularAreaRect rotatedArea = *area; rotatedArea.transform( d->rotationMatrix().inverted() ); - ret = d->m_text->text( &rotatedArea ); + ret = d->m_text->text( &rotatedArea, b ); } else - ret = d->m_text->text(); + ret = d->m_text->text( 0, b ); return ret; } diff --git a/core/page.h b/core/page.h index 32e571dab..e42fb0515 100644 --- a/core/page.h +++ b/core/page.h @@ -15,6 +15,7 @@ #include #include #include +#include class QPixmap; @@ -29,7 +30,6 @@ class FormField; class PagePrivate; class PageTransition; class SourceReference; -class TextPage; class TextSelection; /** @@ -189,6 +189,13 @@ class OKULAR_EXPORT Page */ QString text( const RegularAreaRect * rect = 0 ) const; + /** + * Returns the page text (or part of it). + * @see TextPage::text() + * @since 0.10 (KDE 4.4) + */ + QString text( const RegularAreaRect * rect, TextPage::TextAreaInclusionBehaviour b ) const; + /** * Returns the rectangular area of the given @p selection. */ diff --git a/core/textpage.cpp b/core/textpage.cpp index af698a403..89b674c9b 100644 --- a/core/textpage.cpp +++ b/core/textpage.cpp @@ -606,6 +606,11 @@ RegularAreaRect* TextPagePrivate::findTextInternalBackward( int searchID, const } QString TextPage::text(const RegularAreaRect *area) const +{ + return text(area, AnyPixelTextAreaInclusionBehaviour); +} + +QString TextPage::text(const RegularAreaRect *area, TextAreaInclusionBehaviour b) const { if ( area && area->isNull() ) return QString(); @@ -616,9 +621,20 @@ QString TextPage::text(const RegularAreaRect *area) const { for ( ; it != itEnd; ++it ) { - if ( area->intersects( (*it)->area ) ) + if (b == AnyPixelTextAreaInclusionBehaviour) + { + if ( area->intersects( (*it)->area ) ) + { + ret += (*it)->text(); + } + } + else { - ret += (*it)->text(); + NormalizedPoint center = (*it)->area.center(); + if ( area->contains( center.x, center.y ) ) + { + ret += (*it)->text(); + } } } } diff --git a/core/textpage.h b/core/textpage.h index f5494a434..223ef5191 100644 --- a/core/textpage.h +++ b/core/textpage.h @@ -94,6 +94,16 @@ class OKULAR_EXPORT TextPage /// @endcond public: + /** + * 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 + }; + /** * Creates a new text page. */ @@ -137,9 +147,21 @@ class OKULAR_EXPORT TextPage * - a null string if @p rect is a valid pointer to a null area * - the whole page text if @p rect is a null pointer * - the text which is included by rectangular area @p rect otherwise + * Uses AnyPixelTextAreaInclusionBehaviour */ QString text( const RegularAreaRect *rect = 0 ) const; + /** + * Text extraction function. + * + * Returns: + * - a null string if @p rect is a valid pointer to a null area + * - the whole page text if @p rect is a null pointer + * - the text which is included by rectangular area @p rect otherwise + * @since 0.10 (KDE 4.4) + */ + QString text( const RegularAreaRect * rect, TextAreaInclusionBehaviour b ) const; + /** * Returns the rectangular area of the given @p selection. */