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"
22 #include "insets/InsetCode.h"
24 #include "support/strfwd.h"
25 #include "support/types.h"
50 class ParagraphParameters;
58 /// Invalid font span containing no character
59 FontSpan() : first(0), last(-1) {}
60 /// Span including first and last
61 FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
64 /// Range including first and last.
73 text_capitalization = 1,
80 enum AsStringParameter
82 AS_STR_NONE = 0, ///< No option, only printable characters.
83 AS_STR_LABEL = 1, ///< Prefix with paragraph label.
84 AS_STR_INSETS = 2, ///< Go into insets.
85 AS_STR_NEWLINES = 4 ///< Get also newline characters.
89 /// A Paragraph holds all text, attributes and insets in a text paragraph
96 Paragraph(Paragraph const &);
97 /// Partial copy constructor.
98 /// Copy the Paragraph contents from \p beg to \p end (without end).
99 Paragraph(Paragraph const & par, pos_type beg, pos_type end);
101 Paragraph & operator=(Paragraph const &);
108 void addChangesToToc(DocIterator const & cdit, Buffer const & buf) const;
110 Language const * getParLanguage(BufferParams const &) const;
112 bool isRTL(BufferParams const &) const;
114 void changeLanguage(BufferParams const & bparams,
115 Language const * from, Language const * to);
117 bool isMultiLingual(BufferParams const &) const;
119 /// Convert the paragraph to a string.
120 /// \param AsStringParameter options. This can contain any combination of
121 /// asStringParameter values. Valid examples:
122 /// asString(AS_STR_LABEL)
123 /// asString(AS_STR_LABEL | AS_STR_INSETS)
124 /// asString(AS_STR_INSETS)
125 docstring asString(int options = AS_STR_NONE) const;
127 docstring asString(pos_type beg, pos_type end,
128 int options = AS_STR_NONE) const;
130 /// Extract only the explicitly visible text (without any formatting),
131 /// descending into insets
132 docstring stringify(pos_type beg, pos_type end, int options, OutputParams & runparams) const;
135 void write(std::ostream &, BufferParams const &,
136 depth_type & depth) const;
138 void validate(LaTeXFeatures &) const;
141 bool latex(BufferParams const &, Font const & outerfont, odocstream &,
142 TexRow & texrow, OutputParams const &,
143 int start_pos = 0, int end_pos = -1) const;
145 /// Can we drop the standard paragraph wrapper?
146 bool emptyTag() const;
148 /// Get the id of the paragraph, usefull for docbook
149 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
151 /// Output the first word of a paragraph, return the position where it left.
152 pos_type firstWordDocBook(odocstream & os, OutputParams const & runparams) const;
154 /// Output the first word of a paragraph, return the position where it left.
155 pos_type firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams) const;
157 /// Writes to stream the docbook representation
158 void simpleDocBookOnePar(Buffer const & buf,
160 OutputParams const & runparams,
161 Font const & outerfont,
162 pos_type initial = 0) const;
163 /// \return any material that has had to be deferred until after the
164 /// paragraph has closed.
165 docstring simpleLyXHTMLOnePar(Buffer const & buf,
167 OutputParams const & runparams,
168 Font const & outerfont,
170 pos_type initial = 0) const;
173 bool hasSameLayout(Paragraph const & par) const;
176 void makeSameLayout(Paragraph const & par);
179 void setInsetOwner(Inset const * inset);
181 Inset const & inInset() const;
183 bool allowParagraphCustomization() const;
185 bool usePlainLayout() const;
187 pos_type size() const;
192 Layout const & layout() const;
193 /// Do not pass a temporary to this!
194 void setLayout(Layout const & layout);
196 void setPlainOrDefaultLayout(DocumentClass const & tc);
198 void setDefaultLayout(DocumentClass const & tc);
200 void setPlainLayout(DocumentClass const & tc);
202 /// This is the item depth, only used by enumerate and itemize
203 signed char itemdepth;
205 /// look up change at given pos
206 Change const & lookupChange(pos_type pos) const;
208 /// is there a change within the given range ?
209 bool isChanged(pos_type start, pos_type end) const;
210 /// is there an unchanged char at the given pos ?
211 bool isChanged(pos_type pos) const;
212 /// is there an insertion at the given pos ?
213 bool isInserted(pos_type pos) const;
214 /// is there a deletion at the given pos ?
215 bool isDeleted(pos_type pos) const;
216 /// is the whole paragraph deleted ?
217 bool isDeleted(pos_type start, pos_type end) const;
219 /// will the paragraph be physically merged with the next
220 /// one if the imaginary end-of-par character is logically deleted?
221 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
223 /// set change for the entire par
224 void setChange(Change const & change);
226 /// set change at given pos
227 void setChange(pos_type pos, Change const & change);
229 /// accept changes within the given range
230 void acceptChanges(pos_type start, pos_type end);
232 /// reject changes within the given range
233 void rejectChanges(pos_type start, pos_type end);
235 /// Paragraphs can contain "manual labels", for example, Description
236 /// environment. The text for this user-editable label is stored in
237 /// the paragraph alongside the text of the rest of the paragraph
238 /// (the body). This function returns the starting position of the
239 /// body of the text in the paragraph.
240 pos_type beginOfBody() const;
241 /// recompute this value
242 void setBeginOfBody();
245 docstring const & labelString() const;
247 /// the next two functions are for the manual labels
248 docstring const getLabelWidthString() const;
249 /// Set label width string.
250 void setLabelWidthString(docstring const & s);
251 /// Expand the counters for the labelstring of \c layout
252 docstring expandLabel(Layout const &, BufferParams const &,
253 bool process_appendix = true) const;
254 /// Actual paragraph alignment used
255 char getAlign() const;
256 /// The nesting depth of a paragraph
257 depth_type getDepth() const;
258 /// The maximal possible depth of a paragraph after this one
259 depth_type getMaxDepthAfter() const;
261 void applyLayout(Layout const & new_layout);
263 /// (logically) erase the char at pos; return true if it was actually erased
264 bool eraseChar(pos_type pos, bool trackChanges);
265 /// (logically) erase the given range; return the number of chars actually erased
266 int eraseChars(pos_type start, pos_type end, bool trackChanges);
269 void resetFonts(Font const & font);
271 /** Get uninstantiated font setting. Returns the difference
272 between the characters font and the layoutfont.
273 This is what is stored in the fonttable
276 getFontSettings(BufferParams const &, pos_type pos) const;
278 Font const & getFirstFontSettings(BufferParams const &) const;
280 /** Get fully instantiated font. If pos == -1, use the layout
281 font attached to this paragraph.
282 If pos == -2, use the label font of the layout attached here.
283 In all cases, the font is instantiated, i.e. does not have any
284 attributes with values FONT_INHERIT, FONT_IGNORE or
287 Font const getFont(BufferParams const &, pos_type pos,
288 Font const & outerfont) const;
289 Font const getLayoutFont(BufferParams const &,
290 Font const & outerfont) const;
291 Font const getLabelFont(BufferParams const &,
292 Font const & outerfont) const;
294 * The font returned by the above functions is the same in a
295 * span of characters. This method will return the first and
296 * the last positions in the paragraph for which that font is
297 * the same. This can be used to avoid unnecessary calls to getFont.
299 FontSpan fontSpan(pos_type pos) const;
301 char_type getChar(pos_type pos) const;
302 /// Get the char, but mirror all bracket characters if it is right-to-left
303 char_type getUChar(BufferParams const &, pos_type pos) const;
304 /// pos <= size() (there is a dummy font change at the end of each par)
305 void setFont(pos_type pos, Font const & font);
306 /// Returns the height of the highest font in range
307 FontSize highestFontInRange(pos_type startpos,
308 pos_type endpos, FontSize def_size) const;
310 void insert(pos_type pos, docstring const & str,
311 Font const & font, Change const & change);
314 void appendString(docstring const & s, Font const & font,
315 Change const & change);
317 void appendChar(char_type c, Font const & font, Change const & change);
319 void insertChar(pos_type pos, char_type c, bool trackChanges);
321 void insertChar(pos_type pos, char_type c,
322 Font const &, bool trackChanges);
324 void insertChar(pos_type pos, char_type c,
325 Font const &, Change const & change);
326 /// Insert \p inset at position \p pos with \p change traking status.
327 /// \return true if successful.
328 bool insertInset(pos_type pos, Inset * inset,
329 Change const & change);
330 /// Insert \p inset at position \p pos with \p change traking status and
332 /// \return true if successful.
333 bool insertInset(pos_type pos, Inset * inset,
334 Font const & font, Change const & change);
336 Inset * getInset(pos_type pos);
338 Inset const * getInset(pos_type pos) const;
340 /// Release inset at given position.
341 /// \warning does not honour change tracking!
342 /// Therefore, it should only be used for breaking and merging
344 Inset * releaseInset(pos_type pos);
347 InsetList const & insetList() const;
349 void setBuffer(Buffer &);
352 bool isHfill(pos_type pos) const;
354 /// hinted by profiler
355 bool isInset(pos_type pos) const;
357 bool isNewline(pos_type pos) const;
358 /// return true if the char is a word separator
359 bool isSeparator(pos_type pos) const;
361 bool isLineSeparator(pos_type pos) const;
362 /// True if the character/inset at this point is a word separator.
363 /// Note that digits in particular are not considered as word separator.
364 bool isWordSeparator(pos_type pos) const;
365 /// True if the element at this point is a character that is not a letter.
366 bool isChar(pos_type pos) const;
367 /// True if the element at this point is a space
368 bool isSpace(pos_type pos) const;
370 /// returns true if at least one line break or line separator has been deleted
371 /// at the beginning of the paragraph (either physically or logically)
372 bool stripLeadingSpaces(bool trackChanges);
374 /// return true if we allow multiple spaces
375 bool isFreeSpacing() const;
377 /// return true if we allow this par to stay empty
378 bool allowEmpty() const;
380 char_type transformChar(char_type c, pos_type pos) const;
382 ParagraphParameters & params();
384 ParagraphParameters const & params() const;
386 /// Check if we are in a Biblio environment and insert or
387 /// delete InsetBibitems as necessary.
388 /// \retval int 1, if we had to add an inset, in which case
389 /// the cursor will need to move cursor forward; -pos, if we deleted
390 /// an inset, in which case pos is the position from which the inset
391 /// was deleted, and the cursor will need to be moved back one if it
392 /// was previously past that position. Return 0 otherwise.
393 int checkBiblio(Buffer const & buffer);
395 /// For each author, set 'used' to true if there is a change
396 /// by this author in the paragraph.
397 void checkAuthors(AuthorList const & authorList);
400 void changeCase(BufferParams const & bparams, pos_type pos,
401 pos_type & right, TextCase action);
403 /// find \param str string inside Paragraph.
404 /// \return true if the specified string is at the specified position
405 /// \param del specifies whether deleted strings in ct mode will be considered
407 docstring const & str, ///< string to search
410 pos_type pos, ///< start from here.
411 bool del = true) const;
413 void locateWord(pos_type & from, pos_type & to,
414 word_location const loc) const;
418 /// Spellcheck word at position \p from and fill in found misspelled word
419 /// and \p suggestions if \p do_suggestion is true.
420 /// \return true if pointed word is misspelled.
421 bool spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
422 docstring_list & suggestions, bool do_suggestion = true) const;
424 /// Spellcheck word at position \p pos.
425 /// \return true if pointed word is misspelled.
426 bool isMisspelled(pos_type pos) const;
427 /// an automatically generated identifying label for this paragraph.
428 /// presently used only in the XHTML output routines.
429 std::string magicLabel() const;
433 void deregisterWords();
437 void registerWords();
442 friend class Paragraph::Private;
449 #endif // PARAGRAPH_H