]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Added Liviu Andronic, and modified generate_contributions.py to match what was in...
[lyx.git] / src / BufferParams.h
1 // -*- C++ -*-
2 /**
3  * \file BufferParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  * \author André Pönitz
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef BUFFERPARAMS_H
16 #define BUFFERPARAMS_H
17
18 #include "Font.h"
19 #include "Citation.h"
20 #include "paper.h"
21
22 #include "insets/InsetQuotes.h"
23
24 #include "support/copied_ptr.h"
25
26 #include <set>
27 #include <vector>
28
29 namespace lyx {
30
31 namespace support { class FileName; }
32
33 class AuthorList;
34 class BranchList;
35 class Bullet;
36 class DocumentClass;
37 class Encoding;
38 class Language;
39 class LatexFeatures;
40 class LayoutFile;
41 class LayoutFileIndex;
42 class Lexer;
43 class PDFOptions;
44 class Spacing;
45 class TexRow;
46 class VSpace;
47
48 /** Buffer parameters.
49  *  This class contains all the parameters for this buffer's use. Some
50  *  work needs to be done on this class to make it nice. Now everything
51  *  is in public.
52  */
53 class BufferParams {
54 public:
55         ///
56         typedef std::vector<std::string> LayoutModuleList;
57         ///
58         enum ParagraphSeparation {
59                 ///
60                 ParagraphIndentSeparation,
61                 ///
62                 ParagraphSkipSeparation
63         };
64         ///
65         BufferParams();
66
67         /// get l10n translated to the buffers language
68         docstring B_(std::string const & l10n) const;
69
70         /// read a header token, if unrecognised, return it or an unknown class name
71         std::string readToken(Lexer & lex,
72                 std::string const & token, ///< token to read.
73                 support::FileName const & filepath);
74
75         ///
76         void writeFile(std::ostream &) const;
77
78         /// check what features are implied by the buffer parameters.
79         void validate(LaTeXFeatures &) const;
80
81         /** \returns true if the babel package is used (interogates
82          *  the BufferParams and a LyXRC variable).
83          *  This returned value can then be passed to the insets...
84          */
85         bool writeLaTeX(odocstream &, LaTeXFeatures &, TexRow &) const;
86
87         ///
88         void useClassDefaults();
89         ///
90         bool hasClassDefaults() const;
91
92         ///
93         VSpace const & getDefSkip() const;
94         ///
95         void setDefSkip(VSpace const & vs);
96
97         /** Whether paragraphs are separated by using a indent like in
98          *  articles or by using a little skip like in letters.
99          */
100         ParagraphSeparation paragraph_separation;
101         ///
102         InsetQuotes::QuoteLanguage quotes_language;
103         ///
104         InsetQuotes::QuoteTimes quotes_times;
105         ///
106         std::string fontsize;
107         ///Get the LayoutFile this document is using.
108         LayoutFile const * baseClass() const;
109         ///
110         LayoutFileIndex const & baseClassID() const;
111         /// Set the LyX layout file this document is using.
112         /// NOTE: This does not call makeDocumentClass() to update the local 
113         /// DocumentClass. That needs to be done manually.
114         /// \param filename the name of the layout file
115         bool setBaseClass(std::string const & classname);
116         /// Adds the module information to the baseClass information to
117         /// create our local DocumentClass.
118         void makeDocumentClass();
119         /// Returns the DocumentClass currently in use: the BaseClass as modified
120         /// by modules.
121         DocumentClass const & documentClass() const;
122         /// \return A pointer to the DocumentClass currently in use: the BaseClass 
123         /// as modified by modules. 
124         DocumentClass const * documentClassPtr() const;
125         /// This bypasses the baseClass and sets the textClass directly.
126         /// Should be called with care and would be better not being here,
127         /// but it seems to be needed by CutAndPaste::putClipboard().
128         void setDocumentClass(DocumentClass const * const);
129         /// List of modules in use
130         LayoutModuleList const & getModules() const { return layoutModules_; }
131         /// List of default modules the user has removed
132         std::set<std::string> const & getRemovedModules() const 
133                         { return removedModules_; }
134         ///
135         /// Add a module to the list of modules in use.
136         /// Returns true if module was successfully added.
137         /// The makeClass variable signals whether to call makeDocumentClass. This
138         /// need not be done if we know this isn't the final time through, or if
139         /// the BufferParams do not represent the parameters for an actual buffer
140         /// (as in GuiDocument).
141         bool addLayoutModule(std::string const & modName);
142         ///
143         void addRemovedModule(std::string const & modName) 
144                         { removedModules_.insert(modName); }
145         /// Clear the list
146         void clearLayoutModules() { layoutModules_.clear(); }
147         /// Clear the removed module list
148         void clearRemovedModules() { removedModules_.clear(); }
149
150         /// returns the main font for the buffer (document)
151         Font const getFont() const;
152
153         /* this are for the PaperLayout */
154         /// the papersize
155         PAPER_SIZE papersize;
156         ///
157         PAPER_ORIENTATION orientation;
158         /// use custom margins
159         bool use_geometry;
160         ///
161         std::string paperwidth;
162         ///
163         std::string paperheight;
164         ///
165         std::string leftmargin;
166         ///
167         std::string topmargin;
168         ///
169         std::string rightmargin;
170         ///
171         std::string bottommargin;
172         ///
173         std::string headheight;
174         ///
175         std::string headsep;
176         ///
177         std::string footskip;
178         ///
179         std::string columnsep;
180
181         /* some LaTeX options */
182         /// The graphics driver
183         std::string graphicsDriver;
184         /// the rm font
185         std::string fontsRoman;
186         /// the sf font
187         std::string fontsSans;
188         /// the tt font
189         std::string fontsTypewriter;
190         /// the default family (rm, sf, tt)
191         std::string fontsDefaultFamily;
192         /// use expert Small Caps
193         bool fontsSC;
194         /// use Old Style Figures
195         bool fontsOSF;
196         /// the scale factor of the sf font
197         int fontsSansScale;
198         /// the scale factor of the tt font
199         int fontsTypewriterScale;
200         /// the font used by the CJK command
201         std::string fontsCJK;
202         ///
203         Spacing & spacing();
204         Spacing const & spacing() const;
205         ///
206         int secnumdepth;
207         ///
208         int tocdepth;
209         ///
210         Language const * language;
211         /// BranchList:
212         BranchList & branchlist();
213         BranchList const & branchlist() const;
214         /**
215          * The input encoding for LaTeX. This can be one of
216          * - \c auto: find out the input encoding from the used languages
217          * - \c default: ditto
218          * - any encoding supported by the inputenc package
219          * The encoding of the LyX file is always utf8 and has nothing to
220          * do with this setting.
221          * The difference between \c auto and \c default is that \c auto also
222          * causes loading of the inputenc package, while \c default does not.
223          * \c default will not work unless the user takes additional measures
224          * (such as using special environments like the CJK environment from
225          * CJK.sty).
226          * \c default can be seen as an unspecified 8bit encoding, since LyX
227          * does not interpret it in any way apart from display on screen.
228          */
229         std::string inputenc;
230         /// The main encoding used by this buffer for LaTeX output.
231         /// Individual pieces of text can use different encodings.
232         Encoding const & encoding() const;
233         ///
234         std::string preamble;
235         ///
236         std::string local_layout;
237         ///
238         std::string options;
239         ///
240         std::string master;
241         ///
242         std::string float_placement;
243         ///
244         unsigned int columns;
245         /// parameters for the listings package
246         std::string listings_params;
247         ///
248         PageSides sides;
249         ///
250         std::string pagestyle;
251         /// \param index should lie in the range 0 <= \c index <= 3.
252         Bullet & temp_bullet(size_type index);
253         Bullet const & temp_bullet(size_type index) const;
254         /// \param index should lie in the range 0 <= \c index <= 3.
255         Bullet & user_defined_bullet(size_type index);
256         Bullet const & user_defined_bullet(size_type index) const;
257
258         /// Whether to load a package such as amsmath or esint.
259         /// The enum values must not be changed (file format!)
260         enum Package {
261                 /// Don't load the package. For experts only.
262                 package_off = 0,
263                 /// Load the package if needed (recommended)
264                 package_auto = 1,
265                 /// Always load the package (e.g. if the document contains
266                 /// some ERT that needs the package)
267                 package_on = 2
268         };
269         /// Whether and how to load amsmath
270         Package use_amsmath;
271         /// Whether and how to load esint
272         Package use_esint;
273         ///
274         bool use_bibtopic;
275         /// revision tracking for this buffer ?
276         bool trackChanges;
277         /** This param decides whether change tracking marks should be used
278          *  in output (irrespective of how these marks are actually defined;
279          *  for instance, they may differ for DVI and PDF generation)
280          */
281         bool outputChanges;
282         ///
283         bool compressed;
284
285         /// the author list for the document
286         AuthorList & authors();
287         AuthorList const & authors() const;
288
289         /// map of the file's author IDs to buffer author IDs
290         std::vector<unsigned int> author_map;
291         ///
292         std::string const dvips_options() const;
293         /** The return value of paperSizeName() depends on the
294          *  purpose for which the paper size is needed, since they
295          *  support different subsets of paper sizes.
296         */
297         enum PapersizePurpose {
298                 ///
299                 DVIPS,
300                 ///
301                 DVIPDFM,
302                 ///
303                 XDVI
304         };
305         ///
306         std::string paperSizeName(PapersizePurpose purpose) const;
307         /// set up if and how babel is called
308         std::string babelCall(std::string const & lang_opts) const;
309         /// handle inputenc etc.
310         void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
311                                               TexRow & texrow) const;
312         /// set up the document fonts
313         std::string const loadFonts(std::string const & rm,
314                                      std::string const & sf, std::string const & tt,
315                                      bool const & sc, bool const & osf,
316                                      int const & sfscale, int const & ttscale) const;
317
318         /// get the appropriate cite engine (natbib handling)
319         CiteEngine citeEngine() const;
320         ///
321         void setCiteEngine(CiteEngine const);
322
323         /// options for pdf output
324         PDFOptions & pdfoptions();
325         PDFOptions const & pdfoptions() const;
326
327 private:
328         ///
329         void readPreamble(Lexer &);
330         ///
331         void readLocalLayout(Lexer &);
332         ///
333         void readLanguage(Lexer &);
334         ///
335         void readGraphicsDriver(Lexer &);
336         ///
337         void readBullets(Lexer &);
338         ///
339         void readBulletsLaTeX(Lexer &);
340         ///
341         void readModules(Lexer &);
342         ///
343         void readRemovedModules(Lexer &);
344
345         /// for use with natbib
346         CiteEngine cite_engine_;
347         ///
348         DocumentClass * doc_class_;
349         /// 
350         LayoutModuleList layoutModules_;
351         /// this is for modules that are required by the document class but that
352         /// the user has chosen not to use
353         std::set<std::string> removedModules_;
354
355         /** Use the Pimpl idiom to hide those member variables that would otherwise
356          *  drag in other header files.
357          */
358         class Impl;
359         class MemoryTraits {
360         public:
361                 static Impl * clone(Impl const *);
362                 static void destroy(Impl *);
363         };
364         support::copied_ptr<Impl, MemoryTraits> pimpl_;
365
366 };
367
368 } // namespace lyx
369
370 #endif