2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file ParagraphParameters.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-03-06 14:07:14 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "ParagraphParameters.h"
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2003-03-13 13:56:25 +00:00
|
|
|
|
#include "gettext.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXLayout.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXText.h"
|
|
|
|
|
#include "Paragraph.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "tex-strings.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
|
2003-03-12 07:39:17 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
|
|
|
|
#include <sstream>
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::rtrim;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2003-03-12 06:53:49 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
static int findToken(char const * const str[], string const & search_token)
|
2004-08-20 13:06:33 +00:00
|
|
|
|
{
|
2006-04-20 09:55:45 +00:00
|
|
|
|
return search_token == "default" ?
|
|
|
|
|
0 :
|
2006-10-21 00:16:43 +00:00
|
|
|
|
support::findToken(str, search_token);
|
2004-08-20 13:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-06 14:07:14 +00:00
|
|
|
|
|
|
|
|
|
ParagraphParameters::ParagraphParameters()
|
2004-03-25 09:16:36 +00:00
|
|
|
|
: noindent_(false),
|
|
|
|
|
start_of_appendix_(false), appendix_(false),
|
|
|
|
|
align_(LYX_ALIGN_LAYOUT), depth_(0)
|
|
|
|
|
{}
|
2001-03-06 14:07:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::clear()
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
operator=(ParagraphParameters());
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
depth_type ParagraphParameters::depth() const
|
2003-09-06 20:32:37 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return depth_;
|
2003-09-06 20:32:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-06 14:07:14 +00:00
|
|
|
|
bool ParagraphParameters::sameLayout(ParagraphParameters const & pp) const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return align_ == pp.align_
|
|
|
|
|
&& spacing_ == pp.spacing_
|
|
|
|
|
&& noindent_ == pp.noindent_
|
|
|
|
|
&& depth_ == pp.depth_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spacing const & ParagraphParameters::spacing() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return spacing_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::spacing(Spacing const & s)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
spacing_ = s;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ParagraphParameters::noindent() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return noindent_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::noindent(bool ni)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
noindent_ = ni;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXAlignment ParagraphParameters::align() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return align_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::align(LyXAlignment la)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
align_ = la;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void ParagraphParameters::depth(depth_type d)
|
2001-03-06 14:07:14 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
depth_ = d;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ParagraphParameters::startOfAppendix() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return start_of_appendix_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::startOfAppendix(bool soa)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
start_of_appendix_ = soa;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ParagraphParameters::appendix() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return appendix_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::appendix(bool a)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
appendix_ = a;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-20 19:26:23 +00:00
|
|
|
|
docstring const & ParagraphParameters::labelString() const
|
2001-03-06 14:07:14 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return labelstring_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-20 19:26:23 +00:00
|
|
|
|
void ParagraphParameters::labelString(docstring const & ls)
|
2001-03-06 14:07:14 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
labelstring_ = ls;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-20 19:26:23 +00:00
|
|
|
|
docstring const & ParagraphParameters::labelWidthString() const
|
2001-03-06 14:07:14 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return labelwidthstring_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-20 19:26:23 +00:00
|
|
|
|
void ParagraphParameters::labelWidthString(docstring const & lws)
|
2001-03-06 14:07:14 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
labelwidthstring_ = lws;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-08 12:58:16 +00:00
|
|
|
|
|
|
|
|
|
LyXLength const & ParagraphParameters::leftIndent() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return leftindent_;
|
2002-05-08 12:58:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::leftIndent(LyXLength const & li)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
leftindent_ = li;
|
2002-05-08 12:58:16 +00:00
|
|
|
|
}
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void ParagraphParameters::read(Lexer & lex)
|
2003-03-12 06:53:49 +00:00
|
|
|
|
{
|
2003-03-12 07:39:17 +00:00
|
|
|
|
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") {
|
2004-10-05 12:56:22 +00:00
|
|
|
|
lex.next();
|
2003-03-12 07:39:17 +00:00
|
|
|
|
LyXLength value(lex.getString());
|
|
|
|
|
leftIndent(value);
|
|
|
|
|
} 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,
|
2005-01-06 13:48:13 +00:00
|
|
|
|
lex.getString()));
|
2003-03-12 07:39:17 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.printError("Unknown spacing token: '$$Token'");
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\align") {
|
2004-08-20 13:06:33 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
int tmpret = findToken(string_align, lex.getString());
|
2003-03-12 07:39:17 +00:00
|
|
|
|
if (tmpret == -1)
|
|
|
|
|
++tmpret;
|
2003-03-12 11:22:53 +00:00
|
|
|
|
align(LyXAlignment(1 << tmpret));
|
2003-03-12 07:39:17 +00:00
|
|
|
|
} else if (token == "\\labelwidthstring") {
|
|
|
|
|
lex.eatLine();
|
2006-10-20 19:26:23 +00:00
|
|
|
|
labelWidthString(lex.getDocString());
|
2003-03-12 07:39:17 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-12 06:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::write(ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
// Maybe the paragraph has special spacing
|
2005-01-06 16:52:08 +00:00
|
|
|
|
spacing().writeFile(os, true);
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
|
|
|
|
// The labelwidth string used in lists.
|
|
|
|
|
if (!labelWidthString().empty())
|
2005-01-06 16:52:08 +00:00
|
|
|
|
os << "\\labelwidthstring "
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< to_utf8(labelWidthString()) << '\n';
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
|
|
|
|
// Start of appendix?
|
|
|
|
|
if (startOfAppendix())
|
2005-01-06 16:52:08 +00:00
|
|
|
|
os << "\\start_of_appendix\n";
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
|
|
|
|
// Noindent?
|
|
|
|
|
if (noindent())
|
2005-01-06 16:52:08 +00:00
|
|
|
|
os << "\\noindent\n";
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
|
|
|
|
// Do we have a manual left indent?
|
|
|
|
|
if (!leftIndent().zero())
|
2005-01-06 16:52:08 +00:00
|
|
|
|
os << "\\leftindent " << leftIndent().asString() << '\n';
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
|
|
|
|
// Alignment?
|
|
|
|
|
if (align() != LYX_ALIGN_LAYOUT) {
|
|
|
|
|
int h = 0;
|
|
|
|
|
switch (align()) {
|
|
|
|
|
case LYX_ALIGN_LEFT: h = 1; break;
|
|
|
|
|
case LYX_ALIGN_RIGHT: h = 2; break;
|
|
|
|
|
case LYX_ALIGN_CENTER: h = 3; break;
|
|
|
|
|
default: h = 0; break;
|
|
|
|
|
}
|
2005-01-06 16:52:08 +00:00
|
|
|
|
os << "\\align " << string_align[h] << '\n';
|
2003-03-12 06:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-13 13:56:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2005-01-06 16:52:08 +00:00
|
|
|
|
os << "\\alignpossible " << layout->alignpossible << '\n';
|
2003-03-13 13:56:25 +00:00
|
|
|
|
|
|
|
|
|
/// set default alignment
|
|
|
|
|
os << "\\aligndefault " << layout->align << '\n';
|
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
/// paragraph is always in inset. This is redundant.
|
|
|
|
|
os << "\\ininset " << 1 << '\n';
|
2003-03-13 13:56:25 +00:00
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
data = os.str();
|
2003-03-13 13:56:25 +00:00
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
bool operator==(ParagraphParameeters const & ps1,
|
|
|
|
|
ParagraphParameeters const & ps2)
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
ps1.spacing == ps2.spacing
|
|
|
|
|
&& ps1.noindent == ps2.noindent
|
|
|
|
|
&& ps1.align == ps2.align
|
|
|
|
|
&& ps1.depth == ps2.depth
|
|
|
|
|
&& ps1.start_of_appendix == ps2.start_of_appendix
|
|
|
|
|
&& ps1.appendix == ps2.appendix
|
|
|
|
|
&& ps1.labelstring == ps2.labelstring
|
|
|
|
|
&& ps1.labelwidthstring == ps2.labelwidthstring
|
|
|
|
|
&& ps1.leftindent == ps2.leftindent;
|
|
|
|
|
}
|
|
|
|
|
*/
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|