svg.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2018 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.SVGGraphics = void 0;
  27. var _util = require("../shared/util");
  28. var _dom_utils = require("./dom_utils");
  29. var _is_node = _interopRequireDefault(require("../shared/is_node"));
  30. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  31. var SVGGraphics = function SVGGraphics() {
  32. throw new Error('Not implemented: SVGGraphics');
  33. };
  34. exports.SVGGraphics = SVGGraphics;
  35. {
  36. var SVG_DEFAULTS = {
  37. fontStyle: 'normal',
  38. fontWeight: 'normal',
  39. fillColor: '#000000'
  40. };
  41. var convertImgDataToPng = function convertImgDataToPngClosure() {
  42. var PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  43. var CHUNK_WRAPPER_SIZE = 12;
  44. var crcTable = new Int32Array(256);
  45. for (var i = 0; i < 256; i++) {
  46. var c = i;
  47. for (var h = 0; h < 8; h++) {
  48. if (c & 1) {
  49. c = 0xedB88320 ^ c >> 1 & 0x7fffffff;
  50. } else {
  51. c = c >> 1 & 0x7fffffff;
  52. }
  53. }
  54. crcTable[i] = c;
  55. }
  56. function crc32(data, start, end) {
  57. var crc = -1;
  58. for (var i = start; i < end; i++) {
  59. var a = (crc ^ data[i]) & 0xff;
  60. var b = crcTable[a];
  61. crc = crc >>> 8 ^ b;
  62. }
  63. return crc ^ -1;
  64. }
  65. function writePngChunk(type, body, data, offset) {
  66. var p = offset;
  67. var len = body.length;
  68. data[p] = len >> 24 & 0xff;
  69. data[p + 1] = len >> 16 & 0xff;
  70. data[p + 2] = len >> 8 & 0xff;
  71. data[p + 3] = len & 0xff;
  72. p += 4;
  73. data[p] = type.charCodeAt(0) & 0xff;
  74. data[p + 1] = type.charCodeAt(1) & 0xff;
  75. data[p + 2] = type.charCodeAt(2) & 0xff;
  76. data[p + 3] = type.charCodeAt(3) & 0xff;
  77. p += 4;
  78. data.set(body, p);
  79. p += body.length;
  80. var crc = crc32(data, offset + 4, p);
  81. data[p] = crc >> 24 & 0xff;
  82. data[p + 1] = crc >> 16 & 0xff;
  83. data[p + 2] = crc >> 8 & 0xff;
  84. data[p + 3] = crc & 0xff;
  85. }
  86. function adler32(data, start, end) {
  87. var a = 1;
  88. var b = 0;
  89. for (var i = start; i < end; ++i) {
  90. a = (a + (data[i] & 0xff)) % 65521;
  91. b = (b + a) % 65521;
  92. }
  93. return b << 16 | a;
  94. }
  95. function deflateSync(literals) {
  96. if (!(0, _is_node.default)()) {
  97. return deflateSyncUncompressed(literals);
  98. }
  99. try {
  100. var input;
  101. if (parseInt(process.versions.node) >= 8) {
  102. input = literals;
  103. } else {
  104. input = new Buffer(literals);
  105. }
  106. var output = require('zlib').deflateSync(input, {
  107. level: 9
  108. });
  109. return output instanceof Uint8Array ? output : new Uint8Array(output);
  110. } catch (e) {
  111. (0, _util.warn)('Not compressing PNG because zlib.deflateSync is unavailable: ' + e);
  112. }
  113. return deflateSyncUncompressed(literals);
  114. }
  115. function deflateSyncUncompressed(literals) {
  116. var len = literals.length;
  117. var maxBlockLength = 0xFFFF;
  118. var deflateBlocks = Math.ceil(len / maxBlockLength);
  119. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  120. var pi = 0;
  121. idat[pi++] = 0x78;
  122. idat[pi++] = 0x9c;
  123. var pos = 0;
  124. while (len > maxBlockLength) {
  125. idat[pi++] = 0x00;
  126. idat[pi++] = 0xff;
  127. idat[pi++] = 0xff;
  128. idat[pi++] = 0x00;
  129. idat[pi++] = 0x00;
  130. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  131. pi += maxBlockLength;
  132. pos += maxBlockLength;
  133. len -= maxBlockLength;
  134. }
  135. idat[pi++] = 0x01;
  136. idat[pi++] = len & 0xff;
  137. idat[pi++] = len >> 8 & 0xff;
  138. idat[pi++] = ~len & 0xffff & 0xff;
  139. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  140. idat.set(literals.subarray(pos), pi);
  141. pi += literals.length - pos;
  142. var adler = adler32(literals, 0, literals.length);
  143. idat[pi++] = adler >> 24 & 0xff;
  144. idat[pi++] = adler >> 16 & 0xff;
  145. idat[pi++] = adler >> 8 & 0xff;
  146. idat[pi++] = adler & 0xff;
  147. return idat;
  148. }
  149. function encode(imgData, kind, forceDataSchema, isMask) {
  150. var width = imgData.width;
  151. var height = imgData.height;
  152. var bitDepth, colorType, lineSize;
  153. var bytes = imgData.data;
  154. switch (kind) {
  155. case _util.ImageKind.GRAYSCALE_1BPP:
  156. colorType = 0;
  157. bitDepth = 1;
  158. lineSize = width + 7 >> 3;
  159. break;
  160. case _util.ImageKind.RGB_24BPP:
  161. colorType = 2;
  162. bitDepth = 8;
  163. lineSize = width * 3;
  164. break;
  165. case _util.ImageKind.RGBA_32BPP:
  166. colorType = 6;
  167. bitDepth = 8;
  168. lineSize = width * 4;
  169. break;
  170. default:
  171. throw new Error('invalid format');
  172. }
  173. var literals = new Uint8Array((1 + lineSize) * height);
  174. var offsetLiterals = 0,
  175. offsetBytes = 0;
  176. var y, i;
  177. for (y = 0; y < height; ++y) {
  178. literals[offsetLiterals++] = 0;
  179. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  180. offsetBytes += lineSize;
  181. offsetLiterals += lineSize;
  182. }
  183. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  184. offsetLiterals = 0;
  185. for (y = 0; y < height; y++) {
  186. offsetLiterals++;
  187. for (i = 0; i < lineSize; i++) {
  188. literals[offsetLiterals++] ^= 0xFF;
  189. }
  190. }
  191. }
  192. var ihdr = new Uint8Array([width >> 24 & 0xff, width >> 16 & 0xff, width >> 8 & 0xff, width & 0xff, height >> 24 & 0xff, height >> 16 & 0xff, height >> 8 & 0xff, height & 0xff, bitDepth, colorType, 0x00, 0x00, 0x00]);
  193. var idat = deflateSync(literals);
  194. var pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  195. var data = new Uint8Array(pngLength);
  196. var offset = 0;
  197. data.set(PNG_HEADER, offset);
  198. offset += PNG_HEADER.length;
  199. writePngChunk('IHDR', ihdr, data, offset);
  200. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  201. writePngChunk('IDATA', idat, data, offset);
  202. offset += CHUNK_WRAPPER_SIZE + idat.length;
  203. writePngChunk('IEND', new Uint8Array(0), data, offset);
  204. return (0, _util.createObjectURL)(data, 'image/png', forceDataSchema);
  205. }
  206. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  207. var kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  208. return encode(imgData, kind, forceDataSchema, isMask);
  209. };
  210. }();
  211. var SVGExtraState = function SVGExtraStateClosure() {
  212. function SVGExtraState() {
  213. this.fontSizeScale = 1;
  214. this.fontWeight = SVG_DEFAULTS.fontWeight;
  215. this.fontSize = 0;
  216. this.textMatrix = _util.IDENTITY_MATRIX;
  217. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  218. this.leading = 0;
  219. this.textRenderingMode = _util.TextRenderingMode.FILL;
  220. this.x = 0;
  221. this.y = 0;
  222. this.lineX = 0;
  223. this.lineY = 0;
  224. this.charSpacing = 0;
  225. this.wordSpacing = 0;
  226. this.textHScale = 1;
  227. this.textRise = 0;
  228. this.fillColor = SVG_DEFAULTS.fillColor;
  229. this.strokeColor = '#000000';
  230. this.fillAlpha = 1;
  231. this.strokeAlpha = 1;
  232. this.lineWidth = 1;
  233. this.lineJoin = '';
  234. this.lineCap = '';
  235. this.miterLimit = 0;
  236. this.dashArray = [];
  237. this.dashPhase = 0;
  238. this.dependencies = [];
  239. this.activeClipUrl = null;
  240. this.clipGroup = null;
  241. this.maskId = '';
  242. }
  243. SVGExtraState.prototype = {
  244. clone: function SVGExtraState_clone() {
  245. return Object.create(this);
  246. },
  247. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  248. this.x = x;
  249. this.y = y;
  250. }
  251. };
  252. return SVGExtraState;
  253. }();
  254. exports.SVGGraphics = SVGGraphics = function SVGGraphicsClosure() {
  255. function opListToTree(opList) {
  256. var opTree = [];
  257. var tmp = [];
  258. var opListLen = opList.length;
  259. for (var x = 0; x < opListLen; x++) {
  260. if (opList[x].fn === 'save') {
  261. opTree.push({
  262. 'fnId': 92,
  263. 'fn': 'group',
  264. 'items': []
  265. });
  266. tmp.push(opTree);
  267. opTree = opTree[opTree.length - 1].items;
  268. continue;
  269. }
  270. if (opList[x].fn === 'restore') {
  271. opTree = tmp.pop();
  272. } else {
  273. opTree.push(opList[x]);
  274. }
  275. }
  276. return opTree;
  277. }
  278. function pf(value) {
  279. if (Number.isInteger(value)) {
  280. return value.toString();
  281. }
  282. var s = value.toFixed(10);
  283. var i = s.length - 1;
  284. if (s[i] !== '0') {
  285. return s;
  286. }
  287. do {
  288. i--;
  289. } while (s[i] === '0');
  290. return s.substring(0, s[i] === '.' ? i : i + 1);
  291. }
  292. function pm(m) {
  293. if (m[4] === 0 && m[5] === 0) {
  294. if (m[1] === 0 && m[2] === 0) {
  295. if (m[0] === 1 && m[3] === 1) {
  296. return '';
  297. }
  298. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  299. }
  300. if (m[0] === m[3] && m[1] === -m[2]) {
  301. var a = Math.acos(m[0]) * 180 / Math.PI;
  302. return 'rotate(' + pf(a) + ')';
  303. }
  304. } else {
  305. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  306. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  307. }
  308. }
  309. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' + pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  310. }
  311. function SVGGraphics(commonObjs, objs, forceDataSchema) {
  312. this.svgFactory = new _dom_utils.DOMSVGFactory();
  313. this.current = new SVGExtraState();
  314. this.transformMatrix = _util.IDENTITY_MATRIX;
  315. this.transformStack = [];
  316. this.extraStack = [];
  317. this.commonObjs = commonObjs;
  318. this.objs = objs;
  319. this.pendingClip = null;
  320. this.pendingEOFill = false;
  321. this.embedFonts = false;
  322. this.embeddedFonts = Object.create(null);
  323. this.cssStyle = null;
  324. this.forceDataSchema = !!forceDataSchema;
  325. }
  326. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  327. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  328. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  329. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  330. var clipCount = 0;
  331. var maskCount = 0;
  332. SVGGraphics.prototype = {
  333. save: function SVGGraphics_save() {
  334. this.transformStack.push(this.transformMatrix);
  335. var old = this.current;
  336. this.extraStack.push(old);
  337. this.current = old.clone();
  338. },
  339. restore: function SVGGraphics_restore() {
  340. this.transformMatrix = this.transformStack.pop();
  341. this.current = this.extraStack.pop();
  342. this.pendingClip = null;
  343. this.tgrp = null;
  344. },
  345. group: function SVGGraphics_group(items) {
  346. this.save();
  347. this.executeOpTree(items);
  348. this.restore();
  349. },
  350. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  351. var _this = this;
  352. var fnArray = operatorList.fnArray;
  353. var fnArrayLen = fnArray.length;
  354. var argsArray = operatorList.argsArray;
  355. for (var i = 0; i < fnArrayLen; i++) {
  356. if (_util.OPS.dependency === fnArray[i]) {
  357. var deps = argsArray[i];
  358. for (var n = 0, nn = deps.length; n < nn; n++) {
  359. var obj = deps[n];
  360. var common = obj.substring(0, 2) === 'g_';
  361. var promise;
  362. if (common) {
  363. promise = new Promise(function (resolve) {
  364. _this.commonObjs.get(obj, resolve);
  365. });
  366. } else {
  367. promise = new Promise(function (resolve) {
  368. _this.objs.get(obj, resolve);
  369. });
  370. }
  371. this.current.dependencies.push(promise);
  372. }
  373. }
  374. }
  375. return Promise.all(this.current.dependencies);
  376. },
  377. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  378. var transformMatrix = [a, b, c, d, e, f];
  379. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  380. this.tgrp = null;
  381. },
  382. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  383. var _this2 = this;
  384. this.viewport = viewport;
  385. var svgElement = this._initialize(viewport);
  386. return this.loadDependencies(operatorList).then(function () {
  387. _this2.transformMatrix = _util.IDENTITY_MATRIX;
  388. var opTree = _this2.convertOpList(operatorList);
  389. _this2.executeOpTree(opTree);
  390. return svgElement;
  391. });
  392. },
  393. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  394. var argsArray = operatorList.argsArray;
  395. var fnArray = operatorList.fnArray;
  396. var fnArrayLen = fnArray.length;
  397. var REVOPS = [];
  398. var opList = [];
  399. for (var op in _util.OPS) {
  400. REVOPS[_util.OPS[op]] = op;
  401. }
  402. for (var x = 0; x < fnArrayLen; x++) {
  403. var fnId = fnArray[x];
  404. opList.push({
  405. 'fnId': fnId,
  406. 'fn': REVOPS[fnId],
  407. 'args': argsArray[x]
  408. });
  409. }
  410. return opListToTree(opList);
  411. },
  412. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  413. var opTreeLen = opTree.length;
  414. for (var x = 0; x < opTreeLen; x++) {
  415. var fn = opTree[x].fn;
  416. var fnId = opTree[x].fnId;
  417. var args = opTree[x].args;
  418. switch (fnId | 0) {
  419. case _util.OPS.beginText:
  420. this.beginText();
  421. break;
  422. case _util.OPS.dependency:
  423. break;
  424. case _util.OPS.setLeading:
  425. this.setLeading(args);
  426. break;
  427. case _util.OPS.setLeadingMoveText:
  428. this.setLeadingMoveText(args[0], args[1]);
  429. break;
  430. case _util.OPS.setFont:
  431. this.setFont(args);
  432. break;
  433. case _util.OPS.showText:
  434. this.showText(args[0]);
  435. break;
  436. case _util.OPS.showSpacedText:
  437. this.showText(args[0]);
  438. break;
  439. case _util.OPS.endText:
  440. this.endText();
  441. break;
  442. case _util.OPS.moveText:
  443. this.moveText(args[0], args[1]);
  444. break;
  445. case _util.OPS.setCharSpacing:
  446. this.setCharSpacing(args[0]);
  447. break;
  448. case _util.OPS.setWordSpacing:
  449. this.setWordSpacing(args[0]);
  450. break;
  451. case _util.OPS.setHScale:
  452. this.setHScale(args[0]);
  453. break;
  454. case _util.OPS.setTextMatrix:
  455. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  456. break;
  457. case _util.OPS.setTextRise:
  458. this.setTextRise(args[0]);
  459. break;
  460. case _util.OPS.setTextRenderingMode:
  461. this.setTextRenderingMode(args[0]);
  462. break;
  463. case _util.OPS.setLineWidth:
  464. this.setLineWidth(args[0]);
  465. break;
  466. case _util.OPS.setLineJoin:
  467. this.setLineJoin(args[0]);
  468. break;
  469. case _util.OPS.setLineCap:
  470. this.setLineCap(args[0]);
  471. break;
  472. case _util.OPS.setMiterLimit:
  473. this.setMiterLimit(args[0]);
  474. break;
  475. case _util.OPS.setFillRGBColor:
  476. this.setFillRGBColor(args[0], args[1], args[2]);
  477. break;
  478. case _util.OPS.setStrokeRGBColor:
  479. this.setStrokeRGBColor(args[0], args[1], args[2]);
  480. break;
  481. case _util.OPS.setDash:
  482. this.setDash(args[0], args[1]);
  483. break;
  484. case _util.OPS.setGState:
  485. this.setGState(args[0]);
  486. break;
  487. case _util.OPS.fill:
  488. this.fill();
  489. break;
  490. case _util.OPS.eoFill:
  491. this.eoFill();
  492. break;
  493. case _util.OPS.stroke:
  494. this.stroke();
  495. break;
  496. case _util.OPS.fillStroke:
  497. this.fillStroke();
  498. break;
  499. case _util.OPS.eoFillStroke:
  500. this.eoFillStroke();
  501. break;
  502. case _util.OPS.clip:
  503. this.clip('nonzero');
  504. break;
  505. case _util.OPS.eoClip:
  506. this.clip('evenodd');
  507. break;
  508. case _util.OPS.paintSolidColorImageMask:
  509. this.paintSolidColorImageMask();
  510. break;
  511. case _util.OPS.paintJpegXObject:
  512. this.paintJpegXObject(args[0], args[1], args[2]);
  513. break;
  514. case _util.OPS.paintImageXObject:
  515. this.paintImageXObject(args[0]);
  516. break;
  517. case _util.OPS.paintInlineImageXObject:
  518. this.paintInlineImageXObject(args[0]);
  519. break;
  520. case _util.OPS.paintImageMaskXObject:
  521. this.paintImageMaskXObject(args[0]);
  522. break;
  523. case _util.OPS.paintFormXObjectBegin:
  524. this.paintFormXObjectBegin(args[0], args[1]);
  525. break;
  526. case _util.OPS.paintFormXObjectEnd:
  527. this.paintFormXObjectEnd();
  528. break;
  529. case _util.OPS.closePath:
  530. this.closePath();
  531. break;
  532. case _util.OPS.closeStroke:
  533. this.closeStroke();
  534. break;
  535. case _util.OPS.closeFillStroke:
  536. this.closeFillStroke();
  537. break;
  538. case _util.OPS.closeEOFillStroke:
  539. this.closeEOFillStroke();
  540. break;
  541. case _util.OPS.nextLine:
  542. this.nextLine();
  543. break;
  544. case _util.OPS.transform:
  545. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  546. break;
  547. case _util.OPS.constructPath:
  548. this.constructPath(args[0], args[1]);
  549. break;
  550. case _util.OPS.endPath:
  551. this.endPath();
  552. break;
  553. case 92:
  554. this.group(opTree[x].items);
  555. break;
  556. default:
  557. (0, _util.warn)('Unimplemented operator ' + fn);
  558. break;
  559. }
  560. }
  561. },
  562. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  563. this.current.wordSpacing = wordSpacing;
  564. },
  565. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  566. this.current.charSpacing = charSpacing;
  567. },
  568. nextLine: function SVGGraphics_nextLine() {
  569. this.moveText(0, this.current.leading);
  570. },
  571. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  572. var current = this.current;
  573. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  574. this.current.x = this.current.lineX = 0;
  575. this.current.y = this.current.lineY = 0;
  576. current.xcoords = [];
  577. current.tspan = this.svgFactory.createElement('svg:tspan');
  578. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  579. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  580. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  581. current.txtElement = this.svgFactory.createElement('svg:text');
  582. current.txtElement.appendChild(current.tspan);
  583. },
  584. beginText: function SVGGraphics_beginText() {
  585. this.current.x = this.current.lineX = 0;
  586. this.current.y = this.current.lineY = 0;
  587. this.current.textMatrix = _util.IDENTITY_MATRIX;
  588. this.current.lineMatrix = _util.IDENTITY_MATRIX;
  589. this.current.tspan = this.svgFactory.createElement('svg:tspan');
  590. this.current.txtElement = this.svgFactory.createElement('svg:text');
  591. this.current.txtgrp = this.svgFactory.createElement('svg:g');
  592. this.current.xcoords = [];
  593. },
  594. moveText: function SVGGraphics_moveText(x, y) {
  595. var current = this.current;
  596. this.current.x = this.current.lineX += x;
  597. this.current.y = this.current.lineY += y;
  598. current.xcoords = [];
  599. current.tspan = this.svgFactory.createElement('svg:tspan');
  600. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  601. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  602. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  603. },
  604. showText: function SVGGraphics_showText(glyphs) {
  605. var current = this.current;
  606. var font = current.font;
  607. var fontSize = current.fontSize;
  608. if (fontSize === 0) {
  609. return;
  610. }
  611. var charSpacing = current.charSpacing;
  612. var wordSpacing = current.wordSpacing;
  613. var fontDirection = current.fontDirection;
  614. var textHScale = current.textHScale * fontDirection;
  615. var glyphsLength = glyphs.length;
  616. var vertical = font.vertical;
  617. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  618. var x = 0,
  619. i;
  620. for (i = 0; i < glyphsLength; ++i) {
  621. var glyph = glyphs[i];
  622. if (glyph === null) {
  623. x += fontDirection * wordSpacing;
  624. continue;
  625. } else if ((0, _util.isNum)(glyph)) {
  626. x += -glyph * fontSize * 0.001;
  627. continue;
  628. }
  629. var width = glyph.width;
  630. var character = glyph.fontChar;
  631. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  632. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  633. if (!glyph.isInFont && !font.missingFile) {
  634. x += charWidth;
  635. continue;
  636. }
  637. current.xcoords.push(current.x + x * textHScale);
  638. current.tspan.textContent += character;
  639. x += charWidth;
  640. }
  641. if (vertical) {
  642. current.y -= x * textHScale;
  643. } else {
  644. current.x += x * textHScale;
  645. }
  646. current.tspan.setAttributeNS(null, 'x', current.xcoords.map(pf).join(' '));
  647. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  648. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  649. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  650. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  651. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  652. }
  653. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  654. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  655. }
  656. var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  657. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  658. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  659. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  660. }
  661. if (current.fillAlpha < 1) {
  662. current.tspan.setAttributeNS(null, 'fill-opacity', current.fillAlpha);
  663. }
  664. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  665. current.tspan.setAttributeNS(null, 'fill', 'transparent');
  666. } else {
  667. current.tspan.setAttributeNS(null, 'fill', 'none');
  668. }
  669. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  670. this._setStrokeAttributes(current.tspan);
  671. }
  672. var textMatrix = current.textMatrix;
  673. if (current.textRise !== 0) {
  674. textMatrix = textMatrix.slice();
  675. textMatrix[5] += current.textRise;
  676. }
  677. current.txtElement.setAttributeNS(null, 'transform', pm(textMatrix) + ' scale(1, -1)');
  678. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  679. current.txtElement.appendChild(current.tspan);
  680. current.txtgrp.appendChild(current.txtElement);
  681. this._ensureTransformGroup().appendChild(current.txtElement);
  682. },
  683. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  684. this.setLeading(-y);
  685. this.moveText(x, y);
  686. },
  687. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  688. if (!this.cssStyle) {
  689. this.cssStyle = this.svgFactory.createElement('svg:style');
  690. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  691. this.defs.appendChild(this.cssStyle);
  692. }
  693. var url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  694. this.cssStyle.textContent += '@font-face { font-family: "' + fontObj.loadedName + '";' + ' src: url(' + url + '); }\n';
  695. },
  696. setFont: function SVGGraphics_setFont(details) {
  697. var current = this.current;
  698. var fontObj = this.commonObjs.get(details[0]);
  699. var size = details[1];
  700. this.current.font = fontObj;
  701. if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) {
  702. this.addFontStyle(fontObj);
  703. this.embeddedFonts[fontObj.loadedName] = fontObj;
  704. }
  705. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
  706. var bold = fontObj.black ? fontObj.bold ? 'bolder' : 'bold' : fontObj.bold ? 'bold' : 'normal';
  707. var italic = fontObj.italic ? 'italic' : 'normal';
  708. if (size < 0) {
  709. size = -size;
  710. current.fontDirection = -1;
  711. } else {
  712. current.fontDirection = 1;
  713. }
  714. current.fontSize = size;
  715. current.fontFamily = fontObj.loadedName;
  716. current.fontWeight = bold;
  717. current.fontStyle = italic;
  718. current.tspan = this.svgFactory.createElement('svg:tspan');
  719. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  720. current.xcoords = [];
  721. },
  722. endText: function endText() {
  723. var current = this.current;
  724. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement && current.txtElement.hasChildNodes()) {
  725. current.element = current.txtElement;
  726. this.clip('nonzero');
  727. this.endPath();
  728. }
  729. },
  730. setLineWidth: function SVGGraphics_setLineWidth(width) {
  731. if (width > 0) {
  732. this.current.lineWidth = width;
  733. }
  734. },
  735. setLineCap: function SVGGraphics_setLineCap(style) {
  736. this.current.lineCap = LINE_CAP_STYLES[style];
  737. },
  738. setLineJoin: function SVGGraphics_setLineJoin(style) {
  739. this.current.lineJoin = LINE_JOIN_STYLES[style];
  740. },
  741. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  742. this.current.miterLimit = limit;
  743. },
  744. setStrokeAlpha: function SVGGraphics_setStrokeAlpha(strokeAlpha) {
  745. this.current.strokeAlpha = strokeAlpha;
  746. },
  747. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  748. var color = _util.Util.makeCssRgb(r, g, b);
  749. this.current.strokeColor = color;
  750. },
  751. setFillAlpha: function SVGGraphics_setFillAlpha(fillAlpha) {
  752. this.current.fillAlpha = fillAlpha;
  753. },
  754. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  755. var color = _util.Util.makeCssRgb(r, g, b);
  756. this.current.fillColor = color;
  757. this.current.tspan = this.svgFactory.createElement('svg:tspan');
  758. this.current.xcoords = [];
  759. },
  760. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  761. this.current.dashArray = dashArray;
  762. this.current.dashPhase = dashPhase;
  763. },
  764. constructPath: function SVGGraphics_constructPath(ops, args) {
  765. var current = this.current;
  766. var x = current.x,
  767. y = current.y;
  768. current.path = this.svgFactory.createElement('svg:path');
  769. var d = [];
  770. var opLength = ops.length;
  771. for (var i = 0, j = 0; i < opLength; i++) {
  772. switch (ops[i] | 0) {
  773. case _util.OPS.rectangle:
  774. x = args[j++];
  775. y = args[j++];
  776. var width = args[j++];
  777. var height = args[j++];
  778. var xw = x + width;
  779. var yh = y + height;
  780. d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z');
  781. break;
  782. case _util.OPS.moveTo:
  783. x = args[j++];
  784. y = args[j++];
  785. d.push('M', pf(x), pf(y));
  786. break;
  787. case _util.OPS.lineTo:
  788. x = args[j++];
  789. y = args[j++];
  790. d.push('L', pf(x), pf(y));
  791. break;
  792. case _util.OPS.curveTo:
  793. x = args[j + 4];
  794. y = args[j + 5];
  795. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  796. j += 6;
  797. break;
  798. case _util.OPS.curveTo2:
  799. x = args[j + 2];
  800. y = args[j + 3];
  801. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  802. j += 4;
  803. break;
  804. case _util.OPS.curveTo3:
  805. x = args[j + 2];
  806. y = args[j + 3];
  807. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  808. j += 4;
  809. break;
  810. case _util.OPS.closePath:
  811. d.push('Z');
  812. break;
  813. }
  814. }
  815. current.path.setAttributeNS(null, 'd', d.join(' '));
  816. current.path.setAttributeNS(null, 'fill', 'none');
  817. this._ensureTransformGroup().appendChild(current.path);
  818. current.element = current.path;
  819. current.setCurrentPoint(x, y);
  820. },
  821. endPath: function SVGGraphics_endPath() {
  822. if (!this.pendingClip) {
  823. return;
  824. }
  825. var current = this.current;
  826. var clipId = 'clippath' + clipCount;
  827. clipCount++;
  828. var clipPath = this.svgFactory.createElement('svg:clipPath');
  829. clipPath.setAttributeNS(null, 'id', clipId);
  830. clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  831. var clipElement = current.element.cloneNode(true);
  832. if (this.pendingClip === 'evenodd') {
  833. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  834. } else {
  835. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  836. }
  837. this.pendingClip = null;
  838. clipPath.appendChild(clipElement);
  839. this.defs.appendChild(clipPath);
  840. if (current.activeClipUrl) {
  841. current.clipGroup = null;
  842. this.extraStack.forEach(function (prev) {
  843. prev.clipGroup = null;
  844. });
  845. clipPath.setAttributeNS(null, 'clip-path', current.activeClipUrl);
  846. }
  847. current.activeClipUrl = 'url(#' + clipId + ')';
  848. this.tgrp = null;
  849. },
  850. clip: function SVGGraphics_clip(type) {
  851. this.pendingClip = type;
  852. },
  853. closePath: function SVGGraphics_closePath() {
  854. var current = this.current;
  855. if (current.path) {
  856. var d = current.path.getAttributeNS(null, 'd');
  857. d += 'Z';
  858. current.path.setAttributeNS(null, 'd', d);
  859. }
  860. },
  861. setLeading: function SVGGraphics_setLeading(leading) {
  862. this.current.leading = -leading;
  863. },
  864. setTextRise: function SVGGraphics_setTextRise(textRise) {
  865. this.current.textRise = textRise;
  866. },
  867. setTextRenderingMode: function setTextRenderingMode(textRenderingMode) {
  868. this.current.textRenderingMode = textRenderingMode;
  869. },
  870. setHScale: function SVGGraphics_setHScale(scale) {
  871. this.current.textHScale = scale / 100;
  872. },
  873. setGState: function SVGGraphics_setGState(states) {
  874. for (var i = 0, ii = states.length; i < ii; i++) {
  875. var state = states[i];
  876. var key = state[0];
  877. var value = state[1];
  878. switch (key) {
  879. case 'LW':
  880. this.setLineWidth(value);
  881. break;
  882. case 'LC':
  883. this.setLineCap(value);
  884. break;
  885. case 'LJ':
  886. this.setLineJoin(value);
  887. break;
  888. case 'ML':
  889. this.setMiterLimit(value);
  890. break;
  891. case 'D':
  892. this.setDash(value[0], value[1]);
  893. break;
  894. case 'Font':
  895. this.setFont(value);
  896. break;
  897. case 'CA':
  898. this.setStrokeAlpha(value);
  899. break;
  900. case 'ca':
  901. this.setFillAlpha(value);
  902. break;
  903. default:
  904. (0, _util.warn)('Unimplemented graphic state ' + key);
  905. break;
  906. }
  907. }
  908. },
  909. fill: function SVGGraphics_fill() {
  910. var current = this.current;
  911. if (current.element) {
  912. current.element.setAttributeNS(null, 'fill', current.fillColor);
  913. current.element.setAttributeNS(null, 'fill-opacity', current.fillAlpha);
  914. this.endPath();
  915. }
  916. },
  917. stroke: function SVGGraphics_stroke() {
  918. var current = this.current;
  919. if (current.element) {
  920. this._setStrokeAttributes(current.element);
  921. current.element.setAttributeNS(null, 'fill', 'none');
  922. this.endPath();
  923. }
  924. },
  925. _setStrokeAttributes: function _setStrokeAttributes(element) {
  926. var current = this.current;
  927. element.setAttributeNS(null, 'stroke', current.strokeColor);
  928. element.setAttributeNS(null, 'stroke-opacity', current.strokeAlpha);
  929. element.setAttributeNS(null, 'stroke-miterlimit', pf(current.miterLimit));
  930. element.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  931. element.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  932. element.setAttributeNS(null, 'stroke-width', pf(current.lineWidth) + 'px');
  933. element.setAttributeNS(null, 'stroke-dasharray', current.dashArray.map(pf).join(' '));
  934. element.setAttributeNS(null, 'stroke-dashoffset', pf(current.dashPhase) + 'px');
  935. },
  936. eoFill: function SVGGraphics_eoFill() {
  937. if (this.current.element) {
  938. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  939. }
  940. this.fill();
  941. },
  942. fillStroke: function SVGGraphics_fillStroke() {
  943. this.stroke();
  944. this.fill();
  945. },
  946. eoFillStroke: function SVGGraphics_eoFillStroke() {
  947. if (this.current.element) {
  948. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  949. }
  950. this.fillStroke();
  951. },
  952. closeStroke: function SVGGraphics_closeStroke() {
  953. this.closePath();
  954. this.stroke();
  955. },
  956. closeFillStroke: function SVGGraphics_closeFillStroke() {
  957. this.closePath();
  958. this.fillStroke();
  959. },
  960. closeEOFillStroke: function closeEOFillStroke() {
  961. this.closePath();
  962. this.eoFillStroke();
  963. },
  964. paintSolidColorImageMask: function SVGGraphics_paintSolidColorImageMask() {
  965. var current = this.current;
  966. var rect = this.svgFactory.createElement('svg:rect');
  967. rect.setAttributeNS(null, 'x', '0');
  968. rect.setAttributeNS(null, 'y', '0');
  969. rect.setAttributeNS(null, 'width', '1px');
  970. rect.setAttributeNS(null, 'height', '1px');
  971. rect.setAttributeNS(null, 'fill', current.fillColor);
  972. this._ensureTransformGroup().appendChild(rect);
  973. },
  974. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  975. var imgObj = this.objs.get(objId);
  976. var imgEl = this.svgFactory.createElement('svg:image');
  977. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  978. imgEl.setAttributeNS(null, 'width', pf(w));
  979. imgEl.setAttributeNS(null, 'height', pf(h));
  980. imgEl.setAttributeNS(null, 'x', '0');
  981. imgEl.setAttributeNS(null, 'y', pf(-h));
  982. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  983. this._ensureTransformGroup().appendChild(imgEl);
  984. },
  985. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  986. var imgData = this.objs.get(objId);
  987. if (!imgData) {
  988. (0, _util.warn)('Dependent image isn\'t ready yet');
  989. return;
  990. }
  991. this.paintInlineImageXObject(imgData);
  992. },
  993. paintInlineImageXObject: function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  994. var width = imgData.width;
  995. var height = imgData.height;
  996. var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  997. var cliprect = this.svgFactory.createElement('svg:rect');
  998. cliprect.setAttributeNS(null, 'x', '0');
  999. cliprect.setAttributeNS(null, 'y', '0');
  1000. cliprect.setAttributeNS(null, 'width', pf(width));
  1001. cliprect.setAttributeNS(null, 'height', pf(height));
  1002. this.current.element = cliprect;
  1003. this.clip('nonzero');
  1004. var imgEl = this.svgFactory.createElement('svg:image');
  1005. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  1006. imgEl.setAttributeNS(null, 'x', '0');
  1007. imgEl.setAttributeNS(null, 'y', pf(-height));
  1008. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  1009. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  1010. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / width) + ' ' + pf(-1 / height) + ')');
  1011. if (mask) {
  1012. mask.appendChild(imgEl);
  1013. } else {
  1014. this._ensureTransformGroup().appendChild(imgEl);
  1015. }
  1016. },
  1017. paintImageMaskXObject: function SVGGraphics_paintImageMaskXObject(imgData) {
  1018. var current = this.current;
  1019. var width = imgData.width;
  1020. var height = imgData.height;
  1021. var fillColor = current.fillColor;
  1022. current.maskId = 'mask' + maskCount++;
  1023. var mask = this.svgFactory.createElement('svg:mask');
  1024. mask.setAttributeNS(null, 'id', current.maskId);
  1025. var rect = this.svgFactory.createElement('svg:rect');
  1026. rect.setAttributeNS(null, 'x', '0');
  1027. rect.setAttributeNS(null, 'y', '0');
  1028. rect.setAttributeNS(null, 'width', pf(width));
  1029. rect.setAttributeNS(null, 'height', pf(height));
  1030. rect.setAttributeNS(null, 'fill', fillColor);
  1031. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId + ')');
  1032. this.defs.appendChild(mask);
  1033. this._ensureTransformGroup().appendChild(rect);
  1034. this.paintInlineImageXObject(imgData, mask);
  1035. },
  1036. paintFormXObjectBegin: function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  1037. if (Array.isArray(matrix) && matrix.length === 6) {
  1038. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  1039. }
  1040. if (bbox) {
  1041. var width = bbox[2] - bbox[0];
  1042. var height = bbox[3] - bbox[1];
  1043. var cliprect = this.svgFactory.createElement('svg:rect');
  1044. cliprect.setAttributeNS(null, 'x', bbox[0]);
  1045. cliprect.setAttributeNS(null, 'y', bbox[1]);
  1046. cliprect.setAttributeNS(null, 'width', pf(width));
  1047. cliprect.setAttributeNS(null, 'height', pf(height));
  1048. this.current.element = cliprect;
  1049. this.clip('nonzero');
  1050. this.endPath();
  1051. }
  1052. },
  1053. paintFormXObjectEnd: function SVGGraphics_paintFormXObjectEnd() {},
  1054. _initialize: function _initialize(viewport) {
  1055. var svg = this.svgFactory.create(viewport.width, viewport.height);
  1056. var definitions = this.svgFactory.createElement('svg:defs');
  1057. svg.appendChild(definitions);
  1058. this.defs = definitions;
  1059. var rootGroup = this.svgFactory.createElement('svg:g');
  1060. rootGroup.setAttributeNS(null, 'transform', pm(viewport.transform));
  1061. svg.appendChild(rootGroup);
  1062. this.svg = rootGroup;
  1063. return svg;
  1064. },
  1065. _ensureClipGroup: function SVGGraphics_ensureClipGroup() {
  1066. if (!this.current.clipGroup) {
  1067. var clipGroup = this.svgFactory.createElement('svg:g');
  1068. clipGroup.setAttributeNS(null, 'clip-path', this.current.activeClipUrl);
  1069. this.svg.appendChild(clipGroup);
  1070. this.current.clipGroup = clipGroup;
  1071. }
  1072. return this.current.clipGroup;
  1073. },
  1074. _ensureTransformGroup: function SVGGraphics_ensureTransformGroup() {
  1075. if (!this.tgrp) {
  1076. this.tgrp = this.svgFactory.createElement('svg:g');
  1077. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  1078. if (this.current.activeClipUrl) {
  1079. this._ensureClipGroup().appendChild(this.tgrp);
  1080. } else {
  1081. this.svg.appendChild(this.tgrp);
  1082. }
  1083. }
  1084. return this.tgrp;
  1085. }
  1086. };
  1087. return SVGGraphics;
  1088. }();
  1089. }