This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / bufferparams.C
blobff656f202489483ef6f24ea741a182722c444d44
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  * ======================================================*/
11 #include <config.h>
12 #include <cstdlib>
14 #ifdef __GNUG__
15 #pragma implementation "bufferparams.h"
16 #endif
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"
26 BufferParams::BufferParams()
28         paragraph_separation = LYX_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;
58 void BufferParams::Copy(BufferParams const &p)
60         paragraph_separation = p.paragraph_separation;
61         defskip = p.defskip;
62         quotes_language = p.quotes_language;
63         quotes_times = p.quotes_times;
64         fontsize = p.fontsize;
65         textclass = p.textclass;
66         papersize = p.papersize;
67         papersize2 = p.papersize2;
68         paperpackage = p.paperpackage;
69         orientation = p.orientation;
70         use_geometry = p.use_geometry;
71         paperwidth = p.paperwidth;
72         paperheight = p.paperheight;
73         leftmargin = p.leftmargin;
74         topmargin = p.topmargin;
75         rightmargin = p.rightmargin;
76         bottommargin = p.bottommargin;
77         headheight = p.headheight;
78         headsep = p.headsep;
79         footskip = p.footskip;
80         graphicsDriver = p.graphicsDriver;
81         fonts = p.fonts;
82         spacing = p.spacing;
83         secnumdepth = p.secnumdepth;
84         tocdepth = p.tocdepth;
85         language = p.language;
86         inputenc = p.inputenc;
87         preamble = p.preamble;
88         options = p.options;
89         float_placement = p.float_placement;
90         columns = p.columns;
91         sides = p.sides;
92         pagestyle = p.pagestyle;
94         // WARNING destructor will deallocate paragraph!!
95         // this is not good and will cause an error somewhere else.
96         //paragraph = p.paragraph; 
98         for (int i = 0; i < 4; ++i) {
99                 temp_bullets[i] = p.temp_bullets[i];
100                 user_defined_bullets[i] = p.user_defined_bullets[i];
101         }
103         allowAccents=p.allowAccents;
104         use_amsmath = p.use_amsmath;
108 void BufferParams::writeFile(FILE *file)
110         // The top of the file is written by the buffer.
111         // Prints out the buffer info into the .lyx file given by file
113         // the textclass
114         fprintf(file, "\\textclass %s\n",
115                 textclasslist.NameOfClass(textclass).c_str());
116         
117         // then the the preamble
118         if (!preamble.empty()) {
119                 fprintf(file, "\\begin_preamble\n");
120                 {
121                         // remove '\n' from the end of preamble
122                         preamble = strip(preamble, '\n');
123                         
124                         // write out the whole preamble  in one go
125                         fwrite(preamble.c_str(),
126                                sizeof(char),
127                                preamble.length(),
128                                file);
129                         fprintf(file, "\n\\end_preamble\n");
130                 }
131         }
132       
133         /* the options */ 
134         if (!options.empty()) {
135                 fprintf(file,
136                         "\\options %s\n",
137                         options.c_str());
138         }
139    
140         /* then the text parameters */ 
141         fprintf(file, "\\language %s\n", language.c_str());
142         fprintf(file, "\\inputencoding %s\n", inputenc.c_str());
143         fprintf(file, "\\fontscheme %s\n", fonts.c_str());
144         fprintf(file, "\\graphics %s\n", graphicsDriver.c_str());
146         if (!float_placement.empty()) {
147                 fprintf(file,
148                         "\\float_placement %s\n",
149                         float_placement.c_str());
150         }
151         fprintf(file, "\\paperfontsize %s\n", fontsize.c_str());
153         spacing.writeFile(file);
155         fprintf(file, "\\papersize %s\n", string_papersize[papersize2]);
156         fprintf(file, "\\paperpackage %s\n",
157                 string_paperpackages[paperpackage]);
158         fprintf(file, "\\use_geometry %d\n",use_geometry);
159         fprintf(file, "\\use_amsmath %d\n",use_amsmath);
160         fprintf(file, "\\paperorientation %s\n",
161                 string_orientation[orientation]);
162         if (!paperwidth.empty())
163             fprintf(file, "\\paperwidth %s\n",
164                     VSpace(paperwidth).asLyXCommand().c_str());
165         if (!paperheight.empty())
166             fprintf(file, "\\paperheight %s\n",
167                     VSpace(paperheight).asLyXCommand().c_str());
168         if (!leftmargin.empty())
169             fprintf(file, "\\leftmargin %s\n",
170                     VSpace(leftmargin).asLyXCommand().c_str());
171         if (!topmargin.empty())
172             fprintf(file, "\\topmargin %s\n",
173                     VSpace(topmargin).asLyXCommand().c_str());
174         if (!rightmargin.empty())
175             fprintf(file, "\\rightmargin %s\n",
176                     VSpace(rightmargin).asLyXCommand().c_str());
177         if (!bottommargin.empty())
178             fprintf(file, "\\bottommargin %s\n",
179                     VSpace(bottommargin).asLyXCommand().c_str());
180         if (!headheight.empty())
181             fprintf(file, "\\headheight %s\n",
182                     VSpace(headheight).asLyXCommand().c_str());
183         if (!headsep.empty())
184             fprintf(file, "\\headsep %s\n",
185                     VSpace(headsep).asLyXCommand().c_str());
186         if (!footskip.empty())
187             fprintf(file, "\\footskip %s\n",
188                     VSpace(footskip).asLyXCommand().c_str());
189         fprintf(file, "\\secnumdepth %d\n", secnumdepth);
190         fprintf(file, "\\tocdepth %d\n", tocdepth);
191         fprintf(file, "\\paragraph_separation %s\n",
192                 string_paragraph_separation[paragraph_separation]);
193         fprintf(file, "\\defskip %s\n", defskip.asLyXCommand().c_str());
194         fprintf(file, "\\quotes_language %s\n",
195                 string_quotes_language[quotes_language]);
196         switch(quotes_times) {
197         case InsetQuotes::SingleQ: 
198                 fprintf(file, "\\quotes_times 1\n"); break;
199         case InsetQuotes::DoubleQ: 
200                 fprintf(file, "\\quotes_times 2\n"); break;
201         }               
202         fprintf(file, "\\papercolumns %d\n", columns);
203         fprintf(file, "\\papersides %d\n", sides);
204         fprintf(file, "\\paperpagestyle %s\n", pagestyle.c_str());
205         for (int i = 0; i < 4; ++i) {
206                 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
207                         if (user_defined_bullets[i].getFont() != -1) {
208                                 fprintf(file, "\\bullet %d\n\t%d\n\t%d\n\t%d\n\\end_bullet\n",
209                                                 i,
210                                                 user_defined_bullets[i].getFont(),
211                                                 user_defined_bullets[i].getCharacter(),
212                                                 user_defined_bullets[i].getSize());
213                         }
214                         else {
215                                 fprintf(file, "\\bulletLaTeX %d\n\t%s\n\\end_bullet\n",
216                                                 i,
217                                                 user_defined_bullets[i].c_str());
218                         }
219                 }
220         }
224 void BufferParams::useClassDefaults() {
225         LyXTextClass const & tclass = textclasslist.TextClass(textclass);
227         sides = tclass.sides();
228         columns = tclass.columns();
229         pagestyle = tclass.pagestyle();
230         options = tclass.options();
231         secnumdepth = tclass.secnumdepth();
232         tocdepth = tclass.tocdepth();
236 void BufferParams::readPreamble(LyXLex &lex)
238         if (lex.GetString() != "\\begin_preamble")
239                 lyxerr << "Error (BufferParams::readPreamble):"
240                         "consistency check failed." << endl;
242         preamble = lex.getLongString("\\end_preamble");
246 void BufferParams::readLanguage(LyXLex &lex)
248         string tmptok;
249         string test;
250         int n = 0;
251         
252         if (!lex.next()) return;
253         
254         tmptok = lex.GetString();
255         // check if tmptok is part of tex_babel in tex-defs.h
256         while (true) {
257                 test = tex_babel[n++];
258                 
259                 if (test == tmptok) {
260                         language = tmptok;
261                         break;
262                 }
263                 else if (test.empty()) {
264                         lyxerr << "Warning: language `"
265                                << tmptok << "' not recognized!\n"
266                                << "         Setting language to `default'."
267                                << endl;
268                         language = "default";
269                         break;   
270                 }      
271         }
275 void BufferParams::readGraphicsDriver(LyXLex &lex)
277         string tmptok;
278         string test;
279         int n=0;
280         
281         
282         if (!lex.next()) return;
283         
284         tmptok = lex.GetString();
285         // check if tmptok is part of tex_graphics in tex_defs.h
286         while (true) {
287                 test = tex_graphics[n++];
288                 
289                 if (test == tmptok) {    
290                         graphicsDriver = tmptok;
291                         break;
292                 }      
293                 else if (test == "last_item") {
294                         lex.printError(
295                                 "Warning: graphics driver `$$Token' not recognized!\n"
296                                 "         Setting graphics driver to `default'.\n");
297                         graphicsDriver = "default";
298                         break;
299                 }      
300         }