Cleaned up set_font_size() in NEDsim. Leaving the inefficient version since we only...
authorAaron Taylor <ataylor@subgeniuskitty.com>
Sun, 11 Jul 2021 01:52:51 +0000 (18:52 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Sun, 11 Jul 2021 01:52:51 +0000 (18:52 -0700)
hacks/NEDsim/NEDsim.c

index e4d66e2..67fcb32 100644 (file)
@@ -209,8 +209,9 @@ set_color(struct NEDsim * nedsim, struct color_rgb * color)
     XSetForeground(nedsim->dpy, nedsim->gc, temp.pixel);
 }
 
     XSetForeground(nedsim->dpy, nedsim->gc, temp.pixel);
 }
 
-// TODO: Make this a lot faster.
-// Set font size to fill 'size' cells vertically, minus space for border and padding.
+// Set font size to fill 'size' cells vertically, minus space for border and
+// padding.  There is probably a better way to do this. The current method is
+// horribly slow. Call this function as few times as possible.
 static void
 set_font_size(struct NEDsim * nedsim, int size)
 {
 static void
 set_font_size(struct NEDsim * nedsim, int size)
 {
@@ -220,9 +221,11 @@ set_font_size(struct NEDsim * nedsim, int size)
     const char * font_size_prefix = "-*-helvetica-*-r-*-*-";
     const char * font_size_suffix = "-*-*-*-*-*-*-*";
 
     const char * font_size_prefix = "-*-helvetica-*-r-*-*-";
     const char * font_size_suffix = "-*-*-*-*-*-*-*";
 
-    size_t buffer_size = strlen(font_size_prefix) + strlen(font_size_suffix) + 100; // '100' since nobody needs font with size in 'points' greater than 100 decimal digits long.
+    // In the buffer, we reserve 100 DIGITS for the font size integer.
+    size_t buffer_size = strlen(font_size_prefix) + strlen(font_size_suffix) + 100;
     char * font_full_name = malloc(buffer_size);
     char * font_full_name = malloc(buffer_size);
-    int font_size_in_points = 2; // Start with a 2 pt font and work our way up.
+    // Start with a 2pt font and work our way up.
+    int font_size_in_points = 2;
 
     while (1) {
         // Load the font.
 
     while (1) {
         // Load the font.