halfway through fixing size of math in non-standard sizesd paragraohs like

section headings...


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2907 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-10-19 17:46:13 +00:00
parent 3d8efcecf9
commit 970f0247f7
31 changed files with 204 additions and 203 deletions

View File

@ -68,6 +68,8 @@ libmathed_la_SOURCES = \
math_macrotable.h \
math_matrixinset.C \
math_matrixinset.h \
math_metricsinfo.h \
math_metricsinfo.C \
math_nestinset.C \
math_nestinset.h \
math_notinset.C \

View File

@ -123,6 +123,8 @@ void InsetFormulaBase::metrics(BufferView * bv, LyXFont const * f) const
view_ = bv;
if (f)
font_ = f;
if (f)
lyxerr << "fontsize: " << f->size() << "\n";
MathMetricsInfo mi(view_, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
par()->metrics(mi);
}
@ -194,9 +196,10 @@ void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
//x -= par()->xo();
y -= par()->yo();
y -= 3;
int asc;
int des;
math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, des);
int asc = 0;
int des = 0;
MathMetricsInfo mi(bv, font_, LM_ST_TEXT);
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
bv->showLockedInsetCursor(x, y, asc, des);
}
@ -213,9 +216,10 @@ void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
mathcursor->getPos(x, y);
x -= par()->xo();
y -= par()->yo();
int asc;
int des;
math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, des);
int asc = 0;
int des = 0;
MathMetricsInfo mi(bv, font_, LM_ST_TEXT);
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
bv->fitLockedInsetCursor(x, y, asc, des);
}
toggleInsetCursor(bv);

View File

@ -46,9 +46,9 @@ void MathArrayInset::write(MathWriteInfo & os) const
void MathArrayInset::metrics(MathMetricsInfo const & st) const
{
MathMetricsInfo m = st;
if (m.size == LM_ST_DISPLAY)
m.size = LM_ST_TEXT;
MathGridInset::metrics(m);
size_ = st;
if (size_.style == LM_ST_DISPLAY)
size_.style = LM_ST_TEXT;
MathGridInset::metrics(size_);
}

View File

@ -30,10 +30,10 @@ int MathBinomInset::dw() const
void MathBinomInset::metrics(MathMetricsInfo const & st) const
{
MathMetricsInfo m = st;
m.size = smallerStyleFrac(m.size);
xcell(0).metrics(m);
xcell(1).metrics(m);
size_ = st;
smallerStyleFrac(size_);
xcell(0).metrics(size_);
xcell(1).metrics(size_);
ascent_ = xcell(0).height() + 4 + 5;
descent_ = xcell(1).height() + 4 - 5;
width_ = std::max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4;

View File

@ -60,19 +60,19 @@ MathInset * MathCharInset::clone() const
int MathCharInset::ascent() const
{
return mathed_char_ascent(code_, size(), char_);
return mathed_char_ascent(code_, size_, char_);
}
int MathCharInset::descent() const
{
return mathed_char_descent(code_, size(), char_);
return mathed_char_descent(code_, size_, char_);
}
int MathCharInset::width() const
{
return mathed_char_width(code_, size(), char_);
return mathed_char_width(code_, size_, char_);
}
@ -87,7 +87,7 @@ void MathCharInset::draw(Painter & pain, int x, int y) const
xo(x);
yo(y);
//lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
drawChar(pain, code_, size_.size, x, y, char_);
drawChar(pain, code_, size_, x, y, char_);
}

View File

@ -915,12 +915,6 @@ void MathCursor::pullArg(bool goright)
}
MathStyles MathCursor::style() const
{
return xarray().style();
}
void MathCursor::normalize() const
{
#ifdef WITH_WARNINGS

View File

@ -195,8 +195,6 @@ public:
///
row_type row() const;
///
MathStyles style() const;
/// Make sure cursor position is valid
void normalize() const;

View File

@ -90,7 +90,7 @@ void MathDecorationInset::draw(Painter & pain, int x, int y) const
if (wide())
mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
else {
int w = 2 + mathed_char_width(LM_TC_VAR, size(), 'x');
int w = 2 + mathed_char_width(LM_TC_VAR, size_, 'x');
mathed_draw_deco(pain, x + (width_ - w) / 2, y + dy_, w, dh_, name_);
}
}

