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 "LayoutPtr.h"
22 #include "insets/InsetCode.h"
24 #include "support/strfwd.h"
25 #include "support/types.h"
48 class ParagraphParameters;
54 /// Invalid font span containing no character
55 FontSpan() : first(0), last(-1) {}
56 /// Span including first and last
57 FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
60 /// Range including first and last.
69 text_capitalization = 1,
75 /// A Paragraph holds all text, attributes and insets in a text paragraph
82 Paragraph(Paragraph const &);
84 Paragraph & operator=(Paragraph const &);
91 Language const * getParLanguage(BufferParams const &) const;
93 bool isRTL(BufferParams const &) const;
95 void changeLanguage(BufferParams const & bparams,
96 Language const * from, Language const * to);
98 bool isMultiLingual(BufferParams const &) const;
100 /// Convert the paragraph to a string.
101 /// Used for building the table of contents
102 docstring asString(bool label) const;
104 docstring asString(pos_type beg, pos_type end, bool label) const;
107 void write(std::ostream &, BufferParams const &,
108 depth_type & depth) const;
110 void validate(LaTeXFeatures &) const;
113 bool latex(BufferParams const &, Font const & outerfont, odocstream &,
114 TexRow & texrow, OutputParams const &) const;
116 /// Can we drop the standard paragraph wrapper?
117 bool emptyTag() const;
119 /// Get the id of the paragraph, usefull for docbook
120 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
122 /// Get the first word of a paragraph, return the position where it left
123 pos_type firstWord(odocstream & os, OutputParams const & runparams) const;
125 /// Writes to stream the docbook representation
126 void simpleDocBookOnePar(Buffer const & buf,
128 OutputParams const & runparams,
129 Font const & outerfont,
130 pos_type initial = 0) const;
133 bool hasSameLayout(Paragraph const & par) const;
136 void makeSameLayout(Paragraph const & par);
139 void setInsetOwner(Inset * inset);
141 Inset * inInset() const;
143 InsetCode ownerCode() const;
145 bool forceEmptyLayout() const;
147 bool allowParagraphCustomization() const;
149 bool useEmptyLayout() const;
151 pos_type size() const;
156 LayoutPtr const & layout() const;
158 void setLayout(LayoutPtr const & layout);
160 void setLayout(Layout const & layout) { setLayout(&layout); }
162 void setEmptyOrDefaultLayout(DocumentClass const & tc);
164 /// This is the item depth, only used by enumerate and itemize
165 signed char itemdepth;
167 /// look up change at given pos
168 Change const & lookupChange(pos_type pos) const;
170 /// is there a change within the given range ?
171 bool isChanged(pos_type start, pos_type end) const;
172 /// is there an unchanged char at the given pos ?
173 bool isUnchanged(pos_type pos) const;
174 /// is there an insertion at the given pos ?
175 bool isInserted(pos_type pos) const;
176 /// is there a deletion at the given pos ?
177 bool isDeleted(pos_type pos) const;
179 /// will the paragraph be physically merged with the next
180 /// one if the imaginary end-of-par character is logically deleted?
181 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
183 /// set change for the entire par
184 void setChange(Change const & change);
186 /// set change at given pos
187 void setChange(pos_type pos, Change const & change);
189 /// accept changes within the given range
190 void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
192 /// reject changes within the given range
193 void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
195 /// Paragraphs can contain "manual labels", for example, Description
196 /// environment. The text for this user-editable label is stored in
197 /// the paragraph alongside the text of the rest of the paragraph
198 /// (the body). This function returns the starting position of the
199 /// body of the text in the paragraph.
200 pos_type beginOfBody() const;
201 /// recompute this value
202 void setBeginOfBody();
205 docstring const & labelString() const;
207 /// the next two functions are for the manual labels
208 docstring const getLabelWidthString() const;
209 /// Set label width string.
210 void setLabelWidthString(docstring const & s);
211 /// translate \p label to the paragraph language if possible.
212 docstring const translateIfPossible(docstring const & label,
213 BufferParams const & bparams) const;
214 /// Expand the counters for the labelstring of \c layout
215 docstring expandLabel(LayoutPtr const &, BufferParams const &,
216 bool process_appendix = true) const;
217 /// Actual paragraph alignment used
218 char getAlign() const;
219 /// The nesting depth of a paragraph
220 depth_type getDepth() const;
221 /// The maximal possible depth of a paragraph after this one
222 depth_type getMaxDepthAfter() const;
224 void applyLayout(Layout const & new_layout);
226 /// (logically) erase the char at pos; return true if it was actually erased
227 bool eraseChar(pos_type pos, bool trackChanges);
228 /// (logically) erase the given range; return the number of chars actually erased
229 int eraseChars(pos_type start, pos_type end, bool trackChanges);
232 void resetFonts(Font const & font);
234 /** Get uninstantiated font setting. Returns the difference
235 between the characters font and the layoutfont.
236 This is what is stored in the fonttable
239 getFontSettings(BufferParams const &, pos_type pos) const;
241 Font const getFirstFontSettings(BufferParams const &) const;
243 /** Get fully instantiated font. If pos == -1, use the layout
244 font attached to this paragraph.
245 If pos == -2, use the label font of the layout attached here.
246 In all cases, the font is instantiated, i.e. does not have any
247 attributes with values FONT_INHERIT, FONT_IGNORE or
250 Font const getFont(BufferParams const &, pos_type pos,
251 Font const & outerfont) const;
252 Font const getLayoutFont(BufferParams const &,
253 Font const & outerfont) const;
254 Font const getLabelFont(BufferParams const &,
255 Font const & outerfont) const;
257 * The font returned by the above functions is the same in a
258 * span of characters. This method will return the first and
259 * the last positions in the paragraph for which that font is
260 * the same. This can be used to avoid unnecessary calls to getFont.
262 FontSpan fontSpan(pos_type pos) const;
264 char_type getChar(pos_type pos) const;
265 /// Get the char, but mirror all bracket characters if it is right-to-left
266 char_type getUChar(BufferParams const &, pos_type pos) const;
267 /// pos <= size() (there is a dummy font change at the end of each par)
268 void setFont(pos_type pos, Font const & font);
269 /// Returns the height of the highest font in range
270 FontSize highestFontInRange(pos_type startpos,
271 pos_type endpos, FontSize def_size) const;
273 void insert(pos_type pos, docstring const & str,
274 Font const & font, Change const & change);
277 void appendString(docstring const & s, Font const & font,
278 Change const & change);
280 void appendChar(char_type c, Font const & font, Change const & change);
282 void insertChar(pos_type pos, char_type c, bool trackChanges);
284 void insertChar(pos_type pos, char_type c,
285 Font const &, bool trackChanges);
287 void insertChar(pos_type pos, char_type c,
288 Font const &, Change const & change);
290 void insertInset(pos_type pos, Inset * inset,
291 Change const & change);
293 void insertInset(pos_type pos, Inset * inset,
294 Font const &, Change const & change);
296 bool insetAllowed(InsetCode code);
298 Inset * getInset(pos_type pos);
300 Inset const * getInset(pos_type pos) const;
302 /// Release inset at given position.
303 /// \warning does not honour change tracking!
304 /// Therefore, it should only be used for breaking and merging
306 Inset * releaseInset(pos_type pos);
309 InsetList const & insetList() const;
312 bool isHfill(pos_type pos) const;
314 /// hinted by profiler
315 bool isInset(pos_type pos) const;
317 bool isNewline(pos_type pos) const;
318 /// return true if the char is a word separator
319 bool isSeparator(pos_type pos) const;
321 bool isLineSeparator(pos_type pos) const;
322 /// True if the character/inset at this point can be part of a word.
323 /// Note that digits in particular are considered as letters
324 bool isLetter(pos_type pos) const;
326 /// returns true if at least one line break or line separator has been deleted
327 /// at the beginning of the paragraph (either physically or logically)
328 bool stripLeadingSpaces(bool trackChanges);
330 /// return true if we allow multiple spaces
331 bool isFreeSpacing() const;
333 /// return true if we allow this par to stay empty
334 bool allowEmpty() const;
336 char_type transformChar(char_type c, pos_type pos) const;
338 ParagraphParameters & params();
340 ParagraphParameters const & params() const;
342 /// Check if we are in a Biblio environment and insert or
343 /// delete InsetBibitems as necessary.
344 /// \retval int 1, if we had to add an inset, in which case
345 /// the cursor will need to move cursor forward; -pos, if we deleted
346 /// an inset, in which case pos is the position from which the inset
347 /// was deleted, and the cursor will need to be moved back one if it
348 /// was previously past that position. Return 0 otherwise.
349 int checkBiblio(Buffer const & buffer);
351 /// For each author, set 'used' to true if there is a change
352 /// by this author in the paragraph.
353 void checkAuthors(AuthorList const & authorList);
356 void changeCase(BufferParams const & bparams, pos_type pos,
357 pos_type & right, TextCase action);
359 /// find \param str string inside Paragraph.
360 /// \return true if the specified string is at the specified position
361 /// \param del specifies whether deleted strings in ct mode will be considered
363 docstring const & str, ///< string to search
366 pos_type pos, ///< start from here.
367 bool del = true) const;
370 void updateWords(CursorSlice const & sl);
374 void deregisterWords();
376 void collectWords(CursorSlice const & sl);
378 void registerWords();
383 friend class Paragraph::Private;
390 #endif // PARAGRAPH_H