Ejemplo n.º 1
0
 /**
  * Dump style to a string, which can be directly inserted into content stream
  *
  * @return string
  */
 public function instructions()
 {
     $instructions = '';
     if ($this->_fillColor !== null) {
         $instructions .= $this->_fillColor->instructions(false);
     }
     if ($this->_color !== null) {
         $instructions .= $this->_color->instructions(true);
     }
     if ($this->_lineWidth !== null) {
         $instructions .= $this->_lineWidth->toString() . " w\n";
     }
     if ($this->_lineDashingPattern !== null) {
         $dashPattern = new InternalType\ArrayObject();
         foreach ($this->_lineDashingPattern as $dashItem) {
             $dashElement = new InternalType\NumericObject($dashItem);
             $dashPattern->items[] = $dashElement;
         }
         $instructions .= $dashPattern->toString() . ' ' . $this->_lineDashingPhase->toString() . " d\n";
     }
     return $instructions;
 }
Ejemplo n.º 2
0
 /**
  * Instructions, which can be directly inserted into content stream
  * to switch color.
  * Color set instructions differ for stroking and nonstroking operations.
  *
  * @param boolean $stroking
  * @return string
  */
 public function instructions($stroking)
 {
     return $this->_c->toString() . ' ' . $this->_m->toString() . ' ' . $this->_y->toString() . ' ' . $this->_k->toString() . ($stroking ? " K\n" : " k\n");
 }
Ejemplo n.º 3
0
 /**
  * Instructions, which can be directly inserted into content stream
  * to switch color.
  * Color set instructions differ for stroking and nonstroking operations.
  *
  * @param boolean $stroking
  * @return string
  */
 public function instructions($stroking)
 {
     return $this->_grayLevel->toString() . ($stroking ? " G\n" : " g\n");
 }
Ejemplo n.º 4
0
 /**
  * @param ZendPage $page
  * @param string $text
  * @param float $x
  * @param float $y
  * @param int $renderMode
  *
  * @return ZendPage
  */
 private function drawRawText(ZendPage $page, $text, $x, $y, $renderMode = 0)
 {
     $textObj = new ZendStringObject($text);
     $xObj = new ZendNumericObject($x);
     $yObj = new ZendNumericObject($y);
     $rObj = new ZendNumericObject($renderMode);
     $content = "BT\n" . $xObj->toString() . ' ' . $yObj->toString() . " Td\n" . (0 === $renderMode ? '' : $rObj->toString() . " Tr\n") . $textObj->toString() . " Tj\n" . "ET\n";
     return $page->rawWrite($content, 'Text');
 }
Ejemplo n.º 5
0
 public function testToStringFloat3()
 {
     $intObj = new InternalType\NumericObject(-100.426);
     $this->assertEquals($intObj->toString(), '-100.426');
 }
Ejemplo n.º 6
0
 public function drawRoundedRectangle($x1, $y1, $x2, $y2, $radius, $fillType = self::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 InternalType\NumericObject($topLeftX + $radius[0]);
     $y1Obj = new InternalType\NumericObject($topLeftY);
     $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " m\n";
     $x1Obj = new InternalType\NumericObject($topRightX - $radius[1]);
     $y1Obj = new InternalType\NumericObject($topRightY);
     $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
     //draw top right corner if needed
     if ($radius[1] != 0) {
         $x1Obj = new InternalType\NumericObject($topRightX - $radius[1]);
         $y1Obj = new InternalType\NumericObject($topRightY);
         $x2Obj = new InternalType\NumericObject($topRightX);
         $y2Obj = new InternalType\NumericObject($topRightY);
         $x3Obj = new InternalType\NumericObject($topRightX);
         $y3Obj = new InternalType\NumericObject($topRightY - $radius[1]);
         $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' ' . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' ' . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' ' . " c\n";
     }
     //draw right side
     $x1Obj = new InternalType\NumericObject($bottomRightX);
     $y1Obj = new InternalType\NumericObject($bottomRightY + $radius[2]);
     $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
     //draw bottom right corner if needed
     if ($radius[2] != 0) {
         $x1Obj = new InternalType\NumericObject($bottomRightX);
         $y1Obj = new InternalType\NumericObject($bottomRightY);
         $x2Obj = new InternalType\NumericObject($bottomRightX - $radius[1]);
         $y2Obj = new InternalType\NumericObject($bottomRightY);
         $x3Obj = new InternalType\NumericObject($bottomRightX - $radius[2]);
         $y3Obj = new InternalType\NumericObject($bottomRightY);
         $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' ' . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' ' . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' ' . " c\n";
     }
     //draw bottom side
     $x1Obj = new InternalType\NumericObject($bottomLeftX + $radius[3]);
     $y1Obj = new InternalType\NumericObject($bottomLeftY);
     $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
     //draw bottom left corner if needed
     if ($radius[3] != 0) {
         $x1Obj = new InternalType\NumericObject($bottomLeftX + $radius[1]);
         $y1Obj = new InternalType\NumericObject($bottomLeftY);
         $x2Obj = new InternalType\NumericObject($bottomLeftX);
         $y2Obj = new InternalType\NumericObject($bottomLeftY);
         $x3Obj = new InternalType\NumericObject($bottomLeftX);
         $y3Obj = new InternalType\NumericObject($bottomLeftY + $radius[3]);
         $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' ' . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' ' . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' ' . " c\n";
     }
     //draw left side
     $x1Obj = new InternalType\NumericObject($topLeftX);
     $y1Obj = new InternalType\NumericObject($topLeftY - $radius[0]);
     $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
     //draw top left corner if needed
     if ($radius[0] != 0) {
         $x1Obj = new InternalType\NumericObject($topLeftX);
         $y1Obj = new InternalType\NumericObject($topLeftY);
         $x2Obj = new InternalType\NumericObject($topLeftX + $radius[1]);
         $y2Obj = new InternalType\NumericObject($topLeftY);
         $x3Obj = new InternalType\NumericObject($topLeftX + $radius[0]);
         $y3Obj = new InternalType\NumericObject($topLeftY);
         $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' ' . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' ' . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' ' . " c\n";
     }
     switch ($fillType) {
         case self::SHAPE_DRAW_FILL_AND_STROKE:
             $this->_contents .= " B*\n";
             break;
         case self::SHAPE_DRAW_FILL:
             $this->_contents .= " f*\n";
             break;
         case self::SHAPE_DRAW_STROKE:
             $this->_contents .= " S\n";
             break;
     }
     return $this;
 }
Ejemplo n.º 7
0
 private function getDataForTextDrawing($text, $x, $y, $encoding, $wordSpacing, $fillType)
 {
     $font = $this->getPage()->getFont();
     $xObj = new NumericObject($x);
     $yObj = new NumericObject($y);
     $wordSpacingObj = new NumericObject($wordSpacing);
     $data = "BT\n" . $xObj->toString() . ' ' . $yObj->toString() . " Td\n" . ($fillType != 0 ? $fillType . ' Tr' . "\n" : '');
     if ($this->isFontDefiningSpaceInSingleByte($font)) {
         $textObj = $this->createTextObject($font, $text, $encoding);
         $data .= ($wordSpacing != 0 ? $wordSpacingObj->toString() . ' Tw' . "\n" : '') . $textObj->toString() . " Tj\n";
     } else {
         $words = explode(' ', $text);
         $spaceObj = $this->createTextObject($font, ' ', $encoding);
         foreach ($words as $word) {
             $textObj = $this->createTextObject($font, $word, $encoding);
             $data .= '0 Tc' . "\n" . $textObj->toString() . " Tj\n" . $wordSpacingObj->toString() . " Tc\n" . $spaceObj->toString() . " Tj\n";
         }
     }
     $data .= "ET\n";
     return $data;
 }
Ejemplo n.º 8
0
 /**
  * Instructions, which can be directly inserted into content stream
  * to switch color.
  * Color set instructions differ for stroking and nonstroking operations.
  *
  * @param boolean $stroking
  * @return string
  */
 public function instructions($stroking)
 {
     return $this->_r->toString() . ' ' . $this->_g->toString() . ' ' . $this->_b->toString() . ($stroking ? " RG\n" : " rg\n");
 }
Ejemplo n.º 9
0
 /**
  * Translate coordination system.
  *
  * @param float $x  - the X co-ordinate of axis skew point
  * @param float $y  - the Y co-ordinate of axis skew point
  * @param float $xAngle - X axis skew angle
  * @param float $yAngle - Y axis skew angle
  * @return \ZendPdf\Page
  */
 public function skew($x, $y, $xAngle, $yAngle)
 {
     $tanXObj = new InternalType\NumericObject(tan($xAngle));
     $tanYObj = new InternalType\NumericObject(-tan($yAngle));
     $xObj = new InternalType\NumericObject($x);
     $yObj = new InternalType\NumericObject($y);
     $mXObj = new InternalType\NumericObject(-$x);
     $mYObj = new InternalType\NumericObject(-$y);
     $this->_addProcSet('PDF');
     $this->_contents .= '1 0 0 1 ' . $xObj->toString() . ' ' . $yObj->toString() . " cm\n" . '1 ' . $tanXObj->toString() . ' ' . $tanYObj->toString() . " 1 0 0 cm\n" . '1 0 0 1 ' . $mXObj->toString() . ' ' . $mYObj->toString() . " cm\n";
     return $this;
 }