2424import { FontData , DelimiterData , CharData , CharOptions , DelimiterMap , CharMapMap , CSS , V , H } from '../FontData.js' ;
2525import { StyleList , StyleData } from '../CssStyles.js' ;
2626import { em } from '../../../util/lengths.js' ;
27+ import { OptionList , defaultOptions , userOptions } from '../../../util/Options.js' ;
2728import { StringMap } from '../Wrapper.js' ;
2829import { DIRECTION } from '../FontData.js' ;
2930
@@ -59,6 +60,14 @@ import {delimiters} from './tex/delimiters.js';
5960 * The TeXFont class
6061 */
6162export 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 ( / % % U R L % % / , url ) ;
425+ styles [ name ] = font ;
426+ }
377427 }
378428
379429 /*
0 commit comments