2 * \file output_plaintext.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "output_plaintext.h"
16 #include "bufferparams.h"
20 #include "outputparams.h"
21 #include "paragraph.h"
22 #include "ParagraphList.h"
23 #include "ParagraphParameters.h"
25 #include "support/lstrings.h"
29 using lyx::support::ascii_lowercase;
30 using lyx::support::compare_ascii_no_case;
31 using lyx::support::compare_no_case;
32 using lyx::support::contains;
42 void writeFileAscii(Buffer const & buf,
44 OutputParams const & runparams)
47 if (!::openFileWrite(ofs, fname))
49 writeFileAscii(buf, ofs, runparams);
53 void writeFileAscii(Buffer const & buf, ostream & os,
54 OutputParams const & runparams)
56 bool ref_printed = false;
57 ParagraphList const par = buf.paragraphs();
58 ParagraphList::const_iterator beg = par.begin();
59 ParagraphList::const_iterator end = par.end();
60 ParagraphList::const_iterator it = beg;
61 for (; it != end; ++it) {
62 asciiParagraph(buf, *it, os, runparams, ref_printed);
70 pair<int, string> const addDepth(int depth, int ldepth)
74 d += (ldepth - depth) * 2;
75 return make_pair(d, string(d, ' '));
81 void asciiParagraph(Buffer const & buf,
82 Paragraph const & par,
84 OutputParams const & runparams,
88 Paragraph::depth_type ltype_depth = 0;
89 Paragraph::depth_type depth = par.params().depth();
91 // First write the layout
92 string const & tmp = par.layout()->name();
93 if (compare_no_case(tmp, "itemize") == 0) {
95 ltype_depth = depth + 1;
96 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
98 ltype_depth = depth + 1;
99 } else if (contains(ascii_lowercase(tmp), "ection")) {
101 ltype_depth = depth + 1;
102 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
104 ltype_depth = depth + 1;
105 } else if (compare_ascii_no_case(tmp, "description") == 0) {
107 ltype_depth = depth + 1;
108 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
111 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
119 /* maybe some vertical spaces */
121 /* the labelwidthstring used in lists */
125 /* some pagebreaks? */
129 /* what about the alignment */
131 // runparams.linelen <= 0 is special and means we don't have paragraph breaks
133 string::size_type currlinelen = 0;
135 if (runparams.linelen > 0)
138 os << string(depth * 2, ' ');
139 currlinelen += depth * 2;
142 // we should probably change to the paragraph language in the
143 // gettext here (if possible) so that strings are output in
144 // the correct language! (20012712 Jug)
148 case 4: // (Sub)Paragraph
149 case 5: // Description
153 if (runparams.linelen > 0) {
154 os << _("Abstract") << "\n\n";
157 string const abst = _("Abstract: ");
159 currlinelen += abst.length();
163 case 7: // Bibliography
165 if (runparams.linelen > 0) {
166 os << _("References") << "\n\n";
169 string const refs = _("References: ");
171 currlinelen += refs.length();
178 string const label = par.params().labelString();
180 currlinelen += label.length() + 1;
187 pair<int, string> p = addDepth(depth, ltype_depth);
189 currlinelen += p.first;
192 // this is to change the linebreak to do it by word a bit more
193 // intelligent hopefully! (only in the case where we have a
194 // max runparams.linelength!) (Jug)
198 for (pos_type i = 0; i < par.size(); ++i) {
199 char c = par.getUChar(buf.params(), i);
201 case Paragraph::META_INSET: {
202 InsetBase const * inset = par.getInset(i);
203 if (runparams.linelen > 0) {
205 currlinelen += word.length();
208 OutputParams rp = runparams;
209 rp.depth = par.params().depth();
210 if (inset->plaintext(buf, os, rp)) {
211 // to be sure it breaks paragraph
212 currlinelen += runparams.linelen;
218 if (runparams.linelen > 0 &&
219 currlinelen + word.length() > runparams.linelen - 10) {
221 pair<int, string> p = addDepth(depth, ltype_depth);
223 currlinelen = p.first;
226 currlinelen += word.length() + 1;
231 lyxerr[Debug::INFO] <<
232 "writeAsciiFile: NULL char in structure." << endl;
237 if (runparams.linelen > 0 &&
238 currlinelen + word.length() > runparams.linelen)
241 pair<int, string> p = addDepth(depth, ltype_depth);
243 currlinelen = p.first;