FontTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace FontLib\Tests;
  3. use FontLib\Font;
  4. use PHPUnit\Framework\TestCase;
  5. class FontTest extends TestCase
  6. {
  7. public function testLoadFileNotFound()
  8. {
  9. // @todo when PHP 5.4 support is dropped, uncomment line below and drop
  10. // the try...catch block.
  11. // $this->expectException('\Fontlib\Exception\FontNotFoundException');
  12. try {
  13. Font::load('non-existing/font.ttf');
  14. $this->fail('Load should have failed.');
  15. }
  16. catch (\Fontlib\Exception\FontNotFoundException $e) {
  17. // Avoid throwing a risky test error.
  18. $this->assertTrue(true);
  19. }
  20. }
  21. public function testLoadTTFFont()
  22. {
  23. $trueTypeFont = Font::load('tests/resources/fonts/ahem/ahem.ttf');
  24. $this->assertInstanceOf('FontLib\TrueType\File', $trueTypeFont);
  25. }
  26. public function testGetFontInfoTTF()
  27. {
  28. $font = Font::load('tests/resources/fonts/ahem/ahem.ttf');
  29. $font->parse();
  30. $this->assertSame('Ahem', $font->getFontName());
  31. $this->assertSame('Regular', $font->getFontSubfamily());
  32. $this->assertSame('Version 1.50 Ahem', $font->getFontSubfamilyID());
  33. $this->assertSame('Ahem', $font->getFontFullName());
  34. $this->assertSame('Version 1.50', $font->getFontVersion());
  35. $this->assertSame(400, $font->getFontWeight());
  36. $this->assertSame('Ahem', $font->getFontPostscriptName());
  37. $this->assertTrue($font->close());
  38. }
  39. public function testTTFCmap()
  40. {
  41. $trueTypeFont = Font::load('tests/resources/fonts/noto/NotoSansShavian-Regular.ttf');
  42. $trueTypeFont->parse();
  43. $cmapTable = $trueTypeFont->getData("cmap", "subtables");
  44. $cmapFormat4Table = $cmapTable[0];
  45. $this->assertEquals(4, $cmapFormat4Table['format']);
  46. $this->assertEquals(51, $cmapFormat4Table['segCount']);
  47. $this->assertEquals($cmapFormat4Table['segCount'], count($cmapFormat4Table['startCode']));
  48. $this->assertEquals($cmapFormat4Table['segCount'], count($cmapFormat4Table['endCode']));
  49. $cmapFormat12Table = $cmapTable[1];
  50. $this->assertEquals(12, $cmapFormat12Table['format']);
  51. $this->assertEquals(294, $cmapFormat12Table['ngroups']);
  52. $this->assertEquals(294, count($cmapFormat12Table['startCode']));
  53. $this->assertEquals(294, count($cmapFormat12Table['endCode']));
  54. $this->assertEquals(383, count($cmapFormat12Table['glyphIndexArray']));
  55. }
  56. }