gd_adapter.cls.php

来自「国外很不错的一个开源OA系统Group-Office」· PHP 代码 · 共 729 行 · 第 1/2 页

PHP
729
字号
    $h *= $this->_aa_factor;    $c = $this->_allocate_color($color);    imagefilledrectangle($this->_img, $x1, $y1, $x1 + $w, $y1 + $h, $c);  }  /**   * Draws a polygon   *   * The polygon is formed by joining all the points stored in the $points   * array.  $points has the following structure:   * <code>   * array(0 => x1,   *       1 => y1,   *       2 => x2,   *       3 => y2,   *       ...   *       );   * </code>   *   * See {@link Style::munge_color()} for the format of the color array.   * See {@link Cpdf::setLineStyle()} for a description of the $style   * parameter (aka dash)      *   * @param array $points   * @param array $color   * @param float $width   * @param array $style   * @param bool  $fill  Fills the polygon if true   */  function polygon($points, $color, $width = null, $style = null, $fill = false) {    // Scale each point by the AA factor    foreach (array_keys($points) as $i)      $points[$i] *= $this->_aa_factor;    $c = $this->_allocate_color($color);    // Convert the style array if required    if ( !is_null($style) && !$fill ) {      $gd_style = array();      foreach ($style as $length) {        for ($i = 0; $i < $length; $i++) {          $gd_style[] = $c;        }      }      imagesetstyle($this->_img, $gd_style);      $c = IMG_COLOR_STYLED;    }    imagesetthickness($this->_img, $width);    if ( $fill )       imagefilledpolygon($this->_img, $points, count($points) / 2, $c);    else      imagepolygon($this->_img, $points, count($points) / 2, $c);          }  /**   * Draws a circle at $x,$y with radius $r   *   * See {@link Style::munge_color()} for the format of the color array.   * See {@link Cpdf::setLineStyle()} for a description of the $style   * parameter (aka dash)   *   * @param float $x   * @param float $y   * @param float $r   * @param array $color   * @param float $width   * @param array $style   * @param bool $fill Fills the circle if true      */     function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false) {    // Scale by the AA factor    $x *= $this->_aa_factor;    $y *= $this->_aa_factor;    $r *= $this->_aa_factor;    $c = $this->_allocate_color($color);    // Convert the style array if required    if ( !is_null($style) && !$fill ) {      $gd_style = array();      foreach ($style as $length) {        for ($i = 0; $i < $length; $i++) {          $gd_style[] = $c;        }      }      imagesetstyle($this->_img, $gd_style);      $c = IMG_COLOR_STYLED;    }    imagesetthickness($this->_img, $width);    if ( $fill )      imagefilledellipse($this->_img, $x, $y, $r, $r, $c);    else      imageellipse($this->_img, $x, $y, $r, $r, $c);          }  /**   * Add an image to the pdf.   *   * The image is placed at the specified x and y coordinates with the   * given width and height.   *   * @param string $img_url the path to the image   * @param string $img_type the type (e.g. extension) of the image   * @param float $x x position   * @param float $y y position   * @param int $w width (in pixels)   * @param int $h height (in pixels)   */  function image($img_url, $img_type, $x, $y, $w, $h) {    switch ($img_type) {    case "png":      $src = @imagecreatefrompng($img_url);      break;          case "gif":      $src = @imagecreatefromgif($img_url);      break;          case "jpg":    case "jpeg":      $src = @imagecreatefromjpeg($img_url);      break;    default:      break;          }    if ( !$src )      return; // Probably should add to $_dompdf_errors or whatever here        // Scale by the AA factor    $x *= $this->_aa_factor;    $y *= $this->_aa_factor;    $w *= $this->_aa_factor;    $h *= $this->_aa_factor;        $img_w = imagesx($src);    $img_h = imagesy($src);        imagecopyresampled($this->_img, $src, $x, $y, 0, 0, $w, $h, $img_w, $img_h);      }  /**   * Writes text at the specified x and y coordinates   *   * See {@link Style::munge_color()} for the format of the color array.   *   * @param float $x   * @param float $y   * @param string $text the text to write   * @param string $font the font file to use   * @param float $size the font size, in points   * @param array $color   * @param float $adjust word spacing adjustment   */  function text($x, $y, $text, $font, $size, $color = array(0,0,0), $adjust = 0) {    // Scale by the AA factor    $x *= $this->_aa_factor;    $y *= $this->_aa_factor;    $size *= $this->_aa_factor;        $h = $this->get_font_height($font, $size);        $c = $this->_allocate_color($color);    if ( strpos($font, '.ttf') === false )      $font .= ".ttf";    // FIXME: word spacing    imagettftext($this->_img, $size, 0, $x, $y + $h, $c, $font, $text);      }  /**   * Add a named destination (similar to <a name="foo">...</a> in html)   *   * @param string $anchorname The name of the named destination   */  function add_named_dest($anchorname) {    // Not implemented  }  /**   * Add a link to the pdf   *   * @param string $url The url to link to   * @param float  $x   The x position of the link   * @param float  $y   The y position of the link   * @param float  $width   The width of the link   * @param float  $height   The height of the link   */  function add_link($url, $x, $y, $width, $height) {    // Not implemented  }  /**   * Calculates text size, in points   *   * @param string $text the text to be sized   * @param string $font the desired font   * @param float  $size the desired font size   * @param float  $spacing word spacing, if any   * @return float   */  function get_text_width($text, $font, $size, $spacing = 0) {        if ( strpos($font, '.ttf') === false )      $font .= ".ttf";    // FIXME: word spacing    list($x1,,$x2) = imagettfbbox($size, 0, $font, $text);    return $x2 - $x1;  }  /**   * Calculates font height, in points   *   * @param string $font   * @param float $size   * @return float   */  function get_font_height($font, $size) {    if ( strpos($font, '.ttf') === false )      $font .= ".ttf";    // FIXME: word spacing    list(,$y2,,,,$y1) = imagettfbbox($size, 0, $font, "MXjpqytfhl");  // Test string with ascenders, descenders and caps    return $y2 - $y1;  }    /**   * Starts a new page   *   * Subsequent drawing operations will appear on the new page.   */  function new_page() {    // FIXME  }      /**   * Streams the image directly to the browser   *   * @param string $filename the name of the image file (ignored)   * @param array  $options associative array, 'type' => jpeg|jpg|png, 'quality' => 0 - 100 (jpeg only)   */  function stream($filename, $options = null) {    // Perform any antialiasing    if ( $this->_aa_factor != 1 ) {      $dst_w = $this->_width / $this->_aa_factor;      $dst_h = $this->_height / $this->_aa_factor;      $dst = imagecreatetruecolor($dst_w, $dst_h);      imagecopyresampled($dst, $this->_img, 0, 0, 0, 0,                         $dst_w, $dst_h,                         $this->_width, $this->_height);    } else {      $dst = $this->_img;    }    if ( !isset($options["type"]) )      $options["type"] = "png";    $type = strtolower($options["type"]);        header("Cache-Control: private");        switch ($type) {    case "jpg":    case "jpeg":      if ( !isset($options["quality"]) )        $options["quality"] = 75;            header("Content-type: image/jpeg");      imagejpeg($dst, '', $options["quality"]);      break;    case "png":    default:      header("Content-type: image/png");      imagepng($dst);      break;    }    if ( $this->_aa_factor != 1 )       imagedestroy($dst);  }  /**   * Returns the PNG as a string   *   * @param array  $options associative array, 'type' => jpeg|jpg|png, 'quality' => 0 - 100 (jpeg only)   * @return string   */  function output($options = null) {    if ( $this->_aa_factor != 1 ) {      $dst_w = $this->_width / $this->_aa_factor;      $dst_h = $this->_height / $this->_aa_factor;      $dst = imagecreatetruecolor($dst_w, $dst_h);      imagecopyresampled($dst, $this->_img, 0, 0, 0, 0,                         $dst_w, $dst_h,                         $this->_width, $this->_height);    } else {      $dst = $this->_img;    }        if ( !isset($options["type"]) )      $options["type"] = "png";    $type = $options["type"];        ob_start();    switch ($type) {    case "jpg":    case "jpeg":      if ( !isset($options["quality"]) )        $options["quality"] = 75;            imagejpeg($dst, '', $options["quality"]);      break;    case "png":    default:      imagepng($dst);      break;    }    $image = ob_get_contents();    ob_end_clean();    if ( $this->_aa_factor != 1 )      imagedestroy($dst);        return $image;  }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?