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