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];
68 void BufferParams::writeFile(ostream & os) const
70 // The top of the file is written by the buffer.
71 // Prints out the buffer info into the .lyx file given by file
74 os << "\\textclass " << textclasslist.NameOfClass(textclass) << '\n';
76 // then the the preamble
77 if (!preamble.empty()) {
78 // remove '\n' from the end of preamble
79 string tmppreamble = strip(preamble, '\n');
80 os << "\\begin_preamble\n"
82 << "\n\\end_preamble\n";
86 if (!options.empty()) {
87 os << "\\options " << options << '\n';
90 /* then the text parameters */
91 os << "\\language " << language
92 << "\n\\inputencoding " << inputenc
93 << "\n\\fontscheme " << fonts
94 << "\n\\graphics " << graphicsDriver << '\n';
96 if (!float_placement.empty()) {
97 os << "\\float_placement " << float_placement << '\n';
99 os << "\\paperfontsize " << fontsize << '\n';
101 spacing.writeFile(os);
103 os << "\\papersize " << string_papersize[papersize2]
104 << "\n\\paperpackage " << string_paperpackages[paperpackage]
105 << "\n\\use_geometry " << use_geometry
106 << "\n\\use_amsmath " << use_amsmath
107 << "\n\\paperorientation " << string_orientation[orientation]
109 if (!paperwidth.empty())
110 os << "\\paperwidth "
111 << VSpace(paperwidth).asLyXCommand() << '\n';
112 if (!paperheight.empty())
113 os << "\\paperheight "
114 << VSpace(paperheight).asLyXCommand() << '\n';
115 if (!leftmargin.empty())
116 os << "\\leftmargin "
117 << VSpace(leftmargin).asLyXCommand() << '\n';
118 if (!topmargin.empty())
120 << VSpace(topmargin).asLyXCommand() << '\n';
121 if (!rightmargin.empty())
122 os << "\\rightmargin "
123 << VSpace(rightmargin).asLyXCommand() << '\n';
124 if (!bottommargin.empty())
125 os << "\\bottommargin "
126 << VSpace(bottommargin).asLyXCommand() << '\n';
127 if (!headheight.empty())
128 os << "\\headheight "
129 << VSpace(headheight).asLyXCommand() << '\n';
130 if (!headsep.empty())
132 << VSpace(headsep).asLyXCommand() << '\n';
133 if (!footskip.empty())
135 << VSpace(footskip).asLyXCommand() << '\n';
136 os << "\\secnumdepth " << secnumdepth
137 << "\n\\tocdepth " << tocdepth
138 << "\n\\paragraph_separation "
139 << string_paragraph_separation[paragraph_separation]
140 << "\n\\defskip " << defskip.asLyXCommand()
141 << "\n\\quotes_language "
142 << string_quotes_language[quotes_language] << '\n';
143 switch(quotes_times) {
144 // An output operator for insetquotes would be nice
145 case InsetQuotes::SingleQ:
146 os << "\\quotes_times 1\n"; break;
147 case InsetQuotes::DoubleQ:
148 os << "\\quotes_times 2\n"; break;
150 os << "\\papercolumns " << columns
151 << "\n\\papersides " << sides
152 << "\n\\paperpagestyle " << pagestyle << '\n';
153 for (int i = 0; i < 4; ++i) {
154 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
155 if (user_defined_bullets[i].getFont() != -1) {
156 os << "\\bullet " << i
158 << user_defined_bullets[i].getFont()
160 << user_defined_bullets[i].getCharacter()
162 << user_defined_bullets[i].getSize()
163 << "\n\\end_bullet\n";
166 os << "\\bulletLaTeX " << i
168 << user_defined_bullets[i].getText().c_str()
169 << "\n\\end_bullet\n";
176 void BufferParams::useClassDefaults() {
177 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
179 sides = tclass.sides();
180 columns = tclass.columns();
181 pagestyle = tclass.pagestyle();
182 options = tclass.options();
183 secnumdepth = tclass.secnumdepth();
184 tocdepth = tclass.tocdepth();
188 void BufferParams::readPreamble(LyXLex & lex)
190 if (lex.GetString() != "\\begin_preamble")
191 lyxerr << "Error (BufferParams::readPreamble):"
192 "consistency check failed." << endl;
194 preamble = lex.getLongString("\\end_preamble");
198 void BufferParams::readLanguage(LyXLex & lex)
200 if (!lex.next()) return;
202 string tmptok = lex.GetString();
204 // check if tmptok is part of tex_babel in tex-defs.h
205 Languages::iterator lit = languages.find(tmptok);
206 if (lit != languages.end()) {
209 language_info = &(*lit).second;
212 language = "default";
213 language_info = default_language;
214 if (tmptok != "default") {
215 lyxerr << "Warning: language `"
216 << tmptok << "' not recognized!\n"
217 << " Setting language to `default'."
224 void BufferParams::readGraphicsDriver(LyXLex & lex)
231 if (!lex.next()) return;
233 tmptok = lex.GetString();
234 // check if tmptok is part of tex_graphics in tex_defs.h
236 test = tex_graphics[n++];
238 if (test == tmptok) {
239 graphicsDriver = tmptok;
242 else if (test == "last_item") {
244 "Warning: graphics driver `$$Token' not recognized!\n"
245 " Setting graphics driver to `default'.\n");
246 graphicsDriver = "default";