]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Store both sets of font selections
[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 "DocumentClassPtr.h"
20 #include "Format.h"
21 #include "LayoutModuleList.h"
22 #include "OutputParams.h"
23 #include "paper.h"
24
25 #include "insets/InsetQuotes.h"
26
27 #include "support/copied_ptr.h"
28
29 #include <map>
30 #include <vector>
31
32 namespace lyx {
33
34 namespace support { class FileName; }
35
36 class AuthorList;
37 class BranchList;
38 class Bullet;
39 class DocumentClass;
40 class Encoding;
41 class Font;
42 class HSpace;
43 class IndicesList;
44 class Language;
45 class LatexFeatures;
46 class LayoutFile;
47 class LayoutFileIndex;
48 class Lexer;
49 class PDFOptions;
50 class Spacing;
51 class VSpace;
52
53 /** Buffer parameters.
54  *  This class contains all the parameters for this buffer's use. Some
55  *  work needs to be done on this class to make it nice. Now everything
56  *  is in public.
57  */
58 class BufferParams {
59 public:
60         ///
61         enum ParagraphSeparation {
62                 ///
63                 ParagraphIndentSeparation,
64                 ///
65                 ParagraphSkipSeparation
66         };
67         ///
68         BufferParams();
69
70         /// get l10n translated to the buffers language
71         docstring B_(std::string const & l10n) const;
72
73         /// read a header token, if unrecognised, return it or an unknown class name
74         std::string readToken(Lexer & lex,
75                 std::string const & token, ///< token to read.
76                 support::FileName const & filepath);
77
78         ///
79         void writeFile(std::ostream &, Buffer const *) const;
80
81         /// check what features are implied by the buffer parameters.
82         void validate(LaTeXFeatures &) const;
83
84         /** \returns true if the babel package is used (interrogates
85          *  the BufferParams, a LyXRC variable, and the document class).
86          *  This returned value can then be passed to the insets...
87          */
88         bool writeLaTeX(otexstream &, LaTeXFeatures &,
89                         support::FileName const &) const;
90
91         ///
92         void useClassDefaults();
93         ///
94         bool hasClassDefaults() const;
95
96         ///
97         HSpace const & getIndentation() const;
98         ///
99         void setIndentation(HSpace const & indent);
100         ///
101         VSpace const & getDefSkip() const;
102         ///
103         void setDefSkip(VSpace const & vs);
104
105         /** Whether paragraphs are separated by using a indent like in
106          *  articles or by using a little skip like in letters.
107          */
108         ParagraphSeparation paragraph_separation;
109         ///
110         InsetQuotes::QuoteLanguage quotes_language;
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 classname: 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         /// NOTE: This should NEVER be called externally unless one immediately goes
125         /// on to class BufferView::updateDocumentClass(). The exception, of course,
126         /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
127         /// the parameters from the active Buffer.
128         void makeDocumentClass(bool const clone = false);
129         /// Returns the DocumentClass currently in use: the BaseClass as modified
130         /// by modules.
131         DocumentClass const & documentClass() const;
132         /// \return A pointer to the DocumentClass currently in use: the BaseClass
133         /// as modified by modules.
134         DocumentClassConstPtr documentClassPtr() const;
135         /// This bypasses the baseClass and sets the textClass directly.
136         /// Should be called with care and would be better not being here,
137         /// but it seems to be needed by CutAndPaste::putClipboard().
138         void setDocumentClass(DocumentClassConstPtr);
139         /// List of modules in use
140         LayoutModuleList const & getModules() const { return layout_modules_; }
141         /// List of default modules the user has removed
142         std::list<std::string> const & getRemovedModules() const
143                         { return removed_modules_; }
144         ///
145         /// Add a module to the list of modules in use. This checks only that the
146         /// module is not already in the list, so use layoutModuleCanBeAdeed first 
147         /// if you want to check for compatibility.
148         /// \return true if module was successfully added.
149         bool addLayoutModule(std::string const & modName);
150         /// checks to make sure module's requriements are satisfied, that it does
151         /// not conflict with already-present modules, isn't already loaded, etc.
152         bool layoutModuleCanBeAdded(std::string const & modName) const;
153         /// same, but for citaton modules.
154         bool citationModuleCanBeAdded(std::string const & modName) const;
155         ///
156         void addRemovedModule(std::string const & modName)
157                         { removed_modules_.push_back(modName); }
158         /// Clear the list
159         void clearLayoutModules() { layout_modules_.clear(); }
160         /// Clear the removed module list
161         void clearRemovedModules() { removed_modules_.clear(); }
162         /// Get the local layouts
163         std::string getLocalLayout(bool) const;
164         /// Set the local layouts
165         void setLocalLayout(std::string const &, bool);
166
167         /// returns \c true if the buffer contains a LaTeX document
168         bool isLatex() const;
169         /// returns \c true if the buffer contains a DocBook document
170         bool isDocBook() const;
171         /// returns \c true if the buffer contains a Wed document
172         bool isLiterate() const;
173
174         /// return the format of the buffer on a string
175         std::string bufferFormat() const;
176         /// return the default output format of the current backend
177         std::string getDefaultOutputFormat() const;
178         /// return the output flavor of \p format or the default
179         OutputParams::FLAVOR getOutputFlavor(
180                   std::string const & format = std::string()) const;
181         ///
182         bool isExportable(std::string const & format) const;
183         ///
184         std::vector<Format const *> exportableFormats(bool only_viewable) const;
185         ///
186         bool isExportableFormat(std::string const & format) const;
187         /// the backends appropriate for use with this document.
188         /// so, e.g., latex is excluded , if we're using non-TeX fonts
189         std::vector<std::string> backends() const;
190
191         /// List of included children (for includeonly)
192         std::list<std::string> const & getIncludedChildren() const
193                         { return included_children_; }
194         ///
195         void addIncludedChildren(std::string const & child)
196                         { included_children_.push_back(child); }
197         /// Clear the list of included children
198         void clearIncludedChildren() { included_children_.clear(); }
199
200         /// update aux files of unincluded children (with \includeonly)
201         bool maintain_unincluded_children;
202
203         /// returns the main font for the buffer (document)
204         Font const getFont() const;
205
206         /// translate quote style string to enum value
207         InsetQuotes::QuoteLanguage getQuoteStyle(std::string const & qs) const;
208
209         /* these are for the PaperLayout */
210         /// the papersize
211         PAPER_SIZE papersize;
212         ///
213         PAPER_ORIENTATION orientation;
214         /// use custom margins
215         bool use_geometry;
216         ///
217         std::string paperwidth;
218         ///
219         std::string paperheight;
220         ///
221         std::string leftmargin;
222         ///
223         std::string topmargin;
224         ///
225         std::string rightmargin;
226         ///
227         std::string bottommargin;
228         ///
229         std::string headheight;
230         ///
231         std::string headsep;
232         ///
233         std::string footskip;
234         ///
235         std::string columnsep;
236
237         /* some LaTeX options */
238         /// The graphics driver
239         std::string graphics_driver;
240         /// The default output format
241         std::string default_output_format;
242         /// customized bibliography processor
243         std::string bibtex_command;
244         /// customized index processor
245         std::string index_command;
246         /// font encoding(s) requested for this document
247         std::string fontenc;
248         /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
249         std::string fonts_roman[2];
250         /// the rm font
251         std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
252         /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
253         std::string fonts_sans[2];
254         /// the sf font
255         std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
256         /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
257         std::string fonts_typewriter[2];
258         /// the tt font
259         std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
260         /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
261         std::string fonts_math[2];
262         /// the math font
263         std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
264         /// the default family (rm, sf, tt)
265         std::string fonts_default_family;
266         /// use the fonts of the OS (OpenType, True Type) directly
267         bool useNonTeXFonts;
268         /// use expert Small Caps
269         bool fonts_expert_sc;
270         /// use Old Style Figures
271         bool fonts_old_figures;
272         /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
273         int fonts_sans_scale[2];
274         /// the scale factor of the sf font
275         int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
276         /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
277         int fonts_typewriter_scale[2];
278         /// the scale factor of the tt font
279         int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
280         /// the font used by the CJK command
281         std::string fonts_cjk;
282         ///
283         Spacing & spacing();
284         Spacing const & spacing() const;
285         ///
286         int secnumdepth;
287         ///
288         int tocdepth;
289         ///
290         Language const * language;
291         /// language package
292         std::string lang_package;
293         /// BranchList:
294         BranchList & branchlist();
295         BranchList const & branchlist() const;
296         /// IndicesList:
297         IndicesList & indiceslist();
298         IndicesList const & indiceslist() const;
299         /**
300          * The LyX name of the input encoding for LaTeX. This can be one of
301          * - \c auto: find out the input encoding from the used languages
302          * - \c default: ditto
303          * - any encoding defined in the file lib/encodings
304          * The encoding of the LyX file is always utf8 and has nothing to
305          * do with this setting.
306          * The difference between \c auto and \c default is that \c auto also
307          * causes loading of the inputenc package, while \c default does not.
308          * \c default will not work unless the user takes additional measures
309          * (such as using special environments like the CJK environment from
310          * CJK.sty).
311          * \c default can be seen as an unspecified 8bit encoding, since LyX
312          * does not interpret it in any way apart from display on screen.
313          */
314         std::string inputenc;
315         /// The main encoding used by this buffer for LaTeX output.
316         /// Individual pieces of text can use different encodings.
317         Encoding const & encoding() const;
318         ///
319         std::string origin;
320         ///
321         std::string preamble;
322         ///
323         std::string options;
324         /// use the class options defined in the layout?
325         bool use_default_options;
326         ///
327         std::string master;
328         ///
329         bool suppress_date;
330         ///
331         std::string float_placement;
332         ///
333         unsigned int columns;
334         ///
335         bool justification;
336         /// parameters for the listings package
337         std::string listings_params;
338         ///
339         PageSides sides;
340         ///
341         std::string pagestyle;
342         ///
343         RGBColor backgroundcolor;
344         ///
345         bool isbackgroundcolor;
346         ///
347         RGBColor fontcolor;
348         ///
349         bool isfontcolor;
350         ///
351         RGBColor notefontcolor;
352         ///
353         RGBColor boxbgcolor;
354         /// \param index should lie in the range 0 <= \c index <= 3.
355         Bullet & temp_bullet(size_type index);
356         Bullet const & temp_bullet(size_type index) const;
357         /// \param index should lie in the range 0 <= \c index <= 3.
358         Bullet & user_defined_bullet(size_type index);
359         Bullet const & user_defined_bullet(size_type index) const;
360
361         /// Whether to load a package such as amsmath or esint.
362         /// The enum values must not be changed (file format!)
363         enum Package {
364                 /// Don't load the package. For experts only.
365                 package_off = 0,
366                 /// Load the package if needed (recommended)
367                 package_auto = 1,
368                 /// Always load the package (e.g. if the document contains
369                 /// some ERT that needs the package)
370                 package_on = 2
371         };
372         /// Whether to load a package such as amsmath or esint.
373         Package use_package(std::string const & p) const;
374         /// Set whether to load a package such as amsmath or esint.
375         void use_package(std::string const & p, Package u);
376         /// All packages that can be switched on or off
377         static std::map<std::string, std::string> const & auto_packages();
378         /// Split bibliography?
379         bool use_bibtopic;
380         /// Split the index?
381         bool use_indices;
382         /// revision tracking for this buffer ?
383         bool track_changes;
384         /** This param decides whether change tracking marks should be used
385          *  in output (irrespective of how these marks are actually defined;
386          *  for instance, they may differ for DVI and PDF generation)
387          */
388         bool output_changes;
389         ///
390         bool compressed;
391
392         /// the author list for the document
393         AuthorList & authors();
394         AuthorList const & authors() const;
395
396         /// map of the file's author IDs to AuthorList indexes
397         typedef std::map<int, int> AuthorMap;
398         AuthorMap author_map;
399         /// the buffer's active font encoding
400         std::string const font_encoding() const;
401         /// all font encodings requested by the prefs/document/main language.
402         /// This does NOT include font encodings required by secondary languages
403         std::vector<std::string> const font_encodings() const;
404
405         ///
406         std::string const dvips_options() const;
407         /** The return value of paperSizeName() depends on the
408          *  purpose for which the paper size is needed, since they
409          *  support different subsets of paper sizes.
410         */
411         enum PapersizePurpose {
412                 ///
413                 DVIPS,
414                 ///
415                 DVIPDFM,
416                 ///
417                 XDVI
418         };
419         ///
420         std::string paperSizeName(PapersizePurpose purpose) const;
421         /// set up if and how babel is called
422         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
423         /// return supported drivers for specific packages
424         docstring getGraphicsDriver(std::string const & package) const;
425         /// handle inputenc etc.
426         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
427         ///
428         std::string const parseFontName(std::string const & name) const;
429         /// set up the document fonts
430         std::string const loadFonts(LaTeXFeatures & features) const;
431
432         /// the cite engine modules
433         LayoutModuleList const & citeEngine() const
434                 { return cite_engine_; }
435         /// the type of cite engine (authoryear or numerical)
436         CiteEngineType const & citeEngineType() const
437                 { return cite_engine_type_; }
438         /// add the module to the cite engine modules
439         bool addCiteEngine(std::string const &);
440         /// add the modules to the cite engine modules
441         bool addCiteEngine(std::vector<std::string> const &);
442         /// clear the list of cite engine modules
443         void clearCiteEngine() { cite_engine_.clear(); }
444         /// set the cite engine module
445         void setCiteEngine(std::string const &);
446         /// set the cite engine modules
447         void setCiteEngine(std::vector<std::string> const &);
448         /// set the cite engine type
449         void setCiteEngineType(CiteEngineType const & engine_type)
450                 { cite_engine_type_ = engine_type; }
451
452         /// the available citation commands
453         std::vector<std::string> citeCommands() const;
454         /// the available citation styles
455         std::vector<CitationStyle> citeStyles() const;
456
457         /// the default BibTeX style file for the document
458         std::string biblio_style;
459         /// the default BibTeX style file from the TextClass
460         std::string const & defaultBiblioStyle() const;
461         /// whether the BibTeX style supports full author lists
462         bool const & fullAuthorList() const;
463
464         /// options for pdf output
465         PDFOptions & pdfoptions();
466         PDFOptions const & pdfoptions() const;
467
468         // do not change these values. we rely upon them.
469         enum MathOutput {
470                 MathML = 0,
471                 HTML = 1,
472                 Images = 2,
473                 LaTeX = 3
474         };
475         /// what to use for math output. present choices are above
476         MathOutput html_math_output;
477         /// whether to attempt to be XHTML 1.1 compliant or instead be
478         /// a little more mellow
479         bool html_be_strict;
480         ///
481         double html_math_img_scale;
482         ///
483         double display_pixel_ratio;
484         ///
485         std::string html_latex_start;
486         ///
487         std::string html_latex_end;
488         ///
489         bool html_css_as_file;
490         /// generate output usable for reverse/forward search
491         bool output_sync;
492         /// custom LaTeX macro from user instead our own
493         std::string output_sync_macro;
494         /// use refstyle? or prettyref?
495         bool use_refstyle;
496
497         /// Return true if language could be set to lang,
498         /// otherwise return false and do not change language
499         bool setLanguage(std::string const & lang);
500
501 private:
502         ///
503         void readPreamble(Lexer &);
504         ///
505         void readLocalLayout(Lexer &, bool);
506         ///
507         void readLanguage(Lexer &);
508         ///
509         void readGraphicsDriver(Lexer &);
510         ///
511         void readBullets(Lexer &);
512         ///
513         void readBulletsLaTeX(Lexer &);
514         ///
515         void readModules(Lexer &);
516         ///
517         void readRemovedModules(Lexer &);
518         ///
519         void readIncludeonly(Lexer &);
520         /// A cache for the default flavors
521         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
522         ///
523         mutable DefaultFlavorCache default_flavors_;
524         /// the cite engine modules
525         LayoutModuleList cite_engine_;
526         /// the type of cite engine (authoryear or numerical)
527         CiteEngineType cite_engine_type_;
528         ///
529         DocumentClassPtr doc_class_;
530         ///
531         LayoutModuleList layout_modules_;
532         /// this is for modules that are required by the document class but that
533         /// the user has chosen not to use
534         std::list<std::string> removed_modules_;
535         /// The local layouts without the forced ones
536         std::string local_layout_;
537         /// Forced local layouts only for reading (use getLocalLayout() instead)
538         std::string forced_local_layout_;
539
540         /// the list of included children (for includeonly)
541         std::list<std::string> included_children_;
542
543         typedef std::map<std::string, Package> PackageMap;
544         /** Whether and how to load packages like amsmath, esint, mhchem,
545          *  mathdots, stackrel, stmaryrd and undertilde.
546          */
547         PackageMap use_packages;
548
549         /** Use the Pimpl idiom to hide those member variables that would otherwise
550          *  drag in other header files.
551          */
552         class Impl;
553         class MemoryTraits {
554         public:
555                 static Impl * clone(Impl const *);
556                 static void destroy(Impl *);
557         };
558         support::copied_ptr<Impl, MemoryTraits> pimpl_;
559
560 };
561
562 } // namespace lyx
563
564 #endif