Index: /gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/js/document_viewer.js
===================================================================
--- /gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/js/document_viewer.js	(revision 36996)
+++ /gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/js/document_viewer.js	(revision 36997)
@@ -1,2 +1,134 @@
+function load_gv_dococr_json(json_file, callback) {
+
+    var http_assocfilepath = gs.collectionMetadata["httpPath"]+"/index/assoc/"+gs.documentMetadata["assocfilepath"];
+    var json_url = http_assocfilepath +"/"+json_file;
+
+    $.ajax({
+	method: "GET",
+	url: json_url
+    })
+        .fail(function(jqXHR,textStatus) {
+            console.error("load_gv_dococr_json(): failed to retrieve url '" + json_url +"'");
+	    console.error(textStatus);
+        })
+        .done(function(gv_ocr_json_result) {
+	    callback(gv_ocr_json_result);
+
+        });
+    
+}
+
+function display_gv_ocr_bounding_boxes(gv_ocr_json)
+{
+    console.log(gv_ocr_json);
+
+    
+    var full_text_annotation = gv_ocr_json.fullTextAnnotation;
+    var pages = full_text_annotation.pages;
+    var num_pages = pages.length;
+    
+    if (num_pages == 1) {
+	var page = pages[0];
+
+	var bounding_box_rects = [];
+	var page_x_dim = page.width;
+	var page_y_dim = page.height;
+
+	var blocks = page.blocks;
+	var num_blocks = blocks.length;
+
+	for (b=0; b<num_blocks; b++) {
+	    var block = blocks[b];
+
+	    var boundingBox = block.boundingBox;
+
+	    var min_x = Number.MAX_SAFE_INTEGER;
+	    var min_y = Number.MAX_SAFE_INTEGER;
+	    var max_x = Number.MIN_SAFE_INTEGER;
+	    var max_y = Number.MIN_SAFE_INTEGER;
+
+	    var vertices = boundingBox.vertices;
+	    var num_vertices = vertices.length;
+
+	    for (v=0; v<num_vertices; v++) {
+		var x = vertices[v].x;
+		var y = vertices[v].y;
+		
+		min_x = Math.min(min_x,x);
+		min_y = Math.min(min_y,y);
+		max_x = Math.max(max_x,x);
+		max_y = Math.max(max_y,y);
+	    }
+
+	    var x_org = min_x;
+	    var y_org = min_y;
+	    var x_dim = max_x - min_x +1;
+	    var y_dim = max_y - min_y +1;
+
+	    var rect = { "x_org": x_org, "y_org": y_org, "x_dim": x_dim, "y_dim": y_dim};
+	    bounding_box_rects.push(rect);
+	}
+
+	    
+	display_scaled_div_bounding_boxes(bounding_box_rects, page_x_dim,page_y_dim);
+	
+    }
+    else {
+	console.error("display_gv_ocr_bounding_boxes(): incorrect number of pages found.")
+	console.error("  Expected 1 page, found " + num_pages +" page(s)");
+    }
+
+}
+
+
+function display_scaled_div_bounding_boxes(bounding_box_rects,fullsize_x_dim,fullsize_y_dim)
+{
+    var screen_x_dim = gs.variables.screenImageWidth;
+    var screen_y_dim = gs.variables.screenImageHeight;
+
+    var scale_x = screen_x_dim / fullsize_x_dim;
+    var scale_y = screen_y_dim / fullsize_y_dim;
+
+    //console.log("scale x = " + scale_x);
+    //console.log("scale y = " + scale_y);
+    
+    var docID = gs.variables.d;    
+    var screen_image_id = "small"+docID;
+
+    var $boundingbox_overlay = $("<div>")
+	.attr("id","ocr-boundingbox-overlay-"+docID)
+	.attr("class","ocr-boundingbox-overlay");
+
+    var $screen_div = $('#'+screen_image_id);
+    //var $screen_img = $screen_div.find("img");
+    
+    $screen_div.append($boundingbox_overlay);
+    //$screen_img.append($boundingbox_overlay);
+
+    
+    var num_bb_rects = bounding_box_rects.length;
+
+    console.log("Block bounding boxes:")
+
+    for (r=0; r<num_bb_rects; r++) {
+	var rect = bounding_box_rects[r];
+    	console.log("  " + JSON.stringify(rect));
+
+	var scaled_x_org = rect.x_org * scale_x;
+	var scaled_y_org = rect.y_org * scale_y;
+	var scaled_x_dim = rect.x_dim * scale_x;
+	var scaled_y_dim = rect.y_dim * scale_y;
+		
+	var $boundingbox_div = $("<div>")
+	    .attr("class","ocr-boundingbox")
+	    .css("left",  scaled_x_org)
+	    .css("top",   scaled_y_org)
+	    .css("width", scaled_x_dim)
+	    .css("height",scaled_y_dim);
+	
+	$boundingbox_overlay.append($boundingbox_div)
+    }
+}
+
 /*
 
Index: /gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/transform/pages/document.xsl
===================================================================
--- /gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/transform/pages/document.xsl	(revision 36996)
+++ /gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/transform/pages/document.xsl	(revision 36997)
@@ -9,28 +9,100 @@
 	exclude-result-prefixes="java util gsf">
 
+
+  <xsl:template name="iiif-links">
+    <xsl:param name="identifier"/>
+    
+    <div style="padding-top: 10px; padding-bottom: 10px;">
+      IIIF Server Info URL:
+      <a href="/gs-cantaloupe/iiif/2/{$site_name}:{$collNameChecked}:{$identifier}/info.json">
+	/gs-cantaloupe/iiif/2/<xsl:value-of select="$site_name"/>:<xsl:value-of select="$collNameChecked"/>:<xsl:value-of select="$identifier"/>/info.json
+	</a> 
+    </div>
+
+    <div style="padding-top: 10px; padding-bottom: 10px;">
+      IIIF Server Image URL:
+      <a href="/gs-cantaloupe/iiif/2/{$site_name}:{$collNameChecked}:{$identifier}/full/full/0/default.jpg">
+	/gs-cantaloupe/iiif/2/<xsl:value-of select="$site_name"/>:<xsl:value-of select="$collNameChecked"/>:<xsl:value-of select="$identifier"/>/full/full/0/default.jpg
+	</a> <br />
+    </div>
+    
+  </xsl:template>
+
+
+  <xsl:template name="googlevision-ocr-json">
+    <xsl:param name="assocfilepath"/>
+    
+    <div style="padding-top: 10px; padding-bottom: 10px;">
+      Google Vision OCR JSON:
+      <a>
+	<xsl:attribute name="href">
+	  <xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name = 'httpPath']"/>
+	  <xsl:text>/index/assoc/</xsl:text><xsl:value-of disable-output-escaping="yes" select="$assocfilepath" /><xsl:text>/</xsl:text>enable_document_ocrgoogle-vision-output.json
+	</xsl:attribute>
+	enable_document_ocrgoogle-vision-output.json
+      </a>
+    </div>
+    <gsf:script>
+      load_gv_dococr_json("enable_document_ocrgoogle-vision-output.json",display_gv_ocr_bounding_boxes);
+    </gsf:script>
+  </xsl:template>
+
 <!--
-	<xsl:template name="documentHeading">
-	  <span style="font-weight:bold; font-size: 120%;">
-	    <xsl:call-template name="choose-title"/>
-	  </span>
-	  <gsf:metadata-table>
-	    <gsf:metadata name="ex.im.Work"/>
-	    <gsf:metadata name="ex.im.Artist"/>
-	    <gsf:metadata name="ex.im.Venue"/>
-	    <gsf:metadata name="ex.im.Composer"/>
-	  </gsf:metadata-table>
-	</xsl:template>
+  <xsl:template name="sectionPre">
+    OCR'd Text:
+  </xsl:template>
+
+  <xsl:template name="documentPre">
+    OCR'd Text:
+  </xsl:template>
 -->
+
+  <xsl:template name="sectionPost">
+    <!-- add in IIIF Server link for section image -->
+    <xsl:variable name="nodeID" select="@nodeID"/>
+    <xsl:call-template name="iiif-links">
+      <xsl:with-param name="identifier" select="$nodeID" />
+    </xsl:call-template>
+    <!-- add in Google Vision OCR JSON link for section image -->
+    <xsl:call-template name="googlevision-ocr-json">
+      <xsl:with-param name="assocfilepath"><gsf:metadata name="assocfilepath" select="root"/></xsl:with-param>
+    </xsl:call-template>    
+  </xsl:template>
+
+  <xsl:template name="documentPre">
+     <xsl:variable name="httpCollection">library/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="/page/pageResponse/collection/@name"/></xsl:variable>
+     <gsf:script src="{$httpCollection}/js/document_viewer.js"/>
+     <style>
+       div.ocr-boundingbox-overlay {
+         position: absolute;
+         left: 0;
+         top: 0;
+       }
+
+       div.ocr-boundingbox {
+         position: absolute;
+         border: solid black 1px;
+       }
+
+     </style>
+  </xsl:template>
+  
+  <xsl:template name="documentPost">
+    <!-- add in IIIF Server link for simple page image -->
+    <xsl:if test="@docType='simple'">
+      <xsl:call-template name="iiif-links">
+	<xsl:with-param name="identifier" select="$docID" />
+      </xsl:call-template>
+      <!-- add in Google Vision OCR JSON link for simple page image -->      
+      <xsl:call-template name="googlevision-ocr-json">
+	<xsl:with-param name="assocfilepath"><gsf:metadata name="assocfilepath" pos="first"/></xsl:with-param>
+      </xsl:call-template>
+    </xsl:if>   
+  </xsl:template>
+
   
 	<!-- content of a simple document. Will not be used for editing mode -->
 	<xsl:template name="documentPostInProgress">
 
-			<div style="padding-top: 10px; padding-bottom: 10px;">
-			  <gsf:variable name="OID"><xsl:value-of select="@nodeID"/></gsf:variable>
-			  IIIF Server Info URL:
-			  <a href="/gs-cantaloupe/iiif/2/{$site_name}:{$collNameChecked}:{$OID}/info.json">
-			    /gs-cantaloupe/iiif/2/<xsl:value-of select="$site_name"/>:<xsl:value-of select="$collNameChecked"/>:<xsl:value-of select="$OID"/>/info.json
-			  </a>
-			</div>
 
 			<!--
