Top Banner
John Daggett Mozilla Japan Ampersand 2011 BRIGHTON The Future of CSS Typography
86

The Future of CSS Typography - People of Mozilla

Feb 12, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Future of CSS Typography - People of Mozilla

John DaggettMozilla Japan

Ampersand 2011 BRIGHTON

The Future of CSS Typography

Page 2: The Future of CSS Typography - People of Mozilla
Page 3: The Future of CSS Typography - People of Mozilla

First, a little history

Page 4: The Future of CSS Typography - People of Mozilla

• CSS1 (1996) basic font and text properties• CSS2 (1998) @font-face, font-stretch• CSS 2.1 (2002~) slim down, accurately specify• CSS3 (2002~) independently evolving modules• CSS3 Fonts (2008) @font-face, OpenType support

CSS font property evolution

Page 5: The Future of CSS Typography - People of Mozilla

• Wider choice of fonts (@font-face rule)• Control over font features• Rendering and layout consistency• http://dev.w3.org/csswg/css3-fonts/

CSS3 Fonts: better building blocks

Page 6: The Future of CSS Typography - People of Mozilla

Steps in the spec process (from Murakami)

Page 7: The Future of CSS Typography - People of Mozilla

Existing font properties in CSS

Basics

Page 8: The Future of CSS Typography - People of Mozilla

Individual faces selected by combination of properties

body { font-family: Helvetica, Arial, sans-serif; font-size: 12pt;}

h1, h2, h3 { font-weight: bold; }

em { font-style: italic; }

Choosing a font

Page 9: The Future of CSS Typography - People of Mozilla

First available font family on a given platform is selected

body { font-family: Helvetica, Arial, sans-serif; font-size: 12pt;}

h1, h2, h3 { font-weight: bold; }

em { font-style: italic; }

Font fallback

Page 10: The Future of CSS Typography - People of Mozilla

37signals.com

Firefox 3.5, WinXP vs. Mac OS X 10.5

Page 11: The Future of CSS Typography - People of Mozilla
Page 12: The Future of CSS Typography - People of Mozilla

System font fallback picks up fonts for other scripts

body { font-family: Lucida Grande, Tahoma, Verdana, Arial, sans-serif;}

Page 13: The Future of CSS Typography - People of Mozilla

• A set of closely related typeface designs• Shared name but...• TrueType defined names per-platform• Multiple localizations possible• Platform API’s do strange and interesting things

Font family names

Page 14: The Future of CSS Typography - People of Mozilla

Should match the bold face of Arial

body { font-family: Arial; font-weight: bold;}

font-family

Page 15: The Future of CSS Typography - People of Mozilla

Should match the regular face of the default font!

body { font-family: Arial Bold, ArialBoldMT; font-weight: normal;}

font-family

Page 16: The Future of CSS Typography - People of Mozilla

• Simple values: normal, bold• Numeric values 100 ... 900• Relative values: bolder, lighter• Windows GDI limits family groupings to normal, bold• Reflected in OpenType family name definition (!!!)

font-weight

Page 17: The Future of CSS Typography - People of Mozilla
Page 18: The Future of CSS Typography - People of Mozilla

Based on OS2.usWeightClass values

100 Thin200 Extra-light, Ultra-light300 Light400 Normal, Regular500 Medium600 Semi-bold, Demi-bold700 Bold800 Extra-bold, Ultra-bold900 Black, Heavy

font-weight values in CSS

Page 19: The Future of CSS Typography - People of Mozilla

Helvetica Neue on Mac OS X 10.6

100 UltraLight300 Light400 Regular700 Bold900 Black (only condensed)

Weight value mappings

Page 20: The Future of CSS Typography - People of Mozilla

Helvetica Neue LT Std in Font Folio 11

250 Thin275 Ultra Light300 Light400 Roman500 Medium700 Bold750 Heavy900 Black

Weight value mappings

Page 21: The Future of CSS Typography - People of Mozilla

