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