7
\$\begingroup\$

Description

While support is getting better and better for people to write in various scripts around the world using unicode, and now you can even write in emojis as well, unfortunately most fonts[citation needed] are still missing Latin characters based on the double acute accent, which is required to write properly in Hungarian.

These characters are the following four:

  • U+0150 LATIN CAPITAL LETTER O WITH DOUBLE ACUTE (Ő)
  • U+0151 LATIN SMALL LETTER O WITH DOUBLE ACUTE (ő)
  • U+0170 LATIN CAPITAL LETTER U WITH DOUBLE ACUTE (Ű)
  • U+0171 LATIN SMALL LETTER U WITH DOUBLE ACUTE (ű)

Task

Your task is to write a program / script / function, that given a font or a font's name gives out a truthy value in case the font contains all of the four glyphs described above, or a falsey value if at least one of them is missing from the font.

Scoring

This is code-golf, so lowest byte-count wins

Test cases

These fonts are from Google Fonts. Note that some fonts on Google Fonts (for example Lato) have an updated version on other sites which already contain the missing glyphs, if you have the updated ones then obviously your results might be different from the test cases below.

Truthy values:

Roboto
Open Sans
Lalezar
Source Sans Pro
Arial
Times New Roman
Cinzel

Falsey values:

Voltaire
Rosario
Heebo
Bitter
Arvo
Lato (see note above)
Molengo (contains ű and Ű, but not ő or Ő)
Sue Ellen Francisco (contains only the uppercase variants)
Germania One (contains only the lowercase variants)
Garamond (the one installed on OSX by Office for Mac)

Notes

  • It's up to you if your program requires a font's name as a parameter or the actual font (or the font's location on the system)
  • If it's a font's name the program should check the system font registered at that name (for example if you specify "Arial" it should use the Arial font in your system's font registry)
  • If it's a location the program should use that specific font, even if there is a system font registered with that same name (for example if you specify "/home/user/Arial.ttf" it should use that font even if there's an Arial registered in the system's store)
  • Google Fonts above is just a convenient place you can download fonts for testing purposes, but your code doesn't need to use those fonts
  • It is enough if your program works with only one specific font type, e.g. TTF, OTF, WOFF, SVG font, Type 1, Metafont, etc. However you should support a font format that has generic support for the four glyphs and for signalling missing glyphs mentioned above, e.g. you cannot chose a font format where the answer will always be falsey or truthy
  • Some fonts might have the above glyphs incorrectly hardcoded to a fake value (e.g. the replacement box) instead of not specifying in the font file at all. Your code doesn't need to be able to differentiate between a fake glyph and a real glyph, but it's also acceptable if it does the check based on that.

Please specify in your answer how you have to pass in the font, and what kind of fonts it works with.

\$\endgroup\$
  • 2
    \$\begingroup\$ You might want to close the loophole around choice of font type to support. I've worked with font systems for which 0 would be a valid answer in many languages... \$\endgroup\$ – Peter Taylor Nov 29 '17 at 16:01
  • 1
    \$\begingroup\$ @totallyhuman No, that's just a convenient place you can download TTF/OTF fonts for you to test. As stated the code should work with either system fonts or a locally available font file. \$\endgroup\$ – SztupY Nov 29 '17 at 16:44
  • \$\begingroup\$ @PeterTaylor good note, I added the exclusion \$\endgroup\$ – SztupY Nov 29 '17 at 16:46
9
\$\begingroup\$

Scala, 56 bytes

s=>new java.awt.Font(s,0,0).canDisplayUpTo("ŐőŰű")<0

canDisplayUpTo is a method of the Font object that returns the index of the first charater that cannot be displayed by the font. It return -1 if all characters can be displayed. javadoc

\$\endgroup\$
  • 5
    \$\begingroup\$ Java has a builtin Mathematica doesn't have? \$\endgroup\$ – Erik the Outgolfer Nov 30 '17 at 18:50
  • \$\begingroup\$ If I'm not mistaken, this is valid Java if you replace = with -. Too similar for me to post a separate answer :) \$\endgroup\$ – Socratic Phoenix Dec 1 '17 at 13:33
8
\$\begingroup\$

Mathematica, 80 72 76 bytes

xFreeQ[f=Rasterize@Style[#,FontFamily->x]&;f/@("Ő""ő""Ű""ű"),f@"�"]

Takes the name of a font as a string. For each of the characters in question, generates an image of the character in the given font, and checks if they're all different from a similar image of the replacement character "�".

(The other weird character, , is \[Function].)

In almost all cases, the following 67-byte solution works instead:

xLength[Rasterize@Style[#,FontFamily->x]&/@("Ő""ő""Ű""ű")]>3

Here, we just check if all four images are different, which is valid under several assumptions about the fonts:

  • If the font can actually represent these characters, the results are all different.
  • If it fails to represent one of them, it fails on at least two (both the lowercase ones, or maybe "Ő" and "ő" but not "Ű" and "ű") replacing them both by the same "�"-looking character.

Unfortunately, the first assumption fails in very rare cases. For example, maybe the font doesn't distinguish between uppercase and lowercase characters. One example of this is a variant of EB Garamond, "EB Garamond 12 All SC". (On my laptop, there are 360 fonts installed, and this is the only one of them that the second solution fails on.)

Neither solution can be tried on Try It Online because the script version of Mathematica, unsurprisingly, has no support for different fonts. If you have Mathematica installed and want to try this, the system variable $FontFamilies lists the valid inputs (the fonts you have installed).


-4 bytes thanks to Martin Ender

\$\endgroup\$
7
\$\begingroup\$

C# (Visual C# Compiler), 107 100 + 23 bytes

-7 bytes thanks to briantist, whose Powershell answer helped me realise I'm a dummy and can shave off some bytes.

s=>"ŐőŰű".All(x=>new Windows.Media.GlyphTypeface(new Uri(s)).CharacterToGlyphMap.ContainsKey(x))

+23 bytes from

namespace System.Linq{}

It takes path to a font file (local or internet uri), and only supports OpenType fonts. Unfortunately doesn't work on TIO because it needs reference to PresentationCore.dll, but here's the full program code anyway: LINK

Explanation:
GlyphTypeface class loads font from provided uri, CharacterToGlyphMap loads all possible characters to a map, in which the characters are the keys. So we just take every tested character and check if the keys exist (which means the font supports them).

\$\endgroup\$
  • 1
    \$\begingroup\$ Nice! I didn't realize you could leave off System. without a using System; in C#. \$\endgroup\$ – briantist Dec 2 '17 at 16:04
  • 1
    \$\begingroup\$ @briantist I could because I put the program inside System.Linq namespace. When looking for types, compiler will look in your namespace's whole hierarchy, so first it will try to find it in System.Linq and then in System. (I'm simplifying, it probably is more intricate, but you get the gist) - that's also why I could use Uri without System.Uri or using System; as well \$\endgroup\$ – Grzegorz Puławski Dec 2 '17 at 21:48
4
\$\begingroup\$

PowerShell, 86 bytes

([Windows.Media.GlyphTypeface]::new("$args")|% C*p|? K* -in 336,337,368,369).Count-eq4

This is a shameless port of Grzegorz Puławski's Answer in PowerShell, using some golfing tricks.

I'm confident this could be golfed further but I have run out of time at the moment.

\$\endgroup\$
  • 2
    \$\begingroup\$ I approve of this message. +1 \$\endgroup\$ – Grzegorz Puławski Dec 2 '17 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.