-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test cases for non-Latin fonts. (#99)
* add non_latin_font_names_test.ts * add test pdf
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.