RowPainter::RowPainter(BufferView const & bv,
LyXText const & text, RowList::iterator rit)
- : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit), par_(*rit->par())
+ : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit), pit_(rit->par())
{}
/// "temporary"
LyXFont const RowPainter::getFont(pos_type pos) const
{
- Paragraph * perverted_par = const_cast<Paragraph *>(&par_);
- return text_.getFont(bv_.buffer(), perverted_par, pos);
+ return text_.getFont(bv_.buffer(), pit_, pos);
}
int RowPainter::singleWidth(lyx::pos_type pos) const
{
- Paragraph * par(const_cast<Paragraph*>(&par_));
- return text_.singleWidth(par, pos);
+ return text_.singleWidth(pit_, pos);
}
int RowPainter::singleWidth(lyx::pos_type pos, char c) const
{
- Paragraph * par(const_cast<Paragraph*>(&par_));
- return text_.singleWidth(par, pos, c);
+ return text_.singleWidth(pit_, pos, c);
}
LyXFont const RowPainter::getLabelFont() const
{
- Paragraph * par(const_cast<Paragraph*>(&par_));
- return text_.getLabelFont(bv_.buffer(), par);
+ return text_.getLabelFont(bv_.buffer(), &*pit_);
}
char const RowPainter::transformChar(char c, lyx::pos_type pos) const
{
- Paragraph * par(const_cast<Paragraph*>(&par_));
- return text_.transformChar(c, par, pos);
+ return text_.transformChar(c, *pit_, pos);
}
void RowPainter::paintInset(pos_type const pos)
{
- Inset * inset = const_cast<Inset*>(par_.getInset(pos));
+ Inset * inset = const_cast<Inset*>(pit_->getInset(pos));
lyx::Assert(inset);
string str;
// first char
- char c = par_.getChar(pos);
+ char c = pit_->getChar(pos);
str += c;
++vpos;
int dx = 0;
for (pos_type i = pos - 1; i >= 0; --i) {
- c = par_.getChar(i);
+ c = pit_->getChar(i);
if (!Encodings::IsComposeChar_hebrew(c)) {
if (IsPrintableNonspace(c)) {
int const width2 =
string str;
// first char
- char c = par_.getChar(pos);
+ char c = pit_->getChar(pos);
c = transformChar(c, pos);
str +=c;
++vpos;
int const width = font_metrics::width(c, font);
int dx = 0;
- for (pos_type i = pos-1; i >= 0; --i) {
- c = par_.getChar(i);
+ for (pos_type i = pos - 1; i >= 0; --i) {
+ c = pit_->getChar(i);
if (!Encodings::IsComposeChar_arabic(c)) {
if (IsPrintableNonspace(c)) {
int const width2 =
// first character
string str;
- str += par_.getChar(pos);
+ str += pit_->getChar(pos);
if (arabic) {
unsigned char c = str[0];
str[0] = transformChar(c, pos);
}
- bool prev_struckout(isDeletedText(par_, pos));
- bool prev_newtext(isInsertedText(par_, pos));
+ bool prev_struckout(isDeletedText(*pit_, pos));
+ bool prev_newtext(isInsertedText(*pit_, pos));
++vpos;
// collect as much similar chars as we can
while (vpos <= last && (pos = text_.vis2log(vpos)) >= 0) {
- char c = par_.getChar(pos);
+ char c = pit_->getChar(pos);
if (!IsPrintableNonspace(c))
break;
- if (prev_struckout != isDeletedText(par_, pos))
+ if (prev_struckout != isDeletedText(*pit_, pos))
break;
- if (prev_newtext != isInsertedText(par_, pos))
+ if (prev_newtext != isInsertedText(*pit_, pos))
break;
if (arabic && Encodings::IsComposeChar_arabic(c))
float const orig_x = x_;
- char const c = par_.getChar(pos);
+ char const c = pit_->getChar(pos);
if (IsInsetChar(c)) {
paintInset(pos);
void RowPainter::paintSelection()
{
- bool const is_rtl = par_.isRightToLeftPar(bv_.buffer()->params);
+ bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
// the current selection
int const startx = text_.selection.start.x();
if ((startrow != row_ && !is_rtl) || (endrow != row_ && is_rtl))
pain_.fillRectangle(xo_, yo_, int(x_), row_->height(), LColor::selection);
- pos_type const body_pos = par_.beginningOfBody();
+ pos_type const body_pos = pit_->beginningOfBody();
pos_type const last = lastPrintablePos(text_, row_);
float tmpx = x_;
pos_type pos = text_.vis2log(vpos);
float const old_tmpx = tmpx;
if (body_pos > 0 && pos == body_pos - 1) {
- LyXLayout_ptr const & layout = par_.layout();
+ LyXLayout_ptr const & layout = pit_->layout();
LyXFont const lfont = getLabelFont();
tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
- if (par_.isLineSeparator(body_pos - 1))
+ if (pit_->isLineSeparator(body_pos - 1))
tmpx -= singleWidth(body_pos - 1);
}
tmpx += label_hfill_;
}
- else if (par_.isSeparator(pos)) {
+ else if (pit_->isSeparator(pos)) {
tmpx += singleWidth(pos);
if (pos >= body_pos)
tmpx += separator_;
pos_type const start = row_->pos();
pos_type const end = lastPrintablePos(text_, row_);
- if (!par_.isChanged(start, end))
+ if (!pit_->isChanged(start, end))
return;
int const height = (boost::next(row_) != text_.rows().end()
void RowPainter::paintAppendix()
{
- if (!par_.params().appendix())
+ if (!pit_->params().appendix())
return;
// FIXME: can be just width_ ?
int y = yo_;
- if (par_.params().startOfAppendix())
+ if (pit_->params().startOfAppendix())
y += 2 * defaultRowHeight();
pain_.line(1, y, 1, yo_ + row_->height(), LColor::appendix);
void RowPainter::paintDepthBar()
{
- Paragraph::depth_type const depth = par_.getDepth();
+ Paragraph::depth_type const depth = pit_->getDepth();
if (depth <= 0)
return;
void RowPainter::paintFirst()
{
- ParagraphParameters const & parparams = par_.params();
+ ParagraphParameters const & parparams = pit_->params();
int y_top = 0;
Buffer const * buffer = bv_.buffer();
- LyXLayout_ptr const & layout = par_.layout();
+ LyXLayout_ptr const & layout = pit_->layout();
if (buffer->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
- if (par_.previous()) {
+ if (pit_->previous()) {
if (layout->latextype == LATEX_PARAGRAPH
- && !par_.getDepth()) {
+ && !pit_->getDepth()) {
y_top += buffer->params.getDefSkip().inPixels(bv_);
} else {
LyXLayout_ptr const & playout =
- par_.previous()->layout();
+ boost::prior(pit_)->layout();
if (playout->latextype == LATEX_PARAGRAPH
- && !par_.previous()->getDepth()) {
+ && !boost::prior(pit_)->getDepth()) {
// is it right to use defskip here, too? (AS)
y_top += buffer->params.getDefSkip().inPixels(bv_);
}
y_top += asc;
}
- bool const is_rtl = par_.isRightToLeftPar(bv_.buffer()->params);
+ bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
// should we print a label?
if (layout->labeltype >= LABEL_STATIC
&& (layout->labeltype != LABEL_STATIC
|| layout->latextype != LATEX_ENVIRONMENT
- || par_.isFirstInSequence())) {
+ || pit_->isFirstInSequence())) {
LyXFont font = getLabelFont();
- if (!par_.getLabelstring().empty()) {
+ if (!pit_->getLabelstring().empty()) {
float x = x_;
- string const str = par_.getLabelstring();
+ string const str = pit_->getLabelstring();
// this is special code for the chapter layout. This is
// printed in an extra row and has a pagebreak at
// the labels at the top of an environment.
// More or less for bibliography
- } else if (par_.isFirstInSequence() &&
+ } else if (pit_->isFirstInSequence() &&
(layout->labeltype == LABEL_TOP_ENVIRONMENT ||
layout->labeltype == LABEL_BIBLIO ||
layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
LyXFont font = getLabelFont();
- if (!par_.getLabelstring().empty()) {
- string const str = par_.getLabelstring();
+ if (!pit_->getLabelstring().empty()) {
+ string const str = pit_->getLabelstring();
float spacing_val = 1.0;
if (!parparams.spacing().isDefault()) {
spacing_val = parparams.spacing().getValue();
void RowPainter::paintLast()
{
- ParagraphParameters const & parparams = par_.params();
+ ParagraphParameters const & parparams = pit_->params();
int y_bottom = row_->height() - 1;
// the bottom margin
if (parparams.lineBottom()) {
LyXFont font(LyXFont::ALL_SANE);
int const asc = font_metrics::ascent('x',
- getFont(max(pos_type(0), par_.size() - 1)));
+ getFont(max(pos_type(0), pit_->size() - 1)));
y_bottom -= asc;
y_bottom -= asc;
}
- bool const is_rtl = par_.isRightToLeftPar(bv_.buffer()->params);
- int const endlabel = par_.getEndLabel();
+ bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
+ int const endlabel = pit_->getEndLabel();
// draw an endlabel
switch (endlabel) {
#else
LyXFont font = getLabelFont();
#endif
- string const & str = par_.layout()->endlabelstring();
+ string const & str = pit_->layout()->endlabelstring();
int const x = is_rtl ?
int(x_) - font_metrics::width(str, font)
: ww - text_.rightMargin(*bv_.buffer(), *row_) - row_->fill();
void RowPainter::paintText()
{
pos_type const last = lastPrintablePos(text_, row_);
- pos_type body_pos = par_.beginningOfBody();
+ pos_type body_pos = pit_->beginningOfBody();
if (body_pos > 0 &&
(body_pos - 1 > last ||
- !par_.isLineSeparator(body_pos - 1))) {
+ !pit_->isLineSeparator(body_pos - 1))) {
body_pos = 0;
}
- LyXLayout_ptr const & layout = par_.layout();
+ LyXLayout_ptr const & layout = pit_->layout();
bool running_strikeout = false;
bool is_struckout = false;
break;
pos_type pos = text_.vis2log(vpos);
- if (pos >= par_.size()) {
+ if (pos >= pit_->size()) {
++vpos;
continue;
}
continue;
}
- is_struckout = isDeletedText(par_, pos);
+ is_struckout = isDeletedText(*pit_, pos);
if (is_struckout && !running_strikeout) {
running_strikeout = true;
last_strikeout_x = x_;
}
- bool const highly_editable_inset = par_.isInset(pos)
- && isHighlyEditableInset(par_.getInset(pos));
+ bool const highly_editable_inset = pit_->isInset(pos)
+ && isHighlyEditableInset(pit_->getInset(pos));
// if we reach the end of a struck out range, paint it
// we also don't paint across things like tables
- singleWidth(body_pos - 1);
}
- if (par_.isHfill(pos)) {
+ if (pit_->isHfill(pos)) {
x_ += 1;
int const y0 = yo_ + row_->baseline();
}
x_ += 2;
++vpos;
- } else if (par_.isSeparator(pos)) {
+ } else if (pit_->isSeparator(pos)) {
x_ += singleWidth(pos);
if (pos >= body_pos)
x_ += separator_;
}
-unsigned char LyXText::transformChar(unsigned char c, Paragraph * par,
- pos_type pos) const
+#warning FIXME This function seems to belong outside of LyxText.
+unsigned char LyXText::transformChar(unsigned char c, Paragraph const & par,
+ pos_type pos) const
{
if (!Encodings::is_arabic(c))
if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && IsDigit(c))
else
return c;
- unsigned char const prev_char = pos > 0 ? par->getChar(pos-1) : ' ';
+ unsigned char const prev_char = pos > 0 ? par.getChar(pos - 1) : ' ';
unsigned char next_char = ' ';
- for (pos_type i = pos+1; i < par->size(); ++i)
- if (!Encodings::IsComposeChar_arabic(par->getChar(i))) {
- next_char = par->getChar(i);
+ for (pos_type i = pos + 1; i < par.size(); ++i)
+ if (!Encodings::IsComposeChar_arabic(par.getChar(i))) {
+ next_char = par.getChar(i);
break;
}
//
// Lgb
-#warning FIXME Convert this to ParagraphList::iterator
-int LyXText::singleWidth(Paragraph * par,
- pos_type pos) const
+int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
{
- if (pos >= par->size())
+ if (pos >= pit->size())
return 0;
- char const c = par->getChar(pos);
- return singleWidth(par, pos, c);
+ char const c = pit->getChar(pos);
+ return singleWidth(pit, pos, c);
}
-#warning FIXME Convert this to ParagraphList::iterator
-int LyXText::singleWidth(Paragraph * par,
+int LyXText::singleWidth(ParagraphList::iterator pit,
pos_type pos, char c) const
{
- if (pos >= par->size())
+ if (pos >= pit->size())
return 0;
- LyXFont const font = getFont(bv()->buffer(), par, pos);
+ LyXFont const font = getFont(bv()->buffer(), pit, pos);
// The most common case is handled first (Asger)
if (IsPrintable(c)) {
if (Encodings::IsComposeChar_arabic(c))
return 0;
else
- c = transformChar(c, par, pos);
+ c = transformChar(c, *pit, pos);
} else if (font.language()->lang() == "hebrew" &&
Encodings::IsComposeChar_hebrew(c))
return 0;
}
if (c == Paragraph::META_INSET) {
- Inset * tmpinset = par->getInset(pos);
+ Inset * tmpinset = pit->getInset(pos);
if (tmpinset) {
if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
// Because of the representation as vertical lines
char const c = pit->getChar(i);
- int thiswidth = singleWidth(&*pit, i, c);
+ int thiswidth = singleWidth(pit, i, c);
// add the auto-hfill from label end to the body
if (body_pos && i == body_pos) {
thiswidth += font_metrics::width(layout->labelsep,
getLabelFont(bv()->buffer(), &*pit));
if (pit->isLineSeparator(i - 1))
- thiswidth -= singleWidth(&*pit, i - 1);
+ thiswidth -= singleWidth(pit, i - 1);
}
x += thiswidth;
if (body_pos > 0 && i == body_pos) {
w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), &*pit));
if (pit->isLineSeparator(i - 1))
- w -= singleWidth(&*pit, i - 1);
+ w -= singleWidth(pit, i - 1);
int left_margin = labelEnd(*row);
if (w < left_margin)
w = left_margin;
}
- w += singleWidth(&*pit, i);
+ w += singleWidth(pit, i);
++i;
}
if (body_pos > 0 && body_pos > last) {
w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), &*pit));
if (last >= 0 && pit->isLineSeparator(last))
- w -= singleWidth(&*pit, last);
+ w -= singleWidth(pit, last);
int const left_margin = labelEnd(*row);
if (w < left_margin)
w = left_margin;
int w = 0;
pos_type i = row.pos();
while (i <= last) {
- w += singleWidth(&*row.par(), i);
+ w += singleWidth(row.par(), i);
++i;
}
maxdesc = max(maxdesc, desc);
}
} else {
- maxwidth += singleWidth(&*rit->par(), pos);
+ maxwidth += singleWidth(rit->par(), pos);
}
}
}
// smaller. (Asger)
// If position is -1, we get the layout font of the paragraph.
// If position is -2, we get the font of the manual label of the paragraph.
-LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
+LyXFont const LyXText::getFont(Buffer const * buf, ParagraphList::iterator pit,
pos_type pos) const
{
lyx::Assert(pos >= 0);
- LyXLayout_ptr const & layout = par->layout();
+ LyXLayout_ptr const & layout = pit->layout();
// We specialize the 95% common case:
- if (!par->getDepth()) {
+ if (!pit->getDepth()) {
if (layout->labeltype == LABEL_MANUAL
- && pos < par->beginningOfBody()) {
+ && pos < pit->beginningOfBody()) {
// 1% goes here
- LyXFont f = par->getFontSettings(buf->params, pos);
- if (par->inInset())
- par->inInset()->getDrawFont(f);
+ LyXFont f = pit->getFontSettings(buf->params, pos);
+ if (pit->inInset())
+ pit->inInset()->getDrawFont(f);
return f.realize(layout->reslabelfont);
} else {
- LyXFont f = par->getFontSettings(buf->params, pos);
- if (par->inInset())
- par->inInset()->getDrawFont(f);
+ LyXFont f = pit->getFontSettings(buf->params, pos);
+ if (pit->inInset())
+ pit->inInset()->getDrawFont(f);
return f.realize(layout->resfont);
}
}
LyXFont layoutfont;
- if (pos < par->beginningOfBody()) {
+ if (pos < pit->beginningOfBody()) {
// 1% goes here
layoutfont = layout->labelfont;
} else {
layoutfont = layout->font;
}
- LyXFont tmpfont = par->getFontSettings(buf->params, pos);
+ LyXFont tmpfont = pit->getFontSettings(buf->params, pos);
tmpfont.realize(layoutfont);
- if (par->inInset())
- par->inInset()->getDrawFont(tmpfont);
+ if (pit->inInset())
+ pit->inInset()->getDrawFont(tmpfont);
- return realizeFont(tmpfont, buf, par);
+ return realizeFont(tmpfont, buf, &*pit);
}
Paragraph const * ep)
{
RowList::iterator tmprit = cur.row();
- ParagraphList::iterator begpit = cur.row()->par();
ParagraphList::iterator endpit(const_cast<Paragraph*>(ep));
int y = cur.y() - tmprit->baseline();
getLabelFont(bv()->buffer(),
&*rit->par()));
if (rit->par()->isLineSeparator(body_pos - 1))
- x -= singleWidth(&*rit->par(), body_pos - 1);
+ x -= singleWidth(rit->par(), body_pos - 1);
}
if (hfillExpansion(*this, rit, pos)) {
- x += singleWidth(&*rit->par(), pos);
+ x += singleWidth(rit->par(), pos);
if (pos >= body_pos)
x += fill_hfill;
else
x += fill_label_hfill;
} else if (rit->par()->isSeparator(pos)) {
- x += singleWidth(&*rit->par(), pos);
+ x += singleWidth(rit->par(), pos);
if (pos >= body_pos)
x += fill_separator;
} else
- x += singleWidth(&*rit->par(), pos);
+ x += singleWidth(rit->par(), pos);
}
return x;
}
font_metrics::width(layout->labelsep,
getLabelFont(bv()->buffer(), &*rit->par()));
if (rit->par()->isLineSeparator(body_pos - 1))
- tmpx -= singleWidth(&*rit->par(), body_pos - 1);
+ tmpx -= singleWidth(rit->par(), body_pos - 1);
}
if (hfillExpansion(*this, rit, c)) {
- tmpx += singleWidth(&*rit->par(), c);
+ tmpx += singleWidth(rit->par(), c);
if (c >= body_pos)
tmpx += fill_hfill;
else
tmpx += fill_label_hfill;
} else if (rit->par()->isSeparator(c)) {
- tmpx += singleWidth(&*rit->par(), c);
+ tmpx += singleWidth(rit->par(), c);
if (c >= body_pos)
tmpx+= fill_separator;
} else {
- tmpx += singleWidth(&*rit->par(), c);
+ tmpx += singleWidth(rit->par(), c);
}
++vc;
}
if (rit->pos() <= last && c > last
&& rit->par()->isNewline(last)) {
if (bidi_level(last) % 2 == 0)
- tmpx -= singleWidth(&*rit->par(), last);
+ tmpx -= singleWidth(rit->par(), last);
else
- tmpx += singleWidth(&*rit->par(), last);
+ tmpx += singleWidth(rit->par(), last);
c = last;
}