Add the '\rule' command for drawing boxes

Summary:
Supports the 'ex' and 'em' units for sizes. Doesn't support the optional depth
argument.

Test Plan:
 - See that the huxley test looks good, and nothing else changed
 - See that the tests pass

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D12777
This commit is contained in:
Emily Eisenberg
2014-08-29 14:45:27 -07:00
parent a75bf1afc2
commit f17bbf1b05
8 changed files with 178 additions and 4 deletions

View File

@@ -72,7 +72,8 @@ var groupToType = {
ordgroup: "mord",
namedfn: "mop",
katex: "mord",
overline: "mord"
overline: "mord",
rule: "mord"
};
var getTypeOfGroup = function(group) {
@@ -696,6 +697,31 @@ var groupTypes = {
} else {
throw new ParseError("Illegal delimiter: '" + original + "'");
}
},
rule: function(group, options, prev) {
// Make an empty span for the rule
var rule = makeSpan(["mord", "rule"], []);
var width = group.value.width.number;
if (group.value.width.unit === "ex") {
width *= fontMetrics.metrics.xHeight;
}
var height = group.value.height.number;
if (group.value.height.unit === "ex") {
height *= fontMetrics.metrics.xHeight;
}
// Style the rule to the right size
rule.style.borderRightWidth = width + "em";
rule.style.borderTopWidth = height + "em";
// Record the height and width
rule.width = width;
rule.height = height;
return rule;
}
};