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

Fix handling of italic correction for munderover and msubsup combinations. #634

Merged
merged 4 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
7 changes: 1 addition & 6 deletions ts/output/chtml/FontData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,19 +364,14 @@ export class CHTMLFontData extends FontData<CHTMLCharOptions, CHTMLVariantData,
* @param {CHTMLCharData} data The bounding box data and options for the character
*/
protected addCharStyles(styles: StyleList, vletter: string, n: number, data: CHTMLCharData) {
const [ , , w, options] = data as [number, number, number, CHTMLCharOptions];
const options = data[3] as CHTMLCharOptions;
if (this.options.adaptiveCSS && !options.used) return;
const letter = (options.f !== undefined ? options.f : vletter);
const selector = 'mjx-c' + this.charSelector(n) + (letter ? '.TEX-' + letter : '');
styles[selector + '::before'] = {
padding: this.padding(data, 0, options.ic || 0),
content: (options.c != null ? '"' + options.c + '"' : this.charContent(n))
};
if (options.ic) {
styles['[noIC] ' + selector + ':last-child::before'] = {
'padding-right': this.em(w)
};
}
}

/***********************************************************************/
Expand Down
10 changes: 0 additions & 10 deletions ts/output/chtml/Wrappers/mi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,4 @@ CommonMiMixin<CHTMLConstructor<any, any, any>>(CHTMLWrapper) {
*/
public static kind = MmlMi.prototype.kind;

/**
* @override
*/
public toCHTML(parent: N) {
super.toCHTML(parent);
if (this.noIC) {
this.adaptor.setAttribute(this.chtml, 'noIC', 'true');
}
}

}
3 changes: 0 additions & 3 deletions ts/output/chtml/Wrappers/mo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ CommonMoMixin<CHTMLConstructor<any, any, any>>(CHTMLWrapper) {
this.getStretchedVariant([]);
}
let chtml = this.standardCHTMLnode(parent);
if (this.noIC) {
this.adaptor.setAttribute(chtml, 'noIC', 'true');
}
if (stretchy && this.size < 0) {
this.stretchHTML(chtml);
} else {
Expand Down
29 changes: 9 additions & 20 deletions ts/output/chtml/Wrappers/msubsup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ CommonMsubMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLscriptbase<any, an
*/
public static kind = MmlMsub.prototype.kind;

/**
* don't include italic correction
*/
public static useIC = false;

}

/*****************************************************************/
Expand All @@ -71,11 +66,6 @@ CommonMsupMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLscriptbase<any, an
*/
public static kind = MmlMsup.prototype.kind;

/**
* Use italic correction
*/
public static useIC = true;

}

/*****************************************************************/
Expand Down Expand Up @@ -108,11 +98,6 @@ CommonMsubsupMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLscriptbase<any,
}
};

/**
* Don't use italic correction
*/
public static useIC = false;

/**
* Make sure styles get output when called from munderover with movable limits
*
Expand All @@ -127,18 +112,22 @@ CommonMsubsupMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLscriptbase<any,
* @override
*/
public toCHTML(parent: N) {
const adaptor = this.adaptor;
const chtml = this.standardCHTMLnode(parent);
const [base, sup, sub] = [this.baseChild, this.supChild, this.subChild];
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;
const stack = 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)}}));
adaptor.append(stack, this.html('mjx-spacer', {style: {'margin-top': this.em(q)}}));
sub.toCHTML(stack);
const corebox = this.baseCore.getBBox();
if (corebox.ic) {
this.adaptor.setStyle(sup.chtml, 'marginLeft', this.em(this.baseIc / sup.bbox.rscale));
const ic = this.getAdjustedIc();
if (ic) {
adaptor.setStyle(sup.chtml, 'marginLeft', this.em(ic / sup.bbox.rscale));
}
if (this.baseRemoveIc) {
adaptor.setStyle(stack, 'marginLeft', this.em(-this.baseIc));
}
}

Expand Down
15 changes: 0 additions & 15 deletions ts/output/chtml/Wrappers/munderover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ CommonMunderMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLmsub<any, any, a
*/
public static kind = MmlMunder.prototype.kind;

/**
* Include italic correction
*/
public static useIC: boolean = true;

/**
* @override
*/
Expand Down Expand Up @@ -118,11 +113,6 @@ CommonMoverMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLmsup<any, any, an
*/
public static kind = MmlMover.prototype.kind;

/**
* Include italic correction
*/
public static useIC: boolean = true;

/**
* @override
*/
Expand Down Expand Up @@ -178,11 +168,6 @@ CommonMunderoverMixin<CHTMLWrapper<any, any, any>, Constructor<CHTMLmsubsup<any,
*/
public static kind = MmlMunderover.prototype.kind;

/**
* Include italic correction
*/
public static useIC: boolean = true;

/**
* @override
*/
Expand Down
10 changes: 3 additions & 7 deletions ts/output/chtml/Wrappers/scriptbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ CommonScriptbaseMixin<CHTMLWrapper<any, any, any>, CHTMLConstructor<any, any, an
*/
public static kind = 'scriptbase';

/**
* Set to true for munderover/munder/mover/msup (Appendix G 13)
*/
public static useIC: boolean = false;

