]> git.lyx.org Git - lyx.git/blob - src/bufferparams.C
Small fix.
[lyx.git] / src / bufferparams.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12 #include <cstdlib>
13
14 #ifdef __GNUG__
15 #pragma implementation "bufferparams.h"
16 #endif
17
18 #include "bufferparams.h"
19 #include "tex-strings.h"
20 #include "layout.h"
21 #include "vspace.h"
22 #include "debug.h"
23 #include "support/lyxlib.h"
24 #include "support/lstrings.h"
25 #include "lyxrc.h"
26 #include "language.h"
27
28 using std::ostream;
29 using std::endl;
30
31 BufferParams::BufferParams()
32 {
33         paragraph_separation = PARSEP_INDENT;
34         defskip = VSpace(VSpace::MEDSKIP); 
35         quotes_language = InsetQuotes::EnglishQ;
36         quotes_times = InsetQuotes::DoubleQ;
37         fontsize = "default";
38         // Initialize textclass to point to article. if `first' is
39         // true in the returned pair, then `second' is the textclass
40         // number; if it is false, second is 0. In both cases, second
41         // is what we want.
42         textclass = textclasslist.NumberOfClass("article").second;
43
44         /*  PaperLayout */
45         papersize = PAPER_DEFAULT;
46         papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
47         paperpackage = PACKAGE_NONE;
48         orientation = ORIENTATION_PORTRAIT;
49         use_geometry = false;
50         use_amsmath = false;
51         secnumdepth = 3;
52         tocdepth = 3;
53         language = "default";
54         language_info = default_language;
55         fonts = "default";
56         inputenc = "auto";
57         graphicsDriver = "default";
58         sides = LyXTextClass::OneSide;
59         columns = 1;
60         pagestyle = "default";
61         for(int iter = 0; iter < 4; ++iter) {
62                 user_defined_bullets[iter] = temp_bullets[iter] 
63                                            = ITEMIZE_DEFAULTS[iter];
64         }
65 }
66
67
68 void BufferParams::writeFile(ostream & os) const
69 {
70         // The top of the file is written by the buffer.
71         // Prints out the buffer info into the .lyx file given by file
72
73         // the textclass
74         os << "\\textclass " << textclasslist.NameOfClass(textclass) << '\n';
75         
76         // then the the preamble
77         if (!preamble.empty()) {
78                 // remove '\n' from the end of preamble
79                 string tmppreamble = strip(preamble, '\n');
80                 os << "\\begin_preamble\n"
81                    << tmppreamble
82                    << "\n\\end_preamble\n";
83         }
84       
85         /* the options */ 
86         if (!options.empty()) {
87                 os << "\\options " << options << '\n';
88         }
89    
90         /* then the text parameters */
91         os << "\\language " << language
92            << "\n\\inputencoding " << inputenc
93            << "\n\\fontscheme " << fonts
94            << "\n\\graphics " << graphicsDriver << '\n';
95
96         if (!float_placement.empty()) {
97                 os << "\\float_placement " << float_placement << '\n';
98         }
99         os << "\\paperfontsize " << fontsize << '\n';
100
101         spacing.writeFile(os);
102
103         os << "\\papersize " << string_papersize[papersize2]
104            << "\n\\paperpackage " << string_paperpackages[paperpackage]
105            << "\n\\use_geometry " << use_geometry
106            << "\n\\use_amsmath " << use_amsmath
107            << "\n\\paperorientation " << string_orientation[orientation]
108            << '\n';
109         if (!paperwidth.empty())
110                 os << "\\paperwidth "
111                    << VSpace(paperwidth).asLyXCommand() << '\n';
112         if (!paperheight.empty())
113                 os << "\\paperheight "
114                    << VSpace(paperheight).asLyXCommand() << '\n';
115         if (!leftmargin.empty())
116                 os << "\\leftmargin "
117                    << VSpace(leftmargin).asLyXCommand() << '\n';
118         if (!topmargin.empty())
119                 os << "\\topmargin "
120                    << VSpace(topmargin).asLyXCommand() << '\n';
121         if (!rightmargin.empty())
122                 os << "\\rightmargin "
123                    << VSpace(rightmargin).asLyXCommand() << '\n';
124         if (!bottommargin.empty())
125                 os << "\\bottommargin "
126                    << VSpace(bottommargin).asLyXCommand() << '\n';
127         if (!headheight.empty())
128                 os << "\\headheight "
129                    << VSpace(headheight).asLyXCommand() << '\n';
130         if (!headsep.empty())
131                 os << "\\headsep "
132                    << VSpace(headsep).asLyXCommand() << '\n';
133         if (!footskip.empty())
134                 os << "\\footskip "
135                    << VSpace(footskip).asLyXCommand() << '\n';
136         os << "\\secnumdepth " << secnumdepth
137            << "\n\\tocdepth " << tocdepth
138            << "\n\\paragraph_separation "
139            << string_paragraph_separation[paragraph_separation]
140            << "\n\\defskip " << defskip.asLyXCommand()
141            << "\n\\quotes_language "
142            << string_quotes_language[quotes_language] << '\n';
143         switch(quotes_times) {
144                 // An output operator for insetquotes would be nice
145         case InsetQuotes::SingleQ:
146                 os << "\\quotes_times 1\n"; break;
147         case InsetQuotes::DoubleQ: 
148                 os << "\\quotes_times 2\n"; break;
149         }
150         os << "\\papercolumns " << columns
151            << "\n\\papersides " << sides
152            << "\n\\paperpagestyle " << pagestyle << '\n';
153         for (int i = 0; i < 4; ++i) {
154                 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
155                         if (user_defined_bullets[i].getFont() != -1) {
156                                 os << "\\bullet " << i
157                                    << "\n\t"
158                                    << user_defined_bullets[i].getFont()
159                                    << "\n\t"
160                                    << user_defined_bullets[i].getCharacter()
161                                    << "\n\t"
162                                    << user_defined_bullets[i].getSize()
163                                    << "\n\\end_bullet\n";
164                         }
165                         else {
166                                 os << "\\bulletLaTeX " << i
167                                    << "\n\t"
168                                    << user_defined_bullets[i].c_str()
169                                    << "\n\\end_bullet\n";
170                         }
171                 }
172         }
173 }
174
175
176 void BufferParams::useClassDefaults() {
177         LyXTextClass const & tclass = textclasslist.TextClass(textclass);
178
179         sides = tclass.sides();
180         columns = tclass.columns();
181         pagestyle = tclass.pagestyle();
182         options = tclass.options();
183         secnumdepth = tclass.secnumdepth();
184         tocdepth = tclass.tocdepth();
185 }
186
187
188 void BufferParams::readPreamble(LyXLex & lex)
189 {
190         if (lex.GetString() != "\\begin_preamble")
191                 lyxerr << "Error (BufferParams::readPreamble):"
192                         "consistency check failed." << endl;
193
194         preamble = lex.getLongString("\\end_preamble");
195 }
196
197
198 void BufferParams::readLanguage(LyXLex & lex)
199 {
200         if (!lex.next()) return;
201         
202         string tmptok = lex.GetString();
203
204         // check if tmptok is part of tex_babel in tex-defs.h
205         Languages::iterator lit = languages.find(tmptok);
206         if (lit != languages.end()) {
207                 // found it
208                 language = tmptok;
209                 language_info = &(*lit).second;
210         } else {
211                 // not found
212                 language = "default";
213                 language_info = default_language;
214                 if (tmptok != "default") {
215                         lyxerr << "Warning: language `"
216                                << tmptok << "' not recognized!\n"
217                                << "         Setting language to `default'."
218                                << endl;
219                 }
220         }
221 }
222
223
224 void BufferParams::readGraphicsDriver(LyXLex & lex)
225 {
226         string tmptok;
227         string test;
228         int n = 0;
229         
230         
231         if (!lex.next()) return;
232         
233         tmptok = lex.GetString();
234         // check if tmptok is part of tex_graphics in tex_defs.h
235         while (true) {
236                 test = tex_graphics[n++];
237                 
238                 if (test == tmptok) {    
239                         graphicsDriver = tmptok;
240                         break;
241                 }      
242                 else if (test == "last_item") {
243                         lex.printError(
244                                 "Warning: graphics driver `$$Token' not recognized!\n"
245                                 "         Setting graphics driver to `default'.\n");
246                         graphicsDriver = "default";
247                         break;
248                 }      
249         }
250 }