diff --git a/jest.config.js b/jest.config.js index 6418a26..b909a55 100644 --- a/jest.config.js +++ b/jest.config.js @@ -11,6 +11,9 @@ const config = { "external": {} }, testEnvironment: "jsdom", + testEnvironmentOptions: { + url: "https://localhost/src/__tests__/" + }, testPathIgnorePatterns: ["includes", "test-constants", "test-utils"], sandboxInjectedGlobals: [ "Math", diff --git a/scripts/defines/tools-defines.sh b/scripts/defines/tools-defines.sh index 344d9a3..fd66743 100755 --- a/scripts/defines/tools-defines.sh +++ b/scripts/defines/tools-defines.sh @@ -1,3 +1,3 @@ #!/bin/sh export CLOSURE_LATEST="https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/v20231112/closure-compiler-v20231112.jar" #"http://dl.google.com/closure-compiler/compiler-latest.tar.gz" -export NPM_PACKAGES="source-map@latest prettier@latest pretty-quick@latest eslint@latest eslint-config-prettier@latest lint-staged@latest jest@latest jsdom@latest jest-environment-jsdom@latest jsdoc-to-markdown@latest http-server@latest" +export NPM_PACKAGE_JSON='{"devDependencies":{"eslint":"latest","eslint-config-prettier":"latest","http-server":"latest","jest":"latest","jest-environment-jsdom":"latest","jsdoc-to-markdown":"latest","libass-wasm":"latest","lint-staged":"latest","mime":"latest","prettier":"latest","pretty-quick":"latest","source-map":"latest","ssim.js":"latest","node-canvas-webgl":"latest"},"overrides":{"gl@<8.0.2":"8.0.2"}}' diff --git a/scripts/helpers/execute-node.sh b/scripts/helpers/execute-node.sh index af4dc45..b90845c 100755 --- a/scripts/helpers/execute-node.sh +++ b/scripts/helpers/execute-node.sh @@ -4,7 +4,8 @@ if [ ! -d "$TOOL_BIN_DIR/node_tools" ]; then mkdir "$TOOL_BIN_DIR/node_tools" > /dev/null 2>&1 - printf '%s\n' $NPM_PACKAGES | xargs npm install --prefix "$TOOL_BIN_DIR/node_tools" --save-dev --save-exact + printf "%s\n" "$NPM_PACKAGE_JSON" > "$TOOL_BIN_DIR/node_tools/package.json" + npm install --prefix "$TOOL_BIN_DIR/node_tools" --save-dev --save-exact fi NODE_TOOLS_BINDIR="$TOOL_BIN_DIR/node_tools/node_modules/.bin" diff --git a/src/__tests__/parser.test.js b/src/__tests__/parser.test.js index 0d11753..1226f0d 100644 --- a/src/__tests__/parser.test.js +++ b/src/__tests__/parser.test.js @@ -83,10 +83,12 @@ const ssaEventKeys = [ "Text" ]; -const loadFile = (file) => { +const loadFile = (function(){ const { readFileSync } = require('fs'); - return readFileSync(__dirname+"/testfiles/" + file,null); -} + return function(file){ + return readFileSync(__dirname+"/testfiles/" + file,null); + } +})(); describe("Parser", () => { describe("#load",() => { diff --git a/src/__tests__/renderer.test.js b/src/__tests__/renderer.test.js new file mode 100644 index 0000000..946e468 --- /dev/null +++ b/src/__tests__/renderer.test.js @@ -0,0 +1,154 @@ +{ + const { mockDOM } = require('node-canvas-webgl'); + mockDOM(window); +} +global = globalThis; +require('../util.js') +require('../global-constants.js') +require('../color.js'); +require('../style.js'); +require('../lib/codepage.js'); +require('../text-server.js'); +require('../style-override.js'); +require('../subtitle-event.js'); +require("../subtitle-tags.js"); +require("../subtitle-parser.js"); +require("../scheduler.js"); +require("../shader.js"); +require("../font-server.js"); +require("../canvas-2d-text-renderer.js"); +require("../canvas-2d-shape-renderer.js"); +require("../lib/BSpline.js"); +require("../lib/earcut.js"); +require("../renderer-main.js"); + +sabre.getScriptPath = function(){ + return __dirname+"/../"; + }; + +const opentype = require("./test-modules/opentype.compat.min.js"); + +const loadFile = (function(){ + const { readFileSync } = require('fs'); + return function(file){ + return readFileSync(__dirname+"/testfiles/" + file,null); + } +})(); + +const loadFileAsDataURI = (function(file,mime){ + const data = loadFile(file); + return "data:"+mime+";base64,"+data.toString('base64'); +}); + +const compareImages = (function(){ + const compare = require("./test-utils/image-comparison.utils.js"); + return (function(){ + function canvasToImageData(inputCanvas){ + const wantedColorSpace = (window.matchMedia && window.matchMedia("(color-gamut: p3)").matches ? "display-p3" : "srgb"); + if(inputCanvas.width > 0 && inputCanvas.height > 0){ + ctx = inputCanvas.getContext("2d"); + const imageData = ctx.getImageData(0,0,inputCanvas.width,inputCanvas.height,{colorSpace:wantedColorSpace}); + return imageData; + }else{ + throw new Error("Canvas too small to compare."); + } + } + return function(canvas1,canvas2){ + const imageData1 = canvasToImageData(canvas1); + const imageData2 = canvasToImageData(canvas2); + return compare(imageData1,imageData2); + } + })(); +})(); + +describe("Subtitle Renderer", () => { + + describe("Canvas2DTextRenderer", () => { + + }); + + describe("Canvas2DShapeRenderer", () => { + + }); + + describe("Integration Tests", () => { + + const SubtitlesOctopus = require("libass-wasm"); + + const octopus_options_template = Object.freeze({ + workerUrl: require.resolve('libass-wasm/dist/js/subtitles-octopus-worker.js'), + legacyWorkerUrl: require.resolve('libass-wasm/dist/js/subtitles-octopus-worker-legacy.js'), + }); + + let canvas; + let octopus_canvas; + + const fontsList = [ + "fonts/OpenSans-Light.ttf", + "fonts/OpenSans-Regular.ttf", + "fonts/OpenSans-Medium.ttf", + "fonts/OpenSans-SemiBold.ttf", + "fonts/OpenSans-Bold.ttf", + "fonts/OpenSans-ExtraBold.ttf", + "fonts/OpenSans-LightItalic.ttf", + "fonts/OpenSans-Italic.ttf", + "fonts/OpenSans-MediumItalic.ttf", + "fonts/OpenSans-SemiBoldItalic.ttf", + "fonts/OpenSans-BoldItalic.ttf", + "fonts/OpenSans-ExtraBoldItalic.ttf", + "fonts/Rosario-Regular.otf" + ]; + const fontUrls = fontsList.map(font => loadFileAsDataURI(font,(font.endsWith(".otf") ? "font/otf" : "font/ttf"))); + const fonts = fontsList.map(font => opentype.parse(loadFile(font))); + + beforeEach(() => { + canvas = document.createElement('canvas'); + canvas.width = 640; + canvas.height = 480; + + octopus_canvas = document.createElement('canvas'); + octopus_canvas.width = 640; + octopus_canvas.height = 480; + }); + + describe("Basic Tests", () => { + test("Can we initialize the renderer?", () => { + const renderer = external.SABRERenderer({ + fonts: fonts, + subtitles: loadFile("tag_tests.ass"), + colorSpace:external.VideoColorSpaces.AUTOMATIC, + resolution:[640,480], + nativeResolution:[640,480] + }); + expect(renderer.checkReadyToRender()).toBe(true); + }); + }); + /* + describe("Comparison Tests", () => { + let testBuffer; + let testUri; + let sabre, octopus; + + beforeEach(() => { + const octopus_options = Object.freeze(Object.assign({ + subUrl: testUri + },octopus_options_template)); + octopus = new SubtitlesOctopus(octopus_options); + }); + + afterEach(() => { + octopus.dispose(); + }); + + describe("Tag Tests", () => { + beforeAll(() => { + testBuffer = loadFile("./testfiles/tag_tests.ass"); + testUri = loadFile("./testfiles/tag_tests.ass"); + }); + + }); + + }); + */ + }); +}); diff --git a/src/__tests__/test-modules/opentype.compat.min.js b/src/__tests__/test-modules/opentype.compat.min.js new file mode 100644 index 0000000..a3a8910 --- /dev/null +++ b/src/__tests__/test-modules/opentype.compat.min.js @@ -0,0 +1,3 @@ +var opentype=(function(){var fo=Object.create;var Et=Object.defineProperty;var co=Object.getOwnPropertyDescriptor;var vo=Object.getOwnPropertyNames;var go=Object.getPrototypeOf,mo=Object.prototype.hasOwnProperty;var ge=function(e){return typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:function(t,r){return(typeof require!="undefined"?require:t)[r]}}):e}(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var yo=function(e,t){for(var r in t)Et(e,r,{get:t[r],enumerable:!0})},ra=function(e,t,r,a){if(t&&typeof t=="object"||typeof t=="function")for(var n=vo(t),o=0,s=n.length,i;o>>16-t;return e.tag>>>=t,e.bitcount-=t,a+r}function Tr(e,t){for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<>>=1,++n,r+=t.table[n],a-=t.table[n];while(a>=0);return e.tag=o,e.bitcount-=n,t.trans[r+a]}function sa(e,t,r){for(;;){var a,n,o,s,i=Tr(e,t);if(i===256)return 0;if(i<256)e.dest[e.destLen++]=i;else for(i-=257,a=Re(e,Sr[i],br[i]),n=Tr(e,r),s=o=e.destLen-Re(e,la[n],pa[n]);s>>=1,s}(n),Re(n,2,0)){case 0:a=function(o){for(var s,i;o.bitcount>8;)o.sourceIndex--,o.bitcount-=8;if((s=256*(s=o.source[o.sourceIndex+1])+o.source[o.sourceIndex])!==(65535&~(256*o.source[o.sourceIndex+3]+o.source[o.sourceIndex+2])))return-3;for(o.sourceIndex+=4,i=s;i;--i)o.dest[o.destLen++]=o.source[o.sourceIndex++];return o.bitcount=0,0}(n);break;case 1:a=sa(n,ia,ua);break;case 2:(function(o,s,i){for(f=0,u=Re(o,5,257),l=Re(o,5,1),p=Re(o,4,4);f<19;++f)ke[f]=0;for(f=0;fr)n=s-1;else{o=i;break}}return o}function va(e,t,r){for(var a=0,n=e.length-1;a<=n;){var o=Math.floor((a+n)/2),s=e[o];if(s[t]r))return o;n=o-1}}return-1}function ga(e,t,r){for(var a=0,n=e.length;a>>1;0>e[o][t]-r[t]?a=o+1:n=o}return e.splice(a,0,r),a}function Ur(e){return e[0]===31&&e[1]===139&&e[2]===8}function ma(e){var t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=10,a=e.byteLength-8,n=t.getInt8(3);if(4&n&&(r+=2+t.getUint16(r,!0)),8&n||16&n)for(;r=a)throw Error("Can't find compressed blocks");var o=t.getUint32(t.byteLength-4,!0);return wt(e.subarray(r,a),new Uint8Array(o))}function it(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,a=Array(t);rthis.x2&&(this.x2=e)),typeof t=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=t,this.y2=t),tthis.y2&&(this.y2=t))},Ye.prototype.addX=function(e){this.addPoint(e,null)},Ye.prototype.addY=function(e){this.addPoint(null,e)},Ye.prototype.addBezier=function(e,t,r,a,n,o,s,i){var u=[e,t],l=[r,a],p=[n,o],f=[s,i];this.addPoint(e,t),this.addPoint(s,i);for(var c=0;c<=1;c++){var h=6*u[c]-12*l[c]+6*p[c],g=-3*u[c]+9*l[c]-9*p[c]+3*f[c],y=3*l[c]-3*u[c];if(g===0){if(h===0)continue;var x=-y/h;0-1)n[n.length-1]+=l;else if("-+".indexOf(l)>-1)if(a.type||this.commands.length||(a.type="L"),l==="-")!a.type||p.indexOf("-")>0?o=!0:p.length?n.push("-"):n[n.length-1]=l;else{if(a.type&&!(p.length>0))continue;o=!0}else if(r.indexOf(l)>-1)a.type?(i.apply(this),a={type:l}):a.type=l;else{if("SsTtAa".indexOf(l)>-1)throw Error("Unsupported path command: "+l+". Currently supported commands are "+r.split("").join(", ")+".");" , \n\r\f\v".indexOf(l)>-1?n.push(""):l==="."?!a.type||p.indexOf(l)>-1?o=!0:n[n.length-1]+=l:o=!0}if(o)throw Error("Unexpected character: "+l+" at offset "+u)}i.apply(this),t.optimize&&(this.commands=Ua(this.commands));var f=t.flipY,c=t.flipYBase;if(f===!0&&t.flipYBase===void 0){var h=this.getBoundingBox();c=h.y1+h.y2}for(var g in this.commands){var y=this.commands[g];for(var x in y)["x","x1","x2"].includes(x)?this.commands[g][x]=t.x+y[x]*t.scale:["y","y1","y2"].includes(x)&&(this.commands[g][x]=t.y+(f?c-y[x]:y[x])*t.scale)}return this},re.fromSVG=function(e,t){return new re().fromSVG(e,t)},re.prototype.moveTo=function(e,t){this.commands.push({type:"M",x:e,y:t})},re.prototype.lineTo=function(e,t){this.commands.push({type:"L",x:e,y:t})},re.prototype.curveTo=re.prototype.bezierCurveTo=function(e,t,r,a,n,o){this.commands.push({type:"C",x1:e,y1:t,x2:r,y2:a,x:n,y:o})},re.prototype.quadTo=re.prototype.quadraticCurveTo=function(e,t,r,a){this.commands.push({type:"Q",x1:e,y1:t,x:r,y:a})},re.prototype.close=re.prototype.closePath=function(){this.commands.push({type:"Z"})},re.prototype.extend=function(e){if(e.commands)e=e.commands;else if(e instanceof ut){var t=e;this.moveTo(t.x1,t.y1),this.lineTo(t.x2,t.y1),this.lineTo(t.x2,t.y2),this.lineTo(t.x1,t.y2),this.close();return}Array.prototype.push.apply(this.commands,e)},re.prototype.getBoundingBox=function(){for(var e=new ut,t=0,r=0,a=0,n=0,o=0;o=0&&c>0&&(f+=" "),f+=function(g){var y=Ta(g,e.decimalPlaces);return Math.round(g)===y?""+y:y.toFixed(e.decimalPlaces)}(h)}return f}parseInt(r=e)===r&&(r={decimalPlaces:r,flipY:!1}),e=Object.assign({},{decimalPlaces:2,optimize:!0,flipY:!0,flipYBase:void 0},r);var r,a=this.commands;e.optimize&&(a=Ua(a=JSON.parse(JSON.stringify(this.commands))));var n=e.flipY,o=e.flipYBase;if(n===!0&&o===void 0){var s=new re;s.extend(a);var i=s.getBoundingBox();o=i.y1+i.y2}for(var u="",l=0;l=0&&e<=255,"Byte value should be between 0 and 255."),[e]},M.BYTE=me(1),C.CHAR=function(e){return[e.charCodeAt(0)]},M.CHAR=me(1),C.CHARARRAY=function(e){e==null&&(e="",console.warn("CHARARRAY with undefined or null value encountered and treated as an empty string. This is probably caused by a missing glyph name."));for(var t=[],r=0;r>8&255,255&e]},M.USHORT=me(2),C.SHORT=function(e){return e>=32768&&(e=-(65536-e)),[e>>8&255,255&e]},M.SHORT=me(2),C.UINT24=function(e){return[e>>16&255,e>>8&255,255&e]},M.UINT24=me(3),C.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,255&e]},M.ULONG=me(4),C.LONG=function(e){return e>=2147483648&&(e=-(4294967296-e)),[e>>24&255,e>>16&255,e>>8&255,255&e]},M.LONG=me(4),C.FLOAT=function(e){if(e>To||e<-32768)throw Error("Value "+e+" is outside the range of representable values in 16.16 format");return C.ULONG(Math.round(65536*e)<<0)},M.FLOAT=M.ULONG,C.FIXED=C.ULONG,M.FIXED=M.ULONG,C.FWORD=C.SHORT,M.FWORD=M.SHORT,C.UFWORD=C.USHORT,M.UFWORD=M.USHORT,C.F2DOT14=function(e){return C.USHORT(16384*e)},M.F2DOT14=M.USHORT,C.LONGDATETIME=function(e){return[0,0,0,0,e>>24&255,e>>16&255,e>>8&255,255&e]},M.LONGDATETIME=me(8),C.TAG=function(e){return R.argument(e.length===4,"Tag should be exactly 4 ASCII characters."),[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]},M.TAG=me(4),C.Card8=C.BYTE,M.Card8=M.BYTE,C.Card16=C.USHORT,M.Card16=M.USHORT,C.OffSize=C.BYTE,M.OffSize=M.BYTE,C.SID=C.USHORT,M.SID=M.USHORT,C.NUMBER=function(e){return e>=-107&&e<=107?[e+139]:e>=108&&e<=1131?[((e-=108)>>8)+247,255&e]:e>=-1131&&e<=-108?[((e=-e-108)>>8)+251,255&e]:e>=-32768&&e<=32767?C.NUMBER16(e):C.NUMBER32(e)},M.NUMBER=function(e){return C.NUMBER(e).length},C.NUMBER16=function(e){return[28,e>>8&255,255&e]},M.NUMBER16=me(3),C.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,255&e]},M.NUMBER32=me(5),C.REAL=function(e){var t=e.toString(),r=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(t);if(r){var a=parseFloat("1e"+((r[2]?+r[2]:0)+r[1].length));t=(Math.round(e*a)/a).toString()}for(var n="",o=0,s=t.length;o>8&255,t[t.length]=255&a}return t},M.UTF16=function(e){return 2*e.length};var pt={"x-mac-croatian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\u0160\u2122\xB4\xA8\u2260\u017D\xD8\u221E\xB1\u2264\u2265\u2206\xB5\u2202\u2211\u220F\u0161\u222B\xAA\xBA\u03A9\u017E\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u0106\xAB\u010C\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u0110\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\uF8FF\xA9\u2044\u20AC\u2039\u203A\xC6\xBB\u2013\xB7\u201A\u201E\u2030\xC2\u0107\xC1\u010D\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u0111\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u03C0\xCB\u02DA\xB8\xCA\xE6\u02C7","x-mac-cyrillic":"\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041A\u041B\u041C\u041D\u041E\u041F\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E\u042F\u2020\xB0\u0490\xA3\xA7\u2022\xB6\u0406\xAE\xA9\u2122\u0402\u0452\u2260\u0403\u0453\u221E\xB1\u2264\u2265\u0456\xB5\u0491\u0408\u0404\u0454\u0407\u0457\u0409\u0459\u040A\u045A\u0458\u0405\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\u040B\u045B\u040C\u045C\u0455\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u201E\u040E\u045E\u040F\u045F\u2116\u0401\u0451\u044F\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D\u043E\u043F\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E","x-mac-gaelic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u1E02\xB1\u2264\u2265\u1E03\u010A\u010B\u1E0A\u1E0B\u1E1E\u1E1F\u0120\u0121\u1E40\xE6\xF8\u1E41\u1E56\u1E57\u027C\u0192\u017F\u1E60\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\u1E61\u1E9B\xFF\u0178\u1E6A\u20AC\u2039\u203A\u0176\u0177\u1E6B\xB7\u1EF2\u1EF3\u204A\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\u2663\xD2\xDA\xDB\xD9\u0131\xDD\xFD\u0174\u0175\u1E84\u1E85\u1E80\u1E81\u1E82\u1E83","x-mac-greek":"\xC4\xB9\xB2\xC9\xB3\xD6\xDC\u0385\xE0\xE2\xE4\u0384\xA8\xE7\xE9\xE8\xEA\xEB\xA3\u2122\xEE\xEF\u2022\xBD\u2030\xF4\xF6\xA6\u20AC\xF9\xFB\xFC\u2020\u0393\u0394\u0398\u039B\u039E\u03A0\xDF\xAE\xA9\u03A3\u03AA\xA7\u2260\xB0\xB7\u0391\xB1\u2264\u2265\xA5\u0392\u0395\u0396\u0397\u0399\u039A\u039C\u03A6\u03AB\u03A8\u03A9\u03AC\u039D\xAC\u039F\u03A1\u2248\u03A4\xAB\xBB\u2026\xA0\u03A5\u03A7\u0386\u0388\u0153\u2013\u2015\u201C\u201D\u2018\u2019\xF7\u0389\u038A\u038C\u038E\u03AD\u03AE\u03AF\u03CC\u038F\u03CD\u03B1\u03B2\u03C8\u03B4\u03B5\u03C6\u03B3\u03B7\u03B9\u03BE\u03BA\u03BB\u03BC\u03BD\u03BF\u03C0\u03CE\u03C1\u03C3\u03C4\u03B8\u03C9\u03C2\u03C7\u03C5\u03B6\u03CA\u03CB\u0390\u03B0\xAD","x-mac-icelandic":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\xDD\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\xD0\xF0\xDE\xFE\xFD\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-inuit":"\u1403\u1404\u1405\u1406\u140A\u140B\u1431\u1432\u1433\u1434\u1438\u1439\u1449\u144E\u144F\u1450\u1451\u1455\u1456\u1466\u146D\u146E\u146F\u1470\u1472\u1473\u1483\u148B\u148C\u148D\u148E\u1490\u1491\xB0\u14A1\u14A5\u14A6\u2022\xB6\u14A7\xAE\xA9\u2122\u14A8\u14AA\u14AB\u14BB\u14C2\u14C3\u14C4\u14C5\u14C7\u14C8\u14D0\u14EF\u14F0\u14F1\u14F2\u14F4\u14F5\u1505\u14D5\u14D6\u14D7\u14D8\u14DA\u14DB\u14EA\u1528\u1529\u152A\u152B\u152D\u2026\xA0\u152E\u153E\u1555\u1556\u1557\u2013\u2014\u201C\u201D\u2018\u2019\u1558\u1559\u155A\u155D\u1546\u1547\u1548\u1549\u154B\u154C\u1550\u157F\u1580\u1581\u1582\u1583\u1584\u1585\u158F\u1590\u1591\u1592\u1593\u1594\u1595\u1671\u1672\u1673\u1674\u1675\u1676\u1596\u15A0\u15A1\u15A2\u15A3\u15A4\u15A5\u15A6\u157C\u0141\u0142","x-mac-ce":"\xC4\u0100\u0101\xC9\u0104\xD6\xDC\xE1\u0105\u010C\xE4\u010D\u0106\u0107\xE9\u0179\u017A\u010E\xED\u010F\u0112\u0113\u0116\xF3\u0117\xF4\xF6\xF5\xFA\u011A\u011B\xFC\u2020\xB0\u0118\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\u0119\xA8\u2260\u0123\u012E\u012F\u012A\u2264\u2265\u012B\u0136\u2202\u2211\u0142\u013B\u013C\u013D\u013E\u0139\u013A\u0145\u0146\u0143\xAC\u221A\u0144\u0147\u2206\xAB\xBB\u2026\xA0\u0148\u0150\xD5\u0151\u014C\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\u014D\u0154\u0155\u0158\u2039\u203A\u0159\u0156\u0157\u0160\u201A\u201E\u0161\u015A\u015B\xC1\u0164\u0165\xCD\u017D\u017E\u016A\xD3\xD4\u016B\u016E\xDA\u016F\u0170\u0171\u0172\u0173\xDD\xFD\u0137\u017B\u0141\u017C\u0122\u02C7",macintosh:"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\uFB01\uFB02\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-romanian":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\u0102\u0218\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\u0103\u0219\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u2044\u20AC\u2039\u203A\u021A\u021B\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\u0131\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7","x-mac-turkish":"\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC\u2020\xB0\xA2\xA3\xA7\u2022\xB6\xDF\xAE\xA9\u2122\xB4\xA8\u2260\xC6\xD8\u221E\xB1\u2264\u2265\xA5\xB5\u2202\u2211\u220F\u03C0\u222B\xAA\xBA\u03A9\xE6\xF8\xBF\xA1\xAC\u221A\u0192\u2248\u2206\xAB\xBB\u2026\xA0\xC0\xC3\xD5\u0152\u0153\u2013\u2014\u201C\u201D\u2018\u2019\xF7\u25CA\xFF\u0178\u011E\u011F\u0130\u0131\u015E\u015F\u2021\xB7\u201A\u201E\u2030\xC2\xCA\xC1\xCB\xC8\xCD\xCE\xCF\xCC\xD3\xD4\uF8FF\xD2\xDA\xDB\xD9\uF8A0\u02C6\u02DC\xAF\u02D8\u02D9\u02DA\xB8\u02DD\u02DB\u02C7"};Ne.MACSTRING=function(e,t,r,a){var n=pt[a];if(n!==void 0){for(var o="",s=0;s=-128&&e<=127}C.MACSTRING=function(e,t){var r=Uo(t);if(r!==void 0){for(var a=[],n=0;n=128&&(o=r[o])===void 0)return;a[n]=o}return a}},M.MACSTRING=function(e,t){var r=C.MACSTRING(e,t);return r!==void 0?r.length:0},C.VARDELTAS=function(e){for(var t=0,r=[];t=-128&&a<=127?function(n,o,s){for(var i=0,u=n.length,l=o;l>8&255,c+256&255)}return l}(e,t,r)}return r},C.INDEX=function(e){for(var t=1,r=[1],a=[],n=0;n>8,t[c+1]=255&h;for(var g=0;g0)return new v(this.data,this.offset+t).parseStruct(e)},v.prototype.parsePointer32=function(e){var t=this.parseOffset32();if(t>0)return new v(this.data,this.offset+t).parseStruct(e)},v.prototype.parseListOfLists=function(e){for(var t=this.parseOffset16List(),r=t.length,a=this.relativeOffset,n=Array(r),o=0;o=128){var a=this.parseByte();r=(e&se.POINT_RUN_COUNT_MASK)<<8|a}for(var n=0;t.length=0;p-=1)if(s=k.getUShort(e,t+4+8*p),i=k.getUShort(e,t+4+8*p+2),s===3&&l.includes(i)||s===0&&u.includes(i)||s===1&&i===0){if(o>0)continue;if(o=k.getULong(e,t+4+8*p+4),a)break}else if(s===0&&i===5){if(n=k.getULong(e,t+4+8*p+4),(a=new k.Parser(e,t+n)).parseUShort()!==14)n=-1,a=null;else if(o>0)break}if(o===-1)throw Error("No valid cmap sub-tables found.");var f=new k.Parser(e,t+o);if(r.format=f.parseUShort(),r.format===0)Co(r,f,s,i);else if(r.format===12||r.format===13)(function(c,h,g){h.parseUShort(),c.length=h.parseULong(),c.language=h.parseULong(),c.groupCount=y=h.parseULong(),c.glyphIndexMap={};for(var y,x=0;x>1,h.skip("uShort",3),c.glyphIndexMap={};for(var m,d=new k.Parser(g,y+x+14),U=new k.Parser(g,y+x+16+2*m),O=new k.Parser(g,y+x+16+4*m),E=new k.Parser(g,y+x+16+6*m),S=y+x+16+8*m,L=0;L0;O-=1)if(e.get(O).unicode>65535){console.log("Adding CMAP format 12 (needed!)"),t=!1;break}var r=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:t?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:t?12:20}];t||r.push.apply(r,[{name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}]),r.push.apply(r,[{name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);var a=new b.Table("cmap",r);for(O=0,a.segments=[];O1&&R.argument(n,"Can't infer numPaletteEntries on multiple colorRecordIndices"),new b.Table("CPAL",[{name:"version",type:"USHORT",value:r},{name:"numPaletteEntries",type:"USHORT",value:n||s.length},{name:"numPalettes",type:"USHORT",value:u.length},{name:"numColorRecords",type:"USHORT",value:s.length},{name:"colorRecordsArrayOffset",type:"ULONG",value:12+2*u.length}].concat(ae(u.map(function(l,p){return{name:"colorRecordIndices_"+p,type:"USHORT",value:l}})),ae(s.map(function(l,p){return{name:"colorRecords_"+p,type:"ULONG",value:l}}))))}function _a(e){var t=(4278190080&e)>>24,r=(16711680&e)>>16,a=(65280&e)>>8,n=255&e;return{b:t=t+256&255,g:r=r+256&255,r:a=a+256&255,a:n=(n+256&255)/255}}function ct(e,t,r,a){if(r===void 0&&(r=0),a===void 0&&(a="hexa"),t==65535)return"currentColor";var n=e&&e.tables&&e.tables.cpal;if(!n)return"currentColor";if(r>n.colorRecordIndices.length-1)throw Error("Palette index out of range (colorRecordIndices.length: "+n.colorRecordIndices.length+", index: "+t+")");if(t>n.numPaletteEntries)throw Error("Color index out of range (numPaletteEntries: "+n.numPaletteEntries+", index: "+t+")");var o=n.colorRecordIndices[r]+t;if(o>n.colorRecords)throw Error("Color index out of range (colorRecords.length: "+n.colorRecords.length+", lookupIndex: "+o+")");var s=_a(n.colorRecords[o]);return a==="bgra"?s:He(s,a)}function ye(e){return("0"+parseInt(e).toString(16)).slice(-2)}function Ha(e){return parseInt("0x"+ye(e.b)+ye(e.g)+ye(e.r)+ye(255*e.a),16)}function dt(e,t){t===void 0&&(t="hexa");var r=t=="raw"||t=="cpal",a=Number.isInteger(e),n=!0;if(a&&r||e==="currentColor")return e;if(typeof e=="object"){if(t=="bgra")return e;if(r)return Ha(e)}else if(!a&&/^#([a-f0-9]{3}|[a-f0-9]{4}|[a-f0-9]{6}|[a-f0-9]{8})$/i.test(e.trim())){switch((e=e.trim().substring(1)).length){case 3:e={r:parseInt(e[0].repeat(2),16),g:parseInt(e[1].repeat(2),16),b:parseInt(e[2].repeat(2),16),a:1};break;case 4:e={r:parseInt(e[0].repeat(2),16),g:parseInt(e[1].repeat(2),16),b:parseInt(e[2].repeat(2),16),a:parseInt(e[3].repeat(2),16)/255};break;case 6:e={r:parseInt(e[0]+e[1],16),g:parseInt(e[2]+e[3],16),b:parseInt(e[4]+e[5],16),a:1};break;case 8:e={r:parseInt(e[0]+e[1],16),g:parseInt(e[2]+e[3],16),b:parseInt(e[4]+e[5],16),a:parseInt(e[6]+e[7],16)/255}}if(t=="bgra")return e}else if(globalThis.window&&globalThis.window.HTMLCanvasElement&&/^[a-z]+$/i.test(e)){var o=document.createElement("canvas").getContext("2d");o.fillStyle=e;var s=He(o.fillStyle,"hexa");s==="#000000ff"&&e.toLowerCase()!=="black"?n=!1:e=s}else{e=e.trim();var i=/rgba?\(\s*(?:(\d*\.\d+)(%?)|(\d+)(%?))\s*(?:,|\s*)\s*(?:(\d*\.\d+)(%?)|(\d+)(%?))\s*(?:,|\s*)\s*(?:(\d*\.\d+)(%?)|(\d+)(%?))\s*(?:(?:,|\s|\/)\s*(?:(0*(?:\.\d+)?()|0*1(?:\.0+)?())|(?:\.\d+)|(\d+)(%)|(\d*\.\d+)(%)))?\s*\)/;if(i.test(e)){var u=e.match(i).filter(function(S){return S!==void 0});e={r:Math.round(parseFloat(u[1])/(u[2]?100/255:1)),g:Math.round(parseFloat(u[3])/(u[4]?100/255:1)),b:Math.round(parseFloat(u[5])/(u[6]?100/255:1)),a:u[7]?parseFloat(u[7])/(u[8]?100:1):1}}else{var l=/hsla?\(\s*(?:(\d*\.\d+|\d+)(deg|turn|))\s*(?:,|\s*)\s*(?:(\d*\.\d+)%?|(\d+)%?)\s*(?:,|\s*)\s*(?:(\d*\.\d+)%?|(\d+)%?)\s*(?:(?:,|\s|\/)\s*(?:(0*(?:\.\d+)?()|0*1(?:\.0+)?())|(?:\.\d+)|(\d+)(%)|(\d*\.\d+)(%)))?\s*\)/;if(l.test(e)){var p,f,c,h,g,y,x,m,d,U,O,E=e.match(l).filter(function(S){return S!==void 0});f=(p={h:parseFloat(E[1])*(E[2]==="turn"?360:1),s:parseFloat(E[3]),l:parseFloat(E[4]),a:E[5]?parseFloat(E[5])/(E[6]?100:1):1}).h,c=p.s,h=p.l,g=p.a,x=(y=(1-Math.abs(2*(h/=100)-1))*(c/=100))*(1-Math.abs((f%=360)/60%2-1)),m=h-y/2,d=0,U=0,O=0,0<=f&&f<60?(d=y,U=x,O=0):60<=f&&f<120?(d=x,U=y,O=0):120<=f&&f<180?(d=0,U=y,O=x):180<=f&&f<240?(d=0,U=x,O=y):240<=f&&f<300?(d=x,U=0,O=y):300<=f&&f<=360&&(d=y,U=0,O=x),e={r:Math.round((d+m)*255),g:Math.round((U+m)*255),b:Math.round((O+m)*255),a:g}}else n=!1}}if(!n)throw Error("Invalid color format: "+e);return He(e,t)}function He(e,t){if(t===void 0&&(t="hexa"),e==="currentColor")return e;if(Number.isInteger(e)){if(t=="raw"||t=="cpal")return e;e=_a(e)}else typeof e!="object"&&(e=dt(e,"bgra"));var r=["hsl","hsla"].includes(t)?function(a){var n,o,s=a.r/255,i=a.g/255,u=a.b/255,l=Math.max(s,i,u),p=Math.min(s,i,u),f=(l+p)/2;if(l===p)n=o=0;else{var c=l-p;switch(o=f>.5?c/(2-l-p):c/(l+p),l){case s:n=(i-u)/c+(i=this.length-1;return{value:this.get(e),done:t}}).bind(this)}}),Kt.prototype.get=function(e){if(this.glyphs[e]===void 0){this.font._push(e),typeof this.glyphs[e]=="function"&&(this.glyphs[e]=this.glyphs[e]());var t=this.glyphs[e],r=this.font._IndexToUnicodeMap[e];if(r)for(var a=0;a1?k.getULong(e,t):k.getCard16(e,t),l=a>1?4:2;if(u!==0){var p=k.getByte(e,t+l);n=t+(u+1)*p+l;for(var f=t+l+1,c=0;c1&&u===23){(function(l){for(var p=l.pop();l.length>p;)l.pop()})(s);continue}o.push([u,s]),s=[]}else s.push(function(l,p){if(p===28)return l.parseByte()<<8|l.parseByte();if(p===29)return l.parseByte()<<24|l.parseByte()<<16|l.parseByte()<<8|l.parseByte();if(p===30)return function(f){for(var c="",h=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];;){var g=f.parseByte(),y=g>>4,x=15&g;if(y===15||(c+=h[y],x===15))break;c+=h[x]}return parseFloat(c)}(l);if(p>=32&&p<=246)return p-139;if(p>=247&&p<=250)return(p-247)*256+l.parseByte()+108;if(p>=251&&p<=254)return-(256*(p-251))-l.parseByte()-108;throw Error("Invalid b0 "+p)}(n,u,a))}return function(l){for(var p={},f=0;f1?Do:Za,a)}function Ir(e,t,r,a,n){for(var o=[],s=0;s1?Ya:Xa,a);u._subrs=[],u._subrsBias=0,u._defaultWidthX=0,u._nominalWidthX=0;var l=n<2?u.private[0]:0,p=n<2?u.private[1]:0;if(l!==0&&p!==0){var f=Dr(e,p+t,l,a,n);if(u._defaultWidthX=f.defaultWidthX,u._nominalWidthX=f.nominalWidthX,f.subrs!==0){var c=Le(e,p+f.subrs+t,void 0,n);u._subrs=c.objects,u._subrsBias=Qt(u._subrs)}u._privateDict=f}o.push(u)}return o}function Fr(e,t){var r=e.tables.cff&&e.tables.cff.topDict&&e.tables.cff.topDict.paintType||0;return r===2&&(t.fill=null,t.stroke="black",t.strokeWidth=e.tables.cff.topDict.strokeWidth||0),r}function Va(e,t,r,a){var n,o,s,i,u,l,p,f,c=new fe,h=[],g=0,y=!1,x=!1,m=0,d=0,U=0,O=[],E=e.tables.cff2||e.tables.cff;if(p=E.topDict._defaultWidthX,f=E.topDict._nominalWidthX,e.isCIDFont||a>1){var S=E.topDict._fdSelect?E.topDict._fdSelect[t.index]:0,L=E.topDict._fdArray[S];u=L._subrs,l=L._subrsBias,a>1?(O=E.topDict._vstore.itemVariationStore.itemVariationSubtables,U=L._privateDict.vsindex):(p=L._defaultWidthX,f=L._nominalWidthX)}else u=E.topDict._subrs,l=E.topDict._subrsBias;var D=Fr(e,c),F=p;function Y(w,T){x&&D!==2&&c.closePath(),c.moveTo(w,T),x=!0}function z(){!(1&h.length)||y||(F=h.shift()+f),g+=h.length>>1,h.length=0,y=!0}return function w(T){for(var P,V,B,G,Z,H,A,q,N,_,W,K,X=0;X1&&!y&&(F=h.shift()+f,y=!0),d+=h.pop(),Y(m,d);break;case 5:for(;h.length>0;)m+=h.shift(),d+=h.shift(),c.lineTo(m,d);break;case 6:for(;h.length>0&&(m+=h.shift(),c.lineTo(m,d),h.length!==0);)d+=h.shift(),c.lineTo(m,d);break;case 7:for(;h.length>0&&(d+=h.shift(),c.lineTo(m,d),h.length!==0);)m+=h.shift(),c.lineTo(m,d);break;case 8:for(;h.length>0;)n=m+h.shift(),o=d+h.shift(),s=n+h.shift(),i=o+h.shift(),m=s+h.shift(),d=i+h.shift(),c.curveTo(n,o,s,i,m,d);break;case 10:(H=u[Z=h.pop()+l])&&w(H);break;case 11:if(a>1){console.error("CFF CharString operator return (11) is not supported in CFF2");break}return;case 12:switch(j=T[X],X+=1,j){case 35:n=m+h.shift(),o=d+h.shift(),s=n+h.shift(),i=o+h.shift(),A=s+h.shift(),q=i+h.shift(),N=A+h.shift(),_=q+h.shift(),W=N+h.shift(),K=_+h.shift(),m=W+h.shift(),d=K+h.shift(),h.shift(),c.curveTo(n,o,s,i,A,q),c.curveTo(N,_,W,K,m,d);break;case 34:n=m+h.shift(),o=d,s=n+h.shift(),i=o+h.shift(),A=s+h.shift(),q=i,N=A+h.shift(),_=i,W=N+h.shift(),K=d,m=W+h.shift(),c.curveTo(n,o,s,i,A,q),c.curveTo(N,_,W,K,m,d);break;case 36:n=m+h.shift(),o=d+h.shift(),s=n+h.shift(),i=o+h.shift(),A=s+h.shift(),q=i,N=A+h.shift(),_=i,W=N+h.shift(),K=_+h.shift(),m=W+h.shift(),c.curveTo(n,o,s,i,A,q),c.curveTo(N,_,W,K,m,d);break;case 37:n=m+h.shift(),o=d+h.shift(),s=n+h.shift(),i=o+h.shift(),A=s+h.shift(),q=i+h.shift(),N=A+h.shift(),_=q+h.shift(),W=N+h.shift(),K=_+h.shift(),Math.abs(W-m)>Math.abs(K-d)?m=W+h.shift():d=K+h.shift(),c.curveTo(n,o,s,i,A,q),c.curveTo(N,_,W,K,m,d);break;default:console.log("Glyph "+t.index+": unknown operator 1200"+j),h.length=0}break;case 14:if(a>1){console.error("CFF CharString operator endchar (14) is not supported in CFF2");break}if(h.length>=4){var qe=Xt[h.pop()],Ie=Xt[h.pop()],Te=h.pop(),he=h.pop();if(qe&&Ie){t.isComposite=!0,t.components=[];var Ue=e.cffEncoding.charset.indexOf(qe),Xe=e.cffEncoding.charset.indexOf(Ie);t.components.push({glyphIndex:Xe,dx:0,dy:0}),t.components.push({glyphIndex:Ue,dx:he,dy:Te}),c.extend(e.glyphs.get(Xe).path);for(var Oe=JSON.parse(JSON.stringify(e.glyphs.get(Ue).path.commands)),de=0;de0&&!y&&(F=h.shift()+f,y=!0);x&&D!==2&&(c.closePath(),x=!1);break;case 15:if(a<2){console.error("CFF2 CharString operator vsindex (15) is not supported in CFF");break}U=h.pop();break;case 16:if(a<2){console.error("CFF2 CharString operator blend (16) is not supported in CFF");break}for(var Qe=O[U],ve=h.pop(),De=ve*Qe.regionIndexes.length,Ge=h.length-De,Ae=Ge-ve,Ct=0;Ct>3;break;case 21:h.length>2&&!y&&(F=h.shift()+f,y=!0),d+=h.pop(),Y(m+=h.pop(),d);break;case 22:h.length>1&&!y&&(F=h.shift()+f,y=!0),Y(m+=h.pop(),d);break;case 24:for(;h.length>2;)n=m+h.shift(),o=d+h.shift(),s=n+h.shift(),i=o+h.shift(),m=s+h.shift(),d=i+h.shift(),c.curveTo(n,o,s,i,m,d);m+=h.shift(),d+=h.shift(),c.lineTo(m,d);break;case 25:for(;h.length>6;)m+=h.shift(),d+=h.shift(),c.lineTo(m,d);n=m+h.shift(),o=d+h.shift(),s=n+h.shift(),i=o+h.shift(),m=s+h.shift(),d=i+h.shift(),c.curveTo(n,o,s,i,m,d);break;case 26:for(1&h.length&&(m+=h.shift());h.length>0;)n=m,o=d+h.shift(),s=n+h.shift(),i=o+h.shift(),m=s,d=i+h.shift(),c.curveTo(n,o,s,i,m,d);break;case 27:for(1&h.length&&(d+=h.shift());h.length>0;)n=m+h.shift(),o=d,s=n+h.shift(),i=o+h.shift(),m=s+h.shift(),d=i,c.curveTo(n,o,s,i,m,d);break;case 28:P=T[X],V=T[X+1],h.push((P<<24|V<<16)>>16),X+=2;break;case 29:Z=h.pop()+e.gsubrsBias,(H=e.gsubrs[Z])&&w(H);break;case 30:for(;h.length>0&&(n=m,o=d+h.shift(),s=n+h.shift(),i=o+h.shift(),m=s+h.shift(),d=i+(h.length===1?h.shift():0),c.curveTo(n,o,s,i,m,d),h.length!==0);)n=m+h.shift(),o=d,s=n+h.shift(),d=(i=o+h.shift())+h.shift(),m=s+(h.length===1?h.shift():0),c.curveTo(n,o,s,i,m,d);break;case 31:for(;h.length>0&&(n=m+h.shift(),o=d,s=n+h.shift(),d=(i=o+h.shift())+h.shift(),m=s+(h.length===1?h.shift():0),c.curveTo(n,o,s,i,m,d),h.length!==0);)n=m,o=d+h.shift(),s=n+h.shift(),i=o+h.shift(),m=s+h.shift(),d=i+(h.length===1?h.shift():0),c.curveTo(n,o,s,i,m,d);break;default:j<32?console.log("Glyph "+t.index+": unknown operator "+j):j<247?h.push(j-139):j<251?(P=T[X],X+=1,h.push((j-247)*256+P+108)):j<255?(P=T[X],X+=1,h.push(-(256*(j-251))-P-108)):(P=T[X],V=T[X+1],B=T[X+2],G=T[X+3],X+=4,h.push((P<<24|V<<16|B<<8|G)/65536))}}}(r),y&&(t.advanceWidth=F),c}function za(e,t,r,a,n){var o=[],s=new k.Parser(e,t),i=s.parseCard8();if(i===0)for(var u=0;u=a)throw Error("CFF table CID Font FDSelect has bad FD index value "+l+" (FD count "+a+")");o.push(l)}else if(i===3||n>1&&i===4){var l,p,f=i===4?s.parseULong():s.parseCard16(),c=i===4?s.parseULong():s.parseCard16();if(c!==0)throw Error("CFF Table CID Font FDSelect format "+i+" range has bad initial GID "+c);for(var h=0;h=a)throw Error("CFF table CID Font FDSelect has bad FD index value "+l+" (FD count "+a+")");if(p>r)throw Error("CFF Table CID Font FDSelect format "+n+" range has bad GID "+p);for(;c=0&&(r=a),(a=t.indexOf(e))>=0?r=a+ft.length:(r=ft.length+t.length,t.push(e)),r}function Qa(e,t,r){for(var a={},n=0;n1?Ya:Xa,e,t),a}function qa(e){var t=new b.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return t.topDicts=[{name:"topDict_0",type:"TABLE",value:e}],t}var gt={parse:function(e,t,r,a){var n,o,s,i=function(V,B){var G={};if(G.formatMajor=k.getCard8(V,B),G.formatMinor=k.getCard8(V,B+1),G.formatMajor>2)throw Error("Unsupported CFF table version "+G.formatMajor+"."+G.formatMinor);return G.size=k.getCard8(V,B+2),G.formatMajor<2?(G.offsetSize=k.getCard8(V,B+3),G.startOffset=B,G.endOffset=B+4):(G.topDictLength=k.getCard16(V,B+3),G.endOffset=B+8),G}(e,t);n=i.formatMajor===2?r.tables.cff2={}:r.tables.cff={};var u=i.formatMajor>1?null:Le(e,i.endOffset,k.bytesToString),l=i.formatMajor>1?null:Le(e,u.endOffset),p=i.formatMajor>1?null:Le(e,l.endOffset,k.bytesToString),f=Le(e,i.formatMajor>1?t+i.size+i.topDictLength:p.endOffset,void 0,i.formatMajor);if(r.gsubrs=f.objects,r.gsubrsBias=Qt(r.gsubrs),i.formatMajor>1){var c=t+i.size,h=k.getBytes(e,c,c+i.topDictLength);o=Ir(e,0,[h],void 0,i.formatMajor)[0]}else{var g=Ir(e,t,l.objects,p.objects,i.formatMajor);if(g.length!==1)throw Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+g.length);o=g[0]}if(n.topDict=o,o._privateDict&&(r.defaultWidthX=o._privateDict.defaultWidthX,r.nominalWidthX=o._privateDict.nominalWidthX),i.formatMajor<2&&o.ros[0]!==void 0&&o.ros[1]!==void 0&&(r.isCIDFont=!0),i.formatMajor>1){var y=o.fdArray,x=o.fdSelect;if(!y)throw Error("This is a CFF2 font, but FDArray information is missing");var m=Le(e,t+y,null,i.formatMajor),d=function(V,B,G){for(var Z=[],H=0;H1?k.getULong(V,B):k.getCard16(V,B),N=G>1?4:2;if(q!==0){var _=k.getByte(V,B+N);Z=B+(q+1)*_+N;for(var W=B+N+1,K=0;K1?1:0)):(s=Le(e,t+o.charStrings,null,i.formatMajor),r.nGlyphs=s.objects.length),i.formatMajor>1&&r.tables.maxp&&r.nGlyphs!==r.tables.maxp.numGlyphs&&console.error("Glyph count in the CFF2 table ("+r.nGlyphs+") must correspond to the glyph count in the maxp table ("+r.tables.maxp.numGlyphs+")"),i.formatMajor<2){var Y=[],z=[];Y=o.charset===0?Fa:o.charset===1?Pa:o.charset===2?Ga:function(V,B,G,Z,H){var A,q,N=new k.Parser(V,B);G-=1;var _=[".notdef"],W=N.parseCard8();if(W===0)for(var K=0;K1?k.getULong(H,A):k.getCard16(H,A),W=N>1?4:2,K=0;if(_!==0){var X=k.getByte(H,A+W);K=A+(_+1)*X+W}var j=k.getBytes(H,K+Z[G],K+Z[G+1]);return q&&(j=q(j)),j}(V,s.offsets,e,t+o.charStrings,void 0,i.formatMajor);r.glyphs.push(V,ue.cffGlyphLoader(r,V,Va,B,i.formatMajor))};else for(var w=0;w=1&&(r.ulCodePageRange1=a.parseULong(),r.ulCodePageRange2=a.parseULong()),r.version>=2&&(r.sxHeight=a.parseShort(),r.sCapHeight=a.parseShort(),r.usDefaultChar=a.parseUShort(),r.usBreakChar=a.parseUShort(),r.usMaxContent=a.parseUShort()),r},make:function(e){return new b.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],e)},unicodeRanges:Pr,getUnicodeRange:function(e){for(var t=0;t=r.begin&&e=Be.length){var s=a.parseChar();r.names.push(a.parseString(s))}break;case 2.5:r.numberOfGlyphs=a.parseUShort(),r.offset=Array(r.numberOfGlyphs);for(var i=0;i1||o>0?a.parseUShort():void 0;r!==void 0&&R.argument(i>=r.axes.length,"STAT axis count must be greater than or equal to fvar axis count"),l>0&&R.argument(i>=0,"STAT axis count must be greater than 0 if STAT axis value count is greater than 0");for(var c=[],h=0;hf.value.tag?1:-1}),t.fields=t.fields.concat(a),t.fields=t.fields.concat(n),t}function en(e,t,r){for(var a=0;a0)return e.glyphs.get(n).getMetrics()}return r}var tn={make:$a,fontToTable:function(e){for(var t=[],r=[],a=[],n=[],o=[],s=[],i=[],u=0,l=0,p=0,f=0,c=0,h=0;hy||he===void 0)&&y>0&&(he=y),u 123 are reserved for internal usage");if(g.name!==".notdef"){var m=g.getMetrics();t.push(m.xMin),r.push(m.yMin),a.push(m.xMax),n.push(m.yMax),s.push(m.leftSideBearing),i.push(m.rightSideBearing),o.push(g.advanceWidth)}}var d={xMin:Math.min.apply(null,t),yMin:Math.min.apply(null,r),xMax:Math.max.apply(null,a),yMax:Math.max.apply(null,n),advanceWidthMax:Math.max.apply(null,o),advanceWidthAvg:function(De){for(var Ge=0,Ae=0;Ae=600&&(U|=e.macStyleValues.BOLD),e.italicAngle<0&&(U|=e.macStyleValues.ITALIC);var O=jt.make({flags:3,unitsPerEm:e.unitsPerEm,xMin:d.xMin,yMin:d.yMin,xMax:d.xMax,yMax:d.yMax,lowestRecPPEM:3,macStyle:U,createdTimestamp:e.createdTimestamp}),E=Jt.make({ascender:d.ascender,descender:d.descender,advanceWidthMax:d.advanceWidthMax,minLeftSideBearing:d.minLeftSideBearing,minRightSideBearing:d.minRightSideBearing,xMaxExtent:d.maxLeftSideBearing+(d.xMax-d.xMin),numberOfHMetrics:e.glyphs.length}),S=tr.make(e.glyphs.length),L=mt.make(Object.assign({xAvgCharWidth:Math.round(d.advanceWidthAvg),usFirstCharIndex:he,usLastCharIndex:u,ulUnicodeRange1:l,ulUnicodeRange2:p,ulUnicodeRange3:f,ulUnicodeRange4:c,sTypoAscender:d.ascender,sTypoDescender:d.descender,sTypoLineGap:0,usWinAscent:d.yMax,usWinDescent:Math.abs(d.yMin),ulCodePageRange1:1,sxHeight:en(e,"xyvw",{yMax:Math.round(d.ascender/2)}).yMax,sCapHeight:en(e,"HIKLEFJMNTZBDPRAGOQSUVWXY",d).yMax,usDefaultChar:e.hasChar(" ")?32:0,usBreakChar:e.hasChar(" ")?32:0},e.tables.os2)),D=$t.make(e.glyphs),F=Wt.make(e.glyphs),Y=e.getEnglishName("fontFamily"),z=e.getEnglishName("fontSubfamily"),w=Y+" "+z,T=e.getEnglishName("postScriptName");T||(T=Y.replace(/\s/g,"")+"-"+z);var P={};for(var V in e.names)P[V]=e.names[V];P.unicode=P.unicode||{},P.macintosh=P.macintosh||{},P.windows=P.windows||{};var B=e.names.unicode||{},G=e.names.macintosh||{},Z=e.names.windows||{};for(var H in["unicode","macintosh","windows"])P[H]=P[H]||{},P[H].uniqueID||(P.unicode.uniqueID={en:e.getEnglishName("manufacturer")+":"+w}),P[H].postScriptName||(P.unicode.postScriptName={en:T});P.unicode.preferredFamily||(P.unicode.preferredFamily=B.fontFamily||G.fontFamily||Z.fontFamily),P.macintosh.preferredFamily||(P.macintosh.preferredFamily=G.fontFamily||B.fontFamily||Z.fontFamily),P.windows.preferredFamily||(P.windows.preferredFamily=Z.fontFamily||B.fontFamily||G.fontFamily),P.unicode.preferredSubfamily||(P.unicode.preferredSubfamily=B.fontSubfamily||G.fontSubfamily||Z.fontSubfamily),P.macintosh.preferredSubfamily||(P.macintosh.preferredSubfamily=G.fontSubfamily||B.fontSubfamily||Z.fontSubfamily),P.windows.preferredSubfamily||(P.windows.preferredSubfamily=Z.fontSubfamily||B.fontSubfamily||G.fontSubfamily);var A=[],q=zt.make(P,A),N=A.length>0?er.make(A):void 0,_=rr.make(e),W=gt.make(e.glyphs,{version:e.getEnglishName("version"),fullName:w,familyName:Y,weightName:z,postScriptName:T,unitsPerEm:e.unitsPerEm,fontBBox:[0,d.yMin,d.ascender,d.advanceWidthMax],topDict:e.tables.cff&&e.tables.cff.topDict||{}}),K=e.metas&&Object.keys(e.metas).length>0?nr.make(e.metas):void 0,X=[O,E,S,L,q,F,_,W,D];N&&X.push(N);var j={gsub:ar,cpal:Yt,colr:or,stat:ir,avar:ur,cvar:lr,fvar:sr,gvar:pr,gasp:hr,svg:fr},qe={avar:[e.tables.fvar],fvar:[e.names]};for(var Ie in j){var Te=e.tables[Ie];if(Te){var he,Ue,Xe=(Ue=j[Ie].make).call.apply(Ue,[e,Te].concat(ae(qe[Ie]||[])));Xe&&X.push(Xe)}}K&&X.push(K);for(var Oe=$a(X),de=Gr(Oe.encode()),ne=Oe.fields,Qe=!1,ve=0;ve>>1,o=e[n].tag;if(o===t)return n;o>>1,o=e[n];if(o===t)return n;o>>1,s=(r=e[o]).start;if(s===t)return r;s0)return t>(r=e[a-1]).end?0:r}function nn(e,t){this.font=e,this.tableName=t}nn.prototype={searchTag:Nr,binSearch:rn,getTable:function(e){var t=this.font.tables[this.tableName];return!t&&e&&(t=this.font.tables[this.tableName]=this.createDefaultTable()),t},getScriptNames:function(){var e=this.getTable();return e?e.scripts.map(function(t){return t.tag}):[]},getDefaultScriptName:function(){var e=this.getTable();if(e){for(var t=!1,r=0;r=0)return a[n].script;if(t){var o={tag:e,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return a.splice(-1-n,0,o),o.script}}},getLangSysTable:function(e,t,r){var a=this.getScriptTable(e,r);if(a){if(!t||t==="dflt"||t==="DFLT")return a.defaultLangSys;var n=Nr(a.langSysRecords,t);if(n>=0)return a.langSysRecords[n].langSys;if(r){var o={tag:t,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return a.langSysRecords.splice(-1-n,0,o),o.langSys}}},getFeatureTable:function(e,t,r,a){var n=this.getLangSysTable(e,t,a);if(n){for(var o,s=n.featureIndexes,i=this.font.tables[this.tableName].features,u=0;u=i[l-1].tag,"Features must be added in alphabetical order."),o={tag:r,feature:{params:0,lookupListIndexes:[]}},i.push(o),s.push(l),o.feature}}},getLookupTables:function(e,t,r,a,n){var o=this.getFeatureTable(e,t,r,n),s=[];if(o){for(var i,u=o.lookupListIndexes,l=this.font.tables[this.tableName].lookups,p=0;p=0?r:-1;case 2:var a=an(e.ranges,t);return a?a.index+t-a.start:-1}},expandCoverage:function(e){if(e.format===1)return e.glyphs;for(var t=[],r=e.ranges,a=0;a1,'Multiple: "by" must be an array of two or more ids');var n=Br(this.getLookupTables(r,a,e,2,!0)[0],1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});R.assert(n.coverage.format===1,"Multiple: unable to modify coverage table format "+n.coverage.format);var o=t.sub,s=this.binSearch(n.coverage.glyphs,o);s<0&&(s=-1-s,n.coverage.glyphs.splice(s,0,o),n.sequences.splice(s,0,0)),n.sequences[s]=t.by},le.prototype.addAlternate=function(e,t,r,a){var n=Br(this.getLookupTables(r,a,e,3,!0)[0],1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});R.assert(n.coverage.format===1,"Alternate: unable to modify coverage table format "+n.coverage.format);var o=t.sub,s=this.binSearch(n.coverage.glyphs,o);s<0&&(s=-1-s,n.coverage.glyphs.splice(s,0,o),n.alternateSets.splice(s,0,0)),n.alternateSets[s]=t.by},le.prototype.addLigature=function(e,t,r,a){var n=this.getLookupTables(r,a,e,4,!0)[0],o=n.subtables[0];o||(o={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},n.subtables[0]=o),R.assert(o.coverage.format===1,"Ligature: unable to modify coverage table format "+o.coverage.format);var s=t.sub[0],i=t.sub.slice(1),u={ligGlyph:t.by,components:i},l=this.binSearch(o.coverage.glyphs,s);if(l>=0){for(var p=o.ligatureSets[l],f=0;fu&&(this.extend(a.length+r-u),s=(o=this.getAll("raw"))[n]);for(var l=0;ls?this.extend(r.length-s):r.lengthn.numPaletteEntries-1)throw Error("Replacement index out of range: numPaletteEntries after deletion: "+(n.numPaletteEntries-1)+", replacementIndex: "+a+")");for(var i=0;ir)p[f].paletteIndex-=1;else if(c===r){for(var h=0,g=0;gr&&a<=r+o[g].length){h++;break}p[f].paletteIndex=a-h}}this.font.tables.colr=St({},l,{layerRecords:p})}for(var y=s.flat(),x=0;xo.length?n=o.length:n<0&&(n=o.length+1+n%(o.length+1))>=o.length+1&&(n-=o.length+1);for(var s=[],i=0;i0){var f,c=a.slice(u).map(function(x){return{glyphID:x.glyphID,paletteIndex:x.paletteIndex}});(f=n.layerRecords).splice.apply(f,[i.firstLayerIndex+u,0].concat(ae(c)))}else p<0&&n.layerRecords.splice(i.firstLayerIndex+l,-p);for(var h=0;h",t+4)+1;if(/ id=['"]glyph\d+['"]/.test(e.substring(t,r)))return e;var a=e.lastIndexOf("");return[e.substring(0,r),"",e.substring(r,a),'',e.substring(a)]}function No(e,t){var r=new DOMParser().parseFromString(e,"image/svg+xml").documentElement,a=r.viewBox.baseVal,n=r.width.baseVal,o=r.height.baseVal,s=1,i=1;a.width>0&&a.height>0&&(n.unitType===1?(s=n.valueInSpecifiedUnits/a.width,i=o.unitType===1?o.valueInSpecifiedUnits/a.height:s):o.unitType===1?s=i=o.valueInSpecifiedUnits/a.height:t&&(s=t/a.width,i=t/a.height));var u=document.createElement("div");u.style.position="fixed",u.style.visibility="hidden",u.appendChild(r),document.body.appendChild(u);var l=r.getBBox();document.body.removeChild(u);var p=(l.x-a.x)*s,f=(a.y-l.y)*i,c=l.width*s,h=l.height*i;r.setAttribute("viewBox",[l.x,l.y,l.width,l.height].join(" ")),s!==1&&r.setAttribute("width",c),i!==1&&r.setAttribute("height",h);var g=new Image(c,h);return g.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(r.outerHTML),{leftSideBearing:p,baseline:f,image:g}}function pn(e,t,r,a,n){var o;return(t&a)>0?(o=e.parseByte(),!(t&n)&&(o=-o),o=r+o):o=(t&n)>0?r:r+e.parseShort(),o}function hn(e,t,r){var a=new k.Parser(t,r);if(e.numberOfContours=a.parseShort(),e._xMin=a.parseShort(),e._yMin=a.parseShort(),e._xMax=a.parseShort(),e._yMax=a.parseShort(),e.numberOfContours>0){for(var n=e.endPointIndices=[],o=0;o0)for(var l=a.parseByte(),p=0;p0){var f,c,h,g=[];if(i>0){for(var y=0;y=0,g.push(h);for(var x=0,m=0;m0?(2&f)>0?(E.dx=a.parseShort(),E.dy=a.parseShort()):E.matchedPoints=[a.parseUShort(),a.parseUShort()]:(2&f)>0?(E.dx=a.parseChar(),E.dy=a.parseChar()):E.matchedPoints=[a.parseByte(),a.parseByte()],(8&f)>0?E.xScale=E.yScale=a.parseF2Dot14():(64&f)>0?(E.xScale=a.parseF2Dot14(),E.yScale=a.parseF2Dot14()):(128&f)>0&&(E.xScale=a.parseF2Dot14(),E.scale01=a.parseF2Dot14(),E.scale10=a.parseF2Dot14(),E.yScale=a.parseF2Dot14()),e.components.push(E),O=!!(32&f)}if(256&f){e.instructionLength=a.parseUShort(),e.instructions=[];for(var S=0;St.points.length-1||a.matchedPoints[1]>n.points.length-1)throw Error("Matched points out of range in "+t.name);var s=t.points[a.matchedPoints[0]],i=n.points[a.matchedPoints[1]],u={xScale:a.xScale,scale01:a.scale01,scale10:a.scale10,yScale:a.yScale,dx:0,dy:0};i=_r([i],u)[0],u.dx=s.x-i.x,u.dy=s.y-i.y,o=_r(n.points,u)}t.points=t.points.concat(o)}}return cn(t.points)}var dr={getPath:cn,parse:function(e,t,r,a,n){var o;return n.lowMemory?(o=new ue.GlyphSet(a),a._push=function(s){var i=r[s];i!==r[s+1]?o.push(s,ue.ttfGlyphLoader(a,s,hn,e,t+i,fn)):o.push(s,ue.glyphLoader(a,s))},o):function(s,i,u,l){for(var p=new ue.GlyphSet(l),f=0;f=176&&r<=183)n+=r-176+1;else if(r>=184&&r<=191)n+=(r-184+1)*2;else if(t&&o===1&&r===27)break;while(o>0);e.ip=n}function yn(e,t){t.fv=t.pv=t.dpv=e}function xn(e,t){t.pv=t.dpv=e}function Sn(e,t){t.fv=e}function bn(e,t){var r,a,n=t.stack,o=n.pop(),s=n.pop(),i=t.z2[o],u=t.z1[s];e?(r=i.y-u.y,a=u.x-i.x):(r=u.x-i.x,a=u.y-i.y),t.pv=t.dpv=Ut(r,a)}function Tn(e,t){var r,a,n=t.stack,o=n.pop(),s=n.pop(),i=t.z2[o],u=t.z1[s];e?(r=i.y-u.y,a=u.x-i.x):(r=u.x-i.x,a=u.y-i.y),t.fv=Ut(r,a)}function Vr(e){e.stack.pop()}function Un(e,t){var r=t.stack.pop(),a=t.z0[r],n=t.fv,o=t.pv,s=o.distance(a,Ot);e&&(s=t.round(s)),n.setRelative(a,Ot,s,o),n.touch(a),t.rp0=t.rp1=r}function On(e,t){for(var r,a,n,o=t.z2,s=o.length-2,i=0;i>4)===s){var h=(15&c)-8;h>=0&&h++;var g=l[f];n.setRelative(g,g,h*u,o)}}}function gr(e,t){var r=t.stack,a=r.pop();r.push(64*t.round(a/64))}function Wr(e,t){for(var r=t.stack,a=r.pop(),n=t.ppem,o=t.deltaBase+(e-1)*16,s=t.deltaShift,i=0;i>4)===n){var p=(15&l)-8;p>=0&&p++;var f=p*s;t.cvt[u]+=f}}}function Dn(e,t){var r,a,n=t.stack,o=n.pop(),s=n.pop(),i=t.z2[o],u=t.z1[s];e?(r=i.y-u.y,a=u.x-i.x):(r=u.x-i.x,a=u.y-i.y),t.dpv=Ut(r,a)}function ze(e,t){for(var r=t.stack,a=t.prog,n=t.ip,o=0;o=0?1:-1,i=Math.abs(i),e&&(l=o.cvt[f],a&&Math.abs(i-l)2)){var r=this.font,a=this._prepState;if(!a||a.ppem!==t){var n=this._fpgmState;if(!n){Ve.prototype=Wo,(n=this._fpgmState=new Ve("fpgm",r.tables.fpgm)).funcs=[],n.font=r;try{Ke(n)}catch(l){console.log("Hinting error in FPGM:"+l),this._errorState=3;return}}Ve.prototype=n,(a=this._prepState=new Ve("prep",r.tables.prep)).ppem=t;var o=r.tables.cvt;if(o)for(var s=a.cvt=Array(o.length),i=t/r.unitsPerEm,u=0;u1))try{return vn(e,a)}catch(l){this._errorState<1&&(console.log("Hinting error:"+l),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}}},vn=function(e,t){var r,a,n,o=t.ppem/t.font.unitsPerEm,s=e.components;if(Ve.prototype=t,s){var i=t.font;a=[],r=[];for(var u=0;ur?1:0)},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(a>=r?1:0)},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(r===a?1:0)},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(r!==a?1:0)},function(e){var t=e.stack,r=t.pop();t.push(1&Math.trunc(r)?1:0)},function(e){var t=e.stack,r=t.pop();t.push(1&Math.trunc(r)?0:1)},function(e){var t,r=e.stack.pop();!r&&mn(e,!0)},function(e){},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(r&&a?1:0)},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(r||a?1:0)},function(e){var t=e.stack,r=t.pop();t.push(r?0:1)},zr.bind(void 0,1),function(e){var t=e.stack.pop();e.deltaBase=t},function(e){var t=e.stack.pop();e.deltaShift=Math.pow(.5,t)},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(a+r)},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(a-r)},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(64*a/r)},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(a*r/64)},function(e){var t=e.stack,r=t.pop();t.push(Math.abs(r))},function(e){var t=e.stack,r=t.pop();t.push(-r)},function(e){var t=e.stack,r=t.pop();t.push(64*Math.floor(r/64))},function(e){var t=e.stack,r=t.pop();t.push(64*Math.ceil(r/64))},gr.bind(void 0,0),gr.bind(void 0,1),gr.bind(void 0,2),gr.bind(void 0,3),void 0,void 0,void 0,void 0,function(e){var t=e.stack,r=t.pop(),a=t.pop();e.cvt[a]=r*e.ppem/e.font.unitsPerEm},zr.bind(void 0,2),zr.bind(void 0,3),Wr.bind(void 0,1),Wr.bind(void 0,2),Wr.bind(void 0,3),function(e){var t,r=e.stack.pop();switch(e.round=gn,192&r){case 0:t=.5;break;case 64:t=1;break;case 128:t=2;break;default:throw Error("invalid SROUND value")}switch(e.srPeriod=t,48&r){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*t;break;case 32:e.srPhase=.5*t;break;case 48:e.srPhase=.75*t;break;default:throw Error("invalid SROUND value")}(r&=15)==0?e.srThreshold=0:e.srThreshold=(r/8-.5)*t},function(e){var t,r=e.stack.pop();switch(e.round=gn,192&r){case 0:t=Math.sqrt(2)/2;break;case 64:t=Math.sqrt(2);break;case 128:t=2*Math.sqrt(2);break;default:throw Error("invalid S45ROUND value")}switch(e.srPeriod=t,48&r){case 0:e.srPhase=0;break;case 16:e.srPhase=.25*t;break;case 32:e.srPhase=.5*t;break;case 48:e.srPhase=.75*t;break;default:throw Error("invalid S45ROUND value")}(r&=15)==0?e.srThreshold=0:e.srThreshold=(r/8-.5)*t},void 0,void 0,function(e){e.round=Bo},void 0,function(e){e.round=Vo},function(e){e.round=zo},Vr,Vr,void 0,void 0,void 0,void 0,void 0,function(e){var t=e.stack.pop()},Dn.bind(void 0,0),Dn.bind(void 0,1),function(e){var t=e.stack,r=t.pop(),a=0;1&r&&(a=35),32&r&&(a|=4096),t.push(a)},void 0,function(e){var t=e.stack,r=t.pop(),a=t.pop(),n=t.pop();t.push(a),t.push(r),t.push(n)},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(Math.max(a,r))},function(e){var t=e.stack,r=t.pop(),a=t.pop();t.push(Math.min(a,r))},function(e){var t=e.stack.pop()},function(e){var t=e.stack.pop(),r=e.stack.pop();switch(t){case 1:e.inhibitGridFit=!!r;return;case 2:e.ignoreCvt=!!r;return;default:throw Error("invalid INSTCTRL[] selector")}},void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,ze.bind(void 0,1),ze.bind(void 0,2),ze.bind(void 0,3),ze.bind(void 0,4),ze.bind(void 0,5),ze.bind(void 0,6),ze.bind(void 0,7),ze.bind(void 0,8),We.bind(void 0,1),We.bind(void 0,2),We.bind(void 0,3),We.bind(void 0,4),We.bind(void 0,5),We.bind(void 0,6),We.bind(void 0,7),We.bind(void 0,8),I.bind(void 0,0,0,0,0,0),I.bind(void 0,0,0,0,0,1),I.bind(void 0,0,0,0,0,2),I.bind(void 0,0,0,0,0,3),I.bind(void 0,0,0,0,1,0),I.bind(void 0,0,0,0,1,1),I.bind(void 0,0,0,0,1,2),I.bind(void 0,0,0,0,1,3),I.bind(void 0,0,0,1,0,0),I.bind(void 0,0,0,1,0,1),I.bind(void 0,0,0,1,0,2),I.bind(void 0,0,0,1,0,3),I.bind(void 0,0,0,1,1,0),I.bind(void 0,0,0,1,1,1),I.bind(void 0,0,0,1,1,2),I.bind(void 0,0,0,1,1,3),I.bind(void 0,0,1,0,0,0),I.bind(void 0,0,1,0,0,1),I.bind(void 0,0,1,0,0,2),I.bind(void 0,0,1,0,0,3),I.bind(void 0,0,1,0,1,0),I.bind(void 0,0,1,0,1,1),I.bind(void 0,0,1,0,1,2),I.bind(void 0,0,1,0,1,3),I.bind(void 0,0,1,1,0,0),I.bind(void 0,0,1,1,0,1),I.bind(void 0,0,1,1,0,2),I.bind(void 0,0,1,1,0,3),I.bind(void 0,0,1,1,1,0),I.bind(void 0,0,1,1,1,1),I.bind(void 0,0,1,1,1,2),I.bind(void 0,0,1,1,1,3),I.bind(void 0,1,0,0,0,0),I.bind(void 0,1,0,0,0,1),I.bind(void 0,1,0,0,0,2),I.bind(void 0,1,0,0,0,3),I.bind(void 0,1,0,0,1,0),I.bind(void 0,1,0,0,1,1),I.bind(void 0,1,0,0,1,2),I.bind(void 0,1,0,0,1,3),I.bind(void 0,1,0,1,0,0),I.bind(void 0,1,0,1,0,1),I.bind(void 0,1,0,1,0,2),I.bind(void 0,1,0,1,0,3),I.bind(void 0,1,0,1,1,0),I.bind(void 0,1,0,1,1,1),I.bind(void 0,1,0,1,1,2),I.bind(void 0,1,0,1,1,3),I.bind(void 0,1,1,0,0,0),I.bind(void 0,1,1,0,0,1),I.bind(void 0,1,1,0,0,2),I.bind(void 0,1,1,0,0,3),I.bind(void 0,1,1,0,1,0),I.bind(void 0,1,1,0,1,1),I.bind(void 0,1,1,0,1,2),I.bind(void 0,1,1,0,1,3),I.bind(void 0,1,1,1,0,0),I.bind(void 0,1,1,1,0,1),I.bind(void 0,1,1,1,0,2),I.bind(void 0,1,1,1,0,3),I.bind(void 0,1,1,1,1,0),I.bind(void 0,1,1,1,1,1),I.bind(void 0,1,1,1,1,2),I.bind(void 0,1,1,1,1,3)];var Fn=An;function nt(e){this.char=e,this.state={},this.activeState=null}function qr(e,t,r){this.contextName=r,this.startIndex=e,this.endOffset=t}function qo(e,t,r){this.contextName=e,this.openRange=null,this.ranges=[],this.checkStart=t,this.checkEnd=r}function $(e,t){this.context=e,this.index=t,this.length=e.length,this.current=e[t],this.backtrack=e.slice(0,t),this.lookahead=e.slice(t+1)}function mr(e){this.eventId=e,this.subscribers=[]}function Xo(e){for(var t=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"],r=0;r=0&&e0&&e<=this.lookahead.length):return this.lookahead[e-1];default:return null}},ee.prototype.rangeToText=function(e){if(e instanceof qr)return this.getRangeTokens(e).map(function(t){return t.char}).join("")},ee.prototype.getText=function(){return this.tokens.map(function(e){return e.char}).join("")},ee.prototype.getContext=function(e){return this.registeredContexts[e]||null},ee.prototype.on=function(e,t){var r=this.events[e];return r?r.subscribe(t):null},ee.prototype.dispatch=function(e,t){var r=this.events[e];if(r instanceof mr)for(var a=0;a=n.start&&e<=n.end){var o=e-n.start;return n.index+o}}}return-1}function Yo(e,t){return Pe(e,t.coverage)===-1?null:e+t.deltaGlyphId}function Zo(e,t){var r=Pe(e,t.coverage);return r===-1?null:t.substitute[r]}function Zr(e,t){for(var r=[],a=0;a=0;g--){var y=h[g],x=Yr(y),m=Se(y);if(!x&&!m)return!0;if(x)break}return!1})(o)&&(i|=1),function(c){if(Yr(c.current))return!1;for(var h=0;h1},endCheck:function(e){return e.index===e.context.length-1}};function Xn(e,t){return new $(e.map(function(r){return r.activeState.value}),t||0)}function Yn(e){for(var t="delf",r="ccmp",a=this.tokenizer.getRangeTokens(e),n=Xn(a),o=0;o=6155&&t<=6157||t>=65024&&t<=65039||t>=917760&&t<=917999}var no={startCheck:function(e){var t=e.current,r=e.get(1);return r===null&&Qr(t)||Qr(r)},endCheck:function(e){var t=e.get(1);return t===null||!Qr(t)}};function oo(e){var t=this.query.font,r=this.tokenizer.getRangeTokens(e);if(r[1].setState("deleted",!0),t.tables.cmap&&t.tables.cmap.varSelectorList){var a=r[0].char.codePointAt(0),n=r[1].char.codePointAt(0),o=t.tables.cmap.varSelectorList[n];if(o!==void 0&&o.nonDefaultUVS){var s=o.nonDefaultUVS.uvsMappings;if(s[a]){var i=s[a].glyphID;t.glyphs.glyphs[i]!==void 0&&r[0].setState("glyphIndex",i)}}}}function ce(e){this.baseDir=e||"ltr",this.tokenizer=new Pn,this.featuresTags={}}function ot(e){var t=this.contextChecks[""+e+"Check"];return this.tokenizer.registerContextChecker(e,t.startCheck,t.endCheck)}function rs(){return ot.call(this,"ccmpReplacement"),ot.call(this,"latinWord"),ot.call(this,"arabicWord"),ot.call(this,"arabicSentence"),ot.call(this,"thaiWord"),ot.call(this,"unicodeVariationSequence"),this.tokenizer.tokenize(this.text)}function as(){for(var e=this.tokenizer.getContextRanges("arabicSentence"),t=0;t0&&(t|=this.fsSelectionValues.OBLIQUE),this.weightClass>=600&&(t|=this.fsSelectionValues.BOLD),t==0&&(t=this.fsSelectionValues.REGULAR)),e.panose&&Array.isArray(e.panose)||(e.panose=[0,0,0,0,0,0,0,0,0]),this.tables=Object.assign(e.tables,{os2:Object.assign({usWeightClass:e.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:e.widthClass||this.usWidthClasses.MEDIUM,bFamilyType:e.panose[0]||0,bSerifStyle:e.panose[1]||0,bWeight:e.panose[2]||0,bProportion:e.panose[3]||0,bContrast:e.panose[4]||0,bStrokeVariation:e.panose[5]||0,bArmStyle:e.panose[6]||0,bLetterform:e.panose[7]||0,bMidline:e.panose[8]||0,bXHeight:e.panose[9]||0,fsSelection:t},e.tables.os2)})}this.supported=!0,this.glyphs=new ue.GlyphSet(this,e.glyphs||[]),this.encoding=new Cr(this),this.position=new on(this),this.substitution=new sn(this),this.tables=this.tables||{},this.palettes=new cr(this),this.layers=new un(this),this.svgImages=new ln(this),this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){return this._hinting?this._hinting:this.outlinesFormat==="truetype"?this._hinting=new Fn(this):null}})}J.prototype.hasChar=function(e){return this.encoding.charToGlyphIndex(e)>0},J.prototype.charToGlyphIndex=function(e){return this.encoding.charToGlyphIndex(e)},J.prototype.charToGlyph=function(e){var t=this.charToGlyphIndex(e),r=this.glyphs.get(t);return r||(r=this.glyphs.get(0)),r},J.prototype.updateFeatures=function(e){return this.defaultRenderOptions.features.map(function(t){return t.script==="latn"?{script:"latn",tags:t.tags.filter(function(r){return e[r]})}:t})},J.prototype.stringToGlyphIndexes=function(e,t){var r=this,a=new so;a.registerModifier("glyphIndex",null,function(o){return r.charToGlyphIndex(o.char)});var n=t?this.updateFeatures(t.features):this.defaultRenderOptions.features;return a.applyFeatures(this,n),a.getTextGlyphs(e)},J.prototype.stringToGlyphs=function(e,t){for(var r=this.stringToGlyphIndexes(e,t),a=r.length,n=Array(a),o=this.glyphs.get(0),s=0;s0,"No English "+u+" specified.")}if(a("fontFamily"),a("weightName"),a("manufacturer"),a("copyright"),a("version"),r(this.unitsPerEm>0,"No unitsPerEm specified."),this.tables.colr)for(var n=this.tables.colr.baseGlyphRecords,o=-1,s=0;sn[s].glyphID)break;o=i}return e},J.prototype.toTables=function(){return tn.fontToTable(this)},J.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()},J.prototype.toArrayBuffer=function(){for(var e=this.toTables().encode(),t=new ArrayBuffer(e.length),r=new Uint8Array(t),a=0;a=1.2&&(n.markGlyphSets=r.parsePointer(ds)),n}};var be=Array(10);be[1]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();return t===1?{posFormat:1,coverage:this.parsePointer(v.coverage),value:this.parseValueRecord()}:t===2?{posFormat:2,coverage:this.parsePointer(v.coverage),values:this.parseValueRecordList()}:void R.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")},be[2]=function(){var e=this.offset+this.relativeOffset,t=this.parseUShort();R.assert(t===1||t===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");var r=this.parsePointer(v.coverage),a=this.parseUShort(),n=this.parseUShort();if(t===1)return{posFormat:t,coverage:r,valueFormat1:a,valueFormat2:n,pairSets:this.parseList(v.pointer(v.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(a),value2:this.parseValueRecord(n)}})))};if(t===2){var o=this.parsePointer(v.classDef),s=this.parsePointer(v.classDef),i=this.parseUShort(),u=this.parseUShort();return{posFormat:t,coverage:r,valueFormat1:a,valueFormat2:n,classDef1:o,classDef2:s,class1Count:i,class2Count:u,classRecords:this.parseList(i,v.list(u,function(){return{value1:this.parseValueRecord(a),value2:this.parseValueRecord(n)}}))}}},be[3]=function(){return{error:"GPOS Lookup 3 not supported"}},be[4]=function(){return{error:"GPOS Lookup 4 not supported"}},be[5]=function(){return{error:"GPOS Lookup 5 not supported"}},be[6]=function(){return{error:"GPOS Lookup 6 not supported"}},be[7]=function(){return{error:"GPOS Lookup 7 not supported"}},be[8]=function(){return{error:"GPOS Lookup 8 not supported"}},be[9]=function(){return{error:"GPOS Lookup 9 not supported"}};var vs=Array(10),uo={parse:function(e,t){var r=new v(e,t=t||0),a=r.parseVersion(1);return R.argument(a===1||a===1.1,"Unsupported GPOS table version "+a),a===1?{version:a,scripts:r.parseScriptList(),features:r.parseFeatureList(),lookups:r.parseLookupList(be)}:{version:a,scripts:r.parseScriptList(),features:r.parseFeatureList(),lookups:r.parseLookupList(be),variations:r.parseFeatureVariationsList()}},make:function(e){return new b.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new b.ScriptList(e.scripts)},{name:"features",type:"TABLE",value:new b.FeatureList(e.features)},{name:"lookups",type:"TABLE",value:new b.LookupList(e.lookups,vs)}])}};var lo={parse:function(e,t){var r=new k.Parser(e,t),a=r.parseUShort();if(a===0)return function(n){var o={};n.skip("uShort");var s=n.parseUShort();R.argument(s===0,"Unsupported kern sub-table version."),n.skip("uShort",2);var i=n.parseUShort();n.skip("uShort",3);for(var u=0;u1&&console.warn("Only the first kern subtable is supported."),n.skip("uLong");var s=n.parseUShort();if(n.skip("uShort"),(255&s)==0){var i=n.parseUShort();n.skip("uShort",3);for(var u=0;u Math.pow(value,2)); + const mseComponentLength = Math.trunc(xyzDiffSquared.length/3); + // Calculate the mean squared error for each channel + const mseX = selectArrayFromArray(xyzDiffSquared,3).reduce((sum,value) => sum+value,0)/mseComponentLength; + const mseY = selectArrayFromArray(xyzDiffSquared,3,1).reduce((sum,value) => sum+value,0)/mseComponentLength; + const mseZ = selectArrayFromArray(xyzDiffSquared,3,2).reduce((sum,value) => sum+value,0)/mseComponentLength; + // Calculate the mean squared error across all channels + mse = (mseX + mseY + mseZ) / 3; + } + + // Maximum possible pixel value (we are using floating point values) + const maxPixelValue = 1.0; + + // Return PSNR value. + return 20 * Math.log10(maxPixelValue / Math.sqrt(mse)); +} + +function xyzssim (image1, image2) { + const image1xyz = imageDataToXYZ(image1); + const image2xyz = imageDataToXYZ(image2); + const image1_x_channel = selectArrayFromArray(image1xyz,3); + const image1_y_channel = selectArrayFromArray(image1xyz,3,1); + const image1_z_channel = selectArrayFromArray(image1xyz,3,2); + const image2_x_channel = selectArrayFromArray(image2xyz,3); + const image2_y_channel = selectArrayFromArray(image2xyz,3,1); + const image2_z_channel = selectArrayFromArray(image2xyz,3,2); + const ssim_x = ssim.ssim({width:image1.width,height:image1.height,data:image1_x_channel}, {width:image2.width,height:image2.height,data:image2_x_channel}).mssim; + const ssim_y = ssim.ssim({width:image1.width,height:image1.height,data:image1_y_channel}, {width:image2.width,height:image2.height,data:image2_y_channel}).mssim; + const ssim_z = ssim.ssim({width:image1.width,height:image1.height,data:image1_z_channel}, {width:image2.width,height:image2.height,data:image2_z_channel}).mssim; + return (ssim_x + ssim_y + ssim_z) / 3; +} + +function compare(a,b){ + if(a && b){ + return {psnr: psnr(a,b), ssim: xyzssim(a,b)}; + } + throw new Error("No images to compare."); +} + +module.exports = compare; \ No newline at end of file diff --git a/src/__tests__/testfiles/fonts/OpenSans-Bold.ttf b/src/__tests__/testfiles/fonts/OpenSans-Bold.ttf new file mode 100644 index 0000000..98c74e0 Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-Bold.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-BoldItalic.ttf b/src/__tests__/testfiles/fonts/OpenSans-BoldItalic.ttf new file mode 100644 index 0000000..8558928 Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-BoldItalic.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-ExtraBold.ttf b/src/__tests__/testfiles/fonts/OpenSans-ExtraBold.ttf new file mode 100644 index 0000000..4eb3393 Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-ExtraBold.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-ExtraBoldItalic.ttf b/src/__tests__/testfiles/fonts/OpenSans-ExtraBoldItalic.ttf new file mode 100644 index 0000000..75789b4 Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-ExtraBoldItalic.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-Italic.ttf b/src/__tests__/testfiles/fonts/OpenSans-Italic.ttf new file mode 100644 index 0000000..29ff693 Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-Italic.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-Light.ttf b/src/__tests__/testfiles/fonts/OpenSans-Light.ttf new file mode 100644 index 0000000..ea175cc Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-Light.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-LightItalic.ttf b/src/__tests__/testfiles/fonts/OpenSans-LightItalic.ttf new file mode 100644 index 0000000..edbfe0b Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-LightItalic.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-Medium.ttf b/src/__tests__/testfiles/fonts/OpenSans-Medium.ttf new file mode 100644 index 0000000..ae71693 Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-Medium.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-MediumItalic.ttf b/src/__tests__/testfiles/fonts/OpenSans-MediumItalic.ttf new file mode 100644 index 0000000..6d1e09b Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-MediumItalic.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-Regular.ttf b/src/__tests__/testfiles/fonts/OpenSans-Regular.ttf new file mode 100644 index 0000000..67803bb Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-Regular.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-SemiBold.ttf b/src/__tests__/testfiles/fonts/OpenSans-SemiBold.ttf new file mode 100644 index 0000000..e5ab464 Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-SemiBold.ttf differ diff --git a/src/__tests__/testfiles/fonts/OpenSans-SemiBoldItalic.ttf b/src/__tests__/testfiles/fonts/OpenSans-SemiBoldItalic.ttf new file mode 100644 index 0000000..cd23e15 Binary files /dev/null and b/src/__tests__/testfiles/fonts/OpenSans-SemiBoldItalic.ttf differ diff --git a/src/__tests__/testfiles/fonts/Rosario-Regular.otf b/src/__tests__/testfiles/fonts/Rosario-Regular.otf new file mode 100644 index 0000000..bab03b7 Binary files /dev/null and b/src/__tests__/testfiles/fonts/Rosario-Regular.otf differ diff --git a/src/__tests__/testfiles/tag_tests.ass b/src/__tests__/testfiles/tag_tests.ass index ca422e2..26f4d8b 100644 --- a/src/__tests__/testfiles/tag_tests.ass +++ b/src/__tests__/testfiles/tag_tests.ass @@ -7,8 +7,8 @@ YCbCr Matrix: None [V4+ Styles] Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding -Style: Default,Arial,48,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1 -Style: Bold,Arial,48,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,1,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1 +Style: Default,Open Sans,48,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1 +Style: Bold,Open Sans,48,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,1,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1 [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text diff --git a/src/shader.js b/src/shader.js index 3ead336..26f9402 100644 --- a/src/shader.js +++ b/src/shader.js @@ -109,7 +109,16 @@ const ShaderPrototype = Object.create(Object, { this._textures = {}; this._attributes = {}; let xmlhttp = null; - if ( + if (typeof module !== 'undefined' && module.exports) { + const fs = require('fs'); + let response = fs.readFileSync(vertexUrl, "utf8"); + shaderlog[vertexUrl] = response; + this.vertSrc = response; + response = fs.readFileSync(fragmentUrl, "utf8"); + shaderlog[fragmentUrl] = response; + this.fragSrc = response; + return; + }else if ( typeof global.localStorage === "undefined" || typeof expire === "undefined" || expire <= 0