void InsetMathSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const { if (mi.base.fontname == "mathnormal") { ShapeChanger dummy(mi.base.font, UP_SHAPE); dim = theFontMetrics(mi.base.font).dimension(char_); } else { frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); dim = fm.dimension(char_); kerning_ = fm.rbearing(char_) - dim.wid; } }
void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const { // label Font font = p.base.font; font.setColor(Color_math); PainterInfo pi(p.base.bv, p.pain); pi.base.style = LM_ST_TEXT; pi.base.font = font; int const a = y - dim_.asc + 1; int const w = dim_.wid - 2; int const h = dim_.height() - 2; // Color_mathbg used to be "AntiqueWhite" but is "linen" now, too pi.pain.fillRectangle(x, a, w, h, Color_mathmacrobg); pi.pain.rectangle(x, a, w, h, Color_mathframe); // FIXME #if 0 Cursor & cur = p.base.bv->cursor(); if (cur.isInside(this)) cur.drawSelection(pi); #endif pi.pain.text(x + 2, y, prefix(), font); // body tmpl()->draw(pi, x + theFontMetrics(p.base.font).width(prefix()) + 5, y); setPosCache(pi, x, y); }
void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const { double const h = theFontMetrics(mi.base.font).ascent('I'); double const f = increase(); dim.wid = 6; dim.asc = int(h + f * h); dim.des = int(f * h); }
void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const { //lyxerr << "InsetFormulaMacro: " << this << " -- " << &tmpl() << endl; tmpl()->metrics(mi, dim); dim.asc += 5; dim.des += 5; dim.wid += 10 + theFontMetrics(mi.base.font).width(prefix()); dim_ = dim; }
void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const { frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); dim.asc = fm.maxAscent(); dim.des = 0; dim.wid = 0; docstring s; switch (kind_) { case ALLOWBREAK: dim.asc = fm.xHeight(); dim.des = fm.descent('g'); dim.wid = fm.em() / 8; break; case LIGATURE_BREAK: s = from_ascii("|"); break; case END_OF_SENTENCE: s = from_ascii("."); break; case LDOTS: s = from_ascii(". . ."); break; case MENU_SEPARATOR: // ▹ U+25B9 WHITE RIGHT-POINTING SMALL TRIANGLE // There is a \thinspace on each side of the triangle dim.wid = 2 * fm.em() / 6 + fm.width(char_type(0x25B9)); break; case HYPHENATION: dim.wid = fm.width(from_ascii("-")); if (dim.wid > 5) dim.wid -= 2; // to make it look shorter break; case SLASH: s = from_ascii("/"); dim.des = fm.descent(s[0]); break; case NOBREAKDASH: s = from_ascii("-"); break; case PHRASE_LYX: case PHRASE_TEX: case PHRASE_LATEX2E: case PHRASE_LATEX: dim.asc = fm.maxAscent(); dim.des = fm.maxDescent(); frontend::NullPainter np; PainterInfo pi(mi.base.bv, np); pi.base.font = mi.base.font; drawLogo(pi, dim.wid, 0, kind_); break; } if (dim.wid == 0) dim.wid = fm.width(s); }
void InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const { Dimension dim0; cell(0).metrics(mi, dim0); FontInfo font = mi.base.font; augmentFont(font, from_ascii("mathnormal")); Dimension t = theFontMetrics(font).dimension('{'); dim.asc = max(dim0.asc, t.asc); dim.des = max(dim0.des, t.des); dim.wid = dim0.width() + 2 * t.wid; metricsMarkers(dim); }
void InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const { #if 1 if (char_ == '=' && has_math_fonts) { FontSetChanger dummy(mi.base, "cmr"); dim = theFontMetrics(mi.base.font).dimension(char_); } else if ((char_ == '>' || char_ == '<') && has_math_fonts) { FontSetChanger dummy(mi.base, "cmm"); dim = theFontMetrics(mi.base.font).dimension(char_); } else if (!slanted(char_) && mi.base.fontname == "mathnormal") { ShapeChanger dummy(mi.base.font, UP_SHAPE); dim = theFontMetrics(mi.base.font).dimension(char_); } else { frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); dim = fm.dimension(char_); kerning_ = fm.rbearing(char_) - dim.wid; } int const em = mathed_char_width(mi.base.font, 'M'); if (isBinaryOp(char_)) dim.wid += static_cast<int>(0.5*em+0.5); else if (char_ == '\'') dim.wid += static_cast<int>(0.1667*em+0.5); #else whichFont(font_, code_, mi); dim = theFontMetrics(font_).dimension(char_); if (isBinaryOp(char_, code_)) dim.wid += 2 * theFontMetrics(font_).width(' '); lyxerr << "InsetMathChar::metrics: " << dim << endl; #endif }
void InsetMathBrace::draw(PainterInfo & pi, int x, int y) const { FontInfo font = pi.base.font; augmentFont(font, from_ascii("mathnormal")); font.setShape(UP_SHAPE); font.setColor(Color_latex); Dimension t = theFontMetrics(font).dimension('{'); pi.pain.text(x, y, '{', font); cell(0).draw(pi, x + t.wid, y); Dimension const & dim0 = cell(0).dimension(*pi.base.bv); pi.pain.text(x + t.wid + dim0.width(), y, '}', font); drawMarkers(pi, x, y); }
void RenderButton::metrics(MetricsInfo &, Dimension & dim) const { FontInfo font = sane_font; font.decSize(); frontend::FontMetrics const & fm = theFontMetrics(font); if (editable_) fm.buttonText(text_, dim.wid, dim.asc, dim.des); else fm.rectText(text_, dim.wid, dim.asc, dim.des); dim.wid += 2; dim_ = dim; }
void InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const { Dimension dim0; cell(0).metrics(mi, dim0); Dimension t = theFontMetrics(mi.base.font).dimension('I'); int h0 = (t.asc + t.des) / 2; int a0 = max(dim0.asc, t.asc) - h0; int d0 = max(dim0.des, t.des) + h0; dw_ = dim0.height() / 5; if (dw_ > 8) dw_ = 8; if (dw_ < 4) dw_ = 4; dim.wid = dim0.width() + 2 * dw_ + 8; dim.asc = max(a0, d0) + h0; dim.des = max(a0, d0) - h0; }
void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const { FontInfo tmpfont = mi.base.font; mi.base.font = mi.base.bv->buffer().params().getFont().fontInfo(); labelwidth_ = theFontMetrics(mi.base.font).width(full_label_); // add some space to separate the label from the inset text labelwidth_ += 2 * TEXT_TO_INSET_OFFSET; dim.wid = labelwidth_; Dimension textdim; // Correct for button and label width mi.base.textwidth -= dim.wid; InsetText::metrics(mi, textdim); mi.base.font = tmpfont; mi.base.textwidth += dim.wid; dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des); dim.asc = textdim.asc; dim.wid += textdim.wid; }
void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const { frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); dim.asc = fm.maxAscent(); dim.des = fm.maxDescent(); string s; switch (kind_) { case LIGATURE_BREAK: s = "|"; break; case END_OF_SENTENCE: s = "."; break; case LDOTS: s = ". . ."; break; case MENU_SEPARATOR: s = " x "; break; case HYPHENATION: s = "-"; break; case SLASH: s = "/"; break; case NOBREAKDASH: s = "-"; break; } docstring ds(s.begin(), s.end()); dim.wid = fm.width(ds); if (kind_ == HYPHENATION && dim.wid > 5) dim.wid -= 2; // to make it look shorter setDimCache(mi, dim); }
void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const { FontInfo font = pi.base.font; switch (kind_) { case HYPHENATION: { font.setColor(Color_special); pi.pain.text(x, y, char_type('-'), font); break; } case ALLOWBREAK: { // A small vertical line int const asc = theFontMetrics(pi.base.font).xHeight(); int const desc = theFontMetrics(pi.base.font).descent('g'); int const x0 = x; // x + 1; // FIXME: incline, int const x1 = x; // x - 1; // similar to LibreOffice? int const y0 = y + desc; int const y1 = y - asc / 3; pi.pain.line(x0, y1, x1, y0, Color_special); break; } case LIGATURE_BREAK: { font.setColor(Color_special); pi.pain.text(x, y, char_type('|'), font); break; } case END_OF_SENTENCE: { font.setColor(Color_special); pi.pain.text(x, y, char_type('.'), font); break; } case LDOTS: { font.setColor(Color_special); string ell = ". . . "; docstring dell(ell.begin(), ell.end()); pi.pain.text(x, y, dell, font); break; } case MENU_SEPARATOR: { frontend::FontMetrics const & fm = theFontMetrics(font); // There is a \thinspace on each side of the triangle x += fm.em() / 6; // ▹ U+25B9 WHITE RIGHT-POINTING SMALL TRIANGLE // ◃ U+25C3 WHITE LEFT-POINTING SMALL TRIANGLE char_type const c = pi.ltr_pos ? 0x25B9 : 0x25C3; font.setColor(Color_special); pi.pain.text(x, y, c, font); break; } case SLASH: { font.setColor(Color_special); pi.pain.text(x, y, char_type('/'), font); break; } case NOBREAKDASH: { font.setColor(Color_latex); pi.pain.text(x, y, char_type('-'), font); break; } case PHRASE_LYX: case PHRASE_TEX: case PHRASE_LATEX2E: case PHRASE_LATEX: drawLogo(pi, x, y, kind_); break; } }
int Length::inPixels(MetricsBase const & base) const { return inPixels(base.textwidth, theFontMetrics(base.font).em()); }
void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const { FontInfo font = pi.base.font; switch (kind_) { case HYPHENATION: { font.setColor(Color_special); pi.pain.text(x, y, char_type('-'), font); break; } case LIGATURE_BREAK: { font.setColor(Color_special); pi.pain.text(x, y, char_type('|'), font); break; } case END_OF_SENTENCE: { font.setColor(Color_special); pi.pain.text(x, y, char_type('.'), font); break; } case LDOTS: { font.setColor(Color_special); string ell = ". . . "; docstring dell(ell.begin(), ell.end()); pi.pain.text(x, y, dell, font); break; } case MENU_SEPARATOR: { frontend::FontMetrics const & fm = theFontMetrics(font); // A triangle the width and height of an 'x' int w = fm.width(char_type('x')); int ox = fm.width(char_type(' ')) + x; int h = fm.ascent(char_type('x')); int xp[4], yp[4]; xp[0] = ox; yp[0] = y; xp[1] = ox; yp[1] = y - h; xp[2] = ox + w; yp[2] = y - h/2; xp[3] = ox; yp[3] = y; pi.pain.lines(xp, yp, 4, Color_special); break; } case SLASH: { font.setColor(Color_special); pi.pain.text(x, y, char_type('/'), font); break; } case NOBREAKDASH: { font.setColor(Color_latex); pi.pain.text(x, y, char_type('-'), font); break; } } }