Skip to content

Commit 0be8ee6

Browse files
committed
Merge branch 'config-font-url' into alpha
2 parents 6d911de + f3a7e5d commit 0be8ee6

File tree

2 files changed

+78
-27
lines changed

2 files changed

+78
-27
lines changed

mathjax3-ts/output/chtml.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
import {AbstractOutputJax} from '../core/OutputJax.js';
25-
import {OptionList} from '../util/Options.js';
25+
import {OptionList, separateOptions} from '../util/Options.js';
2626
import {MathDocument} from '../core/MathDocument.js';
2727
import {MathItem} from '../core/MathItem.js';
2828
import {MmlNode} from '../core/MmlTree/MmlNode.js';
@@ -73,7 +73,7 @@ export class CHTML extends AbstractOutputJax {
7373
* wrapper nodes for them (used by functions like core() to locate the wrappers
7474
* from the core nodes)
7575
*/
76-
public nodeMap: Map<MmlNode, CHTMLWrapper> = null;
76+
public nodeMap: Map<MmlNode, CHTMLWrapper>;
7777

7878
/*
7979
* Get the WrapperFactory and connect it to this output jax
@@ -83,12 +83,13 @@ export class CHTML extends AbstractOutputJax {
8383
* @constructor
8484
*/
8585
constructor(options: OptionList = null) {
86-
super(options);
86+
const [chtmlOptions, fontOptions] = separateOptions(options, TeXFont.OPTIONS);
87+
super(chtmlOptions);
8788
this.factory = this.options.CHTMLWrapperFactory || new CHTMLWrapperFactory();
8889
this.factory.chtml = this;
8990
this.nodes = new HTMLNodes();
9091
this.cssStyles = this.options.cssStyles || new CssStyles();
91-
this.font = this.options.font || new TeXFont();
92+
this.font = this.options.font || new TeXFont(fontOptions);
9293
}
9394

9495
/*

mathjax3-ts/output/chtml/fonts/tex.ts

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import {FontData, DelimiterData, CharData, CharOptions, DelimiterMap, CharMapMap, CSS, V, H} from '../FontData.js';
2525
import {StyleList, StyleData} from '../CssStyles.js';
2626
import {em} from '../../../util/lengths.js';
27+
import {OptionList, defaultOptions, userOptions} from '../../../util/Options.js';
2728
import {StringMap} from '../Wrapper.js';
2829
import {DIRECTION} from '../FontData.js';
2930

@@ -59,6 +60,14 @@ import {delimiters} from './tex/delimiters.js';
5960
* The TeXFont class
6061
*/
6162
export class TeXFont extends FontData {
63+
64+
/*
65+
* Default options
66+
*/
67+
public static OPTIONS = {
68+
fontURL: 'mathjax2/css/'
69+
};
70+
6271
/*
6372
* Add the extra variants for the TeX fonts
6473
*/
@@ -241,118 +250,136 @@ export class TeXFont extends FontData {
241250

242251
'.MJX-TEX mjx-stretchy-v mjx-c, .MJX-TEX mjx-stretchy-h mjx-c': {
243252
'font-family': 'MJXZERO, MJXTEX, MJXTEX-S4 ! important'
244-
},
253+
}
254+
};
245255

256+
protected static defaultFonts = {
246257
'@font-face /* 0 */': {
247258
'font-family': 'MJXZERO',
248-
src: 'url("mathjax2/css/otf/MathJax_Zero.otf") format("opentype")'
259+
src: 'url("%%URL%%/otf/MathJax_Zero.otf") format("opentype")'
249260
},
250261

251262
'@font-face /* 1 */': {
252263
'font-family': 'MJXTEX',
253-
src: 'url("mathjax2/css/woff/MathJax_Main-Regular.woff") format("woff")'
264+
src: 'url("%%URL%%/woff/MathJax_Main-Regular.woff") format("woff")'
254265
},
255266

256267
'@font-face /* 2 */': {
257268
'font-family': 'MJXTEX-B',
258-
src: 'url("mathjax2/css/woff/MathJax_Main-Bold.woff") format("woff")'
269+
src: 'url("%%URL%%/woff/MathJax_Main-Bold.woff") format("woff")'
259270
},
260271

261272
'@font-face /* 3 */': {
262273
'font-family': 'MJXTEX-MI',
263-
src: 'url("mathjax2/css/woff/MathJax_Main-Italic.woff") format("woff")'
274+
src: 'url("%%URL%%/woff/MathJax_Main-Italic.woff") format("woff")'
264275
},
265276

266277
'@font-face /* 4 */': {
267278
'font-family': 'MJXTEX-I',
268-
src: 'url("mathjax2/css/woff/MathJax_Math-Italic.woff") format("woff")'
279+
src: 'url("%%URL%%/woff/MathJax_Math-Italic.woff") format("woff")'
269280
},
270281

271282
'@font-face /* 5 */': {
272283
'font-family': 'MJXTEX-BI',
273-
src: 'url("mathjax2/css/woff/MathJax_Math-BoldItalic.woff") format("woff")'
284+
src: 'url("%%URL%%/woff/MathJax_Math-BoldItalic.woff") format("woff")'
274285
},
275286

276287
'@font-face /* 6 */': {
277288
'font-family': 'MJXTEX-S1',
278-
src: 'url("mathjax2/css/woff/MathJax_Size1-Regular.woff") format("woff")'
289+
src: 'url("%%URL%%/woff/MathJax_Size1-Regular.woff") format("woff")'
279290
},
280291

281292
'@font-face /* 7 */': {
282293
'font-family': 'MJXTEX-S2',
283-
src: 'url("mathjax2/css/woff/MathJax_Size2-Regular.woff") format("woff")'
294+
src: 'url("%%URL%%/woff/MathJax_Size2-Regular.woff") format("woff")'
284295
},
285296

286297
'@font-face /* 8 */': {
287298
'font-family': 'MJXTEX-S3',
288-
src: 'url("mathjax2/css/woff/MathJax_Size3-Regular.woff") format("woff")'
299+
src: 'url("%%URL%%/woff/MathJax_Size3-Regular.woff") format("woff")'
289300
},
290301

291302
'@font-face /* 9 */': {
292303
'font-family': 'MJXTEX-S4',
293-
src: 'url("mathjax2/css/woff/MathJax_Size4-Regular.woff") format("woff")'
304+
src: 'url("%%URL%%/woff/MathJax_Size4-Regular.woff") format("woff")'
294305
},
295306

296307
'@font-face /* 10 */': {
297308
'font-family': 'MJXTEX-A',
298-
src: 'url("mathjax2/css/woff/MathJax_AMS-Regular.woff") format("woff")'
309+
src: 'url("%%URL%%/woff/MathJax_AMS-Regular.woff") format("woff")'
299310
},
300311

301312
'@font-face /* 11 */': {
302313
'font-family': 'MJXTEX-C',
303-
src: 'url("mathjax2/css/woff/MathJax_Caligraphic-Regular.woff") format("woff")'
314+
src: 'url("%%URL%%/woff/MathJax_Caligraphic-Regular.woff") format("woff")'
304315
},
305316

306317
'@font-face /* 12 */': {
307318
'font-family': 'MJXTEX-C-B',
308-
src: 'url("mathjax2/css/woff/MathJax_Caligraphic-Bold.woff") format("woff")'
319+
src: 'url("%%URL%%/woff/MathJax_Caligraphic-Bold.woff") format("woff")'
309320
},
310321

311322
'@font-face /* 13 */': {
312323
'font-family': 'MJXTEX-FR',
313-
src: 'url("mathjax2/css/woff/MathJax_Fraktur-Regular.woff") format("woff")'
324+
src: 'url("%%URL%%/woff/MathJax_Fraktur-Regular.woff") format("woff")'
314325
},
315326

316327
'@font-face /* 14 */': {
317328
'font-family': 'MJXTEX-FR-B',
318-
src: 'url("mathjax2/css/woff/MathJax_Fraktur-Bold.woff") format("woff")'
329+
src: 'url("%%URL%%/woff/MathJax_Fraktur-Bold.woff") format("woff")'
319330
},
320331

321332
'@font-face /* 15 */': {
322333
'font-family': 'MJXTEX-SS',
323-
src: 'url("mathjax2/css/woff/MathJax_SansSerif-Regular.woff") format("woff")'
334+
src: 'url("%%URL%%/woff/MathJax_SansSerif-Regular.woff") format("woff")'
324335
},
325336

326337
'@font-face /* 16 */': {
327338
'font-family': 'MJXTEX-SS-B',
328-
src: 'url("mathjax2/css/woff/MathJax_SansSerif-Bold.woff") format("woff")'
339+
src: 'url("%%URL%%/woff/MathJax_SansSerif-Bold.woff") format("woff")'
329340
},
330341

331342
'@font-face /* 17 */': {
332343
'font-family': 'MJXTEX-SS-I',
333-
src: 'url("mathjax2/css/woff/MathJax_SansSerif-Italic.woff") format("woff")'
344+
src: 'url("%%URL%%/woff/MathJax_SansSerif-Italic.woff") format("woff")'
334345
},
335346

336347
'@font-face /* 18 */': {
337348
'font-family': 'MJXTEX-SC',
338-
src: 'url("mathjax2/css/woff/MathJax_Script-Regular.woff") format("woff")'
349+
src: 'url("%%URL%%/woff/MathJax_Script-Regular.woff") format("woff")'
339350
},
340351

341352
'@font-face /* 19 */': {
342353
'font-family': 'MJXTEX-T',
343-
src: 'url("mathjax2/css/woff/MathJax_Typewriter-Regular.woff") format("woff")'
354+
src: 'url("%%URL%%/woff/MathJax_Typewriter-Regular.woff") format("woff")'
344355
},
345356
};
346357

358+
protected options: OptionList;
359+
360+
/*
361+
* @override
362+
*/
363+
constructor(options: OptionList = null) {
364+
super();
365+
let CLASS = this.constructor as typeof TeXFont;
366+
this.options = userOptions(defaultOptions({}, CLASS.OPTIONS), options);
367+
}
368+
347369
/*
348370
* @return{StyleList} The (computed) styles for this font
349371
* (could be used to limit styles to those actually used, for example)
350372
*/
351373
get styles() {
374+
const CLASS = this.constructor as typeof TeXFont;
352375
//
353376
// Include the default styles
354377
//
355-
let styles: StyleList = {...(this.constructor as typeof TeXFont).defaultStyles};
378+
let styles: StyleList = {...CLASS.defaultStyles};
379+
//
380+
// Add fonts with proper URL
381+
//
382+
this.addFontURLs(styles, CLASS.defaultFonts, this.options.fontURL);
356383
//
357384
// Create styles needed for the delimiters
358385
//
@@ -363,6 +390,17 @@ export class TeXFont extends FontData {
363390
//
364391
// Create styles needed for the characters in each variant
365392
//
393+
this.addVariantChars(styles);
394+
//
395+
// Return the final style sheet
396+
//
397+
return styles;
398+
}
399+
400+
/*
401+
* @param{StyleList} styles The style list to add characters to
402+
*/
403+
protected addVariantChars(styles: StyleList) {
366404
for (const name of Object.keys(this.variant)) {
367405
const variant = this.variant[name];
368406
const vclass = (name === 'normal' ? '' : ' .' + variant.classes.replace(/ /g, '.'));
@@ -373,7 +411,19 @@ export class TeXFont extends FontData {
373411
}
374412
}
375413
}
376-
return styles;
414+
}
415+
416+
/*
417+
* @param{StyleList} styles The style object to add styles to
418+
* @param{StyleList} fonts The default font-face directives with %%URL%% where the url should go
419+
* @param{string} url The actual URL to insert into the src strings
420+
*/
421+
protected addFontURLs(styles: StyleList, fonts: StyleList, url: string) {
422+
for (const name of Object.keys(fonts)) {
423+
const font = {...fonts[name]};
424+
font.src = (font.src as string).replace(/%%URL%%/,url);
425+
styles[name] = font;
426+
}
377427
}
378428

379429
/*

0 commit comments

Comments
 (0)