2014-01-26 03:18:22 +09:00
|
|
|
/* Copyright 2014 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-09-02 03:27:13 +09:00
|
|
|
import { FormatError, info, Util } from '../shared/util';
|
2017-04-02 21:25:33 +09:00
|
|
|
import { WebGLUtils } from './webgl';
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2014-01-26 03:18:22 +09:00
|
|
|
var ShadingIRs = {};
|
|
|
|
|
|
|
|
ShadingIRs.RadialAxial = {
|
|
|
|
fromIR: function RadialAxial_fromIR(raw) {
|
|
|
|
var type = raw[1];
|
|
|
|
var colorStops = raw[2];
|
|
|
|
var p0 = raw[3];
|
|
|
|
var p1 = raw[4];
|
|
|
|
var r0 = raw[5];
|
|
|
|
var r1 = raw[6];
|
|
|
|
return {
|
|
|
|
type: 'Pattern',
|
|
|
|
getPattern: function RadialAxial_getPattern(ctx) {
|
|
|
|
var grad;
|
|
|
|
if (type === 'axial') {
|
|
|
|
grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
|
|
|
|
} else if (type === 'radial') {
|
|
|
|
grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0, ii = colorStops.length; i < ii; ++i) {
|
|
|
|
var c = colorStops[i];
|
|
|
|
grad.addColorStop(c[0], c[1]);
|
|
|
|
}
|
|
|
|
return grad;
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2014-01-26 03:18:22 +09:00
|
|
|
};
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2014-01-26 03:18:22 +09:00
|
|
|
};
|
|
|
|
|
2014-01-27 22:17:14 +09:00
|
|
|
var createMeshCanvas = (function createMeshCanvasClosure() {
|
|
|
|
function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
|
|
|
|
// Very basic Gouraud-shaded triangle rasterization algorithm.
|
|
|
|
var coords = context.coords, colors = context.colors;
|
|
|
|
var bytes = data.data, rowSize = data.width * 4;
|
|
|
|
var tmp;
|
2014-02-13 23:20:00 +09:00
|
|
|
if (coords[p1 + 1] > coords[p2 + 1]) {
|
2014-01-27 22:17:14 +09:00
|
|
|
tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
|
|
|
|
}
|
2014-02-13 23:20:00 +09:00
|
|
|
if (coords[p2 + 1] > coords[p3 + 1]) {
|
2014-01-27 22:17:14 +09:00
|
|
|
tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
|
|
|
|
}
|
2014-02-13 23:20:00 +09:00
|
|
|
if (coords[p1 + 1] > coords[p2 + 1]) {
|
2014-01-27 22:17:14 +09:00
|
|
|
tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
|
|
|
|
}
|
2014-02-13 23:20:00 +09:00
|
|
|
var x1 = (coords[p1] + context.offsetX) * context.scaleX;
|
|
|
|
var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
|
|
|
|
var x2 = (coords[p2] + context.offsetX) * context.scaleX;
|
|
|
|
var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
|
|
|
|
var x3 = (coords[p3] + context.offsetX) * context.scaleX;
|
|
|
|
var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
|
2014-01-27 22:17:14 +09:00
|
|
|
if (y1 >= y3) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-13 23:20:00 +09:00
|
|
|
var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
|
|
|
|
var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
|
|
|
|
var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
|
2014-01-27 22:17:14 +09:00
|
|
|
|
|
|
|
var minY = Math.round(y1), maxY = Math.round(y3);
|
|
|
|
var xa, car, cag, cab;
|
|
|
|
var xb, cbr, cbg, cbb;
|
|
|
|
var k;
|
|
|
|
for (var y = minY; y <= maxY; y++) {
|
|
|
|
if (y < y2) {
|
|
|
|
k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
|
|
|
|
xa = x1 - (x1 - x2) * k;
|
|
|
|
car = c1r - (c1r - c2r) * k;
|
|
|
|
cag = c1g - (c1g - c2g) * k;
|
|
|
|
cab = c1b - (c1b - c2b) * k;
|
|
|
|
} else {
|
|
|
|
k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
|
|
|
|
xa = x2 - (x2 - x3) * k;
|
|
|
|
car = c2r - (c2r - c3r) * k;
|
|
|
|
cag = c2g - (c2g - c3g) * k;
|
|
|
|
cab = c2b - (c2b - c3b) * k;
|
|
|
|
}
|
|
|
|
k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
|
|
|
|
xb = x1 - (x1 - x3) * k;
|
|
|
|
cbr = c1r - (c1r - c3r) * k;
|
|
|
|
cbg = c1g - (c1g - c3g) * k;
|
|
|
|
cbb = c1b - (c1b - c3b) * k;
|
|
|
|
var x1_ = Math.round(Math.min(xa, xb));
|
|
|
|
var x2_ = Math.round(Math.max(xa, xb));
|
|
|
|
var j = rowSize * y + x1_ * 4;
|
|
|
|
for (var x = x1_; x <= x2_; x++) {
|
|
|
|
k = (xa - x) / (xa - xb);
|
|
|
|
k = k < 0 ? 0 : k > 1 ? 1 : k;
|
|
|
|
bytes[j++] = (car - (car - cbr) * k) | 0;
|
|
|
|
bytes[j++] = (cag - (cag - cbg) * k) | 0;
|
|
|
|
bytes[j++] = (cab - (cab - cbb) * k) | 0;
|
|
|
|
bytes[j++] = 255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawFigure(data, figure, context) {
|
|
|
|
var ps = figure.coords;
|
|
|
|
var cs = figure.colors;
|
2014-04-09 04:48:16 +09:00
|
|
|
var i, ii;
|
2014-01-27 22:17:14 +09:00
|
|
|
switch (figure.type) {
|
|
|
|
case 'lattice':
|
|
|
|
var verticesPerRow = figure.verticesPerRow;
|
|
|
|
var rows = Math.floor(ps.length / verticesPerRow) - 1;
|
|
|
|
var cols = verticesPerRow - 1;
|
2014-04-09 04:48:16 +09:00
|
|
|
for (i = 0; i < rows; i++) {
|
2014-01-27 22:17:14 +09:00
|
|
|
var q = i * verticesPerRow;
|
|
|
|
for (var j = 0; j < cols; j++, q++) {
|
|
|
|
drawTriangle(data, context,
|
|
|
|
ps[q], ps[q + 1], ps[q + verticesPerRow],
|
|
|
|
cs[q], cs[q + 1], cs[q + verticesPerRow]);
|
|
|
|
drawTriangle(data, context,
|
|
|
|
ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
|
|
|
|
cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'triangles':
|
2014-04-09 04:48:16 +09:00
|
|
|
for (i = 0, ii = ps.length; i < ii; i += 3) {
|
2014-01-27 22:17:14 +09:00
|
|
|
drawTriangle(data, context,
|
|
|
|
ps[i], ps[i + 1], ps[i + 2],
|
|
|
|
cs[i], cs[i + 1], cs[i + 2]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new Error('illegal figure');
|
2014-01-27 22:17:14 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 01:16:32 +09:00
|
|
|
function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
|
2015-11-17 01:50:02 +09:00
|
|
|
backgroundColor, cachedCanvases) {
|
2014-01-27 22:17:14 +09:00
|
|
|
// we will increase scale on some weird factor to let antialiasing take
|
|
|
|
// care of "rough" edges
|
2014-01-30 01:16:32 +09:00
|
|
|
var EXPECTED_SCALE = 1.1;
|
2014-01-27 22:17:14 +09:00
|
|
|
// MAX_PATTERN_SIZE is used to avoid OOM situation.
|
|
|
|
var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
|
2016-04-12 08:21:44 +09:00
|
|
|
// We need to keep transparent border around our pattern for fill():
|
2016-07-17 21:33:41 +09:00
|
|
|
// createPattern with 'no-repeat' will bleed edges across entire area.
|
2016-04-12 08:21:44 +09:00
|
|
|
var BORDER_SIZE = 2;
|
2014-01-27 22:17:14 +09:00
|
|
|
|
2014-02-13 23:44:58 +09:00
|
|
|
var offsetX = Math.floor(bounds[0]);
|
|
|
|
var offsetY = Math.floor(bounds[1]);
|
|
|
|
var boundsWidth = Math.ceil(bounds[2]) - offsetX;
|
|
|
|
var boundsHeight = Math.ceil(bounds[3]) - offsetY;
|
2014-01-27 22:17:14 +09:00
|
|
|
|
2014-01-30 01:16:32 +09:00
|
|
|
var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
|
|
|
|
EXPECTED_SCALE)), MAX_PATTERN_SIZE);
|
|
|
|
var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
|
|
|
|
EXPECTED_SCALE)), MAX_PATTERN_SIZE);
|
2014-02-13 23:44:58 +09:00
|
|
|
var scaleX = boundsWidth / width;
|
|
|
|
var scaleY = boundsHeight / height;
|
2014-01-27 22:17:14 +09:00
|
|
|
|
|
|
|
var context = {
|
2017-04-25 23:17:18 +09:00
|
|
|
coords,
|
|
|
|
colors,
|
2014-02-13 23:44:58 +09:00
|
|
|
offsetX: -offsetX,
|
|
|
|
offsetY: -offsetY,
|
|
|
|
scaleX: 1 / scaleX,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
scaleY: 1 / scaleY,
|
2014-01-27 22:17:14 +09:00
|
|
|
};
|
|
|
|
|
2016-04-12 08:21:44 +09:00
|
|
|
var paddedWidth = width + BORDER_SIZE * 2;
|
|
|
|
var paddedHeight = height + BORDER_SIZE * 2;
|
|
|
|
|
2014-04-10 02:47:42 +09:00
|
|
|
var canvas, tmpCanvas, i, ii;
|
2014-02-13 23:44:58 +09:00
|
|
|
if (WebGLUtils.isEnabled) {
|
|
|
|
canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
|
|
|
|
figures, context);
|
|
|
|
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=972126
|
2016-04-12 08:21:44 +09:00
|
|
|
tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight,
|
|
|
|
false);
|
|
|
|
tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
|
2014-02-13 23:44:58 +09:00
|
|
|
canvas = tmpCanvas.canvas;
|
|
|
|
} else {
|
2016-04-12 08:21:44 +09:00
|
|
|
tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight,
|
|
|
|
false);
|
2014-02-13 23:44:58 +09:00
|
|
|
var tmpCtx = tmpCanvas.context;
|
|
|
|
|
|
|
|
var data = tmpCtx.createImageData(width, height);
|
|
|
|
if (backgroundColor) {
|
|
|
|
var bytes = data.data;
|
2014-04-10 02:47:42 +09:00
|
|
|
for (i = 0, ii = bytes.length; i < ii; i += 4) {
|
2014-02-13 23:44:58 +09:00
|
|
|
bytes[i] = backgroundColor[0];
|
|
|
|
bytes[i + 1] = backgroundColor[1];
|
|
|
|
bytes[i + 2] = backgroundColor[2];
|
|
|
|
bytes[i + 3] = 255;
|
|
|
|
}
|
|
|
|
}
|
2014-04-10 02:47:42 +09:00
|
|
|
for (i = 0; i < figures.length; i++) {
|
2014-02-13 23:44:58 +09:00
|
|
|
drawFigure(data, figures[i], context);
|
|
|
|
}
|
2016-04-12 08:21:44 +09:00
|
|
|
tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
|
2014-02-13 23:44:58 +09:00
|
|
|
canvas = tmpCanvas.canvas;
|
2014-01-27 22:17:14 +09:00
|
|
|
}
|
|
|
|
|
2017-04-25 23:17:18 +09:00
|
|
|
return {
|
|
|
|
canvas,
|
|
|
|
offsetX: offsetX - BORDER_SIZE * scaleX,
|
|
|
|
offsetY: offsetY - BORDER_SIZE * scaleY,
|
|
|
|
scaleX,
|
|
|
|
scaleY,
|
|
|
|
};
|
2014-01-27 22:17:14 +09:00
|
|
|
}
|
|
|
|
return createMeshCanvas;
|
|
|
|
})();
|
|
|
|
|
|
|
|
ShadingIRs.Mesh = {
|
|
|
|
fromIR: function Mesh_fromIR(raw) {
|
2017-01-20 00:26:32 +09:00
|
|
|
// var type = raw[1];
|
2014-01-27 22:17:14 +09:00
|
|
|
var coords = raw[2];
|
|
|
|
var colors = raw[3];
|
|
|
|
var figures = raw[4];
|
|
|
|
var bounds = raw[5];
|
|
|
|
var matrix = raw[6];
|
2017-01-20 00:26:32 +09:00
|
|
|
// var bbox = raw[7];
|
2014-01-27 22:17:14 +09:00
|
|
|
var background = raw[8];
|
|
|
|
return {
|
|
|
|
type: 'Pattern',
|
|
|
|
getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
|
2014-07-01 17:48:31 +09:00
|
|
|
var scale;
|
2014-01-30 01:16:32 +09:00
|
|
|
if (shadingFill) {
|
2014-07-01 17:48:31 +09:00
|
|
|
scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
|
2014-01-30 01:16:32 +09:00
|
|
|
} else {
|
2014-07-01 17:48:31 +09:00
|
|
|
// Obtain scale from matrix and current transformation matrix.
|
|
|
|
scale = Util.singularValueDecompose2dScale(owner.baseTransform);
|
|
|
|
if (matrix) {
|
|
|
|
var matrixScale = Util.singularValueDecompose2dScale(matrix);
|
|
|
|
scale = [scale[0] * matrixScale[0],
|
|
|
|
scale[1] * matrixScale[1]];
|
|
|
|
}
|
2014-01-30 01:16:32 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-27 22:17:14 +09:00
|
|
|
// Rasterizing on the main thread since sending/queue large canvases
|
|
|
|
// might cause OOM.
|
2014-07-01 17:48:31 +09:00
|
|
|
var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
|
2015-11-17 01:50:02 +09:00
|
|
|
colors, figures, shadingFill ? null : background,
|
|
|
|
owner.cachedCanvases);
|
2014-01-27 22:17:14 +09:00
|
|
|
|
|
|
|
if (!shadingFill) {
|
|
|
|
ctx.setTransform.apply(ctx, owner.baseTransform);
|
|
|
|
if (matrix) {
|
|
|
|
ctx.transform.apply(ctx, matrix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 23:44:58 +09:00
|
|
|
ctx.translate(temporaryPatternCanvas.offsetX,
|
|
|
|
temporaryPatternCanvas.offsetY);
|
2014-01-27 22:17:14 +09:00
|
|
|
ctx.scale(temporaryPatternCanvas.scaleX,
|
|
|
|
temporaryPatternCanvas.scaleY);
|
|
|
|
|
|
|
|
return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2014-01-27 22:17:14 +09:00
|
|
|
};
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2014-01-27 22:17:14 +09:00
|
|
|
};
|
|
|
|
|
2014-01-26 03:18:22 +09:00
|
|
|
ShadingIRs.Dummy = {
|
|
|
|
fromIR: function Dummy_fromIR() {
|
|
|
|
return {
|
|
|
|
type: 'Pattern',
|
|
|
|
getPattern: function Dummy_fromIR_getPattern() {
|
|
|
|
return 'hotpink';
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2014-01-26 03:18:22 +09:00
|
|
|
};
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2014-01-26 03:18:22 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
function getShadingPatternFromIR(raw) {
|
2014-01-27 22:17:14 +09:00
|
|
|
var shadingIR = ShadingIRs[raw[0]];
|
|
|
|
if (!shadingIR) {
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new Error(`Unknown IR type: ${raw[0]}`);
|
2014-01-27 22:17:14 +09:00
|
|
|
}
|
|
|
|
return shadingIR.fromIR(raw);
|
2014-01-26 03:18:22 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
var TilingPattern = (function TilingPatternClosure() {
|
|
|
|
var PaintType = {
|
|
|
|
COLORED: 1,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
UNCOLORED: 2,
|
2014-01-26 03:18:22 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
|
|
|
|
|
2015-11-22 01:32:47 +09:00
|
|
|
function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
|
2014-01-26 03:18:22 +09:00
|
|
|
this.operatorList = IR[2];
|
|
|
|
this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
|
2017-05-24 19:12:14 +09:00
|
|
|
this.bbox = IR[4];
|
2014-01-26 03:18:22 +09:00
|
|
|
this.xstep = IR[5];
|
|
|
|
this.ystep = IR[6];
|
|
|
|
this.paintType = IR[7];
|
|
|
|
this.tilingType = IR[8];
|
|
|
|
this.color = color;
|
2015-11-22 01:32:47 +09:00
|
|
|
this.canvasGraphicsFactory = canvasGraphicsFactory;
|
2014-01-26 03:18:22 +09:00
|
|
|
this.baseTransform = baseTransform;
|
|
|
|
this.type = 'Pattern';
|
|
|
|
this.ctx = ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
TilingPattern.prototype = {
|
|
|
|
createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
|
|
|
|
var operatorList = this.operatorList;
|
|
|
|
var bbox = this.bbox;
|
|
|
|
var xstep = this.xstep;
|
|
|
|
var ystep = this.ystep;
|
|
|
|
var paintType = this.paintType;
|
|
|
|
var tilingType = this.tilingType;
|
|
|
|
var color = this.color;
|
2015-11-22 01:32:47 +09:00
|
|
|
var canvasGraphicsFactory = this.canvasGraphicsFactory;
|
2014-01-26 03:18:22 +09:00
|
|
|
|
|
|
|
info('TilingType: ' + tilingType);
|
|
|
|
|
|
|
|
var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
|
|
|
|
|
|
|
|
var topLeft = [x0, y0];
|
|
|
|
// we want the canvas to be as large as the step size
|
|
|
|
var botRight = [x0 + xstep, y0 + ystep];
|
|
|
|
|
|
|
|
var width = botRight[0] - topLeft[0];
|
|
|
|
var height = botRight[1] - topLeft[1];
|
|
|
|
|
|
|
|
// Obtain scale from matrix and current transformation matrix.
|
|
|
|
var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
|
|
|
|
var curMatrixScale = Util.singularValueDecompose2dScale(
|
|
|
|
this.baseTransform);
|
|
|
|
var combinedScale = [matrixScale[0] * curMatrixScale[0],
|
|
|
|
matrixScale[1] * curMatrixScale[1]];
|
|
|
|
|
|
|
|
// MAX_PATTERN_SIZE is used to avoid OOM situation.
|
|
|
|
// Use width and height values that are as close as possible to the end
|
|
|
|
// result when the pattern is used. Too low value makes the pattern look
|
|
|
|
// blurry. Too large value makes it look too crispy.
|
|
|
|
width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
|
|
|
|
MAX_PATTERN_SIZE);
|
|
|
|
|
|
|
|
height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
|
|
|
|
MAX_PATTERN_SIZE);
|
|
|
|
|
2015-11-17 01:50:02 +09:00
|
|
|
var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
|
|
|
|
width, height, true);
|
2014-01-26 03:18:22 +09:00
|
|
|
var tmpCtx = tmpCanvas.context;
|
2015-11-22 01:32:47 +09:00
|
|
|
var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
|
2014-01-26 03:18:22 +09:00
|
|
|
graphics.groupLevel = owner.groupLevel;
|
|
|
|
|
|
|
|
this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
|
|
|
|
|
|
|
|
this.setScale(width, height, xstep, ystep);
|
|
|
|
this.transformToScale(graphics);
|
|
|
|
|
|
|
|
// transform coordinates to pattern space
|
|
|
|
var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
|
|
|
|
graphics.transform.apply(graphics, tmpTranslate);
|
|
|
|
|
|
|
|
this.clipBbox(graphics, bbox, x0, y0, x1, y1);
|
|
|
|
|
|
|
|
graphics.executeOperatorList(operatorList);
|
|
|
|
return tmpCanvas.canvas;
|
|
|
|
},
|
|
|
|
|
|
|
|
setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
|
|
|
|
this.scale = [width / xstep, height / ystep];
|
|
|
|
},
|
|
|
|
|
|
|
|
transformToScale: function TilingPattern_transformToScale(graphics) {
|
|
|
|
var scale = this.scale;
|
|
|
|
var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
|
|
|
|
graphics.transform.apply(graphics, tmpScale);
|
|
|
|
},
|
|
|
|
|
|
|
|
scaleToContext: function TilingPattern_scaleToContext() {
|
|
|
|
var scale = this.scale;
|
|
|
|
this.ctx.scale(1 / scale[0], 1 / scale[1]);
|
|
|
|
},
|
|
|
|
|
|
|
|
clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
|
2017-09-02 03:27:13 +09:00
|
|
|
if (Array.isArray(bbox) && bbox.length === 4) {
|
2014-01-26 03:18:22 +09:00
|
|
|
var bboxWidth = x1 - x0;
|
|
|
|
var bboxHeight = y1 - y0;
|
2014-06-24 05:07:31 +09:00
|
|
|
graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
|
2014-01-26 03:18:22 +09:00
|
|
|
graphics.clip();
|
|
|
|
graphics.endPath();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setFillAndStrokeStyleToContext:
|
|
|
|
function setFillAndStrokeStyleToContext(context, paintType, color) {
|
|
|
|
switch (paintType) {
|
|
|
|
case PaintType.COLORED:
|
|
|
|
var ctx = this.ctx;
|
|
|
|
context.fillStyle = ctx.fillStyle;
|
|
|
|
context.strokeStyle = ctx.strokeStyle;
|
|
|
|
break;
|
|
|
|
case PaintType.UNCOLORED:
|
2014-10-28 05:30:47 +09:00
|
|
|
var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
|
2014-01-26 03:18:22 +09:00
|
|
|
context.fillStyle = cssColor;
|
|
|
|
context.strokeStyle = cssColor;
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new FormatError(`Unsupported paint type: ${paintType}`);
|
2014-01-26 03:18:22 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getPattern: function TilingPattern_getPattern(ctx, owner) {
|
|
|
|
var temporaryPatternCanvas = this.createPatternCanvas(owner);
|
|
|
|
|
2014-04-09 04:48:16 +09:00
|
|
|
ctx = this.ctx;
|
2014-01-26 03:18:22 +09:00
|
|
|
ctx.setTransform.apply(ctx, this.baseTransform);
|
|
|
|
ctx.transform.apply(ctx, this.matrix);
|
|
|
|
this.scaleToContext();
|
|
|
|
|
|
|
|
return ctx.createPattern(temporaryPatternCanvas, 'repeat');
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2014-01-26 03:18:22 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
return TilingPattern;
|
|
|
|
})();
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2017-04-02 21:25:33 +09:00
|
|
|
export {
|
|
|
|
getShadingPatternFromIR,
|
|
|
|
TilingPattern,
|
|
|
|
};
|