*
* Dependencies: Mathed
*
- * Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra
+ * Copyright: 1996, 1997 Alejandro Aguilar Sierra
*
* Version: 0.2, Mathed & Lyx project.
*
#include "support/lstrings.h"
#include "debug.h"
+using std::ostream;
+using std::endl;
ostream & operator<<(ostream & o, MathedTextCodes mtc)
{
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&);
}
-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)
-{
- string output;
- MathMacro::Write(output);
- os << output;
-}
-
-
-void MathMacro::Write(string &file)
+void MathMacro::Write(ostream & os, bool fragile)
{
if (tmplate->flags & MMF_Exp) {
lyxerr[Debug::MATHED] << "Expand " << tmplate->flags
<< ' ' << MMF_Exp << endl;
tmplate->update(this);
- tmplate->Write(file);
+ tmplate->Write(os, fragile);
} else {
if (tmplate->flags & MMF_Env) {
- file += "\\begin{";
- file += name;
- file += "} ";
+ os << "\\begin{"
+ << name
+ << "} ";
} else {
- file += '\\';
- file += name;
+ os << '\\' << name;
}
// if (options) {
// file += '[';
// }
if (!(tmplate->flags & MMF_Env) && nargs > 0)
- file += '{';
+ os << '{';
for (int i = 0; i < nargs; ++i) {
array = args[i].array;
- MathParInset::Write(file);
+ MathParInset::Write(os, fragile);
if (i < nargs - 1)
- file += "}{";
+ os << "}{";
}
if (tmplate->flags & MMF_Env) {
- file += "\\end{";
- file += name;
- file += '}';
+ os << "\\end{"
+ << name
+ << '}';
} else {
if (nargs > 0)
- file += '}';
+ os << '}';
else
- file += ' ';
+ os << ' ';
}
}
}
-
/*--------------- Macro argument -----------------------------------*/
MathMacroArgument::MathMacroArgument(int n)
}
-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(reinterpret_cast<char*>(s), "#%d", number);
- drawStr(LM_TC_TEX, size, x, baseline, &s[0], 2);
+#ifdef HAVE_SSTREAM
+ std::ostringstream ost;
+ ost << '#' << number;
+ drawStr(pain, LM_TC_TEX, size, x, baseline,
+ reinterpret_cast<byte const *>(ost.str().c_str()), 2);
+#else
+ char s[3];
+ ostrstream ost(s, 3);
+ ost << '#' << number << '\0';
+ drawStr(pain, LM_TC_TEX, size, x, baseline,
+ reinterpret_cast<byte *>(ost.str()), 2);
+#endif
}
}
if (expnd_mode) {
MathParInset::Metrics();
} else {
- unsigned char s[3];
- 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);
+#ifdef HAVE_SSTREAM
+ std::ostringstream ost;
+ ost << '#' << number;
+ width = mathed_string_width(LM_TC_TEX, size,
+ reinterpret_cast<byte const *>(ost.str().c_str()), 2);
+ mathed_string_height(LM_TC_TEX, size,
+ reinterpret_cast<byte const *>(ost.str().c_str()),
+ 2, ascent, descent);
+#else
+ char s[3];
+ ostrstream ost(s, 3);
+ ost << '#' << number << '\0';
+ width = mathed_string_width(LM_TC_TEX, size,
+ reinterpret_cast<byte *>
+ (ost.str()), 2);
+ mathed_string_height(LM_TC_TEX, size,
+ reinterpret_cast<byte *>(ost.str()),
+ 2, ascent, descent);
+#endif
}
}
-void MathMacroArgument::Write(ostream & os)
-{
- string output;
- MathMacroArgument::Write(output);
- os << output;
-}
-
-
-void MathMacroArgument::Write(string & file)
+void MathMacroArgument::Write(ostream & os, bool fragile)
{
if (expnd_mode) {
- MathParInset::Write(file);
+ MathParInset::Write(os, fragile);
} else {
- file += '#';
- file += tostr(number);
- file += ' ';
+ os << '#' << number << ' ';
}
}
}
-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) {
}
-void MathMacroTemplate::WriteDef(ostream & os)
+void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
{
os << "\n\\newcommand{\\" << name << "}";
for (int i = 0; i < nargs; ++i) {
args[i].setExpand(false);
}
- Write(os);
+ Write(os, fragile);
os << "}\n";
}
-void MathMacroTemplate::WriteDef(string &file)
-{
- file += "\n\\newcommand{\\";
- file += name;
- file += '}';
-
- if (nargs > 0 ) {
- file += '[';
- file += tostr(nargs);
- file += ']';
- }
-
- file += '{';
-
- for (int i = 0; i < nargs; ++i) {
- args[i].setExpand(false);
- }
- Write(file);
- file += "}\n";
-}
-
-
void MathMacroTemplate::setArgument(LyxArrayBase * a, int i)
{
args[i].SetData(a);
/* -------------------------- MathMacroTable -----------------------*/
-MathMacroTable::MathMacroTable(int n): max_macros(n)
+MathMacroTable::MathMacroTable(int n) : max_macros(n)
{
macro_table = new MathMacroTemplateP[max_macros];
num_macros = 0;