]> git.lyx.org Git - features.git/blob - src/LaTeXFonts.h
Much more flexible implementation of alternative (LaTeX) fonts
[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 font if package() is not available
39         std::vector<docstring> const & altfonts() { return altfonts_; }
40         /// A font that provides all families
41         docstring const & completefont() { return completefont_; }
42         /// A font specifically needed for OT1 font encoding
43         docstring const & ot1font() { return ot1font_; }
44         /// A font that provides Old Style Figures for this type face
45         docstring const & osffont() { return osffont_; }
46         /// A package option needed to load this font
47         docstring const & packageoption() { return packageoption_; }
48         /// A package option for Old Style Figures
49         docstring const & osfoption() { return osfoption_; }
50         /// A package option for true SmallCaps
51         docstring const & scoption() { return scoption_; }
52         /// A package option for both Old Style Figures and SmallCaps
53         docstring const & osfscoption() { return osfscoption_; }
54         /// A package option for font scaling
55         docstring const & scaleoption() { return scaleoption_; }
56         /// Alternative requirement to test for
57         docstring const & requires() { return requires_; }
58         /// Does this font provide a given \p feature
59         bool provides(std::string const & name, bool ot1, bool complete);
60         /// Issue the familydefault switch
61         bool switchdefault() const { return switchdefault_; }
62         /// Does the font provide Old Style Figures as default?
63         bool osfDefault() const { return osfdefault_; }
64         /// Is this font available?
65         bool available(bool ot1);
66         /// Does this font provide Old Style Figures?
67         bool providesOSF(bool ot1, bool complete);
68         /// Does this font provide optional true SmallCaps?
69         bool providesSC(bool ot1, bool complete);
70         /// Does this font provide scaling?
71         bool providesScale(bool ot1, bool complete);
72         /// Return the LaTeX Code
73         std::string const getLaTeXCode(bool dryrun, bool ot1, bool complete,
74                                        bool sc, bool osf,
75                                        int const & scale = 100);
76         /// Return the actually used font
77         docstring const getUsedFont(bool ot1, bool complete);
78         ///
79         bool read(Lexer & lex);
80         ///
81         bool readFont(Lexer & lex);
82 private:
83         /// Return the preferred available package 
84         std::string const getAvailablePackage(bool dryrun);
85         /// Return the package options
86         std::string const getPackageOptions(bool ot1,
87                                             bool complete,
88                                             bool sc,
89                                             bool osf,
90                                             int scale);
91         /// Return an alternative font
92         LaTeXFont altFont(docstring const & name);
93         ///
94         docstring name_;
95         ///
96         docstring guiname_;
97         ///
98         docstring family_;
99         ///
100         docstring package_;
101         ///
102         std::vector<docstring> altfonts_;
103         ///
104         docstring completefont_;
105         ///
106         docstring ot1font_;
107         ///
108         docstring osffont_;
109         ///
110         docstring packageoption_;
111         ///
112         docstring osfoption_;
113         ///
114         docstring scoption_;
115         ///
116         docstring osfscoption_;
117         ///
118         docstring scaleoption_;
119         ///
120         std::vector<std::string> provides_;
121         ///
122         docstring requires_;
123         ///
124         bool osfdefault_;
125         ///
126         bool switchdefault_;
127 };
128   
129   
130 /** The list of available LaTeX fonts
131  */
132 class LaTeXFonts {
133 public:
134         ///
135         typedef std::map<docstring, LaTeXFont> TexFontMap;
136         /// Get all LaTeXFonts
137         TexFontMap getLaTeXFonts();
138         /// Get a specific LaTeXFont \p name
139         LaTeXFont getLaTeXFont(docstring const & name);
140         /// Get a specific AltFont \p name
141         LaTeXFont getAltFont(docstring const & name);
142 private:
143         ///
144         void readLaTeXFonts();
145         ///
146         TexFontMap texfontmap_;
147         ///
148         TexFontMap texaltfontmap_;
149 };
150
151 /// Implementation is in LyX.cpp
152 extern LaTeXFonts & theLaTeXFonts();
153
154
155 } // namespace lyx
156
157 #endif