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"
45 class ParagraphParameters;
51 /// Invalid font span containing no character
52 FontSpan() : first(0), last(-1) {}
53 /// Span including first and last
54 FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
57 /// Range including first and last.
66 text_capitalization = 1,
72 /// A Paragraph holds all text, attributes and insets in a text paragraph
79 Paragraph(Paragraph const &);
81 Paragraph & operator=(Paragraph const &);
88 Language const * getParLanguage(BufferParams const &) const;
90 bool isRTL(BufferParams const &) const;
92 void changeLanguage(BufferParams const & bparams,
93 Language const * from, Language const * to);
95 bool isMultiLingual(BufferParams const &) const;
98 docstring const asString(Buffer const &, bool label) const;
100 docstring const asString(Buffer const & buffer,
106 void write(Buffer const &, std::ostream &, BufferParams const &,
107 depth_type & depth) const;
109 void validate(LaTeXFeatures &) const;
112 bool latex(Buffer const &, BufferParams const &,
113 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,
121 OutputParams const & runparams) const;
123 /// Get the first word of a paragraph, return the position where it left
124 pos_type getFirstWord(Buffer const & buf,
126 OutputParams const & runparams) const;
128 /// Writes to stream the docbook representation
129 void simpleDocBookOnePar(Buffer const & buf,
131 OutputParams const & runparams,
132 Font const & outerfont,
133 pos_type initial = 0) const;
136 bool hasSameLayout(Paragraph const & par) const;
139 void makeSameLayout(Paragraph const & par);
142 void setInsetOwner(Inset * inset);
144 Inset * inInset() const;
146 InsetCode ownerCode() const;
148 bool forceDefaultParagraphs() const;
151 pos_type size() const;
156 LayoutPtr const & layout() const;
158 void layout(LayoutPtr const & new_layout);
160 /// This is the item depth, only used by enumerate and itemize
161 signed char itemdepth;
163 /// look up change at given pos
164 Change const & lookupChange(pos_type pos) const;
166 /// is there a change within the given range ?
167 bool isChanged(pos_type start, pos_type end) const;
168 /// is there an unchanged char at the given pos ?
169 bool isUnchanged(pos_type pos) const;
170 /// is there an insertion at the given pos ?
171 bool isInserted(pos_type pos) const;
172 /// is there a deletion at the given pos ?
173 bool isDeleted(pos_type pos) const;
175 /// will the paragraph be physically merged with the next
176 /// one if the imaginary end-of-par character is logically deleted?
177 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
179 /// set change for the entire par
180 void setChange(Change const & change);
182 /// set change at given pos
183 void setChange(pos_type pos, Change const & change);
185 /// accept changes within the given range
186 void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
188 /// reject changes within the given range
189 void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
191 /// Paragraphs can contain "manual labels", for example, Description
192 /// environment. The text for this user-editable label is stored in
193 /// the paragraph alongside the text of the rest of the paragraph
194 /// (the body). This function returns the starting position of the
195 /// body of the text in the paragraph.
196 pos_type beginOfBody() const;
197 /// recompute this value
198 void setBeginOfBody();
201 docstring const & getLabelstring() const;
203 /// the next two functions are for the manual labels
204 docstring const getLabelWidthString() const;
205 /// Set label width string.
206 void setLabelWidthString(docstring const & s);
207 /// translate \p label to the paragraph language if possible.
208 docstring const translateIfPossible(docstring const & label,
209 BufferParams const & bparams) const;
210 /// Expand the counters for the labelstring of \c layout
211 docstring expandLabel(LayoutPtr const &, BufferParams const &,
212 bool process_appendix = true) const;
213 /// Actual paragraph alignment used
214 char getAlign() const;
215 /// The nesting depth of a paragraph
216 depth_type getDepth() const;
217 /// The maximal possible depth of a paragraph after this one
218 depth_type getMaxDepthAfter() const;
220 void applyLayout(LayoutPtr const & new_layout);
222 /// (logically) erase the char at pos; return true if it was actually erased
223 bool eraseChar(pos_type pos, bool trackChanges);
224 /// (logically) erase the given range; return the number of chars actually erased
225 int eraseChars(pos_type start, pos_type end, bool trackChanges);
228 void resetFonts(Font const & font);
230 /** Get uninstantiated font setting. Returns the difference
231 between the characters font and the layoutfont.
232 This is what is stored in the fonttable
235 getFontSettings(BufferParams const &, pos_type pos) const;
237 Font const getFirstFontSettings(BufferParams const &) const;
239 /** Get fully instantiated font. If pos == -1, use the layout
240 font attached to this paragraph.
241 If pos == -2, use the label font of the layout attached here.
242 In all cases, the font is instantiated, i.e. does not have any
243 attributes with values FONT_INHERIT, FONT_IGNORE or
246 Font const getFont(BufferParams const &, pos_type pos,
247 Font const & outerfont) const;
248 Font const getLayoutFont(BufferParams const &,
249 Font const & outerfont) const;
250 Font const getLabelFont(BufferParams const &,
251 Font const & outerfont) const;
253 * The font returned by the above functions is the same in a
254 * span of characters. This method will return the first and
255 * the last positions in the paragraph for which that font is
256 * the same. This can be used to avoid unnecessary calls to getFont.
258 FontSpan fontSpan(pos_type pos) const;
260 char_type getChar(pos_type pos) const;
261 /// Get the char, but mirror all bracket characters if it is right-to-left
262 char_type getUChar(BufferParams const &, pos_type pos) const;
263 /// pos <= size() (there is a dummy font change at the end of each par)
264 void setFont(pos_type pos, Font const & font);
265 /// Returns the height of the highest font in range
266 FontSize highestFontInRange(pos_type startpos,
267 pos_type endpos, FontSize def_size) const;
269 void insert(pos_type pos, docstring const & str,
270 Font const & font, Change const & change);
273 void appendString(docstring const & s, Font const & font,
274 Change const & change);
276 void appendChar(char_type c, Font const & font, Change const & change);
278 void insertChar(pos_type pos, char_type c, bool trackChanges);
280 void insertChar(pos_type pos, char_type c,
281 Font const &, bool trackChanges);
283 void insertChar(pos_type pos, char_type c,
284 Font const &, Change const & change);
286 void insertInset(pos_type pos, Inset * inset,
287 Change const & change);
289 void insertInset(pos_type pos, Inset * inset,
290 Font const &, Change const & change);
292 bool insetAllowed(InsetCode code);
294 Inset * getInset(pos_type pos);
296 Inset const * getInset(pos_type pos) const;
298 /// Release inset at given position.
299 /// \warning does not honour change tracking!
300 /// Therefore, it should only be used for breaking and merging
302 Inset * releaseInset(pos_type pos);
305 InsetList const & insetList() const;
308 bool isHfill(pos_type pos) const;
310 /// hinted by profiler
311 bool isInset(pos_type pos) const;
313 bool isNewline(pos_type pos) const;
314 /// return true if the char is a word separator
315 bool isSeparator(pos_type pos) const;
317 bool isLineSeparator(pos_type pos) const;
318 /// True if the character/inset at this point can be part of a word.
319 /// Note that digits in particular are considered as letters
320 bool isLetter(pos_type pos) const;
322 /// returns true if at least one line break or line separator has been deleted
323 /// at the beginning of the paragraph (either physically or logically)
324 bool stripLeadingSpaces(bool trackChanges);
326 /// return true if we allow multiple spaces
327 bool isFreeSpacing() const;
329 /// return true if we allow this par to stay empty
330 bool allowEmpty() const;
332 char_type transformChar(char_type c, pos_type pos) const;
334 ParagraphParameters & params();
336 ParagraphParameters const & params() const;
338 /// Check if we are in a Biblio environment and insert or
339 /// delete InsetBibitems as necessary.
340 /// \retval int 1, if we had to add an inset, in which case
341 /// the cursor will need to move cursor forward; -pos, if we deleted
342 /// an inset, in which case pos is the position from which the inset
343 /// was deleted, and the cursor will need to be moved back one if it
344 /// was previously past that position. Return 0 otherwise.
345 int checkBiblio(bool track_changes);
347 /// To resolve macros properly the paragraphs are numbered.
348 /// Every macro definition is stored with its paragraph number
349 /// as well. Only those macros with a smaller number become
350 /// visible in a paragraph (plus those in the same paragraph, but
351 /// in an earlier inset.
352 unsigned int macrocontextPosition() const;
354 void setMacrocontextPosition(unsigned int pos);
356 /// For each author, set 'used' to true if there is a change
357 /// by this author in the paragraph.
358 void checkAuthors(AuthorList const & authorList);
361 void changeCase(BufferParams const & bparams, pos_type pos,
362 pos_type right, TextCase action);
364 /// find \param str string inside Paragraph.
365 /// \return true if the specified string is at the specified position
366 /// \param del specifies whether deleted strings in ct mode will be considered
368 docstring const & str, ///< string to search
371 pos_type pos, ///< start from here.
372 bool del = true) const;
378 friend class Paragraph::Private;
385 #endif // PARAGRAPH_H