CSS rollback for small OpenType caps

I am working on a site where small caps are important: setting the text of the Bible. In the Old Testament, the name of God is transliterated as Lord , but in small caps - not Lord . However, the state of OpenType support with small caps at the moment ... is less than optimal. Safari (even through Safari 8 on Yosemite, from which I am printing this) still does not support the -webkit-font-feature-settings: 'smcp' parameter, and many hits for this site will come from mobile devices.

Unfortunately, "elegant degradation" is problematic here: if you specify both font-variant: small-caps and font-feature-settings: 'smcp' in a browser that supports the latter (for example, Chrome), the font-variant declaration overrides it so the terribly ugly old version, the stylish version still comes into play. (Note: this is how it should be in spec : a font-variant declaration takes precedence over a font-feature-settings declaration). Given the current font-variant: small-caps implementations, although shrunken capitals, rather than actual small capitals, the result is that using font-variant: small-caps implementers does not so gracefully degrade the perception of every reader.

In the past, I exported small caps as a separate webfont and pointed them directly; see this post for a simple example: the first line of each paragraph is shown exactly that way.

While I can do the same here (and at least theoretically could deliver a pretty small font, since I really only need three characters: o , r and d ), I would prefer just to provide reasonable reserves . However, as noted above, this is not possible. I am open-minded, but would very much prefer to avoid server-side solutions (browser detection, etc.) as a point of complexity that is best minimized, especially considering how quickly browsers change. How else can this problem be solved, and especially if there are existing solutions for it?

Edit: refinement based on comments - in the future, font-variant: small-caps will do this fine, according to the specification, it should display a variant with a small capital font if the font supplies it, however, currently no browser supports this ( at least not one that I can find!). This means that instead they all create fake small capitals, simply reducing actual capitals. The result is typographically unpleasant and unacceptable in this project.

+6
source share
4 answers

Last update 2016/02/28.

I spent a lot of time studying this and fighting it. After I was able to dig up, as far as possible, the main solutions at the moment:

@supports

Use the @supports rule in browsers. This is what I initially decided to make this project. [1] You use the rule as follows:

 .some-class { font-variant: small-caps; } @supports(font-feature-settings: 'smcp') { .some-class { font-variant: normal; font-feature-settings: 'smcp'; } } 

I simplified by leaving prefix versions; you will need to add -webkit- and -moz- to get this working. Update, 2012/02/28: you no longer need the -moz- prefix, and this will work in Safari in the next version (iOS 9.3 and OS X Safari 9.1).

This has the advantage that the support for real little caps and the support for the @supports rule @supports very similar:

This is not ideal: since IE10 / 11 does not implement @supports , you are missing one browser. ( Edit, 2015/09/31: IE itself does not have @supports , but Edge 12+ does, and this should more and more cover all users of the site.) However, this gives you most of the way, and it should be in future: this should gradually improve the site. Normal (poor, but functional) Meanwhile, small caps are displayed, and when browsers end up getting around using the default OpenType small closures for font-variant: small-caps , this will work just fine. This is a "progressive improvement" and it will work well for most purposes. [2]

Subset of fonts

As already mentioned in the question, you can create a subset of the font, includes only small capitals. This is what I did for little caps on my own site ; see the first line of the first in this post for an example.

To remove this, you need to start with a subset of the font. You can do this manually using the font tool, or (in a simpler way) you can use FontSquirrel's custom subset tool in the webfont generator . ( Note:. Must verify the license and confirm that the type of modification is being considered. See below.) In the web font generator, first upload the file you want to modify. Then select the Expert radio button. Most of the settings you can leave as they are; they are good normal defaults. Halfway down the page, you'll see OpenType Flattening options . Here, select only "Small caps." Run the generator. The result will be a complete replacement for normal lowercase letters with small caps. [3]

In this case, you can simply apply the style to elements that you want to have small capitals, for example:

 .divine-name { font-family: 'my_typeface_smcp', 'my_typeface', serif; } 

The main advantage of this approach is consistency: this font will be displayed in every browser, back to IE5.5, as long as you deliver it correctly using the various hooks required by @font-face .

