From 970f0247f7d3ebbabc1348549ef4bd8d9b335545 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 19 Oct 2001 17:46:13 +0000 Subject: [PATCH] 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 --- src/mathed/Makefile.am | 2 + src/mathed/formulabase.C | 16 +++--- src/mathed/math_arrayinset.C | 8 +-- src/mathed/math_binominset.C | 8 +-- src/mathed/math_charinset.C | 8 +-- src/mathed/math_cursor.C | 6 --- src/mathed/math_cursor.h | 2 - src/mathed/math_decorationinset.C | 2 +- src/mathed/math_defs.h | 20 -------- src/mathed/math_deliminset.C | 2 +- src/mathed/math_dotsinset.C | 2 +- src/mathed/math_fracinset.C | 2 +- src/mathed/math_funcinset.C | 4 +- src/mathed/math_funcliminset.C | 6 +-- src/mathed/math_inset.C | 18 ------- src/mathed/math_inset.h | 28 +---------- src/mathed/math_macro.C | 16 +++--- src/mathed/math_macroarg.C | 4 +- src/mathed/math_matrixinset.C | 12 ++--- src/mathed/math_metricsinfo.C | 0 src/mathed/math_metricsinfo.h | 39 +++++++++++++++ src/mathed/math_notinset.C | 8 +-- src/mathed/math_scriptinset.C | 13 +++-- src/mathed/math_sizeinset.C | 2 +- src/mathed/math_specialcharinset.C | 8 +-- src/mathed/math_stackrelinset.C | 2 +- src/mathed/math_symbolinset.C | 23 +++++---- src/mathed/support.C | 79 +++++++++++++++++------------- src/mathed/support.h | 51 ++++++++++++------- src/mathed/xarray.C | 10 ++-- src/mathed/xarray.h | 6 +-- 31 files changed, 204 insertions(+), 203 deletions(-) create mode 100644 src/mathed/math_metricsinfo.C create mode 100644 src/mathed/math_metricsinfo.h diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 8b9a43e04a..d9028062c7 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -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 \ diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index f7b9e49b33..eb67e308fc 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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); diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index 25c63eb7ce..0b06d00a59 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -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_); } diff --git a/src/mathed/math_binominset.C b/src/mathed/math_binominset.C index 1f04084c26..a9f419a492 100644 --- a/src/mathed/math_binominset.C +++ b/src/mathed/math_binominset.C @@ -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; diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 44d6884541..197f918525 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -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_); } diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 9623694133..0fe0ef1dd6 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -915,12 +915,6 @@ void MathCursor::pullArg(bool goright) } -MathStyles MathCursor::style() const -{ - return xarray().style(); -} - - void MathCursor::normalize() const { #ifdef WITH_WARNINGS diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index ce9c89cc97..615d3cb7b9 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -195,8 +195,6 @@ public: /// row_type row() const; - /// - MathStyles style() const; /// Make sure cursor position is valid void normalize() const; diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index becc4183f4..35a2515d6b 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -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_); } } diff --git a/src/mathed/math_defs.h b/src/mathed/math_defs.h index 51c6a7b28e..6b49f5db9d 100644 --- a/src/mathed/math_defs.h +++ b/src/mathed/math_defs.h @@ -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 { diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index dfa8884469..cef56a13cc 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -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; diff --git a/src/mathed/math_dotsinset.C b/src/mathed/math_dotsinset.C index 4c142c34c8..40249eeff1 100644 --- a/src/mathed/math_dotsinset.C +++ b/src/mathed/math_dotsinset.C @@ -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; diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index 057366ba7b..e25adc5c0e 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -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; diff --git a/src/mathed/math_funcinset.C b/src/mathed/math_funcinset.C index b5651b9df7..a255258670 100644 --- a/src/mathed/math_funcinset.C +++ b/src/mathed/math_funcinset.C @@ -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_); } diff --git a/src/mathed/math_funcliminset.C b/src/mathed/math_funcliminset.C index f8f03cda1c..2788b42051 100644 --- a/src/mathed/math_funcliminset.C +++ b/src/mathed/math_funcliminset.C @@ -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); } diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 0b43d32b91..114ab8a482 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -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 diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 28a56d845b..d72bcfa0a5 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -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; diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 7e17da748c..f7a327c3f2 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -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(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; diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index ab1b217957..6ed3e3e04a 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -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_); } diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index 690dc0acad..9c289572c6 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -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)); } } } diff --git a/src/mathed/math_metricsinfo.C b/src/mathed/math_metricsinfo.C new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/mathed/math_metricsinfo.h b/src/mathed/math_metricsinfo.h new file mode 100644 index 0000000000..db5a3c2caf --- /dev/null +++ b/src/mathed/math_metricsinfo.h @@ -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 diff --git a/src/mathed/math_notinset.C b/src/mathed/math_notinset.C index 9ebbb3f1bf..5e72280b84 100644 --- a/src/mathed/math_notinset.C +++ b/src/mathed/math_notinset.C @@ -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, '/'); } diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index cc9c481bdb..f362245912 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -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)); } diff --git a/src/mathed/math_sizeinset.C b/src/mathed/math_sizeinset.C index 389b233597..a7d6221c8c 100644 --- a/src/mathed/math_sizeinset.C +++ b/src/mathed/math_sizeinset.C @@ -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_; diff --git a/src/mathed/math_specialcharinset.C b/src/mathed/math_specialcharinset.C index 05c34659b7..0c9d76fec8 100644 --- a/src/mathed/math_specialcharinset.C +++ b/src/mathed/math_specialcharinset.C @@ -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_); } diff --git a/src/mathed/math_stackrelinset.C b/src/mathed/math_stackrelinset.C index 162a8bdf64..3db2779344 100644 --- a/src/mathed/math_stackrelinset.C +++ b/src/mathed/math_stackrelinset.C @@ -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; diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index dd7915780d..f9170c1b2d 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -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; } diff --git a/src/mathed/support.C b/src/mathed/support.C index 9cb0cd114e..513b8f96a1 100644 --- a/src/mathed/support.C +++ b/src/mathed/support.C @@ -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); diff --git a/src/mathed/support.h b/src/mathed/support.h index 3352ec379f..44cbb93ddd 100644 --- a/src/mathed/support.h +++ b/src/mathed/support.h @@ -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 diff --git a/src/mathed/xarray.C b/src/mathed/xarray.C index ffeee12e3a..54b83322ba 100644 --- a/src/mathed/xarray.C +++ b/src/mathed/xarray.C @@ -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"; diff --git a/src/mathed/xarray.h b/src/mathed/xarray.h index b09d6af344..b67d3b9681 100644 --- a/src/mathed/xarray.h +++ b/src/mathed/xarray.h @@ -5,7 +5,7 @@ #include #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); -- 2.39.2