},
setFont: function canvasGraphicsSetFont(fontRefName, size) {
var fontObj = this.objs.get(fontRefName).fontObj;
+ var current = this.current;
- if (!fontObj) {
+ if (!fontObj)
- throw 'Can\'t find font for ' + fontRefName;
+ error('Can\'t find font for ' + fontRefName);
+
+ // Slice-clone matrix so we can manipulate it without affecting original
+ if (fontObj.fontMatrix)
+ current.fontMatrix = fontObj.fontMatrix.slice(0);
+ else
+ current.fontMatrix = IDENTITY_MATRIX.slice(0);
+
+ // A valid matrix needs all main diagonal elements to be non-zero
+ // This also ensures we bypass FF bugzilla bug #719844.
+ if (current.fontMatrix[0] === 0 ||
+ current.fontMatrix[3] === 0) {
+ warn('Invalid font matrix for font ' + fontRefName);
}
- var name = fontObj.loadedName || 'sans-serif';
+ // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
+ // and in some docs this can be negative (inverted x-y axes).
+ // We implement this condition with fontMatrix.
+ if (size < 0) {
+ size = -size;
+ current.fontMatrix[0] *= -1;
+ current.fontMatrix[3] *= -1;
+ }
this.current.font = fontObj;
this.current.fontSize = size;