add a text() function that returns characters not containing any pixel inside the given area but the center pixel of the char rectangle

svn path=/trunk/KDE/kdegraphics/okular/; revision=1048193
remotes/origin/KDE/4.4
Albert Astals Cid 17 years ago
parent 81d255bafb
commit 8f045d06a7
  1. 9
      core/page.cpp
  2. 9
      core/page.h
  3. 20
      core/textpage.cpp
  4. 22
      core/textpage.h

@ -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;
}

@ -15,6 +15,7 @@
#include <okular/core/okular_export.h>
#include <okular/core/area.h>
#include <okular/core/global.h>
#include <okular/core/textpage.h>
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.
*/

@ -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();
}
}
}
}

@ -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.
*/

Loading…
Cancel
Save