ZF-313: TTFBox or TextWidth/Height function (word wrapping functionality)
Description
Problem: When using the drawText function to write a string that is longer than the page, there is no WordWrap. Is there a way to print text wrapped or to find out the width and height of the string that is about to be printed?
Comments
Posted by Willie Alberty (willie) on 2006-08-09T18:32:48.000+0000
I am working on some advanced layout classes that will take care of wrapping long lines for you. This code won't be ready for several more weeks. In the meantime, you may be able to use this function:
Posted by Tobias Plaputta (toby) on 2006-08-10T05:17:09.000+0000
@Wille Alberty: Amazing, this is 100% what I have needed! Thank you very much!
Posted by Bill Karwin (bkarwin) on 2006-11-13T15:09:46.000+0000
Changing fix version to unknown.
Posted by Bill Karwin (bkarwin) on 2006-11-13T15:26:52.000+0000
Changing fix version to 0.6.0.
Posted by Alexander Veremyev (alexander) on 2007-05-25T02:22:25.000+0000
Summary is changed to describe problem more clear.
Posted by Alexander Veremyev (alexander) on 2007-05-25T02:23:59.000+0000
Depends on other text formatting tasks (canvases, paragraphs and so on)
Posted by Alexander Veremyev (alexander) on 2007-05-25T06:34:28.000+0000
Assignee is changed to postpone issue to post-v1.0 period
Posted by Alexander Veremyev (alexander) on 2007-05-25T06:35:04.000+0000
Postponed to post-v1.0
Posted by Alexandre Lemaire (saeven) on 2008-09-12T14:32:38.000+0000
This only partially alleviates the metrics required for word wrapping though. This may be neat, but the instance where it doesn't help, is where you have a long string, need to word-wrap it, but need to know at which width a line should be cut without cutting words.
PHP inherently offers us the wordwrap function, which allows us to cut a string into an array where lines don't exceed a certain width, taking word composition into consideration. It's useless in this case though, since a 'max width' is very variable when font glyphs are of variable sizes.
Is there a function in Zend_PDF somewhat akin to the above, which allows us to determine a cut-strategy given: - a font - a font size - a page width (or width-coordinate restriction) - a (possibly multi-line) string of text?
Thanks. Alex
Posted by Remi ++ (remi) on 2008-11-05T22:58:10.000+0000
There is a new Zend_Font Component Proposal available for this: http://framework.zend.com/wiki/display/…
I would love to see a little bit progress with Zend_Pdf.
Posted by Willie Alberty (willie) on 2008-12-04T22:34:53.000+0000
Unassigning Zend_Pdf issues currently assigned to me pending decision on ZF 2.0 release timeframe and potential contribution of comprehensive changeset.
Posted by Wil Sinclair (wil) on 2008-12-19T13:33:40.000+0000
Alex, could you please look at this issue and mark it 'postponed' if we won't be addressing it before 1.8. Note that it has several votes.
Posted by James Gordon (cryptopia) on 2010-02-15T21:46:35.000+0000
A few minor comments that might save people some time:
{{$glyphs = $font->cmap->glyphNumbersForCharacters($characters);}}
...needs to be changed to this in order to work with later versions of ZF (eg. 1.10.1):
{{$glyphs = $font->glyphNumbersForCharacters($characters);}}
{{$font = Zend_Pdf_FontFactory::fontWithName(Zend_Pdf_Const::FONT_HELVETICA);}}
...needs to be changed to this in order to work with later versions of ZF (eg. 1.10.1):
{{$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);}}
Otherwise excellent function (I see it made its way into {{Zend_Barcode_Renderer_Pdf}}). Many thanks!
James.