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 forceEmptyLayout() const;
150 bool allowParagraphCustomization() const;
152 bool useEmptyLayout() const;
154 pos_type size() const;
159 LayoutPtr const & layout() const;
161 void layout(LayoutPtr const & new_layout);
163 /// This is the item depth, only used by enumerate and itemize
164 signed char itemdepth;
166 /// look up change at given pos
167 Change const & lookupChange(pos_type pos) const;
169 /// is there a change within the given range ?
170 bool isChanged(pos_type start, pos_type end) const;
171 /// is there an unchanged char at the given pos ?
172 bool isUnchanged(pos_type pos) const;
173 /// is there an insertion at the given pos ?
174 bool isInserted(pos_type pos) const;
175 /// is there a deletion at the given pos ?
176 bool isDeleted(pos_type pos) const;
178 /// will the paragraph be physically merged with the next
179 /// one if the imaginary end-of-par character is logically deleted?
180 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
182 /// set change for the entire par
183 void setChange(Change const & change);
185 /// set change at given pos
186 void setChange(pos_type pos, Change const & change);
188 /// accept changes within the given range
189 void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
191 /// reject changes within the given range
192 void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
194 /// Paragraphs can contain "manual labels", for example, Description
195 /// environment. The text for this user-editable label is stored in
196 /// the paragraph alongside the text of the rest of the paragraph
197 /// (the body). This function returns the starting position of the
198 /// body of the text in the paragraph.
199 pos_type beginOfBody() const;
200 /// recompute this value
201 void setBeginOfBody();
204 docstring const & getLabelstring() const;
206 /// the next two functions are for the manual labels
207 docstring const getLabelWidthString() const;
208 /// Set label width string.
209 void setLabelWidthString(docstring const & s);
210 /// translate \p label to the paragraph language if possible.
211 docstring const translateIfPossible(docstring const & label,
212 BufferParams const & bparams) const;
213 /// Expand the counters for the labelstring of \c layout
214 docstring expandLabel(LayoutPtr const &, BufferParams const &,
215 bool process_appendix = true) const;
216 /// Actual paragraph alignment used
217 char getAlign() const;
218 /// The nesting depth of a paragraph
219 depth_type getDepth() const;
220 /// The maximal possible depth of a paragraph after this one
221 depth_type getMaxDepthAfter() const;
223 void applyLayout(LayoutPtr const & new_layout);
225 /// (logically) erase the char at pos; return true if it was actually erased
226 bool eraseChar(pos_type pos, bool trackChanges);
227 /// (logically) erase the given range; return the number of chars actually erased
228 int eraseChars(pos_type start, pos_type end, bool trackChanges);
231 void resetFonts(Font const & font);
233 /** Get uninstantiated font setting. Returns the difference
234 between the characters font and the layoutfont.
235 This is what is stored in the fonttable
238 getFontSettings(BufferParams const &, pos_type pos) const;
240 Font const getFirstFontSettings(BufferParams const &) const;
242 /** Get fully instantiated font. If pos == -1, use the layout
243 font attached to this paragraph.
244 If pos == -2, use the label font of the layout attached here.
245 In all cases, the font is instantiated, i.e. does not have any
246 attributes with values FONT_INHERIT, FONT_IGNORE or
249 Font const getFont(BufferParams const &, pos_type pos,
250 Font const & outerfont) const;
251 Font const getLayoutFont(BufferParams const &,
252 Font const & outerfont) const;
253 Font const getLabelFont(BufferParams const &,
254 Font const & outerfont) const;
256 * The font returned by the above functions is the same in a
257 * span of characters. This method will return the first and
258 * the last positions in the paragraph for which that font is
259 * the same. This can be used to avoid unnecessary calls to getFont.
261 FontSpan fontSpan(pos_type pos) const;
263 char_type getChar(pos_type pos) const;
264 /// Get the char, but mirror all bracket characters if it is right-to-left
265 char_type getUChar(BufferParams const &, pos_type pos) const;
266 /// pos <= size() (there is a dummy font change at the end of each par)
267 void setFont(pos_type pos, Font const & font);
268 /// Returns the height of the highest font in range
269 FontSize highestFontInRange(pos_type startpos,
270 pos_type endpos, FontSize def_size) const;
272 void insert(pos_type pos, docstring const & str,
273 Font const & font, Change const & change);
276 void appendString(docstring const & s, Font const & font,
277 Change const & change);
279 void appendChar(char_type c, Font const & font, Change const & change);
281 void insertChar(pos_type pos, char_type c, bool trackChanges);
283 void insertChar(pos_type pos, char_type c,
284 Font const &, bool trackChanges);
286 void insertChar(pos_type pos, char_type c,
287 Font const &, Change const & change);
289 void insertInset(pos_type pos, Inset * inset,
290 Change const & change);
292 void insertInset(pos_type pos, Inset * inset,
293 Font const &, Change const & change);
295 bool insetAllowed(InsetCode code);
297 Inset * getInset(pos_type pos);
299 Inset const * getInset(pos_type pos) const;
301 /// Release inset at given position.
302 /// \warning does not honour change tracking!
303 /// Therefore, it should only be used for breaking and merging
305 Inset * releaseInset(pos_type pos);
308 InsetList const & insetList() const;
311 bool isHfill(pos_type pos) const;
313 /// hinted by profiler
314 bool isInset(pos_type pos) const;
316 bool isNewline(pos_type pos) const;
317 /// return true if the char is a word separator
318 bool isSeparator(pos_type pos) const;
320 bool isLineSeparator(pos_type pos) const;
321 /// True if the character/inset at this point can be part of a word.
322 /// Note that digits in particular are considered as letters
323 bool isLetter(pos_type pos) const;
325 /// returns true if at least one line break or line separator has been deleted
326 /// at the beginning of the paragraph (either physically or logically)
327 bool stripLeadingSpaces(bool trackChanges);
329 /// return true if we allow multiple spaces
330 bool isFreeSpacing() const;
332 /// return true if we allow this par to stay empty
333 bool allowEmpty() const;
335 char_type transformChar(char_type c, pos_type pos) const;
337 ParagraphParameters & params();
339 ParagraphParameters const & params() const;
341 /// Check if we are in a Biblio environment and insert or
342 /// delete InsetBibitems as necessary.
343 /// \retval int 1, if we had to add an inset, in which case
344 /// the cursor will need to move cursor forward; -pos, if we deleted
345 /// an inset, in which case pos is the position from which the inset
346 /// was deleted, and the cursor will need to be moved back one if it
347 /// was previously past that position. Return 0 otherwise.
348 int checkBiblio(bool track_changes);
350 /// For each author, set 'used' to true if there is a change
351 /// by this author in the paragraph.
352 void checkAuthors(AuthorList const & authorList);
355 void changeCase(BufferParams const & bparams, pos_type pos,
356 pos_type & right, TextCase action);
358 /// find \param str string inside Paragraph.
359 /// \return true if the specified string is at the specified position
360 /// \param del specifies whether deleted strings in ct mode will be considered
362 docstring const & str, ///< string to search
365 pos_type pos, ///< start from here.
366 bool del = true) const;
372 friend class Paragraph::Private;
379 #endif // PARAGRAPH_H