/************************************************************* * * Copyright (c) 2018 The MathJax Consortium * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @fileoverview Implements the SVGsemantics wrapper for the MmlSemantics object * and the associated wrappers for annotations * * @author dpvc@mathjax.org (Davide Cervone) */ import {SVGWrapper, SVGConstructor} from '../Wrapper.js'; import {CommonSemantics, CommonSemanticsMixin} from '../../common/Wrappers/semantics.js'; import {BBox} from '../BBox.js'; import {MmlSemantics, MmlAnnotation, MmlAnnotationXML} from '../../../core/MmlTree/MmlNodes/semantics.js'; import {MmlNode, XMLNode} from '../../../core/MmlTree/MmlNode.js'; /*****************************************************************/ /** * The SVGsemantics wrapper for the MmlSemantics object * * @template N The HTMLElement node class * @template T The Text node class * @template D The Document class */ export class SVGsemantics extends CommonSemanticsMixin>(SVGWrapper) { public static kind = MmlSemantics.prototype.kind; /** * @override */ public toSVG(parent: N) { const svg = this.standardSVGnode(parent); if (this.childNodes.length) { this.childNodes[0].toSVG(svg); } } } /*****************************************************************/ /** * The SVGannotation wrapper for the MmlAnnotation object * * @template N The HTMLElement node class * @template T The Text node class * @template D The Document class */ export class SVGannotation extends SVGWrapper { public static kind = MmlAnnotation.prototype.kind; /** * @override */ public toSVG(parent: N) { // FIXME: output as plain text super.toSVG(parent); } /** * @override */ public computeBBox() { // FIXME: compute using the DOM, if possible return this.bbox; } } /*****************************************************************/ /** * The SVGannotationXML wrapper for the MmlAnnotationXML object * * @template N The HTMLElement node class * @template T The Text node class * @template D The Document class */ export class SVGannotationXML extends SVGWrapper { public static kind = MmlAnnotationXML.prototype.kind; } /*****************************************************************/ /** * The SVGxml wrapper for the XMLNode object * * @template N The HTMLElement node class * @template T The Text node class * @template D The Document class */ export class SVGxml extends SVGWrapper { public static kind = XMLNode.prototype.kind; public static autoStyle = false; /** * @override */ public toSVG(parent: N) { const xml = this.adaptor.clone((this.node as XMLNode).getXML() as N); this.adaptor.append(parent, this.svg('foreignObject', {}, [xml])); } /** * @override */ public computeBBox() { // FIXME: compute using the DOM, if possible return this.bbox; } /** * @override */ protected getStyles() {} /** * @override */ protected getScale() {} /** * @override */ protected getVariant() {} }