mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge branch 'master' of git://github.com/mozilla/pdf.js into text-select
Conflicts: src/canvas.js
This commit is contained in:
commit
5e1d78ef20
10 changed files with 52 additions and 31 deletions
|
@ -568,12 +568,12 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
var ctx = this.ctx;
|
||||
var current = this.current;
|
||||
var textHScale = current.textHScale;
|
||||
var font = current.font;
|
||||
var fontMatrix = current.font.fontMatrix || IDENTITY_MATRIX;
|
||||
|
||||
ctx.transform.apply(ctx, current.textMatrix);
|
||||
ctx.scale(1, -1);
|
||||
ctx.translate(current.x, -1 * current.y);
|
||||
ctx.transform.apply(ctx, font.fontMatrix || IDENTITY_MATRIX);
|
||||
ctx.transform.apply(ctx, fontMatrix);
|
||||
ctx.scale(1 / textHScale, 1);
|
||||
},
|
||||
getTextGeometry: function canvasGetTextGeometry() {
|
||||
|
@ -626,6 +626,8 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
var charSpacing = current.charSpacing;
|
||||
var wordSpacing = current.wordSpacing;
|
||||
var textHScale = current.textHScale;
|
||||
var fontMatrix = font.fontMatrix || IDENTITY_MATRIX;
|
||||
var textHScale2 = textHScale * fontMatrix[0];
|
||||
var glyphsLength = glyphs.length;
|
||||
var textLayer = this.textLayer;
|
||||
var text = {str: '', length: 0, canvasWidth: 0, geom: {}};
|
||||
|
@ -644,7 +646,6 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
ctx.transform.apply(ctx, current.textMatrix);
|
||||
ctx.translate(current.x, current.y);
|
||||
|
||||
var fontMatrix = font.fontMatrix || IDENTITY_MATRIX;
|
||||
ctx.scale(1 / textHScale, 1);
|
||||
for (var i = 0; i < glyphsLength; ++i) {
|
||||
|
||||
|
@ -662,13 +663,14 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
this.restore();
|
||||
|
||||
var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
|
||||
var charWidth = transformed[0] * fontSize + charSpacing;
|
||||
ctx.translate(charWidth, 0);
|
||||
current.x += charWidth;
|
||||
var width = transformed[0] * fontSize + charSpacing;
|
||||
|
||||
text.str += glyph.fontChar;
|
||||
ctx.translate(width, 0);
|
||||
current.x += width * textHScale2;
|
||||
|
||||
text.str += glyph.unicode;
|
||||
text.length++;
|
||||
text.canvasWidth += charWidth;
|
||||
text.canvasWidth += width;
|
||||
}
|
||||
ctx.restore();
|
||||
} else {
|
||||
|
@ -689,12 +691,11 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
ctx.fillText(char, width, 0);
|
||||
width += charWidth;
|
||||
|
||||
text.str += char === ' ' ? ' ' : char;
|
||||
text.str += glyph.unicode === ' ' ? ' ' : glyph.unicode;
|
||||
text.length++;
|
||||
text.canvasWidth += charWidth;
|
||||
}
|
||||
|
||||
current.x += width;
|
||||
current.x += width * textHScale2;
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
|
@ -707,7 +708,8 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
var ctx = this.ctx;
|
||||
var current = this.current;
|
||||
var fontSize = current.fontSize;
|
||||
var textHScale = current.textHScale;
|
||||
var textHScale2 = current.textHScale *
|
||||
(current.font.fontMatrix || IDENTITY_MATRIX)[0];
|
||||
var arrLength = arr.length;
|
||||
var textLayer = this.textLayer;
|
||||
var font = current.font;
|
||||
|
@ -724,7 +726,7 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
for (var i = 0; i < arrLength; ++i) {
|
||||
var e = arr[i];
|
||||
if (isNum(e)) {
|
||||
var spacingLength = -e * 0.001 * fontSize * textHScale;
|
||||
var spacingLength = -e * 0.001 * fontSize * textHScale2;
|
||||
current.x += spacingLength;
|
||||
|
||||
if (textSelection) {
|
||||
|
|
15
src/core.js
15
src/core.js
|
@ -560,20 +560,9 @@ var PDFDoc = (function pdfDoc() {
|
|||
var properties = data[4];
|
||||
|
||||
if (file) {
|
||||
// Rewrap the ArrayBuffer in a stream.
|
||||
var fontFileDict = new Dict();
|
||||
fontFileDict.map = file.dict.map;
|
||||
|
||||
var fontFile = new Stream(file.bytes, file.start,
|
||||
file.end - file.start, fontFileDict);
|
||||
|
||||
// Check if this is a FlateStream. Otherwise just use the created
|
||||
// Stream one. This makes complex_ttf_font.pdf work.
|
||||
var cmf = file.bytes[0];
|
||||
if ((cmf & 0x0f) == 0x08) {
|
||||
file = new FlateStream(fontFile);
|
||||
} else {
|
||||
file = fontFile;
|
||||
}
|
||||
file = new Stream(file, 0, file.length, fontFileDict);
|
||||
}
|
||||
|
||||
// For now, resolve the font object here direclty. The real font
|
||||
|
|
|
@ -155,6 +155,11 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||
font.loadedName = loadedName;
|
||||
|
||||
var translated = font.translated;
|
||||
// Convert the file to an ArrayBuffer which will be turned back into
|
||||
// a Stream in the main thread.
|
||||
if (translated.file)
|
||||
translated.file = translated.file.getBytes();
|
||||
|
||||
handler.send('obj', [
|
||||
loadedName,
|
||||
'Font',
|
||||
|
@ -493,6 +498,8 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||
var baseName = encoding.get('BaseEncoding');
|
||||
if (baseName)
|
||||
baseEncoding = Encodings[baseName.name];
|
||||
else
|
||||
hasEncoding = false; // base encoding was not provided
|
||||
|
||||
// Load the differences between the base and original
|
||||
if (encoding.has('Differences')) {
|
||||
|
|
|
@ -764,6 +764,7 @@ var Font = (function Font() {
|
|||
this.hasEncoding = properties.hasEncoding;
|
||||
|
||||
this.fontMatrix = properties.fontMatrix;
|
||||
this.widthMultiplier = 1.0;
|
||||
if (properties.type == 'Type3')
|
||||
return;
|
||||
|
||||
|
@ -826,6 +827,8 @@ var Font = (function Font() {
|
|||
|
||||
this.data = data;
|
||||
this.fontMatrix = properties.fontMatrix;
|
||||
this.widthMultiplier = !properties.fontMatrix ? 1.0 :
|
||||
1.0 / properties.fontMatrix[0];
|
||||
this.encoding = properties.baseEncoding;
|
||||
this.hasShortCmap = properties.hasShortCmap;
|
||||
this.loadedName = getUniqueName();
|
||||
|
@ -2131,10 +2134,12 @@ var Font = (function Font() {
|
|||
if (typeof unicodeChars === 'number')
|
||||
unicodeChars = String.fromCharCode(unicodeChars);
|
||||
|
||||
width = (isNum(width) ? width : this.defaultWidth) * this.widthMultiplier;
|
||||
|
||||
return {
|
||||
fontChar: String.fromCharCode(unicode),
|
||||
unicode: unicodeChars,
|
||||
width: isNum(width) ? width : this.defaultWidth,
|
||||
width: width,
|
||||
codeIRQueue: codeIRQueue
|
||||
};
|
||||
},
|
||||
|
|
|
@ -4287,6 +4287,7 @@ var GlyphsUnicode = {
|
|||
zretroflexhook: 0x0290,
|
||||
zstroke: 0x01B6,
|
||||
zuhiragana: 0x305A,
|
||||
zukatakana: 0x30BA
|
||||
zukatakana: 0x30BA,
|
||||
'.notdef': 0x0000
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue