Javascriptで任意のフォントを使用します。

優れたsIFR3およびFLIRライブラリを知っています。これらのライブラリは、オンザフライでWebページ上の任意のフォントを使用するのに役立ちます。
確かに、私の観点から、それらの使用(つまり、インストールと構成)は簡単な作業とは見なされません。

今日は、Typeface.jsライブラリについて説明します。このライブラリは、その名前が示すとおり、純粋なJavaScriptで実行されます。


理論のビット


Typeface.jsライブラリの公式Webサイトはhttp://typeface.neocracy.org/です。 このリソースには、すべての追加情報があります。

仕組み


このライブラリは、ベクターグラフィックスをレンダリングするための組み込みブラウザ機能に基づいています。 かなり長い間、ブラウザーはベクターグラフィックスのレンダリングをサポートしており、FirefoxはキャンバスSVGオブジェクトをサポートしており、IEはVMLをサポートしています。 開発者David Chesterが主張するブラウザーサポート:Firefox 1.5以降、Safari 2 +、Internet Explorer 6以降。
このライブラリは、2つのコンポーネントで構成されています。truetypeフォントをベクター座標に変換するperlモジュールと、ベクターフォントの説明を使用してブラウザーでテキストをレンダリングするjavascriptファイルです。

メリット





準備する




プロセス



これで、ブラウザにページをロードして結果を見ることができます!
そして、このようなページ全体の例を次に示します。
blockquote>
  1. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  2. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  3. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  4. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  5. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  6. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  7. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  8. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  9. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  10. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  11. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  12. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  13. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  14. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  15. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  16. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >
  17. <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > < html > < head > < title > </ title > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < script type ="text/javascript" src ="js/typeface-0.11.js" ></ script > <script type= "text/javascript" src= "js/als_agrus__regular.typeface.js" > </ script > </ head > < body > < div class ="myclass typeface-js" style ="font-family: ALSAgrus; font-size:40px;" > . </ div > < div > , < br /> Typeface.js ALS Agrus </ div > </ body > </ html >


たとえば、有料のALS Agrusフォントを使用して、より複雑なフォントで結果を確認します。 私が得たものは、上の写真で見ることができます。

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


All Articles