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"
27 #include "support/lyxlib.h"
28 #include "support/lstrings.h"
35 BufferParams::BufferParams()
36 // Initialize textclass to point to article. if `first' is
37 // true in the returned pair, then `second' is the textclass
38 // number; if it is false, second is 0. In both cases, second
40 : textclass(textclasslist.NumberOfClass("article").second)
42 paragraph_separation = PARSEP_INDENT;
43 defskip = VSpace(VSpace::MEDSKIP);
44 quotes_language = InsetQuotes::EnglishQ;
45 quotes_times = InsetQuotes::DoubleQ;
49 papersize = PAPER_DEFAULT;
50 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
51 paperpackage = PACKAGE_NONE;
52 orientation = ORIENTATION_PORTRAIT;
56 use_numerical_citations = false;
59 language = default_language;
62 graphicsDriver = "default";
63 sides = LyXTextClass::OneSide;
65 pagestyle = "default";
66 for (int iter = 0; iter < 4; ++iter) {
67 user_defined_bullets[iter] = ITEMIZE_DEFAULTS[iter];
68 temp_bullets[iter] = ITEMIZE_DEFAULTS[iter];
73 void BufferParams::writeFile(ostream & os) const
75 // The top of the file is written by the buffer.
76 // Prints out the buffer info into the .lyx file given by file
79 os << "\\textclass " << textclasslist[textclass].name() << '\n';
81 // then the the preamble
82 if (!preamble.empty()) {
83 // remove '\n' from the end of preamble
84 string const tmppreamble = strip(preamble, '\n');
85 os << "\\begin_preamble\n"
87 << "\n\\end_preamble\n";
91 if (!options.empty()) {
92 os << "\\options " << options << '\n';
95 /* then the text parameters */
96 if (language != ignore_language)
97 os << "\\language " << language->lang() << '\n';
98 os << "\\inputencoding " << inputenc
99 << "\n\\fontscheme " << fonts
100 << "\n\\graphics " << graphicsDriver << '\n';
102 if (!float_placement.empty()) {
103 os << "\\float_placement " << float_placement << '\n';
105 os << "\\paperfontsize " << fontsize << '\n';
107 spacing.writeFile(os);
109 os << "\\papersize " << string_papersize[papersize2]
110 << "\n\\paperpackage " << string_paperpackages[paperpackage]
111 << "\n\\use_geometry " << use_geometry
112 << "\n\\use_amsmath " << use_amsmath
113 << "\n\\use_natbib " << use_natbib
114 << "\n\\use_numerical_citations " << use_numerical_citations
115 << "\n\\paperorientation " << string_orientation[orientation]
117 if (!paperwidth.empty())
118 os << "\\paperwidth "
119 << VSpace(paperwidth).asLyXCommand() << '\n';
120 if (!paperheight.empty())
121 os << "\\paperheight "
122 << VSpace(paperheight).asLyXCommand() << '\n';
123 if (!leftmargin.empty())
124 os << "\\leftmargin "
125 << VSpace(leftmargin).asLyXCommand() << '\n';
126 if (!topmargin.empty())
128 << VSpace(topmargin).asLyXCommand() << '\n';
129 if (!rightmargin.empty())
130 os << "\\rightmargin "
131 << VSpace(rightmargin).asLyXCommand() << '\n';
132 if (!bottommargin.empty())
133 os << "\\bottommargin "
134 << VSpace(bottommargin).asLyXCommand() << '\n';
135 if (!headheight.empty())
136 os << "\\headheight "
137 << VSpace(headheight).asLyXCommand() << '\n';
138 if (!headsep.empty())
140 << VSpace(headsep).asLyXCommand() << '\n';
141 if (!footskip.empty())
143 << VSpace(footskip).asLyXCommand() << '\n';
144 os << "\\secnumdepth " << secnumdepth
145 << "\n\\tocdepth " << tocdepth
146 << "\n\\paragraph_separation "
147 << string_paragraph_separation[paragraph_separation]
148 << "\n\\defskip " << defskip.asLyXCommand()
149 << "\n\\quotes_language "
150 << string_quotes_language[quotes_language] << '\n';
151 switch (quotes_times) {
152 // An output operator for insetquotes would be nice
153 case InsetQuotes::SingleQ:
154 os << "\\quotes_times 1\n"; break;
155 case InsetQuotes::DoubleQ:
156 os << "\\quotes_times 2\n"; break;
158 os << "\\papercolumns " << columns
159 << "\n\\papersides " << sides
160 << "\n\\paperpagestyle " << pagestyle << '\n';
161 for (int i = 0; i < 4; ++i) {
162 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
163 if (user_defined_bullets[i].getFont() != -1) {
164 os << "\\bullet " << i
166 << user_defined_bullets[i].getFont()
168 << user_defined_bullets[i].getCharacter()
170 << user_defined_bullets[i].getSize()
171 << "\n\\end_bullet\n";
174 os << "\\bulletLaTeX " << i
176 << user_defined_bullets[i].getText()
177 << "\"\n\\end_bullet\n";
184 void BufferParams::setPaperStuff()
186 papersize = PAPER_DEFAULT;
187 char const c1 = paperpackage;
188 if (c1 == PACKAGE_NONE) {
189 char const c2 = papersize2;
190 if (c2 == VM_PAPER_USLETTER)
191 papersize = PAPER_USLETTER;
192 else if (c2 == VM_PAPER_USLEGAL)
193 papersize = PAPER_LEGALPAPER;
194 else if (c2 == VM_PAPER_USEXECUTIVE)
195 papersize = PAPER_EXECUTIVEPAPER;
196 else if (c2 == VM_PAPER_A3)
197 papersize = PAPER_A3PAPER;
198 else if (c2 == VM_PAPER_A4)
199 papersize = PAPER_A4PAPER;
200 else if (c2 == VM_PAPER_A5)
201 papersize = PAPER_A5PAPER;
202 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
204 papersize = PAPER_B5PAPER;
205 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
206 (c1 == PACKAGE_WIDEMARGINSA4))
207 papersize = PAPER_A4PAPER;
211 void BufferParams::useClassDefaults()
213 LyXTextClass const & tclass = textclasslist[textclass];
215 sides = tclass.sides();
216 columns = tclass.columns();
217 pagestyle = tclass.pagestyle();
218 options = tclass.options();
219 secnumdepth = tclass.secnumdepth();
220 tocdepth = tclass.tocdepth();
224 bool BufferParams::hasClassDefaults() const
226 LyXTextClass const & tclass = textclasslist[textclass];
228 return (sides == tclass.sides()
229 && columns == tclass.columns()
230 && pagestyle == tclass.pagestyle()
231 && options == tclass.options()
232 && secnumdepth == tclass.secnumdepth()
233 && tocdepth == tclass.tocdepth());
237 LyXTextClass const & BufferParams::getLyXTextClass() const
239 return textclasslist[textclass];
243 void BufferParams::readPreamble(LyXLex & lex)
245 if (lex.getString() != "\\begin_preamble")
246 lyxerr << "Error (BufferParams::readPreamble):"
247 "consistency check failed." << endl;
249 preamble = lex.getLongString("\\end_preamble");
253 void BufferParams::readLanguage(LyXLex & lex)
255 if (!lex.next()) return;
257 string const tmptok = lex.getString();
259 // check if tmptok is part of tex_babel in tex-defs.h
260 language = languages.getLanguage(tmptok);
262 // Language tmptok was not found
263 language = default_language;
264 lyxerr << "Warning: Setting language `"
265 << tmptok << "' to `" << language->lang()
271 void BufferParams::readGraphicsDriver(LyXLex & lex)
273 if (!lex.next()) return;
275 string const tmptok = lex.getString();
276 // check if tmptok is part of tex_graphics in tex_defs.h
279 string const test = tex_graphics[n++];
281 if (test == tmptok) {
282 graphicsDriver = tmptok;
284 } else if (test == "last_item") {
286 "Warning: graphics driver `$$Token' not recognized!\n"
287 " Setting graphics driver to `default'.\n");
288 graphicsDriver = "default";