src/lib/memgfx.c 1.53
1.53 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/lib/memgfx.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/memgfx.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -b -B -U 4 -r1.52 -r1.53
--- src/lib/memgfx.c 27 Mar 2010 04:23:08 -0000 1.52
+++ src/lib/memgfx.c 22 Apr 2010 19:35:38 -0000 1.53
@@ -611,8 +611,114 @@
{
return mgFontWidth(font, &c, 1);
}
+char *mgFontSizeBackwardsCompatible(char *size)
+/* Given "size" argument that may be in old tiny/small/medium/big/huge format,
+ * return it in new numerical string format. Do NOT free the return string*/
+{
+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;
+ }
+}
+
+MgFont *mgFontForSizeAndStyle(char *textSize, char *fontType)
+/* Get a font of given size and style. Abort with error message if not found.
+ * The textSize should be 6,8,10,12,14,18,24 or 34. For backwards compatibility
+ * textSizes of "tiny" "small", "medium", "large" and "huge" are also ok.
+ * The fontType should be "medium", "bold", or "fixed" */
+{
+textSize = mgFontSizeBackwardsCompatible(textSize);
+MgFont *font = NULL;
+if (sameString(fontType,"bold"))
+ {
+ if (sameString(textSize, "6"))
+ font = mgTinyBoldFont();
+ else if (sameString(textSize, "8"))
+ font = mgHelveticaBold8Font();
+ else if (sameString(textSize, "10"))
+ font = mgHelveticaBold10Font();
+ else if (sameString(textSize, "12"))
+ font = mgHelveticaBold12Font();
+ else if (sameString(textSize, "14"))
+ font = mgHelveticaBold14Font();
+ else if (sameString(textSize, "18"))
+ font = mgHelveticaBold18Font();
+ else if (sameString(textSize, "24"))
+ font = mgHelveticaBold24Font();
+ else if (sameString(textSize, "34"))
+ font = mgHelveticaBold34Font();
+ else
+ errAbort("unknown textSize %s", textSize);
+ }
+else if (sameString(fontType,"fixed"))
+ {
+ if (sameString(textSize, "6"))
+ font = mgTinyFixedFont();
+ else if (sameString(textSize, "8"))
+ font = mgCourier8Font();
+ else if (sameString(textSize, "10"))
+ font = mgCourier10Font();
+ else if (sameString(textSize, "12"))
+ font = mgCourier12Font();
+ else if (sameString(textSize, "14"))
+ font = mgCourier14Font();
+ else if (sameString(textSize, "18"))
+ font = mgCourier18Font();
+ else if (sameString(textSize, "24"))
+ font = mgCourier24Font();
+ else if (sameString(textSize, "34"))
+ font = mgCourier34Font();
+ else
+ errAbort("unknown textSize %s", textSize);
+ }
+else
+ {
+ if (sameString(textSize, "6"))
+ font = mgTinyFont();
+ else if (sameString(textSize, "8"))
+ font = mgSmallFont();
+ else if (sameString(textSize, "10"))
+ font = mgHelvetica10Font();
+ else if (sameString(textSize, "12"))
+ font = mgHelvetica12Font();
+ else if (sameString(textSize, "14"))
+ font = mgHelvetica14Font();
+ else if (sameString(textSize, "18"))
+ font = mgHelvetica18Font();
+ else if (sameString(textSize, "24"))
+ font = mgHelvetica24Font();
+ else if (sameString(textSize, "34"))
+ font = mgHelvetica34Font();
+ else
+ errAbort("unknown textSize %s", textSize);
+ }
+return font;
+}
+
+MgFont *mgFontForSize(char *textSize)
+/* Get a font of given size and style. Abort with error message if not found.
+ * The textSize should be 6,8,10,12,14,18,24 or 34. For backwards compatibility
+ * textSizes of "tiny" "small", "medium", "large" and "huge" are also ok. */
+{
+return mgFontForSizeAndStyle(textSize, "medium");
+}
+
+
void mgSlowDot(struct memGfx *mg, int x, int y, int colorIx)
/* Draw a dot when a macro won't do. */
{
mgPutDot(mg, x, y, colorIx);