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