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