1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 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;
54 language_info = default_language;
57 graphicsDriver = "default";
58 sides = LyXTextClass::OneSide;
60 pagestyle = "default";
61 for(int iter = 0; iter < 4; ++iter) {
62 user_defined_bullets[iter] = temp_bullets[iter]
63 = 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 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
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\\paperorientation " << string_orientation[orientation]
110 if (!paperwidth.empty())
111 os << "\\paperwidth "
112 << VSpace(paperwidth).asLyXCommand() << '\n';
113 if (!paperheight.empty())
114 os << "\\paperheight "
115 << VSpace(paperheight).asLyXCommand() << '\n';
116 if (!leftmargin.empty())
117 os << "\\leftmargin "
118 << VSpace(leftmargin).asLyXCommand() << '\n';
119 if (!topmargin.empty())
121 << VSpace(topmargin).asLyXCommand() << '\n';
122 if (!rightmargin.empty())
123 os << "\\rightmargin "
124 << VSpace(rightmargin).asLyXCommand() << '\n';
125 if (!bottommargin.empty())
126 os << "\\bottommargin "
127 << VSpace(bottommargin).asLyXCommand() << '\n';
128 if (!headheight.empty())
129 os << "\\headheight "
130 << VSpace(headheight).asLyXCommand() << '\n';
131 if (!headsep.empty())
133 << VSpace(headsep).asLyXCommand() << '\n';
134 if (!footskip.empty())
136 << VSpace(footskip).asLyXCommand() << '\n';
137 os << "\\secnumdepth " << secnumdepth
138 << "\n\\tocdepth " << tocdepth
139 << "\n\\paragraph_separation "
140 << string_paragraph_separation[paragraph_separation]
141 << "\n\\defskip " << defskip.asLyXCommand()
142 << "\n\\quotes_language "
143 << string_quotes_language[quotes_language] << '\n';
144 switch(quotes_times) {
145 // An output operator for insetquotes would be nice
146 case InsetQuotes::SingleQ:
147 os << "\\quotes_times 1\n"; break;
148 case InsetQuotes::DoubleQ:
149 os << "\\quotes_times 2\n"; break;
151 os << "\\papercolumns " << columns
152 << "\n\\papersides " << sides
153 << "\n\\paperpagestyle " << pagestyle << '\n';
154 for (int i = 0; i < 4; ++i) {
155 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
156 if (user_defined_bullets[i].getFont() != -1) {
157 os << "\\bullet " << i
159 << user_defined_bullets[i].getFont()
161 << user_defined_bullets[i].getCharacter()
163 << user_defined_bullets[i].getSize()
164 << "\n\\end_bullet\n";
167 os << "\\bulletLaTeX " << i
169 << user_defined_bullets[i].c_str()
170 << "\n\\end_bullet\n";
177 void BufferParams::useClassDefaults() {
178 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
180 sides = tclass.sides();
181 columns = tclass.columns();
182 pagestyle = tclass.pagestyle();
183 options = tclass.options();
184 secnumdepth = tclass.secnumdepth();
185 tocdepth = tclass.tocdepth();
189 void BufferParams::readPreamble(LyXLex & lex)
191 if (lex.GetString() != "\\begin_preamble")
192 lyxerr << "Error (BufferParams::readPreamble):"
193 "consistency check failed." << endl;
195 preamble = lex.getLongString("\\end_preamble");
199 void BufferParams::readLanguage(LyXLex & lex)
201 if (!lex.next()) return;
203 string tmptok = lex.GetString();
205 // check if tmptok is part of tex_babel in tex-defs.h
206 Languages::iterator lit = languages.find(tmptok);
207 if (lit != languages.end()) {
210 language_info = &(*lit).second;
213 language = "default";
214 language_info = default_language;
215 if (tmptok != "default") {
216 lyxerr << "Warning: language `"
217 << tmptok << "' not recognized!\n"
218 << " Setting language to `default'."
225 void BufferParams::readGraphicsDriver(LyXLex & lex)
232 if (!lex.next()) return;
234 tmptok = lex.GetString();
235 // check if tmptok is part of tex_graphics in tex_defs.h
237 test = tex_graphics[n++];
239 if (test == tmptok) {
240 graphicsDriver = tmptok;
243 else if (test == "last_item") {
245 "Warning: graphics driver `$$Token' not recognized!\n"
246 " Setting graphics driver to `default'.\n");
247 graphicsDriver = "default";