]> git.parisson.com Git - pdf.js.git/commitdiff
Browser minimal font adjustment
authornotmasteryet <async.processingjs@yahoo.com>
Sat, 4 Feb 2012 18:45:18 +0000 (12:45 -0600)
committernotmasteryet <async.processingjs@yahoo.com>
Sat, 4 Feb 2012 18:45:18 +0000 (12:45 -0600)
src/canvas.js
test/pdfs/issue1169.pdf.link [new file with mode: 0644]
test/test_manifest.json

index f4815a655a1b677f9992205f64169bb98350af6b..131db979d497de94e5b6d5df087fd6375933dcef 100644 (file)
@@ -17,11 +17,14 @@ var TextRenderingMode = {
   ADD_TO_PATH: 7
 };
 
+var MIN_FONT_SIZE = 8;
+
 var CanvasExtraState = (function CanvasExtraStateClosure() {
   function CanvasExtraState(old) {
     // Are soft masks and alpha values shapes or opacities?
     this.alphaIsShape = false;
     this.fontSize = 0;
+    this.fontSizeScale = 1;
     this.textMatrix = IDENTITY_MATRIX;
     this.fontMatrix = IDENTITY_MATRIX;
     this.leading = 0;
@@ -577,6 +580,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
       this.current.font = fontObj;
       this.current.fontSize = size;
 
+      if (fontObj.coded)
+        return; // we don't need ctx.font for Type3 fonts
+
       var name = fontObj.loadedName || 'sans-serif';
       var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
                                  (fontObj.bold ? 'bold' : 'normal');
@@ -584,7 +590,12 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
       var italic = fontObj.italic ? 'italic' : 'normal';
       var serif = fontObj.isSerifFont ? 'serif' : 'sans-serif';
       var typeface = '"' + name + '", ' + serif;
-      var rule = italic + ' ' + bold + ' ' + size + 'px ' + typeface;
+
+      var browserFontSize = size >= MIN_FONT_SIZE ? size : MIN_FONT_SIZE;
+      this.current.fontSizeScale = browserFontSize != MIN_FONT_SIZE ? 1.0 :
+                                   size / MIN_FONT_SIZE;
+
+      var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
       this.ctx.font = rule;
     },
     setTextRenderingMode: function canvasGraphicsSetTextRenderingMode(mode) {
@@ -647,6 +658,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
       var font = current.font;
       var glyphs = font.charsToGlyphs(str);
       var fontSize = current.fontSize;
+      var fontSizeScale = current.fontSizeScale;
       var charSpacing = current.charSpacing;
       var wordSpacing = current.wordSpacing;
       var textHScale = current.textHScale;
@@ -715,6 +727,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
         if (textSelection)
           text.geom = this.getTextGeometry();
 
+        ctx.scale(fontSizeScale, fontSizeScale);
+
         var x = 0;
         for (var i = 0; i < glyphsLength; ++i) {
           var glyph = glyphs[i];
@@ -728,20 +742,21 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
           var charWidth = glyph.width * fontSize * 0.001 +
               Util.sign(current.fontMatrix[0]) * charSpacing;
 
+          var scaledX = x / fontSizeScale;
           switch (textRenderingMode) {
             default: // other unsupported rendering modes
             case TextRenderingMode.FILL:
             case TextRenderingMode.FILL_ADD_TO_PATH:
-              ctx.fillText(char, x, 0);
+              ctx.fillText(char, scaledX, 0);
               break;
             case TextRenderingMode.STROKE:
             case TextRenderingMode.STROKE_ADD_TO_PATH:
-              ctx.strokeText(char, x, 0);
+              ctx.strokeText(char, scaledX, 0);
               break;
             case TextRenderingMode.FILL_STROKE:
             case TextRenderingMode.FILL_STROKE_ADD_TO_PATH:
-              ctx.fillText(char, x, 0);
-              ctx.strokeText(char, x, 0);
+              ctx.fillText(char, scaledX, 0);
+              ctx.strokeText(char, scaledX, 0);
               break;
             case TextRenderingMode.INVISIBLE:
               break;
diff --git a/test/pdfs/issue1169.pdf.link b/test/pdfs/issue1169.pdf.link
new file mode 100644 (file)
index 0000000..46559a0
--- /dev/null
@@ -0,0 +1 @@
+http://www.cs.txstate.edu/~mb92/papers/gpgpu11.pdf
index 2b0541edbea8b3159aa1c885f2ba1886853473a0..f4d671a04a5d876f0aa26a5cb7d831d5c48dbb90 100644 (file)
       "link": true,
       "type": "eq"
     },
+    {  "id": "issue1169",
+      "file": "pdfs/issue1169.pdf",
+      "md5": "3df3ed21fd43ac7fdb21e2015c8a7809",
+      "rounds": 1,
+      "link": true,
+      "type": "eq"
+    },
     {  "id": "zerowidthline",
       "file": "pdfs/zerowidthline.pdf",
       "md5": "295d26e61a85635433f8e4b768953f60",