#include "rowpainter.h"
+#include "Bidi.h"
#include "Buffer.h"
#include "CoordCache.h"
#include "Cursor.h"
class RowPainter {
public:
/// initialise and run painter
- RowPainter(PainterInfo & pi, LyXText const & text,
- pit_type pit, Row const & row, int x, int y);
+ RowPainter(PainterInfo & pi, Text const & text,
+ pit_type pit, Row const & row, Bidi & bidi, int x, int y);
// paint various parts
void paintAppendix();
int maxWidth() { return max_width_; }
private:
- void paintForeignMark(double orig_x, LyXFont const & font, int desc = 0);
- void paintHebrewComposeChar(pos_type & vpos, LyXFont const & font);
- void paintArabicComposeChar(pos_type & vpos, LyXFont const & font);
- void paintChars(pos_type & vpos, LyXFont const & font,
+ void paintForeignMark(double orig_x, Font const & font, int desc = 0);
+ void paintHebrewComposeChar(pos_type & vpos, Font const & font);
+ void paintArabicComposeChar(pos_type & vpos, Font const & font);
+ void paintChars(pos_type & vpos, Font const & font,
bool hebrew, bool arabic);
int paintAppendixStart(int y);
void paintFromPos(pos_type & vpos);
- void paintInset(pos_type const pos, LyXFont const & font);
+ void paintInset(pos_type const pos, Font const & font);
/// return left margin
int leftMargin() const;
/// return the label font for this row
- LyXFont const getLabelFont() const;
+ Font const getLabelFont() const;
/// bufferview to paint on
BufferView & bv_;
/// Painter to use
Painter & pain_;
- /// LyXText for the row
- LyXText const & text_;
+ /// Text for the row
+ Text const & text_;
TextMetrics & text_metrics_;
ParagraphList const & pars_;
ParagraphMetrics const & pm_;
int max_width_;
+ /// bidi cache, comes from outside the rowpainter because
+ /// rowpainters are normally created in a for loop and there only
+ /// one of them is active at a time.
+ Bidi & bidi_;
+
/// is row erased? (change tracking)
bool erased_;
RowPainter::RowPainter(PainterInfo & pi,
- LyXText const & text, pit_type pit, Row const & row, int x, int y)
+ Text const & text, pit_type pit, Row const & row, Bidi & bidi, int x, int y)
: bv_(*pi.base.bv), pain_(pi.pain), text_(text),
text_metrics_(pi.base.bv->textMetrics(&text)),
pars_(text.paragraphs()),
row_(row), pit_(pit), par_(text.paragraphs()[pit]),
pm_(text_metrics_.parMetrics(pit)),
max_width_(bv_.workWidth()),
- erased_(pi.erased_),
+ bidi_(bidi), erased_(pi.erased_),
xo_(x), yo_(y), width_(text_metrics_.width())
{
RowMetrics m = text_metrics_.computeRowMetrics(pit_, row_);
+ bidi_.computeTables(par_, *bv_.buffer(), row_);
x_ = m.x + xo_;
//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
}
-LyXFont const RowPainter::getLabelFont() const
+Font const RowPainter::getLabelFont() const
{
return text_.getLabelFont(*bv_.buffer(), par_);
}
// This draws green lines around each inset.
-void RowPainter::paintInset(pos_type const pos, LyXFont const & font)
+void RowPainter::paintInset(pos_type const pos, Font const & font)
{
Inset const * inset = par_.getInset(pos);
BOOST_ASSERT(inset);
pi.base.font = inset->noFontChange() ?
bv_.buffer()->params().getFont() :
font;
- pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0);
+ pi.ltr_pos = (bidi_.level(pos) % 2 == 0);
pi.erased_ = erased_ || par_.isDeleted(pos);
#ifdef DEBUG_METRICS
int const x1 = int(x_);
int const w = max_witdh_ - leftMargin() - right_margin;
MetricsInfo mi(&bv_, font, w);
inset->metrics(mi, dim);
- if (inset->width() > dim.wid)
+ if (inset->width() > dim.wid)
lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
<< " draw width " << inset->width()
<< "> metrics width " << dim.wid << "." << std::endl;
- if (inset->ascent() > dim.asc)
+ if (inset->ascent() > dim.asc)
lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
<< " draw ascent " << inset->ascent()
<< "> metrics ascent " << dim.asc << "." << std::endl;
- if (inset->descent() > dim.des)
+ if (inset->descent() > dim.des)
lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
<< " draw ascent " << inset->descent()
<< "> metrics descent " << dim.des << "." << std::endl;
}
-void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font)
+void RowPainter::paintHebrewComposeChar(pos_type & vpos, Font const & font)
{
- pos_type pos = text_.bidi.vis2log(vpos);
+ pos_type pos = bidi_.vis2log(vpos);
docstring str;
}
-void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
+void RowPainter::paintArabicComposeChar(pos_type & vpos, Font const & font)
{
- pos_type pos = text_.bidi.vis2log(vpos);
+ pos_type pos = bidi_.vis2log(vpos);
docstring str;
// first char
}
-void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
+void RowPainter::paintChars(pos_type & vpos, Font const & font,
bool hebrew, bool arabic)
{
// This method takes up 70% of time when typing
- pos_type pos = text_.bidi.vis2log(vpos);
+ pos_type pos = bidi_.vis2log(vpos);
pos_type const end = row_.endpos();
FontSpan const font_span = par_.fontSpan(pos);
Change::Type const prev_change = par_.lookupChange(pos).type;
if (arabic) {
char_type c = str[0];
+ if (c == '(')
+ c = ')';
+ else if (c == ')')
+ c = '(';
str[0] = par_.transformChar(c, pos);
}
// collect as much similar chars as we can
for (++vpos ; vpos < end ; ++vpos) {
- pos = text_.bidi.vis2log(vpos);
+ pos = bidi_.vis2log(vpos);
if (pos < font_span.first || pos > font_span.last)
break;
* Arabic characters, but rather paint them one at a time.
* See also http://thread.gmane.org/gmane.editors.lyx.devel/79740
*/
- if (hebrew)
+ if (hebrew)
break;
/* FIXME: these checks are irrelevant, since 'arabic' and
*/
if (arabic) {
+ if (c == '(')
+ c = ')';
+ else if (c == ')')
+ c = '(';
c = par_.transformChar(c, pos);
/* see comment in hebrew, explaining why we break */
break;
docstring s(&str[0], str.size());
if (prev_change != Change::UNCHANGED) {
- LyXFont copy(font);
+ Font copy(font);
if (prev_change == Change::DELETED) {
- copy.setColor(Color::strikeout);
+ copy.setColor(Color::deletedtext);
} else if (prev_change == Change::INSERTED) {
- copy.setColor(Color::newtext);
+ copy.setColor(Color::addedtext);
}
x_ += pain_.text(int(x_), yo_, s, copy);
} else {
}
-void RowPainter::paintForeignMark(double orig_x, LyXFont const & font, int desc)
+void RowPainter::paintForeignMark(double orig_x, Font const & font, int desc)
{
if (!lyxrc.mark_foreign_language)
return;
void RowPainter::paintFromPos(pos_type & vpos)
{
- pos_type const pos = text_.bidi.vis2log(vpos);
- LyXFont orig_font = text_.getFont(*bv_.buffer(), par_, pos);
+ pos_type const pos = bidi_.vis2log(vpos);
+ Font orig_font = text_.getFont(*bv_.buffer(), par_, pos);
double const orig_x = x_;
// special case languages
std::string const & lang = orig_font.language()->lang();
bool const hebrew = lang == "hebrew";
- bool const arabic = lang == "arabic";
+ bool const arabic = lang == "arabic_arabtex" || lang == "arabic_arabi" ||
+ lang == "farsi";
// draw as many chars as we can
if ((!hebrew && !arabic)
void RowPainter::paintAppendix()
{
- if (!par_.params().appendix())
+ // only draw the appendix frame once (for the main text)
+ if (!par_.params().appendix() || !text_.isMainText(*bv_.buffer()))
return;
int y = yo_ - row_.ascent();
int RowPainter::paintAppendixStart(int y)
{
- LyXFont pb_font;
+ Font pb_font;
pb_font.setColor(Color::appendix);
pb_font.decSize();
Buffer const & buffer = *bv_.buffer();
- LyXLayout_ptr const & layout = par_.layout();
+ Layout_ptr const & layout = par_.layout();
if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
if (pit_ != 0) {
&& !par_.getDepth()) {
y_top += buffer.params().getDefSkip().inPixels(bv_);
} else {
- LyXLayout_ptr const & playout = pars_[pit_ - 1].layout();
+ Layout_ptr const & playout = pars_[pit_ - 1].layout();
if (playout->latextype == LATEX_PARAGRAPH
&& !pars_[pit_ - 1].getDepth()) {
// is it right to use defskip here, too? (AS)
|| layout->latextype != LATEX_ENVIRONMENT
|| is_seq)) {
- LyXFont const font = getLabelFont();
+ Font const font = getLabelFont();
FontMetrics const & fm = theFontMetrics(font);
docstring const str = par_.getLabelstring();
(layout->labeltype == LABEL_TOP_ENVIRONMENT ||
layout->labeltype == LABEL_BIBLIO ||
layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
- LyXFont font = getLabelFont();
+ Font font = getLabelFont();
if (!par_.getLabelstring().empty()) {
docstring const str = par_.getLabelstring();
double spacing_val = 1.0;
if (par_.isInserted(par_.size()) || par_.isDeleted(par_.size())) {
FontMetrics const & fm = theFontMetrics(bv_.buffer()->params().getFont());
int const length = fm.maxAscent() / 2;
- Color::color col = par_.isInserted(par_.size()) ? Color::newtext : Color::strikeout;
-
+ Color::color col = par_.isInserted(par_.size()) ? Color::addedtext : Color::deletedtext;
+
pain_.line(int(x_) + 1, yo_ + 2, int(x_) + 1, yo_ + 2 - length, col,
- Painter::line_solid, Painter::line_thick);
+ Painter::line_solid, Painter::line_thick);
pain_.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1, yo_ + 2, col,
- Painter::line_solid, Painter::line_thick);
+ Painter::line_solid, Painter::line_thick);
}
// draw an endlabel
switch (endlabel) {
case END_LABEL_BOX:
case END_LABEL_FILLED_BOX: {
- LyXFont const font = getLabelFont();
+ Font const font = getLabelFont();
FontMetrics const & fm = theFontMetrics(font);
int const size = int(0.75 * fm.maxAscent());
int const y = yo_ - size;
}
case END_LABEL_STATIC: {
- LyXFont font = getLabelFont();
+ Font font = getLabelFont();
FontMetrics const & fm = theFontMetrics(font);
docstring const & str = par_.layout()->endlabelstring();
double const x = is_rtl ?
void RowPainter::paintText()
{
pos_type const end = row_.endpos();
+ // Spaces at logical line breaks in bidi text must be skipped during
+ // painting. However, they may appear visually in the middle
+ // of a row; they must be skipped, wherever they are...
+ // * logically "abc_[HEBREW_\nHEBREW]"
+ // * visually "abc_[_WERBEH\nWERBEH]"
+ pos_type skipped_sep_vpos = -1;
pos_type body_pos = par_.beginOfBody();
if (body_pos > 0 &&
(body_pos > end || !par_.isLineSeparator(body_pos - 1))) {
body_pos = 0;
}
- LyXLayout_ptr const & layout = par_.layout();
+ Layout_ptr const & layout = par_.layout();
bool running_strikeout = false;
bool is_struckout = false;
// Use font span to speed things up, see below
FontSpan font_span;
- LyXFont font;
+ Font font;
Buffer const & buffer = *bv_.buffer();
+ // If the last logical character is a separator, don't paint it, unless
+ // it's in the last row of a paragraph; see skipped_sep_vpos declaration
+ if (end > 0 && end < par_.size() && par_.isSeparator(end - 1))
+ skipped_sep_vpos = bidi_.log2vis(end - 1);
+
for (pos_type vpos = row_.pos(); vpos < end; ) {
if (x_ > bv_.workWidth())
break;
- pos_type const pos = text_.bidi.vis2log(vpos);
+ // Skip the separator at the logical end of the row
+ if (vpos == skipped_sep_vpos) {
+ ++vpos;
+ continue;
+ }
+
+ pos_type const pos = bidi_.vis2log(vpos);
if (pos >= par_.size()) {
++vpos;
// We also don't paint across things like tables
if (running_strikeout && (highly_editable_inset || !is_struckout)) {
// Calculate 1/3 height of the buffer's default font
- FontMetrics const & fm
+ FontMetrics const & fm
= theFontMetrics(bv_.buffer()->params().getFont());
int const middle = yo_ - fm.maxAscent() / 3;
pain_.line(last_strikeout_x, middle, int(x_), middle,
- Color::strikeout, Painter::line_solid, Painter::line_thin);
+ Color::deletedtext, Painter::line_solid, Painter::line_thin);
running_strikeout = false;
}
x_ += 2;
++vpos;
} else if (par_.isSeparator(pos)) {
+ Font orig_font = text_.getFont(*bv_.buffer(), par_, pos);
+ double const orig_x = x_;
x_ += width_pos;
if (pos >= body_pos)
x_ += separator_;
++vpos;
+ paintForeignMark(orig_x, orig_font);
} else {
paintFromPos(vpos);
}
// if we reach the end of a struck out range, paint it
if (running_strikeout) {
// calculate 1/3 height of the buffer's default font
- FontMetrics const & fm
+ FontMetrics const & fm
= theFontMetrics(bv_.buffer()->params().getFont());
int const middle = yo_ - fm.maxAscent() / 3;
pain_.line(last_strikeout_x, middle, int(x_), middle,
- Color::strikeout, Painter::line_solid, Painter::line_thin);
+ Color::deletedtext, Painter::line_solid, Painter::line_thin);
running_strikeout = false;
}
}
bool CursorOnRow(PainterInfo & pi, pit_type const pit,
- RowList::const_iterator rit, LyXText const & text)
+ RowList::const_iterator rit, Text const & text)
{
// Is there a cursor on this row (or inside inset on row)
Cursor & cur = pi.base.bv->cursor();
bool innerCursorOnRow(PainterInfo & pi, pit_type pit,
- RowList::const_iterator rit, LyXText const & text)
+ RowList::const_iterator rit, Text const & text)
{
// Is there a cursor inside an inset on this row, and is this inset
// the only "character" on this row
{
// check whether the current inset is nested in a non-wide inset
Cursor & cur = pi.base.bv->cursor();
- for (int i = cur.depth() - 1; --i >= 0; ) {
+ Inset const * cur_in = &cur.inset();
+ // check all higher nested insets
+ for (size_type i = 1; i < cur.depth(); ++i) {
Inset * const in = &cur[i].inset();
- if (in) {
- InsetText * t =
+ if (in == cur_in)
+ // we reached the level of the current inset, so stop
+ return false;
+ else if (in) {
+ if (in->hasFixedWidth())
+ return true;
+ InsetText * t =
const_cast<InsetText *>(in->asTextInset());
- if (t)
- return !t->wide();
+ if (t && !t->wide())
+ // OK, we are in a non-wide() inset
+ return true;
}
}
return false;
void paintPar
- (PainterInfo & pi, LyXText const & text, pit_type pit, int x, int y,
+ (PainterInfo & pi, Text const & text, pit_type pit, int x, int y,
bool repaintAll)
{
// lyxerr << " paintPar: pit: " << pit << " at y: " << y << endl;
RowList::const_iterator const rb = pm.rows().begin();
RowList::const_iterator const re = pm.rows().end();
+ Bidi bidi;
+
y -= rb->ascent();
size_type rowno = 0;
for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) {
bool cursor_on_row = CursorOnRow(pi, pit, rit, text);
bool in_inset_alone_on_row =
innerCursorOnRow(pi, pit, rit, text);
- bool leftEdgeFixed =
+ bool leftEdgeFixed =
(par.getAlign() == LYX_ALIGN_LEFT ||
par.getAlign() == LYX_ALIGN_BLOCK);
bool inNarrowIns = inNarrowInset(pi);
&& y - rit->ascent() < ww);
// it is not needed to draw on screen if we are not inside.
pi.pain.setDrawingEnabled(inside);
- RowPainter rp(pi, text, pit, *rit, x, y);
+ RowPainter rp(pi, text, pit, *rit, bidi, x, y);
// Clear background of this row
// (if paragraph background was not cleared)
if (!repaintAll &&
- (!(in_inset_alone_on_row && leftEdgeFixed)
+ (!(in_inset_alone_on_row && leftEdgeFixed && !inNarrowIns)
|| row_has_changed)) {
pi.pain.fillRectangle(x, y - rit->ascent(),
rp.maxWidth(), rit->height(),
rp.paintChangeBar();
if (rit == rb)
rp.paintFirst();
- rp.paintText();
+ rp.paintText();
if (rit + 1 == re)
rp.paintLast();
}
{
BOOST_ASSERT(bv.buffer());
Buffer const & buffer = *bv.buffer();
- LyXText & text = buffer.text();
+ Text & text = buffer.text();
bool const select = bv.cursor().selection();
ViewMetricsInfo const & vi = bv.viewMetricsInfo();
-
+
PainterInfo pi(const_cast<BufferView *>(&bv), pain);
// Should the whole screen, including insets, be refreshed?
// FIXME: We should also distinguish DecorationUpdate to avoid text
// and grey out above (should not happen later)
// lyxerr << "par ascent: " << text.getPar(vi.p1).ascent() << endl;
- if (vi.y1 > 0 && vi.update_strategy != SingleParUpdate)
+ if (vi.y1 > 0 && vi.update_strategy == FullScreenUpdate)
pain.fillRectangle(0, 0, bv.workWidth(), vi.y1, Color::bottomarea);
// and possibly grey out below
// lyxerr << "par descent: " << text.getPar(vi.p1).ascent() << endl;
- if (vi.y2 < bv.workHeight() && vi.update_strategy != SingleParUpdate)
+ if (vi.y2 < bv.workHeight() && vi.update_strategy == FullScreenUpdate)
pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - vi.y2, Color::bottomarea);
}
-void paintTextInset(LyXText const & text, PainterInfo & pi, int x, int y)
+void paintTextInset(Text const & text, PainterInfo & pi, int x, int y)
{
// lyxerr << " paintTextInset: y: " << y << endl;
// This flag cannot be set from within same inset:
bool repaintAll = refreshInside;
for (int pit = 0; pit < int(text.paragraphs().size()); ++pit) {
- ParagraphMetrics const & pmi
+ ParagraphMetrics const & pmi
= pi.base.bv->parMetrics(&text, pit);
y += pmi.ascent();
paintPar(pi, text, pit, x, y, repaintAll);