]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Embed: allow the use of embedded layout and class (.cls, .sty) files.
[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 {
31 class FileName;
32 }
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         enum PARSEP {
58                 ///
59                 PARSEP_INDENT,
60                 ///
61                 PARSEP_SKIP
62         };
63         ///
64         BufferParams();
65         ~BufferParams();
66
67         /// get l10n translated to the buffers language
68         docstring const B_(std::string const & l10n) const;
69
70         /// read a header token, if unrecognised, return it or an unknown class name
71         std::string const readToken(Lexer & lex,
72                 std::string const & token, ///< token to read.
73                 support::FileName const & filepath,
74                 support::FileName const & temppath); ///< where to look for local layout file.
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         ///
92         bool hasClassDefaults() const;
93
94         ///
95         VSpace const & getDefSkip() const;
96
97         ///
98         void setDefSkip(VSpace const & vs);
99
100         /** Whether paragraphs are separated by using a indent like in
101          *  articles or by using a little skip like in letters.
102          */
103         PARSEP paragraph_separation;
104         ///
105         InsetQuotes::quote_language quotes_language;
106         ///
107         InsetQuotes::quote_times quotes_times;
108         ///
109         std::string fontsize;
110         ///Get the LayoutFile this document is using.
111         LayoutFile const * baseClass() const;
112         ///
113         LayoutFileIndex const & baseClassID() const;
114         /// Set the LyX layout file this document is using.
115         /// NOTE: This does not call makeDocumentClass() to update the local 
116         /// DocumentClass. That needs to be done manually.
117         /// \param filename the name of the layout file
118         bool setBaseClass(std::string const & classname);
119         /// Adds the module information to the baseClass information to
120         /// create our local DocumentClass.
121         void makeDocumentClass();
122         /// Returns the DocumentClass currently in use: the BaseClass as modified
123         /// by modules.
124         DocumentClass const & documentClass() const;
125         /// \return A pointer to the DocumentClass currently in use: the BaseClass 
126         /// as modified by modules. 
127         DocumentClass * documentClassPtr() const;
128         /// This bypasses the baseClass and sets the textClass directly.
129         /// Should be called with care and would be better not being here,
130         /// but it seems to be needed by CutAndPaste::putClipboard().
131         void setDocumentClass(DocumentClass const * const);
132         /// List of modules in use
133         std::vector<std::string> const & getModules() const;
134         /// Add a module to the list of modules in use.
135         /// Returns true if module was successfully added.
136         /// The makeClass variable signals whether to call makeDocumentClass. This
137         /// need not be done if we know this isn't the final time through, or if
138         /// the BufferParams do not represent the parameters for an actual buffer
139         /// (as in GuiDocument).
140         bool addLayoutModule(std::string const & modName);
141         /// Clear the list
142         void clearLayoutModules();
143
144         /// returns the main font for the buffer (document)
145         Font const getFont() const;
146
147         /* this are for the PaperLayout */
148         /// the papersize
149         PAPER_SIZE papersize;
150         ///
151         PAPER_ORIENTATION orientation;
152         /// use custom margins
153         bool use_geometry;
154         ///
155         std::string paperwidth;
156         ///
157         std::string paperheight;
158         ///
159         std::string leftmargin;
160         ///
161         std::string topmargin;
162         ///
163         std::string rightmargin;
164         ///
165         std::string bottommargin;
166         ///
167         std::string headheight;
168         ///
169         std::string headsep;
170         ///
171         std::string footskip;
172         ///
173         std::string columnsep;
174
175         /* some LaTeX options */
176         /// The graphics driver
177         std::string graphicsDriver;
178         /// the rm font
179         std::string fontsRoman;
180         /// the sf font
181         std::string fontsSans;
182         /// the tt font
183         std::string fontsTypewriter;
184         /// the default family (rm, sf, tt)
185         std::string fontsDefaultFamily;
186         /// use expert Small Caps
187         bool fontsSC;
188         /// use Old Style Figures
189         bool fontsOSF;
190         /// the scale factor of the sf font
191         int fontsSansScale;
192         /// the scale factor of the tt font
193         int fontsTypewriterScale;
194         ///
195         Spacing & spacing();
196         Spacing const & spacing() const;
197         ///
198         int secnumdepth;
199         ///
200         int tocdepth;
201         ///
202         Language const * language;
203         /// BranchList:
204         BranchList & branchlist();
205         BranchList const & branchlist() const;
206         /**
207          * The input encoding for LaTeX. This can be one of
208          * - \c auto: find out the input encoding from the used languages
209          * - \c default: ditto
210          * - any encoding supported by the inputenc package
211          * The encoding of the LyX file is always utf8 and has nothing to
212          * do with this setting.
213          * The difference between \c auto and \c default is that \c auto also
214          * causes loading of the inputenc package, while \c default does not.
215          * \c default will not work unless the user takes additional measures
216          * (such as using special environments like the CJK environment from
217          * CJK.sty).
218          * \c default can be seen as an unspecified 8bit encoding, since LyX
219          * does not interpret it in any way apart from display on screen.
220          */
221         std::string inputenc;
222         /// The main encoding used by this buffer for LaTeX output.
223         /// Individual pieces of text can use different encodings.
224         Encoding const & encoding() const;
225         ///
226         std::string preamble;
227         ///
228         std::string options;
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         bool embedded;
274         ///
275         std::vector<std::string> & extraEmbeddedFiles();
276         std::vector<std::string> const & extraEmbeddedFiles() const;
277
278         /// the author list for the document
279         AuthorList & authors();
280         AuthorList const & authors() const;
281
282         /// map of the file's author IDs to buffer author IDs
283         std::vector<unsigned int> author_map;
284         ///
285         std::string const dvips_options() const;
286         /** The return value of paperSizeName() depends on the
287          *  purpose for which the paper size is needed, since they
288          *  support different subsets of paper sizes.
289         */
290         enum Papersize_Purpose {
291                 ///
292                 DVIPS,
293                 ///
294                 DVIPDFM,
295                 ///
296                 XDVI
297         };
298         ///
299         std::string const paperSizeName(Papersize_Purpose const & purpose) const;
300         /// set up if and how babel is called
301         std::string const babelCall(std::string const & lang_opts) const;
302         /// handle inputenc etc.
303         void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
304                                               TexRow & texrow) const;
305         /// set up the document fonts
306         std::string const loadFonts(std::string const & rm,
307                                      std::string const & sf, std::string const & tt,
308                                      bool const & sc, bool const & osf,
309                                      int const & sfscale, int const & ttscale) const;
310
311         /// get the appropriate cite engine (natbib handling)
312         biblio::CiteEngine getEngine() const;
313
314         ///
315         void setCiteEngine(biblio::CiteEngine const);
316
317         /// options for pdf output
318         PDFOptions & pdfoptions();
319         PDFOptions const & pdfoptions() const;
320
321 private:
322         ///
323         void readPreamble(Lexer &);
324         ///
325         void readLanguage(Lexer &);
326         ///
327         void readGraphicsDriver(Lexer &);
328         ///
329         void readBullets(Lexer &);
330         ///
331         void readBulletsLaTeX(Lexer &);
332         ///
333         void readModules(Lexer &);
334
335         /// for use with natbib
336         biblio::CiteEngine cite_engine_;
337         ///
338         DocumentClass * doc_class_;
339         ///
340         typedef std::vector<std::string> LayoutModuleList;
341         /// 
342         LayoutModuleList layoutModules_;
343
344         /** Use the Pimpl idiom to hide those member variables that would otherwise
345          *  drag in other header files.
346          */
347         class Impl;
348         class MemoryTraits {
349         public:
350                 static Impl * clone(Impl const *);
351                 static void destroy(Impl *);
352         };
353         support::copied_ptr<Impl, MemoryTraits> pimpl_;
354
355 };
356
357 } // namespace lyx
358
359 #endif