History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ZF-313
Type: New Feature New Feature
Status: In Progress In Progress
Priority: Major Major
Assignee: Willie Alberty
Reporter: Tobias Plaputta
Votes: 4
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

TTFBox or TextWidth/Height function (word wrapping functionality)

Created: 09/Aug/06 11:08 AM   Updated: 27/Mar/08 02:04 PM
Component/s: Zend_Pdf
Affects Version/s: 0.1.4
Fix Version/s: None

Time Tracking:
Not Specified

Issue Links:
Related
 


 Description  « Hide
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?

 All   Comments   Work Log   Change History   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Willie Alberty - 09/Aug/06 06:32 PM
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:
/**
* Returns the total width in points of the string using the specified font and
* size.
*
* This is not the most efficient way to perform this calculation. I'm 
* concentrating optimization efforts on the upcoming layout manager class.
* Similar calculations exist inside the layout manager class, but widths are
* generally calculated only after determining line fragments.
*
* @param string $string
* @param Zend_Pdf_Resource_Font $font
* @param float $fontSize Font size in points
* @return float
*/
function widthForStringUsingFontSize($string, $font, $fontSize)
{
    $drawingString = iconv('', 'UTF-16BE', $string);
    $characters = array();
    for ($i = 0; $i < strlen($drawingString); $i++) {
        $characters[] = (ord($drawingString[$i++]) << 8) | ord($drawingString[$i]);
    }
    $glyphs = $font->cmap->glyphNumbersForCharacters($characters);
    $widths = $font->widthsForGlyphs($glyphs);
    $stringWidth = (array_sum($widths) / $font->getUnitsPerEm()) * $fontSize;
    return $stringWidth;
}

$font = Zend_Pdf_FontFactory::fontWithName(Zend_Pdf_Const::FONT_HELVETICA);
$stringWidth = widthForStringUsingFontSize('Hello world!', $font, 12);

Tobias Plaputta - 10/Aug/06 05:17 AM
@Wille Alberty: Amazing, this is 100% what I have needed! Thank you very much!

Bill Karwin - 13/Nov/06 03:09 PM
Changing fix version to unknown.

Bill Karwin - 13/Nov/06 03:26 PM
Changing fix version to 0.6.0.

Alexander Veremyev - 25/May/07 02:22 AM
Summary is changed to describe problem more clear.

Alexander Veremyev - 25/May/07 02:23 AM
Depends on other text formatting tasks (canvases, paragraphs and so on)

Alexander Veremyev - 25/May/07 06:34 AM
Assignee is changed to postpone issue to post-v1.0 period

Alexander Veremyev - 25/May/07 06:35 AM
Postponed to post-v1.0