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