Adobe
製品
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
その他の製品一覧
ソリューション
デジタルマーケティング
デジタルメディア
教育
金融機関
Web Experience Management
その他のソリューション
ラーニング サポート ダウンロード 会社情報
ご購入
アドビストア 安心のサポート& サービス
アカデミックストア 学生、教職員、個人向け
アドビライセンスストア 中小企業向け
ボリュームライセンスについて 企業、教育機関、官公庁向け
販売パートナー
キャンペーン情報
検索
 
情報 サインイン
ようこそ、 さん カート 注文状況 マイアカウント
マイアカウント
注文状況
アカウント情報の変更
コミュニケーションの設定を変更
サインアウト
サインインの目的 お客様のアカウントや体験版ダウンロード、製品の拡張機能、コミュニティエリアへのアクセスなどを管理するため
Adobe
製品 セクション ご購入   検索  
ソリューション 会社情報
サポート ラーニング
サインイン サインアウト 注文状況 マイアカウント
先行予約の提供開始予定日Date. 商品が発送されるまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。 先行予約の提供開始予定日Date. ダウンロードの準備が整うまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。
個数:
ご購入には学生・教職員個人版の購入資格の確認が必要です。
小計
カートの中身を見る
Adobe Developer Connection / Adobe AIRデベロッパーセンター /

Using web fonts with Adobe AIR 2.5

著者 Mihai Corlan

Mihai Corlan
  • corlan.org

Content

  • Supported web font formats
  • Overview of the AIRWebFontDemo sample application
  • Working with web fonts in Adobe AIR
  • Where to go from here

Created

24 October 2010

ページ ツール

Facebookでシェア
Twitterでツイート
LinkedInでシェア
ブックマーク
印刷

タグ

必要条件

この記事に必要な予備知識

Familiarity with Adobe AIR, HTML, JavaScript, and CSS is recommended.

ユーザーレベル

すべて

サンプルファイル

  • AIRWebFontDemo.air (119 KB)
  • AIRWebFontDemo.zip (208 KB)

Additional Requirements

In order to make the most of this article, you need the following software and files:

Aptana Studio 2.0

  • Download

Note: You can read here more about Aptana's support for AIR development.

Adobe AIR 2.5 SDK

  • Download

Adobe AIR 2.5 introduces support for downloadable font resources or web fonts. Web fonts can be referenced using the @font-face CSS rule, which is supported by most modern browsers and enables web developers to link and display fonts that are not installed on the user's machine. These fonts are downloaded by the browser from a remote server when the content is viewed.

Typography is important for a number of digital print editions of newspapers, magazines, books. The user experience depends on the quality of the typography. Making sure your carefully selected fonts can be rendered on the user's display is the first and most important step towards a great user experience. Furthermore, web fonts are protected with services such as Typekit: users who browse a page that uses the @font-face rule don't have access to the font files. This allows you to use commercial fonts and thus differentiate your products from others.

Supported web font formats

Adobe AIR 2.5 supports web fonts for desktop applications built using ActionScript/Flex (using HTMLLoader) or HTML/JavaScript/CSS. If you build applications for mobile, then web fonts are supported through the StageWebView control.

AIR supports the following web font formats:

  • TrueType (.ttf)
  • OpenType (.ttf/.otf)

Embedded OpenType (EOT), Web Open Font Format (WOFF), and SVG Fonts are currently not supported. 

Overview of the AIRWebFontDemo sample application

Before going into details on how an AIR application might use web fonts, I'd like to provide a brief overview of the companion application for this article. I decided to build this application using HTML/JavaScript/CSS mainly because web fonts are an HTML-related feature (although you can use this feature in an ActionScript or Flex project as well).

The AIRWebFontDemo sample application is a simple book reader (see Figure 1). It displays a book (Alice in Wonderland by Lewis Caroll) and it lets you change the font size and family. You can navigate through the content using the scrollbar or the navigation buttons on the bottom. The application also has a fullscreen mode and remembers the last state. When the application is closed, information about the application's window size, scroll position, and font size and family are persisted on the disk and restored the next time the user opens the application.

