/**
  * Extend the outline by one pixel.
  *
  * @param  Pixel  $pixel  the next outline pixel
  *
  * @return self
  * 
  */
 public function push(Pixel $pixel)
 {
     $this->boundary->push($pixel);
     if (isset($this->outline[0]) && $this->outline[0]->position() == $pixel->position()) {
         $this->closed = true;
         return $this->clean();
     }
     $this->size++;
     $this->outline[] = $pixel;
     return $this;
 }
Example #2
0
 /**
  * Builds a raw email message by the given parameters
  *
  * @param string[] $to The array of recipients
  * @param string $subject The subject of the email
  * @param string $plain The Plain text version of the email
  * @param string $html The HTML version of the email
  * @param Attachment[] $attachments The array of attachments to send
  * @return string The built raw email
  * @throws RawEmailException
  */
 public function build(array $to, $subject, $plain, $html, array $attachments = array())
 {
     if (!self::isPresent($plain) && !self::isPresent($html)) {
         throw new RawEmailException("Either 'plain' or 'html' parameter must be passed");
     }
     $outerBoundary = new Boundary(Boundary::generate());
     $innerBoundary = new Boundary(Boundary::generate());
     $content = new ContentBuilder();
     $basic = new Item();
     $basic->addField(new Field(Field::RETURN_PATH, array($this->returnPath)));
     $basic->addField(new Field(Field::FROM, array($this->from)));
     $basic->addField(new Field(Field::TO, array(join(', ', $to))));
     $basic->addField(new Field(Field::SUBJECT, array($subject)));
     $basic->addField(new Field(Field::MIME_VERSION, array('1.0')));
     $basic->addField(new Field(Field::CONTENT_TYPE, array('multipart/mixed', "boundary={$outerBoundary->getBoundary()}")));
     $content->insertItem($basic);
     $content->insertBoundary($outerBoundary);
     $message = new Item();
     $message->addField(new Field(Field::CONTENT_TYPE, array('multipart/alternative', "boundary={$innerBoundary->getBoundary()}")));
     $content->insertItem($message);
     if (self::isPresent($plain)) {
         $content->insertBoundary($innerBoundary);
         $plainItem = new Item();
         $plainItem->addField(new Field(Field::CONTENT_TRANSFER_ENCODING, array('base64')));
         $plainItem->addField(new Field(Field::CONTENT_TYPE, array('text/plain', 'charset=UTF-8', 'format=flowed')));
         $plainItem->setValue(base64_encode($plain));
         $content->insertItem($plainItem);
     }
     if (self::isPresent($html)) {
         $content->insertBoundary($innerBoundary);
         $htmlItem = new Item();
         $htmlItem->addField(new Field(Field::CONTENT_TRANSFER_ENCODING, array('7bit')));
         $htmlItem->addField(new Field(Field::CONTENT_TYPE, array('text/html', 'charset=UTF-8')));
         $htmlItem->setValue($html);
         $content->insertItem($htmlItem);
     }
     $content->closeBoundary($innerBoundary);
     foreach ($attachments as $attachment) {
         $content->insertBoundary($outerBoundary);
         $item = new Item();
         $item->addField(new Field(Field::CONTENT_DISPOSITION, array('attachment', "filename=\"{$attachment->getName()}\"")));
         $item->addField(new Field(Field::CONTENT_TYPE, array($attachment->getContentType(), "name=\"{$attachment->getName()}\"")));
         $item->addField(new Field(Field::CONTENT_TRANSFER_ENCODING, array('base64')));
         $item->setValue($attachment->getBody());
         $content->insertItem($item);
     }
     $content->closeBoundary($outerBoundary);
     return $content->getOutput();
 }
Example #3
0
 protected function getValuesArea(Boundary $b)
 {
     $dy = $this->getD()->width;
     $dx = $this->getD()->height;
     $h = $this->axis['font_x']->getTextExtent($this->maxleg)->height;
     $dbottom = $b->bottom() - ($h < $dx * 4 ? $dx * 4 : $h);
     $dleft = $b->left() + $this->axis['font_y']->getTextExtent($this->max)->width + $dy * 2;
     $dtop = $b->top() + $this->depth;
     $dright = $b->right() + $this->depth;
     return new Boundary($dleft, $dtop, $dright, $dbottom);
 }
