7c676d04904b3f19d6724b45fd26d45bb9b3ba6f
larrym
  Fri Dec 16 12:27:31 2011 -0800
show assembly next to scale bar (redmin #4073); add code to support pdf in hgRenderTracks (currently only live in larrym's tree)
diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c
index a91f1d0..a973245 100644
--- src/hg/hgTracks/hgTracks.c
+++ src/hg/hgTracks/hgTracks.c
@@ -1767,30 +1767,35 @@
     char scaleText[32];
     int numBases = winEnd-winStart;
     int scaleBases = computeScaleBar(numBases, scaleText, sizeof(scaleText));
     int scalePixels = (int)((double)insideWidth*scaleBases/numBases);
     int scaleBarX = insideX + (int)(((double)insideWidth-scalePixels)/2);
     int scaleBarEndX = scaleBarX + scalePixels;
     int scaleBarY = y + 0.5 * scaleBarTotalHeight;
     *rulerClickHeight += scaleBarTotalHeight;
     hvGfxTextRight(hvg, insideX, y + scaleBarPad,
 	    (scaleBarX-2)-insideX, scaleBarHeight, MG_BLACK, font, scaleText);
     hvGfxLine(hvg, scaleBarX, scaleBarY, scaleBarEndX, scaleBarY, MG_BLACK);
     hvGfxLine(hvg, scaleBarX, y+scaleBarPad, scaleBarX,
 	    y+scaleBarTotalHeight-scaleBarPad, MG_BLACK);
     hvGfxLine(hvg, scaleBarEndX, y+scaleBarPad, scaleBarEndX,
 	    y+scaleBarTotalHeight-scaleBarPad, MG_BLACK);
+    if(cartUsualBoolean(cart, BASE_SHOWASM_SCALEBAR, TRUE))
+        {
+        int fHeight = vgGetFontPixelHeight(hvg->vg, font);
+        hvGfxText(hvg, scaleBarEndX + 10, y + (scaleBarTotalHeight - fHeight)/2 + ((font == mgSmallFont()) ?  1 : 0), MG_BLACK, font, database);
+        }
     y += scaleBarTotalHeight;
     }
 if (baseShowRuler)
     {
     hvGfxDrawRulerBumpText(hvg, insideX, y, rulerHeight, insideWidth, MG_BLACK,
 		font, relNumOff, winBaseCount, 0, 1);
     }
 *newWinWidth = makeRulerZoomBoxes(hvg, cart,winStart,winEnd,insideWidth,seqBaseCount,rulerClickY,*rulerClickHeight);
 
 if (zoomedToBaseLevel || rulerCds)
     {
     Color baseColor = MG_BLACK;
     int start, end, chromSize;
     struct dnaSeq *extraSeq;
     /* extraSeq has extra leading & trailing bases
@@ -2543,50 +2548,66 @@
     {
     struct jsonHashElement *json = newJsonHash(newHash(8));
 
     printf("Content-Type: application/json\n\n");
     jsonHashAddString(json, "track", cartString(cart, "hgt.trackNameFilter"));
     jsonHashAddNumber(json, "height", pixHeight);
     jsonHashAddNumber(json, "width", pixWidth);
     jsonHashAddString(json, "img", gifTn.forHtml);
     printf("%s(", cartString(cart, "jsonp"));
     hPrintEnable();
     jsonPrint((struct jsonElement *) json, NULL, 0);
     hPrintDisable();
     printf(")\n");
     return;
     }
-else if(sameString(type, "png"))
+else if(sameString(type, "png") || sameString(type, "pdf") || sameString(type, "eps"))
+    {
+    // following code bypasses html and return png's directly - see redmine 4888
+    char *file;
+    if(sameString(type, "pdf"))
+        {
+        printf("Content-Disposition: filename=hgTracks.pdf\nContent-Type: application/pdf\n\n");
+        file = convertEpsToPdf(psOutput);
+        unlink(psOutput);
+        }
+    else if(sameString(type, "eps"))
+        {
+        printf("Content-Disposition: filename=hgTracks.eps\nContent-Type: application/eps\n\n");
+        file = psOutput;
+        }
+    else
     {
-    // following is (currently dead) experimental code to bypass hgml and return png's directly - see redmine 4888
     printf("Content-Disposition: filename=hgTracks.png\nContent-Type: image/png\n\n");
+        file = gifTn.forCgi;
+        }
 
     char buf[4096];
-    FILE *fd = fopen(gifTn.forCgi, "r");
+    FILE *fd = fopen(file, "r");
     if(fd == NULL)
         // fail some other way (e.g. HTTP 500)?
         errAbort("Couldn't open png for reading");
     while(TRUE)
         {
         size_t n = fread(buf, 1, sizeof(buf), fd);
         if(n)
             fwrite(buf, 1, n, stdout);
         else
             break;
         }
     fclose(fd);
-    unlink(gifTn.forCgi);
+    unlink(file);
     return;
     }
 #endif
 
 if(theImgBox)
     {
     imageBoxDraw(theImgBox);
     #ifdef IMAGEv2_DRAG_SCROLL
     // If a portal was established, then set the global dimensions back to the portal size
     if(imgBoxPortalDimensions(theImgBox,NULL,NULL,NULL,NULL,&winStart,&winEnd,&(tl.picWidth),NULL))
         {
         pixWidth = tl.picWidth;
         winBaseCount = winEnd - winStart;
         insideWidth = tl.picWidth-gfxBorder-insideX;
         }
@@ -5482,35 +5503,38 @@
     }
 x = atof(stringVal);
 int ret = round(x*guideBases);
 
 return (ret == 0) ? 1 : ret;
 }
 
 void handlePostscript()
 /* Deal with Postscript output. */
 {
 struct tempName psTn, ideoPsTn;
 char *pdfFile = NULL, *ideoPdfFile = NULL;
 ZeroVar(&ideoPsTn);
 trashDirFile(&psTn, "hgt", "hgt", ".eps");
 
+if(!trackImgOnly)
+    {
 hotLinks();
 printf("<H1>PostScript/PDF Output</H1>\n");
 printf("PostScript images can be printed at high resolution "
        "and edited by many drawing programs such as Adobe "
        "Illustrator.");
+    }
 doTrackForm(psTn.forCgi, &ideoPsTn);
 
 // postscript
 printf("<UL>\n");
 printf("<LI><A HREF=\"%s\">Click here</A> "
        "to download the current browser graphic in PostScript.\n", psTn.forCgi);
 if (strlen(ideoPsTn.forCgi))
     printf("<LI><A HREF=\"%s\">Click here</A> "
            "to download the current chromosome ideogram in PostScript.\n", ideoPsTn.forCgi);
 printf("</UL>\n");
 
 pdfFile = convertEpsToPdf(psTn.forCgi);
 if (strlen(ideoPsTn.forCgi))
     ideoPdfFile = convertEpsToPdf(ideoPsTn.forCgi);
 if(pdfFile != NULL)
@@ -5703,31 +5727,31 @@
     }
 
 if (winStart > seqBaseCount)
     {
     winStart = seqBaseCount - 1000;
     }
 
 winBaseCount = winEnd - winStart;
 if (winBaseCount <= 0)
     hUserAbort("Window out of range on %s", chromName);
 /* Save computed position in cart. */
 sprintf(newPos, "%s:%d-%d", chromName, winStart+1, winEnd);
 cartSetString(cart, "org", organism);
 cartSetString(cart, "db", database);
 cartSetString(cart, "position", newPos);
-if (cgiVarExists("hgt.psOutput"))
+if (cartUsualBoolean(cart, "hgt.psOutput", FALSE))
     handlePostscript();
 else
     doTrackForm(NULL, NULL);
 }
 
 void chromInfoTotalRow(int count, long long total)
 /* Make table row with total number of sequences and size from chromInfo. */
 {
 cgiSimpleTableRowStart();
 cgiSimpleTableFieldStart();
 printf("Total: %d", count);
 cgiTableFieldEnd();
 cgiSimpleTableFieldStart();
 printLongWithCommas(stdout, total);
 cgiTableFieldEnd();