all files / pdfviewer/pdf-base/ image-structure.js

19.4% Statements 13/67
0% Branches 0/52
20% Functions 2/10
19.4% Lines 13/67
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100                                                                                                                                                                              
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-pdf"], function (require, exports, ej2_base_1, ej2_pdf_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ImageStructureBase = (function () {
        function ImageStructureBase(stream, fontDictionary) {
            this.mIsImageStreamParsed = false;
            this.mIsImageInterpolated = false;
            this.isDualFilter = false;
            this.numberOfComponents = 0;
            if (!ej2_base_1.isNullOrUndefined(fontDictionary)) {
                this.mImageStream = stream;
                this.mImageDictionary = fontDictionary;
            }
        }
        ImageStructureBase.prototype.getImageStream = function () {
            this.mIsImageStreamParsed = true;
            var IsDecodeFilterDefined = true;
            var ImageDictionary = this.mImageDictionary;
            this.getImageInterpolation(ImageDictionary);
            var imageFilter = this.setImageFilter();
            var imageUnit8Array = this.imageStream();
            if (ej2_base_1.isNullOrUndefined(imageFilter)) {
                this.mImageFilter.push('FlateDecode');
                IsDecodeFilterDefined = false;
            }
            if (!ej2_base_1.isNullOrUndefined(imageFilter)) {
                for (var i = 0; i < imageFilter.length; i++) {
                    if (imageFilter.length > 1) {
                        this.isDualFilter = true;
                    }
                    switch (imageFilter[parseInt(i.toString(), 10)]) {
                        case 'DCTDecode': {
                            if (!this.mImageDictionary.has('SMask') && !this.mImageDictionary.has('Mask')) {
                                var colorSpace = this.setColorSpace();
                                if (colorSpace.name === 'DeviceCMYK' || colorSpace.name === 'DeviceN' || colorSpace.name === 'DeviceGray' || colorSpace.name === 'Separation' || colorSpace.name === 'DeviceRGB' || (colorSpace.name === 'ICCBased' && this.numberOfComponents === 4)) {
                                    if (colorSpace.name === 'DeviceRGB' && (this.mImageDictionary.has('DecodeParms') || this.mImageDictionary.has('Decode'))) {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                this.mImageFilter = null;
                return imageUnit8Array;
            }
            return null;
        };
        ImageStructureBase.prototype.setColorSpace = function () {
            if (ej2_base_1.isNullOrUndefined(this.mColorspace)) {
                this.getColorSpace();
                return this.mColorspace;
            }
        };
        ImageStructureBase.prototype.getColorSpace = function () {
            if (this.mImageDictionary.has('ColorSpace')) {
                this.internalColorSpace = '';
                var value = null;
                if (this.mImageDictionary.has('ColorSpace')) {
                    var array = this.mImageDictionary.getArray('ColorSpace');
                    if (array && Array.isArray(array) && array.length > 0) {
                        value = this.mImageDictionary.get('ColorSpace');
                    }
                }
                if (this.mImageDictionary.get('ColorSpace') instanceof ej2_pdf_1._PdfName) {
                    this.mColorspace = this.mImageDictionary.get('ColorSpace');
                }
            }
        };
        ImageStructureBase.prototype.setImageFilter = function () {
            if (ej2_base_1.isNullOrUndefined(this.mImageFilter)) {
                this.mImageFilter = this.getImageFilter();
            }
            return this.mImageFilter;
        };
        ImageStructureBase.prototype.getImageFilter = function () {
            var imageFilter = [];
            if (!ej2_base_1.isNullOrUndefined(this.mImageDictionary)) {
                if (this.mImageDictionary.has('Filter')) {
                    if (this.mImageDictionary.get('Filter') instanceof ej2_pdf_1._PdfName) {
                        imageFilter.push(this.mImageDictionary.get('Filter').name);
                    }
                }
            }
            return imageFilter;
        };
        ImageStructureBase.prototype.getImageInterpolation = function (imageDictionary) {
            if (!ej2_base_1.isNullOrUndefined(imageDictionary) && imageDictionary.has('Interpolate')) {
                this.mIsImageInterpolated = imageDictionary.get('Interpolate');
            }
        };
        ImageStructureBase.prototype.imageStream = function () {
            var content = ej2_pdf_1._stringToBytes(this.mImageStream.getString(), false, true);
            return content;
        };
        return ImageStructureBase;
    }());
    exports.ImageStructureBase = ImageStructureBase;
});