* qt_helpers.cpp:
[lyx.git] / src / Font.h
blob97d403627ecd1087ada19c1e54b155946d7974da
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.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
10 * \author Dekel Tsur
12 * Full author contact details are available in file CREDITS.
15 #ifndef FONT_H
16 #define FONT_H
18 #ifdef TEX2LYX
19 #include "tex2lyx/Font.h"
20 #else
22 #include "ColorCode.h"
23 #include "FontInfo.h"
25 #include "support/strfwd.h"
28 namespace lyx {
30 class Lexer;
31 class BufferParams;
32 class Language;
33 class LaTeXFeatures;
34 class OutputParams;
36 ///
37 class Font {
39 public:
40 ///
41 explicit Font(FontInfo = sane_font, Language const * l = 0);
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);
60 /// Returns misc flag after LyX text format
61 FontState setLyXMisc(std::string const &);
64 /// Returns size of font in LaTeX text notation
65 std::string const latexSize() const;
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.
76 void update(Font const & newfont,
77 Language const * default_lang,
78 bool toggleall = false);
80 /// Writes the changes from this font to orgfont in .lyx format in file
81 void lyxWriteChanges(Font const & orgfont, std::ostream &) const;
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.
88 int latexWriteStartChanges(odocstream &, BufferParams const & bparams,
89 OutputParams const & runparams,
90 Font const & base,
91 Font const & prev) const;
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.
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;
104 /// Build GUI description of font state
105 docstring const stateText(BufferParams * params) const;
108 void validate(LaTeXFeatures & features) const;
111 friend
112 bool operator==(Font const & font1, Font const & font2);
114 friend
115 std::ostream & operator<<(std::ostream & os, Font const & font);
117 /// Set \param data using \param font and \param toggle.
118 std::string toString(bool toggle) const;
120 /// Set \param font and \param toggle using \param data. Return success.
121 bool fromString(std::string const & data, bool & toggle);
123 private:
125 FontInfo bits_;
127 Language const * lang_;
129 bool misspelled_;
131 /// Did latexWriteStartChanges open an encoding environment?
132 mutable bool open_encoding_;
137 inline
138 bool operator==(Font const & font1, Font const & font2)
140 return font1.bits_ == font2.bits_ && font1.lang_ == font2.lang_
141 && font1.misspelled_ == font2.misspelled_;
145 inline
146 bool operator!=(Font const & font1, Font const & font2)
148 return !(font1 == font2);
151 /** Returns the current freefont, encoded as a std::string to be passed to the
152 * frontends. Implemented in Text3.cpp.
154 std::string const freefont2string();
157 /// Set family after LyX text format
158 void setLyXFamily(std::string const &, FontInfo &);
160 /// Set series after LyX text format
161 void setLyXSeries(std::string const &, FontInfo &);
163 /// Set shape after LyX text format
164 void setLyXShape(std::string const &, FontInfo &);
166 /// Set size after LyX text format
167 void setLyXSize(std::string const &, FontInfo &);
169 /// Sets color after LyX text format
170 void setLyXColor(std::string const &, FontInfo &);
172 /// Read a font specification from Lexer. Used for layout files.
173 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
175 } // namespace lyx
177 #endif // TEX2LYX
178 #endif