PDF = new Zend_Pdf(); $this->PDF->pages[] = ($page1 = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4)); $this->CurPage = $page1; } function GetWidth() { return $this->CurPage->getWidth(); } function GetHeight() { return $this->CurPage->getHeight(); } function SetFont($font, $size) { $mapping = array( 'helvetica' => Zend_Pdf_Font::FONT_HELVETICA, ); $use_font = Zend_Pdf_Font::FONT_TIMES; foreach ($mapping as $pattern => $zend_font) { if (preg_match('/^'.$pattern.'$/i', $font)) { $use_font = $zend_font; break; } } $this->CurFont = Zend_Pdf_Font::fontWithName($use_font); $this->CurFontSize = $size; return $this->CurPage->setFont($this->CurFont, $size); } function SetFontSize($size) { $this->SetFont($this->CurFont, $size); } function SetFillColor($color) { return $this->CurPage->setFillColor( new Zend_Pdf_Color_HTML($color) ); } function SetLineColor($color) { return $this->CurPage->setLineColor( new Zend_Pdf_Color_HTML($color) ); } function SetLineWidth($width) { return $this->CurPage->setLineWidth($width); } function DrawLine($x1, $y1, $x2, $y2) { return $this->CurPage->drawLine($x1, $y1, $x2, $y2); } function DrawRectangle($x1, $y1, $x2, $y2, $mode) { return $this->CurPage->drawRectangle($x1, $y1, $x2, $y2, $mode); } function DrawText($x, $y, $text) { return $this->CurPage->drawText($x, $y, $text); } function GetPDFString() { return $this->PDF->render(); } function GetAscent() { return ($this->CurFont->getAscent() / $this->CurFont->getUnitsPerEm()) * $this->CurFontSize; } function GetDescent() { return ($this->CurFont->getDescent() / $this->CurFont->getUnitsPerEm()) * $this->CurFontSize; } function GetLineGap() { return ($this->CurFont->getLineGap() / $this->CurFont->getUnitsPerEm()) * $this->CurFontSize; } function GetStringWidth($string) { $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 = $this->CurFont->cmap->glyphNumbersForCharacters($characters); $widths = $this->CurFont->widthsForGlyphs($glyphs); return (array_sum($widths) / $this->CurFont->getUnitsPerEm()) * $this->CurFontSize; } }