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;
88 text_capitalization = 1,
95 enum AsStringParameter
97 AS_STR_NONE = 0, ///< No option, only printable characters.
98 AS_STR_LABEL = 1, ///< Prefix with paragraph label.
99 AS_STR_INSETS = 2, ///< Go into insets.
100 AS_STR_NEWLINES = 4 ///< Get also newline characters.
104 /// A Paragraph holds all text, attributes and insets in a text paragraph
110 /// Copy constructor.
111 Paragraph(Paragraph const &);
112 /// Partial copy constructor.
113 /// Copy the Paragraph contents from \p beg to \p end (without end).
114 Paragraph(Paragraph const & par, pos_type beg, pos_type end);
116 Paragraph & operator=(Paragraph const &);
125 void addChangesToToc(DocIterator const & cdit, Buffer const & buf) const;
127 Language const * getParLanguage(BufferParams const &) const;
129 bool isRTL(BufferParams const &) const;
131 void changeLanguage(BufferParams const & bparams,
132 Language const * from, Language const * to);
134 bool isMultiLingual(BufferParams const &) const;
136 void getLanguages(std::set<Language const *> &) const;
138 /// Convert the paragraph to a string.
139 /// \param AsStringParameter options. This can contain any combination of
140 /// asStringParameter values. Valid examples:
141 /// asString(AS_STR_LABEL)
142 /// asString(AS_STR_LABEL | AS_STR_INSETS)
143 /// asString(AS_STR_INSETS)
144 docstring asString(int options = AS_STR_NONE) const;
146 docstring asString(pos_type beg, pos_type end,
147 int options = AS_STR_NONE) const;
149 /// Extract only the explicitly visible text (without any formatting),
150 /// descending into insets
151 docstring stringify(pos_type beg, pos_type end, int options, OutputParams & runparams) const;
154 void write(std::ostream &, BufferParams const &,
155 depth_type & depth) const;
157 void validate(LaTeXFeatures &) const;
159 /// \param force means: output even if layout.inpreamble is true.
160 void latex(BufferParams const &, Font const & outerfont, odocstream &,
161 TexRow & texrow, OutputParams const &,
162 int start_pos = 0, int end_pos = -1, bool force = false) const;
164 /// Can we drop the standard paragraph wrapper?
165 bool emptyTag() const;
167 /// Get the id of the paragraph, usefull for docbook
168 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
170 /// Output the first word of a paragraph, return the position where it left.
171 pos_type firstWordDocBook(odocstream & os, OutputParams const & runparams) const;
173 /// Output the first word of a paragraph, return the position where it left.
174 pos_type firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams) const;
176 /// Writes to stream the docbook representation
177 void simpleDocBookOnePar(Buffer const & buf,
179 OutputParams const & runparams,
180 Font const & outerfont,
181 pos_type initial = 0) const;
182 /// \return any material that has had to be deferred until after the
183 /// paragraph has closed.
184 docstring simpleLyXHTMLOnePar(Buffer const & buf,
186 OutputParams const & runparams,
187 Font const & outerfont,
188 pos_type initial = 0) const;
191 bool hasSameLayout(Paragraph const & par) const;
194 void makeSameLayout(Paragraph const & par);
197 void setInsetOwner(Inset const * inset);
199 Inset const & inInset() const;
201 bool allowParagraphCustomization() const;
203 bool usePlainLayout() const;
205 pos_type size() const;
210 Layout const & layout() const;
211 /// Do not pass a temporary to this!
212 void setLayout(Layout const & layout);
214 void setPlainOrDefaultLayout(DocumentClass const & tc);
216 void setDefaultLayout(DocumentClass const & tc);
218 void setPlainLayout(DocumentClass const & tc);
220 /// This is the item depth, only used by enumerate and itemize
221 signed char itemdepth;
223 /// look up change at given pos
224 Change const & lookupChange(pos_type pos) const;
226 /// is there a change within the given range ?
227 bool isChanged(pos_type start, pos_type end) const;
228 /// is there an unchanged char at the given pos ?
229 bool isChanged(pos_type pos) const;
230 /// is there an insertion at the given pos ?
231 bool isInserted(pos_type pos) const;
232 /// is there a deletion at the given pos ?
233 bool isDeleted(pos_type pos) const;
234 /// is the whole paragraph deleted ?
235 bool isDeleted(pos_type start, pos_type end) const;
237 /// will the paragraph be physically merged with the next
238 /// one if the imaginary end-of-par character is logically deleted?
239 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
241 /// set change for the entire par
242 void setChange(Change const & change);
244 /// set change at given pos
245 void setChange(pos_type pos, Change const & change);
247 /// accept changes within the given range
248 void acceptChanges(pos_type start, pos_type end);
250 /// reject changes within the given range
251 void rejectChanges(pos_type start, pos_type end);
253 /// Paragraphs can contain "manual labels", for example, Description
254 /// environment. The text for this user-editable label is stored in
255 /// the paragraph alongside the text of the rest of the paragraph
256 /// (the body). This function returns the starting position of the
257 /// body of the text in the paragraph.
258 pos_type beginOfBody() const;
259 /// recompute this value
260 void setBeginOfBody();
263 docstring expandLabel(Layout const &, BufferParams const &) const;
265 docstring expandDocBookLabel(Layout const &, BufferParams const &) const;
267 docstring const & labelString() const;
268 /// the next two functions are for the manual labels
269 docstring const getLabelWidthString() const;
270 /// Set label width string.
271 void setLabelWidthString(docstring const & s);
272 /// Actual paragraph alignment used
273 char getAlign() const;
274 /// The nesting depth of a paragraph
275 depth_type getDepth() const;
276 /// The maximal possible depth of a paragraph after this one
277 depth_type getMaxDepthAfter() const;
279 void applyLayout(Layout const & new_layout);
281 /// (logically) erase the char at pos; return true if it was actually erased
282 bool eraseChar(pos_type pos, bool trackChanges);
283 /// (logically) erase the given range; return the number of chars actually erased
284 int eraseChars(pos_type start, pos_type end, bool trackChanges);
287 void resetFonts(Font const & font);
289 /** Get uninstantiated font setting. Returns the difference
290 between the characters font and the layoutfont.
291 This is what is stored in the fonttable
294 getFontSettings(BufferParams const &, pos_type pos) const;
296 Font const & getFirstFontSettings(BufferParams const &) const;
298 /** Get fully instantiated font. If pos == -1, use the layout
299 font attached to this paragraph.
300 If pos == -2, use the label font of the layout attached here.
301 In all cases, the font is instantiated, i.e. does not have any
302 attributes with values FONT_INHERIT, FONT_IGNORE or
305 Font const getFont(BufferParams const &, pos_type pos,
306 Font const & outerfont) const;
307 Font const getLayoutFont(BufferParams const &,
308 Font const & outerfont) const;
309 Font const getLabelFont(BufferParams const &,
310 Font const & outerfont) const;
312 * The font returned by the above functions is the same in a
313 * span of characters. This method will return the first and
314 * the last positions in the paragraph for which that font is
315 * the same. This can be used to avoid unnecessary calls to getFont.
317 FontSpan fontSpan(pos_type pos) const;
319 char_type getChar(pos_type pos) const;
320 /// Get the char, but mirror all bracket characters if it is right-to-left
321 char_type getUChar(BufferParams const &, pos_type pos) const;
322 /// pos <= size() (there is a dummy font change at the end of each par)
323 void setFont(pos_type pos, Font const & font);
324 /// Returns the height of the highest font in range
325 FontSize highestFontInRange(pos_type startpos,
326 pos_type endpos, FontSize def_size) const;
328 void insert(pos_type pos, docstring const & str,
329 Font const & font, Change const & change);
332 void appendString(docstring const & s, Font const & font,
333 Change const & change);
335 void appendChar(char_type c, Font const & font, Change const & change);
337 void insertChar(pos_type pos, char_type c, bool trackChanges);
339 void insertChar(pos_type pos, char_type c,
340 Font const &, bool trackChanges);
342 void insertChar(pos_type pos, char_type c,
343 Font const &, Change const & change);
344 /// Insert \p inset at position \p pos with \p change traking status.
345 /// \return true if successful.
346 bool insertInset(pos_type pos, Inset * inset,
347 Change const & change);
348 /// Insert \p inset at position \p pos with \p change traking status and
350 /// \return true if successful.
351 bool insertInset(pos_type pos, Inset * inset,
352 Font const & font, Change const & change);
354 Inset * getInset(pos_type pos);
356 Inset const * getInset(pos_type pos) const;
358 /// Release inset at given position.
359 /// \warning does not honour change tracking!
360 /// Therefore, it should only be used for breaking and merging
362 Inset * releaseInset(pos_type pos);
365 InsetList const & insetList() const;
367 void setBuffer(Buffer &);
370 bool isHfill(pos_type pos) const;
372 /// hinted by profiler
373 bool isInset(pos_type pos) const;
375 bool isNewline(pos_type pos) const;
376 /// return true if the char is a word separator
377 bool isSeparator(pos_type pos) const;
379 bool isLineSeparator(pos_type pos) const;
380 /// True if the character/inset at this point is a word separator.
381 /// Note that digits in particular are not considered as word separator.
382 bool isWordSeparator(pos_type pos) const;
383 /// True if the element at this point is a character that is not a letter.
384 bool isChar(pos_type pos) const;
385 /// True if the element at this point is a space
386 bool isSpace(pos_type pos) const;
388 /// returns true if at least one line break or line separator has been deleted
389 /// at the beginning of the paragraph (either physically or logically)
390 bool stripLeadingSpaces(bool trackChanges);
392 /// return true if we allow multiple spaces
393 bool isFreeSpacing() const;
395 /// return true if we allow this par to stay empty
396 bool allowEmpty() const;
398 char_type transformChar(char_type c, pos_type pos) const;
400 ParagraphParameters & params();
402 ParagraphParameters const & params() const;
404 /// Check if we are in a Biblio environment and insert or
405 /// delete InsetBibitems as necessary.
406 /// \retval int 1, if we had to add an inset, in which case
407 /// the cursor will need to move cursor forward; -pos, if we deleted
408 /// an inset, in which case pos is the position from which the inset
409 /// was deleted, and the cursor will need to be moved back one if it
410 /// was previously past that position. Return 0 otherwise.
411 int checkBiblio(Buffer const & buffer);
413 /// For each author, set 'used' to true if there is a change
414 /// by this author in the paragraph.
415 void checkAuthors(AuthorList const & authorList);
418 void changeCase(BufferParams const & bparams, pos_type pos,
419 pos_type & right, TextCase action);
421 /// find \param str string inside Paragraph.
422 /// \return true if the specified string is at the specified position
423 /// \param del specifies whether deleted strings in ct mode will be considered
425 docstring const & str, ///< string to search
428 pos_type pos, ///< start from here.
429 bool del = true) const;
431 void locateWord(pos_type & from, pos_type & to,
432 word_location const loc) const;
436 /// Spellcheck word at position \p from and fill in found misspelled word
437 /// and \p suggestions if \p do_suggestion is true.
438 /// \return result from spell checker, SpellChecker::UNKNOWN_WORD when misspelled.
439 SpellChecker::Result spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
440 docstring_list & suggestions, bool do_suggestion = true,
441 bool check_learned = false) const;
443 /// Spell checker status at position \p pos.
444 /// \return true if pointed position is misspelled.
445 bool isMisspelled(pos_type pos) const;
447 /// spell check of whole paragraph
448 /// remember results until call of requestSpellCheck()
449 void spellCheck() const;
451 /// query state of spell checker results
452 bool needsSpellCheck() const;
453 /// mark position of text manipulation to inform the spell checker
454 /// default value -1 marks the whole paragraph to be checked (again)
455 void requestSpellCheck(pos_type pos = -1);
457 /// an automatically generated identifying label for this paragraph.
458 /// presently used only in the XHTML output routines.
459 std::string magicLabel() const;
462 /// Expand the counters for the labelstring of \c layout
463 docstring expandParagraphLabel(Layout const &, BufferParams const &,
464 bool process_appendix) const;
466 void deregisterWords();
470 void registerWords();
475 friend class Paragraph::Private;
482 #endif // PARAGRAPH_H