Browse Source

PDF.js version 1.0.268

master v1.0.268
Yury Delendik 10 years ago
parent
commit
73759dca08
  1. 2
      bower.json
  2. 214
      build/pdf.combined.js
  3. 195
      build/pdf.js
  4. 23
      build/pdf.worker.js
  5. 2
      package.json

2
bower.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.0.266", "version": "1.0.268",
"keywords": [ "keywords": [
"Mozilla", "Mozilla",
"pdf", "pdf",

214
build/pdf.combined.js

@ -21,8 +21,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.0.266'; PDFJS.version = '1.0.268';
PDFJS.build = '5b16323'; PDFJS.build = '7e6cdc7';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -4014,6 +4014,7 @@ var CanvasExtraState = (function CanvasExtraStateClosure() {
this.fontSize = 0; this.fontSize = 0;
this.fontSizeScale = 1; this.fontSizeScale = 1;
this.textMatrix = IDENTITY_MATRIX; this.textMatrix = IDENTITY_MATRIX;
this.textMatrixScale = 1;
this.fontMatrix = FONT_IDENTITY_MATRIX; this.fontMatrix = FONT_IDENTITY_MATRIX;
this.leading = 0; this.leading = 0;
// Current point (in user coordinates) // Current point (in user coordinates)
@ -4780,6 +4781,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
// Text // Text
beginText: function CanvasGraphics_beginText() { beginText: function CanvasGraphics_beginText() {
this.current.textMatrix = IDENTITY_MATRIX; this.current.textMatrix = IDENTITY_MATRIX;
this.current.textMatrixScale = 1;
this.current.x = this.current.lineX = 0; this.current.x = this.current.lineX = 0;
this.current.y = this.current.lineY = 0; this.current.y = this.current.lineY = 0;
}, },
@ -4884,6 +4886,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}, },
setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) { setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
this.current.textMatrix = [a, b, c, d, e, f]; this.current.textMatrix = [a, b, c, d, e, f];
this.current.textMatrixScale = Math.sqrt(a * a + b * b);
this.current.x = this.current.lineX = 0; this.current.x = this.current.lineX = 0;
this.current.y = this.current.lineY = 0; this.current.y = this.current.lineY = 0;
@ -4891,24 +4894,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
nextLine: function CanvasGraphics_nextLine() { nextLine: function CanvasGraphics_nextLine() {
this.moveText(0, this.current.leading); this.moveText(0, this.current.leading);
}, },
applyTextTransforms: function CanvasGraphics_applyTextTransforms() {
var ctx = this.ctx;
var current = this.current;
ctx.transform.apply(ctx, current.textMatrix);
ctx.translate(current.x, current.y + current.textRise);
if (current.fontDirection > 0) {
ctx.scale(current.textHScale, -1);
} else {
ctx.scale(-current.textHScale, 1);
}
},
paintChar: function CanvasGraphics_paintChar(character, x, y) { paintChar: function CanvasGraphics_paintChar(character, x, y) {
var ctx = this.ctx; var ctx = this.ctx;
var current = this.current; var current = this.current;
var font = current.font; var font = current.font;
var fontSize = current.fontSize / current.fontSizeScale;
var textRenderingMode = current.textRenderingMode; var textRenderingMode = current.textRenderingMode;
var fontSize = current.fontSize / current.fontSizeScale;
var fillStrokeMode = textRenderingMode & var fillStrokeMode = textRenderingMode &
TextRenderingMode.FILL_STROKE_MASK; TextRenderingMode.FILL_STROKE_MASK;
var isAddToPathSet = !!(textRenderingMode & var isAddToPathSet = !!(textRenderingMode &
@ -4974,65 +4966,44 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}, },
showText: function CanvasGraphics_showText(glyphs) { showText: function CanvasGraphics_showText(glyphs) {
var ctx = this.ctx;
var current = this.current; var current = this.current;
var font = current.font; var font = current.font;
if (font.isType3Font) {
return this.showType3Text(glyphs);
}
var fontSize = current.fontSize; var fontSize = current.fontSize;
if (fontSize === 0) {
return;
}
var ctx = this.ctx;
var fontSizeScale = current.fontSizeScale; var fontSizeScale = current.fontSizeScale;
var charSpacing = current.charSpacing; var charSpacing = current.charSpacing;
var wordSpacing = current.wordSpacing; var wordSpacing = current.wordSpacing;
var textHScale = current.textHScale * current.fontDirection; var fontDirection = current.fontDirection;
var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX; var textHScale = current.textHScale * fontDirection;
var glyphsLength = glyphs.length; var glyphsLength = glyphs.length;
var vertical = font.vertical; var vertical = font.vertical;
var defaultVMetrics = font.defaultVMetrics; var defaultVMetrics = font.defaultVMetrics;
var i, glyph, width; var widthAdvanceScale = fontSize * current.fontMatrix[0];
if (fontSize === 0) { var simpleFillText =
return; current.textRenderingMode === TextRenderingMode.FILL &&
} !font.disableFontFace;
// Type3 fonts - each glyph is a "mini-PDF"
if (font.isType3Font) {
ctx.save(); ctx.save();
ctx.transform.apply(ctx, current.textMatrix); ctx.transform.apply(ctx, current.textMatrix);
ctx.translate(current.x, current.y); ctx.translate(current.x, current.y + current.textRise);
if (fontDirection > 0) {
ctx.scale(textHScale, -1);
} else {
ctx.scale(textHScale, 1); ctx.scale(textHScale, 1);
for (i = 0; i < glyphsLength; ++i) {
glyph = glyphs[i];
if (glyph === null) {
// word break
this.ctx.translate(wordSpacing, 0);
current.x += wordSpacing * textHScale;
continue;
}
this.processingType3 = glyph;
this.save();
ctx.scale(fontSize, fontSize);
ctx.transform.apply(ctx, fontMatrix);
var operatorList = font.charProcOperatorList[glyph.operatorListId];
this.executeOperatorList(operatorList);
this.restore();
var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
width = ((transformed[0] * fontSize + charSpacing) *
current.fontDirection);
ctx.translate(width, 0);
current.x += width * textHScale;
} }
ctx.restore();
this.processingType3 = null;
} else {
ctx.save();
this.applyTextTransforms();
var lineWidth = current.lineWidth; var lineWidth = current.lineWidth;
var a1 = current.textMatrix[0], b1 = current.textMatrix[1]; var scale = current.textMatrixScale;
var scale = Math.sqrt(a1 * a1 + b1 * b1);
if (scale === 0 || lineWidth === 0) { if (scale === 0 || lineWidth === 0) {
lineWidth = this.getSinglePixelWidth(); lineWidth = this.getSinglePixelWidth();
} else { } else {
@ -5046,31 +5017,31 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
ctx.lineWidth = lineWidth; ctx.lineWidth = lineWidth;
var x = 0; var x = 0, i;
for (i = 0; i < glyphsLength; ++i) { for (i = 0; i < glyphsLength; ++i) {
glyph = glyphs[i]; var glyph = glyphs[i];
if (glyph === null) { if (glyph === null) {
// word break // word break
x += current.fontDirection * wordSpacing; x += fontDirection * wordSpacing;
continue;
} else if (isNum(glyph)) {
x += -glyph * fontSize * 0.001;
continue; continue;
} }
var restoreNeeded = false; var restoreNeeded = false;
var character = glyph.fontChar; var character = glyph.fontChar;
var vmetric = glyph.vmetric || defaultVMetrics;
if (vertical) {
var vx = glyph.vmetric ? vmetric[1] : glyph.width * 0.5;
vx = -vx * fontSize * current.fontMatrix[0];
var vy = vmetric[2] * fontSize * current.fontMatrix[0];
}
width = vmetric ? -vmetric[0] : glyph.width;
var charWidth = width * fontSize * current.fontMatrix[0] +
charSpacing * current.fontDirection;
var accent = glyph.accent; var accent = glyph.accent;
var scaledX, scaledY, scaledAccentX, scaledAccentY; var scaledX, scaledY, scaledAccentX, scaledAccentY;
var width = glyph.width;
if (vertical) { if (vertical) {
var vmetric, vx, vy;
vmetric = glyph.vmetric || defaultVMetrics;
vx = glyph.vmetric ? vmetric[1] : width * 0.5;
vx = -vx * widthAdvanceScale;
vy = vmetric[2] * widthAdvanceScale;
width = vmetric ? -vmetric[0] : width;
scaledX = vx / fontSizeScale; scaledX = vx / fontSizeScale;
scaledY = (x + vy) / fontSizeScale; scaledY = (x + vy) / fontSizeScale;
} else { } else {
@ -5082,24 +5053,27 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
// some standard fonts may not have the exact width, trying to // some standard fonts may not have the exact width, trying to
// rescale per character // rescale per character
var measuredWidth = ctx.measureText(character).width * 1000 / var measuredWidth = ctx.measureText(character).width * 1000 /
current.fontSize * current.fontSizeScale; fontSize * fontSizeScale;
var characterScaleX = width / measuredWidth; var characterScaleX = width / measuredWidth;
restoreNeeded = true; restoreNeeded = true;
ctx.save(); ctx.save();
ctx.scale(characterScaleX, 1); ctx.scale(characterScaleX, 1);
scaledX /= characterScaleX; scaledX /= characterScaleX;
if (accent) {
scaledAccentX /= characterScaleX;
}
} }
if (simpleFillText && !accent) {
// common case
ctx.fillText(character, scaledX, scaledY);
} else {
this.paintChar(character, scaledX, scaledY); this.paintChar(character, scaledX, scaledY);
if (accent) { if (accent) {
scaledAccentX = scaledX + accent.offset.x / fontSizeScale; scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
scaledAccentY = scaledY - accent.offset.y / fontSizeScale; scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY); this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
} }
}
var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
x += charWidth; x += charWidth;
if (restoreNeeded) { if (restoreNeeded) {
@ -5112,43 +5086,62 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
current.x += x * textHScale; current.x += x * textHScale;
} }
ctx.restore(); ctx.restore();
}
}, },
showSpacedText: function CanvasGraphics_showSpacedText(arr) {
showType3Text: function CanvasGraphics_showType3Text(glyphs) {
// Type3 fonts - each glyph is a "mini-PDF"
var ctx = this.ctx;
var current = this.current; var current = this.current;
var font = current.font; var font = current.font;
var fontSize = current.fontSize; var fontSize = current.fontSize;
// TJ array's number is independent from fontMatrix var fontDirection = current.fontDirection;
var textHScale = current.textHScale * 0.001 * current.fontDirection; var charSpacing = current.charSpacing;
var arrLength = arr.length; var wordSpacing = current.wordSpacing;
var vertical = font.vertical; var textHScale = current.textHScale * fontDirection;
var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
var glyphsLength = glyphs.length;
var i, glyph, width;
for (var i = 0; i < arrLength; ++i) { if (fontSize === 0) {
var e = arr[i]; return;
if (isNum(e)) {
var spacingLength = -e * fontSize * textHScale;
if (vertical) {
current.y += spacingLength;
} else {
current.x += spacingLength;
} }
} else { ctx.save();
this.showText(e); ctx.transform.apply(ctx, current.textMatrix);
ctx.translate(current.x, current.y);
ctx.scale(textHScale, 1);
for (i = 0; i < glyphsLength; ++i) {
glyph = glyphs[i];
if (glyph === null) {
// word break
this.ctx.translate(wordSpacing, 0);
current.x += wordSpacing * textHScale;
continue;
} else if (isNum(glyph)) {
var spacingLength = -glyph * 0.001 * fontSize;
this.ctx.translate(spacingLength, 0);
current.x += spacingLength * textHScale;
continue;
} }
this.processingType3 = glyph;
this.save();
ctx.scale(fontSize, fontSize);
ctx.transform.apply(ctx, fontMatrix);
var operatorList = font.charProcOperatorList[glyph.operatorListId];
this.executeOperatorList(operatorList);
this.restore();
var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
width = ((transformed[0] * fontSize + charSpacing) * fontDirection);
ctx.translate(width, 0);
current.x += width * textHScale;
} }
}, ctx.restore();
nextLineShowText: function CanvasGraphics_nextLineShowText(text) { this.processingType3 = null;
this.nextLine();
this.showText(text);
},
nextLineSetSpacingShowText:
function CanvasGraphics_nextLineSetSpacingShowText(wordSpacing,
charSpacing,
text) {
this.setWordSpacing(wordSpacing);
this.setCharSpacing(charSpacing);
this.nextLineShowText(text);
}, },
// Type3 fonts // Type3 fonts
@ -20673,18 +20666,31 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
break; break;
case OPS.showSpacedText: case OPS.showSpacedText:
var arr = args[0]; var arr = args[0];
var combinedGlyphs = [];
var arrLength = arr.length; var arrLength = arr.length;
for (i = 0; i < arrLength; ++i) { for (i = 0; i < arrLength; ++i) {
if (isString(arr[i])) { var arrItem = arr[i];
arr[i] = self.handleText(arr[i], stateManager.state); if (isString(arrItem)) {
Array.prototype.push.apply(combinedGlyphs,
self.handleText(arrItem, stateManager.state));
} else if (isNum(arrItem)) {
combinedGlyphs.push(arrItem);
} }
} }
args[0] = combinedGlyphs;
fn = OPS.showText;
break; break;
case OPS.nextLineShowText: case OPS.nextLineShowText:
operatorList.addOp(OPS.nextLine);
args[0] = self.handleText(args[0], stateManager.state); args[0] = self.handleText(args[0], stateManager.state);
fn = OPS.showText;
break; break;
case OPS.nextLineSetSpacingShowText: case OPS.nextLineSetSpacingShowText:
args[2] = self.handleText(args[2], stateManager.state); operatorList.addOp(OPS.nextLine);
operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
args[0] = self.handleText(args[0], stateManager.state);
fn = OPS.showText;
break; break;
case OPS.setTextRenderingMode: case OPS.setTextRenderingMode:
stateManager.state.textRenderingMode = args[0]; stateManager.state.textRenderingMode = args[0];

195
build/pdf.js

@ -21,8 +21,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.0.266'; PDFJS.version = '1.0.268';
PDFJS.build = '5b16323'; PDFJS.build = '7e6cdc7';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -4062,6 +4062,7 @@ var CanvasExtraState = (function CanvasExtraStateClosure() {
this.fontSize = 0; this.fontSize = 0;
this.fontSizeScale = 1; this.fontSizeScale = 1;
this.textMatrix = IDENTITY_MATRIX; this.textMatrix = IDENTITY_MATRIX;
this.textMatrixScale = 1;
this.fontMatrix = FONT_IDENTITY_MATRIX; this.fontMatrix = FONT_IDENTITY_MATRIX;
this.leading = 0; this.leading = 0;
// Current point (in user coordinates) // Current point (in user coordinates)
@ -4828,6 +4829,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
// Text // Text
beginText: function CanvasGraphics_beginText() { beginText: function CanvasGraphics_beginText() {
this.current.textMatrix = IDENTITY_MATRIX; this.current.textMatrix = IDENTITY_MATRIX;
this.current.textMatrixScale = 1;
this.current.x = this.current.lineX = 0; this.current.x = this.current.lineX = 0;
this.current.y = this.current.lineY = 0; this.current.y = this.current.lineY = 0;
}, },
@ -4932,6 +4934,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}, },
setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) { setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
this.current.textMatrix = [a, b, c, d, e, f]; this.current.textMatrix = [a, b, c, d, e, f];
this.current.textMatrixScale = Math.sqrt(a * a + b * b);
this.current.x = this.current.lineX = 0; this.current.x = this.current.lineX = 0;
this.current.y = this.current.lineY = 0; this.current.y = this.current.lineY = 0;
@ -4939,24 +4942,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
nextLine: function CanvasGraphics_nextLine() { nextLine: function CanvasGraphics_nextLine() {
this.moveText(0, this.current.leading); this.moveText(0, this.current.leading);
}, },
applyTextTransforms: function CanvasGraphics_applyTextTransforms() {
var ctx = this.ctx;
var current = this.current;
ctx.transform.apply(ctx, current.textMatrix);
ctx.translate(current.x, current.y + current.textRise);
if (current.fontDirection > 0) {
ctx.scale(current.textHScale, -1);
} else {
ctx.scale(-current.textHScale, 1);
}
},
paintChar: function CanvasGraphics_paintChar(character, x, y) { paintChar: function CanvasGraphics_paintChar(character, x, y) {
var ctx = this.ctx; var ctx = this.ctx;
var current = this.current; var current = this.current;
var font = current.font; var font = current.font;
var fontSize = current.fontSize / current.fontSizeScale;
var textRenderingMode = current.textRenderingMode; var textRenderingMode = current.textRenderingMode;
var fontSize = current.fontSize / current.fontSizeScale;
var fillStrokeMode = textRenderingMode & var fillStrokeMode = textRenderingMode &
TextRenderingMode.FILL_STROKE_MASK; TextRenderingMode.FILL_STROKE_MASK;
var isAddToPathSet = !!(textRenderingMode & var isAddToPathSet = !!(textRenderingMode &
@ -5022,65 +5014,44 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}, },
showText: function CanvasGraphics_showText(glyphs) { showText: function CanvasGraphics_showText(glyphs) {
var ctx = this.ctx;
var current = this.current; var current = this.current;
var font = current.font; var font = current.font;
if (font.isType3Font) {
return this.showType3Text(glyphs);
}
var fontSize = current.fontSize; var fontSize = current.fontSize;
if (fontSize === 0) {
return;
}
var ctx = this.ctx;
var fontSizeScale = current.fontSizeScale; var fontSizeScale = current.fontSizeScale;
var charSpacing = current.charSpacing; var charSpacing = current.charSpacing;
var wordSpacing = current.wordSpacing; var wordSpacing = current.wordSpacing;
var textHScale = current.textHScale * current.fontDirection; var fontDirection = current.fontDirection;
var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX; var textHScale = current.textHScale * fontDirection;
var glyphsLength = glyphs.length; var glyphsLength = glyphs.length;
var vertical = font.vertical; var vertical = font.vertical;
var defaultVMetrics = font.defaultVMetrics; var defaultVMetrics = font.defaultVMetrics;
var i, glyph, width; var widthAdvanceScale = fontSize * current.fontMatrix[0];
if (fontSize === 0) { var simpleFillText =
return; current.textRenderingMode === TextRenderingMode.FILL &&
} !font.disableFontFace;
// Type3 fonts - each glyph is a "mini-PDF"
if (font.isType3Font) {
ctx.save(); ctx.save();
ctx.transform.apply(ctx, current.textMatrix); ctx.transform.apply(ctx, current.textMatrix);
ctx.translate(current.x, current.y); ctx.translate(current.x, current.y + current.textRise);
if (fontDirection > 0) {
ctx.scale(textHScale, -1);
} else {
ctx.scale(textHScale, 1); ctx.scale(textHScale, 1);
for (i = 0; i < glyphsLength; ++i) {
glyph = glyphs[i];
if (glyph === null) {
// word break
this.ctx.translate(wordSpacing, 0);
current.x += wordSpacing * textHScale;
continue;
}
this.processingType3 = glyph;
this.save();
ctx.scale(fontSize, fontSize);
ctx.transform.apply(ctx, fontMatrix);
var operatorList = font.charProcOperatorList[glyph.operatorListId];
this.executeOperatorList(operatorList);
this.restore();
var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
width = ((transformed[0] * fontSize + charSpacing) *
current.fontDirection);
ctx.translate(width, 0);
current.x += width * textHScale;
} }
ctx.restore();
this.processingType3 = null;
} else {
ctx.save();
this.applyTextTransforms();
var lineWidth = current.lineWidth; var lineWidth = current.lineWidth;
var a1 = current.textMatrix[0], b1 = current.textMatrix[1]; var scale = current.textMatrixScale;
var scale = Math.sqrt(a1 * a1 + b1 * b1);
if (scale === 0 || lineWidth === 0) { if (scale === 0 || lineWidth === 0) {
lineWidth = this.getSinglePixelWidth(); lineWidth = this.getSinglePixelWidth();
} else { } else {
@ -5094,31 +5065,31 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
ctx.lineWidth = lineWidth; ctx.lineWidth = lineWidth;
var x = 0; var x = 0, i;
for (i = 0; i < glyphsLength; ++i) { for (i = 0; i < glyphsLength; ++i) {
glyph = glyphs[i]; var glyph = glyphs[i];
if (glyph === null) { if (glyph === null) {
// word break // word break
x += current.fontDirection * wordSpacing; x += fontDirection * wordSpacing;
continue;
} else if (isNum(glyph)) {
x += -glyph * fontSize * 0.001;
continue; continue;
} }
var restoreNeeded = false; var restoreNeeded = false;
var character = glyph.fontChar; var character = glyph.fontChar;
var vmetric = glyph.vmetric || defaultVMetrics;
if (vertical) {
var vx = glyph.vmetric ? vmetric[1] : glyph.width * 0.5;
vx = -vx * fontSize * current.fontMatrix[0];
var vy = vmetric[2] * fontSize * current.fontMatrix[0];
}
width = vmetric ? -vmetric[0] : glyph.width;
var charWidth = width * fontSize * current.fontMatrix[0] +
charSpacing * current.fontDirection;
var accent = glyph.accent; var accent = glyph.accent;
var scaledX, scaledY, scaledAccentX, scaledAccentY; var scaledX, scaledY, scaledAccentX, scaledAccentY;
var width = glyph.width;
if (vertical) { if (vertical) {
var vmetric, vx, vy;
vmetric = glyph.vmetric || defaultVMetrics;
vx = glyph.vmetric ? vmetric[1] : width * 0.5;
vx = -vx * widthAdvanceScale;
vy = vmetric[2] * widthAdvanceScale;
width = vmetric ? -vmetric[0] : width;
scaledX = vx / fontSizeScale; scaledX = vx / fontSizeScale;
scaledY = (x + vy) / fontSizeScale; scaledY = (x + vy) / fontSizeScale;
} else { } else {
@ -5130,24 +5101,27 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
// some standard fonts may not have the exact width, trying to // some standard fonts may not have the exact width, trying to
// rescale per character // rescale per character
var measuredWidth = ctx.measureText(character).width * 1000 / var measuredWidth = ctx.measureText(character).width * 1000 /
current.fontSize * current.fontSizeScale; fontSize * fontSizeScale;
var characterScaleX = width / measuredWidth; var characterScaleX = width / measuredWidth;
restoreNeeded = true; restoreNeeded = true;
ctx.save(); ctx.save();
ctx.scale(characterScaleX, 1); ctx.scale(characterScaleX, 1);
scaledX /= characterScaleX; scaledX /= characterScaleX;
if (accent) {
scaledAccentX /= characterScaleX;
}
} }
if (simpleFillText && !accent) {
// common case
ctx.fillText(character, scaledX, scaledY);
} else {
this.paintChar(character, scaledX, scaledY); this.paintChar(character, scaledX, scaledY);
if (accent) { if (accent) {
scaledAccentX = scaledX + accent.offset.x / fontSizeScale; scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
scaledAccentY = scaledY - accent.offset.y / fontSizeScale; scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY); this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
} }
}
var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
x += charWidth; x += charWidth;
if (restoreNeeded) { if (restoreNeeded) {
@ -5160,43 +5134,62 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
current.x += x * textHScale; current.x += x * textHScale;
} }
ctx.restore(); ctx.restore();
}
}, },
showSpacedText: function CanvasGraphics_showSpacedText(arr) {
showType3Text: function CanvasGraphics_showType3Text(glyphs) {
// Type3 fonts - each glyph is a "mini-PDF"
var ctx = this.ctx;
var current = this.current; var current = this.current;
var font = current.font; var font = current.font;
var fontSize = current.fontSize; var fontSize = current.fontSize;
// TJ array's number is independent from fontMatrix var fontDirection = current.fontDirection;
var textHScale = current.textHScale * 0.001 * current.fontDirection; var charSpacing = current.charSpacing;
var arrLength = arr.length; var wordSpacing = current.wordSpacing;
var vertical = font.vertical; var textHScale = current.textHScale * fontDirection;
var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
var glyphsLength = glyphs.length;
var i, glyph, width;
for (var i = 0; i < arrLength; ++i) { if (fontSize === 0) {
var e = arr[i]; return;
if (isNum(e)) {
var spacingLength = -e * fontSize * textHScale;
if (vertical) {
current.y += spacingLength;
} else {
current.x += spacingLength;
} }
} else { ctx.save();
this.showText(e); ctx.transform.apply(ctx, current.textMatrix);
ctx.translate(current.x, current.y);
ctx.scale(textHScale, 1);
for (i = 0; i < glyphsLength; ++i) {
glyph = glyphs[i];
if (glyph === null) {
// word break
this.ctx.translate(wordSpacing, 0);
current.x += wordSpacing * textHScale;
continue;
} else if (isNum(glyph)) {
var spacingLength = -glyph * 0.001 * fontSize;
this.ctx.translate(spacingLength, 0);
current.x += spacingLength * textHScale;
continue;
} }
this.processingType3 = glyph;
this.save();
ctx.scale(fontSize, fontSize);
ctx.transform.apply(ctx, fontMatrix);
var operatorList = font.charProcOperatorList[glyph.operatorListId];
this.executeOperatorList(operatorList);
this.restore();
var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
width = ((transformed[0] * fontSize + charSpacing) * fontDirection);
ctx.translate(width, 0);
current.x += width * textHScale;
} }
}, ctx.restore();
nextLineShowText: function CanvasGraphics_nextLineShowText(text) { this.processingType3 = null;
this.nextLine();
this.showText(text);
},
nextLineSetSpacingShowText:
function CanvasGraphics_nextLineSetSpacingShowText(wordSpacing,
charSpacing,
text) {
this.setWordSpacing(wordSpacing);
this.setCharSpacing(charSpacing);
this.nextLineShowText(text);
}, },
// Type3 fonts // Type3 fonts

23
build/pdf.worker.js vendored

@ -21,8 +21,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.0.266'; PDFJS.version = '1.0.268';
PDFJS.build = '5b16323'; PDFJS.build = '7e6cdc7';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -16166,18 +16166,31 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
break; break;
case OPS.showSpacedText: case OPS.showSpacedText:
var arr = args[0]; var arr = args[0];
var combinedGlyphs = [];
var arrLength = arr.length; var arrLength = arr.length;
for (i = 0; i < arrLength; ++i) { for (i = 0; i < arrLength; ++i) {
if (isString(arr[i])) { var arrItem = arr[i];
arr[i] = self.handleText(arr[i], stateManager.state); if (isString(arrItem)) {
Array.prototype.push.apply(combinedGlyphs,
self.handleText(arrItem, stateManager.state));
} else if (isNum(arrItem)) {
combinedGlyphs.push(arrItem);
} }
} }
args[0] = combinedGlyphs;
fn = OPS.showText;
break; break;
case OPS.nextLineShowText: case OPS.nextLineShowText:
operatorList.addOp(OPS.nextLine);
args[0] = self.handleText(args[0], stateManager.state); args[0] = self.handleText(args[0], stateManager.state);
fn = OPS.showText;
break; break;
case OPS.nextLineSetSpacingShowText: case OPS.nextLineSetSpacingShowText:
args[2] = self.handleText(args[2], stateManager.state); operatorList.addOp(OPS.nextLine);
operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
args[0] = self.handleText(args[0], stateManager.state);
fn = OPS.showText;
break; break;
case OPS.setTextRenderingMode: case OPS.setTextRenderingMode:
stateManager.state.textRenderingMode = args[0]; stateManager.state.textRenderingMode = args[0];

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.0.266", "version": "1.0.268",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [
"Mozilla", "Mozilla",

Loading…
Cancel
Save