Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into text-select
Browse files Browse the repository at this point in the history
Conflicts:
	src/core.js
  • Loading branch information
arturadib committed Nov 2, 2011
2 parents c74d7b8 + 112115c commit 49a303f
Show file tree
Hide file tree
Showing 30 changed files with 217 additions and 150 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
REPO = git@github.com:andreasgal/pdf.js.git
REPO = git@github.com:mozilla/pdf.js.git
BUILD_DIR := build
BUILD_TARGET := $(BUILD_DIR)/pdf.js
DEFAULT_BROWSERS := resources/browser_manifests/browser_manifest.json
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ successful.

For an online demo, visit:

+ http://andreasgal.github.com/pdf.js/web/viewer.html
+ http://mozilla.github.com/pdf.js/web/viewer.html

This demo provides an interactive interface for displaying and browsing PDFs
using the pdf.js API.
Expand All @@ -31,15 +31,15 @@ using the pdf.js API.

A Firefox extension is also available:

+ http://andreasgal.github.com/pdf.js/extensions/firefox/pdf.js.xpi
+ http://mozilla.github.com/pdf.js/extensions/firefox/pdf.js.xpi

However, note that the extension might not reflect the latest source in our master branch.

### Getting the code

To get a local copy of the current code, clone it using git:

$ git clone git://github.com/andreasgal/pdf.js.git pdfjs
$ git clone git://github.com/mozilla/pdf.js.git pdfjs
$ cd pdfjs

Next, you need to start a local web server as some browsers don't allow opening
Expand Down Expand Up @@ -73,7 +73,7 @@ Additional resources are available in a separate section below.

For a "hello world" example, take a look at:

