Hello everyone,

I'm posting this here in order to provide another solution to the terrible
misinformation available on Macromedia's site about how to convert a
landscape image to portrait for printing using the PrintJob class.

The code posted here at Macromedia's forums is VERY WRONG:
http://tinyurl.com/e4cuf

Real URL:
http://www.macromedia.com/cfusion/webforums/forum/messageview.cfm?catid=288&;
threadid=1089277&enterthread=y

It's so wrong, in fact, that it took me a fair bit of debugging to figure
out just how wrong it was.  Whoever wrote it obviously didn't test the code
they posted as a solution.  It's pseudocode and you don't post pseudocode as
real code unless you're an asshat, which evollove is.  If you're on this
list, evollove, do us all a favor and don't post anymore solutions anywhere
on the web.  ;)

Here is the correct, tested code for rotating a movieclip to print as
landscape in portrait using PrintJob, for anyone who is looking for the
solution.

function printImage(mc) {
        var realW = mc._width;
        var realH = mc._height;
        var origX = mc._x;
        //
        pj = new PrintJob();
        var pageCount = 0;
        if (pj.start()) {
                var orient = pj.orientation;
                if (orient.toLowerCase() != "landscape") {
                        mc._rotation = 90;
                        mc._x = mc._width;
                }
                var cWidth = mc._width;
                var cHeight = mc._height;
                var cXscale = (pj.pageWidth / cWidth) * 100;
                var cYscale = (pj.pageHeight / cHeight) * 100;
                mc._xscale = mc._yscale = Math.min(cXscale, cYscale);
                if (pj.addPage(mc, {xMin:0, xMax:realW, yMin:0,
yMax:realH})) {
                        pageCount++;
                }
        }
        if (pageCount > 0) {
                pj.send();
        }
        mc._xscale = mc._yscale = 100;
        mc._rotation = 0;
        mc._x = origX;
        delete pj;
}

// Explanation
Here are the places the original code was wrong and why, and how this proper
code works.  There are inconsistencies between the clip you're trying to
print and they way PrintJob handles that clip, due mostly to PrintJob being
a poorly written class, which doesn't surprise me.

When you rotate a movieclip 90 degrees, Flash swaps its _width and _height,
or rather, it returns the clip's current _width and _height, which when
rotated 90 degrees, are swapped.  If the clip was 1024x768 and you set its
_rotation = 90, its _width will now return 768 and its _height 1024.  This
is important because you're going to use the rotated width and height to
determine how much to scale the printClip down for PrintJob to print the
entire clip on the page.

When you're scaling an image you normally don't want to scale it out of
proportion, so you need to determine which scale difference is greater (the
lower of the 2 scales returned) and use that for both _xscale and _yscale
equally.  Evollove's script did not do this properly.

PrintJob is retarded in that you need to scale the target clip down for it
to print the entire clip image, but PrintJob still uses the clip's
non-scaled and non-rotated width and height as its xMax and yMax values, not
the _width and _height that Flash returns after rotation and scaling.
Evollove obviously didn't test his code because he passed the adjusted
values and didn't take the time to figure out that the PrintJob Class is
stupid.

This is important:  PrintJob requires you to rotate and scale the clip down
before you print it in order to fit the entire image on a page, but it still
wants you to pass the clip's original width and height (not adjusted for
rotation or scaling) for its print area.  Not only is this dumb and
inconsistent, it's not documented at all (nor are the properties like
orientation, pageWidth, pageHeight, etc.).  Par for the course.

Once you send the print job, reset the _xscale, _yscale, _rotation, and _x
of the clip(s) you were printing.

HTH!

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to