1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 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;
54 graphicsDriver = "default";
55 sides = LyXTextClass::OneSide;
57 pagestyle = "default";
58 for(int iter = 0; iter < 4; ++iter) {
59 user_defined_bullets[iter] = temp_bullets[iter]
60 = ITEMIZE_DEFAULTS[iter];
66 void BufferParams::writeFile(ostream & os) const
68 // The top of the file is written by the buffer.
69 // Prints out the buffer info into the .lyx file given by file
72 os << "\\textclass " << textclasslist.NameOfClass(textclass) << '\n';
74 // then the the preamble
75 if (!preamble.empty()) {
76 // remove '\n' from the end of preamble
77 string tmppreamble = strip(preamble, '\n');
78 os << "\\begin_preamble\n"
80 << "\n\\end_preamble\n";
84 if (!options.empty()) {
85 os << "\\options " << options << '\n';
88 /* then the text parameters */
89 os << "\\language " << language
90 << "\n\\inputencoding " << inputenc
91 << "\n\\fontscheme " << fonts
92 << "\n\\graphics " << graphicsDriver << '\n';
94 if (!float_placement.empty()) {
95 os << "\\float_placement " << float_placement << '\n';
97 os << "\\paperfontsize " << fontsize << '\n';
99 spacing.writeFile(os);
101 os << "\\papersize " << string_papersize[papersize2]
102 << "\n\\paperpackage " << string_paperpackages[paperpackage]
103 << "\n\\use_geometry " << use_geometry
104 << "\n\\use_amsmath " << use_amsmath
105 << "\n\\paperorientation " << string_orientation[orientation]
107 if (!paperwidth.empty())
108 os << "\\paperwidth "
109 << VSpace(paperwidth).asLyXCommand() << '\n';
110 if (!paperheight.empty())
111 os << "\\paperheight "
112 << VSpace(paperheight).asLyXCommand() << '\n';
113 if (!leftmargin.empty())
114 os << "\\leftmargin "
115 << VSpace(leftmargin).asLyXCommand() << '\n';
116 if (!topmargin.empty())
118 << VSpace(topmargin).asLyXCommand() << '\n';
119 if (!rightmargin.empty())
120 os << "\\rightmargin "
121 << VSpace(rightmargin).asLyXCommand() << '\n';
122 if (!bottommargin.empty())
123 os << "\\bottommargin "
124 << VSpace(bottommargin).asLyXCommand() << '\n';
125 if (!headheight.empty())
126 os << "\\headheight "
127 << VSpace(headheight).asLyXCommand() << '\n';
128 if (!headsep.empty())
130 << VSpace(headsep).asLyXCommand() << '\n';
131 if (!footskip.empty())
133 << VSpace(footskip).asLyXCommand() << '\n';
134 os << "\\secnumdepth " << secnumdepth
135 << "\n\\tocdepth " << tocdepth
136 << "\n\\paragraph_separation "
137 << string_paragraph_separation[paragraph_separation]
138 << "\n\\defskip " << defskip.asLyXCommand()
139 << "\n\\quotes_language "
140 << string_quotes_language[quotes_language] << '\n';
141 switch(quotes_times) {
142 // An output operator for insetquotes would be nice
143 case InsetQuotes::SingleQ:
144 os << "\\quotes_times 1\n"; break;
145 case InsetQuotes::DoubleQ:
146 os << "\\quotes_times 2\n"; break;
148 os << "\\papercolumns " << columns
149 << "\n\\papersides " << sides
150 << "\n\\paperpagestyle " << pagestyle << '\n';
151 for (int i = 0; i < 4; ++i) {
152 if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
153 if (user_defined_bullets[i].getFont() != -1) {
154 os << "\\bullet " << i
156 << user_defined_bullets[i].getFont()
158 << user_defined_bullets[i].getCharacter()
160 << user_defined_bullets[i].getSize()
161 << "\n\\end_bullet\n";
164 os << "\\bulletLaTeX " << i
166 << user_defined_bullets[i].c_str()
167 << "\n\\end_bullet\n";
174 void BufferParams::useClassDefaults() {
175 LyXTextClass const & tclass = textclasslist.TextClass(textclass);
177 sides = tclass.sides();
178 columns = tclass.columns();
179 pagestyle = tclass.pagestyle();
180 options = tclass.options();
181 secnumdepth = tclass.secnumdepth();
182 tocdepth = tclass.tocdepth();
186 void BufferParams::readPreamble(LyXLex & lex)
188 if (lex.GetString() != "\\begin_preamble")
189 lyxerr << "Error (BufferParams::readPreamble):"
190 "consistency check failed." << endl;
192 preamble = lex.getLongString("\\end_preamble");
196 void BufferParams::readLanguage(LyXLex & lex)
198 if (!lex.next()) return;
200 string tmptok = lex.GetString();
203 // check if tmptok is part of tex_babel in tex-defs.h
205 test = tex_babel[n++];
207 if (test == tmptok) {
211 else if (test.empty()) {
212 lyxerr << "Warning: language `"
213 << tmptok << "' not recognized!\n"
214 << " Setting language to `default'."
216 language = "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";
252 LyXDirection BufferParams::getDocumentDirection() const
254 return (lyxrc->rtl_support && language == "hebrew")
255 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;