Skip to content

Commit

Permalink
Add service routine for remapping characters, as per Volker's review
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc committed Aug 17, 2020
1 parent dbf2d68 commit 3a52e89
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
3 changes: 1 addition & 2 deletions ts/output/chtml/Wrappers/TextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ CommonTextNodeMixin<CHTMLConstructor<any, any, any>>(CHTMLWrapper) {
const font = this.jax.getFontData(this.parent.styles);
adaptor.append(parent, this.jax.unknownText(text, variant, font));
} else {
const c = this.parent.stretch.c;
const chars = c ? [c] : this.parent.remapChars(this.unicodeChars(text, variant));
const chars = this.remappedText(text, variant);
for (const n of chars) {
const data = this.getVariantChar(variant, n)[3];
const font = (data.f ? ' TEX-' + data.f : '');
Expand Down
19 changes: 17 additions & 2 deletions ts/output/common/Wrappers/TextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import {TextNode} from '../../../core/MmlTree/MmlNode.js';
* The CommonTextNode interface
*/
export interface CommonTextNode extends AnyWrapper {
/**
* @param {string} text The text to remap
* @param {string} variant The variant for the character
* @return {number[]} The unicode points for the (remapped) text
*/
remappedText(text: string, variant: string): number[];
}

/**
Expand Down Expand Up @@ -63,8 +69,7 @@ export function CommonTextNodeMixin<T extends WrapperConstructor>(Base: T): Text
bbox.d = d;
bbox.w = w;
} else {
const c = this.parent.stretch.c;
const chars = c ? [c] : this.parent.remapChars(this.unicodeChars(text, variant));
const chars = this.remappedText(text, variant);
bbox.empty();
//
// Loop through the characters and add them in one by one
Expand Down Expand Up @@ -96,6 +101,16 @@ export function CommonTextNodeMixin<T extends WrapperConstructor>(Base: T): Text
}
}

/**
* @param {string} text The text to remap
* @param {string} variant The variant for the character
* @return {number[]} The unicode points for the (remapped) text
*/
public remappedText(text: string, variant: string): number[] {
const c = this.parent.stretch.c;
return (c ? [c] : this.parent.remapChars(this.unicodeChars(text, variant)));
}

/******************************************************/
/*
* TextNodes don't need these, since these properties
Expand Down
3 changes: 1 addition & 2 deletions ts/output/svg/Wrappers/TextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ CommonTextNodeMixin<SVGConstructor<any, any, any>>(SVGWrapper) {
if (variant === '-explicitFont') {
this.adaptor.append(parent, this.jax.unknownText(text, variant));
} else {
const c = this.parent.stretch.c;
const chars = c ? [c] : this.parent.remapChars(this.unicodeChars(text, variant));
const chars = this.remappedText(text, variant);
let x = 0;
for (const n of chars) {
x += this.placeChar(n, x, 0, parent, variant);
Expand Down

0 comments on commit 3a52e89

Please sign in to comment.