From 966cbc21127f0c9db7c466e775e5948810fde139 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Tue, 13 Sep 2011 07:59:24 -0700 Subject: [PATCH] Add FontShape.getRule which returns the name for the ctx object --- fonts.js | 15 +++++++++++++++ pdf.js | 11 +---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/fonts.js b/fonts.js index 59a654aeb..d7a66fd00 100755 --- a/fonts.js +++ b/fonts.js @@ -441,6 +441,17 @@ var FontShape = (function FontShape() { for (var name in obj) { this[name] = obj[name]; } + + var name = this.loadedName; + var bold = this.black ? (this.bold ? 'bolder' : 'bold') : + (this.bold ? 'bold' : 'normal'); + + var italic = this.italic ? 'italic' : 'normal'; + var serif = this.serif ? 'serif' : 'sans-serif'; + var typeface = '"' + name + '", ' + serif; + + this.$name1 = italic + ' ' + bold + ' '; + this.$name2 = 'px ' + typeface; }; function int16(bytes) { @@ -448,6 +459,10 @@ var FontShape = (function FontShape() { }; constructor.prototype = { + getRule: function fonts_getRule(size) { + return this.$name1 + size + this.$name2; + }, + charsToUnicode: function fonts_chars2Unicode(chars) { var charsCache = this.charsCache; var str; diff --git a/pdf.js b/pdf.js index 6068785ba..23dd910aa 100644 --- a/pdf.js +++ b/pdf.js @@ -4824,8 +4824,6 @@ function ScratchCanvas(width, height) { } var CanvasGraphics = (function() { - var kScalePrecision = 50; - var kRasterizerMin = 14; var kExecutionTime = 50; var kExecutionTimeCheck = 500; @@ -5127,14 +5125,7 @@ var CanvasGraphics = (function() { if (this.ctx.$setFont) { this.ctx.$setFont(name, size); } else { - var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') : - (fontObj.bold ? 'bold' : 'normal'); - - var italic = fontObj.italic ? 'italic' : 'normal'; - var serif = fontObj.serif ? 'serif' : 'sans-serif'; - var typeface = '"' + name + '", ' + serif; - var rule = italic + ' ' + bold + ' ' + size + 'px ' + typeface; - this.ctx.font = rule; + this.ctx.font = fontObj.getRule(size); } }, setTextRenderingMode: function(mode) {