gecko-dev/layout/generic/MathMLTextRunFactory.h
Frederic Wang 8343f88354 Bug 1821980: Align mathvariant implementation on MathML Core. r=emilio,jfkthame
In MathML Core, the recommendation is to directly use the proper
character from the Mathematical Alphanumeric Symbols instead of the
mathvariant attribute. The exception is for automatic italicization on
single-char `<mi>` element. This is implemented via a new text-transform
value "math-auto" [1] which is the default on the `<mi>` element. The
mathvariant attribute is now restricted to that element and to value
"normal" in order to force upright text instead [2]. This CL implements
this restriction together with that new text-transform value under the
mathml.legacy_mathvariant_attribute.disabled flag.

Some legacy MathML cases where math-auto alone does not work are
still handled via MathMLTextRunFactory.

[1] https://w3c.github.io/mathml-core/#new-text-transform-values
[2] https://w3c.github.io/mathml-core/#the-mathvariant-attribute

Differential Revision: https://phabricator.services.mozilla.com/D172395
2023-07-14 19:44:04 +00:00

46 lines
1.7 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MATHMLTEXTRUNFACTORY_H_
#define MATHMLTEXTRUNFACTORY_H_
#include "mozilla/UniquePtr.h"
#include "nsTextRunTransformations.h"
/**
* Builds textruns that render their text with MathML specific renderings.
*/
class MathMLTextRunFactory : public nsTransformingTextRunFactory {
public:
MathMLTextRunFactory(mozilla::UniquePtr<nsTransformingTextRunFactory>
aInnerTransformingTextRunFactory,
uint32_t aFlags, uint8_t aSSTYScriptLevel,
float aFontInflation)
: mInnerTransformingTextRunFactory(
std::move(aInnerTransformingTextRunFactory)),
mFlags(aFlags),
mFontInflation(aFontInflation),
mSSTYScriptLevel(aSSTYScriptLevel) {}
static uint32_t MathVariant(uint32_t aCh, mozilla::StyleMathVariant aMathVar);
virtual void RebuildTextRun(nsTransformedTextRun* aTextRun,
mozilla::gfx::DrawTarget* aRefDrawTarget,
gfxMissingFontRecorder* aMFR) override;
enum {
// Style effects which may override single character <mi> behaviour
MATH_FONT_FEATURE_DTLS = 0x4, // font feature dtls should be set
};
protected:
mozilla::UniquePtr<nsTransformingTextRunFactory>
mInnerTransformingTextRunFactory;
uint32_t mFlags;
float mFontInflation;
uint8_t mSSTYScriptLevel;
};
#endif /*MATHMLTEXTRUNFACTORY_H_*/