Skip to content

Commit 5e1d78e

Browse files
committed
Merge branch 'master' of git://github.com/mozilla/pdf.js into text-select
Conflicts: src/canvas.js
2 parents e2e2240 + 12d3a75 commit 5e1d78e

File tree

10 files changed

+52
-31
lines changed

10 files changed

+52
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pdf.js
22

3-
3+
44

55
## Overview
66

extensions/firefox/install.rdf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
<Description about="urn:mozilla:install-manifest">
77
<em:id>uriloader@pdf.js</em:id>
88
<em:name>pdf.js</em:name>
9-
<em:version>0.1</em:version>
9+
<em:version>0.1.0</em:version>
1010
<em:iconURL>chrome://pdf.js/skin/logo.png</em:iconURL>
1111
<em:targetApplication>
1212
<Description>
1313
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
1414
<em:minVersion>6.0</em:minVersion>
15-
<em:maxVersion>11.0.*</em:maxVersion>
15+
<em:maxVersion>11.0a1</em:maxVersion>
1616
</Description>
1717
</em:targetApplication>
1818
<em:bootstrap>true</em:bootstrap>
1919
<em:unpack>true</em:unpack>
2020
<em:creator>Vivien Nicolas</em:creator>
2121
<em:description>pdf.js uri loader</em:description>
2222
<em:homepageURL>https://github.com/mozilla/pdf.js/</em:homepageURL>
23+
<em:type>2</em:type>
2324
</Description>
2425
</RDF>

