#include "support/textutils.h"
#include "support/convert.h"
+#include <boost/current_function.hpp>
+
#include <sstream>
using lyx::pit_type;
void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
- string const & token, LyXFont & font)
+ string const & token, LyXFont & font, Change & change)
{
- static Change change;
-
BufferParams const & bp = buf.params();
if (token[0] != '\\') {
lex.nextToken();
string token = lex.getString();
LyXFont font;
+ Change change;
while (lex.isOK()) {
- readParToken(buf, par, lex, token, font);
+ readParToken(buf, par, lex, token, font, change);
lex.nextToken();
token = lex.getString();
int LyXText::singleWidth(Paragraph const & par,
pos_type pos, char c, LyXFont const & font) const
{
- BOOST_ASSERT(pos < par.size());
-
// The most common case is handled first (Asger)
if (IsPrintable(c)) {
Language const * language = font.language();
&& !isFirstInSequence(pit, pars_)))
&& align == LYX_ALIGN_BLOCK
&& !par.params().noindent()
+ // in some insets, paragraphs are never indented
+ && !(par.inInset() && par.inInset()->neverIndent())
// display style insets are always centered, omit indentation
&& !(!par.empty()
&& par.isInset(pos)
&& par.getInset(pos)->display())
- // in charstyles, tabulars and ert paragraphs are never indented!
- && ((par.ownerCode() != InsetBase::TEXT_CODE || isMainText())
- && par.ownerCode() != InsetBase::ERT_CODE
- && par.ownerCode() != InsetBase::CHARSTYLE_CODE)
&& (par.layout() != tclass.defaultLayout()
|| bv()->buffer()->params().paragraph_separation ==
BufferParams::PARSEP_INDENT))
pos_type i = pos;
for ( ; i < end; ++i, ++fi) {
char const c = par.getChar(i);
+ int thiswidth = singleWidth(par, i, c, *fi);
- {
- int thiswidth = singleWidth(par, i, c, *fi);
+ // add the auto-hfill from label end to the body
+ if (body_pos && i == body_pos) {
+ int add = font_metrics::width(layout->labelsep, getLabelFont(par));
+ if (par.isLineSeparator(i - 1))
+ add -= singleWidth(par, i - 1);
- // add the auto-hfill from label end to the body
- if (body_pos && i == body_pos) {
- int add = font_metrics::width(layout->labelsep, getLabelFont(par));
- if (par.isLineSeparator(i - 1))
- add -= singleWidth(par, i - 1);
-
- add = std::max(add, labelEnd(pit) - x);
- thiswidth += add;
- }
-
- x += thiswidth;
- chunkwidth += thiswidth;
+ add = std::max(add, labelEnd(pit) - x);
+ thiswidth += add;
}
+ x += thiswidth;
+ chunkwidth += thiswidth;
+
// break before a character that will fall off
// the right of the row
if (x >= width) {
if (bv_owner->text() == this) {
if (pit == 0 && row.pos() == 0)
maxasc += 20;
- if (pit + 1 == pars_.size() && row.endpos() == par.size())
+ if (pit + 1 == pit_type(pars_.size()) &&
+ row.endpos() == par.size())
maxdesc += 20;
}
return;
}
BOOST_ASSERT(cur.pos() > 0);
- if (par.isLineSeparator(cur.pos() - 1)
- || par.isNewline(cur.pos() - 1)) {
+ if ((par.isLineSeparator(cur.pos() - 1)
+ || par.isNewline(cur.pos() - 1))
+ && par.lookupChange(cur.pos() - 1) != Change::DELETED) {
static bool sent_space_message = false;
if (!sent_space_message) {
cur.message(_("You cannot type two spaces this way. "
current_font = rawtmpfont;
real_current_font = realtmpfont;
- //setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
- setCursor(cur, cur.pit(), cur.pos() + 1, false, true);
+ setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
charInserted();
}
InsetList::iterator iend = par.insetlist.end();
for (; ii != iend; ++ii) {
Dimension dim;
- int const w = maxwidth_ - leftMargin(pit) - rightMargin(par);
+ int const w = maxwidth_ - leftMargin(pit, ii->pos) - rightMargin(par);
MetricsInfo mi(bv(), getFont(par, ii->pos), w);
ii->inset->metrics(mi, dim);
}
X2 = !isRTL(par2) ? endx : 0 + dim_.wid;
}
- if (!above && !below && &par1.getRow(beg.pos(), end.boundary())
+ if (!above && !below && &par1.getRow(beg.pos(), beg.boundary())
== &par2.getRow(end.pos(), end.boundary()))
{
// paint only one rectangle
- pi.pain.fillRectangle(x + x1, y1, X2 - x1, y2 - y1,
- LColor::selection);
+ int const b( !isRTL(par1) ? x + x1 : x + X1 );
+ int const w( !isRTL(par1) ? X2 - x1 : x2 - X1 );
+ pi.pain.fillRectangle(b, y1, w, y2 - y1, LColor::selection);
return;
}
bool LyXText::read(Buffer const & buf, LyXLex & lex)
{
- static Change current_change;
-
Paragraph::depth_type depth = 0;
while (lex.isOK()) {
(body_pos > end || !par.isLineSeparator(body_pos - 1)))
body_pos = 0;
+ // Use font span to speed things up, see below
+ FontSpan font_span;
+ LyXFont font;
+
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) {
x -= singleWidth(par, body_pos - 1);
}
- x += singleWidth(par, pos);
+ // Use font span to speed things up, see above
+ if (pos < font_span.first || pos > font_span.last) {
+ font_span = par.fontSpan(pos);
+ font = getFont(par, pos);
+ }
+
+ x += singleWidth(par, pos, par.getChar(pos), font);
if (hfillExpansion(par, row, pos))
x += (pos >= body_pos) ? m.hfill : m.label_hfill;
// see correction above
if (boundary_correction)
- x += singleWidth(par, ppos);
-
+ if (getFont(par, ppos).isVisibleRightToLeft())
+ x -= singleWidth(par, ppos);
+ else
+ x += singleWidth(par, ppos);
+
+ // Make sure inside an inset we always count from the left
+ // edge (bidi!) -- MV
+ if (sl.pos() < par.size()) {
+ font = getFont(par, sl.pos());
+ if (!boundary && font.isVisibleRightToLeft()
+ && par.isInset(sl.pos()))
+ x -= par.getInset(sl.pos())->width();
+ }
return int(x);
}
// x,y are screen coordinates
// sets cursor only within this LyXText
-void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
+bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
{
pit_type pit = getPitNearY(y);
int yy = theCoords.get(this, pit).y_ - pars_[pit].ascent();
<< " pos: " << pos
<< endl;
- setCursor(cur, pit, pos, true, bound);
+ return setCursor(cur, pit, pos, true, bound);
}