+ [examples/helloworld/hello.js](https://github.com/andreasgal/pdf.js/blob/master/examples/helloworld/hello.js)
+ [examples/helloworld/hello.js](https://github.com/mozilla/pdf.js/blob/master/examples/helloworld/hello.js)

This example illustrates the bare minimum ingredients for integrating pdf.js
in a custom project.
Expand All @@ -92,19 +92,19 @@ workings of PDF and pdf.js:

pdf.js is a community-driven project, so contributors are always welcome.
Simply fork our repo and contribute away. A great place to start is our
[open issues](https://github.com/andreasgal/pdf.js/issues). For better consistency and
[open issues](https://github.com/mozilla/pdf.js/issues). For better consistency and
long-term stability, please do look around the code and try to follow our conventions.
More information about the contributor process can be found on the
[contributor wiki page](https://github.com/andreasgal/pdf.js/wiki/Contributing).
[contributor wiki page](https://github.com/mozilla/pdf.js/wiki/Contributing).

If you don't want to hack on the project or have little spare time, __you still
can help!__ Just open PDFs in the
[online demo](http://andreasgal.github.com/pdf.js/web/viewer.html) and report
[online demo](http://mozilla.github.com/pdf.js/web/viewer.html) and report
any breakage in rendering.

Our Github contributors so far:

+ https://github.com/andreasgal/pdf.js/contributors
+ https://github.com/mozilla/pdf.js/contributors

You can add your name to it! :)

Expand Down Expand Up @@ -143,14 +143,14 @@ against reference images before merging pull requests.

See the bot repo for details:

+ https://github.com/arturadib/pdf.js-bot
+ https://github.com/mozilla/pdf.js-bot


## Additional resources

Our demo site is here:

+ http://andreasgal.github.com/pdf.js/web/viewer.html
+ http://mozilla.github.com/pdf.js/web/viewer.html

You can read more about pdf.js here:

Expand Down
18 changes: 14 additions & 4 deletions extensions/firefox/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,31 @@ function log(str) {

function startup(aData, aReason) {
let manifestPath = 'chrome.manifest';
let file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile);
let manifest = Cc['@mozilla.org/file/local;1']
.createInstance(Ci.nsILocalFile);
try {
file.initWithPath(aData.installPath.path);
file.append(manifestPath);
Cm.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(file);
manifest.initWithPath(aData.installPath.path);
manifest.append(manifestPath);
Cm.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(manifest);
Services.prefs.setBoolPref('extensions.pdf.js.active', true);
} catch (e) {
log(e);
}
}

function shutdown(aData, aReason) {
if (Services.prefs.getBoolPref('extensions.pdf.js.active'))
Services.prefs.setBoolPref('extensions.pdf.js.active', false);
}

function install(aData, aReason) {
let url = 'chrome://pdf.js/content/web/viewer.html?file=%s';
Services.prefs.setCharPref('extensions.pdf.js.url', url);
Services.prefs.setBoolPref('extensions.pdf.js.active', false);
}

function uninstall(aData, aReason) {
Services.prefs.clearUserPref('extensions.pdf.js.url');
Services.prefs.clearUserPref('extensions.pdf.js.active');
}

5 changes: 4 additions & 1 deletion extensions/firefox/components/pdfContentHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pdfContentHandler.prototype = {
if (!(aRequest instanceof Ci.nsIChannel))
throw NS_ERROR_WONT_HANDLE_CONTENT;

if (!Services.prefs.getBoolPref('extensions.pdf.js.active'))
throw NS_ERROR_WONT_HANDLE_CONTENT;

let window = null;
let callbacks = aRequest.notificationCallbacks ||
aRequest.loadGroup.notificationCallbacks;
Expand All @@ -53,7 +56,7 @@ pdfContentHandler.prototype = {
throw NS_ERROR_WONT_HANDLE_CONTENT;

aRequest.cancel(Cr.NS_BINDING_ABORTED);
window.location = url.replace('%s', targetUrl);
window.location = url.replace('%s', encodeURIComponent(targetUrl));
},

classID: Components.ID('{2278dfd0-b75c-11e0-8257-1ba3d93c9f1a}'),
Expand Down
2 changes: 1 addition & 1 deletion extensions/firefox/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<em:unpack>true</em:unpack>
<em:creator>Vivien Nicolas</em:creator>
<em:description>pdf.js uri loader</em:description>
<em:homepageURL>https://github.com/andreasgal/pdf.js/</em:homepageURL>
<em:homepageURL>https://github.com/mozilla/pdf.js/</em:homepageURL>
</Description>
</RDF>
86 changes: 45 additions & 41 deletions src/canvas.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// <canvas> contexts store most of the state we need natively.
// However, PDF needs a bit more state, which we store here.
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */

'use strict';

// <canvas> contexts store most of the state we need natively.
// However, PDF needs a bit more state, which we store here.

var CanvasExtraState = (function canvasExtraState() {
function constructor(old) {
// Are soft masks and alpha values shapes or opacities?
Expand All @@ -21,13 +24,18 @@ var CanvasExtraState = (function canvasExtraState() {
this.wordSpacing = 0;
this.textHScale = 1;
// 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.old = old;
}
Expand Down Expand Up @@ -243,6 +251,13 @@ var CanvasGraphics = (function canvasGraphics() {
case 'Font':
this.setFont(state[1], state[2]);
break;
case 'CA':
this.current.strokeAlpha = state[1];
break;
case 'ca':
this.current.fillAlpha = state[1];
this.ctx.globalAlpha = state[1];
break;
}
}
},
Expand Down Expand Up @@ -291,9 +306,13 @@ var CanvasGraphics = (function canvasGraphics() {
rectangle: function canvasGraphicsRectangle(x, y, width, height) {
this.ctx.rect(x, y, width, height);
},
stroke: function canvasGraphicsStroke() {
stroke: function canvasGraphicsStroke(consumePath) {
consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
var ctx = this.ctx;
var strokeColor = this.current.strokeColor;
// For stroke we want to temporarily change the global alpha to the
// stroking alpha.
ctx.globalAlpha = this.current.strokeAlpha;
if (strokeColor && strokeColor.hasOwnProperty('type') &&
strokeColor.type === 'Pattern') {
// for patterns, we transform to pattern space, calculate
Expand All @@ -305,14 +324,17 @@ var CanvasGraphics = (function canvasGraphics() {
} else {
ctx.stroke();
}

this.consumePath();
if (consumePath)
this.consumePath();
// Restore the global alpha to the fill alpha
ctx.globalAlpha = this.current.fillAlpha;
},
closeStroke: function canvasGraphicsCloseStroke() {
this.closePath();
this.stroke();
},
fill: function canvasGraphicsFill() {
fill: function canvasGraphicsFill(consumePath) {
consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
var ctx = this.ctx;
var fillColor = this.current.fillColor;

Expand All @@ -325,38 +347,17 @@ var CanvasGraphics = (function canvasGraphics() {
} else {
ctx.fill();
}

this.consumePath();
if (consumePath)
this.consumePath();
},
eoFill: function canvasGraphicsEoFill() {
var savedFillRule = this.setEOFillRule();
this.fill();
this.restoreFillRule(savedFillRule);
},
fillStroke: function canvasGraphicsFillStroke() {
var ctx = this.ctx;

var fillColor = this.current.fillColor;
if (fillColor && fillColor.hasOwnProperty('type') &&
fillColor.type === 'Pattern') {
ctx.save();
ctx.fillStyle = fillColor.getPattern(ctx);
ctx.fill();
ctx.restore();
} else {
ctx.fill();
}

var strokeColor = this.current.strokeColor;
if (strokeColor && strokeColor.hasOwnProperty('type') &&
strokeColor.type === 'Pattern') {
ctx.save();
ctx.strokeStyle = strokeColor.getPattern(ctx);
ctx.stroke();
ctx.restore();
} else {
ctx.stroke();
}
this.fill(false);
this.stroke(false);

this.consumePath();
},
Expand All @@ -366,10 +367,12 @@ var CanvasGraphics = (function canvasGraphics() {
this.restoreFillRule(savedFillRule);
},
closeFillStroke: function canvasGraphicsCloseFillStroke() {
return this.fillStroke();
this.closePath();
this.fillStroke();
},
closeEOFillStroke: function canvasGraphicsCloseEOFillStroke() {
var savedFillRule = this.setEOFillRule();
this.closePath();
this.fillStroke();
this.restoreFillRule(savedFillRule);
},
Expand Down Expand Up @@ -646,8 +649,7 @@ var CanvasGraphics = (function canvasGraphics() {
},

// Color
setStrokeColorSpace:
function canvasGraphicsSetStrokeColorSpacefunction(raw) {
setStrokeColorSpace: function canvasGraphicsSetStrokeColorSpace(raw) {
this.current.strokeColorSpace = ColorSpace.fromIR(raw);
},
setFillColorSpace: function canvasGraphicsSetFillColorSpace(raw) {
Expand All @@ -658,7 +660,7 @@ var CanvasGraphics = (function canvasGraphics() {
var color = cs.getRgb(arguments);
this.setStrokeRGBColor.apply(this, color);
},
getColorN_IR_Pattern: function(IR, cs) {
getColorN_IR_Pattern: function canvasGraphicsGetColorN_IR_Pattern(IR, cs) {
if (IR[0] == 'TilingPattern') {
var args = IR[1];
var base = cs.base;
Expand Down Expand Up @@ -774,8 +776,8 @@ var CanvasGraphics = (function canvasGraphics() {
error('Should not call beginImageData');
},

paintFormXObjectBegin:
function canvasGraphicsPaintFormXObject(matrix, bbox) {
paintFormXObjectBegin: function canvasGraphicsPaintFormXObjectBegin(matrix,
bbox) {
this.save();

if (matrix && isArray(matrix) && 6 == matrix.length)
Expand All @@ -790,11 +792,11 @@ var CanvasGraphics = (function canvasGraphics() {
}
},

paintFormXObjectEnd: function() {
paintFormXObjectEnd: function canvasGraphicsPaintFormXObjectEnd() {
this.restore();
},

paintJpegXObject: function(objId, w, h) {
paintJpegXObject: function canvasGraphicsPaintJpegXObject(objId, w, h) {
var image = this.objs.get(objId);
if (!image) {
error('Dependent image isn\'t ready yet');
Expand All @@ -813,7 +815,8 @@ var CanvasGraphics = (function canvasGraphics() {
this.restore();
},

paintImageMaskXObject: function(imgArray, inverseDecode, width, height) {
paintImageMaskXObject: function canvasGraphicsPaintImageMaskXObject(
imgArray, inverseDecode, width, height) {
function applyStencilMask(buffer, inverseDecode) {
var imgArrayPos = 0;
var i, j, mask, buf;
Expand Down Expand Up @@ -861,7 +864,7 @@ var CanvasGraphics = (function canvasGraphics() {
this.restore();
},

paintImageXObject: function(imgData) {
paintImageXObject: function canvasGraphicsPaintImageXObject(imgData) {
this.save();
var ctx = this.ctx;
var w = imgData.width;
Expand Down Expand Up @@ -950,3 +953,4 @@ var CanvasGraphics = (function canvasGraphics() {

return constructor;
})();

1 change: 1 addition & 0 deletions src/cidmaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -6930,3 +6930,4 @@ var CIDToUnicodeMaps = {
{f: 39, c: 19576}, {f: 111, c: 19620}, {f: 148, c: 19738},
{f: 7, c: 19887}]
};

Loading

0 comments on commit 49a303f

Please sign in to comment.