automatically calculate actual font sizes for arbitrary fonts at startup
Currently we're using some hard-coded pixel font sizes in the GUI tailored to fitting DejaVu Sans Mono exactly into the maxwidth/sizes listed in sys_fontlist of s_main.c. By ignoring the fi_width and fi_height members on the C side, we guarantee pixel-exact object/message/atom box sizing across all platforms.
This means that boxes aren't guaranteed to tightly fit around the text. For example, on Ubuntu 16.04 the font engine changed and happened to make DejaVu Sans Mono wider than previously. When we made a special hard-coded fix, it turned out that there is no pixel size that corresponds exactly to the previous size-- the new font engine quantizes the pixel sizes in a way that is incompatible with the previous font stack. So a message/object box with a long string of text in it under Ubuntu 16.04 will have some space left between the right edge of the text and the right side of the object box.
This may seem like a bug, but it's actually a feature. It prevents users under Ubuntu 16.04 from positioning boxes so tightly horizontally (or vertically) that they create collisions for users on the other systems.
To be able to support this for arbitrary fonts, we need to expand the HTML5 canvas font measuring trick in pdgui.js. Essentially, I think we need to do the following:
- start with a suitably small actual font size guaranteed to fit the sys_fontlist spec.
- write it to the HTML5 canvas and check if it fits into the maxwidth/maxheight for that sys_fontlist size
- if it fits, double the actual font size and goto step 2
- if it is too large, then make a "vice grip" with the current actual font size and the last known actual font size that fits
- find the mid-point of the "vice grip" and goto 3
Now, figure out a reasonable number of times to loop 3-5. At the end of it, find the last known actual font size that fits and use that for the corresponding Pd font dialog size.
Then do the same thing for each other Pd font dialog size.