]> git.lyx.org Git - features.git/blob - src/LaTeXFonts.h
Provide option to prevent unnecessary font loading.
[features.git] / src / LaTeXFonts.h
1 // -*- C++ -*-
2 /**
3  * \file LaTeXFonts.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Spitzmüller
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef LATEXFONTS_H
13 #define LATEXFONTS_H
14
15 #include "support/docstring.h"
16
17 #include <map>
18 #include <vector>
19
20
21 namespace lyx {
22
23 class Lexer;
24
25 /// LaTeX Font definition
26 class LaTeXFont {
27 public:
28         /// TeX font
29         // FIXME Add fontenc tag to classes which is used if no font is specified?
30         LaTeXFont() : osfdefault_(false), switchdefault_(false), moreopts_(false),
31                 osffontonly_(false) { fontenc_.push_back("T1"); }
32         /// The font name
33         docstring const & name() { return name_; }
34         /// The name to appear in the document dialog
35         docstring const & guiname() { return guiname_; }
36         /// Font family (rm, sf, tt)
37         docstring const & family() { return family_; }
38         /// The package that provides this font
39         docstring const & package() { return package_; }
40         /// Does this provide a specific font encoding?
41         bool hasFontenc(std::string const &) const;
42         /// The font encoding(s)
43         std::vector<std::string> const & fontencs() const { return fontenc_; }
44         /// Alternative font if package() is not available
45         std::vector<docstring> const & altfonts() { return altfonts_; }
46         /// A font that provides all families
47         docstring const & completefont() { return completefont_; }
48         /// A font specifically needed for OT1 font encoding
49         docstring const & ot1font() { return ot1font_; }
50         /// A font that provides Old Style Figures for this type face
51         docstring const & osffont() { return osffont_; }
52         /// A package option for Old Style Figures
53         docstring const & osfoption() { return osfoption_; }
54         /// A package option for true SmallCaps
55         docstring const & scoption() { return scoption_; }
56         /// A package option for both Old Style Figures and SmallCaps
57         docstring const & osfscoption() { return osfscoption_; }
58         /// A package option for font scaling
59         docstring const & scaleoption() { return scaleoption_; }
60         /// Does this provide additional options?
61         bool providesMoreOptions(bool ot1, bool complete, bool nomath);
62         /// Alternative requirement to test for
63         docstring const & required() { return required_; }
64         /// Does this font provide a given \p feature
65         bool provides(std::string const & name, bool ot1,
66                       bool complete, bool nomath);
67         /// Issue the familydefault switch
68         bool switchdefault() const { return switchdefault_; }
69         /// Does the font provide Old Style Figures as default?
70         bool osfDefault() const { return osfdefault_; }
71         /// Does OSF font replace (rather than complement) the non-OSF one?
72         bool osfFontOnly() const { return osffontonly_; }
73         /// Is this font available?
74         bool available(bool ot1, bool nomath);
75         /// Does this font provide an alternative without math?
76         bool providesNoMath(bool ot1, bool complete);
77         /// Does this font provide Old Style Figures?
78         bool providesOSF(bool ot1, bool complete, bool nomath);
79         /// Does this font provide optional true SmallCaps?
80         bool providesSC(bool ot1, bool complete, bool nomath);
81         /** does this font provide OSF and Small Caps only via
82          * a single, undifferentiated expert option?
83          */
84         bool hasMonolithicExpertSet(bool ot1, bool complete, bool nomath);
85         /// Does this font provide scaling?
86         bool providesScale(bool ot1, bool complete, bool nomath);
87         /// Return the LaTeX Code
88         std::string const getLaTeXCode(bool dryrun, bool ot1, bool complete,
89                                        bool sc, bool osf, bool nomath,
90                                        std::string const & extraopts = std::string(),
91                                        int const & scale = 100);
92         /// Return the actually used font
93         docstring const getUsedFont(bool ot1, bool complete, bool nomath, bool osf);
94         /// Return the actually used package
95         docstring const getUsedPackage(bool ot1, bool complete, bool nomath);
96         ///
97         bool read(Lexer & lex);
98         ///
99         bool readFont(Lexer & lex);
100 private:
101         /// Return the preferred available package
102         std::string const getAvailablePackage(bool dryrun);
103         /// Return the package options
104         std::string const getPackageOptions(bool ot1,
105                                             bool complete,
106                                             bool sc,
107                                             bool osf,
108                                             int scale,
109                                             std::string const & extraopts,
110                                             bool nomath);
111         /// Return an alternative font
112         LaTeXFont altFont(docstring const & name);
113         ///
114         docstring name_;
115         ///
116         docstring guiname_;
117         ///
118         docstring family_;
119         ///
120         docstring package_;
121         ///
122         std::vector<std::string> fontenc_;
123         ///
124         std::vector<docstring> altfonts_;
125         ///
126         docstring completefont_;
127         ///
128         docstring nomathfont_;
129         ///
130         docstring ot1font_;
131         ///
132         docstring osffont_;
133         ///
134         docstring packageoptions_;
135         ///
136         docstring osfoption_;
137         ///
138         docstring scoption_;
139         ///
140         docstring osfscoption_;
141         ///
142         docstring scaleoption_;
143         ///
144         std::vector<std::string> provides_;
145         ///
146         docstring required_;
147         ///
148         docstring preamble_;
149         ///
150         bool osfdefault_;
151         ///
152         bool switchdefault_;
153         ///
154         bool moreopts_;
155         ///
156         bool osffontonly_;
157 };
158
159
160 /** The list of available LaTeX fonts
161  */
162 class LaTeXFonts {
163 public:
164         ///
165         typedef std::map<docstring, LaTeXFont> TexFontMap;
166         /// Get all LaTeXFonts
167         TexFontMap getLaTeXFonts();
168         /// Get a specific LaTeXFont \p name
169         LaTeXFont getLaTeXFont(docstring const & name);
170         /// Get a specific AltFont \p name
171         LaTeXFont getAltFont(docstring const & name);
172 private:
173         ///
174         void readLaTeXFonts();
175         ///
176         TexFontMap texfontmap_;
177         ///
178         TexFontMap texaltfontmap_;
179 };
180
181 /// Implementation is in LyX.cpp
182 extern LaTeXFonts & theLaTeXFonts();
183
184
185 } // namespace lyx
186
187 #endif