#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))
+ : y(0), height(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), height(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)
else
layoutfont = lout->font;
- LyXFont tmpfont = getFontSettings(bparams, pos);
- tmpfont.realize(layoutfont);
- tmpfont.realize(outerfont);
- tmpfont.realize(bparams.getLyXTextClass().defaultfont());
+ LyXFont font = getFontSettings(bparams, pos);
+ font.realize(layoutfont);
+ font.realize(outerfont);
+ font.realize(bparams.getLyXTextClass().defaultfont());
- return tmpfont;
+ return font;
}
/// Returns the height of the highest font in range
-LyXFont::FONT_SIZE
+LyXFont_size
Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
- LyXFont::FONT_SIZE const def_size) const
+ LyXFont_size def_size) const
{
if (pimpl_->fontlist.empty())
return def_size;
BOOST_ASSERT(pos <= size());
// First, reduce font against layout/label font
- // Update: The SetCharFont() routine in text2.C already
+ // Update: The setCharFont() routine in text2.C already
// reduces font, so we don't need to do that here. (Asger)
// No need to simplify this because it will disappear
// in a new kernel. (Asger)
// Unroll the first two cycles of the loop
// and remember the previous character to
- // remove unnecessary GetChar() calls
+ // remove unnecessary getChar() calls
pos_type i = 0;
if (i < size() && !isNewline(i)) {
++i;
}
+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 =
}
+namespace {
+
+/// return true if the char is a meta-character for an inset
+inline
+bool IsInsetChar(char c)
+{
+ return (c == Paragraph::META_INSET);
+}
+
+} // namespace anon
+
bool Paragraph::isHfill(pos_type pos) const
bool Paragraph::isWord(pos_type pos) const
{
- return IsWordChar(getChar(pos)) ;
+ unsigned char const c = getChar(pos);
+ return !(IsSeparatorChar(c)
+ || IsKommaChar(c)
+ || IsInsetChar(c));
}
getInset(i)->ascii(buffer, os);
}
- return STRCONV(os.str());
+ return os.str();
}
}
-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();
+ BOOST_ASSERT(pos <= siz);
-bool Paragraph::empty() const
-{
- return pimpl_->empty();
-}
-
+ 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;
}
return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
return false;
}
+
+
+RowList::iterator Paragraph::getRow(pos_type pos)
+{
+ RowList::iterator rit = rows.end();
+ RowList::iterator const begin = rows.begin();
+
+ for (--rit; rit != begin && rit->pos() > pos; --rit)
+ ;
+
+ return rit;
+}