There are several drawbacks to this approach:

  • This means delivering another font file. In my case, it will be (since I really only need four characters), but there is something else to consider as a whole. In any case, this is another HTTP request, which will slow down the page loading even more, or at least give you a little flash of uneven text when you reload.

  • It may violate the licenses of the respective fonts. At least one of the fonts that I use in this project is: the license explicitly prohibits rebuilding the font with tools such as FontSquirrel. (FontSquirrel was the tool I've used for this approach before, and it works pretty well.) It's a matter of creating or breaking to use a subset of the font to fulfill the purpose. In this case, if you have every reason for this, you may be able to get support from the supplier (especially if it is a small store). For the project that raised this question, I was able to do it with a nice email - the designer is a great guy.

Another important reason why this is not done is that it has significantly higher operating costs. If at any time you need to change or update the font, you must go through the subset process again and again. By contrast, the first option will just work, although admittedly, it’s not as pleasant as one might hope, and will not only continue to work, but will actually improve over time, as browsers increase the implementation of the CSS3 standard.


Notes

  • For various reasons (especially see Note 2 below), I actually chose the second approach described here, which is the same approach I was trying to avoid. Alas.

  • Problems remain: even in the latest Chrome (38 at the time point edit), using the font-feature-settings: 'smcp' approach, has some questions. For example, if you enable letter-spacing (a fairly common recommendation for small caps), the small caps will revert to regular lowercase letters. Fixed in Chrome 48 . HT for the responder below .

  • From the FontSquirrel blog post in which the function was introduced:

    If you have a font with OpenType features, now you can smooth some of them into your webfont. For example, some fonts have small caps, but they are completely inaccessible in a web browser. By choosing the Small Cap option, the generator will replace all lowercase glyphs with small cap options, giving you a small font. Please note that not all OpenType functions are supported, and if the font does not have OpenType functions, using these parameters will not create them.

+10
source

Support for font-feature-settings:"smcp" improved in recent browsers. Chrome 48 fixes an error with a letter spacing . And, according to caniuse.com, future versions of Safari for iOS and Desktop will support it. However, a prefix version is still required for -webkit.

+1
source

You already mentioned it here, elegant degradation.

Use the font-feature parameter, and if the browser does not support opentype functions, the user will still receive all the content, with the worst case scenario being full-sized capitals; nothing is lost. I would say that this is an elegant degradation.

Aa alternative that you might want to consider using Typogruby ( http://avdgaag.imtqy.com/typogruby/ ) or the like, or manually adding a class to this word, you can target directly in your html by faking it with using CSS2, for example:

 .caps {font-size: .83em; letter-spacing: .25em; text-transform: uppercase;} 

Edit: Of course, using the above method, you can also specify a different font for the .caps class, one with a full cap that will work well with small sizes instead of real little caps.

0
source

Stop thinking OpenType for a moment and think about the content: you need a different style for semantically different data (in this case, to create a small template for a particular religious word). It was literally designed for HTML markup. Just wrap these words in the <span class="smallcapped"> markup with javascript, and use a highlighted font with small caps in your class. This is very easy to do, and even allows you to find the best mini quotes that look independent of the main text font.

Just run some code every time the section is loaded with the DOM (definitely not after completing all your content, unless you are showing only short snippets of text):

 function wrapSmallcaps(element) { var content = element.innerHTML; ["LORD"].forEach(function(term) { var search = new RegExp(" W?"+term+" W?",'g'); content = content.replace(search, function(a,b) { return a.replace(term, "<span class='smallcapped'>"+term+"</span>"); }); }); element.innerHTML = content; } 

ex: http://jsbin.com/cowumaxe/1/edit

We could solve this by trying to use OpenType fonts, but you would snap yourself to one font, not one for each style, which makes it extremely difficult to improve the look later without breaking font licenses when a more convenient text font appears or a font with small windows, or user feedback tells you to improve the look.

(and, of course, this code is literally universal for any browser, since IE8 - http://caniuse.com/#search=queryselector shows zero "no support" or even "partial support" for all browser users who actually use )

-1
source

Source: https://habr.com/ru/post/972516/


All Articles