Example #4
0
 /**
  * Assembles the message body.  Returns a string if successful
  * or false if unsuccessful.
  * @private
  * @returns string
  */
 function create_body()
 {
     $body = array();
     // wordwrap the message body if set
     if ($this->WordWrap > 0) {
         $this->Body = $this->word_wrap($this->Body, $this->WordWrap);
     }
     switch ($this->message_type) {
         case "alt":
             // Return text of body
             $bndry = new Boundary($this->boundary[1]);
             $bndry->CharSet = $this->CharSet;
             $bndry->Encoding = $this->Encoding;
             $body[] = $bndry->GetSource();
             $body[] = sprintf("%s%s", $this->AltBody, $this->LE . $this->LE);
             $bndry = new Boundary($this->boundary[1]);
             $bndry->CharSet = $this->CharSet;
             $bndry->ContentType = "text/html";
             $bndry->Encoding = $this->Encoding;
             $body[] = $bndry->GetSource();
             $body[] = sprintf("%s%s", $this->Body, $this->LE . $this->LE);
             // End the boundary
             $body[] = sprintf("%s--%s--%s", $this->LE, $this->boundary[1], $this->LE . $this->LE);
             break;
         case "plain":
             $body[] = $this->Body;
             break;
         case "attachments":
             $bndry = new Boundary($this->boundary[1]);
             $bndry->CharSet = $this->CharSet;
             $bndry->ContentType = $this->ContentType;
             $bndry->Encoding = $this->Encoding;
             $body[] = sprintf("%s%s%s%s", $bndry->GetSource(false), $this->LE, $this->Body, $this->LE);
             if (!($body[] = $this->attach_all())) {
                 return false;
             }
             break;
         case "alt_attachments":
             $body[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
             $body[] = sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", "multipart/alternative", $this->LE, $this->boundary[2], $this->LE . $this->LE);
             // Create text body
             $bndry = new Boundary($this->boundary[2]);
             $bndry->CharSet = $this->CharSet;
             $bndry->ContentType = "text/plain";
             $bndry->Encoding = $this->Encoding;
             $body[] = $bndry->GetSource() . $this->LE;
             $body[] = sprintf("%s%s", $this->AltBody, $this->LE . $this->LE);
             // Create the HTML body
             $bndry = new Boundary($this->boundary[2]);
             $bndry->CharSet = $this->CharSet;
             $bndry->ContentType = "text/html";
             $bndry->Encoding = $this->Encoding;
             $body[] = $bndry->GetSource() . $this->LE;
             $body[] = sprintf("%s%s", $this->Body, $this->LE . $this->LE);
             $body[] = sprintf("%s--%s--%s", $this->LE, $this->boundary[2], $this->LE . $this->LE);
             if (!($body[] = $this->attach_all())) {
                 return false;
             }
             break;
     }
     // Add the encode string code here
     $sBody = join("", $body);
     $sBody = $this->encode_string($sBody, $this->Encoding);
     return $sBody;
 }
 /**
  * @param Boundary $boundary
  */
 public function closeBoundary(Boundary $boundary)
 {
     $this->output .= $boundary->getFormattedClose();
 }
Example #6
0
 /**
  * Обрезает изображение
  * @param Boundary $s Границы области обрезки
  * @throws GDException 
  * @return GDImage
  */
 function crop(Boundary $s)
 {
     if (($r = @imagecreatetruecolor($s->width(), $s->height())) === FALSE) {
         throw new GDException('Невозможно инициализировать GD поток');
     }
     @imagealphablending($r, false);
     if (!@imagecopy($r, $this->handle, 0, 0, $s->left(), $s->top(), $s->width(), $s->height())) {
         @imagedestroy($r);
         throw new GDException("Не удалось растянуть изображение.");
     }
     @imagealphablending($r, true);
     @imagedestroy($this->handle);
     $this->handle = $r;
     return $this;
 }
Example #7
0
 public function bounds(Boundary $value = NULL)
 {
     if ($value !== NULL) {
         $this->bound = Boundary::copy($value);
     }
     return $this->bound;
 }
Example #8
0
 function drawTitle($image, Boundary $b)
 {
     $s = $this->title['font']->getTextExtent($this->title['text']);
     //var_dump(imagettfbbox($this->title['font']->size,$this->title['font']->angle,$this->title['font']->family,$this->title['text']));
     //throw new exception ($s->height);
     if ($s->height > $b->height() || $s->width > $b->width()) {
         throw new ChartException("Недостаточно места для вывода заголовка.");
     }
     $b->bottom($b->top() + $s->height);
     $title = new Label($b, $this->title['text'], $this->title['font'], $this->title['color'], Label::ALIGN_CENTER_TOP);
     $title->draw($image);
 }