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;
57 tracking_changes = false;
60 language = default_language;
63 graphicsDriver = "default";
64 sides = LyXTextClass::OneSide;
66 pagestyle = "default";
67 for (int iter = 0; iter < 4; ++iter) {
68 user_defined_bullets[iter] = ITEMIZE_DEFAULTS[iter];
69 temp_bullets[iter] = ITEMIZE_DEFAULTS[iter];
74 void BufferParams::writeFile(ostream & os) const
76 // The top of the file is written by the buffer.
77 // Prints out the buffer info into the .lyx file given by file
80 os << "\\textclass " << textclasslist[textclass].name() << '\n';
82 // then the the preamble
83 if (!preamble.empty()) {
84 // remove '\n' from the end of preamble
85 string const tmppreamble = rtrim(preamble, "\n");
86 os << "\\begin_preamble\n"
88 << "\n\\end_preamble\n";
92 if (!options.empty()) {
93 os << "\\options " << options << '\n';
96 /* then the text parameters */
97 if (language != ignore_language)
98 os << "\\language " << language->lang() << '\n';
99 os << "\\inputencoding " << inputenc
100 << "\n\\fontscheme " << fonts
101 << "\n\\graphics " << graphicsDriver << '\n';
103 if (!float_placement.empty()) {
104 os << "\\float_placement " << float_placement << '\n';
106 os << "\\paperfontsize " << fontsize << '\n';
108 spacing.writeFile(os);
110 os << "\\papersize " << string_papersize[papersize2]
111 << "\n\\paperpackage " << string_paperpackages[paperpackage]
112 << "\n\\use_geometry " << use_geometry
113 << "\n\\use_amsmath " << use_amsmath
114 << "\n\\use_natbib " << use_natbib
115 << "\n\\use_numerical_citations " << use_numerical_citations
116 << "\n\\paperorientation " << string_orientation[orientation]
118 if (!paperwidth.empty())
119 os << "\\paperwidth "
120 << VSpace(paperwidth).asLyXCommand() << '\n';
121 if (!paperheight.empty())
122 os << "\\paperheight "
123 << VSpace(paperheight).asLyXCommand() << '\n';
124 if (!leftmargin.empty())
125 os << "\\leftmargin "
126 << VSpace(leftmargin).asLyXCommand() << '\n';
127 if (!topmargin.empty())
129 << VSpace(topmargin).asLyXCommand() << '\n';
130 if (!rightmargin.empty())
131 os << "\\rightmargin "
132 << VSpace(rightmargin).asLyXCommand() << '\n';
133 if (!bottommargin.empty())
134 os << "\\bottommargin "
135 << VSpace(bottommargin).asLyXCommand() << '\n';
136 if (!headheight.empty())
137 os << "\\headheight "
138 << VSpace(headheight).asLyXCommand() << '\n';
139 if (!headsep.empty())
141 << VSpace(headsep).asLyXCommand() << '\n';
142 if (!footskip.empty())
144 << VSpace(footskip).asLyXCommand() << '\n';
145 os << "\\secnumdepth " << secnumdepth
146 << "\n\\tocdepth " << tocdepth
147 << "\n\\paragraph_separation "
148 << string_paragraph_separation[paragraph_separation]
149 << "\n\\defskip " << defskip.asLyXCommand()
150 << "\n\\quotes_language "
151 << string_quotes_language[quotes_language] << '\n';
152 switch (quotes_times) {
153 // An output operator for insetquotes would be nice
154 case InsetQuotes::SingleQ:
155 os << "\\quotes_times 1\n"; break;
156 case InsetQuotes::DoubleQ:
157 os << "\\quotes_times 2\n"; break;
159 os << "\\papercolumns " << columns
160 << "\n\\papersides " << sides
161 << "\n\\paperpagestyle " << pagestyle << '\n';
162 for (int i = 0; i < 4; ++i) {
163 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
164 if (user_defined_bullets[i].getFont() != -1) {
165 os << "\\bullet " << i
167 << user_defined_bullets[i].getFont()
169 << user_defined_bullets[i].getCharacter()
171 << user_defined_bullets[i].getSize()
172 << "\n\\end_bullet\n";
175 os << "\\bulletLaTeX " << i
177 << user_defined_bullets[i].getText()
178 << "\"\n\\end_bullet\n";
183 os << "\\tracking_changes " << tracking_changes << "\n";
187 void BufferParams::setPaperStuff()
189 papersize = PAPER_DEFAULT;
190 char const c1 = paperpackage;
191 if (c1 == PACKAGE_NONE) {
192 char const c2 = papersize2;
193 if (c2 == VM_PAPER_USLETTER)
194 papersize = PAPER_USLETTER;
195 else if (c2 == VM_PAPER_USLEGAL)
196 papersize = PAPER_LEGALPAPER;
197 else if (c2 == VM_PAPER_USEXECUTIVE)
198 papersize = PAPER_EXECUTIVEPAPER;
199 else if (c2 == VM_PAPER_A3)
200 papersize = PAPER_A3PAPER;
201 else if (c2 == VM_PAPER_A4)
202 papersize = PAPER_A4PAPER;
203 else if (c2 == VM_PAPER_A5)
204 papersize = PAPER_A5PAPER;
205 else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
207 papersize = PAPER_B5PAPER;
208 } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
209 (c1 == PACKAGE_WIDEMARGINSA4))
210 papersize = PAPER_A4PAPER;
214 void BufferParams::useClassDefaults()
216 LyXTextClass const & tclass = textclasslist[textclass];
218 sides = tclass.sides();
219 columns = tclass.columns();
220 pagestyle = tclass.pagestyle();
221 options = tclass.options();
222 secnumdepth = tclass.secnumdepth();
223 tocdepth = tclass.tocdepth();
227 bool BufferParams::hasClassDefaults() const
229 LyXTextClass const & tclass = textclasslist[textclass];
231 return (sides == tclass.sides()
232 && columns == tclass.columns()
233 && pagestyle == tclass.pagestyle()
234 && options == tclass.options()
235 && secnumdepth == tclass.secnumdepth()
236 && tocdepth == tclass.tocdepth());
240 LyXTextClass const & BufferParams::getLyXTextClass() const
242 return textclasslist[textclass];
246 void BufferParams::readPreamble(LyXLex & lex)
248 if (lex.getString() != "\\begin_preamble")
249 lyxerr << "Error (BufferParams::readPreamble):"
250 "consistency check failed." << endl;
252 preamble = lex.getLongString("\\end_preamble");
256 void BufferParams::readLanguage(LyXLex & lex)
258 if (!lex.next()) return;
260 string const tmptok = lex.getString();
262 // check if tmptok is part of tex_babel in tex-defs.h
263 language = languages.getLanguage(tmptok);
265 // Language tmptok was not found
266 language = default_language;
267 lyxerr << "Warning: Setting language `"
268 << tmptok << "' to `" << language->lang()
274 void BufferParams::readGraphicsDriver(LyXLex & lex)
276 if (!lex.next()) return;
278 string const tmptok = lex.getString();
279 // check if tmptok is part of tex_graphics in tex_defs.h
282 string const test = tex_graphics[n++];
284 if (test == tmptok) {
285 graphicsDriver = tmptok;
287 } else if (test == "last_item") {
289 "Warning: graphics driver `$$Token' not recognized!\n"
290 " Setting graphics driver to `default'.\n");
291 graphicsDriver = "default";