1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
7 * Copyright (C) 1995-1998 The LyX Team.
9 *======================================================*/
15 #pragma implementation "bufferparams.h"
18 #include "bufferparams.h"
19 #include "tex-strings.h"
25 // $Id: bufferparams.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $
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 $";
32 BufferParams::BufferParams()
34 paragraph_separation = LYX_PARSEP_INDENT;
35 defskip = VSpace(VSpace::MEDSKIP);
36 quotes_language = InsetQuotes::EnglishQ;
37 quotes_times = InsetQuotes::DoubleQ;
41 papersize = PAPER_DEFAULT;
42 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
43 paperpackage = PACKAGE_NONE;
44 orientation = ORIENTATION_PORTRAIT;
52 graphicsDriver = "default";
55 pagestyle = "default";
56 for(int iter = 0; iter < 4; iter++) {
57 user_defined_bullets[iter] = temp_bullets[iter]
58 = ITEMIZE_DEFAULTS[iter];
64 void BufferParams::Copy(BufferParams const &p)
66 paragraph_separation = p.paragraph_separation;
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;
85 footskip = p.footskip;
86 graphicsDriver = p.graphicsDriver;
89 secnumdepth = p.secnumdepth;
90 tocdepth = p.tocdepth;
91 language = p.language;
92 inputenc = p.inputenc;
93 preamble = p.preamble;
95 float_placement = p.float_placement;
98 pagestyle = p.pagestyle;
100 // WARNING destructor will deallocate paragraph!!
101 // this is not good and will cause an error somewhere else.
102 //paragraph = p.paragraph;
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];
109 allowAccents=p.allowAccents;
110 use_amsmath = p.use_amsmath;
114 void BufferParams::writeFile(FILE *file)
116 // The top of the file is written by the buffer.
117 // Prints out the buffer info into the .lyx file given by file
120 fprintf(file, "\\textclass %s\n",
121 lyxstyle.NameOfClass(textclass).c_str());
123 // then the the preamble
124 if (!preamble.empty()) {
125 fprintf(file, "\\begin_preamble\n");
127 // remove '\n' from the end of preamble
128 preamble.strip('\n');
130 // write out the whole preamble in one go
131 fwrite(preamble.c_str(),
135 fprintf(file, "\n\\end_preamble\n");
140 if (!options.empty()) {
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());
152 if (!float_placement.empty()) {
154 "\\float_placement %s\n",
155 float_placement.c_str());
157 fprintf(file, "\\paperfontsize %s\n", fontsize.c_str());
159 spacing.writeFile(file);
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;
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",
216 user_defined_bullets[i].getFont(),
217 user_defined_bullets[i].getCharacter(),
218 user_defined_bullets[i].getSize());
221 fprintf(file, "\\bulletLaTeX %d\n\t%s\n\\end_bullet\n",
223 user_defined_bullets[i].c_str());
230 void BufferParams::useClassDefaults() {
231 LyXTextClass *tclass = lyxstyle.TextClass(textclass);
233 sides = tclass->sides;
234 columns = tclass->columns;
235 pagestyle = tclass->pagestyle;
236 options = tclass->options;
237 secnumdepth = tclass->secnumdepth;
238 tocdepth = tclass->tocdepth;
242 void BufferParams::readPreamble(LyXLex &lex)
244 if (lex.GetString() != "\\begin_preamble")
245 lyxerr.print("Error (BufferParams::readPreamble):"
246 "consistency check failed.");
248 preamble = lex.getLongString("\\end_preamble");
252 void BufferParams::readLanguage(LyXLex &lex)
258 if (!lex.next()) return;
260 tmptok = lex.GetString();
261 // check if tmptok is part of tex_babel in tex-defs.h
263 test = tex_babel[n++];
265 if (test == tmptok) {
269 else if (test.empty()) {
270 lyxerr.print("Warning: language `"
271 + tmptok + "' not recognized!");
272 lyxerr.print(" Setting language to `default'.");
273 language = "default";
280 void BufferParams::readGraphicsDriver(LyXLex &lex)
287 if (!lex.next()) return;
289 tmptok = lex.GetString();
290 // check if tmptok is part of tex_graphics in tex_defs.h
292 test = tex_graphics[n++];
294 if (test == tmptok) {
295 graphicsDriver = tmptok;
298 else if (test == "last_item") {
300 "Warning: graphics driver `$$Token' not recognized!\n"
301 " Setting graphics driver to `default'.\n");
302 graphicsDriver = "default";