Okular
textpage.cpp
75 static bool segmentsOverlap(double left1, double right1, double left2, double right2, int threshold)
104 static bool doesConsumeY(const NormalizedRect &first, const NormalizedRect &second, int threshold)
129 Q_ASSERT_X(sizeof(d) == sizeof(void *), "TinyTextEntity", "internal storage is wider than QChar*, fix it!");
161 return length <= MaxStaticChars ? QString::fromRawData((const QChar *)&d.qc[0], length) : QString::fromRawData(d.data, length);
253 // If this happens it means that the new text + old one have combined, for example A and ◌̊ form Å
258 d->m_words.append(new TinyTextEntity(concatText.normalized(QString::NormalizationForm_KC), newArea));
348 There are two cursors, we need to select all the text between them. The coordinates are normalised, leftTop is (0,0)
349 rightBottom is (1,1), so for cursors start (sx,sy) and end (ex,ey) we start with finding text rectangles under those
350 points, if not we search for the first that is to the right to it in the same baseline, if none found, then we search
351 for the first rectangle with a baseline under the cursor, having two points that are the best rectangles to both
357 To find the closest rectangle to cursor (cx,cy) we search for a rectangle that either contains the cursor
390 * Case 1(a): both startpoint and endpoint are out of the bounding Rectangle and at one side, so the rectangle made of start
393 * Case 1(b): both startpoint and endpoint are out of bounding rect, but they are in different side, so is their rectangle
398 * Case 2(b): if 2(a) fails (if startPoint and endPoint both are unchanged), then we check whether there is any
405 * Also, as 2(b) is passed, we might have it,itEnd or both unchanged, but the fact is that we have
418 const NormalizedRect start_end = (startC.y < endC.y) ? NormalizedRect(startC.x, startC.y, endC.x, endC.y) : NormalizedRect(startC.x, endC.y, endC.x, startC.y);
482 // we have searched every text entities, but none is within the rectangle created by start and end
617 RegularAreaRect *TextPage::findText(int searchID, const QString &query, SearchDirection direct, Qt::CaseSensitivity caseSensitivity, const RegularAreaRect *area)
663 const TextComparisonFunction cmpFn = caseSensitivity == Qt::CaseSensitive ? CaseSensitiveCmpFn : CaseInsensitiveCmpFn;
676 static int stringLengthAdaptedWithHyphen(const QString &str, const TextList::ConstIterator &it, const TextList::ConstIterator &textListEnd)
730 RegularAreaRect *TextPagePrivate::findTextInternalForward(int searchID, const QString &_query, TextComparisonFunction comparer, const TextList::ConstIterator &start, int start_offset, const TextList::ConstIterator &end)
830 RegularAreaRect *TextPagePrivate::findTextInternalBackward(int searchID, const QString &_query, TextComparisonFunction comparer, const TextList::ConstIterator &start, int start_offset, const TextList::ConstIterator &end)
876 if (comparer(str.midRef(offset - min, min - hyphenOffset), query.midRef(j - min + hyphenOffset, min - hyphenOffset))) {
971 static bool compareTinyTextEntityX(const WordWithCharacters &first, const WordWithCharacters &second)
979 static bool compareTinyTextEntityY(const WordWithCharacters &first, const WordWithCharacters &second)
1021 static WordsWithCharacters makeWordFromCharacters(const TextList &characters, int pageWidth, int pageHeight)
1030 * We create a RegionText named regionWord that contains the word and the characters associated with it and
1055 wordCharacters.append(new TinyTextEntity(textString.normalized(QString::NormalizationForm_KC), newRect));
1058 wordCharacters.append(new TinyTextEntity(textString.normalized(QString::NormalizationForm_KC), newRect));
1077 const int text_y1 = elementArea.top(), text_x1 = elementArea.left(), text_y2 = elementArea.y() + elementArea.height(), text_x2 = elementArea.x() + elementArea.width();
1078 const int line_y1 = lineArea.top(), line_x1 = lineArea.left(), line_y2 = lineArea.y() + lineArea.height(), line_x2 = lineArea.x() + lineArea.width();
1103 TinyTextEntity *word = new TinyTextEntity(newString.normalized(QString::NormalizationForm_KC), newRect);
1120 QList<QPair<WordsWithCharacters, QRect>> makeAndSortLines(const WordsWithCharacters &wordsTmp, int pageWidth, int pageHeight)
1158 const int text_y1 = elementArea.top(), text_y2 = elementArea.top() + elementArea.height(), text_x1 = elementArea.left(), text_x2 = elementArea.left() + elementArea.width();
1159 const int line_y1 = lineArea.top(), line_y2 = lineArea.top() + lineArea.height(), line_x1 = lineArea.left(), line_x2 = lineArea.left() + lineArea.width();
1205 static void calculateStatisticalInformation(const QList<WordWithCharacters> &words, int pageWidth, int pageHeight, int *word_spacing, int *line_spacing, int *col_spacing)
1217 const QList<QPair<WordsWithCharacters, QRect>> sortedLines = makeAndSortLines(words, pageWidth, pageHeight);
1337 const int bottom = (max_area1.bottom() < max_area2.bottom()) ? max_area2.bottom() : max_area1.bottom();
1383 * WordsWithCharacters::characters are reused from wordsWithCharacters (i.e. no new nor delete happens in this function)
1385 static RegionTextList XYCutForBoundingBoxes(const QList<WordWithCharacters> &wordsWithCharacters, int pageWidth, int pageHeight)
1422 calculateStatisticalInformation(list, pageWidth, pageHeight, &word_spacing, &line_spacing, &column_spacing);
1564 const QRect bottomRect(regionRect.left(), regionRect.top() + topHeight, regionRect.width(), regionRect.height() - topHeight);
1569 const QRect rightRect(regionRect.left() + leftWidth, regionRect.top(), regionRect.width() - leftWidth, regionRect.height());
1634 * Add spaces in between words in a line. It reuses the pointers passed in tree and might add new ones. You will need to take care of deleting them if needed
1647 QList<QPair<WordsWithCharacters, QRect>> sortedLines = makeAndSortLines(tmpRegion.text(), pageWidth, pageHeight);
1721 const QList<WordWithCharacters> wordsWithCharacters = makeWordFromCharacters(characters, pageWidth, pageHeight);
1731 const WordsWithCharacters listWithWordsAndSpaces = addNecessarySpace(tree, pageWidth, pageHeight);
1744 TextEntity::List TextPage::words(const RegularAreaRect *area, TextAreaInclusionBehaviour b) const
void append(const T &value)
T & first()
QTextStream & center(QTextStream &s)
NormalizationForm_KC
QTextStream & right(QTextStream &stream)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
bool contains(double x, double y) const
Returns whether this area contains the normalized point (x, y).
Definition: area.h:866
void setWidth(int width)
bool contains(const Key &key) const const
const QChar * constData() const const
NormalizedRect transformedArea(const QTransform &matrix) const
Returns the transformed area of the text entity.
Definition: textpage.cpp:205
CaseInsensitive
int right() const const
QStringRef midRef(int position, int n) const const
QTextStream & left(QTextStream &stream)
int length() const const
void append(const T &value)
NormalizedPoint is a helper class which stores the coordinates of a normalized point.
Definition: area.h:116
int width() const const
int x() const const
int y() const const
QList::const_iterator constBegin() const const
int x() const const
int y() const const
bool isRight(const NormalizedPoint &pt) const
Returns true if the point pt is located to the left of the right edge of the rectangle.
Definition: area.h:376
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
int compare(const QString &other, Qt::CaseSensitivity cs) const const
const QList< QKeySequence > & begin()
bool isBottom(const NormalizedPoint &pt) const
Returns true if the point pt is located below the bottom of the rectangle.
Definition: area.h:331
bool intersects(const RegularArea< NormalizedShape, Shape > *area) const
Returns whether this area intersects with the given area.
Definition: area.h:783
QString simplified() const const
int left() const const
QString normalized(QString::NormalizationForm mode, QChar::UnicodeVersion version) const const
void setRight(int x)
QRect geometry(int xScale, int yScale) const
Returns the rectangle mapped to a reference area of xScale x yScale.
Definition: area.cpp:232
int remove(const Key &key)
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
TextAreaInclusionBehaviour
Defines the behaviour of adding characters to text() result.
Definition: textpage.h:117
int bottom() const const
Q_SCRIPTABLE Q_NOREPLY void start()
int top() const const
RegularAreaRect * textArea(TextSelection *selection) const
Returns the rectangular area of the given selection.
Definition: textpage.cpp:340
Wrapper around the information needed to generate the selection area There are two assumptions inside...
Definition: misc.h:33
bool isSpace() const const
This is a list of NormalizedRect, to describe an area consisting of multiple rectangles using normali...
Definition: area.h:932
void setHeight(int height)
void setBottom(int y)
bool isEmpty() const const
int length() const const
const T & at(int i) const const
bool isEmpty() const const
@ FromBottom
Searching from bottom of the page, next result is to be found, there was no earlier search result.
Definition: global.h:37
bool isBottomOrLevel(const NormalizedPoint &pt) const
Returns true if the point pt is located below the top of the rectangle.
Definition: area.h:349
QPoint center() const const
A NormalizedRect is a rectangle which can be defined by two NormalizedPoints.
Definition: area.h:188
@ PreviousResult
Searching for the previous result on the page, earlier result should be located so we search from the...
Definition: global.h:39
void append(const QString &text, NormalizedRect *area)
Appends the given text with the given area as new TextEntity to the page.
Definition: textpage.cpp:246
bool isTopOrLevel(const NormalizedPoint &pt) const
Returns true if the point pt is located above the bottom of the rectangle.
Definition: area.h:358
RegularAreaRect * findText(int searchID, const QString &query, SearchDirection direction, Qt::CaseSensitivity caseSensitivity, const RegularAreaRect *area)
Returns the bounding rect of the text which matches the following criteria or 0 if the search is not ...
Definition: textpage.cpp:617
const Key key(const T &value, const Key &defaultKey) const const
void insert(int i, const T &value)
@ NextResult
Searching for the next result on the page, earlier result should be located so we search from the las...
Definition: global.h:38
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
typedef ConstIterator
void setTop(int y)
int height() const const
QList::const_iterator constEnd() const const
NormalizedRect * area() const
Returns the bounding area of the text entity.
Definition: textpage.cpp:200
TextEntity::List words(const RegularAreaRect *area, TextAreaInclusionBehaviour b) const
Text entity extraction function.
Definition: textpage.cpp:1744
void transform(const QTransform &matrix)
Transforms the normalized rectangle with the operations defined by matrix.
Definition: area.cpp:253
QString right(int n) const const
@ FromTop
Searching from top of the page, next result is to be found, there was no earlier search result.
Definition: global.h:36
QString fromRawData(const QChar *unicode, int size)
const QChar at(int position) const const
void end(const NormalizedPoint &point)
Changes the end point of the selection to the given point.
Definition: misc.cpp:43
bool isTop(const NormalizedPoint &pt) const
Returns true if the point pt is located above the top of the rectangle.
Definition: area.h:340
QList::iterator begin()
bool intersects(const NormalizedRect &other) const
Returns whether the normalized rectangle intersects the other normalized rectangle.
Definition: area.cpp:165
bool contains(double x, double y) const
Returns whether the normalized rectangle contains the normalized point (x, y).
Definition: area.cpp:160
void simplify()
Simplifies this regular area by merging its intersecting subareas.
Definition: area.h:730
void appendShape(const NormalizedShape &shape, MergeSide side=MergeAll)
Appends the given shape to this area.
Definition: area.h:810
Represents a piece of text on a TextPage, containing its textual representation and its bounding box.
Definition: textpage.h:51
RegularAreaRect * wordAt(const NormalizedPoint &p, QString *word=nullptr) const
Returns the area and text of the word at the given point Note that ownership of the returned area bel...
Definition: textpage.cpp:1772
QList::iterator end()
TextEntity(const QString &text, NormalizedRect *area)
Creates a new text entity with the given text and the given area.
Definition: textpage.cpp:183
@ AnyPixelTextAreaInclusionBehaviour
A character is included into text() result if any pixel of his bounding box is in the given area.
Definition: textpage.h:118
void setLeft(int x)
bool isLeft(const NormalizedPoint &pt) const
Returns true if the point pt is located to the right of the left edge of the rectangle.
Definition: area.h:367
const QList< QKeySequence > & end()
QString & append(QChar ch)
ushort unicode() const const
QString text(const RegularAreaRect *area=nullptr) const
Text extraction function.
Definition: textpage.cpp:937
virtual QVariant get(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Sep 22 2023 04:09:42 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Sep 22 2023 04:09:42 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.