├── .gitignore ├── .travis.yml ├── test ├── fonts │ ├── PTSerif-Bold.woff │ ├── PTSerif-Bold.woff2 │ ├── PTSerif-Italic.woff │ ├── PTSerif-Italic.woff2 │ ├── PTSerif-Regular.woff │ └── PTSerif-Regular.woff2 ├── example │ └── index.js └── test.coffee ├── .npmignore ├── .editorconfig ├── Changelog.md ├── index.js ├── .jshintrc ├── License.md ├── package.json ├── .jscs.json ├── Contributing.md ├── Readme.md ├── lib └── fontoptim.js └── demo ├── js └── fontloader.js └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | -------------------------------------------------------------------------------- /test/fonts/PTSerif-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sapegin/fontoptim/HEAD/test/fonts/PTSerif-Bold.woff -------------------------------------------------------------------------------- /test/fonts/PTSerif-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sapegin/fontoptim/HEAD/test/fonts/PTSerif-Bold.woff2 -------------------------------------------------------------------------------- /test/fonts/PTSerif-Italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sapegin/fontoptim/HEAD/test/fonts/PTSerif-Italic.woff -------------------------------------------------------------------------------- /test/fonts/PTSerif-Italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sapegin/fontoptim/HEAD/test/fonts/PTSerif-Italic.woff2 -------------------------------------------------------------------------------- /test/fonts/PTSerif-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sapegin/fontoptim/HEAD/test/fonts/PTSerif-Regular.woff -------------------------------------------------------------------------------- /test/fonts/PTSerif-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sapegin/fontoptim/HEAD/test/fonts/PTSerif-Regular.woff2 -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | test 3 | demo 4 | .editorconfig 5 | .gitignore 6 | .jscs.json 7 | .jshintrc 8 | .travis.yml 9 | Contributing.md 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = tab 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [test/expected/*.css] 12 | insert_final_newline = false 13 | -------------------------------------------------------------------------------- /Changelog.md: -------------------------------------------------------------------------------- 1 | # 0.2.0 - 2016-10-10 2 | 3 | * Change MIME types to `application/font-woff` and `font/woff2` (#4 by @c01nd01r). 4 | 5 | ### 2015-01-22 v0.1.0 6 | 7 | * Change MIME types to `application/font-woff` and `application/font-woff2` (#1). 8 | 9 | ### 2015-01-20 v0.0.1 10 | 11 | * First release. 12 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Generates CSS with WOFF(2) fonts embedded as Base64. 3 | * 4 | * @author Artem Sapegin (http://sapegin.me) 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var FontOptim = require('./lib/fontoptim'); 10 | 11 | module.exports = function(fonts, options) { 12 | return (new FontOptim(fonts, options)).generate(); 13 | }; 14 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "white": false, 4 | "smarttabs": true, 5 | "eqeqeq": true, 6 | "immed": true, 7 | "latedef": false, 8 | "newcap": true, 9 | "undef": true, 10 | "trailing": true, 11 | "esnext": true, 12 | "camelcase": true, 13 | "bitwise": true, 14 | "noempty": true, 15 | "unused": "vars", 16 | "strict": true 17 | } 18 | -------------------------------------------------------------------------------- /test/example/index.js: -------------------------------------------------------------------------------- 1 | module.exports = function() { 2 | 'use strict'; 3 | 4 | var fs = require('fs'); 5 | var fontoptim = require('../../index'); 6 | 7 | var fonts = { 8 | 'PTSerif-Bold.woff': fs.readFileSync('test/fonts/PTSerif-Bold.woff'), 9 | 'PTSerif-Bold.woff2': fs.readFileSync('test/fonts/PTSerif-Bold.woff2'), 10 | 'PTSerif-Italic.woff': fs.readFileSync('test/fonts/PTSerif-Italic.woff'), 11 | 'PTSerif-Italic.woff2': fs.readFileSync('test/fonts/PTSerif-Italic.woff2'), 12 | 'PTSerif-Regular.woff': fs.readFileSync('test/fonts/PTSerif-Regular.woff'), 13 | 'PTSerif-Regular.woff2': fs.readFileSync('test/fonts/PTSerif-Regular.woff2') 14 | }; 15 | 16 | var css = fontoptim(fonts, {fontFamily: 'PT Serif'}); 17 | 18 | fs.writeFileSync('test/tmp/ptserif.woff.css', css.woff); 19 | fs.writeFileSync('test/tmp/ptserif.woff2.css', css.woff2); 20 | }; 21 | -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | The MIT License 2 | =============== 3 | 4 | Copyright © 2015 Artem Sapegin (http://sapegin.me), contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | 'Software'), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fontoptim", 3 | "description": "Generates CSS with WOFF(2) fonts embedded as Base64", 4 | "version": "0.2.0", 5 | "homepage": "https://github.com/sapegin/fontoptim", 6 | "author": { 7 | "name": "Artem Sapegin", 8 | "url": "http://sapegin.me/" 9 | }, 10 | "license": "MIT", 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/sapegin/fontoptim.git" 14 | }, 15 | "bugs": { 16 | "url": "https://github.com/sapegin/fontoptim/issues" 17 | }, 18 | "licenses": [ 19 | { 20 | "type": "MIT", 21 | "url": "https://github.com/sapegin/fontoptim/blob/master/License.md" 22 | } 23 | ], 24 | "main": "index.js", 25 | "scripts": { 26 | "jshint": "jshint --reporter node_modules/jshint-stylish/stylish.js index.js", 27 | "jscs": "jscs index.js", 28 | "mocha": "mocha --reporter spec --compilers coffee:coffee-script/register", 29 | "test": "npm run jshint && npm run jscs && npm run mocha" 30 | }, 31 | "engines": { 32 | "node": ">=0.10.0" 33 | }, 34 | "dependencies": { 35 | "lodash": "~4.16.4" 36 | }, 37 | "devDependencies": { 38 | "chai": "~1.10.0", 39 | "coffee-script": "~1.8.0", 40 | "glob": "~4.3.5", 41 | "jscs": "~1.10.0", 42 | "jshint": "~2.5.11", 43 | "jshint-stylish": "~1.0.0", 44 | "mocha": "~2.1.0" 45 | }, 46 | "keywords": [ 47 | "font", 48 | "webfont", 49 | "woff", 50 | "woff2", 51 | "font-face", 52 | "fontface", 53 | "base64", 54 | "performance", 55 | "optimization", 56 | "optimisation", 57 | "embed", 58 | "inline" 59 | ] 60 | } 61 | -------------------------------------------------------------------------------- /.jscs.json: -------------------------------------------------------------------------------- 1 | { 2 | "requireCurlyBraces": ["for", "while", "do"], 3 | "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return"], 4 | "requireParenthesesAroundIIFE": true, 5 | "requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true }, 6 | "disallowSpacesInFunctionExpression": { "beforeOpeningRoundBrace": true }, 7 | "disallowMultipleVarDecl": true, 8 | "disallowSpacesInsideObjectBrackets": true, 9 | "disallowSpacesInsideArrayBrackets": true, 10 | "disallowSpacesInsideParentheses": true, 11 | "disallowSpaceAfterObjectKeys": true, 12 | "requireCommaBeforeLineBreak": true, 13 | "requireOperatorBeforeLineBreak": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 14 | "disallowSpaceAfterBinaryOperators": ["!"], 15 | "disallowSpaceBeforeBinaryOperators": [","], 16 | "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], 17 | "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], 18 | "requireSpaceBeforeBinaryOperators": ["?", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 19 | "requireSpaceAfterBinaryOperators": ["?", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 20 | "requireCamelCaseOrUpperCaseIdentifiers": true, 21 | "disallowKeywords": ["with"], 22 | "disallowMultipleLineStrings": true, 23 | "validateLineBreaks": "LF", 24 | "validateIndentation": "\t", 25 | "disallowMixedSpacesAndTabs": "smart", 26 | "disallowTrailingWhitespace": true, 27 | "requireKeywordsOnNewLine": ["else"], 28 | "requireLineFeedAtFileEnd": true, 29 | "maximumLineLength": 140, 30 | "safeContextKeyword": "that", 31 | "requireDotNotation": true, 32 | "validateJSDoc": { 33 | "checkParamNames": true, 34 | "checkRedundantParams": true, 35 | "requireParamTypes": true 36 | }, 37 | "excludeFiles": ["node_modules/**"] 38 | } 39 | -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | I love pull requests. And following this simple guidelines will make your pull request easier to merge. 4 | 5 | 6 | ## Submitting pull requests 7 | 8 | 1. Create a new branch, please don’t work in master directly. 9 | 2. Add failing tests (if there’re any tests in project) for the change you want to make. Run tests (usually `grunt` or `npm test`) to see the tests fail. 10 | 3. Hack on. 11 | 4. Run tests to see if the tests pass. Repeat steps 2–4 until done. 12 | 5. Update the documentation to reflect any changes. 13 | 6. Push to your fork and submit a pull request. 14 | 15 | 16 | ## JavaScript code style 17 | 18 | - Tab indentation. 19 | - Single-quotes. 20 | - Semicolon. 21 | - Strict mode. 22 | - No trailing whitespace. 23 | - Variables where needed. 24 | - Multiple variable statements. 25 | - Space after keywords and between arguments and operators. 26 | - Use === and !== over == and !=. 27 | - Return early. 28 | - Limit line lengths to 120 chars. 29 | - Prefer readability over religion. 30 | 31 | Example: 32 | 33 | ```js 34 | 'use strict'; 35 | 36 | function foo(bar, fum) { 37 | if (!bar) return; 38 | 39 | var hello = 'Hello'; 40 | var ret = 0; 41 | for (var barIdx = 0; barIdx < bar.length; barIdx++) { 42 | if (bar[barIdx] === hello) { 43 | ret += fum(bar[barIdx]); 44 | } 45 | } 46 | 47 | return ret; 48 | } 49 | ``` 50 | 51 | 52 | ## Other notes 53 | 54 | - If you have commit access to repo and want to make big change or not sure about something, make a new branch and open pull request. 55 | - Don’t commit generated files: compiled from Stylus CSS, minified JavaScript, etc. 56 | - Install [EditorConfig](http://editorconfig.org/) plugin for your code editor. 57 | - If code you change uses different style (probably it’s an old code) use file’s style instead of style described on this page. 58 | - Feel free to [ask me](http://sapegin.me/contacts) anything you need. 59 | 60 | 61 | ## How to run tests 62 | 63 | Install dependencies: 64 | 65 | ```bash 66 | npm install 67 | ``` 68 | 69 | Run: 70 | 71 | ```bash 72 | npm test 73 | ``` 74 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # fontoptim 2 | 3 | [![Build Status](https://travis-ci.org/sapegin/fontoptim.png)](https://travis-ci.org/sapegin/fontoptim) 4 | 5 | Generates CSS with WOFF(2) fonts embedded as Base64. Use these CSS to load webfonts asynchronously, avoid invisible text and reduce flickering. 6 | 7 | Based on ideas from Adam Beres-Deak’s article [Better webfont loading with using localStorage and providing WOFF2 support](http://bdadam.com/blog/better-webfont-loading-with-localstorage-and-woff2.html). 8 | 9 | ## Installation 10 | 11 | ``` 12 | npm install --save fontoptim 13 | ``` 14 | 15 | 16 | ## Example 17 | 18 | You need WOFF and WOFF2 font files to use fontoptim (you can make them with Font Squirrel’s [webfont generator](http://www.fontsquirrel.com/tools/webfont-generator)): 19 | 20 | ```js 21 | var fs = require('fs'); 22 | var fontoptim = require('fontoptim'); 23 | var fonts = { 24 | 'PTSerif-Bold.woff': fs.readFileSync('fonts/PTSerif-Bold.woff'), 25 | 'PTSerif-Bold.woff2': fs.readFileSync('fonts/PTSerif-Bold.woff2'), 26 | 'PTSerif-Italic.woff': fs.readFileSync('fonts/PTSerif-Italic.woff'), 27 | // ... 28 | }; 29 | var css = fontoptim(fonts, {fontFamily: 'PT Serif'}); 30 | // css.woff = '@font-face{font-family:"PT Serif";src:url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAU...' 31 | // css.woff2 = '@font-face{font-family:"PT Serif";src:url(data:font/woff2;charset=utf-8;base64,d09GMgABAAAAA...' 32 | fs.writeFileSync('build/ptserif.woff.css', css.woff); 33 | fs.writeFileSync('build/ptserif.woff2.css', css.woff2); 34 | ``` 35 | 36 | Then load these CSS files with [`loadFont`](demo/js/fontloader.js) function. 37 | 38 | ```html 39 | 40 | 41 | 42 | 43 | 44 | 45 | 47 | 48 | 49 | ... 50 | ``` 51 | 52 | See `demo` folder for details. 53 | 54 | 55 | ## Build systems 56 | 57 | ### Grunt 58 | 59 | * [grunt-fontoptim](https://github.com/sapegin/grunt-fontoptim) 60 | 61 | 62 | ## Resources 63 | 64 | * [Better webfont loading with using localStorage and providing WOFF2 support](http://bdadam.com/blog/better-webfont-loading-with-localstorage-and-woff2.html) 65 | * [Font Squirrel’s webfont generator](http://www.fontsquirrel.com/tools/webfont-generator) 66 | 67 | 68 | ## Changelog 69 | 70 | The changelog can be found in the [Changelog.md](Changelog.md) file. 71 | 72 | ## Author 73 | 74 | * [Artem Sapegin](http://sapegin.me/) 75 | 76 | --- 77 | 78 | ## License 79 | 80 | The MIT License, see the included [License.md](License.md) file. 81 | -------------------------------------------------------------------------------- /lib/fontoptim.js: -------------------------------------------------------------------------------- 1 | /** 2 | * FontOptim main class. 3 | * 4 | * @author Artem Sapegin (http://sapegin.me) 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var path = require('path'); 10 | var _ = require('lodash'); 11 | 12 | var mimeFonts = { 13 | woff: 'application/font-woff', 14 | woff2: 'font/woff2', 15 | }; 16 | 17 | function FontOptim(fonts, options) { 18 | this.fonts = fonts; 19 | _.extend(this, this.defaults, options); 20 | this.fontFaceTemplate = _.template(this.fontFaceTemplate); 21 | this.fontUriTemplate = _.template(this.fontUriTemplate); 22 | } 23 | 24 | FontOptim.prototype = { 25 | defaults: { 26 | fontFaceTemplate: [ 27 | '@font-face{', 28 | 'font-family:"<%=family%>";', 29 | 'src:url(<%=uri%>) format("<%=format%>");', 30 | 'font-weight:<%=weight%>;', 31 | 'font-style:<%=style%>', 32 | '}' 33 | ].join(''), 34 | fontUriTemplate: 'data:<%=mime%>;charset=utf-8;base64,<%=base64%>', 35 | banner: '/* Generated by github.com/sapegin/fontoptim */\n' 36 | }, 37 | 38 | generate: function() { 39 | var formats = this.getCssLinesForFormats(); 40 | formats = _.mapValues(formats, this.prependBannerAndJoinLines.bind(this)); 41 | return formats; 42 | }, 43 | 44 | getCssLinesForFormats: function() { 45 | var css = {}; 46 | for (var filename in this.fonts) { 47 | var format = this.getFontFormat(filename); 48 | if (!css[format]) { 49 | css[format] = []; 50 | } 51 | css[format].push(this.getFontFace(filename, format, this.fonts[filename])); 52 | } 53 | return css; 54 | }, 55 | 56 | prependBannerAndJoinLines: function(lines) { 57 | return this.banner + lines.join('\n'); 58 | }, 59 | 60 | getFontFace: function(filename, format, font) { 61 | return this.fontFaceTemplate({ 62 | format: format, 63 | family: this.fontFamily, 64 | uri: this.getFontUri(format, font), 65 | weight: this.getFontWeight(filename), 66 | style: this.getFontStyle(filename) 67 | }); 68 | }, 69 | 70 | getFontUri: function(format, font) { 71 | var base64 = this.stringToBase64(font); 72 | var mime = this.getMimeType(format); 73 | return this.fontUriTemplate({ 74 | format: format, 75 | mime: mime, 76 | base64: base64 77 | }); 78 | }, 79 | 80 | getMimeType: function(format) { 81 | return mimeFonts[format]; 82 | }, 83 | 84 | getFontFormat: function(filename) { 85 | var extension = path.extname(filename); 86 | return extension.substring(1); 87 | }, 88 | 89 | getFontWeight: function(filename) { 90 | return /bold/i.test(filename) ? 600 : 400; 91 | }, 92 | 93 | getFontStyle: function(filename) { 94 | return /italic/i.test(filename) ? 'italic' : 'normal'; 95 | }, 96 | 97 | stringToBase64: function(string) { 98 | return new Buffer(string).toString('base64'); 99 | } 100 | }; 101 | 102 | module.exports = FontOptim; 103 | -------------------------------------------------------------------------------- /demo/js/fontloader.js: -------------------------------------------------------------------------------- 1 | // Based on http://bdadam.com/blog/better-webfont-loading-with-localstorage-and-woff2.html 2 | // This script must be placed in the HEAD above all external stylesheet declarations (link[rel=stylesheet]) 3 | /*jshint unused:false*/ 4 | /*global FontFace:false*/ 5 | function loadFont(fontName, fontUrlBase) { 6 | 'use strict'; 7 | 8 | // 0. Many unsupported browsers should stop here 9 | var ua = navigator.userAgent; 10 | var noSupport = !window.addEventListener || // IE8 and below 11 | (ua.match(/(Android (2|3|4.0|4.1|4.2|4.3))|(Opera (Mini|Mobi))/) && !ua.match(/Chrome/)); // Android Stock Browser below 4.4 and Opera Mini 12 | if (noSupport) return; 13 | 14 | // 1. Setting up localStorage 15 | var loSto = {}; 16 | try { 17 | // We set up a proxy variable to help with localStorage, e.g. when cookies are disabled 18 | // and the browser prevents us accessing it. 19 | // Otherwise some exceptions can be thrown which completely prevent font loading. 20 | loSto = localStorage || {}; 21 | } 22 | catch (ex) { 23 | } 24 | 25 | var localStoragePrefix = 'font-' + fontName; 26 | var localStorageUrlKey = localStoragePrefix + 'url'; 27 | var localStorageCssKey = localStoragePrefix + 'css'; 28 | var storedFontUrlBase = loSto[localStorageUrlKey]; 29 | var storedFontCss = loSto[localStorageCssKey]; 30 | 31 | 32 | // 2. Setting up the 17 | 18 | 19 | 20 |

Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, ‘and what is the use of a book,’ thought Alice ‘without pictures or conversation?’

21 | 22 |

So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy- chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.

23 | 24 |

There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, ‘Oh dear! Oh dear! I shall be late!’ (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually took a watch out of its waistcoat- pocket, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.

25 | 26 |

In another moment down went Alice after it, never once considering how in the world she was to get out again.

27 | 28 |

The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well.

29 | 30 |

Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled ‘ORANGE MARMALADE’, but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it.

31 | 32 |

‘Well!’ thought Alice to herself, ‘after such a fall as this, I shall think nothing of tumbling down stairs! How brave they’ll all think me at home! Why, I wouldn’t say anything about it, even if I fell off the top of the house!’ (Which was very likely true.)

33 | 34 |

Down, down, down. Would the fall never come to an end! ‘I wonder how many miles I’ve fallen by this time?’ she said aloud. ‘I must be getting somewhere near the centre of the earth. Let me see: that would be four thousand miles down , I think—’ (for, you see, Alice had learnt several things of this sort in her lessons in the schoolroom, and though this was not a very good opportunity for showing off her knowledge, as there was no one to listen to her, still it was good practice to say it over) ‘—yes, that’s about the right distance—but then I wonder what Latitude or Longitude I’ve got to?’ (Alice had no idea what Latitude was, or Longitude either, but thought they were nice grand words to say .)

35 | 36 |

Presently she began again. ‘I wonder if I shall fall right through the earth! How funny it’ll seem to come out among the people that walk with their heads downward! The Antipathies, I think—’ (she was rather glad there was no one listening, this time, as it didn’t sound at all the right word) ‘—but I shall have to ask them what the name of the country is, you know. Please, Ma’ am, is this New Zealand or Australia?’ (and she tried to curtsey as she spoke— fancy curtseying as you’re falling through the air! Do you think you could manage it?) ‘And what an ignorant little girl she’ll think me for asking! No, it’ll never do to ask: perhaps I shall see it written up somewhere.’

37 | 38 |

Down, down, down. There was nothing else to do, so Alice soon began talking again. ‘Dinah’ll miss me very much to-night, I should think!’ (Dinah was the cat .) ‘I hope they’ll remember her saucer of milk at tea-time. Dinah my dear! I wish you were down here with me! There are no mice in the air, I’m afraid, but you might catch a bat, and that’s very like a mouse, you know. But do cats eat bats, I wonder?’ And here Alice began to get rather sleepy, and went on saying to herself, in a dreamy sort of way, ‘Do cats eat bats? Do cats eat bats?’ and sometimes, ‘Do bats eat cats?’ for, you see, as she couldn’t answer either question, it didn’t much matter which way she put it. She felt that she was dozing off, and had just begun to dream that she was walking hand in hand with Dinah, and saying to her very earnestly, ‘Now, Dinah, tell me the truth: did you ever eat a bat?’ when suddenly, thump! thump! down she came upon a heap of sticks and dry leaves, and the fall was over.

39 | 40 |

Alice was not a bit hurt, and she jumped up on to her feet in a moment: she looked up, but it was all dark overhead; before her was another long passage, and the White Rabbit was still in sight, hurrying down it. There was not a moment to be lost: away went Alice like the wind, and was just in time to hear it say, as it turned a corner, ‘Oh my ears and whiskers, how late it’s getting!’ She was close behind it when she turned the corner, but the Rabbit was no longer to be seen: she found herself in a long, low hall, which was lit up by a row of lamps hanging from the roof.

41 | 42 |

There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again.

43 | 44 |

Suddenly she came upon a little three-legged table, all made of solid glass; there was nothing on it except a tiny golden key, and Alice’s first thought was that it might belong to one of the doors of the hall; but, alas! either the locks were too large, or the key was too small, but at any rate it would not open any of them. However, on the second time round, she came upon a low curtain she had not noticed before, and behind it was a little door about fifteen inches high: she tried the little golden key in the lock, and to her great delight it fitted!

45 | 46 |

Alice opened the door and found that it led into a small passage, not much larger than a rat-hole: she knelt down and looked along the passage into the loveliest garden you ever saw. How she longed to get out of that dark hall, and wander about among those beds of bright flowers and those cool fountains, but she could not even get her head though the doorway; ‘and even if my head would go through,’ thought poor Alice, ‘it would be of very little use without my shoulders. Oh, how I wish I could shut up like a telescope! I think I could, if I only know how to begin.’ For, you see, so many out-of-the-way things had happened lately, that Alice had begun to think that very few things indeed were really impossible.

47 | 48 |

There seemed to be no use in waiting by the little door, so she went back to the table, half hoping she might find another key on it, or at any rate a book of rules for shutting people up like telescopes: this time she found a little bottle on it, (‘which certainly was not here before,’ said Alice,) and round the neck of the bottle was a paper label, with the words ‘DRINK ME’ beautifully printed on it in large letters.

49 | 50 |

It was all very well to say ‘Drink me,’ but the wise little Alice was not going to do that in a hurry. ‘No, I’ll look first,’ she said, ‘and see whether it’s marked "poison" or not’; for she had read several nice little histories about children who had got burnt, and eaten up by wild beasts and other unpleasant things, all because they would not remember the simple rules their friends had taught them: such as, that a red-hot poker will burn you if you hold it too long; and that if you cut your finger very deeply with a knife, it usually bleeds; and she had never forgotten that, if you drink much from a bottle marked ‘poison,’ it is almost certain to disagree with you, sooner or later.

51 | 52 |

However, this bottle was NOT marked ‘poison,’ so Alice ventured to taste it, and finding it very nice, (it had, in fact, a sort of mixed flavour of cherry- tart, custard, pine-apple, roast turkey, toffee, and hot buttered toast,) she very soon finished it off.

53 | 54 | 55 | --------------------------------------------------------------------------------