• GDI synthetic bolding occurs for weights <= 200• Apple treats usWeightClass as unreliable• Weight value is inferred from the style name (!!!)• See WPF font selection model from Microsoft• Affects family groupings in strange and wonderful ways

Weight value mappings

Page 22: The Future of CSS Typography - People of Mozilla

Pause to sigh...

Page 23: The Future of CSS Typography - People of Mozilla

• normal, italic, oblique• oblique usually treated as synonymous with italic• Families with both italic and oblique faces rare

font-style

Page 24: The Future of CSS Typography - People of Mozilla

• When bold or italic don’t exist, use rendering tricks• Authors often unaware• Doesn’t work well in all cases• But users complain if disabled• ick, patooey

Synthetic bold & italic

Page 25: The Future of CSS Typography - People of Mozilla

Futura on Mac OS X lacks a bold face

Page 26: The Future of CSS Typography - People of Mozilla

Browsers fake bold by smearing a regular face

Page 27: The Future of CSS Typography - People of Mozilla

And fake italics by obliqueing

Page 28: The Future of CSS Typography - People of Mozilla

• Should be font-width• In CSS2, now back in CSS3• Values based on usWidthClass names• Ex: condensed, expanded• Used for font selection, no synthetics

font-stretch

Page 29: The Future of CSS Typography - People of Mozilla

The @font-face mechanism

Downloadable fonts

Page 30: The Future of CSS Typography - People of Mozilla

• Proprietary implementations in Netscape & IE• Defined in CSS2 but with lots of features• CSS3 Fonts is more narrowly defined

@font-face rule

Page 31: The Future of CSS Typography - People of Mozilla

@font-face { font-family: Gentium; src: url(fonts/Gentium.woff);}

body { font-family: Gentium, Georgia, serif; }

• Defines a font that is downloaded when needed• Name is completely under author control• One rule per style combination• Activated per-document, not system-wide

Using @font-face

Page 32: The Future of CSS Typography - People of Mozilla

@font-face { font-family: mplus1p; src: url(mplus-1p-regular.woff);}

@font-face { font-family: mplus1p; src: url(mplus-1p-bold.woff); font-weight: bold;}

@font-face { font-family: mplus1p; src: url(mplus-1p-black.woff); font-weight: 900;}

Defining multiple weights

Page 33: The Future of CSS Typography - People of Mozilla

@font-face { font-family: Gentium; src: url(fonts/Gentium.woff) format(“woff”), url(fonts/Gentium.ttf) format(“truetype”);}

• Declares format of data• Unknown formats are skipped• “truetype”, “opentype” synonymous(!)

Format hints

Page 34: The Future of CSS Typography - People of Mozilla

@font-face { font-family: Gentium; src: local(“Gentium”), url(fonts/Gentium.ttf);}

body { font-family: Gentium, Georgia, serif; }

• Uses local version of the font if available• Downloads the font if it isn’t• Defined using fullname or Postscript name• Allows access to all faces!

Using local fonts

Page 35: The Future of CSS Typography - People of Mozilla

@font-face { font-family: DroidSans; src: url(DroidSansJapanese.ttf); unicode-range: U+3000-9FFF, U+ff??;}

@font-face { font-family: DroidSans; src: url(DroidSans.ttf); unicode-range: U+000-5FF, U+1e00-1fff, U+2000-2300;}

• Allows combining fonts for a single “face”• Effective range is intersection of range with

character map

Composite fonts with unicode-range

Page 36: The Future of CSS Typography - People of Mozilla

• EOT• TrueType/OpenType• SVG• WOFF

Supported font formats

Page 37: The Future of CSS Typography - People of Mozilla

ttf/otf woff svg eot

Internet Explorer 9 9

Firefox

Safari 6

Chrome

Opera

Page 38: The Future of CSS Typography - People of Mozilla

• Fonts are only loaded for documents from the same domain

• Prevents cross-site linking• Actual mechanism subject of recent debate

Same origin restriction

Page 39: The Future of CSS Typography - People of Mozilla

• Same protocol• Same site• Same port

