X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathFont.cpp;h=05f9e66e73b081b51fa5653343dfa75d8ff3abd9;hb=02e82157ec583c3900e359de86be79fac6512387;hp=a4675bf0d4d08f8703ba78388c01afd952f9966f;hpb=ed858d73e57ce7aa89e38c1bc4d799362edb0227;p=lyx.git diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index a4675bf0d4..05f9e66e73 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -3,7 +3,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author André Pönitz + * \author André Pönitz * * Full author contact details are available in file CREDITS. */ @@ -11,17 +11,25 @@ #include #include "InsetMathFont.h" + +#include "LaTeXFeatures.h" #include "MathData.h" #include "MathStream.h" #include "MathParser.h" -#include "LaTeXFeatures.h" -#include "support/std_ostream.h" +#include "MetricsInfo.h" + +#include "support/gettext.h" +#include "support/lassert.h" +#include "support/lstrings.h" +#include + +using namespace lyx::support; namespace lyx { -InsetMathFont::InsetMathFont(latexkeys const * key) - : InsetMathNest(1), key_(key) +InsetMathFont::InsetMathFont(Buffer * buf, latexkeys const * key) + : InsetMathNest(buf, 1), key_(key) {} @@ -31,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") @@ -41,30 +56,53 @@ InsetMath::mode_type InsetMathFont::currentMode() const } -bool InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const +bool InsetMathFont::lockedMode() const +{ + if (key_->extra == "forcetext") + return true; + return false; +} + + +void InsetMathFont::write(WriteStream & os) const { - FontSetChanger dummy(mi.base, key_->name); + // 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 +{ + Changer dummy = mi.base.changeFontSet(font()); cell(0).metrics(mi, dim); - metricsMarkers(dim); - if (dim_ == dim) - return false; - dim_ = dim; - return true; + metricsMarkers(mi, dim); } void InsetMathFont::draw(PainterInfo & pi, int x, int y) const { - FontSetChanger dummy(pi.base, key_->name.c_str()); + Changer dummy = pi.base.changeFontSet(font()); cell(0).draw(pi, x + 1, y); drawMarkers(pi, x, y); - setPosCache(pi, x, y); } void InsetMathFont::metricsT(TextMetricsInfo const & mi, Dimension &) const { - cell(0).metricsT(mi, dim_); + // FIXME: BROKEN! + Dimension dim; + cell(0).metricsT(mi, dim); } @@ -83,20 +121,122 @@ docstring InsetMathFont::name() const void InsetMathFont::validate(LaTeXFeatures & features) const { InsetMathNest::validate(features); - // Make sure amssymb is put in preamble if Blackboard Bold or - // Fraktur used: - if (key_->name == "mathfrak" || key_->name == "mathbb") - features.require("amssymb"); - if (key_->name == "text") - features.require("amsmath"); - if (key_->name == "textipa") - features.require("tipa"); + std::string fontname = font(); + if (features.runparams().isLaTeX()) { + // Make sure amssymb is put in preamble if Blackboard Bold or + // Fraktur used: + if (fontname == "mathfrak" || fontname == "mathbb") + features.require("amssymb"); + if (fontname == "text" || fontname == "textnormal" + || (fontname.length() == 6 && fontname.substr(0, 4) == "text")) + features.require("amstext"); + if (fontname == "mathscr") + features.require("mathrsfs"); + if (fontname == "textipa") + features.require("tipa"); + if (fontname == "ce" || fontname == "cf") + features.require("mhchem"); + } else if (features.runparams().math_flavor == OutputParams::MathAsHTML) { + features.addCSSSnippet( + "span.normal{font: normal normal normal inherit serif;}\n" + "span.fraktur{font: normal normal normal inherit cursive;}\n" + "span.bold{font: normal normal bold inherit serif;}\n" + "span.script{font: normal normal normal inherit cursive;}\n" + "span.italic{font: italic normal normal inherit serif;}\n" + "span.sans{font: normal normal normal inherit sans-serif;}\n" + "span.monospace{font: normal normal normal inherit monospace;}\n" + "span.noun{font: normal small-caps normal inherit normal;}"); + } +} + + +// The fonts we want to support are listed in lib/symbols +void InsetMathFont::htmlize(HtmlStream & os) const +{ + // FIXME These are not quite right, because they do not nest + // correctly. A proper fix would presumably involve tracking + // the fonts already in effect. + std::string variant; + docstring const & tag = key_->name; + if (tag == "mathnormal" || tag == "mathrm" + || tag == "text" || tag == "textnormal" + || tag == "textrm" || tag == "textup" + || tag == "textmd") + variant = "normal"; + else if (tag == "frak" || tag == "mathfrak") + variant = "fraktur"; + else if (tag == "mathbb" || tag == "mathbf" + || tag == "textbf") + variant = "bold"; + else if (tag == "mathcal") + variant = "script"; + else if (tag == "mathit" || tag == "textsl" + || tag == "emph" || tag == "textit") + variant = "italic"; + else if (tag == "mathsf" || tag == "textsf") + variant = "sans"; + else if (tag == "mathtt" || tag == "texttt") + variant = "monospace"; + else if (tag == "textipa" || tag == "textsc" || tag == "noun") + variant = "noun"; + + docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4); + if (!variant.empty()) { + os << MTag("span", "class='" + variant + "'") + << cell(0) + << ETag("span"); + } else + os << cell(0); +} + + +// The fonts we want to support are listed in lib/symbols +void InsetMathFont::mathmlize(MathStream & os) const +{ + // FIXME These are not quite right, because they do not nest + // correctly. A proper fix would presumably involve tracking + // the fonts already in effect. + std::string variant; + docstring const & tag = key_->name; + if (tag == "mathnormal" || tag == "mathrm" + || tag == "text" || tag == "textnormal" + || tag == "textrm" || tag == "textup" + || tag == "textmd") + variant = "normal"; + else if (tag == "frak" || tag == "mathfrak") + variant = "fraktur"; + else if (tag == "mathbb" || tag == "mathbf" + || tag == "textbf") + variant = "bold"; + else if (tag == "mathcal") + variant = "script"; + else if (tag == "mathit" || tag == "textsl" + || tag == "emph" || tag == "textit") + variant = "italic"; + else if (tag == "mathsf" || tag == "textsf") + variant = "sans-serif"; + else if (tag == "mathtt" || tag == "texttt") + variant = "monospace"; + // no support at present for textipa, textsc, noun + + if (!variant.empty()) { + if (tag == "mathbb") { + os << MTag("mstyle", "class='mathbb' mathvariant='" + variant + "'") + << cell(0) + << ETag("mstyle"); + } else { + os << MTag("mstyle", "mathvariant='" + variant + "'") + << cell(0) + << ETag("mstyle"); + } + } else + os << cell(0); } void InsetMathFont::infoize(odocstream & os) const { - os << "Font: " << key_->name; + os << bformat(_("Font: %1$s"), key_->name); }