* Licence details can be found in the file COPYING.
*
* \author Asger Alstrup
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
* \author John Levon
- * \author André Pönitz
+ * \author André Pönitz
* \author Dekel Tsur
- * \author Jürgen Vigna
+ * \author Jürgen Vigna
* \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
#include "Cursor.h"
#include "CutAndPaste.h"
#include "FuncRequest.h"
+#include "HSpace.h"
#include "InsetList.h"
#include "Layout.h"
#include "Length.h"
#include "TextClass.h"
#include "VSpace.h"
+#include "insets/InsetText.h"
+
#include "mathed/MacroTable.h"
#include "mathed/MathMacroTemplate.h"
bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim, int min_width)
{
- LASSERT(mi.base.textwidth, /**/);
+ LASSERT(mi.base.textwidth > 0, /**/);
max_width_ = mi.base.textwidth;
// backup old dimension.
Dimension const old_dim = dim_;
// We specialize the 95% common case:
if (!par.getDepth()) {
Font f = par.getFontSettings(params, pos);
- if (!text_->isMainText(buffer))
+ if (!text_->isMainText())
applyOuterFont(f);
bool lab = layout.labeltype == LABEL_MANUAL && pos < body_pos;
Font font = par.getFontSettings(params, pos);
font.fontInfo().realize(layoutfont);
- if (!text_->isMainText(buffer))
+ if (!text_->isMainText())
applyOuterFont(font);
// Realize against environment font information
if (!lyxrc.rtl_support)
return false;
- // no RTL boundary at line start
+ // no RTL boundary at paragraph start
if (pos == 0)
return false;
- Paragraph const & par = text_->getPar(pit);
+ Font const & left_font = displayFont(pit, pos - 1);
- bool left = displayFont(pit, pos - 1).isVisibleRightToLeft();
- bool right;
- if (pos == par.size())
- right = par.isRTL(bv_->buffer().params());
- else
- right = displayFont(pit, pos).isVisibleRightToLeft();
- return left != right;
+ return isRTLBoundary(pit, pos, left_font);
}
if (!lyxrc.rtl_support)
return false;
+ // no RTL boundary at paragraph start
+ if (pos == 0)
+ return false;
+
+ ParagraphMetrics & pm = par_metrics_[pit];
+ // no RTL boundary in empty paragraph
+ if (pm.rows().empty())
+ return false;
+
+ pos_type endpos = pm.getRow(pos - 1, false).endpos();
+ pos_type startpos = pm.getRow(pos, false).pos();
+ // no RTL boundary at line start:
+ // abc\n -> toggle to RTL -> abc\n (and not: abc\n|
+ // | | )
+ if (pos == startpos && pos == endpos) // start of cur row, end of prev row
+ return false;
+
Paragraph const & par = text_->getPar(pit);
bool left = font.isVisibleRightToLeft();
bool right;
right = par.isRTL(bv_->buffer().params());
else
right = displayFont(pit, pos).isVisibleRightToLeft();
+
+ // no RTL boundary at line break:
+ // abc|\n -> move right -> abc\n (and not: abc\n|
+ // FED FED| FED )
+ if (startpos == pos && endpos == pos && endpos != par.size()
+ && (par.isNewline(pos - 1)
+ || par.isLineSeparator(pos - 1)
+ || par.isSeparator(pos - 1)))
+ return false;
+
return left != right;
}
LYXERR(Debug::INFO, "MacroContext not initialised!"
<< " Going through the buffer again and hope"
<< " the context is better then.");
- updateLabels(bv_->buffer());
+ bv_->buffer().updateLabels();
parPos = text_->macrocontextPosition();
LASSERT(!parPos.empty(), /**/);
parPos.pit() = pit;
row.label_hfill = 0;
row.separator = 0;
- Buffer & buffer = bv_->buffer();
Paragraph const & par = text_->getPar(pit);
double w = width - row.width();
//lyxerr << "row.width() " << row.width() << endl;
//lyxerr << "w " << w << endl;
- bool const is_rtl = text_->isRTL(buffer, par);
+ bool const is_rtl = text_->isRTL(par);
if (is_rtl)
row.x = rightMargin(pit);
else
break;
}
- // Display-style insets should always be on a centred row
+ // Display-style insets should always be on a centered row
if (Inset const * inset = par.getInset(row.pos())) {
switch (inset->display()) {
case Inset::AlignLeft:
align = LYX_ALIGN_CENTER;
break;
case Inset::Inline:
- case Inset::AlignRight:
// unchanged (use align)
break;
+ case Inset::AlignRight:
+ align = LYX_ALIGN_RIGHT;
+ break;
}
}
if (body_pos > 0
&& (body_pos > end || !par.isLineSeparator(body_pos - 1)))
{
- row.x += theFontMetrics(text_->labelFont(buffer, par)).
+ row.x += theFontMetrics(text_->labelFont(par)).
width(layout.labelsep);
if (body_pos <= end)
row.x += row.label_hfill;
int TextMetrics::labelFill(pit_type const pit, Row const & row) const
{
- Buffer & buffer = bv_->buffer();
Paragraph const & par = text_->getPar(pit);
pos_type last = par.beginOfBody();
return 0;
FontMetrics const & fm
- = theFontMetrics(text_->labelFont(buffer, par));
+ = theFontMetrics(text_->labelFont(par));
return max(0, fm.width(label) - w);
}
pit_type TextMetrics::rowBreakPoint(int width, pit_type const pit,
pit_type pos) const
{
- Buffer & buffer = bv_->buffer();
ParagraphMetrics const & pm = par_metrics_[pit];
Paragraph const & par = text_->getPar(pit);
pos_type const end = par.size();
// add the auto-hfill from label end to the body
if (body_pos && i == body_pos) {
FontMetrics const & fm = theFontMetrics(
- text_->labelFont(buffer, par));
+ text_->labelFont(par));
int add = fm.width(layout.labelsep);
if (par.isLineSeparator(i - 1))
add -= singleWidth(pit, i - 1);
int TextMetrics::rowWidth(int right_margin, pit_type const pit,
pos_type const first, pos_type const end) const
{
- Buffer & buffer = bv_->buffer();
// get the pure distance
ParagraphMetrics const & pm = par_metrics_[pit];
Paragraph const & par = text_->getPar(pit);
for ( ; i < end; ++i, ++fi) {
if (body_pos > 0 && i == body_pos) {
FontMetrics const & fm = theFontMetrics(
- text_->labelFont(buffer, par));
+ text_->labelFont(par));
w += fm.width(par.layout().labelsep);
if (par.isLineSeparator(i - 1))
w -= singleWidth(pit, i - 1);
if (body_pos > 0 && body_pos >= end) {
FontMetrics const & fm = theFontMetrics(
- text_->labelFont(buffer, par));
+ text_->labelFont(par));
w += fm.width(par.layout().labelsep);
if (end > 0 && par.isLineSeparator(end - 1))
w -= singleWidth(pit, end - 1);
Buffer const & buffer = bv_->buffer();
Font font = displayFont(pit, first);
FontSize const tmpsize = font.fontInfo().size();
- font.fontInfo() = text_->layoutFont(buffer, pit);
+ font.fontInfo() = text_->layoutFont(pit);
FontSize const size = font.fontInfo().size();
font.fontInfo().setSize(tmpsize);
- FontInfo labelfont = text_->labelFont(buffer, par);
+ FontInfo labelfont = text_->labelFont(par);
FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
FontMetrics const & fontmetrics = theFontMetrics(font);
// these are minimum values
double const spacing_val = layout.spacing.getValue()
- * text_->spacing(buffer, par);
+ * text_->spacing(par);
//lyxerr << "spacing_val = " << spacing_val << endl;
int maxasc = int(fontmetrics.maxAscent() * spacing_val);
int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
InsetList::const_iterator ii = par.insetList().begin();
InsetList::const_iterator iend = par.insetList().end();
for ( ; ii != iend; ++ii) {
- Dimension const & dim = pm.insetDimension(ii->inset);
if (ii->pos >= first && ii->pos < end) {
+ Dimension const & dim = pm.insetDimension(ii->inset);
maxasc = max(maxasc, dim.ascent());
maxdesc = max(maxdesc, dim.descent());
}
++maxdesc;
ParagraphList const & pars = text_->paragraphs();
+ Inset const & inset = par.inInset();
// is it a top line?
if (first == 0 && topBottomSpace) {
// some parskips VERY EASY IMPLEMENTATION
if (bufparams.paragraph_separation
== BufferParams::ParagraphSkipSeparation
- && par.ownerCode() != ERT_CODE
- && par.ownerCode() != LISTINGS_CODE
+ && inset.lyxCode() != ERT_CODE
+ && inset.lyxCode() != LISTINGS_CODE
&& pit > 0
&& ((layout.isParagraph() && par.getDepth() == 0)
|| (pars[pit - 1].layout().isParagraph()
&& !par.params().labelString().empty()) {
labeladdon = int(labelfont_metrics.maxHeight()
* layout.spacing.getValue()
- * text_->spacing(buffer, par));
+ * text_->spacing(par));
}
// special code for the top label
labeladdon = int(
labelfont_metrics.maxHeight()
* layout.spacing.getValue()
- * text_->spacing(buffer, par)
+ * text_->spacing(par)
+ (layout.topsep + layout.labelbottomsep) * dh);
}
last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) {
FontMetrics const & fm = theFontMetrics(
- text_->labelFont(buffer, par));
+ text_->labelFont(par));
tmpx += row.label_hfill + fm.width(layout.labelsep);
if (par.isLineSeparator(body_pos - 1))
tmpx -= singleWidth(pit, body_pos - 1);
// If lastrow is false, we don't need to compute
// the value of rtl.
- bool const rtl = lastrow ? text_->isRTL(buffer, par) : false;
+ bool const rtl = lastrow ? text_->isRTL(par) : false;
if (lastrow &&
((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
(!rtl && !left_side && vc == end && x > tmpx + 5))) {
if (y >= last->second.position() + int(pm_last.descent())) {
// We are looking for a position that is after the last paragraph in
- // the cache (which is in priciple off-screen, that is before the
+ // the cache (which is in priciple off-screen), that is before the
// visible part.
pit = last->first + 1;
if (pit == int(text_->paragraphs().size()))
}
-Row const & TextMetrics::getRowNearY(int y, pit_type pit) const
+Row const & TextMetrics::getPitAndRowNearY(int y, pit_type & pit,
+ bool assert_in_view, bool up)
{
ParagraphMetrics const & pm = par_metrics_[pit];
for (; rit != rlast; yy += rit->height(), ++rit)
if (yy + rit->height() > y)
break;
+
+ if (assert_in_view && yy + rit->height() != y) {
+ if (!up) {
+ if (rit != pm.rows().begin())
+ --rit;
+ else if (pit != 0) {
+ --pit;
+ newParMetricsUp();
+ ParagraphMetrics const & pm2 = par_metrics_[pit];
+ rit = pm2.rows().end();
+ --rit;
+ }
+ } else {
+ if (rit != rlast)
+ ++rit;
+ else if (pit != int(par_metrics_.size())) {
+ ++pit;
+ newParMetricsDown();
+ ParagraphMetrics const & pm2 = par_metrics_[pit];
+ rit = pm2.rows().begin();
+ }
+ }
+ }
return *rit;
}
// x,y are absolute screen coordinates
// sets cursor recursively descending into nested editable insets
-Inset * TextMetrics::editXY(Cursor & cur, int x, int y)
+Inset * TextMetrics::editXY(Cursor & cur, int x, int y,
+ bool assert_in_view, bool up)
{
if (lyxerr.debugging(Debug::WORKAREA)) {
LYXERR0("TextMetrics::editXY(cur, " << x << ", " << y << ")");
pit_type pit = getPitNearY(y);
LASSERT(pit != -1, return 0);
- Row const & row = getRowNearY(y, pit);
+ Row const & row = getPitAndRowNearY(y, pit, assert_in_view, up);
bool bound = false;
int xx = x; // is modified by getColumnNearX
}
ParagraphList const & pars = text_->paragraphs();
- Inset const * insetBefore = pos? pars[pit].getInset(pos - 1): 0;
+ Inset const * insetBefore = pos ? pars[pit].getInset(pos - 1) : 0;
//Inset * insetBehind = pars[pit].getInset(pos);
// This should be just before or just behind the
if (end <= row_pos)
cursor_vpos = row_pos;
else if (ppos >= end)
- cursor_vpos = text_->isRTL(buffer, par) ? row_pos : end;
+ cursor_vpos = text_->isRTL(par) ? row_pos : end;
else if (ppos > row_pos && ppos >= end)
// Place cursor after char at (logical) position pos - 1
cursor_vpos = (bidi.level(ppos - 1) % 2 == 0)
pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) {
FontMetrics const & labelfm = theFontMetrics(
- text_->labelFont(buffer, par));
+ text_->labelFont(par));
x += row.label_hfill + labelfm.width(par.layout().labelsep);
if (par.isLineSeparator(body_pos - 1))
x -= singleWidth(pit, body_pos - 1);
int l_margin = 0;
- if (text_->isMainText(buffer))
+ if (text_->isMainText())
l_margin += bv_->leftMargin();
l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
&& pit > 0 && pars[pit - 1].layout().nextnoindent)
parindent.erase();
- FontInfo const labelfont = text_->labelFont(buffer, par);
+ FontInfo const labelfont = text_->labelFont(par);
FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
switch (layout.margintype) {
case MARGIN_FIRST_DYNAMIC:
if (layout.labeltype == LABEL_MANUAL) {
- if (pos >= par.beginOfBody()) {
+ // if we are at position 0, we are never in the body
+ if (pos > 0 && pos >= par.beginOfBody())
l_margin += labelfont_metrics.signedWidth(layout.leftmargin);
- } else {
+ else
l_margin += labelfont_metrics.signedWidth(layout.labelindent);
- }
} else if (pos != 0
// Special case to fix problems with
// theorems (JMarc)
&& align == LYX_ALIGN_BLOCK
&& !par.params().noindent()
// in some insets, paragraphs are never indented
- && !par.inInset().neverIndent()
+ && !text_->inset().neverIndent()
// display style insets are always centered, omit indentation
&& !(!par.empty()
&& par.isInset(pos)
|| tclass.isPlainLayout(par.layout()))
|| buffer.params().paragraph_separation == BufferParams::ParagraphIndentSeparation)
)
- {
- l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
- parindent);
- }
-
+ {
+ // use the parindent of the layout when the default indentation is used
+ // otherwise use the indentation set in the document settings
+ if (buffer.params().getIndentation().asLyXCommand() == "default")
+ l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
+ parindent);
+ else
+ l_margin += buffer.params().getIndentation().inPixels(*bv_);
+ }
+
return l_margin;
}
// 12 lines lower):
if (lyxerr.debugging(Debug::PAINTING) && inside
&& (row.selection() || pi.full_repaint || row_has_changed)) {
- string const foreword = text_->isMainText(bv_->buffer()) ?
+ string const foreword = text_->isMainText() ?
"main text redraw " : "inset text redraw: ";
LYXERR(Debug::PAINTING, foreword << "pit=" << pit << " row=" << i
<< " row_selection=" << row.selection()
bool const begin_boundary = beg.pos() >= row.endpos();
bool const end_boundary = row.sel_end == row.endpos();
- Buffer & buffer = bv_->buffer();
DocIterator cur = beg;
cur.boundary(begin_boundary);
int x1 = cursorX(beg.top(), begin_boundary);
int const y1 = bv_->getPos(cur, cur.boundary()).y_ - row.ascent();
int const y2 = y1 + row.height();
- int const rm = text_->isMainText(buffer) ? bv_->rightMargin() : 0;
- int const lm = text_->isMainText(buffer) ? bv_->leftMargin() : 0;
+ int const rm = text_->isMainText() ? bv_->rightMargin() : 0;
+ int const lm = text_->isMainText() ? bv_->leftMargin() : 0;
// draw the margins
if (row.begin_margin_sel) {
- if (text_->isRTL(buffer, beg.paragraph())) {
+ if (text_->isRTL(beg.paragraph())) {
pi.pain.fillRectangle(x + x1, y1, width() - rm - x1, y2 - y1,
Color_selection);
} else {
}
if (row.end_margin_sel) {
- if (text_->isRTL(buffer, beg.paragraph())) {
+ if (text_->isRTL(beg.paragraph())) {
pi.pain.fillRectangle(x + lm, y1, x2 - lm, y2 - y1,
Color_selection);
} else {