|
@@ -24,6 +24,7 @@ var _api = require('../../display/api');
|
|
|
|
|
|
var _svg = require('../../display/svg');
|
|
|
|
|
|
+var XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
|
function withZlib(isZlibRequired, callback) {
|
|
|
if (isZlibRequired) {
|
|
|
if (!(0, _util.isNodeJS)()) {
|
|
@@ -36,14 +37,18 @@ function withZlib(isZlibRequired, callback) {
|
|
|
}
|
|
|
var zlib = require('zlib');
|
|
|
var deflateSync = zlib.deflateSync;
|
|
|
- zlib.deflateSync = function () {
|
|
|
+ zlib.deflateSync = disabledDeflateSync;
|
|
|
+ function disabledDeflateSync() {
|
|
|
throw new Error('zlib.deflateSync is explicitly disabled for testing.');
|
|
|
- };
|
|
|
- try {
|
|
|
- return callback();
|
|
|
- } finally {
|
|
|
- zlib.deflateSync = deflateSync;
|
|
|
}
|
|
|
+ function restoreDeflateSync() {
|
|
|
+ if (zlib.deflateSync === disabledDeflateSync) {
|
|
|
+ zlib.deflateSync = deflateSync;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var promise = callback();
|
|
|
+ promise.then(restoreDeflateSync, restoreDeflateSync);
|
|
|
+ return promise;
|
|
|
}
|
|
|
describe('SVGGraphics', function () {
|
|
|
var loadingTask;
|
|
@@ -74,15 +79,13 @@ describe('SVGGraphics', function () {
|
|
|
svgImg = element;
|
|
|
}
|
|
|
};
|
|
|
- var xobjectObjId = {
|
|
|
- ref: 4,
|
|
|
- gen: 0
|
|
|
- };
|
|
|
+ var xobjectObjId = 'img_p0_1';
|
|
|
if ((0, _util.isNodeJS)()) {
|
|
|
(0, _domstubs.setStubs)(global);
|
|
|
}
|
|
|
try {
|
|
|
- svgGfx.paintImageXObject(xobjectObjId, elementContainer);
|
|
|
+ var imgData = svgGfx.objs.get(xobjectObjId);
|
|
|
+ svgGfx.paintInlineImageXObject(imgData, elementContainer);
|
|
|
} finally {
|
|
|
if ((0, _util.isNodeJS)()) {
|
|
|
(0, _domstubs.unsetStubs)(global);
|
|
@@ -91,28 +94,28 @@ describe('SVGGraphics', function () {
|
|
|
return svgImg;
|
|
|
});
|
|
|
}
|
|
|
- it('should produce a reasonably small svg:image', function () {
|
|
|
+ it('should produce a reasonably small svg:image', function (done) {
|
|
|
if (!(0, _util.isNodeJS)()) {
|
|
|
pending('zlib.deflateSync is not supported in non-Node environments.');
|
|
|
}
|
|
|
withZlib(true, getSVGImage).then(function (svgImg) {
|
|
|
expect(svgImg.nodeName).toBe('svg:image');
|
|
|
- expect(svgImg.getAttribute('width')).toBe('200px');
|
|
|
- expect(svgImg.getAttribute('height')).toBe('100px');
|
|
|
- var imgUrl = svgImg.getAttribute('xlink:href');
|
|
|
+ expect(svgImg.getAttributeNS(null, 'width')).toBe('200px');
|
|
|
+ expect(svgImg.getAttributeNS(null, 'height')).toBe('100px');
|
|
|
+ var imgUrl = svgImg.getAttributeNS(XLINK_NS, 'href');
|
|
|
expect(imgUrl).toMatch(/^data:image\/png;base64,/);
|
|
|
expect(imgUrl.length).toBeLessThan(367);
|
|
|
- });
|
|
|
+ }).then(done, done.fail);
|
|
|
});
|
|
|
- it('should produce a svg:image even if zlib is unavailable', function () {
|
|
|
+ it('should be able to produce a svg:image without zlib', function (done) {
|
|
|
withZlib(false, getSVGImage).then(function (svgImg) {
|
|
|
expect(svgImg.nodeName).toBe('svg:image');
|
|
|
- expect(svgImg.getAttribute('width')).toBe('200px');
|
|
|
- expect(svgImg.getAttribute('height')).toBe('100px');
|
|
|
- var imgUrl = svgImg.getAttribute('xlink:href');
|
|
|
+ expect(svgImg.getAttributeNS(null, 'width')).toBe('200px');
|
|
|
+ expect(svgImg.getAttributeNS(null, 'height')).toBe('100px');
|
|
|
+ var imgUrl = svgImg.getAttributeNS(XLINK_NS, 'href');
|
|
|
expect(imgUrl).toMatch(/^data:image\/png;base64,/);
|
|
|
- expect(imgUrl.length).toBe(80247);
|
|
|
- });
|
|
|
+ expect(imgUrl.length).toBe(80246);
|
|
|
+ }).then(done, done.fail);
|
|
|
});
|
|
|
});
|
|
|
});
|