/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ 'use strict'; var isWorker = (typeof window == 'undefined'); /** * Maximum time to wait for a font to be loaded by font-face rules. */ var kMaxWaitForFontFace = 1000; // Unicode Private Use Area var kCmapGlyphOffset = 0xE000; // PDF Glyph Space Units are one Thousandth of a TextSpace Unit // except for Type 3 fonts var kPDFGlyphSpaceUnits = 1000; // Until hinting is fully supported this constant can be used var kHintingEnabled = false; /** * Hold a map of decoded fonts and of the standard fourteen Type1 * fonts and their acronyms. */ var stdFontMap = { 'ArialNarrow': 'Helvetica', 'ArialNarrow_Bold': 'Helvetica-Bold', 'ArialNarrow_BoldItalic': 'Helvetica-BoldOblique', 'ArialNarrow_Italic': 'Helvetica-Oblique', 'ArialBlack': 'Helvetica', 'ArialBlack_Bold': 'Helvetica-Bold', 'ArialBlack_BoldItalic': 'Helvetica-BoldOblique', 'ArialBlack_Italic': 'Helvetica-Oblique', 'Arial': 'Helvetica', 'Arial_Bold': 'Helvetica-Bold', 'Arial_BoldItalic': 'Helvetica-BoldOblique', 'Arial_Italic': 'Helvetica-Oblique', 'Arial_BoldItalicMT': 'Helvetica-BoldOblique', 'Arial_BoldMT': 'Helvetica-Bold', 'Arial_ItalicMT': 'Helvetica-Oblique', 'ArialMT': 'Helvetica', 'Courier_Bold': 'Courier-Bold', 'Courier_BoldItalic': 'Courier-BoldOblique', 'Courier_Italic': 'Courier-Oblique', 'CourierNew': 'Courier', 'CourierNew_Bold': 'Courier-Bold', 'CourierNew_BoldItalic': 'Courier-BoldOblique', 'CourierNew_Italic': 'Courier-Oblique', 'CourierNewPS_BoldItalicMT': 'Courier-BoldOblique', 'CourierNewPS_BoldMT': 'Courier-Bold', 'CourierNewPS_ItalicMT': 'Courier-Oblique', 'CourierNewPSMT': 'Courier', 'Helvetica_Bold': 'Helvetica-Bold', 'Helvetica_BoldItalic': 'Helvetica-BoldOblique', 'Helvetica_Italic': 'Helvetica-Oblique', 'Symbol_Bold': 'Symbol', 'Symbol_BoldItalic': 'Symbol', 'Symbol_Italic': 'Symbol', 'TimesNewRoman': 'Times-Roman', 'TimesNewRoman_Bold': 'Times-Bold', 'TimesNewRoman_BoldItalic': 'Times-BoldItalic', 'TimesNewRoman_Italic': 'Times-Italic', 'TimesNewRomanPS': 'Times-Roman', 'TimesNewRomanPS_Bold': 'Times-Bold', 'TimesNewRomanPS_BoldItalic': 'Times-BoldItalic', 'TimesNewRomanPS_BoldItalicMT': 'Times-BoldItalic', 'TimesNewRomanPS_BoldMT': 'Times-Bold', 'TimesNewRomanPS_Italic': 'Times-Italic', 'TimesNewRomanPS_ItalicMT': 'Times-Italic', 'TimesNewRomanPSMT': 'Times-Roman', 'TimesNewRomanPSMT_Bold': 'Times-Bold', 'TimesNewRomanPSMT_BoldItalic': 'Times-BoldItalic', 'TimesNewRomanPSMT_Italic': 'Times-Italic' }; var serifFonts = { 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true, 'Aldus': true, 'Alexandria': true, 'Algerian': true, 'American Typewriter': true, 'Antiqua': true, 'Apex': true, 'Arno': true, 'Aster': true, 'Aurora': true, 'Baskerville': true, 'Bell': true, 'Bembo': true, 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true, 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true, 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true, 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true, 'Calvert': true, 'Capitals': true, 'Cambria': true, 'Cartier': true, 'Caslon': true, 'Catull': true, 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true, 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true, 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true, 'Cochin': true, 'Colonna': true, 'Computer Modern': true, 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true, 'Corona': true, 'Ecotype': true, 'Egyptienne': true, 'Elephant': true, 'Excelsior': true, 'Fairfield': true, 'FF Scala': true, 'Folkard': true, 'Footlight': true, 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true, 'Gentium': true, 'Georgia': true, 'Gloucester': true, 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true, 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true, 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true, 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true, 'Ionic No. 5': true, 'Janson': true, 'Joanna': true, 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true, 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true, 'Lucida Bright': true, 'Melior': true, 'Memphis': true, 'Miller': true, 'Minion': true, 'Modern': true, 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true, 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true, 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true, 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true, 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true, 'Requiem': true, 'Rockwell': true, 'Roman': true, 'Rotis Serif': true, 'Sabon': true, 'Scala': true, 'Seagull': true, 'Sistina': true, 'Souvenir': true, 'STIX': true, 'Stone Informal': true, 'Stone Serif': true, 'Sylfaen': true, 'Times': true, 'Trajan': true, 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true, 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true, 'Versailles': true, 'Wanted': true, 'Weiss': true, 'Wide Latin': true, 'Windsor': true, 'XITS': true }; var FontLoader = { listeningForFontLoad: false, bind: function fontLoaderBind(fonts, callback) { function checkFontsLoaded() { for (var i = 0; i < objs.length; i++) { var fontObj = objs[i]; if (fontObj.loading) { return false; } } document.documentElement.removeEventListener( 'pdfjsFontLoad', checkFontsLoaded, false); callback(); return true; } var rules = [], names = [], objs = []; for (var i = 0; i < fonts.length; i++) { var font = fonts[i]; var obj = new Font(font.name, font.file, font.properties); objs.push(obj); var str = ''; var data = obj.data; if (data) { var length = data.length; for (var j = 0; j < length; j++) str += String.fromCharCode(data[j]); var rule = isWorker ? obj.bindWorker(str) : obj.bindDOM(str); if (rule) { rules.push(rule); names.push(obj.loadedName); } } } this.listeningForFontLoad = false; if (!isWorker && rules.length) { FontLoader.prepareFontLoadEvent(rules, names, objs); } if (!checkFontsLoaded()) { document.documentElement.addEventListener( 'pdfjsFontLoad', checkFontsLoaded, false); } return objs; }, // Set things up so that at least one pdfjsFontLoad event is // dispatched when all the @font-face |rules| for |names| have been // loaded in a subdocument. It's expected that the load of |rules| // has already started in this (outer) document, so that they should // be ordered before the load in the subdocument. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules, names, objs) { /** Hack begin */ // There's no event when a font has finished downloading so the // following code is a dirty hack to 'guess' when a font is // ready. This code will be obsoleted by Mozilla bug 471915. // // The only reliable way to know if a font is loaded in Gecko // (at the moment) is document.onload in a document with // a @font-face rule defined in a "static" stylesheet. We use a // subdocument in an