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