Pomax / lib-font

This library adds a new Font() object to the JavaScript toolbox, similar to new Image() for images
MIT License
730 stars 72 forks source link

Upload font #64

Closed RoelN closed 4 years ago

RoelN commented 4 years ago

What would be the preferred way to "upload" a font through drag/drop or a file input?

I saw this issue, which implies there is a mechanism in the new Font.js. But passing a base64 file trips up the filetype recognition.

Is there a cleaner way?

(Also, would file/font type detection be more thorough, e.g. by ignoring extension and checking on byte level?)

Pomax commented 4 years ago

You shouldn't be creating base64 data, Font operates on the plain data. If the problem is the getFontCSSFormat function not having that information then your solution of supplying the filename in addition to the data is a good solution.

Although let's not convert to Base64: it ends up inside of a binary DataView anyway, so base64 would just grow the memory by 1/3rd, and then undo that again.

Pomax commented 4 years ago

we added this =D