X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathFont.cpp;h=2a0cb997aa15636665d5df6b046e731b151c8eae;hb=d9082639080b9de993742bd352f92e5183058cf5;hp=b49985829a9d6a37bced7e97549a0a753c03047e;hpb=ff85a4902ec4fff1b3bf0dbc9c9c53b3e87563cf;p=lyx.git diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index b49985829a..2a0cb997aa 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -19,6 +19,7 @@ #include "MetricsInfo.h" #include "support/gettext.h" +#include "support/lassert.h" #include "support/lstrings.h" #include @@ -38,6 +39,13 @@ Inset * InsetMathFont::clone() const } +std::string InsetMathFont::font() const +{ + LASSERT(isAscii(key_->name), return "mathnormal"); + return to_ascii(key_->name); +} + + InsetMath::mode_type InsetMathFont::currentMode() const { if (key_->extra == "mathmode") @@ -50,26 +58,39 @@ InsetMath::mode_type InsetMathFont::currentMode() const bool InsetMathFont::lockedMode() const { - if (key_->extra == "forcetext") - return true; - return false; + return key_->extra == "forcetext"; +} + + +void InsetMathFont::write(TeXMathStream & os) const +{ + // Close the mode changing command inserted during export if + // we are going to output another mode changing command that + // actually doesn't change mode. This avoids exporting things + // such as \ensuremath{a\mathit{b}} or \textit{a\text{b}} and + // produce instead \ensuremath{a}\mathit{b} and \textit{a}\text{b}. + if (os.pendingBrace() + && ((currentMode() == TEXT_MODE && os.textMode()) + || (currentMode() == MATH_MODE && !os.textMode()))) { + os.os() << '}'; + os.pendingBrace(false); + os.textMode(!os.textMode()); + } + InsetMathNest::write(os); } void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const { - FontSetChanger dummy(mi.base, key_->name); + Changer dummy = mi.base.changeFontSet(font()); cell(0).metrics(mi, dim); - metricsMarkers(dim); } void InsetMathFont::draw(PainterInfo & pi, int x, int y) const { - FontSetChanger dummy(pi.base, key_->name.c_str()); - cell(0).draw(pi, x + 1, y); - drawMarkers(pi, x, y); - setPosCache(pi, x, y); + Changer dummy = pi.base.changeFontSet(font()); + cell(0).draw(pi, x, y); } @@ -96,20 +117,23 @@ docstring InsetMathFont::name() const void InsetMathFont::validate(LaTeXFeatures & features) const { InsetMathNest::validate(features); + std::string fontname = font(); if (features.runparams().isLaTeX()) { // Make sure amssymb is put in preamble if Blackboard Bold or // Fraktur used: - if (key_->name == "mathfrak" || key_->name == "mathbb") + if (fontname == "mathfrak" || fontname == "mathbb") features.require("amssymb"); - if (key_->name == "text" || key_->name == "textnormal" - || (key_->name.length() == 6 && key_->name.substr(0, 4) == "text")) + if (fontname == "text" || fontname == "textnormal" + || (fontname.length() == 6 && fontname.substr(0, 4) == "text")) features.require("amstext"); - if (key_->name == "mathscr") + if (fontname == "mathscr") features.require("mathrsfs"); - if (key_->name == "textipa") + if (fontname == "textipa") features.require("tipa"); - if (key_->name == "ce" || key_->name == "cf") + if (fontname == "ce" || fontname == "cf") features.require("mhchem"); + if (fontname == "mathds") + features.require("dsfont"); } else if (features.runparams().math_flavor == OutputParams::MathAsHTML) { features.addCSSSnippet( "span.normal{font: normal normal normal inherit serif;}\n" @@ -139,9 +163,11 @@ void InsetMathFont::htmlize(HtmlStream & os) const variant = "normal"; else if (tag == "frak" || tag == "mathfrak") variant = "fraktur"; - else if (tag == "mathbb" || tag == "mathbf" - || tag == "textbf") + else if (tag == "mathbf" || tag == "textbf") variant = "bold"; + else if (tag == "mathbb" || tag == "mathbbm" + || tag == "mathds") + variant = "double-struck"; else if (tag == "mathcal") variant = "script"; else if (tag == "mathit" || tag == "textsl" @@ -165,7 +191,7 @@ void InsetMathFont::htmlize(HtmlStream & os) const // The fonts we want to support are listed in lib/symbols -void InsetMathFont::mathmlize(MathStream & os) const +void InsetMathFont::mathmlize(MathMLStream & ms) const { // FIXME These are not quite right, because they do not nest // correctly. A proper fix would presumably involve tracking @@ -179,9 +205,11 @@ void InsetMathFont::mathmlize(MathStream & os) const variant = "normal"; else if (tag == "frak" || tag == "mathfrak") variant = "fraktur"; - else if (tag == "mathbb" || tag == "mathbf" - || tag == "textbf") + else if (tag == "mathbf" || tag == "textbf") variant = "bold"; + else if (tag == "mathbb" || tag == "mathbbm" + || tag == "mathds") + variant = "double-struck"; else if (tag == "mathcal") variant = "script"; else if (tag == "mathit" || tag == "textsl" @@ -193,12 +221,12 @@ void InsetMathFont::mathmlize(MathStream & os) const variant = "monospace"; // no support at present for textipa, textsc, noun - if (!variant.empty()) { - os << MTag("mstyle", "mathvariant='" + variant + "'") + if (!variant.empty()) + ms << MTag("mstyle", "mathvariant='" + variant + "'") << cell(0) << ETag("mstyle"); - } else - os << cell(0); + else + ms << cell(0); }