Search posts, tags, users, and pages
What you want to do is query for system fonts. With pure JS, that's not possible.
What you can do is check if a font exists. You can do so by
If the screenshot is not blank and has changed pixels, the font exists. You could make a list of fonts you want to include in the list and check for them that way. Check out my reference implementation!
Other than that, you could use a Flash or Java program, which most likely will not run anyway because of security considerations in modern browsers.
The simplest option, however, would be to just provide a set of fonts yourself. Make sure to check the licenses first, though!
Thanks, I just wanted to ensure that there is no way to do this —
I do not want to manually keep track of an array of fonts that I have to then check for availability in the browser. Is there no way to automagically get the names of all the native fonts, without doing so?
which you already included in your answer.
Beware the pixel comparison can fail depending on which OS and browser engine you are using, since all OS use different renderers, and not all browsers even render with the same kerning on the same OS.
Hell some font rendering engines can't even kern the characters and form the same glyphs the same way twice on the same page with the same word! freetype is NOTORIOUS for this and just PART of why I consider Linsux as a desktop OS to be near useless crippleware!
So you'd have to get browser sniffing involved, have multiple different static images involved, and at that bloody point...
Just use a webfont!
Though stick to the 'websafe' stacks for content, since most webfonts render like trash from an accessibility standpoint! You want it for an effect or decoration, fine... just for the love of Christmas don't do it on flow text!
... and if that upsets some artist under the DELUSION they're a "web designer", f** 'em!*
Jason Knight still better than the span-length comparison, which was the only way I found online... while a pixel comparison always is a hacky way to do stuff, I don't see a better way to check if a font is available other than to use it and see if it is rendered by the browser.
By the way, I actively use a Linux Distro, and I cannot confirm your claim that it is near useless crippleware or even that freetype cannot render a glyph the same way twice. I get nice and sharp characters on every redraw. I never heard of your problem before, so maybe that bug is fixed by now? Freetype is used by lots and lots of graphics software in 2D and 3D, even on Windows and macOS, and it works there, too, so I highly doubt that it is that bad. I even once used it myself for debug text for a game...
Arihant I created a sample implementation of the pixel based check. It's a quick and dirty pen, but you should get the gist of it. There is no way to auto-magically get all installed fonts, but you might have your user input a font-name and check if it exists, then store it in localStorage for them to re-use later. You might only provide a list of websafe fonts as a standard font stack, then (and maybe check for the most common ones for Windows, macOS and Linux Distros, like Calibri, Segoe UI, Helvetica, San Francisco, Roboto, Noto,...
Marco Alka The problem is most evident in 'normal' font sizes such as in browsers or in OoO. SOMEHOW Blink based browsers avoid this issue -- to the point I wonder if they're using their own renderer or at least kerning engine.
It's a common problem when the 'word level' kerning in freetype is 'glyph preserving at all costs' without paying attention to the subpixel hammering -- even when subpixel RENDERING is enabled. I'm particularly sensitive to it though many people are not.
It's not as bad as it used to be, and higher PPI displays make it far FAR less pronounced... but check out this 'worst case' scenario that I can STILL make most Linux distro's do with the right combination of font-size and face. Keep in mind this pic is the "perfect storm" of it happening in the extreme.

