2003-02-26 17:04:10 +00:00
|
|
|
/**
|
2014-07-25 19:55:08 +00:00
|
|
|
* \file RowPainter.cpp
|
2003-02-26 17:04:10 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author various
|
|
|
|
* \author John Levon
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-26 17:04:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2008-03-17 21:11:17 +00:00
|
|
|
#include <algorithm>
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2014-07-25 19:55:08 +00:00
|
|
|
#include "RowPainter.h"
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "CoordCache.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "BufferParams.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
#include "BufferView.h"
|
2007-10-18 15:29:51 +00:00
|
|
|
#include "Changes.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Language.h"
|
2007-09-29 20:02:32 +00:00
|
|
|
#include "Layout.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
|
|
|
#include "Row.h"
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "Paragraph.h"
|
2006-12-29 23:54:48 +00:00
|
|
|
#include "ParagraphMetrics.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2006-12-29 23:54:48 +00:00
|
|
|
#include "TextMetrics.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "VSpace.h"
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetText.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
2010-12-22 00:16:51 +00:00
|
|
|
#include "mathed/InsetMath.h"
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2009-07-19 01:41:47 +00:00
|
|
|
#include "support/gettext.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
#include "support/textutils.h"
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2005-12-30 19:02:52 +00:00
|
|
|
#include <boost/crc.hpp>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
2007-08-28 08:57:13 +00:00
|
|
|
namespace lyx {
|
2003-07-14 17:50:00 +00:00
|
|
|
|
2007-08-28 08:57:13 +00:00
|
|
|
using frontend::Painter;
|
|
|
|
using frontend::FontMetrics;
|
2003-07-28 12:20:42 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
RowPainter::RowPainter(PainterInfo & pi,
|
2013-10-11 14:12:20 +00:00
|
|
|
Text const & text, pit_type pit, Row const & row, int x, int y)
|
2007-08-30 14:26:52 +00:00
|
|
|
: pi_(pi), text_(text),
|
2007-08-30 13:53:02 +00:00
|
|
|
text_metrics_(pi_.base.bv->textMetrics(&text)),
|
2006-12-29 23:54:48 +00:00
|
|
|
pars_(text.paragraphs()),
|
2004-11-30 01:59:49 +00:00
|
|
|
row_(row), pit_(pit), par_(text.paragraphs()[pit]),
|
2013-10-11 14:12:20 +00:00
|
|
|
pm_(text_metrics_.parMetrics(pit)), change_(pi_.change_),
|
2010-12-15 07:12:42 +00:00
|
|
|
xo_(x), yo_(y), width_(text_metrics_.width()),
|
2011-02-20 07:50:28 +00:00
|
|
|
solid_line_thickness_(1.0), solid_line_offset_(1),
|
|
|
|
dotted_line_thickness_(1.0), dotted_line_offset_(2)
|
2003-11-24 16:26:55 +00:00
|
|
|
{
|
2007-08-30 13:53:02 +00:00
|
|
|
bidi_.computeTables(par_, pi_.base.bv->buffer(), row_);
|
2010-12-15 07:12:42 +00:00
|
|
|
|
2011-02-20 07:50:28 +00:00
|
|
|
if (lyxrc.zoom >= 200) {
|
|
|
|
// derive the line thickness from zoom factor
|
|
|
|
// the zoom is given in percent
|
|
|
|
// (increase thickness at 250%, 450% etc.)
|
|
|
|
solid_line_thickness_ = (float)(int((lyxrc.zoom + 50) / 200.0));
|
|
|
|
// adjust line_offset_ too
|
|
|
|
solid_line_offset_ = 1 + int(0.5 * solid_line_thickness_);
|
|
|
|
}
|
2010-12-15 07:12:42 +00:00
|
|
|
if (lyxrc.zoom >= 100) {
|
|
|
|
// derive the line thickness from zoom factor
|
|
|
|
// the zoom is given in percent
|
|
|
|
// (increase thickness at 150%, 250% etc.)
|
2011-02-20 07:50:28 +00:00
|
|
|
dotted_line_thickness_ = (float)(int((lyxrc.zoom + 50) / 100.0));
|
2010-12-15 07:12:42 +00:00
|
|
|
// adjust line_offset_ too
|
2011-02-20 07:50:28 +00:00
|
|
|
dotted_line_offset_ = int(0.5 * dotted_line_thickness_) + 1;
|
2010-12-15 07:12:42 +00:00
|
|
|
}
|
2010-12-13 16:18:37 +00:00
|
|
|
|
2014-12-22 09:36:53 +00:00
|
|
|
x_ = row_.left_margin + xo_;
|
2004-08-14 15:55:22 +00:00
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
|
|
|
|
//row_.dump();
|
|
|
|
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(pit >= 0);
|
|
|
|
LBUFERR(pit < int(text.paragraphs().size()));
|
2003-11-24 16:26:55 +00:00
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
|
2008-02-27 23:03:26 +00:00
|
|
|
FontInfo RowPainter::labelFont() const
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2010-09-06 14:35:02 +00:00
|
|
|
FontInfo f = text_.labelFont(par_);
|
|
|
|
// selected text?
|
|
|
|
if (row_.begin_margin_sel || pi_.selected)
|
|
|
|
f.setPaintColor(Color_selectiontext);
|
|
|
|
return f;
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int RowPainter::leftMargin() const
|
|
|
|
{
|
2007-09-02 09:44:08 +00:00
|
|
|
return text_metrics_.leftMargin(text_metrics_.width(), pit_,
|
2007-08-27 14:38:29 +00:00
|
|
|
row_.pos());
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2006-11-03 15:39:58 +00:00
|
|
|
// If you want to debug inset metrics uncomment the following line:
|
2007-08-30 09:01:30 +00:00
|
|
|
//#define DEBUG_METRICS
|
2006-11-03 15:39:58 +00:00
|
|
|
// This draws green lines around each inset.
|
|
|
|
|
|
|
|
|
2007-08-30 13:19:24 +00:00
|
|
|
void RowPainter::paintInset(Inset const * inset, pos_type const pos)
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2008-02-27 23:03:26 +00:00
|
|
|
Font const font = text_metrics_.displayFont(pit_, pos);
|
2007-08-30 09:01:30 +00:00
|
|
|
|
2008-08-24 21:24:21 +00:00
|
|
|
LASSERT(inset, return);
|
2008-01-14 16:24:01 +00:00
|
|
|
// Backup full_repaint status because some insets (InsetTabular)
|
|
|
|
// requires a full repaint
|
2015-05-06 16:39:24 +00:00
|
|
|
bool const pi_full_repaint = pi_.full_repaint;
|
|
|
|
bool const pi_do_spellcheck = pi_.do_spellcheck;
|
2008-01-14 16:24:01 +00:00
|
|
|
|
2011-02-22 19:41:04 +00:00
|
|
|
pi_.base.font = inset->inheritFont() ? font.fontInfo() :
|
|
|
|
pi_.base.bv->buffer().params().getFont().fontInfo();
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.ltr_pos = (bidi_.level(pos) % 2 == 0);
|
2012-04-29 11:44:58 +00:00
|
|
|
Change prev_change = change_;
|
2009-02-09 21:14:23 +00:00
|
|
|
pi_.change_ = change_.changed() ? change_ : par_.lookupChange(pos);
|
2015-05-06 16:39:24 +00:00
|
|
|
pi_.do_spellcheck &= inset->allowSpellCheck();
|
2009-02-09 21:14:23 +00:00
|
|
|
|
2008-12-22 18:16:05 +00:00
|
|
|
int const x1 = int(x_);
|
|
|
|
pi_.base.bv->coordCache().insets().add(inset, x1, yo_);
|
2007-08-27 14:38:29 +00:00
|
|
|
// insets are painted completely. Recursive
|
2010-11-25 13:08:26 +00:00
|
|
|
// FIXME: it is wrong to completely paint the background
|
|
|
|
// if we want to do single row painting.
|
2008-12-22 18:16:05 +00:00
|
|
|
inset->drawBackground(pi_, x1, yo_);
|
|
|
|
inset->drawSelection(pi_, x1, yo_);
|
|
|
|
inset->draw(pi_, x1, yo_);
|
2007-08-30 09:01:30 +00:00
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
Dimension const & dim = pm_.insetDimension(inset);
|
2007-08-30 09:01:30 +00:00
|
|
|
|
2007-10-29 08:52:13 +00:00
|
|
|
paintForeignMark(x_, font.language(), dim.descent());
|
2007-09-21 20:39:47 +00:00
|
|
|
|
|
|
|
x_ += dim.width();
|
2007-08-30 09:01:30 +00:00
|
|
|
|
2008-01-14 16:24:01 +00:00
|
|
|
// Restore full_repaint status.
|
|
|
|
pi_.full_repaint = pi_full_repaint;
|
2012-04-29 11:44:58 +00:00
|
|
|
pi_.change_ = prev_change;
|
2015-05-06 16:39:24 +00:00
|
|
|
pi_.do_spellcheck = pi_do_spellcheck;
|
2008-01-14 16:24:01 +00:00
|
|
|
|
2006-11-03 15:39:58 +00:00
|
|
|
#ifdef DEBUG_METRICS
|
|
|
|
int const x2 = x1 + dim.wid;
|
|
|
|
int const y1 = yo_ + dim.des;
|
|
|
|
int const y2 = yo_ - dim.asc;
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.line(x1, y1, x1, y2, Color_green);
|
|
|
|
pi_.pain.line(x1, y1, x2, y1, Color_green);
|
|
|
|
pi_.pain.line(x2, y1, x2, y2, Color_green);
|
|
|
|
pi_.pain.line(x1, y2, x2, y2, Color_green);
|
2006-11-03 15:39:58 +00:00
|
|
|
#endif
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-10 14:37:21 +00:00
|
|
|
void RowPainter::paintChars(pos_type & vpos, Font const & font)
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2006-10-22 18:49:18 +00:00
|
|
|
// This method takes up 70% of time when typing
|
2007-06-07 20:39:14 +00:00
|
|
|
pos_type pos = bidi_.vis2log(vpos);
|
2014-05-23 16:59:53 +00:00
|
|
|
pos_type start_pos = pos;
|
2003-02-26 17:04:10 +00:00
|
|
|
// first character
|
2014-05-02 13:03:20 +00:00
|
|
|
docstring str;
|
2006-10-22 13:51:37 +00:00
|
|
|
str.reserve(100);
|
2014-07-21 21:57:10 +00:00
|
|
|
char_type const c = par_.getChar(pos);
|
2014-05-02 13:03:20 +00:00
|
|
|
str.push_back(c);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2008-05-14 15:37:20 +00:00
|
|
|
FontSpan const font_span = par_.fontSpan(pos);
|
|
|
|
// Track-change status.
|
2008-09-22 15:30:26 +00:00
|
|
|
Change const & change_running = par_.lookupChange(pos);
|
2010-09-14 05:24:04 +00:00
|
|
|
// spelling correct?
|
|
|
|
bool const spell_state =
|
|
|
|
lyxrc.spellcheck_continuously && par_.isMisspelled(pos);
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
// collect as much similar chars as we can
|
2014-07-20 16:54:31 +00:00
|
|
|
pos_type const end = row_.endpos();
|
2005-06-10 14:55:01 +00:00
|
|
|
for (++vpos ; vpos < end ; ++vpos) {
|
2007-06-07 20:39:14 +00:00
|
|
|
pos = bidi_.vis2log(vpos);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2014-07-28 18:41:01 +00:00
|
|
|
if (!font_span.contains(pos))
|
2008-03-29 11:21:36 +00:00
|
|
|
break;
|
|
|
|
|
2010-09-14 05:24:04 +00:00
|
|
|
bool const new_spell_state =
|
|
|
|
lyxrc.spellcheck_continuously && par_.isMisspelled(pos);
|
|
|
|
if (new_spell_state != spell_state)
|
|
|
|
// Spell checker state changed here.
|
|
|
|
break;
|
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
Change const & change = par_.lookupChange(pos);
|
|
|
|
if (!change_running.isSimilarTo(change))
|
|
|
|
// Track change type or author has changed.
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2014-07-21 21:57:10 +00:00
|
|
|
char_type const c = par_.getChar(pos);
|
2005-06-10 14:55:01 +00:00
|
|
|
|
2014-04-10 14:37:21 +00:00
|
|
|
if (c == '\t')
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
2003-10-23 08:15:57 +00:00
|
|
|
|
2014-07-20 16:54:31 +00:00
|
|
|
if (!isPrintableNonspace(c))
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
|
|
|
|
2006-08-13 22:54:59 +00:00
|
|
|
str.push_back(c);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 16:59:53 +00:00
|
|
|
// Make pos point to the last character in the string.
|
|
|
|
// Using "pos = bidi_.vis2log(vpos)" does not work for some reason.
|
|
|
|
if (vpos < end)
|
|
|
|
pos = bidi_.vis2log(vpos - 1);
|
|
|
|
|
|
|
|
// Now make pos point to the position _after_ the string.
|
|
|
|
// Using vis2log for that is not a good idea in general, we
|
|
|
|
// want logical ordering.
|
|
|
|
if (font.isVisibleRightToLeft())
|
|
|
|
--pos;
|
|
|
|
else
|
|
|
|
++pos;
|
|
|
|
|
2014-05-02 13:03:20 +00:00
|
|
|
if (str[0] == '\t')
|
|
|
|
str.replace(0,1,from_ascii(" "));
|
2014-04-30 14:15:31 +00:00
|
|
|
|
2014-04-10 14:37:21 +00:00
|
|
|
/* Because we do our own bidi, at this point the strings are
|
|
|
|
* already in visual order. However, Qt also applies its own
|
|
|
|
* bidi algorithm to strings that it paints to the screen.
|
|
|
|
* Therefore, if we were to paint Hebrew/Arabic words as a
|
|
|
|
* single string, the letters in the words would get reversed
|
2014-04-30 14:15:31 +00:00
|
|
|
* again. In order to avoid that, we force LTR drawing.
|
2014-04-10 14:37:21 +00:00
|
|
|
* See also http://thread.gmane.org/gmane.editors.lyx.devel/79740
|
|
|
|
* for an earlier thread on the subject
|
|
|
|
*/
|
2014-04-30 14:15:31 +00:00
|
|
|
if (font.isVisibleRightToLeft()) {
|
2014-05-02 13:03:20 +00:00
|
|
|
reverse(str.begin(), str.end());
|
2014-05-23 16:59:53 +00:00
|
|
|
// If the string is reversed, the positions need to be adjusted
|
|
|
|
++pos;
|
|
|
|
++start_pos;
|
|
|
|
swap(start_pos, pos);
|
2014-07-25 20:35:08 +00:00
|
|
|
}
|
2014-05-23 16:59:53 +00:00
|
|
|
|
|
|
|
// at least part of text selected?
|
|
|
|
bool const some_sel = (pos >= row_.sel_beg && start_pos < row_.sel_end)
|
|
|
|
|| pi_.selected;
|
|
|
|
// all the text selected?
|
|
|
|
bool const all_sel = (start_pos >= row_.sel_beg && pos < row_.sel_end)
|
|
|
|
|| pi_.selected;
|
2008-09-30 18:00:02 +00:00
|
|
|
|
2014-05-23 16:59:53 +00:00
|
|
|
if (all_sel) {
|
|
|
|
Font copy = font;
|
|
|
|
copy.fontInfo().setPaintColor(Color_selectiontext);
|
|
|
|
x_ += pi_.pain.text(int(x_), yo_, str, copy);
|
|
|
|
} else if (change_running.changed()) {
|
|
|
|
Font copy = font;
|
|
|
|
copy.fontInfo().setPaintColor(change_running.color());
|
|
|
|
x_ += pi_.pain.text(int(x_), yo_, str, copy);
|
|
|
|
} else if (!some_sel) {
|
|
|
|
x_ += pi_.pain.text(int(x_), yo_, str, font);
|
|
|
|
} else {
|
|
|
|
x_ += pi_.pain.text(int(x_), yo_, str, font, Color_selectiontext,
|
|
|
|
max(row_.sel_beg, start_pos) - start_pos,
|
|
|
|
min(row_.sel_end, pos) - start_pos);
|
2006-10-22 18:49:18 +00:00
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-02 16:02:52 +00:00
|
|
|
void RowPainter::paintSeparator(double orig_x, double width,
|
|
|
|
FontInfo const & font)
|
|
|
|
{
|
|
|
|
pi_.pain.textDecoration(font, int(orig_x), yo_, int(width));
|
|
|
|
x_ += width;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-29 08:52:13 +00:00
|
|
|
void RowPainter::paintForeignMark(double orig_x, Language const * lang,
|
|
|
|
int desc)
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
|
|
|
if (!lyxrc.mark_foreign_language)
|
|
|
|
return;
|
2007-10-29 08:52:13 +00:00
|
|
|
if (lang == latex_language)
|
2003-02-26 17:04:10 +00:00
|
|
|
return;
|
2007-10-29 08:52:13 +00:00
|
|
|
if (lang == pi_.base.bv->buffer().params().language)
|
2003-02-26 17:04:10 +00:00
|
|
|
return;
|
|
|
|
|
2011-02-20 07:50:28 +00:00
|
|
|
int const y = yo_ + solid_line_offset_ + desc + int(solid_line_thickness_/2);
|
2010-12-13 16:18:37 +00:00
|
|
|
pi_.pain.line(int(orig_x), y, int(x_), y, Color_language,
|
2011-02-20 07:50:28 +00:00
|
|
|
Painter::line_solid, solid_line_thickness_);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-13 16:18:37 +00:00
|
|
|
void RowPainter::paintMisspelledMark(double orig_x, bool changed)
|
2009-03-29 19:57:30 +00:00
|
|
|
{
|
2010-10-04 16:26:12 +00:00
|
|
|
// if changed the misspelled marker gets placed slightly lower than normal
|
2010-11-22 08:35:12 +00:00
|
|
|
// to avoid drawing at the same vertical offset
|
2011-03-13 21:06:16 +00:00
|
|
|
float const y = yo_ + solid_line_offset_ + solid_line_thickness_
|
2011-02-20 07:50:28 +00:00
|
|
|
+ (changed ? solid_line_thickness_ + 1 : 0)
|
|
|
|
+ dotted_line_offset_;
|
2011-03-13 21:06:16 +00:00
|
|
|
pi_.pain.line(int(orig_x), int(y), int(x_), int(y), Color_error,
|
2011-02-20 07:50:28 +00:00
|
|
|
Painter::line_onoffdash, dotted_line_thickness_);
|
2009-03-29 19:57:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-04 16:26:12 +00:00
|
|
|
void RowPainter::paintFromPos(pos_type & vpos, bool changed)
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2007-06-07 20:39:14 +00:00
|
|
|
pos_type const pos = bidi_.vis2log(vpos);
|
2014-04-10 14:37:21 +00:00
|
|
|
Font const font = text_metrics_.displayFont(pit_, pos);
|
2003-07-28 12:20:42 +00:00
|
|
|
double const orig_x = x_;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2014-04-10 14:37:21 +00:00
|
|
|
paintChars(vpos, font);
|
|
|
|
paintForeignMark(orig_x, font.language());
|
2009-03-29 19:57:30 +00:00
|
|
|
|
2014-04-10 14:37:21 +00:00
|
|
|
// Paint the spelling mark if needed.
|
|
|
|
if (lyxrc.spellcheck_continuously && par_.isMisspelled(pos)) {
|
2010-12-22 07:29:16 +00:00
|
|
|
// check for cursor position
|
|
|
|
// don't draw misspelled marker for words at cursor position
|
|
|
|
// we don't want to disturb the process of text editing
|
|
|
|
BufferView const * bv = pi_.base.bv;
|
2011-02-03 17:27:13 +00:00
|
|
|
DocIterator const nw = bv->cursor().newWord();
|
|
|
|
bool new_word = false;
|
|
|
|
if (!nw.empty() && par_.id() == nw.paragraph().id()) {
|
|
|
|
pos_type cpos = nw.pos();
|
2010-12-22 07:29:16 +00:00
|
|
|
if (cpos > 0 && cpos == par_.size() && !par_.isWordSeparator(cpos-1))
|
|
|
|
--cpos;
|
2011-01-29 12:28:02 +00:00
|
|
|
else if (cpos > 0 && par_.isWordSeparator(cpos))
|
|
|
|
--cpos;
|
2011-02-03 17:27:13 +00:00
|
|
|
new_word = par_.isSameSpellRange(pos, cpos) ;
|
2010-12-22 07:29:16 +00:00
|
|
|
}
|
2015-05-08 09:13:32 +00:00
|
|
|
if (!new_word && pi_.do_spellcheck)
|
2015-05-08 12:15:38 +00:00
|
|
|
paintMisspelledMark(orig_x, changed);
|
2010-09-14 05:24:04 +00:00
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RowPainter::paintChangeBar()
|
|
|
|
{
|
2003-10-23 08:15:57 +00:00
|
|
|
pos_type const start = row_.pos();
|
2006-10-31 20:07:26 +00:00
|
|
|
pos_type end = row_.endpos();
|
|
|
|
|
|
|
|
if (par_.size() == end) {
|
|
|
|
// this is the last row of the paragraph;
|
|
|
|
// thus, we must also consider the imaginary end-of-par character
|
|
|
|
end++;
|
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2006-03-13 11:05:07 +00:00
|
|
|
if (start == end || !par_.isChanged(start, end))
|
2003-02-26 17:04:10 +00:00
|
|
|
return;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-09-02 11:27:19 +00:00
|
|
|
int const height = text_metrics_.isLastRow(pit_, row_)
|
2004-11-30 01:59:49 +00:00
|
|
|
? row_.ascent()
|
|
|
|
: row_.height();
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.fillRectangle(5, yo_ - row_.ascent(), 3, height, Color_changebar);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
void RowPainter::paintAppendix()
|
|
|
|
{
|
2007-07-17 13:35:32 +00:00
|
|
|
// only draw the appendix frame once (for the main text)
|
2009-08-09 15:29:34 +00:00
|
|
|
if (!par_.params().appendix() || !text_.isMainText())
|
2003-03-13 19:55:39 +00:00
|
|
|
return;
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
int y = yo_ - row_.ascent();
|
2003-03-13 19:55:39 +00:00
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
if (par_.params().startOfAppendix())
|
2003-03-13 19:55:39 +00:00
|
|
|
y += 2 * defaultRowHeight();
|
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.line(1, y, 1, yo_ + row_.height(), Color_appendix);
|
|
|
|
pi_.pain.line(width_ - 2, y, width_ - 2, yo_ + row_.height(), Color_appendix);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RowPainter::paintDepthBar()
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
depth_type const depth = par_.getDepth();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
if (depth <= 0)
|
|
|
|
return;
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
depth_type prev_depth = 0;
|
2007-09-02 11:27:19 +00:00
|
|
|
if (!text_metrics_.isFirstRow(pit_, row_)) {
|
2004-11-24 21:53:46 +00:00
|
|
|
pit_type pit2 = pit_;
|
2003-10-23 08:15:57 +00:00
|
|
|
if (row_.pos() == 0)
|
2003-08-14 12:06:11 +00:00
|
|
|
--pit2;
|
2004-03-25 09:16:36 +00:00
|
|
|
prev_depth = pars_[pit2].getDepth();
|
2003-08-14 12:06:11 +00:00
|
|
|
}
|
2003-06-18 17:43:49 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
depth_type next_depth = 0;
|
2007-09-02 11:27:19 +00:00
|
|
|
if (!text_metrics_.isLastRow(pit_, row_)) {
|
2004-11-24 21:53:46 +00:00
|
|
|
pit_type pit2 = pit_;
|
2004-03-25 09:16:36 +00:00
|
|
|
if (row_.endpos() >= pars_[pit2].size())
|
2003-08-14 12:06:11 +00:00
|
|
|
++pit2;
|
2004-03-25 09:16:36 +00:00
|
|
|
next_depth = pars_[pit2].getDepth();
|
2003-08-14 12:06:11 +00:00
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
for (depth_type i = 1; i <= depth; ++i) {
|
2004-08-14 15:55:22 +00:00
|
|
|
int const w = nestMargin() / 5;
|
2004-08-14 21:56:40 +00:00
|
|
|
int x = int(xo_) + w * i;
|
|
|
|
// only consider the changebar space if we're drawing outermost text
|
2009-08-09 15:29:34 +00:00
|
|
|
if (text_.isMainText())
|
2004-08-14 15:55:22 +00:00
|
|
|
x += changebarMargin();
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
int const starty = yo_ - row_.ascent();
|
|
|
|
int const h = row_.height() - 1 - (i - next_depth - 1) * 3;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.line(x, starty, x, starty + h, Color_depthbar);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2003-07-28 12:20:42 +00:00
|
|
|
if (i > prev_depth)
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.fillRectangle(x, starty, w, 2, Color_depthbar);
|
2003-07-28 12:20:42 +00:00
|
|
|
if (i > next_depth)
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.fillRectangle(x, starty + h, w, 2, Color_depthbar);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-13 19:55:39 +00:00
|
|
|
int RowPainter::paintAppendixStart(int y)
|
|
|
|
{
|
2007-10-29 08:47:19 +00:00
|
|
|
FontInfo pb_font = sane_font;
|
2007-10-25 12:41:02 +00:00
|
|
|
pb_font.setColor(Color_appendix);
|
2003-09-16 09:01:15 +00:00
|
|
|
pb_font.decSize();
|
2003-03-13 19:55:39 +00:00
|
|
|
|
|
|
|
int w = 0;
|
|
|
|
int a = 0;
|
|
|
|
int d = 0;
|
2006-10-17 14:46:45 +00:00
|
|
|
|
|
|
|
docstring const label = _("Appendix");
|
|
|
|
theFontMetrics(pb_font).rectText(label, w, a, d);
|
2003-03-13 19:55:39 +00:00
|
|
|
|
2003-07-28 12:20:42 +00:00
|
|
|
int const text_start = int(xo_ + (width_ - w) / 2);
|
2003-03-13 19:55:39 +00:00
|
|
|
int const text_end = text_start + w;
|
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.rectText(text_start, y + d, label, pb_font, Color_none, Color_none);
|
2003-03-13 19:55:39 +00:00
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.line(int(xo_ + 1), y, text_start, y, Color_appendix);
|
|
|
|
pi_.pain.line(text_end, y, int(xo_ + width_ - 2), y, Color_appendix);
|
2003-03-13 19:55:39 +00:00
|
|
|
|
|
|
|
return 3 * defaultRowHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-27 16:55:10 +00:00
|
|
|
void RowPainter::paintTooLargeMarks(bool const left, bool const right)
|
|
|
|
{
|
|
|
|
if (left)
|
2015-01-11 16:13:36 +00:00
|
|
|
pi_.pain.line(int(dotted_line_thickness_), yo_ - row_.ascent(),
|
|
|
|
int(dotted_line_thickness_), yo_ + row_.descent(),
|
|
|
|
Color_scroll,
|
|
|
|
Painter::line_onoffdash, dotted_line_thickness_);
|
2014-07-27 16:55:10 +00:00
|
|
|
if (right) {
|
2015-01-11 16:13:36 +00:00
|
|
|
int const wwidth = pi_.base.bv->workWidth() - int(dotted_line_thickness_);
|
2014-07-27 16:55:10 +00:00
|
|
|
pi_.pain.line(wwidth, yo_ - row_.ascent(),
|
2015-01-11 16:13:36 +00:00
|
|
|
wwidth, yo_ + row_.descent(),
|
|
|
|
Color_scroll,
|
|
|
|
Painter::line_onoffdash, dotted_line_thickness_);
|
2014-07-27 16:55:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
void RowPainter::paintFirst()
|
|
|
|
{
|
2011-10-30 09:16:30 +00:00
|
|
|
BufferParams const & bparams = pi_.base.bv->buffer().params();
|
2010-09-06 10:56:27 +00:00
|
|
|
Layout const & layout = par_.layout();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2003-03-13 19:55:39 +00:00
|
|
|
int y_top = 0;
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
// start of appendix?
|
2011-10-30 09:16:30 +00:00
|
|
|
if (par_.params().startOfAppendix())
|
2005-05-05 13:11:05 +00:00
|
|
|
y_top += paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2010-09-06 10:56:27 +00:00
|
|
|
if (bparams.paragraph_separation == BufferParams::ParagraphSkipSeparation
|
|
|
|
&& pit_ != 0) {
|
|
|
|
if (layout.latextype == LATEX_PARAGRAPH
|
|
|
|
&& !par_.getDepth()) {
|
|
|
|
y_top += bparams.getDefSkip().inPixels(*pi_.base.bv);
|
|
|
|
} else {
|
|
|
|
Layout const & playout = pars_[pit_ - 1].layout();
|
|
|
|
if (playout.latextype == LATEX_PARAGRAPH
|
|
|
|
&& !pars_[pit_ - 1].getDepth()) {
|
|
|
|
// is it right to use defskip here, too? (AS)
|
|
|
|
y_top += bparams.getDefSkip().inPixels(*pi_.base.bv);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-09 16:13:01 +00:00
|
|
|
bool const is_first =
|
|
|
|
text_.isFirstInSequence(pit_) || !layout.isParagraphGroup();
|
2007-12-12 19:28:07 +00:00
|
|
|
//lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << endl;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2013-02-09 16:13:01 +00:00
|
|
|
if (layout.labelIsInline()
|
|
|
|
&& (layout.labeltype != LABEL_STATIC || is_first)) {
|
2011-10-30 09:16:30 +00:00
|
|
|
paintLabel();
|
2013-02-09 16:13:01 +00:00
|
|
|
} else if (is_first && layout.labelIsAbove()) {
|
2011-10-30 09:16:30 +00:00
|
|
|
paintTopLevelLabel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RowPainter::paintLabel()
|
|
|
|
{
|
|
|
|
docstring const str = par_.labelString();
|
|
|
|
if (str.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool const is_rtl = text_.isRTL(par_);
|
|
|
|
Layout const & layout = par_.layout();
|
|
|
|
FontInfo const font = labelFont();
|
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
|
|
|
double x = x_;
|
|
|
|
|
2013-02-09 16:13:40 +00:00
|
|
|
if (is_rtl) {
|
|
|
|
x = width_ - leftMargin()
|
|
|
|
+ fm.width(layout.labelsep);
|
2011-10-30 09:16:30 +00:00
|
|
|
} else {
|
2013-02-09 16:13:40 +00:00
|
|
|
x = x_ - fm.width(layout.labelsep)
|
|
|
|
- fm.width(str);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
2013-02-09 16:13:40 +00:00
|
|
|
|
|
|
|
pi_.pain.text(int(x), yo_, str, font);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-30 09:16:30 +00:00
|
|
|
void RowPainter::paintTopLevelLabel()
|
|
|
|
{
|
|
|
|
BufferParams const & bparams = pi_.base.bv->buffer().params();
|
|
|
|
bool const is_rtl = text_.isRTL(par_);
|
|
|
|
ParagraphParameters const & pparams = par_.params();
|
|
|
|
Layout const & layout = par_.layout();
|
|
|
|
FontInfo const font = labelFont();
|
|
|
|
docstring const str = par_.labelString();
|
|
|
|
if (str.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
double spacing_val = 1.0;
|
|
|
|
if (!pparams.spacing().isDefault())
|
|
|
|
spacing_val = pparams.spacing().getValue();
|
|
|
|
else
|
|
|
|
spacing_val = bparams.spacing().getValue();
|
|
|
|
|
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
|
|
|
|
|
|
|
int const labeladdon = int(fm.maxHeight()
|
|
|
|
* layout.spacing.getValue() * spacing_val);
|
|
|
|
|
|
|
|
int maxdesc =
|
|
|
|
int(fm.maxDescent() * layout.spacing.getValue() * spacing_val
|
|
|
|
+ (layout.labelbottomsep * defaultRowHeight()));
|
|
|
|
|
|
|
|
double x = x_;
|
2013-02-09 16:13:01 +00:00
|
|
|
if (layout.labeltype == LABEL_CENTERED) {
|
2011-10-30 09:16:30 +00:00
|
|
|
if (is_rtl)
|
|
|
|
x = leftMargin();
|
|
|
|
x += (width_ - text_metrics_.rightMargin(pm_) - leftMargin()) / 2;
|
|
|
|
x -= fm.width(str) / 2;
|
|
|
|
} else if (is_rtl) {
|
|
|
|
x = width_ - leftMargin() - fm.width(str);
|
|
|
|
}
|
|
|
|
pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
|
|
|
|
}
|
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
|
2009-08-09 18:35:39 +00:00
|
|
|
/** Check if the current paragraph is the last paragraph in a
|
|
|
|
proof environment */
|
|
|
|
static int getEndLabel(pit_type p, Text const & text)
|
|
|
|
{
|
|
|
|
ParagraphList const & pars = text.paragraphs();
|
|
|
|
pit_type pit = p;
|
|
|
|
depth_type par_depth = pars[p].getDepth();
|
|
|
|
while (pit != pit_type(pars.size())) {
|
|
|
|
Layout const & layout = pars[pit].layout();
|
|
|
|
int const endlabeltype = layout.endlabeltype;
|
|
|
|
|
|
|
|
if (endlabeltype != END_LABEL_NO_LABEL) {
|
|
|
|
if (p + 1 == pit_type(pars.size()))
|
|
|
|
return endlabeltype;
|
|
|
|
|
|
|
|
depth_type const next_depth =
|
|
|
|
pars[p + 1].getDepth();
|
|
|
|
if (par_depth > next_depth ||
|
|
|
|
(par_depth == next_depth && layout != pars[p + 1].layout()))
|
|
|
|
return endlabeltype;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (par_depth == 0)
|
|
|
|
break;
|
|
|
|
pit = text.outerHook(pit);
|
|
|
|
if (pit != pit_type(pars.size()))
|
|
|
|
par_depth = pars[pit].getDepth();
|
|
|
|
}
|
|
|
|
return END_LABEL_NO_LABEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
void RowPainter::paintLast()
|
|
|
|
{
|
2009-08-09 15:29:34 +00:00
|
|
|
bool const is_rtl = text_.isRTL(par_);
|
2009-08-09 18:35:39 +00:00
|
|
|
int const endlabel = getEndLabel(pit_, text_);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2006-11-23 18:59:05 +00:00
|
|
|
// paint imaginary end-of-paragraph character
|
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
Change const & change = par_.lookupChange(par_.size());
|
|
|
|
if (change.changed()) {
|
2008-09-22 15:41:05 +00:00
|
|
|
FontMetrics const & fm =
|
2008-09-22 15:30:26 +00:00
|
|
|
theFontMetrics(pi_.base.bv->buffer().params().getFont());
|
2006-11-23 18:59:05 +00:00
|
|
|
int const length = fm.maxAscent() / 2;
|
2009-02-09 20:47:32 +00:00
|
|
|
Color col = change.color();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.pain.line(int(x_) + 1, yo_ + 2, int(x_) + 1, yo_ + 2 - length, col,
|
2010-09-05 14:56:07 +00:00
|
|
|
Painter::line_solid, 3);
|
2008-09-22 15:41:05 +00:00
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
if (change.deleted()) {
|
2008-09-22 15:41:05 +00:00
|
|
|
pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1 + length,
|
2010-09-05 14:56:07 +00:00
|
|
|
yo_ + 2, col, Painter::line_solid, 3);
|
2008-09-22 15:30:26 +00:00
|
|
|
} else {
|
2008-09-22 15:41:05 +00:00
|
|
|
pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1,
|
2010-09-05 14:56:07 +00:00
|
|
|
yo_ + 2, col, Painter::line_solid, 3);
|
2008-09-22 15:30:26 +00:00
|
|
|
}
|
2006-11-23 18:59:05 +00:00
|
|
|
}
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
// draw an endlabel
|
2006-11-23 18:59:05 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
switch (endlabel) {
|
|
|
|
case END_LABEL_BOX:
|
2003-10-28 11:18:40 +00:00
|
|
|
case END_LABEL_FILLED_BOX: {
|
2008-02-27 23:03:26 +00:00
|
|
|
FontInfo const font = labelFont();
|
2006-10-11 17:24:46 +00:00
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
2006-10-07 16:15:06 +00:00
|
|
|
int const size = int(0.75 * fm.maxAscent());
|
2004-11-30 01:59:49 +00:00
|
|
|
int const y = yo_ - size;
|
2008-01-29 07:31:24 +00:00
|
|
|
int const max_row_width = width_ - size - Inset::TEXT_TO_INSET_OFFSET;
|
|
|
|
int x = is_rtl ? nestMargin() + changebarMargin()
|
|
|
|
: max_row_width - text_metrics_.rightMargin(pm_);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2008-01-29 07:31:24 +00:00
|
|
|
// If needed, move the box a bit to avoid overlapping with text.
|
|
|
|
int const rem = max_row_width - row_.width();
|
2008-01-28 21:22:29 +00:00
|
|
|
if (rem <= 0)
|
2008-01-29 07:31:24 +00:00
|
|
|
x += is_rtl ? rem : - rem;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2003-07-28 12:20:42 +00:00
|
|
|
if (endlabel == END_LABEL_BOX)
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.rectangle(x, y, size, size, Color_eolmarker);
|
2003-07-28 12:20:42 +00:00
|
|
|
else
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.fillRectangle(x, y, size, size, Color_eolmarker);
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
case END_LABEL_STATIC: {
|
2008-02-27 23:03:26 +00:00
|
|
|
FontInfo const font = labelFont();
|
2006-10-11 17:24:46 +00:00
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
2008-03-06 21:31:27 +00:00
|
|
|
docstring const & str = par_.layout().endlabelstring();
|
2009-08-22 17:51:41 +00:00
|
|
|
double const x = is_rtl ? x_ - fm.width(str) : x_;
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.pain.text(int(x), yo_, str, font);
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
case END_LABEL_NO_LABEL:
|
2009-08-20 18:30:06 +00:00
|
|
|
if (lyxrc.paragraph_markers && size_type(pit_ + 1) < pars_.size()) {
|
2009-08-19 22:46:43 +00:00
|
|
|
docstring const s = docstring(1, char_type(0x00B6));
|
2013-07-21 18:22:32 +00:00
|
|
|
FontInfo f = FontInfo(text_.layoutFont(pit_));
|
2009-08-19 22:46:43 +00:00
|
|
|
f.setColor(Color_paragraphmarker);
|
2009-08-20 18:30:06 +00:00
|
|
|
pi_.pain.text(int(x_), yo_, s, f);
|
2013-07-21 18:22:32 +00:00
|
|
|
x_ += theFontMetrics(f).width(s);
|
2009-08-19 22:46:43 +00:00
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-30 13:19:24 +00:00
|
|
|
void RowPainter::paintOnlyInsets()
|
|
|
|
{
|
2009-02-10 22:27:43 +00:00
|
|
|
CoordCache const & cache = pi_.base.bv->coordCache();
|
2007-08-30 13:19:24 +00:00
|
|
|
pos_type const end = row_.endpos();
|
|
|
|
for (pos_type pos = row_.pos(); pos != end; ++pos) {
|
|
|
|
// If outer row has changed, nested insets are repaint completely.
|
|
|
|
Inset const * inset = par_.getInset(pos);
|
2010-12-22 00:16:51 +00:00
|
|
|
bool const nested_inset = inset &&
|
|
|
|
((inset->asInsetMath() &&
|
|
|
|
!inset->asInsetMath()->asMacroTemplate())
|
|
|
|
|| inset->asInsetText()
|
|
|
|
|| inset->asInsetTabular());
|
2010-12-12 20:56:01 +00:00
|
|
|
if (!nested_inset)
|
2008-02-09 10:41:49 +00:00
|
|
|
continue;
|
2010-11-22 08:35:12 +00:00
|
|
|
if (x_ > pi_.base.bv->workWidth()
|
2009-02-10 22:27:43 +00:00
|
|
|
|| !cache.getInsets().has(inset))
|
2007-08-30 13:19:24 +00:00
|
|
|
continue;
|
2009-02-10 22:27:43 +00:00
|
|
|
x_ = cache.getInsets().x(inset);
|
2008-10-25 10:47:38 +00:00
|
|
|
|
|
|
|
bool const pi_selected = pi_.selected;
|
|
|
|
Cursor const & cur = pi_.base.bv->cursor();
|
2010-11-22 08:35:12 +00:00
|
|
|
if (cur.selection() && cur.text() == &text_
|
2010-04-15 17:49:15 +00:00
|
|
|
&& cur.normalAnchor().text() == &text_)
|
2010-11-22 08:35:12 +00:00
|
|
|
pi_.selected = row_.sel_beg <= pos && row_.sel_end > pos;
|
2007-08-30 13:19:24 +00:00
|
|
|
paintInset(inset, pos);
|
2008-10-25 10:47:38 +00:00
|
|
|
pi_.selected = pi_selected;
|
2007-08-30 13:19:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-22 17:26:03 +00:00
|
|
|
void RowPainter::paintText()
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2014-07-20 16:54:31 +00:00
|
|
|
//LYXERR0("-------------------------------------------------------");
|
2003-10-27 11:44:10 +00:00
|
|
|
pos_type const end = row_.endpos();
|
2010-11-22 08:35:12 +00:00
|
|
|
// Spaces at logical line breaks in bidi text must be skipped during
|
2007-07-09 17:18:35 +00:00
|
|
|
// 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;
|
2004-08-15 00:01:45 +00:00
|
|
|
pos_type body_pos = par_.beginOfBody();
|
2003-03-09 12:37:22 +00:00
|
|
|
if (body_pos > 0 &&
|
2004-08-15 00:01:45 +00:00
|
|
|
(body_pos > end || !par_.isLineSeparator(body_pos - 1))) {
|
2003-03-09 12:37:22 +00:00
|
|
|
body_pos = 0;
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2008-03-06 21:31:27 +00:00
|
|
|
Layout const & layout = par_.layout();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
Change change_running;
|
|
|
|
int change_last_x = 0;
|
2008-09-22 15:41:05 +00:00
|
|
|
|
2008-02-22 21:57:33 +00:00
|
|
|
// check for possible inline completion
|
|
|
|
DocIterator const & inlineCompletionPos = pi_.base.bv->inlineCompletionPos();
|
|
|
|
pos_type inlineCompletionVPos = -1;
|
|
|
|
if (inlineCompletionPos.inTexted()
|
|
|
|
&& inlineCompletionPos.text() == &text_
|
2008-02-22 21:57:45 +00:00
|
|
|
&& inlineCompletionPos.pit() == pit_
|
2008-02-28 12:44:42 +00:00
|
|
|
&& inlineCompletionPos.pos() - 1 >= row_.pos()
|
|
|
|
&& inlineCompletionPos.pos() - 1 < row_.endpos()) {
|
2008-02-22 23:40:36 +00:00
|
|
|
// draw logically behind the previous character
|
2008-02-22 21:57:33 +00:00
|
|
|
inlineCompletionVPos = bidi_.log2vis(inlineCompletionPos.pos() - 1);
|
|
|
|
}
|
|
|
|
|
2006-04-05 23:56:29 +00:00
|
|
|
// Use font span to speed things up, see below
|
2005-07-18 14:25:20 +00:00
|
|
|
FontSpan font_span;
|
2007-10-28 22:49:49 +00:00
|
|
|
Font font;
|
2005-07-18 14:25:20 +00:00
|
|
|
|
2007-07-09 17:18:35 +00:00
|
|
|
// 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);
|
2008-02-21 19:42:34 +00:00
|
|
|
|
2003-10-27 15:39:59 +00:00
|
|
|
for (pos_type vpos = row_.pos(); vpos < end; ) {
|
2007-08-30 13:53:02 +00:00
|
|
|
if (x_ > pi_.base.bv->workWidth())
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
2003-10-27 12:41:26 +00:00
|
|
|
|
2007-07-09 17:18:35 +00:00
|
|
|
// Skip the separator at the logical end of the row
|
|
|
|
if (vpos == skipped_sep_vpos) {
|
|
|
|
++vpos;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-06-07 20:39:14 +00:00
|
|
|
pos_type const pos = bidi_.vis2log(vpos);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
if (pos >= par_.size()) {
|
2003-03-13 10:30:28 +00:00
|
|
|
++vpos;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-07-18 14:25:20 +00:00
|
|
|
// Use font span to speed things up, see above
|
2014-07-28 18:41:01 +00:00
|
|
|
if (!font_span.contains(pos)) {
|
2014-07-24 22:10:10 +00:00
|
|
|
font_span = par_.fontSpan(pos);
|
|
|
|
font = text_metrics_.displayFont(pit_, pos);
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
// split font span if inline completion is inside
|
2014-07-24 22:10:10 +00:00
|
|
|
if (inlineCompletionVPos != -1
|
2014-07-28 18:41:01 +00:00
|
|
|
&& font_span.contains(inlineCompletionPos.pos()))
|
2014-07-24 22:10:10 +00:00
|
|
|
font_span.last = inlineCompletionPos.pos();
|
2005-07-18 14:25:20 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 14:33:58 +00:00
|
|
|
// Note that this value will only be used in
|
|
|
|
// situations where no ligature of composition of
|
2014-07-24 22:10:10 +00:00
|
|
|
// characters is needed. (see comments in uses of width_pos).
|
2007-08-18 21:17:10 +00:00
|
|
|
const int width_pos = pm_.singleWidth(pos, font);
|
2005-07-18 14:25:20 +00:00
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
Change const & change = par_.lookupChange(pos);
|
|
|
|
if (change.changed() && !change_running.changed()) {
|
|
|
|
change_running = change;
|
|
|
|
change_last_x = int(x_);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2008-02-09 10:41:49 +00:00
|
|
|
Inset const * inset = par_.getInset(pos);
|
|
|
|
bool const highly_editable_inset = inset
|
2009-04-22 20:55:13 +00:00
|
|
|
&& inset->editable();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
// If we reach the end of a change or if the author changes, paint it.
|
2005-07-18 14:25:20 +00:00
|
|
|
// We also don't paint across things like tables
|
2008-09-22 15:41:05 +00:00
|
|
|
if (change_running.changed() && (highly_editable_inset
|
2008-09-22 15:30:26 +00:00
|
|
|
|| !change.changed() || !change_running.isSimilarTo(change))) {
|
2005-07-18 14:25:20 +00:00
|
|
|
// Calculate 1/3 height of the buffer's default font
|
2007-05-28 22:27:45 +00:00
|
|
|
FontMetrics const & fm
|
2007-08-30 13:53:02 +00:00
|
|
|
= theFontMetrics(pi_.base.bv->buffer().params().getFont());
|
2011-03-13 21:06:16 +00:00
|
|
|
float const y_bar = change_running.deleted() ?
|
2011-02-20 07:50:28 +00:00
|
|
|
yo_ - fm.maxAscent() / 3 : yo_ + 2 * solid_line_offset_ + solid_line_thickness_;
|
2011-03-13 21:06:16 +00:00
|
|
|
pi_.pain.line(change_last_x, int(y_bar), int(x_), int(y_bar),
|
2011-02-20 07:50:28 +00:00
|
|
|
change_running.color(), Painter::line_solid, solid_line_thickness_);
|
2008-09-22 15:41:05 +00:00
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
// Change might continue with a different author or type
|
|
|
|
if (change.changed() && !highly_editable_inset) {
|
|
|
|
change_running = change;
|
|
|
|
change_last_x = int(x_);
|
2008-09-22 15:41:05 +00:00
|
|
|
} else
|
2008-09-22 15:30:26 +00:00
|
|
|
change_running.setUnchanged();
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-03-09 12:37:22 +00:00
|
|
|
if (body_pos > 0 && pos == body_pos - 1) {
|
2008-02-27 23:03:26 +00:00
|
|
|
int const lwidth = theFontMetrics(labelFont())
|
2008-03-06 21:31:27 +00:00
|
|
|
.width(layout.labelsep);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2014-06-13 14:33:58 +00:00
|
|
|
// width_pos is either the width of a space or an inset
|
2007-08-28 15:47:53 +00:00
|
|
|
x_ += row_.label_hfill + lwidth - width_pos;
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
2010-11-22 08:35:12 +00:00
|
|
|
|
2008-02-22 14:05:27 +00:00
|
|
|
// Is the inline completion in front of character?
|
2008-02-22 21:57:33 +00:00
|
|
|
if (font.isRightToLeft() && vpos == inlineCompletionVPos)
|
2008-02-22 23:40:36 +00:00
|
|
|
paintInlineCompletion(font);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2007-12-05 22:25:07 +00:00
|
|
|
if (par_.isSeparator(pos)) {
|
2008-02-27 23:03:26 +00:00
|
|
|
Font const orig_font = text_metrics_.displayFont(pit_, pos);
|
2007-05-17 21:20:34 +00:00
|
|
|
double const orig_x = x_;
|
2014-06-13 14:33:58 +00:00
|
|
|
// width_pos is the width of a space
|
2012-05-02 16:02:52 +00:00
|
|
|
double separator_width = width_pos;
|
2003-03-09 12:37:22 +00:00
|
|
|
if (pos >= body_pos)
|
2012-05-02 16:02:52 +00:00
|
|
|
separator_width += row_.separator;
|
|
|
|
paintSeparator(orig_x, separator_width, orig_font.fontInfo());
|
2007-10-29 08:52:13 +00:00
|
|
|
paintForeignMark(orig_x, orig_font.language());
|
2007-08-30 13:19:24 +00:00
|
|
|
++vpos;
|
2007-08-30 09:01:30 +00:00
|
|
|
|
2008-02-09 10:41:49 +00:00
|
|
|
} else if (inset) {
|
2007-08-30 09:01:30 +00:00
|
|
|
// If outer row has changed, nested insets are repaint completely.
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_);
|
2010-11-22 08:35:12 +00:00
|
|
|
|
2008-10-25 10:47:38 +00:00
|
|
|
bool const pi_selected = pi_.selected;
|
|
|
|
Cursor const & cur = pi_.base.bv->cursor();
|
2010-11-22 08:35:12 +00:00
|
|
|
if (cur.selection() && cur.text() == &text_
|
2010-04-15 17:49:15 +00:00
|
|
|
&& cur.normalAnchor().text() == &text_)
|
2010-11-22 08:35:12 +00:00
|
|
|
pi_.selected = row_.sel_beg <= pos && row_.sel_end > pos;
|
2007-08-30 13:19:24 +00:00
|
|
|
paintInset(inset, pos);
|
2008-10-25 10:47:38 +00:00
|
|
|
pi_.selected = pi_selected;
|
2007-08-30 13:19:24 +00:00
|
|
|
++vpos;
|
2007-08-30 09:01:30 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
} else {
|
2007-08-30 13:19:24 +00:00
|
|
|
// paint as many characters as possible.
|
2010-10-04 16:26:12 +00:00
|
|
|
paintFromPos(vpos, change_running.changed());
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
2008-02-21 19:42:34 +00:00
|
|
|
|
2008-02-22 14:05:27 +00:00
|
|
|
// Is the inline completion after character?
|
2008-02-22 21:57:33 +00:00
|
|
|
if (!font.isRightToLeft() && vpos - 1 == inlineCompletionVPos)
|
2008-02-22 15:26:52 +00:00
|
|
|
paintInlineCompletion(font);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
// if we reach the end of a struck out range, paint it
|
2008-09-22 15:30:26 +00:00
|
|
|
if (change_running.changed()) {
|
2007-05-28 22:27:45 +00:00
|
|
|
FontMetrics const & fm
|
2007-08-30 13:53:02 +00:00
|
|
|
= theFontMetrics(pi_.base.bv->buffer().params().getFont());
|
2011-03-13 21:06:16 +00:00
|
|
|
float const y_bar = change_running.deleted() ?
|
2011-02-20 07:50:28 +00:00
|
|
|
yo_ - fm.maxAscent() / 3 : yo_ + 2 * solid_line_offset_ + solid_line_thickness_;
|
2011-03-13 21:06:16 +00:00
|
|
|
pi_.pain.line(change_last_x, int(y_bar), int(x_), int(y_bar),
|
2011-02-20 07:50:28 +00:00
|
|
|
change_running.color(), Painter::line_solid, solid_line_thickness_);
|
2008-09-22 15:30:26 +00:00
|
|
|
change_running.setUnchanged();
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-22 14:05:27 +00:00
|
|
|
|
2010-11-25 13:16:30 +00:00
|
|
|
void RowPainter::paintSelection()
|
|
|
|
{
|
|
|
|
if (!row_.selection())
|
|
|
|
return;
|
|
|
|
Cursor const & curs = pi_.base.bv->cursor();
|
|
|
|
DocIterator beg = curs.selectionBegin();
|
|
|
|
beg.pit() = pit_;
|
|
|
|
beg.pos() = row_.sel_beg;
|
|
|
|
|
|
|
|
DocIterator end = curs.selectionEnd();
|
|
|
|
end.pit() = pit_;
|
|
|
|
end.pos() = row_.sel_end;
|
|
|
|
|
|
|
|
bool const begin_boundary = beg.pos() >= row_.endpos();
|
|
|
|
bool const end_boundary = row_.sel_end == row_.endpos();
|
|
|
|
|
|
|
|
DocIterator cur = beg;
|
|
|
|
cur.boundary(begin_boundary);
|
|
|
|
int x1 = text_metrics_.cursorX(beg.top(), begin_boundary);
|
|
|
|
int x2 = text_metrics_.cursorX(end.top(), end_boundary);
|
|
|
|
int const y1 = yo_ - row_.ascent();
|
|
|
|
int const y2 = y1 + row_.height();
|
|
|
|
|
|
|
|
int const rm = text_.isMainText() ? pi_.base.bv->rightMargin() : 0;
|
|
|
|
int const lm = text_.isMainText() ? pi_.base.bv->leftMargin() : 0;
|
|
|
|
|
|
|
|
// draw the margins
|
|
|
|
if (row_.begin_margin_sel) {
|
|
|
|
if (text_.isRTL(beg.paragraph())) {
|
2010-12-03 15:40:23 +00:00
|
|
|
pi_.pain.fillRectangle(int(xo_ + x1), y1,
|
|
|
|
text_metrics_.width() - rm - x1, y2 - y1, Color_selection);
|
2010-11-25 13:16:30 +00:00
|
|
|
} else {
|
2010-12-03 15:40:23 +00:00
|
|
|
pi_.pain.fillRectangle(int(xo_ + lm), y1, x1 - lm, y2 - y1,
|
2010-11-25 13:16:30 +00:00
|
|
|
Color_selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (row_.end_margin_sel) {
|
|
|
|
if (text_.isRTL(beg.paragraph())) {
|
2010-12-03 15:40:23 +00:00
|
|
|
pi_.pain.fillRectangle(int(xo_ + lm), y1, x2 - lm, y2 - y1,
|
2010-11-25 13:16:30 +00:00
|
|
|
Color_selection);
|
|
|
|
} else {
|
2010-12-03 15:40:23 +00:00
|
|
|
pi_.pain.fillRectangle(int(xo_ + x2), y1, text_metrics_.width() - rm - x2,
|
|
|
|
y2 - y1, Color_selection);
|
2010-11-25 13:16:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we are on a boundary from the beginning, it's probably
|
|
|
|
// a RTL boundary and we jump to the other side directly as this
|
|
|
|
// segement is 0-size and confuses the logic below
|
|
|
|
if (cur.boundary())
|
|
|
|
cur.boundary(false);
|
|
|
|
|
|
|
|
// go through row and draw from RTL boundary to RTL boundary
|
|
|
|
while (cur < end) {
|
|
|
|
bool draw_now = false;
|
|
|
|
|
|
|
|
// simplified cursorForward code below which does not
|
|
|
|
// descend into insets and which does not go into the
|
|
|
|
// next line. Compare the logic with the original cursorForward
|
|
|
|
|
|
|
|
// if left of boundary -> just jump to right side, but
|
|
|
|
// for RTL boundaries don't, because: abc|DDEEFFghi -> abcDDEEF|Fghi
|
|
|
|
if (cur.boundary()) {
|
|
|
|
cur.boundary(false);
|
|
|
|
} else if (text_metrics_.isRTLBoundary(cur.pit(), cur.pos() + 1)) {
|
|
|
|
// in front of RTL boundary -> Stay on this side of the boundary
|
|
|
|
// because: ab|cDDEEFFghi -> abc|DDEEFFghi
|
|
|
|
++cur.pos();
|
|
|
|
cur.boundary(true);
|
|
|
|
draw_now = true;
|
|
|
|
} else {
|
|
|
|
// move right
|
|
|
|
++cur.pos();
|
|
|
|
|
|
|
|
// line end?
|
|
|
|
if (cur.pos() == row_.endpos())
|
|
|
|
cur.boundary(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x1 == -1) {
|
|
|
|
// the previous segment was just drawn, now the next starts
|
|
|
|
x1 = text_metrics_.cursorX(cur.top(), cur.boundary());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(cur < end) || draw_now) {
|
|
|
|
x2 = text_metrics_.cursorX(cur.top(), cur.boundary());
|
2010-12-03 15:40:23 +00:00
|
|
|
pi_.pain.fillRectangle(int(xo_ + min(x1, x2)), y1, abs(x2 - x1),
|
|
|
|
y2 - y1, Color_selection);
|
2010-11-25 13:16:30 +00:00
|
|
|
|
|
|
|
// reset x1, so it is set again next round (which will be on the
|
|
|
|
// right side of a boundary or at the selection end)
|
|
|
|
x1 = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 15:26:52 +00:00
|
|
|
void RowPainter::paintInlineCompletion(Font const & font)
|
2008-02-22 14:05:27 +00:00
|
|
|
{
|
|
|
|
docstring completion = pi_.base.bv->inlineCompletion();
|
|
|
|
FontInfo f = font.fontInfo();
|
2008-02-28 12:42:58 +00:00
|
|
|
bool rtl = font.isRightToLeft();
|
2010-11-22 08:35:12 +00:00
|
|
|
|
2008-02-22 14:05:27 +00:00
|
|
|
// draw the unique and the non-unique completion part
|
|
|
|
// Note: this is not time-critical as it is
|
|
|
|
// only done once per screen.
|
|
|
|
size_t uniqueTo = pi_.base.bv->inlineCompletionUniqueChars();
|
|
|
|
docstring s1 = completion.substr(0, uniqueTo);
|
|
|
|
docstring s2 = completion.substr(uniqueTo);
|
2008-02-28 12:42:58 +00:00
|
|
|
ColorCode c1 = Color_inlinecompletion;
|
|
|
|
ColorCode c2 = Color_nonunique_inlinecompletion;
|
2010-11-22 08:35:12 +00:00
|
|
|
|
2008-02-28 12:42:58 +00:00
|
|
|
// right to left?
|
|
|
|
if (rtl) {
|
|
|
|
swap(s1, s2);
|
|
|
|
swap(c1, c2);
|
|
|
|
}
|
|
|
|
|
2012-10-21 19:14:16 +00:00
|
|
|
if (!s1.empty()) {
|
2008-02-28 12:42:58 +00:00
|
|
|
f.setColor(c1);
|
2008-02-25 08:54:51 +00:00
|
|
|
pi_.pain.text(int(x_), yo_, s1, f);
|
2008-02-22 14:05:27 +00:00
|
|
|
x_ += theFontMetrics(font).width(s1);
|
|
|
|
}
|
2010-11-22 08:35:12 +00:00
|
|
|
|
2012-10-21 19:14:16 +00:00
|
|
|
if (!s2.empty()) {
|
2008-02-28 12:42:58 +00:00
|
|
|
f.setColor(c2);
|
2008-02-25 08:54:51 +00:00
|
|
|
pi_.pain.text(int(x_), yo_, s2, f);
|
2008-02-22 14:05:27 +00:00
|
|
|
x_ += theFontMetrics(font).width(s2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|