-
Notifications
You must be signed in to change notification settings - Fork 235
Fix several issues with multi-character stretchy assemblies. (mathjax/MathJax#3528, mathjax/MathJax#3531) #1441
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,8 @@ import { | |
| SvgDelimiterData, | ||
| SvgFontData, | ||
| SvgFontDataClass, | ||
| VFUZZ, | ||
| HFUZZ, | ||
| } from '../FontData.js'; | ||
| import { | ||
| CommonMo, | ||
|
|
@@ -41,11 +43,6 @@ import { MmlMo } from '../../../core/MmlTree/MmlNodes/mo.js'; | |
| import { BBox } from '../../../util/BBox.js'; | ||
| import { DIRECTION, SvgCharData } from '../FontData.js'; | ||
|
|
||
| /*****************************************************************/ | ||
|
|
||
| const VFUZZ = 0.1; // overlap for vertical stretchy glyphs | ||
| const HFUZZ = 0.1; // overlap for horizontal stretchy glyphs | ||
|
|
||
| /*****************************************************************/ | ||
| /** | ||
| * The SvgMo interface for the SVG Mo wrapper | ||
|
|
@@ -269,7 +266,7 @@ export const SvgMo = (function <N, T, D>(): SvgMoClass<N, T, D> { | |
| /** | ||
| * @param {number} n The number of the character to look up | ||
| * @param {string} variant The variant for the character to look up | ||
| * @returns {SvgCharData} The full CharData object, with CharOptions guaranteed to be defined | ||
| * @returns {SvgCharData} The full CharData object, with CharOptions guaranteed to be defined | ||
| */ | ||
| protected getChar(n: number, variant: string): SvgCharData { | ||
| const char = this.font.getChar(variant, n) || [0, 0, 0, null]; | ||
|
|
@@ -287,7 +284,7 @@ export const SvgMo = (function <N, T, D>(): SvgMoClass<N, T, D> { | |
| * @param {number} x The x position of the glyph | ||
| * @param {number} y The y position of the glyph | ||
| * @param {N} parent The container for the glyph | ||
| * @returns {number} The width of the character placed | ||
| * @returns {number} The width of the character placed | ||
| */ | ||
| protected addGlyph( | ||
| n: number, | ||
|
|
@@ -315,7 +312,7 @@ export const SvgMo = (function <N, T, D>(): SvgMoClass<N, T, D> { | |
| * @param {string} v The variant for the top glyph | ||
| * @param {number} H The height of the stretched delimiter | ||
| * @param {number} W The width of the stretched delimiter | ||
| * @returns {number} The total height of the top glyph | ||
| * @returns {number} The total height of the top glyph | ||
| */ | ||
| protected addTop(n: number, v: string, H: number, W: number): number { | ||
| if (!n) return 0; | ||
|
|
@@ -333,27 +330,40 @@ export const SvgMo = (function <N, T, D>(): SvgMoClass<N, T, D> { | |
| * @param {number} B The height of the bottom glyph in the delimiter | ||
| * @param {number} W The width of the stretched delimiter | ||
| */ | ||
| /* prettier-ignore */ | ||
| protected addExtV(n: number, v: string, H: number, D: number, T: number, B: number, W: number) { | ||
| protected addExtV( | ||
| n: number, | ||
| v: string, | ||
| H: number, | ||
| D: number, | ||
| T: number, | ||
| B: number, | ||
| W: number | ||
| ) { | ||
| if (!n) return; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
| T = Math.max(0, T - VFUZZ); // A little overlap on top | ||
| B = Math.max(0, B - VFUZZ); // A little overlap on bottom | ||
| T = Math.max(0, T - VFUZZ); // A little overlap on top | ||
| B = Math.max(0, B - VFUZZ); // A little overlap on bottom | ||
| const adaptor = this.adaptor; | ||
| const [h, d, w] = this.getChar(n, v); | ||
| const Y = H + D - T - B; // The height of the extender | ||
| const s = 1.5 * Y / (h + d); // Scale height by 1.5 to avoid bad ends | ||
| // (glyphs with rounded or anti-aliased ends don't stretch well, | ||
| // so this makes for sharper ends) | ||
| const y = (s * (h - d) - Y) / 2; // The bottom point to clip the extender | ||
| const Y = H + D - T - B; // The height of the extender | ||
| const s = (1.5 * Y) / (h + d); // Scale height by 1.5 to avoid bad ends | ||
| // (glyphs with rounded or anti-aliased ends don't stretch well, | ||
| // so this makes for sharper ends) | ||
| const y = (s * (h - d) - Y) / 2; // The bottom point to clip the extender | ||
| if (Y <= 0) return; | ||
| const svg = this.svg('svg', { | ||
| width: this.fixed(w), height: this.fixed(Y), | ||
| y: this.fixed(B - D), x: this.fixed((W - w) / 2), | ||
| viewBox: [0, y, w, Y].map(x => this.fixed(x)).join(' ') | ||
| width: this.fixed(w), | ||
| height: this.fixed(Y), | ||
| y: this.fixed(B - D), | ||
| x: this.fixed((W - w) / 2), | ||
| viewBox: [0, y, w, Y].map((x) => this.fixed(x)).join(' '), | ||
| }); | ||
| this.addGlyph(n, v, 0, 0, svg); | ||
| const glyph = adaptor.lastChild(svg); | ||
| adaptor.setAttribute(glyph as N, 'transform', `scale(1,${this.jax.fixed(s)})`); | ||
| adaptor.setAttribute( | ||
| glyph as N, | ||
| 'transform', | ||
| `scale(1,${this.jax.fixed(s)})` | ||
| ); | ||
| if (this.dom[0]) { | ||
| adaptor.append(this.dom[0], svg); | ||
| } | ||
|
|
@@ -367,7 +377,7 @@ export const SvgMo = (function <N, T, D>(): SvgMoClass<N, T, D> { | |
| * @param {string} v The variant for the bottom glyph | ||
| * @param {number} D The depth of the stretched delimiter | ||
| * @param {number} W The width of the stretched delimiter | ||
| * @returns {number} The total height of the bottom glyph | ||
| * @returns {number} The total height of the bottom glyph | ||
| */ | ||
| protected addBot(n: number, v: string, D: number, W: number): number { | ||
| if (!n) return 0; | ||
|
|
@@ -395,7 +405,7 @@ export const SvgMo = (function <N, T, D>(): SvgMoClass<N, T, D> { | |
| /** | ||
| * @param {number} n The character number for the left glyph of the stretchy character | ||
| * @param {string} v The variant for the left glyph | ||
| * @returns {number} The width of the left glyph | ||
| * @returns {number} The width of the left glyph | ||
| */ | ||
| protected addLeft(n: number, v: string): number { | ||
| return n ? this.addGlyph(n, v, 0, 0) : 0; | ||
|
|
@@ -418,14 +428,14 @@ export const SvgMo = (function <N, T, D>(): SvgMoClass<N, T, D> { | |
| x: number = 0 | ||
| ) { | ||
| if (!n) return; | ||
| R = Math.max(0, R - HFUZZ); // A little less than the width of the right glyph | ||
| L = Math.max(0, L - HFUZZ); // A little less than the width of the left glyph | ||
| R = Math.max(0, R - HFUZZ); // A little less than the width of the right glyph | ||
| L = Math.max(0, L - HFUZZ); // A little less than the width of the left glyph | ||
| const adaptor = this.adaptor; | ||
| const [h, d, w] = this.getChar(n, v); | ||
| const X = W - L - R; // The width of the extender | ||
| const Y = h + d + 2 * VFUZZ; // The height (plus some fuzz) of the extender | ||
| const s = 1.5 * (X / w); // Scale the width so that left- and right-bearing won't hurt us | ||
| const D = -(d + VFUZZ); // The bottom position of the glyph | ||
| const X = W - L - R; // The width of the extender | ||
| const Y = h + d + 2 * VFUZZ; // The height (plus some fuzz) of the extender | ||
| const s = 1.5 * (X / w); // Scale the width so that left- and right-bearing won't hurt us | ||
| const D = -(d + VFUZZ); // The bottom position of the glyph | ||
| if (X <= 0) return; | ||
| const svg = this.svg('svg', { | ||
| width: this.fixed(X), | ||
|
|
@@ -453,7 +463,7 @@ export const SvgMo = (function <N, T, D>(): SvgMoClass<N, T, D> { | |
| * @param {number} n The character number for the right glyph of the stretchy character | ||
| * @param {string} v The variant for the right glyph | ||
| * @param {number} W The width of the stretched character | ||
| * @returns {number} The width of the right glyph | ||
| * @returns {number} The width of the right glyph | ||
| */ | ||
| protected addRight(n: number, v: string, W: number): number { | ||
| if (!n) return 0; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prettier-ignorehere was probably a bit overkill at the time. But I don't like the double use of//either.We should just use
prettier-ignore-start|endinstead. See below.