Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor handling of baseCore, and take enrichment into account (zorkow/speech-rule-engine#462) #617

Merged
merged 2 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ts/output/chtml/Wrappers/mmultiscripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ CommonMmultiscriptsMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLmsubsup<a
*/
public toCHTML(parent: N) {
const chtml = this.standardCHTMLnode(parent);
const data = this.getScriptData();
const data = this.scriptData;
//
// Combine the bounding boxes of the pre- and post-scripts,
// and get the resulting baseline offsets
//
const sub = this.combinePrePost(data.sub, data.psub);
const sup = this.combinePrePost(data.sup, data.psup);
const [u, v] = this.getUVQ(data.base, sub, sup);
const [u, v] = this.getUVQ(sub, sup);
//
// Place the pre-scripts, then the base, then the post-scripts
//
Expand Down
7 changes: 3 additions & 4 deletions ts/output/chtml/Wrappers/msubsup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,16 @@ CommonMsubsupMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLscriptbase<any,
public toCHTML(parent: N) {
const chtml = this.standardCHTMLnode(parent);
const [base, sup, sub] = [this.baseChild, this.supChild, this.subChild];
const [ , v, q] = this.getUVQ(base.getBBox(), sub.getBBox(), sup.getBBox());
const x = this.baseCore.bbox.ic ? this.coreIC() * this.coreScale() : 0;
const [ , v, q] = this.getUVQ();
const style = {'vertical-align': this.em(v)};
base.toCHTML(chtml);
const stack = this.adaptor.append(chtml, this.html('mjx-script', {style})) as N;
sup.toCHTML(stack);
this.adaptor.append(stack, this.html('mjx-spacer', {style: {'margin-top': this.em(q)}}));
sub.toCHTML(stack);
const corebox = this.baseCore.bbox;
const corebox = this.baseCore.getBBox();
if (corebox.ic) {
this.adaptor.setStyle(sup.chtml, 'marginLeft', this.em(x / sup.bbox.rscale));
this.adaptor.setStyle(sup.chtml, 'marginLeft', this.em(this.baseIc / sup.bbox.rscale));
}
}

Expand Down
8 changes: 4 additions & 4 deletions ts/output/chtml/Wrappers/munderover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ CommonMunderMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLmsub<any, any, a
this.html('mjx-under')
) as N;
this.baseChild.toCHTML(base);
this.script.toCHTML(under);
this.scriptChild.toCHTML(under);
const basebox = this.baseChild.getBBox();
const underbox = this.script.getBBox();
const underbox = this.scriptChild.getBBox();
const k = this.getUnderKV(basebox, underbox)[0];
const delta = this.getDelta(true);
this.adaptor.setStyle(under, 'paddingTop', this.em(k));
Expand Down Expand Up @@ -148,9 +148,9 @@ CommonMoverMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLmsup<any, any, an
this.chtml = this.standardCHTMLnode(parent);
const over = this.adaptor.append(this.chtml, this.html('mjx-over')) as N;
const base = this.adaptor.append(this.chtml, this.html('mjx-base')) as N;
this.script.toCHTML(over);
this.scriptChild.toCHTML(over);
this.baseChild.toCHTML(base);
const overbox = this.script.getBBox();
const overbox = this.scriptChild.getBBox();
const basebox = this.baseChild.getBBox();
const k = this.getOverKU(basebox, overbox)[0];
const delta = this.getDelta();
Expand Down
4 changes: 2 additions & 2 deletions ts/output/chtml/Wrappers/scriptbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ CommonScriptbaseMixin<CHTMLWrapper<any, any, any>, CHTMLConstructor<any, any, an
*/
public toCHTML(parent: N) {
this.chtml = this.standardCHTMLnode(parent);
const [x, v] = this.getOffset(this.baseChild.getBBox(), this.script.getBBox());
const [x, v] = this.getOffset();
const style: StyleData = {'vertical-align': this.em(v)};
if (x) {
style['margin-left'] = this.em(x);
}
this.baseChild.toCHTML(this.chtml);
this.script.toCHTML(this.adaptor.append(this.chtml, this.html('mjx-script', {style})) as N);
this.scriptChild.toCHTML(this.adaptor.append(this.chtml, this.html('mjx-script', {style})) as N);
}

/**
Expand Down
41 changes: 21 additions & 20 deletions ts/output/common/Wrappers/mmultiscripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export interface CommonMmultiscripts<W extends AnyWrapper> extends CommonMsubsup
combinePrePost(pre: BBox, post: BBox): BBox;

/**
* @return {ScriptData} The bounding box information about all the scripts
* Compute the bounding box information about all the scripts
*/
getScriptData(): ScriptData;
getScriptData(): void;

/**
* @return {ScriptLists} The bounding boxes for all the scripts divided into lists by position
Expand Down Expand Up @@ -158,6 +158,14 @@ export function CommonMmultiscriptsMixin<
*/
public firstPrescript = 0;

/**
* @override
*/
constructor(...args: any[]) {
super(...args);
this.getScriptData();
}

/*************************************************************/

/**
Expand All @@ -182,10 +190,10 @@ export function CommonMmultiscriptsMixin<
// to get a common offset for both
//
const scriptspace = this.font.params.scriptspace;
const data = this.getScriptData();
const data = this.scriptData;
const sub = this.combinePrePost(data.sub, data.psub);
const sup = this.combinePrePost(data.sup, data.psup);
const [u, v] = this.getUVQ(data.base, sub, sup);
const [u, v] = this.getUVQ(sub, sup);
//
// Lay out the pre-scripts, then the base, then the post-scripts
//
Expand All @@ -206,15 +214,9 @@ export function CommonMmultiscriptsMixin<
}

/**
* @return {ScriptData} The bounding box information about all the scripts
* Compute the bounding box information about all the scripts
*/
public getScriptData(): ScriptData {
//
// Return cached data, if any
//
if (this.scriptData) {
return this.scriptData;
}
public getScriptData() {
//
// Initialize the bounding box data
//
Expand All @@ -228,13 +230,12 @@ export function CommonMmultiscriptsMixin<
const lists = this.getScriptBBoxLists();
this.combineBBoxLists(data.sub, data.sup, lists.subList, lists.supList);
this.combineBBoxLists(data.psub, data.psup, lists.psubList, lists.psupList);
this.scriptData.base = lists.base[0];
data.base = lists.base[0];
//
// Save the lengths and return the data
//
this.scriptData.numPrescripts = lists.psubList.length;
this.scriptData.numScripts = lists.subList.length;
return this.scriptData;
data.numPrescripts = lists.psubList.length;
data.numScripts = lists.subList.length;
}

/**
Expand Down Expand Up @@ -314,24 +315,24 @@ export function CommonMmultiscriptsMixin<
/**
* @override
*/
public getUVQ(basebox: BBox, subbox: BBox, supbox: BBox) {
public getUVQ(subbox: BBox, supbox: BBox) {
if (!this.UVQ) {
let [u, v, q] = [0, 0, 0];
if (subbox.h === 0 && subbox.d === 0) {
//
// Use placement for superscript only
//
u = this.getU(basebox, supbox);
u = this.getU();
} else if (supbox.h === 0 && supbox.d === 0) {
//
// Use placement for subsccript only
//
u = -this.getV(basebox, subbox);
u = -this.getV();
} else {
//
// Use placement for both
//
[u, v, q] = super.getUVQ(basebox, subbox, supbox);
[u, v, q] = super.getUVQ(subbox, supbox);
}
this.UVQ = [u, v, q];
}
Expand Down
37 changes: 19 additions & 18 deletions ts/output/common/Wrappers/msubsup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function CommonMsubMixin<
/**
* @override
*/
public get script() {
public get scriptChild() {
return this.childNodes[(this.node as MmlMsub).sub];
}

Expand All @@ -69,8 +69,8 @@ export function CommonMsubMixin<
*
* @override
*/
public getOffset(bbox: BBox, sbox: BBox) {
return [0, -this.getV(bbox, sbox)];
public getOffset() {
return [0, -this.getV()];
}

};
Expand Down Expand Up @@ -103,14 +103,14 @@ export type MsupConstructor<W extends AnyWrapper> = Constructor<CommonMsup<W>>;
export function CommonMsupMixin<
W extends AnyWrapper,
T extends ScriptbaseConstructor<W>
>(Base: T): MsubConstructor<W> & T {
>(Base: T): MsupConstructor<W> & T {

return class extends Base {

/**
* @override
*/
public get script() {
public get scriptChild() {
return this.childNodes[(this.node as MmlMsup).sup];
}

Expand All @@ -119,9 +119,9 @@ export function CommonMsupMixin<
*
* @override
*/
public getOffset(bbox: BBox, sbox: BBox) {
public getOffset() {
const x = (this.baseCore.bbox.ic ? .05 * this.baseCore.bbox.ic + .05 : 0);
return [x * this.coreScale(), this.getU(bbox, sbox)];
return [x * this.baseScale, this.getU()];
}

};
Expand Down Expand Up @@ -155,12 +155,11 @@ export interface CommonMsubsup<W extends AnyWrapper> extends CommonScriptbase<W>
/**
* Get the shift for the scripts and their separation (TeXBook Appendix G 18adef)
*
* @param {BBox} basebox The bounding box of the base
* @param {BBox} subbox The bounding box of the superscript
* @param {BBox} supbox The bounding box of the subscript
* @return {number[]} The vertical offsets for super and subscripts, and the space between them
*/
getUVQ(basebox: BBox, subbox: BBox, supbox: BBox): number[];
getUVQ(subbox?: BBox, supbox?: BBox): number[];
}

/**
Expand Down Expand Up @@ -209,15 +208,13 @@ export function CommonMsubsupMixin<
*/
public computeBBox(bbox: BBox, recompute: boolean = false) {
const basebox = this.baseChild.getBBox();
const subbox = this.subChild.getBBox();
const supbox = this.supChild.getBBox();
const [subbox, supbox] = [this.subChild.getBBox(), this.supChild.getBBox()];
bbox.empty();
bbox.append(basebox);
const w = bbox.w;
const [u, v] = this.getUVQ(basebox, subbox, supbox);
const x = (this.baseCore.bbox.ic ? this.coreIC() * this.coreScale() : 0);
const [u, v] = this.getUVQ();
bbox.combine(subbox, w, v);
bbox.combine(supbox, w + x, u);
bbox.combine(supbox, w + this.baseIc, u);
bbox.w += this.font.params.scriptspace;
bbox.clean();
this.setChildPWidths(recompute);
Expand All @@ -226,21 +223,25 @@ export function CommonMsubsupMixin<
/**
* Get the shift for the scripts and their separation (TeXBook Appendix G 18adef)
*
* @param {BBox} basebox The bounding box of the base
* @param {BBox} subbox The bounding box of the superscript
* @param {BBox} supbox The bounding box of the subscript
* @return {number[]} The vertical offsets for super and subscripts, and the space between them
*/
public getUVQ(basebox: BBox, subbox: BBox, supbox: BBox): number[] {
public getUVQ(
subbox: BBox = this.subChild.getBBox(),
supbox: BBox = this.supChild.getBBox()
): number[] {
const basebox = this.baseCore.getBBox();
if (this.UVQ) return this.UVQ;
const tex = this.font.params;
const t = 3 * tex.rule_thickness;
const subscriptshift = this.length2em(this.node.attributes.get('subscriptshift'), tex.sub2);
const drop = (this.isCharBase() ? 0 : basebox.d * basebox.rscale + tex.sub_drop * subbox.rscale);
const scale = this.baseScale;
const drop = (this.baseIsChar && scale === 1 ? 0 : basebox.d * scale + tex.sub_drop * subbox.rscale);
//
// u and v are the veritcal shifts of the scripts, initially set to minimum values and then adjusted
//
let [u, v] = [this.getU(basebox, supbox), Math.max(drop, subscriptshift)];
let [u, v] = [this.getU(), Math.max(drop, subscriptshift)];
//
// q is the space currently between the super- and subscripts.
// If it is less than 3 rule thicknesses,
Expand Down
8 changes: 4 additions & 4 deletions ts/output/common/Wrappers/munderover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function CommonMunderMixin<
/**
* @override
*/
public get script() {
public get scriptChild() {
return this.childNodes[(this.node as MmlMunder).under];
}

Expand All @@ -83,7 +83,7 @@ export function CommonMunderMixin<
}
bbox.empty();
const basebox = this.baseChild.getBBox();
const underbox = this.script.getBBox();
const underbox = this.scriptChild.getBBox();
const v = this.getUnderKV(basebox, underbox)[1];
const delta = this.getDelta(true);
const [bw, uw] = this.getDeltaW([basebox, underbox], [0, -delta]);
Expand Down Expand Up @@ -132,7 +132,7 @@ export function CommonMoverMixin<
/**
* @override
*/
public get script() {
public get scriptChild() {
return this.childNodes[(this.node as MmlMover).over];
}

Expand All @@ -155,7 +155,7 @@ export function CommonMoverMixin<
}
bbox.empty();
const basebox = this.baseChild.getBBox();
const overbox = this.script.getBBox();
const overbox = this.scriptChild.getBBox();
const u = this.getOverKU(basebox, overbox)[1];
const delta = this.getDelta();
const [bw, ow] = this.getDeltaW([basebox, overbox], [0, delta]);
Expand Down
Loading