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
|
|
|
|
2018-01-05 18:59:31 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
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
|
|
|
{
|
2016-10-29 08:28:34 +00:00
|
|
|
if (lyxrc.currentZoom >= 200) {
|
2016-05-22 21:48:28 +00:00
|
|
|
// derive the line thickness from zoom factor
|
|
|
|
// the zoom is given in percent
|
|
|
|
// (increase thickness at 250%, 450% etc.)
|
2016-10-29 08:28:34 +00:00
|
|
|
solid_line_thickness_ = (lyxrc.currentZoom + 150) / 200;
|
2016-05-22 21:48:28 +00:00
|
|
|
// adjust line_offset_ too
|
|
|
|
solid_line_offset_ = 1 + solid_line_thickness_ / 2;
|
|
|
|
}
|
2016-10-29 08:28:34 +00:00
|
|
|
if (lyxrc.currentZoom >= 100) {
|
2016-05-22 21:48:28 +00:00
|
|
|
// derive the line thickness from zoom factor
|
|
|
|
// the zoom is given in percent
|
|
|
|
// (increase thickness at 150%, 250% etc.)
|
2016-10-29 08:28:34 +00:00
|
|
|
dotted_line_thickness_ = (lyxrc.currentZoom + 50) / 100;
|
2016-05-22 21:48:28 +00:00
|
|
|
}
|
|
|
|
}
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
|
|
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer MetricsBase::changeFontSet(string const & name)
|
2016-05-23 21:30:23 +00:00
|
|
|
{
|
|
|
|
RefChanger<MetricsBase> rc = make_save(*this);
|
2016-11-20 18:53:16 +00:00
|
|
|
ColorCode oldcolor = font.color();
|
|
|
|
string const oldname = fontname;
|
|
|
|
fontname = name;
|
|
|
|
if (isMathFont(name) || isMathFont(oldname))
|
|
|
|
font = sane_font;
|
|
|
|
augmentFont(font, name);
|
|
|
|
font.setSize(rc->old.font.size());
|
|
|
|
font.setStyle(rc->old.font.style());
|
|
|
|
if (name != "lyxtex"
|
|
|
|
&& ((isTextFont(oldname) && oldcolor != Color_foreground)
|
|
|
|
|| (isMathFont(oldname) && oldcolor != Color_math)))
|
|
|
|
font.setColor(oldcolor);
|
2019-06-12 16:49:29 +00:00
|
|
|
#if __cplusplus >= 201402L
|
|
|
|
return rc;
|
|
|
|
#else
|
2019-06-07 17:41:16 +00:00
|
|
|
return move(rc);
|
2019-06-12 16:49:29 +00:00
|
|
|
#endif
|
2016-05-23 21:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-12 00:17:41 +00:00
|
|
|
Changer MetricsBase::changeEnsureMath(Inset::mode_type mode)
|
2016-11-22 10:26:15 +00:00
|
|
|
{
|
2016-12-12 00:17:41 +00:00
|
|
|
switch (mode) {
|
|
|
|
case Inset::UNDECIDED_MODE:
|
|
|
|
return Changer();
|
|
|
|
case Inset::TEXT_MODE:
|
|
|
|
return isMathFont(fontname) ? changeFontSet("textnormal") : Changer();
|
|
|
|
case Inset::MATH_MODE:
|
|
|
|
// FIXME:
|
|
|
|
// \textit{\ensuremath{\text{a}}}
|
|
|
|
// should appear in italics
|
|
|
|
return isTextFont(fontname) ? changeFontSet("mathnormal"): Changer();
|
|
|
|
}
|
|
|
|
return Changer();
|
2016-11-22 10:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-05 18:59:31 +00:00
|
|
|
int MetricsBase::inPixels(Length const & len) const
|
|
|
|
{
|
|
|
|
FontInfo fi = font;
|
|
|
|
if (len.unit() == Length::MU)
|
|
|
|
// mu is 1/18th of an em in the math symbol font
|
|
|
|
fi.setFamily(SYMBOL_FAMILY);
|
|
|
|
else
|
|
|
|
// Math style is only taken into account in the case of mu
|
2019-06-14 14:42:02 +00:00
|
|
|
fi.setStyle(TEXT_STYLE);
|
2018-01-05 18:59:31 +00:00
|
|
|
return len.inPixels(textwidth, theFontMetrics(fi).em());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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),
|
2019-04-02 09:05:19 +00:00
|
|
|
do_spellcheck(true), full_repaint(true), background_color(Color_background),
|
|
|
|
leftx(0), rightx(0)
|
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;
|
2019-10-21 14:45:03 +00:00
|
|
|
|
|
|
|
if (pain.develMode() && !inset->isBufferValid())
|
|
|
|
// This inset is in error
|
|
|
|
return Color_error;
|
|
|
|
|
|
|
|
if (color_bg != Color_none)
|
|
|
|
// This inset has its own color
|
|
|
|
return color_bg;
|
|
|
|
|
|
|
|
if (background_color == Color_none)
|
|
|
|
// This inset has no own color and does not inherit a color
|
|
|
|
return Color_background;
|
|
|
|
|
|
|
|
// This inset has no own color, but inherits a color
|
|
|
|
return background_color;
|
2008-10-25 10:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-02 12:13:54 +00:00
|
|
|
Color PainterInfo::textColor(Color const & color) const
|
|
|
|
{
|
2017-07-03 17:53:14 +00:00
|
|
|
if (change_.changed())
|
2010-09-02 12:13:54 +00:00
|
|
|
return change_.color();
|
|
|
|
if (selected)
|
|
|
|
return Color_selectiontext;
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer MetricsBase::changeScript()
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2016-11-19 20:25:34 +00:00
|
|
|
switch (font.style()) {
|
2019-06-14 14:42:02 +00:00
|
|
|
case DISPLAY_STYLE:
|
|
|
|
case TEXT_STYLE:
|
|
|
|
return font.changeStyle(SCRIPT_STYLE);
|
|
|
|
case SCRIPT_STYLE:
|
|
|
|
case SCRIPTSCRIPT_STYLE:
|
|
|
|
return font.changeStyle(SCRIPTSCRIPT_STYLE);
|
|
|
|
case INHERIT_STYLE:
|
|
|
|
case IGNORE_STYLE:
|
2019-03-22 14:19:27 +00:00
|
|
|
return Changer();
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
2016-05-23 21:30:23 +00:00
|
|
|
//remove Warning
|
2016-11-20 18:53:16 +00:00
|
|
|
return Changer();
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 23:30:24 +00:00
|
|
|
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer MetricsBase::changeFrac()
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2016-11-19 20:25:34 +00:00
|
|
|
switch (font.style()) {
|
2019-06-14 14:42:02 +00:00
|
|
|
case DISPLAY_STYLE:
|
|
|
|
return font.changeStyle(TEXT_STYLE);
|
|
|
|
case TEXT_STYLE:
|
|
|
|
return font.changeStyle(SCRIPT_STYLE);
|
|
|
|
case SCRIPT_STYLE:
|
|
|
|
case SCRIPTSCRIPT_STYLE:
|
|
|
|
return font.changeStyle(SCRIPTSCRIPT_STYLE);
|
|
|
|
case INHERIT_STYLE:
|
|
|
|
case IGNORE_STYLE:
|
2019-03-22 14:19:27 +00:00
|
|
|
return Changer();
|
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
|
|
|
|
2019-07-15 11:36:28 +00:00
|
|
|
Changer MetricsBase::changeArray(bool small)
|
2016-11-20 18:53:16 +00:00
|
|
|
{
|
2019-07-15 11:36:28 +00:00
|
|
|
if (small)
|
|
|
|
return font.changeStyle(SCRIPT_STYLE);
|
2019-06-14 14:42:02 +00:00
|
|
|
return (font.style() == DISPLAY_STYLE) ? font.changeStyle(TEXT_STYLE)
|
2016-11-20 18:53:16 +00:00
|
|
|
: Changer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|