1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 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"
31 BufferParams::BufferParams()
33 paragraph_separation = PARSEP_INDENT;
34 defskip = VSpace(VSpace::MEDSKIP);
35 quotes_language = InsetQuotes::EnglishQ;
36 quotes_times = InsetQuotes::DoubleQ;
38 // Initialize textclass to point to article. if `first' is
39 // true in the returned pair, then `second' is the textclass
40 // number; if it is false, second is 0. In both cases, second
42 textclass = textclasslist.NumberOfClass("article").second;
45 papersize = PAPER_DEFAULT;
46 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
47 paperpackage = PACKAGE_NONE;
48 orientation = ORIENTATION_PORTRAIT;
52 use_numerical_citations = false;
55 language = default_language;
58 graphicsDriver = "default";
59 sides = LyXTextClass::OneSide;
61 pagestyle = "default";
62 for (int iter = 0; iter < 4; ++iter) {
63 user_defined_bullets[iter] = temp_bullets[iter]
64 = ITEMIZE_DEFAULTS[iter];
69 void BufferParams::writeFile(ostream & os) const
71 // The top of the file is written by the buffer.
72 // Prints out the buffer info into the .lyx file given by file
75 os << "\\textclass " << textclasslist.NameOfClass(textclass) << '\n';
77 // then the the preamble
78 if (!preamble.empty()) {
79 // remove '\n' from the end of preamble
80 string const tmppreamble = strip(preamble, '\n');
81 os << "\\begin_preamble\n"
83 << "\n\\end_preamble\n";
87 if (!options.empty()) {
88 os << "\\options " << options << '\n';
91 /* then the text parameters */
92 if (language != ignore_language)
93 os << "\\language " << language->lang() << '\n';
94 os << "\\inputencoding " << inputenc
95 << "\n\\fontscheme " << fonts
96 << "\n\\graphics " << graphicsDriver << '\n';
98 if (!float_placement.empty()) {
99 os << "\\float_placement " << float_placement << '\n';
101 os << "\\paperfontsize " << fontsize << '\n';
103 spacing.writeFile(os);
105 os << "\\papersize " << string_papersize[papersize2]
106 << "\n\\paperpackage " << string_paperpackages[paperpackage]
107 << "\n\\use_geometry " << use_geometry
108 << "\n\\use_amsmath " << use_amsmath
109 << "\n\\use_natbib " << use_natbib
110 << "\n\\use_numerical_citations " << use_numerical_citations
111 << "\n\\paperorientation " << string_orientation[orientation]
113 if (!paperwidth.empty())
114 os << "\\paperwidth "
115 << VSpace(paperwidth).asLyXCommand() << '\n';
116 if (!paperheight.empty())
117 os << "\\paperheight "
118 << VSpace(paperheight).asLyXCommand() << '\n';
119 if (!leftmargin.empty())
120 os << "\\leftmargin "
121 << VSpace(leftmargin).asLyXCommand() << '\n';
122 if (!topmargin.empty())
124 << VSpace(topmargin).asLyXCommand() << '\n';
125 if (!rightmargin.empty())
126 os << "\\rightmargin "
127 << VSpace(rightmargin).asLyXCommand() << '\n';
128 if (!bottommargin.empty())
129 os << "\\bottommargin "
130 << VSpace(bottommargin).asLyXCommand() << '\n';
131 if (!headheight.empty())
132 os << "\\headheight "
133 << VSpace(headheight).asLyXCommand() << '\n';
134 if (!headsep.empty())
136 << VSpace(headsep).asLyXCommand() << '\n';
137 if (!footskip.empty())
139 << VSpace(footskip).asLyXCommand() << '\n';
140 os << "\\secnumdepth " << secnumdepth
141 << "\n\\tocdepth " << tocdepth
142 << "\n\\paragraph_separation "
143 << string_paragraph_separation[paragraph_separation]
144 << "\n\\defskip " << defskip.asLyXCommand()
145 << "\n\\quotes_language "
146 << string_quotes_language[quotes_language] << '\n';
147 switch (quotes_times) {
148 // An output operator for insetquotes would be nice
149 case InsetQuotes::SingleQ:
150 os << "\\quotes_times 1\n"; break;
151 case InsetQuotes::DoubleQ:
152 os << "\\quotes_times 2\n"; break;
154 os << "\\papercolumns " << columns
155 << "\n\\papersides " << sides
156 << "\n\\paperpagestyle " << pagestyle << '\n';
157 for (int i = 0; i < 4; ++i) {
158 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
159 if (user_defined_bullets[i].getFont() != -1) {
160 os << "\\bullet " << i
162 << user_defined_bullets[i].getFont()
164 << user_defined_bullets[i].getCharacter()
166 << user_defined_bullets[i].getSize()
167 << "\n\\end_bullet\n";
170 os << "\\bulletLaTeX " << i
172 << user_defined_bullets[i].getText()
173 << "\n\\end_bullet\n";
180 void BufferParams::setPaperStuff()
182 papersize = PAPER_DEFAULT;
183 char const c1 = paperpackage;
184 if (c1 == PACKAGE_NONE) {
185 char const c2 = papersize2;
186 if (c2 == VM_PAPER_USLETTER)
187 papersize = PAPER_USLETTER;
188 else if (c2 == VM_PAPER_USLEGAL)
189 papersize = PAPER_LEGALPAPER;
190 else if (c2 == VM_PAPER_USEXECUTIVE)
191 papersize = PAPER_EXECUTIVEPAPER;
192 else if (c2 == VM_PAPER_A3)
193 papersize = PAPER_A3PAPER;
194 else if (c2 == VM_PAPER_A4)
195 papersize = PAPER_A4PAPER;
196 else if (c2 == VM_PAPER_A5)
197 papersize = PAPER_A5PAPER;
198 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
200 papersize = PAPER_B5PAPER;
201 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
202 (c1 == PACKAGE_WIDEMARGINSA4))
203 papersize = PAPER_A4PAPER;
207 void BufferParams::useClassDefaults()
209 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
211 sides = tclass.sides();
212 columns = tclass.columns();
213 pagestyle = tclass.pagestyle();
214 options = tclass.options();
215 secnumdepth = tclass.secnumdepth();
216 tocdepth = tclass.tocdepth();
220 bool BufferParams::hasClassDefaults() const
222 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
224 return (sides == tclass.sides()
225 && columns == tclass.columns()
226 && pagestyle == tclass.pagestyle()
227 && options == tclass.options()
228 && secnumdepth == tclass.secnumdepth()
229 && tocdepth == tclass.tocdepth());
233 void BufferParams::readPreamble(LyXLex & lex)
235 if (lex.getString() != "\\begin_preamble")
236 lyxerr << "Error (BufferParams::readPreamble):"
237 "consistency check failed." << endl;
239 preamble = lex.getLongString("\\end_preamble");
243 void BufferParams::readLanguage(LyXLex & lex)
245 if (!lex.next()) return;
247 string const tmptok = lex.getString();
249 // check if tmptok is part of tex_babel in tex-defs.h
250 language = languages.getLanguage(tmptok);
252 // Language tmptok was not found
253 language = default_language;
254 lyxerr << "Warning: Setting language `"
255 << tmptok << "' to `" << language->lang()
261 void BufferParams::readGraphicsDriver(LyXLex & lex)
263 if (!lex.next()) return;
265 string const tmptok = lex.getString();
266 // check if tmptok is part of tex_graphics in tex_defs.h
269 string const test = tex_graphics[n++];
271 if (test == tmptok) {
272 graphicsDriver = tmptok;
274 } else if (test == "last_item") {
276 "Warning: graphics driver `$$Token' not recognized!\n"
277 " Setting graphics driver to `default'.\n");
278 graphicsDriver = "default";