3

I am making a robotic "talk and respond" console, and I want to be able to change the font in the console. I know how to change the font, but I do not want to change the font if the given font is not an actual HTML font.

Example: The user enters Arial, the command goes through. The user enters I lost my mommy, the command does not go through and the computer alerts the user that the command is invalid.

I obviously do not want to create a very large array containing all of the HTML fonts. That would not make sense.

If a jQuery solution works, then let me know. I am using jQuery in my code.

3
  • 3
    What You thought of with the Array, that is actually the only Idea I can think of. Check out this JSON Array of all Google Fonts which should basically cover all your needs. Commented May 29, 2017 at 16:35
  • take a look at fontSpy library ...might help github.com/patrickmarabeas/jQuery-FontSpy.js Commented May 29, 2017 at 16:48
  • luca kiebels suggestion may be combined with a bloom filter to reduce loading time drastically... Commented May 29, 2017 at 17:19

1 Answer 1

1

JavaScript/CSS Font Detector is a library that might help.

Include the library and call

detective.detect('[font name]'));

It isn't true font identification, but it may work for what you are trying to accomplish.

detect returns a boolean value based on if the string value provided matches a font that is available in the browser.

 function isFont(fontName) {
      return fontName ? detective.detect(fontName) : false;
 }
Sign up to request clarification or add additional context in comments.

1 Comment

This is good, but could you give me an example? I read the guide and it's a bit vague.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.