diff --git a/src/canvas.js b/src/canvas.js index fdda9f88f..eef785f3b 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -207,7 +207,7 @@ var CanvasExtraState = (function CanvasExtraStateClosure() { var CanvasGraphics = (function CanvasGraphicsClosure() { // Defines the time the executeOperatorList is going to be executing // before it stops and shedules a continue of execution. - var kExecutionTime = 15; + var EXECUTION_TIME = 15; function CanvasGraphics(canvasCtx, commonObjs, objs, textLayer) { this.ctx = canvasCtx; @@ -283,7 +283,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { } var executionEndIdx; - var endTime = Date.now() + kExecutionTime; + var endTime = Date.now() + EXECUTION_TIME; var commonObjs = this.commonObjs; var objs = this.objs; diff --git a/src/evaluator.js b/src/evaluator.js index 7a748c7a6..9ac4a0dc7 100644 --- a/src/evaluator.js +++ b/src/evaluator.js @@ -515,8 +515,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { getTextContent: function PartialEvaluator_getTextContent( stream, resources, state) { var bidiTexts; - var kSpaceFactor = 0.35; - var kMultipleSpaceFactor = 1.5; + var SPACE_FACTOR = 0.35; + var MULTI_SPACE_FACTOR = 1.5; if (!state) { bidiTexts = []; @@ -559,12 +559,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { chunk += fontCharsToUnicode(items[j], font); } else if (items[j] < 0 && font.spaceWidth > 0) { var fakeSpaces = -items[j] / font.spaceWidth; - if (fakeSpaces > kMultipleSpaceFactor) { + if (fakeSpaces > MULTI_SPACE_FACTOR) { fakeSpaces = Math.round(fakeSpaces); while (fakeSpaces--) { chunk += ' '; } - } else if (fakeSpaces > kSpaceFactor) { + } else if (fakeSpaces > SPACE_FACTOR) { chunk += ' '; } } diff --git a/src/fonts.js b/src/fonts.js index 029bcb0d3..3f8928cc4 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -17,22 +17,17 @@ 'use strict'; -/** - * Maximum time to wait for a font to be loaded by font-face rules. - */ -var kMaxWaitForFontFace = 1000; - // Unicode Private Use Area -var kCmapGlyphOffset = 0xE000; -var kSizeOfGlyphArea = 0x1900; -var kSymbolicFontGlyphOffset = 0xF000; +var CMAP_GLYPH_OFFSET = 0xE000; +var GLYPH_AREA_SIZE = 0x1900; +var SYMBOLIC_FONT_GLYPH_OFFSET = 0xF000; // PDF Glyph Space Units are one Thousandth of a TextSpace Unit // except for Type 3 fonts -var kPDFGlyphSpaceUnits = 1000; +var PDF_GLYPH_SPACE_UNITS = 1000; // Until hinting is fully supported this constant can be used -var kHintingEnabled = false; +var HINTING_ENABLED = false; var FontFlags = { FixedPitch: 1, @@ -804,9 +799,9 @@ function isRTLRangeFor(value) { } function isSpecialUnicode(unicode) { - return (unicode <= 0x1F || (unicode >= 127 && unicode < kSizeOfGlyphArea)) || - (unicode >= kCmapGlyphOffset && - unicode < kCmapGlyphOffset + kSizeOfGlyphArea); + return (unicode <= 0x1F || (unicode >= 127 && unicode < GLYPH_AREA_SIZE)) || + (unicode >= CMAP_GLYPH_OFFSET && + unicode < CMAP_GLYPH_OFFSET + GLYPH_AREA_SIZE); } // The normalization table is obtained by filtering the Unicode characters @@ -2627,7 +2622,7 @@ var Font = (function FontClosure() { lastCharIndex = 255; } - var unitsPerEm = override.unitsPerEm || kPDFGlyphSpaceUnits; + var unitsPerEm = override.unitsPerEm || PDF_GLYPH_SPACE_UNITS; var typoAscent = override.ascent || properties.ascent; var typoDescent = override.descent || properties.descent; var winAscent = override.yMax || typoAscent; @@ -2635,12 +2630,13 @@ var Font = (function FontClosure() { // if there is a units per em value but no other override // then scale the calculated ascent - if (unitsPerEm != kPDFGlyphSpaceUnits && + if (unitsPerEm != PDF_GLYPH_SPACE_UNITS && 'undefined' == typeof(override.ascent)) { // if the font units differ to the PDF glyph space units // then scale up the values - typoAscent = Math.round(typoAscent * unitsPerEm / kPDFGlyphSpaceUnits); - typoDescent = Math.round(typoDescent * unitsPerEm / kPDFGlyphSpaceUnits); + typoAscent = Math.round(typoAscent * unitsPerEm / PDF_GLYPH_SPACE_UNITS); + typoDescent = Math.round(typoDescent * unitsPerEm / + PDF_GLYPH_SPACE_UNITS); winAscent = typoAscent; winDescent = -typoDescent; } @@ -3411,13 +3407,13 @@ var Font = (function FontClosure() { } // trying to fit as many unassigned symbols as we can // in the range allocated for the user defined symbols - var unusedUnicode = kCmapGlyphOffset; + var unusedUnicode = CMAP_GLYPH_OFFSET; for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) { var i = unassignedUnicodeItems[j]; var cid = gidToCidMap[i] || i; while (unusedUnicode in usedUnicodes) unusedUnicode++; - if (unusedUnicode >= kCmapGlyphOffset + kSizeOfGlyphArea) + if (unusedUnicode >= CMAP_GLYPH_OFFSET + GLYPH_AREA_SIZE) break; var unicode = unusedUnicode++; this.toFontChar[cid] = unicode; @@ -3441,7 +3437,7 @@ var Font = (function FontClosure() { ids[i] = i; } - var unusedUnicode = kCmapGlyphOffset; + var unusedUnicode = CMAP_GLYPH_OFFSET; var glyphNames = properties.glyphNames || []; var encoding = properties.baseEncoding; var differences = properties.differences; @@ -3522,7 +3518,7 @@ var Font = (function FontClosure() { for (var i = 0, ii = glyphs.length; i < ii; i++) { var code = glyphs[i].unicode; var gid = ids[i]; - glyphs[i].unicode += kCmapGlyphOffset; + glyphs[i].unicode += CMAP_GLYPH_OFFSET; toFontChar[code] = glyphs[i].unicode; var glyphName = glyphNames[gid] || encoding[code]; @@ -3590,7 +3586,7 @@ var Font = (function FontClosure() { if (this.isSymbolicFont) { for (var i = 0, ii = glyphs.length; i < ii; i++) { var code = glyphs[i].unicode & 0xFF; - var fontCharCode = kSymbolicFontGlyphOffset | code; + var fontCharCode = SYMBOLIC_FONT_GLYPH_OFFSET | code; glyphs[i].unicode = toFontChar[code] = fontCharCode; } this.useToFontChar = true; @@ -3695,7 +3691,7 @@ var Font = (function FontClosure() { // to write the table entry information about a table and another offset // representing the offset where to draw the actual data of a particular // table - var kRequiredTablesCount = 9; + var REQ_TABLES_CNT = 9; var otf = { file: '', @@ -3827,7 +3823,7 @@ var Font = (function FontClosure() { buildToFontChar: function Font_buildToFontChar(toUnicode) { var result = []; - var unusedUnicode = kCmapGlyphOffset; + var unusedUnicode = CMAP_GLYPH_OFFSET; for (var i = 0, ii = toUnicode.length; i < ii; i++) { var unicode = toUnicode[i]; var fontCharCode = typeof unicode === 'object' ? unusedUnicode++ : @@ -4151,8 +4147,8 @@ var Type1Parser = function type1Parser() { * of Plaintext Bytes. The function took a key as a parameter which can be * for decrypting the eexec block of for decoding charStrings. */ - var kEexecEncryptionKey = 55665; - var kCharStringsEncryptionKey = 4330; + var EEXEC_ENCRYPT_KEY = 55665; + var CHAR_STRS_ENCRYPT_KEY = 4330; function decrypt(stream, key, discardNumber) { var r = key, c1 = 52845, c2 = 22719; @@ -4268,7 +4264,7 @@ var Type1Parser = function type1Parser() { '31': 'hvcurveto' }; - var kEscapeCommand = 12; + var ESCAPE_CMD = 12; // Breaks up the stack by arguments and also calculates the value. function breakUpArgs(stack, numArgs) { @@ -4320,7 +4316,7 @@ var Type1Parser = function type1Parser() { if (value < 32) { var command = null; - if (value == kEscapeCommand) { + if (value == ESCAPE_CMD) { var escape = array[++i]; // TODO Clean this code @@ -4374,7 +4370,7 @@ var Type1Parser = function type1Parser() { var args = breakUpArgs(charstring, 5); var arg0 = args[0]; charstring.splice(arg0.offset, arg0.arg.length); - } else if (!kHintingEnabled && (escape == 1 || escape == 2)) { + } else if (!HINTING_ENABLED && (escape == 1 || escape == 2)) { charstring.push('drop', 'drop', 'drop', 'drop', 'drop', 'drop'); continue; } @@ -4416,7 +4412,7 @@ var Type1Parser = function type1Parser() { if (flexState > 1) continue; // ignoring rmoveto value = 5; // first segment replacing with rlineto - } else if (!kHintingEnabled && (value == 1 || value == 3)) { + } else if (!HINTING_ENABLED && (value == 1 || value == 3)) { charstring.push('drop', 'drop'); continue; } @@ -4508,7 +4504,7 @@ var Type1Parser = function type1Parser() { } this.extractFontProgram = function Type1Parser_extractFontProgram(stream) { - var eexec = decrypt(stream, kEexecEncryptionKey, 4); + var eexec = decrypt(stream, EEXEC_ENCRYPT_KEY, 4); var eexecStr = ''; for (var i = 0, ii = eexec.length; i < ii; i++) eexecStr += String.fromCharCode(eexec[i]); @@ -4548,7 +4544,7 @@ var Type1Parser = function type1Parser() { i++; var data = eexec.slice(i, i + length); var lenIV = program.properties.privateData['lenIV']; - var encoded = decrypt(data, kCharStringsEncryptionKey, lenIV); + var encoded = decrypt(data, CHAR_STRS_ENCRYPT_KEY, lenIV); var str = decodeCharString(encoded); if (glyphsSection) { @@ -4588,7 +4584,7 @@ var Type1Parser = function type1Parser() { getToken(); // read in 'RD' var data = eexec.slice(i + 1, i + 1 + length); var lenIV = program.properties.privateData['lenIV']; - var encoded = decrypt(data, kCharStringsEncryptionKey, lenIV); + var encoded = decrypt(data, CHAR_STRS_ENCRYPT_KEY, lenIV); var str = decodeCharString(encoded); i = i + 1 + length; t = getToken(); // read in 'NP' @@ -4864,7 +4860,7 @@ Type1Font.prototype = { properties) { var charstrings = []; var i, length, glyphName; - var unusedUnicode = kCmapGlyphOffset; + var unusedUnicode = CMAP_GLYPH_OFFSET; for (i = 0, length = glyphs.length; i < length; i++) { var item = glyphs[i]; var glyphName = item.glyph; @@ -5189,7 +5185,7 @@ var CFFFont = (function CFFFontClosure() { unicodeUsed[code] = true; } - var nextUnusedUnicode = kCmapGlyphOffset; + var nextUnusedUnicode = CMAP_GLYPH_OFFSET; for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; ++j) { var i = unassignedUnicodeItems[j]; // giving unicode value anyway diff --git a/web/viewer.js b/web/viewer.js index ae6e85728..dc0a416d4 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -17,18 +17,19 @@ 'use strict'; -var kDefaultURL = 'compressed.tracemonkey-pldi-09.pdf'; -var kDefaultScale = 'auto'; -var kDefaultScaleDelta = 1.1; -var kUnknownScale = 0; -var kCacheSize = 20; -var kCssUnits = 96.0 / 72.0; -var kScrollbarPadding = 40; -var kVerticalPadding = 5; -var kMinScale = 0.25; -var kMaxScale = 4.0; -var kImageDirectory = './images/'; -var kSettingsMemory = 20; +var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf'; +var DEFAULT_SCALE = 'auto'; +var DEFAULT_SCALE_DELTA = 1.1; +var UNKNOWN_SCALE = 0; +var CACHE_SIZE = 20; +var CSS_UNITS = 96.0 / 72.0; +var SCROLLBAR_PADDING = 40; +var VERTICAL_PADDING = 5; +var MIN_SCALE = 0.25; +var MAX_SCALE = 4.0; +var IMAGE_DIR = './images/'; +var SETTINGS_MEMORY = 20; +var ANNOT_MIN_SIZE = 10; var RenderingStates = { INITIAL: 0, RUNNING: 1, @@ -42,8 +43,6 @@ var FindStates = { FIND_PENDING: 3 }; -var ANNOT_MIN_SIZE = 10; - //#if (FIREFOX || MOZCENTRAL || B2G || GENERIC || CHROME) //PDFJS.workerSrc = '../build/pdf.js'; //#endif @@ -186,7 +185,7 @@ var Settings = (function SettingsClosure() { database = JSON.parse(database); if (!('files' in database)) database.files = []; - if (database.files.length >= kSettingsMemory) + if (database.files.length >= SETTINGS_MEMORY) database.files.shift(); var index; for (var i = 0, length = database.files.length; i < length; i++) { @@ -228,7 +227,7 @@ var Settings = (function SettingsClosure() { return Settings; })(); -var cache = new Cache(kCacheSize); +var cache = new Cache(CACHE_SIZE); var currentPageNumber = 1; var PDFFindController = { @@ -676,7 +675,7 @@ var PDFFindBar = { var PDFView = { pages: [], thumbnails: [], - currentScale: kUnknownScale, + currentScale: UNKNOWN_SCALE, currentScaleValue: null, initialBookmark: document.location.hash.substring(1), startedTextExtraction: false, @@ -742,7 +741,7 @@ var PDFView = { var pages = this.pages; for (var i = 0; i < pages.length; i++) - pages[i].update(val * kCssUnits); + pages[i].update(val * CSS_UNITS); if (!noScroll && this.currentScale != val) this.pages[this.page - 1].scrollIntoView(); @@ -772,10 +771,10 @@ var PDFView = { return; } - var pageWidthScale = (container.clientWidth - kScrollbarPadding) / - currentPage.width * currentPage.scale / kCssUnits; - var pageHeightScale = (container.clientHeight - kVerticalPadding) / - currentPage.height * currentPage.scale / kCssUnits; + var pageWidthScale = (container.clientWidth - SCROLLBAR_PADDING) / + currentPage.width * currentPage.scale / CSS_UNITS; + var pageHeightScale = (container.clientHeight - VERTICAL_PADDING) / + currentPage.height * currentPage.scale / CSS_UNITS; switch (value) { case 'page-actual': scale = 1; @@ -799,14 +798,14 @@ var PDFView = { }, zoomIn: function pdfViewZoomIn() { - var newScale = (this.currentScale * kDefaultScaleDelta).toFixed(2); - newScale = Math.min(kMaxScale, newScale); + var newScale = (this.currentScale * DEFAULT_SCALE_DELTA).toFixed(2); + newScale = Math.min(MAX_SCALE, newScale); this.parseScale(newScale, true); }, zoomOut: function pdfViewZoomOut() { - var newScale = (this.currentScale / kDefaultScaleDelta).toFixed(2); - newScale = Math.max(kMinScale, newScale); + var newScale = (this.currentScale / DEFAULT_SCALE_DELTA).toFixed(2); + newScale = Math.max(MIN_SCALE, newScale); this.parseScale(newScale, true); }, @@ -1312,10 +1311,10 @@ var PDFView = { this.page = 1; } - if (PDFView.currentScale === kUnknownScale) { + if (PDFView.currentScale === UNKNOWN_SCALE) { // Scale was not initialized: invalid bookmark or scale was not specified. // Setting the default one. - this.parseScale(kDefaultScale, true); + this.parseScale(DEFAULT_SCALE, true); } }, @@ -1837,7 +1836,7 @@ var PageView = function pageView(container, pdfPage, id, scale, } var image = createElementWithStyle('img', item, rect); var iconName = item.name; - image.src = kImageDirectory + 'annotation-' + + image.src = IMAGE_DIR + 'annotation-' + iconName.toLowerCase() + '.svg'; image.alt = mozL10n.get('text_annotation_type', {type: iconName}, '[{{type}} Annotation]'); @@ -1941,10 +1940,10 @@ var PageView = function pageView(container, pdfPage, id, scale, y = dest[3]; width = dest[4] - x; height = dest[5] - y; - widthScale = (this.container.clientWidth - kScrollbarPadding) / - width / kCssUnits; - heightScale = (this.container.clientHeight - kScrollbarPadding) / - height / kCssUnits; + widthScale = (this.container.clientWidth - SCROLLBAR_PADDING) / + width / CSS_UNITS; + heightScale = (this.container.clientHeight - SCROLLBAR_PADDING) / + height / CSS_UNITS; scale = Math.min(widthScale, heightScale); break; default: @@ -1953,8 +1952,8 @@ var PageView = function pageView(container, pdfPage, id, scale, if (scale && scale !== PDFView.currentScale) PDFView.parseScale(scale, true, true); - else if (PDFView.currentScale === kUnknownScale) - PDFView.parseScale(kDefaultScale, true, true); + else if (PDFView.currentScale === UNKNOWN_SCALE) + PDFView.parseScale(DEFAULT_SCALE, true, true); var boundingRect = [ this.viewport.convertToViewportPoint(x, y), @@ -2432,9 +2431,9 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) { this.setupRenderLayoutTimer = function textLayerSetupRenderLayoutTimer() { // Schedule renderLayout() if user has been scrolling, otherwise // run it right away - var kRenderDelay = 200; // in ms + var RENDER_DELAY = 200; // in ms var self = this; - if (Date.now() - PDFView.lastScroll > kRenderDelay) { + if (Date.now() - PDFView.lastScroll > RENDER_DELAY) { // Render right away this.renderLayer(); } else { @@ -2443,7 +2442,7 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) { clearTimeout(this.renderTimer); this.renderTimer = setTimeout(function() { self.setupRenderLayoutTimer(); - }, kRenderDelay); + }, RENDER_DELAY); } }; @@ -2693,7 +2692,7 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) { var params = PDFView.parseQueryString(document.location.search.substring(1)); //#if !(FIREFOX || MOZCENTRAL) - var file = params.file || kDefaultURL; + var file = params.file || DEFAULT_URL; //#else //var file = window.location.toString() //#endif @@ -3105,7 +3104,7 @@ window.addEventListener('keydown', function keydown(evt) { handled = true; break; case 48: // '0' - PDFView.parseScale(kDefaultScale, true); + PDFView.parseScale(DEFAULT_SCALE, true); handled = true; break; }