Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Kalervo Kujala 2012-08-30 14:49:08 +03:00
commit aea65f8d7d
12 changed files with 314 additions and 130 deletions

View File

@ -1,24 +1,17 @@
Copyright (C) 2011 by notmasteryet
Copyright (C) 2011 notmasteryet
Contributors: Yury Delendik
Brendan Dahl <bdahl@mozilla.com>
Contributors: Yury Delendik <ydelendik@mozilla.com>
Brendan Dahl <bdahl@mozilla.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
http://www.apache.org/licenses/LICENSE-2.0
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

27
external/jpgjs/jpg.js vendored
View File

@ -1,5 +1,20 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/*
Copyright 2011 notmasteryet
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// - The JPEG specification can be found in the ITU CCITT Recommendation T.81
// (www.w3.org/Graphics/JPEG/itu-t81.pdf)
@ -627,8 +642,9 @@ var JpegImage = (function jpegImage() {
break;
case 0xFFDB: // DQT (Define Quantization Tables)
var quantizationTableCount = Math.floor((readUint16() - 2) / 65);
for (i = 0; i < quantizationTableCount; i++) {
var quantizationTablesLength = readUint16();
var quantizationTablesEnd = quantizationTablesLength + offset - 2;
while (offset < quantizationTablesEnd) {
var quantizationTableSpec = data[offset++];
var tableData = new Int32Array(64);
if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
@ -721,6 +737,13 @@ var JpegImage = (function jpegImage() {
offset += processed;
break;
default:
if (data[offset - 3] == 0xFF &&
data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
// could be incorrect encoding -- last 0xFF byte of the previous
// block was eaten by the encoder
offset -= 3;
break;
}
throw "unknown JPEG marker " + fileMarker.toString(16);
}
fileMarker = readUint16();

68
make.js
View File

@ -6,6 +6,7 @@ var ROOT_DIR = __dirname + '/', // absolute path to project's root
BUILD_DIR = 'build/',
BUILD_TARGET = BUILD_DIR + 'pdf.js',
FIREFOX_BUILD_DIR = BUILD_DIR + '/firefox/',
CHROME_BUILD_DIR = BUILD_DIR + '/chrome/',
EXTENSION_SRC_DIR = 'extensions/',
LOCALE_SRC_DIR = 'l10n/',
GH_PAGES_DIR = BUILD_DIR + 'gh-pages/',
@ -107,6 +108,8 @@ target.web = function() {
cp('-R', GENERIC_DIR + '/*', GH_PAGES_DIR);
cp(FIREFOX_BUILD_DIR + '/*.xpi', FIREFOX_BUILD_DIR + '/*.rdf',
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/');
cp(CHROME_BUILD_DIR + '/*.crx', FIREFOX_BUILD_DIR + '/*.rdf',
GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chrome/');
cp('web/index.html.template', GH_PAGES_DIR + '/index.html');
cd(GH_PAGES_DIR);
@ -258,6 +261,7 @@ target.pagesrepo = function() {
mkdir('-p', GH_PAGES_DIR + '/web/images');
mkdir('-p', GH_PAGES_DIR + BUILD_DIR);
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/firefox');
mkdir('-p', GH_PAGES_DIR + EXTENSION_SRC_DIR + '/chrome');
};
@ -574,6 +578,70 @@ target.chrome = function() {
]
};
builder.build(setup);
// Bundle the files to a Chrome extension file .crx if path to key is set
var pem = env['PDFJS_CHROME_KEY'];
if (!pem) {
return;
}
echo();
echo('### Bundling .crx extension into ' + CHROME_BUILD_DIR);
if (!test('-f', pem)) {
echo('Incorrect PDFJS_CHROME_KEY path');
exit(1);
}
var browserManifest = env['PDF_BROWSERS'] ||
'test/resources/browser_manifests/browser_manifest.json';
if (!test('-f', browserManifest)) {
echo('Browser manifest file ' + browserManifest + ' does not exist.');
echo('Try copying one of the examples in test/resources/browser_manifests');
exit(1);
}
try {
var manifest = JSON.parse(cat(browserManifest));
} catch (e) {
echo('Malformed browser manifest file');
echo(e.message);
exit(1);
}
var executable;
manifest.forEach(function(browser) {
if (browser.name === 'chrome') {
executable = browser.path;
}
});
// If there was no chrome entry in the browser manifest, exit
if (!executable) {
echo('There was no \'chrome\' entry in the browser manifest');
exit(1);
}
// If we're on a Darwin (Mac) OS, then let's check for an .app path
if (process.platform === 'darwin' && executable.indexOf('.app') !== -1) {
executable = executable + '/Contents/MacOS/Google Chrome';
}
// If the chrome executable doesn't exist
if (!test('-f', executable)) {
echo('Incorrect executable path to chrome');
exit(1);
}
// Let chrome pack the extension for us
exec('"' + executable + '"' +
' --no-message-box' +
' "--pack-extension=' + ROOT_DIR + CHROME_BUILD_DIR + '"' +
' "--pack-extension-key=' + pem + '"');
// Rename to pdf.js.crx
mv(BUILD_DIR + 'chrome.crx', CHROME_BUILD_DIR + 'pdf.js.crx');
};

View File

@ -311,13 +311,19 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
ensureFonts: function PDFPageProxy_ensureFonts(fonts, callback) {
this.stats.time('Font Loading');
// Convert the font names to the corresponding font obj.
var fontObjs = [];
for (var i = 0, ii = fonts.length; i < ii; i++) {
fonts[i] = this.objs.objs[fonts[i]].data;
var obj = this.objs.objs[fonts[i]].data;
if (obj.error) {
warn('Error during font loading: ' + obj.error);
continue;
}
fontObjs.push(obj);
}
// Load all the fonts
FontLoader.bind(
fonts,
fontObjs,
function pageEnsureFontsFontObjs(fontObjs) {
this.stats.timeEnd('Font Loading');
@ -565,7 +571,12 @@ var WorkerTransport = (function WorkerTransportClosure() {
// At this point, only the font object is created but the font is
// not yet attached to the DOM. This is done in `FontLoader.bind`.
var font = new Font(name, file, properties);
var font;
try {
font = new Font(name, file, properties);
} catch (e) {
font = new ErrorFont(e);
}
this.objs.resolve(id, font);
break;
default:

View File

@ -404,28 +404,15 @@ function mapPrivateUseChars(code) {
}
var FontLoader = {
listeningForFontLoad: false,
loadingContext: {
requests: [],
nextRequestId: 0
},
bind: function fontLoaderBind(fonts, callback) {
function checkFontsLoaded() {
for (var i = 0, ii = fonts.length; i < ii; i++) {
var fontObj = fonts[i];
if (fontObj.loading) {
return false;
}
}
document.documentElement.removeEventListener(
'pdfjsFontLoad', checkFontsLoaded, false);
// Use timeout to fix chrome intermittent failures on font loading.
setTimeout(callback, 0);
return true;
}
var rules = [], names = [], fontsToLoad = [];
var fontCreateTimer = 0;
assert(!isWorker, 'bind() shall be called from main thread');
var rules = [], fontsToLoad = [];
for (var i = 0, ii = fonts.length; i < ii; i++) {
var font = fonts[i];
@ -436,8 +423,6 @@ var FontLoader = {
}
font.attached = true;
fontsToLoad.push(font);
var str = '';
var data = font.data;
if (data) {
@ -448,28 +433,51 @@ var FontLoader = {
var rule = font.bindDOM(str);
if (rule) {
rules.push(rule);
names.push(font.loadedName);
fontsToLoad.push(font);
}
}
}
this.listeningForFontLoad = false;
if (!isWorker && rules.length) {
FontLoader.prepareFontLoadEvent(rules, names, fontsToLoad);
}
if (!checkFontsLoaded()) {
document.documentElement.addEventListener(
'pdfjsFontLoad', checkFontsLoaded, false);
var request = FontLoader.queueLoadingCallback(callback);
if (rules.length > 0) {
FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
} else {
request.complete();
}
},
queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
function LoadLoader_completeRequest() {
assert(!request.end, 'completeRequest() cannot be called twice');
request.end = Date.now();
// sending all completed requests in order how they were queued
while (context.requests.length > 0 && context.requests[0].end) {
var otherRequest = context.requests.shift();
setTimeout(otherRequest.callback, 0);
}
}
var context = FontLoader.loadingContext;
var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
var request = {
id: requestId,
complete: LoadLoader_completeRequest,
callback: callback,
started: Date.now()
};
context.requests.push(request);
return request;
},
// Set things up so that at least one pdfjsFontLoad event is
// dispatched when all the @font-face |rules| for |names| have been
// dispatched when all the @font-face |rules| for |fonts| 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,
fonts) {
prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
fonts,
request) {
/** 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
@ -493,6 +501,20 @@ var FontLoader = {
// The postMessage() hackery was added to work around chrome bug
// 82402.
var requestId = request.id;
// Validate the requestId parameter -- the value used to construct HTML.
if (!/^[\w\-]+$/.test(requestId)) {
error('Invalid request id: ' + requestId);
// Normally the error-function throws. But if a malicious code
// intercepts the function call then the return is needed.
return;
}
var names = [];
for (var i = 0, ii = fonts.length; i < ii; i++)
names.push(fonts[i].loadedName);
// Validate the names parameter -- the values can used to construct HTML.
if (!/^\w+$/.test(names.join(''))) {
error('Invalid font name(s): ' + names.join());
@ -514,22 +536,21 @@ var FontLoader = {
div.innerHTML = html;
document.body.appendChild(div);
if (!this.listeningForFontLoad) {
window.addEventListener(
'message',
function fontLoaderMessage(e) {
var fontNames = JSON.parse(e.data);
for (var i = 0, ii = fonts.length; i < ii; ++i) {
var font = fonts[i];
font.loading = false;
}
var evt = document.createEvent('Events');
evt.initEvent('pdfjsFontLoad', true, false);
document.documentElement.dispatchEvent(evt);
},
false);
this.listeningForFontLoad = true;
}
window.addEventListener(
'message',
function fontLoaderMessage(e) {
if (e.data !== requestId)
return;
for (var i = 0, ii = fonts.length; i < ii; ++i) {
var font = fonts[i];
font.loading = false;
}
request.complete();
// cleanup
document.body.removeChild(frame);
window.removeEventListener('message', fontLoaderMessage, false);
},
false);
// XXX we should have a time-out here too, and maybe fire
// pdfjsFontLoadFailed?
@ -540,13 +561,8 @@ var FontLoader = {
}
src += '</style>';
src += '<script type="application/javascript">';
var fontNamesArray = '';
for (var i = 0, ii = names.length; i < ii; ++i) {
fontNamesArray += '"' + names[i] + '", ';
}
src += ' var fontNames=[' + fontNamesArray + '];\n';
src += ' window.onload = function fontLoaderOnload() {\n';
src += ' parent.postMessage(JSON.stringify(fontNames), "*");\n';
src += ' parent.postMessage("' + requestId + '", "*");\n';
src += ' }';
// Hack so the end script tag isn't counted if this is inline JS.
src += '</scr' + 'ipt></head><body>';
@ -1561,13 +1577,19 @@ var Font = (function FontClosure() {
return;
}
// Some fonts might use wrong font types for Type1C or CIDFontType0C
var subtype = properties.subtype;
if (subtype == 'Type1C' && (type != 'Type1' && type != 'MMType1'))
type = 'Type1';
if (subtype == 'CIDFontType0C' && type != 'CIDFontType0')
type = 'CIDFontType0';
var data;
switch (type) {
case 'Type1':
case 'CIDFontType0':
this.mimetype = 'font/opentype';
var subtype = properties.subtype;
var cff = (subtype == 'Type1C' || subtype == 'CIDFontType0C') ?
new CFFFont(file, properties) : new Type1Font(name, file, properties);
@ -2922,6 +2944,7 @@ var Font = (function FontClosure() {
}
this.toFontChar = toFontChar;
}
var unitsPerEm = properties.unitsPerEm || 1000; // defaulting to 1000
var fields = {
// PostScript Font Program
@ -2942,7 +2965,7 @@ var Font = (function FontClosure() {
'\x00\x00\x00\x00' + // checksumAdjustement
'\x5F\x0F\x3C\xF5' + // magicNumber
'\x00\x00' + // Flags
'\x03\xE8' + // unitsPerEM (defaulting to 1000)
safeString16(unitsPerEm) + // unitsPerEM
'\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
'\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
'\x00\x00' + // xMin
@ -3293,6 +3316,20 @@ var Font = (function FontClosure() {
return Font;
})();
var ErrorFont = (function ErrorFontClosure() {
function ErrorFont(error) {
this.error = error;
}
ErrorFont.prototype = {
charsToGlyphs: function ErrorFont_charsToGlyphs() {
return [];
}
};
return ErrorFont;
})();
var CallothersubrCmd = (function CallothersubrCmdClosure() {
function CallothersubrCmd(index) {
this.index = index;
@ -4397,6 +4434,19 @@ var CFFParser = (function CFFParserClosure() {
var charStringOffset = topDict.getByName('CharStrings');
cff.charStrings = this.parseCharStrings(charStringOffset);
var fontMatrix = topDict.getByName('FontMatrix');
if (fontMatrix) {
// estimating unitsPerEM for the font
properties.unitsPerEm = 1 / fontMatrix[0];
}
var fontBBox = topDict.getByName('FontBBox');
if (fontBBox) {
// adjusting ascent/descent
properties.ascent = fontBBox[3];
properties.descent = fontBBox[1];
}
var charset, encoding;
if (cff.isCIDFont) {
var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
@ -4470,7 +4520,7 @@ var CFFParser = (function CFFParserClosure() {
return parseFloatOperand(pos);
} else if (value === 28) {
value = dict[pos++];
value = (value << 8) | dict[pos++];
value = ((value << 24) | (dict[pos++] << 16)) >> 16;
return value;
} else if (value === 29) {
value = dict[pos++];

View File

@ -97,7 +97,12 @@ var PDFImage = (function PDFImageClosure() {
if (smask) {
this.smask = new PDFImage(xref, res, smask, false);
} else if (mask) {
this.mask = new PDFImage(xref, res, mask, false);
if (isStream(mask)) {
this.mask = new PDFImage(xref, res, mask, false);
} else {
// Color key mask (just an array).
this.mask = mask;
}
}
}
/**
@ -129,11 +134,15 @@ var PDFImage = (function PDFImageClosure() {
maskPromise.resolve(null);
} else {
smaskPromise.resolve(null);
if (mask && isStream(mask)) {
handleImageData(handler, xref, res, mask, maskPromise);
} else if (mask) {
TODO('handle color key masking');
maskPromise.resolve(null);
if (mask) {
if (isStream(mask)) {
handleImageData(handler, xref, res, mask, maskPromise);
} else if (isArray(mask)) {
maskPromise.resolve(mask);
} else {
warn('Unsupported mask format.');
maskPromise.resolve(null);
}
} else {
maskPromise.resolve(null);
}
@ -279,7 +288,7 @@ var PDFImage = (function PDFImageClosure() {
}
return output;
},
getOpacity: function PDFImage_getOpacity(width, height) {
getOpacity: function PDFImage_getOpacity(width, height, image) {
var smask = this.smask;
var mask = this.mask;
var originalWidth = this.width;
@ -294,18 +303,40 @@ var PDFImage = (function PDFImageClosure() {
if (sw != width || sh != height)
buf = PDFImage.resize(buf, smask.bpc, 1, sw, sh, width, height);
} else if (mask) {
var sw = mask.width;
var sh = mask.height;
buf = new Uint8Array(sw * sh);
mask.numComps = 1;
mask.fillGrayBuffer(buf);
if (mask instanceof PDFImage) {
var sw = mask.width;
var sh = mask.height;
buf = new Uint8Array(sw * sh);
mask.numComps = 1;
mask.fillGrayBuffer(buf);
// Need to invert values in buffer
for (var i = 0, ii = sw * sh; i < ii; ++i)
buf[i] = 255 - buf[i];
// Need to invert values in buffer
for (var i = 0, ii = sw * sh; i < ii; ++i)
buf[i] = 255 - buf[i];
if (sw != width || sh != height)
buf = PDFImage.resize(buf, mask.bpc, 1, sw, sh, width, height);
if (sw != width || sh != height)
buf = PDFImage.resize(buf, mask.bpc, 1, sw, sh, width, height);
} else if (isArray(mask)) {
// Color key mask: if any of the compontents are outside the range
// then they should be painted.
buf = new Uint8Array(width * height);
var numComps = this.numComps;
for (var i = 0, ii = width * height; i < ii; ++i) {
var opacity = 0;
var imageOffset = i * numComps;
for (var j = 0; j < numComps; ++j) {
var color = image[imageOffset + j];
var maskOffset = j * 2;
if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
opacity = 255;
break;
}
}
buf[i] = opacity;
}
} else {
error('Unknown mask format.');
}
} else {
buf = new Uint8Array(width * height);
for (var i = 0, ii = width * height; i < ii; ++i)
@ -357,7 +388,7 @@ var PDFImage = (function PDFImageClosure() {
comps = PDFImage.resize(comps, this.bpc, 3, originalWidth,
originalHeight, width, height);
var compsPos = 0;
var opacity = this.getOpacity(width, height);
var opacity = this.getOpacity(width, height, imgArray);
var opacityPos = 0;
var length = width * actualHeight * 4;

BIN
test/pdfs/colorkeymask.pdf Normal file

Binary file not shown.

View File

@ -1 +1 @@
http://www.freepatentsonline.com/pdf/documents/uspt/D661/USD661296/USD661296S1.pdf
http://assets.sbnation.com/assets/1167519/USD661296S1.pdf

View File

@ -673,5 +673,11 @@
"md5": "2ac7c68e26a8ef797aead15e4875cc6d",
"rounds": 1,
"type": "load"
},
{ "id": "colorkeymask",
"file": "pdfs/colorkeymask.pdf",
"md5": "9f11e815b485f7f0e1fa5c116c636cf9",
"rounds": 1,
"type": "eq"
}
]

View File

@ -42,7 +42,7 @@ describe('font', function() {
}
describe('CFFParser', function() {
var parser = new CFFParser(fontData);
var parser = new CFFParser(fontData, {});
var cff = parser.parse();
it('parses header', function() {

View File

@ -29,29 +29,17 @@ select {
#viewerContainer:-webkit-full-screen {
top: 0px;
padding-top: 6px;
padding-bottom: 24px;
border-top: 5px solid transparent;
background-color: #404040;
background-image: url(images/texture.png);
width: 100%;
height: 100%;
overflow: auto;
}
:-webkit-full-screen #viewer {
margin: 0pt;
padding: 0pt;
height: 100%;
width: 100%;
overflow: hidden;
}
:-webkit-full-screen .page {
margin: 0px auto;
margin-bottom: 10px;
}
#viewerContainer:-moz-full-screen {
top: 0px;
border-top: 5px solid transparent;
background-color: #404040;
background-image: url(images/texture.png);
width: 100%;
@ -59,6 +47,10 @@ select {
overflow: hidden;
}
:-webkit-full-screen .page:last-child {
margin-bottom: 40px;
}
:-moz-full-screen .page:last-child {
margin-bottom: 40px;
}

View File

@ -33,6 +33,19 @@ function getFileName(url) {
return url.substring(url.lastIndexOf('/', end) + 1, end);
}
function scrollIntoView(element, spot) {
var parent = element.offsetParent, offsetY = element.offsetTop;
while (parent.clientHeight == parent.scrollHeight) {
offsetY += parent.offsetTop;
parent = parent.offsetParent;
if (!parent)
return; // no need to scroll
}
if (spot)
offsetY += spot.top;
parent.scrollTop = offsetY;
}
var Cache = function cacheCache(size) {
var data = [];
this.push = function cachePush(view) {
@ -385,7 +398,13 @@ var PDFView = {
setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
this.url = url;
document.title = decodeURIComponent(getFileName(url)) || url;
try {
document.title = decodeURIComponent(getFileName(url)) || url;
} catch (e) {
// decodeURIComponent may throw URIError,
// fall back to using the unprocessed url in that case
document.title = url;
}
},
open: function pdfViewOpen(url, scale, password) {
@ -1309,7 +1328,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
this.scrollIntoView = function pageViewScrollIntoView(dest) {
if (!dest) {
div.scrollIntoView(true);
scrollIntoView(div);
return;
}
@ -1368,16 +1387,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
var width = Math.abs(boundingRect[0][0] - boundingRect[1][0]);
var height = Math.abs(boundingRect[0][1] - boundingRect[1][1]);
// using temporary div to scroll it into view
var tempDiv = document.createElement('div');
tempDiv.style.position = 'absolute';
tempDiv.style.left = Math.floor(x) + 'px';
tempDiv.style.top = Math.floor(y) + 'px';
tempDiv.style.width = Math.ceil(width) + 'px';
tempDiv.style.height = Math.ceil(height) + 'px';
div.appendChild(tempDiv);
tempDiv.scrollIntoView(true);
div.removeChild(tempDiv);
scrollIntoView(div, {left: x, top: y, width: width, height: height});
}, 0);
};
@ -2078,7 +2088,7 @@ window.addEventListener('pagechange', function pagechange(evt) {
var last = numVisibleThumbs > 1 ?
visibleThumbs.last.id : first;
if (page <= first || page >= last)
thumbnail.scrollIntoView();
scrollIntoView(thumbnail);
}
}