mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Removes global PDFJS usage from the src/core/.
This commit is contained in:
parent
21ed8ff71d
commit
bda5e6235e
22 changed files with 376 additions and 299 deletions
|
@ -12,7 +12,6 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals PDFJS */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -108,8 +107,15 @@ var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
|
|||
var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
|
||||
|
||||
var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
var DefaultPartialEvaluatorOptions = {
|
||||
forceDataSchema: false,
|
||||
maxImageSize: -1,
|
||||
disableFontFace: false,
|
||||
cMapOptions: { url: null, packed: false }
|
||||
};
|
||||
|
||||
function PartialEvaluator(pdfManager, xref, handler, pageIndex,
|
||||
uniquePrefix, idCounters, fontCache) {
|
||||
uniquePrefix, idCounters, fontCache, options) {
|
||||
this.pdfManager = pdfManager;
|
||||
this.xref = xref;
|
||||
this.handler = handler;
|
||||
|
@ -117,6 +123,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
this.uniquePrefix = uniquePrefix;
|
||||
this.idCounters = idCounters;
|
||||
this.fontCache = fontCache;
|
||||
this.options = options || DefaultPartialEvaluatorOptions;
|
||||
}
|
||||
|
||||
// Trying to minimize Date.now() usage and check every 100 time
|
||||
|
@ -275,7 +282,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
warn('Image dimensions are missing, or not numbers.');
|
||||
return;
|
||||
}
|
||||
if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
|
||||
var maxImageSize = this.options.maxImageSize;
|
||||
if (maxImageSize !== -1 && w * h > maxImageSize) {
|
||||
warn('Image exceeded maximum allowed size and was removed.');
|
||||
return;
|
||||
}
|
||||
|
@ -339,11 +347,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
// These JPEGs don't need any more processing so we can just send it.
|
||||
operatorList.addOp(OPS.paintJpegXObject, args);
|
||||
this.handler.send('obj',
|
||||
[objId, this.pageIndex, 'JpegStream', image.getIR()]);
|
||||
[objId, this.pageIndex, 'JpegStream',
|
||||
image.getIR(this.options.forceDataSchema)]);
|
||||
return;
|
||||
}
|
||||
|
||||
PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
|
||||
PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
|
||||
this.options.forceDataSchema).
|
||||
then(function(imageObj) {
|
||||
var imgData = imageObj.createImageData(/* forceRGBA = */ false);
|
||||
self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
|
||||
|
@ -451,7 +461,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
var glyphs = font.charsToGlyphs(chars);
|
||||
var isAddToPathSet = !!(state.textRenderingMode &
|
||||
TextRenderingMode.ADD_TO_PATH_FLAG);
|
||||
if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
|
||||
if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
|
||||
var buildPath = function (fontChar) {
|
||||
if (!font.renderer.hasBuiltPath(fontChar)) {
|
||||
var path = font.renderer.getPathJs(fontChar);
|
||||
|
@ -1174,7 +1184,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
|
||||
function runBidiTransform(textChunk) {
|
||||
var str = textChunk.str.join('');
|
||||
var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
|
||||
var bidiResult = bidi(str, -1, textChunk.vertical);
|
||||
return {
|
||||
str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
|
||||
bidiResult.str),
|
||||
|
@ -1757,8 +1767,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
|
||||
// d) Obtain the CMap with the name constructed in step (c) (available
|
||||
// from the ASN Web site; see the Bibliography).
|
||||
return CMapFactory.create(ucs2CMapName,
|
||||
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
|
||||
return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
|
||||
null).then(
|
||||
function (ucs2CMap) {
|
||||
var cMap = properties.cMap;
|
||||
toUnicode = [];
|
||||
|
@ -1785,8 +1795,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
|
||||
var cmapObj = toUnicode;
|
||||
if (isName(cmapObj)) {
|
||||
return CMapFactory.create(cmapObj,
|
||||
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
|
||||
return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
|
||||
function (cmap) {
|
||||
if (cmap instanceof IdentityCMap) {
|
||||
return new IdentityToUnicodeMap(0, 0xFFFF);
|
||||
|
@ -1794,8 +1803,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
return new ToUnicodeMap(cmap.getMap());
|
||||
});
|
||||
} else if (isStream(cmapObj)) {
|
||||
return CMapFactory.create(cmapObj,
|
||||
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
|
||||
return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
|
||||
function (cmap) {
|
||||
if (cmap instanceof IdentityCMap) {
|
||||
return new IdentityToUnicodeMap(0, 0xFFFF);
|
||||
|
@ -2086,6 +2094,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
var descriptor = preEvaluatedFont.descriptor;
|
||||
var type = preEvaluatedFont.type;
|
||||
var maxCharIndex = (composite ? 0xFFFF : 0xFF);
|
||||
var cMapOptions = this.options.cMapOptions;
|
||||
var properties;
|
||||
|
||||
if (!descriptor) {
|
||||
|
@ -2213,8 +2222,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
if (isName(cidEncoding)) {
|
||||
properties.cidEncoding = cidEncoding.name;
|
||||
}
|
||||
cMapPromise = CMapFactory.create(cidEncoding,
|
||||
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
|
||||
cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
|
||||
function (cMap) {
|
||||
properties.cMap = cMap;
|
||||
properties.vertical = properties.cMap.vertical;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue