Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manipulate unicode-range while importing from Google Fonts

My question can be seen as a follow-up of this answer.

I use Google Fonts for my project and now want to change the unicode-range, so only numbers are affected (see linked answer above). My problem is that I don't get it to work with an include:

@import url("http://fonts.googleapis.com/css?family=Lato:300,400,700");

When I import the font like this, the font-face is already generated by Google (Google provides also the correct font-face setup to avoid cross browser problems, very convenient). I tried overwriting the imported font-face like this:

@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 400;
  unicode-range: U+30-39;
}

But that didn't work. To achieve the desired affect of having only numbers attached, I need to take the CSS from the Google import URL and copy it into my own CSS/SASS document. But then I lose the cross browser service that was done by Google Fonts API and also the speed of their CDN.

Is there a way to change the unicode-range while maintaining the Google font import or do I really need to host the fonts myself when I want to use unicode-range?

like image 726
Colonize.bat Avatar asked May 25 '15 00:05

Colonize.bat


People also ask

What is Unicode font range?

The unicode-range CSS descriptor sets the specific range of characters to be used from a font defined by @font-face and made available for use on the current page. If the page doesn't use any character in this range, the font is not downloaded; if it uses at least one, the whole font is downloaded.

Is it better to link or import Google Fonts?

It's better you use link if you are loading it from CDN. If the font is in your local directory then loading it using import or link will not have too much significant difference. But if you are loading it using a third party CDN then it's always better to use link .

Can Google Fonts be modified?

Yes, text in bitmap images or vector graphics made with fonts from Google Fonts can be modified, because the result isn't another font, but an image of text. You can also modify fonts themselves with font editor tools, subject to the license conditions.


1 Answers

If you want set the range while you are importing, just add to the link the variable 'subset'.

For example:

@import url("http://fonts.googleapis.com/css?family=Lato:300,400,700&subset=latin");

Or, if the text is very small you can change the subset variable for text, and add the content inside.

For example:

@import url("http://fonts.googleapis.com/css?family=Inconsolata&text=Hello");

Documentation

like image 170
GonzaloT Avatar answered Sep 23 '22 23:09

GonzaloT