1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 08:08:07 +02:00

Include and use the 14 standard fonts files.

This commit is contained in:
Brendan Dahl 2020-12-10 17:32:18 -08:00
parent 3456ed271b
commit 4c1dd47e65
36 changed files with 463 additions and 80 deletions

View file

@ -21,6 +21,7 @@ const WAITING_TIME = 100; // ms
const PDF_TO_CSS_UNITS = 96.0 / 72.0;
const CMAP_URL = "../external/bcmaps/";
const CMAP_PACKED = true;
const STANDARD_FONT_DATA_URL = "/build/generic/web/standard_fonts/";
const IMAGE_RESOURCES_PATH = "/web/images/";
const WORKER_SRC = "../build/generic/build/pdf.worker.js";
const RENDER_TASK_ON_CONTINUE_DELAY = 5; // ms
@ -415,9 +416,12 @@ var Driver = (function DriverClosure() {
password: task.password,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
standardFontDataUrl: STANDARD_FONT_DATA_URL,
disableRange: task.disableRange,
disableAutoFetch: !task.enableAutoFetch,
pdfBug: true,
useSystemFonts: task.useSystemFonts,
useWorkerFetch: task.useWorkerFetch,
});
loadingTask.promise.then(
doc => {

View file

@ -215,6 +215,7 @@
!bug1473809.pdf
!issue12120_reduced.pdf
!pdfjsbad1586.pdf
!standard_fonts.pdf
!freeculture.pdf
!issue6006.pdf
!pdfkit_compressed.pdf

Binary file not shown.

View file

@ -1974,6 +1974,28 @@
"link": true,
"type": "eq"
},
{ "id": "standard_fonts_system_fonts",
"file": "pdfs/standard_fonts.pdf",
"md5": "bb3a9ab3322328be983e8b4e8089843a",
"rounds": 1,
"type": "eq",
"useSystemFonts": true
},
{ "id": "standard_fonts_no_system_fonts",
"file": "pdfs/standard_fonts.pdf",
"md5": "bb3a9ab3322328be983e8b4e8089843a",
"rounds": 1,
"type": "eq",
"useSystemFonts": false
},
{ "id": "standard_fonts_main_thread_fetch",
"file": "pdfs/standard_fonts.pdf",
"md5": "bb3a9ab3322328be983e8b4e8089843a",
"rounds": 1,
"type": "eq",
"useSystemFonts": false,
"useWorkerFetch": false
},
{ "id": "issue4573",
"file": "pdfs/issue4573.pdf",
"md5": "34b0c4fdee19e57033275b766c5f57a3",

View file

@ -29,10 +29,18 @@ import {
stringToBytes,
stringToUTF8String,
} from "../../src/shared/util.js";
import { CMAP_PARAMS, createIdFactory, XRefMock } from "./test_utils.js";
import {
CMAP_PARAMS,
createIdFactory,
STANDARD_FONT_DATA_URL,
XRefMock,
} from "./test_utils.js";
import {
DefaultCMapReaderFactory,
DefaultStandardFontDataFactory,
} from "../../src/display/api.js";
import { Dict, Name, Ref, RefSetCache } from "../../src/core/primitives.js";
import { Lexer, Parser } from "../../src/core/parser.js";
import { DefaultCMapReaderFactory } from "../../src/display/api.js";
import { PartialEvaluator } from "../../src/core/evaluator.js";
import { StringStream } from "../../src/core/stream.js";
import { WorkerTask } from "../../src/core/worker.js";
@ -68,6 +76,10 @@ describe("annotation", function () {
}
}
const fontDataReader = new DefaultStandardFontDataFactory({
baseUrl: STANDARD_FONT_DATA_URL,
});
function HandlerMock() {
this.inputs = [];
}
@ -75,6 +87,12 @@ describe("annotation", function () {
send(name, data) {
this.inputs.push({ name, data });
},
sendWithPromise(name, data) {
if (name !== "FetchStandardFontData") {
return Promise.reject(new Error(`Unsupported mock ${name}.`));
}
return fontDataReader.fetch(data);
},
};
let pdfManagerMock, idFactoryMock, partialEvaluator;
@ -2282,7 +2300,6 @@ describe("annotation", function () {
]);
const task = new WorkerTask("test print");
const checkboxEvaluator = partialEvaluator.clone({ ignoreErrors: true });
const annotation = await AnnotationFactory.create(
xref,
buttonWidgetRef,
@ -2306,7 +2323,7 @@ describe("annotation", function () {
OPS.showText,
OPS.endAnnotation,
]);
expect(operatorList.argsArray[3][0][0].fontChar).toEqual("✔");
expect(operatorList.argsArray[3][0][0].unicode).toEqual("4");
});
it("should render checkboxes for printing", async function () {

View file

@ -1518,18 +1518,20 @@ describe("api", function () {
const pdfPage = await pdfDoc.getPage(1);
const { items, styles } = await pdfPage.getTextContent();
expect(items.length).toEqual(1);
expect(Object.keys(styles)).toEqual(["Times"]);
// Font name will a random object id.
const fontName = items[0].fontName;
expect(Object.keys(styles)).toEqual([fontName]);
expect(items[0]).toEqual({
dir: "ltr",
fontName: "Times",
fontName,
height: 18,
str: "Issue 8276",
transform: [18, 0, 0, 18, 441.81, 708.4499999999999],
width: 77.49,
hasEOL: false,
});
expect(styles.Times).toEqual({
expect(styles[fontName]).toEqual({
fontFamily: "serif",
ascent: NaN,
descent: NaN,
@ -1678,7 +1680,7 @@ describe("api", function () {
const expectedStreamTypes = {};
expectedStreamTypes[StreamType.FLATE] = true;
const expectedFontTypes = {};
expectedFontTypes[FontType.TYPE1] = true;
expectedFontTypes[FontType.TYPE1STANDARD] = true;
expectedFontTypes[FontType.CIDFONTTYPE2] = true;
expect(stats).toEqual({

View file

@ -26,6 +26,10 @@ const CMAP_PARAMS = {
cMapPacked: true,
};
const STANDARD_FONT_DATA_URL = isNodeJS
? "./external/standard_fonts/"
: "../../external/standard_fonts/";
class DOMFileReaderFactory {
static async fetch(params) {
const response = await fetch(params.path);
@ -61,6 +65,7 @@ function buildGetDocumentParams(filename, options) {
params.url = isNodeJS
? TEST_PDFS_PATH + filename
: new URL(TEST_PDFS_PATH + filename, window.location).href;
params.standardFontDataUrl = STANDARD_FONT_DATA_URL;
for (const option in options) {
params[option] = options[option];
@ -146,6 +151,7 @@ export {
createIdFactory,
DefaultFileReaderFactory,
isEmptyObj,
STANDARD_FONT_DATA_URL,
TEST_PDFS_PATH,
XRefMock,
};