Index: tests/Zend/Pdf/DrawingTest.php =================================================================== --- tests/Zend/Pdf/DrawingTest.php (revision 19737) +++ tests/Zend/Pdf/DrawingTest.php (working copy) @@ -96,8 +96,14 @@ $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.8)) ->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)) ->setLineDashingPattern(array(3, 2, 3, 4), 1.6) - ->drawRectangle(60, 400, 400, 350); + ->drawRectangle(60, 400, 500, 350); + // Draw rounded rectangle + $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.9)) + ->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)) + ->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID) + ->drawRoundedRectangle(425, 350, 475, 400, 20); + // Draw circle $page2->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID) ->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0)) @@ -132,7 +138,7 @@ // Draw line $page2->setLineWidth(0.5) - ->drawLine(60, 375, 400, 375); + ->drawLine(60, 375, 500, 375); // ----------------------------------------------------------------------------------- $page3->translate(200, 10) @@ -152,8 +158,15 @@ $page3->setFillColor(new Zend_Pdf_Color_GrayScale(0.8)) ->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)) ->setLineDashingPattern(array(3, 2, 3, 4), 1.6) - ->drawRectangle(60, 400, 400, 350); + ->drawRectangle(60, 400, 500, 350); + // Draw rounded rectangle + $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.9)) + ->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)) + ->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID) + ->drawRoundedRectangle(425, 350, 475, 400, 20); + + // Draw circle $page3->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID) ->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0)) @@ -188,7 +201,7 @@ // Draw line $page3->setLineWidth(0.5) - ->drawLine(60, 375, 400, 375); + ->drawLine(60, 375, 500, 375); $pdf->save(dirname(__FILE__) . '/_files/output.pdf'); Index: tests/Zend/Pdf/ProcessingTest.php =================================================================== --- tests/Zend/Pdf/ProcessingTest.php (revision 19737) +++ tests/Zend/Pdf/ProcessingTest.php (working copy) @@ -71,8 +71,14 @@ $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.8)) ->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)) ->setLineDashingPattern(array(3, 2, 3, 4), 1.6) - ->drawRectangle(60, 400, 400, 350); + ->drawRectangle(60, 400, 500, 350); + // Draw rounded rectangle + $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.9)) + ->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)) + ->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID) + ->drawRoundedRectangle(425, 350, 475, 400, 20); + // Draw circle $page2->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID) ->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0)) @@ -107,7 +113,7 @@ // Draw line $page2->setLineWidth(0.5) - ->drawLine(60, 375, 400, 375); + ->drawLine(60, 375, 500, 375); $pdf->save(dirname(__FILE__) . '/_files/output.pdf'); unset($pdf); @@ -171,8 +177,14 @@ $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.8)) ->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)) ->setLineDashingPattern(array(3, 2, 3, 4), 1.6) - ->drawRectangle(60, 400, 400, 350); + ->drawRectangle(60, 400, 500, 350); + // Draw rounded rectangle + $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.9)) + ->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)) + ->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID) + ->drawRoundedRectangle(425, 350, 475, 400, 20); + // Draw circle $page2->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID) ->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0)) @@ -207,7 +219,7 @@ // Draw line $page2->setLineWidth(0.5) - ->drawLine(60, 375, 400, 375); + ->drawLine(60, 375, 500, 375); $pdf->save(dirname(__FILE__) . '/_files/output.pdf'); Index: library/Zend/Pdf/Page.php =================================================================== --- library/Zend/Pdf/Page.php (revision 19737) +++ library/Zend/Pdf/Page.php (working copy) @@ -1406,6 +1406,145 @@ } /** + * Draw a rounded rectangle. + * + * Fill types: + * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default) + * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle + * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle + * + * radius is an integer representing radius of the four corners, or an array + * of four integers representing the radius starting at top left, going + * clockwise + * + * @param float $x1 + * @param float $y1 + * @param float $x2 + * @param float $y2 + * @param integer|array $radius + * @param integer $fillType + * @return Zend_Pdf_Page + */ + public function drawRoundedRectangle($x1, $y1, $x2, $y2, $radius, + $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE) + { + + $this->_addProcSet('PDF'); + + if(!is_array($radius)) { + $radius = array($radius, $radius, $radius, $radius); + } else { + for ($i = 0; $i < 4; $i++) { + if(!isset($radius[$i])) { + $radius[$i] = 0; + } + } + } + + $topLeftX = $x1; + $topLeftY = $y2; + $topRightX = $x2; + $topRightY = $y2; + $bottomRightX = $x2; + $bottomRightY = $y1; + $bottomLeftX = $x1; + $bottomLeftY = $y1; + + //draw top side + $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX + $radius[0]); + $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY); + $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " m\n"; + $x1Obj = new Zend_Pdf_Element_Numeric($topRightX - $radius[1]); + $y1Obj = new Zend_Pdf_Element_Numeric($topRightY); + $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n"; + + //draw top right corner if needed + if ($radius[1] != 0) { + $x1Obj = new Zend_Pdf_Element_Numeric($topRightX); + $y1Obj = new Zend_Pdf_Element_Numeric($topRightY); + $x2Obj = new Zend_Pdf_Element_Numeric($topRightX); + $y2Obj = new Zend_Pdf_Element_Numeric($topRightY); + $x3Obj = new Zend_Pdf_Element_Numeric($topRightX); + $y3Obj = new Zend_Pdf_Element_Numeric($topRightY - $radius[1]); + $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' ' + . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' ' + . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' ' + . " c\n"; + } + + //draw right side + $x1Obj = new Zend_Pdf_Element_Numeric($bottomRightX); + $y1Obj = new Zend_Pdf_Element_Numeric($bottomRightY + $radius[2]); + $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n"; + + //draw bottom right corner if needed + if ($radius[2] != 0) { + $x1Obj = new Zend_Pdf_Element_Numeric($bottomRightX); + $y1Obj = new Zend_Pdf_Element_Numeric($bottomRightY); + $x2Obj = new Zend_Pdf_Element_Numeric($bottomRightX); + $y2Obj = new Zend_Pdf_Element_Numeric($bottomRightY); + $x3Obj = new Zend_Pdf_Element_Numeric($bottomRightX - $radius[2]); + $y3Obj = new Zend_Pdf_Element_Numeric($bottomRightY); + $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' ' + . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' ' + . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' ' + . " c\n"; + } + + //draw bottom side + $x1Obj = new Zend_Pdf_Element_Numeric($bottomLeftX + $radius[3]); + $y1Obj = new Zend_Pdf_Element_Numeric($bottomLeftY); + $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n"; + + //draw bottom left corner if needed + if ($radius[3] != 0) { + $x1Obj = new Zend_Pdf_Element_Numeric($bottomLeftX); + $y1Obj = new Zend_Pdf_Element_Numeric($bottomLeftY); + $x2Obj = new Zend_Pdf_Element_Numeric($bottomLeftX); + $y2Obj = new Zend_Pdf_Element_Numeric($bottomLeftY); + $x3Obj = new Zend_Pdf_Element_Numeric($bottomLeftX); + $y3Obj = new Zend_Pdf_Element_Numeric($bottomLeftY + $radius[3]); + $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' ' + . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' ' + . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' ' + . " c\n"; + } + + //draw left side + $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX); + $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY - $radius[0]); + $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n"; + + //draw top left corner if needed + if ($radius[0] != 0) { + $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX); + $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY); + $x2Obj = new Zend_Pdf_Element_Numeric($topLeftX); + $y2Obj = new Zend_Pdf_Element_Numeric($topLeftY); + $x3Obj = new Zend_Pdf_Element_Numeric($topLeftX + $radius[0]); + $y3Obj = new Zend_Pdf_Element_Numeric($topLeftY); + $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' ' + . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' ' + . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' ' + . " c\n"; + } + + switch ($fillType) { + case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE: + $this->_contents .= " B*\n"; + break; + case Zend_Pdf_Page::SHAPE_DRAW_FILL: + $this->_contents .= " f*\n"; + break; + case Zend_Pdf_Page::SHAPE_DRAW_STROKE: + $this->_contents .= " S\n"; + break; + } + + return $this; + } + + /** * Draw a line of text at the specified position. * * @param string $text Index: documentation/manual/en/module_specs/Zend_Pdf-Drawing.xml =================================================================== --- documentation/manual/en/module_specs/Zend_Pdf-Drawing.xml (revision 19737) +++ documentation/manual/en/module_specs/Zend_Pdf-Drawing.xml (working copy) @@ -91,6 +91,30 @@ ]]> +