src/canvas.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,12 @@ var CanvasGraphics = (function canvasGraphics() {
568568
var ctx = this.ctx;
569569
var current = this.current;
570570
var textHScale = current.textHScale;
571-
var font = current.font;
571+
var fontMatrix = current.font.fontMatrix || IDENTITY_MATRIX;
572572

573573
ctx.transform.apply(ctx, current.textMatrix);
574574
ctx.scale(1, -1);
575575
ctx.translate(current.x, -1 * current.y);
576-
ctx.transform.apply(ctx, font.fontMatrix || IDENTITY_MATRIX);
576+
ctx.transform.apply(ctx, fontMatrix);
577577
ctx.scale(1 / textHScale, 1);
578578
},
579579
getTextGeometry: function canvasGetTextGeometry() {
@@ -626,6 +626,8 @@ var CanvasGraphics = (function canvasGraphics() {
626626
var charSpacing = current.charSpacing;
627627
var wordSpacing = current.wordSpacing;
628628
var textHScale = current.textHScale;
629+
var fontMatrix = font.fontMatrix || IDENTITY_MATRIX;
630+
var textHScale2 = textHScale * fontMatrix[0];
629631
var glyphsLength = glyphs.length;
630632
var textLayer = this.textLayer;
631633
var text = {str: '', length: 0, canvasWidth: 0, geom: {}};
@@ -644,7 +646,6 @@ var CanvasGraphics = (function canvasGraphics() {
644646
ctx.transform.apply(ctx, current.textMatrix);
645647
ctx.translate(current.x, current.y);
646648

647-
var fontMatrix = font.fontMatrix || IDENTITY_MATRIX;
648649
ctx.scale(1 / textHScale, 1);
649650
for (var i = 0; i < glyphsLength; ++i) {
650651

@@ -662,13 +663,14 @@ var CanvasGraphics = (function canvasGraphics() {
662663
this.restore();
663664

664665
var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
665-
var charWidth = transformed[0] * fontSize + charSpacing;
666-
ctx.translate(charWidth, 0);
667-
current.x += charWidth;
666+
var width = transformed[0] * fontSize + charSpacing;
667+
668+
ctx.translate(width, 0);
669+
current.x += width * textHScale2;
668670

669-
text.str += glyph.fontChar;
671+
text.str += glyph.unicode;
670672
text.length++;
671-
text.canvasWidth += charWidth;
673+
text.canvasWidth += width;
672674
}
673675
ctx.restore();
674676
} else {
@@ -689,12 +691,11 @@ var CanvasGraphics = (function canvasGraphics() {
689691
ctx.fillText(char, width, 0);
690692
width += charWidth;
691693

692-
text.str += char === ' ' ? '&nbsp;' : char;
694+
text.str += glyph.unicode === ' ' ? '&nbsp;' : glyph.unicode;
693695
text.length++;
694696
text.canvasWidth += charWidth;
695697
}
696-
697-
current.x += width;
698+
current.x += width * textHScale2;
698699
ctx.restore();
699700
}
700701

@@ -707,7 +708,8 @@ var CanvasGraphics = (function canvasGraphics() {
707708
var ctx = this.ctx;
708709
var current = this.current;
709710
var fontSize = current.fontSize;
710-
var textHScale = current.textHScale;
711+
var textHScale2 = current.textHScale *
712+
(current.font.fontMatrix || IDENTITY_MATRIX)[0];
711713
var arrLength = arr.length;
712714
var textLayer = this.textLayer;
713715
var font = current.font;
@@ -724,7 +726,7 @@ var CanvasGraphics = (function canvasGraphics() {
724726
for (var i = 0; i < arrLength; ++i) {
725727
var e = arr[i];
726728
if (isNum(e)) {
727-
var spacingLength = -e * 0.001 * fontSize * textHScale;
729+
var spacingLength = -e * 0.001 * fontSize * textHScale2;
728730
current.x += spacingLength;
729731

730732
if (textSelection) {

src/core.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -560,20 +560,9 @@ var PDFDoc = (function pdfDoc() {
560560
var properties = data[4];
561561

562562
if (file) {
563+
// Rewrap the ArrayBuffer in a stream.
563564
var fontFileDict = new Dict();
564-
fontFileDict.map = file.dict.map;
565-
566-
var fontFile = new Stream(file.bytes, file.start,
567-
file.end - file.start, fontFileDict);
568-
569-
// Check if this is a FlateStream. Otherwise just use the created
570-
// Stream one. This makes complex_ttf_font.pdf work.
571-
var cmf = file.bytes[0];
572-
if ((cmf & 0x0f) == 0x08) {
573-
file = new FlateStream(fontFile);
574-
} else {
575-
file = fontFile;
576-
}
565+
file = new Stream(file, 0, file.length, fontFileDict);
577566
}
578567

579568
// For now, resolve the font object here direclty. The real font

src/evaluator.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ var PartialEvaluator = (function partialEvaluator() {
155155
font.loadedName = loadedName;
156156

157157
var translated = font.translated;
158+
// Convert the file to an ArrayBuffer which will be turned back into
159+
// a Stream in the main thread.
160+
if (translated.file)
161+
translated.file = translated.file.getBytes();
162+
158163
handler.send('obj', [
159164
loadedName,
160165
'Font',
@@ -493,6 +498,8 @@ var PartialEvaluator = (function partialEvaluator() {
493498
var baseName = encoding.get('BaseEncoding');
494499
if (baseName)
495500
baseEncoding = Encodings[baseName.name];
501+
else
502+
hasEncoding = false; // base encoding was not provided
496503

497504
// Load the differences between the base and original
498505
if (encoding.has('Differences')) {

src/fonts.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ var Font = (function Font() {
764764
this.hasEncoding = properties.hasEncoding;
765765

766766
this.fontMatrix = properties.fontMatrix;
767+
this.widthMultiplier = 1.0;
767768
if (properties.type == 'Type3')
768769
return;
769770

@@ -826,6 +827,8 @@ var Font = (function Font() {
826827

827828
this.data = data;
828829
this.fontMatrix = properties.fontMatrix;
830+
this.widthMultiplier = !properties.fontMatrix ? 1.0 :
831+
1.0 / properties.fontMatrix[0];
829832
this.encoding = properties.baseEncoding;
830833
this.hasShortCmap = properties.hasShortCmap;
831834
this.loadedName = getUniqueName();
@@ -2131,10 +2134,12 @@ var Font = (function Font() {
21312134
if (typeof unicodeChars === 'number')
21322135
unicodeChars = String.fromCharCode(unicodeChars);
21332136

2137+
width = (isNum(width) ? width : this.defaultWidth) * this.widthMultiplier;
2138+
21342139
return {
21352140
fontChar: String.fromCharCode(unicode),
21362141
unicode: unicodeChars,
2137-
width: isNum(width) ? width : this.defaultWidth,
2142+
width: width,
21382143
codeIRQueue: codeIRQueue
21392144
};
21402145
},

src/glyphlist.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4287,6 +4287,7 @@ var GlyphsUnicode = {
42874287
zretroflexhook: 0x0290,
42884288
zstroke: 0x01B6,
42894289
zuhiragana: 0x305A,
4290-
zukatakana: 0x30BA
4290+
zukatakana: 0x30BA,
4291+
'.notdef': 0x0000
42914292
};
42924293

test/pdfs/piperine.pdf.link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://www.erowid.org/archive/rhodium/chemistry/3base/piperonal.pepper/piperine.pepper/465e03piperine.pdf

test/pdfs/protectip.pdf.link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://leahy.senate.gov/imo/media/doc/BillText-PROTECTIPAct.pdf

test/test_manifest.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,19 @@
276276
"link": false,
277277
"rounds": 1,
278278
"type": "eq"
279+
},
280+
{ "id": "protectip",
281+
"file": "pdfs/protectip.pdf",
282+
"md5": "676e7a7b8f96d04825361832b1838a93",
283+
"link": true,
284+
"rounds": 1,
285+
"type": "eq"
286+
},
287+
{ "id": "piperine",
288+
"file": "pdfs/piperine.pdf",
289+
"md5": "603ca43dc5732dbba1579f122958c0c2",
290+
"link": true,
291+
"rounds": 1,
292+
"type": "eq"
279293
}
280294
]

0 commit comments

Comments
 (0)