123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- class PHPExcel_Shared_Drawing
- {
-
- public static function pixelsToEMU($pValue = 0)
- {
- return round($pValue * 9525);
- }
-
- public static function EMUToPixels($pValue = 0)
- {
- if ($pValue != 0) {
- return round($pValue / 9525);
- } else {
- return 0;
- }
- }
-
- public static function pixelsToCellDimension($pValue = 0, PHPExcel_Style_Font $pDefaultFont)
- {
-
- $name = $pDefaultFont->getName();
- $size = $pDefaultFont->getSize();
- if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
-
- $colWidth = $pValue * PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'] / PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'];
- } else {
-
-
- $colWidth = $pValue * 11 * PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
- }
- return $colWidth;
- }
-
- public static function cellDimensionToPixels($pValue = 0, PHPExcel_Style_Font $pDefaultFont)
- {
-
- $name = $pDefaultFont->getName();
- $size = $pDefaultFont->getSize();
- if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
-
- $colWidth = $pValue * PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'] / PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'];
- } else {
-
-
- $colWidth = $pValue * $size * PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / 11;
- }
-
- $colWidth = (int) round($colWidth);
- return $colWidth;
- }
-
- public static function pixelsToPoints($pValue = 0)
- {
- return $pValue * 0.67777777;
- }
-
- public static function pointsToPixels($pValue = 0)
- {
- if ($pValue != 0) {
- return (int) ceil($pValue * 1.333333333);
- } else {
- return 0;
- }
- }
-
- public static function degreesToAngle($pValue = 0)
- {
- return (int)round($pValue * 60000);
- }
-
- public static function angleToDegrees($pValue = 0)
- {
- if ($pValue != 0) {
- return round($pValue / 60000);
- } else {
- return 0;
- }
- }
-
- public static function imagecreatefrombmp($p_sFile)
- {
-
- $file = fopen($p_sFile, "rb");
- $read = fread($file, 10);
- while (!feof($file) && ($read<>"")) {
- $read .= fread($file, 1024);
- }
- $temp = unpack("H*", $read);
- $hex = $temp[1];
- $header = substr($hex, 0, 108);
-
-
- if (substr($header, 0, 4)=="424d") {
-
- $header_parts = str_split($header, 2);
-
- $width = hexdec($header_parts[19].$header_parts[18]);
-
- $height = hexdec($header_parts[23].$header_parts[22]);
-
- unset($header_parts);
- }
-
- $x = 0;
- $y = 1;
-
- $image = imagecreatetruecolor($width, $height);
-
- $body = substr($hex, 108);
-
-
-
- $body_size = (strlen($body)/2);
- $header_size = ($width*$height);
-
- $usePadding = ($body_size>($header_size*3)+4);
-
-
- for ($i = 0; $i < $body_size; $i += 3) {
-
- if ($x >= $width) {
-
-
- if ($usePadding) {
- $i += $width%4;
- }
-
- $x = 0;
-
- $y++;
-
- if ($y > $height) {
- break;
- }
- }
-
-
- $i_pos = $i * 2;
- $r = hexdec($body[$i_pos+4].$body[$i_pos+5]);
- $g = hexdec($body[$i_pos+2].$body[$i_pos+3]);
- $b = hexdec($body[$i_pos].$body[$i_pos+1]);
-
- $color = imagecolorallocate($image, $r, $g, $b);
- imagesetpixel($image, $x, $height-$y, $color);
-
- $x++;
- }
-
- unset($body);
-
- return $image;
- }
- }
|