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

get a exception when init Font() with file name #122

Open
luckymore opened this issue Dec 10, 2024 · 4 comments
Open

get a exception when init Font() with file name #122

luckymore opened this issue Dec 10, 2024 · 4 comments

Comments

@luckymore
Copy link

I follow the doc here

import * as mupdfjs from 'mupdf'
import path from 'path'

console.log(mupdfjs)
const font = new mupdfjs.Font(path.resolve('./public/AKNTFL+CMBX10.ttf'))
console.log(font)

Then, mupdfjs consoled, and get an error below:

Error: cannot find builtin font with name '/Users/zhangningning/Documents/github/mupdf.js/examples/vue/public/AKNTFL+CMBX10.ttf'
    at 5735545 (file:///Users/zhangningning/Documents/github/mupdf.js/examples/vue/node_modules/mupdf/dist/mupdf-wasm.js:995:27)
    at runEmAsmFunction (file:///Users/zhangningning/Documents/github/mupdf.js/examples/vue/node_modules/mupdf/dist/mupdf-wasm.js:4272:30)
    at _emscripten_asm_const_int (file:///Users/zhangningning/Documents/github/mupdf.js/examples/vue/node_modules/mupdf/dist/mupdf-wasm.js:4275:14)
    at wasm://wasm/023c430a:wasm-function[111]:0x8286
    at invoke_vi (file:///Users/zhangningning/Documents/github/mupdf.js/examples/vue/node_modules/mupdf/dist/mupdf-wasm.js:5713:29)
    at wasm://wasm/023c430a:wasm-function[259]:0xf172
    at Object._wasm_new_base14_font (file:///Users/zhangningning/Documents/github/mupdf.js/examples/vue/node_modules/mupdf/dist/mupdf-wasm.js:705:12)
    at new Font (file:///Users/zhangningning/Documents/github/mupdf.js/examples/vue/node_modules/mupdf/dist/mupdf.js:520:36)
    at file:///Users/zhangningning/Documents/github/mupdf.js/examples/vue/test.mjs:5:14

Node.js v22.1.0
mupdf.js 1.0.0

@jamie-lemon
Copy link
Collaborator

I would try the following to load a font:

import * as fs from "fs"

let font_buffer = fs.readFileSync("./public/AKNTFL+CMBX10.ttf")
const font = await new mupdfjs.Font('name-of-your-font', font_buffer)
console.log("font="+font.getName())

This is because only the built in fonts can be constructed with just a string. You need to use a different method where you supply the font buffer data. My mistake in the documentation - I will update the documentation to include the other constructor methods for Font.

Having said this we have a related problem with using fonts, so you may run into this issue too:

#120

@luckymore
Copy link
Author

I have tried this, but get false.

import * as fs from "fs"
import * as mupdfjs from 'mupdf'

let font_buffer = fs.readFileSync("./public/8aeac737-de2d-42ce-8db1-d8641c14d579")
const font = await new mupdfjs.Font('name-of-your-font', font_buffer)
console.log(font.isBold())

fontfile

@jamie-lemon
Copy link
Collaborator

@luckymore The font file doesn't look like a font file to me?

@luckymore
Copy link
Author

add file ext .otf is ok, look this please

fontfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants