// there, because otherwise more math symbols would be ready by now..
// just a thought.
-- Some math symbols aren't very well supported (to my knowledge). I'm
- thinking of underbraces with extra data in them,or [] options.
+//- Some math symbols aren't very well supported (to my knowledge). I'm
+// thinking of underbraces with extra data in them
+- Some math symbols aren't very well supported (to my knowledge). I'm
+ thinking of [] options.
Herbert Voss:
math_braceinset.h \
math_boxinset.C \
math_boxinset.h \
+ math_binaryopinset.C \
+ math_binaryopinset.h \
math_charinset.C \
math_charinset.h \
math_cursor.C \
math_sqrtinset.h \
math_stackrelinset.C \
math_stackrelinset.h \
+ math_stringinset.C \
+ math_stringinset.h \
math_symbolinset.C \
math_symbolinset.h \
support.C \
#include "math_inset.h"
#include "math_charinset.h"
#include "math_scriptinset.h"
+#include "math_stringinset.h"
#include "debug.h"
#include "array.h"
#include "mathed/support.h"
}
+MathArray MathArray::glueChars() const
+{
+ MathArray ar;
+ const_iterator it = begin();
+ while (it != end()) {
+ if (it->nucleus() && it->nucleus()->asCharInset()) {
+ string s = charSequence(it, end());
+ MathTextCodes c = it->nucleus()->asCharInset()->code();
+ ar.push_back(MathAtom(new MathStringInset(s, c)));
+ it += s.size();
+ } else {
+ ar.push_back(*it);
+ ++it;
+ }
+ }
+ return ar;
+}
+
+
void MathArray::write(MathWriteInfo & wi) const
+{
+ glueChars().write1(wi);
+}
+
+
+void MathArray::write1(MathWriteInfo & wi) const
{
for (const_iterator it = begin(); it != end(); ++it) {
MathInset * p = it->nucleus();
if (!p)
continue;
-
-/*
- if (p->asCharInset()) {
- MathCharInset const * c = p->asCharInset();
- // special handling for character sequences with the same code
- string s = charSequence(it, end());
- c->writeHeader(os);
- os << s;
- c->writeTrailer(os);
- it += s.size() - 1;
- } else
-*/
if (MathScriptInset const * q = asScript(it)) {
q->write(p, wi);
++it;
MathAtom & at(size_type pos);
///
MathAtom const & at(size_type pos) const;
- ///
+ /// glue chars if necessary
void write(MathWriteInfo & os) const;
+ /// raw write
+ void write1(MathWriteInfo & os) const;
///
void writeNormal(std::ostream &) const;
///
iterator end();
///
MathScriptInset const * asScript(const_iterator it) const;
+ /// glues chars with the same attributes into MathStringInsets
+ MathArray glueChars() const;
private:
/// Buffer
buffer_type bf_;
--- /dev/null
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_binaryopinset.h"
+#include "Painter.h"
+#include "support/LOstream.h"
+#include "support.h"
+
+
+MathBinaryOpInset::MathBinaryOpInset(char op)
+ : MathNestInset(2), op_(op)
+{}
+
+
+MathInset * MathBinaryOpInset::clone() const
+{
+ return new MathBinaryOpInset(*this);
+}
+
+
+int MathBinaryOpInset::opwidth() const
+{
+ return mathed_char_width(LM_TC_CONST, mi_, op_);
+}
+
+
+void MathBinaryOpInset::metrics(MathMetricsInfo const & mi) const
+{
+ mi_ = mi;
+ xcell(0).metrics(mi);
+ xcell(1).metrics(mi);
+ width_ = xcell(0).width() + xcell(1).width() + opwidth();
+ ascent_ = std::max(xcell(0).ascent(), xcell(1).ascent());
+ descent_ = std::max(xcell(0).descent(), xcell(1).descent());
+}
+
+
+void MathBinaryOpInset::draw(Painter & pain, int x, int y) const
+{
+ xcell(0).draw(pain, x, y);
+ drawChar(pain, LM_TC_CONST, mi_, x + xcell(0).width() , y, op_);
+ xcell(1).draw(pain, x + width() - xcell(1).width(), y);
+}
+
+
+void MathBinaryOpInset::write(MathWriteInfo & os) const
+{
+ os << '{' << cell(0) << op_ << cell(1) << '}';
+}
+
+
+void MathBinaryOpInset::writeNormal(std::ostream & os) const
+{
+ os << "[binop " << op_ << ' ';
+ cell(0).writeNormal(os);
+ os << " ";
+ cell(1).writeNormal(os);
+ os << "]";
+}
--- /dev/null
+// -*- C++ -*-
+#ifndef MATH_BINARYOPINSET_H
+#define MATH_BINARYOPINSET_H
+
+#include "math_nestinset.h"
+#include "math_nestinset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+/** An inset for multiplication
+ \author André Pönitz
+ */
+class MathBinaryOpInset : public MathNestInset {
+public:
+ ///
+ explicit MathBinaryOpInset(char op);
+ ///
+ MathInset * clone() const;
+ ///
+ void draw(Painter &, int x, int y) const;
+ ///
+ void write(MathWriteInfo & os) const;
+ ///
+ void writeNormal(std::ostream &) const;
+ ///
+ void metrics(MathMetricsInfo const & st) const;
+private:
+ ///
+ int opwidth() const;
+ ///
+ char op_;
+ ///
+ mutable MathMetricsInfo mi_;
+};
+#endif
#include "debug.h"
-namespace {
-
-char const * math_font_name[] = {
- "mathrm",
- "mathcal",
- "mathbf",
- "mathbb",
- "mathsf",
- "mathtt",
- "mathit",
- "textrm"
-};
-
-}
-
-
MathCharInset::MathCharInset(char c)
: char_(c), code_(nativeCode(c))
{
void MathCharInset::writeHeader(std::ostream & os) const
{
- if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
- os << '\\' << math_font_name[code_ - LM_TC_RM] << '{';
+ if (math_font_name(code_))
+ os << '\\' << math_font_name(code_) << '{';
}
void MathCharInset::writeTrailer(std::ostream & os) const
{
- if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
+ if (math_font_name(code_))
os << '}';
}
bool MathMatrixInset::ams() const
{
return true;
+
+ return
+ objtype_ == LM_OT_ALIGN ||
+ objtype_ == LM_OT_MULTLINE ||
+ objtype_ == LM_OT_GATHER ||
+ objtype_ == LM_OT_ALIGNAT ||
+ objtype_ == LM_OT_XALIGNAT ||
+ objtype_ == LM_OT_XXALIGNAT;
}
--- /dev/null
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include <cctype>
+
+#include "math_stringinset.h"
+#include "LColor.h"
+#include "Painter.h"
+#include "support/LOstream.h"
+#include "support.h"
+#include "math_parser.h"
+#include "debug.h"
+
+
+MathStringInset::MathStringInset(string const & s, MathTextCodes t)
+ : str_(s), code_(t)
+{}
+
+
+MathInset * MathStringInset::clone() const
+{
+ return new MathStringInset(*this);
+}
+
+
+int MathStringInset::ascent() const
+{
+ return mathed_string_ascent(code_, mi_, str_);
+}
+
+
+int MathStringInset::descent() const
+{
+ return mathed_string_descent(code_, mi_, str_);
+}
+
+
+int MathStringInset::width() const
+{
+ return mathed_string_width(code_, mi_, str_);
+}
+
+
+void MathStringInset::metrics(MathMetricsInfo const & mi) const
+{
+ mi_ = mi;
+}
+
+
+void MathStringInset::draw(Painter & pain, int x, int y) const
+{
+ //lyxerr << "drawing '" << str_ << "' code: " << code_ << endl;
+ drawStr(pain, code_, mi_, x, y, str_);
+}
+
+
+void MathStringInset::write(MathWriteInfo & os) const
+{
+ if (math_font_name(code_))
+ os << '\\' << math_font_name(code_) << '{' << str_ << '}';
+ else
+ os << str_;
+}
+
+
+void MathStringInset::writeNormal(std::ostream & os) const
+{
+ os << "[string " << str_ << " " << "mathalpha" << "]";
+}
--- /dev/null
+// -*- C++ -*-
+#ifndef MATH_STRINGINSET_H
+#define MATH_STRINGINSET_H
+
+#include "math_inset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+/** Some cllection of chars with similar properties
+ \author André Pönitz
+ */
+
+class MathStringInset : public MathInset {
+public:
+ ///
+ MathStringInset(string const & s, MathTextCodes t);
+ ///
+ MathInset * clone() const;
+ ///
+ void metrics(MathMetricsInfo const & st) const;
+ ///
+ void draw(Painter &, int x, int y) const;
+ ///
+ void write(MathWriteInfo & os) const;
+ ///
+ void writeNormal(std::ostream &) const;
+ ///
+ int ascent() const;
+ ///
+ int descent() const;
+ ///
+ int width() const;
+ ///
+ string & str();
+
+private:
+ /// the string
+ string str_;
+ /// the font to be used on screen
+ MathTextCodes code_;
+ ///
+ mutable MathMetricsInfo mi_;
+};
+#endif
}
+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)
{
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;
+}
// decrease math size for fractions
void smallerStyleFrac(MathMetricsInfo & st);
+char const * math_font_name(MathTextCodes type);
#endif