]> git.lyx.org Git - lyx.git/blob - src/Font.h
In non-MultiPar insets, we do not want to output paragraphs at all.
[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 #include "ColorCode.h"
19 #include "FontInfo.h"
20
21 #include "support/strfwd.h"
22
23
24 namespace lyx {
25
26 class BufferParams;
27 class Language;
28 class LaTeXFeatures;
29 class OutputParams;
30
31 ///
32 class Font {
33
34 public:
35         ///
36         explicit Font(FontInfo = sane_font, Language const * l = 0);
37
38         ///
39         FontInfo & fontInfo() { return bits_; }
40         ///
41         FontInfo const & fontInfo() const { return bits_; }
42         ///
43         Language const * language() const { return lang_; }
44         ///
45         void setMisspelled(bool misspelled) { misspelled_ = misspelled; }
46         ///
47         bool isMisspelled() const { return misspelled_; }
48         ///
49         bool isRightToLeft() const;
50         ///
51         bool isVisibleRightToLeft() const;
52         ///
53         void setLanguage(Language const * l);
54
55         /// Returns size of font in LaTeX text notation
56         std::string const latexSize() const;
57
58         /** Updates font settings according to request.
59             If an attribute is IGNORE, the attribute is left as it is.
60             When toggleall = true, all properties that matches the font in use
61             will have the effect that the properties is reset to the
62             default.  If we have a text that is TYPEWRITER_FAMILY, and is
63             update()'ed with TYPEWRITER_FAMILY, the operation will be as if
64             a INHERIT_FAMILY was asked for.  This is necessary for the
65             toggle-user-defined-style button on the toolbar.
66         */
67         void update(Font const & newfont,
68                     Language const * default_lang,
69                     bool toggleall = false);
70
71         /// Writes the changes from this font to orgfont in .lyx format in file
72         void lyxWriteChanges(Font const & orgfont, std::ostream &) const;
73
74         /** Writes the head of the LaTeX needed to change to this font.
75             Writes to string, the head of the LaTeX needed to change
76             to this font. Returns number of chars written. Base is the
77             font state active now.
78         */
79         int latexWriteStartChanges(odocstream &, BufferParams const & bparams,
80                                    OutputParams const & runparams,
81                                    Font const & base,
82                                    Font const & prev) const;
83
84         /** Writes the tail of the LaTeX needed to change to this font.
85             Returns number of chars written. Base is the font state we want
86             to achieve.
87         */
88         int latexWriteEndChanges(odocstream &, BufferParams const & bparams,
89                                  OutputParams const & runparams,
90                                  Font const & base,
91                                  Font const & next,
92                                  bool const & closeLanguage = true) const;
93
94
95         /// Build GUI description of font state
96         docstring const stateText(BufferParams * params) const;
97
98         ///
99         void validate(LaTeXFeatures & features) const;
100
101         ///
102         friend
103         bool operator==(Font const & font1, Font const & font2);
104         ///
105         friend
106         std::ostream & operator<<(std::ostream & os, Font const & font);
107
108         /// Set \param data using \param font and \param toggle.
109         std::string toString(bool toggle) const;
110
111         /// Set \param font and \param toggle using \param data. Return success.
112         bool fromString(std::string const & data, bool & toggle);
113
114 private:
115         ///
116         FontInfo bits_;
117         ///
118         Language const * lang_;
119         ///
120         bool misspelled_;
121
122         /// Did latexWriteStartChanges open an encoding environment?
123         mutable bool open_encoding_;
124 };
125
126
127 ///
128 inline
129 bool operator==(Font const & font1, Font const & font2)
130 {
131         return font1.bits_ == font2.bits_ && font1.lang_ == font2.lang_
132             && font1.misspelled_ == font2.misspelled_;
133 }
134
135 ///
136 inline
137 bool operator!=(Font const & font1, Font const & font2)
138 {
139         return !(font1 == font2);
140 }
141
142 /** Returns the current freefont, encoded as a std::string to be passed to the
143  *  frontends. Implemented in Text3.cpp.
144  */
145 std::string const freefont2string();
146
147 } // namespace lyx
148
149 #endif