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(docstring const & name, bool cond)
71 RefChanger<MetricsBase> rc = make_save(*this);
75 ColorCode oldcolor = font.color();
76 docstring const oldname = from_ascii(fontname);
77 fontname = to_utf8(name);
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 Changer MetricsBase::changeFontSet(char const * name, bool cond)
92 return changeFontSet(from_ascii(name), cond);
96 /////////////////////////////////////////////////////////////////////////
100 /////////////////////////////////////////////////////////////////////////
102 MetricsInfo::MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
103 MacroContext const & mc)
104 : base(bv, font, textwidth), macrocontext(mc)
108 /////////////////////////////////////////////////////////////////////////
112 /////////////////////////////////////////////////////////////////////////
114 PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter)
115 : pain(painter), ltr_pos(false), change_(), selected(false),
116 do_spellcheck(true), full_repaint(true), background_color(Color_background)
122 void PainterInfo::draw(int x, int y, char_type c)
124 pain.text(x, y, c, base.font);
128 void PainterInfo::draw(int x, int y, docstring const & str)
130 pain.text(x, y, str, base.font);
134 ColorCode PainterInfo::backgroundColor(Inset const * inset, bool sel) const
136 ColorCode const color_bg = inset->backgroundColor(*this);
139 // This inset is in a selection
140 return Color_selection;
142 if (color_bg != Color_none)
143 // This inset has its own color
146 if (background_color == Color_none)
147 // This inset has no own color and does not inherit a color
148 return Color_background;
150 // This inset has no own color, but inherits a color
151 return background_color;
157 Color PainterInfo::textColor(Color const & color) const
159 if (change_.changed())
160 return change_.color();
162 return Color_selectiontext;
167 Changer MetricsBase::changeScript(bool cond)
172 return changeStyle(LM_ST_SCRIPT, cond);
174 case LM_ST_SCRIPTSCRIPT:
175 return changeStyle(LM_ST_SCRIPTSCRIPT, cond);
178 LASSERT(false, return Changer());
182 Changer MetricsBase::changeFrac(bool cond)
186 return changeStyle(LM_ST_TEXT, cond);
188 return changeStyle(LM_ST_SCRIPT, cond);
190 case LM_ST_SCRIPTSCRIPT:
191 return changeStyle(LM_ST_SCRIPTSCRIPT, cond);
198 Changer MetricsBase::changeStyle(Styles new_style, bool cond)
200 static const int diff[4][4] =
205 int t = diff[style][new_style];
206 RefChanger<MetricsBase> rc = make_save(*this);