/**
* This gives the common output for msub and msup. It is overridden
* for all the others (msubsup, munder, mover, munderover).
Expand All @@ -61,9 +56,10 @@ CommonScriptbaseMixin<CHTMLWrapper<any, any, any>, CHTMLConstructor<any, any, an
public toCHTML(parent: N) {
this.chtml = this.standardCHTMLnode(parent);
const [x, v] = this.getOffset();
const dx = x - (this.baseRemoveIc ? this.baseIc : 0);
const style: StyleData = {'vertical-align': this.em(v)};
if (x) {
style['margin-left'] = this.em(x);
if (dx) {
style['margin-left'] = this.em(dx);
}
this.baseChild.toCHTML(this.chtml);
this.scriptChild.toCHTML(this.adaptor.append(this.chtml, this.html('mjx-script', {style})) as N);
Expand Down
12 changes: 0 additions & 12 deletions ts/output/common/Wrappers/mi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ import {BBox} from '../../../util/BBox.js';
* The CommonMi interface
*/
export interface CommonMi extends AnyWrapper {
/**
* True if no italic correction should be used
*/
noIC: boolean;
}

/**
Expand All @@ -50,20 +46,12 @@ export function CommonMiMixin<T extends WrapperConstructor>(Base: T): MiConstruc

return class extends Base {

/**
* True if no italic correction should be used
*/
public noIC: boolean = false;

/**
* @override
*/
public computeBBox(bbox: BBox, _recompute: boolean = false) {
super.computeBBox(bbox);
this.copySkewIC(bbox);
if (this.noIC) {
bbox.w -= bbox.ic;
}
}
};

Expand Down
12 changes: 0 additions & 12 deletions ts/output/common/Wrappers/mo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ export const DirectionVH: {[n: number]: string} = {
* The CommonMo interface
*/
export interface CommonMo extends AnyWrapper {
/**
* True if no italic correction should be used
*/
noIC: boolean;

/**
* The font size that a stretched operator uses.
Expand Down Expand Up @@ -127,11 +123,6 @@ export function CommonMoMixin<T extends WrapperConstructor>(Base: T): MoConstruc

return class extends Base {

/**
* True if no italic correction should be used
*/
public noIC: boolean = false;

/**
* The font size that a stretched operator uses.
* If -1, then stretch arbitrarily, and bbox gives the actual height, depth, width
Expand Down Expand Up @@ -181,9 +172,6 @@ export function CommonMoMixin<T extends WrapperConstructor>(Base: T): MoConstruc
if (stretchy && this.size < 0) return;
super.computeBBox(bbox);
this.copySkewIC(bbox);
if (this.noIC) {
bbox.w -= bbox.ic;
}
}

/**
Expand Down
22 changes: 16 additions & 6 deletions ts/output/common/Wrappers/msubsup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export function CommonMsubMixin<

return class extends Base {

/**
* Do not include italic correction
*/
public static useIC: boolean = false;

/**
* @override
*/
Expand Down Expand Up @@ -120,8 +125,8 @@ export function CommonMsupMixin<
* @override
*/
public getOffset() {
const x = (this.baseCore.bbox.ic ? .05 * this.baseCore.bbox.ic + .05 : 0);
return [x * this.baseScale, this.getU()];
const x = this.getAdjustedIc() - (this.baseRemoveIc ? 0 : this.baseIc);
return [x, this.getU()];
}

};
Expand Down Expand Up @@ -183,6 +188,11 @@ export function CommonMsubsupMixin<

return class extends Base {

/**
* Do not include italic correction
*/
public static useIC: boolean = false;

/**
* Cached values for the script offsets and separation (so if they are
* computed in computeBBox(), they don't have to be recomputed during output)
Expand Down Expand Up @@ -211,10 +221,11 @@ export function CommonMsubsupMixin<
const [subbox, supbox] = [this.subChild.getBBox(), this.supChild.getBBox()];
bbox.empty();
bbox.append(basebox);
const w = bbox.w;
const w = this.getBaseWidth();
const x = this.getAdjustedIc();
const [u, v] = this.getUVQ();
bbox.combine(subbox, w, v);
bbox.combine(supbox, w + this.baseIc, u);
bbox.combine(supbox, w + x, u);
bbox.w += this.font.params.scriptspace;
bbox.clean();
this.setChildPWidths(recompute);
Expand All @@ -236,8 +247,7 @@ export function CommonMsubsupMixin<
const tex = this.font.params;
const t = 3 * tex.rule_thickness;
const subscriptshift = this.length2em(this.node.attributes.get('subscriptshift'), tex.sub2);
const scale = this.baseScale;
const drop = (this.baseIsChar && scale === 1 ? 0 : basebox.d * scale + tex.sub_drop * subbox.rscale);
const drop = this.baseCharZero(basebox.d * this.baseScale + tex.sub_drop * subbox.rscale);
//
// u and v are the veritcal shifts of the scripts, initially set to minimum values and then adjusted
//
Expand Down
5 changes: 0 additions & 5 deletions ts/output/common/Wrappers/munderover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import {AnyWrapper, Constructor} from '../Wrapper.js';
import {CommonScriptbase, ScriptbaseConstructor} from './scriptbase.js';
import {MmlMunderover, MmlMunder, MmlMover} from '../../../core/MmlTree/MmlNodes/munderover.js';
import {CommonMo} from './mo.js';
import {BBox} from '../../../util/BBox.js';

/*****************************************************************/
Expand Down Expand Up @@ -142,10 +141,6 @@ export function CommonMoverMixin<
*/
constructor(...args: any[]) {
super(...args);
if (this.baseCore && 'noIC' in this.baseCore && this.isCharBase() &&
this.scriptChild.node.getProperty('mathaccent')) {
(this.baseCore as undefined as CommonMo).noIC = true;
}
this.stretchChildren();
}

Expand Down
Loading