Skip to content

Commit aac406f

Browse files
authored
Merge pull request #1109 from Flamenco/hotfix_error_handling
Log and ignore errors in canvg while rendering.
2 parents 8ae35f6 + a8f31be commit aac406f

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

libs/canvg_context2d/canvg.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -919,17 +919,23 @@
919919
if (this.style('visibility').value == 'hidden') return;
920920

921921
ctx.save();
922-
if (this.style('mask').hasValue()) { // mask
923-
var mask = this.style('mask').getDefinition();
924-
if (mask != null) mask.apply(ctx, this);
925-
} else if (this.style('filter').hasValue()) { // filter
926-
var filter = this.style('filter').getDefinition();
927-
if (filter != null) filter.apply(ctx, this);
928-
} else {
929-
this.setContext(ctx);
930-
this.renderChildren(ctx);
931-
this.clearContext(ctx);
932-
}
922+
//ss
923+
try {
924+
if (this.style('mask').hasValue()) { // mask
925+
var mask = this.style('mask').getDefinition();
926+
if (mask != null) mask.apply(ctx, this);
927+
} else if (this.style('filter').hasValue()) { // filter
928+
var filter = this.style('filter').getDefinition();
929+
if (filter != null) filter.apply(ctx, this);
930+
} else {
931+
this.setContext(ctx);
932+
this.renderChildren(ctx);
933+
this.clearContext(ctx);
934+
}
935+
} catch (e) {
936+
console.warn('A rendering error occurred and was ignored.');
937+
}
938+
//ss end
933939
ctx.restore();
934940
}
935941

@@ -3119,10 +3125,26 @@
31193125
this.base = svg.Element.ElementBase;
31203126
this.base(node);
31213127

3122-
this.blurRadius = Math.floor(this.attribute('stdDeviation').numValue());
3128+
//ss IE was returning a GIANT value for stdDeviation
3129+
var stdDev = this.attribute('stdDeviation').numValue();
3130+
if (stdDev > 1000) {
3131+
stdDev =
3132+
//ss IE was mangling name from stdDeviation2 to stddeviation2
3133+
this.attribute('stddeviation2').value !== ''
3134+
? this.attribute('stddeviation2').numValue()
3135+
: 2; //TODO provide default value as an option
3136+
}
3137+
3138+
this.blurRadius = Math.floor(stdDev);
3139+
//ss end
31233140
this.extraFilterDistance = this.blurRadius;
31243141

31253142
this.apply = function(ctx, x, y, width, height) {
3143+
//ss IE was not finding stackBlur using v1.4
3144+
if (stackBlur === undefined && window.StackBlur !== undefined){
3145+
stackBlur = window.StackBlur;
3146+
}
3147+
//ss end
31263148
if (typeof stackBlur.canvasRGBA == 'undefined') {
31273149
svg.log('ERROR: StackBlur.js must be included for blur to work');
31283150
return;

0 commit comments

Comments
 (0)