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 * ====================================================== */
14 #pragma implementation
17 #include "bufferparams.h"
18 #include "tex-strings.h"
24 #include "lyxtextclasslist.h"
26 #include "support/lyxlib.h"
27 #include "support/lstrings.h"
34 BufferParams::BufferParams()
35 // Initialize textclass to point to article. if `first' is
36 // true in the returned pair, then `second' is the textclass
37 // number; if it is false, second is 0. In both cases, second
39 : textclass(textclasslist.NumberOfClass("article").second)
41 paragraph_separation = PARSEP_INDENT;
42 defskip = VSpace(VSpace::MEDSKIP);
43 quotes_language = InsetQuotes::EnglishQ;
44 quotes_times = InsetQuotes::DoubleQ;
48 papersize = PAPER_DEFAULT;
49 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
50 paperpackage = PACKAGE_NONE;
51 orientation = ORIENTATION_PORTRAIT;
55 use_numerical_citations = false;
58 language = default_language;
61 graphicsDriver = "default";
62 sides = LyXTextClass::OneSide;
64 pagestyle = "default";
65 for (int iter = 0; iter < 4; ++iter) {
66 user_defined_bullets[iter] = ITEMIZE_DEFAULTS[iter];
67 temp_bullets[iter] = ITEMIZE_DEFAULTS[iter];
72 void BufferParams::writeFile(ostream & os) const
74 // The top of the file is written by the buffer.
75 // Prints out the buffer info into the .lyx file given by file
78 os << "\\textclass " << textclasslist[textclass].name() << '\n';
80 // then the the preamble
81 if (!preamble.empty()) {
82 // remove '\n' from the end of preamble
83 string const tmppreamble = strip(preamble, '\n');
84 os << "\\begin_preamble\n"
86 << "\n\\end_preamble\n";
90 if (!options.empty()) {
91 os << "\\options " << options << '\n';
94 /* then the text parameters */
95 if (language != ignore_language)
96 os << "\\language " << language->lang() << '\n';
97 os << "\\inputencoding " << inputenc
98 << "\n\\fontscheme " << fonts
99 << "\n\\graphics " << graphicsDriver << '\n';
101 if (!float_placement.empty()) {
102 os << "\\float_placement " << float_placement << '\n';
104 os << "\\paperfontsize " << fontsize << '\n';
106 spacing.writeFile(os);
108 os << "\\papersize " << string_papersize[papersize2]
109 << "\n\\paperpackage " << string_paperpackages[paperpackage]
110 << "\n\\use_geometry " << use_geometry
111 << "\n\\use_amsmath " << use_amsmath
112 << "\n\\use_natbib " << use_natbib
113 << "\n\\use_numerical_citations " << use_numerical_citations
114 << "\n\\paperorientation " << string_orientation[orientation]
116 if (!paperwidth.empty())
117 os << "\\paperwidth "
118 << VSpace(paperwidth).asLyXCommand() << '\n';
119 if (!paperheight.empty())
120 os << "\\paperheight "
121 << VSpace(paperheight).asLyXCommand() << '\n';
122 if (!leftmargin.empty())
123 os << "\\leftmargin "
124 << VSpace(leftmargin).asLyXCommand() << '\n';
125 if (!topmargin.empty())
127 << VSpace(topmargin).asLyXCommand() << '\n';
128 if (!rightmargin.empty())
129 os << "\\rightmargin "
130 << VSpace(rightmargin).asLyXCommand() << '\n';
131 if (!bottommargin.empty())
132 os << "\\bottommargin "
133 << VSpace(bottommargin).asLyXCommand() << '\n';
134 if (!headheight.empty())
135 os << "\\headheight "
136 << VSpace(headheight).asLyXCommand() << '\n';
137 if (!headsep.empty())
139 << VSpace(headsep).asLyXCommand() << '\n';
140 if (!footskip.empty())
142 << VSpace(footskip).asLyXCommand() << '\n';
143 os << "\\secnumdepth " << secnumdepth
144 << "\n\\tocdepth " << tocdepth
145 << "\n\\paragraph_separation "
146 << string_paragraph_separation[paragraph_separation]
147 << "\n\\defskip " << defskip.asLyXCommand()
148 << "\n\\quotes_language "
149 << string_quotes_language[quotes_language] << '\n';
150 switch (quotes_times) {
151 // An output operator for insetquotes would be nice
152 case InsetQuotes::SingleQ:
153 os << "\\quotes_times 1\n"; break;
154 case InsetQuotes::DoubleQ:
155 os << "\\quotes_times 2\n"; break;
157 os << "\\papercolumns " << columns
158 << "\n\\papersides " << sides
159 << "\n\\paperpagestyle " << pagestyle << '\n';
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 os << "\\bullet " << i
165 << user_defined_bullets[i].getFont()
167 << user_defined_bullets[i].getCharacter()
169 << user_defined_bullets[i].getSize()
170 << "\n\\end_bullet\n";
173 os << "\\bulletLaTeX " << i
175 << user_defined_bullets[i].getText()
176 << "\"\n\\end_bullet\n";
183 void BufferParams::setPaperStuff()
185 papersize = PAPER_DEFAULT;
186 char const c1 = paperpackage;
187 if (c1 == PACKAGE_NONE) {
188 char const c2 = papersize2;
189 if (c2 == VM_PAPER_USLETTER)
190 papersize = PAPER_USLETTER;
191 else if (c2 == VM_PAPER_USLEGAL)
192 papersize = PAPER_LEGALPAPER;
193 else if (c2 == VM_PAPER_USEXECUTIVE)
194 papersize = PAPER_EXECUTIVEPAPER;
195 else if (c2 == VM_PAPER_A3)
196 papersize = PAPER_A3PAPER;
197 else if (c2 == VM_PAPER_A4)
198 papersize = PAPER_A4PAPER;
199 else if (c2 == VM_PAPER_A5)
200 papersize = PAPER_A5PAPER;
201 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
203 papersize = PAPER_B5PAPER;
204 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
205 (c1 == PACKAGE_WIDEMARGINSA4))
206 papersize = PAPER_A4PAPER;
210 void BufferParams::useClassDefaults()
212 LyXTextClass const & tclass = textclasslist[textclass];
214 sides = tclass.sides();
215 columns = tclass.columns();
216 pagestyle = tclass.pagestyle();
217 options = tclass.options();
218 secnumdepth = tclass.secnumdepth();
219 tocdepth = tclass.tocdepth();
223 bool BufferParams::hasClassDefaults() const
225 LyXTextClass const & tclass = textclasslist[textclass];
227 return (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)
248 if (!lex.next()) return;
250 string const tmptok = lex.getString();
252 // check if tmptok is part of tex_babel in tex-defs.h
253 language = languages.getLanguage(tmptok);
255 // Language tmptok was not found
256 language = default_language;
257 lyxerr << "Warning: Setting language `"
258 << tmptok << "' to `" << language->lang()
264 void BufferParams::readGraphicsDriver(LyXLex & lex)
266 if (!lex.next()) return;
268 string const tmptok = lex.getString();
269 // check if tmptok is part of tex_graphics in tex_defs.h
272 string const test = tex_graphics[n++];
274 if (test == tmptok) {
275 graphicsDriver = tmptok;
277 } else if (test == "last_item") {
279 "Warning: graphics driver `$$Token' not recognized!\n"
280 " Setting graphics driver to `default'.\n");
281 graphicsDriver = "default";