Minsky
MathDAG::anonymous_namespace{equationDisplayRender.cc} Namespace Reference

Classes

struct  RecordingSurface
 

Enumerations

enum  Anchor {
  Anchor::n, Anchor::e, Anchor::w, Anchor::s,
  Anchor::ne, Anchor::nw, Anchor::se, Anchor::sw
}
 

Functions

template<class T >
void moveToAnchor (cairo_t *cairo, const T &object, Anchor anchor)
 
double print (cairo_t *cairo, const string &text, Anchor anchor)
 
template<class X >
double parenthesise (Surface &s, X x, const string &left="(", const string &right=")")
 
void naryRender (Surface &dest, const vector< WeakNodePtr > &arglist, int BODMASlevel, const char *op, const char *empty)
 
void variableRender (Surface &surf, const VariableDAG &v)
 

Enumeration Type Documentation

◆ Anchor

Function Documentation

◆ moveToAnchor()

template<class T >
void MathDAG::anonymous_namespace{equationDisplayRender.cc}::moveToAnchor ( cairo_t *  cairo,
const T &  object,
Anchor  anchor 
)

Definition at line 41 of file equationDisplayRender.cc.

Referenced by print().

42  {
43  switch (anchor)
44  {
45  case Anchor::n:
46  cairo_rel_move_to(cairo, -0.5*object.width(), 0); break;
47  case Anchor::s:
48  cairo_rel_move_to(cairo, -0.5*object.width(), -object.height()); break;
49  case Anchor::e:
50  cairo_rel_move_to(cairo, object.width(), -0.5*object.height()); break;
51  case Anchor::w:
52  cairo_rel_move_to(cairo, 0, -0.5*object.height()); break;
53  case Anchor::ne:
54  cairo_rel_move_to(cairo, -object.width(), 0); break;
55  case Anchor::nw:
56  break;
57  case Anchor::se:
58  cairo_rel_move_to(cairo, -object.width(), -object.height()); break;
59  case Anchor::sw:
60  cairo_rel_move_to(cairo, 0, -object.height()); break;
61  }
62  }
Here is the caller graph for this function:

◆ naryRender()

void MathDAG::anonymous_namespace{equationDisplayRender.cc}::naryRender ( Surface &  dest,
const vector< WeakNodePtr > &  arglist,
int  BODMASlevel,
const char *  op,
const char *  empty 
)

Definition at line 114 of file equationDisplayRender.cc.

References minsky::op, parenthesise(), and print().

Referenced by MathDAG::OperationDAG< OperationType::subtract >::render().

115  {
116  if (arglist.empty())
117  print(dest.cairo(),empty,Anchor::nw);
118  else
119  for (size_t j=0; j<arglist.size(); j++)
120  {
121  if (arglist[j]->BODMASlevel()>BODMASlevel)
122  parenthesise(dest, [&](Surface& dest) {arglist[j]->render(dest);});
123  else
124  arglist[j]->render(dest);
125  if (j!=arglist.size()-1)
126  print(dest.cairo(),op,Anchor::nw);
127  }
128  }
double parenthesise(Surface &s, X x, const string &left="(", const string &right=")")
double print(cairo_t *cairo, const string &text, Anchor anchor)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parenthesise()

template<class X >
double MathDAG::anonymous_namespace{equationDisplayRender.cc}::parenthesise ( Surface &  s,
x,
const string &  left = "(",
const string &  right = ")" 
)

Definition at line 88 of file equationDisplayRender.cc.

References s.

Referenced by naryRender(), and MathDAG::OperationDAG< OperationType::subtract >::render().

89  {
90  double xx,yy;
91  cairo_get_current_point(s.cairo(),&xx,&yy);
92 
93  RecordingSurface r;
94  x(r);
95  Pango pango(s.cairo());
96  const double oldFs=pango.getFontSize();
97  pango.setFontSize(r.height());
98  pango.setMarkup(left);
99  cairo_rel_move_to(s.cairo(),0,-(r.height()-oldFs));
100  pango.show();
101  cairo_rel_move_to(s.cairo(),0,(r.height()-oldFs));
102  cairo_rel_move_to(s.cairo(),pango.width(),0);
103  x(s);
104 
105  xx+=pango.width()+r.width();
106  pango.setMarkup(right);
107  cairo_move_to(s.cairo(),xx,yy-r.height()+oldFs);
108  pango.show();
109  cairo_move_to(s.cairo(),xx+pango.width(),yy);
110  return r.height();
111  }
Here is the caller graph for this function:

◆ print()

double MathDAG::anonymous_namespace{equationDisplayRender.cc}::print ( cairo_t *  cairo,
const string &  text,
Anchor  anchor 
)

Definition at line 66 of file equationDisplayRender.cc.

References moveToAnchor().

Referenced by naryRender(), MathDAG::ConstantDAG::render(), MathDAG::VariableDAG::render(), MathDAG::OperationDAG< OperationType::subtract >::render(), MathDAG::LockDAG::render(), MathDAG::SystemOfEquations::renderEquations(), and variableRender().

67  {
68  Pango pango(cairo);
69  {
70  const CairoSave cs(cairo);
71  pango.setMarkup(text);
72  moveToAnchor(cairo, pango, anchor);
73  pango.show();
74  }
75  cairo_rel_move_to(cairo, pango.width(), 0);
76  return pango.height();
77  }
void moveToAnchor(cairo_t *cairo, const T &object, Anchor anchor)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ variableRender()

void MathDAG::anonymous_namespace{equationDisplayRender.cc}::variableRender ( Surface &  surf,
const VariableDAG v 
)

Definition at line 130 of file equationDisplayRender.cc.

References MathDAG::VariableDAG::init, MathDAG::latexInit(), minsky::latexToPango(), MathDAG::VariableDAG::name, print(), MathDAG::Node::render(), and MathDAG::VariableDAG::rhs.

Referenced by MathDAG::SystemOfEquations::renderEquations().

131  {
132  print(surf.cairo(), latexToPango(v.name)+" = ", Anchor::nw);
133  if (v.rhs)
134  v.rhs->render(surf);
135  else
136  print(surf.cairo(), latexToPango(latexInit(v.init)), Anchor::nw);
137  }
std::string latexToPango(const char *s)
Definition: latexMarkup.h:30
string latexInit(const string &)
convert an initialisation string into a matlab expression
Definition: node_latex.cc:73
double print(cairo_t *cairo, const string &text, Anchor anchor)
Here is the call graph for this function:
Here is the caller graph for this function: