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 "pariterator.h"
32 #include "frontends/Alert.h"
33 #include "frontends/LyXView.h"
35 #include "insets/insettext.h"
37 #include "support/tostr.h"
41 using lyx::support::bformat;
43 using std::istringstream;
44 using std::ostringstream;
50 // Set data using font and toggle
51 // If successful, returns true
52 bool font2string(LyXFont const & font, bool toggle, string & data)
54 string lang = "ignore";
56 lang = font.language()->lang();
59 os << "family " << font.family() << '\n'
60 << "series " << font.series() << '\n'
61 << "shape " << font.shape() << '\n'
62 << "size " << font.size() << '\n'
63 << "emph " << font.emph() << '\n'
64 << "underbar " << font.underbar() << '\n'
65 << "noun " << font.noun() << '\n'
66 << "number " << font.number() << '\n'
67 << "color " << font.color() << '\n'
68 << "language " << lang << '\n'
69 << "toggleall " << tostr(toggle);
75 // Set font and toggle using data
76 // If successful, returns true
77 bool string2font(string const & data, LyXFont & font, bool & toggle)
79 istringstream is(data);
87 token = lex.getString();
89 if (token.empty() || !lex.next())
92 if (token == "family") {
93 int const next = lex.getInteger();
94 font.setFamily(LyXFont::FONT_FAMILY(next));
96 } else if (token == "series") {
97 int const next = lex.getInteger();
98 font.setSeries(LyXFont::FONT_SERIES(next));
100 } else if (token == "shape") {
101 int const next = lex.getInteger();
102 font.setShape(LyXFont::FONT_SHAPE(next));
104 } else if (token == "size") {
105 int const next = lex.getInteger();
106 font.setSize(LyXFont::FONT_SIZE(next));
108 } else if (token == "emph" || token == "underbar" ||
109 token == "noun" || token == "number") {
111 int const next = lex.getInteger();
112 LyXFont::FONT_MISC_STATE const misc =
113 LyXFont::FONT_MISC_STATE(next);
117 else if (token == "underbar")
118 font.setUnderbar(misc);
119 else if (token == "noun")
121 else if (token == "number")
122 font.setNumber(misc);
124 } else if (token == "color") {
125 int const next = lex.getInteger();
126 font.setColor(LColor::color(next));
128 } else if (token == "language") {
129 string const next = lex.getString();
130 if (next == "ignore")
131 font.setLanguage(ignore_language);
133 font.setLanguage(languages.getLanguage(next));
135 } else if (token == "toggleall") {
136 toggle = lex.getBool();
139 // Unrecognised token
148 } // namespace bv_funcs