095484bc616cbbec0345db69e7e6b7f410676e40 galt Fri Dec 2 18:20:49 2011 -0800 added monospace font option to phyloGif diff --git src/hg/phyloGif/phyloGif.c src/hg/phyloGif/phyloGif.c index b1f8723..7db7a57 100644 --- src/hg/phyloGif/phyloGif.c +++ src/hg/phyloGif/phyloGif.c @@ -66,30 +66,31 @@ #include "errabort.h" #include "errCatch.h" struct cart *cart=NULL; /* The user's ui state. */ struct hash *oldVars = NULL; boolean onWeb = FALSE; int width=240,height=512; boolean branchLengths = FALSE; /* branch lengths */ boolean lengthLegend = FALSE; /* length ruler*/ boolean branchLabels = FALSE; /* labelled branch lengths */ boolean htmlPageWrapper = FALSE; /* wrap output in an html page */ boolean preserveUnderscores = FALSE; /* preserve underscores in input as spaces in output */ +boolean monospace = FALSE; /* use monospace font */ int branchDecimals = 2; /* show branch label length to two decimals by default */ int branchMultiplier = 1; /* multiply branch length by factor */ char *escapePattern = NULL; /* use to escape dash '-' char in input */ char layoutErrMsg[1024] = ""; /* Null terminated list of CGI Variables we don't want to save * permanently. */ char *excludeVars[] = {"Submit", "submit", "phyloGif_submit", "phyloGif_restore", NULL}; void usage(char *msg) /* Explain usage and exit. */ { errAbort( "%s\n\n" "phyloGif - parse and display phyloGenetic tree\n" @@ -104,30 +105,31 @@ " http://someserver.com/cgi-bin/phyloGif?phyloGif_tree=(A:0.1,B:0.1)\n" "Options/CGI-vars:\n" " -phyloGif_width=N - width of output GIF, default %d\n" " -phyloGif_height=N - height of output GIF, default %d\n" " -phyloGif_tree= - data in format (nodeA:0.5,nodeB:0.6):1.2;\n" " If running at the command-line, can put filename here or stdin\n" " (this is actually required)\n" " -phyloGif_branchLengths - use branch lengths for layout\n" " -phyloGif_lengthLegend - show length ruler at bottom\n" " -phyloGif_branchLabels - show length of branch as label\n" " (used with -phyloGif_branchLengths)\n" " -phyloGif_branchDecimals=N - show length of branch to N decimals, default %d\n" " -phyloGif_branchMultiplier=N - multiply branch length by N default %d\n" " -phyloGif_htmlPage - wrap the output in an html page (cgi only)\n" " -phyloGif_underscores - preserve underscores in input as spaces in output\n" + " -phyloGif_monospace - use a monospace proportional font\n" , msg, width, height, branchDecimals, branchMultiplier); } struct phyloLayout { int depth; /* leaves have depth=0 */ double vPos; /* vertical position */ double hPos; /* horizontal position */ }; void stripUnderscoreSuffixes(char *s) /* Strip out underscores in labels, modifies s. */ { @@ -351,92 +353,94 @@ htmlSetBackground(hBackgroundImage()); /* uses cfgOption */ /* this will cause it to kick out the set-cookie: http response header line */ cart = cartAndCookieNoContent(hUserCookie(), excludeVars, oldVars); } else { if (!cgiOptionalString("phyloGif_tree")) usage("-phyloGif_tree is a required 'option' or cgi variable."); } //cartWarnCatcher(doMiddle, cart, cartEarlyWarningHandler); useCart = (!cgiOptionalString("phyloGif_tree") || cgiVarExists("phyloGif_restore")); -MgFont *font = mgMediumBoldFont(); htmlPageWrapper = cgiVarExists("phyloGif_htmlPage"); /* wrap output in a page */ if (onWeb && sameString(getenv("REQUEST_METHOD"),"HEAD")) { /* tell browser it's static just so it can save it */ if (htmlPageWrapper) printf("Content-type: text/html\r\n"); else printf("Content-type: image/gif\r\n"); printf("\r\n"); return 0; } if (useCart) { width = cartUsualInt(cart,"phyloGif_width",width); height = cartUsualInt(cart,"phyloGif_height",height); phyloData = cloneString(cartOptionalString(cart,"phyloGif_tree")); branchLengths = cartVarExists(cart,"phyloGif_branchLengths"); lengthLegend = cartVarExists(cart,"phyloGif_lengthLegend"); branchLabels = cartVarExists(cart,"phyloGif_branchLabels"); branchDecimals = cartUsualInt(cart,"phyloGif_branchDecimals", branchDecimals); branchMultiplier = cartUsualInt(cart,"phyloGif_branchMultiplier", branchMultiplier); preserveUnderscores = cartVarExists(cart,"phyloGif_underscores"); + monospace = cartVarExists(cart, "phyloGif_monospace"); } else { width = cgiUsualInt("phyloGif_width",width); height = cgiUsualInt("phyloGif_height",height); phyloData = cloneString(cgiOptionalString("phyloGif_tree")); branchLengths = cgiVarExists("phyloGif_branchLengths"); lengthLegend = cgiVarExists("phyloGif_lengthLegend"); branchLabels = cgiVarExists("phyloGif_branchLabels"); branchDecimals = cgiUsualInt("phyloGif_branchDecimals", branchDecimals); branchMultiplier = cgiUsualInt("phyloGif_branchMultiplier", branchMultiplier); preserveUnderscores = cgiVarExists("phyloGif_underscores"); + monospace = cgiVarExists("phyloGif_monospace"); } if (useCart) { if (onWeb) { printf("Content-type: text/html\r\n"); printf("\r\n"); cartWebStart(cart, NULL, "%s", "phyloGif Interactive Phylogenetic Tree Gif Maker"); if (isMSIE) /* cannot handle long urls */ puts("<form method=\"POST\" action=\"phyloGif\" name=\"mainForm\">"); else puts("<form method=\"GET\" action=\"phyloGif\" name=\"mainForm\">"); cartSaveSession(cart); puts("<table>"); puts("<tr><td>Width:</td><td>"); cartMakeIntVar(cart, "phyloGif_width", width, 4); puts("</td></tr>"); puts("<tr><td>Height:</td><td>"); cartMakeIntVar(cart, "phyloGif_height", height, 4); puts("</td></tr>"); puts("<tr><td>Use branch lengths?</td><td>"); cartMakeCheckBox(cart, "phyloGif_branchLengths", branchLengths); puts("</td></tr>"); puts("<tr><td> Show length ruler?</td><td>"); cartMakeCheckBox(cart, "phyloGif_lengthLegend", lengthLegend); puts("</td></tr>"); puts("<tr><td> Show length values?</td><td>"); cartMakeCheckBox(cart, "phyloGif_branchLabels", branchLabels); puts("</td></tr>"); puts("<tr><td> How many decimal places?</td><td>"); cartMakeIntVar(cart, "phyloGif_branchDecimals", branchDecimals,1); puts("</td></tr>"); puts("<tr><td> Multiply branch length by factor?</td><td>"); cartMakeIntVar(cart, "phyloGif_branchMultiplier", branchMultiplier,5); puts("</td></tr>"); puts("<tr><td>Preserve Underscores?</td><td>"); cartMakeCheckBox(cart, "phyloGif_underscores", preserveUnderscores); puts("</td></tr>"); puts("<tr><td>Wrap in html page?</td><td>"); cartMakeCheckBox(cart, "phyloGif_htmlPage", htmlPageWrapper); puts("</td></tr>"); + puts("<tr><td>Monospace font?</td><td>"); cartMakeCheckBox(cart, "phyloGif_monospace", monospace); puts("</td></tr>"); printf("<tr><td><big>TREE:</big>"); puts("<br><br><INPUT type=\"submit\" name=\"phyloGif_restore\" value=\"restore default\">"); puts("</td><td><textarea name=\"phyloGif_tree\" rows=14 cols=70>"); if (NULL == phyloData || phyloData[0] == '\0' || cgiVarExists("phyloGif_restore")) { puts( "(((((((((\n" "(human_hg18:0.00669,chimp_panTro1:0.00757):0.0243,\n" " macaque_rheMac2:0.0592):0.0240,\n" " ((rat_rn4:0.0817,mouse_mm8:0.0770):0.229,\n" " rabbit_oryCun1:0.207):0.107):0.0230,\n" " (cow_bosTau2:0.159,dog_canFam2:0.148):0.0394):0.0285,\n" " armadillo_dasNov1:0.150):0.0160,\n" @@ -528,30 +532,32 @@ printf("<IMAGE SRC=\"http://%s%s" "?phyloGif_width=%d" "&phyloGif_height=%d" "&phyloGif_tree=%s" ,getenv("SERVER_NAME"),getenv("SCRIPT_NAME"),width,height,phyloData); if (branchLengths) printf("&phyloGif_branchLengths=1"); if (lengthLegend) printf("&phyloGif_lengthLegend=1"); if (branchLabels) printf("&phyloGif_branchLabels=1"); printf("&phyloGif_branchDecimals=%d",branchDecimals); printf("&phyloGif_branchMultipliers=%d",branchMultiplier); if (preserveUnderscores) printf("&phyloGif_underscores=1"); + if (monospace) + printf("&phyloGif_monospace=1"); puts("\"></body></html>"); freez(&phyloData); return 0; } if (!onWeb && phyloData[0] != '(') { int fd = 0; /* default to stdin */ if (!sameString(phyloData,"stdin")) fd = open(phyloData,O_RDONLY); struct dyString *dy = netSlurpFile(fd); if (fd) close(fd); @@ -624,30 +630,36 @@ printf("Parser syntax error:\n%s",errMsg); puts("</pre></body></html>"); } else { warn("%s", errMsg); } freez(&errMsg); freez(&phyloData); return 0; } } +MgFont *font = NULL; +if (monospace) + font = mgMenloMediumFont(); +else + font = mgMediumBoldFont(); + if (phyloTree) { mg = mgNew(width,height); mgClearPixels(mg); lengthLegend = lengthLegend && branchLengths; /* moot without lengths */ if (lengthLegend) { int fHeight = mgFontPixelHeight(font); height -= (MARGIN+2*fHeight); } phyloTreeLayoutBL(phyloTree, &maxDepth, &numLeafs, 0, font, &maxLabelWidth, width, &minMaxFactor, 0.0);