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.
70 inline bool operator<(FontSpan const & s) const
72 return first < s.first;
75 inline bool operator==(FontSpan const & s) const
77 return first == s.first && last == s.last;
80 inline bool inside(pos_type p) const
82 return first <= p && p <= last;
92 text_capitalization = 1,
99 enum AsStringParameter
101 AS_STR_NONE = 0, ///< No option, only printable characters.
102 AS_STR_LABEL = 1, ///< Prefix with paragraph label.
103 AS_STR_INSETS = 2, ///< Go into insets.
104 AS_STR_NEWLINES = 4, ///< Get also newline characters.
105 AS_STR_SKIPDELETE = 8, ///< Skip deleted text in change tracking.
106 AS_STR_INTOC = 16 ///< Skip insets that are not supposed to go into the TOC
110 /// A Paragraph holds all text, attributes and insets in a text paragraph
116 /// Copy constructor.
117 Paragraph(Paragraph const &);
118 /// Partial copy constructor.
119 /// Copy the Paragraph contents from \p beg to \p end (without end).
120 Paragraph(Paragraph const & par, pos_type beg, pos_type end);
122 Paragraph & operator=(Paragraph const &);
131 void addChangesToToc(DocIterator const & cdit, Buffer const & buf) const;
133 Language const * getParLanguage(BufferParams const &) const;
135 bool isRTL(BufferParams const &) const;
137 void changeLanguage(BufferParams const & bparams,
138 Language const * from, Language const * to);
140 bool isMultiLingual(BufferParams const &) const;
142 void getLanguages(std::set<Language const *> &) const;
144 /// Convert the paragraph to a string.
145 /// \param AsStringParameter options. This can contain any combination of
146 /// asStringParameter values. Valid examples:
147 /// asString(AS_STR_LABEL)
148 /// asString(AS_STR_LABEL | AS_STR_INSETS)
149 /// asString(AS_STR_INSETS)
150 docstring asString(int options = AS_STR_NONE) const;
152 docstring asString(pos_type beg, pos_type end,
153 int options = AS_STR_NONE) const;
155 /// Extract only the explicitly visible text (without any formatting),
156 /// descending into insets
157 docstring stringify(pos_type beg, pos_type end, int options, OutputParams & runparams) const;
160 void write(std::ostream &, BufferParams const &,
161 depth_type & depth) const;
163 void validate(LaTeXFeatures &) const;
165 /// \param force means: output even if layout.inpreamble is true.
166 void latex(BufferParams const &, Font const & outerfont, odocstream &,
167 TexRow & texrow, OutputParams const &,
168 int start_pos = 0, int end_pos = -1, bool force = false) const;
170 /// Can we drop the standard paragraph wrapper?
171 bool emptyTag() const;
173 /// Get the id of the paragraph, usefull for docbook
174 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
176 /// Output the first word of a paragraph, return the position where it left.
177 pos_type firstWordDocBook(odocstream & os, OutputParams const & runparams) const;
179 /// Output the first word of a paragraph, return the position where it left.
180 pos_type firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams) const;
182 /// Writes to stream the docbook representation
183 void simpleDocBookOnePar(Buffer const & buf,
185 OutputParams const & runparams,
186 Font const & outerfont,
187 pos_type initial = 0) const;
188 /// \return any material that has had to be deferred until after the
189 /// paragraph has closed.
190 docstring simpleLyXHTMLOnePar(Buffer const & buf,
192 OutputParams const & runparams,
193 Font const & outerfont,
194 pos_type initial = 0) const;
197 bool hasSameLayout(Paragraph const & par) const;
200 void makeSameLayout(Paragraph const & par);
203 void setInsetOwner(Inset const * inset);
205 Inset const & inInset() const;
207 bool allowParagraphCustomization() const;
209 bool usePlainLayout() const;
211 pos_type size() const;
216 Layout const & layout() const;
217 /// Do not pass a temporary to this!
218 void setLayout(Layout const & layout);
220 void setPlainOrDefaultLayout(DocumentClass const & tc);
222 void setDefaultLayout(DocumentClass const & tc);
224 void setPlainLayout(DocumentClass const & tc);
226 /// This is the item depth, only used by enumerate and itemize
227 signed char itemdepth;
229 /// look up change at given pos
230 Change const & lookupChange(pos_type pos) const;
232 /// is there a change within the given range ?
233 bool isChanged(pos_type start, pos_type end) const;
234 /// is there an unchanged char at the given pos ?
235 bool isChanged(pos_type pos) const;
236 /// is there an insertion at the given pos ?
237 bool isInserted(pos_type pos) const;
238 /// is there a deletion at the given pos ?
239 bool isDeleted(pos_type pos) const;
240 /// is the whole paragraph deleted ?
241 bool isDeleted(pos_type start, pos_type end) const;
243 /// will the paragraph be physically merged with the next
244 /// one if the imaginary end-of-par character is logically deleted?
245 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
247 /// set change for the entire par
248 void setChange(Change const & change);
250 /// set change at given pos
251 void setChange(pos_type pos, Change const & change);
253 /// accept changes within the given range
254 void acceptChanges(pos_type start, pos_type end);
256 /// reject changes within the given range
257 void rejectChanges(pos_type start, pos_type end);
259 /// Paragraphs can contain "manual labels", for example, Description
260 /// environment. The text for this user-editable label is stored in
261 /// the paragraph alongside the text of the rest of the paragraph
262 /// (the body). This function returns the starting position of the
263 /// body of the text in the paragraph.
264 pos_type beginOfBody() const;
265 /// recompute this value
266 void setBeginOfBody();
269 docstring expandLabel(Layout const &, BufferParams const &) const;
271 docstring expandDocBookLabel(Layout const &, BufferParams const &) const;
273 docstring const & labelString() const;
274 /// the next two functions are for the manual labels
275 docstring const getLabelWidthString() const;
276 /// Set label width string.
277 void setLabelWidthString(docstring const & s);
278 /// Actual paragraph alignment used
279 char getAlign() const;
280 /// The nesting depth of a paragraph
281 depth_type getDepth() const;
282 /// The maximal possible depth of a paragraph after this one
283 depth_type getMaxDepthAfter() const;
285 void applyLayout(Layout const & new_layout);
287 /// (logically) erase the char at pos; return true if it was actually erased
288 bool eraseChar(pos_type pos, bool trackChanges);
289 /// (logically) erase the given range; return the number of chars actually erased
290 int eraseChars(pos_type start, pos_type end, bool trackChanges);
293 void resetFonts(Font const & font);
295 /** Get uninstantiated font setting. Returns the difference
296 between the characters font and the layoutfont.
297 This is what is stored in the fonttable
300 getFontSettings(BufferParams const &, pos_type pos) const;
302 Font const & getFirstFontSettings(BufferParams const &) const;
304 /** Get fully instantiated font. If pos == -1, use the layout
305 font attached to this paragraph.
306 If pos == -2, use the label font of the layout attached here.
307 In all cases, the font is instantiated, i.e. does not have any
308 attributes with values FONT_INHERIT, FONT_IGNORE or
311 Font const getFont(BufferParams const &, pos_type pos,
312 Font const & outerfont) const;
313 Font const getLayoutFont(BufferParams const &,
314 Font const & outerfont) const;
315 Font const getLabelFont(BufferParams const &,
316 Font const & outerfont) const;
318 * The font returned by the above functions is the same in a
319 * span of characters. This method will return the first and
320 * the last positions in the paragraph for which that font is
321 * the same. This can be used to avoid unnecessary calls to getFont.
323 FontSpan fontSpan(pos_type pos) const;
325 char_type getChar(pos_type pos) const;
326 /// Get the char, but mirror all bracket characters if it is right-to-left
327 char_type getUChar(BufferParams const &, pos_type pos) const;
328 /// pos <= size() (there is a dummy font change at the end of each par)
329 void setFont(pos_type pos, Font const & font);
330 /// Returns the height of the highest font in range
331 FontSize highestFontInRange(pos_type startpos,
332 pos_type endpos, FontSize def_size) const;
334 void insert(pos_type pos, docstring const & str,
335 Font const & font, Change const & change);
338 void appendString(docstring const & s, Font const & font,
339 Change const & change);
341 void appendChar(char_type c, Font const & font, Change const & change);
343 void insertChar(pos_type pos, char_type c, bool trackChanges);
345 void insertChar(pos_type pos, char_type c,
346 Font const &, bool trackChanges);
348 void insertChar(pos_type pos, char_type c,
349 Font const &, Change const & change);
350 /// Insert \p inset at position \p pos with \p change traking status.
351 /// \return true if successful.
352 bool insertInset(pos_type pos, Inset * inset,
353 Change const & change);
354 /// Insert \p inset at position \p pos with \p change traking status and
356 /// \return true if successful.
357 bool insertInset(pos_type pos, Inset * inset,
358 Font const & font, Change const & change);
360 Inset * getInset(pos_type pos);
362 Inset const * getInset(pos_type pos) const;
364 /// Release inset at given position.
365 /// \warning does not honour change tracking!
366 /// Therefore, it should only be used for breaking and merging
368 Inset * releaseInset(pos_type pos);
371 InsetList const & insetList() const;
373 void setBuffer(Buffer &);
376 bool isHfill(pos_type pos) const;
378 /// hinted by profiler
379 bool isInset(pos_type pos) const;
381 bool isNewline(pos_type pos) const;
382 /// return true if the char is a word separator
383 bool isSeparator(pos_type pos) const;
385 bool isLineSeparator(pos_type pos) const;
386 /// True if the character/inset at this point is a word separator.
387 /// Note that digits in particular are not considered as word separator.
388 bool isWordSeparator(pos_type pos) const;
389 /// True if the element at this point is a character that is not a letter.
390 bool isChar(pos_type pos) const;
391 /// True if the element at this point is a space
392 bool isSpace(pos_type pos) const;
394 /// returns true if at least one line break or line separator has been deleted
395 /// at the beginning of the paragraph (either physically or logically)
396 bool stripLeadingSpaces(bool trackChanges);
398 /// return true if we allow multiple spaces
399 bool isFreeSpacing() const;
401 /// return true if we allow this par to stay empty
402 bool allowEmpty() const;
404 char_type transformChar(char_type c, pos_type pos) const;
406 ParagraphParameters & params();
408 ParagraphParameters const & params() const;
410 /// Check if we are in a Biblio environment and insert or
411 /// delete InsetBibitems as necessary.
412 /// \retval int 1, if we had to add an inset, in which case
413 /// the cursor will need to move cursor forward; -pos, if we deleted
414 /// an inset, in which case pos is the position from which the inset
415 /// was deleted, and the cursor will need to be moved back one if it
416 /// was previously past that position. Return 0 otherwise.
417 int checkBiblio(Buffer const & buffer);
419 /// For each author, set 'used' to true if there is a change
420 /// by this author in the paragraph.
421 void checkAuthors(AuthorList const & authorList);
424 void changeCase(BufferParams const & bparams, pos_type pos,
425 pos_type & right, TextCase action);
427 /// find \param str string inside Paragraph.
428 /// \return non-zero if the specified string is at the specified
429 /// position; returned value is the actual match length in positions
430 /// \param del specifies whether deleted strings in ct mode will be considered
432 docstring const & str, ///< string to search
435 pos_type pos, ///< start from here.
436 bool del = true) const;
438 void locateWord(pos_type & from, pos_type & to,
439 word_location const loc) const;
443 /// Spellcheck word at position \p from and fill in found misspelled word
444 /// and \p suggestions if \p do_suggestion is true.
445 /// \return result from spell checker, SpellChecker::UNKNOWN_WORD when misspelled.
446 SpellChecker::Result spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
447 docstring_list & suggestions, bool do_suggestion = true,
448 bool check_learned = false) const;
450 /// Spell checker status at position \p pos.
451 /// \return true if pointed position is misspelled.
452 bool isMisspelled(pos_type pos) const;
454 /// spell check of whole paragraph
455 /// remember results until call of requestSpellCheck()
456 void spellCheck() const;
458 /// query state of spell checker results
459 bool needsSpellCheck() const;
460 /// mark position of text manipulation to inform the spell checker
461 /// default value -1 marks the whole paragraph to be checked (again)
462 void requestSpellCheck(pos_type pos = -1);
464 /// an automatically generated identifying label for this paragraph.
465 /// presently used only in the XHTML output routines.
466 std::string magicLabel() const;
469 /// Expand the counters for the labelstring of \c layout
470 docstring expandParagraphLabel(Layout const &, BufferParams const &,
471 bool process_appendix) const;
473 void deregisterWords();
477 void registerWords();
482 friend class Paragraph::Private;
489 #endif // PARAGRAPH_H