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 "FontEnums.h"
20 #include "SpellChecker.h"
22 #include "insets/InsetCode.h"
24 #include "support/strfwd.h"
25 #include "support/types.h"
53 class ParagraphParameters;
61 /// Invalid font span containing no character
62 FontSpan() : first(0), last(-1) {}
63 /// Span including first and last
64 FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
67 /// Range including first and last.
76 text_capitalization = 1,
83 enum AsStringParameter
85 AS_STR_NONE = 0, ///< No option, only printable characters.
86 AS_STR_LABEL = 1, ///< Prefix with paragraph label.
87 AS_STR_INSETS = 2, ///< Go into insets.
88 AS_STR_NEWLINES = 4 ///< Get also newline characters.
92 /// A Paragraph holds all text, attributes and insets in a text paragraph
99 Paragraph(Paragraph const &);
100 /// Partial copy constructor.
101 /// Copy the Paragraph contents from \p beg to \p end (without end).
102 Paragraph(Paragraph const & par, pos_type beg, pos_type end);
104 Paragraph & operator=(Paragraph const &);
113 void addChangesToToc(DocIterator const & cdit, Buffer const & buf) const;
115 Language const * getParLanguage(BufferParams const &) const;
117 bool isRTL(BufferParams const &) const;
119 void changeLanguage(BufferParams const & bparams,
120 Language const * from, Language const * to);
122 bool isMultiLingual(BufferParams const &) const;
124 void getLanguages(std::set<Language const *> &) const;
126 /// Convert the paragraph to a string.
127 /// \param AsStringParameter options. This can contain any combination of
128 /// asStringParameter values. Valid examples:
129 /// asString(AS_STR_LABEL)
130 /// asString(AS_STR_LABEL | AS_STR_INSETS)
131 /// asString(AS_STR_INSETS)
132 docstring asString(int options = AS_STR_NONE) const;
134 docstring asString(pos_type beg, pos_type end,
135 int options = AS_STR_NONE) const;
137 /// Extract only the explicitly visible text (without any formatting),
138 /// descending into insets
139 docstring stringify(pos_type beg, pos_type end, int options, OutputParams & runparams) const;
142 void write(std::ostream &, BufferParams const &,
143 depth_type & depth) const;
145 void validate(LaTeXFeatures &) const;
147 /// \param force means: output even if layout.inpreamble is true.
148 void latex(BufferParams const &, Font const & outerfont, odocstream &,
149 TexRow & texrow, OutputParams const &,
150 int start_pos = 0, int end_pos = -1, bool force = false) const;
152 /// Can we drop the standard paragraph wrapper?
153 bool emptyTag() const;
155 /// Get the id of the paragraph, usefull for docbook
156 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
158 /// Output the first word of a paragraph, return the position where it left.
159 pos_type firstWordDocBook(odocstream & os, OutputParams const & runparams) const;
161 /// Output the first word of a paragraph, return the position where it left.
162 pos_type firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams) const;
164 /// Writes to stream the docbook representation
165 void simpleDocBookOnePar(Buffer const & buf,
167 OutputParams const & runparams,
168 Font const & outerfont,
169 pos_type initial = 0) const;
170 /// \return any material that has had to be deferred until after the
171 /// paragraph has closed.
172 docstring simpleLyXHTMLOnePar(Buffer const & buf,
174 OutputParams const & runparams,
175 Font const & outerfont,
176 pos_type initial = 0) const;
179 bool hasSameLayout(Paragraph const & par) const;
182 void makeSameLayout(Paragraph const & par);
185 void setInsetOwner(Inset const * inset);
187 Inset const & inInset() const;
189 bool allowParagraphCustomization() const;
191 bool usePlainLayout() const;
193 pos_type size() const;
198 Layout const & layout() const;
199 /// Do not pass a temporary to this!
200 void setLayout(Layout const & layout);
202 void setPlainOrDefaultLayout(DocumentClass const & tc);
204 void setDefaultLayout(DocumentClass const & tc);
206 void setPlainLayout(DocumentClass const & tc);
208 /// This is the item depth, only used by enumerate and itemize
209 signed char itemdepth;
211 /// look up change at given pos
212 Change const & lookupChange(pos_type pos) const;
214 /// is there a change within the given range ?
215 bool isChanged(pos_type start, pos_type end) const;
216 /// is there an unchanged char at the given pos ?
217 bool isChanged(pos_type pos) const;
218 /// is there an insertion at the given pos ?
219 bool isInserted(pos_type pos) const;
220 /// is there a deletion at the given pos ?
221 bool isDeleted(pos_type pos) const;
222 /// is the whole paragraph deleted ?
223 bool isDeleted(pos_type start, pos_type end) const;
225 /// will the paragraph be physically merged with the next
226 /// one if the imaginary end-of-par character is logically deleted?
227 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
229 /// set change for the entire par
230 void setChange(Change const & change);
232 /// set change at given pos
233 void setChange(pos_type pos, Change const & change);
235 /// accept changes within the given range
236 void acceptChanges(pos_type start, pos_type end);
238 /// reject changes within the given range
239 void rejectChanges(pos_type start, pos_type end);
241 /// Paragraphs can contain "manual labels", for example, Description
242 /// environment. The text for this user-editable label is stored in
243 /// the paragraph alongside the text of the rest of the paragraph
244 /// (the body). This function returns the starting position of the
245 /// body of the text in the paragraph.
246 pos_type beginOfBody() const;
247 /// recompute this value
248 void setBeginOfBody();
251 docstring expandLabel(Layout const &, BufferParams const &) const;
253 docstring expandDocBookLabel(Layout const &, BufferParams const &) const;
255 docstring const & labelString() const;
256 /// the next two functions are for the manual labels
257 docstring const getLabelWidthString() const;
258 /// Set label width string.
259 void setLabelWidthString(docstring const & s);
260 /// Actual paragraph alignment used
261 char getAlign() const;
262 /// The nesting depth of a paragraph
263 depth_type getDepth() const;
264 /// The maximal possible depth of a paragraph after this one
265 depth_type getMaxDepthAfter() const;
267 void applyLayout(Layout const & new_layout);
269 /// (logically) erase the char at pos; return true if it was actually erased
270 bool eraseChar(pos_type pos, bool trackChanges);
271 /// (logically) erase the given range; return the number of chars actually erased
272 int eraseChars(pos_type start, pos_type end, bool trackChanges);
275 void resetFonts(Font const & font);
277 /** Get uninstantiated font setting. Returns the difference
278 between the characters font and the layoutfont.
279 This is what is stored in the fonttable
282 getFontSettings(BufferParams const &, pos_type pos) const;
284 Font const & getFirstFontSettings(BufferParams const &) const;
286 /** Get fully instantiated font. If pos == -1, use the layout
287 font attached to this paragraph.
288 If pos == -2, use the label font of the layout attached here.
289 In all cases, the font is instantiated, i.e. does not have any
290 attributes with values FONT_INHERIT, FONT_IGNORE or
293 Font const getFont(BufferParams const &, pos_type pos,
294 Font const & outerfont) const;
295 Font const getLayoutFont(BufferParams const &,
296 Font const & outerfont) const;
297 Font const getLabelFont(BufferParams const &,
298 Font const & outerfont) const;
300 * The font returned by the above functions is the same in a
301 * span of characters. This method will return the first and
302 * the last positions in the paragraph for which that font is
303 * the same. This can be used to avoid unnecessary calls to getFont.
305 FontSpan fontSpan(pos_type pos) const;
307 char_type getChar(pos_type pos) const;
308 /// Get the char, but mirror all bracket characters if it is right-to-left
309 char_type getUChar(BufferParams const &, pos_type pos) const;
310 /// pos <= size() (there is a dummy font change at the end of each par)
311 void setFont(pos_type pos, Font const & font);
312 /// Returns the height of the highest font in range
313 FontSize highestFontInRange(pos_type startpos,
314 pos_type endpos, FontSize def_size) const;
316 void insert(pos_type pos, docstring const & str,
317 Font const & font, Change const & change);
320 void appendString(docstring const & s, Font const & font,
321 Change const & change);
323 void appendChar(char_type c, Font const & font, Change const & change);
325 void insertChar(pos_type pos, char_type c, bool trackChanges);
327 void insertChar(pos_type pos, char_type c,
328 Font const &, bool trackChanges);
330 void insertChar(pos_type pos, char_type c,
331 Font const &, Change const & change);
332 /// Insert \p inset at position \p pos with \p change traking status.
333 /// \return true if successful.
334 bool insertInset(pos_type pos, Inset * inset,
335 Change const & change);
336 /// Insert \p inset at position \p pos with \p change traking status and
338 /// \return true if successful.
339 bool insertInset(pos_type pos, Inset * inset,
340 Font const & font, Change const & change);
342 Inset * getInset(pos_type pos);
344 Inset const * getInset(pos_type pos) const;
346 /// Release inset at given position.
347 /// \warning does not honour change tracking!
348 /// Therefore, it should only be used for breaking and merging
350 Inset * releaseInset(pos_type pos);
353 InsetList const & insetList() const;
355 void setBuffer(Buffer &);
358 bool isHfill(pos_type pos) const;
360 /// hinted by profiler
361 bool isInset(pos_type pos) const;
363 bool isNewline(pos_type pos) const;
364 /// return true if the char is a word separator
365 bool isSeparator(pos_type pos) const;
367 bool isLineSeparator(pos_type pos) const;
368 /// True if the character/inset at this point is a word separator.
369 /// Note that digits in particular are not considered as word separator.
370 bool isWordSeparator(pos_type pos) const;
371 /// True if the element at this point is a character that is not a letter.
372 bool isChar(pos_type pos) const;
373 /// True if the element at this point is a space
374 bool isSpace(pos_type pos) const;
376 /// returns true if at least one line break or line separator has been deleted
377 /// at the beginning of the paragraph (either physically or logically)
378 bool stripLeadingSpaces(bool trackChanges);
380 /// return true if we allow multiple spaces
381 bool isFreeSpacing() const;
383 /// return true if we allow this par to stay empty
384 bool allowEmpty() const;
386 char_type transformChar(char_type c, pos_type pos) const;
388 ParagraphParameters & params();
390 ParagraphParameters const & params() const;
392 /// Check if we are in a Biblio environment and insert or
393 /// delete InsetBibitems as necessary.
394 /// \retval int 1, if we had to add an inset, in which case
395 /// the cursor will need to move cursor forward; -pos, if we deleted
396 /// an inset, in which case pos is the position from which the inset
397 /// was deleted, and the cursor will need to be moved back one if it
398 /// was previously past that position. Return 0 otherwise.
399 int checkBiblio(Buffer const & buffer);
401 /// For each author, set 'used' to true if there is a change
402 /// by this author in the paragraph.
403 void checkAuthors(AuthorList const & authorList);
406 void changeCase(BufferParams const & bparams, pos_type pos,
407 pos_type & right, TextCase action);
409 /// find \param str string inside Paragraph.
410 /// \return true if the specified string is at the specified position
411 /// \param del specifies whether deleted strings in ct mode will be considered
413 docstring const & str, ///< string to search
416 pos_type pos, ///< start from here.
417 bool del = true) const;
419 void locateWord(pos_type & from, pos_type & to,
420 word_location const loc) const;
424 /// Spellcheck word at position \p from and fill in found misspelled word
425 /// and \p suggestions if \p do_suggestion is true.
426 /// \return result from spell checker, SpellChecker::UNKNOWN_WORD when misspelled.
427 SpellChecker::Result spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
428 docstring_list & suggestions, bool do_suggestion = true) const;
430 /// Spellcheck word at position \p pos.
431 /// \return true if pointed word is misspelled.
432 bool isMisspelled(pos_type pos) const;
433 /// an automatically generated identifying label for this paragraph.
434 /// presently used only in the XHTML output routines.
435 std::string magicLabel() const;
438 /// Expand the counters for the labelstring of \c layout
439 docstring expandParagraphLabel(Layout const &, BufferParams const &,
440 bool process_appendix) const;
442 void deregisterWords();
446 void registerWords();
451 friend class Paragraph::Private;
458 #endif // PARAGRAPH_H