]> git.lyx.org Git - lyx.git/blob - src/bufferview_funcs.cpp
cosmetics
[lyx.git] / src / bufferview_funcs.cpp
1 /**
2  * \file bufferview_funcs.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author John Levon
9  * \author Angus Leeming
10  * \author Juergen Vigna
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #include <config.h>
16
17 #include "bufferview_funcs.h"
18
19 #include "Buffer.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
22 #include "Cursor.h"
23 #include "CoordCache.h"
24 #include "gettext.h"
25 #include "Language.h"
26 #include "Color.h"
27 #include "Lexer.h"
28
29 #include "frontends/alert.h"
30
31 #include "insets/InsetCommand.h"
32 #include "insets/InsetText.h"
33
34 #include "support/convert.h"
35
36 #include <sstream>
37
38 using std::istringstream;
39 using std::ostringstream;
40 using std::string;
41 using std::vector;
42 using std::find;
43
44
45 namespace lyx {
46
47 using support::bformat;
48
49 namespace bv_funcs {
50
51 // Set data using font and toggle
52 // If successful, returns true
53 bool font2string(Font const & font, bool const toggle, string & data)
54 {
55         string lang = "ignore";
56         if (font.language())
57                 lang = font.language()->lang();
58
59         ostringstream os;
60         os << "family " << font.family() << '\n'
61            << "series " << font.series() << '\n'
62            << "shape " << font.shape() << '\n'
63            << "size " << font.size() << '\n'
64            << "emph " << font.emph() << '\n'
65            << "underbar " << font.underbar() << '\n'
66            << "noun " << font.noun() << '\n'
67            << "number " << font.number() << '\n'
68            << "color " << font.color() << '\n'
69            << "language " << lang << '\n'
70            << "toggleall " << convert<string>(toggle);
71         data = os.str();
72         return true;
73 }
74
75
76 // Set font and toggle using data
77 // If successful, returns true
78 bool string2font(string const & data, Font & font, bool & toggle)
79 {
80         istringstream is(data);
81         Lexer lex(0,0);
82         lex.setStream(is);
83
84         int nset = 0;
85         while (lex.isOK()) {
86                 string token;
87                 if (lex.next())
88                         token = lex.getString();
89
90                 if (token.empty() || !lex.next())
91                         break;
92
93                 if (token == "family") {
94                         int const next = lex.getInteger();
95                         font.setFamily(Font::FONT_FAMILY(next));
96
97                 } else if (token == "series") {
98                         int const next = lex.getInteger();
99                         font.setSeries(Font::FONT_SERIES(next));
100
101                 } else if (token == "shape") {
102                         int const next = lex.getInteger();
103                         font.setShape(Font::FONT_SHAPE(next));
104
105                 } else if (token == "size") {
106                         int const next = lex.getInteger();
107                         font.setSize(Font::FONT_SIZE(next));
108
109                 } else if (token == "emph" || token == "underbar" ||
110                            token == "noun" || token == "number") {
111
112                         int const next = lex.getInteger();
113                         Font::FONT_MISC_STATE const misc =
114                                 Font::FONT_MISC_STATE(next);
115
116                         if (token == "emph")
117                             font.setEmph(misc);
118                         else if (token == "underbar")
119                                 font.setUnderbar(misc);
120                         else if (token == "noun")
121                                 font.setNoun(misc);
122                         else if (token == "number")
123                                 font.setNumber(misc);
124
125                 } else if (token == "color") {
126                         int const next = lex.getInteger();
127                         font.setColor(Color::color(next));
128
129                 } else if (token == "language") {
130                         string const next = lex.getString();
131                         if (next == "ignore")
132                                 font.setLanguage(ignore_language);
133                         else
134                                 font.setLanguage(languages.getLanguage(next));
135
136                 } else if (token == "toggleall") {
137                         toggle = lex.getBool();
138
139                 } else {
140                         // Unrecognised token
141                         break;
142                 }
143
144                 ++nset;
145         }
146         return (nset > 0);
147 }
148
149
150 } // namespace bv_funcs
151
152
153 } // namespace lyx