Exemplo n.º 1
0
 public function __construct(Document $doc, $canvas = null)
 {
     if (self::DEBUG) {
         echo __FUNCTION__ . "\n";
     }
     $dimensions = $doc->getDimensions();
     $w = $dimensions["width"];
     $h = $dimensions["height"];
     if (!$canvas) {
         $canvas = new \PDFlib();
         /* all strings are expected as utf8 */
         $canvas->set_option("stringformat=utf8");
         $canvas->set_option("errorpolicy=return");
         /*  open new PDF file; insert a file name to create the PDF on disk */
         if ($canvas->begin_document("", "") == 0) {
             die("Error: " . $canvas->get_errmsg());
         }
         $canvas->set_info("Creator", "PDFlib starter sample");
         $canvas->set_info("Title", "starter_graphics");
         $canvas->begin_page_ext($w, $h, "");
     }
     // Flip PDF coordinate system so that the origin is in
     // the top left rather than the bottom left
     $canvas->setmatrix(1, 0, 0, -1, 0, $h);
     $this->width = $w;
     $this->height = $h;
     $this->canvas = $canvas;
 }
Exemplo n.º 2
0
 public function __construct(Document $doc, $canvas = null)
 {
     if (self::DEBUG) {
         echo __FUNCTION__ . "\n";
     }
     $dimensions = $doc->getDimensions();
     $w = $dimensions["width"];
     $h = $dimensions["height"];
     if (!$canvas) {
         $canvas = new CPdf(array(0, 0, $w, $h));
     }
     // Flip PDF coordinate system so that the origin is in
     // the top left rather than the bottom left
     $canvas->transform(array(1, 0, 0, -1, 0, $h));
     $this->width = $w;
     $this->height = $h;
     $this->canvas = $canvas;
 }
Exemplo n.º 3
0
 protected function applyTransform($attribs)
 {
     if (isset($attribs["transform"])) {
         $surface = $this->document->getSurface();
         $transform = $attribs["transform"];
         $match = array();
         preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)\\((.*?)\\)/is', $transform, $match, PREG_SET_ORDER);
         $transformations = array();
         if (count($match[0])) {
             foreach ($match as $_match) {
                 $arguments = preg_split('/[ ,]+/', $_match[2]);
                 array_unshift($arguments, $_match[1]);
                 $transformations[] = $arguments;
             }
         }
         foreach ($transformations as $t) {
             switch ($t[0]) {
                 case "matrix":
                     $surface->transform($t[1], $t[2], $t[3], $t[4], $t[5], $t[6]);
                     break;
                 case "translate":
                     $surface->translate($t[1], isset($t[2]) ? $t[2] : 0);
                     break;
                 case "scale":
                     $surface->scale($t[1], isset($t[2]) ? $t[2] : $t[1]);
                     break;
                 case "rotate":
                     $surface->rotate($t[1]);
                     break;
                 case "skewX":
                     $surface->skewX($t[1]);
                     break;
                 case "skewY":
                     $surface->skewY($t[1]);
                     break;
             }
         }
     }
 }