diff --git a/phpgwapi/doc/README.fonts b/phpgwapi/doc/README.fonts new file mode 100644 index 0000000000..f2534b9aa0 --- /dev/null +++ b/phpgwapi/doc/README.fonts @@ -0,0 +1,4 @@ +The directory phpgwapi/fonts contains fonts which are licensed under the GNU General Public License +and products of the project Free UCS Outline Fonts [http://savannah.gnu.org/projects/freefont]. + +FreeSans.ttf diff --git a/phpgwapi/fonts/FreeSans.ttf b/phpgwapi/fonts/FreeSans.ttf new file mode 100644 index 0000000000..f8e5d4be3a Binary files /dev/null and b/phpgwapi/fonts/FreeSans.ttf differ diff --git a/phpgwapi/inc/class.gdbutton.inc.php b/phpgwapi/inc/class.gdbutton.inc.php new file mode 100644 index 0000000000..1a1596d294 --- /dev/null +++ b/phpgwapi/inc/class.gdbutton.inc.php @@ -0,0 +1,210 @@ +image = 0; + $this->font_size = 0; + $this->font_text = ''; + $this->ttf_font = PHPGW_SERVER_ROOT . SEP . 'phpgwapi' . SEP . 'fonts' . SEP . 'FreeSans.ttf'; + $this->filename = ''; + + $this->xspace = 4; + $this->yspace = 2; + + $this->docroot = $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT']; + $this->img_dir = PHPGW_IMAGES_DIR . SEP; + } + + function button_init() + { + $this->image = ImageCreate($this->width,$this->height) or die; + ImageColorAllocate($this->image,0x2c,0x6D,0xAF); + return True; + } + + function file_name() + { + $this->filename = 'phpgw_button_' . md5($this->font_text) . '.png'; + $this->filename = strtolower($this->filename); + + return True; + } + + function gd_button() + { + if (file_exists(PHPGW_IMAGES_DIR . SEP . $this->filename)) + { + return $this->filename; + } + + $this->font_size = 5; + + $text_width = ImageFontWidth($this->font_size) * strlen($this->font_text); + $text_height = ImageFontHeight($this->font_size); + + $this->width = intval($this->xspace + $text_width); + $this->height = intval($this->yspace + $text_height); + + $this->xpos = ($this->width/2) - ($text_width/2); + + if ($this->xpos < 0) + { + $this->xpos = $this->xspace; + } + + $this->ypos = ($this->height/2) - ($text_height/2); + + if ($this->ypos < 0) + { + $this->ypos = $this->yspace; + } + + $this->button_init(); + + $black = ImageColorAllocate($this->image, 0,0,0); + ImageRectangle($this->image,0,0,$this->width-1,$this->height-1,$black); + + $white = ImageColorAllocate($this->image, 255,255,255); + ImageRectangle($this->image,0,0,$this->width,$this->height,$white); + + ImageString($this->image, $this->font_size, intval($this->xpos+1), intval($this->ypos), $this->font_text, $black); + ImageString($this->image, $this->font_size, intval($this->xpos), intval($this->ypos-1), $this->font_text, $white); + + return $this->save_button(); + } + + function ttf_button() + { + if (file_exists(PHPGW_IMAGES_DIR . SEP . $this->filename)) + { + return $this->filename; + } + $this->font_size = 11; + + $size = imagettfbbox($this->font_size,0,$this->ttf_font,$this->font_text); + $dx = abs($size[2]-$size[0]); + $dy = abs($size[5]-$size[3]); + + $xpad = 10; + $ypad = 10; + + $this->width = $dx + $xpad; + $this->height = $dy + $xpad; + + $this->button_init(); + + $black = ImageColorAllocate($this->image, 0,0,0); + ImageRectangle($this->image,0,0,$this->width-1,$this->height-1,$black); + + $white = ImageColorAllocate($this->image, 255,255,255); + ImageRectangle($this->image,0,0,$this->width,$this->height,$white); + + ImageTTFText($this->image, $this->font_size, 0, intval($xpad/2)+1, $dy+intval($ypad/2), -$black, $this->ttf_font, $this->font_text); + ImageTTFText($this->image, $this->font_size, 0, intval($xpad/2), $dy+intval($ypad/2)-1, -$white, $this->ttf_font, $this->font_text); + + return $this->save_button(); + } + + function save_button() + { + ImagePNG($this->image,$this->docroot . $this->img_dir . SEP . $this->filename); + ImageDestroy($this->image); + + return $this->filename; + } + + function input_button($data) + { + if (is_array($data)) + { + $this->font_text = $data['font_text']; + $button_name = $data['button_name']; + } + + $this->file_name(); + + if (extension_loaded('gd') && extension_loaded('ttf')) + { + if (dl('gd.so')) + { + return ''; + } + } + elseif(extension_loaded('gd') && !extension_loaded('ttf')) + { + return ''; + } + else + { + return ''; + } + } + + // this function checks, if there is a variable $aaa_x and $aaa_y + // if so, it will create a new variable $aaa + function parseHTTPPostVars() + { + // execute only if libgd support is enabled + if (!extension_loaded('gd')) + { + return; + } + + if (is_array($GLOBALS['HTTP_POST_VARS'])) + { + while( list($key, $val) = each($GLOBALS['HTTP_POST_VARS'])) + { + if (ereg("(.*)_x",$key,$varName) && $HTTP_POST_VARS[$varName[1]."_y"]) + { + $name = $varName[1]; + global $$name; + $$name = "content generated by parseHTTPPostVars()"; + } + } + } + } + } diff --git a/phpgwapi/inc/class.graphics.inc.php b/phpgwapi/inc/class.graphics.inc.php deleted file mode 100644 index 26dbef6ee0..0000000000 --- a/phpgwapi/inc/class.graphics.inc.php +++ /dev/null @@ -1,97 +0,0 @@ - * - * Allows the creation of graphical buttons * - * Copyright (C) 2001 Lars Kneschke * - * -------------------------------------------------------------------------* - * This library is part of the phpGroupWare API * - * http://www.phpgroupware.org/api * - * ------------------------------------------------------------------------ * - * This library is free software; you can redistribute it and/or modify it * - * under the terms of the GNU Lesser General Public License as published by * - * the Free Software Foundation; either version 2.1 of the License, * - * or any later version. * - * This library is distributed in the hope that it will be useful, but * - * WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License * - * along with this library; if not, write to the Free Software Foundation, * - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - \**************************************************************************/ - - /* $Id$ */ - - class graphics - { - /* put a valid font here */ - var $font="/opt/future-project/src/management-server/ttf/arial.ttf"; - - function createImage($_text, $_fontsize=11) - { - /* create filename */ - $filename = 'button_' . md5($_text) . '.png'; - $filename = strtolower($filename); - - /* see if file exists already, we cache it */ - if (file_exists(PHPGW_IMAGES_FILEDIR.'/'.$filename)) - { - return $filename; - } - - $size = imagettfbbox($_fontsize,0,$this->font,$_text); - $dx = abs($size[2]-$size[0]); - $dy = abs($size[5]-$size[3]); - $xpad=9; - $ypad=9; - $im = imagecreate($dx+$xpad,$dy+$ypad); - $blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF); - $black = ImageColorAllocate($im, 0,0,0); - $white = ImageColorAllocate($im, 255,255,255); - ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black); - ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white); - ImageTTFText($im, $_fontsize, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), -$black, $this->font, $_text); - ImageTTFText($im, $_fontsize, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, -$white, $this->font, $_text); - ImagePNG($im,PHPGW_IMAGES_FILEDIR.'/'.$filename); - ImageDestroy($im); - - return $filename; - } - - function createInputButton($_text, $_name, $_mode='graphic') - { - if ($_mode == 'graphic' && extension_loaded('gd')) - { - return ''; - } - else - { - return ''; - } - } - - // this function checks, if there is a variable $aaa_x and $aaa_y - // if so, it will create a new variable $aaa - function parseHTTPPostVars() - { - // execute only if libgd support is enabled - if (!extension_loaded('gd')) - { - return; - } - - if (is_array($GLOBALS['HTTP_POST_VARS'])) - { - while( list($key, $val) = each($GLOBALS['HTTP_POST_VARS'])) - { - if (ereg("(.*)_x",$key,$varName) && $HTTP_POST_VARS[$varName[1]."_y"]) - { - $name = $varName[1]; - global $$name; - $$name = "content generated by parseHTTPPostVars()"; - } - } - } - } - }