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