The branch, betterpaint, has been created.
at 62ac77bfa885c25af226659351da03722f15922f (commit)
- Log -----------------------------------------------------------------
commit 62ac77bfa885c25af226659351da03722f15922f
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Mar 20 20:02:05 2016 +0100
Cleanup Painter text() API
* remove optional arguments to the helpers that use a FontInfo
* add a textwidth argument to the text() methods that are used by
rowpainter.
Now textwidth is only computed if a null value was passed to the
text() method. This means that in the use case of rowpainter, not
textwidth needs to be computed.
diff --git a/development/PAINTING_ANALYSIS b/development/PAINTING_ANALYSIS
index 4934c5e..5121769 100644
--- a/development/PAINTING_ANALYSIS
+++ b/development/PAINTING_ANALYSIS
@@ -60,6 +60,7 @@ cursor.
* Proposals
+
* Clean-up of drawing code
The goal is to make painting with drawing disable fast enough that it
@@ -81,7 +82,7 @@ paintInset needs to be called.
The only thing we want to do here is to set inset positions (for
text). The other insets still use the painter with drawing disabled.
-** Painter::text
+** DONE Painter::text
We cannot remove (or make private) the version that uses a
FontInfo because it is used by PainterInfo::draw. Document this and
diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index 40d2618..c57a68b 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -1,4 +1,4 @@
-/**
+**
* \file RowPainter.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
@@ -246,13 +246,14 @@ void RowPainter::paintStringAndSel(Row::Element const & e)
Color const col = e.change.changed() ? e.change.color()
: Color_selectiontext;
copy.fontInfo().setPaintColor(col);
- pi_.pain.text(int(x_), yo_, e.str, copy, e.extra);
+ pi_.pain.text(int(x_), yo_, e.str, copy, e.extra,
e.full_width());
} else if (!some_sel) {
- pi_.pain.text(int(x_), yo_, e.str, e.font, e.extra);
+ pi_.pain.text(int(x_), yo_, e.str, e.font, e.extra,
e.full_width());
} else {
pi_.pain.text(int(x_), yo_, e.str, e.font, Color_selectiontext,
- max(row_.sel_beg, e.pos) - e.pos,
- min(row_.sel_end, e.endpos) - e.pos, e.extra);
+ max(row_.sel_beg, e.pos) - e.pos,
+ min(row_.sel_end, e.endpos) - e.pos,
+ e.extra, e.full_width());
}
x_ += e.full_width();
}
diff --git a/src/frontends/Painter.h b/src/frontends/Painter.h
index 2106768..b62a4e5 100644
--- a/src/frontends/Painter.h
+++ b/src/frontends/Painter.h
@@ -133,21 +133,17 @@ public:
virtual void image(int x, int y, int w, int h,
graphics::Image const & image) = 0;
- /** draw a character at position x, y (y is the baseline)
- */
- virtual void text(int x, int y, char_type c, FontInfo const & f) = 0;
+ /// draw a string at position x, y (y is the baseline).
+ virtual void text(int x, int y, docstring const & str, FontInfo const &
f) = 0;
- /** draw a string at position x, y (y is the baseline). The
- * text direction is given by \c rtl.
- */
- virtual void text(int x, int y, docstring const & str, FontInfo const &
f,
- bool rtl = false, double wordspacing = 0.0) = 0;
+ /// draw a char at position x, y (y is the baseline)
+ virtual void text(int x, int y, char_type c, FontInfo const & f) = 0;
/** draw a string at position x, y (y is the baseline). The
* text direction is enforced by the \c Font.
*/
virtual void text(int x, int y, docstring const & str, Font const & f,
- double wordspacing = 0.0) = 0;
+ double wordspacing, double textwidth) = 0;
/** draw a string at position x, y (y is the baseline), but
* make sure that the part between \c from and \c to is in
@@ -155,7 +151,7 @@ public:
*/
virtual void text(int x, int y, docstring const & str, Font const & f,
Color other, size_type from, size_type to,
- double const wordspacing) = 0;
+ double wordspacing, double textwidth) = 0;
void setDrawingEnabled(bool drawing_enabled)
{ drawing_enabled_ = drawing_enabled; }
diff --git a/src/frontends/qt4/GuiPainter.cpp b/src/frontends/qt4/GuiPainter.cpp
index 40774dd..477ccbf 100644
--- a/src/frontends/qt4/GuiPainter.cpp
+++ b/src/frontends/qt4/GuiPainter.cpp
@@ -324,6 +324,12 @@ void GuiPainter::text(int x, int y, char_type c, FontInfo
const & f)
}
+void GuiPainter::text(int x, int y, docstring const & s, FontInfo const & f)
+{
+ text(x, y, s, f, false, 0.0, 0.0);
+}
+
+
void GuiPainter::do_drawText(int x, int y, QString str, bool rtl, FontInfo
const & f, QFont ff)
{
setQPainterPen(computeColor(f.realColor()));
@@ -361,7 +367,7 @@ void GuiPainter::do_drawText(int x, int y, QString str,
bool rtl, FontInfo const
void GuiPainter::text(int x, int y, docstring const & s,
FontInfo const & f, bool const rtl,
- double const wordspacing)
+ double const wordspacing, double const tw)
{
//LYXERR0("text: x=" << x << ", s=" << s);
if (s.empty() || !isDrawingEnabled())
@@ -373,8 +379,8 @@ void GuiPainter::text(int x, int y, docstring const & s,
of the symbol in the font (as given in lib/symbols) as a char_type to
the
frontend. This is just wrong, because the symbol is no UCS4 character at
all. You can think of this number as the code point of the symbol in a
- custom symbol encoding. It works because this char_type is lateron again
- interpreted as a position in the font again.
+ custom symbol encoding. It works because this char_type is later on
again
+ interpreted as a position in the font.
The correct solution would be to have extra functions for symbols, but
that
would require to duplicate a lot of frontend and mathed support code.
*/
@@ -391,11 +397,12 @@ void GuiPainter::text(int x, int y, docstring const & s,
ff.setWordSpacing(wordspacing);
GuiFontMetrics const & fm = getFontMetrics(f);
- // Here we use the font width cache instead of
- // textwidth = fontMetrics().width(str);
- // because the above is awfully expensive on MacOSX
- // Note that we have to take in account space stretching (word spacing)
- int const textwidth = fm.width(s) + count(s.begin(), s.end(), ' ') *
wordspacing;
+ int textwidth = 0;
+ if (tw == 0.0)
+ // Note that we have to take in account space stretching (word
spacing)
+ textwidth = fm.width(s) + count(s.begin(), s.end(), ' ') *
wordspacing;
+ else
+ textwidth = static_cast<int>(tw);
textDecoration(f, x, y, textwidth);
@@ -455,15 +462,15 @@ void GuiPainter::text(int x, int y, docstring const & s,
void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
- double const wordspacing)
+ double const wordspacing, double const tw)
{
- text(x, y, str, f.fontInfo(), f.isVisibleRightToLeft(), wordspacing);
+ text(x, y, str, f.fontInfo(), f.isVisibleRightToLeft(), wordspacing,
tw);
}
void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
Color other, size_type const from, size_type const to,
- double const wordspacing)
+ double const wordspacing, double const tw)
{
GuiFontMetrics const & fm = getFontMetrics(f.fontInfo());
FontInfo fi = f.fontInfo();
@@ -482,7 +489,7 @@ void GuiPainter::text(int x, int y, docstring const & str,
Font const & f,
fi.setPaintColor(other);
QRegion const clip(x + xmin, y - ascent, xmax - xmin, height);
setClipRegion(clip);
- text(x, y, str, fi, rtl, wordspacing);
+ text(x, y, str, fi, rtl, wordspacing, tw);
// Then the part in normal color
// Note that in Qt5, it is not possible to use Qt::UniteClip,
@@ -490,7 +497,7 @@ void GuiPainter::text(int x, int y, docstring const & str,
Font const & f,
fi.setPaintColor(orig);
QRegion region(viewport());
setClipRegion(region - clip);
- text(x, y, str, fi, rtl, wordspacing);
+ text(x, y, str, fi, rtl, wordspacing, tw);
setClipping(false);
}
diff --git a/src/frontends/qt4/GuiPainter.h b/src/frontends/qt4/GuiPainter.h
index 5b90961..e6521c1 100644
--- a/src/frontends/qt4/GuiPainter.h
+++ b/src/frontends/qt4/GuiPainter.h
@@ -105,17 +105,17 @@ public:
virtual void image(int x, int y, int w, int h,
lyx::graphics::Image const & image);
- /** draw a string at position x, y (y is the baseline). The
- * text direction is given by \c rtl.
- */
- virtual void text(int x, int y, docstring const & str, FontInfo const &
f,
- bool rtl = false, double wordspacing = 0.0);
+ /// draw a string at position x, y (y is the baseline).
+ virtual void text(int x, int y, docstring const & str, FontInfo const &
f);
+
+ /// draw a char at position x, y (y is the baseline)
+ virtual void text(int x, int y, char_type c, FontInfo const & f);
/** draw a string at position x, y (y is the baseline). The
* text direction is enforced by the \c Font.
*/
virtual void text(int x, int y, docstring const & str, Font const & f,
- double wordspacing = 0.0);
+ double wordspacing, double textwidth);
/** draw a string at position x, y (y is the baseline), but
* make sure that the part between \c from and \c to is in
@@ -123,10 +123,7 @@ public:
*/
virtual void text(int x, int y, docstring const & str, Font const & f,
Color other, size_type from, size_type to,
- double const wordspacing);
-
- /// draw a char at position x, y (y is the baseline)
- virtual void text(int x, int y, char_type c, FontInfo const & f);
+ double wordspacing, double textwidth);
///
virtual void textDecoration(FontInfo const & f, int x, int y, int
width);
@@ -136,11 +133,11 @@ public:
FontInfo const & font, bool mouseHover);
/// start monochrome painting mode, i.e. map every color into [min,max]
- virtual void enterMonochromeMode(Color const & min,
+ virtual void enterMonochromeMode(Color const & min,
Color const & max);
/// leave monochrome painting mode
virtual void leaveMonochromeMode();
-
+
/**
* Draw a string and enclose it inside a rectangle. If
* back color is specified, the background is cleared with
@@ -186,6 +183,11 @@ private:
// Helper for text() method
void do_drawText(int x, int y, QString str, bool rtl, FontInfo const &
f, QFont ff);
+ // Real text() method
+ void text(int x, int y, docstring const & s,
+ FontInfo const & f, bool const rtl,
+ double const wordspacing, double tw);
+
QColor current_color_;
Painter::line_style current_ls_;
int current_lw_;
commit db3d035089e988f4eef071e4f1885f5a451526c9
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sat Mar 19 17:52:07 2016 +0100
Make Painter::text return nothing
This value is not used anymore. Now in some cases we can avoid to
compute it at all.
diff --git a/src/frontends/Painter.h b/src/frontends/Painter.h
index c72d813..2106768 100644
--- a/src/frontends/Painter.h
+++ b/src/frontends/Painter.h
@@ -133,28 +133,29 @@ public:
virtual void image(int x, int y, int w, int h,
graphics::Image const & image) = 0;
+ /** draw a character at position x, y (y is the baseline)
+ */
+ virtual void text(int x, int y, char_type c, FontInfo const & f) = 0;
+
/** draw a string at position x, y (y is the baseline). The
* text direction is given by \c rtl.
- * \return the width of the drawn text.
*/
- virtual int text(int x, int y, docstring const & str, FontInfo const &
f,
- bool rtl = false, double wordspacing = 0.0) = 0;
+ virtual void text(int x, int y, docstring const & str, FontInfo const &
f,
+ bool rtl = false, double wordspacing = 0.0) = 0;
/** draw a string at position x, y (y is the baseline). The
* text direction is enforced by the \c Font.
- * \return the width of the drawn text.
*/
- virtual int text(int x, int y, docstring const & str, Font const & f,
- double wordspacing = 0.0) = 0;
+ virtual void text(int x, int y, docstring const & str, Font const & f,
+ double wordspacing = 0.0) = 0;
/** draw a string at position x, y (y is the baseline), but
* make sure that the part between \c from and \c to is in
* \c other color. The text direction is enforced by the \c Font.
- * \return the width of the drawn text.
*/
- virtual int text(int x, int y, docstring const & str, Font const & f,
- Color other, size_type from, size_type to,
- double const wordspacing) = 0;
+ virtual void text(int x, int y, docstring const & str, Font const & f,
+ Color other, size_type from, size_type to,
+ double const wordspacing) = 0;
void setDrawingEnabled(bool drawing_enabled)
{ drawing_enabled_ = drawing_enabled; }
@@ -164,12 +165,6 @@ public:
double pixelRatio() const { return pixel_ratio_; }
- /// draw a char at position x, y (y is the baseline)
- /**
- * \return the width of the drawn text.
- */
- virtual int text(int x, int y, char_type c, FontInfo const & f) = 0;
-
/// draw the underbar, strikeout, uuline and uwave font attributes
virtual void textDecoration(FontInfo const & f, int x, int y, int
width) = 0;
diff --git a/src/frontends/qt4/GuiPainter.cpp b/src/frontends/qt4/GuiPainter.cpp
index aad38b0..40774dd 100644
--- a/src/frontends/qt4/GuiPainter.cpp
+++ b/src/frontends/qt4/GuiPainter.cpp
@@ -318,9 +318,9 @@ void GuiPainter::image(int x, int y, int w, int h,
graphics::Image const & i)
}
-int GuiPainter::text(int x, int y, char_type c, FontInfo const & f)
+void GuiPainter::text(int x, int y, char_type c, FontInfo const & f)
{
- return text(x, y, docstring(1, c), f);
+ text(x, y, docstring(1, c), f);
}
@@ -359,13 +359,13 @@ void GuiPainter::do_drawText(int x, int y, QString str,
bool rtl, FontInfo const
}
-int GuiPainter::text(int x, int y, docstring const & s,
- FontInfo const & f, bool const rtl,
- double const wordspacing)
+void GuiPainter::text(int x, int y, docstring const & s,
+ FontInfo const & f, bool const rtl,
+ double const wordspacing)
{
//LYXERR0("text: x=" << x << ", s=" << s);
- if (s.empty())
- return 0;
+ if (s.empty() || !isDrawingEnabled())
+ return;
/* Caution: The following ucs4 to QString conversions work for symbol
fonts
only because they are no real conversions but simple casts in reality.
@@ -397,9 +397,6 @@ int GuiPainter::text(int x, int y, docstring const & s,
// Note that we have to take in account space stretching (word spacing)
int const textwidth = fm.width(s) + count(s.begin(), s.end(), ' ') *
wordspacing;
- if (!isDrawingEnabled())
- return textwidth;
-
textDecoration(f, x, y, textwidth);
if (use_pixmap_cache_) {
@@ -419,7 +416,7 @@ int GuiPainter::text(int x, int y, docstring const & s,
if (QPixmapCache::find(key, pm)) {
// Draw the cached pixmap.
drawPixmap(x + lb, y - mA, pm);
- return textwidth;
+ return;
}
// Only the right bearing of the last character is
@@ -447,27 +444,26 @@ int GuiPainter::text(int x, int y, docstring const & s,
drawPixmap(x + lb, y - mA, pm);
//rectangle(x-lb, y-mA, w, h, Color_green);
}
- return textwidth;
+ return;
}
// don't use the pixmap cache,
do_drawText(x, y, str, rtl, f, ff);
//LYXERR(Debug::PAINTING, "draw " << string(str.toUtf8())
// << " at " << x << "," << y);
- return textwidth;
}
-int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
- double const wordspacing)
+void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
+ double const wordspacing)
{
- return text(x, y, str, f.fontInfo(), f.isVisibleRightToLeft(),
wordspacing);
+ text(x, y, str, f.fontInfo(), f.isVisibleRightToLeft(), wordspacing);
}
-int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
- Color other, size_type const from, size_type const to,
- double const wordspacing)
+void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
+ Color other, size_type const from, size_type const to,
+ double const wordspacing)
{
GuiFontMetrics const & fm = getFontMetrics(f.fontInfo());
FontInfo fi = f.fontInfo();
@@ -486,7 +482,7 @@ int GuiPainter::text(int x, int y, docstring const & str,
Font const & f,
fi.setPaintColor(other);
QRegion const clip(x + xmin, y - ascent, xmax - xmin, height);
setClipRegion(clip);
- int const textwidth = text(x, y, str, fi, rtl, wordspacing);
+ text(x, y, str, fi, rtl, wordspacing);
// Then the part in normal color
// Note that in Qt5, it is not possible to use Qt::UniteClip,
@@ -496,8 +492,6 @@ int GuiPainter::text(int x, int y, docstring const & str,
Font const & f,
setClipRegion(region - clip);
text(x, y, str, fi, rtl, wordspacing);
setClipping(false);
-
- return textwidth;
}
diff --git a/src/frontends/qt4/GuiPainter.h b/src/frontends/qt4/GuiPainter.h
index 3819ff3..5b90961 100644
--- a/src/frontends/qt4/GuiPainter.h
+++ b/src/frontends/qt4/GuiPainter.h
@@ -107,29 +107,26 @@ public:
/** draw a string at position x, y (y is the baseline). The
* text direction is given by \c rtl.
- * \return the width of the drawn text.
*/
- virtual int text(int x, int y, docstring const & str, FontInfo const &
f,
- bool rtl = false, double wordspacing = 0.0);
+ virtual void text(int x, int y, docstring const & str, FontInfo const &
f,
+ bool rtl = false, double wordspacing = 0.0);
/** draw a string at position x, y (y is the baseline). The
* text direction is enforced by the \c Font.
- * \return the width of the drawn text.
*/
- virtual int text(int x, int y, docstring const & str, Font const & f,
- double wordspacing = 0.0);
+ virtual void text(int x, int y, docstring const & str, Font const & f,
+ double wordspacing = 0.0);
/** draw a string at position x, y (y is the baseline), but
* make sure that the part between \c from and \c to is in
* \c other color. The text direction is enforced by the \c Font.
- * \return the width of the drawn text.
*/
- virtual int text(int x, int y, docstring const & str, Font const & f,
- Color other, size_type from, size_type to,
- double const wordspacing);
+ virtual void text(int x, int y, docstring const & str, Font const & f,
+ Color other, size_type from, size_type to,
+ double const wordspacing);
/// draw a char at position x, y (y is the baseline)
- virtual int text(int x, int y, char_type c, FontInfo const & f);
+ virtual void text(int x, int y, char_type c, FontInfo const & f);
///
virtual void textDecoration(FontInfo const & f, int x, int y, int
width);
commit f4f3fa973ec37b34a052b93f37eb7958efea550a
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sat Mar 19 17:26:25 2016 +0100
Do not use the return value of Painter::text for logos
This will allow to get rid of this return value (and avoid computing it).
diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp
index 8fa6ead..8671d2b 100644
--- a/src/insets/InsetSpecialChar.cpp
+++ b/src/insets/InsetSpecialChar.cpp
@@ -135,7 +135,16 @@ void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension
& dim) const
namespace {
-void drawLogo(PainterInfo & pi, InsetSpecialChar::Kind kind, int & x, int & y)
{
+// helper function: draw text and update x.
+void drawChar(PainterInfo & pi, int & x, int const y, char_type ch)
+{
+ pi.pain.text(x, y, ch, pi.base.font);
+ x += theFontMetrics(pi.base.font).width(ch);
+}
+
+
+void drawLogo(PainterInfo & pi, int & x, int const y, InsetSpecialChar::Kind
kind)
+{
FontInfo const & font = pi.base.font;
int const em = theFontMetrics(font).em();
switch (kind) {
@@ -143,11 +152,11 @@ void drawLogo(PainterInfo & pi, InsetSpecialChar::Kind
kind, int & x, int & y) {
/** Reference macro:
*
\providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\\@};
*/
- x += pi.pain.text(x, y, from_ascii("L"), font);
+ drawChar(pi, x, y, 'L');
x -= em / 6;
- x += pi.pain.text(x, y + em / 4, from_ascii("Y"), font);
+ drawChar(pi, x, y + em / 4, 'Y');
x -= em / 8;
- x += pi.pain.text(x, y, from_ascii("X"), font);
+ drawChar(pi, x, y, 'X');
break;
case InsetSpecialChar::PHRASE_TEX: {
@@ -155,11 +164,11 @@ void drawLogo(PainterInfo & pi, InsetSpecialChar::Kind
kind, int & x, int & y) {
* \def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}
*/
int const ex = theFontMetrics(font).ascent('x');
- x += pi.pain.text(x, y, from_ascii("T"), font);
+ drawChar(pi, x, y, 'T');
x -= em / 6;
- x += pi.pain.text(x, y + ex / 2, from_ascii("E"), font);
+ drawChar(pi, x, y + ex / 2, 'E');
x -= em / 8;
- x += pi.pain.text(x, y, from_ascii("X"), font);
+ drawChar(pi, x, y, 'X');
break;
}
case InsetSpecialChar::PHRASE_LATEX2E:
@@ -168,10 +177,10 @@ void drawLogo(PainterInfo & pi, InsetSpecialChar::Kind
kind, int & x, int & y) {
* \if b\expandafter\@car\f@series\@nil\boldmath\fi
* \LaTeX\kern.15em2$_{\textstyle\varepsilon}$}}
*/
- drawLogo(pi, InsetSpecialChar::PHRASE_LATEX, x, y);
+ drawLogo(pi, x, y, InsetSpecialChar::PHRASE_LATEX);
x += 3 * em / 20;
- x += pi.pain.text(x, y, from_ascii("2"), font);
- x += pi.pain.text(x, y + em / 4, char_type(0x03b5), font);
+ drawChar(pi, x, y, '2');
+ drawChar(pi, x, y + em / 4, char_type(0x03b5));
break;
case InsetSpecialChar::PHRASE_LATEX: {
@@ -187,13 +196,13 @@ void drawLogo(PainterInfo & pi, InsetSpecialChar::Kind
kind, int & x, int & y) {
* \kern-.15em%
* \TeX}
*/
- x += pi.pain.text(x, y, from_ascii("L"), font);
+ drawChar(pi, x, y, 'L');
x -= 9 * em / 25;
- FontInfo smaller = font;
- smaller.decSize().decSize();
- x += pi.pain.text(x, y - em / 5, from_ascii("A"), smaller);
+ PainterInfo pi2 = pi;
+ pi2.base.font.decSize().decSize();
+ drawChar(pi2, x, y - em / 5, 'A');
x -= 3 * em / 20;
- drawLogo(pi, InsetSpecialChar::PHRASE_TEX, x, y);
+ drawLogo(pi, x, y, InsetSpecialChar::PHRASE_TEX);
break;
}
default:
@@ -269,7 +278,7 @@ void InsetSpecialChar::draw(PainterInfo & pi, int x, int y)
const
case PHRASE_TEX:
case PHRASE_LATEX2E:
case PHRASE_LATEX:
- drawLogo(pi, kind_, x, y);
+ drawLogo(pi, x, y, kind_);
break;
}
}
commit 989be39f48f7efe90d1e612ac6fb836faf79708b
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Mar 6 16:22:53 2016 +0100
Rewrite setRowHeight using row information
The initial values for maxasc and maxdes (renamed from maxdesc) is obtained
as a maximum of max ascents/descents of all row elements.
This allows to get rid of Paragraph::highestFontInRange and
FontList::highestInRange.
Some auxilliary variables declarations are also moved to where they are
needed.
diff --git a/src/FontList.cpp b/src/FontList.cpp
index e5a86db..1bfab76 100644
--- a/src/FontList.cpp
+++ b/src/FontList.cpp
@@ -180,31 +180,6 @@ void FontList::set(pos_type pos, Font const & font)
}
-FontSize FontList::highestInRange(pos_type startpos, pos_type endpos,
- FontSize def_size) const
-{
- if (list_.empty())
- return def_size;
-
- List::const_iterator end_it = fontIterator(endpos);
- const_iterator const end = list_.end();
- if (end_it != end)
- ++end_it;
-
- List::const_iterator cit = fontIterator(startpos);
-
- FontSize maxsize = FONT_SIZE_TINY;
- for (; cit != end_it; ++cit) {
- FontSize size = cit->font().fontInfo().size();
- if (size == FONT_SIZE_INHERIT)
- size = def_size;
- if (size > maxsize && size <= FONT_SIZE_HUGER)
- maxsize = size;
- }
- return maxsize;
-}
-
-
void FontList::validate(LaTeXFeatures & features) const
{
const_iterator fcit = list_.begin();
diff --git a/src/FontList.h b/src/FontList.h
index 9dfd527..6400f97 100644
--- a/src/FontList.h
+++ b/src/FontList.h
@@ -105,13 +105,6 @@ public:
///
void decreasePosAfterPos(pos_type pos);
- /// Returns the height of the highest font in range
- FontSize highestInRange(
- pos_type startpos,
- pos_type endpos,
- FontSize def_size
- ) const;
-
///
void validate(LaTeXFeatures & features) const;
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 734d18a..045d45e 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -1820,14 +1820,6 @@ Font const Paragraph::getLayoutFont
}
-/// Returns the height of the highest font in range
-FontSize Paragraph::highestFontInRange
- (pos_type startpos, pos_type endpos, FontSize def_size) const
-{
- return d->fontlist_.highestInRange(startpos, endpos, def_size);
-}
-
-
char_type Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
{
char_type c = d->text_[pos];
diff --git a/src/Paragraph.h b/src/Paragraph.h
index d0ed94b..02b2f17 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -356,9 +356,6 @@ public:
char_type getUChar(BufferParams const &, pos_type pos) const;
/// pos <= size() (there is a dummy font change at the end of each par)
void setFont(pos_type pos, Font const & font);
- /// Returns the height of the highest font in range
- FontSize highestFontInRange(pos_type startpos,
- pos_type endpos, FontSize def_size)
const;
///
void insert(pos_type pos, docstring const & str,
Font const & font, Change const & change);
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index ea8cf78..b09bbe2 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -913,85 +913,51 @@ void TextMetrics::setRowHeight(Row & row, pit_type const
pit,
bool topBottomSpace) const
{
Paragraph const & par = text_->getPar(pit);
- // get the maximum ascent and the maximum descent
- double layoutasc = 0;
- double layoutdesc = 0;
- double const dh = defaultRowHeight();
-
- // ok, let us initialize the maxasc and maxdesc value.
- // Only the fontsize count. The other properties
- // are taken from the layoutfont. Nicer on the screen :)
Layout const & layout = par.layout();
- // as max get the first character of this row then it can
- // increase but not decrease the height. Just some point to
- // start with so we don't have to do the assignment below too
- // often.
- Buffer const & buffer = bv_->buffer();
- Font font = displayFont(pit, row.pos());
- FontSize const tmpsize = font.fontInfo().size();
- font.fontInfo() = text_->layoutFont(pit);
- FontSize const size = font.fontInfo().size();
- font.fontInfo().setSize(tmpsize);
-
- FontInfo labelfont = text_->labelFont(par);
-
- FontMetrics const & lfm = theFontMetrics(labelfont);
- FontMetrics const & fm = theFontMetrics(font);
+ // this is what we want to compute
+ int maxasc = 0;
+ int maxdes = 0;
- // these are minimum values
+ // Find the ascent descent of the row contents
double const spacing_val = layout.spacing.getValue()
* text_->spacing(par);
- //lyxerr << "spacing_val = " << spacing_val << endl;
- int maxasc = int(fm.maxAscent() * spacing_val);
- int maxdesc = int(fm.maxDescent() * spacing_val);
-
- // insets may be taller
- CoordCache::Insets const & insetCache = bv_->coordCache().getInsets();
Row::const_iterator cit = row.begin();
Row::const_iterator cend = row.end();
for ( ; cit != cend; ++cit) {
if (cit->inset) {
- Dimension const & dim = insetCache.dim(cit->inset);
- maxasc = max(maxasc, dim.ascent());
- maxdesc = max(maxdesc, dim.descent());
+ maxasc = max(maxasc, cit->dim.ascent());
+ maxdes = max(maxdes, cit->dim.descent());
+ } else {
+ FontMetrics const & fm = theFontMetrics(cit->font);
+ maxasc = max(maxasc, int(fm.maxAscent() * spacing_val));
+ maxdes = max(maxdes, int(fm.maxDescent() *
spacing_val));
}
}
- // Check if any custom fonts are larger (Asger)
- // This is not completely correct, but we can live with the small,
- // cosmetic error for now.
- int labeladdon = 0;
-
- FontSize maxsize =
- par.highestFontInRange(row.pos(), row.endpos(), size);
- if (maxsize > font.fontInfo().size()) {
- // use standard paragraph font with the maximal size
- FontInfo maxfont = font.fontInfo();
- maxfont.setSize(maxsize);
- FontMetrics const & maxfontmetrics = theFontMetrics(maxfont);
- maxasc = max(maxasc, maxfontmetrics.maxAscent());
- maxdesc = max(maxdesc, maxfontmetrics.maxDescent());
- }
-
- // This is nicer with box insets:
+ // This is nicer with box insets
++maxasc;
- ++maxdesc;
+ ++maxdes;
+ // Now use the layout information.
+ double layoutasc = 0;
+ double layoutdesc = 0;
+ int labeladdon = 0;
ParagraphList const & pars = text_->paragraphs();
Inset const & inset = text_->inset();
+ double const dh = defaultRowHeight();
// is it a top line?
if (row.pos() == 0 && topBottomSpace) {
- BufferParams const & bufparams = buffer.params();
+ BufferParams const & bufparams = bv_->buffer().params();
// some parskips VERY EASY IMPLEMENTATION
if (bufparams.paragraph_separation ==
BufferParams::ParagraphSkipSeparation
&& !inset.getLayout().parbreakIsNewline()
&& !par.layout().parbreak_is_newline
&& pit > 0
&& ((layout.isParagraph() && par.getDepth() == 0)
- || (pars[pit - 1].layout().isParagraph()
- && pars[pit - 1].getDepth() == 0))) {
+ || (pars[pit - 1].layout().isParagraph()
+ && pars[pit - 1].getDepth() == 0))) {
maxasc += bufparams.getDefSkip().inPixels(*bv_);
}
@@ -1002,6 +968,8 @@ void TextMetrics::setRowHeight(Row & row, pit_type const
pit,
if (layout.labelIsAbove()
&& (!layout.isParagraphGroup() ||
text_->isFirstInSequence(pit))
&& !par.labelString().empty()) {
+ FontInfo labelfont = text_->labelFont(par);
+ FontMetrics const & lfm = theFontMetrics(labelfont);
labeladdon = int(
lfm.maxHeight()
* layout.spacing.getValue()
@@ -1064,8 +1032,8 @@ void TextMetrics::setRowHeight(Row & row, pit_type const
pit,
}
// incalculate the layout spaces
- maxasc += int(layoutasc * 2 / (2 + pars[pit].getDepth()));
- maxdesc += int(layoutdesc * 2 / (2 + pars[pit].getDepth()));
+ maxasc += int(layoutasc * 2 / (2 + pars[pit].getDepth()));
+ maxdes += int(layoutdesc * 2 / (2 + pars[pit].getDepth()));
// FIXME: the correct way is to do the following is to move the
// following code in another method specially tailored for the
@@ -1077,11 +1045,11 @@ void TextMetrics::setRowHeight(Row & row, pit_type
const pit,
if (pit + 1 == pit_type(pars.size()) &&
row.endpos() == par.size() &&
!(row.endpos() > 0 &&
par.isNewline(row.endpos() - 1)))
- maxdesc += 20;
+ maxdes += 20;
}
row.dimension().asc = maxasc + labeladdon;
- row.dimension().des = maxdesc;
+ row.dimension().des = maxdes;
}
commit 949f48c2d272d949299298412fc430480e6fac15
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sat Mar 5 23:11:45 2016 +0100
Simplify redoParagraph by merging duplicated code
Let breakRow return a boolean indicating whether an additional row is
required (after a newline) and use that to replace the code that added
an extra row when a paragraph ends with a newline.
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 5882eb5..ea8cf78 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -438,13 +438,14 @@ bool TextMetrics::redoParagraph(pit_type const pit)
par.setBeginOfBody();
pos_type first = 0;
size_t row_index = 0;
+ bool need_new_row = false;
// maximum pixel width of a row
do {
if (row_index == pm.rows().size())
pm.rows().push_back(Row());
Row & row = pm.rows()[row_index];
row.pos(first);
- breakRow(row, right_margin, pit);
+ need_new_row = breakRow(row, right_margin, pit);
setRowHeight(row, pit);
row.setChanged(false);
if (row_index || row.endpos() < par.size()
@@ -466,26 +467,11 @@ bool TextMetrics::redoParagraph(pit_type const pit)
pm.dim().wid = max(pm.dim().wid, row.width());
pm.dim().des += row.height();
- } while (first < par.size());
+ } while (first < par.size() || need_new_row);
if (row_index < pm.rows().size())
pm.rows().resize(row_index);
- // Make sure that if a par ends in newline, there is one more row
- // under it
- if (first > 0 && par.isNewline(first - 1)) {
- if (row_index == pm.rows().size())
- pm.rows().push_back(Row());
- Row & row = pm.rows()[row_index];
- row.pos(first);
- row.endpos(first);
- setRowHeight(row, pit);
- row.setChanged(false);
- int const max_row_width = max(dim_.wid, row.width());
- computeRowMetrics(pit, row, max_row_width);
- pm.dim().des += row.height();
- }
-
pm.dim().asc += pm.rows()[0].ascent();
pm.dim().des -= pm.rows()[0].ascent();
@@ -784,13 +770,14 @@ private:
* very sensitive to small changes :) Note that part of the
* intelligence is also in Row::shortenIfNeeded.
*/
-void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const
pit) const
+bool TextMetrics::breakRow(Row & row, int const right_margin, pit_type const
pit) const
{
Paragraph const & par = text_->getPar(pit);
pos_type const end = par.size();
pos_type const pos = row.pos();
pos_type const body_pos = par.beginOfBody();
bool const is_rtl = text_->isRTL(par);
+ bool need_new_row = false;
row.clear();
row.left_margin = leftMargin(max_width_, pit, pos);
@@ -805,11 +792,9 @@ void TextMetrics::breakRow(Row & row, int const
right_margin, pit_type const pit
if (pos >= end || row.width() > width) {
row.endpos(end);
- return;
+ return need_new_row;
}
- ParagraphList const & pars = text_->paragraphs();
-
#if 0
//FIXME: As long as leftMargin() is not correctly implemented for
// MARGIN_RIGHT_ADDRESS_BOX, we should also not do this here.
@@ -887,6 +872,7 @@ void TextMetrics::breakRow(Row & row, int const
right_margin, pit_type const pit
|| (!row.empty() && row.back().inset
&& row.back().inset->display())) {
row.right_boundary(true);
+ need_new_row = par.isNewline(i);
++i;
break;
}
@@ -898,6 +884,7 @@ void TextMetrics::breakRow(Row & row, int const
right_margin, pit_type const pit
row.endpos(i);
// End of paragraph marker
+ ParagraphList const & pars = text_->paragraphs();
if (lyxrc.paragraph_markers
&& i == end && size_type(pit + 1) < pars.size()) {
// add a virtual element for the end-of-paragraph
@@ -917,6 +904,8 @@ void TextMetrics::breakRow(Row & row, int const
right_margin, pit_type const pit
// make sure that the RTL elements are in reverse ordering
row.reverseRTL(is_rtl);
//LYXERR0("breakrow: row is " << row);
+
+ return need_new_row;
}
diff --git a/src/TextMetrics.h b/src/TextMetrics.h
index 35b5bdb..64b6473 100644
--- a/src/TextMetrics.h
+++ b/src/TextMetrics.h
@@ -131,7 +131,8 @@ private:
/// sets row.end to the pos value *after* which a row should break.
/// for example, the pos after which isNewLine(pos) == true
- void breakRow(Row & row, int right_margin, pit_type const pit) const;
+ /// \return true when another row is required (after a newline)
+ bool breakRow(Row & row, int right_margin, pit_type const pit) const;
// Expand the alignment of row \param row in paragraph \param par
LyXAlignment getAlign(Paragraph const & par, Row const & row) const;
commit 3810b52f7563877be8f2ffa595506612c1ac40d2
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sat Mar 5 00:09:34 2016 +0100
Update PAINTING_ANALYSIS
Some things were wrong, and some new ideas are added (some are done in
this branch already).
diff --git a/development/PAINTING_ANALYSIS b/development/PAINTING_ANALYSIS
index d1da54b..4934c5e 100644
--- a/development/PAINTING_ANALYSIS
+++ b/development/PAINTING_ANALYSIS
@@ -60,13 +60,75 @@ cursor.
* Proposals
-** set inset position during metrics phase
+* Clean-up of drawing code
-This implies to set inset positions relative to outer inset during
-metrics phase and then in a second loop to descend into insets and
-update positions correctly.
+The goal is to make painting with drawing disable fast enough that it
+can be used after every metrics computation. Then we can separate real
+drawing from metrics.
-Effect: avoid going through the painter machinery when it is not necessary.
+** DONE RowPainter
+
+Inset position is set in paintInset, paintOnlyInsets, and paintText.
+This should be done only once in paintInset
+
+** DONE TextMetrics::drawParagraph
+
+We can really simplify the code when drawing is disabled only
+paintInset needs to be called.
+ + do right at the start when drawing is already disabled
+ + do it in the loop for rows that are not visible on screen.
+
+The only thing we want to do here is to set inset positions (for
+text). The other insets still use the painter with drawing disabled.
+
+** Painter::text
+
+We cannot remove (or make private) the version that uses a
+FontInfo because it is used by PainterInfo::draw. Document this and
+remove unused arguments rtl and double spacing. This would become a
specialized helper.
+Proposed solution: keep the existing function, but private and without
+optional arguments.
+
+Avoid to return (and thus compute) the width of strings?
+ + used by InsetSpecialChar (fixable)
+ + used by textDecoration() in text(): more difficult to fix
+
+Idea: add a version of text where wordspacing and textwidth (giving
+the width of strings) are required parameters and remove optional
+version.
+
+==> more versions, no optional parameters.
+
+** Set inset position during metrics phase
+
+In order to do that, a no-paint drawing will be initiated after every
+redoParagraph. This code path will need to be made as fast as possible.
+
+Effect: avoid depending on actual drawing having taken place. In turn,
+it will allow to do drawing on paint events, like any reasonable
+application would do.
+
+** Cleanup after complete metrics
+ Then the following can be done:
+ + remove hack in InsetMathNest::drawSelection
+ + remove painting when not inside in drawParagraph
+ + remove Cursor::inCoordCache?
+
+** Use Row for MathData
+
+It may not be so difficult. Implement x2pos and pos2x from
+the TM:cursorX and TM::getPosNearX, and use them for both text and
+math.
+
+Will the strings display OK if drawing string-wise?
+
+Then it would be possible to streamline drawing with disabled painter.
+
+** Paint directly to screen
+
+Instead of using an intermediary pixmap. I have no idea of how
+difficult it will prove.
+One benefit will be that subpixel aliasing will work again (#9972)
** Merging bv::updateMetrics and tm::metrics
@@ -75,16 +137,10 @@ paragraphs that are rebroken, the version that is used for
inner inset
does not try any such optimization. This can be very bad for very tall
insets. We should re-use the bv::updateMetrics logic:
+ transfer all the logic of bv::updateMetrics to tm.
- + Main InsetText should not be special.
-
-** Metrics outside of visible area
-
-Currently metrics are computed for current visible paet of text, the
-page above and the page below. It should be possible to compute hidden
-rows ony on demand, although it might be a bit slow.
+ + Main InsetText should not be special.
-There was a proposal to always compute _all_ rows, but this may become
-expensive for large files. This would though help scrolling.
+The difficuly for a tall table cell for example, is that it may be
+necessary to break the whole contents to know the width of the cell.
* Description of current drawing mechanism
commit c1bbf74088a33c9cd7f2d9243abec24e9288510c
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Mon Feb 29 16:07:35 2016 +0100
Make the non-drawing cases faster in TextMetrics::drawParagraph
There are two main cases:
* when drawing is disabled from the start, use a simplified code that only
paints insets (in order to cache positions).
* when the row is not visible, do the same.
The goal of this optimization is to be able to always run a no-drawing draw
after the metrics have been computed.
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index d01d462..5882eb5 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1848,15 +1848,31 @@ void TextMetrics::draw(PainterInfo & pi, int x, int y)
const
void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int
const x, int y) const
{
- BufferParams const & bparams = bv_->buffer().params();
ParagraphMetrics const & pm = par_metrics_[pit];
if (pm.rows().empty())
return;
-
- bool const original_drawing_state = pi.pain.isDrawingEnabled();
- int const ww = bv_->workHeight();
size_t const nrows = pm.rows().size();
+ // Use fast lane when drawing is disabled.
+ if (!pi.pain.isDrawingEnabled()) {
+ for (size_t i = 0; i != nrows; ++i) {
+
+ Row const & row = pm.rows()[i];
+ // Adapt to cursor row scroll offset if applicable.
+ int row_x = x - bv_->horizScrollOffset(text_, pit,
row.pos());
+ if (i)
+ y += row.ascent();
+
+ RowPainter rp(pi, *text_, pit, row, row_x, y);
+
+ rp.paintOnlyInsets();
+ y += row.descent();
+ }
+ return;
+ }
+
+ BufferParams const & bparams = bv_->buffer().params();
+ int const ww = bv_->workHeight();
Cursor const & cur = bv_->cursor();
DocIterator sel_beg = cur.selectionBegin();
DocIterator sel_end = cur.selectionEnd();
@@ -1893,10 +1909,18 @@ void TextMetrics::drawParagraph(PainterInfo & pi,
pit_type const pit, int const
RowPainter rp(pi, *text_, pit, row, row_x, y);
+ // It is not needed to draw on screen if we are not inside.
bool const inside = (y + row.descent() >= 0
&& y - row.ascent() < ww);
- // It is not needed to draw on screen if we are not inside.
- pi.pain.setDrawingEnabled(inside && original_drawing_state);
+ pi.pain.setDrawingEnabled(inside);
+ if (!inside) {
+ // Paint only the insets to set inset cache correctly
+ // FIXME: remove paintOnlyInsets when we know that
positions
+ // have already been set.
+ rp.paintOnlyInsets();
+ y += row.descent();
+ continue;
+ }
if (selection)
row.setSelectionAndMargins(sel_beg_par, sel_end_par);
@@ -1913,8 +1937,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi,
pit_type const pit, int const
}
// Row signature; has row changed since last paint?
- if (pi.pain.isDrawingEnabled())
- row.setCrc(pm.computeRowSignature(row, bparams));
+ row.setCrc(pm.computeRowSignature(row, bparams));
bool row_has_changed = row.changed()
|| bv_->hadHorizScrollOffset(text_, pit, row.pos());
@@ -1945,7 +1968,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi,
pit_type const pit, int const
// Instrumentation for testing row cache (see also
// 12 lines lower):
- if (lyxerr.debugging(Debug::PAINTING) && inside
+ if (lyxerr.debugging(Debug::PAINTING)
&& (row.selection() || pi.full_repaint ||
row_has_changed)) {
string const foreword = text_->isMainText() ?
"main text redraw " : "inset text
redraw: ";
@@ -1983,7 +2006,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi,
pit_type const pit, int const
pi.full_repaint = tmp;
}
// Re-enable screen drawing for future use of the painter.
- pi.pain.setDrawingEnabled(original_drawing_state);
+ pi.pain.setDrawingEnabled(true);
//LYXERR(Debug::PAINTING, ".");
}
commit c30a698517f5f560480593168371d8154d5d4e8e
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Mon Feb 29 16:05:06 2016 +0100
Move some horizontal scrolling code from TextMetrics to BufferView
It is better to have all the code in the same place, and it will avoid code
duplication later.
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 9a549c0..1d29857 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -2906,15 +2906,26 @@ int BufferView::horizScrollOffset() const
}
-CursorSlice const & BufferView::currentRowSlice() const
-{
- return d->current_row_slice_;
+int BufferView::horizScrollOffset(Text const * text,
+ pit_type pit, pos_type pos) const
+{
+ // Is this a row that is currently scrolled?
+ if (!d->current_row_slice_.empty()
+ && &text->inset() == d->current_row_slice_.inset().asInsetText()
+ && pit == d->current_row_slice_.pit()
+ && pos == d->current_row_slice_.pos())
+ return d->horiz_scroll_offset_;
+ return 0;
}
-CursorSlice const & BufferView::lastRowSlice() const
+bool BufferView::hadHorizScrollOffset(Text const * text,
+ pit_type pit, pos_type pos) const
{
- return d->last_row_slice_;
+ return !d->last_row_slice_.empty()
+ && &text->inset() == d->last_row_slice_.inset().asInsetText()
+ && pit == d->last_row_slice_.pit()
+ && pos == d->last_row_slice_.pos();
}
diff --git a/src/BufferView.h b/src/BufferView.h
index 31b6e94..f57801f 100644
--- a/src/BufferView.h
+++ b/src/BufferView.h
@@ -125,12 +125,15 @@ public:
// Returns the amount of horizontal scrolling applied to the
// top-level row where the cursor lies
int horizScrollOffset() const;
-
- // Points to the top-level row where the cursor lies (during draw).
- CursorSlice const & currentRowSlice() const;
-
- // Points to the top-level row where the cursor lied at last draw event.
- CursorSlice const & lastRowSlice() const;
+ // Returns the amount of horizontal scrolling applied to the
+ // row of text starting at (pit, pos)
+ int horizScrollOffset(Text const * text,
+ pit_type pit, pos_type pos) const;
+
+ // Returns true if the row of text starting at (pit, pos) was scrolled
+ // at the last draw event.
+ bool hadHorizScrollOffset(Text const * text,
+ pit_type pit, pos_type pos) const;
/// reset the scrollbar to reflect current view position.
void updateScrollbar();
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 822199f..d01d462 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1886,26 +1886,18 @@ void TextMetrics::drawParagraph(PainterInfo & pi,
pit_type const pit, int const
for (size_t i = 0; i != nrows; ++i) {
Row const & row = pm.rows()[i];
- int row_x = x;
+ // Adapt to cursor row scroll offset if applicable.
+ int row_x = x - bv_->horizScrollOffset(text_, pit, row.pos());
if (i)
y += row.ascent();
- CursorSlice rowSlice(const_cast<InsetText &>(text_->inset()));
- rowSlice.pit() = pit;
- rowSlice.pos() = row.pos();
+ RowPainter rp(pi, *text_, pit, row, row_x, y);
bool const inside = (y + row.descent() >= 0
&& y - row.ascent() < ww);
-
- // Adapt to cursor row scroll offset if applicable.
- if (bv_->currentRowSlice() == rowSlice)
- row_x -= bv_->horizScrollOffset();
-
// It is not needed to draw on screen if we are not inside.
pi.pain.setDrawingEnabled(inside && original_drawing_state);
- RowPainter rp(pi, *text_, pit, row, row_x, y);
-
if (selection)
row.setSelectionAndMargins(sel_beg_par, sel_end_par);
else
@@ -1924,7 +1916,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi,
pit_type const pit, int const
if (pi.pain.isDrawingEnabled())
row.setCrc(pm.computeRowSignature(row, bparams));
bool row_has_changed = row.changed()
- || rowSlice == bv_->lastRowSlice();
+ || bv_->hadHorizScrollOffset(text_, pit, row.pos());
// Take this opportunity to spellcheck the row contents.
if (row_has_changed && pi.do_spellcheck &&
lyxrc.spellcheck_continuously) {
commit 640c70a1e808151b58820d9841a57d17204535f1
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Mon Feb 29 14:34:55 2016 +0100
Only add inset postion to cache in paintInset
It was also added in paintText and paintOnlyInsets.
diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index 2766642..40d2618 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -577,7 +577,6 @@ void RowPainter::paintOnlyInsets()
Row::Element const & e = *cit;
if (e.type == Row::INSET) {
// If outer row has changed, nested insets are
repainted completely.
- pi_.base.bv->coordCache().insets().add(e.inset,
int(x_), yo_);
bool const nested_inset =
(e.inset->asInsetMath() &&
!e.inset->asInsetMath()->asMacroTemplate())
|| e.inset->asInsetText() ||
e.inset->asInsetTabular();
@@ -611,8 +610,7 @@ void RowPainter::paintText()
paintMisspelledMark(orig_x, e);
break;
case Row::INSET: {
- // If outer row has changed, nested insets are repaint
completely.
- pi_.base.bv->coordCache().insets().add(e.inset,
int(x_), yo_);
+ // If outer row has changed, nested insets are
repainted completely.
paintInset(e);
foreign_descent = e.dim.descent();
}
commit 454af396dc178c37637831ad649c192b9ebe2b9c
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Mon Feb 29 14:27:51 2016 +0100
Remove variables set but not used
This was found by cppcheck.
diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index 37c8703..4248cea 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -951,8 +951,7 @@ bool handleFoundFile(string const & ff, DepTable & head)
return true;
// strip off part after last space and try again
string tmp = strippedfile;
- string const stripoff =
- rsplit(tmp, strippedfile, ' ');
+ rsplit(tmp, strippedfile, ' ');
absname.set(strippedfile);
if (insertIfExists(absname, head))
return true;
@@ -977,8 +976,7 @@ bool handleFoundFile(string const & ff, DepTable & head)
break;
// strip off part after last space and try again
string strippedfile;
- string const stripoff =
- rsplit(foundfile, strippedfile, ' ');
+ rsplit(foundfile, strippedfile, ' ');
foundfile = strippedfile;
onlyfile = onlyFileName(strippedfile);
absname = makeAbsPath(onlyfile);
diff --git a/src/frontends/qt4/GuiCommandBuffer.cpp
b/src/frontends/qt4/GuiCommandBuffer.cpp
index 9880e2b..b3f56c7 100644
--- a/src/frontends/qt4/GuiCommandBuffer.cpp
+++ b/src/frontends/qt4/GuiCommandBuffer.cpp
@@ -225,7 +225,6 @@ void GuiCommandBuffer::itemSelected(QListWidgetItem * item)
void GuiCommandBuffer::up()
{
- string const input = fromqstr(edit_->text());
string const h = historyUp();
if (!h.empty())
@@ -238,7 +237,6 @@ void GuiCommandBuffer::up()
void GuiCommandBuffer::down()
{
- string const input = fromqstr(edit_->text());
string const h = historyDown();
if (!h.empty())
diff --git a/src/insets/InsetGraphicsParams.cpp
b/src/insets/InsetGraphicsParams.cpp
index 03ca0d6..b7ea377 100644
--- a/src/insets/InsetGraphicsParams.cpp
+++ b/src/insets/InsetGraphicsParams.cpp
@@ -191,7 +191,6 @@ bool InsetGraphicsParams::Read(Lexer & lex, string const &
token,
lyxscale = lex.getInteger();
} else if (token == "display") {
lex.next();
- string const type = lex.getString();
display = lex.getString() != "false";
} else if (token == "scale") {
lex.next();
commit d3fcea878a0a8b9328c0c6fcadb727f4d69d445e
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Mon Feb 29 13:47:23 2016 +0100
Move one Text::setCursor instance to CursorSlice
This method did access more CursorSlice than Text. It is only a setter for
CursorSlice with some bound checking. The new signature is
setPitPos(pit_type, pos_type).
diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp
index ae3686f..573ca9d 100644
--- a/src/CursorSlice.cpp
+++ b/src/CursorSlice.cpp
@@ -92,6 +92,28 @@ CursorSlice::col_type CursorSlice::col() const
}
+void CursorSlice::setPitPos(pit_type pit, pos_type pos)
+{
+ LASSERT(pit != int(text()->paragraphs().size()), return);
+ pit_ = pit;
+ pos_ = pos;
+
+ // Now some strict checking. None of these should happen, but
+ // we're scaredy-cats
+ if (pos < 0) {
+ LYXERR0("Don't like -1!");
+ LATTEST(false);
+ }
+
+ if (pos > paragraph().size()) {
+ LYXERR0("Don't like 1, pos: " << pos
+ << " size: " << paragraph().size()
+ << " par: " << pit);
+ LATTEST(false);
+ }
+}
+
+
void CursorSlice::forwardPos()
{
// move on one position if possible
diff --git a/src/CursorSlice.h b/src/CursorSlice.h
index f44c92e..308b938 100644
--- a/src/CursorSlice.h
+++ b/src/CursorSlice.h
@@ -119,6 +119,8 @@ public:
Text * text() const { return inset_->getText(idx_); }
/// paragraph in this cell
Paragraph & paragraph() const;
+ ///
+ void setPitPos(pit_type pit, pos_type pos);
///
/// mathed specific stuff
diff --git a/src/Text.cpp b/src/Text.cpp
index 2e2abf6..83a3be4 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -1614,7 +1614,7 @@ bool Text::erase(Cursor & cur)
if (needsUpdate) {
// Make sure the cursor is correct. Is this really needed?
// No, not really... at least not here!
- cur.text()->setCursor(cur.top(), cur.pit(), cur.pos());
+ cur.top().setPitPos(cur.pit(), cur.pos());
cur.checkBufferStructure();
}
@@ -1721,7 +1721,7 @@ bool Text::backspace(Cursor & cur)
// A singlePar update is not enough in this case.
// cur.screenUpdateFlags(Update::Force);
- setCursor(cur.top(), cur.pit(), cur.pos());
+ cur.top().setPitPos(cur.pit(), cur.pos());
return needsUpdate;
}
diff --git a/src/Text.h b/src/Text.h
index fa42290..bdf2169 100644
--- a/src/Text.h
+++ b/src/Text.h
@@ -185,8 +185,6 @@ public:
bool setCursor(Cursor & cur, pit_type pit, pos_type pos,
bool setfont = true, bool boundary = false);
///
- void setCursor(CursorSlice &, pit_type pit, pos_type pos);
- ///
void setCursorIntern(Cursor & cur, pit_type pit,
pos_type pos, bool setfont = true, bool boundary = false);
diff --git a/src/Text2.cpp b/src/Text2.cpp
index ffde834..96d1035 100644
--- a/src/Text2.cpp
+++ b/src/Text2.cpp
@@ -558,36 +558,12 @@ bool Text::setCursor(Cursor & cur, pit_type pit, pos_type
pos,
}
-void Text::setCursor(CursorSlice & cur, pit_type pit, pos_type pos)
-{
- LASSERT(pit != int(paragraphs().size()), return);
- cur.pit() = pit;
- cur.pos() = pos;
-
- // now some strict checking
- Paragraph const & par = getPar(pit);
-
- // None of these should happen, but we're scaredy-cats
- if (pos < 0) {
- LYXERR0("Don't like -1!");
- LATTEST(false);
- }
-
- if (pos > par.size()) {
- LYXERR0("Don't like 1, pos: " << pos
- << " size: " << par.size()
- << " par: " << pit);
- LATTEST(false);
- }
-}
-
-
void Text::setCursorIntern(Cursor & cur, pit_type pit, pos_type pos,
bool setfont, bool boundary)
{
LBUFERR(this == cur.text());
cur.boundary(boundary);
- setCursor(cur.top(), pit, pos);
+ cur.top().setPitPos(pit, pos);
if (setfont)
cur.setCurrentFont();
}
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 5718278..bbeb264 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -250,7 +250,7 @@ void InsetText::edit(Cursor & cur, bool front,
EntryDirection entry_from)
pos = temp_cur.pos();
}
- text_.setCursor(cur.top(), pit, pos);
+ cur.top().setPitPos(pit, pos);
cur.finishUndo();
}
commit 281368c681252e1f92b6a13e4447b656f79b48e0
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Mon Feb 29 13:29:06 2016 +0100
Variables of type pit_type should be named pit, not par
It is easier to use always the same conventions for naming.
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 1d6e6cc..d906eae 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -100,11 +100,11 @@ bool checkPastePossible(int index)
struct PasteReturnValue {
- PasteReturnValue(pit_type r_par, pos_type r_pos, bool r_nu) :
- par(r_par), pos(r_pos), needupdate(r_nu)
+ PasteReturnValue(pit_type r_pit, pos_type r_pos, bool r_nu) :
+ pit(r_pit), pos(r_pos), needupdate(r_nu)
{}
- pit_type par;
+ pit_type pit;
pos_type pos;
bool needupdate;
};
@@ -965,14 +965,14 @@ void copySelectionToStack(Cursor const & cur, CutStack &
cutstack)
// copy behind a space if there is one
ParagraphList & pars = text->paragraphs();
pos_type pos = cur.selBegin().pos();
- pit_type par = cur.selBegin().pit();
- while (pos < pars[par].size() &&
- pars[par].isLineSeparator(pos) &&
- (par != cur.selEnd().pit() || pos < cur.selEnd().pos()))
+ pit_type pit = cur.selBegin().pit();
+ while (pos < pars[pit].size() &&
+ pars[pit].isLineSeparator(pos) &&
+ (pit != cur.selEnd().pit() || pos < cur.selEnd().pos()))
++pos;
- copySelectionHelper(*cur.buffer(), *text, par,
cur.selEnd().pit(),
- pos, cur.selEnd().pos(),
+ copySelectionHelper(*cur.buffer(), *text, pit,
cur.selEnd().pit(),
+ pos, cur.selEnd().pos(),
cur.buffer()->params().documentClassPtr(), cutstack);
// Reset the dirty_tabular_stack_ flag only when something
@@ -1083,7 +1083,7 @@ void pasteParagraphList(Cursor & cur, ParagraphList const
& parlist,
pasteSelectionHelper(cur, parlist, docclass, 0,
errorList);
cur.forceBufferUpdate();
cur.clearSelection();
- text->setCursor(cur, prv.par, prv.pos);
+ text->setCursor(cur, prv.pit, prv.pos);
}
// mathed is handled in InsetMathNest/InsetMathGrid
diff --git a/src/Text.cpp b/src/Text.cpp
index f9f76ec..2e2abf6 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -132,12 +132,12 @@ static bool moveItem(Paragraph & fromPar, pos_type
fromPos,
void breakParagraphConservative(BufferParams const & bparams,
- ParagraphList & pars, pit_type par_offset, pos_type pos)
+ ParagraphList & pars, pit_type pit, pos_type pos)
{
// create a new paragraph
- Paragraph & tmp = *pars.insert(lyx::next(pars.begin(), par_offset + 1),
+ Paragraph & tmp = *pars.insert(lyx::next(pars.begin(), pit + 1),
Paragraph());
- Paragraph & par = pars[par_offset];
+ Paragraph & par = pars[pit];
tmp.setInsetOwner(&par.inInset());
tmp.makeSameLayout(par);
diff --git a/src/Text.h b/src/Text.h
index 2d855ec..fa42290 100644
--- a/src/Text.h
+++ b/src/Text.h
@@ -182,12 +182,12 @@ public:
void rejectChanges();
/// returns true if par was empty and was removed
- bool setCursor(Cursor & cur, pit_type par, pos_type pos,
+ bool setCursor(Cursor & cur, pit_type pit, pos_type pos,
bool setfont = true, bool boundary = false);
///
- void setCursor(CursorSlice &, pit_type par, pos_type pos);
+ void setCursor(CursorSlice &, pit_type pit, pos_type pos);
///
- void setCursorIntern(Cursor & cur, pit_type par,
+ void setCursorIntern(Cursor & cur, pit_type pit,
pos_type pos, bool setfont = true, bool boundary = false);
/// Move cursor one position backwards
@@ -322,20 +322,20 @@ public:
docstring completionPrefix(Cursor const & cur) const;
/// find a paragraph before \p par with the given \p depth, if such
/// a paragraph cannot be found, \p par is returned
- pit_type depthHook(pit_type par, depth_type depth) const;
+ pit_type depthHook(pit_type pit, depth_type depth) const;
/// find a paragraph before \p par with depth less than the
/// depth of \p par. If such paragraph cannot be found because
/// \p par already has depth 0, lastpar + 1 is returned. If
/// such paragraph cannot be found because there isn't a par
/// with less depth before this one, \p par is returned.
- pit_type outerHook(pit_type par) const;
+ pit_type outerHook(pit_type pit) const;
/// Is it the first par with same depth and layout?
- bool isFirstInSequence(pit_type par) const;
+ bool isFirstInSequence(pit_type pit) const;
/// Is this paragraph in the table of contents?
- int getTocLevel(pit_type par) const;
+ int getTocLevel(pit_type pit) const;
/// Get the font of the "environment" of paragraph \p par_offset in \p
pars.
/// All font changes of the paragraph are relative to this font.
- Font const outerFont(pit_type par_offset) const;
+ Font const outerFont(pit_type pit_offset) const;
private:
/// The InsetText owner shall have access to everything.
@@ -383,7 +383,7 @@ private:
///
void breakParagraphConservative(BufferParams const & bparams,
ParagraphList & paragraphs,
- pit_type par,
+ pit_type pit,
pos_type pos);
/**
@@ -391,7 +391,7 @@ void breakParagraphConservative(BufferParams const &
bparams,
* Be careful, this doesent make any check at all.
*/
void mergeParagraph(BufferParams const & bparams,
- ParagraphList & paragraphs, pit_type par);
+ ParagraphList & paragraphs, pit_type pit);
/// accept the changes within the complete ParagraphList
void acceptChanges(ParagraphList & pars, BufferParams const & bparams);
diff --git a/src/Text2.cpp b/src/Text2.cpp
index c3d696e..ffde834 100644
--- a/src/Text2.cpp
+++ b/src/Text2.cpp
@@ -547,25 +547,25 @@ void Text::insertInset(Cursor & cur, Inset * inset)
}
-bool Text::setCursor(Cursor & cur, pit_type par, pos_type pos,
+bool Text::setCursor(Cursor & cur, pit_type pit, pos_type pos,
bool setfont, bool boundary)
{
TextMetrics const & tm = cur.bv().textMetrics(this);
- bool const update_needed = !tm.contains(par);
+ bool const update_needed = !tm.contains(pit);
Cursor old = cur;
- setCursorIntern(cur, par, pos, setfont, boundary);
+ setCursorIntern(cur, pit, pos, setfont, boundary);
return cur.bv().checkDepm(cur, old) || update_needed;
}
-void Text::setCursor(CursorSlice & cur, pit_type par, pos_type pos)
+void Text::setCursor(CursorSlice & cur, pit_type pit, pos_type pos)
{
- LASSERT(par != int(paragraphs().size()), return);
- cur.pit() = par;
+ LASSERT(pit != int(paragraphs().size()), return);
+ cur.pit() = pit;
cur.pos() = pos;
// now some strict checking
- Paragraph & para = getPar(par);
+ Paragraph const & par = getPar(pit);
// None of these should happen, but we're scaredy-cats
if (pos < 0) {
@@ -573,21 +573,21 @@ void Text::setCursor(CursorSlice & cur, pit_type par,
pos_type pos)
LATTEST(false);
}
- if (pos > para.size()) {
+ if (pos > par.size()) {
LYXERR0("Don't like 1, pos: " << pos
- << " size: " << para.size()
- << " par: " << par);
+ << " size: " << par.size()
+ << " par: " << pit);
LATTEST(false);
}
}
-void Text::setCursorIntern(Cursor & cur,
- pit_type par, pos_type pos, bool setfont, bool
boundary)
+void Text::setCursorIntern(Cursor & cur, pit_type pit, pos_type pos,
+ bool setfont, bool boundary)
{
LBUFERR(this == cur.text());
cur.boundary(boundary);
- setCursor(cur.top(), par, pos);
+ setCursor(cur.top(), pit, pos);
if (setfont)
cur.setCurrentFont();
}
commit c07208fbb4516d93b5c28bc63cb215b57c278355
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Feb 28 17:36:29 2016 +0100
Rename Cursor::setSelection(bool) to selection(bool)
The old name would be confusing wrt setSelection(), which does additional
checks.
This one is a pure acessor, and the more complete methods are
* setSelection(), which avoids empty selections
* clearSelection(), which resets anchor, and sets word selection and mark
more to false.
Most of the code should use these two instead of selection(bool), but this
is for later.
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 81ebe79..9a549c0 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1593,7 +1593,7 @@ void BufferView::dispatch(FuncRequest const & cmd,
DispatchResult & dr)
break;
case LFUN_MARK_TOGGLE:
- cur.setSelection(false);
+ cur.selection(false);
if (cur.mark()) {
cur.setMark(false);
dr.setMessage(from_utf8(N_("Mark removed")));
@@ -1785,7 +1785,7 @@ void BufferView::dispatch(FuncRequest const & cmd,
DispatchResult & dr)
// Select the inset from outside.
cur.pop();
cur.resetAnchor();
- cur.setSelection(true);
+ cur.selection(true);
cur.posForward();
} else if (cur.selBegin().idx() != cur.selEnd().idx()
|| (cur.depth() > 1
@@ -1796,7 +1796,7 @@ void BufferView::dispatch(FuncRequest const & cmd,
DispatchResult & dr)
cur.idx() = 0;
cur.pos() = 0;
cur.resetAnchor();
- cur.setSelection(true);
+ cur.selection(true);
cur.idx() = cur.lastidx();
cur.pos() = cur.lastpos();
} else {
@@ -1804,7 +1804,7 @@ void BufferView::dispatch(FuncRequest const & cmd,
DispatchResult & dr)
cur.pit() = 0;
cur.pos() = 0;
cur.resetAnchor();
- cur.setSelection(true);
+ cur.selection(true);
cur.pit() = cur.lastpit();
cur.pos() = cur.lastpos();
}
@@ -2180,7 +2180,7 @@ void BufferView::mouseEventDispatch(FuncRequest const &
cmd0)
Cursor old = cursor();
Cursor cur(*this);
cur.push(buffer_.inset());
- cur.setSelection(d->cursor_.selection());
+ cur.selection(d->cursor_.selection());
// Either the inset under the cursor or the
// surrounding Text will handle this event.
@@ -2362,7 +2362,7 @@ void BufferView::setCursorFromRow(int row, TexRow const &
texrow)
}
d->cursor_.reset();
buffer_.text().setCursor(d->cursor_, newpit, newpos);
- d->cursor_.setSelection(false);
+ d->cursor_.selection(false);
d->cursor_.resetAnchor();
recenter();
}
@@ -2448,7 +2448,7 @@ void BufferView::setCursor(DocIterator const & dit)
dit[i].inset().edit(d->cursor_, true);
d->cursor_.setCursor(dit);
- d->cursor_.setSelection(false);
+ d->cursor_.selection(false);
d->cursor_.setCurrentFont();
// FIXME
// It seems on general grounds as if this is probably needed, but
@@ -2581,7 +2581,7 @@ bool BufferView::selectIfEmpty(DocIterator & cur)
d->cursor_.setCursor(cur);
d->cursor_.pit() = beg_pit;
d->cursor_.pos() = 0;
- d->cursor_.setSelection(false);
+ d->cursor_.selection(false);
d->cursor_.resetAnchor();
d->cursor_.pit() = end_pit;
d->cursor_.pos() = end_pos;
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 758e1c6..090c623 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -997,18 +997,18 @@ DocIterator Cursor::selectionEnd() const
void Cursor::setSelection()
{
- setSelection(true);
+ selection(true);
if (idx() == normalAnchor().idx() &&
pit() == normalAnchor().pit() &&
pos() == normalAnchor().pos())
- setSelection(false);
+ selection(false);
}
void Cursor::setSelection(DocIterator const & where, int n)
{
setCursor(where);
- setSelection(true);
+ selection(true);
anchor_ = where;
pos() += n;
}
@@ -1016,7 +1016,7 @@ void Cursor::setSelection(DocIterator const & where, int
n)
void Cursor::clearSelection()
{
- setSelection(false);
+ selection(false);
setWordSelection(false);
setMark(false);
resetAnchor();
@@ -1079,7 +1079,7 @@ bool Cursor::selHandle(bool sel)
cap::saveSelection(*this);
resetAnchor();
- setSelection(sel);
+ selection(sel);
return true;
}
} // namespace lyx
@@ -1319,7 +1319,7 @@ bool Cursor::backspace()
// let's require two backspaces for 'big stuff' and
// highlight on the first
resetAnchor();
- setSelection(true);
+ selection(true);
--pos();
} else {
--pos();
@@ -1366,7 +1366,7 @@ bool Cursor::erase()
// 'clever' UI hack: only erase large items if previously slected
if (pos() != lastpos() && nextAtom()->nargs() > 0) {
resetAnchor();
- setSelection(true);
+ selection(true);
++pos();
} else {
plainErase();
diff --git a/src/Cursor.h b/src/Cursor.h
index 113d0d5..ec6bf99 100644
--- a/src/Cursor.h
+++ b/src/Cursor.h
@@ -161,8 +161,8 @@ public:
//
/// selection active?
bool selection() const { return selection_; }
- /// set selection;
- void setSelection(bool sel) { selection_ = sel; }
+ /// set selection; this is lower level than (set|clear)Selection
+ void selection(bool sel) { selection_ = sel; }
/// do we have a multicell selection?
bool selIsMultiCell() const
{ return selection_ && selBegin().idx() != selEnd().idx(); }
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 95af6b8..1d6e6cc 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -1334,7 +1334,7 @@ void selClearOrDel(Cursor & cur)
if (lyxrc.auto_region_delete)
selDel(cur);
else
- cur.setSelection(false);
+ cur.selection(false);
}
diff --git a/src/Text.cpp b/src/Text.cpp
index 29ff6cf..f9f76ec 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -1468,7 +1468,7 @@ void Text::deleteWordForward(Cursor & cur)
cursorForward(cur);
else {
cur.resetAnchor();
- cur.setSelection(true);
+ cur.selection(true);
cursorForwardOneWord(cur);
cur.setSelection();
cutSelection(cur, true, false);
@@ -1484,7 +1484,7 @@ void Text::deleteWordBackward(Cursor & cur)
cursorBackward(cur);
else {
cur.resetAnchor();
- cur.setSelection(true);
+ cur.selection(true);
cursorBackwardOneWord(cur);
cur.setSelection();
cutSelection(cur, true, false);
diff --git a/src/Text3.cpp b/src/Text3.cpp
index fbcd9b7..4e0dbc9 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -178,7 +178,7 @@ static void mathDispatch(Cursor & cur, FuncRequest const &
cmd)
LASSERT(cur.inMathed(), return);
cur.pos() = 0;
cur.resetAnchor();
- cur.setSelection(true);
+ cur.selection(true);
cur.pos() = cur.lastpos();
if (cmd.action() != LFUN_MATH_MODE)
// LFUN_MATH_MODE has a different meaning in
math mode
@@ -1675,7 +1675,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
// We continue with our existing selection or start a new one,
so don't
// reset the anchor.
bvcur.setCursor(cur);
- bvcur.setSelection(true);
+ bvcur.selection(true);
if (cur.top() == old) {
// We didn't move one iota, so no need to update the
screen.
cur.screenUpdateFlags(Update::SinglePar |
Update::FitCursor);
@@ -2057,7 +2057,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cur.push(*inset);
cur.top().pos() = cur.top().lastpos();
cur.resetAnchor();
- cur.setSelection(true);
+ cur.selection(true);
cur.top().pos() = 0;
}
break;
@@ -2433,7 +2433,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_ESCAPE:
if (cur.selection()) {
- cur.setSelection(false);
+ cur.selection(false);
} else {
cur.undispatched();
// This used to be LFUN_FINISHED_RIGHT, I think FORWARD
is more
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 17c5777..822199f 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1600,7 +1600,7 @@ void TextMetrics::deleteLineForward(Cursor & cur)
text_->cursorForward(cur);
} else {
cur.resetAnchor();
- cur.setSelection(true); // to avoid deletion
+ cur.selection(true); // to avoid deletion
cursorEnd(cur);
cur.setSelection();
// What is this test for ??? (JMarc)
diff --git a/src/frontends/qt4/GuiSpellchecker.cpp
b/src/frontends/qt4/GuiSpellchecker.cpp
index aa62a9a..24aa43d 100644
--- a/src/frontends/qt4/GuiSpellchecker.cpp
+++ b/src/frontends/qt4/GuiSpellchecker.cpp
@@ -337,9 +337,9 @@ void SpellcheckerWidget::Private::setSelection(
Cursor & bvcur = bv->cursor();
bvcur.setCursor(from);
bvcur.clearSelection();
- bvcur.setSelection(true);
+ bvcur.selection(true);
bvcur.setCursor(end);
- bvcur.setSelection(true);
+ bvcur.selection(true);
} else {
// FIXME LFUN
// If we used a LFUN, dispatch would do all of this for us
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 6d8f7d0..fd35c11 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -3975,7 +3975,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest &
cmd)
cur.idx() = tabular.getLastCellInRow(r);
cur.pit() = cur.lastpit();
cur.pos() = cur.lastpos();
- cur.setSelection(true);
+ cur.selection(true);
bvcur = cur;
rowselect_ = true;
break;
@@ -3992,7 +3992,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest &
cmd)
cur.idx() = tabular.cellIndex(tabular.nrows() - 1, c);
cur.pit() = cur.lastpit();
cur.pos() = cur.lastpos();
- cur.setSelection(true);
+ cur.selection(true);
bvcur = cur;
colselect_ = true;
break;
@@ -4025,7 +4025,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest &
cmd)
cur.pit() = 0;
cur.pos() = 0;
bvcur.setCursor(cur);
- bvcur.setSelection(true);
+ bvcur.selection(true);
break;
}
// select (additional) column
@@ -4037,7 +4037,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest &
cmd)
cur.pit() = 0;
cur.pos() = 0;
bvcur.setCursor(cur);
- bvcur.setSelection(true);
+ bvcur.selection(true);
break;
}
// only update if selection changes
@@ -4046,7 +4046,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest &
cmd)
cur.noScreenUpdate();
setCursorFromCoordinates(cur, cmd.x(), cmd.y());
bvcur.setCursor(cur);
- bvcur.setSelection(true);
+ bvcur.selection(true);
// if this is a multicell selection, we just set the
cursor to
// the beginning of the cell's text.
if (bvcur.selIsMultiCell()) {
@@ -4063,12 +4063,12 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest
& cmd)
case LFUN_CELL_BACKWARD:
movePrevCell(cur);
- cur.setSelection(false);
+ cur.selection(false);
break;
case LFUN_CELL_FORWARD:
moveNextCell(cur);
- cur.setSelection(false);
+ cur.selection(false);
break;
case LFUN_CHAR_FORWARD_SELECT:
@@ -5166,7 +5166,7 @@ int InsetTabular::dist(BufferView & bv, idx_type const
cell, int x, int y) const
Inset * InsetTabular::editXY(Cursor & cur, int x, int y)
{
//lyxerr << "InsetTabular::editXY: " << this << endl;
- cur.setSelection(false);
+ cur.selection(false);
cur.push(*this);
cur.idx() = getNearestCell(cur.bv(), x, y);
return cur.bv().textMetrics(&cell(cur.idx())->text()).editXY(cur, x, y);
@@ -5525,7 +5525,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.cellIndex(sel_row_start, column);
cur.pit() = 0;
cur.pos() = 0;
- cur.setSelection(false);
+ cur.selection(false);
break;
case Tabular::DELETE_COLUMN:
@@ -5548,7 +5548,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.cellIndex(row, sel_col_start);
cur.pit() = 0;
cur.pos() = 0;
- cur.setSelection(false);
+ cur.selection(false);
break;
case Tabular::COPY_ROW:
@@ -5664,7 +5664,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
tabular.rightLine(cur.selEnd().idx()));
cur.pit() = 0;
cur.pos() = 0;
- cur.setSelection(false);
+ cur.selection(false);
break;
}
@@ -5721,7 +5721,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
tabular.getAlignment(cur.selEnd().idx()));
cur.pit() = 0;
cur.pos() = 0;
- cur.setSelection(false);
+ cur.selection(false);
break;
}
@@ -5926,7 +5926,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.setLTCaption(row, true);
cur.pit() = 0;
cur.pos() = 0;
- cur.setSelection(false);
+ cur.selection(false);
// If a row is set as caption, then also insert
// a caption. Otherwise the LaTeX output is broken.
// Select cell if it is non-empty
@@ -5942,7 +5942,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.setLTCaption(row, false);
cur.pit() = 0;
cur.pos() = 0;
- cur.setSelection(false);
+ cur.selection(false);
FuncRequest fr(LFUN_INSET_DISSOLVE, "caption");
if (lyx::getStatus(fr).enabled())
lyx::dispatch(fr);
diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index 12e871a..6044b43 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -1411,7 +1411,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest
& cmd)
case LFUN_CELL_BACKWARD:
// See below.
- cur.setSelection(false);
+ cur.selection(false);
if (!idxPrev(cur)) {
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
cur.undispatched();
@@ -1421,7 +1421,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest
& cmd)
case LFUN_CELL_FORWARD:
// Can't handle selection by additional 'shift' as this is
// hard bound to LFUN_CELL_BACKWARD
- cur.setSelection(false);
+ cur.selection(false);
if (!idxNext(cur)) {
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
cur.undispatched();
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index c7bcdfe..b2ef6db 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -742,7 +742,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest &
cmd)
cur.pos() = 0;
cur.idx() = 0;
cur.resetAnchor();
- cur.setSelection(true);
+ cur.selection(true);
cur.idx() = cur.lastidx();
cur.pos() = cur.lastpos();
cur.bv().cursor() = cur;
@@ -1614,7 +1614,7 @@ void InsetMathNest::lfunMouseRelease(Cursor & cur,
FuncRequest & cmd)
cur.noScreenUpdate();
else {
Cursor & bvcur = cur.bv().cursor();
- bvcur.setSelection(true);
+ bvcur.selection(true);
}
return;
}
@@ -1755,7 +1755,7 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type
const c)
// just clear selection on pressing the space bar
if (cur.selection() && c == ' ') {
- cur.setSelection(false);
+ cur.selection(false);
return true;
}
commit 93fb68b1637bc01f85faa1b8ac373fd34032a9f2
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Feb 28 17:21:26 2016 +0100
Avoid incorrect "Autocorrect Off" message
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 90007c0..c7bcdfe 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -715,8 +715,10 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest &
cmd)
cur.selHandle(select);
// handle autocorrect:
- cur.autocorrect() = false;
- cur.message(_("Autocorrect Off ('!' to enter)"));
+ if (lyxrc.autocorrection_math && cur.autocorrect()) {
+ cur.autocorrect() = false;
+ cur.message(_("Autocorrect Off ('!' to enter)"));
+ }
// go up/down
bool up = act == LFUN_UP || act == LFUN_UP_SELECT;
commit 26a525ef1cce8bcb3f693bca31b7b2d18848f45e
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Feb 28 17:11:51 2016 +0100
FindAndReplace: reorder includes
diff --git a/src/frontends/qt4/FindAndReplace.cpp
b/src/frontends/qt4/FindAndReplace.cpp
index f40666c..ac7084a 100644
--- a/src/frontends/qt4/FindAndReplace.cpp
+++ b/src/frontends/qt4/FindAndReplace.cpp
@@ -12,23 +12,23 @@
#include "FindAndReplace.h"
-#include "Lexer.h"
#include "GuiApplication.h"
#include "GuiView.h"
#include "GuiWorkArea.h"
#include "qt_helpers.h"
-#include "Language.h"
#include "Buffer.h"
-#include "BufferParams.h"
#include "BufferList.h"
+#include "BufferParams.h"
#include "BufferView.h"
-#include "Text.h"
-#include "TextClass.h"
#include "Cursor.h"
#include "FuncRequest.h"
+#include "Language.h"
+#include "Lexer.h"
#include "LyX.h"
#include "lyxfind.h"
+#include "Text.h"
+#include "TextClass.h"
#include "frontends/alert.h"
commit de003b4ec71db8bb5d0fe0f6160b5c417470dbd3
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Feb 28 17:01:01 2016 +0100
TextMetrics: Use shorter names for font metrics
This keeps code easier to read.
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index cb1c4bd..17c5777 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -947,15 +947,15 @@ void TextMetrics::setRowHeight(Row & row, pit_type const
pit,
FontInfo labelfont = text_->labelFont(par);
- FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
- FontMetrics const & fontmetrics = theFontMetrics(font);
+ FontMetrics const & lfm = theFontMetrics(labelfont);
+ FontMetrics const & fm = theFontMetrics(font);
// these are minimum values
double const spacing_val = layout.spacing.getValue()
* text_->spacing(par);
//lyxerr << "spacing_val = " << spacing_val << endl;
- int maxasc = int(fontmetrics.maxAscent() * spacing_val);
- int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
+ int maxasc = int(fm.maxAscent() * spacing_val);
+ int maxdesc = int(fm.maxDescent() * spacing_val);
// insets may be taller
CoordCache::Insets const & insetCache = bv_->coordCache().getInsets();
@@ -1014,7 +1014,7 @@ void TextMetrics::setRowHeight(Row & row, pit_type const
pit,
&& (!layout.isParagraphGroup() ||
text_->isFirstInSequence(pit))
&& !par.labelString().empty()) {
labeladdon = int(
- labelfont_metrics.maxHeight()
+ lfm.maxHeight()
* layout.spacing.getValue()
* text_->spacing(par)
+ (layout.topsep + layout.labelbottomsep) * dh);
@@ -1647,6 +1647,7 @@ int TextMetrics::leftMargin(int max_width,
//lyxerr << "TextMetrics::leftMargin: pit: " << pit << " pos: " << pos
<< endl;
DocumentClass const & tclass = buffer.params().documentClass();
Layout const & layout = par.layout();
+ FontMetrics const & bfm = theFontMetrics(buffer.params().getFont());
docstring parindent = layout.parindent;
@@ -1655,8 +1656,7 @@ int TextMetrics::leftMargin(int max_width,
if (text_->isMainText())
l_margin += bv_->leftMargin();
- l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
- tclass.leftmargin());
+ l_margin += bfm.signedWidth(tclass.leftmargin());
int depth = par.getDepth();
if (depth != 0) {
@@ -1674,8 +1674,7 @@ int TextMetrics::leftMargin(int max_width,
buffer.params().paragraph_separation ==
BufferParams::ParagraphIndentSeparation) {
docstring pi =
pars[newpar].layout().parindent;
- l_margin -= theFontMetrics(
-
buffer.params().getFont()).signedWidth(pi);
+ l_margin -= bfm.signedWidth(pi);
}
}
if (tclass.isDefaultLayout(par.layout())
@@ -1704,37 +1703,36 @@ int TextMetrics::leftMargin(int max_width,
}
FontInfo const labelfont = text_->labelFont(par);
- FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
+ FontMetrics const & lfm = theFontMetrics(labelfont);
switch (layout.margintype) {
case MARGIN_DYNAMIC:
if (!layout.leftmargin.empty()) {
- l_margin +=
theFontMetrics(buffer.params().getFont()).signedWidth(
- layout.leftmargin);
+ l_margin += bfm.signedWidth(layout.leftmargin);
}
if (!par.labelString().empty()) {
- l_margin +=
labelfont_metrics.signedWidth(layout.labelindent);
- l_margin += labelfont_metrics.width(par.labelString());
- l_margin += labelfont_metrics.width(layout.labelsep);
+ l_margin += lfm.signedWidth(layout.labelindent);
+ l_margin += lfm.width(par.labelString());
+ l_margin += lfm.width(layout.labelsep);
}
break;
case MARGIN_MANUAL: {
- l_margin += labelfont_metrics.signedWidth(layout.labelindent);
+ l_margin += lfm.signedWidth(layout.labelindent);
// The width of an empty par, even with manual label, should be 0
if (!par.empty() && pos >= par.beginOfBody()) {
if (!par.getLabelWidthString().empty()) {
docstring labstr = par.getLabelWidthString();
- l_margin += labelfont_metrics.width(labstr);
- l_margin +=
labelfont_metrics.width(layout.labelsep);
+ l_margin += lfm.width(labstr);
+ l_margin += lfm.width(layout.labelsep);
}
}
break;
}
case MARGIN_STATIC: {
- l_margin += theFontMetrics(buffer.params().getFont()).
- signedWidth(layout.leftmargin) * 4 /
(par.getDepth() + 4);
+ l_margin += bfm.signedWidth(layout.leftmargin) * 4
+ / (par.getDepth() + 4);
break;
}
@@ -1742,20 +1740,20 @@ int TextMetrics::leftMargin(int max_width,
if (layout.labeltype == LABEL_MANUAL) {
// 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);
+ l_margin += lfm.signedWidth(layout.leftmargin);
else
- l_margin +=
labelfont_metrics.signedWidth(layout.labelindent);
+ l_margin += lfm.signedWidth(layout.labelindent);
} else if (pos != 0
// Special case to fix problems with
// theorems (JMarc)
|| (layout.labeltype == LABEL_STATIC
&& layout.latextype == LATEX_ENVIRONMENT
&& !text_->isFirstInSequence(pit))) {
- l_margin +=
labelfont_metrics.signedWidth(layout.leftmargin);
+ l_margin += lfm.signedWidth(layout.leftmargin);
} else if (!layout.labelIsAbove()) {
- l_margin +=
labelfont_metrics.signedWidth(layout.labelindent);
- l_margin += labelfont_metrics.width(layout.labelsep);
- l_margin += labelfont_metrics.width(par.labelString());
+ l_margin += lfm.signedWidth(layout.labelindent);
+ l_margin += lfm.width(layout.labelsep);
+ l_margin += lfm.width(par.labelString());
}
break;
@@ -1772,7 +1770,7 @@ int TextMetrics::leftMargin(int max_width,
for ( ; rit != end; ++rit)
if (rit->fill() < minfill)
minfill = rit->fill();
- l_margin +=
theFontMetrics(buffer.params().getFont()).signedWidth(layout.leftmargin);
+ l_margin += bfm.signedWidth(layout.leftmargin);
l_margin += minfill;
#endif
// also wrong, but much shorter.
@@ -1782,7 +1780,7 @@ int TextMetrics::leftMargin(int max_width,
}
if (!par.params().leftIndent().zero())
- l_margin += par.params().leftIndent().inPixels(max_width,
labelfont_metrics.em());
+ l_margin += par.params().leftIndent().inPixels(max_width,
lfm.em());
LyXAlignment align;
@@ -1816,8 +1814,7 @@ int TextMetrics::leftMargin(int max_width,
// the indentation set in the document
// settings
if (buffer.params().getIndentation().asLyXCommand() ==
"default")
- l_margin += theFontMetrics(
-
buffer.params().getFont()).signedWidth(parindent);
+ l_margin += bfm.signedWidth(parindent);
else
l_margin +=
buffer.params().getIndentation().inPixels(*bv_);
}
commit e3e690e39d6bf9a3fd54edfa09d544eb810b1893
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Feb 28 16:56:00 2016 +0100
Cleanup bruteFind.
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index e65c81b..758e1c6 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -73,25 +73,25 @@ DocIterator bruteFind(Cursor const & c, int x, int y)
DocIterator result;
DocIterator it = c;
- it.top().pos() = 0;
+ it.pos() = 0;
DocIterator et = c;
- et.top().pos() = et.top().asInsetMath()->cell(et.top().idx()).size();
+ et.pos() = et.lastpos();
for (size_t i = 0;; ++i) {
int xo;
int yo;
Inset const * inset = &it.inset();
- CoordCache const & cache = c.bv().coordCache();
+ CoordCache::Insets const & insetCache =
c.bv().coordCache().getInsets();
// FIXME: in the case where the inset is not in the cache, this
// means that no part of it is visible on screen. In this case
// we don't do elaborate search and we just return the forwarded
// DocIterator at its beginning.
- if (!cache.getInsets().has(inset)) {
+ if (!insetCache.has(inset)) {
it.top().pos() = 0;
return it;
}
- Point const o = cache.getInsets().xy(inset);
+ Point const o = insetCache.xy(inset);
inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
// Convert to absolute
xo += o.x_;
commit d9b81486a2157db7dce67130cdbfb90a6b28ad51
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Feb 28 16:48:11 2016 +0100
Remove unused bruteFind* functions
And rename bruteFind2 to bruteFind.
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 58dd6a0..e65c81b 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -66,7 +66,7 @@ namespace {
// Find position closest to (x, y) in cell given by iter.
// Used only in mathed
-DocIterator bruteFind2(Cursor const & c, int x, int y)
+DocIterator bruteFind(Cursor const & c, int x, int y)
{
double best_dist = numeric_limits<double>::max();
@@ -113,126 +113,6 @@ DocIterator bruteFind2(Cursor const & c, int x, int y)
}
-/*
-/// moves position closest to (x, y) in given box
-bool bruteFind(Cursor & cursor,
- int x, int y, int xlow, int xhigh, int ylow, int yhigh)
-{
- LASSERT(!cursor.empty(), return false);
- Inset & inset = cursor[0].inset();
- BufferView & bv = cursor.bv();
-
- CoordCache::InnerParPosCache const & cache =
-
bv.coordCache().getParPos().find(cursor.bottom().text())->second;
- // Get an iterator on the first paragraph in the cache
- DocIterator it(inset);
- it.push_back(CursorSlice(inset));
- it.pit() = cache.begin()->first;
- // Get an iterator after the last paragraph in the cache
- DocIterator et(inset);
- et.push_back(CursorSlice(inset));
- et.pit() = prev(cache.end(), 1)->first;
- if (et.pit() >= et.lastpit())
- et = doc_iterator_end(inset);
- else
- ++et.pit();
-
- double best_dist = numeric_limits<double>::max();
- DocIterator best_cursor = et;
-
- for ( ; it != et; it.forwardPos(true)) {
- // avoid invalid nesting when selecting
- if (!cursor.selection() || positionable(it, cursor.anchor_)) {
- Point p = bv.getPos(it, false);
- int xo = p.x_;
- int yo = p.y_;
- if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <=
yhigh) {
- double const dx = xo - x;
- double const dy = yo - y;
- double const d = dx * dx + dy * dy;
- // '<=' in order to take the last possible
position
- // this is important for clicking behind \sum
in e.g. '\sum_i a'
- if (d <= best_dist) {
- // lyxerr << "*" << endl;
- best_dist = d;
- best_cursor = it;
- }
- }
- }
- }
-
- if (best_cursor != et) {
- cursor.setCursor(best_cursor);
- return true;
- }
-
- return false;
-}
-*/
-
-/*
-/// moves position closest to (x, y) in given box
-bool bruteFind3(Cursor & cur, int x, int y, bool up)
-{
- BufferView & bv = cur.bv();
- int ylow = up ? 0 : y + 1;
- int yhigh = up ? y - 1 : bv.workHeight();
- int xlow = 0;
- int xhigh = bv.workWidth();
-
-// FIXME: bit more work needed to get 'from' and 'to' right.
- pit_type from = cur.bottom().pit();
- //pit_type to = cur.bottom().pit();
- //lyxerr << "Pit start: " << from << endl;
-
- //lyxerr << "bruteFind3: x: " << x << " y: " << y
- // << " xlow: " << xlow << " xhigh: " << xhigh
- // << " ylow: " << ylow << " yhigh: " << yhigh
- // << endl;
- DocIterator it = doc_iterator_begin(cur.buffer());
- it.pit() = from;
- DocIterator et = doc_iterator_end(cur.buffer());
-
- double best_dist = numeric_limits<double>::max();
- DocIterator best_cursor = et;
-
- for ( ; it != et; it.forwardPos()) {
- // avoid invalid nesting when selecting
- if (bv.cursorStatus(it) == CUR_INSIDE
- && (!cur.selection() || positionable(it,
cur.realAnchor()))) {
- // If this function is ever used again, check
- // whether this is the same as "bv.getPos(it,
- // false)" with boundary = false.
- Point p = bv.getPos(it);
- int xo = p.x_;
- int yo = p.y_;
- if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <=
yhigh) {
- double const dx = xo - x;
- double const dy = yo - y;
- double const d = dx * dx + dy * dy;
- //lyxerr << "itx: " << xo << " ity: " << yo <<
" d: " << d
- // << " dx: " << dx << " dy: " << dy
- // << " idx: " << it.idx() << " pos: " <<
it.pos()
- // << " it:\n" << it
- // << endl;
- // '<=' in order to take the last possible
position
- // this is important for clicking behind \sum
in e.g. '\sum_i a'
- if (d <= best_dist) {
- //lyxerr << "*" << endl;
- best_dist = d;
- best_cursor = it;
- }
- }
- }
- }
-
- //lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor <<
endl;
- if (best_cursor == et)
- return false;
- cur.setCursor(best_cursor);
- return true;
-}
-*/
} // namespace anon
@@ -1794,7 +1674,7 @@ bool Cursor::upDownInMath(bool up)
//lyxerr << "idxUpDown triggered" << endl;
// try to find best position within this inset
if (!selection())
- setCursor(bruteFind2(*this, xo, yo));
+ setCursor(bruteFind(*this, xo, yo));
return true;
}
commit 09f975504fd29d27826037b8388c5a71220bab69
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Feb 28 16:44:00 2016 +0100
Remove unused CursorData::logicalpos_
This was introduced in 41ecabf5, probably by mistake.
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index e9bdf89..58dd6a0 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -239,7 +239,7 @@ bool bruteFind3(Cursor & cur, int x, int y, bool up)
CursorData::CursorData()
: DocIterator(), anchor_(),
selection_(false), mark_(false), word_selection_(false),
- logicalpos_(false), current_font(inherit_font),
+ current_font(inherit_font),
autocorrect_(false), macromode_(false)
{}
@@ -247,7 +247,7 @@ CursorData::CursorData()
CursorData::CursorData(Buffer * buffer)
: DocIterator(buffer), anchor_(),
selection_(false), mark_(false), word_selection_(false),
- logicalpos_(false), current_font(inherit_font),
+ current_font(inherit_font),
autocorrect_(false), macromode_(false)
{}
@@ -255,7 +255,7 @@ CursorData::CursorData(Buffer * buffer)
CursorData::CursorData(DocIterator const & dit)
: DocIterator(dit), anchor_(),
selection_(false), mark_(false), word_selection_(false),
- logicalpos_(false), current_font(inherit_font),
+ current_font(inherit_font),
autocorrect_(false), macromode_(false)
{}
diff --git a/src/Cursor.h b/src/Cursor.h
index a0f5ec1..113d0d5 100644
--- a/src/Cursor.h
+++ b/src/Cursor.h
@@ -101,11 +101,6 @@ protected:
bool mark_;
/// are we in word-selection mode? This is set when double clicking.
bool word_selection_;
- /// If true, we are behind the previous char, otherwise we are in front
- // of the next char. This only make a difference when we are in front
- // of a big inset spanning a whole row and computing coordinates for
- // displaying the cursor.
- bool logicalpos_;
// FIXME: make them protected.
public:
commit db54b72eb945bd7032a5d45916f5acc559c0162a
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Feb 28 16:42:35 2016 +0100
Directly pass a Row::Element to RowPainter::paintInset
diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index 8c62926..2766642 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -104,42 +104,40 @@ FontInfo RowPainter::labelFont() const
// This draws green lines around each inset.
-void RowPainter::paintInset(Inset const * inset, Font const & font,
- Change const & change,
- pos_type const pos)
+void RowPainter::paintInset(Row::Element const & e)
{
// Handle selection
bool const pi_selected = pi_.selected;
Cursor const & cur = pi_.base.bv->cursor();
if (cur.selection() && cur.text() == &text_
&& cur.normalAnchor().text() == &text_)
- pi_.selected = row_.sel_beg <= pos && row_.sel_end > pos;
+ pi_.selected = row_.sel_beg <= e.pos && row_.sel_end > e.pos;
- LASSERT(inset, return);
+ LASSERT(e.inset, return);
// Backup full_repaint status because some insets (InsetTabular)
// requires a full repaint
bool const pi_full_repaint = pi_.full_repaint;
bool const pi_do_spellcheck = pi_.do_spellcheck;
Change const pi_change = pi_.change_;
- pi_.base.font = inset->inheritFont() ? font.fontInfo() :
+ pi_.base.font = e.inset->inheritFont() ? e.font.fontInfo() :
pi_.base.bv->buffer().params().getFont().fontInfo();
- pi_.ltr_pos = !font.isVisibleRightToLeft();
- pi_.change_ = change_.changed() ? change_ : change;
- pi_.do_spellcheck &= inset->allowSpellCheck();
+ pi_.ltr_pos = !e.font.isVisibleRightToLeft();
+ pi_.change_ = change_.changed() ? change_ : e.change;
+ pi_.do_spellcheck &= e.inset->allowSpellCheck();
int const x1 = int(x_);
- pi_.base.bv->coordCache().insets().add(inset, x1, yo_);
+ pi_.base.bv->coordCache().insets().add(e.inset, x1, yo_);
// insets are painted completely. Recursive
// FIXME: it is wrong to completely paint the background
// if we want to do single row painting.
- inset->drawBackground(pi_, x1, yo_);
- inset->drawSelection(pi_, x1, yo_);
- inset->draw(pi_, x1, yo_);
+ e.inset->drawBackground(pi_, x1, yo_);
+ e.inset->drawSelection(pi_, x1, yo_);
+ e.inset->draw(pi_, x1, yo_);
- Dimension const & dim = pi_.base.bv->coordCache().insets().dim(inset);
+ Dimension const & dim = pi_.base.bv->coordCache().insets().dim(e.inset);
- paintForeignMark(x_, font.language(), dim.descent());
+ paintForeignMark(x_, e.font.language(), dim.descent());
x_ += dim.width();
@@ -587,7 +585,7 @@ void RowPainter::paintOnlyInsets()
x_ += e.full_width();
continue;
}
- paintInset(e.inset, e.font, e.change, e.pos);
+ paintInset(e);
} else
x_ += e.full_width();
}
@@ -615,7 +613,7 @@ void RowPainter::paintText()
case Row::INSET: {
// If outer row has changed, nested insets are repaint
completely.
pi_.base.bv->coordCache().insets().add(e.inset,
int(x_), yo_);
- paintInset(e.inset, e.font, e.change, e.pos);
+ paintInset(e);
foreign_descent = e.dim.descent();
}
break;
diff --git a/src/RowPainter.h b/src/RowPainter.h
index a4120e6..cb70f5d 100644
--- a/src/RowPainter.h
+++ b/src/RowPainter.h
@@ -64,8 +64,7 @@ private:
void paintMisspelledMark(double orig_x, Row::Element const & e) const;
void paintChange(double orig_x , Font const & font, Change const &
change) const;
void paintAppendixStart(int y) const;
- void paintInset(Inset const * inset, Font const & font,
- Change const & change, pos_type const pos);
+ void paintInset(Row::Element const & e);
/// return the label font for this row
FontInfo labelFont() const;
commit 8d35c8447ff7bdf906696e876b9a2946f852e455
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Feb 28 16:34:33 2016 +0100
Remove unused TextMetrics::maxWidth()
diff --git a/src/TextMetrics.h b/src/TextMetrics.h
index f0abcb5..35b5bdb 100644
--- a/src/TextMetrics.h
+++ b/src/TextMetrics.h
@@ -105,9 +105,6 @@ public:
int height() const { return dim_.height(); }
///
- int maxWidth() const { return max_width_; }
-
- ///
int rightMargin(ParagraphMetrics const & pm) const;
int rightMargin(pit_type const pit) const;
commit 7fcf2e2599a5a651c89f9bf412b5ab8e2659e8cb
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Feb 28 16:23:43 2016 +0100
Use isMainText() instead of doing explicit tests
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 80b0bac..5718278 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -290,7 +290,7 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
break;
case LFUN_INSET_DISSOLVE: {
- bool const main_inset = &buffer().inset() == this;
+ bool const main_inset = text_.isMainText();
bool const target_inset = cmd.argument().empty()
|| cmd.getArg(0) == insetName(lyxCode());
bool const one_cell = nargs() == 1;
@@ -322,7 +322,7 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const &
cmd,
{
switch (cmd.action()) {
case LFUN_INSET_DISSOLVE: {
- bool const main_inset = &buffer().inset() == this;
+ bool const main_inset = text_.isMainText();
bool const target_inset = cmd.argument().empty()
|| cmd.getArg(0) == insetName(lyxCode());
bool const one_cell = nargs() == 1;
@@ -338,7 +338,7 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const &
cmd,
status.setEnabled(false);
return true;
}
- if (&buffer().inset() == this ||
!cur.paragraph().layout().args().empty())
+ if (text_.isMainText() ||
!cur.paragraph().layout().args().empty())
return text_.getStatus(cur, cmd, status);
Layout::LaTeXArgMap args = getLayout().args();
-----------------------------------------------------------------------
hooks/post-receive
--
Repository for new features