View File

@ -25,26 +25,6 @@
#endif
/// Standard Math Sizes (Math mode styles)
enum MathStyles {
///
LM_ST_DISPLAY = 0,
///
LM_ST_TEXT,
///
LM_ST_SCRIPT,
///
LM_ST_SCRIPTSCRIPT
};
// decrease math size for super- and subscripts
MathStyles smallerStyleScript(MathStyles);
// decrease math size for fractions
MathStyles smallerStyleFrac(MathStyles st);
/** The restrictions of a standard LaTeX math paragraph
allows to get a small number of text codes (<30) */
enum MathTextCodes {

View File

@ -65,7 +65,7 @@ void MathDelimInset::metrics(MathMetricsInfo const & st) const
xcell(0).metrics(st);
size_ = st;
int a, d, w;
mathed_char_dim(LM_TC_VAR, size_.size,'I', a, d, w);
mathed_char_dim(LM_TC_VAR, size_, 'I', a, d, w);
int h0 = (a + d) / 2;
int a0 = std::max(xcell(0).ascent(), a) - h0;
int d0 = std::max(xcell(0).descent(), d) + h0;

View File

@ -35,7 +35,7 @@ void MathDotsInset::draw(Painter & pain, int x, int y) const
void MathDotsInset::metrics(MathMetricsInfo const & st) const
{
size_ = st;
mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_);
mathed_char_dim(LM_TC_VAR, size_, 'M', ascent_, descent_, width_);
switch (name_[0]) {
case 'l': dh_ = 0; break;
case 'c': dh_ = ascent_ / 2; break;

View File

@ -22,7 +22,7 @@ MathInset * MathFracInset::clone() const
void MathFracInset::metrics(MathMetricsInfo const & st) const
{
size_ = st;
size_.size = smallerStyleFrac(size_.size);
smallerStyleFrac(size_);
xcell(0).metrics(size_);
xcell(1).metrics(size_);
width_ = std::max(xcell(0).width(), xcell(1).width()) + 4;

View File

@ -52,7 +52,7 @@ void MathFuncInset::writeNormal(std::ostream & os) const
void MathFuncInset::metrics(MathMetricsInfo const & st) const
{
size_ = st;
mathed_string_dim(LM_TC_TEX, size_.size, name_, ascent_, descent_, width_);
mathed_string_dim(LM_TC_TEX, size_, name_, ascent_, descent_, width_);
}
@ -60,5 +60,5 @@ void MathFuncInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
drawStr(pain, LM_TC_TEX, size_.size, x, y, name_);
drawStr(pain, LM_TC_TEX, size_, x, y, name_);
}

View File

@ -19,7 +19,7 @@ MathInset * MathFuncLimInset::clone() const
bool MathFuncLimInset::isScriptable() const
{
return size_.size == LM_ST_DISPLAY;
return size_.style == LM_ST_DISPLAY;
}
@ -38,7 +38,7 @@ void MathFuncLimInset::writeNormal(ostream & os) const
void MathFuncLimInset::metrics(MathMetricsInfo const & st) const
{
size_ = st;
mathed_string_dim(LM_TC_TEXTRM, size_.size, sym_->name,
mathed_string_dim(LM_TC_TEXTRM, size_, sym_->name,
ascent_, descent_, width_);
}
@ -47,5 +47,5 @@ void MathFuncLimInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
drawStr(pain, LM_TC_TEXTRM, size_.size, x, y, sym_->name);
drawStr(pain, LM_TC_TEXTRM, size_, x, y, sym_->name);
}

View File

@ -42,12 +42,6 @@ int MathInset::height() const
}
MathStyles MathInset::size() const
{
return size_.size;
}
std::ostream & operator<<(std::ostream & os, MathInset const & inset)
{
MathWriteInfo wi(0, os, false);
@ -226,18 +220,6 @@ void MathInset::dump() const
}
void MathInset::push_back(unsigned char, MathTextCodes)
{
lyxerr << "can't push without a cell\n";
}
void MathInset::push_back(MathInset *)
{
lyxerr << "can't push without a cell\n";
}
bool MathInset::covers(int x, int y) const
{
//lyxerr << "cover? p: " << this << " x: " << x << " y: " << y

View File

@ -29,6 +29,7 @@
#endif
#include "xarray.h"
#include "math_defs.h"
/** Abstract base class for all math objects.
A math insets is for use of the math editor only, it isn't a
@ -49,27 +50,6 @@ class MathMacroTemplate;
class LaTeXFeatures;
class Buffer;
class BufferView;
class LyXFont;
struct MathMetricsInfo {
///
MathMetricsInfo()
: view(0), font(0), size(LM_ST_TEXT)
{}
///
MathMetricsInfo(BufferView * v, LyXFont const * f, MathStyles s)
: view(v), font(f), size(s)
{}
///
BufferView * view;
///
LyXFont const * font;
///
MathStyles size;
};
struct MathWriteInfo {
@ -144,8 +124,6 @@ public:
virtual int width() const { return 2; }
///
virtual int height() const;
///
virtual MathStyles size() const;
/// Where should we go when we press the up cursor key?
virtual bool idxUp(idx_type & idx, pos_type & pos) const;
@ -271,10 +249,6 @@ public:
/// identifies things that can get \limits or \nolimits
virtual bool takesLimits() const { return false; }
///
virtual void push_back(MathInset *);
///
virtual void push_back(unsigned char c, MathTextCodes code);
///
virtual void dump() const;

View File

@ -73,7 +73,7 @@ void MathMacro::metrics(MathMetricsInfo const & st) const
{
if (defining()) {
size_ = st;
mathed_string_dim(LM_TC_TEX, size_.size, name(), ascent_, descent_, width_);
mathed_string_dim(LM_TC_TEX, size_, name(), ascent_, descent_, width_);
return;
}
@ -85,12 +85,12 @@ void MathMacro::metrics(MathMetricsInfo const & st) const
ascent_ = expanded_.ascent() + 2;
descent_ = expanded_.descent() + 2;
width_ += mathed_string_width(LM_TC_TEXTRM, size_.size, name()) + 10;
width_ += mathed_string_width(LM_TC_TEXTRM, size_, name()) + 10;
int lasc;
int ldes;
int lwid;
mathed_string_dim(LM_TC_TEXTRM, size_.size, "#1: ", lasc, ldes, lwid);
mathed_string_dim(LM_TC_TEXTRM, size_, "#1: ", lasc, ldes, lwid);
for (idx_type i = 0; i < nargs(); ++i) {
MathXArray const & c = xcell(i);
@ -120,22 +120,22 @@ void MathMacro::draw(Painter & pain, int x, int y) const
metrics(size_);
if (defining()) {
drawStr(pain, LM_TC_TEX, size_.size, x, y, name());
drawStr(pain, LM_TC_TEX, size_, x, y, name());
return;
}
if (editing()) {
int h = y - ascent() + 2 + expanded_.ascent();
drawStr(pain, LM_TC_TEXTRM, size_.size, x + 3, h, name());
drawStr(pain, LM_TC_TEXTRM, size_, x + 3, h, name());
int const w = mathed_string_width(LM_TC_TEXTRM, size_.size, name());
int const w = mathed_string_width(LM_TC_TEXTRM, size_, name());
expanded_.draw(pain, x + w + 12, h);
h += expanded_.descent();
int lasc;
int ldes;
int lwid;
mathed_string_dim(LM_TC_TEXTRM, size_.size, "#1: ", lasc, ldes, lwid);
mathed_string_dim(LM_TC_TEXTRM, size_, "#1: ", lasc, ldes, lwid);
for (idx_type i = 0; i < nargs(); ++i) {
MathXArray const & c = xcell(i);
@ -143,7 +143,7 @@ void MathMacro::draw(Painter & pain, int x, int y) const
c.draw(pain, x + lwid, h);
char str[] = "#1:";
str[1] += static_cast<char>(i);
drawStr(pain, LM_TC_TEX, size_.size, x + 3, h, str);
drawStr(pain, LM_TC_TEX, size_, x + 3, h, str);
h += std::max(c.descent(), ldes) + 5;
}
return;

View File

@ -43,7 +43,7 @@ void MathMacroArgument::metrics(MathMetricsInfo const & st) const
ascent_ = xcell(0).ascent();
descent_ = xcell(0).descent();
} else
mathed_string_dim(LM_TC_TEX, size_.size, str_, ascent_, descent_, width_);
mathed_string_dim(LM_TC_TEX, size_, str_, ascent_, descent_, width_);
}
@ -52,7 +52,7 @@ void MathMacroArgument::draw(Painter & pain, int x, int y) const
if (expanded_)
xcell(0).draw(pain, x, y);
else
drawStr(pain, LM_TC_TEX, size_.size, x, y, str_);
drawStr(pain, LM_TC_TEX, size_, x, y, str_);
}

View File

@ -143,7 +143,7 @@ int MathMatrixInset::defaultColSpace(col_type col)
void MathMatrixInset::metrics(MathMetricsInfo const & st) const
{
size_ = st;
size_.size = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
size_.style = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
// let the cells adjust themselves
MathGridInset::metrics(size_);
@ -156,7 +156,7 @@ void MathMatrixInset::metrics(MathMetricsInfo const & st) const
if (numberedType()) {
int l = 0;
for (row_type row = 0; row < nrows(); ++row)
l = std::max(l, mathed_string_width(LM_TC_BF, size(), nicelabel(row)));
l = std::max(l, mathed_string_width(LM_TC_BF, size_, nicelabel(row)));
if (l)
width_ += 30 + l;
@ -165,7 +165,7 @@ void MathMatrixInset::metrics(MathMetricsInfo const & st) const
// make it at least as high as the current font
int asc = 0;
int des = 0;
math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, des);
math_font_max_dim(LM_TC_TEXTRM, size_, asc, des);
ascent_ = std::max(ascent_, asc);
descent_ = std::max(descent_, des);
}
@ -179,10 +179,10 @@ void MathMatrixInset::draw(Painter & pain, int x, int y) const
MathGridInset::draw(pain, x, y);
if (numberedType()) {
int xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
for (row_type row = 0; row < nrows(); ++row) {
int yy = y + rowinfo_[row].offset_;
drawStr(pain, LM_TC_BF, size(), xx, yy, nicelabel(row));
int const yy = y + rowinfo_[row].offset_;
drawStr(pain, LM_TC_BF, size_, xx, yy, nicelabel(row));
}
}
}

View File

View File

@ -0,0 +1,39 @@
#ifndef MATH_METRICSINFO
#define MATH_METRICSINFO
class BufferView;
class LyXFont;
/// Standard Math Sizes (Math mode styles)
enum MathStyles {
///
LM_ST_DISPLAY = 0,
///
LM_ST_TEXT,
///
LM_ST_SCRIPT,
///
LM_ST_SCRIPTSCRIPT
};
struct MathMetricsInfo {
///
MathMetricsInfo()
: view(0), font(0), style(LM_ST_TEXT)
{}
///
MathMetricsInfo(BufferView * v, LyXFont const * f, MathStyles s)
: view(v), font(f), style(s)
{}
///
BufferView * view;
///
LyXFont const * font;
///
MathStyles style;
};
#endif

View File

@ -32,9 +32,9 @@ void MathNotInset::metrics(MathMetricsInfo const & st) const
{
size_ = st;
if (math_font_available(LM_TC_CMSY))
mathed_char_dim(LM_TC_CMSY, size(), 54, ascent_, descent_, width_);
mathed_char_dim(LM_TC_CMSY, size_, 54, ascent_, descent_, width_);
else
mathed_char_dim(LM_TC_VAR, size(), '/', ascent_, descent_, width_);
mathed_char_dim(LM_TC_VAR, size_, '/', ascent_, descent_, width_);
width_ = 0;
}
@ -45,7 +45,7 @@ void MathNotInset::draw(Painter & pain, int x, int y) const
yo(y);
if (math_font_available(LM_TC_CMSY))
drawChar(pain, LM_TC_CMSY, size(), x, y, 54);
drawChar(pain, LM_TC_CMSY, size_, x, y, 54);
else
drawChar(pain, LM_TC_VAR, size(), x, y, '/');
drawChar(pain, LM_TC_VAR, size_, x, y, '/');
}

View File

@ -100,7 +100,7 @@ int MathScriptInset::dy1(MathInset const * nuc) const
asc += na + 2;
else
asc = std::max(asc, na);
asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, LM_ST_TEXT, 'I'));
asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, size_, 'I'));
return asc;
}
@ -162,21 +162,21 @@ int MathScriptInset::nwid(MathInset const * nuc) const
{
return nuc ?
nuc->width() :
mathed_char_width(LM_TC_TEX, LM_ST_TEXT, '.');
mathed_char_width(LM_TC_TEX, size_, '.');
}
int MathScriptInset::nasc(MathInset const * nuc) const
{
return nuc ? nuc->ascent()
: mathed_char_ascent(LM_TC_VAR, LM_ST_TEXT, 'I');
: mathed_char_ascent(LM_TC_VAR, size_, 'I');
}
int MathScriptInset::ndes(MathInset const * nuc) const
{
return nuc ? nuc->descent()
: mathed_char_descent(LM_TC_VAR, LM_ST_TEXT, 'I');
: mathed_char_descent(LM_TC_VAR, size_, 'I');
}
@ -211,12 +211,15 @@ void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
{
xo(x);
yo(y);
if (nuc)
nuc->draw(pain, x + dxx(nuc), y);
else
drawStr(pain, LM_TC_TEX, LM_ST_TEXT, x + dxx(nuc), y, ".");
drawStr(pain, LM_TC_TEX, size_, x + dxx(nuc), y, ".");
if (hasUp())
up().draw(pain, x + dx1(nuc), y - dy1(nuc));
if (hasDown())
down().draw(pain, x + dx0(nuc), y + dy0(nuc));
}

View File

@ -29,7 +29,7 @@ void MathSizeInset::draw(Painter & pain, int x, int y) const
void MathSizeInset::metrics(MathMetricsInfo const & st) const
{
size_ = st;
size_.size = MathStyles(key_->id);
size_.style = MathStyles(key_->id);
xcell(0).metrics(size_);
ascent_ = xcell(0).ascent_;
descent_ = xcell(0).descent_;

View File

@ -20,19 +20,19 @@ MathInset * MathSpecialCharInset::clone() const
int MathSpecialCharInset::ascent() const
{
return mathed_char_ascent(LM_TC_CONST, size(), char_);
return mathed_char_ascent(LM_TC_CONST, size_, char_);
}
int MathSpecialCharInset::descent() const
{
return mathed_char_descent(LM_TC_CONST, size(), char_);
return mathed_char_descent(LM_TC_CONST, size_, char_);
}
int MathSpecialCharInset::width() const
{
return mathed_char_width(LM_TC_CONST, size(), char_);
return mathed_char_width(LM_TC_CONST, size_, char_);
}
@ -46,7 +46,7 @@ void MathSpecialCharInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
drawChar(pain, LM_TC_CONST, size(), x, y, char_);
drawChar(pain, LM_TC_CONST, size_, x, y, char_);
}

View File

@ -20,7 +20,7 @@ MathInset * MathStackrelInset::clone() const
void MathStackrelInset::metrics(MathMetricsInfo const & st) const
{
size_ = st;
size_.size = smallerStyleFrac(size_.size);
smallerStyleFrac(size_);
xcell(0).metrics(size_);
xcell(1).metrics(st);
width_ = std::max(xcell(0).width(), xcell(1).width()) + 4;

View File

@ -61,12 +61,11 @@ MathTextCodes MathSymbolInset::code2() const
void MathSymbolInset::metrics(MathMetricsInfo const & st) const
{
size_ = st;
MathTextCodes Code = code();
if (sym_->latex_font_id > 0 && math_font_available(Code)) {
mathed_char_dim(Code, size(), sym_->latex_font_id,
ascent_, descent_, width_);
if (Code == LM_TC_CMEX) {
h_ = 4*descent_/5;
MathTextCodes c = code();
if (sym_->latex_font_id > 0 && math_font_available(c)) {
mathed_char_dim(c, size_, sym_->latex_font_id, ascent_, descent_, width_);
if (c == LM_TC_CMEX) {
h_ = 4 * descent_ / 5;
ascent_ += h_;
descent_ -= h_;
}
@ -74,9 +73,9 @@ void MathSymbolInset::metrics(MathMetricsInfo const & st) const
}
if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
mathed_char_dim(code2(), size(), sym_->id, ascent_, descent_, width_);
mathed_char_dim(code2(), size_, sym_->id, ascent_, descent_, width_);
else
mathed_string_dim(LM_TC_TEX, size(), sym_->name, ascent_, descent_, width_);
mathed_string_dim(LM_TC_TEX, size_, sym_->name, ascent_, descent_, width_);
}
@ -86,11 +85,11 @@ void MathSymbolInset::draw(Painter & pain, int x, int y) const
yo(y);
MathTextCodes Code = code();
if (sym_->latex_font_id > 0 && math_font_available(Code))
drawChar(pain, Code, size(), x, y - h_, sym_->latex_font_id);
drawChar(pain, Code, size_, x, y - h_, sym_->latex_font_id);
else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
drawChar(pain, code2(), size(), x, y, sym_->id);
drawChar(pain, code2(), size_, x, y, sym_->id);
else
drawStr(pain, LM_TC_TEX, size(), x, y, sym_->name);
drawStr(pain, LM_TC_TEX, size_, x, y, sym_->name);
}
@ -102,7 +101,7 @@ bool MathSymbolInset::isRelOp() const
bool MathSymbolInset::isScriptable() const
{
return size() == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
return size_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
}

View File

@ -7,6 +7,7 @@
#include "FontLoader.h"
#include "font.h"
#include "math_defs.h"
#include "math_inset.h"
#include "math_parser.h"
#include "Painter.h"
#include "debug.h"
@ -188,11 +189,20 @@ LyXFont const & whichFontBase(MathTextCodes type)
}
LyXFont whichFont(MathTextCodes type, MathStyles size)
LyXFont whichFont(MathTextCodes type, MathMetricsInfo const & size)
{
LyXFont f = whichFontBase(type);
if (size.font) {
#ifdef WITH_WARNINGS
#warning Want to fix formula sizes in headings? Look here!
#endif
// unfortunatly, size.font is sometimes nonzero and size.font->size()
// is huge...
//lyxerr << "setting font size to " << size.font->size() << "\n";
//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();
@ -215,7 +225,7 @@ LyXFont whichFont(MathTextCodes type, MathStyles size)
break;
default:
lyxerr << "Math Error: wrong font size: " << size << endl;
lyxerr << "Math Error: wrong font size: " << size.style << endl;
break;
}
@ -235,8 +245,7 @@ bool math_font_available(MathTextCodes type)
{
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];
}
@ -505,8 +514,8 @@ deco_struct const * search_deco(string const & name)
} // 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);
@ -515,8 +524,8 @@ void mathed_char_dim(MathTextCodes type, MathStyles size, unsigned char c,
}
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);
@ -525,7 +534,8 @@ int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c,
}
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;
@ -533,21 +543,24 @@ int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c)
}
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))
@ -557,16 +570,16 @@ int mathed_char_width(MathTextCodes type, MathStyles size, unsigned char c)
}
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;
@ -578,7 +591,8 @@ int mathed_string_height(MathTextCodes type, MathStyles size, string const & s,
}
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));
}
@ -653,15 +667,15 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
// 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))
@ -674,30 +688,29 @@ void drawChar
// 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);

View File

@ -8,37 +8,52 @@
class Painter;
class latexkeys;
class MathMetricsInfo;
extern char const * latex_mathspace[];
int mathed_char_height(MathTextCodes type, MathStyles size, unsigned char c,
int & asc, int & des);
void mathed_char_dim(MathTextCodes type, MathStyles size, unsigned char c,
int & asc, int & des, int & wid);
int mathed_char_width(MathTextCodes type, MathStyles size, unsigned char c);
int mathed_char_ascent(MathTextCodes type, MathStyles size, unsigned char c);
int mathed_char_descent(MathTextCodes type, MathStyles size, unsigned char c);
int mathed_char_height(MathTextCodes type, MathMetricsInfo const & size,
unsigned char c, int & asc, int & des);
void mathed_char_dim(MathTextCodes type, MathMetricsInfo const & size,
unsigned char c, int & asc, int & des, int & wid);
int mathed_char_width(MathTextCodes type, MathMetricsInfo const & size,
unsigned char c);
int mathed_char_ascent(MathTextCodes type, MathMetricsInfo const & size,
unsigned char c);
int mathed_char_descent(MathTextCodes type, MathMetricsInfo const & size,
unsigned char c);
void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
string const & name);
void mathed_string_dim(MathTextCodes type, MathStyles size, string const & s,
int & asc, int & des, int & wid);
int mathed_string_height(MathTextCodes type, MathStyles size, string const & s,
int & asc, int & des);
void mathed_string_dim(MathTextCodes type, MathMetricsInfo const & size,
string const & s, int & asc, int & des, int & wid);
int mathed_string_height(MathTextCodes type, MathMetricsInfo const & size,
string const & s, int & asc, int & des);
int mathed_string_width(MathTextCodes type, MathStyles size, string const & s);
int mathed_string_ascent(MathTextCodes type, MathStyles size, string const & s);
int mathed_string_descent(MathTextCodes type, MathStyles size, string const & s);
int mathed_string_width(MathTextCodes type, MathMetricsInfo const & size,
string const & s);
int mathed_string_ascent(MathTextCodes type, MathMetricsInfo const & size,
string const & s);
int mathed_string_descent(MathTextCodes type, MathMetricsInfo const & size,
string const & s);
void drawStr(Painter & pain, MathTextCodes type, MathStyles siz,
void drawStr(Painter & pain, MathTextCodes type, MathMetricsInfo const & siz,
int x, int y, string const & s);
void drawChar(Painter & pain, MathTextCodes type, MathStyles siz,
void drawChar(Painter & pain, MathTextCodes type, MathMetricsInfo const & siz,
int x, int y, char c);
void math_font_max_dim
(MathTextCodes code, MathStyles siz, int & asc, int & desc);
void math_font_max_dim(MathTextCodes code, MathMetricsInfo const & siz,
int & asc, int & desc);
bool math_font_available(MathTextCodes code);
// decrease math size for super- and subscripts
void smallerStyleScript(MathMetricsInfo &);
// decrease math size for fractions
void smallerStyleFrac(MathMetricsInfo & st);
#endif

View File

@ -14,20 +14,20 @@
MathXArray::MathXArray()
: width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), style_(LM_ST_TEXT)
: width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_()
{}
void MathXArray::metrics(MathMetricsInfo const & st) const
{
style_ = st.size;
mathed_char_dim(LM_TC_VAR, style_, 'I', ascent_, descent_, width_);
size_ = st;
mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_);
if (data_.empty())
return;
math_font_max_dim(LM_TC_TEXTRM, style_, ascent_, descent_);
width_ = 0;
math_font_max_dim(LM_TC_TEXTRM, st, ascent_, descent_);
width_ = 0;
//lyxerr << "MathXArray::metrics(): '" << data_ << "'\n";

View File

@ -5,7 +5,7 @@
#include <iosfwd>
#include "array.h"
#include "math_defs.h"
#include "math_metricsinfo.h"
#ifdef __GNUG__
#pragma interface
@ -45,8 +45,6 @@ public:
int height() const { return ascent_ + descent_; }
///
int width() const { return width_; }
///
MathStyles style() const { return style_; }
///
const_iterator begin() const { return data_.begin(); }
@ -67,7 +65,7 @@ public:
///
mutable int yo_;
///
mutable MathStyles style_;
mutable MathMetricsInfo size_;
};
std::ostream & operator<<(std::ostream & os, MathXArray const & ar);