2 * \file MetricsInfo.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "BufferView.h"
16 #include "MetricsInfo.h"
18 #include "insets/Inset.h"
20 #include "mathed/MathSupport.h"
22 #include "frontends/Painter.h"
24 #include "support/docstring.h"
25 #include "support/lassert.h"
26 #include "support/RefChanger.h"
33 /////////////////////////////////////////////////////////////////////////
37 /////////////////////////////////////////////////////////////////////////
39 MetricsBase::MetricsBase()
40 : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"), textwidth(0),
41 solid_line_thickness_(1), solid_line_offset_(1), dotted_line_thickness_(1)
43 if (lyxrc.zoom >= 200) {
44 // derive the line thickness from zoom factor
45 // the zoom is given in percent
46 // (increase thickness at 250%, 450% etc.)
47 solid_line_thickness_ = (lyxrc.zoom + 50) / 200;
48 // adjust line_offset_ too
49 solid_line_offset_ = 1 + solid_line_thickness_ / 2;
51 if (lyxrc.zoom >= 100) {
52 // derive the line thickness from zoom factor
53 // the zoom is given in percent
54 // (increase thickness at 150%, 250% etc.)
55 dotted_line_thickness_ = (lyxrc.zoom + 50) / 100;
60 MetricsBase::MetricsBase(BufferView * b, FontInfo f, int w)
69 Changer MetricsBase::changeFontSet(string const & name, bool cond)
71 RefChanger<MetricsBase> rc = make_save(*this);
75 ColorCode oldcolor = font.color();
76 string const oldname = fontname;
79 augmentFont(font, name);
80 font.setSize(rc->old.font.size());
82 && ((isTextFont(oldname) && oldcolor != Color_foreground)
83 || (isMathFont(oldname) && oldcolor != Color_math)))
84 font.setColor(oldcolor);
90 /////////////////////////////////////////////////////////////////////////
94 /////////////////////////////////////////////////////////////////////////
96 MetricsInfo::MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
97 MacroContext const & mc)
98 : base(bv, font, textwidth), macrocontext(mc)
102 /////////////////////////////////////////////////////////////////////////
106 /////////////////////////////////////////////////////////////////////////
108 PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter)
109 : pain(painter), ltr_pos(false), change_(), selected(false),
110 do_spellcheck(true), full_repaint(true), background_color(Color_background)
116 void PainterInfo::draw(int x, int y, char_type c)
118 pain.text(x, y, c, base.font);
122 void PainterInfo::draw(int x, int y, docstring const & str)
124 pain.text(x, y, str, base.font);
128 ColorCode PainterInfo::backgroundColor(Inset const * inset, bool sel) const
130 ColorCode const color_bg = inset->backgroundColor(*this);
133 // This inset is in a selection
134 return Color_selection;
136 if (color_bg != Color_none)
137 // This inset has its own color
140 if (background_color == Color_none)
141 // This inset has no own color and does not inherit a color
142 return Color_background;
144 // This inset has no own color, but inherits a color
145 return background_color;
151 Color PainterInfo::textColor(Color const & color) const
153 if (change_.changed())
154 return change_.color();
156 return Color_selectiontext;
161 Changer MetricsBase::changeScript(bool cond)
166 return changeStyle(LM_ST_SCRIPT, cond);
168 case LM_ST_SCRIPTSCRIPT:
169 return changeStyle(LM_ST_SCRIPTSCRIPT, cond);
172 LASSERT(false, return Changer());
176 Changer MetricsBase::changeFrac(bool cond)
180 return changeStyle(LM_ST_TEXT, cond);
182 return changeStyle(LM_ST_SCRIPT, cond);
184 case LM_ST_SCRIPTSCRIPT:
185 return changeStyle(LM_ST_SCRIPTSCRIPT, cond);
192 Changer MetricsBase::changeStyle(Styles new_style, bool cond)
194 static const int diff[4][4] =
199 int t = diff[style][new_style];
200 RefChanger<MetricsBase> rc = make_save(*this);