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"
46 class ParagraphParameters;
53 /// Invalid font span containing no character
54 FontSpan() : first(0), last(-1) {}
55 /// Span including first and last
56 FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
59 /// Range including first and last.
68 text_capitalization = 1,
74 /// A Paragraph holds all text, attributes and insets in a text paragraph
81 Paragraph(Paragraph const &);
83 Paragraph & operator=(Paragraph const &);
90 Language const * getParLanguage(BufferParams const &) const;
92 bool isRTL(BufferParams const &) const;
94 void changeLanguage(BufferParams const & bparams,
95 Language const * from, Language const * to);
97 bool isMultiLingual(BufferParams const &) const;
100 docstring const asString(Buffer const &, bool label) const;
102 docstring const asString(Buffer const & buffer,
108 void write(Buffer const &, std::ostream &, BufferParams const &,
109 depth_type & depth) const;
111 void validate(LaTeXFeatures &) const;
114 bool latex(Buffer const &, BufferParams const &,
115 Font const & outerfont, odocstream &,
116 TexRow & texrow, OutputParams const &) const;
118 /// Can we drop the standard paragraph wrapper?
119 bool emptyTag() const;
121 /// Get the id of the paragraph, usefull for docbook
122 std::string getID(Buffer const & buf,
123 OutputParams const & runparams) const;
125 /// Get the first word of a paragraph, return the position where it left
126 pos_type getFirstWord(Buffer const & buf,
128 OutputParams const & runparams) const;
130 /// Writes to stream the docbook representation
131 void simpleDocBookOnePar(Buffer const & buf,
133 OutputParams const & runparams,
134 Font const & outerfont,
135 pos_type initial = 0) const;
138 bool hasSameLayout(Paragraph const & par) const;
141 void makeSameLayout(Paragraph const & par);
144 void setInsetOwner(Inset * inset);
146 Inset * inInset() const;
148 InsetCode ownerCode() const;
150 bool forceEmptyLayout() const;
152 bool allowParagraphCustomization() const;
154 bool useEmptyLayout() const;
156 pos_type size() const;
161 LayoutPtr const & layout() const;
163 void setLayout(LayoutPtr const & layout);
165 void setEmptyOrDefaultLayout(TextClass const & tc);
167 /// This is the item depth, only used by enumerate and itemize
168 signed char itemdepth;
170 /// look up change at given pos
171 Change const & lookupChange(pos_type pos) const;
173 /// is there a change within the given range ?
174 bool isChanged(pos_type start, pos_type end) const;
175 /// is there an unchanged char at the given pos ?
176 bool isUnchanged(pos_type pos) const;
177 /// is there an insertion at the given pos ?
178 bool isInserted(pos_type pos) const;
179 /// is there a deletion at the given pos ?
180 bool isDeleted(pos_type pos) const;
182 /// will the paragraph be physically merged with the next
183 /// one if the imaginary end-of-par character is logically deleted?
184 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
186 /// set change for the entire par
187 void setChange(Change const & change);
189 /// set change at given pos
190 void setChange(pos_type pos, Change const & change);
192 /// accept changes within the given range
193 void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
195 /// reject changes within the given range
196 void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
198 /// Paragraphs can contain "manual labels", for example, Description
199 /// environment. The text for this user-editable label is stored in
200 /// the paragraph alongside the text of the rest of the paragraph
201 /// (the body). This function returns the starting position of the
202 /// body of the text in the paragraph.
203 pos_type beginOfBody() const;
204 /// recompute this value
205 void setBeginOfBody();
208 docstring const & labelString() const;
210 /// the next two functions are for the manual labels
211 docstring const getLabelWidthString() const;
212 /// Set label width string.
213 void setLabelWidthString(docstring const & s);
214 /// translate \p label to the paragraph language if possible.
215 docstring const translateIfPossible(docstring const & label,
216 BufferParams const & bparams) const;
217 /// Expand the counters for the labelstring of \c layout
218 docstring expandLabel(LayoutPtr const &, BufferParams const &,
219 bool process_appendix = true) const;
220 /// Actual paragraph alignment used
221 char getAlign() const;
222 /// The nesting depth of a paragraph
223 depth_type getDepth() const;
224 /// The maximal possible depth of a paragraph after this one
225 depth_type getMaxDepthAfter() const;
227 void applyLayout(LayoutPtr const & new_layout);
229 /// (logically) erase the char at pos; return true if it was actually erased
230 bool eraseChar(pos_type pos, bool trackChanges);
231 /// (logically) erase the given range; return the number of chars actually erased
232 int eraseChars(pos_type start, pos_type end, bool trackChanges);
235 void resetFonts(Font const & font);
237 /** Get uninstantiated font setting. Returns the difference
238 between the characters font and the layoutfont.
239 This is what is stored in the fonttable
242 getFontSettings(BufferParams const &, pos_type pos) const;
244 Font const getFirstFontSettings(BufferParams const &) const;
246 /** Get fully instantiated font. If pos == -1, use the layout
247 font attached to this paragraph.
248 If pos == -2, use the label font of the layout attached here.
249 In all cases, the font is instantiated, i.e. does not have any
250 attributes with values FONT_INHERIT, FONT_IGNORE or
253 Font const getFont(BufferParams const &, pos_type pos,
254 Font const & outerfont) const;
255 Font const getLayoutFont(BufferParams const &,
256 Font const & outerfont) const;
257 Font const getLabelFont(BufferParams const &,
258 Font const & outerfont) const;
260 * The font returned by the above functions is the same in a
261 * span of characters. This method will return the first and
262 * the last positions in the paragraph for which that font is
263 * the same. This can be used to avoid unnecessary calls to getFont.
265 FontSpan fontSpan(pos_type pos) const;
267 char_type getChar(pos_type pos) const;
268 /// Get the char, but mirror all bracket characters if it is right-to-left
269 char_type getUChar(BufferParams const &, pos_type pos) const;
270 /// pos <= size() (there is a dummy font change at the end of each par)
271 void setFont(pos_type pos, Font const & font);
272 /// Returns the height of the highest font in range
273 FontSize highestFontInRange(pos_type startpos,
274 pos_type endpos, FontSize def_size) const;
276 void insert(pos_type pos, docstring const & str,
277 Font const & font, Change const & change);
280 void appendString(docstring const & s, Font const & font,
281 Change const & change);
283 void appendChar(char_type c, Font const & font, Change const & change);
285 void insertChar(pos_type pos, char_type c, bool trackChanges);
287 void insertChar(pos_type pos, char_type c,
288 Font const &, bool trackChanges);
290 void insertChar(pos_type pos, char_type c,
291 Font const &, Change const & change);
293 void insertInset(pos_type pos, Inset * inset,
294 Change const & change);
296 void insertInset(pos_type pos, Inset * inset,
297 Font const &, Change const & change);
299 bool insetAllowed(InsetCode code);
301 Inset * getInset(pos_type pos);
303 Inset const * getInset(pos_type pos) const;
305 /// Release inset at given position.
306 /// \warning does not honour change tracking!
307 /// Therefore, it should only be used for breaking and merging
309 Inset * releaseInset(pos_type pos);
312 InsetList const & insetList() const;
315 bool isHfill(pos_type pos) const;
317 /// hinted by profiler
318 bool isInset(pos_type pos) const;
320 bool isNewline(pos_type pos) const;
321 /// return true if the char is a word separator
322 bool isSeparator(pos_type pos) const;
324 bool isLineSeparator(pos_type pos) const;
325 /// True if the character/inset at this point can be part of a word.
326 /// Note that digits in particular are considered as letters
327 bool isLetter(pos_type pos) const;
329 /// returns true if at least one line break or line separator has been deleted
330 /// at the beginning of the paragraph (either physically or logically)
331 bool stripLeadingSpaces(bool trackChanges);
333 /// return true if we allow multiple spaces
334 bool isFreeSpacing() const;
336 /// return true if we allow this par to stay empty
337 bool allowEmpty() const;
339 char_type transformChar(char_type c, pos_type pos) const;
341 ParagraphParameters & params();
343 ParagraphParameters const & params() const;
345 /// Check if we are in a Biblio environment and insert or
346 /// delete InsetBibitems as necessary.
347 /// \retval int 1, if we had to add an inset, in which case
348 /// the cursor will need to move cursor forward; -pos, if we deleted
349 /// an inset, in which case pos is the position from which the inset
350 /// was deleted, and the cursor will need to be moved back one if it
351 /// was previously past that position. Return 0 otherwise.
352 int checkBiblio(bool track_changes);
354 /// For each author, set 'used' to true if there is a change
355 /// by this author in the paragraph.
356 void checkAuthors(AuthorList const & authorList);
359 void changeCase(BufferParams const & bparams, pos_type pos,
360 pos_type & right, TextCase action);
362 /// find \param str string inside Paragraph.
363 /// \return true if the specified string is at the specified position
364 /// \param del specifies whether deleted strings in ct mode will be considered
366 docstring const & str, ///< string to search
369 pos_type pos, ///< start from here.
370 bool del = true) const;
373 void updateWords(Cursor const & cur);
377 void deregisterWords();
379 void registerWords(Cursor const & cur);
384 friend class Paragraph::Private;
391 #endif // PARAGRAPH_H