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