2003-08-23 00:17:00 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file MetricsInfo.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
2002-09-11 09:14:57 +00:00
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
#include "BufferView.h"
|
2009-02-09 23:30:24 +00:00
|
|
|
#include "ColorSet.h"
|
2016-05-22 21:48:28 +00:00
|
|
|
#include "LyXRC.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
2008-10-25 10:47:38 +00:00
|
|
|
#include "insets/Inset.h"
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "mathed/MathSupport.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
#include "frontends/Painter.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
2007-11-27 23:53:13 +00:00
|
|
|
#include "support/docstring.h"
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2016-05-23 21:30:23 +00:00
|
|
|
#include "support/RefChanger.h"
|
2002-05-30 07:09:54 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2009-02-09 23:30:24 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
2006-08-13 22:54:59 +00:00
|
|
|
|
2009-02-09 23:30:24 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// MetricsBase
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2002-05-30 07:09:54 +00:00
|
|
|
|
2016-06-14 18:22:24 +00:00
|
|
|
MetricsBase::MetricsBase(BufferView * b, FontInfo f, int w)
|
2016-11-19 20:25:34 +00:00
|
|
|
: bv(b), font(move(f)), fontname("mathnormal"),
|
2016-11-14 17:01:56 +00:00
|
|
|
textwidth(w), macro_nesting(0),
|
|
|
|
solid_line_thickness_(1), solid_line_offset_(1), dotted_line_thickness_(1)
|
2016-05-22 21:48:28 +00:00
|
|
|
{
|
|
|
|
if (lyxrc.zoom >= 200) {
|
|
|
|
// derive the line thickness from zoom factor
|
|
|
|
// the zoom is given in percent
|
|
|
|
// (increase thickness at 250%, 450% etc.)
|
2016-07-03 23:03:36 +00:00
|
|
|
solid_line_thickness_ = (lyxrc.zoom + 150) / 200;
|
2016-05-22 21:48:28 +00:00
|
|
|
// adjust line_offset_ too
|
|
|
|
solid_line_offset_ = 1 + solid_line_thickness_ / 2;
|
|
|
|
}
|
|
|
|
if (lyxrc.zoom >= 100) {
|
|
|
|
// derive the line thickness from zoom factor
|
|
|
|
// the zoom is given in percent
|
|
|
|
// (increase thickness at 150%, 250% etc.)
|
|
|
|
dotted_line_thickness_ = (lyxrc.zoom + 50) / 100;
|
|
|
|
}
|
|
|
|
}
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
|
|
|
Remove a conversion to_utf8() inside FontSetChanger
This requires to change many docstrings into std::strings. The logic behind that
is that they represent a fixed set of math fonts, and therefore “string” means
here “poor man's enum” rather than text (this is consistent with MetricsBase).
Profiling of scrolling inside a document over macro-instensive areas:
Before the patch:
44,1% BufferView::updateMetrics()
-> 34,8% InsetMathHull::metrics()
-> 9,8% FontSetChanger::FontSetChanger()
28,4% BufferView::draw()
After the patch:
35,3% BufferView::updateMetrics()
-> 27,2% InsetMathHull::metrics
-> 0,4% FontSetChanger::FontSetChanger()
47,5% BufferView::draw()
FontSetChanger::FontSetChanger() is made 41x less expensive (with reference
BV::draw()) just by removing this conversion. The remaining 0,4% could be
squished by replacing the strings with a proper enum, but this is premature. Of
course, this only treats the symptoms: there is no good reason that this
function is called 45500 times over the time of 40 repaints.
2016-06-07 21:58:55 +00:00
|
|
|
Changer MetricsBase::changeFontSet(string const & name, bool cond)
|
2016-05-23 21:30:23 +00:00
|
|
|
{
|
|
|
|
RefChanger<MetricsBase> rc = make_save(*this);
|
|
|
|
if (!cond)
|
|
|
|
rc->keep();
|
|
|
|
else {
|
|
|
|
ColorCode oldcolor = font.color();
|
Remove a conversion to_utf8() inside FontSetChanger
This requires to change many docstrings into std::strings. The logic behind that
is that they represent a fixed set of math fonts, and therefore “string” means
here “poor man's enum” rather than text (this is consistent with MetricsBase).
Profiling of scrolling inside a document over macro-instensive areas:
Before the patch:
44,1% BufferView::updateMetrics()
-> 34,8% InsetMathHull::metrics()
-> 9,8% FontSetChanger::FontSetChanger()
28,4% BufferView::draw()
After the patch:
35,3% BufferView::updateMetrics()
-> 27,2% InsetMathHull::metrics
-> 0,4% FontSetChanger::FontSetChanger()
47,5% BufferView::draw()
FontSetChanger::FontSetChanger() is made 41x less expensive (with reference
BV::draw()) just by removing this conversion. The remaining 0,4% could be
squished by replacing the strings with a proper enum, but this is premature. Of
course, this only treats the symptoms: there is no good reason that this
function is called 45500 times over the time of 40 repaints.
2016-06-07 21:58:55 +00:00
|
|
|
string const oldname = fontname;
|
|
|
|
fontname = name;
|
2016-10-25 14:03:34 +00:00
|
|
|
if (isMathFont(name) || isMathFont(oldname))
|
|
|
|
font = sane_font;
|
2016-05-23 21:30:23 +00:00
|
|
|
augmentFont(font, name);
|
|
|
|
font.setSize(rc->old.font.size());
|
2016-11-19 20:25:34 +00:00
|
|
|
font.setStyle(rc->old.font.style());
|
2016-05-23 21:30:23 +00:00
|
|
|
if (name != "lyxtex"
|
|
|
|
&& ((isTextFont(oldname) && oldcolor != Color_foreground)
|
|
|
|
|| (isMathFont(oldname) && oldcolor != Color_math)))
|
|
|
|
font.setColor(oldcolor);
|
|
|
|
}
|
|
|
|
return move(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-09 23:30:24 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// MetricsInfo
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-05-22 21:48:28 +00:00
|
|
|
MetricsInfo::MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
|
|
|
|
MacroContext const & mc)
|
2016-11-14 17:01:56 +00:00
|
|
|
: base(bv, font, textwidth), macrocontext(mc)
|
2002-05-30 07:09:54 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2009-02-09 23:30:24 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// PainterInfo
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter)
|
2009-02-09 21:14:23 +00:00
|
|
|
: pain(painter), ltr_pos(false), change_(), selected(false),
|
2015-05-06 16:39:24 +00:00
|
|
|
do_spellcheck(true), full_repaint(true), background_color(Color_background)
|
2003-05-28 13:22:36 +00:00
|
|
|
{
|
|
|
|
base.bv = bv;
|
|
|
|
}
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
|
|
|
2006-08-13 22:54:59 +00:00
|
|
|
void PainterInfo::draw(int x, int y, char_type c)
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
|
|
|
pain.text(x, y, c, base.font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-13 22:54:59 +00:00
|
|
|
void PainterInfo::draw(int x, int y, docstring const & str)
|
2005-07-17 10:31:44 +00:00
|
|
|
{
|
|
|
|
pain.text(x, y, str, base.font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-25 10:47:38 +00:00
|
|
|
ColorCode PainterInfo::backgroundColor(Inset const * inset, bool sel) const
|
|
|
|
{
|
2009-12-17 14:09:37 +00:00
|
|
|
ColorCode const color_bg = inset->backgroundColor(*this);
|
2008-10-25 10:47:38 +00:00
|
|
|
|
|
|
|
if (selected && sel)
|
|
|
|
// This inset is in a selection
|
|
|
|
return Color_selection;
|
|
|
|
else {
|
|
|
|
if (color_bg != Color_none)
|
|
|
|
// This inset has its own color
|
|
|
|
return color_bg;
|
|
|
|
else {
|
|
|
|
if (background_color == Color_none)
|
|
|
|
// This inset has no own color and does not inherit a color
|
|
|
|
return Color_background;
|
|
|
|
else
|
|
|
|
// This inset has no own color, but inherits a color
|
|
|
|
return background_color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-02 12:13:54 +00:00
|
|
|
Color PainterInfo::textColor(Color const & color) const
|
|
|
|
{
|
|
|
|
if (change_.changed())
|
|
|
|
return change_.color();
|
|
|
|
if (selected)
|
|
|
|
return Color_selectiontext;
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-23 21:30:23 +00:00
|
|
|
Changer MetricsBase::changeScript(bool cond)
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2016-11-19 20:25:34 +00:00
|
|
|
switch (font.style()) {
|
2016-05-23 21:30:23 +00:00
|
|
|
case LM_ST_DISPLAY:
|
|
|
|
case LM_ST_TEXT:
|
2016-11-19 20:25:34 +00:00
|
|
|
return font.changeStyle(LM_ST_SCRIPT, cond);
|
2016-05-23 21:30:23 +00:00
|
|
|
case LM_ST_SCRIPT:
|
|
|
|
case LM_ST_SCRIPTSCRIPT:
|
2016-11-19 20:25:34 +00:00
|
|
|
return font.changeStyle(LM_ST_SCRIPTSCRIPT, cond);
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
2016-05-23 21:30:23 +00:00
|
|
|
//remove Warning
|
|
|
|
LASSERT(false, return Changer());
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 23:30:24 +00:00
|
|
|
|
2016-05-23 21:30:23 +00:00
|
|
|
Changer MetricsBase::changeFrac(bool cond)
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2016-11-19 20:25:34 +00:00
|
|
|
switch (font.style()) {
|
2016-05-23 21:30:23 +00:00
|
|
|
case LM_ST_DISPLAY:
|
2016-11-19 20:25:34 +00:00
|
|
|
return font.changeStyle(LM_ST_TEXT, cond);
|
2016-05-23 21:30:23 +00:00
|
|
|
case LM_ST_TEXT:
|
2016-11-19 20:25:34 +00:00
|
|
|
return font.changeStyle(LM_ST_SCRIPT, cond);
|
2016-05-23 21:30:23 +00:00
|
|
|
case LM_ST_SCRIPT:
|
|
|
|
case LM_ST_SCRIPTSCRIPT:
|
2016-11-19 20:25:34 +00:00
|
|
|
return font.changeStyle(LM_ST_SCRIPTSCRIPT, cond);
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
2016-05-23 21:30:23 +00:00
|
|
|
//remove Warning
|
|
|
|
return Changer();
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|