mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-25 10:55:37 +00:00
Fix stuff for a better merge
This commit is contained in:
parent
92e3c16066
commit
7825e4c545
|
@ -23,17 +23,8 @@
|
|||
#include <QtAlgorithms>
|
||||
#include <QVarLengthArray>
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
using namespace Okular;
|
||||
|
||||
// Common Function Declaration
|
||||
static bool compareTinyTextEntityX(TinyTextEntity* first, TinyTextEntity* second);
|
||||
static bool compareTinyTextEntityY(TinyTextEntity* first, TinyTextEntity* second);
|
||||
static bool doesConsumeX(const QRect& first, const QRect& second, int threshold);
|
||||
static bool doesConsumeY(const QRect& first, const QRect& second, int threshold);
|
||||
|
||||
class SearchPoint
|
||||
{
|
||||
public:
|
||||
|
@ -71,6 +62,63 @@ bool CaseSensitiveCmpFn( const QStringRef & from, const QStringRef & to,
|
|||
return from.compare( to, Qt::CaseSensitive ) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the horizontal arm of one rectangle fully contains the other (example below)
|
||||
* -------- ---- ----- first
|
||||
* ---- -------- ----- second
|
||||
* or we can make it overlap of spaces by threshold%
|
||||
*/
|
||||
static bool doesConsumeX(const QRect& first, const QRect& second, int threshold)
|
||||
{
|
||||
// if one consumes another fully
|
||||
if(first.left() <= second.left() && first.right() >= second.right())
|
||||
return true;
|
||||
|
||||
if(first.left() >= second.left() && first.right() <= second.right())
|
||||
return true;
|
||||
|
||||
// or if there is overlap of space by more than threshold%
|
||||
// there is overlap
|
||||
if(second.right() >= first.left() && first.right() >= second.left())
|
||||
{
|
||||
const int overlap = (second.right() >= first.right()) ? first.right() - second.left()
|
||||
: second.right() - first.left();
|
||||
// we will divide by the smaller rectangle to calculate the overlap
|
||||
const int percentage = (first.width() < second.width()) ? overlap * 100 / (first.right() - first.left())
|
||||
: overlap * 100 / (second.right() - second.left());
|
||||
if(percentage >= threshold) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same concept of doesConsumeX but in this case we calculate on y axis
|
||||
*/
|
||||
static bool doesConsumeY(const QRect& first, const QRect& second, int threshold)
|
||||
{
|
||||
// if one consumes another fully
|
||||
if(first.top() <= second.top() && first.bottom() >= second.bottom())
|
||||
return true;
|
||||
|
||||
if(first.top() >= second.top() && first.bottom() <= second.bottom())
|
||||
return true;
|
||||
|
||||
// or if there is overlap of space by more than 80%
|
||||
// there is overlap
|
||||
if(second.bottom() >= first.top() && first.bottom() >= second.top())
|
||||
{
|
||||
const int overlap = (second.bottom() >= first.bottom()) ? first.bottom() - second.top()
|
||||
: second.bottom() - first.top();
|
||||
//we will divide by the smaller rectangle to calculate the overlap
|
||||
const int percentage = (first.width() < second.width()) ? overlap * 100 / (first.bottom() - first.top())
|
||||
: overlap * 100 / (second.bottom() - second.top());
|
||||
|
||||
if(percentage >= threshold) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Rationale behind TinyTextEntity:
|
||||
|
@ -768,59 +816,45 @@ RegularAreaRect* TextPagePrivate::findTextInternalForward( int searchID, const Q
|
|||
// we have equal (or less than) area of the query left as the length of the current
|
||||
// entity
|
||||
|
||||
|
||||
// hyphenated '-' must be at the end of a word, so hyphenation means
|
||||
// we have a '-' just followed by a '\n' character
|
||||
// check if the string contains a '-' character
|
||||
if(str.contains('-')){
|
||||
// if the '-' is the last entry
|
||||
if ( str.endsWith( '-' ) )
|
||||
{
|
||||
// validity chek of it + 1
|
||||
if ( ( it + 1 ) != end )
|
||||
{
|
||||
// 1. if the next character is '\n'
|
||||
const QString &lookahedStr = (*(it+1))->text();
|
||||
if (lookahedStr.startsWith('\n'))
|
||||
{
|
||||
len -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2. if the next word is in a different line or not
|
||||
const int pageWidth = m_page->m_page->width();
|
||||
const int pageHeight = m_page->m_page->height();
|
||||
|
||||
// if the '-' is the last entry
|
||||
// if(str.at(len-1) == '-'){
|
||||
if(str.endsWith('-')){
|
||||
const QRect hyphenArea = (*it)->area.roundedGeometry(pageWidth, pageHeight);
|
||||
const QRect lookaheadArea = (*(it + 1))->area.roundedGeometry(pageWidth, pageHeight);
|
||||
|
||||
// validity chek of it + 1
|
||||
if( ( it + 1 ) != end){
|
||||
|
||||
// 1. if the next character is '\n'
|
||||
const QString &lookahedStr = (*(it+1))->text();
|
||||
if(lookahedStr.at(0) == '\n'){
|
||||
// lookahead to check whether both the '-' rect and next character rect overlap
|
||||
if( !doesConsumeY( hyphenArea, lookaheadArea, 70 ) )
|
||||
{
|
||||
len -= 1;
|
||||
}
|
||||
|
||||
else{
|
||||
// 2. if the next word is in a different line or not
|
||||
|
||||
QRect hyphenArea,lookaheadArea;
|
||||
const int pageWidth = m_page->m_page->width();
|
||||
const int pageHeight = m_page->m_page->height();
|
||||
|
||||
hyphenArea = (*it)->area.roundedGeometry(pageWidth,pageHeight);
|
||||
lookaheadArea = (*(it + 1))->area.roundedGeometry(pageWidth,pageHeight);
|
||||
|
||||
// lookahead to check whether both the '-' rect and next character rect overlap
|
||||
if( !doesConsumeY(hyphenArea,lookaheadArea,70) ){
|
||||
len -= 1;
|
||||
// cout << "f: " << lookahedStr.toAscii().data() << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// else if it is the second last entry - for example in pdf format
|
||||
else if(str.at(len-2) == '-'){
|
||||
// if(str.at(len-1) == '\n'){
|
||||
if(str.endsWith('\n')){
|
||||
len -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// else if it is the second last entry - for example in pdf format
|
||||
else if (str.endsWith("-\n"))
|
||||
{
|
||||
len -= 2;
|
||||
}
|
||||
|
||||
int min=qMin(queryLeft,len);
|
||||
|
||||
int resStrLen = 0, resQueryLen = 0;
|
||||
if ( !comparer( str.midRef( offset, min ), query.midRef( j, min ),
|
||||
&resStrLen, &resQueryLen ) )
|
||||
|
@ -938,51 +972,40 @@ RegularAreaRect* TextPagePrivate::findTextInternalBackward( int searchID, const
|
|||
// hyphenated '-' must be at the end of a word, so hyphenation means
|
||||
// we have a '-' just followed by a '\n' character
|
||||
// check if the string contains a '-' character
|
||||
if(str.contains('-')){
|
||||
// if the '-' is the last entry
|
||||
if ( str.endsWith('-') )
|
||||
{
|
||||
// validity chek of it + 1
|
||||
if ( ( it + 1 ) != end )
|
||||
{
|
||||
// 1. if the next character is '\n'
|
||||
const QString &lookahedStr = (*(it+1))->text();
|
||||
if ( lookahedStr.startsWith('\n') )
|
||||
{
|
||||
len -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2. if the next word is in a different line or not
|
||||
const int pageWidth = m_page->m_page->width();
|
||||
const int pageHeight = m_page->m_page->height();
|
||||
|
||||
// if the '-' is the last entry
|
||||
if(str.endsWith('-')){
|
||||
const QRect hyphenArea = (*it)->area.roundedGeometry(pageWidth,pageHeight);
|
||||
const QRect lookaheadArea = (*(it + 1))->area.roundedGeometry(pageWidth,pageHeight);
|
||||
|
||||
// validity chek of it + 1
|
||||
if( ( it + 1 ) != end){
|
||||
|
||||
// 1. if the next character is '\n'
|
||||
const QString &lookahedStr = (*(it+1))->text();
|
||||
if(lookahedStr == "\n"){
|
||||
// lookahead to check whether both the '-' rect and next character rect overlap
|
||||
if ( !doesConsumeY( hyphenArea, lookaheadArea, 70 ) )
|
||||
{
|
||||
len -= 1;
|
||||
}
|
||||
|
||||
else{
|
||||
// 2. if the next word is in a different line or not
|
||||
|
||||
QRect hyphenArea,lookaheadArea;
|
||||
const int pageWidth = m_page->m_page->width();
|
||||
const int pageHeight = m_page->m_page->height();
|
||||
|
||||
hyphenArea = (*it)->area.roundedGeometry(pageWidth,pageHeight);
|
||||
lookaheadArea = (*(it + 1))->area.roundedGeometry(pageWidth,pageHeight);
|
||||
|
||||
// lookahead to check whether both the '-' rect and next character rect overlap
|
||||
if( !doesConsumeY(hyphenArea,lookaheadArea,70) ){
|
||||
// cout << "djvu" << endl;
|
||||
// cout << "b:" << str.toAscii().data() << lookahedStr.toAscii().data() << endl;
|
||||
// str.remove(len-1,1);
|
||||
len -= 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// else if it is the second last entry - for example in pdf format
|
||||
else if(str.endsWith("-\n")){
|
||||
len -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// else if it is the second last entry - for example in pdf format
|
||||
else if ( str.endsWith("-\n") )
|
||||
{
|
||||
len -= 2;
|
||||
}
|
||||
|
||||
int min=qMin(queryLeft,len);
|
||||
#ifdef DEBUG_TEXTPAGE
|
||||
|
@ -1145,64 +1168,6 @@ TextList TextPagePrivate::duplicateWordList() const
|
|||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the horizontal arm of one rectangle fully contains the other (example below)
|
||||
* -------- ---- ----- first
|
||||
* ---- -------- ----- second
|
||||
* or we can make it overlap of spaces by threshold%
|
||||
*/
|
||||
static bool doesConsumeX(const QRect& first, const QRect& second, int threshold)
|
||||
{
|
||||
// if one consumes another fully
|
||||
if(first.left() <= second.left() && first.right() >= second.right())
|
||||
return true;
|
||||
|
||||
if(first.left() >= second.left() && first.right() <= second.right())
|
||||
return true;
|
||||
|
||||
// or if there is overlap of space by more than threshold%
|
||||
// there is overlap
|
||||
if(second.right() >= first.left() && first.right() >= second.left())
|
||||
{
|
||||
const int overlap = (second.right() >= first.right()) ? first.right() - second.left()
|
||||
: second.right() - first.left();
|
||||
// we will divide by the smaller rectangle to calculate the overlap
|
||||
const int percentage = (first.width() < second.width()) ? overlap * 100 / (first.right() - first.left())
|
||||
: overlap * 100 / (second.right() - second.left());
|
||||
if(percentage >= threshold) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same concept of doesConsumeX but in this case we calculate on y axis
|
||||
*/
|
||||
static bool doesConsumeY(const QRect& first, const QRect& second, int threshold)
|
||||
{
|
||||
// if one consumes another fully
|
||||
if(first.top() <= second.top() && first.bottom() >= second.bottom())
|
||||
return true;
|
||||
|
||||
if(first.top() >= second.top() && first.bottom() <= second.bottom())
|
||||
return true;
|
||||
|
||||
// or if there is overlap of space by more than 80%
|
||||
// there is overlap
|
||||
if(second.bottom() >= first.top() && first.bottom() >= second.top())
|
||||
{
|
||||
const int overlap = (second.bottom() >= first.bottom()) ? first.bottom() - second.top()
|
||||
: second.bottom() - first.top();
|
||||
//we will divide by the smaller rectangle to calculate the overlap
|
||||
const int percentage = (first.width() < second.width()) ? overlap * 100 / (first.bottom() - first.top())
|
||||
: overlap * 100 / (second.bottom() - second.top());
|
||||
|
||||
if(percentage >= threshold) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all the spaces in between texts. It will make all the generators
|
||||
* same, whether they save spaces(like pdf) or not(like djvu).
|
||||
|
|
|
@ -27,7 +27,6 @@ class TextPagePrivate;
|
|||
class TextSelection;
|
||||
class RegularAreaRect;
|
||||
|
||||
|
||||
/*! @class TextEntity
|
||||
* @short Abstract textentity of Okular
|
||||
* @par The context
|
||||
|
|
|
@ -297,11 +297,6 @@ void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okula
|
|||
QRect highlightRect = r.geometry( scaledWidth, scaledHeight ).translated( -scaledCrop.topLeft() ).intersect( limits );
|
||||
highlightRect.translate( -limits.left(), -limits.top() );
|
||||
|
||||
|
||||
/**
|
||||
* We need to change in this function to resolve some issues with transparency.
|
||||
* This is the next phase of work.
|
||||
*/
|
||||
// highlight composition (product: highlight color * destcolor)
|
||||
unsigned int * data = (unsigned int *)backImage.bits();
|
||||
int val, newR, newG, newB,
|
||||
|
|
Loading…
Reference in a new issue