]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
2e670f3eeb13544a2cd044a03962474379241b6a
[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 also calls makeTextClass(), to update the local
113         ///TextClass.
114         bool setBaseClass(textclass_type);
115         ///Returns the TextClass currently in use: the BaseClass as modified
116         ///by modules.
117         TextClass const & getTextClass() const;
118         ///Returns a pointer to the TextClass currently in use: the BaseClass 
119         ///as modified by modules. (See \file TextClassPtr.h for the typedef.)
120         TextClassPtr getTextClassPtr() const;
121         ///Set the LyX TextClass---layout file---this document is using.
122         ///This does NOT call makeTextClass() and so should be used with
123         ///care. This is most likely not what you want if you are operating on 
124         ///BufferParams that are actually associatd with a Buffer. If, on the
125         ///other hand, you are using a temporary set of BufferParams---say, in
126         ///a controller, it may well be, since in that case the local TextClass
127         ///has nothing to do.
128         void setJustBaseClass(textclass_type);
129         /// This bypasses the baseClass and sets the textClass directly.
130         /// Should be called with care and would be better not being here,
131         /// but it seems to be needed by CutAndPaste::putClipboard().
132         void setTextClass(TextClassPtr);
133         /// List of modules in use
134         std::vector<std::string> const & getModules() const;
135         /// Add a module to the list of modules in use.
136         /// Returns true if module was successfully added.
137         bool addLayoutModule(std::string modName, bool makeClass = true);
138         /// Add a list of modules.
139         /// Returns true if all modules were successfully added.
140         bool addLayoutModules(std::vector<std::string>modNames);
141         /// Clear the list
142         void clearLayoutModules();
143
144         /// returns the main font for the buffer (document)
145         Font const getFont() const;
146
147         /* this are for the PaperLayout */
148         /// the papersize
149         PAPER_SIZE papersize;
150         ///
151         PAPER_ORIENTATION orientation;
152         /// use custom margins
153         bool use_geometry;
154         ///
155         std::string paperwidth;
156         ///
157         std::string paperheight;
158         ///
159         std::string leftmargin;
160         ///
161         std::string topmargin;
162         ///
163         std::string rightmargin;
164         ///
165         std::string bottommargin;
166         ///
167         std::string headheight;
168         ///
169         std::string headsep;
170         ///
171         std::string footskip;
172
173         /* some LaTeX options */
174         /// The graphics driver
175         std::string graphicsDriver;
176         /// the rm font
177         std::string fontsRoman;
178         /// the sf font
179         std::string fontsSans;
180         /// the tt font
181         std::string fontsTypewriter;
182         /// the default family (rm, sf, tt)
183         std::string fontsDefaultFamily;
184         /// use expert Small Caps
185         bool fontsSC;
186         /// use Old Style Figures
187         bool fontsOSF;
188         /// the scale factor of the sf font
189         int fontsSansScale;
190         /// the scale factor of the tt font
191         int fontsTypewriterScale;
192         ///
193         Spacing & spacing();
194         Spacing const & spacing() const;
195         ///
196         int secnumdepth;
197         ///
198         int tocdepth;
199         ///
200         Language const * language;
201         /// BranchList:
202         BranchList & branchlist();
203         BranchList const & branchlist() const;
204         /**
205          * The input encoding for LaTeX. This can be one of
206          * - \c auto: find out the input encoding from the used languages
207          * - \c default: ditto
208          * - any encoding supported by the inputenc package
209          * The encoding of the LyX file is always utf8 and has nothing to
210          * do with this setting.
211          * The difference between \c auto and \c default is that \c auto also
212          * causes loading of the inputenc package, while \c default does not.
213          * \c default will not work unless the user takes additional measures
214          * (such as using special environments like the CJK environment from
215          * CJK.sty).
216          * \c default can be seen as an unspecified 8bit encoding, since LyX
217          * does not interpret it in any way apart from display on screen.
218          */
219         std::string inputenc;
220         /// The main encoding used by this buffer for LaTeX output.
221         /// Individual pieces of text can use different encodings.
222         Encoding const & encoding() const;
223         ///
224         std::string preamble;
225         ///
226         std::string options;
227         ///
228         std::string float_placement;
229         ///
230         unsigned int columns;
231         /// parameters for the listings package
232         std::string listings_params;
233         ///
234         PageSides sides;
235         ///
236         std::string pagestyle;
237         /// \param index should lie in the range 0 <= \c index <= 3.
238         Bullet & temp_bullet(size_type index);
239         Bullet const & temp_bullet(size_type index) const;
240         /// \param index should lie in the range 0 <= \c index <= 3.
241         Bullet & user_defined_bullet(size_type index);
242         Bullet const & user_defined_bullet(size_type index) const;
243
244         /// Whether to load a package such as amsmath or esint.
245         /// The enum values must not be changed (file format!)
246         enum Package {
247                 /// Don't load the package. For experts only.
248                 package_off = 0,
249                 /// Load the package if needed (recommended)
250                 package_auto = 1,
251                 /// Always load the package (e.g. if the document contains
252                 /// some ERT that needs the package)
253                 package_on = 2
254         };
255         /// Whether and how to load amsmath
256         Package use_amsmath;
257         /// Whether and how to load esint
258         Package use_esint;
259         ///
260         bool use_bibtopic;
261         /// revision tracking for this buffer ?
262         bool trackChanges;
263         /** This param decides whether change tracking marks should be used
264          *  in output (irrespective of how these marks are actually defined;
265          *  for instance, they may differ for DVI and PDF generation)
266          */
267         bool outputChanges;
268         ///
269         bool compressed;
270         ///
271         bool embedded;
272
273         /// the author list for the document
274         AuthorList & authors();
275         AuthorList const & authors() const;
276
277         /// map of the file's author IDs to buffer author IDs
278         std::vector<unsigned int> author_map;
279         ///
280         std::string const dvips_options() const;
281         ///
282         std::string const paperSizeName() const;
283         /// set up if and how babel is called
284         std::string const babelCall(std::string const & lang_opts) const;
285         /// handle inputenc etc.
286         void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
287                                               TexRow & texrow) const;
288         /// set up the document fonts
289         std::string const loadFonts(std::string const & rm,
290                                      std::string const & sf, std::string const & tt,
291                                      bool const & sc, bool const & osf,
292                                      int const & sfscale, int const & ttscale) const;
293
294         /// get the appropriate cite engine (natbib handling)
295         biblio::CiteEngine getEngine() const;
296
297         ///
298         void setCiteEngine(biblio::CiteEngine const);
299
300         /// options for pdf output
301         PDFOptions & pdfoptions();
302         PDFOptions const & pdfoptions() const;
303
304 private:
305         ///
306         void readPreamble(Lexer &);
307         ///
308         void readLanguage(Lexer &);
309         ///
310         void readGraphicsDriver(Lexer &);
311         ///
312         void readBullets(Lexer &);
313         ///
314         void readBulletsLaTeX(Lexer &);
315         ///
316         void readModules(Lexer &);
317         /// Adds the module information to the baseClass information to
318         /// create our local TextClass.
319         void makeTextClass();
320
321         
322         /// for use with natbib
323         biblio::CiteEngine cite_engine_;
324         /// the base TextClass associated with the document
325         textclass_type baseClass_;
326         /// the possibly modular TextClass actually in use
327         TextClassPtr textClass_;
328         ///
329         typedef std::vector<std::string> LayoutModuleList;
330         /// 
331         LayoutModuleList layoutModules_;
332
333         /** Use the Pimpl idiom to hide those member variables that would otherwise
334          *  drag in other header files.
335          */
336         class Impl;
337         class MemoryTraits {
338         public:
339                 static Impl * clone(Impl const *);
340                 static void destroy(Impl *);
341         };
342         support::copied_ptr<Impl, MemoryTraits> pimpl_;
343
344 };
345
346 } // namespace lyx
347
348 #endif