]> git.lyx.org Git - lyx.git/blob - src/bufferview_funcs.C
changelogs
[lyx.git] / src / bufferview_funcs.C
1 /**
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.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author John Levon
9  * \author Angus Leeming
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "bufferview_funcs.h"
17
18 #include "author.h"
19 #include "buffer.h"
20 #include "bufferparams.h"
21 #include "BufferView.h"
22 #include "cursor.h"
23 #include "gettext.h"
24 #include "language.h"
25 #include "LColor.h"
26 #include "lyxlex.h"
27 #include "lyxrow.h"
28 #include "paragraph.h"
29 #include "ParagraphParameters.h"
30 #include "pariterator.h"
31
32 #include "frontends/Alert.h"
33 #include "frontends/LyXView.h"
34
35 #include "insets/insettext.h"
36
37 #include "support/tostr.h"
38
39 #include <sstream>
40
41 using lyx::support::bformat;
42
43 using std::istringstream;
44 using std::ostringstream;
45 using std::string;
46
47
48 namespace bv_funcs {
49
50 // Set data using font and toggle
51 // If successful, returns true
52 bool font2string(LyXFont const & font, bool toggle, string & data)
53 {
54         string lang = "ignore";
55         if (font.language())
56                 lang = font.language()->lang();
57
58         ostringstream os;
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);
70         data = os.str();
71         return true;
72 }
73
74
75 // Set font and toggle using data
76 // If successful, returns true
77 bool string2font(string const & data, LyXFont & font, bool & toggle)
78 {
79         istringstream is(data);
80         LyXLex lex(0,0);
81         lex.setStream(is);
82
83         int nset = 0;
84         while (lex.isOK()) {
85                 string token;
86                 if (lex.next())
87                         token = lex.getString();
88
89                 if (token.empty() || !lex.next())
90                         break;
91
92                 if (token == "family") {
93                         int const next = lex.getInteger();
94                         font.setFamily(LyXFont::FONT_FAMILY(next));
95
96                 } else if (token == "series") {
97                         int const next = lex.getInteger();
98                         font.setSeries(LyXFont::FONT_SERIES(next));
99
100                 } else if (token == "shape") {
101                         int const next = lex.getInteger();
102                         font.setShape(LyXFont::FONT_SHAPE(next));
103
104                 } else if (token == "size") {
105                         int const next = lex.getInteger();
106                         font.setSize(LyXFont::FONT_SIZE(next));
107
108                 } else if (token == "emph" || token == "underbar" ||
109                            token == "noun" || token == "number") {
110
111                         int const next = lex.getInteger();
112                         LyXFont::FONT_MISC_STATE const misc =
113                                 LyXFont::FONT_MISC_STATE(next);
114
115                         if (token == "emph")
116                             font.setEmph(misc);
117                         else if (token == "underbar")
118                                 font.setUnderbar(misc);
119                         else if (token == "noun")
120                                 font.setNoun(misc);
121                         else if (token == "number")
122                                 font.setNumber(misc);
123
124                 } else if (token == "color") {
125                         int const next = lex.getInteger();
126                         font.setColor(LColor::color(next));
127
128                 } else if (token == "language") {
129                         string const next = lex.getString();
130                         if (next == "ignore")
131                                 font.setLanguage(ignore_language);
132                         else
133                                 font.setLanguage(languages.getLanguage(next));
134
135                 } else if (token == "toggleall") {
136                         toggle = lex.getBool();
137
138                 } else {
139                         // Unrecognised token
140                         break;
141                 }
142
143                 ++nset;
144         }
145         return (nset > 0);
146 }
147
148 } // namespace bv_funcs