Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test cases for non-Latin fonts. #99

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading