webfonts - Packaging a font with a Google Chrome extension -


i want use other standard fonts chrome extension. excited possibility of using google web fonts, seems incur penalty transferring web font on network whenever extension uses it, point of affecting performance of extension. have option packaging font extension work on chrome-supported platforms (windows/mac/etc.)? in advance

choose font. example i'll take "stint ultra expanded". there example how add page:

<link href='http://fonts.googleapis.com/css?family=stint+ultra+expanded' rel='stylesheet' type='text/css'> 

take href , open in browser. you'll see smth this:

@font-face {   font-family: 'stint ultra expanded';   font-style: normal;   font-weight: 400;   src: local('stint ultra expanded'), local('stintultraexpanded-regular'), url(http://themes.googleusercontent.com/static/fonts/stintultraexpanded/v1/feigx-wddghmckuhekhedwmdhyvwfbygze-w47q2x_f3rgvtstkpsbdajuo5ueqw.woff) format('woff'); } 

take first parameter of url value src property (http://themes.googleusercontent.com/static/fonts/stintultraexpanded/v1/feigx-wddghmckuhekhedwmdhyvwfbygze-w47q2x_f3rgvtstkpsbdajuo5ueqw.woff).

download file.

use parameter of local value of src property filename (stint ultra expanded)

easy way download using wget:

wget -o "stint ultra expanded.woff" http://themes.googleusercontent.com/static/fonts/stintultraexpanded/v1/feigx-wddghmckuhekhedwmdhyvwfbygze-w47q2x_f3rgvtstkpsbdajuo5ueqw.woff 

now create css file , add content have seen before. have change value of src property. remove locals , adjust url. should smth this:

@font-face {   font-family: 'stint ultra expanded';   font-style: normal;   font-weight: 400;   src: url('../fonts/stint ultra expanded.woff') format('woff'); } 

now add css file extension , use font:

popup.html

<!doctype html> <html> <head>     <title></title>     <link href='css/fonts.css' rel='stylesheet' type='text/css'> </head> <body>      <span style="font-family: 'stint ultra expanded';">hello font</span>  </body> </html> 

if use font in content_script have adjust url in css:

@font-face {   font-family: 'stint ultra expanded';   font-style: normal;   font-weight: 400;   src: url('chrome-extension://__msg_@@extension_id__/fonts/stint ultra expanded.woff') format('woff'); } 

you can add many @font-face rules in css like.

notice: local value in src property tells name should used store it. idea use name.

second notice: if using google expected, browser check if font available local. if not case, downloaded , stored. next time use font stored.

as of chrome 37 (maybe earlier), need mention font web accessible resource in extension's manifest:

"web_accessible_resources": [   "font/*.woff2" ] 

otherwise see error like:

denying load of chrome-extension://{id}/font/my web font.woff2.  resources must listed in web_accessible_resources manifest key in order loaded pages outside extension. 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -