]> git.lyx.org Git - lyx.git/blob - src/Font.h
Fix bug #4510: GuiInclude->Edit marks master as changed.
[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         void setMisspelled(bool misspelled) { misspelled_ = misspelled; }
51         ///
52         bool isMisspelled() const { return misspelled_; }
53         ///
54         bool isRightToLeft() const;
55         ///
56         bool isVisibleRightToLeft() const;
57         ///
58         void setLanguage(Language const * l);
59
60         /// Returns misc flag after LyX text format
61         FontState setLyXMisc(std::string const &);
62
63
64         /// Returns size of font in LaTeX text notation
65         std::string const latexSize() const;
66
67         /** Updates font settings according to request.
68             If an attribute is IGNORE, the attribute is left as it is.
69             When toggleall = true, all properties that matches the font in use
70             will have the effect that the properties is reset to the
71             default.  If we have a text that is TYPEWRITER_FAMILY, and is
72             update()'ed with TYPEWRITER_FAMILY, the operation will be as if
73             a INHERIT_FAMILY was asked for.  This is necessary for the
74             toggle-user-defined-style button on the toolbar.
75         */
76         void update(Font const & newfont,
77                     Language const * default_lang,
78                     bool toggleall = false);
79
80         /// Writes the changes from this font to orgfont in .lyx format in file
81         void lyxWriteChanges(Font const & orgfont, std::ostream &) const;
82
83         /** Writes the head of the LaTeX needed to change to this font.
84             Writes to string, the head of the LaTeX needed to change
85             to this font. Returns number of chars written. Base is the
86             font state active now.
87         */
88         int latexWriteStartChanges(odocstream &, BufferParams const & bparams,
89                                    OutputParams const & runparams,
90                                    Font const & base,
91                                    Font const & prev) const;
92
93         /** Writes the tail of the LaTeX needed to change to this font.
94             Returns number of chars written. Base is the font state we want
95             to achieve.
96         */
97         int latexWriteEndChanges(odocstream &, BufferParams const & bparams,
98                                  OutputParams const & runparams,
99                                  Font const & base,
100                                  Font const & next,
101                                  bool const & closeLanguage = true) const;
102
103
104         /// Build GUI description of font state
105         docstring const stateText(BufferParams * params) const;
106
107         ///
108         void validate(LaTeXFeatures & features) const;
109
110         ///
111         friend
112         bool operator==(Font const & font1, Font const & font2);
113         ///
114         friend
115         std::ostream & operator<<(std::ostream & os, Font const & font);
116
117         /// Set \param data using \param font and \param toggle.
118         std::string toString(bool toggle) const;
119
120         /// Set \param font and \param toggle using \param data. Return success.
121         bool fromString(std::string const & data, bool & toggle);
122
123 private:
124         ///
125         FontInfo bits_;
126         ///
127         Language const * lang_;
128         ///
129         bool misspelled_;
130
131         /// Did latexWriteStartChanges open an encoding environment?
132         mutable bool open_encoding_;
133 };
134
135
136 ///
137 inline
138 bool operator==(Font const & font1, Font const & font2)
139 {
140         return font1.bits_ == font2.bits_ && font1.lang_ == font2.lang_
141             && font1.misspelled_ == font2.misspelled_;
142 }
143
144 ///
145 inline
146 bool operator!=(Font const & font1, Font const & font2)
147 {
148         return !(font1 == font2);
149 }
150
151 /** Returns the current freefont, encoded as a std::string to be passed to the
152  *  frontends. Implemented in Text3.cpp.
153  */
154 std::string const freefont2string();
155
156
157 /// Set family after LyX text format
158 void setLyXFamily(std::string const &, FontInfo &);
159
160 /// Set series after LyX text format
161 void setLyXSeries(std::string const &, FontInfo &);
162
163 /// Set shape after LyX text format
164 void setLyXShape(std::string const &, FontInfo &);
165
166 /// Set size after LyX text format
167 void setLyXSize(std::string const &, FontInfo &);
168
169 /// Sets color after LyX text format
170 void setLyXColor(std::string const &, FontInfo &);
171
172 /// Read a font specification from Lexer. Used for layout files.
173 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
174
175 } // namespace lyx
176
177 #endif // TEX2LYX
178 #endif