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 = PARSEP_INDENT;
29 defskip = VSpace(VSpace::MEDSKIP);
30 quotes_language = InsetQuotes::EnglishQ;
31 quotes_times = InsetQuotes::DoubleQ;
33 // Initialize textclass to point to article. if `first' is
34 // true in the returned pair, then `second' is the textclass
35 // number; if it is false, second is 0. In both cases, second
37 textclass = textclasslist.NumberOfClass("article").second;
40 papersize = PAPER_DEFAULT;
41 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
42 paperpackage = PACKAGE_NONE;
43 orientation = ORIENTATION_PORTRAIT;
51 graphicsDriver = "default";
52 sides = LyXTextClass::OneSide;
54 pagestyle = "default";
55 for(int iter = 0; iter < 4; iter++) {
56 user_defined_bullets[iter] = temp_bullets[iter]
57 = ITEMIZE_DEFAULTS[iter];
63 void BufferParams::writeFile(FILE * file)
65 // The top of the file is written by the buffer.
66 // Prints out the buffer info into the .lyx file given by file
69 fprintf(file, "\\textclass %s\n",
70 textclasslist.NameOfClass(textclass).c_str());
72 // then the the preamble
73 if (!preamble.empty()) {
74 fprintf(file, "\\begin_preamble\n");
76 // remove '\n' from the end of preamble
77 preamble = strip(preamble, '\n');
79 // write out the whole preamble in one go
80 fwrite(preamble.c_str(),
84 fprintf(file, "\n\\end_preamble\n");
89 if (!options.empty()) {
95 /* then the text parameters */
96 fprintf(file, "\\language %s\n", language.c_str());
97 fprintf(file, "\\inputencoding %s\n", inputenc.c_str());
98 fprintf(file, "\\fontscheme %s\n", fonts.c_str());
99 fprintf(file, "\\graphics %s\n", graphicsDriver.c_str());
101 if (!float_placement.empty()) {
103 "\\float_placement %s\n",
104 float_placement.c_str());
106 fprintf(file, "\\paperfontsize %s\n", fontsize.c_str());
108 spacing.writeFile(file);
110 fprintf(file, "\\papersize %s\n", string_papersize[papersize2]);
111 fprintf(file, "\\paperpackage %s\n",
112 string_paperpackages[paperpackage]);
113 fprintf(file, "\\use_geometry %d\n", use_geometry);
114 fprintf(file, "\\use_amsmath %d\n", use_amsmath);
115 fprintf(file, "\\paperorientation %s\n",
116 string_orientation[orientation]);
117 if (!paperwidth.empty())
118 fprintf(file, "\\paperwidth %s\n",
119 VSpace(paperwidth).asLyXCommand().c_str());
120 if (!paperheight.empty())
121 fprintf(file, "\\paperheight %s\n",
122 VSpace(paperheight).asLyXCommand().c_str());
123 if (!leftmargin.empty())
124 fprintf(file, "\\leftmargin %s\n",
125 VSpace(leftmargin).asLyXCommand().c_str());
126 if (!topmargin.empty())
127 fprintf(file, "\\topmargin %s\n",
128 VSpace(topmargin).asLyXCommand().c_str());
129 if (!rightmargin.empty())
130 fprintf(file, "\\rightmargin %s\n",
131 VSpace(rightmargin).asLyXCommand().c_str());
132 if (!bottommargin.empty())
133 fprintf(file, "\\bottommargin %s\n",
134 VSpace(bottommargin).asLyXCommand().c_str());
135 if (!headheight.empty())
136 fprintf(file, "\\headheight %s\n",
137 VSpace(headheight).asLyXCommand().c_str());
138 if (!headsep.empty())
139 fprintf(file, "\\headsep %s\n",
140 VSpace(headsep).asLyXCommand().c_str());
141 if (!footskip.empty())
142 fprintf(file, "\\footskip %s\n",
143 VSpace(footskip).asLyXCommand().c_str());
144 fprintf(file, "\\secnumdepth %d\n", secnumdepth);
145 fprintf(file, "\\tocdepth %d\n", tocdepth);
146 fprintf(file, "\\paragraph_separation %s\n",
147 string_paragraph_separation[paragraph_separation]);
148 fprintf(file, "\\defskip %s\n", defskip.asLyXCommand().c_str());
149 fprintf(file, "\\quotes_language %s\n",
150 string_quotes_language[quotes_language]);
151 switch(quotes_times) {
152 case InsetQuotes::SingleQ:
153 fprintf(file, "\\quotes_times 1\n"); break;
154 case InsetQuotes::DoubleQ:
155 fprintf(file, "\\quotes_times 2\n"); break;
157 fprintf(file, "\\papercolumns %d\n", columns);
158 fprintf(file, "\\papersides %d\n", sides);
159 fprintf(file, "\\paperpagestyle %s\n", pagestyle.c_str());
160 for (int i = 0; i < 4; ++i) {
161 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
162 if (user_defined_bullets[i].getFont() != -1) {
163 fprintf(file, "\\bullet %d\n\t%d\n\t%d\n\t%d\n\\end_bullet\n",
165 user_defined_bullets[i].getFont(),
166 user_defined_bullets[i].getCharacter(),
167 user_defined_bullets[i].getSize());
170 fprintf(file, "\\bulletLaTeX %d\n\t%s\n\\end_bullet\n",
172 user_defined_bullets[i].c_str());
179 void BufferParams::useClassDefaults() {
180 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
182 sides = tclass.sides();
183 columns = tclass.columns();
184 pagestyle = tclass.pagestyle();
185 options = tclass.options();
186 secnumdepth = tclass.secnumdepth();
187 tocdepth = tclass.tocdepth();
191 void BufferParams::readPreamble(LyXLex & lex)
193 if (lex.GetString() != "\\begin_preamble")
194 lyxerr << "Error (BufferParams::readPreamble):"
195 "consistency check failed." << endl;
197 preamble = lex.getLongString("\\end_preamble");
201 void BufferParams::readLanguage(LyXLex & lex)
203 if (!lex.next()) return;
205 string tmptok = lex.GetString();
208 // check if tmptok is part of tex_babel in tex-defs.h
210 test = tex_babel[n++];
212 if (test == tmptok) {
216 else if (test.empty()) {
217 lyxerr << "Warning: language `"
218 << tmptok << "' not recognized!\n"
219 << " Setting language to `default'."
221 language = "default";
228 void BufferParams::readGraphicsDriver(LyXLex & lex)
235 if (!lex.next()) return;
237 tmptok = lex.GetString();
238 // check if tmptok is part of tex_graphics in tex_defs.h
240 test = tex_graphics[n++];
242 if (test == tmptok) {
243 graphicsDriver = tmptok;
246 else if (test == "last_item") {
248 "Warning: graphics driver `$$Token' not recognized!\n"
249 " Setting graphics driver to `default'.\n");
250 graphicsDriver = "default";