]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Whitespace.
[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 "Citation.h"
19 #include "Font.h"
20 #include "LayoutModuleList.h"
21 #include "paper.h"
22
23 #include "insets/InsetQuotes.h"
24
25 #include "support/copied_ptr.h"
26
27 #include <list>
28 #include <map>
29 #include <vector>
30
31 namespace lyx {
32
33 namespace support { class FileName; }
34
35 class AuthorList;
36 class BranchList;
37 class Bullet;
38 class DocumentClass;
39 class Encoding;
40 class HSpace;
41 class IndicesList;
42 class Language;
43 class LatexFeatures;
44 class LayoutFile;
45 class LayoutFileIndex;
46 class Lexer;
47 class PDFOptions;
48 class Spacing;
49 class TexRow;
50 class VSpace;
51
52 /** Buffer parameters.
53  *  This class contains all the parameters for this buffer's use. Some
54  *  work needs to be done on this class to make it nice. Now everything
55  *  is in public.
56  */
57 class BufferParams {
58 public:
59         ///
60         enum ParagraphSeparation {
61                 ///
62                 ParagraphIndentSeparation,
63                 ///
64                 ParagraphSkipSeparation
65         };
66         ///
67         BufferParams();
68
69         /// get l10n translated to the buffers language
70         docstring B_(std::string const & l10n) const;
71
72         /// read a header token, if unrecognised, return it or an unknown class name
73         std::string readToken(Lexer & lex,
74                 std::string const & token, ///< token to read.
75                 support::FileName const & filepath);
76
77         ///
78         void writeFile(std::ostream &) const;
79
80         /// check what features are implied by the buffer parameters.
81         void validate(LaTeXFeatures &) const;
82
83         /** \returns true if the babel package is used (interogates
84          *  the BufferParams and a LyXRC variable).
85          *  This returned value can then be passed to the insets...
86          */
87         bool writeLaTeX(odocstream &, LaTeXFeatures &, TexRow &) const;
88
89         ///
90         void useClassDefaults();
91         ///
92         bool hasClassDefaults() const;
93
94         ///
95         HSpace const & getIndentation() const;
96         ///
97         void setIndentation(HSpace const & indent);
98         ///
99         VSpace const & getDefSkip() const;
100         ///
101         void setDefSkip(VSpace const & vs);
102
103         /** Whether paragraphs are separated by using a indent like in
104          *  articles or by using a little skip like in letters.
105          */
106         ParagraphSeparation paragraph_separation;
107         ///
108         InsetQuotes::QuoteLanguage quotes_language;
109         ///
110         InsetQuotes::QuoteTimes quotes_times;
111         ///
112         std::string fontsize;
113         ///Get the LayoutFile this document is using.
114         LayoutFile const * baseClass() const;
115         ///
116         LayoutFileIndex const & baseClassID() const;
117         /// Set the LyX layout file this document is using.
118         /// NOTE: This does not call makeDocumentClass() to update the local 
119         /// DocumentClass. That needs to be done manually.
120         /// \param filename the name of the layout file
121         bool setBaseClass(std::string const & classname);
122         /// Adds the module information to the baseClass information to
123         /// create our local DocumentClass.
124         void makeDocumentClass();
125         /// Returns the DocumentClass currently in use: the BaseClass as modified
126         /// by modules.
127         DocumentClass const & documentClass() const;
128         /// \return A pointer to the DocumentClass currently in use: the BaseClass 
129         /// as modified by modules. 
130         DocumentClass const * documentClassPtr() const;
131         /// This bypasses the baseClass and sets the textClass directly.
132         /// Should be called with care and would be better not being here,
133         /// but it seems to be needed by CutAndPaste::putClipboard().
134         void setDocumentClass(DocumentClass const * const);
135         /// List of modules in use
136         LayoutModuleList const & getModules() const { return layoutModules_; }
137         /// List of default modules the user has removed
138         std::list<std::string> const & getRemovedModules() const 
139                         { return removedModules_; }
140         ///
141         /// Add a module to the list of modules in use. This checks only that the
142         /// module is not already in the list, so use moduleIsCompatible first if
143         /// you want to check for compatibility.
144         /// \return true if module was successfully added.
145         bool addLayoutModule(std::string const & modName);
146         /// checks to make sure module's requriements are satisfied, that it does
147         /// not conflict with already-present modules, isn't already loaded, etc.
148         bool moduleCanBeAdded(std::string const & modName) const;
149         ///
150         void addRemovedModule(std::string const & modName) 
151                         { removedModules_.push_back(modName); }
152         /// Clear the list
153         void clearLayoutModules() { layoutModules_.clear(); }
154         /// Clear the removed module list
155         void clearRemovedModules() { removedModules_.clear(); }
156
157         /// returns the main font for the buffer (document)
158         Font const getFont() const;
159
160         /* these are for the PaperLayout */
161         /// the papersize
162         PAPER_SIZE papersize;
163         ///
164         PAPER_ORIENTATION orientation;
165         /// use custom margins
166         bool use_geometry;
167         ///
168         std::string paperwidth;
169         ///
170         std::string paperheight;
171         ///
172         std::string leftmargin;
173         ///
174         std::string topmargin;
175         ///
176         std::string rightmargin;
177         ///
178         std::string bottommargin;
179         ///
180         std::string headheight;
181         ///
182         std::string headsep;
183         ///
184         std::string footskip;
185         ///
186         std::string columnsep;
187
188         /* some LaTeX options */
189         /// The graphics driver
190         std::string graphicsDriver;
191         /// The default output format
192         std::string defaultOutputFormat;
193         /// customized bibliography processor
194         std::string bibtex_command;
195         /// customized index processor
196         std::string index_command;
197         /// font encoding
198         std::string fontenc;
199         /// the rm font
200         std::string fontsRoman;
201         /// the sf font
202         std::string fontsSans;
203         /// the tt font
204         std::string fontsTypewriter;
205         /// the default family (rm, sf, tt)
206         std::string fontsDefaultFamily;
207         /// use the XeTeX processor
208         bool useXetex;
209         /// use expert Small Caps
210         bool fontsSC;
211         /// use Old Style Figures
212         bool fontsOSF;
213         /// the scale factor of the sf font
214         int fontsSansScale;
215         /// the scale factor of the tt font
216         int fontsTypewriterScale;
217         /// the font used by the CJK command
218         std::string fontsCJK;
219         ///
220         Spacing & spacing();
221         Spacing const & spacing() const;
222         ///
223         int secnumdepth;
224         ///
225         int tocdepth;
226         ///
227         Language const * language;
228         /// BranchList:
229         BranchList & branchlist();
230         BranchList const & branchlist() const;
231         /// IndicesList:
232         IndicesList & indiceslist();
233         IndicesList const & indiceslist() const;
234         /**
235          * The input encoding for LaTeX. This can be one of
236          * - \c auto: find out the input encoding from the used languages
237          * - \c default: ditto
238          * - any encoding supported by the inputenc package
239          * The encoding of the LyX file is always utf8 and has nothing to
240          * do with this setting.
241          * The difference between \c auto and \c default is that \c auto also
242          * causes loading of the inputenc package, while \c default does not.
243          * \c default will not work unless the user takes additional measures
244          * (such as using special environments like the CJK environment from
245          * CJK.sty).
246          * \c default can be seen as an unspecified 8bit encoding, since LyX
247          * does not interpret it in any way apart from display on screen.
248          */
249         std::string inputenc;
250         /// The main encoding used by this buffer for LaTeX output.
251         /// Individual pieces of text can use different encodings.
252         Encoding const & encoding() const;
253         ///
254         std::string preamble;
255         ///
256         std::string local_layout;
257         ///
258         std::string options;
259         /// use the class options defined in the layout?
260         bool use_default_options;
261         ///
262         std::string master;
263         ///
264         bool suppress_date;
265         ///
266         std::string float_placement;
267         ///
268         unsigned int columns;
269         /// parameters for the listings package
270         std::string listings_params;
271         ///
272         PageSides sides;
273         ///
274         std::string pagestyle;
275         ///
276         RGBColor backgroundcolor;
277         /// \param index should lie in the range 0 <= \c index <= 3.
278         Bullet & temp_bullet(size_type index);
279         Bullet const & temp_bullet(size_type index) const;
280         /// \param index should lie in the range 0 <= \c index <= 3.
281         Bullet & user_defined_bullet(size_type index);
282         Bullet const & user_defined_bullet(size_type index) const;
283
284         /// Whether to load a package such as amsmath or esint.
285         /// The enum values must not be changed (file format!)
286         enum Package {
287                 /// Don't load the package. For experts only.
288                 package_off = 0,
289                 /// Load the package if needed (recommended)
290                 package_auto = 1,
291                 /// Always load the package (e.g. if the document contains
292                 /// some ERT that needs the package)
293                 package_on = 2
294         };
295         /// Whether and how to load amsmath
296         Package use_amsmath;
297         /// Whether and how to load esint
298         Package use_esint;
299         /// Whether and how to load mhchem
300         Package use_mhchem;
301         /// Split bibliography?
302         bool use_bibtopic;
303         /// Split the index?
304         bool use_indices;
305         /// revision tracking for this buffer ?
306         bool trackChanges;
307         /** This param decides whether change tracking marks should be used
308          *  in output (irrespective of how these marks are actually defined;
309          *  for instance, they may differ for DVI and PDF generation)
310          */
311         bool outputChanges;
312         ///
313         bool compressed;
314
315         /// the author list for the document
316         AuthorList & authors();
317         AuthorList const & authors() const;
318
319         /// map of the file's author IDs to AuthorList indexes
320         std::map<unsigned int, int> author_map;
321         /// the buffer's font encoding
322         std::string const font_encoding() const;
323         ///
324         std::string const dvips_options() const;
325         /** The return value of paperSizeName() depends on the
326          *  purpose for which the paper size is needed, since they
327          *  support different subsets of paper sizes.
328         */
329         enum PapersizePurpose {
330                 ///
331                 DVIPS,
332                 ///
333                 DVIPDFM,
334                 ///
335                 XDVI
336         };
337         ///
338         std::string paperSizeName(PapersizePurpose purpose) const;
339         /// set up if and how babel is called
340         std::string babelCall(std::string const & lang_opts) const;
341         /// return supported drivers for specific packages
342         docstring getGraphicsDriver(std::string const & package) const;
343         /// handle inputenc etc.
344         void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
345                                               TexRow & texrow) const;
346         ///
347         std::string const parseFontName(std::string const & name) const;
348         /// set up the document fonts
349         std::string const loadFonts(std::string const & rm,
350                                      std::string const & sf, std::string const & tt,
351                                      bool const & sc, bool const & osf,
352                                      int const & sfscale, int const & ttscale,
353                                      bool const & xetex) const;
354
355         /// get the appropriate cite engine (natbib handling)
356         CiteEngine citeEngine() const;
357         ///
358         void setCiteEngine(CiteEngine const);
359
360         /// options for pdf output
361         PDFOptions & pdfoptions();
362         PDFOptions const & pdfoptions() const;
363
364         /// whether to use MathML for math output, or instead images
365         bool html_use_mathml;
366         /// whether to attempt to be XHTML 1.1 compliant or instead be
367         /// a little more mellow
368         bool html_be_strict;
369
370 private:
371         ///
372         void readPreamble(Lexer &);
373         ///
374         void readLocalLayout(Lexer &);
375         ///
376         void readLanguage(Lexer &);
377         ///
378         void readGraphicsDriver(Lexer &);
379         ///
380         void readBullets(Lexer &);
381         ///
382         void readBulletsLaTeX(Lexer &);
383         ///
384         void readModules(Lexer &);
385         ///
386         void readRemovedModules(Lexer &);
387         /// for use with natbib
388         CiteEngine cite_engine_;
389         ///
390         DocumentClass * doc_class_;
391         /// 
392         LayoutModuleList layoutModules_;
393         /// this is for modules that are required by the document class but that
394         /// the user has chosen not to use
395         std::list<std::string> removedModules_;
396
397         /** Use the Pimpl idiom to hide those member variables that would otherwise
398          *  drag in other header files.
399          */
400         class Impl;
401         class MemoryTraits {
402         public:
403                 static Impl * clone(Impl const *);
404                 static void destroy(Impl *);
405         };
406         support::copied_ptr<Impl, MemoryTraits> pimpl_;
407
408 };
409
410 } // namespace lyx
411
412 #endif