AIRWebFontDemo application in action.
Figure 1. AIRWebFontDemo application in action.

As you can see it is a pretty simple application both from the point of view of the source code and features. Nevertheless, it touches on some of the features you'd probably want to have in a real book reader.

If you download the AIRWebFontDemo.zip file (this file is an Aptana AIR project), unzip the file, and import it into Aptana Studio using File > Import > General > Existing Projects into Workspace (selecting the folder where you unzipped the file) you will see a project with the structure shown in Figure 2.

AIRWebFontDemo project structure in Aptana Studio 2.0.
Figure 2. AIRWebFontDemo project structure in Aptana Studio 2.0.

Now that you have an overview of the structure of the application have a look how it was implemented.

The application user interface is defined in the AIRWebFontDemo.html file and its companion CSS file, style.css. Basically, what I did here is a liquid design with two fixed zones on the Y axis (the top and the bottom stripes) and a mobile one in between them. On these two zones I placed the UI controls. In the flexible one I placed an <iframe> . And this <iframe> is used for displaying the book itself.

If you take a look at the AIRWebFontDemo.html and style.css files you'll notice that I had to use a lot of DIVs and CSS in order to create this liquid design. After finishing the user interface for this application I came to this conclusion: when developing desktop applications with AIR and HTML I don't think using DIV tags instead of TABLE tags is recommended. When you build applications you have to position (pixel perfect) a lot of controls and using a mix of DIV and TABLE tags helps both in development speed and quality. Imagine the work needed for creating the user interface of a complex text editor using only DIV tags.

Next, all the scripting that brings to life the user interface defined in AIRWebFontDemo.html is in js/script.js file. These are the main features provided by this script:

  • Sending style and navigation changes to the <iframe> that displays the book. These changes include: increasing/decreasing font size, changing the font familly, or navigating though the book using the Prev/Next/Top buttons.
  • Registering event listeners for key down and exit application events. When a user chooses fullscreen mode and presses the ESC key, then the script changes the display mode. When the application is closed, the current state is saved to disk.
  • Saving and reading to or from disk the application state on loading the application or closing it.

Some of this logic is hooked using the onload events of the main HTML application and <iframe> content. For example once the onload event is thrown by the main application (and this means the applicatin was initialized, thus I can access the stage, for example), the initialize() function is executed and I use this to register the listeners. Then, when the onload event is thrown by the <iframe> (this means the book content was loaded by the <iframe> including the Web Font used) I execute the restorePosition() function, which in turns applies the values saved in the previous session.

In order to persist the information related to application state I chose to create a JavaScript object and then I serialize this object in a file in the application storage directory.

Finally, the last important part of this application is the books/alice.html file. This file stores the book content. It has some JavaScript code and CSS. There are two reasons for the presence of JavaScript:

  • In this application I chose to use Adobe Web Fonts served by Typekit . Typekit is a subsription-based service and it offers fonts that can be used either for free or for a subscription fee. In order to support this workflow Typekit requires developers to include some JavaScript when using their services.
  • Because of the way I load the <iframe> content (in the nonapplication sandbox) I had to use the Sandbox Bridge in order to push the style or scrolling changes from the main application to the page displayed by the <iframe> . Thus I have a number of JavaScript functions defined here and exposed through the Sandbox Bridge.

Working with web fonts in Adobe AIR

The main idea behind web fonts is that the font is loaded by the browser at runtime from a remote server. Depending on who's the remote server you have different workflows to follow in order to use web fonts in Adobe AIR.

If you use Typekit services, for example, you'll have to:

  1. Load the HTML content that you want to use web fonts from Typekit in an <iframe> and set the documentRoot and sandboxRoot to reflect where the HTML file is located relative to appliction source folder and what is the domain name you set in your Typekit account. For example, these are values set in my application:
<iframe id="myFrame" src="alice.html" documentRoot="app:/books/" sandboxRoot="http://corlan.org"> </iframe>
  1. In the <head> section of the HTML file where you use the web fonts you have to add the following <script> tags (the URL for the first script is customized for each account; this means you have to retrieve the script from your Typekit account):
<script type="text/javascript" src="http://use.typekit.com/opp1ueg.js"></script> <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
  1. In your Typekit account, depending on the account type you have, you add the fonts you want to use. Then you add the selectors or tags you want to apply to the fonts. In Figure 3 you can see in the top-left corner that the Adobe Garamond Pro font is enabled for the body tag and the tk-adobe-garamond-pro class. Then you have to press the Publish button in order to enable the settings.
  2. You apply the font you've enabled in the Typekit account by adding CSS to the HTML file like this (in order to find what is the name of the font, click the Advanced link shown in Figure 3):
<style type="text/css"> body { font-family: adobe-garamond-pro-1,adobe-garamond-pro-2, serif; } </style>
Typekit Control Panel settings for fonts.
Figure 3. Typekit Control Panel settings for fonts.

If you want to use a font from Google Font Directory, then the steps are:

  • Retrieve the font CSS inclusion tag for the font you want to use from the Google Font Directory site and add this tag as the first tag of the <head> node. For example, for the Cantarell font the tag is: 
<link href='http://fonts.googleapis.com/css?family=Cantarell&subset=latin' rel='stylesheet' type='text/css'>
  • Then declare the font name on the elements you want to be rendered withthe font you chose. Example:
h1 { font-family: 'Cantarell', arial, serif; }

Lastly, you should be aware of the overhead that web fonts add to a project in terms of resources which have to be downloaded at runtime. Because web fonts are retrieved from a remote server, as you can observe if you run my application, it can take some time in order to download the font file. This means you should always take this in consideration when using a large number of web fonts.

Where to go from here

The addition of web fonts support in Adobe AIR opens up the possibility to finetune and control the text presentation in your applications. This can improve a lot your projects when what are you building a digital version of a book, magazine, or newspaper. If you want to stay in touch with what the Adobe Type Team is doing you can follow their blog. Also refer to the Adobe Web Fonts FAQ.

More Like This

  • Distributing AIR in the enterprise
  • Performance-tuning Adobe AIR applications
  • Getting started with the custom install badge
  • What's new in Adobe AIR 2.5
  • Building a mobile RSS reader with Flash Builder "Burrito"
  • Adobe AIR Marketplace FAQ
  • Getting started with Adobe AIR for HTML/JavaScript developers
  • Getting started with Adobe AIR for Flex and ActionScript 3 developers
  • Ten tips for building better Adobe AIR applications
  • Multiscreen development techniques with Flex and Adobe AIR

製品

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • モバイルアプリ
  • Photoshop
  • Touch Apps

ソリューション

  • デジタルマーケティング
  • コンテンツオーサリング
  • Web Experience Management

業種別ソリューション

  • 教育
  • 金融機関

サポート

  • ヘルプ&サポート
  • 注文と返品
  • ダウンロードに関するヘルプ
  • ユーザー登録に関するヘルプ

ラーニング

  • ADC: Adobe Developer Center
  • Adobe TV
  • Design Magazine
  • Photoshop Magazine
  • Focus In

ご購入方法

  • アドビストア
  • アカデミックストア
  • アドビライセンスストア
  • ボリュームライセンスについて
  • 販売パートナー
  • キャンペーン情報

ダウンロード

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

会社情報

  • プレスルーム
  • パートナープログラム
  • 企業の社会的責任(英語)
  • 採用情報
  • 投資家の皆様へ(英語)
  • イベント&セミナー
  • Legal(英語)
  • セキュリティ
  • お問い合わせ
国・地域および言語の選択 日本(変更)
国・地域および言語の選択 閉じる

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

利用条件 | プライバシーポリシーとCookie (更新)

Reviewed by TRUSTe: site privacy statement