return o << int(mmf);
}
-extern GC mathGC, mathFrameGC, latexGC;
extern int mathed_string_width(short type, int style, byte const* s, int ls);
extern int mathed_string_height(short, int, byte const*, int, int&, int&);
/* int k = tmplate->getMacroPar(i)->GetColumns();
if (k>0) {
args[i].array = new LyxArrayBase;
- for (int j= 0; j<k-1; j++) args[i].array->Insert(j, LM_TC_TAB);
+ for (int j= 0; j<k-1; ++j) args[i].array->Insert(j, LM_TC_TAB);
}*/
}
idx = 0;
}
-void MathMacro::Draw(int x, int y)
+void MathMacro::draw(Painter & pain, int x, int y)
{
xo = x; yo = y;
Metrics();
tmplate->update(this);
tmplate->SetStyle(size);
- mathGC = latexGC;
- tmplate->Draw(x, y);
+ tmplate->draw(pain, x, y);
for (int i = 0; i < nargs; ++i)
tmplate->GetMacroXY(i, args[i].x, args[i].y);
}
void MathMacro::Write(ostream & os)
{
+#ifdef USE_OSTREAM_ONLY
+ if (tmplate->flags & MMF_Exp) {
+ lyxerr[Debug::MATHED] << "Expand " << tmplate->flags
+ << ' ' << MMF_Exp << endl;
+ tmplate->update(this);
+ tmplate->Write(os);
+ } else {
+ if (tmplate->flags & MMF_Env) {
+ os << "\\begin{"
+ << name
+ << "} ";
+ } else {
+ os << '\\' << name;
+ }
+// if (options) {
+// file += '[';
+// file += options;
+// file += ']';
+// }
+
+ if (!(tmplate->flags & MMF_Env) && nargs > 0)
+ os << '{';
+
+ for (int i = 0; i < nargs; ++i) {
+ array = args[i].array;
+ MathParInset::Write(os);
+ if (i < nargs - 1)
+ os << "}{";
+ }
+ if (tmplate->flags & MMF_Env) {
+ os << "\\end{"
+ << name
+ << '}';
+ } else {
+ if (nargs > 0)
+ os << '}';
+ else
+ os << ' ';
+ }
+ }
+#else
string output;
MathMacro::Write(output);
os << output;
+#endif
}
+#ifndef USE_OSTREAM_ONLY
void MathMacro::Write(string &file)
{
if (tmplate->flags & MMF_Exp) {
}
}
}
-
+#endif
/*--------------- Macro argument -----------------------------------*/
}
-void MathMacroArgument::Draw(int x, int baseline)
+void MathMacroArgument::draw(Painter & pain, int x, int baseline)
{
if (expnd_mode) {
- MathParInset::Draw(x, baseline);
+ MathParInset::draw(pain, x, baseline);
} else {
unsigned char s[3];
- sprintf((char*)s, "#%d", number);
- drawStr(LM_TC_TEX, size, x, baseline, &s[0], 2);
+ sprintf(reinterpret_cast<char*>(s), "#%d", number);
+ drawStr(pain, LM_TC_TEX, size, x, baseline, &s[0], 2);
}
}
MathParInset::Metrics();
} else {
unsigned char s[3];
- sprintf((char*)s, "#%d", number);
+ sprintf(reinterpret_cast<char*>(s), "#%d", number);
width = mathed_string_width(LM_TC_TEX, size, &s[0], 2);
mathed_string_height(LM_TC_TEX, size, &s[0], 2, ascent, descent);
}
void MathMacroArgument::Write(ostream & os)
{
+#ifdef USE_OSTREAM_ONLY
+ if (expnd_mode) {
+ MathParInset::Write(os);
+ } else {
+ os << '#' << number << ' ';
+ }
+#else
string output;
MathMacroArgument::Write(output);
os << output;
+#endif
}
+#ifndef USE_OSTREAM_ONLY
void MathMacroArgument::Write(string & file)
{
if (expnd_mode) {
file += ' ';
}
}
+#endif
/* --------------------- MathMacroTemplate ---------------------------*/
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
flags(flg), nargs(na)
{
- if (nargs>0) {
+ if (nargs > 0) {
tcode = LM_TC_ACTIVE_INSET;
args = new MathMacroArgument[nargs];
- for (int i= 0; i<nargs; i++) {
- args[i].setNumber(i+1);
+ for (int i = 0; i < nargs; ++i) {
+ args[i].setNumber(i + 1);
}
} else
tcode = LM_TC_INSET;
MathMacroTemplate::~MathMacroTemplate()
{
// prevent to delete already deleted objects
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].SetData(0);
}
delete[] args;
}
-void MathMacroTemplate::Draw(int x, int y)
+void MathMacroTemplate::draw(Painter & pain, int x, int y)
{
int x2, y2;
- bool expnd = (nargs>0) ? args[0].getExpand(): false;
+ bool expnd = (nargs > 0) ? args[0].getExpand(): false;
if (flags & MMF_Edit) {
for (int i = 0; i < nargs; ++i) {
args[i].setExpand(false);
}
x2 = xo; y2 = yo;
}
- MathParInset::Draw(x, y);
+ MathParInset::draw(pain, x, y);
xo = x2; yo = y2;
for (int i = 0; i < nargs; ++i) {
bool expnd = (nargs>0) ? args[0].getExpand(): false;
if (flags & MMF_Edit) {
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(false);
}
} else {
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(true);
}
}
MathParInset::Metrics();
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
args[i].setExpand(expnd);
}
}
void MathMacroTemplate::update(MathMacro * macro)
{
int idx = (macro) ? macro->getArgumentIdx(): 0;
- for (int i= 0; i<nargs; i++) {
+ for (int i = 0; i < nargs; ++i) {
if (macro) {
macro->setArgumentIdx(i);
args[i].SetData(macro->GetData());
}
-void MathMacroTemplate::WriteDef(string &file)
+#ifndef USE_OSTREAM_ONLY
+void MathMacroTemplate::WriteDef(string & file)
{
file += "\n\\newcommand{\\";
file += name;
Write(file);
file += "}\n";
}
+#endif
void MathMacroTemplate::setArgument(LyxArrayBase * a, int i)
MathParInset * MathMacroTemplate::getMacroPar(int i) const
{
- return (i >= 0 && i < nargs) ? (MathParInset*)&args[i] : 0;
+ return (i >= 0 && i < nargs) ? static_cast<MathParInset*>(&args[i]) : 0;
}
/* -------------------------- MathMacroTable -----------------------*/
-MathMacroTable::MathMacroTable(int n): max_macros(n)
+MathMacroTable::MathMacroTable(int n) : max_macros(n)
{
macro_table = new MathMacroTemplateP[max_macros];
num_macros = 0;