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"
21 #include "insets/InsetCode.h"
23 #include "support/strfwd.h"
24 #include "support/types.h"
52 class ParagraphParameters;
60 /// Invalid font span containing no character
61 FontSpan() : first(0), last(-1) {}
62 /// Span including first and last
63 FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
66 /// Range including first and last.
75 text_capitalization = 1,
82 enum AsStringParameter
84 AS_STR_NONE = 0, ///< No option, only printable characters.
85 AS_STR_LABEL = 1, ///< Prefix with paragraph label.
86 AS_STR_INSETS = 2, ///< Go into insets.
87 AS_STR_NEWLINES = 4 ///< Get also newline characters.
91 /// A Paragraph holds all text, attributes and insets in a text paragraph
98 Paragraph(Paragraph const &);
99 /// Partial copy constructor.
100 /// Copy the Paragraph contents from \p beg to \p end (without end).
101 Paragraph(Paragraph const & par, pos_type beg, pos_type end);
103 Paragraph & operator=(Paragraph const &);
112 void addChangesToToc(DocIterator const & cdit, Buffer const & buf) const;
114 Language const * getParLanguage(BufferParams const &) const;
116 bool isRTL(BufferParams const &) const;
118 void changeLanguage(BufferParams const & bparams,
119 Language const * from, Language const * to);
121 bool isMultiLingual(BufferParams const &) const;
123 void getLanguages(std::set<Language const *> &) const;
125 /// Convert the paragraph to a string.
126 /// \param AsStringParameter options. This can contain any combination of
127 /// asStringParameter values. Valid examples:
128 /// asString(AS_STR_LABEL)
129 /// asString(AS_STR_LABEL | AS_STR_INSETS)
130 /// asString(AS_STR_INSETS)
131 docstring asString(int options = AS_STR_NONE) const;
133 docstring asString(pos_type beg, pos_type end,
134 int options = AS_STR_NONE) const;
136 /// Extract only the explicitly visible text (without any formatting),
137 /// descending into insets
138 docstring stringify(pos_type beg, pos_type end, int options, OutputParams & runparams) const;
141 void write(std::ostream &, BufferParams const &,
142 depth_type & depth) const;
144 void validate(LaTeXFeatures &) const;
147 bool latex(BufferParams const &, Font const & outerfont, odocstream &,
148 TexRow & texrow, OutputParams const &,
149 int start_pos = 0, int end_pos = -1) const;
151 /// Can we drop the standard paragraph wrapper?
152 bool emptyTag() const;
154 /// Get the id of the paragraph, usefull for docbook
155 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
157 /// Output the first word of a paragraph, return the position where it left.
158 pos_type firstWordDocBook(odocstream & os, OutputParams const & runparams) const;
160 /// Output the first word of a paragraph, return the position where it left.
161 pos_type firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams) const;
163 /// Writes to stream the docbook representation
164 void simpleDocBookOnePar(Buffer const & buf,
166 OutputParams const & runparams,
167 Font const & outerfont,
168 pos_type initial = 0) const;
169 /// \return any material that has had to be deferred until after the
170 /// paragraph has closed.
171 docstring simpleLyXHTMLOnePar(Buffer const & buf,
173 OutputParams const & runparams,
174 Font const & outerfont,
175 pos_type initial = 0) const;
178 bool hasSameLayout(Paragraph const & par) const;
181 void makeSameLayout(Paragraph const & par);
184 void setInsetOwner(Inset const * inset);
186 Inset const & inInset() const;
188 bool allowParagraphCustomization() const;
190 bool usePlainLayout() const;
192 pos_type size() const;
197 Layout const & layout() const;
198 /// Do not pass a temporary to this!
199 void setLayout(Layout const & layout);
201 void setPlainOrDefaultLayout(DocumentClass const & tc);
203 void setDefaultLayout(DocumentClass const & tc);
205 void setPlainLayout(DocumentClass const & tc);
207 /// This is the item depth, only used by enumerate and itemize
208 signed char itemdepth;
210 /// look up change at given pos
211 Change const & lookupChange(pos_type pos) const;
213 /// is there a change within the given range ?
214 bool isChanged(pos_type start, pos_type end) const;
215 /// is there an unchanged char at the given pos ?
216 bool isChanged(pos_type pos) const;
217 /// is there an insertion at the given pos ?
218 bool isInserted(pos_type pos) const;
219 /// is there a deletion at the given pos ?
220 bool isDeleted(pos_type pos) const;
221 /// is the whole paragraph deleted ?
222 bool isDeleted(pos_type start, pos_type end) const;
224 /// will the paragraph be physically merged with the next
225 /// one if the imaginary end-of-par character is logically deleted?
226 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
228 /// set change for the entire par
229 void setChange(Change const & change);
231 /// set change at given pos
232 void setChange(pos_type pos, Change const & change);
234 /// accept changes within the given range
235 void acceptChanges(pos_type start, pos_type end);
237 /// reject changes within the given range
238 void rejectChanges(pos_type start, pos_type end);
240 /// Paragraphs can contain "manual labels", for example, Description
241 /// environment. The text for this user-editable label is stored in
242 /// the paragraph alongside the text of the rest of the paragraph
243 /// (the body). This function returns the starting position of the
244 /// body of the text in the paragraph.
245 pos_type beginOfBody() const;
246 /// recompute this value
247 void setBeginOfBody();
250 docstring expandLabel(Layout const &, BufferParams const &) const;
252 docstring expandDocBookLabel(Layout const &, BufferParams const &) const;
254 docstring const & labelString() const;
255 /// the next two functions are for the manual labels
256 docstring const getLabelWidthString() const;
257 /// Set label width string.
258 void setLabelWidthString(docstring const & s);
259 /// Actual paragraph alignment used
260 char getAlign() const;
261 /// The nesting depth of a paragraph
262 depth_type getDepth() const;
263 /// The maximal possible depth of a paragraph after this one
264 depth_type getMaxDepthAfter() const;
266 void applyLayout(Layout const & new_layout);
268 /// (logically) erase the char at pos; return true if it was actually erased
269 bool eraseChar(pos_type pos, bool trackChanges);
270 /// (logically) erase the given range; return the number of chars actually erased
271 int eraseChars(pos_type start, pos_type end, bool trackChanges);
274 void resetFonts(Font const & font);
276 /** Get uninstantiated font setting. Returns the difference
277 between the characters font and the layoutfont.
278 This is what is stored in the fonttable
281 getFontSettings(BufferParams const &, pos_type pos) const;
283 Font const & getFirstFontSettings(BufferParams const &) const;
285 /** Get fully instantiated font. If pos == -1, use the layout
286 font attached to this paragraph.
287 If pos == -2, use the label font of the layout attached here.
288 In all cases, the font is instantiated, i.e. does not have any
289 attributes with values FONT_INHERIT, FONT_IGNORE or
292 Font const getFont(BufferParams const &, pos_type pos,
293 Font const & outerfont) const;
294 Font const getLayoutFont(BufferParams const &,
295 Font const & outerfont) const;
296 Font const getLabelFont(BufferParams const &,
297 Font const & outerfont) const;
299 * The font returned by the above functions is the same in a
300 * span of characters. This method will return the first and
301 * the last positions in the paragraph for which that font is
302 * the same. This can be used to avoid unnecessary calls to getFont.
304 FontSpan fontSpan(pos_type pos) const;
306 char_type getChar(pos_type pos) const;
307 /// Get the char, but mirror all bracket characters if it is right-to-left
308 char_type getUChar(BufferParams const &, pos_type pos) const;
309 /// pos <= size() (there is a dummy font change at the end of each par)
310 void setFont(pos_type pos, Font const & font);
311 /// Returns the height of the highest font in range
312 FontSize highestFontInRange(pos_type startpos,
313 pos_type endpos, FontSize def_size) const;
315 void insert(pos_type pos, docstring const & str,
316 Font const & font, Change const & change);
319 void appendString(docstring const & s, Font const & font,
320 Change const & change);
322 void appendChar(char_type c, Font const & font, Change const & change);
324 void insertChar(pos_type pos, char_type c, bool trackChanges);
326 void insertChar(pos_type pos, char_type c,
327 Font const &, bool trackChanges);
329 void insertChar(pos_type pos, char_type c,
330 Font const &, Change const & change);
331 /// Insert \p inset at position \p pos with \p change traking status.
332 /// \return true if successful.
333 bool insertInset(pos_type pos, Inset * inset,
334 Change const & change);
335 /// Insert \p inset at position \p pos with \p change traking status and
337 /// \return true if successful.
338 bool insertInset(pos_type pos, Inset * inset,
339 Font const & font, Change const & change);
341 Inset * getInset(pos_type pos);
343 Inset const * getInset(pos_type pos) const;
345 /// Release inset at given position.
346 /// \warning does not honour change tracking!
347 /// Therefore, it should only be used for breaking and merging
349 Inset * releaseInset(pos_type pos);
352 InsetList const & insetList() const;
354 void setBuffer(Buffer &);
357 bool isHfill(pos_type pos) const;
359 /// hinted by profiler
360 bool isInset(pos_type pos) const;
362 bool isNewline(pos_type pos) const;
363 /// return true if the char is a word separator
364 bool isSeparator(pos_type pos) const;
366 bool isLineSeparator(pos_type pos) const;
367 /// True if the character/inset at this point is a word separator.
368 /// Note that digits in particular are not considered as word separator.
369 bool isWordSeparator(pos_type pos) const;
370 /// True if the element at this point is a character that is not a letter.
371 bool isChar(pos_type pos) const;
372 /// True if the element at this point is a space
373 bool isSpace(pos_type pos) const;
375 /// returns true if at least one line break or line separator has been deleted
376 /// at the beginning of the paragraph (either physically or logically)
377 bool stripLeadingSpaces(bool trackChanges);
379 /// return true if we allow multiple spaces
380 bool isFreeSpacing() const;
382 /// return true if we allow this par to stay empty
383 bool allowEmpty() const;
385 char_type transformChar(char_type c, pos_type pos) const;
387 ParagraphParameters & params();
389 ParagraphParameters const & params() const;
391 /// Check if we are in a Biblio environment and insert or
392 /// delete InsetBibitems as necessary.
393 /// \retval int 1, if we had to add an inset, in which case
394 /// the cursor will need to move cursor forward; -pos, if we deleted
395 /// an inset, in which case pos is the position from which the inset
396 /// was deleted, and the cursor will need to be moved back one if it
397 /// was previously past that position. Return 0 otherwise.
398 int checkBiblio(Buffer const & buffer);
400 /// For each author, set 'used' to true if there is a change
401 /// by this author in the paragraph.
402 void checkAuthors(AuthorList const & authorList);
405 void changeCase(BufferParams const & bparams, pos_type pos,
406 pos_type & right, TextCase action);
408 /// find \param str string inside Paragraph.
409 /// \return true if the specified string is at the specified position
410 /// \param del specifies whether deleted strings in ct mode will be considered
412 docstring const & str, ///< string to search
415 pos_type pos, ///< start from here.
416 bool del = true) const;
418 void locateWord(pos_type & from, pos_type & to,
419 word_location const loc) const;
423 /// Spellcheck word at position \p from and fill in found misspelled word
424 /// and \p suggestions if \p do_suggestion is true.
425 /// \return true if pointed word is misspelled.
426 bool spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
427 docstring_list & suggestions, bool do_suggestion = true) const;
429 /// Spellcheck word at position \p pos.
430 /// \return true if pointed word is misspelled.
431 bool isMisspelled(pos_type pos) const;
432 /// an automatically generated identifying label for this paragraph.
433 /// presently used only in the XHTML output routines.
434 std::string magicLabel() const;
437 /// Expand the counters for the labelstring of \c layout
438 docstring expandParagraphLabel(Layout const &, BufferParams const &,
439 bool process_appendix) const;
441 void deregisterWords();
445 void registerWords();
450 friend class Paragraph::Private;
457 #endif // PARAGRAPH_H