2003-08-23 00:17:00 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file MetricsInfo.h
|
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
|
2007-11-01 11:13:07 +00:00
|
|
|
* \author Stefan Schimanski
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
#ifndef METRICSINFO_H
|
|
|
|
#define METRICSINFO_H
|
|
|
|
|
2009-02-09 21:14:23 +00:00
|
|
|
#include "Changes.h"
|
2010-09-02 12:13:54 +00:00
|
|
|
#include "Color.h"
|
2007-10-28 18:51:54 +00:00
|
|
|
#include "FontInfo.h"
|
2007-10-31 22:40:34 +00:00
|
|
|
|
|
|
|
#include "support/strfwd.h"
|
|
|
|
#include "support/types.h"
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
#include <string>
|
2003-03-21 14:20:48 +00:00
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
class BufferView;
|
2003-03-21 14:20:48 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
namespace lyx {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace frontend { class Painter; }
|
2008-10-25 10:47:38 +00:00
|
|
|
class Inset;
|
2007-11-01 11:13:07 +00:00
|
|
|
class MacroContext;
|
2006-06-20 08:39:16 +00:00
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
|
|
|
/// Standard Sizes (mode styles)
|
|
|
|
enum Styles {
|
|
|
|
///
|
|
|
|
LM_ST_DISPLAY = 0,
|
|
|
|
///
|
|
|
|
LM_ST_TEXT,
|
|
|
|
///
|
|
|
|
LM_ST_SCRIPT,
|
|
|
|
///
|
|
|
|
LM_ST_SCRIPTSCRIPT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-09-09 18:27:24 +00:00
|
|
|
//
|
2003-03-21 14:20:48 +00:00
|
|
|
// This is the part common to MetricsInfo and PainterInfo
|
|
|
|
//
|
2005-01-19 15:03:31 +00:00
|
|
|
class MetricsBase {
|
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
MetricsBase();
|
2003-07-17 09:10:16 +00:00
|
|
|
///
|
2007-10-28 18:51:54 +00:00
|
|
|
MetricsBase(BufferView * bv, FontInfo const & font, int textwidth);
|
2003-03-21 14:20:48 +00:00
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
/// the current view
|
|
|
|
BufferView * bv;
|
|
|
|
/// current font
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo font;
|
2003-05-28 13:22:36 +00:00
|
|
|
/// current math style (display/text/script/..)
|
2003-03-21 14:20:48 +00:00
|
|
|
Styles style;
|
2003-07-25 19:18:43 +00:00
|
|
|
/// name of current font - mathed specific
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string fontname;
|
2003-07-25 19:18:43 +00:00
|
|
|
/// This is the width available in pixels
|
2003-03-21 14:20:48 +00:00
|
|
|
int textwidth;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2004-04-08 16:07:20 +00:00
|
|
|
// This contains a MetricsBase and information that's only relevant during
|
2003-03-21 14:20:48 +00:00
|
|
|
// the first phase of the two-phase draw
|
|
|
|
//
|
2005-01-19 15:03:31 +00:00
|
|
|
class MetricsInfo {
|
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
MetricsInfo();
|
2003-07-17 09:10:16 +00:00
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth, MacroContext const & mc);
|
2003-03-21 14:20:48 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
MetricsBase base;
|
2007-11-01 11:13:07 +00:00
|
|
|
/// The context to resolve macros
|
|
|
|
MacroContext const & macrocontext;
|
2003-03-21 14:20:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2004-04-08 16:07:20 +00:00
|
|
|
// This contains a MetricsBase and information that's only relevant during
|
2003-03-21 14:20:48 +00:00
|
|
|
// the second phase of the two-phase draw
|
|
|
|
//
|
2005-01-19 15:03:31 +00:00
|
|
|
class PainterInfo {
|
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
PainterInfo(BufferView * bv, frontend::Painter & pain);
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
void draw(int x, int y, char_type c);
|
2005-07-17 10:31:44 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
void draw(int x, int y, docstring const & str);
|
2008-10-25 10:47:38 +00:00
|
|
|
/// Determines the background color for the specified inset based on the
|
|
|
|
/// selection state, the background color inherited from the parent inset
|
|
|
|
/// and the inset's own background color.
|
|
|
|
/// \param sel whether to take the selection state into account
|
|
|
|
ColorCode backgroundColor(Inset const * inset, bool sel = true) const;
|
2003-03-21 14:20:48 +00:00
|
|
|
|
2010-09-02 12:13:54 +00:00
|
|
|
/// Determines the text color based on the intended color, the
|
|
|
|
/// change tracking state and the selectio state.
|
|
|
|
/// \param color what the color should be by default
|
|
|
|
Color textColor(Color const & color) const;
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
MetricsBase base;
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
frontend::Painter & pain;
|
2004-08-14 23:57:29 +00:00
|
|
|
/// Whether the text at this point is right-to-left (for InsetNewline)
|
|
|
|
bool ltr_pos;
|
2009-02-09 21:14:23 +00:00
|
|
|
/// The change the parent is part of (change tracking)
|
|
|
|
Change change_;
|
2008-10-25 10:47:38 +00:00
|
|
|
/// Whether the parent is selected as a whole
|
|
|
|
bool selected;
|
2007-08-30 13:53:02 +00:00
|
|
|
///
|
|
|
|
bool full_repaint;
|
2008-10-25 10:47:38 +00:00
|
|
|
/// Current background color
|
2007-10-29 10:36:20 +00:00
|
|
|
ColorCode background_color;
|
2003-03-21 14:20:48 +00:00
|
|
|
};
|
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
class TextMetricsInfo {};
|
2003-03-21 14:20:48 +00:00
|
|
|
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
/// Generic base for temporarily changing things.
|
|
|
|
/// The original state gets restored when the Changer is destructed.
|
2003-03-21 14:20:48 +00:00
|
|
|
template <class Struct, class Temp = Struct>
|
2005-01-19 15:03:31 +00:00
|
|
|
class Changer {
|
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
Changer(Struct & orig) : orig_(orig) {}
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
Struct & orig_;
|
|
|
|
///
|
|
|
|
Temp save_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// temporarily change some aspect of a font
|
2007-10-28 18:51:54 +00:00
|
|
|
class FontChanger : public Changer<FontInfo> {
|
2005-01-19 15:03:31 +00:00
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
2007-10-28 18:51:54 +00:00
|
|
|
FontChanger(FontInfo & orig, docstring const & font);
|
2006-10-22 10:15:23 +00:00
|
|
|
FontChanger(MetricsBase & mb, char const * const font);
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
~FontChanger();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// temporarily change a full font
|
2005-01-19 15:03:31 +00:00
|
|
|
class FontSetChanger : public Changer<MetricsBase> {
|
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
2010-04-27 21:31:28 +00:00
|
|
|
FontSetChanger(MetricsBase & mb, docstring const & font,
|
|
|
|
bool really_change_font = true);
|
|
|
|
FontSetChanger(MetricsBase & mb, char const * const font,
|
|
|
|
bool really_change_font = true);
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
~FontSetChanger();
|
2010-04-27 21:31:28 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
bool change_;
|
2003-03-21 14:20:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// temporarily change the style
|
2005-01-19 15:03:31 +00:00
|
|
|
class StyleChanger : public Changer<MetricsBase> {
|
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
StyleChanger(MetricsBase & mb, Styles style);
|
|
|
|
///
|
|
|
|
~StyleChanger();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// temporarily change the style to script style
|
2005-01-19 15:03:31 +00:00
|
|
|
class ScriptChanger : public StyleChanger {
|
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
ScriptChanger(MetricsBase & mb);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// temporarily change the style suitable for use in fractions
|
2005-01-19 15:03:31 +00:00
|
|
|
class FracChanger : public StyleChanger {
|
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
FracChanger(MetricsBase & mb);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// temporarily change the style suitable for use in tabulars and arrays
|
2005-01-19 15:03:31 +00:00
|
|
|
class ArrayChanger : public StyleChanger {
|
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
ArrayChanger(MetricsBase & mb);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// temporarily change the shape of a font
|
2007-10-28 18:51:54 +00:00
|
|
|
class ShapeChanger : public Changer<FontInfo, FontShape> {
|
2005-01-19 15:03:31 +00:00
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
2007-10-28 18:51:54 +00:00
|
|
|
ShapeChanger(FontInfo & font, FontShape shape);
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
~ShapeChanger();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// temporarily change the available text width
|
2005-01-19 15:03:31 +00:00
|
|
|
class WidthChanger : public Changer<MetricsBase>
|
2003-03-21 14:20:48 +00:00
|
|
|
{
|
2005-01-19 15:03:31 +00:00
|
|
|
public:
|
2003-03-21 14:20:48 +00:00
|
|
|
///
|
|
|
|
WidthChanger(MetricsBase & mb, int width);
|
|
|
|
///
|
|
|
|
~WidthChanger();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-10-02 14:42:31 +00:00
|
|
|
// temporarily change the used color
|
Index: src/mathed/InsetMathHull.cpp
===================================================================
--- src/mathed/InsetMathHull.cpp (revisione 34304)
+++ src/mathed/InsetMathHull.cpp (copia locale)
@@ -328,6 +328,23 @@ docstring InsetMathHull::standardFont()
}
+docstring InsetMathHull::standardColor() const
+{
+ docstring color;
+ switch (type_) {
+ case hullRegexp:
+ color = from_ascii("foreground");
+ break;
+ case hullNone:
+ color = from_ascii("foreground");
+ break;
+ default:
+ color = from_ascii("math");
+ }
+ return color;
+}
+
+
bool InsetMathHull::previewState(BufferView * bv) const
{
if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
@@ -417,8 +434,11 @@ void InsetMathHull::draw(PainterInfo & p
return;
}
+ bool const really_change_color = pi.base.font.color() == Color_none;
+ ColorChanger dummy0(pi.base.font, standardColor(), really_change_color);
FontSetChanger dummy1(pi.base, standardFont());
StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+
InsetMathGrid::draw(pi, x + 1, y);
if (numberedType()) {
Index: src/mathed/MathSupport.cpp
===================================================================
--- src/mathed/MathSupport.cpp (revisione 34311)
+++ src/mathed/MathSupport.cpp (copia locale)
@@ -653,6 +653,13 @@ bool isMathFont(docstring const & name)
}
+bool isTextFont(docstring const & name)
+{
+ fontinfo * f = lookupFont(name);
+ return f && f->color_ == Color_foreground;
+}
+
+
FontInfo getFont(docstring const & name)
{
FontInfo font;
Index: src/mathed/MathSupport.h
===================================================================
--- src/mathed/MathSupport.h (revisione 34311)
+++ src/mathed/MathSupport.h (copia locale)
@@ -51,6 +51,8 @@ bool isFontName(docstring const & name);
bool isMathFont(docstring const & name);
+bool isTextFont(docstring const & name);
+
// converts single cell to string
docstring asString(MathData const & ar);
// converts single inset to string
Index: src/mathed/InsetMathHull.h
===================================================================
--- src/mathed/InsetMathHull.h (revisione 34304)
+++ src/mathed/InsetMathHull.h (copia locale)
@@ -197,6 +197,8 @@ private:
void changeCols(col_type);
///
docstring standardFont() const;
+ ///
+ docstring standardColor() const;
/// consistency check
void check() const;
/// can this change its number of rows?
Index: src/MetricsInfo.cpp
===================================================================
--- src/MetricsInfo.cpp (revisione 34312)
+++ src/MetricsInfo.cpp (copia locale)
@@ -235,11 +235,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = name;
mb.font = sane_font;
augmentFont(mb.font, from_ascii(name));
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (string(name) != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -252,11 +256,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = to_utf8(name);
mb.font = sane_font;
augmentFont(mb.font, name);
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (name != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -294,17 +302,21 @@ WidthChanger::~WidthChanger()
//
/////////////////////////////////////////////////////////////////////////
-ColorChanger::ColorChanger(FontInfo & font, string const & color)
- : Changer<FontInfo, string>(font)
+ColorChanger::ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color)
+ : Changer<FontInfo, ColorCode>(font), change_(really_change_color)
{
- save_ = lcolor.getFromLyXName(color);
- font.setColor(lcolor.getFromLyXName(color));
+ if (change_) {
+ save_ = font.color();
+ font.setColor(lcolor.getFromLyXName(to_utf8(color)));
+ }
}
ColorChanger::~ColorChanger()
{
- orig_.setColor(lcolor.getFromLyXName(save_));
+ if (change_)
+ orig_.setColor(save_);
}
Index: src/MetricsInfo.h
===================================================================
--- src/MetricsInfo.h (revisione 34312)
+++ src/MetricsInfo.h (copia locale)
@@ -222,12 +222,16 @@ public:
// temporarily change the used color
-class ColorChanger : public Changer<FontInfo, std::string> {
+class ColorChanger : public Changer<FontInfo, ColorCode> {
public:
///
- ColorChanger(FontInfo & font, std::string const & color);
+ ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color = true);
///
~ColorChanger();
+private:
+ ///
+ bool change_;
};
} // namespace lyx
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34320 a592a061-630c-0410-9148-cb99ea01b6c8
2010-04-28 01:40:11 +00:00
|
|
|
class ColorChanger : public Changer<FontInfo, ColorCode> {
|
2005-01-19 15:03:31 +00:00
|
|
|
public:
|
2003-10-02 14:42:31 +00:00
|
|
|
///
|
Index: src/mathed/InsetMathHull.cpp
===================================================================
--- src/mathed/InsetMathHull.cpp (revisione 34304)
+++ src/mathed/InsetMathHull.cpp (copia locale)
@@ -328,6 +328,23 @@ docstring InsetMathHull::standardFont()
}
+docstring InsetMathHull::standardColor() const
+{
+ docstring color;
+ switch (type_) {
+ case hullRegexp:
+ color = from_ascii("foreground");
+ break;
+ case hullNone:
+ color = from_ascii("foreground");
+ break;
+ default:
+ color = from_ascii("math");
+ }
+ return color;
+}
+
+
bool InsetMathHull::previewState(BufferView * bv) const
{
if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
@@ -417,8 +434,11 @@ void InsetMathHull::draw(PainterInfo & p
return;
}
+ bool const really_change_color = pi.base.font.color() == Color_none;
+ ColorChanger dummy0(pi.base.font, standardColor(), really_change_color);
FontSetChanger dummy1(pi.base, standardFont());
StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+
InsetMathGrid::draw(pi, x + 1, y);
if (numberedType()) {
Index: src/mathed/MathSupport.cpp
===================================================================
--- src/mathed/MathSupport.cpp (revisione 34311)
+++ src/mathed/MathSupport.cpp (copia locale)
@@ -653,6 +653,13 @@ bool isMathFont(docstring const & name)
}
+bool isTextFont(docstring const & name)
+{
+ fontinfo * f = lookupFont(name);
+ return f && f->color_ == Color_foreground;
+}
+
+
FontInfo getFont(docstring const & name)
{
FontInfo font;
Index: src/mathed/MathSupport.h
===================================================================
--- src/mathed/MathSupport.h (revisione 34311)
+++ src/mathed/MathSupport.h (copia locale)
@@ -51,6 +51,8 @@ bool isFontName(docstring const & name);
bool isMathFont(docstring const & name);
+bool isTextFont(docstring const & name);
+
// converts single cell to string
docstring asString(MathData const & ar);
// converts single inset to string
Index: src/mathed/InsetMathHull.h
===================================================================
--- src/mathed/InsetMathHull.h (revisione 34304)
+++ src/mathed/InsetMathHull.h (copia locale)
@@ -197,6 +197,8 @@ private:
void changeCols(col_type);
///
docstring standardFont() const;
+ ///
+ docstring standardColor() const;
/// consistency check
void check() const;
/// can this change its number of rows?
Index: src/MetricsInfo.cpp
===================================================================
--- src/MetricsInfo.cpp (revisione 34312)
+++ src/MetricsInfo.cpp (copia locale)
@@ -235,11 +235,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = name;
mb.font = sane_font;
augmentFont(mb.font, from_ascii(name));
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (string(name) != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -252,11 +256,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = to_utf8(name);
mb.font = sane_font;
augmentFont(mb.font, name);
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (name != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -294,17 +302,21 @@ WidthChanger::~WidthChanger()
//
/////////////////////////////////////////////////////////////////////////
-ColorChanger::ColorChanger(FontInfo & font, string const & color)
- : Changer<FontInfo, string>(font)
+ColorChanger::ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color)
+ : Changer<FontInfo, ColorCode>(font), change_(really_change_color)
{
- save_ = lcolor.getFromLyXName(color);
- font.setColor(lcolor.getFromLyXName(color));
+ if (change_) {
+ save_ = font.color();
+ font.setColor(lcolor.getFromLyXName(to_utf8(color)));
+ }
}
ColorChanger::~ColorChanger()
{
- orig_.setColor(lcolor.getFromLyXName(save_));
+ if (change_)
+ orig_.setColor(save_);
}
Index: src/MetricsInfo.h
===================================================================
--- src/MetricsInfo.h (revisione 34312)
+++ src/MetricsInfo.h (copia locale)
@@ -222,12 +222,16 @@ public:
// temporarily change the used color
-class ColorChanger : public Changer<FontInfo, std::string> {
+class ColorChanger : public Changer<FontInfo, ColorCode> {
public:
///
- ColorChanger(FontInfo & font, std::string const & color);
+ ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color = true);
///
~ColorChanger();
+private:
+ ///
+ bool change_;
};
} // namespace lyx
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34320 a592a061-630c-0410-9148-cb99ea01b6c8
2010-04-28 01:40:11 +00:00
|
|
|
ColorChanger(FontInfo & font, docstring const & color,
|
|
|
|
bool really_change_color = true);
|
2003-10-02 14:42:31 +00:00
|
|
|
///
|
|
|
|
~ColorChanger();
|
Index: src/mathed/InsetMathHull.cpp
===================================================================
--- src/mathed/InsetMathHull.cpp (revisione 34304)
+++ src/mathed/InsetMathHull.cpp (copia locale)
@@ -328,6 +328,23 @@ docstring InsetMathHull::standardFont()
}
+docstring InsetMathHull::standardColor() const
+{
+ docstring color;
+ switch (type_) {
+ case hullRegexp:
+ color = from_ascii("foreground");
+ break;
+ case hullNone:
+ color = from_ascii("foreground");
+ break;
+ default:
+ color = from_ascii("math");
+ }
+ return color;
+}
+
+
bool InsetMathHull::previewState(BufferView * bv) const
{
if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
@@ -417,8 +434,11 @@ void InsetMathHull::draw(PainterInfo & p
return;
}
+ bool const really_change_color = pi.base.font.color() == Color_none;
+ ColorChanger dummy0(pi.base.font, standardColor(), really_change_color);
FontSetChanger dummy1(pi.base, standardFont());
StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+
InsetMathGrid::draw(pi, x + 1, y);
if (numberedType()) {
Index: src/mathed/MathSupport.cpp
===================================================================
--- src/mathed/MathSupport.cpp (revisione 34311)
+++ src/mathed/MathSupport.cpp (copia locale)
@@ -653,6 +653,13 @@ bool isMathFont(docstring const & name)
}
+bool isTextFont(docstring const & name)
+{
+ fontinfo * f = lookupFont(name);
+ return f && f->color_ == Color_foreground;
+}
+
+
FontInfo getFont(docstring const & name)
{
FontInfo font;
Index: src/mathed/MathSupport.h
===================================================================
--- src/mathed/MathSupport.h (revisione 34311)
+++ src/mathed/MathSupport.h (copia locale)
@@ -51,6 +51,8 @@ bool isFontName(docstring const & name);
bool isMathFont(docstring const & name);
+bool isTextFont(docstring const & name);
+
// converts single cell to string
docstring asString(MathData const & ar);
// converts single inset to string
Index: src/mathed/InsetMathHull.h
===================================================================
--- src/mathed/InsetMathHull.h (revisione 34304)
+++ src/mathed/InsetMathHull.h (copia locale)
@@ -197,6 +197,8 @@ private:
void changeCols(col_type);
///
docstring standardFont() const;
+ ///
+ docstring standardColor() const;
/// consistency check
void check() const;
/// can this change its number of rows?
Index: src/MetricsInfo.cpp
===================================================================
--- src/MetricsInfo.cpp (revisione 34312)
+++ src/MetricsInfo.cpp (copia locale)
@@ -235,11 +235,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = name;
mb.font = sane_font;
augmentFont(mb.font, from_ascii(name));
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (string(name) != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -252,11 +256,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = to_utf8(name);
mb.font = sane_font;
augmentFont(mb.font, name);
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (name != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -294,17 +302,21 @@ WidthChanger::~WidthChanger()
//
/////////////////////////////////////////////////////////////////////////
-ColorChanger::ColorChanger(FontInfo & font, string const & color)
- : Changer<FontInfo, string>(font)
+ColorChanger::ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color)
+ : Changer<FontInfo, ColorCode>(font), change_(really_change_color)
{
- save_ = lcolor.getFromLyXName(color);
- font.setColor(lcolor.getFromLyXName(color));
+ if (change_) {
+ save_ = font.color();
+ font.setColor(lcolor.getFromLyXName(to_utf8(color)));
+ }
}
ColorChanger::~ColorChanger()
{
- orig_.setColor(lcolor.getFromLyXName(save_));
+ if (change_)
+ orig_.setColor(save_);
}
Index: src/MetricsInfo.h
===================================================================
--- src/MetricsInfo.h (revisione 34312)
+++ src/MetricsInfo.h (copia locale)
@@ -222,12 +222,16 @@ public:
// temporarily change the used color
-class ColorChanger : public Changer<FontInfo, std::string> {
+class ColorChanger : public Changer<FontInfo, ColorCode> {
public:
///
- ColorChanger(FontInfo & font, std::string const & color);
+ ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color = true);
///
~ColorChanger();
+private:
+ ///
+ bool change_;
};
} // namespace lyx
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34320 a592a061-630c-0410-9148-cb99ea01b6c8
2010-04-28 01:40:11 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
bool change_;
|
2003-10-02 14:42:31 +00:00
|
|
|
};
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
#endif
|