]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
dae8c4e3b2a086149e513f1cdef6bfd13685d69b
[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 <vector>
27
28 namespace lyx {
29
30 namespace support { class FileName; }
31
32 class AuthorList;
33 class BranchList;
34 class Bullet;
35 class DocumentClass;
36 class Encoding;
37 class Language;
38 class LatexFeatures;
39 class LayoutFile;
40 class LayoutFileIndex;
41 class Lexer;
42 class PDFOptions;
43 class Spacing;
44 class TexRow;
45 class VSpace;
46
47 /** Buffer parameters.
48  *  This class contains all the parameters for this buffer's use. Some
49  *  work needs to be done on this class to make it nice. Now everything
50  *  is in public.
51  */
52 class BufferParams {
53 public:
54         ///
55         enum ParagraphSeparation {
56                 ///
57                 ParagraphIndentSeparation,
58                 ///
59                 ParagraphSkipSeparation
60         };
61         ///
62         BufferParams();
63
64         /// get l10n translated to the buffers language
65         docstring B_(std::string const & l10n) const;
66
67         /// read a header token, if unrecognised, return it or an unknown class name
68         std::string readToken(Lexer & lex,
69                 std::string const & token, ///< token to read.
70                 support::FileName const & filepath);
71
72         ///
73         void writeFile(std::ostream &) const;
74
75         /// check what features are implied by the buffer parameters.
76         void validate(LaTeXFeatures &) 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         bool hasClassDefaults() const;
88
89         ///
90         VSpace const & getDefSkip() const;
91         ///
92         void setDefSkip(VSpace const & vs);
93
94         /** Whether paragraphs are separated by using a indent like in
95          *  articles or by using a little skip like in letters.
96          */
97         ParagraphSeparation paragraph_separation;
98         ///
99         InsetQuotes::QuoteLanguage quotes_language;
100         ///
101         InsetQuotes::QuoteTimes quotes_times;
102         ///
103         std::string fontsize;
104         ///Get the LayoutFile this document is using.
105         LayoutFile const * baseClass() const;
106         ///
107         LayoutFileIndex const & baseClassID() const;
108         /// Set the LyX layout file this document is using.
109         /// NOTE: This does not call makeDocumentClass() to update the local 
110         /// DocumentClass. That needs to be done manually.
111         /// \param filename the name of the layout file
112         bool setBaseClass(std::string const & classname);
113         /// Adds the module information to the baseClass information to
114         /// create our local DocumentClass.
115         void makeDocumentClass();
116         /// Returns the DocumentClass currently in use: the BaseClass as modified
117         /// by modules.
118         DocumentClass const & documentClass() const;
119         /// \return A pointer to the DocumentClass currently in use: the BaseClass 
120         /// as modified by modules. 
121         DocumentClass const * documentClassPtr() const;
122         /// This bypasses the baseClass and sets the textClass directly.
123         /// Should be called with care and would be better not being here,
124         /// but it seems to be needed by CutAndPaste::putClipboard().
125         void setDocumentClass(DocumentClass const * const);
126         /// List of modules in use
127         std::vector<std::string> const & getModules() const;
128         /// Add a module to the list of modules in use.
129         /// Returns true if module was successfully added.
130         /// The makeClass variable signals whether to call makeDocumentClass. This
131         /// need not be done if we know this isn't the final time through, or if
132         /// the BufferParams do not represent the parameters for an actual buffer
133         /// (as in GuiDocument).
134         bool addLayoutModule(std::string const & modName);
135         /// Clear the list
136         void clearLayoutModules();
137
138         /// returns the main font for the buffer (document)
139         Font const getFont() const;
140
141         /* this are for the PaperLayout */
142         /// the papersize
143         PAPER_SIZE papersize;
144         ///
145         PAPER_ORIENTATION orientation;
146         /// use custom margins
147         bool use_geometry;
148         ///
149         std::string paperwidth;
150         ///
151         std::string paperheight;
152         ///
153         std::string leftmargin;
154         ///
155         std::string topmargin;
156         ///
157         std::string rightmargin;
158         ///
159         std::string bottommargin;
160         ///
161         std::string headheight;
162         ///
163         std::string headsep;
164         ///
165         std::string footskip;
166         ///
167         std::string columnsep;
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 local_layout;
223         ///
224         std::string options;
225         ///
226         std::string master;
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         /// the author list for the document
272         AuthorList & authors();
273         AuthorList const & authors() const;
274
275         /// map of the file's author IDs to buffer author IDs
276         std::vector<unsigned int> author_map;
277         ///
278         std::string const dvips_options() const;
279         /** The return value of paperSizeName() depends on the
280          *  purpose for which the paper size is needed, since they
281          *  support different subsets of paper sizes.
282         */
283         enum PapersizePurpose {
284                 ///
285                 DVIPS,
286                 ///
287                 DVIPDFM,
288                 ///
289                 XDVI
290         };
291         ///
292         std::string paperSizeName(PapersizePurpose purpose) const;
293         /// set up if and how babel is called
294         std::string babelCall(std::string const & lang_opts) const;
295         /// handle inputenc etc.
296         void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
297                                               TexRow & texrow) const;
298         /// set up the document fonts
299         std::string const loadFonts(std::string const & rm,
300                                      std::string const & sf, std::string const & tt,
301                                      bool const & sc, bool const & osf,
302                                      int const & sfscale, int const & ttscale) const;
303
304         /// get the appropriate cite engine (natbib handling)
305         CiteEngine citeEngine() const;
306         ///
307         void setCiteEngine(CiteEngine const);
308
309         /// options for pdf output
310         PDFOptions & pdfoptions();
311         PDFOptions const & pdfoptions() const;
312
313 private:
314         ///
315         void readPreamble(Lexer &);
316         ///
317         void readLocalLayout(Lexer &);
318         ///
319         void readLanguage(Lexer &);
320         ///
321         void readGraphicsDriver(Lexer &);
322         ///
323         void readBullets(Lexer &);
324         ///
325         void readBulletsLaTeX(Lexer &);
326         ///
327         void readModules(Lexer &);
328
329         /// for use with natbib
330         CiteEngine cite_engine_;
331         ///
332         DocumentClass * doc_class_;
333         ///
334         typedef std::vector<std::string> LayoutModuleList;
335         /// 
336         LayoutModuleList layoutModules_;
337
338         /** Use the Pimpl idiom to hide those member variables that would otherwise
339          *  drag in other header files.
340          */
341         class Impl;
342         class MemoryTraits {
343         public:
344                 static Impl * clone(Impl const *);
345                 static void destroy(Impl *);
346         };
347         support::copied_ptr<Impl, MemoryTraits> pimpl_;
348
349 };
350
351 } // namespace lyx
352
353 #endif