ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Shared\Drawing Class Reference
+ Inheritance diagram for PhpOffice\PhpSpreadsheet\Shared\Drawing:
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Shared\Drawing:

Static Public Member Functions

static pixelsToEMU ($pValue)
 Convert pixels to EMU. More...
 
static EMUToPixels ($pValue)
 Convert EMU to pixels. More...
 
static pixelsToCellDimension ($pValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont)
 Convert pixels to column width. More...
 
static cellDimensionToPixels ($pValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont)
 Convert column width from (intrinsic) Excel units to pixels. More...
 
static pixelsToPoints ($pValue)
 Convert pixels to points. More...
 
static pointsToPixels ($pValue)
 Convert points to pixels. More...
 
static degreesToAngle ($pValue)
 Convert degrees to angle. More...
 
static angleToDegrees ($pValue)
 Convert angle to degrees. More...
 
static imagecreatefrombmp ($p_sFile)
 Create a new image from file. More...
 

Detailed Description

Definition at line 7 of file Drawing.php.

Member Function Documentation

◆ angleToDegrees()

static PhpOffice\PhpSpreadsheet\Shared\Drawing::angleToDegrees (   $pValue)
static

Convert angle to degrees.

Parameters
int$pValueAngle
Returns
int Degrees

Definition at line 141 of file Drawing.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Xlsx\getFromZipArchive().

142  {
143  if ($pValue != 0) {
144  return (int) round($pValue / 60000);
145  }
146 
147  return 0;
148  }
+ Here is the caller graph for this function:

◆ cellDimensionToPixels()

static PhpOffice\PhpSpreadsheet\Shared\Drawing::cellDimensionToPixels (   $pValue,
\PhpOffice\PhpSpreadsheet\Style\Font  $pDefaultFont 
)
static

Convert column width from (intrinsic) Excel units to pixels.

Parameters
float$pValueValue in cell dimension
\PhpOffice\PhpSpreadsheet\Style\Font$pDefaultFontDefault font of the workbook
Returns
int Value in pixels

Definition at line 73 of file Drawing.php.

References PhpOffice\PhpSpreadsheet\Shared\Font\$defaultColumnWidths, $name, and $size.

Referenced by PhpOffice\PhpSpreadsheet\Shared\Xls\sizeCol().

74  {
75  // Font name and size
76  $name = $pDefaultFont->getName();
77  $size = $pDefaultFont->getSize();
78 
79  if (isset(Font::$defaultColumnWidths[$name][$size])) {
80  // Exact width can be determined
81  $colWidth = $pValue * Font::$defaultColumnWidths[$name][$size]['px'] / Font::$defaultColumnWidths[$name][$size]['width'];
82  } else {
83  // We don't have data for this particular font and size, use approximation by
84  // extrapolating from Calibri 11
85  $colWidth = $pValue * $size * Font::$defaultColumnWidths['Calibri'][11]['px'] / Font::$defaultColumnWidths['Calibri'][11]['width'] / 11;
86  }
87 
88  // Round pixels to closest integer
89  $colWidth = (int) round($colWidth);
90 
91  return $colWidth;
92  }
$size
Definition: RandomTest.php:84
+ Here is the caller graph for this function:

◆ degreesToAngle()

static PhpOffice\PhpSpreadsheet\Shared\Drawing::degreesToAngle (   $pValue)
static

Convert degrees to angle.

Parameters
int$pValueDegrees
Returns
int Angle

Definition at line 129 of file Drawing.php.

130  {
131  return (int) round($pValue * 60000);
132  }

◆ EMUToPixels()

static PhpOffice\PhpSpreadsheet\Shared\Drawing::EMUToPixels (   $pValue)
static

Convert EMU to pixels.

Parameters
int$pValueValue in EMU
Returns
int Value in pixels

Definition at line 28 of file Drawing.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Xlsx\getFromZipArchive().

29  {
30  if ($pValue != 0) {
31  return (int) round($pValue / 9525);
32  }
33 
34  return 0;
35  }
+ Here is the caller graph for this function:

◆ imagecreatefrombmp()

static PhpOffice\PhpSpreadsheet\Shared\Drawing::imagecreatefrombmp (   $p_sFile)
static

Create a new image from file.

By alexander at alexauto dot nl.

See also
http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214
Parameters
string$p_sFilePath to Windows DIB (BMP) image
Returns
GdImage|resource

Definition at line 159 of file Drawing.php.

References $header, $i, $r, $x, and $y.

