2 * \file bufferview_funcs.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS.
16 #include "bufferview_funcs.h"
20 #include "bufferparams.h"
21 #include "BufferView.h"
28 #include "paragraph.h"
29 #include "ParagraphParameters.h"
30 #include "iterators.h"
32 #include "frontends/Alert.h"
33 #include "frontends/LyXView.h"
35 #include "insets/insettext.h"
37 #include "support/tostr.h"
38 #include "support/std_sstream.h"
40 using lyx::support::bformat;
42 using std::istringstream;
43 using std::ostringstream;
49 // Set data using font and toggle
50 // If successful, returns true
51 bool font2string(LyXFont const & font, bool toggle, string & data)
53 string lang = "ignore";
55 lang = font.language()->lang();
58 os << "family " << font.family() << '\n'
59 << "series " << font.series() << '\n'
60 << "shape " << font.shape() << '\n'
61 << "size " << font.size() << '\n'
62 << "emph " << font.emph() << '\n'
63 << "underbar " << font.underbar() << '\n'
64 << "noun " << font.noun() << '\n'
65 << "number " << font.number() << '\n'
66 << "color " << font.color() << '\n'
67 << "language " << lang << '\n'
68 << "toggleall " << tostr(toggle);
74 // Set font and toggle using data
75 // If successful, returns true
76 bool string2font(string const & data, LyXFont & font, bool & toggle)
78 istringstream is(data);
86 token = lex.getString();
88 if (token.empty() || !lex.next())
91 if (token == "family") {
92 int const next = lex.getInteger();
93 font.setFamily(LyXFont::FONT_FAMILY(next));
95 } else if (token == "series") {
96 int const next = lex.getInteger();
97 font.setSeries(LyXFont::FONT_SERIES(next));
99 } else if (token == "shape") {
100 int const next = lex.getInteger();
101 font.setShape(LyXFont::FONT_SHAPE(next));
103 } else if (token == "size") {
104 int const next = lex.getInteger();
105 font.setSize(LyXFont::FONT_SIZE(next));
107 } else if (token == "emph" || token == "underbar" ||
108 token == "noun" || token == "number") {
110 int const next = lex.getInteger();
111 LyXFont::FONT_MISC_STATE const misc =
112 LyXFont::FONT_MISC_STATE(next);
116 else if (token == "underbar")
117 font.setUnderbar(misc);
118 else if (token == "noun")
120 else if (token == "number")
121 font.setNumber(misc);
123 } else if (token == "color") {
124 int const next = lex.getInteger();
125 font.setColor(LColor::color(next));
127 } else if (token == "language") {
128 string const next = lex.getString();
129 if (next == "ignore")
130 font.setLanguage(ignore_language);
132 font.setLanguage(languages.getLanguage(next));
134 } else if (token == "toggleall") {
135 toggle = lex.getBool();
138 // Unrecognised token
147 } // namespace bv_funcs