5

I followed instructions on the google/roboto repository, but no OTF file can be used as webfont.

The only feedback I can get is Chrome saying Failed to decode downloaded font.

OTS says everything is fine.

Why is that and how can I use Roboto opentype features on the web?

FYI I also opened google/roboto#283

Here is one of the generated fonts: https://drive.google.com/open?id=157_-UBTyswylqY3DOK-mKihd7Vk-vFA_

MatTheCat
  • 18,071
  • 6
  • 54
  • 69

3 Answers3

3

Update (based on the updated question)

Apparently the generated OTF font is not encoded properly for the web — all browsers have different font rendering engines and the decoding of this file fails in Chrome and Firefox, and even Font Squirrel reports The font is corrupt and cannot be converted. Funnily enough works just fine in Safari.

If you want to use the Roboto font features you'll have to generate your own web fonts. I have created a demo page that demonstrates some of Roboto's font features, with various web fonts (woff2, woff, otf, ttf) going through the following steps:

Once you run make with the google/roboto repository you should get the TTF fonts in the RobotoTTF directory. These files include all of Roboto's font features, and you can use them to generate your web fonts files. If you wish you can even use the TTF fonts:

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  src: local('Roboto'), local('Roboto-Regular'), url('./Roboto-Regular.ttf') format('truetype');
}

although your file size will be large and you should definitely convert them to other web fonts formats (woff2 yields best results and it's supported in all modern browsers) to decrease the file size significantly, so your @font-face declaration would be:

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  src: local('Roboto'), local('Roboto-Regular'), url('./Roboto-Regular.woff2') format('woff2');
}

You can still include and use font features in the generated web fonts too, and use them in your CSS code:

.yourclass {
  font-feature-settings: ...;
}

There are many tools you can use, online and on your computer. I tried the following ones which work pretty nice with keeping the OpenType Features within the generated web fonts:

On a side note, you may find LCDF Typetools useful, specifically otfinfo use as otfinfo -f Roboto-Regular.ttf to list all the features supported by a font.

Here's the list of the features for the Roboto font:

  • c2sc — Small Capitals From Capitals
  • ccmp — Glyph Composition/Decomposition
  • cpsp — Capital Spacing
  • dlig — Discretionary Ligatures
  • dnom — Denominators
  • frac — Fractions
  • kern — Kerning
  • liga — Standard Ligatures
  • lnum — Lining Figures
  • mark — Mark Positioning
  • mkmk — Mark to Mark Positioning
  • numr — Numerators
  • onum — Oldstyle Figures
  • pnum — Proportional Figures
  • salt — Stylistic Alternates
  • smcp — Small Capitals
  • ss01 — Stylistic Set 1
  • ss02 — Stylistic Set 2
  • ss03 — Stylistic Set 3
  • ss04 — Stylistic Set 4
  • ss05 — Stylistic Set 5
  • ss06 — Stylistic Set 6
  • ss07 — Stylistic Set 7
  • tnum — Tabular Figures
  • unic — Unicase

I hope you'll find this helpful.

** Deleted as not relevant to the updated question

