#include "gettext.h"
#include "language.h"
#include "latexrunparams.h"
+#include "lyxfont.h"
#include "lyxrc.h"
#include "lyxrow.h"
#include "texrow.h"
using lyx::support::subst;
using std::endl;
-
+using std::string;
using std::ostream;
using std::ostringstream;
Paragraph::Paragraph()
: y(0), pimpl_(new Paragraph::Pimpl(this))
{
- enumdepth = 0;
itemdepth = 0;
params().clear();
}
Paragraph::Paragraph(Paragraph const & lp)
- : y(0), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
+ : y(0), text_(lp.text_), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
{
- enumdepth = 0;
itemdepth = 0;
// this is because of the dummy layout of the paragraphs that
// follow footnotes
lyxerr << "Paragraph::operator=()" << endl;
+ text_ = lp.text_;
+
delete pimpl_;
pimpl_ = new Pimpl(*lp.pimpl_, this);
- enumdepth = lp.enumdepth;
itemdepth = lp.itemdepth;
// this is because of the dummy layout of the paragraphs that
// follow footnotes
}
-bool Paragraph::insetAllowed(InsetOld::Code code)
+bool Paragraph::insetAllowed(InsetOld_code code)
{
//lyxerr << "Paragraph::InsertInsetAllowed" << endl;
if (pimpl_->inset_owner)
}
+namespace {
+
+/* paragraphs inside floats need different alignment tags to avoid
+unwanted space */
+
+bool noTrivlistCentering(UpdatableInset const * inset)
+{
+ if (inset && inset->owner()) {
+ InsetOld::Code const code = inset->owner()->lyxCode();
+ return code == InsetOld::FLOAT_CODE ||
+ code == InsetOld::WRAP_CODE;
+ }
+ return false;
+}
+
+
+string correction(string const & orig)
+{
+ if (orig == "flushleft")
+ return "raggedright";
+ if (orig == "flushright")
+ return "raggedleft";
+ if (orig == "center")
+ return "centering";
+ return orig;
+}
+
+
+string const corrected_env(string const & suffix, string const & env,
+ UpdatableInset const * inset)
+{
+ string output = suffix + "{";
+ if (noTrivlistCentering(inset))
+ output += correction(env);
+ else
+ output += env;
+ return output + "}";
+}
+
+} // namespace anon
+
// This could go to ParagraphParameters if we want to
int Paragraph::startTeXParParams(BufferParams const & bparams,
case LYX_ALIGN_LAYOUT:
case LYX_ALIGN_SPECIAL:
break;
- case LYX_ALIGN_LEFT:
- if (getParLanguage(bparams)->babel() != "hebrew") {
- os << "\\begin{flushleft}";
- column += 17;
- } else {
- os << "\\begin{flushright}";
- column += 18;
- }
+ case LYX_ALIGN_LEFT: {
+ string output;
+ UpdatableInset const * const inset = pimpl_->inset_owner;
+ if (getParLanguage(bparams)->babel() != "hebrew")
+ output = corrected_env("\\begin", "flushleft", inset);
+ else
+ output = corrected_env("\\begin", "flushright", inset);
+ os << output;
+ column += output.size();
break;
- case LYX_ALIGN_RIGHT:
- if (getParLanguage(bparams)->babel() != "hebrew") {
- os << "\\begin{flushright}";
- column += 18;
- } else {
- os << "\\begin{flushleft}";
- column += 17;
- }
+ } case LYX_ALIGN_RIGHT: {
+ string output;
+ UpdatableInset const * const inset = pimpl_->inset_owner;
+ if (getParLanguage(bparams)->babel() != "hebrew")
+ output = corrected_env("\\begin", "flushright", inset);
+ else
+ output = corrected_env("\\begin", "flushleft", inset);
+ os << output;
+ column += output.size();
break;
- case LYX_ALIGN_CENTER:
- os << "\\begin{center}";
- column += 14;
+ } case LYX_ALIGN_CENTER: {
+ string output;
+ output = corrected_env("\\begin", "center", pimpl_->inset_owner);
+ os << output;
+ column += output.size();
break;
}
+ }
return column;
}
case LYX_ALIGN_LAYOUT:
case LYX_ALIGN_SPECIAL:
break;
- case LYX_ALIGN_LEFT:
- if (getParLanguage(bparams)->babel() != "hebrew") {
- os << "\\end{flushleft}";
- column = 15;
- } else {
- os << "\\end{flushright}";
- column = 16;
- }
+ case LYX_ALIGN_LEFT: {
+ string output;
+ UpdatableInset const * const inset = pimpl_->inset_owner;
+ if (getParLanguage(bparams)->babel() != "hebrew")
+ output = corrected_env("\\par\\end", "flushleft", inset);
+ else
+ output = corrected_env("\\par\\end", "flushright", inset);
+ os << output;
+ column += output.size();
break;
- case LYX_ALIGN_RIGHT:
- if (getParLanguage(bparams)->babel() != "hebrew") {
- os << "\\end{flushright}";
- column+= 16;
- } else {
- os << "\\end{flushleft}";
- column = 15;
- }
+ } case LYX_ALIGN_RIGHT: {
+ string output;
+ UpdatableInset const * const inset = pimpl_->inset_owner;
+ if (getParLanguage(bparams)->babel() != "hebrew")
+ output = corrected_env("\\par\\end", "flushright", inset);
+ else
+ output = corrected_env("\\par\\end", "flushleft", inset);
+ os << output;
+ column += output.size();
break;
- case LYX_ALIGN_CENTER:
- os << "\\end{center}";
- column = 12;
+ } case LYX_ALIGN_CENTER: {
+ string output;
+ output = corrected_env("\\par\\end", "center", pimpl_->inset_owner);
+ os << output;
+ column += output.size();
break;
}
+ }
+
return column;
}
LyXLayout_ptr style;
// well we have to check if we are in an inset with unlimited
- // lenght (all in one row) if that is true then we don't allow
+ // length (all in one row) if that is true then we don't allow
// any special options in the paragraph and also we don't allow
// any environment other then "Standard" to be valid!
bool asdefault =
}
-lyx::pos_type Paragraph::size() const
+Paragraph::value_type Paragraph::getChar(pos_type pos) const
{
- return pimpl_->size();
-}
-
+ // This is in the critical path!
+ pos_type const siz = text_.size();
-bool Paragraph::empty() const
-{
- return pimpl_->empty();
-}
+ BOOST_ASSERT(pos <= siz);
+ if (pos == siz) {
+ lyxerr << "getChar() on pos " << pos << " in par id "
+ << id() << " of size " << siz
+ << " is a bit silly !" << endl;
+ return '\0';
+ }
-Paragraph::value_type Paragraph::getChar(pos_type pos) const
-{
- return pimpl_->getChar(pos);
+ return text_[pos];
}
void Paragraph::clearContents()
{
- pimpl_->clear();
+ text_.clear();
}
+
void Paragraph::setChar(pos_type pos, value_type c)
{
- pimpl_->setChar(pos, c);
+ text_[pos] = c;
}