mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
This commit is contained in:
parent
8ec1dfde49
commit
de36b2aaba
205 changed files with 40024 additions and 31859 deletions
|
@ -15,11 +15,17 @@
|
|||
/* eslint-disable no-multi-spaces */
|
||||
|
||||
import {
|
||||
assert, FormatError, info, unreachable, UNSUPPORTED_FEATURES, Util, warn
|
||||
} from '../shared/util';
|
||||
import { ColorSpace } from './colorspace';
|
||||
import { isStream } from './primitives';
|
||||
import { MissingDataException } from './core_utils';
|
||||
assert,
|
||||
FormatError,
|
||||
info,
|
||||
unreachable,
|
||||
UNSUPPORTED_FEATURES,
|
||||
Util,
|
||||
warn,
|
||||
} from "../shared/util";
|
||||
import { ColorSpace } from "./colorspace";
|
||||
import { isStream } from "./primitives";
|
||||
import { MissingDataException } from "./core_utils";
|
||||
|
||||
var ShadingType = {
|
||||
FUNCTION_BASED: 1,
|
||||
|
@ -34,7 +40,7 @@ var ShadingType = {
|
|||
var Pattern = (function PatternClosure() {
|
||||
// Constructor should define this.getPattern
|
||||
function Pattern() {
|
||||
unreachable('should not call Pattern constructor');
|
||||
unreachable("should not call Pattern constructor");
|
||||
}
|
||||
|
||||
Pattern.prototype = {
|
||||
|
@ -45,33 +51,50 @@ var Pattern = (function PatternClosure() {
|
|||
},
|
||||
};
|
||||
|
||||
Pattern.parseShading = function(shading, matrix, xref, res, handler,
|
||||
pdfFunctionFactory) {
|
||||
Pattern.parseShading = function(
|
||||
shading,
|
||||
matrix,
|
||||
xref,
|
||||
res,
|
||||
handler,
|
||||
pdfFunctionFactory
|
||||
) {
|
||||
var dict = isStream(shading) ? shading.dict : shading;
|
||||
var type = dict.get('ShadingType');
|
||||
var type = dict.get("ShadingType");
|
||||
|
||||
try {
|
||||
switch (type) {
|
||||
case ShadingType.AXIAL:
|
||||
case ShadingType.RADIAL:
|
||||
// Both radial and axial shadings are handled by RadialAxial shading.
|
||||
return new Shadings.RadialAxial(dict, matrix, xref, res,
|
||||
pdfFunctionFactory);
|
||||
return new Shadings.RadialAxial(
|
||||
dict,
|
||||
matrix,
|
||||
xref,
|
||||
res,
|
||||
pdfFunctionFactory
|
||||
);
|
||||
case ShadingType.FREE_FORM_MESH:
|
||||
case ShadingType.LATTICE_FORM_MESH:
|
||||
case ShadingType.COONS_PATCH_MESH:
|
||||
case ShadingType.TENSOR_PATCH_MESH:
|
||||
return new Shadings.Mesh(shading, matrix, xref, res,
|
||||
pdfFunctionFactory);
|
||||
return new Shadings.Mesh(
|
||||
shading,
|
||||
matrix,
|
||||
xref,
|
||||
res,
|
||||
pdfFunctionFactory
|
||||
);
|
||||
default:
|
||||
throw new FormatError('Unsupported ShadingType: ' + type);
|
||||
throw new FormatError("Unsupported ShadingType: " + type);
|
||||
}
|
||||
} catch (ex) {
|
||||
if (ex instanceof MissingDataException) {
|
||||
throw ex;
|
||||
}
|
||||
handler.send('UnsupportedFeature',
|
||||
{ featureId: UNSUPPORTED_FEATURES.shadingPattern, });
|
||||
handler.send("UnsupportedFeature", {
|
||||
featureId: UNSUPPORTED_FEATURES.shadingPattern,
|
||||
});
|
||||
warn(ex);
|
||||
return new Shadings.Dummy();
|
||||
}
|
||||
|
@ -90,35 +113,39 @@ Shadings.SMALL_NUMBER = 1e-6;
|
|||
Shadings.RadialAxial = (function RadialAxialClosure() {
|
||||
function RadialAxial(dict, matrix, xref, res, pdfFunctionFactory) {
|
||||
this.matrix = matrix;
|
||||
this.coordsArr = dict.getArray('Coords');
|
||||
this.shadingType = dict.get('ShadingType');
|
||||
this.type = 'Pattern';
|
||||
var cs = dict.get('ColorSpace', 'CS');
|
||||
this.coordsArr = dict.getArray("Coords");
|
||||
this.shadingType = dict.get("ShadingType");
|
||||
this.type = "Pattern";
|
||||
var cs = dict.get("ColorSpace", "CS");
|
||||
cs = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
this.cs = cs;
|
||||
const bbox = dict.getArray('BBox');
|
||||
const bbox = dict.getArray("BBox");
|
||||
if (Array.isArray(bbox) && bbox.length === 4) {
|
||||
this.bbox = Util.normalizeRect(bbox);
|
||||
} else {
|
||||
this.bbox = null;
|
||||
}
|
||||
|
||||
var t0 = 0.0, t1 = 1.0;
|
||||
if (dict.has('Domain')) {
|
||||
var domainArr = dict.getArray('Domain');
|
||||
var t0 = 0.0,
|
||||
t1 = 1.0;
|
||||
if (dict.has("Domain")) {
|
||||
var domainArr = dict.getArray("Domain");
|
||||
t0 = domainArr[0];
|
||||
t1 = domainArr[1];
|
||||
}
|
||||
|
||||
var extendStart = false, extendEnd = false;
|
||||
if (dict.has('Extend')) {
|
||||
var extendArr = dict.getArray('Extend');
|
||||
var extendStart = false,
|
||||
extendEnd = false;
|
||||
if (dict.has("Extend")) {
|
||||
var extendArr = dict.getArray("Extend");
|
||||
extendStart = extendArr[0];
|
||||
extendEnd = extendArr[1];
|
||||
}
|
||||
|
||||
if (this.shadingType === ShadingType.RADIAL &&
|
||||
(!extendStart || !extendEnd)) {
|
||||
if (
|
||||
this.shadingType === ShadingType.RADIAL &&
|
||||
(!extendStart || !extendEnd)
|
||||
) {
|
||||
// Radial gradient only currently works if either circle is fully within
|
||||
// the other circle.
|
||||
var x1 = this.coordsArr[0];
|
||||
|
@ -128,16 +155,15 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
|
|||
var y2 = this.coordsArr[4];
|
||||
var r2 = this.coordsArr[5];
|
||||
var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
|
||||
if (r1 <= r2 + distance &&
|
||||
r2 <= r1 + distance) {
|
||||
warn('Unsupported radial gradient.');
|
||||
if (r1 <= r2 + distance && r2 <= r1 + distance) {
|
||||
warn("Unsupported radial gradient.");
|
||||
}
|
||||
}
|
||||
|
||||
this.extendStart = extendStart;
|
||||
this.extendEnd = extendEnd;
|
||||
|
||||
var fnObj = dict.get('Function');
|
||||
var fnObj = dict.get("Function");
|
||||
var fn = pdfFunctionFactory.createFromArray(fnObj);
|
||||
|
||||
// 10 samples seems good enough for now, but probably won't work
|
||||
|
@ -146,17 +172,18 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
|
|||
const NUMBER_OF_SAMPLES = 10;
|
||||
const step = (t1 - t0) / NUMBER_OF_SAMPLES;
|
||||
|
||||
var colorStops = this.colorStops = [];
|
||||
var colorStops = (this.colorStops = []);
|
||||
|
||||
// Protect against bad domains.
|
||||
if (t0 >= t1 || step <= 0) {
|
||||
// Acrobat doesn't seem to handle these cases so we'll ignore for
|
||||
// now.
|
||||
info('Bad shading domain.');
|
||||
info("Bad shading domain.");
|
||||
return;
|
||||
}
|
||||
|
||||
var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
|
||||
var color = new Float32Array(cs.numComps),
|
||||
ratio = new Float32Array(1);
|
||||
var rgbColor;
|
||||
for (let i = 0; i <= NUMBER_OF_SAMPLES; i++) {
|
||||
ratio[0] = t0 + i * step;
|
||||
|
@ -166,9 +193,9 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
|
|||
colorStops.push([i / NUMBER_OF_SAMPLES, cssColor]);
|
||||
}
|
||||
|
||||
var background = 'transparent';
|
||||
if (dict.has('Background')) {
|
||||
rgbColor = cs.getRgb(dict.get('Background'), 0);
|
||||
var background = "transparent";
|
||||
if (dict.has("Background")) {
|
||||
rgbColor = cs.getRgb(dict.get("Background"), 0);
|
||||
background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
|
||||
}
|
||||
|
||||
|
@ -197,13 +224,13 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
|
|||
p1 = [coordsArr[2], coordsArr[3]];
|
||||
r0 = null;
|
||||
r1 = null;
|
||||
type = 'axial';
|
||||
type = "axial";
|
||||
} else if (shadingType === ShadingType.RADIAL) {
|
||||
p0 = [coordsArr[0], coordsArr[1]];
|
||||
p1 = [coordsArr[3], coordsArr[4]];
|
||||
r0 = coordsArr[2];
|
||||
r1 = coordsArr[5];
|
||||
type = 'radial';
|
||||
type = "radial";
|
||||
} else {
|
||||
unreachable(`getPattern type unknown: ${shadingType}`);
|
||||
}
|
||||
|
@ -219,7 +246,7 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
|
|||
}
|
||||
}
|
||||
|
||||
return ['RadialAxial', type, this.bbox, this.colorStops, p0, p1, r0, r1];
|
||||
return ["RadialAxial", type, this.bbox, this.colorStops, p0, p1, r0, r1];
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -238,8 +265,9 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
var numComps = context.numComps;
|
||||
this.tmpCompsBuf = new Float32Array(numComps);
|
||||
var csNumComps = context.colorSpace.numComps;
|
||||
this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
|
||||
this.tmpCompsBuf;
|
||||
this.tmpCsCompsBuf = context.colorFn
|
||||
? new Float32Array(csNumComps)
|
||||
: this.tmpCompsBuf;
|
||||
}
|
||||
MeshStreamReader.prototype = {
|
||||
get hasData() {
|
||||
|
@ -262,16 +290,26 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
var bufferLength = this.bufferLength;
|
||||
if (n === 32) {
|
||||
if (bufferLength === 0) {
|
||||
return ((this.stream.getByte() << 24) |
|
||||
(this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
|
||||
this.stream.getByte()) >>> 0;
|
||||
return (
|
||||
((this.stream.getByte() << 24) |
|
||||
(this.stream.getByte() << 16) |
|
||||
(this.stream.getByte() << 8) |
|
||||
this.stream.getByte()) >>>
|
||||
0
|
||||
);
|
||||
}
|
||||
buffer = (buffer << 24) | (this.stream.getByte() << 16) |
|
||||
(this.stream.getByte() << 8) | this.stream.getByte();
|
||||
buffer =
|
||||
(buffer << 24) |
|
||||
(this.stream.getByte() << 16) |
|
||||
(this.stream.getByte() << 8) |
|
||||
this.stream.getByte();
|
||||
var nextByte = this.stream.getByte();
|
||||
this.buffer = nextByte & ((1 << bufferLength) - 1);
|
||||
return ((buffer << (8 - bufferLength)) |
|
||||
((nextByte & 0xFF) >> bufferLength)) >>> 0;
|
||||
return (
|
||||
((buffer << (8 - bufferLength)) |
|
||||
((nextByte & 0xff) >> bufferLength)) >>>
|
||||
0
|
||||
);
|
||||
}
|
||||
if (n === 8 && bufferLength === 0) {
|
||||
return this.stream.getByte();
|
||||
|
@ -297,18 +335,22 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
var xi = this.readBits(bitsPerCoordinate);
|
||||
var yi = this.readBits(bitsPerCoordinate);
|
||||
var decode = this.context.decode;
|
||||
var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
|
||||
2.3283064365386963e-10; // 2 ^ -32
|
||||
var scale =
|
||||
bitsPerCoordinate < 32
|
||||
? 1 / ((1 << bitsPerCoordinate) - 1)
|
||||
: 2.3283064365386963e-10; // 2 ^ -32
|
||||
return [
|
||||
xi * scale * (decode[1] - decode[0]) + decode[0],
|
||||
yi * scale * (decode[3] - decode[2]) + decode[2]
|
||||
yi * scale * (decode[3] - decode[2]) + decode[2],
|
||||
];
|
||||
},
|
||||
readComponents: function MeshStreamReader_readComponents() {
|
||||
var numComps = this.context.numComps;
|
||||
var bitsPerComponent = this.context.bitsPerComponent;
|
||||
var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
|
||||
2.3283064365386963e-10; // 2 ^ -32
|
||||
var scale =
|
||||
bitsPerComponent < 32
|
||||
? 1 / ((1 << bitsPerComponent) - 1)
|
||||
: 2.3283064365386963e-10; // 2 ^ -32
|
||||
var decode = this.context.decode;
|
||||
var components = this.tmpCompsBuf;
|
||||
for (var i = 0, j = 4; i < numComps; i++, j += 2) {
|
||||
|
@ -333,9 +375,10 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
var f = reader.readFlag();
|
||||
var coord = reader.readCoordinate();
|
||||
var color = reader.readComponents();
|
||||
if (verticesLeft === 0) { // ignoring flags if we started a triangle
|
||||
if (verticesLeft === 0) {
|
||||
// ignoring flags if we started a triangle
|
||||
if (!(0 <= f && f <= 2)) {
|
||||
throw new FormatError('Unknown type4 flag');
|
||||
throw new FormatError("Unknown type4 flag");
|
||||
}
|
||||
switch (f) {
|
||||
case 0:
|
||||
|
@ -360,7 +403,7 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
reader.align();
|
||||
}
|
||||
mesh.figures.push({
|
||||
type: 'triangles',
|
||||
type: "triangles",
|
||||
coords: new Int32Array(ps),
|
||||
colors: new Int32Array(ps),
|
||||
});
|
||||
|
@ -378,7 +421,7 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
colors.push(color);
|
||||
}
|
||||
mesh.figures.push({
|
||||
type: 'lattice',
|
||||
type: "lattice",
|
||||
coords: new Int32Array(ps),
|
||||
colors: new Int32Array(ps),
|
||||
verticesPerRow,
|
||||
|
@ -394,9 +437,16 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
function buildB(count) {
|
||||
var lut = [];
|
||||
for (var i = 0; i <= count; i++) {
|
||||
var t = i / count, t_ = 1 - t;
|
||||
lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
|
||||
3 * t * t * t_, t * t * t]));
|
||||
var t = i / count,
|
||||
t_ = 1 - t;
|
||||
lut.push(
|
||||
new Float32Array([
|
||||
t_ * t_ * t_,
|
||||
3 * t * t_ * t_,
|
||||
3 * t * t * t_,
|
||||
t * t * t,
|
||||
])
|
||||
);
|
||||
}
|
||||
return lut;
|
||||
}
|
||||
|
@ -411,37 +461,66 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
|
||||
function buildFigureFromPatch(mesh, index) {
|
||||
var figure = mesh.figures[index];
|
||||
assert(figure.type === 'patch', 'Unexpected patch mesh figure');
|
||||
assert(figure.type === "patch", "Unexpected patch mesh figure");
|
||||
|
||||
var coords = mesh.coords, colors = mesh.colors;
|
||||
var coords = mesh.coords,
|
||||
colors = mesh.colors;
|
||||
var pi = figure.coords;
|
||||
var ci = figure.colors;
|
||||
|
||||
var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
|
||||
coords[pi[12]][0], coords[pi[15]][0]);
|
||||
var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
|
||||
coords[pi[12]][1], coords[pi[15]][1]);
|
||||
var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
|
||||
coords[pi[12]][0], coords[pi[15]][0]);
|
||||
var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
|
||||
coords[pi[12]][1], coords[pi[15]][1]);
|
||||
var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
|
||||
(mesh.bounds[2] - mesh.bounds[0]));
|
||||
splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
|
||||
Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
|
||||
var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
|
||||
(mesh.bounds[3] - mesh.bounds[1]));
|
||||
splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
|
||||
Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
|
||||
var figureMinX = Math.min(
|
||||
coords[pi[0]][0],
|
||||
coords[pi[3]][0],
|
||||
coords[pi[12]][0],
|
||||
coords[pi[15]][0]
|
||||
);
|
||||
var figureMinY = Math.min(
|
||||
coords[pi[0]][1],
|
||||
coords[pi[3]][1],
|
||||
coords[pi[12]][1],
|
||||
coords[pi[15]][1]
|
||||
);
|
||||
var figureMaxX = Math.max(
|
||||
coords[pi[0]][0],
|
||||
coords[pi[3]][0],
|
||||
coords[pi[12]][0],
|
||||
coords[pi[15]][0]
|
||||
);
|
||||
var figureMaxY = Math.max(
|
||||
coords[pi[0]][1],
|
||||
coords[pi[3]][1],
|
||||
coords[pi[12]][1],
|
||||
coords[pi[15]][1]
|
||||
);
|
||||
var splitXBy = Math.ceil(
|
||||
((figureMaxX - figureMinX) * TRIANGLE_DENSITY) /
|
||||
(mesh.bounds[2] - mesh.bounds[0])
|
||||
);
|
||||
splitXBy = Math.max(
|
||||
MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
|
||||
Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy)
|
||||
);
|
||||
var splitYBy = Math.ceil(
|
||||
((figureMaxY - figureMinY) * TRIANGLE_DENSITY) /
|
||||
(mesh.bounds[3] - mesh.bounds[1])
|
||||
);
|
||||
splitYBy = Math.max(
|
||||
MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
|
||||
Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy)
|
||||
);
|
||||
|
||||
var verticesPerRow = splitXBy + 1;
|
||||
var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
|
||||
var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
|
||||
var k = 0;
|
||||
var cl = new Uint8Array(3), cr = new Uint8Array(3);
|
||||
var c0 = colors[ci[0]], c1 = colors[ci[1]],
|
||||
c2 = colors[ci[2]], c3 = colors[ci[3]];
|
||||
var bRow = getB(splitYBy), bCol = getB(splitXBy);
|
||||
var cl = new Uint8Array(3),
|
||||
cr = new Uint8Array(3);
|
||||
var c0 = colors[ci[0]],
|
||||
c1 = colors[ci[1]],
|
||||
c2 = colors[ci[2]],
|
||||
c3 = colors[ci[3]];
|
||||
var bRow = getB(splitYBy),
|
||||
bCol = getB(splitXBy);
|
||||
for (var row = 0; row <= splitYBy; row++) {
|
||||
cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
|
||||
cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
|
||||
|
@ -452,11 +531,14 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
|
||||
|
||||
for (var col = 0; col <= splitXBy; col++, k++) {
|
||||
if ((row === 0 || row === splitYBy) &&
|
||||
(col === 0 || col === splitXBy)) {
|
||||
if (
|
||||
(row === 0 || row === splitYBy) &&
|
||||
(col === 0 || col === splitXBy)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
var x = 0, y = 0;
|
||||
var x = 0,
|
||||
y = 0;
|
||||
var q = 0;
|
||||
for (var i = 0; i <= 3; i++) {
|
||||
for (var j = 0; j <= 3; j++, q++) {
|
||||
|
@ -485,7 +567,7 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
|
||||
|
||||
mesh.figures[index] = {
|
||||
type: 'lattice',
|
||||
type: "lattice",
|
||||
coords: figureCoords,
|
||||
colors: figureColors,
|
||||
verticesPerRow,
|
||||
|
@ -501,15 +583,15 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
while (reader.hasData) {
|
||||
var f = reader.readFlag();
|
||||
if (!(0 <= f && f <= 3)) {
|
||||
throw new FormatError('Unknown type6 flag');
|
||||
throw new FormatError("Unknown type6 flag");
|
||||
}
|
||||
var i, ii;
|
||||
var pi = coords.length;
|
||||
for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
|
||||
for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
|
||||
coords.push(reader.readCoordinate());
|
||||
}
|
||||
var ci = colors.length;
|
||||
for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
|
||||
for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
|
||||
colors.push(reader.readComponents());
|
||||
}
|
||||
var tmp1, tmp2, tmp3, tmp4;
|
||||
|
@ -559,50 +641,66 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
// set p11, p12, p21, p22
|
||||
ps[5] = coords.length;
|
||||
coords.push([
|
||||
(-4 * coords[ps[0]][0] - coords[ps[15]][0] +
|
||||
(-4 * coords[ps[0]][0] -
|
||||
coords[ps[15]][0] +
|
||||
6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
|
||||
2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
|
||||
3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
|
||||
(-4 * coords[ps[0]][1] - coords[ps[15]][1] +
|
||||
3 * (coords[ps[13]][0] + coords[ps[7]][0])) /
|
||||
9,
|
||||
(-4 * coords[ps[0]][1] -
|
||||
coords[ps[15]][1] +
|
||||
6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
|
||||
2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
|
||||
3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
|
||||
3 * (coords[ps[13]][1] + coords[ps[7]][1])) /
|
||||
9,
|
||||
]);
|
||||
ps[6] = coords.length;
|
||||
coords.push([
|
||||
(-4 * coords[ps[3]][0] - coords[ps[12]][0] +
|
||||
(-4 * coords[ps[3]][0] -
|
||||
coords[ps[12]][0] +
|
||||
6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
|
||||
2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
|
||||
3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
|
||||
(-4 * coords[ps[3]][1] - coords[ps[12]][1] +
|
||||
3 * (coords[ps[4]][0] + coords[ps[14]][0])) /
|
||||
9,
|
||||
(-4 * coords[ps[3]][1] -
|
||||
coords[ps[12]][1] +
|
||||
6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
|
||||
2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
|
||||
3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
|
||||
3 * (coords[ps[4]][1] + coords[ps[14]][1])) /
|
||||
9,
|
||||
]);
|
||||
ps[9] = coords.length;
|
||||
coords.push([
|
||||
(-4 * coords[ps[12]][0] - coords[ps[3]][0] +
|
||||
(-4 * coords[ps[12]][0] -
|
||||
coords[ps[3]][0] +
|
||||
6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
|
||||
2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
|
||||
3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
|
||||
(-4 * coords[ps[12]][1] - coords[ps[3]][1] +
|
||||
3 * (coords[ps[11]][0] + coords[ps[1]][0])) /
|
||||
9,
|
||||
(-4 * coords[ps[12]][1] -
|
||||
coords[ps[3]][1] +
|
||||
6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
|
||||
2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
|
||||
3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
|
||||
3 * (coords[ps[11]][1] + coords[ps[1]][1])) /
|
||||
9,
|
||||
]);
|
||||
ps[10] = coords.length;
|
||||
coords.push([
|
||||
(-4 * coords[ps[15]][0] - coords[ps[0]][0] +
|
||||
(-4 * coords[ps[15]][0] -
|
||||
coords[ps[0]][0] +
|
||||
6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
|
||||
2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
|
||||
3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
|
||||
(-4 * coords[ps[15]][1] - coords[ps[0]][1] +
|
||||
3 * (coords[ps[2]][0] + coords[ps[8]][0])) /
|
||||
9,
|
||||
(-4 * coords[ps[15]][1] -
|
||||
coords[ps[0]][1] +
|
||||
6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
|
||||
2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
|
||||
3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
|
||||
3 * (coords[ps[2]][1] + coords[ps[8]][1])) /
|
||||
9,
|
||||
]);
|
||||
mesh.figures.push({
|
||||
type: 'patch',
|
||||
type: "patch",
|
||||
coords: new Int32Array(ps), // making copies of ps and cs
|
||||
colors: new Int32Array(cs),
|
||||
});
|
||||
|
@ -617,15 +715,15 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
while (reader.hasData) {
|
||||
var f = reader.readFlag();
|
||||
if (!(0 <= f && f <= 3)) {
|
||||
throw new FormatError('Unknown type7 flag');
|
||||
throw new FormatError("Unknown type7 flag");
|
||||
}
|
||||
var i, ii;
|
||||
var pi = coords.length;
|
||||
for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
|
||||
for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
|
||||
coords.push(reader.readCoordinate());
|
||||
}
|
||||
var ci = colors.length;
|
||||
for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
|
||||
for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
|
||||
colors.push(reader.readComponents());
|
||||
}
|
||||
var tmp1, tmp2, tmp3, tmp4;
|
||||
|
@ -673,7 +771,7 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
break;
|
||||
}
|
||||
mesh.figures.push({
|
||||
type: 'patch',
|
||||
type: "patch",
|
||||
coords: new Int32Array(ps), // making copies of ps and cs
|
||||
colors: new Int32Array(cs),
|
||||
});
|
||||
|
@ -681,10 +779,13 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
}
|
||||
|
||||
function updateBounds(mesh) {
|
||||
var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
|
||||
maxX = minX, maxY = minY;
|
||||
var minX = mesh.coords[0][0],
|
||||
minY = mesh.coords[0][1],
|
||||
maxX = minX,
|
||||
maxY = minY;
|
||||
for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
|
||||
var x = mesh.coords[i][0], y = mesh.coords[i][1];
|
||||
var x = mesh.coords[i][0],
|
||||
y = mesh.coords[i][1];
|
||||
minX = minX > x ? x : minX;
|
||||
minY = minY > y ? y : minY;
|
||||
maxX = maxX < x ? x : maxX;
|
||||
|
@ -717,7 +818,9 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
|
||||
var figures = mesh.figures;
|
||||
for (i = 0, ii = figures.length; i < ii; i++) {
|
||||
var figure = figures[i], ps = figure.coords, cs = figure.colors;
|
||||
var figure = figures[i],
|
||||
ps = figure.coords,
|
||||
cs = figure.colors;
|
||||
for (j = 0, jj = ps.length; j < jj; j++) {
|
||||
ps[j] *= 2;
|
||||
cs[j] *= 3;
|
||||
|
@ -727,25 +830,26 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
|
||||
function Mesh(stream, matrix, xref, res, pdfFunctionFactory) {
|
||||
if (!isStream(stream)) {
|
||||
throw new FormatError('Mesh data is not a stream');
|
||||
throw new FormatError("Mesh data is not a stream");
|
||||
}
|
||||
var dict = stream.dict;
|
||||
this.matrix = matrix;
|
||||
this.shadingType = dict.get('ShadingType');
|
||||
this.type = 'Pattern';
|
||||
const bbox = dict.getArray('BBox');
|
||||
this.shadingType = dict.get("ShadingType");
|
||||
this.type = "Pattern";
|
||||
const bbox = dict.getArray("BBox");
|
||||
if (Array.isArray(bbox) && bbox.length === 4) {
|
||||
this.bbox = Util.normalizeRect(bbox);
|
||||
} else {
|
||||
this.bbox = null;
|
||||
}
|
||||
var cs = dict.get('ColorSpace', 'CS');
|
||||
var cs = dict.get("ColorSpace", "CS");
|
||||
cs = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
|
||||
this.cs = cs;
|
||||
this.background = dict.has('Background') ?
|
||||
cs.getRgb(dict.get('Background'), 0) : null;
|
||||
this.background = dict.has("Background")
|
||||
? cs.getRgb(dict.get("Background"), 0)
|
||||
: null;
|
||||
|
||||
var fnObj = dict.get('Function');
|
||||
var fnObj = dict.get("Function");
|
||||
var fn = fnObj ? pdfFunctionFactory.createFromArray(fnObj) : null;
|
||||
|
||||
this.coords = [];
|
||||
|
@ -753,10 +857,10 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
this.figures = [];
|
||||
|
||||
var decodeContext = {
|
||||
bitsPerCoordinate: dict.get('BitsPerCoordinate'),
|
||||
bitsPerComponent: dict.get('BitsPerComponent'),
|
||||
bitsPerFlag: dict.get('BitsPerFlag'),
|
||||
decode: dict.getArray('Decode'),
|
||||
bitsPerCoordinate: dict.get("BitsPerCoordinate"),
|
||||
bitsPerComponent: dict.get("BitsPerComponent"),
|
||||
bitsPerFlag: dict.get("BitsPerFlag"),
|
||||
decode: dict.getArray("Decode"),
|
||||
colorFn: fn,
|
||||
colorSpace: cs,
|
||||
numComps: fn ? 1 : cs.numComps,
|
||||
|
@ -769,9 +873,9 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
decodeType4Shading(this, reader);
|
||||
break;
|
||||
case ShadingType.LATTICE_FORM_MESH:
|
||||
var verticesPerRow = dict.get('VerticesPerRow') | 0;
|
||||
var verticesPerRow = dict.get("VerticesPerRow") | 0;
|
||||
if (verticesPerRow < 2) {
|
||||
throw new FormatError('Invalid VerticesPerRow');
|
||||
throw new FormatError("Invalid VerticesPerRow");
|
||||
}
|
||||
decodeType5Shading(this, reader, verticesPerRow);
|
||||
break;
|
||||
|
@ -784,7 +888,7 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
patchMesh = true;
|
||||
break;
|
||||
default:
|
||||
unreachable('Unsupported mesh type.');
|
||||
unreachable("Unsupported mesh type.");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -803,8 +907,17 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
|
||||
Mesh.prototype = {
|
||||
getIR: function Mesh_getIR() {
|
||||
return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
|
||||
this.bounds, this.matrix, this.bbox, this.background];
|
||||
return [
|
||||
"Mesh",
|
||||
this.shadingType,
|
||||
this.coords,
|
||||
this.colors,
|
||||
this.figures,
|
||||
this.bounds,
|
||||
this.matrix,
|
||||
this.bbox,
|
||||
this.background,
|
||||
];
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -813,38 +926,42 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
|
||||
Shadings.Dummy = (function DummyClosure() {
|
||||
function Dummy() {
|
||||
this.type = 'Pattern';
|
||||
this.type = "Pattern";
|
||||
}
|
||||
|
||||
Dummy.prototype = {
|
||||
getIR: function Dummy_getIR() {
|
||||
return ['Dummy'];
|
||||
return ["Dummy"];
|
||||
},
|
||||
};
|
||||
return Dummy;
|
||||
})();
|
||||
|
||||
function getTilingPatternIR(operatorList, dict, args) {
|
||||
let matrix = dict.getArray('Matrix');
|
||||
let bbox = Util.normalizeRect(dict.getArray('BBox'));
|
||||
let xstep = dict.get('XStep');
|
||||
let ystep = dict.get('YStep');
|
||||
let paintType = dict.get('PaintType');
|
||||
let tilingType = dict.get('TilingType');
|
||||
let matrix = dict.getArray("Matrix");
|
||||
let bbox = Util.normalizeRect(dict.getArray("BBox"));
|
||||
let xstep = dict.get("XStep");
|
||||
let ystep = dict.get("YStep");
|
||||
let paintType = dict.get("PaintType");
|
||||
let tilingType = dict.get("TilingType");
|
||||
|
||||
// Ensure that the pattern has a non-zero width and height, to prevent errors
|
||||
// in `pattern_helper.js` (fixes issue8330.pdf).
|
||||
if ((bbox[2] - bbox[0]) === 0 || (bbox[3] - bbox[1]) === 0) {
|
||||
if (bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) {
|
||||
throw new FormatError(`Invalid getTilingPatternIR /BBox array: [${bbox}].`);
|
||||
}
|
||||
|
||||
return [
|
||||
'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
|
||||
paintType, tilingType
|
||||
"TilingPattern",
|
||||
args,
|
||||
operatorList,
|
||||
matrix,
|
||||
bbox,
|
||||
xstep,
|
||||
ystep,
|
||||
paintType,
|
||||
tilingType,
|
||||
];
|
||||
}
|
||||
|
||||
export {
|
||||
Pattern,
|
||||
getTilingPatternIR,
|
||||
};
|
||||
export { Pattern, getTilingPatternIR };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue