Subversion Repositories Scribus

Rev

Rev 5559 | Rev 5581 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4669 avox 1
#ifndef STORYTEXT_H_
2
#define STORYTEXT_H_
3
 
4
#include <qstring.h>
5
#include <qvaluevector.h>
6
#include <qptrvector.h>
7
#include <qptrlist.h>
8
 
9
//#include "text/paragraphlayout.h"
10
//#include "text/frect.h"
11
 
12
#ifdef NLS_CONFORMANCE
13
#define NLS_PRIVATE private
14
#else
15
#define NLS_PRIVATE public
16
#endif
17
 
18
class SpecialChars {
19
public:
20
        static QChar OBJECT;
21
        static QChar TAB;
22
        static QChar PARSEP;
23
        static QChar LINEBREAK;
24
        static QChar COLBREAK;
25
        static QChar FRAMEBREAK;
26
        static QChar SHYPHEN;
27
        static QChar NBHYPHEN;
28
        static QChar NBSPACE;
29
        static QChar ZWNBSPACE;
30
        static QChar ZWSPACE;
31
//      static QChar SPACE;
32
};
33
 
34
class CharStyle;
5346 mrdocs 35
class ParagraphStyle;
4669 avox 36
class PageItem;
37
//class ScTextEngine;
38
//class ScScriptItem;
39
//class ScText_Shared;
40
class ScribusDoc;
41
 
42
/**
43
 * This class holds the text of a Scribus textframe and pointers to its
44
 * styles and embedded objects.
45
 *
46
 * The logical view of the text consists of a sequence of Unicode chars.
47
 * Partition objects keep track of the positions of style changes,
48
 * paragraph ends and embedded objects.
49
 *
50
 * The physical view consists of a sequence of ScriptItems. Each ScriptItem
51
 * corresponds to a subsequence of Unicode chars in the original sequence
52
 * and associates this with an array of glyph indices. Metrics information
53
 * give the physical position of the ScriptItem in the textframe and its
54
 * bounding box. For each glyph there's also its advance and the relative
55
 * offsets to its basepoint. Other information in the ScriptItem is only
56
 * used by the layouter.
57
 */
58
 class StoryText : NLS_PRIVATE QPtrList<ScText> {
59
 public:
60
        StoryText(ScribusDoc * doc);
61
        StoryText(const StoryText & other);
62
        StoryText& operator= (const StoryText & other);
63
        virtual ~StoryText();
64
        void clear();
65
        void removeChars(int pos, uint len);
66
        void insertChars(int pos, QString txt);
67
        void insertObject(int pos, PageItem* obj);
68
        void replaceChar(int pos, QChar ch);
69
 
5559 avox 70
        void hyphenateWord(int pos, uint len, char* hyphens);
71
 
4669 avox 72
        int length() const;
73
        QChar text(int pos) const;
74
        QString text(int pos, uint len) const;
75
        PageItem* object(int pos) const;
5559 avox 76
 
77
        int nextCharPos(int c);
78
        int prevCharPos(int c);
79
        int nextWordPos(int c);
80
        int prevWordPos(int c);
81
        int nextLinePos(int c, double oldX);
82
        int prevLinePos(int c, double oldX);
83
        int nextFramePos(int c);
84
        int prevFramePos(int c);
85
 
4669 avox 86
        const CharStyle& charStyle(int pos) const;
5346 mrdocs 87
        const ParagraphStyle& paragraphStyle(int pos) const;
5559 avox 88
        const ParagraphStyle& defaultStyle() const;
89
        void setDefaultStyle(const ParagraphStyle& style);
4669 avox 90
        void applyStyle(int pos, uint len, const CharStyle& style);
91
        void applyStyle(int pos, const ParagraphStyle& style);
92
 
93
        uint nrOfParagraphs() const;
94
        int startOfParagraph(uint index) const;
95
        int endOfParagraph(uint index) const;
96
 
97
        uint nrOfRuns() const;
98
        int startOfRun(uint index) const;
99
        int endOfRun(uint index) const;
100
 
5184 avox 101
// positioning
102
        int nextChar(int pos);
103
        int prevChar(int pos);
104
        int nextWord(int pos);
105
        int prevWord(int pos);
106
        int nextSentence(int pos);
107
        int prevSentence(int pos);
108
        int nextParagraph(int pos);
109
        int prevParagraph(int pos);
110
 
111
// these need valid layout:
112
 
113
        int startOfLine(int pos);
114
        int endOfLine(int pos);
115
        int lineUp(int pos, int oldX);
116
        int lineDown(int pos, int oldX);
117
        int startOfFrame(int pos);
118
        int endOfFrame(int pos);
119
 
4669 avox 120
// selection
121
 
122
        void selectAll();
123
        void deselectAll();
124
        void removeSelection();
125
        void select(int pos, uint len, bool on = true);
126
        bool selected(int pos) const;
127
        int startOfSelection() const;
128
        int endOfSelection() const;
129
        int lengthOfSelection() const;
130
 
131
 
132
//  when physical view doesn't match logical view any more:
133
 
134
        /// call this if the shape of an embedded object changes (redos layout)
135
        void invalidateObject(const PageItem* embedded);
136
        /// call this if the shape of the paragraph changes (redos layout)
137
        void invalidateLayout();
138
        /// call this if some logical style changes (redos shaping and layout)
139
        void invalidateAll();
140
 
141
 
142
 
143
 
144
// physical view
145
 
5184 avox 146
        bool overflows() const;
4669 avox 147
        /// layouts the text -- FIXME: better interface for this
148
        int layout(int startItem);
149
        uint nrOfItems() const;
150
        ScText * item(uint index);
151
//      void bidiReorder(uint firstItem, uint lastItem, uint indices[]) const;
152
        /** returns the Unicode string which belongs to this ScScriptItem */
153
        const QString itemText(uint index) const;
154
        /** returns the CharStyle which belongs to this ScScriptItem */
155
        const CharStyle itemStyle(uint index) const;
156
        /// returns the character postion at the start of this item
157
        int startOfItem(uint index) const;
158
        /// returns the character position after this item
159
        int endOfItem(uint index) const;
160
//      const ScTextEngine * engineForRun(uint index) const;
161
//      const ScTextEngine * engineForItem(uint index) const;
162
 
163
//      ParagraphLayout layouter;
164
 
165
        int screenToPosition(FPoint coord) const;
166
        FPoint  boundingBox(int pos, uint len = 1) const;
167
 
168
 private:
169
        ScribusDoc * doc;
170
        int selFirst, selLast;
171
        int firstFrameItem, lastFrameItem;
5569 avox 172
        ParagraphStyle defaultStyle_;
4669 avox 173
 
174
        /// mark these runs as invalid, ie. need itemize and shaping
175
        void invalidate(int firstRun, int lastRun);
176
 
177
//      int splitRun(int pos);
178
 
179
        /** bring physical view in sync with logical one.
180
         *  This gets called automatically from all physical view methods
181
         */
182
//      void validate();
183
        /// private data structure
184
//      ScText_Shared * d;
185
        /// gives the physical view which was last given to the layouter
186
//      uint layouterVersion;
187
        /// is true after layout() has been exercised
188
//      bool layouterValid;
189
 };
190
#endif /*STORYTEXT_H_*/