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 * ====================================================== */
13 #include "bufferparams.h"
14 #include "tex-strings.h"
20 #include "lyxtextclasslist.h"
23 #include "support/lyxlib.h"
24 #include "support/lstrings.h"
31 BufferParams::BufferParams()
32 // Initialize textclass to point to article. if `first' is
33 // true in the returned pair, then `second' is the textclass
34 // number; if it is false, second is 0. In both cases, second
36 : textclass(textclasslist.NumberOfClass("article").second)
38 paragraph_separation = PARSEP_INDENT;
39 defskip = VSpace(VSpace::MEDSKIP);
40 quotes_language = InsetQuotes::EnglishQ;
41 quotes_times = InsetQuotes::DoubleQ;
45 papersize = PAPER_DEFAULT;
46 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
47 paperpackage = PACKAGE_NONE;
48 orientation = ORIENTATION_PORTRAIT;
52 use_numerical_citations = false;
53 tracking_changes = false;
56 language = default_language;
59 graphicsDriver = "default";
60 sides = LyXTextClass::OneSide;
62 pagestyle = "default";
63 for (int iter = 0; iter < 4; ++iter) {
64 user_defined_bullets[iter] = ITEMIZE_DEFAULTS[iter];
65 temp_bullets[iter] = ITEMIZE_DEFAULTS[iter];
70 void BufferParams::writeFile(ostream & os) const
72 // The top of the file is written by the buffer.
73 // Prints out the buffer info into the .lyx file given by file
76 os << "\\textclass " << textclasslist[textclass].name() << '\n';
78 // then the the preamble
79 if (!preamble.empty()) {
80 // remove '\n' from the end of preamble
81 string const tmppreamble = rtrim(preamble, "\n");
82 os << "\\begin_preamble\n"
84 << "\n\\end_preamble\n";
88 if (!options.empty()) {
89 os << "\\options " << options << '\n';
92 /* then the text parameters */
93 if (language != ignore_language)
94 os << "\\language " << language->lang() << '\n';
95 os << "\\inputencoding " << inputenc
96 << "\n\\fontscheme " << fonts
97 << "\n\\graphics " << graphicsDriver << '\n';
99 if (!float_placement.empty()) {
100 os << "\\float_placement " << float_placement << '\n';
102 os << "\\paperfontsize " << fontsize << '\n';
104 spacing.writeFile(os);
106 os << "\\papersize " << string_papersize[papersize2]
107 << "\n\\paperpackage " << string_paperpackages[paperpackage]
108 << "\n\\use_geometry " << use_geometry
109 << "\n\\use_amsmath " << use_amsmath
110 << "\n\\use_natbib " << use_natbib
111 << "\n\\use_numerical_citations " << use_numerical_citations
112 << "\n\\paperorientation " << string_orientation[orientation]
114 if (!paperwidth.empty())
115 os << "\\paperwidth "
116 << VSpace(paperwidth).asLyXCommand() << '\n';
117 if (!paperheight.empty())
118 os << "\\paperheight "
119 << VSpace(paperheight).asLyXCommand() << '\n';
120 if (!leftmargin.empty())
121 os << "\\leftmargin "
122 << VSpace(leftmargin).asLyXCommand() << '\n';
123 if (!topmargin.empty())
125 << VSpace(topmargin).asLyXCommand() << '\n';
126 if (!rightmargin.empty())
127 os << "\\rightmargin "
128 << VSpace(rightmargin).asLyXCommand() << '\n';
129 if (!bottommargin.empty())
130 os << "\\bottommargin "
131 << VSpace(bottommargin).asLyXCommand() << '\n';
132 if (!headheight.empty())
133 os << "\\headheight "
134 << VSpace(headheight).asLyXCommand() << '\n';
135 if (!headsep.empty())
137 << VSpace(headsep).asLyXCommand() << '\n';
138 if (!footskip.empty())
140 << VSpace(footskip).asLyXCommand() << '\n';
141 os << "\\secnumdepth " << secnumdepth
142 << "\n\\tocdepth " << tocdepth
143 << "\n\\paragraph_separation "
144 << string_paragraph_separation[paragraph_separation]
145 << "\n\\defskip " << defskip.asLyXCommand()
146 << "\n\\quotes_language "
147 << string_quotes_language[quotes_language] << '\n';
148 switch (quotes_times) {
149 // An output operator for insetquotes would be nice
150 case InsetQuotes::SingleQ:
151 os << "\\quotes_times 1\n"; break;
152 case InsetQuotes::DoubleQ:
153 os << "\\quotes_times 2\n"; break;
155 os << "\\papercolumns " << columns
156 << "\n\\papersides " << sides
157 << "\n\\paperpagestyle " << pagestyle << '\n';
158 for (int i = 0; i < 4; ++i) {
159 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
160 if (user_defined_bullets[i].getFont() != -1) {
161 os << "\\bullet " << i
163 << user_defined_bullets[i].getFont()
165 << user_defined_bullets[i].getCharacter()
167 << user_defined_bullets[i].getSize()
168 << "\n\\end_bullet\n";
171 os << "\\bulletLaTeX " << i
173 << user_defined_bullets[i].getText()
174 << "\"\n\\end_bullet\n";
179 os << "\\tracking_changes " << tracking_changes << "\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 LyXTextClass const & BufferParams::getLyXTextClass() const
238 return textclasslist[textclass];
242 void BufferParams::readPreamble(LyXLex & lex)
244 if (lex.getString() != "\\begin_preamble")
245 lyxerr << "Error (BufferParams::readPreamble):"
246 "consistency check failed." << endl;
248 preamble = lex.getLongString("\\end_preamble");
252 void BufferParams::readLanguage(LyXLex & lex)
254 if (!lex.next()) return;
256 string const tmptok = lex.getString();
258 // check if tmptok is part of tex_babel in tex-defs.h
259 language = languages.getLanguage(tmptok);
261 // Language tmptok was not found
262 language = default_language;
263 lyxerr << "Warning: Setting language `"
264 << tmptok << "' to `" << language->lang()
270 void BufferParams::readGraphicsDriver(LyXLex & lex)
272 if (!lex.next()) return;
274 string const tmptok = lex.getString();
275 // check if tmptok is part of tex_graphics in tex_defs.h
278 string const test = tex_graphics[n++];
280 if (test == tmptok) {
281 graphicsDriver = tmptok;
283 } else if (test == "last_item") {
285 "Warning: graphics driver `$$Token' not recognized!\n"
286 " Setting graphics driver to `default'.\n");
287 graphicsDriver = "default";