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_fwd.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 ParagraphList const par = buf.paragraphs();
57 ParagraphList::const_iterator beg = par.begin();
58 ParagraphList::const_iterator end = par.end();
59 ParagraphList::const_iterator it = beg;
60 for (; it != end; ++it) {
61 asciiParagraph(buf, *it, os, runparams, it == beg);
69 pair<int, string> const addDepth(int depth, int ldepth)
73 d += (ldepth - depth) * 2;
74 return make_pair(d, string(d, ' '));
80 void asciiParagraph(Buffer const & buf,
81 Paragraph const & par,
83 OutputParams const & runparams,
87 Paragraph::depth_type ltype_depth = 0;
88 static bool ref_printed = false;
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;
136 if (runparams.linelen > 0)
139 os << string(depth * 2, ' ');
140 currlinelen += depth * 2;
143 // we should probably change to the paragraph language in the
144 // gettext here (if possible) so that strings are output in
145 // the correct language! (20012712 Jug)
149 case 4: // (Sub)Paragraph
150 case 5: // Description
154 if (runparams.linelen > 0) {
155 os << _("Abstract") << "\n\n";
158 string const abst = _("Abstract: ");
160 currlinelen += abst.length();
164 case 7: // Bibliography
166 if (runparams.linelen > 0) {
167 os << _("References") << "\n\n";
170 string const refs = _("References: ");
172 currlinelen += refs.length();
179 string const label = par.params().labelString();
181 currlinelen += label.length() + 1;
189 pair<int, string> p = addDepth(depth, ltype_depth);
191 currlinelen += p.first;
194 // this is to change the linebreak to do it by word a bit more
195 // intelligent hopefully! (only in the case where we have a
196 // max runparams.linelength!) (Jug)
200 for (pos_type i = 0; i < par.size(); ++i) {
201 char c = par.getUChar(buf.params(), i);
203 case Paragraph::META_INSET: {
204 InsetBase const * inset = par.getInset(i);
205 if (runparams.linelen > 0) {
207 currlinelen += word.length();
210 OutputParams rp = runparams;
211 rp.depth = par.params().depth();
212 if (inset->plaintext(buf, os, rp)) {
213 // to be sure it breaks paragraph
214 currlinelen += runparams.linelen;
220 if (runparams.linelen > 0 &&
221 currlinelen + word.length() > runparams.linelen - 10) {
223 pair<int, string> p = addDepth(depth, ltype_depth);
225 currlinelen = p.first;
228 currlinelen += word.length() + 1;
233 lyxerr[Debug::INFO] <<
234 "writeAsciiFile: NULL char in structure." << endl;
239 if (runparams.linelen > 0 &&
240 currlinelen + word.length() > runparams.linelen)
243 pair<int, string> p = addDepth(depth, ltype_depth);
245 currlinelen = p.first;