From ebc483a0c7a4f1e0b79074b964ed996719e9f7c7 Mon Sep 17 00:00:00 2001
From: Chris Jones <jones.chris.g@gmail.com>
Date: Thu, 2 Jun 2011 14:24:46 -0500
Subject: [PATCH] Font and XObject entries can be refs, and dump image magic
 bytes

---
 pdf.js    | 12 +++++++++++-
 test.html |  1 +
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/pdf.js b/pdf.js
index 8ac26e932..061be93c5 100644
--- a/pdf.js
+++ b/pdf.js
@@ -2129,6 +2129,7 @@ var CanvasGraphics = (function() {
             this.xref = xref;
             this.res = resources || new Dict();
             this.xobjs = this.res.get("XObject") || new Dict();
+            this.xobjs = this.xref.fetchIfRef(this.xobjs);
 
             var args = [];
             var map = this.map;
@@ -2252,7 +2253,11 @@ var CanvasGraphics = (function() {
         endText: function() {
         },
         setFont: function(fontRef, size) {
-            var font = this.res.get("Font").get(fontRef.name);
+            var fontRes = this.res.get("Font");
+            if (!fontRes)
+                return;
+            fontRes = this.xref.fetchIfRef(fontRes);
+            var font = fontRes.get(fontRef.name);
             if (!font)
                 return;
             this.current.fontSize = size;
@@ -2353,6 +2358,11 @@ var CanvasGraphics = (function() {
             var type = xobj.dict.get("Subtype");
             assertWellFormed(IsName(type), "XObject should have a Name subtype");
             if ("Image" == type.name) {
+                var magic = "";
+                for (var i = 0; i < 8; ++i)
+                    magic += xobj.bytes[i].toString(16) +" ";
+                console.log("Image magic bytes: "+ magic);
+
                 TODO("Image XObjects");
             } else if ("Form" == type.name) {
                 this.paintFormXObject(xobj);
diff --git a/test.html b/test.html
index 10a35e163..0d7d8ce8e 100644
--- a/test.html
+++ b/test.html
@@ -41,6 +41,7 @@ function load() {
     pageDisplay = document.getElementById("pageNumber");
     infoDisplay = document.getElementById("info");
     open("uncompressed.tracemonkey-pldi-09.pdf");
+//    open("uncompressed.report.pdf");
 }
 
 function open(url) {