Meaning of same origin

http://www.example.com:80/lovelythings.html

Page 41: The Future of CSS Typography - People of Mozilla

• Firefox, IE9: same origin restriction by default• Firefox, IE9: use CORS to relax restriction• Webkit, Opera proposal: use From-Origin to

explicitly restrict• Useful for all resource types, not just fonts• More work for authors• What’s the default when no header present?

Origin restriction mechanism

Page 42: The Future of CSS Typography - People of Mozilla

Allows linking from any site

Using CORS to relax the restriction# example Apache .htaccess file to add # access control header <FilesMatch "\.(ttf|otf|woff)$"><IfModule mod_headers.c>Header set Access-Control-Allow-Origin "*"</IfModule></FilesMatch>

Page 43: The Future of CSS Typography - People of Mozilla

Restricts use to pages with the same origin

Using From-Origin to restrict# example Apache .htaccess file to add # From-Origin header <FilesMatch "\.(ttf|otf|woff)$"><IfModule mod_headers.c>Header set From-Origin "same"</IfModule></FilesMatch>

Page 44: The Future of CSS Typography - People of Mozilla

• Timing of how fonts load• For large fonts, what to do while waiting?

Font loading

Page 45: The Future of CSS Typography - People of Mozilla

<!DOCTYPE html><html><head> <title>An Interesting Page</title> <script src="/js/pageutils.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /></head><body> ** page contents **</body></html>

Pages contain content and link to other resources

Common page structure

Page 46: The Future of CSS Typography - People of Mozilla

What should be shown while the font loads?

Page 47: The Future of CSS Typography - People of Mozilla

Safari uses default metrics and shows blank text

Page 48: The Future of CSS Typography - People of Mozilla

Page when loaded

Page 49: The Future of CSS Typography - People of Mozilla

Firefox 4 shows blank, then displays with fallback fonts after a delay (default: 3 seconds)

Page 50: The Future of CSS Typography - People of Mozilla

Page loading behavior can get complicated!

Page 51: The Future of CSS Typography - People of Mozilla

• Japanese fonts are largely print oriented• Lots of glyphs, large size• Complexity of the characters means cost is high• Can’t use vertical layout across browsers• Japanese web fonts are a completely different product• Hinting requirements mean huge cost

Japanese font handling

Page 52: The Future of CSS Typography - People of Mozilla

ClearType Meiyro: A new standard for reading on the screen

Page 54: The Future of CSS Typography - People of Mozilla

Group most commonly used glyphs into first font

@font-face { font-family: MyGothic; src: url(gothic-jis1.woff); unicode-range: ** jis-1 **;}

@font-face { font-family: MyGothic; src: url(gothic-jis2.woff); unicode-range: ** jis-2 **;}

Splitting up a font

Page 55: The Future of CSS Typography - People of Mozilla

民主党 Manifesto 2010

Page 56: The Future of CSS Typography - People of Mozilla

Supporting OpenType features in CSS

Controlling font features

Page 57: The Future of CSS Typography - People of Mozilla

What are OpenType font features?

Page 60: The Future of CSS Typography - People of Mozilla

• TrueType fonts: one glyph per character• OpenType: multiple possible glyphs per character• Maps characters to set of glyphs and positions• Script, language, context can affect this• How to map control of this into CSS?• WPF font features as one possible way

OpenType features

Page 61: The Future of CSS Typography - People of Mozilla

• From discussions between Håkon Wium Lie, Adam Twardoch and Tal Leming

• Etan Wexler also proposed something similar• font-variant becomes a shorthand• Subproperties enable OpenType features

Extending font-variant

Page 62: The Future of CSS Typography - People of Mozilla

• Used to select variant glyphs within a given font• If the font lacks feature support default glyph used• Avoid synthesizing...• Exceptions for backwards compatibility• To prevent property explosion, values grouped• Selecting alternates gets a bit hairy

font-variant subproperties

Page 63: The Future of CSS Typography - People of Mozilla

