1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ======================================================*/
15 #pragma implementation "bufferparams.h"
18 #include "bufferparams.h"
19 #include "tex-strings.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;
35 papersize = PAPER_DEFAULT;
36 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
37 paperpackage = PACKAGE_NONE;
38 orientation = ORIENTATION_PORTRAIT;
46 graphicsDriver = "default";
49 pagestyle = "default";
50 for(int iter = 0; iter < 4; iter++) {
51 user_defined_bullets[iter] = temp_bullets[iter]
52 = ITEMIZE_DEFAULTS[iter];
58 void BufferParams::Copy(BufferParams const &p)
60 paragraph_separation = p.paragraph_separation;
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;
79 footskip = p.footskip;
80 graphicsDriver = p.graphicsDriver;
83 secnumdepth = p.secnumdepth;
84 tocdepth = p.tocdepth;
85 language = p.language;
86 inputenc = p.inputenc;
87 preamble = p.preamble;
89 float_placement = p.float_placement;
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];
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
114 fprintf(file, "\\textclass %s\n",
115 lyxstyle.NameOfClass(textclass).c_str());
117 // then the the preamble
118 if (!preamble.empty()) {
119 fprintf(file, "\\begin_preamble\n");
121 // remove '\n' from the end of preamble
122 preamble = strip(preamble, '\n');
124 // write out the whole preamble in one go
125 fwrite(preamble.c_str(),
129 fprintf(file, "\n\\end_preamble\n");
134 if (!options.empty()) {
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()) {
148 "\\float_placement %s\n",
149 float_placement.c_str());
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;
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",
210 user_defined_bullets[i].getFont(),
211 user_defined_bullets[i].getCharacter(),
212 user_defined_bullets[i].getSize());
215 fprintf(file, "\\bulletLaTeX %d\n\t%s\n\\end_bullet\n",
217 user_defined_bullets[i].c_str());
224 void BufferParams::useClassDefaults() {
225 LyXTextClass *tclass = lyxstyle.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)
252 if (!lex.next()) return;
254 tmptok = lex.GetString();
255 // check if tmptok is part of tex_babel in tex-defs.h
257 test = tex_babel[n++];
259 if (test == tmptok) {
263 else if (test.empty()) {
264 lyxerr << "Warning: language `"
265 << tmptok << "' not recognized!\n"
266 << " Setting language to `default'."
268 language = "default";
275 void BufferParams::readGraphicsDriver(LyXLex &lex)
282 if (!lex.next()) return;
284 tmptok = lex.GetString();
285 // check if tmptok is part of tex_graphics in tex_defs.h
287 test = tex_graphics[n++];
289 if (test == tmptok) {
290 graphicsDriver = tmptok;
293 else if (test == "last_item") {
295 "Warning: graphics driver `$$Token' not recognized!\n"
296 " Setting graphics driver to `default'.\n");
297 graphicsDriver = "default";