]> git.parisson.com Git - pdf.js.git/commitdiff
Fix OS/2 table to match font yMax and yMin from head table
authorAdil Allawi <adil@diwan.com>
Thu, 15 Sep 2011 22:23:22 +0000 (23:23 +0100)
committerAdil Allawi <adil@diwan.com>
Fri, 16 Sep 2011 16:46:15 +0000 (17:46 +0100)
fonts.js

index 7d51e2c4b2acddf272cca0f70be6a6c47c6fefa9..064702de2aa0169d43a49bb4f65bb2d46d592883 100644 (file)
--- a/fonts.js
+++ b/fonts.js
@@ -833,9 +833,11 @@ var Font = (function Font() {
         var data = file.getBytes(length);
         file.pos = previousPosition;
 
-        if (tag == 'head')
+        if (tag == 'head') {
           // clearing checksum adjustment
           data[8] = data[9] = data[10] = data[11] = 0;
+          data[17] |= 0x20; //Set font optimized for cleartype flag
+        }
 
         return {
           tag: tag,
@@ -1008,7 +1010,7 @@ var Font = (function Font() {
       var header = readOpenTypeHeader(font);
       var numTables = header.numTables;
 
-      var cmap, maxp, hhea, hmtx, vhea, vmtx;
+      var cmap, maxp, hhea, hmtx, vhea, vmtx, head;
       var tables = [];
       for (var i = 0; i < numTables; i++) {
         var table = readTableEntry(font);
@@ -1022,6 +1024,8 @@ var Font = (function Font() {
             hhea = table;
           else if (table.tag == 'hmtx')
             hmtx = table;
+          else if (table.tag == 'head')
+            head = table;
 
           requiredTables.splice(index, 1);
         } else {
@@ -1048,6 +1052,13 @@ var Font = (function Font() {
       createOpenTypeHeader(header.version, ttf, numTables);
 
       if (requiredTables.indexOf('OS/2') != -1) {
+        if (typeof(head) != 'undefined') {
+          var ymax = int16([head.data[42],head.data[43]]);
+          var ymin = int16([head.data[38],head.data[39]]) - 0x10000;   //always negative
+          properties.ascent = ymax;
+          properties.descent = ymin;
+        }
+
         tables.push({
           tag: 'OS/2',
           data: stringToArray(createOS2Table(properties))