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"
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,
76 enum AsStringParameter
78 AS_STR_NONE = 0, ///< No option, only printable characters.
79 AS_STR_LABEL = 1, ///< Prefix with paragraph label.
80 AS_STR_INSETS = 2 ///< Go into insets.
84 /// A Paragraph holds all text, attributes and insets in a text paragraph
91 Paragraph(Paragraph const &);
93 Paragraph & operator=(Paragraph const &);
100 Language const * getParLanguage(BufferParams const &) const;
102 bool isRTL(BufferParams const &) const;
104 void changeLanguage(BufferParams const & bparams,
105 Language const * from, Language const * to);
107 bool isMultiLingual(BufferParams const &) const;
109 /// Convert the paragraph to a string.
110 /// \param AsStringParameter options. This can contain any combination of
111 /// asStringParameter values. Valid examples:
112 /// asString(AS_STR_LABEL)
113 /// asString(AS_STR_LABEL | AS_STR_INSETS)
114 /// asString(AS_STR_INSETS)
115 docstring asString(int options = AS_STR_NONE) const;
117 docstring asString(pos_type beg, pos_type end,
118 int options = AS_STR_NONE) const;
121 void write(std::ostream &, BufferParams const &,
122 depth_type & depth) const;
124 void validate(LaTeXFeatures &) const;
127 bool latex(BufferParams const &, Font const & outerfont, odocstream &,
128 TexRow & texrow, OutputParams const &) const;
130 /// Can we drop the standard paragraph wrapper?
131 bool emptyTag() const;
133 /// Get the id of the paragraph, usefull for docbook
134 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
136 /// Get the first word of a paragraph, return the position where it left
137 pos_type firstWord(odocstream & os, OutputParams const & runparams) const;
139 /// Writes to stream the docbook representation
140 void simpleDocBookOnePar(Buffer const & buf,
142 OutputParams const & runparams,
143 Font const & outerfont,
144 pos_type initial = 0) const;
147 bool hasSameLayout(Paragraph const & par) const;
150 void makeSameLayout(Paragraph const & par);
153 void setInsetOwner(Inset * inset);
155 Inset * inInset() const;
157 InsetCode ownerCode() const;
159 bool forceEmptyLayout() const;
161 bool allowParagraphCustomization() const;
163 bool useEmptyLayout() const;
165 pos_type size() const;
170 Layout const & layout() const;
171 /// Do not pass a temporary to this!
172 void setLayout(Layout const & layout);
174 void setEmptyOrDefaultLayout(DocumentClass const & tc);
176 /// This is the item depth, only used by enumerate and itemize
177 signed char itemdepth;
179 /// look up change at given pos
180 Change const & lookupChange(pos_type pos) const;
182 /// is there a change within the given range ?
183 bool isChanged(pos_type start, pos_type end) const;
184 /// is there an unchanged char at the given pos ?
185 bool isUnchanged(pos_type pos) const;
186 /// is there an insertion at the given pos ?
187 bool isInserted(pos_type pos) const;
188 /// is there a deletion at the given pos ?
189 bool isDeleted(pos_type pos) const;
191 /// will the paragraph be physically merged with the next
192 /// one if the imaginary end-of-par character is logically deleted?
193 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
195 /// set change for the entire par
196 void setChange(Change const & change);
198 /// set change at given pos
199 void setChange(pos_type pos, Change const & change);
201 /// accept changes within the given range
202 void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
204 /// reject changes within the given range
205 void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
207 /// Paragraphs can contain "manual labels", for example, Description
208 /// environment. The text for this user-editable label is stored in
209 /// the paragraph alongside the text of the rest of the paragraph
210 /// (the body). This function returns the starting position of the
211 /// body of the text in the paragraph.
212 pos_type beginOfBody() const;
213 /// recompute this value
214 void setBeginOfBody();
217 docstring const & labelString() const;
219 /// the next two functions are for the manual labels
220 docstring const getLabelWidthString() const;
221 /// Set label width string.
222 void setLabelWidthString(docstring const & s);
223 /// translate \p label to the paragraph language if possible.
224 docstring const translateIfPossible(docstring const & label,
225 BufferParams const & bparams) const;
226 /// Expand the counters for the labelstring of \c layout
227 docstring expandLabel(Layout const &, BufferParams const &,
228 bool process_appendix = true) const;
229 /// Actual paragraph alignment used
230 char getAlign() const;
231 /// The nesting depth of a paragraph
232 depth_type getDepth() const;
233 /// The maximal possible depth of a paragraph after this one
234 depth_type getMaxDepthAfter() const;
236 void applyLayout(Layout const & new_layout);
238 /// (logically) erase the char at pos; return true if it was actually erased
239 bool eraseChar(pos_type pos, bool trackChanges);
240 /// (logically) erase the given range; return the number of chars actually erased
241 int eraseChars(pos_type start, pos_type end, bool trackChanges);
244 void resetFonts(Font const & font);
246 /** Get uninstantiated font setting. Returns the difference
247 between the characters font and the layoutfont.
248 This is what is stored in the fonttable
251 getFontSettings(BufferParams const &, pos_type pos) const;
253 Font const getFirstFontSettings(BufferParams const &) const;
255 /** Get fully instantiated font. If pos == -1, use the layout
256 font attached to this paragraph.
257 If pos == -2, use the label font of the layout attached here.
258 In all cases, the font is instantiated, i.e. does not have any
259 attributes with values FONT_INHERIT, FONT_IGNORE or
262 Font const getFont(BufferParams const &, pos_type pos,
263 Font const & outerfont) const;
264 Font const getLayoutFont(BufferParams const &,
265 Font const & outerfont) const;
266 Font const getLabelFont(BufferParams const &,
267 Font const & outerfont) const;
269 * The font returned by the above functions is the same in a
270 * span of characters. This method will return the first and
271 * the last positions in the paragraph for which that font is
272 * the same. This can be used to avoid unnecessary calls to getFont.
274 FontSpan fontSpan(pos_type pos) const;
276 char_type getChar(pos_type pos) const;
277 /// Get the char, but mirror all bracket characters if it is right-to-left
278 char_type getUChar(BufferParams const &, pos_type pos) const;
279 /// pos <= size() (there is a dummy font change at the end of each par)
280 void setFont(pos_type pos, Font const & font);
281 /// Returns the height of the highest font in range
282 FontSize highestFontInRange(pos_type startpos,
283 pos_type endpos, FontSize def_size) const;
285 void insert(pos_type pos, docstring const & str,
286 Font const & font, Change const & change);
289 void appendString(docstring const & s, Font const & font,
290 Change const & change);
292 void appendChar(char_type c, Font const & font, Change const & change);
294 void insertChar(pos_type pos, char_type c, bool trackChanges);
296 void insertChar(pos_type pos, char_type c,
297 Font const &, bool trackChanges);
299 void insertChar(pos_type pos, char_type c,
300 Font const &, Change const & change);
302 void insertInset(pos_type pos, Inset * inset,
303 Change const & change);
305 void insertInset(pos_type pos, Inset * inset,
306 Font const &, Change const & change);
308 bool insetAllowed(InsetCode code);
310 Inset * getInset(pos_type pos);
312 Inset const * getInset(pos_type pos) const;
314 /// Release inset at given position.
315 /// \warning does not honour change tracking!
316 /// Therefore, it should only be used for breaking and merging
318 Inset * releaseInset(pos_type pos);
321 InsetList const & insetList() const;
324 bool isHfill(pos_type pos) const;
326 /// hinted by profiler
327 bool isInset(pos_type pos) const;
329 bool isNewline(pos_type pos) const;
330 /// return true if the char is a word separator
331 bool isSeparator(pos_type pos) const;
333 bool isLineSeparator(pos_type pos) const;
334 /// True if the character/inset at this point can be part of a word.
335 /// Note that digits in particular are considered as letters
336 bool isLetter(pos_type pos) const;
338 /// returns true if at least one line break or line separator has been deleted
339 /// at the beginning of the paragraph (either physically or logically)
340 bool stripLeadingSpaces(bool trackChanges);
342 /// return true if we allow multiple spaces
343 bool isFreeSpacing() const;
345 /// return true if we allow this par to stay empty
346 bool allowEmpty() const;
348 char_type transformChar(char_type c, pos_type pos) const;
350 ParagraphParameters & params();
352 ParagraphParameters const & params() const;
354 /// Check if we are in a Biblio environment and insert or
355 /// delete InsetBibitems as necessary.
356 /// \retval int 1, if we had to add an inset, in which case
357 /// the cursor will need to move cursor forward; -pos, if we deleted
358 /// an inset, in which case pos is the position from which the inset
359 /// was deleted, and the cursor will need to be moved back one if it
360 /// was previously past that position. Return 0 otherwise.
361 int checkBiblio(Buffer const & buffer);
363 /// For each author, set 'used' to true if there is a change
364 /// by this author in the paragraph.
365 void checkAuthors(AuthorList const & authorList);
368 void changeCase(BufferParams const & bparams, pos_type pos,
369 pos_type & right, TextCase action);
371 /// find \param str string inside Paragraph.
372 /// \return true if the specified string is at the specified position
373 /// \param del specifies whether deleted strings in ct mode will be considered
375 docstring const & str, ///< string to search
378 pos_type pos, ///< start from here.
379 bool del = true) const;
382 void updateWords(CursorSlice const & sl);
386 void deregisterWords();
388 void collectWords(CursorSlice const & sl);
390 void registerWords();
395 friend class Paragraph::Private;
402 #endif // PARAGRAPH_H