From 7a531fe9f2c003e470f9b0a612eff3957c9b5a02 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 5 May 2021 20:35:19 -0400 Subject: [PATCH 1/2] Add support for shifting combining-character accents into place --- ts/output/common/FontData.ts | 1 + ts/output/common/Wrapper.ts | 5 +++-- ts/output/common/Wrappers/TextNode.ts | 1 + ts/output/common/Wrappers/scriptbase.ts | 3 ++- ts/util/BBox.ts | 3 ++- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ts/output/common/FontData.ts b/ts/output/common/FontData.ts index 21ae2b263..29104c962 100644 --- a/ts/output/common/FontData.ts +++ b/ts/output/common/FontData.ts @@ -33,6 +33,7 @@ import {StyleList} from '../../util/StyleList.js'; export interface CharOptions { ic?: number; // italic correction value sk?: number; // skew value + dx?: number; // offset for combining characters unknown?: boolean; // true if not found in the given variant smp?: number; // Math Alphanumeric codepoint this char is mapped to } diff --git a/ts/output/common/Wrapper.ts b/ts/output/common/Wrapper.ts index 8d718fc35..dd606acde 100644 --- a/ts/output/common/Wrapper.ts +++ b/ts/output/common/Wrapper.ts @@ -375,8 +375,9 @@ export class CommonWrapper< */ protected copySkewIC(bbox: BBox) { const first = this.childNodes[0]; - if (first && first.bbox.sk) { - bbox.sk = first.bbox.sk; + if (first) { + first.bbox.sk && (bbox.sk = first.bbox.sk); + first.bbox.dx && (bbox.dx = first.bbox.dx); } const last = this.childNodes[this.childNodes.length - 1]; if (last && last.bbox.ic) { diff --git a/ts/output/common/Wrappers/TextNode.ts b/ts/output/common/Wrappers/TextNode.ts index 67a26d543..f7cad70e1 100644 --- a/ts/output/common/Wrappers/TextNode.ts +++ b/ts/output/common/Wrappers/TextNode.ts @@ -93,6 +93,7 @@ export function CommonTextNodeMixin(Base: T): Text if (d > bbox.d) bbox.d = d; bbox.ic = data.ic || 0; bbox.sk = data.sk || 0; + bbox.dx = data.dx || 0; } if (chars.length > 1) { bbox.sk = 0; diff --git a/ts/output/common/Wrappers/scriptbase.ts b/ts/output/common/Wrappers/scriptbase.ts index 5abf91faf..1f5b685f3 100644 --- a/ts/output/common/Wrappers/scriptbase.ts +++ b/ts/output/common/Wrappers/scriptbase.ts @@ -635,7 +635,7 @@ export function CommonScriptbaseMixin< const widths = boxes.map(box => box.w * box.rscale); widths[0] -= (this.baseRemoveIc && !this.baseCore.node.attributes.get('largeop') ? this.baseIc : 0); const w = Math.max(...widths); - const dw = []; + const dw = [] as number[]; let m = 0; for (const i of widths.keys()) { dw[i] = (align === 'center' ? (w - widths[i]) / 2 : @@ -649,6 +649,7 @@ export function CommonScriptbaseMixin< dw[i] += m; } } + [1, 2].map(i => dw[i] += (boxes[i] ? boxes[i].dx * boxes[0].scale : 0)); return dw; } diff --git a/ts/util/BBox.ts b/ts/util/BBox.ts index 73d7a6065..4d16b6d68 100644 --- a/ts/util/BBox.ts +++ b/ts/util/BBox.ts @@ -71,6 +71,7 @@ export class BBox { public pwidth: string; // percentage width (for tables) public ic: number; // italic correction public sk: number; // skew + public dx: number; // offset for combining characters as accents /* tslint:enable */ /** @@ -96,7 +97,7 @@ export class BBox { this.w = def.w || 0; this.h = ('h' in def ? def.h : -BIGDIMEN); this.d = ('d' in def ? def.d : -BIGDIMEN); - this.L = this.R = this.ic = this.sk = 0; + this.L = this.R = this.ic = this.sk = this.dx = 0; this.scale = this.rscale = 1; this.pwidth = ''; } From 4b7cbdc65f358114863044b2ff1fd25de26c9658 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Mon, 24 May 2021 11:53:01 -0400 Subject: [PATCH 2/2] Use ?. operation rather than && test, as per review --- ts/output/common/Wrapper.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ts/output/common/Wrapper.ts b/ts/output/common/Wrapper.ts index dd606acde..219c28844 100644 --- a/ts/output/common/Wrapper.ts +++ b/ts/output/common/Wrapper.ts @@ -375,12 +375,14 @@ export class CommonWrapper< */ protected copySkewIC(bbox: BBox) { const first = this.childNodes[0]; - if (first) { - first.bbox.sk && (bbox.sk = first.bbox.sk); - first.bbox.dx && (bbox.dx = first.bbox.dx); + if (first?.bbox.sk) { + bbox.sk = first.bbox.sk; + } + if (first?.bbox.dx) { + bbox.dx = first.bbox.dx; } const last = this.childNodes[this.childNodes.length - 1]; - if (last && last.bbox.ic) { + if (last?.bbox.ic) { bbox.ic = last.bbox.ic; bbox.w += bbox.ic; }