nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.35k stars 3.88k forks source link

Detect Installed Fonts #1710

Open benjismith opened 10 years ago

benjismith commented 10 years ago

I'm developing a word-processor-like application, and ideally, I'd like to detect all the installed fonts available on the user's system. But there doesn't seem to be any way of doing this from javascript.

In an ordinary web browser, I might be willing to try this hack, which uses the Flash Player to detect the font list and then Javascript to communicate with the Flash Player. But in a node-webkit environment, where the plugin situation is somewhat more complicated, and I'd rather not try to coerce the user into installing the flash player, it would be really nice to have this functionality provided by the NW container.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

rawcreative commented 10 years ago

+1 on this. The app I'm building needs support for this as well. On a Mac, in theory, you can traverse ~/Library/Fonts and /Library/Fonts to find all of the installed font files, though whether you can actually pull the names from those files is something I've yet to attempt. I haven't even looked into doing it on Windows or Linux so I don't know if something similar is possible or not.

CodeTrol commented 10 years ago

On Windows: %SystemRoot%/Fonts On Linux: /usr/share/fonts/truetype

benjismith commented 10 years ago

For each font, I need to know its family name, plus any additional details about its weight and style (bold, italic, condensed, etc)

I thought about just traversing all the files in the system's default font locations, but then I'd need to find (or write) file-format parsers in JavaScript for all the different font file formats: TTF, TTC, FNT, FON, OTF, and WOFF.

It seems silly to reimplement all that stuff in JavaScript, since the browser already needs to know the available system fonts in order to render the DOM. Why not just expose those existing browser capabilities to the JavaScript api?

jwu commented 10 years ago

+1, anyone knowns how to do this?

Mithgol commented 10 years ago

npm windows package has some .getFontNames() method; however, not without an issue (Benvie/node-Windows#8).