shithub: puzzles

Download patch

ref: fcf1d274c3f512e6f70cba71832e0ecc97b656d3
parent: 42cc7f6cb0bfb99255e94c86e3c155bc1c9fd0e1
author: Ben Harris <bjh21@bjh21.me.uk>
date: Mon Apr 24 18:12:30 EDT 2023

Pattern: switch to small font when there are many row clues

If you have a particularly large number of clues in a row, they can
end up falling off the left edge of the window.  This used not to be a
problem because the rendering code would squash them closer together
if necessary.  But then I switched to drawing them all as a single
string (so that two-digit row clues would get enough space with a
large font) and that broke the old mechanism.

Now we detect if there are enough clues that our conservative guess at
the string length looks like overflowing in the big font, and switch
to the small one if necessary.  If we had a drawing call to measure a
string then we could be cleverer about this, but we don't.

This problem can be demonstrated with "7x1:1//1//1//1/1.1.1.1" in the
GTK port with the fonts my laptop has.

I think overflow can still occur even with a small font, so once I've
demonstrated that I'll try to fix it.

--- a/pattern.c
+++ b/pattern.c
@@ -1025,6 +1025,16 @@
         for (j = 0; j < state->common->rowlen[i]; j++)
             if (state->common->rowdata[state->common->rowsize * i + j] >= 10)
                 state->common->fontsize = FS_SMALL;
+    /*
+     * We might also need to use the small font if there are lots of
+     * row clues.  We assume that all clues are one digit and that a
+     * single-digit clue takes up 1.5 tiles, of which the clue is 0.5
+     * tiles and the space is 1.0 tiles.
+     */
+    for (i = params->w; i < params->w + params->h; i++)
+        if ((state->common->rowlen[i] * 3 - 2) >
+            TLBORDER(state->common->w) * 2)
+            state->common->fontsize = FS_SMALL;
 
     if (desc[-1] == ',') {
         /*