2011-10-28 03:51:10 +09:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
2012-09-01 07:48:21 +09:00
|
|
|
/* Copyright 2012 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.
|
|
|
|
*/
|
2013-02-03 07:49:19 +09:00
|
|
|
/* globals ColorSpace, DeviceCmykCS, DeviceGrayCS, DeviceRgbCS, error,
|
|
|
|
FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageData, isArray, isNum,
|
2013-04-17 07:45:29 +09:00
|
|
|
isString, Pattern, TilingPattern, TODO, Util, warn, assert, info */
|
2011-10-26 10:18:22 +09:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2011-10-28 03:51:10 +09:00
|
|
|
// <canvas> contexts store most of the state we need natively.
|
|
|
|
// However, PDF needs a bit more state, which we store here.
|
|
|
|
|
2011-12-03 13:30:31 +09:00
|
|
|
var TextRenderingMode = {
|
|
|
|
FILL: 0,
|
|
|
|
STROKE: 1,
|
|
|
|
FILL_STROKE: 2,
|
|
|
|
INVISIBLE: 3,
|
|
|
|
FILL_ADD_TO_PATH: 4,
|
|
|
|
STROKE_ADD_TO_PATH: 5,
|
|
|
|
FILL_STROKE_ADD_TO_PATH: 6,
|
2012-10-13 12:33:56 +09:00
|
|
|
ADD_TO_PATH: 7,
|
2013-05-16 05:57:27 +09:00
|
|
|
FILL_STROKE_MASK: 3,
|
2012-10-13 12:33:56 +09:00
|
|
|
ADD_TO_PATH_FLAG: 4
|
2011-12-03 13:30:31 +09:00
|
|
|
};
|
|
|
|
|
2012-02-05 05:42:07 +09:00
|
|
|
// Minimal font size that would be used during canvas fillText operations.
|
2013-04-17 00:18:07 +09:00
|
|
|
var MIN_FONT_SIZE = 16;
|
2012-02-05 03:45:18 +09:00
|
|
|
|
2013-05-11 12:50:14 +09:00
|
|
|
var COMPILE_TYPE3_GLYPHS = true;
|
|
|
|
|
2012-02-23 23:46:00 +09:00
|
|
|
function createScratchCanvas(width, height) {
|
2011-10-25 08:55:23 +09:00
|
|
|
var canvas = document.createElement('canvas');
|
|
|
|
canvas.width = width;
|
|
|
|
canvas.height = height;
|
|
|
|
return canvas;
|
|
|
|
}
|
|
|
|
|
2011-11-27 17:22:08 +09:00
|
|
|
function addContextCurrentTransform(ctx) {
|
2011-11-23 05:00:04 +09:00
|
|
|
// If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
|
|
|
|
if (!ctx.mozCurrentTransform) {
|
|
|
|
// Store the original context
|
2013-01-16 09:40:39 +09:00
|
|
|
ctx._scaleX = ctx._scaleX || 1.0;
|
|
|
|
ctx._scaleY = ctx._scaleY || 1.0;
|
2011-11-23 05:00:04 +09:00
|
|
|
ctx._originalSave = ctx.save;
|
|
|
|
ctx._originalRestore = ctx.restore;
|
|
|
|
ctx._originalRotate = ctx.rotate;
|
|
|
|
ctx._originalScale = ctx.scale;
|
|
|
|
ctx._originalTranslate = ctx.translate;
|
|
|
|
ctx._originalTransform = ctx.transform;
|
2013-05-01 02:01:01 +09:00
|
|
|
ctx._originalSetTransform = ctx.setTransform;
|
2011-11-23 05:00:04 +09:00
|
|
|
|
2013-01-16 09:40:39 +09:00
|
|
|
ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
|
2011-11-23 05:00:04 +09:00
|
|
|
ctx._transformStack = [];
|
|
|
|
|
2011-11-27 17:22:08 +09:00
|
|
|
Object.defineProperty(ctx, 'mozCurrentTransform', {
|
|
|
|
get: function getCurrentTransform() {
|
|
|
|
return this._transformMatrix;
|
|
|
|
}
|
2011-11-23 05:00:04 +09:00
|
|
|
});
|
|
|
|
|
2011-11-27 17:22:08 +09:00
|
|
|
Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
|
|
|
|
get: function getCurrentTransformInverse() {
|
2011-11-23 05:00:04 +09:00
|
|
|
// Calculation done using WolframAlpha:
|
|
|
|
// http://www.wolframalpha.com/input/?
|
|
|
|
// i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
|
|
|
|
|
|
|
|
var m = this._transformMatrix;
|
|
|
|
var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
|
|
|
|
|
2011-11-27 17:22:08 +09:00
|
|
|
var ad_bc = a * d - b * c;
|
|
|
|
var bc_ad = b * c - a * d;
|
|
|
|
|
2011-11-23 05:00:04 +09:00
|
|
|
return [
|
2011-11-27 17:22:08 +09:00
|
|
|
d / ad_bc,
|
|
|
|
b / bc_ad,
|
|
|
|
c / bc_ad,
|
|
|
|
a / ad_bc,
|
|
|
|
(d * e - c * f) / bc_ad,
|
|
|
|
(b * e - a * f) / ad_bc
|
2011-11-23 05:00:04 +09:00
|
|
|
];
|
|
|
|
}
|
2011-11-27 17:22:08 +09:00
|
|
|
});
|
2011-11-23 05:00:04 +09:00
|
|
|
|
|
|
|
ctx.save = function ctxSave() {
|
|
|
|
var old = this._transformMatrix;
|
|
|
|
this._transformStack.push(old);
|
|
|
|
this._transformMatrix = old.slice(0, 6);
|
|
|
|
|
|
|
|
this._originalSave();
|
|
|
|
};
|
|
|
|
|
|
|
|
ctx.restore = function ctxRestore() {
|
|
|
|
var prev = this._transformStack.pop();
|
|
|
|
if (prev) {
|
|
|
|
this._transformMatrix = prev;
|
|
|
|
this._originalRestore();
|
|
|
|
}
|
2011-11-27 17:22:08 +09:00
|
|
|
};
|
2011-11-23 05:00:04 +09:00
|
|
|
|
|
|
|
ctx.translate = function ctxTranslate(x, y) {
|
|
|
|
var m = this._transformMatrix;
|
|
|
|
m[4] = m[0] * x + m[2] * y + m[4];
|
|
|
|
m[5] = m[1] * x + m[3] * y + m[5];
|
|
|
|
|
|
|
|
this._originalTranslate(x, y);
|
2011-11-27 17:22:08 +09:00
|
|
|
};
|
2011-11-23 05:00:04 +09:00
|
|
|
|
|
|
|
ctx.scale = function ctxScale(x, y) {
|
|
|
|
var m = this._transformMatrix;
|
|
|
|
m[0] = m[0] * x;
|
|
|
|
m[1] = m[1] * x;
|
|
|
|
m[2] = m[2] * y;
|
|
|
|
m[3] = m[3] * y;
|
|
|
|
|
|
|
|
this._originalScale(x, y);
|
2011-11-27 17:22:08 +09:00
|
|
|
};
|
2011-11-23 05:00:04 +09:00
|
|
|
|
|
|
|
ctx.transform = function ctxTransform(a, b, c, d, e, f) {
|
|
|
|
var m = this._transformMatrix;
|
|
|
|
this._transformMatrix = [
|
|
|
|
m[0] * a + m[2] * b,
|
|
|
|
m[1] * a + m[3] * b,
|
|
|
|
m[0] * c + m[2] * d,
|
|
|
|
m[1] * c + m[3] * d,
|
|
|
|
m[0] * e + m[2] * f + m[4],
|
|
|
|
m[1] * e + m[3] * f + m[5]
|
|
|
|
];
|
|
|
|
|
|
|
|
ctx._originalTransform(a, b, c, d, e, f);
|
2011-11-27 17:22:08 +09:00
|
|
|
};
|
2011-11-23 05:00:04 +09:00
|
|
|
|
2013-05-01 02:01:01 +09:00
|
|
|
ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
|
|
|
|
this._transformMatrix = [a, b, c, d, e, f];
|
|
|
|
|
|
|
|
ctx._originalSetTransform(a, b, c, d, e, f);
|
|
|
|
};
|
|
|
|
|
2011-11-23 05:00:04 +09:00
|
|
|
ctx.rotate = function ctxRotate(angle) {
|
|
|
|
var cosValue = Math.cos(angle);
|
|
|
|
var sinValue = Math.sin(angle);
|
|
|
|
|
|
|
|
var m = this._transformMatrix;
|
|
|
|
this._transformMatrix = [
|
|
|
|
m[0] * cosValue + m[2] * sinValue,
|
|
|
|
m[1] * cosValue + m[3] * sinValue,
|
|
|
|
m[0] * (-sinValue) + m[2] * cosValue,
|
|
|
|
m[1] * (-sinValue) + m[3] * cosValue,
|
|
|
|
m[4],
|
|
|
|
m[5]
|
|
|
|
];
|
|
|
|
|
|
|
|
this._originalRotate(angle);
|
2011-11-27 17:22:08 +09:00
|
|
|
};
|
2011-11-23 05:00:04 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-11 12:50:14 +09:00
|
|
|
function compileType3Glyph(imgData) {
|
|
|
|
var POINT_TO_PROCESS_LIMIT = 1000;
|
|
|
|
|
|
|
|
var width = imgData.width, height = imgData.height;
|
|
|
|
var i, j;
|
|
|
|
// we need sparse arrays
|
|
|
|
var points = [];
|
|
|
|
for (i = 0; i <= height; i++) {
|
|
|
|
points.push([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// finding iteresting points: every point is located between mask pixels,
|
|
|
|
// so there will be points of the (width + 1)x(height + 1) grid. Every point
|
|
|
|
// will have flags assigned based on neighboring mask pixels:
|
|
|
|
// 4 | 8
|
|
|
|
// --P--
|
|
|
|
// 2 | 1
|
|
|
|
// We are interested only in points with the flags:
|
|
|
|
// - outside corners: 1, 2, 4, 8;
|
|
|
|
// - inside corners: 7, 11, 13, 14;
|
|
|
|
// - and, intersections: 5, 10.
|
|
|
|
var pos = 3, data = imgData.data, lineSize = width * 4, count = 0;
|
|
|
|
if (data[3] !== 0) {
|
|
|
|
points[0][0] = 1;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
for (j = 1; j < width; j++) {
|
|
|
|
if (data[pos] !== data[pos + 4]) {
|
|
|
|
points[0][j] = data[pos] ? 2 : 1;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
pos += 4;
|
|
|
|
}
|
|
|
|
if (data[pos] !== 0) {
|
|
|
|
points[0][j] = 2;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
pos += 4;
|
|
|
|
for (i = 1; i < height; i++) {
|
|
|
|
if (data[pos - lineSize] !== data[pos]) {
|
|
|
|
points[i][0] = data[pos] ? 1 : 8;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
for (j = 1; j < width; j++) {
|
|
|
|
var f1 = data[pos + 4] ? 1 : 0;
|
|
|
|
var f2 = data[pos] ? 1 : 0;
|
|
|
|
var f4 = data[pos - lineSize] ? 1 : 0;
|
|
|
|
var f8 = data[pos - lineSize + 4] ? 1 : 0;
|
|
|
|
var fSum = f1 + f2 + f4 + f8;
|
|
|
|
if (fSum === 1 || fSum === 3 || (fSum === 2 && f1 === f4)) {
|
|
|
|
points[i][j] = f1 | (f2 << 1) | (f4 << 2) | (f8 << 3);
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
pos += 4;
|
|
|
|
}
|
|
|
|
if (data[pos - lineSize] !== data[pos]) {
|
|
|
|
points[i][j] = data[pos] ? 2 : 4;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
pos += 4;
|
|
|
|
|
|
|
|
if (count > POINT_TO_PROCESS_LIMIT) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos -= lineSize;
|
|
|
|
if (data[pos] !== 0) {
|
|
|
|
points[i][0] = 8;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
for (j = 1; j < width; j++) {
|
|
|
|
if (data[pos] !== data[pos + 4]) {
|
|
|
|
points[i][j] = data[pos] ? 4 : 8;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
pos += 4;
|
|
|
|
}
|
|
|
|
if (data[pos] !== 0) {
|
|
|
|
points[i][j] = 4;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
if (count > POINT_TO_PROCESS_LIMIT) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// building outlines
|
|
|
|
var outline = [];
|
|
|
|
outline.push('c.save();');
|
|
|
|
// the path shall be painted in [0..1]x[0..1] space
|
|
|
|
outline.push('c.scale(' + (1 / width) + ',' + (-1 / height) + ');');
|
|
|
|
outline.push('c.translate(0,-' + height + ');');
|
|
|
|
outline.push('c.beginPath();');
|
|
|
|
for (i = 0; i <= height; i++) {
|
|
|
|
if (points[i].length === 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var js = null;
|
|
|
|
for (js in points[i]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (js === null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var i0 = i, j0 = (j = +js);
|
|
|
|
|
|
|
|
outline.push('c.moveTo(' + j + ',' + i + ');');
|
|
|
|
var type = points[i][j], d = 0;
|
|
|
|
do {
|
|
|
|
if (type === 5 || type === 10) {
|
|
|
|
// line crossed: following dirrection we followed
|
|
|
|
points[i0][j0] = type | (15 ^ d); // changing direction for "future hit"
|
|
|
|
type |= d;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 1:
|
|
|
|
case 13:
|
|
|
|
do { i0++; } while (!points[i0][j0]);
|
|
|
|
d = 9;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 7:
|
|
|
|
do { i0--; } while (!points[i0][j0]);
|
|
|
|
d = 6;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
case 14:
|
|
|
|
do { j0++; } while (!points[i0][j0]);
|
|
|
|
d = 12;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 11:
|
|
|
|
do { j0--; } while (!points[i0][j0]);
|
|
|
|
d = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
outline.push('c.lineTo(' + j0 + ',' + i0 + ');');
|
|
|
|
|
|
|
|
type = points[i0][j0];
|
|
|
|
delete points[i0][j0];
|
|
|
|
} while (j0 !== j || i0 !== i);
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
outline.push('c.fill();');
|
|
|
|
outline.push('c.beginPath();');
|
|
|
|
outline.push('c.restore();');
|
|
|
|
|
|
|
|
/*jshint -W054 */
|
|
|
|
return new Function('c', outline.join('\n'));
|
|
|
|
}
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
var CanvasExtraState = (function CanvasExtraStateClosure() {
|
|
|
|
function CanvasExtraState(old) {
|
|
|
|
// Are soft masks and alpha values shapes or opacities?
|
|
|
|
this.alphaIsShape = false;
|
|
|
|
this.fontSize = 0;
|
|
|
|
this.fontSizeScale = 1;
|
|
|
|
this.textMatrix = IDENTITY_MATRIX;
|
2013-01-04 09:39:06 +09:00
|
|
|
this.fontMatrix = FONT_IDENTITY_MATRIX;
|
2012-04-05 05:43:26 +09:00
|
|
|
this.leading = 0;
|
|
|
|
// Current point (in user coordinates)
|
|
|
|
this.x = 0;
|
|
|
|
this.y = 0;
|
|
|
|
// Start of text line (in text coordinates)
|
|
|
|
this.lineX = 0;
|
|
|
|
this.lineY = 0;
|
|
|
|
// Character and word spacing
|
|
|
|
this.charSpacing = 0;
|
|
|
|
this.wordSpacing = 0;
|
|
|
|
this.textHScale = 1;
|
|
|
|
this.textRenderingMode = TextRenderingMode.FILL;
|
2012-08-02 05:10:48 +09:00
|
|
|
this.textRise = 0;
|
2012-04-05 05:43:26 +09:00
|
|
|
// Color spaces
|
|
|
|
this.fillColorSpace = new DeviceGrayCS();
|
|
|
|
this.fillColorSpaceObj = null;
|
|
|
|
this.strokeColorSpace = new DeviceGrayCS();
|
|
|
|
this.strokeColorSpaceObj = null;
|
|
|
|
this.fillColorObj = null;
|
|
|
|
this.strokeColorObj = null;
|
|
|
|
// Default fore and background colors
|
|
|
|
this.fillColor = '#000000';
|
|
|
|
this.strokeColor = '#000000';
|
|
|
|
// Note: fill alpha applies to all non-stroking operations
|
|
|
|
this.fillAlpha = 1;
|
|
|
|
this.strokeAlpha = 1;
|
|
|
|
this.lineWidth = 1;
|
2012-10-27 13:30:01 +09:00
|
|
|
this.paintFormXObjectDepth = 0;
|
2012-04-05 05:43:26 +09:00
|
|
|
|
|
|
|
this.old = old;
|
|
|
|
}
|
|
|
|
|
|
|
|
CanvasExtraState.prototype = {
|
|
|
|
clone: function CanvasExtraState_clone() {
|
|
|
|
return Object.create(this);
|
|
|
|
},
|
|
|
|
setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return CanvasExtraState;
|
|
|
|
})();
|
|
|
|
|
2011-12-09 07:18:43 +09:00
|
|
|
var CanvasGraphics = (function CanvasGraphicsClosure() {
|
2012-03-13 02:41:40 +09:00
|
|
|
// Defines the time the executeOperatorList is going to be executing
|
2011-10-25 08:55:23 +09:00
|
|
|
// before it stops and shedules a continue of execution.
|
2012-11-10 06:34:11 +09:00
|
|
|
var EXECUTION_TIME = 15;
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2013-02-11 03:19:36 +09:00
|
|
|
function CanvasGraphics(canvasCtx, commonObjs, objs, textLayer, imageLayer) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx = canvasCtx;
|
|
|
|
this.current = new CanvasExtraState();
|
|
|
|
this.stateStack = [];
|
|
|
|
this.pendingClip = null;
|
2013-05-04 08:47:40 +09:00
|
|
|
this.pendingEOFill = false;
|
2011-10-25 08:55:23 +09:00
|
|
|
this.res = null;
|
|
|
|
this.xobjs = null;
|
2012-10-29 05:10:34 +09:00
|
|
|
this.commonObjs = commonObjs;
|
2011-10-25 08:55:23 +09:00
|
|
|
this.objs = objs;
|
2011-10-29 06:37:55 +09:00
|
|
|
this.textLayer = textLayer;
|
2013-02-11 03:19:36 +09:00
|
|
|
this.imageLayer = imageLayer;
|
2013-03-13 09:20:38 +09:00
|
|
|
this.groupStack = [];
|
2013-05-11 12:50:14 +09:00
|
|
|
this.processingType3 = null;
|
2011-11-23 05:00:04 +09:00
|
|
|
if (canvasCtx) {
|
2011-11-27 17:22:08 +09:00
|
|
|
addContextCurrentTransform(canvasCtx);
|
2011-11-23 05:00:04 +09:00
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
|
|
|
|
2012-12-08 03:19:43 +09:00
|
|
|
function applyStencilMask(imgArray, width, height, inverseDecode, buffer) {
|
|
|
|
var imgArrayPos = 0;
|
|
|
|
var i, j, mask, buf;
|
|
|
|
// removing making non-masked pixels transparent
|
|
|
|
var bufferPos = 3; // alpha component offset
|
|
|
|
for (i = 0; i < height; i++) {
|
|
|
|
mask = 0;
|
|
|
|
for (j = 0; j < width; j++) {
|
|
|
|
if (!mask) {
|
|
|
|
buf = imgArray[imgArrayPos++];
|
|
|
|
mask = 128;
|
|
|
|
}
|
2013-02-01 08:30:47 +09:00
|
|
|
if (!(buf & mask) === inverseDecode) {
|
2012-12-08 03:19:43 +09:00
|
|
|
buffer[bufferPos] = 0;
|
|
|
|
}
|
|
|
|
bufferPos += 4;
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-22 07:31:57 +09:00
|
|
|
function putBinaryImageData(ctx, data, w, h) {
|
|
|
|
var tmpImgData = 'createImageData' in ctx ? ctx.createImageData(w, h) :
|
|
|
|
ctx.getImageData(0, 0, w, h);
|
|
|
|
|
|
|
|
var tmpImgDataPixels = tmpImgData.data;
|
|
|
|
if ('set' in tmpImgDataPixels)
|
|
|
|
tmpImgDataPixels.set(data);
|
|
|
|
else {
|
|
|
|
// Copy over the imageData pixel by pixel.
|
|
|
|
for (var i = 0, ii = tmpImgDataPixels.length; i < ii; i++)
|
|
|
|
tmpImgDataPixels[i] = data[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.putImageData(tmpImgData, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function prescaleImage(pixels, width, height, widthScale, heightScale) {
|
|
|
|
pixels = new Uint8Array(pixels); // creating a copy
|
|
|
|
while (widthScale > 2 || heightScale > 2) {
|
|
|
|
if (heightScale > 2) {
|
|
|
|
// scaling image twice vertically
|
|
|
|
var rowSize = width * 4;
|
|
|
|
var k = 0, l = 0;
|
|
|
|
for (var i = 0; i < height - 1; i += 2) {
|
|
|
|
for (var j = 0; j < width; j++) {
|
|
|
|
var alpha1 = pixels[k + 3], alpha2 = pixels[k + 3 + rowSize];
|
|
|
|
if (alpha1 === alpha2) {
|
|
|
|
pixels[l] = (pixels[k] + pixels[k + rowSize]) >> 1;
|
|
|
|
pixels[l + 1] = (pixels[k + 1] + pixels[k + 1 + rowSize]) >> 1;
|
|
|
|
pixels[l + 2] = (pixels[k + 2] + pixels[k + 2 + rowSize]) >> 1;
|
|
|
|
pixels[l + 3] = alpha1;
|
|
|
|
} else if (alpha1 < alpha2) {
|
|
|
|
var d = 256 - alpha2 + alpha1;
|
|
|
|
pixels[l] = (pixels[k] * d + (pixels[k + rowSize] << 8)) >> 9;
|
|
|
|
pixels[l + 1] = (pixels[k + 1] * d +
|
|
|
|
(pixels[k + 1 + rowSize] << 8)) >> 9;
|
|
|
|
pixels[l + 2] = (pixels[k + 2] * d +
|
|
|
|
(pixels[k + 2 + rowSize] << 8)) >> 9;
|
|
|
|
pixels[l + 3] = alpha2;
|
|
|
|
} else {
|
|
|
|
var d = 256 - alpha1 + alpha2;
|
|
|
|
pixels[l] = ((pixels[k] << 8) + pixels[k + rowSize] * d) >> 9;
|
|
|
|
pixels[l + 1] = ((pixels[k + 1] << 8) +
|
|
|
|
pixels[k + 1 + rowSize] * d) >> 9;
|
|
|
|
pixels[l + 2] = ((pixels[k + 2] << 8) +
|
|
|
|
pixels[k + 2 + rowSize] * d) >> 9;
|
|
|
|
pixels[l + 3] = alpha1;
|
|
|
|
}
|
|
|
|
k += 4; l += 4;
|
|
|
|
}
|
|
|
|
k += rowSize;
|
2012-12-05 02:36:42 +09:00
|
|
|
}
|
2012-12-22 07:31:57 +09:00
|
|
|
if (height & 1) {
|
|
|
|
for (var i = 0; i < rowSize; i++) {
|
|
|
|
pixels[l++] = pixels[k++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
height = (height + 1) >> 1;
|
|
|
|
heightScale /= 2;
|
|
|
|
}
|
|
|
|
if (widthScale > 2) {
|
|
|
|
// scaling image twice horizontally
|
|
|
|
var k = 0, l = 0;
|
|
|
|
for (var i = 0; i < height; i++) {
|
|
|
|
for (var j = 0; j < width - 1; j += 2) {
|
|
|
|
var alpha1 = pixels[k + 3], alpha2 = pixels[k + 7];
|
|
|
|
if (alpha1 === alpha2) {
|
|
|
|
pixels[l] = (pixels[k] + pixels[k + 4]) >> 1;
|
|
|
|
pixels[l + 1] = (pixels[k + 1] + pixels[k + 5]) >> 1;
|
|
|
|
pixels[l + 2] = (pixels[k + 2] + pixels[k + 6]) >> 1;
|
|
|
|
pixels[l + 3] = alpha1;
|
|
|
|
} else if (alpha1 < alpha2) {
|
|
|
|
var d = 256 - alpha2 + alpha1;
|
|
|
|
pixels[l] = (pixels[k] * d + (pixels[k + 4] << 8)) >> 9;
|
|
|
|
pixels[l + 1] = (pixels[k + 1] * d + (pixels[k + 5] << 8)) >> 9;
|
|
|
|
pixels[l + 2] = (pixels[k + 2] * d + (pixels[k + 6] << 8)) >> 9;
|
|
|
|
pixels[l + 3] = alpha2;
|
|
|
|
} else {
|
|
|
|
var d = 256 - alpha1 + alpha2;
|
|
|
|
pixels[l] = ((pixels[k] << 8) + pixels[k + 4] * d) >> 9;
|
|
|
|
pixels[l + 1] = ((pixels[k + 1] << 8) + pixels[k + 5] * d) >> 9;
|
|
|
|
pixels[l + 2] = ((pixels[k + 2] << 8) + pixels[k + 6] * d) >> 9;
|
|
|
|
pixels[l + 3] = alpha1;
|
|
|
|
}
|
|
|
|
k += 8; l += 4;
|
|
|
|
}
|
|
|
|
if (width & 1) {
|
|
|
|
pixels[l++] = pixels[k++];
|
|
|
|
pixels[l++] = pixels[k++];
|
|
|
|
pixels[l++] = pixels[k++];
|
|
|
|
pixels[l++] = pixels[k++];
|
|
|
|
}
|
2012-12-05 02:36:42 +09:00
|
|
|
}
|
2012-12-22 07:31:57 +09:00
|
|
|
width = (width + 1) >> 1;
|
|
|
|
widthScale /= 2;
|
2012-12-05 02:36:42 +09:00
|
|
|
}
|
|
|
|
}
|
2012-12-22 07:31:57 +09:00
|
|
|
|
|
|
|
var tmpCanvas = createScratchCanvas(width, height);
|
2012-12-05 02:36:42 +09:00
|
|
|
var tmpCtx = tmpCanvas.getContext('2d');
|
2012-12-22 07:31:57 +09:00
|
|
|
putBinaryImageData(tmpCtx, pixels.subarray(0, width * height * 4),
|
|
|
|
width, height);
|
|
|
|
|
2012-12-05 02:36:42 +09:00
|
|
|
return tmpCanvas;
|
|
|
|
}
|
|
|
|
|
2013-03-13 09:20:38 +09:00
|
|
|
function copyCtxState(sourceCtx, destCtx) {
|
|
|
|
var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
|
|
|
|
'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
|
|
|
|
'globalCompositeOperation', 'font'];
|
|
|
|
for (var i = 0, ii = properties.length; i < ii; i++) {
|
|
|
|
var property = properties[i];
|
|
|
|
if (property in sourceCtx) {
|
|
|
|
destCtx[property] = sourceCtx[property];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ('setLineDash' in sourceCtx) {
|
|
|
|
destCtx.setLineDash(sourceCtx.getLineDash());
|
|
|
|
destCtx.lineDashOffset = sourceCtx.lineDashOffset;
|
|
|
|
} else if ('mozDash' in sourceCtx) {
|
|
|
|
destCtx.mozDash = sourceCtx.mozDash;
|
|
|
|
destCtx.mozDashOffset = sourceCtx.mozDashOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-25 08:55:23 +09:00
|
|
|
var LINE_CAP_STYLES = ['butt', 'round', 'square'];
|
|
|
|
var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
|
|
|
|
var NORMAL_CLIP = {};
|
|
|
|
var EO_CLIP = {};
|
|
|
|
|
2011-12-09 07:18:43 +09:00
|
|
|
CanvasGraphics.prototype = {
|
2011-12-01 08:02:30 +09:00
|
|
|
slowCommands: {
|
|
|
|
'stroke': true,
|
|
|
|
'closeStroke': true,
|
|
|
|
'fill': true,
|
|
|
|
'eoFill': true,
|
|
|
|
'fillStroke': true,
|
|
|
|
'eoFillStroke': true,
|
|
|
|
'closeFillStroke': true,
|
|
|
|
'closeEOFillStroke': true,
|
|
|
|
'showText': true,
|
|
|
|
'showSpacedText': true,
|
|
|
|
'setStrokeColorSpace': true,
|
|
|
|
'setFillColorSpace': true,
|
|
|
|
'setStrokeColor': true,
|
|
|
|
'setStrokeColorN': true,
|
|
|
|
'setFillColor': true,
|
2012-02-21 22:36:15 +09:00
|
|
|
'setFillColorN': true,
|
2011-12-01 08:02:30 +09:00
|
|
|
'setStrokeGray': true,
|
|
|
|
'setFillGray': true,
|
|
|
|
'setStrokeRGBColor': true,
|
|
|
|
'setFillRGBColor': true,
|
|
|
|
'setStrokeCMYKColor': true,
|
|
|
|
'setFillCMYKColor': true,
|
|
|
|
'paintJpegXObject': true,
|
|
|
|
'paintImageXObject': true,
|
2012-12-08 08:19:06 +09:00
|
|
|
'paintInlineImageXObject': true,
|
|
|
|
'paintInlineImageXObjectGroup': true,
|
2011-12-01 08:02:30 +09:00
|
|
|
'paintImageMaskXObject': true,
|
2012-12-08 08:19:06 +09:00
|
|
|
'paintImageMaskXObjectGroup': true,
|
2011-12-01 08:02:30 +09:00
|
|
|
'shadingFill': true
|
|
|
|
},
|
|
|
|
|
2013-03-30 05:26:25 +09:00
|
|
|
beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
|
|
|
|
// For pdfs that use blend modes we have to clear the canvas else certain
|
|
|
|
// blend modes can look wrong since we'd be blending with a white
|
|
|
|
// backdrop. The problem with a transparent backdrop though is we then
|
|
|
|
// don't get sub pixel anti aliasing on text, so we fill with white if
|
|
|
|
// we can.
|
|
|
|
var width = this.ctx.canvas.width;
|
|
|
|
var height = this.ctx.canvas.height;
|
|
|
|
if (transparency) {
|
|
|
|
this.ctx.clearRect(0, 0, width, height);
|
|
|
|
} else {
|
2013-03-30 06:25:10 +09:00
|
|
|
this.ctx.mozOpaque = true;
|
2013-03-30 05:26:25 +09:00
|
|
|
this.ctx.save();
|
|
|
|
this.ctx.fillStyle = 'rgb(255, 255, 255)';
|
|
|
|
this.ctx.fillRect(0, 0, width, height);
|
|
|
|
this.ctx.restore();
|
|
|
|
}
|
|
|
|
|
2012-04-12 00:29:44 +09:00
|
|
|
var transform = viewport.transform;
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.save();
|
2012-04-12 00:29:44 +09:00
|
|
|
this.ctx.transform.apply(this.ctx, transform);
|
2011-12-19 03:53:30 +09:00
|
|
|
|
2013-02-11 03:19:36 +09:00
|
|
|
if (this.textLayer) {
|
2011-12-19 03:53:30 +09:00
|
|
|
this.textLayer.beginLayout();
|
2013-02-11 03:19:36 +09:00
|
|
|
}
|
|
|
|
if (this.imageLayer) {
|
|
|
|
this.imageLayer.beginLayout();
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
executeOperatorList: function CanvasGraphics_executeOperatorList(
|
2012-03-13 02:41:40 +09:00
|
|
|
operatorList,
|
|
|
|
executionStartIdx, continueCallback,
|
|
|
|
stepper) {
|
|
|
|
var argsArray = operatorList.argsArray;
|
|
|
|
var fnArray = operatorList.fnArray;
|
2011-10-25 08:55:23 +09:00
|
|
|
var i = executionStartIdx || 0;
|
|
|
|
var argsArrayLen = argsArray.length;
|
|
|
|
|
2012-03-13 02:41:40 +09:00
|
|
|
// Sometimes the OperatorList to execute is empty.
|
2011-11-28 04:54:25 +09:00
|
|
|
if (argsArrayLen == i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2011-10-25 08:55:23 +09:00
|
|
|
var executionEndIdx;
|
2012-11-10 06:34:11 +09:00
|
|
|
var endTime = Date.now() + EXECUTION_TIME;
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2012-10-29 05:10:34 +09:00
|
|
|
var commonObjs = this.commonObjs;
|
2011-10-25 08:55:23 +09:00
|
|
|
var objs = this.objs;
|
2011-12-01 08:02:30 +09:00
|
|
|
var fnName;
|
|
|
|
var slowCommands = this.slowCommands;
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2011-11-28 04:54:25 +09:00
|
|
|
while (true) {
|
2012-02-15 03:25:53 +09:00
|
|
|
if (stepper && i === stepper.nextBreakPoint) {
|
2012-02-14 10:35:58 +09:00
|
|
|
stepper.breakIt(i, continueCallback);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2011-12-01 08:02:30 +09:00
|
|
|
fnName = fnArray[i];
|
|
|
|
|
|
|
|
if (fnName !== 'dependency') {
|
|
|
|
this[fnName].apply(this, argsArray[i]);
|
2011-11-28 04:54:25 +09:00
|
|
|
} else {
|
|
|
|
var deps = argsArray[i];
|
|
|
|
for (var n = 0, nn = deps.length; n < nn; n++) {
|
|
|
|
var depObjId = deps[n];
|
2012-10-29 05:10:34 +09:00
|
|
|
var common = depObjId.substring(0, 2) == 'g_';
|
2011-11-28 04:54:25 +09:00
|
|
|
|
|
|
|
// If the promise isn't resolved yet, add the continueCallback
|
|
|
|
// to the promise and bail out.
|
2012-10-29 05:10:34 +09:00
|
|
|
if (!common && !objs.isResolved(depObjId)) {
|
2011-11-28 04:54:25 +09:00
|
|
|
objs.get(depObjId, continueCallback);
|
|
|
|
return i;
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
2012-10-29 05:10:34 +09:00
|
|
|
if (common && !commonObjs.isResolved(depObjId)) {
|
|
|
|
commonObjs.get(depObjId, continueCallback);
|
|
|
|
return i;
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
|
|
|
}
|
2011-12-01 08:02:30 +09:00
|
|
|
|
2011-11-28 04:54:25 +09:00
|
|
|
i++;
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2012-03-13 02:41:40 +09:00
|
|
|
// If the entire operatorList was executed, stop as were done.
|
2011-10-25 08:55:23 +09:00
|
|
|
if (i == argsArrayLen) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the execution took longer then a certain amount of time, shedule
|
|
|
|
// to continue exeution after a short delay.
|
|
|
|
// However, this is only possible if a 'continueCallback' is passed in.
|
2011-12-01 08:02:30 +09:00
|
|
|
if (continueCallback && slowCommands[fnName] && Date.now() > endTime) {
|
2011-10-25 08:55:23 +09:00
|
|
|
setTimeout(continueCallback, 0);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2012-03-13 02:41:40 +09:00
|
|
|
// If the operatorList isn't executed completely yet OR the execution
|
|
|
|
// time was short enough, do another execution round.
|
2011-11-28 04:54:25 +09:00
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
endDrawing: function CanvasGraphics_endDrawing() {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.restore();
|
2011-10-29 06:37:55 +09:00
|
|
|
|
2013-02-11 03:19:36 +09:00
|
|
|
if (this.textLayer) {
|
2011-12-19 03:53:30 +09:00
|
|
|
this.textLayer.endLayout();
|
2013-02-11 03:19:36 +09:00
|
|
|
}
|
|
|
|
if (this.imageLayer) {
|
|
|
|
this.imageLayer.endLayout();
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
// Graphics state
|
2012-04-05 05:43:26 +09:00
|
|
|
setLineWidth: function CanvasGraphics_setLineWidth(width) {
|
2012-01-18 13:50:49 +09:00
|
|
|
this.current.lineWidth = width;
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.lineWidth = width;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setLineCap: function CanvasGraphics_setLineCap(style) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.lineCap = LINE_CAP_STYLES[style];
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setLineJoin: function CanvasGraphics_setLineJoin(style) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.lineJoin = LINE_JOIN_STYLES[style];
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.miterLimit = limit;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
|
2012-12-04 23:26:10 +09:00
|
|
|
var ctx = this.ctx;
|
|
|
|
if ('setLineDash' in ctx) {
|
|
|
|
ctx.setLineDash(dashArray);
|
|
|
|
ctx.lineDashOffset = dashPhase;
|
|
|
|
} else {
|
|
|
|
ctx.mozDash = dashArray;
|
|
|
|
ctx.mozDashOffset = dashPhase;
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
|
2012-05-15 09:19:09 +09:00
|
|
|
// Maybe if we one day fully support color spaces this will be important
|
|
|
|
// for now we can ignore.
|
|
|
|
// TODO set rendering intent?
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setFlatness: function CanvasGraphics_setFlatness(flatness) {
|
2012-05-15 09:19:09 +09:00
|
|
|
// There's no way to control this with canvas, but we can safely ignore.
|
|
|
|
// TODO set flatness?
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setGState: function CanvasGraphics_setGState(states) {
|
2011-11-03 04:21:45 +09:00
|
|
|
for (var i = 0, ii = states.length; i < ii; i++) {
|
2011-10-25 08:55:23 +09:00
|
|
|
var state = states[i];
|
|
|
|
var key = state[0];
|
|
|
|
var value = state[1];
|
|
|
|
|
|
|
|
switch (key) {
|
|
|
|
case 'LW':
|
|
|
|
this.setLineWidth(value);
|
|
|
|
break;
|
|
|
|
case 'LC':
|
|
|
|
this.setLineCap(value);
|
|
|
|
break;
|
|
|
|
case 'LJ':
|
|
|
|
this.setLineJoin(value);
|
|
|
|
break;
|
|
|
|
case 'ML':
|
|
|
|
this.setMiterLimit(value);
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
this.setDash(value[0], value[1]);
|
|
|
|
break;
|
|
|
|
case 'RI':
|
|
|
|
this.setRenderingIntent(value);
|
|
|
|
break;
|
|
|
|
case 'FL':
|
|
|
|
this.setFlatness(value);
|
|
|
|
break;
|
|
|
|
case 'Font':
|
|
|
|
this.setFont(state[1], state[2]);
|
|
|
|
break;
|
2011-10-29 06:10:10 +09:00
|
|
|
case 'CA':
|
|
|
|
this.current.strokeAlpha = state[1];
|
|
|
|
break;
|
|
|
|
case 'ca':
|
|
|
|
this.current.fillAlpha = state[1];
|
|
|
|
this.ctx.globalAlpha = state[1];
|
|
|
|
break;
|
2013-03-12 02:23:47 +09:00
|
|
|
case 'BM':
|
|
|
|
if (value && value.name && (value.name !== 'Normal')) {
|
|
|
|
var mode = value.name.replace(/([A-Z])/g,
|
|
|
|
function(c) {
|
|
|
|
return '-' + c.toLowerCase();
|
|
|
|
}
|
|
|
|
).substring(1);
|
|
|
|
this.ctx.globalCompositeOperation = mode;
|
|
|
|
if (this.ctx.globalCompositeOperation !== mode) {
|
|
|
|
warn('globalCompositeOperation "' + mode +
|
|
|
|
'" is not supported');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.ctx.globalCompositeOperation = 'source-over';
|
|
|
|
}
|
|
|
|
break;
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
save: function CanvasGraphics_save() {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.save();
|
|
|
|
var old = this.current;
|
|
|
|
this.stateStack.push(old);
|
|
|
|
this.current = old.clone();
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
restore: function CanvasGraphics_restore() {
|
2011-10-25 08:55:23 +09:00
|
|
|
var prev = this.stateStack.pop();
|
|
|
|
if (prev) {
|
|
|
|
this.current = prev;
|
|
|
|
this.ctx.restore();
|
|
|
|
}
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.transform(a, b, c, d, e, f);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Path
|
2012-04-05 05:43:26 +09:00
|
|
|
moveTo: function CanvasGraphics_moveTo(x, y) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.moveTo(x, y);
|
|
|
|
this.current.setCurrentPoint(x, y);
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
lineTo: function CanvasGraphics_lineTo(x, y) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.lineTo(x, y);
|
|
|
|
this.current.setCurrentPoint(x, y);
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
curveTo: function CanvasGraphics_curveTo(x1, y1, x2, y2, x3, y3) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
|
|
|
|
this.current.setCurrentPoint(x3, y3);
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
curveTo2: function CanvasGraphics_curveTo2(x2, y2, x3, y3) {
|
2011-10-25 08:55:23 +09:00
|
|
|
var current = this.current;
|
|
|
|
this.ctx.bezierCurveTo(current.x, current.y, x2, y2, x3, y3);
|
|
|
|
current.setCurrentPoint(x3, y3);
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
curveTo3: function CanvasGraphics_curveTo3(x1, y1, x3, y3) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.curveTo(x1, y1, x3, y3, x3, y3);
|
|
|
|
this.current.setCurrentPoint(x3, y3);
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
closePath: function CanvasGraphics_closePath() {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.closePath();
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
rectangle: function CanvasGraphics_rectangle(x, y, width, height) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.rect(x, y, width, height);
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
stroke: function CanvasGraphics_stroke(consumePath) {
|
2011-10-29 06:10:10 +09:00
|
|
|
consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
|
2011-10-25 08:55:23 +09:00
|
|
|
var ctx = this.ctx;
|
|
|
|
var strokeColor = this.current.strokeColor;
|
2012-01-18 13:50:49 +09:00
|
|
|
if (this.current.lineWidth === 0)
|
|
|
|
ctx.lineWidth = this.getSinglePixelWidth();
|
2011-10-29 06:10:10 +09:00
|
|
|
// For stroke we want to temporarily change the global alpha to the
|
|
|
|
// stroking alpha.
|
|
|
|
ctx.globalAlpha = this.current.strokeAlpha;
|
2011-10-25 08:55:23 +09:00
|
|
|
if (strokeColor && strokeColor.hasOwnProperty('type') &&
|
|
|
|
strokeColor.type === 'Pattern') {
|
|
|
|
// for patterns, we transform to pattern space, calculate
|
|
|
|
// the pattern, call stroke, and restore to user space
|
|
|
|
ctx.save();
|
|
|
|
ctx.strokeStyle = strokeColor.getPattern(ctx);
|
|
|
|
ctx.stroke();
|
|
|
|
ctx.restore();
|
|
|
|
} else {
|
|
|
|
ctx.stroke();
|
|
|
|
}
|
2011-10-29 06:10:10 +09:00
|
|
|
if (consumePath)
|
|
|
|
this.consumePath();
|
|
|
|
// Restore the global alpha to the fill alpha
|
|
|
|
ctx.globalAlpha = this.current.fillAlpha;
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
closeStroke: function CanvasGraphics_closeStroke() {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.closePath();
|
|
|
|
this.stroke();
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
fill: function CanvasGraphics_fill(consumePath) {
|
2011-10-29 06:10:10 +09:00
|
|
|
consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
|
2011-10-25 08:55:23 +09:00
|
|
|
var ctx = this.ctx;
|
|
|
|
var fillColor = this.current.fillColor;
|
2013-05-04 08:47:40 +09:00
|
|
|
var needRestore = false;
|
2011-10-25 08:55:23 +09:00
|
|
|
|
|
|
|
if (fillColor && fillColor.hasOwnProperty('type') &&
|
|
|
|
fillColor.type === 'Pattern') {
|
|
|
|
ctx.save();
|
|
|
|
ctx.fillStyle = fillColor.getPattern(ctx);
|
2013-05-04 08:47:40 +09:00
|
|
|
needRestore = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.pendingEOFill) {
|
|
|
|
if ('mozFillRule' in this.ctx) {
|
|
|
|
this.ctx.mozFillRule = 'evenodd';
|
|
|
|
this.ctx.fill();
|
|
|
|
this.ctx.mozFillRule = 'nonzero';
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
this.ctx.fill('evenodd');
|
|
|
|
} catch (ex) {
|
|
|
|
// shouldn't really happen, but browsers might think differently
|
|
|
|
this.ctx.fill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.pendingEOFill = false;
|
2011-10-25 08:55:23 +09:00
|
|
|
} else {
|
2013-05-04 08:47:40 +09:00
|
|
|
this.ctx.fill();
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
2013-05-04 08:47:40 +09:00
|
|
|
|
|
|
|
if (needRestore) {
|
|
|
|
ctx.restore();
|
|
|
|
}
|
|
|
|
if (consumePath) {
|
2011-10-29 06:10:10 +09:00
|
|
|
this.consumePath();
|
2013-05-04 08:47:40 +09:00
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
eoFill: function CanvasGraphics_eoFill() {
|
2013-05-04 08:47:40 +09:00
|
|
|
this.pendingEOFill = true;
|
2011-10-25 08:55:23 +09:00
|
|
|
this.fill();
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
fillStroke: function CanvasGraphics_fillStroke() {
|
2011-10-29 06:10:10 +09:00
|
|
|
this.fill(false);
|
|
|
|
this.stroke(false);
|
2011-10-25 08:55:23 +09:00
|
|
|
|
|
|
|
this.consumePath();
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
eoFillStroke: function CanvasGraphics_eoFillStroke() {
|
2013-05-04 08:47:40 +09:00
|
|
|
this.pendingEOFill = true;
|
2011-10-25 08:55:23 +09:00
|
|
|
this.fillStroke();
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
closeFillStroke: function CanvasGraphics_closeFillStroke() {
|
2011-10-28 20:34:56 +09:00
|
|
|
this.closePath();
|
|
|
|
this.fillStroke();
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
|
2013-05-04 08:47:40 +09:00
|
|
|
this.pendingEOFill = true;
|
2011-10-28 20:34:56 +09:00
|
|
|
this.closePath();
|
2011-10-25 08:55:23 +09:00
|
|
|
this.fillStroke();
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
endPath: function CanvasGraphics_endPath() {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.consumePath();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Clipping
|
2012-04-05 05:43:26 +09:00
|
|
|
clip: function CanvasGraphics_clip() {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.pendingClip = NORMAL_CLIP;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
eoClip: function CanvasGraphics_eoClip() {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.pendingClip = EO_CLIP;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Text
|
2012-04-05 05:43:26 +09:00
|
|
|
beginText: function CanvasGraphics_beginText() {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.current.textMatrix = IDENTITY_MATRIX;
|
|
|
|
this.current.x = this.current.lineX = 0;
|
|
|
|
this.current.y = this.current.lineY = 0;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
endText: function CanvasGraphics_endText() {
|
2013-05-16 05:57:27 +09:00
|
|
|
if (!('pendingTextPaths' in this)) {
|
|
|
|
this.ctx.beginPath();
|
|
|
|
return;
|
2012-10-13 12:33:56 +09:00
|
|
|
}
|
2013-05-16 05:57:27 +09:00
|
|
|
var paths = this.pendingTextPaths;
|
2012-10-13 12:33:56 +09:00
|
|
|
var ctx = this.ctx;
|
|
|
|
|
|
|
|
ctx.save();
|
2013-05-16 05:57:27 +09:00
|
|
|
ctx.beginPath();
|
|
|
|
for (var i = 0; i < paths.length; i++) {
|
|
|
|
var path = paths[i];
|
|
|
|
ctx.setTransform.apply(ctx, path.transform);
|
|
|
|
ctx.translate(path.x, path.y);
|
|
|
|
path.addToPath(ctx, path.fontSize);
|
|
|
|
}
|
2012-10-13 12:33:56 +09:00
|
|
|
ctx.restore();
|
2013-05-16 05:57:27 +09:00
|
|
|
ctx.clip();
|
|
|
|
ctx.beginPath();
|
|
|
|
delete this.pendingTextPaths;
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.current.charSpacing = spacing;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.current.wordSpacing = spacing;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setHScale: function CanvasGraphics_setHScale(scale) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.current.textHScale = scale / 100;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setLeading: function CanvasGraphics_setLeading(leading) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.current.leading = -leading;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setFont: function CanvasGraphics_setFont(fontRefName, size) {
|
2012-10-29 05:10:34 +09:00
|
|
|
var fontObj = this.commonObjs.get(fontRefName);
|
2012-01-24 05:23:09 +09:00
|
|
|
var current = this.current;
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2012-01-24 05:23:09 +09:00
|
|
|
if (!fontObj)
|
2012-01-25 05:04:59 +09:00
|
|
|
error('Can\'t find font for ' + fontRefName);
|
2012-01-24 05:23:09 +09:00
|
|
|
|
2013-01-04 09:39:06 +09:00
|
|
|
current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix :
|
|
|
|
FONT_IDENTITY_MATRIX;
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2012-01-21 08:41:01 +09:00
|
|
|
// A valid matrix needs all main diagonal elements to be non-zero
|
|
|
|
// This also ensures we bypass FF bugzilla bug #719844.
|
2012-01-24 05:23:09 +09:00
|
|
|
if (current.fontMatrix[0] === 0 ||
|
|
|
|
current.fontMatrix[3] === 0) {
|
2012-01-21 04:55:52 +09:00
|
|
|
warn('Invalid font matrix for font ' + fontRefName);
|
|
|
|
}
|
|
|
|
|
2012-01-21 08:41:01 +09:00
|
|
|
// The spec for Tf (setFont) says that 'size' specifies the font 'scale',
|
2012-01-24 05:23:09 +09:00
|
|
|
// and in some docs this can be negative (inverted x-y axes).
|
2012-01-21 08:41:01 +09:00
|
|
|
if (size < 0) {
|
|
|
|
size = -size;
|
2013-01-04 09:39:06 +09:00
|
|
|
current.fontDirection = -1;
|
|
|
|
} else {
|
|
|
|
current.fontDirection = 1;
|
2012-01-21 08:41:01 +09:00
|
|
|
}
|
|
|
|
|
2011-10-25 08:55:23 +09:00
|
|
|
this.current.font = fontObj;
|
|
|
|
this.current.fontSize = size;
|
|
|
|
|
2012-02-05 03:45:18 +09:00
|
|
|
if (fontObj.coded)
|
|
|
|
return; // we don't need ctx.font for Type3 fonts
|
|
|
|
|
2011-10-25 08:55:23 +09:00
|
|
|
var name = fontObj.loadedName || 'sans-serif';
|
|
|
|
var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
|
|
|
|
(fontObj.bold ? 'bold' : 'normal');
|
|
|
|
|
|
|
|
var italic = fontObj.italic ? 'italic' : 'normal';
|
2012-09-15 02:58:33 +09:00
|
|
|
var typeface = '"' + name + '", ' + fontObj.fallbackName;
|
2012-02-05 03:45:18 +09:00
|
|
|
|
2012-02-14 13:35:42 +09:00
|
|
|
// Some font backends cannot handle fonts below certain size.
|
|
|
|
// Keeping the font at minimal size and using the fontSizeScale to change
|
|
|
|
// the current transformation matrix before the fillText/strokeText.
|
|
|
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
|
2012-02-05 03:45:18 +09:00
|
|
|
var browserFontSize = size >= MIN_FONT_SIZE ? size : MIN_FONT_SIZE;
|
|
|
|
this.current.fontSizeScale = browserFontSize != MIN_FONT_SIZE ? 1.0 :
|
|
|
|
size / MIN_FONT_SIZE;
|
|
|
|
|
|
|
|
var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.font = rule;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
|
2011-12-03 07:52:31 +09:00
|
|
|
this.current.textRenderingMode = mode;
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setTextRise: function CanvasGraphics_setTextRise(rise) {
|
2012-08-02 05:10:48 +09:00
|
|
|
this.current.textRise = rise;
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
moveText: function CanvasGraphics_moveText(x, y) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.current.x = this.current.lineX += x;
|
|
|
|
this.current.y = this.current.lineY += y;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.setLeading(-y);
|
|
|
|
this.moveText(x, y);
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.current.textMatrix = [a, b, c, d, e, f];
|
|
|
|
|
|
|
|
this.current.x = this.current.lineX = 0;
|
|
|
|
this.current.y = this.current.lineY = 0;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
nextLine: function CanvasGraphics_nextLine() {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.moveText(0, this.current.leading);
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
applyTextTransforms: function CanvasGraphics_applyTextTransforms() {
|
2011-11-09 05:27:03 +09:00
|
|
|
var ctx = this.ctx;
|
|
|
|
var current = this.current;
|
|
|
|
ctx.transform.apply(ctx, current.textMatrix);
|
2013-01-04 09:39:06 +09:00
|
|
|
ctx.translate(current.x, current.y + current.textRise);
|
|
|
|
if (current.fontDirection > 0) {
|
|
|
|
ctx.scale(current.textHScale, -1);
|
|
|
|
} else {
|
|
|
|
ctx.scale(-current.textHScale, 1);
|
|
|
|
}
|
2011-11-09 05:27:03 +09:00
|
|
|
},
|
2012-10-09 22:25:41 +09:00
|
|
|
createTextGeometry: function CanvasGraphics_createTextGeometry() {
|
2011-12-02 04:11:17 +09:00
|
|
|
var geometry = {};
|
2011-11-09 05:27:03 +09:00
|
|
|
var ctx = this.ctx;
|
|
|
|
var font = this.current.font;
|
|
|
|
var ctxMatrix = ctx.mozCurrentTransform;
|
|
|
|
if (ctxMatrix) {
|
|
|
|
var bl = Util.applyTransform([0, 0], ctxMatrix);
|
|
|
|
var tr = Util.applyTransform([1, 1], ctxMatrix);
|
2011-12-02 04:11:17 +09:00
|
|
|
geometry.x = bl[0];
|
|
|
|
geometry.y = bl[1];
|
|
|
|
geometry.hScale = tr[0] - bl[0];
|
|
|
|
geometry.vScale = tr[1] - bl[1];
|
2011-11-09 05:27:03 +09:00
|
|
|
}
|
2011-12-13 12:32:20 +09:00
|
|
|
geometry.spaceWidth = font.spaceWidth;
|
2012-10-09 22:25:41 +09:00
|
|
|
geometry.fontName = font.loadedName;
|
|
|
|
geometry.fontFamily = font.fallbackName;
|
|
|
|
geometry.fontSize = this.current.fontSize;
|
2011-12-02 04:11:17 +09:00
|
|
|
return geometry;
|
2011-11-09 05:27:03 +09:00
|
|
|
},
|
2011-12-02 04:11:17 +09:00
|
|
|
|
2013-05-16 05:57:27 +09:00
|
|
|
paintChar: function (character, x, y) {
|
|
|
|
var ctx = this.ctx;
|
|
|
|
var current = this.current;
|
|
|
|
var font = current.font;
|
|
|
|
var fontSize = current.fontSize / current.fontSizeScale;
|
|
|
|
var textRenderingMode = current.textRenderingMode;
|
|
|
|
var fillStrokeMode = textRenderingMode &
|
|
|
|
TextRenderingMode.FILL_STROKE_MASK;
|
|
|
|
var isAddToPathSet = !!(textRenderingMode &
|
|
|
|
TextRenderingMode.ADD_TO_PATH_FLAG);
|
|
|
|
|
|
|
|
var addToPath;
|
|
|
|
if (font.disableFontFace || isAddToPathSet) {
|
|
|
|
addToPath = font.renderer.getPathGenerator(character);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (font.disableFontFace) {
|
|
|
|
ctx.save();
|
|
|
|
ctx.translate(x, y);
|
|
|
|
ctx.beginPath();
|
|
|
|
addToPath(ctx, fontSize);
|
|
|
|
if (fillStrokeMode === TextRenderingMode.FILL ||
|
|
|
|
fillStrokeMode === TextRenderingMode.FILL_STROKE) {
|
|
|
|
ctx.fill();
|
|
|
|
}
|
|
|
|
if (fillStrokeMode === TextRenderingMode.STROKE ||
|
|
|
|
fillStrokeMode === TextRenderingMode.FILL_STROKE) {
|
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
ctx.restore();
|
|
|
|
} else {
|
|
|
|
if (fillStrokeMode === TextRenderingMode.FILL ||
|
|
|
|
fillStrokeMode === TextRenderingMode.FILL_STROKE) {
|
|
|
|
ctx.fillText(character, x, y);
|
|
|
|
}
|
|
|
|
if (fillStrokeMode === TextRenderingMode.STROKE ||
|
|
|
|
fillStrokeMode === TextRenderingMode.FILL_STROKE) {
|
|
|
|
ctx.strokeText(character, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAddToPathSet) {
|
|
|
|
var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
|
|
|
|
paths.push({
|
|
|
|
transform: ctx.mozCurrentTransform,
|
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
fontSize: fontSize,
|
|
|
|
addToPath: addToPath
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
showText: function CanvasGraphics_showText(str, skipTextSelection) {
|
2011-10-25 08:55:23 +09:00
|
|
|
var ctx = this.ctx;
|
|
|
|
var current = this.current;
|
|
|
|
var font = current.font;
|
2011-11-09 05:27:03 +09:00
|
|
|
var glyphs = font.charsToGlyphs(str);
|
2011-10-25 08:55:23 +09:00
|
|
|
var fontSize = current.fontSize;
|
2012-02-05 03:45:18 +09:00
|
|
|
var fontSizeScale = current.fontSizeScale;
|
2011-10-25 08:55:23 +09:00
|
|
|
var charSpacing = current.charSpacing;
|
|
|
|
var wordSpacing = current.wordSpacing;
|
2013-01-04 09:39:06 +09:00
|
|
|
var textHScale = current.textHScale * current.fontDirection;
|
|
|
|
var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
|
2011-10-25 08:55:23 +09:00
|
|
|
var glyphsLength = glyphs.length;
|
2011-11-09 05:27:03 +09:00
|
|
|
var textLayer = this.textLayer;
|
2012-09-20 05:17:01 +09:00
|
|
|
var geom;
|
2011-11-09 05:27:03 +09:00
|
|
|
var textSelection = textLayer && !skipTextSelection ? true : false;
|
2012-09-20 05:17:01 +09:00
|
|
|
var canvasWidth = 0.0;
|
2013-02-08 21:29:22 +09:00
|
|
|
var vertical = font.vertical;
|
|
|
|
var defaultVMetrics = font.defaultVMetrics;
|
2011-11-09 05:27:03 +09:00
|
|
|
|
|
|
|
// Type3 fonts - each glyph is a "mini-PDF"
|
2011-10-25 08:55:23 +09:00
|
|
|
if (font.coded) {
|
|
|
|
ctx.save();
|
|
|
|
ctx.transform.apply(ctx, current.textMatrix);
|
|
|
|
ctx.translate(current.x, current.y);
|
|
|
|
|
2011-12-02 11:56:26 +09:00
|
|
|
ctx.scale(textHScale, 1);
|
2011-12-13 12:32:20 +09:00
|
|
|
|
|
|
|
if (textSelection) {
|
|
|
|
this.save();
|
2011-12-14 09:28:02 +09:00
|
|
|
ctx.scale(1, -1);
|
2012-10-09 22:25:41 +09:00
|
|
|
geom = this.createTextGeometry();
|
2011-12-13 12:32:20 +09:00
|
|
|
this.restore();
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
for (var i = 0; i < glyphsLength; ++i) {
|
|
|
|
|
|
|
|
var glyph = glyphs[i];
|
|
|
|
if (glyph === null) {
|
|
|
|
// word break
|
|
|
|
this.ctx.translate(wordSpacing, 0);
|
2012-09-20 05:19:21 +09:00
|
|
|
current.x += wordSpacing * textHScale;
|
2011-10-25 08:55:23 +09:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-11 12:50:14 +09:00
|
|
|
this.processingType3 = glyph;
|
2011-10-25 08:55:23 +09:00
|
|
|
this.save();
|
|
|
|
ctx.scale(fontSize, fontSize);
|
|
|
|
ctx.transform.apply(ctx, fontMatrix);
|
2012-03-13 02:41:40 +09:00
|
|
|
this.executeOperatorList(glyph.operatorList);
|
2011-10-25 08:55:23 +09:00
|
|
|
this.restore();
|
|
|
|
|
|
|
|
var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
|
2013-01-04 09:39:06 +09:00
|
|
|
var width = (transformed[0] * fontSize + charSpacing) *
|
|
|
|
current.fontDirection;
|
2011-10-25 08:55:23 +09:00
|
|
|
|
|
|
|
ctx.translate(width, 0);
|
2011-12-13 12:32:20 +09:00
|
|
|
current.x += width * textHScale;
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2012-09-20 05:17:01 +09:00
|
|
|
canvasWidth += width;
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
|
|
|
ctx.restore();
|
2013-05-11 12:50:14 +09:00
|
|
|
this.processingType3 = null;
|
2011-10-25 08:55:23 +09:00
|
|
|
} else {
|
|
|
|
ctx.save();
|
2011-11-09 05:27:03 +09:00
|
|
|
this.applyTextTransforms();
|
2012-01-18 13:50:49 +09:00
|
|
|
|
|
|
|
var lineWidth = current.lineWidth;
|
2012-11-02 22:10:22 +09:00
|
|
|
var a1 = current.textMatrix[0], b1 = current.textMatrix[1];
|
2013-01-04 09:39:06 +09:00
|
|
|
var scale = Math.sqrt(a1 * a1 + b1 * b1);
|
2013-02-01 08:30:47 +09:00
|
|
|
if (scale === 0 || lineWidth === 0)
|
2012-01-18 13:50:49 +09:00
|
|
|
lineWidth = this.getSinglePixelWidth();
|
|
|
|
else
|
|
|
|
lineWidth /= scale;
|
|
|
|
|
2011-12-13 12:32:20 +09:00
|
|
|
if (textSelection)
|
2012-10-09 22:25:41 +09:00
|
|
|
geom = this.createTextGeometry();
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2012-02-14 12:12:55 +09:00
|
|
|
if (fontSizeScale != 1.0) {
|
2012-02-08 10:14:58 +09:00
|
|
|
ctx.scale(fontSizeScale, fontSizeScale);
|
2012-02-14 12:12:55 +09:00
|
|
|
lineWidth /= fontSizeScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.lineWidth = lineWidth;
|
2012-02-05 03:45:18 +09:00
|
|
|
|
2012-01-21 05:20:25 +09:00
|
|
|
var x = 0;
|
2011-10-25 08:55:23 +09:00
|
|
|
for (var i = 0; i < glyphsLength; ++i) {
|
|
|
|
var glyph = glyphs[i];
|
|
|
|
if (glyph === null) {
|
|
|
|
// word break
|
2013-01-04 09:39:06 +09:00
|
|
|
x += current.fontDirection * wordSpacing;
|
2011-10-25 08:55:23 +09:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-06 23:34:47 +09:00
|
|
|
var restoreNeeded = false;
|
2012-03-31 06:17:04 +09:00
|
|
|
var character = glyph.fontChar;
|
2013-02-08 21:29:22 +09:00
|
|
|
var vmetric = glyph.vmetric || defaultVMetrics;
|
|
|
|
if (vertical) {
|
2013-03-13 01:27:45 +09:00
|
|
|
var vx = glyph.vmetric ? vmetric[1] : glyph.width * 0.5;
|
|
|
|
vx = -vx * fontSize * current.fontMatrix[0];
|
2013-02-08 21:29:22 +09:00
|
|
|
var vy = vmetric[2] * fontSize * current.fontMatrix[0];
|
|
|
|
}
|
|
|
|
var width = vmetric ? -vmetric[0] : glyph.width;
|
|
|
|
var charWidth = width * fontSize * current.fontMatrix[0] +
|
2013-01-04 09:39:06 +09:00
|
|
|
charSpacing * current.fontDirection;
|
2013-02-27 03:00:20 +09:00
|
|
|
var accent = glyph.accent;
|
2011-12-03 07:52:31 +09:00
|
|
|
|
2013-02-27 03:00:20 +09:00
|
|
|
var scaledX, scaledY, scaledAccentX, scaledAccentY;
|
2012-03-26 04:31:28 +09:00
|
|
|
if (!glyph.disabled) {
|
2013-02-08 21:29:22 +09:00
|
|
|
if (vertical) {
|
2013-02-27 03:00:20 +09:00
|
|
|
scaledX = vx / fontSizeScale;
|
|
|
|
scaledY = (x + vy) / fontSizeScale;
|
2013-02-08 21:29:22 +09:00
|
|
|
} else {
|
2013-02-27 03:00:20 +09:00
|
|
|
scaledX = x / fontSizeScale;
|
|
|
|
scaledY = 0;
|
|
|
|
}
|
2013-05-06 23:34:47 +09:00
|
|
|
|
|
|
|
if (font.remeasure && width > 0) {
|
|
|
|
// some standard fonts may not have the exact width, trying to
|
|
|
|
// rescale per character
|
|
|
|
var measuredWidth = ctx.measureText(character).width * 1000 /
|
|
|
|
current.fontSize * current.fontSizeScale;
|
|
|
|
var characterScaleX = width / measuredWidth;
|
|
|
|
restoreNeeded = true;
|
|
|
|
ctx.save();
|
|
|
|
ctx.scale(characterScaleX, 1);
|
|
|
|
scaledX /= characterScaleX;
|
|
|
|
if (accent) {
|
|
|
|
scaledAccentX /= characterScaleX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-16 05:57:27 +09:00
|
|
|
this.paintChar(character, scaledX, scaledY);
|
|
|
|
if (accent) {
|
|
|
|
scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
|
|
|
|
scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
|
|
|
|
this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
|
2012-10-13 12:33:56 +09:00
|
|
|
}
|
2011-12-03 07:52:31 +09:00
|
|
|
}
|
|
|
|
|
2012-01-21 05:20:25 +09:00
|
|
|
x += charWidth;
|
2011-11-30 06:02:12 +09:00
|
|
|
|
2012-09-20 05:17:01 +09:00
|
|
|
canvasWidth += charWidth;
|
2013-05-06 23:34:47 +09:00
|
|
|
|
|
|
|
if (restoreNeeded) {
|
|
|
|
ctx.restore();
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
2013-02-08 21:29:22 +09:00
|
|
|
if (vertical) {
|
|
|
|
current.y -= x * textHScale;
|
|
|
|
} else {
|
|
|
|
current.x += x * textHScale;
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
ctx.restore();
|
|
|
|
}
|
2011-11-09 05:27:03 +09:00
|
|
|
|
2012-09-20 05:17:01 +09:00
|
|
|
if (textSelection) {
|
|
|
|
geom.canvasWidth = canvasWidth;
|
2013-02-08 21:29:22 +09:00
|
|
|
if (vertical) {
|
|
|
|
var vmetric = font.defaultVMetrics;
|
2013-03-13 01:27:45 +09:00
|
|
|
geom.x += vmetric[1] * fontSize * current.fontMatrix[0] /
|
2013-02-08 21:29:22 +09:00
|
|
|
fontSizeScale * geom.hScale;
|
|
|
|
geom.y += vmetric[2] * fontSize * current.fontMatrix[0] /
|
|
|
|
fontSizeScale * geom.vScale;
|
|
|
|
}
|
2012-10-09 22:25:41 +09:00
|
|
|
this.textLayer.appendText(geom);
|
2012-09-21 04:48:18 +09:00
|
|
|
}
|
2011-11-09 05:27:03 +09:00
|
|
|
|
2012-09-20 05:17:01 +09:00
|
|
|
return canvasWidth;
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
showSpacedText: function CanvasGraphics_showSpacedText(arr) {
|
2011-10-25 08:55:23 +09:00
|
|
|
var ctx = this.ctx;
|
|
|
|
var current = this.current;
|
2011-12-13 12:32:20 +09:00
|
|
|
var font = current.font;
|
2011-10-25 08:55:23 +09:00
|
|
|
var fontSize = current.fontSize;
|
2013-03-01 00:27:48 +09:00
|
|
|
// TJ array's number is independent from fontMatrix
|
|
|
|
var textHScale = current.textHScale * 0.001 * current.fontDirection;
|
2011-10-25 08:55:23 +09:00
|
|
|
var arrLength = arr.length;
|
2011-10-29 06:37:55 +09:00
|
|
|
var textLayer = this.textLayer;
|
2012-09-20 05:17:01 +09:00
|
|
|
var geom;
|
|
|
|
var canvasWidth = 0.0;
|
2011-11-09 05:27:03 +09:00
|
|
|
var textSelection = textLayer ? true : false;
|
2013-02-08 21:29:22 +09:00
|
|
|
var vertical = font.vertical;
|
2013-02-26 12:00:17 +09:00
|
|
|
var spacingAccumulator = 0;
|
2011-10-29 06:37:55 +09:00
|
|
|
|
2011-11-09 05:27:03 +09:00
|
|
|
if (textSelection) {
|
2011-11-01 05:49:18 +09:00
|
|
|
ctx.save();
|
2013-01-04 09:39:06 +09:00
|
|
|
this.applyTextTransforms();
|
2012-10-09 22:25:41 +09:00
|
|
|
geom = this.createTextGeometry();
|
2011-11-01 05:49:18 +09:00
|
|
|
ctx.restore();
|
2011-10-29 06:37:55 +09:00
|
|
|
}
|
2011-11-30 06:02:12 +09:00
|
|
|
|
2011-10-25 08:55:23 +09:00
|
|
|
for (var i = 0; i < arrLength; ++i) {
|
|
|
|
var e = arr[i];
|
|
|
|
if (isNum(e)) {
|
2013-01-04 09:39:06 +09:00
|
|
|
var spacingLength = -e * fontSize * textHScale;
|
2013-02-08 21:29:22 +09:00
|
|
|
if (vertical) {
|
|
|
|
current.y += spacingLength;
|
|
|
|
} else {
|
|
|
|
current.x += spacingLength;
|
|
|
|
}
|
2011-10-29 06:37:55 +09:00
|
|
|
|
2012-09-20 05:17:01 +09:00
|
|
|
if (textSelection)
|
2013-02-26 12:00:17 +09:00
|
|
|
spacingAccumulator += spacingLength;
|
2011-10-25 08:55:23 +09:00
|
|
|
} else if (isString(e)) {
|
2012-09-20 05:17:01 +09:00
|
|
|
var shownCanvasWidth = this.showText(e, true);
|
2011-10-29 06:37:55 +09:00
|
|
|
|
2013-02-26 12:00:17 +09:00
|
|
|
if (textSelection) {
|
|
|
|
canvasWidth += spacingAccumulator + shownCanvasWidth;
|
|
|
|
spacingAccumulator = 0;
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
} else {
|
2012-05-15 09:19:09 +09:00
|
|
|
error('TJ array element ' + e + ' is not string or num');
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
|
|
|
}
|
2011-11-30 06:02:12 +09:00
|
|
|
|
2012-09-20 05:17:01 +09:00
|
|
|
if (textSelection) {
|
|
|
|
geom.canvasWidth = canvasWidth;
|
2013-02-08 21:29:22 +09:00
|
|
|
if (vertical) {
|
|
|
|
var fontSizeScale = current.fontSizeScale;
|
|
|
|
var vmetric = font.defaultVMetrics;
|
2013-03-13 01:27:45 +09:00
|
|
|
geom.x += vmetric[1] * fontSize * current.fontMatrix[0] /
|
2013-02-08 21:29:22 +09:00
|
|
|
fontSizeScale * geom.hScale;
|
|
|
|
geom.y += vmetric[2] * fontSize * current.fontMatrix[0] /
|
|
|
|
fontSizeScale * geom.vScale;
|
|
|
|
}
|
2012-10-09 22:25:41 +09:00
|
|
|
this.textLayer.appendText(geom);
|
2012-09-20 05:17:01 +09:00
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
nextLineShowText: function CanvasGraphics_nextLineShowText(text) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.nextLine();
|
|
|
|
this.showText(text);
|
|
|
|
},
|
|
|
|
nextLineSetSpacingShowText:
|
2012-04-05 05:43:26 +09:00
|
|
|
function CanvasGraphics_nextLineSetSpacingShowText(wordSpacing,
|
|
|
|
charSpacing,
|
|
|
|
text) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.setWordSpacing(wordSpacing);
|
|
|
|
this.setCharSpacing(charSpacing);
|
|
|
|
this.nextLineShowText(text);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Type3 fonts
|
2012-04-05 05:43:26 +09:00
|
|
|
setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
|
2011-10-25 08:55:23 +09:00
|
|
|
// We can safely ignore this since the width should be the same
|
|
|
|
// as the width in the Widths array.
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
|
2011-10-25 08:55:23 +09:00
|
|
|
yWidth,
|
|
|
|
llx,
|
|
|
|
lly,
|
|
|
|
urx,
|
|
|
|
ury) {
|
|
|
|
// TODO According to the spec we're also suppose to ignore any operators
|
|
|
|
// that set color or include images while processing this type3 font.
|
|
|
|
this.rectangle(llx, lly, urx - llx, ury - lly);
|
|
|
|
this.clip();
|
|
|
|
this.endPath();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Color
|
2012-04-05 05:43:26 +09:00
|
|
|
setStrokeColorSpace: function CanvasGraphics_setStrokeColorSpace(raw) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.current.strokeColorSpace = ColorSpace.fromIR(raw);
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setFillColorSpace: function CanvasGraphics_setFillColorSpace(raw) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.current.fillColorSpace = ColorSpace.fromIR(raw);
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setStrokeColor: function CanvasGraphics_setStrokeColor(/*...*/) {
|
2011-10-25 08:55:23 +09:00
|
|
|
var cs = this.current.strokeColorSpace;
|
2012-11-29 10:32:27 +09:00
|
|
|
var rgbColor = cs.getRgb(arguments, 0);
|
|
|
|
var color = Util.makeCssRgb(rgbColor);
|
2011-11-16 11:16:22 +09:00
|
|
|
this.ctx.strokeStyle = color;
|
|
|
|
this.current.strokeColor = color;
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR, cs) {
|
2011-10-25 08:55:23 +09:00
|
|
|
if (IR[0] == 'TilingPattern') {
|
|
|
|
var args = IR[1];
|
|
|
|
var base = cs.base;
|
|
|
|
var color;
|
|
|
|
if (base) {
|
|
|
|
var baseComps = base.numComps;
|
|
|
|
|
2012-11-29 10:32:27 +09:00
|
|
|
color = base.getRgb(args, 0);
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
2013-03-03 21:36:44 +09:00
|
|
|
var pattern = new TilingPattern(IR, color, this.ctx, this.objs,
|
|
|
|
this.commonObjs);
|
2011-10-26 01:10:56 +09:00
|
|
|
} else if (IR[0] == 'RadialAxial' || IR[0] == 'Dummy') {
|
2012-03-30 00:53:51 +09:00
|
|
|
var pattern = Pattern.shadingFromIR(IR);
|
2011-10-25 08:55:23 +09:00
|
|
|
} else {
|
2012-01-25 05:04:59 +09:00
|
|
|
error('Unkown IR type ' + IR[0]);
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
|
|
|
return pattern;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
|
2011-10-25 08:55:23 +09:00
|
|
|
var cs = this.current.strokeColorSpace;
|
|
|
|
|
|
|
|
if (cs.name == 'Pattern') {
|
2012-02-21 22:36:15 +09:00
|
|
|
this.current.strokeColor = this.getColorN_Pattern(arguments, cs);
|
2011-10-25 08:55:23 +09:00
|
|
|
} else {
|
|
|
|
this.setStrokeColor.apply(this, arguments);
|
|
|
|
}
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setFillColor: function CanvasGraphics_setFillColor(/*...*/) {
|
2011-10-25 08:55:23 +09:00
|
|
|
var cs = this.current.fillColorSpace;
|
2012-11-29 10:32:27 +09:00
|
|
|
var rgbColor = cs.getRgb(arguments, 0);
|
|
|
|
var color = Util.makeCssRgb(rgbColor);
|
2011-11-16 11:16:22 +09:00
|
|
|
this.ctx.fillStyle = color;
|
|
|
|
this.current.fillColor = color;
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
|
2011-10-25 08:55:23 +09:00
|
|
|
var cs = this.current.fillColorSpace;
|
|
|
|
|
|
|
|
if (cs.name == 'Pattern') {
|
2012-02-21 22:36:15 +09:00
|
|
|
this.current.fillColor = this.getColorN_Pattern(arguments, cs);
|
2011-10-25 08:55:23 +09:00
|
|
|
} else {
|
|
|
|
this.setFillColor.apply(this, arguments);
|
|
|
|
}
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setStrokeGray: function CanvasGraphics_setStrokeGray(gray) {
|
2011-11-16 09:23:45 +09:00
|
|
|
if (!(this.current.strokeColorSpace instanceof DeviceGrayCS))
|
|
|
|
this.current.strokeColorSpace = new DeviceGrayCS();
|
|
|
|
|
2012-11-29 10:32:27 +09:00
|
|
|
var rgbColor = this.current.strokeColorSpace.getRgb(arguments, 0);
|
|
|
|
var color = Util.makeCssRgb(rgbColor);
|
2011-11-16 11:16:22 +09:00
|
|
|
this.ctx.strokeStyle = color;
|
|
|
|
this.current.strokeColor = color;
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setFillGray: function CanvasGraphics_setFillGray(gray) {
|
2011-11-16 09:23:45 +09:00
|
|
|
if (!(this.current.fillColorSpace instanceof DeviceGrayCS))
|
|
|
|
this.current.fillColorSpace = new DeviceGrayCS();
|
|
|
|
|
2012-11-29 10:32:27 +09:00
|
|
|
var rgbColor = this.current.fillColorSpace.getRgb(arguments, 0);
|
|
|
|
var color = Util.makeCssRgb(rgbColor);
|
2011-11-16 11:16:22 +09:00
|
|
|
this.ctx.fillStyle = color;
|
|
|
|
this.current.fillColor = color;
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
|
2011-11-16 09:23:45 +09:00
|
|
|
if (!(this.current.strokeColorSpace instanceof DeviceRgbCS))
|
|
|
|
this.current.strokeColorSpace = new DeviceRgbCS();
|
|
|
|
|
2012-11-29 10:32:27 +09:00
|
|
|
var rgbColor = this.current.strokeColorSpace.getRgb(arguments, 0);
|
|
|
|
var color = Util.makeCssRgb(rgbColor);
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.strokeStyle = color;
|
|
|
|
this.current.strokeColor = color;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
|
2011-11-16 09:23:45 +09:00
|
|
|
if (!(this.current.fillColorSpace instanceof DeviceRgbCS))
|
|
|
|
this.current.fillColorSpace = new DeviceRgbCS();
|
|
|
|
|
2012-11-29 10:32:27 +09:00
|
|
|
var rgbColor = this.current.fillColorSpace.getRgb(arguments, 0);
|
|
|
|
var color = Util.makeCssRgb(rgbColor);
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.fillStyle = color;
|
|
|
|
this.current.fillColor = color;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setStrokeCMYKColor: function CanvasGraphics_setStrokeCMYKColor(c, m, y, k) {
|
2011-11-16 09:23:45 +09:00
|
|
|
if (!(this.current.strokeColorSpace instanceof DeviceCmykCS))
|
|
|
|
this.current.strokeColorSpace = new DeviceCmykCS();
|
|
|
|
|
2012-11-29 10:32:27 +09:00
|
|
|
var color = Util.makeCssCmyk(arguments);
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.strokeStyle = color;
|
|
|
|
this.current.strokeColor = color;
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
setFillCMYKColor: function CanvasGraphics_setFillCMYKColor(c, m, y, k) {
|
2011-11-16 09:23:45 +09:00
|
|
|
if (!(this.current.fillColorSpace instanceof DeviceCmykCS))
|
|
|
|
this.current.fillColorSpace = new DeviceCmykCS();
|
|
|
|
|
2012-11-29 10:32:27 +09:00
|
|
|
var color = Util.makeCssCmyk(arguments);
|
2011-10-25 08:55:23 +09:00
|
|
|
this.ctx.fillStyle = color;
|
|
|
|
this.current.fillColor = color;
|
|
|
|
},
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
shadingFill: function CanvasGraphics_shadingFill(patternIR) {
|
2011-10-25 08:55:23 +09:00
|
|
|
var ctx = this.ctx;
|
|
|
|
|
|
|
|
this.save();
|
2012-03-30 00:53:51 +09:00
|
|
|
var pattern = Pattern.shadingFromIR(patternIR);
|
|
|
|
ctx.fillStyle = pattern.getPattern(ctx);
|
2011-10-25 08:55:23 +09:00
|
|
|
|
|
|
|
var inv = ctx.mozCurrentTransformInverse;
|
|
|
|
if (inv) {
|
|
|
|
var canvas = ctx.canvas;
|
|
|
|
var width = canvas.width;
|
|
|
|
var height = canvas.height;
|
|
|
|
|
|
|
|
var bl = Util.applyTransform([0, 0], inv);
|
2011-12-07 21:42:01 +09:00
|
|
|
var br = Util.applyTransform([0, height], inv);
|
|
|
|
var ul = Util.applyTransform([width, 0], inv);
|
|
|
|
var ur = Util.applyTransform([width, height], inv);
|
2011-10-25 08:55:23 +09:00
|
|
|
|
|
|
|
var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
|
|
|
|
var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
|
|
|
|
var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
|
|
|
|
var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
|
|
|
|
|
|
|
|
this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
|
|
|
|
} else {
|
|
|
|
// HACK to draw the gradient onto an infinite rectangle.
|
|
|
|
// PDF gradients are drawn across the entire image while
|
|
|
|
// Canvas only allows gradients to be drawn in a rectangle
|
|
|
|
// The following bug should allow us to remove this.
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=664884
|
|
|
|
|
|
|
|
this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.restore();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Images
|
2012-04-05 05:43:26 +09:00
|
|
|
beginInlineImage: function CanvasGraphics_beginInlineImage() {
|
2011-10-25 08:55:23 +09:00
|
|
|
error('Should not call beginInlineImage');
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
beginImageData: function CanvasGraphics_beginImageData() {
|
2011-10-25 08:55:23 +09:00
|
|
|
error('Should not call beginImageData');
|
|
|
|
},
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
|
2011-10-30 20:46:15 +09:00
|
|
|
bbox) {
|
2011-10-25 08:55:23 +09:00
|
|
|
this.save();
|
2012-10-27 13:30:01 +09:00
|
|
|
this.current.paintFormXObjectDepth++;
|
2011-10-25 08:55:23 +09:00
|
|
|
|
|
|
|
if (matrix && isArray(matrix) && 6 == matrix.length)
|
|
|
|
this.transform.apply(this, matrix);
|
|
|
|
|
|
|
|
if (bbox && isArray(bbox) && 4 == bbox.length) {
|
|
|
|
var width = bbox[2] - bbox[0];
|
|
|
|
var height = bbox[3] - bbox[1];
|
|
|
|
this.rectangle(bbox[0], bbox[1], width, height);
|
|
|
|
this.clip();
|
|
|
|
this.endPath();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
|
2012-10-27 13:30:01 +09:00
|
|
|
var depth = this.current.paintFormXObjectDepth;
|
|
|
|
do {
|
|
|
|
this.restore();
|
|
|
|
// some pdf don't close all restores inside object
|
|
|
|
// closing those for them
|
|
|
|
} while (this.current.paintFormXObjectDepth >= depth);
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
|
|
|
|
2013-03-13 09:20:38 +09:00
|
|
|
beginGroup: function CanvasGraphics_beginGroup(group) {
|
|
|
|
this.save();
|
|
|
|
var currentCtx = this.ctx;
|
|
|
|
// TODO non-isolated groups - according to Rik at adobe non-isolated
|
|
|
|
// group results aren't usually that different and they even have tools
|
|
|
|
// that ignore this setting. Notes from Rik on implmenting:
|
|
|
|
// - When you encounter an transparency group, create a new canvas with
|
|
|
|
// the dimensions of the bbox
|
|
|
|
// - copy the content from the previous canvas to the new canvas
|
|
|
|
// - draw as usual
|
|
|
|
// - remove the backdrop alpha:
|
|
|
|
// alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
|
|
|
|
// value of your transparency group and 'alphaBackdrop' the alpha of the
|
|
|
|
// backdrop
|
|
|
|
// - remove background color:
|
|
|
|
// colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
|
|
|
|
if (!group.isolated) {
|
2013-04-17 07:45:29 +09:00
|
|
|
info('TODO: Support non-isolated groups.');
|
2013-03-13 09:20:38 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO knockout - supposedly possible with the clever use of compositing
|
|
|
|
// modes.
|
|
|
|
if (group.knockout) {
|
|
|
|
TODO('Support knockout groups.');
|
|
|
|
}
|
|
|
|
|
|
|
|
var currentTransform = currentCtx.mozCurrentTransform;
|
|
|
|
if (group.matrix) {
|
|
|
|
currentCtx.transform.apply(currentCtx, group.matrix);
|
|
|
|
}
|
|
|
|
assert(group.bbox, 'Bounding box is required.');
|
|
|
|
|
|
|
|
// Based on the current transform figure out how big the bounding box
|
|
|
|
// will actually be.
|
|
|
|
var bounds = Util.getAxialAlignedBoundingBox(
|
|
|
|
group.bbox,
|
|
|
|
currentCtx.mozCurrentTransform);
|
|
|
|
// Use ceil in case we're between sizes so we don't create canvas that is
|
2013-04-12 03:19:42 +09:00
|
|
|
// too small and make the canvas at least 1x1 pixels.
|
|
|
|
var drawnWidth = Math.max(Math.ceil(bounds[2] - bounds[0]), 1);
|
|
|
|
var drawnHeight = Math.max(Math.ceil(bounds[3] - bounds[1]), 1);
|
|
|
|
|
2013-03-13 09:20:38 +09:00
|
|
|
var scratchCanvas = createScratchCanvas(drawnWidth, drawnHeight);
|
|
|
|
var groupCtx = scratchCanvas.getContext('2d');
|
|
|
|
addContextCurrentTransform(groupCtx);
|
|
|
|
// Since we created a new canvas that is just the size of the bounding box
|
|
|
|
// we have to translate the group ctx.
|
|
|
|
var offsetX = bounds[0];
|
|
|
|
var offsetY = bounds[1];
|
|
|
|
groupCtx.translate(-offsetX, -offsetY);
|
|
|
|
groupCtx.transform.apply(groupCtx, currentTransform);
|
|
|
|
|
|
|
|
// Setup the current ctx so when the group is popped we draw it the right
|
|
|
|
// location.
|
|
|
|
currentCtx.setTransform(1, 0, 0, 1, 0, 0);
|
|
|
|
currentCtx.translate(offsetX, offsetY);
|
|
|
|
|
|
|
|
// The transparency group inherits all off the current graphics state
|
|
|
|
// except the blend mode, soft mask, and alpha constants.
|
|
|
|
copyCtxState(currentCtx, groupCtx);
|
|
|
|
this.ctx = groupCtx;
|
|
|
|
this.setGState([
|
|
|
|
['SMask', 'None'],
|
|
|
|
['BM', 'Normal'],
|
|
|
|
['ca', 1],
|
|
|
|
['CA', 1]
|
|
|
|
]);
|
|
|
|
this.groupStack.push(currentCtx);
|
|
|
|
},
|
|
|
|
|
|
|
|
endGroup: function CanvasGraphics_endGroup(group) {
|
|
|
|
var groupCtx = this.ctx;
|
|
|
|
this.ctx = this.groupStack.pop();
|
|
|
|
// Turn off image smoothing to avoid sub pixel interpolation which can
|
|
|
|
// look kind of blurry for some pdfs.
|
|
|
|
if ('imageSmoothingEnabled' in this.ctx) {
|
|
|
|
this.ctx.imageSmoothingEnabled = false;
|
|
|
|
} else {
|
|
|
|
this.ctx.mozImageSmoothingEnabled = false;
|
|
|
|
}
|
|
|
|
this.ctx.drawImage(groupCtx.canvas, 0, 0);
|
|
|
|
this.restore();
|
|
|
|
},
|
|
|
|
|
2013-05-29 07:12:35 +09:00
|
|
|
beginAnnotations: function CanvasGraphics_beginAnnotations() {
|
|
|
|
this.save();
|
|
|
|
this.current = new CanvasExtraState();
|
|
|
|
},
|
|
|
|
|
|
|
|
endAnnotations: function CanvasGraphics_endAnnotations() {
|
|
|
|
this.restore();
|
|
|
|
},
|
|
|
|
|
2013-03-14 04:24:55 +09:00
|
|
|
beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
|
2013-03-21 17:04:44 +09:00
|
|
|
matrix) {
|
2013-03-14 04:24:55 +09:00
|
|
|
this.save();
|
|
|
|
|
|
|
|
if (rect && isArray(rect) && 4 == rect.length) {
|
|
|
|
var width = rect[2] - rect[0];
|
|
|
|
var height = rect[3] - rect[1];
|
|
|
|
this.rectangle(rect[0], rect[1], width, height);
|
|
|
|
this.clip();
|
|
|
|
this.endPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.transform.apply(this, transform);
|
|
|
|
this.transform.apply(this, matrix);
|
|
|
|
},
|
|
|
|
|
|
|
|
endAnnotation: function CanvasGraphics_endAnnotation() {
|
|
|
|
this.restore();
|
|
|
|
},
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
|
2011-12-09 14:18:04 +09:00
|
|
|
var domImage = this.objs.get(objId);
|
|
|
|
if (!domImage) {
|
|
|
|
error('Dependent image isn\'t ready yet');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.save();
|
|
|
|
|
|
|
|
var ctx = this.ctx;
|
|
|
|
// scale the image to the unit square
|
|
|
|
ctx.scale(1 / w, -1 / h);
|
|
|
|
|
|
|
|
ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
|
|
|
|
0, -h, w, h);
|
2013-02-11 03:19:36 +09:00
|
|
|
if (this.imageLayer) {
|
|
|
|
var currentTransform = ctx.mozCurrentTransformInverse;
|
|
|
|
var position = this.getCanvasPosition(0, 0);
|
|
|
|
this.imageLayer.appendImage({
|
|
|
|
objId: objId,
|
|
|
|
left: position[0],
|
|
|
|
top: position[1],
|
2013-02-12 19:30:19 +09:00
|
|
|
width: w / currentTransform[0],
|
|
|
|
height: h / currentTransform[3]
|
2013-02-11 03:19:36 +09:00
|
|
|
});
|
|
|
|
}
|
2011-12-09 14:18:04 +09:00
|
|
|
this.restore();
|
|
|
|
},
|
2011-12-13 02:53:31 +09:00
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(
|
2011-10-30 20:46:15 +09:00
|
|
|
imgArray, inverseDecode, width, height) {
|
2012-12-08 03:19:43 +09:00
|
|
|
var ctx = this.ctx;
|
2013-05-11 12:50:14 +09:00
|
|
|
var glyph = this.processingType3;
|
|
|
|
|
|
|
|
if (COMPILE_TYPE3_GLYPHS && glyph && !('compiled' in glyph)) {
|
|
|
|
var MAX_SIZE_TO_COMPILE = 1000;
|
|
|
|
if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
|
|
|
|
var pixels = new Uint8Array(width * height * 4);
|
|
|
|
for (var i = 3, ii = pixels.length; i < ii; i += 4) {
|
|
|
|
pixels[i] = 255;
|
|
|
|
}
|
|
|
|
applyStencilMask(imgArray, width, height, inverseDecode, pixels);
|
|
|
|
glyph.compiled =
|
|
|
|
compileType3Glyph({data: pixels, width: width, height: height});
|
|
|
|
} else {
|
|
|
|
glyph.compiled = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glyph && glyph.compiled) {
|
|
|
|
glyph.compiled(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-08 03:19:43 +09:00
|
|
|
var tmpCanvas = createScratchCanvas(width, height);
|
2011-10-25 08:55:23 +09:00
|
|
|
var tmpCtx = tmpCanvas.getContext('2d');
|
|
|
|
|
|
|
|
var fillColor = this.current.fillColor;
|
|
|
|
tmpCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
|
|
|
|
fillColor.type === 'Pattern') ?
|
|
|
|
fillColor.getPattern(tmpCtx) : fillColor;
|
2012-12-08 03:19:43 +09:00
|
|
|
tmpCtx.fillRect(0, 0, width, height);
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2012-12-08 03:19:43 +09:00
|
|
|
var imgData = tmpCtx.getImageData(0, 0, width, height);
|
2011-10-25 08:55:23 +09:00
|
|
|
var pixels = imgData.data;
|
|
|
|
|
2012-12-08 03:19:43 +09:00
|
|
|
applyStencilMask(imgArray, width, height, inverseDecode, pixels);
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2012-12-08 03:19:43 +09:00
|
|
|
this.paintInlineImageXObject(imgData);
|
|
|
|
},
|
|
|
|
|
|
|
|
paintImageMaskXObjectGroup:
|
|
|
|
function CanvasGraphics_paintImageMaskXObjectGroup(images) {
|
|
|
|
var ctx = this.ctx;
|
|
|
|
var tmpCanvasWidth = 0, tmpCanvasHeight = 0, tmpCanvas, tmpCtx;
|
|
|
|
for (var i = 0, ii = images.length; i < ii; i++) {
|
|
|
|
var image = images[i];
|
|
|
|
var w = image.width, h = image.height;
|
|
|
|
if (w > tmpCanvasWidth || h > tmpCanvasHeight) {
|
|
|
|
tmpCanvasWidth = Math.max(w, tmpCanvasWidth);
|
|
|
|
tmpCanvasHeight = Math.max(h, tmpCanvasHeight);
|
|
|
|
tmpCanvas = createScratchCanvas(tmpCanvasWidth, tmpCanvasHeight);
|
|
|
|
tmpCtx = tmpCanvas.getContext('2d');
|
|
|
|
|
|
|
|
var fillColor = this.current.fillColor;
|
|
|
|
tmpCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
|
|
|
|
fillColor.type === 'Pattern') ?
|
|
|
|
fillColor.getPattern(tmpCtx) : fillColor;
|
|
|
|
}
|
|
|
|
tmpCtx.fillRect(0, 0, w, h);
|
|
|
|
|
|
|
|
var imgData = tmpCtx.getImageData(0, 0, w, h);
|
|
|
|
var pixels = imgData.data;
|
|
|
|
|
|
|
|
applyStencilMask(image.data, w, h, image.inverseDecode, pixels);
|
|
|
|
|
|
|
|
tmpCtx.putImageData(imgData, 0, 0);
|
|
|
|
|
|
|
|
ctx.save();
|
|
|
|
ctx.transform.apply(ctx, image.transform);
|
|
|
|
ctx.scale(1, -1);
|
|
|
|
ctx.drawImage(tmpCanvas, 0, 0, w, h,
|
|
|
|
0, -1, 1, 1);
|
|
|
|
ctx.restore();
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
|
2011-12-09 05:50:34 +09:00
|
|
|
var imgData = this.objs.get(objId);
|
2011-12-16 08:13:48 +09:00
|
|
|
if (!imgData)
|
2011-12-09 05:50:34 +09:00
|
|
|
error('Dependent image isn\'t ready yet');
|
2011-12-16 08:13:48 +09:00
|
|
|
|
2012-12-08 03:19:43 +09:00
|
|
|
this.paintInlineImageXObject(imgData);
|
2012-12-05 02:36:42 +09:00
|
|
|
},
|
|
|
|
|
2012-12-08 03:19:43 +09:00
|
|
|
paintInlineImageXObject:
|
|
|
|
function CanvasGraphics_paintInlineImageXObject(imgData) {
|
2012-12-05 02:36:42 +09:00
|
|
|
var width = imgData.width;
|
|
|
|
var height = imgData.height;
|
2011-10-25 08:55:23 +09:00
|
|
|
var ctx = this.ctx;
|
2012-12-05 02:36:42 +09:00
|
|
|
this.save();
|
2011-10-25 08:55:23 +09:00
|
|
|
// scale the image to the unit square
|
2012-12-05 02:36:42 +09:00
|
|
|
ctx.scale(1 / width, -1 / height);
|
2011-10-25 08:55:23 +09:00
|
|
|
|
2012-12-05 02:36:42 +09:00
|
|
|
var currentTransform = ctx.mozCurrentTransformInverse;
|
|
|
|
var widthScale = Math.max(Math.abs(currentTransform[0]), 1);
|
|
|
|
var heightScale = Math.max(Math.abs(currentTransform[3]), 1);
|
|
|
|
var tmpCanvas = createScratchCanvas(width, height);
|
2011-10-25 08:55:23 +09:00
|
|
|
var tmpCtx = tmpCanvas.getContext('2d');
|
|
|
|
|
2012-12-22 07:31:57 +09:00
|
|
|
if (widthScale > 2 || heightScale > 2) {
|
2012-12-05 02:36:42 +09:00
|
|
|
// canvas does not resize well large images to small -- using simple
|
|
|
|
// algorithm to perform pre-scaling
|
2012-12-22 07:31:57 +09:00
|
|
|
tmpCanvas = prescaleImage(imgData.data,
|
2012-12-05 02:36:42 +09:00
|
|
|
width, height,
|
|
|
|
widthScale, heightScale);
|
2012-12-22 07:31:57 +09:00
|
|
|
ctx.drawImage(tmpCanvas, 0, 0, tmpCanvas.width, tmpCanvas.height,
|
|
|
|
0, -height, width, height);
|
2012-12-05 02:36:42 +09:00
|
|
|
} else {
|
|
|
|
if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
|
|
|
|
tmpCtx.putImageData(imgData, 0, 0);
|
|
|
|
} else {
|
2012-12-22 07:31:57 +09:00
|
|
|
putBinaryImageData(tmpCtx, imgData.data, width, height);
|
2012-12-05 02:36:42 +09:00
|
|
|
}
|
|
|
|
ctx.drawImage(tmpCanvas, 0, -height);
|
|
|
|
}
|
2013-02-11 03:19:36 +09:00
|
|
|
|
|
|
|
if (this.imageLayer) {
|
|
|
|
var position = this.getCanvasPosition(0, -height);
|
|
|
|
this.imageLayer.appendImage({
|
|
|
|
imgData: imgData,
|
|
|
|
left: position[0],
|
|
|
|
top: position[1],
|
2013-02-12 19:30:19 +09:00
|
|
|
width: width / currentTransform[0],
|
|
|
|
height: height / currentTransform[3]
|
2013-02-11 03:19:36 +09:00
|
|
|
});
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
this.restore();
|
|
|
|
},
|
|
|
|
|
2012-12-08 03:19:43 +09:00
|
|
|
paintInlineImageXObjectGroup:
|
|
|
|
function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
|
|
|
|
var ctx = this.ctx;
|
|
|
|
var w = imgData.width;
|
|
|
|
var h = imgData.height;
|
|
|
|
|
|
|
|
var tmpCanvas = createScratchCanvas(w, h);
|
|
|
|
var tmpCtx = tmpCanvas.getContext('2d');
|
2012-12-22 07:31:57 +09:00
|
|
|
putBinaryImageData(tmpCtx, imgData.data, w, h);
|
2012-12-08 03:19:43 +09:00
|
|
|
|
|
|
|
for (var i = 0, ii = map.length; i < ii; i++) {
|
|
|
|
var entry = map[i];
|
|
|
|
ctx.save();
|
|
|
|
ctx.transform.apply(ctx, entry.transform);
|
|
|
|
ctx.scale(1, -1);
|
|
|
|
ctx.drawImage(tmpCanvas, entry.x, entry.y, entry.w, entry.h,
|
|
|
|
0, -1, 1, 1);
|
2013-02-11 03:19:36 +09:00
|
|
|
if (this.imageLayer) {
|
|
|
|
var position = this.getCanvasPosition(entry.x, entry.y);
|
|
|
|
this.imageLayer.appendImage({
|
|
|
|
imgData: imgData,
|
|
|
|
left: position[0],
|
|
|
|
top: position[1],
|
|
|
|
width: w,
|
|
|
|
height: h
|
|
|
|
});
|
|
|
|
}
|
2012-12-08 03:19:43 +09:00
|
|
|
ctx.restore();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-10-25 08:55:23 +09:00
|
|
|
// Marked content
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
markPoint: function CanvasGraphics_markPoint(tag) {
|
2012-07-21 01:09:48 +09:00
|
|
|
// TODO Marked content.
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
|
2012-07-21 01:09:48 +09:00
|
|
|
// TODO Marked content.
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
|
2012-07-21 01:09:48 +09:00
|
|
|
// TODO Marked content.
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
|
|
|
|
tag, properties) {
|
2012-07-21 01:09:48 +09:00
|
|
|
// TODO Marked content.
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
endMarkedContent: function CanvasGraphics_endMarkedContent() {
|
2012-07-21 01:09:48 +09:00
|
|
|
// TODO Marked content.
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
// Compatibility
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
beginCompat: function CanvasGraphics_beginCompat() {
|
2013-02-06 03:57:59 +09:00
|
|
|
// TODO ignore undefined operators (should we do that anyway?)
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
endCompat: function CanvasGraphics_endCompat() {
|
2013-02-06 03:57:59 +09:00
|
|
|
// TODO stop ignoring undefined operators
|
2011-10-25 08:55:23 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
// Helper functions
|
|
|
|
|
2012-04-05 05:43:26 +09:00
|
|
|
consumePath: function CanvasGraphics_consumePath() {
|
2011-10-25 08:55:23 +09:00
|
|
|
if (this.pendingClip) {
|
2013-05-04 08:47:40 +09:00
|
|
|
if (this.pendingClip == EO_CLIP) {
|
|
|
|
if ('mozFillRule' in this.ctx) {
|
|
|
|
this.ctx.mozFillRule = 'evenodd';
|
|
|
|
this.ctx.clip();
|
|
|
|
this.ctx.mozFillRule = 'nonzero';
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
this.ctx.clip('evenodd');
|
|
|
|
} catch (ex) {
|
|
|
|
// shouldn't really happen, but browsers might think differently
|
|
|
|
this.ctx.clip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.ctx.clip();
|
|
|
|
}
|
2011-10-25 08:55:23 +09:00
|
|
|
this.pendingClip = null;
|
|
|
|
}
|
|
|
|
this.ctx.beginPath();
|
|
|
|
},
|
2012-04-05 05:43:26 +09:00
|
|
|
getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
|
2012-01-18 13:50:49 +09:00
|
|
|
var inverse = this.ctx.mozCurrentTransformInverse;
|
2012-11-02 22:10:22 +09:00
|
|
|
// max of the current horizontal and vertical scale
|
|
|
|
return Math.sqrt(Math.max(
|
|
|
|
(inverse[0] * inverse[0] + inverse[1] * inverse[1]),
|
|
|
|
(inverse[2] * inverse[2] + inverse[3] * inverse[3])));
|
2013-02-11 03:19:36 +09:00
|
|
|
},
|
|
|
|
getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
|
|
|
|
var transform = this.ctx.mozCurrentTransform;
|
|
|
|
return [
|
|
|
|
transform[0] * x + transform[2] * y + transform[4],
|
|
|
|
transform[1] * x + transform[3] * y + transform[5]
|
|
|
|
];
|
2011-10-25 08:55:23 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-09 07:18:43 +09:00
|
|
|
return CanvasGraphics;
|
2011-10-25 08:55:23 +09:00
|
|
|
})();
|
2011-10-28 03:51:10 +09:00
|
|
|
|