Ejemplo n.º 1
0
 /**
  * Init the PDF Font
  *
  * @return void
  */
 public function fontSet()
 {
     $family = strtolower($this->value['font-family']);
     $b = $this->value['font-bold'] ? 'B' : '';
     $i = $this->value['font-italic'] ? 'I' : '';
     $u = $this->value['font-underline'] ? 'U' : '';
     $d = $this->value['font-linethrough'] ? 'D' : '';
     $o = $this->value['font-overline'] ? 'O' : '';
     // font style
     $style = $b . $i;
     if ($this->defaultFont) {
         if ($family == 'arial') {
             $family = 'helvetica';
         } elseif ($family == 'symbol' || $family == 'zapfdingbats') {
             $style = '';
         }
         $fontkey = $family . $style;
         if (!$this->pdf->isLoadedFont($fontkey)) {
             $family = $this->defaultFont;
         }
     }
     if ($family == 'arial') {
         $family = 'helvetica';
     } elseif ($family == 'symbol' || $family == 'zapfdingbats') {
         $style = '';
     }
     // complete style
     $style .= $u . $d . $o;
     // size : mm => pt
     $size = $this->value['font-size'];
     $size = 72 * $size / 25.4;
     // apply the font
     $this->pdf->SetFont($family, $style, $this->value['mini-size'] * $size);
     $this->pdf->setTextColorArray($this->value['color']);
     if ($this->value['background']['color']) {
         $this->pdf->setFillColorArray($this->value['background']['color']);
     } else {
         $this->pdf->setFillColor(255);
     }
 }
Ejemplo n.º 2
0
 /**
  * draw a line with a specific type, and specific start and end for radius
  *
  * @access protected
  * @param  array   $pt
  * @param  array   $color
  * @param  string  $type (dashed, dotted, double, solid)
  * @param  float   $width
  * @param  integer $radius (binary from 0 to 3 with 1=>start with a radius, 2=>end with a radius)
  */
 protected function _drawLine($pt, $color, $type, $width, $radius = 3)
 {
     // set the fill color
     $this->pdf->setFillColorArray($color);
     // if dashed or dotted
     if ($type == 'dashed' || $type == 'dotted') {
         // clean the end of the line, if radius
         if ($radius == 1) {
             $tmp = array();
             $tmp[] = $pt[0];
             $tmp[] = $pt[1];
             $tmp[] = $pt[2];
             $tmp[] = $pt[3];
             $tmp[] = $pt[8];
             $tmp[] = $pt[9];
             $this->pdf->Polygon($tmp, 'F');
             $tmp = array();
             $tmp[] = $pt[2];
             $tmp[] = $pt[3];
             $tmp[] = $pt[4];
             $tmp[] = $pt[5];
             $tmp[] = $pt[6];
             $tmp[] = $pt[7];
             $tmp[] = $pt[8];
             $tmp[] = $pt[9];
             $pt = $tmp;
         } elseif ($radius == 2) {
             $tmp = array();
             $tmp[] = $pt[2];
             $tmp[] = $pt[3];
             $tmp[] = $pt[4];
             $tmp[] = $pt[5];
             $tmp[] = $pt[6];
             $tmp[] = $pt[7];
             $this->pdf->Polygon($tmp, 'F');
             $tmp = array();
             $tmp[] = $pt[0];
             $tmp[] = $pt[1];
             $tmp[] = $pt[2];
             $tmp[] = $pt[3];
             $tmp[] = $pt[6];
             $tmp[] = $pt[7];
             $tmp[] = $pt[8];
             $tmp[] = $pt[9];
             $pt = $tmp;
         } elseif ($radius == 3) {
             $tmp = array();
             $tmp[] = $pt[0];
             $tmp[] = $pt[1];
             $tmp[] = $pt[2];
             $tmp[] = $pt[3];
             $tmp[] = $pt[10];
             $tmp[] = $pt[11];
             $this->pdf->Polygon($tmp, 'F');
             $tmp = array();
             $tmp[] = $pt[4];
             $tmp[] = $pt[5];
             $tmp[] = $pt[6];
             $tmp[] = $pt[7];
             $tmp[] = $pt[8];
             $tmp[] = $pt[9];
             $this->pdf->Polygon($tmp, 'F');
             $tmp = array();
             $tmp[] = $pt[2];
             $tmp[] = $pt[3];
             $tmp[] = $pt[4];
             $tmp[] = $pt[5];
             $tmp[] = $pt[8];
             $tmp[] = $pt[9];
             $tmp[] = $pt[10];
             $tmp[] = $pt[11];
             $pt = $tmp;
         }
         // horisontal or vertical line
         if ($pt[2] == $pt[0]) {
             $l = abs(($pt[3] - $pt[1]) * 0.5);
             $px = 0;
             $py = $width;
             $x1 = $pt[0];
             $y1 = ($pt[3] + $pt[1]) * 0.5;
             $x2 = $pt[6];
             $y2 = ($pt[7] + $pt[5]) * 0.5;
         } else {
             $l = abs(($pt[2] - $pt[0]) * 0.5);
             $px = $width;
             $py = 0;
             $x1 = ($pt[2] + $pt[0]) * 0.5;
             $y1 = $pt[1];
             $x2 = ($pt[6] + $pt[4]) * 0.5;
             $y2 = $pt[7];
         }
         // if dashed : 3x bigger than dotted
         if ($type == 'dashed') {
             $px = $px * 3.0;
             $py = $py * 3.0;
         }
         $mode = $l / ($px + $py) < 0.5;
         // display the dotted/dashed line
         for ($i = 0; $l - ($px + $py) * ($i - 0.5) > 0; $i++) {
             if ($i % 2 == $mode) {
                 $j = $i - 0.5;
                 $lx1 = $px * $j;
                 if ($lx1 < -$l) {
                     $lx1 = -$l;
                 }
                 $ly1 = $py * $j;
                 if ($ly1 < -$l) {
                     $ly1 = -$l;
                 }
                 $lx2 = $px * ($j + 1);
                 if ($lx2 > $l) {
                     $lx2 = $l;
                 }
                 $ly2 = $py * ($j + 1);
                 if ($ly2 > $l) {
                     $ly2 = $l;
                 }
                 $tmp = array();
                 $tmp[] = $x1 + $lx1;
                 $tmp[] = $y1 + $ly1;
                 $tmp[] = $x1 + $lx2;
                 $tmp[] = $y1 + $ly2;
                 $tmp[] = $x2 + $lx2;
                 $tmp[] = $y2 + $ly2;
                 $tmp[] = $x2 + $lx1;
                 $tmp[] = $y2 + $ly1;
                 $this->pdf->Polygon($tmp, 'F');
                 if ($j > 0) {
                     $tmp = array();
                     $tmp[] = $x1 - $lx1;
                     $tmp[] = $y1 - $ly1;
                     $tmp[] = $x1 - $lx2;
                     $tmp[] = $y1 - $ly2;
                     $tmp[] = $x2 - $lx2;
                     $tmp[] = $y2 - $ly2;
                     $tmp[] = $x2 - $lx1;
                     $tmp[] = $y2 - $ly1;
                     $this->pdf->Polygon($tmp, 'F');
                 }
             }
         }
     } elseif ($type == 'double') {
         // if double, 2 lines : 0=>1/3 and 2/3=>1
         $pt1 = $pt;
         $pt2 = $pt;
         if (count($pt) == 12) {
             // line 1
             $pt1[0] = ($pt[0] - $pt[10]) * 0.33 + $pt[10];
             $pt1[1] = ($pt[1] - $pt[11]) * 0.33 + $pt[11];
             $pt1[2] = ($pt[2] - $pt[10]) * 0.33 + $pt[10];
             $pt1[3] = ($pt[3] - $pt[11]) * 0.33 + $pt[11];
             $pt1[4] = ($pt[4] - $pt[8]) * 0.33 + $pt[8];
             $pt1[5] = ($pt[5] - $pt[9]) * 0.33 + $pt[9];
             $pt1[6] = ($pt[6] - $pt[8]) * 0.33 + $pt[8];
             $pt1[7] = ($pt[7] - $pt[9]) * 0.33 + $pt[9];
             $pt2[10] = ($pt[10] - $pt[0]) * 0.33 + $pt[0];
             $pt2[11] = ($pt[11] - $pt[1]) * 0.33 + $pt[1];
             // line 2
             $pt2[2] = ($pt[2] - $pt[0]) * 0.33 + $pt[0];
             $pt2[3] = ($pt[3] - $pt[1]) * 0.33 + $pt[1];
             $pt2[4] = ($pt[4] - $pt[6]) * 0.33 + $pt[6];
             $pt2[5] = ($pt[5] - $pt[7]) * 0.33 + $pt[7];
             $pt2[8] = ($pt[8] - $pt[6]) * 0.33 + $pt[6];
             $pt2[9] = ($pt[9] - $pt[7]) * 0.33 + $pt[7];
         } else {
             // line 1
             $pt1[0] = ($pt[0] - $pt[6]) * 0.33 + $pt[6];
             $pt1[1] = ($pt[1] - $pt[7]) * 0.33 + $pt[7];
             $pt1[2] = ($pt[2] - $pt[4]) * 0.33 + $pt[4];
             $pt1[3] = ($pt[3] - $pt[5]) * 0.33 + $pt[5];
             // line 2
             $pt2[6] = ($pt[6] - $pt[0]) * 0.33 + $pt[0];
             $pt2[7] = ($pt[7] - $pt[1]) * 0.33 + $pt[1];
             $pt2[4] = ($pt[4] - $pt[2]) * 0.33 + $pt[2];
             $pt2[5] = ($pt[5] - $pt[3]) * 0.33 + $pt[3];
         }
         $this->pdf->Polygon($pt1, 'F');
         $this->pdf->Polygon($pt2, 'F');
     } elseif ($type == 'solid') {
         // solid line : draw directly the polygon
         $this->pdf->Polygon($pt, 'F');
     }
 }