Skip to content

Commit

Permalink
Added test cases for non-Latin fonts. (#99)
Browse files Browse the repository at this point in the history
* add non_latin_font_names_test.ts

* add test pdf
  • Loading branch information
mipo1357 authored Jul 18, 2024
1 parent cb04a26 commit c48c442
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/tests/src/non_latin_font_names.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as fs from "fs";
import * as mupdf from "mupdf";
import * as path from "path";
import { describe, expect, it } from "vitest";

const scriptdir = path.resolve(__dirname);
const filename = path.join(scriptdir, "resources", "has-bad-fonts.pdf");
const fileData = fs.readFileSync(filename);

describe("Non-Latin font names test", () => {
it("should handle PDFs with non-Latin font names", async () => {
const document = await mupdf.Document.openDocument(fileData, "application/pdf") as mupdf.PDFDocument;
const page = document.loadPage(0);
const pageObj = page.getObject();
const resources = pageObj.get("Resources");
const fonts = resources.get("Font");

console.log(`File '${filename}' uses the following fonts on page 0:`);

const fontNames: string[] = [];
fonts.forEach((value, key) => {
const fontName = value.get("BaseFont").asName();
fontNames.push(fontName);
});

expect(fontNames.length).toBeGreaterThan(0);

const hasNonLatinFont = fontNames.some(name => /[^\u0000-\u007F]/.test(name));
expect(hasNonLatinFont).toBe(true);

document.destroy();
});
});
Binary file added examples/tests/src/resources/has-bad-fonts.pdf
Binary file not shown.
Binary file added examples/tests/src/resources/test.pdf
Binary file not shown.

0 comments on commit c48c442

Please sign in to comment.