1 |
|
2 | import buildCommon from "../buildCommon";
|
3 | import defineFunction from "../defineFunction";
|
4 | import mathMLTree from "../mathMLTree";
|
5 | import {assertNodeType} from "../parseNode";
|
6 | import {calculateSize} from "../units";
|
7 |
|
8 | defineFunction({
|
9 | type: "rule",
|
10 | names: ["\\rule"],
|
11 | props: {
|
12 | numArgs: 2,
|
13 | numOptionalArgs: 1,
|
14 | argTypes: ["size", "size", "size"],
|
15 | },
|
16 | handler({parser}, args, optArgs) {
|
17 | const shift = optArgs[0];
|
18 | const width = assertNodeType(args[0], "size");
|
19 | const height = assertNodeType(args[1], "size");
|
20 | return {
|
21 | type: "rule",
|
22 | mode: parser.mode,
|
23 | shift: shift && assertNodeType(shift, "size").value,
|
24 | width: width.value,
|
25 | height: height.value,
|
26 | };
|
27 | },
|
28 | htmlBuilder(group, options) {
|
29 |
|
30 | const rule = buildCommon.makeSpan(["mord", "rule"], [], options);
|
31 |
|
32 |
|
33 | const width = calculateSize(group.width, options);
|
34 | const height = calculateSize(group.height, options);
|
35 | const shift = (group.shift) ? calculateSize(group.shift, options) : 0;
|
36 |
|
37 |
|
38 | rule.style.borderRightWidth = width + "em";
|
39 | rule.style.borderTopWidth = height + "em";
|
40 | rule.style.bottom = shift + "em";
|
41 |
|
42 |
|
43 | rule.width = width;
|
44 | rule.height = height + shift;
|
45 | rule.depth = -shift;
|
46 |
|
47 |
|
48 |
|
49 | rule.maxFontSize = height * 1.125 * options.sizeMultiplier;
|
50 |
|
51 | return rule;
|
52 | },
|
53 | mathmlBuilder(group, options) {
|
54 | const width = calculateSize(group.width, options);
|
55 | const height = calculateSize(group.height, options);
|
56 | const shift = (group.shift) ? calculateSize(group.shift, options) : 0;
|
57 | const color = options.color && options.getColor() || "black";
|
58 |
|
59 | const rule = new mathMLTree.MathNode("mspace");
|
60 | rule.setAttribute("mathbackground", color);
|
61 | rule.setAttribute("width", width + "em");
|
62 | rule.setAttribute("height", height + "em");
|
63 |
|
64 | const wrapper = new mathMLTree.MathNode("mpadded", [rule]);
|
65 | if (shift >= 0) {
|
66 | wrapper.setAttribute("height", "+" + shift + "em");
|
67 | } else {
|
68 | wrapper.setAttribute("height", shift + "em");
|
69 | wrapper.setAttribute("depth", "+" + (-shift) + "em");
|
70 | }
|
71 | wrapper.setAttribute("voffset", shift + "em");
|
72 |
|
73 | return wrapper;
|
74 | },
|
75 | });
|