textpage_p.h 4.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/***************************************************************************
 *   Copyright (C) 2006      by Tobias Koenig <tokoe@kde.org>              *
 *   Copyright (C) 2007      by Pino Toscano <pino@kde.org>                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef _OKULAR_TEXTPAGE_P_H_
#define _OKULAR_TEXTPAGE_P_H_

14
#include <QtCore/QList>
15
16
17
18
#include <QtCore/QMap>
#include <QtGui/QMatrix>

class SearchPoint;
19
class TinyTextEntity;
20
class RegionText;
21
22
23
24

namespace Okular
{

25
class PagePrivate;
26
typedef QList< TinyTextEntity* > TextList;
27

28
29
30
typedef bool ( *TextComparisonFunction )( const QStringRef & from, const QStringRef & to,
                                          int *fromLength, int *toLength );

31
/**
32
33
 * Make a line of TextList and store the bounding rectangle of line
 */
34
35
36
typedef QList<TextList> SortedTextList;
typedef QList<QRect> LineRect;

37
38
39
/**
 * A list of RegionText. It keeps a bunch of TextList with their bounding rectangles
 */
40
typedef QList<RegionText> RegionTextList;
41

42
43
44
class TextPagePrivate
{
    public:
45
        TextPagePrivate();
46
47
48
49
        ~TextPagePrivate();

        RegularAreaRect * findTextInternalForward( int searchID, const QString &query,
                                                   Qt::CaseSensitivity caseSensitivity,
50
                                                   TextComparisonFunction comparer,
51
52
                                                   const TextList::ConstIterator &start,
                                                   const TextList::ConstIterator &end );
53
54
        RegularAreaRect * findTextInternalBackward( int searchID, const QString &query,
                                                    Qt::CaseSensitivity caseSensitivity,
55
                                                    TextComparisonFunction comparer,
56
57
                                                    const TextList::ConstIterator &start,
                                                    const TextList::ConstIterator &end );
58

59
        /**
60
         * Copy a TextList to m_words, the pointers of list are adopted
61
         */
62
        void setWordList(const TextList &list);
63

64
        /**
65
         * Copy m_words to a new TextList, it is the caller responsability to free the pointers
66
         */
67
        TextList duplicateWordList() const;
68

69
70
71
72
73
74
        /**
         * Make necessary modifications in the TextList to make the text order correct, so
         * that textselection works fine
         */
        void correctTextOrder();

75
        /**
76
77
         * Remove odd spaces which are much bigger than normal spaces from m_words
         */
78
79
80
        void removeSpace();

        /**
81
82
         * Create words from characters
         */
83
        QHash<QRect, RegionText> makeWordFromCharacters();
84
85

        /**
86
87
         * Create lines from TextList and sort them according to their position
         */
88
        void makeAndSortLines(const TextList &words, SortedTextList *lines, LineRect *line_rects) const;
89
90

        /**
91
92
93
         * Caluclate statistical info like, word spacing, column spacing, line spacing from the Lines
         * we made
         */
Albert Astals Cid's avatar
Albert Astals Cid committed
94
95
        void calculateStatisticalInformation(const SortedTextList &lines, const LineRect &line_rects, int *word_spacing,
                                             int *line_spacing, int *column_spacing);
96
97

        /**
98
99
100
         * Functions necessary for document file segmentation into text regions for document layout
         * analysis.
         */
Albert Astals Cid's avatar
Albert Astals Cid committed
101
        RegionTextList XYCutForBoundingBoxes(int tcx, int tcy);
102

103
        /**
104
105
106
         * Add additional spaces between words, if necessary, which can make the words valuable
         * while copying after selection
         */
Albert Astals Cid's avatar
Albert Astals Cid committed
107
        void addNecessarySpace(RegionTextList tree);
108
109

        /**
110
111
         * Break the words into characters, so the text selection wors fine
         */
112
        void breakWordIntoCharacters(const QHash<QRect, RegionText> &words_char_map);
113
114

        // variables those can be accessed directly from TextPage
115
        TextList m_words;
116
        QMap< int, SearchPoint* > m_searchPoints;
117
        PagePrivate *m_page;
118
119
120
121
122
};

}

#endif