DrawingTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Shared;
  3. use PhpOffice\PhpSpreadsheet\Shared\Drawing;
  4. use PhpOffice\PhpSpreadsheet\Style\Font;
  5. use PHPUnit\Framework\TestCase;
  6. class DrawingTest extends TestCase
  7. {
  8. /**
  9. * @dataProvider providerPixelsToCellDimension
  10. */
  11. public function testPixelsToCellDimension(
  12. float $expectedResult,
  13. int $pixelSize,
  14. string $fontName,
  15. int $fontSize
  16. ): void {
  17. $font = new Font();
  18. $font->setName($fontName);
  19. $font->setSize($fontSize);
  20. $result = Drawing::pixelsToCellDimension($pixelSize, $font);
  21. self::assertSame($expectedResult, $result);
  22. }
  23. /**
  24. * @dataProvider providerCellDimensionToPixels
  25. */
  26. public function testCellDimensionToPixels(
  27. int $expectedResult,
  28. int $cellSize,
  29. string $fontName,
  30. int $fontSize
  31. ): void {
  32. $font = new Font();
  33. $font->setName($fontName);
  34. $font->setSize($fontSize);
  35. $result = Drawing::cellDimensionToPixels($cellSize, $font);
  36. self::assertSame($expectedResult, $result);
  37. }
  38. public function providerPixelsToCellDimension(): array
  39. {
  40. return [
  41. [19.9951171875, 100, 'Arial', 7],
  42. [14.2822265625, 100, 'Arial', 9],
  43. [14.2822265625, 100, 'Arial', 11],
  44. [13.092041015625, 100, 'Arial', 12], // approximation by extrapolating from Calibri 11
  45. [19.9951171875, 100, 'Calibri', 7],
  46. [16.664341517857142, 100, 'Calibri', 9],
  47. [14.2822265625, 100, 'Calibri', 11],
  48. [13.092041015625, 100, 'Calibri', 12], // approximation by extrapolating from Calibri 11
  49. [19.9951171875, 100, 'Verdana', 7],
  50. [12.5, 100, 'Verdana', 9],
  51. [13.092041015625, 100, 'Verdana', 12], // approximation by extrapolating from Calibri 11
  52. [17.4560546875, 100, 'Wingdings', 9], // approximation by extrapolating from Calibri 11
  53. ];
  54. }
  55. public function providerCellDimensionToPixels(): array
  56. {
  57. return [
  58. [500, 100, 'Arial', 7],
  59. [700, 100, 'Arial', 9],
  60. [700, 100, 'Arial', 11],
  61. [764, 100, 'Arial', 12], // approximation by extrapolating from Calibri 11
  62. [500, 100, 'Calibri', 7],
  63. [600, 100, 'Calibri', 9],
  64. [700, 100, 'Calibri', 11],
  65. [764, 100, 'Calibri', 12], // approximation by extrapolating from Calibri 11
  66. [500, 100, 'Verdana', 7],
  67. [800, 100, 'Verdana', 9],
  68. [764, 100, 'Verdana', 12], // approximation by extrapolating from Calibri 11
  69. [573, 100, 'Wingdings', 9], // approximation by extrapolating from Calibri 11
  70. ];
  71. }
  72. }