Skip to content

Commit

Permalink
double quote font-family when create font style for canvas context to…
Browse files Browse the repository at this point in the history
… fix font rendering in node-canvas
  • Loading branch information
fuzhenn committed Nov 15, 2016
1 parent 80e8dcb commit 623676a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions canvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
if (nodeEnv) {
c = new CanvasClass();
} else {
c = document.createElement('canvas');
c = document.createElement('canvas');
}
return c;
}
Expand Down Expand Up @@ -135,7 +135,7 @@
}
return false;
};
} else {
} else {
// see https://developer.mozilla.org/en-US/docs/Web/API/Element.matches

if (typeof Element.prototype.matches != 'undefined') {
Expand Down Expand Up @@ -176,7 +176,7 @@
}
}



// slightly modified version of https://github.com/keeganstreet/specificity/blob/master/specificity.js
var attributeRegex = /(\[[^\]]+\])/g;
Expand Down Expand Up @@ -233,7 +233,7 @@
svg.Images = [];
svg.ctx = ctx;
svg.ViewPort = new (function () {

this.viewPorts = [];
this.Clear = function() { this.viewPorts = []; }
this.SetCurrent = function(width, height) { this.viewPorts.push({ width: width, height: height }); }
Expand Down Expand Up @@ -271,7 +271,7 @@
var AJAX;
if(windowEnv.XMLHttpRequest){AJAX=new windowEnv.XMLHttpRequest();}
else{AJAX=new ActiveXObject('Microsoft.XMLHTTP');}
if(AJAX){
if(AJAX){
AJAX.open('GET',url,false);
AJAX.send(null);
return AJAX.responseText;
Expand Down Expand Up @@ -469,8 +469,15 @@

this.CreateFont = function(fontStyle, fontVariant, fontWeight, fontSize, fontFamily, inherit) {
var f = inherit != null ? this.Parse(inherit) : this.CreateFont('', '', '', '', '', svg.ctx.font);
var fontFamily = fontFamily || f.fontFamily;
if (fontFamily) {
var trimed = fontFamily.trim();
if (trimed[0] !== '"' && trimed.indexOf(' ') > 0) {
fontFamily = '"' + trimed + '"';
}
}
return {
fontFamily: fontFamily || f.fontFamily,
fontFamily: fontFamily,
fontSize: fontSize || f.fontSize,
fontStyle: fontStyle || f.fontStyle,
fontWeight: fontWeight || f.fontWeight,
Expand Down Expand Up @@ -1172,7 +1179,7 @@
ctx.closePath();
ctx.clip();
}
}
}
svg.ViewPort.SetCurrent(width, height);

// viewbox
Expand Down Expand Up @@ -1860,7 +1867,7 @@
tempSvg.attributes['width'] = new svg.Property('width', rootView.width);
tempSvg.attributes['height'] = new svg.Property('height', rootView.height);
tempSvg.children = [ group ];
var c = createCanvas();
var c = createCanvas();
c.width = rootView.width;
c.height = rootView.height;
var tempCtx = c.getContext('2d');
Expand Down Expand Up @@ -2472,7 +2479,7 @@
this.img.onerror = function() { svg.log('ERROR: image "' + href + '" not found'); self.loaded = true; }
this.img.src = href;
}
else {
else {
this.img = svg.ajax(href);
this.loaded = true;
}
Expand Down Expand Up @@ -2944,7 +2951,7 @@
}

// load from xml
svg.loadXml = function(ctx, xml) {
svg.loadXml = function(ctx, xml) {
svg.loadXmlDoc(ctx, svg.parseXml(xml));
}

Expand Down

0 comments on commit 623676a

Please sign in to comment.