Scale an image with unscalable parts

Posted by Uko on Programmers See other posts from Programmers or by Uko
Published on 2012-12-06T15:32:55Z Indexed on 2012/12/06 17:20 UTC
Read the original article Hit count: 166

Filed under:
|

Brief description of problem: imagine having some vector picture(s) and text annotations on the sides outside of the picture(s).

enter image description here

Now the task is to scale the whole composition while preserving the aspect ratio in order to fit some view-port. The tricky part is that the text is not scalable only the picture(s). The distance between text and the image is still relative to the whole image, but the text size is always a constant.

Example: let's assume that our total composition is two times larger than a view-port. Then we can just scale it by 1/2. But because the text parts are a fixed font size, they will become larger than we expect and won't fit in the view-port.

One option I can think of is an iterative process where we repeatedly scale our composition until the delta between it and the view-port satisfies some precision. But this algorithm is quite costly as it involves working with the graphics and the image may be composed of a lot of components which will lead to a lot of matrix computations. What's more, this solution seems to be hard to debug, extend, etc.

Are there any other approaches to solving this scaling problem?

© Programmers or respective owner

Related posts about algorithms

Related posts about graphics