• Values: normal, none, auto• auto means browser decides the default• normal means browser must use kerning data• Hopefully text engines will get faster

font-kerning

Page 64: The Future of CSS Typography - People of Mozilla

• control over common, discretionary, historical ligatures• normal implies default behavior• common ligatures on, discretionary ligatures off• defined by OpenType not by CSS

font-variant-ligatures

Page 66: The Future of CSS Typography - People of Mozilla

• Support for true small caps• Small caps, petite caps, etc.• Small caps must be simulated when no available• Petite caps fallback to small caps• all-small-caps is not the same as small-caps with

text-transform: lowercase

font-variant-caps

Page 67: The Future of CSS Typography - People of Mozilla

• Lining or old-style figures• Proportional or tabular figures• Automatic fractions, slashed zero

font-variant-numeric

Page 68: The Future of CSS Typography - People of Mozilla

Using various number styles

Page 70: The Future of CSS Typography - People of Mozilla

• Control over CJK variants, width features• Some width features not defined• Define with vertical text layout controls

font-variant-east-asian

Page 71: The Future of CSS Typography - People of Mozilla

• Some OpenType features allow multiple selections• e.g. swash, styleset, character-variant• Early spec draft used numbers to select• e.g. styleset(1, 2, 5)• Widely disliked, ugly to look at, fallback dodgy• Solution: new @-rule to specify values

font-variant-alternates

Page 72: The Future of CSS Typography - People of Mozilla

Author defines ‘flowing’ to mean second swash alternate

@font-feature-values Jupiter Sans { @swash delicate 1, flowing 2;}

h2 { font-family: Jupiter Sans, sans-serif; }

/* show the second swash variant in h2 headings */h2:first-letter { font-variant-alternates: swash(flowing); }

@font-feature-values

Page 73: The Future of CSS Typography - People of Mozilla

Settings for Whitney from Hoefler & Frere-Jones

@font-feature-values Whitney { @styleset flat-terminals 1; @styleset alt-g 8, alt-a 9, alt-M 10; @styleset curly-quotes 17; }

Real world example

Page 74: The Future of CSS Typography - People of Mozilla

/* dlig=1 enable discretionary ligatures */font-feature-settings: "dlig" 1;

/* smcp=1 enable small caps */font-feature-settings: "smcp" on;

/* liga=0 no common ligatures */font-feature-settings: "liga" off;

• Low-level control over arbitrary features• Syntax is OpenType feature name with value• Interaction with font-variant subproperties• Implemented in Firefox 4 (old syntax)!

font-feature-settings

Page 76: The Future of CSS Typography - People of Mozilla

• OpenType fonts allow language-specific features• Turkish ligatures, Serbian, Bulgarian Cyrillic forms• OpenType language inferred from ‘lang’ attribute• Can be overriden with font-language-override

Language support

Page 78: The Future of CSS Typography - People of Mozilla

Stumbles along the road

Rendering considerations

Page 79: The Future of CSS Typography - People of Mozilla

• Type doesn’t look the same everywhere• Windows is the problem child• Getting better but...• Change is hard• Goal: roughly the same results everywhere

Visual consistency

Page 80: The Future of CSS Typography - People of Mozilla

Font rendering

How to turn a letterform into screen pixels?

Page 81: The Future of CSS Typography - People of Mozilla

Subpixel antialiasing relies on the geometry of a pixel

Page 82: The Future of CSS Typography - People of Mozilla

Subpixel antialiasing relies on the geometry of a pixel

Page 83: The Future of CSS Typography - People of Mozilla

• Cleartype vs. grayscale antialiasing• Windows XP: Cleartype off by default• IE7+ forces it on• FF4: force it on for downloadable fonts• DirectWrite: FF4, IE9 on Windows 7

Type on Windows

Page 84: The Future of CSS Typography - People of Mozilla

Screenshots

Page 85: The Future of CSS Typography - People of Mozilla
Page 86: The Future of CSS Typography - People of Mozilla

Thanks for listening

That’s all folks