]> git.lyx.org Git - lyx.git/blob - src/Font.h
revert erroneous previous commit.
[lyx.git] / src / Font.h
1 // -*- C++ -*-
2 /**
3  * \file src/Font.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author Angus Leeming
10  * \author Dekel Tsur
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef FONT_H
16 #define FONT_H
17
18 #ifdef TEX2LYX
19 #include "tex2lyx/Font.h"
20 #else
21
22 #include "ColorCode.h"
23 #include "FontInfo.h"
24
25 #include "support/strfwd.h"
26
27
28 namespace lyx {
29
30 class Lexer;
31 class BufferParams;
32 class Language;
33 class LaTeXFeatures;
34 class OutputParams;
35
36 ///
37 class Font {
38
39 public:
40         ///
41         explicit Font(FontInfo = sane_font, Language const * l = 0);
42
43         ///
44         FontInfo & fontInfo() { return bits_; }
45         ///
46         FontInfo const & fontInfo() const { return bits_; }
47         ///
48         Language const * language() const { return lang_; }
49         ///
50         bool isRightToLeft() const;
51         ///
52         bool isVisibleRightToLeft() const;
53         ///
54         void setLanguage(Language const * l);
55
56         /// Returns misc flag after LyX text format
57         FontState setLyXMisc(std::string const &);
58
59
60         /// Returns size of font in LaTeX text notation
61         std::string const latexSize() const;
62
63         /** Updates font settings according to request.
64             If an attribute is IGNORE, the attribute is left as it is.
65             When toggleall = true, all properties that matches the font in use
66             will have the effect that the properties is reset to the
67             default.  If we have a text that is TYPEWRITER_FAMILY, and is
68             update()'ed with TYPEWRITER_FAMILY, the operation will be as if
69             a INHERIT_FAMILY was asked for.  This is necessary for the
70             toggle-user-defined-style button on the toolbar.
71         */
72         void update(Font const & newfont,
73                     Language const * default_lang,
74                     bool toggleall = false);
75
76         /// Writes the changes from this font to orgfont in .lyx format in file
77         void lyxWriteChanges(Font const & orgfont, std::ostream &) const;
78
79         /** Writes the head of the LaTeX needed to change to this font.
80             Writes to string, the head of the LaTeX needed to change
81             to this font. Returns number of chars written. Base is the
82             font state active now.
83         */
84         int latexWriteStartChanges(odocstream &, BufferParams const & bparams,
85                                    OutputParams const & runparams,
86                                    Font const & base,
87                                    Font const & prev) const;
88
89         /** Writes the tail of the LaTeX needed to change to this font.
90             Returns number of chars written. Base is the font state we want
91             to achieve.
92         */
93         int latexWriteEndChanges(odocstream &, BufferParams const & bparams,
94                                  OutputParams const & runparams,
95                                  Font const & base,
96                                  Font const & next,
97                                  bool const & closeLanguage = true) const;
98
99
100         /// Build GUI description of font state
101         docstring const stateText(BufferParams * params) const;
102
103         ///
104         void validate(LaTeXFeatures & features) const;
105
106         ///
107         friend
108         bool operator==(Font const & font1, Font const & font2);
109         ///
110         friend
111         std::ostream & operator<<(std::ostream & os, Font const & font);
112
113         /// Set \param data using \param font and \param toggle.
114         std::string toString(bool toggle) const;
115
116         /// Set \param font and \param toggle using \param data. Return success.
117         bool fromString(std::string const & data, bool & toggle);
118
119 private:
120         ///
121         FontInfo bits_;
122         ///
123         Language const * lang_;
124
125         /// Did latexWriteStartChanges open an encoding environment?
126         mutable bool open_encoding_;
127 };
128
129
130 ///
131 inline
132 bool operator==(Font const & font1, Font const & font2)
133 {
134         return font1.bits_ == font2.bits_ && font1.lang_ == font2.lang_;
135 }
136
137 ///
138 inline
139 bool operator!=(Font const & font1, Font const & font2)
140 {
141         return !(font1 == font2);
142 }
143
144 /** Returns the current freefont, encoded as a std::string to be passed to the
145  *  frontends. Implemented in Text3.cpp.
146  */
147 std::string const freefont2string();
148
149
150 /// Set family after LyX text format
151 void setLyXFamily(std::string const &, FontInfo &);
152
153 /// Set series after LyX text format
154 void setLyXSeries(std::string const &, FontInfo &);
155
156 /// Set shape after LyX text format
157 void setLyXShape(std::string const &, FontInfo &);
158
159 /// Set size after LyX text format
160 void setLyXSize(std::string const &, FontInfo &);
161
162 /// Sets color after LyX text format
163 void setLyXColor(std::string const &, FontInfo &);
164
165 /// Read a font specification from Lexer. Used for layout files.
166 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
167
168 } // namespace lyx
169
170 #endif // TEX2LYX
171 #endif