van100j
  • 1,005
  • 8
  • 19
  • Thanks but I realized my question was not clear so I edited it: why can't I use this font on the web and how could I use it? – MatTheCat Jan 07 '18 at 09:04
  • What do you mean by _OpenType features on the web_? Do you want to use [Variable fonts on the web](https://webkit.org/blog/7051/variable-fonts-on-the-web/)? – van100j Jan 07 '18 at 23:04
  • I have updated the answer to reflect your updated question. Were you able to use Roboto's font features? – van100j Jan 09 '18 at 09:31
  • Yeah thanks a lot! What prevented me to move forward was the fact I thought opentype features couldn't exist in a TTF... – MatTheCat Jan 09 '18 at 10:32
  • 1
    Note that `ttf` and `otf` are *not different fonts*, they're both OpenType fonts, and only differ in the way they model glyph outlines. Everything else, like metadata and font features, are "just opentype" (the only reason they have different extensions is to appease older tech like old font parsers and printer hardware) – Mike 'Pomax' Kamermans Jan 10 '18 at 23:37
1

Building the font from the Roboto repo does indeed produce an invalid font. As you established, Chrome (and Firefox) reject it. Fontforge's fontlint produces a lot of errors when this OTF of Roboto is checked. Among many about mismatching adavance width, it's conclusion is:

ERROR      2 Self-intersecting glyph
ERROR      3 Wrong direction
ERROR      5 Missing points at extrema
FAIL         Roboto-Regular.otf

These errors only seemed to point to glyphs that were broken, but that shouldn't make Chrome reject the font altogether.

For fun I dove in to see what exactly breaks the font. After some sleuthing, I found two entries in the CFF table that apparently make for an invalid font:

<FamilyBlues value="0"/>
<FamilyOtherBlues value="0"/>

Removing these will fix the font. (I'll add this to the issue you reported)

About using OpenType features: a lot of layout features can be enabled through CSS, if they're in the font of course. You can write the CSS yourself (e.g. font-feature-settings: "liga"; to enable ligatures), or use a handy cross-browser CSS library like Utility OpenType.

RoelN
  • 2,181
  • 13
  • 15
0

Don't use otf, ttf, svg, or eot fonts on the web. The first two are universal OpenType fonts with way more data than necessary to work on the web, including data that is spec-legal, but will get rejected by overly protective parsers like OTS, and the latter two have been dead formats for years now and should never be used.

Pack the original source (otf or ttf, the choice of which doesn't matter unless you know why it does matter, which would mean you're pretty familiar with the internals of OpenType)) as a WOFF or WOFF2 font with something like google's woff2 utility or TTX, and then just use that, and only that:

@font-face {
  font-family: Roboto;
  src: url(./assets/myfonts/roboto.woff2) format("woff2");      
}

And things should work just fine.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
  • 3
    woff and woff2 subsets of this font produce the exact same behavior so I mentionned the OTF only to not question the subsetting/conversion step. I asked about the only thing I don't know so I would like an answer about that thing only. – MatTheCat Jan 07 '18 at 21:14
  • Then please update your post to make it clear that you already tested woff/woff2 conversion to rule out the whole "OpenType data that is necessary for ttf/otf fonts but can lead to rejection by OTS"? – Mike 'Pomax' Kamermans Jan 10 '18 at 23:35
  • And of course with that said, using TTX to verify your font is *really* not corrupt is still 100% recommended. – Mike 'Pomax' Kamermans Jan 10 '18 at 23:40
  • Well the font wasn't corrupt and the fact I tested woff and woff2 doesn't change the fact you didn't answer my questions. – MatTheCat Jan 11 '18 at 06:41
  • no but it *does* change the available information we have that lets us try to answer your question. Your original information was about a system font format: without knowing that you already tested woff, the first thing I will always tell anyone is to first do a proper woff conversion, because 90% of the time, that fixes the problem. If you don't mention you already tried that, then there is no reason to think more about the problem until that's been verified to not work, and mentioned in the post. That's how debugging works: you suggest the obvious things first, given the information posted. – Mike 'Pomax' Kamermans Jan 11 '18 at 16:14
  • Maybe you need to read the question before suggesting the obvious. Thanks anyways. – MatTheCat Jan 11 '18 at 16:35
  • perhaps you don't remember what you wrote: I have been working on font parsing for years, I've read your question three times now just in case you updated it between reads, and the text I've given you *still stands* because you don't mention a woff verification, or a TTX verification (which is *very different* from OTS verification) at all. You have an accepted answer: that's great, but that does not change the fact that your question, as written, merits the answer and comments I've given you independently of that. – Mike 'Pomax' Kamermans Jan 11 '18 at 17:35