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