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