]> git.parisson.com Git - pdf.js.git/commitdiff
Add FontShape.getRule which returns the name for the ctx object
authorJulian Viereck <julian.viereck@gmail.com>
Tue, 13 Sep 2011 14:59:24 +0000 (07:59 -0700)
committerJulian Viereck <julian.viereck@gmail.com>
Thu, 15 Sep 2011 20:17:09 +0000 (13:17 -0700)
fonts.js
pdf.js

index 59a654aeb17e1d15ba26ada4538fff7b19b7698e..d7a66fd001d3c748c1c9ee7eea7ef0694e48f1b7 100755 (executable)
--- 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 6068785ba3fd933ced1b0622880494c8bcc0f53b..23dd910aaac48102ae1615a7688b963e4e76589c 100644 (file)
--- 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) {