Skip to content

Commit

Permalink
some fixes to get it back running and working
Browse files Browse the repository at this point in the history
  • Loading branch information
dodo committed Dec 1, 2010
1 parent 0bd5dd6 commit 8cc9cd1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
12 changes: 7 additions & 5 deletions lib/canvas-svg/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,29 @@ var checkAndReadFile = function (filename, callback) {
path.exists(filename, function (exists) {
if (exists) return fs.readFile(filename, callback);
throw new Error("Cannot find file '" + filename +
"' but it is hardly required.\nTry git submodules update --init "+
"to get all dependencies.");
"' but it is hardly required.\n"+
"It should be already in the repo. If not get it from:"+
" http://code.google.com/p/canvg/");
});
};


// main


result = function () {
var result = function () {
var args = new Vargs(arguments);
if (result.debug) console.log("* loading canvg rgbcolor …");
checkAndReadFile(depdir+'/lib/canvg/rgbcolor.js', function (err, ccode) {
checkAndReadFile(depdir+'/canvg/rgbcolor.js', function (err, rcode) {
if (err)
return args.callback(err);

var code = ["var CanvasRenderingContext2D"];
if(rcode)
code.push(rcode);

checkAndReadFile(depdir+'/lib/canvg/canvg.js', function (err, ccode) {
if (result.debug) console.log("* loading canvg …");
checkAndReadFile(depdir+'/canvg/canvg.js', function (err, ccode) {
if (err)
return args.callback(err);
if (ccode)
Expand Down
2 changes: 1 addition & 1 deletion lib/canvas-svg/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function (dir) {
try {
return require(path)
} catch (e) {
if (e.message !== "Cannot find module '" + path + "'")
if (e.message.slice(0,18) !== "Cannot find module")
throw e;
return check_next();
}
Expand Down
25 changes: 19 additions & 6 deletions lib/node-canvas-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ var jsdom = _require('jsdom', 'jsdom/lib/jsdom'),
var svg = exports.svg = {};


exports.svg.render = function (svg, /*options, callback*/) {
var args = new Vargs(argmuents);
if (!svg)
var check_canvg = function () {
if (svg.canvg) return true;
throw new Error("You have to load Canvg first."+
"\nIt should be already in the repo. If not get it from:"+
" http://code.google.com/p/canvg/");
};


exports.svg.render = function (svgdata/*, options, callback*/) {
check_canvg();
var args = new Vargs(arguments);
if (!svgdata)
return args.callback(new Error("no svg given"), new Canvas(42, 42));

var doc = jsdom.jsdom(),
Expand All @@ -30,7 +39,7 @@ exports.svg.render = function (svg, /*options, callback*/) {
};};
win.DOMParser = true;

var obj = jsdom.jsdom("<html><body>" + svg + "</body></html>"); // FIXME meh :(
var obj = jsdom.jsdom("<html><body>" + svgdata + "</body></html>"); // FIXME meh :(
obj = obj.body.firstChild;
var canvas = new Canvas(
parseInt(obj.getAttribute('width')),
Expand All @@ -56,8 +65,12 @@ exports.svg.render = function (svg, /*options, callback*/) {
options[key] = defaults[key];
}

svg.canvg(win, doc, DOMParser)(canvas, svg, options);
try {
svg.canvg(win, doc, DOMParser)(canvas, svgdata, options);
} catch(e) {
args.callback(e, canvas);
}
};


exports.load = require('./canvas-svg/loader')(depdir, vargs, svg);

0 comments on commit 8cc9cd1

Please sign in to comment.