|
|
@ -404,28 +404,15 @@ function mapPrivateUseChars(code) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var FontLoader = { |
|
|
|
var FontLoader = { |
|
|
|
listeningForFontLoad: false, |
|
|
|
loadingContext: { |
|
|
|
|
|
|
|
requests: [], |
|
|
|
|
|
|
|
nextRequestId: 0 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
bind: function fontLoaderBind(fonts, callback) { |
|
|
|
bind: function fontLoaderBind(fonts, callback) { |
|
|
|
function checkFontsLoaded() { |
|
|
|
assert(!isWorker, 'bind() shall be called from main thread'); |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rules = [], fontsToLoad = []; |
|
|
|
for (var i = 0, ii = fonts.length; i < ii; i++) { |
|
|
|
for (var i = 0, ii = fonts.length; i < ii; i++) { |
|
|
|
var font = fonts[i]; |
|
|
|
var font = fonts[i]; |
|
|
|
|
|
|
|
|
|
|
@ -436,8 +423,6 @@ var FontLoader = { |
|
|
|
} |
|
|
|
} |
|
|
|
font.attached = true; |
|
|
|
font.attached = true; |
|
|
|
|
|
|
|
|
|
|
|
fontsToLoad.push(font); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var str = ''; |
|
|
|
var str = ''; |
|
|
|
var data = font.data; |
|
|
|
var data = font.data; |
|
|
|
if (data) { |
|
|
|
if (data) { |
|
|
@ -448,28 +433,51 @@ var FontLoader = { |
|
|
|
var rule = font.bindDOM(str); |
|
|
|
var rule = font.bindDOM(str); |
|
|
|
if (rule) { |
|
|
|
if (rule) { |
|
|
|
rules.push(rule); |
|
|
|
rules.push(rule); |
|
|
|
names.push(font.loadedName); |
|
|
|
fontsToLoad.push(font); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.listeningForFontLoad = false; |
|
|
|
var request = FontLoader.queueLoadingCallback(callback); |
|
|
|
if (!isWorker && rules.length) { |
|
|
|
if (rules.length > 0) { |
|
|
|
FontLoader.prepareFontLoadEvent(rules, names, fontsToLoad); |
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
|
|
if (!checkFontsLoaded()) { |
|
|
|
// sending all completed requests in order how they were queued
|
|
|
|
document.documentElement.addEventListener( |
|
|
|
while (context.requests.length > 0 && context.requests[0].end) { |
|
|
|
'pdfjsFontLoad', checkFontsLoaded, false); |
|
|
|
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
|
|
|
|
// 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|
|
|
|
|
// loaded in a subdocument. It's expected that the load of |rules|
|
|
|
|
// has already started in this (outer) document, so that they should
|
|
|
|
// has already started in this (outer) document, so that they should
|
|
|
|
// be ordered before the load in the subdocument.
|
|
|
|
// be ordered before the load in the subdocument.
|
|
|
|
prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules, names, |
|
|
|
prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules, |
|
|
|
fonts) { |
|
|
|
fonts, |
|
|
|
|
|
|
|
request) { |
|
|
|
/** Hack begin */ |
|
|
|
/** Hack begin */ |
|
|
|
// There's no event when a font has finished downloading so the
|
|
|
|
// There's no event when a font has finished downloading so the
|
|
|
|
// following code is a dirty hack to 'guess' when a font is
|
|
|
|
// 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
|
|
|
|
// The postMessage() hackery was added to work around chrome bug
|
|
|
|
// 82402.
|
|
|
|
// 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.
|
|
|
|
// Validate the names parameter -- the values can used to construct HTML.
|
|
|
|
if (!/^\w+$/.test(names.join(''))) { |
|
|
|
if (!/^\w+$/.test(names.join(''))) { |
|
|
|
error('Invalid font name(s): ' + names.join()); |
|
|
|
error('Invalid font name(s): ' + names.join()); |
|
|
@ -514,22 +536,21 @@ var FontLoader = { |
|
|
|
div.innerHTML = html; |
|
|
|
div.innerHTML = html; |
|
|
|
document.body.appendChild(div); |
|
|
|
document.body.appendChild(div); |
|
|
|
|
|
|
|
|
|
|
|
if (!this.listeningForFontLoad) { |
|
|
|
window.addEventListener( |
|
|
|
window.addEventListener( |
|
|
|
'message', |
|
|
|
'message', |
|
|
|
function fontLoaderMessage(e) { |
|
|
|
function fontLoaderMessage(e) { |
|
|
|
if (e.data !== requestId) |
|
|
|
var fontNames = JSON.parse(e.data); |
|
|
|
return; |
|
|
|
for (var i = 0, ii = fonts.length; i < ii; ++i) { |
|
|
|
for (var i = 0, ii = fonts.length; i < ii; ++i) { |
|
|
|
var font = fonts[i]; |
|
|
|
var font = fonts[i]; |
|
|
|
font.loading = false; |
|
|
|
font.loading = false; |
|
|
|
} |
|
|
|
} |
|
|
|
var evt = document.createEvent('Events'); |
|
|
|
request.complete(); |
|
|
|
evt.initEvent('pdfjsFontLoad', true, false); |
|
|
|
// cleanup
|
|
|
|
document.documentElement.dispatchEvent(evt); |
|
|
|
document.body.removeChild(frame); |
|
|
|
}, |
|
|
|
window.removeEventListener('message', fontLoaderMessage, false); |
|
|
|
false); |
|
|
|
}, |
|
|
|
this.listeningForFontLoad = true; |
|
|
|
false); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// XXX we should have a time-out here too, and maybe fire
|
|
|
|
// XXX we should have a time-out here too, and maybe fire
|
|
|
|
// pdfjsFontLoadFailed?
|
|
|
|
// pdfjsFontLoadFailed?
|
|
|
@ -540,13 +561,8 @@ var FontLoader = { |
|
|
|
} |
|
|
|
} |
|
|
|
src += '</style>'; |
|
|
|
src += '</style>'; |
|
|
|
src += '<script type="application/javascript">'; |
|
|
|
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 += ' window.onload = function fontLoaderOnload() {\n'; |
|
|
|
src += ' parent.postMessage(JSON.stringify(fontNames), "*");\n'; |
|
|
|
src += ' parent.postMessage("' + requestId + '", "*");\n'; |
|
|
|
src += ' }'; |
|
|
|
src += ' }'; |
|
|
|
// Hack so the end script tag isn't counted if this is inline JS.
|
|
|
|
// Hack so the end script tag isn't counted if this is inline JS.
|
|
|
|
src += '</scr' + 'ipt></head><body>'; |
|
|
|
src += '</scr' + 'ipt></head><body>'; |
|
|
@ -1561,13 +1577,19 @@ var Font = (function FontClosure() { |
|
|
|
return; |
|
|
|
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; |
|
|
|
var data; |
|
|
|
switch (type) { |
|
|
|
switch (type) { |
|
|
|
case 'Type1': |
|
|
|
case 'Type1': |
|
|
|
case 'CIDFontType0': |
|
|
|
case 'CIDFontType0': |
|
|
|
this.mimetype = 'font/opentype'; |
|
|
|
this.mimetype = 'font/opentype'; |
|
|
|
|
|
|
|
|
|
|
|
var subtype = properties.subtype; |
|
|
|
|
|
|
|
var cff = (subtype == 'Type1C' || subtype == 'CIDFontType0C') ? |
|
|
|
var cff = (subtype == 'Type1C' || subtype == 'CIDFontType0C') ? |
|
|
|
new CFFFont(file, properties) : new Type1Font(name, file, properties); |
|
|
|
new CFFFont(file, properties) : new Type1Font(name, file, properties); |
|
|
|
|
|
|
|
|
|
|
@ -2922,6 +2944,7 @@ var Font = (function FontClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
this.toFontChar = toFontChar; |
|
|
|
this.toFontChar = toFontChar; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var unitsPerEm = properties.unitsPerEm || 1000; // defaulting to 1000
|
|
|
|
|
|
|
|
|
|
|
|
var fields = { |
|
|
|
var fields = { |
|
|
|
// PostScript Font Program
|
|
|
|
// PostScript Font Program
|
|
|
@ -2942,7 +2965,7 @@ var Font = (function FontClosure() { |
|
|
|
'\x00\x00\x00\x00' + // checksumAdjustement
|
|
|
|
'\x00\x00\x00\x00' + // checksumAdjustement
|
|
|
|
'\x5F\x0F\x3C\xF5' + // magicNumber
|
|
|
|
'\x5F\x0F\x3C\xF5' + // magicNumber
|
|
|
|
'\x00\x00' + // Flags
|
|
|
|
'\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' + // creation date
|
|
|
|
'\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
|
|
|
|
'\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
|
|
|
|
'\x00\x00' + // xMin
|
|
|
|
'\x00\x00' + // xMin
|
|
|
@ -3293,6 +3316,20 @@ var Font = (function FontClosure() { |
|
|
|
return Font; |
|
|
|
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() { |
|
|
|
var CallothersubrCmd = (function CallothersubrCmdClosure() { |
|
|
|
function CallothersubrCmd(index) { |
|
|
|
function CallothersubrCmd(index) { |
|
|
|
this.index = index; |
|
|
|
this.index = index; |
|
|
@ -4397,6 +4434,19 @@ var CFFParser = (function CFFParserClosure() { |
|
|
|
var charStringOffset = topDict.getByName('CharStrings'); |
|
|
|
var charStringOffset = topDict.getByName('CharStrings'); |
|
|
|
cff.charStrings = this.parseCharStrings(charStringOffset); |
|
|
|
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; |
|
|
|
var charset, encoding; |
|
|
|
if (cff.isCIDFont) { |
|
|
|
if (cff.isCIDFont) { |
|
|
|
var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj; |
|
|
|
var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj; |
|
|
@ -4470,7 +4520,7 @@ var CFFParser = (function CFFParserClosure() { |
|
|
|
return parseFloatOperand(pos); |
|
|
|
return parseFloatOperand(pos); |
|
|
|
} else if (value === 28) { |
|
|
|
} else if (value === 28) { |
|
|
|
value = dict[pos++]; |
|
|
|
value = dict[pos++]; |
|
|
|
value = (value << 8) | dict[pos++]; |
|
|
|
value = ((value << 24) | (dict[pos++] << 16)) >> 16; |
|
|
|
return value; |
|
|
|
return value; |
|
|
|
} else if (value === 29) { |
|
|
|
} else if (value === 29) { |
|
|
|
value = dict[pos++]; |
|
|
|
value = dict[pos++]; |
|
|
|