/* draw the string s with current font, but stretch it to fit the given width (a+d). We haven't implemented stretching, so i just center the character. */ void CairoPainter::drawText(const DOMString &s, float w) { float sw = stringWidth(s) + absx; // this can't be right float hdiff = w - sw; cairo_move_to(m_painter, hdiff/2+absx, absy); cairo_show_text(m_painter, s.utf8()); }
void CairoPainter::drawText(const DOMString &s) { if (debugdrawtext) { drawOutline(stringWidth(s)); } cairo_move_to(m_painter, absx, absy); cairo_show_text(m_painter, s.utf8()); }
void CairoPainter::drawText(const DOMString &s, float w, float a, float d) { float sw = stringWidth(s); float hdiff = w-sw; float fa = fontAscent(); float fd = fontDescent(); float vdiff = d-fd - a+fa; cairo_move_to(m_painter, hdiff/2, vdiff/2); cairo_show_text(m_painter, s.utf8()); }
/* this function sets an attribute in a dictionary entry */ void MMLmo::setAttribute(const char *op, const std::string &name, const DOMString &v, const MMLAttribute **a) { int pos = createAttribute(name.c_str(), v, MML::MO, a); if (pos == -1) { cerr << "internal error in MMLmo::makedict: invalid attribute '" << name << "', value invalid: '" << v.utf8() << "' for operator '" << op << "'." << endl; exit(1); } }
// static functions for initializing the operator dictionary void MMLmo::makedict() { madedict = true; for (int i=0; i<351; ++i) { const char *end; const char *start = rawopdict[i]; const char *send = start+strlen(start); end = strchr(start, ' '); DOMString op; for (const char *j=start; j!=end; ++j) { op += *j; } const MMLAttribute **a = new const MMLAttribute*[MML::moNumAtts]; for (uint j=0; j<MML::moNumAtts; ++j) { a[j] = 0; } while (*end != '\0') { std::string name; start = end+1; end = strchr(start, '='); for (const char *j=start; j!=end; ++j) { name += *j; } start = end+1; end = strchr(start, ' '); if (!end) end = send; DOMString value; for (const char *j=start; j!=end; ++j) { value += *j; } setAttribute(op.utf8(), name, value, a); } // dict.insert(pair<DOMString, MMLAttribute **>(op, a)); // DOMString uni = op; op.resolveEntities(); // if (uni != op) { dict.insert(pair<DOMString, const MMLAttribute **> (op, a)); // } } }
float CairoPainter::stringWidth(const DOMString &s) const { cairo_text_extents(m_painter, s.utf8(), &m_textsize); return m_textsize.width; }