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.
109 /// A Paragraph holds all text, attributes and insets in a text paragraph
115 /// Copy constructor.
116 Paragraph(Paragraph const &);
117 /// Partial copy constructor.
118 /// Copy the Paragraph contents from \p beg to \p end (without end).
119 Paragraph(Paragraph const & par, pos_type beg, pos_type end);
121 Paragraph & operator=(Paragraph const &);
130 void addChangesToToc(DocIterator const & cdit, Buffer const & buf) const;
132 Language const * getParLanguage(BufferParams const &) const;
134 bool isRTL(BufferParams const &) const;
136 void changeLanguage(BufferParams const & bparams,
137 Language const * from, Language const * to);
139 bool isMultiLingual(BufferParams const &) const;
141 void getLanguages(std::set<Language const *> &) const;
143 /// Convert the paragraph to a string.
144 /// \param AsStringParameter options. This can contain any combination of
145 /// asStringParameter values. Valid examples:
146 /// asString(AS_STR_LABEL)
147 /// asString(AS_STR_LABEL | AS_STR_INSETS)
148 /// asString(AS_STR_INSETS)
149 docstring asString(int options = AS_STR_NONE) const;
151 docstring asString(pos_type beg, pos_type end,
152 int options = AS_STR_NONE) const;
154 /// Extract only the explicitly visible text (without any formatting),
155 /// descending into insets
156 docstring stringify(pos_type beg, pos_type end, int options, OutputParams & runparams) const;
159 void write(std::ostream &, BufferParams const &,
160 depth_type & depth) const;
162 void validate(LaTeXFeatures &) const;
164 /// \param force means: output even if layout.inpreamble is true.
165 void latex(BufferParams const &, Font const & outerfont, odocstream &,
166 TexRow & texrow, OutputParams const &,
167 int start_pos = 0, int end_pos = -1, bool force = false) const;
169 /// Can we drop the standard paragraph wrapper?
170 bool emptyTag() const;
172 /// Get the id of the paragraph, usefull for docbook
173 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
175 /// Output the first word of a paragraph, return the position where it left.
176 pos_type firstWordDocBook(odocstream & os, OutputParams const & runparams) const;
178 /// Output the first word of a paragraph, return the position where it left.
179 pos_type firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams) const;
181 /// Writes to stream the docbook representation
182 void simpleDocBookOnePar(Buffer const & buf,
184 OutputParams const & runparams,
185 Font const & outerfont,
186 pos_type initial = 0) const;
187 /// \return any material that has had to be deferred until after the
188 /// paragraph has closed.
189 docstring simpleLyXHTMLOnePar(Buffer const & buf,
191 OutputParams const & runparams,
192 Font const & outerfont,
193 pos_type initial = 0) const;
196 bool hasSameLayout(Paragraph const & par) const;
199 void makeSameLayout(Paragraph const & par);
202 void setInsetOwner(Inset const * inset);
204 Inset const & inInset() const;
206 bool allowParagraphCustomization() const;
208 bool usePlainLayout() const;
210 pos_type size() const;
215 Layout const & layout() const;
216 /// Do not pass a temporary to this!
217 void setLayout(Layout const & layout);
219 void setPlainOrDefaultLayout(DocumentClass const & tc);
221 void setDefaultLayout(DocumentClass const & tc);
223 void setPlainLayout(DocumentClass const & tc);
225 /// This is the item depth, only used by enumerate and itemize
226 signed char itemdepth;
228 /// look up change at given pos
229 Change const & lookupChange(pos_type pos) const;
231 /// is there a change within the given range ?
232 bool isChanged(pos_type start, pos_type end) const;
233 /// is there an unchanged char at the given pos ?
234 bool isChanged(pos_type pos) const;
235 /// is there an insertion at the given pos ?
236 bool isInserted(pos_type pos) const;
237 /// is there a deletion at the given pos ?
238 bool isDeleted(pos_type pos) const;
239 /// is the whole paragraph deleted ?
240 bool isDeleted(pos_type start, pos_type end) const;
242 /// will the paragraph be physically merged with the next
243 /// one if the imaginary end-of-par character is logically deleted?
244 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
246 /// set change for the entire par
247 void setChange(Change const & change);
249 /// set change at given pos
250 void setChange(pos_type pos, Change const & change);
252 /// accept changes within the given range
253 void acceptChanges(pos_type start, pos_type end);
255 /// reject changes within the given range
256 void rejectChanges(pos_type start, pos_type end);
258 /// Paragraphs can contain "manual labels", for example, Description
259 /// environment. The text for this user-editable label is stored in
260 /// the paragraph alongside the text of the rest of the paragraph
261 /// (the body). This function returns the starting position of the
262 /// body of the text in the paragraph.
263 pos_type beginOfBody() const;
264 /// recompute this value
265 void setBeginOfBody();
268 docstring expandLabel(Layout const &, BufferParams const &) const;
270 docstring expandDocBookLabel(Layout const &, BufferParams const &) const;
272 docstring const & labelString() const;
273 /// the next two functions are for the manual labels
274 docstring const getLabelWidthString() const;
275 /// Set label width string.
276 void setLabelWidthString(docstring const & s);
277 /// Actual paragraph alignment used
278 char getAlign() const;
279 /// The nesting depth of a paragraph
280 depth_type getDepth() const;
281 /// The maximal possible depth of a paragraph after this one
282 depth_type getMaxDepthAfter() const;
284 void applyLayout(Layout const & new_layout);
286 /// (logically) erase the char at pos; return true if it was actually erased
287 bool eraseChar(pos_type pos, bool trackChanges);
288 /// (logically) erase the given range; return the number of chars actually erased
289 int eraseChars(pos_type start, pos_type end, bool trackChanges);
292 void resetFonts(Font const & font);
294 /** Get uninstantiated font setting. Returns the difference
295 between the characters font and the layoutfont.
296 This is what is stored in the fonttable
299 getFontSettings(BufferParams const &, pos_type pos) const;
301 Font const & getFirstFontSettings(BufferParams const &) const;
303 /** Get fully instantiated font. If pos == -1, use the layout
304 font attached to this paragraph.
305 If pos == -2, use the label font of the layout attached here.
306 In all cases, the font is instantiated, i.e. does not have any
307 attributes with values FONT_INHERIT, FONT_IGNORE or
310 Font const getFont(BufferParams const &, pos_type pos,
311 Font const & outerfont) const;
312 Font const getLayoutFont(BufferParams const &,
313 Font const & outerfont) const;
314 Font const getLabelFont(BufferParams const &,
315 Font const & outerfont) const;
317 * The font returned by the above functions is the same in a
318 * span of characters. This method will return the first and
319 * the last positions in the paragraph for which that font is
320 * the same. This can be used to avoid unnecessary calls to getFont.
322 FontSpan fontSpan(pos_type pos) const;
324 char_type getChar(pos_type pos) const;
325 /// Get the char, but mirror all bracket characters if it is right-to-left
326 char_type getUChar(BufferParams const &, pos_type pos) const;
327 /// pos <= size() (there is a dummy font change at the end of each par)
328 void setFont(pos_type pos, Font const & font);
329 /// Returns the height of the highest font in range
330 FontSize highestFontInRange(pos_type startpos,
331 pos_type endpos, FontSize def_size) const;
333 void insert(pos_type pos, docstring const & str,
334 Font const & font, Change const & change);
337 void appendString(docstring const & s, Font const & font,
338 Change const & change);
340 void appendChar(char_type c, Font const & font, Change const & change);
342 void insertChar(pos_type pos, char_type c, bool trackChanges);
344 void insertChar(pos_type pos, char_type c,
345 Font const &, bool trackChanges);
347 void insertChar(pos_type pos, char_type c,
348 Font const &, Change const & change);
349 /// Insert \p inset at position \p pos with \p change traking status.
350 /// \return true if successful.
351 bool insertInset(pos_type pos, Inset * inset,
352 Change const & change);
353 /// Insert \p inset at position \p pos with \p change traking status and
355 /// \return true if successful.
356 bool insertInset(pos_type pos, Inset * inset,
357 Font const & font, Change const & change);
359 Inset * getInset(pos_type pos);
361 Inset const * getInset(pos_type pos) const;
363 /// Release inset at given position.
364 /// \warning does not honour change tracking!
365 /// Therefore, it should only be used for breaking and merging
367 Inset * releaseInset(pos_type pos);
370 InsetList const & insetList() const;
372 void setBuffer(Buffer &);
375 bool isHfill(pos_type pos) const;
377 /// hinted by profiler
378 bool isInset(pos_type pos) const;
380 bool isNewline(pos_type pos) const;
381 /// return true if the char is a word separator
382 bool isSeparator(pos_type pos) const;
384 bool isLineSeparator(pos_type pos) const;
385 /// True if the character/inset at this point is a word separator.
386 /// Note that digits in particular are not considered as word separator.
387 bool isWordSeparator(pos_type pos) const;
388 /// True if the element at this point is a character that is not a letter.
389 bool isChar(pos_type pos) const;
390 /// True if the element at this point is a space
391 bool isSpace(pos_type pos) const;
393 /// returns true if at least one line break or line separator has been deleted
394 /// at the beginning of the paragraph (either physically or logically)
395 bool stripLeadingSpaces(bool trackChanges);
397 /// return true if we allow multiple spaces
398 bool isFreeSpacing() const;
400 /// return true if we allow this par to stay empty
401 bool allowEmpty() const;
403 char_type transformChar(char_type c, pos_type pos) const;
405 ParagraphParameters & params();
407 ParagraphParameters const & params() const;
409 /// Check if we are in a Biblio environment and insert or
410 /// delete InsetBibitems as necessary.
411 /// \retval int 1, if we had to add an inset, in which case
412 /// the cursor will need to move cursor forward; -pos, if we deleted
413 /// an inset, in which case pos is the position from which the inset
414 /// was deleted, and the cursor will need to be moved back one if it
415 /// was previously past that position. Return 0 otherwise.
416 int checkBiblio(Buffer const & buffer);
418 /// For each author, set 'used' to true if there is a change
419 /// by this author in the paragraph.
420 void checkAuthors(AuthorList const & authorList);
423 void changeCase(BufferParams const & bparams, pos_type pos,
424 pos_type & right, TextCase action);
426 /// find \param str string inside Paragraph.
427 /// \return non-zero if the specified string is at the specified
428 /// position; returned value is the actual match length in positions
429 /// \param del specifies whether deleted strings in ct mode will be considered
431 docstring const & str, ///< string to search
434 pos_type pos, ///< start from here.
435 bool del = true) const;
437 void locateWord(pos_type & from, pos_type & to,
438 word_location const loc) const;
442 /// Spellcheck word at position \p from and fill in found misspelled word
443 /// and \p suggestions if \p do_suggestion is true.
444 /// \return result from spell checker, SpellChecker::UNKNOWN_WORD when misspelled.
445 SpellChecker::Result spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
446 docstring_list & suggestions, bool do_suggestion = true,
447 bool check_learned = false) const;
449 /// Spell checker status at position \p pos.
450 /// \return true if pointed position is misspelled.
451 bool isMisspelled(pos_type pos) const;
453 /// spell check of whole paragraph
454 /// remember results until call of requestSpellCheck()
455 void spellCheck() const;
457 /// query state of spell checker results
458 bool needsSpellCheck() const;
459 /// mark position of text manipulation to inform the spell checker
460 /// default value -1 marks the whole paragraph to be checked (again)
461 void requestSpellCheck(pos_type pos = -1);
463 /// an automatically generated identifying label for this paragraph.
464 /// presently used only in the XHTML output routines.
465 std::string magicLabel() const;
468 /// Expand the counters for the labelstring of \c layout
469 docstring expandParagraphLabel(Layout const &, BufferParams const &,
470 bool process_appendix) const;
472 void deregisterWords();
476 void registerWords();
481 friend class Paragraph::Private;
488 #endif // PARAGRAPH_H