src/hg/lib/trackLayout.c 1.5

1.5 2010/04/22 19:35:38 kent
Refactoring font-for-size code so that Table Browser can reuse it, and thus not make an error message in correlation page.
Index: src/hg/lib/trackLayout.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/trackLayout.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -b -B -U 4 -r1.4 -r1.5
--- src/hg/lib/trackLayout.c	27 Mar 2010 04:26:47 -0000	1.4
+++ src/hg/lib/trackLayout.c	22 Apr 2010 19:35:38 -0000	1.5
@@ -45,103 +45,19 @@
     }
 return enabled;
 }
 
-static char *fontSizeBackwardsCompatible(char *size)
-/* Given "size" argument that may be in old tiny/small/medium/big/huge format,
- * return it in new numerical string format. */
-{
-if (isdigit(size[0]))
-    return size;
-else if (sameWord(size, "tiny"))
-    return "6";
-else if (sameWord(size, "small"))
-    return "8";
-else if (sameWord(size, "medium"))
-    return "14";
-else if (sameWord(size, "large"))
-    return "18";
-else if (sameWord(size, "huge"))
-    return "34";
-else
-    {
-    errAbort("unknown font size %s", size);
-    return NULL;
-    }
-}
-
 void trackLayoutInit(struct trackLayout *tl, struct cart *cart)
 /* Initialize layout around small font and a picture about 600 pixels
  * wide, but this can be overridden by cart. */
 {
-char *fontType = cartUsualString(cart, "fontType", "medium");
+char *fontType = "medium";
 boolean fontExtras = trackLayoutInclFontExtras();
+if (fontExtras)
+    fontType = cartUsualString(cart, "fontType", fontType);
 
-tl->textSize = fontSizeBackwardsCompatible(cartUsualString(cart, textSizeVar, "small"));
-MgFont *font = NULL;
-if (fontExtras && sameString(fontType,"bold"))
-    {
-    if (sameString(tl->textSize, "6"))
-	 font = mgTinyBoldFont();
-    else if (sameString(tl->textSize, "8"))
-	 font = mgHelveticaBold8Font();
-    else if (sameString(tl->textSize, "10"))
-	 font = mgHelveticaBold10Font();
-    else if (sameString(tl->textSize, "12"))
-	 font = mgHelveticaBold12Font();
-    else if (sameString(tl->textSize, "14"))
-	 font = mgHelveticaBold14Font();
-    else if (sameString(tl->textSize, "18"))
-	 font = mgHelveticaBold18Font();
-    else if (sameString(tl->textSize, "24"))
-	 font = mgHelveticaBold24Font();
-    else if (sameString(tl->textSize, "34"))
-	 font = mgHelveticaBold34Font();
-    else
-	 errAbort("unknown textSize %s", tl->textSize);
-    }
-else if (fontExtras && sameString(fontType,"fixed"))
-    {
-    if (sameString(tl->textSize, "6"))
-	 font = mgTinyFixedFont();
-    else if (sameString(tl->textSize, "8"))
-	 font = mgCourier8Font();
-    else if (sameString(tl->textSize, "10"))
-	 font = mgCourier10Font();
-    else if (sameString(tl->textSize, "12"))
-	 font = mgCourier12Font();
-    else if (sameString(tl->textSize, "14"))
-	 font = mgCourier14Font();
-    else if (sameString(tl->textSize, "18"))
-	 font = mgCourier18Font();
-    else if (sameString(tl->textSize, "24"))
-	 font = mgCourier24Font();
-    else if (sameString(tl->textSize, "34"))
-	 font = mgCourier34Font();
-    else
-	 errAbort("unknown textSize %s", tl->textSize);
-    }
-else
-    {
-    if (sameString(tl->textSize, "6"))
-	 font = mgTinyFont();
-    else if (sameString(tl->textSize, "8"))
-	 font = mgSmallFont();
-    else if (sameString(tl->textSize, "10"))
-	 font = mgHelvetica10Font();
-    else if (sameString(tl->textSize, "12"))
-	 font = mgHelvetica12Font();
-    else if (sameString(tl->textSize, "14"))
-	 font = mgHelvetica14Font();
-    else if (sameString(tl->textSize, "18"))
-	 font = mgHelvetica18Font();
-    else if (sameString(tl->textSize, "24"))
-	 font = mgHelvetica24Font();
-    else if (sameString(tl->textSize, "34"))
-	 font = mgHelvetica34Font();
-    else
-	 errAbort("unknown textSize %s", tl->textSize);
-    }
+tl->textSize = mgFontSizeBackwardsCompatible(cartUsualString(cart, textSizeVar, "small"));
+MgFont *font = mgFontForSizeAndStyle(tl->textSize, fontType);
 tl->font = font;
 tl->mWidth = mgFontStringWidth(font, "M");
 tl->nWidth = mgFontStringWidth(font, "n");
 tl->fontHeight = mgFontLineHeight(font);