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 os << "\\language " << language->lang()
93 << "\n\\inputencoding " << inputenc
94 << "\n\\fontscheme " << fonts
95 << "\n\\graphics " << graphicsDriver << '\n';
97 if (!float_placement.empty()) {
98 os << "\\float_placement " << float_placement << '\n';
100 os << "\\paperfontsize " << fontsize << '\n';
102 spacing.writeFile(os);
104 os << "\\papersize " << string_papersize[papersize2]
105 << "\n\\paperpackage " << string_paperpackages[paperpackage]
106 << "\n\\use_geometry " << use_geometry
107 << "\n\\use_amsmath " << use_amsmath
108 << "\n\\use_natbib " << use_natbib
109 << "\n\\use_numerical_citations " << use_numerical_citations
110 << "\n\\paperorientation " << string_orientation[orientation]
112 if (!paperwidth.empty())
113 os << "\\paperwidth "
114 << VSpace(paperwidth).asLyXCommand() << '\n';
115 if (!paperheight.empty())
116 os << "\\paperheight "
117 << VSpace(paperheight).asLyXCommand() << '\n';
118 if (!leftmargin.empty())
119 os << "\\leftmargin "
120 << VSpace(leftmargin).asLyXCommand() << '\n';
121 if (!topmargin.empty())
123 << VSpace(topmargin).asLyXCommand() << '\n';
124 if (!rightmargin.empty())
125 os << "\\rightmargin "
126 << VSpace(rightmargin).asLyXCommand() << '\n';
127 if (!bottommargin.empty())
128 os << "\\bottommargin "
129 << VSpace(bottommargin).asLyXCommand() << '\n';
130 if (!headheight.empty())
131 os << "\\headheight "
132 << VSpace(headheight).asLyXCommand() << '\n';
133 if (!headsep.empty())
135 << VSpace(headsep).asLyXCommand() << '\n';
136 if (!footskip.empty())
138 << VSpace(footskip).asLyXCommand() << '\n';
139 os << "\\secnumdepth " << secnumdepth
140 << "\n\\tocdepth " << tocdepth
141 << "\n\\paragraph_separation "
142 << string_paragraph_separation[paragraph_separation]
143 << "\n\\defskip " << defskip.asLyXCommand()
144 << "\n\\quotes_language "
145 << string_quotes_language[quotes_language] << '\n';
146 switch (quotes_times) {
147 // An output operator for insetquotes would be nice
148 case InsetQuotes::SingleQ:
149 os << "\\quotes_times 1\n"; break;
150 case InsetQuotes::DoubleQ:
151 os << "\\quotes_times 2\n"; break;
153 os << "\\papercolumns " << columns
154 << "\n\\papersides " << sides
155 << "\n\\paperpagestyle " << pagestyle << '\n';
156 for (int i = 0; i < 4; ++i) {
157 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
158 if (user_defined_bullets[i].getFont() != -1) {
159 os << "\\bullet " << i
161 << user_defined_bullets[i].getFont()
163 << user_defined_bullets[i].getCharacter()
165 << user_defined_bullets[i].getSize()
166 << "\n\\end_bullet\n";
169 os << "\\bulletLaTeX " << i
171 << user_defined_bullets[i].getText()
172 << "\n\\end_bullet\n";
179 void BufferParams::useClassDefaults() {
180 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
182 sides = tclass.sides();
183 columns = tclass.columns();
184 pagestyle = tclass.pagestyle();
185 options = tclass.options();
186 secnumdepth = tclass.secnumdepth();
187 tocdepth = tclass.tocdepth();
191 void BufferParams::readPreamble(LyXLex & lex)
193 if (lex.GetString() != "\\begin_preamble")
194 lyxerr << "Error (BufferParams::readPreamble):"
195 "consistency check failed." << endl;
197 preamble = lex.getLongString("\\end_preamble");
201 void BufferParams::readLanguage(LyXLex & lex)
203 if (!lex.next()) return;
205 string const tmptok = lex.GetString();
207 // check if tmptok is part of tex_babel in tex-defs.h
208 language = languages.getLanguage(tmptok);
210 // Language tmptok was not found
211 language = default_language;
212 lyxerr << "Warning: Setting language `"
213 << tmptok << "' to `" << language->lang()
219 void BufferParams::readGraphicsDriver(LyXLex & lex)
221 if (!lex.next()) return;
223 string const tmptok = lex.GetString();
224 // check if tmptok is part of tex_graphics in tex_defs.h
227 string const test = tex_graphics[n++];
229 if (test == tmptok) {
230 graphicsDriver = tmptok;
232 } else if (test == "last_item") {
234 "Warning: graphics driver `$$Token' not recognized!\n"
235 " Setting graphics driver to `default'.\n");
236 graphicsDriver = "default";