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;
128 void write(std::ostream &, BufferParams const &,
129 depth_type & depth) const;
131 void validate(LaTeXFeatures &) const;
134 bool latex(BufferParams const &, Font const & outerfont, odocstream &,
135 TexRow & texrow, OutputParams const &) const;
137 /// Can we drop the standard paragraph wrapper?
138 bool emptyTag() const;
140 /// Get the id of the paragraph, usefull for docbook
141 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
143 /// Get the first word of a paragraph, return the position where it left
144 pos_type firstWord(odocstream & os, OutputParams const & runparams) const;
146 /// Writes to stream the docbook representation
147 void simpleDocBookOnePar(Buffer const & buf,
149 OutputParams const & runparams,
150 Font const & outerfont,
151 pos_type initial = 0) const;
154 bool hasSameLayout(Paragraph const & par) const;
157 void makeSameLayout(Paragraph const & par);
160 void setInsetOwner(Inset const * inset);
162 Inset const & inInset() const;
164 InsetCode ownerCode() const;
166 bool forcePlainLayout() const;
168 bool allowParagraphCustomization() const;
170 bool usePlainLayout() const;
172 pos_type size() const;
177 Layout const & layout() const;
178 /// Do not pass a temporary to this!
179 void setLayout(Layout const & layout);
181 void setPlainOrDefaultLayout(DocumentClass const & tc);
183 /// This is the item depth, only used by enumerate and itemize
184 signed char itemdepth;
186 /// look up change at given pos
187 Change const & lookupChange(pos_type pos) const;
189 /// is there a change within the given range ?
190 bool isChanged(pos_type start, pos_type end) const;
191 /// is there an unchanged char at the given pos ?
192 bool isUnchanged(pos_type pos) const;
193 /// is there an insertion at the given pos ?
194 bool isInserted(pos_type pos) const;
195 /// is there a deletion at the given pos ?
196 bool isDeleted(pos_type pos) const;
198 /// will the paragraph be physically merged with the next
199 /// one if the imaginary end-of-par character is logically deleted?
200 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
202 /// set change for the entire par
203 void setChange(Change const & change);
205 /// set change at given pos
206 void setChange(pos_type pos, Change const & change);
208 /// accept changes within the given range
209 void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
211 /// reject changes within the given range
212 void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
214 /// Paragraphs can contain "manual labels", for example, Description
215 /// environment. The text for this user-editable label is stored in
216 /// the paragraph alongside the text of the rest of the paragraph
217 /// (the body). This function returns the starting position of the
218 /// body of the text in the paragraph.
219 pos_type beginOfBody() const;
220 /// recompute this value
221 void setBeginOfBody();
224 docstring const & labelString() const;
226 /// the next two functions are for the manual labels
227 docstring const getLabelWidthString() const;
228 /// Set label width string.
229 void setLabelWidthString(docstring const & s);
230 /// translate \p label to the paragraph language if possible.
231 docstring const translateIfPossible(docstring const & label,
232 BufferParams const & bparams) const;
233 /// Expand the counters for the labelstring of \c layout
234 docstring expandLabel(Layout const &, BufferParams const &,
235 bool process_appendix = true) const;
236 /// Actual paragraph alignment used
237 char getAlign() const;
238 /// The nesting depth of a paragraph
239 depth_type getDepth() const;
240 /// The maximal possible depth of a paragraph after this one
241 depth_type getMaxDepthAfter() const;
243 void applyLayout(Layout const & new_layout);
245 /// (logically) erase the char at pos; return true if it was actually erased
246 bool eraseChar(pos_type pos, bool trackChanges);
247 /// (logically) erase the given range; return the number of chars actually erased
248 int eraseChars(pos_type start, pos_type end, bool trackChanges);
251 void resetFonts(Font const & font);
253 /** Get uninstantiated font setting. Returns the difference
254 between the characters font and the layoutfont.
255 This is what is stored in the fonttable
258 getFontSettings(BufferParams const &, pos_type pos) const;
260 Font const & getFirstFontSettings(BufferParams const &) const;
262 /** Get fully instantiated font. If pos == -1, use the layout
263 font attached to this paragraph.
264 If pos == -2, use the label font of the layout attached here.
265 In all cases, the font is instantiated, i.e. does not have any
266 attributes with values FONT_INHERIT, FONT_IGNORE or
269 Font const getFont(BufferParams const &, pos_type pos,
270 Font const & outerfont) const;
271 Font const getLayoutFont(BufferParams const &,
272 Font const & outerfont) const;
273 Font const getLabelFont(BufferParams const &,
274 Font const & outerfont) const;
276 * The font returned by the above functions is the same in a
277 * span of characters. This method will return the first and
278 * the last positions in the paragraph for which that font is
279 * the same. This can be used to avoid unnecessary calls to getFont.
281 FontSpan fontSpan(pos_type pos) const;
283 char_type getChar(pos_type pos) const;
284 /// Get the char, but mirror all bracket characters if it is right-to-left
285 char_type getUChar(BufferParams const &, pos_type pos) const;
286 /// pos <= size() (there is a dummy font change at the end of each par)
287 void setFont(pos_type pos, Font const & font);
288 /// Returns the height of the highest font in range
289 FontSize highestFontInRange(pos_type startpos,
290 pos_type endpos, FontSize def_size) const;
292 void insert(pos_type pos, docstring const & str,
293 Font const & font, Change const & change);
296 void appendString(docstring const & s, Font const & font,
297 Change const & change);
299 void appendChar(char_type c, Font const & font, Change const & change);
301 void insertChar(pos_type pos, char_type c, bool trackChanges);
303 void insertChar(pos_type pos, char_type c,
304 Font const &, bool trackChanges);
306 void insertChar(pos_type pos, char_type c,
307 Font const &, Change const & change);
308 /// Insert \p inset at position \p pos with \p change traking status.
309 /// \return true if successful.
310 bool insertInset(pos_type pos, Inset * inset,
311 Change const & change);
312 /// Insert \p inset at position \p pos with \p change traking status and
314 /// \return true if successful.
315 bool insertInset(pos_type pos, Inset * inset,
316 Font const & font, Change const & change);
318 Inset * getInset(pos_type pos);
320 Inset const * getInset(pos_type pos) const;
322 /// Release inset at given position.
323 /// \warning does not honour change tracking!
324 /// Therefore, it should only be used for breaking and merging
326 Inset * releaseInset(pos_type pos);
329 InsetList const & insetList() const;
331 void setBuffer(Buffer &);
334 bool isHfill(pos_type pos) const;
336 /// hinted by profiler
337 bool isInset(pos_type pos) const;
339 bool isNewline(pos_type pos) const;
340 /// return true if the char is a word separator
341 bool isSeparator(pos_type pos) const;
343 bool isLineSeparator(pos_type pos) const;
344 /// True if the character/inset at this point can be part of a word.
345 /// Note that digits in particular are considered as letters
346 bool isLetter(pos_type pos) const;
347 /// True if the element at this point is a character that is not a letter.
348 bool isChar(pos_type pos) const;
349 /// True if the element at this point is a space
350 bool isSpace(pos_type pos) const;
352 /// returns true if at least one line break or line separator has been deleted
353 /// at the beginning of the paragraph (either physically or logically)
354 bool stripLeadingSpaces(bool trackChanges);
356 /// return true if we allow multiple spaces
357 bool isFreeSpacing() const;
359 /// return true if we allow this par to stay empty
360 bool allowEmpty() const;
362 char_type transformChar(char_type c, pos_type pos) const;
364 ParagraphParameters & params();
366 ParagraphParameters const & params() const;
368 /// Check if we are in a Biblio environment and insert or
369 /// delete InsetBibitems as necessary.
370 /// \retval int 1, if we had to add an inset, in which case
371 /// the cursor will need to move cursor forward; -pos, if we deleted
372 /// an inset, in which case pos is the position from which the inset
373 /// was deleted, and the cursor will need to be moved back one if it
374 /// was previously past that position. Return 0 otherwise.
375 int checkBiblio(Buffer const & buffer);
377 /// For each author, set 'used' to true if there is a change
378 /// by this author in the paragraph.
379 void checkAuthors(AuthorList const & authorList);
382 void changeCase(BufferParams const & bparams, pos_type pos,
383 pos_type & right, TextCase action);
385 /// find \param str string inside Paragraph.
386 /// \return true if the specified string is at the specified position
387 /// \param del specifies whether deleted strings in ct mode will be considered
389 docstring const & str, ///< string to search
392 pos_type pos, ///< start from here.
393 bool del = true) const;
396 void updateWords(CursorSlice const & sl);
400 void deregisterWords();
402 void collectWords(CursorSlice const & sl);
404 void registerWords();
409 friend class Paragraph::Private;
416 #endif // PARAGRAPH_H