]> git.lyx.org Git - lyx.git/blob - src/bufferparams.C
1478f966861f379505de5e8d646e192619cc5591
[lyx.git] / src / bufferparams.C
1 /* This file is part of
2 * ======================================================
3
4 *           LyX, The Document Processor
5 *        
6 *           Copyright (C) 1995 Matthias Ettrich
7 *           Copyright (C) 1995-1998 The LyX Team.
8 *
9 *======================================================*/
10
11 #include <config.h>
12 #include <stdlib.h>
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 "error.h"
23 #include "lyxlib.h"
24
25 //      $Id: bufferparams.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $      
26
27 #if !defined(lint) && !defined(WITH_WARNINGS)
28 static char vcid[] = "$Id: bufferparams.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $";
29 #endif /* lint */
30
31
32 BufferParams::BufferParams()
33 {
34         paragraph_separation = LYX_PARSEP_INDENT;
35         defskip = VSpace(VSpace::MEDSKIP); 
36         quotes_language = InsetQuotes::EnglishQ;
37         quotes_times = InsetQuotes::DoubleQ;
38         fontsize = "default";
39         textclass = 0; 
40         /*  PaperLayout */
41         papersize = PAPER_DEFAULT;
42         papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
43         paperpackage = PACKAGE_NONE;
44         orientation = ORIENTATION_PORTRAIT;
45         use_geometry = false;
46         use_amsmath = false;
47         secnumdepth = 3;
48         tocdepth = 3;
49         language = "default";
50         fonts = "default";
51         inputenc = "default";
52         graphicsDriver = "default";
53         sides = 1;
54         columns = 1;
55         pagestyle = "default";
56         for(int iter = 0; iter < 4; iter++) {
57                 user_defined_bullets[iter] = temp_bullets[iter] 
58                                            = ITEMIZE_DEFAULTS[iter];
59         }
60         allowAccents=false;
61 }
62
63
64 void BufferParams::Copy(BufferParams const &p)
65 {
66         paragraph_separation = p.paragraph_separation;
67         defskip = p.defskip;
68         quotes_language = p.quotes_language;
69         quotes_times = p.quotes_times;
70         fontsize = p.fontsize;
71         textclass = p.textclass;
72         papersize = p.papersize;
73         papersize2 = p.papersize2;
74         paperpackage = p.paperpackage;
75         orientation = p.orientation;
76         use_geometry = p.use_geometry;
77         paperwidth = p.paperwidth;
78         paperheight = p.paperheight;
79         leftmargin = p.leftmargin;
80         topmargin = p.topmargin;
81         rightmargin = p.rightmargin;
82         bottommargin = p.bottommargin;
83         headheight = p.headheight;
84         headsep = p.headsep;
85         footskip = p.footskip;
86         graphicsDriver = p.graphicsDriver;
87         fonts = p.fonts;
88         spacing = p.spacing;
89         secnumdepth = p.secnumdepth;
90         tocdepth = p.tocdepth;
91         language = p.language;
92         inputenc = p.inputenc;
93         preamble = p.preamble;
94         options = p.options;
95         float_placement = p.float_placement;
96         columns = p.columns;
97         sides = p.sides;
98         pagestyle = p.pagestyle;
99
100         // WARNING destructor will deallocate paragraph!!
101         // this is not good and will cause an error somewhere else.
102         //paragraph = p.paragraph; 
103
104         for (int i = 0; i < 4; ++i) {
105                 temp_bullets[i] = p.temp_bullets[i];
106                 user_defined_bullets[i] = p.user_defined_bullets[i];
107         }
108
109         allowAccents=p.allowAccents;
110         use_amsmath = p.use_amsmath;
111 }
112
113
114 void BufferParams::writeFile(FILE *file)
115 {
116         // The top of the file is written by the buffer.
117         // Prints out the buffer info into the .lyx file given by file
118
119         // the textclass
120         fprintf(file, "\\textclass %s\n",
121                 lyxstyle.NameOfClass(textclass).c_str());
122         
123         // then the the preamble
124         if (!preamble.empty()) {
125                 fprintf(file, "\\begin_preamble\n");
126                 {
127                         // remove '\n' from the end of preamble
128                         preamble.strip('\n');
129                         
130                         // write out the whole preamble  in one go
131                         fwrite(preamble.c_str(),
132                                sizeof(char),
133                                preamble.length(),
134                                file);
135                         fprintf(file, "\n\\end_preamble\n");
136                 }
137         }
138       
139         /* the options */ 
140         if (!options.empty()) {
141                 fprintf(file,
142                         "\\options %s\n",
143                         options.c_str());
144         }
145    
146         /* then the text parameters */ 
147         fprintf(file, "\\language %s\n", language.c_str());
148         fprintf(file, "\\inputencoding %s\n", inputenc.c_str());
149         fprintf(file, "\\fontscheme %s\n", fonts.c_str());
150         fprintf(file, "\\graphics %s\n", graphicsDriver.c_str());
151
152         if (!float_placement.empty()) {
153                 fprintf(file,
154                         "\\float_placement %s\n",
155                         float_placement.c_str());
156         }
157         fprintf(file, "\\paperfontsize %s\n", fontsize.c_str());
158
159         spacing.writeFile(file);
160
161         fprintf(file, "\\papersize %s\n", string_papersize[papersize2]);
162         fprintf(file, "\\paperpackage %s\n",
163                 string_paperpackages[paperpackage]);
164         fprintf(file, "\\use_geometry %d\n",use_geometry);
165         fprintf(file, "\\use_amsmath %d\n",use_amsmath);
166         fprintf(file, "\\paperorientation %s\n",
167                 string_orientation[orientation]);
168         if (!paperwidth.empty())
169             fprintf(file, "\\paperwidth %s\n",
170                     VSpace(paperwidth).asLyXCommand().c_str());
171         if (!paperheight.empty())
172             fprintf(file, "\\paperheight %s\n",
173                     VSpace(paperheight).asLyXCommand().c_str());
174         if (!leftmargin.empty())
175             fprintf(file, "\\leftmargin %s\n",
176                     VSpace(leftmargin).asLyXCommand().c_str());
177         if (!topmargin.empty())
178             fprintf(file, "\\topmargin %s\n",
179                     VSpace(topmargin).asLyXCommand().c_str());
180         if (!rightmargin.empty())
181             fprintf(file, "\\rightmargin %s\n",
182                     VSpace(rightmargin).asLyXCommand().c_str());
183         if (!bottommargin.empty())
184             fprintf(file, "\\bottommargin %s\n",
185                     VSpace(bottommargin).asLyXCommand().c_str());
186         if (!headheight.empty())
187             fprintf(file, "\\headheight %s\n",
188                     VSpace(headheight).asLyXCommand().c_str());
189         if (!headsep.empty())
190             fprintf(file, "\\headsep %s\n",
191                     VSpace(headsep).asLyXCommand().c_str());
192         if (!footskip.empty())
193             fprintf(file, "\\footskip %s\n",
194                     VSpace(footskip).asLyXCommand().c_str());
195         fprintf(file, "\\secnumdepth %d\n", secnumdepth);
196         fprintf(file, "\\tocdepth %d\n", tocdepth);
197         fprintf(file, "\\paragraph_separation %s\n",
198                 string_paragraph_separation[paragraph_separation]);
199         fprintf(file, "\\defskip %s\n", defskip.asLyXCommand().c_str());
200         fprintf(file, "\\quotes_language %s\n",
201                 string_quotes_language[quotes_language]);
202         switch(quotes_times) {
203         case InsetQuotes::SingleQ: 
204                 fprintf(file, "\\quotes_times 1\n"); break;
205         case InsetQuotes::DoubleQ: 
206                 fprintf(file, "\\quotes_times 2\n"); break;
207         }               
208         fprintf(file, "\\papercolumns %d\n", columns);
209         fprintf(file, "\\papersides %d\n", sides);
210         fprintf(file, "\\paperpagestyle %s\n", pagestyle.c_str());
211         for (int i = 0; i < 4; ++i) {
212                 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
213                         if (user_defined_bullets[i].getFont() != -1) {
214                                 fprintf(file, "\\bullet %d\n\t%d\n\t%d\n\t%d\n\\end_bullet\n",
215                                                 i,
216                                                 user_defined_bullets[i].getFont(),
217                                                 user_defined_bullets[i].getCharacter(),
218                                                 user_defined_bullets[i].getSize());
219                         }
220                         else {
221                                 fprintf(file, "\\bulletLaTeX %d\n\t%s\n\\end_bullet\n",
222                                                 i,
223                                                 user_defined_bullets[i].c_str());
224                         }
225                 }
226         }
227 }
228
229
230 void BufferParams::useClassDefaults() {
231         LyXTextClass *tclass = lyxstyle.TextClass(textclass);
232
233         sides = tclass->sides;
234         columns = tclass->columns;
235         pagestyle = tclass->pagestyle;
236         options = tclass->options;
237         secnumdepth = tclass->secnumdepth;
238         tocdepth = tclass->tocdepth;
239 }
240
241
242 void BufferParams::readPreamble(LyXLex &lex)
243 {
244         if (lex.GetString() != "\\begin_preamble")
245                 lyxerr.print("Error (BufferParams::readPreamble):"
246                               "consistency check failed.");
247
248         preamble = lex.getLongString("\\end_preamble");
249 }
250
251
252 void BufferParams::readLanguage(LyXLex &lex)
253 {
254         LString tmptok;
255         LString test;
256         int n = 0;
257         
258         if (!lex.next()) return;
259         
260         tmptok = lex.GetString();
261         // check if tmptok is part of tex_babel in tex-defs.h
262         while (true) {
263                 test = tex_babel[n++];
264                 
265                 if (test == tmptok) {
266                         language = tmptok;
267                         break;
268                 }
269                 else if (test.empty()) {
270                         lyxerr.print("Warning: language `"
271                                       + tmptok + "' not recognized!");
272                         lyxerr.print("         Setting language to `default'.");
273                         language = "default";
274                         break;   
275                 }      
276         }
277 }
278
279
280 void BufferParams::readGraphicsDriver(LyXLex &lex)
281 {
282         LString tmptok;
283         LString test;
284         int n=0;
285         
286         
287         if (!lex.next()) return;
288         
289         tmptok = lex.GetString();
290         // check if tmptok is part of tex_graphics in tex_defs.h
291         while (true) {
292                 test = tex_graphics[n++];
293                 
294                 if (test == tmptok) {    
295                         graphicsDriver = tmptok;
296                         break;
297                 }      
298                 else if (test == "last_item") {
299                         lex.printError(
300                                 "Warning: graphics driver `$$Token' not recognized!\n"
301                                 "         Setting graphics driver to `default'.\n");
302                         graphicsDriver = "default";
303                         break;
304                 }      
305         }
306 }