I've figured out the lines that set top and width, and now see that they're needed because of the 90 degree rotation. I'm used to rotating about the origin, but you're rotating about the center here (the default, and I forget that).

But I'm not convinced that these lines do the right thing if the preview is bigger than the screen.  In that case, I imagine you need to use a transform to make the preview fit the screen?