]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Revert unintentional commits.
[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         /// the font used by the CJK command
189         std::string fontsCJK;
190         ///
191         Spacing & spacing();
192         Spacing const & spacing() const;
193         ///
194         int secnumdepth;
195         ///
196         int tocdepth;
197         ///
198         Language const * language;
199         /// BranchList:
200         BranchList & branchlist();
201         BranchList const & branchlist() const;
202         /**
203          * The input encoding for LaTeX. This can be one of
204          * - \c auto: find out the input encoding from the used languages
205          * - \c default: ditto
206          * - any encoding supported by the inputenc package
207          * The encoding of the LyX file is always utf8 and has nothing to
208          * do with this setting.
209          * The difference between \c auto and \c default is that \c auto also
210          * causes loading of the inputenc package, while \c default does not.
211          * \c default will not work unless the user takes additional measures
212          * (such as using special environments like the CJK environment from
213          * CJK.sty).
214          * \c default can be seen as an unspecified 8bit encoding, since LyX
215          * does not interpret it in any way apart from display on screen.
216          */
217         std::string inputenc;
218         /// The main encoding used by this buffer for LaTeX output.
219         /// Individual pieces of text can use different encodings.
220         Encoding const & encoding() const;
221         ///
222         std::string preamble;
223         ///
224         std::string local_layout;
225         ///
226         std::string options;
227         ///
228         std::string master;
229         ///
230         std::string float_placement;
231         ///
232         unsigned int columns;
233         /// parameters for the listings package
234         std::string listings_params;
235         ///
236         PageSides sides;
237         ///
238         std::string pagestyle;
239         /// \param index should lie in the range 0 <= \c index <= 3.
240         Bullet & temp_bullet(size_type index);
241         Bullet const & temp_bullet(size_type index) const;
242         /// \param index should lie in the range 0 <= \c index <= 3.
243         Bullet & user_defined_bullet(size_type index);
244         Bullet const & user_defined_bullet(size_type index) const;
245
246         /// Whether to load a package such as amsmath or esint.
247         /// The enum values must not be changed (file format!)
248         enum Package {
249                 /// Don't load the package. For experts only.
250                 package_off = 0,
251                 /// Load the package if needed (recommended)
252                 package_auto = 1,
253                 /// Always load the package (e.g. if the document contains
254                 /// some ERT that needs the package)
255                 package_on = 2
256         };
257         /// Whether and how to load amsmath
258         Package use_amsmath;
259         /// Whether and how to load esint
260         Package use_esint;
261         ///
262         bool use_bibtopic;
263         /// revision tracking for this buffer ?
264         bool trackChanges;
265         /** This param decides whether change tracking marks should be used
266          *  in output (irrespective of how these marks are actually defined;
267          *  for instance, they may differ for DVI and PDF generation)
268          */
269         bool outputChanges;
270         ///
271         bool compressed;
272
273         /// the author list for the document
274         AuthorList & authors();
275         AuthorList const & authors() const;
276
277         /// map of the file's author IDs to buffer author IDs
278         std::vector<unsigned int> author_map;
279         ///
280         std::string const dvips_options() const;
281         /** The return value of paperSizeName() depends on the
282          *  purpose for which the paper size is needed, since they
283          *  support different subsets of paper sizes.
284         */
285         enum PapersizePurpose {
286                 ///
287                 DVIPS,
288                 ///
289                 DVIPDFM,
290                 ///
291                 XDVI
292         };
293         ///
294         std::string paperSizeName(PapersizePurpose purpose) const;
295         /// set up if and how babel is called
296         std::string babelCall(std::string const & lang_opts) const;
297         /// handle inputenc etc.
298         void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
299                                               TexRow & texrow) const;
300         /// set up the document fonts
301         std::string const loadFonts(std::string const & rm,
302                                      std::string const & sf, std::string const & tt,
303                                      bool const & sc, bool const & osf,
304                                      int const & sfscale, int const & ttscale) const;
305
306         /// get the appropriate cite engine (natbib handling)
307         CiteEngine citeEngine() const;
308         ///
309         void setCiteEngine(CiteEngine const);
310
311         /// options for pdf output
312         PDFOptions & pdfoptions();
313         PDFOptions const & pdfoptions() const;
314
315 private:
316         ///
317         void readPreamble(Lexer &);
318         ///
319         void readLocalLayout(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         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