Esempio n. 1
0
 /**
  * Try to set font
  *
  * Stays with the old font, if the newly specified font is not available.
  *
  * If the font does not support the given style, it falls back to the style
  * used beforehand, and if this is also not support the plain style will be
  * used.
  * 
  * @param string $name 
  * @param int $style 
  * @return void
  */
 public function trySetFont($name, $style)
 {
     // Just du no use new font, if it is unknown
     // @TODO: Add some kind of weak error reporting here?
     if (!isset($this->fonts[$name])) {
         $name = $this->currentFont['name'];
     }
     // Style fallback
     if (!isset($this->fonts[$name][$style])) {
         $style = isset($this->fonts[$name][$this->currentFont['style']]) ? $this->currentFont['style'] : self::FONT_PLAIN;
     }
     // Create and use font on current page
     $font = $this->document->getFont($this->fonts[$name][$style]);
     $this->currentPage->setFontAndSize($font, $this->currentFont['size']);
     $this->currentFont = array('name' => $name, 'style' => $style, 'size' => $this->currentFont['size'], 'font' => $font);
 }
Esempio n. 2
0
 /**
  * Try to set font
  *
  * Stays with the old font, if the newly specified font is not available.
  *
  * If the font does not support the given style, it falls back to the style
  * used beforehand, and if this is also not support the plain style will be
  * used.
  *
  * @param string $name
  * @param int $style
  * @return void
  */
 public function trySetFont($name, $style)
 {
     // Just du no use new font, if it is unknown
     if (!isset($this->fonts[$name])) {
         throw new ezcDocumentInvalidFontException($name);
     }
     // Style fallback
     if (!isset($this->fonts[$name][$style])) {
         $style = isset($this->fonts[$name][$this->currentFont['style']]) ? $this->currentFont['style'] : self::FONT_PLAIN;
     }
     // Create and use font on current page
     if ($this->currentPage) {
         $font = $this->document->getFont($this->fonts[$name][$style]);
         $this->currentPage->setFontAndSize($font, $this->currentFont['size']);
     } else {
         $font = $this->dummyDoc->getFont($this->fonts[$name][$style]);
         $this->dummyDoc->getCurrentPage()->setFontAndSize($font, $this->currentFont['size']);
     }
     $this->currentFont = array('name' => $name, 'style' => $style, 'size' => $this->currentFont['size'], 'font' => $font);
 }
Esempio n. 3
0
<?php

$doc = new HaruDoc();
$p = $doc->addPage();
/* set the color (dark blue) */
$p->setRGBFill(0.2, 0.2, 0.5);
/* draw a rectangle */
$p->rectangle(150, 400, 300, 200);
/* fill it */
$p->fill();
/* se the color (white) */
$p->setRGBFill(1, 1, 1);
/* enter text mode */
$p->beginText();
/* choose the font and its size */
$font = $doc->getFont("Helvetica");
$p->setFontAndSize($font, 35);
/* move text position */
$p->moveTextPos(200, 500);
/* print a well-known phrase */
$p->showText("Hello world!");
/* leave text mode */
$p->endText();
/* save the result */
$doc->save("/tmp/test.pdf");