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"
47 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;
101 docstring const asString(Buffer const &, bool label) const;
103 docstring const asString(Buffer const & buffer,
109 void write(Buffer const &, std::ostream &, BufferParams const &,
110 depth_type & depth) const;
112 void validate(LaTeXFeatures &) const;
115 bool latex(Buffer const &, BufferParams const &,
116 Font const & outerfont, odocstream &,
117 TexRow & texrow, OutputParams const &) const;
119 /// Can we drop the standard paragraph wrapper?
120 bool emptyTag() const;
122 /// Get the id of the paragraph, usefull for docbook
123 std::string getID(Buffer const & buf,
124 OutputParams const & runparams) const;
126 /// Get the first word of a paragraph, return the position where it left
127 pos_type getFirstWord(Buffer const & buf,
129 OutputParams const & runparams) const;
131 /// Writes to stream the docbook representation
132 void simpleDocBookOnePar(Buffer const & buf,
134 OutputParams const & runparams,
135 Font const & outerfont,
136 pos_type initial = 0) const;
139 bool hasSameLayout(Paragraph const & par) const;
142 void makeSameLayout(Paragraph const & par);
145 void setInsetOwner(Inset * inset);
147 Inset * inInset() const;
149 InsetCode ownerCode() const;
151 bool forceEmptyLayout() const;
153 bool allowParagraphCustomization() const;
155 bool useEmptyLayout() const;
157 pos_type size() const;
162 LayoutPtr const & layout() const;
164 void setLayout(LayoutPtr const & layout);
166 void setEmptyOrDefaultLayout(TextClass const & tc);
168 /// This is the item depth, only used by enumerate and itemize
169 signed char itemdepth;
171 /// look up change at given pos
172 Change const & lookupChange(pos_type pos) const;
174 /// is there a change within the given range ?
175 bool isChanged(pos_type start, pos_type end) const;
176 /// is there an unchanged char at the given pos ?
177 bool isUnchanged(pos_type pos) const;
178 /// is there an insertion at the given pos ?
179 bool isInserted(pos_type pos) const;
180 /// is there a deletion at the given pos ?
181 bool isDeleted(pos_type pos) const;
183 /// will the paragraph be physically merged with the next
184 /// one if the imaginary end-of-par character is logically deleted?
185 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
187 /// set change for the entire par
188 void setChange(Change const & change);
190 /// set change at given pos
191 void setChange(pos_type pos, Change const & change);
193 /// accept changes within the given range
194 void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
196 /// reject changes within the given range
197 void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
199 /// Paragraphs can contain "manual labels", for example, Description
200 /// environment. The text for this user-editable label is stored in
201 /// the paragraph alongside the text of the rest of the paragraph
202 /// (the body). This function returns the starting position of the
203 /// body of the text in the paragraph.
204 pos_type beginOfBody() const;
205 /// recompute this value
206 void setBeginOfBody();
209 docstring const & labelString() const;
211 /// the next two functions are for the manual labels
212 docstring const getLabelWidthString() const;
213 /// Set label width string.
214 void setLabelWidthString(docstring const & s);
215 /// translate \p label to the paragraph language if possible.
216 docstring const translateIfPossible(docstring const & label,
217 BufferParams const & bparams) const;
218 /// Expand the counters for the labelstring of \c layout
219 docstring expandLabel(LayoutPtr const &, BufferParams const &,
220 bool process_appendix = true) const;
221 /// Actual paragraph alignment used
222 char getAlign() const;
223 /// The nesting depth of a paragraph
224 depth_type getDepth() const;
225 /// The maximal possible depth of a paragraph after this one
226 depth_type getMaxDepthAfter() const;
228 void applyLayout(LayoutPtr const & new_layout);
230 /// (logically) erase the char at pos; return true if it was actually erased
231 bool eraseChar(pos_type pos, bool trackChanges);
232 /// (logically) erase the given range; return the number of chars actually erased
233 int eraseChars(pos_type start, pos_type end, bool trackChanges);
236 void resetFonts(Font const & font);
238 /** Get uninstantiated font setting. Returns the difference
239 between the characters font and the layoutfont.
240 This is what is stored in the fonttable
243 getFontSettings(BufferParams const &, pos_type pos) const;
245 Font const getFirstFontSettings(BufferParams const &) const;
247 /** Get fully instantiated font. If pos == -1, use the layout
248 font attached to this paragraph.
249 If pos == -2, use the label font of the layout attached here.
250 In all cases, the font is instantiated, i.e. does not have any
251 attributes with values FONT_INHERIT, FONT_IGNORE or
254 Font const getFont(BufferParams const &, pos_type pos,
255 Font const & outerfont) const;
256 Font const getLayoutFont(BufferParams const &,
257 Font const & outerfont) const;
258 Font const getLabelFont(BufferParams const &,
259 Font const & outerfont) const;
261 * The font returned by the above functions is the same in a
262 * span of characters. This method will return the first and
263 * the last positions in the paragraph for which that font is
264 * the same. This can be used to avoid unnecessary calls to getFont.
266 FontSpan fontSpan(pos_type pos) const;
268 char_type getChar(pos_type pos) const;
269 /// Get the char, but mirror all bracket characters if it is right-to-left
270 char_type getUChar(BufferParams const &, pos_type pos) const;
271 /// pos <= size() (there is a dummy font change at the end of each par)
272 void setFont(pos_type pos, Font const & font);
273 /// Returns the height of the highest font in range
274 FontSize highestFontInRange(pos_type startpos,
275 pos_type endpos, FontSize def_size) const;
277 void insert(pos_type pos, docstring const & str,
278 Font const & font, Change const & change);
281 void appendString(docstring const & s, Font const & font,
282 Change const & change);
284 void appendChar(char_type c, Font const & font, Change const & change);
286 void insertChar(pos_type pos, char_type c, bool trackChanges);
288 void insertChar(pos_type pos, char_type c,
289 Font const &, bool trackChanges);
291 void insertChar(pos_type pos, char_type c,
292 Font const &, Change const & change);
294 void insertInset(pos_type pos, Inset * inset,
295 Change const & change);
297 void insertInset(pos_type pos, Inset * inset,
298 Font const &, Change const & change);
300 bool insetAllowed(InsetCode code);
302 Inset * getInset(pos_type pos);
304 Inset const * getInset(pos_type pos) const;
306 /// Release inset at given position.
307 /// \warning does not honour change tracking!
308 /// Therefore, it should only be used for breaking and merging
310 Inset * releaseInset(pos_type pos);
313 InsetList const & insetList() const;
316 bool isHfill(pos_type pos) const;
318 /// hinted by profiler
319 bool isInset(pos_type pos) const;
321 bool isNewline(pos_type pos) const;
322 /// return true if the char is a word separator
323 bool isSeparator(pos_type pos) const;
325 bool isLineSeparator(pos_type pos) const;
326 /// True if the character/inset at this point can be part of a word.
327 /// Note that digits in particular are considered as letters
328 bool isLetter(pos_type pos) const;
330 /// returns true if at least one line break or line separator has been deleted
331 /// at the beginning of the paragraph (either physically or logically)
332 bool stripLeadingSpaces(bool trackChanges);
334 /// return true if we allow multiple spaces
335 bool isFreeSpacing() const;
337 /// return true if we allow this par to stay empty
338 bool allowEmpty() const;
340 char_type transformChar(char_type c, pos_type pos) const;
342 ParagraphParameters & params();
344 ParagraphParameters const & params() const;
346 /// Check if we are in a Biblio environment and insert or
347 /// delete InsetBibitems as necessary.
348 /// \retval int 1, if we had to add an inset, in which case
349 /// the cursor will need to move cursor forward; -pos, if we deleted
350 /// an inset, in which case pos is the position from which the inset
351 /// was deleted, and the cursor will need to be moved back one if it
352 /// was previously past that position. Return 0 otherwise.
353 int checkBiblio(bool track_changes);
355 /// For each author, set 'used' to true if there is a change
356 /// by this author in the paragraph.
357 void checkAuthors(AuthorList const & authorList);
360 void changeCase(BufferParams const & bparams, pos_type pos,
361 pos_type & right, TextCase action);
363 /// find \param str string inside Paragraph.
364 /// \return true if the specified string is at the specified position
365 /// \param del specifies whether deleted strings in ct mode will be considered
367 docstring const & str, ///< string to search
370 pos_type pos, ///< start from here.
371 bool del = true) const;
374 void updateWords(Buffer const & buf, CursorSlice const & sl);
378 void deregisterWords();
380 void collectWords(Buffer const & buf, CursorSlice const & sl);
382 void registerWords();
387 friend class Paragraph::Private;
394 #endif // PARAGRAPH_H