4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Asger Alstrup
8 * \author Lars Gullik Bjønnes
10 * \author André Pönitz
11 * \author Jürgen Vigna
13 * Full author contact details are available in file CREDITS.
19 #include "LayoutPtr.h"
21 #include "insets/InsetCode.h"
23 #include "support/docstring.h"
24 // FIXME: would be nice to forward declare odocstream instead of
26 #include "support/docstream.h"
46 class ParagraphParameters;
52 /// Invalid font span containing no character
53 FontSpan() : first(0), last(-1) {}
54 /// Span including first and last
55 FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
58 /// Range including first and last.
67 text_capitalization = 1,
73 /// A Paragraph holds all text, attributes and insets in a text paragraph
74 /// \todo FIXME: any reference to ParagraphMetrics (including inheritance)
75 /// should go in order to complete the Model/View separation of this class.
81 Paragraph(Paragraph const &);
83 Paragraph & operator=(Paragraph const &);
90 Language const * getParLanguage(BufferParams const &) const;
92 bool isRTL(BufferParams const &) const;
94 void changeLanguage(BufferParams const & bparams,
95 Language const * from, Language const * to);
97 bool isMultiLingual(BufferParams const &) const;
100 docstring const asString(Buffer const &, bool label) const;
102 docstring const asString(Buffer const & buffer,
108 void write(Buffer const &, std::ostream &, BufferParams const &,
109 depth_type & depth) const;
111 void validate(LaTeXFeatures &) const;
114 bool latex(Buffer const &, BufferParams const &,
115 Font const & outerfont, odocstream &,
116 TexRow & texrow, OutputParams const &) const;
118 /// Can we drop the standard paragraph wrapper?
119 bool emptyTag() const;
121 /// Get the id of the paragraph, usefull for docbook
122 std::string getID(Buffer const & buf,
123 OutputParams const & runparams) const;
125 /// Get the first word of a paragraph, return the position where it left
126 pos_type getFirstWord(Buffer const & buf,
128 OutputParams const & runparams) const;
130 /// Checks if the paragraph contains only text and no inset or font change.
131 bool onlyText(Buffer const & buf, Font const & outerfont,
132 pos_type initial) const;
134 /// Writes to stream the docbook representation
135 void simpleDocBookOnePar(Buffer const & buf,
137 OutputParams const & runparams,
138 Font const & outerfont,
139 pos_type initial = 0) const;
142 bool hasSameLayout(Paragraph const & par) const;
145 void makeSameLayout(Paragraph const & par);
148 void setInsetOwner(Inset * inset);
150 Inset * inInset() const;
152 InsetCode ownerCode() const;
154 bool forceDefaultParagraphs() const;
157 pos_type size() const;
162 LayoutPtr const & layout() const;
164 void layout(LayoutPtr const & new_layout);
166 /// This is the item depth, only used by enumerate and itemize
167 signed char itemdepth;
170 InsetBibitem * bibitem() const; // ale970302
172 /// look up change at given pos
173 Change const & lookupChange(pos_type pos) const;
175 /// is there a change within the given range ?
176 bool isChanged(pos_type start, pos_type end) const;
177 /// is there an unchanged char at the given pos ?
178 bool isUnchanged(pos_type pos) const;
179 /// is there an insertion at the given pos ?
180 bool isInserted(pos_type pos) const;
181 /// is there a deletion at the given pos ?
182 bool isDeleted(pos_type pos) const;
184 /// will the paragraph be physically merged with the next
185 /// one if the imaginary end-of-par character is logically deleted?
186 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
188 /// set change for the entire par
189 void setChange(Change const & change);
191 /// set change at given pos
192 void setChange(pos_type pos, Change const & change);
194 /// accept changes within the given range
195 void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
197 /// reject changes within the given range
198 void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
200 /// Paragraphs can contain "manual labels", for example, Description
201 /// environment. The text for this user-editable label is stored in
202 /// the paragraph alongside the text of the rest of the paragraph
203 /// (the body). This function returns the starting position of the
204 /// body of the text in the paragraph.
205 pos_type beginOfBody() const;
206 /// recompute this value
207 void setBeginOfBody();
210 docstring const & getLabelstring() const;
212 /// the next two functions are for the manual labels
213 docstring const getLabelWidthString() const;
214 /// Set label width string.
215 void setLabelWidthString(docstring const & s);
216 /// translate \p label to the paragraph language if possible.
217 docstring const translateIfPossible(docstring const & label,
218 BufferParams const & bparams) const;
219 /// Expand the counters for the labelstring of \c layout
220 docstring expandLabel(LayoutPtr const &, BufferParams const &,
221 bool process_appendix = true) const;
222 /// Actual paragraph alignment used
223 char getAlign() const;
224 /// The nesting depth of a paragraph
225 depth_type getDepth() const;
226 /// The maximal possible depth of a paragraph after this one
227 depth_type getMaxDepthAfter() const;
229 void applyLayout(LayoutPtr const & new_layout);
231 /// (logically) erase the char at pos; return true if it was actually erased
232 bool eraseChar(pos_type pos, bool trackChanges);
233 /// (logically) erase the given range; return the number of chars actually erased
234 int eraseChars(pos_type start, pos_type end, bool trackChanges);
236 /** Get uninstantiated font setting. Returns the difference
237 between the characters font and the layoutfont.
238 This is what is stored in the fonttable
241 getFontSettings(BufferParams const &, pos_type pos) const;
243 Font const getFirstFontSettings(BufferParams const &) const;
245 /** Get fully instantiated font. If pos == -1, use the layout
246 font attached to this paragraph.
247 If pos == -2, use the label font of the layout attached here.
248 In all cases, the font is instantiated, i.e. does not have any
249 attributes with values Font::INHERIT, Font::IGNORE or
252 Font const getFont(BufferParams const &, pos_type pos,
253 Font const & outerfont) const;
254 Font const getLayoutFont(BufferParams const &,
255 Font const & outerfont) const;
256 Font const getLabelFont(BufferParams const &,
257 Font const & outerfont) const;
259 * The font returned by the above functions is the same in a
260 * span of characters. This method will return the first and
261 * the last positions in the paragraph for which that font is
262 * the same. This can be used to avoid unnecessary calls to getFont.
264 FontSpan fontSpan(pos_type pos) const;
266 char_type getChar(pos_type pos) const;
267 /// Get the char, but mirror all bracket characters if it is right-to-left
268 char_type getUChar(BufferParams const &, pos_type pos) const;
269 /// pos <= size() (there is a dummy font change at the end of each par)
270 void setFont(pos_type pos, Font const & font);
271 /// Returns the height of the highest font in range
272 Font_size highestFontInRange(pos_type startpos,
273 pos_type endpos, Font_size def_size) const;
275 void insert(pos_type pos, docstring const & str,
276 Font const & font, Change const & change);
279 void appendString(docstring const & s, Font const & font,
280 Change const & change);
282 void appendChar(char_type c, Font const & font, Change const & change);
284 void insertChar(pos_type pos, char_type c, bool trackChanges);
286 void insertChar(pos_type pos, char_type c,
287 Font const &, bool trackChanges);
289 void insertChar(pos_type pos, char_type c,
290 Font const &, Change const & change);
292 void insertInset(pos_type pos, Inset * inset,
293 Change const & change);
295 void insertInset(pos_type pos, Inset * inset,
296 Font const &, Change const & change);
298 bool insetAllowed(InsetCode code);
300 Inset * getInset(pos_type pos);
302 Inset const * getInset(pos_type pos) const;
304 /// Release inset at given position.
305 /// \warning does not honour change tracking!
306 /// Therefore, it should only be used for breaking and merging
308 Inset * releaseInset(pos_type pos);
311 InsetList const & insetList() const;
314 bool isHfill(pos_type pos) const;
316 /// hinted by profiler
317 bool isInset(pos_type pos) const;
319 bool isNewline(pos_type pos) const;
320 /// return true if the char is a word separator
321 bool isSeparator(pos_type pos) const;
323 bool isLineSeparator(pos_type pos) const;
324 /// True if the character/inset at this point can be part of a word.
325 /// Note that digits in particular are considered as letters
326 bool isLetter(pos_type pos) const;
328 /// returns true if at least one line break or line separator has been deleted
329 /// at the beginning of the paragraph (either physically or logically)
330 bool stripLeadingSpaces(bool trackChanges);
332 /// return true if we allow multiple spaces
333 bool isFreeSpacing() const;
335 /// return true if we allow this par to stay empty
336 bool allowEmpty() const;
338 char_type transformChar(char_type c, pos_type pos) const;
340 ParagraphParameters & params();
342 ParagraphParameters const & params() const;
344 /// Check if we are in a Biblio environment and insert or
345 /// delete InsetBibitems as necessary.
346 /// \retval int 1, if we had to add an inset, in which case
347 /// the cursor will need to move cursor forward; -pos, if we deleted
348 /// an inset, in which case pos is the position from which the inset
349 /// was deleted, and the cursor will need to be moved back one if it
350 /// was previously past that position. Return 0 otherwise.
351 int checkBiblio(bool track_changes);
353 /// For each author, set 'used' to true if there is a change
354 /// by this author in the paragraph.
355 void checkAuthors(AuthorList const & authorList);
357 /// return the number of InsetOptArg in a paragraph
358 int numberOfOptArgs() const;
361 void changeCase(BufferParams const & bparams, pos_type pos,
362 pos_type right, TextCase action);
364 /// find \param str string inside Paragraph.
365 /// \return true if the specified string is at the specified position
366 /// \param del specifies whether deleted strings in ct mode will be considered
368 docstring const & str, ///< string to search
371 pos_type pos, ///< start from here.
372 bool del = true) const;
378 friend class Paragraph::Private;
385 #endif // PARAGRAPH_H