It be spacin g!
It's just ANOTHER of dozens if not hundreds of little glitches and niggles that make it crippled for me as a desktop OS... alongside the crippled video performance, agonizing audio latency (I'm also a musician), lack of consistent API's for audio production, crippled audio drivers that half the time require you to start screwing around with mod-probe if you DARE to let the system 'sleep' -- (don't get me started over how after a decade "hibernate" is still a banjaxed MESS!), lack of proper user queues on the desktop that a damned thing is actually happening, and in terms of useful content production tools apart from browsers, Gimp, and Blender you're looking at half-assed pathetic attempts that make most indie games look polished and professional. to the point to do half the damned stuff I want to do on a desktop OS machine I'm either running Wine -- at which point why bother -- or dicking around with needlessly complex agonizingly convoluted 1960's style command line BS. I wanted to waste time with that crap I'd drag out my Trash-80 Model 12 and boot up Xenix! Actually no... I'd power up the Coco 3 and use NitroOS9
DAMNED fine server OS... on the desktop? No... Just no. and a LOT of that are the X11 implementations hanging around its neck like a dead albatross. There's a reason Apple didn't use it (and ran their X11 compatibility atop their own stack) and Google are abandoning it.
Oh, that power saving and overall power consumption is through the roof sucking away a third of my battery life on mobile and elevating my electric bill across the board? Doesn't help!
... and apologies for the drift -- don't know how people feel 'bout that round here.
Jason Knight I don't think that Linux distros are the problem here, though. It's more a problem of the configuration, how the packages were compiled. I use Gentoo, so i decide what I want in them, but often, certain flags are omitted, because of patents and licenses and unfree code. A sad reality! It's the same for most other stuff. video quality is really good, if you select the right software with the right config. Audio latency is extremely low with JACK, however you usually get PulseAudio, which was not made for studio-quality audio processing. I can see why you have a lot of trouble, and I can see why the Linux folks want to have a tinker-y system. It all has its pros and cons. Imho, a Linux Distro can be a damn fine desktop OS, but usually it is not, because the Distro you selected has a different audience or maintainers with different ideas of how things should work.
Here are some positive examples of how well a Linux can work: Android is Linux. It powers most mobile devices and does a damn fine job, even with the energy consumption. Clear Linux (by Intel) is a power horse. If you ever need performance and nothing else matters, that's the way to go. KaOS is a quite unknown, Neon-like distro, which is user-oriented, pleasant and out-of-the-way, keeping your weak 2010 laptop kicking.
Yeah, I know, I try to defend something which I don't really have to. A Linux distro might not be the right OS for you, if you do not like to tinker and prefer to use Wine anyway. Anything Linux is always a mixed bag and might present problems, which stem from some small package you wouldn't even think is involved with your software. It can be very tedious. I like how solveing a problem is rewarding, though, so for me, a Linux distro usually is a rather positive experience.
... and apologies for the drift -- don't know how people feel 'bout that round her
well, why not? It's always nice to talk about stuff, and we still don't really have a chat system or OT corner. Also, we are not annoying anyone with our replies :D Well, we might need something like that. I will talk to the Hashnode Team and see what we can get.
Marco Alka Jack does fix some issues, but it still comes in at around 65ns latency, which for a professional musician is still DOUBLE the acceptable limit. Said latency also has a minimum packet size of 1k, where most musicians want a quarter of that. End effect being the equivalent of 240-260ms latency against an ASIO ready OS like OSX.
Like there's no way I could stomach playing sample modeling's VST's through linux even with jack -- it would be like trying to use directX for the same task, it just can't deliver.
NOT that Windows is any better on that front with the shitstorm that is a LACK of ASIO and the bigger shitstorm of workarounds like ASIO4ALL, but at least I can get it working with latencies down where I 'need' them in terms of 1) responsiveness for playing MIDI controllers like the EWI or external keyboards, and 2) syncing realtime play to playback.
Though in this case despite my distaste for it, the prize on this one subject goes to OSX. working multi-channel ASIO 'out of box' with zero configuration nightmares. EVEN THOUGH Creative cards and some specialty cards like Asus Xonar CLAIM ASIO support on windows, it's still quite iffy. As evidenced by the five to ten seconds of "is this even working?!?" when you try to open the configuration/setup screens for them or when an application using them starts.
But again it's just one after another after another of issues like that with ZERO practical fixes that make me look at the Linux desktop as crippleware. No one of them would be a deal-breaker on its own, but there's just too many of them to even list.
You called it a 'mixed bag' -- that's being polite about it.
Jason Knight well, I am not too versed with ASIO, so it's hard for me to judge. I got a Xonar card myself, and I at least know about a few itches which took quite a few months to fix on Linux.
It's a shame, really. I would love to see a lot more FLOSS software being used everywhere, without walled gardens. Companies working together on open standards and quality products. Not only software, but hardware, too. But pay-for-support does not seem to rake in enough money on the consumer market, and the best alternative, selling ads, would 1) not work anymore and 2) be completely against my wishes for privacy. The world today is a bad place for hoping that such dreams become a reality~
Seems like we have to keep watching out for the jewels