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;
35 papersize = PAPER_DEFAULT;
36 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
37 paperpackage = PACKAGE_NONE;
38 orientation = ORIENTATION_PORTRAIT;
46 graphicsDriver = "default";
47 sides = LyXTextClass::OneSide;
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::writeFile(FILE * file)
60 // The top of the file is written by the buffer.
61 // Prints out the buffer info into the .lyx file given by file
64 fprintf(file, "\\textclass %s\n",
65 textclasslist.NameOfClass(textclass).c_str());
67 // then the the preamble
68 if (!preamble.empty()) {
69 fprintf(file, "\\begin_preamble\n");
71 // remove '\n' from the end of preamble
72 preamble = strip(preamble, '\n');
74 // write out the whole preamble in one go
75 fwrite(preamble.c_str(),
79 fprintf(file, "\n\\end_preamble\n");
84 if (!options.empty()) {
90 /* then the text parameters */
91 fprintf(file, "\\language %s\n", language.c_str());
92 fprintf(file, "\\inputencoding %s\n", inputenc.c_str());
93 fprintf(file, "\\fontscheme %s\n", fonts.c_str());
94 fprintf(file, "\\graphics %s\n", graphicsDriver.c_str());
96 if (!float_placement.empty()) {
98 "\\float_placement %s\n",
99 float_placement.c_str());
101 fprintf(file, "\\paperfontsize %s\n", fontsize.c_str());
103 spacing.writeFile(file);
105 fprintf(file, "\\papersize %s\n", string_papersize[papersize2]);
106 fprintf(file, "\\paperpackage %s\n",
107 string_paperpackages[paperpackage]);
108 fprintf(file, "\\use_geometry %d\n", use_geometry);
109 fprintf(file, "\\use_amsmath %d\n", use_amsmath);
110 fprintf(file, "\\paperorientation %s\n",
111 string_orientation[orientation]);
112 if (!paperwidth.empty())
113 fprintf(file, "\\paperwidth %s\n",
114 VSpace(paperwidth).asLyXCommand().c_str());
115 if (!paperheight.empty())
116 fprintf(file, "\\paperheight %s\n",
117 VSpace(paperheight).asLyXCommand().c_str());
118 if (!leftmargin.empty())
119 fprintf(file, "\\leftmargin %s\n",
120 VSpace(leftmargin).asLyXCommand().c_str());
121 if (!topmargin.empty())
122 fprintf(file, "\\topmargin %s\n",
123 VSpace(topmargin).asLyXCommand().c_str());
124 if (!rightmargin.empty())
125 fprintf(file, "\\rightmargin %s\n",
126 VSpace(rightmargin).asLyXCommand().c_str());
127 if (!bottommargin.empty())
128 fprintf(file, "\\bottommargin %s\n",
129 VSpace(bottommargin).asLyXCommand().c_str());
130 if (!headheight.empty())
131 fprintf(file, "\\headheight %s\n",
132 VSpace(headheight).asLyXCommand().c_str());
133 if (!headsep.empty())
134 fprintf(file, "\\headsep %s\n",
135 VSpace(headsep).asLyXCommand().c_str());
136 if (!footskip.empty())
137 fprintf(file, "\\footskip %s\n",
138 VSpace(footskip).asLyXCommand().c_str());
139 fprintf(file, "\\secnumdepth %d\n", secnumdepth);
140 fprintf(file, "\\tocdepth %d\n", tocdepth);
141 fprintf(file, "\\paragraph_separation %s\n",
142 string_paragraph_separation[paragraph_separation]);
143 fprintf(file, "\\defskip %s\n", defskip.asLyXCommand().c_str());
144 fprintf(file, "\\quotes_language %s\n",
145 string_quotes_language[quotes_language]);
146 switch(quotes_times) {
147 case InsetQuotes::SingleQ:
148 fprintf(file, "\\quotes_times 1\n"); break;
149 case InsetQuotes::DoubleQ:
150 fprintf(file, "\\quotes_times 2\n"); break;
152 fprintf(file, "\\papercolumns %d\n", columns);
153 fprintf(file, "\\papersides %d\n", sides);
154 fprintf(file, "\\paperpagestyle %s\n", pagestyle.c_str());
155 for (int i = 0; i < 4; ++i) {
156 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
157 if (user_defined_bullets[i].getFont() != -1) {
158 fprintf(file, "\\bullet %d\n\t%d\n\t%d\n\t%d\n\\end_bullet\n",
160 user_defined_bullets[i].getFont(),
161 user_defined_bullets[i].getCharacter(),
162 user_defined_bullets[i].getSize());
165 fprintf(file, "\\bulletLaTeX %d\n\t%s\n\\end_bullet\n",
167 user_defined_bullets[i].c_str());
174 void BufferParams::useClassDefaults() {
175 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
177 sides = tclass.sides();
178 columns = tclass.columns();
179 pagestyle = tclass.pagestyle();
180 options = tclass.options();
181 secnumdepth = tclass.secnumdepth();
182 tocdepth = tclass.tocdepth();
186 void BufferParams::readPreamble(LyXLex & lex)
188 if (lex.GetString() != "\\begin_preamble")
189 lyxerr << "Error (BufferParams::readPreamble):"
190 "consistency check failed." << endl;
192 preamble = lex.getLongString("\\end_preamble");
196 void BufferParams::readLanguage(LyXLex & lex)
202 if (!lex.next()) return;
204 tmptok = lex.GetString();
205 // check if tmptok is part of tex_babel in tex-defs.h
207 test = tex_babel[n++];
209 if (test == tmptok) {
213 else if (test.empty()) {
214 lyxerr << "Warning: language `"
215 << tmptok << "' not recognized!\n"
216 << " Setting language to `default'."
218 language = "default";
225 void BufferParams::readGraphicsDriver(LyXLex & lex)
232 if (!lex.next()) return;
234 tmptok = lex.GetString();
235 // check if tmptok is part of tex_graphics in tex_defs.h
237 test = tex_graphics[n++];
239 if (test == tmptok) {
240 graphicsDriver = tmptok;
243 else if (test == "last_item") {
245 "Warning: graphics driver `$$Token' not recognized!\n"
246 " Setting graphics driver to `default'.\n");
247 graphicsDriver = "default";