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>
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
2020-10-24 21:47:13 +00:00
|
|
|
#include "LyXRC.h"
|
|
|
|
|
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-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)
|
2022-10-21 12:11:36 +00:00
|
|
|
: bv(b), font(std::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());
|
2021-03-04 10:58:44 +00:00
|
|
|
if (name == "emph") {
|
|
|
|
font.setColor(oldcolor);
|
|
|
|
if (rc->old.font.shape() != UP_SHAPE)
|
|
|
|
font.setShape(UP_SHAPE);
|
|
|
|
else
|
|
|
|
font.setShape(ITALIC_SHAPE);
|
|
|
|
} else if (name != "lyxtex"
|
2016-11-20 18:53:16 +00:00
|
|
|
&& ((isTextFont(oldname) && oldcolor != Color_foreground)
|
|
|
|
|| (isMathFont(oldname) && oldcolor != Color_math)))
|
|
|
|
font.setColor(oldcolor);
|
2022-11-16 16:43:22 +00:00
|
|
|
#if __cplusplus >= 201402L
|
2019-06-12 16:49:29 +00:00
|
|
|
return rc;
|
2022-11-16 16:43:22 +00:00
|
|
|
#else
|
|
|
|
/** In theory, this is not needed with C++11, and modern compilers
|
|
|
|
* will complain in C++11 mode, but gcc 4.9 requires this. */
|
|
|
|
return std::move(rc);
|
|
|
|
#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:
|
2020-11-12 12:09:36 +00:00
|
|
|
return noChange();
|
2016-12-12 00:17:41 +00:00
|
|
|
case Inset::TEXT_MODE:
|
2020-11-12 12:09:36 +00:00
|
|
|
return isMathFont(fontname) ? changeFontSet("textnormal") : noChange();
|
2016-12-12 00:17:41 +00:00
|
|
|
case Inset::MATH_MODE:
|
|
|
|
// FIXME:
|
|
|
|
// \textit{\ensuremath{\text{a}}}
|
|
|
|
// should appear in italics
|
2020-11-12 12:09:36 +00:00
|
|
|
return isTextFont(fontname) ? changeFontSet("mathnormal"): noChange();
|
2016-12-12 00:17:41 +00:00
|
|
|
}
|
2020-11-12 12:09:36 +00:00
|
|
|
return noChange();
|
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,
|
2020-07-14 21:28:43 +00:00
|
|
|
MacroContext const & mc, bool vm, bool tight)
|
|
|
|
: base(bv, font, textwidth), macrocontext(mc), vmode(vm), tight_insets(tight)
|
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)
|
2021-07-01 16:35:16 +00:00
|
|
|
: pain(painter), ltr_pos(false), change(),
|
|
|
|
selected(false), selected_left(false), selected_right(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
|
|
|
|
{
|
|
|
|
if (selected && sel)
|
|
|
|
// This inset is in a selection
|
|
|
|
return Color_selection;
|
2019-10-21 14:45:03 +00:00
|
|
|
|
2020-06-05 20:32:58 +00:00
|
|
|
// special handling for inset background
|
|
|
|
if (inset != nullptr) {
|
|
|
|
if (pain.develMode() && !inset->isBufferValid())
|
|
|
|
// This inset is in error
|
|
|
|
return Color_error;
|
2019-10-21 14:45:03 +00:00
|
|
|
|
2020-06-05 20:32:58 +00:00
|
|
|
ColorCode const color_bg = inset->backgroundColor(*this);
|
|
|
|
if (color_bg != Color_none)
|
|
|
|
// This inset has its own color
|
|
|
|
return color_bg;
|
|
|
|
}
|
2019-10-21 14:45:03 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2020-01-14 10:50:44 +00:00
|
|
|
if (change.changed())
|
|
|
|
return change.color();
|
2010-09-02 12:13:54 +00:00
|
|
|
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:
|
2020-11-12 12:09:36 +00:00
|
|
|
return noChange();
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
2016-05-23 21:30:23 +00:00
|
|
|
//remove Warning
|
2020-11-12 12:09:36 +00:00
|
|
|
return noChange();
|
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:
|
2020-11-12 12:09:36 +00:00
|
|
|
return noChange();
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
2016-05-23 21:30:23 +00:00
|
|
|
//remove Warning
|
2020-11-12 12:09:36 +00:00
|
|
|
return noChange();
|
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)
|
2020-11-12 12:09:36 +00:00
|
|
|
: noChange();
|
2016-11-20 18:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|