FontTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * This file is part of PHPOffice Common
  4. *
  5. * PHPOffice Common is free software distributed under the terms of the GNU Lesser
  6. * General Public License version 3 as published by the Free Software Foundation.
  7. *
  8. * For the full copyright and license information, please read the LICENSE
  9. * file that was distributed with this source code. For the full list of
  10. * contributors, visit https://github.com/PHPOffice/Common/contributors.
  11. *
  12. * @link https://github.com/PHPOffice/Common
  13. * @copyright 2009-2016 PHPOffice Common contributors
  14. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  15. */
  16. namespace PhpOffice\Common\Tests;
  17. use PhpOffice\Common\Font;
  18. /**
  19. * Test class for Font
  20. *
  21. * @coversDefaultClass PhpOffice\Common\Font
  22. */
  23. class FontTest extends \PHPUnit\Framework\TestCase
  24. {
  25. /**
  26. */
  27. public function testMath()
  28. {
  29. $value = rand(1, 100);
  30. $this->assertEquals(16, Font::fontSizeToPixels());
  31. $this->assertEquals((16 / 12) * $value, Font::fontSizeToPixels($value));
  32. $this->assertEquals(96, Font::inchSizeToPixels());
  33. $this->assertEquals(96 * $value, Font::inchSizeToPixels($value));
  34. $this->assertEquals(37.795275591, Font::centimeterSizeToPixels());
  35. $this->assertEquals(37.795275591 * $value, Font::centimeterSizeToPixels($value));
  36. $this->assertEquals($value / 2.54 * 1440, Font::centimeterSizeToTwips($value));
  37. $this->assertEquals($value * 1440, Font::inchSizeToTwips($value));
  38. $this->assertEquals($value / 96 * 1440, Font::pixelSizeToTwips($value));
  39. $this->assertEquals($value / 72 * 1440, Font::pointSizeToTwips($value));
  40. }
  41. }