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