quick6black / alivepdf

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

Allow support for rotated type #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
How can we support rotation of text within the PDF?

Could we possibly modify the addText method to accept a Matrix? This
modification will probably require a combination addCell and addText method
so that a user can add a text string that is rotated, without having to
create cells and additional elements on their own.

addCell does not currently support rotation, so I'm not sure right yet how
this would be possible.

Original issue reported on code.google.com by bustb...@gmail.com on 10 Oct 2007 at 1:10

GoogleCodeExporter commented 9 years ago
The Pear modification of the FPDF library includes a routine called 
writeRotated().
I'm not sure if it will support any angle, but from the looks of it, it should.

I'm working on converting this, but since I haven't done too much with the 
source
yet, I'm not exactly sure how it is going to work out. If anyone else would 
like to
give it a shot, here's the method:

    function writeRotated($x, $y, $text, $text_angle, $font_angle = 0)
    {
        if ($x < 0) {
            $x += $this->w;
        }
        if ($y < 0) {
            $y += $this->h;
        }

        /* Escape text. */
        $text = $this->_escape($text);

        $font_angle += 90 + $text_angle;
        $text_angle *= M_PI / 180;
        $font_angle *= M_PI / 180;

        $text_dx = cos($text_angle);
        $text_dy = sin($text_angle);
        $font_dx = cos($font_angle);
        $font_dy = sin($font_angle);

        $s= sprintf('BT %.2' . FILE_PDF_FLOAT . ' %.2' . FILE_PDF_FLOAT . ' %.2' .
FILE_PDF_FLOAT . ' %.2' . FILE_PDF_FLOAT . ' %.2' . FILE_PDF_FLOAT . ' %.2' .
FILE_PDF_FLOAT . ' Tm (%s) Tj ET',
                    $text_dx, $text_dy, $font_dx, $font_dy,
                    $x * $this->_scale, ($this->h-$y) * $this->_scale, $text);

        if ($this->_draw_color) {
            $s = 'q ' . $this->_draw_color . ' ' . $s . ' Q';
        }
        $this->_out($s);
    }

Original comment by bustb...@gmail.com on 10 Oct 2007 at 1:21

GoogleCodeExporter commented 9 years ago
Hi bustback,

I have added a rotate method which is accepting a matrix. I will call it
transparently for all the different drawing methodds (addImage, addCell, 
addText, etc).

Give me a few days and I'll post an update ;)

Thanks !

Original comment by thibault.imbert on 10 Oct 2007 at 11:25