#include "FontLoader.h"
#include "font.h"
#include "math_defs.h"
+#include "math_inset.h"
#include "math_parser.h"
#include "Painter.h"
#include "debug.h"
}
-LyXFont whichFont(MathTextCodes type, MathStyles size)
+LyXFont whichFont(MathTextCodes type, MathMetricsInfo const & size)
{
LyXFont f = whichFontBase(type);
+ // use actual size
+ f.setSize(size.font.size());
- switch (size) {
+ switch (size.style) {
case LM_ST_DISPLAY:
if (type == LM_TC_BOLDSYMB || type == LM_TC_CMEX) {
f.incSize();
break;
default:
- lyxerr << "Math Error: wrong font size: " << size << endl;
+ lyxerr << "Math Error: wrong font size: " << size.style << endl;
break;
}
{
if (!font_available_initialized[type]) {
font_available_initialized[type] = true;
- font_available[type] =
- fontloader.available(whichFontBase(type));
+ font_available[type] = fontloader.available(whichFontBase(type));
}
return font_available[type];
}
} // namespace anon
-void mathed_char_dim(MathTextCodes type, MathStyles size, unsigned char c,
- int & asc, int & des, int & wid)
+void mathed_char_dim(MathTextCodes type, MathMetricsInfo const & size,
+ unsigned char c, int & asc, int & des, int & wid)
{
LyXFont const font = whichFont(type, size);
des = lyxfont::descent(c, font);
}
-int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c,
- int & asc, int & des)
+int mathed_char_height(MathTextCodes type, MathMetricsInfo const & size,
+ unsigned char c, int & asc, int & des)
{
LyXFont const font = whichFont(type, size);
des = lyxfont::descent(c, font);
}
-int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c)
+int mathed_char_height(MathTextCodes type, MathMetricsInfo const & size,
+ unsigned char c)
{
int asc;
int des;
}
-int mathed_char_ascent(MathTextCodes type, MathStyles size, unsigned char c)
+int mathed_char_ascent(MathTextCodes type, MathMetricsInfo const & size,
+ unsigned char c)
{
LyXFont const font = whichFont(type, size);
return lyxfont::ascent(c, font);
}
-int mathed_char_descent(MathTextCodes type, MathStyles size, unsigned char c)
+int mathed_char_descent(MathTextCodes type, MathMetricsInfo const & size,
+ unsigned char c)
{
LyXFont const font = whichFont(type, size);
return lyxfont::descent(c, font);
}
-int mathed_char_width(MathTextCodes type, MathStyles size, unsigned char c)
+int mathed_char_width(MathTextCodes type, MathMetricsInfo const & size,
+ unsigned char c)
{
LyXFont const font = whichFont(type, size);
if (isBinaryOp(c, type))
}
-void mathed_string_dim(MathTextCodes type, MathStyles size, string const & s,
- int & asc, int & des, int & wid)
+void mathed_string_dim(MathTextCodes type, MathMetricsInfo const & size,
+ string const & s, int & asc, int & des, int & wid)
{
mathed_string_height(type, size, s, asc, des);
wid = mathed_string_width(type, size, s);
}
-int mathed_string_height(MathTextCodes type, MathStyles size, string const & s,
- int & asc, int & des)
+int mathed_string_height(MathTextCodes type, MathMetricsInfo const & size,
+ string const & s, int & asc, int & des)
{
LyXFont const font = whichFont(type, size);
asc = des = 0;
}
-int mathed_string_width(MathTextCodes type, MathStyles size, string const & s)
+int mathed_string_width(MathTextCodes type, MathMetricsInfo const & size,
+ string const & s)
{
return lyxfont::width(s, whichFont(type, size));
}
+int mathed_string_ascent(MathTextCodes type, MathMetricsInfo const & size,
+ string const & s)
+{
+ LyXFont const font = whichFont(type, size);
+ int asc = 0;
+ for (string::const_iterator it = s.begin(); it != s.end(); ++it)
+ asc = max(asc, lyxfont::ascent(*it, font));
+ return asc;
+}
+
+
+int mathed_string_descent(MathTextCodes type, MathMetricsInfo const & size,
+ string const & s)
+{
+ LyXFont const font = whichFont(type, size);
+ int des = 0;
+ for (string::const_iterator it = s.begin(); it != s.end(); ++it)
+ des = max(des, lyxfont::descent(*it, font));
+ return des;
+}
+
+
+
void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
const string & name)
{
// In the future maybe we use a better fonts renderer
-void drawStr(Painter & pain, MathTextCodes type, MathStyles siz,
+void drawStr(Painter & pain, MathTextCodes type, MathMetricsInfo const & siz,
int x, int y, string const & s)
{
pain.text(x, y, s, whichFont(type, siz));
}
-void drawChar
- (Painter & pain, MathTextCodes type, MathStyles siz, int x, int y, char c)
+void drawChar(Painter & pain, MathTextCodes type, MathMetricsInfo const & siz,
+ int x, int y, char c)
{
string s;
if (isBinaryOp(c, type))
// decrease math size for super- and subscripts
-MathStyles smallerStyleScript(MathStyles st)
+void smallerStyleScript(MathMetricsInfo & st)
{
- switch (st) {
+ switch (st.style) {
case LM_ST_DISPLAY:
- case LM_ST_TEXT: st = LM_ST_SCRIPT; break;
- default: st = LM_ST_SCRIPTSCRIPT;
+ case LM_ST_TEXT: st.style = LM_ST_SCRIPT; break;
+ default: st.style = LM_ST_SCRIPTSCRIPT;
}
- return st;
}
// decrease math size for fractions
-MathStyles smallerStyleFrac(MathStyles st)
+void smallerStyleFrac(MathMetricsInfo & st)
{
- switch (st) {
- case LM_ST_DISPLAY: st = LM_ST_TEXT; break;
- case LM_ST_TEXT: st = LM_ST_SCRIPT; break;
- default: st = LM_ST_SCRIPTSCRIPT;
+ switch (st.style) {
+ case LM_ST_DISPLAY: st.style = LM_ST_TEXT; break;
+ case LM_ST_TEXT: st.style = LM_ST_SCRIPT; break;
+ default: st.style = LM_ST_SCRIPTSCRIPT;
}
- return st;
}
-void math_font_max_dim(MathTextCodes code, MathStyles siz, int & asc, int & des)
+void math_font_max_dim(MathTextCodes code, MathMetricsInfo const & siz,
+ int & asc, int & des)
{
LyXFont font = whichFont(code, siz);
asc = lyxfont::maxAscent(font);
char const * latex_mathspace[] = {
"!", ",", ":", ";", "quad", "qquad"
};
+
+
+char const * math_font_name(MathTextCodes code)
+{
+ static char const * theFontNames[] = {
+ "mathrm",
+ "mathcal",
+ "mathbf",
+ "mathbb",
+ "mathsf",
+ "mathtt",
+ "mathit",
+ "textrm"
+ };
+
+ if (code >= LM_TC_RM && code <= LM_TC_TEXTRM)
+ return theFontNames[code - LM_TC_RM];
+ return 0;
+}