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
|
|
|
|
|
|
|
|
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);
|
2016-05-23 21:30:23 +00:00
|
|
|
return move(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-22 10:26:15 +00:00
|
|
|
Changer MetricsBase::changeEnsureMath()
|
|
|
|
{
|
|
|
|
// FIXME:
|
|
|
|
// \textit{\ensuremath{\text{a}}}
|
|
|
|
// should appear in italics
|
|
|
|
return isTextFont(fontname) ? changeFontSet("mathnormal") : Changer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-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()) {
|
2016-05-23 21:30:23 +00:00
|
|
|
case LM_ST_DISPLAY:
|
|
|
|
case LM_ST_TEXT:
|
2016-11-20 18:53:16 +00:00
|
|
|
return font.changeStyle(LM_ST_SCRIPT);
|
2016-05-23 21:30:23 +00:00
|
|
|
case LM_ST_SCRIPT:
|
|
|
|
case LM_ST_SCRIPTSCRIPT:
|
2016-11-20 18:53:16 +00:00
|
|
|
return font.changeStyle(LM_ST_SCRIPTSCRIPT);
|
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()) {
|
2016-05-23 21:30:23 +00:00
|
|
|
case LM_ST_DISPLAY:
|
2016-11-20 18:53:16 +00:00
|
|
|
return font.changeStyle(LM_ST_TEXT);
|
2016-05-23 21:30:23 +00:00
|
|
|
case LM_ST_TEXT:
|
2016-11-20 18:53:16 +00:00
|
|
|
return font.changeStyle(LM_ST_SCRIPT);
|
2016-05-23 21:30:23 +00:00
|
|
|
case LM_ST_SCRIPT:
|
|
|
|
case LM_ST_SCRIPTSCRIPT:
|
2016-11-20 18:53:16 +00:00
|
|
|
return font.changeStyle(LM_ST_SCRIPTSCRIPT);
|
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
|
|
|
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer MetricsBase::changeArray()
|
|
|
|
{
|
|
|
|
return (font.style() == LM_ST_DISPLAY) ? font.changeStyle(LM_ST_TEXT)
|
|
|
|
: Changer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|