Merge pull request #12532 from Snuffleupagus/refactor-font-tests
Modernize, and remove SystemJS usage from, the font-tests
This commit is contained in:
commit
8098102714
@ -13,5 +13,4 @@ test/tmp/
|
||||
test/features/
|
||||
test/pdfs/
|
||||
test/resources/
|
||||
test/font/*_spec.js
|
||||
*~/
|
||||
|
10
test/font/.eslintrc
Normal file
10
test/font/.eslintrc
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": [
|
||||
"../.eslintrc"
|
||||
],
|
||||
|
||||
"rules": {
|
||||
// ECMAScript 6
|
||||
"no-var": "error",
|
||||
},
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
'use strict';
|
||||
import { decodeFontData, ttx, verifyTtxOutput } from "./fontutils.js";
|
||||
|
||||
describe('font1', function() {
|
||||
var font1_1 = decodeFontData('T1RUTwAJAIAAAwAQQ0ZGIP/t0rAAAACcAAADKU9TLzJDxycMAAADyAAAAGBjbWFwwFIBcgAABCgAAABUaGVhZKsnTJ4AAAR8AAAANmhoZWEDHvxTAAAEtAAAACRobXR4AAAAAAAABNgAAAA4bWF4cAAOUAAAAAUQAAAABm5hbWX8Fq+xAAAFGAAAAfhwb3N0AAMAAAAABxAAAAAgAQAEAgABAQEMS0hQRkxFK01UU1kAAQEBOfgeAPgfAfggAvghA/gXBIv+Tvqn+bAFHQAAAMgPHQAAAL0QHQAAANsRHQAAACcdAAADARL4IAwWAAcBAQgUGx5TV19yYWRpY2FsY2lyY2xlY29weXJ0c2ltaWxhcjEuMUNvcHlyaWdodCAoQykgMTk5MiwgMTk5MyBUaGUgVGVYcGxvcmF0b3JzIENvcnBvcmF0aW9uTVRTWU1hdGhUaW1lAAAAAAkAAg0YQ0RmZ3AAAKYAqAGIAYkADAAeAFwAXgGHAAoCAAEAAwAWAFoAtgDxARcBNgGKAd4CDiAO93W9Ad/4+AP5TPd1Fb38+FkHDvfslp/3PtH3Pp8B9xjR9zDQ9zDRFPz4P/eAFfd193UFRQb7UvtS+1L3UgVFBvd1+3X7dvt1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AAAAAAAAAAAAAAAAAAAAAABQAAAOAAAAAAAUAPYAAQAAAAAAAAAQAAAAAQAAAAAAAQALABAAAQAAAAAAAgAHABsAAQAAAAAAAwAIACIAAQAAAAAABAALACoAAQAAAAAABQAMADUAAQAAAAAABgAAAEEAAQAAAAAABwAHAEEAAQAAAAAACAAHAEgAAQAAAAAACQAHAE8AAwABBAkAAAAgAFYAAwABBAkAAQAWAHYAAwABBAkAAgAOAIwAAwABBAkAAwAQAJoAAwABBAkABAAWAKoAAwABBAkABQAYAMAAAwABBAkABgAAANgAAwABBAkABwAOANgAAwABBAkACAAOAOYAAwABBAkACQAOAPRPcmlnaW5hbCBsaWNlbmNlS0hQRkxFK01UU1lVbmtub3dudW5pcXVlSURLSFBGTEUrTVRTWVZlcnNpb24gMC4xMVVua25vd25Vbmtub3duVW5rbm93bgBPAHIAaQBnAGkAbgBhAGwAIABsAGkAYwBlAG4AYwBlAEsASABQAEYATABFACsATQBUAFMAWQBVAG4AawBuAG8AdwBuAHUAbgBpAHEAdQBlAEkARABLAEgAUABGAEwARQArAE0AVABTAFkAVgBlAHIAcwBpAG8AbgAgADAALgAxADEAVQBuAGsAbgBvAHcAbgBVAG4AawBuAG8AdwBuAFUAbgBrAG4AbwB3AG4AAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==');
|
||||
describe('test harness testing', function() {
|
||||
it('returns output', function(done) {
|
||||
ttx(font1_1, function(output) {
|
||||
describe("font1", function () {
|
||||
const font1_1 = decodeFontData(
|
||||
// eslint-disable-next-line max-len
|
||||
"T1RUTwAJAIAAAwAQQ0ZGIP/t0rAAAACcAAADKU9TLzJDxycMAAADyAAAAGBjbWFwwFIBcgAABCgAAABUaGVhZKsnTJ4AAAR8AAAANmhoZWEDHvxTAAAEtAAAACRobXR4AAAAAAAABNgAAAA4bWF4cAAOUAAAAAUQAAAABm5hbWX8Fq+xAAAFGAAAAfhwb3N0AAMAAAAABxAAAAAgAQAEAgABAQEMS0hQRkxF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AG4AbwB3AG4AAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
|
||||
);
|
||||
|
||||
describe("test harness testing", function () {
|
||||
it("returns output", function (done) {
|
||||
ttx(font1_1, function (output) {
|
||||
verifyTtxOutput(output);
|
||||
expect(/<ttFont /.test(output)).toEqual(true);
|
||||
expect(/<\/ttFont>/.test(output)).toEqual(true);
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -5,20 +5,22 @@
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
|
||||
|
||||
<script src="../../node_modules/systemjs/dist/system.js"></script>
|
||||
<script src="../../systemjs.config.js"></script>
|
||||
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
|
||||
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
|
||||
<script src="../unit/testreporter.js"></script>
|
||||
<script src="jasmine-boot.js"></script>
|
||||
|
||||
<script src="fontutils.js"></script>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script src="font_core_spec.js"></script>
|
||||
<script src="font_os2_spec.js"></script>
|
||||
<script src="font_post_spec.js"></script>
|
||||
<script src="font_fpgm_spec.js"></script>
|
||||
<script defer src="../../node_modules/es-module-shims/dist/es-module-shims.js"></script>
|
||||
<script type="importmap-shim">
|
||||
{
|
||||
"imports": {
|
||||
"pdfjs/": "../../src/",
|
||||
"pdfjs-lib": "../../src/pdf.js",
|
||||
"pdfjs-web/": "../../web/",
|
||||
"pdfjs-test/": "../"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script src="jasmine-boot.js" type="module-shim"></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
|
@ -14,23 +14,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
var base64alphabet =
|
||||
const base64alphabet =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function decodeFontData(base64) {
|
||||
var result = [];
|
||||
const result = [];
|
||||
|
||||
var bits = 0,
|
||||
let bits = 0,
|
||||
bitsLength = 0;
|
||||
for (var i = 0, ii = base64.length; i < ii; i++) {
|
||||
var ch = base64[i];
|
||||
for (let i = 0, ii = base64.length; i < ii; i++) {
|
||||
const ch = base64[i];
|
||||
if (ch <= " ") {
|
||||
continue;
|
||||
}
|
||||
var index = base64alphabet.indexOf(ch);
|
||||
const index = base64alphabet.indexOf(ch);
|
||||
if (index < 0) {
|
||||
throw new Error("Invalid character");
|
||||
}
|
||||
@ -41,7 +38,7 @@ function decodeFontData(base64) {
|
||||
bitsLength += 6;
|
||||
if (bitsLength >= 8) {
|
||||
bitsLength -= 8;
|
||||
var code = (bits >> bitsLength) & 0xff;
|
||||
const code = (bits >> bitsLength) & 0xff;
|
||||
result.push(code);
|
||||
}
|
||||
}
|
||||
@ -49,16 +46,16 @@ function decodeFontData(base64) {
|
||||
}
|
||||
|
||||
function encodeFontData(data) {
|
||||
var buffer = "";
|
||||
var i, n;
|
||||
let buffer = "";
|
||||
let i, n;
|
||||
for (i = 0, n = data.length; i < n; i += 3) {
|
||||
var b1 = data[i] & 0xff;
|
||||
var b2 = data[i + 1] & 0xff;
|
||||
var b3 = data[i + 2] & 0xff;
|
||||
var d1 = b1 >> 2,
|
||||
const b1 = data[i] & 0xff;
|
||||
const b2 = data[i + 1] & 0xff;
|
||||
const b3 = data[i + 2] & 0xff;
|
||||
const d1 = b1 >> 2,
|
||||
d2 = ((b1 & 3) << 4) | (b2 >> 4);
|
||||
var d3 = i + 1 < n ? ((b2 & 0xf) << 2) | (b3 >> 6) : 64;
|
||||
var d4 = i + 2 < n ? b3 & 0x3f : 64;
|
||||
const d3 = i + 1 < n ? ((b2 & 0xf) << 2) | (b3 >> 6) : 64;
|
||||
const d4 = i + 2 < n ? b3 & 0x3f : 64;
|
||||
buffer +=
|
||||
base64alphabet.charAt(d1) +
|
||||
base64alphabet.charAt(d2) +
|
||||
@ -68,12 +65,11 @@ function encodeFontData(data) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function ttx(data, callback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/ttx");
|
||||
|
||||
var encodedData = encodeFontData(data);
|
||||
const encodedData = encodeFontData(data);
|
||||
xhr.setRequestHeader("Content-type", "text/plain");
|
||||
xhr.setRequestHeader("Content-length", encodedData.length);
|
||||
|
||||
@ -89,10 +85,11 @@ function ttx(data, callback) {
|
||||
xhr.send(encodedData);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function verifyTtxOutput(output) {
|
||||
var m = /^<error>(.*?)<\/error>/.exec(output);
|
||||
const m = /^<error>(.*?)<\/error>/.exec(output);
|
||||
if (m) {
|
||||
throw m[1];
|
||||
}
|
||||
}
|
||||
|
||||
export { decodeFontData, encodeFontData, ttx, verifyTtxOutput };
|
||||
|
@ -40,26 +40,20 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
function initializePDFJS(callback) {
|
||||
Promise.all([
|
||||
SystemJS.import("pdfjs/core/fonts.js"),
|
||||
SystemJS.import("pdfjs/core/stream.js"),
|
||||
SystemJS.import("pdfjs/core/primitives.js"),
|
||||
SystemJS.import("pdfjs/core/cmap.js"),
|
||||
]).then(function (modules) {
|
||||
var fonts = modules[0],
|
||||
stream = modules[1],
|
||||
primitives = modules[2],
|
||||
cmap = modules[3];
|
||||
// Expose some of the PDFJS members to global scope for tests.
|
||||
window.Font = fonts.Font;
|
||||
window.ToUnicodeMap = fonts.ToUnicodeMap;
|
||||
window.Stream = stream.Stream;
|
||||
window.Name = primitives.Name;
|
||||
window.CMapFactory = cmap.CMapFactory;
|
||||
async function initializePDFJS(callback) {
|
||||
await Promise.all(
|
||||
[
|
||||
"pdfjs-test/font/font_core_spec.js",
|
||||
"pdfjs-test/font/font_os2_spec.js",
|
||||
"pdfjs-test/font/font_post_spec.js",
|
||||
"pdfjs-test/font/font_fpgm_spec.js",
|
||||
].map(function (moduleName) {
|
||||
// eslint-disable-next-line no-unsanitized/method
|
||||
return import(moduleName);
|
||||
})
|
||||
);
|
||||
|
||||
callback();
|
||||
});
|
||||
callback();
|
||||
}
|
||||
|
||||
(function () {
|
||||
@ -67,36 +61,36 @@ function initializePDFJS(callback) {
|
||||
|
||||
jasmineRequire.html(jasmine);
|
||||
|
||||
var env = jasmine.getEnv();
|
||||
const env = jasmine.getEnv();
|
||||
|
||||
var jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
const jasmineInterface = jasmineRequire.interface(jasmine, env);
|
||||
extend(window, jasmineInterface);
|
||||
|
||||
// Runner Parameters
|
||||
var queryString = new jasmine.QueryString({
|
||||
const queryString = new jasmine.QueryString({
|
||||
getWindowLocation() {
|
||||
return window.location;
|
||||
},
|
||||
});
|
||||
|
||||
var config = {
|
||||
const config = {
|
||||
failFast: queryString.getParam("failFast"),
|
||||
oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
|
||||
hideDisabled: queryString.getParam("hideDisabled"),
|
||||
};
|
||||
|
||||
var random = queryString.getParam("random");
|
||||
const random = queryString.getParam("random");
|
||||
if (random !== undefined && random !== "") {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
var seed = queryString.getParam("seed");
|
||||
const seed = queryString.getParam("seed");
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
|
||||
// Reporters
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
const htmlReporter = new jasmine.HtmlReporter({
|
||||
env,
|
||||
navigateWithNewParam(key, value) {
|
||||
return queryString.navigateWithNewParam(key, value);
|
||||
@ -119,13 +113,13 @@ function initializePDFJS(callback) {
|
||||
env.addReporter(htmlReporter);
|
||||
|
||||
if (queryString.getParam("browser")) {
|
||||
var testReporter = new TestReporter(queryString.getParam("browser"));
|
||||
const testReporter = new TestReporter(queryString.getParam("browser"));
|
||||
env.addReporter(testReporter);
|
||||
}
|
||||
|
||||
// Filter which specs will be run by matching the start of the full name
|
||||
// against the `spec` query param.
|
||||
var specFilter = new jasmine.HtmlSpecFilter({
|
||||
const specFilter = new jasmine.HtmlSpecFilter({
|
||||
filterString() {
|
||||
return queryString.getParam("spec");
|
||||
},
|
||||
@ -140,26 +134,26 @@ function initializePDFJS(callback) {
|
||||
// Sets longer timeout.
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||
|
||||
// Replace the browser window's `onload`, ensure it's called, and then run
|
||||
// all of the loaded specs. This includes initializing the `HtmlReporter`
|
||||
// instance and then executing the loaded Jasmine environment.
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function () {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
|
||||
initializePDFJS(function () {
|
||||
htmlReporter.initialize();
|
||||
env.execute();
|
||||
});
|
||||
};
|
||||
|
||||
function extend(destination, source) {
|
||||
for (var property in source) {
|
||||
for (const property in source) {
|
||||
destination[property] = source[property];
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
function fontTestInit() {
|
||||
initializePDFJS(function () {
|
||||
htmlReporter.initialize();
|
||||
env.execute();
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
document.readyState === "interactive" ||
|
||||
document.readyState === "complete"
|
||||
) {
|
||||
fontTestInit();
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", fontTestInit, true);
|
||||
}
|
||||
})();
|
||||
|
@ -16,34 +16,34 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var spawn = require("child_process").spawn;
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const spawn = require("child_process").spawn;
|
||||
|
||||
var ttxResourcesHome = path.join(__dirname, "..", "ttx");
|
||||
const ttxResourcesHome = path.join(__dirname, "..", "ttx");
|
||||
|
||||
var nextTTXTaskId = Date.now();
|
||||
let nextTTXTaskId = Date.now();
|
||||
|
||||
function runTtx(ttxResourcesHomePath, fontPath, registerOnCancel, callback) {
|
||||
fs.realpath(ttxResourcesHomePath, function (error, realTtxResourcesHomePath) {
|
||||
var fontToolsHome = path.join(realTtxResourcesHomePath, "fonttools-code");
|
||||
const fontToolsHome = path.join(realTtxResourcesHomePath, "fonttools-code");
|
||||
fs.realpath(fontPath, function (errorFontPath, realFontPath) {
|
||||
var ttxPath = path.join("Tools", "ttx");
|
||||
const ttxPath = path.join("Tools", "ttx");
|
||||
if (!fs.existsSync(path.join(fontToolsHome, ttxPath))) {
|
||||
callback("TTX was not found, please checkout PDF.js submodules");
|
||||
return;
|
||||
}
|
||||
var ttxEnv = {
|
||||
const ttxEnv = {
|
||||
PYTHONPATH: path.join(fontToolsHome, "Lib"),
|
||||
PYTHONDONTWRITEBYTECODE: true,
|
||||
};
|
||||
var ttxStdioMode = "ignore";
|
||||
var ttx = spawn("python", [ttxPath, realFontPath], {
|
||||
const ttxStdioMode = "ignore";
|
||||
const ttx = spawn("python", [ttxPath, realFontPath], {
|
||||
cwd: fontToolsHome,
|
||||
stdio: ttxStdioMode,
|
||||
env: ttxEnv,
|
||||
});
|
||||
var ttxRunError;
|
||||
let ttxRunError;
|
||||
registerOnCancel(function (reason) {
|
||||
ttxRunError = reason;
|
||||
callback(reason);
|
||||
@ -68,10 +68,10 @@ exports.translateFont = function translateFont(
|
||||
registerOnCancel,
|
||||
callback
|
||||
) {
|
||||
var buffer = Buffer.from(content, "base64");
|
||||
var taskId = (nextTTXTaskId++).toString();
|
||||
var fontPath = path.join(ttxResourcesHome, taskId + ".otf");
|
||||
var resultPath = path.join(ttxResourcesHome, taskId + ".ttx");
|
||||
const buffer = Buffer.from(content, "base64");
|
||||
const taskId = (nextTTXTaskId++).toString();
|
||||
const fontPath = path.join(ttxResourcesHome, taskId + ".otf");
|
||||
const resultPath = path.join(ttxResourcesHome, taskId + ".ttx");
|
||||
|
||||
fs.writeFileSync(fontPath, buffer);
|
||||
runTtx(ttxResourcesHome, fontPath, registerOnCancel, function (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user