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