FontTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace FontLib\Tests;
  3. use FontLib\Font;
  4. use PHPUnit\Framework\TestCase;
  5. class FontTest extends TestCase
  6. {
  7. /**
  8. * @expectedException \Fontlib\Exception\FontNotFoundException
  9. */
  10. public function testLoadFileNotFound()
  11. {
  12. Font::load('non-existing/font.ttf');
  13. }
  14. public function testLoadTTFFontSuccessfully()
  15. {
  16. $trueTypeFont = Font::load('sample-fonts/IntelClear-Light.ttf');
  17. $this->assertInstanceOf('FontLib\TrueType\File', $trueTypeFont);
  18. }
  19. public function test12CmapFormat()
  20. {
  21. $trueTypeFont = Font::load('sample-fonts/NotoSansShavian-Regular.ttf');
  22. $trueTypeFont->parse();
  23. $cmapTable = $trueTypeFont->getData("cmap", "subtables");
  24. $cmapFormat4Table = $cmapTable[0];
  25. $this->assertEquals(4, $cmapFormat4Table['format']);
  26. $this->assertEquals(6, $cmapFormat4Table['segCount']);
  27. $this->assertEquals($cmapFormat4Table['segCount'], count($cmapFormat4Table['startCode']));
  28. $this->assertEquals($cmapFormat4Table['segCount'], count($cmapFormat4Table['endCode']));
  29. $cmapFormat12Table = $cmapTable[1];
  30. $this->assertEquals(12, $cmapFormat12Table['format']);
  31. $this->assertEquals(6, $cmapFormat12Table['ngroups']);
  32. $this->assertEquals(6, count($cmapFormat12Table['startCode']));
  33. $this->assertEquals(6, count($cmapFormat12Table['endCode']));
  34. $this->assertEquals(53, count($cmapFormat12Table['glyphIndexArray']));
  35. }
  36. }