2003-02-26 17:04:10 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +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
|
|
|
|
2003-09-06 23:36:02 +00:00
|
|
|
#include "rowpainter.h"
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2007-06-07 20:39:14 +00:00
|
|
|
#include "Bidi.h"
|
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 "Encoding.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/gettext.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 "paragraph_funcs.h"
|
|
|
|
#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
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.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
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
RowPainter::RowPainter(PainterInfo & pi,
|
2007-06-08 05:14:49 +00:00
|
|
|
Text const & text, pit_type pit, Row const & row, Bidi & bidi, 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]),
|
2006-12-29 23:54:48 +00:00
|
|
|
pm_(text_metrics_.parMetrics(pit)),
|
2007-08-30 13:53:02 +00:00
|
|
|
bidi_(bidi), erased_(pi_.erased_),
|
2006-12-29 23:54:48 +00:00
|
|
|
xo_(x), yo_(y), width_(text_metrics_.width())
|
2003-11-24 16:26:55 +00:00
|
|
|
{
|
2007-08-30 13:53:02 +00:00
|
|
|
bidi_.computeTables(par_, pi_.base.bv->buffer(), row_);
|
2007-08-28 15:47:53 +00:00
|
|
|
x_ = row_.x + 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();
|
|
|
|
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(pit >= 0, /**/);
|
|
|
|
LASSERT(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
|
|
|
{
|
2008-02-27 23:03:26 +00:00
|
|
|
return text_.labelFont(pi_.base.bv->buffer(), par_);
|
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
|
|
|
|
bool pi_full_repaint = pi_.full_repaint;
|
|
|
|
|
2005-12-17 15:03:41 +00:00
|
|
|
// FIXME: We should always use font, see documentation of
|
2007-04-29 13:39:47 +00:00
|
|
|
// noFontChange() in Inset.h.
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.base.font = inset->noFontChange() ?
|
2007-10-28 18:51:54 +00:00
|
|
|
pi_.base.bv->buffer().params().getFont().fontInfo() :
|
2007-10-28 22:49:49 +00:00
|
|
|
font.fontInfo();
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.ltr_pos = (bidi_.level(pos) % 2 == 0);
|
|
|
|
pi_.erased_ = erased_ || par_.isDeleted(pos);
|
2007-09-17 21:45:14 +00:00
|
|
|
pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_);
|
2007-08-27 14:38:29 +00:00
|
|
|
// insets are painted completely. Recursive
|
2008-10-25 10:47:38 +00:00
|
|
|
inset->drawBackground(pi_, int(x_), yo_);
|
2007-08-30 13:53:02 +00:00
|
|
|
inset->drawSelection(pi_, int(x_), yo_);
|
|
|
|
inset->draw(pi_, int(x_), 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;
|
|
|
|
|
2006-11-03 15:39:58 +00:00
|
|
|
#ifdef DEBUG_METRICS
|
2007-09-21 20:39:47 +00:00
|
|
|
int const x1 = int(x_ - dim.width());
|
|
|
|
Dimension dim2;
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(max_witdh_ > 0, /**/);
|
2006-12-29 23:54:48 +00:00
|
|
|
int right_margin = text_metrics_.rightMargin(pm_);
|
|
|
|
int const w = max_witdh_ - leftMargin() - right_margin;
|
2007-10-28 22:49:49 +00:00
|
|
|
MetricsInfo mi(pi_.base.bv, font.fontInfo(), w);
|
2007-09-21 20:39:47 +00:00
|
|
|
inset->metrics(mi, dim2);
|
|
|
|
if (dim.wid != dim2.wid)
|
2006-11-03 15:39:58 +00:00
|
|
|
lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
|
2007-09-21 20:39:47 +00:00
|
|
|
<< " draw width " << dim.width()
|
2007-12-12 19:28:07 +00:00
|
|
|
<< "> metrics width " << dim2.wid << "." << endl;
|
2007-09-21 20:39:47 +00:00
|
|
|
if (dim->asc != dim2.asc)
|
2006-11-03 15:39:58 +00:00
|
|
|
lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
|
2007-09-21 20:39:47 +00:00
|
|
|
<< " draw ascent " << dim.ascent()
|
2007-12-12 19:28:07 +00:00
|
|
|
<< "> metrics ascent " << dim2.asc << "." << endl;
|
2007-09-21 20:39:47 +00:00
|
|
|
if (dim2.descent() != dim.des)
|
2006-11-03 15:39:58 +00:00
|
|
|
lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
|
2007-09-21 20:39:47 +00:00
|
|
|
<< " draw ascent " << dim.descent()
|
2007-12-12 19:28:07 +00:00
|
|
|
<< "> metrics descent " << dim2.des << "." << endl;
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(dim2.wid == dim.wid, /**/);
|
|
|
|
LASSERT(dim2.asc == dim.asc, /**/);
|
|
|
|
LASSERT(dim2.des == dim.des, /**/);
|
2006-11-03 15:39:58 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
void RowPainter::paintHebrewComposeChar(pos_type & vpos, FontInfo const & font)
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2007-06-07 20:39:14 +00:00
|
|
|
pos_type pos = bidi_.vis2log(vpos);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2006-10-17 14:46:45 +00:00
|
|
|
docstring str;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
// first char
|
2006-04-09 02:30:40 +00:00
|
|
|
char_type c = par_.getChar(pos);
|
2003-02-26 17:04:10 +00:00
|
|
|
str += c;
|
|
|
|
++vpos;
|
|
|
|
|
2006-10-11 17:24:46 +00:00
|
|
|
int const width = theFontMetrics(font).width(c);
|
2003-02-26 17:04:10 +00:00
|
|
|
int dx = 0;
|
|
|
|
|
|
|
|
for (pos_type i = pos - 1; i >= 0; --i) {
|
2004-08-15 00:01:45 +00:00
|
|
|
c = par_.getChar(i);
|
2008-03-21 21:47:37 +00:00
|
|
|
if (!Encodings::isHebrewComposeChar(c)) {
|
2006-04-08 09:09:57 +00:00
|
|
|
if (isPrintableNonspace(c)) {
|
2007-08-18 21:17:10 +00:00
|
|
|
int const width2 = pm_.singleWidth(i,
|
2008-02-27 23:03:26 +00:00
|
|
|
text_metrics_.displayFont(pit_, i));
|
2007-03-25 14:04:29 +00:00
|
|
|
dx = (c == 0x05e8 || // resh
|
|
|
|
c == 0x05d3) // dalet
|
2003-02-26 17:04:10 +00:00
|
|
|
? width2 - width
|
|
|
|
: (width2 - width) / 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw nikud
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.pain.text(int(x_) + dx, yo_, str, font);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
void RowPainter::paintArabicComposeChar(pos_type & vpos, FontInfo const & font)
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2007-06-07 20:39:14 +00:00
|
|
|
pos_type pos = bidi_.vis2log(vpos);
|
2006-10-17 14:46:45 +00:00
|
|
|
docstring str;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
// first char
|
2006-04-09 02:30:40 +00:00
|
|
|
char_type c = par_.getChar(pos);
|
2004-08-15 00:01:45 +00:00
|
|
|
c = par_.transformChar(c, pos);
|
2004-01-26 10:13:15 +00:00
|
|
|
str += c;
|
2003-02-26 17:04:10 +00:00
|
|
|
++vpos;
|
|
|
|
|
2006-10-11 17:24:46 +00:00
|
|
|
int const width = theFontMetrics(font).width(c);
|
2003-02-26 17:04:10 +00:00
|
|
|
int dx = 0;
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
for (pos_type i = pos - 1; i >= 0; --i) {
|
2004-08-15 00:01:45 +00:00
|
|
|
c = par_.getChar(i);
|
2008-03-21 21:47:37 +00:00
|
|
|
if (!Encodings::isArabicComposeChar(c)) {
|
2006-04-08 09:09:57 +00:00
|
|
|
if (isPrintableNonspace(c)) {
|
2007-08-18 21:17:10 +00:00
|
|
|
int const width2 = pm_.singleWidth(i,
|
2008-02-27 23:03:26 +00:00
|
|
|
text_metrics_.displayFont(pit_, i));
|
2003-02-26 17:04:10 +00:00
|
|
|
dx = (width2 - width) / 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Draw nikud
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.pain.text(int(x_) + dx, yo_, str, font);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2007-02-26 15:13:08 +00:00
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
void RowPainter::paintChars(pos_type & vpos, FontInfo const & font,
|
2005-06-10 14:55:01 +00:00
|
|
|
bool hebrew, bool arabic)
|
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);
|
2003-02-26 17:04:10 +00:00
|
|
|
// first character
|
2007-12-12 19:28:07 +00:00
|
|
|
vector<char_type> str;
|
2006-10-22 13:51:37 +00:00
|
|
|
str.reserve(100);
|
2006-08-13 22:54:59 +00:00
|
|
|
str.push_back(par_.getChar(pos));
|
2006-10-22 18:49:18 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
if (arabic) {
|
2006-08-13 22:54:59 +00:00
|
|
|
char_type c = str[0];
|
2007-05-31 18:53:01 +00:00
|
|
|
if (c == '(')
|
|
|
|
c = ')';
|
|
|
|
else if (c == ')')
|
|
|
|
c = '(';
|
2004-08-15 00:01:45 +00:00
|
|
|
str[0] = par_.transformChar(c, pos);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2008-05-14 15:37:20 +00:00
|
|
|
pos_type const end = row_.endpos();
|
|
|
|
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);
|
2008-09-22 15:41:05 +00:00
|
|
|
|
2008-03-29 11:21:36 +00:00
|
|
|
// selected text?
|
2008-05-14 15:16:10 +00:00
|
|
|
bool const selection = pos >= row_.sel_beg && pos < row_.sel_end;
|
2008-03-29 11:21:36 +00:00
|
|
|
|
2008-09-30 18:00:02 +00:00
|
|
|
char_type prev_char = ' ';
|
2003-02-26 17:04:10 +00:00
|
|
|
// collect as much similar chars as we can
|
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);
|
2005-07-18 12:13:32 +00:00
|
|
|
if (pos < font_span.first || pos > font_span.last)
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-14 15:16:10 +00:00
|
|
|
bool const new_selection = pos >= row_.sel_beg && pos < row_.sel_end;
|
2008-05-14 15:37:20 +00:00
|
|
|
if (new_selection != selection)
|
|
|
|
// Selection ends or starts here.
|
2008-03-29 11:21:36 +00:00
|
|
|
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
|
|
|
|
2006-04-09 02:30:40 +00:00
|
|
|
char_type c = par_.getChar(pos);
|
2005-06-10 14:55:01 +00:00
|
|
|
|
2008-09-30 18:00:02 +00:00
|
|
|
if (c == '\t' || prev_char == '\t') {
|
|
|
|
prev_char = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-04-08 09:09:57 +00:00
|
|
|
if (!isPrintableNonspace(c))
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2007-03-25 10:53:01 +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
|
|
|
|
* again. In order to avoid that, we don't collect Hebrew/
|
|
|
|
* Arabic characters, but rather paint them one at a time.
|
|
|
|
* See also http://thread.gmane.org/gmane.editors.lyx.devel/79740
|
|
|
|
*/
|
2007-05-28 22:27:45 +00:00
|
|
|
if (hebrew)
|
2007-03-23 09:18:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* FIXME: these checks are irrelevant, since 'arabic' and
|
|
|
|
* 'hebrew' alone are already going to trigger a break.
|
|
|
|
* However, this should not be removed completely, because
|
|
|
|
* if an alternative solution is found which allows grouping
|
|
|
|
* of arabic and hebrew characters, then these breaks may have
|
|
|
|
* to be re-applied.
|
|
|
|
|
2008-03-21 21:47:37 +00:00
|
|
|
if (arabic && Encodings::isArabicComposeChar(c))
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
2003-10-23 08:15:57 +00:00
|
|
|
|
2008-03-21 21:47:37 +00:00
|
|
|
if (hebrew && Encodings::isHebrewComposeChar(c))
|
2003-02-26 17:04:10 +00:00
|
|
|
break;
|
2007-03-23 09:18:07 +00:00
|
|
|
*/
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2007-03-23 09:18:07 +00:00
|
|
|
if (arabic) {
|
2007-05-31 18:53:01 +00:00
|
|
|
if (c == '(')
|
|
|
|
c = ')';
|
|
|
|
else if (c == ')')
|
|
|
|
c = '(';
|
2004-08-15 00:01:45 +00:00
|
|
|
c = par_.transformChar(c, pos);
|
2007-03-25 10:53:01 +00:00
|
|
|
/* see comment in hebrew, explaining why we break */
|
2007-03-23 09:18:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-27 15:39:59 +00:00
|
|
|
|
2006-08-13 22:54:59 +00:00
|
|
|
str.push_back(c);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2007-02-26 15:13:08 +00:00
|
|
|
docstring s(&str[0], str.size());
|
|
|
|
|
2008-09-30 18:00:02 +00:00
|
|
|
if (s[0] == '\t')
|
|
|
|
s.replace(0,1,from_ascii(" "));
|
|
|
|
|
2008-09-22 15:30:26 +00:00
|
|
|
if (!selection && !change_running.changed()) {
|
2007-08-30 13:53:02 +00:00
|
|
|
x_ += pi_.pain.text(int(x_), yo_, s, font);
|
2008-05-14 15:24:36 +00:00
|
|
|
return;
|
2006-10-22 18:49:18 +00:00
|
|
|
}
|
2008-05-14 15:24:36 +00:00
|
|
|
|
|
|
|
FontInfo copy = font;
|
2008-09-22 15:30:26 +00:00
|
|
|
if (change_running.changed())
|
2009-03-14 20:41:04 +00:00
|
|
|
copy.setPaintColor(change_running.color());
|
2008-07-28 14:58:29 +00:00
|
|
|
else if (selection)
|
2009-03-14 20:41:04 +00:00
|
|
|
copy.setPaintColor(Color_selectiontext);
|
2008-05-14 15:24:36 +00:00
|
|
|
|
|
|
|
x_ += pi_.pain.text(int(x_), yo_, s, copy);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2006-02-03 17:21:51 +00:00
|
|
|
int const y = yo_ + 1 + desc;
|
2007-10-25 12:41:02 +00:00
|
|
|
pi_.pain.line(int(orig_x), y, int(x_), y, Color_language);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-22 17:26:03 +00:00
|
|
|
void RowPainter::paintFromPos(pos_type & vpos)
|
2003-02-26 17:04:10 +00:00
|
|
|
{
|
2007-06-07 20:39:14 +00:00
|
|
|
pos_type const pos = bidi_.vis2log(vpos);
|
2008-02-27 23:03:26 +00:00
|
|
|
Font const orig_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
|
|
|
|
|
|
|
// usual characters, no insets
|
2006-04-09 02:30:40 +00:00
|
|
|
char_type const c = par_.getChar(pos);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
// special case languages
|
2007-12-12 19:28:07 +00:00
|
|
|
string const & lang = orig_font.language()->lang();
|
2005-07-18 14:25:20 +00:00
|
|
|
bool const hebrew = lang == "hebrew";
|
2007-06-26 00:11:03 +00:00
|
|
|
bool const arabic = lang == "arabic_arabtex" || lang == "arabic_arabi" ||
|
|
|
|
lang == "farsi";
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
// draw as many chars as we can
|
|
|
|
if ((!hebrew && !arabic)
|
2008-03-21 21:47:37 +00:00
|
|
|
|| (hebrew && !Encodings::isHebrewComposeChar(c))
|
|
|
|
|| (arabic && !Encodings::isArabicComposeChar(c))) {
|
2007-10-28 18:51:54 +00:00
|
|
|
paintChars(vpos, orig_font.fontInfo(), hebrew, arabic);
|
2003-02-26 17:04:10 +00:00
|
|
|
} else if (hebrew) {
|
2007-10-28 18:51:54 +00:00
|
|
|
paintHebrewComposeChar(vpos, orig_font.fontInfo());
|
2003-02-26 17:04:10 +00:00
|
|
|
} else if (arabic) {
|
2007-10-28 18:51:54 +00:00
|
|
|
paintArabicComposeChar(vpos, orig_font.fontInfo());
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2007-10-29 08:52:13 +00:00
|
|
|
paintForeignMark(orig_x, orig_font.language());
|
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)
|
2007-08-30 13:53:02 +00:00
|
|
|
if (!par_.params().appendix() || !text_.isMainText(pi_.base.bv->buffer()))
|
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
|
2007-08-30 13:53:02 +00:00
|
|
|
if (text_.isMainText(pi_.base.bv->buffer()))
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
void RowPainter::paintFirst()
|
|
|
|
{
|
2004-08-15 00:01:45 +00:00
|
|
|
ParagraphParameters const & parparams = par_.params();
|
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?
|
2003-07-28 12:20:42 +00:00
|
|
|
if (parparams.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
|
|
|
|
2007-08-30 13:53:02 +00:00
|
|
|
Buffer const & buffer = pi_.base.bv->buffer();
|
2008-03-06 21:31:27 +00:00
|
|
|
Layout const & layout = par_.layout();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2008-03-15 00:22:54 +00:00
|
|
|
if (buffer.params().paragraph_separation == BufferParams::ParagraphSkipSeparation) {
|
2004-03-25 09:16:36 +00:00
|
|
|
if (pit_ != 0) {
|
2008-03-06 21:31:27 +00:00
|
|
|
if (layout.latextype == LATEX_PARAGRAPH
|
2004-08-15 00:01:45 +00:00
|
|
|
&& !par_.getDepth()) {
|
2007-08-30 13:53:02 +00:00
|
|
|
y_top += buffer.params().getDefSkip().inPixels(*pi_.base.bv);
|
2003-02-26 17:04:10 +00:00
|
|
|
} else {
|
2008-03-06 21:31:27 +00:00
|
|
|
Layout const & playout = pars_[pit_ - 1].layout();
|
|
|
|
if (playout.latextype == LATEX_PARAGRAPH
|
2004-03-25 09:16:36 +00:00
|
|
|
&& !pars_[pit_ - 1].getDepth()) {
|
2003-02-26 17:04:10 +00:00
|
|
|
// is it right to use defskip here, too? (AS)
|
2007-08-30 13:53:02 +00:00
|
|
|
y_top += buffer.params().getDefSkip().inPixels(*pi_.base.bv);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Move BufferView cached pointer out of LyXText:
* LyXText
- bv(), bv_owner, : deleted.
- These methods now need a (Buffer const &) argument: getFont(), applyOuterFont(), getLayoutFont(), getLabelFont(), setCharFont(), setLayout(), singleWidth(), leftMargin(), rightMargin(), computeRowMetrics(), isMainText(), spacing(), isRTL(), cursorX(), rowBreakPoint(), setRowWidth(), labelFill(), labelEnd().
- These methods now need a (BufferView const &) argument and are propably candidates for future removal when 1.6 is opened for development: redoParagraph(), x2pos(), getRowNearY(), getColumnNearX(), checkInsetHit(), setHeightOfRow().
- recUndo(): now need a LCursor argument.
* CoordCache::get(LyXText const *, pit_type):
- now const.
- use const_iterator instead of iterator.
* FontIterator:
- add (Buffer const &) argument to ctor
- buffer_: new const reference to applicable BufferView.
* InsetBase
- xo(), yo(), covers() and neverIndent() are now const.
* InsetText::setViewCache(): deleted
All other changes are due to the LyXText and InsetBase API changes.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15618 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-30 12:45:33 +00:00
|
|
|
bool const is_rtl = text_.isRTL(buffer, par_);
|
2003-12-01 13:35:49 +00:00
|
|
|
bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
|
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
|
|
|
|
|
|
|
// should we print a label?
|
2008-03-06 21:31:27 +00:00
|
|
|
if (layout.labeltype >= LABEL_STATIC
|
|
|
|
&& (layout.labeltype != LABEL_STATIC
|
|
|
|
|| layout.latextype != LATEX_ENVIRONMENT
|
2003-10-22 16:30:57 +00:00
|
|
|
|| is_seq)) {
|
2003-02-26 17:04:10 +00:00
|
|
|
|
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
|
|
|
|
2008-02-23 16:45:38 +00:00
|
|
|
docstring const str = par_.labelString();
|
2005-04-19 09:04:25 +00:00
|
|
|
if (!str.empty()) {
|
2003-07-28 12:20:42 +00:00
|
|
|
double x = x_;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
// this is special code for the chapter layout. This is
|
|
|
|
// printed in an extra row and has a pagebreak at
|
|
|
|
// the top.
|
2008-03-06 21:31:27 +00:00
|
|
|
if (layout.counter == "chapter") {
|
2005-04-19 09:04:25 +00:00
|
|
|
double spacing_val = 1.0;
|
|
|
|
if (!parparams.spacing().isDefault()) {
|
|
|
|
spacing_val = parparams.spacing().getValue();
|
|
|
|
} else {
|
|
|
|
spacing_val = buffer.params().spacing().getValue();
|
|
|
|
}
|
2005-09-19 10:18:37 +00:00
|
|
|
|
2008-03-06 21:31:27 +00:00
|
|
|
int const labeladdon = int(fm.maxHeight() * layout.spacing.getValue() * spacing_val);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2008-03-06 21:31:27 +00:00
|
|
|
int const maxdesc = int(fm.maxDescent() * layout.spacing.getValue() * spacing_val)
|
|
|
|
+ int(layout.parsep) * defaultRowHeight();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2005-04-19 09:04:25 +00:00
|
|
|
if (is_rtl) {
|
|
|
|
x = width_ - leftMargin() -
|
2006-10-17 14:46:45 +00:00
|
|
|
fm.width(str);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
2005-04-26 11:12:20 +00:00
|
|
|
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
|
2003-02-26 17:04:10 +00:00
|
|
|
} else {
|
|
|
|
if (is_rtl) {
|
2004-02-27 09:18:03 +00:00
|
|
|
x = width_ - leftMargin()
|
2008-03-06 21:31:27 +00:00
|
|
|
+ fm.width(layout.labelsep);
|
2003-02-26 17:04:10 +00:00
|
|
|
} else {
|
2008-03-06 21:31:27 +00:00
|
|
|
x = x_ - fm.width(layout.labelsep)
|
2006-10-17 14:46:45 +00:00
|
|
|
- fm.width(str);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.pain.text(int(x), yo_, str, font);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// the labels at the top of an environment.
|
|
|
|
// More or less for bibliography
|
2003-10-22 16:30:57 +00:00
|
|
|
} else if (is_seq &&
|
2008-03-06 21:31:27 +00:00
|
|
|
(layout.labeltype == LABEL_TOP_ENVIRONMENT ||
|
|
|
|
layout.labeltype == LABEL_BIBLIO ||
|
|
|
|
layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
|
2008-02-27 23:03:26 +00:00
|
|
|
FontInfo const font = labelFont();
|
2008-02-23 16:45:38 +00:00
|
|
|
docstring const str = par_.labelString();
|
|
|
|
if (!str.empty()) {
|
2005-01-06 13:48:13 +00:00
|
|
|
double spacing_val = 1.0;
|
2005-07-18 14:25:20 +00:00
|
|
|
if (!parparams.spacing().isDefault())
|
2003-02-26 17:04:10 +00:00
|
|
|
spacing_val = parparams.spacing().getValue();
|
2005-07-18 14:25:20 +00:00
|
|
|
else
|
2003-09-09 17:00:19 +00:00
|
|
|
spacing_val = buffer.params().spacing().getValue();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2006-10-11 17:24:46 +00:00
|
|
|
FontMetrics const & fm = theFontMetrics(font);
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
|
|
int const labeladdon = int(fm.maxHeight()
|
2008-03-06 21:31:27 +00:00
|
|
|
* layout.spacing.getValue() * spacing_val);
|
2005-09-19 10:18:37 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
int maxdesc =
|
2008-03-06 21:31:27 +00:00
|
|
|
int(fm.maxDescent() * layout.spacing.getValue() * spacing_val
|
|
|
|
+ (layout.labelbottomsep * defaultRowHeight()));
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2003-07-28 12:20:42 +00:00
|
|
|
double x = x_;
|
2008-03-06 21:31:27 +00:00
|
|
|
if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
|
2005-12-02 13:20:26 +00:00
|
|
|
if (is_rtl)
|
|
|
|
x = leftMargin();
|
2006-12-29 23:54:48 +00:00
|
|
|
x += (width_ - text_metrics_.rightMargin(pm_) - leftMargin()) / 2;
|
2006-10-17 14:46:45 +00:00
|
|
|
x -= fm.width(str) / 2;
|
2003-02-26 17:04:10 +00:00
|
|
|
} else if (is_rtl) {
|
2006-10-17 14:46:45 +00:00
|
|
|
x = width_ - leftMargin() - fm.width(str);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
2007-08-30 13:53:02 +00:00
|
|
|
pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RowPainter::paintLast()
|
|
|
|
{
|
2007-08-30 13:53:02 +00:00
|
|
|
bool const is_rtl = text_.isRTL(pi_.base.bv->buffer(), par_);
|
2003-12-01 13:35:49 +00:00
|
|
|
int const endlabel = getEndLabel(pit_, text_.paragraphs());
|
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-03-14 20:41:04 +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,
|
2007-05-28 22:27:45 +00:00
|
|
|
Painter::line_solid, Painter::line_thick);
|
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,
|
2008-09-22 15:30:26 +00:00
|
|
|
yo_ + 2, col, Painter::line_solid, Painter::line_thick);
|
|
|
|
} else {
|
2008-09-22 15:41:05 +00:00
|
|
|
pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1,
|
2008-09-22 15:30:26 +00:00
|
|
|
yo_ + 2, col, Painter::line_solid, Painter::line_thick);
|
|
|
|
}
|
|
|
|
|
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-10-24 10:32:26 +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:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-30 13:19:24 +00:00
|
|
|
void RowPainter::paintOnlyInsets()
|
|
|
|
{
|
2009-02-11 14:44:35 +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);
|
2008-02-09 10:41:49 +00:00
|
|
|
if (!inset)
|
|
|
|
continue;
|
2009-02-11 14:44:35 +00:00
|
|
|
if (x_ > pi_.base.bv->workWidth()
|
|
|
|
|| !cache.getInsets().has(inset))
|
2007-08-30 13:19:24 +00:00
|
|
|
continue;
|
2009-02-11 14:44:35 +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();
|
|
|
|
if (cur.selection() && cur.text() == &text_
|
|
|
|
&& cur.anchor().text() == &text_)
|
|
|
|
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
|
|
|
{
|
2003-10-27 11:44:10 +00:00
|
|
|
pos_type const end = row_.endpos();
|
2007-07-09 17:18:35 +00:00
|
|
|
// 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;
|
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
|
|
|
|
if (vpos < font_span.first || vpos > font_span.last) {
|
|
|
|
font_span = par_.fontSpan(vpos);
|
2008-02-27 23:03:26 +00:00
|
|
|
font = text_metrics_.displayFont(pit_, vpos);
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
// split font span if inline completion is inside
|
2008-02-22 21:57:33 +00:00
|
|
|
if (font_span.first <= inlineCompletionVPos
|
|
|
|
&& font_span.last > inlineCompletionVPos)
|
|
|
|
font_span.last = inlineCompletionVPos;
|
2005-07-18 14:25:20 +00:00
|
|
|
}
|
|
|
|
|
2007-08-18 21:17:10 +00:00
|
|
|
const int width_pos = pm_.singleWidth(pos, font);
|
2005-07-18 14:25:20 +00:00
|
|
|
|
2004-08-15 16:52:44 +00:00
|
|
|
if (x_ + width_pos < 0) {
|
|
|
|
x_ += width_pos;
|
2003-02-26 17:04:10 +00:00
|
|
|
++vpos;
|
|
|
|
continue;
|
|
|
|
}
|
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
|
|
|
|
&& inset->editable() == Inset::HIGHLY_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());
|
2008-09-22 15:41:05 +00:00
|
|
|
int const y_bar = change_running.deleted() ?
|
2008-09-22 15:30:26 +00:00
|
|
|
yo_ - fm.maxAscent() / 3 : yo_ + fm.maxAscent() / 6;
|
|
|
|
pi_.pain.line(change_last_x, y_bar, int(x_), y_bar,
|
2008-09-22 15:41:05 +00:00
|
|
|
change_running.color(), Painter::line_solid,
|
2008-09-22 15:30:26 +00:00
|
|
|
Painter::line_thin);
|
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
|
|
|
|
2007-08-28 15:47:53 +00:00
|
|
|
x_ += row_.label_hfill + lwidth - width_pos;
|
2003-02-26 17:04:10 +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_;
|
2004-08-15 16:52:44 +00:00
|
|
|
x_ += width_pos;
|
2003-03-09 12:37:22 +00:00
|
|
|
if (pos >= body_pos)
|
2007-08-28 15:47:53 +00:00
|
|
|
x_ += row_.separator;
|
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_);
|
2008-10-25 10:47:38 +00:00
|
|
|
|
|
|
|
bool const pi_selected = pi_.selected;
|
|
|
|
Cursor const & cur = pi_.base.bv->cursor();
|
|
|
|
if (cur.selection() && cur.text() == &text_
|
|
|
|
&& cur.anchor().text() == &text_)
|
|
|
|
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.
|
2003-03-22 17:26:03 +00:00
|
|
|
paintFromPos(vpos);
|
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());
|
2008-09-22 15:41:05 +00:00
|
|
|
int const y_bar = change_running.deleted() ?
|
2008-09-22 15:30:26 +00:00
|
|
|
yo_ - fm.maxAscent() / 3 : yo_ + fm.maxAscent() / 6;
|
|
|
|
pi_.pain.line(change_last_x, y_bar, int(x_), y_bar,
|
|
|
|
change_running.color(), Painter::line_solid, Painter::line_thin);
|
|
|
|
change_running.setUnchanged();
|
2003-02-26 17:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-22 14:05:27 +00:00
|
|
|
|
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();
|
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;
|
2008-02-22 14:05:27 +00:00
|
|
|
|
2008-02-28 12:42:58 +00:00
|
|
|
// right to left?
|
|
|
|
if (rtl) {
|
|
|
|
swap(s1, s2);
|
|
|
|
swap(c1, c2);
|
|
|
|
}
|
|
|
|
|
2008-02-22 14:05:27 +00:00
|
|
|
if (s1.size() > 0) {
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s2.size() > 0) {
|
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
|