I did something similar, where I implemented a tiny language that specified the
order in which to try and modify the formatting to get content to fit on a
specific page (the last page). I implemented font changes, text frame changes,
line space changes, and I forget what else. The language specified
combinations in discrete chunks, and the order in which to try them.
I never thought about making it generally applicable to any problem on any
page. I wonder if you could specify how such a thing would work? For example,
how would it know to look in aframes for text frames that exhibit some overrun?
And how do you specify the overrun? Often a callout is supposed to be
multi-line. Often the text frame is made larger than the callout text -- how do
you know you have a problem? If you can describe these issues in a way a
machine could understand, then it can be implemented. And I already have code
(somewhere) for one half of the problem.