Skip to content

Save zoom level in patch file, so that it can be restored when the patch gets reloaded. Fixes #145.

Albert Gräf requested to merge aggraef/purr-data:save-zoom-in-patch into master

I think that this improves usability a lot. I use the zoom feature very frequently, for me it's one of Purr Data's killer features. Fiddling around with font sizes is only a poor substitute for that. But then I really want to have the zoom level stored in the patch, along with the font size and geometry of the canvas window. If I provide sample patches to my students I'd like to be sure that they are displayed the way I saved them, at the right zoom level.

The implementation employs a little hack, but it's a fairly safe one, and doesn't break compatibility with vanilla, Pd-l2ork or any other Pd flavor. Pd's binbuf parser happily reads a float when it expects an int and will cast it to an int automatically, no questions asked. It's reasonable to assert that this was done on purpose, but in any case it has been there forever (the relevant code dates back to 2007 at least, that's how far the Pd git history goes). So I simply store the zoom level as a fraction in the font size argument of a toplevel canvas' #N header. This is only done for zoom levels != 0. In any case, other Pd versions will read the patch without any problems, at the correct font size.

This should be safe unless vanilla suddenly starts supporting fractional font sizes at some point. I don't expect this to happen anytime soon, given Pd's track record of enforcing backward compatibility in its public interface, let alone the patch format.

Now there might be 3rd party tools which parse Pd patches and may be thrown off if the font size of a toplevel canvas is a not an int. (Do you know any? I don't.) However, I think that the ability to save zoom levels will be more important for most users than keeping compatibility with some obscure tool which can't read a patch that Pd itself is perfectly happy with.

As usual I've tested this on Linux and Mac, the code is portable and should work on Windows, too.

Merge request reports