#include "tex-strings.h"
#include "lyxlex.h"
+#include "buffer.h"
+#include "BufferView.h"
+#include "Lsstream.h"
+#include "gettext.h"
+#include "paragraph.h"
+#include "lyxtext.h"
+#include "Lsstream.h"
+
+#include "frontends/LyXView.h"
+
+#include "support/lstrings.h"
+
#include <iostream>
+using namespace lyx::support;
+
using std::ostream;
// Initialize static member var.
void ParagraphParameters::read(LyXLex & lex)
{
+ while (lex.isOK()) {
+ lex.nextToken();
+ string const token = lex.getString();
+
+ if (token.empty())
+ continue;
+
+ if (token[0] != '\\') {
+ lex.pushToken(token);
+ break;
+ }
+
+ if (token == "\\noindent") {
+ noindent(true);
+ } else if (token == "\\leftindent") {
+ lex.nextToken();
+ LyXLength value(lex.getString());
+ leftIndent(value);
+ } else if (token == "\\fill_top") {
+ spaceTop(VSpace(VSpace::VFILL));
+ } else if (token == "\\fill_bottom") {
+ spaceBottom(VSpace(VSpace::VFILL));
+ } else if (token == "\\line_top") {
+ lineTop(true);
+ } else if (token == "\\line_bottom") {
+ lineBottom(true);
+ } else if (token == "\\pagebreak_top") {
+ pagebreakTop(true);
+ } else if (token == "\\pagebreak_bottom") {
+ pagebreakBottom(true);
+ } else if (token == "\\start_of_appendix") {
+ startOfAppendix(true);
+ } else if (token == "\\paragraph_spacing") {
+ lex.next();
+ string const tmp = rtrim(lex.getString());
+ if (tmp == "single") {
+ spacing(Spacing(Spacing::Single));
+ } else if (tmp == "onehalf") {
+ spacing(Spacing(Spacing::Onehalf));
+ } else if (tmp == "double") {
+ spacing(Spacing(Spacing::Double));
+ } else if (tmp == "other") {
+ lex.next();
+ spacing(Spacing(Spacing::Other,
+ lex.getFloat()));
+ } else {
+ lex.printError("Unknown spacing token: '$$Token'");
+ }
+ } else if (token == "\\align") {
+ int tmpret = lex.findToken(string_align);
+ if (tmpret == -1)
+ ++tmpret;
+ align(LyXAlignment(1 << tmpret));
+ } else if (token == "\\added_space_top") {
+ lex.nextToken();
+ VSpace value = VSpace(lex.getString());
+ // only add the length when value > 0 or
+ // with option keep
+ if ((value.length().len().value() != 0) ||
+ value.keep() ||
+ (value.kind() != VSpace::LENGTH))
+ spaceTop(value);
+ } else if (token == "\\added_space_bottom") {
+ lex.nextToken();
+ VSpace value = VSpace(lex.getString());
+ // only add the length when value > 0 or
+ // with option keep
+ if ((value.length().len().value() != 0) ||
+ value.keep() ||
+ (value.kind() != VSpace::LENGTH))
+ spaceBottom(value);
+ } else if (token == "\\labelwidthstring") {
+ lex.eatLine();
+ labelWidthString(lex.getString());
+ } else {
+ lex.pushToken(token);
+ break;
+ }
+ }
}
os << "\\align " << string_align[h] << ' ';
}
}
+
+
+void setParagraphParams(BufferView & bv, string const & data)
+{
+ istringstream is(STRCONV(data));
+ LyXLex lex(0,0);
+ lex.setStream(is);
+
+ ParagraphParameters params;
+ params.read(lex);
+
+ LyXText * text = bv.getLyXText();
+ text->setParagraph(params.lineTop(),
+ params.lineBottom(),
+ params.pagebreakTop(),
+ params.pagebreakBottom(),
+ params.spaceTop(),
+ params.spaceBottom(),
+ params.spacing(),
+ params.align(),
+ params.labelWidthString(),
+ params.noindent());
+
+ // Actually apply these settings
+ bv.update(text, BufferView::SELECT);
+
+ bv.owner()->message(_("Paragraph layout set"));
+}
+
+
+void params2string(Paragraph const & par, string & data)
+{
+ // A local copy
+ ParagraphParameters params = par.params();
+
+ // This needs to be done separately
+ params.labelWidthString(par.getLabelWidthString());
+
+ // Alignment
+ LyXLayout_ptr const & layout = par.layout();
+ if (params.align() == LYX_ALIGN_LAYOUT)
+ params.align(layout->align);
+
+ ostringstream os;
+ params.write(os);
+
+ // Is alignment possible
+ os << '\n' << "\\alignpossible " << layout->alignpossible << '\n';
+
+ /// set default alignment
+ os << "\\aligndefault " << layout->align << '\n';
+
+ /// is paragraph in inset
+ os << "\\ininset " << (par.inInset()?1:0) << '\n';
+
+ data = STRCONV(os.str());
+}