160  {
161  // Load the image into a string
162  $file = fopen($p_sFile, 'rb');
163  $read = fread($file, 10);
164  while (!feof($file) && ($read != '')) {
165  $read .= fread($file, 1024);
166  }
167 
168  $temp = unpack('H*', $read);
169  $hex = $temp[1];
170  $header = substr($hex, 0, 108);
171 
172  // Process the header
173  // Structure: http://www.fastgraph.com/help/bmp_header_format.html
174  $width = 0;
175  $height = 0;
176  if (substr($header, 0, 4) == '424d') {
177  // Cut it in parts of 2 bytes
178  $header_parts = str_split($header, 2);
179 
180  // Get the width 4 bytes
181  $width = hexdec($header_parts[19] . $header_parts[18]);
182 
183  // Get the height 4 bytes
184  $height = hexdec($header_parts[23] . $header_parts[22]);
185 
186  // Unset the header params
187  unset($header_parts);
188  }
189 
190  // Define starting X and Y
191  $x = 0;
192  $y = 1;
193 
194  // Create newimage
195  $image = imagecreatetruecolor($width, $height);
196 
197  // Grab the body from the image
198  $body = substr($hex, 108);
199 
200  // Calculate if padding at the end-line is needed
201  // Divided by two to keep overview.
202  // 1 byte = 2 HEX-chars
203  $body_size = (strlen($body) / 2);
204  $header_size = ($width * $height);
205 
206  // Use end-line padding? Only when needed
207  $usePadding = ($body_size > ($header_size * 3) + 4);
208 
209  // Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption
210  // Calculate the next DWORD-position in the body
211  for ($i = 0; $i < $body_size; $i += 3) {
212  // Calculate line-ending and padding
213  if ($x >= $width) {
214  // If padding needed, ignore image-padding
215  // Shift i to the ending of the current 32-bit-block
216  if ($usePadding) {
217  $i += $width % 4;
218  }
219 
220  // Reset horizontal position
221  $x = 0;
222 
223  // Raise the height-position (bottom-up)
224  ++$y;
225 
226  // Reached the image-height? Break the for-loop
227  if ($y > $height) {
228  break;
229  }
230  }
231 
232  // Calculation of the RGB-pixel (defined as BGR in image-data)
233  // Define $i_pos as absolute position in the body
234  $i_pos = $i * 2;
235  $r = hexdec($body[$i_pos + 4] . $body[$i_pos + 5]);
236  $g = hexdec($body[$i_pos + 2] . $body[$i_pos + 3]);
237  $b = hexdec($body[$i_pos] . $body[$i_pos + 1]);
238 
239  // Calculate and draw the pixel
240  $color = imagecolorallocate($image, $r, $g, $b);
241  imagesetpixel($image, $x, $height - $y, $color);
242 
243  // Raise the horizontal position
244  ++$x;
245  }
246 
247  // Unset the body / free the memory
248  unset($body);
249 
250  // Return image-object
251  return $image;
252  }
$r
Definition: example_031.php:79
$y
Definition: example_007.php:83
$i
Definition: disco.tpl.php:19
$x
Definition: complexTest.php:9

◆ pixelsToCellDimension()

static PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToCellDimension (   $pValue,
\PhpOffice\PhpSpreadsheet\Style\Font  $pDefaultFont 
)
static

Convert pixels to column width.

Exact algorithm not known. By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875 This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional.

Parameters
int$pValueValue in pixels
\PhpOffice\PhpSpreadsheet\Style\Font$pDefaultFontDefault font of the workbook
Returns
int Value in cell dimension

Definition at line 47 of file Drawing.php.

References PhpOffice\PhpSpreadsheet\Shared\Font\$defaultColumnWidths, $name, and $size.

Referenced by PhpOffice\PhpSpreadsheet\Shared\Font\calculateColumnWidth().

48  {
49  // Font name and size
50  $name = $pDefaultFont->getName();
51  $size = $pDefaultFont->getSize();
52 
53  if (isset(Font::$defaultColumnWidths[$name][$size])) {
54  // Exact width can be determined
55  $colWidth = $pValue * Font::$defaultColumnWidths[$name][$size]['width'] / Font::$defaultColumnWidths[$name][$size]['px'];
56  } else {
57  // We don't have data for this particular font and size, use approximation by
58  // extrapolating from Calibri 11
59  $colWidth = $pValue * 11 * Font::$defaultColumnWidths['Calibri'][11]['width'] / Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
60  }
61 
62  return $colWidth;
63  }
$size
Definition: RandomTest.php:84
+ Here is the caller graph for this function:

◆ pixelsToEMU()

static PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU (   $pValue)
static

Convert pixels to EMU.

Parameters
int$pValueValue in pixels
Returns
int Value in EMU

Definition at line 16 of file Drawing.php.

17  {
18  return $pValue * 9525;
19  }

◆ pixelsToPoints()

static PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToPoints (   $pValue)
static

Convert pixels to points.

Parameters
int$pValueValue in pixels
Returns
float Value in points

Definition at line 101 of file Drawing.php.

102  {
103  return $pValue * 0.75;
104  }

◆ pointsToPixels()

static PhpOffice\PhpSpreadsheet\Shared\Drawing::pointsToPixels (   $pValue)
static

Convert points to pixels.

Parameters
int$pValueValue in points
Returns
int Value in pixels

Definition at line 113 of file Drawing.php.

Referenced by PhpOffice\PhpSpreadsheet\Shared\Xls\sizeRow().

114  {
115  if ($pValue != 0) {
116  return (int) ceil($pValue / 0.75);
117  }
118 
119  return 0;
120  }
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: