]> git.lyx.org Git - features.git/blob - src/LaTeXFonts.h
Factor out duplicated code
[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         LaTeXFont() : 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         /// Alternative packages if package() is not available
39         std::vector<docstring> const & altpackages() { return altpackages_; }
40         /// A package that provides all families
41         docstring const & completepackage() { return completepackage_; }
42         /// A package specifically needed for OT1 font encoding
43         docstring const & ot1package() { return ot1package_; }
44         /// A package that provides Old Style Figures for this font
45         docstring const & osfpackage() { return osfpackage_; }
46         /// A package option for Old Style Figures
47         docstring const & osfoption() { return osfoption_; }
48         /// A package option for true SmallCaps
49         docstring const & scoption() { return scoption_; }
50         /// A package option for both Old Style Figures and SmallCaps
51         docstring const & osfscoption() { return osfscoption_; }
52         /// A package option for font scaling
53         docstring const & scaleoption() { return scaleoption_; }
54         /// Alternative requirement to test for
55         docstring const & requires() { return requires_; }
56         /// Issue the familydefault switch
57         bool switchdefault() const { return switchdefault_; }
58         /// Is this font available?
59         bool available(bool ot1 = false) const;
60         /// Does this font provide Old Style Figures?
61         bool providesOSF(bool ot1 = false) const;
62         /// Does this font provide optional true SmallCaps?
63         bool providesSC(bool ot1 = false) const;
64         /// Does this font provide scaling?
65         bool providesScale(bool ot1 = false) const;
66         /// Return the LaTeX Code
67         std::string const getLaTeXCode(bool dryrun, bool ot1, bool complete,
68                                        bool sc, bool osf,
69                                        int const & scale = 100);
70         ///
71         bool read(Lexer & lex);
72         ///
73         bool readFont(Lexer & lex);
74 private:
75         /// Return the preferred available package 
76         std::string const getAvailablePackage(bool dryrun,
77                                               bool ot1,
78                                               bool complete);
79         /// Return the package options
80         std::string const getPackageOptions(bool ot1,
81                                             bool sc,
82                                             bool osf,
83                                             int scale);
84         ///
85         docstring name_;
86         ///
87         docstring guiname_;
88         ///
89         docstring family_;
90         ///
91         docstring package_;
92         ///
93         std::vector<docstring> altpackages_;
94         ///
95         docstring completepackage_;
96         ///
97         docstring ot1package_;
98         ///
99         docstring osfpackage_;
100         ///
101         docstring osfoption_;
102         ///
103         docstring scoption_;
104         ///
105         docstring osfscoption_;
106         ///
107         docstring scaleoption_;
108         ///
109         docstring requires_;
110         ///
111         bool switchdefault_;
112         ///
113         bool available_;
114         ///
115         bool available_ot1_;
116 };
117   
118   
119 /** The list of available LaTeX fonts
120  */
121 class LaTeXFonts {
122 public:
123         ///
124         typedef std::map<docstring, LaTeXFont> TexFontMap;
125         /// Get all LaTeXFonts
126         TexFontMap getLaTeXFonts();
127         /// Get a specific LaTeXFont \p name
128         LaTeXFont getLaTeXFont(docstring const & name);
129 private:
130         ///
131         void readLaTeXFonts();
132         ///
133         TexFontMap texfontmap_;
134 };
135
136 /// Implementation is in LyX.cpp
137 extern LaTeXFonts & theLaTeXFonts();
138
139
140 } // namespace lyx
141
142 #endif