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"
49 class ParagraphParameters;
55 /// Invalid font span containing no character
56 FontSpan() : first(0), last(-1) {}
57 /// Span including first and last
58 FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
61 /// Range including first and last.
70 text_capitalization = 1,
77 enum AsStringParameter
79 AS_STR_NONE = 0, ///< No option, only printable characters.
80 AS_STR_LABEL = 1, ///< Prefix with paragraph label.
81 AS_STR_INSETS = 2, ///< Go into insets.
82 AS_STR_NEWLINES = 4 ///< Get also newline characters.
86 /// A Paragraph holds all text, attributes and insets in a text paragraph
93 Paragraph(Paragraph const &);
94 /// Partial copy constructor.
95 /// Copy the Paragraph contents from \p beg to \p end (without end).
96 Paragraph(Paragraph const & par, pos_type beg, pos_type end);
98 Paragraph & operator=(Paragraph const &);
105 void addChangesToToc(DocIterator const & cdit, Buffer const & buf) const;
107 Language const * getParLanguage(BufferParams const &) const;
109 bool isRTL(BufferParams const &) const;
111 void changeLanguage(BufferParams const & bparams,
112 Language const * from, Language const * to);
114 bool isMultiLingual(BufferParams const &) const;
116 /// Convert the paragraph to a string.
117 /// \param AsStringParameter options. This can contain any combination of
118 /// asStringParameter values. Valid examples:
119 /// asString(AS_STR_LABEL)
120 /// asString(AS_STR_LABEL | AS_STR_INSETS)
121 /// asString(AS_STR_INSETS)
122 docstring asString(int options = AS_STR_NONE) const;
124 docstring asString(pos_type beg, pos_type end,
125 int options = AS_STR_NONE) const;
127 /// Extract only the explicitly visible text (without any formatting),
128 /// descending into insets
129 docstring stringify(pos_type beg, pos_type end, int options, OutputParams & runparams) const;
132 void write(std::ostream &, BufferParams const &,
133 depth_type & depth) const;
135 void validate(LaTeXFeatures &) const;
138 bool latex(BufferParams const &, Font const & outerfont, odocstream &,
139 TexRow & texrow, OutputParams const &,
140 int start_pos = 0, int end_pos = -1) const;
142 /// Can we drop the standard paragraph wrapper?
143 bool emptyTag() const;
145 /// Get the id of the paragraph, usefull for docbook
146 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
148 /// Get the first word of a paragraph, return the position where it left
149 pos_type firstWord(odocstream & os, OutputParams const & runparams) const;
151 /// Writes to stream the docbook representation
152 void simpleDocBookOnePar(Buffer const & buf,
154 OutputParams const & runparams,
155 Font const & outerfont,
156 pos_type initial = 0) const;
159 bool hasSameLayout(Paragraph const & par) const;
162 void makeSameLayout(Paragraph const & par);
165 void setInsetOwner(Inset const * inset);
167 Inset const & inInset() const;
169 InsetCode ownerCode() const;
171 bool forcePlainLayout() const;
173 bool allowParagraphCustomization() const;
175 bool usePlainLayout() const;
177 pos_type size() const;
182 Layout const & layout() const;
183 /// Do not pass a temporary to this!
184 void setLayout(Layout const & layout);
186 void setPlainOrDefaultLayout(DocumentClass const & tc);
188 void setDefaultLayout(DocumentClass const & tc);
190 void setPlainLayout(DocumentClass const & tc);
192 /// This is the item depth, only used by enumerate and itemize
193 signed char itemdepth;
195 /// look up change at given pos
196 Change const & lookupChange(pos_type pos) const;
198 /// is there a change within the given range ?
199 bool isChanged(pos_type start, pos_type end) const;
200 /// is there an unchanged char at the given pos ?
201 bool isUnchanged(pos_type pos) const;
202 /// is there an insertion at the given pos ?
203 bool isInserted(pos_type pos) const;
204 /// is there a deletion at the given pos ?
205 bool isDeleted(pos_type pos) const;
206 /// is the whole paragraph deleted ?
207 bool isFullyDeleted(pos_type start, pos_type end) const;
209 /// will the paragraph be physically merged with the next
210 /// one if the imaginary end-of-par character is logically deleted?
211 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
213 /// set change for the entire par
214 void setChange(Change const & change);
216 /// set change at given pos
217 void setChange(pos_type pos, Change const & change);
219 /// accept changes within the given range
220 void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
222 /// reject changes within the given range
223 void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
225 /// Paragraphs can contain "manual labels", for example, Description
226 /// environment. The text for this user-editable label is stored in
227 /// the paragraph alongside the text of the rest of the paragraph
228 /// (the body). This function returns the starting position of the
229 /// body of the text in the paragraph.
230 pos_type beginOfBody() const;
231 /// recompute this value
232 void setBeginOfBody();
235 docstring const & labelString() const;
237 /// the next two functions are for the manual labels
238 docstring const getLabelWidthString() const;
239 /// Set label width string.
240 void setLabelWidthString(docstring const & s);
241 /// translate \p label to the paragraph language if possible.
242 docstring const translateIfPossible(docstring const & label,
243 BufferParams const & bparams) const;
244 /// Expand the counters for the labelstring of \c layout
245 docstring expandLabel(Layout const &, BufferParams const &,
246 bool process_appendix = true) const;
247 /// Actual paragraph alignment used
248 char getAlign() const;
249 /// The nesting depth of a paragraph
250 depth_type getDepth() const;
251 /// The maximal possible depth of a paragraph after this one
252 depth_type getMaxDepthAfter() const;
254 void applyLayout(Layout const & new_layout);
256 /// (logically) erase the char at pos; return true if it was actually erased
257 bool eraseChar(pos_type pos, bool trackChanges);
258 /// (logically) erase the given range; return the number of chars actually erased
259 int eraseChars(pos_type start, pos_type end, bool trackChanges);
262 void resetFonts(Font const & font);
264 /** Get uninstantiated font setting. Returns the difference
265 between the characters font and the layoutfont.
266 This is what is stored in the fonttable
269 getFontSettings(BufferParams const &, pos_type pos) const;
271 Font const & getFirstFontSettings(BufferParams const &) const;
273 /** Get fully instantiated font. If pos == -1, use the layout
274 font attached to this paragraph.
275 If pos == -2, use the label font of the layout attached here.
276 In all cases, the font is instantiated, i.e. does not have any
277 attributes with values FONT_INHERIT, FONT_IGNORE or
280 Font const getFont(BufferParams const &, pos_type pos,
281 Font const & outerfont) const;
282 Font const getLayoutFont(BufferParams const &,
283 Font const & outerfont) const;
284 Font const getLabelFont(BufferParams const &,
285 Font const & outerfont) const;
287 * The font returned by the above functions is the same in a
288 * span of characters. This method will return the first and
289 * the last positions in the paragraph for which that font is
290 * the same. This can be used to avoid unnecessary calls to getFont.
292 FontSpan fontSpan(pos_type pos) const;
294 char_type getChar(pos_type pos) const;
295 /// Get the char, but mirror all bracket characters if it is right-to-left
296 char_type getUChar(BufferParams const &, pos_type pos) const;
297 /// pos <= size() (there is a dummy font change at the end of each par)
298 void setFont(pos_type pos, Font const & font);
299 /// Returns the height of the highest font in range
300 FontSize highestFontInRange(pos_type startpos,
301 pos_type endpos, FontSize def_size) const;
303 void insert(pos_type pos, docstring const & str,
304 Font const & font, Change const & change);
307 void appendString(docstring const & s, Font const & font,
308 Change const & change);
310 void appendChar(char_type c, Font const & font, Change const & change);
312 void insertChar(pos_type pos, char_type c, bool trackChanges);
314 void insertChar(pos_type pos, char_type c,
315 Font const &, bool trackChanges);
317 void insertChar(pos_type pos, char_type c,
318 Font const &, Change const & change);
319 /// Insert \p inset at position \p pos with \p change traking status.
320 /// \return true if successful.
321 bool insertInset(pos_type pos, Inset * inset,
322 Change const & change);
323 /// Insert \p inset at position \p pos with \p change traking status and
325 /// \return true if successful.
326 bool insertInset(pos_type pos, Inset * inset,
327 Font const & font, Change const & change);
329 Inset * getInset(pos_type pos);
331 Inset const * getInset(pos_type pos) const;
333 /// Release inset at given position.
334 /// \warning does not honour change tracking!
335 /// Therefore, it should only be used for breaking and merging
337 Inset * releaseInset(pos_type pos);
340 InsetList const & insetList() const;
342 void setBuffer(Buffer &);
345 bool isHfill(pos_type pos) const;
347 /// hinted by profiler
348 bool isInset(pos_type pos) const;
350 bool isNewline(pos_type pos) const;
351 /// return true if the char is a word separator
352 bool isSeparator(pos_type pos) const;
354 bool isLineSeparator(pos_type pos) const;
355 /// True if the character/inset at this point can be part of a word.
356 /// Note that digits in particular are considered as letters
357 bool isLetter(pos_type pos) const;
358 /// True if the element at this point is a character that is not a letter.
359 bool isChar(pos_type pos) const;
360 /// True if the element at this point is a space
361 bool isSpace(pos_type pos) const;
363 /// returns true if at least one line break or line separator has been deleted
364 /// at the beginning of the paragraph (either physically or logically)
365 bool stripLeadingSpaces(bool trackChanges);
367 /// return true if we allow multiple spaces
368 bool isFreeSpacing() const;
370 /// return true if we allow this par to stay empty
371 bool allowEmpty() const;
373 char_type transformChar(char_type c, pos_type pos) const;
375 ParagraphParameters & params();
377 ParagraphParameters const & params() const;
379 /// Check if we are in a Biblio environment and insert or
380 /// delete InsetBibitems as necessary.
381 /// \retval int 1, if we had to add an inset, in which case
382 /// the cursor will need to move cursor forward; -pos, if we deleted
383 /// an inset, in which case pos is the position from which the inset
384 /// was deleted, and the cursor will need to be moved back one if it
385 /// was previously past that position. Return 0 otherwise.
386 int checkBiblio(Buffer const & buffer);
388 /// For each author, set 'used' to true if there is a change
389 /// by this author in the paragraph.
390 void checkAuthors(AuthorList const & authorList);
393 void changeCase(BufferParams const & bparams, pos_type pos,
394 pos_type & right, TextCase action);
396 /// find \param str string inside Paragraph.
397 /// \return true if the specified string is at the specified position
398 /// \param del specifies whether deleted strings in ct mode will be considered
400 docstring const & str, ///< string to search
403 pos_type pos, ///< start from here.
404 bool del = true) const;
406 void locateWord(pos_type & from, pos_type & to,
407 word_location const loc) const;
410 /// Spellcheck word at position \p pos.
411 /// \return true if pointed word is misspelled.
412 bool isMisspelled(pos_type pos) const;
416 void deregisterWords();
420 void registerWords();
425 friend class Paragraph::Private;
432 #endif // PARAGRAPH_H