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"
29 BufferParams::BufferParams()
31 paragraph_separation = PARSEP_INDENT;
32 defskip = VSpace(VSpace::MEDSKIP);
33 quotes_language = InsetQuotes::EnglishQ;
34 quotes_times = InsetQuotes::DoubleQ;
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;
43 papersize = PAPER_DEFAULT;
44 papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
45 paperpackage = PACKAGE_NONE;
46 orientation = ORIENTATION_PORTRAIT;
52 language_info = default_language;
55 graphicsDriver = "default";
56 sides = LyXTextClass::OneSide;
58 pagestyle = "default";
59 for(int iter = 0; iter < 4; ++iter) {
60 user_defined_bullets[iter] = temp_bullets[iter]
61 = ITEMIZE_DEFAULTS[iter];
67 void BufferParams::writeFile(ostream & os) const
69 // The top of the file is written by the buffer.
70 // Prints out the buffer info into the .lyx file given by file
73 os << "\\textclass " << textclasslist.NameOfClass(textclass) << '\n';
75 // then the the preamble
76 if (!preamble.empty()) {
77 // remove '\n' from the end of preamble
78 string tmppreamble = strip(preamble, '\n');
79 os << "\\begin_preamble\n"
81 << "\n\\end_preamble\n";
85 if (!options.empty()) {
86 os << "\\options " << options << '\n';
89 /* then the text parameters */
90 os << "\\language " << language
91 << "\n\\inputencoding " << inputenc
92 << "\n\\fontscheme " << fonts
93 << "\n\\graphics " << graphicsDriver << '\n';
95 if (!float_placement.empty()) {
96 os << "\\float_placement " << float_placement << '\n';
98 os << "\\paperfontsize " << fontsize << '\n';
100 spacing.writeFile(os);
102 os << "\\papersize " << string_papersize[papersize2]
103 << "\n\\paperpackage " << string_paperpackages[paperpackage]
104 << "\n\\use_geometry " << use_geometry
105 << "\n\\use_amsmath " << use_amsmath
106 << "\n\\paperorientation " << string_orientation[orientation]
108 if (!paperwidth.empty())
109 os << "\\paperwidth "
110 << VSpace(paperwidth).asLyXCommand() << '\n';
111 if (!paperheight.empty())
112 os << "\\paperheight "
113 << VSpace(paperheight).asLyXCommand() << '\n';
114 if (!leftmargin.empty())
115 os << "\\leftmargin "
116 << VSpace(leftmargin).asLyXCommand() << '\n';
117 if (!topmargin.empty())
119 << VSpace(topmargin).asLyXCommand() << '\n';
120 if (!rightmargin.empty())
121 os << "\\rightmargin "
122 << VSpace(rightmargin).asLyXCommand() << '\n';
123 if (!bottommargin.empty())
124 os << "\\bottommargin "
125 << VSpace(bottommargin).asLyXCommand() << '\n';
126 if (!headheight.empty())
127 os << "\\headheight "
128 << VSpace(headheight).asLyXCommand() << '\n';
129 if (!headsep.empty())
131 << VSpace(headsep).asLyXCommand() << '\n';
132 if (!footskip.empty())
134 << VSpace(footskip).asLyXCommand() << '\n';
135 os << "\\secnumdepth " << secnumdepth
136 << "\n\\tocdepth " << tocdepth
137 << "\n\\paragraph_separation "
138 << string_paragraph_separation[paragraph_separation]
139 << "\n\\defskip " << defskip.asLyXCommand()
140 << "\n\\quotes_language "
141 << string_quotes_language[quotes_language] << '\n';
142 switch(quotes_times) {
143 // An output operator for insetquotes would be nice
144 case InsetQuotes::SingleQ:
145 os << "\\quotes_times 1\n"; break;
146 case InsetQuotes::DoubleQ:
147 os << "\\quotes_times 2\n"; break;
149 os << "\\papercolumns " << columns
150 << "\n\\papersides " << sides
151 << "\n\\paperpagestyle " << pagestyle << '\n';
152 for (int i = 0; i < 4; ++i) {
153 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
154 if (user_defined_bullets[i].getFont() != -1) {
155 os << "\\bullet " << i
157 << user_defined_bullets[i].getFont()
159 << user_defined_bullets[i].getCharacter()
161 << user_defined_bullets[i].getSize()
162 << "\n\\end_bullet\n";
165 os << "\\bulletLaTeX " << i
167 << user_defined_bullets[i].c_str()
168 << "\n\\end_bullet\n";
175 void BufferParams::useClassDefaults() {
176 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
178 sides = tclass.sides();
179 columns = tclass.columns();
180 pagestyle = tclass.pagestyle();
181 options = tclass.options();
182 secnumdepth = tclass.secnumdepth();
183 tocdepth = tclass.tocdepth();
187 void BufferParams::readPreamble(LyXLex & lex)
189 if (lex.GetString() != "\\begin_preamble")
190 lyxerr << "Error (BufferParams::readPreamble):"
191 "consistency check failed." << endl;
193 preamble = lex.getLongString("\\end_preamble");
197 void BufferParams::readLanguage(LyXLex & lex)
199 if (!lex.next()) return;
201 string tmptok = lex.GetString();
203 // check if tmptok is part of tex_babel in tex-defs.h
204 Languages::iterator lit = languages.find(tmptok);
205 if (lit != languages.end()) {
208 language_info = &(*lit).second;
211 language = "default";
212 language_info = default_language;
213 if (tmptok != "default") {
214 lyxerr << "Warning: language `"
215 << tmptok << "' not recognized!\n"
216 << " Setting language to `default'."
223 void BufferParams::readGraphicsDriver(LyXLex & lex)
230 if (!lex.next()) return;
232 tmptok = lex.GetString();
233 // check if tmptok is part of tex_graphics in tex_defs.h
235 test = tex_graphics[n++];
237 if (test == tmptok) {
238 graphicsDriver = tmptok;
241 else if (test == "last_item") {
243 "Warning: graphics driver `$$Token' not recognized!\n"
244 " Setting graphics driver to `default'.\n");
245 graphicsDriver = "default";