yyn0210 / alivepdf

Automatically exported from code.google.com/p/alivepdf
0 stars 0 forks source link

addImageStream with rotation messes x , width and height values #267

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. pdf.addImageStream(myObject.byteArray, ColorSpace.DEVICE_RGB, null, 
the_x_pos, the_y_pos, the_width, the_height, myObject.rotation); 
2.
3.

What is the expected output? What do you see instead?

in the generated pdf file, if rotation = 0 (real one or hardcoded), sizes and 
positions are ok, but if the rotation is taken into account, some images appear 
(but not as expected), and some do not appear at all (maybe because outside of 
the page)

What version of the product are you using? On what operating system?

AlivePDF0.1.5 RC on windows 7

Please provide any additional information below.

I have a custom component which looks like an A4 page, and the user may add 
images on it (drag, scale, rotate...). Id did some test with images not rotated 
in order to correctly do my computations (scale on the page, positions on the 
page, etc) and it works. Then, with the reals rotations values, coords are not 
as expected (and some images' rotation are not correct!)

2 attached files:
-> The first one: screen shot of my app / generated pdf
-> The second one: generated pdf with no rotation (you can not compare, but it 
was ok with what was in my app!)

Original issue reported on code.google.com by delamare...@yahoo.fr on 6 Aug 2010 at 10:03

Attachments:

GoogleCodeExporter commented 8 years ago
Here is how I did to correct it in my app:

// for all children
for (var i:int = 0; i < num; i++) {
   cur   =   MyImage(paper.getElementAt(i));        
   // work with percentages as my custom component has nearly the same
   // dimensions as an A4 page
   px    =   cur.x / paperW;                // x
   py    =   cur.y / paperH;                // y
   pw    =   cur.width * cur.scaleX / paperW;   // width
   ph    =   cur.height * cur.scaleY / paperH;  // height

   // keep an eye on the rotation (rad)
   teta  =   cur.rotation * 0.01745329251994329576923690768489;     // Pi / 180;
   cos   =   Math.cos(teta);
   sin   =   Math.sin(teta);

   // rotate the page (degree)
   pdf.rotate(cur.rotation, 0, 0);

   // coords on the non-rotated page
   tmpX   =   px * pageW;
   tmpY   =   py * pageH;

   // in the rotated one
   finalX   = cos * tmpX + sin * tmpY;
   finalY   = -sin * tmpX + cos * tmpY;

   // add the object with no rotation
   pdf.addImageStream(cur.byteArray, ColorSpace.DEVICE_RGB, null, finalX, finalY, pw * pageW, ph * pageH, 0);

   // return to the normal page
   pdf.rotate(-cur.rotation, 0, 0);

}

I would have like to do it directly into the source code, but I have no time 
for that.

I hope it will help someone to correct it!

attached: an output. There are stills some imperfections, but i think that they 
are due to percentages and scales of my component (maybe not a perfect scaled 
A4 page)!

Original comment by delamare...@yahoo.fr on 10 Aug 2010 at 11:40

Attachments:

GoogleCodeExporter commented 8 years ago
I tried this and It works, tnx. Do you know how I could change the 
transformation point of the image so it rotates it from  middle? 

Original comment by radu.fl...@gmail.com on 19 Sep 2012 at 7:04

GoogleCodeExporter commented 8 years ago
Sorry, it has been a long time since I didn't use AS3...
However, I think that I computed my rotations myself, then did the 
transformations in order to have my values for the uppon left corner... but not 
really sure... (and I do not have access to this project anymore...)

Original comment by delamare...@yahoo.fr on 12 Oct 2012 at 3:25