2008年11月5日星期三

Re: [fw-formats] Zend_Pdf : How to calculate size of text ?

I'm not sure what the problem could be ....
I've also used that function, after reading this:
http://framework.zend.com/issues/browse/ZF-313

And created this class with it:
http://devshed.excudo.net/scripts/php/source/excudo+pdf+textblock

Right aligning the text for example - which gives you problems - worked
perfectly for me. So, maybe have a look at my class and see if that works
for you. If it does you can work from there to see what the problem in your
code is.

SŽébastien Cramatte wrote:
>
> Hello,
>
> I need to use Zend_Pdf to make an invoice.
> How I can calulate width of a "text" with a specific font and size ?
>
> I've tried the method behind
> (http://devzone.zend.com/article/2525-Zend_Pdf-tutorial)
> I've extend Zend_Pdf class and append the method ...
>
> I've tried to call the method as this :
>
> $this->widthForStringUsingFontSize($cell, Zend_Pdf_Font::FONT_HELVETICA,
> 8);
>
>
> It works but seems that returns incorrect value because when I draw a
> vertical line
> to this same position, text and line are aligned !
>
>
> public function widthForStringUsingFontSize($string, $font, $fontSize)
> {
> $drawingString = iconv('UTF-8', 'UTF-16BE//IGNORE', $string);
> $characters = array();
> for ($i = 0; $i < strlen($drawingString); $i++) {
> $characters[] = (ord($drawingString[$i++]) << 8) |
> ord($drawingString[$i]);
> }
> $glyphs = $font->glyphNumbersForCharacters($characters);
> $widths = $font->widthsForGlyphs($glyphs);
> $stringWidth = (array_sum($widths) / $font->getUnitsPerEm()) *
> $fontSize;
> return $stringWidth;
>
> }
>
>
> I've got the same problem when I try to
> right align data. As returned with is incorrect I'm not be abble to align
> my cells !
>
> Any ideas ?
>
> Regards
>
>
>


-----
http://devshed.excudo.net http://devshed.excudo.net
--
View this message in context: http://www.nabble.com/Zend_Pdf-%3A-How-to-calculate-size-of-text---tp20322766p20337581.html
Sent from the Zend MFS mailing list archive at Nabble.com.

没有评论: