feature-detection-operators.js (3724B)
1 // This is a helper for MathML feature detection. 2 // It is indented to be used to prevent false negative test results. 3 // This adds operator-specific feature detections. 4 5 Object.assign(MathMLFeatureDetection, { 6 "has_operator_lspace/rspace": async function() { 7 return this.has_operator_spacing(); 8 }, 9 10 "has_operator_movablelimits": async function() { 11 return this.has_movablelimits(); 12 }, 13 14 "has_operator_largeop": async function() { 15 if (!this.hasOwnProperty("_has_operator_largeop")) { 16 document.body.insertAdjacentHTML("beforeend", "\ 17 <math style='font: 10px HasOperatorLargeopTestFont;'\ 18 displaystyle='true'>\ 19 <mo largeop='false' stretchy='false' symmetric='false'>⫿</mo>\ 20 <mo largeop='true' stretchy='false' symmetric='false'>⫿</mo>\ 21 </math>"); 22 let font_face = new FontFace('HasOperatorLargeopTestFont', 23 'url(/fonts/math/largeop-displayoperatorminheight5000.woff)'); 24 document.fonts.add(font_face); 25 await font_face.load(); 26 var math = document.body.lastElementChild; 27 var mo = math.getElementsByTagName("mo"); 28 this._has_operator_largeop = 29 (mo[1].getBoundingClientRect().height > 30 mo[0].getBoundingClientRect().height); 31 document.body.removeChild(math); 32 document.fonts.delete(font_face); 33 } 34 return this._has_operator_largeop; 35 }, 36 37 "has_operator_stretchy": async function() { 38 if (!this.hasOwnProperty("_has_operator_stretchy")) { 39 document.body.insertAdjacentHTML("beforeend", "\ 40 <math style='font: 10px HasOperatorStretchyTestFont;'>\ 41 <mrow>\ 42 <mo stretchy='false' largeop='false' symmetric='false'>⫿</mo>\ 43 <mo stretchy='true' largeop='false' symmetric='false'>⫿</mo>\ 44 <mspace style='background: black;' width='1px' height='2em'></mspace>\ 45 </mrow>\ 46 </math>"); 47 let font_face = new FontFace('HasOperatorLargeopTestFont', 48 'url(/fonts/math/largeop-displayoperatorminheight5000.woff)'); 49 document.fonts.add(font_face); 50 await font_face.load(); 51 var math = document.body.lastElementChild; 52 var mo = math.getElementsByTagName("mo"); 53 this._has_operator_stretchy = 54 (mo[1].getBoundingClientRect().height > 55 mo[0].getBoundingClientRect().height); 56 document.body.removeChild(math); 57 document.fonts.delete(font_face); 58 } 59 return this._has_operator_stretchy; 60 }, 61 62 "has_operator_symmetric": async function() { 63 if (!this.hasOwnProperty("_has_operator_symmetric")) { 64 document.body.insertAdjacentHTML("beforeend", "\ 65 <math style='font: 10px HasOperatorSymmetricTestFont;'>\ 66 <mrow>\ 67 <mo stretchy='true' largeop='false' symmetric='false'>⫿</mo>\ 68 <mo stretchy='true' largeop='false' symmetric='true'>⫿</mo>\ 69 <mspace style='background: black;' width='1px' height='2em'></mspace>\ 70 </mrow>\ 71 </math>"); 72 let font_face = new FontFace('HasOperatorLargeopTestFont', 73 'url(/fonts/math/largeop-displayoperatorminheight5000.woff)'); 74 document.fonts.add(font_face); 75 await font_face.load(); 76 var math = document.body.lastElementChild; 77 var mo = math.getElementsByTagName("mo"); 78 this._has_operator_symmetric = 79 (mo[1].getBoundingClientRect().height > 80 mo[0].getBoundingClientRect().height); 81 document.body.removeChild(math); 82 document.fonts.delete(font_face); 83 } 84 return this._has_operator_symmetric; 85 }, 86 });