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