2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathFontOld.cpp
|
2003-08-19 13:00:56 +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-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
2002-07-17 10:25:33 +00:00
|
|
|
|
2003-08-19 13:00:56 +00:00
|
|
|
#include <config.h>
|
2002-07-17 10:25:33 +00:00
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathFontOld.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathParser.h"
|
2010-08-14 17:57:06 +00:00
|
|
|
#include "MathStream.h"
|
|
|
|
#include "MathSupport.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
2014-11-14 17:18:30 +00:00
|
|
|
#include "support/gettext.h"
|
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
|
|
|
#include "support/lassert.h"
|
2014-11-14 17:18:30 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2008-05-06 10:36:32 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2014-11-14 17:18:30 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathFontOld::InsetMathFontOld(Buffer * buf, latexkeys const * key)
|
2010-08-14 17:57:06 +00:00
|
|
|
: InsetMathNest(buf, 1), key_(key), current_mode_(TEXT_MODE)
|
2002-07-17 10:25:33 +00:00
|
|
|
{
|
|
|
|
//lock(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
std::string InsetMathFontOld::font() const
|
|
|
|
{
|
|
|
|
LASSERT(isAscii(key_->name), return "mathnormal");
|
|
|
|
return to_ascii(key_->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathFontOld::clone() const
|
2002-07-17 10:25:33 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathFontOld(*this);
|
2002-07-17 10:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathFontOld::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-07-17 10:25:33 +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
|
|
|
current_mode_ = isTextFont(mi.base.fontname)
|
2010-08-14 17:57:06 +00:00
|
|
|
? TEXT_MODE : MATH_MODE;
|
|
|
|
|
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
|
|
|
std::string const fontname = current_mode_ == MATH_MODE
|
|
|
|
? "math" + font() : "text" + font();// I doubt that this still works
|
2010-08-14 17:57:06 +00:00
|
|
|
|
|
|
|
// When \cal is used in text mode, the font is not changed
|
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
|
|
|
bool really_change_font = fontname != "textcal";
|
2010-08-14 17:57:06 +00:00
|
|
|
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer dummy = really_change_font ? mi.base.changeFontSet(fontname)
|
|
|
|
: Changer();
|
2004-01-30 11:41:12 +00:00
|
|
|
cell(0).metrics(mi, dim);
|
2002-07-17 10:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathFontOld::draw(PainterInfo & pi, int x, int y) const
|
2002-07-17 10:25:33 +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
|
|
|
current_mode_ = isTextFont(pi.base.fontname)
|
2010-08-14 17:57:06 +00:00
|
|
|
? TEXT_MODE : MATH_MODE;
|
|
|
|
|
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
|
|
|
std::string const fontname = current_mode_ == MATH_MODE
|
|
|
|
? "math" + font() : "text" + font();// I doubt that this still works
|
2010-08-14 17:57:06 +00:00
|
|
|
|
|
|
|
// When \cal is used in text mode, the font is not changed
|
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
|
|
|
bool really_change_font = fontname != "textcal";
|
2010-08-14 17:57:06 +00:00
|
|
|
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer dummy = really_change_font ? pi.base.changeFontSet(fontname)
|
|
|
|
: Changer();
|
2017-01-06 08:52:10 +00:00
|
|
|
cell(0).draw(pi, x, y);
|
2002-07-17 10:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathFontOld::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
2002-07-17 10:25:33 +00:00
|
|
|
{
|
2003-05-28 13:22:36 +00:00
|
|
|
cell(0).metricsT(mi, dim);
|
2002-07-17 10:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathFontOld::drawT(TextPainter & pain, int x, int y) const
|
2002-07-17 10:25:33 +00:00
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(0).drawT(pain, x, y);
|
2002-07-17 10:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathFontOld::write(WriteStream & os) const
|
2002-07-17 10:25:33 +00:00
|
|
|
{
|
|
|
|
os << "{\\" << key_->name << ' ' << cell(0) << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathFontOld::normalize(NormalStream & os) const
|
2002-07-17 10:25:33 +00:00
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
os << "[font " << key_->name << ' ' << cell(0) << ']';
|
2002-07-17 10:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathFontOld::infoize(odocstream & os) const
|
2002-07-17 10:25:33 +00:00
|
|
|
{
|
2014-11-14 17:18:30 +00:00
|
|
|
os << bformat(_("Font: %1$s"), key_->name);
|
2002-07-17 10:25:33 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|