]> git.lyx.org Git - lyx.git/blob - src/LaTeXFonts.h
ca37be5a5989cba9490b7d9a40a56bbd9a5c7020
[lyx.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         LaTeXFont() : osfdefault_(false), switchdefault_(false) {}
30         /// The font name
31         docstring const & name() { return name_; }
32         /// The name to appear in the document dialog
33         docstring const & guiname() { return guiname_; }
34         /// Font family (rm, sf, tt)
35         docstring const & family() { return family_; }
36         /// The package that provides this font
37         docstring const & package() { return package_; }
38         /// Does this provide a specific font encoding?
39         bool hasFontenc(std::string const &) const;
40         /// The font encoding(s)
41         std::vector<std::string> const & fontencs() const { return fontenc_; }
42         /// Alternative font if package() is not available
43         std::vector<docstring> const & altfonts() { return altfonts_; }
44         /// A font that provides all families
45         docstring const & completefont() { return completefont_; }
46         /// A font specifically needed for OT1 font encoding
47         docstring const & ot1font() { return ot1font_; }
48         /// A font that provides Old Style Figures for this type face
49         docstring const & osffont() { return osffont_; }
50         /// A package option needed to load this font
51         docstring const & packageoption() { return packageoption_; }
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         /// Alternative requirement to test for
61         docstring const & requires() { return requires_; }
62         /// Does this font provide a given \p feature
63         bool provides(std::string const & name, bool ot1,
64                       bool complete, bool nomath);
65         /// Issue the familydefault switch
66         bool switchdefault() const { return switchdefault_; }
67         /// Does the font provide Old Style Figures as default?
68         bool osfDefault() const { return osfdefault_; }
69         /// Is this font available?
70         bool available(bool ot1, bool nomath);
71         /// Does this font provide an alternative without math?
72         bool providesNoMath(bool ot1, bool complete);
73         /// Does this font provide Old Style Figures?
74         bool providesOSF(bool ot1, bool complete, bool nomath);
75         /// Does this font provide optional true SmallCaps?
76         bool providesSC(bool ot1, bool complete, bool nomath);
77         /** does this font provide OSF and Small Caps only via
78          * a single, undifferentiated expert option?
79          */
80         bool hasMonolithicExpertSet(bool ot1, bool complete, bool nomath);
81         /// Does this font provide scaling?
82         bool providesScale(bool ot1, bool complete, bool nomath);
83         /// Return the LaTeX Code
84         std::string const getLaTeXCode(bool dryrun, bool ot1, bool complete,
85                                        bool sc, bool osf, bool nomath,
86                                        int const & scale = 100);
87         /// Return the actually used font
88         docstring const getUsedFont(bool ot1, bool complete, bool nomath);
89         /// Return the actually used package
90         docstring const getUsedPackage(bool ot1, bool complete, bool nomath);
91         ///
92         bool read(Lexer & lex);
93         ///
94         bool readFont(Lexer & lex);
95 private:
96         /// Return the preferred available package
97         std::string const getAvailablePackage(bool dryrun);
98         /// Return the package options
99         std::string const getPackageOptions(bool ot1,
100                                             bool complete,
101                                             bool sc,
102                                             bool osf,
103                                             int scale,
104                                             bool nomath);
105         /// Return an alternative font
106         LaTeXFont altFont(docstring const & name);
107         ///
108         docstring name_;
109         ///
110         docstring guiname_;
111         ///
112         docstring family_;
113         ///
114         docstring package_;
115         ///
116         std::vector<std::string> fontenc_;
117         ///
118         std::vector<docstring> altfonts_;
119         ///
120         docstring completefont_;
121         ///
122         docstring nomathfont_;
123         ///
124         docstring ot1font_;
125         ///
126         docstring osffont_;
127         ///
128         docstring packageoption_;
129         ///
130         docstring osfoption_;
131         ///
132         docstring scoption_;
133         ///
134         docstring osfscoption_;
135         ///
136         docstring scaleoption_;
137         ///
138         std::vector<std::string> provides_;
139         ///
140         docstring requires_;
141         ///
142         docstring preamble_;
143         ///
144         bool osfdefault_;
145         ///
146         bool switchdefault_;
147 };
148
149
150 /** The list of available LaTeX fonts
151  */
152 class LaTeXFonts {
153 public:
154         ///
155         typedef std::map<docstring, LaTeXFont> TexFontMap;
156         /// Get all LaTeXFonts
157         TexFontMap getLaTeXFonts();
158         /// Get a specific LaTeXFont \p name
159         LaTeXFont getLaTeXFont(docstring const & name);
160         /// Get a specific AltFont \p name
161         LaTeXFont getAltFont(docstring const & name);
162 private:
163         ///
164         void readLaTeXFonts();
165         ///
166         TexFontMap texfontmap_;
167         ///
168         TexFontMap texaltfontmap_;
169 };
170
171 /// Implementation is in LyX.cpp
172 extern LaTeXFonts & theLaTeXFonts();
173
174
175 } // namespace lyx
176
177 #endif